]> granicus.if.org Git - clang/commitdiff
Prevent clang from emitting output when input has errors
authorDaniel Dunbar <daniel@zuster.org>
Fri, 18 Jul 2008 16:38:05 +0000 (16:38 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Fri, 18 Jul 2008 16:38:05 +0000 (16:38 +0000)
 + test case
<rdar://problem/6080040>
http://llvm.org/bugs/show_bug.cgi?id=2280

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@53756 91177308-0d34-0410-b5e6-96231b3b80d8

Driver/clang.cpp
test/CodeGen/2008-07-17-no-emit-on-error.c [new file with mode: 0644]

index 5e8f51cbc973b7ed9fa4798c71bbb54682c45465..cf3f9793d91077789e5fe51aeeffed56d79e3d8c 100644 (file)
@@ -1285,6 +1285,12 @@ static void ProcessInputFile(Preprocessor &PP, PreprocessorFactory &PPF,
     ParseAST(PP, Consumer, Stats);
   }
 
+  // Don't emit code when the input had errors.
+  if (CodeGenModule && PP.getDiagnostics().hasErrorOccurred()) {
+    delete CodeGenModule;
+    CodeGenModule = 0;
+  }
+
   // If running the code generator, finish up now.
   if (CodeGenModule) {
     std::ostream *Out;
diff --git a/test/CodeGen/2008-07-17-no-emit-on-error.c b/test/CodeGen/2008-07-17-no-emit-on-error.c
new file mode 100644 (file)
index 0000000..5339695
--- /dev/null
@@ -0,0 +1,10 @@
+// RUN: rm -f %t1.bc 
+// RUN: ! clang %s -emit-llvm-bc -o %t1.bc
+// RUN: ! test -f %t1.bc
+
+void f() {
+}
+
+void g() {
+  *10;
+}