r259116 - Check for frontend errors after releasing the Builder.

Manman Ren via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 28 15:29:02 PST 2016


Author: mren
Date: Thu Jan 28 17:29:02 2016
New Revision: 259116

URL: http://llvm.org/viewvc/llvm-project?rev=259116&view=rev
Log:
Check for frontend errors after releasing the Builder.

Frontend can emit errors when releaseing the Builder. If there are errors before
or when releasing the Builder, we reset the module to stop here before invoking
the backend.

Before this commit, clang will continue to invoke the backend and backend can
crash.

Differential Revision: http://reviews.llvm.org/D16564

Added:
    cfe/trunk/test/CodeGen/target-builtin-error-3.c
Modified:
    cfe/trunk/lib/CodeGen/ModuleBuilder.cpp

Modified: cfe/trunk/lib/CodeGen/ModuleBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/ModuleBuilder.cpp?rev=259116&r1=259115&r2=259116&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/ModuleBuilder.cpp (original)
+++ cfe/trunk/lib/CodeGen/ModuleBuilder.cpp Thu Jan 28 17:29:02 2016
@@ -199,15 +199,18 @@ namespace {
     }
 
     void HandleTranslationUnit(ASTContext &Ctx) override {
+      // Release the Builder when there is no error.
+      if (!Diags.hasErrorOccurred() && Builder)
+        Builder->Release();
+
+      // If there are errors before or when releasing the Builder, reset
+      // the module to stop here before invoking the backend.
       if (Diags.hasErrorOccurred()) {
         if (Builder)
           Builder->clear();
         M.reset();
         return;
       }
-
-      if (Builder)
-        Builder->Release();
     }
 
     void AssignInheritanceModel(CXXRecordDecl *RD) override {

Added: cfe/trunk/test/CodeGen/target-builtin-error-3.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/target-builtin-error-3.c?rev=259116&view=auto
==============================================================================
--- cfe/trunk/test/CodeGen/target-builtin-error-3.c (added)
+++ cfe/trunk/test/CodeGen/target-builtin-error-3.c Thu Jan 28 17:29:02 2016
@@ -0,0 +1,28 @@
+// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin -S -verify -o - -target-feature +avx
+
+// RUN: not %clang_cc1 %s -triple=x86_64-apple-darwin -emit-obj -target-feature +avx 2> %t.err
+// RUN: FileCheck < %t.err %s
+// CHECK: 1 error generated
+
+typedef unsigned short uint16_t;
+typedef long long __m128i __attribute__((__vector_size__(16)));
+typedef float __v8sf __attribute__ ((__vector_size__ (32)));
+typedef float __m256 __attribute__ ((__vector_size__ (32)));
+typedef uint16_t half;
+typedef __attribute__ ((ext_vector_type( 8),__aligned__( 16))) half half8;
+typedef __attribute__ ((ext_vector_type(16),__aligned__( 32))) half half16;
+typedef __attribute__ ((ext_vector_type(16),__aligned__( 2))) half half16U;
+typedef __attribute__ ((ext_vector_type( 8),__aligned__( 32))) float float8;
+typedef __attribute__ ((ext_vector_type(16),__aligned__( 64))) float float16;
+static inline half8 __attribute__((__overloadable__)) convert_half( float8 a ) {
+  return __extension__ ({ __m256 __a = (a); (__m128i)__builtin_ia32_vcvtps2ph256((__v8sf)__a, (0x00)); }); // expected-error {{'__builtin_ia32_vcvtps2ph256' needs target feature f16c}}
+}
+static inline half16 __attribute__((__overloadable__)) convert_half( float16 a ) {
+  half16 r; 
+  r.lo = convert_half( a.lo); 
+  return r;
+}
+void avx_test( uint16_t *destData, float16 argbF)
+{
+   ((half16U*)destData)[0] = convert_half(argbF);
+}




More information about the cfe-commits mailing list