[cfe-commits] r55738 - in /cfe/trunk: Driver/clang.cpp test/Lexer/block_cmt_end.c test/Lexer/escape_newline.c

Ted Kremenek kremenek at apple.com
Wed Sep 3 14:22:17 PDT 2008


Author: kremenek
Date: Wed Sep  3 16:22:16 2008
New Revision: 55738

URL: http://llvm.org/viewvc/llvm-project?rev=55738&view=rev
Log:
Following gcc's behavior, only enable trigraphs if '-trigraphs' or '-ansi' is
specified, or -std is set to a conforming mode.

Modified:
    cfe/trunk/Driver/clang.cpp
    cfe/trunk/test/Lexer/block_cmt_end.c
    cfe/trunk/test/Lexer/escape_newline.c

Modified: cfe/trunk/Driver/clang.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/clang.cpp?rev=55738&r1=55737&r2=55738&view=diff

==============================================================================
--- cfe/trunk/Driver/clang.cpp (original)
+++ cfe/trunk/Driver/clang.cpp Wed Sep  3 16:22:16 2008
@@ -307,7 +307,8 @@
 enum LangStds {
   lang_unspecified,  
   lang_c89, lang_c94, lang_c99,
-  lang_gnu89, lang_gnu99,
+  lang_gnu_START,
+  lang_gnu89 = lang_gnu_START, lang_gnu99,
   lang_cxx98, lang_gnucxx98,
   lang_cxx0x, lang_gnucxx0x
 };
@@ -386,13 +387,23 @@
 NeXTRuntime("fnext-runtime",
             llvm::cl::desc("Generate output compatible with the NeXT runtime."));
 
+
+
+static llvm::cl::opt<bool>
+Trigraphs("trigraphs", llvm::cl::desc("Process trigraph sequences."));
+
+static llvm::cl::opt<bool>
+Ansi("ansi", llvm::cl::desc("Equivalent to specifying -std=c89."));
+
 // FIXME: add:
-//   -ansi
-//   -trigraphs
 //   -fdollars-in-identifiers
 //   -fpascal-strings
 static void InitializeLanguageStandard(LangOptions &Options, LangKind LK,
                                        TargetInfo *Target) {
+  
+  if (Ansi) // "The -ansi option is equivalent to -std=c89."
+    LangStd = lang_c89;
+  
   if (LangStd == lang_unspecified) {
     // Based on the base language, pick one.
     switch (LK) {
@@ -446,7 +457,11 @@
     Options.ImplicitInt = 1;
   else
     Options.ImplicitInt = 0;
-  Options.Trigraphs = 1; // -trigraphs or -ansi
+  
+  // Mimicing gcc's behavior, trigraphs are only enabled if -trigraphs or -ansi
+  // is specified, or -std is set to a conforming mode.  
+  Options.Trigraphs = LangStd < lang_gnu_START || Trigraphs ? 1 : 0;
+
   Options.DollarIdents = 1;  // FIXME: Really a target property.
   Options.PascalStrings = PascalStrings;
   Options.Microsoft = MSExtensions;

Modified: cfe/trunk/test/Lexer/block_cmt_end.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Lexer/block_cmt_end.c?rev=55738&r1=55737&r2=55738&view=diff

==============================================================================
--- cfe/trunk/test/Lexer/block_cmt_end.c (original)
+++ cfe/trunk/test/Lexer/block_cmt_end.c Wed Sep  3 16:22:16 2008
@@ -1,10 +1,10 @@
 /*
-  RUN: clang -E %s | grep bar &&
-  RUN: clang -E %s | grep foo &&
-  RUN: clang -E %s | not grep abc &&
-  RUN: clang -E %s | not grep xyz &&
-  RUN: clang -fsyntax-only -verify %s
- */
+  RUN: clang -E -trigraphs %s | grep bar &&
+  RUN: clang -E -trigraphs %s | grep foo &&
+  RUN: clang -E -trigraphs %s | not grep abc &&
+  RUN: clang -E -trigraphs %s | not grep xyz &&
+  RUN: clang -fsyntax-only -trigraphs -verify %s  
+*/
 
 // This is a simple comment, /*/ does not end a comment, the trailing */ does.
 int i = /*/ */ 1;

Modified: cfe/trunk/test/Lexer/escape_newline.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Lexer/escape_newline.c?rev=55738&r1=55737&r2=55738&view=diff

==============================================================================
--- cfe/trunk/test/Lexer/escape_newline.c (original)
+++ cfe/trunk/test/Lexer/escape_newline.c Wed Sep  3 16:22:16 2008
@@ -1,6 +1,6 @@
-// RUN: clang -E %s | grep -- ' ->' &&
-// RUN: clang -E %s 2>&1 | grep 'backslash and newline separated by space' &&
-// RUN: clang -E %s 2>&1 | grep 'trigraph converted'
+// RUN: clang -E -trigraphs %s | grep -- ' ->' &&
+// RUN: clang -E -trigraphs %s 2>&1 | grep 'backslash and newline separated by space' &&
+// RUN: clang -E -trigraphs %s 2>&1 | grep 'trigraph converted'
 
 // This is an ugly way to spell a -> token.
  -??/      





More information about the cfe-commits mailing list