This is an archive of the discontinued LLVM Phabricator instance.

rewording note note_constexpr_invalid_cast
ClosedPublic

Authored by Codesbyusman on Sep 2 2022, 3:11 AM.

Details

Summary

The diagnostics here are correct, but the note is really silly. It talks about reinterpret_cast in C code. So rewording it for c mode by using more select.

int array[(long)(char *)0];

previous note:

cast that performs the conversions of a reinterpret_cast is not allowed in a constant expression

reworded note:

this conversion is not allowed in a constant expression

Diff Detail

Event Timeline

Codesbyusman created this revision.Sep 2 2022, 3:11 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 2 2022, 3:11 AM
Codesbyusman requested review of this revision.Sep 2 2022, 3:11 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 2 2022, 3:11 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
Codesbyusman edited the summary of this revision. (Show Details)Sep 2 2022, 3:15 AM
aaron.ballman requested changes to this revision.Sep 2 2022, 5:49 AM

Thanks for the cleanup here! Precommit CI pointed out places where test coverage found issues, and you're missing new test coverage for the change. If you run the failing constant-expression-cxx11.cpp test in an asserts build, it'll help you to narrow down where the issue is. I think the problem is that there are more instances of issuing diag::note_constexpr_invalid_cast with the trailing argument 2 that weren't updated to pass the additional trailing argument you added.

This revision now requires changes to proceed.Sep 2 2022, 5:49 AM
shafik added a subscriber: shafik.Sep 2 2022, 10:50 AM

I can't find any C tests that exercise this diagnostic. We should add a C test as well to confirm that we obtain the diagnostic we expect in a C context.

Codesbyusman edited the summary of this revision. (Show Details)

updated the test work for the patch

Hi,
I am not getting why Sema/cast.c is failing here. While all test are running fine on my system?

updating one time again, to again run test as no failed test on my system.

aaron.ballman added inline comments.Sep 9 2022, 10:42 AM
clang/test/Sema/cast.c
2

Instead of adding this RUN line, I think you can modify the previous RUN line to add -Wvla, and skip the #ifdef entirely.

The reason this test is passing for you locally but failing on the server is because this RUN line is missing a triple and there are parts of the test which are sensitive to the target architecture.

Codesbyusman added inline comments.Sep 9 2022, 11:03 AM
clang/test/Sema/cast.c
2

Instead of adding this RUN line, I think you can modify the previous RUN line to add -Wvla, and skip the #ifdef entirely.

The reason this test is passing for you locally but failing on the server is because this RUN line is missing a triple and there are parts of the test which are sensitive to the target architecture.

ok, Thank you

updating test

aaron.ballman added inline comments.Sep 9 2022, 11:35 AM
clang/lib/AST/ExprConstant.cpp
7475–7481

You shouldn't pass the extra argument to either of these -- 0 maps to reinterpret_cast and 1 maps to dynamic_cast in the %select{}, neither of which use a %1 placeholder.

8893

This one should also drop the extra streamed argument for similar reasons as above.

clang/test/Sema/cast.c
1–6

I realized that we don't need to pass -Wvla at all, the other warning and note are on by default.

clang/test/SemaCXX/constant-expression-cxx11.cpp
3

We don't need to use -Wvla to see the diagnostic change, and this will fix the test failures from the other RUN lines not generating the same warning about use of a VLA.

14–16
Codesbyusman marked 4 inline comments as done.Sep 9 2022, 12:35 PM
Codesbyusman added inline comments.
clang/test/Sema/cast.c
1–6

I realized that we don't need to pass -Wvla at all, the other warning and note are on by default.

But the note is not enabled without it, without it i got this error:
that I am expecting but there is no diagnostic for it

error: 'note' diagnostics expected but not seen:

File /home/kali/llvm-project/clang/test/Sema/cast.c Line 3: this conversion is not allowed in a constant expression

1 error generated.

aaron.ballman added inline comments.Sep 9 2022, 12:39 PM
clang/test/Sema/cast.c
1–6

Oh! I was thinking that the note was associated with the constant folding warning, not the "you used a VLA" warning, but you're absolutely right! Ignore the suggestion and keep passing -Wvla here.

clang/test/SemaCXX/constant-expression-cxx11.cpp
3

And this is a better suggestion here.

14–16
Codesbyusman marked an inline comment as done.Sep 9 2022, 12:43 PM
Codesbyusman added inline comments.
clang/test/SemaCXX/constant-expression-cxx11.cpp
3

Sorry I forget to mention removing here in cpp case -Wvla was working so go with vla or without it?

aaron.ballman added inline comments.Sep 9 2022, 12:44 PM
clang/test/SemaCXX/constant-expression-cxx11.cpp
3

Let's go with the vla here as well.

updated, I am not getting why this is happening but in the .cpp test file without Wvla all is working and is detecting by default as you are saying but when I use vla-warning/note it gives me error that "warning seen but not expected"

aaron.ballman accepted this revision.Sep 10 2022, 5:34 AM

updated, I am not getting why this is happening but in the .cpp test file without Wvla all is working and is detecting by default as you are saying but when I use vla-warning/note it gives me error that "warning seen but not expected"

It's because we're passing -pedantic on all three RUN lines; because the file is a C++ source file, we issue the pedantic "you're using an extension" warning: https://godbolt.org/z/a8nv6dhE5 so the -Wvla is redundant after all (sorry for not catching that sooner).

clang/lib/AST/ExprConstant.cpp
7475–7476
This revision is now accepted and ready to land.Sep 10 2022, 5:34 AM

updated, I am not getting why this is happening but in the .cpp test file without Wvla all is working and is detecting by default as you are saying but when I use vla-warning/note it gives me error that "warning seen but not expected"

It's because we're passing -pedantic on all three RUN lines; because the file is a C++ source file, we issue the pedantic "you're using an extension" warning: https://godbolt.org/z/a8nv6dhE5 so the -Wvla is redundant after all (sorry for not catching that sooner).

Thank you for explanation.

updating with the suggested changes.

This revision was automatically updated to reflect the committed changes.