[PATCH] D137107: Allow MS extension: support of constexpr with __declspec(dllimport).
Zahira Ammarguellat via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Nov 7 08:44:38 PST 2022
zahiraam updated this revision to Diff 473693.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D137107/new/
https://reviews.llvm.org/D137107
Files:
clang/lib/Sema/SemaDecl.cpp
clang/test/CodeGenCXX/PR19955.cpp
clang/test/CodeGenCXX/dllimport.cpp
clang/test/SemaCXX/constant-expression-cxx11.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
@@ -60,3 +60,12 @@
// expected-note at +1 {{requested here}}
StaticConstexpr<imported_func>::g_fp();
}
+
+extern int __declspec(dllimport) val;
+// expected-error at +1{{constexpr variable 'val_ref' must be initialized by a constant expression}}
+constexpr int& val_ref = val;
+
+void AssignDllImportToConst () {
+ extern int _declspec(dllimport) val;
+ constexpr int& val_ref = val;
+}
Index: clang/test/SemaCXX/constant-expression-cxx11.cpp
===================================================================
--- clang/test/SemaCXX/constant-expression-cxx11.cpp
+++ clang/test/SemaCXX/constant-expression-cxx11.cpp
@@ -1594,8 +1594,8 @@
void f(int k) { // expected-note {{here}}
int arr[k]; // expected-warning {{C99}} expected-note {{function parameter 'k'}}
- constexpr int n = 1 +
- sizeof(arr) // expected-error {{constant expression}}
+ constexpr int n = 1 + // expected-error{{constexpr variable 'n' must be initialized by a constant expression}}
+ sizeof(arr)
* 3;
}
}
Index: clang/test/CodeGenCXX/dllimport.cpp
===================================================================
--- clang/test/CodeGenCXX/dllimport.cpp
+++ clang/test/CodeGenCXX/dllimport.cpp
@@ -769,6 +769,7 @@
USEVAR(D<42>::y);
// MSC-DAG: @"?x@?$D@$0CK@@PR19933@@2HA" = external dllimport global i32
// MSC-DAG: @"?y@?$D@$0CK@@PR19933@@2HA" = external dllimport global i32
+ // MSC-DAG: @"?val@@3HA" = external dllimport global i32
}
namespace PR21355 {
@@ -1026,3 +1027,11 @@
void baz() { U<int> u; u.foo(); } // No diagnostic.
}
+
+void assigndllimport () {
+ // MSC-DAG: define dso_local void @"?assigndllimport@@YAXXZ"()
+ // MSC-DAG: %[[VAL_REF:.*]] = alloca ptr
+ // MSC-DAG-NEXT: store ptr @"?val@@3HA", ptr %[[VAL_REF]]
+ extern int _declspec(dllimport) val;
+ constexpr int& val_ref = val;
+}
Index: clang/test/CodeGenCXX/PR19955.cpp
===================================================================
--- clang/test/CodeGenCXX/PR19955.cpp
+++ clang/test/CodeGenCXX/PR19955.cpp
@@ -14,9 +14,6 @@
// CHECK-DAG: @"?funp@@3P6AXXZA" = dso_local global ptr null
// X64-DAG: @"?funp@@3P6AXXZEA" = dso_local global ptr null
-// CHECK-LABEL: @"??__Evarp@@YAXXZ"
-// CHECK-DAG: store ptr @"?var@@3HA", ptr @"?varp@@3PAHA"
-
// X64-LABEL: @"??__Evarp@@YAXXZ"
// X64-DAG: store ptr @"?var@@3HA", ptr @"?varp@@3PEAHEA"
Index: clang/lib/Sema/SemaDecl.cpp
===================================================================
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -13890,6 +13890,9 @@
// FIXME: Consider replacing the initializer with a ConstantExpr.
} else if (var->isConstexpr()) {
SourceLocation DiagLoc = var->getLocation();
+ if (IsGlobal || (!IsGlobal && Notes.size() != 0))
+ Diag(DiagLoc, diag::err_constexpr_var_requires_const_init)
+ << var << Init->getSourceRange();
// If the note doesn't add any useful information other than a source
// location, fold it into the primary diagnostic.
if (Notes.size() == 1 && Notes[0].second.getDiagID() ==
@@ -13897,8 +13900,6 @@
DiagLoc = Notes[0].first;
Notes.clear();
}
- Diag(DiagLoc, diag::err_constexpr_var_requires_const_init)
- << var << Init->getSourceRange();
for (unsigned I = 0, N = Notes.size(); I != N; ++I)
Diag(Notes[I].first, Notes[I].second);
} else if (GlobalStorage && var->hasAttr<ConstInitAttr>()) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D137107.473693.patch
Type: text/x-patch
Size: 3684 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221107/a7b98367/attachment-0001.bin>
More information about the cfe-commits
mailing list