r239170 - [AST] There is no message for C++1z-style static_assert

David Majnemer david.majnemer at gmail.com
Fri Jun 5 11:03:59 PDT 2015


Author: majnemer
Date: Fri Jun  5 13:03:58 2015
New Revision: 239170

URL: http://llvm.org/viewvc/llvm-project?rev=239170&view=rev
Log:
[AST] There is no message for C++1z-style static_assert

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.

Modified:
    cfe/trunk/lib/AST/DeclPrinter.cpp
    cfe/trunk/lib/Headers/Intrin.h
    cfe/trunk/test/SemaCXX/static-assert.cpp

Modified: cfe/trunk/lib/AST/DeclPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclPrinter.cpp?rev=239170&r1=239169&r2=239170&view=diff
==============================================================================
--- cfe/trunk/lib/AST/DeclPrinter.cpp (original)
+++ cfe/trunk/lib/AST/DeclPrinter.cpp Fri Jun  5 13:03:58 2015
@@ -733,8 +733,10 @@ void DeclPrinter::VisitImportDecl(Import
 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 << ")";
 }
 

Modified: cfe/trunk/lib/Headers/Intrin.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/Intrin.h?rev=239170&r1=239169&r2=239170&view=diff
==============================================================================
--- cfe/trunk/lib/Headers/Intrin.h (original)
+++ cfe/trunk/lib/Headers/Intrin.h Fri Jun  5 13:03:58 2015
@@ -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__

Modified: cfe/trunk/test/SemaCXX/static-assert.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/static-assert.cpp?rev=239170&r1=239169&r2=239170&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/static-assert.cpp (original)
+++ cfe/trunk/test/SemaCXX/static-assert.cpp Fri Jun  5 13:03:58 2015
@@ -51,3 +51,12 @@ StaticAssertProtected<X> sap2; // expect
 
 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;
+      })){};
+}





More information about the cfe-commits mailing list