[PATCH] Allow transformation of VariableArray to ConstantArray.
Serge Pavlov
sepavloff at gmail.com
Tue Feb 4 06:40:39 PST 2014
sepavloff added you to the CC list for the revision "Allow transformation of VariableArray to ConstantArray.".
In the following code:
struct A { static const int sz; };
template<class T> void f() { T arr[A::sz]; }
the array 'arr' is represented as a variable size array in the template.
If 'A::sz' gets value below in the translation unit, the array in
instantiation can turn into constant size array.
This change fixes PR18633.
http://llvm-reviews.chandlerc.com/D2688
Files:
lib/Sema/TreeTransform.h
test/SemaCXX/crashes.cpp
Index: lib/Sema/TreeTransform.h
===================================================================
--- lib/Sema/TreeTransform.h
+++ lib/Sema/TreeTransform.h
@@ -3929,7 +3929,11 @@
return QualType();
}
- VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
+ ArrayTypeLoc NewTL;
+ if (Result->getTypeClass() == Type::ConstantArray)
+ NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
+ else
+ NewTL = TLB.push<VariableArrayTypeLoc>(Result);
NewTL.setLBracketLoc(TL.getLBracketLoc());
NewTL.setRBracketLoc(TL.getRBracketLoc());
NewTL.setSizeExpr(Size);
Index: test/SemaCXX/crashes.cpp
===================================================================
--- test/SemaCXX/crashes.cpp
+++ test/SemaCXX/crashes.cpp
@@ -231,3 +231,17 @@
};
void C2::f() {}
}
+
+namespace pr18633 {
+ struct A1 {
+ static const int sz;
+ };
+ template<typename T>
+ void func () {
+ int arr[A1::sz];
+ }
+ const int A1::sz = 12;
+ void func2() {
+ func<int>();
+ }
+}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D2688.1.patch
Type: text/x-patch
Size: 1013 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140204/fd3a65dd/attachment.bin>
More information about the cfe-commits
mailing list