aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/CodeGen/CGCall.cpp
diff options
context:
space:
mode:
authorJeroen Dobbelaere <jeroen.dobbelaere@synopsys.com>2021-02-18 17:29:46 +0100
committerJeroen Dobbelaere <jeroen.dobbelaere@synopsys.com>2021-02-18 17:29:46 +0100
commit46757ccb49ab88da54ca8ddd43665d5255ee80f7 (patch)
tree6af8bdf98a3f7a7fd526eec16b3f9c14b6179578 /clang/lib/CodeGen/CGCall.cpp
parent2e851c4172a35cc37fe6bf4ce8150c628fd66c0c (diff)
downloadllvm-46757ccb49ab88da54ca8ddd43665d5255ee80f7.zip
llvm-46757ccb49ab88da54ca8ddd43665d5255ee80f7.tar.gz
llvm-46757ccb49ab88da54ca8ddd43665d5255ee80f7.tar.bz2
[clang] functions with the 'const' or 'pure' attribute must always return.
As described in * https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-pure-function-attribute * https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-const-function-attribute An `__attribute__((pure))` function must always return, as well as an `__attribute__((const))` function. Reviewed By: jdoerfert Differential Revision: https://reviews.llvm.org/D96960
Diffstat (limited to 'clang/lib/CodeGen/CGCall.cpp')
-rw-r--r--clang/lib/CodeGen/CGCall.cpp5
1 files changed, 5 insertions, 0 deletions
diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 405b4d2..992e873 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -1994,9 +1994,14 @@ void CodeGenModule::ConstructAttributeList(
if (TargetDecl->hasAttr<ConstAttr>()) {
FuncAttrs.addAttribute(llvm::Attribute::ReadNone);
FuncAttrs.addAttribute(llvm::Attribute::NoUnwind);
+ // gcc specifies that 'const' functions have greater restrictions than
+ // 'pure' functions, so they also cannot have infinite loops.
+ FuncAttrs.addAttribute(llvm::Attribute::WillReturn);
} else if (TargetDecl->hasAttr<PureAttr>()) {
FuncAttrs.addAttribute(llvm::Attribute::ReadOnly);
FuncAttrs.addAttribute(llvm::Attribute::NoUnwind);
+ // gcc specifies that 'pure' functions cannot have infinite loops.
+ FuncAttrs.addAttribute(llvm::Attribute::WillReturn);
} else if (TargetDecl->hasAttr<NoAliasAttr>()) {
FuncAttrs.addAttribute(llvm::Attribute::ArgMemOnly);
FuncAttrs.addAttribute(llvm::Attribute::NoUnwind);