aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/CodeGen/CodeGenFunction.cpp
diff options
context:
space:
mode:
authorJames Molloy <james.molloy@arm.com>2015-11-12 15:36:04 +0000
committerJames Molloy <james.molloy@arm.com>2015-11-12 15:36:04 +0000
commitc16a60b63e49d4ee8a054c0df54793aacd336289 (patch)
treebb6faf00712affbba06810b9d856f925564b0520 /clang/lib/CodeGen/CodeGenFunction.cpp
parentc744e120f601955b20f84273e2d770b6c054f45d (diff)
downloadllvm-c16a60b63e49d4ee8a054c0df54793aacd336289.zip
llvm-c16a60b63e49d4ee8a054c0df54793aacd336289.tar.gz
llvm-c16a60b63e49d4ee8a054c0df54793aacd336289.tar.bz2
[C++] Add the "norecurse" attribute to main() if in C++ mode
The C++ spec (3.6.1.3) says "The function `main` shall not be used within a program". This implies that it cannot recurse, so add the norecurse attribute to help the midend out a bit. llvm-svn: 252902
Diffstat (limited to 'clang/lib/CodeGen/CodeGenFunction.cpp')
-rw-r--r--clang/lib/CodeGen/CodeGenFunction.cpp8
1 files changed, 8 insertions, 0 deletions
diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp
index 1d3ad9b..b5812c8 100644
--- a/clang/lib/CodeGen/CodeGenFunction.cpp
+++ b/clang/lib/CodeGen/CodeGenFunction.cpp
@@ -716,6 +716,14 @@ void CodeGenFunction::StartFunction(GlobalDecl GD,
}
}
+ // If we're in C++ mode and the function name is "main", it is guaranteed
+ // to be norecurse by the standard (3.6.1.3 "The function main shall not be
+ // used within a program").
+ if (getLangOpts().CPlusPlus)
+ if (const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(D))
+ if (FD->isMain())
+ Fn->addFnAttr(llvm::Attribute::NoRecurse);
+
llvm::BasicBlock *EntryBB = createBasicBlock("entry", CurFn);
// Create a marker to make it easy to insert allocas into the entryblock