[PATCH] D21126: Fix crash when rewriting call to match placeholder

Alyssa Milburn via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 8 03:44:13 PDT 2016


amilburn created this revision.
amilburn added a reviewer: rsmith.
amilburn added a subscriber: cfe-commits.

If an argument is a placeholder, rewriteBuiltinFunctionDecl should skip it when trying to rewrite address spaces.

This situation can happen because not all placeholders are rejected by ActOnCallExpr. The supplied test passes it an UnresolvedLookupExpr with overload type.

Fixes PR25961.

http://reviews.llvm.org/D21126

Files:
  lib/Sema/SemaExpr.cpp
  test/Sema/implicit-function-typo-crash.c

Index: test/Sema/implicit-function-typo-crash.c
===================================================================
--- /dev/null
+++ test/Sema/implicit-function-typo-crash.c
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+// PR25961
+void free(); // expected-note {{'free' declared here}}
+int main() {
+  strcpy(file, 0); // expected-warning {{implicitly declaring library function 'strcpy' with type}} \
+  // expected-note {{include the header <string.h>}} \
+  // expected-error {{use of undeclared identifier 'file'; did you mean 'free'}}
+}
Index: lib/Sema/SemaExpr.cpp
===================================================================
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -5050,7 +5050,10 @@
   for (QualType ParamType : FT->param_types()) {
 
     // Convert array arguments to pointer to simplify type lookup.
-    Expr *Arg = Sema->DefaultFunctionArrayLvalueConversion(ArgExprs[i++]).get();
+    ExprResult R = Sema->DefaultFunctionArrayLvalueConversion(ArgExprs[i++]);
+    if (R.isInvalid())
+      continue;
+    Expr *Arg = R.get();
     QualType ArgType = Arg->getType();
     if (!ParamType->isPointerType() ||
         ParamType.getQualifiers().hasAddressSpace() ||


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D21126.60012.patch
Type: text/x-patch
Size: 1220 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160608/75898cee/attachment.bin>


More information about the cfe-commits mailing list