Skip to content

Commit 85d4d03

Browse files
author
z1.cciauto
committed
merge main into amd-staging
2 parents 49ecd55 + fa45bf4 commit 85d4d03

29 files changed

+1346
-71
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ Bug Fixes to C++ Support
294294
direct-list-initialized from an array is corrected to direct-initialization.
295295
- Clang no longer crashes when a coroutine is declared ``[[noreturn]]``. (#GH127327)
296296
- Clang now uses the parameter location for abbreviated function templates in ``extern "C"``. (#GH46386)
297+
- Clang now correctly parses ``if constexpr`` expressions in immediate function context. (#GH123524)
297298

298299
Improvements to C++ diagnostics
299300
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

clang/include/clang/Basic/LangOptions.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ VALUE_LANGOPT(FuchsiaAPILevel, 32, 0, "Fuchsia API level")
530530
// on large _BitInts.
531531
BENIGN_VALUE_LANGOPT(MaxBitIntWidth, 32, 128, "Maximum width of a _BitInt")
532532

533-
COMPATIBLE_LANGOPT(IncrementalExtensions, 1, 0, " True if we want to process statements"
533+
COMPATIBLE_LANGOPT(IncrementalExtensions, 1, 0, "True if we want to process statements "
534534
"on the global scope, ignore EOF token and continue later on (thus "
535535
"avoid tearing the Lexer and etc. down). Controlled by "
536536
"-fincremental-extensions.")

clang/include/clang/Driver/Options.td

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -878,7 +878,7 @@ def Wa_COMMA : CommaJoined<["-"], "Wa,">,
878878
MetaVarName<"<arg>">;
879879
def warning_suppression_mappings_EQ : Joined<["--"],
880880
"warning-suppression-mappings=">, Group<Diag_Group>,
881-
HelpText<"File containing diagnostic suppresion mappings. See user manual "
881+
HelpText<"File containing diagnostic suppression mappings. See user manual "
882882
"for file format.">, Visibility<[ClangOption, CC1Option]>;
883883
def Wall : Flag<["-"], "Wall">, Group<W_Group>, Flags<[HelpHidden]>,
884884
Visibility<[ClangOption, CC1Option, FlangOption]>;
@@ -943,7 +943,7 @@ def Xarch__
943943
target matches the specified architecture. This can be used with the target
944944
CPU, triple architecture, or offloading host and device. It is most useful
945945
for separating behavior undesirable on one of the targets when combining many
946-
compilation jobs, as is commong with offloading. For example, -Xarch_x86_64,
946+
compilation jobs, as is common with offloading. For example, -Xarch_x86_64,
947947
-Xarch_gfx90a, and -Xarch_device are all valid selectors. -Xarch_device will
948948
forward the argument to the offloading device while -Xarch_host will target
949949
the host system, which can be used to suppress incompatible GPU arguments.}]>,
@@ -1683,7 +1683,7 @@ def fsample_profile_use_profi : Flag<["-"], "fsample-profile-use-profi">,
16831683
HelpText<"Use profi to infer block and edge counts">,
16841684
DocBrief<[{Infer block and edge counts. If the profiles have errors or missing
16851685
blocks caused by sampling, profile inference (profi) can convert
1686-
basic block counts to branch probabilites to fix them by extended
1686+
basic block counts to branch probabilities to fix them by extended
16871687
and re-engineered classic MCMF (min-cost max-flow) approach.}]>;
16881688
def fno_profile_sample_accurate : Flag<["-"], "fno-profile-sample-accurate">, Group<f_Group>;
16891689
def fno_auto_profile : Flag<["-"], "fno-auto-profile">, Group<f_Group>,

clang/lib/AST/ExprConstant.cpp

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2419,6 +2419,16 @@ static bool CheckLValueConstantExpression(EvalInfo &Info, SourceLocation Loc,
24192419
LVal.getLValueCallIndex() == 0) &&
24202420
"have call index for global lvalue");
24212421

2422+
if (LVal.allowConstexprUnknown()) {
2423+
if (BaseVD) {
2424+
Info.FFDiag(Loc, diag::note_constexpr_var_init_non_constant, 1) << BaseVD;
2425+
NoteLValueLocation(Info, Base);
2426+
} else {
2427+
Info.FFDiag(Loc);
2428+
}
2429+
return false;
2430+
}
2431+
24222432
if (Base.is<DynamicAllocLValue>()) {
24232433
Info.FFDiag(Loc, diag::note_constexpr_dynamic_alloc)
24242434
<< IsReferenceType << !Designator.Entries.empty();
@@ -3597,7 +3607,8 @@ static bool evaluateVarDeclInit(EvalInfo &Info, const Expr *E,
35973607
// expressions here; doing so would regress diagnostics for things like
35983608
// reading from a volatile constexpr variable.
35993609
if ((Info.getLangOpts().CPlusPlus && !VD->hasConstantInitialization() &&
3600-
VD->mightBeUsableInConstantExpressions(Info.Ctx)) ||
3610+
VD->mightBeUsableInConstantExpressions(Info.Ctx) &&
3611+
!AllowConstexprUnknown) ||
36013612
((Info.getLangOpts().CPlusPlus || Info.getLangOpts().OpenCL) &&
36023613
!Info.getLangOpts().CPlusPlus11 && !VD->hasICEInitializer(Info.Ctx))) {
36033614
if (Init) {
@@ -16993,18 +17004,6 @@ bool Expr::EvaluateAsInitializer(APValue &Value, const ASTContext &Ctx,
1699317004

1699417005
if (!Info.discardCleanups())
1699517006
llvm_unreachable("Unhandled cleanup; missing full expression marker?");
16996-
16997-
if (Value.allowConstexprUnknown()) {
16998-
assert(Value.isLValue() && "Expected an lvalue");
16999-
auto Base = Value.getLValueBase();
17000-
const auto *NewVD = Base.dyn_cast<const ValueDecl *>();
17001-
if (!NewVD)
17002-
NewVD = VD;
17003-
Info.FFDiag(getExprLoc(), diag::note_constexpr_var_init_non_constant, 1)
17004-
<< NewVD;
17005-
NoteLValueLocation(Info, Base);
17006-
return false;
17007-
}
1700817007
}
1700917008

1701017009
return CheckConstantExpression(Info, DeclLoc, DeclTy, Value,

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2078,9 +2078,10 @@ StringRef CodeGenModule::getMangledName(GlobalDecl GD) {
20782078
// Prior work:
20792079
// https://discourse.llvm.org/t/rfc-clang-diagnostic-for-demangling-failures/82835/8
20802080
// https://github.com/llvm/llvm-project/issues/111345
2081-
// assert((MangledName.startswith("_Z") || MangledName.startswith("?")) &&
2082-
// !GD->hasAttr<AsmLabelAttr>() &&
2083-
// llvm::demangle(MangledName) != MangledName &&
2081+
// assert(!((StringRef(MangledName).starts_with("_Z") ||
2082+
// StringRef(MangledName).starts_with("?")) &&
2083+
// !GD.getDecl()->hasAttr<AsmLabelAttr>() &&
2084+
// llvm::demangle(MangledName) == MangledName) &&
20842085
// "LLVM demangler must demangle clang-generated names");
20852086

20862087
auto Result = Manglings.insert(std::make_pair(MangledName, GD));

clang/lib/Parse/ParseExprCXX.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2203,8 +2203,16 @@ Parser::ParseCXXCondition(StmtResult *InitStmt, SourceLocation Loc,
22032203
return ParseCXXCondition(nullptr, Loc, CK, MissingOK);
22042204
}
22052205

2206-
// Parse the expression.
2207-
ExprResult Expr = ParseExpression(); // expression
2206+
ExprResult Expr = [&] {
2207+
EnterExpressionEvaluationContext Eval(
2208+
Actions, Sema::ExpressionEvaluationContext::ConstantEvaluated,
2209+
/*LambdaContextDecl=*/nullptr,
2210+
/*ExprContext=*/Sema::ExpressionEvaluationContextRecord::EK_Other,
2211+
/*ShouldEnter=*/CK == Sema::ConditionKind::ConstexprIf);
2212+
// Parse the expression.
2213+
return ParseExpression(); // expression
2214+
}();
2215+
22082216
if (Expr.isInvalid())
22092217
return Sema::ConditionError();
22102218

clang/test/CodeGenCXX/cxx23-p2280r4.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
extern int& s;
66

7-
// CHECK: @_Z4testv()
7+
// CHECK-LABEL: @_Z4testv()
88
// CHECK-NEXT: entry:
99
// CHECK-NEXT: [[I:%.*]] = alloca ptr, align {{.*}}
1010
// CHECK-NEXT: [[X:%.*]] = load ptr, ptr @s, align {{.*}}
@@ -13,3 +13,16 @@ int& test() {
1313
auto &i = s;
1414
return i;
1515
}
16+
17+
// CHECK-LABEL: @_Z1fv(
18+
// CHECK: [[X1:%.*]] = load ptr, ptr @x, align 8
19+
// CHECK-NEXT: store ptr [[X1]]
20+
// CHECK: [[X2:%.*]] = load ptr, ptr @x, align 8
21+
// CHECK-NEXT: store ptr [[X2]]
22+
// CHECK: [[X3:%.*]] = load ptr, ptr @x, align 8
23+
// CHECK-NEXT: store ptr [[X3]]
24+
int &ff();
25+
int &x = ff();
26+
struct A { int& x; };
27+
struct B { A x[20]; };
28+
B f() { return {x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x}; }

clang/test/SemaCXX/constant-expression-cxx11.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1472,8 +1472,8 @@ namespace ConvertedConstantExpr {
14721472
enum class E {
14731473
em = m,
14741474
en = n, // expected-error {{enumerator value is not a constant expression}} cxx11_20-note {{initializer of 'n' is unknown}}
1475-
eo = (m + // pre-cxx23-error {{not a constant expression}}
1476-
n // cxx11_20-note {{initializer of 'n' is unknown}} cxx23-error {{not a constant expression}}
1475+
eo = (m + // expected-error {{not a constant expression}}
1476+
n // cxx11_20-note {{initializer of 'n' is unknown}}
14771477
),
14781478
eq = reinterpret_cast<long>((int*)0) // expected-error {{not a constant expression}} expected-note {{reinterpret_cast}}
14791479
};

clang/test/SemaCXX/constant-expression-p2280r4.cpp

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clang_cc1 -std=c++23 -verify %s
1+
// RUN: %clang_cc1 -std=c++23 -verify=expected,nointerpreter %s
22
// RUN: %clang_cc1 -std=c++23 -verify %s -fexperimental-new-constant-interpreter
33

44
using size_t = decltype(sizeof(0));
@@ -39,8 +39,8 @@ void splash(Swim& swam) {
3939
static_assert(swam.phelps() == 28); // ok
4040
static_assert((&swam)->phelps() == 28); // ok
4141
Swim* pswam = &swam; // expected-note {{declared here}}
42-
static_assert(pswam->phelps() == 28); // expected-error {{static assertion expression is not an integral constant expression}}
43-
// expected-note@-1 {{read of non-constexpr variable 'pswam' is not allowed in a constant expression}}
42+
static_assert(pswam->phelps() == 28); // expected-error {{static assertion expression is not an integral constant expression}} \
43+
// expected-note {{read of non-constexpr variable 'pswam' is not allowed in a constant expression}}
4444
static_assert(how_many(swam) == 28); // ok
4545
static_assert(Swim().lochte() == 12); // ok
4646
static_assert(swam.lochte() == 12); // expected-error {{static assertion expression is not an integral constant expression}}
@@ -154,3 +154,26 @@ int g() {
154154
static_assert(f(arr) == 5);
155155
}
156156
}
157+
158+
namespace GH128409 {
159+
int &ff();
160+
int &x = ff(); // nointerpreter-note {{declared here}}
161+
constinit int &z = x; // expected-error {{variable does not have a constant initializer}} \
162+
// expected-note {{required by 'constinit' specifier here}} \
163+
// nointerpreter-note {{initializer of 'x' is not a constant expression}}
164+
}
165+
166+
namespace GH129845 {
167+
int &ff();
168+
int &x = ff(); // nointerpreter-note {{declared here}}
169+
struct A { int& x; };
170+
constexpr A g = {x}; // expected-error {{constexpr variable 'g' must be initialized by a constant expression}} \
171+
// nointerpreter-note {{initializer of 'x' is not a constant expression}}
172+
const A* gg = &g;
173+
}
174+
175+
namespace extern_reference_used_as_unknown {
176+
extern int &x;
177+
int y;
178+
constinit int& g = (x,y); // expected-warning {{left operand of comma operator has no effect}}
179+
}

clang/test/SemaCXX/constexpr-if.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// RUN: %clang_cc1 -std=c++20 -verify=cxx20,expected %s
2+
// RUN: %clang_cc1 -std=c++23 -verify=cxx23,expected %s
3+
// RUN: %clang_cc1 -std=c++26 -verify=cxx26,expected %s
4+
5+
// expected-no-diagnostics
6+
7+
namespace GH123524 {
8+
consteval void fn1() {}
9+
void fn2() {
10+
if constexpr (&fn1 != nullptr) { }
11+
}
12+
}

0 commit comments

Comments
 (0)