This is an archive of the discontinued LLVM Phabricator instance.

[clang][AST] Constexpr evaluator should treat [[gnu::weak]] member pointer comparisons as evaluation failure
ClosedPublic

Authored by hazohelet on Apr 15 2023, 2:08 AM.

Details

Summary

This patch fixes the wrong signal from the constexpr evaluator that [[gnu::weak]] member pointer comparison is valid, while it is emitting notes on them.
I found a crashing case fixed by this change and added it as a test case.
https://godbolt.org/z/8391fGjGn

I noticed this while I was working on D146358
CC @rsmith as the original author

Diff Detail

Event Timeline

hazohelet created this revision.Apr 15 2023, 2:08 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 15 2023, 2:08 AM
hazohelet requested review of this revision.Apr 15 2023, 2:08 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 15 2023, 2:08 AM
aaron.ballman accepted this revision.Apr 17 2023, 5:36 AM

LGTM, though the changes need a release note. Do you still need someone to commit on your behalf? (Alternatively, you could consider requesting commit access: https://llvm.org/docs/DeveloperPolicy.html#obtaining-commit-access)

This revision is now accepted and ready to land.Apr 17 2023, 5:36 AM
aaron.ballman added inline comments.Apr 17 2023, 5:36 AM
clang/test/SemaCXX/crash-lambda-weak-attr.cpp
1

I don't think we need this to be in C++2b mode explicitly, right?

hazohelet updated this revision to Diff 514179.Apr 17 2023, 5:53 AM

Address comments from @aaron.ballman

  • Added release note
  • Do not specify std c++ version in test code
hazohelet marked an inline comment as done.Apr 17 2023, 5:58 AM

LGTM, though the changes need a release note. Do you still need someone to commit on your behalf? (Alternatively, you could consider requesting commit access: https://llvm.org/docs/DeveloperPolicy.html#obtaining-commit-access)

Since I don't have commit access, I would like you to commit this on my behalf. Please use "Takuya Shimizu <shimizu2486@gmail.com>" as patch attribution.
I'll try requesting commit access. Thanks!

clang/test/SemaCXX/crash-lambda-weak-attr.cpp
1

Yeah, we don't need it

This revision was landed with ongoing or failed builds.Apr 17 2023, 6:51 AM
This revision was automatically updated to reflect the committed changes.
hazohelet marked an inline comment as done.Apr 17 2023, 7:09 AM

@aaron.ballman
Sorry, this change is breaking the buildbot and because I don't have commit access I would like you to revert it for me.
It seems we need to specify the std option in the test code.

BUILD FAILED: 41435 expected passes 84 expected failures 28291 unsupported tests 1 unexpected failures (failure)

Step 5 (build-unified-tree) warnings: Build unified tree
/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/llvm/lib/CodeGen/MachineModuleInfo.cpp:73:51: warning: ‘this’ pointer is null [-Wnonnull]

Step 6 (test-build-unified-tree-check-all) failure: 41435 expected passes 84 expected failures 28291 unsupported tests 1 unexpected failures (failure)
******************** TEST 'Clang :: SemaCXX/crash-lambda-weak-attr.cpp' FAILED ********************
Script:
--
: 'RUN: at line 1';   /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/clang -cc1 -internal-isystem /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/lib/clang/17/include -nostdsysteminc -fsyntax-only -verify /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/clang/test/SemaCXX/crash-lambda-weak-attr.cpp
--
Exit Code: 1

Command Output (stderr):
--
error: 'error' diagnostics seen but not expected: 
  File /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/clang/test/SemaCXX/crash-lambda-weak-attr.cpp Line 6: a lambda expression may not appear inside of a constant expression
error: 'warning' diagnostics seen but not expected: 
  File /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/clang/test/SemaCXX/crash-lambda-weak-attr.cpp Line 6: 'static_assert' with no message is a C++17 extension
error: 'note' diagnostics expected but not seen: 
  File /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/clang/test/SemaCXX/crash-lambda-weak-attr.cpp Line 6: comparison against pointer to weak member 'Weak::weak_method' can only be performed at runtime
  File /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/clang/test/SemaCXX/crash-lambda-weak-attr.cpp Line 6: in call to
error: 'note' diagnostics seen but not expected: 
  File /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/clang/test/SemaCXX/crash-lambda-weak-attr.cpp Line 6: non-literal type '(lambda at /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/clang/test/SemaCXX/crash-lambda-weak-attr.cpp:6:15)' cannot be used in a constant expression
5 errors generated.

--

********************

@aaron.ballman
Sorry, this change is breaking the buildbot and because I don't have commit access I would like you to revert it for me.
It seems we need to specify the std option in the test code.

BUILD FAILED: 41435 expected passes 84 expected failures 28291 unsupported tests 1 unexpected failures (failure)

Step 5 (build-unified-tree) warnings: Build unified tree
/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/llvm/lib/CodeGen/MachineModuleInfo.cpp:73:51: warning: ‘this’ pointer is null [-Wnonnull]

Step 6 (test-build-unified-tree-check-all) failure: 41435 expected passes 84 expected failures 28291 unsupported tests 1 unexpected failures (failure)
******************** TEST 'Clang :: SemaCXX/crash-lambda-weak-attr.cpp' FAILED ********************
Script:
--
: 'RUN: at line 1';   /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/clang -cc1 -internal-isystem /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/lib/clang/17/include -nostdsysteminc -fsyntax-only -verify /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/clang/test/SemaCXX/crash-lambda-weak-attr.cpp
--
Exit Code: 1

Command Output (stderr):
--
error: 'error' diagnostics seen but not expected: 
  File /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/clang/test/SemaCXX/crash-lambda-weak-attr.cpp Line 6: a lambda expression may not appear inside of a constant expression
error: 'warning' diagnostics seen but not expected: 
  File /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/clang/test/SemaCXX/crash-lambda-weak-attr.cpp Line 6: 'static_assert' with no message is a C++17 extension
error: 'note' diagnostics expected but not seen: 
  File /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/clang/test/SemaCXX/crash-lambda-weak-attr.cpp Line 6: comparison against pointer to weak member 'Weak::weak_method' can only be performed at runtime
  File /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/clang/test/SemaCXX/crash-lambda-weak-attr.cpp Line 6: in call to
error: 'note' diagnostics seen but not expected: 
  File /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/clang/test/SemaCXX/crash-lambda-weak-attr.cpp Line 6: non-literal type '(lambda at /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/clang/test/SemaCXX/crash-lambda-weak-attr.cpp:6:15)' cannot be used in a constant expression
5 errors generated.

--

********************

I noticed that as well and corrected the issue in a4edc2c9fa35a763fc5f4c9cf6383096a13a9cf6.