From: Anders Carlsson Date: Wed, 13 May 2009 19:49:53 +0000 (+0000) Subject: Disable access control by default. It can be enabled with the -faccess-control option... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a33d9b4ebf732a5da6d56fd7319ff6c020789b1c;p=clang Disable access control by default. It can be enabled with the -faccess-control option. When we have better support for it, we can enable it by default again. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@71706 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/DiagnosticFrontendKinds.td b/include/clang/Basic/DiagnosticFrontendKinds.td index 94ec2a5a16..1bc296babd 100644 --- a/include/clang/Basic/DiagnosticFrontendKinds.td +++ b/include/clang/Basic/DiagnosticFrontendKinds.td @@ -127,6 +127,10 @@ def warn_macro_name_used_in_pch : Error< def warn_pch_compiler_options_mismatch : Error< "compiler options used when building the precompiled header differ from " "the options used when using the precompiled header">; +def warn_pch_access_control : Error< + "C++ access control was %select{disabled|enabled}0 in the PCH file but " + "is currently %select{disabled|enabled}1">; + def err_not_a_pch_file : Error< "'%0' does not appear to be a precompiled header file">, DefaultFatal; } diff --git a/include/clang/Basic/LangOptions.h b/include/clang/Basic/LangOptions.h index fba474b2f5..1214afacd0 100644 --- a/include/clang/Basic/LangOptions.h +++ b/include/clang/Basic/LangOptions.h @@ -75,6 +75,8 @@ public: unsigned ObjCGCBitmapPrint : 1; // Enable printing of gc's bitmap layout // for __weak/__strong ivars. + unsigned AccessControl : 1; // Whether C++ access control should + // be enabled. private: unsigned GC : 2; // Objective-C Garbage Collection modes. We declare // this enum as unsigned because MSVC insists on making enums @@ -115,6 +117,9 @@ public: EmitAllDecls = 0; MathErrno = 1; + // FIXME: The default should be 1. + AccessControl = 0; + OverflowChecking = 0; ObjCGCBitmapPrint = 0; diff --git a/lib/Frontend/PCHReader.cpp b/lib/Frontend/PCHReader.cpp index ab7ad04e9d..25415bb368 100644 --- a/lib/Frontend/PCHReader.cpp +++ b/lib/Frontend/PCHReader.cpp @@ -1520,6 +1520,7 @@ bool PCHReader::ParseLanguageOptions( PARSE_LANGOPT_IMPORTANT(PICLevel, diag::warn_pch_pic_level); PARSE_LANGOPT_IMPORTANT(GNUInline, diag::warn_pch_gnu_inline); PARSE_LANGOPT_IMPORTANT(NoInline, diag::warn_pch_no_inline); + PARSE_LANGOPT_IMPORTANT(AccessControl, diag::warn_pch_access_control); if ((LangOpts.getGCMode() != 0) != (Record[Idx] != 0)) { Diag(diag::warn_pch_gc_mode) << (unsigned)Record[Idx] << LangOpts.getGCMode(); diff --git a/lib/Frontend/PCHWriter.cpp b/lib/Frontend/PCHWriter.cpp index e05a73568f..883825418e 100644 --- a/lib/Frontend/PCHWriter.cpp +++ b/lib/Frontend/PCHWriter.cpp @@ -546,6 +546,8 @@ void PCHWriter::WriteLanguageOptions(const LangOptions &LangOpts) { Record.push_back(LangOpts.GNUInline); // Should GNU inline semantics be // used (instead of C99 semantics). Record.push_back(LangOpts.NoInline); // Should __NO_INLINE__ be defined. + Record.push_back(LangOpts.AccessControl); // Whether C++ access control should + // be enabled. Record.push_back(LangOpts.getGCMode()); Record.push_back(LangOpts.getVisibilityMode()); Record.push_back(LangOpts.InstantiationDepth); diff --git a/lib/Sema/SemaAccess.cpp b/lib/Sema/SemaAccess.cpp index cc212434b7..b832d38d1d 100644 --- a/lib/Sema/SemaAccess.cpp +++ b/lib/Sema/SemaAccess.cpp @@ -53,6 +53,9 @@ bool Sema::CheckBaseClassAccess(QualType Derived, QualType Base, assert(Paths.isRecordingPaths() && "Can't check base class access without recorded paths"); + if (!getLangOptions().AccessControl) + return false; + const CXXBaseSpecifier *InacessibleBase = 0; const CXXRecordDecl* CurrentClassDecl = 0; diff --git a/test/SemaCXX/access-base-class.cpp b/test/SemaCXX/access-base-class.cpp index f98437695e..4a9ee51dbf 100644 --- a/test/SemaCXX/access-base-class.cpp +++ b/test/SemaCXX/access-base-class.cpp @@ -1,4 +1,4 @@ -// RUN: clang-cc -fsyntax-only -verify %s +// RUN: clang-cc -fsyntax-only -faccess-control -verify %s namespace T1 { class A { }; diff --git a/test/SemaCXX/conditional-expr.cpp b/test/SemaCXX/conditional-expr.cpp index 3fede303b6..3f4d7159a0 100644 --- a/test/SemaCXX/conditional-expr.cpp +++ b/test/SemaCXX/conditional-expr.cpp @@ -1,4 +1,4 @@ -// RUN: clang-cc -fsyntax-only -verify -std=c++0x %s +// RUN: clang-cc -fsyntax-only -verify -faccess-control -std=c++0x %s // C++ rules for ?: are a lot stricter than C rules, and have to take into // account more conversion options. diff --git a/tools/clang-cc/clang-cc.cpp b/tools/clang-cc/clang-cc.cpp index 9fa0d79e69..a7f65902d8 100644 --- a/tools/clang-cc/clang-cc.cpp +++ b/tools/clang-cc/clang-cc.cpp @@ -669,6 +669,11 @@ static llvm::cl::opt MainFileName("main-file-name", llvm::cl::desc("Main file name to use for debug info")); +// FIXME: Also add an "-fno-access-control" option. +static llvm::cl::opt +AccessControl("faccess-control", + llvm::cl::desc("Enable C++ access control")); + // It might be nice to add bounds to the CommandLine library directly. struct OptLevelParser : public llvm::cl::parser { bool parse(llvm::cl::Option &O, const char *ArgName, @@ -801,6 +806,9 @@ static void InitializeLanguageStandard(LangOptions &Options, LangKind LK, if (EnableHeinousExtensions) Options.HeinousExtensions = 1; + if (AccessControl) + Options.AccessControl = 1; + Options.MathErrno = MathErrno; Options.InstantiationDepth = TemplateDepth;