This is an archive of the discontinued LLVM Phabricator instance.

[AST][RecoveryExpr] Part3: Support dependent conditional operators in C for error recovery.
ClosedPublic

Authored by hokein on Jul 22 2020, 6:50 AM.

Details

Summary

suppress spurious "typecheck_cond_expect_scalar" diagnostic.

Diff Detail

Event Timeline

hokein created this revision.Jul 22 2020, 6:50 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 22 2020, 6:50 AM
hokein marked an inline comment as done.Jul 22 2020, 6:55 AM
hokein added inline comments.
clang/lib/Sema/SemaExpr.cpp
8072

This follows the same way of how C++ codepath handles dependent code, see the above Line 8069 CXXCheckConditionalOperands.

hokein retitled this revision from [AST][RecoveryExpr] Suppress spurious "typecheck_cond_expect_scalar" diagnostic to [AST][RecoveryExpr] Part3: Suppress spurious "typecheck_cond_expect_scalar" diagnostic.Aug 17 2020, 4:03 AM
sammccall added inline comments.Sep 18 2020, 3:52 AM
clang/test/Sema/error-dependence.c
14

nit: parens would help me understand here :-)

I don't find this example compelling because we should know that "ptr > f" is a boolean.

Can we just have undefined ? ptr : f, expecting the only diag to be the undeclared ident?

hokein updated this revision to Diff 296374.Oct 6 2020, 12:52 AM

rebase and add ast-dump test.

clang/test/Sema/error-dependence.c
14

I don't find this example compelling because we should know that "ptr > f" is a boolean.

this is a reasonable impression, but in this case, there is no binary-operator > -- operands ptr, f have different types, and invalid for binary operator, instead we build a recovery-expr.

so the AST looks like (added in the dump-recovery.c test as well)

ConditionalOperator> '<dependent type>' contains-errors
  | |-RecoveryExpr  '<dependent type>' contains-errors lvalue
  | | |-DeclRefExpr  'int *' lvalue Var 0x8fdb620 'ptr' 'int *'
  | | `-DeclRefExpr  'float' lvalue Var 0x8ffd388 'f' 'float'
  | |-DeclRefExpr  'int *' lvalue Var 0x8fdb620 'ptr' 'int *'
  | `-DeclRefExpr  'float' lvalue Var 0x8ffd388 'f' 'float'

Can we just have undefined ? ptr : f, expecting the only diag to be the undeclared ident?

no unfortunately. the whole statement is being dropped (we don't preserve this in C/C++).

sammccall accepted this revision.Oct 6 2020, 1:00 AM
sammccall added inline comments.
clang/test/AST/ast-dump-recovery.c
75

add to comment: (comparison is invalid)

83

again - parens

clang/test/Sema/error-dependence.c
14

undefined() ? ptr : f then?

This revision is now accepted and ready to land.Oct 6 2020, 1:00 AM
hokein retitled this revision from [AST][RecoveryExpr] Part3: Suppress spurious "typecheck_cond_expect_scalar" diagnostic to [AST][RecoveryExpr] Part3: Support dependent conditional operators in C for error recovery..Oct 7 2020, 12:25 AM
hokein edited the summary of this revision. (Show Details)
hokein updated this revision to Diff 296609.Oct 7 2020, 12:26 AM
hokein marked 2 inline comments as done.

address comments

clang/test/Sema/error-dependence.c
14

oh, yeah. undefined() is not working (undefined function is implicitly treated as int () in C), but call() would work.

This revision was landed with ongoing or failed builds.Oct 7 2020, 12:34 AM
This revision was automatically updated to reflect the committed changes.