[clang] [Clang] Apply exclude_from_explicit_instantiation to dllimport/dllexport (PR #168171)
Hans Wennborg via cfe-commits
cfe-commits at lists.llvm.org
Wed Jan 21 05:25:40 PST 2026
================
@@ -0,0 +1,181 @@
+// RUN: %clang_cc1 -triple x86_64-win32 -fms-extensions -emit-llvm -o - %s | \
+// RUN: FileCheck %s --check-prefixes=MSC --implicit-check-not=to_be_ --implicit-check-not=dllexport
+// RUN: %clang_cc1 -triple x86_64-mingw -emit-llvm -o - %s | \
+// RUN: FileCheck %s --check-prefixes=GNU --implicit-check-not=to_be_ --implicit-check-not=dllexport
+// RUN: %clang_cc1 -triple x86_64-cygwin -emit-llvm -o - %s | \
+// RUN: FileCheck %s --check-prefixes=GNU --implicit-check-not=to_be_ --implicit-check-not=dllexport
+
+// Test that __declspec(dllexport) doesn't instantiate entities marked with
+// the exclude_from_explicit_instantiation attribute unless marked as dllexport explicitly.
+
+// Silence --implicit-check-not=dllexport.
+// MSC: ModuleID = {{.*}}exclude_from_dllexport.cpp
+// MSC: source_filename = {{.*}}exclude_from_dllexport.cpp
+// GNU: ModuleID = {{.*}}exclude_from_dllexport.cpp
+// GNU: source_filename = {{.*}}exclude_from_dllexport.cpp
+
+#define EXCLUDE_FROM_EXPLICIT_INSTANTIATION __attribute__((exclude_from_explicit_instantiation))
----------------
zmodem wrote:
(nit: Since you're using a macro to get a shorter name anyway, I'd consider making it even shorter, like `EXCLUDE_ATTR`)
https://github.com/llvm/llvm-project/pull/168171
More information about the cfe-commits
mailing list