]> CyberLeo.Net >> Repos - FreeBSD/releng/10.2.git/blob - contrib/llvm/patches/patch-r261680-clang-r200899-fix-security-quantis.diff
- Copy stable/10@285827 to releng/10.2 in preparation for 10.2-RC1
[FreeBSD/releng/10.2.git] / contrib / llvm / patches / patch-r261680-clang-r200899-fix-security-quantis.diff
1 Pull in r200899 from upstream clang trunk (by Serge Pavlov):
2
3   Allow transformation of VariableArray to ConstantArray.
4
5   In the following code:
6
7       struct A { static const int sz; };
8       template<class T> void f() { T arr[A::sz]; }
9
10   the array 'arr' is represented as a variable size array in the template.
11   If 'A::sz' gets value below in the translation unit, the array in
12   instantiation can turn into constant size array.
13
14   This change fixes PR18633.
15
16   Differential Revision: http://llvm-reviews.chandlerc.com/D2688
17
18 Introduced here: http://svnweb.freebsd.org/changeset/base/261680
19
20 Index: tools/clang/test/SemaCXX/c99-variable-length-array.cpp
21 ===================================================================
22 --- tools/clang/test/SemaCXX/c99-variable-length-array.cpp
23 +++ tools/clang/test/SemaCXX/c99-variable-length-array.cpp
24 @@ -140,3 +140,24 @@ namespace PR11744 {
25    }
26    int test = f<int>(0); // expected-note {{instantiation of}}
27  }
28 +
29 +namespace pr18633 {
30 +  struct A1 {
31 +    static const int sz;
32 +    static const int sz2;
33 +  };
34 +  const int A1::sz2 = 11;
35 +  template<typename T>
36 +  void func () {
37 +    int arr[A1::sz]; // expected-warning{{variable length arrays are a C99 feature}}
38 +  }
39 +  template<typename T>
40 +  void func2 () {
41 +    int arr[A1::sz2];
42 +  }
43 +  const int A1::sz = 12;
44 +  void func2() {
45 +    func<int>();
46 +    func2<int>();
47 +  }
48 +}
49 Index: tools/clang/lib/Sema/TreeTransform.h
50 ===================================================================
51 --- tools/clang/lib/Sema/TreeTransform.h
52 +++ tools/clang/lib/Sema/TreeTransform.h
53 @@ -3966,7 +3966,9 @@ TreeTransform<Derived>::TransformVariableArrayType
54        return QualType();
55    }
56  
57 -  VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
58 +  // We might have constant size array now, but fortunately it has the same
59 +  // location layout.
60 +  ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
61    NewTL.setLBracketLoc(TL.getLBracketLoc());
62    NewTL.setRBracketLoc(TL.getRBracketLoc());
63    NewTL.setSizeExpr(Size);