From 4c922aba3f75f04ab51ebd9623b89963c2f5dbd2 Mon Sep 17 00:00:00 2001 From: Erik Pilkington Date: Fri, 29 Jul 2016 00:55:40 +0000 Subject: [PATCH] [Parser] Fix bug where delayed typo in conditional expression was corrected twice Patch by David Tarditi! Differential revision: https://reviews.llvm.org/D22930 llvm-svn: 277095 --- clang/lib/Parse/ParseExpr.cpp | 7 ++++--- clang/test/Sema/typo-correction.c | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/clang/lib/Parse/ParseExpr.cpp b/clang/lib/Parse/ParseExpr.cpp index c71e270cb4c4..3788b18f0730 100644 --- a/clang/lib/Parse/ParseExpr.cpp +++ b/clang/lib/Parse/ParseExpr.cpp @@ -446,14 +446,15 @@ Parser::ParseRHSOfBinaryExpression(ExprResult LHS, prec::Level MinPrec) { LHS = Actions.ActOnBinOp(getCurScope(), OpToken.getLocation(), OpToken.getKind(), LHS.get(), RHS.get()); - // In this case, ActOnBinOp performed the CorrectDelayedTyposInExpr check. - if (!getLangOpts().CPlusPlus) - continue; } else { LHS = Actions.ActOnConditionalOp(OpToken.getLocation(), ColonLoc, LHS.get(), TernaryMiddle.get(), RHS.get()); } + // In this case, ActOnBinOp or ActOnConditionalOp performed the + // CorrectDelayedTyposInExpr check. + if (!getLangOpts().CPlusPlus) + continue; } // Ensure potential typos aren't left undiagnosed. if (LHS.isInvalid()) { diff --git a/clang/test/Sema/typo-correction.c b/clang/test/Sema/typo-correction.c index a1107a25ee54..59f022dfe528 100644 --- a/clang/test/Sema/typo-correction.c +++ b/clang/test/Sema/typo-correction.c @@ -65,3 +65,18 @@ int fn_with_rs(int r) { r = TYPO + r * TYPO; } // expected-error 2 {{use of unde void fn_with_unknown(int a, int b) { fn_with_unknown(unknown, unknown | unknown); // expected-error 3 {{use of undeclared identifier}} } + +// Two typos in a parenthesized expression or argument list with a conditional +// expression caused a crash in C mode. +// +// r272587 fixed a similar bug for binary operations. The same fix was needed for +// conditional expressions. + +int g(int x, int y) { + return x + y; +} + +int h() { + g(x, 5 ? z : 0); // expected-error 2 {{use of undeclared identifier}} + (x, 5 ? z : 0); // expected-error 2 {{use of undeclared identifier}} +}