diff --git a/clang/Driver/clang.cpp b/clang/Driver/clang.cpp index f402a20c01c8..54e93f803124 100644 --- a/clang/Driver/clang.cpp +++ b/clang/Driver/clang.cpp @@ -517,6 +517,12 @@ Trigraphs("trigraphs", llvm::cl::desc("Process trigraph sequences.")); static llvm::cl::opt Ansi("ansi", llvm::cl::desc("Equivalent to specifying -std=c89.")); + +static llvm::cl::list +TargetOptions("m", llvm::cl::Prefix, llvm::cl::value_desc("option"), + llvm::cl::desc("Target-specific options, such as -msse3")); + + // FIXME: add: // -fdollars-in-identifiers static void InitializeLanguageStandard(LangOptions &Options, LangKind LK, @@ -524,6 +530,23 @@ static void InitializeLanguageStandard(LangOptions &Options, LangKind LK, // Allow the target to set the default the langauge options as it sees fit. Target->getDefaultLangOptions(Options); + // If the user specified any -mfoo options, pass them to the target for + // validation and processing. + if (!TargetOptions.empty()) { + std::string ErrorStr; + int Opt = Target->HandleTargetOptions(&TargetOptions[0], + TargetOptions.size(), ErrorStr); + if (Opt != -1) { + if (ErrorStr.empty()) + fprintf(stderr, "invalid command line option '%s'\n", + TargetOptions[Opt].c_str()); + else + fprintf(stderr, "command line option '%s': %s\n", + TargetOptions[Opt].c_str(), ErrorStr.c_str()); + exit(1); + } + } + if (Ansi) // "The -ansi option is equivalent to -std=c89." LangStd = lang_c89; diff --git a/clang/include/clang/Basic/TargetInfo.h b/clang/include/clang/Basic/TargetInfo.h index 00edc57547d5..b9c8b14e09f6 100644 --- a/clang/include/clang/Basic/TargetInfo.h +++ b/clang/include/clang/Basic/TargetInfo.h @@ -249,6 +249,16 @@ public: /// options. virtual void getDefaultLangOptions(LangOptions &Opts) {} + /// HandleTargetOptions - Handle target-specific options like -msse2 and + /// friends. An array of arguments is passed in: if they are all valid, this + /// should handle them and return -1. If there is an error, the index of the + /// invalid argument should be returned along with an optional error string. + virtual int HandleTargetOptions(std::string *StrArray, unsigned NumStrs, + std::string &ErrorReason) { + if (NumStrs == 0) + return -1; + return 0; + } protected: virtual uint64_t getPointerWidthV(unsigned AddrSpace) const { return PointerWidth;