Skip to content

Commit 878b266

Browse files
authored
merge main into amd-staging (#598)
2 parents f473089 + 810ebe6 commit 878b266

File tree

137 files changed

+2004
-596
lines changed

Some content is hidden

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

137 files changed

+2004
-596
lines changed

clang-tools-extra/clang-doc/JSONGenerator.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,13 @@ static Object serializeComment(const CommentInfo &I, Object &Description) {
140140
insertComment(Description, TextCommentsArray, "BriefComments");
141141
else if (I.Name == "return")
142142
insertComment(Description, TextCommentsArray, "ReturnComments");
143+
else if (I.Name == "throws" || I.Name == "throw") {
144+
json::Value ThrowsVal = Object();
145+
auto &ThrowsObj = *ThrowsVal.getAsObject();
146+
ThrowsObj["Exception"] = I.Args.front();
147+
ThrowsObj["Children"] = TextCommentsArray;
148+
insertComment(Description, ThrowsVal, "ThrowsComments");
149+
}
143150
return Obj;
144151
}
145152

clang-tools-extra/clang-doc/assets/comment-template.mustache

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,14 @@
5454
</div>
5555
{{/CodeComments}}
5656
{{/HasCodeComments}}
57+
{{#HasThrowsComments}}
58+
<h3>Throws</h3>
59+
{{#ThrowsComments}}
60+
<div>
61+
<b>{{Exception}}</b> {{#Children}}{{TextComment}}{{/Children}}
62+
</div>
63+
{{/ThrowsComments}}
64+
{{/HasThrowsComments}}
5765
{{#BlockCommandComment}}
5866
<div class="block-command-comment__command">
5967
<div class="block-command-command">

clang-tools-extra/test/clang-doc/basic-project.mustache.test

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,10 @@ HTML-CALC: </div>
384384
HTML-CALC: <h3>Returns</h3>
385385
HTML-CALC: <p> double The result of a / b.</p>
386386
HTML-CALC: <p></p>
387-
HTML-CALC: </div>
387+
HTML-CALC: <h3>Throws</h3>
388+
HTML-CALC: <div>
389+
HTML-CALC: <b>std::invalid_argument</b> if b is zero.
390+
HTML-CALC: </div>
388391
HTML-CALC: </div>
389392
HTML-CALC: </div>
390393
HTML-CALC: <div class="delimiter-container">

clang/docs/ReleaseNotes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,10 @@ Non-comprehensive list of changes in this release
307307
allocator-level heap organization strategies. A feature to instrument all
308308
allocation functions with a token ID can be enabled via the
309309
``-fsanitize=alloc-token`` flag.
310+
311+
- A new generic byte swap builtin function ``__builtin_bswapg`` that extends the existing
312+
__builtin_bswap{16,32,64} function family to support all standard integer types.
313+
310314
- A builtin ``__builtin_infer_alloc_token(<args>, ...)`` is provided to allow
311315
compile-time querying of allocation token IDs, where the builtin arguments
312316
mirror those normally passed to an allocation function.

clang/include/clang/Basic/Builtins.td

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,12 @@ def BSwap : Builtin, Template<["unsigned short", "uint32_t", "uint64_t"],
755755
let Prototype = "T(T)";
756756
}
757757

758+
def BSwapg : Builtin {
759+
let Spellings = ["__builtin_bswapg"];
760+
let Attributes = [NoThrow, Const, Constexpr, CustomTypeChecking];
761+
let Prototype = "int(...)";
762+
}
763+
758764
def Bitreverse : BitInt8_16_32_64BuiltinsTemplate, Builtin {
759765
let Spellings = ["__builtin_bitreverse"];
760766
let Attributes = [NoThrow, Const, Constexpr];

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12967,6 +12967,9 @@ def err_builtin_invalid_arg_type: Error<
1296712967
"%plural{0:|: }3"
1296812968
"%plural{[0,3]:type|:types}1 (was %4)">;
1296912969

12970+
def err_bswapg_invalid_bit_width : Error<
12971+
"_BitInt type %0 (%1 bits) must be a multiple of 16 bits for byte swapping">;
12972+
1297012973
def err_builtin_trivially_relocate_invalid_arg_type: Error <
1297112974
"first%select{||| and second}0 argument%select{|||s}0 to "
1297212975
"'__builtin_trivially_relocate' must be"

clang/lib/AST/ByteCode/InterpBuiltin.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -972,9 +972,10 @@ static bool interp__builtin_bswap(InterpState &S, CodePtr OpPC,
972972
const InterpFrame *Frame,
973973
const CallExpr *Call) {
974974
const APSInt &Val = popToAPSInt(S, Call->getArg(0));
975-
assert(Val.getActiveBits() <= 64);
976-
977-
pushInteger(S, Val.byteSwap(), Call->getType());
975+
if (Val.getBitWidth() == 8)
976+
pushInteger(S, Val, Call->getType());
977+
else
978+
pushInteger(S, Val.byteSwap(), Call->getType());
978979
return true;
979980
}
980981

@@ -3687,7 +3688,7 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const CallExpr *Call,
36873688
case Builtin::BI__builtin_elementwise_ctzg:
36883689
return interp__builtin_elementwise_countzeroes(S, OpPC, Frame, Call,
36893690
BuiltinID);
3690-
3691+
case Builtin::BI__builtin_bswapg:
36913692
case Builtin::BI__builtin_bswap16:
36923693
case Builtin::BI__builtin_bswap32:
36933694
case Builtin::BI__builtin_bswap64:

clang/lib/AST/ExprConstant.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15306,13 +15306,15 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const CallExpr *E,
1530615306

1530715307
return Success(Val.reverseBits(), E);
1530815308
}
15309-
15309+
case Builtin::BI__builtin_bswapg:
1531015310
case Builtin::BI__builtin_bswap16:
1531115311
case Builtin::BI__builtin_bswap32:
1531215312
case Builtin::BI__builtin_bswap64: {
1531315313
APSInt Val;
1531415314
if (!EvaluateInteger(E->getArg(0), Val, Info))
1531515315
return false;
15316+
if (Val.getBitWidth() == 8)
15317+
return Success(Val, E);
1531615318

1531715319
return Success(Val.byteSwap(), E);
1531815320
}

clang/lib/Analysis/BodyFarm.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -293,15 +293,14 @@ static CallExpr *create_call_once_lambda_call(ASTContext &C, ASTMaker M,
293293
FunctionDecl *callOperatorDecl = CallbackDecl->getLambdaCallOperator();
294294
assert(callOperatorDecl != nullptr);
295295

296-
DeclRefExpr *callOperatorDeclRef =
297-
DeclRefExpr::Create(/* Ctx =*/ C,
298-
/* QualifierLoc =*/ NestedNameSpecifierLoc(),
299-
/* TemplateKWLoc =*/ SourceLocation(),
300-
const_cast<FunctionDecl *>(callOperatorDecl),
301-
/* RefersToEnclosingVariableOrCapture=*/ false,
302-
/* NameLoc =*/ SourceLocation(),
303-
/* T =*/ callOperatorDecl->getType(),
304-
/* VK =*/ VK_LValue);
296+
DeclRefExpr *callOperatorDeclRef = DeclRefExpr::Create(
297+
/* Ctx =*/C,
298+
/* QualifierLoc =*/NestedNameSpecifierLoc(),
299+
/* TemplateKWLoc =*/SourceLocation(), callOperatorDecl,
300+
/* RefersToEnclosingVariableOrCapture=*/false,
301+
/* NameLoc =*/SourceLocation(),
302+
/* T =*/callOperatorDecl->getType(),
303+
/* VK =*/VK_LValue);
305304

306305
return CXXOperatorCallExpr::Create(
307306
/*AstContext=*/C, OO_Call, callOperatorDeclRef,

clang/lib/CodeGen/CGBuiltin.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3618,6 +3618,19 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
36183618
Builder.CreateArithmeticFence(ArgValue, ConvertType(ArgType)));
36193619
return RValue::get(ArgValue);
36203620
}
3621+
case Builtin::BI__builtin_bswapg: {
3622+
Value *ArgValue = EmitScalarExpr(E->getArg(0));
3623+
llvm::IntegerType *IntTy = cast<llvm::IntegerType>(ArgValue->getType());
3624+
assert(IntTy && "LLVM's __builtin_bswapg only supports integer variants");
3625+
assert(((IntTy->getBitWidth() % 16 == 0 && IntTy->getBitWidth() != 0) ||
3626+
IntTy->getBitWidth() == 8) &&
3627+
"LLVM's __builtin_bswapg only supports integer variants that has a "
3628+
"multiple of 16 bits as well as a single byte");
3629+
if (IntTy->getBitWidth() == 8)
3630+
return RValue::get(ArgValue);
3631+
return RValue::get(
3632+
emitBuiltinWithOneOverloadedType<1>(*this, E, Intrinsic::bswap));
3633+
}
36213634
case Builtin::BI__builtin_bswap16:
36223635
case Builtin::BI__builtin_bswap32:
36233636
case Builtin::BI__builtin_bswap64:

0 commit comments

Comments
 (0)