From fb2af643e49a29fc99ebd728dca19cfc39fe6ff5 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Thu, 2 Jun 2011 16:13:27 +0000 Subject: [PATCH] Implement -fgnu89-inline. Fixes PR10041. llvm-svn: 132460 --- clang/include/clang/Driver/CC1Options.td | 2 ++ clang/include/clang/Driver/Options.td | 1 + clang/lib/AST/Decl.cpp | 2 +- clang/lib/Driver/Tools.cpp | 3 +++ clang/lib/Frontend/CompilerInvocation.cpp | 3 +++ clang/lib/Sema/SemaDecl.cpp | 2 +- clang/test/CodeGen/extern-inline.c | 1 + 7 files changed, 12 insertions(+), 2 deletions(-) diff --git a/clang/include/clang/Driver/CC1Options.td b/clang/include/clang/Driver/CC1Options.td index 62e4c3f98f99..155ecae5798a 100644 --- a/clang/include/clang/Driver/CC1Options.td +++ b/clang/include/clang/Driver/CC1Options.td @@ -423,6 +423,8 @@ def fno_assume_sane_operator_new : Flag<"-fno-assume-sane-operator-new">, HelpText<"Don't assume that C++'s global operator new can't alias any pointer">; def fgnu_keywords : Flag<"-fgnu-keywords">, HelpText<"Allow GNU-extension keywords regardless of language standard">; +def fgnu89_inline : Flag<"-fgnu89-inline">, + HelpText<"Use the gnu89 inline semantics">; def fno_gnu_keywords : Flag<"-fno-gnu-keywords">, HelpText<"Disallow GNU-extension keywords regardless of language standard">; def fdollars_in_identifiers : Flag<"-fdollars-in-identifiers">, diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 5260c71d6a6f..2cba46c65021 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -299,6 +299,7 @@ def fno_for_scope : Flag<"-fno-for-scope">, Group; def ffreestanding : Flag<"-ffreestanding">, Group; def fgnu_keywords : Flag<"-fgnu-keywords">, Group; +def fgnu89_inline : Flag<"-fgnu89-inline">, Group; def fgnu_runtime : Flag<"-fgnu-runtime">, Group; def fheinous_gnu_extensions : Flag<"-fheinous-gnu-extensions">; def filelist : Separate<"-filelist">, Flags<[LinkerInput]>; diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp index 81d976f4e83a..1cad64e055bf 100644 --- a/clang/lib/AST/Decl.cpp +++ b/clang/lib/AST/Decl.cpp @@ -1743,7 +1743,7 @@ bool FunctionDecl::isInlineDefinitionExternallyVisible() const { assert(isInlined() && "Function must be inline"); ASTContext &Context = getASTContext(); - if (!Context.getLangOptions().C99 || hasAttr()) { + if (Context.getLangOptions().GNUInline || hasAttr()) { // If it's not the case that both 'inline' and 'extern' are // specified on the definition, then this inline definition is // externally visible. diff --git a/clang/lib/Driver/Tools.cpp b/clang/lib/Driver/Tools.cpp index eff594259908..fbc5109207ce 100644 --- a/clang/lib/Driver/Tools.cpp +++ b/clang/lib/Driver/Tools.cpp @@ -1712,6 +1712,9 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, options::OPT_fno_gnu_keywords)) A->render(Args, CmdArgs); + if (Arg *A = Args.getLastArg(options::OPT_fgnu89_inline)) + CmdArgs.push_back("-fgnu89-inline"); + // -fnext-runtime defaults to on Darwin and when rewriting Objective-C, and is // -the -cc1 default. bool NeXTRuntimeIsDefault = diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index d1de31b95c6b..b8b5011bbfa9 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -1477,6 +1477,9 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK, if (Args.hasArg(OPT_fno_operator_names)) Opts.CXXOperatorNames = 0; + if (Args.hasArg(OPT_fgnu89_inline)) + Opts.GNUInline = 1; + if (Args.hasArg(OPT_fobjc_gc_only)) Opts.setGCMode(LangOptions::GCOnly); else if (Args.hasArg(OPT_fobjc_gc)) diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index f5b642191c6b..d77bda7676a9 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -1527,7 +1527,7 @@ Sema::CXXSpecialMember Sema::getSpecialMember(const CXXMethodDecl *MD) { /// GNU89 mode. static bool canRedefineFunction(const FunctionDecl *FD, const LangOptions& LangOpts) { - return (LangOpts.GNUMode && !LangOpts.C99 && !LangOpts.CPlusPlus && + return (LangOpts.GNUInline && !LangOpts.CPlusPlus && FD->isInlineSpecified() && FD->getStorageClass() == SC_Extern); } diff --git a/clang/test/CodeGen/extern-inline.c b/clang/test/CodeGen/extern-inline.c index 60f6d034bf1f..e3df9968bfd2 100644 --- a/clang/test/CodeGen/extern-inline.c +++ b/clang/test/CodeGen/extern-inline.c @@ -1,4 +1,5 @@ // RUN: %clang -S -emit-llvm -std=gnu89 -o - %s | FileCheck %s +// RUN: %clang -S -emit-llvm -fgnu89-inline -o - %s | FileCheck %s // PR5253 // If an extern inline function is redefined, functions should call the -- GitLab