================
@@ -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)))
+ return;
+
+ // Indices of the %select in warn_loadtime_comment_var_not_preserved.
+ enum {
----------------
AaronBallman wrote:
When you switch to `enum_select`, you can get rid of this because an
enumeration will be generated for you to use.
https://github.com/llvm/llvm-project/pull/187986
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits