This is an archive of the discontinued LLVM Phabricator instance.

Sema: typo correct both sides of binary expression
Needs ReviewPublic

Authored by compnerd on Feb 12 2016, 11:22 PM.

Details

Reviewers
rtrieu
Summary

When parsing a ternary expression, we would parse the middle and the last
components of the expression. If there was a typo in both, we would only
run the typo correction once. Normally, this would be fine, but, when Sema
would be destructed in an Asserts build, we would assert that a delayed typo was
not handled. This was caused by the fact that the RHS would evaluate as valid
as a TypoExpr would be returned via the ExprResult, and invalid simply ensures
that an expression is present. Peek into the result and perform the handling
that we would reserve for the invalid type.

Resolves PR265598.

Diff Detail

Event Timeline

compnerd updated this revision to Diff 47902.Feb 12 2016, 11:22 PM
compnerd retitled this revision from to Sema: typo correct both sides of binary expression.
compnerd updated this object.
compnerd added a reviewer: rtrieu.
compnerd added a subscriber: cfe-commits.
rtrieu edited edge metadata.Feb 23 2016, 5:09 PM

While this change does add the intended error messages, it won't produce a correct a typo-corrected AST. For instance:

void run(int sss) {
 sss = ssss ? ssss : ssss;
}

Will produce an empty function body:

`-FunctionDecl 0x7082ef0 <typo2.cc:1:1, line:3:1> line:1:6 run 'void (int)'
  |-ParmVarDecl 0x7082e30 <col:10, col:14> col:14 used sss 'int'
  `-CompoundStmt 0x70830f8 <col:19, line:3:1>

While the old code would make an AST for the body:

`-FunctionDecl 0x59c0790 <typo2.cc:1:1, line:3:1> line:1:6 run 'void (int)'
  |-ParmVarDecl 0x59c06d0 <col:10, col:14> col:14 used sss 'int'
  `-CompoundStmt 0x59c0a90 <col:19, line:3:1>
    `-BinaryOperator 0x59c0a68 <line:2:2, col:22> 'int' lvalue '='
      |-DeclRefExpr 0x59c0880 <col:2> 'int' lvalue ParmVar 0x59c06d0 'sss' 'int'
      `-ImplicitCastExpr 0x59c0a50 <col:8, col:22> 'int' <LValueToRValue>
        `-ConditionalOperator 0x59c0a20 <col:8, col:22> 'int' lvalue
          |-ImplicitCastExpr 0x59c0a08 <col:8> '_Bool' <IntegralToBoolean>
          | `-ImplicitCastExpr 0x59c09f0 <col:8> 'int' <LValueToRValue>
          |   `-DeclRefExpr 0x59c0978 <col:8> 'int' lvalue ParmVar 0x59c06d0 'sss' 'int'
          |-DeclRefExpr 0x59c09a0 <col:15> 'int' lvalue ParmVar 0x59c06d0 'sss' 'int'
          `-DeclRefExpr 0x59c09c8 <col:22> 'int' lvalue ParmVar 0x59c06d0 'sss' 'int'