]> granicus.if.org Git - clang/commitdiff
Support for -fno-constant-cfstrings option - wip.
authorFariborz Jahanian <fjahanian@apple.com>
Thu, 22 Apr 2010 20:26:39 +0000 (20:26 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Thu, 22 Apr 2010 20:26:39 +0000 (20:26 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102112 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/LangOptions.h
include/clang/Driver/CC1Options.td
lib/CodeGen/CGObjCMac.cpp
lib/CodeGen/CodeGenModule.cpp
lib/CodeGen/CodeGenModule.h
lib/Frontend/CompilerInvocation.cpp

index ba98a087f75a4c1b5a3725fbbd0586dc1a0584a3..f88b0ef325e6c0535cc400c39660b90b5c1650a5 100644 (file)
@@ -101,6 +101,7 @@ public:
   unsigned CatchUndefined    : 1; // Generate code to check for undefined ops.
   unsigned DumpRecordLayouts : 1; /// Dump the layout of IRgen'd records.
   unsigned DumpVTableLayouts : 1; /// Dump the layouts of emitted vtables.
+  unsigned NoConstantCFStrings : 1;  // Do not do CF strings
 
   // FIXME: This is just a temporary option, for testing purposes.
   unsigned NoBitFieldTypeAlign : 1;
@@ -134,6 +135,7 @@ public:
     GNUMode = GNUKeywords = ImplicitInt = Digraphs = 0;
     HexFloats = 0;
     GC = ObjC1 = ObjC2 = ObjCNonFragileABI = ObjCNonFragileABI2 = 0;
+    NoConstantCFStrings = 0;
     C99 = Microsoft = CPlusPlus = CPlusPlus0x = 0;
     CXXOperatorNames = PascalStrings = WritableStrings = ConstStrings = 0;
     Exceptions = SjLjExceptions = Freestanding = NoBuiltin = 0;
index 815fc1bcfbef46094dd4ed17972708d95d2d887f..e45cfa9920f6270a0dbf03fba1e79b48a069fca4 100644 (file)
@@ -385,6 +385,8 @@ def fno_use_cxa_atexit : Flag<"-fno-use-cxa-atexit">,
 def fconstant_string_class : Separate<"-fconstant-string-class">,
   MetaVarName<"<class name>">,
   HelpText<"Specify the class to use for constant Objective-C string objects.">;
+def fno_constant_cfstrings : Flag<"-fno-constant-cfstrings">,
+  HelpText<"Enable creation of CodeFoundation-type constant strings">;
 def fobjc_gc : Flag<"-fobjc-gc">,
   HelpText<"Enable Objective-C garbage collection">;
 def fobjc_gc_only : Flag<"-fobjc-gc-only">,
index 5af3f5815c65f51a7a4eafe6e616d18e7d982ada..d546db771bc2ee927d7fe0b8c34e47ffaa962306 100644 (file)
@@ -1493,9 +1493,20 @@ llvm::Value *CGObjCMac::GetSelector(CGBuilderTy &Builder, const ObjCMethodDecl
   };
 */
 
+/// or Generate a constant NSString object.
+/*
+   struct __builtin_NSString {
+     const int *isa; // point to __NSConstantStringClassReference
+     const char *str;
+     unsigned int length;
+   };
+*/
+
 llvm::Constant *CGObjCCommonMac::GenerateConstantString(
   const StringLiteral *SL) {
-  return CGM.GetAddrOfConstantCFString(SL);
+  return (CGM.getLangOptions().NoConstantCFStrings == 0 ? 
+          CGM.GetAddrOfConstantCFString(SL) :
+          CGM.GetAddrOfConstantNSString(SL));
 }
 
 /// Generates a message send where the super is the receiver.  This is
index 486c6948d1748c7a3e818075bea99a0d4cf4eb7d..b140837337b482732455cfdf3ce15b3c8247b592 100644 (file)
@@ -1593,6 +1593,12 @@ CodeGenModule::GetAddrOfConstantCFString(const StringLiteral *Literal) {
   return GV;
 }
 
+llvm::Constant *
+CodeGenModule::GetAddrOfConstantNSString(const StringLiteral *Literal) {
+  // FIXME. This is temporary so -fno-constant-cfstrings same as old.
+  return GetAddrOfConstantCFString(Literal);
+}
+
 /// GetStringForStringLiteral - Return the appropriate bytes for a
 /// string literal, properly padded to match the literal type.
 std::string CodeGenModule::GetStringForStringLiteral(const StringLiteral *E) {
index 8bfa0b9ab79923678f14f994e78feb496c0f45a4..7e52f76b3c27843b8abf171484dd660ab22dfd14 100644 (file)
@@ -250,6 +250,10 @@ public:
   /// GetAddrOfConstantCFString - Return a pointer to a constant CFString object
   /// for the given string.
   llvm::Constant *GetAddrOfConstantCFString(const StringLiteral *Literal);
+  
+  /// GetAddrOfConstantNSString - Return a pointer to a constant NSString object
+  /// for the given string.
+  llvm::Constant *GetAddrOfConstantNSString(const StringLiteral *Literal);
 
   /// GetAddrOfConstantStringFromLiteral - Return a pointer to a constant array
   /// for the given string literal.
index f9cfd73c7e633ce33cf71a0a7ba5a0903722bb68..3386eff5bacfac7b91e00406c0ce119637c81b21 100644 (file)
@@ -549,6 +549,8 @@ static void LangOptsToArgs(const LangOptions &Opts,
   }
   if (Opts.ObjCGCBitmapPrint)
     Res.push_back("-print-ivar-layout");
+  if (Opts.NoConstantCFStrings)
+    Res.push_back("-fno-constant-cfstrings");
   if (!Opts.AccessControl)
     Res.push_back("-fno-access-control");
   if (!Opts.CharIsSigned)
@@ -1180,6 +1182,8 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args,
 
   if (Args.hasArg(OPT_print_ivar_layout))
     Opts.ObjCGCBitmapPrint = 1;
+  if (Args.hasArg(OPT_fno_constant_cfstrings))
+    Opts.NoConstantCFStrings = 1;
 
   if (Args.hasArg(OPT_faltivec))
     Opts.AltiVec = 1;