r225124 - Crash less enthusiasticially on _Atomic or __restrict__ on invalid types.

Nico Weber nicolasweber at gmx.de
Sat Jan 3 20:53:10 PST 2015


Author: nico
Date: Sat Jan  3 22:53:10 2015
New Revision: 225124

URL: http://llvm.org/viewvc/llvm-project?rev=225124&view=rev
Log:
Crash less enthusiasticially on _Atomic or __restrict__ on invalid types.

Many places in Sema cannot handle isNull() types.  This is fine, because in
most places the type building code recovers by falling back to IntTy.  In
GetFullTypeForDeclarator(), this is done at the end of the getNumTypeObjects()
loop body.  This function calls BuildQualifiedType() before this fallback is
done though, so it explicitly needs to check for isNull() types.

Modified:
    cfe/trunk/lib/Sema/SemaType.cpp
    cfe/trunk/test/Sema/types.c

Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=225124&r1=225123&r2=225124&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Sat Jan  3 22:53:10 2015
@@ -1188,6 +1188,9 @@ static std::string getPrintableNameForEn
 
 QualType Sema::BuildQualifiedType(QualType T, SourceLocation Loc,
                                   Qualifiers Qs, const DeclSpec *DS) {
+  if (T.isNull())
+    return QualType();
+
   // Enforce C99 6.7.3p2: "Types other than pointer types derived from
   // object or incomplete types shall not be restrict-qualified."
   if (Qs.hasRestrict()) {
@@ -1226,6 +1229,9 @@ QualType Sema::BuildQualifiedType(QualTy
 
 QualType Sema::BuildQualifiedType(QualType T, SourceLocation Loc,
                                   unsigned CVRA, const DeclSpec *DS) {
+  if (T.isNull())
+    return QualType();
+
   // Convert from DeclSpec::TQ to Qualifiers::TQ by just dropping TQ_atomic.
   unsigned CVR = CVRA & ~DeclSpec::TQ_atomic;
 

Modified: cfe/trunk/test/Sema/types.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/types.c?rev=225124&r1=225123&r2=225124&view=diff
==============================================================================
--- cfe/trunk/test/Sema/types.c (original)
+++ cfe/trunk/test/Sema/types.c Sat Jan  3 22:53:10 2015
@@ -1,7 +1,7 @@
-// RUN: %clang_cc1 %s -pedantic -verify -triple=x86_64-apple-darwin9
-// RUN: %clang_cc1 %s -pedantic -verify -triple=mips64-linux-gnu
-// RUN: %clang_cc1 %s -pedantic -verify -triple=x86_64-unknown-linux
-// RUN: %clang_cc1 %s -pedantic -verify -triple=x86_64-unknown-linux-gnux32
+// RUN: %clang_cc1 %s -fblocks -pedantic -verify -triple=x86_64-apple-darwin9
+// RUN: %clang_cc1 %s -fblocks -pedantic -verify -triple=mips64-linux-gnu
+// RUN: %clang_cc1 %s -fblocks -pedantic -verify -triple=x86_64-unknown-linux
+// RUN: %clang_cc1 %s -fblocks -pedantic -verify -triple=x86_64-unknown-linux-gnux32
 
 // rdar://6097662
 typedef int (*T)[2];
@@ -84,3 +84,7 @@ void convert() {
     uchar32 r = 0;
     r.s[ 1234 ] = 1; // expected-error {{illegal vector component name 's'}}
 }
+
+int &*_Atomic null_type_0; // expected-error {{expected identifier or '('}}
+int &*__restrict__ null_type_1; // expected-error {{expected identifier or '('}}
+int ^_Atomic null_type_2; // expected-error {{block pointer to non-function type is invalid}}





More information about the cfe-commits mailing list