Skip to content

Commit ca91dd7

Browse files
committed
Merge c3bf73b into cheriot-upstream
2 parents 868eb19 + c3bf73b commit ca91dd7

File tree

423 files changed

+26953
-5889
lines changed

Some content is hidden

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

423 files changed

+26953
-5889
lines changed

.ci/utils.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,15 @@ function at-exit {
2626
mkdir -p artifacts
2727
sccache --show-stats >> artifacts/sccache_stats.txt
2828
cp "${BUILD_DIR}"/.ninja_log artifacts/.ninja_log
29+
cp "${MONOREPO_ROOT}"/*.log artifacts/ || :
2930
cp "${BUILD_DIR}"/test-results.*.xml artifacts/ || :
3031

3132
# If building fails there will be no results files.
3233
shopt -s nullglob
3334

3435
if [[ "$GITHUB_STEP_SUMMARY" != "" ]]; then
3536
python "${MONOREPO_ROOT}"/.ci/generate_test_report_github.py \
36-
$retcode "${BUILD_DIR}"/test-results.*.xml "${BUILD_DIR}"/ninja*.log \
37+
$retcode "${BUILD_DIR}"/test-results.*.xml "${MONOREPO_ROOT}"/ninja*.log \
3738
>> $GITHUB_STEP_SUMMARY
3839
fi
3940
}

clang/docs/LanguageExtensions.rst

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -759,7 +759,8 @@ Unless specified otherwise operation(±0) = ±0 and operation(±infinity) = ±in
759759

760760
The integer elementwise intrinsics, including ``__builtin_elementwise_popcount``,
761761
``__builtin_elementwise_bitreverse``, ``__builtin_elementwise_add_sat``,
762-
``__builtin_elementwise_sub_sat`` can be called in a ``constexpr`` context.
762+
``__builtin_elementwise_sub_sat``, ``__builtin_elementwise_max``,
763+
``__builtin_elementwise_min`` can be called in a ``constexpr`` context.
763764

764765
No implicit promotion of integer types takes place. The mixing of integer types
765766
of different sizes and signs is forbidden in binary and ternary builtins.
@@ -859,6 +860,15 @@ of different sizes and signs is forbidden in binary and ternary builtins.
859860
semantics, see `LangRef
860861
<http://llvm.org/docs/LangRef.html#llvm-min-intrinsics-comparation>`_
861862
for the comparison.
863+
T __builtin_elementwise_fshl(T x, T y, T z) perform a funnel shift left. Concatenate x and y (x is the most integer types
864+
significant bits of the wide value), the combined value is shifted
865+
left by z, and the most significant bits are extracted to produce
866+
a result that is the same size as the original arguments.
867+
868+
T __builtin_elementwise_fshr(T x, T y, T z) perform a funnel shift right. Concatenate x and y (x is the most integer types
869+
significant bits of the wide value), the combined value is shifted
870+
right by z, and the least significant bits are extracted to produce
871+
a result that is the same size as the original arguments.
862872
============================================== ====================================================================== =========================================
863873

864874

clang/docs/ReleaseNotes.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ C23 Feature Support
113113

114114
Non-comprehensive list of changes in this release
115115
-------------------------------------------------
116+
- Added ``__builtin_elementwise_fshl`` and ``__builtin_elementwise_fshr``.
117+
116118
- Added ``__builtin_elementwise_minnumnum`` and ``__builtin_elementwise_maxnumnum``.
117119

118120
- Trapping UBSan (e.g. ``-fsanitize-trap=undefined``) now emits a string describing the reason for
@@ -124,6 +126,9 @@ Non-comprehensive list of changes in this release
124126
This feature is enabled by default but can be disabled by compiling with
125127
``-fno-sanitize-annotate-debug-info-traps``.
126128

129+
- ``__builtin_elementwise_max`` and ``__builtin_elementwise_min`` functions for integer types can
130+
now be used in constant expressions.
131+
127132
New Compiler Flags
128133
------------------
129134
- New option ``-fno-sanitize-annotate-debug-info-traps`` added to disable emitting trap reasons into the debug info when compiling with trapping UBSan (e.g. ``-fsanitize-trap=undefined``).
@@ -295,6 +300,7 @@ Crash and bug fixes
295300
^^^^^^^^^^^^^^^^^^^
296301
- Fixed a crash in the static analyzer that when the expression in an
297302
``[[assume(expr)]]`` attribute was enclosed in parentheses. (#GH151529)
303+
- Fixed a crash when parsing ``#embed`` parameters with unmatched closing brackets. (#GH152829)
298304

299305
Improvements
300306
^^^^^^^^^^^^

clang/include/clang/Basic/Attr.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5077,6 +5077,7 @@ def HLSLResourceBinding: InheritableAttr {
50775077
return SpaceNumber;
50785078
}
50795079
void setImplicitBindingOrderID(uint32_t Value) {
5080+
assert(!hasImplicitBindingOrderID() && "attribute already has implicit binding order id");
50805081
ImplicitBindingOrderID = Value;
50815082
}
50825083
bool hasImplicitBindingOrderID() const {

clang/include/clang/Basic/Builtins.td

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1300,13 +1300,13 @@ def ElementwiseBitreverse : Builtin {
13001300

13011301
def ElementwiseMax : Builtin {
13021302
let Spellings = ["__builtin_elementwise_max"];
1303-
let Attributes = [NoThrow, Const, CustomTypeChecking];
1303+
let Attributes = [NoThrow, Const, CustomTypeChecking, Constexpr];
13041304
let Prototype = "void(...)";
13051305
}
13061306

13071307
def ElementwiseMin : Builtin {
13081308
let Spellings = ["__builtin_elementwise_min"];
1309-
let Attributes = [NoThrow, Const, CustomTypeChecking];
1309+
let Attributes = [NoThrow, Const, CustomTypeChecking, Constexpr];
13101310
let Prototype = "void(...)";
13111311
}
13121312

@@ -1514,6 +1514,18 @@ def ElementwiseSubSat : Builtin {
15141514
let Prototype = "void(...)";
15151515
}
15161516

1517+
def ElementwiseFshl : Builtin {
1518+
let Spellings = ["__builtin_elementwise_fshl"];
1519+
let Attributes = [NoThrow, Const, CustomTypeChecking];
1520+
let Prototype = "void(...)";
1521+
}
1522+
1523+
def ElementwiseFshr : Builtin {
1524+
let Spellings = ["__builtin_elementwise_fshr"];
1525+
let Attributes = [NoThrow, Const, CustomTypeChecking];
1526+
let Prototype = "void(...)";
1527+
}
1528+
15171529
def ReduceMax : Builtin {
15181530
let Spellings = ["__builtin_reduce_max"];
15191531
let Attributes = [NoThrow, Const, CustomTypeChecking, Constexpr];

clang/include/clang/Driver/CommonArgs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ const char *RelocationModelName(llvm::Reloc::Model Model);
8585
std::tuple<llvm::Reloc::Model, unsigned, bool>
8686
ParsePICArgs(const ToolChain &ToolChain, const llvm::opt::ArgList &Args);
8787

88+
bool getStaticPIE(const llvm::opt::ArgList &Args, const ToolChain &TC);
89+
8890
unsigned ParseFunctionAlignment(const ToolChain &TC,
8991
const llvm::opt::ArgList &Args);
9092

clang/lib/AST/ByteCode/InterpBuiltin.cpp

Lines changed: 78 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2259,7 +2259,6 @@ static bool interp__builtin_is_within_lifetime(InterpState &S, CodePtr OpPC,
22592259
static bool interp__builtin_elementwise_sat(InterpState &S, CodePtr OpPC,
22602260
const CallExpr *Call,
22612261
unsigned BuiltinID) {
2262-
Call->dumpColor();
22632262
assert(Call->getNumArgs() == 2);
22642263

22652264
// Single integer case.
@@ -2326,6 +2325,80 @@ static bool interp__builtin_elementwise_sat(InterpState &S, CodePtr OpPC,
23262325
return true;
23272326
}
23282327

2328+
static bool interp__builtin_elementwise_maxmin(InterpState &S, CodePtr OpPC,
2329+
const CallExpr *Call,
2330+
unsigned BuiltinID) {
2331+
assert(Call->getNumArgs() == 2);
2332+
2333+
QualType Arg0Type = Call->getArg(0)->getType();
2334+
2335+
// TODO: Support floating-point types.
2336+
if (!(Arg0Type->isIntegerType() ||
2337+
(Arg0Type->isVectorType() &&
2338+
Arg0Type->castAs<VectorType>()->getElementType()->isIntegerType())))
2339+
return false;
2340+
2341+
if (!Arg0Type->isVectorType()) {
2342+
assert(!Call->getArg(1)->getType()->isVectorType());
2343+
APSInt RHS = popToAPSInt(
2344+
S.Stk, *S.getContext().classify(Call->getArg(1)->getType()));
2345+
APSInt LHS = popToAPSInt(
2346+
S.Stk, *S.getContext().classify(Call->getArg(0)->getType()));
2347+
APInt Result;
2348+
if (BuiltinID == Builtin::BI__builtin_elementwise_max) {
2349+
Result = std::max(LHS, RHS);
2350+
} else if (BuiltinID == Builtin::BI__builtin_elementwise_min) {
2351+
Result = std::min(LHS, RHS);
2352+
} else {
2353+
llvm_unreachable("Wrong builtin ID");
2354+
}
2355+
2356+
pushInteger(S, APSInt(Result, !LHS.isSigned()), Call->getType());
2357+
return true;
2358+
}
2359+
2360+
// Vector case.
2361+
assert(Call->getArg(0)->getType()->isVectorType() &&
2362+
Call->getArg(1)->getType()->isVectorType());
2363+
const auto *VT = Call->getArg(0)->getType()->castAs<VectorType>();
2364+
assert(VT->getElementType() ==
2365+
Call->getArg(1)->getType()->castAs<VectorType>()->getElementType());
2366+
assert(VT->getNumElements() ==
2367+
Call->getArg(1)->getType()->castAs<VectorType>()->getNumElements());
2368+
assert(VT->getElementType()->isIntegralOrEnumerationType());
2369+
2370+
const Pointer &RHS = S.Stk.pop<Pointer>();
2371+
const Pointer &LHS = S.Stk.pop<Pointer>();
2372+
const Pointer &Dst = S.Stk.peek<Pointer>();
2373+
PrimType ElemT = *S.getContext().classify(VT->getElementType());
2374+
unsigned NumElems = VT->getNumElements();
2375+
for (unsigned I = 0; I != NumElems; ++I) {
2376+
APSInt Elem1;
2377+
APSInt Elem2;
2378+
INT_TYPE_SWITCH_NO_BOOL(ElemT, {
2379+
Elem1 = LHS.elem<T>(I).toAPSInt();
2380+
Elem2 = RHS.elem<T>(I).toAPSInt();
2381+
});
2382+
2383+
APSInt Result;
2384+
if (BuiltinID == Builtin::BI__builtin_elementwise_max) {
2385+
Result = APSInt(std::max(Elem1, Elem2),
2386+
Call->getType()->isUnsignedIntegerOrEnumerationType());
2387+
} else if (BuiltinID == Builtin::BI__builtin_elementwise_min) {
2388+
Result = APSInt(std::min(Elem1, Elem2),
2389+
Call->getType()->isUnsignedIntegerOrEnumerationType());
2390+
} else {
2391+
llvm_unreachable("Wrong builtin ID");
2392+
}
2393+
2394+
INT_TYPE_SWITCH_NO_BOOL(ElemT,
2395+
{ Dst.elem<T>(I) = static_cast<T>(Result); });
2396+
}
2397+
Dst.initializeAllElements();
2398+
2399+
return true;
2400+
}
2401+
23292402
bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const CallExpr *Call,
23302403
uint32_t BuiltinID) {
23312404
if (!S.getASTContext().BuiltinInfo.isConstantEvaluated(BuiltinID))
@@ -2733,6 +2806,10 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const CallExpr *Call,
27332806
case Builtin::BI__builtin_elementwise_sub_sat:
27342807
return interp__builtin_elementwise_sat(S, OpPC, Call, BuiltinID);
27352808

2809+
case Builtin::BI__builtin_elementwise_max:
2810+
case Builtin::BI__builtin_elementwise_min:
2811+
return interp__builtin_elementwise_maxmin(S, OpPC, Call, BuiltinID);
2812+
27362813
default:
27372814
S.FFDiag(S.Current->getLocation(OpPC),
27382815
diag::note_invalid_subexpr_in_const_expr)

clang/lib/AST/ExprConstant.cpp

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11728,6 +11728,41 @@ bool VectorExprEvaluator::VisitCallExpr(const CallExpr *E) {
1172811728

1172911729
return Success(APValue(ResultElements.data(), ResultElements.size()), E);
1173011730
}
11731+
case Builtin::BI__builtin_elementwise_max:
11732+
case Builtin::BI__builtin_elementwise_min: {
11733+
APValue SourceLHS, SourceRHS;
11734+
if (!EvaluateAsRValue(Info, E->getArg(0), SourceLHS) ||
11735+
!EvaluateAsRValue(Info, E->getArg(1), SourceRHS))
11736+
return false;
11737+
11738+
QualType DestEltTy = E->getType()->castAs<VectorType>()->getElementType();
11739+
11740+
if (!DestEltTy->isIntegerType())
11741+
return false;
11742+
11743+
unsigned SourceLen = SourceLHS.getVectorLength();
11744+
SmallVector<APValue, 4> ResultElements;
11745+
ResultElements.reserve(SourceLen);
11746+
11747+
for (unsigned EltNum = 0; EltNum < SourceLen; ++EltNum) {
11748+
APSInt LHS = SourceLHS.getVectorElt(EltNum).getInt();
11749+
APSInt RHS = SourceRHS.getVectorElt(EltNum).getInt();
11750+
switch (E->getBuiltinCallee()) {
11751+
case Builtin::BI__builtin_elementwise_max:
11752+
ResultElements.push_back(
11753+
APValue(APSInt(std::max(LHS, RHS),
11754+
DestEltTy->isUnsignedIntegerOrEnumerationType())));
11755+
break;
11756+
case Builtin::BI__builtin_elementwise_min:
11757+
ResultElements.push_back(
11758+
APValue(APSInt(std::min(LHS, RHS),
11759+
DestEltTy->isUnsignedIntegerOrEnumerationType())));
11760+
break;
11761+
}
11762+
}
11763+
11764+
return Success(APValue(ResultElements.data(), ResultElements.size()), E);
11765+
}
1173111766
}
1173211767
}
1173311768

@@ -13626,7 +13661,24 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const CallExpr *E,
1362613661
APInt Result = LHS.isSigned() ? LHS.ssub_sat(RHS) : LHS.usub_sat(RHS);
1362713662
return Success(APSInt(Result, !LHS.isSigned()), E);
1362813663
}
13664+
case Builtin::BI__builtin_elementwise_max: {
13665+
APSInt LHS, RHS;
13666+
if (!EvaluateInteger(E->getArg(0), LHS, Info) ||
13667+
!EvaluateInteger(E->getArg(1), RHS, Info))
13668+
return false;
13669+
13670+
APInt Result = std::max(LHS, RHS);
13671+
return Success(APSInt(Result, !LHS.isSigned()), E);
13672+
}
13673+
case Builtin::BI__builtin_elementwise_min: {
13674+
APSInt LHS, RHS;
13675+
if (!EvaluateInteger(E->getArg(0), LHS, Info) ||
13676+
!EvaluateInteger(E->getArg(1), RHS, Info))
13677+
return false;
1362913678

13679+
APInt Result = std::min(LHS, RHS);
13680+
return Success(APSInt(Result, !LHS.isSigned()), E);
13681+
}
1363013682
case Builtin::BIstrlen:
1363113683
case Builtin::BIwcslen:
1363213684
// A call to strlen is not a constant expression.

clang/lib/Basic/Targets/AVR.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@ class LLVM_LIBRARY_VISIBILITY AVRTargetInfo : public TargetInfo {
5757
Int16Type = SignedInt;
5858
Char32Type = UnsignedLong;
5959
SigAtomicType = SignedChar;
60-
resetDataLayout(
61-
"e-P1-p:16:8-i8:8-i16:8-i32:8-i64:8-f32:8-f64:8-n8-n16:8-a:8");
60+
resetDataLayout("e-P1-p:16:8-i8:8-i16:8-i32:8-i64:8-f32:8-f64:8-n8:16-a:8");
6261
}
6362

6463
void getTargetDefines(const LangOptions &Opts,

clang/lib/CIR/CodeGen/CIRGenCall.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,17 @@ CIRGenFunctionInfo::create(CanQualType resultType,
4242
return fi;
4343
}
4444

45-
cir::FuncType CIRGenTypes::getFunctionType(const CIRGenFunctionInfo &fi) {
46-
mlir::Type resultType = convertType(fi.getReturnType());
45+
cir::FuncType CIRGenTypes::getFunctionType(const CIRGenFunctionInfo &info) {
46+
mlir::Type resultType = convertType(info.getReturnType());
4747
SmallVector<mlir::Type, 8> argTypes;
48-
argTypes.reserve(fi.getNumRequiredArgs());
48+
argTypes.reserve(info.getNumRequiredArgs());
4949

50-
for (const CanQualType &argType : fi.requiredArguments())
50+
for (const CanQualType &argType : info.requiredArguments())
5151
argTypes.push_back(convertType(argType));
5252

5353
return cir::FuncType::get(argTypes,
5454
(resultType ? resultType : builder.getVoidTy()),
55-
fi.isVariadic());
55+
info.isVariadic());
5656
}
5757

5858
CIRGenCallee CIRGenCallee::prepareConcreteCallee(CIRGenFunction &cgf) const {

0 commit comments

Comments
 (0)