[PATCH] D102820: [Clang] Check for returns_nonnull when deciding to add allocation null checks
Di Mo via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu May 20 19:55:25 PDT 2021
modimo added a comment.
In D102820#2772184 <https://reviews.llvm.org/D102820#2772184>, @bruno wrote:
> Sounds reasonable to me! Can you double check whether this attribute gets correctly serialized/deserialized in face of `CXXNewExpr`? An example of how to test that would be in `clang/test/PCH/cxx-method.cpp`.
Piggybacking on that test case:
Inputs/cxx-method.h:
typedef __typeof__(sizeof(0)) size_t;
void *operator new(size_t size)
{
return ::operator new(size);
}
cxx-method.cpp:
int * foo()
{
return new int;
}
Testing
~/llvm-project/clang/test/PCH# ~/llvm-project/build-rel/bin/clang++ -cc1 -x c++ -emit-pch Inputs/cxx-method.h -o test.pch
~/llvm-project/clang/test/PCH# ~/llvm-project/build-rel/bin/clang++ -cc1 -x c++ cxx-method.cpp -include-pch test.pch -emit-llvm
~/llvm-project/clang/test/PCH# grep _Znwm cxx-method.ll
define dso_local nonnull i8* @_Znwm(i64 %size) #0 {
%call = call noalias nonnull i8* @_Znwm(i64 %0) #2
%call = call noalias nonnull i8* @_Znwm(i64 4) #3
Assuming I'm answering the correct question that the returns_nonnull is preserved through a PCH, the answer is yes.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D102820/new/
https://reviews.llvm.org/D102820
More information about the cfe-commits
mailing list