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
diff --git a/include/clang/Basic/LangOptions.h b/include/clang/Basic/LangOptions.h
index 9b308e1..aed8822 100644
--- a/include/clang/Basic/LangOptions.h
+++ b/include/clang/Basic/LangOptions.h
@@ -84,16 +84,16 @@
 
   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 @@
   unsigned InstantiationDepth;    // Maximum template instantiation depth.
 
   enum GCMode { NonGC, GCOnly, HybridGC };
+  enum StackProtectorMode { SSPOff, SSPOn, SSPReq };
   enum VisibilityMode { 
     Default, 
     Protected, 
@@ -156,6 +157,13 @@
   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 d1158a6..9ca014d 100644
--- a/lib/Basic/Targets.cpp
+++ b/lib/Basic/Targets.cpp
@@ -238,7 +238,7 @@
   // 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 61b6737..8ff5891 100644
--- a/lib/CodeGen/CGCall.cpp
+++ b/lib/CodeGen/CGCall.cpp
@@ -392,9 +392,9 @@
   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 554868f..05f9607 100644
--- a/lib/Frontend/InitPreprocessor.cpp
+++ b/lib/Frontend/InitPreprocessor.cpp
@@ -424,9 +424,9 @@
           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 a1efe01..641d119 100644
--- a/tools/clang-cc/clang-cc.cpp
+++ b/tools/clang-cc/clang-cc.cpp
@@ -819,9 +819,14 @@
 
   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());