Skip to content

Commit 20adb1c

Browse files
committed
[clang] Use internal linkage for c23 constexpr vars.
Set `static` storage class specifier for such decls to have `internal` linkage in produced IR and then in the object file. Fix #97830
1 parent 3bb2563 commit 20adb1c

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

clang/lib/Parse/ParseDecl.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4428,10 +4428,15 @@ void Parser::ParseDeclarationSpecifiers(
44284428

44294429
// constexpr, consteval, constinit specifiers
44304430
case tok::kw_constexpr:
4431-
if (getLangOpts().C23)
4431+
if (getLangOpts().C23) {
44324432
Diag(Tok, diag::warn_c23_compat_keyword) << Tok.getName();
4433-
isInvalid = DS.SetConstexprSpec(ConstexprSpecKind::Constexpr, Loc,
4434-
PrevSpec, DiagID);
4433+
isInvalid = DS.SetConstexprSpec(ConstexprSpecKind::Constexpr, Loc,
4434+
PrevSpec, DiagID);
4435+
4436+
isInvalid = DS.SetStorageClassSpec(Actions, DeclSpec::SCS_static, Loc,
4437+
PrevSpec, DiagID, Policy);
4438+
isStorageClass = true;
4439+
}
44354440
break;
44364441
case tok::kw_consteval:
44374442
isInvalid = DS.SetConstexprSpec(ConstexprSpecKind::Consteval, Loc,
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
* RUN: %clang_cc1 -std=c23 -emit-llvm -o - %s | FileCheck %s
3+
*/
4+
5+
constexpr int var_int = 1;
6+
constexpr char var_char = 'a';
7+
constexpr float var_float = 2.5;
8+
9+
const int *p_i = &var_int;
10+
const char *p_c = &var_char;
11+
const float *p_f = &var_float;
12+
13+
/*
14+
CHECK: @var_int = internal constant i32 1{{.*}}
15+
CHECK: @var_char = internal constant i8 97{{.*}}
16+
CHECK: @var_float = internal constant float 2.5{{.*}}
17+
*/
18+

0 commit comments

Comments
 (0)