-
Notifications
You must be signed in to change notification settings - Fork 14.9k
[clang] add array out-of-bounds access constraints using llvm.assume #159046
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
Closed
Closed
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
7fdec0a
[clang] add array out-of-bounds access constraints using llvm.assume
sebpop 702d9dd
add -fassume-array-bounds flag disabled by default for now
sebpop ec1024d
fix UB in testcase
sebpop 77e2606
fix UB in testcase
sebpop 0ed60c2
avoid optimization in testcase
sebpop 1c11e60
handle zero-length array pattern
sebpop 033a1ce
handle VLAs
sebpop f46618d
use Accessed to generate strict vs. size+1 checks
sebpop File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Test that array bounds constraints generate llvm.assume statements for optimization hints. | ||
// RUN: %clang_cc1 -emit-llvm -O2 %s -o - | FileCheck %s | ||
|
||
// This test verifies that clang generates llvm.assume statements to inform the | ||
// optimizer that array subscripts are within bounds to enable better optimization. | ||
|
||
// CHECK-LABEL: define {{.*}} @test_simple_array | ||
int test_simple_array(int i) { | ||
int arr[10]; // C arrays are 0-based: valid indices are [0, 9] | ||
// CHECK: %{{.*}} = icmp ult i32 %i, 10 | ||
// CHECK: call void @llvm.assume(i1 %{{.*}}) | ||
return arr[i]; | ||
} | ||
|
||
// CHECK-LABEL: define {{.*}} @test_multidimensional_array | ||
int test_multidimensional_array(int i, int j) { | ||
int arr[5][8]; // Valid indices: i in [0, 4], j in [0, 7] | ||
// CHECK: %{{.*}} = icmp ult i32 %i, 5 | ||
// CHECK: call void @llvm.assume(i1 %{{.*}}) | ||
// CHECK: %{{.*}} = icmp ult i32 %j, 8 | ||
// CHECK: call void @llvm.assume(i1 %{{.*}}) | ||
return arr[i][j]; | ||
} | ||
|
||
// CHECK-LABEL: define {{.*}} @test_unsigned_index | ||
int test_unsigned_index(unsigned int i) { | ||
int arr[10]; | ||
// CHECK: %{{.*}} = icmp ult i32 %i, 10 | ||
// CHECK: call void @llvm.assume(i1 %{{.*}}) | ||
return arr[i]; | ||
} | ||
|
||
// CHECK-LABEL: define {{.*}} @test_store_undef | ||
void test_store_undef(int i, int value) { | ||
int arr[10]; | ||
// CHECK: %{{.*}} = icmp ult i32 %i, 10 | ||
// CHECK: call void @llvm.assume(i1 %{{.*}}) | ||
arr[i] = value; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.