This is an archive of the discontinued LLVM Phabricator instance.

[clang][Interp] Handle PredefinedExprs
ClosedPublic

Authored by tbaeder on Apr 18 2023, 11:50 PM.

Diff Detail

Event Timeline

tbaeder created this revision.Apr 18 2023, 11:50 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 18 2023, 11:50 PM
tbaeder requested review of this revision.Apr 18 2023, 11:50 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 18 2023, 11:50 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
shafik added inline comments.May 2 2023, 10:23 AM
clang/test/AST/Interp/literals.cpp
855

Can we add tests for each predefined expressions, it does not look like there are a lot of them.

tbaeder added inline comments.May 4 2023, 12:34 AM
clang/test/AST/Interp/literals.cpp
855

Not sure that adds much value? Didn't the output of __PRETTY_FUNCTION__ change at some point in the last release even, which would make this test brittle?

aaron.ballman added inline comments.May 4 2023, 6:58 AM
clang/test/AST/Interp/literals.cpp
855

The behavior doesn't change all that often and we should test that we get the expected results from each of the expressions. It should be straightforward: https://godbolt.org/z/qveWPGWjK

tbaeder added inline comments.May 4 2023, 7:12 AM
clang/test/AST/Interp/literals.cpp
855

Oh well if you provide the test cases as well, that's of course a completely different situation :)

tbaeder updated this revision to Diff 519479.May 4 2023, 7:14 AM
aaron.ballman added inline comments.May 4 2023, 7:33 AM
clang/test/AST/Interp/literals.cpp
869

You should add coverage for the others as well:

enum IdentKind {
  Func,
  Function,
  LFunction, // Same as Function, but as wide string.
  FuncDName,
  FuncSig,
  LFuncSig, // Same as FuncSig, but as wide string
  PrettyFunction,
  /// The same as PrettyFunction, except that the
  /// 'virtual' keyword is omitted for virtual member functions.
  PrettyFunctionNoVirtual
};

(you can handle the wide string variants by making strings_match into a template.)

tbaeder added inline comments.May 4 2023, 7:59 AM
clang/test/AST/Interp/literals.cpp
869

These don't seem to exist in C++14 onwards:

array.cpp:1238:33: error: use of undeclared identifier '__FUNCDNAME__'
 1238 |     static_assert(strings_match(__FUNCDNAME__, "foo"), "");
      |                                 ^
array.cpp:1239:33: error: use of undeclared identifier '__FUNCSIG__'
 1239 |     static_assert(strings_match(__FUNCSIG__, "foo"), "");
      |                                 ^
array.cpp:1240:33: error: use of undeclared identifier '__LFUNCSIG__'
 1240 |     static_assert(strings_match(__LFUNCSIG__, "foo"), "");
      |                                 ^
array.cpp:1241:33: error: use of undeclared identifier '__LFUNCTION__'
 1241 |     static_assert(strings_match(__LFUNCTION__, "foo"), "");
      |                                 ^
array.cpp:1244:33: error: use of undeclared identifier '__PRETTY_FUNCTION_NO_VIRTUAL__'
 1244 |     static_assert(strings_match(__PRETTY_FUNCTION_NO_VIRTUAL__, "void PredefinedExprs::foo()"), "");
      |                                 ^
5 errors generated.

... but I can't use a while loop (or any kind of loop, I think?) before C++14 :)

869

e

aaron.ballman added inline comments.May 4 2023, 9:48 AM
clang/test/AST/Interp/literals.cpp
869

They exist, but you need to enable -fms-extensions for them: https://godbolt.org/z/E94snrMd9

tbaeder updated this revision to Diff 519834.May 5 2023, 6:21 AM
tbaeder updated this revision to Diff 519835.May 5 2023, 6:23 AM
aaron.ballman accepted this revision.May 5 2023, 8:46 AM

LGTM with a caution about testing the mangled signature (you can fix that up when landing though).

clang/test/AST/Interp/literals.cpp
868

I suspect this will pass for you on one ABI but fail on another due to mangling differences. You might need to specify an ABI on the RUN lines to account for that.

This revision is now accepted and ready to land.May 5 2023, 8:46 AM
shafik accepted this revision.May 5 2023, 9:36 AM

LGTM

This revision was landed with ongoing or failed builds.Jun 16 2023, 6:52 AM
This revision was automatically updated to reflect the committed changes.