Skip to content

Commit 2657f76

Browse files
committed
Cleanup
1 parent 24b5867 commit 2657f76

File tree

2 files changed

+26
-23
lines changed

2 files changed

+26
-23
lines changed

clang/include/clang/Sema/Sema.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2819,34 +2819,35 @@ class Sema final : public SemaBase {
28192819

28202820
/// BuiltinConstantArg - Handle a check if argument ArgNum of CallExpr
28212821
/// TheCall is a constant expression.
2822-
bool BuiltinConstantArg(CallExpr *TheCall, int ArgNum, llvm::APSInt &Result);
2822+
bool BuiltinConstantArg(CallExpr *TheCall, unsigned ArgNum,
2823+
llvm::APSInt &Result);
28232824

28242825
/// BuiltinConstantArgRange - Handle a check if argument ArgNum of CallExpr
28252826
/// TheCall is a constant expression in the range [Low, High].
2826-
bool BuiltinConstantArgRange(CallExpr *TheCall, int ArgNum, int Low, int High,
2827-
bool RangeIsError = true);
2827+
bool BuiltinConstantArgRange(CallExpr *TheCall, unsigned ArgNum, int Low,
2828+
int High, bool RangeIsError = true);
28282829

28292830
/// BuiltinConstantArgMultiple - Handle a check if argument ArgNum of CallExpr
28302831
/// TheCall is a constant expression is a multiple of Num..
2831-
bool BuiltinConstantArgMultiple(CallExpr *TheCall, int ArgNum,
2832+
bool BuiltinConstantArgMultiple(CallExpr *TheCall, unsigned ArgNum,
28322833
unsigned Multiple);
28332834

28342835
/// BuiltinConstantArgPower2 - Check if argument ArgNum of TheCall is a
28352836
/// constant expression representing a power of 2.
2836-
bool BuiltinConstantArgPower2(CallExpr *TheCall, int ArgNum);
2837+
bool BuiltinConstantArgPower2(CallExpr *TheCall, unsigned ArgNum);
28372838

28382839
/// BuiltinConstantArgShiftedByte - Check if argument ArgNum of TheCall is
28392840
/// a constant expression representing an arbitrary byte value shifted left by
28402841
/// a multiple of 8 bits.
2841-
bool BuiltinConstantArgShiftedByte(CallExpr *TheCall, int ArgNum,
2842+
bool BuiltinConstantArgShiftedByte(CallExpr *TheCall, unsigned ArgNum,
28422843
unsigned ArgBits);
28432844

28442845
/// BuiltinConstantArgShiftedByteOr0xFF - Check if argument ArgNum of
28452846
/// TheCall is a constant expression representing either a shifted byte value,
28462847
/// or a value of the form 0x??FF (i.e. a member of the arithmetic progression
28472848
/// 0x00FF, 0x01FF, ..., 0xFFFF). This strange range check is needed for some
28482849
/// Arm MVE intrinsics.
2849-
bool BuiltinConstantArgShiftedByteOrXXFF(CallExpr *TheCall, int ArgNum,
2850+
bool BuiltinConstantArgShiftedByteOrXXFF(CallExpr *TheCall, unsigned ArgNum,
28502851
unsigned ArgBits);
28512852

28522853
/// Checks that a call expression's argument count is at least the desired

clang/lib/Sema/SemaChecking.cpp

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5618,8 +5618,8 @@ ExprResult Sema::BuiltinShuffleVector(CallExpr *TheCall) {
56185618
if (Arg->isTypeDependent() || Arg->isValueDependent())
56195619
continue;
56205620

5621-
std::optional<llvm::APSInt> Result;
5622-
if (!(Result = Arg->getIntegerConstantExpr(Context)))
5621+
std::optional<llvm::APSInt> Result = Arg->getIntegerConstantExpr(Context);
5622+
if (!Result)
56235623
return ExprError(Diag(TheCall->getBeginLoc(),
56245624
diag::err_shufflevector_nonconstant_argument)
56255625
<< Arg->getSourceRange());
@@ -5886,23 +5886,26 @@ bool Sema::BuiltinOSLogFormat(CallExpr *TheCall) {
58865886
return false;
58875887
}
58885888

5889-
bool Sema::BuiltinConstantArg(CallExpr *TheCall, int ArgNum,
5889+
bool Sema::BuiltinConstantArg(CallExpr *TheCall, unsigned ArgNum,
58905890
llvm::APSInt &Result) {
58915891
Expr *Arg = TheCall->getArg(ArgNum);
5892-
DeclRefExpr *DRE =cast<DeclRefExpr>(TheCall->getCallee()->IgnoreParenCasts());
5893-
FunctionDecl *FDecl = cast<FunctionDecl>(DRE->getDecl());
58945892

5895-
if (Arg->isTypeDependent() || Arg->isValueDependent()) return false;
5893+
if (Arg->isTypeDependent() || Arg->isValueDependent())
5894+
return false;
58965895

5897-
std::optional<llvm::APSInt> R;
5898-
if (!(R = Arg->getIntegerConstantExpr(Context)))
5896+
std::optional<llvm::APSInt> R = Arg->getIntegerConstantExpr(Context);
5897+
if (!R) {
5898+
auto *DRE = cast<DeclRefExpr>(TheCall->getCallee()->IgnoreParenCasts());
5899+
auto *FDecl = cast<FunctionDecl>(DRE->getDecl());
58995900
return Diag(TheCall->getBeginLoc(), diag::err_constant_integer_arg_type)
59005901
<< FDecl->getDeclName() << Arg->getSourceRange();
5902+
}
59015903
Result = *R;
5904+
59025905
return false;
59035906
}
59045907

5905-
bool Sema::BuiltinConstantArgRange(CallExpr *TheCall, int ArgNum, int Low,
5908+
bool Sema::BuiltinConstantArgRange(CallExpr *TheCall, unsigned ArgNum, int Low,
59065909
int High, bool RangeIsError) {
59075910
if (isConstantEvaluatedContext())
59085911
return false;
@@ -5933,7 +5936,7 @@ bool Sema::BuiltinConstantArgRange(CallExpr *TheCall, int ArgNum, int Low,
59335936
return false;
59345937
}
59355938

5936-
bool Sema::BuiltinConstantArgMultiple(CallExpr *TheCall, int ArgNum,
5939+
bool Sema::BuiltinConstantArgMultiple(CallExpr *TheCall, unsigned ArgNum,
59375940
unsigned Num) {
59385941
llvm::APSInt Result;
59395942

@@ -5953,7 +5956,7 @@ bool Sema::BuiltinConstantArgMultiple(CallExpr *TheCall, int ArgNum,
59535956
return false;
59545957
}
59555958

5956-
bool Sema::BuiltinConstantArgPower2(CallExpr *TheCall, int ArgNum) {
5959+
bool Sema::BuiltinConstantArgPower2(CallExpr *TheCall, unsigned ArgNum) {
59575960
llvm::APSInt Result;
59585961

59595962
// We can't check the value of a dependent argument.
@@ -5965,9 +5968,7 @@ bool Sema::BuiltinConstantArgPower2(CallExpr *TheCall, int ArgNum) {
59655968
if (BuiltinConstantArg(TheCall, ArgNum, Result))
59665969
return true;
59675970

5968-
// Bit-twiddling to test for a power of 2: for x > 0, x & (x-1) is zero if
5969-
// and only if x is a power of 2.
5970-
if (Result.isStrictlyPositive() && (Result & (Result - 1)) == 0)
5971+
if (Result.isPowerOf2())
59715972
return false;
59725973

59735974
return Diag(TheCall->getBeginLoc(), diag::err_argument_not_power_of_2)
@@ -5996,7 +5997,7 @@ static bool IsShiftedByte(llvm::APSInt Value) {
59965997
}
59975998
}
59985999

5999-
bool Sema::BuiltinConstantArgShiftedByte(CallExpr *TheCall, int ArgNum,
6000+
bool Sema::BuiltinConstantArgShiftedByte(CallExpr *TheCall, unsigned ArgNum,
60006001
unsigned ArgBits) {
60016002
llvm::APSInt Result;
60026003

@@ -6020,7 +6021,8 @@ bool Sema::BuiltinConstantArgShiftedByte(CallExpr *TheCall, int ArgNum,
60206021
<< Arg->getSourceRange();
60216022
}
60226023

6023-
bool Sema::BuiltinConstantArgShiftedByteOrXXFF(CallExpr *TheCall, int ArgNum,
6024+
bool Sema::BuiltinConstantArgShiftedByteOrXXFF(CallExpr *TheCall,
6025+
unsigned ArgNum,
60246026
unsigned ArgBits) {
60256027
llvm::APSInt Result;
60266028

0 commit comments

Comments
 (0)