This is an archive of the discontinued LLVM Phabricator instance.

[clang] Don't emit redundant warnings for 'return;'
ClosedPublic

Authored by Quuxplusone on Feb 6 2022, 1:47 PM.

Details

Summary

...when the function declaration's return type is already invalid for
some reason. This is relevant to https://github.com/llvm/llvm-project/issues/49188
because another way that the declaration's return type could become
invalid is that it might be C auto where C<void> is false.

(This doesn't actually fix 49188, but it eliminates a surprising redundant warning in the fix I tried, and also eliminates redundant warnings in the test cases depicted here.)

Diff Detail

Event Timeline

Quuxplusone requested review of this revision.Feb 6 2022, 1:47 PM
Quuxplusone created this revision.
sammccall accepted this revision.Feb 7 2022, 12:00 AM

Makes sense to me, thanks!

clang/lib/Sema/SemaStmt.cpp
4102

The comment in the test helped me understand this case better. I'd find "(The intended return type may have been void)" a useful hint here.

This revision is now accepted and ready to land.Feb 7 2022, 12:00 AM
Quuxplusone planned changes to this revision.Feb 7 2022, 8:04 AM

Unfortunately some existing tests fail: https://reviews.llvm.org/harbormaster/unit/view/2282838/
I haven't yet figured out why consteval functions are considered to have FD->isInvalidDecl(). There's also an Objective-C failure that I assume indicates sometimes (when this is a method not a function) we have no FD at all. I'd need to solve both of these problems (the former being the difficult one) before I can make progress here.

Unfortunately some existing tests fail: https://reviews.llvm.org/harbormaster/unit/view/2282838/
I haven't yet figured out why consteval functions are considered to have FD->isInvalidDecl(). There's also an Objective-C failure that I assume indicates sometimes (when this is a method not a function) we have no FD at all. I'd need to solve both of these problems (the former being the difficult one) before I can make progress here.

The example seems to be invalid even apart from the missing return value. (I assume on purpose).

There's a constexpr version and a consteval version of the same function there. It looks like the call to MergeCXXFunctionDecl reports that the merge is invalid, which will result in FD ending up invalid.

Note that if you fix those errors (return {}) you hit the error consteval declaration of 'operator+' follows constexpr declaration (err_constexpr_redecl_mismatch) which comes from MergeCXXFunctionDecl.

Unfortunately some existing tests fail: https://reviews.llvm.org/harbormaster/unit/view/2282838/
I haven't yet figured out why consteval functions are considered to have FD->isInvalidDecl(). There's also an Objective-C failure that I assume indicates sometimes (when this is a method not a function) we have no FD at all. I'd need to solve both of these problems (the former being the difficult one) before I can make progress here.

The example seems to be invalid even apart from the missing return value. (I assume on purpose).

Ohhh, wow, I had missed that. In that case, I'm shocked that Clang isn't giving any more serious error message: shouldn't it be considered invalid, and diagnosed as an error, to have a constexpr definition followed by a consteval redefinition?
https://godbolt.org/z/vKjGvEor8
However, I think the pattern of operators used (++--*/*/) indicates that the original author made a typo there, and it should always have been +-+-*/*/. So I'll feel good about changing that test.

Unfortunately some existing tests fail: https://reviews.llvm.org/harbormaster/unit/view/2282838/
I haven't yet figured out why consteval functions are considered to have FD->isInvalidDecl(). There's also an Objective-C failure that I assume indicates sometimes (when this is a method not a function) we have no FD at all. I'd need to solve both of these problems (the former being the difficult one) before I can make progress here.

The example seems to be invalid even apart from the missing return value. (I assume on purpose).

Ohhh, wow, I had missed that. In that case, I'm shocked that Clang isn't giving any more serious error message: shouldn't it be considered invalid, and diagnosed as an error, to have a constexpr definition followed by a consteval redefinition?
https://godbolt.org/z/vKjGvEor8
However, I think the pattern of operators used (++--*/*/) indicates that the original author made a typo there, and it should always have been +-+-*/*/. So I'll feel good about changing that test.

It is diagnosed as an error (err_constexpr_redecl_mismatch), but in this case the error for the missing return value ends up suppressing it somehow.

I'm not sure exactly what the intent of this test was :-(

Fix the two failing test cases (in one case by fixing what seems to have been a typo in the test).

This revision is now accepted and ready to land.Feb 7 2022, 1:12 PM

Fix the two failing test cases (in one case by fixing what seems to have been a typo in the test).

I think you forgot to upload these changes.

Oops. I'd put [clang] [test] Fix an apparent typo in SemaCXX/consteval-return-void.cpp in a separate commit for hygiene purposes, and forgot to include that commit in this diff. Updated.

sammccall accepted this revision.Feb 8 2022, 8:25 AM