[PATCH] D86412: [clang][Driver] Implement AddClangSystemIncludeArgs and HasNativeLLVMSupport for the OpenBSD clang driver.

2020-08-22 Thread Brad Smith via Phabricator via cfe-commits
brad added a comment.

Looks reasonable. I'm a little surprised I don't see this in the FreeBSD 
driver. What about FreeBSD, NetBSD and DragonFly?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86412/new/

https://reviews.llvm.org/D86412

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


[PATCH] D86412: [clang][Driver] Implement AddClangSystemIncludeArgs and HasNativeLLVMSupport for the OpenBSD clang driver.

2020-08-22 Thread dana koch via Phabricator via cfe-commits
3405691582 updated this revision to Diff 287238.
3405691582 added a comment.

Finally got the formatting fixed properly.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86412/new/

https://reviews.llvm.org/D86412

Files:
  clang/lib/Driver/ToolChains/OpenBSD.cpp
  clang/lib/Driver/ToolChains/OpenBSD.h


Index: clang/lib/Driver/ToolChains/OpenBSD.h
===
--- clang/lib/Driver/ToolChains/OpenBSD.h
+++ clang/lib/Driver/ToolChains/OpenBSD.h
@@ -65,6 +65,12 @@
 return ToolChain::CST_Libcxx;
   }
 
+  void
+  AddClangSystemIncludeArgs(const llvm::opt::ArgList ,
+llvm::opt::ArgStringList ) const override;
+
+  bool HasNativeLLVMSupport() const override;
+
   void AddCXXStdlibLibArgs(const llvm::opt::ArgList ,
llvm::opt::ArgStringList ) const override;
 
Index: clang/lib/Driver/ToolChains/OpenBSD.cpp
===
--- clang/lib/Driver/ToolChains/OpenBSD.cpp
+++ clang/lib/Driver/ToolChains/OpenBSD.cpp
@@ -10,10 +10,12 @@
 #include "Arch/Mips.h"
 #include "Arch/Sparc.h"
 #include "CommonArgs.h"
+#include "clang/Config/config.h"
 #include "clang/Driver/Compilation.h"
 #include "clang/Driver/Options.h"
 #include "clang/Driver/SanitizerArgs.h"
 #include "llvm/Option/ArgList.h"
+#include "llvm/Support/Path.h"
 
 using namespace clang::driver;
 using namespace clang::driver::tools;
@@ -276,3 +278,38 @@
   options::OPT_fno_use_init_array, false))
 CC1Args.push_back("-fno-use-init-array");
 }
+
+void OpenBSD::AddClangSystemIncludeArgs(
+const llvm::opt::ArgList ,
+llvm::opt::ArgStringList ) const {
+  const Driver  = getDriver();
+
+  if (DriverArgs.hasArg(clang::driver::options::OPT_nostdinc))
+return;
+
+  if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) {
+SmallString<128> Dir(D.ResourceDir);
+llvm::sys::path::append(Dir, "include");
+addSystemInclude(DriverArgs, CC1Args, Dir.str());
+  }
+
+  if (DriverArgs.hasArg(options::OPT_nostdlibinc))
+return;
+
+  // Check for configure-time C include directories.
+  StringRef CIncludeDirs(C_INCLUDE_DIRS);
+  if (CIncludeDirs != "") {
+SmallVector dirs;
+CIncludeDirs.split(dirs, ":");
+for (StringRef dir : dirs) {
+  StringRef Prefix =
+  llvm::sys::path::is_absolute(dir) ? StringRef(D.SysRoot) : "";
+  addExternCSystemInclude(DriverArgs, CC1Args, Prefix + dir);
+}
+return;
+  }
+
+  addExternCSystemInclude(DriverArgs, CC1Args, D.SysRoot + "/usr/include");
+}
+
+bool OpenBSD::HasNativeLLVMSupport() const { return true; }


Index: clang/lib/Driver/ToolChains/OpenBSD.h
===
--- clang/lib/Driver/ToolChains/OpenBSD.h
+++ clang/lib/Driver/ToolChains/OpenBSD.h
@@ -65,6 +65,12 @@
 return ToolChain::CST_Libcxx;
   }
 
+  void
+  AddClangSystemIncludeArgs(const llvm::opt::ArgList ,
+llvm::opt::ArgStringList ) const override;
+
+  bool HasNativeLLVMSupport() const override;
+
   void AddCXXStdlibLibArgs(const llvm::opt::ArgList ,
llvm::opt::ArgStringList ) const override;
 
Index: clang/lib/Driver/ToolChains/OpenBSD.cpp
===
--- clang/lib/Driver/ToolChains/OpenBSD.cpp
+++ clang/lib/Driver/ToolChains/OpenBSD.cpp
@@ -10,10 +10,12 @@
 #include "Arch/Mips.h"
 #include "Arch/Sparc.h"
 #include "CommonArgs.h"
+#include "clang/Config/config.h"
 #include "clang/Driver/Compilation.h"
 #include "clang/Driver/Options.h"
 #include "clang/Driver/SanitizerArgs.h"
 #include "llvm/Option/ArgList.h"
+#include "llvm/Support/Path.h"
 
 using namespace clang::driver;
 using namespace clang::driver::tools;
@@ -276,3 +278,38 @@
   options::OPT_fno_use_init_array, false))
 CC1Args.push_back("-fno-use-init-array");
 }
+
+void OpenBSD::AddClangSystemIncludeArgs(
+const llvm::opt::ArgList ,
+llvm::opt::ArgStringList ) const {
+  const Driver  = getDriver();
+
+  if (DriverArgs.hasArg(clang::driver::options::OPT_nostdinc))
+return;
+
+  if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) {
+SmallString<128> Dir(D.ResourceDir);
+llvm::sys::path::append(Dir, "include");
+addSystemInclude(DriverArgs, CC1Args, Dir.str());
+  }
+
+  if (DriverArgs.hasArg(options::OPT_nostdlibinc))
+return;
+
+  // Check for configure-time C include directories.
+  StringRef CIncludeDirs(C_INCLUDE_DIRS);
+  if (CIncludeDirs != "") {
+SmallVector dirs;
+CIncludeDirs.split(dirs, ":");
+for (StringRef dir : dirs) {
+  StringRef Prefix =
+  llvm::sys::path::is_absolute(dir) ? StringRef(D.SysRoot) : "";
+  addExternCSystemInclude(DriverArgs, CC1Args, Prefix + dir);
+}
+return;
+  }
+
+  addExternCSystemInclude(DriverArgs, CC1Args, D.SysRoot + "/usr/include");
+}
+
+bool 

[PATCH] D86412: [clang][Driver] Implement AddClangSystemIncludeArgs and HasNativeLLVMSupport for the OpenBSD clang driver.

2020-08-22 Thread dana koch via Phabricator via cfe-commits
3405691582 updated this revision to Diff 287237.
Herald added a subscriber: fedor.sergeev.

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86412/new/

https://reviews.llvm.org/D86412

Files:
  clang/lib/Driver/ToolChains/OpenBSD.cpp
  clang/lib/Driver/ToolChains/OpenBSD.h

Index: clang/lib/Driver/ToolChains/OpenBSD.h
===
--- clang/lib/Driver/ToolChains/OpenBSD.h
+++ clang/lib/Driver/ToolChains/OpenBSD.h
@@ -65,6 +65,12 @@
 return ToolChain::CST_Libcxx;
   }
 
+  void
+  AddClangSystemIncludeArgs(const llvm::opt::ArgList ,
+llvm::opt::ArgStringList ) const override;
+
+  bool HasNativeLLVMSupport() const override;
+
   void AddCXXStdlibLibArgs(const llvm::opt::ArgList ,
llvm::opt::ArgStringList ) const override;
 
Index: clang/lib/Driver/ToolChains/OpenBSD.cpp
===
--- clang/lib/Driver/ToolChains/OpenBSD.cpp
+++ clang/lib/Driver/ToolChains/OpenBSD.cpp
@@ -10,10 +10,12 @@
 #include "Arch/Mips.h"
 #include "Arch/Sparc.h"
 #include "CommonArgs.h"
+#include "clang/Config/config.h"
 #include "clang/Driver/Compilation.h"
 #include "clang/Driver/Options.h"
 #include "clang/Driver/SanitizerArgs.h"
 #include "llvm/Option/ArgList.h"
+#include "llvm/Support/Path.h"
 
 using namespace clang::driver;
 using namespace clang::driver::tools;
@@ -45,7 +47,8 @@
   case llvm::Triple::sparcel: {
 CmdArgs.push_back("-32");
 std::string CPU = getCPUName(Args, getToolChain().getTriple());
-CmdArgs.push_back(sparc::getSparcAsmModeForCPU(CPU, getToolChain().getTriple()));
+CmdArgs.push_back(
+sparc::getSparcAsmModeForCPU(CPU, getToolChain().getTriple()));
 AddAssemblerKPIC(getToolChain(), Args, CmdArgs);
 break;
   }
@@ -53,7 +56,8 @@
   case llvm::Triple::sparcv9: {
 CmdArgs.push_back("-64");
 std::string CPU = getCPUName(Args, getToolChain().getTriple());
-CmdArgs.push_back(sparc::getSparcAsmModeForCPU(CPU, getToolChain().getTriple()));
+CmdArgs.push_back(
+sparc::getSparcAsmModeForCPU(CPU, getToolChain().getTriple()));
 AddAssemblerKPIC(getToolChain(), Args, CmdArgs);
 break;
   }
@@ -170,9 +174,9 @@
 
   Args.AddAllArgs(CmdArgs, options::OPT_L);
   ToolChain.AddFilePathLibArgs(Args, CmdArgs);
-  Args.AddAllArgs(CmdArgs, {options::OPT_T_Group, options::OPT_e,
-options::OPT_s, options::OPT_t,
-options::OPT_Z_Flag, options::OPT_r});
+  Args.AddAllArgs(CmdArgs,
+  {options::OPT_T_Group, options::OPT_e, options::OPT_s,
+   options::OPT_t, options::OPT_Z_Flag, options::OPT_r});
 
   bool NeedsSanitizerDeps = addSanitizerRuntimes(ToolChain, Args, CmdArgs);
   bool NeedsXRayDeps = addXRayRuntime(ToolChain, Args, CmdArgs);
@@ -276,3 +280,38 @@
   options::OPT_fno_use_init_array, false))
 CC1Args.push_back("-fno-use-init-array");
 }
+
+void OpenBSD::AddClangSystemIncludeArgs(
+const llvm::opt::ArgList ,
+llvm::opt::ArgStringList ) const {
+  const Driver  = getDriver();
+
+  if (DriverArgs.hasArg(clang::driver::options::OPT_nostdinc))
+return;
+
+  if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) {
+SmallString<128> Dir(D.ResourceDir);
+llvm::sys::path::append(Dir, "include");
+addSystemInclude(DriverArgs, CC1Args, Dir.str());
+  }
+
+  if (DriverArgs.hasArg(options::OPT_nostdlibinc))
+return;
+
+  // Check for configure-time C include directories.
+  StringRef CIncludeDirs(C_INCLUDE_DIRS);
+  if (CIncludeDirs != "") {
+SmallVector dirs;
+CIncludeDirs.split(dirs, ":");
+for (StringRef dir : dirs) {
+  StringRef Prefix =
+  llvm::sys::path::is_absolute(dir) ? StringRef(D.SysRoot) : "";
+  addExternCSystemInclude(DriverArgs, CC1Args, Prefix + dir);
+}
+return;
+  }
+
+  addExternCSystemInclude(DriverArgs, CC1Args, D.SysRoot + "/usr/include");
+}
+
+bool OpenBSD::HasNativeLLVMSupport() const { return true; }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D86412: [clang][Driver] Implement AddClangSystemIncludeArgs and HasNativeLLVMSupport for the OpenBSD clang driver.

2020-08-22 Thread dana koch via Phabricator via cfe-commits
3405691582 created this revision.
3405691582 added a reviewer: brad.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
3405691582 requested review of this revision.

If not overridden, `AddClangSystemIncludeArgs`'s implementation is empty, so by 
default, no system include args are added to clang currently. This means clang 
invocations must include a manual `-I /usr/include` flag, which is inconsistent 
behavior. Therefore, override and implement this method to match. Some 
boilerplate is also borrowed for handling of the other driver flags.

While we are here, also override and enable `HasNativeLLVMSupport`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D86412

Files:
  clang/lib/Driver/ToolChains/OpenBSD.cpp
  clang/lib/Driver/ToolChains/OpenBSD.h


Index: clang/lib/Driver/ToolChains/OpenBSD.h
===
--- clang/lib/Driver/ToolChains/OpenBSD.h
+++ clang/lib/Driver/ToolChains/OpenBSD.h
@@ -65,6 +65,12 @@
 return ToolChain::CST_Libcxx;
   }
 
+  void
+  AddClangSystemIncludeArgs(const llvm::opt::ArgList ,
+llvm::opt::ArgStringList ) const override;
+
+  bool HasNativeLLVMSupport() const override;
+
   void AddCXXStdlibLibArgs(const llvm::opt::ArgList ,
llvm::opt::ArgStringList ) const override;
 
Index: clang/lib/Driver/ToolChains/OpenBSD.cpp
===
--- clang/lib/Driver/ToolChains/OpenBSD.cpp
+++ clang/lib/Driver/ToolChains/OpenBSD.cpp
@@ -10,10 +10,12 @@
 #include "Arch/Mips.h"
 #include "Arch/Sparc.h"
 #include "CommonArgs.h"
+#include "clang/Config/config.h"
 #include "clang/Driver/Compilation.h"
 #include "clang/Driver/Options.h"
 #include "clang/Driver/SanitizerArgs.h"
 #include "llvm/Option/ArgList.h"
+#include "llvm/Support/Path.h"
 
 using namespace clang::driver;
 using namespace clang::driver::tools;
@@ -276,3 +278,37 @@
   options::OPT_fno_use_init_array, false))
 CC1Args.push_back("-fno-use-init-array");
 }
+
+void OpenBSD::AddClangSystemIncludeArgs(const llvm::opt::ArgList ,
+llvm::opt::ArgStringList ) 
const {
+  const Driver  = getDriver();
+
+  if (DriverArgs.hasArg(clang::driver::options::OPT_nostdinc))
+return;
+
+  if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) {
+SmallString<128> Dir(D.ResourceDir);
+llvm::sys::path::append(Dir, "include");
+addSystemInclude(DriverArgs, CC1Args, Dir.str());
+  }
+
+  if (DriverArgs.hasArg(options::OPT_nostdlibinc))
+return;
+
+  // Check for configure-time C include directories.
+  StringRef CIncludeDirs(C_INCLUDE_DIRS);
+  if (CIncludeDirs != "") {
+SmallVector dirs;
+CIncludeDirs.split(dirs, ":");
+for (StringRef dir : dirs) {
+  StringRef Prefix =
+  llvm::sys::path::is_absolute(dir) ? StringRef(D.SysRoot) : "";
+  addExternCSystemInclude(DriverArgs, CC1Args, Prefix + dir);
+}
+return;
+  }
+
+  addExternCSystemInclude(DriverArgs, CC1Args, D.SysRoot + "/usr/include");
+}
+
+bool OpenBSD::HasNativeLLVMSupport() const { return true; }


Index: clang/lib/Driver/ToolChains/OpenBSD.h
===
--- clang/lib/Driver/ToolChains/OpenBSD.h
+++ clang/lib/Driver/ToolChains/OpenBSD.h
@@ -65,6 +65,12 @@
 return ToolChain::CST_Libcxx;
   }
 
+  void
+  AddClangSystemIncludeArgs(const llvm::opt::ArgList ,
+llvm::opt::ArgStringList ) const override;
+
+  bool HasNativeLLVMSupport() const override;
+
   void AddCXXStdlibLibArgs(const llvm::opt::ArgList ,
llvm::opt::ArgStringList ) const override;
 
Index: clang/lib/Driver/ToolChains/OpenBSD.cpp
===
--- clang/lib/Driver/ToolChains/OpenBSD.cpp
+++ clang/lib/Driver/ToolChains/OpenBSD.cpp
@@ -10,10 +10,12 @@
 #include "Arch/Mips.h"
 #include "Arch/Sparc.h"
 #include "CommonArgs.h"
+#include "clang/Config/config.h"
 #include "clang/Driver/Compilation.h"
 #include "clang/Driver/Options.h"
 #include "clang/Driver/SanitizerArgs.h"
 #include "llvm/Option/ArgList.h"
+#include "llvm/Support/Path.h"
 
 using namespace clang::driver;
 using namespace clang::driver::tools;
@@ -276,3 +278,37 @@
   options::OPT_fno_use_init_array, false))
 CC1Args.push_back("-fno-use-init-array");
 }
+
+void OpenBSD::AddClangSystemIncludeArgs(const llvm::opt::ArgList ,
+llvm::opt::ArgStringList ) const {
+  const Driver  = getDriver();
+
+  if (DriverArgs.hasArg(clang::driver::options::OPT_nostdinc))
+return;
+
+  if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) {
+SmallString<128> Dir(D.ResourceDir);
+llvm::sys::path::append(Dir, "include");
+addSystemInclude(DriverArgs, CC1Args, Dir.str());
+  }
+
+  if 

[libunwind] 3c1b2e3 - [libunwind] Make findUnwindSectionsByPhdr static

2020-08-22 Thread Ryan Prichard via cfe-commits

Author: Ryan Prichard
Date: 2020-08-22T17:12:52-07:00
New Revision: 3c1b2e338dfdf4f305b1cb40e2ebcb93a7e470c3

URL: 
https://github.com/llvm/llvm-project/commit/3c1b2e338dfdf4f305b1cb40e2ebcb93a7e470c3
DIFF: 
https://github.com/llvm/llvm-project/commit/3c1b2e338dfdf4f305b1cb40e2ebcb93a7e470c3.diff

LOG: [libunwind] Make findUnwindSectionsByPhdr static

Currently, this function is present in the dynsym table of
libunwind.so (on ELF targets). Make the function static instead.

In the previous release (LLVM 10.x), this function was instead a lambda
function inside LocalAddressSpace::findUnwindSections, and because
LocalAddressSpace was marked with _LIBUNWIND_HIDDEN, the lambda
function was also a hidden symbol.

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

Added: 


Modified: 
libunwind/src/AddressSpace.hpp

Removed: 




diff  --git a/libunwind/src/AddressSpace.hpp b/libunwind/src/AddressSpace.hpp
index 2443bd761cc4..b3949b2d27a4 100644
--- a/libunwind/src/AddressSpace.hpp
+++ b/libunwind/src/AddressSpace.hpp
@@ -432,8 +432,8 @@ static bool checkAddrInSegment(const Elf_Phdr *phdr, size_t 
image_base,
   return false;
 }
 
-int findUnwindSectionsByPhdr(struct dl_phdr_info *pinfo, size_t pinfo_size,
- void *data) {
+static int findUnwindSectionsByPhdr(struct dl_phdr_info *pinfo,
+size_t pinfo_size, void *data) {
   auto cbdata = static_cast(data);
   if (pinfo->dlpi_phnum == 0 || cbdata->targetAddr < pinfo->dlpi_addr)
 return 0;
@@ -482,7 +482,8 @@ int findUnwindSectionsByPhdr(struct dl_phdr_info *pinfo, 
size_t pinfo_size,
 // Given all the #ifdef's above, the code here is for
 // defined(LIBUNWIND_ARM_EHABI)
 
-int findUnwindSectionsByPhdr(struct dl_phdr_info *pinfo, size_t, void *data) {
+static int findUnwindSectionsByPhdr(struct dl_phdr_info *pinfo, size_t,
+void *data) {
   auto *cbdata = static_cast(data);
   bool found_obj = false;
   bool found_hdr = false;



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


[PATCH] D86398: [X86] Enable constexpr on _cast fp<-> uint intrinsics (PR31446)

2020-08-22 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith accepted this revision.
rsmith added a comment.

It would be useful to include in our documentation a brief list of which of 
these intrinsics can be used in constant expressions.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86398/new/

https://reviews.llvm.org/D86398

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


[clang] cc7bf9b - [X86] Allow 32-bit mode only CPUs with -mtune on 64-bit targets

2020-08-22 Thread Craig Topper via cfe-commits

Author: Craig Topper
Date: 2020-08-22T16:38:05-07:00
New Revision: cc7bf9bcbfbc8d8188d9fe540c2bc1aee23824af

URL: 
https://github.com/llvm/llvm-project/commit/cc7bf9bcbfbc8d8188d9fe540c2bc1aee23824af
DIFF: 
https://github.com/llvm/llvm-project/commit/cc7bf9bcbfbc8d8188d9fe540c2bc1aee23824af.diff

LOG: [X86] Allow 32-bit mode only CPUs with -mtune on 64-bit targets

gcc errors on this, but I'm nervous that since -mtune has been
ignored by clang for so long that there may be code bases out
there that pass 32-bit cpus to clang.

Added: 


Modified: 
clang/include/clang/Basic/TargetInfo.h
clang/lib/Basic/Targets.cpp
clang/lib/Basic/Targets/X86.cpp
clang/lib/Basic/Targets/X86.h
clang/test/Driver/x86-mtune.c
clang/test/Misc/target-invalid-cpu-note.c
llvm/include/llvm/Support/X86TargetParser.h

Removed: 




diff  --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index 9c65ca18632a..7253b5ea9abe 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -1143,11 +1143,22 @@ class TargetInfo : public virtual 
TransferrableTargetInfo,
   /// Fill a SmallVectorImpl with the valid values to setCPU.
   virtual void fillValidCPUList(SmallVectorImpl ) const {}
 
+  /// Fill a SmallVectorImpl with the valid values for tuning CPU.
+  virtual void fillValidTuneCPUList(SmallVectorImpl ) const {
+fillValidCPUList(Values);
+  }
+
   /// brief Determine whether this TargetInfo supports the given CPU name.
   virtual bool isValidCPUName(StringRef Name) const {
 return true;
   }
 
+  /// brief Determine whether this TargetInfo supports the given CPU name for
+  // tuning.
+  virtual bool isValidTuneCPUName(StringRef Name) const {
+return isValidCPUName(Name);
+  }
+
   /// brief Determine whether this TargetInfo supports tune in target 
attribute.
   virtual bool supportsTargetAttributeTune() const {
 return false;

diff  --git a/clang/lib/Basic/Targets.cpp b/clang/lib/Basic/Targets.cpp
index 50a3b0e83a56..38a388afa534 100644
--- a/clang/lib/Basic/Targets.cpp
+++ b/clang/lib/Basic/Targets.cpp
@@ -655,10 +655,11 @@ TargetInfo::CreateTargetInfo(DiagnosticsEngine ,
   }
 
   // Check the TuneCPU name if specified.
-  if (!Opts->TuneCPU.empty() && !Target->isValidCPUName(Opts->TuneCPU)) {
+  if (!Opts->TuneCPU.empty() &&
+  !Target->isValidTuneCPUName(Opts->TuneCPU)) {
 Diags.Report(diag::err_target_unknown_cpu) << Opts->TuneCPU;
 SmallVector ValidList;
-Target->fillValidCPUList(ValidList);
+Target->fillValidTuneCPUList(ValidList);
 if (!ValidList.empty())
   Diags.Report(diag::note_valid_options) << llvm::join(ValidList, ", ");
 return nullptr;

diff  --git a/clang/lib/Basic/Targets/X86.cpp b/clang/lib/Basic/Targets/X86.cpp
index 8b8f7d43b277..64c7ce9182c9 100644
--- a/clang/lib/Basic/Targets/X86.cpp
+++ b/clang/lib/Basic/Targets/X86.cpp
@@ -1436,6 +1436,10 @@ void 
X86TargetInfo::fillValidCPUList(SmallVectorImpl ) const {
   llvm::X86::fillValidCPUArchList(Values, Only64Bit);
 }
 
+void X86TargetInfo::fillValidTuneCPUList(SmallVectorImpl ) 
const {
+  llvm::X86::fillValidCPUArchList(Values);
+}
+
 ArrayRef X86TargetInfo::getGCCRegNames() const {
   return llvm::makeArrayRef(GCCRegNames);
 }

diff  --git a/clang/lib/Basic/Targets/X86.h b/clang/lib/Basic/Targets/X86.h
index 754aae3ebbf3..853c4e621222 100644
--- a/clang/lib/Basic/Targets/X86.h
+++ b/clang/lib/Basic/Targets/X86.h
@@ -305,7 +305,15 @@ class LLVM_LIBRARY_VISIBILITY X86TargetInfo : public 
TargetInfo {
 return llvm::X86::parseArchX86(Name, Only64Bit) != llvm::X86::CK_None;
   }
 
+  bool isValidTuneCPUName(StringRef Name) const override {
+// Allow 32-bit only CPUs regardless of 64-bit mode unlike isValidCPUName.
+// NOTE: gcc rejects 32-bit mtune CPUs in 64-bit mode. But being lenient
+// since mtune was ignored by clang for so long.
+return llvm::X86::parseArchX86(Name) != llvm::X86::CK_None;
+  }
+
   void fillValidCPUList(SmallVectorImpl ) const override;
+  void fillValidTuneCPUList(SmallVectorImpl ) const override;
 
   bool setCPU(const std::string ) override {
 bool Only64Bit = getTriple().getArch() != llvm::Triple::x86;

diff  --git a/clang/test/Driver/x86-mtune.c b/clang/test/Driver/x86-mtune.c
index 65ac1a510eec..731c580afc48 100644
--- a/clang/test/Driver/x86-mtune.c
+++ b/clang/test/Driver/x86-mtune.c
@@ -3,3 +3,18 @@
 // RUN: %clang -target x86_64-unknown-unknown -c -### %s -mtune=nocona 2>&1 \
 // RUN:   | FileCheck %s -check-prefix=nocona
 // nocona: "-tune-cpu" "nocona"
+
+// Unlike march we allow 32-bit only cpus with mtune.
+
+// RUN: %clang -target x86_64-unknown-unknown -c -### %s -mtune=i686 2>&1 \
+// RUN:   | FileCheck %s -check-prefix=i686
+// i686: "-tune-cpu" "i686"
+
+// RUN: %clang -target x86_64-unknown-unknown -c -### %s -mtune=pentium4 2>&1 \
+// RUN:   | FileCheck %s 

[PATCH] D85097: [Sema] add warning for comparisons like 'x<=y<=z'

2020-08-22 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 added inline comments.



Comment at: clang/test/Sema/warn-compare-op-parentheses.c:49
+  b = p1 > p2 < p3;
+  // expected-warning@-1 {{comparisons like 'x<=y<=z' are interpreted as 
'(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-2 {{place parentheses around the '>' comparison to silence 
this warning}}

Not very user friendly warning text..


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D85097/new/

https://reviews.llvm.org/D85097

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


[PATCH] D86398: [X86] Enable constexpr on _cast fp<-> uint intrinsics (PR31446)

2020-08-22 Thread Craig Topper via Phabricator via cfe-commits
craig.topper accepted this revision.
craig.topper added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86398/new/

https://reviews.llvm.org/D86398

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


[PATCH] D85097: [Sema] add warning for comparisons like 'x<=y<=z'

2020-08-22 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

In D85097#2201609 , @vabridgers wrote:

> Thanks for the recent comments. I just pushed a few improvements over the 
> last patch that didn't comprehend latest comments from @rsmith and 
> @Quuxplusone. I'll read through those carefully and address those.

Reverse-ping, thanks. I think this is a worthwhile warning.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D85097/new/

https://reviews.llvm.org/D85097

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


[libunwind] 542db87 - [libunwind] Ensure enough alignment for unw_cursor_t for SEH build configurations

2020-08-22 Thread Martin Storsjö via cfe-commits

Author: Martin Storsjö
Date: 2020-08-22T22:48:57+03:00
New Revision: 542db87f1ac67087aeb5cf572b1f9744d482da69

URL: 
https://github.com/llvm/llvm-project/commit/542db87f1ac67087aeb5cf572b1f9744d482da69
DIFF: 
https://github.com/llvm/llvm-project/commit/542db87f1ac67087aeb5cf572b1f9744d482da69.diff

LOG: [libunwind] Ensure enough alignment for unw_cursor_t for SEH build 
configurations

When built in SEH mode, UnwindCursor contains a CONTEXT struct,
which is aligned to 16 bytes in most configurations, causing the
whole UnwindCursor object to have 16 byte alignment.

This fixes backtraces using _Unwind_Backtrace on x86_64 mingw,
where an unw_cursor_t allocated on the stack was misaligned before.

This is an ABI break for this struct for this configuration, but very
few callers call libunwind directly (and even fewer directly allocate
an unw_cursor_t anyway).

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

Added: 


Modified: 
libunwind/include/libunwind.h
libunwind/src/UnwindCursor.hpp

Removed: 




diff  --git a/libunwind/include/libunwind.h b/libunwind/include/libunwind.h
index 23ef47f4ac83..6ec649a460b8 100644
--- a/libunwind/include/libunwind.h
+++ b/libunwind/include/libunwind.h
@@ -43,6 +43,12 @@
   #define LIBUNWIND_AVAIL
 #endif
 
+#if defined(_WIN32) && defined(__SEH__)
+  #define LIBUNWIND_CURSOR_ALIGNMENT_ATTR __attribute__((__aligned__(16)))
+#else
+  #define LIBUNWIND_CURSOR_ALIGNMENT_ATTR
+#endif
+
 /* error codes */
 enum {
   UNW_ESUCCESS  = 0, /* no error */
@@ -68,7 +74,7 @@ typedef struct unw_context_t unw_context_t;
 
 struct unw_cursor_t {
   uint64_t data[_LIBUNWIND_CURSOR_SIZE];
-};
+} LIBUNWIND_CURSOR_ALIGNMENT_ATTR;
 typedef struct unw_cursor_t unw_cursor_t;
 
 typedef struct unw_addr_space *unw_addr_space_t;

diff  --git a/libunwind/src/UnwindCursor.hpp b/libunwind/src/UnwindCursor.hpp
index 03e21fb87a8d..54913360ca29 100644
--- a/libunwind/src/UnwindCursor.hpp
+++ b/libunwind/src/UnwindCursor.hpp
@@ -530,6 +530,8 @@ UnwindCursor::UnwindCursor(unw_context_t *context, A 
)
 : _addressSpace(as), _unwindInfoMissing(false) {
   static_assert((check_fit, unw_cursor_t>::does_fit),
 "UnwindCursor<> does not fit in unw_cursor_t");
+  static_assert((alignof(UnwindCursor) <= alignof(unw_cursor_t)),
+"UnwindCursor<> requires more alignment than unw_cursor_t");
   memset(&_info, 0, sizeof(_info));
   memset(&_histTable, 0, sizeof(_histTable));
   _dispContext.ContextRecord = &_msContext;
@@ -1182,6 +1184,8 @@ UnwindCursor::UnwindCursor(unw_context_t *context, 
A )
   _isSignalFrame(false) {
   static_assert((check_fit, unw_cursor_t>::does_fit),
 "UnwindCursor<> does not fit in unw_cursor_t");
+  static_assert((alignof(UnwindCursor) <= alignof(unw_cursor_t)),
+"UnwindCursor<> requires more alignment than unw_cursor_t");
   memset(&_info, 0, sizeof(_info));
 }
 



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


[PATCH] D80197: [DebugInfo] Upgrade DISubrange to support Fortran dynamic arrays

2020-08-22 Thread Josh Stone via Phabricator via cfe-commits
cuviper added inline comments.



Comment at: llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp:1595
 const DISubrange *Subrange = cast(Element);
-assert(Subrange->getLowerBound() == 0 &&
+assert(!Subrange->getRawLowerBound() &&
"codeview doesn't support subranges with lower bounds");

Please see [[ https://bugs.llvm.org/show_bug.cgi?id=47287 | bug 47287 ]] on 
this.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D80197/new/

https://reviews.llvm.org/D80197

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


[PATCH] D85528: [analyzer] Fix cast evaluation on scoped enums in ExprEngine

2020-08-22 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun added a comment.

In D85528#2229309 , @steakhal wrote:

> It would be nice to have this fix in clang11.
> Do you think it's qualified for it?

Unfortunately, this is not a fix only change. This is a fix for refutation, but 
also a behavioral change for the default settings (so for most users). With 
this little time left until release, I would be uncomfortable landing a 
behavioral change. I'm not opposed to landing this to master, as we will have 
more time there to see whether there are any unwanted side effects in practice.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D85528/new/

https://reviews.llvm.org/D85528

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


[PATCH] D86295: [analyzer] Reorder the layout of MemRegion and cache by hand for optimal size

2020-08-22 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added a comment.

In D86295#2231760 , @NoQ wrote:

> I mean, like, you can measure the entire process with `time` or something 
> like that. I believe @vsavchenko's docker thingy already knows how to do that.

I tried to measure this with `time`, without much luck:
F12735724: time-verbose-results.txt 

> What i'm trying to say is that for almost every region //R// it's a trivial 
> O(1) operation that yields `RegionOffset` (//R//, +0). It is only non-trivial 
> for non-base regions like `FieldRegion` or `ElementRegion` or, well, 
> `CXXBaseObjectRegion`.

What should be my next step?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86295/new/

https://reviews.llvm.org/D86295

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


[PATCH] D86223: [analyzer][z3] Use more elaborate z3 variable names in debug build

2020-08-22 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added inline comments.



Comment at: clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConv.h:335
+llvm::raw_svector_ostream OS(Str);
+OS << PRETTY_SYMBOL_KIND << ID;
+#undef PRETTY_SYMBOL_KIND

xazax.hun wrote:
> Maybe, in this case, it is cleaner to duplicate the line rather than 
> introduce `PRETTY_SYMBOL_KIND`?
Thanks.



Comment at: clang/test/Analysis/z3/pretty-dump.c:15
+// CHECK: "constraints": [
+// CHECK-NEXT: { "symbol": "(reg_$[[#]]) == 3", "range": "(= 
reg_$[[#]] #x0003)" }
+  }

xazax.hun wrote:
> Will this test case work with non-debug builds? 
Fixed.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86223/new/

https://reviews.llvm.org/D86223

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


[PATCH] D86223: [analyzer][z3] Use more elaborate z3 variable names in debug build

2020-08-22 Thread Balázs Benics via Phabricator via cfe-commits
steakhal updated this revision to Diff 287197.
steakhal marked 2 inline comments as done.
steakhal edited the summary of this revision.
steakhal added a comment.

In D86223#2231959 , @mikhail.ramalho 
wrote:

> I don't mind having it for release builds as well, why are you applying it 
> only for debug builds?

It might introduce a slight overhead since Z3 will parse longer the symbol 
names.

---

Diff update:

- Simplify macro usage.
- Introduce the `llvm_enable_dump` lit test requires clause.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86223/new/

https://reviews.llvm.org/D86223

Files:
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConv.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/SymExpr.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h
  clang/lib/StaticAnalyzer/Core/SymbolManager.cpp
  clang/test/Analysis/z3/pretty-dump.c
  clang/test/lit.cfg.py
  clang/test/lit.site.cfg.py.in

Index: clang/test/lit.site.cfg.py.in
===
--- clang/test/lit.site.cfg.py.in
+++ clang/test/lit.site.cfg.py.in
@@ -12,6 +12,7 @@
 config.clang_obj_root = path(r"@CLANG_BINARY_DIR@")
 config.clang_src_dir = path(r"@CLANG_SOURCE_DIR@")
 config.clang_tools_dir = path(r"@CLANG_TOOLS_DIR@")
+config.llvm_enable_dump = "@LLVM_ENABLE_DUMP@"
 config.host_triple = "@LLVM_HOST_TRIPLE@"
 config.target_triple = "@TARGET_TRIPLE@"
 config.host_cxx = "@CMAKE_CXX_COMPILER@"
Index: clang/test/lit.cfg.py
===
--- clang/test/lit.cfg.py
+++ clang/test/lit.cfg.py
@@ -68,6 +68,10 @@
 'clang-extdef-mapping'), unresolved='ignore'),
 ]
 
+llvm_enable_dump = getattr(config, 'llvm_enable_dump', None)
+if llvm_enable_dump:
+config.available_features.add('llvm_enable_dump')
+
 if config.clang_examples:
 config.available_features.add('examples')
 tools.append('clang-interpreter')
Index: clang/test/Analysis/z3/pretty-dump.c
===
--- /dev/null
+++ clang/test/Analysis/z3/pretty-dump.c
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 -analyze -analyzer-constraints=z3 -setup-static-analyzer \
+// RUN:   -analyzer-checker=core,debug.ExprInspection %s 2>&1 | FileCheck %s
+//
+// REQUIRES: llvm_enable_dump, z3
+//
+// Works only with the z3 constraint manager.
+
+void clang_analyzer_printState();
+
+void foo(int x) {
+  if (x == 3) {
+clang_analyzer_printState();
+(void)x;
+// CHECK: "constraints": [
+// CHECK-NEXT: { "symbol": "(reg_$[[#]]) == 3", "range": "(= reg_$[[#]] #x0003)" }
+  }
+}
Index: clang/lib/StaticAnalyzer/Core/SymbolManager.cpp
===
--- clang/lib/StaticAnalyzer/Core/SymbolManager.cpp
+++ clang/lib/StaticAnalyzer/Core/SymbolManager.cpp
@@ -34,6 +34,12 @@
 
 void SymExpr::anchor() {}
 
+StringRef SymbolConjured::getKindStr() const { return "conj_$"; }
+StringRef SymbolDerived::getKindStr() const { return "derived_$"; }
+StringRef SymbolExtent::getKindStr() const { return "extent_$"; }
+StringRef SymbolMetadata::getKindStr() const { return "meta_$"; }
+StringRef SymbolRegionValue::getKindStr() const { return "reg_$"; }
+
 LLVM_DUMP_METHOD void SymExpr::dump() const { dumpToStream(llvm::errs()); }
 
 void BinarySymExpr::dumpToStreamImpl(raw_ostream , const SymExpr *Sym) {
@@ -64,7 +70,7 @@
 }
 
 void SymbolConjured::dumpToStream(raw_ostream ) const {
-  os << "conj_$" << getSymbolID() << '{' << T.getAsString() << ", LC"
+  os << getKindStr() << getSymbolID() << '{' << T.getAsString() << ", LC"
  << LCtx->getID();
   if (S)
 os << ", S" << S->getID(LCtx->getDecl()->getASTContext());
@@ -74,24 +80,24 @@
 }
 
 void SymbolDerived::dumpToStream(raw_ostream ) const {
-  os << "derived_$" << getSymbolID() << '{'
- << getParentSymbol() << ',' << getRegion() << '}';
+  os << getKindStr() << getSymbolID() << '{' << getParentSymbol() << ','
+ << getRegion() << '}';
 }
 
 void SymbolExtent::dumpToStream(raw_ostream ) const {
-  os << "extent_$" << getSymbolID() << '{' << getRegion() << '}';
+  os << getKindStr() << getSymbolID() << '{' << getRegion() << '}';
 }
 
 void SymbolMetadata::dumpToStream(raw_ostream ) const {
-  os << "meta_$" << getSymbolID() << '{'
- << getRegion() << ',' << T.getAsString() << '}';
+  os << getKindStr() << getSymbolID() << '{' << getRegion() << ','
+ << T.getAsString() << '}';
 }
 
 void SymbolData::anchor() {}
 
 void SymbolRegionValue::dumpToStream(raw_ostream ) const {
-  os << "reg_$" << getSymbolID()
- << '<' << getType().getAsString() << ' ' << R << '>';
+  os << getKindStr() << getSymbolID() << '<' << getType().getAsString() << ' '
+ << R << '>';
 }
 
 bool SymExpr::symbol_iterator::operator==(const 

[PATCH] D86400: [NFC][compiler-rt] Factor out __div[sdt]i3 and __mod[dt]i3 implementations

2020-08-22 Thread Anatoly Trosinenko via Phabricator via cfe-commits
atrosinenko created this revision.
atrosinenko added reviewers: MaskRay, aykevl, uabelho.
Herald added subscribers: Sanitizers, dberris.
Herald added a project: Sanitizers.
atrosinenko requested review of this revision.

An attempt was made to generically recreate these functions as close to the 
original implementations as possible to reduce possibility of performance any 
regression.

This patch is intended to simplify implementation of 16-bit integer 
division/multiplication LibCalls required on 16-bit targets and fixing some UB.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D86400

Files:
  compiler-rt/lib/builtins/divdi3.c
  compiler-rt/lib/builtins/divsi3.c
  compiler-rt/lib/builtins/divti3.c
  compiler-rt/lib/builtins/int_div_impl.inc
  compiler-rt/lib/builtins/moddi3.c
  compiler-rt/lib/builtins/modti3.c

Index: compiler-rt/lib/builtins/modti3.c
===
--- compiler-rt/lib/builtins/modti3.c
+++ compiler-rt/lib/builtins/modti3.c
@@ -16,15 +16,11 @@
 
 // Returns: a % b
 
-COMPILER_RT_ABI ti_int __modti3(ti_int a, ti_int b) {
-  const int bits_in_tword_m1 = (int)(sizeof(ti_int) * CHAR_BIT) - 1;
-  ti_int s = b >> bits_in_tword_m1; // s = b < 0 ? -1 : 0
-  b = (b ^ s) - s;  // negate if s == -1
-  s = a >> bits_in_tword_m1;// s = a < 0 ? -1 : 0
-  a = (a ^ s) - s;  // negate if s == -1
-  tu_int r;
-  __udivmodti4(a, b, );
-  return ((ti_int)r ^ s) - s; // negate if s == -1
-}
+#define fixint_t ti_int
+#define fixuint_t tu_int
+#define ASSIGN_UMOD(res, a, b) __udivmodti4((a), (b), &(res))
+#include "int_div_impl.inc"
+
+COMPILER_RT_ABI ti_int __modti3(ti_int a, ti_int b) { return __modXi3(a, b); }
 
 #endif // CRT_HAS_128BIT
Index: compiler-rt/lib/builtins/moddi3.c
===
--- compiler-rt/lib/builtins/moddi3.c
+++ compiler-rt/lib/builtins/moddi3.c
@@ -14,13 +14,9 @@
 
 // Returns: a % b
 
-COMPILER_RT_ABI di_int __moddi3(di_int a, di_int b) {
-  const int bits_in_dword_m1 = (int)(sizeof(di_int) * CHAR_BIT) - 1;
-  di_int s = b >> bits_in_dword_m1; // s = b < 0 ? -1 : 0
-  b = (b ^ s) - s;  // negate if s == -1
-  s = a >> bits_in_dword_m1;// s = a < 0 ? -1 : 0
-  a = (a ^ s) - s;  // negate if s == -1
-  du_int r;
-  __udivmoddi4(a, b, );
-  return ((di_int)r ^ s) - s; // negate if s == -1
-}
+#define fixint_t di_int
+#define fixuint_t du_int
+#define ASSIGN_UMOD(res, a, b) __udivmoddi4((a), (b), &(res))
+#include "int_div_impl.inc"
+
+COMPILER_RT_ABI di_int __moddi3(di_int a, di_int b) { return __modXi3(a, b); }
Index: compiler-rt/lib/builtins/int_div_impl.inc
===
--- compiler-rt/lib/builtins/int_div_impl.inc
+++ compiler-rt/lib/builtins/int_div_impl.inc
@@ -68,3 +68,28 @@
   }
   return r;
 }
+
+#ifdef COMPUTE_UDIV
+static __inline fixint_t __divXi3(fixint_t a, fixint_t b) {
+  const int N = (int)(sizeof(fixint_t) * CHAR_BIT) - 1;
+  fixint_t s_a = a >> N;   // s_a = a < 0 ? -1 : 0
+  fixint_t s_b = b >> N;   // s_b = b < 0 ? -1 : 0
+  a = (a ^ s_a) - s_a; // negate if s_a == -1
+  b = (b ^ s_b) - s_b; // negate if s_b == -1
+  s_a ^= s_b;  // sign of quotient
+  return (COMPUTE_UDIV(a, b) ^ s_a) - s_a; // negate if s_a == -1
+}
+#endif // COMPUTE_UDIV
+
+#ifdef ASSIGN_UMOD
+static __inline fixint_t __modXi3(fixint_t a, fixint_t b) {
+  const int N = (int)(sizeof(fixint_t) * CHAR_BIT) - 1;
+  fixint_t s = b >> N;// s = b < 0 ? -1 : 0
+  b = (b ^ s) - s;// negate if s == -1
+  s = a >> N; // s = a < 0 ? -1 : 0
+  a = (a ^ s) - s;// negate if s == -1
+  fixuint_t res;
+  ASSIGN_UMOD(res, a, b);
+  return (res ^ s) - s;   // negate if s == -1
+}
+#endif // ASSIGN_UMOD
Index: compiler-rt/lib/builtins/divti3.c
===
--- compiler-rt/lib/builtins/divti3.c
+++ compiler-rt/lib/builtins/divti3.c
@@ -16,14 +16,11 @@
 
 // Returns: a / b
 
-COMPILER_RT_ABI ti_int __divti3(ti_int a, ti_int b) {
-  const int bits_in_tword_m1 = (int)(sizeof(ti_int) * CHAR_BIT) - 1;
-  ti_int s_a = a >> bits_in_tword_m1;   // s_a = a < 0 ? -1 : 0
-  ti_int s_b = b >> bits_in_tword_m1;   // s_b = b < 0 ? -1 : 0
-  a = (a ^ s_a) - s_a;  // negate if s_a == -1
-  b = (b ^ s_b) - s_b;  // negate if s_b == -1
-  s_a ^= s_b;   // sign of quotient
-  return (__udivmodti4(a, b, (tu_int *)0) ^ s_a) - s_a; // negate if s_a == -1
-}
+#define fixint_t ti_int
+#define fixuint_t tu_int
+#define COMPUTE_UDIV(a, b) __udivmodti4((a), (b), (tu_int *)0)
+#include "int_div_impl.inc"
+
+COMPILER_RT_ABI ti_int __divti3(ti_int a, ti_int b) { return 

[PATCH] D86293: [analyzer] Add modeling of Eq operator in smart ptr

2020-08-22 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp:351
 
+bool SmartPtrModeling::handleEqOp(const CallEvent ,
+  CheckerContext ) const {

I'd prefer to call this AssignOp to avoid confusion with `==`. While your 
naming is correct, I always found this nomenclature confusing.



Comment at: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp:384
+
+  const auto *ArgRegionVal = State->get(ArgRegion);
+  if (ArgRegionVal) {

I also find the names of the variables confusing.

Instead of `ArgRegion` what about `OtherSmartPtrRegion`?
Instead of `ArgRegionVal` what about `OtherInnerPtr`?



Comment at: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp:391
+
+C.addTransition(State, C.getNoteTag([ThisRegion, ArgRegion, IsArgValNull](
+PathSensitiveBugReport ,

Adding return after every `addTransition` is a good practive that we should 
follow.



Comment at: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp:419
+llvm::raw_ostream ) {
+  if (() != smartptr::getNullDereferenceBugType() ||
+  !BR.isInteresting(ArgRegion))

Isn't this the same as the beginning of the note tag above?

I wonder if there is a way to deduplicate this code. Not a huge priority though 
as I do not have an immediate idea for doing this in a clean way.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86293/new/

https://reviews.llvm.org/D86293

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


[PATCH] D86223: [analyzer][z3] Use more elaborate z3 variable names in debug build

2020-08-22 Thread Mikhail Ramalho via Phabricator via cfe-commits
mikhail.ramalho added a comment.

I don't mind having it for release builds as well, why are you applying it only 
for debug builds?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86223/new/

https://reviews.llvm.org/D86223

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


[PATCH] D86027: [analyzer] Add bool operator modeling for unque_ptr

2020-08-22 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun requested changes to this revision.
xazax.hun added a comment.
This revision now requires changes to proceed.

Please add a test case, where the unique_ptr is initialized from a pointer 
parameter that has no assumptions. I think that case is not handled correctly.




Comment at: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp:137
+  const auto *RecordDecl = MethodDecl->getParent();
+  if (!RecordDecl || !RecordDecl->getDeclContext()->isStdNamespace())
+return InnerType;

I'd rather use `Decl::isInStdNamespace` instead of querying the DeclContext of 
the decl. The former is more robust with inline namespaces. 



Comment at: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp:141
+  const auto *TSD = dyn_cast(RecordDecl);
+  if (TSD) {
+auto TemplateArgs = TSD->getTemplateArgs().asArray();

Inverting this condition would reduce the indentation in the rest of the 
function.



Comment at: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp:147
+auto InnerValueType = TemplateArgs[0].getAsType();
+InnerType =
+C.getASTContext().getPointerType(InnerValueType.getCanonicalType());

You could return the real inner type here and replace all other returns with 
`return {};` making the code a bit cleaner.



Comment at: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp:413
+  if (InnerPointVal) {
+bool IsInnerPtrNull = InnerPointVal->isZeroConstant();
+State = State->BindExpr(CallExpr, C.getLocationContext(),

Is this actually correct? What if the InnerPtr is an unconstrained symbol. In 
that case, it is not a zero constant so we will assume that it is constrained 
to non-zero. As far as I understand.



Comment at: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp:432
+return;
+  } else {
+// In case of inner pointer SVal is not available we create

I'd do it the other way around as we discussed during the call.
* Move the task of conjuring a new symbol to the beginning of the method.
* Start by calling this function at the beginning of modeling operator bool.
* The rest of the function could assume that there always is a symbol. It could 
be constrained to be non-null, it could be the zero constant, or it could be a 
completely unconstrained symbol. The latter will not work as expected with your 
current implementation, see my comment above.



Comment at: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp:448
+
+if (NullState) {
+  auto NullVal = C.getSValBuilder().makeNull();

NoQ wrote:
> There's no need to check. You just conjured a brand new symbol out of thin 
> air; you can be sure that it's completely unconstrained and both states are 
> feasible. You can instead `assert()` that they're both feasible.
I think instead of removing this check, this method should be reworked. I think 
it might have some bugs, see my comment at the beginning of this method.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86027/new/

https://reviews.llvm.org/D86027

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


[PATCH] D86223: [analyzer][z3] Use more elaborate z3 variable names in debug build

2020-08-22 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun added inline comments.



Comment at: clang/test/Analysis/z3/pretty-dump.c:15
+// CHECK: "constraints": [
+// CHECK-NEXT: { "symbol": "(reg_$[[#]]) == 3", "range": "(= 
reg_$[[#]] #x0003)" }
+  }

Will this test case work with non-debug builds? 


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86223/new/

https://reviews.llvm.org/D86223

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


[PATCH] D86223: [analyzer][z3] Use more elaborate z3 variable names in debug build

2020-08-22 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun accepted this revision.
xazax.hun added a comment.

This is what I had in mind, thanks!




Comment at: clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConv.h:335
+llvm::raw_svector_ostream OS(Str);
+OS << PRETTY_SYMBOL_KIND << ID;
+#undef PRETTY_SYMBOL_KIND

Maybe, in this case, it is cleaner to duplicate the line rather than introduce 
`PRETTY_SYMBOL_KIND`?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86223/new/

https://reviews.llvm.org/D86223

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


[PATCH] D79219: [CMake] Simplify CMake handling for zlib

2020-08-22 Thread Mateusz Mikuła via Phabricator via cfe-commits
mati865 added a comment.

@phosek in MSYS2 (targeting x86_64-w64-windows-gnu) Zlib works properly for 
LLVM 10 but with master I'm now seeing:

  -- Constructing LLVMBuild project information
  -- DEBUG zlib_library=D:/msys64/mingw64/lib/libz.dll.a
  CMake Error at lib/Support/CMakeLists.txt:9 (string):
string sub-command REGEX, mode REPLACE: regex "^(lib|)" matched an empty
string.
  Call Stack (most recent call first):
lib/Support/CMakeLists.txt:226 (get_system_libname)

`-- DEBUG zlib_library=D:/msys64/mingw64/lib/libz.dll.a` was printed by my 
change to help debugging it.
FYI `zlib_library` is set here: 
https://github.com/llvm/llvm-project/blob/8e06bf6b3a2e8d25e56cd52dca0cf3ff1b37b5d1/llvm/lib/Support/CMakeLists.txt#L218


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D79219/new/

https://reviews.llvm.org/D79219

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


[PATCH] D86223: [analyzer][z3] Use more elaborate z3 variable names in debug build

2020-08-22 Thread Balázs Benics via Phabricator via cfe-commits
steakhal updated this revision to Diff 287192.
steakhal edited the summary of this revision.
steakhal added a comment.

Use virtual getKindStr method for acquiring the kind name.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86223/new/

https://reviews.llvm.org/D86223

Files:
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConv.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/SymExpr.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h
  clang/lib/StaticAnalyzer/Core/SymbolManager.cpp
  clang/test/Analysis/z3/pretty-dump.c

Index: clang/test/Analysis/z3/pretty-dump.c
===
--- /dev/null
+++ clang/test/Analysis/z3/pretty-dump.c
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 -analyze -analyzer-constraints=z3 -setup-static-analyzer \
+// RUN:   -analyzer-checker=core,debug.ExprInspection %s 2>&1 | FileCheck %s
+//
+// REQUIRES: z3
+//
+// Works only with the z3 constraint manager.
+
+void clang_analyzer_printState();
+
+void foo(int x) {
+  if (x == 3) {
+clang_analyzer_printState();
+(void)x;
+// CHECK: "constraints": [
+// CHECK-NEXT: { "symbol": "(reg_$[[#]]) == 3", "range": "(= reg_$[[#]] #x0003)" }
+  }
+}
Index: clang/lib/StaticAnalyzer/Core/SymbolManager.cpp
===
--- clang/lib/StaticAnalyzer/Core/SymbolManager.cpp
+++ clang/lib/StaticAnalyzer/Core/SymbolManager.cpp
@@ -34,6 +34,12 @@
 
 void SymExpr::anchor() {}
 
+StringRef SymbolConjured::getKindStr() const { return "conj_$"; }
+StringRef SymbolDerived::getKindStr() const { return "derived_$"; }
+StringRef SymbolExtent::getKindStr() const { return "extent_$"; }
+StringRef SymbolMetadata::getKindStr() const { return "meta_$"; }
+StringRef SymbolRegionValue::getKindStr() const { return "reg_$"; }
+
 LLVM_DUMP_METHOD void SymExpr::dump() const { dumpToStream(llvm::errs()); }
 
 void BinarySymExpr::dumpToStreamImpl(raw_ostream , const SymExpr *Sym) {
@@ -64,7 +70,7 @@
 }
 
 void SymbolConjured::dumpToStream(raw_ostream ) const {
-  os << "conj_$" << getSymbolID() << '{' << T.getAsString() << ", LC"
+  os << getKindStr() << getSymbolID() << '{' << T.getAsString() << ", LC"
  << LCtx->getID();
   if (S)
 os << ", S" << S->getID(LCtx->getDecl()->getASTContext());
@@ -74,24 +80,24 @@
 }
 
 void SymbolDerived::dumpToStream(raw_ostream ) const {
-  os << "derived_$" << getSymbolID() << '{'
- << getParentSymbol() << ',' << getRegion() << '}';
+  os << getKindStr() << getSymbolID() << '{' << getParentSymbol() << ','
+ << getRegion() << '}';
 }
 
 void SymbolExtent::dumpToStream(raw_ostream ) const {
-  os << "extent_$" << getSymbolID() << '{' << getRegion() << '}';
+  os << getKindStr() << getSymbolID() << '{' << getRegion() << '}';
 }
 
 void SymbolMetadata::dumpToStream(raw_ostream ) const {
-  os << "meta_$" << getSymbolID() << '{'
- << getRegion() << ',' << T.getAsString() << '}';
+  os << getKindStr() << getSymbolID() << '{' << getRegion() << ','
+ << T.getAsString() << '}';
 }
 
 void SymbolData::anchor() {}
 
 void SymbolRegionValue::dumpToStream(raw_ostream ) const {
-  os << "reg_$" << getSymbolID()
- << '<' << getType().getAsString() << ' ' << R << '>';
+  os << getKindStr() << getSymbolID() << '<' << getType().getAsString() << ' '
+ << R << '>';
 }
 
 bool SymExpr::symbol_iterator::operator==(const symbol_iterator ) const {
Index: clang/include/clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h
===
--- clang/include/clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h
+++ clang/include/clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h
@@ -59,6 +59,8 @@
 Profile(profile, R);
   }
 
+  StringRef getKindStr() const override;
+
   void dumpToStream(raw_ostream ) const override;
   const MemRegion *getOriginRegion() const override { return getRegion(); }
 
@@ -99,6 +101,8 @@
 
   QualType getType() const override;
 
+  StringRef getKindStr() const override;
+
   void dumpToStream(raw_ostream ) const override;
 
   static void Profile(llvm::FoldingSetNodeID& profile, const Stmt *S,
@@ -141,6 +145,8 @@
 
   QualType getType() const override;
 
+  StringRef getKindStr() const override;
+
   void dumpToStream(raw_ostream ) const override;
   const MemRegion *getOriginRegion() const override { return getRegion(); }
 
@@ -177,6 +183,8 @@
 
   QualType getType() const override;
 
+  StringRef getKindStr() const override;
+
   void dumpToStream(raw_ostream ) const override;
 
   static void Profile(llvm::FoldingSetNodeID& profile, const SubRegion *R) {
@@ -226,6 +234,8 @@
 
   QualType getType() const override;
 
+  StringRef getKindStr() const override;
+
   void dumpToStream(raw_ostream ) const override;
 
   static void 

[PATCH] D86398: [X86] Enable constexpr on _cast fp<-> uint intrinsics (PR31446)

2020-08-22 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon created this revision.
RKSimon added reviewers: rsmith, craig.topper, erichkeane.
Herald added a project: clang.
RKSimon requested review of this revision.

As suggested by @rsmith on PR47267, by replacing the __builtin_memcpy bitcast 
pattern with __builtin_bit_cast we can use _castf32_u32, _castu32_f32, 
_castf64_u64 and _castu64_f64 inside constant expresssions (constexpr). 
Although __builtin_bit_cast was added for c++20 it works on all clang c/c++ 
modes.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D86398

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Headers/ia32intrin.h
  clang/test/CodeGen/x86-builtins.c

Index: clang/test/CodeGen/x86-builtins.c
===
--- clang/test/CodeGen/x86-builtins.c
+++ clang/test/CodeGen/x86-builtins.c
@@ -1,45 +1,43 @@
-// RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-unknown-unknown -emit-llvm -o - -Wall -Werror | FileCheck %s -check-prefix=CHECK-64
-// RUN: %clang_cc1 -ffreestanding %s -triple=i386-unknown-unknown -emit-llvm -o - -Wall -Werror | FileCheck %s -check-prefix=CHECK-32
+// RUN: %clang_cc1 -x c -ffreestanding %s -triple=x86_64-unknown-unknown -emit-llvm -o - -Wall -Werror | FileCheck %s
+// RUN: %clang_cc1 -x c -ffreestanding %s -triple=i386-unknown-unknown -emit-llvm -o - -Wall -Werror | FileCheck %s
+// RUN: %clang_cc1 -x c++ -std=c++11 -ffreestanding %s -triple=x86_64-unknown-unknown -emit-llvm -o - -Wall -Werror | FileCheck %s
+// RUN: %clang_cc1 -x c++ -std=c++11 -ffreestanding %s -triple=i386-unknown-unknown -emit-llvm -o - -Wall -Werror | FileCheck %s
 
 #include 
 
 unsigned int test_castf32_u32 (float __A){
-  // CHECK-64-LABEL: @test_castf32_u32
-  // CHECK-64: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 4 %{{.*}}, i8* align 4 %{{.*}}, i64 4, i1 false)
-  // CHECK-64: %{{.*}} = load i32, i32* %{{.*}}, align 4
-  // CHECK-32-LABEL: @test_castf32_u32
-  // CHECK-32: call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 4 %{{.*}}, i8* align 4 %{{.*}}, i32 4, i1 false)
-  // CHECK-32: %{{.*}} = load i32, i32* %{{.*}}, align 4
+  // CHECK-LABEL: test_castf32_u32
+  // CHECK: bitcast float* %{{.*}} to i32*
+  // CHECK: %{{.*}} = load i32, i32* %{{.*}}, align 4
   return _castf32_u32(__A);
 }
 
 unsigned long long test_castf64_u64 (double __A){
-  // CHECK-64-LABEL: @test_castf64_u64
-  // CHECK-64: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 8 %{{.*}}, i8* align 8 %{{.*}}, i64 8, i1 false)
-  // CHECK-64: %{{.*}} = load i64, i64* %{{.*}}, align 8
-  // CHECK-32-LABEL: @test_castf64_u64
-  // CHECK-32: call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 8 %{{.*}}, i8* align 8 %{{.*}}, i32 8, i1 false)
-  // CHECK-32: %{{.*}} = load i64, i64* %{{.*}}, align 8
+  // CHECK-LABEL: test_castf64_u64
+  // CHECK: bitcast double* %{{.*}} to i64*
+  // CHECK: %{{.*}} = load i64, i64* %{{.*}}, align 8
   return _castf64_u64(__A);
 }
 
 float test_castu32_f32 (unsigned int __A){
-  // CHECK-64-LABEL: @test_castu32_f32
-  // CHECK-64: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 4 %{{.*}}, i8* align 4 %{{.*}}, i64 4, i1 false)
-  // CHECK-64: %{{.*}} = load float, float* %{{.*}}, align 4
-  // CHECK-32-LABEL: @test_castu32_f32
-  // CHECK-32: call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 4 %{{.*}}, i8* align 4 %{{.*}}, i32 4, i1 false)
-  // CHECK-32: %{{.*}} = load float, float* %{{.*}}, align 4
+  // CHECK-LABEL: test_castu32_f32
+  // CHECK: bitcast i32* %{{.*}} to float*
+  // CHECK: %{{.*}} = load float, float* %{{.*}}, align 4
   return _castu32_f32(__A);
 }
 
 double test_castu64_f64 (unsigned long long __A){
-  // CHECK-64-LABEL: @test_castu64_f64
-  // CHECK-64: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 8 %{{.*}}, i8* align 8 %{{.*}}, i64 8, i1 false)
-  // CHECK-64: %{{.*}} = load double, double* %{{.*}}, align 8
-  // CHECK-32-LABEL: @test_castu64_f64
-  // CHECK-32: call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 8 %{{.*}}, i8* align 8 %{{.*}}, i32 8, i1 false)
-  // CHECK-32: %{{.*}} = load double, double* %{{.*}}, align 8
+  // CHECK-LABEL: test_castu64_f64
+  // CHECK: bitcast i64* %{{.*}} to double*
+  // CHECK: %{{.*}} = load double, double* %{{.*}}, align 8
   return _castu64_f64(__A);
 }
 
+// Test constexpr handling.
+#if defined(__cplusplus) && (__cplusplus >= 201103L)
+char cast_f32_u32_0[_castf32_u32(-0.0f) == 0x8000 ? 1 : -1];
+char cast_u32_f32_0[_castu32_f32(0x3F80) == +1.0f ? 1 : -1];
+
+char castf64_u64_0[_castf64_u64(-0.0) == 0x8000 ? 1 : -1];
+char castu64_f64_0[_castu64_f64(0xBFF0ULL) == -1.0 ? 1 : -1];
+#endif
Index: clang/lib/Headers/ia32intrin.h
===
--- clang/lib/Headers/ia32intrin.h
+++ clang/lib/Headers/ia32intrin.h
@@ -16,12 +16,13 @@
 
 /* Define the default attributes for the functions in this file. */
 #define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__))
-#define __DEFAULT_FN_ATTRS_CAST 

[clang] 42b993d - [X86] ia32intrin.h - pull out common attributes used in cast helpers into define. NFCI.

2020-08-22 Thread Simon Pilgrim via cfe-commits

Author: Simon Pilgrim
Date: 2020-08-22T15:25:15+01:00
New Revision: 42b993d97d31d7810fa3c1f7f2e79f72baa02416

URL: 
https://github.com/llvm/llvm-project/commit/42b993d97d31d7810fa3c1f7f2e79f72baa02416
DIFF: 
https://github.com/llvm/llvm-project/commit/42b993d97d31d7810fa3c1f7f2e79f72baa02416.diff

LOG: [X86] ia32intrin.h - pull out common attributes used in cast helpers into 
define. NFCI.

Added: 


Modified: 
clang/lib/Headers/ia32intrin.h

Removed: 




diff  --git a/clang/lib/Headers/ia32intrin.h b/clang/lib/Headers/ia32intrin.h
index a86ef868c3ce..1d17a565378a 100644
--- a/clang/lib/Headers/ia32intrin.h
+++ b/clang/lib/Headers/ia32intrin.h
@@ -16,6 +16,7 @@
 
 /* Define the default attributes for the functions in this file. */
 #define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__))
+#define __DEFAULT_FN_ATTRS_CAST __attribute__((__always_inline__))
 #define __DEFAULT_FN_ATTRS_SSE42 __attribute__((__always_inline__, 
__nodebug__, __target__("sse4.2")))
 
 #if defined(__cplusplus) && (__cplusplus >= 201103L)
@@ -215,7 +216,7 @@ __writeeflags(unsigned int __f)
  * A 32-bit float value.
  *  \returns a 32-bit unsigned integer containing the converted value.
  */
-static __inline__ unsigned int __attribute__((__always_inline__))
+static __inline__ unsigned int __DEFAULT_FN_ATTRS_CAST
 _castf32_u32(float __A) {
   unsigned int D;
   __builtin_memcpy(, &__A, sizeof(__A));
@@ -232,7 +233,7 @@ _castf32_u32(float __A) {
  * A 64-bit float value.
  *  \returns a 64-bit unsigned integer containing the converted value.
  */
-static __inline__ unsigned long long __attribute__((__always_inline__))
+static __inline__ unsigned long long __DEFAULT_FN_ATTRS_CAST
 _castf64_u64(double __A) {
   unsigned long long D;
   __builtin_memcpy(, &__A, sizeof(__A));
@@ -249,7 +250,7 @@ _castf64_u64(double __A) {
  * A 32-bit unsigned integer value.
  *  \returns a 32-bit float value containing the converted value.
  */
-static __inline__ float __attribute__((__always_inline__))
+static __inline__ float __DEFAULT_FN_ATTRS_CAST
 _castu32_f32(unsigned int __A) {
   float D;
   __builtin_memcpy(, &__A, sizeof(__A));
@@ -266,7 +267,7 @@ _castu32_f32(unsigned int __A) {
  * A 64-bit unsigned integer value.
  *  \returns a 64-bit float value containing the converted value.
  */
-static __inline__ double __attribute__((__always_inline__))
+static __inline__ double __DEFAULT_FN_ATTRS_CAST
 _castu64_f64(unsigned long long __A) {
   double D;
   __builtin_memcpy(, &__A, sizeof(__A));
@@ -440,6 +441,7 @@ __rorq(unsigned long long __X, int __C) {
 #define _rotwr(a,b) __rorw((a), (b))
 
 #undef __DEFAULT_FN_ATTRS
+#undef __DEFAULT_FN_ATTRS_CAST
 #undef __DEFAULT_FN_ATTRS_SSE42
 #undef __DEFAULT_FN_ATTRS_CONSTEXPR
 



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


[clang] e7d9182 - Enable constexpr on BITREVERSE builtin intrinsics (PR47249)

2020-08-22 Thread Simon Pilgrim via cfe-commits

Author: Simon Pilgrim
Date: 2020-08-22T14:43:22+01:00
New Revision: e7d9182a666a2a8f903bd330c82d7c623b783371

URL: 
https://github.com/llvm/llvm-project/commit/e7d9182a666a2a8f903bd330c82d7c623b783371
DIFF: 
https://github.com/llvm/llvm-project/commit/e7d9182a666a2a8f903bd330c82d7c623b783371.diff

LOG: Enable constexpr on BITREVERSE builtin intrinsics (PR47249)

This enables us to use the __builtin_bitreverse 8/16/32/64 intrinsics inside 
constexpr code.

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

Added: 


Modified: 
clang/docs/LanguageExtensions.rst
clang/docs/ReleaseNotes.rst
clang/lib/AST/ExprConstant.cpp
clang/test/Sema/constant-builtins-2.c

Removed: 




diff  --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index fd563b0d59ba..a431239f887b 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -1984,7 +1984,7 @@ Query for this feature with 
``__has_builtin(__builtin_convertvector)``.
 
 The '``__builtin_bitreverse``' family of builtins is used to reverse
 the bitpattern of an integer value; for example ``0b10110110`` becomes
-``0b01101101``.
+``0b01101101``. These builtins can be used within constant expressions.
 
 ``__builtin_rotateleft``
 

diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7a94039f9a26..ba2b540639ad 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -56,6 +56,10 @@ Improvements to Clang's diagnostics
 Non-comprehensive list of changes in this release
 -
 
+- The builtin intrinsics ``__builtin_bitreverse8``, ``__builtin_bitreverse16``,
+  ``__builtin_bitreverse32`` and ``__builtin_bitreverse64`` may now be used
+  within constant expressions.
+
 - The builtin intrinsics ``__builtin_rotateleft8``, ``__builtin_rotateleft16``,
   ``__builtin_rotateleft32`` and ``__builtin_rotateleft64`` may now be used
   within constant expressions.

diff  --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 09ef5629182a..c23233ab8c8c 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -11180,6 +11180,17 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const 
CallExpr *E,
 return Success(AlignedVal, E);
   }
 
+  case Builtin::BI__builtin_bitreverse8:
+  case Builtin::BI__builtin_bitreverse16:
+  case Builtin::BI__builtin_bitreverse32:
+  case Builtin::BI__builtin_bitreverse64: {
+APSInt Val;
+if (!EvaluateInteger(E->getArg(0), Val, Info))
+  return false;
+
+return Success(Val.reverseBits(), E);
+  }
+
   case Builtin::BI__builtin_bswap16:
   case Builtin::BI__builtin_bswap32:
   case Builtin::BI__builtin_bswap64: {

diff  --git a/clang/test/Sema/constant-builtins-2.c 
b/clang/test/Sema/constant-builtins-2.c
index b0f566e9eecf..19d1599dc4a1 100644
--- a/clang/test/Sema/constant-builtins-2.c
+++ b/clang/test/Sema/constant-builtins-2.c
@@ -169,6 +169,11 @@ char parity8[__builtin_parity(~0) == 0 ? 1 : -1];
 char parity9[__builtin_parityl(1L << (BITSIZE(long) - 1)) == 1 ? 1 : -1];
 char parity10[__builtin_parityll(1LL << (BITSIZE(long long) - 1)) == 1 ? 1 : 
-1];
 
+char bitreverse1[__builtin_bitreverse8(0x01) == 0x80 ? 1 : -1];
+char bitreverse2[__builtin_bitreverse16(0x3C48) == 0x123C ? 1 : -1];
+char bitreverse3[__builtin_bitreverse32(0x12345678) == 0x1E6A2C48 ? 1 : -1];
+char bitreverse4[__builtin_bitreverse64(0x0123456789ABCDEFULL) == 
0xF7B3D591E6A2C480 ? 1 : -1];
+
 char rotateleft1[__builtin_rotateleft8(0x01, 5) == 0x20 ? 1 : -1];
 char rotateleft2[__builtin_rotateleft16(0x3210, 11) == 0x8190 ? 1 : -1];
 char rotateleft2[__builtin_rotateleft32(0x76543210, 22) == 0x841D950C ? 1 : 
-1];



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


[PATCH] D86339: Enable constexpr on BITREVERSE builtin intrinsics (PR47249)

2020-08-22 Thread Simon Pilgrim via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe7d9182a666a: Enable constexpr on BITREVERSE builtin 
intrinsics (PR47249) (authored by RKSimon).

Changed prior to commit:
  https://reviews.llvm.org/D86339?vs=286999=287182#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86339/new/

https://reviews.llvm.org/D86339

Files:
  clang/docs/LanguageExtensions.rst
  clang/docs/ReleaseNotes.rst
  clang/lib/AST/ExprConstant.cpp
  clang/test/Sema/constant-builtins-2.c


Index: clang/test/Sema/constant-builtins-2.c
===
--- clang/test/Sema/constant-builtins-2.c
+++ clang/test/Sema/constant-builtins-2.c
@@ -169,6 +169,11 @@
 char parity9[__builtin_parityl(1L << (BITSIZE(long) - 1)) == 1 ? 1 : -1];
 char parity10[__builtin_parityll(1LL << (BITSIZE(long long) - 1)) == 1 ? 1 : 
-1];
 
+char bitreverse1[__builtin_bitreverse8(0x01) == 0x80 ? 1 : -1];
+char bitreverse2[__builtin_bitreverse16(0x3C48) == 0x123C ? 1 : -1];
+char bitreverse3[__builtin_bitreverse32(0x12345678) == 0x1E6A2C48 ? 1 : -1];
+char bitreverse4[__builtin_bitreverse64(0x0123456789ABCDEFULL) == 
0xF7B3D591E6A2C480 ? 1 : -1];
+
 char rotateleft1[__builtin_rotateleft8(0x01, 5) == 0x20 ? 1 : -1];
 char rotateleft2[__builtin_rotateleft16(0x3210, 11) == 0x8190 ? 1 : -1];
 char rotateleft2[__builtin_rotateleft32(0x76543210, 22) == 0x841D950C ? 1 : 
-1];
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -11180,6 +11180,17 @@
 return Success(AlignedVal, E);
   }
 
+  case Builtin::BI__builtin_bitreverse8:
+  case Builtin::BI__builtin_bitreverse16:
+  case Builtin::BI__builtin_bitreverse32:
+  case Builtin::BI__builtin_bitreverse64: {
+APSInt Val;
+if (!EvaluateInteger(E->getArg(0), Val, Info))
+  return false;
+
+return Success(Val.reverseBits(), E);
+  }
+
   case Builtin::BI__builtin_bswap16:
   case Builtin::BI__builtin_bswap32:
   case Builtin::BI__builtin_bswap64: {
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -56,6 +56,10 @@
 Non-comprehensive list of changes in this release
 -
 
+- The builtin intrinsics ``__builtin_bitreverse8``, ``__builtin_bitreverse16``,
+  ``__builtin_bitreverse32`` and ``__builtin_bitreverse64`` may now be used
+  within constant expressions.
+
 - The builtin intrinsics ``__builtin_rotateleft8``, ``__builtin_rotateleft16``,
   ``__builtin_rotateleft32`` and ``__builtin_rotateleft64`` may now be used
   within constant expressions.
Index: clang/docs/LanguageExtensions.rst
===
--- clang/docs/LanguageExtensions.rst
+++ clang/docs/LanguageExtensions.rst
@@ -1984,7 +1984,7 @@
 
 The '``__builtin_bitreverse``' family of builtins is used to reverse
 the bitpattern of an integer value; for example ``0b10110110`` becomes
-``0b01101101``.
+``0b01101101``. These builtins can be used within constant expressions.
 
 ``__builtin_rotateleft``
 


Index: clang/test/Sema/constant-builtins-2.c
===
--- clang/test/Sema/constant-builtins-2.c
+++ clang/test/Sema/constant-builtins-2.c
@@ -169,6 +169,11 @@
 char parity9[__builtin_parityl(1L << (BITSIZE(long) - 1)) == 1 ? 1 : -1];
 char parity10[__builtin_parityll(1LL << (BITSIZE(long long) - 1)) == 1 ? 1 : -1];
 
+char bitreverse1[__builtin_bitreverse8(0x01) == 0x80 ? 1 : -1];
+char bitreverse2[__builtin_bitreverse16(0x3C48) == 0x123C ? 1 : -1];
+char bitreverse3[__builtin_bitreverse32(0x12345678) == 0x1E6A2C48 ? 1 : -1];
+char bitreverse4[__builtin_bitreverse64(0x0123456789ABCDEFULL) == 0xF7B3D591E6A2C480 ? 1 : -1];
+
 char rotateleft1[__builtin_rotateleft8(0x01, 5) == 0x20 ? 1 : -1];
 char rotateleft2[__builtin_rotateleft16(0x3210, 11) == 0x8190 ? 1 : -1];
 char rotateleft2[__builtin_rotateleft32(0x76543210, 22) == 0x841D950C ? 1 : -1];
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -11180,6 +11180,17 @@
 return Success(AlignedVal, E);
   }
 
+  case Builtin::BI__builtin_bitreverse8:
+  case Builtin::BI__builtin_bitreverse16:
+  case Builtin::BI__builtin_bitreverse32:
+  case Builtin::BI__builtin_bitreverse64: {
+APSInt Val;
+if (!EvaluateInteger(E->getArg(0), Val, Info))
+  return false;
+
+return Success(Val.reverseBits(), E);
+  }
+
   case Builtin::BI__builtin_bswap16:
   case Builtin::BI__builtin_bswap32:
   case Builtin::BI__builtin_bswap64: {
Index: clang/docs/ReleaseNotes.rst

[clang] 2ceac91 - Enable constexpr on ROTATELEFT/ROTATERIGHT builtin intrinsics (PR47249)

2020-08-22 Thread Simon Pilgrim via cfe-commits

Author: Simon Pilgrim
Date: 2020-08-22T14:43:21+01:00
New Revision: 2ceac91ec0fc186ff503402e7b88e4576a69008d

URL: 
https://github.com/llvm/llvm-project/commit/2ceac91ec0fc186ff503402e7b88e4576a69008d
DIFF: 
https://github.com/llvm/llvm-project/commit/2ceac91ec0fc186ff503402e7b88e4576a69008d.diff

LOG: Enable constexpr on ROTATELEFT/ROTATERIGHT builtin intrinsics (PR47249)

This enables us to use the __builtin_rotateleft / __builtin_rotateright 
8/16/32/64 intrinsics inside constexpr code.

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

Added: 


Modified: 
clang/docs/LanguageExtensions.rst
clang/docs/ReleaseNotes.rst
clang/lib/AST/ExprConstant.cpp
clang/test/Sema/constant-builtins-2.c

Removed: 




diff  --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 518ab6385263..fd563b0d59ba 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -2016,7 +2016,8 @@ the bits in the first argument by the amount in the 
second argument.
 For example, ``0b1110`` rotated left by 11 becomes ``0b00110100``.
 The shift value is treated as an unsigned amount modulo the size of
 the arguments. Both arguments and the result have the bitwidth specified
-by the name of the builtin.
+by the name of the builtin. These builtins can be used within constant
+expressions.
 
 ``__builtin_rotateright``
 -
@@ -2048,7 +2049,8 @@ the bits in the first argument by the amount in the 
second argument.
 For example, ``0b1110`` rotated right by 3 becomes ``0b1101``.
 The shift value is treated as an unsigned amount modulo the size of
 the arguments. Both arguments and the result have the bitwidth specified
-by the name of the builtin.
+by the name of the builtin. These builtins can be used within constant
+expressions.
 
 ``__builtin_unreachable``
 -

diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index b01408bba575..7a94039f9a26 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -56,7 +56,13 @@ Improvements to Clang's diagnostics
 Non-comprehensive list of changes in this release
 -
 
-- ...
+- The builtin intrinsics ``__builtin_rotateleft8``, ``__builtin_rotateleft16``,
+  ``__builtin_rotateleft32`` and ``__builtin_rotateleft64`` may now be used
+  within constant expressions.
+
+- The builtin intrinsics ``__builtin_rotateright8``, 
``__builtin_rotateright16``,
+  ``__builtin_rotateright32`` and ``__builtin_rotateright64`` may now be used
+  within constant expressions.
 
 New Compiler Flags
 --

diff  --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index b22797b5c3c0..09ef5629182a 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -11347,6 +11347,30 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const 
CallExpr *E,
 return Success(Val.countPopulation(), E);
   }
 
+  case Builtin::BI__builtin_rotateleft8:
+  case Builtin::BI__builtin_rotateleft16:
+  case Builtin::BI__builtin_rotateleft32:
+  case Builtin::BI__builtin_rotateleft64: {
+APSInt Val, Amt;
+if (!EvaluateInteger(E->getArg(0), Val, Info) ||
+!EvaluateInteger(E->getArg(1), Amt, Info))
+  return false;
+
+return Success(Val.rotl(Amt.urem(Val.getBitWidth())), E);
+  }
+
+  case Builtin::BI__builtin_rotateright8:
+  case Builtin::BI__builtin_rotateright16:
+  case Builtin::BI__builtin_rotateright32:
+  case Builtin::BI__builtin_rotateright64: {
+APSInt Val, Amt;
+if (!EvaluateInteger(E->getArg(0), Val, Info) ||
+!EvaluateInteger(E->getArg(1), Amt, Info))
+  return false;
+
+return Success(Val.rotr(Amt.urem(Val.getBitWidth())), E);
+  }
+
   case Builtin::BIstrlen:
   case Builtin::BIwcslen:
 // A call to strlen is not a constant expression.

diff  --git a/clang/test/Sema/constant-builtins-2.c 
b/clang/test/Sema/constant-builtins-2.c
index 9bb5215b8dbd..b0f566e9eecf 100644
--- a/clang/test/Sema/constant-builtins-2.c
+++ b/clang/test/Sema/constant-builtins-2.c
@@ -169,6 +169,16 @@ char parity8[__builtin_parity(~0) == 0 ? 1 : -1];
 char parity9[__builtin_parityl(1L << (BITSIZE(long) - 1)) == 1 ? 1 : -1];
 char parity10[__builtin_parityll(1LL << (BITSIZE(long long) - 1)) == 1 ? 1 : 
-1];
 
+char rotateleft1[__builtin_rotateleft8(0x01, 5) == 0x20 ? 1 : -1];
+char rotateleft2[__builtin_rotateleft16(0x3210, 11) == 0x8190 ? 1 : -1];
+char rotateleft2[__builtin_rotateleft32(0x76543210, 22) == 0x841D950C ? 1 : 
-1];
+char rotateleft2[__builtin_rotateleft64(0xFEDCBA9876543210ULL, 55) == 
0x87F6E5D4C3B2A19ULL ? 1 : -1];
+
+char rotateright1[__builtin_rotateright8(0x01, 5) == 0x08 ? 1 : -1];
+char rotateright2[__builtin_rotateright16(0x3210, 11) == 0x4206 ? 1 : -1];
+char rotateright2[__builtin_rotateright32(0x76543210, 22) == 

[PATCH] D86342: Enable constexpr on ROTATELEFT/ROTATERIGHT builtin intrinsics (PR47249)

2020-08-22 Thread Simon Pilgrim via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG2ceac91ec0fc: Enable constexpr on ROTATELEFT/ROTATERIGHT 
builtin intrinsics (PR47249) (authored by RKSimon).

Changed prior to commit:
  https://reviews.llvm.org/D86342?vs=287006=287181#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86342/new/

https://reviews.llvm.org/D86342

Files:
  clang/docs/LanguageExtensions.rst
  clang/docs/ReleaseNotes.rst
  clang/lib/AST/ExprConstant.cpp
  clang/test/Sema/constant-builtins-2.c


Index: clang/test/Sema/constant-builtins-2.c
===
--- clang/test/Sema/constant-builtins-2.c
+++ clang/test/Sema/constant-builtins-2.c
@@ -169,6 +169,16 @@
 char parity9[__builtin_parityl(1L << (BITSIZE(long) - 1)) == 1 ? 1 : -1];
 char parity10[__builtin_parityll(1LL << (BITSIZE(long long) - 1)) == 1 ? 1 : 
-1];
 
+char rotateleft1[__builtin_rotateleft8(0x01, 5) == 0x20 ? 1 : -1];
+char rotateleft2[__builtin_rotateleft16(0x3210, 11) == 0x8190 ? 1 : -1];
+char rotateleft2[__builtin_rotateleft32(0x76543210, 22) == 0x841D950C ? 1 : 
-1];
+char rotateleft2[__builtin_rotateleft64(0xFEDCBA9876543210ULL, 55) == 
0x87F6E5D4C3B2A19ULL ? 1 : -1];
+
+char rotateright1[__builtin_rotateright8(0x01, 5) == 0x08 ? 1 : -1];
+char rotateright2[__builtin_rotateright16(0x3210, 11) == 0x4206 ? 1 : -1];
+char rotateright2[__builtin_rotateright32(0x76543210, 22) == 0x50C841D9 ? 1 : 
-1];
+char rotateright2[__builtin_rotateright64(0xFEDCBA9876543210ULL, 55) == 
0xB97530ECA86421FDULL ? 1 : -1];
+
 char ffs1[__builtin_ffs(0) == 0 ? 1 : -1];
 char ffs2[__builtin_ffs(1) == 1 ? 1 : -1];
 char ffs3[__builtin_ffs(0xfbe71) == 1 ? 1 : -1];
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -11347,6 +11347,30 @@
 return Success(Val.countPopulation(), E);
   }
 
+  case Builtin::BI__builtin_rotateleft8:
+  case Builtin::BI__builtin_rotateleft16:
+  case Builtin::BI__builtin_rotateleft32:
+  case Builtin::BI__builtin_rotateleft64: {
+APSInt Val, Amt;
+if (!EvaluateInteger(E->getArg(0), Val, Info) ||
+!EvaluateInteger(E->getArg(1), Amt, Info))
+  return false;
+
+return Success(Val.rotl(Amt.urem(Val.getBitWidth())), E);
+  }
+
+  case Builtin::BI__builtin_rotateright8:
+  case Builtin::BI__builtin_rotateright16:
+  case Builtin::BI__builtin_rotateright32:
+  case Builtin::BI__builtin_rotateright64: {
+APSInt Val, Amt;
+if (!EvaluateInteger(E->getArg(0), Val, Info) ||
+!EvaluateInteger(E->getArg(1), Amt, Info))
+  return false;
+
+return Success(Val.rotr(Amt.urem(Val.getBitWidth())), E);
+  }
+
   case Builtin::BIstrlen:
   case Builtin::BIwcslen:
 // A call to strlen is not a constant expression.
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -56,7 +56,13 @@
 Non-comprehensive list of changes in this release
 -
 
-- ...
+- The builtin intrinsics ``__builtin_rotateleft8``, ``__builtin_rotateleft16``,
+  ``__builtin_rotateleft32`` and ``__builtin_rotateleft64`` may now be used
+  within constant expressions.
+
+- The builtin intrinsics ``__builtin_rotateright8``, 
``__builtin_rotateright16``,
+  ``__builtin_rotateright32`` and ``__builtin_rotateright64`` may now be used
+  within constant expressions.
 
 New Compiler Flags
 --
Index: clang/docs/LanguageExtensions.rst
===
--- clang/docs/LanguageExtensions.rst
+++ clang/docs/LanguageExtensions.rst
@@ -2016,7 +2016,8 @@
 For example, ``0b1110`` rotated left by 11 becomes ``0b00110100``.
 The shift value is treated as an unsigned amount modulo the size of
 the arguments. Both arguments and the result have the bitwidth specified
-by the name of the builtin.
+by the name of the builtin. These builtins can be used within constant
+expressions.
 
 ``__builtin_rotateright``
 -
@@ -2048,7 +2049,8 @@
 For example, ``0b1110`` rotated right by 3 becomes ``0b1101``.
 The shift value is treated as an unsigned amount modulo the size of
 the arguments. Both arguments and the result have the bitwidth specified
-by the name of the builtin.
+by the name of the builtin. These builtins can be used within constant
+expressions.
 
 ``__builtin_unreachable``
 -


Index: clang/test/Sema/constant-builtins-2.c
===
--- clang/test/Sema/constant-builtins-2.c
+++ clang/test/Sema/constant-builtins-2.c
@@ -169,6 +169,16 @@
 char parity9[__builtin_parityl(1L << (BITSIZE(long) - 1)) == 1 ? 1 : -1];
 char parity10[__builtin_parityll(1LL << (BITSIZE(long long) 

[clang] 436a35a - [docs] Replace "constexpr expressions" with "constant expressions".

2020-08-22 Thread Simon Pilgrim via cfe-commits

Author: Simon Pilgrim
Date: 2020-08-22T14:14:36+01:00
New Revision: 436a35a77313598eedad867a0f086aeb1b5b6eb2

URL: 
https://github.com/llvm/llvm-project/commit/436a35a77313598eedad867a0f086aeb1b5b6eb2
DIFF: 
https://github.com/llvm/llvm-project/commit/436a35a77313598eedad867a0f086aeb1b5b6eb2.diff

LOG: [docs] Replace "constexpr expressions" with "constant expressions".

Based off comment from @rsmith on D86339

Added: 


Modified: 
clang/docs/ReleaseNotes.rst

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 6ea9a1499ed3..b01408bba575 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -158,16 +158,16 @@ X86 Support in Clang
 
 - The x86 intrinsics ``_mm_popcnt_u32``, ``_mm_popcnt_u64``, ``_popcnt32``,
   ``_popcnt64``, ``__popcntd`` and ``__popcntq``  may now be used within
-  constexpr expressions.
+  constant expressions.
 
 - The x86 intrinsics ``_bit_scan_forward``, ``__bsfd`` and ``__bsfq`` may now
-  be used within constexpr expressions.
+  be used within constant expressions.
 
 - The x86 intrinsics ``_bit_scan_reverse``, ``__bsrd`` and ``__bsrq`` may now
-  be used within constexpr expressions.
+  be used within constant expressions.
 
 - The x86 intrinsics ``__bswap``, ``__bswapd``, ``__bswap64`` and ``__bswapq``
-  may now be used within constexpr expressions.
+  may now be used within constant expressions.
 
 Internal API Changes
 



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


[PATCH] D86176: [clang-tidy] readability-simplify-boolean-expr detects negated literals

2020-08-22 Thread Nathan James via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGdf5335a36d3d: [clang-tidy] readability-simplify-boolean-expr 
detects negated literals (authored by njames93).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86176/new/

https://reviews.llvm.org/D86176

Files:
  clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
  clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.h
  clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr.cpp
@@ -98,6 +98,46 @@
   // CHECK-FIXES-NEXT: {{^  i = 11;$}}
 }
 
+void if_with_negated_bool_condition() {
+  int i = 10;
+  if (!true) {
+i = 11;
+  } else {
+i = 12;
+  }
+  i = 13;
+  // CHECK-MESSAGES: :[[@LINE-6]]:7: warning: {{.*}} in if statement condition
+  // CHECK-FIXES:  {{^  int i = 10;$}}
+  // CHECK-FIXES-NEXT: {{^  {$}}
+  // CHECK-FIXES-NEXT: {{^i = 12;$}}
+  // CHECK-FIXES-NEXT: {{^  }$}}
+  // CHECK-FIXES-NEXT: {{^  i = 13;$}}
+
+  i = 14;
+  if (!false) {
+i = 15;
+  } else {
+i = 16;
+  }
+  i = 17;
+  // CHECK-MESSAGES: :[[@LINE-6]]:7: warning: {{.*}} in if statement condition
+  // CHECK-FIXES:  {{^  i = 14;$}}
+  // CHECK-FIXES-NEXT: {{^  {$}}
+  // CHECK-FIXES-NEXT: {{^i = 15;$}}
+  // CHECK-FIXES-NEXT: {{^  }$}}
+  // CHECK-FIXES-NEXT: {{^  i = 17;$}}
+
+  i = 18;
+  if (!true) {
+i = 19;
+  }
+  i = 20;
+  // CHECK-MESSAGES: :[[@LINE-4]]:7: warning: {{.*}} in if statement condition
+  // CHECK-FIXES:  {{^  i = 18;$}}
+  // CHECK-FIXES-NEXT: {{^  $}}
+  // CHECK-FIXES-NEXT: {{^  i = 20;$}}
+}
+
 void operator_equals() {
   int i = 0;
   bool b1 = (i > 2);
Index: clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.h
===
--- clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.h
+++ clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.h
@@ -51,11 +51,11 @@
 
   void
   replaceWithThenStatement(const ast_matchers::MatchFinder::MatchResult ,
-   const CXXBoolLiteralExpr *BoolLiteral);
+   const Expr *BoolLiteral);
 
   void
   replaceWithElseStatement(const ast_matchers::MatchFinder::MatchResult ,
-   const CXXBoolLiteralExpr *FalseConditionRemoved);
+   const Expr *FalseConditionRemoved);
 
   void
   replaceWithCondition(const ast_matchers::MatchFinder::MatchResult ,
Index: clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
@@ -58,16 +58,28 @@
 const char SimplifyConditionalReturnDiagnostic[] =
 "redundant boolean literal in conditional return statement";
 
-const CXXBoolLiteralExpr *getBoolLiteral(const MatchFinder::MatchResult ,
- StringRef Id) {
-  const auto *Literal = Result.Nodes.getNodeAs(Id);
-  return (Literal && Literal->getBeginLoc().isMacroID()) ? nullptr : Literal;
+const Expr *getBoolLiteral(const MatchFinder::MatchResult ,
+   StringRef Id) {
+  if (const Expr *Literal = Result.Nodes.getNodeAs(Id))
+return Literal->getBeginLoc().isMacroID() ? nullptr : Literal;
+  if (const auto *Negated = Result.Nodes.getNodeAs(Id)) {
+if (Negated->getOpcode() == UO_LNot &&
+isa(Negated->getSubExpr()))
+  return Negated->getBeginLoc().isMacroID() ? nullptr : Negated;
+  }
+  return nullptr;
+}
+
+internal::BindableMatcher literalOrNegatedBool(bool Value) {
+  return expr(anyOf(cxxBoolLiteral(equals(Value)),
+unaryOperator(hasUnaryOperand(ignoringParenImpCasts(
+  cxxBoolLiteral(equals(!Value,
+  hasOperatorName("!";
 }
 
 internal::Matcher returnsBool(bool Value, StringRef Id = "ignored") {
-  auto SimpleReturnsBool =
-  returnStmt(has(cxxBoolLiteral(equals(Value)).bind(Id)))
-  .bind("returns-bool");
+  auto SimpleReturnsBool = returnStmt(has(literalOrNegatedBool(Value).bind(Id)))
+   .bind("returns-bool");
   return anyOf(SimpleReturnsBool,
compoundStmt(statementCountIs(1), has(SimpleReturnsBool)));
 }
@@ -269,16 +281,25 @@
   return asBool(getText(Result, *E), NeedsStaticCast);
 }
 
-const CXXBoolLiteralExpr *stmtReturnsBool(const ReturnStmt *Ret, bool Negated) {
+const Expr *stmtReturnsBool(const ReturnStmt 

[clang-tools-extra] df5335a - [clang-tidy] readability-simplify-boolean-expr detects negated literals

2020-08-22 Thread Nathan James via cfe-commits

Author: Nathan James
Date: 2020-08-22T13:57:36+01:00
New Revision: df5335a36d3d70927d1834f31c705e31b4b3701f

URL: 
https://github.com/llvm/llvm-project/commit/df5335a36d3d70927d1834f31c705e31b4b3701f
DIFF: 
https://github.com/llvm/llvm-project/commit/df5335a36d3d70927d1834f31c705e31b4b3701f.diff

LOG: [clang-tidy] readability-simplify-boolean-expr detects negated literals

Adds support for detecting cases like `if (!true) ...`.
Addresses [[ https://bugs.llvm.org/show_bug.cgi?id=47166 | 
readability-simplify-boolean-expr not detected for negated boolean literals. ]]

Reviewed By: aaron.ballman

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

Added: 


Modified: 
clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.h

clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr.cpp

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
index 4c83499ff7ca..9dcb10b9d20c 100644
--- a/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
@@ -58,16 +58,28 @@ const char SimplifyConditionDiagnostic[] =
 const char SimplifyConditionalReturnDiagnostic[] =
 "redundant boolean literal in conditional return statement";
 
-const CXXBoolLiteralExpr *getBoolLiteral(const MatchFinder::MatchResult 
,
- StringRef Id) {
-  const auto *Literal = Result.Nodes.getNodeAs(Id);
-  return (Literal && Literal->getBeginLoc().isMacroID()) ? nullptr : Literal;
+const Expr *getBoolLiteral(const MatchFinder::MatchResult ,
+   StringRef Id) {
+  if (const Expr *Literal = Result.Nodes.getNodeAs(Id))
+return Literal->getBeginLoc().isMacroID() ? nullptr : Literal;
+  if (const auto *Negated = Result.Nodes.getNodeAs(Id)) {
+if (Negated->getOpcode() == UO_LNot &&
+isa(Negated->getSubExpr()))
+  return Negated->getBeginLoc().isMacroID() ? nullptr : Negated;
+  }
+  return nullptr;
+}
+
+internal::BindableMatcher literalOrNegatedBool(bool Value) {
+  return expr(anyOf(cxxBoolLiteral(equals(Value)),
+unaryOperator(hasUnaryOperand(ignoringParenImpCasts(
+  cxxBoolLiteral(equals(!Value,
+  hasOperatorName("!";
 }
 
 internal::Matcher returnsBool(bool Value, StringRef Id = "ignored") {
-  auto SimpleReturnsBool =
-  returnStmt(has(cxxBoolLiteral(equals(Value)).bind(Id)))
-  .bind("returns-bool");
+  auto SimpleReturnsBool = 
returnStmt(has(literalOrNegatedBool(Value).bind(Id)))
+   .bind("returns-bool");
   return anyOf(SimpleReturnsBool,
compoundStmt(statementCountIs(1), has(SimpleReturnsBool)));
 }
@@ -269,16 +281,25 @@ std::string replacementExpression(const 
MatchFinder::MatchResult ,
   return asBool(getText(Result, *E), NeedsStaticCast);
 }
 
-const CXXBoolLiteralExpr *stmtReturnsBool(const ReturnStmt *Ret, bool Negated) 
{
+const Expr *stmtReturnsBool(const ReturnStmt *Ret, bool Negated) {
   if (const auto *Bool = dyn_cast(Ret->getRetValue())) {
 if (Bool->getValue() == !Negated)
   return Bool;
   }
+  if (const auto *Unary = dyn_cast(Ret->getRetValue())) {
+if (Unary->getOpcode() == UO_LNot) {
+  if (const auto *Bool =
+  dyn_cast(Unary->getSubExpr())) {
+if (Bool->getValue() == Negated)
+  return Bool;
+  }
+}
+  }
 
   return nullptr;
 }
 
-const CXXBoolLiteralExpr *stmtReturnsBool(const IfStmt *IfRet, bool Negated) {
+const Expr *stmtReturnsBool(const IfStmt *IfRet, bool Negated) {
   if (IfRet->getElse() != nullptr)
 return nullptr;
 
@@ -423,7 +444,7 @@ void 
SimplifyBooleanExprCheck::matchBoolCondition(MatchFinder *Finder,
   StringRef BooleanId) {
   Finder->addMatcher(
   ifStmt(unless(isInTemplateInstantiation()),
- hasCondition(cxxBoolLiteral(equals(Value)).bind(BooleanId)))
+ hasCondition(literalOrNegatedBool(Value).bind(BooleanId)))
   .bind(IfStmtId),
   this);
 }
@@ -433,8 +454,8 @@ void 
SimplifyBooleanExprCheck::matchTernaryResult(MatchFinder *Finder,
   StringRef TernaryId) {
   Finder->addMatcher(
   conditionalOperator(unless(isInTemplateInstantiation()),
-  hasTrueExpression(cxxBoolLiteral(equals(Value))),
-  hasFalseExpression(cxxBoolLiteral(equals(!Value
+  hasTrueExpression(literalOrNegatedBool(Value)),
+  hasFalseExpression(literalOrNegatedBool(!Value)))
   .bind(TernaryId),
  

[PATCH] D86027: [analyzer] Add bool operator modeling for unque_ptr

2020-08-22 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp:130
+// Returns empty type if not found valid inner pointer type.
+static QualType getInnerPointerType(const CallEvent , CheckerContext ) {
+  QualType InnerType{};

vrnithinkumar wrote:
> It seems like a long shot to me.
> I am not sure is there any direct or easy way to get inner pointer type from 
> a smart pointer  
That's about right. You're doing exactly what you're asked: grab the template 
parameter of the class. The problem is indeed that complicated!



Comment at: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp:145
+TemplateArgs.size() > 0 &&
+"Smart pointer should have specialized with atleast one template 
type");
+auto InnerValueType = TemplateArgs[0].getAsType();

That's pretty fundamental, right? If it's a specialization, it must have 
something specialized. It isn't specific to unique pointers, right?

Because unique pointers aren't special; technically anybody can define an 
arbitrary class with name `std::unique_ptr` and any properties they'd like. 
It's going to be undefined behavior according to the standard (because 
namespace `std` is explicitly reserved for the standard library) but if the 
compiler *crashes* it'll still be our fault.





Comment at: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp:448
+
+if (NullState) {
+  auto NullVal = C.getSValBuilder().makeNull();

There's no need to check. You just conjured a brand new symbol out of thin air; 
you can be sure that it's completely unconstrained and both states are 
feasible. You can instead `assert()` that they're both feasible.



Comment at: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp:458-460
+OS << "Assuming smart pointer ";
+ThisRegion->printPretty(OS);
+OS << " is null";

Wait, what happens when the region can't be pretty-printed? Does it print two 
spaces between "pointer" and "is"?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86027/new/

https://reviews.llvm.org/D86027

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


[PATCH] D86029: [analyzer] Add modeling for unque_ptr::get()

2020-08-22 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ accepted this revision.
NoQ added a comment.

This patch looks correct to me at a glance. I think we should land it as is and 
debug/improve later.




Comment at: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp:362-363
+  const auto *InnerPointVal = State->get(ThisRegion);
+  if (!InnerPointVal)
+return;
+

vrnithinkumar wrote:
> vrnithinkumar wrote:
> > xazax.hun wrote:
> > > NoQ wrote:
> > > > You'll have to actively handle this case, sooner or later. Consider the 
> > > > following test cases that won't work until you do:
> > > > ```lang=c++
> > > > void foo(std::unique_ptr p) {
> > > >   A *x = p.get();
> > > >   A *y = p.get();
> > > >   clang_analyzer_eval(x == y); // expected-warning{{TRUE}}
> > > >   if (!x) {
> > > > y->foo(); // expected-warning{{Called C++ object pointer is null}}
> > > >   }
> > > > }
> > > > 
> > > > ```
> > > You mean the case where we do not have an inner pointer registered in the 
> > > state yet, right?
> > > 
> > > I believe we might also have to handle similar cases for `operator 
> > > bool()` as well. 
> > Added the above test case. 
> > Using conjureSymbolVal in case of missing inner pointer value
> ```
> void foo(std::unique_ptr P) {
>   A *X = P.get();
>   if (!X) {
> P->foo(); // expected-warning {{Dereference of null smart pointer 'Pl' 
> [alpha.cplusplus.SmartPtr]}}
>   }
> }
> ```
> I was trying to add the above use case. Since we are using conjureSymbolVal 
> in case of missing inner pointer value.
> 
> But still the inner pointer value is constrained to [0, 0] in false branch, 
> `InnerPointVal->isZeroConstant()` returning false. 
> Also I tried `State->isNull(*InnerPointVal).isConstrainedTrue();` This is 
> also not working.
> How should we check whether the conjureSymbolVal for inner pointer value is 
> constrained to [0, 0]?
> How should we check whether the conjureSymbolVal for inner pointer value is 
> constrained to [0, 0]?

View exploded graphs. That's literally the only reasonable answer to every such 
question. In particular, it shows you constraints for all symbols at every 
moment of time, and given that you implemented `printState()` it also shows you 
inner pointer values that you keep track of at every moment of time.

Check if it's still the same symbol. Check that the symbol lives long enough - 
or does it get forgotten about in the middle? - if so you might need to get 
your `checkLiveSymbols` callback right.

Please let us know if you still can't seem to debug it on your own.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86029/new/

https://reviews.llvm.org/D86029

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


[PATCH] D86295: [analyzer] Reorder the layout of MemRegion and cache by hand for optimal size

2020-08-22 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

In D86295#2230603 , @steakhal wrote:

> In D86295#2229712 , @NoQ wrote:
>
>> Heh, nice! Did you try to measure the actual impact of this change on memory 
>> and/or performance?
>
> Eh, I don't really know how to bench this.

I mean, like, you can measure the entire process with `time` or something like 
that. I believe @vsavchenko's docker thingy already knows how to do that.

> It seems that at least with this configuration the `MemRegion::getAsOffset` 
> was called every single time.

What i'm trying to say is that for almost every region //R// it's a trivial 
O(1) operation that yields `RegionOffset` (//R//, +0). It is only non-trivial 
for non-base regions like `FieldRegion` or `ElementRegion` or, well, 
`CXXBaseObjectRegion`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86295/new/

https://reviews.llvm.org/D86295

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