r227220 - Properly handle typos in the conditional of ?: expressions in C.
Hans Wennborg
hans at chromium.org
Tue Jan 27 10:49:50 PST 2015
Let's have it run on the buildbots for a while, and then I'll merge it.
Thanks,
Hans
On Tue, Jan 27, 2015 at 10:42 AM, Kaelyn Takata <rikka at google.com> wrote:
> This is also a candidate for the 3.6 release branch as it fixes another
> post-3.5 diagnostics regression.
>
> On Tue, Jan 27, 2015 at 10:26 AM, Kaelyn Takata <rikka at google.com> wrote:
>>
>> Author: rikka
>> Date: Tue Jan 27 12:26:18 2015
>> New Revision: 227220
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=227220&view=rev
>> Log:
>> Properly handle typos in the conditional of ?: expressions in C.
>>
>> In particular, remove the OpaqueExpr transformation from r225389 and
>> move the correction of the conditional from CheckConditionalOperands to
>> ActOnConditionalOp before the OpaqueExpr is created. This fixes the
>> typo correction behavior in C code that uses the GNU extension for a
>> binary ?: (without an expression between the "?" and the ":").
>>
>> Modified:
>> cfe/trunk/lib/Sema/SemaExpr.cpp
>> cfe/trunk/lib/Sema/SemaExprCXX.cpp
>> cfe/trunk/test/Sema/typo-correction.c
>>
>> Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=227220&r1=227219&r2=227220&view=diff
>>
>> ==============================================================================
>> --- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
>> +++ cfe/trunk/lib/Sema/SemaExpr.cpp Tue Jan 27 12:26:18 2015
>> @@ -5785,15 +5785,6 @@ QualType Sema::CheckConditionalOperands(
>> ExprObjectKind &OK,
>> SourceLocation QuestionLoc) {
>>
>> - if (!getLangOpts().CPlusPlus) {
>> - // C cannot handle TypoExpr nodes on either side of a binop because
>> it
>> - // doesn't handle dependent types properly, so make sure any
>> TypoExprs have
>> - // been dealt with before checking the operands.
>> - ExprResult CondResult = CorrectDelayedTyposInExpr(Cond);
>> - if (!CondResult.isUsable()) return QualType();
>> - Cond = CondResult;
>> - }
>> -
>> ExprResult LHSResult = CheckPlaceholderExpr(LHS.get());
>> if (!LHSResult.isUsable()) return QualType();
>> LHS = LHSResult;
>> @@ -6175,6 +6166,15 @@ ExprResult Sema::ActOnConditionalOp(Sour
>> SourceLocation ColonLoc,
>> Expr *CondExpr, Expr *LHSExpr,
>> Expr *RHSExpr) {
>> + if (!getLangOpts().CPlusPlus) {
>> + // C cannot handle TypoExpr nodes in the condition because it
>> + // doesn't handle dependent types properly, so make sure any
>> TypoExprs have
>> + // been dealt with before checking the operands.
>> + ExprResult CondResult = CorrectDelayedTyposInExpr(CondExpr);
>> + if (!CondResult.isUsable()) return ExprError();
>> + CondExpr = CondResult.get();
>> + }
>> +
>> // If this is the gnu "x ?: y" extension, analyze the types as though
>> the LHS
>> // was the condition.
>> OpaqueValueExpr *opaqueValue = nullptr;
>>
>> Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=227220&r1=227219&r2=227220&view=diff
>>
>> ==============================================================================
>> --- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
>> +++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Tue Jan 27 12:26:18 2015
>> @@ -6146,12 +6146,6 @@ public:
>>
>> ExprResult TransformLambdaExpr(LambdaExpr *E) { return Owned(E); }
>>
>> - ExprResult TransformOpaqueValueExpr(OpaqueValueExpr *E) {
>> - if (Expr *SE = E->getSourceExpr())
>> - return TransformExpr(SE);
>> - return BaseTransform::TransformOpaqueValueExpr(E);
>> - }
>> -
>> ExprResult Transform(Expr *E) {
>> ExprResult Res;
>> while (true) {
>>
>> Modified: cfe/trunk/test/Sema/typo-correction.c
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/typo-correction.c?rev=227220&r1=227219&r2=227220&view=diff
>>
>> ==============================================================================
>> --- cfe/trunk/test/Sema/typo-correction.c (original)
>> +++ cfe/trunk/test/Sema/typo-correction.c Tue Jan 27 12:26:18 2015
>> @@ -13,6 +13,11 @@ void PR21656() {
>> a = b ? : 0; // expected-warning {{type specifier missing, defaults to
>> 'int'}} \
>> // expected-error {{use of undeclared identifier 'b'}}
>>
>> +int foobar; // expected-note {{'foobar' declared here}}
>> +a = goobar ?: 4; // expected-warning {{type specifier missing, defaults
>> to 'int'}} \
>> + // expected-error {{use of undeclared identifier
>> 'goobar'; did you mean 'foobar'?}} \
>> + // expected-error {{initializer element is not a
>> compile-time constant}}
>> +
>> struct ContainerStuct {
>> enum { SOME_ENUM }; // expected-note {{'SOME_ENUM' declared here}}
>> };
>>
>>
>> _______________________________________________
>> cfe-commits mailing list
>> cfe-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
>
More information about the cfe-commits
mailing list