Add nonnull in CodeGen for __attribute__((returns_nonnull))

As a follow-up to r212835, also add the LLVM nonnull function attribute when
__attribute__((returns_nonnull)) is provided.

llvm-svn: 212874
This commit is contained in:
Hal Finkel 2014-07-12 04:51:04 +00:00
parent 289ca249f0
commit d8442b1b21
2 changed files with 8 additions and 0 deletions
clang
lib/CodeGen
test/CodeGen

View File

@ -1107,6 +1107,8 @@ void CodeGenModule::ConstructAttributeList(const CGFunctionInfo &FI,
}
if (TargetDecl->hasAttr<MallocAttr>())
RetAttrs.addAttribute(llvm::Attribute::NoAlias);
if (TargetDecl->hasAttr<ReturnsNonNullAttr>())
RetAttrs.addAttribute(llvm::Attribute::NonNull);
}
if (CodeGenOpts.OptimizeSize)

View File

@ -15,3 +15,9 @@ void bar2(int * x, int * y) __attribute__((nonnull(2))) {
*x = 0;
}
static int a;
// CHECK: define nonnull i32* @bar3()
int * bar3() __attribute__((returns_nonnull)) {
return &a;
}