================
@@ -15460,6 +15461,108 @@ void Sema::CheckThreadLocalForLargeAlignment(VarDecl 
*VD) {
   }
 }
 
+/// Process a variable definition whose mangled name may be listed in
+/// '-mloadtime-comment-vars=': attach an implicit attribute to supported
+/// string variables so CodeGen preserves them as loadtime identifying
+/// strings, and warn when a named variable cannot be preserved.
+static void processForLoadTimeCommentVar(Sema &S, VarDecl *VD) {
+  // Declarations that cannot be name-matched are silently skipped: an
+  // automatic variable has no symbol of its own, and neither does a template
+  // pattern (only its specializations do, and those are processed
+  // separately). Only definitions are considered.
+  if (VD->hasLocalStorage())
+    return;
+  if (VD->isTemplated())
+    return;
+  if (VD->isThisDeclarationADefinition(S.Context) != VarDecl::Definition)
+    return;
+
+  // Only plain `char` pointers/arrays with an initializer are supported; a
+  // matched variable of any other form (int, struct, wide or explicitly
+  // signed/unsigned character types, no initializer, ...) is silently
+  // ignored.
+  QualType Ty = VD->getType();
+  const PointerType *PT = Ty->getAsCanonical<PointerType>();
+  const ArrayType *AT = PT ? nullptr : S.Context.getAsArrayType(Ty);
+  QualType Pointee = PT   ? PT->getPointeeType()
+                     : AT ? AT->getElementType()
+                          : QualType();
+  if (Pointee.isNull() ||
+      !S.Context.hasSameUnqualifiedType(Pointee, S.Context.CharTy) ||
+      !VD->hasInit())
+    return;
+
+  // Names are matched against the mangled name, as it appears in the object
+  // file. For plain C file-scope variables this is the source identifier; for
+  // C++ variables it is the mangled symbol.
+  if (!S.getLangOpts().isLoadTimeCommentVar(
+          ASTNameGenerator(S.Context).getName(VD)))
----------------
AaronBallman wrote:

This causes a dynamic allocation and deallocation on every call and I think we 
call this for every declaration in the TU. I wonder what kind of compile time 
hit this will have. It might make sense to early return if no load time comment 
option is passed so the only people paying the price are the ones using the 
feature.

https://github.com/llvm/llvm-project/pull/187986
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to