[PATCH] D149834: [clang][Interp] Fix ignoring TypeTraitExprs

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon May 8 05:10:21 PDT 2023


aaron.ballman added inline comments.


================
Comment at: clang/test/AST/Interp/literals.cpp:875
     1 ? 0 : 1;
+    sizeof(A);
+    alignof(A);
----------------
tbaeder wrote:
> aaron.ballman wrote:
> > Let's make sure we still reject this:
> > ```
> > constexpr int oh_my() {
> >   int x = 0;
> >   sizeof(int[x++]); // This would usually be evaluated because VLAs are terrible
> >   return x;
> > }
> > ```
> > https://godbolt.org/z/E3jx6co46
> Hm, no, doesn't get rejected:
> ```
> array.cpp:1240:3: warning: expression result unused [-Wunused-value]
>  1240 |   sizeof(int[x++]); // This would usually be evaluated because VLAs are terrible
>       |   ^~~~~~~~~~~~~~~~
> array.cpp:1243:15: error: static assertion failed due to requirement 'oh_my() == 1'
>  1243 | static_assert(oh_my() == 1);
>       |               ^~~~~~~~~~~~
> array.cpp:1243:23: note: expression evaluates to '0 == 1'
>  1243 | static_assert(oh_my() == 1);
>       |               ~~~~~~~~^~~~
> ```
It looks to me like we're not modelling the side effects properly (we would return `1` if we were, so the `static_assert` would have passed), which might explain why we're failing to reject the code.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149834/new/

https://reviews.llvm.org/D149834



More information about the cfe-commits mailing list