Skip to content

Commit d06f631

Browse files
committed
Merge from 'master' to 'sycl-web' (#1)
CONFLICT (content): Merge conflict in clang/lib/Sema/SemaStmtAttr.cpp
2 parents 5465fc0 + c943329 commit d06f631

14 files changed

+272
-252
lines changed

clang/include/clang/AST/Expr.h

+7-6
Original file line numberDiff line numberDiff line change
@@ -510,15 +510,16 @@ class Expr : public ValueStmt {
510510
/// semantically correspond to a bool.
511511
bool isKnownToHaveBooleanValue(bool Semantic = true) const;
512512

513-
/// isIntegerConstantExpr - Return the value if this expression is a valid
514-
/// integer constant expression. If not a valid i-c-e, return None and fill
515-
/// in Loc (if specified) with the location of the invalid expression.
513+
/// isIntegerConstantExpr - Return true if this expression is a valid integer
514+
/// constant expression, and, if so, return its value in Result. If not a
515+
/// valid i-c-e, return false and fill in Loc (if specified) with the location
516+
/// of the invalid expression.
516517
///
517518
/// Note: This does not perform the implicit conversions required by C++11
518519
/// [expr.const]p5.
519-
Optional<llvm::APSInt> getIntegerConstantExpr(const ASTContext &Ctx,
520-
SourceLocation *Loc = nullptr,
521-
bool isEvaluated = true) const;
520+
bool isIntegerConstantExpr(llvm::APSInt &Result, const ASTContext &Ctx,
521+
SourceLocation *Loc = nullptr,
522+
bool isEvaluated = true) const;
522523
bool isIntegerConstantExpr(const ASTContext &Ctx,
523524
SourceLocation *Loc = nullptr) const;
524525

clang/lib/AST/ASTContext.cpp

+9-7
Original file line numberDiff line numberDiff line change
@@ -9496,15 +9496,17 @@ QualType ASTContext::mergeTypes(QualType LHS, QualType RHS,
94969496
const ConstantArrayType* CAT)
94979497
-> std::pair<bool,llvm::APInt> {
94989498
if (VAT) {
9499-
Optional<llvm::APSInt> TheInt;
9499+
llvm::APSInt TheInt;
95009500
Expr *E = VAT->getSizeExpr();
9501-
if (E && (TheInt = E->getIntegerConstantExpr(*this)))
9502-
return std::make_pair(true, *TheInt);
9503-
return std::make_pair(false, llvm::APSInt());
9501+
if (E && E->isIntegerConstantExpr(TheInt, *this))
9502+
return std::make_pair(true, TheInt);
9503+
else
9504+
return std::make_pair(false, TheInt);
9505+
} else if (CAT) {
9506+
return std::make_pair(true, CAT->getSize());
9507+
} else {
9508+
return std::make_pair(false, llvm::APInt());
95049509
}
9505-
if (CAT)
9506-
return std::make_pair(true, CAT->getSize());
9507-
return std::make_pair(false, llvm::APInt());
95089510
};
95099511

95109512
bool HaveLSize, HaveRSize;

clang/lib/AST/ExprConstant.cpp

+7-12
Original file line numberDiff line numberDiff line change
@@ -14888,22 +14888,16 @@ bool Expr::isIntegerConstantExpr(const ASTContext &Ctx,
1488814888
return true;
1488914889
}
1489014890

14891-
Optional<llvm::APSInt> Expr::getIntegerConstantExpr(const ASTContext &Ctx,
14892-
SourceLocation *Loc,
14893-
bool isEvaluated) const {
14891+
bool Expr::isIntegerConstantExpr(llvm::APSInt &Value, const ASTContext &Ctx,
14892+
SourceLocation *Loc, bool isEvaluated) const {
1489414893
assert(!isValueDependent() &&
1489514894
"Expression evaluator can't be called on a dependent expression.");
1489614895

14897-
APSInt Value;
14898-
14899-
if (Ctx.getLangOpts().CPlusPlus11) {
14900-
if (EvaluateCPlusPlus11IntegralConstantExpr(Ctx, this, &Value, Loc))
14901-
return Value;
14902-
return None;
14903-
}
14896+
if (Ctx.getLangOpts().CPlusPlus11)
14897+
return EvaluateCPlusPlus11IntegralConstantExpr(Ctx, this, &Value, Loc);
1490414898

1490514899
if (!isIntegerConstantExpr(Ctx, Loc))
14906-
return None;
14900+
return false;
1490714901

1490814902
// The only possible side-effects here are due to UB discovered in the
1490914903
// evaluation (for instance, INT_MAX + 1). In such a case, we are still
@@ -14917,7 +14911,8 @@ Optional<llvm::APSInt> Expr::getIntegerConstantExpr(const ASTContext &Ctx,
1491714911
if (!::EvaluateAsInt(this, ExprResult, Ctx, SE_AllowSideEffects, Info))
1491814912
llvm_unreachable("ICE cannot be evaluated!");
1491914913

14920-
return ExprResult.Val.getInt();
14914+
Value = ExprResult.Val.getInt();
14915+
return true;
1492114916
}
1492214917

1492314918
bool Expr::isCXX98IntegralConstantExpr(const ASTContext &Ctx) const {

clang/lib/AST/MicrosoftMangle.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -1372,9 +1372,9 @@ void MicrosoftCXXNameMangler::mangleIntegerLiteral(const llvm::APSInt &Value,
13721372

13731373
void MicrosoftCXXNameMangler::mangleExpression(const Expr *E) {
13741374
// See if this is a constant expression.
1375-
if (Optional<llvm::APSInt> Value =
1376-
E->getIntegerConstantExpr(Context.getASTContext())) {
1377-
mangleIntegerLiteral(*Value, E->getType()->isBooleanType());
1375+
llvm::APSInt Value;
1376+
if (E->isIntegerConstantExpr(Value, Context.getASTContext())) {
1377+
mangleIntegerLiteral(Value, E->getType()->isBooleanType());
13781378
return;
13791379
}
13801380

clang/lib/CodeGen/CGBuiltin.cpp

+65-49
Original file line numberDiff line numberDiff line change
@@ -4425,9 +4425,11 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
44254425
} else {
44264426
// If this is required to be a constant, constant fold it so that we
44274427
// know that the generated intrinsic gets a ConstantInt.
4428-
ArgValue = llvm::ConstantInt::get(
4429-
getLLVMContext(),
4430-
*E->getArg(i)->getIntegerConstantExpr(getContext()));
4428+
llvm::APSInt Result;
4429+
bool IsConst = E->getArg(i)->isIntegerConstantExpr(Result,getContext());
4430+
assert(IsConst && "Constant arg isn't actually constant?");
4431+
(void)IsConst;
4432+
ArgValue = llvm::ConstantInt::get(getLLVMContext(), Result);
44314433
}
44324434

44334435
// If the intrinsic arg type is different from the builtin arg type
@@ -5600,14 +5602,13 @@ Value *CodeGenFunction::EmitCommonNeonBuiltinExpr(
56005602
SmallVectorImpl<llvm::Value *> &Ops, Address PtrOp0, Address PtrOp1,
56015603
llvm::Triple::ArchType Arch) {
56025604
// Get the last argument, which specifies the vector type.
5605+
llvm::APSInt NeonTypeConst;
56035606
const Expr *Arg = E->getArg(E->getNumArgs() - 1);
5604-
Optional<llvm::APSInt> NeonTypeConst =
5605-
Arg->getIntegerConstantExpr(getContext());
5606-
if (!NeonTypeConst)
5607+
if (!Arg->isIntegerConstantExpr(NeonTypeConst, getContext()))
56075608
return nullptr;
56085609

56095610
// Determine the type of this overloaded NEON intrinsic.
5610-
NeonTypeFlags Type(NeonTypeConst->getZExtValue());
5611+
NeonTypeFlags Type(NeonTypeConst.getZExtValue());
56115612
bool Usgn = Type.isUnsigned();
56125613
bool Quad = Type.isQuad();
56135614
const bool HasLegalHalfType = getTarget().hasLegalHalfType();
@@ -6890,9 +6891,10 @@ Value *CodeGenFunction::EmitARMBuiltinExpr(unsigned BuiltinID,
68906891
} else {
68916892
// If this is required to be a constant, constant fold it so that we know
68926893
// that the generated intrinsic gets a ConstantInt.
6893-
Ops.push_back(llvm::ConstantInt::get(
6894-
getLLVMContext(),
6895-
*E->getArg(i)->getIntegerConstantExpr(getContext())));
6894+
llvm::APSInt Result;
6895+
bool IsConst = E->getArg(i)->isIntegerConstantExpr(Result, getContext());
6896+
assert(IsConst && "Constant arg isn't actually constant?"); (void)IsConst;
6897+
Ops.push_back(llvm::ConstantInt::get(getLLVMContext(), Result));
68966898
}
68976899
}
68986900

@@ -7103,9 +7105,9 @@ Value *CodeGenFunction::EmitARMBuiltinExpr(unsigned BuiltinID,
71037105

71047106
// Get the last argument, which specifies the vector type.
71057107
assert(HasExtraArg);
7108+
llvm::APSInt Result;
71067109
const Expr *Arg = E->getArg(E->getNumArgs()-1);
7107-
Optional<llvm::APSInt> Result = Arg->getIntegerConstantExpr(getContext());
7108-
if (!Result)
7110+
if (!Arg->isIntegerConstantExpr(Result, getContext()))
71097111
return nullptr;
71107112

71117113
if (BuiltinID == ARM::BI__builtin_arm_vcvtr_f ||
@@ -7118,7 +7120,7 @@ Value *CodeGenFunction::EmitARMBuiltinExpr(unsigned BuiltinID,
71187120
Ty = DoubleTy;
71197121

71207122
// Determine whether this is an unsigned conversion or not.
7121-
bool usgn = Result->getZExtValue() == 1;
7123+
bool usgn = Result.getZExtValue() == 1;
71227124
unsigned Int = usgn ? Intrinsic::arm_vcvtru : Intrinsic::arm_vcvtr;
71237125

71247126
// Call the appropriate intrinsic.
@@ -7127,7 +7129,7 @@ Value *CodeGenFunction::EmitARMBuiltinExpr(unsigned BuiltinID,
71277129
}
71287130

71297131
// Determine the type of this overloaded NEON intrinsic.
7130-
NeonTypeFlags Type = Result->getZExtValue();
7132+
NeonTypeFlags Type(Result.getZExtValue());
71317133
bool usgn = Type.isUnsigned();
71327134
bool rightShift = false;
71337135

@@ -7271,7 +7273,11 @@ Value *CodeGenFunction::EmitARMBuiltinExpr(unsigned BuiltinID,
72717273

72727274
template<typename Integer>
72737275
static Integer GetIntegerConstantValue(const Expr *E, ASTContext &Context) {
7274-
return E->getIntegerConstantExpr(Context)->getExtValue();
7276+
llvm::APSInt IntVal;
7277+
bool IsConst = E->isIntegerConstantExpr(IntVal, Context);
7278+
assert(IsConst && "Sema should have checked this was a constant");
7279+
(void)IsConst;
7280+
return IntVal.getExtValue();
72757281
}
72767282

72777283
static llvm::Value *SignOrZeroExtend(CGBuilderTy &Builder, llvm::Value *V,
@@ -7544,13 +7550,13 @@ static Value *EmitAArch64TblBuiltinExpr(CodeGenFunction &CGF, unsigned BuiltinID
75447550
assert(E->getNumArgs() >= 3);
75457551

75467552
// Get the last argument, which specifies the vector type.
7553+
llvm::APSInt Result;
75477554
const Expr *Arg = E->getArg(E->getNumArgs() - 1);
7548-
Optional<llvm::APSInt> Result = Arg->getIntegerConstantExpr(CGF.getContext());
7549-
if (!Result)
7555+
if (!Arg->isIntegerConstantExpr(Result, CGF.getContext()))
75507556
return nullptr;
75517557

75527558
// Determine the type of this overloaded NEON intrinsic.
7553-
NeonTypeFlags Type = Result->getZExtValue();
7559+
NeonTypeFlags Type(Result.getZExtValue());
75547560
llvm::VectorType *Ty = GetNeonType(&CGF, Type);
75557561
if (!Ty)
75567562
return nullptr;
@@ -8936,9 +8942,11 @@ Value *CodeGenFunction::EmitAArch64BuiltinExpr(unsigned BuiltinID,
89368942
} else {
89378943
// If this is required to be a constant, constant fold it so that we know
89388944
// that the generated intrinsic gets a ConstantInt.
8939-
Ops.push_back(llvm::ConstantInt::get(
8940-
getLLVMContext(),
8941-
*E->getArg(i)->getIntegerConstantExpr(getContext())));
8945+
llvm::APSInt Result;
8946+
bool IsConst = E->getArg(i)->isIntegerConstantExpr(Result, getContext());
8947+
assert(IsConst && "Constant arg isn't actually constant?");
8948+
(void)IsConst;
8949+
Ops.push_back(llvm::ConstantInt::get(getLLVMContext(), Result));
89428950
}
89438951
}
89448952

@@ -8953,11 +8961,12 @@ Value *CodeGenFunction::EmitAArch64BuiltinExpr(unsigned BuiltinID,
89538961
return Result;
89548962
}
89558963

8964+
llvm::APSInt Result;
89568965
const Expr *Arg = E->getArg(E->getNumArgs()-1);
89578966
NeonTypeFlags Type(0);
8958-
if (Optional<llvm::APSInt> Result = Arg->getIntegerConstantExpr(getContext()))
8967+
if (Arg->isIntegerConstantExpr(Result, getContext()))
89598968
// Determine the type of this overloaded NEON intrinsic.
8960-
Type = NeonTypeFlags(Result->getZExtValue());
8969+
Type = NeonTypeFlags(Result.getZExtValue());
89618970

89628971
bool usgn = Type.isUnsigned();
89638972
bool quad = Type.isQuad();
@@ -11788,8 +11797,10 @@ Value *CodeGenFunction::EmitX86BuiltinExpr(unsigned BuiltinID,
1178811797

1178911798
// If this is required to be a constant, constant fold it so that we know
1179011799
// that the generated intrinsic gets a ConstantInt.
11791-
Ops.push_back(llvm::ConstantInt::get(
11792-
getLLVMContext(), *E->getArg(i)->getIntegerConstantExpr(getContext())));
11800+
llvm::APSInt Result;
11801+
bool IsConst = E->getArg(i)->isIntegerConstantExpr(Result, getContext());
11802+
assert(IsConst && "Constant arg isn't actually constant?"); (void)IsConst;
11803+
Ops.push_back(llvm::ConstantInt::get(getLLVMContext(), Result));
1179311804
}
1179411805

1179511806
// These exist so that the builtin that takes an immediate can be bounds
@@ -15068,8 +15079,11 @@ Value *CodeGenFunction::EmitSystemZBuiltinExpr(unsigned BuiltinID,
1506815079
llvm::Type *ResultType = ConvertType(E->getType());
1506915080
Value *X = EmitScalarExpr(E->getArg(0));
1507015081
// Constant-fold the M4 and M5 mask arguments.
15071-
llvm::APSInt M4 = *E->getArg(1)->getIntegerConstantExpr(getContext());
15072-
llvm::APSInt M5 = *E->getArg(2)->getIntegerConstantExpr(getContext());
15082+
llvm::APSInt M4, M5;
15083+
bool IsConstM4 = E->getArg(1)->isIntegerConstantExpr(M4, getContext());
15084+
bool IsConstM5 = E->getArg(2)->isIntegerConstantExpr(M5, getContext());
15085+
assert(IsConstM4 && IsConstM5 && "Constant arg isn't actually constant?");
15086+
(void)IsConstM4; (void)IsConstM5;
1507315087
// Check whether this instance can be represented via a LLVM standard
1507415088
// intrinsic. We only support some combinations of M4 and M5.
1507515089
Intrinsic::ID ID = Intrinsic::not_intrinsic;
@@ -15124,7 +15138,10 @@ Value *CodeGenFunction::EmitSystemZBuiltinExpr(unsigned BuiltinID,
1512415138
Value *X = EmitScalarExpr(E->getArg(0));
1512515139
Value *Y = EmitScalarExpr(E->getArg(1));
1512615140
// Constant-fold the M4 mask argument.
15127-
llvm::APSInt M4 = *E->getArg(2)->getIntegerConstantExpr(getContext());
15141+
llvm::APSInt M4;
15142+
bool IsConstM4 = E->getArg(2)->isIntegerConstantExpr(M4, getContext());
15143+
assert(IsConstM4 && "Constant arg isn't actually constant?");
15144+
(void)IsConstM4;
1512815145
// Check whether this instance can be represented via a LLVM standard
1512915146
// intrinsic. We only support some values of M4.
1513015147
Intrinsic::ID ID = Intrinsic::not_intrinsic;
@@ -15158,7 +15175,10 @@ Value *CodeGenFunction::EmitSystemZBuiltinExpr(unsigned BuiltinID,
1515815175
Value *X = EmitScalarExpr(E->getArg(0));
1515915176
Value *Y = EmitScalarExpr(E->getArg(1));
1516015177
// Constant-fold the M4 mask argument.
15161-
llvm::APSInt M4 = *E->getArg(2)->getIntegerConstantExpr(getContext());
15178+
llvm::APSInt M4;
15179+
bool IsConstM4 = E->getArg(2)->isIntegerConstantExpr(M4, getContext());
15180+
assert(IsConstM4 && "Constant arg isn't actually constant?");
15181+
(void)IsConstM4;
1516215182
// Check whether this instance can be represented via a LLVM standard
1516315183
// intrinsic. We only support some values of M4.
1516415184
Intrinsic::ID ID = Intrinsic::not_intrinsic;
@@ -15825,11 +15845,10 @@ CodeGenFunction::EmitNVPTXBuiltinExpr(unsigned BuiltinID, const CallExpr *E) {
1582515845
Address Dst = EmitPointerWithAlignment(E->getArg(0));
1582615846
Value *Src = EmitScalarExpr(E->getArg(1));
1582715847
Value *Ldm = EmitScalarExpr(E->getArg(2));
15828-
Optional<llvm::APSInt> isColMajorArg =
15829-
E->getArg(3)->getIntegerConstantExpr(getContext());
15830-
if (!isColMajorArg)
15848+
llvm::APSInt isColMajorArg;
15849+
if (!E->getArg(3)->isIntegerConstantExpr(isColMajorArg, getContext()))
1583115850
return nullptr;
15832-
bool isColMajor = isColMajorArg->getSExtValue();
15851+
bool isColMajor = isColMajorArg.getSExtValue();
1583315852
NVPTXMmaLdstInfo II = getNVPTXMmaLdstInfo(BuiltinID);
1583415853
unsigned IID = isColMajor ? II.IID_col : II.IID_row;
1583515854
if (IID == 0)
@@ -15870,11 +15889,10 @@ CodeGenFunction::EmitNVPTXBuiltinExpr(unsigned BuiltinID, const CallExpr *E) {
1587015889
Value *Dst = EmitScalarExpr(E->getArg(0));
1587115890
Address Src = EmitPointerWithAlignment(E->getArg(1));
1587215891
Value *Ldm = EmitScalarExpr(E->getArg(2));
15873-
Optional<llvm::APSInt> isColMajorArg =
15874-
E->getArg(3)->getIntegerConstantExpr(getContext());
15875-
if (!isColMajorArg)
15892+
llvm::APSInt isColMajorArg;
15893+
if (!E->getArg(3)->isIntegerConstantExpr(isColMajorArg, getContext()))
1587615894
return nullptr;
15877-
bool isColMajor = isColMajorArg->getSExtValue();
15895+
bool isColMajor = isColMajorArg.getSExtValue();
1587815896
NVPTXMmaLdstInfo II = getNVPTXMmaLdstInfo(BuiltinID);
1587915897
unsigned IID = isColMajor ? II.IID_col : II.IID_row;
1588015898
if (IID == 0)
@@ -15921,20 +15939,16 @@ CodeGenFunction::EmitNVPTXBuiltinExpr(unsigned BuiltinID, const CallExpr *E) {
1592115939
Address SrcA = EmitPointerWithAlignment(E->getArg(1));
1592215940
Address SrcB = EmitPointerWithAlignment(E->getArg(2));
1592315941
Address SrcC = EmitPointerWithAlignment(E->getArg(3));
15924-
Optional<llvm::APSInt> LayoutArg =
15925-
E->getArg(4)->getIntegerConstantExpr(getContext());
15926-
if (!LayoutArg)
15942+
llvm::APSInt LayoutArg;
15943+
if (!E->getArg(4)->isIntegerConstantExpr(LayoutArg, getContext()))
1592715944
return nullptr;
15928-
int Layout = LayoutArg->getSExtValue();
15945+
int Layout = LayoutArg.getSExtValue();
1592915946
if (Layout < 0 || Layout > 3)
1593015947
return nullptr;
1593115948
llvm::APSInt SatfArg;
1593215949
if (BuiltinID == NVPTX::BI__bmma_m8n8k128_mma_xor_popc_b1)
1593315950
SatfArg = 0; // .b1 does not have satf argument.
15934-
else if (Optional<llvm::APSInt> OptSatfArg =
15935-
E->getArg(5)->getIntegerConstantExpr(getContext()))
15936-
SatfArg = *OptSatfArg;
15937-
else
15951+
else if (!E->getArg(5)->isIntegerConstantExpr(SatfArg, getContext()))
1593815952
return nullptr;
1593915953
bool Satf = SatfArg.getSExtValue();
1594015954
NVPTXMmaInfo MI = getNVPTXMmaInfo(BuiltinID);
@@ -16263,8 +16277,9 @@ Value *CodeGenFunction::EmitWebAssemblyBuiltinExpr(unsigned BuiltinID,
1626316277
case WebAssembly::BI__builtin_wasm_extract_lane_i64x2:
1626416278
case WebAssembly::BI__builtin_wasm_extract_lane_f32x4:
1626516279
case WebAssembly::BI__builtin_wasm_extract_lane_f64x2: {
16266-
llvm::APSInt LaneConst =
16267-
*E->getArg(1)->getIntegerConstantExpr(getContext());
16280+
llvm::APSInt LaneConst;
16281+
if (!E->getArg(1)->isIntegerConstantExpr(LaneConst, getContext()))
16282+
llvm_unreachable("Constant arg isn't actually constant?");
1626816283
Value *Vec = EmitScalarExpr(E->getArg(0));
1626916284
Value *Lane = llvm::ConstantInt::get(getLLVMContext(), LaneConst);
1627016285
Value *Extract = Builder.CreateExtractElement(Vec, Lane);
@@ -16290,8 +16305,9 @@ Value *CodeGenFunction::EmitWebAssemblyBuiltinExpr(unsigned BuiltinID,
1629016305
case WebAssembly::BI__builtin_wasm_replace_lane_i64x2:
1629116306
case WebAssembly::BI__builtin_wasm_replace_lane_f32x4:
1629216307
case WebAssembly::BI__builtin_wasm_replace_lane_f64x2: {
16293-
llvm::APSInt LaneConst =
16294-
*E->getArg(1)->getIntegerConstantExpr(getContext());
16308+
llvm::APSInt LaneConst;
16309+
if (!E->getArg(1)->isIntegerConstantExpr(LaneConst, getContext()))
16310+
llvm_unreachable("Constant arg isn't actually constant?");
1629516311
Value *Vec = EmitScalarExpr(E->getArg(0));
1629616312
Value *Lane = llvm::ConstantInt::get(getLLVMContext(), LaneConst);
1629716313
Value *Val = EmitScalarExpr(E->getArg(2));

0 commit comments

Comments
 (0)