]> CyberLeo.Net >> Repos - FreeBSD/releng/10.2.git/blob - contrib/llvm/patches/patch-r279289-clang-r199571-fix-string-literal-assertion.diff
- Copy stable/10@285827 to releng/10.2 in preparation for 10.2-RC1
[FreeBSD/releng/10.2.git] / contrib / llvm / patches / patch-r279289-clang-r199571-fix-string-literal-assertion.diff
1 Pull in r199571 from upstream clang trunk (by Ted Kremenek):
2
3   Harden InitListExpr::isStringLiteralInit() against getInit()
4   returning null.
5
6   This led to a crash on invalid code (sorry, no good test case).
7
8   Fixes <rdar://problem/15831804>.
9
10 This fixes an assertion when compiling certain incorrect code, as
11 reported upstream in http://llvm.org/PR22684 .
12
13 Introduced here: http://svnweb.freebsd.org/changeset/base/279289
14
15 Index: tools/clang/lib/AST/Expr.cpp
16 ===================================================================
17 --- tools/clang/lib/AST/Expr.cpp
18 +++ tools/clang/lib/AST/Expr.cpp
19 @@ -1892,7 +1892,11 @@ bool InitListExpr::isStringLiteralInit() const {
20    const ArrayType *AT = getType()->getAsArrayTypeUnsafe();
21    if (!AT || !AT->getElementType()->isIntegerType())
22      return false;
23 -  const Expr *Init = getInit(0)->IgnoreParens();
24 +  // It is possible for getInit() to return null.
25 +  const Expr *Init = getInit(0);
26 +  if (!Init)
27 +    return false;
28 +  Init = Init->IgnoreParens();
29    return isa<StringLiteral>(Init) || isa<ObjCEncodeExpr>(Init);
30  }
31