This is an archive of the discontinued LLVM Phabricator instance.

[clang][Interp] Reject invalid declarations and expressions
ClosedPublic

Authored by tbaeder on Nov 3 2022, 10:05 PM.

Details

Summary

I'm not really sure if this is the right thing to do. These expressions and declarations have been marked as containing errors before, so they can't work properly during constant evaluation anyway. But I don't see them being rejected in the current constant interpreter.

Diff Detail

Event Timeline

tbaeder created this revision.Nov 3 2022, 10:05 PM
Herald added a project: Restricted Project. · View Herald TranscriptNov 3 2022, 10:05 PM
tbaeder requested review of this revision.Nov 3 2022, 10:05 PM
Herald added a project: Restricted Project. · View Herald TranscriptNov 3 2022, 10:05 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript

I'd like to see some test coverage for what these changes catch that wasn't caught before. On its face, this seems reasonable in that we don't want to bother running the interpreter (further) once we know we've hit an expression, declaration, or type that's not valid.

tbaeder updated this revision to Diff 473939.Nov 8 2022, 3:20 AM

Tried to find an example for an invalid declaration but couldn't even manage to find one :|

aaron.ballman added inline comments.Nov 8 2022, 8:41 AM
clang/test/AST/Interp/functions.cpp
88–97

There should definitely be diagnostics here, right? There's a use of an undeclared identifier in each function, but also, invalid() doesn't have a return statement despite returning an int.

tbaeder updated this revision to Diff 474172.Nov 9 2022, 12:15 AM
tbaeder marked an inline comment as done.
tbaeder added inline comments.
clang/test/AST/Interp/functions.cpp
88–97

Right, I forgot to update the tests, sorry!

aaron.ballman added inline comments.Nov 9 2022, 11:14 AM
clang/lib/AST/Interp/ByteCodeExprGen.cpp
1166–1167

Because we can't find a case where we hit this, I think we should try asserting instead.

tbaeder updated this revision to Diff 474726.Nov 11 2022, 4:28 AM
tbaeder marked an inline comment as done.
tbaeder updated this revision to Diff 474727.Nov 11 2022, 4:30 AM
tbaeder marked an inline comment as done.
This revision is now accepted and ready to land.Nov 29 2022, 10:19 AM
This revision was landed with ongoing or failed builds.Jan 25 2023, 3:53 AM
This revision was automatically updated to reflect the committed changes.