r245199 - [modules] When explicitly building a module file, don't include timestamps in

2015-08-17 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Mon Aug 17 02:13:32 2015
New Revision: 245199

URL: http://llvm.org/viewvc/llvm-project?rev=245199&view=rev
Log:
[modules] When explicitly building a module file, don't include timestamps in
the produced pcm file for stable file creation across distributed build
systems.

Modified:
cfe/trunk/include/clang/Frontend/FrontendOptions.h
cfe/trunk/include/clang/Serialization/ASTWriter.h
cfe/trunk/include/clang/Serialization/Module.h
cfe/trunk/lib/Frontend/CompilerInstance.cpp
cfe/trunk/lib/Frontend/FrontendActions.cpp
cfe/trunk/lib/Serialization/ASTReader.cpp
cfe/trunk/lib/Serialization/ASTReaderInternals.h
cfe/trunk/lib/Serialization/ASTWriter.cpp
cfe/trunk/lib/Serialization/GeneratePCH.cpp
cfe/trunk/test/Modules/explicit-build-missing-files.cpp
cfe/trunk/test/Modules/module-map-path-hash.cpp

Modified: cfe/trunk/include/clang/Frontend/FrontendOptions.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/FrontendOptions.h?rev=245199&r1=245198&r2=245199&view=diff
==
--- cfe/trunk/include/clang/Frontend/FrontendOptions.h (original)
+++ cfe/trunk/include/clang/Frontend/FrontendOptions.h Mon Aug 17 02:13:32 2015
@@ -147,6 +147,8 @@ public:
///< dumps in AST dumps.
   unsigned ASTDumpLookups : 1; ///< Whether we include lookup table
///< dumps in AST dumps.
+  unsigned BuildingImplicitModule : 1; ///< Whether we are performing an
+   ///< implicit module build.
 
   CodeCompleteOptions CodeCompleteOpts;
 
@@ -263,6 +265,7 @@ public:
 FixToTemporaries(false), ARCMTMigrateEmitARCErrors(false),
 SkipFunctionBodies(false), UseGlobalModuleIndex(true),
 GenerateGlobalModuleIndex(true), ASTDumpDecls(false), 
ASTDumpLookups(false),
+BuildingImplicitModule(false),
 ARCMTAction(ARCMT_None), ObjCMTAction(ObjCMT_None),
 ProgramAction(frontend::ParseSyntaxOnly)
   {}

Modified: cfe/trunk/include/clang/Serialization/ASTWriter.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ASTWriter.h?rev=245199&r1=245198&r2=245199&view=diff
==
--- cfe/trunk/include/clang/Serialization/ASTWriter.h (original)
+++ cfe/trunk/include/clang/Serialization/ASTWriter.h Mon Aug 17 02:13:32 2015
@@ -119,6 +119,12 @@ private:
   /// \brief The base directory for any relative paths we emit.
   std::string BaseDirectory;
 
+  /// \brief Indicates whether timestamps should be written to the produced
+  /// module file. This is the case for files implicitly written to the
+  /// module cache, where we need the timestamps to determine if the module
+  /// file is up to date, but not otherwise.
+  bool IncludeTimestamps;
+
   /// \brief Indicates when the AST writing is actively performing
   /// serialization, rather than just queueing updates.
   bool WritingAST;
@@ -569,11 +575,16 @@ private:
 public:
   /// \brief Create a new precompiled header writer that outputs to
   /// the given bitstream.
-  ASTWriter(llvm::BitstreamWriter &Stream);
+  ASTWriter(llvm::BitstreamWriter &Stream, bool IncludeTimestamps = true);
   ~ASTWriter() override;
 
   const LangOptions &getLangOpts() const;
 
+  /// \brief Get a timestamp for output into the AST file. The actual timestamp
+  /// of the specified file may be ignored if we have been instructed to not
+  /// include timestamps in the output file.
+  time_t getTimestampForOutput(const FileEntry *E) const;
+
   /// \brief Write a precompiled header for the given semantic analysis.
   ///
   /// \param SemaRef a reference to the semantic analysis object that processed
@@ -892,7 +903,8 @@ public:
   PCHGenerator(const Preprocessor &PP, StringRef OutputFile,
clang::Module *Module, StringRef isysroot,
std::shared_ptr Buffer,
-   bool AllowASTWithErrors = false);
+   bool AllowASTWithErrors = false,
+   bool IncludeTimestamps = true);
   ~PCHGenerator() override;
   void InitializeSema(Sema &S) override { SemaPtr = &S; }
   void HandleTranslationUnit(ASTContext &Ctx) override;

Modified: cfe/trunk/include/clang/Serialization/Module.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/Module.h?rev=245199&r1=245198&r2=245199&view=diff
==
--- cfe/trunk/include/clang/Serialization/Module.h (original)
+++ cfe/trunk/include/clang/Serialization/Module.h Mon Aug 17 02:13:32 2015
@@ -152,6 +152,9 @@ public:
   /// \brief Whether this precompiled header is a relocatable PCH file.
   bool RelocatablePCH;
 
+  /// \brief Whether timestamps are included in this module file.
+  bool HasTimestamps;
+
   /// \brief The file entry for the 

Re: [PATCH] D11832: [Patch] [Analyzer] false positive: Potential leak connected with memcpy (PR 22954)

2015-08-17 Thread pierre gousseau via cfe-commits
pgousseau added a comment.

In http://reviews.llvm.org/D11832#224929, @dcoughlin wrote:

> You should consider what should happen when the memcpy may write past the end 
> of the fixed-size array and add tests that specify correct behavior for these 
> cases. An important example is:
>
>   struct Foo {
> char data[4];
> int i;
>   };
>   
>   Foo f;
>   f.i = 10;
>  
>   memcpy(f.data, someBuf, 100);
>   
>   clang_analyzer_eval(f.i == 10); // What should this yield?
>   
>
> I think it is also important to add tests for regions at symbolic offsets, 
> for bindings in the super region having keys with symbolic offsets, and for 
> cases where there is potential aliasing and casting between regions with 
> symbolic offsets.


Yes it seems I overlooked symbolic offsets in the test cases, will handle those.

> Also, Jordan wrote up a description of the region store in 
> docs/analyzer/RegionStore.txt that you might find helpful if you haven't 
> already seen it.


Very usefull thanks !



Comment at: lib/StaticAnalyzer/Core/RegionStore.cpp:746
@@ -739,1 +745,3 @@
+return static_cast(this)->hasTrait(MR, IK);
+  }
 };

ayartsev wrote:
> Hmm.. Either we completely encapsulate 'RegionAndSymbolInvalidationTraits' in 
> the 'invalidateRegionsWorker' class or we move 
> 'RegionAndSymbolInvalidationTraits' (maybe renamed to the more general name) 
> to the base 'ClusterAnalysis' class. 
> In the suggested solution you on the one hand make processing of 
> 'RegionAndSymbolInvalidationTraits' specific to 'invalidateRegionsWorker' 
> class but on the other hand explicitly refer to 
> 'RegionAndSymbolInvalidationTraits::InvalidationKinds' and  
> 'RegionAndSymbolInvalidationTraits::TK_DoNotInvalidateSuperRegion' in the 
> 'ClusterAnalysis' class.
> It seems to me the proper way to encapsulate 
> 'RegionAndSymbolInvalidationTraits' in the 'invalidateRegionsWorker' is to 
> just override 'AddToWorkList()' in subclasses (as you done with 'hasTrait()').
I agree yes overriding AddToWorkList would fit better, will upload new patch. 
Thanks !


Comment at: lib/StaticAnalyzer/Core/RegionStore.cpp:1110
@@ +1109,3 @@
+  assert(RO.getOffset() >= 0 && "Offset should not be negative");
+  uint64_t LowerOffset = RO.getOffset();
+  uint64_t UpperOffset = LowerOffset + *NumElements * ElemSize;

dcoughlin wrote:
> R0.getOffset() will assert if R0 is a symbolic region offset. This can happen 
> if the invalidated array is itself in an array (e.g., 
> someOtherArray[i].array) or is in a union.
Yes that definitely needs fixing. Thanks !


Comment at: lib/StaticAnalyzer/Core/RegionStore.cpp:1118
@@ +1117,3 @@
+   ++I) {
+uint64_t ROffset = I.getKey().getOffset();
+if (ROffset >= LowerOffset && ROffset <= UpperOffset)

dcoughlin wrote:
> getOffset() here will assert also if there is any key with a symbolic offset 
> in SuperR.
Will fix. Thanks !


Comment at: lib/StaticAnalyzer/Core/RegionStore.cpp:1119
@@ +1118,3 @@
+uint64_t ROffset = I.getKey().getOffset();
+if (ROffset >= LowerOffset && ROffset <= UpperOffset)
+  B = B.removeBinding(I.getKey());

dcoughlin wrote:
> Should this be ROffset < UpperOffset?
Yes, will change to (ROffset < UpperOffset || (LowerOffset == UpperOffset && 
ROffset == LowerOffset)).
To handle arrays of 0 elements and arrays of 0 sized elements.
Thanks !


http://reviews.llvm.org/D11832



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


Re: [PATCH] D11932: [OPENMP] Link libomp.lib on Windows

2015-08-17 Thread Alexey Bataev via cfe-commits
ABataev updated this revision to Diff 32275.
ABataev added a comment.

Add path to libomp.lib.


http://reviews.llvm.org/D11932

Files:
  lib/Driver/Tools.cpp
  test/OpenMP/linking.c

Index: lib/Driver/Tools.cpp
===
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -8884,6 +8884,27 @@
 
   Args.AddAllArgValues(CmdArgs, options::OPT__SLASH_link);
 
+  if (Args.hasFlag(options::OPT_fopenmp, options::OPT_fopenmp_EQ,
+   options::OPT_fno_openmp, false)) {
+CmdArgs.push_back("-nodefaultlib:vcomp.lib");
+CmdArgs.push_back("-nodefaultlib:vcompd.lib");
+CmdArgs.push_back(Args.MakeArgString(std::string("-libpath:") +
+ TC.getDriver().Dir + "/../lib"));
+switch (getOpenMPRuntime(getToolChain(), Args)) {
+case OMPRT_OMP:
+  CmdArgs.push_back("-defaultlib:libomp.lib");
+  break;
+case OMPRT_IOMP5:
+  CmdArgs.push_back("-defaultlib:libiomp5md.lib");
+  break;
+case OMPRT_GOMP:
+  break;
+case OMPRT_Unknown:
+  // Already diagnosed.
+  break;
+}
+  }
+
   // Add filenames, libraries, and other linker inputs.
   for (const auto &Input : Inputs) {
 if (Input.isFilename()) {
Index: test/OpenMP/linking.c
===
--- test/OpenMP/linking.c
+++ test/OpenMP/linking.c
@@ -69,3 +69,21 @@
 // CHECK-LD-OVERRIDE-64: "-lgomp" "-lrt" "-lgcc"
 // CHECK-LD-OVERRIDE-64: "-lpthread" "-lc"
 //
+// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
+// RUN: -fopenmp=libomp -target x86_64-msvc-win32 \
+// RUN:   | FileCheck --check-prefix=CHECK-MSVC-LINK-64 %s
+// CHECK-MSVC-LINK-64: link.exe
+// CHECK-MSVC-LINK-64-SAME: -nodefaultlib:vcomp.lib
+// CHECK-MSVC-LINK-64-SAME: -nodefaultlib:vcompd.lib
+// CHECK-MSVC-LINK-64-SAME: -libpath:{{.+}}/../lib
+// CHECK-MSVC-LINK-64-SAME: -defaultlib:libomp.lib
+//
+// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
+// RUN: -fopenmp=libiomp5 -target x86_64-msvc-win32 \
+// RUN:   | FileCheck --check-prefix=CHECK-MSVC-ILINK-64 %s
+// CHECK-MSVC-ILINK-64: link.exe
+// CHECK-MSVC-ILINK-64-SAME: -nodefaultlib:vcomp.lib
+// CHECK-MSVC-ILINK-64-SAME: -nodefaultlib:vcompd.lib
+// CHECK-MSVC-ILINK-64-SAME: -libpath:{{.+}}/../lib
+// CHECK-MSVC-ILINK-64-SAME: -defaultlib:libiomp5md.lib
+//


Index: lib/Driver/Tools.cpp
===
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -8884,6 +8884,27 @@
 
   Args.AddAllArgValues(CmdArgs, options::OPT__SLASH_link);
 
+  if (Args.hasFlag(options::OPT_fopenmp, options::OPT_fopenmp_EQ,
+   options::OPT_fno_openmp, false)) {
+CmdArgs.push_back("-nodefaultlib:vcomp.lib");
+CmdArgs.push_back("-nodefaultlib:vcompd.lib");
+CmdArgs.push_back(Args.MakeArgString(std::string("-libpath:") +
+ TC.getDriver().Dir + "/../lib"));
+switch (getOpenMPRuntime(getToolChain(), Args)) {
+case OMPRT_OMP:
+  CmdArgs.push_back("-defaultlib:libomp.lib");
+  break;
+case OMPRT_IOMP5:
+  CmdArgs.push_back("-defaultlib:libiomp5md.lib");
+  break;
+case OMPRT_GOMP:
+  break;
+case OMPRT_Unknown:
+  // Already diagnosed.
+  break;
+}
+  }
+
   // Add filenames, libraries, and other linker inputs.
   for (const auto &Input : Inputs) {
 if (Input.isFilename()) {
Index: test/OpenMP/linking.c
===
--- test/OpenMP/linking.c
+++ test/OpenMP/linking.c
@@ -69,3 +69,21 @@
 // CHECK-LD-OVERRIDE-64: "-lgomp" "-lrt" "-lgcc"
 // CHECK-LD-OVERRIDE-64: "-lpthread" "-lc"
 //
+// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
+// RUN: -fopenmp=libomp -target x86_64-msvc-win32 \
+// RUN:   | FileCheck --check-prefix=CHECK-MSVC-LINK-64 %s
+// CHECK-MSVC-LINK-64: link.exe
+// CHECK-MSVC-LINK-64-SAME: -nodefaultlib:vcomp.lib
+// CHECK-MSVC-LINK-64-SAME: -nodefaultlib:vcompd.lib
+// CHECK-MSVC-LINK-64-SAME: -libpath:{{.+}}/../lib
+// CHECK-MSVC-LINK-64-SAME: -defaultlib:libomp.lib
+//
+// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
+// RUN: -fopenmp=libiomp5 -target x86_64-msvc-win32 \
+// RUN:   | FileCheck --check-prefix=CHECK-MSVC-ILINK-64 %s
+// CHECK-MSVC-ILINK-64: link.exe
+// CHECK-MSVC-ILINK-64-SAME: -nodefaultlib:vcomp.lib
+// CHECK-MSVC-ILINK-64-SAME: -nodefaultlib:vcompd.lib
+// CHECK-MSVC-ILINK-64-SAME: -libpath:{{.+}}/../lib
+// CHECK-MSVC-ILINK-64-SAME: -defaultlib:libiomp5md.lib
+//
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D10933: Add new IdentifierNaming check

2015-08-17 Thread Beren Minor via cfe-commits
berenm marked 2 inline comments as done.


Comment at: clang-tidy/readability/IdentifierNamingCheck.cpp:166
@@ +165,3 @@
+  static llvm::Regex Splitter(
+  "(([a-z0-9A-Z]*)(_+)|([A-Z]?[a-z0-9]+)([A-Z]|$)|([A-Z]+)([A-Z]|$))");
+

alexfh wrote:
> Why do you need the outermost parentheses?
For some unknown reason, I always thought parentheses were required around 
regex alternation... Well, I now know they are not.


http://reviews.llvm.org/D10933



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


Re: [PATCH] D10933: Add new IdentifierNaming check

2015-08-17 Thread Beren Minor via cfe-commits
berenm updated this revision to Diff 32277.
berenm added a comment.

Here is an updated version with the latest comments fixed.


http://reviews.llvm.org/D10933

Files:
  clang-tidy/readability/CMakeLists.txt
  clang-tidy/readability/IdentifierNamingCheck.cpp
  clang-tidy/readability/IdentifierNamingCheck.h
  clang-tidy/readability/ReadabilityTidyModule.cpp
  test/clang-tidy/readability-identifier-naming.cpp

Index: test/clang-tidy/readability-identifier-naming.cpp
===
--- /dev/null
+++ test/clang-tidy/readability-identifier-naming.cpp
@@ -0,0 +1,260 @@
+// RUN: $(dirname %s)/check_clang_tidy.sh %s readability-identifier-naming %t \
+// RUN:   -config='{CheckOptions: [ \
+// RUN: {key: readability-identifier-naming.AbstractClassCase, value: CamelCase}, \
+// RUN: {key: readability-identifier-naming.AbstractClassPrefix, value: 'A'}, \
+// RUN: {key: readability-identifier-naming.ClassCase, value: CamelCase}, \
+// RUN: {key: readability-identifier-naming.ClassPrefix, value: 'C'}, \
+// RUN: {key: readability-identifier-naming.ClassConstantCase, value: CamelCase}, \
+// RUN: {key: readability-identifier-naming.ClassConstantPrefix, value: 'k'}, \
+// RUN: {key: readability-identifier-naming.ClassMemberCase, value: CamelCase}, \
+// RUN: {key: readability-identifier-naming.ClassMethodCase, value: camelBack}, \
+// RUN: {key: readability-identifier-naming.ConstantCase, value: UPPER_CASE}, \
+// RUN: {key: readability-identifier-naming.ConstantSuffix, value: '_CST'}, \
+// RUN: {key: readability-identifier-naming.ConstexprFunctionCase, value: lower_case}, \
+// RUN: {key: readability-identifier-naming.ConstexprMethodCase, value: lower_case}, \
+// RUN: {key: readability-identifier-naming.ConstexprVariableCase, value: lower_case}, \
+// RUN: {key: readability-identifier-naming.EnumCase, value: CamelCase}, \
+// RUN: {key: readability-identifier-naming.EnumPrefix, value: 'E'}, \
+// RUN: {key: readability-identifier-naming.EnumConstantCase, value: UPPER_CASE}, \
+// RUN: {key: readability-identifier-naming.FunctionCase, value: camelBack}, \
+// RUN: {key: readability-identifier-naming.GlobalConstantCase, value: UPPER_CASE}, \
+// RUN: {key: readability-identifier-naming.GlobalFunctionCase, value: CamelCase}, \
+// RUN: {key: readability-identifier-naming.GlobalVariableCase, value: lower_case}, \
+// RUN: {key: readability-identifier-naming.GlobalVariablePrefix, value: 'g_'}, \
+// RUN: {key: readability-identifier-naming.InlineNamespaceCase, value: lower_case}, \
+// RUN: {key: readability-identifier-naming.LocalConstantCase, value: CamelCase}, \
+// RUN: {key: readability-identifier-naming.LocalConstantPrefix, value: 'k'}, \
+// RUN: {key: readability-identifier-naming.LocalVariableCase, value: lower_case}, \
+// RUN: {key: readability-identifier-naming.MemberCase, value: CamelCase}, \
+// RUN: {key: readability-identifier-naming.MemberPrefix, value: 'm_'}, \
+// RUN: {key: readability-identifier-naming.ConstantMemberCase, value: lower_case}, \
+// RUN: {key: readability-identifier-naming.PrivateMemberPrefix, value: '__'}, \
+// RUN: {key: readability-identifier-naming.ProtectedMemberPrefix, value: '_'}, \
+// RUN: {key: readability-identifier-naming.PublicMemberCase, value: lower_case}, \
+// RUN: {key: readability-identifier-naming.MethodCase, value: camelBack}, \
+// RUN: {key: readability-identifier-naming.PrivateMethodPrefix, value: '__'}, \
+// RUN: {key: readability-identifier-naming.ProtectedMethodPrefix, value: '_'}, \
+// RUN: {key: readability-identifier-naming.NamespaceCase, value: lower_case}, \
+// RUN: {key: readability-identifier-naming.ParameterCase, value: camelBack}, \
+// RUN: {key: readability-identifier-naming.ParameterPrefix, value: 'a_'}, \
+// RUN: {key: readability-identifier-naming.ConstantParameterCase, value: camelBack}, \
+// RUN: {key: readability-identifier-naming.ConstantParameterPrefix, value: 'i_'}, \
+// RUN: {key: readability-identifier-naming.ParameterPackCase, value: camelBack}, \
+// RUN: {key: readability-identifier-naming.PureFunctionCase, value: lower_case}, \
+// RUN: {key: readability-identifier-naming.PureMethodCase, value: camelBack}, \
+// RUN: {key: readability-identifier-naming.StaticConstantCase, value: UPPER_CASE}, \
+// RUN: {key: readability-identifier-naming.StaticVariableCase, value: camelBack}, \
+// RUN: {key: readability-identifier-naming.StaticVariablePrefix, value: 's_'}, \
+// RUN: {key: readability-identifier-naming.StructCase, value: lower_case}, \
+// RUN: {key: readability-identifier-naming.TemplateParameterCase, value: UPPER_CASE}, \
+// RUN: {key: readability-identifier-naming.TemplateTemplateParameterCase, value: CamelCase}, \
+// RUN: {key: readability-identifier-naming.TemplateUsingCase, 

Re: [PATCH] D10933: Add new IdentifierNaming check

2015-08-17 Thread Beren Minor via cfe-commits
berenm marked 6 inline comments as done.
berenm added a comment.

http://reviews.llvm.org/D10933



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


r245204 - [clang-tidy] Make NumOccurrenceFlag for SourcePaths configurable.

2015-08-17 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Mon Aug 17 05:01:42 2015
New Revision: 245204

URL: http://llvm.org/viewvc/llvm-project?rev=245204&view=rev
Log:
[clang-tidy] Make NumOccurrenceFlag for SourcePaths configurable.

Added an additional ctor that takes a NumOccurrenceFlag parameter for the
SourcePaths option. This frees applications from always having to pass at least
one source file, e.g., -list-checks.

http://reviews.llvm.org/D12069

Patch by Don Hinton!

Modified:
cfe/trunk/include/clang/Tooling/CommonOptionsParser.h
cfe/trunk/lib/Tooling/CommonOptionsParser.cpp

Modified: cfe/trunk/include/clang/Tooling/CommonOptionsParser.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Tooling/CommonOptionsParser.h?rev=245204&r1=245203&r2=245204&view=diff
==
--- cfe/trunk/include/clang/Tooling/CommonOptionsParser.h (original)
+++ cfe/trunk/include/clang/Tooling/CommonOptionsParser.h Mon Aug 17 05:01:42 
2015
@@ -72,6 +72,23 @@ public:
   /// This constructor exits program in case of error.
   CommonOptionsParser(int &argc, const char **argv,
   llvm::cl::OptionCategory &Category,
+  const char *Overview = nullptr)
+  : CommonOptionsParser(argc, argv, Category, llvm::cl::OneOrMore,
+Overview) {}
+
+  /// \brief Parses command-line, initializes a compilation database.
+  ///
+  /// This constructor can change argc and argv contents, e.g. consume
+  /// command-line options used for creating FixedCompilationDatabase.
+  ///
+  /// All options not belonging to \p Category become hidden.
+  ///
+  /// I also allows calls to set the required number of positional parameters.
+  ///
+  /// This constructor exits program in case of error.
+  CommonOptionsParser(int &argc, const char **argv,
+  llvm::cl::OptionCategory &Category,
+  llvm::cl::NumOccurrencesFlag OccurrencesFlag,
   const char *Overview = nullptr);
 
   /// Returns a reference to the loaded compilations database.

Modified: cfe/trunk/lib/Tooling/CommonOptionsParser.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/CommonOptionsParser.cpp?rev=245204&r1=245203&r2=245204&view=diff
==
--- cfe/trunk/lib/Tooling/CommonOptionsParser.cpp (original)
+++ cfe/trunk/lib/Tooling/CommonOptionsParser.cpp Mon Aug 17 05:01:42 2015
@@ -92,16 +92,16 @@ private:
 };
 } // namespace
 
-CommonOptionsParser::CommonOptionsParser(int &argc, const char **argv,
- cl::OptionCategory &Category,
- const char *Overview) {
+CommonOptionsParser::CommonOptionsParser(
+int &argc, const char **argv, cl::OptionCategory &Category,
+llvm::cl::NumOccurrencesFlag OccurrencesFlag, const char *Overview) {
   static cl::opt Help("h", cl::desc("Alias for -help"), cl::Hidden);
 
   static cl::opt BuildPath("p", cl::desc("Build path"),
 cl::Optional, cl::cat(Category));
 
   static cl::list SourcePaths(
-  cl::Positional, cl::desc(" [... ]"), cl::OneOrMore,
+  cl::Positional, cl::desc(" [... ]"), OccurrencesFlag,
   cl::cat(Category));
 
   static cl::list ArgsAfter(
@@ -120,6 +120,9 @@ CommonOptionsParser::CommonOptionsParser
argv));
   cl::ParseCommandLineOptions(argc, argv, Overview);
   SourcePathList = SourcePaths;
+  if ((OccurrencesFlag == cl::ZeroOrMore || OccurrencesFlag == cl::Optional) &&
+  SourcePathList.empty())
+return;
   if (!Compilations) {
 std::string ErrorMessage;
 if (!BuildPath.empty()) {


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


[clang-tools-extra] r245205 - [clang-tidy] Allow use of -list-checks option without need to pass source files.

2015-08-17 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Mon Aug 17 05:03:27 2015
New Revision: 245205

URL: http://llvm.org/viewvc/llvm-project?rev=245205&view=rev
Log:
[clang-tidy] Allow use of -list-checks option without need to pass source files.

Initialize CommonOptionsParser with ZeroOrOne NumOccurrenceFlag so callers can
pass -list-checks without the need to pass additional positional parameters,
then add dummy file if none were supplied.

http://reviews.llvm.org/D12070

Patch by Don Hinton!

Modified:
clang-tools-extra/trunk/clang-tidy/tool/ClangTidyMain.cpp
clang-tools-extra/trunk/test/clang-tidy/validate-check-names.cpp

Modified: clang-tools-extra/trunk/clang-tidy/tool/ClangTidyMain.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/tool/ClangTidyMain.cpp?rev=245205&r1=245204&r2=245205&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/tool/ClangTidyMain.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/tool/ClangTidyMain.cpp Mon Aug 17 
05:03:27 2015
@@ -262,17 +262,21 @@ static std::unique_ptrgetOptions(FileName);
   std::vector EnabledChecks = getCheckNames(EffectiveOptions);
 
-  // FIXME: Allow using --list-checks without positional arguments.
   if (ListChecks) {
 llvm::outs() << "Enabled checks:";
 for (auto CheckName : EnabledChecks)
@@ -283,8 +287,9 @@ static int clangTidyMain(int argc, const
 
   if (DumpConfig) {
 EffectiveOptions.CheckOptions = getCheckOptions(EffectiveOptions);
-llvm::outs() << configurationAsText(ClangTidyOptions::getDefaults()
-.mergeWith(EffectiveOptions))
+llvm::outs() << configurationAsText(
+ClangTidyOptions::getDefaults().mergeWith(
+EffectiveOptions))
  << "\n";
 return 0;
   }
@@ -295,12 +300,18 @@ static int clangTidyMain(int argc, const
 return 1;
   }
 
+  if (PathList.empty()) {
+llvm::errs() << "Error: no input files specified.\n";
+llvm::cl::PrintHelpMessage(/*Hidden=*/false, /*Categorized=*/true);
+return 1;
+  }
+
   ProfileData Profile;
 
   std::vector Errors;
   ClangTidyStats Stats =
   runClangTidy(std::move(OptionsProvider), OptionsParser.getCompilations(),
-   OptionsParser.getSourcePathList(), &Errors,
+   PathList, &Errors,
EnableCheckProfile ? &Profile : nullptr);
   bool FoundErrors =
   std::find_if(Errors.begin(), Errors.end(), [](const ClangTidyError &E) {

Modified: clang-tools-extra/trunk/test/clang-tidy/validate-check-names.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/validate-check-names.cpp?rev=245205&r1=245204&r2=245205&view=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/validate-check-names.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/validate-check-names.cpp Mon Aug 17 
05:03:27 2015
@@ -1,2 +1,2 @@
 // Check names may only contain alphanumeric characters, '-', '_', and '.'.
-// RUN: clang-tidy -checks=* -list-checks - -- | grep '^' | cut -b5- | not 
grep -v '^[a-zA-Z0-9_.\-]\+$'
+// RUN: clang-tidy -checks=* -list-checks | grep '^' | cut -b5- | not grep 
-v '^[a-zA-Z0-9_.\-]\+$'


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


[PATCH] Fix crash with two typos in the arguments of a function

2015-08-17 Thread Olivier Goffart via cfe-commits
Hi,

Attached you will find the fix for a crash on invalid code in clang 3.7

It crashes on this code:

void fn2() {
  f(THIS_IS_AN_ERROR,  afunction(afunction_));  
}

The problem is that the arguments are of TheCall are reset later to the ones 
in Args. Some TypoExpr that have already been diagnosed will assert later in 
Sema::getTypoExprState.

I was wondering if instead of reusing the TheCall->getArgs() array I should 
copy the arguments in an array on the stack instead.

I suppose I should commit to trunk and ask someone to merge into release_37?

Regards
-- 
Olivier
>From 7da528047bb8d925078cdc8226a9961f74130b93 Mon Sep 17 00:00:00 2001
From: Olivier Goffart 
Date: Fri, 14 Aug 2015 12:59:17 +0200
Subject: [PATCH] Fix crash with two typos in the arguments of a function

The problem is that the arguments are of TheCall are reset later
to the ones in Args, making TypoExpr put back. Some TypoExpr that have
already  been diagnosed and will assert later in Sema::getTypoExprState
---
 lib/Sema/SemaExpr.cpp   | 1 +
 test/Sema/typo-correction.c | 6 ++
 2 files changed, 7 insertions(+)

diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp
index dd99ad2..a271cbd 100644
--- a/lib/Sema/SemaExpr.cpp
+++ b/lib/Sema/SemaExpr.cpp
@@ -4937,6 +4937,7 @@ Sema::BuildResolvedCallExpr(Expr *Fn, NamedDecl *NDecl,
 if (!Result.isUsable()) return ExprError();
 TheCall = dyn_cast(Result.get());
 if (!TheCall) return Result;
+Args = ArrayRef(TheCall->getArgs(), TheCall->getNumArgs());
   }
 
   // Bail out early if calling a builtin with custom typechecking.
diff --git a/test/Sema/typo-correction.c b/test/Sema/typo-correction.c
index ff43064..4ef5057 100644
--- a/test/Sema/typo-correction.c
+++ b/test/Sema/typo-correction.c
@@ -49,3 +49,9 @@ extern double cabs(_Complex double z);
 void fn1() {
   cabs(errij);  // expected-error {{use of undeclared identifier 'errij'}}
 }
+
+extern long afunction(int); // expected-note {{'afunction' declared here}}
+void fn2() {
+  f(THIS_IS_AN_ERROR, // expected-error {{use of undeclared identifier 'THIS_IS_AN_ERROR'}}
+afunction(afunction_));  // expected-error {{use of undeclared identifier 'afunction_'; did you mean 'afunction'?}}
+}
-- 
2.5.0

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


Re: [PATCH] D12076: Add loop-convert check to clang-tidy.

2015-08-17 Thread Alexander Kornienko via cfe-commits
alexfh added a comment.

Some initial comments. I'll need a bit more time to review this thoroughly.



Comment at: test/clang-tidy/modernize-loop-convert.cpp:149
@@ +148,3 @@
+arr[i] = 0;
+  // CHECK-MESSAGES-NOT: :[[@LINE-2]]:3: warning: use range-based for loop 
instead
+  // CHECK-FIXES: for (int i = 0; i < N; ++i)

You don't need CHECK-MESSAGES-NOT. The script runs FileCheck with 
-implicit-check-not='{{warning|error}}:', which would complain on any warning 
or error that you don't have a specific check pattern for.

I'd also trust clang-tidy to not make any changes in the code without a 
corresponding warning. Thus CHECK-FIXES that verify that the code isn't changed 
are superfluous.


http://reviews.llvm.org/D12076



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


[clang-tools-extra] r245215 - [clang-tidy] Fix a use-after-free.

2015-08-17 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Mon Aug 17 06:27:11 2015
New Revision: 245215

URL: http://llvm.org/viewvc/llvm-project?rev=245215&view=rev
Log:
[clang-tidy] Fix a use-after-free.

Modified:
clang-tools-extra/trunk/clang-tidy/tool/ClangTidyMain.cpp

Modified: clang-tools-extra/trunk/clang-tidy/tool/ClangTidyMain.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/tool/ClangTidyMain.cpp?rev=245215&r1=245214&r2=245215&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/tool/ClangTidyMain.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/tool/ClangTidyMain.cpp Mon Aug 17 
06:27:11 2015
@@ -272,7 +272,7 @@ static int clangTidyMain(int argc, const
   StringRef FileName("dummy");
   auto PathList = OptionsParser.getSourcePathList();
   if (!PathList.empty()) {
-FileName = OptionsParser.getSourcePathList().front();
+FileName = PathList.front();
   }
   ClangTidyOptions EffectiveOptions = OptionsProvider->getOptions(FileName);
   std::vector EnabledChecks = getCheckNames(EffectiveOptions);


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


Re: [PATCH] D10933: Add new IdentifierNaming check

2015-08-17 Thread Alexander Kornienko via cfe-commits
alexfh accepted this revision.
alexfh added a comment.
This revision is now accepted and ready to land.

Looks good with a couple of comments. Tell me if you need me to submit the 
patch for you, once you address the comments.

Thank you for the awesome new check!



Comment at: clang-tidy/readability/IdentifierNamingCheck.cpp:153
@@ +152,3 @@
+  else
+Matches = false;
+

nit: Maybe remove the bool variable and just `return false;` instead of 
`Matches = false;`?

```
  if (Name.startswith(Style.Prefix))
Name = Name.drop_front(Style.Prefix.size());
  else
return false;

  if (Name.endswith(Style.Suffix))
Name = Name.drop_back(Style.Suffix.size());
  else
return false;

  return Matchers[static_cast(Style.Case)].match(Name);
```


Comment at: test/clang-tidy/readability-identifier-naming.cpp:70
@@ +69,3 @@
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: invalid case style for namespace 
'FOO_NS' [readability-identifier-naming]
+// CHECK-FIXES: foo_ns
+inline namespace InlineNamespace {

Looking at the tests once again, I find that they should be more strict. E.g. 
the presence of `foo_ns` doesn't say anything about whether the replacement was 
done in the right place (e.g. if the code replaces a wrong token and the result 
is `foo_ns FOO_NS {`, the test would pass). Please add more context to the 
CHECK-FIXES lines, maybe even whole lines including start- and end-of-line 
anchors (`{{^}}` and `{{$}}` respectively).

Thanks!


http://reviews.llvm.org/D10933



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


Re: [PATCH] D10933: Add new IdentifierNaming check

2015-08-17 Thread Beren Minor via cfe-commits
berenm added a comment.

In http://reviews.llvm.org/D10933#225671, @alexfh wrote:

> Looks good with a couple of comments. Tell me if you need me to submit the 
> patch for you, once you address the comments.


If you tell me how I should proceed, I can maybe do it myself (do I just have 
to send the patch to the cfe-commits list ?).


http://reviews.llvm.org/D10933



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


Re: [PATCH] D11932: [OPENMP] Link libomp.lib on Windows

2015-08-17 Thread İsmail Dönmez via cfe-commits
ismail accepted this revision.
ismail added a reviewer: ismail.
ismail added a comment.
This revision is now accepted and ready to land.

Great work. Tested fine on Windows. Next step would be mapping /openmp flag to 
-fopenmp but I guess thats for another bug.


http://reviews.llvm.org/D11932



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


RE: [PATCH] RE: [cfe-dev] missing return statement for non-void functions in C++

2015-08-17 Thread Sjoerd Meijer via cfe-commits
Agreed, let’s get that right first.
The attached patch causes the program to trap for all optimizations levels, 
except when optimizing for size.

Sjoerd.

From: dosr...@gmail.com [mailto:dosr...@gmail.com] On Behalf Of Gabriel Dos Reis
Sent: 13 August 2015 21:51
To: Richard Smith
Cc: Sjoerd Meijer; Marshall Clow; cfe-commits
Subject: Re: [PATCH] RE: [cfe-dev] missing return statement for non-void 
functions in C++

Please make such programs crash early and often.  They are a nightmare to 
maintain.  Make them blow in the face of the original authors; not after they 
are gone.

-- Gaby


-- IMPORTANT NOTICE: The contents of this email and any attachments are 
confidential and may also be privileged. If you are not the intended recipient, 
please notify the sender immediately and do not disclose the contents to any 
other person, use it for any purpose, or store or copy the information in any 
medium. Thank you.

ARM Limited, Registered office 110 Fulbourn Road, Cambridge CB1 9NJ, Registered 
in England & Wales, Company No: 2557590
ARM Holdings plc, Registered office 110 Fulbourn Road, Cambridge CB1 9NJ, 
Registered in England & Wales, Company No: 2548782


0001-Always-trap-for-missing-return-statements-except-whe.patch
Description: 0001-Always-trap-for-missing-return-statements-except-whe.patch
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D10933: Add new IdentifierNaming check

2015-08-17 Thread Alexander Kornienko via cfe-commits
alexfh added a comment.

In http://reviews.llvm.org/D10933#225678, @berenm wrote:

> In http://reviews.llvm.org/D10933#225671, @alexfh wrote:
>
> > Looks good with a couple of comments. Tell me if you need me to submit the 
> > patch for you, once you address the comments.
>
>
> If you tell me how I should proceed, I can maybe do it myself (do I just have 
> to send the patch to the cfe-commits list ?).


The question was whether you have commit rights to the LLVM Subversion 
repository. Apparently, no, so someone needs to commit the patch for you. I'll 
happily do so once you update it.


http://reviews.llvm.org/D10933



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


Re: [PATCH] D5102: [analyzer][Bugfix/improvement] Fix for PR16833

2015-08-17 Thread Aleksei Sidorin via cfe-commits
a.sidorin updated this revision to Diff 32293.
a.sidorin added a comment.

- Fix review notes
- Add some more tests
- Add a fix and a test for incorrect pruning of trivially unreachable case 
statements in CFG for SwitchStmt (accidentially found while writing a test).


http://reviews.llvm.org/D5102

Files:
  include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h
  include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
  lib/Analysis/CFG.cpp
  lib/StaticAnalyzer/Core/ExprEngine.cpp
  lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
  lib/StaticAnalyzer/Core/SimpleConstraintManager.cpp
  lib/StaticAnalyzer/Core/SimpleConstraintManager.h
  test/Analysis/switch-case.c

Index: test/Analysis/switch-case.c
===
--- /dev/null
+++ test/Analysis/switch-case.c
@@ -0,0 +1,220 @@
+// RUN: %clang_cc1 -analyze -analyzer-checker=core,debug.ExprInspection -verify %s
+
+void clang_analyzer_eval(int);
+void clang_analyzer_warnIfReached();
+
+#define INT_MIN 0x8000
+#define INT_MAX 0x7fff
+
+// PR16833: Analyzer consumes memory until killed by kernel OOM killer
+// while analyzing large case ranges.
+void PR16833(unsigned op) {
+  switch (op) {
+  case 0x02 << 26 ... 0x03 << 26: // Analyzer should not hang here.
+return;
+  }
+}
+
+void testAdjustment(int t) {
+  switch (t + 1) {
+  case 2:
+clang_analyzer_eval(t == 1); // expected-warning{{TRUE}}
+break;
+  case 3 ... 10:
+clang_analyzer_eval(t > 1);// expected-warning{{TRUE}}
+clang_analyzer_eval(t + 2 <= 11);  // expected-warning{{TRUE}}
+clang_analyzer_eval(t > 2);// expected-warning{{UNKNOWN}}
+clang_analyzer_eval(t + 1 == 3);   // expected-warning{{UNKNOWN}}
+clang_analyzer_eval(t + 1 == 10);  // expected-warning{{UNKNOWN}}
+break;
+  default:
+clang_analyzer_warnIfReached();// expected-warning{{REACHABLE}}
+  }
+}
+
+void testUnknownVal(int value, int mask) {
+  // Once ConstraintManager will process '&' and this test will require some changes.
+  switch (value & mask) {
+case 1:
+  clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
+  break;
+case 3 ... 10:
+  clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
+  break;
+default:
+  clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
+  }
+}
+
+void testSwitchCond(int arg) {
+  if (arg > 10) {
+switch (arg) {
+case INT_MIN ... 10:
+  clang_analyzer_warnIfReached(); // no-warning
+  break;
+case 11 ... 20:
+  clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
+  break;
+default:
+  clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
+}
+
+switch (arg) {
+case INT_MIN ... 9:
+  clang_analyzer_warnIfReached();  // no-warning
+  break;
+case 10 ... 20:
+  clang_analyzer_warnIfReached();  // expected-warning{{REACHABLE}}
+  clang_analyzer_eval(arg > 10);   // expected-warning{{TRUE}}
+  break;
+default:
+  clang_analyzer_warnIfReached();  // expected-warning{{REACHABLE}}
+}
+  } // arg > 10
+}
+
+void testDefaultUnreachable(int arg) {
+  if (arg > 10) {
+switch (arg) {
+case INT_MIN ... 9:
+  clang_analyzer_warnIfReached();   // no-warning
+  break;
+case 10 ... INT_MAX:
+  clang_analyzer_warnIfReached();   // expected-warning{{REACHABLE}}
+  clang_analyzer_eval(arg > 10);// expected-warning{{TRUE}}
+  break;
+default:
+  clang_analyzer_warnIfReached();   // no-warning
+}
+  }
+}
+
+void testBranchReachability(int arg) {
+  if (arg > 10 && arg < 20) {
+switch (arg) {
+case INT_MIN ... 4:
+  clang_analyzer_warnIfReached(); // no-warning
+  break;
+case 5 ... 9:
+  clang_analyzer_warnIfReached(); // no-warning
+  break;
+case 10 ... 15:
+  clang_analyzer_warnIfReached();  // expected-warning{{REACHABLE}}
+  clang_analyzer_eval(arg > 10 && arg <= 15);  // expected-warning{{TRUE}}
+  break;
+default:
+  clang_analyzer_warnIfReached(); // no-warning
+  break;
+case 17 ... 25:
+  clang_analyzer_warnIfReached();  // expected-warning{{REACHABLE}}
+  clang_analyzer_eval(arg >= 17 && arg < 20);  // expected-warning{{TRUE}}
+  break;
+case 26 ... INT_MAX:
+  clang_analyzer_warnIfReached();   // no-warning
+  break;
+case 16:
+  clang_analyzer_warnIfReached();   // expected-warning{{REACHABLE}}
+  clang_analyzer_eval(arg == 16);   // expected-warning{{TRUE}}
+  break;
+}
+  }
+}
+
+void testDefaultBranchRange(int arg) {
+  switch (arg) {
+  case INT_MIN ... 9:
+clang_analyzer_warnIfReached();  // expected-warning{{REACHABLE}}
+break;
+  case 20 ... INT_MAX:
+clang_analyzer_warnIfReached();  // expected-warning{{REACHABLE}}
+clang_analyzer_eval(arg >= 20);  // expected-warning{{TRUE}}
+break;
+  default:
+c

Re: [PATCH] D10933: Add new IdentifierNaming check

2015-08-17 Thread Beren Minor via cfe-commits
berenm updated this revision to Diff 32294.
berenm added a comment.

Indeed, I probably don't have rights on Clang/LLVM repositories.

I have updated the patch with stricter tests - and found a missing break 
statement (`clang-tidy/readability/IdentifierNamingCheck.cpp:201`).

I also realized that the DeclRefExpr matcher used to find references to 
declared identifiers is only matching references to values and not to classes.

For example, when referencing the class in the out-of-line class static member 
declaration (`test/clang-tidy/readability-identifier-naming.cpp:133` and 
`test/clang-tidy/readability-identifier-naming.cpp:136`), or  when using a 
class identifier as the type of a typedef, 
(`test/clang-tidy/readability-identifier-naming.cpp:243`). Or even when 
declaring a variable of a type whose name must be fixed.

Is there any matcher that could be used for finding references to a TypeDecl? 
Should I go through calls to `getDeclContext`, `getType`, or 
`getUnderlyingType` depending on the context? Any easier way I don't know about?


http://reviews.llvm.org/D10933

Files:
  clang-tidy/readability/CMakeLists.txt
  clang-tidy/readability/IdentifierNamingCheck.cpp
  clang-tidy/readability/IdentifierNamingCheck.h
  clang-tidy/readability/ReadabilityTidyModule.cpp
  test/clang-tidy/readability-identifier-naming.cpp

Index: test/clang-tidy/readability-identifier-naming.cpp
===
--- /dev/null
+++ test/clang-tidy/readability-identifier-naming.cpp
@@ -0,0 +1,253 @@
+// RUN: $(dirname %s)/check_clang_tidy.sh %s readability-identifier-naming %t \
+// RUN:   -config='{CheckOptions: [ \
+// RUN: {key: readability-identifier-naming.AbstractClassCase, value: CamelCase}, \
+// RUN: {key: readability-identifier-naming.AbstractClassPrefix, value: 'A'}, \
+// RUN: {key: readability-identifier-naming.ClassCase, value: CamelCase}, \
+// RUN: {key: readability-identifier-naming.ClassPrefix, value: 'C'}, \
+// RUN: {key: readability-identifier-naming.ClassConstantCase, value: CamelCase}, \
+// RUN: {key: readability-identifier-naming.ClassConstantPrefix, value: 'k'}, \
+// RUN: {key: readability-identifier-naming.ClassMemberCase, value: CamelCase}, \
+// RUN: {key: readability-identifier-naming.ClassMethodCase, value: camelBack}, \
+// RUN: {key: readability-identifier-naming.ConstantCase, value: UPPER_CASE}, \
+// RUN: {key: readability-identifier-naming.ConstantSuffix, value: '_CST'}, \
+// RUN: {key: readability-identifier-naming.ConstexprFunctionCase, value: lower_case}, \
+// RUN: {key: readability-identifier-naming.ConstexprMethodCase, value: lower_case}, \
+// RUN: {key: readability-identifier-naming.ConstexprVariableCase, value: lower_case}, \
+// RUN: {key: readability-identifier-naming.EnumCase, value: CamelCase}, \
+// RUN: {key: readability-identifier-naming.EnumPrefix, value: 'E'}, \
+// RUN: {key: readability-identifier-naming.EnumConstantCase, value: UPPER_CASE}, \
+// RUN: {key: readability-identifier-naming.FunctionCase, value: camelBack}, \
+// RUN: {key: readability-identifier-naming.GlobalConstantCase, value: UPPER_CASE}, \
+// RUN: {key: readability-identifier-naming.GlobalFunctionCase, value: CamelCase}, \
+// RUN: {key: readability-identifier-naming.GlobalVariableCase, value: lower_case}, \
+// RUN: {key: readability-identifier-naming.GlobalVariablePrefix, value: 'g_'}, \
+// RUN: {key: readability-identifier-naming.InlineNamespaceCase, value: lower_case}, \
+// RUN: {key: readability-identifier-naming.LocalConstantCase, value: CamelCase}, \
+// RUN: {key: readability-identifier-naming.LocalConstantPrefix, value: 'k'}, \
+// RUN: {key: readability-identifier-naming.LocalVariableCase, value: lower_case}, \
+// RUN: {key: readability-identifier-naming.MemberCase, value: CamelCase}, \
+// RUN: {key: readability-identifier-naming.MemberPrefix, value: 'm_'}, \
+// RUN: {key: readability-identifier-naming.ConstantMemberCase, value: lower_case}, \
+// RUN: {key: readability-identifier-naming.PrivateMemberPrefix, value: '__'}, \
+// RUN: {key: readability-identifier-naming.ProtectedMemberPrefix, value: '_'}, \
+// RUN: {key: readability-identifier-naming.PublicMemberCase, value: lower_case}, \
+// RUN: {key: readability-identifier-naming.MethodCase, value: camelBack}, \
+// RUN: {key: readability-identifier-naming.PrivateMethodPrefix, value: '__'}, \
+// RUN: {key: readability-identifier-naming.ProtectedMethodPrefix, value: '_'}, \
+// RUN: {key: readability-identifier-naming.NamespaceCase, value: lower_case}, \
+// RUN: {key: readability-identifier-naming.ParameterCase, value: camelBack}, \
+// RUN: {key: readability-identifier-naming.ParameterPrefix, value: 'a_'}, \
+// RUN: {key: readability-identifier-naming.ConstantParameterCase, value: camelBack}, \
+// RUN: {key: readability-identif

[PATCH] D12081: Add use-nullptr check to clang-tidy.

2015-08-17 Thread Angel Garcia via cfe-commits
angelgarcia created this revision.
angelgarcia added a reviewer: alexfh.
angelgarcia added subscribers: klimek, cfe-commits.
angelgarcia changed the visibility of this Differential Revision from "Public 
(No Login Required)" to "All Users".

Move UseNullptr from clang-modernize to modernize module in clang-tidy.

http://reviews.llvm.org/D12081

Files:
  clang-tidy/modernize/CMakeLists.txt
  clang-tidy/modernize/ModernizeTidyModule.cpp
  clang-tidy/modernize/UseNullptrCheck.cpp
  clang-tidy/modernize/UseNullptrCheck.h
  test/clang-tidy/modernize-use-nullptr-basic.cpp
  test/clang-tidy/modernize-use-nullptr.cpp

Index: test/clang-tidy/modernize-use-nullptr.cpp
===
--- test/clang-tidy/modernize-use-nullptr.cpp
+++ test/clang-tidy/modernize-use-nullptr.cpp
@@ -0,0 +1,179 @@
+// RUN: $(dirname %s)/check_clang_tidy.sh %s modernize-use-nullptr %t \
+// -config="{CheckOptions: [{key: modernize-use-nullptr.UserNullMacros, value: 'MY_NULL'}]}" \
+// -- -std=c++11
+
+// REQUIRES: shell
+
+#define NULL 0
+
+namespace std {
+
+typedef decltype(nullptr) nullptr_t;
+
+} // namespace std
+
+// Just to make sure make_null() could have side effects.
+void external();
+
+std::nullptr_t make_null() {
+  external();
+  return nullptr;
+}
+
+void func() {
+  void *CallTest = make_null();
+
+  int var = 1;
+  void *CommaTest = (var+=2, make_null());
+
+  int *CastTest = static_cast(make_null());
+}
+
+void dummy(int*) {}
+void side_effect() {}
+
+#define MACRO_EXPANSION_HAS_NULL \
+  void foo() { \
+dummy(0); \
+dummy(NULL); \
+side_effect(); \
+  }
+
+MACRO_EXPANSION_HAS_NULL;
+#undef MACRO_EXPANSION_HAS_NULL
+
+
+void test_macro_expansion1() {
+#define MACRO_EXPANSION_HAS_NULL \
+  dummy(NULL); \
+  side_effect();
+
+  MACRO_EXPANSION_HAS_NULL;
+
+#undef MACRO_EXPANSION_HAS_NULL
+}
+
+// Test macro expansion with cast sequence, PR15572.
+void test_macro_expansion2() {
+#define MACRO_EXPANSION_HAS_NULL \
+  dummy((int*)0); \
+  side_effect();
+
+  MACRO_EXPANSION_HAS_NULL;
+
+#undef MACRO_EXPANSION_HAS_NULL
+}
+
+void test_macro_expansion3() {
+#define MACRO_EXPANSION_HAS_NULL \
+  dummy(NULL); \
+  side_effect();
+
+#define OUTER_MACRO \
+  MACRO_EXPANSION_HAS_NULL; \
+  side_effect();
+
+  OUTER_MACRO;
+
+#undef OUTER_MACRO
+#undef MACRO_EXPANSION_HAS_NULL
+}
+
+void test_macro_expansion4() {
+#define MY_NULL NULL
+  int *p = MY_NULL;
+  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: use nullptr [modernize-use-nullptr]
+  // CHECK-FIXES: int *p = nullptr;
+#undef MY_NULL
+}
+
+#define IS_EQ(x, y) if (x != y) return;
+void test_macro_args() {
+  int i = 0;
+  int *Ptr;
+
+  IS_EQ(static_cast(0), Ptr);
+  // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: use nullptr
+  // CHECK-FIXES: IS_EQ(static_cast(nullptr), Ptr);
+
+  IS_EQ(0, Ptr);// literal
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: use nullptr
+  // CHECK-FIXES: IS_EQ(nullptr, Ptr);
+
+  IS_EQ(NULL, Ptr); // macro
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: use nullptr
+  // CHECK-FIXES: IS_EQ(nullptr, Ptr);
+
+  // These are ok since the null literal is not spelled within a macro.
+#define myassert(x) if (!(x)) return;
+  myassert(0 == Ptr);
+  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: use nullptr
+  // CHECK-FIXES: myassert(nullptr == Ptr);
+
+  myassert(NULL == Ptr);
+  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: use nullptr
+  // CHECK-FIXES: myassert(nullptr == Ptr);
+
+  // These are bad as the null literal is buried in a macro.
+#define BLAH(X) myassert(0 == (X));
+#define BLAH2(X) myassert(NULL == (X));
+  BLAH(Ptr);
+  BLAH2(Ptr);
+
+  // Same as above but testing extra macro expansion.
+#define EXPECT_NULL(X) IS_EQ(0, X);
+#define EXPECT_NULL2(X) IS_EQ(NULL, X);
+  EXPECT_NULL(Ptr);
+  EXPECT_NULL2(Ptr);
+
+  // Almost the same as above but now null literal is not in a macro so ok
+  // to transform.
+#define EQUALS_PTR(X) IS_EQ(X, Ptr);
+  EQUALS_PTR(0);
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: use nullptr
+  // CHECK-FIXES: EQUALS_PTR(nullptr);
+  EQUALS_PTR(NULL);
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: use nullptr
+  // CHECK-FIXES: EQUALS_PTR(nullptr);
+
+  // Same as above but testing extra macro expansion.
+#define EQUALS_PTR_I(X) EQUALS_PTR(X)
+  EQUALS_PTR_I(0);
+  // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: use nullptr
+  // CHECK-FIXES: EQUALS_PTR_I(nullptr);
+  EQUALS_PTR_I(NULL);
+  // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: use nullptr
+  // CHECK-FIXES: EQUALS_PTR_I(nullptr);
+
+  // Ok since null literal not within macro. However, now testing macro
+  // used as arg to another macro.
+#define decorate(EXPR) side_effect(); EXPR;
+  decorate(IS_EQ(NULL, Ptr));
+  // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: use nullptr
+  // CHECK-FIXES: decorate(IS_EQ(nullptr, Ptr));
+  decorate(IS_EQ(0, Ptr));
+  // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: use nullptr
+  // CHECK-FIXES: decorate(IS_EQ(nullptr, Ptr));
+
+  // This macro causes a NullToPointer c

Re: [PATCH] D10933: Add new IdentifierNaming check

2015-08-17 Thread Alexander Kornienko via cfe-commits
alexfh added a comment.

In http://reviews.llvm.org/D10933#225696, @berenm wrote:

> Indeed, I probably don't have rights on Clang/LLVM repositories.
>
> I have updated the patch with stricter tests - and found a missing break 
> statement (`clang-tidy/readability/IdentifierNamingCheck.cpp:201`).


Behold the magic power of testing ;)

> I also realized that the DeclRefExpr matcher used to find references to 
> declared identifiers is only matching references to values and not to classes.

> 

> For example, when referencing the class in the out-of-line class static 
> member declaration (`test/clang-tidy/readability-identifier-naming.cpp:133` 
> and `test/clang-tidy/readability-identifier-naming.cpp:136`), or  when using 
> a class identifier as the type of a typedef, 
> (`test/clang-tidy/readability-identifier-naming.cpp:243`). Or even when 
> declaring a variable of a type whose name must be fixed.

> 

> Is there any matcher that could be used for finding references to a TypeDecl? 
> Should I go through calls to `getDeclContext`, `getType`, or 
> `getUnderlyingType` depending on the context? Any easier way I don't know 
> about?


Yep, renaming classes is not as trivial as it might seem. You'll need to look 
for `TypeLoc`s (the `loc()` matcher) of `QualType`s and `NestedNameSpecifier`s 
referring to the old class name. You'd also need to match constructor 
declarations and `UsingDecl`s separately.

Here's a rough list of matchers that search for the name of a class:

  loc(qualType(hasDeclaration(namedDecl(hasName(old_class)
  loc(nestedNameSpecifier(specifiesType(
hasDeclaration(recordDecl(hasName(old_class))
  usingDecl(hasAnyUsingShadowDecl(hasTargetDecl(hasName(old_class
  recordDecl(hasName(old_class))
  constructorDecl(ofClass(hasName(old_class)))

I suggest that you add a bunch of FIXMEs in the test and we can iterate on the 
check in follow-up patches. Similar issues apply to namespace and function 
renaming.

What needs to be tested:

- for classes: forward declarations, definitions, constructors, destructors, 
using declarations, type aliases, use of the class name in `new`, casting, 
qualified names (Class::member) (also resulting from injected class name usage 
- `Class::Class::Class`), use of the class name in templates and macros (to 
ensure there are no duplicate or incorrect fixes), and probably something else 
that I forgot.
- for functions/methods: declarations, calls, using declarations, taking 
address of, with qualified names and without, probably something else.
- for namespaces: use in qualified names and using declarations and directives.


http://reviews.llvm.org/D10933



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


Re: [PATCH] D12081: Add use-nullptr check to clang-tidy.

2015-08-17 Thread Angel Garcia via cfe-commits
angelgarcia updated this revision to Diff 32303.
angelgarcia added a comment.

Previous diff was not the newest one.


http://reviews.llvm.org/D12081

Files:
  clang-tidy/modernize/CMakeLists.txt
  clang-tidy/modernize/ModernizeTidyModule.cpp
  clang-tidy/modernize/UseNullptrCheck.cpp
  clang-tidy/modernize/UseNullptrCheck.h
  test/clang-tidy/modernize-use-nullptr-basic.cpp
  test/clang-tidy/modernize-use-nullptr.cpp

Index: test/clang-tidy/modernize-use-nullptr.cpp
===
--- test/clang-tidy/modernize-use-nullptr.cpp
+++ test/clang-tidy/modernize-use-nullptr.cpp
@@ -0,0 +1,179 @@
+// RUN: $(dirname %s)/check_clang_tidy.sh %s modernize-use-nullptr %t \
+// -config="{CheckOptions: [{key: modernize-use-nullptr.UserNullMacros, value: 'MY_NULL'}]}" \
+// -- -std=c++11
+
+// REQUIRES: shell
+
+#define NULL 0
+
+namespace std {
+
+typedef decltype(nullptr) nullptr_t;
+
+} // namespace std
+
+// Just to make sure make_null() could have side effects.
+void external();
+
+std::nullptr_t make_null() {
+  external();
+  return nullptr;
+}
+
+void func() {
+  void *CallTest = make_null();
+
+  int var = 1;
+  void *CommaTest = (var+=2, make_null());
+
+  int *CastTest = static_cast(make_null());
+}
+
+void dummy(int*) {}
+void side_effect() {}
+
+#define MACRO_EXPANSION_HAS_NULL \
+  void foo() { \
+dummy(0); \
+dummy(NULL); \
+side_effect(); \
+  }
+
+MACRO_EXPANSION_HAS_NULL;
+#undef MACRO_EXPANSION_HAS_NULL
+
+
+void test_macro_expansion1() {
+#define MACRO_EXPANSION_HAS_NULL \
+  dummy(NULL); \
+  side_effect();
+
+  MACRO_EXPANSION_HAS_NULL;
+
+#undef MACRO_EXPANSION_HAS_NULL
+}
+
+// Test macro expansion with cast sequence, PR15572.
+void test_macro_expansion2() {
+#define MACRO_EXPANSION_HAS_NULL \
+  dummy((int*)0); \
+  side_effect();
+
+  MACRO_EXPANSION_HAS_NULL;
+
+#undef MACRO_EXPANSION_HAS_NULL
+}
+
+void test_macro_expansion3() {
+#define MACRO_EXPANSION_HAS_NULL \
+  dummy(NULL); \
+  side_effect();
+
+#define OUTER_MACRO \
+  MACRO_EXPANSION_HAS_NULL; \
+  side_effect();
+
+  OUTER_MACRO;
+
+#undef OUTER_MACRO
+#undef MACRO_EXPANSION_HAS_NULL
+}
+
+void test_macro_expansion4() {
+#define MY_NULL NULL
+  int *p = MY_NULL;
+  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: use nullptr [modernize-use-nullptr]
+  // CHECK-FIXES: int *p = nullptr;
+#undef MY_NULL
+}
+
+#define IS_EQ(x, y) if (x != y) return;
+void test_macro_args() {
+  int i = 0;
+  int *Ptr;
+
+  IS_EQ(static_cast(0), Ptr);
+  // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: use nullptr
+  // CHECK-FIXES: IS_EQ(static_cast(nullptr), Ptr);
+
+  IS_EQ(0, Ptr);// literal
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: use nullptr
+  // CHECK-FIXES: IS_EQ(nullptr, Ptr);
+
+  IS_EQ(NULL, Ptr); // macro
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: use nullptr
+  // CHECK-FIXES: IS_EQ(nullptr, Ptr);
+
+  // These are ok since the null literal is not spelled within a macro.
+#define myassert(x) if (!(x)) return;
+  myassert(0 == Ptr);
+  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: use nullptr
+  // CHECK-FIXES: myassert(nullptr == Ptr);
+
+  myassert(NULL == Ptr);
+  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: use nullptr
+  // CHECK-FIXES: myassert(nullptr == Ptr);
+
+  // These are bad as the null literal is buried in a macro.
+#define BLAH(X) myassert(0 == (X));
+#define BLAH2(X) myassert(NULL == (X));
+  BLAH(Ptr);
+  BLAH2(Ptr);
+
+  // Same as above but testing extra macro expansion.
+#define EXPECT_NULL(X) IS_EQ(0, X);
+#define EXPECT_NULL2(X) IS_EQ(NULL, X);
+  EXPECT_NULL(Ptr);
+  EXPECT_NULL2(Ptr);
+
+  // Almost the same as above but now null literal is not in a macro so ok
+  // to transform.
+#define EQUALS_PTR(X) IS_EQ(X, Ptr);
+  EQUALS_PTR(0);
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: use nullptr
+  // CHECK-FIXES: EQUALS_PTR(nullptr);
+  EQUALS_PTR(NULL);
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: use nullptr
+  // CHECK-FIXES: EQUALS_PTR(nullptr);
+
+  // Same as above but testing extra macro expansion.
+#define EQUALS_PTR_I(X) EQUALS_PTR(X)
+  EQUALS_PTR_I(0);
+  // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: use nullptr
+  // CHECK-FIXES: EQUALS_PTR_I(nullptr);
+  EQUALS_PTR_I(NULL);
+  // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: use nullptr
+  // CHECK-FIXES: EQUALS_PTR_I(nullptr);
+
+  // Ok since null literal not within macro. However, now testing macro
+  // used as arg to another macro.
+#define decorate(EXPR) side_effect(); EXPR;
+  decorate(IS_EQ(NULL, Ptr));
+  // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: use nullptr
+  // CHECK-FIXES: decorate(IS_EQ(nullptr, Ptr));
+  decorate(IS_EQ(0, Ptr));
+  // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: use nullptr
+  // CHECK-FIXES: decorate(IS_EQ(nullptr, Ptr));
+
+  // This macro causes a NullToPointer cast to happen where 0 is assigned to z
+  // but the 0 literal cannot be replaced because it is also used as an
+  // integer in the comparison.
+#define INT_AND_PTR_USE(X) do { int *z = X; if (X 

Re: [PATCH] D12081: Add use-nullptr check to clang-tidy.

2015-08-17 Thread Alexander Kornienko via cfe-commits
alexfh added inline comments.


Comment at: clang-tidy/modernize/UseNullptrCheck.cpp:16
@@ +15,3 @@
+
+using namespace clang::ast_matchers;
+using namespace clang;

nit: The list should be sorted.


Comment at: clang-tidy/modernize/UseNullptrCheck.cpp:72
@@ +71,3 @@
+/// Returns true if and only if a replacement was made.
+void ReplaceWithNullptr(ClangTidyCheck &check, SourceManager &SM,
+SourceLocation StartLoc, SourceLocation EndLoc) {

Function names should start with a lower-case character. Also, s/check/Check/.


Comment at: clang-tidy/modernize/UseNullptrCheck.cpp:95
@@ +94,3 @@
+/// If \p Loc points to NULL, this function will return the name MY_NULL.
+llvm::StringRef GetOutermostMacroName(SourceLocation Loc,
+  const SourceManager &SM,

s/llvm:://

Function names should start with a lower-case character.


Comment at: clang-tidy/modernize/UseNullptrCheck.cpp:106
@@ +105,3 @@
+
+  return clang::Lexer::getImmediateMacroName(OutermostMacroLoc, SM, LO);
+}

s/clang:://


Comment at: clang-tidy/modernize/UseNullptrCheck.cpp:205
@@ +204,3 @@
+  return true;
+} else if (!FirstSubExpr) {
+  FirstSubExpr = C->getSubExpr()->IgnoreParens();

http://llvm.org/docs/CodingStandards.html#don-t-use-else-after-a-return


Comment at: clang-tidy/modernize/UseNullptrCheck.cpp:232
@@ +231,3 @@
+  SM.isMacroBodyExpansion(EndLoc)) {
+llvm::StringRef OutermostMacroName =
+GetOutermostMacroName(StartLoc, SM, Context.getLangOpts());

s/llvm:://


Comment at: clang-tidy/modernize/UseNullptrCheck.cpp:340
@@ +339,3 @@
+  FileID MacroFID = SM.getFileID(MacroLoc);
+  if (SM.isInFileID(ArgLoc, MacroFID))
+// Don't transform this case. If the characters that caused the

I'd use braces around the `if` body here.


Comment at: clang-tidy/modernize/UseNullptrCheck.cpp:367
@@ +366,3 @@
+
+while (1) {
+  std::pair LocInfo = SM.getDecomposedLoc(Loc);

`while (true)` or `for (;;)`


Comment at: clang-tidy/modernize/UseNullptrCheck.h:27
@@ +26,3 @@
+private:
+  llvm::SmallVector UserNullMacros;
+};

nit: I suspect that `llvm::` is not needed on both types here, as they should 
be imported to the `clang` namespace as well. Please try without it.


Comment at: test/clang-tidy/modernize-use-nullptr.cpp:2
@@ +1,3 @@
+// RUN: $(dirname %s)/check_clang_tidy.sh %s modernize-use-nullptr %t \
+// -config="{CheckOptions: [{key: modernize-use-nullptr.UserNullMacros, value: 
'MY_NULL'}]}" \
+// -- -std=c++11

This line must start with RUN: as well, and the next one. Also, please add two 
more spaces after RUN:, so that it's more obvious that the command line is 
wrapped.


http://reviews.llvm.org/D12081



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


Re: [PATCH] D10933: Add new IdentifierNaming check

2015-08-17 Thread Beren Minor via cfe-commits
berenm updated this revision to Diff 32304.
berenm added a comment.

Alright!

Here is the latest revision then, with FIXMEs comments mentioning this missing 
feature. I will work on implementing it and come back to you when i've got 
something working.

Thanks for your time and your advices!


http://reviews.llvm.org/D10933

Files:
  clang-tidy/readability/CMakeLists.txt
  clang-tidy/readability/IdentifierNamingCheck.cpp
  clang-tidy/readability/IdentifierNamingCheck.h
  clang-tidy/readability/ReadabilityTidyModule.cpp
  test/clang-tidy/readability-identifier-naming.cpp

Index: test/clang-tidy/readability-identifier-naming.cpp
===
--- /dev/null
+++ test/clang-tidy/readability-identifier-naming.cpp
@@ -0,0 +1,266 @@
+// RUN: $(dirname %s)/check_clang_tidy.sh %s readability-identifier-naming %t \
+// RUN:   -config='{CheckOptions: [ \
+// RUN: {key: readability-identifier-naming.AbstractClassCase, value: CamelCase}, \
+// RUN: {key: readability-identifier-naming.AbstractClassPrefix, value: 'A'}, \
+// RUN: {key: readability-identifier-naming.ClassCase, value: CamelCase}, \
+// RUN: {key: readability-identifier-naming.ClassPrefix, value: 'C'}, \
+// RUN: {key: readability-identifier-naming.ClassConstantCase, value: CamelCase}, \
+// RUN: {key: readability-identifier-naming.ClassConstantPrefix, value: 'k'}, \
+// RUN: {key: readability-identifier-naming.ClassMemberCase, value: CamelCase}, \
+// RUN: {key: readability-identifier-naming.ClassMethodCase, value: camelBack}, \
+// RUN: {key: readability-identifier-naming.ConstantCase, value: UPPER_CASE}, \
+// RUN: {key: readability-identifier-naming.ConstantSuffix, value: '_CST'}, \
+// RUN: {key: readability-identifier-naming.ConstexprFunctionCase, value: lower_case}, \
+// RUN: {key: readability-identifier-naming.ConstexprMethodCase, value: lower_case}, \
+// RUN: {key: readability-identifier-naming.ConstexprVariableCase, value: lower_case}, \
+// RUN: {key: readability-identifier-naming.EnumCase, value: CamelCase}, \
+// RUN: {key: readability-identifier-naming.EnumPrefix, value: 'E'}, \
+// RUN: {key: readability-identifier-naming.EnumConstantCase, value: UPPER_CASE}, \
+// RUN: {key: readability-identifier-naming.FunctionCase, value: camelBack}, \
+// RUN: {key: readability-identifier-naming.GlobalConstantCase, value: UPPER_CASE}, \
+// RUN: {key: readability-identifier-naming.GlobalFunctionCase, value: CamelCase}, \
+// RUN: {key: readability-identifier-naming.GlobalVariableCase, value: lower_case}, \
+// RUN: {key: readability-identifier-naming.GlobalVariablePrefix, value: 'g_'}, \
+// RUN: {key: readability-identifier-naming.InlineNamespaceCase, value: lower_case}, \
+// RUN: {key: readability-identifier-naming.LocalConstantCase, value: CamelCase}, \
+// RUN: {key: readability-identifier-naming.LocalConstantPrefix, value: 'k'}, \
+// RUN: {key: readability-identifier-naming.LocalVariableCase, value: lower_case}, \
+// RUN: {key: readability-identifier-naming.MemberCase, value: CamelCase}, \
+// RUN: {key: readability-identifier-naming.MemberPrefix, value: 'm_'}, \
+// RUN: {key: readability-identifier-naming.ConstantMemberCase, value: lower_case}, \
+// RUN: {key: readability-identifier-naming.PrivateMemberPrefix, value: '__'}, \
+// RUN: {key: readability-identifier-naming.ProtectedMemberPrefix, value: '_'}, \
+// RUN: {key: readability-identifier-naming.PublicMemberCase, value: lower_case}, \
+// RUN: {key: readability-identifier-naming.MethodCase, value: camelBack}, \
+// RUN: {key: readability-identifier-naming.PrivateMethodPrefix, value: '__'}, \
+// RUN: {key: readability-identifier-naming.ProtectedMethodPrefix, value: '_'}, \
+// RUN: {key: readability-identifier-naming.NamespaceCase, value: lower_case}, \
+// RUN: {key: readability-identifier-naming.ParameterCase, value: camelBack}, \
+// RUN: {key: readability-identifier-naming.ParameterPrefix, value: 'a_'}, \
+// RUN: {key: readability-identifier-naming.ConstantParameterCase, value: camelBack}, \
+// RUN: {key: readability-identifier-naming.ConstantParameterPrefix, value: 'i_'}, \
+// RUN: {key: readability-identifier-naming.ParameterPackCase, value: camelBack}, \
+// RUN: {key: readability-identifier-naming.PureFunctionCase, value: lower_case}, \
+// RUN: {key: readability-identifier-naming.PureMethodCase, value: camelBack}, \
+// RUN: {key: readability-identifier-naming.StaticConstantCase, value: UPPER_CASE}, \
+// RUN: {key: readability-identifier-naming.StaticVariableCase, value: camelBack}, \
+// RUN: {key: readability-identifier-naming.StaticVariablePrefix, value: 's_'}, \
+// RUN: {key: readability-identifier-naming.StructCase, value: lower_case}, \
+// RUN: {key: readability-identifier-naming.TemplateParameterCase, value: UPPER_CASE}, \
+//

Re: [PATCH] D11194: Instantiate function declarations in instantiated functions.

2015-08-17 Thread Serge Pavlov via cfe-commits
sepavloff updated this revision to Diff 32310.
sepavloff added a comment.

Updated method isLexicallyWithinFunctionOrMethod according to Richard's notes.


http://reviews.llvm.org/D11194

Files:
  include/clang/AST/DeclBase.h
  lib/AST/DeclBase.cpp
  lib/Sema/SemaTemplateInstantiate.cpp
  lib/Sema/SemaTemplateInstantiateDecl.cpp
  test/SemaTemplate/default-arguments.cpp
  test/SemaTemplate/instantiate-exception-spec-cxx11.cpp

Index: test/SemaTemplate/instantiate-exception-spec-cxx11.cpp
===
--- test/SemaTemplate/instantiate-exception-spec-cxx11.cpp
+++ test/SemaTemplate/instantiate-exception-spec-cxx11.cpp
@@ -178,3 +178,11 @@
   }
 
 }
+
+namespace NondefDecls {
+  template void f1() {
+int g1(int) noexcept(T::error); // expected-error{{type 'int' cannot be used prior to '::' because it has no members}}
+  }
+  template void f1(); // expected-note{{in instantiation of function template specialization 'NondefDecls::f1' requested here}}
+}
+
Index: test/SemaTemplate/default-arguments.cpp
===
--- test/SemaTemplate/default-arguments.cpp
+++ test/SemaTemplate/default-arguments.cpp
@@ -159,3 +159,10 @@
 
   int g() { X::f(0); } // expected-note {{in instantiation of template class 'DR1635::X' requested here}}
 }
+
+namespace NondefDecls {
+  template void f1() {
+int g1(int defarg = T::error);  // expected-error{{type 'int' cannot be used prior to '::' because it has no members}}
+  }
+  template void f1();  // expected-note{{in instantiation of function template specialization 'NondefDecls::f1' requested here}}
+}
Index: lib/Sema/SemaTemplateInstantiateDecl.cpp
===
--- lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -3246,16 +3246,11 @@
 // exception specification.
 // DR1484: Local classes and their members are instantiated along with the
 // containing function.
-bool RequireInstantiation = false;
-if (CXXRecordDecl *Cls = dyn_cast(Tmpl->getDeclContext())) {
-  if (Cls->isLocalClass())
-RequireInstantiation = true;
-}
 if (SemaRef.getLangOpts().CPlusPlus11 &&
 EPI.ExceptionSpec.Type != EST_None &&
 EPI.ExceptionSpec.Type != EST_DynamicNone &&
 EPI.ExceptionSpec.Type != EST_BasicNoexcept &&
-!RequireInstantiation) {
+!Tmpl->isLexicallyWithinFunctionOrMethod()) {
   FunctionDecl *ExceptionSpecTemplate = Tmpl;
   if (EPI.ExceptionSpec.Type == EST_Uninstantiated)
 ExceptionSpecTemplate = EPI.ExceptionSpec.SourceTemplate;
Index: lib/Sema/SemaTemplateInstantiate.cpp
===
--- lib/Sema/SemaTemplateInstantiate.cpp
+++ lib/Sema/SemaTemplateInstantiate.cpp
@@ -1682,11 +1682,10 @@
 UnparsedDefaultArgInstantiations[OldParm].push_back(NewParm);
   } else if (Expr *Arg = OldParm->getDefaultArg()) {
 FunctionDecl *OwningFunc = cast(OldParm->getDeclContext());
-CXXRecordDecl *ClassD = dyn_cast(OwningFunc->getDeclContext());
-if (ClassD && ClassD->isLocalClass() && !ClassD->isLambda()) {
-  // If this is a method of a local class, as per DR1484 its default
-  // arguments must be instantiated.
-  Sema::ContextRAII SavedContext(*this, ClassD);
+if (OwningFunc->isLexicallyWithinFunctionOrMethod()) {
+  // Instantiate default arguments for methods of local classes (DR1484)
+  // and non-defining declarations.
+  Sema::ContextRAII SavedContext(*this, OwningFunc);
   LocalInstantiationScope Local(*this);
   ExprResult NewArg = SubstExpr(Arg, TemplateArgs);
   if (NewArg.isUsable())
Index: lib/AST/DeclBase.cpp
===
--- lib/AST/DeclBase.cpp
+++ lib/AST/DeclBase.cpp
@@ -266,6 +266,15 @@
   }
 }
 
+bool Decl::isLexicallyWithinFunctionOrMethod() const {
+  const DeclContext *LDC = getLexicalDeclContext();
+  if (LDC->isFunctionOrMethod())
+return true;
+  if (const CXXRecordDecl *ClassD = dyn_cast(LDC))
+return ClassD->isLocalClass() && !ClassD->isLambda();;
+  return false;
+}
+
 bool Decl::isInAnonymousNamespace() const {
   const DeclContext *DC = getDeclContext();
   do {
Index: include/clang/AST/DeclBase.h
===
--- include/clang/AST/DeclBase.h
+++ include/clang/AST/DeclBase.h
@@ -728,6 +728,15 @@
 return getParentFunctionOrMethod() == nullptr;
   }
 
+  /// \brief Returns true if this declaration lexically is inside a function.
+  /// It recognizes non-defining declarations as well as members of local
+  /// classes:
+  /// \code
+  /// void foo() { void bar(); }
+  /// void foo2() { class ABC { void bar(); }; }
+  /// \endcode
+  bool isLexicallyWithinFunctionOrMethod() const;
+
   /// \brief If this decl is defined inside a function/meth

Re: [PATCH] D12081: Add use-nullptr check to clang-tidy.

2015-08-17 Thread Angel Garcia via cfe-commits
angelgarcia updated this revision to Diff 32311.
angelgarcia marked 9 inline comments as done.
angelgarcia added a comment.

Comments fixed.


http://reviews.llvm.org/D12081

Files:
  clang-tidy/modernize/CMakeLists.txt
  clang-tidy/modernize/ModernizeTidyModule.cpp
  clang-tidy/modernize/UseNullptrCheck.cpp
  clang-tidy/modernize/UseNullptrCheck.h
  test/clang-tidy/modernize-use-nullptr-basic.cpp
  test/clang-tidy/modernize-use-nullptr.cpp

Index: test/clang-tidy/modernize-use-nullptr.cpp
===
--- test/clang-tidy/modernize-use-nullptr.cpp
+++ test/clang-tidy/modernize-use-nullptr.cpp
@@ -0,0 +1,179 @@
+// RUN:   $(dirname %s)/check_clang_tidy.sh %s modernize-use-nullptr %t \
+// RUN:   -config="{CheckOptions: [{key: modernize-use-nullptr.UserNullMacros, value: 'MY_NULL'}]}" \
+// RUN:   -- -std=c++11
+
+// REQUIRES: shell
+
+#define NULL 0
+
+namespace std {
+
+typedef decltype(nullptr) nullptr_t;
+
+} // namespace std
+
+// Just to make sure make_null() could have side effects.
+void external();
+
+std::nullptr_t make_null() {
+  external();
+  return nullptr;
+}
+
+void func() {
+  void *CallTest = make_null();
+
+  int var = 1;
+  void *CommaTest = (var+=2, make_null());
+
+  int *CastTest = static_cast(make_null());
+}
+
+void dummy(int*) {}
+void side_effect() {}
+
+#define MACRO_EXPANSION_HAS_NULL \
+  void foo() { \
+dummy(0); \
+dummy(NULL); \
+side_effect(); \
+  }
+
+MACRO_EXPANSION_HAS_NULL;
+#undef MACRO_EXPANSION_HAS_NULL
+
+
+void test_macro_expansion1() {
+#define MACRO_EXPANSION_HAS_NULL \
+  dummy(NULL); \
+  side_effect();
+
+  MACRO_EXPANSION_HAS_NULL;
+
+#undef MACRO_EXPANSION_HAS_NULL
+}
+
+// Test macro expansion with cast sequence, PR15572.
+void test_macro_expansion2() {
+#define MACRO_EXPANSION_HAS_NULL \
+  dummy((int*)0); \
+  side_effect();
+
+  MACRO_EXPANSION_HAS_NULL;
+
+#undef MACRO_EXPANSION_HAS_NULL
+}
+
+void test_macro_expansion3() {
+#define MACRO_EXPANSION_HAS_NULL \
+  dummy(NULL); \
+  side_effect();
+
+#define OUTER_MACRO \
+  MACRO_EXPANSION_HAS_NULL; \
+  side_effect();
+
+  OUTER_MACRO;
+
+#undef OUTER_MACRO
+#undef MACRO_EXPANSION_HAS_NULL
+}
+
+void test_macro_expansion4() {
+#define MY_NULL NULL
+  int *p = MY_NULL;
+  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: use nullptr [modernize-use-nullptr]
+  // CHECK-FIXES: int *p = nullptr;
+#undef MY_NULL
+}
+
+#define IS_EQ(x, y) if (x != y) return;
+void test_macro_args() {
+  int i = 0;
+  int *Ptr;
+
+  IS_EQ(static_cast(0), Ptr);
+  // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: use nullptr
+  // CHECK-FIXES: IS_EQ(static_cast(nullptr), Ptr);
+
+  IS_EQ(0, Ptr);// literal
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: use nullptr
+  // CHECK-FIXES: IS_EQ(nullptr, Ptr);
+
+  IS_EQ(NULL, Ptr); // macro
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: use nullptr
+  // CHECK-FIXES: IS_EQ(nullptr, Ptr);
+
+  // These are ok since the null literal is not spelled within a macro.
+#define myassert(x) if (!(x)) return;
+  myassert(0 == Ptr);
+  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: use nullptr
+  // CHECK-FIXES: myassert(nullptr == Ptr);
+
+  myassert(NULL == Ptr);
+  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: use nullptr
+  // CHECK-FIXES: myassert(nullptr == Ptr);
+
+  // These are bad as the null literal is buried in a macro.
+#define BLAH(X) myassert(0 == (X));
+#define BLAH2(X) myassert(NULL == (X));
+  BLAH(Ptr);
+  BLAH2(Ptr);
+
+  // Same as above but testing extra macro expansion.
+#define EXPECT_NULL(X) IS_EQ(0, X);
+#define EXPECT_NULL2(X) IS_EQ(NULL, X);
+  EXPECT_NULL(Ptr);
+  EXPECT_NULL2(Ptr);
+
+  // Almost the same as above but now null literal is not in a macro so ok
+  // to transform.
+#define EQUALS_PTR(X) IS_EQ(X, Ptr);
+  EQUALS_PTR(0);
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: use nullptr
+  // CHECK-FIXES: EQUALS_PTR(nullptr);
+  EQUALS_PTR(NULL);
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: use nullptr
+  // CHECK-FIXES: EQUALS_PTR(nullptr);
+
+  // Same as above but testing extra macro expansion.
+#define EQUALS_PTR_I(X) EQUALS_PTR(X)
+  EQUALS_PTR_I(0);
+  // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: use nullptr
+  // CHECK-FIXES: EQUALS_PTR_I(nullptr);
+  EQUALS_PTR_I(NULL);
+  // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: use nullptr
+  // CHECK-FIXES: EQUALS_PTR_I(nullptr);
+
+  // Ok since null literal not within macro. However, now testing macro
+  // used as arg to another macro.
+#define decorate(EXPR) side_effect(); EXPR;
+  decorate(IS_EQ(NULL, Ptr));
+  // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: use nullptr
+  // CHECK-FIXES: decorate(IS_EQ(nullptr, Ptr));
+  decorate(IS_EQ(0, Ptr));
+  // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: use nullptr
+  // CHECK-FIXES: decorate(IS_EQ(nullptr, Ptr));
+
+  // This macro causes a NullToPointer cast to happen where 0 is assigned to z
+  // but the 0 literal cannot be replaced because it is also used as an
+  // integer in the comparison.
+#define IN

Re: [PATCH] D10431: PR21174 - clang only searches current working directory for precompiled include file

2015-08-17 Thread Nico Weber via cfe-commits
thakis added a subscriber: thakis.


Comment at: lib/Driver/Tools.cpp:398
@@ +397,3 @@
+  FoundPTH = !UsePCH;
+}
+  }

kimgr wrote:
> kimgr wrote:
> > kimgr wrote:
> > > kimgr wrote:
> > > > Add a `break;` here so we don't continue searching after a valid path 
> > > > has been found
> > > The GCC docs here [1] say:
> > > 
> > > If not found there, it is searched for in the remainder of the 
> > > #include "..." search chain as normal.
> > > 
> > > I can't tell if the quotes are significant and if they mean only -I is 
> > > searched. I don't have a GCC environment currently to test with.
> > > 
> > > [1] 
> > > https://gcc.gnu.org/onlinedocs/gcc-4.9.3/gcc/Preprocessor-Options.html#index-nostdinc_002b_002b-1026
> > I found a FreeBSD machine and set up GCC. I had to adjust the repro case to 
> > use `truss` instead of `strace`, so I hope I didn't mess anything up.
> > 
> > I removed the rule generating the .gch file, so GCC would have to keep 
> > searching and it appears to be following the entire include search path, 
> > including system paths. Trace below:
> > 
> > ...
> > 30860: stat("./precompiled.header.gch",0x7fffe540) ERR#2 'No such file 
> > or directory'
> > 30860: open("./precompiled.header",O_NOCTTY,0666) ERR#2 'No such file or 
> > directory'
> > 30860: stat("./build/include/precompiled.header.gch",0x7fffe540) ERR#2 
> > 'No such file or directory'
> > 30860: open("./build/include/precompiled.header",O_NOCTTY,0666) ERR#2 'No 
> > such file or directory'
> > 30860: stat("./include/precompiled.header.gch",0x7fffe540) ERR#2 'No 
> > such file or directory'
> > 30860: open("./include/precompiled.header",O_NOCTTY,0666) ERR#2 'No such 
> > file or directory'
> > 30860: lstat("/usr",{ mode=drwxr-xr-x ,inode=9,size=16,blksize=4096 }) = 0 
> > (0x0)
> > 30860: lstat("/usr/local",{ mode=drwxr-xr-x ,inode=115,size=16,blksize=4096 
> > }) = 0 (0x0)
> > 30860: lstat("/usr/local/lib",{ mode=drwxr-xr-x 
> > ,inode=16476,size=1318,blksize=84480 }) = 0 (0x0)
> > 30860: lstat("/usr/local/lib/gcc48",{ mode=drwxr-xr-x 
> > ,inode=24335,size=66,blksize=131072 }) = 0 (0x0)
> > 30860: lstat("/usr/local/lib/gcc48/include",{ mode=drwxr-xr-x 
> > ,inode=24336,size=3,blksize=131072 }) = 0 (0x0)
> > 30860: lstat("/usr/local/lib/gcc48/include/c++",{ mode=drwxr-xr-x 
> > ,inode=24337,size=98,blksize=131072 }) = 0 (0x0)
> > 30860: 
> > lstat("/usr/local/lib/gcc48/include/c++/precompiled.header",0x7fffd3d8) 
> > ERR#2 'No such file or directory'
> > 30860: 
> > stat("/usr/local/lib/gcc48/include/c++/precompiled.header.gch",0x7fffe540)
> >  ERR#2 'No such file or directory'
> > 30860: 
> > open("/usr/local/lib/gcc48/include/c++/precompiled.header",O_NOCTTY,0666) 
> > ERR#2 'No such file or directory'
> > 30860: lstat("/usr",{ mode=drwxr-xr-x ,inode=9,size=16,blksize=4096 }) = 0 
> > (0x0)
> > 30860: lstat("/usr/local",{ mode=drwxr-xr-x ,inode=115,size=16,blksize=4096 
> > }) = 0 (0x0)
> > 30860: lstat("/usr/local/lib",{ mode=drwxr-xr-x 
> > ,inode=16476,size=1318,blksize=84480 }) = 0 (0x0)
> > 30860: lstat("/usr/local/lib/gcc48",{ mode=drwxr-xr-x 
> > ,inode=24335,size=66,blksize=131072 }) = 0 (0x0)
> > 30860: lstat("/usr/local/lib/gcc48/include",{ mode=drwxr-xr-x 
> > ,inode=24336,size=3,blksize=131072 }) = 0 (0x0)
> > 30860: lstat("/usr/local/lib/gcc48/include/c++",{ mode=drwxr-xr-x 
> > ,inode=24337,size=98,blksize=131072 }) = 0 (0x0)
> > 30860: 
> > lstat("/usr/local/lib/gcc48/include/c++/x86_64-portbld-freebsd10.1",{ 
> > mode=drwxr-xr-x ,inode=21305,size=4,blksize=131072 }) = 0 (0x0)
> > 30860: 
> > lstat("/usr/local/lib/gcc48/include/c++/x86_64-portbld-freebsd10.1/precompiled.header",0x7fffd3d8)
> >  ERR#2 'No such file or directory'
> > 30860: 
> > stat("/usr/local/lib/gcc48/include/c++//x86_64-portbld-freebsd10.1/precompiled.header.gch",0x7fffe540)
> >  ERR#2 'No such file or directory'
> > 30860: 
> > open("/usr/local/lib/gcc48/include/c++//x86_64-portbld-freebsd10.1/precompiled.header",O_NOCTTY,0666)
> >  ERR#2 'No such file or directory'
> > 30860: lstat("/usr",{ mode=drwxr-xr-x ,inode=9,size=16,blksize=4096 }) = 0 
> > (0x0)
> > 30860: lstat("/usr/local",{ mode=drwxr-xr-x ,inode=115,size=16,blksize=4096 
> > }) = 0 (0x0)
> > 30860: lstat("/usr/local/lib",{ mode=drwxr-xr-x 
> > ,inode=16476,size=1318,blksize=84480 }) = 0 (0x0)
> > 30860: lstat("/usr/local/lib/gcc48",{ mode=drwxr-xr-x 
> > ,inode=24335,size=66,blksize=131072 }) = 0 (0x0)
> > 30860: lstat("/usr/local/lib/gcc48/include",{ mode=drwxr-xr-x 
> > ,inode=24336,size=3,blksize=131072 }) = 0 (0x0)
> > 30860: lstat("/usr/local/lib/gcc48/include/c++",{ mode=drwxr-xr-x 
> > ,inode=24337,size=98,blksize=131072 }) = 0 (0x0)
> > 30860: lstat("/usr/local/lib/gcc48/include/c++/backward",{ mode=drwxr-xr-x 
> > ,inode=21290,size=10,blksize=131072 }) = 0 (0x0)
> > 30860: 
> > lstat("/usr/local/lib/gcc48/include/c++/backward/precompiled.header",0x7fffd3d8)
> >  ERR#2 'No 

r245228 - [modules] PR20507: Avoid silent textual inclusion.

2015-08-17 Thread Sean Silva via cfe-commits
Author: silvas
Date: Mon Aug 17 11:39:30 2015
New Revision: 245228

URL: http://llvm.org/viewvc/llvm-project?rev=245228&view=rev
Log:
[modules] PR20507: Avoid silent textual inclusion.

Summary:
If a module was unavailable (either a missing requirement on the module
being imported, or a missing file anywhere in the top-level module (and
not dominated by an unsatisfied `requires`)), we would silently treat
inclusions as textual. This would cause all manner of crazy and
confusing errors (and would also silently "work" sometimes, making the
problem difficult to track down).

I'm really not a fan of the `M->isAvailable(getLangOpts(), getTargetInfo(),
Requirement, MissingHeader)` function; it seems to do too many things at
once, but for now I've done things in a sort of awkward way.

The changes to test/Modules/Inputs/declare-use/module.map
were necessitated because the thing that was meant to be tested there
(introduced in r197805) was predicated on silently falling back to textual
inclusion, which we no longer do.

The changes to test/Modules/Inputs/macro-reexport/module.modulemap
are just an overlooked missing header that seems to have been missing since
this code was committed (r213922), which is now caught.

Reviewers: rsmith, benlangmuir, djasper

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D10423

Added:
cfe/trunk/test/Modules/Inputs/auto-import-unavailable/
cfe/trunk/test/Modules/Inputs/auto-import-unavailable/missing_header/

cfe/trunk/test/Modules/Inputs/auto-import-unavailable/missing_header/not_missing.h
cfe/trunk/test/Modules/Inputs/auto-import-unavailable/missing_requirement.h
cfe/trunk/test/Modules/Inputs/auto-import-unavailable/module.modulemap

cfe/trunk/test/Modules/Inputs/auto-import-unavailable/nonrequired_missing_header/

cfe/trunk/test/Modules/Inputs/auto-import-unavailable/nonrequired_missing_header/not_missing.h

cfe/trunk/test/Modules/Inputs/auto-import-unavailable/nonrequired_missing_header/requires_feature_you_dont_have.h
cfe/trunk/test/Modules/Inputs/available-is-better/
cfe/trunk/test/Modules/Inputs/available-is-better/available-is-better.h
cfe/trunk/test/Modules/Inputs/available-is-better/module.modulemap
cfe/trunk/test/Modules/auto-import-unavailable.cpp
cfe/trunk/test/Modules/available-is-better.cpp
Modified:
cfe/trunk/include/clang/Basic/DiagnosticCommonKinds.td
cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td
cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td
cfe/trunk/lib/Lex/ModuleMap.cpp
cfe/trunk/lib/Lex/PPDirectives.cpp
cfe/trunk/test/Modules/Inputs/declare-use/module.map
cfe/trunk/test/Modules/Inputs/macro-reexport/module.modulemap

Modified: cfe/trunk/include/clang/Basic/DiagnosticCommonKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticCommonKinds.td?rev=245228&r1=245227&r2=245228&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticCommonKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticCommonKinds.td Mon Aug 17 11:39:30 
2015
@@ -84,6 +84,10 @@ def err_module_not_built : Error<"could
 def err_module_build_disabled: Error<
   "module '%0' is needed but has not been provided, and implicit use of module 
"
   "files is disabled">, DefaultFatal;
+def err_module_unavailable : Error<
+  "module '%0' %select{is incompatible with|requires}1 feature '%2'">;
+def err_module_header_missing : Error<
+  "%select{|umbrella }0header '%1' not found">;
 def err_module_lock_failure : Error<
   "could not acquire lock file for module '%0'">, DefaultFatal;
 def err_module_lock_timeout : Error<

Modified: cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td?rev=245228&r1=245227&r2=245228&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td Mon Aug 17 
11:39:30 2015
@@ -183,10 +183,6 @@ def err_no_submodule_suggest : Error<
   "no submodule named %0 in module '%1'; did you mean '%2'?">;
 def warn_missing_submodule : Warning<"missing submodule '%0'">,
   InGroup;
-def err_module_unavailable : Error<
-  "module '%0' %select{is incompatible with|requires}1 feature '%2'">;
-def err_module_header_missing : Error<
-  "%select{|umbrella }0header '%1' not found">;
 def err_module_cannot_create_includes : Error<
   "cannot create includes file for module %0: %1">;
 def warn_module_config_macro_undef : Warning<

Modified: cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td?rev=245228&r1=245227&r2=245228&view=diff
==
--

Re: [PATCH] D10423: [modules] PR20507: Avoid silent textual inclusion.

2015-08-17 Thread Sean Silva via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL245228: [modules] PR20507: Avoid silent textual inclusion. 
(authored by silvas).

Changed prior to commit:
  http://reviews.llvm.org/D10423?vs=30196&id=32317#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D10423

Files:
  cfe/trunk/include/clang/Basic/DiagnosticCommonKinds.td
  cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td
  cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td
  cfe/trunk/lib/Lex/ModuleMap.cpp
  cfe/trunk/lib/Lex/PPDirectives.cpp
  
cfe/trunk/test/Modules/Inputs/auto-import-unavailable/missing_header/not_missing.h
  cfe/trunk/test/Modules/Inputs/auto-import-unavailable/missing_requirement.h
  cfe/trunk/test/Modules/Inputs/auto-import-unavailable/module.modulemap
  
cfe/trunk/test/Modules/Inputs/auto-import-unavailable/nonrequired_missing_header/not_missing.h
  
cfe/trunk/test/Modules/Inputs/auto-import-unavailable/nonrequired_missing_header/requires_feature_you_dont_have.h
  cfe/trunk/test/Modules/Inputs/available-is-better/available-is-better.h
  cfe/trunk/test/Modules/Inputs/available-is-better/module.modulemap
  cfe/trunk/test/Modules/Inputs/declare-use/module.map
  cfe/trunk/test/Modules/Inputs/macro-reexport/module.modulemap
  cfe/trunk/test/Modules/auto-import-unavailable.cpp
  cfe/trunk/test/Modules/available-is-better.cpp

Index: cfe/trunk/include/clang/Basic/DiagnosticCommonKinds.td
===
--- cfe/trunk/include/clang/Basic/DiagnosticCommonKinds.td
+++ cfe/trunk/include/clang/Basic/DiagnosticCommonKinds.td
@@ -84,6 +84,10 @@
 def err_module_build_disabled: Error<
   "module '%0' is needed but has not been provided, and implicit use of module "
   "files is disabled">, DefaultFatal;
+def err_module_unavailable : Error<
+  "module '%0' %select{is incompatible with|requires}1 feature '%2'">;
+def err_module_header_missing : Error<
+  "%select{|umbrella }0header '%1' not found">;
 def err_module_lock_failure : Error<
   "could not acquire lock file for module '%0'">, DefaultFatal;
 def err_module_lock_timeout : Error<
Index: cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td
===
--- cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td
+++ cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td
@@ -623,6 +623,8 @@
 def warn_auto_module_import : Warning<
   "treating #%select{include|import|include_next|__include_macros}0 as an "
   "import of module '%1'">, InGroup, DefaultIgnore;
+def note_implicit_top_level_module_import_here : Note<
+  "submodule of top-level module '%0' implicitly imported here">;
 def warn_uncovered_module_header : Warning<
   "umbrella header for module '%0' does not include header '%1'">, 
   InGroup;
Index: cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td
===
--- cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td
+++ cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td
@@ -183,10 +183,6 @@
   "no submodule named %0 in module '%1'; did you mean '%2'?">;
 def warn_missing_submodule : Warning<"missing submodule '%0'">,
   InGroup;
-def err_module_unavailable : Error<
-  "module '%0' %select{is incompatible with|requires}1 feature '%2'">;
-def err_module_header_missing : Error<
-  "%select{|umbrella }0header '%1' not found">;
 def err_module_cannot_create_includes : Error<
   "cannot create includes file for module %0: %1">;
 def warn_module_config_macro_undef : Warning<
Index: cfe/trunk/test/Modules/available-is-better.cpp
===
--- cfe/trunk/test/Modules/available-is-better.cpp
+++ cfe/trunk/test/Modules/available-is-better.cpp
@@ -0,0 +1,5 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -x c++ -Rmodule-build -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I %S/Inputs/available-is-better %s 2>&1 | FileCheck %s
+
+#include "available-is-better.h"
+// CHECK: remark: building module
Index: cfe/trunk/test/Modules/Inputs/auto-import-unavailable/nonrequired_missing_header/not_missing.h
===
--- cfe/trunk/test/Modules/Inputs/auto-import-unavailable/nonrequired_missing_header/not_missing.h
+++ cfe/trunk/test/Modules/Inputs/auto-import-unavailable/nonrequired_missing_header/not_missing.h
@@ -0,0 +1 @@
+// nonrequired_missing_header/not_missing.h
Index: cfe/trunk/test/Modules/Inputs/auto-import-unavailable/nonrequired_missing_header/requires_feature_you_dont_have.h
===
--- cfe/trunk/test/Modules/Inputs/auto-import-unavailable/nonrequired_missing_header/requires_feature_you_dont_have.h
+++ cfe/trunk/test/Modules/Inputs/auto-import-unavailable/nonrequired_missing_header/requires_feature_you_dont_have.h
@@ -0,0 +1 @@
+// nonrequired_missing_header/requires_feature_you_dont_have.h
I

Second Lit tests C++11 compatibility patch: using preprocessor to filter expected-error

2015-08-17 Thread Li, Charles via cfe-commits
Hi Clang developers,

We here at Sony are continuing to update the Lit tests for C++ dialects 
compatibility.
Attached is the second patch. (As a reference, here is the link to the 
discussion on the previous Lit patch. 
http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20150727/134667.html)
In this second patch, there is 1 complicated change and 3 simple changes.

Here is the complicated change first.

test/Sema/switch-1.c
  This test verifies the diagnostics for integer overflows.
  Due to C++11's more strict requirements on constant-expressions in 5.19p2 
[expr.const],
  The diagnostics have changed from "overflow in expression" to "not a constant 
expression".

  Usually we would create a C++11 version of the switch-1.c file.
  But here we propose a novel approach to "#ifdef" the expected diagnostics. 
(We hope to use this approach for all similar cases in the future.)
  Normally '// expected-error' does not honor any '#ifdef'.
  But if we first preprocess the source into a temporary file, only the valid 
'#ifdef' sections remain.
  We then run the preprocessed file at the desired dialect.
  The main downside to this approach is If the test fails, the errors are 
reported on the temporary file, not on the original file, and the line numbers 
of these two files  do not match


Here are the simple changes.

test/Analysis/temp-obj-dtors-cfg-output.cpp
  This test verifies CFG dump for temporary destructors
  C++11 no longer has the following implicit cast.
(ImplicitCastExpr, NoOp, const struct D)
  We modified the test using the #ifdef approach to have the preprocessor 
generate the desired CHECK lines.

test/CodeCompletion/ordinary-name.cpp
  This test verifies for code completion patterns.
  Since C++11 has more keywords than C++98,
  We made this test to be C++98 specific, and create a separate C++11 version.

test/CodeCompletion/ordinary-name-cxx11.cpp
  This is the C++11 specific version of the code completion.
  This test added patterns for the following keywords:
char16, char32, noexcept, nullptr, sizeof...,
auto, decltype, char16_t, char32_t

test/Sema/thread-specifier.c
  Tests for __thread specifier at various C++ dialects
  We made the default RUN line explicit to be at -std=c++98


If there is anything that seems confusing to you, please let me know.
I would be more than happy to expand on the reasons for the these changes.


Thanks,
Charles


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


Re: [PATCH] D11361: [OpenMP] Target directive host codegen

2015-08-17 Thread Samuel Antao via cfe-commits
sfantao updated this revision to Diff 32322.
sfantao added a comment.

Adress reviewers concerns.

Also fix issue with target regions with no arguments and in the VLA size 
computation I found in the meantime.


http://reviews.llvm.org/D11361

Files:
  include/clang/AST/Decl.h
  include/clang/AST/Stmt.h
  include/clang/Basic/CapturedStmt.h
  include/clang/Sema/ScopeInfo.h
  lib/CodeGen/CGExpr.cpp
  lib/CodeGen/CGOpenMPRuntime.cpp
  lib/CodeGen/CGOpenMPRuntime.h
  lib/CodeGen/CGStmt.cpp
  lib/CodeGen/CGStmtOpenMP.cpp
  lib/CodeGen/CodeGenFunction.cpp
  lib/CodeGen/CodeGenFunction.h
  lib/Sema/SemaOpenMP.cpp
  test/OpenMP/target_codegen.cpp

Index: test/OpenMP/target_codegen.cpp
===
--- /dev/null
+++ test/OpenMP/target_codegen.cpp
@@ -0,0 +1,583 @@
+// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple powerpc64le-unknown-unknown -emit-llvm %s -o - | FileCheck %s
+// RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple powerpc64le-unknown-unknown -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp -x c++ -triple powerpc64le-unknown-unknown -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s
+// expected-no-diagnostics
+// REQUIRES: powerpc-registered-target
+#ifndef HEADER
+#define HEADER
+
+// CHECK-DAG: [[TT:%.+]] = type { i64, i8 }
+// CHECK-DAG: [[S1:%.+]] = type { double }
+
+// We have 8 target regions, but only 7 that actually will generate offloading
+// code, and only 6 will have mapped arguments.
+
+// CHECK-DAG: [[MAPT2:@.+]] = private constant [1 x i32] [i32 3]
+// CHECK-DAG: [[MAPT3:@.+]] = private constant [2 x i32] [i32 3, i32 3]
+// CHECK-DAG: [[MAPT4:@.+]] = private constant [9 x i32] [i32 3, i32 3, i32 1, i32 3, i32 3, i32 1, i32 1, i32 3, i32 3]
+// CHECK-DAG: [[MAPT5:@.+]] = private constant [3 x i32] [i32 3, i32 3, i32 3]
+// CHECK-DAG: [[MAPT6:@.+]] = private constant [4 x i32] [i32 3, i32 3, i32 3, i32 3]
+// CHECK-DAG: [[MAPT7:@.+]] = private constant [5 x i32] [i32 3, i32 3, i32 1, i32 1, i32 3]
+// CHECK-DAG: @{{.*}} = private constant i8 0
+// CHECK-DAG: @{{.*}} = private constant i8 0
+// CHECK-DAG: @{{.*}} = private constant i8 0
+// CHECK-DAG: @{{.*}} = private constant i8 0
+// CHECK-DAG: @{{.*}} = private constant i8 0
+// CHECK-DAG: @{{.*}} = private constant i8 0
+// CHECK-DAG: @{{.*}} = private constant i8 0
+
+template
+struct TT{
+  tx X;
+  ty Y;
+};
+
+// CHECK: define {{.*}}[[FOO:@.+]](
+int foo(int n) {
+  int a = 0;
+  short aa = 0;
+  float b[10];
+  float bn[n];
+  double c[5][10];
+  double cn[5][n];
+  TT d;
+
+  // CHECK:   br label %[[TRY:[^,]+]]
+  // CHECK:   [[TRY]]
+  // CHECK:   [[RET:%.+]] = call i32 @__tgt_target(i32 -1, i8* @{{[^,]+}}, i32 0, i8** null, i8** null, i64* null, i32* null)
+  // CHECK-NEXT:  [[ERROR:%.+]] = icmp ne i32 [[RET]], 0
+  // CHECK-NEXT:  br i1 [[ERROR]], label %[[FAIL:[^,]+]], label %[[END:[^,]+]]
+  // CHECK:   [[FAIL]]
+  // CHECK:   call void [[HVT0:@.+]]()
+  // CHECK-NEXT:  br label %[[END]]
+  // CHECK:   [[END]]
+  #pragma omp target
+  {
+  }
+
+  // CHECK:   call void [[HVT1:@.+]](i32* {{[^,]+}})
+  #pragma omp target if(0)
+  {
+a += 1;
+  }
+
+  // CHECK:   br label %[[TRY:[^,]+]]
+  // CHECK:   [[TRY]]
+  // CHECK-DAG:   [[RET:%.+]] = call i32 @__tgt_target(i32 -1, i8* @{{[^,]+}}, i32 1, i8** [[BP:%[^,]+]], i8** [[P:%[^,]+]], i64* [[S:%[^,]+]], i32* getelementptr inbounds ([1 x i32], [1 x i32]* [[MAPT2]], i32 0, i32 0))
+
+  // CHECK-DAG:   store i64 4, i64* [[SADDR0:%.+]]
+  // CHECK-DAG:   [[SADDR0]] = getelementptr inbounds i64, i64* [[S]], i32 [[IDX0:[0-9]+]]
+  // CHECK-DAG:   [[BPADDR0:%.+]] = getelementptr inbounds i8*, i8** [[BP]], i32 [[IDX0]]
+  // CHECK-DAG:   [[PADDR0:%.+]] = getelementptr inbounds i8*, i8** [[P]], i32 [[IDX0]]
+  // CHECK-DAG:   store i8* [[BP0:%[^,]+]], i8** [[BPADDR0]]
+  // CHECK-DAG:   store i8* [[P0:%[^,]+]], i8** [[PADDR0]]
+  // CHECK-DAG:   [[BP0]] = bitcast i32* %{{.+}} to i8*
+  // CHECK-DAG:   [[P0]] = bitcast i32* %{{.+}} to i8*
+
+  // CHECK:   [[ERROR:%.+]] = icmp ne i32 [[RET]], 0
+  // CHECK-NEXT:  br i1 [[ERROR]], label %[[FAIL:[^,]+]], label %[[END:[^,]+]]
+  // CHECK:   [[FAIL]]
+  // CHECK:   call void [[HVT2:@.+]](i32* {{[^,]+}})
+  // CHECK-NEXT:  br label %[[END]]
+  // CHECK:   [[END]]
+  #pragma omp target if(1)
+  {
+a += 1;
+  }
+
+  // CHECK:   [[IF:%.+]] = icmp sgt i32 {{[^,]+}}, 10
+  // CHECK:   br i1 [[IF]], label %[[TRY:[^,]+]], label %[[FAIL:[^,]+]]
+  // CHECK:   [[TRY]]
+  // CHECK-DAG:   [[RET:%.+]] = call i32 @__tgt_target(i32 -1, i8* @{{[^,]+}}, i32 2, i8** [[BP:%[^,]+]], i8** [[P:%[^,]+]], i64* [[S:%[^,]+]], i32* getelementptr inbounds ([2 x i32], [2 x i32]* [[MAPT3]], i32 0, i32 0))
+
+  // CHECK-DAG:   store i64 4, i64* [[SADDR0:%.+]]
+  // CHECK-DAG:   [[SADDR0]] = getelementptr inbounds i64, i64* [[S]], i32 [[IDX0:[0-9]+]]
+  // CHECK-DAG:   [[BPADDR0:%.+]] = getelementptr inbounds i8*, i8** [[BP]], i32 

Re: [PATCH] D11361: [OpenMP] Target directive host codegen

2015-08-17 Thread Samuel Antao via cfe-commits
sfantao added a comment.

Alexey,

Thanks for the review! Find my comments inlined.

Thanks again!
Samuel



Comment at: lib/CodeGen/CGExpr.cpp:1969
@@ -1945,3 +1968,3 @@
 else
-  return EmitCapturedFieldLValue(*this, CapturedStmtInfo->lookup(VD),
- CapturedStmtInfo->getContextValue());
+  return EmitCapturedValue(*this, CapturedStmtInfo->lookup(VD),
+   CapturedStmtInfo->getContextValue());

ABataev wrote:
> Samuel, why you don't want to capture all used variables in CapturedDecl 
> instead of creating ImplicitParamDecl for each captured variable? Also, you 
> will solve possible trouble with VLAs automatically using CapturedDecl.
Alexey, I'm not sure I understand what you mean here. Unlike the other captured 
regions, the target region outlined function does not take a context that 
captures all the variables in fields of a record as argument. Instead, it takes 
all the captured references as arguments. This will enable the device runtime 
library to decide what is best to pass the arguments to the device (see my 
response to John's question in my previous diff).

It happens that all the machinery in the common infrastructure that creates the 
outlined functions (`CodeGenFunction::StartFunction` and 
`GenerateCapturedStmtFunction`)  is prepared to get the context record from the 
`CapuredDecl`. Therefore, in order to not disrupt the common infrastructure, in 
`Sema::ActOnOpenMPRegionEnd` I am creating a new `CapturedDecl` that contains 
implicit parameters. I gather the information to build the new `CapturedDecl` 
from the `CapturedDecl` that is created with the context argument and the 
`RecordDecl` fields so that I don't need to touch the capturing code in Sema.

Having  `CapturedDecl` with implicit parameters will drive `StartFunction` to 
create the outlined region  with the right signature without having to change 
anything in there. I only had to guard the initialization of VLAs and 'this' in 
`GenerateCapturedStmtFunction` to not do anything that expects the context 
argument. However, during the emission of the VLAs that happens in 
`StartFunction`, the emission of these implicit parameters is attempted based 
on references that are marked as `refersToEnclosingVariableOrCapture`- this is 
the reason for the change in `EmitDeclRefLValue`.

Given that the references in the outlined function statements are still 
expecting the VLAs expression used in the caller of the outlined function, 
`PrepareOMPTargetDirectiveBodyEmission` will make sure that the mapped values 
to those expressions will be the same as the ones that use the new expression 
based on implicit parameters.

Let me know if you need me to clarify anything.
Thanks!

 


Comment at: lib/CodeGen/CGOpenMPRuntime.cpp:2953
@@ +2952,3 @@
+  BasePointer = Pointer = LV.getAddress();
+  uint64_t SizeVal = CGM.getContext().getTypeSize(ri->getType()) / 8;
+  Size = CGF.Builder.getInt64(SizeVal);

ABataev wrote:
> Use CGM.getContext().getTypeSizeInChars() instead of 
> CGM.getContext().getTypeSize() / 8.
Done!


Comment at: lib/CodeGen/CGOpenMPRuntime.cpp:2954
@@ +2953,3 @@
+  uint64_t SizeVal = CGM.getContext().getTypeSize(ri->getType()) / 8;
+  Size = CGF.Builder.getInt64(SizeVal);
+

ABataev wrote:
> Maybe llvm::ConstantInt::get(CGF.SizeTy, SizeVal)?
I agree, it makes more sense to use size_t. Thanks for the suggestion!


Comment at: lib/CodeGen/CGOpenMPRuntime.cpp:2963
@@ +2962,3 @@
+  uint64_t SizeVal =
+  CGM.getContext().getTypeSize(PtrTy->getPointeeType()) / 8;
+  Size = CGF.Builder.getInt64(SizeVal);

ABataev wrote:
> Use CGM.getContext().getTypeSizeInChars() instead of 
> CGM.getContext().getTypeSize() / 8.
done!


Comment at: lib/CodeGen/CGOpenMPRuntime.cpp:2980
@@ +2979,3 @@
+uint64_t ElementTypeSize =
+CGM.getContext().getTypeSize(ElementType) / 8;
+Size = CGF.Builder.getInt64(ElementTypeSize);

ABataev wrote:
> The same
Done!


Comment at: lib/CodeGen/CGStmtOpenMP.cpp:2144-2145
@@ +2143,4 @@
+  auto *ThisRef = LocalDeclMap[*pi];
+  LValue Addr = LValue::MakeAddr(ThisRef, ri->getType(), CharUnits(),
+ CGM.getContext());
+  CXXThisValue = EmitLoadOfLValue(Addr, CS.getLocStart()).getScalarVal();

ABataev wrote:
> MakeNaturalAlignAddrLValue(ThisRef, ri->getType())?
Now using `MakeNaturalAlignAddrLValue`.


Comment at: lib/CodeGen/CGStmtOpenMP.cpp:2147
@@ +2146,3 @@
+  CXXThisValue = EmitLoadOfLValue(Addr, CS.getLocStart()).getScalarVal();
+  ;
+  continue;

ABataev wrote:
> Extra semicolon
Fixed.


http://reviews.llvm.org/D11361



___
cfe-commits mailing list

Re: Second Lit tests C++11 compatibility patch: using preprocessor to filter expected-error

2015-08-17 Thread Justin Bogner via cfe-commits
"Li, Charles via cfe-commits"  writes:
> Hi Clang developers,
>
> We here at Sony are continuing to update the Lit tests for C++ dialects
> compatibility.
>
> Attached is the second patch. (As a reference, here is the link to the
> discussion on the previous Lit patch. http://lists.cs.uiuc.edu/pipermail/
> cfe-commits/Week-of-Mon-20150727/134667.html)
>
> In this second patch, there is 1 complicated change and 3 simple changes.
>
> Here is the complicated change first.
>
> test/Sema/switch-1.c
>
>   This test verifies the diagnostics for integer overflows.
>
>   Due to C++11’s more strict requirements on constant-expressions in 5.19p2
> [expr.const],
>
>   The diagnostics have changed from “overflow in expression” to “not a
> constant expression”.
>
>   Usually we would create a C++11 version of the switch-1.c file.
>
>   But here we propose a novel approach to “#ifdef” the expected diagnostics.
> (We hope to use this approach for all similar cases in the future.)
>
>   Normally ‘// expected-error’ does not honor any ‘#ifdef’.
>
>   But if we first preprocess the source into a temporary file, only the valid
> ‘#ifdef’ sections remain.
>
>   We then run the preprocessed file at the desired dialect.
>
>   The main downside to this approach is If the test fails, the errors are
> reported on the temporary file, not on the original file, and the line numbers
> of these two files  do not match

What's the upside to this approach? AFAICT it makes the test harder to
read and errors less informative due to pointing at the wrong lines, but
(at least in switch-1.c) it doesn't actually reduce any code duplication
or anything like that. What is this gaining us apart from not having to
create one more file?

> Here are the simple changes.
>
> test/Analysis/temp-obj-dtors-cfg-output.cpp
>
>   This test verifies CFG dump for temporary destructors
>
>   C++11 no longer has the following implicit cast.
>
> (ImplicitCastExpr, NoOp, const struct D)
>
>   We modified the test using the #ifdef approach to have the preprocessor
> generate the desired CHECK lines.
>
> test/CodeCompletion/ordinary-name.cpp
>
>   This test verifies for code completion patterns.
>
>   Since C++11 has more keywords than C++98,
>
>   We made this test to be C++98 specific, and create a separate C++11 version.
>
> test/CodeCompletion/ordinary-name-cxx11.cpp
>
>   This is the C++11 specific version of the code completion.
>
>   This test added patterns for the following keywords:
>
> char16, char32, noexcept, nullptr, sizeof...,
>
> auto, decltype, char16_t, char32_t
>
> test/Sema/thread-specifier.c
>
>   Tests for __thread specifier at various C++ dialects
>
>   We made the default RUN line explicit to be at –std=c++98
>
> If there is anything that seems confusing to you, please let me know.
>
> I would be more than happy to expand on the reasons for the these changes.
>
> Thanks,
>
> Charles
>
> diff --git test/Analysis/temp-obj-dtors-cfg-output.cpp 
> test/Analysis/temp-obj-dtors-cfg-output.cpp
> index 491c68e..b703cea 100644
> --- test/Analysis/temp-obj-dtors-cfg-output.cpp
> +++ test/Analysis/temp-obj-dtors-cfg-output.cpp
> @@ -1,6 +1,13 @@
>  // RUN: rm -f %t
> -// RUN: %clang_cc1 -analyze -analyzer-checker=debug.DumpCFG -analyzer-config 
> cfg-temporary-dtors=true %s > %t 2>&1
> -// RUN: FileCheck --input-file=%t %s
> +// RUN: %clang_cc1 -E -C -P -std=c++98 %s > %t_cxx98.cpp 2>&1
> +// RUN: %clang_cc1 -analyze -analyzer-checker=debug.DumpCFG -analyzer-config 
> cfg-temporary-dtors=true -std=c++98 %t_cxx98.cpp > %t 2>&1
> +// RUN: FileCheck --input-file=%t %t_cxx98.cpp
> +// RUN: %clang_cc1 -E -C -P -std=c++11 %s > %t_cxx11.cpp 2>&1
> +// RUN: %clang_cc1 -analyze -analyzer-checker=debug.DumpCFG -analyzer-config 
> cfg-temporary-dtors=true -std=c++11 %t_cxx11.cpp > %t 2>&1
> +// RUN: FileCheck --input-file=%t %t_cxx11.cpp
> +// RUN: %clang_cc1 -E -C -P %s > %t_default.cpp 2>&1
> +// RUN: %clang_cc1 -analyze -analyzer-checker=debug.DumpCFG -analyzer-config 
> cfg-temporary-dtors=true -std=c++11 %t_default.cpp > %t 2>&1
> +// RUN: FileCheck --input-file=%t %t_default.cpp
>  
>  class A {
>  public:
> @@ -671,6 +678,7 @@ int testConsistencyNestedNormalReturn(bool value) {
>  // CHECK: Succs (1): B0
>  // CHECK:   [B3]
>  // CHECK: 1: D() (CXXConstructExpr, struct D)
> +#if (__cplusplus <= 199711L) // C++03 or earlier modes
>  // CHECK: 2: [B3.1] (ImplicitCastExpr, NoOp, const struct D)
>  // CHECK: 3: [B3.2]
>  // CHECK: 4: [B3.3] (CXXConstructExpr, struct D)
> @@ -680,6 +688,16 @@ int testConsistencyNestedNormalReturn(bool value) {
>  // CHECK: 8: [B3.6]
>  // CHECK: 9: [B3.8] (ImplicitCastExpr, UserDefinedConversion, _Bool)
>  // CHECK: T: if [B3.9]
> +#else
> +// CHECK: 2: [B3.1]
> +// CHECK: 3: [B3.2] (CXXConstructExpr, struct D)
> +// CHECK: 4: D d = D();
> +// CHECK: 5: d
> +// CHECK: 6: [B3.5].operator bool
> +// CHECK: 7: [B3.5]
> +// CHECK: 8: [B3.7] (ImplicitCastExpr, Us

[PATCH] D12087: always_inline codegen rewrite

2015-08-17 Thread Evgeniy Stepanov via cfe-commits
eugenis created this revision.
eugenis added reviewers: chandlerc, rsmith.
eugenis added a subscriber: cfe-commits.
eugenis set the repository for this revision to rL LLVM.

Currently always_inline definitions are emitted as (in most cases) an 
available_externally llvm function with an alwaysinline attribute. This is not 
exactly right: always_inline functions are NOT available externally, and, for 
example, libc++ uses this semantics to preserve ABI stability.

Emitting an undefined symbol for an always_inline function is always a bug. The 
current code can still do it in certain cases. 
 a. Inliner is an SCC pass. It traverses the graph starting from the roots, 
which are either main() function, or all externally-visible functions. Inlining 
does not happen in functions that are not reachable.
 b. Dead code elimination is not perfect. There are cases where a function will 
become unreachable due to some late optimizations and will still be emitted 
into the binary.

This patch changes the way always_inline functions are emitted in the Clang 
codegen to ensure this never happens. A function F is emitted as a pair of
 a. internal F.inlinefunction() alwaysinline { **original function body** }
and, depending on the function visibility, either 
 b1. declare F()
or
 b2. define external F() { musttail call F.inlinefunction() }

Frontend ensures that all direct calls go to F.inlinefunction().

This provides a simple invariant that all alwaysinline functions are internal, 
which can be checked in the IR verifier. Another invariant would be that 
alwaysinline functions never reach the backend.

This patch is based on ideas by Chandler Carruth and Richard Smith.


Repository:
  rL LLVM

http://reviews.llvm.org/D12087

Files:
  lib/CodeGen/CGCXX.cpp
  lib/CodeGen/CodeGenModule.cpp
  lib/CodeGen/CodeGenModule.h
  lib/CodeGen/ItaniumCXXABI.cpp
  test/CodeGen/2008-05-19-AlwaysInline.c
  test/CodeGen/always-inline.c
  test/CodeGen/always_inline.c
  test/CodeGen/alwaysinline.c
  test/CodeGen/dllimport.c
  test/CodeGen/function-attributes.c
  test/CodeGen/pr9614.c
  test/CodeGenCXX/alwaysinline.cpp
  test/CodeGenCXX/dllimport.cpp
  test/Frontend/optimization-remark-line-directive.c
  test/Frontend/optimization-remark.c
  test/Modules/cxx-irgen.cpp

Index: test/Modules/cxx-irgen.cpp
===
--- test/Modules/cxx-irgen.cpp
+++ test/Modules/cxx-irgen.cpp
@@ -26,14 +26,17 @@
   };
 }
 
-// CHECK-DAG: define available_externally hidden {{.*}}{{signext i32|i32}} @_ZN1SIiE1gEv({{.*}} #[[ALWAYS_INLINE:.*]] align
+// CHECK-DAG: define internal i32 @_ZN1SIiE1gEv.inlinefunction() #[[ALWAYS_INLINE:.*]] align
+// CHECK-DAG: declare hidden i32 @_ZN1SIiE1gEv()
 int a = S::g();
 
 int b = h();
 
 // CHECK-DAG: define linkonce_odr {{.*}}{{signext i32|i32}} @_Z3minIiET_S0_S0_(i32
 int c = min(1, 2);
-// CHECK: define available_externally {{.*}}{{signext i32|i32}} @_ZN1SIiE1fEv({{.*}} #[[ALWAYS_INLINE]] align
+// CHECK-DAG: define internal {{.*}}{{signext i32|i32}} @_ZN1SIiE1fEv.inlinefunction() #[[ALWAYS_INLINE]] align
+// CHECK-DAG: declare {{.*}}{{signext i32|i32}} @_ZN1SIiE1fEv()
+
 
 namespace ImplicitSpecialMembers {
   // CHECK-LABEL: define {{.*}} @_ZN22ImplicitSpecialMembers1BC2ERKS0_(
Index: test/Frontend/optimization-remark.c
===
--- test/Frontend/optimization-remark.c
+++ test/Frontend/optimization-remark.c
@@ -32,6 +32,8 @@
 // CHECK-NOT: !llvm.dbg.cu = !{
 
 int foo(int x, int y) __attribute__((always_inline));
+// expected-remark@+2 {{foo.inlinefunction should always be inlined}}
+// expected-remark@+1 {{foo.inlinefunction inlined into foo}}
 int foo(int x, int y) { return x + y; }
 
 float foz(int x, int y) __attribute__((noinline));
@@ -45,7 +47,7 @@
 // expected-remark@+5 {{foz will not be inlined into bar}}
 // expected-remark@+4 {{foz should never be inlined}}
 // expected-remark@+3 {{foz will not be inlined into bar}}
-// expected-remark@+2 {{foo should always be inlined}}
-// expected-remark@+1 {{foo inlined into bar}}
+// expected-remark@+2 {{foo.inlinefunction should always be inlined}}
+// expected-remark@+1 {{foo.inlinefunction inlined into bar}}
   return foo(j, j - 2) * foz(j - 2, j);
 }
Index: test/Frontend/optimization-remark-line-directive.c
===
--- test/Frontend/optimization-remark-line-directive.c
+++ test/Frontend/optimization-remark-line-directive.c
@@ -5,8 +5,9 @@
 // RUN: %clang_cc1 %s -Rpass=inline -gline-tables-only -dwarf-column-info -emit-llvm-only -verify
 
 int foo(int x, int y) __attribute__((always_inline));
+// expected-remark@+1 {{foo.inlinefunction inlined into foo}}
 int foo(int x, int y) { return x + y; }
 
-// expected-remark@+2 {{foo inlined into bar}} expected-note@+2 {{could not determine the original source location for /bad/path/to/original.c:1230:25}}
+// expected-remark@+2 {{foo.inlinefunction inlin

Re: [PATCH] D12087: always_inline codegen rewrite

2015-08-17 Thread Richard Smith via cfe-commits
rsmith added inline comments.


Comment at: lib/CodeGen/CodeGenModule.cpp:447-448
@@ +446,4 @@
+  C->handleOperandChange(GV, IndirectReplacement, &U);
+} else if (!isa(U.getUser()) &&
+   !isa(U.getUser())) {
+  U.set(IndirectReplacement);

Do you need to check which operand of the call or invoke you found? For 
instance:

  void f(void (*)());
  extern inline __attribute__((always_inline, gnu_inline)) void g() {}
  void h() { f(g); } // should not use alwaysinline symbol


Comment at: lib/CodeGen/CodeGenModule.cpp:505-506
@@ +504,4 @@
+void CodeGenModule::RewriteAlwaysInlineFunctions() {
+  for (llvm::Function &Fn : TheModule.functions()) {
+if (Fn.hasFnAttribute(llvm::Attribute::AlwaysInline)) {
+  RewriteAlwaysInlineFunction(&Fn);

I think it would be better to make a list of `always_inline` functions rather 
than actually marking them as `always_inline` in the IR; that way, you don't 
need to walk all the functions here, and you don't need to temporarily violate 
the invariant that only `internal`/`private` functions are ever `always_inline`.


Repository:
  rL LLVM

http://reviews.llvm.org/D12087



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


Re: r245041 - [OPENMP] Fix for http://llvm.org/PR24371: Assert failure compiling blender 2.75.

2015-08-17 Thread Hans Wennborg via cfe-commits
Merged in r245229.

There were merge conflicts in StmtOpenMP.h because we don't have
r244209 on the branch. I think I got it right, but I'd appreciate if
someone could double check
http://llvm.org/viewvc/llvm-project?rev=245229&view=rev

Thanks,
Hans

On Sun, Aug 16, 2015 at 8:55 PM, Bataev, Alexey  wrote:
> Yes, please, forget to tell you. :)
>
> Best regards,
> Alexey Bataev
> =
> Software Engineer
> Intel Compiler Team
>
> 14.08.2015 19:03, Hans Wennborg пишет:
>
>> On Fri, Aug 14, 2015 at 5:25 AM, Alexey Bataev via cfe-commits
>>  wrote:
>>>
>>> Author: abataev
>>> Date: Fri Aug 14 07:25:37 2015
>>> New Revision: 245041
>>>
>>> URL: http://llvm.org/viewvc/llvm-project?rev=245041&view=rev
>>> Log:
>>> [OPENMP] Fix for http://llvm.org/PR24371: Assert failure compiling
>>> blender 2.75.
>>> blender uses statements expression in condition of the loop under control
>>> of the '#pragma omp parallel for'. This condition is used several times in
>>> different expressions required for codegen of the loop directive. If there
>>> are some variables defined in statement expression, it fires an assert
>>> during codegen because of redefinition of the same variables.
>>> We have to rebuild several expression to be sure that all variables are
>>> unique.
>>
>> Should we merge this to 3.7?
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D12052: [X86][SSE] Add _mm_undefined_* intrinsics

2015-08-17 Thread Eric Christopher via cfe-commits
On Sun, Aug 16, 2015 at 3:05 AM Simon Pilgrim 
wrote:

> RKSimon added a comment.
>
> Yes using that uninitialized value has worried me as well. I originally
> set it to zero (and considered using __ LINE __ or __ COUNTER __) but both
> introduce defined behaviour that I could see causing all sorts of problems
> further down the line in debug vs release builds. How undefined do we want
> our undefined to be? ;-)
>
>
Yeah, this is why I hadn't implemented them yet either.


> I can create __builtin_ia32_undef64mmx / __builtin_ia32_undef128 /
> __builtin_ia32_undef256 / __builtin_ia32_undef512 if nobody can think of a
> better alternative?
>
>
This seems fairly heavyweight, but I don't have any better ideas. I'll
assume we don't want to try to expose undef as a value in C (making it as
something we could just add), if not then this seems to make the most
sense. It's pretty painful/ugly though.

Are people using these or did they just notice for completeness? We
probably _could_ define them to zero and leave it at that. It's not
pleasant and slower than it needs to be but not crazy.

-eric


>
> Repository:
>   rL LLVM
>
> http://reviews.llvm.org/D12052
>
>
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D12087: always_inline codegen rewrite

2015-08-17 Thread Chandler Carruth via cfe-commits
chandlerc added a comment.

FYI, we should send an RFC to llvm-dev about the design change of always_inline 
and make sure folks generally like the IR-level direction as well. We can point 
at this review as an example.

I'm happy to write that up and send it if that's useful?


Repository:
  rL LLVM

http://reviews.llvm.org/D12087



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


Re: [PATCH] D11815: Pass subtarget feature "force-align-stack"

2015-08-17 Thread Akira Hatanaka via cfe-commits
On Thu, Aug 13, 2015 at 5:56 PM, Eric Christopher 
wrote:

>
>> > Apologies, I'm really resistant to more things being used in
>> > TargetOptions and I was (perhaps mistakenly) under the impression
>> > that you wanted to move it to TargetOptions without an IR
>> > serialization. We need all options to have that sort of
>> > serialization right? :)
>>
>> Absolutely, they all need function-level serialization for LTO to work.
>> We're definitely both on the same page there :)
>>
>>
> Cool.
>
>
>> > In this case it's for the -mstackrealign
>> > option and we need to keep that if it's going to work for separate
>> > compilation.
>> >
>> >
>> > I'm guessing from the comment here that you're talking about
>> > something on the order of:
>> >
>> >
>> > "force-stack-align"="true"
>> >
>> >
>> >
>> > versus something like:
>> >
>> >
>> > target-features="+force-stack-align".
>> >
>>
>> Yes.
>>
>>
> Yep.
>
>
>> >
>> > Which I can somewhat agree with if we really want to. I don't know if
>> > this is better suited toward an actual IR level attribute though?
>> >
>> > I moved soft-float over to a subtarget feature because it was
>> > something used to conditionalize initialization for each subtarget.
>> > RESET_OPTIONS needs to die a horrible death though so I don't think
>> > we should move this to TargetOptions. If we're going to do something
>> > then let's just add a target attribute and use that as a lookup. If
>> > you don't want to use it as a subtarget feature (it's not clear at
>> > all that it should be I agree), then we should just have it as a
>> > serializable attribute.
>>
>> To be clear, I don't care whether it is a subtarget feature or not. But
>> if it is a subtarget feature, we need a way of doing that in some kind of
>> base class (either in C++ or in TableGen) so that we don't just need to
>> copy-and-paste it into every backend. Adding a particular subtarget feature
>> with a specific name to every target goes beyond justifiable boilerplate.
>>
>>
> Agreed. It's one reason the patch had sat for a while (thanks for looking
> btw, it spurred me to a bit of action). I had some patches that added
> generic subtarget features to Target.td for soft float originally and was
> convinced to do the per-target bit. I agree that per-target is insanely
> boilerplate here and we should come up with something else.
>
>

If we aren't going to have generic subtarget features, I think we should
just use function attributes for target independent code-gen options like
force-align-stack.


> And, whatever we do, we really need to be consistent about it. Let's
>> decide on a way forward and unify everything in that direction. We also
>> have direct calls to check attributes in various places (such as 'if
>> (MF.getFunction()->hasFnAttribute("no-frame-pointer-elim-non-leaf"))' in
>> lib/CodeGen/TargetOptionsImpl.cpp) and we could simply add utility
>> functions to MachineFunction if we'd like too.
>>
>>
> I'm all about something new here. I've got "use-soft-float"="true"
> autoupgrading to the particular subtarget feature now (IIRC), but these
> kinds of string pair features are a bit odd after a while. Perhaps either a
> generic target-options="stuff" on the function that gets parsed once at
> Function creation time? That seems nice and extensible?
>
>
So, this is about changing the implementation of Attribute or AttributeSet
and convert "attrkind"="attrval" in the IR to something different
internally? Is this supposed to fix some flaws of Attribtue or AttributeSet?


> -eric
>
>
>>  -Hal
>>
>> >
>> >
>> > -eric
>>
>> --
>> Hal Finkel
>> Assistant Computational Scientist
>> Leadership Computing Facility
>> Argonne National Laboratory
>>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D11433: [Static Analyzer] Make NonNullParamChecker emit implicit null dereference events.

2015-08-17 Thread Anna Zaks via cfe-commits
zaks.anna requested changes to this revision.
zaks.anna added a comment.
This revision now requires changes to proceed.

I believe we saw a regression in diagnostics with this modification. Gabor, do 
you recall what it was?


http://reviews.llvm.org/D11433



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


Re: [PATCH] D12087: always_inline codegen rewrite

2015-08-17 Thread Evgeniy Stepanov via cfe-commits
eugenis removed rL LLVM as the repository for this revision.
eugenis updated this revision to Diff 32330.

http://reviews.llvm.org/D12087

Files:
  lib/CodeGen/CGCXX.cpp
  lib/CodeGen/CodeGenModule.cpp
  lib/CodeGen/CodeGenModule.h
  lib/CodeGen/ItaniumCXXABI.cpp
  test/CodeGen/2008-05-19-AlwaysInline.c
  test/CodeGen/always-inline.c
  test/CodeGen/always_inline.c
  test/CodeGen/alwaysinline.c
  test/CodeGen/dllimport.c
  test/CodeGen/function-attributes.c
  test/CodeGen/pr9614.c
  test/CodeGenCXX/alwaysinline.cpp
  test/CodeGenCXX/dllimport.cpp
  test/Frontend/optimization-remark-line-directive.c
  test/Frontend/optimization-remark.c
  test/Modules/cxx-irgen.cpp

Index: test/Modules/cxx-irgen.cpp
===
--- test/Modules/cxx-irgen.cpp
+++ test/Modules/cxx-irgen.cpp
@@ -26,14 +26,17 @@
   };
 }
 
-// CHECK-DAG: define available_externally hidden {{.*}}{{signext i32|i32}} @_ZN1SIiE1gEv({{.*}} #[[ALWAYS_INLINE:.*]] align
+// CHECK-DAG: define internal i32 @_ZN1SIiE1gEv.inlinefunction() #[[ALWAYS_INLINE:.*]] align
+// CHECK-DAG: declare hidden i32 @_ZN1SIiE1gEv()
 int a = S::g();
 
 int b = h();
 
 // CHECK-DAG: define linkonce_odr {{.*}}{{signext i32|i32}} @_Z3minIiET_S0_S0_(i32
 int c = min(1, 2);
-// CHECK: define available_externally {{.*}}{{signext i32|i32}} @_ZN1SIiE1fEv({{.*}} #[[ALWAYS_INLINE]] align
+// CHECK-DAG: define internal {{.*}}{{signext i32|i32}} @_ZN1SIiE1fEv.inlinefunction() #[[ALWAYS_INLINE]] align
+// CHECK-DAG: declare {{.*}}{{signext i32|i32}} @_ZN1SIiE1fEv()
+
 
 namespace ImplicitSpecialMembers {
   // CHECK-LABEL: define {{.*}} @_ZN22ImplicitSpecialMembers1BC2ERKS0_(
Index: test/Frontend/optimization-remark.c
===
--- test/Frontend/optimization-remark.c
+++ test/Frontend/optimization-remark.c
@@ -32,6 +32,8 @@
 // CHECK-NOT: !llvm.dbg.cu = !{
 
 int foo(int x, int y) __attribute__((always_inline));
+// expected-remark@+2 {{foo.inlinefunction should always be inlined}}
+// expected-remark@+1 {{foo.inlinefunction inlined into foo}}
 int foo(int x, int y) { return x + y; }
 
 float foz(int x, int y) __attribute__((noinline));
@@ -45,7 +47,7 @@
 // expected-remark@+5 {{foz will not be inlined into bar}}
 // expected-remark@+4 {{foz should never be inlined}}
 // expected-remark@+3 {{foz will not be inlined into bar}}
-// expected-remark@+2 {{foo should always be inlined}}
-// expected-remark@+1 {{foo inlined into bar}}
+// expected-remark@+2 {{foo.inlinefunction should always be inlined}}
+// expected-remark@+1 {{foo.inlinefunction inlined into bar}}
   return foo(j, j - 2) * foz(j - 2, j);
 }
Index: test/Frontend/optimization-remark-line-directive.c
===
--- test/Frontend/optimization-remark-line-directive.c
+++ test/Frontend/optimization-remark-line-directive.c
@@ -5,8 +5,9 @@
 // RUN: %clang_cc1 %s -Rpass=inline -gline-tables-only -dwarf-column-info -emit-llvm-only -verify
 
 int foo(int x, int y) __attribute__((always_inline));
+// expected-remark@+1 {{foo.inlinefunction inlined into foo}}
 int foo(int x, int y) { return x + y; }
 
-// expected-remark@+2 {{foo inlined into bar}} expected-note@+2 {{could not determine the original source location for /bad/path/to/original.c:1230:25}}
+// expected-remark@+2 {{foo.inlinefunction inlined into bar}} expected-note@+2 {{could not determine the original source location for /bad/path/to/original.c:1230:25}}
 #line 1230 "/bad/path/to/original.c"
 int bar(int j) { return foo(j, j - 2); }
Index: test/CodeGenCXX/dllimport.cpp
===
--- test/CodeGenCXX/dllimport.cpp
+++ test/CodeGenCXX/dllimport.cpp
@@ -244,6 +244,11 @@
 USE(noinline)
 
 // MSC2-NOT: @"\01?alwaysInline@@YAXXZ"()
+// MSC2: declare dllimport void @"\01?alwaysInline@@YAXXZ"()
+// MSC2-NOT: @"\01?alwaysInline@@YAXXZ"()
+
+// GNU2-NOT: @_Z12alwaysInlinev()
+// GNU2: define linkonce_odr void @_Z12alwaysInlinev()
 // GNU2-NOT: @_Z12alwaysInlinev()
 __declspec(dllimport) __attribute__((always_inline)) inline void alwaysInline() {}
 USE(alwaysInline)
Index: test/CodeGenCXX/alwaysinline.cpp
===
--- test/CodeGenCXX/alwaysinline.cpp
+++ test/CodeGenCXX/alwaysinline.cpp
@@ -0,0 +1,83 @@
+// Test different kinds of alwaysinline *structor definitions.
+
+// RUN: %clang_cc1 -disable-llvm-optzns -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK
+// RUN: %clang_cc1 -disable-llvm-optzns -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK-CALL
+
+// RUN: %clang_cc1 -mconstructor-aliases -disable-llvm-optzns -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK
+// RUN: %clang_cc1 -mconstructor-aliases -disable-llvm-optzns -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK-CALL
+
+struct A1 {
+  __attribute__((__always_inline__)) A1() {}
+  __attribute__((__always_inline__))

Re: [PATCH] D9924: Ignore report when the argument to malloc is assigned known value

2015-08-17 Thread Anna Zaks via cfe-commits
zaks.anna added a comment.

> x = a/b; where n < b

>  malloc (x*n); Then x*n will not overflow


I am not convinced that the new rule is strong enough. 'a' can be any 
expression. For example, maybe you have (b-1)*a/b and the denominator cancels 
out something unrelated to 'n' in the numerator? Maybe we could change the rule 
to "where n==b"? By the way, that is the only subcase that is being tested.

> With regards to copy paste, I'm not sure about how to do this in a different 
> way.


I suggest to experiment with refactoring out common parts into subroutines.


http://reviews.llvm.org/D9924



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


Re: [PATCH] D11815: Pass subtarget feature "force-align-stack"

2015-08-17 Thread Eric Christopher via cfe-commits
On Mon, Aug 17, 2015 at 11:57 AM Akira Hatanaka  wrote:

> On Thu, Aug 13, 2015 at 5:56 PM, Eric Christopher 
> wrote:
>
>>
>>> > Apologies, I'm really resistant to more things being used in
>>> > TargetOptions and I was (perhaps mistakenly) under the impression
>>> > that you wanted to move it to TargetOptions without an IR
>>> > serialization. We need all options to have that sort of
>>> > serialization right? :)
>>>
>>> Absolutely, they all need function-level serialization for LTO to work.
>>> We're definitely both on the same page there :)
>>>
>>>
>> Cool.
>>
>>
>>> > In this case it's for the -mstackrealign
>>> > option and we need to keep that if it's going to work for separate
>>> > compilation.
>>> >
>>> >
>>> > I'm guessing from the comment here that you're talking about
>>> > something on the order of:
>>> >
>>> >
>>> > "force-stack-align"="true"
>>> >
>>> >
>>> >
>>> > versus something like:
>>> >
>>> >
>>> > target-features="+force-stack-align".
>>> >
>>>
>>> Yes.
>>>
>>>
>> Yep.
>>
>>
>>> >
>>> > Which I can somewhat agree with if we really want to. I don't know if
>>> > this is better suited toward an actual IR level attribute though?
>>> >
>>> > I moved soft-float over to a subtarget feature because it was
>>> > something used to conditionalize initialization for each subtarget.
>>> > RESET_OPTIONS needs to die a horrible death though so I don't think
>>> > we should move this to TargetOptions. If we're going to do something
>>> > then let's just add a target attribute and use that as a lookup. If
>>> > you don't want to use it as a subtarget feature (it's not clear at
>>> > all that it should be I agree), then we should just have it as a
>>> > serializable attribute.
>>>
>>> To be clear, I don't care whether it is a subtarget feature or not. But
>>> if it is a subtarget feature, we need a way of doing that in some kind of
>>> base class (either in C++ or in TableGen) so that we don't just need to
>>> copy-and-paste it into every backend. Adding a particular subtarget feature
>>> with a specific name to every target goes beyond justifiable boilerplate.
>>>
>>>
>> Agreed. It's one reason the patch had sat for a while (thanks for looking
>> btw, it spurred me to a bit of action). I had some patches that added
>> generic subtarget features to Target.td for soft float originally and was
>> convinced to do the per-target bit. I agree that per-target is insanely
>> boilerplate here and we should come up with something else.
>>
>>
>
> If we aren't going to have generic subtarget features, I think we should
> just use function attributes for target independent code-gen options like
> force-align-stack.
>

I've been using subtarget features for anything necessary to initialize the
subtarget. Notice soft float for example.


>
>
>> And, whatever we do, we really need to be consistent about it. Let's
>>> decide on a way forward and unify everything in that direction. We also
>>> have direct calls to check attributes in various places (such as 'if
>>> (MF.getFunction()->hasFnAttribute("no-frame-pointer-elim-non-leaf"))' in
>>> lib/CodeGen/TargetOptionsImpl.cpp) and we could simply add utility
>>> functions to MachineFunction if we'd like too.
>>>
>>>
>> I'm all about something new here. I've got "use-soft-float"="true"
>> autoupgrading to the particular subtarget feature now (IIRC), but these
>> kinds of string pair features are a bit odd after a while. Perhaps either a
>> generic target-options="stuff" on the function that gets parsed once at
>> Function creation time? That seems nice and extensible?
>>
>>
> So, this is about changing the implementation of Attribute or AttributeSet
> and convert "attrkind"="attrval" in the IR to something different
> internally? Is this supposed to fix some flaws of Attribtue or AttributeSet?
>

No, thinking about representing certain sets of features as "attributes on
functions" that are perhaps a bit more free form, but not as ... verbose as
the current implementation.

-eric


>
>
>> -eric
>>
>>
>>>  -Hal
>>>
>>> >
>>> >
>>> > -eric
>>>
>>> --
>>> Hal Finkel
>>> Assistant Computational Scientist
>>> Leadership Computing Facility
>>> Argonne National Laboratory
>>>
>>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D12087: always_inline codegen rewrite

2015-08-17 Thread Paul Robinson via cfe-commits
probinson added a subscriber: probinson.


Comment at: lib/CodeGen/CodeGenModule.cpp:496
@@ +495,3 @@
+  llvm::ReturnInst::Create(Ctx, CI, BB);
+  }
+

What does the debug info look like for the wrapper?


http://reviews.llvm.org/D12087



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


Re: Second Lit tests C++11 compatibility patch: using preprocessor to filter expected-error

2015-08-17 Thread Richard Smith via cfe-commits
On Mon, Aug 17, 2015 at 9:56 AM, Li, Charles via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Hi Clang developers,
>
>
>
> We here at Sony are continuing to update the Lit tests for C++ dialects
> compatibility.
>
> Attached is the second patch. (As a reference, here is the link to the
> discussion on the previous Lit patch.
> http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20150727/134667.html
> )
>
> In this second patch, there is 1 complicated change and 3 simple changes.
>
>
>
> Here is the complicated change first.
>
>
>
> test/Sema/switch-1.c
>
>   This test verifies the diagnostics for integer overflows.
>
>   Due to C++11’s more strict requirements on constant-expressions in
> 5.19p2 [expr.const],
>
>   The diagnostics have changed from “overflow in expression” to “not a
> constant expression”.
>
>
>
>   Usually we would create a C++11 version of the switch-1.c file.
>
>   But here we propose a novel approach to “#ifdef” the expected
> diagnostics. (We hope to use this approach for all similar cases in the
> future.)
>
>   Normally ‘// expected-error’ does not honor any ‘#ifdef’.
>
>   But if we first preprocess the source into a temporary file, only the
> valid ‘#ifdef’ sections remain.
>
>   We then run the preprocessed file at the desired dialect.
>
>   The main downside to this approach is If the test fails, the errors are
> reported on the temporary file, not on the original file, and the line
> numbers of these two files  do not match
>

The only thing novel about this approach is using the preprocessor to
achieve it. -verify *does* respect #ifdef, and we have a lot of tests that
rely on that.


> Here are the simple changes.
>
>
>
> test/Analysis/temp-obj-dtors-cfg-output.cpp
>
>   This test verifies CFG dump for temporary destructors
>
>   C++11 no longer has the following implicit cast.
>
> (ImplicitCastExpr, NoOp, const struct D)
>
>   We modified the test using the #ifdef approach to have the preprocessor
> generate the desired CHECK lines.
>
>
>
> test/CodeCompletion/ordinary-name.cpp
>
>   This test verifies for code completion patterns.
>
>   Since C++11 has more keywords than C++98,
>
>   We made this test to be C++98 specific, and create a separate C++11
> version.
>
>
>
> test/CodeCompletion/ordinary-name-cxx11.cpp
>
>   This is the C++11 specific version of the code completion.
>
>   This test added patterns for the following keywords:
>
> char16, char32, noexcept, nullptr, sizeof...,
>
> auto, decltype, char16_t, char32_t
>
>
>
> test/Sema/thread-specifier.c
>
>   Tests for __thread specifier at various C++ dialects
>
>   We made the default RUN line explicit to be at –std=c++98
>
>
>
>
>
> If there is anything that seems confusing to you, please let me know.
>
> I would be more than happy to expand on the reasons for the these changes.
>
>
>
>
>
> Thanks,
>
> Charles
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D12000: Bugfix - Clang handles __builtin_object_size in wrong way

2015-08-17 Thread George Burgess IV via cfe-commits
george.burgess.iv updated the summary for this revision.
george.burgess.iv updated this revision to Diff 32333.
george.burgess.iv marked an inline comment as done.
george.burgess.iv added a comment.

Addressed feedback.


http://reviews.llvm.org/D12000

Files:
  lib/AST/ExprConstant.cpp
  test/CodeGen/object-size.c
  test/Sema/const-eval.c

Index: test/Sema/const-eval.c
===
--- test/Sema/const-eval.c
+++ test/Sema/const-eval.c
@@ -118,10 +118,6 @@
 const float constfloat = 0;
 EVAL_EXPR(43, varfloat && constfloat) // expected-error {{must have a constant size}}
 
-// 
-// (Make sure we continue to reject this.)
-EVAL_EXPR(44, "x"[0]); // expected-error {{variable length array}}
-
 // 
 EVAL_EXPR(45, ((char*)-1) + 1 == 0 ? 1 : -1)
 EVAL_EXPR(46, ((char*)-1) + 1 < (char*) -1 ? 1 : -1)
Index: test/CodeGen/object-size.c
===
--- test/CodeGen/object-size.c
+++ test/CodeGen/object-size.c
@@ -146,3 +146,73 @@
   // CHECK: call i64 @llvm.objectsize.i64
   return __builtin_object_size(cond ? a : b, 0);
 }
+
+// CHECK: @test19
+void test19() {
+  struct {
+int a, b;
+  } foo;
+
+  // CHECK: store i32 8
+  gi = __builtin_object_size(&foo.a, 0);
+  // CHECK: store i32 4
+  gi = __builtin_object_size(&foo.a, 1);
+  // CHECK: store i32 8
+  gi = __builtin_object_size(&foo.a, 2);
+  // CHECK: store i32 4
+  gi = __builtin_object_size(&foo.a, 3);
+}
+
+// CHECK: @test20
+void test20() {
+  struct { int t[10]; } t[10];
+
+  // CHECK: store i32 380
+  gi = __builtin_object_size(&t[0].t[5], 0);
+  // CHECK: store i32 20
+  gi = __builtin_object_size(&t[0].t[5], 1);
+  // CHECK: store i32 380
+  gi = __builtin_object_size(&t[0].t[5], 2);
+  // CHECK: store i32 20
+  gi = __builtin_object_size(&t[0].t[5], 3);
+}
+
+// CHECK: @test21
+void test21() {
+  struct { int t[10]; } t[10];
+
+  // CHECK: store i32 0
+  gi = __builtin_object_size(&t[10], 0);
+  // CHECK: store i32 0
+  gi = __builtin_object_size(&t[10], 1);
+  // CHECK: store i32 0
+  gi = __builtin_object_size(&t[10], 2);
+  // CHECK: store i32 0
+  gi = __builtin_object_size(&t[10], 3);
+
+  // CHECK: store i32 0
+  gi = __builtin_object_size(&t[9].t[10], 0);
+  // CHECK: store i32 0
+  gi = __builtin_object_size(&t[9].t[10], 1);
+  // CHECK: store i32 0
+  gi = __builtin_object_size(&t[9].t[10], 2);
+  // CHECK: store i32 0
+  gi = __builtin_object_size(&t[9].t[10], 3);
+}
+
+struct Test22Ty { int t[10]; };
+
+// CHECK: @test22
+void test22(struct Test22Ty *p) {
+  // CHECK: call i64 @llvm.objectsize.i64.p0i8(i8* %{{.*}}, i1 false)
+  gi = __builtin_object_size(p, 0);
+  // CHECK: call i64 @llvm.objectsize.i64.p0i8(i8* %{{.*}}, i1 false)
+  gi = __builtin_object_size(p, 1);
+  // CHECK:= call i64 @llvm.objectsize.i64.p0i8(i8* %{{.*}}, i1 true)
+  gi = __builtin_object_size(p, 2);
+
+  // Note: this is currently fixed at 0 because LLVM doesn't have sufficient
+  // data to correctly handle type=3
+  // CHECK: store i32 0
+  gi = __builtin_object_size(p, 3);
+}
Index: lib/AST/ExprConstant.cpp
===
--- lib/AST/ExprConstant.cpp
+++ lib/AST/ExprConstant.cpp
@@ -967,10 +967,6 @@
 // Check this LValue refers to an object. If not, set the designator to be
 // invalid and emit a diagnostic.
 bool checkSubobject(EvalInfo &Info, const Expr *E, CheckSubobjectKind CSK) {
-  // Outside C++11, do not build a designator referring to a subobject of
-  // any object: we won't use such a designator for anything.
-  if (!Info.getLangOpts().CPlusPlus11)
-Designator.setInvalid();
   return (CSK == CSK_ArrayToPointer || checkNullPointer(Info, E, CSK)) &&
  Designator.checkSubobject(Info, E, CSK);
 }
@@ -2713,8 +2709,7 @@
 
   // Check for special cases where there is no existing APValue to look at.
   const Expr *Base = LVal.Base.dyn_cast();
-  if (!LVal.Designator.Invalid && Base && !LVal.CallIndex &&
-  !Type.isVolatileQualified()) {
+  if (Base && !LVal.CallIndex && !Type.isVolatileQualified()) {
 if (const CompoundLiteralExpr *CLE = dyn_cast(Base)) {
   // In C99, a CompoundLiteralExpr is an lvalue, and we defer evaluating the
   // initializer until now for such expressions. Such an expression can't be
@@ -5998,8 +5993,7 @@
   bool VisitSizeOfPackExpr(const SizeOfPackExpr *E);
 
 private:
-  static QualType GetObjectType(APValue::LValueBase B);
-  bool TryEvaluateBuiltinObjectSize(const CallExpr *E);
+  bool TryEvaluateBuiltinObjectSize(const CallExpr *E, unsigned Type);
   // FIXME: Missing: array subscript of vector, member of vector
 };
 } // end anonymous namespace
@@ -6171,7 +6165,7 @@
 
 /// Retrieves the "underlying object type" of the given expression,
 /// as used by __builtin_object_size.
-QualType IntExprEvaluator::GetObjectType(APValue::LValueBase B) {
+static QualType getObjectType(APValue::LValueBase B) {
   if (c

Re: [PATCH] D12000: Bugfix - Clang handles __builtin_object_size in wrong way

2015-08-17 Thread George Burgess IV via cfe-commits
george.burgess.iv added inline comments.


Comment at: lib/AST/ExprConstant.cpp:6221-6223
@@ +6220,5 @@
+  //
+  //   extern struct X { char buff[32]; int a, b, c; } *p;
+  //   int a = __builtin_object_size(p->buff + 4, 3); // returns 28
+  //   int b = __builtin_object_size(p->buff + 4, 2); // returns 0, not 40
+  //

rsmith wrote:
> Please add a testcase like this (where the base object is unknown but the 
> designator is known, and thus we can compute the Type == 1 and Type == 3 
> forms but not the Type == 0 and Type == 2 forms).
EvaluatePointer is stricter than I thought -- this is actually not possible 
without adding a decent amount of complexity to the current patch. Will replace 
the comment with a TODO, and add the test case in the next patch that makes us 
support things like this. :)


http://reviews.llvm.org/D12000



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


Re: [PATCH] D12000: Bugfix - Clang handles __builtin_object_size in wrong way

2015-08-17 Thread Richard Smith via cfe-commits
rsmith accepted this revision.
rsmith added a reviewer: rsmith.
rsmith added a comment.
This revision is now accepted and ready to land.

LGTM with one more testcase :)



Comment at: lib/AST/ExprConstant.cpp:6243-6245
@@ +6242,5 @@
+  } else if (End.Designator.IsOnePastTheEnd) {
+// We're already pointing at the end of the object.
+AmountToAdd = 0;
+  }
+

rsmith wrote:
> Please add testcases for the pointer-to-the-end case:
> 
>   int n;
>   static_assert(__builtin_object_size(&n + 1, 1) == 0);
> 
>   struct X { int a, b, c; } x;
>   static_assert(__builtin_object_size(&x.a + 1, 1) == 0);
> 
I think you now have a testcase for the end-of-array case, but not the 
end-of-nonarray case.


http://reviews.llvm.org/D12000



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


RE: [PATCH] D9924: Ignore report when the argument to malloc is assigned known value

2015-08-17 Thread Aditya K via cfe-commits



> Date: Mon, 17 Aug 2015 19:29:29 +
> To: hiradi...@msn.com; jordan_r...@apple.com; kreme...@apple.com; 
> daniel.marjam...@evidente.se; mclow.li...@gmail.com; adasg...@codeaurora.org; 
> zaks.a...@gmail.com
> From: zaks.a...@gmail.com
> CC: cfe-commits@lists.llvm.org
> Subject: Re: [PATCH] D9924: Ignore report when the argument to malloc is 
> assigned known value
>
> zaks.anna added a comment.
>
>> x = a/b; where n < b
>
>> malloc (x*n); Then x*n will not overflow
>
>
> I am not convinced that the new rule is strong enough. 'a' can be any 
> expression. For example, maybe you have (b-1)*a/b and the denominator cancels 
> out something unrelated to 'n' in the numerator? Maybe we could change the 
> rule to "where n==b"? By the way, that is the only subcase that is being 
> tested.

Please correct me if I'm wrong.
My point was, as long as `n x*n < a which does not overflow.

Maybe, I should add a check that `a, b, n' are positive.
So, in this case static analyzer can choose to be strict and reject false 
positives.

If `a' might overflow, then in this case we can emit warning stating that the 
overflow is caused because `a' might overflow.

>
>> With regards to copy paste, I'm not sure about how to do this in a different 
>> way.
>
>
> I suggest to experiment with refactoring out common parts into subroutines.

Thanks, I'll try to refactor parts of it.
-Aditya

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


Re: [PATCH] D11859: Generating vptr assume loads

2015-08-17 Thread John McCall via cfe-commits
rjmccall added inline comments.


Comment at: lib/CodeGen/CGClass.cpp:1862
@@ +1861,3 @@
+  for (const VPtr &Vptr : getVTablePointers(ClassDecl))
+if (CGM.getCXXABI().requiresVPtrInitialization(Vptr))
+  EmitVTableAssumptionLoad(Vptr, This);

No, it only checks whether VTableClass has novtable.  VTableClass is the 
derived class for which we're initializing subobject v-tables, and it's 
invariant during getVTablePointers; that's why it's passed separately from 
BaseSubobject.

And if you think about how novtable works as a language feature, you'll see 
that it has to be that way.  The purpose of "novtable" is to avoid emitting 
v-tables just for the short-term purposes of construction and destruction.  
It's not supposed to apply when initializing derived classes: eventually, the 
complete object does need all the v-tables to be initialized, or else you'll 
never be able to call virtual methods on it, meaning that it might as well not 
have any.


http://reviews.llvm.org/D11859



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


r245236 - [modules] When parsing the base specifiers of a parse-merged class, the current

2015-08-17 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Mon Aug 17 15:24:17 2015
New Revision: 245236

URL: http://llvm.org/viewvc/llvm-project?rev=245236&view=rev
Log:
[modules] When parsing the base specifiers of a parse-merged class, the current
context is the class itself but lookups should be performed starting with the
lookup parent of the class (class and base members don't shadow types from the
surrounding context because they have not been declared yet).

Modified:
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/Modules/Inputs/submodules-merge-defs/defs.h
cfe/trunk/test/Modules/Inputs/template-default-args/a.h
cfe/trunk/test/Modules/submodules-merge-defs.cpp
cfe/trunk/test/Modules/template-default-args.cpp

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=245236&r1=245235&r2=245236&view=diff
==
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Mon Aug 17 15:24:17 2015
@@ -1089,7 +1089,9 @@ Sema::SkippedDefinitionContext Sema::Act
   auto Result = static_cast(CurContext);
   CurContext = cast(D)->getDefinition();
   assert(CurContext && "skipping definition of undefined tag");
-  S->setEntity(CurContext);
+  // Start lookups from the parent of the current context; we don't want to 
look
+  // into the pre-existing complete definition.
+  S->setEntity(CurContext->getLookupParent());
   return Result;
 }
 

Modified: cfe/trunk/test/Modules/Inputs/submodules-merge-defs/defs.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/submodules-merge-defs/defs.h?rev=245236&r1=245235&r2=245236&view=diff
==
--- cfe/trunk/test/Modules/Inputs/submodules-merge-defs/defs.h (original)
+++ cfe/trunk/test/Modules/Inputs/submodules-merge-defs/defs.h Mon Aug 17 
15:24:17 2015
@@ -5,10 +5,17 @@ class B {
   struct Inner1 {};
 public:
   struct Inner2;
+  struct Inner3;
   template void f();
 };
+struct BFriend {
+  friend class B::Inner3;
+private:
+  struct Inner3Base {};
+};
 // Check that lookup and access checks are performed in the right context.
 struct B::Inner2 : Inner1 {};
+struct B::Inner3 : BFriend::Inner3Base {};
 template void B::f() {}
 template<> inline void B::f() {}
 

Modified: cfe/trunk/test/Modules/Inputs/template-default-args/a.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/template-default-args/a.h?rev=245236&r1=245235&r2=245236&view=diff
==
--- cfe/trunk/test/Modules/Inputs/template-default-args/a.h (original)
+++ cfe/trunk/test/Modules/Inputs/template-default-args/a.h Mon Aug 17 15:24:17 
2015
@@ -6,4 +6,7 @@ template struct D;
 template struct E;
 template struct G;
 template struct H;
+template struct J {};
+template struct J;
+struct K : J<> {};
 END

Modified: cfe/trunk/test/Modules/submodules-merge-defs.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/submodules-merge-defs.cpp?rev=245236&r1=245235&r2=245236&view=diff
==
--- cfe/trunk/test/Modules/submodules-merge-defs.cpp (original)
+++ cfe/trunk/test/Modules/submodules-merge-defs.cpp Mon Aug 17 15:24:17 2015
@@ -26,38 +26,38 @@ int pre_use_a = use_a(pre_a); // expecte
 
 B::Inner2 pre_bi; // expected-error +{{must be imported}}
 // expected-note@defs.h:4 +{{here}}
-// expected-note@defs.h:11 +{{here}}
+// expected-note@defs.h:17 +{{here}}
 void pre_bfi(B b) { // expected-error {{must use 'class'}} expected-error 
+{{must be imported}}
   b.f(); // expected-error +{{must be imported}} expected-error +{{}}
-  // expected-note@defs.h:12 +{{here}}
+  // expected-note@defs.h:19 +{{here}}
 }
 
 C_Base<1> pre_cb1; // expected-error +{{must be imported}}
-// expected-note@defs.h:16 +{{here}}
+// expected-note@defs.h:23 +{{here}}
 C1 pre_c1; // expected-error +{{must be imported}} expected-error {{must use 
'struct'}}
-// expected-note@defs.h:18 +{{here}}
+// expected-note@defs.h:25 +{{here}}
 C2 pre_c2; // expected-error +{{must be imported}} expected-error {{must use 
'struct'}}
-// expected-note@defs.h:19 +{{here}}
+// expected-note@defs.h:26 +{{here}}
 
 D::X pre_dx; // expected-error +{{must be imported}}
-// expected-note@defs.h:21 +{{here}}
-// expected-note@defs.h:22 +{{here}}
+// expected-note@defs.h:28 +{{here}}
+// expected-note@defs.h:29 +{{here}}
 // FIXME: We should warn that use_dx is being used without being imported.
 int pre_use_dx = use_dx(pre_dx);
 
 int pre_e = E(0); // expected-error {{must be imported}}
-// expected-note@defs.h:25 +{{here}}
+// expected-note@defs.h:32 +{{here}}
 
 int pre_ff = F().f(); // expected-error +{{must be imported}}
 int pre_fg = F().g(); // expected-error +{{must be imported}}
-// expected-note@defs.h:27 +{{here}}
+// expected-note@defs.h:34 +{{here}

Re: [PATCH] D12087: always_inline codegen rewrite

2015-08-17 Thread Evgeniy Stepanov via cfe-commits
eugenis updated this revision to Diff 32338.

http://reviews.llvm.org/D12087

Files:
  lib/CodeGen/CGCXX.cpp
  lib/CodeGen/CGClass.cpp
  lib/CodeGen/CGOpenMPRuntime.cpp
  lib/CodeGen/CodeGenModule.cpp
  lib/CodeGen/CodeGenModule.h
  lib/CodeGen/ItaniumCXXABI.cpp
  test/CodeGen/2008-05-19-AlwaysInline.c
  test/CodeGen/always-inline.c
  test/CodeGen/always_inline.c
  test/CodeGen/alwaysinline.c
  test/CodeGen/dllimport.c
  test/CodeGen/function-attributes.c
  test/CodeGen/pr9614.c
  test/CodeGenCXX/alwaysinline.cpp
  test/CodeGenCXX/dllimport.cpp
  test/Frontend/optimization-remark-line-directive.c
  test/Frontend/optimization-remark.c
  test/Modules/cxx-irgen.cpp

Index: test/Modules/cxx-irgen.cpp
===
--- test/Modules/cxx-irgen.cpp
+++ test/Modules/cxx-irgen.cpp
@@ -26,14 +26,17 @@
   };
 }
 
-// CHECK-DAG: define available_externally hidden {{.*}}{{signext i32|i32}} @_ZN1SIiE1gEv({{.*}} #[[ALWAYS_INLINE:.*]] align
+// CHECK-DAG: define internal i32 @_ZN1SIiE1gEv.inlinefunction() #[[ALWAYS_INLINE:.*]] align
+// CHECK-DAG: declare hidden i32 @_ZN1SIiE1gEv()
 int a = S::g();
 
 int b = h();
 
 // CHECK-DAG: define linkonce_odr {{.*}}{{signext i32|i32}} @_Z3minIiET_S0_S0_(i32
 int c = min(1, 2);
-// CHECK: define available_externally {{.*}}{{signext i32|i32}} @_ZN1SIiE1fEv({{.*}} #[[ALWAYS_INLINE]] align
+// CHECK-DAG: define internal {{.*}}{{signext i32|i32}} @_ZN1SIiE1fEv.inlinefunction() #[[ALWAYS_INLINE]] align
+// CHECK-DAG: declare {{.*}}{{signext i32|i32}} @_ZN1SIiE1fEv()
+
 
 namespace ImplicitSpecialMembers {
   // CHECK-LABEL: define {{.*}} @_ZN22ImplicitSpecialMembers1BC2ERKS0_(
Index: test/Frontend/optimization-remark.c
===
--- test/Frontend/optimization-remark.c
+++ test/Frontend/optimization-remark.c
@@ -32,6 +32,8 @@
 // CHECK-NOT: !llvm.dbg.cu = !{
 
 int foo(int x, int y) __attribute__((always_inline));
+// expected-remark@+2 {{foo.inlinefunction should always be inlined}}
+// expected-remark@+1 {{foo.inlinefunction inlined into foo}}
 int foo(int x, int y) { return x + y; }
 
 float foz(int x, int y) __attribute__((noinline));
@@ -45,7 +47,7 @@
 // expected-remark@+5 {{foz will not be inlined into bar}}
 // expected-remark@+4 {{foz should never be inlined}}
 // expected-remark@+3 {{foz will not be inlined into bar}}
-// expected-remark@+2 {{foo should always be inlined}}
-// expected-remark@+1 {{foo inlined into bar}}
+// expected-remark@+2 {{foo.inlinefunction should always be inlined}}
+// expected-remark@+1 {{foo.inlinefunction inlined into bar}}
   return foo(j, j - 2) * foz(j - 2, j);
 }
Index: test/Frontend/optimization-remark-line-directive.c
===
--- test/Frontend/optimization-remark-line-directive.c
+++ test/Frontend/optimization-remark-line-directive.c
@@ -5,8 +5,9 @@
 // RUN: %clang_cc1 %s -Rpass=inline -gline-tables-only -dwarf-column-info -emit-llvm-only -verify
 
 int foo(int x, int y) __attribute__((always_inline));
+// expected-remark@+1 {{foo.inlinefunction inlined into foo}}
 int foo(int x, int y) { return x + y; }
 
-// expected-remark@+2 {{foo inlined into bar}} expected-note@+2 {{could not determine the original source location for /bad/path/to/original.c:1230:25}}
+// expected-remark@+2 {{foo.inlinefunction inlined into bar}} expected-note@+2 {{could not determine the original source location for /bad/path/to/original.c:1230:25}}
 #line 1230 "/bad/path/to/original.c"
 int bar(int j) { return foo(j, j - 2); }
Index: test/CodeGenCXX/dllimport.cpp
===
--- test/CodeGenCXX/dllimport.cpp
+++ test/CodeGenCXX/dllimport.cpp
@@ -244,6 +244,11 @@
 USE(noinline)
 
 // MSC2-NOT: @"\01?alwaysInline@@YAXXZ"()
+// MSC2: declare dllimport void @"\01?alwaysInline@@YAXXZ"()
+// MSC2-NOT: @"\01?alwaysInline@@YAXXZ"()
+
+// GNU2-NOT: @_Z12alwaysInlinev()
+// GNU2: define linkonce_odr void @_Z12alwaysInlinev()
 // GNU2-NOT: @_Z12alwaysInlinev()
 __declspec(dllimport) __attribute__((always_inline)) inline void alwaysInline() {}
 USE(alwaysInline)
Index: test/CodeGenCXX/alwaysinline.cpp
===
--- test/CodeGenCXX/alwaysinline.cpp
+++ test/CodeGenCXX/alwaysinline.cpp
@@ -0,0 +1,83 @@
+// Test different kinds of alwaysinline *structor definitions.
+
+// RUN: %clang_cc1 -disable-llvm-optzns -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK
+// RUN: %clang_cc1 -disable-llvm-optzns -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK-CALL
+
+// RUN: %clang_cc1 -mconstructor-aliases -disable-llvm-optzns -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK
+// RUN: %clang_cc1 -mconstructor-aliases -disable-llvm-optzns -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK-CALL
+
+struct A1 {
+  __attribute__((__always_inline__)) A1() {}
+  __attribute__((__always_inline__)) 

Re: [PATCH] D12087: always_inline codegen rewrite

2015-08-17 Thread Evgeniy Stepanov via cfe-commits
eugenis marked an inline comment as done.


Comment at: lib/CodeGen/CodeGenModule.cpp:447-448
@@ +446,4 @@
+if (C && !isa(C)) {
+  C->handleOperandChange(GV, IndirectReplacement, &U);
+  continue;
+}

Good catch.


Comment at: lib/CodeGen/CodeGenModule.cpp:496
@@ +495,3 @@
+CI->setAttributes(Fn->getAttributes());
+if (FT->getReturnType()->isVoidTy())
+  llvm::ReturnInst::Create(Ctx, BB);

I don't see any difference from the current behavior. All lines inlined from 
F.inlinefunction to F are attrubuted directly to F, and inspecting debug info 
in the binary and IR I don't find any mentions of "inlinefunction".


http://reviews.llvm.org/D12087



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


Re: [PATCH] D12087: always_inline codegen rewrite

2015-08-17 Thread Richard Smith via cfe-commits
rsmith added inline comments.


Comment at: lib/CodeGen/CodeGenModule.cpp:513
@@ +512,3 @@
+void CodeGenModule::RewriteAlwaysInlineFunctions() {
+  for (llvm::Function *Fn : AlwaysInlineFunctions)
+RewriteAlwaysInlineFunction(Fn);

Does it matter that this traversal is nondeterministic? (Is the nondeterminism 
visible in the output IR?) Could you use a vector type for 
`AlwaysInlineFunctions`? (Does the same function ever actually get added to it 
twice?) If not, maybe a `SetVector` would be more appropriate.


http://reviews.llvm.org/D12087



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


Re: [PATCH] D11194: Instantiate function declarations in instantiated functions.

2015-08-17 Thread Richard Smith via cfe-commits
rsmith added inline comments.


Comment at: lib/AST/DeclBase.cpp:273
@@ +272,3 @@
+return true;
+  if (const CXXRecordDecl *ClassD = dyn_cast(LDC))
+return ClassD->isLocalClass() && !ClassD->isLambda();;

It's not necessary for this change, but to match its documentation this 
function should handle other kinds of `TagDecl` too (enums, C structs). 
Something like:

  do {
if (LDC->isFunctionOrMethod())
  return true;
if (!isa(LDC))
  return false;
LDC = LDC->getLexicalParent();
  } while (LDC);
  return false;

... maybe?


Comment at: lib/AST/DeclBase.cpp:274
@@ +273,3 @@
+  if (const CXXRecordDecl *ClassD = dyn_cast(LDC))
+return ClassD->isLocalClass() && !ClassD->isLambda();;
+  return false;

You have a double-semicolon here.


Comment at: lib/AST/DeclBase.cpp:274
@@ +273,3 @@
+  if (const CXXRecordDecl *ClassD = dyn_cast(LDC))
+return ClassD->isLocalClass() && !ClassD->isLambda();;
+  return false;

rsmith wrote:
> You have a double-semicolon here.
Why are you discounting lambdas here?


http://reviews.llvm.org/D11194



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


Re: [PATCH] D12087: always_inline codegen rewrite

2015-08-17 Thread David Blaikie via cfe-commits
On Mon, Aug 17, 2015 at 11:07 AM, Evgeniy Stepanov via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> eugenis created this revision.
> eugenis added reviewers: chandlerc, rsmith.
> eugenis added a subscriber: cfe-commits.
> eugenis set the repository for this revision to rL LLVM.
>
> Currently always_inline definitions are emitted as (in most cases) an
> available_externally llvm function with an alwaysinline attribute.


Naive dude missing some context here: How can that ^ be correct?

A basic test case doesn't seem to indicate that that's the case:

__attribute__((always_inline)) void f1() { }
void f2() { f1(); }

Compile with LLVM optimizations disabled, etc - the bitcode has no mention
of available_externally in it...



> This is not exactly right: always_inline functions are NOT available
> externally, and, for example, libc++ uses this semantics to preserve ABI
> stability.
>
> Emitting an undefined symbol for an always_inline function is always a
> bug. The current code can still do it in certain cases.
>  a. Inliner is an SCC pass. It traverses the graph starting from the
> roots, which are either main() function, or all externally-visible
> functions. Inlining does not happen in functions that are not reachable.
>  b. Dead code elimination is not perfect. There are cases where a function
> will become unreachable due to some late optimizations and will still be
> emitted into the binary.
>
> This patch changes the way always_inline functions are emitted in the
> Clang codegen to ensure this never happens. A function F is emitted as a
> pair of
>  a. internal F.inlinefunction() alwaysinline { **original function body** }
> and, depending on the function visibility, either
>  b1. declare F()
> or
>  b2. define external F() { musttail call F.inlinefunction() }
>
> Frontend ensures that all direct calls go to F.inlinefunction().
>
> This provides a simple invariant that all alwaysinline functions are
> internal, which can be checked in the IR verifier. Another invariant would
> be that alwaysinline functions never reach the backend.
>
> This patch is based on ideas by Chandler Carruth and Richard Smith.
>
>
> Repository:
>   rL LLVM
>
> http://reviews.llvm.org/D12087
>
> Files:
>   lib/CodeGen/CGCXX.cpp
>   lib/CodeGen/CodeGenModule.cpp
>   lib/CodeGen/CodeGenModule.h
>   lib/CodeGen/ItaniumCXXABI.cpp
>   test/CodeGen/2008-05-19-AlwaysInline.c
>   test/CodeGen/always-inline.c
>   test/CodeGen/always_inline.c
>   test/CodeGen/alwaysinline.c
>   test/CodeGen/dllimport.c
>   test/CodeGen/function-attributes.c
>   test/CodeGen/pr9614.c
>   test/CodeGenCXX/alwaysinline.cpp
>   test/CodeGenCXX/dllimport.cpp
>   test/Frontend/optimization-remark-line-directive.c
>   test/Frontend/optimization-remark.c
>   test/Modules/cxx-irgen.cpp
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D12087: always_inline codegen rewrite

2015-08-17 Thread Evgeniy Stepanov via cfe-commits
eugenis updated this revision to Diff 32341.

http://reviews.llvm.org/D12087

Files:
  lib/CodeGen/CGCXX.cpp
  lib/CodeGen/CGClass.cpp
  lib/CodeGen/CGOpenMPRuntime.cpp
  lib/CodeGen/CodeGenModule.cpp
  lib/CodeGen/CodeGenModule.h
  lib/CodeGen/ItaniumCXXABI.cpp
  test/CodeGen/2008-05-19-AlwaysInline.c
  test/CodeGen/always-inline.c
  test/CodeGen/always_inline.c
  test/CodeGen/alwaysinline.c
  test/CodeGen/dllimport.c
  test/CodeGen/function-attributes.c
  test/CodeGen/pr9614.c
  test/CodeGenCXX/alwaysinline.cpp
  test/CodeGenCXX/dllimport.cpp
  test/Frontend/optimization-remark-line-directive.c
  test/Frontend/optimization-remark.c
  test/Modules/cxx-irgen.cpp

Index: test/Modules/cxx-irgen.cpp
===
--- test/Modules/cxx-irgen.cpp
+++ test/Modules/cxx-irgen.cpp
@@ -26,14 +26,17 @@
   };
 }
 
-// CHECK-DAG: define available_externally hidden {{.*}}{{signext i32|i32}} @_ZN1SIiE1gEv({{.*}} #[[ALWAYS_INLINE:.*]] align
+// CHECK-DAG: define internal i32 @_ZN1SIiE1gEv.inlinefunction() #[[ALWAYS_INLINE:.*]] align
+// CHECK-DAG: declare hidden i32 @_ZN1SIiE1gEv()
 int a = S::g();
 
 int b = h();
 
 // CHECK-DAG: define linkonce_odr {{.*}}{{signext i32|i32}} @_Z3minIiET_S0_S0_(i32
 int c = min(1, 2);
-// CHECK: define available_externally {{.*}}{{signext i32|i32}} @_ZN1SIiE1fEv({{.*}} #[[ALWAYS_INLINE]] align
+// CHECK-DAG: define internal {{.*}}{{signext i32|i32}} @_ZN1SIiE1fEv.inlinefunction() #[[ALWAYS_INLINE]] align
+// CHECK-DAG: declare {{.*}}{{signext i32|i32}} @_ZN1SIiE1fEv()
+
 
 namespace ImplicitSpecialMembers {
   // CHECK-LABEL: define {{.*}} @_ZN22ImplicitSpecialMembers1BC2ERKS0_(
Index: test/Frontend/optimization-remark.c
===
--- test/Frontend/optimization-remark.c
+++ test/Frontend/optimization-remark.c
@@ -32,6 +32,8 @@
 // CHECK-NOT: !llvm.dbg.cu = !{
 
 int foo(int x, int y) __attribute__((always_inline));
+// expected-remark@+2 {{foo.inlinefunction should always be inlined}}
+// expected-remark@+1 {{foo.inlinefunction inlined into foo}}
 int foo(int x, int y) { return x + y; }
 
 float foz(int x, int y) __attribute__((noinline));
@@ -45,7 +47,7 @@
 // expected-remark@+5 {{foz will not be inlined into bar}}
 // expected-remark@+4 {{foz should never be inlined}}
 // expected-remark@+3 {{foz will not be inlined into bar}}
-// expected-remark@+2 {{foo should always be inlined}}
-// expected-remark@+1 {{foo inlined into bar}}
+// expected-remark@+2 {{foo.inlinefunction should always be inlined}}
+// expected-remark@+1 {{foo.inlinefunction inlined into bar}}
   return foo(j, j - 2) * foz(j - 2, j);
 }
Index: test/Frontend/optimization-remark-line-directive.c
===
--- test/Frontend/optimization-remark-line-directive.c
+++ test/Frontend/optimization-remark-line-directive.c
@@ -5,8 +5,9 @@
 // RUN: %clang_cc1 %s -Rpass=inline -gline-tables-only -dwarf-column-info -emit-llvm-only -verify
 
 int foo(int x, int y) __attribute__((always_inline));
+// expected-remark@+1 {{foo.inlinefunction inlined into foo}}
 int foo(int x, int y) { return x + y; }
 
-// expected-remark@+2 {{foo inlined into bar}} expected-note@+2 {{could not determine the original source location for /bad/path/to/original.c:1230:25}}
+// expected-remark@+2 {{foo.inlinefunction inlined into bar}} expected-note@+2 {{could not determine the original source location for /bad/path/to/original.c:1230:25}}
 #line 1230 "/bad/path/to/original.c"
 int bar(int j) { return foo(j, j - 2); }
Index: test/CodeGenCXX/dllimport.cpp
===
--- test/CodeGenCXX/dllimport.cpp
+++ test/CodeGenCXX/dllimport.cpp
@@ -244,6 +244,11 @@
 USE(noinline)
 
 // MSC2-NOT: @"\01?alwaysInline@@YAXXZ"()
+// MSC2: declare dllimport void @"\01?alwaysInline@@YAXXZ"()
+// MSC2-NOT: @"\01?alwaysInline@@YAXXZ"()
+
+// GNU2-NOT: @_Z12alwaysInlinev()
+// GNU2: define linkonce_odr void @_Z12alwaysInlinev()
 // GNU2-NOT: @_Z12alwaysInlinev()
 __declspec(dllimport) __attribute__((always_inline)) inline void alwaysInline() {}
 USE(alwaysInline)
Index: test/CodeGenCXX/alwaysinline.cpp
===
--- test/CodeGenCXX/alwaysinline.cpp
+++ test/CodeGenCXX/alwaysinline.cpp
@@ -0,0 +1,83 @@
+// Test different kinds of alwaysinline *structor definitions.
+
+// RUN: %clang_cc1 -disable-llvm-optzns -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK
+// RUN: %clang_cc1 -disable-llvm-optzns -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK-CALL
+
+// RUN: %clang_cc1 -mconstructor-aliases -disable-llvm-optzns -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK
+// RUN: %clang_cc1 -mconstructor-aliases -disable-llvm-optzns -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK-CALL
+
+struct A1 {
+  __attribute__((__always_inline__)) A1() {}
+  __attribute__((__always_inline__)) 

Re: [PATCH] D12087: always_inline codegen rewrite

2015-08-17 Thread Evgeniy Stepanov via cfe-commits
eugenis added inline comments.


Comment at: lib/CodeGen/CodeGenModule.cpp:513
@@ +512,3 @@
+void CodeGenModule::RewriteAlwaysInlineFunctions() {
+  for (llvm::Function *Fn : AlwaysInlineFunctions)
+RewriteAlwaysInlineFunction(Fn);

Done. Should I make it a "SmallSetVector"? The number of always_inline 
functions seems very unpredictable and usually quite big, so it would not help, 
I guess.


http://reviews.llvm.org/D12087



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


Re: [PATCH] D11859: Generating vptr assume loads

2015-08-17 Thread Piotr Padlewski via cfe-commits
Prazek marked 3 inline comments as done.


Comment at: lib/CodeGen/CGClass.cpp:1862
@@ +1861,3 @@
+  for (const VPtr &Vptr : getVTablePointers(ClassDecl))
+if (CGM.getCXXABI().requiresVPtrInitialization(Vptr))
+  EmitVTableAssumptionLoad(Vptr, This);

rjmccall wrote:
> No, it only checks whether VTableClass has novtable.  VTableClass is the 
> derived class for which we're initializing subobject v-tables, and it's 
> invariant during getVTablePointers; that's why it's passed separately from 
> BaseSubobject.
> 
> And if you think about how novtable works as a language feature, you'll see 
> that it has to be that way.  The purpose of "novtable" is to avoid emitting 
> v-tables just for the short-term purposes of construction and destruction.  
> It's not supposed to apply when initializing derived classes: eventually, the 
> complete object does need all the v-tables to be initialized, or else you'll 
> never be able to call virtual methods on it, meaning that it might as well 
> not have any.
You are right. I changed things like You said - I only named it 
doStructorsInitilizeVPtrs


http://reviews.llvm.org/D11859



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


Re: [PATCH] D11433: [Static Analyzer] Make NonNullParamChecker emit implicit null dereference events.

2015-08-17 Thread Gábor Horváth via cfe-commits
xazax.hun added a comment.

The problem here is that, this checker can emit a warning for two cases:
1, Null was bound to a reference which should be reported as a dereference
2, Null was passed to parameter that should be non-null (marked by the 
attribute, not the qualifier) which should be reported appropriately

Right now exactly the same event will be triggered for both cases, so the 
checkers that process this event has no information whether it is a dereference 
or a value passed to a nonnull parameter, so it can not provide appropriate 
diagnostic for both cases.

One possibility would be to have two separate events, the other is to have an 
argument to an event that determines its origin. Probably it would be better to 
have two separate events, since it might be confusing to have dereference in 
the name of the event in the second case.

What do you think?


http://reviews.llvm.org/D11433



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


Re: [PATCH] D11859: Generating vptr assume loads

2015-08-17 Thread Piotr Padlewski via cfe-commits
Prazek updated this revision to Diff 32343.
Prazek marked an inline comment as done.

http://reviews.llvm.org/D11859

Files:
  lib/CodeGen/CGCXXABI.h
  lib/CodeGen/CGClass.cpp
  lib/CodeGen/CodeGenFunction.h
  lib/CodeGen/ItaniumCXXABI.cpp
  lib/CodeGen/MicrosoftCXXABI.cpp
  test/CodeGen/available-externally-hidden.cpp
  test/CodeGenCXX/ctor-globalopt.cpp
  test/CodeGenCXX/template-instantiation.cpp
  test/CodeGenCXX/thunks.cpp
  test/CodeGenCXX/virtual-base-ctor.cpp
  test/CodeGenCXX/vtable-assume-load.cpp
  test/CodeGenCXX/vtable-available-externally.cpp

Index: test/CodeGenCXX/vtable-available-externally.cpp
===
--- test/CodeGenCXX/vtable-available-externally.cpp
+++ test/CodeGenCXX/vtable-available-externally.cpp
@@ -182,8 +182,8 @@
 namespace Test9 {
 // all virtual functions are outline, so we can assume that it will
 // be generated in translation unit where foo is defined
-// CHECK-TEST9: @_ZTVN5Test91AE = available_externally unnamed_addr constant
-// CHECK-TEST9: @_ZTVN5Test91BE = available_externally unnamed_addr constant
+// CHECK-TEST9-DAG: @_ZTVN5Test91AE = available_externally unnamed_addr constant
+// CHECK-TEST9-DAG: @_ZTVN5Test91BE = available_externally unnamed_addr constant
 struct A {
   virtual void foo();
   virtual void bar();
@@ -206,39 +206,39 @@
 namespace Test10 {
 
 // because A's key function is defined here, vtable is generated in this TU
-// CHECK-TEST10: @_ZTVN6Test101AE = unnamed_addr constant
+// CHECK-TEST10-DAG: @_ZTVN6Test101AE = unnamed_addr constant
 struct A {
   virtual void foo();
   virtual void bar();
 };
 void A::foo() {}
 
 // Because key function is inline we will generate vtable as linkonce_odr
-// CHECK-TEST10: @_ZTVN6Test101DE = linkonce_odr unnamed_addr constant
+// CHECK-TEST10-DAG: @_ZTVN6Test101DE = linkonce_odr unnamed_addr constant
 struct D : A {
   void bar();
 };
 inline void D::bar() {}
 
 // because B has outline key function then we can refer to
-// CHECK-TEST10: @_ZTVN6Test101BE = available_externally unnamed_addr constant
+// CHECK-TEST10-DAG: @_ZTVN6Test101BE = available_externally unnamed_addr constant
 struct B : A {
   void foo();
   void bar();
 };
 
 // C's key function (car) is outline, but C has inline virtual function so we
 // can't guarantee that we will be able to refer to bar from name
 // so (at the moment) we can't emit vtable available_externally
-// CHECK-TEST10: @_ZTVN6Test101CE = external unnamed_addr constant
+// CHECK-TEST10-DAG: @_ZTVN6Test101CE = external unnamed_addr constant
 struct C : A {
   void bar() {}   // defined in body - not key function
   virtual inline void gar();  // inline in body - not key function
   virtual void car();
 };
 
 // no key function, vtable will be generated everywhere it will be used
-// CHECK-TEST10: @_ZTVN6Test101EE = linkonce_odr unnamed_addr constant
+// CHECK-TEST10-DAG: @_ZTVN6Test101EE = linkonce_odr unnamed_addr constant
 struct E : A {};
 
 void g(A& a) {
Index: test/CodeGenCXX/vtable-assume-load.cpp
===
--- /dev/null
+++ test/CodeGenCXX/vtable-assume-load.cpp
@@ -0,0 +1,173 @@
+// RUN: %clang_cc1 %s -triple x86_64-apple-darwin10 -emit-llvm -o %t.ll -O1 -disable-llvm-optzns -fms-extensions
+// RUN: %clang_cc1 %s -triple i686-pc-win32 -emit-llvm -o %t.ms.ll -O1 -disable-llvm-optzns -fms-extensions
+
+// RUN: FileCheck --check-prefix=CHECK1 --input-file=%t.ll %s
+// RUN: FileCheck --check-prefix=CHECK2 --input-file=%t.ll %s
+// RUN: FileCheck --check-prefix=CHECK3 --input-file=%t.ll %s
+// RUN: FileCheck --check-prefix=CHECK4 --input-file=%t.ll %s
+// RUN: FileCheck --check-prefix=CHECK-MS --input-file=%t.ms.ll %s
+
+namespace test1 {
+
+struct A {
+  A();
+  virtual void foo();
+};
+
+struct B : A {
+  virtual void foo();
+};
+
+void g(A *a) { a->foo(); }
+
+// CHECK1-LABEL: define void @_ZN5test14fooAEv()
+// CHECK1: call void @_ZN5test11AC1Ev(%"struct.test1::A"* %a)
+// CHECK1: %vtable = load i8**, i8*** %1
+// CHECK1: %cmp.vtables = icmp eq i8** %vtable, getelementptr inbounds ([3 x i8*], [3 x i8*]* @_ZTVN5test11AE, i64 0, i64 2)
+// CHECK1: call void @llvm.assume(i1 %cmp.vtables)
+// CHECK1-LABEL: }
+
+void fooA() {
+  A a;
+  g(&a);
+}
+
+// CHECK1-LABEL: define void @_ZN5test14fooBEv()
+// CHECK1: call void @_ZN5test11BC1Ev(%"struct.test1::B"* %b)
+// CHECK1: %vtable = load i8**, i8*** %1
+// CHECK1: %cmp.vtables = icmp eq i8** %vtable, getelementptr inbounds ([3 x i8*], [3 x i8*]* @_ZTVN5test11BE, i64 0, i64 2)
+// CHECK1: call void @llvm.assume(i1 %cmp.vtables)
+// CHECK1-LABEL: }
+
+void fooB() {
+  B b;
+  g(&b);
+}
+// there should not be any assumes in the ctor that calls base ctor
+// CHECK1-LABEL: define linkonce_odr void @_ZN5test11BC2Ev(%"struct.test1::B"* %this)
+// CHECK1-NOT: @llvm.assume(
+// CHECK1-LABEL: }
+}
+namespace test2 {
+struct A {
+  A();
+  virtual void foo();
+};
+
+struct B {
+  B();
+  virtual void bar();
+};

Re: [PATCH] D12087: always_inline codegen rewrite

2015-08-17 Thread Richard Smith via cfe-commits
On Mon, Aug 17, 2015 at 1:59 PM, David Blaikie  wrote:

>
>
> On Mon, Aug 17, 2015 at 11:07 AM, Evgeniy Stepanov via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>> eugenis created this revision.
>> eugenis added reviewers: chandlerc, rsmith.
>> eugenis added a subscriber: cfe-commits.
>> eugenis set the repository for this revision to rL LLVM.
>>
>> Currently always_inline definitions are emitted as (in most cases) an
>> available_externally llvm function with an alwaysinline attribute.
>
>
> Naive dude missing some context here: How can that ^ be correct?
>
> A basic test case doesn't seem to indicate that that's the case:
>
> __attribute__((always_inline)) void f1() { }
> void f2() { f1(); }
>
> Compile with LLVM optimizations disabled, etc - the bitcode has no mention
> of available_externally in it...
>

1) __attribute__((always_inline)) does not imply inline; you need to add
'inline' to f1 or you're not in the "in most cases" case
2) always-inlining is performed even at -O0; you need -mllvm
-disable-llvm-optzns to see the always_inline body
3) The "in most cases" case is for C or for C++ functions with
__attribute__((gnu_inline)); in plain C++ you get a linkonce_odr function
definition instead.


> This is not exactly right: always_inline functions are NOT available
>> externally, and, for example, libc++ uses this semantics to preserve ABI
>> stability.
>>
>> Emitting an undefined symbol for an always_inline function is always a
>> bug. The current code can still do it in certain cases.
>>  a. Inliner is an SCC pass. It traverses the graph starting from the
>> roots, which are either main() function, or all externally-visible
>> functions. Inlining does not happen in functions that are not reachable.
>>  b. Dead code elimination is not perfect. There are cases where a
>> function will become unreachable due to some late optimizations and will
>> still be emitted into the binary.
>>
>> This patch changes the way always_inline functions are emitted in the
>> Clang codegen to ensure this never happens. A function F is emitted as a
>> pair of
>>  a. internal F.inlinefunction() alwaysinline { **original function body**
>> }
>> and, depending on the function visibility, either
>>  b1. declare F()
>> or
>>  b2. define external F() { musttail call F.inlinefunction() }
>>
>> Frontend ensures that all direct calls go to F.inlinefunction().
>>
>> This provides a simple invariant that all alwaysinline functions are
>> internal, which can be checked in the IR verifier. Another invariant would
>> be that alwaysinline functions never reach the backend.
>>
>> This patch is based on ideas by Chandler Carruth and Richard Smith.
>>
>>
>> Repository:
>>   rL LLVM
>>
>> http://reviews.llvm.org/D12087
>>
>> Files:
>>   lib/CodeGen/CGCXX.cpp
>>   lib/CodeGen/CodeGenModule.cpp
>>   lib/CodeGen/CodeGenModule.h
>>   lib/CodeGen/ItaniumCXXABI.cpp
>>   test/CodeGen/2008-05-19-AlwaysInline.c
>>   test/CodeGen/always-inline.c
>>   test/CodeGen/always_inline.c
>>   test/CodeGen/alwaysinline.c
>>   test/CodeGen/dllimport.c
>>   test/CodeGen/function-attributes.c
>>   test/CodeGen/pr9614.c
>>   test/CodeGenCXX/alwaysinline.cpp
>>   test/CodeGenCXX/dllimport.cpp
>>   test/Frontend/optimization-remark-line-directive.c
>>   test/Frontend/optimization-remark.c
>>   test/Modules/cxx-irgen.cpp
>>
>>
>> ___
>> cfe-commits mailing list
>> cfe-commits@lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>>
>>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D11859: Generating vptr assume loads

2015-08-17 Thread Piotr Padlewski via cfe-commits
Prazek marked 3 inline comments as done.
Prazek added a comment.

http://reviews.llvm.org/D11859



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


Re: [PATCH] D12087: always_inline codegen rewrite

2015-08-17 Thread Evgenii Stepanov via cfe-commits
On Mon, Aug 17, 2015 at 1:59 PM, David Blaikie  wrote:
>
>
> On Mon, Aug 17, 2015 at 11:07 AM, Evgeniy Stepanov via cfe-commits
>  wrote:
>>
>> eugenis created this revision.
>> eugenis added reviewers: chandlerc, rsmith.
>> eugenis added a subscriber: cfe-commits.
>> eugenis set the repository for this revision to rL LLVM.
>>
>> Currently always_inline definitions are emitted as (in most cases) an
>> available_externally llvm function with an alwaysinline attribute.
>
>
> Naive dude missing some context here: How can that ^ be correct?
>
> A basic test case doesn't seem to indicate that that's the case:
>
> __attribute__((always_inline)) void f1() { }
> void f2() { f1(); }
>
> Compile with LLVM optimizations disabled, etc - the bitcode has no mention
> of available_externally in it...

Add "inline" and build as C, not C++.
Yes, not in "most cases". Just sometimes.

>
>
>>
>> This is not exactly right: always_inline functions are NOT available
>> externally, and, for example, libc++ uses this semantics to preserve ABI
>> stability.
>>
>> Emitting an undefined symbol for an always_inline function is always a
>> bug. The current code can still do it in certain cases.
>>  a. Inliner is an SCC pass. It traverses the graph starting from the
>> roots, which are either main() function, or all externally-visible
>> functions. Inlining does not happen in functions that are not reachable.
>>  b. Dead code elimination is not perfect. There are cases where a function
>> will become unreachable due to some late optimizations and will still be
>> emitted into the binary.
>>
>> This patch changes the way always_inline functions are emitted in the
>> Clang codegen to ensure this never happens. A function F is emitted as a
>> pair of
>>  a. internal F.inlinefunction() alwaysinline { **original function body**
>> }
>> and, depending on the function visibility, either
>>  b1. declare F()
>> or
>>  b2. define external F() { musttail call F.inlinefunction() }
>>
>> Frontend ensures that all direct calls go to F.inlinefunction().
>>
>> This provides a simple invariant that all alwaysinline functions are
>> internal, which can be checked in the IR verifier. Another invariant would
>> be that alwaysinline functions never reach the backend.
>>
>> This patch is based on ideas by Chandler Carruth and Richard Smith.
>>
>>
>> Repository:
>>   rL LLVM
>>
>> http://reviews.llvm.org/D12087
>>
>> Files:
>>   lib/CodeGen/CGCXX.cpp
>>   lib/CodeGen/CodeGenModule.cpp
>>   lib/CodeGen/CodeGenModule.h
>>   lib/CodeGen/ItaniumCXXABI.cpp
>>   test/CodeGen/2008-05-19-AlwaysInline.c
>>   test/CodeGen/always-inline.c
>>   test/CodeGen/always_inline.c
>>   test/CodeGen/alwaysinline.c
>>   test/CodeGen/dllimport.c
>>   test/CodeGen/function-attributes.c
>>   test/CodeGen/pr9614.c
>>   test/CodeGenCXX/alwaysinline.cpp
>>   test/CodeGenCXX/dllimport.cpp
>>   test/Frontend/optimization-remark-line-directive.c
>>   test/Frontend/optimization-remark.c
>>   test/Modules/cxx-irgen.cpp
>>
>>
>> ___
>> cfe-commits mailing list
>> cfe-commits@lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libcxx] r245239 - Make regex and any assert when they should throw an exception _but_ the user has decreed 'no exceptions'. This matches the behavior of string and vector

2015-08-17 Thread Marshall Clow via cfe-commits
Author: marshall
Date: Mon Aug 17 16:14:16 2015
New Revision: 245239

URL: http://llvm.org/viewvc/llvm-project?rev=245239&view=rev
Log:
Make regex and any assert when they should throw an exception _but_ the user 
has decreed 'no exceptions'. This matches the behavior of string and vector

Modified:
libcxx/trunk/include/experimental/any
libcxx/trunk/include/regex

Modified: libcxx/trunk/include/experimental/any
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/experimental/any?rev=245239&r1=245238&r2=245239&view=diff
==
--- libcxx/trunk/include/experimental/any (original)
+++ libcxx/trunk/include/experimental/any Mon Aug 17 16:14:16 2015
@@ -82,6 +82,7 @@ inline namespace fundamentals_v1 {
 #include 
 #include 
 #include 
+#include 
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #pragma GCC system_header
@@ -106,7 +107,7 @@ inline void __throw_bad_any_cast()
 #ifndef _LIBCPP_NO_EXCEPTIONS
 throw bad_any_cast();
 #else
-_VSTD::abort();
+assert(!"bad_any_cast");
 #endif
 }
 

Modified: libcxx/trunk/include/regex
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/regex?rev=245239&r1=245238&r2=245239&view=diff
==
--- libcxx/trunk/include/regex (original)
+++ libcxx/trunk/include/regex Mon Aug 17 16:14:16 2015
@@ -762,6 +762,7 @@ typedef regex_token_iterator
 #include 
 #include 
+#include 
 
 #include <__undef_min_max>
 
@@ -960,7 +961,9 @@ _LIBCPP_ALWAYS_INLINE
 void __throw_regex_error()
 {
 #ifndef _LIBCPP_NO_EXCEPTIONS
-   throw regex_error(_Ev);
+throw regex_error(_Ev);
+#else
+assert(!"regex_error");
 #endif
 }
 


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


Re: [PATCH] D11815: Pass subtarget feature "force-align-stack"

2015-08-17 Thread Akira Hatanaka via cfe-commits
On Mon, Aug 17, 2015 at 12:41 PM, Eric Christopher 
wrote:

>
>
> On Mon, Aug 17, 2015 at 11:57 AM Akira Hatanaka 
> wrote:
>
>> On Thu, Aug 13, 2015 at 5:56 PM, Eric Christopher 
>> wrote:
>>
>>>
 > Apologies, I'm really resistant to more things being used in
 > TargetOptions and I was (perhaps mistakenly) under the impression
 > that you wanted to move it to TargetOptions without an IR
 > serialization. We need all options to have that sort of
 > serialization right? :)

 Absolutely, they all need function-level serialization for LTO to work.
 We're definitely both on the same page there :)


>>> Cool.
>>>
>>>
 > In this case it's for the -mstackrealign
 > option and we need to keep that if it's going to work for separate
 > compilation.
 >
 >
 > I'm guessing from the comment here that you're talking about
 > something on the order of:
 >
 >
 > "force-stack-align"="true"
 >
 >
 >
 > versus something like:
 >
 >
 > target-features="+force-stack-align".
 >

 Yes.


>>> Yep.
>>>
>>>
 >
 > Which I can somewhat agree with if we really want to. I don't know if
 > this is better suited toward an actual IR level attribute though?
 >
 > I moved soft-float over to a subtarget feature because it was
 > something used to conditionalize initialization for each subtarget.
 > RESET_OPTIONS needs to die a horrible death though so I don't think
 > we should move this to TargetOptions. If we're going to do something
 > then let's just add a target attribute and use that as a lookup. If
 > you don't want to use it as a subtarget feature (it's not clear at
 > all that it should be I agree), then we should just have it as a
 > serializable attribute.

 To be clear, I don't care whether it is a subtarget feature or not. But
 if it is a subtarget feature, we need a way of doing that in some kind of
 base class (either in C++ or in TableGen) so that we don't just need to
 copy-and-paste it into every backend. Adding a particular subtarget feature
 with a specific name to every target goes beyond justifiable boilerplate.


>>> Agreed. It's one reason the patch had sat for a while (thanks for
>>> looking btw, it spurred me to a bit of action). I had some patches that
>>> added generic subtarget features to Target.td for soft float originally and
>>> was convinced to do the per-target bit. I agree that per-target is insanely
>>> boilerplate here and we should come up with something else.
>>>
>>>
>>
>> If we aren't going to have generic subtarget features, I think we should
>> just use function attributes for target independent code-gen options like
>> force-align-stack.
>>
>
> I've been using subtarget features for anything necessary to initialize
> the subtarget. Notice soft float for example.
>
>

OK, a subtarget feature should be used if there is a variable of subtarget
that needs initialization. force-align-stack doesn't seem to need a
variable in subtarget, so it can be a function attribute.


>
>>
>>> And, whatever we do, we really need to be consistent about it. Let's
 decide on a way forward and unify everything in that direction. We also
 have direct calls to check attributes in various places (such as 'if
 (MF.getFunction()->hasFnAttribute("no-frame-pointer-elim-non-leaf"))' in
 lib/CodeGen/TargetOptionsImpl.cpp) and we could simply add utility
 functions to MachineFunction if we'd like too.


>>> I'm all about something new here. I've got "use-soft-float"="true"
>>> autoupgrading to the particular subtarget feature now (IIRC), but these
>>> kinds of string pair features are a bit odd after a while. Perhaps either a
>>> generic target-options="stuff" on the function that gets parsed once at
>>> Function creation time? That seems nice and extensible?
>>>
>>>
>> So, this is about changing the implementation of Attribute or
>> AttributeSet and convert "attrkind"="attrval" in the IR to something
>> different internally? Is this supposed to fix some flaws of Attribtue or
>> AttributeSet?
>>
>
> No, thinking about representing certain sets of features as "attributes on
> functions" that are perhaps a bit more free form, but not as ... verbose as
> the current implementation.
>
>
Could you give some examples?

So for a function attribute like "force-align-stack" (can be either an enum
or a string, but note that there is no "false" or "true" value as there is
no need to make it a tri-state), what would the new less verbose
representation look like and how would it improve the way function
attributes are handled?


> -eric
>
>
>>
>>
>>> -eric
>>>
>>>
  -Hal

 >
 >
 > -eric

 --
 Hal Finkel
 Assistant Computational Scientist
 Leadership Computing Facility
 Argonne National Laboratory

>>>
___
cfe-commits mail

Re: [PATCH] D9924: Ignore report when the argument to malloc is assigned known value

2015-08-17 Thread Anna Zaks via cfe-commits
zaks.anna added a comment.

> Maybe, I should add a check that `a, b, n' are positive.

>  So, in this case static analyzer can choose to be strict and reject false 
> positives.


What would this buy us? Does the checker warn on underflow?

> If a' might overflow, then in this case we can emit warning stating that the 
> overflow is caused because a' might overflow.


I see your point now! I think we should improve the diagnostic that is produced 
in this case!


http://reviews.llvm.org/D9924



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


Re: r239883 - Update the intel intrinsic headers to use the target attribute support.

2015-08-17 Thread Dimitry Andric via cfe-commits
[Re-sending, used the old cfe-commits address by accident]

Where is the other thread?  This problem still exists, for both trunk and the 
upcoming 3.7.0 RC3.  I'll try to submit a patch tomorrow to partially restore 
the include guards, so we won't have a broken release.

-Dimitry

> On 03 Aug 2015, at 18:48, Eric Christopher  > wrote:
> 
> 
> 
> Where are the negative test cases? Diagnosing uses of these functions
> when they aren't valid is really important - it's a pretty serious
> regression if we don't.
> 
> Two threads, I'm going to take this in the other thread. :)
> 
> -eric
> 
> 
> ___
> cfe-commits mailing list
> cfe-comm...@cs.uiuc.edu 
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits



signature.asc
Description: Message signed with OpenPGP using GPGMail
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r239883 - Update the intel intrinsic headers to use the target attribute support.

2015-08-17 Thread Eric Christopher via cfe-commits
There is nothing broken about not having the include guards there, it's
just not helpful. I'm working on the infrastructure for an error if you
call a function from within an incompatible routine at the moment (without
duplicating a lot of code it's actually a bit annoying), but there's
nothing actually wrong with the code. It's just the same as basically
saying asm("invalid_instruction") in a random function.

Any configure script that was depending on error conditions from this is
already broken by gcc as well, and likely icc.

-eric

On Mon, Aug 17, 2015 at 3:04 PM Dimitry Andric  wrote:

> [Re-sending, used the old cfe-commits address by accident]
>
> Where is the other thread?  This problem still exists, for both trunk and
> the upcoming 3.7.0 RC3.  I'll try to submit a patch tomorrow to partially
> restore the include guards, so we won't have a broken release.
>
> -Dimitry
>
> On 03 Aug 2015, at 18:48, Eric Christopher  wrote:
>
>
>>
>> Where are the negative test cases? Diagnosing uses of these functions
>> when they aren't valid is really important - it's a pretty serious
>> regression if we don't.
>>
>
> Two threads, I'm going to take this in the other thread. :)
>
> -eric
>
>
> ___
> cfe-commits mailing list
> cfe-comm...@cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r245250 - Make a test less brittle.

2015-08-17 Thread Richard Trieu via cfe-commits
Author: rtrieu
Date: Mon Aug 17 17:18:30 2015
New Revision: 245250

URL: http://llvm.org/viewvc/llvm-project?rev=245250&view=rev
Log:
Make a test less brittle.

Capture line numbers in a variable for FileCheck instead of hardcoding them.

Modified:
cfe/trunk/test/SemaCXX/warn-logical-not-compare.cpp

Modified: cfe/trunk/test/SemaCXX/warn-logical-not-compare.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-logical-not-compare.cpp?rev=245250&r1=245249&r2=245250&view=diff
==
--- cfe/trunk/test/SemaCXX/warn-logical-not-compare.cpp (original)
+++ cfe/trunk/test/SemaCXX/warn-logical-not-compare.cpp Mon Aug 17 17:18:30 2015
@@ -11,67 +11,73 @@ bool test1(int i1, int i2, bool b1, bool
   // expected-warning@-1 {{logical not is only applied to the left hand side 
of this comparison}}
   // expected-note@-2 {{add parentheses after the '!' to evaluate the 
comparison first}}
   // expected-note@-3 {{add parentheses around left hand side expression to 
silence this warning}}
+  // CHECK: warn-logical-not-compare.cpp:[[line:[0-9]*]]:9: warning
   // CHECK: to evaluate the comparison first
-  // CHECK: fix-it:"{{.*}}":{10:10-10:10}:"("
-  // CHECK: fix-it:"{{.*}}":{10:18-10:18}:")"
+  // CHECK: fix-it:"{{.*}}":{[[line]]:10-[[line]]:10}:"("
+  // CHECK: fix-it:"{{.*}}":{[[line]]:18-[[line]]:18}:")"
   // CHECK: to silence this warning
-  // CHECK: fix-it:"{{.*}}":{10:9-10:9}:"("
-  // CHECK: fix-it:"{{.*}}":{10:12-10:12}:")"
+  // CHECK: fix-it:"{{.*}}":{[[line]]:9-[[line]]:9}:"("
+  // CHECK: fix-it:"{{.*}}":{[[line]]:12-[[line]]:12}:")"
 
   ret = !i1 != i2;
   //expected-warning@-1 {{logical not is only applied to the left hand side of 
this comparison}}
   // expected-note@-2 {{add parentheses after the '!' to evaluate the 
comparison first}}
   // expected-note@-3 {{add parentheses around left hand side expression to 
silence this warning}}
+  // CHECK: warn-logical-not-compare.cpp:[[line:[0-9]*]]:9: warning
   // CHECK: to evaluate the comparison first
-  // CHECK: fix-it:"{{.*}}":{21:10-21:10}:"("
-  // CHECK: fix-it:"{{.*}}":{21:18-21:18}:")"
+  // CHECK: fix-it:"{{.*}}":{[[line]]:10-[[line]]:10}:"("
+  // CHECK: fix-it:"{{.*}}":{[[line]]:18-[[line]]:18}:")"
   // CHECK: to silence this warning
-  // CHECK: fix-it:"{{.*}}":{21:9-21:9}:"("
-  // CHECK: fix-it:"{{.*}}":{21:12-21:12}:")"
+  // CHECK: fix-it:"{{.*}}":{[[line]]:9-[[line]]:9}:"("
+  // CHECK: fix-it:"{{.*}}":{[[line]]:12-[[line]]:12}:")"
 
   ret = !i1 < i2;
   //expected-warning@-1 {{logical not is only applied to the left hand side of 
this comparison}}
   // expected-note@-2 {{add parentheses after the '!' to evaluate the 
comparison first}}
   // expected-note@-3 {{add parentheses around left hand side expression to 
silence this warning}}
+  // CHECK: warn-logical-not-compare.cpp:[[line:[0-9]*]]:9: warning
   // CHECK: to evaluate the comparison first
-  // CHECK: fix-it:"{{.*}}":{32:10-32:10}:"("
-  // CHECK: fix-it:"{{.*}}":{32:17-32:17}:")"
+  // CHECK: fix-it:"{{.*}}":{[[line]]:10-[[line]]:10}:"("
+  // CHECK: fix-it:"{{.*}}":{[[line]]:17-[[line]]:17}:")"
   // CHECK: to silence this warning
-  // CHECK: fix-it:"{{.*}}":{32:9-32:9}:"("
-  // CHECK: fix-it:"{{.*}}":{32:12-32:12}:")"
+  // CHECK: fix-it:"{{.*}}":{[[line]]:9-[[line]]:9}:"("
+  // CHECK: fix-it:"{{.*}}":{[[line]]:12-[[line]]:12}:")"
 
   ret = !i1 > i2;
   //expected-warning@-1 {{logical not is only applied to the left hand side of 
this comparison}}
   // expected-note@-2 {{add parentheses after the '!' to evaluate the 
comparison first}}
   // expected-note@-3 {{add parentheses around left hand side expression to 
silence this warning}}
+  // CHECK: warn-logical-not-compare.cpp:[[line:[0-9]*]]:9: warning
   // CHECK: to evaluate the comparison first
-  // CHECK: fix-it:"{{.*}}":{43:10-43:10}:"("
-  // CHECK: fix-it:"{{.*}}":{43:17-43:17}:")"
+  // CHECK: fix-it:"{{.*}}":{[[line]]:10-[[line]]:10}:"("
+  // CHECK: fix-it:"{{.*}}":{[[line]]:17-[[line]]:17}:")"
   // CHECK: to silence this warning
-  // CHECK: fix-it:"{{.*}}":{43:9-43:9}:"("
-  // CHECK: fix-it:"{{.*}}":{43:12-43:12}:")"
+  // CHECK: fix-it:"{{.*}}":{[[line]]:9-[[line]]:9}:"("
+  // CHECK: fix-it:"{{.*}}":{[[line]]:12-[[line]]:12}:")"
 
   ret = !i1 <= i2;
   //expected-warning@-1 {{logical not is only applied to the left hand side of 
this comparison}}
   // expected-note@-2 {{add parentheses after the '!' to evaluate the 
comparison first}}
   // expected-note@-3 {{add parentheses around left hand side expression to 
silence this warning}}
+  // CHECK: warn-logical-not-compare.cpp:[[line:[0-9]*]]:9: warning
   // CHECK: to evaluate the comparison first
-  // CHECK: fix-it:"{{.*}}":{54:10-54:10}:"("
-  // CHECK: fix-it:"{{.*}}":{54:18-54:18}:")"
+  // CHECK: fix-it:"{{.*}}":{[[line]]:10-[[line]]:10}:"("
+  // CHECK: fix-it:"{{.*}}":{[[line]]:18-[[line]]:18}:")"
   // CHECK: to silence this warning
-  // CHECK: f

r245251 - Remove dead code, there's no need for an override that just duplicates

2015-08-17 Thread Eric Christopher via cfe-commits
Author: echristo
Date: Mon Aug 17 17:22:28 2015
New Revision: 245251

URL: http://llvm.org/viewvc/llvm-project?rev=245251&view=rev
Log:
Remove dead code, there's no need for an override that just duplicates
the default behavior.

Modified:
cfe/trunk/lib/Basic/Targets.cpp

Modified: cfe/trunk/lib/Basic/Targets.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?rev=245251&r1=245250&r2=245251&view=diff
==
--- cfe/trunk/lib/Basic/Targets.cpp (original)
+++ cfe/trunk/lib/Basic/Targets.cpp Mon Aug 17 17:22:28 2015
@@ -6816,8 +6816,6 @@ public:
 this->RegParmMax = 0; // Disallow regparm
   }
 
-  void getDefaultFeatures(llvm::StringMap &Features) const override {
-  }
   void getArchDefines(const LangOptions &Opts, MacroBuilder &Builder) const {
 Builder.defineMacro("__le32__");
 Builder.defineMacro("__pnacl__");


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


Re: [PATCH] D11859: Generating vptr assume loads

2015-08-17 Thread John McCall via cfe-commits
rjmccall added a comment.

Just a couple tweaks and then LGTM.



Comment at: lib/CodeGen/CGClass.cpp:1833
@@ +1832,3 @@
+  // unless we are calling base constructor - we don't want to generating
+  // assumption loads for not completed because vptr may still change.
+  if (CGM.getCodeGenOpts().OptimizationLevel > 0 &&

Please use this comment:

  // Generate vtable assumptions if we're constructing a complete object
  // with a vtable.  We don't do this for base subobjects for two reasons:
  // first, it's incorrect for classes with virtual bases, and second, we're
  // about to overwrite the vptrs anyway.


Comment at: lib/CodeGen/CGClass.cpp:2155
@@ -2122,1 +2154,3 @@
+for (const VPtr &Vptr : Vptrs)
+  InitializeVTablePointer(Vptr);
 

Please also skip the call to getVTablePointers when doStructorsInitializeVPtrs, 
thanks.


Comment at: lib/CodeGen/ItaniumCXXABI.cpp:196
@@ +195,3 @@
+
+  bool doStructorsInitilizeVPtrs(const CXXRecordDecl *VTableClass) override {
+return true;

Typo: "Initialize".


http://reviews.llvm.org/D11859



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


Re: [PATCH] D12036: We shouldn't need to pass -fno-strict-aliasing when building clang with clang.

2015-08-17 Thread Chris Bieneman via cfe-commits
beanz updated this revision to Diff 32349.
beanz added a comment.

- Adapting to r245255 which exposes a variable in autoconf for which compiler 
you are building with.
- Updated the CMake to be more CMake-y

Note: This has been tested by running a check on a stage2 clang built with asan 
and ubsan.


http://reviews.llvm.org/D12036

Files:
  CMakeLists.txt
  Makefile

Index: Makefile
===
--- Makefile
+++ Makefile
@@ -67,8 +67,11 @@
 #   http://gcc.gnu.org/PR41874
 #   http://gcc.gnu.org/PR41838
 #
-# We can revisit this when LLVM/Clang support it.
+# We don't need to do this if the host compiler is clang.
+ifeq ($(CXX_COMPILER), "clang")
 CXX.Flags += -fno-strict-aliasing
+endif
+
 
 # Set up Clang's tblgen.
 ifndef CLANG_TBLGEN
Index: CMakeLists.txt
===
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -253,7 +253,10 @@
 
 # Add appropriate flags for GCC
 if (LLVM_COMPILER_IS_GCC_COMPATIBLE)
-  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-common -Woverloaded-virtual 
-fno-strict-aliasing")
+  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-common -Woverloaded-virtual")
+  if (NOT "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-strict-aliasing")
+  endif ()
 
   # Enable -pedantic for Clang even if it's not enabled for LLVM.
   if (NOT LLVM_ENABLE_PEDANTIC)


Index: Makefile
===
--- Makefile
+++ Makefile
@@ -67,8 +67,11 @@
 #   http://gcc.gnu.org/PR41874
 #   http://gcc.gnu.org/PR41838
 #
-# We can revisit this when LLVM/Clang support it.
+# We don't need to do this if the host compiler is clang.
+ifeq ($(CXX_COMPILER), "clang")
 CXX.Flags += -fno-strict-aliasing
+endif
+
 
 # Set up Clang's tblgen.
 ifndef CLANG_TBLGEN
Index: CMakeLists.txt
===
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -253,7 +253,10 @@
 
 # Add appropriate flags for GCC
 if (LLVM_COMPILER_IS_GCC_COMPATIBLE)
-  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-common -Woverloaded-virtual -fno-strict-aliasing")
+  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-common -Woverloaded-virtual")
+  if (NOT "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-strict-aliasing")
+  endif ()
 
   # Enable -pedantic for Clang even if it's not enabled for LLVM.
   if (NOT LLVM_ENABLE_PEDANTIC)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r239883 - Update the intel intrinsic headers to use the target attribute support.

2015-08-17 Thread Hans Wennborg via cfe-commits
The 3.7 branch does have the include guards; they were re-added in
http://llvm.org/viewvc/llvm-project?rev=243925&view=rev. That happened
after rc2, but it will be in rc3.

Can you double check if you're still running into problems on the 3.7 branch?

 - Hans


On Mon, Aug 17, 2015 at 3:04 PM, Dimitry Andric  wrote:
> [Re-sending, used the old cfe-commits address by accident]
>
> Where is the other thread?  This problem still exists, for both trunk and
> the upcoming 3.7.0 RC3.  I'll try to submit a patch tomorrow to partially
> restore the include guards, so we won't have a broken release.
>
> -Dimitry
>
> On 03 Aug 2015, at 18:48, Eric Christopher  wrote:
>
>>
>>
>> Where are the negative test cases? Diagnosing uses of these functions
>> when they aren't valid is really important - it's a pretty serious
>> regression if we don't.
>
>
> Two threads, I'm going to take this in the other thread. :)
>
> -eric
>
>
> ___
> cfe-commits mailing list
> cfe-comm...@cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D11859: Generating vptr assume loads

2015-08-17 Thread Piotr Padlewski via cfe-commits
Prazek updated this revision to Diff 32355.
Prazek marked 2 inline comments as done.

http://reviews.llvm.org/D11859

Files:
  lib/CodeGen/CGCXXABI.h
  lib/CodeGen/CGClass.cpp
  lib/CodeGen/CodeGenFunction.h
  lib/CodeGen/ItaniumCXXABI.cpp
  lib/CodeGen/MicrosoftCXXABI.cpp
  test/CodeGen/available-externally-hidden.cpp
  test/CodeGenCXX/ctor-globalopt.cpp
  test/CodeGenCXX/template-instantiation.cpp
  test/CodeGenCXX/thunks.cpp
  test/CodeGenCXX/virtual-base-ctor.cpp
  test/CodeGenCXX/vtable-assume-load.cpp
  test/CodeGenCXX/vtable-available-externally.cpp

Index: test/CodeGenCXX/vtable-available-externally.cpp
===
--- test/CodeGenCXX/vtable-available-externally.cpp
+++ test/CodeGenCXX/vtable-available-externally.cpp
@@ -182,8 +182,8 @@
 namespace Test9 {
 // all virtual functions are outline, so we can assume that it will
 // be generated in translation unit where foo is defined
-// CHECK-TEST9: @_ZTVN5Test91AE = available_externally unnamed_addr constant
-// CHECK-TEST9: @_ZTVN5Test91BE = available_externally unnamed_addr constant
+// CHECK-TEST9-DAG: @_ZTVN5Test91AE = available_externally unnamed_addr constant
+// CHECK-TEST9-DAG: @_ZTVN5Test91BE = available_externally unnamed_addr constant
 struct A {
   virtual void foo();
   virtual void bar();
@@ -206,39 +206,39 @@
 namespace Test10 {
 
 // because A's key function is defined here, vtable is generated in this TU
-// CHECK-TEST10: @_ZTVN6Test101AE = unnamed_addr constant
+// CHECK-TEST10-DAG: @_ZTVN6Test101AE = unnamed_addr constant
 struct A {
   virtual void foo();
   virtual void bar();
 };
 void A::foo() {}
 
 // Because key function is inline we will generate vtable as linkonce_odr
-// CHECK-TEST10: @_ZTVN6Test101DE = linkonce_odr unnamed_addr constant
+// CHECK-TEST10-DAG: @_ZTVN6Test101DE = linkonce_odr unnamed_addr constant
 struct D : A {
   void bar();
 };
 inline void D::bar() {}
 
 // because B has outline key function then we can refer to
-// CHECK-TEST10: @_ZTVN6Test101BE = available_externally unnamed_addr constant
+// CHECK-TEST10-DAG: @_ZTVN6Test101BE = available_externally unnamed_addr constant
 struct B : A {
   void foo();
   void bar();
 };
 
 // C's key function (car) is outline, but C has inline virtual function so we
 // can't guarantee that we will be able to refer to bar from name
 // so (at the moment) we can't emit vtable available_externally
-// CHECK-TEST10: @_ZTVN6Test101CE = external unnamed_addr constant
+// CHECK-TEST10-DAG: @_ZTVN6Test101CE = external unnamed_addr constant
 struct C : A {
   void bar() {}   // defined in body - not key function
   virtual inline void gar();  // inline in body - not key function
   virtual void car();
 };
 
 // no key function, vtable will be generated everywhere it will be used
-// CHECK-TEST10: @_ZTVN6Test101EE = linkonce_odr unnamed_addr constant
+// CHECK-TEST10-DAG: @_ZTVN6Test101EE = linkonce_odr unnamed_addr constant
 struct E : A {};
 
 void g(A& a) {
Index: test/CodeGenCXX/vtable-assume-load.cpp
===
--- /dev/null
+++ test/CodeGenCXX/vtable-assume-load.cpp
@@ -0,0 +1,173 @@
+// RUN: %clang_cc1 %s -triple x86_64-apple-darwin10 -emit-llvm -o %t.ll -O1 -disable-llvm-optzns -fms-extensions
+// RUN: %clang_cc1 %s -triple i686-pc-win32 -emit-llvm -o %t.ms.ll -O1 -disable-llvm-optzns -fms-extensions
+
+// RUN: FileCheck --check-prefix=CHECK1 --input-file=%t.ll %s
+// RUN: FileCheck --check-prefix=CHECK2 --input-file=%t.ll %s
+// RUN: FileCheck --check-prefix=CHECK3 --input-file=%t.ll %s
+// RUN: FileCheck --check-prefix=CHECK4 --input-file=%t.ll %s
+// RUN: FileCheck --check-prefix=CHECK-MS --input-file=%t.ms.ll %s
+
+namespace test1 {
+
+struct A {
+  A();
+  virtual void foo();
+};
+
+struct B : A {
+  virtual void foo();
+};
+
+void g(A *a) { a->foo(); }
+
+// CHECK1-LABEL: define void @_ZN5test14fooAEv()
+// CHECK1: call void @_ZN5test11AC1Ev(%"struct.test1::A"* %a)
+// CHECK1: %vtable = load i8**, i8*** %1
+// CHECK1: %cmp.vtables = icmp eq i8** %vtable, getelementptr inbounds ([3 x i8*], [3 x i8*]* @_ZTVN5test11AE, i64 0, i64 2)
+// CHECK1: call void @llvm.assume(i1 %cmp.vtables)
+// CHECK1-LABEL: }
+
+void fooA() {
+  A a;
+  g(&a);
+}
+
+// CHECK1-LABEL: define void @_ZN5test14fooBEv()
+// CHECK1: call void @_ZN5test11BC1Ev(%"struct.test1::B"* %b)
+// CHECK1: %vtable = load i8**, i8*** %1
+// CHECK1: %cmp.vtables = icmp eq i8** %vtable, getelementptr inbounds ([3 x i8*], [3 x i8*]* @_ZTVN5test11BE, i64 0, i64 2)
+// CHECK1: call void @llvm.assume(i1 %cmp.vtables)
+// CHECK1-LABEL: }
+
+void fooB() {
+  B b;
+  g(&b);
+}
+// there should not be any assumes in the ctor that calls base ctor
+// CHECK1-LABEL: define linkonce_odr void @_ZN5test11BC2Ev(%"struct.test1::B"* %this)
+// CHECK1-NOT: @llvm.assume(
+// CHECK1-LABEL: }
+}
+namespace test2 {
+struct A {
+  A();
+  virtual void foo();
+};
+
+struct B {
+  B();
+  virtual void bar();
+};

r245257 - Generating assumption loads of vptr after ctor call

2015-08-17 Thread Piotr Padlewski via cfe-commits
Author: prazek
Date: Mon Aug 17 18:33:49 2015
New Revision: 245257

URL: http://llvm.org/viewvc/llvm-project?rev=245257&view=rev
Log:
Generating assumption loads of vptr after ctor call

Generating call assume(icmp %vtable, %global_vtable) after constructor
call for devirtualization purposes.

For more info go to:
http://lists.llvm.org/pipermail/cfe-dev/2015-July/044227.html

http://reviews.llvm.org/D11859

Added:
cfe/trunk/test/CodeGenCXX/vtable-assume-load.cpp
Modified:
cfe/trunk/lib/CodeGen/CGCXXABI.h
cfe/trunk/lib/CodeGen/CGClass.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.h
cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp
cfe/trunk/test/CodeGen/available-externally-hidden.cpp
cfe/trunk/test/CodeGenCXX/ctor-globalopt.cpp
cfe/trunk/test/CodeGenCXX/template-instantiation.cpp
cfe/trunk/test/CodeGenCXX/thunks.cpp
cfe/trunk/test/CodeGenCXX/virtual-base-ctor.cpp
cfe/trunk/test/CodeGenCXX/vtable-available-externally.cpp

Modified: cfe/trunk/lib/CodeGen/CGCXXABI.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCXXABI.h?rev=245257&r1=245256&r2=245257&view=diff
==
--- cfe/trunk/lib/CodeGen/CGCXXABI.h (original)
+++ cfe/trunk/lib/CodeGen/CGCXXABI.h Mon Aug 17 18:33:49 2015
@@ -346,13 +346,25 @@ public:
   virtual void emitVTableDefinitions(CodeGenVTables &CGVT,
  const CXXRecordDecl *RD) = 0;
 
+  /// Checks if ABI requires extra virtual offset for vtable field.
+  virtual bool
+  isVirtualOffsetNeededForVTableField(CodeGenFunction &CGF,
+  CodeGenFunction::VPtr Vptr) = 0;
+
+  /// Checks if ABI requires to initilize vptrs for given dynamic class.
+  virtual bool doStructorsInitializeVPtrs(const CXXRecordDecl *VTableClass) = 
0;
+
+  /// Get the address point of the vtable for the given base subobject.
+  virtual llvm::Constant *
+  getVTableAddressPoint(BaseSubobject Base,
+const CXXRecordDecl *VTableClass) = 0;
+
   /// Get the address point of the vtable for the given base subobject while
-  /// building a constructor or a destructor. On return, NeedsVirtualOffset
-  /// tells if a virtual base adjustment is needed in order to get the offset
-  /// of the base subobject.
-  virtual llvm::Value *getVTableAddressPointInStructor(
-  CodeGenFunction &CGF, const CXXRecordDecl *RD, BaseSubobject Base,
-  const CXXRecordDecl *NearestVBase, bool &NeedsVirtualOffset) = 0;
+  /// building a constructor or a destructor.
+  virtual llvm::Value *
+  getVTableAddressPointInStructor(CodeGenFunction &CGF, const CXXRecordDecl 
*RD,
+  BaseSubobject Base,
+  const CXXRecordDecl *NearestVBase) = 0;
 
   /// Get the address point of the vtable for the given base subobject while
   /// building a constexpr.

Modified: cfe/trunk/lib/CodeGen/CGClass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGClass.cpp?rev=245257&r1=245256&r2=245257&view=diff
==
--- cfe/trunk/lib/CodeGen/CGClass.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGClass.cpp Mon Aug 17 18:33:49 2015
@@ -1806,12 +1806,14 @@ void CodeGenFunction::EmitCXXConstructor
  bool ForVirtualBase,
  bool Delegating, llvm::Value 
*This,
  const CXXConstructExpr *E) {
+  const CXXRecordDecl *ClassDecl = D->getParent();
+
   // C++11 [class.mfct.non-static]p2:
   //   If a non-static member function of a class X is called for an object 
that
   //   is not of type X, or of a type derived from X, the behavior is 
undefined.
   // FIXME: Provide a source location here.
   EmitTypeCheck(CodeGenFunction::TCK_ConstructorCall, SourceLocation(), This,
-getContext().getRecordType(D->getParent()));
+getContext().getRecordType(ClassDecl));
 
   if (D->isTrivial() && D->isDefaultConstructor()) {
 assert(E->getNumArgs() == 0 && "trivial default ctor with args");
@@ -1827,7 +1829,7 @@ void CodeGenFunction::EmitCXXConstructor
 const Expr *Arg = E->getArg(0);
 QualType SrcTy = Arg->getType();
 llvm::Value *Src = EmitLValue(Arg).getAddress();
-QualType DestTy = getContext().getTypeDeclType(D->getParent());
+QualType DestTy = getContext().getTypeDeclType(ClassDecl);
 EmitAggregateCopyCtor(This, Src, DestTy, SrcTy);
 return;
   }
@@ -1850,6 +1852,41 @@ void CodeGenFunction::EmitCXXConstructor
   const CGFunctionInfo &Info =
   CGM.getTypes().arrangeCXXConstructorCall(Args, D, Type, ExtraArgs);
   EmitCall(Info, Callee, ReturnValueSlot(), Args, D);
+
+  // Generate vtable assumptions if we're constructing a complete object
+  // with a vtable.  We don't do this for base subobjec

r245259 - Doxygen: add build option to use svg instead of png files for graphs

2015-08-17 Thread Hans Wennborg via cfe-commits
Author: hans
Date: Mon Aug 17 18:38:56 2015
New Revision: 245259

URL: http://llvm.org/viewvc/llvm-project?rev=245259&view=rev
Log:
Doxygen: add build option to use svg instead of png files for graphs

Differential Revision: http://reviews.llvm.org/D11994

Modified:
cfe/trunk/docs/CMakeLists.txt
cfe/trunk/docs/Makefile
cfe/trunk/docs/doxygen.cfg.in

Modified: cfe/trunk/docs/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/CMakeLists.txt?rev=245259&r1=245258&r2=245259&view=diff
==
--- cfe/trunk/docs/CMakeLists.txt (original)
+++ cfe/trunk/docs/CMakeLists.txt Mon Aug 17 18:38:56 2015
@@ -47,6 +47,14 @@ if (LLVM_ENABLE_DOXYGEN)
 set(clang_doxygen_qhp_cust_filter_attrs "")
   endif()
 
+  option(LLVM_DOXYGEN_SVG
+"Use svg instead of png files for doxygen graphs." OFF)
+  if (LLVM_DOXYGEN_SVG)
+set(DOT_IMAGE_FORMAT "svg")
+  else()
+set(DOT_IMAGE_FORMAT "png")
+  endif()
+
   configure_file(${CMAKE_CURRENT_SOURCE_DIR}/doxygen.cfg.in
 ${CMAKE_CURRENT_BINARY_DIR}/doxygen.cfg @ONLY)
 
@@ -64,6 +72,7 @@ if (LLVM_ENABLE_DOXYGEN)
   set(clang_doxygen_qhelpgenerator_path)
   set(clang_doxygen_qhp_cust_filter_name)
   set(clang_doxygen_qhp_cust_filter_attrs)
+  set(DOT_IMAGE_FORMAT)
 
   add_custom_target(doxygen-clang
 COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/doxygen.cfg

Modified: cfe/trunk/docs/Makefile
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/Makefile?rev=245259&r1=245258&r2=245259&view=diff
==
--- cfe/trunk/docs/Makefile (original)
+++ cfe/trunk/docs/Makefile Mon Aug 17 18:38:56 2015
@@ -30,6 +30,7 @@ $(PROJ_OBJ_DIR)/doxygen.cfg: doxygen.cfg
  -e 's/@enable_server_based_search@/NO/g' \
  -e 's/@extra_search_mappings@//g' \
  -e 's/@searchengine_url@//g' \
+ -e 's/@DOT_IMAGE_FORMAT@/png/g' \
  > $@
 endif
 

Modified: cfe/trunk/docs/doxygen.cfg.in
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/doxygen.cfg.in?rev=245259&r1=245258&r2=245259&view=diff
==
--- cfe/trunk/docs/doxygen.cfg.in (original)
+++ cfe/trunk/docs/doxygen.cfg.in Mon Aug 17 18:38:56 2015
@@ -2205,7 +2205,7 @@ DIRECTORY_GRAPH= YES
 # The default value is: png.
 # This tag requires that the tag HAVE_DOT is set to YES.
 
-DOT_IMAGE_FORMAT   = png
+DOT_IMAGE_FORMAT   = @DOT_IMAGE_FORMAT@
 
 # If DOT_IMAGE_FORMAT is set to svg, then this option can be set to YES to
 # enable generation of interactive SVG images that allow zooming and panning.


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


Re: [PATCH] D10431: PR21174 - clang only searches current working directory for precompiled include file

2015-08-17 Thread Richard Smith via cfe-commits
On Mon, Aug 17, 2015 at 9:24 AM, Nico Weber  wrote:

> thakis added a subscriber: thakis.
>
> 
> Comment at: lib/Driver/Tools.cpp:398
> @@ +397,3 @@
> +  FoundPTH = !UsePCH;
> +}
> +  }
> 
> kimgr wrote:
> > kimgr wrote:
> > > kimgr wrote:
> > > > kimgr wrote:
> > > > > Add a `break;` here so we don't continue searching after a valid
> path has been found
> > > > The GCC docs here [1] say:
> > > >
> > > > If not found there, it is searched for in the remainder of the
> #include "..." search chain as normal.
> > > >
> > > > I can't tell if the quotes are significant and if they mean only -I
> is searched. I don't have a GCC environment currently to test with.
> > > >
> > > > [1]
> https://gcc.gnu.org/onlinedocs/gcc-4.9.3/gcc/Preprocessor-Options.html#index-nostdinc_002b_002b-1026
> > > I found a FreeBSD machine and set up GCC. I had to adjust the repro
> case to use `truss` instead of `strace`, so I hope I didn't mess anything
> up.
> > >
> > > I removed the rule generating the .gch file, so GCC would have to keep
> searching and it appears to be following the entire include search path,
> including system paths. Trace below:
> > >
> > > ...
> > > 30860: stat("./precompiled.header.gch",0x7fffe540) ERR#2 'No such
> file or directory'
> > > 30860: open("./precompiled.header",O_NOCTTY,0666) ERR#2 'No such file
> or directory'
> > > 30860: stat("./build/include/precompiled.header.gch",0x7fffe540)
> ERR#2 'No such file or directory'
> > > 30860: open("./build/include/precompiled.header",O_NOCTTY,0666) ERR#2
> 'No such file or directory'
> > > 30860: stat("./include/precompiled.header.gch",0x7fffe540) ERR#2
> 'No such file or directory'
> > > 30860: open("./include/precompiled.header",O_NOCTTY,0666) ERR#2 'No
> such file or directory'
> > > 30860: lstat("/usr",{ mode=drwxr-xr-x ,inode=9,size=16,blksize=4096 })
> = 0 (0x0)
> > > 30860: lstat("/usr/local",{ mode=drwxr-xr-x
> ,inode=115,size=16,blksize=4096 }) = 0 (0x0)
> > > 30860: lstat("/usr/local/lib",{ mode=drwxr-xr-x
> ,inode=16476,size=1318,blksize=84480 }) = 0 (0x0)
> > > 30860: lstat("/usr/local/lib/gcc48",{ mode=drwxr-xr-x
> ,inode=24335,size=66,blksize=131072 }) = 0 (0x0)
> > > 30860: lstat("/usr/local/lib/gcc48/include",{ mode=drwxr-xr-x
> ,inode=24336,size=3,blksize=131072 }) = 0 (0x0)
> > > 30860: lstat("/usr/local/lib/gcc48/include/c++",{ mode=drwxr-xr-x
> ,inode=24337,size=98,blksize=131072 }) = 0 (0x0)
> > > 30860:
> lstat("/usr/local/lib/gcc48/include/c++/precompiled.header",0x7fffd3d8)
> ERR#2 'No such file or directory'
> > > 30860:
> stat("/usr/local/lib/gcc48/include/c++/precompiled.header.gch",0x7fffe540)
> ERR#2 'No such file or directory'
> > > 30860:
> open("/usr/local/lib/gcc48/include/c++/precompiled.header",O_NOCTTY,0666)
> ERR#2 'No such file or directory'
> > > 30860: lstat("/usr",{ mode=drwxr-xr-x ,inode=9,size=16,blksize=4096 })
> = 0 (0x0)
> > > 30860: lstat("/usr/local",{ mode=drwxr-xr-x
> ,inode=115,size=16,blksize=4096 }) = 0 (0x0)
> > > 30860: lstat("/usr/local/lib",{ mode=drwxr-xr-x
> ,inode=16476,size=1318,blksize=84480 }) = 0 (0x0)
> > > 30860: lstat("/usr/local/lib/gcc48",{ mode=drwxr-xr-x
> ,inode=24335,size=66,blksize=131072 }) = 0 (0x0)
> > > 30860: lstat("/usr/local/lib/gcc48/include",{ mode=drwxr-xr-x
> ,inode=24336,size=3,blksize=131072 }) = 0 (0x0)
> > > 30860: lstat("/usr/local/lib/gcc48/include/c++",{ mode=drwxr-xr-x
> ,inode=24337,size=98,blksize=131072 }) = 0 (0x0)
> > > 30860:
> lstat("/usr/local/lib/gcc48/include/c++/x86_64-portbld-freebsd10.1",{
> mode=drwxr-xr-x ,inode=21305,size=4,blksize=131072 }) = 0 (0x0)
> > > 30860:
> lstat("/usr/local/lib/gcc48/include/c++/x86_64-portbld-freebsd10.1/precompiled.header",0x7fffd3d8)
> ERR#2 'No such file or directory'
> > > 30860:
> stat("/usr/local/lib/gcc48/include/c++//x86_64-portbld-freebsd10.1/precompiled.header.gch",0x7fffe540)
> ERR#2 'No such file or directory'
> > > 30860:
> open("/usr/local/lib/gcc48/include/c++//x86_64-portbld-freebsd10.1/precompiled.header",O_NOCTTY,0666)
> ERR#2 'No such file or directory'
> > > 30860: lstat("/usr",{ mode=drwxr-xr-x ,inode=9,size=16,blksize=4096 })
> = 0 (0x0)
> > > 30860: lstat("/usr/local",{ mode=drwxr-xr-x
> ,inode=115,size=16,blksize=4096 }) = 0 (0x0)
> > > 30860: lstat("/usr/local/lib",{ mode=drwxr-xr-x
> ,inode=16476,size=1318,blksize=84480 }) = 0 (0x0)
> > > 30860: lstat("/usr/local/lib/gcc48",{ mode=drwxr-xr-x
> ,inode=24335,size=66,blksize=131072 }) = 0 (0x0)
> > > 30860: lstat("/usr/local/lib/gcc48/include",{ mode=drwxr-xr-x
> ,inode=24336,size=3,blksize=131072 }) = 0 (0x0)
> > > 30860: lstat("/usr/local/lib/gcc48/include/c++",{ mode=drwxr-xr-x
> ,inode=24337,size=98,blksize=131072 }) = 0 (0x0)
> > > 30860: lstat("/usr/local/lib/gcc48/include/c++/backward",{
> mode=drwxr-xr-x ,inode=21290,size=10,blksize=131072 }) = 0 (0x0)
> > > 30860:
> lstat("/usr/local/lib/gcc48/include/c++/backward/precompiled.header",0x7fffd3d8)

RE: [PATCH] D9924: Ignore report when the argument to malloc is assigned known value

2015-08-17 Thread Aditya K via cfe-commits



> Date: Mon, 17 Aug 2015 21:39:32 +
> To: hiradi...@msn.com; jordan_r...@apple.com; kreme...@apple.com; 
> daniel.marjam...@evidente.se; mclow.li...@gmail.com; adasg...@codeaurora.org; 
> zaks.a...@gmail.com
> From: zaks.a...@gmail.com
> CC: cfe-commits@lists.llvm.org
> Subject: Re: [PATCH] D9924: Ignore report when the argument to malloc is 
> assigned known value
>
> zaks.anna added a comment.
>
>> Maybe, I should add a check that `a, b, n' are positive.
>
>> So, in this case static analyzer can choose to be strict and reject false 
>> positives.
>
>
> What would this buy us? Does the checker warn on underflow?

I mean, checking `a,b,n' are positive would ensure that there is no overflow in 
this case and then we would not emit report.
The checker does not warn on underflow, so we can ignore checking `a,b,n' are 
positive, if it is too complicated.

>
>> If a' might overflow, then in this case we can emit warning stating that the 
>> overflow is caused because a' might overflow.
>
>
> I see your point now! I think we should improve the diagnostic that is 
> produced in this case!

I'm trying to implement that.
Thanks,
-Aditya

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


RE: Second Lit tests C++11 compatibility patch: using preprocessor to filter expected-error

2015-08-17 Thread Li, Charles via cfe-commits
Hi Richard and Justin,



> What's the upside to this approach? AFAICT it makes the test harder to read 
> and errors less informative due to pointing at the wrong lines, but (at least 
> in switch-1.c) it doesn't actually reduce any code duplication or anything 
> like that. What is this gaining us apart from not having to create one more 
> file?

Thank you Justin.
Our original intention was to get the Lit tests to run at any default C++ 
dialect.

We first discovered that FileCheck does not respect #ifdef since it does not 
know about pre-defined macros.
So we figured if we preprocess the source first, the preprocessor will filter 
the #ifdef sections and the output will feed nicely into FileCheck.
The upside is the test can run at the default dialect in addition to explicitly 
specified dialect.
The downside is, as you mentioned, the errors diagnostics would point to the 
wrong lines.


> The only thing novel about this approach is using the preprocessor to achieve 
> it. -verify *does* respect #ifdef, and we have a lot of tests that rely on 
> that.

Thank you Richard.
We erroneously assumed that “// CHECK:” and “// expected-error” work the same 
way.
But now we realized that assumption was wrong.

In light this discussion, I have removed the preprocessing to temporary step 
for all tests.
The attached patch (Lit_24.patch) revised 2 test fixes relative to the previous 
patch (Lit_22.patch)

  test/Analysis/temp-obj-dtors-cfg-output.cpp
This test uses FileCheck to check for CFG dump.
Instead of using #ifdef for the dialect specific “// CHECK:” lines,
I have created 2 check-prefixes “CXX11” and “CXX98”.
The pre-process step have been removed.

  test/Sema/switch-1.c
This test uses –verify to check for integer overflows diagnostics.
The pre-process step have been removed.
The #ifdef is kept since it works with -verify.


Please let me know how you feel about this patch.

Sincerely,
Charles


From: meta...@gmail.com [mailto:meta...@gmail.com] On Behalf Of Richard Smith
Sent: Monday, August 17, 2015 1:07 PM
To: Li, Charles
Cc: cfe-commits@lists.llvm.org
Subject: Re: Second Lit tests C++11 compatibility patch: using preprocessor to 
filter expected-error

On Mon, Aug 17, 2015 at 9:56 AM, Li, Charles via cfe-commits 
mailto:cfe-commits@lists.llvm.org>> wrote:
Hi Clang developers,

We here at Sony are continuing to update the Lit tests for C++ dialects 
compatibility.
Attached is the second patch. (As a reference, here is the link to the 
discussion on the previous Lit patch. 
http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20150727/134667.html)
In this second patch, there is 1 complicated change and 3 simple changes.

Here is the complicated change first.

test/Sema/switch-1.c
  This test verifies the diagnostics for integer overflows.
  Due to C++11’s more strict requirements on constant-expressions in 5.19p2 
[expr.const],
  The diagnostics have changed from “overflow in expression” to “not a constant 
expression”.

  Usually we would create a C++11 version of the switch-1.c file.
  But here we propose a novel approach to “#ifdef” the expected diagnostics. 
(We hope to use this approach for all similar cases in the future.)
  Normally ‘// expected-error’ does not honor any ‘#ifdef’.
  But if we first preprocess the source into a temporary file, only the valid 
‘#ifdef’ sections remain.
  We then run the preprocessed file at the desired dialect.
  The main downside to this approach is If the test fails, the errors are 
reported on the temporary file, not on the original file, and the line numbers 
of these two files  do not match

The only thing novel about this approach is using the preprocessor to achieve 
it. -verify *does* respect #ifdef, and we have a lot of tests that rely on that.

Here are the simple changes.

test/Analysis/temp-obj-dtors-cfg-output.cpp
  This test verifies CFG dump for temporary destructors
  C++11 no longer has the following implicit cast.
(ImplicitCastExpr, NoOp, const struct D)
  We modified the test using the #ifdef approach to have the preprocessor 
generate the desired CHECK lines.

test/CodeCompletion/ordinary-name.cpp
  This test verifies for code completion patterns.
  Since C++11 has more keywords than C++98,
  We made this test to be C++98 specific, and create a separate C++11 version.

test/CodeCompletion/ordinary-name-cxx11.cpp
  This is the C++11 specific version of the code completion.
  This test added patterns for the following keywords:
char16, char32, noexcept, nullptr, sizeof...,
auto, decltype, char16_t, char32_t

test/Sema/thread-specifier.c
  Tests for __thread specifier at various C++ dialects
  We made the default RUN line explicit to be at –std=c++98


If there is anything that seems confusing to you, please let me know.
I would be more than happy to expand on the reasons for the these changes.


Thanks,
Charles

___
cfe-commits mailing list
cfe-commits@lists.llv

Re: r239883 - Update the intel intrinsic headers to use the target attribute support.

2015-08-17 Thread Justin Bogner via cfe-commits
Eric Christopher  writes:
> There is nothing broken about not having the include guards there, it's just
> not helpful. I'm working on the infrastructure for an error if you call a
> function from within an incompatible routine at the moment (without
> duplicating a lot of code it's actually a bit annoying), but there's nothing
> actually wrong with the code. It's just the same as basically saying asm
> ("invalid_instruction") in a random function.
>
> Any configure script that was depending on error conditions from this is
> already broken by gcc as well, and likely icc.

Well, I'm pretty sure gcc will warn/error about using invalid builtins,
so the configure scripts might work for it, I'm not really sure. In any
case, once you get the incompatible caller checking infrastructure
working we'll warn on misusing these builtins too, so this will behave
as well or better than gcc for this stuff.

> -eric
>
> On Mon, Aug 17, 2015 at 3:04 PM Dimitry Andric  wrote:
>
> [Re-sending, used the old cfe-commits address by accident]
>
> Where is the other thread?  This problem still exists, for both trunk and
> the upcoming 3.7.0 RC3.  I'll try to submit a patch tomorrow to partially
> restore the include guards, so we won't have a broken release.
>
> -Dimitry
>
> On 03 Aug 2015, at 18:48, Eric Christopher  wrote:
>
> Where are the negative test cases? Diagnosing uses of these
> functions
> when they aren't valid is really important - it's a pretty serious
> regression if we don't.
>
> Two threads, I'm going to take this in the other thread. :)
>
> -eric
>
> ___
> cfe-commits mailing list
> cfe-comm...@cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r245260 - Revert r245257 "Generating assumption loads of vptr after ctor call"

2015-08-17 Thread Hans Wennborg via cfe-commits
Author: hans
Date: Mon Aug 17 19:17:58 2015
New Revision: 245260

URL: http://llvm.org/viewvc/llvm-project?rev=245260&view=rev
Log:
Revert r245257 "Generating assumption loads of vptr after ctor call"

It caused PR24479

Removed:
cfe/trunk/test/CodeGenCXX/vtable-assume-load.cpp
Modified:
cfe/trunk/lib/CodeGen/CGCXXABI.h
cfe/trunk/lib/CodeGen/CGClass.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.h
cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp
cfe/trunk/test/CodeGen/available-externally-hidden.cpp
cfe/trunk/test/CodeGenCXX/ctor-globalopt.cpp
cfe/trunk/test/CodeGenCXX/template-instantiation.cpp
cfe/trunk/test/CodeGenCXX/thunks.cpp
cfe/trunk/test/CodeGenCXX/virtual-base-ctor.cpp
cfe/trunk/test/CodeGenCXX/vtable-available-externally.cpp

Modified: cfe/trunk/lib/CodeGen/CGCXXABI.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCXXABI.h?rev=245260&r1=245259&r2=245260&view=diff
==
--- cfe/trunk/lib/CodeGen/CGCXXABI.h (original)
+++ cfe/trunk/lib/CodeGen/CGCXXABI.h Mon Aug 17 19:17:58 2015
@@ -346,25 +346,13 @@ public:
   virtual void emitVTableDefinitions(CodeGenVTables &CGVT,
  const CXXRecordDecl *RD) = 0;
 
-  /// Checks if ABI requires extra virtual offset for vtable field.
-  virtual bool
-  isVirtualOffsetNeededForVTableField(CodeGenFunction &CGF,
-  CodeGenFunction::VPtr Vptr) = 0;
-
-  /// Checks if ABI requires to initilize vptrs for given dynamic class.
-  virtual bool doStructorsInitializeVPtrs(const CXXRecordDecl *VTableClass) = 
0;
-
-  /// Get the address point of the vtable for the given base subobject.
-  virtual llvm::Constant *
-  getVTableAddressPoint(BaseSubobject Base,
-const CXXRecordDecl *VTableClass) = 0;
-
   /// Get the address point of the vtable for the given base subobject while
-  /// building a constructor or a destructor.
-  virtual llvm::Value *
-  getVTableAddressPointInStructor(CodeGenFunction &CGF, const CXXRecordDecl 
*RD,
-  BaseSubobject Base,
-  const CXXRecordDecl *NearestVBase) = 0;
+  /// building a constructor or a destructor. On return, NeedsVirtualOffset
+  /// tells if a virtual base adjustment is needed in order to get the offset
+  /// of the base subobject.
+  virtual llvm::Value *getVTableAddressPointInStructor(
+  CodeGenFunction &CGF, const CXXRecordDecl *RD, BaseSubobject Base,
+  const CXXRecordDecl *NearestVBase, bool &NeedsVirtualOffset) = 0;
 
   /// Get the address point of the vtable for the given base subobject while
   /// building a constexpr.

Modified: cfe/trunk/lib/CodeGen/CGClass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGClass.cpp?rev=245260&r1=245259&r2=245260&view=diff
==
--- cfe/trunk/lib/CodeGen/CGClass.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGClass.cpp Mon Aug 17 19:17:58 2015
@@ -1806,14 +1806,12 @@ void CodeGenFunction::EmitCXXConstructor
  bool ForVirtualBase,
  bool Delegating, llvm::Value 
*This,
  const CXXConstructExpr *E) {
-  const CXXRecordDecl *ClassDecl = D->getParent();
-
   // C++11 [class.mfct.non-static]p2:
   //   If a non-static member function of a class X is called for an object 
that
   //   is not of type X, or of a type derived from X, the behavior is 
undefined.
   // FIXME: Provide a source location here.
   EmitTypeCheck(CodeGenFunction::TCK_ConstructorCall, SourceLocation(), This,
-getContext().getRecordType(ClassDecl));
+getContext().getRecordType(D->getParent()));
 
   if (D->isTrivial() && D->isDefaultConstructor()) {
 assert(E->getNumArgs() == 0 && "trivial default ctor with args");
@@ -1829,7 +1827,7 @@ void CodeGenFunction::EmitCXXConstructor
 const Expr *Arg = E->getArg(0);
 QualType SrcTy = Arg->getType();
 llvm::Value *Src = EmitLValue(Arg).getAddress();
-QualType DestTy = getContext().getTypeDeclType(ClassDecl);
+QualType DestTy = getContext().getTypeDeclType(D->getParent());
 EmitAggregateCopyCtor(This, Src, DestTy, SrcTy);
 return;
   }
@@ -1852,41 +1850,6 @@ void CodeGenFunction::EmitCXXConstructor
   const CGFunctionInfo &Info =
   CGM.getTypes().arrangeCXXConstructorCall(Args, D, Type, ExtraArgs);
   EmitCall(Info, Callee, ReturnValueSlot(), Args, D);
-
-  // Generate vtable assumptions if we're constructing a complete object
-  // with a vtable.  We don't do this for base subobjects for two reasons:
-  // first, it's incorrect for classes with virtual bases, and second, we're
-  // about to overwrite the vptrs anyway.
-  if (CGM.getCodeGenOpts().OptimizationLevel >

Re: [PATCH] D12036: We shouldn't need to pass -fno-strict-aliasing when building clang with clang.

2015-08-17 Thread Justin Bogner via cfe-commits
Chris Bieneman  writes:
> beanz updated this revision to Diff 32349.
> beanz added a comment.
>
> - Adapting to r245255 which exposes a variable in autoconf for which
> compiler you are building with.
> - Updated the CMake to be more CMake-y
>
> Note: This has been tested by running a check on a stage2 clang built
> with asan and ubsan.

LGTM.

>
> http://reviews.llvm.org/D12036
>
> Files:
>   CMakeLists.txt
>   Makefile
>
> Index: Makefile
> ===
> --- Makefile
> +++ Makefile
> @@ -67,8 +67,11 @@
>  #   http://gcc.gnu.org/PR41874
>  #   http://gcc.gnu.org/PR41838
>  #
> -# We can revisit this when LLVM/Clang support it.
> +# We don't need to do this if the host compiler is clang.
> +ifeq ($(CXX_COMPILER), "clang")
>  CXX.Flags += -fno-strict-aliasing
> +endif
> +
>  
>  # Set up Clang's tblgen.
>  ifndef CLANG_TBLGEN
> Index: CMakeLists.txt
> ===
> --- CMakeLists.txt
> +++ CMakeLists.txt
> @@ -253,7 +253,10 @@
>  
>  # Add appropriate flags for GCC
>  if (LLVM_COMPILER_IS_GCC_COMPATIBLE)
> -  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-common -Woverloaded-virtual 
> -fno-strict-aliasing")
> +  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-common -Woverloaded-virtual")
> +  if (NOT "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
> +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-strict-aliasing")
> +  endif ()
>  
># Enable -pedantic for Clang even if it's not enabled for LLVM.
>if (NOT LLVM_ENABLE_PEDANTIC)
>
>
> Index: Makefile
> ===
> --- Makefile
> +++ Makefile
> @@ -67,8 +67,11 @@
>  #   http://gcc.gnu.org/PR41874
>  #   http://gcc.gnu.org/PR41838
>  #
> -# We can revisit this when LLVM/Clang support it.
> +# We don't need to do this if the host compiler is clang.
> +ifeq ($(CXX_COMPILER), "clang")
>  CXX.Flags += -fno-strict-aliasing
> +endif
> +
>  
>  # Set up Clang's tblgen.
>  ifndef CLANG_TBLGEN
> Index: CMakeLists.txt
> ===
> --- CMakeLists.txt
> +++ CMakeLists.txt
> @@ -253,7 +253,10 @@
>  
>  # Add appropriate flags for GCC
>  if (LLVM_COMPILER_IS_GCC_COMPATIBLE)
> -  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-common -Woverloaded-virtual 
> -fno-strict-aliasing")
> +  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-common -Woverloaded-virtual")
> +  if (NOT "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
> +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-strict-aliasing")
> +  endif ()
>  
># Enable -pedantic for Clang even if it's not enabled for LLVM.
>if (NOT LLVM_ENABLE_PEDANTIC)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r245257 - Generating assumption loads of vptr after ctor call

2015-08-17 Thread Hans Wennborg via cfe-commits
I reverted this in r245260 as it caused
https://llvm.org/bugs/show_bug.cgi?id=24479

 - Hans

On Mon, Aug 17, 2015 at 4:34 PM, Piotr Padlewski via cfe-commits
 wrote:
> Author: prazek
> Date: Mon Aug 17 18:33:49 2015
> New Revision: 245257
>
> URL: http://llvm.org/viewvc/llvm-project?rev=245257&view=rev
> Log:
> Generating assumption loads of vptr after ctor call
>
> Generating call assume(icmp %vtable, %global_vtable) after constructor
> call for devirtualization purposes.
>
> For more info go to:
> http://lists.llvm.org/pipermail/cfe-dev/2015-July/044227.html
>
> http://reviews.llvm.org/D11859
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: Second Lit tests C++11 compatibility patch: using preprocessor to filter expected-error

2015-08-17 Thread Richard Smith via cfe-commits
On Mon, Aug 17, 2015 at 5:15 PM, Li, Charles via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Hi Richard and Justin,
>
>
>
>
>
> > What's the upside to this approach? AFAICT it makes the test harder to
> read and errors less informative due to pointing at the wrong lines, but
> (at least in switch-1.c) it doesn't actually reduce any code duplication or
> anything like that. What is this gaining us apart from not having to create
> one more file?
>
>
>
> Thank you Justin.
>
> Our original intention was to get the Lit tests to run at any default C++
> dialect.
>
>
>
> We first discovered that FileCheck does not respect #ifdef since it does
> not know about pre-defined macros.
>
> So we figured if we preprocess the source first, the preprocessor will
> filter the #ifdef sections and the output will feed nicely into FileCheck.
>
> The upside is the test can run at the default dialect in addition to
> explicitly specified dialect.
>
> The downside is, as you mentioned, the errors diagnostics would point to
> the wrong lines.
>
>
>
>
>
> > The only thing novel about this approach is using the preprocessor to
> achieve it. -verify *does* respect #ifdef, and we have a lot of tests that
> rely on that.
>
>
>
> Thank you Richard.
>
> We erroneously assumed that “// CHECK:” and “// expected-error” work the
> same way.
>
> But now we realized that assumption was wrong.
>
>
>
> In light this discussion, I have removed the preprocessing to temporary
> step for all tests.
>
> The attached patch (Lit_24.patch) revised 2 test fixes relative to the
> previous patch (Lit_22.patch)
>
>
>
>   test/Analysis/temp-obj-dtors-cfg-output.cpp
>
> This test uses FileCheck to check for CFG dump.
>
> Instead of using #ifdef for the dialect specific “// CHECK:” lines,
>
> I have created 2 check-prefixes “CXX11” and “CXX98”.
>
> The pre-process step have been removed.
>
>
>
>   test/Sema/switch-1.c
>
> This test uses –verify to check for integer overflows diagnostics.
>
> The pre-process step have been removed.
>
> The #ifdef is kept since it works with -verify.
>

Instead of duplicating the code, you can do this:

case blah:
#if __cplusplus >= 201103L
// expected-error@-2 {{error 2 lines above}}
#else
// expected-error@-4 {{error 4 lines above}}
#endif


> Please let me know how you feel about this patch.
>
>
>
> Sincerely,
>
> Charles
>
>
>
>
>
> *From:* meta...@gmail.com [mailto:meta...@gmail.com] *On Behalf Of *Richard
> Smith
> *Sent:* Monday, August 17, 2015 1:07 PM
> *To:* Li, Charles
> *Cc:* cfe-commits@lists.llvm.org
> *Subject:* Re: Second Lit tests C++11 compatibility patch: using
> preprocessor to filter expected-error
>
>
>
> On Mon, Aug 17, 2015 at 9:56 AM, Li, Charles via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
> Hi Clang developers,
>
>
>
> We here at Sony are continuing to update the Lit tests for C++ dialects
> compatibility.
>
> Attached is the second patch. (As a reference, here is the link to the
> discussion on the previous Lit patch.
> http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20150727/134667.html
> )
>
> In this second patch, there is 1 complicated change and 3 simple changes.
>
>
>
> Here is the complicated change first.
>
>
>
> test/Sema/switch-1.c
>
>   This test verifies the diagnostics for integer overflows.
>
>   Due to C++11’s more strict requirements on constant-expressions in
> 5.19p2 [expr.const],
>
>   The diagnostics have changed from “overflow in expression” to “not a
> constant expression”.
>
>
>
>   Usually we would create a C++11 version of the switch-1.c file.
>
>   But here we propose a novel approach to “#ifdef” the expected
> diagnostics. (We hope to use this approach for all similar cases in the
> future.)
>
>   Normally ‘// expected-error’ does not honor any ‘#ifdef’.
>
>   But if we first preprocess the source into a temporary file, only the
> valid ‘#ifdef’ sections remain.
>
>   We then run the preprocessed file at the desired dialect.
>
>   The main downside to this approach is If the test fails, the errors are
> reported on the temporary file, not on the original file, and the line
> numbers of these two files  do not match
>
>
>
> The only thing novel about this approach is using the preprocessor to
> achieve it. -verify *does* respect #ifdef, and we have a lot of tests that
> rely on that.
>
>
>
> Here are the simple changes.
>
>
>
> test/Analysis/temp-obj-dtors-cfg-output.cpp
>
>   This test verifies CFG dump for temporary destructors
>
>   C++11 no longer has the following implicit cast.
>
> (ImplicitCastExpr, NoOp, const struct D)
>
>   We modified the test using the #ifdef approach to have the preprocessor
> generate the desired CHECK lines.
>
>
>
> test/CodeCompletion/ordinary-name.cpp
>
>   This test verifies for code completion patterns.
>
>   Since C++11 has more keywords than C++98,
>
>   We made this test to be C++98 specific, and create a separate C++11
> version.
>
>
>
> test/CodeCompletion/ordinary-name-cx

Re: [PATCH] D12036: We shouldn't need to pass -fno-strict-aliasing when building clang with clang.

2015-08-17 Thread Eric Christopher via cfe-commits
echristo accepted this revision.
echristo added a comment.
This revision is now accepted and ready to land.

Sure I guess. I'm still not sure why we can't do this in the configure side of 
things, but I don't really care that much for now.


http://reviews.llvm.org/D12036



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


RE: Second Lit tests C++11 compatibility patch: using preprocessor to filter expected-error

2015-08-17 Thread Li, Charles via cfe-commits
Hi Richard,

I have modified the “expected-“ lines as you requested.

Cheers,
Charles


From: meta...@gmail.com [mailto:meta...@gmail.com] On Behalf Of Richard Smith
Sent: Monday, August 17, 2015 5:41 PM
To: Li, Charles
Cc: Justin Bogner; cfe-commits@lists.llvm.org
Subject: Re: Second Lit tests C++11 compatibility patch: using preprocessor to 
filter expected-error

On Mon, Aug 17, 2015 at 5:15 PM, Li, Charles via cfe-commits 
mailto:cfe-commits@lists.llvm.org>> wrote:
Hi Richard and Justin,



> What's the upside to this approach? AFAICT it makes the test harder to read 
> and errors less informative due to pointing at the wrong lines, but (at least 
> in switch-1.c) it doesn't actually reduce any code duplication or anything 
> like that. What is this gaining us apart from not having to create one more 
> file?

Thank you Justin.
Our original intention was to get the Lit tests to run at any default C++ 
dialect.

We first discovered that FileCheck does not respect #ifdef since it does not 
know about pre-defined macros.
So we figured if we preprocess the source first, the preprocessor will filter 
the #ifdef sections and the output will feed nicely into FileCheck.
The upside is the test can run at the default dialect in addition to explicitly 
specified dialect.
The downside is, as you mentioned, the errors diagnostics would point to the 
wrong lines.


> The only thing novel about this approach is using the preprocessor to achieve 
> it. -verify *does* respect #ifdef, and we have a lot of tests that rely on 
> that.

Thank you Richard.
We erroneously assumed that “// CHECK:” and “// expected-error” work the same 
way.
But now we realized that assumption was wrong.

In light this discussion, I have removed the preprocessing to temporary step 
for all tests.
The attached patch (Lit_24.patch) revised 2 test fixes relative to the previous 
patch (Lit_22.patch)

  test/Analysis/temp-obj-dtors-cfg-output.cpp
This test uses FileCheck to check for CFG dump.
Instead of using #ifdef for the dialect specific “// CHECK:” lines,
I have created 2 check-prefixes “CXX11” and “CXX98”.
The pre-process step have been removed.

  test/Sema/switch-1.c
This test uses –verify to check for integer overflows diagnostics.
The pre-process step have been removed.
The #ifdef is kept since it works with -verify.

Instead of duplicating the code, you can do this:

case blah:
#if __cplusplus >= 201103L
// expected-error@-2 {{error 2 lines above}}
#else
// expected-error@-4 {{error 4 lines above}}
#endif

Please let me know how you feel about this patch.

Sincerely,
Charles


From: meta...@gmail.com 
[mailto:meta...@gmail.com] On Behalf Of Richard Smith
Sent: Monday, August 17, 2015 1:07 PM
To: Li, Charles
Cc: cfe-commits@lists.llvm.org
Subject: Re: Second Lit tests C++11 compatibility patch: using preprocessor to 
filter expected-error

On Mon, Aug 17, 2015 at 9:56 AM, Li, Charles via cfe-commits 
mailto:cfe-commits@lists.llvm.org>> wrote:
Hi Clang developers,

We here at Sony are continuing to update the Lit tests for C++ dialects 
compatibility.
Attached is the second patch. (As a reference, here is the link to the 
discussion on the previous Lit patch. 
http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20150727/134667.html)
In this second patch, there is 1 complicated change and 3 simple changes.

Here is the complicated change first.

test/Sema/switch-1.c
  This test verifies the diagnostics for integer overflows.
  Due to C++11’s more strict requirements on constant-expressions in 5.19p2 
[expr.const],
  The diagnostics have changed from “overflow in expression” to “not a constant 
expression”.

  Usually we would create a C++11 version of the switch-1.c file.
  But here we propose a novel approach to “#ifdef” the expected diagnostics. 
(We hope to use this approach for all similar cases in the future.)
  Normally ‘// expected-error’ does not honor any ‘#ifdef’.
  But if we first preprocess the source into a temporary file, only the valid 
‘#ifdef’ sections remain.
  We then run the preprocessed file at the desired dialect.
  The main downside to this approach is If the test fails, the errors are 
reported on the temporary file, not on the original file, and the line numbers 
of these two files  do not match

The only thing novel about this approach is using the preprocessor to achieve 
it. -verify *does* respect #ifdef, and we have a lot of tests that rely on that.

Here are the simple changes.

test/Analysis/temp-obj-dtors-cfg-output.cpp
  This test verifies CFG dump for temporary destructors
  C++11 no longer has the following implicit cast.
(ImplicitCastExpr, NoOp, const struct D)
  We modified the test using the #ifdef approach to have the preprocessor 
generate the desired CHECK lines.

test/CodeCompletion/ordinary-name.cpp
  This test verifies for code completion patterns.
  Since C++11 has more k

Re: [PATCH] D11944: Nativize filename in FileManager::getFile().

2015-08-17 Thread Alex Rosenberg via cfe-commits
alexr added a subscriber: alexr.
alexr added a comment.

Just to remind everybody, different OSes handle Unicode differently as well. 
Think of it as case insensitivity for the different Unicode ways of encoding 
the same glyph. For example U+00DC (LATIN CAPITAL LETTER U WITH DIAERESIS) vs 
U+0055 (LATIN CAPITAL LETTER U) and U+0308 (COMBINING DIAERESIS). Apple's HFS+ 
file system always decomposes file names to ensure consistent matching. Other 
OSes, not so much.


http://reviews.llvm.org/D11944



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


Re: [PATCH] D11859: Generating vptr assume loads

2015-08-17 Thread Piotr Padlewski via cfe-commits
Prazek updated this revision to Diff 32363.
Prazek added a comment.

Fix for the PR24479


http://reviews.llvm.org/D11859

Files:
  lib/CodeGen/CGCXXABI.h
  lib/CodeGen/CGCall.cpp
  lib/CodeGen/CGClass.cpp
  lib/CodeGen/CodeGenFunction.h
  lib/CodeGen/ItaniumCXXABI.cpp
  lib/CodeGen/MicrosoftCXXABI.cpp
  test/CodeGen/available-externally-hidden.cpp
  test/CodeGenCXX/ctor-globalopt.cpp
  test/CodeGenCXX/template-instantiation.cpp
  test/CodeGenCXX/thunks.cpp
  test/CodeGenCXX/virtual-base-ctor.cpp
  test/CodeGenCXX/vtable-assume-load.cpp
  test/CodeGenCXX/vtable-available-externally.cpp

Index: test/CodeGenCXX/vtable-available-externally.cpp
===
--- test/CodeGenCXX/vtable-available-externally.cpp
+++ test/CodeGenCXX/vtable-available-externally.cpp
@@ -182,8 +182,8 @@
 namespace Test9 {
 // all virtual functions are outline, so we can assume that it will
 // be generated in translation unit where foo is defined
-// CHECK-TEST9: @_ZTVN5Test91AE = available_externally unnamed_addr constant
-// CHECK-TEST9: @_ZTVN5Test91BE = available_externally unnamed_addr constant
+// CHECK-TEST9-DAG: @_ZTVN5Test91AE = available_externally unnamed_addr constant
+// CHECK-TEST9-DAG: @_ZTVN5Test91BE = available_externally unnamed_addr constant
 struct A {
   virtual void foo();
   virtual void bar();
@@ -206,39 +206,39 @@
 namespace Test10 {
 
 // because A's key function is defined here, vtable is generated in this TU
-// CHECK-TEST10: @_ZTVN6Test101AE = unnamed_addr constant
+// CHECK-TEST10-DAG: @_ZTVN6Test101AE = unnamed_addr constant
 struct A {
   virtual void foo();
   virtual void bar();
 };
 void A::foo() {}
 
 // Because key function is inline we will generate vtable as linkonce_odr
-// CHECK-TEST10: @_ZTVN6Test101DE = linkonce_odr unnamed_addr constant
+// CHECK-TEST10-DAG: @_ZTVN6Test101DE = linkonce_odr unnamed_addr constant
 struct D : A {
   void bar();
 };
 inline void D::bar() {}
 
 // because B has outline key function then we can refer to
-// CHECK-TEST10: @_ZTVN6Test101BE = available_externally unnamed_addr constant
+// CHECK-TEST10-DAG: @_ZTVN6Test101BE = available_externally unnamed_addr constant
 struct B : A {
   void foo();
   void bar();
 };
 
 // C's key function (car) is outline, but C has inline virtual function so we
 // can't guarantee that we will be able to refer to bar from name
 // so (at the moment) we can't emit vtable available_externally
-// CHECK-TEST10: @_ZTVN6Test101CE = external unnamed_addr constant
+// CHECK-TEST10-DAG: @_ZTVN6Test101CE = external unnamed_addr constant
 struct C : A {
   void bar() {}   // defined in body - not key function
   virtual inline void gar();  // inline in body - not key function
   virtual void car();
 };
 
 // no key function, vtable will be generated everywhere it will be used
-// CHECK-TEST10: @_ZTVN6Test101EE = linkonce_odr unnamed_addr constant
+// CHECK-TEST10-DAG: @_ZTVN6Test101EE = linkonce_odr unnamed_addr constant
 struct E : A {};
 
 void g(A& a) {
Index: test/CodeGenCXX/vtable-assume-load.cpp
===
--- /dev/null
+++ test/CodeGenCXX/vtable-assume-load.cpp
@@ -0,0 +1,172 @@
+// RUN: %clang_cc1 %s -triple x86_64-apple-darwin10 -emit-llvm -o %t.ll -O1 -disable-llvm-optzns -fms-extensions
+// RUN: %clang_cc1 %s -triple i686-pc-win32 -emit-llvm -o %t.ms.ll -O1 -disable-llvm-optzns -fms-extensions
+
+// RUN: FileCheck --check-prefix=CHECK1 --input-file=%t.ll %s
+// RUN: FileCheck --check-prefix=CHECK2 --input-file=%t.ll %s
+// RUN: FileCheck --check-prefix=CHECK3 --input-file=%t.ll %s
+// RUN: FileCheck --check-prefix=CHECK4 --input-file=%t.ll %s
+// RUN: FileCheck --check-prefix=CHECK-MS --input-file=%t.ms.ll %s
+
+namespace test1 {
+
+struct A {
+  A();
+  virtual void foo();
+};
+
+struct B : A {
+  virtual void foo();
+};
+
+void g(A *a) { a->foo(); }
+
+// CHECK1-LABEL: define void @_ZN5test14fooAEv()
+// CHECK1: call void @_ZN5test11AC1Ev(%"struct.test1::A"*
+// CHECK1: %[[VTABLE:.*]] = load i8**, i8*** %{{.*}}
+// CHECK1: %[[CMP:.*]] = icmp eq i8** %[[VTABLE]], getelementptr inbounds ([3 x i8*], [3 x i8*]* @_ZTVN5test11AE, i64 0, i64 2)
+// CHECK1: call void @llvm.assume(i1 %[[CMP]])
+// CHECK1-LABEL: }
+
+void fooA() {
+  A a;
+  g(&a);
+}
+
+// CHECK1-LABEL: define void @_ZN5test14fooBEv()
+// CHECK1: call void @_ZN5test11BC1Ev(%"struct.test1::B"* %{{.*}})
+// CHECK1: %[[VTABLE:.*]] = load i8**, i8*** %{{.*}}
+// CHECK1: %[[CMP:.*]] = icmp eq i8** %[[VTABLE]], getelementptr inbounds ([3 x i8*], [3 x i8*]* @_ZTVN5test11BE, i64 0, i64 2)
+// CHECK1: call void @llvm.assume(i1 %[[CMP]])
+// CHECK1-LABEL: }
+
+void fooB() {
+  B b;
+  g(&b);
+}
+// there should not be any assumes in the ctor that calls base ctor
+// CHECK1-LABEL: define linkonce_odr void @_ZN5test11BC2Ev(%"struct.test1::B"*
+// CHECK1-NOT: @llvm.assume(
+// CHECK1-LABEL: }
+}
+namespace test2 {
+struct A {
+  A();
+  virtual void foo();
+};
+

Re: Second Lit tests C++11 compatibility patch: using preprocessor to filter expected-error

2015-08-17 Thread Richard Smith via cfe-commits
On Mon, Aug 17, 2015 at 6:27 PM, Li, Charles <
charles...@playstation.sony.com> wrote:

> Hi Richard,
>
>
>
> I have modified the “expected-“ lines as you requested.
>

+#if (!defined(__cplusplus)) || (__cplusplus <= 199711L) // C or C++03 or
earlier modes

You can simplify that to:

#if __cplusplus <= 199711L

__cplusplus will expand to 0 inside a #if in C (as will any un#defined
identifier).

Otherwise, this LGTM.

Cheers,
>
> Charles
>
>
>
>
>
> *From:* meta...@gmail.com [mailto:meta...@gmail.com] *On Behalf Of *Richard
> Smith
> *Sent:* Monday, August 17, 2015 5:41 PM
> *To:* Li, Charles
> *Cc:* Justin Bogner; cfe-commits@lists.llvm.org
>
> *Subject:* Re: Second Lit tests C++11 compatibility patch: using
> preprocessor to filter expected-error
>
>
>
> On Mon, Aug 17, 2015 at 5:15 PM, Li, Charles via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
> Hi Richard and Justin,
>
>
>
>
>
> > What's the upside to this approach? AFAICT it makes the test harder to
> read and errors less informative due to pointing at the wrong lines, but
> (at least in switch-1.c) it doesn't actually reduce any code duplication or
> anything like that. What is this gaining us apart from not having to create
> one more file?
>
>
>
> Thank you Justin.
>
> Our original intention was to get the Lit tests to run at any default C++
> dialect.
>
>
>
> We first discovered that FileCheck does not respect #ifdef since it does
> not know about pre-defined macros.
>
> So we figured if we preprocess the source first, the preprocessor will
> filter the #ifdef sections and the output will feed nicely into FileCheck.
>
> The upside is the test can run at the default dialect in addition to
> explicitly specified dialect.
>
> The downside is, as you mentioned, the errors diagnostics would point to
> the wrong lines.
>
>
>
>
>
> > The only thing novel about this approach is using the preprocessor to
> achieve it. -verify *does* respect #ifdef, and we have a lot of tests that
> rely on that.
>
>
>
> Thank you Richard.
>
> We erroneously assumed that “// CHECK:” and “// expected-error” work the
> same way.
>
> But now we realized that assumption was wrong.
>
>
>
> In light this discussion, I have removed the preprocessing to temporary
> step for all tests.
>
> The attached patch (Lit_24.patch) revised 2 test fixes relative to the
> previous patch (Lit_22.patch)
>
>
>
>   test/Analysis/temp-obj-dtors-cfg-output.cpp
>
> This test uses FileCheck to check for CFG dump.
>
> Instead of using #ifdef for the dialect specific “// CHECK:” lines,
>
> I have created 2 check-prefixes “CXX11” and “CXX98”.
>
> The pre-process step have been removed.
>
>
>
>   test/Sema/switch-1.c
>
> This test uses –verify to check for integer overflows diagnostics.
>
> The pre-process step have been removed.
>
> The #ifdef is kept since it works with -verify.
>
>
>
> Instead of duplicating the code, you can do this:
>
>
>
> case blah:
>
> #if __cplusplus >= 201103L
>
> // expected-error@-2 {{error 2 lines above}}
>
> #else
>
> // expected-error@-4 {{error 4 lines above}}
>
> #endif
>
>
>
> Please let me know how you feel about this patch.
>
>
>
> Sincerely,
>
> Charles
>
>
>
>
>
> *From:* meta...@gmail.com [mailto:meta...@gmail.com] *On Behalf Of *Richard
> Smith
> *Sent:* Monday, August 17, 2015 1:07 PM
> *To:* Li, Charles
> *Cc:* cfe-commits@lists.llvm.org
> *Subject:* Re: Second Lit tests C++11 compatibility patch: using
> preprocessor to filter expected-error
>
>
>
> On Mon, Aug 17, 2015 at 9:56 AM, Li, Charles via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
> Hi Clang developers,
>
>
>
> We here at Sony are continuing to update the Lit tests for C++ dialects
> compatibility.
>
> Attached is the second patch. (As a reference, here is the link to the
> discussion on the previous Lit patch.
> http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20150727/134667.html
> )
>
> In this second patch, there is 1 complicated change and 3 simple changes.
>
>
>
> Here is the complicated change first.
>
>
>
> test/Sema/switch-1.c
>
>   This test verifies the diagnostics for integer overflows.
>
>   Due to C++11’s more strict requirements on constant-expressions in
> 5.19p2 [expr.const],
>
>   The diagnostics have changed from “overflow in expression” to “not a
> constant expression”.
>
>
>
>   Usually we would create a C++11 version of the switch-1.c file.
>
>   But here we propose a novel approach to “#ifdef” the expected
> diagnostics. (We hope to use this approach for all similar cases in the
> future.)
>
>   Normally ‘// expected-error’ does not honor any ‘#ifdef’.
>
>   But if we first preprocess the source into a temporary file, only the
> valid ‘#ifdef’ sections remain.
>
>   We then run the preprocessed file at the desired dialect.
>
>   The main downside to this approach is If the test fails, the errors are
> reported on the temporary file, not on the original file, and the line
> numbers of these two files  do not match
>
>
>
> The

Re: [PATCH] D11859: Generating vptr assume loads

2015-08-17 Thread Richard Smith via cfe-commits
rsmith accepted this revision.
rsmith added a comment.
This revision is now accepted and ready to land.

LGTM



Comment at: test/CodeGenCXX/vtable-assume-load.cpp:24
@@ +23,3 @@
+// CHECK1-LABEL: define void @_ZN5test14fooAEv()
+// CHECK1: call void @_ZN5test11AC1Ev(%"struct.test1::A"*
+// CHECK1: %[[VTABLE:.*]] = load i8**, i8*** %{{.*}}

While you're here, maybe also remove the `%"struct.test1::A"*` (and likewise 
for the tests below).


http://reviews.llvm.org/D11859



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


Re: [PATCH] D11844: [Modules] More descriptive diagnostics for misplaced import directive

2015-08-17 Thread Sean Silva via cfe-commits
On Wed, Aug 12, 2015 at 6:05 PM, Richard Smith 
wrote:

> On Wed, Aug 12, 2015 at 6:00 PM, Sean Silva  wrote:
>
>>
>>
>> On Wed, Aug 12, 2015 at 2:43 PM, Richard Smith 
>> wrote:
>>
>>> On Wed, Aug 12, 2015 at 12:08 AM, Sean Silva 
>>> wrote:
>>>
 silvas added a subscriber: silvas.

 
 Comment at: lib/Parse/Parser.cpp:2003
 @@ +2002,3 @@
 +Diag(Tok, diag::err_unexpected_module_start);
 +// Recover by skipping content of the included submodule.
 +unsigned ModuleNesting = 1;
 
 rsmith wrote:
 > This is liable to produce bad follow-on diagnostics; I don't think
 this is a reasonable way to recover. I can see a few feasible options here:
 >
 > 1) Emit a fatal error when this happens (suppressing further
 diagnostics)
 > 2) Break out to the top level of parsing and resume from there (that
 is, assume that a modular header expects to be included at the top level
 and that the user didn't screw up their module map)
 > 3) Enter the module and carry on parsing from here
 >
 > My preference would be either (1) or (2). But either way, we should
 diagnose the still-open bracketing constructs, because the problem is
 likely to be a missing close brace at the end of an unrelated header file.
 I strongly prefer (1). In all cases I have recorded in my notes when
 modularizing, the `error: expected '}'` diagnostic indicated one of two
 things:
 - that a header needed to be marked textual in the module map.
 - that a #include had to be moved to the top of the file (this case was
 likely behaving unexpectedly in the non-modules case and "happened to
 work").
 For the sake of our users, it is probably best to immediately fatal
 error and suggest an alternative (the suggestions can be a separate patch;
 my recommendations are below).

 I believe a user is most likely to run into this diagnostic when
 developing an initial set of module maps, so our diagnostic should be
 tailored to that audience.
>>>
>>>
>>> I think your observations may be biased by your current experiences
>>> modularizing existing code, and not representative of the complete
>>> development cycle. Modularization is a one-time effort; maintaining the
>>> code after modularization is a continuous process. I think it's *far* more
>>> likely that a header listed in your module map was expected to be modular,
>>> and that a brace mismatch within that file is unintentional and due to a
>>> missing brace somewhere.
>>>
>>
>> I don't think so. That implies that the inclusion is not at the top of
>> the file, which is extremely unlikely in a modular codebase.
>>
>
> This also happens when there's a missing brace at the end of your modular
> header, which is almost certainly the most common way to hit this problem
> in an already-modularized codebase.
>

I think that handling the missing brace at end of module differently should
be doable without disturbing the notes that Serge already has here.


> And it happens in codebases that use a mixture of modular and non-modular
> headers, where there's no reason to expect all the modular includes are
> before the non-modular ones.
>

We could check that the opening brace was in the file containing the import
to avoid misdiagnosing a missing brace in a textual header.

Richard, are these cases that you want Serge to deal with in the present
patch?

-- Sean Silva


>
>
>> 125993 #include lines.
>>
>>
>>>
>>> However, we should aim to provide diagnostics that are helpful for
>>> either case.
>>>
>>> These users may have little experience with modules when they encounter
 this diagnostic, so a notes suggesting a likely remedy helps them develop
 confidence by providing authoritative advice (and avoiding a round trip to
 the documentation).

 My fine-grained recommendations from experience are:
 - #include inside extern "C": always meant to be modular, always the
 fix is to move it out of the braced block.
 - #include inside namespace: always meant to be modular, always the fix
 is to move it out of the braced block.
 - #include inside class: always textual (e.g. bringing in methods like
 TableGen .inc files; sometimes similar ".inc" files are manually written
 and not autogenerated. I have observed e.g. "classfoo_methods.h" files;
 another instance of this is stamping out ".def" files)
 - #include inside array initializer: always textual. Typically ".def"
 files
 - #include inside function: always textual. Typically ".def" files
 (e.g. generate a switch)

 ".inl" files are theoretically a problem inside namespaces, but I have
 not observed this issue in practice. In my experience code taking the
 effort to have ".inl" files is quite clean and avoids such textual
 dependencies. The issues I have seen in practice with ".inl" files usually
 end up com

Re: [PATCH] D11944: Nativize filename in FileManager::getFile().

2015-08-17 Thread Sean Silva via cfe-commits
On Thu, Aug 13, 2015 at 10:50 AM, Richard Smith via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> rsmith added a comment.
>
> I would think most Windows users would be surprised if we showed them
> paths with /s instead of \s, but I'm fine with us using / internally if it
> doesn't leak out to the user.
>

I think it makes sense to have a "canonical" form internally, similar to
how all our filesystem API's ensure that internally all of clang's buffers
are UTF-8.

-- Sean Silva


>
> klimek: if we want to nativize, I think the right thing to do is to remove
> the wrong "normalization" of non-Windows paths from
> `llvm::sys::path::native`, and add a more efficient overload to
> `llvm::sys::path::native`, such as `StringRef native(StringRef Input,
> SmallVectorImpl &Buffer)`.
>
>
> http://reviews.llvm.org/D11944
>
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r245264 - Generating assumption loads of vptr after ctor call (fixed)

2015-08-17 Thread Piotr Padlewski via cfe-commits
Author: prazek
Date: Mon Aug 17 22:52:00 2015
New Revision: 245264

URL: http://llvm.org/viewvc/llvm-project?rev=245264&view=rev
Log:
Generating assumption loads of vptr after ctor call (fixed)

Generating call assume(icmp %vtable, %global_vtable) after constructor
call for devirtualization purposes.

For more info go to:
http://lists.llvm.org/pipermail/cfe-dev/2015-July/044227.html

Edit:
Fixed version because of PR24479.

http://reviews.llvm.org/D11859

Added:
cfe/trunk/test/CodeGenCXX/vtable-assume-load.cpp
Modified:
cfe/trunk/lib/CodeGen/CGCXXABI.h
cfe/trunk/lib/CodeGen/CGCall.cpp
cfe/trunk/lib/CodeGen/CGClass.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.h
cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp
cfe/trunk/test/CodeGen/available-externally-hidden.cpp
cfe/trunk/test/CodeGenCXX/ctor-globalopt.cpp
cfe/trunk/test/CodeGenCXX/template-instantiation.cpp
cfe/trunk/test/CodeGenCXX/thunks.cpp
cfe/trunk/test/CodeGenCXX/virtual-base-ctor.cpp
cfe/trunk/test/CodeGenCXX/vtable-available-externally.cpp

Modified: cfe/trunk/lib/CodeGen/CGCXXABI.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCXXABI.h?rev=245264&r1=245263&r2=245264&view=diff
==
--- cfe/trunk/lib/CodeGen/CGCXXABI.h (original)
+++ cfe/trunk/lib/CodeGen/CGCXXABI.h Mon Aug 17 22:52:00 2015
@@ -346,13 +346,25 @@ public:
   virtual void emitVTableDefinitions(CodeGenVTables &CGVT,
  const CXXRecordDecl *RD) = 0;
 
+  /// Checks if ABI requires extra virtual offset for vtable field.
+  virtual bool
+  isVirtualOffsetNeededForVTableField(CodeGenFunction &CGF,
+  CodeGenFunction::VPtr Vptr) = 0;
+
+  /// Checks if ABI requires to initilize vptrs for given dynamic class.
+  virtual bool doStructorsInitializeVPtrs(const CXXRecordDecl *VTableClass) = 
0;
+
+  /// Get the address point of the vtable for the given base subobject.
+  virtual llvm::Constant *
+  getVTableAddressPoint(BaseSubobject Base,
+const CXXRecordDecl *VTableClass) = 0;
+
   /// Get the address point of the vtable for the given base subobject while
-  /// building a constructor or a destructor. On return, NeedsVirtualOffset
-  /// tells if a virtual base adjustment is needed in order to get the offset
-  /// of the base subobject.
-  virtual llvm::Value *getVTableAddressPointInStructor(
-  CodeGenFunction &CGF, const CXXRecordDecl *RD, BaseSubobject Base,
-  const CXXRecordDecl *NearestVBase, bool &NeedsVirtualOffset) = 0;
+  /// building a constructor or a destructor.
+  virtual llvm::Value *
+  getVTableAddressPointInStructor(CodeGenFunction &CGF, const CXXRecordDecl 
*RD,
+  BaseSubobject Base,
+  const CXXRecordDecl *NearestVBase) = 0;
 
   /// Get the address point of the vtable for the given base subobject while
   /// building a constexpr.

Modified: cfe/trunk/lib/CodeGen/CGCall.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCall.cpp?rev=245264&r1=245263&r2=245264&view=diff
==
--- cfe/trunk/lib/CodeGen/CGCall.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCall.cpp Mon Aug 17 22:52:00 2015
@@ -1412,7 +1412,8 @@ void CodeGenModule::ConstructAttributeLi
 
 if (const FunctionDecl *Fn = dyn_cast(TargetDecl)) {
   const FunctionProtoType *FPT = Fn->getType()->getAs();
-  if (FPT && FPT->isNothrow(getContext()))
+  if (FPT && !isUnresolvedExceptionSpec(FPT->getExceptionSpecType()) &&
+  FPT->isNothrow(getContext()))
 FuncAttrs.addAttribute(llvm::Attribute::NoUnwind);
   // Don't use [[noreturn]] or _Noreturn for a call to a virtual function.
   // These attributes are not inherited by overloads.

Modified: cfe/trunk/lib/CodeGen/CGClass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGClass.cpp?rev=245264&r1=245263&r2=245264&view=diff
==
--- cfe/trunk/lib/CodeGen/CGClass.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGClass.cpp Mon Aug 17 22:52:00 2015
@@ -1806,12 +1806,14 @@ void CodeGenFunction::EmitCXXConstructor
  bool ForVirtualBase,
  bool Delegating, llvm::Value 
*This,
  const CXXConstructExpr *E) {
+  const CXXRecordDecl *ClassDecl = D->getParent();
+
   // C++11 [class.mfct.non-static]p2:
   //   If a non-static member function of a class X is called for an object 
that
   //   is not of type X, or of a type derived from X, the behavior is 
undefined.
   // FIXME: Provide a source location here.
   EmitTypeCheck(CodeGenFunction::TCK_ConstructorCall, SourceLocation(), This,
-   

Re: [PATCH] D12038: CodeGen: Introduce CodeGenModule::CreateMetadataIdentifierForType.

2015-08-17 Thread Piotr Padlewski via cfe-commits
Prazek added inline comments.


Comment at: lib/CodeGen/CodeGenModule.cpp:3677
@@ +3676,3 @@
+llvm::Metadata *CodeGenModule::CreateMetadataIdentifierForType(QualType T) {
+  llvm::Metadata *&InternalId = MetadataIdMap[T.getCanonicalType()];
+  if (InternalId)

question: so You are storing distinct and normal mdnodes here. Is it faster to 
grap normal node from this map than to just create new one using get?


http://reviews.llvm.org/D12038



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


Re: r245041 - [OPENMP] Fix for http://llvm.org/PR24371: Assert failure compiling blender 2.75.

2015-08-17 Thread Bataev, Alexey via cfe-commits

Hans, everything is fine.

Best regards,
Alexey Bataev
=
Software Engineer
Intel Compiler Team

17.08.2015 21:30, Hans Wennborg пишет:

Merged in r245229.

There were merge conflicts in StmtOpenMP.h because we don't have
r244209 on the branch. I think I got it right, but I'd appreciate if
someone could double check
http://llvm.org/viewvc/llvm-project?rev=245229&view=rev

Thanks,
Hans

On Sun, Aug 16, 2015 at 8:55 PM, Bataev, Alexey  wrote:

Yes, please, forget to tell you. :)

Best regards,
Alexey Bataev
=
Software Engineer
Intel Compiler Team

14.08.2015 19:03, Hans Wennborg пишет:


On Fri, Aug 14, 2015 at 5:25 AM, Alexey Bataev via cfe-commits
 wrote:

Author: abataev
Date: Fri Aug 14 07:25:37 2015
New Revision: 245041

URL: http://llvm.org/viewvc/llvm-project?rev=245041&view=rev
Log:
[OPENMP] Fix for http://llvm.org/PR24371: Assert failure compiling
blender 2.75.
blender uses statements expression in condition of the loop under control
of the '#pragma omp parallel for'. This condition is used several times in
different expressions required for codegen of the loop directive. If there
are some variables defined in statement expression, it fires an assert
during codegen because of redefinition of the same variables.
We have to rebuild several expression to be sure that all variables are
unique.

Should we merge this to 3.7?




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


Re: [PATCH] D12038: CodeGen: Introduce CodeGenModule::CreateMetadataIdentifierForType.

2015-08-17 Thread Peter Collingbourne via cfe-commits
pcc added inline comments.


Comment at: lib/CodeGen/CodeGenModule.cpp:3677
@@ +3676,3 @@
+llvm::Metadata *CodeGenModule::CreateMetadataIdentifierForType(QualType T) {
+  llvm::Metadata *&InternalId = MetadataIdMap[T.getCanonicalType()];
+  if (InternalId)

Prazek wrote:
> question: so You are storing distinct and normal mdnodes here. Is it faster 
> to grap normal node from this map than to just create new one using get?
Quite possibly (the latter involves string comparisons and possibly memory 
allocation) but they should both have the same complexity so it doesn't matter 
much.


http://reviews.llvm.org/D12038



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


Re: Second Lit tests C++11 compatibility patch: using preprocessor to filter expected-error

2015-08-17 Thread Justin Bogner via cfe-commits
"Li, Charles"  writes:
> Hi Richard,
>
> I have modified the “expected-“ lines as you requested.
>
> Cheers,
>
> Charles
>
> From: meta...@gmail.com [mailto:meta...@gmail.com] On Behalf Of Richard Smith
> Sent: Monday, August 17, 2015 5:41 PM
> To: Li, Charles
> Cc: Justin Bogner; cfe-commits@lists.llvm.org
> Subject: Re: Second Lit tests C++11 compatibility patch: using preprocessor to
> filter expected-error
>
> On Mon, Aug 17, 2015 at 5:15 PM, Li, Charles via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
> Hi Richard and Justin,
>
>> What's the upside to this approach? AFAICT it makes the test harder to read
> and errors less informative due to pointing at the wrong lines, but (at least
> in switch-1.c) it doesn't actually reduce any code duplication or anything
> like that. What is this gaining us apart from not having to create one more
> file?
>
> Thank you Justin.
>
> Our original intention was to get the Lit tests to run at any default C++
> dialect.
>
> We first discovered that FileCheck does not respect #ifdef since it does not
> know about pre-defined macros.
>
> So we figured if we preprocess the source first, the preprocessor will filter
> the #ifdef sections and the output will feed nicely into FileCheck.
>
> The upside is the test can run at the default dialect in addition to
> explicitly specified dialect.
>
> The downside is, as you mentioned, the errors diagnostics would point to the
> wrong lines.
>
>> The only thing novel about this approach is using the preprocessor to
> achieve it. -verify *does* respect #ifdef, and we have a lot of tests that
> rely on that.
>
> Thank you Richard.
>
> We erroneously assumed that “// CHECK:” and “// expected-error” work the same
> way.
>
> But now we realized that assumption was wrong.
>
> In light this discussion, I have removed the preprocessing to temporary step
> for all tests.
>
> The attached patch (Lit_24.patch) revised 2 test fixes relative to the
> previous patch (Lit_22.patch)
>
>   test/Analysis/temp-obj-dtors-cfg-output.cpp
>
> This test uses FileCheck to check for CFG dump.
>
> Instead of using #ifdef for the dialect specific “// CHECK:” lines,
>
> I have created 2 check-prefixes “CXX11” and “CXX98”.
>
> The pre-process step have been removed.
>
>   test/Sema/switch-1.c
>
> This test uses –verify to check for integer overflows diagnostics.
>
> The pre-process step have been removed.
>
> The #ifdef is kept since it works with -verify.
>
> Instead of duplicating the code, you can do this:
>
> case blah:
>
> #if __cplusplus >= 201103L
>
> // expected-error@-2 {{error 2 lines above}}
>
> #else
>
> // expected-error@-4 {{error 4 lines above}}
>
> #endif
>
> Please let me know how you feel about this patch.
>
> Sincerely,
>
> Charles
>
> From: meta...@gmail.com [mailto:meta...@gmail.com] On Behalf Of Richard
> Smith
> Sent: Monday, August 17, 2015 1:07 PM
> To: Li, Charles
> Cc: cfe-commits@lists.llvm.org
> Subject: Re: Second Lit tests C++11 compatibility patch: using
> preprocessor to filter expected-error
>
> On Mon, Aug 17, 2015 at 9:56 AM, Li, Charles via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
> Hi Clang developers,
>
> We here at Sony are continuing to update the Lit tests for C++ dialects
> compatibility.
>
> Attached is the second patch. (As a reference, here is the link to the
> discussion on the previous Lit patch. http://lists.cs.uiuc.edu/pipermail/
> cfe-commits/Week-of-Mon-20150727/134667.html)
>
> In this second patch, there is 1 complicated change and 3 simple changes.
>
> Here is the complicated change first.
>
> test/Sema/switch-1.c
>
>   This test verifies the diagnostics for integer overflows.
>
>   Due to C++11’s more strict requirements on constant-expressions in
> 5.19p2 [expr.const],
>
>   The diagnostics have changed from “overflow in expression” to “not a
> constant expression”.
>
>   Usually we would create a C++11 version of the switch-1.c file.
>
>   But here we propose a novel approach to “#ifdef” the expected
> diagnostics. (We hope to use this approach for all similar cases in the
> future.)
>
>   Normally ‘// expected-error’ does not honor any ‘#ifdef’.
>
>   But if we first preprocess the source into a temporary file, only the
> valid ‘#ifdef’ sections remain.
>
>   We then run the preprocessed file at the desired dialect.
>
>   The main downside to this approach is If the test fails, the errors are
> reported on the temporary file, not on the original file, and the line
> numbers of these two files  do not match
>
> The only thing novel about this approach is using the preprocessor to
> achieve it. -verify *does* respect #ifdef, and we have a lot of tests that
> rely on that.
>
> Here are the simple changes.
>
> test/Analysis/temp-obj-dtors-cf

Re: [PATCH] D10431: PR21174 - clang only searches current working directory for precompiled include file

2015-08-17 Thread Kim Gräsman via cfe-commits
On Tue, Aug 18, 2015 at 2:00 AM, Richard Smith  wrote:
>
>> > Should this logic for PCH/PTH scanning move out of the driver and into
>> > the frontend?
>
>> gcc also checks if the gch file is a directory and if so finds the first
>> file with matching language / defines etc. It also uses gch files for
>> #included files instead of just -included files
>> (https://gcc.gnu.org/onlinedocs/gcc/Precompiled-Headers.html). I thought
>> clang intentionally did none of this so it doesn't have to stat all these
>> directories.
>
> Right, so the question is: what do we want our semantics to be here? Do we
> have sufficient motivation to change our existing design to something closer
> to GCC's? Or should we be encouraging people to use modules instead of PCH
> here, which has all of the desirable properties of the above, and doesn't
> have the "no preceding tokens" limitation?

We find Clang's GCC compat very useful overall, because we use GCC as
a cross-compiler and we can more or less drop in Clang for better
diagnostics and tooling.

So from a personal convenience standpoint, Nikola's patch would be
sufficient, because it would bring Clang just close enough to GCC to
solve our problem (we've now worked around it by disabling PCH in our
build system when we build for Clang.)

Encouraging modules would (I suppose?) create a split where Clang had
modules and other compilers had precompiled headers. For a Clang-only
shop, that's fine, but for a GCC/MSVC/Clang environment like ours,
that would be more work to find common ground. The remaining GCC PCH
behavior sounds mostly esoteric, so I, personally, don't see any point
in trying to mimic it, but others will probably disagree here.

All that said, I think we can solve this locally by just changing our
build system to -include an absolute path, so this isn't critical for
us at the moment. It would be convenient for us if this compat glitch
could be solved, but if you'd rather focus on modules, I can
understand that too :-)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r245267 - Revert "Generating assumption loads of vptr after ctor call (fixed)"

2015-08-17 Thread Justin Bogner via cfe-commits
Author: bogner
Date: Tue Aug 18 00:40:20 2015
New Revision: 245267

URL: http://llvm.org/viewvc/llvm-project?rev=245267&view=rev
Log:
Revert "Generating assumption loads of vptr after ctor call (fixed)"

Bootstrap bots were failing:

http://lab.llvm.org:8080/green/job/clang-stage2-configure-Rlto_build/6382/
http://bb.pgr.jp/builders/clang-3stage-i686-linux/builds/2969

This reverts r245264.

Removed:
cfe/trunk/test/CodeGenCXX/vtable-assume-load.cpp
Modified:
cfe/trunk/lib/CodeGen/CGCXXABI.h
cfe/trunk/lib/CodeGen/CGCall.cpp
cfe/trunk/lib/CodeGen/CGClass.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.h
cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp
cfe/trunk/test/CodeGen/available-externally-hidden.cpp
cfe/trunk/test/CodeGenCXX/ctor-globalopt.cpp
cfe/trunk/test/CodeGenCXX/template-instantiation.cpp
cfe/trunk/test/CodeGenCXX/thunks.cpp
cfe/trunk/test/CodeGenCXX/virtual-base-ctor.cpp
cfe/trunk/test/CodeGenCXX/vtable-available-externally.cpp

Modified: cfe/trunk/lib/CodeGen/CGCXXABI.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCXXABI.h?rev=245267&r1=245266&r2=245267&view=diff
==
--- cfe/trunk/lib/CodeGen/CGCXXABI.h (original)
+++ cfe/trunk/lib/CodeGen/CGCXXABI.h Tue Aug 18 00:40:20 2015
@@ -346,25 +346,13 @@ public:
   virtual void emitVTableDefinitions(CodeGenVTables &CGVT,
  const CXXRecordDecl *RD) = 0;
 
-  /// Checks if ABI requires extra virtual offset for vtable field.
-  virtual bool
-  isVirtualOffsetNeededForVTableField(CodeGenFunction &CGF,
-  CodeGenFunction::VPtr Vptr) = 0;
-
-  /// Checks if ABI requires to initilize vptrs for given dynamic class.
-  virtual bool doStructorsInitializeVPtrs(const CXXRecordDecl *VTableClass) = 
0;
-
-  /// Get the address point of the vtable for the given base subobject.
-  virtual llvm::Constant *
-  getVTableAddressPoint(BaseSubobject Base,
-const CXXRecordDecl *VTableClass) = 0;
-
   /// Get the address point of the vtable for the given base subobject while
-  /// building a constructor or a destructor.
-  virtual llvm::Value *
-  getVTableAddressPointInStructor(CodeGenFunction &CGF, const CXXRecordDecl 
*RD,
-  BaseSubobject Base,
-  const CXXRecordDecl *NearestVBase) = 0;
+  /// building a constructor or a destructor. On return, NeedsVirtualOffset
+  /// tells if a virtual base adjustment is needed in order to get the offset
+  /// of the base subobject.
+  virtual llvm::Value *getVTableAddressPointInStructor(
+  CodeGenFunction &CGF, const CXXRecordDecl *RD, BaseSubobject Base,
+  const CXXRecordDecl *NearestVBase, bool &NeedsVirtualOffset) = 0;
 
   /// Get the address point of the vtable for the given base subobject while
   /// building a constexpr.

Modified: cfe/trunk/lib/CodeGen/CGCall.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCall.cpp?rev=245267&r1=245266&r2=245267&view=diff
==
--- cfe/trunk/lib/CodeGen/CGCall.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCall.cpp Tue Aug 18 00:40:20 2015
@@ -1412,8 +1412,7 @@ void CodeGenModule::ConstructAttributeLi
 
 if (const FunctionDecl *Fn = dyn_cast(TargetDecl)) {
   const FunctionProtoType *FPT = Fn->getType()->getAs();
-  if (FPT && !isUnresolvedExceptionSpec(FPT->getExceptionSpecType()) &&
-  FPT->isNothrow(getContext()))
+  if (FPT && FPT->isNothrow(getContext()))
 FuncAttrs.addAttribute(llvm::Attribute::NoUnwind);
   // Don't use [[noreturn]] or _Noreturn for a call to a virtual function.
   // These attributes are not inherited by overloads.

Modified: cfe/trunk/lib/CodeGen/CGClass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGClass.cpp?rev=245267&r1=245266&r2=245267&view=diff
==
--- cfe/trunk/lib/CodeGen/CGClass.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGClass.cpp Tue Aug 18 00:40:20 2015
@@ -1806,14 +1806,12 @@ void CodeGenFunction::EmitCXXConstructor
  bool ForVirtualBase,
  bool Delegating, llvm::Value 
*This,
  const CXXConstructExpr *E) {
-  const CXXRecordDecl *ClassDecl = D->getParent();
-
   // C++11 [class.mfct.non-static]p2:
   //   If a non-static member function of a class X is called for an object 
that
   //   is not of type X, or of a type derived from X, the behavior is 
undefined.
   // FIXME: Provide a source location here.
   EmitTypeCheck(CodeGenFunction::TCK_ConstructorCall, SourceLocation(), This,
-getContext().getRecordType(ClassDecl));
+getCo

Re: r245264 - Generating assumption loads of vptr after ctor call (fixed)

2015-08-17 Thread Justin Bogner via cfe-commits
Piotr Padlewski via cfe-commits  writes:
> Author: prazek
> Date: Mon Aug 17 22:52:00 2015
> New Revision: 245264
>
> URL: http://llvm.org/viewvc/llvm-project?rev=245264&view=rev
> Log:
> Generating assumption loads of vptr after ctor call (fixed)
>
> Generating call assume(icmp %vtable, %global_vtable) after constructor
> call for devirtualization purposes.
>
> For more info go to:
> http://lists.llvm.org/pipermail/cfe-dev/2015-July/044227.html
>
> Edit:
> Fixed version because of PR24479.

(resending since I foolishly sent a very large text file and it got
caught in moderation)

This was hitting asserts on a couple of bootstrap bots, so I reverted
it in r245267.

Failing bots:

http://lab.llvm.org:8080/green/job/clang-stage2-configure-Rlto_build/6382/
http://bb.pgr.jp/builders/clang-3stage-i686-linux/builds/2969

I also managed to grab the crash diagnostics from one of the bots, but
the preprocessed source is too large for the list.

> http://reviews.llvm.org/D11859
>
> Added:
> cfe/trunk/test/CodeGenCXX/vtable-assume-load.cpp
> Modified:
> cfe/trunk/lib/CodeGen/CGCXXABI.h
> cfe/trunk/lib/CodeGen/CGCall.cpp
> cfe/trunk/lib/CodeGen/CGClass.cpp
> cfe/trunk/lib/CodeGen/CodeGenFunction.h
> cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
> cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp
> cfe/trunk/test/CodeGen/available-externally-hidden.cpp
> cfe/trunk/test/CodeGenCXX/ctor-globalopt.cpp
> cfe/trunk/test/CodeGenCXX/template-instantiation.cpp
> cfe/trunk/test/CodeGenCXX/thunks.cpp
> cfe/trunk/test/CodeGenCXX/virtual-base-ctor.cpp
> cfe/trunk/test/CodeGenCXX/vtable-available-externally.cpp
>
> Modified: cfe/trunk/lib/CodeGen/CGCXXABI.h
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCXXABI.h?rev=245264&r1=245263&r2=245264&view=diff
> ==
> --- cfe/trunk/lib/CodeGen/CGCXXABI.h (original)
> +++ cfe/trunk/lib/CodeGen/CGCXXABI.h Mon Aug 17 22:52:00 2015
> @@ -346,13 +346,25 @@ public:
>virtual void emitVTableDefinitions(CodeGenVTables &CGVT,
>   const CXXRecordDecl *RD) = 0;
>  
> +  /// Checks if ABI requires extra virtual offset for vtable field.
> +  virtual bool
> +  isVirtualOffsetNeededForVTableField(CodeGenFunction &CGF,
> +  CodeGenFunction::VPtr Vptr) = 0;
> +
> +  /// Checks if ABI requires to initilize vptrs for given dynamic class.
> +  virtual bool doStructorsInitializeVPtrs(const CXXRecordDecl *VTableClass) 
> = 0;
> +
> +  /// Get the address point of the vtable for the given base subobject.
> +  virtual llvm::Constant *
> +  getVTableAddressPoint(BaseSubobject Base,
> +const CXXRecordDecl *VTableClass) = 0;
> +
>/// Get the address point of the vtable for the given base subobject while
> -  /// building a constructor or a destructor. On return, NeedsVirtualOffset
> -  /// tells if a virtual base adjustment is needed in order to get the offset
> -  /// of the base subobject.
> -  virtual llvm::Value *getVTableAddressPointInStructor(
> -  CodeGenFunction &CGF, const CXXRecordDecl *RD, BaseSubobject Base,
> -  const CXXRecordDecl *NearestVBase, bool &NeedsVirtualOffset) = 0;
> +  /// building a constructor or a destructor.
> +  virtual llvm::Value *
> +  getVTableAddressPointInStructor(CodeGenFunction &CGF, const CXXRecordDecl 
> *RD,
> +  BaseSubobject Base,
> +  const CXXRecordDecl *NearestVBase) = 0;
>  
>/// Get the address point of the vtable for the given base subobject while
>/// building a constexpr.
>
> Modified: cfe/trunk/lib/CodeGen/CGCall.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCall.cpp?rev=245264&r1=245263&r2=245264&view=diff
> ==
> --- cfe/trunk/lib/CodeGen/CGCall.cpp (original)
> +++ cfe/trunk/lib/CodeGen/CGCall.cpp Mon Aug 17 22:52:00 2015
> @@ -1412,7 +1412,8 @@ void CodeGenModule::ConstructAttributeLi
>  
>  if (const FunctionDecl *Fn = dyn_cast(TargetDecl)) {
>const FunctionProtoType *FPT = 
> Fn->getType()->getAs();
> -  if (FPT && FPT->isNothrow(getContext()))
> +  if (FPT && !isUnresolvedExceptionSpec(FPT->getExceptionSpecType()) &&
> +  FPT->isNothrow(getContext()))
>  FuncAttrs.addAttribute(llvm::Attribute::NoUnwind);
>// Don't use [[noreturn]] or _Noreturn for a call to a virtual 
> function.
>// These attributes are not inherited by overloads.
>
> Modified: cfe/trunk/lib/CodeGen/CGClass.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGClass.cpp?rev=245264&r1=245263&r2=245264&view=diff
> ==
> --- cfe/trunk/lib/CodeGen/CGClass.cpp (original)
> +++ cfe/trunk/lib/CodeGen/CGClass.cpp Mon Aug 17 22:52:00 2015
> 

  1   2   >