Skip to content

Commit 53a7009

Browse files
author
z1_cciauto
authored
merge main into amd-staging (llvm#2459)
2 parents 0de3479 + ac7d4fb commit 53a7009

File tree

189 files changed

+8650
-5208
lines changed

Some content is hidden

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

189 files changed

+8650
-5208
lines changed

clang-tools-extra/docs/clang-tidy/checks/modernize/deprecated-headers.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,5 +79,5 @@ Options
7979
analyzed C++ source file is not included by any other C source files.
8080
Hence, to omit false-positives and wrong fixit-hints, we ignore emitting
8181
reports into header files. One can set this option to `true` if they know
82-
that the header files in the project are only used by C++ source file.
82+
that the header files in the project are only used by C++ source files.
8383
Default is `false`.

clang/docs/LanguageExtensions.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,6 +1001,7 @@ to ``float``; see below for more information on this emulation.
10011001
* X86 (if SSE2 is available; natively if AVX512-FP16 is also available)
10021002
* RISC-V (natively if Zfh or Zhinx is available)
10031003
* SystemZ (emulated)
1004+
* LoongArch (emulated)
10041005

10051006
* ``__bf16`` is supported on the following targets (currently never natively):
10061007

@@ -2042,6 +2043,17 @@ references can be used instead of numeric references.
20422043
return -1;
20432044
}
20442045

2046+
ASM Goto versus Branch Target Enforcement
2047+
=========================================
2048+
2049+
Some target architectures implement branch target enforcement, by requiring
2050+
indirect (register-controlled) branch instructions to jump only to locations
2051+
marked by a special instruction (such as AArch64 ``bti``).
2052+
2053+
The assembler code inside an ``asm goto`` statement is expected not to use a
2054+
branch instruction of that kind to transfer control to any of its destination
2055+
labels. Therefore, using a label in an ``asm goto`` statement does not cause
2056+
clang to put a ``bti`` or equivalent instruction at the label.
20452057

20462058
Constexpr strings in GNU ASM statements
20472059
=======================================

clang/docs/ReleaseNotes.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ Potentially Breaking Changes
4141
- For ARM targets when compiling assembly files, the features included in the selected CPU
4242
or Architecture's FPU are included. If you wish not to use a specific feature,
4343
the relevant ``+no`` option will need to be amended to the command line option.
44+
- When compiling with branch target enforcement, ``asm goto``
45+
statements will no longer guarantee to place a ``bti`` or
46+
``endbr64`` instruction at the labels named as possible branch
47+
destinations, so it is not safe to use a register-controlled branch
48+
instruction to branch to one. (In line with gcc.)
4449

4550
C/C++ Language Potentially Breaking Changes
4651
-------------------------------------------

clang/docs/UsersManual.rst

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3743,6 +3743,35 @@ Doxygen-style comments and ignores ordinary comments starting with ``//`` and
37433743
``-fcomment-block-commands=foo -fcomment-block-commands=bar`` does the same
37443744
as above.
37453745

3746+
.. _ccc-override-options:
3747+
3748+
CCC_OVERRIDE_OPTIONS
3749+
--------------------
3750+
The environment variable ``CCC_OVERRIDE_OPTIONS`` can be used to edit clang's
3751+
command line arguments. The value of this variable is a space-separated list of
3752+
edits to perform. The edits are applied in the order in which they appear in
3753+
``CCC_OVERRIDE_OPTIONS``. Each edit should be one of the following forms:
3754+
3755+
- ``#``: Silence information about the changes to the command line arguments.
3756+
3757+
- ``^FOO``: Add ``FOO`` as a new argument at the beginning of the command line
3758+
right after the name of the compiler executable.
3759+
3760+
- ``+FOO``: Add ``FOO`` as a new argument at the end of the command line.
3761+
3762+
- ``s/XXX/YYY/``: Substitute the regular expression ``XXX`` with ``YYY`` in the
3763+
command line.
3764+
3765+
- ``xOPTION``: Removes all instances of the literal argument ``OPTION``.
3766+
3767+
- ``XOPTION``: Removes all instances of the literal argument ``OPTION``, and the
3768+
following argument.
3769+
3770+
- ``Ox``: Removes all flags matching ``O`` or ``O[sz0-9]`` and adds ``Ox`` at
3771+
the end of the command line.
3772+
3773+
This environment variable does not affect the options added by the config files.
3774+
37463775
.. _c:
37473776

37483777
C Language Features

clang/include/clang/Lex/Preprocessor.h

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,6 @@ enum class EmbedResult {
129129
Empty = 2, // Corresponds to __STDC_EMBED_EMPTY__
130130
};
131131

132-
struct CXXStandardLibraryVersionInfo {
133-
enum Library { Unknown, LibStdCXX };
134-
Library Lib;
135-
unsigned Version;
136-
};
137-
138132
/// Engages in a tight little dance with the lexer to efficiently
139133
/// preprocess tokens.
140134
///
@@ -2712,15 +2706,6 @@ class Preprocessor {
27122706
return IsFileLexer(CurLexer.get(), CurPPLexer);
27132707
}
27142708

2715-
//===--------------------------------------------------------------------===//
2716-
// Standard Library Identification
2717-
std::optional<CXXStandardLibraryVersionInfo> CXXStandardLibraryVersion;
2718-
2719-
public:
2720-
std::optional<unsigned> getStdLibCxxVersion();
2721-
bool NeedsStdLibCxxWorkaroundBefore(unsigned FixedVersion);
2722-
2723-
private:
27242709
//===--------------------------------------------------------------------===//
27252710
// Caching stuff.
27262711
void CachingLex(Token &Result);

clang/lib/Basic/Targets/LoongArch.cpp

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,73 @@ bool LoongArchTargetInfo::handleTargetFeatures(
392392
return true;
393393
}
394394

395+
enum class AttrFeatureKind { Arch, Tune, NoFeature, Feature };
396+
397+
static std::pair<AttrFeatureKind, llvm::StringRef>
398+
getAttrFeatureTypeAndValue(llvm::StringRef AttrFeature) {
399+
if (auto Split = AttrFeature.split("="); !Split.second.empty()) {
400+
if (Split.first.trim() == "arch")
401+
return {AttrFeatureKind::Arch, Split.second.trim()};
402+
if (Split.first.trim() == "tune")
403+
return {AttrFeatureKind::Tune, Split.second.trim()};
404+
}
405+
if (AttrFeature.starts_with("no-"))
406+
return {AttrFeatureKind::NoFeature, AttrFeature.drop_front(3)};
407+
return {AttrFeatureKind::Feature, AttrFeature};
408+
}
409+
410+
ParsedTargetAttr
411+
LoongArchTargetInfo::parseTargetAttr(StringRef Features) const {
412+
ParsedTargetAttr Ret;
413+
if (Features == "default")
414+
return Ret;
415+
SmallVector<StringRef, 1> AttrFeatures;
416+
Features.split(AttrFeatures, ",");
417+
418+
for (auto &Feature : AttrFeatures) {
419+
auto [Kind, Value] = getAttrFeatureTypeAndValue(Feature.trim());
420+
421+
switch (Kind) {
422+
case AttrFeatureKind::Arch: {
423+
if (llvm::LoongArch::isValidArchName(Value) || Value == "la64v1.0" ||
424+
Value == "la64v1.1") {
425+
std::vector<llvm::StringRef> ArchFeatures;
426+
if (llvm::LoongArch::getArchFeatures(Value, ArchFeatures)) {
427+
Ret.Features.insert(Ret.Features.end(), ArchFeatures.begin(),
428+
ArchFeatures.end());
429+
}
430+
431+
if (!Ret.CPU.empty())
432+
Ret.Duplicate = "arch=";
433+
else if (Value == "la64v1.0" || Value == "la64v1.1")
434+
Ret.CPU = "loongarch64";
435+
else
436+
Ret.CPU = Value;
437+
} else {
438+
Ret.Features.push_back("!arch=" + Value.str());
439+
}
440+
break;
441+
}
442+
443+
case AttrFeatureKind::Tune:
444+
if (!Ret.Tune.empty())
445+
Ret.Duplicate = "tune=";
446+
else
447+
Ret.Tune = Value;
448+
break;
449+
450+
case AttrFeatureKind::NoFeature:
451+
Ret.Features.push_back("-" + Value.str());
452+
break;
453+
454+
case AttrFeatureKind::Feature:
455+
Ret.Features.push_back("+" + Value.str());
456+
break;
457+
}
458+
}
459+
return Ret;
460+
}
461+
395462
bool LoongArchTargetInfo::isValidCPUName(StringRef Name) const {
396463
return llvm::LoongArch::isValidCPUName(Name);
397464
}
@@ -400,3 +467,7 @@ void LoongArchTargetInfo::fillValidCPUList(
400467
SmallVectorImpl<StringRef> &Values) const {
401468
llvm::LoongArch::fillValidCPUList(Values);
402469
}
470+
471+
bool LoongArchTargetInfo::isValidFeatureName(StringRef Name) const {
472+
return llvm::LoongArch::isValidFeatureName(Name);
473+
}

clang/lib/Basic/Targets/LoongArch.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class LLVM_LIBRARY_VISIBILITY LoongArchTargetInfo : public TargetInfo {
5353
LongDoubleAlign = 128;
5454
LongDoubleFormat = &llvm::APFloat::IEEEquad();
5555
MCountName = "_mcount";
56+
HasFloat16 = true;
5657
SuitableAlign = 128;
5758
WCharType = SignedInt;
5859
WIntType = UnsignedInt;
@@ -98,9 +99,14 @@ class LLVM_LIBRARY_VISIBILITY LoongArchTargetInfo : public TargetInfo {
9899

99100
bool hasBitIntType() const override { return true; }
100101

102+
bool useFP16ConversionIntrinsics() const override { return false; }
103+
101104
bool handleTargetFeatures(std::vector<std::string> &Features,
102105
DiagnosticsEngine &Diags) override;
103106

107+
ParsedTargetAttr parseTargetAttr(StringRef Str) const override;
108+
bool supportsTargetAttributeTune() const override { return true; }
109+
104110
bool
105111
initFeatureMap(llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags,
106112
StringRef CPU,
@@ -110,6 +116,7 @@ class LLVM_LIBRARY_VISIBILITY LoongArchTargetInfo : public TargetInfo {
110116

111117
bool isValidCPUName(StringRef Name) const override;
112118
void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const override;
119+
bool isValidFeatureName(StringRef Name) const override;
113120
};
114121

115122
class LLVM_LIBRARY_VISIBILITY LoongArch32TargetInfo

clang/lib/CodeGen/CGCall.cpp

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1426,24 +1426,30 @@ void CodeGenFunction::CreateCoercedStore(llvm::Value *Src, Address Dst,
14261426
SrcSize == CGM.getDataLayout().getTypeAllocSize(Dst.getElementType())) {
14271427
// If the value is supposed to be a pointer, convert it before storing it.
14281428
Src = CoerceIntOrPtrToIntOrPtr(Src, Dst.getElementType(), *this);
1429-
Builder.CreateStore(Src, Dst, DstIsVolatile);
1429+
auto *I = Builder.CreateStore(Src, Dst, DstIsVolatile);
1430+
addInstToCurrentSourceAtom(I, Src);
14301431
} else if (llvm::StructType *STy =
14311432
dyn_cast<llvm::StructType>(Src->getType())) {
14321433
// Prefer scalar stores to first-class aggregate stores.
14331434
Dst = Dst.withElementType(SrcTy);
14341435
for (unsigned i = 0, e = STy->getNumElements(); i != e; ++i) {
14351436
Address EltPtr = Builder.CreateStructGEP(Dst, i);
14361437
llvm::Value *Elt = Builder.CreateExtractValue(Src, i);
1437-
Builder.CreateStore(Elt, EltPtr, DstIsVolatile);
1438+
auto *I = Builder.CreateStore(Elt, EltPtr, DstIsVolatile);
1439+
addInstToCurrentSourceAtom(I, Elt);
14381440
}
14391441
} else {
1440-
Builder.CreateStore(Src, Dst.withElementType(SrcTy), DstIsVolatile);
1442+
auto *I =
1443+
Builder.CreateStore(Src, Dst.withElementType(SrcTy), DstIsVolatile);
1444+
addInstToCurrentSourceAtom(I, Src);
14411445
}
14421446
} else if (SrcTy->isIntegerTy()) {
14431447
// If the source is a simple integer, coerce it directly.
14441448
llvm::Type *DstIntTy = Builder.getIntNTy(DstSize.getFixedValue() * 8);
14451449
Src = CoerceIntOrPtrToIntOrPtr(Src, DstIntTy, *this);
1446-
Builder.CreateStore(Src, Dst.withElementType(DstIntTy), DstIsVolatile);
1450+
auto *I =
1451+
Builder.CreateStore(Src, Dst.withElementType(DstIntTy), DstIsVolatile);
1452+
addInstToCurrentSourceAtom(I, Src);
14471453
} else {
14481454
// Otherwise do coercion through memory. This is stupid, but
14491455
// simple.
@@ -1457,10 +1463,11 @@ void CodeGenFunction::CreateCoercedStore(llvm::Value *Src, Address Dst,
14571463
RawAddress Tmp =
14581464
CreateTempAllocaForCoercion(*this, SrcTy, Dst.getAlignment());
14591465
Builder.CreateStore(Src, Tmp);
1460-
Builder.CreateMemCpy(Dst.emitRawPointer(*this),
1461-
Dst.getAlignment().getAsAlign(), Tmp.getPointer(),
1462-
Tmp.getAlignment().getAsAlign(),
1463-
Builder.CreateTypeSize(IntPtrTy, DstSize));
1466+
auto *I = Builder.CreateMemCpy(
1467+
Dst.emitRawPointer(*this), Dst.getAlignment().getAsAlign(),
1468+
Tmp.getPointer(), Tmp.getAlignment().getAsAlign(),
1469+
Builder.CreateTypeSize(IntPtrTy, DstSize));
1470+
addInstToCurrentSourceAtom(I, Src);
14641471
}
14651472
}
14661473

clang/lib/CodeGen/CodeGenFunction.h

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "CGValue.h"
1919
#include "CodeGenModule.h"
2020
#include "EHScopeStack.h"
21+
#include "SanitizerHandler.h"
2122
#include "VarBypassDetector.h"
2223
#include "clang/AST/CharUnits.h"
2324
#include "clang/AST/CurrentSourceLocExprScope.h"
@@ -117,40 +118,6 @@ enum TypeEvaluationKind {
117118
};
118119
// clang-format on
119120

120-
#define LIST_SANITIZER_CHECKS \
121-
SANITIZER_CHECK(AddOverflow, add_overflow, 0) \
122-
SANITIZER_CHECK(BuiltinUnreachable, builtin_unreachable, 0) \
123-
SANITIZER_CHECK(CFICheckFail, cfi_check_fail, 0) \
124-
SANITIZER_CHECK(DivremOverflow, divrem_overflow, 0) \
125-
SANITIZER_CHECK(DynamicTypeCacheMiss, dynamic_type_cache_miss, 0) \
126-
SANITIZER_CHECK(FloatCastOverflow, float_cast_overflow, 0) \
127-
SANITIZER_CHECK(FunctionTypeMismatch, function_type_mismatch, 0) \
128-
SANITIZER_CHECK(ImplicitConversion, implicit_conversion, 0) \
129-
SANITIZER_CHECK(InvalidBuiltin, invalid_builtin, 0) \
130-
SANITIZER_CHECK(InvalidObjCCast, invalid_objc_cast, 0) \
131-
SANITIZER_CHECK(LoadInvalidValue, load_invalid_value, 0) \
132-
SANITIZER_CHECK(MissingReturn, missing_return, 0) \
133-
SANITIZER_CHECK(MulOverflow, mul_overflow, 0) \
134-
SANITIZER_CHECK(NegateOverflow, negate_overflow, 0) \
135-
SANITIZER_CHECK(NullabilityArg, nullability_arg, 0) \
136-
SANITIZER_CHECK(NullabilityReturn, nullability_return, 1) \
137-
SANITIZER_CHECK(NonnullArg, nonnull_arg, 0) \
138-
SANITIZER_CHECK(NonnullReturn, nonnull_return, 1) \
139-
SANITIZER_CHECK(OutOfBounds, out_of_bounds, 0) \
140-
SANITIZER_CHECK(PointerOverflow, pointer_overflow, 0) \
141-
SANITIZER_CHECK(ShiftOutOfBounds, shift_out_of_bounds, 0) \
142-
SANITIZER_CHECK(SubOverflow, sub_overflow, 0) \
143-
SANITIZER_CHECK(TypeMismatch, type_mismatch, 1) \
144-
SANITIZER_CHECK(AlignmentAssumption, alignment_assumption, 0) \
145-
SANITIZER_CHECK(VLABoundNotPositive, vla_bound_not_positive, 0) \
146-
SANITIZER_CHECK(BoundsSafety, bounds_safety, 0)
147-
148-
enum SanitizerHandler {
149-
#define SANITIZER_CHECK(Enum, Name, Version) Enum,
150-
LIST_SANITIZER_CHECKS
151-
#undef SANITIZER_CHECK
152-
};
153-
154121
/// Helper class with most of the code for saving a value for a
155122
/// conditional expression cleanup.
156123
struct DominatingLLVMValue {

clang/lib/CodeGen/SanitizerHandler.h

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
//===-- SanitizerHandler.h - Definition of sanitizer handlers ---*- 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+
// This is the internal per-function state used for llvm translation.
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#ifndef LLVM_CLANG_LIB_CODEGEN_SANITIZER_HANDLER_H
14+
#define LLVM_CLANG_LIB_CODEGEN_SANITIZER_HANDLER_H
15+
16+
#define LIST_SANITIZER_CHECKS \
17+
SANITIZER_CHECK(AddOverflow, add_overflow, 0) \
18+
SANITIZER_CHECK(BuiltinUnreachable, builtin_unreachable, 0) \
19+
SANITIZER_CHECK(CFICheckFail, cfi_check_fail, 0) \
20+
SANITIZER_CHECK(DivremOverflow, divrem_overflow, 0) \
21+
SANITIZER_CHECK(DynamicTypeCacheMiss, dynamic_type_cache_miss, 0) \
22+
SANITIZER_CHECK(FloatCastOverflow, float_cast_overflow, 0) \
23+
SANITIZER_CHECK(FunctionTypeMismatch, function_type_mismatch, 0) \
24+
SANITIZER_CHECK(ImplicitConversion, implicit_conversion, 0) \
25+
SANITIZER_CHECK(InvalidBuiltin, invalid_builtin, 0) \
26+
SANITIZER_CHECK(InvalidObjCCast, invalid_objc_cast, 0) \
27+
SANITIZER_CHECK(LoadInvalidValue, load_invalid_value, 0) \
28+
SANITIZER_CHECK(MissingReturn, missing_return, 0) \
29+
SANITIZER_CHECK(MulOverflow, mul_overflow, 0) \
30+
SANITIZER_CHECK(NegateOverflow, negate_overflow, 0) \
31+
SANITIZER_CHECK(NullabilityArg, nullability_arg, 0) \
32+
SANITIZER_CHECK(NullabilityReturn, nullability_return, 1) \
33+
SANITIZER_CHECK(NonnullArg, nonnull_arg, 0) \
34+
SANITIZER_CHECK(NonnullReturn, nonnull_return, 1) \
35+
SANITIZER_CHECK(OutOfBounds, out_of_bounds, 0) \
36+
SANITIZER_CHECK(PointerOverflow, pointer_overflow, 0) \
37+
SANITIZER_CHECK(ShiftOutOfBounds, shift_out_of_bounds, 0) \
38+
SANITIZER_CHECK(SubOverflow, sub_overflow, 0) \
39+
SANITIZER_CHECK(TypeMismatch, type_mismatch, 1) \
40+
SANITIZER_CHECK(AlignmentAssumption, alignment_assumption, 0) \
41+
SANITIZER_CHECK(VLABoundNotPositive, vla_bound_not_positive, 0) \
42+
SANITIZER_CHECK(BoundsSafety, bounds_safety, 0)
43+
44+
enum SanitizerHandler {
45+
#define SANITIZER_CHECK(Enum, Name, Version) Enum,
46+
LIST_SANITIZER_CHECKS
47+
#undef SANITIZER_CHECK
48+
};
49+
50+
#endif // LLVM_CLANG_LIB_CODEGEN_SANITIZER_HANDLER_H

clang/lib/CodeGen/Targets/LoongArch.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,9 @@ bool LoongArchABIInfo::detectFARsEligibleStructHelper(
110110
uint64_t Size = getContext().getTypeSize(Ty);
111111
if (IsInt && Size > GRLen)
112112
return false;
113-
// Can't be eligible if larger than the FP registers. Half precision isn't
114-
// currently supported on LoongArch and the ABI hasn't been confirmed, so
115-
// default to the integer ABI in that case.
116-
if (IsFloat && (Size > FRLen || Size < 32))
113+
// Can't be eligible if larger than the FP registers. Handling of half
114+
// precision values has been specified in the ABI, so don't block those.
115+
if (IsFloat && Size > FRLen)
117116
return false;
118117
// Can't be eligible if an integer type was already found (int+int pairs
119118
// are not eligible).

0 commit comments

Comments
 (0)