summaryrefslogtreecommitdiffstats
path: root/contrib/llvm/patches/patch-r279289-clang-r199571-fix-string-literal-assertion.diff
blob: b2079dfc1bc0025e21b7d276feb28a43ffe43678 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
Pull in r199571 from upstream clang trunk (by Ted Kremenek):

  Harden InitListExpr::isStringLiteralInit() against getInit()
  returning null.

  This led to a crash on invalid code (sorry, no good test case).

  Fixes <rdar://problem/15831804>.

This fixes an assertion when compiling certain incorrect code, as
reported upstream in http://llvm.org/PR22684 .

Introduced here: http://svnweb.freebsd.org/changeset/base/279289

Index: tools/clang/lib/AST/Expr.cpp
===================================================================
--- tools/clang/lib/AST/Expr.cpp
+++ tools/clang/lib/AST/Expr.cpp
@@ -1892,7 +1892,11 @@ bool InitListExpr::isStringLiteralInit() const {
   const ArrayType *AT = getType()->getAsArrayTypeUnsafe();
   if (!AT || !AT->getElementType()->isIntegerType())
     return false;
-  const Expr *Init = getInit(0)->IgnoreParens();
+  // It is possible for getInit() to return null.
+  const Expr *Init = getInit(0);
+  if (!Init)
+    return false;
+  Init = Init->IgnoreParens();
   return isa<StringLiteral>(Init) || isa<ObjCEncodeExpr>(Init);
 }
 
OpenPOWER on IntegriCloud