mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-01-31 12:41:49 +01:00
Don't infer attributes on '::operator new'.
These attributes were all incorrect or inappropriate for LLVM to infer: - inaccessiblememonly is generally wrong; user replacement operator new can access memory that's visible to the caller, as can a new_handler function. - willreturn is generally wrong; a custom new_handler is not guaranteed to terminate. - noalias is inappropriate: Clang has a flag to determine whether this attribute should be present and adds it itself when appropriate. - noundef and nonnull on the return value should be specified by the frontend on all 'operator new' functions if we want them, not here. In any case, inferring attributes on functions declared 'nobuiltin' (as these are when Clang emits them) seems questionable.
This commit is contained in:
parent
c07a815edb
commit
8a8273062f
@ -170,16 +170,6 @@ static bool setRetAndArgsNoUndef(Function &F) {
|
||||
return setRetNoUndef(F) | setArgsNoUndef(F);
|
||||
}
|
||||
|
||||
static bool setRetNonNull(Function &F) {
|
||||
assert(F.getReturnType()->isPointerTy() &&
|
||||
"nonnull applies only to pointers");
|
||||
if (F.hasAttribute(AttributeList::ReturnIndex, Attribute::NonNull))
|
||||
return false;
|
||||
F.addAttribute(AttributeList::ReturnIndex, Attribute::NonNull);
|
||||
++NumNonNull;
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool setReturnedArg(Function &F, unsigned ArgNo) {
|
||||
if (F.hasParamAttribute(ArgNo, Attribute::Returned))
|
||||
return false;
|
||||
@ -1005,21 +995,6 @@ bool llvm::inferLibFuncAttributes(Function &F, const TargetLibraryInfo &TLI) {
|
||||
Changed |= setDoesNotCapture(F, 0);
|
||||
Changed |= setDoesNotCapture(F, 1);
|
||||
return Changed;
|
||||
case LibFunc_Znwj: // new(unsigned int)
|
||||
case LibFunc_Znwm: // new(unsigned long)
|
||||
case LibFunc_Znaj: // new[](unsigned int)
|
||||
case LibFunc_Znam: // new[](unsigned long)
|
||||
case LibFunc_msvc_new_int: // new(unsigned int)
|
||||
case LibFunc_msvc_new_longlong: // new(unsigned long long)
|
||||
case LibFunc_msvc_new_array_int: // new[](unsigned int)
|
||||
case LibFunc_msvc_new_array_longlong: // new[](unsigned long long)
|
||||
Changed |= setOnlyAccessesInaccessibleMemory(F);
|
||||
// Operator new always returns a nonnull noalias pointer
|
||||
Changed |= setRetNoUndef(F);
|
||||
Changed |= setRetNonNull(F);
|
||||
Changed |= setRetDoesNotAlias(F);
|
||||
Changed |= setWillReturn(F);
|
||||
return Changed;
|
||||
// TODO: add LibFunc entries for:
|
||||
// case LibFunc_memset_pattern4:
|
||||
// case LibFunc_memset_pattern8:
|
||||
|
@ -4,12 +4,6 @@
|
||||
; RUN: opt < %s -mtriple=x86_64-unknown-linux-gnu -inferattrs -S | FileCheck -check-prefix=CHECK -check-prefix=CHECK-LINUX %s
|
||||
; RUN: opt < %s -mtriple=nvptx -inferattrs -S | FileCheck -check-prefix=CHECK-NVPTX %s
|
||||
|
||||
; operator new routines
|
||||
declare i8* @_Znwj(i64 )
|
||||
; CHECK: declare noalias noundef nonnull i8* @_Znwj(i64) [[INACCESSIBLEMEMONLY_NOFREE_WILLRETURN:#[0-9]+]]
|
||||
declare i8* @_Znwm(i64)
|
||||
; CHECK: declare noalias noundef nonnull i8* @_Znwm(i64) [[INACCESSIBLEMEMONLY_NOFREE_WILLRETURN]]
|
||||
|
||||
declare i32 @__nvvm_reflect(i8*)
|
||||
; CHECK-NVPTX: declare noundef i32 @__nvvm_reflect(i8* noundef) [[NOFREE_NOUNWIND_READNONE:#[0-9]+]]
|
||||
; CHECK-NVPTX: attributes [[NOFREE_NOUNWIND_READNONE]] = { nofree nounwind readnone }
|
||||
|
Loading…
x
Reference in New Issue
Block a user