This is an archive of the discontinued LLVM Phabricator instance.

[CUDA][HIP] Do not promote constexpr var with non-constant initializer
ClosedPublic

Authored by yaxunl on Feb 11 2022, 8:34 PM.

Details

Summary

constexpr var may be initialized with address of non-const variable.
In this case the initializer is not constant in device compilation.
This has been handled for const vars but not for constexpr vars.

This patch makes handling of const var and constexpr var
consistent.

Fixes: https://github.com/llvm/llvm-project/issues/53780

Diff Detail

Event Timeline

yaxunl requested review of this revision.Feb 11 2022, 8:34 PM
yaxunl created this revision.
yaxunl edited the summary of this revision. (Show Details)Feb 11 2022, 8:39 PM
tra accepted this revision.Feb 12 2022, 12:01 AM
tra added inline comments.
clang/lib/Sema/SemaCUDA.cpp
148–153

So the idea here is that the constexpr vars that have an initializer that may not be static enough for CUDA would not get the implicit const attribute. I.e. it's tied to the change below that checks for allowed initializers.
We could use a comment about that here.

This revision is now accepted and ready to land.Feb 12 2022, 12:01 AM
yaxunl marked an inline comment as done.Feb 15 2022, 7:59 AM
yaxunl added inline comments.
clang/lib/Sema/SemaCUDA.cpp
148–153

will add a comment when committing

This revision was landed with ongoing or failed builds.Feb 15 2022, 12:17 PM
This revision was automatically updated to reflect the committed changes.
yaxunl marked an inline comment as done.
Herald added a project: Restricted Project. · View Herald TranscriptFeb 15 2022, 12:17 PM