Skip to content

Commit 2a816fe

Browse files
committed
Florian1 feedback
1 parent 827dcbd commit 2a816fe

File tree

3 files changed

+18
-19
lines changed

3 files changed

+18
-19
lines changed

clang/lib/CodeGen/CGExprScalar.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4238,18 +4238,19 @@ static Value *emitPointerArithmetic(CodeGenFunction &CGF,
42384238
PtrTy->getPointerAddressSpace()))
42394239
return Ptr;
42404240
// The inbounds GEP of null is valid iff the index is zero.
4241+
auto CheckOrdinal = SanitizerKind::SO_PointerOverflow;
42414242
auto CheckHandler = SanitizerHandler::PointerOverflow;
4242-
CodeGenFunction::SanitizerScope SanScope(
4243-
&CGF, {SanitizerKind::SO_PointerOverflow}, CheckHandler);
4243+
CodeGenFunction::SanitizerScope SanScope(&CGF, {CheckOrdinal},
4244+
CheckHandler);
42444245
Value *IsZeroIndex = CGF.Builder.CreateIsNull(index);
42454246
llvm::Constant *StaticArgs[] = {
42464247
CGF.EmitCheckSourceLocation(op.E->getExprLoc())};
42474248
llvm::Type *IntPtrTy = DL.getIntPtrType(PtrTy);
42484249
Value *IntPtr = llvm::Constant::getNullValue(IntPtrTy);
42494250
Value *ComputedGEP = CGF.Builder.CreateZExtOrTrunc(index, IntPtrTy);
42504251
Value *DynamicArgs[] = {IntPtr, ComputedGEP};
4251-
CGF.EmitCheck({{IsZeroIndex, SanitizerKind::SO_PointerOverflow}},
4252-
CheckHandler, StaticArgs, DynamicArgs);
4252+
CGF.EmitCheck({{IsZeroIndex, CheckOrdinal}}, CheckHandler, StaticArgs,
4253+
DynamicArgs);
42534254
return Ptr;
42544255
}
42554256

@@ -4770,16 +4771,16 @@ Value *ScalarExprEmitter::EmitShl(const BinOpInfo &Ops) {
47704771
RHS = ConstrainShiftValue(Ops.LHS, RHS, "shl.mask");
47714772
else if ((SanitizeBase || SanitizeExponent) &&
47724773
isa<llvm::IntegerType>(Ops.LHS->getType())) {
4773-
SmallVector<SanitizerKind::SanitizerOrdinal, 3> Kinds;
4774+
SmallVector<SanitizerKind::SanitizerOrdinal, 3> Ordinals;
47744775
if (SanitizeSignedBase)
4775-
Kinds.push_back(SanitizerKind::SO_ShiftBase);
4776+
Ordinals.push_back(SanitizerKind::SO_ShiftBase);
47764777
if (SanitizeUnsignedBase)
4777-
Kinds.push_back(SanitizerKind::SO_UnsignedShiftBase);
4778+
Ordinals.push_back(SanitizerKind::SO_UnsignedShiftBase);
47784779
if (SanitizeExponent)
4779-
Kinds.push_back(SanitizerKind::SO_ShiftExponent);
4780+
Ordinals.push_back(SanitizerKind::SO_ShiftExponent);
47804781

47814782
CodeGenFunction::SanitizerScope SanScope(
4782-
&CGF, Kinds, SanitizerHandler::ShiftOutOfBounds);
4783+
&CGF, Ordinals, SanitizerHandler::ShiftOutOfBounds);
47834784
SmallVector<std::pair<Value *, SanitizerKind::SanitizerOrdinal>, 2> Checks;
47844785
bool RHSIsSigned = Ops.rhsHasSignedIntegerRepresentation();
47854786
llvm::Value *WidthMinusOne =

clang/lib/CodeGen/CodeGenFunction.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2757,24 +2757,20 @@ CodeGenFunction::CGCapturedStmtInfo::~CGCapturedStmtInfo() { }
27572757
CodeGenFunction::SanitizerScope::SanitizerScope(CodeGenFunction *CGF)
27582758
: CGF(CGF) {
27592759
assert(!CGF->IsSanitizerScope);
2760+
assert(!ApplyTrapDI);
27602761
CGF->IsSanitizerScope = true;
2761-
2762-
assert(!this->ApplyTrapDI);
27632762
}
27642763

27652764
CodeGenFunction::SanitizerScope::SanitizerScope(
27662765
CodeGenFunction *CGF, ArrayRef<SanitizerKind::SanitizerOrdinal> Ordinals,
27672766
SanitizerHandler Handler)
27682767
: SanitizerScope(CGF) {
2769-
this->ApplyTrapDI = new ApplyDebugLocation(
2770-
*CGF, CGF->SanitizerAnnotateDebugInfo(Ordinals, Handler));
2768+
ApplyTrapDI = std::unique_ptr<ApplyDebugLocation>(new ApplyDebugLocation(
2769+
*CGF, CGF->SanitizerAnnotateDebugInfo(Ordinals, Handler)));
27712770
}
27722771

27732772
CodeGenFunction::SanitizerScope::~SanitizerScope() {
27742773
CGF->IsSanitizerScope = false;
2775-
2776-
delete ((ApplyDebugLocation *)this->ApplyTrapDI);
2777-
this->ApplyTrapDI = nullptr;
27782774
}
27792775

27802776
void CodeGenFunction::InsertHelper(llvm::Instruction *I,

clang/lib/CodeGen/CodeGenFunction.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,10 @@ class ApplyAtomGroup {
272272
~ApplyAtomGroup();
273273
};
274274

275+
// CGDebugInfo.h is not #included in this header due to overhead
276+
// (b384d6d6ccc8f4452cd7086061c657ce76b41224)
277+
class ApplyDebugLocation;
278+
275279
/// CodeGenFunction - This class organizes the per-function state that is used
276280
/// while generating LLVM code.
277281
class CodeGenFunction : public CodeGenTypeCache {
@@ -597,9 +601,7 @@ class CodeGenFunction : public CodeGenTypeCache {
597601
class SanitizerScope {
598602
CodeGenFunction *CGF;
599603

600-
// ApplyDebugLocation is undeclared: CGDebugInfo.h is not #included in this
601-
// header due to overhead (b384d6d6ccc8f4452cd7086061c657ce76b41224)
602-
void *ApplyTrapDI = nullptr;
604+
std::unique_ptr<ApplyDebugLocation> ApplyTrapDI;
603605

604606
public:
605607
SanitizerScope(CodeGenFunction *CGF);

0 commit comments

Comments
 (0)