Skip to content

Commit 9c7c0d3

Browse files
authored
Merge branch 'main' into foldconvert
2 parents cbc9651 + 2c40fd6 commit 9c7c0d3

File tree

24 files changed

+756
-883
lines changed

24 files changed

+756
-883
lines changed

clang/lib/AST/ByteCode/Compiler.cpp

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2062,21 +2062,36 @@ bool Compiler<Emitter>::visitArrayElemInit(unsigned ElemIndex, const Expr *Init,
20622062
template <class Emitter>
20632063
bool Compiler<Emitter>::visitCallArgs(ArrayRef<const Expr *> Args,
20642064
const FunctionDecl *FuncDecl,
2065-
bool Activate) {
2065+
bool Activate, bool IsOperatorCall) {
20662066
assert(VarScope->getKind() == ScopeKind::Call);
20672067
llvm::BitVector NonNullArgs;
20682068
if (FuncDecl && FuncDecl->hasAttr<NonNullAttr>())
20692069
NonNullArgs = collectNonNullArgs(FuncDecl, Args);
20702070

2071+
bool ExplicitMemberFn = false;
2072+
if (const auto *MD = dyn_cast_if_present<CXXMethodDecl>(FuncDecl))
2073+
ExplicitMemberFn = MD->isExplicitObjectMemberFunction();
2074+
20712075
unsigned ArgIndex = 0;
20722076
for (const Expr *Arg : Args) {
20732077
if (canClassify(Arg)) {
20742078
if (!this->visit(Arg))
20752079
return false;
20762080
} else {
20772081

2078-
std::optional<unsigned> LocalIndex = allocateLocal(
2079-
Arg, Arg->getType(), /*ExtendingDecl=*/nullptr, ScopeKind::Call);
2082+
DeclTy Source = Arg;
2083+
if (FuncDecl) {
2084+
// Try to use the parameter declaration instead of the argument
2085+
// expression as a source.
2086+
unsigned DeclIndex = ArgIndex - IsOperatorCall + ExplicitMemberFn;
2087+
if (DeclIndex < FuncDecl->getNumParams())
2088+
Source = FuncDecl->getParamDecl(ArgIndex - IsOperatorCall +
2089+
ExplicitMemberFn);
2090+
}
2091+
2092+
std::optional<unsigned> LocalIndex =
2093+
allocateLocal(std::move(Source), Arg->getType(),
2094+
/*ExtendingDecl=*/nullptr, ScopeKind::Call);
20802095
if (!LocalIndex)
20812096
return false;
20822097

@@ -4489,14 +4504,6 @@ template <class Emitter>
44894504
unsigned Compiler<Emitter>::allocateLocalPrimitive(
44904505
DeclTy &&Src, PrimType Ty, bool IsConst, const ValueDecl *ExtendingDecl,
44914506
ScopeKind SC, bool IsConstexprUnknown) {
4492-
// Make sure we don't accidentally register the same decl twice.
4493-
if (const auto *VD =
4494-
dyn_cast_if_present<ValueDecl>(Src.dyn_cast<const Decl *>())) {
4495-
assert(!P.getGlobal(VD));
4496-
assert(!Locals.contains(VD));
4497-
(void)VD;
4498-
}
4499-
45004507
// FIXME: There are cases where Src.is<Expr*>() is wrong, e.g.
45014508
// (int){12} in C. Consider using Expr::isTemporaryObject() instead
45024509
// or isa<MaterializeTemporaryExpr>().
@@ -4518,19 +4525,11 @@ std::optional<unsigned>
45184525
Compiler<Emitter>::allocateLocal(DeclTy &&Src, QualType Ty,
45194526
const ValueDecl *ExtendingDecl, ScopeKind SC,
45204527
bool IsConstexprUnknown) {
4521-
// Make sure we don't accidentally register the same decl twice.
4522-
if ([[maybe_unused]] const auto *VD =
4523-
dyn_cast_if_present<ValueDecl>(Src.dyn_cast<const Decl *>())) {
4524-
assert(!P.getGlobal(VD));
4525-
assert(!Locals.contains(VD));
4526-
}
4527-
45284528
const ValueDecl *Key = nullptr;
45294529
const Expr *Init = nullptr;
45304530
bool IsTemporary = false;
45314531
if (auto *VD = dyn_cast_if_present<ValueDecl>(Src.dyn_cast<const Decl *>())) {
45324532
Key = VD;
4533-
Ty = VD->getType();
45344533

45354534
if (const auto *VarD = dyn_cast<VarDecl>(VD))
45364535
Init = VarD->getInit();
@@ -5167,7 +5166,8 @@ bool Compiler<Emitter>::VisitCallExpr(const CallExpr *E) {
51675166
return false;
51685167
}
51695168

5170-
if (!this->visitCallArgs(Args, FuncDecl, IsAssignmentOperatorCall))
5169+
if (!this->visitCallArgs(Args, FuncDecl, IsAssignmentOperatorCall,
5170+
isa<CXXOperatorCallExpr>(E)))
51715171
return false;
51725172

51735173
// Undo the argument reversal we did earlier.

clang/lib/AST/ByteCode/Compiler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ class Compiler : public ConstStmtVisitor<Compiler<Emitter>, bool>,
306306
bool visitArrayElemInit(unsigned ElemIndex, const Expr *Init,
307307
OptPrimType InitT);
308308
bool visitCallArgs(ArrayRef<const Expr *> Args, const FunctionDecl *FuncDecl,
309-
bool Activate);
309+
bool Activate, bool IsOperatorCall);
310310

311311
/// Creates a local primitive value.
312312
unsigned allocateLocalPrimitive(DeclTy &&Decl, PrimType Ty, bool IsConst,

clang/test/AST/ByteCode/cxx23.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -309,15 +309,14 @@ namespace NonLiteralDtorInParam {
309309
~NonLiteral() {} // all23-note {{declared here}}
310310
};
311311
constexpr int F2(NonLiteral N) { // all20-error {{constexpr function's 1st parameter type 'NonLiteral' is not a literal type}} \
312-
// ref23-note {{non-constexpr function '~NonLiteral' cannot be used in a constant expression}}
312+
// all23-note {{non-constexpr function '~NonLiteral' cannot be used in a constant expression}}
313313
return 8;
314314
}
315315

316316

317317
void test() {
318318
NonLiteral L;
319-
constexpr auto D = F2(L); // all23-error {{must be initialized by a constant expression}} \
320-
// expected23-note {{non-constexpr function '~NonLiteral' cannot be used in a constant expression}}
319+
constexpr auto D = F2(L); // all23-error {{must be initialized by a constant expression}}
321320
}
322321
}
323322

clang/test/AST/ByteCode/lifetimes.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,13 @@ namespace CallScope {
9494
int n = 0;
9595
constexpr int f() const { return 0; }
9696
};
97-
constexpr Q *out_of_lifetime(Q q) { return &q; } // both-warning {{address of stack}}
97+
constexpr Q *out_of_lifetime(Q q) { return &q; } // both-warning {{address of stack}} \
98+
// expected-note 2{{declared here}}
9899
constexpr int k3 = out_of_lifetime({})->n; // both-error {{must be initialized by a constant expression}} \
99-
// expected-note {{read of temporary whose lifetime has ended}} \
100-
// expected-note {{temporary created here}} \
100+
// expected-note {{read of variable whose lifetime has ended}} \
101101
// ref-note {{read of object outside its lifetime}}
102102

103103
constexpr int k4 = out_of_lifetime({})->f(); // both-error {{must be initialized by a constant expression}} \
104-
// expected-note {{member call on temporary whose lifetime has ended}} \
105-
// expected-note {{temporary created here}} \
104+
// expected-note {{member call on variable whose lifetime has ended}} \
106105
// ref-note {{member call on object outside its lifetime}}
107106
}

clang/test/SemaCXX/cxx23-invalid-constexpr.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// RUN: %clang_cc1 -fsyntax-only -verify=expected -std=c++23 %s
2+
// RUN: %clang_cc1 -fsyntax-only -verify=expected -std=c++23 %s -fexperimental-new-constant-interpreter
23

34
// This test covers modifications made by P2448R2.
45

llvm/docs/ReleaseNotes.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ Changes to Vectorizers
7777

7878
* Added initial support for copyable elements in SLP, which models copyable
7979
elements as add <element>, 0, i.e. uses identity constants for missing lanes.
80-
* SLP vectorizer supports initial recognition of FMA/FMAD pattern
8180

8281
Changes to the AArch64 Backend
8382
------------------------------

llvm/include/llvm/IR/GenericFloatingPointPredicateUtils.h

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,12 @@ template <typename ContextT> class GenericFloatingPointPredicateUtils {
135135
if (Mode.Input != DenormalMode::IEEE)
136136
return {Invalid, fcAllFlags, fcAllFlags};
137137

138+
auto ExactClass = [IsFabs, Src](FPClassTest Mask) {
139+
if (IsFabs)
140+
Mask = llvm::inverse_fabs(Mask);
141+
return exactClass(Src, Mask);
142+
};
143+
138144
switch (Pred) {
139145
case FCmpInst::FCMP_OEQ: // Match x == 0.0
140146
return exactClass(Src, fcZero);
@@ -151,26 +157,24 @@ template <typename ContextT> class GenericFloatingPointPredicateUtils {
151157
case FCmpInst::FCMP_UNO:
152158
return exactClass(Src, fcNan);
153159
case FCmpInst::FCMP_OGT: // x > 0
154-
return exactClass(Src, fcPosSubnormal | fcPosNormal | fcPosInf);
160+
return ExactClass(fcPosSubnormal | fcPosNormal | fcPosInf);
155161
case FCmpInst::FCMP_UGT: // isnan(x) || x > 0
156-
return exactClass(Src, fcPosSubnormal | fcPosNormal | fcPosInf | fcNan);
162+
return ExactClass(fcPosSubnormal | fcPosNormal | fcPosInf | fcNan);
157163
case FCmpInst::FCMP_OGE: // x >= 0
158-
return exactClass(Src, fcPositive | fcNegZero);
164+
return ExactClass(fcPositive | fcNegZero);
159165
case FCmpInst::FCMP_UGE: // isnan(x) || x >= 0
160-
return exactClass(Src, fcPositive | fcNegZero | fcNan);
166+
return ExactClass(fcPositive | fcNegZero | fcNan);
161167
case FCmpInst::FCMP_OLT: // x < 0
162-
return exactClass(Src, fcNegSubnormal | fcNegNormal | fcNegInf);
168+
return ExactClass(fcNegSubnormal | fcNegNormal | fcNegInf);
163169
case FCmpInst::FCMP_ULT: // isnan(x) || x < 0
164-
return exactClass(Src, fcNegSubnormal | fcNegNormal | fcNegInf | fcNan);
170+
return ExactClass(fcNegSubnormal | fcNegNormal | fcNegInf | fcNan);
165171
case FCmpInst::FCMP_OLE: // x <= 0
166-
return exactClass(Src, fcNegative | fcPosZero);
172+
return ExactClass(fcNegative | fcPosZero);
167173
case FCmpInst::FCMP_ULE: // isnan(x) || x <= 0
168-
return exactClass(Src, fcNegative | fcPosZero | fcNan);
174+
return ExactClass(fcNegative | fcPosZero | fcNan);
169175
default:
170176
llvm_unreachable("all compare types are handled");
171177
}
172-
173-
return {Invalid, fcAllFlags, fcAllFlags};
174178
}
175179

176180
const bool IsDenormalRHS = (OrigClass & fcSubnormal) == OrigClass;

0 commit comments

Comments
 (0)