r321587 - Enable configuration files in clang

2017-12-30 Thread Serge Pavlov via cfe-commits
Author: sepavloff
Date: Sat Dec 30 09:59:26 2017
New Revision: 321587

URL: http://llvm.org/viewvc/llvm-project?rev=321587&view=rev
Log:
Enable configuration files in clang

Clang is inherently a cross compiler and can generate code for any target
enabled during build. It however requires to specify many parameters in the
invocation, which could be hardcoded during configuration process in the
case of single-target compiler. The purpose of configuration files is to
make specifying clang arguments easier.

A configuration file is a collection of driver options, which are inserted
into command line before other options specified in the clang invocation.
It groups related options together and allows specifying them in simpler,
more flexible and less error prone way than just listing the options
somewhere in build scripts. Configuration file may be thought as a "macro"
that names an option set and is expanded when the driver is called.

Use of configuration files is described in `UserManual.rst`.

Differential Revision: https://reviews.llvm.org/D24933

Added:
cfe/trunk/test/Driver/Inputs/config/
cfe/trunk/test/Driver/Inputs/config-1.cfg
cfe/trunk/test/Driver/Inputs/config-2.cfg
cfe/trunk/test/Driver/Inputs/config-2a.cfg
cfe/trunk/test/Driver/Inputs/config-3.cfg
cfe/trunk/test/Driver/Inputs/config-4.cfg
cfe/trunk/test/Driver/Inputs/config-5.cfg
cfe/trunk/test/Driver/Inputs/config-6.cfg
cfe/trunk/test/Driver/Inputs/config/config-4.cfg
cfe/trunk/test/Driver/Inputs/config/i386-qqq.cfg
cfe/trunk/test/Driver/Inputs/config/i386-qqq3.cfg
cfe/trunk/test/Driver/Inputs/config/x86_64-qqq.cfg
cfe/trunk/test/Driver/Inputs/config/x86_64-qqq2.cfg
cfe/trunk/test/Driver/Inputs/config/x86_64.cfg
cfe/trunk/test/Driver/Inputs/config2/
cfe/trunk/test/Driver/Inputs/config2/config-4.cfg
cfe/trunk/test/Driver/Inputs/config2/i386.cfg
cfe/trunk/test/Driver/config-file-errs.c
cfe/trunk/test/Driver/config-file.c
cfe/trunk/test/Driver/config-file2.c
cfe/trunk/test/Driver/config-file3.c
Modified:
cfe/trunk/docs/UsersManual.rst
cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
cfe/trunk/include/clang/Config/config.h.cmake
cfe/trunk/include/clang/Driver/Driver.h
cfe/trunk/include/clang/Driver/Options.td
cfe/trunk/lib/Driver/Driver.cpp

Modified: cfe/trunk/docs/UsersManual.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/UsersManual.rst?rev=321587&r1=321586&r2=321587&view=diff
==
--- cfe/trunk/docs/UsersManual.rst (original)
+++ cfe/trunk/docs/UsersManual.rst Sat Dec 30 09:59:26 2017
@@ -694,6 +694,77 @@ a special character, which is the conven
 option tells Clang to put double-quotes around the entire filename, which
 is the convention used by NMake and Jom.
 
+Configuration files
+---
+
+Configuration files group command-line options and allow all of them to be
+specified just by referencing the configuration file. They may be used, for
+example, to collect options required to tune compilation for particular
+target, such as -L, -I, -l, --sysroot, codegen options, etc.
+
+The command line option `--config` can be used to specify configuration
+file in a Clang invocation. For example:
+
+::
+
+clang --config /home/user/cfgs/testing.txt
+clang --config debug.cfg
+
+If the provided argument contains a directory separator, it is considered as
+a file path, and options are read from that file. Otherwise the argument is
+treated as a file name and is searched for sequentially in the directories:
+- user directory,
+- system directory,
+- the directory where Clang executable resides.
+Both user and system directories for configuration files are specified during
+clang build using CMake parameters, CLANG_CONFIG_FILE_USER_DIR and
+CLANG_CONFIG_FILE_SYSTEM_DIR respectively. The first file found is used. It is
+an error if the required file cannot be found.
+
+Another way to specify a configuration file is to encode it in executable name.
+For example, if the Clang executable is named `armv7l-clang` (it may be a
+symbolic link to `clang`), then Clang will search for file `armv7l.cfg` in the
+directory where Clang resides.
+
+If a driver mode is specified in invocation, Clang tries to find a file 
specific
+for the specified mode. For example, if the executable file is named
+`x86_64-clang-cl`, Clang first looks for `x86_64-cl.cfg` and if it is not 
found,
+looks for `x86_64.cfg'.
+
+If the command line contains options that effectively change target 
architecture
+(these are -m32, -EL, and some others) and the configuration file starts with 
an
+architecture name, Clang tries to load the configuration file for the effective
+architecture. For example, invocation:
+
+::
+
+x86_64-clang -m32 abc.c
+
+causes Clang search for a file `i368.cfg` first, and if no such file is found,
+Clang looks for the file `x86_64.cfg`.

[PATCH] D24933: Enable configuration files in clang

2017-12-30 Thread Serge Pavlov via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL321587: Enable configuration files in clang (authored by 
sepavloff, committed by ).

Repository:
  rL LLVM

https://reviews.llvm.org/D24933

Files:
  cfe/trunk/docs/UsersManual.rst
  cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
  cfe/trunk/include/clang/Config/config.h.cmake
  cfe/trunk/include/clang/Driver/Driver.h
  cfe/trunk/include/clang/Driver/Options.td
  cfe/trunk/lib/Driver/Driver.cpp
  cfe/trunk/test/Driver/Inputs/config-1.cfg
  cfe/trunk/test/Driver/Inputs/config-2.cfg
  cfe/trunk/test/Driver/Inputs/config-2a.cfg
  cfe/trunk/test/Driver/Inputs/config-3.cfg
  cfe/trunk/test/Driver/Inputs/config-4.cfg
  cfe/trunk/test/Driver/Inputs/config-5.cfg
  cfe/trunk/test/Driver/Inputs/config-6.cfg
  cfe/trunk/test/Driver/Inputs/config/config-4.cfg
  cfe/trunk/test/Driver/Inputs/config/i386-qqq.cfg
  cfe/trunk/test/Driver/Inputs/config/i386-qqq3.cfg
  cfe/trunk/test/Driver/Inputs/config/x86_64-qqq.cfg
  cfe/trunk/test/Driver/Inputs/config/x86_64-qqq2.cfg
  cfe/trunk/test/Driver/Inputs/config/x86_64.cfg
  cfe/trunk/test/Driver/Inputs/config2/config-4.cfg
  cfe/trunk/test/Driver/Inputs/config2/i386.cfg
  cfe/trunk/test/Driver/config-file-errs.c
  cfe/trunk/test/Driver/config-file.c
  cfe/trunk/test/Driver/config-file2.c
  cfe/trunk/test/Driver/config-file3.c

Index: cfe/trunk/lib/Driver/Driver.cpp
===
--- cfe/trunk/lib/Driver/Driver.cpp
+++ cfe/trunk/lib/Driver/Driver.cpp
@@ -62,14 +62,16 @@
 #include "llvm/Option/OptSpecifier.h"
 #include "llvm/Option/OptTable.h"
 #include "llvm/Option/Option.h"
+#include "llvm/Support/CommandLine.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/PrettyStackTrace.h"
 #include "llvm/Support/Process.h"
 #include "llvm/Support/Program.h"
 #include "llvm/Support/TargetRegistry.h"
 #include "llvm/Support/raw_ostream.h"
+#include "llvm/Support/StringSaver.h"
 #include 
 #include 
 #include 
@@ -92,7 +94,8 @@
   CCPrintHeadersFilename(nullptr), CCLogDiagnosticsFilename(nullptr),
   CCCPrintBindings(false), CCPrintHeaders(false), CCLogDiagnostics(false),
   CCGenDiagnostics(false), DefaultTargetTriple(DefaultTargetTriple),
-  CCCGenericGCCName(""), CheckInputsExist(true), CCCUsePCH(true),
+  CCCGenericGCCName(""), Saver(Alloc),
+  CheckInputsExist(true), CCCUsePCH(true),
   GenReproducer(false), SuppressMissingInputWarning(false) {
 
   // Provide a sane fallback if no VFS is specified.
@@ -103,6 +106,13 @@
   Dir = llvm::sys::path::parent_path(ClangExecutable);
   InstalledDir = Dir; // Provide a sensible default installed dir.
 
+#if defined(CLANG_CONFIG_FILE_SYSTEM_DIR)
+  SystemConfigDir = CLANG_CONFIG_FILE_SYSTEM_DIR;
+#endif
+#if defined(CLANG_CONFIG_FILE_USER_DIR)
+  UserConfigDir = CLANG_CONFIG_FILE_USER_DIR;
+#endif
+
   // Compute the path to the resource directory.
   StringRef ClangResourceDir(CLANG_RESOURCE_DIR);
   SmallString<128> P(Dir);
@@ -600,6 +610,216 @@
   //
 }
 
+/// Looks the given directories for the specified file.
+///
+/// \param[out] FilePath File path, if the file was found.
+/// \param[in]  Dirs Directories used for the search.
+/// \param[in]  FileName Name of the file to search for.
+/// \return True if file was found.
+///
+/// Looks for file specified by FileName sequentially in directories specified
+/// by Dirs.
+///
+static bool searchForFile(SmallVectorImpl &FilePath,
+  ArrayRef Dirs,
+  StringRef FileName) {
+  SmallString<128> WPath;
+  for (const StringRef &Dir : Dirs) {
+if (Dir.empty())
+  continue;
+WPath.clear();
+llvm::sys::path::append(WPath, Dir, FileName);
+llvm::sys::path::native(WPath);
+if (llvm::sys::fs::is_regular_file(WPath)) {
+  FilePath = std::move(WPath);
+  return true;
+}
+  }
+  return false;
+}
+
+bool Driver::readConfigFile(StringRef FileName) {
+  // Try reading the given file.
+  SmallVector NewCfgArgs;
+  if (!llvm::cl::readConfigFile(FileName, Saver, NewCfgArgs)) {
+Diag(diag::err_drv_cannot_read_config_file) << FileName;
+return true;
+  }
+
+  // Read options from config file.
+  llvm::SmallString<128> CfgFileName(FileName);
+  llvm::sys::path::native(CfgFileName);
+  ConfigFile = CfgFileName.str();
+  bool ContainErrors;
+  CfgOptions = llvm::make_unique(
+  ParseArgStrings(NewCfgArgs, ContainErrors));
+  if (ContainErrors) {
+CfgOptions.reset();
+return true;
+  }
+
+  if (CfgOptions->hasArg(options::OPT_config)) {
+CfgOptions.reset();
+Diag(diag::err_drv_nested_config_file);
+return true;
+  }
+
+  // Claim all arguments that come from a configuration file so that the driver
+  // does not warn on any that is unused.
+  for (Arg *A : *CfgOptions)
+A->claim();
+  return false;
+}
+
+bool Driver::loadConfigFile() {

r321588 - Reverted 321587: Enable configuration files in clang

2017-12-30 Thread Serge Pavlov via cfe-commits
Author: sepavloff
Date: Sat Dec 30 10:38:44 2017
New Revision: 321588

URL: http://llvm.org/viewvc/llvm-project?rev=321588&view=rev
Log:
Reverted 321587: Enable configuration files in clang

Need to check targets in tests more carefully.


Removed:
cfe/trunk/test/Driver/Inputs/config/
cfe/trunk/test/Driver/Inputs/config-1.cfg
cfe/trunk/test/Driver/Inputs/config-2.cfg
cfe/trunk/test/Driver/Inputs/config-2a.cfg
cfe/trunk/test/Driver/Inputs/config-3.cfg
cfe/trunk/test/Driver/Inputs/config-4.cfg
cfe/trunk/test/Driver/Inputs/config-5.cfg
cfe/trunk/test/Driver/Inputs/config-6.cfg
cfe/trunk/test/Driver/Inputs/config2/
cfe/trunk/test/Driver/config-file-errs.c
cfe/trunk/test/Driver/config-file.c
cfe/trunk/test/Driver/config-file2.c
cfe/trunk/test/Driver/config-file3.c
Modified:
cfe/trunk/docs/UsersManual.rst
cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
cfe/trunk/include/clang/Config/config.h.cmake
cfe/trunk/include/clang/Driver/Driver.h
cfe/trunk/include/clang/Driver/Options.td
cfe/trunk/lib/Driver/Driver.cpp

Modified: cfe/trunk/docs/UsersManual.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/UsersManual.rst?rev=321588&r1=321587&r2=321588&view=diff
==
--- cfe/trunk/docs/UsersManual.rst (original)
+++ cfe/trunk/docs/UsersManual.rst Sat Dec 30 10:38:44 2017
@@ -694,77 +694,6 @@ a special character, which is the conven
 option tells Clang to put double-quotes around the entire filename, which
 is the convention used by NMake and Jom.
 
-Configuration files

-
-Configuration files group command-line options and allow all of them to be
-specified just by referencing the configuration file. They may be used, for
-example, to collect options required to tune compilation for particular
-target, such as -L, -I, -l, --sysroot, codegen options, etc.
-
-The command line option `--config` can be used to specify configuration
-file in a Clang invocation. For example:
-
-::
-
-clang --config /home/user/cfgs/testing.txt
-clang --config debug.cfg
-
-If the provided argument contains a directory separator, it is considered as
-a file path, and options are read from that file. Otherwise the argument is
-treated as a file name and is searched for sequentially in the directories:
-- user directory,
-- system directory,
-- the directory where Clang executable resides.
-Both user and system directories for configuration files are specified during
-clang build using CMake parameters, CLANG_CONFIG_FILE_USER_DIR and
-CLANG_CONFIG_FILE_SYSTEM_DIR respectively. The first file found is used. It is
-an error if the required file cannot be found.
-
-Another way to specify a configuration file is to encode it in executable name.
-For example, if the Clang executable is named `armv7l-clang` (it may be a
-symbolic link to `clang`), then Clang will search for file `armv7l.cfg` in the
-directory where Clang resides.
-
-If a driver mode is specified in invocation, Clang tries to find a file 
specific
-for the specified mode. For example, if the executable file is named
-`x86_64-clang-cl`, Clang first looks for `x86_64-cl.cfg` and if it is not 
found,
-looks for `x86_64.cfg'.
-
-If the command line contains options that effectively change target 
architecture
-(these are -m32, -EL, and some others) and the configuration file starts with 
an
-architecture name, Clang tries to load the configuration file for the effective
-architecture. For example, invocation:
-
-::
-
-x86_64-clang -m32 abc.c
-
-causes Clang search for a file `i368.cfg` first, and if no such file is found,
-Clang looks for the file `x86_64.cfg`.
-
-The configuration file consists of command-line options specified on one or
-more lines. Lines composed of whitespace characters only are ignored as well as
-lines in which the first non-blank character is `#`. Long options may be split
-between several lines by a trailing backslash. Here is example of a
-configuration file:
-
-::
-
-# Several options on line
--c --target=x86_64-unknown-linux-gnu
-
-# Long option split between lines
--I/usr/lib/gcc/x86_64-linux-gnu/5.4.0/../../../../\
-include/c++/5.4.0
-
-# other config files may be included
-@linux.options
-
-Files included by `@file` directives in configuration files are resolved
-relative to the including file. For example, if a configuration file
-`~/.llvm/target.cfg` contains the directive `@os/linux.opts`, the file
-`linux.opts` is searched for in the directory `~/.llvm/os`.
 
 Language and Target-Independent Features
 

Modified: cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td?rev=321588&r1=321587&r2=321588&view=diff
==
--- c

r321590 - [NFC] Modernize enum DeclSpecContext into a scoped enum.

2017-12-30 Thread Faisal Vali via cfe-commits
Author: faisalv
Date: Sat Dec 30 16:06:40 2017
New Revision: 321590

URL: http://llvm.org/viewvc/llvm-project?rev=321590&view=rev
Log:
[NFC] Modernize enum DeclSpecContext into a scoped enum.

Modified:
cfe/trunk/include/clang/Parse/Parser.h
cfe/trunk/lib/Parse/ParseDecl.cpp
cfe/trunk/lib/Parse/ParseDeclCXX.cpp
cfe/trunk/lib/Parse/ParseExprCXX.cpp
cfe/trunk/lib/Parse/ParseObjc.cpp
cfe/trunk/lib/Parse/ParseTemplate.cpp
cfe/trunk/lib/Parse/Parser.cpp

Modified: cfe/trunk/include/clang/Parse/Parser.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Parser.h?rev=321590&r1=321589&r2=321590&view=diff
==
--- cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/trunk/include/clang/Parse/Parser.h Sat Dec 30 16:06:40 2017
@@ -1856,7 +1856,7 @@ private:
   /// A context for parsing declaration specifiers.  TODO: flesh this
   /// out, there are other significant restrictions on specifiers than
   /// would be best implemented in the parser.
-  enum DeclSpecContext {
+  enum class DeclSpecContext {
 DSC_normal, // normal context
 DSC_class,  // class context, enables 'friend'
 DSC_type_specifier, // C++ type-specifier-seq or C specifier-qualifier-list
@@ -1873,18 +1873,18 @@ private:
   /// trailing-type-specifier)?
   static bool isTypeSpecifier(DeclSpecContext DSC) {
 switch (DSC) {
-case DSC_normal:
-case DSC_template_param:
-case DSC_class:
-case DSC_top_level:
-case DSC_objc_method_result:
-case DSC_condition:
+case DeclSpecContext::DSC_normal:
+case DeclSpecContext::DSC_template_param:
+case DeclSpecContext::DSC_class:
+case DeclSpecContext::DSC_top_level:
+case DeclSpecContext::DSC_objc_method_result:
+case DeclSpecContext::DSC_condition:
   return false;
 
-case DSC_template_type_arg:
-case DSC_type_specifier:
-case DSC_trailing:
-case DSC_alias_declaration:
+case DeclSpecContext::DSC_template_type_arg:
+case DeclSpecContext::DSC_type_specifier:
+case DeclSpecContext::DSC_trailing:
+case DeclSpecContext::DSC_alias_declaration:
   return true;
 }
 llvm_unreachable("Missing DeclSpecContext case");
@@ -1894,18 +1894,18 @@ private:
   /// deduction?
   static bool isClassTemplateDeductionContext(DeclSpecContext DSC) {
 switch (DSC) {
-case DSC_normal:
-case DSC_template_param:
-case DSC_class:
-case DSC_top_level:
-case DSC_condition:
-case DSC_type_specifier:
+case DeclSpecContext::DSC_normal:
+case DeclSpecContext::DSC_template_param:
+case DeclSpecContext::DSC_class:
+case DeclSpecContext::DSC_top_level:
+case DeclSpecContext::DSC_condition:
+case DeclSpecContext::DSC_type_specifier:
   return true;
 
-case DSC_objc_method_result:
-case DSC_template_type_arg:
-case DSC_trailing:
-case DSC_alias_declaration:
+case DeclSpecContext::DSC_objc_method_result:
+case DeclSpecContext::DSC_template_type_arg:
+case DeclSpecContext::DSC_trailing:
+case DeclSpecContext::DSC_alias_declaration:
   return false;
 }
 llvm_unreachable("Missing DeclSpecContext case");
@@ -1954,17 +1954,19 @@ private:
 ParsedAttributesWithRange &Attrs);
   DeclSpecContext
   getDeclSpecContextFromDeclaratorContext(DeclaratorContext Context);
-  void ParseDeclarationSpecifiers(DeclSpec &DS,
-const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(),
-  AccessSpecifier AS = AS_none,
-  DeclSpecContext DSC = DSC_normal,
-  LateParsedAttrList *LateAttrs = nullptr);
-  bool DiagnoseMissingSemiAfterTagDefinition(DeclSpec &DS, AccessSpecifier AS,
-   DeclSpecContext DSContext,
-   LateParsedAttrList *LateAttrs = 
nullptr);
-
-  void ParseSpecifierQualifierList(DeclSpec &DS, AccessSpecifier AS = AS_none,
-   DeclSpecContext DSC = DSC_normal);
+  void ParseDeclarationSpecifiers(
+  DeclSpec &DS,
+  const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(),
+  AccessSpecifier AS = AS_none,
+  DeclSpecContext DSC = DeclSpecContext::DSC_normal,
+  LateParsedAttrList *LateAttrs = nullptr);
+  bool DiagnoseMissingSemiAfterTagDefinition(
+  DeclSpec &DS, AccessSpecifier AS, DeclSpecContext DSContext,
+  LateParsedAttrList *LateAttrs = nullptr);
+
+  void ParseSpecifierQualifierList(
+  DeclSpec &DS, AccessSpecifier AS = AS_none,
+  DeclSpecContext DSC = DeclSpecContext::DSC_normal);
 
   void ParseObjCTypeQualifierList(ObjCDeclSpec &DS,
   DeclaratorContext Context);

Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=321590&r1=321589&r2=32159

[PATCH] D39937: [Sema] Improve diagnostics for const- and ref-qualified member functions

2017-12-30 Thread Jacob Bandes-Storch via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC321592: [Sema] Improve diagnostics for const- and 
ref-qualified member functions (authored by jtbandes, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D39937?vs=123481&id=128366#toc

Repository:
  rC Clang

https://reviews.llvm.org/D39937

Files:
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/Sema/SemaOverload.cpp
  test/CXX/over/over.match/over.match.funcs/p4-0x.cpp
  test/SemaCXX/copy-initialization.cpp

Index: include/clang/Basic/DiagnosticSemaKinds.td
===
--- include/clang/Basic/DiagnosticSemaKinds.td
+++ include/clang/Basic/DiagnosticSemaKinds.td
@@ -1589,12 +1589,20 @@
 def ext_pure_function_definition : ExtWarn<
   "function definition with pure-specifier is a Microsoft extension">,
   InGroup;
-def err_implicit_object_parameter_init : Error<
-  "cannot initialize object parameter of type %0 with an expression "
-  "of type %1">;
 def err_qualified_member_of_unrelated : Error<
   "%q0 is not a member of class %1">;
 
+def err_member_function_call_bad_cvr : Error<
+  "'this' argument to member function %0 has type %1, but function is not marked "
+  "%select{const|restrict|const or restrict|volatile|const or volatile|"
+  "volatile or restrict|const, volatile, or restrict}2">;
+def err_member_function_call_bad_ref : Error<
+  "'this' argument to member function %0 is an %select{lvalue|rvalue}1, "
+  "but function has %select{non-const lvalue|rvalue}2 ref-qualifier">;
+def err_member_function_call_bad_type : Error<
+  "cannot initialize object parameter of type %0 with an expression "
+  "of type %1">;
+
 def warn_call_to_pure_virtual_member_function_from_ctor_dtor : Warning<
   "call to pure virtual member function %0 has undefined behavior; "
   "overrides of %0 in subclasses are not available in the "
@@ -1815,10 +1823,6 @@
 def err_init_list_bad_dest_type : Error<
   "%select{|non-aggregate }0type %1 cannot be initialized with an initializer "
   "list">;
-def err_member_function_call_bad_cvr : Error<"member function %0 not viable: "
-"'this' argument has type %1, but function is not marked "
-"%select{const|restrict|const or restrict|volatile|const or volatile|"
-"volatile or restrict|const, volatile, or restrict}2">;
 
 def err_reference_bind_to_bitfield : Error<
   "%select{non-const|volatile}0 reference cannot bind to "
Index: test/SemaCXX/copy-initialization.cpp
===
--- test/SemaCXX/copy-initialization.cpp
+++ test/SemaCXX/copy-initialization.cpp
@@ -26,7 +26,7 @@
 };
 
 // PR3600
-void test(const foo *P) { P->bar(); } // expected-error{{'bar' not viable: 'this' argument has type 'const foo', but function is not marked const}}
+void test(const foo *P) { P->bar(); } // expected-error{{'this' argument to member function 'bar' has type 'const foo', but function is not marked const}}
 
 namespace PR6757 {
   struct Foo {
Index: test/CXX/over/over.match/over.match.funcs/p4-0x.cpp
===
--- test/CXX/over/over.match/over.match.funcs/p4-0x.cpp
+++ test/CXX/over/over.match/over.match.funcs/p4-0x.cpp
@@ -1,5 +1,4 @@
 // RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
-// expected-no-diagnostics
 
 template T &lvalue();
 template T &&xvalue();
@@ -20,6 +19,18 @@
 
   void g();
 
+  void c() const; // expected-note {{'c' declared here}}
+  void v() volatile; // expected-note {{'v' declared here}}
+  void r() __restrict__; // expected-note {{'r' declared here}}
+  void cr() const __restrict__; // expected-note {{'cr' declared here}}
+  void cv() const volatile;
+  void vr() volatile __restrict__; // expected-note {{'vr' declared here}}
+  void cvr() const volatile __restrict__;
+
+  void lvalue() &; // expected-note 2 {{'lvalue' declared here}}
+  void const_lvalue() const&;
+  void rvalue() &&; // expected-note {{'rvalue' declared here}}
+
   int &operator+(const X0&) &;
   float &operator+(const X0&) &&;
 
@@ -32,7 +43,7 @@
   float &h2() const&&;
 };
 
-void X0::g() {
+void X0::g() { // expected-note {{'g' declared here}}
   int &ir1 = f();
   int &ir2 = X0::f();
 }
@@ -69,3 +80,26 @@
   float &fr3 = xvalue().h2();
   float &fr4 = prvalue().h2();
 }
+
+void test_diagnostics(const volatile X0 &__restrict__ cvr) {
+  cvr.g(); // expected-error {{'this' argument to member function 'g' has type 'const volatile X0', but function is not marked const or volatile}}
+  cvr.c(); // expected-error {{not marked volatile}}
+  cvr.v(); // expected-error {{not marked const}}
+  cvr.r(); // expected-error {{not marked const or volatile}}
+  cvr.cr(); // expected-error {{not marked volatile}}
+  cvr.cv();
+  cvr.vr(); // expected-error {{not marked const}}
+  cvr.cvr();
+
+  lvalue().lvalue();
+  lvalue().const_lvalue();
+  lvalue().rvalue(); // expected-error {{'this' argument to member function 'r

[PATCH] D41646: [Sema] Improve diagnostics for const- and ref-qualified member functions

2017-12-30 Thread Jacob Bandes-Storch via Phabricator via cfe-commits
jtbandes created this revision.
jtbandes added a reviewer: aaron.ballman.

Re-submission of https://reviews.llvm.org/D39937 with additional fixed tests.


Repository:
  rC Clang

https://reviews.llvm.org/D41646

Files:
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/Sema/SemaOverload.cpp
  test/CXX/over/over.match/over.match.funcs/p4-0x.cpp
  test/CXX/stmt.stmt/stmt.iter/stmt.ranged/p1.cpp
  test/SemaCXX/copy-initialization.cpp
  test/SemaCXX/cxx1y-contextual-conversion-tweaks.cpp
  test/SemaCXX/cxx2a-pointer-to-const-ref-member.cpp

Index: test/SemaCXX/cxx2a-pointer-to-const-ref-member.cpp
===
--- test/SemaCXX/cxx2a-pointer-to-const-ref-member.cpp
+++ test/SemaCXX/cxx2a-pointer-to-const-ref-member.cpp
@@ -1,12 +1,12 @@
 // RUN: %clang_cc1 -std=c++2a %s -verify
 
 struct X {
-  void ref() & {}
+  void ref() & {} // expected-note{{'ref' declared here}}
   void cref() const& {}
 };
 
 void test() {
-  X{}.ref(); // expected-error{{cannot initialize object parameter of type 'X' with an expression of type 'X'}}
+  X{}.ref(); // expected-error{{'this' argument to member function 'ref' is an rvalue, but function has non-const lvalue ref-qualifier}}
   X{}.cref(); // expected-no-error
 
   (X{}.*&X::ref)(); // expected-error-re{{pointer-to-member function type 'void (X::*)() {{.*}}&' can only be called on an lvalue}}
Index: test/SemaCXX/cxx1y-contextual-conversion-tweaks.cpp
===
--- test/SemaCXX/cxx1y-contextual-conversion-tweaks.cpp
+++ test/SemaCXX/cxx1y-contextual-conversion-tweaks.cpp
@@ -96,8 +96,8 @@
 //expected-error@81 {{statement requires expression of integer type ('extended_examples::A1' invalid)}}
 //expected-error@85 {{statement requires expression of integer type ('extended_examples::B2' invalid)}}
 #else
-//expected-error@81 {{cannot initialize object parameter of type 'extended_examples::A1' with an expression of type 'extended_examples::A1'}}
-//expected-error@85 {{cannot initialize object parameter of type 'extended_examples::B2' with an expression of type 'extended_examples::B2'}}
+//expected-error@81 {{'this' argument to member function 'operator int' is an lvalue, but function has rvalue ref-qualifier}} expected-note@54 {{'operator int' declared here}}
+//expected-error@85 {{'this' argument to member function 'operator int' is an lvalue, but function has rvalue ref-qualifier}} expected-note@75 {{'operator int' declared here}}
 #endif
 
 namespace extended_examples_cxx1y {
@@ -149,9 +149,9 @@
 #ifdef CXX1Y
 //expected-error@139 {{statement requires expression of integer type ('extended_examples_cxx1y::A2' invalid)}}
 #else
-//expected-error@138 {{cannot initialize object parameter of type 'extended_examples_cxx1y::A1' with an expression of type 'extended_examples_cxx1y::A1'}}
-//expected-error@139 {{cannot initialize object parameter of type 'extended_examples_cxx1y::A2' with an expression of type 'extended_examples_cxx1y::A2'}}
-//expected-error@143 {{cannot initialize object parameter of type 'extended_examples_cxx1y::D' with an expression of type 'extended_examples_cxx1y::D'}}
+//expected-error@138 {{'this' argument to member function 'operator int' is an lvalue, but function has rvalue ref-qualifier}} expected-note@106 {{'operator int' declared here}}
+//expected-error@139 {{'this' argument to member function 'operator int' is an lvalue, but function has rvalue ref-qualifier}} expected-note@111 {{'operator int' declared here}}
+//expected-error@143 {{'this' argument to member function 'operator int' is an lvalue, but function has rvalue ref-qualifier}} expected-note@131 {{'operator int' declared here}}
 #endif
 
 namespace extended_examples_array_bounds {
Index: test/SemaCXX/copy-initialization.cpp
===
--- test/SemaCXX/copy-initialization.cpp
+++ test/SemaCXX/copy-initialization.cpp
@@ -26,7 +26,7 @@
 };
 
 // PR3600
-void test(const foo *P) { P->bar(); } // expected-error{{'bar' not viable: 'this' argument has type 'const foo', but function is not marked const}}
+void test(const foo *P) { P->bar(); } // expected-error{{'this' argument to member function 'bar' has type 'const foo', but function is not marked const}}
 
 namespace PR6757 {
   struct Foo {
Index: test/CXX/stmt.stmt/stmt.iter/stmt.ranged/p1.cpp
===
--- test/CXX/stmt.stmt/stmt.iter/stmt.ranged/p1.cpp
+++ test/CXX/stmt.stmt/stmt.iter/stmt.ranged/p1.cpp
@@ -215,7 +215,7 @@
 template
 void i(T t) {
   for (auto u : t) { // expected-error {{invalid range expression of type 'X::A *'; no viable 'begin' function available}} \
-expected-error {{member function 'begin' not viable}} \
+expected-error {{'this' argument to member function 'begin' has type 'const X::A', but function is not marked const}} \
 expected

[PATCH] D39937: [Sema] Improve diagnostics for const- and ref-qualified member functions

2017-12-30 Thread Jacob Bandes-Storch via Phabricator via cfe-commits
jtbandes added a comment.

After merging the buildbots informed me some other tests were broken that I 
failed to notice. I reverted this commit and submitted 
https://reviews.llvm.org/D41646 which reintroduces the changes and fixes the 
other broken tests.


Repository:
  rC Clang

https://reviews.llvm.org/D39937



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits