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

David Majnemer david.majnemer at gmail.com
Fri Apr 10 00:37:01 PDT 2015


Hi rsmith,

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

http://reviews.llvm.org/D8958

Files:
  lib/Sema/SemaDecl.cpp
  test/CXX/basic/basic.types/p10.cpp

Index: lib/Sema/SemaDecl.cpp
===================================================================
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -4891,6 +4891,8 @@
 
 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(),
Index: test/CXX/basic/basic.types/p10.cpp
===================================================================
--- test/CXX/basic/basic.types/p10.cpp
+++ test/CXX/basic/basic.types/p10.cpp
@@ -139,3 +139,5 @@
 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}}

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D8958.23576.patch
Type: text/x-patch
Size: 1077 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150410/2fbe091e/attachment.bin>


More information about the cfe-commits mailing list