This is an archive of the discontinued LLVM Phabricator instance.

[clang][Interp] Check declarations for constexpr-ness in Load() instructions
AbandonedPublic

Authored by tbaeder on Nov 7 2022, 9:04 AM.

Details

Summary

Refering to non-constexpr variables in a constant expression is (apparently) just fine, and only problematic once we load a value.

Diff Detail

Event Timeline

tbaeder created this revision.Nov 7 2022, 9:04 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 7 2022, 9:04 AM
tbaeder requested review of this revision.Nov 7 2022, 9:04 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 7 2022, 9:04 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript

This is wrong if the (constant) initializer is for a legitimate non-constexpr variable declaration. We do a load in visitDecl().

shafik added inline comments.Nov 14 2022, 1:03 PM
clang/lib/AST/Interp/Interp.cpp
101

Is CheckConstexpr descriptive enough? Would something like CheckLoadIsValid be better?

110

Is this sufficient? How about something like this:

int *p;

int constexpr f(int &x) {
    *p=1;
    return 10;
}

Maybe I am not understanding. I think more test case would be useful.

tbaeder abandoned this revision.Jul 28 2023, 12:24 AM