[clang] 201fdef - libclang: Pass Clang install directory to driver via argv[0].

2023-03-22 Thread Peter Collingbourne via cfe-commits

Author: Peter Collingbourne
Date: 2023-03-22T15:28:21-07:00
New Revision: 201fdef40dd6ec193d18d39638454a3c972f1fec

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

LOG: libclang: Pass Clang install directory to driver via argv[0].

Various driver features, such as the sysroot path detection for Android
targets, rely on being able to find the Clang install directory (look
for callers of `getDriver().getInstalledDir()`). However, the install
directory isn't currently being plumbed through to the driver, which is
conventionally done via the argv[0] passed to the Driver constructor.

It looks like D14695 attempted to fix this by adding another API that
allows specifying the argv[0]. However, rather than requiring every
user of libclang to switch to this API for correct behavior, let's have
the other existing APIs work by default, by using the existing logic in
libclang for finding the install directory.

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang-c/Index.h
clang/test/Index/record-completion-invocation.c
clang/test/Index/record-parsing-invocation.c
clang/tools/libclang/CIndex.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 005bf99a62457..94e0f10a31743 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -368,6 +368,14 @@ libclang
   has an evaluable bit width. Fixes undefined behavior when called on a
   bit-field whose width depends on a template paramter.
 
+- ``clang_parseTranslationUnit`` and ``clang_parseTranslationUnit2`` have been
+  changed to automatically locate the Clang installation directory relative to
+  the location of the libclang binary and use it for system headers installed
+  alongside the Clang installation. It is no longer necessary to manually
+  locate such system headers or use the ``clang_parseTranslationUnit2FullArgv``
+  function for this purpose if libclang has been installed in the default
+  location.
+ 
 Static Analyzer
 ---
 - Fix incorrect alignment attribute on the this parameter of certain

diff  --git a/clang/include/clang-c/Index.h b/clang/include/clang-c/Index.h
index c7d32e6a152ae..8275f2941a41c 100644
--- a/clang/include/clang-c/Index.h
+++ b/clang/include/clang-c/Index.h
@@ -899,8 +899,13 @@ CINDEX_LINKAGE enum CXErrorCode 
clang_parseTranslationUnit2(
 
 /**
  * Same as clang_parseTranslationUnit2 but requires a full command line
- * for \c command_line_args including argv[0]. This is useful if the standard
- * library paths are relative to the binary.
+ * for \c command_line_args including argv[0].
+ *
+ * This is useful if the driver uses paths relative to the binary and either
+ * you are targeting libclang versions older than Clang 17, or libclang is
+ * installed to a non-standard location. Clang 17 and newer will automatically
+ * use the correct argv[0] if libclang is installed in the lib directory
+ * parallel to the bin directory where the clang binary is installed.
  */
 CINDEX_LINKAGE enum CXErrorCode clang_parseTranslationUnit2FullArgv(
 CXIndex CIdx, const char *source_filename,

diff  --git a/clang/test/Index/record-completion-invocation.c 
b/clang/test/Index/record-completion-invocation.c
index 4b667134fa2d4..75eb9083908ae 100644
--- a/clang/test/Index/record-completion-invocation.c
+++ b/clang/test/Index/record-completion-invocation.c
@@ -9,4 +9,4 @@
 // RUN: env LIBCLANG_DISABLE_CRASH_RECOVERY=1 
CINDEXTEST_INVOCATION_EMISSION_PATH=%t not --crash c-index-test 
-code-completion-at=%s:10:1 
"-remap-file=%s,%S/Inputs/record-parsing-invocation-remap.c" %s
 // RUN: cat %t/libclang-* | FileCheck %s
 
-// CHECK: 
{"toolchain":"{{.*}}","libclang.operation":"complete","libclang.opts":1,"args":["clang","-fno-spell-checking","{{.*}}record-completion-invocation.c","-Xclang","-detailed-preprocessing-record","-fallow-editor-placeholders"],"invocation-args":["-code-completion-at={{.*}}record-completion-invocation.c:10:1"],"unsaved_file_hashes":[{"name":"{{.*}}record-completion-invocation.c","md5":"aee23773de90e665992b48209351d70e"}]}
+// CHECK: 
{"toolchain":"{{.*}}","libclang.operation":"complete","libclang.opts":1,"args":["{{.*}}bin{{.*}}clang","-fno-spell-checking","{{.*}}record-completion-invocation.c","-Xclang","-detailed-preprocessing-record","-fallow-editor-placeholders"],"invocation-args":["-code-completion-at={{.*}}record-completion-invocation.c:10:1"],"unsaved_file_hashes":[{"name":"{{.*}}record-completion-invocation.c","md5":"aee23773de90e665992b48209351d70e"}]}

diff  --git a/clang/test/Index/record-parsing-invocation.c 
b/clang/test/Index/record-parsing-invocation.c
index e0c4cdb05fb00..f370f014fb1cc 100644
--- 

[clang] 8d9c4a7 - Driver: Change default Android linker to lld.

2022-10-13 Thread Peter Collingbourne via cfe-commits

Author: Peter Collingbourne
Date: 2022-10-13T15:40:30-07:00
New Revision: 8d9c4a7425d9b097c275eb3465aa88a6d19d6c9d

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

LOG: Driver: Change default Android linker to lld.

The clang distributed with the Android NDK has defaulted to lld since r22,
so let's update the driver to match.

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

Added: 


Modified: 
clang/lib/Driver/ToolChains/Linux.cpp
clang/lib/Driver/ToolChains/Linux.h
clang/test/Driver/coverage-ld.c
clang/test/Driver/fuse-ld.c
clang/test/Driver/sanitizer-ld.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Linux.cpp 
b/clang/lib/Driver/ToolChains/Linux.cpp
index 756994aeba1c..ccbdda11345f 100644
--- a/clang/lib/Driver/ToolChains/Linux.cpp
+++ b/clang/lib/Driver/ToolChains/Linux.cpp
@@ -810,3 +810,9 @@ void Linux::addExtraOpts(llvm::opt::ArgStringList ) 
const {
   for (const auto  : ExtraOpts)
 CmdArgs.push_back(Opt.c_str());
 }
+
+const char *Linux::getDefaultLinker() const {
+  if (getTriple().isAndroid())
+return "ld.lld";
+  return Generic_ELF::getDefaultLinker();
+}

diff  --git a/clang/lib/Driver/ToolChains/Linux.h 
b/clang/lib/Driver/ToolChains/Linux.h
index 188cb1f09788..524391743090 100644
--- a/clang/lib/Driver/ToolChains/Linux.h
+++ b/clang/lib/Driver/ToolChains/Linux.h
@@ -63,6 +63,8 @@ class LLVM_LIBRARY_VISIBILITY Linux : public Generic_ELF {
   const llvm::opt::ArgList , const JobAction ,
   const llvm::fltSemantics *FPType = nullptr) const override;
 
+  const char *getDefaultLinker() const override;
+
 protected:
   Tool *buildAssembler() const override;
   Tool *buildLinker() const override;

diff  --git a/clang/test/Driver/coverage-ld.c b/clang/test/Driver/coverage-ld.c
index 3808e16e190f..e72bbf86bf4e 100644
--- a/clang/test/Driver/coverage-ld.c
+++ b/clang/test/Driver/coverage-ld.c
@@ -59,5 +59,5 @@
 // RUN: --sysroot=%S/Inputs/basic_android_tree/sysroot \
 // RUN:   | FileCheck --check-prefix=CHECK-ANDROID-ARM %s
 //
-// CHECK-ANDROID-ARM: "{{(.*[^.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
+// CHECK-ANDROID-ARM: "{{(.*[^.0-9A-Z_a-z])?}}ld.lld{{(.exe)?}}"
 // CHECK-ANDROID-ARM: 
"{{.*}}/Inputs/resource_dir{{/|}}lib{{/|}}linux{{/|}}libclang_rt.profile-arm-android.a"

diff  --git a/clang/test/Driver/fuse-ld.c b/clang/test/Driver/fuse-ld.c
index dfcf31e25ffa..e7c7cc07fd12 100644
--- a/clang/test/Driver/fuse-ld.c
+++ b/clang/test/Driver/fuse-ld.c
@@ -44,7 +44,7 @@
 // RUN: -target arm-linux-androideabi \
 // RUN: -B%S/Inputs/basic_android_tree/bin/arm-linux-androideabi- 2>&1 \
 // RUN:   | FileCheck %s --check-prefix=CHECK-ANDROID-ARM-LD
-// CHECK-ANDROID-ARM-LD: 
Inputs/basic_android_tree/bin{{/|\\+}}arm-linux-androideabi-ld
+// CHECK-ANDROID-ARM-LD: ld.lld
 
 // RUN: %clang %s -### -fuse-ld=bfd \
 // RUN: -target arm-linux-androideabi \
@@ -62,7 +62,7 @@
 // RUN: -target arm-linux-androideabi \
 // RUN: --gcc-toolchain=%S/Inputs/basic_android_tree 2>&1 \
 // RUN:   | FileCheck %s --check-prefix=CHECK-ANDROID-ARM-LD-TC
-// CHECK-ANDROID-ARM-LD-TC: 
Inputs/basic_android_tree/lib/gcc/arm-linux-androideabi/4.4.3/../../../../arm-linux-androideabi/bin{{/|\\+}}ld
+// CHECK-ANDROID-ARM-LD-TC: ld.lld
 
 // RUN: %clang %s -### -fuse-ld=bfd \
 // RUN: -target arm-linux-androideabi \

diff  --git a/clang/test/Driver/sanitizer-ld.c 
b/clang/test/Driver/sanitizer-ld.c
index 423ce8beaa84..1c9b6d783be3 100644
--- a/clang/test/Driver/sanitizer-ld.c
+++ b/clang/test/Driver/sanitizer-ld.c
@@ -169,7 +169,7 @@
 // RUN: --sysroot=%S/Inputs/basic_android_tree/sysroot \
 // RUN:   | FileCheck --check-prefix=CHECK-ASAN-ANDROID %s
 //
-// CHECK-ASAN-ANDROID: "{{(.*[^.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
+// CHECK-ASAN-ANDROID: "{{(.*[^.0-9A-Z_a-z])?}}ld.lld{{(.exe)?}}"
 // CHECK-ASAN-ANDROID: "-pie"
 // CHECK-ASAN-ANDROID-NOT: "-lc"
 // CHECK-ASAN-ANDROID-NOT: "-lpthread"
@@ -184,7 +184,7 @@
 // RUN: -static-libsan \
 // RUN:   | FileCheck --check-prefix=CHECK-ASAN-ANDROID-STATICLIBASAN %s
 //
-// CHECK-ASAN-ANDROID-STATICLIBASAN: "{{(.*[^.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
+// CHECK-ASAN-ANDROID-STATICLIBASAN: "{{(.*[^.0-9A-Z_a-z])?}}ld.lld{{(.exe)?}}"
 // CHECK-ASAN-ANDROID-STATICLIBASAN: libclang_rt.asan-arm-android.a"
 // CHECK-ASAN-ANDROID-STATICLIBASAN-NOT: "-lpthread"
 // CHECK-ASAN-ANDROID-STATICLIBASAN-NOT: "-lrt"
@@ -195,7 +195,7 @@
 // RUN: --sysroot=%S/Inputs/basic_android_tree/sysroot \
 // RUN:   | FileCheck --check-prefix=CHECK-UBSAN-ANDROID %s
 //
-// CHECK-UBSAN-ANDROID: "{{(.*[^.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
+// CHECK-UBSAN-ANDROID: "{{(.*[^.0-9A-Z_a-z])?}}ld.lld{{(.exe)?}}"
 // CHECK-UBSAN-ANDROID: "-pie"
 // CHECK-UBSAN-ANDROID-NOT: "-lc"
 // CHECK-UBSAN-ANDROID-NOT: "-lpthread"
@@ 

[clang] 18ead23 - AST: Make getEffectiveDeclContext() a member function of ItaniumMangleContextImpl. NFCI.

2022-02-17 Thread Peter Collingbourne via cfe-commits

Author: Peter Collingbourne
Date: 2022-02-17T11:31:40-08:00
New Revision: 18ead23385a4e0e6421d658591b1ee6a1c592b53

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

LOG: AST: Make getEffectiveDeclContext() a member function of 
ItaniumMangleContextImpl. NFCI.

In an upcoming change we are going to need to access mangler state
from the getEffectiveDeclContext() function. Therefore, make it a
member function of ItaniumMangleContextImpl. Any callers that are
not currently members of ItaniumMangleContextImpl or CXXNameMangler
are made members of one or the other depending on where they are
called from.

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

Added: 


Modified: 
clang/lib/AST/ItaniumMangle.cpp

Removed: 




diff  --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp
index 63e40a0f3072..4277a0166f20 100644
--- a/clang/lib/AST/ItaniumMangle.cpp
+++ b/clang/lib/AST/ItaniumMangle.cpp
@@ -40,65 +40,10 @@ using namespace clang;
 
 namespace {
 
-/// Retrieve the declaration context that should be used when mangling the 
given
-/// declaration.
-static const DeclContext *getEffectiveDeclContext(const Decl *D) {
-  // The ABI assumes that lambda closure types that occur within
-  // default arguments live in the context of the function. However, due to
-  // the way in which Clang parses and creates function declarations, this is
-  // not the case: the lambda closure type ends up living in the context
-  // where the function itself resides, because the function declaration itself
-  // had not yet been created. Fix the context here.
-  if (const CXXRecordDecl *RD = dyn_cast(D)) {
-if (RD->isLambda())
-  if (ParmVarDecl *ContextParam
-= dyn_cast_or_null(RD->getLambdaContextDecl()))
-return ContextParam->getDeclContext();
-  }
-
-  // Perform the same check for block literals.
-  if (const BlockDecl *BD = dyn_cast(D)) {
-if (ParmVarDecl *ContextParam
-  = dyn_cast_or_null(BD->getBlockManglingContextDecl()))
-  return ContextParam->getDeclContext();
-  }
-
-  const DeclContext *DC = D->getDeclContext();
-  if (isa(DC) || isa(DC) ||
-  isa(DC)) {
-return getEffectiveDeclContext(cast(DC));
-  }
-
-  if (const auto *VD = dyn_cast(D))
-if (VD->isExternC())
-  return VD->getASTContext().getTranslationUnitDecl();
-
-  if (const auto *FD = dyn_cast(D))
-if (FD->isExternC())
-  return FD->getASTContext().getTranslationUnitDecl();
-
-  return DC->getRedeclContext();
-}
-
-static const DeclContext *getEffectiveParentContext(const DeclContext *DC) {
-  return getEffectiveDeclContext(cast(DC));
-}
-
 static bool isLocalContainerContext(const DeclContext *DC) {
   return isa(DC) || isa(DC) || 
isa(DC);
 }
 
-static const RecordDecl *GetLocalClassDecl(const Decl *D) {
-  const DeclContext *DC = getEffectiveDeclContext(D);
-  while (!DC->isNamespace() && !DC->isTranslationUnit()) {
-if (isLocalContainerContext(DC))
-  return dyn_cast(D);
-D = cast(DC);
-DC = getEffectiveDeclContext(D);
-  }
-  return nullptr;
-}
-
 static const FunctionDecl *getStructor(const FunctionDecl *fn) {
   if (const FunctionTemplateDecl *ftd = fn->getPrimaryTemplate())
 return ftd->getTemplatedDecl();
@@ -249,6 +194,14 @@ class ItaniumMangleContextImpl : public 
ItaniumMangleContext {
 return DiscriminatorOverride;
   }
 
+  const DeclContext *getEffectiveDeclContext(const Decl *D);
+  const DeclContext *getEffectiveParentContext(const DeclContext *DC) {
+return getEffectiveDeclContext(cast(DC));
+  }
+
+  bool isInternalLinkageDecl(const NamedDecl *ND);
+  const DeclContext *IgnoreLinkageSpecDecls(const DeclContext *DC);
+
   /// @}
 };
 
@@ -427,6 +380,15 @@ class CXXNameMangler {
 
   ASTContext () const { return Context.getASTContext(); }
 
+  bool isStd(const NamespaceDecl *NS);
+  bool isStdNamespace(const DeclContext *DC);
+
+  const RecordDecl *GetLocalClassDecl(const Decl *D);
+  const DeclContext *IgnoreLinkageSpecDecls(const DeclContext *DC);
+  bool isSpecializedAs(QualType S, llvm::StringRef Name, QualType A);
+  bool isStdCharSpecialization(const ClassTemplateSpecializationDecl *SD,
+   llvm::StringRef Name, bool HasAllocator);
+
 public:
   CXXNameMangler(ItaniumMangleContextImpl , raw_ostream _,
  const NamedDecl *D = nullptr, bool NullOut_ = false)
@@ -628,7 +590,48 @@ class CXXNameMangler {
 
 }
 
-static bool isInternalLinkageDecl(const NamedDecl *ND) {
+/// Retrieve the declaration context that should be used when mangling the 
given
+/// declaration.
+const DeclContext *
+ItaniumMangleContextImpl::getEffectiveDeclContext(const Decl *D) {
+  // The ABI assumes that lambda closure types that occur within
+  // default arguments live 

[clang] 82e5f95 - AST: Move __va_list tag back to std conditionally on AArch64.

2022-02-17 Thread Peter Collingbourne via cfe-commits

Author: Peter Collingbourne
Date: 2022-02-17T11:31:40-08:00
New Revision: 82e5f951fd6e6ad6323067d8afcf025fc72d9c33

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

LOG: AST: Move __va_list tag back to std conditionally on AArch64.

In post-commit feedback on D104830 Jessica Clarke pointed out that
unconditionally adding __va_list to the std namespace caused namespace
debug info to be emitted in C, which is not only inappropriate but
turned out to confuse the dtrace tool. Therefore, move __va_list back
to std only in C++ so that the correct debug info is generated. We
also considered moving __va_list to the top level unconditionally
but this would contradict the specification and be visible to AST
matchers and such, so make it conditional on the language mode.

To avoid breaking name mangling for __va_list, teach the Itanium
name mangler to always mangle it as if it were in the std namespace
when targeting ARM architectures. This logic is not needed for the
Microsoft name mangler because Microsoft platforms define va_list as
a typedef of char *.

Depends on D116773

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

Added: 


Modified: 
clang/lib/AST/ASTContext.cpp
clang/lib/AST/ItaniumMangle.cpp
clang/test/CodeGen/aarch64-varargs.c
clang/test/CodeGen/arm64-be-hfa-vararg.c
clang/test/Headers/stdarg.cpp

Removed: 




diff  --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 527c8b56159e..f29e90c05713 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -8548,21 +8548,18 @@ static TypedefDecl 
*CreateVoidPtrBuiltinVaListDecl(const ASTContext *Context) {
 
 static TypedefDecl *
 CreateAArch64ABIBuiltinVaListDecl(const ASTContext *Context) {
+  // struct __va_list
   RecordDecl *VaListTagDecl = Context->buildImplicitRecord("__va_list");
-  // namespace std { struct __va_list {
-  // Note that we create the namespace even in C. This is intentional so that
-  // the type is consistent between C and C++, which is important in cases 
where
-  // the types need to match between translation units (e.g. with
-  // -fsanitize=cfi-icall). Ideally we wouldn't have created this namespace at
-  // all, but it's now part of the ABI (e.g. in mangled names), so we can't
-  // change it.
-  auto *NS = NamespaceDecl::Create(
-  const_cast(*Context), Context->getTranslationUnitDecl(),
-  /*Inline*/ false, SourceLocation(), SourceLocation(),
-  >Idents.get("std"),
-  /*PrevDecl*/ nullptr);
-  NS->setImplicit();
-  VaListTagDecl->setDeclContext(NS);
+  if (Context->getLangOpts().CPlusPlus) {
+// namespace std { struct __va_list {
+auto *NS = NamespaceDecl::Create(
+const_cast(*Context), Context->getTranslationUnitDecl(),
+/*Inline*/ false, SourceLocation(), SourceLocation(),
+>Idents.get("std"),
+/*PrevDecl*/ nullptr);
+NS->setImplicit();
+VaListTagDecl->setDeclContext(NS);
+  }
 
   VaListTagDecl->startDefinition();
 

diff  --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp
index 4277a0166f20..d1d7a7c40ceb 100644
--- a/clang/lib/AST/ItaniumMangle.cpp
+++ b/clang/lib/AST/ItaniumMangle.cpp
@@ -71,6 +71,7 @@ class ItaniumMangleContextImpl : public ItaniumMangleContext {
   llvm::DenseMap Discriminator;
   llvm::DenseMap Uniquifier;
   const DiscriminatorOverrideTy DiscriminatorOverride = nullptr;
+  NamespaceDecl *StdNamespace = nullptr;
 
   bool NeedsUniqueInternalLinkageNames = false;
 
@@ -194,6 +195,8 @@ class ItaniumMangleContextImpl : public 
ItaniumMangleContext {
 return DiscriminatorOverride;
   }
 
+  NamespaceDecl *getStdNamespace();
+
   const DeclContext *getEffectiveDeclContext(const Decl *D);
   const DeclContext *getEffectiveParentContext(const DeclContext *DC) {
 return getEffectiveDeclContext(cast(DC));
@@ -590,6 +593,18 @@ class CXXNameMangler {
 
 }
 
+NamespaceDecl *ItaniumMangleContextImpl::getStdNamespace() {
+  if (!StdNamespace) {
+StdNamespace = NamespaceDecl::Create(
+getASTContext(), getASTContext().getTranslationUnitDecl(),
+/*Inline*/ false, SourceLocation(), SourceLocation(),
+().Idents.get("std"),
+/*PrevDecl*/ nullptr);
+StdNamespace->setImplicit();
+  }
+  return StdNamespace;
+}
+
 /// Retrieve the declaration context that should be used when mangling the 
given
 /// declaration.
 const DeclContext *
@@ -614,6 +629,17 @@ ItaniumMangleContextImpl::getEffectiveDeclContext(const 
Decl *D) {
   return ContextParam->getDeclContext();
   }
 
+  // On ARM and AArch64, the va_list tag is always mangled as if in the std
+  // namespace. We do not represent va_list as actually being in the std
+  // namespace in C because this would result in incorrect debug info in C,

[clang] e655e74 - AST: Create __va_list in the std namespace even in C.

2021-06-23 Thread Peter Collingbourne via cfe-commits

Author: Peter Collingbourne
Date: 2021-06-23T18:59:10-07:00
New Revision: e655e74a318e0b4140391ae18725300c7f0629f6

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

LOG: AST: Create __va_list in the std namespace even in C.

This ensures that the mangled type names match between C and C++,
which is significant when using -fsanitize=cfi-icall. Ideally we
wouldn't have created this namespace at all, but it's now part of
the ABI (e.g. in mangled names), so we can't change it.

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

Added: 
clang/test/CodeGen/cfi-icall-va-list.c

Modified: 
clang/lib/AST/ASTContext.cpp
clang/test/CodeGen/aarch64-varargs.c
clang/test/CodeGen/arm64-be-hfa-vararg.c
clang/test/Headers/stdarg.cpp

Removed: 




diff  --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index a1f3baf997046..47f30f5ff9a41 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -7998,19 +7998,21 @@ static TypedefDecl 
*CreateVoidPtrBuiltinVaListDecl(const ASTContext *Context) {
 
 static TypedefDecl *
 CreateAArch64ABIBuiltinVaListDecl(const ASTContext *Context) {
-  // struct __va_list
   RecordDecl *VaListTagDecl = Context->buildImplicitRecord("__va_list");
-  if (Context->getLangOpts().CPlusPlus) {
-// namespace std { struct __va_list {
-NamespaceDecl *NS;
-NS = NamespaceDecl::Create(const_cast(*Context),
-   Context->getTranslationUnitDecl(),
-   /*Inline*/ false, SourceLocation(),
-   SourceLocation(), >Idents.get("std"),
-   /*PrevDecl*/ nullptr);
-NS->setImplicit();
-VaListTagDecl->setDeclContext(NS);
-  }
+  // namespace std { struct __va_list {
+  // Note that we create the namespace even in C. This is intentional so that
+  // the type is consistent between C and C++, which is important in cases 
where
+  // the types need to match between translation units (e.g. with
+  // -fsanitize=cfi-icall). Ideally we wouldn't have created this namespace at
+  // all, but it's now part of the ABI (e.g. in mangled names), so we can't
+  // change it.
+  auto *NS = NamespaceDecl::Create(
+  const_cast(*Context), Context->getTranslationUnitDecl(),
+  /*Inline*/ false, SourceLocation(), SourceLocation(),
+  >Idents.get("std"),
+  /*PrevDecl*/ nullptr);
+  NS->setImplicit();
+  VaListTagDecl->setDeclContext(NS);
 
   VaListTagDecl->startDefinition();
 

diff  --git a/clang/test/CodeGen/aarch64-varargs.c 
b/clang/test/CodeGen/aarch64-varargs.c
index 908fb4ae5d10e..397d61616b916 100644
--- a/clang/test/CodeGen/aarch64-varargs.c
+++ b/clang/test/CodeGen/aarch64-varargs.c
@@ -11,18 +11,18 @@ va_list the_list;
 int simple_int(void) {
 // CHECK-LABEL: define{{.*}} i32 @simple_int
   return va_arg(the_list, int);
-// CHECK: [[GR_OFFS:%[a-z_0-9]+]] = load i32, i32* getelementptr inbounds 
(%struct.__va_list, %struct.__va_list* @the_list, i32 0, i32 3)
+// CHECK: [[GR_OFFS:%[a-z_0-9]+]] = load i32, i32* getelementptr inbounds 
(%"struct.std::__va_list", %"struct.std::__va_list"* @the_list, i32 0, i32 3)
 // CHECK: [[EARLY_ONSTACK:%[a-z_0-9]+]] = icmp sge i32 [[GR_OFFS]], 0
 // CHECK: br i1 [[EARLY_ONSTACK]], label %[[VAARG_ON_STACK:[a-z_.0-9]+]], 
label %[[VAARG_MAYBE_REG:[a-z_.0-9]+]]
 
 // CHECK: [[VAARG_MAYBE_REG]]
 // CHECK: [[NEW_REG_OFFS:%[a-z_0-9]+]] = add i32 [[GR_OFFS]], 8
-// CHECK: store i32 [[NEW_REG_OFFS]], i32* getelementptr inbounds 
(%struct.__va_list, %struct.__va_list* @the_list, i32 0, i32 3)
+// CHECK: store i32 [[NEW_REG_OFFS]], i32* getelementptr inbounds 
(%"struct.std::__va_list", %"struct.std::__va_list"* @the_list, i32 0, i32 3)
 // CHECK: [[INREG:%[a-z_0-9]+]] = icmp sle i32 [[NEW_REG_OFFS]], 0
 // CHECK: br i1 [[INREG]], label %[[VAARG_IN_REG:[a-z_.0-9]+]], label 
%[[VAARG_ON_STACK]]
 
 // CHECK: [[VAARG_IN_REG]]
-// CHECK: [[REG_TOP:%[a-z_0-9]+]] = load i8*, i8** getelementptr inbounds 
(%struct.__va_list, %struct.__va_list* @the_list, i32 0, i32 1)
+// CHECK: [[REG_TOP:%[a-z_0-9]+]] = load i8*, i8** getelementptr inbounds 
(%"struct.std::__va_list", %"struct.std::__va_list"* @the_list, i32 0, i32 1)
 // CHECK: [[REG_ADDR:%[a-z_0-9]+]] = getelementptr inbounds i8, i8* 
[[REG_TOP]], i32 [[GR_OFFS]]
 // CHECK-BE: [[REG_ADDR_ALIGNED:%[0-9]+]] = getelementptr inbounds i8, i8* 
[[REG_ADDR]], i64 4
 // CHECK-BE: [[FROMREG_ADDR:%[a-z_0-9]+]] = bitcast i8* [[REG_ADDR_ALIGNED]] 
to i32*
@@ -30,9 +30,9 @@ int simple_int(void) {
 // CHECK: br label %[[VAARG_END:[a-z._0-9]+]]
 
 // CHECK: [[VAARG_ON_STACK]]
-// CHECK: [[STACK:%[a-z_0-9]+]] = load i8*, i8** getelementptr inbounds 
(%struct.__va_list, %struct.__va_list* @the_list, i32 0, i32 0)
+// CHECK: 

[libunwind] cddc53e - libunwind: Don't attempt to authenticate a null return address.

2021-02-16 Thread Peter Collingbourne via cfe-commits

Author: Peter Collingbourne
Date: 2021-02-16T11:18:02-08:00
New Revision: cddc53ef088b68586094c9841a76b41bee3994a4

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

LOG: libunwind: Don't attempt to authenticate a null return address.

Null return addresses can appear at the bottom of the stack (i.e. the
frame corresponding to the entry point). Authenticating these addresses
will set the error code in the address, which will lead to a segfault
in the sigreturn trampoline detection code. Fix this problem by not
authenticating null addresses.

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

Added: 


Modified: 
libunwind/src/DwarfInstructions.hpp

Removed: 




diff  --git a/libunwind/src/DwarfInstructions.hpp 
b/libunwind/src/DwarfInstructions.hpp
index c39cabe1f783..bd13d1623153 100644
--- a/libunwind/src/DwarfInstructions.hpp
+++ b/libunwind/src/DwarfInstructions.hpp
@@ -213,7 +213,8 @@ int DwarfInstructions::stepWithDwarf(A , 
pint_t pc,
   // restored. autia1716 is used instead of autia as autia1716 assembles
   // to a NOP on pre-v8.3a architectures.
   if ((R::getArch() == REGISTERS_ARM64) &&
-  prolog.savedRegisters[UNW_ARM64_RA_SIGN_STATE].value) {
+  prolog.savedRegisters[UNW_ARM64_RA_SIGN_STATE].value &&
+  returnAddress != 0) {
 #if !defined(_LIBUNWIND_IS_NATIVE_ONLY)
 return UNW_ECROSSRASIGNING;
 #else



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


[clang] c9b1a2b - AArch64: Use SBFX instead of UBFX to extract address granule in outlined HWASan checks.

2020-10-30 Thread Peter Collingbourne via cfe-commits

Author: Peter Collingbourne
Date: 2020-10-30T12:53:15-07:00
New Revision: c9b1a2b41dca6e6734aa39833a0dab0d0a8b53d3

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

LOG: AArch64: Use SBFX instead of UBFX to extract address granule in outlined 
HWASan checks.

In a kernel (or in general in environments where bit 55 of the address
is set) the shadow base needs to point to the end of the shadow region,
not the beginning. Bit 55 needs to be sign extended into bits 52-63
of the shadow base offset, otherwise we end up loading from an invalid
address. We can do this by using SBFX instead of UBFX.

Using SBFX should have no effect in the userspace case where bit 55
of the address is clear so we do so unconditionally. I don't think
we need a ABI version bump for this (but one will come anyway when
we switch to x20 for the shadow base register).

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

Added: 


Modified: 
clang/docs/HardwareAssistedAddressSanitizerDesign.rst
llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
llvm/test/CodeGen/AArch64/hwasan-check-memaccess.ll

Removed: 




diff  --git a/clang/docs/HardwareAssistedAddressSanitizerDesign.rst 
b/clang/docs/HardwareAssistedAddressSanitizerDesign.rst
index bb612138264e..b97fbb91a43a 100644
--- a/clang/docs/HardwareAssistedAddressSanitizerDesign.rst
+++ b/clang/docs/HardwareAssistedAddressSanitizerDesign.rst
@@ -96,7 +96,7 @@ Currently, the following sequence is used:
 
   [...]
   __hwasan_check_x0_2_short_v2:
-ubfxx16, x0, #4, #52// shadow offset
+sbfxx16, x0, #4, #52// shadow offset
 ldrbw16, [x20, x16] // load shadow tag
 cmp x16, x0, lsr #56// extract address 
tag, compare with shadow tag
 b.ne.Ltmp0  // jump to short tag 
handler on mismatch

diff  --git a/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp 
b/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
index dd101db1917c..006986d70456 100644
--- a/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
+++ b/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
@@ -348,7 +348,7 @@ void AArch64AsmPrinter::EmitHwasanMemaccessSymbols(Module 
) {
 OutStreamer->emitSymbolAttribute(Sym, MCSA_Hidden);
 OutStreamer->emitLabel(Sym);
 
-OutStreamer->emitInstruction(MCInstBuilder(AArch64::UBFMXri)
+OutStreamer->emitInstruction(MCInstBuilder(AArch64::SBFMXri)
  .addReg(AArch64::X16)
  .addReg(Reg)
  .addImm(4)

diff  --git a/llvm/test/CodeGen/AArch64/hwasan-check-memaccess.ll 
b/llvm/test/CodeGen/AArch64/hwasan-check-memaccess.ll
index 4042eee6d262..61fcff5433ed 100644
--- a/llvm/test/CodeGen/AArch64/hwasan-check-memaccess.ll
+++ b/llvm/test/CodeGen/AArch64/hwasan-check-memaccess.ll
@@ -38,7 +38,7 @@ declare void @llvm.hwasan.check.memaccess.shortgranules(i8*, 
i8*, i32)
 ; CHECK-NEXT: .weak __hwasan_check_x0_2_short_v2
 ; CHECK-NEXT: .hidden __hwasan_check_x0_2_short_v2
 ; CHECK-NEXT: __hwasan_check_x0_2_short_v2:
-; CHECK-NEXT: ubfx x16, x0, #4, #52
+; CHECK-NEXT: sbfx x16, x0, #4, #52
 ; CHECK-NEXT: ldrb w16, [x20, x16]
 ; CHECK-NEXT: cmp x16, x0, lsr #56
 ; CHECK-NEXT: b.ne .Ltmp0
@@ -69,7 +69,7 @@ declare void @llvm.hwasan.check.memaccess.shortgranules(i8*, 
i8*, i32)
 ; CHECK-NEXT: .weak __hwasan_check_x1_1
 ; CHECK-NEXT: .hidden __hwasan_check_x1_1
 ; CHECK-NEXT: __hwasan_check_x1_1:
-; CHECK-NEXT: ubfx x16, x1, #4, #52
+; CHECK-NEXT: sbfx x16, x1, #4, #52
 ; CHECK-NEXT: ldrb w16, [x9, x16]
 ; CHECK-NEXT: cmp x16, x1, lsr #56
 ; CHECK-NEXT: b.ne .Ltmp3



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


[clang] 3859fc6 - AArch64: Switch to x20 as the shadow base register for outlined HWASan checks.

2020-10-30 Thread Peter Collingbourne via cfe-commits

Author: Peter Collingbourne
Date: 2020-10-30T12:51:30-07:00
New Revision: 3859fc653fb49f4acfb61b6f2c38736ec9bfae06

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

LOG: AArch64: Switch to x20 as the shadow base register for outlined HWASan 
checks.

>From a code size perspective it turns out to be better to use a
callee-saved register to pass the shadow base. For non-leaf functions
it avoids the need to reload the shadow base into x9 after each
function call, at the cost of an additional stack slot to save the
caller's x20. But with x9 there is also a stack size cost, either
as a result of copying x9 to a callee-saved register across calls or
by spilling it to stack, so for the non-leaf functions the change to
stack usage is largely neutral.

It is also code size (and stack size) neutral for many leaf functions.
Although they now need to save/restore x20 this can typically be
combined via LDP/STP into the x30 save/restore. In the case where
the function needs callee-saved registers or stack spills we end up
needing, on average, 8 more bytes of stack and 1 more instruction
but given the improvements to other functions this seems like the
right tradeoff.

Unfortunately we cannot change the register for the v1 (non short
granules) check because the runtime assumes that the shadow base
register is stored in x9, so the v1 check still uses x9.

Aside from that there is no change to the ABI because the choice
of shadow base register is a contract between the caller and the
outlined check function, both of which are compiler generated. We do
need to rename the v2 check functions though because the functions
are deduplicated based on their names, not on their contents, and we
need to make sure that when object files from old and new compilers
are linked together we don't end up with a function that uses x9
calling an outlined check that uses x20 or vice versa.

With this change code size of /system/lib64/*.so in an Android build
with HWASan goes from 200066976 bytes to 194085912 bytes, or a 3%
decrease.

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

Added: 


Modified: 
clang/docs/HardwareAssistedAddressSanitizerDesign.rst
compiler-rt/test/hwasan/TestCases/register-dump-read.c
llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
llvm/lib/Target/AArch64/AArch64InstrInfo.td
llvm/test/CodeGen/AArch64/hwasan-check-memaccess.ll

Removed: 




diff  --git a/clang/docs/HardwareAssistedAddressSanitizerDesign.rst 
b/clang/docs/HardwareAssistedAddressSanitizerDesign.rst
index 0e6c6902cfb3..bb612138264e 100644
--- a/clang/docs/HardwareAssistedAddressSanitizerDesign.rst
+++ b/clang/docs/HardwareAssistedAddressSanitizerDesign.rst
@@ -84,20 +84,20 @@ Currently, the following sequence is used:
   // clang -O2 --target=aarch64-linux-android30 -fsanitize=hwaddress -S -o - 
load.c
   [...]
   foo:
-str x30, [sp, #-16]!
-adrpx9, :got:__hwasan_shadow// load shadow address 
from GOT into x9
-ldr x9, [x9, :got_lo12:__hwasan_shadow]
-bl  __hwasan_check_x0_2_short   // call outlined tag 
check
-// (arguments: x0 = 
address, x9 = shadow base;
+stp x30, x20, [sp, #-16]!
+adrpx20, :got:__hwasan_shadow   // load shadow address 
from GOT into x20
+ldr x20, [x20, :got_lo12:__hwasan_shadow]
+bl  __hwasan_check_x0_2_short_v2// call outlined tag 
check
+// (arguments: x0 = 
address, x20 = shadow base;
 // "2" encodes the 
access type and size)
 ldr w0, [x0]// inline load
-ldr x30, [sp], #16
+ldp x30, x20, [sp], #16
 ret
 
   [...]
-  __hwasan_check_x0_2_short:
+  __hwasan_check_x0_2_short_v2:
 ubfxx16, x0, #4, #52// shadow offset
-ldrbw16, [x9, x16]  // load shadow tag
+ldrbw16, [x20, x16] // load shadow tag
 cmp x16, x0, lsr #56// extract address 
tag, compare with shadow tag
 b.ne.Ltmp0  // jump to short tag 
handler on mismatch
   .Ltmp1:

diff  --git a/compiler-rt/test/hwasan/TestCases/register-dump-read.c 
b/compiler-rt/test/hwasan/TestCases/register-dump-read.c
index 19bf03f5d030..8325857fa916 100644
--- a/compiler-rt/test/hwasan/TestCases/register-dump-read.c
+++ b/compiler-rt/test/hwasan/TestCases/register-dump-read.c
@@ -15,7 +15,7 @@ int main() {
   __hwasan_enable_allocator_tagging();
   char * volatile x = (char*) 

[clang] c5acd34 - Driver: Add integer sanitizers to trapping group automatically.

2020-10-20 Thread Peter Collingbourne via cfe-commits

Author: Peter Collingbourne
Date: 2020-10-20T13:45:39-07:00
New Revision: c5acd3490b79703426931f7b88b544fe7c6e1ef2

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

LOG: Driver: Add integer sanitizers to trapping group automatically.

In D86000 we added a new sanitizer to the integer group
without adding it to the trapping group. This broke usage of
-fsanitize=integer -fsanitize-trap=integer or -fsanitize=integer
-fsanitize-minimal-runtime.

I think we can reasonably expect any new integer sanitizers to be
compatible with trapping and the minimal runtime, so add them to the
trapping group automatically.

Also add a test to ensure that any future additions of sanitizers
to the integer group will most likely result in test failures which
would lead to updates to the minimal runtime if necessary. For this
particular sanitizer no updates are required because it uses the
existing shift_out_of_bounds callback function.

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

Added: 


Modified: 
clang/lib/Driver/SanitizerArgs.cpp
clang/test/Driver/fsanitize.c

Removed: 




diff  --git a/clang/lib/Driver/SanitizerArgs.cpp 
b/clang/lib/Driver/SanitizerArgs.cpp
index 90dbced3240d..68ae25e9cc20 100644
--- a/clang/lib/Driver/SanitizerArgs.cpp
+++ b/clang/lib/Driver/SanitizerArgs.cpp
@@ -60,8 +60,7 @@ static const SanitizerMask AlwaysRecoverable =
 SanitizerKind::KernelAddress | SanitizerKind::KernelHWAddress;
 static const SanitizerMask NeedsLTO = SanitizerKind::CFI;
 static const SanitizerMask TrappingSupported =
-(SanitizerKind::Undefined & ~SanitizerKind::Vptr) |
-SanitizerKind::UnsignedIntegerOverflow | SanitizerKind::ImplicitConversion 
|
+(SanitizerKind::Undefined & ~SanitizerKind::Vptr) | SanitizerKind::Integer 
|
 SanitizerKind::Nullability | SanitizerKind::LocalBounds |
 SanitizerKind::CFI | SanitizerKind::FloatDivideByZero |
 SanitizerKind::ObjCCast;

diff  --git a/clang/test/Driver/fsanitize.c b/clang/test/Driver/fsanitize.c
index bad519fcef24..0ecf656f292c 100644
--- a/clang/test/Driver/fsanitize.c
+++ b/clang/test/Driver/fsanitize.c
@@ -786,6 +786,13 @@
 // CHECK-UBSAN-MINIMAL: 
"-fsanitize={{((signed-integer-overflow|integer-divide-by-zero|shift-base|shift-exponent|unreachable|return|vla-bound|alignment|null|pointer-overflow|float-cast-overflow|array-bounds|enum|bool|builtin|returns-nonnull-attribute|nonnull-attribute),?){17}"}}
 // CHECK-UBSAN-MINIMAL: "-fsanitize-minimal-runtime"
 
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=integer 
-fsanitize-trap=integer %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-INTSAN-TRAP
+// CHECK-INTSAN-TRAP: 
"-fsanitize-trap=integer-divide-by-zero,shift-base,shift-exponent,signed-integer-overflow,unsigned-integer-overflow,unsigned-shift-base,implicit-unsigned-integer-truncation,implicit-signed-integer-truncation,implicit-integer-sign-change"
+
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=integer 
-fsanitize-minimal-runtime %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-INTSAN-MINIMAL
+// CHECK-INTSAN-MINIMAL: 
"-fsanitize=integer-divide-by-zero,shift-base,shift-exponent,signed-integer-overflow,unsigned-integer-overflow,unsigned-shift-base,implicit-unsigned-integer-truncation,implicit-signed-integer-truncation,implicit-integer-sign-change"
+// CHECK-INTSAN-MINIMAL: "-fsanitize-minimal-runtime"
+
 // RUN: %clang -target aarch64-linux-android -march=armv8-a+memtag 
-fsanitize=memtag -fsanitize-minimal-runtime %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-MEMTAG-MINIMAL
 // CHECK-MEMTAG-MINIMAL: "-fsanitize=memtag"
 // CHECK-MEMTAG-MINIMAL: "-fsanitize-minimal-runtime"



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


[clang] 7931e8e - Update hwasan docs to cover outlined checks and globals.

2020-02-06 Thread Peter Collingbourne via cfe-commits

Author: Peter Collingbourne
Date: 2020-02-06T17:44:43-08:00
New Revision: 7931e8eee3dafe64101dcc1e88276ba81071

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

LOG: Update hwasan docs to cover outlined checks and globals.

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

Added: 


Modified: 
clang/docs/HardwareAssistedAddressSanitizerDesign.rst

Removed: 




diff  --git a/clang/docs/HardwareAssistedAddressSanitizerDesign.rst 
b/clang/docs/HardwareAssistedAddressSanitizerDesign.rst
index d02dc00057fe..0e6c6902cfb3 100644
--- a/clang/docs/HardwareAssistedAddressSanitizerDesign.rst
+++ b/clang/docs/HardwareAssistedAddressSanitizerDesign.rst
@@ -67,43 +67,59 @@ Instrumentation
 
 Memory Accesses
 ---
-All memory accesses are prefixed with an inline instruction sequence that
-verifies the tags. Currently, the following sequence is used:
+In the majority of cases, memory accesses are prefixed with a call to
+an outlined instruction sequence that verifies the tags. The code size
+and performance overhead of the call is reduced by using a custom calling
+convention that
+
+* preserves most registers, and
+* is specialized to the register containing the address, and the type and
+  size of the memory access.
+
+Currently, the following sequence is used:
 
 .. code-block:: none
 
   // int foo(int *a) { return *a; }
-  // clang -O2 --target=aarch64-linux -fsanitize=hwaddress 
-fsanitize-recover=hwaddress -c load.c
+  // clang -O2 --target=aarch64-linux-android30 -fsanitize=hwaddress -S -o - 
load.c
+  [...]
   foo:
-   0:  9008adrpx8, 0 <__hwasan_shadow>
-   4:  f9400108ldr x8, [x8] // shadow base (to be 
resolved by the loader)
-   8:  d344dc09ubfxx9, x0, #4, #52  // shadow offset
-   c:  38696909ldrbw9, [x8, x9] // load shadow tag
-  10:  d378fc08lsr x8, x0, #56  // extract address tag
-  14:  6b09011fcmp w8, w9   // compare tags
-  18:  5461b.ne24 // jump to short tag 
handler on mismatch
-  1c:  b940ldr w0, [x0] // original load
-  20:  d65f03c0ret
-  24:  7100413fcmp w9, #0x10// is this a short tag?
-  28:  54000142b.cs50 // if not, trap
-  2c:  12000c0aand w10, w0, #0xf// find the address's 
position in the short granule
-  30:  11000d4aadd w10, w10, #0x3   // adjust to the 
position of the last byte loaded
-  34:  6b09015fcmp w10, w9  // check that position 
is in bounds
-  38:  54c2b.cs50 // if not, trap
-  3c:  9240dc09and x9, x0, #0xff
-  40:  b2400d29orr x9, x9, #0xf // compute address of 
last byte of granule
-  44:  39400129ldrbw9, [x9] // load tag from it
-  48:  6b09011fcmp w8, w9   // compare with 
pointer tag
-  4c:  54fffe80b.eq1c // if so, continue
-  50:  d4212440brk #0x922   // otherwise trap
-  54:  b940ldr w0, [x0] // tail duplicated 
original load (to handle recovery)
-  58:  d65f03c0ret
-
-Alternatively, memory accesses are prefixed with a function call.
-On AArch64, a function call is used by default in trapping mode. The code size
-and performance overhead of the call is reduced by using a custom calling
-convention that preserves most registers and is specialized to the register
-containing the address and the type and size of the memory access.
+str x30, [sp, #-16]!
+adrpx9, :got:__hwasan_shadow// load shadow address 
from GOT into x9
+ldr x9, [x9, :got_lo12:__hwasan_shadow]
+bl  __hwasan_check_x0_2_short   // call outlined tag 
check
+// (arguments: x0 = 
address, x9 = shadow base;
+// "2" encodes the 
access type and size)
+ldr w0, [x0]// inline load
+ldr x30, [sp], #16
+ret
+
+  [...]
+  __hwasan_check_x0_2_short:
+ubfxx16, x0, #4, #52// shadow offset
+ldrbw16, [x9, x16]  // load shadow tag
+cmp x16, x0, lsr #56// extract address 
tag, compare with shadow tag
+b.ne.Ltmp0  // jump to short tag 
handler on mismatch
+  .Ltmp1:
+ret
+  .Ltmp0:
+

[clang] bab9849 - Reland 198fbcb8, "Driver: Don't look for libc++ headers in the install directory on Android.", which was reverted in b3249027.

2019-12-09 Thread Peter Collingbourne via cfe-commits

Author: Peter Collingbourne
Date: 2019-12-09T10:08:02-08:00
New Revision: bab9849963eb9b9f1fa03900e8c48a7c7d6fc305

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

LOG: Reland 198fbcb8, "Driver: Don't look for libc++ headers in the install 
directory on Android.", which was reverted in b3249027.

Fixed the test case to set --sysroot, which lets it succeed in the case where
a directory named "/usr/include/c++/v1" or "/usr/local/include/c++/v1" exists.

Original commit message:
> The NDK uses a separate set of libc++ headers in the sysroot. Any headers
> in the installation directory are not going to work on Android, not least
> because they use a different name for the inline namespace (std::__1 instead
> of std::__ndk1).
>
> This effectively makes it impossible to produce a single toolchain that is
> capable of targeting both Android and another platform that expects libc++
> headers to be installed in the installation directory, such as Mac.
>
> In order to allow this scenario to work, stop looking for headers in the
> install directory on Android.

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

Added: 
clang/test/Driver/android-no-installed-libcxx.cpp

Modified: 
clang/lib/Driver/ToolChains/Linux.cpp
clang/test/Driver/stdlibxx-isystem.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Linux.cpp 
b/clang/lib/Driver/ToolChains/Linux.cpp
index 736a2d435ca5..adacd705d831 100644
--- a/clang/lib/Driver/ToolChains/Linux.cpp
+++ b/clang/lib/Driver/ToolChains/Linux.cpp
@@ -888,20 +888,25 @@ static std::string 
DetectLibcxxIncludePath(llvm::vfs::FileSystem ,
 void Linux::addLibCxxIncludePaths(const llvm::opt::ArgList ,
   llvm::opt::ArgStringList ) const {
   const std::string& SysRoot = computeSysRoot();
-  const std::string LibCXXIncludePathCandidates[] = {
-  DetectLibcxxIncludePath(getVFS(), getDriver().Dir + "/../include/c++"),
-  // If this is a development, non-installed, clang, libcxx will
-  // not be found at ../include/c++ but it likely to be found at
-  // one of the following two locations:
-  DetectLibcxxIncludePath(getVFS(), SysRoot + "/usr/local/include/c++"),
-  DetectLibcxxIncludePath(getVFS(), SysRoot + "/usr/include/c++") };
-  for (const auto  : LibCXXIncludePathCandidates) {
+  auto AddIncludePath = [&](std::string Path) {
+std::string IncludePath = DetectLibcxxIncludePath(getVFS(), Path);
 if (IncludePath.empty() || !getVFS().exists(IncludePath))
-  continue;
-// Use the first candidate that exists.
+  return false;
 addSystemInclude(DriverArgs, CC1Args, IncludePath);
+return true;
+  };
+  // Android never uses the libc++ headers installed alongside the toolchain,
+  // which are generally incompatible with the NDK libraries anyway.
+  if (!getTriple().isAndroid())
+if (AddIncludePath(getDriver().Dir + "/../include/c++"))
+  return;
+  // If this is a development, non-installed, clang, libcxx will
+  // not be found at ../include/c++ but it likely to be found at
+  // one of the following two locations:
+  if (AddIncludePath(SysRoot + "/usr/local/include/c++"))
+return;
+  if (AddIncludePath(SysRoot + "/usr/include/c++"))
 return;
-  }
 }
 
 void Linux::addLibStdCxxIncludePaths(const llvm::opt::ArgList ,

diff  --git a/clang/test/Driver/android-no-installed-libcxx.cpp 
b/clang/test/Driver/android-no-installed-libcxx.cpp
new file mode 100644
index ..a496a8289b91
--- /dev/null
+++ b/clang/test/Driver/android-no-installed-libcxx.cpp
@@ -0,0 +1,10 @@
+// Check that we don't find the libc++ in the installation directory when
+// targeting Android.
+
+// RUN: mkdir -p %t/bin
+// RUN: mkdir -p %t/include/c++/v1
+// RUN: mkdir -p %t/sysroot
+// RUN: %clang -target aarch64-linux-android -ccc-install-dir %t/bin \
+// RUN:   --sysroot=%t/sysroot -stdlib=libc++ -fsyntax-only \
+// RUN:   %s -### 2>&1 | FileCheck %s
+// CHECK-NOT: "-internal-isystem" "{{.*}}v1"

diff  --git a/clang/test/Driver/stdlibxx-isystem.cpp 
b/clang/test/Driver/stdlibxx-isystem.cpp
index cf7535ff423e..827cdf9a7c71 100644
--- a/clang/test/Driver/stdlibxx-isystem.cpp
+++ b/clang/test/Driver/stdlibxx-isystem.cpp
@@ -6,7 +6,7 @@
 // By default, we should search for libc++ next to the driver.
 // RUN: mkdir -p %t/bin
 // RUN: mkdir -p %t/include/c++/v1
-// RUN: %clang -target aarch64-linux-android -ccc-install-dir %t/bin \
+// RUN: %clang -target aarch64-linux-gnu -ccc-install-dir %t/bin \
 // RUN:   -stdlib=libc++ -fsyntax-only %s -### 2>&1 | \
 // RUN:   FileCheck -check-prefix=LIBCXX %s
 // RUN: %clang -target x86_64-apple-darwin -ccc-install-dir %t/bin \
@@ -16,7 +16,7 @@
 // LIBCXX: "-internal-isystem" "[[INSTALLDIR]]/../include/c++/v1"
 
 // Passing 

[clang] 198fbcb - Driver: Don't look for libc++ headers in the install directory on Android.

2019-12-06 Thread Peter Collingbourne via cfe-commits

Author: Peter Collingbourne
Date: 2019-12-06T18:24:23-08:00
New Revision: 198fbcb817492ff45946e3f7517de15e8cdf0607

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

LOG: Driver: Don't look for libc++ headers in the install directory on Android.

The NDK uses a separate set of libc++ headers in the sysroot. Any headers
in the installation directory are not going to work on Android, not least
because they use a different name for the inline namespace (std::__1 instead
of std::__ndk1).

This effectively makes it impossible to produce a single toolchain that is
capable of targeting both Android and another platform that expects libc++
headers to be installed in the installation directory, such as Mac.

In order to allow this scenario to work, stop looking for headers in the
install directory on Android.

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

Added: 
clang/test/Driver/android-no-installed-libcxx.cpp

Modified: 
clang/lib/Driver/ToolChains/Linux.cpp
clang/test/Driver/stdlibxx-isystem.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Linux.cpp 
b/clang/lib/Driver/ToolChains/Linux.cpp
index 736a2d435ca5..adacd705d831 100644
--- a/clang/lib/Driver/ToolChains/Linux.cpp
+++ b/clang/lib/Driver/ToolChains/Linux.cpp
@@ -888,20 +888,25 @@ static std::string 
DetectLibcxxIncludePath(llvm::vfs::FileSystem ,
 void Linux::addLibCxxIncludePaths(const llvm::opt::ArgList ,
   llvm::opt::ArgStringList ) const {
   const std::string& SysRoot = computeSysRoot();
-  const std::string LibCXXIncludePathCandidates[] = {
-  DetectLibcxxIncludePath(getVFS(), getDriver().Dir + "/../include/c++"),
-  // If this is a development, non-installed, clang, libcxx will
-  // not be found at ../include/c++ but it likely to be found at
-  // one of the following two locations:
-  DetectLibcxxIncludePath(getVFS(), SysRoot + "/usr/local/include/c++"),
-  DetectLibcxxIncludePath(getVFS(), SysRoot + "/usr/include/c++") };
-  for (const auto  : LibCXXIncludePathCandidates) {
+  auto AddIncludePath = [&](std::string Path) {
+std::string IncludePath = DetectLibcxxIncludePath(getVFS(), Path);
 if (IncludePath.empty() || !getVFS().exists(IncludePath))
-  continue;
-// Use the first candidate that exists.
+  return false;
 addSystemInclude(DriverArgs, CC1Args, IncludePath);
+return true;
+  };
+  // Android never uses the libc++ headers installed alongside the toolchain,
+  // which are generally incompatible with the NDK libraries anyway.
+  if (!getTriple().isAndroid())
+if (AddIncludePath(getDriver().Dir + "/../include/c++"))
+  return;
+  // If this is a development, non-installed, clang, libcxx will
+  // not be found at ../include/c++ but it likely to be found at
+  // one of the following two locations:
+  if (AddIncludePath(SysRoot + "/usr/local/include/c++"))
+return;
+  if (AddIncludePath(SysRoot + "/usr/include/c++"))
 return;
-  }
 }
 
 void Linux::addLibStdCxxIncludePaths(const llvm::opt::ArgList ,

diff  --git a/clang/test/Driver/android-no-installed-libcxx.cpp 
b/clang/test/Driver/android-no-installed-libcxx.cpp
new file mode 100644
index ..b6f4227c7dc1
--- /dev/null
+++ b/clang/test/Driver/android-no-installed-libcxx.cpp
@@ -0,0 +1,8 @@
+// Check that we don't find the libc++ in the installation directory when
+// targeting Android.
+
+// RUN: mkdir -p %t/bin
+// RUN: mkdir -p %t/include/c++/v1
+// RUN: %clang -target aarch64-linux-android -ccc-install-dir %t/bin \
+// RUN:   -stdlib=libc++ -fsyntax-only %s -### 2>&1 | FileCheck %s
+// CHECK-NOT: "-internal-isystem" "{{.*}}v1"

diff  --git a/clang/test/Driver/stdlibxx-isystem.cpp 
b/clang/test/Driver/stdlibxx-isystem.cpp
index cf7535ff423e..827cdf9a7c71 100644
--- a/clang/test/Driver/stdlibxx-isystem.cpp
+++ b/clang/test/Driver/stdlibxx-isystem.cpp
@@ -6,7 +6,7 @@
 // By default, we should search for libc++ next to the driver.
 // RUN: mkdir -p %t/bin
 // RUN: mkdir -p %t/include/c++/v1
-// RUN: %clang -target aarch64-linux-android -ccc-install-dir %t/bin \
+// RUN: %clang -target aarch64-linux-gnu -ccc-install-dir %t/bin \
 // RUN:   -stdlib=libc++ -fsyntax-only %s -### 2>&1 | \
 // RUN:   FileCheck -check-prefix=LIBCXX %s
 // RUN: %clang -target x86_64-apple-darwin -ccc-install-dir %t/bin \
@@ -16,7 +16,7 @@
 // LIBCXX: "-internal-isystem" "[[INSTALLDIR]]/../include/c++/v1"
 
 // Passing -stdlib++-isystem should suppress the default search.
-// RUN: %clang -target aarch64-linux-android -ccc-install-dir %t/bin \
+// RUN: %clang -target aarch64-linux-gnu -ccc-install-dir %t/bin \
 // RUN:   -stdlib++-isystem /tmp/foo -stdlib++-isystem /tmp/bar -stdlib=libc++ 
\
 // RUN:   -fsyntax-only %s -### 2>&1 | FileCheck 

[clang] 90b8bc0 - IRGen: Call SetLLVMFunctionAttributes{, ForDefinition} on __cfi_check_fail.

2019-11-25 Thread Peter Collingbourne via cfe-commits

Author: Peter Collingbourne
Date: 2019-11-25T15:16:43-08:00
New Revision: 90b8bc003caacd165dedbb9cafc32de10d610ea7

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

LOG: IRGen: Call SetLLVMFunctionAttributes{,ForDefinition} on __cfi_check_fail.

This has the main effect of causing target-cpu and target-features to be set
on __cfi_check_fail, causing the function to become ABI-compatible with other
functions in the case where these attributes affect ABI (e.g. reserve-x18).

Technically we only need to call SetLLVMFunctionAttributes to get the target-*
attributes set, but since we're creating a definition we probably ought to
call the ForDefinition function as well.

Fixes PR44094.

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

Added: 
clang/test/CodeGen/cfi-check-fail-attrs.c

Modified: 
clang/lib/CodeGen/CGExpr.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 214378a966f0..04c6504910b8 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -3200,6 +3200,9 @@ void CodeGenFunction::EmitCfiCheckFail() {
   llvm::Function *F = llvm::Function::Create(
   llvm::FunctionType::get(VoidTy, {VoidPtrTy, VoidPtrTy}, false),
   llvm::GlobalValue::WeakODRLinkage, "__cfi_check_fail", ());
+
+  CGM.SetLLVMFunctionAttributes(GlobalDecl(), FI, F);
+  CGM.SetLLVMFunctionAttributesForDefinition(nullptr, F);
   F->setVisibility(llvm::GlobalValue::HiddenVisibility);
 
   StartFunction(GlobalDecl(), CGM.getContext().VoidTy, F, FI, Args,

diff  --git a/clang/test/CodeGen/cfi-check-fail-attrs.c 
b/clang/test/CodeGen/cfi-check-fail-attrs.c
new file mode 100644
index ..77ba29a5581c
--- /dev/null
+++ b/clang/test/CodeGen/cfi-check-fail-attrs.c
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 -triple aarch64-unknown-linux -fsanitize-cfi-cross-dso 
-target-feature +reserve-x18 -emit-llvm -o - %s | FileCheck %s
+
+// CHECK: define weak_odr hidden void @__cfi_check_fail{{.*}} [[ATTR:#[0-9]*]]
+
+// CHECK: attributes [[ATTR]] = {{.*}} "target-features"="+reserve-x18"



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


r375313 - Sema: Create a no-op implicit cast for lvalue function conversions.

2019-10-18 Thread Peter Collingbourne via cfe-commits
Author: pcc
Date: Fri Oct 18 17:34:54 2019
New Revision: 375313

URL: http://llvm.org/viewvc/llvm-project?rev=375313=rev
Log:
Sema: Create a no-op implicit cast for lvalue function conversions.

This fixes an assertion failure in the case where an implicit conversion for a
function call involves an lvalue function conversion, and makes the AST for
initializations involving implicit lvalue function conversions more accurate.

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

Added:
cfe/trunk/test/CodeGenCXX/implicit-function-conversion.cpp
Modified:
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/Sema/SemaCast.cpp
cfe/trunk/lib/Sema/SemaExprCXX.cpp
cfe/trunk/lib/Sema/SemaInit.cpp
cfe/trunk/lib/Sema/SemaOverload.cpp

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=375313=375312=375313=diff
==
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Fri Oct 18 17:34:54 2019
@@ -10419,11 +10419,11 @@ public:
 Ref_Compatible
   };
 
-  ReferenceCompareResult CompareReferenceRelationship(SourceLocation Loc,
-  QualType T1, QualType T2,
-  bool ,
-  bool ,
-bool );
+  ReferenceCompareResult
+  CompareReferenceRelationship(SourceLocation Loc, QualType T1, QualType T2,
+   bool , bool ,
+   bool ,
+   bool );
 
   ExprResult checkUnknownAnyCast(SourceRange TypeRange, QualType CastType,
  Expr *CastExpr, CastKind ,

Modified: cfe/trunk/lib/Sema/SemaCast.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCast.cpp?rev=375313=375312=375313=diff
==
--- cfe/trunk/lib/Sema/SemaCast.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCast.cpp Fri Oct 18 17:34:54 2019
@@ -1304,6 +1304,7 @@ TryCastResult TryLValueToRValueCast(Sema
   bool DerivedToBase;
   bool ObjCConversion;
   bool ObjCLifetimeConversion;
+  bool FunctionConversion;
   QualType FromType = SrcExpr->getType();
   QualType ToType = R->getPointeeType();
   if (CStyle) {
@@ -1313,7 +1314,7 @@ TryCastResult TryLValueToRValueCast(Sema
 
   Sema::ReferenceCompareResult RefResult = Self.CompareReferenceRelationship(
   SrcExpr->getBeginLoc(), ToType, FromType, DerivedToBase, ObjCConversion,
-  ObjCLifetimeConversion);
+  ObjCLifetimeConversion, FunctionConversion);
   if (RefResult != Sema::Ref_Compatible) {
 if (CStyle || RefResult == Sema::Ref_Incompatible)
   return TC_NotApplicable;

Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=375313=375312=375313=diff
==
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Fri Oct 18 17:34:54 2019
@@ -5852,20 +5852,21 @@ QualType Sema::CXXCheckConditionalOperan
   LVK == RVK && LVK != VK_RValue) {
 // DerivedToBase was already handled by the class-specific case above.
 // FIXME: Should we allow ObjC conversions here?
-bool DerivedToBase, ObjCConversion, ObjCLifetimeConversion;
-if (CompareReferenceRelationship(
-QuestionLoc, LTy, RTy, DerivedToBase,
-ObjCConversion, ObjCLifetimeConversion) == Ref_Compatible &&
+bool DerivedToBase, ObjCConversion, ObjCLifetimeConversion,
+FunctionConversion;
+if (CompareReferenceRelationship(QuestionLoc, LTy, RTy, DerivedToBase,
+ ObjCConversion, ObjCLifetimeConversion,
+ FunctionConversion) == Ref_Compatible &&
 !DerivedToBase && !ObjCConversion && !ObjCLifetimeConversion &&
 // [...] subject to the constraint that the reference must bind
 // directly [...]
-!RHS.get()->refersToBitField() &&
-!RHS.get()->refersToVectorElement()) {
+!RHS.get()->refersToBitField() && !RHS.get()->refersToVectorElement()) 
{
   RHS = ImpCastExprToType(RHS.get(), LTy, CK_NoOp, RVK);
   RTy = RHS.get()->getType();
 } else if (CompareReferenceRelationship(
-   QuestionLoc, RTy, LTy, DerivedToBase,
-   ObjCConversion, ObjCLifetimeConversion) == Ref_Compatible &&
+   QuestionLoc, RTy, LTy, DerivedToBase, ObjCConversion,
+   ObjCLifetimeConversion,
+   FunctionConversion) == Ref_Compatible &&
!DerivedToBase && !ObjCConversion && !ObjCLifetimeConversion &&
!LHS.get()->refersToBitField() &&

Re: r369999 - Don't lose the FoundDecl and template arguments for a DeclRefExpr in

2019-09-25 Thread Peter Collingbourne via cfe-commits
Hi Richard, it looks like this commit caused an assertion failure on the
following input:

$ cat test2.ii
# 2 "" 3
namespace a {
enum { b };
}
template  void c() {
  auto d = [](auto) {
using a::b;
b;
  };
  d(0);
}
void e() { c; }
$ clang test2.ii
clang: ../clang/lib/Sema/SemaTemplateInstantiate.cpp:2985:
llvm::PointerUnion
*clang::LocalInstantiationScope::findInstantiationOf(const clang::Decl *):
Assertion `isa(D) && "declaration not instantiated in this
scope"' failed.

Can you please take a look?

Peter

On Mon, Aug 26, 2019 at 6:04 PM Richard Smith via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: rsmith
> Date: Mon Aug 26 18:06:21 2019
> New Revision: 36
>
> URL: http://llvm.org/viewvc/llvm-project?rev=36=rev
> Log:
> Don't lose the FoundDecl and template arguments for a DeclRefExpr in
> TreeTransform.
>
> Modified:
> cfe/trunk/lib/Sema/TreeTransform.h
>
> Modified: cfe/trunk/lib/Sema/TreeTransform.h
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/TreeTransform.h?rev=36=369998=36=diff
>
> ==
> --- cfe/trunk/lib/Sema/TreeTransform.h (original)
> +++ cfe/trunk/lib/Sema/TreeTransform.h Mon Aug 26 18:06:21 2019
> @@ -2167,13 +2167,12 @@ public:
>ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
>  ValueDecl *VD,
>  const DeclarationNameInfo ,
> +NamedDecl *Found,
>  TemplateArgumentListInfo *TemplateArgs) {
>  CXXScopeSpec SS;
>  SS.Adopt(QualifierLoc);
> -
> -// FIXME: loses template args.
> -
> -return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
> +return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD, Found,
> +  TemplateArgs);
>}
>
>/// Build a new expression in parentheses.
> @@ -9204,6 +9203,14 @@ TreeTransform::TransformDeclRef
>if (!ND)
>  return ExprError();
>
> +  NamedDecl *Found = ND;
> +  if (E->getFoundDecl() != E->getDecl()) {
> +Found = cast_or_null(
> +getDerived().TransformDecl(E->getLocation(), E->getFoundDecl()));
> +if (!Found)
> +  return ExprError();
> +  }
> +
>DeclarationNameInfo NameInfo = E->getNameInfo();
>if (NameInfo.getName()) {
>  NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
> @@ -9236,7 +9243,7 @@ TreeTransform::TransformDeclRef
>}
>
>return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
> - TemplateArgs);
> + Found, TemplateArgs);
>  }
>
>  template
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>


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


r369697 - IR. Change strip* family of functions to not look through aliases.

2019-08-22 Thread Peter Collingbourne via cfe-commits
Author: pcc
Date: Thu Aug 22 12:56:14 2019
New Revision: 369697

URL: http://llvm.org/viewvc/llvm-project?rev=369697=rev
Log:
IR. Change strip* family of functions to not look through aliases.

I noticed another instance of the issue where references to aliases were
being replaced with aliasees, this time in InstCombine. In the instance that
I saw it turned out to be only a QoI issue (a symbol ended up being missing
from the symbol table due to the last reference to the alias being removed,
preventing HWASAN from symbolizing a global reference), but it could easily
have manifested as incorrect behaviour.

Since this is the third such issue encountered (previously: D65118, D65314)
it seems to be time to address this common error/QoI issue once and for all
and make the strip* family of functions not look through aliases.

Includes a test for the specific issue that I saw, but no doubt there are
other similar bugs fixed here.

As with D65118 this has been tested to make sure that the optimization isn't
load bearing. I built Clang, Chromium for Linux, Android and Windows as well
as the test-suite and there were no size regressions.

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

Modified:
cfe/trunk/lib/CodeGen/CGExpr.cpp

Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=369697=369696=369697=diff
==
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Thu Aug 22 12:56:14 2019
@@ -677,8 +677,7 @@ void CodeGenFunction::EmitTypeCheck(Type
   // Quickly determine whether we have a pointer to an alloca. It's possible
   // to skip null checks, and some alignment checks, for these pointers. This
   // can reduce compile-time significantly.
-  auto PtrToAlloca =
-  dyn_cast(Ptr->stripPointerCastsNoFollowAliases());
+  auto PtrToAlloca = dyn_cast(Ptr->stripPointerCasts());
 
   llvm::Value *True = llvm::ConstantInt::getTrue(getLLVMContext());
   llvm::Value *IsNonNull = nullptr;


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


r368495 - cfi-icall: Allow the jump table to be optionally made non-canonical.

2019-08-09 Thread Peter Collingbourne via cfe-commits
Author: pcc
Date: Fri Aug  9 15:31:59 2019
New Revision: 368495

URL: http://llvm.org/viewvc/llvm-project?rev=368495=rev
Log:
cfi-icall: Allow the jump table to be optionally made non-canonical.

The default behavior of Clang's indirect function call checker will replace
the address of each CFI-checked function in the output file's symbol table
with the address of a jump table entry which will pass CFI checks. We refer
to this as making the jump table `canonical`. This property allows code that
was not compiled with ``-fsanitize=cfi-icall`` to take a CFI-valid address
of a function, but it comes with a couple of caveats that are especially
relevant for users of cross-DSO CFI:

- There is a performance and code size overhead associated with each
  exported function, because each such function must have an associated
  jump table entry, which must be emitted even in the common case where the
  function is never address-taken anywhere in the program, and must be used
  even for direct calls between DSOs, in addition to the PLT overhead.

- There is no good way to take a CFI-valid address of a function written in
  assembly or a language not supported by Clang. The reason is that the code
  generator would need to insert a jump table in order to form a CFI-valid
  address for assembly functions, but there is no way in general for the
  code generator to determine the language of the function. This may be
  possible with LTO in the intra-DSO case, but in the cross-DSO case the only
  information available is the function declaration. One possible solution
  is to add a C wrapper for each assembly function, but these wrappers can
  present a significant maintenance burden for heavy users of assembly in
  addition to adding runtime overhead.

For these reasons, we provide the option of making the jump table non-canonical
with the flag ``-fno-sanitize-cfi-canonical-jump-tables``. When the jump
table is made non-canonical, symbol table entries point directly to the
function body. Any instances of a function's address being taken in C will
be replaced with a jump table address.

This scheme does have its own caveats, however. It does end up breaking
function address equality more aggressively than the default behavior,
especially in cross-DSO mode which normally preserves function address
equality entirely.

Furthermore, it is occasionally necessary for code not compiled with
``-fsanitize=cfi-icall`` to take a function address that is valid
for CFI. For example, this is necessary when a function's address
is taken by assembly code and then called by CFI-checking C code. The
``__attribute__((cfi_jump_table_canonical))`` attribute may be used to make
the jump table entry of a specific function canonical so that the external
code will end up taking a address for the function that will pass CFI checks.

Fixes PR41972.

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

Added:
cfe/trunk/test/CodeGen/cfi-icall-canonical-jump-tables.c
cfe/trunk/test/SemaCXX/attr-cfi-canonical-jump-table.cpp
Modified:
cfe/trunk/docs/ControlFlowIntegrity.rst
cfe/trunk/include/clang/Basic/Attr.td
cfe/trunk/include/clang/Basic/AttrDocs.td
cfe/trunk/include/clang/Basic/CodeGenOptions.def
cfe/trunk/include/clang/Driver/Options.td
cfe/trunk/include/clang/Driver/SanitizerArgs.h
cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
cfe/trunk/lib/Driver/SanitizerArgs.cpp
cfe/trunk/lib/Frontend/CompilerInvocation.cpp
cfe/trunk/lib/Sema/SemaDeclAttr.cpp
cfe/trunk/test/CodeGen/cfi-icall-cross-dso.c
cfe/trunk/test/Driver/fsanitize.c
cfe/trunk/test/Misc/pragma-attribute-supported-attributes-list.test

Modified: cfe/trunk/docs/ControlFlowIntegrity.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ControlFlowIntegrity.rst?rev=368495=368494=368495=diff
==
--- cfe/trunk/docs/ControlFlowIntegrity.rst (original)
+++ cfe/trunk/docs/ControlFlowIntegrity.rst Fri Aug  9 15:31:59 2019
@@ -235,6 +235,54 @@ long as the qualifiers for the type they
 ``-fsanitize-cfi-icall-generalize-pointers`` is not compatible with
 ``-fsanitize-cfi-cross-dso``.
 
+.. _cfi-canonical-jump-tables:
+
+``-fsanitize-cfi-canonical-jump-tables``
+
+
+The default behavior of Clang's indirect function call checker will replace
+the address of each CFI-checked function in the output file's symbol table
+with the address of a jump table entry which will pass CFI checks. We refer
+to this as making the jump table `canonical`. This property allows code that
+was not compiled with ``-fsanitize=cfi-icall`` to take a CFI-valid address
+of a function, but it comes with a couple of caveats that are especially
+relevant for users of cross-DSO CFI:
+
+- There is a performance and code size overhead associated with each
+  exported function, because each such function must have an 

r368102 - hwasan: Instrument globals.

2019-08-06 Thread Peter Collingbourne via cfe-commits
Author: pcc
Date: Tue Aug  6 15:07:29 2019
New Revision: 368102

URL: http://llvm.org/viewvc/llvm-project?rev=368102=rev
Log:
hwasan: Instrument globals.

Globals are instrumented by adding a pointer tag to their symbol values
and emitting metadata into a special section that allows the runtime to tag
their memory when the library is loaded.

Due to order of initialization issues explained in more detail in the comments,
shadow initialization cannot happen during regular global initialization.
Instead, the location of the global section is marked using an ELF note,
and we require libc support for calling a function provided by the HWASAN
runtime when libraries are loaded and unloaded.

Based on ideas discussed with @evgeny777 in D56672.

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

Modified:
cfe/trunk/lib/Driver/SanitizerArgs.cpp
cfe/trunk/test/Driver/fsanitize.c

Modified: cfe/trunk/lib/Driver/SanitizerArgs.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/SanitizerArgs.cpp?rev=368102=368101=368102=diff
==
--- cfe/trunk/lib/Driver/SanitizerArgs.cpp (original)
+++ cfe/trunk/lib/Driver/SanitizerArgs.cpp Tue Aug  6 15:07:29 2019
@@ -1013,6 +1013,11 @@ void SanitizerArgs::addArgs(const ToolCh
 CmdArgs.push_back(Args.MakeArgString("hwasan-abi=" + HwasanAbi));
   }
 
+  if (Sanitizers.has(SanitizerKind::HWAddress)) {
+CmdArgs.push_back("-target-feature");
+CmdArgs.push_back("+tagged-globals");
+  }
+
   // MSan: Workaround for PR16386.
   // ASan: This is mainly to help LSan with cases such as
   // https://github.com/google/sanitizers/issues/373

Modified: cfe/trunk/test/Driver/fsanitize.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/fsanitize.c?rev=368102=368101=368102=diff
==
--- cfe/trunk/test/Driver/fsanitize.c (original)
+++ cfe/trunk/test/Driver/fsanitize.c Tue Aug  6 15:07:29 2019
@@ -843,7 +843,9 @@
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=hwaddress 
-fsanitize-hwaddress-abi=platform %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-HWASAN-PLATFORM-ABI
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=hwaddress 
-fsanitize-hwaddress-abi=foo %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-HWASAN-FOO-ABI
 // CHECK-HWASAN-INTERCEPTOR-ABI: "-default-function-attr" 
"hwasan-abi=interceptor"
+// CHECK-HWASAN-INTERCEPTOR-ABI: "-target-feature" "+tagged-globals"
 // CHECK-HWASAN-PLATFORM-ABI: "-default-function-attr" "hwasan-abi=platform"
+// CHECK-HWASAN-PLATFORM-ABI: "-target-feature" "+tagged-globals"
 // CHECK-HWASAN-FOO-ABI: error: invalid value 'foo' in 
'-fsanitize-hwaddress-abi=foo'
 
 // RUN: %clang -target x86_64-linux-gnu 
-fsanitize=address,pointer-compare,pointer-subtract %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-POINTER-ALL


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


r366379 - hwasan: Initialize the pass only once.

2019-07-17 Thread Peter Collingbourne via cfe-commits
Author: pcc
Date: Wed Jul 17 14:45:19 2019
New Revision: 366379

URL: http://llvm.org/viewvc/llvm-project?rev=366379=rev
Log:
hwasan: Initialize the pass only once.

This will let us instrument globals during initialization. This required
making the new PM pass a module pass, which should still provide access to
analyses via the ModuleAnalysisManager.

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

Modified:
cfe/trunk/lib/CodeGen/BackendUtil.cpp

Modified: cfe/trunk/lib/CodeGen/BackendUtil.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/BackendUtil.cpp?rev=366379=366378=366379=diff
==
--- cfe/trunk/lib/CodeGen/BackendUtil.cpp (original)
+++ cfe/trunk/lib/CodeGen/BackendUtil.cpp Wed Jul 17 14:45:19 2019
@@ -967,17 +967,6 @@ static void addSanitizersAtO0(ModulePass
   if (LangOpts.Sanitize.has(SanitizerKind::Thread)) {
 MPM.addPass(createModuleToFunctionPassAdaptor(ThreadSanitizerPass()));
   }
-
-  if (LangOpts.Sanitize.has(SanitizerKind::HWAddress)) {
-bool Recover = CodeGenOpts.SanitizeRecover.has(SanitizerKind::HWAddress);
-MPM.addPass(createModuleToFunctionPassAdaptor(
-HWAddressSanitizerPass(/*CompileKernel=*/false, Recover)));
-  }
-
-  if (LangOpts.Sanitize.has(SanitizerKind::KernelHWAddress)) {
-MPM.addPass(createModuleToFunctionPassAdaptor(
-HWAddressSanitizerPass(/*CompileKernel=*/true, /*Recover=*/true)));
-  }
 }
 
 /// A clean version of `EmitAssembly` that uses the new pass manager.
@@ -1176,23 +1165,6 @@ void EmitAssemblyHelper::EmitAssemblyWit
   UseOdrIndicator));
 });
   }
-  if (LangOpts.Sanitize.has(SanitizerKind::HWAddress)) {
-bool Recover =
-CodeGenOpts.SanitizeRecover.has(SanitizerKind::HWAddress);
-PB.registerOptimizerLastEPCallback(
-[Recover](FunctionPassManager ,
-  PassBuilder::OptimizationLevel Level) {
-  FPM.addPass(HWAddressSanitizerPass(
-  /*CompileKernel=*/false, Recover));
-});
-  }
-  if (LangOpts.Sanitize.has(SanitizerKind::KernelHWAddress)) {
-PB.registerOptimizerLastEPCallback(
-[](FunctionPassManager , PassBuilder::OptimizationLevel Level) 
{
-  FPM.addPass(HWAddressSanitizerPass(
-  /*CompileKernel=*/true, /*Recover=*/true));
-});
-  }
   if (Optional Options = getGCOVOptions(CodeGenOpts))
 PB.registerPipelineStartEPCallback([Options](ModulePassManager ) {
   MPM.addPass(GCOVProfilerPass(*Options));
@@ -1219,6 +1191,16 @@ void EmitAssemblyHelper::EmitAssemblyWit
   }
 }
 
+if (LangOpts.Sanitize.has(SanitizerKind::HWAddress)) {
+  bool Recover = CodeGenOpts.SanitizeRecover.has(SanitizerKind::HWAddress);
+  MPM.addPass(HWAddressSanitizerPass(
+  /*CompileKernel=*/false, Recover));
+}
+if (LangOpts.Sanitize.has(SanitizerKind::KernelHWAddress)) {
+  MPM.addPass(HWAddressSanitizerPass(
+  /*CompileKernel=*/true, /*Recover=*/true));
+}
+
 if (CodeGenOpts.OptimizationLevel == 0)
   addSanitizersAtO0(MPM, TargetTriple, LangOpts, CodeGenOpts);
   }


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


r365551 - hwasan: Improve precision of checks using short granule tags.

2019-07-09 Thread Peter Collingbourne via cfe-commits
Author: pcc
Date: Tue Jul  9 13:22:36 2019
New Revision: 365551

URL: http://llvm.org/viewvc/llvm-project?rev=365551=rev
Log:
hwasan: Improve precision of checks using short granule tags.

A short granule is a granule of size between 1 and `TG-1` bytes. The size
of a short granule is stored at the location in shadow memory where the
granule's tag is normally stored, while the granule's actual tag is stored
in the last byte of the granule. This means that in order to verify that a
pointer tag matches a memory tag, HWASAN must check for two possibilities:

* the pointer tag is equal to the memory tag in shadow memory, or
* the shadow memory tag is actually a short granule size, the value being loaded
  is in bounds of the granule and the pointer tag is equal to the last byte of
  the granule.

Pointer tags between 1 to `TG-1` are possible and are as likely as any other
tag. This means that these tags in memory have two interpretations: the full
tag interpretation (where the pointer tag is between 1 and `TG-1` and the
last byte of the granule is ordinary data) and the short tag interpretation
(where the pointer tag is stored in the granule).

When HWASAN detects an error near a memory tag between 1 and `TG-1`, it
will show both the memory tag and the last byte of the granule. Currently,
it is up to the user to disambiguate the two possibilities.

Because this functionality obsoletes the right aligned heap feature of
the HWASAN memory allocator (and because we can no longer easily test
it), the feature is removed.

Also update the documentation to cover both short granule tags and
outlined checks.

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

Modified:
cfe/trunk/docs/HardwareAssistedAddressSanitizerDesign.rst

Modified: cfe/trunk/docs/HardwareAssistedAddressSanitizerDesign.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/HardwareAssistedAddressSanitizerDesign.rst?rev=365551=365550=365551=diff
==
--- cfe/trunk/docs/HardwareAssistedAddressSanitizerDesign.rst (original)
+++ cfe/trunk/docs/HardwareAssistedAddressSanitizerDesign.rst Tue Jul  9 
13:22:36 2019
@@ -38,6 +38,30 @@ Algorithm
 
 For a more detailed discussion of this approach see 
https://arxiv.org/pdf/1802.09517.pdf
 
+Short granules
+--
+
+A short granule is a granule of size between 1 and `TG-1` bytes. The size
+of a short granule is stored at the location in shadow memory where the
+granule's tag is normally stored, while the granule's actual tag is stored
+in the last byte of the granule. This means that in order to verify that a
+pointer tag matches a memory tag, HWASAN must check for two possibilities:
+
+* the pointer tag is equal to the memory tag in shadow memory, or
+* the shadow memory tag is actually a short granule size, the value being 
loaded
+  is in bounds of the granule and the pointer tag is equal to the last byte of
+  the granule.
+
+Pointer tags between 1 to `TG-1` are possible and are as likely as any other
+tag. This means that these tags in memory have two interpretations: the full
+tag interpretation (where the pointer tag is between 1 and `TG-1` and the
+last byte of the granule is ordinary data) and the short tag interpretation
+(where the pointer tag is stored in the granule).
+
+When HWASAN detects an error near a memory tag between 1 and `TG-1`, it
+will show both the memory tag and the last byte of the granule. Currently,
+it is up to the user to disambiguate the two possibilities.
+
 Instrumentation
 ===
 
@@ -46,24 +70,40 @@ Memory Accesses
 All memory accesses are prefixed with an inline instruction sequence that
 verifies the tags. Currently, the following sequence is used:
 
-
 .. code-block:: none
 
   // int foo(int *a) { return *a; }
-  // clang -O2 --target=aarch64-linux -fsanitize=hwaddress -c load.c
+  // clang -O2 --target=aarch64-linux -fsanitize=hwaddress 
-fsanitize-recover=hwaddress -c load.c
   foo:
-   0:  08 00 00 90 adrpx8, 0 <__hwasan_shadow>
-   4:  08 01 40 f9 ldr x8, [x8]  // shadow base (to be 
resolved by the loader)
-   8:  09 dc 44 d3 ubfxx9, x0, #4, #52 // shadow offset
-   c:  28 69 68 38 ldrbw8, [x9, x8]// load shadow tag
-  10:  09 fc 78 d3 lsr x9, x0, #56   // extract address tag
-  14:  3f 01 08 6b cmp w9, w8// compare tags
-  18:  61 00 00 54 b.ne24  // jump on mismatch
-  1c:  00 00 40 b9 ldr w0, [x0]  // original load
-  20:  c0 03 5f d6 ret
-  24:  40 20 21 d4 brk #0x902// trap
+   0:  9008adrpx8, 0 <__hwasan_shadow>
+   4:  f9400108ldr x8, [x8] // shadow base (to be 
resolved by the loader)
+   8:  d344dc09ubfxx9, x0, #4, #52  // shadow offset
+   c:  38696909

r362836 - Relax test so that the clang binary doesn't need to be named "clang".

2019-06-07 Thread Peter Collingbourne via cfe-commits
Author: pcc
Date: Fri Jun  7 13:26:47 2019
New Revision: 362836

URL: http://llvm.org/viewvc/llvm-project?rev=362836=rev
Log:
Relax test so that the clang binary doesn't need to be named "clang".

Modified:
cfe/trunk/test/Driver/symbol-partition.c

Modified: cfe/trunk/test/Driver/symbol-partition.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/symbol-partition.c?rev=362836=362835=362836=diff
==
--- cfe/trunk/test/Driver/symbol-partition.c (original)
+++ cfe/trunk/test/Driver/symbol-partition.c Fri Jun  7 13:26:47 2019
@@ -2,4 +2,4 @@
 // RUN: %clang -### -target x86_64-pc-win32 -c -fsymbol-partition=foo %s 2>&1 
| FileCheck --check-prefix=ERROR %s
 
 // CHECK: "-fsymbol-partition=foo"
-// ERROR: clang: error: unsupported option '-fsymbol-partition=foo' for target 
'x86_64-pc-windows-msvc'
+// ERROR: error: unsupported option '-fsymbol-partition=foo' for target 
'x86_64-pc-windows-msvc'


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


r362829 - Driver, IRGen: Set partitions on GlobalValues according to -fsymbol-partition flag.

2019-06-07 Thread Peter Collingbourne via cfe-commits
Author: pcc
Date: Fri Jun  7 12:10:08 2019
New Revision: 362829

URL: http://llvm.org/viewvc/llvm-project?rev=362829=rev
Log:
Driver, IRGen: Set partitions on GlobalValues according to -fsymbol-partition 
flag.

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

Added:
cfe/trunk/test/CodeGenCXX/symbol-partition.cpp
cfe/trunk/test/Driver/symbol-partition.c
Modified:
cfe/trunk/include/clang/Basic/CodeGenOptions.h
cfe/trunk/include/clang/Driver/Options.td
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
cfe/trunk/lib/CodeGen/CodeGenModule.h
cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
cfe/trunk/lib/Driver/ToolChains/Clang.cpp
cfe/trunk/lib/Frontend/CompilerInvocation.cpp

Modified: cfe/trunk/include/clang/Basic/CodeGenOptions.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/CodeGenOptions.h?rev=362829=362828=362829=diff
==
--- cfe/trunk/include/clang/Basic/CodeGenOptions.h (original)
+++ cfe/trunk/include/clang/Basic/CodeGenOptions.h Fri Jun  7 12:10:08 2019
@@ -243,6 +243,10 @@ public:
   /// records.
   std::string OptRecordPasses;
 
+  /// The name of the partition that symbols are assigned to, specified with
+  /// -fsymbol-partition (see https://lld.llvm.org/Partitions.html).
+  std::string SymbolPartition;
+
   /// Regular expression to select optimizations for which we should enable
   /// optimization remarks. Transformation passes whose name matches this
   /// expression (and support this feature), will emit a diagnostic

Modified: cfe/trunk/include/clang/Driver/Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=362829=362828=362829=diff
==
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Fri Jun  7 12:10:08 2019
@@ -935,6 +935,8 @@ def fno_cxx_static_destructors : Flag<["
   Group,
   Flags<[CC1Option]>,
   HelpText<"Disable C++ static destructor registration">;
+def fsymbol_partition_EQ : Joined<["-"], "fsymbol-partition=">, Group,
+  Flags<[CC1Option]>;
 
 // Begin sanitizer flags. These should all be core options exposed in all 
driver
 // modes.

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=362829=362828=362829=diff
==
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Fri Jun  7 12:10:08 2019
@@ -875,19 +875,20 @@ void CodeGenModule::setDLLImportDLLExpor
 void CodeGenModule::setGVProperties(llvm::GlobalValue *GV,
 GlobalDecl GD) const {
   setDLLImportDLLExport(GV, GD);
-  setGlobalVisibilityAndLocal(GV, dyn_cast(GD.getDecl()));
+  setGVPropertiesAux(GV, dyn_cast(GD.getDecl()));
 }
 
 void CodeGenModule::setGVProperties(llvm::GlobalValue *GV,
 const NamedDecl *D) const {
   setDLLImportDLLExport(GV, D);
-  setGlobalVisibilityAndLocal(GV, D);
+  setGVPropertiesAux(GV, D);
 }
 
-void CodeGenModule::setGlobalVisibilityAndLocal(llvm::GlobalValue *GV,
-const NamedDecl *D) const {
+void CodeGenModule::setGVPropertiesAux(llvm::GlobalValue *GV,
+   const NamedDecl *D) const {
   setGlobalVisibility(GV, D);
   setDSOLocal(GV);
+  GV->setPartition(CodeGenOpts.SymbolPartition);
 }
 
 static llvm::GlobalVariable::ThreadLocalMode GetLLVMTLSModel(StringRef S) {

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.h?rev=362829=362828=362829=diff
==
--- cfe/trunk/lib/CodeGen/CodeGenModule.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.h Fri Jun  7 12:10:08 2019
@@ -759,9 +759,6 @@ public:
   /// Set the visibility for the given LLVM GlobalValue.
   void setGlobalVisibility(llvm::GlobalValue *GV, const NamedDecl *D) const;
 
-  void setGlobalVisibilityAndLocal(llvm::GlobalValue *GV,
-   const NamedDecl *D) const;
-
   void setDSOLocal(llvm::GlobalValue *GV) const;
 
   void setDLLImportDLLExport(llvm::GlobalValue *GV, GlobalDecl D) const;
@@ -771,6 +768,8 @@ public:
   void setGVProperties(llvm::GlobalValue *GV, GlobalDecl GD) const;
   void setGVProperties(llvm::GlobalValue *GV, const NamedDecl *D) const;
 
+  void setGVPropertiesAux(llvm::GlobalValue *GV, const NamedDecl *D) const;
+
   /// Set the TLS mode for the given LLVM GlobalValue for the thread-local
   /// variable declaration D.
   void setTLSMode(llvm::GlobalValue *GV, const VarDecl ) const;

Modified: cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
URL: 

[clang-tools-extra] r358549 - clangd: Change Windows.h to windows.h.

2019-04-16 Thread Peter Collingbourne via cfe-commits
Author: pcc
Date: Tue Apr 16 20:02:18 2019
New Revision: 358549

URL: http://llvm.org/viewvc/llvm-project?rev=358549=rev
Log:
clangd: Change Windows.h to windows.h.

This makes the file more cross compilation friendly.

Modified:
clang-tools-extra/trunk/clangd/Threading.cpp

Modified: clang-tools-extra/trunk/clangd/Threading.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Threading.cpp?rev=358549=358548=358549=diff
==
--- clang-tools-extra/trunk/clangd/Threading.cpp (original)
+++ clang-tools-extra/trunk/clangd/Threading.cpp Tue Apr 16 20:02:18 2019
@@ -10,7 +10,7 @@
 #elif defined(__APPLE__)
 #include 
 #elif defined (_WIN32)
-#include 
+#include 
 #endif
 
 namespace clang {


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


r356822 - IRGen: Remove StructorType; thread GlobalDecl through more code. NFCI.

2019-03-22 Thread Peter Collingbourne via cfe-commits
Author: pcc
Date: Fri Mar 22 16:05:10 2019
New Revision: 356822

URL: http://llvm.org/viewvc/llvm-project?rev=356822=rev
Log:
IRGen: Remove StructorType; thread GlobalDecl through more code. NFCI.

This should make it easier to add more structor variants.

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

Modified:
cfe/trunk/include/clang/AST/GlobalDecl.h
cfe/trunk/lib/CodeGen/CGCXX.cpp
cfe/trunk/lib/CodeGen/CGCXXABI.h
cfe/trunk/lib/CodeGen/CGCall.cpp
cfe/trunk/lib/CodeGen/CGClass.cpp
cfe/trunk/lib/CodeGen/CGDeclCXX.cpp
cfe/trunk/lib/CodeGen/CGExpr.cpp
cfe/trunk/lib/CodeGen/CGExprCXX.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.h
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
cfe/trunk/lib/CodeGen/CodeGenModule.h
cfe/trunk/lib/CodeGen/CodeGenTypes.h
cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp

Modified: cfe/trunk/include/clang/AST/GlobalDecl.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/GlobalDecl.h?rev=356822=356821=356822=diff
==
--- cfe/trunk/include/clang/AST/GlobalDecl.h (original)
+++ cfe/trunk/include/clang/AST/GlobalDecl.h Fri Mar 22 16:05:10 2019
@@ -104,6 +104,20 @@ public:
 return Result;
   }
 
+  GlobalDecl getWithCtorType(CXXCtorType Type) {
+assert(isa(getDecl()));
+GlobalDecl Result(*this);
+Result.Value.setInt(Type);
+return Result;
+  }
+
+  GlobalDecl getWithDtorType(CXXDtorType Type) {
+assert(isa(getDecl()));
+GlobalDecl Result(*this);
+Result.Value.setInt(Type);
+return Result;
+  }
+
   GlobalDecl getWithMultiVersionIndex(unsigned Index) {
 assert(isa(getDecl()) &&
!isa(getDecl()) &&

Modified: cfe/trunk/lib/CodeGen/CGCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCXX.cpp?rev=356822=356821=356822=diff
==
--- cfe/trunk/lib/CodeGen/CGCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCXX.cpp Fri Mar 22 16:05:10 2019
@@ -203,50 +203,37 @@ bool CodeGenModule::TryEmitBaseDestructo
   return false;
 }
 
-llvm::Function *CodeGenModule::codegenCXXStructor(const CXXMethodDecl *MD,
-  StructorType Type) {
-  const CGFunctionInfo  =
-  getTypes().arrangeCXXStructorDeclaration(MD, Type);
+llvm::Function *CodeGenModule::codegenCXXStructor(GlobalDecl GD) {
+  const CGFunctionInfo  = getTypes().arrangeCXXStructorDeclaration(GD);
   auto *Fn = cast(
-  getAddrOfCXXStructor(MD, Type, , /*FnType=*/nullptr,
+  getAddrOfCXXStructor(GD, , /*FnType=*/nullptr,
/*DontDefer=*/true, ForDefinition));
 
-  GlobalDecl GD;
-  if (const auto *DD = dyn_cast(MD)) {
-GD = GlobalDecl(DD, toCXXDtorType(Type));
-  } else {
-const auto *CD = cast(MD);
-GD = GlobalDecl(CD, toCXXCtorType(Type));
-  }
-
   setFunctionLinkage(GD, Fn);
 
   CodeGenFunction(*this).GenerateCode(GD, Fn, FnInfo);
   setNonAliasAttributes(GD, Fn);
-  SetLLVMFunctionAttributesForDefinition(MD, Fn);
+  SetLLVMFunctionAttributesForDefinition(cast(GD.getDecl()), 
Fn);
   return Fn;
 }
 
 llvm::FunctionCallee CodeGenModule::getAddrAndTypeOfCXXStructor(
-const CXXMethodDecl *MD, StructorType Type, const CGFunctionInfo *FnInfo,
-llvm::FunctionType *FnType, bool DontDefer,
-ForDefinition_t IsForDefinition) {
-
-  GlobalDecl GD;
-  if (auto *CD = dyn_cast(MD)) {
-GD = GlobalDecl(CD, toCXXCtorType(Type));
-  } else {
+GlobalDecl GD, const CGFunctionInfo *FnInfo, llvm::FunctionType *FnType,
+bool DontDefer, ForDefinition_t IsForDefinition) {
+  auto *MD = cast(GD.getDecl());
+
+  if (auto *DD = dyn_cast(MD)) {
 // Always alias equivalent complete destructors to base destructors in the
 // MS ABI.
 if (getTarget().getCXXABI().isMicrosoft() &&
-Type == StructorType::Complete && MD->getParent()->getNumVBases() == 0)
-  Type = StructorType::Base;
-GD = GlobalDecl(cast(MD), toCXXDtorType(Type));
+GD.getDtorType() == Dtor_Complete &&
+MD->getParent()->getNumVBases() == 0)
+  GD = GD.getWithDtorType(Dtor_Base);
   }
 
   if (!FnType) {
 if (!FnInfo)
-  FnInfo = ().arrangeCXXStructorDeclaration(MD, Type);
+  FnInfo = ().arrangeCXXStructorDeclaration(GD);
 FnType = getTypes().GetFunctionType(*FnInfo);
   }
 
@@ -313,7 +300,7 @@ CodeGenFunction::BuildAppleKextVirtualDe
   assert(DD->isVirtual() && Type != Dtor_Base);
   // Compute the function type we're calling.
   const CGFunctionInfo  = CGM.getTypes().arrangeCXXStructorDeclaration(
-  DD, StructorType::Complete);
+  GlobalDecl(DD, Dtor_Complete));
   llvm::Type *Ty = CGM.getTypes().GetFunctionType(FInfo);
   return ::BuildAppleKextVirtualCall(*this, GlobalDecl(DD, Type), Ty, RD);
 }

Modified: cfe/trunk/lib/CodeGen/CGCXXABI.h
URL: 

r356328 - CodeGen: Preserve packed attribute in constStructWithPadding.

2019-03-16 Thread Peter Collingbourne via cfe-commits
Author: pcc
Date: Sat Mar 16 12:25:39 2019
New Revision: 356328

URL: http://llvm.org/viewvc/llvm-project?rev=356328=rev
Log:
CodeGen: Preserve packed attribute in constStructWithPadding.

Otherwise the object may have an incorrect size due to tail padding.

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

Modified:
cfe/trunk/lib/CodeGen/CGDecl.cpp
cfe/trunk/test/CodeGenCXX/auto-var-init.cpp

Modified: cfe/trunk/lib/CodeGen/CGDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDecl.cpp?rev=356328=356327=356328=diff
==
--- cfe/trunk/lib/CodeGen/CGDecl.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDecl.cpp Sat Mar 16 12:25:39 2019
@@ -1113,7 +1113,7 @@ static llvm::Constant *constStructWithPa
   }
   if (NestedIntact && Values.size() == STy->getNumElements())
 return constant;
-  return llvm::ConstantStruct::getAnon(Values);
+  return llvm::ConstantStruct::getAnon(Values, STy->isPacked());
 }
 
 /// Replace all padding bytes in a given constant with either a pattern byte or

Modified: cfe/trunk/test/CodeGenCXX/auto-var-init.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/auto-var-init.cpp?rev=356328=356327=356328=diff
==
--- cfe/trunk/test/CodeGenCXX/auto-var-init.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/auto-var-init.cpp Sat Mar 16 12:25:39 2019
@@ -85,6 +85,8 @@ struct paddedpacked { char c; int i; } _
 // PATTERN: @__const.test_paddedpackedarray_custom.custom = private 
unnamed_addr constant %struct.paddedpackedarray { [2 x %struct.paddedpacked] 
[%struct.paddedpacked <{ i8 42, i32 13371337 }>, %struct.paddedpacked <{ i8 43, 
i32 13371338 }>] }, align 1
 // ZERO: @__const.test_paddedpackedarray_custom.custom = private unnamed_addr 
constant %struct.paddedpackedarray { [2 x %struct.paddedpacked] 
[%struct.paddedpacked <{ i8 42, i32 13371337 }>, %struct.paddedpacked <{ i8 43, 
i32 13371338 }>] }, align 1
 struct paddedpackedarray { struct paddedpacked p[2]; };
+// PATTERN-O0: @__const.test_unpackedinpacked_uninit.uninit = private 
unnamed_addr constant <{ { i8, [3 x i8], i32 }, i8 }> <{ { i8, [3 x i8], i32 } 
{ i8 -86, [3 x i8] c"\AA\AA\AA", i32 -1431655766 }, i8 -86 }>, align 1
+struct unpackedinpacked { padded a; char b; } __attribute__((packed));
 // PATTERN-O0: @__const.test_paddednested_uninit.uninit = private unnamed_addr 
constant { { i8, [3 x i8], i32 }, { i8, [3 x i8], i32 } } { { i8, [3 x i8], i32 
} { i8 -86, [3 x i8] c"\AA\AA\AA", i32 -1431655766 }, { i8, [3 x i8], i32 } { 
i8 -86, [3 x i8] c"\AA\AA\AA", i32 -1431655766 } }, align 4
 // PATTERN: @__const.test_paddednested_custom.custom = private unnamed_addr 
constant { { i8, [3 x i8], i32 }, { i8, [3 x i8], i32 } } { { i8, [3 x i8], i32 
} { i8 42, [3 x i8] c"\AA\AA\AA", i32 13371337 }, { i8, [3 x i8], i32 } { i8 
43, [3 x i8] c"\AA\AA\AA", i32 13371338 } }, align 4
 // ZERO: @__const.test_paddednested_custom.custom = private unnamed_addr 
constant { { i8, [3 x i8], i32 }, { i8, [3 x i8], i32 } } { { i8, [3 x i8], i32 
} { i8 42, [3 x i8] zeroinitializer, i32 13371337 }, { i8, [3 x i8], i32 } { i8 
43, [3 x i8] zeroinitializer, i32 13371338 } }, align 4
@@ -778,6 +780,10 @@ TEST_CUSTOM(paddedpackedarray, paddedpac
 // CHECK-NEXT:  call void 
@llvm.memcpy{{.*}}({{.*}}@__const.test_paddedpackedarray_custom.custom
 // CHECK-NEXT:  call void @{{.*}}used{{.*}}%custom)
 
+TEST_UNINIT(unpackedinpacked, unpackedinpacked);
+// CHECK-LABEL: @test_unpackedinpacked_uninit()
+// PATTERN-O0:  call void @llvm.memcpy{{.*}}, i64 9, i1 false)
+
 TEST_UNINIT(paddednested, paddednested);
 // CHECK-LABEL: @test_paddednested_uninit()
 // CHECK:   %uninit = alloca %struct.paddednested, align


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


r353890 - docs: Update the ShadowCallStack documentation.

2019-02-12 Thread Peter Collingbourne via cfe-commits
Author: pcc
Date: Tue Feb 12 14:45:23 2019
New Revision: 353890

URL: http://llvm.org/viewvc/llvm-project?rev=353890=rev
Log:
docs: Update the ShadowCallStack documentation.

- Remove most of the discussion of the x86_64 implementation;
  link to an older version of the documentation for details of
  that implementation.
- Add description of the compatibility and security issues discovered
  during the development of the aarch64 implementation for Android.

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

Modified:
cfe/trunk/docs/ShadowCallStack.rst

Modified: cfe/trunk/docs/ShadowCallStack.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ShadowCallStack.rst?rev=353890=353889=353890=diff
==
--- cfe/trunk/docs/ShadowCallStack.rst (original)
+++ cfe/trunk/docs/ShadowCallStack.rst Tue Feb 12 14:45:23 2019
@@ -8,28 +8,45 @@ ShadowCallStack
 Introduction
 
 
-ShadowCallStack is an **experimental** instrumentation pass, currently only
-implemented for x86_64 and aarch64, that protects programs against return
-address overwrites (e.g. stack buffer overflows.) It works by saving a
-function's return address to a separately allocated 'shadow call stack'
-in the function prolog and checking the return address on the stack against
-the shadow call stack in the function epilog.
+ShadowCallStack is an instrumentation pass, currently only implemented for
+aarch64 and x86_64, that protects programs against return address overwrites
+(e.g. stack buffer overflows.) It works by saving a function's return address
+to a separately allocated 'shadow call stack' in the function prolog in
+non-leaf functions and loading the return address from the shadow call stack
+in the function epilog. The return address is also stored on the regular stack
+for compatibility with unwinders, but is otherwise unused.
+
+The aarch64 implementation is considered production ready, and
+an `implementation of the runtime`_ has been added to Android's libc
+(bionic). The x86_64 implementation was evaluated using Chromium and was
+found to have critical performance and security deficiencies, and may be
+removed in a future release of the compiler. This document only describes
+the aarch64 implementation; details on the x86_64 implementation are found
+in the `Clang 7.0.1 documentation`_.
+
+.. _`implementation of the runtime`: 
https://android.googlesource.com/platform/bionic/+/808d176e7e0dd727c7f929622ec017f6e065c582/libc/bionic/pthread_create.cpp#128
+.. _`Clang 7.0.1 documentation`: 
https://releases.llvm.org/7.0.1/tools/clang/docs/ShadowCallStack.html
 
 Comparison
 --
 
-To optimize for memory consumption and cache locality, the shadow call stack
-stores an index followed by an array of return addresses. This is in contrast
-to other schemes, like :doc:`SafeStack`, that mirror the entire stack and
-trade-off consuming more memory for shorter function prologs and epilogs with
-fewer memory accesses. Similarly, `Return Flow Guard`_ consumes more memory 
with
-shorter function prologs and epilogs than ShadowCallStack but suffers from the
-same race conditions (see `Security`_). Intel `Control-flow Enforcement 
Technology`_
-(CET) is a proposed hardware extension that would add native support to
-use a shadow stack to store/check return addresses at call/return time. It
-would not suffer from race conditions at calls and returns and not incur the
-overhead of function instrumentation, but it does require operating system
-support.
+To optimize for memory consumption and cache locality, the shadow call
+stack stores only an array of return addresses. This is in contrast to other
+schemes, like :doc:`SafeStack`, that mirror the entire stack and trade-off
+consuming more memory for shorter function prologs and epilogs with fewer
+memory accesses.
+
+`Return Flow Guard`_ is a pure software implementation of shadow call stacks
+on x86_64. It is similar to the ShadowCallStack x86_64 implementation but
+trades off higher memory usage for a shorter prologue and epilogue. Like
+x86_64 ShadowCallStack, it is inherently racy due to the architecture's use
+of the stack for calls and returns.
+
+Intel `Control-flow Enforcement Technology`_ (CET) is a proposed hardware
+extension that would add native support to use a shadow stack to store/check
+return addresses at call/return time. Being a hardware implementation, it
+would not suffer from race conditions and would not incur the overhead of
+function instrumentation, but it does require operating system support.
 
 .. _`Return Flow Guard`: 
https://xlab.tencent.com/en/2016/11/02/return-flow-guard/
 .. _`Control-flow Enforcement Technology`: 
https://software.intel.com/sites/default/files/managed/4d/2a/control-flow-enforcement-technology-preview.pdf
@@ -37,57 +54,96 @@ support.
 Compatibility
 -
 
-ShadowCallStack currently only supports x86_64 and aarch64. A runtime is not

r351241 - CodeGen: Remove debug printf unintentionally added in r351228.

2019-01-15 Thread Peter Collingbourne via cfe-commits
Author: pcc
Date: Tue Jan 15 12:59:59 2019
New Revision: 351241

URL: http://llvm.org/viewvc/llvm-project?rev=351241=rev
Log:
CodeGen: Remove debug printf unintentionally added in r351228.

Modified:
cfe/trunk/lib/CodeGen/CodeGenModule.cpp

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=351241=351240=351241=diff
==
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Tue Jan 15 12:59:59 2019
@@ -137,12 +137,10 @@ CodeGenModule::CodeGenModule(ASTContext
 
   // Enable TBAA unless it's suppressed. ThreadSanitizer needs TBAA even at O0.
   if (LangOpts.Sanitize.has(SanitizerKind::Thread) ||
-  (!CodeGenOpts.RelaxedAliasing && CodeGenOpts.OptimizationLevel > 0)) {
-fprintf(stderr, "TBAA enabled\n");
+  (!CodeGenOpts.RelaxedAliasing && CodeGenOpts.OptimizationLevel > 0))
 TBAA.reset(new CodeGenTBAA(Context, TheModule, CodeGenOpts, getLangOpts(),
getCXXABI().getMangleContext()));
-  }
-  
+
   // If debug info or coverage generation is enabled, create the CGDebugInfo
   // object.
   if (CodeGenOpts.getDebugInfo() != codegenoptions::NoDebugInfo ||


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


r350433 - Fix default-function-attr.c so that it works on Windows.

2019-01-04 Thread Peter Collingbourne via cfe-commits
Author: pcc
Date: Fri Jan  4 12:51:54 2019
New Revision: 350433

URL: http://llvm.org/viewvc/llvm-project?rev=350433=rev
Log:
Fix default-function-attr.c so that it works on Windows.

Modified:
cfe/trunk/test/CodeGen/default-function-attr.c

Modified: cfe/trunk/test/CodeGen/default-function-attr.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/default-function-attr.c?rev=350433=350432=350433=diff
==
--- cfe/trunk/test/CodeGen/default-function-attr.c (original)
+++ cfe/trunk/test/CodeGen/default-function-attr.c Fri Jan  4 12:51:54 2019
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -default-function-attr foo=bar -emit-llvm %s -o - | 
FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-unknown-linux -default-function-attr foo=bar 
-emit-llvm %s -o - | FileCheck %s
 
 // CHECK: define void @foo() #[[X:[0-9]+]]
 void foo() {}


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


r350429 - hwasan: Implement lazy thread initialization for the interceptor ABI.

2019-01-04 Thread Peter Collingbourne via cfe-commits
Author: pcc
Date: Fri Jan  4 11:27:04 2019
New Revision: 350429

URL: http://llvm.org/viewvc/llvm-project?rev=350429=rev
Log:
hwasan: Implement lazy thread initialization for the interceptor ABI.

The problem is similar to D55986 but for threads: a process with the
interceptor hwasan library loaded might have some threads started by
instrumented libraries and some by uninstrumented libraries, and we
need to be able to run instrumented code on the latter.

The solution is to perform per-thread initialization lazily. If a
function needs to access shadow memory or add itself to the per-thread
ring buffer its prologue checks to see whether the value in the
sanitizer TLS slot is null, and if so it calls __hwasan_thread_enter
and reloads from the TLS slot. The runtime does the same thing if it
needs to access this data structure.

This change means that the code generator needs to know whether we
are targeting the interceptor runtime, since we don't want to pay
the cost of lazy initialization when targeting a platform with native
hwasan support. A flag -fsanitize-hwaddress-abi={interceptor,platform}
has been introduced for selecting the runtime ABI to target. The
default ABI is set to interceptor since it's assumed that it will
be more common that users will be compiling application code than
platform code.

Because we can no longer assume that the TLS slot is initialized,
the pthread_create interceptor is no longer necessary, so it has
been removed.

Ideally, lazy initialization should only cost one instruction in the
hot path, but at present the call may cause us to spill arguments
to the stack, which means more instructions in the hot path (or
theoretically in the cold path if the spills are moved with shrink
wrapping). With an appropriately chosen calling convention for
the per-thread initialization function (TODO) the hot path should
always need just one instruction and the cold path should need two
instructions with no spilling required.

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

Added:
cfe/trunk/test/CodeGen/default-function-attr.c
Modified:
cfe/trunk/include/clang/Basic/CodeGenOptions.h
cfe/trunk/include/clang/Driver/CC1Options.td
cfe/trunk/include/clang/Driver/Options.td
cfe/trunk/include/clang/Driver/SanitizerArgs.h
cfe/trunk/lib/CodeGen/CGCall.cpp
cfe/trunk/lib/Driver/SanitizerArgs.cpp
cfe/trunk/lib/Frontend/CompilerInvocation.cpp
cfe/trunk/test/Driver/fsanitize.c

Modified: cfe/trunk/include/clang/Basic/CodeGenOptions.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/CodeGenOptions.h?rev=350429=350428=350429=diff
==
--- cfe/trunk/include/clang/Basic/CodeGenOptions.h (original)
+++ cfe/trunk/include/clang/Basic/CodeGenOptions.h Fri Jan  4 11:27:04 2019
@@ -286,6 +286,8 @@ public:
   /// Set of XRay instrumentation kinds to emit.
   XRayInstrSet XRayInstrumentationBundle;
 
+  std::vector DefaultFunctionAttrs;
+
 public:
   // Define accessors/mutators for code generation options of enumeration type.
 #define CODEGENOPT(Name, Bits, Default)

Modified: cfe/trunk/include/clang/Driver/CC1Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/CC1Options.td?rev=350429=350428=350429=diff
==
--- cfe/trunk/include/clang/Driver/CC1Options.td (original)
+++ cfe/trunk/include/clang/Driver/CC1Options.td Fri Jan  4 11:27:04 2019
@@ -163,6 +163,8 @@ let Flags = [CC1Option, CC1AsOption, NoD
 def debug_info_kind_EQ : Joined<["-"], "debug-info-kind=">;
 def debug_info_macro : Flag<["-"], "debug-info-macro">,
   HelpText<"Emit macro debug information">;
+def default_function_attr : Separate<["-"], "default-function-attr">,
+  HelpText<"Apply given attribute to all functions">;
 def dwarf_version_EQ : Joined<["-"], "dwarf-version=">;
 def debugger_tuning_EQ : Joined<["-"], "debugger-tuning=">;
 def fdebug_compilation_dir : Separate<["-"], "fdebug-compilation-dir">,

Modified: cfe/trunk/include/clang/Driver/Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=350429=350428=350429=diff
==
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Fri Jan  4 11:27:04 2019
@@ -998,6 +998,10 @@ def fno_sanitize_address_use_odr_indicat
 : Flag<["-"], "fno-sanitize-address-use-odr-indicator">,
   Group,
   HelpText<"Disable ODR indicator globals">;
+def fsanitize_hwaddress_abi_EQ
+: Joined<["-"], "fsanitize-hwaddress-abi=">,
+  Group,
+  HelpText<"Select the HWAddressSanitizer ABI to target (interceptor or 
platform, default interceptor)">;
 def fsanitize_recover : Flag<["-"], "fsanitize-recover">, Group;
 def fno_sanitize_recover : Flag<["-"], "fno-sanitize-recover">,
  

r347282 - Driver: SCS is compatible with every other sanitizer.

2018-11-19 Thread Peter Collingbourne via cfe-commits
Author: pcc
Date: Mon Nov 19 17:01:49 2018
New Revision: 347282

URL: http://llvm.org/viewvc/llvm-project?rev=347282=rev
Log:
Driver: SCS is compatible with every other sanitizer.

Because SCS relies on system-provided runtime support, we can use it
together with any other sanitizer simply by linking the runtime for
the other sanitizer.

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

Modified:
cfe/trunk/lib/Driver/SanitizerArgs.cpp
cfe/trunk/test/Driver/sanitizer-ld.c

Modified: cfe/trunk/lib/Driver/SanitizerArgs.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/SanitizerArgs.cpp?rev=347282=347281=347282=diff
==
--- cfe/trunk/lib/Driver/SanitizerArgs.cpp (original)
+++ cfe/trunk/lib/Driver/SanitizerArgs.cpp Mon Nov 19 17:01:49 2018
@@ -376,12 +376,9 @@ SanitizerArgs::SanitizerArgs(const ToolC
 KernelAddress | Efficiency),
   std::make_pair(SafeStack, Address | HWAddress | Leak | Thread | Memory |
 KernelAddress | Efficiency),
-  std::make_pair(ShadowCallStack, Address | HWAddress | Leak | Thread |
-  Memory | KernelAddress | Efficiency |
-  SafeStack),
   std::make_pair(KernelHWAddress, Address | HWAddress | Leak | Thread |
   Memory | KernelAddress | Efficiency |
-  SafeStack | ShadowCallStack),
+  SafeStack),
   std::make_pair(KernelMemory, Address | HWAddress | Leak | Thread |
Memory | KernelAddress | Efficiency |
Scudo | SafeStack)};

Modified: cfe/trunk/test/Driver/sanitizer-ld.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/sanitizer-ld.c?rev=347282=347281=347282=diff
==
--- cfe/trunk/test/Driver/sanitizer-ld.c (original)
+++ cfe/trunk/test/Driver/sanitizer-ld.c Mon Nov 19 17:01:49 2018
@@ -588,7 +588,7 @@
 // RUN: %clang -fsanitize=shadow-call-stack %s -### -o %t.o 2>&1 \
 // RUN: -fsanitize=safe-stack -target x86_64-unknown-linux -fuse-ld=ld \
 // RUN:   | FileCheck --check-prefix=CHECK-SHADOWCALLSTACK-SAFESTACK %s
-// CHECK-SHADOWCALLSTACK-SAFESTACK: error: invalid argument 
'-fsanitize=shadow-call-stack' not allowed with '-fsanitize=safe-stack'
+// CHECK-SHADOWCALLSTACK-SAFESTACK-NOT: error:
 
 // RUN: %clang -fsanitize=cfi -fsanitize-stats %s -### -o %t.o 2>&1 \
 // RUN: -target x86_64-unknown-linux -fuse-ld=ld \


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


[clang-tools-extra] r346998 - Remove myself as owner of clang-query.

2018-11-15 Thread Peter Collingbourne via cfe-commits
Author: pcc
Date: Thu Nov 15 14:02:10 2018
New Revision: 346998

URL: http://llvm.org/viewvc/llvm-project?rev=346998=rev
Log:
Remove myself as owner of clang-query.

I haven't been involved with the project for years, so it's probably
best for someone else to be the code owner.

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

Modified:
clang-tools-extra/trunk/CODE_OWNERS.TXT

Modified: clang-tools-extra/trunk/CODE_OWNERS.TXT
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/CODE_OWNERS.TXT?rev=346998=346997=346998=diff
==
--- clang-tools-extra/trunk/CODE_OWNERS.TXT (original)
+++ clang-tools-extra/trunk/CODE_OWNERS.TXT Thu Nov 15 14:02:10 2018
@@ -12,10 +12,6 @@ N: Aaron Ballman
 E: aa...@aaronballman.com
 D: clang-query
 
-N: Peter Collingbourne
-E: pe...@pcc.me.uk
-D: clang-query
-
 N: Manuel Klimek
 E: kli...@google.com
 D: clang-rename, all parts of clang-tools-extra not covered by someone else


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


r346526 - Driver: Make -fsanitize=shadow-call-stack compatible with -fsanitize-minimal-runtime.

2018-11-09 Thread Peter Collingbourne via cfe-commits
Author: pcc
Date: Fri Nov  9 09:54:49 2018
New Revision: 346526

URL: http://llvm.org/viewvc/llvm-project?rev=346526=rev
Log:
Driver: Make -fsanitize=shadow-call-stack compatible with 
-fsanitize-minimal-runtime.

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

Modified:
cfe/trunk/lib/Driver/SanitizerArgs.cpp
cfe/trunk/test/Driver/fsanitize.c

Modified: cfe/trunk/lib/Driver/SanitizerArgs.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/SanitizerArgs.cpp?rev=346526=346525=346526=diff
==
--- cfe/trunk/lib/Driver/SanitizerArgs.cpp (original)
+++ cfe/trunk/lib/Driver/SanitizerArgs.cpp Fri Nov  9 09:54:49 2018
@@ -47,7 +47,7 @@ enum : SanitizerMask {
   TrappingDefault = CFI,
   CFIClasses =
   CFIVCall | CFINVCall | CFIMFCall | CFIDerivedCast | CFIUnrelatedCast,
-  CompatibleWithMinimalRuntime = TrappingSupported | Scudo,
+  CompatibleWithMinimalRuntime = TrappingSupported | Scudo | ShadowCallStack,
 };
 
 enum CoverageFeature {

Modified: cfe/trunk/test/Driver/fsanitize.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/fsanitize.c?rev=346526=346525=346526=diff
==
--- cfe/trunk/test/Driver/fsanitize.c (original)
+++ cfe/trunk/test/Driver/fsanitize.c Fri Nov  9 09:54:49 2018
@@ -767,6 +767,10 @@
 // CHECK-CFI-NOICALL-MINIMAL: 
"-fsanitize-trap=cfi-derived-cast,cfi-mfcall,cfi-unrelated-cast,cfi-nvcall,cfi-vcall"
 // CHECK-CFI-NOICALL-MINIMAL: "-fsanitize-minimal-runtime"
 
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=shadow-call-stack 
-fsanitize-minimal-runtime %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-SCS-MINIMAL
+// CHECK-SCS-MINIMAL: "-fsanitize=shadow-call-stack"
+// CHECK-SCS-MINIMAL: "-fsanitize-minimal-runtime"
+
 // RUN: %clang -target aarch64-linux-gnu -fsanitize=scudo %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-SCUDO
 // RUN: %clang -target arm-linux-androideabi -fsanitize=scudo %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-SCUDO
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=scudo %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-SCUDO


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


r341989 - Introduce the VTable interleaving scheme to the CFI design documentation

2018-09-11 Thread Peter Collingbourne via cfe-commits
Author: pcc
Date: Tue Sep 11 13:43:52 2018
New Revision: 341989

URL: http://llvm.org/viewvc/llvm-project?rev=341989=rev
Log:
Introduce the VTable interleaving scheme to the CFI design documentation

Dimitar et. al. in [1] proposed a novel VTable layout scheme that enables 
efficient implementation of virtual call CFI.

This patch adds an introduction of this scheme to the CFI design documentation.

[1] Protecting C++ Dynamic Dispatch Through VTable Interleaving. Dimitar 
Bounov, Rami Gökhan Kıcı, Sorin Lerner. 
https://cseweb.ucsd.edu/~lerner/papers/ivtbl-ndss16.pdf

Patch by Zhaomo Yang!

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

Modified:
cfe/trunk/docs/ControlFlowIntegrityDesign.rst

Modified: cfe/trunk/docs/ControlFlowIntegrityDesign.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ControlFlowIntegrityDesign.rst?rev=341989=341988=341989=diff
==
--- cfe/trunk/docs/ControlFlowIntegrityDesign.rst (original)
+++ cfe/trunk/docs/ControlFlowIntegrityDesign.rst Tue Sep 11 13:43:52 2018
@@ -274,6 +274,154 @@ If the bit vector is all ones, the bit v
 need to check that the address is in range and well aligned. This is more
 likely to occur if the virtual tables are padded.
 
+Forward-Edge CFI for Virtual Calls by Interleaving Virtual Tables
+-
+
+Dimitar et. al. proposed a novel approach that interleaves virtual tables in 
[1]_.  
+This approach is more efficient in terms of space because padding and bit 
vectors are no longer needed. 
+At the same time, it is also more efficient in terms of performance because in 
the interleaved layout 
+address points of the virtual tables are consecutive, thus the validity check 
of a virtual 
+vtable pointer is always a range check. 
+
+At a high level, the interleaving scheme consists of three steps: 1) split 
virtual table groups into 
+separate virtual tables, 2) order virtual tables by a pre-order traversal of 
the class hierarchy 
+and 3) interleave virtual tables.
+
+The interleaving scheme implemented in LLVM is inspired by [1]_ but has its own
+enhancements (more in `Interleave virtual tables`_).
+
+.. [1] `Protecting C++ Dynamic Dispatch Through VTable Interleaving 
`_. Dimitar Bounov, 
Rami Gökhan Kıcı, Sorin Lerner.
+
+Split virtual table groups into separate virtual tables
+~~~
+
+The Itanium C++ ABI glues multiple individual virtual tables for a class into 
a combined virtual table (virtual table group). 
+The interleaving scheme, however, can only work with individual virtual tables 
so it must split the combined virtual tables first.
+In comparison, the old scheme does not require the splitting but it is more 
efficient when the combined virtual tables have been split.
+The `GlobalSplit`_ pass is responsible for splitting combined virtual tables 
into individual ones. 
+
+.. _GlobalSplit: 
https://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/GlobalSplit.cpp?view=markup
+
+Order virtual tables by a pre-order traversal of the class hierarchy 
+
+
+This step is common to both the old scheme described above and the 
interleaving scheme. 
+For the interleaving scheme, since the combined virtual tables have been split 
in the previous step, 
+this step ensures that for any class all the compatible virtual tables will 
appear consecutively. 
+For the old scheme, the same property may not hold since it may work on 
combined virtual tables. 
+
+For example, consider the following four C++ classes:
+
+.. code-block:: c++
+
+  struct A {
+virtual void f1();
+  };
+
+  struct B : A {
+virtual void f1();
+virtual void f2();
+  };
+
+  struct C : A {
+virtual void f1();
+virtual void f3();
+  };
+
+  struct D : B {
+virtual void f1();
+virtual void f2();
+  };
+
+This step will arrange the virtual tables for A, B, C, and D in the order of 
*vtable-of-A, vtable-of-B, vtable-of-D, vtable-of-C*.
+
+Interleave virtual tables
+~
+
+This step is where the interleaving scheme deviates from the old scheme. 
Instead of laying out 
+whole virtual tables in the previously computed order, the interleaving scheme 
lays out table 
+entries of the virtual tables strategically to ensure the following 
properties:  
+
+(1) offset-to-top and RTTI fields layout property
+
+The Itanium C++ ABI specifies that offset-to-top and RTTI fields appear at the 
offsets behind the 
+address point. Note that libraries like libcxxabi do assume this property. 
+
+(2) virtual function entry layout property
+
+For each virtual function the distance between an virtual table entry for this 
function and the corresponding 
+address point is always the same. This property ensures that dynamic dispatch 

r340889 - Start reserving x18 by default on Android targets.

2018-08-28 Thread Peter Collingbourne via cfe-commits
Author: pcc
Date: Tue Aug 28 18:38:47 2018
New Revision: 340889

URL: http://llvm.org/viewvc/llvm-project?rev=340889=rev
Log:
Start reserving x18 by default on Android targets.

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

Modified:
cfe/trunk/test/Driver/sanitizer-ld.c

Modified: cfe/trunk/test/Driver/sanitizer-ld.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/sanitizer-ld.c?rev=340889=340888=340889=diff
==
--- cfe/trunk/test/Driver/sanitizer-ld.c (original)
+++ cfe/trunk/test/Driver/sanitizer-ld.c Tue Aug 28 18:38:47 2018
@@ -575,6 +575,9 @@
 // RUN: %clang -fsanitize=shadow-call-stack %s -### -o %t.o 2>&1 \
 // RUN: -target arm64-unknown-ios -fuse-ld=ld \
 // RUN:   | FileCheck --check-prefix=CHECK-SHADOWCALLSTACK-LINUX-AARCH64-X18 %s
+// RUN: %clang -fsanitize=shadow-call-stack %s -### -o %t.o 2>&1 \
+// RUN: -target aarch64-unknown-linux-android -fuse-ld=ld \
+// RUN:   | FileCheck --check-prefix=CHECK-SHADOWCALLSTACK-LINUX-AARCH64-X18 %s
 // CHECK-SHADOWCALLSTACK-LINUX-AARCH64-X18-NOT: error:
 
 // RUN: %clang -fsanitize=shadow-call-stack %s -### -o %t.o 2>&1 \


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


r340649 - Reland r340552, "Driver: Enable address-significance tables by default when targeting COFF." which was reverted in r340579.

2018-08-24 Thread Peter Collingbourne via cfe-commits
Author: pcc
Date: Fri Aug 24 13:38:15 2018
New Revision: 340649

URL: http://llvm.org/viewvc/llvm-project?rev=340649=rev
Log:
Reland r340552, "Driver: Enable address-significance tables by default when 
targeting COFF." which was reverted in r340579.

The underlying problem that caused the revert was fixed in r340648.

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

Modified:
cfe/trunk/lib/Driver/ToolChains/Clang.cpp
cfe/trunk/test/Driver/addrsig.c

Modified: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Clang.cpp?rev=340649=340648=340649=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp Fri Aug 24 13:38:15 2018
@@ -4857,7 +4857,8 @@ void Clang::ConstructJob(Compilation ,
   }
 
   if (Args.hasFlag(options::OPT_faddrsig, options::OPT_fno_addrsig,
-   getToolChain().getTriple().isOSBinFormatELF() &&
+   (getToolChain().getTriple().isOSBinFormatELF() ||
+getToolChain().getTriple().isOSBinFormatCOFF()) &&
getToolChain().useIntegratedAs()))
 CmdArgs.push_back("-faddrsig");
 

Modified: cfe/trunk/test/Driver/addrsig.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/addrsig.c?rev=340649=340648=340649=diff
==
--- cfe/trunk/test/Driver/addrsig.c (original)
+++ cfe/trunk/test/Driver/addrsig.c Fri Aug 24 13:38:15 2018
@@ -1,4 +1,5 @@
 // RUN: %clang -### -target x86_64-unknown-linux -c %s 2>&1 | FileCheck 
-check-prefix=ADDRSIG %s
+// RUN: %clang -### -target x86_64-pc-win32 -c %s 2>&1 | FileCheck 
-check-prefix=ADDRSIG %s
 // RUN: %clang -### -target x86_64-unknown-linux -fno-integrated-as -c %s 2>&1 
| FileCheck -check-prefix=NO-ADDRSIG %s
 // RUN: %clang -### -target x86_64-unknown-linux -fno-integrated-as -faddrsig 
-c %s 2>&1 | FileCheck -check-prefix=ADDRSIG %s
 // RUN: %clang -### -target x86_64-unknown-linux -fno-addrsig -c %s 2>&1 | 
FileCheck -check-prefix=NO-ADDRSIG %s


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


r340579 - Revert r340552, "Driver: Enable address-significance tables by default when targeting COFF."

2018-08-23 Thread Peter Collingbourne via cfe-commits
Author: pcc
Date: Thu Aug 23 14:34:57 2018
New Revision: 340579

URL: http://llvm.org/viewvc/llvm-project?rev=340579=rev
Log:
Revert r340552, "Driver: Enable address-significance tables by default when 
targeting COFF."

Received multiple reports of breakage due to undefined symbols
suspected to be caused by this change.

Modified:
cfe/trunk/lib/Driver/ToolChains/Clang.cpp
cfe/trunk/test/Driver/addrsig.c

Modified: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Clang.cpp?rev=340579=340578=340579=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp Thu Aug 23 14:34:57 2018
@@ -4857,8 +4857,7 @@ void Clang::ConstructJob(Compilation ,
   }
 
   if (Args.hasFlag(options::OPT_faddrsig, options::OPT_fno_addrsig,
-   (getToolChain().getTriple().isOSBinFormatELF() ||
-getToolChain().getTriple().isOSBinFormatCOFF()) &&
+   getToolChain().getTriple().isOSBinFormatELF() &&
getToolChain().useIntegratedAs()))
 CmdArgs.push_back("-faddrsig");
 

Modified: cfe/trunk/test/Driver/addrsig.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/addrsig.c?rev=340579=340578=340579=diff
==
--- cfe/trunk/test/Driver/addrsig.c (original)
+++ cfe/trunk/test/Driver/addrsig.c Thu Aug 23 14:34:57 2018
@@ -1,5 +1,4 @@
 // RUN: %clang -### -target x86_64-unknown-linux -c %s 2>&1 | FileCheck 
-check-prefix=ADDRSIG %s
-// RUN: %clang -### -target x86_64-pc-win32 -c %s 2>&1 | FileCheck 
-check-prefix=ADDRSIG %s
 // RUN: %clang -### -target x86_64-unknown-linux -fno-integrated-as -c %s 2>&1 
| FileCheck -check-prefix=NO-ADDRSIG %s
 // RUN: %clang -### -target x86_64-unknown-linux -fno-integrated-as -faddrsig 
-c %s 2>&1 | FileCheck -check-prefix=ADDRSIG %s
 // RUN: %clang -### -target x86_64-unknown-linux -fno-addrsig -c %s 2>&1 | 
FileCheck -check-prefix=NO-ADDRSIG %s


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


r340552 - Driver: Enable address-significance tables by default when targeting COFF.

2018-08-23 Thread Peter Collingbourne via cfe-commits
Author: pcc
Date: Thu Aug 23 10:43:29 2018
New Revision: 340552

URL: http://llvm.org/viewvc/llvm-project?rev=340552=rev
Log:
Driver: Enable address-significance tables by default when targeting COFF.

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

Modified:
cfe/trunk/lib/Driver/ToolChains/Clang.cpp
cfe/trunk/test/Driver/addrsig.c

Modified: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Clang.cpp?rev=340552=340551=340552=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp Thu Aug 23 10:43:29 2018
@@ -4857,7 +4857,8 @@ void Clang::ConstructJob(Compilation ,
   }
 
   if (Args.hasFlag(options::OPT_faddrsig, options::OPT_fno_addrsig,
-   getToolChain().getTriple().isOSBinFormatELF() &&
+   (getToolChain().getTriple().isOSBinFormatELF() ||
+getToolChain().getTriple().isOSBinFormatCOFF()) &&
getToolChain().useIntegratedAs()))
 CmdArgs.push_back("-faddrsig");
 

Modified: cfe/trunk/test/Driver/addrsig.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/addrsig.c?rev=340552=340551=340552=diff
==
--- cfe/trunk/test/Driver/addrsig.c (original)
+++ cfe/trunk/test/Driver/addrsig.c Thu Aug 23 10:43:29 2018
@@ -1,4 +1,5 @@
 // RUN: %clang -### -target x86_64-unknown-linux -c %s 2>&1 | FileCheck 
-check-prefix=ADDRSIG %s
+// RUN: %clang -### -target x86_64-pc-win32 -c %s 2>&1 | FileCheck 
-check-prefix=ADDRSIG %s
 // RUN: %clang -### -target x86_64-unknown-linux -fno-integrated-as -c %s 2>&1 
| FileCheck -check-prefix=NO-ADDRSIG %s
 // RUN: %clang -### -target x86_64-unknown-linux -fno-integrated-as -faddrsig 
-c %s 2>&1 | FileCheck -check-prefix=ADDRSIG %s
 // RUN: %clang -### -target x86_64-unknown-linux -fno-addrsig -c %s 2>&1 | 
FileCheck -check-prefix=NO-ADDRSIG %s


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


[libcxx] r339797 - libcxx: Mark __temp_value::__temp_value as _LIBCPP_NO_CFI.

2018-08-15 Thread Peter Collingbourne via cfe-commits
Author: pcc
Date: Wed Aug 15 10:49:30 2018
New Revision: 339797

URL: http://llvm.org/viewvc/llvm-project?rev=339797=rev
Log:
libcxx: Mark __temp_value::__temp_value as _LIBCPP_NO_CFI.

This constructor needs to cast a pointer to uninitialized
memory to a pointer to object type in order to call
allocator_traits::construct(). This cast is not allowed when CFI cast
checks are enabled.

I did this instead of marking __addr() as _LIBCPP_NO_CFI so that we
don't lose CFI checks on get() or the dtor.

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

Modified:
libcxx/trunk/include/memory

Modified: libcxx/trunk/include/memory
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/memory?rev=339797=339796=339797=diff
==
--- libcxx/trunk/include/memory (original)
+++ libcxx/trunk/include/memory Wed Aug 15 10:49:30 2018
@@ -5631,8 +5631,11 @@ struct __temp_value {
 _Tp &   get() { return *__addr(); }
 
 template
-__temp_value(_Alloc &__alloc, _Args&& ... __args) : __a(__alloc)
-{ _Traits::construct(__a, __addr(), _VSTD::forward<_Args>(__args)...); }
+_LIBCPP_NO_CFI
+__temp_value(_Alloc &__alloc, _Args&& ... __args) : __a(__alloc) {
+  _Traits::construct(__a, reinterpret_cast<_Tp*>(addressof(__v)),
+ _VSTD::forward<_Args>(__args)...);
+}
 
 ~__temp_value() { _Traits::destroy(__a, __addr()); }
 };


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


r337339 - Re-land r337333, "Teach Clang to emit address-significance tables.",

2018-07-17 Thread Peter Collingbourne via cfe-commits
Author: pcc
Date: Tue Jul 17 17:27:07 2018
New Revision: 337339

URL: http://llvm.org/viewvc/llvm-project?rev=337339=rev
Log:
Re-land r337333, "Teach Clang to emit address-significance tables.",
which was reverted in r337336.

The problem that required a revert was fixed in r337338.

Also added a missing "REQUIRES: x86-registered-target" to one of
the tests.

Original commit message:
> Teach Clang to emit address-significance tables.
>
> By default, we emit an address-significance table on all ELF
> targets when the integrated assembler is enabled. The emission of an
> address-significance table can be controlled with the -faddrsig and
> -fno-addrsig flags.
>
> Differential Revision: https://reviews.llvm.org/D48155

Added:
cfe/trunk/test/CodeGen/addrsig.c
cfe/trunk/test/Driver/addrsig.c
Modified:
cfe/trunk/docs/ReleaseNotes.rst
cfe/trunk/docs/UsersManual.rst
cfe/trunk/include/clang/Driver/Options.td
cfe/trunk/include/clang/Frontend/CodeGenOptions.def
cfe/trunk/lib/CodeGen/BackendUtil.cpp
cfe/trunk/lib/Driver/ToolChains/Clang.cpp
cfe/trunk/lib/Frontend/CompilerInvocation.cpp

Modified: cfe/trunk/docs/ReleaseNotes.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ReleaseNotes.rst?rev=337339=337338=337339=diff
==
--- cfe/trunk/docs/ReleaseNotes.rst (original)
+++ cfe/trunk/docs/ReleaseNotes.rst Tue Jul 17 17:27:07 2018
@@ -98,6 +98,14 @@ Non-comprehensive list of changes in thi
   finding out the warning hierarchy, and which of them are enabled by default
   or for a particular compiler invocation.
 
+- By default, Clang emits an address-significance table into
+  every ELF object file when using the integrated assembler.
+  Address-significance tables allow linkers to implement `safe ICF
+  `_ without the false
+  positives that can result from other implementation techniques such as
+  relocation scanning. The ``-faddrsig`` and ``-fno-addrsig`` flags can be
+  used to control whether to emit the address-significance table.
+
 - ...
 
 New Compiler Flags

Modified: cfe/trunk/docs/UsersManual.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/UsersManual.rst?rev=337339=337338=337339=diff
==
--- cfe/trunk/docs/UsersManual.rst (original)
+++ cfe/trunk/docs/UsersManual.rst Tue Jul 17 17:27:07 2018
@@ -1382,6 +1382,15 @@ are listed below.
 // value of -fmax-type-align.
   }
 
+.. option:: -faddrsig, -fno-addrsig
+
+   Controls whether Clang emits an address-significance table into the object
+   file. Address-significance tables allow linkers to implement `safe ICF
+   `_ without the false
+   positives that can result from other implementation techniques such as
+   relocation scanning. Address-significance tables are enabled by default
+   on ELF targets when using the integrated assembler. This flag currently
+   only has an effect on ELF targets.
 
 Profile Guided Optimization
 ---

Modified: cfe/trunk/include/clang/Driver/Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=337339=337338=337339=diff
==
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Tue Jul 17 17:27:07 2018
@@ -758,6 +758,10 @@ def fno_profile_instr_use : Flag<["-"],
 def fno_profile_use : Flag<["-"], "fno-profile-use">,
 Alias;
 
+def faddrsig : Flag<["-"], "faddrsig">, Group, Flags<[CoreOption, 
CC1Option]>,
+  HelpText<"Emit an address-significance table">;
+def fno_addrsig : Flag<["-"], "fno-addrsig">, Group, 
Flags<[CoreOption]>,
+  HelpText<"Don't emit an address-significance table">;
 def fblocks : Flag<["-"], "fblocks">, Group, Flags<[CC1Option]>,
   HelpText<"Enable the 'blocks' language feature">;
 def fbootclasspath_EQ : Joined<["-"], "fbootclasspath=">, Group;

Modified: cfe/trunk/include/clang/Frontend/CodeGenOptions.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/CodeGenOptions.def?rev=337339=337338=337339=diff
==
--- cfe/trunk/include/clang/Frontend/CodeGenOptions.def (original)
+++ cfe/trunk/include/clang/Frontend/CodeGenOptions.def Tue Jul 17 17:27:07 2018
@@ -335,6 +335,9 @@ CODEGENOPT(EmbedSource, 1, 0)
 /// Whether to emit all vtables
 CODEGENOPT(ForceEmitVTables, 1, 0)
 
+/// Whether to emit an address-significance table into the object file.
+CODEGENOPT(Addrsig, 1, 0)
+
 
 #undef CODEGENOPT
 #undef ENUM_CODEGENOPT

Modified: cfe/trunk/lib/CodeGen/BackendUtil.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/BackendUtil.cpp?rev=337339=337338=337339=diff

r337336 - Revert r337333, "Teach Clang to emit address-significance tables."

2018-07-17 Thread Peter Collingbourne via cfe-commits
Author: pcc
Date: Tue Jul 17 16:56:30 2018
New Revision: 337336

URL: http://llvm.org/viewvc/llvm-project?rev=337336=rev
Log:
Revert r337333, "Teach Clang to emit address-significance tables."

Causing multiple failures on sanitizer bots due to TLS symbol errors,
e.g.

/usr/bin/ld: __msan_origin_tls: TLS definition in 
/home/buildbots/ppc64be-clang-test/clang-ppc64be/stage1/lib/clang/7.0.0/lib/linux/libclang_rt.msan-powerpc64.a(msan.cc.o)
 section .tbss.__msan_origin_tls mismatches non-TLS reference in 
/tmp/lit_tmp_0a71tA/mallinfo-3ca75e.o

Removed:
cfe/trunk/test/CodeGen/addrsig.c
cfe/trunk/test/Driver/addrsig.c
Modified:
cfe/trunk/docs/ReleaseNotes.rst
cfe/trunk/docs/UsersManual.rst
cfe/trunk/include/clang/Driver/Options.td
cfe/trunk/include/clang/Frontend/CodeGenOptions.def
cfe/trunk/lib/CodeGen/BackendUtil.cpp
cfe/trunk/lib/Driver/ToolChains/Clang.cpp
cfe/trunk/lib/Frontend/CompilerInvocation.cpp

Modified: cfe/trunk/docs/ReleaseNotes.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ReleaseNotes.rst?rev=337336=337335=337336=diff
==
--- cfe/trunk/docs/ReleaseNotes.rst (original)
+++ cfe/trunk/docs/ReleaseNotes.rst Tue Jul 17 16:56:30 2018
@@ -98,14 +98,6 @@ Non-comprehensive list of changes in thi
   finding out the warning hierarchy, and which of them are enabled by default
   or for a particular compiler invocation.
 
-- By default, Clang emits an address-significance table into
-  every ELF object file when using the integrated assembler.
-  Address-significance tables allow linkers to implement `safe ICF
-  `_ without the false
-  positives that can result from other implementation techniques such as
-  relocation scanning. The ``-faddrsig`` and ``-fno-addrsig`` flags can be
-  used to control whether to emit the address-significance table.
-
 - ...
 
 New Compiler Flags

Modified: cfe/trunk/docs/UsersManual.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/UsersManual.rst?rev=337336=337335=337336=diff
==
--- cfe/trunk/docs/UsersManual.rst (original)
+++ cfe/trunk/docs/UsersManual.rst Tue Jul 17 16:56:30 2018
@@ -1382,15 +1382,6 @@ are listed below.
 // value of -fmax-type-align.
   }
 
-.. option:: -faddrsig, -fno-addrsig
-
-   Controls whether Clang emits an address-significance table into the object
-   file. Address-significance tables allow linkers to implement `safe ICF
-   `_ without the false
-   positives that can result from other implementation techniques such as
-   relocation scanning. Address-significance tables are enabled by default
-   on ELF targets when using the integrated assembler. This flag currently
-   only has an effect on ELF targets.
 
 Profile Guided Optimization
 ---

Modified: cfe/trunk/include/clang/Driver/Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=337336=337335=337336=diff
==
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Tue Jul 17 16:56:30 2018
@@ -758,10 +758,6 @@ def fno_profile_instr_use : Flag<["-"],
 def fno_profile_use : Flag<["-"], "fno-profile-use">,
 Alias;
 
-def faddrsig : Flag<["-"], "faddrsig">, Group, Flags<[CoreOption, 
CC1Option]>,
-  HelpText<"Emit an address-significance table">;
-def fno_addrsig : Flag<["-"], "fno-addrsig">, Group, 
Flags<[CoreOption]>,
-  HelpText<"Don't emit an address-significance table">;
 def fblocks : Flag<["-"], "fblocks">, Group, Flags<[CC1Option]>,
   HelpText<"Enable the 'blocks' language feature">;
 def fbootclasspath_EQ : Joined<["-"], "fbootclasspath=">, Group;

Modified: cfe/trunk/include/clang/Frontend/CodeGenOptions.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/CodeGenOptions.def?rev=337336=337335=337336=diff
==
--- cfe/trunk/include/clang/Frontend/CodeGenOptions.def (original)
+++ cfe/trunk/include/clang/Frontend/CodeGenOptions.def Tue Jul 17 16:56:30 2018
@@ -335,9 +335,6 @@ CODEGENOPT(EmbedSource, 1, 0)
 /// Whether to emit all vtables
 CODEGENOPT(ForceEmitVTables, 1, 0)
 
-/// Whether to emit an address-significance table into the object file.
-CODEGENOPT(Addrsig, 1, 0)
-
 
 #undef CODEGENOPT
 #undef ENUM_CODEGENOPT

Modified: cfe/trunk/lib/CodeGen/BackendUtil.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/BackendUtil.cpp?rev=337336=337335=337336=diff
==
--- cfe/trunk/lib/CodeGen/BackendUtil.cpp (original)
+++ cfe/trunk/lib/CodeGen/BackendUtil.cpp Tue Jul 17 16:56:30 2018

r337333 - Teach Clang to emit address-significance tables.

2018-07-17 Thread Peter Collingbourne via cfe-commits
Author: pcc
Date: Tue Jul 17 16:17:16 2018
New Revision: 337333

URL: http://llvm.org/viewvc/llvm-project?rev=337333=rev
Log:
Teach Clang to emit address-significance tables.

By default, we emit an address-significance table on all ELF
targets when the integrated assembler is enabled. The emission of an
address-significance table can be controlled with the -faddrsig and
-fno-addrsig flags.

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

Added:
cfe/trunk/test/CodeGen/addrsig.c
cfe/trunk/test/Driver/addrsig.c
Modified:
cfe/trunk/docs/ReleaseNotes.rst
cfe/trunk/docs/UsersManual.rst
cfe/trunk/include/clang/Driver/Options.td
cfe/trunk/include/clang/Frontend/CodeGenOptions.def
cfe/trunk/lib/CodeGen/BackendUtil.cpp
cfe/trunk/lib/Driver/ToolChains/Clang.cpp
cfe/trunk/lib/Frontend/CompilerInvocation.cpp

Modified: cfe/trunk/docs/ReleaseNotes.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ReleaseNotes.rst?rev=337333=337332=337333=diff
==
--- cfe/trunk/docs/ReleaseNotes.rst (original)
+++ cfe/trunk/docs/ReleaseNotes.rst Tue Jul 17 16:17:16 2018
@@ -98,6 +98,14 @@ Non-comprehensive list of changes in thi
   finding out the warning hierarchy, and which of them are enabled by default
   or for a particular compiler invocation.
 
+- By default, Clang emits an address-significance table into
+  every ELF object file when using the integrated assembler.
+  Address-significance tables allow linkers to implement `safe ICF
+  `_ without the false
+  positives that can result from other implementation techniques such as
+  relocation scanning. The ``-faddrsig`` and ``-fno-addrsig`` flags can be
+  used to control whether to emit the address-significance table.
+
 - ...
 
 New Compiler Flags

Modified: cfe/trunk/docs/UsersManual.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/UsersManual.rst?rev=337333=337332=337333=diff
==
--- cfe/trunk/docs/UsersManual.rst (original)
+++ cfe/trunk/docs/UsersManual.rst Tue Jul 17 16:17:16 2018
@@ -1382,6 +1382,15 @@ are listed below.
 // value of -fmax-type-align.
   }
 
+.. option:: -faddrsig, -fno-addrsig
+
+   Controls whether Clang emits an address-significance table into the object
+   file. Address-significance tables allow linkers to implement `safe ICF
+   `_ without the false
+   positives that can result from other implementation techniques such as
+   relocation scanning. Address-significance tables are enabled by default
+   on ELF targets when using the integrated assembler. This flag currently
+   only has an effect on ELF targets.
 
 Profile Guided Optimization
 ---

Modified: cfe/trunk/include/clang/Driver/Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=337333=337332=337333=diff
==
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Tue Jul 17 16:17:16 2018
@@ -758,6 +758,10 @@ def fno_profile_instr_use : Flag<["-"],
 def fno_profile_use : Flag<["-"], "fno-profile-use">,
 Alias;
 
+def faddrsig : Flag<["-"], "faddrsig">, Group, Flags<[CoreOption, 
CC1Option]>,
+  HelpText<"Emit an address-significance table">;
+def fno_addrsig : Flag<["-"], "fno-addrsig">, Group, 
Flags<[CoreOption]>,
+  HelpText<"Don't emit an address-significance table">;
 def fblocks : Flag<["-"], "fblocks">, Group, Flags<[CC1Option]>,
   HelpText<"Enable the 'blocks' language feature">;
 def fbootclasspath_EQ : Joined<["-"], "fbootclasspath=">, Group;

Modified: cfe/trunk/include/clang/Frontend/CodeGenOptions.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/CodeGenOptions.def?rev=337333=337332=337333=diff
==
--- cfe/trunk/include/clang/Frontend/CodeGenOptions.def (original)
+++ cfe/trunk/include/clang/Frontend/CodeGenOptions.def Tue Jul 17 16:17:16 2018
@@ -335,6 +335,9 @@ CODEGENOPT(EmbedSource, 1, 0)
 /// Whether to emit all vtables
 CODEGENOPT(ForceEmitVTables, 1, 0)
 
+/// Whether to emit an address-significance table into the object file.
+CODEGENOPT(Addrsig, 1, 0)
+
 
 #undef CODEGENOPT
 #undef ENUM_CODEGENOPT

Modified: cfe/trunk/lib/CodeGen/BackendUtil.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/BackendUtil.cpp?rev=337333=337332=337333=diff
==
--- cfe/trunk/lib/CodeGen/BackendUtil.cpp (original)
+++ cfe/trunk/lib/CodeGen/BackendUtil.cpp Tue Jul 17 16:17:16 2018
@@ -454,6 +454,7 @@ static void initTargetOptions(llvm::Targ
   Options.ExplicitEmulatedTLS = 

r335636 - Compile CodeGenModule.cpp with /bigobj.

2018-06-26 Thread Peter Collingbourne via cfe-commits
Author: pcc
Date: Tue Jun 26 10:45:26 2018
New Revision: 335636

URL: http://llvm.org/viewvc/llvm-project?rev=335636=rev
Log:
Compile CodeGenModule.cpp with /bigobj.

Apparently we're now hitting an object file section limit on this
file with expensive checks enabled.

Modified:
cfe/trunk/lib/CodeGen/CMakeLists.txt

Modified: cfe/trunk/lib/CodeGen/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CMakeLists.txt?rev=335636=335635=335636=diff
==
--- cfe/trunk/lib/CodeGen/CMakeLists.txt (original)
+++ cfe/trunk/lib/CodeGen/CMakeLists.txt Tue Jun 26 10:45:26 2018
@@ -32,6 +32,10 @@ if (CLANG_BUILT_STANDALONE)
   set(codegen_deps)
 endif()
 
+if (MSVC)
+  set_source_files_properties(CodeGenModule.cpp PROPERTIES COMPILE_FLAGS 
/bigobj)
+endif()
+
 add_clang_library(clangCodeGen
   BackendUtil.cpp
   CGAtomic.cpp


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


r335569 - Implement CFI for indirect calls via a member function pointer.

2018-06-25 Thread Peter Collingbourne via cfe-commits
Author: pcc
Date: Mon Jun 25 19:15:47 2018
New Revision: 335569

URL: http://llvm.org/viewvc/llvm-project?rev=335569=rev
Log:
Implement CFI for indirect calls via a member function pointer.

Similarly to CFI on virtual and indirect calls, this implementation
tries to use program type information to make the checks as precise
as possible.  The basic way that it works is as follows, where `C`
is the name of the class being defined or the target of a call and
the function type is assumed to be `void()`.

For virtual calls:
- Attach type metadata to the addresses of function pointers in vtables
  (not the functions themselves) of type `void (B::*)()` for each `B`
  that is a recursive dynamic base class of `C`, including `C` itself.
  This type metadata has an annotation that the type is for virtual
  calls (to distinguish it from the non-virtual case).
- At the call site, check that the computed address of the function
  pointer in the vtable has type `void (C::*)()`.

For non-virtual calls:
- Attach type metadata to each non-virtual member function whose address
  can be taken with a member function pointer. The type of a function
  in class `C` of type `void()` is each of the types `void (B::*)()`
  where `B` is a most-base class of `C`. A most-base class of `C`
  is defined as a recursive base class of `C`, including `C` itself,
  that does not have any bases.
- At the call site, check that the function pointer has one of the types
  `void (B::*)()` where `B` is a most-base class of `C`.

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

Added:
cfe/trunk/test/CodeGenCXX/cfi-mfcall-incomplete.cpp
cfe/trunk/test/CodeGenCXX/cfi-mfcall.cpp
cfe/trunk/test/CodeGenCXX/type-metadata-memfun.cpp
Modified:
cfe/trunk/docs/ControlFlowIntegrity.rst
cfe/trunk/docs/LTOVisibility.rst
cfe/trunk/include/clang/Basic/Sanitizers.def
cfe/trunk/lib/CodeGen/CGClass.cpp
cfe/trunk/lib/CodeGen/CGVTables.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.h
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
cfe/trunk/lib/CodeGen/CodeGenModule.h
cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
cfe/trunk/lib/Driver/SanitizerArgs.cpp
cfe/trunk/lib/Driver/ToolChains/MSVC.cpp
cfe/trunk/test/CodeGenCXX/type-metadata.cpp
cfe/trunk/test/Driver/fsanitize.c

Modified: cfe/trunk/docs/ControlFlowIntegrity.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ControlFlowIntegrity.rst?rev=335569=335568=335569=diff
==
--- cfe/trunk/docs/ControlFlowIntegrity.rst (original)
+++ cfe/trunk/docs/ControlFlowIntegrity.rst Mon Jun 25 19:15:47 2018
@@ -66,6 +66,8 @@ Available schemes are:
  wrong dynamic type.
   -  ``-fsanitize=cfi-icall``: Indirect call of a function with wrong dynamic
  type.
+  -  ``-fsanitize=cfi-mfcall``: Indirect call via a member function pointer 
with
+ wrong dynamic type.
 
 You can use ``-fsanitize=cfi`` to enable all the schemes and use
 ``-fno-sanitize`` flag to narrow down the set of schemes as desired.
@@ -255,6 +257,34 @@ the identity of function pointers is mai
 library boundaries are no different from calls within a single program or
 shared library.
 
+Member Function Pointer Call Checking
+=
+
+This scheme checks that indirect calls via a member function pointer
+take place using an object of the correct dynamic type. Specifically, we
+check that the dynamic type of the member function referenced by the member
+function pointer matches the "function pointer" part of the member function
+pointer, and that the member function's class type is related to the base
+type of the member function. This CFI scheme can be enabled on its own using
+``-fsanitize=cfi-mfcall``.
+
+The compiler will only emit a full CFI check if the member function pointer's
+base type is complete. This is because the complete definition of the base
+type contains information that is necessary to correctly compile the CFI
+check. To ensure that the compiler always emits a full CFI check, it is
+recommended to also pass the flag ``-fcomplete-member-pointers``, which
+enables a non-conforming language extension that requires member pointer
+base types to be complete if they may be used for a call.
+
+For this scheme to work, all translation units containing the definition
+of a virtual member function (whether inline or not), other than members
+of :ref:`blacklisted ` types or types with public :doc:`LTO
+visibility `, must be compiled with ``-flto`` or ``-flto=thin``
+enabled and be statically linked into the program.
+
+This scheme is currently not compatible with cross-DSO CFI or the
+Microsoft ABI.
+
 .. _cfi-blacklist:
 
 Blacklist

Modified: cfe/trunk/docs/LTOVisibility.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/LTOVisibility.rst?rev=335569=335568=335569=diff
==
--- 

r334982 - IRgen: Mark aliases of ctors and dtors as unnamed_addr.

2018-06-18 Thread Peter Collingbourne via cfe-commits
Author: pcc
Date: Mon Jun 18 13:58:54 2018
New Revision: 334982

URL: http://llvm.org/viewvc/llvm-project?rev=334982=rev
Log:
IRgen: Mark aliases of ctors and dtors as unnamed_addr.

This is not only semantically correct but ensures that they will not
be marked as address-significant once D48155 lands.

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

Modified:
cfe/trunk/lib/CodeGen/CGCXX.cpp
cfe/trunk/lib/CodeGen/CodeGenModule.h
cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
cfe/trunk/test/CodeGenCXX/constructor-alias.cpp
cfe/trunk/test/CodeGenCXX/ctor-dtor-alias.cpp
cfe/trunk/test/CodeGenCXX/destructors.cpp
cfe/trunk/test/CodeGenCXX/dllexport-alias.cpp
cfe/trunk/test/CodeGenCXX/dllexport.cpp
cfe/trunk/test/CodeGenCXX/microsoft-abi-structors-alias.cpp
cfe/trunk/test/CodeGenCXX/virtual-bases.cpp
cfe/trunk/test/CodeGenCXX/virtual-destructor-calls.cpp

Modified: cfe/trunk/lib/CodeGen/CGCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCXX.cpp?rev=334982=334981=334982=diff
==
--- cfe/trunk/lib/CodeGen/CGCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCXX.cpp Mon Jun 18 13:58:54 2018
@@ -109,17 +109,8 @@ bool CodeGenModule::TryEmitBaseDestructo
   D->getType()->getAs()->getCallConv())
 return true;
 
-  return TryEmitDefinitionAsAlias(GlobalDecl(D, Dtor_Base),
-  GlobalDecl(BaseD, Dtor_Base));
-}
-
-/// Try to emit a definition as a global alias for another definition.
-/// If \p InEveryTU is true, we know that an equivalent alias can be produced
-/// in every translation unit.
-bool CodeGenModule::TryEmitDefinitionAsAlias(GlobalDecl AliasDecl,
- GlobalDecl TargetDecl) {
-  if (!getCodeGenOpts().CXXCtorDtorAliases)
-return true;
+  GlobalDecl AliasDecl(D, Dtor_Base);
+  GlobalDecl TargetDecl(BaseD, Dtor_Base);
 
   // The alias will use the linkage of the referent.  If we can't
   // support aliases with that linkage, fail.
@@ -193,6 +184,9 @@ bool CodeGenModule::TryEmitDefinitionAsA
   auto *Alias = llvm::GlobalAlias::create(AliasValueType, 0, Linkage, "",
   Aliasee, ());
 
+  // Destructors are always unnamed_addr.
+  Alias->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
+
   // Switch any previous uses to the alias.
   if (Entry) {
 assert(Entry->getType() == AliasType &&

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.h?rev=334982=334981=334982=diff
==
--- cfe/trunk/lib/CodeGen/CodeGenModule.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.h Mon Jun 18 13:58:54 2018
@@ -1193,7 +1193,6 @@ public:
   /// are emitted lazily.
   void EmitGlobal(GlobalDecl D);
 
-  bool TryEmitDefinitionAsAlias(GlobalDecl Alias, GlobalDecl Target);
   bool TryEmitBaseDestructorAsAlias(const CXXDestructorDecl *D);
 
   llvm::GlobalValue *GetGlobalValue(StringRef Ref);

Modified: cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp?rev=334982=334981=334982=diff
==
--- cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp (original)
+++ cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp Mon Jun 18 13:58:54 2018
@@ -3693,6 +3693,9 @@ static void emitConstructorDestructorAli
   // Create the alias with no name.
   auto *Alias = llvm::GlobalAlias::create(Linkage, "", Aliasee);
 
+  // Constructors and destructors are always unnamed_addr.
+  Alias->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
+
   // Switch any previous uses to the alias.
   if (Entry) {
 assert(Entry->getType() == Aliasee->getType() &&

Modified: cfe/trunk/test/CodeGenCXX/constructor-alias.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/constructor-alias.cpp?rev=334982=334981=334982=diff
==
--- cfe/trunk/test/CodeGenCXX/constructor-alias.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/constructor-alias.cpp Mon Jun 18 13:58:54 2018
@@ -9,4 +9,4 @@ struct B {
 B::B() {
 }
 
-// CHECK: @_ZN1BC1Ev = alias void (%struct.B*), void (%struct.B*)* @_ZN1BC2Ev
+// CHECK: @_ZN1BC1Ev = unnamed_addr alias void (%struct.B*), void 
(%struct.B*)* @_ZN1BC2Ev

Modified: cfe/trunk/test/CodeGenCXX/ctor-dtor-alias.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/ctor-dtor-alias.cpp?rev=334982=334981=334982=diff
==
--- cfe/trunk/test/CodeGenCXX/ctor-dtor-alias.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/ctor-dtor-alias.cpp Mon Jun 18 13:58:54 2018
@@ -14,8 +14,8 @@ namespace test1 {
 // Test that we produce the appropriate 

r334673 - Driver: De-duplicate some code. NFCI.

2018-06-13 Thread Peter Collingbourne via cfe-commits
Author: pcc
Date: Wed Jun 13 17:03:41 2018
New Revision: 334673

URL: http://llvm.org/viewvc/llvm-project?rev=334673=rev
Log:
Driver: De-duplicate some code. NFCI.

Modified:
cfe/trunk/lib/Driver/ToolChains/Clang.cpp

Modified: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Clang.cpp?rev=334673=334672=334673=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp Wed Jun 13 17:03:41 2018
@@ -3501,8 +3501,7 @@ void Clang::ConstructJob(Compilation ,
   Args.hasArg(options::OPT_dA))
 CmdArgs.push_back("-masm-verbose");
 
-  if (!Args.hasFlag(options::OPT_fintegrated_as, 
options::OPT_fno_integrated_as,
-IsIntegratedAssemblerDefault))
+  if (!getToolChain().useIntegratedAs())
 CmdArgs.push_back("-no-integrated-as");
 
   if (Args.hasArg(options::OPT_fdebug_pass_structure)) {


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


r334671 - docs: Add a missing LTO visibility reference.

2018-06-13 Thread Peter Collingbourne via cfe-commits
Author: pcc
Date: Wed Jun 13 16:21:02 2018
New Revision: 334671

URL: http://llvm.org/viewvc/llvm-project?rev=334671=rev
Log:
docs: Add a missing LTO visibility reference.

Modified:
cfe/trunk/docs/ControlFlowIntegrity.rst

Modified: cfe/trunk/docs/ControlFlowIntegrity.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ControlFlowIntegrity.rst?rev=334671=334670=334671=diff
==
--- cfe/trunk/docs/ControlFlowIntegrity.rst (original)
+++ cfe/trunk/docs/ControlFlowIntegrity.rst Wed Jun 13 16:21:02 2018
@@ -104,10 +104,11 @@ dynamic type; that is, the dynamic type
 derived class of the static type of the object used to make the call.
 This CFI scheme can be enabled on its own using ``-fsanitize=cfi-vcall``.
 
-For this scheme to work, all translation units containing the definition of
-a virtual member function (whether inline or not), other than members of
-:ref:`blacklisted ` types, must be compiled with ``-flto``
-or ``-flto=thin`` enabled and be statically linked into the program.
+For this scheme to work, all translation units containing the definition
+of a virtual member function (whether inline or not), other than members
+of :ref:`blacklisted ` types or types with public :doc:`LTO
+visibility `, must be compiled with ``-flto`` or ``-flto=thin``
+enabled and be statically linked into the program.
 
 Performance
 ---


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


r334669 - docs: Correct some misstatements in the control flow integrity docs.

2018-06-13 Thread Peter Collingbourne via cfe-commits
Author: pcc
Date: Wed Jun 13 16:18:26 2018
New Revision: 334669

URL: http://llvm.org/viewvc/llvm-project?rev=334669=rev
Log:
docs: Correct some misstatements in the control flow integrity docs.

These were true at one point but haven't been true for a long time.

Modified:
cfe/trunk/docs/ControlFlowIntegrity.rst

Modified: cfe/trunk/docs/ControlFlowIntegrity.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ControlFlowIntegrity.rst?rev=334669=334668=334669=diff
==
--- cfe/trunk/docs/ControlFlowIntegrity.rst (original)
+++ cfe/trunk/docs/ControlFlowIntegrity.rst Wed Jun 13 16:18:26 2018
@@ -104,10 +104,10 @@ dynamic type; that is, the dynamic type
 derived class of the static type of the object used to make the call.
 This CFI scheme can be enabled on its own using ``-fsanitize=cfi-vcall``.
 
-For this scheme to work, all translation units containing the definition
-of a virtual member function (whether inline or not), other than members
-of :ref:`blacklisted ` types, must be compiled with
-``-fsanitize=cfi-vcall`` enabled and be statically linked into the program.
+For this scheme to work, all translation units containing the definition of
+a virtual member function (whether inline or not), other than members of
+:ref:`blacklisted ` types, must be compiled with ``-flto``
+or ``-flto=thin`` enabled and be statically linked into the program.
 
 Performance
 ---
@@ -152,9 +152,9 @@ functions may be :ref:`blacklisted ` types, must be compiled with
-``-fsanitize=cfi-derived-cast`` or ``-fsanitize=cfi-unrelated-cast`` enabled
-and be statically linked into the program.
+of :ref:`blacklisted ` types or types with public :doc:`LTO
+visibility `, must be compiled with ``-flto`` or ``-flto=thin``
+enabled and be statically linked into the program.
 
 Non-Virtual Member Function Call Checking
 =
@@ -168,8 +168,9 @@ polymorphic class type.  This CFI scheme
 
 For this scheme to work, all translation units containing the definition
 of a virtual member function (whether inline or not), other than members
-of :ref:`blacklisted ` types, must be compiled with
-``-fsanitize=cfi-nvcall`` enabled and be statically linked into the program.
+of :ref:`blacklisted ` types or types with public :doc:`LTO
+visibility `, must be compiled with ``-flto`` or ``-flto=thin``
+enabled and be statically linked into the program.
 
 .. _cfi-strictness:
 


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


Re: [PATCH] D47597: IRGen: Write .dwo files when -split-dwarf-file is used together with -fthinlto-index.

2018-05-31 Thread Peter Collingbourne via cfe-commits
On Thu, May 31, 2018 at 11:54 AM, David Blaikie  wrote:

>
>
> On Thu, May 31, 2018 at 11:20 AM Peter Collingbourne via Phabricator <
> revi...@reviews.llvm.org> wrote:
>
>> pcc created this revision.
>> pcc added reviewers: tejohnson, dblaikie.
>> Herald added subscribers: JDevlieghere, hiraditya, eraman, inglorion,
>> mehdi_amini.
>>
>> https://reviews.llvm.org/D47597
>>
>> Files:
>>   clang/lib/CodeGen/BackendUtil.cpp
>>   clang/test/CodeGen/thinlto-split-dwarf.c
>>   llvm/include/llvm/LTO/Config.h
>>   llvm/lib/LTO/LTOBackend.cpp
>>
>>
>> Index: llvm/lib/LTO/LTOBackend.cpp
>> ===
>> --- llvm/lib/LTO/LTOBackend.cpp
>> +++ llvm/lib/LTO/LTOBackend.cpp
>> @@ -291,14 +291,19 @@
>>  return;
>>
>>std::unique_ptr DwoOut;
>> +  SmallString<1024> DwoFile(Conf.DwoPath);
>>if (!Conf.DwoDir.empty()) {
>>  std::error_code EC;
>>  if (auto EC = llvm::sys::fs::create_directories(Conf.DwoDir))
>>report_fatal_error("Failed to create directory " + Conf.DwoDir +
>> ": " +
>>   EC.message());
>>
>> -SmallString<1024> DwoFile(Conf.DwoDir);
>> +DwoFile = Conf.DwoDir;
>>  sys::path::append(DwoFile, std::to_string(Task) + ".dwo");
>> +  }
>> +
>> +  if (!DwoFile.empty()) {
>> +std::error_code EC;
>>  TM->Options.MCOptions.SplitDwarfFile = DwoFile.str().str();
>>  DwoOut = llvm::make_unique(DwoFile, EC,
>> sys::fs::F_None);
>>  if (EC)
>> Index: llvm/include/llvm/LTO/Config.h
>> ===
>> --- llvm/include/llvm/LTO/Config.h
>> +++ llvm/include/llvm/LTO/Config.h
>> @@ -76,6 +76,11 @@
>>/// The directory to store .dwo files.
>>std::string DwoDir;
>>
>> +  /// The path to write a .dwo file to. This should generally only be
>> used when
>> +  /// running an individual backend directly via thinBackend(), as
>> otherwise
>> +  /// all .dwo files will be written to the same path.
>> +  std::string DwoPath;
>> +
>>/// Optimization remarks file path.
>>std::string RemarksFilename = "";
>>
>> Index: clang/test/CodeGen/thinlto-split-dwarf.c
>> ===
>> --- /dev/null
>> +++ clang/test/CodeGen/thinlto-split-dwarf.c
>> @@ -0,0 +1,21 @@
>> +// REQUIRES: x86-registered-target
>> +
>> +// RUN: %clang_cc1 -debug-info-kind=limited -triple
>> x86_64-unknown-linux-gnu \
>> +// RUN:   -flto=thin -emit-llvm-bc \
>> +// RUN:   -o %t.o %s
>> +
>> +// RUN: llvm-lto2 run -thinlto-distributed-indexes %t.o \
>> +// RUN:   -o %t2.index \
>> +// RUN:   -r=%t.o,main,px
>> +
>> +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu \
>> +// RUN:   -emit-obj -fthinlto-index=%t.o.thinlto.bc \
>> +// RUN:   -o %t.native.o -split-dwarf-file %t.native.dwo -x ir %t.o
>>
>
> Can this be written in a single IR file yet (rather than frontend
> compiling, indexing, then backend compiling), now that Teresa's implemented
> some of the summary IR syntax?
>

I think the parsing part isn't implemented yet, so that wouldn't work.
Besides, we would need two separate files anyway: the bitcode file (%t.o)
and the combined summary (%t.o.thinlto.bc).

Peter


>
>
>> +
>> +// RUN: llvm-readobj -sections %t.native.o | FileCheck --check-prefix=O
>> %s
>> +// RUN: llvm-readobj -sections %t.native.dwo | FileCheck
>> --check-prefix=DWO %s
>> +
>> +// O-NOT: .dwo
>> +// DWO: .dwo
>> +
>> +int main() {}
>> Index: clang/lib/CodeGen/BackendUtil.cpp
>> ===
>> --- clang/lib/CodeGen/BackendUtil.cpp
>> +++ clang/lib/CodeGen/BackendUtil.cpp
>> @@ -1161,6 +1161,7 @@
>>Conf.DebugPassManager = CGOpts.DebugPassManager;
>>Conf.RemarksWithHotness = CGOpts.DiagnosticsWithHotness;
>>Conf.RemarksFilename = CGOpts.OptRecordFile;
>> +  Conf.DwoPath = CGOpts.SplitDwarfFile;
>>switch (Action) {
>>case Backend_EmitNothing:
>>  Conf.PreCodeGenModuleHook = [](size_t Task, const Module ) {
>>
>>
>>


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


r333677 - IRGen: Write .dwo files when -split-dwarf-file is used together with -fthinlto-index.

2018-05-31 Thread Peter Collingbourne via cfe-commits
Author: pcc
Date: Thu May 31 11:25:59 2018
New Revision: 333677

URL: http://llvm.org/viewvc/llvm-project?rev=333677=rev
Log:
IRGen: Write .dwo files when -split-dwarf-file is used together with 
-fthinlto-index.

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

Added:
cfe/trunk/test/CodeGen/thinlto-split-dwarf.c
Modified:
cfe/trunk/lib/CodeGen/BackendUtil.cpp

Modified: cfe/trunk/lib/CodeGen/BackendUtil.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/BackendUtil.cpp?rev=333677=333676=333677=diff
==
--- cfe/trunk/lib/CodeGen/BackendUtil.cpp (original)
+++ cfe/trunk/lib/CodeGen/BackendUtil.cpp Thu May 31 11:25:59 2018
@@ -1161,6 +1161,7 @@ static void runThinLTOBackend(ModuleSumm
   Conf.DebugPassManager = CGOpts.DebugPassManager;
   Conf.RemarksWithHotness = CGOpts.DiagnosticsWithHotness;
   Conf.RemarksFilename = CGOpts.OptRecordFile;
+  Conf.DwoPath = CGOpts.SplitDwarfFile;
   switch (Action) {
   case Backend_EmitNothing:
 Conf.PreCodeGenModuleHook = [](size_t Task, const Module ) {

Added: cfe/trunk/test/CodeGen/thinlto-split-dwarf.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/thinlto-split-dwarf.c?rev=333677=auto
==
--- cfe/trunk/test/CodeGen/thinlto-split-dwarf.c (added)
+++ cfe/trunk/test/CodeGen/thinlto-split-dwarf.c Thu May 31 11:25:59 2018
@@ -0,0 +1,21 @@
+// REQUIRES: x86-registered-target
+
+// RUN: %clang_cc1 -debug-info-kind=limited -triple x86_64-unknown-linux-gnu \
+// RUN:   -flto=thin -emit-llvm-bc \
+// RUN:   -o %t.o %s
+
+// RUN: llvm-lto2 run -thinlto-distributed-indexes %t.o \
+// RUN:   -o %t2.index \
+// RUN:   -r=%t.o,main,px
+
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu \
+// RUN:   -emit-obj -fthinlto-index=%t.o.thinlto.bc \
+// RUN:   -o %t.native.o -split-dwarf-file %t.native.dwo -x ir %t.o
+
+// RUN: llvm-readobj -sections %t.native.o | FileCheck --check-prefix=O %s
+// RUN: llvm-readobj -sections %t.native.dwo | FileCheck --check-prefix=DWO %s
+
+// O-NOT: .dwo
+// DWO: .dwo
+
+int main() {}


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


r333602 - IRGen: Rename bitsets -> type metadata. NFC.

2018-05-30 Thread Peter Collingbourne via cfe-commits
Author: pcc
Date: Wed May 30 15:29:08 2018
New Revision: 333602

URL: http://llvm.org/viewvc/llvm-project?rev=333602=rev
Log:
IRGen: Rename bitsets -> type metadata. NFC.

"Type metadata" is the term that we've been using for the CFI-related
information on vtables for a while now.

Modified:
cfe/trunk/lib/CodeGen/CGVTables.cpp

Modified: cfe/trunk/lib/CodeGen/CGVTables.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGVTables.cpp?rev=333602=333601=333602=diff
==
--- cfe/trunk/lib/CodeGen/CGVTables.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGVTables.cpp Wed May 30 15:29:08 2018
@@ -1012,31 +1012,30 @@ void CodeGenModule::EmitVTableTypeMetada
   CharUnits PointerWidth =
   Context.toCharUnitsFromBits(Context.getTargetInfo().getPointerWidth(0));
 
-  typedef std::pair BSEntry;
-  std::vector BitsetEntries;
-  // Create a bit set entry for each address point.
+  typedef std::pair TypeMetadata;
+  std::vector TypeMetadatas;
+  // Create type metadata for each address point.
   for (auto & : VTLayout.getAddressPoints())
-BitsetEntries.push_back(
-std::make_pair(AP.first.getBase(),
-   VTLayout.getVTableOffset(AP.second.VTableIndex) +
-   AP.second.AddressPointIndex));
-
-  // Sort the bit set entries for determinism.
-  llvm::sort(BitsetEntries.begin(), BitsetEntries.end(),
- [this](const BSEntry , const BSEntry ) {
-if ( == )
+TypeMetadatas.push_back(std::make_pair(
+AP.first.getBase(), VTLayout.getVTableOffset(AP.second.VTableIndex) +
+AP.second.AddressPointIndex));
+
+  // Sort the type metadata for determinism.
+  llvm::sort(TypeMetadatas.begin(), TypeMetadatas.end(),
+ [this](const TypeMetadata , const TypeMetadata ) {
+if ( == )
   return false;
 
 std::string S1;
 llvm::raw_string_ostream O1(S1);
 getCXXABI().getMangleContext().mangleTypeName(
-QualType(E1.first->getTypeForDecl(), 0), O1);
+QualType(M1.first->getTypeForDecl(), 0), O1);
 O1.flush();
 
 std::string S2;
 llvm::raw_string_ostream O2(S2);
 getCXXABI().getMangleContext().mangleTypeName(
-QualType(E2.first->getTypeForDecl(), 0), O2);
+QualType(M2.first->getTypeForDecl(), 0), O2);
 O2.flush();
 
 if (S1 < S2)
@@ -1044,10 +1043,10 @@ void CodeGenModule::EmitVTableTypeMetada
 if (S1 != S2)
   return false;
 
-return E1.second < E2.second;
+return M1.second < M2.second;
   });
 
-  for (auto BitsetEntry : BitsetEntries)
-AddVTableTypeMetadata(VTable, PointerWidth * BitsetEntry.second,
-  BitsetEntry.first);
+  for (auto TypeMetadata : TypeMetadatas)
+AddVTableTypeMetadata(VTable, PointerWidth * TypeMetadata.second,
+  TypeMetadata.first);
 }


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


r333600 - AST: Remove an unused ctor. NFC.

2018-05-30 Thread Peter Collingbourne via cfe-commits
Author: pcc
Date: Wed May 30 15:14:17 2018
New Revision: 333600

URL: http://llvm.org/viewvc/llvm-project?rev=333600=rev
Log:
AST: Remove an unused ctor. NFC.

Modified:
cfe/trunk/include/clang/AST/VTableBuilder.h

Modified: cfe/trunk/include/clang/AST/VTableBuilder.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/VTableBuilder.h?rev=333600=333599=333600=diff
==
--- cfe/trunk/include/clang/AST/VTableBuilder.h (original)
+++ cfe/trunk/include/clang/AST/VTableBuilder.h Wed May 30 15:14:17 2018
@@ -222,9 +222,6 @@ private:
 return static_cast(Value & ~7ULL);
   }
 
-  explicit VTableComponent(uint64_t Value)
-: Value(Value) { }
-
   /// The kind is stored in the lower 3 bits of the value. For offsets, we
   /// make use of the facts that classes can't be larger than 2^55 bytes,
   /// so we store the offset in the lower part of the 61 bits that remain.


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


r333598 - AST: Remove an unused function. NFC.

2018-05-30 Thread Peter Collingbourne via cfe-commits
Author: pcc
Date: Wed May 30 15:10:07 2018
New Revision: 333598

URL: http://llvm.org/viewvc/llvm-project?rev=333598=rev
Log:
AST: Remove an unused function. NFC.

Modified:
cfe/trunk/include/clang/AST/VTableBuilder.h

Modified: cfe/trunk/include/clang/AST/VTableBuilder.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/VTableBuilder.h?rev=333598=333597=333598=diff
==
--- cfe/trunk/include/clang/AST/VTableBuilder.h (original)
+++ cfe/trunk/include/clang/AST/VTableBuilder.h Wed May 30 15:10:07 2018
@@ -93,10 +93,6 @@ public:
reinterpret_cast(MD));
   }
 
-  static VTableComponent getFromOpaqueInteger(uint64_t I) {
-return VTableComponent(I);
-  }
-
   /// Get the kind of this vtable component.
   Kind getKind() const {
 return (Kind)(Value & 0x7);


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


r333501 - Protect a clang-cl file path with --.

2018-05-29 Thread Peter Collingbourne via cfe-commits
Author: pcc
Date: Tue May 29 21:08:34 2018
New Revision: 333501

URL: http://llvm.org/viewvc/llvm-project?rev=333501=rev
Log:
Protect a clang-cl file path with --.

Modified:
cfe/trunk/test/Driver/complete-member-pointers.cpp

Modified: cfe/trunk/test/Driver/complete-member-pointers.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/complete-member-pointers.cpp?rev=333501=333500=333501=diff
==
--- cfe/trunk/test/Driver/complete-member-pointers.cpp (original)
+++ cfe/trunk/test/Driver/complete-member-pointers.cpp Tue May 29 21:08:34 2018
@@ -1,7 +1,7 @@
 // RUN: %clangxx -### -c %s -o %t.o -target x86_64-unknown-linux 2>&1 | 
FileCheck --check-prefix=NOFLAG %s
 // RUN: %clangxx -### -c %s -o %t.o -target x86_64-unknown-linux 
-fcomplete-member-pointers 2>&1 | FileCheck %s
 // RUN: %clangxx -### -c %s -o %t.o -target x86_64-unknown-linux 
-fcomplete-member-pointers -fno-complete-member-pointers 2>&1 | FileCheck 
--check-prefix=NOFLAG %s
-// RUN: %clang_cl -### /c %s /Fo%t.o -target x86_64-pc-win32 
-fcomplete-member-pointers 2>&1 | FileCheck %s
+// RUN: %clang_cl -### /c /Fo%t.o -target x86_64-pc-win32 
-fcomplete-member-pointers -- %s 2>&1 | FileCheck %s
 
 // CHECK: "-fcomplete-member-pointers"
 // NOFLAG-NOT: "-fcomplete-member-pointers"


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


r333498 - Sema: Add a flag for rejecting member pointers with incomplete base types.

2018-05-29 Thread Peter Collingbourne via cfe-commits
Author: pcc
Date: Tue May 29 20:40:04 2018
New Revision: 333498

URL: http://llvm.org/viewvc/llvm-project?rev=333498=rev
Log:
Sema: Add a flag for rejecting member pointers with incomplete base types.

Codebases that need to be compatible with the Microsoft ABI can pass
this flag to avoid issues caused by the lack of a fixed ABI for
incomplete member pointers.

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

Added:
cfe/trunk/test/Driver/complete-member-pointers.cpp
cfe/trunk/test/SemaCXX/complete-member-pointers.cpp
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/include/clang/Basic/LangOptions.def
cfe/trunk/include/clang/Driver/Options.td
cfe/trunk/lib/Driver/ToolChains/Clang.cpp
cfe/trunk/lib/Frontend/CompilerInvocation.cpp
cfe/trunk/lib/Sema/SemaType.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=333498=333497=333498=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue May 29 20:40:04 
2018
@@ -6350,6 +6350,8 @@ def err_bad_memptr_rhs : Error<
 def err_bad_memptr_lhs : Error<
   "left hand operand to %0 must be a %select{|pointer to }1class "
   "compatible with the right hand operand, but is %2">;
+def err_memptr_incomplete : Error<
+  "member pointer has incomplete base type %0">;
 def warn_exception_caught_by_earlier_handler : Warning<
   "exception of type %0 will be caught by earlier handler">,
   InGroup;

Modified: cfe/trunk/include/clang/Basic/LangOptions.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/LangOptions.def?rev=333498=333497=333498=diff
==
--- cfe/trunk/include/clang/Basic/LangOptions.def (original)
+++ cfe/trunk/include/clang/Basic/LangOptions.def Tue May 29 20:40:04 2018
@@ -247,6 +247,10 @@ ENUM_LANGOPT(AddressSpaceMapMangling , A
 LANGOPT(IncludeDefaultHeader, 1, 0, "Include default header file for OpenCL")
 BENIGN_LANGOPT(DelayedTemplateParsing , 1, 0, "delayed template parsing")
 LANGOPT(BlocksRuntimeOptional , 1, 0, "optional blocks runtime")
+LANGOPT(
+CompleteMemberPointers, 1, 0,
+"Require member pointer base types to be complete at the point where the "
+"type's inheritance model would be determined under the Microsoft ABI")
 
 ENUM_LANGOPT(GC, GCMode, 2, NonGC, "Objective-C Garbage Collection mode")
 ENUM_LANGOPT(ValueVisibilityMode, Visibility, 3, DefaultVisibility,

Modified: cfe/trunk/include/clang/Driver/Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=333498=333497=333498=diff
==
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Tue May 29 20:40:04 2018
@@ -782,6 +782,12 @@ def fcomment_block_commands : CommaJoine
 def fparse_all_comments : Flag<["-"], "fparse-all-comments">, 
Group, Flags<[CC1Option]>;
 def fcommon : Flag<["-"], "fcommon">, Group;
 def fcompile_resource_EQ : Joined<["-"], "fcompile-resource=">, Group;
+def fcomplete_member_pointers : Flag<["-"], "fcomplete-member-pointers">, 
Group,
+   Flags<[CoreOption, CC1Option]>,
+   HelpText<"Require member pointer base types to be complete if they would be 
significant under the Microsoft ABI">;
+def fno_complete_member_pointers : Flag<["-"], 
"fno-complete-member-pointers">, Group,
+   Flags<[CoreOption]>,
+   HelpText<"Do not require member pointer base types to be complete if they 
would be significant under the Microsoft ABI">;
 def fconstant_cfstrings : Flag<["-"], "fconstant-cfstrings">, Group;
 def fconstant_string_class_EQ : Joined<["-"], "fconstant-string-class=">, 
Group;
 def fconstexpr_depth_EQ : Joined<["-"], "fconstexpr-depth=">, Group;

Modified: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Clang.cpp?rev=333498=333497=333498=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp Tue May 29 20:40:04 2018
@@ -4784,6 +4784,10 @@ void Clang::ConstructJob(Compilation ,
   CmdArgs.push_back("-fforce-enable-int128");
   }
 
+  if (Args.hasFlag(options::OPT_fcomplete_member_pointers,
+   options::OPT_fno_complete_member_pointers, false))
+CmdArgs.push_back("-fcomplete-member-pointers");
+
   // Finally add the compile command to the compilation.
   if (Args.hasArg(options::OPT__SLASH_fallback) &&
   Output.getType() == types::TY_Object &&

Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
URL: 

Re: r332885 - CodeGen, Driver: Start using direct split dwarf emission in clang.

2018-05-22 Thread Peter Collingbourne via cfe-commits
Sorry about that, I was keeping an eye on the bots but I must have missed
that one. I've relanded with a fix in r333013.

Peter

On Tue, May 22, 2018 at 4:25 AM, Amara Emerson <aemer...@apple.com> wrote:

> On 21 May 2018, at 21:31, Peter Collingbourne via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
> Author: pcc
> Date: Mon May 21 13:31:59 2018
> New Revision: 332885
>
> URL: http://llvm.org/viewvc/llvm-project?rev=332885=rev
> Log:
> CodeGen, Driver: Start using direct split dwarf emission in clang.
>
> Fixes PR37466.
>
> Differential Revision: https://reviews.llvm.org/D47093
>
> Added:
>cfe/trunk/test/Misc/cc1as-split-dwarf.s
> Modified:
>cfe/trunk/include/clang/Driver/CC1Options.td
>cfe/trunk/lib/CodeGen/BackendUtil.cpp
>cfe/trunk/lib/Driver/ToolChains/Clang.cpp
>cfe/trunk/test/CodeGen/split-debug-filename.c
>cfe/trunk/test/Driver/split-debug.c
>cfe/trunk/test/Driver/split-debug.s
>cfe/trunk/tools/driver/cc1as_main.cpp
>
> Modified: cfe/trunk/include/clang/Driver/CC1Options.td
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/
> clang/Driver/CC1Options.td?rev=332885=332884=332885=diff
> 
> ==
> --- cfe/trunk/include/clang/Driver/CC1Options.td (original)
> +++ cfe/trunk/include/clang/Driver/CC1Options.td Mon May 21 13:31:59 2018
> @@ -619,6 +619,8 @@ def version : Flag<["-"], "version">,
>   HelpText<"Print the compiler version">;
> def main_file_name : Separate<["-"], "main-file-name">,
>   HelpText<"Main file name to use for debug info">;
> +def split_dwarf_file : Separate<["-"], "split-dwarf-file">,
> +  HelpText<"File name to use for split dwarf debug info output">;
>
> }
>
> @@ -628,8 +630,6 @@ def fexternc_nounwind : Flag<["-"], "fex
>   HelpText<"Assume all functions with C linkage do not unwind">;
> def enable_split_dwarf : Flag<["-"], "enable-split-dwarf">,
>   HelpText<"Use split dwarf/Fission">;
> -def split_dwarf_file : Separate<["-"], "split-dwarf-file">,
> -  HelpText<"File name to use for split dwarf debug info output">;
> def fno_wchar : Flag<["-"], "fno-wchar">,
>   HelpText<"Disable C++ builtin type wchar_t">;
> def fconstant_string_class : Separate<["-"], "fconstant-string-class">,
>
> Modified: cfe/trunk/lib/CodeGen/BackendUtil.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/
> BackendUtil.cpp?rev=332885=332884=332885=diff
> 
> ==
> --- cfe/trunk/lib/CodeGen/BackendUtil.cpp (original)
> +++ cfe/trunk/lib/CodeGen/BackendUtil.cpp Mon May 21 13:31:59 2018
> @@ -104,7 +104,17 @@ class EmitAssemblyHelper {
>   ///
>   /// \return True on success.
>   bool AddEmitPasses(legacy::PassManager , BackendAction
> Action,
> - raw_pwrite_stream );
> + raw_pwrite_stream , raw_pwrite_stream *DwoOS);
> +
> +  std::unique_ptr openOutputFile(StringRef Path) {
> +std::error_code EC;
> +auto F = make_unique(Path, EC,
> llvm::sys::fs::F_None);
> +if (EC) {
> +  Diags.Report(diag::err_fe_unable_to_open_output) << Path <<
> EC.message();
> +  F.reset();
> +}
> +return F;
> +  }
>
> public:
>   EmitAssemblyHelper(DiagnosticsEngine &_Diags,
> @@ -701,7 +711,8 @@ void EmitAssemblyHelper::CreateTargetMac
>
> bool EmitAssemblyHelper::AddEmitPasses(legacy::PassManager ,
>BackendAction Action,
> -   raw_pwrite_stream ) {
> +   raw_pwrite_stream ,
> +   raw_pwrite_stream *DwoOS) {
>   // Add LibraryInfo.
>   llvm::Triple TargetTriple(TheModule->getTargetTriple());
>   std::unique_ptr TLII(
> @@ -718,7 +729,7 @@ bool EmitAssemblyHelper::AddEmitPasses(l
>   if (CodeGenOpts.OptimizationLevel > 0)
> CodeGenPasses.add(createObjCARCContractPass());
>
> -  if (TM->addPassesToEmitFile(CodeGenPasses, OS, nullptr, CGFT,
> +  if (TM->addPassesToEmitFile(CodeGenPasses, OS, DwoOS, CGFT,
>   /*DisableVerify=*/!CodeGenOpts.VerifyModule))
> {
> Diags.Report(diag::err_fe_unable_to_interface_with_target);
> return false;
> @@ -757,7 +768,7 @@ void EmitAssemblyHelper::EmitAssembly(Ba
>   Cod

r333013 - Reland r332885, "CodeGen, Driver: Start using direct split dwarf emission in clang."

2018-05-22 Thread Peter Collingbourne via cfe-commits
Author: pcc
Date: Tue May 22 11:52:37 2018
New Revision: 333013

URL: http://llvm.org/viewvc/llvm-project?rev=333013=rev
Log:
Reland r332885, "CodeGen, Driver: Start using direct split dwarf emission in 
clang."

As well as two follow-on commits r332906, r332911 with a fix for
test clang/test/CodeGen/split-debug-filename.c.

Added:
cfe/trunk/test/Misc/cc1as-split-dwarf.s
Modified:
cfe/trunk/include/clang/Driver/CC1Options.td
cfe/trunk/lib/CodeGen/BackendUtil.cpp
cfe/trunk/lib/Driver/ToolChains/Clang.cpp
cfe/trunk/test/CodeGen/split-debug-filename.c
cfe/trunk/test/Driver/split-debug.c
cfe/trunk/test/Driver/split-debug.s
cfe/trunk/tools/driver/cc1as_main.cpp

Modified: cfe/trunk/include/clang/Driver/CC1Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/CC1Options.td?rev=333013=333012=333013=diff
==
--- cfe/trunk/include/clang/Driver/CC1Options.td (original)
+++ cfe/trunk/include/clang/Driver/CC1Options.td Tue May 22 11:52:37 2018
@@ -619,6 +619,8 @@ def version : Flag<["-"], "version">,
   HelpText<"Print the compiler version">;
 def main_file_name : Separate<["-"], "main-file-name">,
   HelpText<"Main file name to use for debug info">;
+def split_dwarf_file : Separate<["-"], "split-dwarf-file">,
+  HelpText<"File name to use for split dwarf debug info output">;
 
 }
 
@@ -628,8 +630,6 @@ def fexternc_nounwind : Flag<["-"], "fex
   HelpText<"Assume all functions with C linkage do not unwind">;
 def enable_split_dwarf : Flag<["-"], "enable-split-dwarf">,
   HelpText<"Use split dwarf/Fission">;
-def split_dwarf_file : Separate<["-"], "split-dwarf-file">,
-  HelpText<"File name to use for split dwarf debug info output">;
 def fno_wchar : Flag<["-"], "fno-wchar">,
   HelpText<"Disable C++ builtin type wchar_t">;
 def fconstant_string_class : Separate<["-"], "fconstant-string-class">,

Modified: cfe/trunk/lib/CodeGen/BackendUtil.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/BackendUtil.cpp?rev=333013=333012=333013=diff
==
--- cfe/trunk/lib/CodeGen/BackendUtil.cpp (original)
+++ cfe/trunk/lib/CodeGen/BackendUtil.cpp Tue May 22 11:52:37 2018
@@ -104,7 +104,18 @@ class EmitAssemblyHelper {
   ///
   /// \return True on success.
   bool AddEmitPasses(legacy::PassManager , BackendAction Action,
- raw_pwrite_stream );
+ raw_pwrite_stream , raw_pwrite_stream *DwoOS);
+
+  std::unique_ptr openOutputFile(StringRef Path) {
+std::error_code EC;
+auto F = llvm::make_unique(Path, EC,
+ llvm::sys::fs::F_None);
+if (EC) {
+  Diags.Report(diag::err_fe_unable_to_open_output) << Path << EC.message();
+  F.reset();
+}
+return F;
+  }
 
 public:
   EmitAssemblyHelper(DiagnosticsEngine &_Diags,
@@ -701,7 +712,8 @@ void EmitAssemblyHelper::CreateTargetMac
 
 bool EmitAssemblyHelper::AddEmitPasses(legacy::PassManager ,
BackendAction Action,
-   raw_pwrite_stream ) {
+   raw_pwrite_stream ,
+   raw_pwrite_stream *DwoOS) {
   // Add LibraryInfo.
   llvm::Triple TargetTriple(TheModule->getTargetTriple());
   std::unique_ptr TLII(
@@ -718,7 +730,7 @@ bool EmitAssemblyHelper::AddEmitPasses(l
   if (CodeGenOpts.OptimizationLevel > 0)
 CodeGenPasses.add(createObjCARCContractPass());
 
-  if (TM->addPassesToEmitFile(CodeGenPasses, OS, nullptr, CGFT,
+  if (TM->addPassesToEmitFile(CodeGenPasses, OS, DwoOS, CGFT,
   /*DisableVerify=*/!CodeGenOpts.VerifyModule)) {
 Diags.Report(diag::err_fe_unable_to_interface_with_target);
 return false;
@@ -757,7 +769,7 @@ void EmitAssemblyHelper::EmitAssembly(Ba
   CodeGenPasses.add(
   createTargetTransformInfoWrapperPass(getTargetIRAnalysis()));
 
-  std::unique_ptr ThinLinkOS;
+  std::unique_ptr ThinLinkOS, DwoOS;
 
   switch (Action) {
   case Backend_EmitNothing:
@@ -766,18 +778,12 @@ void EmitAssemblyHelper::EmitAssembly(Ba
   case Backend_EmitBC:
 if (CodeGenOpts.EmitSummaryIndex) {
   if (!CodeGenOpts.ThinLinkBitcodeFile.empty()) {
-std::error_code EC;
-ThinLinkOS.reset(new llvm::raw_fd_ostream(
-CodeGenOpts.ThinLinkBitcodeFile, EC,
-llvm::sys::fs::F_None));
-if (EC) {
-  Diags.Report(diag::err_fe_unable_to_open_output) << 
CodeGenOpts.ThinLinkBitcodeFile
-   << EC.message();
+ThinLinkOS = openOutputFile(CodeGenOpts.ThinLinkBitcodeFile);
+if (!ThinLinkOS)
   return;
-}
   }
-  PerModulePasses.add(
-  createWriteThinLTOBitcodePass(*OS, ThinLinkOS.get()));
+  

r332911 - Add missing x86-registered-target.

2018-05-21 Thread Peter Collingbourne via cfe-commits
Author: pcc
Date: Mon May 21 15:14:02 2018
New Revision: 332911

URL: http://llvm.org/viewvc/llvm-project?rev=332911=rev
Log:
Add missing x86-registered-target.

Modified:
cfe/trunk/test/Misc/cc1as-split-dwarf.s

Modified: cfe/trunk/test/Misc/cc1as-split-dwarf.s
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Misc/cc1as-split-dwarf.s?rev=332911=332910=332911=diff
==
--- cfe/trunk/test/Misc/cc1as-split-dwarf.s (original)
+++ cfe/trunk/test/Misc/cc1as-split-dwarf.s Mon May 21 15:14:02 2018
@@ -1,3 +1,4 @@
+// REQUIRES: x86-registered-target
 // RUN: %clang -cc1as -triple x86_64-pc-linux-gnu %s -filetype obj -o %t1 
-split-dwarf-file %t2
 // RUN: llvm-objdump -s %t1 | FileCheck --check-prefix=O %s
 // RUN: llvm-objdump -s %t2 | FileCheck --check-prefix=DWO %s


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


r332906 - Fix another make_unique ambiguity.

2018-05-21 Thread Peter Collingbourne via cfe-commits
Author: pcc
Date: Mon May 21 14:48:17 2018
New Revision: 332906

URL: http://llvm.org/viewvc/llvm-project?rev=332906=rev
Log:
Fix another make_unique ambiguity.

Modified:
cfe/trunk/lib/CodeGen/BackendUtil.cpp

Modified: cfe/trunk/lib/CodeGen/BackendUtil.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/BackendUtil.cpp?rev=332906=332905=332906=diff
==
--- cfe/trunk/lib/CodeGen/BackendUtil.cpp (original)
+++ cfe/trunk/lib/CodeGen/BackendUtil.cpp Mon May 21 14:48:17 2018
@@ -108,7 +108,8 @@ class EmitAssemblyHelper {
 
   std::unique_ptr openOutputFile(StringRef Path) {
 std::error_code EC;
-auto F = make_unique(Path, EC, 
llvm::sys::fs::F_None);
+auto F = llvm::make_unique(Path, EC,
+ llvm::sys::fs::F_None);
 if (EC) {
   Diags.Report(diag::err_fe_unable_to_open_output) << Path << EC.message();
   F.reset();


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


r332885 - CodeGen, Driver: Start using direct split dwarf emission in clang.

2018-05-21 Thread Peter Collingbourne via cfe-commits
Author: pcc
Date: Mon May 21 13:31:59 2018
New Revision: 332885

URL: http://llvm.org/viewvc/llvm-project?rev=332885=rev
Log:
CodeGen, Driver: Start using direct split dwarf emission in clang.

Fixes PR37466.

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

Added:
cfe/trunk/test/Misc/cc1as-split-dwarf.s
Modified:
cfe/trunk/include/clang/Driver/CC1Options.td
cfe/trunk/lib/CodeGen/BackendUtil.cpp
cfe/trunk/lib/Driver/ToolChains/Clang.cpp
cfe/trunk/test/CodeGen/split-debug-filename.c
cfe/trunk/test/Driver/split-debug.c
cfe/trunk/test/Driver/split-debug.s
cfe/trunk/tools/driver/cc1as_main.cpp

Modified: cfe/trunk/include/clang/Driver/CC1Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/CC1Options.td?rev=332885=332884=332885=diff
==
--- cfe/trunk/include/clang/Driver/CC1Options.td (original)
+++ cfe/trunk/include/clang/Driver/CC1Options.td Mon May 21 13:31:59 2018
@@ -619,6 +619,8 @@ def version : Flag<["-"], "version">,
   HelpText<"Print the compiler version">;
 def main_file_name : Separate<["-"], "main-file-name">,
   HelpText<"Main file name to use for debug info">;
+def split_dwarf_file : Separate<["-"], "split-dwarf-file">,
+  HelpText<"File name to use for split dwarf debug info output">;
 
 }
 
@@ -628,8 +630,6 @@ def fexternc_nounwind : Flag<["-"], "fex
   HelpText<"Assume all functions with C linkage do not unwind">;
 def enable_split_dwarf : Flag<["-"], "enable-split-dwarf">,
   HelpText<"Use split dwarf/Fission">;
-def split_dwarf_file : Separate<["-"], "split-dwarf-file">,
-  HelpText<"File name to use for split dwarf debug info output">;
 def fno_wchar : Flag<["-"], "fno-wchar">,
   HelpText<"Disable C++ builtin type wchar_t">;
 def fconstant_string_class : Separate<["-"], "fconstant-string-class">,

Modified: cfe/trunk/lib/CodeGen/BackendUtil.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/BackendUtil.cpp?rev=332885=332884=332885=diff
==
--- cfe/trunk/lib/CodeGen/BackendUtil.cpp (original)
+++ cfe/trunk/lib/CodeGen/BackendUtil.cpp Mon May 21 13:31:59 2018
@@ -104,7 +104,17 @@ class EmitAssemblyHelper {
   ///
   /// \return True on success.
   bool AddEmitPasses(legacy::PassManager , BackendAction Action,
- raw_pwrite_stream );
+ raw_pwrite_stream , raw_pwrite_stream *DwoOS);
+
+  std::unique_ptr openOutputFile(StringRef Path) {
+std::error_code EC;
+auto F = make_unique(Path, EC, 
llvm::sys::fs::F_None);
+if (EC) {
+  Diags.Report(diag::err_fe_unable_to_open_output) << Path << EC.message();
+  F.reset();
+}
+return F;
+  }
 
 public:
   EmitAssemblyHelper(DiagnosticsEngine &_Diags,
@@ -701,7 +711,8 @@ void EmitAssemblyHelper::CreateTargetMac
 
 bool EmitAssemblyHelper::AddEmitPasses(legacy::PassManager ,
BackendAction Action,
-   raw_pwrite_stream ) {
+   raw_pwrite_stream ,
+   raw_pwrite_stream *DwoOS) {
   // Add LibraryInfo.
   llvm::Triple TargetTriple(TheModule->getTargetTriple());
   std::unique_ptr TLII(
@@ -718,7 +729,7 @@ bool EmitAssemblyHelper::AddEmitPasses(l
   if (CodeGenOpts.OptimizationLevel > 0)
 CodeGenPasses.add(createObjCARCContractPass());
 
-  if (TM->addPassesToEmitFile(CodeGenPasses, OS, nullptr, CGFT,
+  if (TM->addPassesToEmitFile(CodeGenPasses, OS, DwoOS, CGFT,
   /*DisableVerify=*/!CodeGenOpts.VerifyModule)) {
 Diags.Report(diag::err_fe_unable_to_interface_with_target);
 return false;
@@ -757,7 +768,7 @@ void EmitAssemblyHelper::EmitAssembly(Ba
   CodeGenPasses.add(
   createTargetTransformInfoWrapperPass(getTargetIRAnalysis()));
 
-  std::unique_ptr ThinLinkOS;
+  std::unique_ptr ThinLinkOS, DwoOS;
 
   switch (Action) {
   case Backend_EmitNothing:
@@ -766,18 +777,12 @@ void EmitAssemblyHelper::EmitAssembly(Ba
   case Backend_EmitBC:
 if (CodeGenOpts.EmitSummaryIndex) {
   if (!CodeGenOpts.ThinLinkBitcodeFile.empty()) {
-std::error_code EC;
-ThinLinkOS.reset(new llvm::raw_fd_ostream(
-CodeGenOpts.ThinLinkBitcodeFile, EC,
-llvm::sys::fs::F_None));
-if (EC) {
-  Diags.Report(diag::err_fe_unable_to_open_output) << 
CodeGenOpts.ThinLinkBitcodeFile
-   << EC.message();
+ThinLinkOS = openOutputFile(CodeGenOpts.ThinLinkBitcodeFile);
+if (!ThinLinkOS)
   return;
-}
   }
-  PerModulePasses.add(
-  createWriteThinLTOBitcodePass(*OS, ThinLinkOS.get()));
+  PerModulePasses.add(createWriteThinLTOBitcodePass(
+  *OS, ThinLinkOS ? >os() : nullptr));
 }
 else
   PerModulePasses.add(
@@ -790,7 

r332881 - CodeGen: Add a dwo output file argument to addPassesToEmitFile and hook it up to dwo output.

2018-05-21 Thread Peter Collingbourne via cfe-commits
Author: pcc
Date: Mon May 21 13:16:41 2018
New Revision: 332881

URL: http://llvm.org/viewvc/llvm-project?rev=332881=rev
Log:
CodeGen: Add a dwo output file argument to addPassesToEmitFile and hook it up 
to dwo output.

Part of PR37466.

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

Modified:
cfe/trunk/lib/CodeGen/BackendUtil.cpp

Modified: cfe/trunk/lib/CodeGen/BackendUtil.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/BackendUtil.cpp?rev=332881=332880=332881=diff
==
--- cfe/trunk/lib/CodeGen/BackendUtil.cpp (original)
+++ cfe/trunk/lib/CodeGen/BackendUtil.cpp Mon May 21 13:16:41 2018
@@ -718,7 +718,7 @@ bool EmitAssemblyHelper::AddEmitPasses(l
   if (CodeGenOpts.OptimizationLevel > 0)
 CodeGenPasses.add(createObjCARCContractPass());
 
-  if (TM->addPassesToEmitFile(CodeGenPasses, OS, CGFT,
+  if (TM->addPassesToEmitFile(CodeGenPasses, OS, nullptr, CGFT,
   /*DisableVerify=*/!CodeGenOpts.VerifyModule)) {
 Diags.Report(diag::err_fe_unable_to_interface_with_target);
 return false;


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


r332757 - Support: Simplify endian stream interface. NFCI.

2018-05-18 Thread Peter Collingbourne via cfe-commits
Author: pcc
Date: Fri May 18 12:46:24 2018
New Revision: 332757

URL: http://llvm.org/viewvc/llvm-project?rev=332757=rev
Log:
Support: Simplify endian stream interface. NFCI.

Provide some free functions to reduce verbosity of endian-writing
a single value, and replace the endianness template parameter with
a field.

Part of PR37466.

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

Modified:
cfe/trunk/lib/Frontend/CacheTokens.cpp
cfe/trunk/lib/Serialization/ASTWriter.cpp
cfe/trunk/lib/Serialization/GlobalModuleIndex.cpp
cfe/trunk/lib/Serialization/MultiOnDiskHashTable.h

Modified: cfe/trunk/lib/Frontend/CacheTokens.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CacheTokens.cpp?rev=332757=332756=332757=diff
==
--- cfe/trunk/lib/Frontend/CacheTokens.cpp (original)
+++ cfe/trunk/lib/Frontend/CacheTokens.cpp Fri May 18 12:46:24 2018
@@ -88,7 +88,7 @@ public:
 
   void EmitData(raw_ostream& Out) {
 using namespace llvm::support;
-endian::Writer LE(Out);
+endian::Writer LE(Out, little);
 switch (Kind) {
 case IsFE: {
   // Emit stat information.
@@ -135,7 +135,7 @@ public:
   EmitKeyDataLength(raw_ostream& Out, PTHEntryKeyVariant V,
 const PTHEntry& E) {
 using namespace llvm::support;
-endian::Writer LE(Out);
+endian::Writer LE(Out, little);
 
 unsigned n = V.getString().size() + 1 + 1;
 LE.write(n);
@@ -149,7 +149,7 @@ public:
   static void EmitKey(raw_ostream& Out, PTHEntryKeyVariant V, unsigned n){
 using namespace llvm::support;
 // Emit the entry kind.
-endian::Writer(Out).write((unsigned)V.getKind());
+Out << char(V.getKind());
 // Emit the string.
 Out.write(V.getString().data(), n - 1);
   }
@@ -157,7 +157,7 @@ public:
   static void EmitData(raw_ostream& Out, PTHEntryKeyVariant V,
const PTHEntry& E, unsigned) {
 using namespace llvm::support;
-endian::Writer LE(Out);
+endian::Writer LE(Out, little);
 
 // For file entries emit the offsets into the PTH file for token data
 // and the preprocessor blocks table.
@@ -205,18 +205,17 @@ class PTHWriter {
   void EmitToken(const Token& T);
 
   void Emit8(uint32_t V) {
-using namespace llvm::support;
-endian::Writer(Out).write(V);
+Out << char(V);
   }
 
   void Emit16(uint32_t V) {
 using namespace llvm::support;
-endian::Writer(Out).write(V);
+endian::write(Out, V, little);
   }
 
   void Emit32(uint32_t V) {
 using namespace llvm::support;
-endian::Writer(Out).write(V);
+endian::write(Out, V, little);
   }
 
   void EmitBuf(const char *Ptr, unsigned NumBytes) {
@@ -225,7 +224,7 @@ class PTHWriter {
 
   void EmitString(StringRef V) {
 using namespace llvm::support;
-endian::Writer(Out).write(V.size());
+endian::write(Out, V.size(), little);
 EmitBuf(V.data(), V.size());
   }
 
@@ -299,7 +298,7 @@ PTHEntry PTHWriter::LexTokens(Lexer& L)
   // Pad 0's so that we emit tokens to a 4-byte alignment.
   // This speed up reading them back in.
   using namespace llvm::support;
-  endian::Writer LE(Out);
+  endian::Writer LE(Out, little);
   uint32_t TokenOff = Out.tell();
   for (uint64_t N = llvm::OffsetToAlignment(TokenOff, 4); N; --N, ++TokenOff)
 LE.write(0);
@@ -632,7 +631,7 @@ public:
   EmitKeyDataLength(raw_ostream& Out, const PTHIdKey* key, uint32_t) {
 using namespace llvm::support;
 unsigned n = key->II->getLength() + 1;
-endian::Writer(Out).write(n);
+endian::write(Out, n, little);
 return std::make_pair(n, sizeof(uint32_t));
   }
 
@@ -646,7 +645,7 @@ public:
   static void EmitData(raw_ostream& Out, PTHIdKey*, uint32_t pID,
unsigned) {
 using namespace llvm::support;
-endian::Writer(Out).write(pID);
+endian::write(Out, pID, little);
   }
 };
 } // end anonymous namespace

Modified: cfe/trunk/lib/Serialization/ASTWriter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriter.cpp?rev=332757=332756=332757=diff
==
--- cfe/trunk/lib/Serialization/ASTWriter.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTWriter.cpp Fri May 18 12:46:24 2018
@@ -1955,7 +1955,7 @@ namespace {
 EmitKeyDataLength(raw_ostream& Out, key_type_ref key, data_type_ref Data) {
   using namespace llvm::support;
 
-  endian::Writer LE(Out);
+  endian::Writer LE(Out, little);
   unsigned KeyLen = key.Filename.size() + 1 + 8 + 8;
   LE.write(KeyLen);
   unsigned DataLen = 1 + 2 + 4 + 4;
@@ -1971,7 +1971,7 @@ namespace {
 void EmitKey(raw_ostream& Out, key_type_ref key, unsigned KeyLen) {
   using namespace llvm::support;
 
-  endian::Writer LE(Out);
+  endian::Writer LE(Out, little);
   LE.write(key.Size);
   KeyLen -= 8;
   LE.write(key.ModTime);
@@ -1983,7 +1983,7 @@ 

r332749 - MC: Change the streamer ctors to take an object writer instead of a stream. NFCI.

2018-05-18 Thread Peter Collingbourne via cfe-commits
Author: pcc
Date: Fri May 18 11:26:45 2018
New Revision: 332749

URL: http://llvm.org/viewvc/llvm-project?rev=332749=rev
Log:
MC: Change the streamer ctors to take an object writer instead of a stream. 
NFCI.

The idea is that a client that wants split dwarf would create a
specific kind of object writer that creates two files, and use it to
create the streamer.

Part of PR37466.

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

Modified:
cfe/trunk/tools/driver/cc1as_main.cpp

Modified: cfe/trunk/tools/driver/cc1as_main.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/driver/cc1as_main.cpp?rev=332749=332748=332749=diff
==
--- cfe/trunk/tools/driver/cc1as_main.cpp (original)
+++ cfe/trunk/tools/driver/cc1as_main.cpp Fri May 18 11:26:45 2018
@@ -29,6 +29,7 @@
 #include "llvm/MC/MCContext.h"
 #include "llvm/MC/MCInstrInfo.h"
 #include "llvm/MC/MCObjectFileInfo.h"
+#include "llvm/MC/MCObjectWriter.h"
 #include "llvm/MC/MCParser/MCAsmParser.h"
 #include "llvm/MC/MCParser/MCTargetAsmParser.h"
 #include "llvm/MC/MCRegisterInfo.h"
@@ -426,11 +427,12 @@ static bool ExecuteAssembler(AssemblerIn
 MCTargetOptions MCOptions;
 std::unique_ptr MAB(
 TheTarget->createMCAsmBackend(*STI, *MRI, MCOptions));
+std::unique_ptr OW = MAB->createObjectWriter(*Out);
 
 Triple T(Opts.Triple);
 Str.reset(TheTarget->createMCObjectStreamer(
-T, Ctx, std::move(MAB), *Out, std::move(CE), *STI, Opts.RelaxAll,
-Opts.IncrementalLinkerCompatible,
+T, Ctx, std::move(MAB), std::move(OW), std::move(CE), *STI,
+Opts.RelaxAll, Opts.IncrementalLinkerCompatible,
 /*DWARFMustBeAtTheEnd*/ true));
 Str.get()->InitSections(Opts.NoExecStack);
   }


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


r332675 - Support: Add a raw_ostream::write_zeros() function. NFCI.

2018-05-17 Thread Peter Collingbourne via cfe-commits
Author: pcc
Date: Thu May 17 15:11:43 2018
New Revision: 332675

URL: http://llvm.org/viewvc/llvm-project?rev=332675=rev
Log:
Support: Add a raw_ostream::write_zeros() function. NFCI.

This will eventually replace MCObjectWriter::WriteZeros.

Part of PR37466.

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

Modified:
cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp

Modified: cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp?rev=332675=332674=332675=diff
==
--- cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp (original)
+++ cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp Thu May 17 15:11:43 2018
@@ -1372,8 +1372,7 @@ void CoverageMappingModuleGen::emit() {
   // and coverage mappings is a multiple of 8.
   if (size_t Rem = OS.str().size() % 8) {
 CoverageMappingSize += 8 - Rem;
-for (size_t I = 0, S = 8 - Rem; I < S; ++I)
-  OS << '\0';
+OS.write_zeros(8 - Rem);
   }
   auto *FilenamesAndMappingsVal =
   llvm::ConstantDataArray::getString(Ctx, OS.str(), false);


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


[libcxx] r332543 - Condition usage of locale stdlib functions on Android API version

2018-05-16 Thread Peter Collingbourne via cfe-commits
Author: pcc
Date: Wed May 16 15:40:12 2018
New Revision: 332543

URL: http://llvm.org/viewvc/llvm-project?rev=332543=rev
Log:
Condition usage of locale stdlib functions on Android API version

Some *_l functions were not available in some versions of Bionic. This CL
checks that the NDK version supports the functions, and if not, falls back
on the corresponding functions that don't take a locale.

Patch by Tom Anderson!

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

Modified:
libcxx/trunk/include/support/android/locale_bionic.h

Modified: libcxx/trunk/include/support/android/locale_bionic.h
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/support/android/locale_bionic.h?rev=332543=332542=332543=diff
==
--- libcxx/trunk/include/support/android/locale_bionic.h (original)
+++ libcxx/trunk/include/support/android/locale_bionic.h Wed May 16 15:40:12 
2018
@@ -27,14 +27,14 @@ extern "C" {
 #if defined(__ANDROID__)
 
 #include 
-
-// Android gained most locale aware functions in L (API level 21)
-#if __ANDROID_API__ < 21
+#include 
 #include 
-#endif
-
-// The strto* family was added in O (API Level 26)
-#if __ANDROID_API__ < 26
+// In NDK versions later than 16, locale-aware functions are provided by
+// legacy_stdlib_inlines.h
+#if __NDK_MAJOR__ <= 16
+#if __ANDROID_API__ < 21
+#include 
+#elif __ANDROID_API__ < 26
 
 #if defined(__cplusplus)
 extern "C" {
@@ -61,6 +61,7 @@ inline _LIBCPP_ALWAYS_INLINE long strtol
 
 #endif // __ANDROID_API__ < 26
 
+#endif // __NDK_MAJOR__ <= 16
 #endif // defined(__ANDROID__)
 
 #endif // defined(__BIONIC__)


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


r331681 - Relax a FileCheck pattern to make it pass on Windows.

2018-05-07 Thread Peter Collingbourne via cfe-commits
Author: pcc
Date: Mon May  7 14:40:53 2018
New Revision: 331681

URL: http://llvm.org/viewvc/llvm-project?rev=331681=rev
Log:
Relax a FileCheck pattern to make it pass on Windows.

Should fix Windows bot failure:
http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast/builds/16956

Modified:
cfe/trunk/test/Driver/fsanitize-blacklist.c

Modified: cfe/trunk/test/Driver/fsanitize-blacklist.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/fsanitize-blacklist.c?rev=331681=331680=331681=diff
==
--- cfe/trunk/test/Driver/fsanitize-blacklist.c (original)
+++ cfe/trunk/test/Driver/fsanitize-blacklist.c Mon May  7 14:40:53 2018
@@ -64,6 +64,6 @@
 
 // If cfi_blacklist.txt cannot be found in the resource dir, driver should 
fail.
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=cfi -resource-dir=/dev/null 
%s -### 2>&1 | FileCheck %s --check-prefix=CHECK-MISSING-CFI-BLACKLIST
-// CHECK-MISSING-CFI-BLACKLIST: error: no such file or directory: 
'{{.*}}/share/cfi_blacklist.txt'
+// CHECK-MISSING-CFI-BLACKLIST: error: no such file or directory: 
'{{.*}}cfi_blacklist.txt'
 
 // DELIMITERS: {{^ *"}}


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


r331674 - [CFI] Force LLVM to die if the implicit blacklist files cannot be found.

2018-05-07 Thread Peter Collingbourne via cfe-commits
Author: pcc
Date: Mon May  7 13:54:05 2018
New Revision: 331674

URL: http://llvm.org/viewvc/llvm-project?rev=331674=rev
Log:
[CFI] Force LLVM to die if the implicit blacklist files cannot be found.

Currently LLVM CFI tries to use an implicit blacklist file, currently
in /usr/lib64/clang//share. If the file is not there, LLVM
happily continues, which causes CFI to add checks to files/functions
that are known to fail, generating binaries that fail. This CL causes
LLVM to die (I hope) if it can't find these implicit blacklist files.

Patch by Caroline Tice!

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

Added:
cfe/trunk/test/Driver/Inputs/resource_dir_with_cfi_blacklist/
cfe/trunk/test/Driver/Inputs/resource_dir_with_cfi_blacklist/share/

cfe/trunk/test/Driver/Inputs/resource_dir_with_cfi_blacklist/share/cfi_blacklist.txt
Modified:
cfe/trunk/lib/Driver/SanitizerArgs.cpp
cfe/trunk/test/Driver/fsanitize-blacklist.c
cfe/trunk/test/Frontend/dependency-gen.c

Modified: cfe/trunk/lib/Driver/SanitizerArgs.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/SanitizerArgs.cpp?rev=331674=331673=331674=diff
==
--- cfe/trunk/lib/Driver/SanitizerArgs.cpp (original)
+++ cfe/trunk/lib/Driver/SanitizerArgs.cpp Mon May  7 13:54:05 2018
@@ -115,6 +115,10 @@ static void addDefaultBlacklists(const D
 llvm::sys::path::append(Path, "share", BL.File);
 if (llvm::sys::fs::exists(Path))
   BlacklistFiles.push_back(Path.str());
+else if (BL.Mask == CFI)
+  // If cfi_blacklist.txt cannot be found in the resource dir, driver
+  // should fail.
+  D.Diag(clang::diag::err_drv_no_such_file) << Path;
   }
 }
 

Added: 
cfe/trunk/test/Driver/Inputs/resource_dir_with_cfi_blacklist/share/cfi_blacklist.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/Inputs/resource_dir_with_cfi_blacklist/share/cfi_blacklist.txt?rev=331674=auto
==
(empty)

Modified: cfe/trunk/test/Driver/fsanitize-blacklist.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/fsanitize-blacklist.c?rev=331674=331673=331674=diff
==
--- cfe/trunk/test/Driver/fsanitize-blacklist.c (original)
+++ cfe/trunk/test/Driver/fsanitize-blacklist.c Mon May  7 13:54:05 2018
@@ -62,4 +62,8 @@
 // CHECK-ONLY-FIRST-DISABLED: -fsanitize-blacklist={{.*}}.second
 // CHECK-ONLY_FIRST-DISABLED-NOT: good
 
+// If cfi_blacklist.txt cannot be found in the resource dir, driver should 
fail.
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=cfi -resource-dir=/dev/null 
%s -### 2>&1 | FileCheck %s --check-prefix=CHECK-MISSING-CFI-BLACKLIST
+// CHECK-MISSING-CFI-BLACKLIST: error: no such file or directory: 
'{{.*}}/share/cfi_blacklist.txt'
+
 // DELIMITERS: {{^ *"}}

Modified: cfe/trunk/test/Frontend/dependency-gen.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Frontend/dependency-gen.c?rev=331674=331673=331674=diff
==
--- cfe/trunk/test/Frontend/dependency-gen.c (original)
+++ cfe/trunk/test/Frontend/dependency-gen.c Mon May  7 13:54:05 2018
@@ -21,7 +21,7 @@
 // RUN: %clang -MD -MF - %s -fsyntax-only -I ./ | FileCheck 
-check-prefix=CHECK-SIX %s
 // CHECK-SIX: {{ }}x.h
 // RUN: echo "fun:foo" > %t.blacklist
-// RUN: %clang -MD -MF - %s -fsyntax-only -fsanitize=cfi-vcall -flto 
-fvisibility=hidden -fsanitize-blacklist=%t.blacklist -I ./ | FileCheck 
-check-prefix=CHECK-SEVEN %s
+// RUN: %clang -MD -MF - %s -fsyntax-only 
-resource-dir=%S/../Driver/Inputs/resource_dir_with_cfi_blacklist 
-fsanitize=cfi-vcall -flto -fvisibility=hidden 
-fsanitize-blacklist=%t.blacklist -I ./ | FileCheck -check-prefix=CHECK-SEVEN %s
 // CHECK-SEVEN: .blacklist
 // CHECK-SEVEN: {{ }}x.h
 #ifndef INCLUDE_FLAG_TEST


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


Re: r330210 - Remove unused variable

2018-04-17 Thread Peter Collingbourne via cfe-commits
FWIW, I don't think you actually need the if.

Peter

On Tue, Apr 17, 2018 at 1:21 PM, Teresa Johnson via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: tejohnson
> Date: Tue Apr 17 13:21:53 2018
> New Revision: 330210
>
> URL: http://llvm.org/viewvc/llvm-project?rev=330210=rev
> Log:
> Remove unused variable
>
> Fixes unused variable error introduced in r330194.
>
> Modified:
> cfe/trunk/lib/Driver/ToolChains/Clang.cpp
>
> Modified: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/
> ToolChains/Clang.cpp?rev=330210=330209=330210=diff
> 
> ==
> --- cfe/trunk/lib/Driver/ToolChains/Clang.cpp (original)
> +++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp Tue Apr 17 13:21:53 2018
> @@ -3267,7 +3267,7 @@ void Clang::ConstructJob(Compilation ,
>  Args.AddLastArg(CmdArgs, options::OPT_fthinlto_index_EQ);
>}
>
> -  if (const Arg *A = Args.getLastArg(options::OPT_save_temps_EQ))
> +  if (Args.getLastArg(options::OPT_save_temps_EQ))
>  Args.AddLastArg(CmdArgs, options::OPT_save_temps_EQ);
>
>// Embed-bitcode option.
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>



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


r329236 - AArch64: Implement support for the shadowcallstack attribute.

2018-04-04 Thread Peter Collingbourne via cfe-commits
Author: pcc
Date: Wed Apr  4 14:55:44 2018
New Revision: 329236

URL: http://llvm.org/viewvc/llvm-project?rev=329236=rev
Log:
AArch64: Implement support for the shadowcallstack attribute.

The implementation of shadow call stack on aarch64 is quite different to
the implementation on x86_64. Instead of reserving a segment register for
the shadow call stack, we reserve the platform register, x18. Any function
that spills lr to sp also spills it to the shadow call stack, a pointer to
which is stored in x18.

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

Modified:
cfe/trunk/docs/ShadowCallStack.rst
cfe/trunk/lib/Driver/SanitizerArgs.cpp
cfe/trunk/lib/Driver/ToolChain.cpp
cfe/trunk/test/Driver/sanitizer-ld.c

Modified: cfe/trunk/docs/ShadowCallStack.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ShadowCallStack.rst?rev=329236=329235=329236=diff
==
--- cfe/trunk/docs/ShadowCallStack.rst (original)
+++ cfe/trunk/docs/ShadowCallStack.rst Wed Apr  4 14:55:44 2018
@@ -9,11 +9,11 @@ Introduction
 
 
 ShadowCallStack is an **experimental** instrumentation pass, currently only
-implemented for x86_64, that protects programs against return address
-overwrites (e.g. stack buffer overflows.) It works by saving a function's 
return
-address to a separately allocated 'shadow call stack' in the function prolog 
and
-checking the return address on the stack against the shadow call stack in the
-function epilog.
+implemented for x86_64 and aarch64, that protects programs against return
+address overwrites (e.g. stack buffer overflows.) It works by saving a
+function's return address to a separately allocated 'shadow call stack'
+in the function prolog and checking the return address on the stack against
+the shadow call stack in the function epilog.
 
 Comparison
 --
@@ -37,8 +37,16 @@ support.
 Compatibility
 -
 
-ShadowCallStack currently only supports x86_64. A runtime is not currently
-provided in compiler-rt so one must be provided by the compiled application.
+ShadowCallStack currently only supports x86_64 and aarch64. A runtime is not
+currently provided in compiler-rt so one must be provided by the compiled
+application.
+
+On aarch64, the instrumentation makes use of the platform register ``x18``.
+On some platforms, ``x18`` is reserved, and on others, it is designated as
+a scratch register.  This generally means that any code that may run on the
+same thread as code compiled with ShadowCallStack must either target one
+of the platforms whose ABI reserves ``x18`` (currently Darwin, Fuchsia and
+Windows) or be compiled with the flag ``-ffixed-x18``.
 
 Security
 
@@ -56,28 +64,37 @@ has been checked and before it has been
 semantics to fix this on x86_64 would incur an unacceptable performance 
overhead
 due to return branch prediction.
 
-The instrumentation makes use of the ``gs`` segment register to reference the
-shadow call stack meaning that references to the shadow call stack do not have
-to be stored in memory. This makes it possible to implement a runtime that
-avoids exposing the address of the shadow call stack to attackers that can read
-arbitrary memory. However, attackers could still try to exploit side channels
-exposed by the operating system `[1]`_ `[2]`_ or processor `[3]`_ to discover
-the address of the shadow call stack.
+The instrumentation makes use of the ``gs`` segment register on x86_64,
+or the ``x18`` register on aarch64, to reference the shadow call stack
+meaning that references to the shadow call stack do not have to be stored in
+memory. This makes it possible to implement a runtime that avoids exposing
+the address of the shadow call stack to attackers that can read arbitrary
+memory. However, attackers could still try to exploit side channels exposed
+by the operating system `[1]`_ `[2]`_ or processor `[3]`_ to discover the
+address of the shadow call stack.
 
 .. _`[1]`: 
https://eyalitkin.wordpress.com/2017/09/01/cartography-lighting-up-the-shadows/
 .. _`[2]`: 
https://www.blackhat.com/docs/eu-16/materials/eu-16-Goktas-Bypassing-Clangs-SafeStack.pdf
 .. _`[3]`: https://www.vusec.net/projects/anc/
 
-Leaf functions are optimized to store the return address in a free register
-and avoid writing to the shadow call stack if a register is available. Very
-short leaf functions are uninstrumented if their execution is judged to be
-shorter than the race condition window intrinsic to the instrumentation.
+On x86_64, leaf functions are optimized to store the return address in a
+free register and avoid writing to the shadow call stack if a register is
+available. Very short leaf functions are uninstrumented if their execution
+is judged to be shorter than the race condition window intrinsic to the
+instrumentation.
+
+On aarch64, the architecture's call and return instructions (``bl`` and
+``ret``) operate on a register rather than the 

r327166 - Fix Clang test case.

2018-03-09 Thread Peter Collingbourne via cfe-commits
Author: pcc
Date: Fri Mar  9 11:37:28 2018
New Revision: 327166

URL: http://llvm.org/viewvc/llvm-project?rev=327166=rev
Log:
Fix Clang test case.

Modified:
cfe/trunk/test/CodeGen/thinlto-distributed-cfi-devirt.ll

Modified: cfe/trunk/test/CodeGen/thinlto-distributed-cfi-devirt.ll
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/thinlto-distributed-cfi-devirt.ll?rev=327166=327165=327166=diff
==
--- cfe/trunk/test/CodeGen/thinlto-distributed-cfi-devirt.ll (original)
+++ cfe/trunk/test/CodeGen/thinlto-distributed-cfi-devirt.ll Fri Mar  9 
11:37:28 2018
@@ -23,7 +23,7 @@
 ; Ensure that typeids are in the index.
 ; RUN: llvm-bcanalyzer -dump %t.o.thinlto.bc | FileCheck %s
 ; CHECK-LABEL: 
+; CHECK: 
 ; CHECK-LABEL: http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libcxx] r325723 - libcxx: Unbreak external thread library configuration.

2018-02-21 Thread Peter Collingbourne via cfe-commits
Author: pcc
Date: Wed Feb 21 13:36:18 2018
New Revision: 325723

URL: http://llvm.org/viewvc/llvm-project?rev=325723=rev
Log:
libcxx: Unbreak external thread library configuration.

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

Modified:
libcxx/trunk/include/__threading_support

Modified: libcxx/trunk/include/__threading_support
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__threading_support?rev=325723=325722=325723=diff
==
--- libcxx/trunk/include/__threading_support (original)
+++ libcxx/trunk/include/__threading_support Wed Feb 21 13:36:18 2018
@@ -31,6 +31,14 @@
 _LIBCPP_PUSH_MACROS
 #include <__undef_macros>
 
+#if defined(_LIBCPP_HAS_THREAD_LIBRARY_EXTERNAL) || \
+defined(_LIBCPP_BUILDING_THREAD_LIBRARY_EXTERNAL) || \
+defined(_LIBCPP_HAS_THREAD_API_WIN32)
+#define _LIBCPP_THREAD_ABI_VISIBILITY _LIBCPP_FUNC_VIS
+#else
+#define _LIBCPP_THREAD_ABI_VISIBILITY inline _LIBCPP_INLINE_VISIBILITY
+#endif
+
 #if defined(__FreeBSD__) && defined(__clang__) && 
__has_attribute(no_thread_safety_analysis)
 #define _LIBCPP_NO_THREAD_SAFETY_ANALYSIS 
__attribute__((no_thread_safety_analysis))
 #else
@@ -39,15 +47,7 @@ _LIBCPP_PUSH_MACROS
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-#if defined(_LIBCPP_HAS_THREAD_LIBRARY_EXTERNAL) || \
-defined(_LIBCPP_BUILDING_THREAD_LIBRARY_EXTERNAL)
-
-#define _LIBCPP_THREAD_ABI_VISIBILITY _LIBCPP_FUNC_VIS
-
-#elif defined(_LIBCPP_HAS_THREAD_API_PTHREAD)
-
-#define _LIBCPP_THREAD_ABI_VISIBILITY inline _LIBCPP_INLINE_VISIBILITY
-
+#if defined(_LIBCPP_HAS_THREAD_API_PTHREAD)
 // Mutex
 typedef pthread_mutex_t __libcpp_mutex_t;
 #define _LIBCPP_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
@@ -75,9 +75,6 @@ typedef pthread_key_t __libcpp_tls_key;
 
 #define _LIBCPP_TLS_DESTRUCTOR_CC
 #else
-
-#define _LIBCPP_THREAD_ABI_VISIBILITY _LIBCPP_FUNC_VIS
-
 // Mutex
 typedef void* __libcpp_mutex_t;
 #define _LIBCPP_MUTEX_INITIALIZER 0


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


r324286 - IRGen: Move vtable load after argument evaluation.

2018-02-05 Thread Peter Collingbourne via cfe-commits
Author: pcc
Date: Mon Feb  5 15:09:13 2018
New Revision: 324286

URL: http://llvm.org/viewvc/llvm-project?rev=324286=rev
Log:
IRGen: Move vtable load after argument evaluation.

This change reduces the live range of the loaded function pointer,
resulting in a slight code size decrease (~10KB in clang), and also
improves the security of CFI for virtual calls by making it less
likely that the function pointer will be spilled, and ensuring that
it is not spilled across a function call boundary.

Fixes PR35353.

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

Added:
cfe/trunk/test/CodeGenCXX/cfi-vcall-check-after-args.cpp
Modified:
cfe/trunk/lib/CodeGen/CGCXXABI.h
cfe/trunk/lib/CodeGen/CGCall.cpp
cfe/trunk/lib/CodeGen/CGCall.h
cfe/trunk/lib/CodeGen/CGExprCXX.cpp
cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp
cfe/trunk/test/CodeGenCXX/cxx2a-destroying-delete.cpp
cfe/trunk/test/CodeGenCXX/microsoft-abi-multiple-nonvirtual-inheritance.cpp
cfe/trunk/test/CodeGenCXX/microsoft-abi-virtual-inheritance.cpp

cfe/trunk/test/CodeGenCXX/microsoft-abi-vtables-multiple-nonvirtual-inheritance-this-adjustment.cpp

Modified: cfe/trunk/lib/CodeGen/CGCXXABI.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCXXABI.h?rev=324286=324285=324286=diff
==
--- cfe/trunk/lib/CodeGen/CGCXXABI.h (original)
+++ cfe/trunk/lib/CodeGen/CGCXXABI.h Mon Feb  5 15:09:13 2018
@@ -413,11 +413,10 @@ public:
 CharUnits VPtrOffset) = 0;
 
   /// Build a virtual function pointer in the ABI-specific way.
-  virtual CGCallee getVirtualFunctionPointer(CodeGenFunction ,
- GlobalDecl GD,
- Address This,
- llvm::Type *Ty,
- SourceLocation Loc) = 0;
+  virtual llvm::Value *getVirtualFunctionPointer(CodeGenFunction ,
+ GlobalDecl GD, Address This,
+ llvm::Type *Ty,
+ SourceLocation Loc) = 0;
 
   /// Emit the ABI-specific virtual destructor call.
   virtual llvm::Value *

Modified: cfe/trunk/lib/CodeGen/CGCall.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCall.cpp?rev=324286=324285=324286=diff
==
--- cfe/trunk/lib/CodeGen/CGCall.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCall.cpp Mon Feb  5 15:09:13 2018
@@ -3728,7 +3728,7 @@ RValue CodeGenFunction::EmitCall(const C
  SourceLocation Loc) {
   // FIXME: We no longer need the types from CallArgs; lift up and simplify.
 
-  assert(Callee.isOrdinary());
+  assert(Callee.isOrdinary() || Callee.isVirtual());
 
   // Handle struct-return functions by passing a pointer to the
   // location that we would like to return into.
@@ -4052,7 +4052,14 @@ RValue CodeGenFunction::EmitCall(const C
 }
   }
 
-  llvm::Value *CalleePtr = Callee.getFunctionPointer();
+  llvm::Value *CalleePtr;
+  if (Callee.isVirtual()) {
+const CallExpr *CE = Callee.getVirtualCallExpr();
+CalleePtr = CGM.getCXXABI().getVirtualFunctionPointer(
+*this, Callee.getVirtualMethodDecl(), Callee.getThisAddress(),
+Callee.getFunctionType(), CE ? CE->getLocStart() : SourceLocation());
+  } else
+CalleePtr = Callee.getFunctionPointer();
 
   // If we're using inalloca, set up that argument.
   if (ArgMemory.isValid()) {

Modified: cfe/trunk/lib/CodeGen/CGCall.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCall.h?rev=324286=324285=324286=diff
==
--- cfe/trunk/lib/CodeGen/CGCall.h (original)
+++ cfe/trunk/lib/CodeGen/CGCall.h Mon Feb  5 15:09:13 2018
@@ -18,6 +18,7 @@
 #include "CGValue.h"
 #include "EHScopeStack.h"
 #include "clang/AST/CanonicalType.h"
+#include "clang/AST/GlobalDecl.h"
 #include "clang/AST/Type.h"
 #include "llvm/IR/Value.h"
 
@@ -68,8 +69,9 @@ public:
   Invalid,
   Builtin,
   PseudoDestructor,
+  Virtual,
 
-  Last = PseudoDestructor
+  Last = Virtual
 };
 
 struct BuiltinInfoStorage {
@@ -79,12 +81,19 @@ public:
 struct PseudoDestructorInfoStorage {
   const CXXPseudoDestructorExpr *Expr;
 };
+struct VirtualInfoStorage {
+  const CallExpr *CE;
+  GlobalDecl MD;
+  Address Addr;
+  llvm::FunctionType *FTy;
+};
 
 SpecialKind KindOrFunctionPointer;
 union {
   CGCalleeInfo AbstractInfo;
   BuiltinInfoStorage BuiltinInfo;
   PseudoDestructorInfoStorage PseudoDestructorInfo;
+  VirtualInfoStorage VirtualInfo;
 };
 
 explicit CGCallee(SpecialKind 

[libcxx] r323563 - Fix the BinaryPredicate form of std::is_permutation to not rely on operator==

2018-01-26 Thread Peter Collingbourne via cfe-commits
Author: pcc
Date: Fri Jan 26 13:23:27 2018
New Revision: 323563

URL: http://llvm.org/viewvc/llvm-project?rev=323563=rev
Log:
Fix the BinaryPredicate form of std::is_permutation to not rely on operator==

According to [1], forms 2 and 4 of std::is_permutation should use the passed in
binary predicate to compare elements. operator== should only be used for forms
1 and 3 which do not take a binary predicate.

This CL fixes forms 2 and 4 which relied on operator== for some comparisons.

[1] http://en.cppreference.com/w/cpp/algorithm/is_permutation

Patch by Thomas Anderson!

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

Modified:
libcxx/trunk/include/algorithm

libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.is_permutation/is_permutation_pred.pass.cpp

Modified: libcxx/trunk/include/algorithm
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/algorithm?rev=323563=323562=323563=diff
==
--- libcxx/trunk/include/algorithm (original)
+++ libcxx/trunk/include/algorithm Fri Jan 26 13:23:27 2018
@@ -1418,7 +1418,11 @@ is_permutation(_ForwardIterator1 __first
 for (_ForwardIterator1 __i = __first1; __i != __last1; ++__i)
 {
 //  Have we already counted the number of *__i in [f1, l1)?
-if (find(__first1, __i, *__i) == __i) {
+_ForwardIterator1 __match = __first1;
+for (; __match != __i; ++__match)
+if (__pred(*__match, *__i))
+break;
+if (__match == __i) {
 // Count number of *__i in [f2, l2)
 _D1 __c2 = 0;
 for (_ForwardIterator2 __j = __first2; __j != __last2; ++__j)
@@ -1479,7 +1483,11 @@ __is_permutation(_ForwardIterator1 __fir
 for (_ForwardIterator1 __i = __first1; __i != __last1; ++__i)
 {
 //  Have we already counted the number of *__i in [f1, l1)?
-if (find(__first1, __i, *__i) == __i) {
+_ForwardIterator1 __match = __first1;
+for (; __match != __i; ++__match)
+if (__pred(*__match, *__i))
+break;
+if (__match == __i) {
 // Count number of *__i in [f2, l2)
 _D1 __c2 = 0;
 for (_ForwardIterator2 __j = __first2; __j != __last2; ++__j)

Modified: 
libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.is_permutation/is_permutation_pred.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.is_permutation/is_permutation_pred.pass.cpp?rev=323563=323562=323563=diff
==
--- 
libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.is_permutation/is_permutation_pred.pass.cpp
 (original)
+++ 
libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.is_permutation/is_permutation_pred.pass.cpp
 Fri Jan 26 13:23:27 2018
@@ -738,6 +738,30 @@ int main()
std::equal_to()) == false);
 #endif
 }
+{
+  struct S {
+  S(int i) : i_(i) {}
+  bool operator==(const S& other) = delete;
+  int i_;
+  };
+  struct eq {
+  bool operator()(const S& a, const S) { return a.i_ == b.i_; }
+  };
+  const S a[] = {S(0), S(1)};
+  const S b[] = {S(1), S(0)};
+  const unsigned sa = sizeof(a)/sizeof(a[0]);
+  assert(std::is_permutation(forward_iterator(a),
+ forward_iterator(a + sa),
+ forward_iterator(b),
+ eq()));
+#if TEST_STD_VER >= 14
+  assert(std::is_permutation(forward_iterator(a),
+ forward_iterator(a + sa),
+ forward_iterator(b),
+ forward_iterator(b + sa),
+ eq()));
+#endif
+}
 
 #if TEST_STD_VER > 17
 static_assert(test_constexpr());


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


[libcxx] r323491 - libcxx: Use vcruntime declarations for typeinfo on Windows.

2018-01-25 Thread Peter Collingbourne via cfe-commits
Author: pcc
Date: Thu Jan 25 17:22:17 2018
New Revision: 323491

URL: http://llvm.org/viewvc/llvm-project?rev=323491=rev
Log:
libcxx: Use vcruntime declarations for typeinfo on Windows.

We need to use the vcruntime declarations on Windows to avoid an
ODR violation involving rtti.obj, which provides the definition of
the runtime function implementing dynamic_cast and depends on the
vcruntime implementations of bad_cast and bad_typeid.

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

Modified:
libcxx/trunk/include/typeinfo
libcxx/trunk/src/support/runtime/exception_msvc.ipp
libcxx/trunk/src/typeinfo.cpp

Modified: libcxx/trunk/include/typeinfo
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/typeinfo?rev=323491=323490=323491=diff
==
--- libcxx/trunk/include/typeinfo (original)
+++ libcxx/trunk/include/typeinfo Thu Jan 25 17:22:17 2018
@@ -69,6 +69,10 @@ public:
 #pragma GCC system_header
 #endif
 
+#if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_NO_VCRUNTIME)
+#include 
+#else
+
 #if !defined(_LIBCPP_ABI_MICROSOFT)
 #if defined(_LIBCPP_NONUNIQUE_RTTI_BIT)
 #define _LIBCPP_HAS_NONUNIQUE_TYPEINFO
@@ -219,6 +223,8 @@ public:
 
 }  // std
 
+#endif // defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_NO_VCRUNTIME)
+
 _LIBCPP_BEGIN_NAMESPACE_STD
 _LIBCPP_NORETURN inline _LIBCPP_ALWAYS_INLINE
 void __throw_bad_cast()

Modified: libcxx/trunk/src/support/runtime/exception_msvc.ipp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/support/runtime/exception_msvc.ipp?rev=323491=323490=323491=diff
==
--- libcxx/trunk/src/support/runtime/exception_msvc.ipp (original)
+++ libcxx/trunk/src/support/runtime/exception_msvc.ipp Thu Jan 25 17:22:17 2018
@@ -97,6 +97,7 @@ bad_array_length::what() const _NOEXCEPT
 return "bad_array_length";
 }
 
+#if defined(_LIBCPP_NO_VCRUNTIME)
 bad_cast::bad_cast() _NOEXCEPT
 {
 }
@@ -125,7 +126,6 @@ bad_typeid::what() const _NOEXCEPT
   return "std::bad_typeid";
 }
 
-#if defined(_LIBCPP_NO_VCRUNTIME)
 exception::~exception() _NOEXCEPT
 {
 }

Modified: libcxx/trunk/src/typeinfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/typeinfo.cpp?rev=323491=323490=323491=diff
==
--- libcxx/trunk/src/typeinfo.cpp (original)
+++ libcxx/trunk/src/typeinfo.cpp Thu Jan 25 17:22:17 2018
@@ -9,7 +9,7 @@
 
 #include "typeinfo"
 
-#if defined(_LIBCPP_ABI_MICROSOFT)
+#if defined(_LIBCPP_ABI_MICROSOFT) && defined(_LIBCPP_NO_VCRUNTIME)
 #include 
 
 int std::type_info::__compare(const type_info &__rhs) const _NOEXCEPT {
@@ -49,7 +49,8 @@ size_t std::type_info::hash_code() const
 // FIXME: Remove __APPLE__ default here once buildit is gone.
 // FIXME: Remove the _LIBCPP_BUILDING_HAS_NO_ABI_LIBRARY configuration.
 #if (!defined(LIBCXX_BUILDING_LIBCXXABI) && !defined(LIBCXXRT) &&  
\
- !defined(__GLIBCXX__) && !defined(__APPLE__)) ||  
\
+ !defined(__GLIBCXX__) && !defined(__APPLE__) &&   
\
+ !(defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_NO_VCRUNTIME))) ||   
\
 defined(_LIBCPP_BUILDING_HAS_NO_ABI_LIBRARY)
 std::type_info::~type_info()
 {


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


[libcxx] r323490 - libcxx: Move #include_next out of header guard in wrapper header.

2018-01-25 Thread Peter Collingbourne via cfe-commits
Author: pcc
Date: Thu Jan 25 17:19:23 2018
New Revision: 323490

URL: http://llvm.org/viewvc/llvm-project?rev=323490=rev
Log:
libcxx: Move #include_next  out of header guard in wrapper header.

Code on Windows expects to be able to do:

 #define _USE_MATH_DEFINES
 #include 

and receive the definitions of mathematical constants, even if 
has previously been included. To support this scenario, re-include
 every time the wrapper header is included.

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

Added:
libcxx/trunk/test/libcxx/depr/depr.c.headers/math_h.sh.cpp
Modified:
libcxx/trunk/include/math.h

Modified: libcxx/trunk/include/math.h
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/math.h?rev=323490=323489=323490=diff
==
--- libcxx/trunk/include/math.h (original)
+++ libcxx/trunk/include/math.h Thu Jan 25 17:19:23 2018
@@ -8,6 +8,16 @@
 //
 
//===--===//
 
+// This include lives outside the header guard in order to support an MSVC
+// extension which allows users to do:
+//
+// #define _USE_MATH_DEFINES
+// #include 
+//
+// and receive the definitions of mathematical constants, even if 
+// has previously been included.
+#include_next 
+
 #ifndef _LIBCPP_MATH_H
 #define _LIBCPP_MATH_H
 
@@ -298,8 +308,6 @@ long doubletruncl(long double x);
 #pragma GCC system_header
 #endif
 
-#include_next 
-
 #ifdef __cplusplus
 
 // We support including .h headers inside 'extern "C"' contexts, so switch

Added: libcxx/trunk/test/libcxx/depr/depr.c.headers/math_h.sh.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/libcxx/depr/depr.c.headers/math_h.sh.cpp?rev=323490=auto
==
--- libcxx/trunk/test/libcxx/depr/depr.c.headers/math_h.sh.cpp (added)
+++ libcxx/trunk/test/libcxx/depr/depr.c.headers/math_h.sh.cpp Thu Jan 25 
17:19:23 2018
@@ -0,0 +1,23 @@
+//===--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+
+// RUN: %compile -fsyntax-only
+
+#ifdef _MSC_VER
+
+#include 
+
+#define _USE_MATH_DEFINES
+#include 
+
+#ifndef M_PI
+#error M_PI not defined
+#endif
+
+#endif


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


[libcxxabi] r323397 - [libc++abi] Fix unused function when building with LIBCXXABI_SILENT_TERMINATE

2018-01-24 Thread Peter Collingbourne via cfe-commits
Author: pcc
Date: Wed Jan 24 17:38:43 2018
New Revision: 323397

URL: http://llvm.org/viewvc/llvm-project?rev=323397=rev
Log:
[libc++abi] Fix unused function when building with LIBCXXABI_SILENT_TERMINATE

This fixes:
src/cxa_default_handlers.cpp:25:13: error: unused function 
'demangling_terminate_handler' [-Werror,-Wunused-function]

Patch by Thomas Anderson!

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

Modified:
libcxxabi/trunk/src/cxa_default_handlers.cpp

Modified: libcxxabi/trunk/src/cxa_default_handlers.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/src/cxa_default_handlers.cpp?rev=323397=323396=323397=diff
==
--- libcxxabi/trunk/src/cxa_default_handlers.cpp (original)
+++ libcxxabi/trunk/src/cxa_default_handlers.cpp Wed Jan 24 17:38:43 2018
@@ -19,6 +19,7 @@
 #include "cxa_exception.hpp"
 #include "private_typeinfo.h"
 
+#if !defined(LIBCXXABI_SILENT_TERMINATE)
 static const char* cause = "uncaught";
 
 __attribute__((noreturn))
@@ -84,7 +85,6 @@ static void demangling_unexpected_handle
 std::terminate();
 }
 
-#if !defined(LIBCXXABI_SILENT_TERMINATE)
 static std::terminate_handler default_terminate_handler = 
demangling_terminate_handler;
 static std::terminate_handler default_unexpected_handler = 
demangling_unexpected_handler;
 #else


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


r323362 - IRGen: Emit an inline implementation of __builtin_wmemcmp on MSVCRT platforms.

2018-01-24 Thread Peter Collingbourne via cfe-commits
Author: pcc
Date: Wed Jan 24 10:59:58 2018
New Revision: 323362

URL: http://llvm.org/viewvc/llvm-project?rev=323362=rev
Log:
IRGen: Emit an inline implementation of __builtin_wmemcmp on MSVCRT platforms.

The MSVC runtime library does not provide a definition of wmemcmp,
so we need an inline implementation.

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

Added:
cfe/trunk/test/CodeGen/wmemcmp.c
Modified:
cfe/trunk/lib/CodeGen/CGBuiltin.cpp

Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=323362=323361=323362=diff
==
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Wed Jan 24 10:59:58 2018
@@ -1741,6 +1741,63 @@ RValue CodeGenFunction::EmitBuiltinExpr(
 Builder.CreateMemSet(Dest, ByteVal, SizeVal, false);
 return RValue::get(Dest.getPointer());
   }
+  case Builtin::BI__builtin_wmemcmp: {
+// The MSVC runtime library does not provide a definition of wmemcmp, so we
+// need an inline implementation.
+if (!getTarget().getTriple().isOSMSVCRT())
+  break;
+
+llvm::Type *WCharTy = ConvertType(getContext().WCharTy);
+
+Value *Dst = EmitScalarExpr(E->getArg(0));
+Value *Src = EmitScalarExpr(E->getArg(1));
+Value *Size = EmitScalarExpr(E->getArg(2));
+
+BasicBlock *Entry = Builder.GetInsertBlock();
+BasicBlock *CmpGT = createBasicBlock("wmemcmp.gt");
+BasicBlock *CmpLT = createBasicBlock("wmemcmp.lt");
+BasicBlock *Next = createBasicBlock("wmemcmp.next");
+BasicBlock *Exit = createBasicBlock("wmemcmp.exit");
+Value *SizeEq0 = Builder.CreateICmpEQ(Size, ConstantInt::get(SizeTy, 0));
+Builder.CreateCondBr(SizeEq0, Exit, CmpGT);
+
+EmitBlock(CmpGT);
+PHINode *DstPhi = Builder.CreatePHI(Dst->getType(), 2);
+DstPhi->addIncoming(Dst, Entry);
+PHINode *SrcPhi = Builder.CreatePHI(Src->getType(), 2);
+SrcPhi->addIncoming(Src, Entry);
+PHINode *SizePhi = Builder.CreatePHI(SizeTy, 2);
+SizePhi->addIncoming(Size, Entry);
+CharUnits WCharAlign =
+getContext().getTypeAlignInChars(getContext().WCharTy);
+Value *DstCh = Builder.CreateAlignedLoad(WCharTy, DstPhi, WCharAlign);
+Value *SrcCh = Builder.CreateAlignedLoad(WCharTy, SrcPhi, WCharAlign);
+Value *DstGtSrc = Builder.CreateICmpUGT(DstCh, SrcCh);
+Builder.CreateCondBr(DstGtSrc, Exit, CmpLT);
+
+EmitBlock(CmpLT);
+Value *DstLtSrc = Builder.CreateICmpULT(DstCh, SrcCh);
+Builder.CreateCondBr(DstLtSrc, Exit, Next);
+
+EmitBlock(Next);
+Value *NextDst = Builder.CreateConstInBoundsGEP1_32(WCharTy, DstPhi, 1);
+Value *NextSrc = Builder.CreateConstInBoundsGEP1_32(WCharTy, SrcPhi, 1);
+Value *NextSize = Builder.CreateSub(SizePhi, ConstantInt::get(SizeTy, 1));
+Value *NextSizeEq0 =
+Builder.CreateICmpEQ(NextSize, ConstantInt::get(SizeTy, 0));
+Builder.CreateCondBr(NextSizeEq0, Exit, CmpGT);
+DstPhi->addIncoming(NextDst, Next);
+SrcPhi->addIncoming(NextSrc, Next);
+SizePhi->addIncoming(NextSize, Next);
+
+EmitBlock(Exit);
+PHINode *Ret = Builder.CreatePHI(IntTy, 4);
+Ret->addIncoming(ConstantInt::get(IntTy, 0), Entry);
+Ret->addIncoming(ConstantInt::get(IntTy, 1), CmpGT);
+Ret->addIncoming(ConstantInt::get(IntTy, -1), CmpLT);
+Ret->addIncoming(ConstantInt::get(IntTy, 0), Next);
+return RValue::get(Ret);
+  }
   case Builtin::BI__builtin_dwarf_cfa: {
 // The offset in bytes from the first argument to the CFA.
 //

Added: cfe/trunk/test/CodeGen/wmemcmp.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/wmemcmp.c?rev=323362=auto
==
--- cfe/trunk/test/CodeGen/wmemcmp.c (added)
+++ cfe/trunk/test/CodeGen/wmemcmp.c Wed Jan 24 10:59:58 2018
@@ -0,0 +1,37 @@
+// RUN: %clang_cc1 %s -triple x86_64-pc-win32 -emit-llvm -o - | FileCheck %s
+
+typedef __SIZE_TYPE__ size_t;
+typedef __WCHAR_TYPE__ wchar_t;
+
+int wmemcmp_test(const wchar_t *s1, const wchar_t *s2, size_t n) {
+  // CHECK: [[S1:%.*]] = load
+  // CHECK: [[S2:%.*]] = load
+  // CHECK: [[N:%.*]] = load
+  // CHECK: [[N0:%.*]] = icmp eq i64 [[N]], 0
+  // CHECK: br i1 [[N0]], label %[[EXIT:.*]], label %[[GT:.*]]
+
+  // CHECK: [[GT]]:
+  // CHECK: [[S1P:%.*]] = phi i16* [ [[S1]], %[[ENTRY:.*]] ], [ [[S1N:.*]], 
%[[NEXT:.*]] ]
+  // CHECK: [[S2P:%.*]] = phi i16* [ [[S2]], %[[ENTRY]] ], [ [[S2N:.*]], 
%[[NEXT]] ]
+  // CHECK: [[NP:%.*]] = phi i64 [ [[N]], %[[ENTRY]] ], [ [[NN:.*]], %[[NEXT]] 
]
+  // CHECK: [[S1L:%.*]] = load i16, i16* [[S1P]], align 2
+  // CHECK: [[S2L:%.*]] = load i16, i16* [[S2P]], align 2
+  // CHECK: [[CMPGT:%.*]] = icmp ugt i16 [[S1L]], [[S2L]]
+  // CHECK: br i1 [[CMPGT]], label %[[EXIT]], label %[[LT:.*]]
+
+  // CHECK: [[LT]]:
+  // CHECK: [[CMPLT:%.*]] = icmp ult i16 [[S1L]], [[S2L]]
+  // CHECK: br 

[libcxx] r323300 - libcxx: Allow auto-linking to be disabled with a macro.

2018-01-23 Thread Peter Collingbourne via cfe-commits
Author: pcc
Date: Tue Jan 23 20:30:19 2018
New Revision: 323300

URL: http://llvm.org/viewvc/llvm-project?rev=323300=rev
Log:
libcxx: Allow auto-linking to be disabled with a macro.

Some users may have a custom build system which gives a different
name to the libc++ archive (or does not create an archive at all,
instead passing the object files directly to the linker). Give those
users a way to disable auto-linking.

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

Modified:
libcxx/trunk/include/__config

Modified: libcxx/trunk/include/__config
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__config?rev=323300=323299=323300=diff
==
--- libcxx/trunk/include/__config (original)
+++ libcxx/trunk/include/__config Tue Jan 23 20:30:19 2018
@@ -1285,13 +1285,15 @@ _LIBCPP_FUNC_VIS extern "C" void __sanit
 # endif
 #endif // defined(_LIBCPP_HAS_NO_PRAGMA_PUSH_POP_MACRO)
 
-#if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_BUILDING_LIBRARY)
-# if defined(_DLL)
+#ifndef _LIBCPP_NO_AUTO_LINK
+# if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_BUILDING_LIBRARY)
+#  if defined(_DLL)
 #   pragma comment(lib, "c++.lib")
-# else
+#  else
 #   pragma comment(lib, "libc++.lib")
-# endif
-#endif // defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_BUILDING_LIBRARY)
+#  endif
+# endif // defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_BUILDING_LIBRARY)
+#endif // _LIBCPP_NO_AUTO_LINK
 
 #endif // __cplusplus
 


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


[libcxx] r323237 - libcxx: Rename vasprintf function to __libcpp_vasprintf.

2018-01-23 Thread Peter Collingbourne via cfe-commits
Author: pcc
Date: Tue Jan 23 10:53:33 2018
New Revision: 323237

URL: http://llvm.org/viewvc/llvm-project?rev=323237=rev
Log:
libcxx: Rename vasprintf function to __libcpp_vasprintf.

The language standard does not define a function with this name,
so it is part of the user's namespace. This change fixes a duplicate
symbol error that occurs when a user attempts to define a function
with this name.

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

Modified:
libcxx/trunk/include/stdio.h
libcxx/trunk/src/support/win32/locale_win32.cpp
libcxx/trunk/src/support/win32/support.cpp

Modified: libcxx/trunk/include/stdio.h
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/stdio.h?rev=323237=323236=323237=diff
==
--- libcxx/trunk/include/stdio.h (original)
+++ libcxx/trunk/include/stdio.h Tue Jan 23 10:53:33 2018
@@ -109,13 +109,6 @@ void perror(const char* s);
 
 #ifdef __cplusplus
 
-// snprintf
-#if defined(_LIBCPP_MSVCRT_LIKE)
-extern "C" {
-int vasprintf(char **sptr, const char *__restrict fmt, va_list ap);
-}
-#endif
-
 #undef getc
 #undef putc
 #undef clearerr

Modified: libcxx/trunk/src/support/win32/locale_win32.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/support/win32/locale_win32.cpp?rev=323237=323236=323237=diff
==
--- libcxx/trunk/src/support/win32/locale_win32.cpp (original)
+++ libcxx/trunk/src/support/win32/locale_win32.cpp Tue Jan 23 10:53:33 2018
@@ -13,6 +13,8 @@
 #include 
 #include 
 
+int __libcpp_vasprintf(char **sptr, const char *__restrict fmt, va_list ap);
+
 using std::__libcpp_locale_guard;
 
 // FIXME: base currently unused. Needs manual work to construct the new locale
@@ -105,7 +107,7 @@ int asprintf_l( char **ret, locale_t loc
 int vasprintf_l( char **ret, locale_t loc, const char *format, va_list ap )
 {
 __libcpp_locale_guard __current(loc);
-return vasprintf( ret, format, ap );
+return __libcpp_vasprintf( ret, format, ap );
 }
 
 #if !defined(_LIBCPP_MSVCRT)

Modified: libcxx/trunk/src/support/win32/support.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/support/win32/support.cpp?rev=323237=323236=323237=diff
==
--- libcxx/trunk/src/support/win32/support.cpp (original)
+++ libcxx/trunk/src/support/win32/support.cpp Tue Jan 23 10:53:33 2018
@@ -19,7 +19,7 @@
 // Like sprintf, but when return value >= 0 it returns
 // a pointer to a malloc'd string in *sptr.
 // If return >= 0, use free to delete *sptr.
-int vasprintf( char **sptr, const char *__restrict format, va_list ap )
+int __libcpp_vasprintf( char **sptr, const char *__restrict format, va_list ap 
)
 {
 *sptr = NULL;
 // Query the count required.


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


[libcxx] r323170 - libcxx: Provide overloads for basic_filebuf::open() et al that take wchar_t* filenames on Windows.

2018-01-22 Thread Peter Collingbourne via cfe-commits
Author: pcc
Date: Mon Jan 22 18:07:27 2018
New Revision: 323170

URL: http://llvm.org/viewvc/llvm-project?rev=323170=rev
Log:
libcxx: Provide overloads for basic_filebuf::open() et al that take wchar_t* 
filenames on Windows.

This is an MSVC standard library extension. It seems like a reasonable
enough extension to me because wchar_t* is the native format for
filenames on that platform.

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

Added:
libcxx/trunk/test/libcxx/input.output/file.streams/fstreams/fstream.cons/

libcxx/trunk/test/libcxx/input.output/file.streams/fstreams/fstream.cons/wchar_pointer.pass.cpp
libcxx/trunk/test/libcxx/input.output/file.streams/fstreams/fstream.members/

libcxx/trunk/test/libcxx/input.output/file.streams/fstreams/fstream.members/open_wchar_pointer.pass.cpp
libcxx/trunk/test/libcxx/input.output/file.streams/fstreams/ifstream.cons/

libcxx/trunk/test/libcxx/input.output/file.streams/fstreams/ifstream.cons/test.dat

libcxx/trunk/test/libcxx/input.output/file.streams/fstreams/ifstream.cons/wchar_pointer.pass.cpp

libcxx/trunk/test/libcxx/input.output/file.streams/fstreams/ifstream.members/

libcxx/trunk/test/libcxx/input.output/file.streams/fstreams/ifstream.members/open_wchar_pointer.pass.cpp

libcxx/trunk/test/libcxx/input.output/file.streams/fstreams/ifstream.members/test.dat
libcxx/trunk/test/libcxx/input.output/file.streams/fstreams/ofstream.cons/

libcxx/trunk/test/libcxx/input.output/file.streams/fstreams/ofstream.cons/wchar_pointer.pass.cpp

libcxx/trunk/test/libcxx/input.output/file.streams/fstreams/ofstream.members/

libcxx/trunk/test/libcxx/input.output/file.streams/fstreams/ofstream.members/open_wchar_pointer.pass.cpp
Modified:
libcxx/trunk/include/__config
libcxx/trunk/include/fstream
libcxx/trunk/test/support/platform_support.h

Modified: libcxx/trunk/include/__config
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__config?rev=323170=323169=323170=diff
==
--- libcxx/trunk/include/__config (original)
+++ libcxx/trunk/include/__config Mon Jan 22 18:07:27 2018
@@ -247,6 +247,7 @@
 #  if (defined(_M_AMD64) || defined(__x86_64__)) || (defined(_M_ARM) || 
defined(__arm__))
 #define _LIBCPP_HAS_BITSCAN64
 #  endif
+#  define _LIBCPP_HAS_OPEN_WITH_WCHAR
 # if defined(_LIBCPP_MSVCRT)
 #   define _LIBCPP_HAS_QUICK_EXIT
 # endif

Modified: libcxx/trunk/include/fstream
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/fstream?rev=323170=323169=323170=diff
==
--- libcxx/trunk/include/fstream (original)
+++ libcxx/trunk/include/fstream Mon Jan 22 18:07:27 2018
@@ -212,6 +212,9 @@ public:
 bool is_open() const;
 #ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE
 basic_filebuf* open(const char* __s, ios_base::openmode __mode);
+#ifdef _LIBCPP_HAS_OPEN_WITH_WCHAR
+basic_filebuf* open(const wchar_t* __s, ios_base::openmode __mode);
+#endif
 _LIBCPP_INLINE_VISIBILITY
 basic_filebuf* open(const string& __s, ios_base::openmode __mode);
 #endif
@@ -551,6 +554,90 @@ basic_filebuf<_CharT, _Traits>::open(con
 return __rt;
 }
 
+#ifdef _LIBCPP_HAS_OPEN_WITH_WCHAR
+// This is basically the same as the char* overload except that it uses _wfopen
+// and long mode strings.
+template 
+basic_filebuf<_CharT, _Traits>*
+basic_filebuf<_CharT, _Traits>::open(const wchar_t* __s, ios_base::openmode 
__mode)
+{
+basic_filebuf<_CharT, _Traits>* __rt = 0;
+if (__file_ == 0)
+{
+__rt = this;
+const wchar_t* __mdstr;
+switch (__mode & ~ios_base::ate)
+{
+case ios_base::out:
+case ios_base::out | ios_base::trunc:
+__mdstr = L"w";
+break;
+case ios_base::out | ios_base::app:
+case ios_base::app:
+__mdstr = L"a";
+break;
+case ios_base::in:
+__mdstr = L"r";
+break;
+case ios_base::in | ios_base::out:
+__mdstr = L"r+";
+break;
+case ios_base::in | ios_base::out | ios_base::trunc:
+__mdstr = L"w+";
+break;
+case ios_base::in | ios_base::out | ios_base::app:
+case ios_base::in | ios_base::app:
+__mdstr = L"a+";
+break;
+case ios_base::out | ios_base::binary:
+case ios_base::out | ios_base::trunc | ios_base::binary:
+__mdstr = L"wb";
+break;
+case ios_base::out | ios_base::app | ios_base::binary:
+case ios_base::app | ios_base::binary:
+__mdstr = L"ab";
+break;
+case ios_base::in | ios_base::binary:
+__mdstr = L"rb";
+break;
+case ios_base::in | ios_base::out | ios_base::binary:
+__mdstr = L"r+b";
+break;
+case ios_base::in | 

[libcxx] r323169 - libcxx: Move Windows threading support into a .cpp file.

2018-01-22 Thread Peter Collingbourne via cfe-commits
Author: pcc
Date: Mon Jan 22 17:59:43 2018
New Revision: 323169

URL: http://llvm.org/viewvc/llvm-project?rev=323169=rev
Log:
libcxx: Move Windows threading support into a .cpp file.

This allows us to avoid polluting the namespace of users of 
with the definitions in windows.h.

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

Added:
libcxx/trunk/src/support/win32/thread_win32.cpp
Modified:
libcxx/trunk/include/__threading_support

Modified: libcxx/trunk/include/__threading_support
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__threading_support?rev=323169=323168=323169=diff
==
--- libcxx/trunk/include/__threading_support (original)
+++ libcxx/trunk/include/__threading_support Mon Jan 22 17:59:43 2018
@@ -26,23 +26,11 @@
 #if defined(_LIBCPP_HAS_THREAD_API_PTHREAD)
 # include 
 # include 
-#elif defined(_LIBCPP_HAS_THREAD_API_WIN32)
-#include 
-#include 
-#include 
 #endif
 
 _LIBCPP_PUSH_MACROS
 #include <__undef_macros>
 
-
-#if defined(_LIBCPP_HAS_THREAD_LIBRARY_EXTERNAL) || \
-defined(_LIBCPP_BUILDING_THREAD_LIBRARY_EXTERNAL)
-#define _LIBCPP_THREAD_ABI_VISIBILITY _LIBCPP_FUNC_VIS
-#else
-#define _LIBCPP_THREAD_ABI_VISIBILITY inline _LIBCPP_INLINE_VISIBILITY
-#endif
-
 #if defined(__FreeBSD__) && defined(__clang__) && 
__has_attribute(no_thread_safety_analysis)
 #define _LIBCPP_NO_THREAD_SAFETY_ANALYSIS 
__attribute__((no_thread_safety_analysis))
 #else
@@ -51,7 +39,15 @@ _LIBCPP_PUSH_MACROS
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-#if defined(_LIBCPP_HAS_THREAD_API_PTHREAD)
+#if defined(_LIBCPP_HAS_THREAD_LIBRARY_EXTERNAL) || \
+defined(_LIBCPP_BUILDING_THREAD_LIBRARY_EXTERNAL)
+
+#define _LIBCPP_THREAD_ABI_VISIBILITY _LIBCPP_FUNC_VIS
+
+#elif defined(_LIBCPP_HAS_THREAD_API_PTHREAD)
+
+#define _LIBCPP_THREAD_ABI_VISIBILITY inline _LIBCPP_INLINE_VISIBILITY
+
 // Mutex
 typedef pthread_mutex_t __libcpp_mutex_t;
 #define _LIBCPP_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
@@ -79,32 +75,41 @@ typedef pthread_key_t __libcpp_tls_key;
 
 #define _LIBCPP_TLS_DESTRUCTOR_CC
 #else
+
+#define _LIBCPP_THREAD_ABI_VISIBILITY _LIBCPP_FUNC_VIS
+
 // Mutex
-typedef SRWLOCK __libcpp_mutex_t;
-#define _LIBCPP_MUTEX_INITIALIZER SRWLOCK_INIT
+typedef void* __libcpp_mutex_t;
+#define _LIBCPP_MUTEX_INITIALIZER 0
 
-typedef CRITICAL_SECTION __libcpp_recursive_mutex_t;
+#if defined(_M_IX86) || defined(__i386__) || defined(_M_ARM) || 
defined(__arm__)
+typedef void* __libcpp_recursive_mutex_t[6];
+#elif defined(_M_AMD64) || defined(__x86_64__) || defined(_M_ARM64) || 
defined(__aarch64__)
+typedef void* __libcpp_recursive_mutex_t[5];
+#else
+# error Unsupported architecture
+#endif
 
 // Condition Variable
-typedef CONDITION_VARIABLE __libcpp_condvar_t;
-#define _LIBCPP_CONDVAR_INITIALIZER CONDITION_VARIABLE_INIT
+typedef void* __libcpp_condvar_t;
+#define _LIBCPP_CONDVAR_INITIALIZER 0
 
 // Execute Once
-typedef INIT_ONCE __libcpp_exec_once_flag;
-#define _LIBCPP_EXEC_ONCE_INITIALIZER INIT_ONCE_STATIC_INIT
+typedef void* __libcpp_exec_once_flag;
+#define _LIBCPP_EXEC_ONCE_INITIALIZER 0
 
 // Thread ID
-typedef DWORD __libcpp_thread_id;
+typedef long __libcpp_thread_id;
 
 // Thread
 #define _LIBCPP_NULL_THREAD 0U
 
-typedef HANDLE __libcpp_thread_t;
+typedef void* __libcpp_thread_t;
 
 // Thread Local Storage
-typedef DWORD __libcpp_tls_key;
+typedef long __libcpp_tls_key;
 
-#define _LIBCPP_TLS_DESTRUCTOR_CC WINAPI
+#define _LIBCPP_TLS_DESTRUCTOR_CC __stdcall
 #endif
 
 // Mutex
@@ -201,10 +206,9 @@ void *__libcpp_tls_get(__libcpp_tls_key
 _LIBCPP_THREAD_ABI_VISIBILITY
 int __libcpp_tls_set(__libcpp_tls_key __key, void *__p);
 
-#if !defined(_LIBCPP_HAS_THREAD_LIBRARY_EXTERNAL) || \
-defined(_LIBCPP_BUILDING_THREAD_LIBRARY_EXTERNAL)
-
-#if defined(_LIBCPP_HAS_THREAD_API_PTHREAD)
+#if (!defined(_LIBCPP_HAS_THREAD_LIBRARY_EXTERNAL) || \
+ defined(_LIBCPP_BUILDING_THREAD_LIBRARY_EXTERNAL)) && \
+defined(_LIBCPP_HAS_THREAD_API_PTHREAD)
 
 int __libcpp_recursive_mutex_init(__libcpp_recursive_mutex_t *__m)
 {
@@ -390,244 +394,6 @@ int __libcpp_tls_set(__libcpp_tls_key __
 return pthread_setspecific(__key, __p);
 }
 
-#elif defined(_LIBCPP_HAS_THREAD_API_WIN32)
-
-// Mutex
-int __libcpp_recursive_mutex_init(__libcpp_recursive_mutex_t *__m)
-{
-  InitializeCriticalSection(__m);
-  return 0;
-}
-
-int __libcpp_recursive_mutex_lock(__libcpp_recursive_mutex_t *__m)
-{
-  EnterCriticalSection(__m);
-  return 0;
-}
-
-bool __libcpp_recursive_mutex_trylock(__libcpp_recursive_mutex_t *__m)
-{
-  return TryEnterCriticalSection(__m) != 0;
-}
-
-int __libcpp_recursive_mutex_unlock(__libcpp_recursive_mutex_t *__m)
-{
-  LeaveCriticalSection(__m);
-  return 0;
-}
-
-int __libcpp_recursive_mutex_destroy(__libcpp_recursive_mutex_t *__m)
-{
-  DeleteCriticalSection(__m);
-  return 0;
-}
-
-int __libcpp_mutex_lock(__libcpp_mutex_t *__m)
-{
-  AcquireSRWLockExclusive(__m);
-  return 0;
-}
-
-bool 

[libcxx] r322794 - libcxx: Define set_unexpected, _get_unexpected and __uncaught_exceptions without dllimport.

2018-01-17 Thread Peter Collingbourne via cfe-commits
Author: pcc
Date: Wed Jan 17 16:33:35 2018
New Revision: 322794

URL: http://llvm.org/viewvc/llvm-project?rev=322794=rev
Log:
libcxx: Define set_unexpected, _get_unexpected and __uncaught_exceptions 
without dllimport.

It turns out that the MSVC headers define these functions without
dllimport even when compiling with /MD. This change fixes the resulting
compile-time error.

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

Modified:
libcxx/trunk/src/support/runtime/exception_msvc.ipp

Modified: libcxx/trunk/src/support/runtime/exception_msvc.ipp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/support/runtime/exception_msvc.ipp?rev=322794=322793=322794=diff
==
--- libcxx/trunk/src/support/runtime/exception_msvc.ipp (original)
+++ libcxx/trunk/src/support/runtime/exception_msvc.ipp Wed Jan 17 16:33:35 2018
@@ -22,11 +22,11 @@ _LIBCPP_CRT_FUNC terminate_handler __cde
 _LIBCPP_CRT_FUNC terminate_handler __cdecl _get_terminate();
 
 typedef void (__cdecl* unexpected_handler)();
-_LIBCPP_CRT_FUNC unexpected_handler __cdecl set_unexpected(
+unexpected_handler __cdecl set_unexpected(
 unexpected_handler _NewUnexpectedHandler) throw();
-_LIBCPP_CRT_FUNC unexpected_handler __cdecl _get_unexpected();
+unexpected_handler __cdecl _get_unexpected();
 
-_LIBCPP_CRT_FUNC int __cdecl __uncaught_exceptions();
+int __cdecl __uncaught_exceptions();
 }
 
 namespace std {


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


[libcxx] r322744 - libcxx: Disable CFI in function std::get_temporary_buffer.

2018-01-17 Thread Peter Collingbourne via cfe-commits
Author: pcc
Date: Wed Jan 17 11:32:35 2018
New Revision: 322744

URL: http://llvm.org/viewvc/llvm-project?rev=322744=rev
Log:
libcxx: Disable CFI in function std::get_temporary_buffer.

The specification of this function mandates a cast to uninitialized
T*, which is forbidden under CFI.

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

Modified:
libcxx/trunk/include/memory

Modified: libcxx/trunk/include/memory
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/memory?rev=322744=322743=322744=diff
==
--- libcxx/trunk/include/memory (original)
+++ libcxx/trunk/include/memory Wed Jan 17 11:32:35 2018
@@ -1992,6 +1992,7 @@ public:
 };
 
 template 
+_LIBCPP_NO_CFI
 pair<_Tp*, ptrdiff_t>
 get_temporary_buffer(ptrdiff_t __n) _NOEXCEPT
 {


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


[libcxx] r322617 - libcxx: Stop using private MSVC macros in the exception implementation.

2018-01-16 Thread Peter Collingbourne via cfe-commits
Author: pcc
Date: Tue Jan 16 20:37:04 2018
New Revision: 322617

URL: http://llvm.org/viewvc/llvm-project?rev=322617=rev
Log:
libcxx: Stop using private MSVC macros in the exception implementation.

Inline the provided "fallback" definitions (which seem to always be
taken) that expand to __cdecl into users. The fallback definitions
for the *CRTIMP* macros were wrong in the case where the CRT is being
linked statically, so define our own macro as a replacement.

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

Modified:
libcxx/trunk/include/__config
libcxx/trunk/src/support/runtime/exception_msvc.ipp
libcxx/trunk/src/support/runtime/exception_pointer_msvc.ipp

Modified: libcxx/trunk/include/__config
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__config?rev=322617=322616=322617=diff
==
--- libcxx/trunk/include/__config (original)
+++ libcxx/trunk/include/__config Tue Jan 16 20:37:04 2018
@@ -626,6 +626,12 @@ namespace std {
 #endif // _LIBCPP_COMPILER_[CLANG|GCC|MSVC|IBM]
 
 #if defined(_LIBCPP_OBJECT_FORMAT_COFF)
+#ifdef _DLL
+# define _LIBCPP_CRT_FUNC __declspec(dllimport)
+#else
+# define _LIBCPP_CRT_FUNC
+#endif
+
 #if defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
 # define _LIBCPP_DLL_VIS
 # define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS

Modified: libcxx/trunk/src/support/runtime/exception_msvc.ipp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/support/runtime/exception_msvc.ipp?rev=322617=322616=322617=diff
==
--- libcxx/trunk/src/support/runtime/exception_msvc.ipp (original)
+++ libcxx/trunk/src/support/runtime/exception_msvc.ipp Tue Jan 16 20:37:04 2018
@@ -15,30 +15,18 @@
 #include 
 #include 
 
-#if !defined(_ACRTIMP)
-#define _ACRTIMP __declspec(dllimport)
-#endif
-
-#if !defined(_VCRTIMP)
-#define _VCRTIMP __declspec(dllimport)
-#endif
-
-#if !defined(__CRTDECL)
-#define __CRTDECL __cdecl
-#endif
-
 extern "C" {
-typedef void (__CRTDECL* terminate_handler)();
-_ACRTIMP terminate_handler __cdecl set_terminate(
+typedef void (__cdecl* terminate_handler)();
+_LIBCPP_CRT_FUNC terminate_handler __cdecl set_terminate(
 terminate_handler _NewTerminateHandler) throw();
-_ACRTIMP terminate_handler __cdecl _get_terminate();
+_LIBCPP_CRT_FUNC terminate_handler __cdecl _get_terminate();
 
-typedef void (__CRTDECL* unexpected_handler)();
-_VCRTIMP unexpected_handler __cdecl set_unexpected(
+typedef void (__cdecl* unexpected_handler)();
+_LIBCPP_CRT_FUNC unexpected_handler __cdecl set_unexpected(
 unexpected_handler _NewUnexpectedHandler) throw();
-_VCRTIMP unexpected_handler __cdecl _get_unexpected();
+_LIBCPP_CRT_FUNC unexpected_handler __cdecl _get_unexpected();
 
-_VCRTIMP int __cdecl __uncaught_exceptions();
+_LIBCPP_CRT_FUNC int __cdecl __uncaught_exceptions();
 }
 
 namespace std {

Modified: libcxx/trunk/src/support/runtime/exception_pointer_msvc.ipp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/support/runtime/exception_pointer_msvc.ipp?rev=322617=322616=322617=diff
==
--- libcxx/trunk/src/support/runtime/exception_pointer_msvc.ipp (original)
+++ libcxx/trunk/src/support/runtime/exception_pointer_msvc.ipp Tue Jan 16 
20:37:04 2018
@@ -11,30 +11,16 @@
 #include 
 #include 
 
-#if !defined(_CRTIMP2_PURE)
-#define _CRTIMP2_PURE __declspec(dllimport)
-#endif
-
-#if !defined(__CLRCALL_PURE_OR_CDECL)
-#define __CLRCALL_PURE_OR_CDECL __cdecl
-#endif
-
-_CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL __ExceptionPtrCreate(void*);
-_CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL __ExceptionPtrDestroy(void*);
-_CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL __ExceptionPtrCopy(void*,
-  const void*);
-_CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL
-__ExceptionPtrAssign(void*, const void*);
-_CRTIMP2_PURE bool __CLRCALL_PURE_OR_CDECL
-__ExceptionPtrCompare(const void*, const void*);
-_CRTIMP2_PURE bool __CLRCALL_PURE_OR_CDECL
-__ExceptionPtrToBool(const void*);
-_CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL __ExceptionPtrSwap(void*, void*);
-_CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL
-__ExceptionPtrCurrentException(void*);
-[[noreturn]] _CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL
-__ExceptionPtrRethrow(const void*);
-_CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL
+_LIBCPP_CRT_FUNC void __cdecl __ExceptionPtrCreate(void*);
+_LIBCPP_CRT_FUNC void __cdecl __ExceptionPtrDestroy(void*);
+_LIBCPP_CRT_FUNC void __cdecl __ExceptionPtrCopy(void*, const void*);
+_LIBCPP_CRT_FUNC void __cdecl __ExceptionPtrAssign(void*, const void*);
+_LIBCPP_CRT_FUNC bool __cdecl __ExceptionPtrCompare(const void*, const void*);
+_LIBCPP_CRT_FUNC bool __cdecl __ExceptionPtrToBool(const void*);
+_LIBCPP_CRT_FUNC void __cdecl __ExceptionPtrSwap(void*, void*);
+_LIBCPP_CRT_FUNC void __cdecl 

[libcxx] r322201 - libcxx: Stop providing a definition of __GLIBC_PREREQ.

2018-01-10 Thread Peter Collingbourne via cfe-commits
Author: pcc
Date: Wed Jan 10 10:16:58 2018
New Revision: 322201

URL: http://llvm.org/viewvc/llvm-project?rev=322201=rev
Log:
libcxx: Stop providing a definition of __GLIBC_PREREQ.

An application may determine whether the C standard library is glibc
by testing whether __GLIBC_PREREQ is defined. This breaks if libc++
provides its own definition. Instead, define our own macro in our
namespace with the desired semantics.

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

Modified:
libcxx/trunk/include/__config

Modified: libcxx/trunk/include/__config
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__config?rev=322201=322200=322201=diff
==
--- libcxx/trunk/include/__config (original)
+++ libcxx/trunk/include/__config Wed Jan 10 10:16:58 2018
@@ -184,9 +184,11 @@
 // Need to detect which libc we're using if we're on Linux.
 #if defined(__linux__)
 #include 
-#if !defined(__GLIBC_PREREQ)
-#define __GLIBC_PREREQ(a, b) 0
-#endif // !defined(__GLIBC_PREREQ)
+#if defined(__GLIBC_PREREQ)
+#define _LIBCPP_GLIBC_PREREQ(a, b) __GLIBC_PREREQ(a, b)
+#else
+#define _LIBCPP_GLIBC_PREREQ(a, b) 0
+#endif // defined(__GLIBC_PREREQ)
 #endif // defined(__linux__)
 
 #ifdef __LITTLE_ENDIAN__
@@ -416,10 +418,10 @@ typedef __char32_t char32_t;
 #define _LIBCPP_HAS_C11_FEATURES
 #elif defined(__linux__)
 #if !defined(_LIBCPP_HAS_MUSL_LIBC)
-#if __GLIBC_PREREQ(2, 15) || defined(__BIONIC__)
+#if _LIBCPP_GLIBC_PREREQ(2, 15) || defined(__BIONIC__)
 #define _LIBCPP_HAS_QUICK_EXIT
 #endif
-#if __GLIBC_PREREQ(2, 17)
+#if _LIBCPP_GLIBC_PREREQ(2, 17)
 #define _LIBCPP_HAS_C11_FEATURES
 #endif
 #else // defined(_LIBCPP_HAS_MUSL_LIBC)


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


Re: r320942 - [ASTImporter] Support importing FunctionTemplateDecl and CXXDependentScopeMemberExpr

2017-12-19 Thread Peter Collingbourne via cfe-commits
Hi,

I reverted this change in r321139 because it causes a test failure on
Windows.
e.g.
https://logs.chromium.org/v/?s=chromium%2Fbb%2Ftryserver.chromium.win%2Fwin_upload_clang%2F277%2F%2B%2Frecipes%2Fsteps%2Fpackage_clang%2F0%2Fstdout
Please let me know if you have trouble reproducing.

Thanks,
Peter

On Sun, Dec 17, 2017 at 6:16 AM, Aleksei Sidorin via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: a.sidorin
> Date: Sun Dec 17 06:16:17 2017
> New Revision: 320942
>
> URL: http://llvm.org/viewvc/llvm-project?rev=320942=rev
> Log:
> [ASTImporter] Support importing FunctionTemplateDecl and
> CXXDependentScopeMemberExpr
>
> * Also introduces ImportTemplateArgumentListInfo facility (A. Sidorin)
>
> Patch by Peter Szecsi!
>
> Differential Revision: https://reviews.llvm.org/D38692
>
> Modified:
> cfe/trunk/lib/AST/ASTImporter.cpp
> cfe/trunk/unittests/AST/ASTImporterTest.cpp
>
> Modified: cfe/trunk/lib/AST/ASTImporter.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/
> ASTImporter.cpp?rev=320942=320941=320942=diff
> 
> ==
> --- cfe/trunk/lib/AST/ASTImporter.cpp (original)
> +++ cfe/trunk/lib/AST/ASTImporter.cpp Sun Dec 17 06:16:17 2017
> @@ -134,12 +134,17 @@ namespace clang {
>  bool ImportTemplateArguments(const TemplateArgument *FromArgs,
>   unsigned NumFromArgs,
> SmallVectorImpl
> );
> +template 
> +bool ImportTemplateArgumentListInfo(const InContainerTy ,
> +TemplateArgumentListInfo
> );
>  bool IsStructuralMatch(RecordDecl *FromRecord, RecordDecl *ToRecord,
> bool Complain = true);
>  bool IsStructuralMatch(VarDecl *FromVar, VarDecl *ToVar,
> bool Complain = true);
>  bool IsStructuralMatch(EnumDecl *FromEnum, EnumDecl *ToRecord);
>  bool IsStructuralMatch(EnumConstantDecl *FromEC, EnumConstantDecl
> *ToEC);
> +bool IsStructuralMatch(FunctionTemplateDecl *From,
> +   FunctionTemplateDecl *To);
>  bool IsStructuralMatch(ClassTemplateDecl *From, ClassTemplateDecl
> *To);
>  bool IsStructuralMatch(VarTemplateDecl *From, VarTemplateDecl *To);
>  Decl *VisitDecl(Decl *D);
> @@ -195,6 +200,7 @@ namespace clang {
>  ClassTemplateSpecializationDecl
> *D);
>  Decl *VisitVarTemplateDecl(VarTemplateDecl *D);
>  Decl *VisitVarTemplateSpecializationDecl(VarTemplateSpecializationDecl
> *D);
> +Decl *VisitFunctionTemplateDecl(FunctionTemplateDecl *D);
>
>  // Importing statements
>  DeclGroupRef ImportDeclGroup(DeclGroupRef DG);
> @@ -280,6 +286,7 @@ namespace clang {
>  Expr *VisitCXXDeleteExpr(CXXDeleteExpr *E);
>  Expr *VisitCXXConstructExpr(CXXConstructExpr *E);
>  Expr *VisitCXXMemberCallExpr(CXXMemberCallExpr *E);
> +Expr *VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr
> *E);
>  Expr *VisitExprWithCleanups(ExprWithCleanups *EWC);
>  Expr *VisitCXXThisExpr(CXXThisExpr *E);
>  Expr *VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E);
> @@ -1247,6 +1254,18 @@ bool ASTNodeImporter::ImportTemplateArgu
>return false;
>  }
>
> +template 
> +bool ASTNodeImporter::ImportTemplateArgumentListInfo(
> +const InContainerTy , TemplateArgumentListInfo ) {
> +  for (const auto  : Container) {
> +if (auto ToLoc = ImportTemplateArgumentLoc(FromLoc))
> +  ToTAInfo.addArgument(*ToLoc);
> +else
> +  return true;
> +  }
> +  return false;
> +}
> +
>  bool ASTNodeImporter::IsStructuralMatch(RecordDecl *FromRecord,
>  RecordDecl *ToRecord, bool
> Complain) {
>// Eliminate a potential failure point where we attempt to re-import
> @@ -1280,6 +1299,14 @@ bool ASTNodeImporter::IsStructuralMatch(
>return Ctx.IsStructurallyEquivalent(FromEnum, ToEnum);
>  }
>
> +bool ASTNodeImporter::IsStructuralMatch(FunctionTemplateDecl *From,
> +FunctionTemplateDecl *To) {
> +  StructuralEquivalenceContext Ctx(
> +  Importer.getFromContext(), Importer.getToContext(),
> +  Importer.getNonEquivalentDecls(), false, false);
> +  return Ctx.IsStructurallyEquivalent(From, To);
> +}
> +
>  bool ASTNodeImporter::IsStructuralMatch(EnumConstantDecl *FromEC,
>  EnumConstantDecl *ToEC)
>  {
> @@ -4197,6 +4224,64 @@ Decl *ASTNodeImporter::VisitVarTemplateS
>return D2;
>  }
>
> +Decl *ASTNodeImporter::VisitFunctionTemplateDecl(FunctionTemplateDecl
> *D) {
> +  DeclContext *DC, *LexicalDC;
> +  DeclarationName Name;
> +  SourceLocation Loc;
> +  NamedDecl *ToD;
> +
> +  if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
> +return nullptr;
> +
> +  if (ToD)
> +return ToD;
> +
> +  // Try to find a function in our own ("to") context with the same name,
> same
> +  

r321139 - Revert r320942, "[ASTImporter] Support importing FunctionTemplateDecl and CXXDependentScopeMemberExpr"

2017-12-19 Thread Peter Collingbourne via cfe-commits
Author: pcc
Date: Tue Dec 19 17:47:08 2017
New Revision: 321139

URL: http://llvm.org/viewvc/llvm-project?rev=321139=rev
Log:
Revert r320942, "[ASTImporter] Support importing FunctionTemplateDecl and 
CXXDependentScopeMemberExpr"

Caused a test failure on Windows:

[ RUN  ] ImportExpr.ImportCXXDependentScopeMemberExpr
C:\b\rr\tmppzcp4w\w\src\third_party\llvm\tools\clang\unittests\AST\ASTImporterTest.cpp(526):
 error: Value of: testImport("template  class C { T t; };" 
"template  void declToImport() {" "  C d;" "  d.t;" "}", 
Lang_CXX, "", Lang_CXX, Verifier, 
functionTemplateDecl(has(functionDecl(has(compoundStmt( 
has(cxxDependentScopeMemberExpr(
  Actual: false (Could not find match)
Expected: true
C:\b\rr\tmppzcp4w\w\src\third_party\llvm\tools\clang\unittests\AST\ASTImporterTest.cpp(534):
 error: Value of: testImport("template  class C { T t; };" 
"template  void declToImport() {" "  C d;" "  ()->t;" "}", 
Lang_CXX, "", Lang_CXX, Verifier, 
functionTemplateDecl(has(functionDecl(has(compoundStmt( 
has(cxxDependentScopeMemberExpr(
  Actual: false (Could not find match)
Expected: true
[  FAILED  ] ImportExpr.ImportCXXDependentScopeMemberExpr (37 ms)

Modified:
cfe/trunk/lib/AST/ASTImporter.cpp
cfe/trunk/unittests/AST/ASTImporterTest.cpp

Modified: cfe/trunk/lib/AST/ASTImporter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTImporter.cpp?rev=321139=321138=321139=diff
==
--- cfe/trunk/lib/AST/ASTImporter.cpp (original)
+++ cfe/trunk/lib/AST/ASTImporter.cpp Tue Dec 19 17:47:08 2017
@@ -134,17 +134,12 @@ namespace clang {
 bool ImportTemplateArguments(const TemplateArgument *FromArgs,
  unsigned NumFromArgs,
SmallVectorImpl );
-template 
-bool ImportTemplateArgumentListInfo(const InContainerTy ,
-TemplateArgumentListInfo );
 bool IsStructuralMatch(RecordDecl *FromRecord, RecordDecl *ToRecord,
bool Complain = true);
 bool IsStructuralMatch(VarDecl *FromVar, VarDecl *ToVar,
bool Complain = true);
 bool IsStructuralMatch(EnumDecl *FromEnum, EnumDecl *ToRecord);
 bool IsStructuralMatch(EnumConstantDecl *FromEC, EnumConstantDecl *ToEC);
-bool IsStructuralMatch(FunctionTemplateDecl *From,
-   FunctionTemplateDecl *To);
 bool IsStructuralMatch(ClassTemplateDecl *From, ClassTemplateDecl *To);
 bool IsStructuralMatch(VarTemplateDecl *From, VarTemplateDecl *To);
 Decl *VisitDecl(Decl *D);
@@ -200,7 +195,6 @@ namespace clang {
 ClassTemplateSpecializationDecl 
*D);
 Decl *VisitVarTemplateDecl(VarTemplateDecl *D);
 Decl *VisitVarTemplateSpecializationDecl(VarTemplateSpecializationDecl *D);
-Decl *VisitFunctionTemplateDecl(FunctionTemplateDecl *D);
 
 // Importing statements
 DeclGroupRef ImportDeclGroup(DeclGroupRef DG);
@@ -286,7 +280,6 @@ namespace clang {
 Expr *VisitCXXDeleteExpr(CXXDeleteExpr *E);
 Expr *VisitCXXConstructExpr(CXXConstructExpr *E);
 Expr *VisitCXXMemberCallExpr(CXXMemberCallExpr *E);
-Expr *VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E);
 Expr *VisitExprWithCleanups(ExprWithCleanups *EWC);
 Expr *VisitCXXThisExpr(CXXThisExpr *E);
 Expr *VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E);
@@ -1254,18 +1247,6 @@ bool ASTNodeImporter::ImportTemplateArgu
   return false;
 }
 
-template 
-bool ASTNodeImporter::ImportTemplateArgumentListInfo(
-const InContainerTy , TemplateArgumentListInfo ) {
-  for (const auto  : Container) {
-if (auto ToLoc = ImportTemplateArgumentLoc(FromLoc))
-  ToTAInfo.addArgument(*ToLoc);
-else
-  return true;
-  }
-  return false;
-}
-
 bool ASTNodeImporter::IsStructuralMatch(RecordDecl *FromRecord, 
 RecordDecl *ToRecord, bool Complain) {
   // Eliminate a potential failure point where we attempt to re-import
@@ -1299,14 +1280,6 @@ bool ASTNodeImporter::IsStructuralMatch(
   return Ctx.IsStructurallyEquivalent(FromEnum, ToEnum);
 }
 
-bool ASTNodeImporter::IsStructuralMatch(FunctionTemplateDecl *From,
-FunctionTemplateDecl *To) {
-  StructuralEquivalenceContext Ctx(
-  Importer.getFromContext(), Importer.getToContext(),
-  Importer.getNonEquivalentDecls(), false, false);
-  return Ctx.IsStructurallyEquivalent(From, To);
-}
-
 bool ASTNodeImporter::IsStructuralMatch(EnumConstantDecl *FromEC,
 EnumConstantDecl *ToEC)
 {
@@ -4224,64 +4197,6 @@ Decl *ASTNodeImporter::VisitVarTemplateS
   return D2;
 }
 
-Decl *ASTNodeImporter::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) {
-  DeclContext *DC, *LexicalDC;
-  DeclarationName Name;
-  SourceLocation Loc;
-  NamedDecl *ToD;
-
-  if 

[libcxx] r321124 - libcxx: Fix for basic_stringbuf::seekoff() after r320604.

2017-12-19 Thread Peter Collingbourne via cfe-commits
Author: pcc
Date: Tue Dec 19 15:33:16 2017
New Revision: 321124

URL: http://llvm.org/viewvc/llvm-project?rev=321124=rev
Log:
libcxx: Fix for basic_stringbuf::seekoff() after r320604.

As a result of this change, the basic_stringbuf constructor that
takes a mode ends up leaving __hm_ set to 0, causing the comparison
"__hm_ - __str_.data() < __noff" in seekoff() to succeed, which caused
the function to incorrectly return -1. The fix is to account for the
possibility of __hm_ being 0 when computing the distance from __hm_
to the start of the string.

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

Modified:
libcxx/trunk/include/sstream

libcxx/trunk/test/std/input.output/string.streams/stringbuf/stringbuf.virtuals/seekoff.pass.cpp

Modified: libcxx/trunk/include/sstream
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/sstream?rev=321124=321123=321124=diff
==
--- libcxx/trunk/include/sstream (original)
+++ libcxx/trunk/include/sstream Tue Dec 19 15:33:16 2017
@@ -577,6 +577,7 @@ basic_stringbuf<_CharT, _Traits, _Alloca
 if ((__wch & (ios_base::in | ios_base::out)) == (ios_base::in | 
ios_base::out)
 && __way == ios_base::cur)
 return pos_type(-1);
+const ptrdiff_t __hm = __hm_ == nullptr ? 0 : __hm_ - __str_.data();
 off_type __noff;
 switch (__way)
 {
@@ -590,13 +591,13 @@ basic_stringbuf<_CharT, _Traits, _Alloca
 __noff = this->pptr() - this->pbase();
 break;
 case ios_base::end:
-__noff = __hm_ - __str_.data();
+__noff = __hm;
 break;
 default:
 return pos_type(-1);
 }
 __noff += __off;
-if (__noff < 0 || __hm_ - __str_.data() < __noff)
+if (__noff < 0 || __hm < __noff)
 return pos_type(-1);
 if (__noff != 0)
 {

Modified: 
libcxx/trunk/test/std/input.output/string.streams/stringbuf/stringbuf.virtuals/seekoff.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/input.output/string.streams/stringbuf/stringbuf.virtuals/seekoff.pass.cpp?rev=321124=321123=321124=diff
==
--- 
libcxx/trunk/test/std/input.output/string.streams/stringbuf/stringbuf.virtuals/seekoff.pass.cpp
 (original)
+++ 
libcxx/trunk/test/std/input.output/string.streams/stringbuf/stringbuf.virtuals/seekoff.pass.cpp
 Tue Dec 19 15:33:16 2017
@@ -21,6 +21,30 @@
 int main()
 {
 {
+std::stringbuf sb(std::ios_base::in);
+assert(sb.pubseekoff(3, std::ios_base::beg, std::ios_base::out) == -1);
+assert(sb.pubseekoff(3, std::ios_base::cur, std::ios_base::out) == -1);
+assert(sb.pubseekoff(-3, std::ios_base::end, std::ios_base::out) == 
-1);
+assert(sb.pubseekoff(3, std::ios_base::beg, std::ios_base::in | 
std::ios_base::out) == -1);
+assert(sb.pubseekoff(3, std::ios_base::cur, std::ios_base::in | 
std::ios_base::out) == -1);
+assert(sb.pubseekoff(-3, std::ios_base::end, std::ios_base::in | 
std::ios_base::out) == -1);
+assert(sb.pubseekoff(0, std::ios_base::beg, std::ios_base::in) == 0);
+assert(sb.pubseekoff(0, std::ios_base::cur, std::ios_base::in) == 0);
+assert(sb.pubseekoff(0, std::ios_base::end, std::ios_base::in) == 0);
+}
+{
+std::stringbuf sb(std::ios_base::out);
+assert(sb.pubseekoff(3, std::ios_base::beg, std::ios_base::in) == -1);
+assert(sb.pubseekoff(3, std::ios_base::cur, std::ios_base::in) == -1);
+assert(sb.pubseekoff(-3, std::ios_base::end, std::ios_base::in) == -1);
+assert(sb.pubseekoff(3, std::ios_base::beg, std::ios_base::in | 
std::ios_base::out) == -1);
+assert(sb.pubseekoff(3, std::ios_base::cur, std::ios_base::in | 
std::ios_base::out) == -1);
+assert(sb.pubseekoff(-3, std::ios_base::end, std::ios_base::in | 
std::ios_base::out) == -1);
+assert(sb.pubseekoff(0, std::ios_base::beg, std::ios_base::out) == 0);
+assert(sb.pubseekoff(0, std::ios_base::cur, std::ios_base::out) == 0);
+assert(sb.pubseekoff(0, std::ios_base::end, std::ios_base::out) == 0);
+}
+{
 std::stringbuf sb("0123456789", std::ios_base::in);
 assert(sb.pubseekoff(3, std::ios_base::beg, std::ios_base::out) == -1);
 assert(sb.pubseekoff(3, std::ios_base::cur, std::ios_base::out) == -1);


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


r320638 - IRGen: When performing CFI checks, load vtable pointer from vbase when necessary.

2017-12-13 Thread Peter Collingbourne via cfe-commits
Author: pcc
Date: Wed Dec 13 13:53:04 2017
New Revision: 320638

URL: http://llvm.org/viewvc/llvm-project?rev=320638=rev
Log:
IRGen: When performing CFI checks, load vtable pointer from vbase when 
necessary.

Under the Microsoft ABI, it is possible for an object not to have
a virtual table pointer of its own if all of its virtual functions
were introduced by virtual bases. In that case, we need to load the
vtable pointer from one of the virtual bases and perform the type
check using its type.

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

Added:
cfe/trunk/test/CodeGenCXX/cfi-ms-vbase-derived-cast.cpp
cfe/trunk/test/CodeGenCXX/cfi-ms-vbase-nvcall.cpp
Modified:
cfe/trunk/lib/CodeGen/CGCXXABI.h
cfe/trunk/lib/CodeGen/CGClass.cpp
cfe/trunk/lib/CodeGen/CGExprCXX.cpp
cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp

Modified: cfe/trunk/lib/CodeGen/CGCXXABI.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCXXABI.h?rev=320638=320637=320638=diff
==
--- cfe/trunk/lib/CodeGen/CGCXXABI.h (original)
+++ cfe/trunk/lib/CodeGen/CGCXXABI.h Wed Dec 13 13:53:04 2017
@@ -582,6 +582,13 @@ public:
   /// Emit a single constructor/destructor with the given type from a C++
   /// constructor Decl.
   virtual void emitCXXStructor(const CXXMethodDecl *MD, StructorType Type) = 0;
+
+  /// Load a vtable from This, an object of polymorphic type RD, or from one of
+  /// its virtual bases if it does not have its own vtable. Returns the vtable
+  /// and the class from which the vtable was loaded.
+  virtual std::pair
+  LoadVTablePtr(CodeGenFunction , Address This,
+const CXXRecordDecl *RD) = 0;
 };
 
 // Create an instance of a C++ ABI class:

Modified: cfe/trunk/lib/CodeGen/CGClass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGClass.cpp?rev=320638=320637=320638=diff
==
--- cfe/trunk/lib/CodeGen/CGClass.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGClass.cpp Wed Dec 13 13:53:04 2017
@@ -2627,8 +2627,9 @@ void CodeGenFunction::EmitVTablePtrCheck
 EmitBlock(CheckBlock);
   }
 
-  llvm::Value *VTable =
-GetVTablePtr(Address(Derived, getPointerAlign()), Int8PtrTy, ClassDecl);
+  llvm::Value *VTable;
+  std::tie(VTable, ClassDecl) = CGM.getCXXABI().LoadVTablePtr(
+  *this, Address(Derived, getPointerAlign()), ClassDecl);
 
   EmitVTablePtrCheck(ClassDecl, VTable, TCK, Loc);
 

Modified: cfe/trunk/lib/CodeGen/CGExprCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprCXX.cpp?rev=320638=320637=320638=diff
==
--- cfe/trunk/lib/CodeGen/CGExprCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprCXX.cpp Wed Dec 13 13:53:04 2017
@@ -368,9 +368,11 @@ RValue CodeGenFunction::EmitCXXMemberOrO
   } else {
 if (SanOpts.has(SanitizerKind::CFINVCall) &&
 MD->getParent()->isDynamicClass()) {
-  llvm::Value *VTable = GetVTablePtr(This, Int8PtrTy, MD->getParent());
-  EmitVTablePtrCheckForCall(MD->getParent(), VTable, CFITCK_NVCall,
-CE->getLocStart());
+  llvm::Value *VTable;
+  const CXXRecordDecl *RD;
+  std::tie(VTable, RD) =
+  CGM.getCXXABI().LoadVTablePtr(*this, This, MD->getParent());
+  EmitVTablePtrCheckForCall(RD, VTable, CFITCK_NVCall, CE->getLocStart());
 }
 
 if (getLangOpts().AppleKext && MD->isVirtual() && HasQualifier)

Modified: cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp?rev=320638=320637=320638=diff
==
--- cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp (original)
+++ cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp Wed Dec 13 13:53:04 2017
@@ -389,6 +389,10 @@ public:
 
   void emitCXXStructor(const CXXMethodDecl *MD, StructorType Type) override;
 
+  std::pair
+  LoadVTablePtr(CodeGenFunction , Address This,
+const CXXRecordDecl *RD) override;
+
  private:
bool hasAnyUnusedVirtualInlineFunction(const CXXRecordDecl *RD) const {
  const auto  =
@@ -4041,3 +4045,9 @@ ItaniumCXXABI::emitTerminateForUnexpecte
   }
   return CGF.EmitNounwindRuntimeCall(CGF.CGM.getTerminateFn());
 }
+
+std::pair
+ItaniumCXXABI::LoadVTablePtr(CodeGenFunction , Address This,
+ const CXXRecordDecl *RD) {
+  return {CGF.GetVTablePtr(This, CGM.Int8PtrTy, RD), RD};
+}

Modified: cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp?rev=320638=320637=320638=diff
==
--- cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp (original)
+++ cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp 

r318857 - CachePruning: Allow limiting the number of files in the cache directory.

2017-11-22 Thread Peter Collingbourne via cfe-commits
Author: pcc
Date: Wed Nov 22 10:27:31 2017
New Revision: 318857

URL: http://llvm.org/viewvc/llvm-project?rev=318857=rev
Log:
CachePruning: Allow limiting the number of files in the cache directory.

The default limit is 100 but it can be configured with a cache
policy. The motivation is that some filesystems (notably ext4) have
a limit on the number of files that can be contained in a directory
(separate from the inode limit).

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

Modified:
cfe/trunk/docs/ThinLTO.rst

Modified: cfe/trunk/docs/ThinLTO.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ThinLTO.rst?rev=318857=318856=318857=diff
==
--- cfe/trunk/docs/ThinLTO.rst (original)
+++ cfe/trunk/docs/ThinLTO.rst Wed Nov 22 10:27:31 2017
@@ -173,6 +173,10 @@ Possible key-value pairs are:
   ``cache_size_bytes=1g`` on its own will cause both the 1GB and default 75%
   policies to be applied unless the default ``cache_size`` is overridden.
 
+- ``cache_size_files=X``:
+  Set the maximum number of files in the cache directory. Set to 0 to indicate
+  no limit. The default is 100 files.
+
 - ``prune_after=Xs``, ``prune_after=Xm``, ``prune_after=Xh``: Sets the
   expiration time for cache files to ``X`` seconds (or minutes, hours
   respectively).  When a file hasn't been accessed for ``prune_after`` seconds,


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


Re: r313096 - [ubsan] Function Sanitizer: Don't require writable text segments

2017-10-13 Thread Peter Collingbourne via cfe-commits
On Fri, Oct 13, 2017 at 6:12 PM, Vedant Kumar  wrote:

>
> On Oct 13, 2017, at 6:05 PM, Peter Collingbourne  wrote:
>
>
>
> On Fri, Oct 13, 2017 at 5:59 PM, Vedant Kumar  wrote:
>
>>
>> On Oct 13, 2017, at 4:33 PM, Peter Collingbourne  wrote:
>>
>>
>>
>> On Fri, Oct 13, 2017 at 4:19 PM, Vedant Kumar  wrote:
>>
>>>
>>> On Oct 13, 2017, at 4:08 PM, Peter Collingbourne 
>>> wrote:
>>>
>>> On Fri, Oct 13, 2017 at 4:06 PM, Peter Collingbourne 
>>> wrote:
>>>
 Here's a small reproducer.

 struct A {
   virtual void f(...);
 };

 struct B : virtual A {
   virtual void b();
   virtual void f(...);
 };

 void B::f(...) {}

 $ clang++ -fsanitize=function fsan.cpp -ffunction-sections
 -fdata-sections -c -o /dev/null
 fatal error: error in backend: Cannot represent a difference across
 sections

 Looking at the IR I see this function definition:
 define void @_ZTv0_n24_N1B1fEz(%struct.B* %this, ...) unnamed_addr #0
 align 2 prologue <{ i32, i32 }> <{ i32 846595819, i32 trunc (i64 sub (i64
 ptrtoint (i8** @0 to i64), i64 ptrtoint (void (%struct.B*, ...)* @_ZN1B1fEz
 to i64)) to i32) }> {
 which appears to cause the error.

 I get basically the same IR if I use a Darwin target triple, so this
 isn't a Linux-specific issue. (On Darwin we end up successfully creating an
 object file, but the embedded offset in the text section will presumably be
 incorrect.)

 Note that we're emitting prologue data on virtual functions, which is
 unnecessary because -fsanitize=function only checks indirect calls via
 function pointers. So I imagine that one way to solve the problem would be
 to turn off prologue data emission on non-virtual functions.

>>>
>>> Sorry, I meant "limit prologue data emission to non-virtual functions".
>>>
>>>
>>> That's independently a great idea :).
>>>
>>> I don't see a problem in the IR you've showed above, however. Why do you
>>> expect the embedded offset to be incorrect? This program links and runs
>>> fine on Darwin:
>>>
>>> ---
>>> struct A {
>>>   virtual void f(...) {}
>>> };
>>>
>>> struct B : virtual A {
>>>   virtual void b() {}
>>>   virtual void f(...);
>>> };
>>>
>>> void B::f(...) {}
>>>
>>> int main() {
>>>   A a;
>>>   a.f();
>>>
>>>   B b;
>>>   b.f();
>>>   b.b();
>>>   return 0;
>>> }
>>> ---
>>>
>>> The "Cannot represent difference..." error appears limited to ELF and
>>> Wasm, afaik.
>>>
>>
>> In order to find the RTTI data for a function, the generated code will
>> add the embedded offset to the function's address in order to find the
>> global that contains the pointer to the RTTI data. So if we were to compute
>> the address of _ZTv0_n24_N1B1fEz's global, we would compute the value:
>> _ZTv0_n24_N1B1fEz + (@0 -_ZN1B1fEz)
>> which, of course, will not yield the address of @0.
>>
>> I would certainly expect your program to run correctly because we do not
>> try to interpret the prologue data when calling a virtual function, so the
>> incorrectness of the offset has no effect on the program's execution.
>>
>>
>> Thanks for explaining. I am still confused on one point.
>>
>> Calling a function pointer to a virtual member doesn't seem to trigger a
>> UBSan type check. I can see why "_ZTv0_n24_N1B1fEz + (@0 -_ZN1B1fEz)"
>> doesn't make sense, but I don't know how we'd ever get there. Consider:
>>
>> ---
>> class A {
>> public:
>>   virtual int f() = 0;
>> };
>>
>> class B : public A {
>>   int f() { return 42; }
>> };
>>
>> struct C {
>>   void g() {}
>>   static void h() {}
>> };
>>
>> int main() {
>>   auto h = ::h;
>>   h(); // type checked
>>
>>   C c;
>>   void (C::*g)() = ::g;
>>   (c.*g)(); // not checked
>>
>>   int (A::*f)() = ::f;
>>   A *a = new B;
>>   return (a->*f)(); // not checked
>> }
>> ---
>>
>> So, I'm not sure how we would get into a situation where we compute
>> "_ZTv0_n24_N1B1fEz + (@0 -_ZN1B1fEz)".
>>
>
> Right, my point was that we wouldn't get into such a situation. I'm sorry
> if I was unclear.
>
>
> Oh, in that case were you suggesting that simply storing "(@0 -_ZN1B1fEz)"
> in the prologue for _ZTv0_n24_N1B1fEz would cause the backend error
> ("Cannot represent a difference...")?
>

Yes, exactly. The basic problem is that object format relocations generally
cannot represent the difference between two arbitrary symbols, but they can
represent the difference between a symbol and the current address (i.e. in
this case, the address of the offset in the prologue data), plus a constant
addend (this is known as a PC-relative relocation). So if the RHS of the
subtraction can be resolved to the current address (or an address with an
assembler-constant offset from the current address), the reference can be
represented using a PC-relative relocation (with the offset from the start
of the prologue data being used as the 

Re: r313096 - [ubsan] Function Sanitizer: Don't require writable text segments

2017-10-13 Thread Peter Collingbourne via cfe-commits
On Fri, Oct 13, 2017 at 5:59 PM, Vedant Kumar  wrote:

>
> On Oct 13, 2017, at 4:33 PM, Peter Collingbourne  wrote:
>
>
>
> On Fri, Oct 13, 2017 at 4:19 PM, Vedant Kumar  wrote:
>
>>
>> On Oct 13, 2017, at 4:08 PM, Peter Collingbourne  wrote:
>>
>> On Fri, Oct 13, 2017 at 4:06 PM, Peter Collingbourne 
>> wrote:
>>
>>> Here's a small reproducer.
>>>
>>> struct A {
>>>   virtual void f(...);
>>> };
>>>
>>> struct B : virtual A {
>>>   virtual void b();
>>>   virtual void f(...);
>>> };
>>>
>>> void B::f(...) {}
>>>
>>> $ clang++ -fsanitize=function fsan.cpp -ffunction-sections
>>> -fdata-sections -c -o /dev/null
>>> fatal error: error in backend: Cannot represent a difference across
>>> sections
>>>
>>> Looking at the IR I see this function definition:
>>> define void @_ZTv0_n24_N1B1fEz(%struct.B* %this, ...) unnamed_addr #0
>>> align 2 prologue <{ i32, i32 }> <{ i32 846595819, i32 trunc (i64 sub (i64
>>> ptrtoint (i8** @0 to i64), i64 ptrtoint (void (%struct.B*, ...)* @_ZN1B1fEz
>>> to i64)) to i32) }> {
>>> which appears to cause the error.
>>>
>>> I get basically the same IR if I use a Darwin target triple, so this
>>> isn't a Linux-specific issue. (On Darwin we end up successfully creating an
>>> object file, but the embedded offset in the text section will presumably be
>>> incorrect.)
>>>
>>> Note that we're emitting prologue data on virtual functions, which is
>>> unnecessary because -fsanitize=function only checks indirect calls via
>>> function pointers. So I imagine that one way to solve the problem would be
>>> to turn off prologue data emission on non-virtual functions.
>>>
>>
>> Sorry, I meant "limit prologue data emission to non-virtual functions".
>>
>>
>> That's independently a great idea :).
>>
>> I don't see a problem in the IR you've showed above, however. Why do you
>> expect the embedded offset to be incorrect? This program links and runs
>> fine on Darwin:
>>
>> ---
>> struct A {
>>   virtual void f(...) {}
>> };
>>
>> struct B : virtual A {
>>   virtual void b() {}
>>   virtual void f(...);
>> };
>>
>> void B::f(...) {}
>>
>> int main() {
>>   A a;
>>   a.f();
>>
>>   B b;
>>   b.f();
>>   b.b();
>>   return 0;
>> }
>> ---
>>
>> The "Cannot represent difference..." error appears limited to ELF and
>> Wasm, afaik.
>>
>
> In order to find the RTTI data for a function, the generated code will add
> the embedded offset to the function's address in order to find the global
> that contains the pointer to the RTTI data. So if we were to compute the
> address of _ZTv0_n24_N1B1fEz's global, we would compute the value:
> _ZTv0_n24_N1B1fEz + (@0 -_ZN1B1fEz)
> which, of course, will not yield the address of @0.
>
> I would certainly expect your program to run correctly because we do not
> try to interpret the prologue data when calling a virtual function, so the
> incorrectness of the offset has no effect on the program's execution.
>
>
> Thanks for explaining. I am still confused on one point.
>
> Calling a function pointer to a virtual member doesn't seem to trigger a
> UBSan type check. I can see why "_ZTv0_n24_N1B1fEz + (@0 -_ZN1B1fEz)"
> doesn't make sense, but I don't know how we'd ever get there. Consider:
>
> ---
> class A {
> public:
>   virtual int f() = 0;
> };
>
> class B : public A {
>   int f() { return 42; }
> };
>
> struct C {
>   void g() {}
>   static void h() {}
> };
>
> int main() {
>   auto h = ::h;
>   h(); // type checked
>
>   C c;
>   void (C::*g)() = ::g;
>   (c.*g)(); // not checked
>
>   int (A::*f)() = ::f;
>   A *a = new B;
>   return (a->*f)(); // not checked
> }
> ---
>
> So, I'm not sure how we would get into a situation where we compute
> "_ZTv0_n24_N1B1fEz + (@0 -_ZN1B1fEz)".
>

Right, my point was that we wouldn't get into such a situation. I'm sorry
if I was unclear.


> In the last code example I posted, there are also no calls to the function
> type check handler.
>
> At any rate, I implemented your idea to not emit signatures for virtual
> methods:
> https://reviews.llvm.org/D38913
>
> It's at least good for a code size savings, and it might fix the issue
> Eric and Han are seeing. I'd appreciate any feedback.
>

Thanks, I will take a look.

Peter


> thanks,
> vedant
>
>
>
> Peter
>
>
>> vedant
>>
>>
>> Peter
>>>
>>> On Fri, Oct 13, 2017 at 3:06 PM, Vedant Kumar  wrote:
>>>

 On Oct 13, 2017, at 2:52 PM, Eric Christopher 
 wrote:



 On Fri, Oct 13, 2017 at 2:50 PM Vedant Kumar  wrote:

> On Oct 13, 2017, at 1:44 PM, Eric Christopher 
> wrote:
>
>
>
> On Fri, Oct 13, 2017 at 1:42 PM Vedant Kumar  wrote:
>
>> On Oct 13, 2017, at 1:39 PM, Vedant Kumar  wrote:
>>
>> Hey Eric,
>>
>> I'm sorry for the breakage. I made sure to check the run-time tests
>> in compiler-rt but we could have missing 

Re: r313096 - [ubsan] Function Sanitizer: Don't require writable text segments

2017-10-13 Thread Peter Collingbourne via cfe-commits
On Fri, Oct 13, 2017 at 4:19 PM, Vedant Kumar  wrote:

>
> On Oct 13, 2017, at 4:08 PM, Peter Collingbourne  wrote:
>
> On Fri, Oct 13, 2017 at 4:06 PM, Peter Collingbourne 
> wrote:
>
>> Here's a small reproducer.
>>
>> struct A {
>>   virtual void f(...);
>> };
>>
>> struct B : virtual A {
>>   virtual void b();
>>   virtual void f(...);
>> };
>>
>> void B::f(...) {}
>>
>> $ clang++ -fsanitize=function fsan.cpp -ffunction-sections
>> -fdata-sections -c -o /dev/null
>> fatal error: error in backend: Cannot represent a difference across
>> sections
>>
>> Looking at the IR I see this function definition:
>> define void @_ZTv0_n24_N1B1fEz(%struct.B* %this, ...) unnamed_addr #0
>> align 2 prologue <{ i32, i32 }> <{ i32 846595819, i32 trunc (i64 sub (i64
>> ptrtoint (i8** @0 to i64), i64 ptrtoint (void (%struct.B*, ...)* @_ZN1B1fEz
>> to i64)) to i32) }> {
>> which appears to cause the error.
>>
>> I get basically the same IR if I use a Darwin target triple, so this
>> isn't a Linux-specific issue. (On Darwin we end up successfully creating an
>> object file, but the embedded offset in the text section will presumably be
>> incorrect.)
>>
>> Note that we're emitting prologue data on virtual functions, which is
>> unnecessary because -fsanitize=function only checks indirect calls via
>> function pointers. So I imagine that one way to solve the problem would be
>> to turn off prologue data emission on non-virtual functions.
>>
>
> Sorry, I meant "limit prologue data emission to non-virtual functions".
>
>
> That's independently a great idea :).
>
> I don't see a problem in the IR you've showed above, however. Why do you
> expect the embedded offset to be incorrect? This program links and runs
> fine on Darwin:
>
> ---
> struct A {
>   virtual void f(...) {}
> };
>
> struct B : virtual A {
>   virtual void b() {}
>   virtual void f(...);
> };
>
> void B::f(...) {}
>
> int main() {
>   A a;
>   a.f();
>
>   B b;
>   b.f();
>   b.b();
>   return 0;
> }
> ---
>
> The "Cannot represent difference..." error appears limited to ELF and
> Wasm, afaik.
>

In order to find the RTTI data for a function, the generated code will add
the embedded offset to the function's address in order to find the global
that contains the pointer to the RTTI data. So if we were to compute the
address of _ZTv0_n24_N1B1fEz's global, we would compute the value:
_ZTv0_n24_N1B1fEz + (@0 -_ZN1B1fEz)
which, of course, will not yield the address of @0.

I would certainly expect your program to run correctly because we do not
try to interpret the prologue data when calling a virtual function, so the
incorrectness of the offset has no effect on the program's execution.

Peter


> vedant
>
>
> Peter
>>
>> On Fri, Oct 13, 2017 at 3:06 PM, Vedant Kumar  wrote:
>>
>>>
>>> On Oct 13, 2017, at 2:52 PM, Eric Christopher 
>>> wrote:
>>>
>>>
>>>
>>> On Fri, Oct 13, 2017 at 2:50 PM Vedant Kumar  wrote:
>>>
 On Oct 13, 2017, at 1:44 PM, Eric Christopher 
 wrote:



 On Fri, Oct 13, 2017 at 1:42 PM Vedant Kumar  wrote:

> On Oct 13, 2017, at 1:39 PM, Vedant Kumar  wrote:
>
> Hey Eric,
>
> I'm sorry for the breakage. I made sure to check the run-time tests in
> compiler-rt but we could have missing coverage there.
>
> The original version of this patch restricted the prologue data
> changes to Darwin only. We can switch back to that easily, just let me 
> know.
>
>
> Actually I'll go ahead and work a patch up.
>
>
 Appreciated :)

 Basically we were getting an error of:

 error: Cannot represent a difference across sections

 trying to compile things with the current code.


 Oh I see.. well, we started using a difference between the address of a
 function and the address of a global, so the error makes sense.

 I'd be interested in any factors that could narrow the problem down
 (e.g using a specific linker, using -ffunction-sections, using
 data-sections, etc). Basically I'm not sure why this would work on some
 Linux setups but not others.


>>> Definitely using the latter two options and gold as a linker. I'll see
>>> what Han can come up with.
>>>
>>>
>>> Gotcha. Well, -ffunction-sections appears to be untested in
>>> compiler-rt/test/ubsan, at least.
>>>
>>> There's a test somewhere in there called function.cpp -- it would be
>>> great if we could cover the *-sections options there. I'm not sure whether
>>> that's what caused the failure, but the extra coverage couldn't hurt :). I
>>> would do it myself but I don't have a Linux machine to test on.
>>>
>>> vedant
>>>
>>>
>>>
 While we figure that out here's a patch to limit the impact on
 non-Darwin platforms:
 https://reviews.llvm.org/D38903

>>>
>>> *goes a looking*
>>>
>>> Thanks!

Re: r313096 - [ubsan] Function Sanitizer: Don't require writable text segments

2017-10-13 Thread Peter Collingbourne via cfe-commits
On Fri, Oct 13, 2017 at 4:06 PM, Peter Collingbourne 
wrote:

> Here's a small reproducer.
>
> struct A {
>   virtual void f(...);
> };
>
> struct B : virtual A {
>   virtual void b();
>   virtual void f(...);
> };
>
> void B::f(...) {}
>
> $ clang++ -fsanitize=function fsan.cpp -ffunction-sections -fdata-sections
> -c -o /dev/null
> fatal error: error in backend: Cannot represent a difference across
> sections
>
> Looking at the IR I see this function definition:
> define void @_ZTv0_n24_N1B1fEz(%struct.B* %this, ...) unnamed_addr #0
> align 2 prologue <{ i32, i32 }> <{ i32 846595819, i32 trunc (i64 sub (i64
> ptrtoint (i8** @0 to i64), i64 ptrtoint (void (%struct.B*, ...)* @_ZN1B1fEz
> to i64)) to i32) }> {
> which appears to cause the error.
>
> I get basically the same IR if I use a Darwin target triple, so this isn't
> a Linux-specific issue. (On Darwin we end up successfully creating an
> object file, but the embedded offset in the text section will presumably be
> incorrect.)
>
> Note that we're emitting prologue data on virtual functions, which is
> unnecessary because -fsanitize=function only checks indirect calls via
> function pointers. So I imagine that one way to solve the problem would be
> to turn off prologue data emission on non-virtual functions.
>

Sorry, I meant "limit prologue data emission to non-virtual functions".

Peter
>
> On Fri, Oct 13, 2017 at 3:06 PM, Vedant Kumar  wrote:
>
>>
>> On Oct 13, 2017, at 2:52 PM, Eric Christopher  wrote:
>>
>>
>>
>> On Fri, Oct 13, 2017 at 2:50 PM Vedant Kumar  wrote:
>>
>>> On Oct 13, 2017, at 1:44 PM, Eric Christopher 
>>> wrote:
>>>
>>>
>>>
>>> On Fri, Oct 13, 2017 at 1:42 PM Vedant Kumar  wrote:
>>>
 On Oct 13, 2017, at 1:39 PM, Vedant Kumar  wrote:

 Hey Eric,

 I'm sorry for the breakage. I made sure to check the run-time tests in
 compiler-rt but we could have missing coverage there.

 The original version of this patch restricted the prologue data changes
 to Darwin only. We can switch back to that easily, just let me know.


 Actually I'll go ahead and work a patch up.


>>> Appreciated :)
>>>
>>> Basically we were getting an error of:
>>>
>>> error: Cannot represent a difference across sections
>>>
>>> trying to compile things with the current code.
>>>
>>>
>>> Oh I see.. well, we started using a difference between the address of a
>>> function and the address of a global, so the error makes sense.
>>>
>>> I'd be interested in any factors that could narrow the problem down (e.g
>>> using a specific linker, using -ffunction-sections, using data-sections,
>>> etc). Basically I'm not sure why this would work on some Linux setups but
>>> not others.
>>>
>>>
>> Definitely using the latter two options and gold as a linker. I'll see
>> what Han can come up with.
>>
>>
>> Gotcha. Well, -ffunction-sections appears to be untested in
>> compiler-rt/test/ubsan, at least.
>>
>> There's a test somewhere in there called function.cpp -- it would be
>> great if we could cover the *-sections options there. I'm not sure whether
>> that's what caused the failure, but the extra coverage couldn't hurt :). I
>> would do it myself but I don't have a Linux machine to test on.
>>
>> vedant
>>
>>
>>
>>> While we figure that out here's a patch to limit the impact on
>>> non-Darwin platforms:
>>> https://reviews.llvm.org/D38903
>>>
>>
>> *goes a looking*
>>
>> Thanks!
>>
>> -eric
>>
>>>
>>> vedant
>>>
>>>
>>> Thanks!
>>>
>>> -eric
>>>
>>>
 vedant


 vedant


 On Oct 13, 2017, at 1:33 PM, Eric Christopher 
 wrote:

 Hi Vedant,

 So this actually broke -fsanitize=function on linux. Han is working up
 a testcase for it, but letting you know for now that we'll probably need
 some change here.

 -eric

 On Tue, Sep 12, 2017 at 5:05 PM Vedant Kumar via cfe-commits <
 cfe-commits@lists.llvm.org> wrote:

> Author: vedantk
> Date: Tue Sep 12 17:04:35 2017
> New Revision: 313096
>
> URL: http://llvm.org/viewvc/llvm-project?rev=313096=rev
> Log:
> [ubsan] Function Sanitizer: Don't require writable text segments
>
> This change will make it possible to use -fsanitize=function on Darwin
> and
> possibly on other platforms. It fixes an issue with the way RTTI is
> stored into
> function prologue data.
>
> On Darwin, addresses stored in prologue data can't require run-time
> fixups and
> must be PC-relative. Run-time fixups are undesirable because they
> necessitate
> writable text segments, which can lead to security issues. And absolute
> addresses are undesirable because they break PIE mode.
>
> The fix is to create a private global which points to the RTTI, and
> then to
> encode a PC-relative reference to the 

Re: r313096 - [ubsan] Function Sanitizer: Don't require writable text segments

2017-10-13 Thread Peter Collingbourne via cfe-commits
Here's a small reproducer.

struct A {
  virtual void f(...);
};

struct B : virtual A {
  virtual void b();
  virtual void f(...);
};

void B::f(...) {}

$ clang++ -fsanitize=function fsan.cpp -ffunction-sections -fdata-sections
-c -o /dev/null
fatal error: error in backend: Cannot represent a difference across sections

Looking at the IR I see this function definition:
define void @_ZTv0_n24_N1B1fEz(%struct.B* %this, ...) unnamed_addr #0 align
2 prologue <{ i32, i32 }> <{ i32 846595819, i32 trunc (i64 sub (i64
ptrtoint (i8** @0 to i64), i64 ptrtoint (void (%struct.B*, ...)* @_ZN1B1fEz
to i64)) to i32) }> {
which appears to cause the error.

I get basically the same IR if I use a Darwin target triple, so this isn't
a Linux-specific issue. (On Darwin we end up successfully creating an
object file, but the embedded offset in the text section will presumably be
incorrect.)

Note that we're emitting prologue data on virtual functions, which is
unnecessary because -fsanitize=function only checks indirect calls via
function pointers. So I imagine that one way to solve the problem would be
to turn off prologue data emission on non-virtual functions.

Peter

On Fri, Oct 13, 2017 at 3:06 PM, Vedant Kumar  wrote:

>
> On Oct 13, 2017, at 2:52 PM, Eric Christopher  wrote:
>
>
>
> On Fri, Oct 13, 2017 at 2:50 PM Vedant Kumar  wrote:
>
>> On Oct 13, 2017, at 1:44 PM, Eric Christopher  wrote:
>>
>>
>>
>> On Fri, Oct 13, 2017 at 1:42 PM Vedant Kumar  wrote:
>>
>>> On Oct 13, 2017, at 1:39 PM, Vedant Kumar  wrote:
>>>
>>> Hey Eric,
>>>
>>> I'm sorry for the breakage. I made sure to check the run-time tests in
>>> compiler-rt but we could have missing coverage there.
>>>
>>> The original version of this patch restricted the prologue data changes
>>> to Darwin only. We can switch back to that easily, just let me know.
>>>
>>>
>>> Actually I'll go ahead and work a patch up.
>>>
>>>
>> Appreciated :)
>>
>> Basically we were getting an error of:
>>
>> error: Cannot represent a difference across sections
>>
>> trying to compile things with the current code.
>>
>>
>> Oh I see.. well, we started using a difference between the address of a
>> function and the address of a global, so the error makes sense.
>>
>> I'd be interested in any factors that could narrow the problem down (e.g
>> using a specific linker, using -ffunction-sections, using data-sections,
>> etc). Basically I'm not sure why this would work on some Linux setups but
>> not others.
>>
>>
> Definitely using the latter two options and gold as a linker. I'll see
> what Han can come up with.
>
>
> Gotcha. Well, -ffunction-sections appears to be untested in
> compiler-rt/test/ubsan, at least.
>
> There's a test somewhere in there called function.cpp -- it would be great
> if we could cover the *-sections options there. I'm not sure whether that's
> what caused the failure, but the extra coverage couldn't hurt :). I would
> do it myself but I don't have a Linux machine to test on.
>
> vedant
>
>
>
>> While we figure that out here's a patch to limit the impact on non-Darwin
>> platforms:
>> https://reviews.llvm.org/D38903
>>
>
> *goes a looking*
>
> Thanks!
>
> -eric
>
>>
>> vedant
>>
>>
>> Thanks!
>>
>> -eric
>>
>>
>>> vedant
>>>
>>>
>>> vedant
>>>
>>>
>>> On Oct 13, 2017, at 1:33 PM, Eric Christopher 
>>> wrote:
>>>
>>> Hi Vedant,
>>>
>>> So this actually broke -fsanitize=function on linux. Han is working up a
>>> testcase for it, but letting you know for now that we'll probably need some
>>> change here.
>>>
>>> -eric
>>>
>>> On Tue, Sep 12, 2017 at 5:05 PM Vedant Kumar via cfe-commits <
>>> cfe-commits@lists.llvm.org> wrote:
>>>
 Author: vedantk
 Date: Tue Sep 12 17:04:35 2017
 New Revision: 313096

 URL: http://llvm.org/viewvc/llvm-project?rev=313096=rev
 Log:
 [ubsan] Function Sanitizer: Don't require writable text segments

 This change will make it possible to use -fsanitize=function on Darwin
 and
 possibly on other platforms. It fixes an issue with the way RTTI is
 stored into
 function prologue data.

 On Darwin, addresses stored in prologue data can't require run-time
 fixups and
 must be PC-relative. Run-time fixups are undesirable because they
 necessitate
 writable text segments, which can lead to security issues. And absolute
 addresses are undesirable because they break PIE mode.

 The fix is to create a private global which points to the RTTI, and
 then to
 encode a PC-relative reference to the global into prologue data.

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

 Modified:
 cfe/trunk/lib/CodeGen/CGExpr.cpp
 cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
 cfe/trunk/lib/CodeGen/CodeGenFunction.h
 cfe/trunk/lib/CodeGen/TargetInfo.cpp
 

[clang-tools-extra] r315378 - Support: Have directory_iterator::status() return FindFirstFileEx/FindNextFile results on Windows.

2017-10-10 Thread Peter Collingbourne via cfe-commits
Author: pcc
Date: Tue Oct 10 15:19:46 2017
New Revision: 315378

URL: http://llvm.org/viewvc/llvm-project?rev=315378=rev
Log:
Support: Have directory_iterator::status() return FindFirstFileEx/FindNextFile 
results on Windows.

This allows clients to avoid an unnecessary fs::status() call on each
directory entry. Because the information returned by FindFirstFileEx
is a subset of the information returned by a regular status() call,
I needed to extract a base class from file_status that contains only
that information.

On my machine, this reduces the time required to enumerate a ThinLTO
cache directory containing 520k files from almost 4 minutes to less
than 2 seconds.

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

Modified:
clang-tools-extra/trunk/modularize/CoverageChecker.cpp
clang-tools-extra/trunk/modularize/ModularizeUtilities.cpp

Modified: clang-tools-extra/trunk/modularize/CoverageChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/modularize/CoverageChecker.cpp?rev=315378=315377=315378=diff
==
--- clang-tools-extra/trunk/modularize/CoverageChecker.cpp (original)
+++ clang-tools-extra/trunk/modularize/CoverageChecker.cpp Tue Oct 10 15:19:46 
2017
@@ -242,14 +242,15 @@ bool CoverageChecker::collectUmbrellaHea
 Directory = ".";
   // Walk the directory.
   std::error_code EC;
-  sys::fs::file_status Status;
   for (sys::fs::directory_iterator I(Directory.str(), EC), E; I != E;
 I.increment(EC)) {
 if (EC)
   return false;
 std::string File(I->path());
-I->status(Status);
-sys::fs::file_type Type = Status.type();
+llvm::ErrorOr Status = I->status();
+if (!Status)
+  return false;
+sys::fs::file_type Type = Status->type();
 // If the file is a directory, ignore the name and recurse.
 if (Type == sys::fs::file_type::directory_file) {
   if (!collectUmbrellaHeaders(File))
@@ -363,7 +364,6 @@ bool CoverageChecker::collectFileSystemH
 
   // Recursively walk the directory tree.
   std::error_code EC;
-  sys::fs::file_status Status;
   int Count = 0;
   for (sys::fs::recursive_directory_iterator I(Directory.str(), EC), E; I != E;
 I.increment(EC)) {
@@ -371,8 +371,10 @@ bool CoverageChecker::collectFileSystemH
   return false;
 //std::string file(I->path());
 StringRef file(I->path());
-I->status(Status);
-sys::fs::file_type type = Status.type();
+llvm::ErrorOr Status = I->status();
+if (!Status)
+  return false;
+sys::fs::file_type type = Status->type();
 // If the file is a directory, ignore the name (but still recurses).
 if (type == sys::fs::file_type::directory_file)
   continue;

Modified: clang-tools-extra/trunk/modularize/ModularizeUtilities.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/modularize/ModularizeUtilities.cpp?rev=315378=315377=315378=diff
==
--- clang-tools-extra/trunk/modularize/ModularizeUtilities.cpp (original)
+++ clang-tools-extra/trunk/modularize/ModularizeUtilities.cpp Tue Oct 10 
15:19:46 2017
@@ -399,14 +399,15 @@ bool ModularizeUtilities::collectUmbrell
   SmallString<256> Directory(UmbrellaDirName);
   // Walk the directory.
   std::error_code EC;
-  llvm::sys::fs::file_status Status;
   for (llvm::sys::fs::directory_iterator I(Directory.str(), EC), E; I != E;
 I.increment(EC)) {
 if (EC)
   return false;
 std::string File(I->path());
-I->status(Status);
-llvm::sys::fs::file_type Type = Status.type();
+llvm::ErrorOr Status = I->status();
+if (!Status)
+  return false;
+llvm::sys::fs::file_type Type = Status->type();
 // If the file is a directory, ignore the name and recurse.
 if (Type == llvm::sys::fs::file_type::directory_file) {
   if (!collectUmbrellaHeaders(File, Dependents))


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


r315378 - Support: Have directory_iterator::status() return FindFirstFileEx/FindNextFile results on Windows.

2017-10-10 Thread Peter Collingbourne via cfe-commits
Author: pcc
Date: Tue Oct 10 15:19:46 2017
New Revision: 315378

URL: http://llvm.org/viewvc/llvm-project?rev=315378=rev
Log:
Support: Have directory_iterator::status() return FindFirstFileEx/FindNextFile 
results on Windows.

This allows clients to avoid an unnecessary fs::status() call on each
directory entry. Because the information returned by FindFirstFileEx
is a subset of the information returned by a regular status() call,
I needed to extract a base class from file_status that contains only
that information.

On my machine, this reduces the time required to enumerate a ThinLTO
cache directory containing 520k files from almost 4 minutes to less
than 2 seconds.

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

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

Modified: cfe/trunk/lib/Basic/VirtualFileSystem.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/VirtualFileSystem.cpp?rev=315378=315377=315378=diff
==
--- cfe/trunk/lib/Basic/VirtualFileSystem.cpp (original)
+++ cfe/trunk/lib/Basic/VirtualFileSystem.cpp Tue Oct 10 15:19:46 2017
@@ -244,7 +244,7 @@ public:
   RealFSDirIter(const Twine , std::error_code ) : Iter(Path, EC) {
 if (!EC && Iter != llvm::sys::fs::directory_iterator()) {
   llvm::sys::fs::file_status S;
-  EC = Iter->status(S);
+  EC = llvm::sys::fs::status(Iter->path(), S, true);
   CurrentEntry = Status::copyWithNewName(S, Iter->path());
 }
   }
@@ -258,7 +258,7 @@ public:
   CurrentEntry = Status();
 } else {
   llvm::sys::fs::file_status S;
-  EC = Iter->status(S);
+  EC = llvm::sys::fs::status(Iter->path(), S, true);
   CurrentEntry = Status::copyWithNewName(S, Iter->path());
 }
 return EC;


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


Re: r313957 - Closure types have no name (and can't have a typedef name for linkage

2017-10-02 Thread Peter Collingbourne via cfe-commits
On Mon, Oct 2, 2017 at 7:02 PM, Richard Smith <rich...@metafoo.co.uk> wrote:

> On 2 October 2017 at 17:10, Peter Collingbourne via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>> Looks like this caused PR34811, which caused a link error on a Chromium
>> bot:
>> https://build.chromium.org/p/chromium.fyi/builders/CFI%20Lin
>> ux%20ToT/builds/7081
>>
>> The link error might be caused by an unrelated LTO bug, but this bug does
>> seem real.
>>
>
> Agreed. This turned out to be a pre-existing bug that we hit a lot more
> often after this change. Fixed in r314754.
>

Thanks for the quick fix!


> That said, this bug would only cause declarations to have default
> visibility when they should have some other visibility (it should only
> cause too much visibility, not too little), and it's not obvious to me how
> that could result in the link error on the Chromium bot.
>

The link error is probably an LTO bug. If a symbol has default visibility
and we are linking a DSO, the symbol is treated by a live root by the
linker. LTO has a mechanism for dead stripping of unused symbol
definitions, and I suspect that this mechanism isn't handling these symbols
correctly (perhaps because they are linkonce_odr?) and stripping
definitions that turn out to be needed for the final link.

Peter


>
>
>> Peter
>>
>> On Thu, Sep 21, 2017 at 9:33 PM, Richard Smith via cfe-commits <
>> cfe-commits@lists.llvm.org> wrote:
>>
>>> Author: rsmith
>>> Date: Thu Sep 21 21:33:20 2017
>>> New Revision: 313957
>>>
>>> URL: http://llvm.org/viewvc/llvm-project?rev=313957=rev
>>> Log:
>>> Closure types have no name (and can't have a typedef name for linkage
>>> purposes), so they never formally have linkage.
>>>
>>> Modified:
>>> cfe/trunk/lib/AST/Decl.cpp
>>> cfe/trunk/test/CXX/basic/basic.link/p8.cpp
>>>
>>> Modified: cfe/trunk/lib/AST/Decl.cpp
>>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Decl.c
>>> pp?rev=313957=313956=313957=diff
>>> 
>>> ==
>>> --- cfe/trunk/lib/AST/Decl.cpp (original)
>>> +++ cfe/trunk/lib/AST/Decl.cpp Thu Sep 21 21:33:20 2017
>>> @@ -1104,24 +1104,25 @@ LinkageInfo LinkageComputer::getLVForClo
>>>else
>>>  Owner = cast(ContextDecl);
>>>
>>> -  // FIXME: If there is no owner, the closure should have no linkage.
>>>if (!Owner)
>>> -return LinkageInfo::external();
>>> +return LinkageInfo::none();
>>>
>>>// If the owner has a deduced type, we need to skip querying the
>>> linkage and
>>>// visibility of that type, because it might involve this closure
>>> type.  The
>>>// only effect of this is that we might give a lambda
>>> VisibleNoLinkage rather
>>>// than NoLinkage when we don't strictly need to, which is benign.
>>>auto *VD = dyn_cast(Owner);
>>> -  LinkageInfo OwnerLinkage =
>>> +  LinkageInfo OwnerLV =
>>>VD && VD->getType()->getContainedDeducedType()
>>>? computeLVForDecl(Owner, computation,
>>> /*IgnoreVarTypeLinkage*/true)
>>>: getLVForDecl(Owner, computation);
>>>
>>> -  // FIXME: This is wrong. A lambda never formally has linkage; if this
>>> -  // calculation determines a lambda has external linkage, it should be
>>> -  // downgraded to VisibleNoLinkage.
>>> -  return OwnerLinkage;
>>> +  // A lambda never formally has linkage. But if the owner is externally
>>> +  // visible, then the lambda is too. We apply the same rules to blocks.
>>> +  if (!isExternallyVisible(OwnerLV.getLinkage()))
>>> +return LinkageInfo::none();
>>> +  return LinkageInfo(VisibleNoLinkage, OwnerLV.getVisibility(),
>>> + OwnerLV.isVisibilityExplicit());
>>>  }
>>>
>>>  LinkageInfo LinkageComputer::getLVForLocalDecl(const NamedDecl *D,
>>>
>>> Modified: cfe/trunk/test/CXX/basic/basic.link/p8.cpp
>>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/basic
>>> /basic.link/p8.cpp?rev=313957=313956=313957=diff
>>> 
>>> ==
>>> --- cfe/trunk/test/CXX/basic/basic.link/p8.cpp (original)
>>> +++ cfe/trunk/test/CXX/basic/basic.link/p8.cpp Thu Sep 21 21:33:20 2017
>>> @@ -14,7 +14,7 @@ typedef decltype(f()) NoLinkage3;
>

Re: r313957 - Closure types have no name (and can't have a typedef name for linkage

2017-10-02 Thread Peter Collingbourne via cfe-commits
Looks like this caused PR34811, which caused a link error on a Chromium bot:
https://build.chromium.org/p/chromium.fyi/builders/CFI%20Linux%20ToT/builds/7081

The link error might be caused by an unrelated LTO bug, but this bug does
seem real. Please take a look.

Peter

On Thu, Sep 21, 2017 at 9:33 PM, Richard Smith via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: rsmith
> Date: Thu Sep 21 21:33:20 2017
> New Revision: 313957
>
> URL: http://llvm.org/viewvc/llvm-project?rev=313957=rev
> Log:
> Closure types have no name (and can't have a typedef name for linkage
> purposes), so they never formally have linkage.
>
> Modified:
> cfe/trunk/lib/AST/Decl.cpp
> cfe/trunk/test/CXX/basic/basic.link/p8.cpp
>
> Modified: cfe/trunk/lib/AST/Decl.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/
> Decl.cpp?rev=313957=313956=313957=diff
> 
> ==
> --- cfe/trunk/lib/AST/Decl.cpp (original)
> +++ cfe/trunk/lib/AST/Decl.cpp Thu Sep 21 21:33:20 2017
> @@ -1104,24 +1104,25 @@ LinkageInfo LinkageComputer::getLVForClo
>else
>  Owner = cast(ContextDecl);
>
> -  // FIXME: If there is no owner, the closure should have no linkage.
>if (!Owner)
> -return LinkageInfo::external();
> +return LinkageInfo::none();
>
>// If the owner has a deduced type, we need to skip querying the
> linkage and
>// visibility of that type, because it might involve this closure
> type.  The
>// only effect of this is that we might give a lambda VisibleNoLinkage
> rather
>// than NoLinkage when we don't strictly need to, which is benign.
>auto *VD = dyn_cast(Owner);
> -  LinkageInfo OwnerLinkage =
> +  LinkageInfo OwnerLV =
>VD && VD->getType()->getContainedDeducedType()
>? computeLVForDecl(Owner, computation,
> /*IgnoreVarTypeLinkage*/true)
>: getLVForDecl(Owner, computation);
>
> -  // FIXME: This is wrong. A lambda never formally has linkage; if this
> -  // calculation determines a lambda has external linkage, it should be
> -  // downgraded to VisibleNoLinkage.
> -  return OwnerLinkage;
> +  // A lambda never formally has linkage. But if the owner is externally
> +  // visible, then the lambda is too. We apply the same rules to blocks.
> +  if (!isExternallyVisible(OwnerLV.getLinkage()))
> +return LinkageInfo::none();
> +  return LinkageInfo(VisibleNoLinkage, OwnerLV.getVisibility(),
> + OwnerLV.isVisibilityExplicit());
>  }
>
>  LinkageInfo LinkageComputer::getLVForLocalDecl(const NamedDecl *D,
>
> Modified: cfe/trunk/test/CXX/basic/basic.link/p8.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/
> basic/basic.link/p8.cpp?rev=313957=313956=313957=diff
> 
> ==
> --- cfe/trunk/test/CXX/basic/basic.link/p8.cpp (original)
> +++ cfe/trunk/test/CXX/basic/basic.link/p8.cpp Thu Sep 21 21:33:20 2017
> @@ -14,7 +14,7 @@ typedef decltype(f()) NoLinkage3;
>  inline auto g() { return [] {}; }
>  typedef decltype(g()) VisibleNoLinkage1;
>  inline auto y = [] {};
> -typedef decltype(x) VisibleNoLinkage2;
> +typedef decltype(y) VisibleNoLinkage2;
>  inline auto h() { struct {} x; return x; }
>  typedef decltype(h()) VisibleNoLinkage3;
>
> @@ -42,19 +42,12 @@ void use_no_linkage() {
>no_linkage3(); // expected-note {{used here}}
>  }
>
> -// FIXME: This should emit an extension warning. It does not because we
> -// incorrectly give the lambda external linkage.
> -extern VisibleNoLinkage1 visible_no_linkage1();
> -
> -// FIXME: We should accept this as an extension. We don't because we
> -// incorrectly give the lambda no linkage instead of "VisibleNoLinkage".
> -extern VisibleNoLinkage2 visible_no_linkage2(); // expected-error {{used
> but not defined}}
> -
> -// This case is correctly accepted as an extension.
> +extern VisibleNoLinkage1 visible_no_linkage1(); // expected-warning {{ISO
> C++ requires a definition}}
> +extern VisibleNoLinkage2 visible_no_linkage2(); // expected-warning {{ISO
> C++ requires a definition}}
>  extern VisibleNoLinkage3 visible_no_linkage3(); // expected-warning {{ISO
> C++ requires a definition}}
>
>  void use_visible_no_linkage() {
> -  visible_no_linkage1();
> +  visible_no_linkage1(); // expected-note {{used here}}
>visible_no_linkage2(); // expected-note {{used here}}
>visible_no_linkage3(); // expected-note {{used here}}
>  }
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>



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


r313201 - Use -- to prevent the driver from confusing paths with flags, should fix Mac bot.

2017-09-13 Thread Peter Collingbourne via cfe-commits
Author: pcc
Date: Wed Sep 13 14:49:17 2017
New Revision: 313201

URL: http://llvm.org/viewvc/llvm-project?rev=313201=rev
Log:
Use -- to prevent the driver from confusing paths with flags, should fix Mac 
bot.

Modified:
cfe/trunk/test/Driver/whole-program-vtables.c

Modified: cfe/trunk/test/Driver/whole-program-vtables.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/whole-program-vtables.c?rev=313201=313200=313201=diff
==
--- cfe/trunk/test/Driver/whole-program-vtables.c (original)
+++ cfe/trunk/test/Driver/whole-program-vtables.c Wed Sep 13 14:49:17 2017
@@ -1,11 +1,11 @@
 // RUN: %clang -target x86_64-unknown-linux -fwhole-program-vtables -### %s 
2>&1 | FileCheck --check-prefix=NO-LTO %s
-// RUN: %clang_cl --target=x86_64-pc-win32 -fwhole-program-vtables -### %s 
2>&1 | FileCheck --check-prefix=NO-LTO %s
+// RUN: %clang_cl --target=x86_64-pc-win32 -fwhole-program-vtables -### -- %s 
2>&1 | FileCheck --check-prefix=NO-LTO %s
 // NO-LTO: invalid argument '-fwhole-program-vtables' only allowed with '-flto'
 
 // RUN: %clang -target x86_64-unknown-linux -fwhole-program-vtables -flto -### 
%s 2>&1 | FileCheck --check-prefix=LTO %s
-// RUN: %clang_cl --target=x86_64-pc-win32 -fwhole-program-vtables -flto -### 
%s 2>&1 | FileCheck --check-prefix=LTO %s
+// RUN: %clang_cl --target=x86_64-pc-win32 -fwhole-program-vtables -flto -### 
-- %s 2>&1 | FileCheck --check-prefix=LTO %s
 // LTO: "-fwhole-program-vtables"
 
 // RUN: %clang -target x86_64-unknown-linux -fwhole-program-vtables 
-fno-whole-program-vtables -flto -### %s 2>&1 | FileCheck 
--check-prefix=LTO-DISABLE %s
-// RUN: %clang_cl --target=x86_64-pc-win32 -fwhole-program-vtables 
-fno-whole-program-vtables -flto -### %s 2>&1 | FileCheck 
--check-prefix=LTO-DISABLE %s
+// RUN: %clang_cl --target=x86_64-pc-win32 -fwhole-program-vtables 
-fno-whole-program-vtables -flto -### -- %s 2>&1 | FileCheck 
--check-prefix=LTO-DISABLE %s
 // LTO-DISABLE-NOT: "-fwhole-program-vtables"


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


r313169 - Driver: Make -fwhole-program-vtables a core option so it can be used from clang-cl.

2017-09-13 Thread Peter Collingbourne via cfe-commits
Author: pcc
Date: Wed Sep 13 11:36:07 2017
New Revision: 313169

URL: http://llvm.org/viewvc/llvm-project?rev=313169=rev
Log:
Driver: Make -fwhole-program-vtables a core option so it can be used from 
clang-cl.

Also add some missing driver tests for the regular clang driver.

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

Modified:
cfe/trunk/include/clang/Driver/Options.td
cfe/trunk/test/Driver/whole-program-vtables.c

Modified: cfe/trunk/include/clang/Driver/Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=313169=313168=313169=diff
==
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Wed Sep 13 11:36:07 2017
@@ -1502,9 +1502,10 @@ def fvisibility_ms_compat : Flag<["-"],
   HelpText<"Give global types 'default' visibility and global functions and "
"variables 'hidden' visibility by default">;
 def fwhole_program_vtables : Flag<["-"], "fwhole-program-vtables">, 
Group,
-  Flags<[CC1Option]>,
+  Flags<[CoreOption, CC1Option]>,
   HelpText<"Enables whole-program vtable optimization. Requires -flto">;
-def fno_whole_program_vtables : Flag<["-"], "fno-whole-program-vtables">, 
Group;
+def fno_whole_program_vtables : Flag<["-"], "fno-whole-program-vtables">, 
Group,
+  Flags<[CoreOption]>;
 def fwrapv : Flag<["-"], "fwrapv">, Group, Flags<[CC1Option]>,
   HelpText<"Treat signed integer overflow as two's complement">;
 def fwritable_strings : Flag<["-"], "fwritable-strings">, Group, 
Flags<[CC1Option]>,

Modified: cfe/trunk/test/Driver/whole-program-vtables.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/whole-program-vtables.c?rev=313169=313168=313169=diff
==
--- cfe/trunk/test/Driver/whole-program-vtables.c (original)
+++ cfe/trunk/test/Driver/whole-program-vtables.c Wed Sep 13 11:36:07 2017
@@ -1,2 +1,11 @@
 // RUN: %clang -target x86_64-unknown-linux -fwhole-program-vtables -### %s 
2>&1 | FileCheck --check-prefix=NO-LTO %s
+// RUN: %clang_cl --target=x86_64-pc-win32 -fwhole-program-vtables -### %s 
2>&1 | FileCheck --check-prefix=NO-LTO %s
 // NO-LTO: invalid argument '-fwhole-program-vtables' only allowed with '-flto'
+
+// RUN: %clang -target x86_64-unknown-linux -fwhole-program-vtables -flto -### 
%s 2>&1 | FileCheck --check-prefix=LTO %s
+// RUN: %clang_cl --target=x86_64-pc-win32 -fwhole-program-vtables -flto -### 
%s 2>&1 | FileCheck --check-prefix=LTO %s
+// LTO: "-fwhole-program-vtables"
+
+// RUN: %clang -target x86_64-unknown-linux -fwhole-program-vtables 
-fno-whole-program-vtables -flto -### %s 2>&1 | FileCheck 
--check-prefix=LTO-DISABLE %s
+// RUN: %clang_cl --target=x86_64-pc-win32 -fwhole-program-vtables 
-fno-whole-program-vtables -flto -### %s 2>&1 | FileCheck 
--check-prefix=LTO-DISABLE %s
+// LTO-DISABLE-NOT: "-fwhole-program-vtables"


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


  1   2   3   4   >