https://github.com/aganea updated https://github.com/llvm/llvm-project/pull/171628
>From 29817263e2e11c468089d742fd39179e78d4ca1a Mon Sep 17 00:00:00 2001 From: Alexandre Ganea <[email protected]> Date: Tue, 9 Dec 2025 19:36:08 -0500 Subject: [PATCH 1/4] [SemaCXX] Fix static constexpr in dllimport function --- clang/lib/AST/ExprConstant.cpp | 7 +++++-- clang/test/SemaCXX/dllimport.cpp | 22 ++++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index d81496ffd74e0..e5ca6912ed566 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -2407,8 +2407,11 @@ static bool CheckLValueConstantExpression(EvalInfo &Info, SourceLocation Loc, return false; // A dllimport variable never acts like a constant, unless we're - // evaluating a value for use only in name mangling. - if (!isForManglingOnly(Kind) && Var->hasAttr<DLLImportAttr>()) + // evaluating a value for use only in name mangling, and unless we're a + // static local. For the latter case, we'd still need to evaluate the + // constant expression in case we're inside a (inlined) function. + if (!isForManglingOnly(Kind) && Var->hasAttr<DLLImportAttr>() && + !Var->isStaticLocal()) // FIXME: Diagnostic! return false; diff --git a/clang/test/SemaCXX/dllimport.cpp b/clang/test/SemaCXX/dllimport.cpp index b7a1a62b8725b..dafb12fab6888 100644 --- a/clang/test/SemaCXX/dllimport.cpp +++ b/clang/test/SemaCXX/dllimport.cpp @@ -1526,6 +1526,28 @@ template <typename T> struct __declspec(dllimport) PartiallySpecializedClassTemp template <typename T> struct ExpliciallySpecializedClassTemplate {}; template <> struct __declspec(dllimport) ExpliciallySpecializedClassTemplate<int> { void f() {} }; +// Function-local static constexpr in dllimport function (or class). +struct DLLImportFuncWithConstexprStatic { + __declspec(dllimport) static const int *func() { + // expected-warning@-1{{'dllimport' attribute ignored on inline function}} + static constexpr int value = 42; + static constexpr const int *p = &value; + static_assert(*p == 42, ""); + return p; + } + __declspec(dllimport) __forceinline static const int *funcForceInline() { + // expected-warning@-1{{'dllimport' attribute ignored on inline function}} + static constexpr int value = 42; + static constexpr const int *p = &value; + static_assert(*p == 42, ""); + return p; + } +}; +const int* (*pFunc)() = &DLLImportFuncWithConstexprStatic::func; +const int* (*pFuncForceInline)() = &DLLImportFuncWithConstexprStatic::funcForceInline; +bool UsedDLLImportFuncWithConstexprStatic() { + return pFunc() == DLLImportFuncWithConstexprStatic::func() && pFuncForceInline() == DLLImportFuncWithConstexprStatic::funcForceInline(); +} //===----------------------------------------------------------------------===// // Classes with template base classes >From 17a28e40e670961fefc303603602687667b3a53e Mon Sep 17 00:00:00 2001 From: Alexandre Ganea <[email protected]> Date: Wed, 10 Dec 2025 09:30:05 -0500 Subject: [PATCH 2/4] Fix tests --- clang/test/SemaCXX/dllimport.cpp | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/clang/test/SemaCXX/dllimport.cpp b/clang/test/SemaCXX/dllimport.cpp index dafb12fab6888..eaf217c8e2d3b 100644 --- a/clang/test/SemaCXX/dllimport.cpp +++ b/clang/test/SemaCXX/dllimport.cpp @@ -1528,26 +1528,38 @@ template <> struct __declspec(dllimport) ExpliciallySpecializedClassTemplate<int // Function-local static constexpr in dllimport function (or class). struct DLLImportFuncWithConstexprStatic { +#if defined(GNU) +// expected-warning@+2{{'dllimport' attribute ignored on inline function}} +#endif __declspec(dllimport) static const int *func() { - // expected-warning@-1{{'dllimport' attribute ignored on inline function}} static constexpr int value = 42; static constexpr const int *p = &value; static_assert(*p == 42, ""); return p; } - __declspec(dllimport) __forceinline static const int *funcForceInline() { - // expected-warning@-1{{'dllimport' attribute ignored on inline function}} +}; +const int* (*pFunc)() = &DLLImportFuncWithConstexprStatic::func; +bool UsedDLLImportFuncWithConstexprStatic() { + return pFunc() == DLLImportFuncWithConstexprStatic::func(); +} + +#if !defined(PS) +struct DLLImportInlineFuncWithConstexprStatic { +#if defined(GNU) + // expected-warning@+2{{'dllimport' attribute ignored on inline function}} +#endif + __declspec(dllimport) __forceinline static const int* funcForceInline() { static constexpr int value = 42; - static constexpr const int *p = &value; + static constexpr const int* p = &value; static_assert(*p == 42, ""); return p; } }; -const int* (*pFunc)() = &DLLImportFuncWithConstexprStatic::func; -const int* (*pFuncForceInline)() = &DLLImportFuncWithConstexprStatic::funcForceInline; -bool UsedDLLImportFuncWithConstexprStatic() { - return pFunc() == DLLImportFuncWithConstexprStatic::func() && pFuncForceInline() == DLLImportFuncWithConstexprStatic::funcForceInline(); +const int* (*pFuncForceInline)() = &DLLImportInlineFuncWithConstexprStatic::funcForceInline; +bool UsedDLLImportInlineFuncWithConstexprStatic() { + return pFuncForceInline() == DLLImportInlineFuncWithConstexprStatic::funcForceInline(); } +#endif // !PS //===----------------------------------------------------------------------===// // Classes with template base classes >From 20fbbaff1166f0e58fd8d6d4938848543a2adb96 Mon Sep 17 00:00:00 2001 From: Alexandre Ganea <[email protected]> Date: Thu, 18 Dec 2025 10:16:34 -0500 Subject: [PATCH 3/4] Change wording and remove FIXME --- clang/lib/AST/ExprConstant.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index e5ca6912ed566..1ba5a347a25a5 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -2407,12 +2407,11 @@ static bool CheckLValueConstantExpression(EvalInfo &Info, SourceLocation Loc, return false; // A dllimport variable never acts like a constant, unless we're - // evaluating a value for use only in name mangling, and unless we're a + // evaluating a value for use only in name mangling, and unless it's a // static local. For the latter case, we'd still need to evaluate the // constant expression in case we're inside a (inlined) function. if (!isForManglingOnly(Kind) && Var->hasAttr<DLLImportAttr>() && !Var->isStaticLocal()) - // FIXME: Diagnostic! return false; // In CUDA/HIP device compilation, only device side variables have >From 201ddcbc587617fd87240c29487680018bb884b6 Mon Sep 17 00:00:00 2001 From: Alexandre Ganea <[email protected]> Date: Thu, 18 Dec 2025 10:27:31 -0500 Subject: [PATCH 4/4] Simplify lit test. --- clang/test/SemaCXX/dllimport.cpp | 36 ++++++++++++++------------------ 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/clang/test/SemaCXX/dllimport.cpp b/clang/test/SemaCXX/dllimport.cpp index eaf217c8e2d3b..cecabe98cfb5c 100644 --- a/clang/test/SemaCXX/dllimport.cpp +++ b/clang/test/SemaCXX/dllimport.cpp @@ -1527,37 +1527,33 @@ template <typename T> struct ExpliciallySpecializedClassTemplate {}; template <> struct __declspec(dllimport) ExpliciallySpecializedClassTemplate<int> { void f() {} }; // Function-local static constexpr in dllimport function (or class). -struct DLLImportFuncWithConstexprStatic { #if defined(GNU) // expected-warning@+2{{'dllimport' attribute ignored on inline function}} #endif - __declspec(dllimport) static const int *func() { - static constexpr int value = 42; - static constexpr const int *p = &value; - static_assert(*p == 42, ""); - return p; - } -}; -const int* (*pFunc)() = &DLLImportFuncWithConstexprStatic::func; +__declspec(dllimport) inline const int *dLLImportFuncWithConstexprStatic() { + static constexpr int value = 42; + static constexpr const int *p = &value; + static_assert(*p == 42, ""); + return p; +} +const int* (*pFunc)() = &dLLImportFuncWithConstexprStatic; bool UsedDLLImportFuncWithConstexprStatic() { - return pFunc() == DLLImportFuncWithConstexprStatic::func(); + return pFunc() == dLLImportFuncWithConstexprStatic(); } #if !defined(PS) -struct DLLImportInlineFuncWithConstexprStatic { #if defined(GNU) // expected-warning@+2{{'dllimport' attribute ignored on inline function}} #endif - __declspec(dllimport) __forceinline static const int* funcForceInline() { - static constexpr int value = 42; - static constexpr const int* p = &value; - static_assert(*p == 42, ""); - return p; - } -}; -const int* (*pFuncForceInline)() = &DLLImportInlineFuncWithConstexprStatic::funcForceInline; +__declspec(dllimport) __forceinline const int* dLLImportInlineFuncWithConstexprStatic() { + static constexpr int value = 42; + static constexpr const int* p = &value; + static_assert(*p == 42, ""); + return p; +} +const int* (*pFuncForceInline)() = &dLLImportInlineFuncWithConstexprStatic; bool UsedDLLImportInlineFuncWithConstexprStatic() { - return pFuncForceInline() == DLLImportInlineFuncWithConstexprStatic::funcForceInline(); + return pFuncForceInline() == dLLImportInlineFuncWithConstexprStatic(); } #endif // !PS _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
