-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[clang] Use internal linkage for c23 constexpr vars. #97846
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[clang] Use internal linkage for c23 constexpr vars. #97846
Conversation
@llvm/pr-subscribers-clang Author: Dmitriy Chestnykh (chestnykh) ChangesSet Full diff: https://github.com/llvm/llvm-project/pull/97846.diff 2 Files Affected:
diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index a07f7ad2233fe..a4e66bb78d6df 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -4428,10 +4428,15 @@ void Parser::ParseDeclarationSpecifiers(
// constexpr, consteval, constinit specifiers
case tok::kw_constexpr:
- if (getLangOpts().C23)
+ if (getLangOpts().C23) {
Diag(Tok, diag::warn_c23_compat_keyword) << Tok.getName();
- isInvalid = DS.SetConstexprSpec(ConstexprSpecKind::Constexpr, Loc,
- PrevSpec, DiagID);
+ isInvalid = DS.SetConstexprSpec(ConstexprSpecKind::Constexpr, Loc,
+ PrevSpec, DiagID);
+
+ isInvalid = DS.SetStorageClassSpec(Actions, DeclSpec::SCS_static, Loc,
+ PrevSpec, DiagID, Policy);
+ isStorageClass = true;
+ }
break;
case tok::kw_consteval:
isInvalid = DS.SetConstexprSpec(ConstexprSpecKind::Consteval, Loc,
diff --git a/clang/test/CodeGen/constexpr-c23-internal-linkage.c b/clang/test/CodeGen/constexpr-c23-internal-linkage.c
new file mode 100644
index 0000000000000..a1df206d520d0
--- /dev/null
+++ b/clang/test/CodeGen/constexpr-c23-internal-linkage.c
@@ -0,0 +1,17 @@
+/* RUN: %clang_cc1 -std=c23 -emit-llvm -o - %s | FileCheck %s
+ */
+
+constexpr int var_int = 1;
+constexpr char var_char = 'a';
+constexpr float var_float = 2.5;
+
+const int *p_i = &var_int;
+const char *p_c = &var_char;
+const float *p_f = &var_float;
+
+/*
+CHECK: @var_int = internal constant i32 1{{.*}}
+CHECK: @var_char = internal constant i8 97{{.*}}
+CHECK: @var_float = internal constant float 2.5{{.*}}
+*/
+
|
5285c93
to
20adb1c
Compare
20adb1c
to
ecf8360
Compare
clang/lib/Parse/ParseDecl.cpp
Outdated
isInvalid = DS.SetConstexprSpec(ConstexprSpecKind::Constexpr, Loc, | ||
PrevSpec, DiagID); | ||
|
||
isInvalid = DS.SetStorageClassSpec(Actions, DeclSpec::SCS_static, Loc, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure that you want to assign isInvalid
twice?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I need to rework this PR a little bit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
ecf8360
to
70a5e96
Compare
70a5e96
to
b8252ed
Compare
✅ With the latest revision this PR passed the C/C++ code formatter. |
b8252ed
to
7a3f285
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, though please let others to take a look too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM but please add a release note to clang/docs/ReleaseNotes.rst so users know about the fix as well.
Once that's added, will you need someone to land the changes on your behalf?
@AaronBallman , yes, i will need this. I'm going to add release notes right now. |
Note that only clang 19 has |
Release notes added |
94eb71d
to
317b3e2
Compare
Ooh oops, I thought we had this in Clang 18 |
Should I change anything? |
Sorry for the back-and-forth -- no new release note needed, so you can remove what you added. |
317b3e2
to
0619f78
Compare
Removed :) |
See C23 std 6.2.2p3. Fix llvm#97830
See C23 std 6.2.2p3.
Fix #97830