aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBill Wendling <isanbard@gmail.com>2009-06-28 23:01:01 +0000
committerBill Wendling <isanbard@gmail.com>2009-06-28 23:01:01 +0000
commit4ebe3e4c811a376c423a544f5e76ee2e96533324 (patch)
treee88708201a65e970635549e34585b10056f5eedd
parentd966a55bccae13f34d18958877c5e71dd643a125 (diff)
Make the StackProtector bitfield use enums instead of obscure numbers.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@74414 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/Basic/LangOptions.h24
-rw-r--r--lib/Basic/Targets.cpp2
-rw-r--r--lib/CodeGen/CGCall.cpp4
-rw-r--r--lib/Frontend/InitPreprocessor.cpp4
-rw-r--r--tools/clang-cc/clang-cc.cpp11
5 files changed, 29 insertions, 16 deletions
diff --git a/include/clang/Basic/LangOptions.h b/include/clang/Basic/LangOptions.h
index 9b308e1b32..aed8822f0a 100644
--- a/include/clang/Basic/LangOptions.h
+++ b/include/clang/Basic/LangOptions.h
@@ -84,16 +84,16 @@ public:
unsigned OpenCL : 1; // OpenCL C99 language extensions.
- unsigned StackProtector : 2; // Whether stack protectors are on:
- // 0 - None
- // 1 - On
- // 2 - All
-
private:
- unsigned GC : 2; // Objective-C Garbage Collection modes. We declare
- // this enum as unsigned because MSVC insists on making enums
- // signed. Set/Query this value using accessors.
+ unsigned GC : 2; // Objective-C Garbage Collection modes. We
+ // declare this enum as unsigned because MSVC
+ // insists on making enums signed. Set/Query
+ // this value using accessors.
unsigned SymbolVisibility : 3; // Symbol's visibility.
+ unsigned StackProtector : 2; // Whether stack protectors are on. We declare
+ // this enum as unsigned because MSVC insists
+ // on making enums signed. Set/Query this
+ // value using accessors.
/// The user provided name for the "main file", if non-null. This is
/// useful in situations where the input file name does not match
@@ -104,6 +104,7 @@ public:
unsigned InstantiationDepth; // Maximum template instantiation depth.
enum GCMode { NonGC, GCOnly, HybridGC };
+ enum StackProtectorMode { SSPOff, SSPOn, SSPReq };
enum VisibilityMode {
Default,
Protected,
@@ -156,6 +157,13 @@ public:
GCMode getGCMode() const { return (GCMode) GC; }
void setGCMode(GCMode m) { GC = (unsigned) m; }
+ StackProtectorMode getStackProtectorMode() const {
+ return static_cast<StackProtectorMode>(StackProtector);
+ }
+ void setStackProtectorMode(StackProtectorMode m) {
+ StackProtector = static_cast<unsigned>(m);
+ }
+
const char *getMainFileName() const { return MainFileName; }
void setMainFileName(const char *Name) { MainFileName = Name; }
diff --git a/lib/Basic/Targets.cpp b/lib/Basic/Targets.cpp
index d1158a6c6f..9ca014d4ff 100644
--- a/lib/Basic/Targets.cpp
+++ b/lib/Basic/Targets.cpp
@@ -238,7 +238,7 @@ static void GetDarwinLanguageOptions(LangOptions &Opts,
// Blocks and stack protectors default to on for 10.6 (darwin10) and beyond.
if (Maj > 9) {
Opts.Blocks = 1;
- Opts.StackProtector = 1;
+ Opts.setStackProtectorMode(LangOptions::SSPOn);
}
// Non-fragile ABI (in 64-bit mode) default to on for 10.5 (darwin9) and
diff --git a/lib/CodeGen/CGCall.cpp b/lib/CodeGen/CGCall.cpp
index 61b6737be1..8ff58914cb 100644
--- a/lib/CodeGen/CGCall.cpp
+++ b/lib/CodeGen/CGCall.cpp
@@ -392,9 +392,9 @@ void CodeGenModule::ConstructAttributeList(const CGFunctionInfo &FI,
if (CompileOpts.NoImplicitFloat)
FuncAttrs |= llvm::Attribute::NoImplicitFloat;
- if (Features.StackProtector == 1)
+ if (Features.getStackProtectorMode() == LangOptions::SSPOn)
FuncAttrs |= llvm::Attribute::StackProtect;
- else if (Features.StackProtector == 2)
+ else if (Features.getStackProtectorMode() == LangOptions::SSPReq)
FuncAttrs |= llvm::Attribute::StackProtectReq;
QualType RetTy = FI.getReturnType();
diff --git a/lib/Frontend/InitPreprocessor.cpp b/lib/Frontend/InitPreprocessor.cpp
index 554868fd27..05f9607355 100644
--- a/lib/Frontend/InitPreprocessor.cpp
+++ b/lib/Frontend/InitPreprocessor.cpp
@@ -424,9 +424,9 @@ static void InitializePredefinedMacros(const TargetInfo &TI,
PickFP(&TI.getLongDoubleFormat(), -1/*FIXME*/, 17, 21, 33, 36));
DefineBuiltinMacro(Buf, MacroBuf);
- if (LangOpts.StackProtector == 1)
+ if (LangOpts.getStackProtectorMode() == LangOptions::SSPOn)
DefineBuiltinMacro(Buf, "__SSP__=1");
- else if (LangOpts.StackProtector == 2)
+ else if (LangOpts.getStackProtectorMode() == LangOptions::SSPReq)
DefineBuiltinMacro(Buf, "__SSP_ALL__=2");
// Get other target #defines.
diff --git a/tools/clang-cc/clang-cc.cpp b/tools/clang-cc/clang-cc.cpp
index a1efe0101d..641d1195c2 100644
--- a/tools/clang-cc/clang-cc.cpp
+++ b/tools/clang-cc/clang-cc.cpp
@@ -819,9 +819,14 @@ static void InitializeLanguageStandard(LangOptions &Options, LangKind LK,
Options.Static = StaticDefine;
- assert(StackProtector <= 2 && "Invalid value for -stack-protector");
- if (StackProtector != -1)
- Options.StackProtector = StackProtector;
+ switch (StackProtector) {
+ default:
+ assert(StackProtector <= 2 && "Invalid value for -stack-protector");
+ case -1: break;
+ case 0: Options.setStackProtectorMode(LangOptions::SSPOff); break;
+ case 1: Options.setStackProtectorMode(LangOptions::SSPOn); break;
+ case 2: Options.setStackProtectorMode(LangOptions::SSPReq); break;
+ }
if (MainFileName.getPosition())
Options.setMainFileName(MainFileName.c_str());