r371920 - [clang-scan-deps] Add -M to work around -MT issue after r371918

2019-09-14 Thread Fangrui Song via cfe-commits
Author: maskray
Date: Sat Sep 14 00:25:27 2019
New Revision: 371920

URL: http://llvm.org/viewvc/llvm-project?rev=371920&view=rev
Log:
[clang-scan-deps] Add -M to work around -MT issue after r371918

gcc will complain if -MT is used but neither -M nor -MM is specified:

> cc1: error: to generate dependencies you must specify either -M or -MM

r371918 changed our behavior to match GCC, but apparently
clang-scan-deps is not happy.

Modified:
cfe/trunk/tools/clang-scan-deps/ClangScanDeps.cpp

Modified: cfe/trunk/tools/clang-scan-deps/ClangScanDeps.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-scan-deps/ClangScanDeps.cpp?rev=371920&r1=371919&r2=371920&view=diff
==
--- cfe/trunk/tools/clang-scan-deps/ClangScanDeps.cpp (original)
+++ cfe/trunk/tools/clang-scan-deps/ClangScanDeps.cpp Sat Sep 14 00:25:27 2019
@@ -242,6 +242,7 @@ int main(int argc, const char **argv) {
 AdjustedArgs.push_back("-o");
 AdjustedArgs.push_back("/dev/null");
 if (!HasMT && !HasMQ) {
+  AdjustedArgs.push_back("-M");
   AdjustedArgs.push_back("-MT");
   // We're interested in source dependencies of an object file.
   if (!HasMD) {


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


[PATCH] D67584: [Support] Replace function with function_ref in writeFileAtomically. NFC

2019-09-14 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov created this revision.
ilya-biryukov added a reviewer: jkorous.
Herald added subscribers: llvm-commits, jfb, dexonsmith, hiraditya.
Herald added a project: LLVM.

The latter is slightly more efficient and communicates the intent of the
API: writeFileAtomically does not own or copy the callback, it merely
calls it at some point.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D67584

Files:
  llvm/include/llvm/Support/FileUtilities.h
  llvm/lib/Support/FileUtilities.cpp


Index: llvm/lib/Support/FileUtilities.cpp
===
--- llvm/lib/Support/FileUtilities.cpp
+++ llvm/lib/Support/FileUtilities.cpp
@@ -296,7 +296,7 @@
 
 llvm::Error llvm::writeFileAtomically(
 StringRef TempPathModel, StringRef FinalPath,
-std::function Writer) {
+llvm::function_ref Writer) {
   SmallString<128> GeneratedUniqPath;
   int TempFD;
   if (sys::fs::createUniqueFile(TempPathModel.str(), TempFD,
Index: llvm/include/llvm/Support/FileUtilities.h
===
--- llvm/include/llvm/Support/FileUtilities.h
+++ llvm/include/llvm/Support/FileUtilities.h
@@ -14,6 +14,7 @@
 #ifndef LLVM_SUPPORT_FILEUTILITIES_H
 #define LLVM_SUPPORT_FILEUTILITIES_H
 
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Errc.h"
 #include "llvm/Support/ErrorHandling.h"
@@ -109,7 +110,7 @@
 
   llvm::Error
   writeFileAtomically(StringRef TempPathModel, StringRef FinalPath,
-  std::function Writer);
+  llvm::function_ref 
Writer);
 } // End llvm namespace
 
 #endif


Index: llvm/lib/Support/FileUtilities.cpp
===
--- llvm/lib/Support/FileUtilities.cpp
+++ llvm/lib/Support/FileUtilities.cpp
@@ -296,7 +296,7 @@
 
 llvm::Error llvm::writeFileAtomically(
 StringRef TempPathModel, StringRef FinalPath,
-std::function Writer) {
+llvm::function_ref Writer) {
   SmallString<128> GeneratedUniqPath;
   int TempFD;
   if (sys::fs::createUniqueFile(TempPathModel.str(), TempFD,
Index: llvm/include/llvm/Support/FileUtilities.h
===
--- llvm/include/llvm/Support/FileUtilities.h
+++ llvm/include/llvm/Support/FileUtilities.h
@@ -14,6 +14,7 @@
 #ifndef LLVM_SUPPORT_FILEUTILITIES_H
 #define LLVM_SUPPORT_FILEUTILITIES_H
 
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Errc.h"
 #include "llvm/Support/ErrorHandling.h"
@@ -109,7 +110,7 @@
 
   llvm::Error
   writeFileAtomically(StringRef TempPathModel, StringRef FinalPath,
-  std::function Writer);
+  llvm::function_ref Writer);
 } // End llvm namespace
 
 #endif
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D67584: [Support] Replace function with function_ref in writeFileAtomically. NFC

2019-09-14 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov updated this revision to Diff 220209.
ilya-biryukov added a comment.

- Reformat


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D67584

Files:
  llvm/include/llvm/Support/FileUtilities.h
  llvm/lib/Support/FileUtilities.cpp


Index: llvm/lib/Support/FileUtilities.cpp
===
--- llvm/lib/Support/FileUtilities.cpp
+++ llvm/lib/Support/FileUtilities.cpp
@@ -296,7 +296,7 @@
 
 llvm::Error llvm::writeFileAtomically(
 StringRef TempPathModel, StringRef FinalPath,
-std::function Writer) {
+llvm::function_ref Writer) {
   SmallString<128> GeneratedUniqPath;
   int TempFD;
   if (sys::fs::createUniqueFile(TempPathModel.str(), TempFD,
Index: llvm/include/llvm/Support/FileUtilities.h
===
--- llvm/include/llvm/Support/FileUtilities.h
+++ llvm/include/llvm/Support/FileUtilities.h
@@ -14,6 +14,7 @@
 #ifndef LLVM_SUPPORT_FILEUTILITIES_H
 #define LLVM_SUPPORT_FILEUTILITIES_H
 
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Errc.h"
 #include "llvm/Support/ErrorHandling.h"
@@ -107,9 +108,9 @@
   llvm::Error writeFileAtomically(StringRef TempPathModel, StringRef FinalPath,
   StringRef Buffer);
 
-  llvm::Error
-  writeFileAtomically(StringRef TempPathModel, StringRef FinalPath,
-  std::function Writer);
+  llvm::Error writeFileAtomically(
+  StringRef TempPathModel, StringRef FinalPath,
+  llvm::function_ref Writer);
 } // End llvm namespace
 
 #endif


Index: llvm/lib/Support/FileUtilities.cpp
===
--- llvm/lib/Support/FileUtilities.cpp
+++ llvm/lib/Support/FileUtilities.cpp
@@ -296,7 +296,7 @@
 
 llvm::Error llvm::writeFileAtomically(
 StringRef TempPathModel, StringRef FinalPath,
-std::function Writer) {
+llvm::function_ref Writer) {
   SmallString<128> GeneratedUniqPath;
   int TempFD;
   if (sys::fs::createUniqueFile(TempPathModel.str(), TempFD,
Index: llvm/include/llvm/Support/FileUtilities.h
===
--- llvm/include/llvm/Support/FileUtilities.h
+++ llvm/include/llvm/Support/FileUtilities.h
@@ -14,6 +14,7 @@
 #ifndef LLVM_SUPPORT_FILEUTILITIES_H
 #define LLVM_SUPPORT_FILEUTILITIES_H
 
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Errc.h"
 #include "llvm/Support/ErrorHandling.h"
@@ -107,9 +108,9 @@
   llvm::Error writeFileAtomically(StringRef TempPathModel, StringRef FinalPath,
   StringRef Buffer);
 
-  llvm::Error
-  writeFileAtomically(StringRef TempPathModel, StringRef FinalPath,
-  std::function Writer);
+  llvm::Error writeFileAtomically(
+  StringRef TempPathModel, StringRef FinalPath,
+  llvm::function_ref Writer);
 } // End llvm namespace
 
 #endif
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D63960: [C++20] Add consteval-specific semantic for functions

2019-09-14 Thread Tyker via Phabricator via cfe-commits
Tyker added a comment.

@rsmith Ping


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

https://reviews.llvm.org/D63960



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


[PATCH] D67585: [clang] [cmake] Make building dylib optional

2019-09-14 Thread Michał Górny via Phabricator via cfe-commits
mgorny created this revision.
mgorny added reviewers: tstellar, sylvestre.ledru, smeenai, beanz.

Similarly to how LLVM dylib can be disabled via LLVM_BUILD_LLVM_DYLIB,
introduce CLANG_BUILD_CLANG_DYLIB to make it possible to disable
building clang's dylib.  This is useful for pure testing environments
where linking huge libraries can take a lot of memory/time.


https://reviews.llvm.org/D67585

Files:
  clang/CMakeLists.txt
  clang/tools/clang-shlib/CMakeLists.txt


Index: clang/tools/clang-shlib/CMakeLists.txt
===
--- clang/tools/clang-shlib/CMakeLists.txt
+++ clang/tools/clang-shlib/CMakeLists.txt
@@ -1,5 +1,5 @@
 # Building libclang-cpp.so fails if LLVM_ENABLE_PIC=Off
-if (NOT LLVM_ENABLE_PIC)
+if (NOT LLVM_ENABLE_PIC OR NOT CLANG_BUILD_CLANG_DYLIB)
   return()
 endif()
 
Index: clang/CMakeLists.txt
===
--- clang/CMakeLists.txt
+++ clang/CMakeLists.txt
@@ -322,6 +322,8 @@
 set(CLANG_PYTHON_BINDINGS_VERSIONS "" CACHE STRING
 "Python versions to install libclang python bindings for")
 
+set(CLANG_BUILD_CLANG_DYLIB ON CACHE BOOL
+"Build libclang-cpp.so dynamic library")
 set(CLANG_LINK_CLANG_DYLIB ${LLVM_LINK_LLVM_DYLIB} CACHE BOOL
 "Link tools against libclang-cpp.so")
 


Index: clang/tools/clang-shlib/CMakeLists.txt
===
--- clang/tools/clang-shlib/CMakeLists.txt
+++ clang/tools/clang-shlib/CMakeLists.txt
@@ -1,5 +1,5 @@
 # Building libclang-cpp.so fails if LLVM_ENABLE_PIC=Off
-if (NOT LLVM_ENABLE_PIC)
+if (NOT LLVM_ENABLE_PIC OR NOT CLANG_BUILD_CLANG_DYLIB)
   return()
 endif()
 
Index: clang/CMakeLists.txt
===
--- clang/CMakeLists.txt
+++ clang/CMakeLists.txt
@@ -322,6 +322,8 @@
 set(CLANG_PYTHON_BINDINGS_VERSIONS "" CACHE STRING
 "Python versions to install libclang python bindings for")
 
+set(CLANG_BUILD_CLANG_DYLIB ON CACHE BOOL
+"Build libclang-cpp.so dynamic library")
 set(CLANG_LINK_CLANG_DYLIB ${LLVM_LINK_LLVM_DYLIB} CACHE BOOL
 "Link tools against libclang-cpp.so")
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D67409: [RISCV] enable LTO support, pass some options to linker.

2019-09-14 Thread Kuan Hsu Chen via Phabricator via cfe-commits
khchen updated this revision to Diff 220214.
khchen edited the summary of this revision.
khchen added a comment.
Herald added subscribers: fedor.sergeev, aheejin, dschuff.

This commit is inspired by @MaskRay's suggestion, I think maybe fix the 
insufficient of clang::driver:tools::AddGoldPlugin is good choose.


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

https://reviews.llvm.org/D67409

Files:
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/lib/Driver/ToolChains/CommonArgs.h
  clang/lib/Driver/ToolChains/RISCVToolchain.cpp
  clang/lib/Driver/ToolChains/RISCVToolchain.h
  clang/test/Driver/gold-lto.c

Index: clang/test/Driver/gold-lto.c
===
--- clang/test/Driver/gold-lto.c
+++ clang/test/Driver/gold-lto.c
@@ -26,3 +26,21 @@
 // RUN: %clang -target i686-linux-android -### %t.o -flto 2>&1 \
 // RUN: | FileCheck %s --check-prefix=CHECK-X86-ANDROID
 // CHECK-X86-ANDROID: "-plugin" "{{.*}}{{[/\\]}}LLVMgold.{{dll|dylib|so}}"
+//
+// RUN: %clang -target riscv64-unknown-elf -### %t.o -flto 2>&1 \
+// RUN: -march=rv64imf -mabi=lp64f \
+// RUN: | FileCheck %s --check-prefix=CHECK-RISCV-BAREMETAL
+// CHECK-RISCV-BAREMETAL: "-plugin" "{{.*}}{{[/\\]}}LLVMgold.{{dll|dylib|so}}"
+// CHECK-RISCV-BAREMETAL: "-plugin-opt=-mattr=+m"
+// CHECK-RISCV-BAREMETAL: "-plugin-opt=-mattr=+f"
+// CHECK-RISCV-BAREMETAL: "-plugin-opt=-mattr=+relax"
+// CHECK-RISCV-BAREMETAL: "-plugin-opt=-target-abi=lp64f"
+//
+// RUN: %clang -target riscv64-unknown-linux-gnu -### %t.o -flto 2>&1 \
+// RUN: -march=rv64imf -mabi=lp64f \
+// RUN: | FileCheck %s --check-prefix=CHECK-RISCV-LINUX
+// CHECK-RISCV-LINUX: "-plugin" "{{.*}}{{[/\\]}}LLVMgold.{{dll|dylib|so}}"
+// CHECK-RISCV-LINUX: "-plugin-opt=-mattr=+m"
+// CHECK-RISCV-LINUX: "-plugin-opt=-mattr=+f"
+// CHECK-RISCV-LINUX: "-plugin-opt=-mattr=+relax"
+// CHECK-RISCV-LINUX: "-plugin-opt=-target-abi=lp64f"
Index: clang/lib/Driver/ToolChains/RISCVToolchain.h
===
--- clang/lib/Driver/ToolChains/RISCVToolchain.h
+++ clang/lib/Driver/ToolChains/RISCVToolchain.h
@@ -25,6 +25,7 @@
   void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
  llvm::opt::ArgStringList &CC1Args,
  Action::OffloadKind) const override;
+  bool HasNativeLLVMSupport() const override { return true; }
   void
   AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
 llvm::opt::ArgStringList &CC1Args) const override;
Index: clang/lib/Driver/ToolChains/RISCVToolchain.cpp
===
--- clang/lib/Driver/ToolChains/RISCVToolchain.cpp
+++ clang/lib/Driver/ToolChains/RISCVToolchain.cpp
@@ -7,6 +7,7 @@
 //===--===//
 
 #include "RISCVToolchain.h"
+#include "Arch/RISCV.h"
 #include "CommonArgs.h"
 #include "InputInfo.h"
 #include "clang/Driver/Compilation.h"
@@ -100,6 +101,12 @@
 
   std::string Linker = getToolChain().GetProgramPath(getShortName());
 
+  if (D.isUsingLTO()) {
+assert(!Inputs.empty() && "Must have at least one input.");
+AddGoldPlugin(ToolChain, Args, CmdArgs, Output, Inputs[0],
+  D.getLTOMode() == LTOK_Thin);
+  }
+
   bool WantCRTs =
   !Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles);
 
Index: clang/lib/Driver/ToolChains/CommonArgs.h
===
--- clang/lib/Driver/ToolChains/CommonArgs.h
+++ clang/lib/Driver/ToolChains/CommonArgs.h
@@ -125,6 +125,14 @@
 void addMultilibFlag(bool Enabled, const char *const Flag,
  Multilib::flags_list &Flags);
 
+StringRef getTargetABI(const llvm::opt::ArgList &Args,
+   const llvm::Triple &Triple);
+
+void getTargetFeatures(const ToolChain &TC, const llvm::Triple &Triple,
+   const llvm::opt::ArgList &Args,
+   llvm::opt::ArgStringList &CmdArgs, bool ForAS,
+   bool ForLTOPlugin);
+
 } // end namespace tools
 } // end namespace driver
 } // end namespace clang
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -11,8 +11,12 @@
 #include "Arch/ARM.h"
 #include "Arch/Mips.h"
 #include "Arch/PPC.h"
+#include "Arch/RISCV.h"
+#include "Arch/Sparc.h"
 #include "Arch/SystemZ.h"
 #include "Arch/X86.h"
+#include "AMDGPU.h"
+#include "MSP430.h"
 #include "HIP.h"
 #include "Hexagon.h"
 #include "InputInfo.h"
@@ -490,6 +494,14 @@
   if (!StatsFile.empty())
 CmdArgs.push_back(
 Args.MakeArgString(Twine("-plugin-opt=stats-file=") + StatsFile));
+
+  getTargetFeatures(ToolChain, ToolChain.getTri

[PATCH] D45050: [clang-tidy] New checker for not null-terminated result caused by strlen(), size() or equal length

2019-09-14 Thread Csaba Dabis via Phabricator via cfe-commits
Charusso updated this revision to Diff 220215.
Charusso edited the summary of this revision.
Charusso removed reviewers: hokein, ilya-biryukov, xbolva00, dyung.
Charusso set the repository for this revision to rCTE Clang Tools Extra.
Charusso added a comment.
Herald added a project: clang.

After a while I try to make this patch arrive. I wanted to split it up to 
multiple patches, but everything tied together so I decided to fix false 
positives instead with improving the existing APIs. Please visit the diff of 
the test cases and the documentation to see the changes.

Here are some interesting findings:

  bitcoin/src/leveldb/db/c.cc:
  - char* result = reinterpret_cast(malloc(sizeof(char) * str.size()));
  - memcpy(result, str.data(), sizeof(char) * str.size());
  + char* result = reinterpret_cast(malloc((sizeof(char) * str.size()) + 
1));
  + strcpy(result, str.data());
  
  ffmpeg/libavformat/avio.c:
  - memmove(start, key+1, strlen(key));
  + memmove(start, key+1, strlen(key) + 1);
  
  ffmpeg/libavformat/mpeg.c:
  - memcpy(ext, !strncmp(ext, "IDX", 3) ? "SUB" : "sub", 3);
  + strcpy(ext, !strncmp(ext, "IDX", 3) ? "SUB" : "sub");
  
  ffmpeg/libavformat/oggparseskeleton.c:
  - strncmp(buf, "fishead", 8)
  + strncmp(buf, "fishead", 7)
  
  sqlite/shell.c:
  #define APND_MARK_PREFIX "Start-Of-SQLite3-"
  #define APND_MARK_PREFIX_SZ  17
  unsigned char a[APND_MARK_SIZE];
  - memcpy(a, APND_MARK_PREFIX, APND_MARK_PREFIX_SZ);
  + strcpy((char *)a, APND_MARK_PREFIX);


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D45050

Files:
  clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
  clang-tools-extra/clang-tidy/bugprone/NotNullTerminatedResultCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/NotNullTerminatedResultCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/bugprone-not-null-terminated-result.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/test/clang-tidy/Inputs/bugprone-not-null-terminated-result/not-null-terminated-result-c.h
  
clang-tools-extra/test/clang-tidy/Inputs/bugprone-not-null-terminated-result/not-null-terminated-result-cxx.h
  
clang-tools-extra/test/clang-tidy/bugprone-not-null-terminated-result-in-initialization-strlen.c
  
clang-tools-extra/test/clang-tidy/bugprone-not-null-terminated-result-memcpy-before-safe.c
  
clang-tools-extra/test/clang-tidy/bugprone-not-null-terminated-result-memcpy-safe-cxx.cpp
  
clang-tools-extra/test/clang-tidy/bugprone-not-null-terminated-result-memcpy-safe-other.c
  
clang-tools-extra/test/clang-tidy/bugprone-not-null-terminated-result-memcpy-safe.c
  clang-tools-extra/test/clang-tidy/bugprone-not-null-terminated-result-strlen.c
  
clang-tools-extra/test/clang-tidy/bugprone-not-null-terminated-result-wcslen.cpp
  
clang-tools-extra/test/clang-tidy/bugprone-not-null-terminated-result-wmemcpy-safe-cxx.cpp

Index: clang-tools-extra/test/clang-tidy/bugprone-not-null-terminated-result-wmemcpy-safe-cxx.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/bugprone-not-null-terminated-result-wmemcpy-safe-cxx.cpp
@@ -0,0 +1,111 @@
+// RUN: %check_clang_tidy %s bugprone-not-null-terminated-result %t -- \
+// RUN: -- -std=c++11 -I %S/Inputs/bugprone-not-null-terminated-result
+
+#include "not-null-terminated-result-cxx.h"
+
+#define __STDC_LIB_EXT1__ 1
+#define __STDC_WANT_LIB_EXT1__ 1
+
+//===--===//
+// wmemcpy() - destination array tests
+//===--===//
+
+void bad_wmemcpy_known_dest(const wchar_t *src) {
+  wchar_t dest01[13];
+  wmemcpy(dest01, src, wcslen(src));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: the result from calling 'wmemcpy' is not null-terminated [bugprone-not-null-terminated-result]
+  // CHECK-FIXES: wchar_t dest01[14];
+  // CHECK-FIXES-NEXT: wcscpy_s(dest01, src);
+}
+
+void good_wmemcpy_known_dest(const wchar_t *src) {
+  wchar_t dst01[14];
+  wcscpy_s(dst01, src);
+}
+
+//===--===//
+// wmemcpy() - length tests
+//===--===//
+
+void bad_wmemcpy_full_source_length(const wchar_t *src) {
+  wchar_t dest20[13];
+  wmemcpy(dest20, src, wcslen(src));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: the result from calling 'wmemcpy' is not null-terminated [bugprone-not-null-terminated-result]
+  // CHECK-FIXES: wchar_t dest20[14];
+  // CHECK-FIXES-NEXT: wcscpy_s(dest20, src);
+}
+
+void good_wmemcpy_full_source_length(const wchar_t *src) {
+  wchar_t dst20[14];
+  wcscpy_s(dst20, src);
+}
+
+void bad_wmemcpy_partial_source_length(const wchar_t *src) {
+  wchar_t dest21[13];
+  wmemcpy(de

[PATCH] D45050: [clang-tidy] New checker for not null-terminated result caused by strlen(), size() or equal length

2019-09-14 Thread Csaba Dabis via Phabricator via cfe-commits
Charusso added a comment.

Hm, I wanted to upload the new patch here to see the changes with the 
diff-mode, but it does not work, sorry.


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D45050



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


[PATCH] D67385: Pass -mcmodel to LTO plugin

2019-09-14 Thread Kuan Hsu Chen via Phabricator via cfe-commits
khchen updated this revision to Diff 220218.
khchen retitled this revision from "Pass -mcmodel to gold-pulgin" to "Pass 
-mcmodel to LTO plugin".
khchen edited the summary of this revision.
khchen added a comment.
Herald added subscribers: steven_wu, inglorion.

added a test


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

https://reviews.llvm.org/D67385

Files:
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/test/Driver/lto.c


Index: clang/test/Driver/lto.c
===
--- clang/test/Driver/lto.c
+++ clang/test/Driver/lto.c
@@ -58,3 +58,7 @@
 //
 // CHECK-TUNING-LLDB:   "-plugin-opt=-debugger-tune=lldb"
 // CHECK-NO-TUNING-NOT: "-plugin-opt=-debugger-tune
+
+// RUN: %clang -target x86_64-unknown-linux -### %s -flto -mcmodel=small 2> %t
+// RUN: FileCheck -check-prefix=CHECK-CODE-MODEL-OPTION < %t %s
+// CHECK-CODE-MODEL-OPTION: "-plugin-opt=-code-model=small"
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -396,6 +396,12 @@
   CmdArgs.push_back(Args.MakeArgString(Twine("-plugin-opt=O") + OOpt));
   }
 
+  if (const Arg *A = Args.getLastArg(options::OPT_mcmodel_EQ)) {
+StringRef ModelArg = A->getValue();
+CmdArgs.push_back(
+Args.MakeArgString(Twine("-plugin-opt=-code-model=") + ModelArg));
+  }
+
   if (Args.hasArg(options::OPT_gsplit_dwarf)) {
 CmdArgs.push_back(
 Args.MakeArgString(Twine("-plugin-opt=dwo_dir=") +


Index: clang/test/Driver/lto.c
===
--- clang/test/Driver/lto.c
+++ clang/test/Driver/lto.c
@@ -58,3 +58,7 @@
 //
 // CHECK-TUNING-LLDB:   "-plugin-opt=-debugger-tune=lldb"
 // CHECK-NO-TUNING-NOT: "-plugin-opt=-debugger-tune
+
+// RUN: %clang -target x86_64-unknown-linux -### %s -flto -mcmodel=small 2> %t
+// RUN: FileCheck -check-prefix=CHECK-CODE-MODEL-OPTION < %t %s
+// CHECK-CODE-MODEL-OPTION: "-plugin-opt=-code-model=small"
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -396,6 +396,12 @@
   CmdArgs.push_back(Args.MakeArgString(Twine("-plugin-opt=O") + OOpt));
   }
 
+  if (const Arg *A = Args.getLastArg(options::OPT_mcmodel_EQ)) {
+StringRef ModelArg = A->getValue();
+CmdArgs.push_back(
+Args.MakeArgString(Twine("-plugin-opt=-code-model=") + ModelArg));
+  }
+
   if (Args.hasArg(options::OPT_gsplit_dwarf)) {
 CmdArgs.push_back(
 Args.MakeArgString(Twine("-plugin-opt=dwo_dir=") +
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D67585: [clang] [cmake] Make building dylib optional

2019-09-14 Thread Chris Bieneman via Phabricator via cfe-commits
beanz requested changes to this revision.
beanz added a comment.
This revision now requires changes to proceed.

Please no. You don’t need to build the library. ‘check-clang’ doesn’t depend on 
it, so it should not impact your build and test cycles. We want it included in 
the ‘all’ target for every possible configuration so that it gets tested and 
not broken as frequently as the LLVM dylib target has in the past.

If you don’t want to link it you can avoid linking it by running the ‘check’ 
targets instead of building ‘all’. In general, I believe we need to reduce the 
number of options for configuring the LLVM build. The build system has reached 
a point where the number of possible configurations is so massive that the 
build system is fragile and becoming more challenging to modify.


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

https://reviews.llvm.org/D67585



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


[PATCH] D67585: [clang] [cmake] Make building dylib optional

2019-09-14 Thread Michał Górny via Phabricator via cfe-commits
mgorny added a comment.

Sure but I want to build-test practically everything else. I wouldn't mind if 
this didn't basically kill my test system by resource exhaustion.


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

https://reviews.llvm.org/D67585



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


[PATCH] D67585: [clang] [cmake] Make building dylib optional

2019-09-14 Thread Michał Górny via Phabricator via cfe-commits
mgorny added a comment.

Also note that I'm leaving it enabled by default, so only people explicitly 
opting out would not be testing it.


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

https://reviews.llvm.org/D67585



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


[PATCH] D67585: [clang] [cmake] Make building dylib optional

2019-09-14 Thread Chris Bieneman via Phabricator via cfe-commits
beanz added a comment.

In D67585#1670420 , @mgorny wrote:

> Sure but I want to build-test practically everything else. I wouldn't mind if 
> this didn't basically kill my test system by resource exhaustion


You can use the ‘LLVM_DISTRIBUTION_COMPONENTS’ option to create a build test 
target that includes the things you care to test.


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

https://reviews.llvm.org/D67585



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


[PATCH] D67585: [clang] [cmake] Make building dylib optional

2019-09-14 Thread Michał Górny via Phabricator via cfe-commits
mgorny added a comment.

In D67585#1670422 , @beanz wrote:

> In D67585#1670420 , @mgorny wrote:
>
> > Sure but I want to build-test practically everything else. I wouldn't mind 
> > if this didn't basically kill my test system by resource exhaustion
>
>
> You can use the ‘LLVM_DISTRIBUTION_COMPONENTS’ option to create a build test 
> target that includes the things you care to test.


This is really much more work than disabling the one component I don't need or 
care for, especially when I do shared lib build and therefore the additional 
library is entirely useless.


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

https://reviews.llvm.org/D67585



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


[PATCH] D67368: [NFCI]Create CommonAttributeInfo Type as base type of *Attr and ParsedAttr.

2019-09-14 Thread Sebastian Pop via Phabricator via cfe-commits
sebpop added a comment.

I still see a link error on aarch64-linux on master:

  /usr/bin/ld: tools/clang/lib/AST/CMakeFiles/obj.clangAST.dir/AttrImpl.cpp.o: 
in function `clang::AttributeCommonInfo::getAttributeSpellingListIndex() const':
  
/home/ubuntu/llvm-project/llvm/tools/clang/include/clang/Basic/AttributeCommonInfo.h:166:
 undefined reference to 
`clang::AttributeCommonInfo::calculateAttributeSpellingListIndex() const'
  collect2: error: ld returned 1 exit status

I reverted locally this patch and it finishes building.


Repository:
  rL LLVM

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

https://reviews.llvm.org/D67368



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


[PATCH] D67420: [analyzer] NFC: Separate PathDiagnosticConsumer options from AnalyzerOptions.

2019-09-14 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus added a comment.

Aha, so every user gets to create their own `PathDiagnosticConsumerOptions` 
object, makes sense! There is no interface misconception, because 
`-analyzer-config` will only configure what the analyzer would tinket with. I 
like this patch! If you dont mind, I'd prefer to have one last round with this, 
but otherwise LGTM.




Comment at: clang/include/clang/Analysis/PathDiagnostic.h:63
+/// Most of these options are currently supported by very few consumers.
+struct PathDiagnosticConsumerOptions {
+  /// Whether to include additional information about macro expansions

Lets delete the default constructor. It would be an option to generate this 
with the analyzer secific `.def` file, but since we have so few users, lets 
force them to create this object manually :)


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

https://reviews.llvm.org/D67420



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


Re: r371918 - [Driver] Fix multiple bugs related to dependency file options: -M -MM -MD -MMD -MT -MQ

2019-09-14 Thread Nico Weber via cfe-commits
This looks similar to https://reviews.llvm.org/D67542

On Sat, Sep 14, 2019 at 1:59 AM Fangrui Song via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: maskray
> Date: Fri Sep 13 23:01:22 2019
> New Revision: 371918
>
> URL: http://llvm.org/viewvc/llvm-project?rev=371918&view=rev
> Log:
> [Driver] Fix multiple bugs related to dependency file options: -M -MM -MD
> -MMD -MT -MQ
>
> -M -o test.i => dependency file is test.d, not test.i
> -MM -o test.i => dependency file is test.d, not test.i
> -M -MMD => bogus warning -Wunused-command-line-argument
> -M MT dummy => -w not rendered
>
> Modified:
> cfe/trunk/lib/Driver/Driver.cpp
> cfe/trunk/lib/Driver/ToolChains/Clang.cpp
> cfe/trunk/test/Driver/m-and-mm.c
>
> Modified: cfe/trunk/lib/Driver/Driver.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Driver.cpp?rev=371918&r1=371917&r2=371918&view=diff
>
> ==
> --- cfe/trunk/lib/Driver/Driver.cpp (original)
> +++ cfe/trunk/lib/Driver/Driver.cpp Fri Sep 13 23:01:22 2019
> @@ -3450,8 +3450,10 @@ Action *Driver::ConstructPhaseAction(
>  llvm_unreachable("link action invalid here.");
>case phases::Preprocess: {
>  types::ID OutputTy;
> -// -{M, MM} alter the output type.
> -if (Args.hasArg(options::OPT_M, options::OPT_MM)) {
> +// -M and -MM specify the dependency file name by altering the output
> type,
> +// -if -MD and -MMD are not specified.
> +if (Args.hasArg(options::OPT_M, options::OPT_MM) &&
> +!Args.hasArg(options::OPT_MD, options::OPT_MMD)) {
>OutputTy = types::TY_Dependencies;
>  } else {
>OutputTy = Input->getType();
>
> Modified: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Clang.cpp?rev=371918&r1=371917&r2=371918&view=diff
>
> ==
> --- cfe/trunk/lib/Driver/ToolChains/Clang.cpp (original)
> +++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp Fri Sep 13 23:01:22 2019
> @@ -1061,7 +1061,6 @@ void Clang::AddPreprocessingOptions(Comp
>  ArgStringList &CmdArgs,
>  const InputInfo &Output,
>  const InputInfoList &Inputs) const {
> -  Arg *A;
>const bool IsIAMCU = getToolChain().getTriple().isOSIAMCU();
>
>CheckPreprocessingOptions(D, Args);
> @@ -1070,9 +1069,20 @@ void Clang::AddPreprocessingOptions(Comp
>Args.AddLastArg(CmdArgs, options::OPT_CC);
>
>// Handle dependency file generation.
> -  if ((A = Args.getLastArg(options::OPT_M, options::OPT_MM)) ||
> -  (A = Args.getLastArg(options::OPT_MD)) ||
> -  (A = Args.getLastArg(options::OPT_MMD))) {
> +  Arg *ArgM = Args.getLastArg(options::OPT_MM);
> +  if (!ArgM)
> +ArgM = Args.getLastArg(options::OPT_M);
> +  Arg *ArgMD = Args.getLastArg(options::OPT_MMD);
> +  if (!ArgMD)
> +ArgMD = Args.getLastArg(options::OPT_MD);
> +
> +  // -M and -MM imply -w.
> +  if (ArgM)
> +CmdArgs.push_back("-w");
> +  else
> +ArgM = ArgMD;
> +
> +  if (ArgM) {
>  // Determine the output location.
>  const char *DepFile;
>  if (Arg *MF = Args.getLastArg(options::OPT_MF)) {
> @@ -1080,8 +1090,7 @@ void Clang::AddPreprocessingOptions(Comp
>C.addFailureResultFile(DepFile, &JA);
>  } else if (Output.getType() == types::TY_Dependencies) {
>DepFile = Output.getFilename();
> -} else if (A->getOption().matches(options::OPT_M) ||
> -   A->getOption().matches(options::OPT_MM)) {
> +} else if (!ArgMD) {
>DepFile = "-";
>  } else {
>DepFile = getDependencyFileName(Args, Inputs);
> @@ -1090,8 +1099,22 @@ void Clang::AddPreprocessingOptions(Comp
>  CmdArgs.push_back("-dependency-file");
>  CmdArgs.push_back(DepFile);
>
> +bool HasTarget = false;
> +for (const Arg *A : Args.filtered(options::OPT_MT, options::OPT_MQ)) {
> +  HasTarget = true;
> +  A->claim();
> +  if (A->getOption().matches(options::OPT_MT)) {
> +A->render(Args, CmdArgs);
> +  } else {
> +CmdArgs.push_back("-MT");
> +SmallString<128> Quoted;
> +QuoteTarget(A->getValue(), Quoted);
> +CmdArgs.push_back(Args.MakeArgString(Quoted));
> +  }
> +}
> +
>  // Add a default target if one wasn't specified.
> -if (!Args.hasArg(options::OPT_MT) && !Args.hasArg(options::OPT_MQ)) {
> +if (!HasTarget) {
>const char *DepTarget;
>
>// If user provided -o, that is the dependency target, except
> @@ -1108,17 +1131,14 @@ void Clang::AddPreprocessingOptions(Comp
>  DepTarget = Args.MakeArgString(llvm::sys::path::filename(P));
>}
>
> -  if (!A->getOption().matches(options::OPT_MD) &&
> !A->getOption().matches(options::OPT_MMD)) {
> -CmdArgs.push_back("-w");
> -  }
>CmdArgs.pus

[PATCH] D67588: Add builtin trait for add/remove cv (and similar)

2019-09-14 Thread Zoe Carver via Phabricator via cfe-commits
zoecarver created this revision.
zoecarver added reviewers: EricWF, eli.friedman, rsmith, craig.topper, 
mclow.lists.
zoecarver added projects: clang, libc++.
zoecarver updated this revision to Diff 220226.
zoecarver added a comment.

- diff from D67052 , not master


This patch adds six builtins: `__remove_cv`, `__remove_cosnt`, 
`__remove_volatile`, `__add_cv`, `__add_const`, and `__add_volatile`. I have 
added two stress tests to show the performace improvements. The `__remove_cv`  
test sees a 160% build time imporvement while the `__add_cv` test sees an 8% 
improvement.

This patch is based on D67052 .

I will submit a patch for implementing these in libc++ after this lands.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D67588

Files:
  clang/include/clang/AST/Type.h
  clang/include/clang/Basic/Specifiers.h
  clang/include/clang/Basic/TokenKinds.def
  clang/include/clang/Parse/Parser.h
  clang/include/clang/Sema/DeclSpec.h
  clang/lib/Format/FormatToken.cpp
  clang/lib/Lex/PPMacroExpansion.cpp
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/lib/Sema/DeclSpec.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaTemplateVariadic.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/SemaCXX/add_cv.cpp
  clang/test/SemaCXX/add_reference.cpp
  libcxx/test/libcxx/utilities/meta/stress_tests/stress_test_add_cv.sh.cpp
  
libcxx/test/libcxx/utilities/meta/stress_tests/stress_test_add_lvalue_reference.sh.cpp
  
libcxx/test/libcxx/utilities/meta/stress_tests/stress_test_add_rvalue_reference.sh.cpp
  libcxx/test/libcxx/utilities/meta/stress_tests/stress_test_remove_cv.sh.cpp
  
libcxx/test/libcxx/utilities/meta/stress_tests/stress_test_remove_reference.sh.cpp

Index: libcxx/test/libcxx/utilities/meta/stress_tests/stress_test_remove_reference.sh.cpp
===
--- /dev/null
+++ libcxx/test/libcxx/utilities/meta/stress_tests/stress_test_remove_reference.sh.cpp
@@ -0,0 +1,63 @@
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This is a dummy feature that prevents this test from running by default.
+
+// The table below compares the compile time and object size for each of the
+// variants listed in the RUN script.
+//
+//  Impl   Compile Time  Object Size
+// --
+// new_remove_reference:   22.849 s  121 K
+// std::remove_reference:  25.643 s  121 K
+//
+// RUN: %cxx %flags %compile_flags -c %s -o %S/orig.o -ggdb  -ggnu-pubnames -ftemplate-depth=5000 -ftime-trace -std=c++17
+// RUN: %cxx %flags %compile_flags -c %s -o %S/new.o -ggdb  -ggnu-pubnames -ftemplate-depth=5000 -ftime-trace -std=c++17 -DTEST_NEW
+
+#include 
+#include 
+
+#include "test_macros.h"
+#include "template_cost_testing.h"
+
+template  struct Arg { enum { value = 1 }; };
+
+#ifdef TEST_NEW
+
+template 
+struct new_remove_reference
+{
+  typedef __remove_reference(T) type;
+};
+
+#define TEST_CASE_NOP()  new_remove_reference< Arg< __COUNTER__ > >{},
+#define TEST_CASE_TYPE() typename new_remove_reference< Arg< __COUNTER__ > >::type,
+
+#else
+
+#define TEST_CASE_NOP()  std::remove_reference< Arg< __COUNTER__ > >{},
+#define TEST_CASE_TYPE() typename std::remove_reference< Arg< __COUNTER__ > >::type,
+
+#endif
+
+int sink(...);
+
+int x = sink(
+  REPEAT_1(TEST_CASE_NOP)
+  REPEAT_1(TEST_CASE_NOP) 42
+);
+
+void Foo( REPEAT_1(TEST_CASE_TYPE) int) { }
+
+void escape() {
+
+sink(&x);
+sink(&Foo);
+}
+
+
Index: libcxx/test/libcxx/utilities/meta/stress_tests/stress_test_remove_cv.sh.cpp
===
--- /dev/null
+++ libcxx/test/libcxx/utilities/meta/stress_tests/stress_test_remove_cv.sh.cpp
@@ -0,0 +1,62 @@
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This is a dummy feature that prevents this test from running by default.
+
+// The table below compares the compile time and object size for each of the
+// variants listed in the RUN script.
+//
+//  Impl   Compile Time  Object Size
+// --
+// new_remove_cv:   23.594 s  121 K
+// std::remove_cv:  38.817 s  121 K
+

[PATCH] D67588: Add builtin trait for add/remove cv (and similar)

2019-09-14 Thread Zoe Carver via Phabricator via cfe-commits
zoecarver updated this revision to Diff 220226.
zoecarver added a comment.

- diff from D67052 , not master


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D67588

Files:
  clang/include/clang/AST/Type.h
  clang/include/clang/Basic/Specifiers.h
  clang/include/clang/Basic/TokenKinds.def
  clang/include/clang/Parse/Parser.h
  clang/include/clang/Sema/DeclSpec.h
  clang/lib/Format/FormatToken.cpp
  clang/lib/Lex/PPMacroExpansion.cpp
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/lib/Sema/DeclSpec.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaTemplateVariadic.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/SemaCXX/add_cv.cpp
  clang/test/SemaCXX/add_reference.cpp
  libcxx/test/libcxx/utilities/meta/stress_tests/stress_test_add_cv.sh.cpp
  
libcxx/test/libcxx/utilities/meta/stress_tests/stress_test_add_lvalue_reference.sh.cpp
  
libcxx/test/libcxx/utilities/meta/stress_tests/stress_test_add_rvalue_reference.sh.cpp
  libcxx/test/libcxx/utilities/meta/stress_tests/stress_test_remove_cv.sh.cpp
  
libcxx/test/libcxx/utilities/meta/stress_tests/stress_test_remove_reference.sh.cpp

Index: libcxx/test/libcxx/utilities/meta/stress_tests/stress_test_remove_reference.sh.cpp
===
--- /dev/null
+++ libcxx/test/libcxx/utilities/meta/stress_tests/stress_test_remove_reference.sh.cpp
@@ -0,0 +1,63 @@
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This is a dummy feature that prevents this test from running by default.
+
+// The table below compares the compile time and object size for each of the
+// variants listed in the RUN script.
+//
+//  Impl   Compile Time  Object Size
+// --
+// new_remove_reference:   22.849 s  121 K
+// std::remove_reference:  25.643 s  121 K
+//
+// RUN: %cxx %flags %compile_flags -c %s -o %S/orig.o -ggdb  -ggnu-pubnames -ftemplate-depth=5000 -ftime-trace -std=c++17
+// RUN: %cxx %flags %compile_flags -c %s -o %S/new.o -ggdb  -ggnu-pubnames -ftemplate-depth=5000 -ftime-trace -std=c++17 -DTEST_NEW
+
+#include 
+#include 
+
+#include "test_macros.h"
+#include "template_cost_testing.h"
+
+template  struct Arg { enum { value = 1 }; };
+
+#ifdef TEST_NEW
+
+template 
+struct new_remove_reference
+{
+  typedef __remove_reference(T) type;
+};
+
+#define TEST_CASE_NOP()  new_remove_reference< Arg< __COUNTER__ > >{},
+#define TEST_CASE_TYPE() typename new_remove_reference< Arg< __COUNTER__ > >::type,
+
+#else
+
+#define TEST_CASE_NOP()  std::remove_reference< Arg< __COUNTER__ > >{},
+#define TEST_CASE_TYPE() typename std::remove_reference< Arg< __COUNTER__ > >::type,
+
+#endif
+
+int sink(...);
+
+int x = sink(
+  REPEAT_1(TEST_CASE_NOP)
+  REPEAT_1(TEST_CASE_NOP) 42
+);
+
+void Foo( REPEAT_1(TEST_CASE_TYPE) int) { }
+
+void escape() {
+
+sink(&x);
+sink(&Foo);
+}
+
+
Index: libcxx/test/libcxx/utilities/meta/stress_tests/stress_test_remove_cv.sh.cpp
===
--- /dev/null
+++ libcxx/test/libcxx/utilities/meta/stress_tests/stress_test_remove_cv.sh.cpp
@@ -0,0 +1,62 @@
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This is a dummy feature that prevents this test from running by default.
+
+// The table below compares the compile time and object size for each of the
+// variants listed in the RUN script.
+//
+//  Impl   Compile Time  Object Size
+// --
+// new_remove_cv:   23.594 s  121 K
+// std::remove_cv:  38.817 s  121 K
+//
+// RUN: %cxx %flags %compile_flags -c %s -o %S/orig.o -ggdb  -ggnu-pubnames -ftemplate-depth=5000 -ftime-trace -std=c++17
+// RUN: %cxx %flags %compile_flags -c %s -o %S/new.o -ggdb  -ggnu-pubnames -ftemplate-depth=5000 -ftime-trace -std=c++17 -DTEST_NEW
+
+#include 
+
+#include "test_macros.h"
+#include "template_cost_testing.h"
+
+template  struct Arg { enum { value = 1 }; };
+
+#ifdef TEST_NEW
+
+template 
+struct new_remove_cv
+{
+  typedef __remove_cv(T) type;
+};
+
+#define TEST_CASE_NOP()  new_remove_cv< Arg< __COUNTER__ > >{},
+#d

[PATCH] D67588: Add builtin trait for add/remove cv (and similar)

2019-09-14 Thread Zoe Carver via Phabricator via cfe-commits
zoecarver updated this revision to Diff 220227.
zoecarver added a comment.

Generate diff based on D67052  (arc wasn't 
working so I had to do it manually this time).


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

https://reviews.llvm.org/D67588

Files:
  clang/include/clang/AST/Type.h
  clang/include/clang/Basic/Specifiers.h
  clang/include/clang/Basic/TokenKinds.def
  clang/include/clang/Parse/Parser.h
  clang/include/clang/Sema/DeclSpec.h
  clang/lib/Format/FormatToken.cpp
  clang/lib/Lex/PPMacroExpansion.cpp
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/lib/Sema/DeclSpec.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaTemplateVariadic.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/SemaCXX/add_cv.cpp
  libcxx/test/libcxx/utilities/meta/stress_tests/stress_test_add_cv.sh.cpp
  libcxx/test/libcxx/utilities/meta/stress_tests/stress_test_remove_cv.sh.cpp

Index: libcxx/test/libcxx/utilities/meta/stress_tests/stress_test_remove_cv.sh.cpp
===
--- /dev/null
+++ libcxx/test/libcxx/utilities/meta/stress_tests/stress_test_remove_cv.sh.cpp
@@ -0,0 +1,62 @@
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This is a dummy feature that prevents this test from running by default.
+
+// The table below compares the compile time and object size for each of the
+// variants listed in the RUN script.
+//
+//  Impl   Compile Time  Object Size
+// --
+// new_remove_cv:   23.594 s  121 K
+// std::remove_cv:  38.817 s  121 K
+//
+// RUN: %cxx %flags %compile_flags -c %s -o %S/orig.o -ggdb  -ggnu-pubnames -ftemplate-depth=5000 -ftime-trace -std=c++17
+// RUN: %cxx %flags %compile_flags -c %s -o %S/new.o -ggdb  -ggnu-pubnames -ftemplate-depth=5000 -ftime-trace -std=c++17 -DTEST_NEW
+
+#include 
+
+#include "test_macros.h"
+#include "template_cost_testing.h"
+
+template  struct Arg { enum { value = 1 }; };
+
+#ifdef TEST_NEW
+
+template 
+struct new_remove_cv
+{
+  typedef __remove_cv(T) type;
+};
+
+#define TEST_CASE_NOP()  new_remove_cv< Arg< __COUNTER__ > >{},
+#define TEST_CASE_TYPE() typename new_remove_cv< Arg< __COUNTER__ > >::type,
+
+#else
+
+#define TEST_CASE_NOP()  std::remove_cv< Arg< __COUNTER__ > >{},
+#define TEST_CASE_TYPE() typename std::remove_cv< Arg< __COUNTER__ > >::type,
+
+#endif
+
+int sink(...);
+
+int x = sink(
+  REPEAT_1(TEST_CASE_NOP)
+  REPEAT_1(TEST_CASE_NOP) 42
+);
+
+void Foo( REPEAT_1(TEST_CASE_TYPE) int) { }
+
+void escape() {
+
+sink(&x);
+sink(&Foo);
+}
+
+
Index: libcxx/test/libcxx/utilities/meta/stress_tests/stress_test_add_cv.sh.cpp
===
--- /dev/null
+++ libcxx/test/libcxx/utilities/meta/stress_tests/stress_test_add_cv.sh.cpp
@@ -0,0 +1,62 @@
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This is a dummy feature that prevents this test from running by default.
+
+// The table below compares the compile time and object size for each of the
+// variants listed in the RUN script.
+//
+//  Impl   Compile Time  Object Size
+// --
+// new_add_cv:   22.710 s  121 K
+// std::add_cv:  25.643 s  121 K
+//
+// RUN: %cxx %flags %compile_flags -c %s -o %S/orig.o -ggdb  -ggnu-pubnames -ftemplate-depth=5000 -ftime-trace -std=c++17
+// RUN: %cxx %flags %compile_flags -c %s -o %S/new.o -ggdb  -ggnu-pubnames -ftemplate-depth=5000 -ftime-trace -std=c++17 -DTEST_NEW
+
+#include 
+
+#include "test_macros.h"
+#include "template_cost_testing.h"
+
+template  struct Arg { enum { value = 1 }; };
+
+#ifdef TEST_NEW
+
+template 
+struct new_add_cv
+{
+  typedef __add_cv(T) type;
+};
+
+#define TEST_CASE_NOP()  new_add_cv< Arg< __COUNTER__ > >{},
+#define TEST_CASE_TYPE() typename new_add_cv< Arg< __COUNTER__ > >::type,
+
+#else
+
+#define TEST_CASE_NOP()  std::add_cv< Arg< __COUNTER__ > >{},
+#define TEST_CASE_TYPE() typename std::add_cv< Arg< __COUNTER__ > >::type,
+
+#endif
+
+int sink(...);
+
+int x = sink(
+  REPEAT_1(TEST_CASE_NOP)
+  REPEAT_1(TEST_CASE_NOP) 42
+);
+
+void Foo( REPEAT_1(TEST_CASE_TYPE) int) { }

[PATCH] D67588: Add builtin trait for add/remove cv (and similar)

2019-09-14 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

> The `__remove_cv` test sees a 160% build time imporvement while the 
> `__add_cv` test sees an 8% improvement.

Those numbers are specifically for those macrobenchmarks, right?
What impact does this have on some real-world code?
I'm just curious as to cost/benefit here.


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

https://reviews.llvm.org/D67588



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


[PATCH] D67585: [clang] [cmake] Make building dylib optional

2019-09-14 Thread Chris Bieneman via Phabricator via cfe-commits
beanz added a reviewer: compnerd.
beanz added a comment.

In D67585#1670433 , @mgorny wrote:

> This is really much more work than disabling the one component I don't need 
> or care for, especially when I do shared lib build and therefore the 
> additional library is entirely useless.


It is one-time effort to figure out what you "care" about, which makes me 
pretty unsympathetic to the argument that it is much more work. Further, your 
argument for building the `all` target is that you want to build-test things, 
but you have decided this library is "useless" so you don't want to build it. 
How many other things in tree do you deem "useless"?

Using `LLVM_DISTRIBUTION_COMPONENTS` is the best way (and hopefully in the 
future the only supported way) to make an arbitrary choice about what is 
meaningful to you.

I believe the fundamental direction of the build system needs to be different 
from what it has been in the past, and I've had conversations with other 
contributors that agree. My plan is to have a larger discussion at the 
Developer Meeting in October, and formulate a document describing the direction 
and guidelines for the build system. Presently the build system is growing 
along a trajectory that is unsustainable and actively harmful to its 
maintainability. My belief is that the build system should have less options, 
not more. In particular we should avoid options that conflict with other 
options creating invalid build configurations, which this patch does (see 
`CLANG_LINK_CLANG_DYLIB`). I also believe that we should not add options for 
each individual's preferred workflow, instead we need to coalesce around a more 
limited set of supported workflows. Following this direction will reduce the 
maintenance cost of the build system by making it easier and less risky to make 
changes, and it will provide a general improvement to the project by reducing 
the matrix of possible configurations that require distinct testing.


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

https://reviews.llvm.org/D67585



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


[PATCH] D67585: [clang] [cmake] Make building dylib optional

2019-09-14 Thread Michał Górny via Phabricator via cfe-commits
mgorny added a comment.

But in that case, we should aim for consistency, i.e. remove the matching 
option from LLVM.


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

https://reviews.llvm.org/D67585



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


[PATCH] D67585: [clang] [cmake] Make building dylib optional

2019-09-14 Thread Chris Bieneman via Phabricator via cfe-commits
beanz added a comment.

In D67585#1670491 , @mgorny wrote:

> But in that case, we should aim for consistency, i.e. remove the matching 
> option from LLVM.


Yes! I want to do that too.

After the mono-repo transition is finalized I think we need to invest time in 
cleaning up the LLVM build system and removing a bunch of legacy functionality. 
At the same time I think we should move the system in a new architectural 
direction. This is why I'm targeting to have the discussions at the Developer 
Meeting in October, which corresponds with the mono-repo becoming the source of 
truth.


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

https://reviews.llvm.org/D67585



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


r371924 - [Diagnostics] Added silence note for -Wsizeof-array-div; suggest extra parens

2019-09-14 Thread David Bolvansky via cfe-commits
Author: xbolva00
Date: Sat Sep 14 12:38:55 2019
New Revision: 371924

URL: http://llvm.org/viewvc/llvm-project?rev=371924&view=rev
Log:
[Diagnostics] Added silence note for -Wsizeof-array-div; suggest extra parens


Modified:
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/test/Sema/div-sizeof-array.cpp

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=371924&r1=371923&r2=371924&view=diff
==
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Sat Sep 14 12:38:55 2019
@@ -9200,6 +9200,8 @@ static void DiagnoseDivisionSizeofPointe
 S.Diag(LHSArgDecl->getLocation(), diag::note_array_declared_here)
 << LHSArgDecl;
 }
+
+S.Diag(Loc, diag::note_precedence_silence) << RHS;
   }
 }
 

Modified: cfe/trunk/test/Sema/div-sizeof-array.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/div-sizeof-array.cpp?rev=371924&r1=371923&r2=371924&view=diff
==
--- cfe/trunk/test/Sema/div-sizeof-array.cpp (original)
+++ cfe/trunk/test/Sema/div-sizeof-array.cpp Sat Sep 14 12:38:55 2019
@@ -9,21 +9,38 @@ int f(Ty (&Array)[N]) {
 typedef int int32;
 
 void test(void) {
-  int arr[12];// expected-note 2 {{array 'arr' declared here}}
+  int arr[12]; // expected-note 2 {{array 'arr' declared here}}
   unsigned long long arr2[4];
   int *p = &arr[0];
   int a1 = sizeof(arr) / sizeof(*arr);
   int a2 = sizeof arr / sizeof p; // expected-warning {{expression does not 
compute the number of elements in this array; element type is 'int', not 'int 
*'}}
+  // expected-note@-1 {{place parentheses around the 'sizeof p' expression to 
silence this warning}}
   int a4 = sizeof arr2 / sizeof p;
   int a5 = sizeof(arr) / sizeof(short); // expected-warning {{expression does 
not compute the number of elements in this array; element type is 'int', not 
'short'}}
+  // expected-note@-1 {{place parentheses around the 'sizeof(short)' 
expression to silence this warning}}
   int a6 = sizeof(arr) / sizeof(int32);
   int a7 = sizeof(arr) / sizeof(int);
   int a9 = sizeof(arr) / sizeof(unsigned int);
   const char arr3[2] = "A";
   int a10 = sizeof(arr3) / sizeof(char);
+  int a11 = sizeof(arr2) / (sizeof(unsigned));
+  int a12 = sizeof(arr) / (sizeof(short));
 
   int arr4[10][12]; // expected-note 3 {{array 'arr4' 
declared here}}
   int b1 = sizeof(arr4) / sizeof(arr2[12]); // expected-warning {{expression 
does not compute the number of elements in this array; element type is 'int 
[12]', not 'unsigned long long'}}
-  int b2 = sizeof(arr4) / sizeof(int *);// expected-warning {{expression 
does not compute the number of elements in this array; element type is 'int 
[12]', not 'int *'}}
-  int b3 = sizeof(arr4) / sizeof(short *);  // expected-warning {{expression 
does not compute the number of elements in this array; element type is 'int 
[12]', not 'short *'}}
+  // expected-note@-1 {{place parentheses around the 'sizeof (arr2[12])' 
expression to silence this warning}}
+  int b2 = sizeof(arr4) / sizeof(int *); // expected-warning {{expression does 
not compute the number of elements in this array; element type is 'int [12]', 
not 'int *'}}
+  // expected-note@-1 {{place parentheses around the 'sizeof(int *)' 
expression to silence this warning}}
+  int b3 = sizeof(arr4) / sizeof(short *); // expected-warning {{expression 
does not compute the number of elements in this array; element type is 'int 
[12]', not 'short *'}}
+  // expected-note@-1 {{place parentheses around the 'sizeof(short *)' 
expression to silence this warning}}
+
+  int arr5[][5] = { // expected-note 2 {{array 'arr5' declared here}}
+  {1, 2, 3, 4, 5},
+  {6, 7, 8, 9, 0},
+  };
+  int c1 = sizeof(arr5) / sizeof(*arr5);
+  int c2 = sizeof(arr5) / sizeof(**arr5); // expected-warning {{expression 
does not compute the number of elements in this array; element type is 'int 
[5]', not 'int'}}
+  // expected-note@-1 {{place parentheses around the 'sizeof (**arr5)' 
expression to silence this warning}}
+  int c3 = sizeof(arr5) / sizeof(int); // expected-warning {{expression does 
not compute the number of elements in this array; element type is 'int [5]', 
not 'int'}}
+  // expected-note@-1 {{place parentheses around the 'sizeof(int)' expression 
to silence this warning}}
 }


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


[PATCH] D67590: Properly ignore mismatched exception specifiers in MSVC Compat mode.

2019-09-14 Thread Alex Fusco via Phabricator via cfe-commits
alexfusco created this revision.
alexfusco added a project: clang.
Herald added a subscriber: cfe-commits.

This fixes the error compiling _com_ptr_t described in 
https://bugs.llvm.org/show_bug.cgi?id=42842

  

In MSVCCompat mode, clang already attempts to downgrade these mismatches to a 
warning, but because C++17 considers the specifiers part of the type, the check 
in MergeFunctionDecl needs to ignore these specifiers for purpose of comparison.


Repository:
  rC Clang

https://reviews.llvm.org/D67590

Files:
  lib/Sema/SemaDecl.cpp
  test/SemaCXX/ms-ignore-mismatched-except-specifier.cpp


Index: test/SemaCXX/ms-ignore-mismatched-except-specifier.cpp
===
--- /dev/null
+++ test/SemaCXX/ms-ignore-mismatched-except-specifier.cpp
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 %s -std=c++1z -fms-extensions -fms-compatibility
+
+template  struct FooPtr {
+  template  FooPtr(U *p) : m_pT(nullptr) {}
+  template <> FooPtr(T *pInterface) throw() : m_pT(pInterface) {}  // 
expected-warning {{exception specification in declaration does not match 
previous declaration}}
+  T *m_pT;
+};
+struct Bar{};
+template struct FooPtr;
Index: lib/Sema/SemaDecl.cpp
===
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -3562,7 +3562,14 @@
   }
 }
 
-if (OldQTypeForComparison == NewQType)
+if (OldQTypeForComparison == NewQType ||
+// In Microsoft compatibility mode, the intent is to only warn on
+// mismatched exception specifiers.  By this point, that warning has
+// already been issued, so we should treat mismatches only in exception
+// specifier as equivalent.
+(getLangOpts().MSVCCompat &&
+ 
Context.hasSameFunctionTypeIgnoringExceptionSpec(OldQTypeForComparison,
+  NewQType)))
   return MergeCompatibleFunctionDecls(New, Old, S, MergeTypeWithOld);
 
 // If the types are imprecise (due to dependent constructs in friends or


Index: test/SemaCXX/ms-ignore-mismatched-except-specifier.cpp
===
--- /dev/null
+++ test/SemaCXX/ms-ignore-mismatched-except-specifier.cpp
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 %s -std=c++1z -fms-extensions -fms-compatibility
+
+template  struct FooPtr {
+  template  FooPtr(U *p) : m_pT(nullptr) {}
+  template <> FooPtr(T *pInterface) throw() : m_pT(pInterface) {}  // expected-warning {{exception specification in declaration does not match previous declaration}}
+  T *m_pT;
+};
+struct Bar{};
+template struct FooPtr;
Index: lib/Sema/SemaDecl.cpp
===
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -3562,7 +3562,14 @@
   }
 }
 
-if (OldQTypeForComparison == NewQType)
+if (OldQTypeForComparison == NewQType ||
+// In Microsoft compatibility mode, the intent is to only warn on
+// mismatched exception specifiers.  By this point, that warning has
+// already been issued, so we should treat mismatches only in exception
+// specifier as equivalent.
+(getLangOpts().MSVCCompat &&
+ Context.hasSameFunctionTypeIgnoringExceptionSpec(OldQTypeForComparison,
+  NewQType)))
   return MergeCompatibleFunctionDecls(New, Old, S, MergeTypeWithOld);
 
 // If the types are imprecise (due to dependent constructs in friends or
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D67253: clang-misexpect: a standalone tool for verifying the use of __builtin_expect with PGO data

2019-09-14 Thread Paul Kirth via Phabricator via cfe-commits
paulkirth updated this revision to Diff 220239.
paulkirth added a comment.

Addresses problems running the standalone tool w/ the libTooling executors.

When using the CodeGenAction and setting LLVM backend options, I found several 
places where data races occurred. This seems like a more significant 
architectural issue than mitigating access to a few global variables. To avoid 
these issues I've locked the executor concurrency to 1, i.e. single threaded. 
This prevents any data races when the executor is configuring the backends for 
each compiler invocation.

I've included a python script based on the run-clang-tidy.py that tidy uses. 
This allows the standalone tool to take advantage of parallellism without 
running into the data races between threads.

I have also added a new checking mechanism to ensure that PGO profiles and the 
command line options are compatible.

Lastly, I've included new documentation and tests for the standalone tool.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D67253

Files:
  clang-tools-extra/CMakeLists.txt
  clang-tools-extra/clang-misexpect/CMakeLists.txt
  clang-tools-extra/clang-misexpect/ClangMisExpect.cpp
  clang-tools-extra/clang-misexpect/ClangMisExpect.h
  clang-tools-extra/clang-misexpect/tool/CMakeLists.txt
  clang-tools-extra/clang-misexpect/tool/ClangMisExpectMain.cpp
  clang-tools-extra/clang-misexpect/tool/run-clang-misexpect.py
  clang-tools-extra/docs/clang-misexpect.rst
  clang-tools-extra/test/CMakeLists.txt
  clang-tools-extra/test/clang-misexpect/Inputs/basic.proftext
  clang-tools-extra/test/clang-misexpect/Inputs/clean.c
  clang-tools-extra/test/clang-misexpect/basic.cpp
  clang-tools-extra/test/lit.cfg.py
  clang/cmake/caches/Fuchsia-stage2.cmake
  clang/test/Profile/misexpect-switch-nonconst.c
  llvm/lib/Transforms/Utils/MisExpect.cpp

Index: llvm/lib/Transforms/Utils/MisExpect.cpp
===
--- llvm/lib/Transforms/Utils/MisExpect.cpp
+++ llvm/lib/Transforms/Utils/MisExpect.cpp
@@ -43,7 +43,8 @@
 static cl::opt PGOWarnMisExpect(
 "pgo-warn-misexpect", cl::init(false), cl::Hidden,
 cl::desc("Use this option to turn on/off "
- "warnings about incorrect usage of llvm.expect intrinsics."));
+ "warnings about incorrect usage of llvm.expect intrinsics."),
+cl::ZeroOrMore);
 
 } // namespace llvm
 
Index: clang/test/Profile/misexpect-switch-nonconst.c
===
--- clang/test/Profile/misexpect-switch-nonconst.c
+++ clang/test/Profile/misexpect-switch-nonconst.c
@@ -1,7 +1,7 @@
 // Test that misexpect emits no warning when switch condition is non-const
 
 // RUN: llvm-profdata merge %S/Inputs/misexpect-switch-nonconst.proftext -o %t.profdata
-// RUN: %clang_cc1 %s -O2 -o - -disable-llvm-passes -emit-llvm -fprofile-instrument-use-path=%t.profdata -verify
+// RUN: %clang_cc1 %s -O2 -o - -disable-llvm-passes -emit-llvm -fprofile-instrument-use-path=%t.profdata -verify -Wmisexpect
 
 // expected-no-diagnostics
 int sum(int *buff, int size);
Index: clang/cmake/caches/Fuchsia-stage2.cmake
===
--- clang/cmake/caches/Fuchsia-stage2.cmake
+++ clang/cmake/caches/Fuchsia-stage2.cmake
@@ -207,6 +207,7 @@
   LTO
   clang-apply-replacements
   clang-doc
+  clang-misexpect
   clang-format
   clang-resource-headers
   clang-include-fixer
Index: clang-tools-extra/test/lit.cfg.py
===
--- clang-tools-extra/test/lit.cfg.py
+++ clang-tools-extra/test/lit.cfg.py
@@ -144,6 +144,12 @@
 ('%run_clang_tidy',
  '%s %s' % (python_exec, run_clang_tidy)) )
 
+run_clang_misexpect = os.path.join(
+config.test_source_root, "..", "clang-misexpect", "tool", "run-clang-misexpect.py")
+config.substitutions.append(
+('%run_clang_misexpect',
+ '%s %s' % (python_exec, run_clang_misexpect)) )
+
 clangd_benchmarks_dir = os.path.join(os.path.dirname(config.clang_tools_dir),
  "tools", "clang", "tools", "extra",
  "clangd", "benchmarks")
Index: clang-tools-extra/test/clang-misexpect/basic.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-misexpect/basic.cpp
@@ -0,0 +1,41 @@
+// Test that clang-misexpect can run over a compilation database
+
+// Now create a directory with a compilation database file and ensure we don't
+// use it after failing to parse commands from the command line:
+//
+// RUN: mkdir -p %T/misexpect/
+// RUN: echo '[{"directory": "%/T/misexpect/","arguments": ["clang++","-O2","-c","%/T/misexpect/basic.cpp"], "file": "basic.cpp"},{"directory": "%/T/misexpect/","command": "clang -c %/T/misexpect/clean.c", "file": "%/T/misexpect/clean.c"}]' > %T/misexpect/compile_comm