LLVM optimizes source codes with mm_malloc better, especially due to alignment info.
alloc align https://clang.llvm.org/docs/AttributeReference.html#alloc-align
alloc size https://clang.llvm.org/docs/AttributeReference.html#alloc-size
Differential D117091
[Clang] Add attributes alloc_size and alloc_align to mm_malloc xbolva00 on Jan 12 2022, 1:11 AM. Authored by
Details LLVM optimizes source codes with mm_malloc better, especially due to alignment info. alloc align https://clang.llvm.org/docs/AttributeReference.html#alloc-align
Diff Detail
Event TimelineComment Actions Not really familiar with testing for clang headers. Is it possible to test the new attributes have the desired effect? Comment Actions Yes, test for alignment should be possible, something like _Bool alig_test(void) { // CHECK: ret i1 true yvoid *p = _mm_malloc(2014, 16); _Bool ret = ((__SIZE_TYPE__)p % 16) == 0; _mm_free(p); return ret; } For alloc size not sure how.. Comment Actions Not qualified to review clang/c++ library semantic changes. Also, did we implement allocalign in LLVM? Last I knew it was a clang only attribute. If we did, it's missing from LangRef. Comment Actions There's a testing issue on Windows: ******************** TEST 'Clang :: Headers/mm_malloc.c' FAILED ******************** Script: -- : 'RUN: at line 1'; c:\ws\w2\llvm-project\premerge-checks\build\bin\clang.exe -emit-llvm -std=c11 -x c C:\ws\w2\llvm-project\premerge-checks\clang\test\Headers\mm_malloc.c -O1 --target=x86_64-linux-gnu -S -o - | c:\ws\w2\llvm-project\premerge-checks\build\bin\filecheck.exe C:\ws\w2\llvm-project\premerge-checks\clang\test\Headers\mm_malloc.c -- Exit Code: 2 Command Output (stdout): -- $ ":" "RUN: at line 1" $ "c:\ws\w2\llvm-project\premerge-checks\build\bin\clang.exe" "-emit-llvm" "-std=c11" "-x" "c" "C:\ws\w2\llvm-project\premerge-checks\clang\test\Headers\mm_malloc.c" "-O1" "--target=x86_64-linux-gnu" "-S" "-o" "-" # command stderr: In file included from C:\ws\w2\llvm-project\premerge-checks\clang\test\Headers\mm_malloc.c:2: c:\ws\w2\llvm-project\premerge-checks\build\lib\clang\14.0.0\include\mm_malloc.h:13:10: fatal error: 'stdlib.h' file not found #include <stdlib.h> ^~~~~~~~~~ 1 error generated. error: command failed with exit status: 1 $ "c:\ws\w2\llvm-project\premerge-checks\build\bin\filecheck.exe" "C:\ws\w2\llvm-project\premerge-checks\clang\test\Headers\mm_malloc.c" # command stderr: FileCheck error: '<stdin>' is empty. FileCheck command line: c:\ws\w2\llvm-project\premerge-checks\build\bin\filecheck.exe C:\ws\w2\llvm-project\premerge-checks\clang\test\Headers\mm_malloc.c error: command failed with exit status: 2 This one is neat because stdlib.h is not a header provided by the compiler but is instead provided by whatever CRT happens to be used. Normally, we require those headers to be mocked, but the goal here is to test the header the compiler does provide. Comment Actions Don't test with O1, add the dummy include folder to the include path (clang/test/Headers/Inputs/include), stdlib.h is already there, malloc.h is not and needs to be created. See clang/test/Headers/nvptx_device_cmath_functions.c for an example. Comment Actions The header bits LGTM aside from a nit I found with potential identifier conflicts. I don't feel super qualified to review the behavioral aspects of the change, but if others are happy with that, I'm happy with the header changes.
|
Protect against user macros.