r345370 - Reapply: [Driver] Use forward slashes in most linker arguments

2018-10-26 Thread Martin Storsjo via cfe-commits
Author: mstorsjo
Date: Fri Oct 26 00:01:59 2018
New Revision: 345370

URL: http://llvm.org/viewvc/llvm-project?rev=345370&view=rev
Log:
Reapply: [Driver] Use forward slashes in most linker arguments

libtool inspects the output of $CC -v to detect what object files and
libraries are linked in by default. When clang is built as a native
windows executable, all paths are formatted with backslashes, and
the backslashes cause each argument to be enclosed in quotes. The
backslashes and quotes break further processing within libtool (which
is implemented in shell script, running in e.g. msys) pretty badly.

Between unix style pathes (that only work in tools that are linked
to the msys runtime, essentially the same as cygwin) and proper windows
style paths (with backslashes, that can easily break shell scripts
and msys environments), the best compromise is to use windows style
paths (starting with e.g. c:) but with forward slashes, which both
msys based tools, shell scripts and native windows executables can
cope with. This incidentally turns out to be the form of paths that
GCC prints out when run with -v on windows as well.

This change potentially makes the output from clang -v a bit more
inconsistent, but it is isn't necessarily very consistent to begin with.

Compared to the previous attempt in SVN r345004, this now does
the same transformation on more paths, hopefully on the right set
of paths so that all tests pass (previously some tests failed, where
path fragments that were required to be identical turned out to
use different path separators in different places). This now also
is done only for non-windows, or cygwin/mingw targets, to preserve
all backslashes for MSVC cases (where the paths can end up e.g. embedded
into PDB files. (The transformation function itself,
llvm::sys::path::convert_to_slash only has an effect when run on windows.)

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

Modified:
cfe/trunk/include/clang/Driver/ToolChain.h
cfe/trunk/lib/Driver/Driver.cpp
cfe/trunk/lib/Driver/ToolChain.cpp
cfe/trunk/lib/Driver/ToolChains/Clang.cpp
cfe/trunk/lib/Driver/ToolChains/CommonArgs.cpp
cfe/trunk/lib/Driver/ToolChains/Gnu.cpp

Modified: cfe/trunk/include/clang/Driver/ToolChain.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/ToolChain.h?rev=345370&r1=345369&r2=345370&view=diff
==
--- cfe/trunk/include/clang/Driver/ToolChain.h (original)
+++ cfe/trunk/include/clang/Driver/ToolChain.h Fri Oct 26 00:01:59 2018
@@ -21,6 +21,7 @@
 #include "llvm/ADT/Triple.h"
 #include "llvm/MC/MCTargetOptions.h"
 #include "llvm/Option/Option.h"
+#include "llvm/Support/Path.h"
 #include "llvm/Support/VersionTuple.h"
 #include "llvm/Target/TargetOptions.h"
 #include 
@@ -370,6 +371,12 @@ public:
  StringRef Component,
  bool Shared = false) const;
 
+  std::string normalizePath(StringRef Path) const {
+if (!Triple.isOSWindows() || Triple.isOSCygMing())
+  return llvm::sys::path::convert_to_slash(Path);
+return Path;
+  }
+
   // Returns /lib//.  This is used by runtimes (such
   // as OpenMP) to find arch-specific libraries.
   std::string getArchSpecificLibPath() const;

Modified: cfe/trunk/lib/Driver/Driver.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Driver.cpp?rev=345370&r1=345369&r2=345370&view=diff
==
--- cfe/trunk/lib/Driver/Driver.cpp (original)
+++ cfe/trunk/lib/Driver/Driver.cpp Fri Oct 26 00:01:59 2018
@@ -1011,6 +1011,12 @@ Compilation *Driver::BuildCompilation(Ar
 .Default(SaveTempsCwd);
   }
 
+  llvm::Triple EffectiveTriple = computeTargetTriple(*this, TargetTriple, 
Args);
+  if (!EffectiveTriple.isOSWindows() || EffectiveTriple.isOSCygMing()) {
+for (auto *Str : {&Dir, &InstalledDir, &SysRoot, &ResourceDir})
+  *Str = llvm::sys::path::convert_to_slash(*Str);
+  }
+
   setLTOMode(Args);
 
   // Process -fembed-bitcode= flags.

Modified: cfe/trunk/lib/Driver/ToolChain.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChain.cpp?rev=345370&r1=345369&r2=345370&view=diff
==
--- cfe/trunk/lib/Driver/ToolChain.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChain.cpp Fri Oct 26 00:01:59 2018
@@ -376,9 +376,10 @@ std::string ToolChain::getCompilerRT(con
 
   for (const auto &LibPath : getLibraryPaths()) {
 SmallString<128> P(LibPath);
-llvm::sys::path::append(P, Prefix + Twine("clang_rt.") + Component + 
Suffix);
+llvm::sys::path::append(P,
+Prefix + Twine("clang_rt.") + Component + Suffix);
 if (getVFS().exists(P))
-  return P.str();
+  return normalizePath(P);
   }
 
   StringRef Arch = getArchNameForCompilerRTLib(*this, Args);
@@ 

[PATCH] D53066: [Driver] Use forward slashes in most linker arguments

2018-10-26 Thread Martin Storsjö via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL345370: Reapply: [Driver] Use forward slashes in most linker 
arguments (authored by mstorsjo, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D53066?vs=170989&id=171253#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D53066

Files:
  cfe/trunk/include/clang/Driver/ToolChain.h
  cfe/trunk/lib/Driver/Driver.cpp
  cfe/trunk/lib/Driver/ToolChain.cpp
  cfe/trunk/lib/Driver/ToolChains/Clang.cpp
  cfe/trunk/lib/Driver/ToolChains/CommonArgs.cpp
  cfe/trunk/lib/Driver/ToolChains/Gnu.cpp

Index: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
===
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp
@@ -3570,7 +3570,8 @@
 for (const auto &II : Inputs) {
   addDashXForInput(Args, II, CmdArgs);
   if (II.isFilename())
-CmdArgs.push_back(II.getFilename());
+CmdArgs.push_back(
+Args.MakeArgString(TC.normalizePath(II.getFilename(;
   else
 II.getInputArg().renderAsInput(Args, CmdArgs);
 }
@@ -4963,7 +4964,8 @@
 // Handled with other dependency code.
   } else if (Output.isFilename()) {
 CmdArgs.push_back("-o");
-CmdArgs.push_back(Output.getFilename());
+CmdArgs.push_back(
+Args.MakeArgString(TC.normalizePath(Output.getFilename(;
   } else {
 assert(Output.isNothing() && "Invalid output.");
   }
@@ -4978,7 +4980,8 @@
 
   for (const InputInfo &Input : FrontendInputs) {
 if (Input.isFilename())
-  CmdArgs.push_back(Input.getFilename());
+  CmdArgs.push_back(
+  Args.MakeArgString(TC.normalizePath(Input.getFilename(;
 else
   Input.getInputArg().renderAsInput(Args, CmdArgs);
   }
@@ -5671,9 +5674,10 @@
   assert(Inputs.size() == 1 && "Unexpected number of inputs.");
   const InputInfo &Input = Inputs[0];
 
-  const llvm::Triple &Triple = getToolChain().getEffectiveTriple();
+  const ToolChain &TC = getToolChain();
+  const llvm::Triple &Triple = TC.getEffectiveTriple();
   const std::string &TripleStr = Triple.getTriple();
-  const auto &D = getToolChain().getDriver();
+  const auto &D = TC.getDriver();
 
   // Don't warn about "clang -w -c foo.s"
   Args.ClaimAllArgs(options::OPT_w);
@@ -5847,7 +5851,7 @@
 
   assert(Output.isFilename() && "Unexpected lipo output.");
   CmdArgs.push_back("-o");
-  CmdArgs.push_back(Output.getFilename());
+  CmdArgs.push_back(Args.MakeArgString(TC.normalizePath(Output.getFilename(;
 
   const llvm::Triple &T = getToolChain().getTriple();
   if (Args.hasArg(options::OPT_gsplit_dwarf) &&
@@ -5857,7 +5861,7 @@
   }
 
   assert(Input.isFilename() && "Invalid input.");
-  CmdArgs.push_back(Input.getFilename());
+  CmdArgs.push_back(Args.MakeArgString(TC.normalizePath(Input.getFilename(;
 
   const char *Exec = getToolChain().getDriver().getClangProgramPath();
   C.addCommand(llvm::make_unique(JA, *this, Exec, CmdArgs, Inputs));
Index: cfe/trunk/lib/Driver/ToolChains/Gnu.cpp
===
--- cfe/trunk/lib/Driver/ToolChains/Gnu.cpp
+++ cfe/trunk/lib/Driver/ToolChains/Gnu.cpp
@@ -1699,7 +1699,7 @@
 if (GCCToolchainDir.back() == '/')
   GCCToolchainDir = GCCToolchainDir.drop_back(); // remove the /
 
-Prefixes.push_back(GCCToolchainDir);
+Prefixes.push_back(llvm::sys::path::convert_to_slash(GCCToolchainDir));
   } else {
 // If we have a SysRoot, try that first.
 if (!D.SysRoot.empty()) {
Index: cfe/trunk/lib/Driver/ToolChains/CommonArgs.cpp
===
--- cfe/trunk/lib/Driver/ToolChains/CommonArgs.cpp
+++ cfe/trunk/lib/Driver/ToolChains/CommonArgs.cpp
@@ -163,7 +163,7 @@
 
 // Add filenames immediately.
 if (II.isFilename()) {
-  CmdArgs.push_back(II.getFilename());
+  CmdArgs.push_back(Args.MakeArgString(TC.normalizePath(II.getFilename(;
   continue;
 }
 
Index: cfe/trunk/lib/Driver/ToolChain.cpp
===
--- cfe/trunk/lib/Driver/ToolChain.cpp
+++ cfe/trunk/lib/Driver/ToolChain.cpp
@@ -376,17 +376,18 @@
 
   for (const auto &LibPath : getLibraryPaths()) {
 SmallString<128> P(LibPath);
-llvm::sys::path::append(P, Prefix + Twine("clang_rt.") + Component + Suffix);
+llvm::sys::path::append(P,
+Prefix + Twine("clang_rt.") + Component + Suffix);
 if (getVFS().exists(P))
-  return P.str();
+  return normalizePath(P);
   }
 
   StringRef Arch = getArchNameForCompilerRTLib(*this, Args);
   const char *Env = TT.isAndroid() ? "-android" : "";
   SmallString<128> Path(getCompilerRTPath());
   llvm::sys::path::append(Path, Prefix + Twine("clang_rt.") + Component + "-" +
 Arch + Env + Suffix);
-  return Path.str();
+  return normalizePath(Path);
 }
 
 const char *

r345371 - Update the example of BS_Stroustrup to match what is done by clang-format

2018-10-26 Thread Sylvestre Ledru via cfe-commits
Author: sylvestre
Date: Fri Oct 26 00:25:37 2018
New Revision: 345371

URL: http://llvm.org/viewvc/llvm-project?rev=345371&view=rev
Log:
Update the example of BS_Stroustrup to match what is done by clang-format

Summary:
reported here https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=911561

clang-format-7 -style="{BreakBeforeBraces: Stroustrup}" wasn't doing
the same as the doc

Reviewers: krasimir

Reviewed By: krasimir

Subscribers: cfe-commits

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

Modified:
cfe/trunk/docs/ClangFormatStyleOptions.rst
cfe/trunk/include/clang/Format/Format.h

Modified: cfe/trunk/docs/ClangFormatStyleOptions.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ClangFormatStyleOptions.rst?rev=345371&r1=345370&r2=345371&view=diff
==
--- cfe/trunk/docs/ClangFormatStyleOptions.rst (original)
+++ cfe/trunk/docs/ClangFormatStyleOptions.rst Fri Oct 26 00:25:37 2018
@@ -908,20 +908,17 @@ the configuration (without a prefix: ``A
 
   try {
 foo();
-  } catch () {
+  }
+  catch () {
   }
   void foo() { bar(); }
-  class foo
-  {
+  class foo {
   };
   if (foo()) {
-  } else {
   }
-  enum X : int
-  {
-A,
-B
-  };
+  else {
+  }
+  enum X : int { A, B };
 
   * ``BS_Allman`` (in configuration: ``Allman``)
 Always break before braces.

Modified: cfe/trunk/include/clang/Format/Format.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Format/Format.h?rev=345371&r1=345370&r2=345371&view=diff
==
--- cfe/trunk/include/clang/Format/Format.h (original)
+++ cfe/trunk/include/clang/Format/Format.h Fri Oct 26 00:25:37 2018
@@ -533,20 +533,17 @@ struct FormatStyle {
 /// \code
 ///   try {
 /// foo();
-///   } catch () {
+///   }
+///   catch () {
 ///   }
 ///   void foo() { bar(); }
-///   class foo
-///   {
+///   class foo {
 ///   };
 ///   if (foo()) {
-///   } else {
 ///   }
-///   enum X : int
-///   {
-/// A,
-/// B
-///   };
+///   else {
+///   }
+///   enum X : int { A, B };
 /// \endcode
 BS_Stroustrup,
 /// Always break before braces.


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


[PATCH] D53520: Update the example of BS_Stroustrup to match what is done by clang-format

2018-10-26 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL345371: Update the example of BS_Stroustrup to match what is 
done by clang-format (authored by sylvestre, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D53520

Files:
  cfe/trunk/docs/ClangFormatStyleOptions.rst
  cfe/trunk/include/clang/Format/Format.h


Index: cfe/trunk/docs/ClangFormatStyleOptions.rst
===
--- cfe/trunk/docs/ClangFormatStyleOptions.rst
+++ cfe/trunk/docs/ClangFormatStyleOptions.rst
@@ -908,20 +908,17 @@
 
   try {
 foo();
-  } catch () {
+  }
+  catch () {
   }
   void foo() { bar(); }
-  class foo
-  {
+  class foo {
   };
   if (foo()) {
-  } else {
   }
-  enum X : int
-  {
-A,
-B
-  };
+  else {
+  }
+  enum X : int { A, B };
 
   * ``BS_Allman`` (in configuration: ``Allman``)
 Always break before braces.
Index: cfe/trunk/include/clang/Format/Format.h
===
--- cfe/trunk/include/clang/Format/Format.h
+++ cfe/trunk/include/clang/Format/Format.h
@@ -533,20 +533,17 @@
 /// \code
 ///   try {
 /// foo();
-///   } catch () {
+///   }
+///   catch () {
 ///   }
 ///   void foo() { bar(); }
-///   class foo
-///   {
+///   class foo {
 ///   };
 ///   if (foo()) {
-///   } else {
 ///   }
-///   enum X : int
-///   {
-/// A,
-/// B
-///   };
+///   else {
+///   }
+///   enum X : int { A, B };
 /// \endcode
 BS_Stroustrup,
 /// Always break before braces.


Index: cfe/trunk/docs/ClangFormatStyleOptions.rst
===
--- cfe/trunk/docs/ClangFormatStyleOptions.rst
+++ cfe/trunk/docs/ClangFormatStyleOptions.rst
@@ -908,20 +908,17 @@
 
   try {
 foo();
-  } catch () {
+  }
+  catch () {
   }
   void foo() { bar(); }
-  class foo
-  {
+  class foo {
   };
   if (foo()) {
-  } else {
   }
-  enum X : int
-  {
-A,
-B
-  };
+  else {
+  }
+  enum X : int { A, B };
 
   * ``BS_Allman`` (in configuration: ``Allman``)
 Always break before braces.
Index: cfe/trunk/include/clang/Format/Format.h
===
--- cfe/trunk/include/clang/Format/Format.h
+++ cfe/trunk/include/clang/Format/Format.h
@@ -533,20 +533,17 @@
 /// \code
 ///   try {
 /// foo();
-///   } catch () {
+///   }
+///   catch () {
 ///   }
 ///   void foo() { bar(); }
-///   class foo
-///   {
+///   class foo {
 ///   };
 ///   if (foo()) {
-///   } else {
 ///   }
-///   enum X : int
-///   {
-/// A,
-/// B
-///   };
+///   else {
+///   }
+///   enum X : int { A, B };
 /// \endcode
 BS_Stroustrup,
 /// Always break before braces.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D53654: [clang] Improve ctor initializer completions.

2018-10-26 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 171259.
kadircet added a comment.

- Add a generic constructor if found none.
- format && add comments.
- Add generic constructors to tests.


Repository:
  rC Clang

https://reviews.llvm.org/D53654

Files:
  include/clang/Sema/CodeCompleteConsumer.h
  lib/Sema/SemaCodeComplete.cpp
  test/CodeCompletion/ctor-initializer.cpp
  test/CodeCompletion/ordinary-name-cxx11.cpp
  test/CodeCompletion/ordinary-name.cpp
  test/CodeCompletion/templates.cpp
  test/Index/complete-ctor-inits.cpp
  test/Index/complete-cxx-inline-methods.cpp

Index: test/Index/complete-cxx-inline-methods.cpp
===
--- test/Index/complete-cxx-inline-methods.cpp
+++ test/Index/complete-cxx-inline-methods.cpp
@@ -21,6 +21,13 @@
   int value;
   MyCls *object;
 };
+
+template 
+class X {};
+
+class Y : public X {
+  Y() : X() {}
+};
 }
 
 // RUN: c-index-test -code-completion-at=%s:4:9 -std=c++98 %s | FileCheck %s
@@ -35,10 +42,12 @@
 // CHECK-NEXT: Container Kind: StructDecl
 
 // RUN: c-index-test -code-completion-at=%s:18:41 %s | FileCheck -check-prefix=CHECK-CTOR-INIT %s
-// CHECK-CTOR-INIT: NotImplemented:{TypedText MyCls}{LeftParen (}{Placeholder args}{RightParen )} (7)
-// CHECK-CTOR-INIT: MemberRef:{TypedText object}{LeftParen (}{Placeholder args}{RightParen )} (35)
-// CHECK-CTOR-INIT: MemberRef:{TypedText value}{LeftParen (}{Placeholder args}{RightParen )} (35)
+// CHECK-CTOR-INIT: ClassDecl:{TypedText MyCls}{LeftParen (}{Placeholder MyCls}{RightParen )} (40)
+// CHECK-CTOR-INIT: MemberRef:{TypedText object}{LeftParen (}{Placeholder MyCls *}{RightParen )} (35)
+// CHECK-CTOR-INIT: MemberRef:{TypedText value}{LeftParen (}{Placeholder int}{RightParen )} (35)
 // RUN: c-index-test -code-completion-at=%s:18:55 %s | FileCheck -check-prefix=CHECK-CTOR-INIT-2 %s
-// CHECK-CTOR-INIT-2-NOT: NotImplemented:{TypedText MyCls}{LeftParen (}{Placeholder args}{RightParen )}
-// CHECK-CTOR-INIT-2: MemberRef:{TypedText object}{LeftParen (}{Placeholder args}{RightParen )} (35)
-// CHECK-CTOR-INIT-2: MemberRef:{TypedText value}{LeftParen (}{Placeholder args}{RightParen )} (7)
+// CHECK-CTOR-INIT-2-NOT: ClassDecl:{TypedText MyCls}{LeftParen (}{Placeholder MyCls}{RightParen )} (40)
+// CHECK-CTOR-INIT-2: MemberRef:{TypedText object}{LeftParen (}{Placeholder MyCls *}{RightParen )} (35)
+// CHECK-CTOR-INIT-2: MemberRef:{TypedText value}{LeftParen (}{Placeholder int}{RightParen )} (35)
+// RUN: c-index-test -code-completion-at=%s:29:9 %s | FileCheck -check-prefix=CHECK-CTOR-INIT-3 %s
+// CHECK-CTOR-INIT-3: ClassDecl:{TypedText X}{LeftParen (}{Placeholder X}{RightParen )} (40)
Index: test/Index/complete-ctor-inits.cpp
===
--- test/Index/complete-ctor-inits.cpp
+++ test/Index/complete-ctor-inits.cpp
@@ -30,27 +30,33 @@
 };
 
 // RUN: c-index-test -code-completion-at=%s:18:10 %s | FileCheck -check-prefix=CHECK-CC1 %s
-// CHECK-CC1: MemberRef:{TypedText a}{LeftParen (}{Placeholder args}{RightParen )} (35)
-// CHECK-CC1: MemberRef:{TypedText b}{LeftParen (}{Placeholder args}{RightParen )} (35)
-// CHECK-CC1: MemberRef:{TypedText c}{LeftParen (}{Placeholder args}{RightParen )} (35)
-// CHECK-CC1: NotImplemented:{TypedText Virt}{LeftParen (}{Placeholder args}{RightParen )} (35)
-// CHECK-CC1: NotImplemented:{TypedText X}{LeftParen (}{Placeholder args}{RightParen )} (7)
-// CHECK-CC1: NotImplemented:{TypedText Y}{LeftParen (}{Placeholder args}{RightParen )} (35)
+// CHECK-CC1: MemberRef:{TypedText a}{LeftParen (}{Placeholder int}{RightParen )} (35)
+// CHECK-CC1: MemberRef:{TypedText b}{LeftParen (}{Placeholder int}{RightParen )} (35)
+// CHECK-CC1: MemberRef:{TypedText c}{LeftParen (}{Placeholder int}{RightParen )} (35)
+// CHECK-CC1: CXXConstructor:{TypedText Virt}{LeftParen (}{Placeholder const Virt &}{RightParen )} (35)
+// CHECK-CC1: CXXConstructor:{TypedText Virt}{LeftParen (}{Placeholder Virt &&}{RightParen )} (35)
+// CHECK-CC1: CXXConstructor:{TypedText X}{LeftParen (}{Placeholder int}{RightParen )} (7)
+// CHECK-CC1: CXXConstructor:{TypedText Y}{LeftParen (}{Placeholder const Y &}{RightParen )} (35)
+// CHECK-CC1: CXXConstructor:{TypedText Y}{LeftParen (}{Placeholder Y &&}{RightParen )} (35)
 
 // RUN: c-index-test -code-completion-at=%s:18:23 %s | FileCheck -check-prefix=CHECK-CC2 %s
-// CHECK-CC2: MemberRef:{TypedText a}{LeftParen (}{Placeholder args}{RightParen )} (35)
-// CHECK-CC2: MemberRef:{TypedText b}{LeftParen (}{Placeholder args}{RightParen )} (35)
-// CHECK-CC2: MemberRef:{TypedText c}{LeftParen (}{Placeholder args}{RightParen )} (35)
-// CHECK-CC2: NotImplemented:{TypedText Virt}{LeftParen (}{Placeholder args}{RightParen )} (35)
-// CHECK-CC2: NotImplemented:{TypedText Y}{LeftParen (}{Placeholder args}{RightParen )} (7)
+// CHECK-CC2: MemberRef:{TypedText a}{LeftParen (}{Placeholder int}{RightParen )} (35)
+// CHECK-CC2: MemberRef:{TypedText b}{LeftParen (}{Placeholder int}{RightPar

r345372 - Revert "Reapply: [Driver] Use forward slashes in most linker arguments"

2018-10-26 Thread Martin Storsjo via cfe-commits
Author: mstorsjo
Date: Fri Oct 26 01:33:29 2018
New Revision: 345372

URL: http://llvm.org/viewvc/llvm-project?rev=345372&view=rev
Log:
Revert "Reapply: [Driver] Use forward slashes in most linker arguments"

This reverts commit r345370, as it uncovered even more issues in
tests with partial/inconsistent path normalization:
http://lab.llvm.org:8011/builders/llvm-clang-x86_64-expensive-checks-win/builds/13562
http://lab.llvm.org:8011/builders/clang-x64-windows-msvc/builds/886
http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast/builds/20994

In particular, these tests seem to have failed:
Clang :: CodeGen/thinlto-diagnostic-handler-remarks-with-hotness.ll
Clang :: CodeGen/thinlto-multi-module.ll
Clang :: Driver/cuda-external-tools.cu
Clang :: Driver/cuda-options.cu
Clang :: Driver/hip-toolchain-no-rdc.hip
Clang :: Driver/hip-toolchain-rdc.hip
Clang :: Driver/openmp-offload-gpu.c

At least the Driver tests could potentially be fixed by extending
the path normalization to even more places, but the issues with the
CodeGen tests are still unknown.

In addition, a number of other tests seem to have been broken in
other clang dependent tools such as clang-tidy and clangd.

Modified:
cfe/trunk/include/clang/Driver/ToolChain.h
cfe/trunk/lib/Driver/Driver.cpp
cfe/trunk/lib/Driver/ToolChain.cpp
cfe/trunk/lib/Driver/ToolChains/Clang.cpp
cfe/trunk/lib/Driver/ToolChains/CommonArgs.cpp
cfe/trunk/lib/Driver/ToolChains/Gnu.cpp

Modified: cfe/trunk/include/clang/Driver/ToolChain.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/ToolChain.h?rev=345372&r1=345371&r2=345372&view=diff
==
--- cfe/trunk/include/clang/Driver/ToolChain.h (original)
+++ cfe/trunk/include/clang/Driver/ToolChain.h Fri Oct 26 01:33:29 2018
@@ -21,7 +21,6 @@
 #include "llvm/ADT/Triple.h"
 #include "llvm/MC/MCTargetOptions.h"
 #include "llvm/Option/Option.h"
-#include "llvm/Support/Path.h"
 #include "llvm/Support/VersionTuple.h"
 #include "llvm/Target/TargetOptions.h"
 #include 
@@ -371,12 +370,6 @@ public:
  StringRef Component,
  bool Shared = false) const;
 
-  std::string normalizePath(StringRef Path) const {
-if (!Triple.isOSWindows() || Triple.isOSCygMing())
-  return llvm::sys::path::convert_to_slash(Path);
-return Path;
-  }
-
   // Returns /lib//.  This is used by runtimes (such
   // as OpenMP) to find arch-specific libraries.
   std::string getArchSpecificLibPath() const;

Modified: cfe/trunk/lib/Driver/Driver.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Driver.cpp?rev=345372&r1=345371&r2=345372&view=diff
==
--- cfe/trunk/lib/Driver/Driver.cpp (original)
+++ cfe/trunk/lib/Driver/Driver.cpp Fri Oct 26 01:33:29 2018
@@ -1011,12 +1011,6 @@ Compilation *Driver::BuildCompilation(Ar
 .Default(SaveTempsCwd);
   }
 
-  llvm::Triple EffectiveTriple = computeTargetTriple(*this, TargetTriple, 
Args);
-  if (!EffectiveTriple.isOSWindows() || EffectiveTriple.isOSCygMing()) {
-for (auto *Str : {&Dir, &InstalledDir, &SysRoot, &ResourceDir})
-  *Str = llvm::sys::path::convert_to_slash(*Str);
-  }
-
   setLTOMode(Args);
 
   // Process -fembed-bitcode= flags.

Modified: cfe/trunk/lib/Driver/ToolChain.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChain.cpp?rev=345372&r1=345371&r2=345372&view=diff
==
--- cfe/trunk/lib/Driver/ToolChain.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChain.cpp Fri Oct 26 01:33:29 2018
@@ -376,10 +376,9 @@ std::string ToolChain::getCompilerRT(con
 
   for (const auto &LibPath : getLibraryPaths()) {
 SmallString<128> P(LibPath);
-llvm::sys::path::append(P,
-Prefix + Twine("clang_rt.") + Component + Suffix);
+llvm::sys::path::append(P, Prefix + Twine("clang_rt.") + Component + 
Suffix);
 if (getVFS().exists(P))
-  return normalizePath(P);
+  return P.str();
   }
 
   StringRef Arch = getArchNameForCompilerRTLib(*this, Args);
@@ -387,7 +386,7 @@ std::string ToolChain::getCompilerRT(con
   SmallString<128> Path(getCompilerRTPath());
   llvm::sys::path::append(Path, Prefix + Twine("clang_rt.") + Component + "-" +
 Arch + Env + Suffix);
-  return normalizePath(Path);
+  return Path.str();
 }
 
 const char *ToolChain::getCompilerRTArgString(const llvm::opt::ArgList &Args,
@@ -426,7 +425,7 @@ Tool *ToolChain::SelectTool(const JobAct
 }
 
 std::string ToolChain::GetFilePath(const char *Name) const {
-  return normalizePath(D.GetFilePath(Name, *this));
+  return D.GetFilePath(Name, *this);
 }
 
 std::string ToolChain::GetProgramPath(const char *Name) const {
@@ -775,14 +774,1

[PATCH] D53066: [Driver] Use forward slashes in most linker arguments

2018-10-26 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo reopened this revision.
mstorsjo added a comment.
This revision is now accepted and ready to land.

Nope, still no really working properly with all the tests out there (I had only 
run the Driver subdirectory since I'm only testing in a very underpowered VM, 
and it had skipped the cuda/hip tests which also seemed to have a few issues):
http://lab.llvm.org:8011/builders/llvm-clang-x86_64-expensive-checks-win/builds/13562
http://lab.llvm.org:8011/builders/clang-x64-windows-msvc/builds/886
http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast/builds/20994

I could potentially make all the tests in Driver work by continuing doing 
whack-a-mole for normalizing all paths in places where they are matched in 
tests, but this also failed some tests in CodeGen/thinlto which I haven't 
studied closer yet. It also seems to break tests in clang-tidy/clangd. So this 
doesn't really seem sustainable unless we do it completely thoroughly all over 
the place, but given cross-project dependencies, it looks like that is a much 
much larger scope change that I probably don't have time to pusue.

What other options are there? The actual original problem (libtool) I'm trying 
to solve only requires paths in this form in the output of `clang -v` (for 
linking). I guess that one could be worked around by scaling the change back to 
one of the original versions where I only changed a couple paths, and making 
that change conditional on `-v` being set (plus conditional on target as it is 
right now). Having that behave differently than `-###` as used in most tests, 
isn't really nice though, but if we change the output of `-###`, we're back at 
whack-a-mole.


Repository:
  rL LLVM

https://reviews.llvm.org/D53066



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


[PATCH] D53751: [ASTImporter] Added Import functions for transition to new API.

2018-10-26 Thread Balázs Kéri via Phabricator via cfe-commits
balazske created this revision.
Herald added subscribers: cfe-commits, Szelethus, martong, dkrupp.
Herald added a reviewer: a.sidorin.

These Import_New functions should be used in the ASTImporter,
and the old Import functions should not be used. Later the
Import_New should be renamed to Import again and the old Import
functions must be removed. But this can happen only after LLDB
was updated to use the new Import interface.

This commit is only about introducing the new Import_New
functions. These are not implemented now, only calling the old
Import ones.


Repository:
  rC Clang

https://reviews.llvm.org/D53751

Files:
  include/clang/AST/ASTImporter.h
  lib/AST/ASTImporter.cpp

Index: lib/AST/ASTImporter.cpp
===
--- lib/AST/ASTImporter.cpp
+++ lib/AST/ASTImporter.cpp
@@ -7656,6 +7656,12 @@
 
 ASTImporter::~ASTImporter() = default;
 
+Expected ASTImporter::Import_New(QualType FromT) {
+  QualType ToT = Import(FromT);
+  if (ToT.isNull() && !FromT.isNull())
+return make_error();
+  return ToT;
+}
 QualType ASTImporter::Import(QualType FromT) {
   if (FromT.isNull())
 return {};
@@ -7682,6 +7688,12 @@
   return ToContext.getQualifiedType(*ToTOrErr, FromT.getLocalQualifiers());
 }
 
+Expected ASTImporter::Import_New(TypeSourceInfo *FromTSI) {
+  TypeSourceInfo *ToTSI = Import(FromTSI);
+  if (!ToTSI && FromTSI)
+return llvm::make_error();
+  return ToTSI;
+}
 TypeSourceInfo *ASTImporter::Import(TypeSourceInfo *FromTSI) {
   if (!FromTSI)
 return FromTSI;
@@ -7715,6 +7727,12 @@
   }
 }
 
+Expected ASTImporter::Import_New(Decl *FromD) {
+  Decl *ToD = Import(FromD);
+  if (!ToD && FromD)
+return llvm::make_error();
+  return ToD;
+}
 Decl *ASTImporter::Import(Decl *FromD) {
   if (!FromD)
 return nullptr;
@@ -7803,13 +7821,25 @@
   return ToDC;
 }
 
+Expected ASTImporter::Import_New(Expr *FromE) {
+  Expr *ToE = Import(FromE);
+  if (!ToE && FromE)
+return llvm::make_error();
+  return ToE;
+}
 Expr *ASTImporter::Import(Expr *FromE) {
   if (!FromE)
 return nullptr;
 
   return cast_or_null(Import(cast(FromE)));
 }
 
+Expected ASTImporter::Import_New(Stmt *FromS) {
+  Stmt *ToS = Import(FromS);
+  if (!ToS && FromS)
+return llvm::make_error();
+  return ToS;
+}
 Stmt *ASTImporter::Import(Stmt *FromS) {
   if (!FromS)
 return nullptr;
@@ -7845,6 +7875,12 @@
   return *ToSOrErr;
 }
 
+Expected ASTImporter::Import_New(NestedNameSpecifier *FromNNS) {
+  NestedNameSpecifier *ToNNS = Import(FromNNS);
+  if (!ToNNS && FromNNS)
+return llvm::make_error();
+  return ToNNS;
+}
 NestedNameSpecifier *ASTImporter::Import(NestedNameSpecifier *FromNNS) {
   if (!FromNNS)
 return nullptr;
@@ -7898,6 +7934,10 @@
   llvm_unreachable("Invalid nested name specifier kind");
 }
 
+Expected ASTImporter::Import_New(NestedNameSpecifierLoc FromNNS) {
+  NestedNameSpecifierLoc ToNNS = Import(FromNNS);
+  return ToNNS;
+}
 NestedNameSpecifierLoc ASTImporter::Import(NestedNameSpecifierLoc FromNNS) {
   // Copied from NestedNameSpecifier mostly.
   SmallVector NestedNames;
@@ -7969,6 +8009,12 @@
   return Builder.getWithLocInContext(getToContext());
 }
 
+Expected ASTImporter::Import_New(TemplateName From) {
+  TemplateName To = Import(From);
+  if (To.isNull() && !From.isNull())
+return llvm::make_error();
+  return To;
+}
 TemplateName ASTImporter::Import(TemplateName From) {
   switch (From.getKind()) {
   case TemplateName::Template:
@@ -8059,6 +8105,12 @@
   llvm_unreachable("Invalid template name kind");
 }
 
+Expected ASTImporter::Import_New(SourceLocation FromLoc) {
+  SourceLocation ToLoc = Import(FromLoc);
+  if (ToLoc.isInvalid() && !FromLoc.isInvalid())
+return llvm::make_error();
+  return ToLoc;
+}
 SourceLocation ASTImporter::Import(SourceLocation FromLoc) {
   if (FromLoc.isInvalid())
 return {};
@@ -8073,10 +8125,20 @@
   return ToSM.getComposedLoc(ToFileID, Decomposed.second);
 }
 
+Expected ASTImporter::Import_New(SourceRange FromRange) {
+  SourceRange ToRange = Import(FromRange);
+  return ToRange;
+}
 SourceRange ASTImporter::Import(SourceRange FromRange) {
   return SourceRange(Import(FromRange.getBegin()), Import(FromRange.getEnd()));
 }
 
+Expected ASTImporter::Import_New(FileID FromID) {
+  FileID ToID = Import(FromID);
+  if (ToID.isInvalid() && FromID.isValid())
+return llvm::make_error();
+  return ToID;
+}
 FileID ASTImporter::Import(FileID FromID) {
   llvm::DenseMap::iterator Pos = ImportedFileIDs.find(FromID);
   if (Pos != ImportedFileIDs.end())
@@ -8134,6 +8196,12 @@
   return ToID;
 }
 
+Expected ASTImporter::Import_New(CXXCtorInitializer *From) {
+  CXXCtorInitializer *To = Import(From);
+  if (!To && From)
+return llvm::make_error();
+  return To;
+}
 CXXCtorInitializer *ASTImporter::Import(CXXCtorInitializer *From) {
   Expr *ToExpr = Import(From->getInit());
   if (!ToExpr && From->getInit())
@@ -8179,6 +8247,12 @@
   }
 }
 
+Expected ASTImporter::Import_New(const CXXBa

[PATCH] D53655: [ASTImporter] Fix redecl chain of classes and class templates

2018-10-26 Thread Balázs Kéri via Phabricator via cfe-commits
balazske added inline comments.



Comment at: lib/AST/ASTImporter.cpp:5054
+if (!ToTemplated->getPreviousDecl()) {
+  auto *PrevTemplated = 
FoundByLookup->getTemplatedDecl()->getMostRecentDecl();
+  if (ToTemplated != PrevTemplated)

This is a long line that should be split.


Repository:
  rC Clang

https://reviews.llvm.org/D53655



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


[PATCH] D53738: [Fixed Point Arithmetic] Fixed Point Addition

2018-10-26 Thread Bevin Hansson via Phabricator via cfe-commits
ebevhan added a comment.

I think I've already expressed that I'm not at all a fan of encoding the 
full-precision logic in the operations themselves and not explicitly in the 
AST. We already have (well, not yet, but we will) routines for emitting 
conversions to/from/between fixed-point types of arbitrary semantics - why not 
use that instead of reimplementing the same logic for every binary operation?

As it is now, EmitFixedPointAdd replicates the logic for both converting from 
integer to fixed-point and fixed-point to fixed-point. You mention a special 
case with saturating addition, but this special case only exists because the 
routine needs to do fixed-point->saturating fixed-point on its own. If all 
EmitFixedPointAdd did was perform an add between two fixed-point values with 
the same semantics, then the logic would be much simpler and the act of 
conversion would be delegated to the routines that actually handle it.

I want to float the idea again of adding an AST type to encapsulate an 
arbitrary fixed-point semantic and using that as the 'common type' for binary 
operations involving fixed-point types. This would enable 
UsualArithmeticConversions to handle fixed-point types similarly to how it does 
today (find the 'common' full precision type, implicitly cast the LHS and RHS 
if necessary). There is one new thing that it would have to do; the result 
after the operation should not be the full precision type, but rather be casted 
to the operand type of highest rank. I don't think the existing code in 
SemaExpr can handle the case of adding an implicit cast after the operation. I 
don't think it should be hard to add, though.




Comment at: clang/lib/Sema/SemaExpr.cpp:1393
+/// rules in N1169 4.1.4.
+QualType Sema::FixedPointConversions(ExprResult &FixedExpr,
+ ExprResult &OtherExpr, bool IsCompAssign) 
{

I'm not sure I understand why this is in a separate function. What part of this 
doesn't work in UsualArithmeticConversions, in a 'handleFixedPointConversion' 
similar to the other cases?



Comment at: clang/lib/Sema/SemaExpr.cpp:1416
+  // converted to its corresponding signed fixed-point type and the resulting
+  // type is the type of the converted operand.
+  if (OtherTy->isSignedFixedPointType() &&

I feel like this logic can be folded into the rank handling. Does it work 
properly if you give signed types higher rank than unsigned ones?



Comment at: clang/lib/Sema/SemaExpr.cpp:1435
+  // account rounding and overflow) to the precision of the resulting type.
+  if (OtherTy->isIntegerType())
+return FixedTy;

This can be avoided by making all integer types lower rank than the fixed point 
types. The rank between them doesn't matter, either; they can all be the same.


Repository:
  rC Clang

https://reviews.llvm.org/D53738



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


[PATCH] D53751: [ASTImporter] Added Import functions for transition to new API.

2018-10-26 Thread Balázs Kéri via Phabricator via cfe-commits
balazske updated this revision to Diff 171278.
balazske added a comment.

- Corrected Import_New(const Attr *)


Repository:
  rC Clang

https://reviews.llvm.org/D53751

Files:
  include/clang/AST/ASTImporter.h
  lib/AST/ASTImporter.cpp

Index: lib/AST/ASTImporter.cpp
===
--- lib/AST/ASTImporter.cpp
+++ lib/AST/ASTImporter.cpp
@@ -7656,6 +7656,12 @@
 
 ASTImporter::~ASTImporter() = default;
 
+Expected ASTImporter::Import_New(QualType FromT) {
+  QualType ToT = Import(FromT);
+  if (ToT.isNull() && !FromT.isNull())
+return make_error();
+  return ToT;
+}
 QualType ASTImporter::Import(QualType FromT) {
   if (FromT.isNull())
 return {};
@@ -7682,6 +7688,12 @@
   return ToContext.getQualifiedType(*ToTOrErr, FromT.getLocalQualifiers());
 }
 
+Expected ASTImporter::Import_New(TypeSourceInfo *FromTSI) {
+  TypeSourceInfo *ToTSI = Import(FromTSI);
+  if (!ToTSI && FromTSI)
+return llvm::make_error();
+  return ToTSI;
+}
 TypeSourceInfo *ASTImporter::Import(TypeSourceInfo *FromTSI) {
   if (!FromTSI)
 return FromTSI;
@@ -7696,8 +7708,12 @@
   T, Import(FromTSI->getTypeLoc().getBeginLoc()));
 }
 
+Expected ASTImporter::Import_New(const Attr *FromAttr) {
+  return Import(FromAttr);
+}
 Attr *ASTImporter::Import(const Attr *FromAttr) {
   Attr *ToAttr = FromAttr->clone(ToContext);
+  // NOTE: Import of SourceRange may fail.
   ToAttr->setRange(Import(FromAttr->getRange()));
   return ToAttr;
 }
@@ -7715,6 +7731,12 @@
   }
 }
 
+Expected ASTImporter::Import_New(Decl *FromD) {
+  Decl *ToD = Import(FromD);
+  if (!ToD && FromD)
+return llvm::make_error();
+  return ToD;
+}
 Decl *ASTImporter::Import(Decl *FromD) {
   if (!FromD)
 return nullptr;
@@ -7803,13 +7825,25 @@
   return ToDC;
 }
 
+Expected ASTImporter::Import_New(Expr *FromE) {
+  Expr *ToE = Import(FromE);
+  if (!ToE && FromE)
+return llvm::make_error();
+  return ToE;
+}
 Expr *ASTImporter::Import(Expr *FromE) {
   if (!FromE)
 return nullptr;
 
   return cast_or_null(Import(cast(FromE)));
 }
 
+Expected ASTImporter::Import_New(Stmt *FromS) {
+  Stmt *ToS = Import(FromS);
+  if (!ToS && FromS)
+return llvm::make_error();
+  return ToS;
+}
 Stmt *ASTImporter::Import(Stmt *FromS) {
   if (!FromS)
 return nullptr;
@@ -7845,6 +7879,12 @@
   return *ToSOrErr;
 }
 
+Expected ASTImporter::Import_New(NestedNameSpecifier *FromNNS) {
+  NestedNameSpecifier *ToNNS = Import(FromNNS);
+  if (!ToNNS && FromNNS)
+return llvm::make_error();
+  return ToNNS;
+}
 NestedNameSpecifier *ASTImporter::Import(NestedNameSpecifier *FromNNS) {
   if (!FromNNS)
 return nullptr;
@@ -7898,6 +7938,10 @@
   llvm_unreachable("Invalid nested name specifier kind");
 }
 
+Expected ASTImporter::Import_New(NestedNameSpecifierLoc FromNNS) {
+  NestedNameSpecifierLoc ToNNS = Import(FromNNS);
+  return ToNNS;
+}
 NestedNameSpecifierLoc ASTImporter::Import(NestedNameSpecifierLoc FromNNS) {
   // Copied from NestedNameSpecifier mostly.
   SmallVector NestedNames;
@@ -7969,6 +8013,12 @@
   return Builder.getWithLocInContext(getToContext());
 }
 
+Expected ASTImporter::Import_New(TemplateName From) {
+  TemplateName To = Import(From);
+  if (To.isNull() && !From.isNull())
+return llvm::make_error();
+  return To;
+}
 TemplateName ASTImporter::Import(TemplateName From) {
   switch (From.getKind()) {
   case TemplateName::Template:
@@ -8059,6 +8109,12 @@
   llvm_unreachable("Invalid template name kind");
 }
 
+Expected ASTImporter::Import_New(SourceLocation FromLoc) {
+  SourceLocation ToLoc = Import(FromLoc);
+  if (ToLoc.isInvalid() && !FromLoc.isInvalid())
+return llvm::make_error();
+  return ToLoc;
+}
 SourceLocation ASTImporter::Import(SourceLocation FromLoc) {
   if (FromLoc.isInvalid())
 return {};
@@ -8073,10 +8129,20 @@
   return ToSM.getComposedLoc(ToFileID, Decomposed.second);
 }
 
+Expected ASTImporter::Import_New(SourceRange FromRange) {
+  SourceRange ToRange = Import(FromRange);
+  return ToRange;
+}
 SourceRange ASTImporter::Import(SourceRange FromRange) {
   return SourceRange(Import(FromRange.getBegin()), Import(FromRange.getEnd()));
 }
 
+Expected ASTImporter::Import_New(FileID FromID) {
+  FileID ToID = Import(FromID);
+  if (ToID.isInvalid() && FromID.isValid())
+return llvm::make_error();
+  return ToID;
+}
 FileID ASTImporter::Import(FileID FromID) {
   llvm::DenseMap::iterator Pos = ImportedFileIDs.find(FromID);
   if (Pos != ImportedFileIDs.end())
@@ -8134,6 +8200,12 @@
   return ToID;
 }
 
+Expected ASTImporter::Import_New(CXXCtorInitializer *From) {
+  CXXCtorInitializer *To = Import(From);
+  if (!To && From)
+return llvm::make_error();
+  return To;
+}
 CXXCtorInitializer *ASTImporter::Import(CXXCtorInitializer *From) {
   Expr *ToExpr = Import(From->getInit());
   if (!ToExpr && From->getInit())
@@ -8179,6 +8251,12 @@
   }
 }
 
+Expected ASTImporter::Import_New(const CXXBaseSpecifier *From) {
+  CXXBaseSpecifier *To = Import(From);
+  if

[PATCH] D52670: [clang-tidy] Add new 'readability-uppercase-literal-suffix' check (CERT DCL16-C, MISRA C:2012, 7.3, MISRA C++:2008, 2-13-4)

2018-10-26 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri updated this revision to Diff 171279.
lebedev.ri added a comment.
This revision is now accepted and ready to land.

Finally finished creducing the issue i wasn't able to understand even after 
https://reviews.llvm.org/D53719+https://reviews.llvm.org/D53723,
and it turned out to be `hasParent()`vs.`hasAncestor()`. (all tests added)

With that fixed, i do not observe any other bugs.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D52670

Files:
  clang-tidy/cert/CERTTidyModule.cpp
  clang-tidy/cert/CMakeLists.txt
  clang-tidy/hicpp/HICPPTidyModule.cpp
  clang-tidy/readability/CMakeLists.txt
  clang-tidy/readability/IdentifierNamingCheck.cpp
  clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tidy/readability/UppercaseLiteralSuffixCheck.cpp
  clang-tidy/readability/UppercaseLiteralSuffixCheck.h
  clang-tidy/utils/ASTUtils.cpp
  clang-tidy/utils/ASTUtils.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/cert-dcl16-c.rst
  docs/clang-tidy/checks/hicpp-uppercase-literal-suffix.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/readability-uppercase-literal-suffix.rst
  test/clang-tidy/cert-uppercase-literal-suffix-integer.cpp
  
test/clang-tidy/readability-uppercase-literal-suffix-floating-point-opencl-half.cpp
  test/clang-tidy/readability-uppercase-literal-suffix-floating-point.cpp
  
test/clang-tidy/readability-uppercase-literal-suffix-hexadecimal-floating-point.cpp
  test/clang-tidy/readability-uppercase-literal-suffix-integer-custom-list.cpp
  test/clang-tidy/readability-uppercase-literal-suffix-integer-macro.cpp
  test/clang-tidy/readability-uppercase-literal-suffix-integer-ms.cpp
  test/clang-tidy/readability-uppercase-literal-suffix-integer.cpp
  test/clang-tidy/readability-uppercase-literal-suffix.h

Index: test/clang-tidy/readability-uppercase-literal-suffix.h
===
--- /dev/null
+++ test/clang-tidy/readability-uppercase-literal-suffix.h
@@ -0,0 +1,16 @@
+template 
+struct integral_constant {
+  static constexpr T value = v;
+  typedef T value_type;
+  typedef integral_constant type; // using injected-class-name
+  constexpr operator value_type() const noexcept { return value; }
+};
+
+using false_type = integral_constant;
+using true_type = integral_constant;
+
+template 
+struct is_same : false_type {};
+
+template 
+struct is_same : true_type {};
Index: test/clang-tidy/readability-uppercase-literal-suffix-integer.cpp
===
--- /dev/null
+++ test/clang-tidy/readability-uppercase-literal-suffix-integer.cpp
@@ -0,0 +1,268 @@
+// RUN: %check_clang_tidy %s readability-uppercase-literal-suffix %t -- -- -I %S
+// RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp
+// RUN: clang-tidy %t.cpp -checks='-*,readability-uppercase-literal-suffix' -fix -- -I %S
+// RUN: clang-tidy %t.cpp -checks='-*,readability-uppercase-literal-suffix' -warnings-as-errors='-*,readability-uppercase-literal-suffix' -- -I %S
+
+#include "readability-uppercase-literal-suffix.h"
+
+void integer_suffix() {
+  static constexpr auto v0 = __LINE__; // synthetic
+  static_assert(v0 == 9 || v0 == 5, "");
+
+  static constexpr auto v1 = __cplusplus; // synthetic, long
+
+  static constexpr auto v2 = 1; // no literal
+  static_assert(is_same::value, "");
+  static_assert(v2 == 1, "");
+
+  // Unsigned
+
+  static constexpr auto v3 = 1u;
+  // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: integer literal has suffix 'u', which is not uppercase
+  // CHECK-MESSAGES-NEXT: static constexpr auto v3 = 1u;
+  // CHECK-MESSAGES-NEXT: ^~
+  // CHECK-MESSAGES-NEXT: {{^ *}}U{{$}}
+  // CHECK-FIXES: static constexpr auto v3 = 1U;
+  static_assert(is_same::value, "");
+  static_assert(v3 == 1, "");
+
+  static constexpr auto v4 = 1U; // OK.
+  static_assert(is_same::value, "");
+  static_assert(v4 == 1, "");
+
+  // Long
+
+  static constexpr auto v5 = 1l;
+  // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: integer literal has suffix 'l', which is not uppercase
+  // CHECK-MESSAGES-NEXT: static constexpr auto v5 = 1l;
+  // CHECK-MESSAGES-NEXT: ^~
+  // CHECK-MESSAGES-NEXT: {{^ *}}L{{$}}
+  // CHECK-FIXES: static constexpr auto v5 = 1L;
+  static_assert(is_same::value, "");
+  static_assert(v5 == 1, "");
+
+  static constexpr auto v6 = 1L; // OK.
+  static_assert(is_same::value, "");
+  static_assert(v6 == 1, "");
+
+  // Long Long
+
+  static constexpr auto v7 = 1ll;
+  // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: integer literal has suffix 'll', which is not uppercase
+  // CHECK-MESSAGES-NEXT: static constexpr auto v7 = 1ll;
+  // CHECK-MESSAGES-NEXT: ^~~
+  // CHECK-MESSAGES-NEXT: {{^ *}}LL{{$}}
+  // CHECK-FIXES: static constexpr auto v7 = 1LL;
+  static_assert(is_same::value, "");
+  static_assert(v7 == 1, "");
+
+  static constexpr auto v8 = 1LL; // OK.
+  static_assert(is_same::value, "");
+  static_assert(v8 == 1, "");
+
+  // Unsigned Long
+
+  static constexpr auto v9 = 1ul;
+  // CHECK-MESSAGES

Re: r345330 - Add MS ABI mangling for operator<=>.

2018-10-26 Thread Peter Smith via cfe-commits
This commit, specifically the changes made to
CodeGenCXX/cxx2a-three-way-comparison.cpp, are failing on all the Arm
and AArch64 builders that run check-clang and some of the other
non-X86 builders as well like S390 and PPC.

It seems to be the // RUN: not %clang_cc1 -std=c++2a -emit-llvm %s -o
- -triple %ms_abi_triple 2>&1 | FileCheck %s --check-prefix=MSABI
that is failing. I originally thought that this was due to our
builders not having the X86 target configured but it seems to be
reproducible on an Arm v7 machine (Cortex-A72) with the X86 backend
included. The triple expands to -triple i686-pc-windows-msvc

The failure appears to be common across all builders:
/home/buildbots/ppc64le-clang-test/clang-ppc64le/llvm/tools/clang/test/CodeGenCXX/cxx2a-three-way-comparison.cpp:11:11:
error: MSABI: expected string not found in input
// MSABI: define {{.*}}@"??__MA@@QEAAXH@Z"(
  ^
:1:1: note: scanning from here
; ModuleID = 
'/home/buildbots/ppc64le-clang-test/clang-ppc64le/llvm/tools/clang/test/CodeGenCXX/cxx2a-three-way-comparison.cpp'
^
:9:23: note: possible intended match here
define dso_local x86_thiscallcc void @"??__MA@@QAEXH@Z"(%struct.A*
%this, i32) #0 align 2 {

Could you take a look?

Thanks in advance

Peter

Links to builders:
http://lab.llvm.org:8011/builders/clang-cmake-aarch64-quick
http://lab.llvm.org:8011/builders/clang-cmake-armv7-quick
http://lab.llvm.org:8011/builders/clang-s390x-linux
http://lab.llvm.org:8011/builders/clang-ppc64le-linux
On Fri, 26 Oct 2018 at 00:23, Richard Smith via cfe-commits
 wrote:
>
> I've already pointed Zach at this and I think he's going to handle it.
>
> On Thu, 25 Oct 2018 at 16:00, Nico Weber via cfe-commits 
>  wrote:
>>
>> Could you update the demangler too?
>>
>> On Thu, Oct 25, 2018 at 6:53 PM Richard Smith via cfe-commits 
>>  wrote:
>>>
>>> Author: rsmith
>>> Date: Thu Oct 25 15:51:16 2018
>>> New Revision: 345330
>>>
>>> URL: http://llvm.org/viewvc/llvm-project?rev=345330&view=rev
>>> Log:
>>> Add MS ABI mangling for operator<=>.
>>>
>>> Thanks to Cameron DaCamara at Microsoft for letting us know what their
>>> chosen mangling is here!
>>>
>>> Added:
>>> cfe/trunk/test/CodeGenCXX/mangle-ms-cxx2a.cpp
>>> Modified:
>>> cfe/trunk/lib/AST/MicrosoftMangle.cpp
>>> cfe/trunk/test/CodeGenCXX/cxx2a-three-way-comparison.cpp
>>>
>>> Modified: cfe/trunk/lib/AST/MicrosoftMangle.cpp
>>> URL: 
>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/MicrosoftMangle.cpp?rev=345330&r1=345329&r2=345330&view=diff
>>> ==
>>> --- cfe/trunk/lib/AST/MicrosoftMangle.cpp (original)
>>> +++ cfe/trunk/lib/AST/MicrosoftMangle.cpp Thu Oct 25 15:51:16 2018
>>> @@ -1240,15 +1240,8 @@ void MicrosoftCXXNameMangler::mangleOper
>>>case OO_Array_Delete: Out << "?_V"; break;
>>>//  ::= ?__L # co_await
>>>case OO_Coawait: Out << "?__L"; break;
>>> -
>>> -  case OO_Spaceship: {
>>> -// FIXME: Once MS picks a mangling, use it.
>>> -DiagnosticsEngine &Diags = Context.getDiags();
>>> -unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error,
>>> -  "cannot mangle this three-way comparison operator yet");
>>> -Diags.Report(Loc, DiagID);
>>> -break;
>>> -  }
>>> +  //  ::= ?__M # <=>
>>> +  case OO_Spaceship: Out << "?__M"; break;
>>>
>>>case OO_Conditional: {
>>>  DiagnosticsEngine &Diags = Context.getDiags();
>>>
>>> Modified: cfe/trunk/test/CodeGenCXX/cxx2a-three-way-comparison.cpp
>>> URL: 
>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/cxx2a-three-way-comparison.cpp?rev=345330&r1=345329&r2=345330&view=diff
>>> ==
>>> --- cfe/trunk/test/CodeGenCXX/cxx2a-three-way-comparison.cpp (original)
>>> +++ cfe/trunk/test/CodeGenCXX/cxx2a-three-way-comparison.cpp Thu Oct 25 
>>> 15:51:16 2018
>>> @@ -1,24 +1,28 @@
>>> -// RUN: %clang_cc1 -std=c++2a -emit-llvm %s -o - -triple 
>>> %itanium_abi_triple | FileCheck %s --check-prefix=ITANIUM
>>> -// RUN: not %clang_cc1 -std=c++2a -emit-llvm %s -o - -triple 
>>> %ms_abi_triple 2>&1 | FileCheck %s --check-prefix=MSABI
>>> +// RUN: %clang_cc1 -std=c++2a -emit-llvm %s -o - -triple 
>>> %itanium_abi_triple | FileCheck %s --check-prefixes=CHECK,ITANIUM
>>> +// RUN: %clang_cc1 -std=c++2a -emit-llvm %s -o - -triple %ms_abi_triple | 
>>> FileCheck %s --check-prefixes=CHECK,MSABI
>>>  // RUN: not %clang_cc1 -std=c++2a -emit-llvm %s -o - -triple 
>>> %itanium_abi_triple -DBUILTIN 2>&1 | FileCheck %s --check-prefix=BUILTIN
>>> -// MSABI: cannot mangle this three-way comparison operator yet
>>> +// RUN: not %clang_cc1 -std=c++2a -emit-llvm %s -o - -triple 
>>> %ms_abi_triple -DBUILTIN 2>&1 | FileCheck %s --check-prefix=BUILTIN
>>>
>>>  struct A {
>>>void operator<=>(int);
>>>  };
>>>
>>>  // ITANIUM: define {{.*}}@_ZN1AssEi(
>>> +// MSABI: define {{.*}}@"??__MA@@QEAAXH@Z"(
>>>  void A::operator<=>(int) {}
>>>
>>>  // ITANIUM: 

r345344 - [AArch64] Implement FP16FML intrinsics

2018-10-26 Thread Bryan Chan via cfe-commits
Author: bryanpkc
Date: Thu Oct 25 16:47:00 2018
New Revision: 345344

URL: http://llvm.org/viewvc/llvm-project?rev=345344&view=rev
Log:
[AArch64] Implement FP16FML intrinsics

Generate the FP16FML intrinsics into arm_neon.h (AArch64 only for now).
Add two new type modifiers to NeonEmitter to handle the new prototypes.
Define __ARM_FEATURE_FP16FML when +fp16fml is enabled and guard the
intrinsics with the macro in arm_neon.h.

Based on a patch by Gao Yiling.

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


Added:
cfe/trunk/test/CodeGen/aarch64-neon-fp16fml.c
Modified:
cfe/trunk/include/clang/Basic/arm_neon.td
cfe/trunk/include/clang/Basic/arm_neon_incl.td
cfe/trunk/lib/Basic/Targets/AArch64.cpp
cfe/trunk/lib/Basic/Targets/AArch64.h
cfe/trunk/lib/CodeGen/CGBuiltin.cpp
cfe/trunk/test/Preprocessor/aarch64-target-features.c
cfe/trunk/utils/TableGen/NeonEmitter.cpp

Modified: cfe/trunk/include/clang/Basic/arm_neon.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/arm_neon.td?rev=345344&r1=345343&r2=345344&view=diff
==
--- cfe/trunk/include/clang/Basic/arm_neon.td (original)
+++ cfe/trunk/include/clang/Basic/arm_neon.td Thu Oct 25 16:47:00 2018
@@ -206,6 +206,15 @@ def OP_DOT_LNQ
 : Op<(call "vdot", $p0, $p1,
   (bitcast $p1, (splat(bitcast "uint32x4_t", $p2), $p3)))>;
 
+def OP_FMLAL_LN : Op<(call "vfmlal_low", $p0, $p1,
+   (dup_typed $p1, (call "vget_lane", $p2, $p3)))>;
+def OP_FMLSL_LN : Op<(call "vfmlsl_low", $p0, $p1,
+   (dup_typed $p1, (call "vget_lane", $p2, $p3)))>;
+def OP_FMLAL_LN_Hi  : Op<(call "vfmlal_high", $p0, $p1,
+   (dup_typed $p1, (call "vget_lane", $p2, $p3)))>;
+def OP_FMLSL_LN_Hi  : Op<(call "vfmlsl_high", $p0, $p1,
+   (dup_typed $p1, (call "vget_lane", $p2, $p3)))>;
+
 
//===--===//
 // Instructions
 
//===--===//
@@ -1640,3 +1649,21 @@ let ArchGuard = "defined(__ARM_FEATURE_D
   // Variants indexing into a 128-bit vector are A64 only.
   def UDOT_LANEQ : SOpInst<"vdot_laneq", "dd89i", "iUiQiQUi", OP_DOT_LNQ>;
 }
+
+// v8.2-A FP16 fused multiply-add long instructions.
+let ArchGuard = "defined(__ARM_FEATURE_FP16FML) && defined(__aarch64__)" in {
+  def VFMLAL_LOW  : SInst<"vfmlal_low", "ffHH", "UiQUi">;
+  def VFMLSL_LOW  : SInst<"vfmlsl_low", "ffHH", "UiQUi">;
+  def VFMLAL_HIGH : SInst<"vfmlal_high", "ffHH", "UiQUi">;
+  def VFMLSL_HIGH : SInst<"vfmlsl_high", "ffHH", "UiQUi">;
+
+  def VFMLAL_LANE_LOW  : SOpInst<"vfmlal_lane_low", "ffH0i", "UiQUi", 
OP_FMLAL_LN>;
+  def VFMLSL_LANE_LOW  : SOpInst<"vfmlsl_lane_low", "ffH0i", "UiQUi", 
OP_FMLSL_LN>;
+  def VFMLAL_LANE_HIGH : SOpInst<"vfmlal_lane_high", "ffH0i", "UiQUi", 
OP_FMLAL_LN_Hi>;
+  def VFMLSL_LANE_HIGH : SOpInst<"vfmlsl_lane_high", "ffH0i", "UiQUi", 
OP_FMLSL_LN_Hi>;
+
+  def VFMLAL_LANEQ_LOW  : SOpInst<"vfmlal_laneq_low", "ffH1i", "UiQUi", 
OP_FMLAL_LN>;
+  def VFMLSL_LANEQ_LOW  : SOpInst<"vfmlsl_laneq_low", "ffH1i", "UiQUi", 
OP_FMLSL_LN>;
+  def VFMLAL_LANEQ_HIGH : SOpInst<"vfmlal_laneq_high", "ffH1i", "UiQUi", 
OP_FMLAL_LN_Hi>;
+  def VFMLSL_LANEQ_HIGH : SOpInst<"vfmlsl_laneq_high", "ffH1i", "UiQUi", 
OP_FMLSL_LN_Hi>;
+}

Modified: cfe/trunk/include/clang/Basic/arm_neon_incl.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/arm_neon_incl.td?rev=345344&r1=345343&r2=345344&view=diff
==
--- cfe/trunk/include/clang/Basic/arm_neon_incl.td (original)
+++ cfe/trunk/include/clang/Basic/arm_neon_incl.td Thu Oct 25 16:47:00 2018
@@ -96,6 +96,11 @@ def bitcast;
 // example: (dup $p1) -> "(uint32x2_t) {__p1, __p1}" (assuming the base type
 //  is uint32x2_t).
 def dup;
+// dup_typed - Take a vector and a scalar argument, and create a new vector of
+// the same type by duplicating the scalar value into all lanes.
+// example: (dup_typed $p1, $p2) -> "(float16x4_t) {__p2, __p2, __p2, __p2}"
+//  (assuming __p1 is float16x4_t, and __p2 is a compatible scalar).
+def dup_typed;
 // splat - Take a vector and a lane index, and return a vector of the same type
 // containing repeated instances of the source vector at the lane 
index.
 // example: (splat $p0, $p1) ->
@@ -229,6 +234,8 @@ def OP_UNAVAILABLE : Operation {
 // f: float (int args)
 // F: double (int args)
 // H: half (int args)
+// 0: half (int args), ignore 'Q' size modifier.
+// 1: half (int args), force 'Q' size modifier.
 // d: default
 // g: default, ignore 'Q' size modifier.
 // j: default, force 'Q' size modifier.

Modified: cfe/trunk/lib/Basic/Targets/AArch64.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets/AArch64.cpp?rev=345344

[PATCH] D53754: [Analyzer] Skip symbolic regions based on conjured symbols in comparison of the containers of iterators

2018-10-26 Thread Balogh , Ádám via Phabricator via cfe-commits
baloghadamsoftware created this revision.
baloghadamsoftware added a reviewer: NoQ.
baloghadamsoftware added a project: clang.
Herald added subscribers: donat.nagy, Szelethus, mikhail.ramalho, a.sidorin, 
rnkovacs, szepet, whisperity.
Herald added a reviewer: george.karpenkov.

Checking whether two regions are the same is a partially decidable problem: 
either we know for sure that they are the same or we cannot decide. A typical 
case for this are the symbolic regions based on conjured symbols. Two different 
conjured symbols are either the same or they are different. Since we cannot 
decide this and want to reduce false positives as much as possible we exclude 
these regions whenever checking whether two containers are the same at iterator 
mismatch check.


Repository:
  rC Clang

https://reviews.llvm.org/D53754

Files:
  lib/StaticAnalyzer/Checkers/IteratorChecker.cpp
  test/Analysis/mismatched-iterator.cpp


Index: test/Analysis/mismatched-iterator.cpp
===
--- test/Analysis/mismatched-iterator.cpp
+++ test/Analysis/mismatched-iterator.cpp
@@ -186,3 +186,17 @@
 *v1.cbegin();
   }
 }
+
+std::vector &return_vector_ref();
+
+void ignore_conjured1() {
+  std::vector &v1 = return_vector_ref(), &v2 = return_vector_ref();
+
+  v2.erase(v1.cbegin()); // no-warning
+}
+
+void ignore_conjured2() {
+  std::vector &v1 = return_vector_ref(), &v2 = return_vector_ref();
+
+  if (v1.cbegin() == v2.cbegin()) {} //no-warning
+}
Index: lib/StaticAnalyzer/Checkers/IteratorChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/IteratorChecker.cpp
+++ lib/StaticAnalyzer/Checkers/IteratorChecker.cpp
@@ -1093,24 +1093,57 @@
 Cont = CBOR->getSuperRegion();
   }
 
+  if (const auto *ContSym = Cont->getSymbolicBase()) {
+if (isa(ContSym->getSymbol()))
+  return;
+  }
+
   auto State = C.getState();
   const auto *Pos = getIteratorPosition(State, Iter);
-  if (Pos && Pos->getContainer() != Cont) {
+  if (!Pos)
+return;
+
+  const auto *IterCont = Pos->getContainer();
+  if (const auto *ContSym = IterCont->getSymbolicBase()) {
+if (isa(ContSym->getSymbol()))
+  return;
+  }
+
+  if (IterCont != Cont) {
 auto *N = C.generateNonFatalErrorNode(State);
 if (!N) {
   return;
 }
-reportMismatchedBug("Container accessed using foreign iterator argument.", 
Iter, Cont, C, N);
+reportMismatchedBug("Container accessed using foreign iterator argument.",
+Iter, Cont, C, N);
   }
 }
 
 void IteratorChecker::verifyMatch(CheckerContext &C, const SVal &Iter1,
   const SVal &Iter2) const {
   // Verify match between the containers of two iterators
   auto State = C.getState();
   const auto *Pos1 = getIteratorPosition(State, Iter1);
+  if (!Pos1)
+return;
+
+  const auto *IterCont1 = Pos1->getContainer();
+  if (const auto *ContSym = IterCont1->getSymbolicBase()) {
+if (isa(ContSym->getSymbol()))
+  return;
+  }
+
   const auto *Pos2 = getIteratorPosition(State, Iter2);
-  if (Pos1 && Pos2 && Pos1->getContainer() != Pos2->getContainer()) {
+  if (!Pos2)
+return;
+
+  const auto *IterCont2 = Pos2->getContainer();
+  if (const auto *ContSym = IterCont2->getSymbolicBase()) {
+if (isa(ContSym->getSymbol()))
+  return;
+  }
+
+  if (IterCont1 != IterCont2) {
 auto *N = C.generateNonFatalErrorNode(State);
 if (!N)
   return;


Index: test/Analysis/mismatched-iterator.cpp
===
--- test/Analysis/mismatched-iterator.cpp
+++ test/Analysis/mismatched-iterator.cpp
@@ -186,3 +186,17 @@
 *v1.cbegin();
   }
 }
+
+std::vector &return_vector_ref();
+
+void ignore_conjured1() {
+  std::vector &v1 = return_vector_ref(), &v2 = return_vector_ref();
+
+  v2.erase(v1.cbegin()); // no-warning
+}
+
+void ignore_conjured2() {
+  std::vector &v1 = return_vector_ref(), &v2 = return_vector_ref();
+
+  if (v1.cbegin() == v2.cbegin()) {} //no-warning
+}
Index: lib/StaticAnalyzer/Checkers/IteratorChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/IteratorChecker.cpp
+++ lib/StaticAnalyzer/Checkers/IteratorChecker.cpp
@@ -1093,24 +1093,57 @@
 Cont = CBOR->getSuperRegion();
   }
 
+  if (const auto *ContSym = Cont->getSymbolicBase()) {
+if (isa(ContSym->getSymbol()))
+  return;
+  }
+
   auto State = C.getState();
   const auto *Pos = getIteratorPosition(State, Iter);
-  if (Pos && Pos->getContainer() != Cont) {
+  if (!Pos)
+return;
+
+  const auto *IterCont = Pos->getContainer();
+  if (const auto *ContSym = IterCont->getSymbolicBase()) {
+if (isa(ContSym->getSymbol()))
+  return;
+  }
+
+  if (IterCont != Cont) {
 auto *N = C.generateNonFatalErrorNode(State);
 if (!N) {
   return;
 }
-reportMismatchedBug("Container accessed using foreign iterator arg

[PATCH] D53755: [ASTImporter] Remove import of definition from GetAlreadyImportedOrNull

2018-10-26 Thread Gabor Marton via Phabricator via cfe-commits
martong created this revision.
Herald added subscribers: cfe-commits, Szelethus, dkrupp, rnkovacs.
Herald added a reviewer: a.sidorin.

a_sidorin


Repository:
  rC Clang

https://reviews.llvm.org/D53755

Files:
  include/clang/AST/ASTImporter.h
  lib/AST/ASTImporter.cpp
  lib/AST/ExternalASTMerger.cpp


Index: lib/AST/ExternalASTMerger.cpp
===
--- lib/AST/ExternalASTMerger.cpp
+++ lib/AST/ExternalASTMerger.cpp
@@ -144,14 +144,14 @@
 }
 if (auto *ToTag = dyn_cast(To)) {
   ToTag->setHasExternalLexicalStorage();
-  ToTag->setMustBuildLookupTable();
+  ToTag->getPrimaryContext()->setMustBuildLookupTable();
   assert(Parent.CanComplete(ToTag));
 } else if (auto *ToNamespace = dyn_cast(To)) {
   ToNamespace->setHasExternalVisibleStorage();
   assert(Parent.CanComplete(ToNamespace));
 } else if (auto *ToContainer = dyn_cast(To)) {
   ToContainer->setHasExternalLexicalStorage();
-  ToContainer->setMustBuildLookupTable();
+  ToContainer->getPrimaryContext()->setMustBuildLookupTable();
   assert(Parent.CanComplete(ToContainer));
 }
 return To;
Index: lib/AST/ASTImporter.cpp
===
--- lib/AST/ASTImporter.cpp
+++ lib/AST/ASTImporter.cpp
@@ -1575,6 +1575,9 @@
 return Err;
 
   ToD = cast_or_null(Importer.GetAlreadyImportedOrNull(D));
+  if (ToD)
+if (Error Err = ASTNodeImporter(*this).ImportDefinitionIfNeeded(D, ToD))
+  return Err;
 
   return Error::success();
 }
@@ -7702,13 +7705,10 @@
   return ToAttr;
 }
 
-Decl *ASTImporter::GetAlreadyImportedOrNull(Decl *FromD) {
-  llvm::DenseMap::iterator Pos = ImportedDecls.find(FromD);
+Decl *ASTImporter::GetAlreadyImportedOrNull(const Decl *FromD) const {
+  auto Pos = ImportedDecls.find(FromD);
   if (Pos != ImportedDecls.end()) {
 Decl *ToD = Pos->second;
-// FIXME: move this call to ImportDeclParts().
-if (Error Err = ASTNodeImporter(*this).ImportDefinitionIfNeeded(FromD, 
ToD))
-  llvm::consumeError(std::move(Err));
 return ToD;
   } else {
 return nullptr;
Index: include/clang/AST/ASTImporter.h
===
--- include/clang/AST/ASTImporter.h
+++ include/clang/AST/ASTImporter.h
@@ -198,7 +198,7 @@
 /// Return the copy of the given declaration in the "to" context if
 /// it has already been imported from the "from" context.  Otherwise return
 /// NULL.
-Decl *GetAlreadyImportedOrNull(Decl *FromD);
+Decl *GetAlreadyImportedOrNull(const Decl *FromD) const;
 
 /// Import the given declaration context from the "from"
 /// AST context into the "to" AST context.


Index: lib/AST/ExternalASTMerger.cpp
===
--- lib/AST/ExternalASTMerger.cpp
+++ lib/AST/ExternalASTMerger.cpp
@@ -144,14 +144,14 @@
 }
 if (auto *ToTag = dyn_cast(To)) {
   ToTag->setHasExternalLexicalStorage();
-  ToTag->setMustBuildLookupTable();
+  ToTag->getPrimaryContext()->setMustBuildLookupTable();
   assert(Parent.CanComplete(ToTag));
 } else if (auto *ToNamespace = dyn_cast(To)) {
   ToNamespace->setHasExternalVisibleStorage();
   assert(Parent.CanComplete(ToNamespace));
 } else if (auto *ToContainer = dyn_cast(To)) {
   ToContainer->setHasExternalLexicalStorage();
-  ToContainer->setMustBuildLookupTable();
+  ToContainer->getPrimaryContext()->setMustBuildLookupTable();
   assert(Parent.CanComplete(ToContainer));
 }
 return To;
Index: lib/AST/ASTImporter.cpp
===
--- lib/AST/ASTImporter.cpp
+++ lib/AST/ASTImporter.cpp
@@ -1575,6 +1575,9 @@
 return Err;
 
   ToD = cast_or_null(Importer.GetAlreadyImportedOrNull(D));
+  if (ToD)
+if (Error Err = ASTNodeImporter(*this).ImportDefinitionIfNeeded(D, ToD))
+  return Err;
 
   return Error::success();
 }
@@ -7702,13 +7705,10 @@
   return ToAttr;
 }
 
-Decl *ASTImporter::GetAlreadyImportedOrNull(Decl *FromD) {
-  llvm::DenseMap::iterator Pos = ImportedDecls.find(FromD);
+Decl *ASTImporter::GetAlreadyImportedOrNull(const Decl *FromD) const {
+  auto Pos = ImportedDecls.find(FromD);
   if (Pos != ImportedDecls.end()) {
 Decl *ToD = Pos->second;
-// FIXME: move this call to ImportDeclParts().
-if (Error Err = ASTNodeImporter(*this).ImportDefinitionIfNeeded(FromD, ToD))
-  llvm::consumeError(std::move(Err));
 return ToD;
   } else {
 return nullptr;
Index: include/clang/AST/ASTImporter.h
===
--- include/clang/AST/ASTImporter.h
+++ include/clang/AST/ASTImporter.h
@@ -198,7 +198,7 @@
 /// Return the copy of the given declaration in the "to" context if
 /// it has already been imported from the "from" context.  Otherwise return
 /// NULL.
-Decl *GetAlreadyImportedOrNul

[PATCH] D53025: [clang-tidy] implement new check for const return types.

2018-10-26 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel added a comment.

Thanks!  What's the next step in the process? Does someone need to approve this 
change?


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D53025



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


[PATCH] D53755: [ASTImporter] Remove import of definition from GetAlreadyImportedOrNull

2018-10-26 Thread Gabor Marton via Phabricator via cfe-commits
martong added a comment.

This is about to make `GetAlreadyImportedOrNull` to be a const function, as it 
should be naturally. This is a query function which should not initiate other 
imports.


Repository:
  rC Clang

https://reviews.llvm.org/D53755



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


[PATCH] D53025: [clang-tidy] implement new check for const return types.

2018-10-26 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added inline comments.



Comment at: clang-tidy/readability/ConstValueReturnCheck.cpp:54
+
+namespace {
+

Extend the namespace /\ above, so that function is also covered?



Comment at: clang-tidy/readability/ConstValueReturnCheck.h:19-20
+
+/// Suggests removal of the `const` qualifier from any function that returns a
+/// const type.
+///

It isn't immediately clear whether this is talking about
```
const T func();
```
or
```
T func() const; // member function
```
I'd suggest to emphasize that this is about the const on the return type, not 
on the function.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D53025



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


[PATCH] D52615: Handle -fsanitize-address-poison-class-member-array-new-cookie in the driver and propagate it to cc1

2018-10-26 Thread Filipe Cabecinhas via Phabricator via cfe-commits
filcab added a comment.

In https://reviews.llvm.org/D52615#1276938, @rjmccall wrote:

> In https://reviews.llvm.org/D52615#1275946, @filcab wrote:
>
> > In https://reviews.llvm.org/D52615#1272725, @rjmccall wrote:
> >
> > > In https://reviews.llvm.org/D52615#1266320, @filcab wrote:
> > >
> > > > In https://reviews.llvm.org/D52615#1254567, @rsmith wrote:
> > > >
> > > > > This seems like an unreasonably long flag name. Can you try to find a 
> > > > > shorter name for it?
> > > >
> > > >
> > > > `-fsanitize-poison-extra-operator-new`?
> > > >  Not as explicit, but maybe ok if documented?
> > >
> > >
> > > `-fsanitize-address-poison-array-cookie`?
> >
> >
> > I strongly dislike this one because "poison array cookie", in general, is 
> > always enabled (it's actually triggered by a runtime flag). This flag is 
> > about poisoning it in more cases (cases where the standard doesn't 
> > completely disallow accesses to the cookie, so we have to have a flag and 
> > can't enable it all the time).
>
>
> Hmm.  This naming discussion might be a proxy for another debate.  I 
> understand the argument that programs are allowed to assume a particular C++ 
> ABI and therefore access the array cookie.  And I can understand having an 
> option that makes ASan stricter and disallow accessing the array cookie 
> anyway.  But I don't understand why this analysis is in any way 
> case-specific, and the discussion you've linked doesn't seem particularly 
> clarifying about that point.  Can you explain this a little?


If you don't have a class-member operator new[], then you don't expect to be 
able to have access to the memory occupied by the array cookie, since you never 
"see" a pointer that points to it.
But if you have a class-member operator new[], then you can keep a copy of all 
the pointers you've returned, and you're allowed to read from them, even if 
they contain an array cookie (you're just reading from memory you've returned 
to users).
With this flag, we disallow this second case, at the expense of having ASan 
trigger an error on code that is standards compliant. We're making it more 
strict, therefore we start emitting ASan errors on the test I was removing in 
https://reviews.llvm.org/D41664. Kostya's comment on me removing that test was 
that the code is valid, so ASan shouldn't reject it by default (but ok to have 
flags that make it more strict).

Thank you,
Filipe

P.S: We still have "placement new" (`::operator new[](size_t, void*)`as a 
special case, which will not have an array cookie, so we don't poison it. This 
flag only applies to user-defined, class-specific allocation functions.

P.P.S: Sorry if I misunderstood your question. Please let me know.


Repository:
  rC Clang

https://reviews.llvm.org/D52615



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


[PATCH] D53757: [ASTImporter] Changed use of Import to Import_New in ASTNodeImporter.

2018-10-26 Thread Balázs Kéri via Phabricator via cfe-commits
balazske created this revision.
Herald added subscribers: cfe-commits, Szelethus, martong, dkrupp.
Herald added a reviewer: a.sidorin.
Herald added a reviewer: a.sidorin.

Repository:
  rC Clang

https://reviews.llvm.org/D53757

Files:
  lib/AST/ASTImporter.cpp

Index: lib/AST/ASTImporter.cpp
===
--- lib/AST/ASTImporter.cpp
+++ lib/AST/ASTImporter.cpp
@@ -187,32 +187,20 @@
 // Use this to import pointers of specific type.
 template 
 LLVM_NODISCARD Error importInto(ImportT *&To, ImportT *From) {
-  auto ToI = Importer.Import(From);
-  if (!ToI && From)
-return make_error();
-  To = cast_or_null(ToI);
-  return Error::success();
-  // FIXME: This should be the final code.
-  //auto ToOrErr = Importer.Import(From);
-  //if (ToOrErr) {
-  //  To = cast_or_null(*ToOrErr);
-  //}
-  //return ToOrErr.takeError();
+  auto ToOrErr = Importer.Import_New(From);
+  if (ToOrErr)
+To = cast_or_null(*ToOrErr);
+  return ToOrErr.takeError();
 }
 
 // Call the import function of ASTImporter for a baseclass of type `T` and
 // cast the return value to `T`.
 template 
 Expected import(T *From) {
-  auto *To = Importer.Import(From);
-  if (!To && From)
-return make_error();
-  return cast_or_null(To);
-  // FIXME: This should be the final code.
-  //auto ToOrErr = Importer.Import(From);
-  //if (!ToOrErr)
-  //  return ToOrErr.takeError();
-  //return cast_or_null(*ToOrErr);
+  auto ToOrErr = Importer.Import_New(From);
+  if (!ToOrErr)
+return ToOrErr.takeError();
+  return cast_or_null(*ToOrErr);
 }
 
 template 
@@ -223,13 +211,7 @@
 // Call the import function of ASTImporter for type `T`.
 template 
 Expected import(const T &From) {
-  T To = Importer.Import(From);
-  T DefaultT;
-  if (To == DefaultT && !(From == DefaultT))
-return make_error();
-  return To;
-  // FIXME: This should be the final code.
-  //return Importer.Import(From);
+  return Importer.Import_New(From);
 }
 
 template 
@@ -319,8 +301,15 @@
   Importer.MapImported(FromD, ToD);
   ToD->IdentifierNamespace = FromD->IdentifierNamespace;
   if (FromD->hasAttrs())
-for (const Attr *FromAttr : FromD->getAttrs())
-  ToD->addAttr(Importer.Import(FromAttr));
+for (const Attr *FromAttr : FromD->getAttrs()) {
+  // FIXME: Return of the error here is not possible until store of
+  // import errors is implemented.
+  auto ToAttrOrErr = import(FromAttr);
+  if (ToAttrOrErr)
+ToD->addAttr(*ToAttrOrErr);
+  else
+llvm::consumeError(ToAttrOrErr.takeError());
+}
   if (FromD->isUsed())
 ToD->setIsUsed();
   if (FromD->isImplicit())
@@ -665,15 +654,6 @@
 FunctionDecl *FromFD);
   };
 
-// FIXME: Temporary until every import returns Expected.
-template <>
-Expected ASTNodeImporter::import(const TemplateName &From) {
-  TemplateName To = Importer.Import(From);
-  if (To.isNull() && !From.isNull())
-return make_error();
-  return To;
-}
-
 template 
 Error ASTNodeImporter::ImportTemplateArgumentListInfo(
 SourceLocation FromLAngleLoc, SourceLocation FromRAngleLoc,
@@ -1707,15 +1687,10 @@
 static Error setTypedefNameForAnonDecl(TagDecl *From, TagDecl *To,
ASTImporter &Importer) {
   if (TypedefNameDecl *FromTypedef = From->getTypedefNameForAnonDecl()) {
-Decl *ToTypedef = Importer.Import(FromTypedef);
-if (!ToTypedef)
-  return make_error();
-To->setTypedefNameForAnonDecl(cast(ToTypedef));
-// FIXME: This should be the final code.
-//if (Expected ToTypedefOrErr = Importer.Import(FromTypedef))
-//  To->setTypedefNameForAnonDecl(cast(*ToTypedefOrErr));
-//else
-//  return ToTypedefOrErr.takeError();
+if (ExpectedDecl ToTypedefOrErr = Importer.Import_New(FromTypedef))
+  To->setTypedefNameForAnonDecl(cast(*ToTypedefOrErr));
+else
+  return ToTypedefOrErr.takeError();
   }
   return Error::success();
 }
@@ -3438,9 +3413,6 @@
 // FIXME here we leak `NamedChain` which is allocated before
 return ToIndirectField;
 
-  for (const auto *Attr : D->attrs())
-ToIndirectField->addAttr(Importer.Import(Attr));
-
   ToIndirectField->setAccess(D->getAccess());
   ToIndirectField->setLexicalDeclContext(LexicalDC);
   LexicalDC->addDeclInternal(ToIndirectField);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D53754: [Analyzer] Skip symbolic regions based on conjured symbols in comparison of the containers of iterators

2018-10-26 Thread Umann Kristóf via Phabricator via cfe-commits
Szelethus added a comment.

I wonder whether a method in `MemRegion` called `isSameRegion` or 
`isSurelySameRegion` would be better. I think it's likely that there are (or 
will be) checkers that would do similar things.

Maybe something like this?

  bool MemRegion::isSurelySameRegion(const MemRegion *Other) const {
// We can't reason about symbolic regions.
if (/* this or Other is symbolic*/)
  return;
return this == Other;
  }


Repository:
  rC Clang

https://reviews.llvm.org/D53754



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


[PATCH] D53025: [clang-tidy] implement new check for const return types.

2018-10-26 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added inline comments.



Comment at: clang-tidy/readability/ConstValueReturnCheck.cpp:54
+
+namespace {
+

lebedev.ri wrote:
> Extend the namespace /\ above, so that function is also covered?
Anonymous namespaces are only for class/struct declarations. See LLVM coding 
guidelines.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D53025



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


r345380 - Revert r345330 "Add MS ABI mangling for operator<=>."

2018-10-26 Thread Hans Wennborg via cfe-commits
Author: hans
Date: Fri Oct 26 06:05:45 2018
New Revision: 345380

URL: http://llvm.org/viewvc/llvm-project?rev=345380&view=rev
Log:
Revert r345330 "Add MS ABI mangling for operator<=>."

The generated MS manglings differ between 32- and 64-bit, and the test only
expects the latter. See also the commit email thread.

> Thanks to Cameron DaCamara at Microsoft for letting us know what their
> chosen mangling is here!

Removed:
cfe/trunk/test/CodeGenCXX/mangle-ms-cxx2a.cpp
Modified:
cfe/trunk/lib/AST/MicrosoftMangle.cpp
cfe/trunk/test/CodeGenCXX/cxx2a-three-way-comparison.cpp

Modified: cfe/trunk/lib/AST/MicrosoftMangle.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/MicrosoftMangle.cpp?rev=345380&r1=345379&r2=345380&view=diff
==
--- cfe/trunk/lib/AST/MicrosoftMangle.cpp (original)
+++ cfe/trunk/lib/AST/MicrosoftMangle.cpp Fri Oct 26 06:05:45 2018
@@ -1240,8 +1240,15 @@ void MicrosoftCXXNameMangler::mangleOper
   case OO_Array_Delete: Out << "?_V"; break;
   //  ::= ?__L # co_await
   case OO_Coawait: Out << "?__L"; break;
-  //  ::= ?__M # <=>
-  case OO_Spaceship: Out << "?__M"; break;
+
+  case OO_Spaceship: {
+// FIXME: Once MS picks a mangling, use it.
+DiagnosticsEngine &Diags = Context.getDiags();
+unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error,
+  "cannot mangle this three-way comparison operator yet");
+Diags.Report(Loc, DiagID);
+break;
+  }
 
   case OO_Conditional: {
 DiagnosticsEngine &Diags = Context.getDiags();

Modified: cfe/trunk/test/CodeGenCXX/cxx2a-three-way-comparison.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/cxx2a-three-way-comparison.cpp?rev=345380&r1=345379&r2=345380&view=diff
==
--- cfe/trunk/test/CodeGenCXX/cxx2a-three-way-comparison.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/cxx2a-three-way-comparison.cpp Fri Oct 26 
06:05:45 2018
@@ -1,28 +1,24 @@
-// RUN: %clang_cc1 -std=c++2a -emit-llvm %s -o - -triple %itanium_abi_triple | 
FileCheck %s --check-prefixes=CHECK,ITANIUM
-// RUN: %clang_cc1 -std=c++2a -emit-llvm %s -o - -triple %ms_abi_triple | 
FileCheck %s --check-prefixes=CHECK,MSABI
+// RUN: %clang_cc1 -std=c++2a -emit-llvm %s -o - -triple %itanium_abi_triple | 
FileCheck %s --check-prefix=ITANIUM
+// RUN: not %clang_cc1 -std=c++2a -emit-llvm %s -o - -triple %ms_abi_triple 
2>&1 | FileCheck %s --check-prefix=MSABI
 // RUN: not %clang_cc1 -std=c++2a -emit-llvm %s -o - -triple 
%itanium_abi_triple -DBUILTIN 2>&1 | FileCheck %s --check-prefix=BUILTIN
-// RUN: not %clang_cc1 -std=c++2a -emit-llvm %s -o - -triple %ms_abi_triple 
-DBUILTIN 2>&1 | FileCheck %s --check-prefix=BUILTIN
+// MSABI: cannot mangle this three-way comparison operator yet
 
 struct A {
   void operator<=>(int);
 };
 
 // ITANIUM: define {{.*}}@_ZN1AssEi(
-// MSABI: define {{.*}}@"??__MA@@QEAAXH@Z"(
 void A::operator<=>(int) {}
 
 // ITANIUM: define {{.*}}@_Zssi1A(
-// MSABI: define {{.*}}@"??__M@YAXHUA@@@Z"(
 void operator<=>(int, A) {}
 
 int operator<=>(A, A);
 
 // ITANIUM: define {{.*}}_Z1f1A(
-// MSABI: define {{.*}}"?f@@YAHUA@@@Z"(
 int f(A a) {
   // ITANIUM: %[[RET:.*]] = call {{.*}}_Zss1AS_(
-  // MSABI: %[[RET:.*]] = call {{.*}}"??__M@YAHUA@@0@Z"(
-  // CHECK: ret i32 %[[RET]]
+  // ITANIUM: ret i32 %[[RET]]
   return a <=> a;
 }
 

Removed: cfe/trunk/test/CodeGenCXX/mangle-ms-cxx2a.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/mangle-ms-cxx2a.cpp?rev=345379&view=auto
==
--- cfe/trunk/test/CodeGenCXX/mangle-ms-cxx2a.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/mangle-ms-cxx2a.cpp (removed)
@@ -1,6 +0,0 @@
-// RUN: %clang_cc1 -std=c++2a -fms-extensions -emit-llvm %s -o - 
-triple=i386-pc-win32 -fms-compatibility-version=19.00 | FileCheck %s
-
-struct A {};
-
-// CHECK-DAG: define {{.*}} @"??__M@YAXUA@@0@Z"
-void operator<=>(A, A) {}


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


[PATCH] D52670: [clang-tidy] Add new 'readability-uppercase-literal-suffix' check (CERT DCL16-C, MISRA C:2012, 7.3, MISRA C++:2008, 2-13-4)

2018-10-26 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

Rerun on clang-tools-extra+lld+clang codebase, nothing broken.
I'm gonna reland.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D52670



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


Re: r345330 - Add MS ABI mangling for operator<=>.

2018-10-26 Thread Hans Wennborg via cfe-commits
It seems the generated MS mangling differs between 32- and 64-bit, and
the test expects the latter.

Let's revert in the meantime.. r345380


On Fri, Oct 26, 2018 at 1:10 PM, Peter Smith via cfe-commits
 wrote:
> This commit, specifically the changes made to
> CodeGenCXX/cxx2a-three-way-comparison.cpp, are failing on all the Arm
> and AArch64 builders that run check-clang and some of the other
> non-X86 builders as well like S390 and PPC.
>
> It seems to be the // RUN: not %clang_cc1 -std=c++2a -emit-llvm %s -o
> - -triple %ms_abi_triple 2>&1 | FileCheck %s --check-prefix=MSABI
> that is failing. I originally thought that this was due to our
> builders not having the X86 target configured but it seems to be
> reproducible on an Arm v7 machine (Cortex-A72) with the X86 backend
> included. The triple expands to -triple i686-pc-windows-msvc
>
> The failure appears to be common across all builders:
> /home/buildbots/ppc64le-clang-test/clang-ppc64le/llvm/tools/clang/test/CodeGenCXX/cxx2a-three-way-comparison.cpp:11:11:
> error: MSABI: expected string not found in input
> // MSABI: define {{.*}}@"??__MA@@QEAAXH@Z"(
>   ^
> :1:1: note: scanning from here
> ; ModuleID = 
> '/home/buildbots/ppc64le-clang-test/clang-ppc64le/llvm/tools/clang/test/CodeGenCXX/cxx2a-three-way-comparison.cpp'
> ^
> :9:23: note: possible intended match here
> define dso_local x86_thiscallcc void @"??__MA@@QAEXH@Z"(%struct.A*
> %this, i32) #0 align 2 {
>
> Could you take a look?
>
> Thanks in advance
>
> Peter
>
> Links to builders:
> http://lab.llvm.org:8011/builders/clang-cmake-aarch64-quick
> http://lab.llvm.org:8011/builders/clang-cmake-armv7-quick
> http://lab.llvm.org:8011/builders/clang-s390x-linux
> http://lab.llvm.org:8011/builders/clang-ppc64le-linux
> On Fri, 26 Oct 2018 at 00:23, Richard Smith via cfe-commits
>  wrote:
>>
>> I've already pointed Zach at this and I think he's going to handle it.
>>
>> On Thu, 25 Oct 2018 at 16:00, Nico Weber via cfe-commits 
>>  wrote:
>>>
>>> Could you update the demangler too?
>>>
>>> On Thu, Oct 25, 2018 at 6:53 PM Richard Smith via cfe-commits 
>>>  wrote:

 Author: rsmith
 Date: Thu Oct 25 15:51:16 2018
 New Revision: 345330

 URL: http://llvm.org/viewvc/llvm-project?rev=345330&view=rev
 Log:
 Add MS ABI mangling for operator<=>.

 Thanks to Cameron DaCamara at Microsoft for letting us know what their
 chosen mangling is here!

 Added:
 cfe/trunk/test/CodeGenCXX/mangle-ms-cxx2a.cpp
 Modified:
 cfe/trunk/lib/AST/MicrosoftMangle.cpp
 cfe/trunk/test/CodeGenCXX/cxx2a-three-way-comparison.cpp

 Modified: cfe/trunk/lib/AST/MicrosoftMangle.cpp
 URL: 
 http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/MicrosoftMangle.cpp?rev=345330&r1=345329&r2=345330&view=diff
 ==
 --- cfe/trunk/lib/AST/MicrosoftMangle.cpp (original)
 +++ cfe/trunk/lib/AST/MicrosoftMangle.cpp Thu Oct 25 15:51:16 2018
 @@ -1240,15 +1240,8 @@ void MicrosoftCXXNameMangler::mangleOper
case OO_Array_Delete: Out << "?_V"; break;
//  ::= ?__L # co_await
case OO_Coawait: Out << "?__L"; break;
 -
 -  case OO_Spaceship: {
 -// FIXME: Once MS picks a mangling, use it.
 -DiagnosticsEngine &Diags = Context.getDiags();
 -unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error,
 -  "cannot mangle this three-way comparison operator yet");
 -Diags.Report(Loc, DiagID);
 -break;
 -  }
 +  //  ::= ?__M # <=>
 +  case OO_Spaceship: Out << "?__M"; break;

case OO_Conditional: {
  DiagnosticsEngine &Diags = Context.getDiags();

 Modified: cfe/trunk/test/CodeGenCXX/cxx2a-three-way-comparison.cpp
 URL: 
 http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/cxx2a-three-way-comparison.cpp?rev=345330&r1=345329&r2=345330&view=diff
 ==
 --- cfe/trunk/test/CodeGenCXX/cxx2a-three-way-comparison.cpp (original)
 +++ cfe/trunk/test/CodeGenCXX/cxx2a-three-way-comparison.cpp Thu Oct 25 
 15:51:16 2018
 @@ -1,24 +1,28 @@
 -// RUN: %clang_cc1 -std=c++2a -emit-llvm %s -o - -triple 
 %itanium_abi_triple | FileCheck %s --check-prefix=ITANIUM
 -// RUN: not %clang_cc1 -std=c++2a -emit-llvm %s -o - -triple 
 %ms_abi_triple 2>&1 | FileCheck %s --check-prefix=MSABI
 +// RUN: %clang_cc1 -std=c++2a -emit-llvm %s -o - -triple 
 %itanium_abi_triple | FileCheck %s --check-prefixes=CHECK,ITANIUM
 +// RUN: %clang_cc1 -std=c++2a -emit-llvm %s -o - -triple %ms_abi_triple | 
 FileCheck %s --check-prefixes=CHECK,MSABI
  // RUN: not %clang_cc1 -std=c++2a -emit-llvm %s -o - -triple 
 %itanium_abi_triple -DBUILTIN 2>&1 | FileCheck %s --check-prefix=BUILTIN
 -// MSABI: cannot mangle this three-way comparison operat

[clang-tools-extra] r345381 - [clang-tidy] Re-commit: Add new 'readability-uppercase-literal-suffix' check (CERT DCL16-C, MISRA C:2012, 7.3, MISRA C++:2008, 2-13-4)

2018-10-26 Thread Roman Lebedev via cfe-commits
Author: lebedevri
Date: Fri Oct 26 06:09:27 2018
New Revision: 345381

URL: http://llvm.org/viewvc/llvm-project?rev=345381&view=rev
Log:
[clang-tidy] Re-commit: Add new 'readability-uppercase-literal-suffix' check 
(CERT DCL16-C, MISRA C:2012, 7.3, MISRA C++:2008, 2-13-4)

Summary:
Detects when the integral literal or floating point (decimal or hexadecimal)
literal has non-uppercase suffix, and suggests to make the suffix uppercase,
with fix-it.

All valid combinations of suffixes are supported.

```
  auto x = 1;  // OK, no suffix.

  auto x = 1u; // warning: integer literal suffix 'u' is not upper-case

  auto x = 1U; // OK, suffix is uppercase.

  ...
```

This is a re-commit, the original was reverted by me in
rL345305 due to discovered bugs. (implicit code, template instantiation)
Tests were added, and the bugs were fixed.
I'm unable to find any further bugs, hopefully there aren't any..

References:
* [[ https://wiki.sei.cmu.edu/confluence/pages/viewpage.action?pageId=87152241 
| CERT DCL16-C ]]
* MISRA C:2012, 7.3 - The lowercase character "l" shall not be used in a 
literal suffix
* MISRA C++:2008, 2-13-4 - Literal suffixes shall be upper case

Reviewers: JonasToth, aaron.ballman, alexfh, hokein, xazax.hun

Reviewed By: aaron.ballman

Subscribers: Eugene.Zelenko, mgorny, rnkovacs, cfe-commits

Tags: #clang-tools-extra

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

Added:

clang-tools-extra/trunk/clang-tidy/readability/UppercaseLiteralSuffixCheck.cpp
clang-tools-extra/trunk/clang-tidy/readability/UppercaseLiteralSuffixCheck.h
clang-tools-extra/trunk/docs/clang-tidy/checks/cert-dcl16-c.rst

clang-tools-extra/trunk/docs/clang-tidy/checks/hicpp-uppercase-literal-suffix.rst

clang-tools-extra/trunk/docs/clang-tidy/checks/readability-uppercase-literal-suffix.rst

clang-tools-extra/trunk/test/clang-tidy/cert-uppercase-literal-suffix-integer.cpp

clang-tools-extra/trunk/test/clang-tidy/readability-uppercase-literal-suffix-floating-point-opencl-half.cpp

clang-tools-extra/trunk/test/clang-tidy/readability-uppercase-literal-suffix-floating-point.cpp

clang-tools-extra/trunk/test/clang-tidy/readability-uppercase-literal-suffix-hexadecimal-floating-point.cpp

clang-tools-extra/trunk/test/clang-tidy/readability-uppercase-literal-suffix-integer-custom-list.cpp

clang-tools-extra/trunk/test/clang-tidy/readability-uppercase-literal-suffix-integer-macro.cpp

clang-tools-extra/trunk/test/clang-tidy/readability-uppercase-literal-suffix-integer-ms.cpp

clang-tools-extra/trunk/test/clang-tidy/readability-uppercase-literal-suffix-integer.cpp

clang-tools-extra/trunk/test/clang-tidy/readability-uppercase-literal-suffix.h
Modified:
clang-tools-extra/trunk/clang-tidy/cert/CERTTidyModule.cpp
clang-tools-extra/trunk/clang-tidy/cert/CMakeLists.txt
clang-tools-extra/trunk/clang-tidy/hicpp/HICPPTidyModule.cpp
clang-tools-extra/trunk/clang-tidy/readability/CMakeLists.txt
clang-tools-extra/trunk/clang-tidy/readability/IdentifierNamingCheck.cpp
clang-tools-extra/trunk/clang-tidy/readability/ReadabilityTidyModule.cpp
clang-tools-extra/trunk/clang-tidy/utils/ASTUtils.cpp
clang-tools-extra/trunk/clang-tidy/utils/ASTUtils.h
clang-tools-extra/trunk/docs/ReleaseNotes.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst

Modified: clang-tools-extra/trunk/clang-tidy/cert/CERTTidyModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/cert/CERTTidyModule.cpp?rev=345381&r1=345380&r2=345381&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/cert/CERTTidyModule.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/cert/CERTTidyModule.cpp Fri Oct 26 
06:09:27 2018
@@ -16,6 +16,7 @@
 #include "../misc/StaticAssertCheck.h"
 #include "../misc/ThrowByValueCatchByReferenceCheck.h"
 #include "../performance/MoveConstructorInitCheck.h"
+#include "../readability/UppercaseLiteralSuffixCheck.h"
 #include "CommandProcessorCheck.h"
 #include "DontModifyStdNamespaceCheck.h"
 #include "FloatLoopCounter.h"
@@ -65,6 +66,8 @@ public:
 // C checkers
 // DCL
 CheckFactories.registerCheck("cert-dcl03-c");
+CheckFactories.registerCheck(
+"cert-dcl16-c");
 // ENV
 CheckFactories.registerCheck("cert-env33-c");
 // FLP
@@ -78,6 +81,13 @@ public:
 CheckFactories.registerCheck(
 "cert-msc32-c");
   }
+
+  ClangTidyOptions getModuleOptions() override {
+ClangTidyOptions Options;
+ClangTidyOptions::OptionMap &Opts = Options.CheckOptions;
+Opts["cert-dcl16-c.NewSuffixes"] = "L;LL;LU;LLU";
+return Options;
+  }
 };
 
 } // namespace cert

Modified: clang-tools-extra/trunk/clang-tidy/cert/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/cert/CMakeLists.txt?rev=345381&r1=345380&r2=345381&view=diff
===

[PATCH] D53025: [clang-tidy] implement new check for const return types.

2018-10-26 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang-tidy/readability/ConstValueReturnCheck.cpp:107
+diag(Def->getInnerLocStart(), "return type %0 is 'const'-qualified "
+  "hindering compiler optimizations")
+<< Def->getReturnType();

It seems strange to me that this is in the readability module but the 
diagnostic here is about compiler optimizations. Should this be in the 
performance module instead? Or should this diagnostic be reworded about the 
readability concerns?


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D53025



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


[PATCH] D52670: [clang-tidy] Add new 'readability-uppercase-literal-suffix' check (CERT DCL16-C, MISRA C:2012, 7.3, MISRA C++:2008, 2-13-4)

2018-10-26 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL345381: [clang-tidy] Re-commit: Add new 
'readability-uppercase-literal-suffix' check… (authored by lebedevri, 
committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D52670?vs=171279&id=171290#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D52670

Files:
  clang-tools-extra/trunk/clang-tidy/cert/CERTTidyModule.cpp
  clang-tools-extra/trunk/clang-tidy/cert/CMakeLists.txt
  clang-tools-extra/trunk/clang-tidy/hicpp/HICPPTidyModule.cpp
  clang-tools-extra/trunk/clang-tidy/readability/CMakeLists.txt
  clang-tools-extra/trunk/clang-tidy/readability/IdentifierNamingCheck.cpp
  clang-tools-extra/trunk/clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tools-extra/trunk/clang-tidy/readability/UppercaseLiteralSuffixCheck.cpp
  clang-tools-extra/trunk/clang-tidy/readability/UppercaseLiteralSuffixCheck.h
  clang-tools-extra/trunk/clang-tidy/utils/ASTUtils.cpp
  clang-tools-extra/trunk/clang-tidy/utils/ASTUtils.h
  clang-tools-extra/trunk/docs/ReleaseNotes.rst
  clang-tools-extra/trunk/docs/clang-tidy/checks/cert-dcl16-c.rst
  
clang-tools-extra/trunk/docs/clang-tidy/checks/hicpp-uppercase-literal-suffix.rst
  clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/trunk/docs/clang-tidy/checks/readability-uppercase-literal-suffix.rst
  
clang-tools-extra/trunk/test/clang-tidy/cert-uppercase-literal-suffix-integer.cpp
  
clang-tools-extra/trunk/test/clang-tidy/readability-uppercase-literal-suffix-floating-point-opencl-half.cpp
  
clang-tools-extra/trunk/test/clang-tidy/readability-uppercase-literal-suffix-floating-point.cpp
  
clang-tools-extra/trunk/test/clang-tidy/readability-uppercase-literal-suffix-hexadecimal-floating-point.cpp
  
clang-tools-extra/trunk/test/clang-tidy/readability-uppercase-literal-suffix-integer-custom-list.cpp
  
clang-tools-extra/trunk/test/clang-tidy/readability-uppercase-literal-suffix-integer-macro.cpp
  
clang-tools-extra/trunk/test/clang-tidy/readability-uppercase-literal-suffix-integer-ms.cpp
  
clang-tools-extra/trunk/test/clang-tidy/readability-uppercase-literal-suffix-integer.cpp
  clang-tools-extra/trunk/test/clang-tidy/readability-uppercase-literal-suffix.h

Index: clang-tools-extra/trunk/clang-tidy/cert/CERTTidyModule.cpp
===
--- clang-tools-extra/trunk/clang-tidy/cert/CERTTidyModule.cpp
+++ clang-tools-extra/trunk/clang-tidy/cert/CERTTidyModule.cpp
@@ -16,6 +16,7 @@
 #include "../misc/StaticAssertCheck.h"
 #include "../misc/ThrowByValueCatchByReferenceCheck.h"
 #include "../performance/MoveConstructorInitCheck.h"
+#include "../readability/UppercaseLiteralSuffixCheck.h"
 #include "CommandProcessorCheck.h"
 #include "DontModifyStdNamespaceCheck.h"
 #include "FloatLoopCounter.h"
@@ -65,6 +66,8 @@
 // C checkers
 // DCL
 CheckFactories.registerCheck("cert-dcl03-c");
+CheckFactories.registerCheck(
+"cert-dcl16-c");
 // ENV
 CheckFactories.registerCheck("cert-env33-c");
 // FLP
@@ -78,6 +81,13 @@
 CheckFactories.registerCheck(
 "cert-msc32-c");
   }
+
+  ClangTidyOptions getModuleOptions() override {
+ClangTidyOptions Options;
+ClangTidyOptions::OptionMap &Opts = Options.CheckOptions;
+Opts["cert-dcl16-c.NewSuffixes"] = "L;LL;LU;LLU";
+return Options;
+  }
 };
 
 } // namespace cert
Index: clang-tools-extra/trunk/clang-tidy/cert/CMakeLists.txt
===
--- clang-tools-extra/trunk/clang-tidy/cert/CMakeLists.txt
+++ clang-tools-extra/trunk/clang-tidy/cert/CMakeLists.txt
@@ -24,5 +24,6 @@
   clangTidyGoogleModule
   clangTidyMiscModule
   clangTidyPerformanceModule
+  clangTidyReadabilityModule
   clangTidyUtils
   )
Index: clang-tools-extra/trunk/clang-tidy/hicpp/HICPPTidyModule.cpp
===
--- clang-tools-extra/trunk/clang-tidy/hicpp/HICPPTidyModule.cpp
+++ clang-tools-extra/trunk/clang-tidy/hicpp/HICPPTidyModule.cpp
@@ -35,6 +35,7 @@
 #include "../readability/BracesAroundStatementsCheck.h"
 #include "../readability/FunctionSizeCheck.h"
 #include "../readability/IdentifierNamingCheck.h"
+#include "../readability/UppercaseLiteralSuffixCheck.h"
 #include "ExceptionBaseclassCheck.h"
 #include "MultiwayPathsCoveredCheck.h"
 #include "NoAssemblerCheck.h"
@@ -100,6 +101,8 @@
 "hicpp-use-nullptr");
 CheckFactories.registerCheck(
 "hicpp-use-override");
+CheckFactories.registerCheck(
+"hicpp-uppercase-literal-suffix");
 CheckFactories.registerCheck(
 "hicpp-vararg");
   }
Index: clang-tools-extra/trunk/clang-tidy/utils/ASTUtils.h
===
--- clang-tools-extra/trunk/clang-tidy/utils/ASTUtils.h
+++ clang-tools-extra/trunk/clang-tidy/utils/ASTUtils.h
@@ -27,6 +27,18 @@
 bool exprHasBitFlagWithSpelling(const Expr *Fla

[PATCH] D53755: [ASTImporter] Remove import of definition from GetAlreadyImportedOrNull

2018-10-26 Thread Balázs Kéri via Phabricator via cfe-commits
balazske added inline comments.



Comment at: lib/AST/ASTImporter.cpp:7716
   }
 }
 

This can be simplified by removing brace characters and removing `ToD`.


Repository:
  rC Clang

https://reviews.llvm.org/D53755



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


[PATCH] D53751: [ASTImporter] Added Import functions for transition to new API.

2018-10-26 Thread Balázs Kéri via Phabricator via cfe-commits
balazske updated this revision to Diff 171292.
balazske added a comment.

- Added missing Import_New with Selector and DeclarationName.


Repository:
  rC Clang

https://reviews.llvm.org/D53751

Files:
  include/clang/AST/ASTImporter.h
  lib/AST/ASTImporter.cpp

Index: lib/AST/ASTImporter.cpp
===
--- lib/AST/ASTImporter.cpp
+++ lib/AST/ASTImporter.cpp
@@ -7656,6 +7656,12 @@
 
 ASTImporter::~ASTImporter() = default;
 
+Expected ASTImporter::Import_New(QualType FromT) {
+  QualType ToT = Import(FromT);
+  if (ToT.isNull() && !FromT.isNull())
+return make_error();
+  return ToT;
+}
 QualType ASTImporter::Import(QualType FromT) {
   if (FromT.isNull())
 return {};
@@ -7682,6 +7688,12 @@
   return ToContext.getQualifiedType(*ToTOrErr, FromT.getLocalQualifiers());
 }
 
+Expected ASTImporter::Import_New(TypeSourceInfo *FromTSI) {
+  TypeSourceInfo *ToTSI = Import(FromTSI);
+  if (!ToTSI && FromTSI)
+return llvm::make_error();
+  return ToTSI;
+}
 TypeSourceInfo *ASTImporter::Import(TypeSourceInfo *FromTSI) {
   if (!FromTSI)
 return FromTSI;
@@ -7696,8 +7708,12 @@
   T, Import(FromTSI->getTypeLoc().getBeginLoc()));
 }
 
+Expected ASTImporter::Import_New(const Attr *FromAttr) {
+  return Import(FromAttr);
+}
 Attr *ASTImporter::Import(const Attr *FromAttr) {
   Attr *ToAttr = FromAttr->clone(ToContext);
+  // NOTE: Import of SourceRange may fail.
   ToAttr->setRange(Import(FromAttr->getRange()));
   return ToAttr;
 }
@@ -7715,6 +7731,12 @@
   }
 }
 
+Expected ASTImporter::Import_New(Decl *FromD) {
+  Decl *ToD = Import(FromD);
+  if (!ToD && FromD)
+return llvm::make_error();
+  return ToD;
+}
 Decl *ASTImporter::Import(Decl *FromD) {
   if (!FromD)
 return nullptr;
@@ -7803,13 +7825,25 @@
   return ToDC;
 }
 
+Expected ASTImporter::Import_New(Expr *FromE) {
+  Expr *ToE = Import(FromE);
+  if (!ToE && FromE)
+return llvm::make_error();
+  return ToE;
+}
 Expr *ASTImporter::Import(Expr *FromE) {
   if (!FromE)
 return nullptr;
 
   return cast_or_null(Import(cast(FromE)));
 }
 
+Expected ASTImporter::Import_New(Stmt *FromS) {
+  Stmt *ToS = Import(FromS);
+  if (!ToS && FromS)
+return llvm::make_error();
+  return ToS;
+}
 Stmt *ASTImporter::Import(Stmt *FromS) {
   if (!FromS)
 return nullptr;
@@ -7845,6 +7879,12 @@
   return *ToSOrErr;
 }
 
+Expected ASTImporter::Import_New(NestedNameSpecifier *FromNNS) {
+  NestedNameSpecifier *ToNNS = Import(FromNNS);
+  if (!ToNNS && FromNNS)
+return llvm::make_error();
+  return ToNNS;
+}
 NestedNameSpecifier *ASTImporter::Import(NestedNameSpecifier *FromNNS) {
   if (!FromNNS)
 return nullptr;
@@ -7898,6 +7938,10 @@
   llvm_unreachable("Invalid nested name specifier kind");
 }
 
+Expected ASTImporter::Import_New(NestedNameSpecifierLoc FromNNS) {
+  NestedNameSpecifierLoc ToNNS = Import(FromNNS);
+  return ToNNS;
+}
 NestedNameSpecifierLoc ASTImporter::Import(NestedNameSpecifierLoc FromNNS) {
   // Copied from NestedNameSpecifier mostly.
   SmallVector NestedNames;
@@ -7969,6 +8013,12 @@
   return Builder.getWithLocInContext(getToContext());
 }
 
+Expected ASTImporter::Import_New(TemplateName From) {
+  TemplateName To = Import(From);
+  if (To.isNull() && !From.isNull())
+return llvm::make_error();
+  return To;
+}
 TemplateName ASTImporter::Import(TemplateName From) {
   switch (From.getKind()) {
   case TemplateName::Template:
@@ -8059,6 +8109,12 @@
   llvm_unreachable("Invalid template name kind");
 }
 
+Expected ASTImporter::Import_New(SourceLocation FromLoc) {
+  SourceLocation ToLoc = Import(FromLoc);
+  if (ToLoc.isInvalid() && !FromLoc.isInvalid())
+return llvm::make_error();
+  return ToLoc;
+}
 SourceLocation ASTImporter::Import(SourceLocation FromLoc) {
   if (FromLoc.isInvalid())
 return {};
@@ -8073,10 +8129,20 @@
   return ToSM.getComposedLoc(ToFileID, Decomposed.second);
 }
 
+Expected ASTImporter::Import_New(SourceRange FromRange) {
+  SourceRange ToRange = Import(FromRange);
+  return ToRange;
+}
 SourceRange ASTImporter::Import(SourceRange FromRange) {
   return SourceRange(Import(FromRange.getBegin()), Import(FromRange.getEnd()));
 }
 
+Expected ASTImporter::Import_New(FileID FromID) {
+  FileID ToID = Import(FromID);
+  if (ToID.isInvalid() && FromID.isValid())
+return llvm::make_error();
+  return ToID;
+}
 FileID ASTImporter::Import(FileID FromID) {
   llvm::DenseMap::iterator Pos = ImportedFileIDs.find(FromID);
   if (Pos != ImportedFileIDs.end())
@@ -8134,6 +8200,12 @@
   return ToID;
 }
 
+Expected ASTImporter::Import_New(CXXCtorInitializer *From) {
+  CXXCtorInitializer *To = Import(From);
+  if (!To && From)
+return llvm::make_error();
+  return To;
+}
 CXXCtorInitializer *ASTImporter::Import(CXXCtorInitializer *From) {
   Expr *ToExpr = Import(From->getInit());
   if (!ToExpr && From->getInit())
@@ -8179,6 +8251,12 @@
   }
 }
 
+Expected ASTImporter::Import_New(const CXXBaseSpecifier *From) {
+  CXXBaseSpecifier 

[PATCH] D53621: Support for groups of attributes in #pragma clang attribute

2018-10-26 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM aside from some small nits.




Comment at: clang/docs/LanguageExtensions.rst:2666
 
-  #pragma clang attribute push(__attribute__((annotate("custom"))), apply_to = 
function)
+  #pragma clang attribute push (__attribute__((annotate("custom"))), apply_to 
= function)
 

The whitespace changes here are not needed as part of this patch, right? (It's 
just changing the style of the docs?)



Comment at: clang/lib/Parse/ParsePragma.cpp:3149
   else {
-PP.Diag(Tok.getLocation(), diag::err_pragma_attribute_invalid_argument)
-<< PP.getSpelling(Tok);
-return;
+const auto *II = Tok.getIdentifierInfo();
+if (II->isStr("push"))

I'd prefer dropping the `auto` here.


https://reviews.llvm.org/D53621



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


[PATCH] D53717: [AST] Only store the needed data in ForStmt.

2018-10-26 Thread Bruno Ricci via Phabricator via cfe-commits
riccibruno added a comment.

In https://reviews.llvm.org/D53717#1276388, @rsmith wrote:

> In https://reviews.llvm.org/D53717#1276245, @rsmith wrote:
>
> > Do you have evidence that this complexity is worthwhile? (I wouldn't 
> > imagine we have very many `ForStmt`s per translation unit, so saving 16 
> > bytes for each of them seems unlikely to matter.)
>
>
> Strikes me that some data would be useful here, to help prioritize. Here's a 
> histogram of occurrence counts for a libc++ module:
>
>   Count# Bits b/Rec   % Abv  Record Kind
>   43731   5471391 125.1   87.46  EXPR_DECL_REF
>   35751822273  23.0  DECL_OMP_DECLARE_REDUCTION
>   29734   3431612 115.4  TYPE_TEMPLATE_SPECIALIZATION
>   25750   7472591 290.2   55.89  DECL_PARM_VAR
>   14986651081  43.4   98.81  EXPR_IMPLICIT_CAST
>   14847   1620549 109.1  EXPR_CALL
>   13153   1968371 149.7  TYPE_FUNCTION_PROTO
>   12605   3797017 301.2  100.00  DECL_CONTEXT_LEXICAL
>   12515715141  57.1  TYPE_TEMPLATE_TYPE_PARM
>   12480   2608644 209.0  DECL_TEMPLATE_TYPE_PARM
>   10571   1200811 113.6  EXPR_BINARY_OPERATOR
>   10300955610  92.8  STMT_COMPOUND
>   10254   9421030 918.8   17.66  DECL_CXX_METHOD
>   10220   2252926 220.4  EXPR_CXX_DEPENDENT_SCOPE_MEMBER
>   10083231909  23.0  STMT_NULL_PTR
>9731   5196865 534.1  EXPR_CXX_UNRESOLVED_LOOKUP
>8015580911  72.5   87.16  EXPR_INTEGER_LITERAL
>7935   3298497 415.7  EXPR_CXX_DEPENDENT_SCOPE_DECL_REF
>7934   3379054 425.9  DECL_CXX_RECORD
>7790946360 121.5  EXPR_CXX_THIS
>7508350806  46.7  LOCAL_REDECLARATIONS
>7155   1239819 173.3  EXPR_MEMBER
>6754   1264508 187.2  EXPR_CXX_OPERATOR_CALL
>6607   5819360 880.8  100.00  DECL_CONTEXT_VISIBLE
>6461736861 114.0  EXPR_UNARY_OPERATOR
>6117284391  46.5  TYPE_LVALUE_REFERENCE
>6081372753  61.3  STMT_RETURN
>6066   1964810 323.9   99.64  DECL_TYPEDEF
>5659249455  44.1  TYPE_RECORD
>5252   4884856 930.1  DECL_CLASS_TEMPLATE_SPECIALIZATION
>5196313722  60.4  TYPE_SUBST_TEMPLATE_TYPE_PARM
>5189532009 102.5  TYPE_DEPENDENT_NAME
>5083   2145083 422.01.65  DECL_VAR
>4886296440  60.7  TYPE_TYPEDEF
>4340473950 109.2  STMT_DECL
>4314   4078644 945.4  DECL_FUNCTION
>4150   1436618 346.2  DECL_FUNCTION_TEMPLATE
>3686343246  93.1  TYPE_ELABORATED
>3629144649  39.9  TYPE_POINTER
>3435   2907387 846.4  DECL_CXX_CONSTRUCTOR
>3341896701 268.4  DECL_CXX_BASE_SPECIFIERS
>2847376713 132.3  EXPR_PAREN
>2684271156 101.0  EXPR_CXX_BOOL_LITERAL
>2651208771  78.8  STMT_IF
>2053550511 268.1  EXPR_CXX_UNRESOLVED_CONSTRUCT
>1938268044 138.3  DECL_ACCESS_SPEC
>1725472401 273.9  DECL_NON_TYPE_TEMPLATE_PARM
>1647224673 136.4  EXPR_PAREN_LIST
>1610 64624  40.1  TYPE_RVALUE_REFERENCE
>1542380997 247.1   48.57  DECL_FIELD
>1446392676 271.6  EXPR_CXX_UNRESOLVED_MEMBER
>1411283553 201.0  DECL_USING_SHADOW
>1411 87833  62.2  TYPE_INJECTED_CLASS_NAME
>1339164195 122.6  EXPR_SUBST_NON_TYPE_TEMPLATE_PARM
>1226311278 253.9  DECL_CXX_CTOR_INITIALIZERS
>1110215604 194.2  EXPR_SIZEOF_PACK
>1054476456 452.0  DECL_CLASS_TEMPLATE
> 987112161 113.6  EXPR_CXX_MEMBER_CALL
> 943195005 206.8  EXPR_CXX_CONSTRUCT
> 941271069 288.1  EXPR_CXX_STATIC_CAST
> 879171231 194.8  EXPR_TYPE_TRAIT
> 771 40707  52.8  TYPE_PACK_EXPANSION
> 727106103 145.9  DECL_IMPORT
> 696146286 210.2  DECL_FRIEND
> 678136788 201.8  EXPR_CSTYLE_CAST
> 664 70292 105.9  EXPR_ARRAY_SUBSCRIPT
> 628 67550 107.6  EXPR_PACK_EXPANSION
> 601 84473 140.6  EXPR_COMPOUND_ASSIGN_OPERATOR
> 564 71760 127.2  STMT_FOR
> 557 57643 103.5  EXPR_CXX_NULL_PTR_LITERAL
> 545350959 644.0  DECL_CXX_DESTRUCTOR
> 5238679471659.6  
> DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION
> 495120219 242.9  DECL_USING
> 476 87196 183.2  EXPR_SIZEOF_ALIGN_OF
> 447292917 655.3  EXPR_STRING_LITERAL
> 434 32634  75.2  100.

[PATCH] D53025: [clang-tidy] implement new check for const return types.

2018-10-26 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel updated this revision to Diff 171293.
ymandel marked 4 inline comments as done.
ymandel added a comment.

Reword comment on the check, for clarity.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D53025

Files:
  clang-tidy/readability/CMakeLists.txt
  clang-tidy/readability/ConstValueReturnCheck.cpp
  clang-tidy/readability/ConstValueReturnCheck.h
  clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tidy/utils/LexerUtils.cpp
  clang-tidy/utils/LexerUtils.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/readability-const-value-return.rst
  test/clang-tidy/readability-const-value-return.cpp

Index: test/clang-tidy/readability-const-value-return.cpp
===
--- /dev/null
+++ test/clang-tidy/readability-const-value-return.cpp
@@ -0,0 +1,227 @@
+// RUN: %check_clang_tidy %s readability-const-value-return %t -- -- -isystem
+
+//  p# = positive test
+//  n# = negative test
+
+#include 
+
+const int p1() {
+// CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 'const int' is 'const'-qualified hindering compiler optimizations
+// CHECK-FIXES: int p1() {
+  return 1;
+}
+
+const int p15();
+// CHECK-FIXES: int p15();
+
+template 
+const int p31(T v) { return 2; }
+// CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 'const int' is 'const'-qu
+// CHECK-FIXES: int p31(T v) { return 2; }
+
+// We detect const-ness even without instantiating T.
+template 
+const T p32(T t) { return t; }
+// CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 'const T' is 'const'-qual
+// CHECK-FIXES: T p32(T t) { return t; }
+
+// However, if the return type is itself a template instantiation, Clang does
+// not consider it const-qualified without knowing `T`.
+template 
+typename std::add_const::type n15(T v) { return v; }
+
+template 
+class Klazz {
+public:
+  Klazz(A) {}
+};
+
+class Clazz {
+ public:
+  Clazz *const p2() {
+// CHECK-MESSAGES: [[@LINE-1]]:3: warning: return type 'Clazz *const' is 'co
+// CHECK-FIXES: Clazz *p2() {
+return this;
+  }
+
+  Clazz *const p3();
+  // CHECK-FIXES: Clazz *p3();
+
+  const int p4() const {
+// CHECK-MESSAGES: [[@LINE-1]]:3: warning: return type 'const int' is 'const
+// CHECK-FIXES: int p4() const {
+return 4;
+  }
+
+  const Klazz* const p5() const;
+  // CHECK-FIXES: const Klazz* p5() const;
+
+  const Clazz operator++(int x) {  //  p12
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: return type 'const Clazz' is 'const
+  // CHECK-FIXES: Clazz operator++(int x) {
+  }
+
+  struct Strukt {
+int i;
+  };
+
+  const Strukt p6() {}
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: return type 'const Clazz::Strukt' i
+  // CHECK-FIXES: Strukt p6() {}
+
+  // No warning is emitted here, because this is only the declaration.  The
+  // warning will be associated with the definition, below.
+  const Strukt* const p7();
+  // CHECK-FIXES: const Strukt* p7();
+
+  // const-qualifier is the first `const` token, but not the first token.
+  static const int p8() {}
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: return type 'const int' is 'const'-
+  // CHECK-FIXES: static int p8() {}
+
+  static const Strukt p9() {}
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: return type 'const Clazz::Strukt' i
+  // CHECK-FIXES: static Strukt p9() {}
+
+  int n0() const { return 0; }
+  const Klazz& n11(const Klazz) const;
+};
+
+Clazz *const Clazz::p3() {
+  // CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 'Clazz *const' is 'cons
+  // CHECK-FIXES: Clazz *Clazz::p3() {
+  return this;
+}
+
+const Klazz* const Clazz::p5() const {}
+// CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 'const Klazz *
+// CHECK-FIXES: const Klazz* Clazz::p5() const {}
+
+const Clazz::Strukt* const Clazz::p7() {}
+// CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 'const Clazz::Strukt *con
+// CHECK-FIXES: const Clazz::Strukt* Clazz::p7() {}
+
+Clazz *const p10();
+// CHECK-FIXES: Clazz *p10();
+
+Clazz *const p10() {
+  // CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 'Clazz *const' is 'cons
+  // CHECK-FIXES: Clazz *p10() {
+  return new Clazz();
+}
+
+const Clazz bar;
+const Clazz *const p11() {
+  // CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 'const Clazz *const' is
+  // CHECK-FIXES: const Clazz *p11() {
+  return &bar;
+}
+
+const Klazz p12() {}
+// CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 'const Klazz'
+// CHECK-FIXES: Klazz p12() {}
+
+const Klazz* const p13() {}
+// CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 'const Klazz *
+// CHECK-FIXES: const Klazz* p13() {}
+
+// re-declaration of p15.
+const int p15();
+// CHECK-FIXES: int p15();
+
+const int p15() {
+// CHECK-MESSAGES: [[@LINE-1]]:1: warning:
+// CHECK-FIXES: int p15() {
+  return 0;
+}
+
+// Exercise the lexer.
+
+const /* comment */ /* another comment*/ int p16() { return 0; }
+// CHECK-MESSAGES: [[@LINE-1]]:1: warning:
+// CHECK-FIXES: /* comment */ /* another comment*/ in

[PATCH] D53025: [clang-tidy] implement new check for const return types.

2018-10-26 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel added inline comments.



Comment at: clang-tidy/readability/ConstValueReturnCheck.cpp:107
+diag(Def->getInnerLocStart(), "return type %0 is 'const'-qualified "
+  "hindering compiler optimizations")
+<< Def->getReturnType();

aaron.ballman wrote:
> It seems strange to me that this is in the readability module but the 
> diagnostic here is about compiler optimizations. Should this be in the 
> performance module instead? Or should this diagnostic be reworded about the 
> readability concerns?
Good point. The readability angle is that the const clutters the code to no 
benefit.  That is, even if it was performance neutral, I'd still want to 
discourage this practice.  But, it does seem like the primary impact is 
performance. 

I'm fine either way -- moving it to performance or emphasizing the clutter of 
the unhelpful "const".  I'm inclined to moving it, but don't have good sense of 
how strict these hierarchies are. What do you think?


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D53025



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


[PATCH] D53457: clang-cl: Add "/clang:" pass-through arg support.

2018-10-26 Thread Hans Wennborg via Phabricator via cfe-commits
hans added a comment.

  One note about flag ordering: the /clang: flags are concatenated to the end of
  the argument list, so in cases where the last flag wins, the /clang: flags
  will be chosen regardless of their order relative to other flags on the driver
  command line.

This seems a little unfortunate. I wonder if it would be possible to not have 
this restriction, i.e. to process these in-line with the rest of the flags?

One way to achieve this would be to change Driver::ParseArgStrings() to handle 
the "/clang:" arguments. After doing the regular option parsing, it would look 
for "/clang:" options and substitute them for the underlying option. This has 
the downside of adding some option-specific logic to ParseArgStrings, but on 
the other hand it's less intrusive than passing around the IsCLMode bool. Do 
you think something like this could work?




Comment at: docs/UsersManual.rst:3100
+
+The /clang: Option
+

Thanks for thinking about the docs!

I think we should put this above the /fallback section, since this new flag is 
more important and /fallback shouldn't be used much these days.



Comment at: include/clang/Driver/CLCompatOptions.td:324
   HelpText<"Volatile loads and stores have acquire and release semantics">;
+def _SLASH_clang : CLJoinedOrSeparate<"clang:">,
+  HelpText<"Pass  to the clang driver">, MetaVarName<"">;

Do we really want the "OrSeparate" part of this? Is there any downside of 
limiting it to "/clang:-foo" rather than also allowing "/clang: -foo"?


https://reviews.llvm.org/D53457



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


[PATCH] D51949: [clang-tidy] new check 'readability-isolate-declaration'

2018-10-26 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added inline comments.



Comment at: test/clang-tidy/readability-isolate-declaration.cpp:233
+  int member1, member2;
+  // TODO: Transform FieldDecl's as well
+};

Comment is misleading. Transform == fixit, at least for me.
But they are not even diagnosed.
So maybe
```
// TODO: Handle FieldDecl's as well
```


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D51949



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


[PATCH] D51949: [clang-tidy] new check 'readability-isolate-declaration'

2018-10-26 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

Mostly minor nits that clean up wording and comments.




Comment at: clang-tidy/readability/IsolateDeclarationCheck.cpp:52
+ const LangOptions &LangOpts) {
+  assert(Indirections >= 0 && "Indirections must be non-negative");
+  if (Indirections == 0)

JonasToth wrote:
> aaron.ballman wrote:
> > This assertion suggests that `Indirections` should be `unsigned` and that 
> > you perform the assertion before doing a decrement to ensure it isn't 
> > trying to decrement past 0.
> Because the decrement is post-fix it will decrement past 0 on the breaking 
> condition.
> Having `unsigned` will result in a wrap (is defined, but still slightly 
> non-obvious).
> 
> I could make a `do - while`, then the condition can be `--Indirections != 0`. 
> I would just like to follow the CPPCG that say 'don't use unsigned unless you 
> need modulo arithmetic'.
I disagree with this logic (personally, I think this is a code smell), but 
don't feel strongly enough about it to ask you to change it.



Comment at: clang-tidy/readability/IsolateDeclarationCheck.cpp:69
+static int countIndirections(const Type *T, int Indirections = 0) {
+  if (isa(T) && T->isFunctionPointerType()) {
+const auto *Pointee =

No need for the `isa<>` check -- `isFunctionPointerType()` already does the 
right thing.



Comment at: clang-tidy/readability/IsolateDeclarationCheck.cpp:71
+const auto *Pointee =
+T->getPointeeType().getTypePtr()->castAs();
+return countIndirections(

You don't need to call `getTypePtr()` -- `QualType` overloads `operator->()` to 
do this directly.



Comment at: clang-tidy/readability/IsolateDeclarationCheck.cpp:141
+
+  // FIXME: Member pointer are not transformed correctly right now, that's
+  // why they are treated as problematic here.

Member pointer -> Member pointers



Comment at: clang-tidy/readability/IsolateDeclarationCheck.cpp:191
+
+// FIXME: Member pointer are not transformed correctly right now, that's
+// why they are treated as problematic here.

Member pointer -> Member pointers



Comment at: clang-tidy/utils/LexerUtils.cpp:86
+
+if ((*Tok).is(tok::hash))
+  return false;

`Tok->is()`



Comment at: clang-tidy/utils/LexerUtils.h:78
+
+/// Relex the provide \p Range and return \c false if either a macro spanning
+/// multiple tokens, a pre-processor directive or failure to retrieve the

Relex the provide -> Re-lex the provided
spanning -> spans



Comment at: clang-tidy/utils/LexerUtils.h:81
+/// next token is found, otherwise \c true.
+bool saveFromPreProcessor(SourceRange Range, const SourceManager &SM,
+  const LangOptions &LangOpts);

I don't think the functionality is obvious from the name -- this is testing to 
see whether any token in the given range is either a macro or a preprocessor 
directive. How about reversing the logic to: 
`rangeContainsExpansionsOrDirectives()`



Comment at: docs/clang-tidy/checks/readability-isolate-declaration.rst:3
+
+readability-isolate-declarationaration
+==

Typo. declarationaration -> declaration

(Don't forget to fix the underlines as well.)



Comment at: docs/clang-tidy/checks/readability-isolate-declaration.rst:10
+The automatic code-transformation will use the same indentation as the original
+for every created statement and add a linebreak after each statement.
+

linebreak -> line break

I think it may also be important to point out that the declarations will remain 
in the same order as their original source order. For instance, you may run 
into code like: `int i = 5, j = i;` and it's crucial that it be transformed 
into `int i = 5; int j = i;`.



Comment at: docs/clang-tidy/checks/readability-isolate-declaration.rst:23
+
+The check does exclude places where it is necessary or commong to declare
+multiple variables in one statement and there is no other way supported in the

does exclude -> excludes
commong -> common



Comment at: docs/clang-tidy/checks/readability-isolate-declaration.rst:31
+  // before the loop will increase the scope of the variable 'Begin' and 'End'
+  // which is undesired in it's own.
+  for (int Begin = 0, End = 100; Begin < End; ++Begin);

undesired in it's own -> undesirable



Comment at: docs/clang-tidy/checks/readability-isolate-declaration.rst:45
+
+Global variables and member variables are excluded.
+

Why are global variables excluded from this check? It seems like they should 
have the exact same behavior as local variables in terms of the transfor

[PATCH] D53200: [OpenCL] Fix serialization of OpenCLExtensionDecls

2018-10-26 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia accepted this revision.
Anastasia added a comment.
This revision is now accepted and ready to land.

LGTM! Thanks!




Comment at: test/SemaOpenCL/extension-begin.cl:43
   g(0); // expected-error {{no matching function for call to 'g'}}
-// expected-note@-26 {{candidate unavailable as it requires OpenCL 
extension 'my_ext' to be disabled}}
-// expected-note@-22 {{candidate function not viable: requires 0 
arguments, but 1 was provided}}
+// expected-note@extension-begin.h:18 {{candidate unavailable as it 
requires OpenCL extension 'my_ext' to be disabled}}
+// expected-note@extension-begin.h:23 {{candidate function not viable: 
requires 0 arguments, but 1 was provided}}

Is this a typo? Should this be 'enabled' instead of 'disabled'?


https://reviews.llvm.org/D53200



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


[PATCH] D52742: [analyzer][PlistMacroExpansion] Part 1.: New expand-macros flag

2018-10-26 Thread Umann Kristóf via Phabricator via cfe-commits
Szelethus planned changes to this revision.
Szelethus added a comment.

@xazax.hun observed that the way `diagnostics` looks like is this:

  diagnostics
report 1
  notes
  macro_expansions
  path
  executed_lines
report 2
  ...

Bt, if I didn't insist on this structure, but rather print macros at the 
end of the report, we wouldn't need all this hackery (converting a immutable 
container, into a mutable one, and then actually modifying the path). This 
however does imply that macro pieces have to be collected, which would imply 
the need for adding //yet another// parameter to //every single function// in 
this file. I think the time has come to collect them in a class, so I'll put 
this patch on hold.

Mind you, the rest of the patches don't contain logic that depends on this 
patch.


https://reviews.llvm.org/D52742



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


[PATCH] D53025: [clang-tidy] implement new check for const return types.

2018-10-26 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang-tidy/readability/ConstValueReturnCheck.cpp:107
+diag(Def->getInnerLocStart(), "return type %0 is 'const'-qualified "
+  "hindering compiler optimizations")
+<< Def->getReturnType();

ymandel wrote:
> aaron.ballman wrote:
> > It seems strange to me that this is in the readability module but the 
> > diagnostic here is about compiler optimizations. Should this be in the 
> > performance module instead? Or should this diagnostic be reworded about the 
> > readability concerns?
> Good point. The readability angle is that the const clutters the code to no 
> benefit.  That is, even if it was performance neutral, I'd still want to 
> discourage this practice.  But, it does seem like the primary impact is 
> performance. 
> 
> I'm fine either way -- moving it to performance or emphasizing the clutter of 
> the unhelpful "const".  I'm inclined to moving it, but don't have good sense 
> of how strict these hierarchies are. What do you think?
I'm not sold that `const`-qualified return types always pessimize 
optimizations. However, I'm also not sold that it's *always* a bad idea to have 
a top-level cv-qualifier on a return type either (for instance, this is one way 
to prevent callers from modifying a temp returned by a function). How about 
leaving this in readability and changing the diagnostic into: "top-level 
'const' qualifier on a return type may reduce code readability with limited 
benefit" or something equally weasely?


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D53025



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


[PATCH] D53763: [libc++] [test] Fix logic error in tests; enable for MSVC previews

2018-10-26 Thread Casey Carter via Phabricator via cfe-commits
CaseyCarter created this revision.
CaseyCarter added reviewers: EricWF, mclow.lists.

Fairly straightforward: these tests were written without an implementation of 
`<=>`, and they're incorrectly testing that `0 <=> foo` has the behavior that 
is required for `foo <=> 0`.


https://reviews.llvm.org/D53763

Files:
  test/std/language.support/cmp/cmp.partialord/partialord.pass.cpp
  test/std/language.support/cmp/cmp.strongord/strongord.pass.cpp
  test/std/language.support/cmp/cmp.weakord/weakord.pass.cpp
  test/support/test_macros.h


Index: test/support/test_macros.h
===
--- test/support/test_macros.h
+++ test/support/test_macros.h
@@ -203,8 +203,9 @@
 
 // FIXME: Fix this feature check when either (A) a compiler provides a complete
 // implementation, or (b) a feature check macro is specified
+#if !defined(_MSC_VER) || defined(__clang__) || _MSC_VER < 1920 || _MSVC_LANG 
<= 201703L
 #define TEST_HAS_NO_SPACESHIP_OPERATOR
-
+#endif
 
 #if TEST_STD_VER < 11
 #define ASSERT_NOEXCEPT(...)
Index: test/std/language.support/cmp/cmp.weakord/weakord.pass.cpp
===
--- test/std/language.support/cmp/cmp.weakord/weakord.pass.cpp
+++ test/std/language.support/cmp/cmp.weakord/weakord.pass.cpp
@@ -142,7 +142,7 @@
   };
   for (auto TC : SpaceshipTestCases)
   {
-std::weak_ordering Res = (0 <=> TC.Value);
+std::weak_ordering Res = (TC.Value <=> 0);
 switch (TC.Expect) {
 case ER_Equiv:
   assert(Res == 0);
Index: test/std/language.support/cmp/cmp.strongord/strongord.pass.cpp
===
--- test/std/language.support/cmp/cmp.strongord/strongord.pass.cpp
+++ test/std/language.support/cmp/cmp.strongord/strongord.pass.cpp
@@ -185,7 +185,7 @@
   };
   for (auto TC : SpaceshipTestCases)
   {
-std::strong_ordering Res = (0 <=> TC.Value);
+std::strong_ordering Res = (TC.Value <=> 0);
 switch (TC.Expect) {
 case ER_Equiv:
   assert(Res == 0);
Index: test/std/language.support/cmp/cmp.partialord/partialord.pass.cpp
===
--- test/std/language.support/cmp/cmp.partialord/partialord.pass.cpp
+++ test/std/language.support/cmp/cmp.partialord/partialord.pass.cpp
@@ -130,7 +130,7 @@
   };
   for (auto TC : SpaceshipTestCases)
   {
-std::partial_ordering Res = (0 <=> TC.Value);
+std::partial_ordering Res = (TC.Value <=> 0);
 switch (TC.Expect) {
 case ER_Equiv:
   assert(Res == 0);


Index: test/support/test_macros.h
===
--- test/support/test_macros.h
+++ test/support/test_macros.h
@@ -203,8 +203,9 @@
 
 // FIXME: Fix this feature check when either (A) a compiler provides a complete
 // implementation, or (b) a feature check macro is specified
+#if !defined(_MSC_VER) || defined(__clang__) || _MSC_VER < 1920 || _MSVC_LANG <= 201703L
 #define TEST_HAS_NO_SPACESHIP_OPERATOR
-
+#endif
 
 #if TEST_STD_VER < 11
 #define ASSERT_NOEXCEPT(...)
Index: test/std/language.support/cmp/cmp.weakord/weakord.pass.cpp
===
--- test/std/language.support/cmp/cmp.weakord/weakord.pass.cpp
+++ test/std/language.support/cmp/cmp.weakord/weakord.pass.cpp
@@ -142,7 +142,7 @@
   };
   for (auto TC : SpaceshipTestCases)
   {
-std::weak_ordering Res = (0 <=> TC.Value);
+std::weak_ordering Res = (TC.Value <=> 0);
 switch (TC.Expect) {
 case ER_Equiv:
   assert(Res == 0);
Index: test/std/language.support/cmp/cmp.strongord/strongord.pass.cpp
===
--- test/std/language.support/cmp/cmp.strongord/strongord.pass.cpp
+++ test/std/language.support/cmp/cmp.strongord/strongord.pass.cpp
@@ -185,7 +185,7 @@
   };
   for (auto TC : SpaceshipTestCases)
   {
-std::strong_ordering Res = (0 <=> TC.Value);
+std::strong_ordering Res = (TC.Value <=> 0);
 switch (TC.Expect) {
 case ER_Equiv:
   assert(Res == 0);
Index: test/std/language.support/cmp/cmp.partialord/partialord.pass.cpp
===
--- test/std/language.support/cmp/cmp.partialord/partialord.pass.cpp
+++ test/std/language.support/cmp/cmp.partialord/partialord.pass.cpp
@@ -130,7 +130,7 @@
   };
   for (auto TC : SpaceshipTestCases)
   {
-std::partial_ordering Res = (0 <=> TC.Value);
+std::partial_ordering Res = (TC.Value <=> 0);
 switch (TC.Expect) {
 case ER_Equiv:
   assert(Res == 0);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D53764: [OpenCL] Enable address spaces for references in C++

2018-10-26 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia created this revision.
Anastasia added reviewers: rjmccall, yaxunl.

I first enabled AS deduction for references that allowed to inherit the right 
conversion diagnostics based on qualification conversion rules implemented 
earlier for the pointer type.

Then in order to tests the deduction rules fully, I had to enable some extra 
features from OpenCL 2.0 that are also valid in C++.

A number of ICEs fired in the `CodeGen` due to missing `addrspacecast`. Not 
convinced the current solution is good though. May be it would be cleaner to 
add a separate `CastKind` here - `CK_LValueAddressSpaceConversion`? Although I 
am not entirely clear about the benefits yet.


https://reviews.llvm.org/D53764

Files:
  lib/AST/Expr.cpp
  lib/CodeGen/CGExpr.cpp
  lib/Sema/DeclSpec.cpp
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaExprCXX.cpp
  lib/Sema/SemaInit.cpp
  lib/Sema/SemaType.cpp
  test/CodeGenOpenCLCXX/address-space-deduction.cl

Index: test/CodeGenOpenCLCXX/address-space-deduction.cl
===
--- /dev/null
+++ test/CodeGenOpenCLCXX/address-space-deduction.cl
@@ -0,0 +1,42 @@
+// RUN: %clang_cc1 %s -triple spir-unknown-unknown -cl-std=c++ -O0 -emit-llvm -o - | FileCheck %s -check-prefixes=COMMON,PTR
+// RUN: %clang_cc1 %s -triple spir-unknown-unknown -cl-std=c++ -O0 -emit-llvm -o - -DREF | FileCheck %s -check-prefixes=COMMON,REF
+
+#ifdef REF
+#define PTR &
+#define ADR(x) x
+#else
+#define PTR *
+#define ADR(x) &x
+#endif
+
+//COMMON: @glob = addrspace(1) global i32
+int glob;
+//PTR: @glob_p = addrspace(1) global i32 addrspace(4)* addrspacecast (i32 addrspace(1)* @glob to i32 addrspace(4)*)
+//REF: @glob_p = addrspace(1) global i32 addrspace(4)* null
+int PTR glob_p = ADR(glob);
+
+//COMMON: @_ZZ3fooi{{P|R}}U3AS4iE6loc_st = internal addrspace(1) global i32
+//PTR: @_ZZ3fooiPU3AS4iE8loc_st_p = internal addrspace(1) global i32 addrspace(4)* addrspacecast (i32 addrspace(1)* @_ZZ3fooiPU3AS4iE6loc_st to i32 addrspace(4)*)
+//REF: @_ZZ3fooiRU3AS4iE8loc_st_p = internal addrspace(1) global i32 addrspace(4)* null
+//COMMON: @loc_ext_p = external addrspace(1) {{global|constant}} i32 addrspace(4)*
+//COMMON: @loc_ext = external addrspace(1) global i32
+
+//REF: store i32 addrspace(4)* addrspacecast (i32 addrspace(1)* @glob to i32 addrspace(4)*), i32 addrspace(4)* addrspace(1)* @glob_p
+
+//COMMON: define spir_func i32 @_Z3fooi{{P|R}}U3AS4i(i32 %par, i32 addrspace(4)*{{.*}} %par_p)
+int foo(int par, int PTR par_p){
+//COMMON: %loc = alloca i32
+  int loc;
+//COMMON: %loc_p = alloca i32 addrspace(4)*
+//COMMON: [[GAS:%[0-9]+]] = addrspacecast i32* %loc to i32 addrspace(4)*
+//COMMON: store i32 addrspace(4)* [[GAS]], i32 addrspace(4)** %loc_p
+  int PTR loc_p = ADR(loc);
+
+// CHECK directives for the following code are located above.
+  static int loc_st;
+  static int PTR loc_st_p = ADR(loc_st);
+  extern int loc_ext;
+  extern int PTR loc_ext_p;
+  (void)loc_ext_p;
+  return loc_ext;
+}
Index: lib/Sema/SemaType.cpp
===
--- lib/Sema/SemaType.cpp
+++ lib/Sema/SemaType.cpp
@@ -7177,7 +7177,8 @@
   bool IsPointee =
   ChunkIndex > 0 &&
   (D.getTypeObject(ChunkIndex - 1).Kind == DeclaratorChunk::Pointer ||
-   D.getTypeObject(ChunkIndex - 1).Kind == DeclaratorChunk::BlockPointer);
+   D.getTypeObject(ChunkIndex - 1).Kind == DeclaratorChunk::BlockPointer ||
+   D.getTypeObject(ChunkIndex - 1).Kind == DeclaratorChunk::Reference);
   bool IsFuncReturnType =
   ChunkIndex > 0 &&
   D.getTypeObject(ChunkIndex - 1).Kind == DeclaratorChunk::Function;
Index: lib/Sema/SemaInit.cpp
===
--- lib/Sema/SemaInit.cpp
+++ lib/Sema/SemaInit.cpp
@@ -7603,12 +7603,15 @@
 case SK_QualificationConversionRValue: {
   // Perform a qualification conversion; these can never go wrong.
   ExprValueKind VK =
-  Step->Kind == SK_QualificationConversionLValue ?
-  VK_LValue :
-  (Step->Kind == SK_QualificationConversionXValue ?
-   VK_XValue :
-   VK_RValue);
-  CurInit = S.ImpCastExprToType(CurInit.get(), Step->Type, CK_NoOp, VK);
+  Step->Kind == SK_QualificationConversionLValue
+  ? VK_LValue
+  : (Step->Kind == SK_QualificationConversionXValue ? VK_XValue
+: VK_RValue);
+  CastKind CK = (Step->Type.getAddressSpace() !=
+ CurInit.get()->getType().getAddressSpace())
+? CK_AddressSpaceConversion
+: CK_NoOp;
+  CurInit = S.ImpCastExprToType(CurInit.get(), Step->Type, CK, VK);
   break;
 }
 
Index: lib/Sema/SemaExprCXX.cpp
===
--- lib/Sema/SemaExprCXX.cpp
+++ lib/Sema/SemaExprCXX.cpp
@@ -4276,10 +4276,17 @@
   case ICK_Qualifi

[PATCH] D53764: [OpenCL] Enable address spaces for references in C++

2018-10-26 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added inline comments.



Comment at: lib/AST/Expr.cpp:1609
   case CK_AddressSpaceConversion:
-assert(getType()->isPointerType() || getType()->isBlockPointerType());
-assert(getSubExpr()->getType()->isPointerType() ||
-   getSubExpr()->getType()->isBlockPointerType());
-assert(getType()->getPointeeType().getAddressSpace() !=
-   getSubExpr()->getType()->getPointeeType().getAddressSpace());
-LLVM_FALLTHROUGH;
+assert(/*If pointer type then addr spaces for pointees must differ*/
+   (((getType()->isPointerType() &&

I don't like this assert now. Would adding extra variable be cleaner here?


https://reviews.llvm.org/D53764



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


[PATCH] D53448: [OpenMP][NVPTX] Use single loops when generating code for distribute parallel for

2018-10-26 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev accepted this revision.
ABataev added a comment.
This revision is now accepted and ready to land.

LG, with a nit




Comment at: lib/Sema/SemaOpenMP.cpp:5308
+
+// Build IV <= PrevEUB to be used in parallel for is in combination with
+// a distribute directive with schedule(static, 1)

Fix the comment here


Repository:
  rC Clang

https://reviews.llvm.org/D53448



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


[PATCH] D51484: [OpenCL] Add support of cl_intel_device_side_avc_motion_estimation extension

2018-10-26 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia accepted this revision.
Anastasia added a comment.
This revision is now accepted and ready to land.

LGTM! Thanks!




Comment at: test/SemaOpenCL/intel-subgroup-avc-ext-types.cl:5
+
+// All intel_sub_group_avc_* types can only be used as argument or return value
+// of built-in functions defined in the extension.

Btw do you plan to implement this later:
  All intel_sub_group_avc_* types can only be used as argument or return value 
of built-in functions defined in the extension.


https://reviews.llvm.org/D51484



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


[PATCH] D53023: Prototype OpenCL BIFs using Tablegen

2018-10-26 Thread Andrew Savonichev via Phabricator via cfe-commits
asavonic added a comment.

> TODO
>  Measure the performance / size impact

I looks like the total size of OpenCLBuiltinDecl table should be
~450KB (for ~15000 functions). I guess it can be reduced furthermore by:

1. Replacing return type with an index (you've mentioned this in TODO).
2. Replace extension and a version with a single index.
3. Same for NumArgs and ArgTableIndex - they seem to be really tied together, 
so maybe we can use a single identifier for them?

With these improvements the total size should become ~175KB, which
seems to be ok, considering that libclangSema.so takes 9.4MB.

In my opinion, even 450KB is a vast improvement over what we have now,
because opencl-c.h alone takes 786KB.




Comment at: lib/Sema/SemaExpr.cpp:2131
+  ParmVarDecl::Create(Context, NewFD, SourceLocation(),
+  SourceLocation(), PP.getIdentifierInfo(arg_name),
+  ArgTypes[i], nullptr, SC_None, nullptr));

This dummy identifier name actually makes a diagnostic a bit weird:

t/gid.cl:3:31: error: too many arguments to function call, expected single 
argument 'a0', have 2 arguments
uint gid = get_global_id(0, 2);

It seems to be better if you pass nullptr instead:
t/gid.cl:4:31: error: too many arguments to function call, expected 1, have 
2
uint gid = get_global_id(0, 1);




https://reviews.llvm.org/D53023



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


[PATCH] D44100: [ASTImporter] Reorder fields after structure import is finished

2018-10-26 Thread Gabor Marton via Phabricator via cfe-commits
martong added a comment.

Ping. This is still not committed, however, essential for ctu analyse any C++ 
project. Aleksei, I am happy to commit it for you if you don't have time, just 
let me know.


Repository:
  rC Clang

https://reviews.llvm.org/D44100



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


[PATCH] D53023: Prototype OpenCL BIFs using Tablegen

2018-10-26 Thread Andrew Savonichev via Phabricator via cfe-commits
asavonic added inline comments.



Comment at: lib/Sema/SemaExpr.cpp:2247
   if (R.empty() && HasTrailingLParen && II && !getLangOpts().CPlusPlus) {
-NamedDecl *D = ImplicitlyDefineFunction(NameLoc, *II, S);
-if (D) R.addDecl(D);
+if (getLangOpts().OpenCL) {
+  auto Index =

It will be good to have a driver option to enable this feature.


https://reviews.llvm.org/D53023



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


[PATCH] D53443: [OpenMP][NVPTX] Enable default scheduling for parallel for in non-SPMD cases.

2018-10-26 Thread Gheorghe-Teodor Bercea via Phabricator via cfe-commits
gtbercea updated this revision to Diff 171310.
gtbercea added a comment.

  Add test.


Repository:
  rC Clang

https://reviews.llvm.org/D53443

Files:
  lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
  test/OpenMP/nvptx_parallel_for_codegen.cpp

Index: test/OpenMP/nvptx_parallel_for_codegen.cpp
===
--- /dev/null
+++ test/OpenMP/nvptx_parallel_for_codegen.cpp
@@ -0,0 +1,123 @@
+// Test target codegen - host bc file has to be created first.
+// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm-bc %s -o %t-ppc-host.bc
+// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple nvptx64-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o - | FileCheck %s --check-prefix CHECK --check-prefix CHECK-64
+// expected-no-diagnostics
+#ifndef HEADER
+#define HEADER
+
+template
+tx ftemplate(int n) {
+  tx b[10];
+
+  #pragma omp target
+  {
+tx d = n;
+#pragma omp parallel for
+for(int i=0; i<10; i++) {
+  b[i] += d;
+}
+b[3] += 1;
+  }
+
+  return b[3];
+}
+
+int bar(int n){
+  int a = 0;
+
+  a += ftemplate(n);
+
+  return a;
+}
+
+// CHECK-LABEL: define {{.*}}void {{@__omp_offloading_.+template.+l12}}_worker()
+// CHECK: call void @llvm.nvvm.barrier0()
+// CHECK: call i1 @__kmpc_kernel_parallel(
+// CHECK: call void @__omp_outlined___wrapper(
+
+// CHECK: define weak void @__omp_offloading_{{.*}}l12(
+// CHECK: call void @__omp_offloading_{{.*}}l12_worker()
+// CHECK: call void @__kmpc_kernel_init(
+// CHECK: call void @__kmpc_data_sharing_init_stack()
+// CHECK: call i8* @__kmpc_data_sharing_push_stack(i64 4, i16 0)
+// CHECK: call void @__kmpc_kernel_prepare_parallel(
+// CHECK: call void @__kmpc_begin_sharing_variables(i8*** %shared_arg_refs, i64 2)
+// CHECK: call void @llvm.nvvm.barrier0()
+// CHECK: call void @llvm.nvvm.barrier0()
+// CHECK: call void @__kmpc_end_sharing_variables()
+// CHECK: call void @__kmpc_data_sharing_pop_stack(
+// CHECK: call void @__kmpc_kernel_deinit(i16 1)
+
+// CHECK: define internal void @__omp_outlined__(
+// CHECK: alloca
+// CHECK: alloca
+// CHECK: alloca
+// CHECK: alloca
+// CHECK: [[OMP_IV:%.*]] = alloca i32
+// CHECK: store i32 0, {{.*}} [[OMP_LB:%.+]],
+// CHECK: store i32 9, {{.*}} [[OMP_UB:%.+]],
+// CHECK: store i32 1, {{.*}} [[OMP_ST:%.+]],
+// CHECK: call void @__kmpc_for_static_init_4({{.*}} i32 33, {{.*}} [[OMP_LB]], {{.*}} [[OMP_UB]], {{.*}} [[OMP_ST]], i32 1, i32 1)
+// CHECK: br label %[[OMP_DISPATCH_COND:.+]]
+
+// CHECK: [[OMP_DISPATCH_COND]]
+// CHECK: [[OMP_UB_1:%.+]] = load {{.*}} [[OMP_UB]]
+// CHECK: [[COMP_1:%.+]] = icmp sgt {{.*}} [[OMP_UB_1]]
+// CHECK: br i1 [[COMP_1]], label %[[COND_TRUE:.+]], label %[[COND_FALSE:.+]]
+
+// CHECK: [[COND_TRUE]]
+// CHECK: br label %[[COND_END:.+]]
+
+// CHECK: [[COND_FALSE]]
+// CHECK: [[OMP_UB_2:%.+]] = load {{.*}}* [[OMP_UB]]
+// CHECK: br label %[[COND_END]]
+
+// CHECK: [[COND_END]]
+// CHECK: [[COND_RES:%.+]] = phi i32 [ 9, %[[COND_TRUE]] ], [ [[OMP_UB_2]], %[[COND_FALSE]] ]
+// CHECK: store i32 [[COND_RES]], i32* [[OMP_UB]]
+// CHECK: [[OMP_LB_1:%.+]] = load i32, i32* [[OMP_LB]]
+// CHECK: store i32 [[OMP_LB_1]], i32* [[OMP_IV]]
+// CHECK: [[OMP_IV_1:%.+]] = load i32, i32* [[OMP_IV]]
+// CHECK: [[OMP_UB_3:%.+]] = load i32, i32* [[OMP_UB]]
+// CHECK: [[COMP_2:%.+]] = icmp sle i32 [[OMP_IV_1]], [[OMP_UB_3]]
+// CHECK: br i1 [[COMP_2]], label %[[DISPATCH_BODY:.+]], label %[[DISPATCH_END:.+]]
+
+// CHECK: [[DISPATCH_BODY]]
+// CHECK: br label %[[OMP_INNER_FOR_COND:.+]]
+
+// CHECK: [[OMP_INNER_FOR_COND]]
+// CHECK: [[OMP_IV_2:%.+]] = load i32, i32* [[OMP_IV]]
+// CHECK: [[OMP_UB_4:%.+]] = load i32, i32* [[OMP_UB]]
+// CHECK: [[COMP_3:%.+]] = icmp sle i32 [[OMP_IV_2]], [[OMP_UB_4]]
+// CHECK: br i1 [[COMP_3]], label %[[OMP_INNER_FOR_BODY:.+]], label %[[OMP_INNER_FOR_END:.+]]
+
+// CHECK: [[OMP_INNER_FOR_BODY]]
+// CHECK: br label %[[OMP_BODY_CONTINUE:.+]]
+
+// CHECK: [[OMP_BODY_CONTINUE]]
+// CHECK: br label %[[OMP_INNER_FOR_INC:.+]]
+
+// CHECK: [[OMP_INNER_FOR_INC]]
+// CHECK: [[OMP_IV_3:%.+]] = load i32, i32* [[OMP_IV]]
+// CHECK: [[ADD_1:%.+]] = add nsw i32 [[OMP_IV_3]], 1
+// CHECK: store i32 [[ADD_1]], i32* [[OMP_IV]]
+// CHECK: br label %[[OMP_INNER_FOR_COND]]
+
+// CHECK: [[OMP_INNER_FOR_COND]]
+// CHECK: br label %[[OMP_DISPATCH_INC:.+]]
+
+// CHECK: [[OMP_DISPATCH_INC]]
+// CHECK: [[OMP_LB_2:%.+]] = load i32, i32* [[OMP_LB]]
+// CHECK: [[OMP_ST_1:%.+]] = load i32, i32* [[OMP_ST]]
+// CHECK: [[ADD_2:%.+]] = add nsw i32 [[OMP_LB_2]], [[OMP_ST_1]]
+// CHECK: store i32 [[ADD_2]], i32* [[OMP_LB]]
+// CHECK: [[OMP_UB_5:%.+]] = load i32, i32* [[OMP_UB]]
+// CHECK: [[OMP_ST_2:%.+]] = load i32, i32* [[OMP_ST]]
+// CHECK: [[ADD_3:%.+]] = add nsw i32 [[OMP_UB_5]], [[OMP_ST_2]]
+// CHECK: store i32 [[ADD_3]], i32* [[OMP_UB]]
+
+// CHECK: [[DISPATCH_END]]
+// CHECK: call void @__kmpc_for_static_fin

[PATCH] D53693: [ASTImporter] Typedef import brings in the complete type

2018-10-26 Thread Aleksei Sidorin via Phabricator via cfe-commits
a_sidorin added a comment.

Hi Gabor,
Thank you for the patch. I looks reasonable but I have some questions.




Comment at: lib/AST/ASTImporter.cpp:2310
+D->getUnderlyingType(), FoundTypedef->getUnderlyingType())) {
+  QualType FromUT = D->getUnderlyingType();
+  QualType FoundUT = FoundTypedef->getUnderlyingType();

We can move these two vars upper and use them in the condition.



Comment at: lib/AST/ASTImporter.cpp:2314
+  // already have a complete underlying type then return with that.
+  if (!FromUT->isIncompleteType() && !FoundUT->isIncompleteType())
 return Importer.MapImported(D, FoundTypedef);

This condition omits the case where both types are complete. Should we use 
`FromUT->isIncompleteType == FoundUT-isIncompleteType()` instead?


Repository:
  rC Clang

https://reviews.llvm.org/D53693



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


[PATCH] D53443: [OpenMP][NVPTX] Enable default scheduling for parallel for in non-SPMD cases.

2018-10-26 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: test/OpenMP/nvptx_parallel_for_codegen.cpp:44
+// CHECK: call void @__kmpc_kernel_prepare_parallel(
+// CHECK: call void @__kmpc_begin_sharing_variables(i8*** %shared_arg_refs, 
i64 2)
+// CHECK: call void @llvm.nvvm.barrier0()

Do not use names of the IR vars, use regular expressions.


Repository:
  rC Clang

https://reviews.llvm.org/D53443



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


[PATCH] D44100: [ASTImporter] Reorder fields after structure import is finished

2018-10-26 Thread Aleksei Sidorin via Phabricator via cfe-commits
a_sidorin added a comment.

Hi Gabor,
I have tried to rebase it last week but there were some test failures. I hope 
to fix them this weekend and finally commit the patch.


Repository:
  rC Clang

https://reviews.llvm.org/D44100



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


r345398 - [Fixed Point Arithmetic] Refactor fixed point casts

2018-10-26 Thread Bjorn Pettersson via cfe-commits
Author: bjope
Date: Fri Oct 26 09:12:12 2018
New Revision: 345398

URL: http://llvm.org/viewvc/llvm-project?rev=345398&view=rev
Log:
[Fixed Point Arithmetic] Refactor fixed point casts

Summary:
- Added names for some emitted values (such as "tobool" for
  the result of a cast to boolean).
- Replaced explicit IRBuilder request for doing sext/zext/trunc
  by using CreateIntCast instead.
- Simplify code for emitting satuation into one if-statement
  for clamping to max, and one if-statement for clamping to min.

Reviewers: leonardchan, ebevhan

Reviewed By: leonardchan

Subscribers: cfe-commits

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

Modified:
cfe/trunk/lib/CodeGen/CGExprScalar.cpp
cfe/trunk/test/Frontend/fixed_point_conversions.c
cfe/trunk/test/Frontend/fixed_point_to_bool.c

Modified: cfe/trunk/lib/CodeGen/CGExprScalar.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprScalar.cpp?rev=345398&r1=345397&r2=345398&view=diff
==
--- cfe/trunk/lib/CodeGen/CGExprScalar.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprScalar.cpp Fri Oct 26 09:12:12 2018
@@ -1029,7 +1029,7 @@ Value *ScalarExprEmitter::EmitScalarConv
   // We do not need to check the padding bit on unsigned types if unsigned
   // padding is enabled because overflow into this bit is undefined
   // behavior.
-  return Builder.CreateIsNotNull(Src);
+  return Builder.CreateIsNotNull(Src, "tobool");
 }
 
 llvm_unreachable(
@@ -1247,79 +1247,62 @@ Value *ScalarExprEmitter::EmitFixedPoint
   unsigned DstWidth = DstFPSema.getWidth();
   unsigned SrcScale = SrcFPSema.getScale();
   unsigned DstScale = DstFPSema.getScale();
-  bool IsSigned = SrcFPSema.isSigned();
+  bool SrcIsSigned = SrcFPSema.isSigned();
+  bool DstIsSigned = DstFPSema.isSigned();
+
+  llvm::Type *DstIntTy = Builder.getIntNTy(DstWidth);
 
   Value *Result = Src;
   unsigned ResultWidth = SrcWidth;
 
   if (!DstFPSema.isSaturated()) {
-// Downscale
-if (DstScale < SrcScale) {
-  if (IsSigned)
-Result = Builder.CreateAShr(Result, SrcScale - DstScale);
-  else
-Result = Builder.CreateLShr(Result, SrcScale - DstScale);
-}
+// Downscale.
+if (DstScale < SrcScale)
+  Result = SrcIsSigned ?
+  Builder.CreateAShr(Result, SrcScale - DstScale, "downscale") :
+  Builder.CreateLShr(Result, SrcScale - DstScale, "downscale");
 
-// Resize
-llvm::Type *DstIntTy = Builder.getIntNTy(DstWidth);
-if (IsSigned)
-  Result = Builder.CreateSExtOrTrunc(Result, DstIntTy);
-else
-  Result = Builder.CreateZExtOrTrunc(Result, DstIntTy);
+// Resize.
+Result = Builder.CreateIntCast(Result, DstIntTy, SrcIsSigned, "resize");
 
-// Upscale
+// Upscale.
 if (DstScale > SrcScale)
-  Result = Builder.CreateShl(Result, DstScale - SrcScale);
+  Result = Builder.CreateShl(Result, DstScale - SrcScale, "upscale");
   } else {
+// Adjust the number of fractional bits.
 if (DstScale > SrcScale) {
-  // Need to extend first before scaling up
   ResultWidth = SrcWidth + DstScale - SrcScale;
   llvm::Type *UpscaledTy = Builder.getIntNTy(ResultWidth);
-
-  if (IsSigned)
-Result = Builder.CreateSExt(Result, UpscaledTy);
-  else
-Result = Builder.CreateZExt(Result, UpscaledTy);
-
-  Result = Builder.CreateShl(Result, DstScale - SrcScale);
+  Result = Builder.CreateIntCast(Result, UpscaledTy, SrcIsSigned, 
"resize");
+  Result = Builder.CreateShl(Result, DstScale - SrcScale, "upscale");
 } else if (DstScale < SrcScale) {
-  if (IsSigned)
-Result = Builder.CreateAShr(Result, SrcScale - DstScale);
-  else
-Result = Builder.CreateLShr(Result, SrcScale - DstScale);
+  Result = SrcIsSigned ?
+  Builder.CreateAShr(Result, SrcScale - DstScale, "downscale") :
+  Builder.CreateLShr(Result, SrcScale - DstScale, "downscale");
 }
 
-if (DstFPSema.getIntegralBits() < SrcFPSema.getIntegralBits()) {
-  auto Max = ConstantInt::get(
+// Handle saturation.
+bool LessIntBits = DstFPSema.getIntegralBits() < 
SrcFPSema.getIntegralBits();
+if (LessIntBits) {
+  Value *Max = ConstantInt::get(
   CGF.getLLVMContext(),
   APFixedPoint::getMax(DstFPSema).getValue().extOrTrunc(ResultWidth));
-  Value *TooHigh = IsSigned ? Builder.CreateICmpSGT(Result, Max)
-: Builder.CreateICmpUGT(Result, Max);
-  Result = Builder.CreateSelect(TooHigh, Max, Result);
-
-  if (IsSigned) {
-// Cannot overflow min to dest type is src is unsigned since all fixed
-// point types can cover the unsigned min of 0.
-auto Min = ConstantInt::get(
-CGF.getLLVMContext(),
-
APFixedPoint::getMin(DstFPSema).getValue().extOrTrunc(ResultWidth));
-Value *TooLow = Builder.CreateICmpSLT(Result,

[PATCH] D53738: [Fixed Point Arithmetic] Fixed Point Addition

2018-10-26 Thread Bjorn Pettersson via Phabricator via cfe-commits
bjope added inline comments.



Comment at: clang/lib/CodeGen/CGExprScalar.cpp:3208
+  if (LHSWidth < CommonWidth)
+LHS = LHSSign ? Builder.CreateSExt(LHS, CommonTy)
+  : Builder.CreateZExt(LHS, CommonTy);

`LHS = Builder.CreateIntCast(LHS, CommonTy, LHSSign);`

(I think that it even is possible to remove the condition and always do this 
(the cast will be a no-op if LHSWidth==CommonWidth))



Comment at: clang/lib/CodeGen/CGExprScalar.cpp:3211
+  if (RHSWidth < CommonWidth)
+RHS = RHSSign ? Builder.CreateSExt(RHS, CommonTy)
+  : Builder.CreateZExt(RHS, CommonTy);

Same as above, this can be simplified as:
  RHS = Builder.CreateIntCast(RHS, CommonTy, RHSSign);




Comment at: clang/lib/CodeGen/CGExprScalar.cpp:3214
+
+  // Align scales
+  unsigned CommonScale = std::max({LHSScale, RHSScale, ResultScale});

Arithmetically I think that it would be enough to align the scale to
```
 std::max(std::min(LHSScale, RHSScale), ResultScale)
```
As adding low fractional bits outside the result precision, when we know that 
those bits are zero in either of the inputs, won't impact any more significant 
bits in the result.

Maybe your solution is easier and good enough for a first implementation. And 
maybe `opt` is smart enough to optimize this anyway. Or maybe codegen could be 
worse due to not using legal types. Or maybe codegen could be improved due to 
using sadd.sat in more cases?
Lots of "maybes", so I don't think you need to do anything about this right 
now. It is just an idea from my side.



Comment at: clang/lib/CodeGen/CGExprScalar.cpp:3252
+  llvm::Function *intrinsic = CGF.CGM.getIntrinsic(IID, CommonTy);
+  Result = Builder.CreateCall(intrinsic, {LHS, RHS});
+}

It should be possible to do it like this (if you add some line wrapping):
```
Builder.CreateBinaryIntrinsic(ResultSign ? llvm::Intrinsic::sadd_sat : 
 llvm::Intrinsic::uadd_sat, LHS, RHS);

```


Repository:
  rC Clang

https://reviews.llvm.org/D53738



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


[PATCH] D53707: [Fixed Point Arithmetic] Refactor fixed point casts

2018-10-26 Thread Bjorn Pettersson via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC345398: [Fixed Point Arithmetic] Refactor fixed point casts 
(authored by bjope, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D53707?vs=171113&id=171311#toc

Repository:
  rC Clang

https://reviews.llvm.org/D53707

Files:
  lib/CodeGen/CGExprScalar.cpp
  test/Frontend/fixed_point_conversions.c
  test/Frontend/fixed_point_to_bool.c

Index: lib/CodeGen/CGExprScalar.cpp
===
--- lib/CodeGen/CGExprScalar.cpp
+++ lib/CodeGen/CGExprScalar.cpp
@@ -1029,7 +1029,7 @@
   // We do not need to check the padding bit on unsigned types if unsigned
   // padding is enabled because overflow into this bit is undefined
   // behavior.
-  return Builder.CreateIsNotNull(Src);
+  return Builder.CreateIsNotNull(Src, "tobool");
 }
 
 llvm_unreachable(
@@ -1247,79 +1247,62 @@
   unsigned DstWidth = DstFPSema.getWidth();
   unsigned SrcScale = SrcFPSema.getScale();
   unsigned DstScale = DstFPSema.getScale();
-  bool IsSigned = SrcFPSema.isSigned();
+  bool SrcIsSigned = SrcFPSema.isSigned();
+  bool DstIsSigned = DstFPSema.isSigned();
+
+  llvm::Type *DstIntTy = Builder.getIntNTy(DstWidth);
 
   Value *Result = Src;
   unsigned ResultWidth = SrcWidth;
 
   if (!DstFPSema.isSaturated()) {
-// Downscale
-if (DstScale < SrcScale) {
-  if (IsSigned)
-Result = Builder.CreateAShr(Result, SrcScale - DstScale);
-  else
-Result = Builder.CreateLShr(Result, SrcScale - DstScale);
-}
+// Downscale.
+if (DstScale < SrcScale)
+  Result = SrcIsSigned ?
+  Builder.CreateAShr(Result, SrcScale - DstScale, "downscale") :
+  Builder.CreateLShr(Result, SrcScale - DstScale, "downscale");
 
-// Resize
-llvm::Type *DstIntTy = Builder.getIntNTy(DstWidth);
-if (IsSigned)
-  Result = Builder.CreateSExtOrTrunc(Result, DstIntTy);
-else
-  Result = Builder.CreateZExtOrTrunc(Result, DstIntTy);
+// Resize.
+Result = Builder.CreateIntCast(Result, DstIntTy, SrcIsSigned, "resize");
 
-// Upscale
+// Upscale.
 if (DstScale > SrcScale)
-  Result = Builder.CreateShl(Result, DstScale - SrcScale);
+  Result = Builder.CreateShl(Result, DstScale - SrcScale, "upscale");
   } else {
+// Adjust the number of fractional bits.
 if (DstScale > SrcScale) {
-  // Need to extend first before scaling up
   ResultWidth = SrcWidth + DstScale - SrcScale;
   llvm::Type *UpscaledTy = Builder.getIntNTy(ResultWidth);
-
-  if (IsSigned)
-Result = Builder.CreateSExt(Result, UpscaledTy);
-  else
-Result = Builder.CreateZExt(Result, UpscaledTy);
-
-  Result = Builder.CreateShl(Result, DstScale - SrcScale);
+  Result = Builder.CreateIntCast(Result, UpscaledTy, SrcIsSigned, "resize");
+  Result = Builder.CreateShl(Result, DstScale - SrcScale, "upscale");
 } else if (DstScale < SrcScale) {
-  if (IsSigned)
-Result = Builder.CreateAShr(Result, SrcScale - DstScale);
-  else
-Result = Builder.CreateLShr(Result, SrcScale - DstScale);
+  Result = SrcIsSigned ?
+  Builder.CreateAShr(Result, SrcScale - DstScale, "downscale") :
+  Builder.CreateLShr(Result, SrcScale - DstScale, "downscale");
 }
 
-if (DstFPSema.getIntegralBits() < SrcFPSema.getIntegralBits()) {
-  auto Max = ConstantInt::get(
+// Handle saturation.
+bool LessIntBits = DstFPSema.getIntegralBits() < SrcFPSema.getIntegralBits();
+if (LessIntBits) {
+  Value *Max = ConstantInt::get(
   CGF.getLLVMContext(),
   APFixedPoint::getMax(DstFPSema).getValue().extOrTrunc(ResultWidth));
-  Value *TooHigh = IsSigned ? Builder.CreateICmpSGT(Result, Max)
-: Builder.CreateICmpUGT(Result, Max);
-  Result = Builder.CreateSelect(TooHigh, Max, Result);
-
-  if (IsSigned) {
-// Cannot overflow min to dest type is src is unsigned since all fixed
-// point types can cover the unsigned min of 0.
-auto Min = ConstantInt::get(
-CGF.getLLVMContext(),
-APFixedPoint::getMin(DstFPSema).getValue().extOrTrunc(ResultWidth));
-Value *TooLow = Builder.CreateICmpSLT(Result, Min);
-Result = Builder.CreateSelect(TooLow, Min, Result);
-  }
-} else if (IsSigned && !DstFPSema.isSigned()) {
-  llvm::Type *ResultTy = Builder.getIntNTy(ResultWidth);
-  Value *Zero = ConstantInt::getNullValue(ResultTy);
-  Value *LTZero = Builder.CreateICmpSLT(Result, Zero);
-  Result = Builder.CreateSelect(LTZero, Zero, Result);
+  Value *TooHigh = SrcIsSigned ? Builder.CreateICmpSGT(Result, Max)
+   : Builder.CreateICmpUGT(Result, Max);
+  Result = Builder.CreateSelect(TooHigh, Max, Result, "satmax");
+}
+// Cannot overflow min to dest type if src is unsign

[PATCH] D52676: [clang-format] tweaked another case of lambda formatting

2018-10-26 Thread Oleg Smolsky via Phabricator via cfe-commits
oleg.smolsky added a comment.

Folks, are there any other comments/suggestions?


Repository:
  rC Clang

https://reviews.llvm.org/D52676



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


[PATCH] D53200: [OpenCL] Fix serialization of OpenCLExtensionDecls

2018-10-26 Thread Alexey Sachkov via Phabricator via cfe-commits
AlexeySachkov added inline comments.



Comment at: test/SemaOpenCL/extension-begin.cl:43
   g(0); // expected-error {{no matching function for call to 'g'}}
-// expected-note@-26 {{candidate unavailable as it requires OpenCL 
extension 'my_ext' to be disabled}}
-// expected-note@-22 {{candidate function not viable: requires 0 
arguments, but 1 was provided}}
+// expected-note@extension-begin.h:18 {{candidate unavailable as it 
requires OpenCL extension 'my_ext' to be disabled}}
+// expected-note@extension-begin.h:23 {{candidate function not viable: 
requires 0 arguments, but 1 was provided}}

Anastasia wrote:
> Is this a typo? Should this be 'enabled' instead of 'disabled'?
I left the diagnostic message the same as it was. Looks like it is a bug in the 
diagnostic. I can try to fix it, but I would like to do it in a separate patch


https://reviews.llvm.org/D53200



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


[PATCH] D53768: Add VerboseOutputStream to CompilerInstance

2018-10-26 Thread Scott Linder via Phabricator via cfe-commits
scott.linder created this revision.
scott.linder added a reviewer: rsmith.
Herald added a subscriber: cfe-commits.

An attempt at removing one instance of a hardcoded output stream in 
`CompilerInstance::ExecuteAction`. There are still other cases of output being 
hard-coded to standard streams in `ExecuteCompilerInvocation`, but this patch 
attempts to cover some cases when no specific flags (e.g. -version or -help) 
are passed, namely the "X warnings and Y errors generated." diagnostic.


Repository:
  rC Clang

https://reviews.llvm.org/D53768

Files:
  include/clang/Frontend/CompilerInstance.h
  lib/Frontend/CompilerInstance.cpp
  unittests/Frontend/OutputStreamTest.cpp

Index: unittests/Frontend/OutputStreamTest.cpp
===
--- unittests/Frontend/OutputStreamTest.cpp
+++ unittests/Frontend/OutputStreamTest.cpp
@@ -10,6 +10,7 @@
 #include "clang/CodeGen/BackendUtil.h"
 #include "clang/CodeGen/CodeGenAction.h"
 #include "clang/Frontend/CompilerInstance.h"
+#include "clang/Frontend/TextDiagnosticPrinter.h"
 #include "clang/FrontendTool/Utils.h"
 #include "clang/Lex/PreprocessorOptions.h"
 #include "gtest/gtest.h"
@@ -43,4 +44,29 @@
   EXPECT_TRUE(!IRBuffer.empty());
   EXPECT_TRUE(StringRef(IRBuffer.data()).startswith("BC"));
 }
+
+TEST(FrontendOutputTests, TestVerboseOutputStream) {
+  auto Invocation = std::make_shared();
+  Invocation->getPreprocessorOpts().addRemappedFile(
+  "test.cc", MemoryBuffer::getMemBuffer("invalid").release());
+  Invocation->getFrontendOpts().Inputs.push_back(
+  FrontendInputFile("test.cc", InputKind::CXX));
+  Invocation->getFrontendOpts().ProgramAction = EmitBC;
+  Invocation->getTargetOpts().Triple = "i386-unknown-linux-gnu";
+  CompilerInstance Compiler;
+
+  std::string VerboseBuffer;
+  raw_string_ostream VerboseStream(VerboseBuffer);
+
+  Compiler.setInvocation(std::move(Invocation));
+  IntrusiveRefCntPtr DiagOpts = new DiagnosticOptions();
+  Compiler.createDiagnostics(
+  new TextDiagnosticPrinter(llvm::nulls(), &*DiagOpts), true);
+  Compiler.setVerboseOutputStream(VerboseStream);
+
+  bool Success = ExecuteCompilerInvocation(&Compiler);
+  EXPECT_FALSE(Success);
+  EXPECT_TRUE(!VerboseStream.str().empty());
+  EXPECT_TRUE(StringRef(VerboseBuffer.data()).contains("errors generated"));
+}
 }
Index: lib/Frontend/CompilerInstance.cpp
===
--- lib/Frontend/CompilerInstance.cpp
+++ lib/Frontend/CompilerInstance.cpp
@@ -70,6 +70,8 @@
 
 CompilerInstance::~CompilerInstance() {
   assert(OutputFiles.empty() && "Still output files in flight?");
+  if (OwnsVerboseOutputStream)
+delete VerboseOutputStream;
 }
 
 void CompilerInstance::setInvocation(
@@ -88,6 +90,12 @@
   Diagnostics = Value;
 }
 
+void CompilerInstance::setVerboseOutputStream(raw_ostream &Value,
+  bool OwnsOutputStream) {
+  OwnsVerboseOutputStream = OwnsOutputStream;
+  VerboseOutputStream = &Value;
+}
+
 void CompilerInstance::setTarget(TargetInfo *Value) { Target = Value; }
 void CompilerInstance::setAuxTarget(TargetInfo *Value) { AuxTarget = Value; }
 
@@ -907,9 +915,7 @@
   assert(!getFrontendOpts().ShowHelp && "Client must handle '-help'!");
   assert(!getFrontendOpts().ShowVersion && "Client must handle '-version'!");
 
-  // FIXME: Take this as an argument, once all the APIs we used have moved to
-  // taking it as an input instead of hard-coding llvm::errs.
-  raw_ostream &OS = llvm::errs();
+  raw_ostream &OS = getVerboseOutputStream();
 
   if (!Act.PrepareToExecute(*this))
 return false;
Index: include/clang/Frontend/CompilerInstance.h
===
--- include/clang/Frontend/CompilerInstance.h
+++ include/clang/Frontend/CompilerInstance.h
@@ -161,6 +161,12 @@
   /// One or more modules failed to build.
   bool ModuleBuildFailed = false;
 
+  /// Whether we should delete VerboseOutputStream on destruction.
+  bool OwnsVerboseOutputStream = false;
+
+  /// The stream for verbose output.
+  raw_ostream *VerboseOutputStream = &llvm::errs();
+
   /// Holds information about the output file.
   ///
   /// If TempFilename is not empty we must rename it to Filename at the end.
@@ -223,9 +229,6 @@
   /// \param Act - The action to execute.
   /// \return - True on success.
   //
-  // FIXME: This function should take the stream to write any debugging /
-  // verbose output to as an argument.
-  //
   // FIXME: Eliminate the llvm_shutdown requirement, that should either be part
   // of the context or else not CompilerInstance specific.
   bool ExecuteAction(FrontendAction &Act);
@@ -356,6 +359,21 @@
   }
 
   /// }
+  /// @name VerboseOutputStream
+  /// }
+
+  /// Replace the current stream for verbose output.
+  ///
+  /// If not set, this stream defaults to \c llvm::errs().
+  void setVerboseOutputStream(raw_ostream &Value,
+  bool Owns

[PATCH] D53417: [Clang][Sema][PowerPC] Choose a better candidate in overload function call if there is a compatible vector conversion instead of ambiguous call error

2018-10-26 Thread Hubert Tong via Phabricator via cfe-commits
hubert.reinterpretcast added inline comments.



Comment at: clang/lib/Sema/SemaOverload.cpp:3913
+for (auto Type : Types) {
+  if (S.Context.getCanonicalType(Type)->getTypeClass() != Type::Vector)
+return false;

wuzish wrote:
> hubert.reinterpretcast wrote:
> > wuzish wrote:
> > > hubert.reinterpretcast wrote:
> > > > wuzish wrote:
> > > > > hubert.reinterpretcast wrote:
> > > > > > Considering that this is a local lambda called in one place, are we 
> > > > > > expecting cases where the canonical type is not something on which 
> > > > > > we can call getVectorKind()? If not, then we do not need this `if`.
> > > > > Well, that's for ExtVectorType. I encounter some testcase failure 
> > > > > because of that. So I just narrow the condition to only handle 
> > > > > Type::Vector.
> > > > > 
> > > > > As the following comment said, so I treat it separately.
> > > > > 
> > > > > /// ExtVectorType - Extended vector type. This type is created using
> > > > > /// __attribute__((ext_vector_type(n)), where "n" is the number of 
> > > > > elements.
> > > > > /// Unlike vector_size, ext_vector_type is only allowed on typedef's. 
> > > > > This
> > > > > /// class enables syntactic extensions, like Vector Components for 
> > > > > accessing
> > > > > /// points (as .xyzw), colors (as .rgba), and textures (modeled after 
> > > > > OpenGL
> > > > > /// Shading Language).
> > > > An ExtVectorType is a VectorType, so what sort of failures are you 
> > > > hitting?
> > > Yes. But the TypeClass of ExtVectorType is ExtVector.
> > > 
> > > some test points check the error report for ambiguous call because of too 
> > > many implicit cast choices from ext_vector_type to vector type. Such as 
> > > blow.
> > > 
> > > 
> > > ```
> > > typedef char char16 __attribute__ ((__vector_size__ (16)));
> > > typedef long long longlong16 __attribute__ ((__vector_size__ (16)));
> > > typedef char char16_e __attribute__ ((__ext_vector_type__ (16)));
> > > typedef long long longlong16_e __attribute__ ((__ext_vector_type__ (2)));
> > > 
> > > 
> > > void f1_test(char16 c16, longlong16 ll16, char16_e c16e, longlong16_e 
> > > ll16e) {
> > >   int &ir1 = f1(c16);
> > >   float &fr1 = f1(ll16);
> > >   f1(c16e); // expected-error{{call to 'f1' is ambiguous}}
> > >   f1(ll16e); // expected-error{{call to 'f1' is ambiguous}}
> > > }
> > > ```
> > > 
> > > If we are gonna widen the condition, we can make a follow-up patch. Or we 
> > > need include this condition and do this together in this patch?
> > The widening that has occurred is in allowing the scope of the change to 
> > encompass cases where AltiVec vectors are not sufficiently involved. The 
> > change in behaviour makes sense, and perhaps the community may want to 
> > pursue it; however, the mandate to make that level of change has not been 
> > given.
> > 
> > I do not believe that requiring that the TypeClass be VectorType is the 
> > correct narrowing of the scope. Instead, we may want to consider requiring 
> > that for each `SCS` in { `SCS1`, `SCS2` }, there is one AltiVec type and 
> > one generic vector type in { `SCS.getFromType()`, `SCS.getToType(2)` }.
> > 
> The key point is that ExtVector is a kind of typeclass, **and** its vector 
> kind is generic vector type.
> 
> So you think we should encompass ext_vector cases as a part of the scope of 
> this patch? And modify the above cases' expected behavior (remove the 
> **expected-error**)?
I gave a concrete suggested narrowing of the scope that does not exclude 
ExtVectorType or other derived types of VectorType. It also does not change the 
behaviour of the `f1_test` case above. We could pursue additional discussion 
over that case (separable from the current patch) on the mailing list.

I believe my suggestion does do something about this case:
```
typedef unsigned int GccType __attribute__((__ext_vector_type__(16)));
typedef __vector unsigned int AltiVecType;

typedef float GccOtherType __attribute__((__vector_size__(16)));

void f(GccType);
void f(GccOtherType);

void g(AltiVecType v) { f(v); }
```

I think that addressing the latter case is within the realm of things that we 
should consider for this patch. Either way, we should ensure that tests for 
AltiVec/__ext_vector_type__ conversions are available.


https://reviews.llvm.org/D53417



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


[PATCH] D53770: Support g++ headers in include/g++

2018-10-26 Thread David Greene via Phabricator via cfe-commits
greened created this revision.
greened added reviewers: danalbert, dlj, atanasyan, phosek.
Herald added a subscriber: cfe-commits.

Some gcc installations put C++ headers in PREFIX/include/g++ without indicating 
a gcc version at all.  Typically this is because the version is encoded 
somewhere in PREFIX.


Repository:
  rC Clang

https://reviews.llvm.org/D53770

Files:
  lib/Driver/ToolChains/Linux.cpp


Index: lib/Driver/ToolChains/Linux.cpp
===
--- lib/Driver/ToolChains/Linux.cpp
+++ lib/Driver/ToolChains/Linux.cpp
@@ -924,6 +924,9 @@
   // Freescale SDK C++ headers are directly in /usr/include/c++,
   // without a subdirectory corresponding to the gcc version.
   LibDir.str() + "/../include/c++",
+  // Some gcc installations put headers under "g++" without a
+  // version suffix.
+  LibDir.str() + "/../include/g++",
   };
 
   for (const auto &IncludePath : LibStdCXXIncludePathCandidates) {


Index: lib/Driver/ToolChains/Linux.cpp
===
--- lib/Driver/ToolChains/Linux.cpp
+++ lib/Driver/ToolChains/Linux.cpp
@@ -924,6 +924,9 @@
   // Freescale SDK C++ headers are directly in /usr/include/c++,
   // without a subdirectory corresponding to the gcc version.
   LibDir.str() + "/../include/c++",
+  // Some gcc installations put headers under "g++" without a
+  // version suffix.
+  LibDir.str() + "/../include/g++",
   };
 
   for (const auto &IncludePath : LibStdCXXIncludePathCandidates) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D53771: [clang-tidy] Avoid C arrays check

2018-10-26 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri created this revision.
lebedev.ri added reviewers: aaron.ballman, JonasToth, alexfh, hokein, xazax.hun.
lebedev.ri added a project: clang-tools-extra.
Herald added subscribers: rnkovacs, mgorny.
lebedev.ri edited the summary of this revision.

PR39224 
As discussed, we can't always do the transform automatically due to that 
array-to-pointer decay of C array.
In order to detect whether we can do said transform, we'd need to be able to 
see all usages of said array,
which is, i would say, rather impossible if e.g. it is in the header.
Thus right now no fixit exists.

Also, is `misc` the best place for this check?

Exceptions: `extern "C"` code.

References:

- CPPCG ES.27: Use std::array or stack_array for arrays on the stack 

- CPPCG SL.con.1: Prefer using STL array or vector instead of a C array 

- HICPP `4.1.1 Ensure that a function argument does not undergo an 
array-to-pointer conversion`
- MISRA `5-2-12 An identifier with array type passed as a function argument 
shall not decay to a pointer`


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D53771

Files:
  clang-tidy/misc/AvoidCArraysCheck.cpp
  clang-tidy/misc/AvoidCArraysCheck.h
  clang-tidy/misc/CMakeLists.txt
  clang-tidy/misc/MiscTidyModule.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/misc-avoid-c-arrays.rst
  test/clang-tidy/misc-avoid-c-arrays.cpp

Index: test/clang-tidy/misc-avoid-c-arrays.cpp
===
--- /dev/null
+++ test/clang-tidy/misc-avoid-c-arrays.cpp
@@ -0,0 +1,35 @@
+// RUN: %check_clang_tidy %s misc-avoid-c-arrays %t
+
+int a[] = {1, 2};
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: do not declare C-style arrays, use std::array<> instead
+
+int b[1];
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: do not declare C-style arrays, use std::array<> instead
+
+void foo() {
+  int c[b[0]];
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: do not declare C-style arrays, use std::array<> instead
+}
+
+template 
+class array {
+  T d[Size];
+  // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: do not declare C-style arrays, use std::array<> instead
+
+  int e[1];
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: do not declare C-style arrays, use std::array<> instead
+};
+
+// Some header
+extern "C" {
+
+int f[] = {1, 2};
+
+int j[1];
+
+inline void bar() {
+  {
+int j[j[0]];
+  }
+}
+}
Index: docs/clang-tidy/checks/misc-avoid-c-arrays.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/misc-avoid-c-arrays.rst
@@ -0,0 +1,52 @@
+.. title:: clang-tidy - misc-avoid-c-arrays
+
+misc-avoid-c-arrays
+===
+
+Find C-style array delarations and recommend to use ``std::array<>``.
+All types of C arrays are diagnosed.
+
+Hoever, no fix-its are provided. Such transform would need to be able to
+observe *all* the uses of said declaration in order to decide whether it is
+safe to transform or not, and that is impossible in case of headers.
+
+.. code:: c++
+
+  int a[] = {1, 2}; // warning: do not declare C-style arrays, use std::array<> instead
+
+  int b[1]; // warning: do not declare C-style arrays, use std::array<> instead
+
+  void foo() {
+int c[b[0]]; // warning: do not declare C-style arrays, use std::array<> instead
+  }
+
+  template 
+  class array {
+T d[Size]; // warning: do not declare C-style arrays, use std::array<> instead
+
+int e[1]; // warning: do not declare C-style arrays, use std::array<> instead
+  };
+
+  ...
+
+However, the ``extern "C"`` code is ignored, since it is common to share
+such headers between C code, and C++ code.
+
+.. code:: c++
+
+  // Some header
+  extern "C" {
+
+  int f[] = {1, 2}; // not diagnosed
+
+  int j[1]; // not diagnosed
+
+  inline void bar() {
+{
+  int j[j[0]]; // not diagnosed
+}
+  }
+
+  }
+
+  ...
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -10,8 +10,8 @@
abseil-no-internal-dependencies
abseil-no-namespace
abseil-redundant-strcat-calls
-   abseil-string-find-startswith
abseil-str-cat-append
+   abseil-string-find-startswith
android-cloexec-accept
android-cloexec-accept4
android-cloexec-creat
@@ -151,19 +151,20 @@
hicpp-special-member-functions (redirects to cppcoreguidelines-special-member-functions) 
hicpp-static-assert (redirects to misc-static-assert) 
hicpp-undelegated-constructor (redirects to bugprone-undelegated-constructor) 
+   hicpp-uppercase-literal-suffix (redirects to readability-uppercase-literal-suffix) 

[PATCH] D53025: [clang-tidy] implement new check for const return types.

2018-10-26 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel marked 2 inline comments as done.
ymandel added inline comments.



Comment at: clang-tidy/readability/ConstValueReturnCheck.cpp:107
+diag(Def->getInnerLocStart(), "return type %0 is 'const'-qualified "
+  "hindering compiler optimizations")
+<< Def->getReturnType();

aaron.ballman wrote:
> ymandel wrote:
> > aaron.ballman wrote:
> > > It seems strange to me that this is in the readability module but the 
> > > diagnostic here is about compiler optimizations. Should this be in the 
> > > performance module instead? Or should this diagnostic be reworded about 
> > > the readability concerns?
> > Good point. The readability angle is that the const clutters the code to no 
> > benefit.  That is, even if it was performance neutral, I'd still want to 
> > discourage this practice.  But, it does seem like the primary impact is 
> > performance. 
> > 
> > I'm fine either way -- moving it to performance or emphasizing the clutter 
> > of the unhelpful "const".  I'm inclined to moving it, but don't have good 
> > sense of how strict these hierarchies are. What do you think?
> I'm not sold that `const`-qualified return types always pessimize 
> optimizations. However, I'm also not sold that it's *always* a bad idea to 
> have a top-level cv-qualifier on a return type either (for instance, this is 
> one way to prevent callers from modifying a temp returned by a function). How 
> about leaving this in readability and changing the diagnostic into: 
> "top-level 'const' qualifier on a return type may reduce code readability 
> with limited benefit" or something equally weasely?
I talked this over with other google folks and seems like the consensus is:

1.  The readability benefits may be controversial.  Some folks might not view 
`const` as clutter and there are some corner cases where the qualifier may 
prevent something harmful.
2.  The performance implication is real, if not guaranteed to be a problem.

Based on this, seems best to move it to performance, but water down the 
performance claims.  That keeps the focus to an issue we can assume nearly 
everyone agrees on.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D53025



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


[PATCH] D53417: [Clang][Sema][PowerPC] Choose a better candidate in overload function call if there is a compatible vector conversion instead of ambiguous call error

2018-10-26 Thread Hubert Tong via Phabricator via cfe-commits
hubert.reinterpretcast added inline comments.



Comment at: clang/lib/Sema/SemaOverload.cpp:3913
+for (auto Type : Types) {
+  if (S.Context.getCanonicalType(Type)->getTypeClass() != Type::Vector)
+return false;

hubert.reinterpretcast wrote:
> wuzish wrote:
> > hubert.reinterpretcast wrote:
> > > wuzish wrote:
> > > > hubert.reinterpretcast wrote:
> > > > > wuzish wrote:
> > > > > > hubert.reinterpretcast wrote:
> > > > > > > Considering that this is a local lambda called in one place, are 
> > > > > > > we expecting cases where the canonical type is not something on 
> > > > > > > which we can call getVectorKind()? If not, then we do not need 
> > > > > > > this `if`.
> > > > > > Well, that's for ExtVectorType. I encounter some testcase failure 
> > > > > > because of that. So I just narrow the condition to only handle 
> > > > > > Type::Vector.
> > > > > > 
> > > > > > As the following comment said, so I treat it separately.
> > > > > > 
> > > > > > /// ExtVectorType - Extended vector type. This type is created using
> > > > > > /// __attribute__((ext_vector_type(n)), where "n" is the number of 
> > > > > > elements.
> > > > > > /// Unlike vector_size, ext_vector_type is only allowed on 
> > > > > > typedef's. This
> > > > > > /// class enables syntactic extensions, like Vector Components for 
> > > > > > accessing
> > > > > > /// points (as .xyzw), colors (as .rgba), and textures (modeled 
> > > > > > after OpenGL
> > > > > > /// Shading Language).
> > > > > An ExtVectorType is a VectorType, so what sort of failures are you 
> > > > > hitting?
> > > > Yes. But the TypeClass of ExtVectorType is ExtVector.
> > > > 
> > > > some test points check the error report for ambiguous call because of 
> > > > too many implicit cast choices from ext_vector_type to vector type. 
> > > > Such as blow.
> > > > 
> > > > 
> > > > ```
> > > > typedef char char16 __attribute__ ((__vector_size__ (16)));
> > > > typedef long long longlong16 __attribute__ ((__vector_size__ (16)));
> > > > typedef char char16_e __attribute__ ((__ext_vector_type__ (16)));
> > > > typedef long long longlong16_e __attribute__ ((__ext_vector_type__ 
> > > > (2)));
> > > > 
> > > > 
> > > > void f1_test(char16 c16, longlong16 ll16, char16_e c16e, longlong16_e 
> > > > ll16e) {
> > > >   int &ir1 = f1(c16);
> > > >   float &fr1 = f1(ll16);
> > > >   f1(c16e); // expected-error{{call to 'f1' is ambiguous}}
> > > >   f1(ll16e); // expected-error{{call to 'f1' is ambiguous}}
> > > > }
> > > > ```
> > > > 
> > > > If we are gonna widen the condition, we can make a follow-up patch. Or 
> > > > we need include this condition and do this together in this patch?
> > > The widening that has occurred is in allowing the scope of the change to 
> > > encompass cases where AltiVec vectors are not sufficiently involved. The 
> > > change in behaviour makes sense, and perhaps the community may want to 
> > > pursue it; however, the mandate to make that level of change has not been 
> > > given.
> > > 
> > > I do not believe that requiring that the TypeClass be VectorType is the 
> > > correct narrowing of the scope. Instead, we may want to consider 
> > > requiring that for each `SCS` in { `SCS1`, `SCS2` }, there is one AltiVec 
> > > type and one generic vector type in { `SCS.getFromType()`, 
> > > `SCS.getToType(2)` }.
> > > 
> > The key point is that ExtVector is a kind of typeclass, **and** its vector 
> > kind is generic vector type.
> > 
> > So you think we should encompass ext_vector cases as a part of the scope of 
> > this patch? And modify the above cases' expected behavior (remove the 
> > **expected-error**)?
> I gave a concrete suggested narrowing of the scope that does not exclude 
> ExtVectorType or other derived types of VectorType. It also does not change 
> the behaviour of the `f1_test` case above. We could pursue additional 
> discussion over that case (separable from the current patch) on the mailing 
> list.
> 
> I believe my suggestion does do something about this case:
> ```
> typedef unsigned int GccType __attribute__((__ext_vector_type__(16)));
> typedef __vector unsigned int AltiVecType;
> 
> typedef float GccOtherType __attribute__((__vector_size__(16)));
> 
> void f(GccType);
> void f(GccOtherType);
> 
> void g(AltiVecType v) { f(v); }
> ```
> 
> I think that addressing the latter case is within the realm of things that we 
> should consider for this patch. Either way, we should ensure that tests for 
> AltiVec/__ext_vector_type__ conversions are available.
Sorry, typo in the above case:
```
typedef unsigned int GccType __attribute__((__ext_vector_type__(4)));
```



https://reviews.llvm.org/D53417



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


[PATCH] D53771: [clang-tidy] Avoid C arrays check

2018-10-26 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth added a comment.

`modernize` would be a fitting module, wouldn't it?


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D53771



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


[PATCH] D53771: [clang-tidy] Avoid C arrays check

2018-10-26 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth added inline comments.



Comment at: docs/clang-tidy/checks/list.rst:13
abseil-redundant-strcat-calls
-   abseil-string-find-startswith
abseil-str-cat-append

spurious change



Comment at: docs/clang-tidy/checks/list.rst:154
hicpp-undelegated-constructor (redirects to 
bugprone-undelegated-constructor) 
+   hicpp-uppercase-literal-suffix (redirects to 
readability-uppercase-literal-suffix) 
hicpp-use-auto (redirects to modernize-use-auto) 

here as well



Comment at: docs/clang-tidy/checks/misc-avoid-c-arrays.rst:51
+  }
+
+  ...

The last two lines do not add value, i think you can safely remove them



Comment at: test/clang-tidy/misc-avoid-c-arrays.cpp:14
+
+template 
+class array {

Please add a case with templates, where `T` itself is the array type, maybe 
there are other fancy template tricks that could create an array implictly?


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D53771



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


[PATCH] D50860: [libc++][test] Remove non-portable assumption that thread's constructor allocates with ::new

2018-10-26 Thread Casey Carter via Phabricator via cfe-commits
CaseyCarter added a comment.

I'll put this explanation in the comments and push a change.




Comment at: 
test/std/thread/thread.threads/thread.thread.class/thread.thread.constr/F.pass.cpp:121
 //allocations.
+int numAllocs;
+

EricWF wrote:
> Why?
`main` non-portably assumes that thread creation results in at least one call 
to `::operator new`. This change fixes that assumption by counting the number 
of calls to `::operator new` here for creation of a do-nothing thread, and 
communicating that count to `main` via `numAllocs`.



Comment at: 
test/std/thread/thread.threads/thread.thread.class/thread.thread.constr/F.pass.cpp:171
 #ifndef TEST_HAS_NO_EXCEPTIONS
-{
+if (numAllocs > 0) {
 try

EricWF wrote:
> I'm not sure I understand this change either.
> 
If thread creation in `test_throwing_new_during_thread_creation` resulted in 
`0` calls to `::operator new`, the expectation is that the same will occur here 
when we create a thread. If `::operator new` isn't called, it can't throw the 
exception this test is expecting to catch.


https://reviews.llvm.org/D50860



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


[PATCH] D53200: [OpenCL] Fix serialization of OpenCLExtensionDecls

2018-10-26 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added inline comments.



Comment at: test/SemaOpenCL/extension-begin.cl:43
   g(0); // expected-error {{no matching function for call to 'g'}}
-// expected-note@-26 {{candidate unavailable as it requires OpenCL 
extension 'my_ext' to be disabled}}
-// expected-note@-22 {{candidate function not viable: requires 0 
arguments, but 1 was provided}}
+// expected-note@extension-begin.h:18 {{candidate unavailable as it 
requires OpenCL extension 'my_ext' to be disabled}}
+// expected-note@extension-begin.h:23 {{candidate function not viable: 
requires 0 arguments, but 1 was provided}}

AlexeySachkov wrote:
> Anastasia wrote:
> > Is this a typo? Should this be 'enabled' instead of 'disabled'?
> I left the diagnostic message the same as it was. Looks like it is a bug in 
> the diagnostic. I can try to fix it, but I would like to do it in a separate 
> patch
Sure! Thanks!


https://reviews.llvm.org/D53200



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


[PATCH] D53206: Allow padding checker to traverse simple class hierarchies

2018-10-26 Thread Max Bernstein via Phabricator via cfe-commits
tekknolagi added inline comments.



Comment at: lib/StaticAnalyzer/Checkers/PaddingChecker.cpp:78-81
+// We need to be looking at a definition, not just any pointer to the
+// declaration.
+if (!(RD = RD->getDefinition()))
+  return;

tekknolagi wrote:
> NoQ wrote:
> > This check is already in `shouldSkipDecl()` (?)
> Oh yes, you're right.
Actually, I'm not sure if you're right. I think it's necessary here because 
it's only tested for C++ classes in shouldSkipDecl(). This tests it for C 
structs too.  Either we could lift that outside the C++ section of 
shouldSkipDecl or repeat it here.


Repository:
  rC Clang

https://reviews.llvm.org/D53206



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


[PATCH] D53206: Allow padding checker to traverse simple class hierarchies

2018-10-26 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added inline comments.



Comment at: lib/StaticAnalyzer/Checkers/PaddingChecker.cpp:78-81
+// We need to be looking at a definition, not just any pointer to the
+// declaration.
+if (!(RD = RD->getDefinition()))
+  return;

tekknolagi wrote:
> tekknolagi wrote:
> > NoQ wrote:
> > > This check is already in `shouldSkipDecl()` (?)
> > Oh yes, you're right.
> Actually, I'm not sure if you're right. I think it's necessary here because 
> it's only tested for C++ classes in shouldSkipDecl(). This tests it for C 
> structs too.  Either we could lift that outside the C++ section of 
> shouldSkipDecl or repeat it here.
Hmm, indeed. Sry!


Repository:
  rC Clang

https://reviews.llvm.org/D53206



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


[PATCH] D53772: [NFC][OpenMP] Add new test for parallel for code generation.

2018-10-26 Thread Gheorghe-Teodor Bercea via Phabricator via cfe-commits
gtbercea created this revision.
gtbercea added reviewers: ABataev, caomhin.
Herald added subscribers: cfe-commits, guansong.

This is a simple test of the parallel for code generation. It will be used to 
showcase the change introduced by patch https://reviews.llvm.org/D53443.


Repository:
  rC Clang

https://reviews.llvm.org/D53772

Files:
  test/OpenMP/nvptx_parallel_for_codegen.cpp

Index: test/OpenMP/nvptx_parallel_for_codegen.cpp
===
--- /dev/null
+++ test/OpenMP/nvptx_parallel_for_codegen.cpp
@@ -0,0 +1,101 @@
+// Test target codegen - host bc file has to be created first.
+// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm-bc %s -o %t-ppc-host.bc
+// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple nvptx64-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o - | FileCheck %s --check-prefix CHECK --check-prefix CHECK-64
+// expected-no-diagnostics
+#ifndef HEADER
+#define HEADER
+
+template
+tx ftemplate(int n) {
+  tx b[10];
+
+  #pragma omp target
+  {
+tx d = n;
+#pragma omp parallel for
+for(int i=0; i<10; i++) {
+  b[i] += d;
+}
+b[3] += 1;
+  }
+
+  return b[3];
+}
+
+int bar(int n){
+  int a = 0;
+
+  a += ftemplate(n);
+
+  return a;
+}
+
+// CHECK-LABEL: define {{.*}}void {{@__omp_offloading_.+template.+l12}}_worker()
+// CHECK: call void @llvm.nvvm.barrier0()
+// CHECK: call i1 @__kmpc_kernel_parallel(
+// CHECK: call void @__omp_outlined___wrapper(
+
+// CHECK: define weak void @__omp_offloading_{{.*}}l12(
+// CHECK: call void @__omp_offloading_{{.*}}l12_worker()
+// CHECK: call void @__kmpc_kernel_init(
+// CHECK: call void @__kmpc_data_sharing_init_stack()
+// CHECK: call i8* @__kmpc_data_sharing_push_stack(i64 4, i16 0)
+// CHECK: call void @__kmpc_kernel_prepare_parallel(
+// CHECK: call void @__kmpc_begin_sharing_variables({{.*}}, i64 2)
+// CHECK: call void @llvm.nvvm.barrier0()
+// CHECK: call void @llvm.nvvm.barrier0()
+// CHECK: call void @__kmpc_end_sharing_variables()
+// CHECK: call void @__kmpc_data_sharing_pop_stack(
+// CHECK: call void @__kmpc_kernel_deinit(i16 1)
+
+// CHECK: define internal void @__omp_outlined__(
+// CHECK: alloca
+// CHECK: alloca
+// CHECK: alloca
+// CHECK: alloca
+// CHECK: [[OMP_IV:%.*]] = alloca i32
+// CHECK: store i32 0, {{.*}} [[OMP_LB:%.+]],
+// CHECK: store i32 9, {{.*}} [[OMP_UB:%.+]],
+// CHECK: store i32 1, {{.*}} [[OMP_ST:%.+]],
+// CHECK: call void @__kmpc_for_static_init_4({{.*}} i32 34, {{.*}} [[OMP_LB]], {{.*}} [[OMP_UB]], {{.*}} [[OMP_ST]], i32 1, i32 1)
+// CHECK: [[OMP_UB_1:%.+]] = load {{.*}} [[OMP_UB]]
+// CHECK: [[COMP_1:%.+]] = icmp sgt {{.*}} [[OMP_UB_1]]
+// CHECK: br i1 [[COMP_1]], label %[[COND_TRUE:.+]], label %[[COND_FALSE:.+]]
+
+// CHECK: [[COND_TRUE]]
+// CHECK: br label %[[COND_END:.+]]
+
+// CHECK: [[COND_FALSE]]
+// CHECK: [[OMP_UB_2:%.+]] = load {{.*}}* [[OMP_UB]]
+// CHECK: br label %[[COND_END]]
+
+// CHECK: [[COND_END]]
+// CHECK: [[COND_RES:%.+]] = phi i32 [ 9, %[[COND_TRUE]] ], [ [[OMP_UB_2]], %[[COND_FALSE]] ]
+// CHECK: store i32 [[COND_RES]], i32* [[OMP_UB]]
+// CHECK: [[OMP_LB_1:%.+]] = load i32, i32* [[OMP_LB]]
+// CHECK: store i32 [[OMP_LB_1]], i32* [[OMP_IV]]
+// CHECK: br label %[[OMP_INNER_FOR_COND:.+]]
+
+// CHECK: [[OMP_INNER_FOR_COND]]
+// CHECK: [[OMP_IV_2:%.+]] = load i32, i32* [[OMP_IV]]
+// CHECK: [[OMP_UB_4:%.+]] = load i32, i32* [[OMP_UB]]
+// CHECK: [[COMP_3:%.+]] = icmp sle i32 [[OMP_IV_2]], [[OMP_UB_4]]
+// CHECK: br i1 [[COMP_3]], label %[[OMP_INNER_FOR_BODY:.+]], label %[[OMP_INNER_FOR_END:.+]]
+
+// CHECK: [[OMP_INNER_FOR_BODY]]
+// CHECK: br label %[[OMP_BODY_CONTINUE:.+]]
+
+// CHECK: [[OMP_BODY_CONTINUE]]
+// CHECK: br label %[[OMP_INNER_FOR_INC:.+]]
+
+// CHECK: [[OMP_INNER_FOR_INC]]
+// CHECK: [[OMP_IV_3:%.+]] = load i32, i32* [[OMP_IV]]
+// CHECK: [[ADD_1:%.+]] = add nsw i32 [[OMP_IV_3]], 1
+// CHECK: store i32 [[ADD_1]], i32* [[OMP_IV]]
+// CHECK: br label %[[OMP_INNER_FOR_COND]]
+
+// CHECK: [[OMP_INNER_FOR_END]]
+// CHECK: call void @__kmpc_for_static_fini(
+// CHECK: ret void
+
+#endif
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D53772: [NFC][OpenMP] Add new test for parallel for code generation.

2018-10-26 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev accepted this revision.
ABataev added a comment.
This revision is now accepted and ready to land.

LG


Repository:
  rC Clang

https://reviews.llvm.org/D53772



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


r345417 - [NFC][OpenMP] Add new test for parallel for code generation.

2018-10-26 Thread Gheorghe-Teodor Bercea via cfe-commits
Author: gbercea
Date: Fri Oct 26 11:59:52 2018
New Revision: 345417

URL: http://llvm.org/viewvc/llvm-project?rev=345417&view=rev
Log:
[NFC][OpenMP] Add new test for parallel for code generation.

Summary:
This is a simple test of the parallel for code generation. It will be used to 
showcase the change introduced by patch D53443.


Reviewers: ABataev, caomhin

Reviewed By: ABataev

Subscribers: guansong, cfe-commits

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

Added:
cfe/trunk/test/OpenMP/nvptx_parallel_for_codegen.cpp

Added: cfe/trunk/test/OpenMP/nvptx_parallel_for_codegen.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/nvptx_parallel_for_codegen.cpp?rev=345417&view=auto
==
--- cfe/trunk/test/OpenMP/nvptx_parallel_for_codegen.cpp (added)
+++ cfe/trunk/test/OpenMP/nvptx_parallel_for_codegen.cpp Fri Oct 26 11:59:52 
2018
@@ -0,0 +1,101 @@
+// Test target codegen - host bc file has to be created first.
+// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple powerpc64le-unknown-unknown 
-fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm-bc %s -o %t-ppc-host.bc
+// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple nvptx64-unknown-unknown 
-fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm %s -fopenmp-is-device 
-fopenmp-host-ir-file-path %t-ppc-host.bc -o - | FileCheck %s --check-prefix 
CHECK --check-prefix CHECK-64
+// expected-no-diagnostics
+#ifndef HEADER
+#define HEADER
+
+template
+tx ftemplate(int n) {
+  tx b[10];
+
+  #pragma omp target
+  {
+tx d = n;
+#pragma omp parallel for
+for(int i=0; i<10; i++) {
+  b[i] += d;
+}
+b[3] += 1;
+  }
+
+  return b[3];
+}
+
+int bar(int n){
+  int a = 0;
+
+  a += ftemplate(n);
+
+  return a;
+}
+
+// CHECK-LABEL: define {{.*}}void 
{{@__omp_offloading_.+template.+l12}}_worker()
+// CHECK: call void @llvm.nvvm.barrier0()
+// CHECK: call i1 @__kmpc_kernel_parallel(
+// CHECK: call void @__omp_outlined___wrapper(
+
+// CHECK: define weak void @__omp_offloading_{{.*}}l12(
+// CHECK: call void @__omp_offloading_{{.*}}l12_worker()
+// CHECK: call void @__kmpc_kernel_init(
+// CHECK: call void @__kmpc_data_sharing_init_stack()
+// CHECK: call i8* @__kmpc_data_sharing_push_stack(i64 4, i16 0)
+// CHECK: call void @__kmpc_kernel_prepare_parallel(
+// CHECK: call void @__kmpc_begin_sharing_variables({{.*}}, i64 2)
+// CHECK: call void @llvm.nvvm.barrier0()
+// CHECK: call void @llvm.nvvm.barrier0()
+// CHECK: call void @__kmpc_end_sharing_variables()
+// CHECK: call void @__kmpc_data_sharing_pop_stack(
+// CHECK: call void @__kmpc_kernel_deinit(i16 1)
+
+// CHECK: define internal void @__omp_outlined__(
+// CHECK: alloca
+// CHECK: alloca
+// CHECK: alloca
+// CHECK: alloca
+// CHECK: [[OMP_IV:%.*]] = alloca i32
+// CHECK: store i32 0, {{.*}} [[OMP_LB:%.+]],
+// CHECK: store i32 9, {{.*}} [[OMP_UB:%.+]],
+// CHECK: store i32 1, {{.*}} [[OMP_ST:%.+]],
+// CHECK: call void @__kmpc_for_static_init_4({{.*}} i32 34, {{.*}} 
[[OMP_LB]], {{.*}} [[OMP_UB]], {{.*}} [[OMP_ST]], i32 1, i32 1)
+// CHECK: [[OMP_UB_1:%.+]] = load {{.*}} [[OMP_UB]]
+// CHECK: [[COMP_1:%.+]] = icmp sgt {{.*}} [[OMP_UB_1]]
+// CHECK: br i1 [[COMP_1]], label %[[COND_TRUE:.+]], label %[[COND_FALSE:.+]]
+
+// CHECK: [[COND_TRUE]]
+// CHECK: br label %[[COND_END:.+]]
+
+// CHECK: [[COND_FALSE]]
+// CHECK: [[OMP_UB_2:%.+]] = load {{.*}}* [[OMP_UB]]
+// CHECK: br label %[[COND_END]]
+
+// CHECK: [[COND_END]]
+// CHECK: [[COND_RES:%.+]] = phi i32 [ 9, %[[COND_TRUE]] ], [ [[OMP_UB_2]], 
%[[COND_FALSE]] ]
+// CHECK: store i32 [[COND_RES]], i32* [[OMP_UB]]
+// CHECK: [[OMP_LB_1:%.+]] = load i32, i32* [[OMP_LB]]
+// CHECK: store i32 [[OMP_LB_1]], i32* [[OMP_IV]]
+// CHECK: br label %[[OMP_INNER_FOR_COND:.+]]
+
+// CHECK: [[OMP_INNER_FOR_COND]]
+// CHECK: [[OMP_IV_2:%.+]] = load i32, i32* [[OMP_IV]]
+// CHECK: [[OMP_UB_4:%.+]] = load i32, i32* [[OMP_UB]]
+// CHECK: [[COMP_3:%.+]] = icmp sle i32 [[OMP_IV_2]], [[OMP_UB_4]]
+// CHECK: br i1 [[COMP_3]], label %[[OMP_INNER_FOR_BODY:.+]], label 
%[[OMP_INNER_FOR_END:.+]]
+
+// CHECK: [[OMP_INNER_FOR_BODY]]
+// CHECK: br label %[[OMP_BODY_CONTINUE:.+]]
+
+// CHECK: [[OMP_BODY_CONTINUE]]
+// CHECK: br label %[[OMP_INNER_FOR_INC:.+]]
+
+// CHECK: [[OMP_INNER_FOR_INC]]
+// CHECK: [[OMP_IV_3:%.+]] = load i32, i32* [[OMP_IV]]
+// CHECK: [[ADD_1:%.+]] = add nsw i32 [[OMP_IV_3]], 1
+// CHECK: store i32 [[ADD_1]], i32* [[OMP_IV]]
+// CHECK: br label %[[OMP_INNER_FOR_COND]]
+
+// CHECK: [[OMP_INNER_FOR_END]]
+// CHECK: call void @__kmpc_for_static_fini(
+// CHECK: ret void
+
+#endif


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


[PATCH] D53772: [NFC][OpenMP] Add new test for parallel for code generation.

2018-10-26 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC345417: [NFC][OpenMP] Add new test for parallel for code 
generation. (authored by gbercea, committed by ).

Repository:
  rC Clang

https://reviews.llvm.org/D53772

Files:
  test/OpenMP/nvptx_parallel_for_codegen.cpp

Index: test/OpenMP/nvptx_parallel_for_codegen.cpp
===
--- test/OpenMP/nvptx_parallel_for_codegen.cpp
+++ test/OpenMP/nvptx_parallel_for_codegen.cpp
@@ -0,0 +1,101 @@
+// Test target codegen - host bc file has to be created first.
+// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm-bc %s -o %t-ppc-host.bc
+// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple nvptx64-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o - | FileCheck %s --check-prefix CHECK --check-prefix CHECK-64
+// expected-no-diagnostics
+#ifndef HEADER
+#define HEADER
+
+template
+tx ftemplate(int n) {
+  tx b[10];
+
+  #pragma omp target
+  {
+tx d = n;
+#pragma omp parallel for
+for(int i=0; i<10; i++) {
+  b[i] += d;
+}
+b[3] += 1;
+  }
+
+  return b[3];
+}
+
+int bar(int n){
+  int a = 0;
+
+  a += ftemplate(n);
+
+  return a;
+}
+
+// CHECK-LABEL: define {{.*}}void {{@__omp_offloading_.+template.+l12}}_worker()
+// CHECK: call void @llvm.nvvm.barrier0()
+// CHECK: call i1 @__kmpc_kernel_parallel(
+// CHECK: call void @__omp_outlined___wrapper(
+
+// CHECK: define weak void @__omp_offloading_{{.*}}l12(
+// CHECK: call void @__omp_offloading_{{.*}}l12_worker()
+// CHECK: call void @__kmpc_kernel_init(
+// CHECK: call void @__kmpc_data_sharing_init_stack()
+// CHECK: call i8* @__kmpc_data_sharing_push_stack(i64 4, i16 0)
+// CHECK: call void @__kmpc_kernel_prepare_parallel(
+// CHECK: call void @__kmpc_begin_sharing_variables({{.*}}, i64 2)
+// CHECK: call void @llvm.nvvm.barrier0()
+// CHECK: call void @llvm.nvvm.barrier0()
+// CHECK: call void @__kmpc_end_sharing_variables()
+// CHECK: call void @__kmpc_data_sharing_pop_stack(
+// CHECK: call void @__kmpc_kernel_deinit(i16 1)
+
+// CHECK: define internal void @__omp_outlined__(
+// CHECK: alloca
+// CHECK: alloca
+// CHECK: alloca
+// CHECK: alloca
+// CHECK: [[OMP_IV:%.*]] = alloca i32
+// CHECK: store i32 0, {{.*}} [[OMP_LB:%.+]],
+// CHECK: store i32 9, {{.*}} [[OMP_UB:%.+]],
+// CHECK: store i32 1, {{.*}} [[OMP_ST:%.+]],
+// CHECK: call void @__kmpc_for_static_init_4({{.*}} i32 34, {{.*}} [[OMP_LB]], {{.*}} [[OMP_UB]], {{.*}} [[OMP_ST]], i32 1, i32 1)
+// CHECK: [[OMP_UB_1:%.+]] = load {{.*}} [[OMP_UB]]
+// CHECK: [[COMP_1:%.+]] = icmp sgt {{.*}} [[OMP_UB_1]]
+// CHECK: br i1 [[COMP_1]], label %[[COND_TRUE:.+]], label %[[COND_FALSE:.+]]
+
+// CHECK: [[COND_TRUE]]
+// CHECK: br label %[[COND_END:.+]]
+
+// CHECK: [[COND_FALSE]]
+// CHECK: [[OMP_UB_2:%.+]] = load {{.*}}* [[OMP_UB]]
+// CHECK: br label %[[COND_END]]
+
+// CHECK: [[COND_END]]
+// CHECK: [[COND_RES:%.+]] = phi i32 [ 9, %[[COND_TRUE]] ], [ [[OMP_UB_2]], %[[COND_FALSE]] ]
+// CHECK: store i32 [[COND_RES]], i32* [[OMP_UB]]
+// CHECK: [[OMP_LB_1:%.+]] = load i32, i32* [[OMP_LB]]
+// CHECK: store i32 [[OMP_LB_1]], i32* [[OMP_IV]]
+// CHECK: br label %[[OMP_INNER_FOR_COND:.+]]
+
+// CHECK: [[OMP_INNER_FOR_COND]]
+// CHECK: [[OMP_IV_2:%.+]] = load i32, i32* [[OMP_IV]]
+// CHECK: [[OMP_UB_4:%.+]] = load i32, i32* [[OMP_UB]]
+// CHECK: [[COMP_3:%.+]] = icmp sle i32 [[OMP_IV_2]], [[OMP_UB_4]]
+// CHECK: br i1 [[COMP_3]], label %[[OMP_INNER_FOR_BODY:.+]], label %[[OMP_INNER_FOR_END:.+]]
+
+// CHECK: [[OMP_INNER_FOR_BODY]]
+// CHECK: br label %[[OMP_BODY_CONTINUE:.+]]
+
+// CHECK: [[OMP_BODY_CONTINUE]]
+// CHECK: br label %[[OMP_INNER_FOR_INC:.+]]
+
+// CHECK: [[OMP_INNER_FOR_INC]]
+// CHECK: [[OMP_IV_3:%.+]] = load i32, i32* [[OMP_IV]]
+// CHECK: [[ADD_1:%.+]] = add nsw i32 [[OMP_IV_3]], 1
+// CHECK: store i32 [[ADD_1]], i32* [[OMP_IV]]
+// CHECK: br label %[[OMP_INNER_FOR_COND]]
+
+// CHECK: [[OMP_INNER_FOR_END]]
+// CHECK: call void @__kmpc_for_static_fini(
+// CHECK: ret void
+
+#endif
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D53025: [clang-tidy] implement new check for const return types.

2018-10-26 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang-tidy/readability/ConstValueReturnCheck.cpp:107
+diag(Def->getInnerLocStart(), "return type %0 is 'const'-qualified "
+  "hindering compiler optimizations")
+<< Def->getReturnType();

ymandel wrote:
> aaron.ballman wrote:
> > ymandel wrote:
> > > aaron.ballman wrote:
> > > > It seems strange to me that this is in the readability module but the 
> > > > diagnostic here is about compiler optimizations. Should this be in the 
> > > > performance module instead? Or should this diagnostic be reworded about 
> > > > the readability concerns?
> > > Good point. The readability angle is that the const clutters the code to 
> > > no benefit.  That is, even if it was performance neutral, I'd still want 
> > > to discourage this practice.  But, it does seem like the primary impact 
> > > is performance. 
> > > 
> > > I'm fine either way -- moving it to performance or emphasizing the 
> > > clutter of the unhelpful "const".  I'm inclined to moving it, but don't 
> > > have good sense of how strict these hierarchies are. What do you think?
> > I'm not sold that `const`-qualified return types always pessimize 
> > optimizations. However, I'm also not sold that it's *always* a bad idea to 
> > have a top-level cv-qualifier on a return type either (for instance, this 
> > is one way to prevent callers from modifying a temp returned by a 
> > function). How about leaving this in readability and changing the 
> > diagnostic into: "top-level 'const' qualifier on a return type may reduce 
> > code readability with limited benefit" or something equally weasely?
> I talked this over with other google folks and seems like the consensus is:
> 
> 1.  The readability benefits may be controversial.  Some folks might not view 
> `const` as clutter and there are some corner cases where the qualifier may 
> prevent something harmful.
> 2.  The performance implication is real, if not guaranteed to be a problem.
> 
> Based on this, seems best to move it to performance, but water down the 
> performance claims.  That keeps the focus to an issue we can assume nearly 
> everyone agrees on.
I'm not convinced the performance implications are real compared to how the 
check is currently implemented. I know there are performance concerns when you 
return a const value of class type because it pessimizes the ability to use 
move constructors, but that's a very specific performance concern that I don't 
believe is present in general. For instance, I don't know of any performance 
concerns regarding `const int f();` as a declaration. I'd be fine moving this 
to the performance module, but I think the check would need to be tightened to 
only focus on actual performance concerns.

FWIW, I do agree that the readability benefits may be controversial, but I kind 
of thought that was the point to the check and as such, it's a very reasonable 
check. Almost everything in readability is subjective to some degree and our 
metric has always been "if you agree with a style check, don't enable it".

It's up to you how you want to proceed, but I see two ways forward: 1) keep 
this as a readability check that broadly finds top-level const qualifiers and 
removes them, 2) move this to the performance module and rework the check to 
focus on only the scenarios that have concrete performance impact.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D53025



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


[PATCH] D53771: [clang-tidy] Avoid C arrays check

2018-10-26 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added a comment.

May be this check belongs to modernize?




Comment at: docs/clang-tidy/checks/misc-avoid-c-arrays.rst:6
+
+Find C-style array delarations and recommend to use ``std::array<>``.
+All types of C arrays are diagnosed.

Finds.



Comment at: docs/clang-tidy/checks/misc-avoid-c-arrays.rst:9
+
+Hoever, no fix-its are provided. Such transform would need to be able to
+observe *all* the uses of said declaration in order to decide whether it is

However



Comment at: docs/clang-tidy/checks/misc-avoid-c-arrays.rst:30
+
+  ...
+

Please remove ellipsis. and newline.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D53771



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


[clang-tools-extra] r345418 - [clang-doc] Switch to default to all-TUs executor

2018-10-26 Thread Julie Hockett via cfe-commits
Author: juliehockett
Date: Fri Oct 26 12:11:34 2018
New Revision: 345418

URL: http://llvm.org/viewvc/llvm-project?rev=345418&view=rev
Log:
[clang-doc] Switch to default to all-TUs executor

Since we generally want to document a whole project, not just one file.

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

Modified:
clang-tools-extra/trunk/clang-doc/tool/ClangDocMain.cpp
clang-tools-extra/trunk/test/clang-doc/single-file-public.cpp
clang-tools-extra/trunk/test/clang-doc/single-file.cpp

Modified: clang-tools-extra/trunk/clang-doc/tool/ClangDocMain.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-doc/tool/ClangDocMain.cpp?rev=345418&r1=345417&r2=345418&view=diff
==
--- clang-tools-extra/trunk/clang-doc/tool/ClangDocMain.cpp (original)
+++ clang-tools-extra/trunk/clang-doc/tool/ClangDocMain.cpp Fri Oct 26 12:11:34 
2018
@@ -31,7 +31,6 @@
 #include "clang/Frontend/FrontendActions.h"
 #include "clang/Tooling/CommonOptionsParser.h"
 #include "clang/Tooling/Execution.h"
-#include "clang/Tooling/StandaloneExecution.h"
 #include "clang/Tooling/Tooling.h"
 #include "llvm/ADT/APFloat.h"
 #include "llvm/Support/CommandLine.h"
@@ -169,6 +168,7 @@ int main(int argc, const char **argv) {
   llvm::sys::PrintStackTraceOnErrorSignal(argv[0]);
   std::error_code OK;
 
+  ExecutorName.setInitialValue("all-TUs");
   auto Exec = clang::tooling::createExecutorFromCommandLineArgs(
   argc, argv, ClangDocCategory);
 

Modified: clang-tools-extra/trunk/test/clang-doc/single-file-public.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-doc/single-file-public.cpp?rev=345418&r1=345417&r2=345418&view=diff
==
--- clang-tools-extra/trunk/test/clang-doc/single-file-public.cpp (original)
+++ clang-tools-extra/trunk/test/clang-doc/single-file-public.cpp Fri Oct 26 
12:11:34 2018
@@ -2,7 +2,7 @@
 // RUN: mkdir %t
 // RUN: echo "" > %t/compile_flags.txt
 // RUN: cp "%s" "%t/test.cpp"
-// RUN: clang-doc --doxygen --public -p %t %t/test.cpp -output=%t/docs
+// RUN: clang-doc --doxygen --public --executor=standalone -p %t %t/test.cpp 
-output=%t/docs
 // RUN: cat %t/docs/Record.yaml | FileCheck %s --check-prefix=CHECK
 // RUN: rm -rf %t
 

Modified: clang-tools-extra/trunk/test/clang-doc/single-file.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-doc/single-file.cpp?rev=345418&r1=345417&r2=345418&view=diff
==
--- clang-tools-extra/trunk/test/clang-doc/single-file.cpp (original)
+++ clang-tools-extra/trunk/test/clang-doc/single-file.cpp Fri Oct 26 12:11:34 
2018
@@ -2,7 +2,7 @@
 // RUN: mkdir %t
 // RUN: echo "" > %t/compile_flags.txt
 // RUN: cp "%s" "%t/test.cpp"
-// RUN: clang-doc --doxygen -p %t %t/test.cpp -output=%t/docs
+// RUN: clang-doc --doxygen --executor=standalone -p %t %t/test.cpp 
-output=%t/docs
 // RUN: cat %t/docs/GlobalNamespace.yaml | FileCheck %s --check-prefix=CHECK
 // RUN: rm -rf %t
 


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


[PATCH] D53170: [clang-doc] Switch to default to all-TUs executor

2018-10-26 Thread Julie Hockett via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rCTE345418: [clang-doc] Switch to default to all-TUs executor 
(authored by juliehockett, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D53170?vs=169414&id=171331#toc

Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D53170

Files:
  clang-doc/tool/ClangDocMain.cpp
  test/clang-doc/single-file-public.cpp
  test/clang-doc/single-file.cpp


Index: clang-doc/tool/ClangDocMain.cpp
===
--- clang-doc/tool/ClangDocMain.cpp
+++ clang-doc/tool/ClangDocMain.cpp
@@ -31,7 +31,6 @@
 #include "clang/Frontend/FrontendActions.h"
 #include "clang/Tooling/CommonOptionsParser.h"
 #include "clang/Tooling/Execution.h"
-#include "clang/Tooling/StandaloneExecution.h"
 #include "clang/Tooling/Tooling.h"
 #include "llvm/ADT/APFloat.h"
 #include "llvm/Support/CommandLine.h"
@@ -169,6 +168,7 @@
   llvm::sys::PrintStackTraceOnErrorSignal(argv[0]);
   std::error_code OK;
 
+  ExecutorName.setInitialValue("all-TUs");
   auto Exec = clang::tooling::createExecutorFromCommandLineArgs(
   argc, argv, ClangDocCategory);
 
Index: test/clang-doc/single-file.cpp
===
--- test/clang-doc/single-file.cpp
+++ test/clang-doc/single-file.cpp
@@ -2,7 +2,7 @@
 // RUN: mkdir %t
 // RUN: echo "" > %t/compile_flags.txt
 // RUN: cp "%s" "%t/test.cpp"
-// RUN: clang-doc --doxygen -p %t %t/test.cpp -output=%t/docs
+// RUN: clang-doc --doxygen --executor=standalone -p %t %t/test.cpp 
-output=%t/docs
 // RUN: cat %t/docs/GlobalNamespace.yaml | FileCheck %s --check-prefix=CHECK
 // RUN: rm -rf %t
 
Index: test/clang-doc/single-file-public.cpp
===
--- test/clang-doc/single-file-public.cpp
+++ test/clang-doc/single-file-public.cpp
@@ -2,7 +2,7 @@
 // RUN: mkdir %t
 // RUN: echo "" > %t/compile_flags.txt
 // RUN: cp "%s" "%t/test.cpp"
-// RUN: clang-doc --doxygen --public -p %t %t/test.cpp -output=%t/docs
+// RUN: clang-doc --doxygen --public --executor=standalone -p %t %t/test.cpp 
-output=%t/docs
 // RUN: cat %t/docs/Record.yaml | FileCheck %s --check-prefix=CHECK
 // RUN: rm -rf %t
 


Index: clang-doc/tool/ClangDocMain.cpp
===
--- clang-doc/tool/ClangDocMain.cpp
+++ clang-doc/tool/ClangDocMain.cpp
@@ -31,7 +31,6 @@
 #include "clang/Frontend/FrontendActions.h"
 #include "clang/Tooling/CommonOptionsParser.h"
 #include "clang/Tooling/Execution.h"
-#include "clang/Tooling/StandaloneExecution.h"
 #include "clang/Tooling/Tooling.h"
 #include "llvm/ADT/APFloat.h"
 #include "llvm/Support/CommandLine.h"
@@ -169,6 +168,7 @@
   llvm::sys::PrintStackTraceOnErrorSignal(argv[0]);
   std::error_code OK;
 
+  ExecutorName.setInitialValue("all-TUs");
   auto Exec = clang::tooling::createExecutorFromCommandLineArgs(
   argc, argv, ClangDocCategory);
 
Index: test/clang-doc/single-file.cpp
===
--- test/clang-doc/single-file.cpp
+++ test/clang-doc/single-file.cpp
@@ -2,7 +2,7 @@
 // RUN: mkdir %t
 // RUN: echo "" > %t/compile_flags.txt
 // RUN: cp "%s" "%t/test.cpp"
-// RUN: clang-doc --doxygen -p %t %t/test.cpp -output=%t/docs
+// RUN: clang-doc --doxygen --executor=standalone -p %t %t/test.cpp -output=%t/docs
 // RUN: cat %t/docs/GlobalNamespace.yaml | FileCheck %s --check-prefix=CHECK
 // RUN: rm -rf %t
 
Index: test/clang-doc/single-file-public.cpp
===
--- test/clang-doc/single-file-public.cpp
+++ test/clang-doc/single-file-public.cpp
@@ -2,7 +2,7 @@
 // RUN: mkdir %t
 // RUN: echo "" > %t/compile_flags.txt
 // RUN: cp "%s" "%t/test.cpp"
-// RUN: clang-doc --doxygen --public -p %t %t/test.cpp -output=%t/docs
+// RUN: clang-doc --doxygen --public --executor=standalone -p %t %t/test.cpp -output=%t/docs
 // RUN: cat %t/docs/Record.yaml | FileCheck %s --check-prefix=CHECK
 // RUN: rm -rf %t
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D53771: [clang-tidy] Avoid C arrays check

2018-10-26 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added inline comments.



Comment at: test/clang-tidy/misc-avoid-c-arrays.cpp:14
+
+template 
+class array {

JonasToth wrote:
> Please add a case with templates, where `T` itself is the array type, maybe 
> there are other fancy template tricks that could create an array implictly?
Oh i see, `array` is not diagnosed, that is where it gets 
interesting :S
So i need to match `type(arrayType())`, and then find the location to complain 
about
(the type does not seem to have it).


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D53771



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


[PATCH] D53605: [AST] Refactor PredefinedExpr

2018-10-26 Thread Bruno Ricci via Phabricator via cfe-commits
riccibruno updated this revision to Diff 171326.
riccibruno marked 4 inline comments as done.
riccibruno retitled this revision from "[AST] Pack PredefinedExpr" to "[AST] 
Refactor PredefinedExpr".
riccibruno edited the summary of this revision.
riccibruno added a comment.

Address rjmcall's comments. In particular use "Kind" instead of "Type" and 
propagate
the change to the users. Change the title to "[AST] Refactor PredefinedExpr" 
since this
patch is doing various changes to `PredefinedExpr`.


Repository:
  rC Clang

https://reviews.llvm.org/D53605

Files:
  include/clang/AST/Expr.h
  include/clang/AST/Stmt.h
  include/clang/AST/StmtDataCollectors.td
  include/clang/Sema/Sema.h
  lib/AST/ASTDumper.cpp
  lib/AST/ASTImporter.cpp
  lib/AST/Expr.cpp
  lib/AST/StmtPrinter.cpp
  lib/AST/StmtProfile.cpp
  lib/CodeGen/CGExpr.cpp
  lib/CodeGen/CGExprConstant.cpp
  lib/Sema/SemaExpr.cpp
  lib/Sema/SemaTemplateInstantiate.cpp
  lib/Sema/TreeTransform.h
  lib/Serialization/ASTReaderStmt.cpp
  lib/Serialization/ASTWriterStmt.cpp

Index: lib/Serialization/ASTWriterStmt.cpp
===
--- lib/Serialization/ASTWriterStmt.cpp
+++ lib/Serialization/ASTWriterStmt.cpp
@@ -388,9 +388,13 @@
 
 void ASTStmtWriter::VisitPredefinedExpr(PredefinedExpr *E) {
   VisitExpr(E);
+
+  bool HasFunctionName = E->getFunctionName() != nullptr;
+  Record.push_back(HasFunctionName);
+  Record.push_back(E->getIdentKind()); // FIXME: stable encoding
   Record.AddSourceLocation(E->getLocation());
-  Record.push_back(E->getIdentType()); // FIXME: stable encoding
-  Record.AddStmt(E->getFunctionName());
+  if (HasFunctionName)
+Record.AddStmt(E->getFunctionName());
   Code = serialization::EXPR_PREDEFINED;
 }
 
Index: lib/Serialization/ASTReaderStmt.cpp
===
--- lib/Serialization/ASTReaderStmt.cpp
+++ lib/Serialization/ASTReaderStmt.cpp
@@ -496,9 +496,12 @@
 
 void ASTStmtReader::VisitPredefinedExpr(PredefinedExpr *E) {
   VisitExpr(E);
+  bool HasFunctionName = Record.readInt();
+  E->PredefinedExprBits.HasFunctionName = HasFunctionName;
+  E->PredefinedExprBits.Kind = Record.readInt();
   E->setLocation(ReadSourceLocation());
-  E->Type = (PredefinedExpr::IdentType)Record.readInt();
-  E->FnName = cast_or_null(Record.readSubExpr());
+  if (HasFunctionName)
+E->setFunctionName(cast(Record.readSubExpr()));
 }
 
 void ASTStmtReader::VisitDeclRefExpr(DeclRefExpr *E) {
@@ -2334,12 +2337,14 @@
   break;
 
 case STMT_CAPTURED:
-  S = CapturedStmt::CreateDeserialized(Context,
-   Record[ASTStmtReader::NumStmtFields]);
+  S = CapturedStmt::CreateDeserialized(
+  Context, Record[ASTStmtReader::NumStmtFields]);
   break;
 
 case EXPR_PREDEFINED:
-  S = new (Context) PredefinedExpr(Empty);
+  S = PredefinedExpr::CreateEmpty(
+  Context,
+  /*HasFunctionName*/ Record[ASTStmtReader::NumExprFields]);
   break;
 
 case EXPR_DECL_REF:
Index: lib/Sema/TreeTransform.h
===
--- lib/Sema/TreeTransform.h
+++ lib/Sema/TreeTransform.h
@@ -2096,8 +2096,8 @@
   /// By default, performs semantic analysis to build the new expression.
   /// Subclasses may override this routine to provide different behavior.
   ExprResult RebuildPredefinedExpr(SourceLocation Loc,
-   PredefinedExpr::IdentType IT) {
-return getSema().BuildPredefinedExpr(Loc, IT);
+   PredefinedExpr::IdentKind IK) {
+return getSema().BuildPredefinedExpr(Loc, IK);
   }
 
   /// Build a new expression that references a declaration.
@@ -8921,7 +8921,7 @@
 return E;
 
   return getDerived().RebuildPredefinedExpr(E->getLocation(),
-E->getIdentType());
+E->getIdentKind());
 }
 
 template
Index: lib/Sema/SemaTemplateInstantiate.cpp
===
--- lib/Sema/SemaTemplateInstantiate.cpp
+++ lib/Sema/SemaTemplateInstantiate.cpp
@@ -1167,7 +1167,7 @@
   if (!E->isTypeDependent())
 return E;
 
-  return getSema().BuildPredefinedExpr(E->getLocation(), E->getIdentType());
+  return getSema().BuildPredefinedExpr(E->getLocation(), E->getIdentKind());
 }
 
 ExprResult
Index: lib/Sema/SemaExpr.cpp
===
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -3036,7 +3036,7 @@
 }
 
 ExprResult Sema::BuildPredefinedExpr(SourceLocation Loc,
- PredefinedExpr::IdentType IT) {
+ PredefinedExpr::IdentKind IK) {
   // Pick the current block, lambda, captured statement or function.
   Decl *currentDecl = nullptr;
   if (const BlockScopeInfo *BSI = getCurBlock())
@@ -3060,11 +3060,11 @@
   els

[PATCH] D53607: [AST] Only store the needed data in IfStmt.

2018-10-26 Thread Bruno Ricci via Phabricator via cfe-commits
riccibruno updated this revision to Diff 171332.
riccibruno added a reviewer: rsmith.
riccibruno added a comment.

Add a flag to the output of -ast-dump indicating
which sub-statement `IfStmt` is storing. This removes
the ambiguity in the output of -ast-dump and addresses
rsmith's comment in https://reviews.llvm.org/D53717.


Repository:
  rC Clang

https://reviews.llvm.org/D53607

Files:
  include/clang/AST/Stmt.h
  lib/AST/ASTDumper.cpp
  lib/AST/ASTImporter.cpp
  lib/AST/Stmt.cpp
  lib/Analysis/BodyFarm.cpp
  lib/Sema/SemaStmt.cpp
  lib/Serialization/ASTReaderStmt.cpp
  lib/Serialization/ASTWriterStmt.cpp
  test/Import/if-stmt/test.cpp
  test/Misc/ast-dump-invalid.cpp

Index: test/Misc/ast-dump-invalid.cpp
===
--- test/Misc/ast-dump-invalid.cpp
+++ test/Misc/ast-dump-invalid.cpp
@@ -33,8 +33,6 @@
 // CHECK-NEXT:   |-ParmVarDecl
 // CHECK-NEXT:   `-CompoundStmt
 // CHECK-NEXT: `-IfStmt {{.*}} 
-// CHECK-NEXT:   |-<<>>
-// CHECK-NEXT:   |-<<>>
 // CHECK-NEXT:   |-OpaqueValueExpr {{.*}} <> 'bool'
 // CHECK-NEXT:   |-ReturnStmt {{.*}} 
 // CHECK-NEXT:   | `-IntegerLiteral {{.*}}  'int' 4
@@ -50,15 +48,15 @@
 { return 45; }
 }
 // CHECK: NamespaceDecl {{.*}} <{{.*}}> {{.*}} TestInvalidFunctionDecl
-// CHECK-NEXT: |-CXXRecordDecl {{.*}}  line:46:8 struct Str definition
+// CHECK-NEXT: |-CXXRecordDecl {{.*}}  line:44:8 struct Str definition
 // CHECK:  | |-CXXRecordDecl {{.*}}  col:8 implicit struct Str
-// CHECK-NEXT: | `-CXXMethodDecl {{.*}}  col:11 invalid foo1 'double (double, int)'
+// CHECK-NEXT: | `-CXXMethodDecl {{.*}}  col:11 invalid foo1 'double (double, int)'
 // CHECK-NEXT: |   |-ParmVarDecl {{.*}}  col:22 'double'
 // CHECK-NEXT: |   `-ParmVarDecl {{.*}} > col:36 invalid 'int'
-// CHECK-NEXT: `-CXXMethodDecl {{.*}} parent {{.*}}  line:49:13 invalid foo1 'double (double, int)'
+// CHECK-NEXT: `-CXXMethodDecl {{.*}} parent {{.*}}  line:47:13 invalid foo1 'double (double, int)'
 // CHECK-NEXT:   |-ParmVarDecl {{.*}}  col:24 'double'
 // CHECK-NEXT:   |-ParmVarDecl {{.*}} > col:38 invalid 'int'
-// CHECK-NEXT:   `-CompoundStmt {{.*}} 
+// CHECK-NEXT:   `-CompoundStmt {{.*}} 
 // CHECK-NEXT: `-ReturnStmt {{.*}} 
 // CHECK-NEXT:   `-ImplicitCastExpr {{.*}}  'double' 
 // CHECK-NEXT: `-IntegerLiteral {{.*}}  'int' 45
Index: test/Import/if-stmt/test.cpp
===
--- test/Import/if-stmt/test.cpp
+++ test/Import/if-stmt/test.cpp
@@ -1,41 +1,30 @@
 // RUN: clang-import-test -dump-ast -import %S/Inputs/F.cpp -expression %s | FileCheck %s
 
 // CHECK: IfStmt
-// CHECK-NEXT: <>
-// CHECK-NEXT: <>
 // CHECK-NEXT: CXXBoolLiteralExpr
 // CHECK-NEXT: ReturnStmt
-// CHECK-NEXT: <>
 
 // CHECK: IfStmt
-// CHECK-NEXT: <>
 // CHECK-NEXT: DeclStmt
 // CHECK-NEXT: VarDecl
 // CHECK-NEXT: IntegerLiteral
 // CHECK-NEXT: ImplicitCastExpr
 // CHECK-NEXT: ImplicitCastExpr
 // CHECK-NEXT: DeclRefExpr
 // CHECK-NEXT: ReturnStmt
-// CHECK-NEXT: <>
 
 // CHECK: IfStmt
 // CHECK-NEXT: DeclStmt
 // CHECK-NEXT: VarDecl
-// CHECK-NEXT: <>
 // CHECK-NEXT: CXXBoolLiteralExpr
 // CHECK-NEXT: ReturnStmt
-// CHECK-NEXT: <>
 
 // CHECK: IfStmt
-// CHECK-NEXT: <>
-// CHECK-NEXT: <>
 // CHECK-NEXT: CXXBoolLiteralExpr
 // CHECK-NEXT: ReturnStmt
 // CHECK-NEXT: ReturnStmt
 
 // CHECK: IfStmt
-// CHECK-NEXT: <>
-// CHECK-NEXT: <>
 // CHECK-NEXT: CXXBoolLiteralExpr
 // CHECK-NEXT: CompoundStmt
 // CHECK-NEXT: ReturnStmt
Index: lib/Serialization/ASTWriterStmt.cpp
===
--- lib/Serialization/ASTWriterStmt.cpp
+++ lib/Serialization/ASTWriterStmt.cpp
@@ -128,14 +128,29 @@
 
 void ASTStmtWriter::VisitIfStmt(IfStmt *S) {
   VisitStmt(S);
+
+  bool HasElse = S->getElse() != nullptr;
+  bool HasVar = S->getConditionVariableDeclStmt() != nullptr;
+  bool HasInit = S->getInit() != nullptr;
+
   Record.push_back(S->isConstexpr());
-  Record.AddStmt(S->getInit());
-  Record.AddDeclRef(S->getConditionVariable());
+  Record.push_back(HasElse);
+  Record.push_back(HasVar);
+  Record.push_back(HasInit);
+
   Record.AddStmt(S->getCond());
   Record.AddStmt(S->getThen());
-  Record.AddStmt(S->getElse());
+  if (HasElse)
+Record.AddStmt(S->getElse());
+  if (HasVar)
+Record.AddDeclRef(S->getConditionVariable());
+  if (HasInit)
+Record.AddStmt(S->getInit());
+
   Record.AddSourceLocation(S->getIfLoc());
-  Record.AddSourceLocation(S->getElseLoc());
+  if (HasElse)
+Record.AddSourceLocation(S->getElseLoc());
+
   Code = serialization::STMT_IF;
 }
 
Index: lib/Serialization/ASTReaderStmt.cpp
===
--- lib/Serialization/ASTReaderStmt.cpp
+++ lib/Serialization/ASTReaderStmt.cpp
@@ -215,14 +215,24 @@
 
 void ASTStmtReader::VisitIfStmt(IfStmt *S) {
   VisitStmt(S);
+
   S->setConstexpr(Record.readInt());
-  S->setInit(Record.readSubStmt());
-  S->setConditionVariable(R

r345419 - PR26547: alignof should return ABI alignment, not preferred alignment

2018-10-26 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Fri Oct 26 12:26:45 2018
New Revision: 345419

URL: http://llvm.org/viewvc/llvm-project?rev=345419&view=rev
Log:
PR26547: alignof should return ABI alignment, not preferred alignment

Summary:
- Add `UETT_PreferredAlignOf` to account for the difference between `__alignof` 
and `alignof`
- `AlignOfType` now returns ABI alignment instead of preferred alignment iff 
clang-abi-compat > 7, and one uses _Alignof or alignof

Patch by Nicole Mazzuca!

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

Added:
cfe/trunk/test/Sema/align-x86-abi7.c
cfe/trunk/test/SemaCXX/align-x86-abi7.cpp
cfe/trunk/test/SemaCXX/align-x86.cpp
Modified:
cfe/trunk/docs/ReleaseNotes.rst
cfe/trunk/include/clang/AST/Stmt.h
cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/include/clang/Basic/LangOptions.h
cfe/trunk/include/clang/Basic/TypeTraits.h
cfe/trunk/lib/AST/ASTDumper.cpp
cfe/trunk/lib/AST/Expr.cpp
cfe/trunk/lib/AST/ExprConstant.cpp
cfe/trunk/lib/AST/ItaniumMangle.cpp
cfe/trunk/lib/AST/StmtPrinter.cpp
cfe/trunk/lib/Frontend/CompilerInvocation.cpp
cfe/trunk/lib/Parse/ParseExpr.cpp
cfe/trunk/lib/Sema/SemaChecking.cpp
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/test/Headers/thumbv7-apple-ios-types.cpp
cfe/trunk/test/Sema/align-x86.c
cfe/trunk/test/SemaCXX/alignof.cpp

Modified: cfe/trunk/docs/ReleaseNotes.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ReleaseNotes.rst?rev=345419&r1=345418&r2=345419&view=diff
==
--- cfe/trunk/docs/ReleaseNotes.rst (original)
+++ cfe/trunk/docs/ReleaseNotes.rst Fri Oct 26 12:26:45 2018
@@ -77,6 +77,11 @@ future versions of Clang.
 Modified Compiler Flags
 ---
 
+- As of clang 8, `alignof` and `_Alignof` return the ABI alignment of a type,
+  as opposed to the preferred alignment. `__alignof` still returns the
+  preferred alignment. `-fclang-abi-compat=7` (and previous) will make
+  `alignof` and `_Alignof` return preferred alignment again.
+
 
 New Pragmas in Clang
 
@@ -132,6 +137,21 @@ OpenCL C Language Changes in Clang
 
 ...
 
+ABI Changes in Clang
+
+
+- `_Alignof` and `alignof` now return the ABI alignment of a type, as opposed
+  to the preferred alignment.
+  - This is more in keeping with the language of the standards, as well as
+being compatible with gcc
+  - `__alignof` and `__alignof__` still return the preferred alignment of
+a type
+  - This shouldn't break any ABI except for things that explicitly ask for
+`alignas(alignof(T))`.
+  - If you have interfaces that break with this change, you may wish to switch
+to `alignas(__alignof(T))`, instead of using the `-fclang-abi-compat`
+switch.
+
 OpenMP Support in Clang
 --
 

Modified: cfe/trunk/include/clang/AST/Stmt.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Stmt.h?rev=345419&r1=345418&r2=345419&view=diff
==
--- cfe/trunk/include/clang/AST/Stmt.h (original)
+++ cfe/trunk/include/clang/AST/Stmt.h Fri Oct 26 12:26:45 2018
@@ -179,7 +179,7 @@ protected:
 
 unsigned : NumExprBits;
 
-unsigned Kind : 2;
+unsigned Kind : 3;
 unsigned IsType : 1; // true if operand is a type, false if an expression.
   };
 

Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h?rev=345419&r1=345418&r2=345419&view=diff
==
--- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h (original)
+++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h Fri Oct 26 12:26:45 2018
@@ -2425,8 +2425,9 @@ AST_MATCHER_P(UnaryExprOrTypeTraitExpr,
 /// alignof.
 inline internal::Matcher alignOfExpr(
 const internal::Matcher &InnerMatcher) {
-  return stmt(unaryExprOrTypeTraitExpr(allOf(
-  ofKind(UETT_AlignOf), InnerMatcher)));
+  return stmt(unaryExprOrTypeTraitExpr(
+  allOf(anyOf(ofKind(UETT_AlignOf), ofKind(UETT_PreferredAlignOf)),
+InnerMatcher)));
 }
 
 /// Same as unaryExprOrTypeTraitExpr, but only matching

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=345419&r1=345418&r2=345419&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri Oct 26 12:26:45 
2018
@@ -5474,20 +5474,24 @@ def err_atomic_specifier_bad_type : Erro
   "%1 %select{||which is not trivially copyable}0">;
 
 // Expressions.
+def select_unary_expr_or_type_trait_

[PATCH] D53207: Fix bug 26547 - alignof should return ABI alignment, not preferred alignment

2018-10-26 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL345419: PR26547: alignof should return ABI alignment, not 
preferred alignment (authored by rsmith, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D53207?vs=171247&id=171333#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D53207

Files:
  cfe/trunk/docs/ReleaseNotes.rst
  cfe/trunk/include/clang/AST/Stmt.h
  cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
  cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
  cfe/trunk/include/clang/Basic/LangOptions.h
  cfe/trunk/include/clang/Basic/TypeTraits.h
  cfe/trunk/lib/AST/ASTDumper.cpp
  cfe/trunk/lib/AST/Expr.cpp
  cfe/trunk/lib/AST/ExprConstant.cpp
  cfe/trunk/lib/AST/ItaniumMangle.cpp
  cfe/trunk/lib/AST/StmtPrinter.cpp
  cfe/trunk/lib/Frontend/CompilerInvocation.cpp
  cfe/trunk/lib/Parse/ParseExpr.cpp
  cfe/trunk/lib/Sema/SemaChecking.cpp
  cfe/trunk/lib/Sema/SemaExpr.cpp
  cfe/trunk/test/Headers/thumbv7-apple-ios-types.cpp
  cfe/trunk/test/Sema/align-x86-abi7.c
  cfe/trunk/test/Sema/align-x86.c
  cfe/trunk/test/SemaCXX/align-x86-abi7.cpp
  cfe/trunk/test/SemaCXX/align-x86.cpp
  cfe/trunk/test/SemaCXX/alignof.cpp

Index: cfe/trunk/lib/AST/ASTDumper.cpp
===
--- cfe/trunk/lib/AST/ASTDumper.cpp
+++ cfe/trunk/lib/AST/ASTDumper.cpp
@@ -2281,6 +2281,9 @@
   case UETT_OpenMPRequiredSimdAlign:
 OS << " __builtin_omp_required_simd_align";
 break;
+  case UETT_PreferredAlignOf:
+OS << " __alignof";
+break;
   }
   if (Node->isArgumentType())
 dumpType(Node->getArgumentType());
Index: cfe/trunk/lib/AST/ItaniumMangle.cpp
===
--- cfe/trunk/lib/AST/ItaniumMangle.cpp
+++ cfe/trunk/lib/AST/ItaniumMangle.cpp
@@ -3864,6 +3864,7 @@
 case UETT_SizeOf:
   Out << 's';
   break;
+case UETT_PreferredAlignOf:
 case UETT_AlignOf:
   Out << 'a';
   break;
Index: cfe/trunk/lib/AST/StmtPrinter.cpp
===
--- cfe/trunk/lib/AST/StmtPrinter.cpp
+++ cfe/trunk/lib/AST/StmtPrinter.cpp
@@ -1235,6 +1235,9 @@
 else
   OS << "__alignof";
 break;
+  case UETT_PreferredAlignOf:
+OS << "__alignof";
+break;
   case UETT_VecStep:
 OS << "vec_step";
 break;
Index: cfe/trunk/lib/AST/Expr.cpp
===
--- cfe/trunk/lib/AST/Expr.cpp
+++ cfe/trunk/lib/AST/Expr.cpp
@@ -1446,7 +1446,7 @@
 
   // Check to see if we are in the situation where alignof(decl) should be
   // dependent because decl's alignment is dependent.
-  if (ExprKind == UETT_AlignOf) {
+  if (ExprKind == UETT_AlignOf || ExprKind == UETT_PreferredAlignOf) {
 if (!isValueDependent() || !isInstantiationDependent()) {
   E = E->IgnoreParens();
 
Index: cfe/trunk/lib/AST/ExprConstant.cpp
===
--- cfe/trunk/lib/AST/ExprConstant.cpp
+++ cfe/trunk/lib/AST/ExprConstant.cpp
@@ -5946,21 +5946,35 @@
   return ExprEvaluatorBaseTy::VisitCastExpr(E);
 }
 
-static CharUnits GetAlignOfType(EvalInfo &Info, QualType T) {
+static CharUnits GetAlignOfType(EvalInfo &Info, QualType T,
+UnaryExprOrTypeTrait ExprKind) {
   // C++ [expr.alignof]p3:
   // When alignof is applied to a reference type, the result is the
   // alignment of the referenced type.
   if (const ReferenceType *Ref = T->getAs())
 T = Ref->getPointeeType();
 
-  // __alignof is defined to return the preferred alignment.
   if (T.getQualifiers().hasUnaligned())
 return CharUnits::One();
-  return Info.Ctx.toCharUnitsFromBits(
-Info.Ctx.getPreferredTypeAlign(T.getTypePtr()));
+
+  const bool AlignOfReturnsPreferred =
+  Info.Ctx.getLangOpts().getClangABICompat() <= LangOptions::ClangABI::Ver7;
+
+  // __alignof is defined to return the preferred alignment.
+  // Before 8, clang returned the preferred alignment for alignof and _Alignof
+  // as well.
+  if (ExprKind == UETT_PreferredAlignOf || AlignOfReturnsPreferred)
+return Info.Ctx.toCharUnitsFromBits(
+  Info.Ctx.getPreferredTypeAlign(T.getTypePtr()));
+  // alignof and _Alignof are defined to return the ABI alignment.
+  else if (ExprKind == UETT_AlignOf)
+return Info.Ctx.getTypeAlignInChars(T.getTypePtr());
+  else
+llvm_unreachable("GetAlignOfType on a non-alignment ExprKind");
 }
 
-static CharUnits GetAlignOfExpr(EvalInfo &Info, const Expr *E) {
+static CharUnits GetAlignOfExpr(EvalInfo &Info, const Expr *E,
+UnaryExprOrTypeTrait ExprKind) {
   E = E->IgnoreParens();
 
   // The kinds of expressions that we have special-case logic here for
@@ -5977,7 +5991,7 @@
 return Info.Ctx.getDeclAlign(ME->getMemberDecl(),
  /*RefAsPointee*/true);
 
-  return GetAli

[PATCH] D53770: Support g++ headers in include/g++

2018-10-26 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

This needs a test.




Comment at: lib/Driver/ToolChains/Linux.cpp:927-928
   LibDir.str() + "/../include/c++",
+  // Some gcc installations put headers under "g++" without a
+  // version suffix.
+  LibDir.str() + "/../include/g++",

It'd be useful to say who this "some" is, so we can check whether this is still 
a valid concern in the future.


Repository:
  rC Clang

https://reviews.llvm.org/D53770



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


r345421 - Fix typo.

2018-10-26 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Fri Oct 26 12:35:39 2018
New Revision: 345421

URL: http://llvm.org/viewvc/llvm-project?rev=345421&view=rev
Log:
Fix typo.

Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=345421&r1=345420&r2=345421&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri Oct 26 12:35:39 
2018
@@ -5476,7 +5476,7 @@ def err_atomic_specifier_bad_type : Erro
 // Expressions.
 def select_unary_expr_or_type_trait_kind : TextSubstitution<
   "%select{sizeof|alignof|vec_step|__builtin_omp_required_simd_align|"
-  "__alignof}0">
+  "__alignof}0">;
 def ext_sizeof_alignof_function_type : Extension<
   "invalid application of '%sub{select_unary_expr_or_type_trait_kind}0' "
   "to a function type">, InGroup;


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


r345423 - Fix test expectation to match reality.

2018-10-26 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Fri Oct 26 12:42:43 2018
New Revision: 345423

URL: http://llvm.org/viewvc/llvm-project?rev=345423&view=rev
Log:
Fix test expectation to match reality.

Modified:
cfe/trunk/test/SemaCXX/alignof.cpp

Modified: cfe/trunk/test/SemaCXX/alignof.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/alignof.cpp?rev=345423&r1=345422&r2=345423&view=diff
==
--- cfe/trunk/test/SemaCXX/alignof.cpp (original)
+++ cfe/trunk/test/SemaCXX/alignof.cpp Fri Oct 26 12:42:43 2018
@@ -4,9 +4,9 @@
 
 struct S0 {
   int x;
-  static const int test0 = __alignof__(x); // expected-error {{invalid 
application of '__alignof' to a field of a class still being defined}}
-  static const int test1 = __alignof__(S0::x); // expected-error {{invalid 
application of '__alignof' to a field of a class still being defined}}
-  auto test2() -> char(&)[__alignof__(x)]; // expected-error {{invalid 
application of '__alignof' to a field of a class still being defined}}
+  static const int test0 = __alignof__(x); // expected-error {{invalid 
application of 'alignof' to a field of a class still being defined}}
+  static const int test1 = __alignof__(S0::x); // expected-error {{invalid 
application of 'alignof' to a field of a class still being defined}}
+  auto test2() -> char(&)[__alignof__(x)]; // expected-error {{invalid 
application of 'alignof' to a field of a class still being defined}}
 };
 
 struct S1; // expected-note 6 {{forward declaration}}


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


[PATCH] D53609: [AST] Don't store data for GNU range case statement if not needed.

2018-10-26 Thread Bruno Ricci via Phabricator via cfe-commits
riccibruno updated this revision to Diff 171336.
riccibruno added a reviewer: rsmith.
riccibruno added a comment.

Add a flag in the output of -ast-dump to indicate that
a `CaseStmt` is a GNU range case statement, following
rsmith's comment in https://reviews.llvm.org/D53717


Repository:
  rC Clang

https://reviews.llvm.org/D53609

Files:
  include/clang/AST/Stmt.h
  lib/AST/ASTDumper.cpp
  lib/AST/ASTImporter.cpp
  lib/AST/Stmt.cpp
  lib/Sema/SemaStmt.cpp
  lib/Serialization/ASTReaderStmt.cpp
  lib/Serialization/ASTWriterStmt.cpp
  test/Import/switch-stmt/test.cpp
  test/Misc/ast-dump-color.cpp

Index: test/Misc/ast-dump-color.cpp
===
--- test/Misc/ast-dump-color.cpp
+++ test/Misc/ast-dump-color.cpp
@@ -51,13 +51,11 @@
 //CHECK: {{^}}[[Blue]]| |   `-[[RESET]][[MAGENTA]]CompoundStmt[[RESET]][[Yellow]] 0x{{[0-9a-fA-F]*}}[[RESET]] <[[Yellow]]col:14[[RESET]], [[Yellow]]line:15:3[[RESET]]>{{$}}
 //CHECK: {{^}}[[Blue]]| | |-[[RESET]][[MAGENTA]]CaseStmt[[RESET]][[Yellow]] 0x{{[0-9a-fA-F]*}}[[RESET]] <[[Yellow]]line:11:3[[RESET]], [[Yellow]]line:12:27[[RESET]]>{{$}}
 //CHECK: {{^}}[[Blue]]| | | |-[[RESET]][[MAGENTA]]IntegerLiteral[[RESET]][[Yellow]] 0x{{[0-9a-fA-F]*}}[[RESET]] <[[Yellow]]line:11:8[[RESET]]> [[Green]]'int'[[RESET]][[Cyan]][[RESET]][[Cyan]][[RESET]][[CYAN]] 1[[RESET]]{{$}}
-//CHECK: {{^}}[[Blue]]| | | |-[[RESET]][[Blue]]<<>>[[RESET]]{{$}}
 //CHECK: {{^}}[[Blue]]| | | `-[[RESET]][[MAGENTA]]AttributedStmt[[RESET]][[Yellow]] 0x{{[0-9a-fA-F]*}}[[RESET]] <[[Yellow]]line:12:5[[RESET]], [[Yellow]]col:27[[RESET]]>{{$}}
 //CHECK: {{^}}[[Blue]]| | |   |-[[RESET]][[BLUE]]FallThroughAttr[[RESET]][[Yellow]] 0x{{[0-9a-fA-F]*}}[[RESET]] <[[Yellow]]col:7[[RESET]], [[Yellow]]col:14[[RESET]]>{{$}}
 //CHECK: {{^}}[[Blue]]| | |   `-[[RESET]][[MAGENTA]]NullStmt[[RESET]][[Yellow]] 0x{{[0-9a-fA-F]*}}[[RESET]] <[[Yellow]]col:27[[RESET]]>{{$}}
 //CHECK: {{^}}[[Blue]]| | `-[[RESET]][[MAGENTA]]CaseStmt[[RESET]][[Yellow]] 0x{{[0-9a-fA-F]*}}[[RESET]] <[[Yellow]]line:13:3[[RESET]], [[Yellow]]line:14:5[[RESET]]>{{$}}
 //CHECK: {{^}}[[Blue]]| |   |-[[RESET]][[MAGENTA]]IntegerLiteral[[RESET]][[Yellow]] 0x{{[0-9a-fA-F]*}}[[RESET]] <[[Yellow]]line:13:8[[RESET]]> [[Green]]'int'[[RESET]][[Cyan]][[RESET]][[Cyan]][[RESET]][[CYAN]] 2[[RESET]]{{$}}
-//CHECK: {{^}}[[Blue]]| |   |-[[RESET]][[Blue]]<<>>[[RESET]]{{$}}
 //CHECK: {{^}}[[Blue]]| |   `-[[RESET]][[MAGENTA]]NullStmt[[RESET]][[Yellow]] 0x{{[0-9a-fA-F]*}}[[RESET]] <[[Yellow]]line:14:5[[RESET]]>{{$}}
 //CHECK: {{^}}[[Blue]]| `-[[RESET]][[Blue]]FullComment[[RESET]][[Yellow]] 0x{{[0-9a-fA-F]*}}[[RESET]] <[[Yellow]]line:8:4[[RESET]], [[Yellow]]col:11[[RESET]]>{{$}}
 //CHECK: {{^}}[[Blue]]|   `-[[RESET]][[Blue]]ParagraphComment[[RESET]][[Yellow]] 0x{{[0-9a-fA-F]*}}[[RESET]] <[[Yellow]]col:4[[RESET]], [[Yellow]]col:11[[RESET]]>{{$}}
Index: test/Import/switch-stmt/test.cpp
===
--- test/Import/switch-stmt/test.cpp
+++ test/Import/switch-stmt/test.cpp
@@ -7,10 +7,8 @@
 // CHECK-NEXT: CompoundStmt
 // CHECK-NEXT: CaseStmt
 // CHECK-NEXT: IntegerLiteral
-// CHECK-NEXT: <>
 // CHECK-NEXT: CaseStmt
 // CHECK-NEXT: IntegerLiteral
-// CHECK-NEXT: <>
 // CHECK-NEXT: BreakStmt
 
 // CHECK: SwitchStmt
@@ -22,11 +20,9 @@
 // CHECK-NEXT: CompoundStmt
 // CHECK-NEXT: CaseStmt
 // CHECK-NEXT: IntegerLiteral
-// CHECK-NEXT: <>
 // CHECK-NEXT: BreakStmt
 // CHECK-NEXT: CaseStmt
 // CHECK-NEXT: IntegerLiteral
-// CHECK-NEXT: <>
 // CHECK-NEXT: BreakStmt
 
 // CHECK: SwitchStmt
Index: lib/Serialization/ASTWriterStmt.cpp
===
--- lib/Serialization/ASTWriterStmt.cpp
+++ lib/Serialization/ASTWriterStmt.cpp
@@ -96,10 +96,13 @@
 
 void ASTStmtWriter::VisitCaseStmt(CaseStmt *S) {
   VisitSwitchCase(S);
+  Record.push_back(S->caseStmtIsGNURange());
   Record.AddStmt(S->getLHS());
-  Record.AddStmt(S->getRHS());
   Record.AddStmt(S->getSubStmt());
-  Record.AddSourceLocation(S->getEllipsisLoc());
+  if (S->caseStmtIsGNURange()) {
+Record.AddStmt(S->getRHS());
+Record.AddSourceLocation(S->getEllipsisLoc());
+  }
   Code = serialization::STMT_CASE;
 }
 
Index: lib/Serialization/ASTReaderStmt.cpp
===
--- lib/Serialization/ASTReaderStmt.cpp
+++ lib/Serialization/ASTReaderStmt.cpp
@@ -177,10 +177,13 @@
 
 void ASTStmtReader::VisitCaseStmt(CaseStmt *S) {
   VisitSwitchCase(S);
+  bool CaseStmtIsGNURange = Record.readInt();
   S->setLHS(Record.readSubExpr());
-  S->setRHS(Record.readSubExpr());
   S->setSubStmt(Record.readSubStmt());
-  S->setEllipsisLoc(ReadSourceLocation());
+  if (CaseStmtIsGNURange) {
+S->setRHS(Record.readSubExpr());
+S->setEllipsisLoc(ReadSourceLocation());
+  }
 }
 
 void ASTStmtReader::VisitDefaultStmt(DefaultStmt *S) {
@@ -2277,7 +2280,9 @@
   break;
 
 case STMT_CASE:
-  S = new 

[PATCH] D53684: [COFF, ARM64] Change setjmp for AArch64 Windows to use Intrinsic.sponentry

2018-10-26 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo accepted this revision.
mstorsjo added a comment.
This revision is now accepted and ready to land.

Looks good to me, once the dependency patch is done.


Repository:
  rC Clang

https://reviews.llvm.org/D53684



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


[PATCH] D53714: [AST] Only store the needed data in SwitchStmt.

2018-10-26 Thread Bruno Ricci via Phabricator via cfe-commits
riccibruno updated this revision to Diff 171337.
riccibruno added a reviewer: rsmith.
riccibruno added a comment.

Add a flag to the output of -ast-dump indicating which sub-statement
a `SwitchStmt` is storing. This removes the ambiguity in the output
of -ast-dump as per rsmith's comment in https://reviews.llvm.org/D53717.


Repository:
  rC Clang

https://reviews.llvm.org/D53714

Files:
  include/clang/AST/Stmt.h
  lib/AST/ASTDumper.cpp
  lib/AST/ASTImporter.cpp
  lib/AST/Stmt.cpp
  lib/Sema/SemaStmt.cpp
  lib/Serialization/ASTReaderStmt.cpp
  lib/Serialization/ASTWriterStmt.cpp
  test/Import/switch-stmt/test.cpp
  test/Misc/ast-dump-color.cpp

Index: test/Misc/ast-dump-color.cpp
===
--- test/Misc/ast-dump-color.cpp
+++ test/Misc/ast-dump-color.cpp
@@ -46,7 +46,6 @@
 //CHECK: {{^}}[[Blue]]|-[[RESET]][[GREEN]]FunctionDecl[[RESET]][[Yellow]] 0x{{[0-9a-fA-F]*}}[[RESET]] <[[Yellow]]line:9:1[[RESET]], [[Yellow]]line:16:1[[RESET]]> [[Yellow]]line:9:6[[RESET]][[CYAN]] TestAttributedStmt[[RESET]] [[Green]]'void ()'[[RESET]]{{$}}
 //CHECK: {{^}}[[Blue]]| |-[[RESET]][[MAGENTA:.\[0;1;35m]]CompoundStmt[[RESET]][[Yellow]] 0x{{[0-9a-fA-F]*}}[[RESET]] <[[Yellow]]col:27[[RESET]], [[Yellow]]line:16:1[[RESET]]>{{$}}
 //CHECK: {{^}}[[Blue]]| | `-[[RESET]][[MAGENTA]]SwitchStmt[[RESET]][[Yellow]] 0x{{[0-9a-fA-F]*}}[[RESET]] <[[Yellow]]line:10:3[[RESET]], [[Yellow]]line:15:3[[RESET]]>{{$}}
-//CHECK: {{^}}[[Blue]]| |   |-[[RESET]][[Blue:.\[0;34m]]<<>>[[RESET]]{{$}}
 //CHECK: {{^}}[[Blue]]| |   |-[[RESET]][[MAGENTA]]IntegerLiteral[[RESET]][[Yellow]] 0x{{[0-9a-fA-F]*}}[[RESET]] <[[Yellow]]line:10:11[[RESET]]> [[Green]]'int'[[RESET]][[Cyan:.\[0;36m]][[RESET]][[Cyan]][[RESET]][[CYAN]] 1[[RESET]]{{$}}
 //CHECK: {{^}}[[Blue]]| |   `-[[RESET]][[MAGENTA]]CompoundStmt[[RESET]][[Yellow]] 0x{{[0-9a-fA-F]*}}[[RESET]] <[[Yellow]]col:14[[RESET]], [[Yellow]]line:15:3[[RESET]]>{{$}}
 //CHECK: {{^}}[[Blue]]| | |-[[RESET]][[MAGENTA]]CaseStmt[[RESET]][[Yellow]] 0x{{[0-9a-fA-F]*}}[[RESET]] <[[Yellow]]line:11:3[[RESET]], [[Yellow]]line:12:27[[RESET]]>{{$}}
Index: test/Import/switch-stmt/test.cpp
===
--- test/Import/switch-stmt/test.cpp
+++ test/Import/switch-stmt/test.cpp
@@ -1,8 +1,6 @@
 // RUN: clang-import-test -dump-ast -import %S/Inputs/F.cpp -expression %s | FileCheck %s
 
 // CHECK: SwitchStmt
-// CHECK-NEXT: <>
-// CHECK-NEXT: <>
 // CHECK-NEXT: IntegerLiteral
 // CHECK-NEXT: CompoundStmt
 // CHECK-NEXT: CaseStmt
@@ -22,7 +20,6 @@
 // CHECK-NEXT: DeclStmt
 // CHECK-NEXT: VarDecl
 // CHECK-SAME: varname
-// CHECK-NEXT: <>
 // CHECK-NEXT: IntegerLiteral
 // CHECK-NEXT: CompoundStmt
 // CHECK-NEXT: CaseStmt
@@ -37,15 +34,11 @@
 // CHECK-NEXT: BreakStmt
 
 // CHECK: SwitchStmt
-// CHECK-NEXT: <>
-// CHECK-NEXT: <>
 // CHECK-NEXT: IntegerLiteral
 // CHECK-NEXT: DefaultStmt
 // CHECK-NEXT: BreakStmt
 
 // CHECK: SwitchStmt
-// CHECK-NEXT: <>
-// CHECK-NEXT: <>
 // CHECK-NEXT: IntegerLiteral
 // CHECK-NEXT: NullStmt
 
Index: lib/Serialization/ASTWriterStmt.cpp
===
--- lib/Serialization/ASTWriterStmt.cpp
+++ lib/Serialization/ASTWriterStmt.cpp
@@ -159,12 +159,22 @@
 
 void ASTStmtWriter::VisitSwitchStmt(SwitchStmt *S) {
   VisitStmt(S);
-  Record.AddStmt(S->getInit());
-  Record.AddDeclRef(S->getConditionVariable());
+
+  bool HasInit = S->getInit() != nullptr;
+  bool HasVar = S->getConditionVariableDeclStmt() != nullptr;
+  Record.push_back(HasInit);
+  Record.push_back(HasVar);
+  Record.push_back(S->isAllEnumCasesCovered());
+
   Record.AddStmt(S->getCond());
   Record.AddStmt(S->getBody());
+  if (HasInit)
+Record.AddStmt(S->getInit());
+  if (HasVar)
+Record.AddDeclRef(S->getConditionVariable());
+
   Record.AddSourceLocation(S->getSwitchLoc());
-  Record.push_back(S->isAllEnumCasesCovered());
+
   for (SwitchCase *SC = S->getSwitchCaseList(); SC;
SC = SC->getNextSwitchCase())
 Record.push_back(Writer.RecordSwitchCaseID(SC));
Index: lib/Serialization/ASTReaderStmt.cpp
===
--- lib/Serialization/ASTReaderStmt.cpp
+++ lib/Serialization/ASTReaderStmt.cpp
@@ -240,13 +240,21 @@
 
 void ASTStmtReader::VisitSwitchStmt(SwitchStmt *S) {
   VisitStmt(S);
-  S->setInit(Record.readSubStmt());
-  S->setConditionVariable(Record.getContext(), ReadDeclAs());
+
+  bool HasInit = Record.readInt();
+  bool HasVar = Record.readInt();
+  bool AllEnumCasesCovered = Record.readInt();
+  if (AllEnumCasesCovered)
+S->setAllEnumCasesCovered();
+
   S->setCond(Record.readSubExpr());
   S->setBody(Record.readSubStmt());
+  if (HasInit)
+S->setInit(Record.readSubStmt());
+  if (HasVar)
+S->setConditionVariable(Record.getContext(), ReadDeclAs());
+
   S->setSwitchLoc(ReadSourceLocation());
-  if (Record.readInt())
-S->setAllEnumCasesCovered();
 
   SwitchCase *PrevSC = nullptr;
   f

[PATCH] D53715: [AST] Only store the needed data in WhileStmt.

2018-10-26 Thread Bruno Ricci via Phabricator via cfe-commits
riccibruno updated this revision to Diff 171338.
riccibruno added a reviewer: rsmith.
riccibruno added a comment.

Add a flag to the output of -ast-dump indicating which sub-statement
a `WhileStmt` is storing.


Repository:
  rC Clang

https://reviews.llvm.org/D53715

Files:
  include/clang/AST/Stmt.h
  lib/AST/ASTDumper.cpp
  lib/AST/ASTImporter.cpp
  lib/AST/Stmt.cpp
  lib/Sema/SemaStmt.cpp
  lib/Serialization/ASTReaderStmt.cpp
  lib/Serialization/ASTWriterStmt.cpp
  test/Import/while-stmt/test.cpp

Index: test/Import/while-stmt/test.cpp
===
--- test/Import/while-stmt/test.cpp
+++ test/Import/while-stmt/test.cpp
@@ -1,12 +1,10 @@
 // RUN: clang-import-test -dump-ast -import %S/Inputs/F.cpp -expression %s | FileCheck %s
 
 // CHECK: WhileStmt
-// CHECK-NEXT: <>
 // CHECK-NEXT: CXXBoolLiteralExpr
 // CHECK-NEXT: NullStmt
 
 // CHECK: WhileStmt
-// CHECK-NEXT: <>
 // CHECK-NEXT: CXXBoolLiteralExpr
 // CHECK-NEXT: CompoundStmt
 
Index: lib/Serialization/ASTWriterStmt.cpp
===
--- lib/Serialization/ASTWriterStmt.cpp
+++ lib/Serialization/ASTWriterStmt.cpp
@@ -183,9 +183,15 @@
 
 void ASTStmtWriter::VisitWhileStmt(WhileStmt *S) {
   VisitStmt(S);
-  Record.AddDeclRef(S->getConditionVariable());
+
+  bool HasVar = S->getConditionVariableDeclStmt() != nullptr;
+  Record.push_back(HasVar);
+
   Record.AddStmt(S->getCond());
   Record.AddStmt(S->getBody());
+  if (HasVar)
+Record.AddDeclRef(S->getConditionVariable());
+
   Record.AddSourceLocation(S->getWhileLoc());
   Code = serialization::STMT_WHILE;
 }
Index: lib/Serialization/ASTReaderStmt.cpp
===
--- lib/Serialization/ASTReaderStmt.cpp
+++ lib/Serialization/ASTReaderStmt.cpp
@@ -270,10 +270,14 @@
 
 void ASTStmtReader::VisitWhileStmt(WhileStmt *S) {
   VisitStmt(S);
-  S->setConditionVariable(Record.getContext(), ReadDeclAs());
+
+  bool HasVar = Record.readInt();
 
   S->setCond(Record.readSubExpr());
   S->setBody(Record.readSubStmt());
+  if (HasVar)
+S->setConditionVariable(Record.getContext(), ReadDeclAs());
+
   S->setWhileLoc(ReadSourceLocation());
 }
 
@@ -2323,7 +2327,9 @@
   break;
 
 case STMT_WHILE:
-  S = new (Context) WhileStmt(Empty);
+  S = WhileStmt::CreateEmpty(
+  Context,
+  /* HasVar=*/Record[ASTStmtReader::NumStmtFields + 0]);
   break;
 
 case STMT_DO:
Index: lib/Sema/SemaStmt.cpp
===
--- lib/Sema/SemaStmt.cpp
+++ lib/Sema/SemaStmt.cpp
@@ -1305,8 +1305,8 @@
   if (isa(Body))
 getCurCompoundScope().setHasEmptyLoopBodies();
 
-  return new (Context)
-  WhileStmt(Context, CondVal.first, CondVal.second, Body, WhileLoc);
+  return WhileStmt::Create(Context, CondVal.first, CondVal.second, Body,
+   WhileLoc);
 }
 
 StmtResult
Index: lib/AST/Stmt.cpp
===
--- lib/AST/Stmt.cpp
+++ lib/AST/Stmt.cpp
@@ -978,32 +978,60 @@
   DeclStmt(DeclGroupRef(V), VarRange.getBegin(), VarRange.getEnd());
 }
 
-WhileStmt::WhileStmt(const ASTContext &C, VarDecl *Var, Expr *cond, Stmt *body,
- SourceLocation WL)
-  : Stmt(WhileStmtClass) {
-  setConditionVariable(C, Var);
-  SubExprs[COND] = cond;
-  SubExprs[BODY] = body;
-  WhileStmtBits.WhileLoc = WL;
+WhileStmt::WhileStmt(const ASTContext &Ctx, VarDecl *Var, Expr *Cond,
+ Stmt *Body, SourceLocation WL)
+: Stmt(WhileStmtClass) {
+  bool HasVar = Var != nullptr;
+  WhileStmtBits.HasVar = HasVar;
+
+  setCond(Cond);
+  setBody(Body);
+  if (HasVar)
+setConditionVariable(Ctx, Var);
+
+  setWhileLoc(WL);
 }
 
-VarDecl *WhileStmt::getConditionVariable() const {
-  if (!SubExprs[VAR])
-return nullptr;
+WhileStmt::WhileStmt(EmptyShell Empty, bool HasVar)
+: Stmt(WhileStmtClass, Empty) {
+  WhileStmtBits.HasVar = HasVar;
+}
+
+WhileStmt *WhileStmt::Create(const ASTContext &Ctx, VarDecl *Var, Expr *Cond,
+ Stmt *Body, SourceLocation WL) {
+  bool HasVar = Var != nullptr;
+  void *Mem =
+  Ctx.Allocate(totalSizeToAlloc(NumMandatoryStmtPtr + HasVar),
+   alignof(WhileStmt));
+  return new (Mem) WhileStmt(Ctx, Var, Cond, Body, WL);
+}
 
-  auto *DS = cast(SubExprs[VAR]);
+WhileStmt *WhileStmt::CreateEmpty(const ASTContext &Ctx, bool HasVar) {
+  void *Mem =
+  Ctx.Allocate(totalSizeToAlloc(NumMandatoryStmtPtr + HasVar),
+   alignof(WhileStmt));
+  return new (Mem) WhileStmt(EmptyShell(), HasVar);
+}
+
+VarDecl *WhileStmt::getConditionVariable() {
+  auto *DS = getConditionVariableDeclStmt();
+  if (!DS)
+return nullptr;
   return cast(DS->getSingleDecl());
 }
 
-void WhileStmt::setConditionVariable(const ASTContext &C, VarDecl *V) {
+void WhileStmt::setConditionVariable(const ASTContext &Ctx, VarDecl *V

[PATCH] D53717: [AST] Only store the needed data in ForStmt.

2018-10-26 Thread Bruno Ricci via Phabricator via cfe-commits
riccibruno updated this revision to Diff 171340.
riccibruno marked 6 inline comments as done.
riccibruno added a comment.

Add a flag in the output of -ast-dump indicating which sub-statement
the `ForStmt` is storing. This removes the ambiguity in the output
of -ast-dump.


Repository:
  rC Clang

https://reviews.llvm.org/D53717

Files:
  include/clang/AST/Stmt.h
  lib/AST/ASTDumper.cpp
  lib/AST/ASTImporter.cpp
  lib/AST/Stmt.cpp
  lib/Sema/SemaStmt.cpp
  lib/Serialization/ASTReaderStmt.cpp
  lib/Serialization/ASTWriterStmt.cpp
  test/Import/for-stmt/test.cpp

Index: test/Import/for-stmt/test.cpp
===
--- test/Import/for-stmt/test.cpp
+++ test/Import/for-stmt/test.cpp
@@ -3,21 +3,17 @@
 // CHECK: ForStmt
 // CHECK-NEXT: <>
 // CHECK-NEXT: <>
-// CHECK-NEXT: <>
-// CHECK-NEXT: <>
 // CHECK-NEXT: NullStmt
 
 // CHECK: ForStmt
 // CHECK-NEXT: DeclStmt
 // CHECK-NEXT: VarDecl
 // CHECK-NEXT: IntegerLiteral
 // CHECK-NEXT: <>
 // CHECK-NEXT: <>
-// CHECK-NEXT: <>
 // CHECK-NEXT: ContinueStmt
 
 // CHECK: ForStmt
-// CHECK-NEXT: <>
 // CHECK-NEXT: DeclStmt
 // CHECK-NEXT: VarDecl
 // CHECK-NEXT: CXXBoolLiteralExpr
@@ -32,7 +28,6 @@
 // CHECK-NEXT: DeclStmt
 // CHECK-NEXT: VarDecl
 // CHECK-NEXT: IntegerLiteral
-// CHECK-NEXT: <>
 
 // CHECK-NEXT: BinaryOperator
 // CHECK-NEXT: ImplicitCastExpr
Index: lib/Serialization/ASTWriterStmt.cpp
===
--- lib/Serialization/ASTWriterStmt.cpp
+++ lib/Serialization/ASTWriterStmt.cpp
@@ -208,11 +208,20 @@
 
 void ASTStmtWriter::VisitForStmt(ForStmt *S) {
   VisitStmt(S);
-  Record.AddStmt(S->getInit());
+
+  bool HasInit = S->getInit() != nullptr;
+  bool HasVar = S->getConditionVariableDeclStmt() != nullptr;
+  Record.push_back(HasInit);
+  Record.push_back(HasVar);
+
   Record.AddStmt(S->getCond());
-  Record.AddDeclRef(S->getConditionVariable());
   Record.AddStmt(S->getInc());
   Record.AddStmt(S->getBody());
+  if (HasInit)
+Record.AddStmt(S->getInit());
+  if (HasVar)
+Record.AddDeclRef(S->getConditionVariable());
+
   Record.AddSourceLocation(S->getForLoc());
   Record.AddSourceLocation(S->getLParenLoc());
   Record.AddSourceLocation(S->getRParenLoc());
Index: lib/Serialization/ASTReaderStmt.cpp
===
--- lib/Serialization/ASTReaderStmt.cpp
+++ lib/Serialization/ASTReaderStmt.cpp
@@ -292,11 +292,18 @@
 
 void ASTStmtReader::VisitForStmt(ForStmt *S) {
   VisitStmt(S);
-  S->setInit(Record.readSubStmt());
+
+  bool HasInit = Record.readInt();
+  bool HasVar = Record.readInt();
+
   S->setCond(Record.readSubExpr());
-  S->setConditionVariable(Record.getContext(), ReadDeclAs());
   S->setInc(Record.readSubExpr());
   S->setBody(Record.readSubStmt());
+  if (HasInit)
+S->setInit(Record.readSubStmt());
+  if (HasVar)
+S->setConditionVariable(Record.getContext(), ReadDeclAs());
+
   S->setForLoc(ReadSourceLocation());
   S->setLParenLoc(ReadSourceLocation());
   S->setRParenLoc(ReadSourceLocation());
@@ -2342,7 +2349,10 @@
   break;
 
 case STMT_FOR:
-  S = new (Context) ForStmt(Empty);
+  S = ForStmt::CreateEmpty(
+  Context,
+  /* HasInit=*/Record[ASTStmtReader::NumStmtFields + 0],
+  /* HasVar=*/Record[ASTStmtReader::NumStmtFields + 1]);
   break;
 
 case STMT_GOTO:
Index: lib/Sema/SemaStmt.cpp
===
--- lib/Sema/SemaStmt.cpp
+++ lib/Sema/SemaStmt.cpp
@@ -1780,9 +1780,9 @@
   if (isa(Body))
 getCurCompoundScope().setHasEmptyLoopBodies();
 
-  return new (Context)
-  ForStmt(Context, First, Second.get().second, Second.get().first, Third,
-  Body, ForLoc, LParenLoc, RParenLoc);
+  return ForStmt::Create(Context, First, Second.get().second,
+ Second.get().first, Third, Body, ForLoc, LParenLoc,
+ RParenLoc);
 }
 
 /// In an Objective C collection iteration statement:
Index: lib/AST/Stmt.cpp
===
--- lib/AST/Stmt.cpp
+++ lib/AST/Stmt.cpp
@@ -881,36 +881,71 @@
   return isa(getCond());
 }
 
-ForStmt::ForStmt(const ASTContext &C, Stmt *Init, Expr *Cond, VarDecl *condVar,
- Expr *Inc, Stmt *Body, SourceLocation FL, SourceLocation LP,
- SourceLocation RP)
-  : Stmt(ForStmtClass), LParenLoc(LP), RParenLoc(RP)
-{
-  SubExprs[INIT] = Init;
-  setConditionVariable(C, condVar);
-  SubExprs[COND] = Cond;
-  SubExprs[INC] = Inc;
-  SubExprs[BODY] = Body;
-  ForStmtBits.ForLoc = FL;
-}
-
-VarDecl *ForStmt::getConditionVariable() const {
-  if (!SubExprs[CONDVAR])
-return nullptr;
+ForStmt::ForStmt(const ASTContext &Ctx, Stmt *Init, Expr *Cond,
+ VarDecl *CondVar, Expr *Inc, Stmt *Body, SourceLocation FL,
+ SourceLocation LP, SourceLocation RP)
+: Stmt(ForStmtClass), LParenLoc(LP), R

[PATCH] D53771: [clang-tidy] Avoid C arrays check

2018-10-26 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth added inline comments.



Comment at: test/clang-tidy/misc-avoid-c-arrays.cpp:14
+
+template 
+class array {

lebedev.ri wrote:
> JonasToth wrote:
> > Please add a case with templates, where `T` itself is the array type, maybe 
> > there are other fancy template tricks that could create an array implictly?
> Oh i see, `array` is not diagnosed, that is where it gets 
> interesting :S
> So i need to match `type(arrayType())`, and then find the location to 
> complain about
> (the type does not seem to have it).
you could leave it as known limitation as well.
If the type `T` is then diagnosed as array creation through 
template-instantiation the warning is still valid.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D53771



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


[PATCH] D53717: [AST] Only store the needed data in ForStmt.

2018-10-26 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added inline comments.



Comment at: include/clang/AST/Stmt.h:1863
+  Expr *getCond() {
+return reinterpret_cast(getTrailingObjects()[condOffset()]);
+  }

riccibruno wrote:
> rsmith wrote:
> > Please `static_cast` rather than `reinterpret_cast` throughout. (If the 
> > `Stmt` base class weren't at offset 0 within `Expr`, we'd want to apply the 
> > adjustment.)
> I would gladly get rid of these ugly `reinterpret_cast`,
> but unfortunately the definition of `Expr` is not available in `Stmt.h`.
> 
> As you say these `reinterpret_cast` only work now because of the layout.
> 
> A solution would be to move `Expr` and `Stmt` to something like `StmtBase.h`
> and include this in `Stmt.h`. This would allow us to get of these casts 
> between
> `Stmt` and `Expr`. Of the 91 `reinterpret_cast` in all of the `Stmt*.h` it 
> seems that
> at least 2/3 of them could be removed.
Ugh, I see, thanks. Yes, pulling `Expr` and `Stmt` out into a `StmtBase.h` or 
similar seems like a good approach to me.


Repository:
  rC Clang

https://reviews.llvm.org/D53717



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


[PATCH] D50860: [libc++][test] Remove non-portable assumption that thread's constructor allocates with ::new

2018-10-26 Thread Casey Carter via Phabricator via cfe-commits
CaseyCarter updated this revision to Diff 171344.
CaseyCarter added a comment.

Clarify use of `numAllocs`.


https://reviews.llvm.org/D50860

Files:
  
test/std/thread/thread.threads/thread.thread.class/thread.thread.constr/F.pass.cpp


Index: 
test/std/thread/thread.threads/thread.thread.class/thread.thread.constr/F.pass.cpp
===
--- 
test/std/thread/thread.threads/thread.thread.class/thread.thread.constr/F.pass.cpp
+++ 
test/std/thread/thread.threads/thread.thread.class/thread.thread.constr/F.pass.cpp
@@ -31,17 +31,19 @@
 
 void* operator new(std::size_t s) TEST_THROW_SPEC(std::bad_alloc)
 {
-if (throw_one == 0)
-TEST_THROW(std::bad_alloc());
---throw_one;
+unsigned expected = throw_one;
+do {
+if (expected == 0) TEST_THROW(std::bad_alloc());
+} while (!throw_one.compare_exchange_weak(expected, expected - 1));
 ++outstanding_new;
 void* ret = std::malloc(s);
 if (!ret) std::abort(); // placate MSVC's unchecked malloc warning
 return ret;
 }
 
 void  operator delete(void* p) TEST_NOEXCEPT
 {
+if (!p) return;
 --outstanding_new;
 std::free(p);
 }
@@ -109,21 +111,23 @@
 //  B std::thread's constructor should properly handle exceptions and not leak
 //memory.
 // Plan:
-//  1 Create a thread and count the number of allocations, 'N', it performs.
+//  1 Create a thread and count the number of allocations, 'numAllocs', it 
performs.
 //  2 For each allocation performed run a test where that allocation throws.
 //2.1 check that the exception can be caught in the parent thread.
 //2.2 Check that the functor has not been called.
 //2.3 Check that no memory allocated by the creation of the thread is 
leaked.
-//  3 Finally check that a thread runs successfully if we throw after 'N+1'
+//  3 Finally check that a thread runs successfully if we throw after 
'numAllocs+1'
 //allocations.
+int numAllocs;
+
 void test_throwing_new_during_thread_creation() {
 #ifndef TEST_HAS_NO_EXCEPTIONS
 throw_one = 0xFFF;
 {
 std::thread t(f);
 t.join();
 }
-const int numAllocs = 0xFFF - throw_one;
+numAllocs = 0xFFF - throw_one;
 // i <= numAllocs means the last iteration is expected not to throw.
 for (int i=0; i <= numAllocs; ++i) {
 throw_one = i;
@@ -167,16 +171,16 @@
 }
 G::op_run = false;
 #ifndef TEST_HAS_NO_EXCEPTIONS
-{
+if (numAllocs > 0) { // Creating a thread might not call new at all.
 try
 {
 throw_one = 0;
 assert(G::n_alive == 0);
 assert(!G::op_run);
 std::thread t((G()));
 assert(false);
 }
-catch (...)
+catch (std::bad_alloc const&)
 {
 throw_one = 0x;
 assert(G::n_alive == 0);


Index: test/std/thread/thread.threads/thread.thread.class/thread.thread.constr/F.pass.cpp
===
--- test/std/thread/thread.threads/thread.thread.class/thread.thread.constr/F.pass.cpp
+++ test/std/thread/thread.threads/thread.thread.class/thread.thread.constr/F.pass.cpp
@@ -31,17 +31,19 @@
 
 void* operator new(std::size_t s) TEST_THROW_SPEC(std::bad_alloc)
 {
-if (throw_one == 0)
-TEST_THROW(std::bad_alloc());
---throw_one;
+unsigned expected = throw_one;
+do {
+if (expected == 0) TEST_THROW(std::bad_alloc());
+} while (!throw_one.compare_exchange_weak(expected, expected - 1));
 ++outstanding_new;
 void* ret = std::malloc(s);
 if (!ret) std::abort(); // placate MSVC's unchecked malloc warning
 return ret;
 }
 
 void  operator delete(void* p) TEST_NOEXCEPT
 {
+if (!p) return;
 --outstanding_new;
 std::free(p);
 }
@@ -109,21 +111,23 @@
 //  B std::thread's constructor should properly handle exceptions and not leak
 //memory.
 // Plan:
-//  1 Create a thread and count the number of allocations, 'N', it performs.
+//  1 Create a thread and count the number of allocations, 'numAllocs', it performs.
 //  2 For each allocation performed run a test where that allocation throws.
 //2.1 check that the exception can be caught in the parent thread.
 //2.2 Check that the functor has not been called.
 //2.3 Check that no memory allocated by the creation of the thread is leaked.
-//  3 Finally check that a thread runs successfully if we throw after 'N+1'
+//  3 Finally check that a thread runs successfully if we throw after 'numAllocs+1'
 //allocations.
+int numAllocs;
+
 void test_throwing_new_during_thread_creation() {
 #ifndef TEST_HAS_NO_EXCEPTIONS
 throw_one = 0xFFF;
 {
 std::thread t(f);
 t.join();
 }
-const int numAllocs = 0xFFF - throw_one;
+numAllocs = 0xFFF - throw_one;
 // i <= numAllocs means the last iteration is expected not to throw.
 for (int i=0; i <= numAllocs; ++i) {
 throw_one = i;
@@ -167,16 +

[PATCH] D51949: [clang-tidy] new check 'readability-isolate-declaration'

2018-10-26 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth added inline comments.



Comment at: clang-tidy/readability/IsolateDeclarationCheck.cpp:52
+ const LangOptions &LangOpts) {
+  assert(Indirections >= 0 && "Indirections must be non-negative");
+  if (Indirections == 0)

aaron.ballman wrote:
> JonasToth wrote:
> > aaron.ballman wrote:
> > > This assertion suggests that `Indirections` should be `unsigned` and that 
> > > you perform the assertion before doing a decrement to ensure it isn't 
> > > trying to decrement past 0.
> > Because the decrement is post-fix it will decrement past 0 on the breaking 
> > condition.
> > Having `unsigned` will result in a wrap (is defined, but still slightly 
> > non-obvious).
> > 
> > I could make a `do - while`, then the condition can be `--Indirections != 
> > 0`. I would just like to follow the CPPCG that say 'don't use unsigned 
> > unless you need modulo arithmetic'.
> I disagree with this logic (personally, I think this is a code smell), but 
> don't feel strongly enough about it to ask you to change it.
I totally see the point, and it started as `unsigned` as well, but it felt 
uncomfortable. thanks for letting me do it :)



Comment at: docs/clang-tidy/checks/readability-isolate-declaration.rst:3
+
+readability-isolate-declarationaration
+==

aaron.ballman wrote:
> Typo. declarationaration -> declaration
> 
> (Don't forget to fix the underlines as well.)
That was definitly too deep in the night :D



Comment at: docs/clang-tidy/checks/readability-isolate-declaration.rst:45
+
+Global variables and member variables are excluded.
+

aaron.ballman wrote:
> Why are global variables excluded from this check? It seems like they should 
> have the exact same behavior as local variables in terms of the 
> transformation, no?
I thought so too, but take a look at the AST:

```
int global_i, global_j = 42, global_k;
void f() {
int local_i, local_j = 42, local_k;
}
```

```
|-VarDecl 0x55c428c4ab08  col:5 global_i 'int'
|-VarDecl 0x55c428c4abc0  col:15 global_j 'int' cinit
| `-IntegerLiteral 0x55c428c4ac20  'int' 42
|-VarDecl 0x55c428c4ac58  col:30 global_k 'int'
`-FunctionDecl 0x55c428c4ad30  line:2:6 f 'void ()'
  `-CompoundStmt 0x55c428c4af90 
`-DeclStmt 0x55c428c4af78 
  |-VarDecl 0x55c428c4ade8  col:9 local_i 'int'
  |-VarDecl 0x55c428c4ae60  col:18 local_j 'int' cinit
  | `-IntegerLiteral 0x55c428c4aec0  'int' 42
  `-VarDecl 0x55c428c4aef8  col:32 local_k 'int'
```

The locals create a `DeclStmt` and the globals don't, right now the 
transformation depends on the fact that its a `DeclStmt`, similar to class 
members that are `FieldDecl`.

I did short investigation on the issue, but couldn't think of a good way to fix 
that issue. I was not capable of "grouping" these decls even though they are 
together. Maybe I just missed something obvious, but right it's not supported. 
I would love to actually support it tough.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D51949



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


[PATCH] D51949: [clang-tidy] new check 'readability-isolate-declaration'

2018-10-26 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth updated this revision to Diff 171346.
JonasToth marked 16 inline comments as done.
JonasToth added a comment.

- address review comments


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D51949

Files:
  clang-tidy/readability/CMakeLists.txt
  clang-tidy/readability/IsolateDeclarationCheck.cpp
  clang-tidy/readability/IsolateDeclarationCheck.h
  clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tidy/utils/LexerUtils.cpp
  clang-tidy/utils/LexerUtils.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/readability-isolate-declaration.rst
  test/clang-tidy/readability-isolate-declaration-cxx17.cpp
  test/clang-tidy/readability-isolate-declaration-fixing.cpp
  test/clang-tidy/readability-isolate-declaration.c
  test/clang-tidy/readability-isolate-declaration.cpp

Index: test/clang-tidy/readability-isolate-declaration.cpp
===
--- /dev/null
+++ test/clang-tidy/readability-isolate-declaration.cpp
@@ -0,0 +1,412 @@
+// RUN: %check_clang_tidy %s readability-isolate-declaration %t
+
+void f() {
+  int i;
+}
+
+void f2() {
+  int i, j, *k, lala = 42;
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: multiple declarations in a single statement reduces readability
+  // CHECK-FIXES: int i;
+  // CHECK-FIXES: {{^  }}int j;
+  // CHECK-FIXES: {{^  }}int *k;
+  // CHECK-FIXES: {{^  }}int lala = 42;
+
+  int normal, weird = /* comment */ 42;
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: multiple declarations in a single statement reduces readability
+  // CHECK-FIXES: int normal;
+  // CHECK-FIXES: {{^  }}int weird = /* comment */ 42;
+
+  int /* here is a comment */ v1,
+  // another comment
+  v2 = 42 // Ok, more comments
+  ;
+  // CHECK-MESSAGES: [[@LINE-4]]:3: warning: multiple declarations in a single statement reduces readability
+  // CHECK-FIXES: int /* here is a comment */ v1;
+  // CHECK-FIXES: {{^  }}int /* here is a comment */ // another comment
+  // CHECK-FIXES: {{^  }}v2 = 42 // Ok, more comments
+  // CHECK-FIXES: {{^  }};
+
+  auto int1 = 42, int2 = 0, int3 = 43;
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: multiple declarations in a single statement reduces readability
+  // CHECK-FIXES: auto int1 = 42;
+  // CHECK-FIXES: {{^  }}auto int2 = 0;
+  // CHECK-FIXES: {{^  }}auto int3 = 43;
+
+  decltype(auto) ptr1 = &int1, ptr2 = &int1;
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: multiple declarations in a single statement reduces readability
+  // CHECK-FIXES: decltype(auto) ptr1 = &int1;
+  // CHECK-FIXES: {{^  }}decltype(auto) ptr2 = &int1;
+
+  decltype(k) ptr3 = &int1, ptr4 = &int1;
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: multiple declarations in a single statement reduces readability
+  // CHECK-FIXES: decltype(k) ptr3 = &int1;
+  // CHECK-FIXES: {{^  }}decltype(k) ptr4 = &int1;
+}
+
+void f3() {
+  int i, *pointer1;
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: multiple declarations in a single statement reduces readability
+  // CHECK-FIXES: int i;
+  // CHECK-FIXES: {{^  }}int *pointer1;
+  //
+  int *pointer2 = nullptr, *pointer3 = &i;
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: multiple declarations in a single statement reduces readability
+  // CHECK-FIXES: int *pointer2 = nullptr;
+  // CHECK-FIXES: {{^  }}int *pointer3 = &i;
+
+  int *(i_ptr) = nullptr, *((i_ptr2));
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: multiple declarations in a single statement reduces readability
+  // CHECK-FIXES: int *(i_ptr) = nullptr;
+  // CHECK-FIXES: {{^  }}int *((i_ptr2));
+
+  float(*f_ptr)[42], (((f_value))) = 42;
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: multiple declarations in a single statement reduces readability
+  // CHECK-FIXES: float (*f_ptr)[42];
+  // CHECK-FIXES: {{^  }}float (((f_value))) = 42;
+
+  float(((*f_ptr2)))[42], ((*f_ptr3)), f_value2 = 42.f;
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: multiple declarations in a single statement reduces readability
+  // CHECK-FIXES: float (((*f_ptr2)))[42];
+  // CHECK-FIXES: {{^  }}float ((*f_ptr3));
+  // CHECK-FIXES: {{^  }}float f_value2 = 42.f;
+
+  float(((*f_ptr4)))[42], *f_ptr5, ((f_value3));
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: multiple declarations in a single statement reduces readability
+  // CHECK-FIXES: float (((*f_ptr4)))[42];
+  // CHECK-FIXES: {{^  }}float *f_ptr5;
+  // CHECK-FIXES: {{^  }}float ((f_value3));
+
+  void(((*f2))(int)), (*g2)(int, float);
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: multiple declarations in a single statement reduces readability
+  // CHECK-FIXES: void (((*f2))(int));
+  // CHECK-FIXES: {{^  }}void (*g2)(int, float);
+
+  float(*(*(*f_ptr6)))[42], (*f_ptr7);
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: multiple declarations in a single statement reduces readability
+  // CHECK-FIXES: float (*(*(*f_ptr6)))[42];
+  // CHECK-FIXES: {{^  }}float (*f_ptr7);
+}
+
+void f4() {
+  double d = 42. /* foo */, z = 43., /* hi */ y, c /* */ /*  

[PATCH] D53621: Support for groups of attributes in #pragma clang attribute

2018-10-26 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman accepted this revision.
arphaman added a comment.

LGTM too when Aaron's comments are addressed


https://reviews.llvm.org/D53621



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


[PATCH] D53443: [OpenMP][NVPTX] Enable default scheduling for parallel for in non-SPMD cases.

2018-10-26 Thread Gheorghe-Teodor Bercea via Phabricator via cfe-commits
gtbercea updated this revision to Diff 171352.
gtbercea added a comment.

  Add test.


Repository:
  rC Clang

https://reviews.llvm.org/D53443

Files:
  lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
  test/OpenMP/nvptx_parallel_for_codegen.cpp


Index: test/OpenMP/nvptx_parallel_for_codegen.cpp
===
--- test/OpenMP/nvptx_parallel_for_codegen.cpp
+++ test/OpenMP/nvptx_parallel_for_codegen.cpp
@@ -57,7 +57,10 @@
 // CHECK: store i32 0, {{.*}} [[OMP_LB:%.+]],
 // CHECK: store i32 9, {{.*}} [[OMP_UB:%.+]],
 // CHECK: store i32 1, {{.*}} [[OMP_ST:%.+]],
-// CHECK: call void @__kmpc_for_static_init_4({{.*}} i32 34, {{.*}} 
[[OMP_LB]], {{.*}} [[OMP_UB]], {{.*}} [[OMP_ST]], i32 1, i32 1)
+// CHECK: call void @__kmpc_for_static_init_4({{.*}} i32 33, {{.*}} 
[[OMP_LB]], {{.*}} [[OMP_UB]], {{.*}} [[OMP_ST]], i32 1, i32 1)
+// CHECK: br label %[[OMP_DISPATCH_COND:.+]]
+
+// CHECK: [[OMP_DISPATCH_COND]]
 // CHECK: [[OMP_UB_1:%.+]] = load {{.*}} [[OMP_UB]]
 // CHECK: [[COMP_1:%.+]] = icmp sgt {{.*}} [[OMP_UB_1]]
 // CHECK: br i1 [[COMP_1]], label %[[COND_TRUE:.+]], label %[[COND_FALSE:.+]]
@@ -74,6 +77,12 @@
 // CHECK: store i32 [[COND_RES]], i32* [[OMP_UB]]
 // CHECK: [[OMP_LB_1:%.+]] = load i32, i32* [[OMP_LB]]
 // CHECK: store i32 [[OMP_LB_1]], i32* [[OMP_IV]]
+// CHECK: [[OMP_IV_1:%.+]] = load i32, i32* [[OMP_IV]]
+// CHECK: [[OMP_UB_3:%.+]] = load i32, i32* [[OMP_UB]]
+// CHECK: [[COMP_2:%.+]] = icmp sle i32 [[OMP_IV_1]], [[OMP_UB_3]]
+// CHECK: br i1 [[COMP_2]], label %[[DISPATCH_BODY:.+]], label 
%[[DISPATCH_END:.+]]
+
+// CHECK: [[DISPATCH_BODY]]
 // CHECK: br label %[[OMP_INNER_FOR_COND:.+]]
 
 // CHECK: [[OMP_INNER_FOR_COND]]
@@ -94,7 +103,20 @@
 // CHECK: store i32 [[ADD_1]], i32* [[OMP_IV]]
 // CHECK: br label %[[OMP_INNER_FOR_COND]]
 
-// CHECK: [[OMP_INNER_FOR_END]]
+// CHECK: [[OMP_INNER_FOR_COND]]
+// CHECK: br label %[[OMP_DISPATCH_INC:.+]]
+
+// CHECK: [[OMP_DISPATCH_INC]]
+// CHECK: [[OMP_LB_2:%.+]] = load i32, i32* [[OMP_LB]]
+// CHECK: [[OMP_ST_1:%.+]] = load i32, i32* [[OMP_ST]]
+// CHECK: [[ADD_2:%.+]] = add nsw i32 [[OMP_LB_2]], [[OMP_ST_1]]
+// CHECK: store i32 [[ADD_2]], i32* [[OMP_LB]]
+// CHECK: [[OMP_UB_5:%.+]] = load i32, i32* [[OMP_UB]]
+// CHECK: [[OMP_ST_2:%.+]] = load i32, i32* [[OMP_ST]]
+// CHECK: [[ADD_3:%.+]] = add nsw i32 [[OMP_UB_5]], [[OMP_ST_2]]
+// CHECK: store i32 [[ADD_3]], i32* [[OMP_UB]]
+
+// CHECK: [[DISPATCH_END]]
 // CHECK: call void @__kmpc_for_static_fini(
 // CHECK: ret void
 
Index: lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
===
--- lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
+++ lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
@@ -4238,16 +4238,17 @@
 Chunk = CGF.EmitScalarConversion(getNVPTXNumThreads(CGF),
 CGF.getContext().getIntTypeForBitwidth(32, /*Signed=*/0),
 S.getIterationVariable()->getType(), S.getBeginLoc());
+return;
   }
+  CGOpenMPRuntime::getDefaultDistScheduleAndChunk(
+  CGF, S, ScheduleKind, Chunk);
 }
 
 void CGOpenMPRuntimeNVPTX::getDefaultScheduleAndChunk(
 CodeGenFunction &CGF, const OMPLoopDirective &S,
 OpenMPScheduleClauseKind &ScheduleKind,
 llvm::Value *&Chunk) const {
-  if (getExecutionMode() == CGOpenMPRuntimeNVPTX::EM_SPMD) {
-ScheduleKind = OMPC_SCHEDULE_static;
-Chunk = CGF.Builder.getIntN(CGF.getContext().getTypeSize(
-S.getIterationVariable()->getType()), 1);
-  }
+  ScheduleKind = OMPC_SCHEDULE_static;
+  Chunk = CGF.Builder.getIntN(CGF.getContext().getTypeSize(
+  S.getIterationVariable()->getType()), 1);
 }


Index: test/OpenMP/nvptx_parallel_for_codegen.cpp
===
--- test/OpenMP/nvptx_parallel_for_codegen.cpp
+++ test/OpenMP/nvptx_parallel_for_codegen.cpp
@@ -57,7 +57,10 @@
 // CHECK: store i32 0, {{.*}} [[OMP_LB:%.+]],
 // CHECK: store i32 9, {{.*}} [[OMP_UB:%.+]],
 // CHECK: store i32 1, {{.*}} [[OMP_ST:%.+]],
-// CHECK: call void @__kmpc_for_static_init_4({{.*}} i32 34, {{.*}} [[OMP_LB]], {{.*}} [[OMP_UB]], {{.*}} [[OMP_ST]], i32 1, i32 1)
+// CHECK: call void @__kmpc_for_static_init_4({{.*}} i32 33, {{.*}} [[OMP_LB]], {{.*}} [[OMP_UB]], {{.*}} [[OMP_ST]], i32 1, i32 1)
+// CHECK: br label %[[OMP_DISPATCH_COND:.+]]
+
+// CHECK: [[OMP_DISPATCH_COND]]
 // CHECK: [[OMP_UB_1:%.+]] = load {{.*}} [[OMP_UB]]
 // CHECK: [[COMP_1:%.+]] = icmp sgt {{.*}} [[OMP_UB_1]]
 // CHECK: br i1 [[COMP_1]], label %[[COND_TRUE:.+]], label %[[COND_FALSE:.+]]
@@ -74,6 +77,12 @@
 // CHECK: store i32 [[COND_RES]], i32* [[OMP_UB]]
 // CHECK: [[OMP_LB_1:%.+]] = load i32, i32* [[OMP_LB]]
 // CHECK: store i32 [[OMP_LB_1]], i32* [[OMP_IV]]
+// CHECK: [[OMP_IV_1:%.+]] = load i32, i32* [[OMP_IV]]
+// CHECK: [[OMP_UB_3:%.+]] = load i32, i32* [[OMP_UB]]
+// CHECK: [[COMP_2:%.+]] = icmp sle i32 [[OMP_IV_1]], [[OMP_UB_3]]
+// CHECK: br i1 [[COMP_2]], label %[[DISPATCH_BODY:.+]], label %[[DISPATCH_END:.+]]
+
+// CHECK: [[DISPATCH_BODY]]
 // CHECK: b

[PATCH] D51949: [clang-tidy] new check 'readability-isolate-declaration'

2018-10-26 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth updated this revision to Diff 171361.
JonasToth added a comment.

- [Fix] wrong condition in matcher coming from incorrect code change


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D51949

Files:
  clang-tidy/readability/CMakeLists.txt
  clang-tidy/readability/IsolateDeclarationCheck.cpp
  clang-tidy/readability/IsolateDeclarationCheck.h
  clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tidy/utils/LexerUtils.cpp
  clang-tidy/utils/LexerUtils.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/readability-isolate-declaration.rst
  test/clang-tidy/readability-isolate-declaration-cxx17.cpp
  test/clang-tidy/readability-isolate-declaration-fixing.cpp
  test/clang-tidy/readability-isolate-declaration.c
  test/clang-tidy/readability-isolate-declaration.cpp

Index: test/clang-tidy/readability-isolate-declaration.cpp
===
--- /dev/null
+++ test/clang-tidy/readability-isolate-declaration.cpp
@@ -0,0 +1,412 @@
+// RUN: %check_clang_tidy %s readability-isolate-declaration %t
+
+void f() {
+  int i;
+}
+
+void f2() {
+  int i, j, *k, lala = 42;
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: multiple declarations in a single statement reduces readability
+  // CHECK-FIXES: int i;
+  // CHECK-FIXES: {{^  }}int j;
+  // CHECK-FIXES: {{^  }}int *k;
+  // CHECK-FIXES: {{^  }}int lala = 42;
+
+  int normal, weird = /* comment */ 42;
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: multiple declarations in a single statement reduces readability
+  // CHECK-FIXES: int normal;
+  // CHECK-FIXES: {{^  }}int weird = /* comment */ 42;
+
+  int /* here is a comment */ v1,
+  // another comment
+  v2 = 42 // Ok, more comments
+  ;
+  // CHECK-MESSAGES: [[@LINE-4]]:3: warning: multiple declarations in a single statement reduces readability
+  // CHECK-FIXES: int /* here is a comment */ v1;
+  // CHECK-FIXES: {{^  }}int /* here is a comment */ // another comment
+  // CHECK-FIXES: {{^  }}v2 = 42 // Ok, more comments
+  // CHECK-FIXES: {{^  }};
+
+  auto int1 = 42, int2 = 0, int3 = 43;
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: multiple declarations in a single statement reduces readability
+  // CHECK-FIXES: auto int1 = 42;
+  // CHECK-FIXES: {{^  }}auto int2 = 0;
+  // CHECK-FIXES: {{^  }}auto int3 = 43;
+
+  decltype(auto) ptr1 = &int1, ptr2 = &int1;
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: multiple declarations in a single statement reduces readability
+  // CHECK-FIXES: decltype(auto) ptr1 = &int1;
+  // CHECK-FIXES: {{^  }}decltype(auto) ptr2 = &int1;
+
+  decltype(k) ptr3 = &int1, ptr4 = &int1;
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: multiple declarations in a single statement reduces readability
+  // CHECK-FIXES: decltype(k) ptr3 = &int1;
+  // CHECK-FIXES: {{^  }}decltype(k) ptr4 = &int1;
+}
+
+void f3() {
+  int i, *pointer1;
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: multiple declarations in a single statement reduces readability
+  // CHECK-FIXES: int i;
+  // CHECK-FIXES: {{^  }}int *pointer1;
+  //
+  int *pointer2 = nullptr, *pointer3 = &i;
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: multiple declarations in a single statement reduces readability
+  // CHECK-FIXES: int *pointer2 = nullptr;
+  // CHECK-FIXES: {{^  }}int *pointer3 = &i;
+
+  int *(i_ptr) = nullptr, *((i_ptr2));
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: multiple declarations in a single statement reduces readability
+  // CHECK-FIXES: int *(i_ptr) = nullptr;
+  // CHECK-FIXES: {{^  }}int *((i_ptr2));
+
+  float(*f_ptr)[42], (((f_value))) = 42;
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: multiple declarations in a single statement reduces readability
+  // CHECK-FIXES: float (*f_ptr)[42];
+  // CHECK-FIXES: {{^  }}float (((f_value))) = 42;
+
+  float(((*f_ptr2)))[42], ((*f_ptr3)), f_value2 = 42.f;
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: multiple declarations in a single statement reduces readability
+  // CHECK-FIXES: float (((*f_ptr2)))[42];
+  // CHECK-FIXES: {{^  }}float ((*f_ptr3));
+  // CHECK-FIXES: {{^  }}float f_value2 = 42.f;
+
+  float(((*f_ptr4)))[42], *f_ptr5, ((f_value3));
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: multiple declarations in a single statement reduces readability
+  // CHECK-FIXES: float (((*f_ptr4)))[42];
+  // CHECK-FIXES: {{^  }}float *f_ptr5;
+  // CHECK-FIXES: {{^  }}float ((f_value3));
+
+  void(((*f2))(int)), (*g2)(int, float);
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: multiple declarations in a single statement reduces readability
+  // CHECK-FIXES: void (((*f2))(int));
+  // CHECK-FIXES: {{^  }}void (*g2)(int, float);
+
+  float(*(*(*f_ptr6)))[42], (*f_ptr7);
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: multiple declarations in a single statement reduces readability
+  // CHECK-FIXES: float (*(*(*f_ptr6)))[42];
+  // CHECK-FIXES: {{^  }}float (*f_ptr7);
+}
+
+void f4() {
+  double d = 42. /* foo */, z = 43., /* hi */ y, c /* */ /*  */

[PATCH] D53780: Fix bitcast to address space cast for coerced load/stores

2018-10-26 Thread David Salinas via Phabricator via cfe-commits
david-salinas created this revision.
david-salinas added reviewers: yaxunl, scchan.
Herald added a subscriber: cfe-commits.

Coerced load/stores through memory do not take into account potential address 
space differences  when it creates its bitcasts.


Repository:
  rC Clang

https://reviews.llvm.org/D53780

Files:
  lib/CodeGen/CGCall.cpp
  test/CodeGenCXX/address-space-cast-coerce.cpp


Index: test/CodeGenCXX/address-space-cast-coerce.cpp
===
--- /dev/null
+++ test/CodeGenCXX/address-space-cast-coerce.cpp
@@ -0,0 +1,56 @@
+// RUN: %clang_cc1 %s -triple=amdgcn-amd-amdhsa -emit-llvm -o - | FileCheck %s
+
+template struct my_vector_base;
+
+template
+struct my_vector_base {
+typedef T Native_vec_ __attribute__((ext_vector_type(1)));
+
+union {
+Native_vec_ data;
+struct {
+T x;
+};
+};
+};
+
+template
+struct my_vector_type : public my_vector_base {
+using my_vector_base::data;
+using typename my_vector_base::Native_vec_;
+
+template< typename U>
+__attribute__((cpu)) __attribute__((hc))
+my_vector_type(U x) noexcept
+{
+for (auto i = 0u; i != rank; ++i) data[i] = x;
+}
+__attribute__((cpu)) __attribute__((hc))
+my_vector_type& operator+=(const my_vector_type& x) noexcept
+{
+data += x.data;
+return *this;
+}
+};
+
+template
+__attribute__((cpu)) __attribute__((hc))
+inline
+my_vector_type operator+(
+const my_vector_type& x, const my_vector_type& y) noexcept
+{
+return my_vector_type{x} += y;
+}
+
+using char1 = my_vector_type;
+
+int main() {
+
+char1 f1{1};
+char1 f2{1};
+
+// CHECK: %[[a:[^ ]+]] = addrspacecast i16 addrspace(5)* %{{[^ ]+}} to i16*
+// CHECK: %[[a:[^ ]+]] = addrspacecast %{{[^ ]+}} addrspace(5)* %{{[^ ]+}} to 
%{{[^ ]+}} 
+
+char1 f3 = f1 + f2;
+}
Index: lib/CodeGen/CGCall.cpp
===
--- lib/CodeGen/CGCall.cpp
+++ lib/CodeGen/CGCall.cpp
@@ -1253,8 +1253,8 @@
 
   // Otherwise do coercion through memory. This is stupid, but simple.
   Address Tmp = CreateTempAllocaForCoercion(CGF, Ty, Src.getAlignment());
-  Address Casted = CGF.Builder.CreateBitCast(Tmp, CGF.AllocaInt8PtrTy);
-  Address SrcCasted = CGF.Builder.CreateBitCast(Src, CGF.AllocaInt8PtrTy);
+  Address Casted = CGF.Builder.CreatePointerBitCastOrAddrSpaceCast(Tmp, 
CGF.AllocaInt8PtrTy);
+  Address SrcCasted = CGF.Builder.CreatePointerBitCastOrAddrSpaceCast(Src, 
CGF.AllocaInt8PtrTy);
   CGF.Builder.CreateMemCpy(Casted, SrcCasted,
   llvm::ConstantInt::get(CGF.IntPtrTy, SrcSize),
   false);
@@ -1335,8 +1335,8 @@
 // to that information.
 Address Tmp = CreateTempAllocaForCoercion(CGF, SrcTy, Dst.getAlignment());
 CGF.Builder.CreateStore(Src, Tmp);
-Address Casted = CGF.Builder.CreateBitCast(Tmp, CGF.AllocaInt8PtrTy);
-Address DstCasted = CGF.Builder.CreateBitCast(Dst, CGF.AllocaInt8PtrTy);
+Address Casted = CGF.Builder.CreatePointerBitCastOrAddrSpaceCast(Tmp, 
CGF.AllocaInt8PtrTy);
+Address DstCasted = CGF.Builder.CreatePointerBitCastOrAddrSpaceCast(Dst, 
CGF.AllocaInt8PtrTy);
 CGF.Builder.CreateMemCpy(DstCasted, Casted,
 llvm::ConstantInt::get(CGF.IntPtrTy, DstSize),
 false);


Index: test/CodeGenCXX/address-space-cast-coerce.cpp
===
--- /dev/null
+++ test/CodeGenCXX/address-space-cast-coerce.cpp
@@ -0,0 +1,56 @@
+// RUN: %clang_cc1 %s -triple=amdgcn-amd-amdhsa -emit-llvm -o - | FileCheck %s
+
+template struct my_vector_base;
+
+template
+struct my_vector_base {
+typedef T Native_vec_ __attribute__((ext_vector_type(1)));
+
+union {
+Native_vec_ data;
+struct {
+T x;
+};
+};
+};
+
+template
+struct my_vector_type : public my_vector_base {
+using my_vector_base::data;
+using typename my_vector_base::Native_vec_;
+
+template< typename U>
+__attribute__((cpu)) __attribute__((hc))
+my_vector_type(U x) noexcept
+{
+for (auto i = 0u; i != rank; ++i) data[i] = x;
+}
+__attribute__((cpu)) __attribute__((hc))
+my_vector_type& operator+=(const my_vector_type& x) noexcept
+{
+data += x.data;
+return *this;
+}
+};
+
+template
+__attribute__((cpu)) __attribute__((hc))
+inline
+my_vector_type operator+(
+const my_vector_type& x, const my_vector_type& y) noexcept
+{
+return my_vector_type{x} += y;
+}
+
+using char1 = my_vector_type;
+
+int main() {
+
+char1 f1{1};
+char1 f2{1};
+
+// CHECK: %[[a:[^ ]+]] = addrspacecast i16 addrspace(5)* %{{[^ ]+}} to i16*
+// CHECK: %[[a:[^ 

  1   2   >