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() ||


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() ||
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to