Handle DeclRefExprs pointing to EnumConstantDecls.
Details
Diff Detail
Unit Tests
Event Timeline
I can't come up with a way to get a reference to one of these, so the logic in the rest of the DeclRefExpr handling is a little MORE awkward looking now. I think I'm OK with this, but I want to give a few other folks a chance to look.
Ah right, I could to through that code path as well and not immediately return. I actually tested references but the AST expresses that through a MaterializeTemporaryExpr, which don't work yet.
Yup, that needs one of the other open patches.
clang/lib/AST/Interp/ByteCodeExprGen.cpp | ||
---|---|---|
866 | If I check out IntExprEvaluator::CheckReferenceDecl(...) it is checking the sign and width match between the expression and the EnumConstantDecl. I am guessing we need to do that here as well? |
clang/lib/AST/Interp/ByteCodeExprGen.cpp | ||
---|---|---|
866 | I'm having a hard time trying to cause that code to trigger. e.g. in enum Foo : unsigned int { A = -1, }; static_assert(A == -1); Both with the new and current interpreter, I get a`-Wc++11-narrowing` error by default, and the assertion works if I pass -Wno-c++11-narrowing. |
clang/lib/AST/Interp/ByteCodeExprGen.cpp | ||
---|---|---|
866 | Reading the code again, this seems to just compute a new value to not trigger assertions in Success(). Since those assertions don't exist in the new interpreter, the special casing shouldn't be needed. |
Anything still missing here? (CI failure is because one of the other patches is missing)
LGTM
clang/test/AST/Interp/enums.cpp | ||
---|---|---|
26 | Maybe some edge case values for enumerators like __INT_MAX__ *2U +1U (UINT_MAX) and enum E { // warning: enumeration values exceed range of largest integer [-Wenum-too-large] E1 = -__LONG_MAX__ -1L, E2 = __LONG_MAX__ *2UL+1UL }; |
clang/test/AST/Interp/enums.cpp | ||
---|---|---|
26 | Hm, looks like that test broke one of the windows builders: https://lab.llvm.org/buildbot/#/builders/123/builds/13424 - are enums larger by default on Windows? What do you suggest to fix the test? |
clang/test/AST/Interp/enums.cpp | ||
---|---|---|
26 | If we're trying to be compatible with MSVC, we use their rules for picking the underlying type of an enumeration is which not fixed. One way to handle this is to add more RUN lines with explicit triples, but I think we lose too much interesting coverage that way. I'd probably use a #ifndef _MSC_VER block to control the expected diagnostics with a comment as to why the diagnostic is not expected on Windows. |
clang/test/AST/Interp/enums.cpp | ||
---|---|---|
26 | The second builder that broke was a hexagon builder: https://lab.llvm.org/buildbot/#/builders/38/builds/6231 - this would still fail with the _MSC_VER change, right? |
clang/test/AST/Interp/enums.cpp | ||
---|---|---|
26 | Nope, drat. I would recommend breaking that specific test out into a separate file where we can add various RUN lines with triples, and the rest of the test can remain targetless. |
clang/test/AST/Interp/enums.cpp | ||
---|---|---|
26 | Shame, but alright. So, what triples should I test? :) |
clang/test/AST/Interp/enums.cpp | ||
---|---|---|
26 | The ones from the failing bots, and I'd say maybe x86_64-pc-linux and i686-pc-linux would be reasonable. |
clang/test/AST/Interp/enums.cpp | ||
---|---|---|
26 | Heh, the warning doesn't happen with the i686 triple either (with the old interpreter). Is that expected? |
clang/test/AST/Interp/enums.cpp | ||
---|---|---|
26 | Yeah, that sounds about like what I'd expect. |
If I check out IntExprEvaluator::CheckReferenceDecl(...) it is checking the sign and width match between the expression and the EnumConstantDecl. I am guessing we need to do that here as well?