Skip to content

Commit 8325430

Browse files
committed
TargetLibraryInfo: Use pointer index size to determine getSizeTSize().
When using non-integral pointer types, such as on CHERI targets, size_t is equivalent to the index size, which is allowed to be smaller than the size of the pointer.
1 parent cfa582e commit 8325430

File tree

3 files changed

+6
-10
lines changed

3 files changed

+6
-10
lines changed

llvm/lib/Analysis/TargetLibraryInfo.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1465,13 +1465,10 @@ unsigned TargetLibraryInfoImpl::getSizeTSize(const Module &M) const {
14651465

14661466
// Historically LLVM assume that size_t has same size as intptr_t (hence
14671467
// deriving the size from sizeof(int*) in address space zero). This should
1468-
// work for most targets. For future consideration: DataLayout also implement
1469-
// getIndexSizeInBits which might map better to size_t compared to
1470-
// getPointerSizeInBits. Hard coding address space zero here might be
1471-
// unfortunate as well. Maybe getDefaultGlobalsAddressSpace() or
1472-
// getAllocaAddrSpace() is better.
1468+
// work for most targets. For future consideration: Hard coding address space
1469+
// zero here might be unfortunate. Maybe getMaxIndexSizeInBits() is better.
14731470
unsigned AddressSpace = 0;
1474-
return M.getDataLayout().getPointerSizeInBits(AddressSpace);
1471+
return M.getDataLayout().getIndexSizeInBits(AddressSpace);
14751472
}
14761473

14771474
TargetLibraryInfoWrapperPass::TargetLibraryInfoWrapperPass()

llvm/test/Transforms/InstCombine/stdio-custom-dl.ll

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@ target datalayout = "e-m:o-p:40:64:64:32-i64:64-f80:128-n8:16:32:64-S128"
88
@.str.1 = private unnamed_addr constant [2 x i8] c"w\00", align 1
99
@.str.2 = private unnamed_addr constant [4 x i8] c"str\00", align 1
1010

11-
; Check fwrite is generated with arguments of ptr size, not index size
1211
define internal void @fputs_test_custom_dl() {
1312
; CHECK-LABEL: @fputs_test_custom_dl(
1413
; CHECK-NEXT: [[CALL:%.*]] = call ptr @fopen(ptr nonnull @.str, ptr nonnull @.str.1)
15-
; CHECK-NEXT: [[TMP1:%.*]] = call i40 @fwrite(ptr nonnull @.str.2, i40 3, i40 1, ptr [[CALL]])
14+
; CHECK-NEXT: [[TMP1:%.*]] = call i32 @fwrite(ptr nonnull @.str.2, i32 3, i32 1, ptr %call)
1615
; CHECK-NEXT: ret void
1716
;
1817
%call = call ptr @fopen(ptr @.str, ptr @.str.1)

llvm/test/Transforms/MergeICmps/X86/distinct-index-width-crash.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ target triple = "x86_64"
88
target datalayout = "e-p:64:64:64:32"
99

1010
; Define a cunstom data layout that has index width < pointer width
11-
; and make sure that doesn't mreak anything
11+
; and make sure that doesn't break anything
1212
define void @fat_ptrs(ptr dereferenceable(16) %a, ptr dereferenceable(16) %b) {
1313
; CHECK-LABEL: @fat_ptrs(
1414
; CHECK-NEXT: bb0:
1515
; CHECK-NEXT: [[PTR_A1:%.*]] = getelementptr inbounds [2 x i64], ptr [[A:%.*]], i32 0, i32 1
1616
; CHECK-NEXT: [[PTR_B1:%.*]] = getelementptr inbounds [2 x i64], ptr [[B:%.*]], i32 0, i32 1
1717
; CHECK-NEXT: br label %"bb1+bb2"
1818
; CHECK: "bb1+bb2":
19-
; CHECK-NEXT: [[MEMCMP:%.*]] = call i32 @memcmp(ptr [[A]], ptr [[B]], i64 16)
19+
; CHECK-NEXT: [[MEMCMP:%.*]] = call i32 @memcmp(ptr [[A]], ptr [[B]], i32 16)
2020
; CHECK-NEXT: [[TMP0:%.*]] = icmp eq i32 [[MEMCMP]], 0
2121
; CHECK-NEXT: br label [[BB3:%.*]]
2222
; CHECK: bb3:

0 commit comments

Comments
 (0)