Skip to content

[ASAN] Do not consider alignment during object size calculations #109120

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3057,9 +3057,7 @@ bool AddressSanitizer::instrumentFunction(Function &F,
OperandsToInstrument.size() + IntrinToInstrument.size() >
(unsigned)InstrumentationWithCallsThreshold);
const DataLayout &DL = F.getDataLayout();
ObjectSizeOpts ObjSizeOpts;
ObjSizeOpts.RoundToAlign = true;
ObjectSizeOffsetVisitor ObjSizeVis(DL, TLI, F.getContext(), ObjSizeOpts);
ObjectSizeOffsetVisitor ObjSizeVis(DL, TLI, F.getContext());

// Instrument.
int NumInstrumented = 0;
Expand Down
21 changes: 21 additions & 0 deletions llvm/test/Instrumentation/AddressSanitizer/instrument_global.ll
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ target triple = "x86_64-unknown-linux-gnu"
; indexed with constants in-bounds. But instrument all other cases.

@GlobSt = global [10 x i32] zeroinitializer, align 16 ; static initializer
@GlobStAlignInBounds = global [10 x i8] zeroinitializer, align 16 ; static initializer
@GlobDy = global [10 x i32] zeroinitializer, align 16, sanitize_address_dyninit ; dynamic initializer
@GlobEx = external global [10 x i32] , align 16 ; extern initializer

Expand Down Expand Up @@ -49,6 +50,26 @@ entry:
; CHECK: ret i32
}

; GlobStAlignInBount is accessed with out of bounds index, but in bounds of allocated area (because of alignemnt)
define i8 @AccessGlobStAlignInBounds_0_11() sanitize_address {
entry:
%0 = load i8, ptr getelementptr inbounds ([10 x i8], ptr @GlobStAlignInBounds, i64 0, i64 11), align 1
ret i8 %0
; CHECK-LABEL: define i8 @AccessGlobStAlignInBounds_0_11
; CHECK: __asan_report
; CHECK: ret i8
}

; GlobStAlignInBount is accessed with in-bound index
define i8 @AccessGlobStAlignInBounds_0_9() sanitize_address {
entry:
%0 = load i8, ptr getelementptr inbounds ([10 x i8], ptr @GlobStAlignInBounds, i64 0, i64 9), align 1
ret i8 %0
; CHECK-LABEL: define i8 @AccessGlobStAlignInBounds_0_9
; CHECK-NOT: __asan_report
; CHECK: ret i8
}

; GlobDy is declared with dynamic initializer -- can't optimize.
define i32 @AccessGlobDy_0_2() sanitize_address {
entry:
Expand Down
Loading