-
Notifications
You must be signed in to change notification settings - Fork 11k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Clang] Propagate guaranteed alignment for malloc and others
LLVM should be smarter about *known* malloc's alignment and this knowledge may enable other optimizations. Originally started as LLVM patch - https://reviews.llvm.org/D100862 but this logic should be really in Clang. Reviewed By: rjmccall Differential Revision: https://reviews.llvm.org/D100879
- Loading branch information
1 parent
a819e73
commit c229754
Showing
3 changed files
with
55 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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 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 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,35 @@ | ||
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm < %s | FileCheck %s --check-prefix=ALIGN16 | ||
// RUN: %clang_cc1 -triple x86_64-windows-msvc -emit-llvm < %s | FileCheck %s --check-prefix=ALIGN16 | ||
// RUN: %clang_cc1 -triple i386-apple-darwin -emit-llvm < %s | FileCheck %s --check-prefix=ALIGN16 | ||
// RUN: %clang_cc1 -triple i386-unknown-linux-gnu -emit-llvm < %s | FileCheck %s --check-prefix=ALIGN8 | ||
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fno-builtin-malloc -emit-llvm < %s | FileCheck %s --check-prefix=NOBUILTIN-MALLOC | ||
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fno-builtin-calloc -emit-llvm < %s | FileCheck %s --check-prefix=NOBUILTIN-CALLOC | ||
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fno-builtin-realloc -emit-llvm < %s | FileCheck %s --check-prefix=NOBUILTIN-REALLOC | ||
|
||
typedef __SIZE_TYPE__ size_t; | ||
|
||
void *malloc(size_t); | ||
void *calloc(size_t, size_t); | ||
void *realloc(void *, size_t); | ||
|
||
void *malloc_test(size_t n) { | ||
return malloc(n); | ||
} | ||
|
||
void *calloc_test(size_t n) { | ||
return calloc(1, n); | ||
} | ||
|
||
void *raalloc_test(void *p, size_t n) { | ||
return realloc(p, n); | ||
} | ||
|
||
// ALIGN16: align 16 i8* @malloc | ||
// ALIGN16: align 16 i8* @calloc | ||
// ALIGN16: align 16 i8* @realloc | ||
// ALIGN8: align 8 i8* @malloc | ||
// ALIGN8: align 8 i8* @calloc | ||
// ALIGN8: align 8 i8* @realloc | ||
// NOBUILTIN-MALLOC: declare i8* @malloc | ||
// NOBUILTIN-CALLOC: declare i8* @calloc | ||
// NOBUILTIN-REALLOC: declare i8* @realloc |