]> granicus.if.org Git - clang/commitdiff
[AST] There is no message for C++1z-style static_assert
authorDavid Majnemer <david.majnemer@gmail.com>
Fri, 5 Jun 2015 18:03:58 +0000 (18:03 +0000)
committerDavid Majnemer <david.majnemer@gmail.com>
Fri, 5 Jun 2015 18:03:58 +0000 (18:03 +0000)
We would crash in the DeclPrinter trying to pretty-print the
static_assert message.  C++1z-style assertions don't have a message so
we would crash.

This fixes PR23756.

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

lib/AST/DeclPrinter.cpp
lib/Headers/Intrin.h
test/SemaCXX/static-assert.cpp

index c0f3e17693dccf0b020504b0c9d56c636d06adce..d8cd40ec9c60ac0033eea918752baa43b78ccd4f 100644 (file)
@@ -733,8 +733,10 @@ void DeclPrinter::VisitImportDecl(ImportDecl *D) {
 void DeclPrinter::VisitStaticAssertDecl(StaticAssertDecl *D) {
   Out << "static_assert(";
   D->getAssertExpr()->printPretty(Out, nullptr, Policy, Indentation);
-  Out << ", ";
-  D->getMessage()->printPretty(Out, nullptr, Policy, Indentation);
+  if (StringLiteral *SL = D->getMessage()) {
+    Out << ", ";
+    SL->printPretty(Out, nullptr, Policy, Indentation);
+  }
   Out << ")";
 }
 
index 727a55e5b7619c83616e4e2a623cc156cba3c8fa..9592cccb15c72bde18cc6e6dc3ff615ca5186d73 100644 (file)
@@ -546,13 +546,8 @@ _bittestandset(long *a, long b) {
 #if defined(__i386__) || defined(__x86_64__)
 static __inline__ unsigned char __attribute__((__always_inline__, __nodebug__))
 _interlockedbittestandset(long volatile *__BitBase, long __BitPos) {
-  unsigned char __Res;
-  __asm__ ("xor %0, %0\n"
-           "lock bts %2, %1\n"
-           "setc %0\n"
-           : "=r" (__Res), "+m"(*__BitBase)
-           : "Ir"(__BitPos));
-  return __Res;
+  long __OldVal = __atomic_fetch_or(__BitBase, 1 << __BitPos, 5);
+  return (__OldVal >> __BitPos) & 1;
 }
 #endif
 #ifdef __x86_64__
index 7de4d07b50b8e3f0c8819c03adc5d8615511c825..52be1a3904254175696a95223643f7cda3389038 100644 (file)
@@ -51,3 +51,12 @@ StaticAssertProtected<X> sap2; // expected-note {{instantiation}}
 
 static_assert(true); // expected-warning {{C++1z extension}}
 static_assert(false); // expected-error-re {{failed{{$}}}} expected-warning {{extension}}
+
+void PR23756() {
+  struct { // expected-note 2 {{no known conversion from}}
+  } _ = decltype(            // expected-error {{no viable conversion}}
+      ({                     // expected-warning {{no effect in an unevaluated context}}
+        static_assert(true); // expected-warning {{C++1z extension}}
+        1;
+      })){};
+}