Hi,

Attached you will find the fix for a crash on invalid code in clang 3.7

It crashes on this code:

void fn2() {
  f(THIS_IS_AN_ERROR,  afunction(afunction_));  
}

The problem is that the arguments are of TheCall are reset later to the ones 
in Args. Some TypoExpr that have already been diagnosed will assert later in 
Sema::getTypoExprState.

I was wondering if instead of reusing the TheCall->getArgs() array I should 
copy the arguments in an array on the stack instead.

I suppose I should commit to trunk and ask someone to merge into release_37?

Regards
-- 
Olivier
>From 7da528047bb8d925078cdc8226a9961f74130b93 Mon Sep 17 00:00:00 2001
From: Olivier Goffart <ogoff...@woboq.com>
Date: Fri, 14 Aug 2015 12:59:17 +0200
Subject: [PATCH] Fix crash with two typos in the arguments of a function

The problem is that the arguments are of TheCall are reset later
to the ones in Args, making TypoExpr put back. Some TypoExpr that have
already  been diagnosed and will assert later in Sema::getTypoExprState
---
 lib/Sema/SemaExpr.cpp       | 1 +
 test/Sema/typo-correction.c | 6 ++++++
 2 files changed, 7 insertions(+)

diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp
index dd99ad2..a271cbd 100644
--- a/lib/Sema/SemaExpr.cpp
+++ b/lib/Sema/SemaExpr.cpp
@@ -4937,6 +4937,7 @@ Sema::BuildResolvedCallExpr(Expr *Fn, NamedDecl *NDecl,
     if (!Result.isUsable()) return ExprError();
     TheCall = dyn_cast<CallExpr>(Result.get());
     if (!TheCall) return Result;
+    Args = ArrayRef<Expr *>(TheCall->getArgs(), TheCall->getNumArgs());
   }
 
   // Bail out early if calling a builtin with custom typechecking.
diff --git a/test/Sema/typo-correction.c b/test/Sema/typo-correction.c
index ff43064..4ef5057 100644
--- a/test/Sema/typo-correction.c
+++ b/test/Sema/typo-correction.c
@@ -49,3 +49,9 @@ extern double cabs(_Complex double z);
 void fn1() {
   cabs(errij);  // expected-error {{use of undeclared identifier 'errij'}}
 }
+
+extern long afunction(int); // expected-note {{'afunction' declared here}}
+void fn2() {
+  f(THIS_IS_AN_ERROR, // expected-error {{use of undeclared identifier 'THIS_IS_AN_ERROR'}}
+    afunction(afunction_));  // expected-error {{use of undeclared identifier 'afunction_'; did you mean 'afunction'?}}
+}
-- 
2.5.0

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to