r235251 - [Sema] Don't crash if array bound calculation overflowed constexpr array

David Majnemer david.majnemer at gmail.com
Fri Apr 17 21:55:51 PDT 2015


Author: majnemer
Date: Fri Apr 17 23:55:51 2015
New Revision: 235251

URL: http://llvm.org/viewvc/llvm-project?rev=235251&view=rev
Log:
[Sema] Don't crash if array bound calculation overflowed constexpr array

We didn't correctly expect a QualifiedTypeLoc when faced with fixing a
variable array type into a constant array type.

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

Modified:
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/test/CXX/basic/basic.types/p10.cpp

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=235251&r1=235250&r2=235251&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Fri Apr 17 23:55:51 2015
@@ -4891,6 +4891,8 @@ static QualType TryToFixInvalidVariablyM
 
 static void
 FixInvalidVariablyModifiedTypeLoc(TypeLoc SrcTL, TypeLoc DstTL) {
+  SrcTL = SrcTL.getUnqualifiedLoc();
+  DstTL = DstTL.getUnqualifiedLoc();
   if (PointerTypeLoc SrcPTL = SrcTL.getAs<PointerTypeLoc>()) {
     PointerTypeLoc DstPTL = DstTL.castAs<PointerTypeLoc>();
     FixInvalidVariablyModifiedTypeLoc(SrcPTL.getPointeeLoc(),

Modified: cfe/trunk/test/CXX/basic/basic.types/p10.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/basic/basic.types/p10.cpp?rev=235251&r1=235250&r2=235251&view=diff
==============================================================================
--- cfe/trunk/test/CXX/basic/basic.types/p10.cpp (original)
+++ cfe/trunk/test/CXX/basic/basic.types/p10.cpp Fri Apr 17 23:55:51 2015
@@ -139,3 +139,5 @@ constexpr int f(ArrBad) { return 0; } //
 constexpr int arb(int n) {
   int a[n]; // expected-error {{variable of non-literal type 'int [n]' cannot be defined in a constexpr function}}
 }
+constexpr long Overflow[ // expected-error {{constexpr variable cannot have non-literal type 'long const[(1 << 30) << 2]'}}
+    (1 << 30) << 2]{};   // expected-warning {{requires 34 bits to represent}}





More information about the cfe-commits mailing list