[clang] [llvm] [Clang][AIX] Add -mloadtime-comment-vars flag to preserve identifying variables (PR #187986)

Hubert Tong via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 5 15:51:55 PDT 2026


================
@@ -0,0 +1,128 @@
+// Verify that -mloadtime-comment-vars= diagnoses C++ variables it cannot
+// preserve.
+//
+// Three scenarios are covered, each with its own set of named variables and
+// its own -verify prefix:
+//
+//   storage — storage duration: thread_local variables and a name-matched
+//             function-local static are diagnosed; a namespace-scope
+//             variable is accepted without diagnostic. Also covers a
+//             name-matched variable of an unsupported (wide character)
+//             type, which is diagnosed.
+//   init    — initializer form: dynamically initialized pointers, and
+//             constant initializers that are not a direct string literal
+//             (pointer to another global, consteval call, user-defined
+//             literal), are diagnosed. (-std=c++20 for consteval.)
+//   kinds   — unsupported declaration kinds: name-matched static data
+//             members (out-of-line, in-class inline, instantiated from a
+//             class template), variable template specializations
+//             (explicit and implicit), and namespace-scope inline variables
+//             are diagnosed.
+
+// RUN: %clang_cc1 -std=c++20 -triple powerpc64-ibm-aix \
+// RUN:   -mloadtime-comment-vars=keep,_ZN1N2tlE,_ZL3stl,_ZN1A2tmE,_ZZ1fvE2fn,_ZL4wstr \
+// RUN:   -fsyntax-only -verify=storage %s
+
+// RUN: %clang_cc1 -std=c++20 -triple powerpc64-ibm-aix \
+// RUN:   -mloadtime-comment-vars=p_ok,arr_ok,p_dyn,p_ind,p_ce,p_udl \
+// RUN:   -fsyntax-only -verify=init %s
+
+// RUN: %clang_cc1 -std=c++20 -triple powerpc64-ibm-aix \
+// RUN:   -mloadtime-comment-vars=_ZN2B23sidE,_ZN2B34isidE,_Z2vtIcE,_Z2vtIiE,_ZN2SCIiE1mE,_ZN1M2ivE \
+// RUN:   -fsyntax-only -verify=kinds %s
+
+// ---- storage: storage-duration cases ----------------------------------------
+
+// A namespace-scope variable with static storage duration is supported; no
+// diagnostic is expected.
+const char *keep = "@(#) keep";
+
+namespace N {
+// A thread_local variable has thread storage duration rather than static,
+// so it is diagnosed.
+thread_local const char *tl = "@(#) tl"; // storage-warning {{'tl' named in '-mloadtime-comment-vars=' does not have static storage duration and will not be preserved}}
+} // namespace N
+
+// 'static' here changes linkage only; storage duration is still thread.
+static thread_local const char *stl = "@(#) stl"; // storage-warning {{'stl' named in '-mloadtime-comment-vars=' does not have static storage duration and will not be preserved}}
+
+struct A {
+  static thread_local const char *tm;
+};
+// The static-data-member reason outranks the storage-duration one.
+thread_local const char *A::tm = "@(#) tm"; // storage-warning {{'tm' named in '-mloadtime-comment-vars=' is a static data member and will not be preserved}}
+
+// Function-local static: a name match demonstrates intent, so it is
+// diagnosed rather than silently ignored.
+void f() { static const char *fn = "@(#) fn"; (void)fn; } // storage-warning {{'fn' named in '-mloadtime-comment-vars=' is a function-local variable and will not be preserved}}
+
+// A name match on a variable of an unsupported type is diagnosed as well.
+static wchar_t wstr[] = L"@(#) w"; // storage-warning {{'wstr' named in '-mloadtime-comment-vars=' does not have a plain char pointer or array type and will not be preserved}}
+
----------------
hubert-reinterpretcast wrote:

Why are these "storage" tests? These would fit better as "type/kind" tests.

https://github.com/llvm/llvm-project/pull/187986


More information about the cfe-commits mailing list