Skip to content

Commit f070204

Browse files
authored
Merge branch 'main' into repack_arrays_lowering
2 parents 3c86bae + 351bcd9 commit f070204

File tree

332 files changed

+10590
-15330
lines changed

Some content is hidden

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

332 files changed

+10590
-15330
lines changed

bolt/lib/Target/RISCV/RISCVMCPlusBuilder.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ class RISCVMCPlusBuilder : public MCPlusBuilder {
244244
Inst.clear();
245245
Inst.addOperand(MCOperand::createExpr(RISCVMCExpr::create(
246246
MCSymbolRefExpr::create(Target, MCSymbolRefExpr::VK_None, *Ctx),
247-
RISCVMCExpr::VK_RISCV_CALL, *Ctx)));
247+
RISCVMCExpr::VK_CALL, *Ctx)));
248248
}
249249

250250
void createCall(MCInst &Inst, const MCSymbol *Target,
@@ -434,19 +434,19 @@ class RISCVMCPlusBuilder : public MCPlusBuilder {
434434
case ELF::R_RISCV_TLS_GOT_HI20:
435435
// The GOT is reused so no need to create GOT relocations
436436
case ELF::R_RISCV_PCREL_HI20:
437-
return RISCVMCExpr::create(Expr, RISCVMCExpr::VK_RISCV_PCREL_HI, Ctx);
437+
return RISCVMCExpr::create(Expr, RISCVMCExpr::VK_PCREL_HI, Ctx);
438438
case ELF::R_RISCV_PCREL_LO12_I:
439439
case ELF::R_RISCV_PCREL_LO12_S:
440-
return RISCVMCExpr::create(Expr, RISCVMCExpr::VK_RISCV_PCREL_LO, Ctx);
440+
return RISCVMCExpr::create(Expr, RISCVMCExpr::VK_PCREL_LO, Ctx);
441441
case ELF::R_RISCV_HI20:
442-
return RISCVMCExpr::create(Expr, RISCVMCExpr::VK_RISCV_HI, Ctx);
442+
return RISCVMCExpr::create(Expr, RISCVMCExpr::VK_HI, Ctx);
443443
case ELF::R_RISCV_LO12_I:
444444
case ELF::R_RISCV_LO12_S:
445-
return RISCVMCExpr::create(Expr, RISCVMCExpr::VK_RISCV_LO, Ctx);
445+
return RISCVMCExpr::create(Expr, RISCVMCExpr::VK_LO, Ctx);
446446
case ELF::R_RISCV_CALL:
447-
return RISCVMCExpr::create(Expr, RISCVMCExpr::VK_RISCV_CALL, Ctx);
447+
return RISCVMCExpr::create(Expr, RISCVMCExpr::VK_CALL, Ctx);
448448
case ELF::R_RISCV_CALL_PLT:
449-
return RISCVMCExpr::create(Expr, RISCVMCExpr::VK_RISCV_CALL_PLT, Ctx);
449+
return RISCVMCExpr::create(Expr, RISCVMCExpr::VK_CALL_PLT, Ctx);
450450
}
451451
}
452452

@@ -471,8 +471,8 @@ class RISCVMCPlusBuilder : public MCPlusBuilder {
471471
switch (cast<RISCVMCExpr>(ImmExpr)->getKind()) {
472472
default:
473473
return false;
474-
case RISCVMCExpr::VK_RISCV_CALL:
475-
case RISCVMCExpr::VK_RISCV_CALL_PLT:
474+
case RISCVMCExpr::VK_CALL:
475+
case RISCVMCExpr::VK_CALL_PLT:
476476
return true;
477477
}
478478
}

clang/docs/ClangOffloadBundler.rst

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -266,15 +266,14 @@ without differentiation based on offload kind.
266266
The target triple of the code object. See `Target Triple
267267
<https://clang.llvm.org/docs/CrossCompilation.html#target-triple>`_.
268268

269-
The bundler accepts target triples with or without the optional environment
270-
field:
269+
LLVM target triples can be with or without the optional environment field:
271270

272271
``<arch><sub>-<vendor>-<sys>``, or
273272
``<arch><sub>-<vendor>-<sys>-<env>``
274273

275-
However, in order to standardize outputs for tools that consume bitcode
276-
bundles, bundles written by the bundler internally use only the 4-field
277-
target triple:
274+
However, in order to standardize outputs for tools that consume bitcode bundles
275+
and to parse target ID containing dashes, the bundler only accepts target
276+
triples in the 4-field format:
278277

279278
``<arch><sub>-<vendor>-<sys>-<env>``
280279

@@ -543,4 +542,4 @@ The compressed offload bundle begins with a header followed by the compressed bi
543542
- **Compressed Data**:
544543
The actual compressed binary data follows the header. Its size can be inferred from the total size of the file minus the header size.
545544

546-
> **Note**: Version 3 of the format is under development. It uses 64-bit fields for Total File Size and Uncompressed Binary Size to support files larger than 4GB. To experiment with version 3, set the environment variable `COMPRESSED_BUNDLE_FORMAT_VERSION=3`. This support is experimental and not recommended for production use.
545+
> **Note**: Version 3 of the format is under development. It uses 64-bit fields for Total File Size and Uncompressed Binary Size to support files larger than 4GB. To experiment with version 3, set the environment variable `COMPRESSED_BUNDLE_FORMAT_VERSION=3`. This support is experimental and not recommended for production use.

clang/docs/LanguageExtensions.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1652,6 +1652,7 @@ Designated initializers (N494) C
16521652
Array & element qualification (N2607) C23 C89
16531653
Attributes (N2335) C23 C89
16541654
``#embed`` (N3017) C23 C89, C++
1655+
Octal literals prefixed with ``0o`` or ``0O`` C2y C89, C++
16551656
============================================= ================================ ============= =============
16561657

16571658
Builtin type aliases

clang/docs/ReleaseNotes.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,13 @@ C2y Feature Support
129129
- Implemented `WG14 N3411 <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3411.pdf>`_
130130
which allows a source file to not end with a newline character. This is still
131131
reported as a conforming extension in earlier language modes.
132+
- Implemented `WG14 N3353 <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3353.htm>_`
133+
which adds the new ``0o`` and ``0O`` ocal literal prefixes and deprecates
134+
octal literals other than ``0`` which do not start with the new prefix. This
135+
feature is exposed in earlier language modes and in C++ as an extension. The
136+
paper also introduced octal and hexadecimal delimited escape sequences (e.g.,
137+
``"\x{12}\o{12}"``) which are also supported as an extension in older C
138+
language modes.
132139

133140
C23 Feature Support
134141
^^^^^^^^^^^^^^^^^^^

clang/include/clang/Basic/DiagnosticGroups.td

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ def EnumCompare : DiagGroup<"enum-compare", [EnumCompareSwitch,
9292
def DeprecatedAnonEnumEnumConversion : DiagGroup<"deprecated-anon-enum-enum-conversion">;
9393
def DeprecatedEnumEnumConversion : DiagGroup<"deprecated-enum-enum-conversion">;
9494
def DeprecatedEnumFloatConversion : DiagGroup<"deprecated-enum-float-conversion">;
95+
def DeprecatedOctalLiterals : DiagGroup<"deprecated-octal-literals">;
9596
def AnonEnumEnumConversion : DiagGroup<"anon-enum-enum-conversion",
9697
[DeprecatedAnonEnumEnumConversion]>;
9798
def EnumEnumConversion : DiagGroup<"enum-enum-conversion",
@@ -235,7 +236,8 @@ def Deprecated : DiagGroup<"deprecated", [DeprecatedAnonEnumEnumConversion,
235236
DeprecatedVolatile,
236237
DeprecatedWritableStr,
237238
DeprecatedRedundantConstexprStaticDef,
238-
DeprecatedMissingCommaVariadicParam
239+
DeprecatedMissingCommaVariadicParam,
240+
DeprecatedOctalLiterals
239241
]>,
240242
DiagCategory<"Deprecations">;
241243

clang/include/clang/Basic/DiagnosticLexKinds.td

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -148,14 +148,14 @@ def ext_mathematical_notation : ExtWarn<
148148
InGroup<DiagGroup<"mathematical-notation-identifier-extension">>;
149149

150150
def ext_delimited_escape_sequence : Extension<
151-
"%select{delimited|named}0 escape sequences are a "
152-
"%select{Clang|C++23}1 extension">,
153-
InGroup<DiagGroup<"delimited-escape-sequence-extension">>;
154-
151+
"%select{delimited|named}0 escape sequences are a %select{C++23|C2y|Clang}1 "
152+
"extension">, InGroup<DiagGroup<"delimited-escape-sequence-extension">>;
155153
def warn_cxx23_delimited_escape_sequence : Warning<
156-
"%select{delimited|named}0 escape sequences are "
157-
"incompatible with C++ standards before C++23">,
158-
InGroup<CXXPre23Compat>, DefaultIgnore;
154+
"%select{delimited|named}0 escape sequences are incompatible with C++ "
155+
"standards before C++23">, InGroup<CXXPre23Compat>, DefaultIgnore;
156+
def warn_c2y_delimited_escape_sequence : Warning<
157+
"delimited escape sequences are incompatible with C standards before C2y">,
158+
InGroup<CPre2yCompat>, DefaultIgnore;
159159

160160
def err_delimited_escape_empty : Error<
161161
"delimited escape sequence cannot be empty">;
@@ -256,6 +256,17 @@ def warn_cxx17_hex_literal : Warning<
256256
"hexadecimal floating literals are incompatible with "
257257
"C++ standards before C++17">,
258258
InGroup<CXXPre17CompatPedantic>, DefaultIgnore;
259+
def ext_octal_literal : Extension<
260+
"octal integer literals are a C2y extension">, InGroup<C2y>;
261+
def ext_cpp_octal_literal : Extension<
262+
"octal integer literals are a Clang extension">,
263+
InGroup<DiagGroup<"octal-prefix-extension">>;
264+
def warn_c2y_compat_octal_literal : Warning<
265+
"octal integer literals are incompatible with standards before C2y">,
266+
InGroup<CPre2yCompat>, DefaultIgnore;
267+
def warn_unprefixed_octal_deprecated : Warning<
268+
"octal literals without a '0o' prefix are deprecated">,
269+
InGroup<DeprecatedOctalLiterals>;
259270
def ext_binary_literal : Extension<
260271
"binary integer literals are a C23 extension">, InGroup<C23>;
261272
def warn_c23_compat_binary_literal : Warning<

clang/include/clang/Driver/OffloadBundler.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,11 @@ class CompressedOffloadBundle {
158158
static llvm::Expected<std::unique_ptr<llvm::MemoryBuffer>>
159159
decompress(const llvm::MemoryBuffer &Input, bool Verbose = false);
160160
};
161+
162+
/// Check whether the bundle id is in the following format:
163+
/// <kind>-<triple>[-<target id>[:target features]]
164+
/// <triple> := <arch>-<vendor>-<os>-<env>
165+
bool checkOffloadBundleID(const llvm::StringRef Str);
161166
} // namespace clang
162167

163168
#endif // LLVM_CLANG_DRIVER_OFFLOADBUNDLER_H

clang/include/clang/Lex/Lexer.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,12 @@ class Lexer : public PreprocessorLexer {
582582
/// sequence.
583583
static bool isNewLineEscaped(const char *BufferStart, const char *Str);
584584

585+
/// Diagnose use of a delimited or named escape sequence.
586+
static void DiagnoseDelimitedOrNamedEscapeSequence(SourceLocation Loc,
587+
bool Named,
588+
const LangOptions &Opts,
589+
DiagnosticsEngine &Diags);
590+
585591
/// Represents a char and the number of bytes parsed to produce it.
586592
struct SizedChar {
587593
char Char;

clang/lib/AST/ByteCode/Interp.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1364,7 +1364,8 @@ static bool checkDestructor(InterpState &S, CodePtr OpPC, const Function *Func,
13641364

13651365
static void compileFunction(InterpState &S, const Function *Func) {
13661366
Compiler<ByteCodeEmitter>(S.getContext(), S.P)
1367-
.compileFunc(Func->getDecl(), const_cast<Function *>(Func));
1367+
.compileFunc(Func->getDecl()->getMostRecentDecl(),
1368+
const_cast<Function *>(Func));
13681369
}
13691370

13701371
bool CallVar(InterpState &S, CodePtr OpPC, const Function *Func,

clang/lib/AST/ItaniumMangle.cpp

Lines changed: 21 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -5327,7 +5327,19 @@ void CXXNameMangler::mangleExpression(const Expr *E, unsigned Arity,
53275327
}
53285328
};
53295329

5330-
switch(SAE->getKind()) {
5330+
auto MangleExtensionBuiltin = [&](const UnaryExprOrTypeTraitExpr *E,
5331+
StringRef Name = {}) {
5332+
if (Name.empty())
5333+
Name = getTraitSpelling(E->getKind());
5334+
mangleVendorType(Name);
5335+
if (SAE->isArgumentType())
5336+
mangleType(SAE->getArgumentType());
5337+
else
5338+
mangleTemplateArgExpr(SAE->getArgumentExpr());
5339+
Out << 'E';
5340+
};
5341+
5342+
switch (SAE->getKind()) {
53315343
case UETT_SizeOf:
53325344
Out << 's';
53335345
MangleAlignofSizeofArg();
@@ -5337,56 +5349,24 @@ void CXXNameMangler::mangleExpression(const Expr *E, unsigned Arity,
53375349
// have acted differently since Clang 8, but were previously mangled the
53385350
// same.)
53395351
if (!isCompatibleWith(LangOptions::ClangABI::Ver11)) {
5340-
Out << "u11__alignof__";
5341-
if (SAE->isArgumentType())
5342-
mangleType(SAE->getArgumentType());
5343-
else
5344-
mangleTemplateArgExpr(SAE->getArgumentExpr());
5345-
Out << 'E';
5352+
MangleExtensionBuiltin(SAE, "__alignof__");
53465353
break;
53475354
}
53485355
[[fallthrough]];
53495356
case UETT_AlignOf:
53505357
Out << 'a';
53515358
MangleAlignofSizeofArg();
53525359
break;
5360+
5361+
case UETT_VectorElements:
5362+
case UETT_OpenMPRequiredSimdAlign:
5363+
case UETT_VecStep:
5364+
case UETT_PtrAuthTypeDiscriminator:
53535365
case UETT_DataSizeOf: {
5354-
DiagnosticsEngine &Diags = Context.getDiags();
5355-
unsigned DiagID =
5356-
Diags.getCustomDiagID(DiagnosticsEngine::Error,
5357-
"cannot yet mangle __datasizeof expression");
5358-
Diags.Report(DiagID);
5359-
return;
5360-
}
5361-
case UETT_PtrAuthTypeDiscriminator: {
5362-
DiagnosticsEngine &Diags = Context.getDiags();
5363-
unsigned DiagID = Diags.getCustomDiagID(
5364-
DiagnosticsEngine::Error,
5365-
"cannot yet mangle __builtin_ptrauth_type_discriminator expression");
5366-
Diags.Report(E->getExprLoc(), DiagID);
5367-
return;
5368-
}
5369-
case UETT_VecStep: {
5370-
DiagnosticsEngine &Diags = Context.getDiags();
5371-
unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error,
5372-
"cannot yet mangle vec_step expression");
5373-
Diags.Report(DiagID);
5374-
return;
5375-
}
5376-
case UETT_OpenMPRequiredSimdAlign: {
5377-
DiagnosticsEngine &Diags = Context.getDiags();
5378-
unsigned DiagID = Diags.getCustomDiagID(
5379-
DiagnosticsEngine::Error,
5380-
"cannot yet mangle __builtin_omp_required_simd_align expression");
5381-
Diags.Report(DiagID);
5382-
return;
5383-
}
5384-
case UETT_VectorElements: {
53855366
DiagnosticsEngine &Diags = Context.getDiags();
53865367
unsigned DiagID = Diags.getCustomDiagID(
5387-
DiagnosticsEngine::Error,
5388-
"cannot yet mangle __builtin_vectorelements expression");
5389-
Diags.Report(DiagID);
5368+
DiagnosticsEngine::Error, "cannot yet mangle %0 expression");
5369+
Diags.Report(E->getExprLoc(), DiagID) << getTraitSpelling(SAE->getKind());
53905370
return;
53915371
}
53925372
}

clang/lib/Driver/OffloadBundler.cpp

Lines changed: 52 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -83,32 +83,27 @@ OffloadTargetInfo::OffloadTargetInfo(const StringRef Target,
8383
const OffloadBundlerConfig &BC)
8484
: BundlerConfig(BC) {
8585

86-
// TODO: Add error checking from ClangOffloadBundler.cpp
87-
auto TargetFeatures = Target.split(':');
88-
auto TripleOrGPU = TargetFeatures.first.rsplit('-');
89-
90-
if (clang::StringToOffloadArch(TripleOrGPU.second) !=
91-
clang::OffloadArch::UNKNOWN) {
92-
auto KindTriple = TripleOrGPU.first.split('-');
93-
this->OffloadKind = KindTriple.first;
94-
95-
// Enforce optional env field to standardize bundles
96-
llvm::Triple t = llvm::Triple(KindTriple.second);
97-
this->Triple = llvm::Triple(t.getArchName(), t.getVendorName(),
98-
t.getOSName(), t.getEnvironmentName());
99-
100-
this->TargetID = Target.substr(Target.find(TripleOrGPU.second));
101-
} else {
102-
auto KindTriple = TargetFeatures.first.split('-');
103-
this->OffloadKind = KindTriple.first;
104-
105-
// Enforce optional env field to standardize bundles
106-
llvm::Triple t = llvm::Triple(KindTriple.second);
107-
this->Triple = llvm::Triple(t.getArchName(), t.getVendorName(),
108-
t.getOSName(), t.getEnvironmentName());
109-
86+
// <kind>-<triple>[-<target id>[:target features]]
87+
// <triple> := <arch>-<vendor>-<os>-<env>
88+
SmallVector<StringRef, 6> Components;
89+
Target.split(Components, '-', /*MaxSplit=*/5);
90+
assert((Components.size() == 5 || Components.size() == 6) &&
91+
"malformed target string");
92+
93+
StringRef TargetIdWithFeature =
94+
Components.size() == 6 ? Components.back() : "";
95+
StringRef TargetId = TargetIdWithFeature.split(':').first;
96+
if (!TargetId.empty() &&
97+
clang::StringToOffloadArch(TargetId) != clang::OffloadArch::UNKNOWN)
98+
this->TargetID = TargetIdWithFeature;
99+
else
110100
this->TargetID = "";
111-
}
101+
102+
this->OffloadKind = Components.front();
103+
ArrayRef<StringRef> TripleSlice{&Components[1], /*length=*/4};
104+
llvm::Triple T = llvm::Triple(llvm::join(TripleSlice, "-"));
105+
this->Triple = llvm::Triple(T.getArchName(), T.getVendorName(), T.getOSName(),
106+
T.getEnvironmentName());
112107
}
113108

114109
bool OffloadTargetInfo::hasHostKind() const {
@@ -148,7 +143,18 @@ bool OffloadTargetInfo::operator==(const OffloadTargetInfo &Target) const {
148143
}
149144

150145
std::string OffloadTargetInfo::str() const {
151-
return Twine(OffloadKind + "-" + Triple.str() + "-" + TargetID).str();
146+
std::string NormalizedTriple;
147+
// Unfortunately we need some special sauce for AMDGPU because all the runtime
148+
// assumes the triple to be "amdgcn-amd-amdhsa-" (empty environment) instead
149+
// of "amdgcn-amd-amdhsa-unknown". It's gonna be very tricky to patch
150+
// different layers of runtime.
151+
if (Triple.isAMDGPU()) {
152+
NormalizedTriple = Triple.normalize(Triple::CanonicalForm::THREE_IDENT);
153+
NormalizedTriple.push_back('-');
154+
} else {
155+
NormalizedTriple = Triple.normalize(Triple::CanonicalForm::FOUR_IDENT);
156+
}
157+
return Twine(OffloadKind + "-" + NormalizedTriple + "-" + TargetID).str();
152158
}
153159

154160
static StringRef getDeviceFileExtension(StringRef Device,
@@ -1507,6 +1513,9 @@ Error OffloadBundler::UnbundleFiles() {
15071513
StringMap<StringRef> Worklist;
15081514
auto Output = BundlerConfig.OutputFileNames.begin();
15091515
for (auto &Triple : BundlerConfig.TargetNames) {
1516+
if (!checkOffloadBundleID(Triple))
1517+
return createStringError(errc::invalid_argument,
1518+
"invalid bundle id from bundle config");
15101519
Worklist[Triple] = *Output;
15111520
++Output;
15121521
}
@@ -1526,6 +1535,9 @@ Error OffloadBundler::UnbundleFiles() {
15261535

15271536
StringRef CurTriple = **CurTripleOrErr;
15281537
assert(!CurTriple.empty());
1538+
if (!checkOffloadBundleID(CurTriple))
1539+
return createStringError(errc::invalid_argument,
1540+
"invalid bundle id read from the bundle");
15291541

15301542
auto Output = Worklist.begin();
15311543
for (auto E = Worklist.end(); Output != E; Output++) {
@@ -1584,6 +1596,8 @@ Error OffloadBundler::UnbundleFiles() {
15841596
return createFileError(E.second, EC);
15851597

15861598
// If this entry has a host kind, copy the input file to the output file.
1599+
// We don't need to check E.getKey() here through checkOffloadBundleID
1600+
// because the entire WorkList has been checked above.
15871601
auto OffloadInfo = OffloadTargetInfo(E.getKey(), BundlerConfig);
15881602
if (OffloadInfo.hasHostKind())
15891603
OutputFile.write(Input.getBufferStart(), Input.getBufferSize());
@@ -1813,6 +1827,10 @@ Error OffloadBundler::UnbundleArchive() {
18131827
// archive.
18141828
while (!CodeObject.empty()) {
18151829
SmallVector<StringRef> CompatibleTargets;
1830+
if (!checkOffloadBundleID(CodeObject)) {
1831+
return createStringError(errc::invalid_argument,
1832+
"Invalid bundle id read from code object");
1833+
}
18161834
auto CodeObjectInfo = OffloadTargetInfo(CodeObject, BundlerConfig);
18171835
if (getCompatibleOffloadTargets(CodeObjectInfo, CompatibleTargets,
18181836
BundlerConfig)) {
@@ -1894,3 +1912,11 @@ Error OffloadBundler::UnbundleArchive() {
18941912

18951913
return Error::success();
18961914
}
1915+
1916+
bool clang::checkOffloadBundleID(const llvm::StringRef Str) {
1917+
// <kind>-<triple>[-<target id>[:target features]]
1918+
// <triple> := <arch>-<vendor>-<os>-<env>
1919+
SmallVector<StringRef, 6> Components;
1920+
Str.split(Components, '-', /*MaxSplit=*/5);
1921+
return Components.size() == 5 || Components.size() == 6;
1922+
}

0 commit comments

Comments
 (0)