[PATCH] D156453: [clang][Interp] Create only globals when initializing a global variable

Timm Bäder via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Oct 15 23:32:21 PDT 2023


tbaeder added inline comments.


================
Comment at: clang/lib/AST/Interp/ByteCodeExprGen.cpp:1213
   std::optional<PrimType> SubExprT = classify(SubExpr);
-  if (E->getStorageDuration() == SD_Static) {
+  bool IsStatic = E->getStorageDuration() == SD_Static;
+  if (GlobalDecl || IsStatic) {
----------------
aaron.ballman wrote:
> Should we be looking at the TLS kind of the extended declaration? (`CheckCompleteVariableDeclaration()` is using `VarDecl::getTLSKind() == VarDecl::TLS_Static`)
> 
> Would something along these lines work instead?
> ```
> bool EmitGlobalTemp = E->getStorageDuration() == SD_Static;
> if (!EmitGlobalTemp) {
>   if (const LifetimeExtendedTemporaryDecl *LETD = E->getLifetimeExtendedTemporaryDecl()) {
>     if (const auto *VD = dyn_cast_if_present<VarDecl>(LETD->getExtendingDecl()) {
>       EmitGlobalTemp= VD->getTLSKind() == VarDecl::TLS_Static;
>     }
>   }
> }
> ```
That code definitely works for the current `AST/Interp/` tests, but we don't have tests for thread local stuff in there right now.


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

https://reviews.llvm.org/D156453



More information about the cfe-commits mailing list