[PATCH] D117569: Constexpr not supported with __declspec(dllimport).
Zahira Ammarguellat via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Jan 20 08:00:29 PST 2022
zahiraam updated this revision to Diff 401644.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D117569/new/
https://reviews.llvm.org/D117569
Files:
clang/lib/AST/ExprConstant.cpp
clang/test/CodeGenCXX/PR19955.cpp
clang/test/CodeGenCXX/dllimport.cpp
clang/test/SemaCXX/PR19955.cpp
clang/test/SemaCXX/dllimport-constexpr.cpp
Index: clang/test/SemaCXX/dllimport-constexpr.cpp
===================================================================
--- clang/test/SemaCXX/dllimport-constexpr.cpp
+++ clang/test/SemaCXX/dllimport-constexpr.cpp
@@ -40,7 +40,6 @@
// constexpr initialization doesn't work for dllimport things.
// expected-error at +1{{must be initialized by a constant expression}}
constexpr void (*constexpr_import_func)() = &imported_func;
-// expected-error at +1{{must be initialized by a constant expression}}
constexpr int *constexpr_import_int = &imported_int;
// expected-error at +1{{must be initialized by a constant expression}}
constexpr void (Foo::*constexpr_memptr)() = &Foo::imported_method;
@@ -60,3 +59,8 @@
// expected-note at +1 {{requested here}}
StaticConstexpr<imported_func>::g_fp();
}
+
+void foo() {
+ extern int __declspec(dllimport) dll_import_int;
+ constexpr int& dll_import_constexpr_ref = dll_import_int;
+}
Index: clang/test/SemaCXX/PR19955.cpp
===================================================================
--- clang/test/SemaCXX/PR19955.cpp
+++ clang/test/SemaCXX/PR19955.cpp
@@ -2,7 +2,7 @@
// RUN: %clang_cc1 -triple i686-mingw32 -verify -std=c++11 %s
extern int __attribute__((dllimport)) var;
-constexpr int *varp = &var; // expected-error {{must be initialized by a constant expression}}
+constexpr int *varp = &var;
extern __attribute__((dllimport)) void fun();
constexpr void (*funp)(void) = &fun; // expected-error {{must be initialized by a constant expression}}
Index: clang/test/CodeGenCXX/dllimport.cpp
===================================================================
--- clang/test/CodeGenCXX/dllimport.cpp
+++ clang/test/CodeGenCXX/dllimport.cpp
@@ -98,8 +98,8 @@
USE(inlineStaticLocalsFunc);
// The address of a dllimport global cannot be used in constant initialization.
-// M32-DAG: @"?arr@?1??initializationFunc@@YAPAHXZ at 4QBQAHB" = internal global [1 x i32*] zeroinitializer
-// GNU-DAG: @_ZZ18initializationFuncvE3arr = internal global [1 x i32*] zeroinitializer
+// M32-DAG: @"?arr@?1??initializationFunc@@YAPAHXZ at 4QBQAHB" = internal constant [1 x i32*] [i32* @"?ExternGlobalDecl@@3HA"]
+// GNU-DAG: @_ZZ18initializationFuncvE3arr = internal constant [1 x i32*] [i32* @ExternGlobalDecl]
int *initializationFunc() {
static int *const arr[] = {&ExternGlobalDecl};
return arr[0];
Index: clang/test/CodeGenCXX/PR19955.cpp
===================================================================
--- clang/test/CodeGenCXX/PR19955.cpp
+++ clang/test/CodeGenCXX/PR19955.cpp
@@ -6,20 +6,16 @@
extern int *varp;
int *varp = &var;
-// CHECK-DAG: @"?varp@@3PAHA" = dso_local global i32* null
-// X64-DAG: @"?varp@@3PEAHEA" = dso_local global i32* null
+// CHECK-DAG: @"?var@@3HA" = external dllimport global i32
+// CHECK-DAG: @"?varp@@3PAHA" = dso_local global i32* @"?var@@3HA"
+// X64-DAG: @"?var@@3HA" = external dllimport global i32, align 4
+// X64-DAG: @"?varp@@3PEAHEA" = dso_local global i32* @"?var@@3HA"
extern void (*funp)();
void (*funp)() = &fun;
// CHECK-DAG: @"?funp@@3P6AXXZA" = dso_local global void ()* null
// X64-DAG: @"?funp@@3P6AXXZEA" = dso_local global void ()* null
-// CHECK-LABEL: @"??__Evarp@@YAXXZ"
-// CHECK-DAG: store i32* @"?var@@3HA", i32** @"?varp@@3PAHA"
-
-// X64-LABEL: @"??__Evarp@@YAXXZ"
-// X64-DAG: store i32* @"?var@@3HA", i32** @"?varp@@3PEAHEA"
-
// CHECK-LABEL: @"??__Efunp@@YAXXZ"()
// CHECK-DAG: store void ()* @"?fun@@YAXXZ", void ()** @"?funp@@3P6AXXZA"
Index: clang/lib/AST/ExprConstant.cpp
===================================================================
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -2211,9 +2211,12 @@
// FIXME: Diagnostic!
return false;
- // A dllimport variable never acts like a constant, unless we're
+ // A dllimport/dllexport variable never acts like a constant, unless we're
// evaluating a value for use only in name mangling.
- if (!isForManglingOnly(Kind) && Var->hasAttr<DLLImportAttr>())
+ if (Info.getLangOpts().C99 && !isForManglingOnly(Kind) &&
+ Var->hasAttr<DLLImportAttr>() ||
+ Info.getLangOpts().CPlusPlus && !isForManglingOnly(Kind) &&
+ Var->hasAttr<DLLExportAttr>())
// FIXME: Diagnostic!
return false;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D117569.401644.patch
Type: text/x-patch
Size: 4301 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220120/2fcee1e1/attachment-0001.bin>
More information about the cfe-commits
mailing list