Skip to content

Commit 0d77823

Browse files
SC llvm teamSC llvm team
authored andcommitted
Merged main:3082a381f57ef2885c270f41f2955e08c79634c5 into amd-gfx:961ceed5c647
Local branch amd-gfx 961ceed Merged main:6932f47cfdf4734d68759586047aee240861058e into amd-gfx:781baf4fd9cc Remote branch main 3082a38 [LTO] Introduce helper functions to add GUIDs to ImportList (NFC) (llvm#105555)
2 parents 961ceed + 3082a38 commit 0d77823

File tree

388 files changed

+18359
-4582
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

388 files changed

+18359
-4582
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,8 @@ Bug Fixes to C++ Support
294294
- Correctly check constraints of explicit instantiations of member functions. (#GH46029)
295295
- Fixed an assertion failure about a constraint of a friend function template references to a value with greater
296296
template depth than the friend function template. (#GH98258)
297+
- Clang now rebuilds the template parameters of out-of-line declarations and specializations in the context
298+
of the current instantiation in all cases.
297299

298300
Bug Fixes to AST Handling
299301
^^^^^^^^^^^^^^^^^^^^^^^^^

clang/include/clang/Basic/BuiltinsWebAssembly.def

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,10 @@ TARGET_BUILTIN(__builtin_wasm_min_f64x2, "V2dV2dV2d", "nc", "simd128")
135135
TARGET_BUILTIN(__builtin_wasm_max_f64x2, "V2dV2dV2d", "nc", "simd128")
136136
TARGET_BUILTIN(__builtin_wasm_pmin_f64x2, "V2dV2dV2d", "nc", "simd128")
137137
TARGET_BUILTIN(__builtin_wasm_pmax_f64x2, "V2dV2dV2d", "nc", "simd128")
138-
TARGET_BUILTIN(__builtin_wasm_min_f16x8, "V8hV8hV8h", "nc", "half-precision")
139-
TARGET_BUILTIN(__builtin_wasm_max_f16x8, "V8hV8hV8h", "nc", "half-precision")
140-
TARGET_BUILTIN(__builtin_wasm_pmin_f16x8, "V8hV8hV8h", "nc", "half-precision")
141-
TARGET_BUILTIN(__builtin_wasm_pmax_f16x8, "V8hV8hV8h", "nc", "half-precision")
138+
TARGET_BUILTIN(__builtin_wasm_min_f16x8, "V8hV8hV8h", "nc", "fp16")
139+
TARGET_BUILTIN(__builtin_wasm_max_f16x8, "V8hV8hV8h", "nc", "fp16")
140+
TARGET_BUILTIN(__builtin_wasm_pmin_f16x8, "V8hV8hV8h", "nc", "fp16")
141+
TARGET_BUILTIN(__builtin_wasm_pmax_f16x8, "V8hV8hV8h", "nc", "fp16")
142142

143143
TARGET_BUILTIN(__builtin_wasm_ceil_f32x4, "V4fV4f", "nc", "simd128")
144144
TARGET_BUILTIN(__builtin_wasm_floor_f32x4, "V4fV4f", "nc", "simd128")
@@ -170,8 +170,8 @@ TARGET_BUILTIN(__builtin_wasm_relaxed_madd_f32x4, "V4fV4fV4fV4f", "nc", "relaxed
170170
TARGET_BUILTIN(__builtin_wasm_relaxed_nmadd_f32x4, "V4fV4fV4fV4f", "nc", "relaxed-simd")
171171
TARGET_BUILTIN(__builtin_wasm_relaxed_madd_f64x2, "V2dV2dV2dV2d", "nc", "relaxed-simd")
172172
TARGET_BUILTIN(__builtin_wasm_relaxed_nmadd_f64x2, "V2dV2dV2dV2d", "nc", "relaxed-simd")
173-
TARGET_BUILTIN(__builtin_wasm_relaxed_madd_f16x8, "V8hV8hV8hV8h", "nc", "half-precision")
174-
TARGET_BUILTIN(__builtin_wasm_relaxed_nmadd_f16x8, "V8hV8hV8hV8h", "nc", "half-precision")
173+
TARGET_BUILTIN(__builtin_wasm_relaxed_madd_f16x8, "V8hV8hV8hV8h", "nc", "fp16")
174+
TARGET_BUILTIN(__builtin_wasm_relaxed_nmadd_f16x8, "V8hV8hV8hV8h", "nc", "fp16")
175175

176176
TARGET_BUILTIN(__builtin_wasm_relaxed_laneselect_i8x16, "V16ScV16ScV16ScV16Sc", "nc", "relaxed-simd")
177177
TARGET_BUILTIN(__builtin_wasm_relaxed_laneselect_i16x8, "V8sV8sV8sV8s", "nc", "relaxed-simd")
@@ -197,11 +197,11 @@ TARGET_BUILTIN(__builtin_wasm_relaxed_dot_i8x16_i7x16_add_s_i32x4, "V4iV16ScV16S
197197
TARGET_BUILTIN(__builtin_wasm_relaxed_dot_bf16x8_add_f32_f32x4, "V4fV8UsV8UsV4f", "nc", "relaxed-simd")
198198

199199
// Half-Precision (fp16)
200-
TARGET_BUILTIN(__builtin_wasm_loadf16_f32, "fh*", "nU", "half-precision")
201-
TARGET_BUILTIN(__builtin_wasm_storef16_f32, "vfh*", "n", "half-precision")
202-
TARGET_BUILTIN(__builtin_wasm_splat_f16x8, "V8hf", "nc", "half-precision")
203-
TARGET_BUILTIN(__builtin_wasm_extract_lane_f16x8, "fV8hi", "nc", "half-precision")
204-
TARGET_BUILTIN(__builtin_wasm_replace_lane_f16x8, "V8hV8hif", "nc", "half-precision")
200+
TARGET_BUILTIN(__builtin_wasm_loadf16_f32, "fh*", "nU", "fp16")
201+
TARGET_BUILTIN(__builtin_wasm_storef16_f32, "vfh*", "n", "fp16")
202+
TARGET_BUILTIN(__builtin_wasm_splat_f16x8, "V8hf", "nc", "fp16")
203+
TARGET_BUILTIN(__builtin_wasm_extract_lane_f16x8, "fV8hi", "nc", "fp16")
204+
TARGET_BUILTIN(__builtin_wasm_replace_lane_f16x8, "V8hV8hif", "nc", "fp16")
205205

206206
// Reference Types builtins
207207
// Some builtins are custom type-checked - see 't' as part of the third argument,

clang/include/clang/Basic/CodeGenOptions.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ VALUE_CODEGENOPT(Name, Bits, Default)
3737

3838
CODEGENOPT(DisableIntegratedAS, 1, 0) ///< -no-integrated-as
3939
CODEGENOPT(Crel, 1, 0) ///< -Wa,--crel
40+
CODEGENOPT(ImplicitMapSyms, 1, 0) ///< -Wa,-mmapsyms=implicit
4041
CODEGENOPT(AsmVerbose , 1, 0) ///< -dA, -fverbose-asm.
4142
CODEGENOPT(PreserveAsmComments, 1, 1) ///< -dA, -fno-preserve-as-comments.
4243
CODEGENOPT(AssumeSaneOperatorNew , 1, 1) ///< implicit __attribute__((malloc)) operator new

clang/include/clang/Driver/Options.td

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5033,8 +5033,8 @@ def mexception_handing : Flag<["-"], "mexception-handling">, Group<m_wasm_Featur
50335033
def mno_exception_handing : Flag<["-"], "mno-exception-handling">, Group<m_wasm_Features_Group>;
50345034
def mextended_const : Flag<["-"], "mextended-const">, Group<m_wasm_Features_Group>;
50355035
def mno_extended_const : Flag<["-"], "mno-extended-const">, Group<m_wasm_Features_Group>;
5036-
def mhalf_precision : Flag<["-"], "mhalf-precision">, Group<m_wasm_Features_Group>;
5037-
def mno_half_precision : Flag<["-"], "mno-half-precision">, Group<m_wasm_Features_Group>;
5036+
def mfp16 : Flag<["-"], "mfp16">, Group<m_wasm_Features_Group>;
5037+
def mno_fp16 : Flag<["-"], "mno-fp16">, Group<m_wasm_Features_Group>;
50385038
def mmultimemory : Flag<["-"], "mmultimemory">, Group<m_wasm_Features_Group>;
50395039
def mno_multimemory : Flag<["-"], "mno-multimemory">, Group<m_wasm_Features_Group>;
50405040
def mmultivalue : Flag<["-"], "mmultivalue">, Group<m_wasm_Features_Group>;
@@ -7142,6 +7142,12 @@ def massembler_fatal_warnings : Flag<["-"], "massembler-fatal-warnings">,
71427142
def crel : Flag<["--"], "crel">,
71437143
HelpText<"Enable CREL relocation format (ELF only)">,
71447144
MarshallingInfoFlag<CodeGenOpts<"Crel">>;
7145+
def mmapsyms_implicit : Flag<["-"], "mmapsyms=implicit">,
7146+
HelpText<"Allow mapping symbol at section beginning to be implicit, "
7147+
"lowering number of mapping symbols at the expense of some "
7148+
"portability. Recommended for projects that can build all their "
7149+
"object files using this option">,
7150+
MarshallingInfoFlag<CodeGenOpts<"ImplicitMapSyms">>;
71457151
def mrelax_relocations_no : Flag<["-"], "mrelax-relocations=no">,
71467152
HelpText<"Disable x86 relax relocations">,
71477153
MarshallingInfoNegativeFlag<CodeGenOpts<"X86RelaxRelocations">>;

clang/lib/AST/ByteCode/Compiler.cpp

Lines changed: 46 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -885,34 +885,60 @@ bool Compiler<Emitter>::VisitPointerArithBinOp(const BinaryOperator *E) {
885885
if (!LT || !RT)
886886
return false;
887887

888+
// Visit the given pointer expression and optionally convert to a PT_Ptr.
889+
auto visitAsPointer = [&](const Expr *E, PrimType T) -> bool {
890+
if (!this->visit(E))
891+
return false;
892+
if (T != PT_Ptr)
893+
return this->emitDecayPtr(T, PT_Ptr, E);
894+
return true;
895+
};
896+
888897
if (LHS->getType()->isPointerType() && RHS->getType()->isPointerType()) {
889898
if (Op != BO_Sub)
890899
return false;
891900

892901
assert(E->getType()->isIntegerType());
893-
if (!visit(RHS) || !visit(LHS))
902+
if (!visitAsPointer(RHS, *RT) || !visitAsPointer(LHS, *LT))
894903
return false;
895904

896905
return this->emitSubPtr(classifyPrim(E->getType()), E);
897906
}
898907

899908
PrimType OffsetType;
900909
if (LHS->getType()->isIntegerType()) {
901-
if (!visit(RHS) || !visit(LHS))
910+
if (!visitAsPointer(RHS, *RT))
911+
return false;
912+
if (!this->visit(LHS))
902913
return false;
903914
OffsetType = *LT;
904915
} else if (RHS->getType()->isIntegerType()) {
905-
if (!visit(LHS) || !visit(RHS))
916+
if (!visitAsPointer(LHS, *LT))
917+
return false;
918+
if (!this->visit(RHS))
906919
return false;
907920
OffsetType = *RT;
908921
} else {
909922
return false;
910923
}
911924

912-
if (Op == BO_Add)
913-
return this->emitAddOffset(OffsetType, E);
914-
else if (Op == BO_Sub)
915-
return this->emitSubOffset(OffsetType, E);
925+
// Do the operation and optionally transform to
926+
// result pointer type.
927+
if (Op == BO_Add) {
928+
if (!this->emitAddOffset(OffsetType, E))
929+
return false;
930+
931+
if (classifyPrim(E) != PT_Ptr)
932+
return this->emitDecayPtr(PT_Ptr, classifyPrim(E), E);
933+
return true;
934+
} else if (Op == BO_Sub) {
935+
if (!this->emitSubOffset(OffsetType, E))
936+
return false;
937+
938+
if (classifyPrim(E) != PT_Ptr)
939+
return this->emitDecayPtr(PT_Ptr, classifyPrim(E), E);
940+
return true;
941+
}
916942

917943
return false;
918944
}
@@ -4359,11 +4385,6 @@ bool Compiler<Emitter>::visitReturnStmt(const ReturnStmt *RS) {
43594385
}
43604386

43614387
template <class Emitter> bool Compiler<Emitter>::visitIfStmt(const IfStmt *IS) {
4362-
if (IS->isNonNegatedConsteval())
4363-
return visitStmt(IS->getThen());
4364-
if (IS->isNegatedConsteval())
4365-
return IS->getElse() ? visitStmt(IS->getElse()) : true;
4366-
43674388
if (auto *CondInit = IS->getInit())
43684389
if (!visitStmt(CondInit))
43694390
return false;
@@ -4372,8 +4393,19 @@ template <class Emitter> bool Compiler<Emitter>::visitIfStmt(const IfStmt *IS) {
43724393
if (!visitDeclStmt(CondDecl))
43734394
return false;
43744395

4375-
if (!this->visitBool(IS->getCond()))
4376-
return false;
4396+
// Compile condition.
4397+
if (IS->isNonNegatedConsteval()) {
4398+
if (!this->emitIsConstantContext(IS))
4399+
return false;
4400+
} else if (IS->isNegatedConsteval()) {
4401+
if (!this->emitIsConstantContext(IS))
4402+
return false;
4403+
if (!this->emitInv(IS))
4404+
return false;
4405+
} else {
4406+
if (!this->visitBool(IS->getCond()))
4407+
return false;
4408+
}
43774409

43784410
if (const Stmt *Else = IS->getElse()) {
43794411
LabelTy LabelElse = this->getLabel();
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
//===----------------------- FunctionPointer.cpp ----------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "FunctionPointer.h"
10+
11+
namespace clang {
12+
namespace interp {
13+
14+
APValue FunctionPointer::toAPValue(const ASTContext &) const {
15+
if (!Func)
16+
return APValue(static_cast<Expr *>(nullptr), CharUnits::Zero(), {},
17+
/*OnePastTheEnd=*/false, /*IsNull=*/true);
18+
19+
if (!Valid)
20+
return APValue(static_cast<Expr *>(nullptr),
21+
CharUnits::fromQuantity(getIntegerRepresentation()), {},
22+
/*OnePastTheEnd=*/false, /*IsNull=*/false);
23+
24+
if (Func->getDecl())
25+
return APValue(Func->getDecl(), CharUnits::fromQuantity(Offset), {},
26+
/*OnePastTheEnd=*/false, /*IsNull=*/false);
27+
return APValue(Func->getExpr(), CharUnits::fromQuantity(Offset), {},
28+
/*OnePastTheEnd=*/false, /*IsNull=*/false);
29+
}
30+
31+
void FunctionPointer::print(llvm::raw_ostream &OS) const {
32+
OS << "FnPtr(";
33+
if (Func && Valid)
34+
OS << Func->getName();
35+
else if (Func)
36+
OS << reinterpret_cast<uintptr_t>(Func);
37+
else
38+
OS << "nullptr";
39+
OS << ") + " << Offset;
40+
}
41+
42+
} // namespace interp
43+
} // namespace clang

clang/lib/AST/ByteCode/FunctionPointer.h

Lines changed: 10 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,29 @@
1111

1212
#include "Function.h"
1313
#include "Primitives.h"
14-
#include "clang/AST/APValue.h"
1514

1615
namespace clang {
1716
class ASTContext;
17+
class APValue;
1818
namespace interp {
1919

2020
class FunctionPointer final {
2121
private:
2222
const Function *Func;
23+
uint64_t Offset;
2324
bool Valid;
2425

2526
public:
2627
FunctionPointer() = default;
27-
FunctionPointer(const Function *Func) : Func(Func), Valid(true) {}
28+
FunctionPointer(const Function *Func, uint64_t Offset = 0)
29+
: Func(Func), Offset(Offset), Valid(true) {}
2830

2931
FunctionPointer(uintptr_t IntVal, const Descriptor *Desc = nullptr)
30-
: Func(reinterpret_cast<const Function *>(IntVal)), Valid(false) {}
32+
: Func(reinterpret_cast<const Function *>(IntVal)), Offset(0),
33+
Valid(false) {}
3134

3235
const Function *getFunction() const { return Func; }
36+
uint64_t getOffset() const { return Offset; }
3337
bool isZero() const { return !Func; }
3438
bool isValid() const { return Valid; }
3539
bool isWeak() const {
@@ -39,33 +43,8 @@ class FunctionPointer final {
3943
return Func->getDecl()->isWeak();
4044
}
4145

42-
APValue toAPValue(const ASTContext &) const {
43-
if (!Func)
44-
return APValue(static_cast<Expr *>(nullptr), CharUnits::Zero(), {},
45-
/*OnePastTheEnd=*/false, /*IsNull=*/true);
46-
47-
if (!Valid)
48-
return APValue(static_cast<Expr *>(nullptr),
49-
CharUnits::fromQuantity(getIntegerRepresentation()), {},
50-
/*OnePastTheEnd=*/false, /*IsNull=*/false);
51-
52-
if (Func->getDecl())
53-
return APValue(Func->getDecl(), CharUnits::Zero(), {},
54-
/*OnePastTheEnd=*/false, /*IsNull=*/false);
55-
return APValue(Func->getExpr(), CharUnits::Zero(), {},
56-
/*OnePastTheEnd=*/false, /*IsNull=*/false);
57-
}
58-
59-
void print(llvm::raw_ostream &OS) const {
60-
OS << "FnPtr(";
61-
if (Func && Valid)
62-
OS << Func->getName();
63-
else if (Func)
64-
OS << reinterpret_cast<uintptr_t>(Func);
65-
else
66-
OS << "nullptr";
67-
OS << ")";
68-
}
46+
APValue toAPValue(const ASTContext &) const;
47+
void print(llvm::raw_ostream &OS) const;
6948

7049
std::string toDiagnosticString(const ASTContext &Ctx) const {
7150
if (!Func)
@@ -79,7 +58,7 @@ class FunctionPointer final {
7958
}
8059

8160
ComparisonCategoryResult compare(const FunctionPointer &RHS) const {
82-
if (Func == RHS.Func)
61+
if (Func == RHS.Func && Offset == RHS.Offset)
8362
return ComparisonCategoryResult::Equal;
8463
return ComparisonCategoryResult::Unordered;
8564
}

clang/lib/AST/ByteCode/Interp.h

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1857,8 +1857,23 @@ bool OffsetHelper(InterpState &S, CodePtr OpPC, const T &Offset,
18571857
else
18581858
S.Stk.push<Pointer>(V - O, Ptr.asIntPointer().Desc);
18591859
return true;
1860+
} else if (Ptr.isFunctionPointer()) {
1861+
uint64_t O = static_cast<uint64_t>(Offset);
1862+
uint64_t N;
1863+
if constexpr (Op == ArithOp::Add)
1864+
N = Ptr.getByteOffset() + O;
1865+
else
1866+
N = Ptr.getByteOffset() - O;
1867+
1868+
if (N > 1)
1869+
S.CCEDiag(S.Current->getSource(OpPC), diag::note_constexpr_array_index)
1870+
<< N << /*non-array*/ true << 0;
1871+
S.Stk.push<Pointer>(Ptr.asFunctionPointer().getFunction(), N);
1872+
return true;
18601873
}
18611874

1875+
assert(Ptr.isBlockPointer());
1876+
18621877
uint64_t MaxIndex = static_cast<uint64_t>(Ptr.getNumElems());
18631878
uint64_t Index;
18641879
if (Ptr.isOnePastEnd())
@@ -2024,10 +2039,15 @@ inline bool SubPtr(InterpState &S, CodePtr OpPC) {
20242039
return true;
20252040
}
20262041

2027-
T A = LHS.isElementPastEnd() ? T::from(LHS.getNumElems())
2028-
: T::from(LHS.getIndex());
2029-
T B = RHS.isElementPastEnd() ? T::from(RHS.getNumElems())
2030-
: T::from(RHS.getIndex());
2042+
T A = LHS.isBlockPointer()
2043+
? (LHS.isElementPastEnd() ? T::from(LHS.getNumElems())
2044+
: T::from(LHS.getIndex()))
2045+
: T::from(LHS.getIntegerRepresentation());
2046+
T B = RHS.isBlockPointer()
2047+
? (RHS.isElementPastEnd() ? T::from(RHS.getNumElems())
2048+
: T::from(RHS.getIndex()))
2049+
: T::from(RHS.getIntegerRepresentation());
2050+
20312051
return AddSubMulHelper<T, T::sub, std::minus>(S, OpPC, A.bitWidth(), A, B);
20322052
}
20332053

@@ -2905,8 +2925,15 @@ inline bool DecayPtr(InterpState &S, CodePtr OpPC) {
29052925

29062926
if constexpr (std::is_same_v<FromT, FunctionPointer> &&
29072927
std::is_same_v<ToT, Pointer>) {
2908-
S.Stk.push<Pointer>(OldPtr.getFunction());
2928+
S.Stk.push<Pointer>(OldPtr.getFunction(), OldPtr.getOffset());
29092929
return true;
2930+
} else if constexpr (std::is_same_v<FromT, Pointer> &&
2931+
std::is_same_v<ToT, FunctionPointer>) {
2932+
if (OldPtr.isFunctionPointer()) {
2933+
S.Stk.push<FunctionPointer>(OldPtr.asFunctionPointer().getFunction(),
2934+
OldPtr.getByteOffset());
2935+
return true;
2936+
}
29102937
}
29112938

29122939
S.Stk.push<ToT>(ToT(OldPtr.getIntegerRepresentation(), nullptr));
@@ -3049,6 +3076,11 @@ static inline bool Free(InterpState &S, CodePtr OpPC, bool DeleteIsArrayForm) {
30493076
BlockDesc, Source);
30503077
}
30513078

3079+
static inline bool IsConstantContext(InterpState &S, CodePtr OpPC) {
3080+
S.Stk.push<Boolean>(Boolean::from(S.inConstantContext()));
3081+
return true;
3082+
}
3083+
30523084
inline bool CheckLiteralType(InterpState &S, CodePtr OpPC, const Type *T) {
30533085
assert(T);
30543086
assert(!S.getLangOpts().CPlusPlus23);

clang/lib/AST/ByteCode/Opcodes.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -780,3 +780,5 @@ def AllocCN : Opcode {
780780
def Free : Opcode {
781781
let Args = [ArgBool];
782782
}
783+
784+
def IsConstantContext: Opcode;

0 commit comments

Comments
 (0)