From ea644d8440479359ea2480d458e3751a6bfae123 Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Wed, 3 Sep 2008 21:22:16 +0000 Subject: [PATCH] Following gcc's behavior, only enable trigraphs if '-trigraphs' or '-ansi' is specified, or -std is set to a conforming mode. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@55738 91177308-0d34-0410-b5e6-96231b3b80d8 --- Driver/clang.cpp | 23 +++++++++++++++++++---- test/Lexer/block_cmt_end.c | 12 ++++++------ test/Lexer/escape_newline.c | 6 +++--- 3 files changed, 28 insertions(+), 13 deletions(-) diff --git a/Driver/clang.cpp b/Driver/clang.cpp index 8b24474681..bcad4959b4 100644 --- a/Driver/clang.cpp +++ b/Driver/clang.cpp @@ -307,7 +307,8 @@ static void InitializeLangOptions(LangOptions &Options, LangKind LK) { 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 @@ static llvm::cl::opt NeXTRuntime("fnext-runtime", llvm::cl::desc("Generate output compatible with the NeXT runtime.")); + + +static llvm::cl::opt +Trigraphs("trigraphs", llvm::cl::desc("Process trigraph sequences.")); + +static llvm::cl::opt +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 @@ static void InitializeLanguageStandard(LangOptions &Options, LangKind LK, 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; diff --git a/test/Lexer/block_cmt_end.c b/test/Lexer/block_cmt_end.c index 30e6d92eee..347f78f5e8 100644 --- a/test/Lexer/block_cmt_end.c +++ b/test/Lexer/block_cmt_end.c @@ -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; diff --git a/test/Lexer/escape_newline.c b/test/Lexer/escape_newline.c index 235ee51ef0..2e4b7cd7cd 100644 --- a/test/Lexer/escape_newline.c +++ b/test/Lexer/escape_newline.c @@ -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. -??/ -- 2.40.0