r315015 - Cleanup and generalize -shared-libasan.

2017-10-05 Thread Evgeniy Stepanov via cfe-commits
Author: eugenis
Date: Thu Oct  5 13:14:00 2017
New Revision: 315015

URL: http://llvm.org/viewvc/llvm-project?rev=315015&view=rev
Log:
Cleanup and generalize -shared-libasan.

Summary:
* Rename -shared-libasan to -shared-libsan, keeping the old name as alias.
* Add -static-libsan for targets that default to shared.
* Remove an Android special case. It is now possible (but untested) to use 
static compiler-rt libraries there.
* Support libclang_rt.ubsan_standalone as a shared library.

Unlike GCC, this change applies -shared-libsan / -static-libsan to all 
sanitizers.
I don't see a point in multiple flags like -shared-libubsan, considering that 
most sanitizers
are not compatible with each other, and each link has basically a single 
shared/static choice.

Reviewers: vitalybuka, kcc, rsmith

Subscribers: srhines, cfe-commits

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

Modified:
cfe/trunk/include/clang/Driver/Options.td
cfe/trunk/include/clang/Driver/SanitizerArgs.h
cfe/trunk/lib/Driver/SanitizerArgs.cpp
cfe/trunk/lib/Driver/ToolChains/CommonArgs.cpp
cfe/trunk/lib/Driver/ToolChains/Fuchsia.cpp
cfe/trunk/lib/Driver/ToolChains/MSVC.cpp
cfe/trunk/test/Driver/sanitizer-ld.c

Modified: cfe/trunk/include/clang/Driver/Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=315015&r1=315014&r2=315015&view=diff
==
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Thu Oct  5 13:14:00 2017
@@ -592,7 +592,9 @@ def fapple_kext : Flag<["-"], "fapple-ke
   HelpText<"Use Apple's kernel extensions ABI">;
 def fapple_pragma_pack : Flag<["-"], "fapple-pragma-pack">, Group, 
Flags<[CC1Option]>,
   HelpText<"Enable Apple gcc-compatible #pragma pack handling">;
-def shared_libasan : Flag<["-"], "shared-libasan">;
+def shared_libsan : Flag<["-"], "shared-libsan">;
+def static_libsan : Flag<["-"], "static-libsan">;
+def : Flag<["-"], "shared-libasan">, Alias;
 def fasm : Flag<["-"], "fasm">, Group;
 
 def fasm_blocks : Flag<["-"], "fasm-blocks">, Group, 
Flags<[CC1Option]>;

Modified: cfe/trunk/include/clang/Driver/SanitizerArgs.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/SanitizerArgs.h?rev=315015&r1=315014&r2=315015&view=diff
==
--- cfe/trunk/include/clang/Driver/SanitizerArgs.h (original)
+++ cfe/trunk/include/clang/Driver/SanitizerArgs.h Thu Oct  5 13:14:00 2017
@@ -33,7 +33,7 @@ class SanitizerArgs {
   bool MsanUseAfterDtor = false;
   bool CfiCrossDso = false;
   int AsanFieldPadding = 0;
-  bool AsanSharedRuntime = false;
+  bool SharedRuntime = false;
   bool AsanUseAfterScope = true;
   bool AsanGlobalsDeadStripping = false;
   bool LinkCXXRuntimes = false;
@@ -49,8 +49,9 @@ class SanitizerArgs {
   /// Parses the sanitizer arguments from an argument list.
   SanitizerArgs(const ToolChain &TC, const llvm::opt::ArgList &Args);
 
+  bool needsSharedRt() const { return SharedRuntime; }
+
   bool needsAsanRt() const { return Sanitizers.has(SanitizerKind::Address); }
-  bool needsSharedAsanRt() const { return AsanSharedRuntime; }
   bool needsTsanRt() const { return Sanitizers.has(SanitizerKind::Thread); }
   bool needsMsanRt() const { return Sanitizers.has(SanitizerKind::Memory); }
   bool needsFuzzer() const { return Sanitizers.has(SanitizerKind::Fuzzer); }

Modified: cfe/trunk/lib/Driver/SanitizerArgs.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/SanitizerArgs.cpp?rev=315015&r1=315014&r2=315015&view=diff
==
--- cfe/trunk/lib/Driver/SanitizerArgs.cpp (original)
+++ cfe/trunk/lib/Driver/SanitizerArgs.cpp Thu Oct  5 13:14:00 2017
@@ -610,10 +610,11 @@ SanitizerArgs::SanitizerArgs(const ToolC
   CoverageFeatures |= CoverageFunc;
   }
 
+  SharedRuntime =
+  Args.hasFlag(options::OPT_shared_libsan, options::OPT_static_libsan,
+   TC.getTriple().isAndroid() || TC.getTriple().isOSFuchsia());
+
   if (AllAddedKinds & Address) {
-AsanSharedRuntime =
-Args.hasArg(options::OPT_shared_libasan) ||
-TC.getTriple().isAndroid() || TC.getTriple().isOSFuchsia();
 NeedPIE |= TC.getTriple().isAndroid() || TC.getTriple().isOSFuchsia();
 if (Arg *A =
 Args.getLastArg(options::OPT_fsanitize_address_field_padding)) {

Modified: cfe/trunk/lib/Driver/ToolChains/CommonArgs.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/CommonArgs.cpp?rev=315015&r1=315014&r2=315015&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/CommonArgs.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/CommonArgs.cpp Thu Oct  5 13:14:00 2017
@@ -560,8 +560,20 @@ collectSanitizerRuntimes(const ToolChain

r315921 - Do not link clang_rt.cfi on Android.

2017-10-16 Thread Evgeniy Stepanov via cfe-commits
Author: eugenis
Date: Mon Oct 16 11:02:57 2017
New Revision: 315921

URL: http://llvm.org/viewvc/llvm-project?rev=315921&view=rev
Log:
Do not link clang_rt.cfi on Android.

Summary:
The OS provides cross-dso CFI support starting with Android O.
Trapping mode does not require any runtime at all, and diagnostic mode
requires just ubsan-standalone.

Reviewers: pcc

Subscribers: srhines, cfe-commits

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

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

Modified: cfe/trunk/include/clang/Driver/SanitizerArgs.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/SanitizerArgs.h?rev=315921&r1=315920&r2=315921&view=diff
==
--- cfe/trunk/include/clang/Driver/SanitizerArgs.h (original)
+++ cfe/trunk/include/clang/Driver/SanitizerArgs.h Mon Oct 16 11:02:57 2017
@@ -44,6 +44,8 @@ class SanitizerArgs {
   bool TsanFuncEntryExit = true;
   bool TsanAtomics = true;
   bool MinimalRuntime = false;
+  // True if cross-dso CFI support if provided by the system (i.e. Android).
+  bool ImplicitCfiRuntime = false;
 
  public:
   /// Parses the sanitizer arguments from an argument list.

Modified: cfe/trunk/lib/Driver/SanitizerArgs.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/SanitizerArgs.cpp?rev=315921&r1=315920&r2=315921&view=diff
==
--- cfe/trunk/lib/Driver/SanitizerArgs.cpp (original)
+++ cfe/trunk/lib/Driver/SanitizerArgs.cpp Mon Oct 16 11:02:57 2017
@@ -171,19 +171,23 @@ static SanitizerMask parseSanitizeTrapAr
 }
 
 bool SanitizerArgs::needsUbsanRt() const {
-  return ((Sanitizers.Mask & NeedsUbsanRt & ~TrapSanitizers.Mask) ||
-  CoverageFeatures) &&
- !Sanitizers.has(Address) && !Sanitizers.has(Memory) &&
- !Sanitizers.has(Thread) && !Sanitizers.has(DataFlow) &&
- !Sanitizers.has(Leak) && !CfiCrossDso;
+  // All of these include ubsan.
+  if (needsAsanRt() || needsMsanRt() || needsTsanRt() || needsDfsanRt() ||
+  needsLsanRt() || needsCfiDiagRt())
+return false;
+
+  return (Sanitizers.Mask & NeedsUbsanRt & ~TrapSanitizers.Mask) ||
+ CoverageFeatures;
 }
 
 bool SanitizerArgs::needsCfiRt() const {
-  return !(Sanitizers.Mask & CFI & ~TrapSanitizers.Mask) && CfiCrossDso;
+  return !(Sanitizers.Mask & CFI & ~TrapSanitizers.Mask) && CfiCrossDso &&
+ !ImplicitCfiRuntime;
 }
 
 bool SanitizerArgs::needsCfiDiagRt() const {
-  return (Sanitizers.Mask & CFI & ~TrapSanitizers.Mask) && CfiCrossDso;
+  return (Sanitizers.Mask & CFI & ~TrapSanitizers.Mask) && CfiCrossDso &&
+ !ImplicitCfiRuntime;
 }
 
 bool SanitizerArgs::requiresPIE() const {
@@ -615,6 +619,8 @@ SanitizerArgs::SanitizerArgs(const ToolC
TC.getTriple().isAndroid() || TC.getTriple().isOSFuchsia() 
||
TC.getTriple().isOSDarwin());
 
+  ImplicitCfiRuntime = TC.getTriple().isAndroid();
+
   if (AllAddedKinds & Address) {
 NeedPIE |= TC.getTriple().isAndroid() || TC.getTriple().isOSFuchsia();
 if (Arg *A =

Modified: cfe/trunk/test/Driver/sanitizer-ld.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/sanitizer-ld.c?rev=315921&r1=315920&r2=315921&view=diff
==
--- cfe/trunk/test/Driver/sanitizer-ld.c (original)
+++ cfe/trunk/test/Driver/sanitizer-ld.c Mon Oct 16 11:02:57 2017
@@ -508,6 +508,24 @@
 // CHECK-CFI-CROSS-DSO-DIAG-LINUX: "-whole-archive" 
"{{[^"]*}}libclang_rt.cfi_diag-x86_64.a" "-no-whole-archive"
 // CHECK-CFI-CROSS-DSO-DIAG-LINUX: -export-dynamic
 
+// Cross-DSO CFI on Android does not link runtime libraries.
+// RUN: %clang -fsanitize=cfi -fsanitize-cfi-cross-dso %s -### -o %t.o 2>&1 \
+// RUN: -target aarch64-linux-android -fuse-ld=ld \
+// RUN: --sysroot=%S/Inputs/basic_android_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-CFI-CROSS-DSO-ANDROID %s
+// CHECK-CFI-CROSS-DSO-ANDROID: "{{.*}}ld{{(.exe)?}}"
+// CHECK-CFI-CROSS-DSO-ANDROID-NOT: libclang_rt.
+
+// Cross-DSO CFI with diagnostics on Android links just the UBSAN runtime.
+// RUN: %clang -fsanitize=cfi -fsanitize-cfi-cross-dso %s -### -o %t.o 2>&1 \
+// RUN: -fno-sanitize-trap=cfi -fsanitize-recover=cfi \
+// RUN: -target aarch64-linux-android -fuse-ld=ld \
+// RUN: --sysroot=%S/Inputs/basic_android_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-CFI-CROSS-DSO-DIAG-ANDROID %s
+// CHECK-CFI-CROSS-DSO-DIAG-ANDROID: "{{.*}}ld{{(.exe)?}}"
+// CHECK-CFI-CROSS-DSO-DIAG-ANDROID: 
"{{[^"]*}}libclang_rt.ubsan_standalone-aarch64-android.so"
+// CHECK-CFI-CROSS-DSO-DIAG-ANDROID: "-export-dynamic-symbol=__cfi_check"
+
 // RUN: %clangxx -fsanitize=address %s -### -o %t.o 2>&1 \
 // RUN: -mmacosx-version-min=10.6 \
 // RUN: -target x86_64

r321203 - [hwasan] Implement -fsanitize-recover=hwaddress.

2017-12-20 Thread Evgeniy Stepanov via cfe-commits
Author: eugenis
Date: Wed Dec 20 11:05:44 2017
New Revision: 321203

URL: http://llvm.org/viewvc/llvm-project?rev=321203&view=rev
Log:
[hwasan] Implement -fsanitize-recover=hwaddress.

Summary: Very similar to AddressSanitizer, with the exception of the error type 
encoding.

Reviewers: kcc, alekseyshl

Subscribers: cfe-commits, kubamracek, llvm-commits, hiraditya

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

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=321203&r1=321202&r2=321203&view=diff
==
--- cfe/trunk/lib/CodeGen/BackendUtil.cpp (original)
+++ cfe/trunk/lib/CodeGen/BackendUtil.cpp Wed Dec 20 11:05:44 2017
@@ -239,7 +239,11 @@ static void addKernelAddressSanitizerPas
 
 static void addHWAddressSanitizerPasses(const PassManagerBuilder &Builder,
 legacy::PassManagerBase &PM) {
-  PM.add(createHWAddressSanitizerPass());
+  const PassManagerBuilderWrapper &BuilderWrapper =
+  static_cast(Builder);
+  const CodeGenOptions &CGOpts = BuilderWrapper.getCGOpts();
+  bool Recover = CGOpts.SanitizeRecover.has(SanitizerKind::HWAddress);
+  PM.add(createHWAddressSanitizerPass(Recover));
 }
 
 static void addMemorySanitizerPass(const PassManagerBuilder &Builder,


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


r327165 - Don't use -pie in relocatable link.

2018-03-09 Thread Evgeniy Stepanov via cfe-commits
Author: eugenis
Date: Fri Mar  9 11:35:16 2018
New Revision: 327165

URL: http://llvm.org/viewvc/llvm-project?rev=327165&view=rev
Log:
Don't use -pie in relocatable link.

Summary:
Android, in particular, got PIE enabled by default in r316606. It resulted in
relocatable links passing both -r and -pie to the linker, which is not allowed.

Reviewers: srhines

Subscribers: cfe-commits

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

Modified:
cfe/trunk/lib/Driver/ToolChains/Gnu.cpp
cfe/trunk/test/Driver/android-pie.c

Modified: cfe/trunk/lib/Driver/ToolChains/Gnu.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Gnu.cpp?rev=327165&r1=327164&r2=327165&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Gnu.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Gnu.cpp Fri Mar  9 11:35:16 2018
@@ -307,7 +307,8 @@ static const char *getLDMOption(const ll
 }
 
 static bool getPIE(const ArgList &Args, const toolchains::Linux &ToolChain) {
-  if (Args.hasArg(options::OPT_shared) || Args.hasArg(options::OPT_static))
+  if (Args.hasArg(options::OPT_shared) || Args.hasArg(options::OPT_static) ||
+  Args.hasArg(options::OPT_r))
 return false;
 
   Arg *A = Args.getLastArg(options::OPT_pie, options::OPT_no_pie,

Modified: cfe/trunk/test/Driver/android-pie.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/android-pie.c?rev=327165&r1=327164&r2=327165&view=diff
==
--- cfe/trunk/test/Driver/android-pie.c (original)
+++ cfe/trunk/test/Driver/android-pie.c Fri Mar  9 11:35:16 2018
@@ -64,3 +64,20 @@
 // RUN:   | FileCheck --check-prefix=NO-PIE %s
 // RUN: %clang %s -### -o %t.o 2>&1 -pie -no-pie 
--target=arm-linux-androideabi24 \
 // RUN:   | FileCheck --check-prefix=NO-PIE %s
+
+// Static/shared/relocatable disable -pie
+
+// RUN: %clang %s -### --target=aarch64-linux-android -static 2>&1 \
+// RUN: | FileCheck %s -check-prefix=CHECK-STATIC
+// CHECK-STATIC-NOT: "-pie"
+// CHECK-STATIC: -static
+
+// RUN: %clang %s -### --target=aarch64-linux-android -shared 2>&1 \
+// RUN: | FileCheck %s -check-prefix=CHECK-SHARED
+// CHECK-SHARED-NOT: "-pie"
+// CHECK-SHARED: "-shared"
+
+// RUN: %clang %s -### --target=aarch64-linux-android -r 2>&1 \
+// RUN: | FileCheck %s -check-prefix=CHECK-RELOCATABLE
+// CHECK-RELOCATABLE-NOT: "-pie"
+// CHECK-RELOCATABLE: "-r"


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


r335193 - ASan docs: no_sanitize("address") works on globals.

2018-06-20 Thread Evgeniy Stepanov via cfe-commits
Author: eugenis
Date: Wed Jun 20 17:16:32 2018
New Revision: 335193

URL: http://llvm.org/viewvc/llvm-project?rev=335193&view=rev
Log:
ASan docs: no_sanitize("address") works on globals.

Summary: Mention that no_sanitize attribute can be used with globals.

Reviewers: alekseyshl

Subscribers: cfe-commits

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

Modified:
cfe/trunk/docs/AddressSanitizer.rst
cfe/trunk/include/clang/Basic/AttrDocs.td

Modified: cfe/trunk/docs/AddressSanitizer.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/AddressSanitizer.rst?rev=335193&r1=335192&r2=335193&view=diff
==
--- cfe/trunk/docs/AddressSanitizer.rst (original)
+++ cfe/trunk/docs/AddressSanitizer.rst Wed Jun 20 17:16:32 2018
@@ -197,13 +197,17 @@ this purpose.
 Disabling Instrumentation with ``__attribute__((no_sanitize("address")))``
 --
 
-Some code should not be instrumented by AddressSanitizer. One may use the
-function attribute ``__attribute__((no_sanitize("address")))`` (which has
-deprecated synonyms `no_sanitize_address` and `no_address_safety_analysis`) to
-disable instrumentation of a particular function. This attribute may not be
-supported by other compilers, so we suggest to use it together with
+Some code should not be instrumented by AddressSanitizer. One may use
+the attribute ``__attribute__((no_sanitize("address")))`` (which has
+deprecated synonyms `no_sanitize_address` and
+`no_address_safety_analysis`) to disable instrumentation of a
+particular function. This attribute may not be supported by other
+compilers, so we suggest to use it together with
 ``__has_feature(address_sanitizer)``.
 
+The same attribute used on a global variable prevents AddressSanitizer
+from adding redzones around it and detecting out of bounds accesses.
+
 Suppressing Errors in Recompiled Code (Blacklist)
 -
 

Modified: cfe/trunk/include/clang/Basic/AttrDocs.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/AttrDocs.td?rev=335193&r1=335192&r2=335193&view=diff
==
--- cfe/trunk/include/clang/Basic/AttrDocs.td (original)
+++ cfe/trunk/include/clang/Basic/AttrDocs.td Wed Jun 20 17:16:32 2018
@@ -1804,13 +1804,14 @@ This attribute accepts a single paramete
 def NoSanitizeDocs : Documentation {
   let Category = DocCatFunction;
   let Content = [{
-Use the ``no_sanitize`` attribute on a function declaration to specify
-that a particular instrumentation or set of instrumentations should not be
-applied to that function. The attribute takes a list of string literals,
-which have the same meaning as values accepted by the ``-fno-sanitize=``
-flag. For example, ``__attribute__((no_sanitize("address", "thread")))``
-specifies that AddressSanitizer and ThreadSanitizer should not be applied
-to the function.
+Use the ``no_sanitize`` attribute on a function or a global variable
+declaration to specify that a particular instrumentation or set of
+instrumentations should not be applied. The attribute takes a list of
+string literals, which have the same meaning as values accepted by the
+``-fno-sanitize=`` flag. For example,
+``__attribute__((no_sanitize("address", "thread")))`` specifies that
+AddressSanitizer and ThreadSanitizer should not be applied to the
+function or variable.
 
 See :ref:`Controlling Code Generation ` for a
 full list of supported sanitizer flags.
@@ -1825,9 +1826,9 @@ def NoSanitizeAddressDocs : Documentatio
   let Content = [{
 .. _langext-address_sanitizer:
 
-Use ``__attribute__((no_sanitize_address))`` on a function declaration to
-specify that address safety instrumentation (e.g. AddressSanitizer) should
-not be applied to that function.
+Use ``__attribute__((no_sanitize_address))`` on a function or a global
+variable declaration to specify that address safety instrumentation
+(e.g. AddressSanitizer) should not be applied.
   }];
 }
 


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


r335305 - Ignore blacklist when generating __cfi_check_fail.

2018-06-21 Thread Evgeniy Stepanov via cfe-commits
Author: eugenis
Date: Thu Jun 21 16:22:37 2018
New Revision: 335305

URL: http://llvm.org/viewvc/llvm-project?rev=335305&view=rev
Log:
Ignore blacklist when generating __cfi_check_fail.

Summary: Fixes PR37898.

Reviewers: pcc, vlad.tsyrklevich

Subscribers: cfe-commits

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

Modified:
cfe/trunk/lib/CodeGen/CGExpr.cpp
cfe/trunk/test/CodeGen/cfi-check-fail2.c

Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=335305&r1=335304&r2=335305&view=diff
==
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Thu Jun 21 16:22:37 2018
@@ -3075,6 +3075,11 @@ void CodeGenFunction::EmitCfiCheckFail()
   StartFunction(GlobalDecl(), CGM.getContext().VoidTy, F, FI, Args,
 SourceLocation());
 
+  // This function should not be affected by blacklist. This function does
+  // not have a source location, but "src:*" would still apply. Revert any
+  // changes to SanOpts made in StartFunction.
+  SanOpts = CGM.getLangOpts().Sanitize;
+
   llvm::Value *Data =
   EmitLoadOfScalar(GetAddrOfLocalVar(&ArgData), /*Volatile=*/false,
CGM.getContext().VoidPtrTy, ArgData.getLocation());

Modified: cfe/trunk/test/CodeGen/cfi-check-fail2.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/cfi-check-fail2.c?rev=335305&r1=335304&r2=335305&view=diff
==
--- cfe/trunk/test/CodeGen/cfi-check-fail2.c (original)
+++ cfe/trunk/test/CodeGen/cfi-check-fail2.c Thu Jun 21 16:22:37 2018
@@ -3,6 +3,12 @@
 // RUN: -fsanitize=cfi-vcall \
 // RUN: -emit-llvm -o - %s | FileCheck %s
 
+// Check that blacklist does not affect generated code.
+// RUN: echo "src:*" > %t-all.blacklist
+// RUN: %clang_cc1 -triple x86_64-unknown-linux -O0 -fsanitize-cfi-cross-dso \
+// RUN: -fsanitize=cfi-vcall -fsanitize-blacklist=%t-all.blacklist \
+// RUN: -emit-llvm -o - %s | FileCheck %s
+
 void caller(void (*f)()) {
   f();
 }


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


r312029 - Minimal runtime for UBSan.

2017-08-29 Thread Evgeniy Stepanov via cfe-commits
Author: eugenis
Date: Tue Aug 29 13:03:51 2017
New Revision: 312029

URL: http://llvm.org/viewvc/llvm-project?rev=312029&view=rev
Log:
Minimal runtime for UBSan.

Summary:
An implementation of ubsan runtime library suitable for use in production.

Minimal attack surface.
* No stack traces.
* Definitely no C++ demangling.
* No UBSAN_OPTIONS=log_file=/path (very suid-unfriendly). And no UBSAN_OPTIONS 
in general.
* as simple as possible

Minimal CPU and RAM overhead.
* Source locations unnecessary in the presence of (split) debug info.
* Values and types (as in A+B overflows T) can be reconstructed from 
register/stack dumps, once you know what type of error you are looking at.
* above two items save 3% binary size.

When UBSan is used with -ftrap-function=abort, sometimes it is hard to reason 
about failures. This library replaces abort with a slightly more informative 
message without much extra overhead. Since ubsan interface in not stable, this 
code must reside in compiler-rt.

Reviewers: pcc, kcc

Subscribers: srhines, mgorny, aprantl, krytarowski, llvm-commits

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

Added:
cfe/trunk/test/CodeGen/unsigned-overflow-minimal.c
Modified:
cfe/trunk/include/clang/Driver/Options.td
cfe/trunk/include/clang/Driver/SanitizerArgs.h
cfe/trunk/include/clang/Frontend/CodeGenOptions.def
cfe/trunk/lib/CodeGen/CGExpr.cpp
cfe/trunk/lib/Driver/SanitizerArgs.cpp
cfe/trunk/lib/Driver/ToolChains/CommonArgs.cpp
cfe/trunk/lib/Frontend/CompilerInvocation.cpp
cfe/trunk/test/Driver/fsanitize.c
cfe/trunk/test/Driver/sanitizer-ld.c

Modified: cfe/trunk/include/clang/Driver/Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=312029&r1=312028&r2=312029&view=diff
==
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Tue Aug 29 13:03:51 2017
@@ -885,6 +885,10 @@ def fsanitize_undefined_trap_on_error :
 Group;
 def fno_sanitize_undefined_trap_on_error : Flag<["-"], 
"fno-sanitize-undefined-trap-on-error">,
Group;
+def fsanitize_minimal_runtime : Flag<["-"], "fsanitize-minimal-runtime">,
+Group;
+def fno_sanitize_minimal_runtime : Flag<["-"], "fno-sanitize-minimal-runtime">,
+Group;
 def fsanitize_link_cxx_runtime : Flag<["-"], "fsanitize-link-c++-runtime">,
  Group;
 def fsanitize_cfi_cross_dso : Flag<["-"], "fsanitize-cfi-cross-dso">,

Modified: cfe/trunk/include/clang/Driver/SanitizerArgs.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/SanitizerArgs.h?rev=312029&r1=312028&r2=312029&view=diff
==
--- cfe/trunk/include/clang/Driver/SanitizerArgs.h (original)
+++ cfe/trunk/include/clang/Driver/SanitizerArgs.h Tue Aug 29 13:03:51 2017
@@ -43,6 +43,7 @@ class SanitizerArgs {
   bool TsanMemoryAccess = true;
   bool TsanFuncEntryExit = true;
   bool TsanAtomics = true;
+  bool MinimalRuntime = false;
 
  public:
   /// Parses the sanitizer arguments from an argument list.
@@ -58,6 +59,7 @@ class SanitizerArgs {
!Sanitizers.has(SanitizerKind::Address);
   }
   bool needsUbsanRt() const;
+  bool requiresMinimalRuntime() const { return MinimalRuntime; }
   bool needsDfsanRt() const { return Sanitizers.has(SanitizerKind::DataFlow); }
   bool needsSafeStackRt() const { return SafeStackRuntime; }
   bool needsCfiRt() const;

Modified: cfe/trunk/include/clang/Frontend/CodeGenOptions.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/CodeGenOptions.def?rev=312029&r1=312028&r2=312029&view=diff
==
--- cfe/trunk/include/clang/Frontend/CodeGenOptions.def (original)
+++ cfe/trunk/include/clang/Frontend/CodeGenOptions.def Tue Aug 29 13:03:51 2017
@@ -152,6 +152,8 @@ CODEGENOPT(SanitizeMemoryTrackOrigins, 2
 CODEGENOPT(SanitizeMemoryUseAfterDtor, 1, 0) ///< Enable use-after-delete 
detection
  ///< in MemorySanitizer
 CODEGENOPT(SanitizeCfiCrossDso, 1, 0) ///< Enable cross-dso support in CFI.
+CODEGENOPT(SanitizeMinimalRuntime, 1, 0) ///< Use "_minimal" sanitizer runtime 
for
+ ///< diagnostics.
 CODEGENOPT(SanitizeCoverageType, 2, 0) ///< Type of sanitizer coverage
///< instrumentation.
 CODEGENOPT(SanitizeCoverageIndirectCalls, 1, 0) ///< Enable sanitizer coverage

Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=312029&r1=312028&r2=312029&view=diff
===

r312048 - Restore clang_rt library name on i686-android.

2017-08-29 Thread Evgeniy Stepanov via cfe-commits
Author: eugenis
Date: Tue Aug 29 15:12:31 2017
New Revision: 312048

URL: http://llvm.org/viewvc/llvm-project?rev=312048&view=rev
Log:
Restore clang_rt library name on i686-android.

Summary:
Recent changes canonicalized clang_rt library names to refer to
"i386" on all x86 targets. Android historically uses i686.

This change adds a special case to keep i686 in all clang_rt
libraries when targeting Android.

Reviewers: hans, mgorny, beanz

Subscribers: srhines, cfe-commits, llvm-commits

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

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

Modified: cfe/trunk/lib/Driver/ToolChain.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChain.cpp?rev=312048&r1=312047&r2=312048&view=diff
==
--- cfe/trunk/lib/Driver/ToolChain.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChain.cpp Tue Aug 29 15:12:31 2017
@@ -305,6 +305,10 @@ static StringRef getArchNameForCompilerR
? "armhf"
: "arm";
 
+  // For historic reasons, Android library is using i686 instead of i386.
+  if (TC.getArch() == llvm::Triple::x86 && Triple.isAndroid())
+return "i686";
+
   return llvm::Triple::getArchTypeName(TC.getArch());
 }
 

Modified: cfe/trunk/test/Driver/sanitizer-ld.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/sanitizer-ld.c?rev=312048&r1=312047&r2=312048&view=diff
==
--- cfe/trunk/test/Driver/sanitizer-ld.c (original)
+++ cfe/trunk/test/Driver/sanitizer-ld.c Tue Aug 29 15:12:31 2017
@@ -133,6 +133,18 @@
 // CHECK-ASAN-ANDROID-NOT: "-lpthread"
 //
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
+// RUN: -target i686-linux-android -fuse-ld=ld -fsanitize=address \
+// RUN: --sysroot=%S/Inputs/basic_android_tree/sysroot \
+// RUN:   | FileCheck --check-prefix=CHECK-ASAN-ANDROID-X86 %s
+//
+// CHECK-ASAN-ANDROID-X86: "{{(.*[^.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
+// CHECK-ASAN-ANDROID-X86-NOT: "-lc"
+// CHECK-ASAN-ANDROID-X86: "-pie"
+// CHECK-ASAN-ANDROID-X86-NOT: "-lpthread"
+// CHECK-ASAN-ANDROID-X86: libclang_rt.asan-i686-android.so"
+// CHECK-ASAN-ANDROID-X86-NOT: "-lpthread"
+//
+// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
 // RUN: -target arm-linux-androideabi -fsanitize=address \
 // RUN: --sysroot=%S/Inputs/basic_android_tree/sysroot \
 // RUN: -shared-libasan \


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


r312361 - Enable check-ubsan-minimal in standalone compiler-rt build.

2017-09-01 Thread Evgeniy Stepanov via cfe-commits
Author: eugenis
Date: Fri Sep  1 13:37:20 2017
New Revision: 312361

URL: http://llvm.org/viewvc/llvm-project?rev=312361&view=rev
Log:
Enable check-ubsan-minimal in standalone compiler-rt build.

Modified:
cfe/trunk/runtime/CMakeLists.txt

Modified: cfe/trunk/runtime/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/runtime/CMakeLists.txt?rev=312361&r1=312360&r2=312361&view=diff
==
--- cfe/trunk/runtime/CMakeLists.txt (original)
+++ cfe/trunk/runtime/CMakeLists.txt Fri Sep  1 13:37:20 2017
@@ -108,7 +108,7 @@ if(LLVM_BUILD_EXTERNAL_COMPILER_RT AND E
 USES_TERMINAL)
 
   # Add top-level targets that build specific compiler-rt runtimes.
-  set(COMPILER_RT_RUNTIMES asan builtins dfsan lsan msan profile tsan ubsan)
+  set(COMPILER_RT_RUNTIMES asan builtins dfsan lsan msan profile tsan ubsan 
ubsan-minimal)
   foreach(runtime ${COMPILER_RT_RUNTIMES})
 get_ext_project_build_command(build_runtime_cmd ${runtime})
 add_custom_target(${runtime}
@@ -125,7 +125,7 @@ if(LLVM_BUILD_EXTERNAL_COMPILER_RT AND E
 
 # Add top-level targets for various compiler-rt test suites.
 set(COMPILER_RT_TEST_SUITES check-asan check-asan-dynamic check-dfsan
-  check-lsan check-msan check-sanitizer check-tsan check-ubsan
+  check-lsan check-msan check-sanitizer check-tsan check-ubsan 
check-ubsan-minimal
   check-profile check-cfi check-cfi-and-supported check-safestack)
 foreach(test_suite ${COMPILER_RT_TEST_SUITES})
   get_ext_project_build_command(run_test_suite ${test_suite})


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


r366123 - ARM MTE stack sanitizer.

2019-07-15 Thread Evgeniy Stepanov via cfe-commits
Author: eugenis
Date: Mon Jul 15 13:02:23 2019
New Revision: 366123

URL: http://llvm.org/viewvc/llvm-project?rev=366123&view=rev
Log:
ARM MTE stack sanitizer.

Add "memtag" sanitizer that detects and mitigates stack memory issues
using armv8.5 Memory Tagging Extension.

It is similar in principle to HWASan, which is a software implementation
of the same idea, but there are enough differencies to warrant a new
sanitizer type IMHO. It is also expected to have very different
performance properties.

The new sanitizer does not have a runtime library (it may grow one
later, along with a "debugging" mode). Similar to SafeStack and
StackProtector, the instrumentation pass (in a follow up change) will be
inserted in all cases, but will only affect functions marked with the
new sanitize_memtag attribute.

Reviewers: pcc, hctim, vitalybuka, ostannard

Subscribers: srhines, mehdi_amini, javed.absar, kristof.beyls, hiraditya, 
cryptoad, steven_wu, dexonsmith, cfe-commits, llvm-commits

Tags: #clang, #llvm

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

Added:
cfe/trunk/test/CodeGen/memtag-attr.cpp
cfe/trunk/test/Lexer/has_feature_memtag_sanitizer.cpp
Modified:
cfe/trunk/include/clang/Basic/Features.def
cfe/trunk/include/clang/Basic/Sanitizers.def
cfe/trunk/lib/CodeGen/CGDeclCXX.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
cfe/trunk/lib/CodeGen/SanitizerMetadata.cpp
cfe/trunk/lib/Driver/SanitizerArgs.cpp
cfe/trunk/lib/Driver/ToolChains/Linux.cpp
cfe/trunk/test/Driver/fsanitize.c
cfe/trunk/test/SemaCXX/attr-no-sanitize.cpp

Modified: cfe/trunk/include/clang/Basic/Features.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Features.def?rev=366123&r1=366122&r2=366123&view=diff
==
--- cfe/trunk/include/clang/Basic/Features.def (original)
+++ cfe/trunk/include/clang/Basic/Features.def Mon Jul 15 13:02:23 2019
@@ -42,6 +42,7 @@ FEATURE(address_sanitizer,
 FEATURE(hwaddress_sanitizer,
 LangOpts.Sanitize.hasOneOf(SanitizerKind::HWAddress |
SanitizerKind::KernelHWAddress))
+FEATURE(memtag_sanitizer, LangOpts.Sanitize.has(SanitizerKind::MemTag))
 FEATURE(xray_instrument, LangOpts.XRayInstrument)
 FEATURE(undefined_behavior_sanitizer,
 LangOpts.Sanitize.hasOneOf(SanitizerKind::Undefined))

Modified: cfe/trunk/include/clang/Basic/Sanitizers.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Sanitizers.def?rev=366123&r1=366122&r2=366123&view=diff
==
--- cfe/trunk/include/clang/Basic/Sanitizers.def (original)
+++ cfe/trunk/include/clang/Basic/Sanitizers.def Mon Jul 15 13:02:23 2019
@@ -55,6 +55,9 @@ SANITIZER("hwaddress", HWAddress)
 // Kernel Hardware-assisted AddressSanitizer (KHWASan)
 SANITIZER("kernel-hwaddress", KernelHWAddress)
 
+// A variant of AddressSanitizer using AArch64 MTE extension.
+SANITIZER("memtag", MemTag)
+
 // MemorySanitizer
 SANITIZER("memory", Memory)
 

Modified: cfe/trunk/lib/CodeGen/CGDeclCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDeclCXX.cpp?rev=366123&r1=366122&r2=366123&view=diff
==
--- cfe/trunk/lib/CodeGen/CGDeclCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDeclCXX.cpp Mon Jul 15 13:02:23 2019
@@ -369,6 +369,10 @@ llvm::Function *CodeGenModule::CreateGlo
   !isInSanitizerBlacklist(SanitizerKind::KernelHWAddress, Fn, Loc))
 Fn->addFnAttr(llvm::Attribute::SanitizeHWAddress);
 
+  if (getLangOpts().Sanitize.has(SanitizerKind::MemTag) &&
+  !isInSanitizerBlacklist(SanitizerKind::MemTag, Fn, Loc))
+Fn->addFnAttr(llvm::Attribute::SanitizeMemTag);
+
   if (getLangOpts().Sanitize.has(SanitizerKind::Thread) &&
   !isInSanitizerBlacklist(SanitizerKind::Thread, Fn, Loc))
 Fn->addFnAttr(llvm::Attribute::SanitizeThread);

Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.cpp?rev=366123&r1=366122&r2=366123&view=diff
==
--- cfe/trunk/lib/CodeGen/CodeGenFunction.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.cpp Mon Jul 15 13:02:23 2019
@@ -696,6 +696,8 @@ void CodeGenFunction::StartFunction(Glob
 Fn->addFnAttr(llvm::Attribute::SanitizeAddress);
   if (SanOpts.hasOneOf(SanitizerKind::HWAddress | 
SanitizerKind::KernelHWAddress))
 Fn->addFnAttr(llvm::Attribute::SanitizeHWAddress);
+  if (SanOpts.has(SanitizerKind::MemTag))
+Fn->addFnAttr(llvm::Attribute::SanitizeMemTag);
   if (SanOpts.has(SanitizerKind::Thread))
 Fn->addFnAttr(llvm::Attribute::SanitizeThread);
   if (SanOpts.hasOneOf(SanitizerKind::Memory | SanitizerKind::KernelMemory))

Modified: cfe/trunk/l

r350361 - [cmake] Fix monorepo + LLVM_BUILD_EXTERNAL_COMPILER_RT=ON.

2019-01-03 Thread Evgeniy Stepanov via cfe-commits
Author: eugenis
Date: Thu Jan  3 14:41:10 2019
New Revision: 350361

URL: http://llvm.org/viewvc/llvm-project?rev=350361&view=rev
Log:
[cmake] Fix monorepo + LLVM_BUILD_EXTERNAL_COMPILER_RT=ON.

In cmake 3.10.2, if (${VARIABLE_NAME}) seems to always be false no
matter what documentation says (or maybe I just failed at reading).

Anyway, if (VARIABLE_NAME) seems to do what this code intended.

Modified:
cfe/trunk/runtime/CMakeLists.txt

Modified: cfe/trunk/runtime/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/runtime/CMakeLists.txt?rev=350361&r1=350360&r2=350361&view=diff
==
--- cfe/trunk/runtime/CMakeLists.txt (original)
+++ cfe/trunk/runtime/CMakeLists.txt Thu Jan  3 14:41:10 2019
@@ -28,7 +28,7 @@ set(COMPILER_RT_SRC_ROOT ${LLVM_MAIN_SRC
 # variable) as in add_llvm_external_project
 if(NOT EXISTS ${COMPILER_RT_SRC_ROOT})
   # We don't want to set it if LLVM_EXTERNAL_COMPILER_RT_SOURCE_DIR is ""
-  if(${LLVM_EXTERNAL_COMPILER_RT_SOURCE_DIR})
+  if(LLVM_EXTERNAL_COMPILER_RT_SOURCE_DIR)
 set(COMPILER_RT_SRC_ROOT ${LLVM_EXTERNAL_COMPILER_RT_SOURCE_DIR})
   endif()
 endif()


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


r350363 - Fix check-hwasan with LLVM_BUILD_EXTERNAL_COMPILER_RT=ON

2019-01-03 Thread Evgeniy Stepanov via cfe-commits
Author: eugenis
Date: Thu Jan  3 14:50:45 2019
New Revision: 350363

URL: http://llvm.org/viewvc/llvm-project?rev=350363&view=rev
Log:
Fix check-hwasan with LLVM_BUILD_EXTERNAL_COMPILER_RT=ON

Add a forwarding target for check-hwasan in clang.

Modified:
cfe/trunk/runtime/CMakeLists.txt

Modified: cfe/trunk/runtime/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/runtime/CMakeLists.txt?rev=350363&r1=350362&r2=350363&view=diff
==
--- cfe/trunk/runtime/CMakeLists.txt (original)
+++ cfe/trunk/runtime/CMakeLists.txt Thu Jan  3 14:50:45 2019
@@ -126,7 +126,7 @@ if(LLVM_BUILD_EXTERNAL_COMPILER_RT AND E
   FileCheck count not llvm-nm llvm-objdump llvm-symbolizer)
 
 # Add top-level targets for various compiler-rt test suites.
-set(COMPILER_RT_TEST_SUITES check-fuzzer check-asan check-asan-dynamic 
check-dfsan
+set(COMPILER_RT_TEST_SUITES check-fuzzer check-asan check-hwasan 
check-asan-dynamic check-dfsan
   check-lsan check-msan check-sanitizer check-tsan check-ubsan 
check-ubsan-minimal
   check-profile check-cfi check-cfi-and-supported check-safestack)
 foreach(test_suite ${COMPILER_RT_TEST_SUITES})


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


r372925 - Fix memory leak in DeclTest.

2019-09-25 Thread Evgeniy Stepanov via cfe-commits
Author: eugenis
Date: Wed Sep 25 15:38:20 2019
New Revision: 372925

URL: http://llvm.org/viewvc/llvm-project?rev=372925&view=rev
Log:
Fix memory leak in DeclTest.

Fixes a leak introduced in r372903, detected on the ASan bot.
http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-fast/builds/35430/steps/check-clang%20asan/logs/stdio

Direct leak of 192 byte(s) in 1 object(s) allocated from:
#0 0x561d88 in operator new(unsigned long) 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/compiler-rt/lib/asan/asan_new_delete.cc:105
#1 0x1a48779 in clang::ItaniumMangleContext::create(clang::ASTContext&, 
clang::DiagnosticsEngine&) 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/AST/ItaniumMangle.cpp:5134:10
#2 0xdff000 in Decl_AsmLabelAttr_Test::TestBody() 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/unittests/AST/DeclTest.cpp:97:23

Modified:
cfe/trunk/unittests/AST/DeclTest.cpp

Modified: cfe/trunk/unittests/AST/DeclTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/AST/DeclTest.cpp?rev=372925&r1=372924&r2=372925&view=diff
==
--- cfe/trunk/unittests/AST/DeclTest.cpp (original)
+++ cfe/trunk/unittests/AST/DeclTest.cpp Wed Sep 25 15:38:20 2019
@@ -94,7 +94,8 @@ TEST(Decl, AsmLabelAttr) {
 
   // Mangle the decl names.
   std::string MangleF, MangleG;
-  MangleContext *MC = ItaniumMangleContext::create(Ctx, Diags);
+  std::unique_ptr MC(
+  ItaniumMangleContext::create(Ctx, Diags));
   {
 llvm::raw_string_ostream OS_F(MangleF);
 llvm::raw_string_ostream OS_G(MangleG);


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


r335684 - Revert "[MS] Use mangled names and comdats for string merging with ASan"

2018-06-26 Thread Evgeniy Stepanov via cfe-commits
Author: eugenis
Date: Tue Jun 26 16:10:48 2018
New Revision: 335684

URL: http://llvm.org/viewvc/llvm-project?rev=335684&view=rev
Log:
Revert "[MS] Use mangled names and comdats for string merging with ASan"

Depends on r334313, which has been reverted in r335681.

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=335684&r1=335683&r2=335684&view=diff
==
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Tue Jun 26 16:10:48 2018
@@ -4155,13 +4155,15 @@ CodeGenModule::GetAddrOfConstantStringFr
   StringRef GlobalVariableName;
   llvm::GlobalValue::LinkageTypes LT;
 
-  // Mangle the string literal if that's how the ABI merges duplicate strings.
-  // Don't do it if they are writable, since we don't want writes in one TU to
-  // affect strings in another.
-  if (getCXXABI().getMangleContext().shouldMangleStringLiteral(S) &&
-  !LangOpts.WritableStrings) {
+  // Mangle the string literal if the ABI allows for it.  However, we cannot
+  // do this if  we are compiling with ASan or -fwritable-strings because they
+  // rely on strings having normal linkage.
+  if (!LangOpts.WritableStrings &&
+  !LangOpts.Sanitize.has(SanitizerKind::Address) &&
+  getCXXABI().getMangleContext().shouldMangleStringLiteral(S)) {
 llvm::raw_svector_ostream Out(MangledNameBuffer);
 getCXXABI().getMangleContext().mangleStringLiteral(S, Out);
+
 LT = llvm::GlobalValue::LinkOnceODRLinkage;
 GlobalVariableName = MangledNameBuffer;
   } else {


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


r336715 - Revert r336591 "[libclang] NFC, simplify clang_Cursor_Evaluate"

2018-07-10 Thread Evgeniy Stepanov via cfe-commits
Author: eugenis
Date: Tue Jul 10 12:48:53 2018
New Revision: 336715

URL: http://llvm.org/viewvc/llvm-project?rev=336715&view=rev
Log:
Revert r336591 "[libclang] NFC, simplify clang_Cursor_Evaluate"

This change is blocking r336590 which is being reverted due to memory leaks.

Modified:
cfe/trunk/tools/libclang/CIndex.cpp

Modified: cfe/trunk/tools/libclang/CIndex.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=336715&r1=336714&r2=336715&view=diff
==
--- cfe/trunk/tools/libclang/CIndex.cpp (original)
+++ cfe/trunk/tools/libclang/CIndex.cpp Tue Jul 10 12:48:53 2018
@@ -3889,32 +3889,33 @@ static const ExprEvalResult* evaluateExp
   return nullptr;
 }
 
-static const Expr *evaluateDeclExpr(const Decl *D) {
-  if (!D)
-return nullptr;
-  if (auto *Var = dyn_cast(D))
-return Var->getInit();
-  else if (auto *Field = dyn_cast(D))
-return Field->getInClassInitializer();
-  return nullptr;
-}
-
-static const Expr *evaluateCompoundStmtExpr(const CompoundStmt *CS) {
-  assert(CS && "invalid compound statement");
-  for (auto *bodyIterator : CS->body()) {
-if (const auto *E = dyn_cast(bodyIterator))
-  return E;
+CXEvalResult clang_Cursor_Evaluate(CXCursor C) {
+  if (clang_getCursorKind(C) == CXCursor_CompoundStmt) {
+const CompoundStmt *compoundStmt = cast(getCursorStmt(C));
+Expr *expr = nullptr;
+for (auto *bodyIterator : compoundStmt->body()) {
+  if ((expr = dyn_cast(bodyIterator))) {
+break;
+  }
+}
+if (expr)
+  return const_cast(
+  reinterpret_cast(evaluateExpr(expr, C)));
   }
-  return nullptr;
-}
 
-CXEvalResult clang_Cursor_Evaluate(CXCursor C) {
-  if (const Expr *E =
-  clang_getCursorKind(C) == CXCursor_CompoundStmt
-  ? evaluateCompoundStmtExpr(cast(getCursorStmt(C)))
-  : evaluateDeclExpr(getCursorDecl(C)))
-return const_cast(
-reinterpret_cast(evaluateExpr(const_cast(E), 
C)));
+  const Decl *D = getCursorDecl(C);
+  if (D) {
+const Expr *expr = nullptr;
+if (auto *Var = dyn_cast(D)) {
+  expr = Var->getInit();
+} else if (auto *Field = dyn_cast(D)) {
+  expr = Field->getInClassInitializer();
+}
+if (expr)
+  return const_cast(reinterpret_cast(
+  evaluateExpr(const_cast(expr), C)));
+return nullptr;
+  }
   return nullptr;
 }
 


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


r336716 - Revert r336590 "[libclang] evalute compound statement cursors before trying to evaluate"

2018-07-10 Thread Evgeniy Stepanov via cfe-commits
Author: eugenis
Date: Tue Jul 10 12:49:07 2018
New Revision: 336716

URL: http://llvm.org/viewvc/llvm-project?rev=336716&view=rev
Log:
Revert r336590 "[libclang] evalute compound statement cursors before trying to 
evaluate"

New memory leaks in
LibclangParseTest_EvaluateChildExpression_Test::TestBody()

Modified:
cfe/trunk/tools/libclang/CIndex.cpp
cfe/trunk/unittests/libclang/LibclangTest.cpp

Modified: cfe/trunk/tools/libclang/CIndex.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=336716&r1=336715&r2=336716&view=diff
==
--- cfe/trunk/tools/libclang/CIndex.cpp (original)
+++ cfe/trunk/tools/libclang/CIndex.cpp Tue Jul 10 12:49:07 2018
@@ -3890,19 +3890,6 @@ static const ExprEvalResult* evaluateExp
 }
 
 CXEvalResult clang_Cursor_Evaluate(CXCursor C) {
-  if (clang_getCursorKind(C) == CXCursor_CompoundStmt) {
-const CompoundStmt *compoundStmt = cast(getCursorStmt(C));
-Expr *expr = nullptr;
-for (auto *bodyIterator : compoundStmt->body()) {
-  if ((expr = dyn_cast(bodyIterator))) {
-break;
-  }
-}
-if (expr)
-  return const_cast(
-  reinterpret_cast(evaluateExpr(expr, C)));
-  }
-
   const Decl *D = getCursorDecl(C);
   if (D) {
 const Expr *expr = nullptr;
@@ -3916,6 +3903,19 @@ CXEvalResult clang_Cursor_Evaluate(CXCur
   evaluateExpr(const_cast(expr), C)));
 return nullptr;
   }
+
+  const CompoundStmt *compoundStmt = 
dyn_cast_or_null(getCursorStmt(C));
+  if (compoundStmt) {
+Expr *expr = nullptr;
+for (auto *bodyIterator : compoundStmt->body()) {
+  if ((expr = dyn_cast(bodyIterator))) {
+break;
+  }
+}
+if (expr)
+  return const_cast(
+  reinterpret_cast(evaluateExpr(expr, C)));
+  }
   return nullptr;
 }
 

Modified: cfe/trunk/unittests/libclang/LibclangTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/libclang/LibclangTest.cpp?rev=336716&r1=336715&r2=336716&view=diff
==
--- cfe/trunk/unittests/libclang/LibclangTest.cpp (original)
+++ cfe/trunk/unittests/libclang/LibclangTest.cpp Tue Jul 10 12:49:07 2018
@@ -461,47 +461,6 @@ TEST_F(LibclangParseTest, AllSkippedRang
   clang_disposeSourceRangeList(Ranges);
 }
 
-TEST_F(LibclangParseTest, EvaluateChildExpression) {
-  std::string Main = "main.m";
-  WriteFile(Main, "#define kFOO @\"foo\"\n"
-  "void foobar(void) {\n"
-  " {kFOO;}\n"
-  "}\n");
-  ClangTU = clang_parseTranslationUnit(Index, Main.c_str(), nullptr, 0, 
nullptr,
-   0, TUFlags);
-
-  CXCursor C = clang_getTranslationUnitCursor(ClangTU);
-  clang_visitChildren(
-  C,
-  [](CXCursor cursor, CXCursor parent,
- CXClientData client_data) -> CXChildVisitResult {
-if (clang_getCursorKind(cursor) == CXCursor_FunctionDecl) {
-  int numberedStmt = 0;
-  clang_visitChildren(
-  cursor,
-  [](CXCursor cursor, CXCursor parent,
- CXClientData client_data) -> CXChildVisitResult {
-int &numberedStmt = *((int *)client_data);
-if (clang_getCursorKind(cursor) == CXCursor_CompoundStmt) {
-  if (numberedStmt) {
-CXEvalResult RE = clang_Cursor_Evaluate(cursor);
-EXPECT_NE(RE, nullptr);
-EXPECT_EQ(clang_EvalResult_getKind(RE),
-  CXEval_ObjCStrLiteral);
-return CXChildVisit_Break;
-  }
-  numberedStmt++;
-}
-return CXChildVisit_Recurse;
-  },
-  &numberedStmt);
-  EXPECT_EQ(numberedStmt, 1);
-}
-return CXChildVisit_Continue;
-  },
-  nullptr);
-}
-
 class LibclangReparseTest : public LibclangParseTest {
 public:
   void DisplayDiagnostics() {


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


Re: [PATCH] D24693: [CodeGen] Don't emit lifetime intrinsics for some local variables

2016-09-19 Thread Evgeniy Stepanov via cfe-commits
eugenis added inline comments.


Comment at: lib/CodeGen/VarBypassDetector.h:50
@@ +49,3 @@
+public:
+  void Reset(const Stmt *Body);
+

rename to smth like StartFunction()?
add some API documentation.


https://reviews.llvm.org/D24693



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


Re: [PATCH] D24693: [CodeGen] Don't emit lifetime intrinsics for some local variables

2016-09-28 Thread Evgeniy Stepanov via cfe-commits
eugenis added a comment.

In https://reviews.llvm.org/D24693#553474, @vitalybuka wrote:

> My assumption is that "start" makes access valid, and "end" makes access 
> invalid, up to the next "start".


That's also my understanding, but LangRef does not say anything about 
llvm.lifetime.start cancelling the effects of llvm.lifetime.end.

llvm.lifetime.end:
Any stores into the memory object following this intrinsic may be removed as 
dead.


https://reviews.llvm.org/D24693



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


[PATCH] D25453: Add -fno-sanitize-address-use-after-scope flag

2016-10-10 Thread Evgeniy Stepanov via cfe-commits
eugenis accepted this revision.
eugenis added a comment.
This revision is now accepted and ready to land.

LGTM




Comment at: lib/Frontend/CompilerInvocation.cpp:739
+  UasArg &&
+  UasArg->getOption().matches(OPT_fsanitize_address_use_after_scope);
   Opts.SSPBufferSize =

Consider doing this the same way as EmitLLVMUseLists above to avoid a function 
level declaration.



Comment at: test/Driver/fsanitize.c:124
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=address %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-ASAN-WITHOUT-USE-AFTER-SCOPE
+// CHECK-ASAN-WITHOUT-USE-AFTER-SCOPE-NOT: -cc1{{.*}}address-use-after-scope
 

Check the case
-fno-sanitize-address-use-after-scope -fsanitize-address-use-after-scope


https://reviews.llvm.org/D25453



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


r320232 - Hardware-assisted AddressSanitizer (clang part).

2017-12-08 Thread Evgeniy Stepanov via cfe-commits
Author: eugenis
Date: Fri Dec  8 17:32:07 2017
New Revision: 320232

URL: http://llvm.org/viewvc/llvm-project?rev=320232&view=rev
Log:
Hardware-assisted AddressSanitizer (clang part).

Summary:
Driver, frontend and LLVM codegen for HWASan.
A clone of ASan, basically.

Reviewers: kcc, pcc, alekseyshl

Subscribers: srhines, javed.absar, cfe-commits

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

Added:
cfe/trunk/test/CodeGen/address-safety-attr-kasan-hwasan.cpp
cfe/trunk/test/Driver/Inputs/resource_dir/hwasan_blacklist.txt

cfe/trunk/test/Driver/Inputs/resource_dir/lib/linux/libclang_rt.hwasan-aarch64.a.syms
Modified:
cfe/trunk/include/clang/Basic/Sanitizers.def
cfe/trunk/include/clang/Driver/SanitizerArgs.h
cfe/trunk/lib/CodeGen/BackendUtil.cpp
cfe/trunk/lib/CodeGen/CGDeclCXX.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
cfe/trunk/lib/CodeGen/SanitizerMetadata.cpp
cfe/trunk/lib/Driver/SanitizerArgs.cpp
cfe/trunk/lib/Driver/ToolChains/CommonArgs.cpp
cfe/trunk/lib/Driver/ToolChains/Linux.cpp
cfe/trunk/lib/Lex/PPMacroExpansion.cpp
cfe/trunk/test/Driver/asan.c
cfe/trunk/test/Driver/fsanitize-blacklist.c
cfe/trunk/test/Driver/fsanitize-coverage.c
cfe/trunk/test/Driver/fsanitize.c
cfe/trunk/test/Driver/sanitize_unwind_tables.c
cfe/trunk/test/Driver/sanitizer-ld.c
cfe/trunk/test/Lexer/has_feature_address_sanitizer.cpp
cfe/trunk/test/SemaCXX/attr-no-sanitize.cpp

Modified: cfe/trunk/include/clang/Basic/Sanitizers.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Sanitizers.def?rev=320232&r1=320231&r2=320232&view=diff
==
--- cfe/trunk/include/clang/Basic/Sanitizers.def (original)
+++ cfe/trunk/include/clang/Basic/Sanitizers.def Fri Dec  8 17:32:07 2017
@@ -44,6 +44,8 @@ SANITIZER("address", Address)
 // Kernel AddressSanitizer (KASan)
 SANITIZER("kernel-address", KernelAddress)
 
+SANITIZER("hwaddress", HWAddress)
+
 // MemorySanitizer
 SANITIZER("memory", Memory)
 

Modified: cfe/trunk/include/clang/Driver/SanitizerArgs.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/SanitizerArgs.h?rev=320232&r1=320231&r2=320232&view=diff
==
--- cfe/trunk/include/clang/Driver/SanitizerArgs.h (original)
+++ cfe/trunk/include/clang/Driver/SanitizerArgs.h Fri Dec  8 17:32:07 2017
@@ -55,12 +55,14 @@ class SanitizerArgs {
   bool needsSharedRt() const { return SharedRuntime; }
 
   bool needsAsanRt() const { return Sanitizers.has(SanitizerKind::Address); }
+  bool needsHwasanRt() const { return 
Sanitizers.has(SanitizerKind::HWAddress); }
   bool needsTsanRt() const { return Sanitizers.has(SanitizerKind::Thread); }
   bool needsMsanRt() const { return Sanitizers.has(SanitizerKind::Memory); }
   bool needsFuzzer() const { return Sanitizers.has(SanitizerKind::Fuzzer); }
   bool needsLsanRt() const {
 return Sanitizers.has(SanitizerKind::Leak) &&
-   !Sanitizers.has(SanitizerKind::Address);
+   !Sanitizers.has(SanitizerKind::Address) &&
+   !Sanitizers.has(SanitizerKind::HWAddress);
   }
   bool needsUbsanRt() const;
   bool requiresMinimalRuntime() const { return MinimalRuntime; }

Modified: cfe/trunk/lib/CodeGen/BackendUtil.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/BackendUtil.cpp?rev=320232&r1=320231&r2=320232&view=diff
==
--- cfe/trunk/lib/CodeGen/BackendUtil.cpp (original)
+++ cfe/trunk/lib/CodeGen/BackendUtil.cpp Fri Dec  8 17:32:07 2017
@@ -237,6 +237,11 @@ static void addKernelAddressSanitizerPas
   /*Recover*/true));
 }
 
+static void addHWAddressSanitizerPasses(const PassManagerBuilder &Builder,
+legacy::PassManagerBase &PM) {
+  PM.add(createHWAddressSanitizerPass());
+}
+
 static void addMemorySanitizerPass(const PassManagerBuilder &Builder,
legacy::PassManagerBase &PM) {
   const PassManagerBuilderWrapper &BuilderWrapper =
@@ -556,6 +561,13 @@ void EmitAssemblyHelper::CreatePasses(le
addKernelAddressSanitizerPasses);
   }
 
+  if (LangOpts.Sanitize.has(SanitizerKind::HWAddress)) {
+PMBuilder.addExtension(PassManagerBuilder::EP_OptimizerLast,
+   addHWAddressSanitizerPasses);
+PMBuilder.addExtension(PassManagerBuilder::EP_EnabledOnOptLevel0,
+   addHWAddressSanitizerPasses);
+  }
+
   if (LangOpts.Sanitize.has(SanitizerKind::Memory)) {
 PMBuilder.addExtension(PassManagerBuilder::EP_OptimizerLast,
addMemorySanitizerPass);

Modified: cfe/trunk/lib/CodeGen/CGDeclCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/C

r320233 - Fix fsanitize-blacklist test on Windows.

2017-12-08 Thread Evgeniy Stepanov via cfe-commits
Author: eugenis
Date: Fri Dec  8 18:15:42 2017
New Revision: 320233

URL: http://llvm.org/viewvc/llvm-project?rev=320233&view=rev
Log:
Fix fsanitize-blacklist test on Windows.

Broken in r320232.

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=320233&r1=320232&r2=320233&view=diff
==
--- cfe/trunk/test/Driver/fsanitize-blacklist.c (original)
+++ cfe/trunk/test/Driver/fsanitize-blacklist.c Fri Dec  8 18:15:42 2017
@@ -22,9 +22,9 @@
 
 // Check that the default blacklist is not added as an extra dependency.
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=address 
-resource-dir=%S/Inputs/resource_dir %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-DEFAULT-BLACKLIST-ASAN --implicit-check-not=fdepfile-entry
-// CHECK-DEFAULT-BLACKLIST-ASAN: -fsanitize-blacklist={{.*}}/asan_blacklist.txt
+// CHECK-DEFAULT-BLACKLIST-ASAN: 
-fsanitize-blacklist={{.*[^w]}}asan_blacklist.txt
 // RUN: %clang -target aarch64-linux-gnu -fsanitize=hwaddress 
-resource-dir=%S/Inputs/resource_dir %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-DEFAULT-BLACKLIST-HWASAN 
--implicit-check-not=fdepfile-entry
-// CHECK-DEFAULT-BLACKLIST-HWASAN: 
-fsanitize-blacklist={{.*}}/hwasan_blacklist.txt
+// CHECK-DEFAULT-BLACKLIST-HWASAN: 
-fsanitize-blacklist={{.*}}hwasan_blacklist.txt
 
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=integer 
-resource-dir=%S/Inputs/resource_dir %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-DEFAULT-UBSAN-BLACKLIST --implicit-check-not=fdepfile-entry
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=nullability 
-resource-dir=%S/Inputs/resource_dir %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-DEFAULT-UBSAN-BLACKLIST --implicit-check-not=fdepfile-entry


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


r329241 - Enable msan unconditionally on Linux.

2018-04-04 Thread Evgeniy Stepanov via cfe-commits
Author: eugenis
Date: Wed Apr  4 16:48:06 2018
New Revision: 329241

URL: http://llvm.org/viewvc/llvm-project?rev=329241&view=rev
Log:
Enable msan unconditionally on Linux.

Memory sanitizer compatibility are already done in
MemorySanitizer::doInitialization. It verifies whether the necessary offsets
exist and bails out if not. For this reason it is no good to duplicate two
checks in two projects. This patch removes clang check and postpones msan
compatibility validation till MemorySanitizer::doInitialization.

Another reason for this patch is to allow using msan with any CPU (given
compatible runtime) and custom mapping provided via the arguments added by
https://reviews.llvm.org/D44926.

Patch by vit9696.

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

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

Modified: cfe/trunk/lib/Driver/ToolChains/Linux.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Linux.cpp?rev=329241&r1=329240&r2=329241&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Linux.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Linux.cpp Wed Apr  4 16:48:06 2018
@@ -884,6 +884,7 @@ SanitizerMask Linux::getSupportedSanitiz
   Res |= SanitizerKind::Fuzzer;
   Res |= SanitizerKind::FuzzerNoLink;
   Res |= SanitizerKind::KernelAddress;
+  Res |= SanitizerKind::Memory;
   Res |= SanitizerKind::Vptr;
   Res |= SanitizerKind::SafeStack;
   if (IsX86_64 || IsMIPS64 || IsAArch64)
@@ -892,8 +893,6 @@ SanitizerMask Linux::getSupportedSanitiz
 Res |= SanitizerKind::Leak;
   if (IsX86_64 || IsMIPS64 || IsAArch64 || IsPowerPC64)
 Res |= SanitizerKind::Thread;
-  if (IsX86_64 || IsMIPS64 || IsPowerPC64 || IsAArch64)
-Res |= SanitizerKind::Memory;
   if (IsX86_64 || IsMIPS64)
 Res |= SanitizerKind::Efficiency;
   if (IsX86 || IsX86_64)

Modified: cfe/trunk/test/Driver/fsanitize.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/fsanitize.c?rev=329241&r1=329240&r2=329241&view=diff
==
--- cfe/trunk/test/Driver/fsanitize.c (original)
+++ cfe/trunk/test/Driver/fsanitize.c Wed Apr  4 16:48:06 2018
@@ -308,9 +308,6 @@
 // CHECK-DIAG1: unsupported argument 'zzz' to option 'fsanitize='
 // CHECK-DIAG1-NOT: unsupported argument 'zzz' to option 'fsanitize='
 
-// RUN: %clang -target i686-linux-gnu -fsanitize=memory %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-MSAN-X86
-// CHECK-MSAN-X86: error: unsupported option '-fsanitize=memory' for target 
'i686--linux-gnu'
-
 // RUN: %clang -target x86_64-apple-darwin10 -fsanitize=memory %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-MSAN-DARWIN
 // CHECK-MSAN-DARWIN: unsupported option '-fsanitize=memory' for target 
'x86_64-apple-darwin10'
 


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


r316606 - Enable -pie and --enable-new-dtags by default on Android.

2017-10-25 Thread Evgeniy Stepanov via cfe-commits
Author: eugenis
Date: Wed Oct 25 13:39:22 2017
New Revision: 316606

URL: http://llvm.org/viewvc/llvm-project?rev=316606&view=rev
Log:
Enable -pie and --enable-new-dtags by default on Android.

Summary:
Also enable -no-pie on Gnu toolchain (previously available on Darwin only).

Non-PIE executables won't even start on recent Android, and DT_RPATH is ignored 
by the loader.

Reviewers: srhines, danalbert

Subscribers: cfe-commits

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

Added:
cfe/trunk/test/Driver/android-pie.c
Modified:
cfe/trunk/lib/Driver/SanitizerArgs.cpp
cfe/trunk/lib/Driver/ToolChains/Gnu.cpp
cfe/trunk/lib/Driver/ToolChains/Linux.cpp
cfe/trunk/test/Driver/fsanitize.c
cfe/trunk/test/Driver/linux-ld.c
cfe/trunk/test/Driver/pic.c
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=316606&r1=316605&r2=316606&view=diff
==
--- cfe/trunk/lib/Driver/SanitizerArgs.cpp (original)
+++ cfe/trunk/lib/Driver/SanitizerArgs.cpp Wed Oct 25 13:39:22 2017
@@ -622,7 +622,7 @@ SanitizerArgs::SanitizerArgs(const ToolC
   ImplicitCfiRuntime = TC.getTriple().isAndroid();
 
   if (AllAddedKinds & Address) {
-NeedPIE |= TC.getTriple().isAndroid() || TC.getTriple().isOSFuchsia();
+NeedPIE |= TC.getTriple().isOSFuchsia();
 if (Arg *A =
 Args.getLastArg(options::OPT_fsanitize_address_field_padding)) {
 StringRef S = A->getValue();

Modified: cfe/trunk/lib/Driver/ToolChains/Gnu.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Gnu.cpp?rev=316606&r1=316605&r2=316606&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Gnu.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Gnu.cpp Wed Oct 25 13:39:22 2017
@@ -282,6 +282,17 @@ static const char *getLDMOption(const ll
   }
 }
 
+static bool getPIE(const ArgList &Args, const toolchains::Linux &ToolChain) {
+  if (Args.hasArg(options::OPT_shared) || Args.hasArg(options::OPT_static))
+return false;
+
+  Arg *A = Args.getLastArg(options::OPT_pie, options::OPT_no_pie,
+   options::OPT_nopie);
+  if (!A)
+return ToolChain.isPIEDefault();
+  return A->getOption().matches(options::OPT_pie);
+}
+
 void tools::gnutools::Linker::ConstructJob(Compilation &C, const JobAction &JA,
const InputInfo &Output,
const InputInfoList &Inputs,
@@ -296,9 +307,7 @@ void tools::gnutools::Linker::ConstructJ
   const llvm::Triple::ArchType Arch = ToolChain.getArch();
   const bool isAndroid = ToolChain.getTriple().isAndroid();
   const bool IsIAMCU = ToolChain.getTriple().isOSIAMCU();
-  const bool IsPIE =
-  !Args.hasArg(options::OPT_shared) && !Args.hasArg(options::OPT_static) &&
-  (Args.hasArg(options::OPT_pie) || ToolChain.isPIEDefault());
+  const bool IsPIE = getPIE(Args, ToolChain);
   const bool HasCRTBeginEndFiles =
   ToolChain.getTriple().hasEnvironment() ||
   (ToolChain.getTriple().getVendor() != llvm::Triple::MipsTechnologies);

Modified: cfe/trunk/lib/Driver/ToolChains/Linux.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Linux.cpp?rev=316606&r1=316605&r2=316606&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Linux.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Linux.cpp Wed Oct 25 13:39:22 2017
@@ -248,7 +248,7 @@ Linux::Linux(const Driver &D, const llvm
   ExtraOpts.push_back("--build-id");
 #endif
 
-  if (Distro.IsOpenSUSE())
+  if (IsAndroid || Distro.IsOpenSUSE())
 ExtraOpts.push_back("--enable-new-dtags");
 
   // The selection of paths to try here is designed to match the patterns which
@@ -810,7 +810,10 @@ void Linux::AddIAMCUIncludeArgs(const Ar
   }
 }
 
-bool Linux::isPIEDefault() const { return getSanitizerArgs().requiresPIE(); }
+bool Linux::isPIEDefault() const {
+  return (getTriple().isAndroid() && !getTriple().isAndroidVersionLT(16)) ||
+ getSanitizerArgs().requiresPIE();
+}
 
 SanitizerMask Linux::getSupportedSanitizers() const {
   const bool IsX86 = getTriple().getArch() == llvm::Triple::x86;

Added: cfe/trunk/test/Driver/android-pie.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/android-pie.c?rev=316606&view=auto
==
--- cfe/trunk/test/Driver/android-pie.c (added)
+++ cfe/trunk/test/Driver/android-pie.c Wed Oct 25 13:39:22 2017
@@ -0,0 +1,66 @@
+// NO-PIE-NOT: "-pie"
+// PIE: "-pie"
+
+// RUN: %clang %s -### -o %t.o 2>&1 --target=arm-linux-androideabi \
+// RUN:   | FileCheck --check-prefix=NO-PIE %s
+// RUN: %clang %s -### -o %t.o 2>&1 --target=arm-linux-andr

r280028 - Fix typo in test.

2016-08-29 Thread Evgeniy Stepanov via cfe-commits
Author: eugenis
Date: Mon Aug 29 18:15:46 2016
New Revision: 280028

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

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=280028&r1=280027&r2=280028&view=diff
==
--- cfe/trunk/test/Driver/sanitizer-ld.c (original)
+++ cfe/trunk/test/Driver/sanitizer-ld.c Mon Aug 29 18:15:46 2016
@@ -439,7 +439,7 @@
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o -shared 2>&1 \
 // RUN: -target arm-linux-androideabi -fsanitize=safe-stack \
 // RUN: --sysroot=%S/Inputs/basic_android_tree \
-// RUN:   | FileCheck --check-prefix=CHECK-SAFESTACK-ANDROID-ARM %s
+// RUN:   | FileCheck --check-prefix=CHECK-SAFESTACK-SHARED-ANDROID-ARM %s
 //
 // CHECK-SAFESTACK-SHARED-ANDROID-ARM: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
 // CHECK-SAFESTACK-SHARED-ANDROID-ARM-NOT: libclang_rt.safestack


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


r280031 - [cfi] Export __cfi_check when linking with -fsanitize-cfi-cross-dso.

2016-08-29 Thread Evgeniy Stepanov via cfe-commits
Author: eugenis
Date: Mon Aug 29 18:42:34 2016
New Revision: 280031

URL: http://llvm.org/viewvc/llvm-project?rev=280031&view=rev
Log:
[cfi] Export __cfi_check when linking with -fsanitize-cfi-cross-dso.

Multi-DSO CFI model requires every DSO to export a __cfi_check function.

Modified:
cfe/trunk/include/clang/Driver/SanitizerArgs.h
cfe/trunk/lib/Driver/Tools.cpp
cfe/trunk/test/Driver/sanitizer-ld.c

Modified: cfe/trunk/include/clang/Driver/SanitizerArgs.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/SanitizerArgs.h?rev=280031&r1=280030&r2=280031&view=diff
==
--- cfe/trunk/include/clang/Driver/SanitizerArgs.h (original)
+++ cfe/trunk/include/clang/Driver/SanitizerArgs.h Mon Aug 29 18:42:34 2016
@@ -66,6 +66,7 @@ class SanitizerArgs {
   bool requiresPIE() const;
   bool needsUnwindTables() const;
   bool linkCXXRuntimes() const { return LinkCXXRuntimes; }
+  bool hasCrossDsoCfi() const { return CfiCrossDso; }
   void addArgs(const ToolChain &TC, const llvm::opt::ArgList &Args,
llvm::opt::ArgStringList &CmdArgs, types::ID InputType) const;
 };

Modified: cfe/trunk/lib/Driver/Tools.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=280031&r1=280030&r2=280031&view=diff
==
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Mon Aug 29 18:42:34 2016
@@ -3194,6 +3194,11 @@ static bool addSanitizerRuntimes(const T
   // to be dynamic to be sure we export sanitizer interface functions.
   if (AddExportDynamic)
 CmdArgs.push_back("-export-dynamic");
+
+  const SanitizerArgs &SanArgs = TC.getSanitizerArgs();
+  if (SanArgs.hasCrossDsoCfi() && !AddExportDynamic)
+CmdArgs.push_back("-export-dynamic-symbol=__cfi_check");
+
   return !StaticRuntimes.empty();
 }
 

Modified: cfe/trunk/test/Driver/sanitizer-ld.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/sanitizer-ld.c?rev=280031&r1=280030&r2=280031&view=diff
==
--- cfe/trunk/test/Driver/sanitizer-ld.c (original)
+++ cfe/trunk/test/Driver/sanitizer-ld.c Mon Aug 29 18:42:34 2016
@@ -365,6 +365,7 @@
 // RUN:   | FileCheck --check-prefix=CHECK-CFI-CROSS-DSO-LINUX %s
 // CHECK-CFI-CROSS-DSO-LINUX: "{{.*}}ld{{(.exe)?}}"
 // CHECK-CFI-CROSS-DSO-LINUX: "-whole-archive" 
"{{[^"]*}}libclang_rt.cfi-x86_64.a" "-no-whole-archive"
+// CHECK-CFI-CROSS-DSO-LINUX: -export-dynamic
 
 // Cross-DSO CFI with diagnostics links just the CFI runtime.
 // RUN: %clang -fsanitize=cfi -fsanitize-cfi-cross-dso %s -### -o %t.o 2>&1 \
@@ -374,6 +375,7 @@
 // RUN:   | FileCheck --check-prefix=CHECK-CFI-CROSS-DSO-DIAG-LINUX %s
 // CHECK-CFI-CROSS-DSO-DIAG-LINUX: "{{.*}}ld{{(.exe)?}}"
 // CHECK-CFI-CROSS-DSO-DIAG-LINUX: "-whole-archive" 
"{{[^"]*}}libclang_rt.cfi_diag-x86_64.a" "-no-whole-archive"
+// CHECK-CFI-CROSS-DSO-DIAG-LINUX: -export-dynamic
 
 // RUN: %clangxx -fsanitize=address %s -### -o %t.o 2>&1 \
 // RUN: -mmacosx-version-min=10.6 \
@@ -452,6 +454,26 @@
 // CHECK-SAFESTACK-ANDROID-AARCH64: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
 // CHECK-SAFESTACK-ANDROID-AARCH64-NOT: libclang_rt.safestack
 
+// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
+// RUN: -target arm-linux-androideabi -fsanitize=cfi \
+// RUN: --sysroot=%S/Inputs/basic_android_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-CFI-ANDROID %s
+//
+// CHECK-CFI-ANDROID: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
+// CHECK-CFI-ANDROID-NOT: libclang_rt.cfi
+// CHECK-CFI-ANDROID-NOT: __cfi_check
+
+// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
+// RUN: -target arm-linux-androideabi -fsanitize=cfi \
+// RUN: -fsanitize-cfi-cross-dso \
+// RUN: --sysroot=%S/Inputs/basic_android_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-CROSSDSO-CFI-ANDROID %s
+//
+// CHECK-CROSSDSO-CFI-ANDROID: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
+// CHECK-CROSSDSO-CFI-ANDROID-NOT: libclang_rt.cfi
+// CHECK-CROSSDSO-CFI-ANDROID: -export-dynamic-symbol=__cfi_check
+// CHECK-CROSSDSO-CFI-ANDROID-NOT: libclang_rt.cfi
+
 // RUN: %clang -fsanitize=undefined %s -### -o %t.o 2>&1 \
 // RUN: -target x86_64-scei-ps4 \
 // RUN: -shared \


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


Re: [PATCH] D24048: [Driver] [Darwin] Add sanitizer libraries even if -nodefaultlibs is passed

2016-09-02 Thread Evgeniy Stepanov via cfe-commits
eugenis added a comment.

I would also expect -nodefaultlibs and -nostdlib to remove all standard 
libraries from the link command line, including the sanitizer ones.

I like the idea of -flink-sanitizer-runtime=address, but may be without 
"address" - the set of sanitizer runtime libraries can be found from 
-fsanitize=* flags.

Alternatively, we could extend (or add something like) -print-libgcc-name to 
report the set of sanitizer link flags (there may be multiple libraries and 
possible other flags).


https://reviews.llvm.org/D24048



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


Re: [PATCH] D24642: Use __attribute__((internal_linkage)) when available.

2016-09-15 Thread Evgeniy Stepanov via cfe-commits
eugenis accepted this revision.
eugenis added a comment.
This revision is now accepted and ready to land.

Looks great.
Thank you for seeing it through!


https://reviews.llvm.org/D24642



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


r299806 - [cfi] Emit __cfi_check stub in the frontend.

2017-04-07 Thread Evgeniy Stepanov via cfe-commits
Author: eugenis
Date: Fri Apr  7 18:00:38 2017
New Revision: 299806

URL: http://llvm.org/viewvc/llvm-project?rev=299806&view=rev
Log:
[cfi] Emit __cfi_check stub in the frontend.

Previously __cfi_check was created in LTO optimization pipeline, which
means LLD has no way of knowing about the existence of this symbol
without rescanning the LTO output object. As a result, LLD fails to
export __cfi_check, even when given --export-dynamic-symbol flag.

Modified:
cfe/trunk/lib/CodeGen/CGExpr.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.h
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
cfe/trunk/test/CodeGen/cfi-check-fail.c

Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=299806&r1=299805&r2=299806&view=diff
==
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Fri Apr  7 18:00:38 2017
@@ -2783,6 +2783,24 @@ void CodeGenFunction::EmitCfiSlowPathChe
   EmitBlock(Cont);
 }
 
+// Emit a stub for __cfi_check function so that the linker knows about this
+// symbol in LTO mode.
+void CodeGenFunction::EmitCfiCheckStub() {
+  llvm::Module *M = &CGM.getModule();
+  auto &Ctx = M->getContext();
+  llvm::Function *F = llvm::Function::Create(
+  llvm::FunctionType::get(VoidTy, {Int64Ty, Int8PtrTy, Int8PtrTy}, false),
+  llvm::GlobalValue::WeakAnyLinkage, "__cfi_check", M);
+  llvm::BasicBlock *BB = llvm::BasicBlock::Create(Ctx, "entry", F);
+  // FIXME: consider emitting an intrinsic call like
+  // call void @llvm.cfi_check(i64 %0, i8* %1, i8* %2)
+  // which can be lowered in CrossDSOCFI pass to the actual contents of
+  // __cfi_check. This would allow inlining of __cfi_check calls.
+  llvm::CallInst::Create(
+  llvm::Intrinsic::getDeclaration(M, llvm::Intrinsic::trap), "", BB);
+  llvm::ReturnInst::Create(Ctx, nullptr, BB);
+}
+
 // This function is basically a switch over the CFI failure kind, which is
 // extracted from CFICheckFailData (1st function argument). Each case is either
 // llvm.trap or a call to one of the two runtime handlers, based on

Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.h?rev=299806&r1=299805&r2=299806&view=diff
==
--- cfe/trunk/lib/CodeGen/CodeGenFunction.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.h Fri Apr  7 18:00:38 2017
@@ -3524,6 +3524,9 @@ public:
   /// "trap-func-name" if specified.
   llvm::CallInst *EmitTrapCall(llvm::Intrinsic::ID IntrID);
 
+  /// \brief Emit a stub for the cross-DSO CFI check function.
+  void EmitCfiCheckStub();
+
   /// \brief Emit a cross-DSO CFI failure handling function.
   void EmitCfiCheckFail();
 

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=299806&r1=299805&r2=299806&view=diff
==
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Fri Apr  7 18:00:38 2017
@@ -406,8 +406,10 @@ void CodeGenModule::Release() {
   EmitDeferredUnusedCoverageMappings();
   if (CoverageMapping)
 CoverageMapping->emit();
-  if (CodeGenOpts.SanitizeCfiCrossDso)
+  if (CodeGenOpts.SanitizeCfiCrossDso) {
 CodeGenFunction(*this).EmitCfiCheckFail();
+CodeGenFunction(*this).EmitCfiCheckStub();
+  }
   emitAtAvailableLinkGuard();
   emitLLVMUsed();
   if (SanStats)

Modified: cfe/trunk/test/CodeGen/cfi-check-fail.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/cfi-check-fail.c?rev=299806&r1=299805&r2=299806&view=diff
==
--- cfe/trunk/test/CodeGen/cfi-check-fail.c (original)
+++ cfe/trunk/test/CodeGen/cfi-check-fail.c Fri Apr  7 18:00:38 2017
@@ -72,3 +72,8 @@ void caller(void (*f)()) {
 
 // CHECK: [[CONT5]]:
 // CHECK:   ret void
+
+// CHECK: define weak void @__cfi_check(i64, i8*, i8*)
+// CHECK-NOT: }
+// CHECK: call void @llvm.trap()
+// CHECK-NEXT: ret void


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


r307341 - Update Cross-DSO CFI documentation.

2017-07-06 Thread Evgeniy Stepanov via cfe-commits
Author: eugenis
Date: Thu Jul  6 17:48:12 2017
New Revision: 307341

URL: http://llvm.org/viewvc/llvm-project?rev=307341&view=rev
Log:
Update Cross-DSO CFI documentation.

Reviewers: pcc

Subscribers: llvm-commits

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

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=307341&r1=307340&r2=307341&view=diff
==
--- cfe/trunk/docs/ControlFlowIntegrityDesign.rst (original)
+++ cfe/trunk/docs/ControlFlowIntegrityDesign.rst Thu Jul  6 17:48:12 2017
@@ -437,12 +437,17 @@ export this information, every DSO imple
 
 .. code-block:: none
 
-   void __cfi_check(uint64 CallSiteTypeId, void *TargetAddr)
+   void __cfi_check(uint64 CallSiteTypeId, void *TargetAddr, void *DiagData)
 
-This function provides external modules with access to CFI checks for the
-targets inside this DSO.  For each known ``CallSiteTypeId``, this function
-performs an ``llvm.type.test`` with the corresponding type identifier. It
-aborts if the type is unknown, or if the check fails.
+This function provides external modules with access to CFI checks for
+the targets inside this DSO.  For each known ``CallSiteTypeId``, this
+function performs an ``llvm.type.test`` with the corresponding type
+identifier. It reports an error if the type is unknown, or if the
+check fails. Depending on the values of compiler flags
+``-fsanitize-trap`` and ``-fsanitize-recover``, this function may
+print an error, abort and/or return to the caller. ``DiagData`` is an
+opaque pointer to the diagnostic information about the error, or
+``null`` if the caller does not provide this information.
 
 The basic implementation is a large switch statement over all values
 of CallSiteTypeId supported by this DSO, and each case is similar to
@@ -452,11 +457,10 @@ CFI Shadow
 --
 
 To route CFI checks to the target DSO's __cfi_check function, a
-mapping from possible virtual / indirect call targets to
-the corresponding __cfi_check functions is maintained. This mapping is
+mapping from possible virtual / indirect call targets to the
+corresponding __cfi_check functions is maintained. This mapping is
 implemented as a sparse array of 2 bytes for every possible page (4096
-bytes) of memory. The table is kept readonly (FIXME: not yet) most of
-the time.
+bytes) of memory. The table is kept readonly most of the time.
 
 There are 3 types of shadow values:
 
@@ -481,14 +485,24 @@ them.
 CFI_SlowPath
 
 
-The slow path check is implemented in compiler-rt library as
+The slow path check is implemented in a runtime support library as
 
 .. code-block:: none
 
   void __cfi_slowpath(uint64 CallSiteTypeId, void *TargetAddr)
+  void __cfi_slowpath_diag(uint64 CallSiteTypeId, void *TargetAddr, void 
*DiagData)
 
-This functions loads a shadow value for ``TargetAddr``, finds the
-address of __cfi_check as described above and calls that.
+These functions loads a shadow value for ``TargetAddr``, finds the
+address of ``__cfi_check`` as described above and calls
+that. ``DiagData`` is an opaque pointer to diagnostic data which is
+passed verbatim to ``__cfi_check``, and ``__cfi_slowpath`` passes
+``nullptr`` instead.
+
+Compiler-RT library contains reference implementations of slowpath
+functions, but they have unresolvable issues with correctness and
+performance in the handling of dlopen(). It is recommended that
+platforms provide their own implementations, usually as part of libc
+or libdl.
 
 Position-independent executable requirement
 ---


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


r324163 - [hwasan] Add a paragraph on stack instrumentation.

2018-02-02 Thread Evgeniy Stepanov via cfe-commits
Author: eugenis
Date: Fri Feb  2 17:06:21 2018
New Revision: 324163

URL: http://llvm.org/viewvc/llvm-project?rev=324163&view=rev
Log:
[hwasan] Add a paragraph on stack instrumentation.

Reviewers: kcc

Subscribers: cfe-commits

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

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=324163&r1=324162&r2=324163&view=diff
==
--- cfe/trunk/docs/HardwareAssistedAddressSanitizerDesign.rst (original)
+++ cfe/trunk/docs/HardwareAssistedAddressSanitizerDesign.rst Fri Feb  2 
17:06:21 2018
@@ -77,11 +77,18 @@ This can be based on any malloc that for
 Stack
 -
 
-Special compiler instrumentation is required to align the local variables
-by N, tag the memory and the pointers.
+Stack frames are instrumented by aligning all non-promotable allocas
+by `N` and tagging stack memory in function prologue and epilogue.
+
+Tags for different allocas in one function are **not** generated
+independently; doing that in a function with `M` allocas would require
+maintaining `M` live stack pointers, significantly increasing register
+pressure. Instead we generate a single base tag value in the prologue,
+and build the tag for alloca number `M` as `ReTag(BaseTag, M)`, where
+ReTag can be as simple as exclusive-or with constant `M`.
+
 Stack instrumentation is expected to be a major source of overhead,
 but could be optional.
-TODO: details.
 
 Globals
 ---


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


r295267 - Add missing regexp quantifiers in a test.

2017-02-15 Thread Evgeniy Stepanov via cfe-commits
Author: eugenis
Date: Wed Feb 15 19:35:23 2017
New Revision: 295267

URL: http://llvm.org/viewvc/llvm-project?rev=295267&view=rev
Log:
Add missing regexp quantifiers in a test.

Modified:
cfe/trunk/test/CodeGen/sanitize-init-order.cpp

Modified: cfe/trunk/test/CodeGen/sanitize-init-order.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/sanitize-init-order.cpp?rev=295267&r1=295266&r2=295267&view=diff
==
--- cfe/trunk/test/CodeGen/sanitize-init-order.cpp (original)
+++ cfe/trunk/test/CodeGen/sanitize-init-order.cpp Wed Feb 15 19:35:23 2017
@@ -36,13 +36,13 @@ const volatile PODWithCtor array[5][5];
 
 // Check that ASan init-order checking ignores structs with trivial default
 // constructor.
-// CHECK: !llvm.asan.globals = !{![[GLOB_1:[0-9]+]], ![[GLOB_2:[0-9]+]], 
![[GLOB_3:[0-9]]], ![[GLOB_4:[0-9]]]}
+// CHECK: !llvm.asan.globals = !{![[GLOB_1:[0-9]+]], ![[GLOB_2:[0-9]+]], 
![[GLOB_3:[0-9]+]], ![[GLOB_4:[0-9]+]]
 // CHECK: ![[GLOB_1]] = !{%struct.PODStruct* {{.*}}, i1 false, i1 false}
 // CHECK: ![[GLOB_2]] = !{%struct.PODWithDtor* {{.*}}, i1 false, i1 false}
 // CHECK: ![[GLOB_3]] = !{%struct.PODWithCtorAndDtor* {{.*}}, i1 true, i1 
false}
 // CHECK: ![[GLOB_4]] = !{{{.*}}class.NS::PODWithCtor{{.*}}, i1 true, i1 false}
 
-// BLACKLIST: !llvm.asan.globals = !{![[GLOB_1:[0-9]+]], ![[GLOB_2:[0-9]+]], 
![[GLOB_3:[0-9]]], ![[GLOB_4:[0-9]]]}
+// BLACKLIST: !llvm.asan.globals = !{![[GLOB_1:[0-9]+]], ![[GLOB_2:[0-9]+]], 
![[GLOB_3:[0-9]+]], ![[GLOB_4:[0-9]+]]}
 // BLACKLIST: ![[GLOB_1]] = !{%struct.PODStruct* {{.*}}, i1 false, i1 false}
 // BLACKLIST: ![[GLOB_2]] = !{%struct.PODWithDtor* {{.*}}, i1 false, i1 false}
 // BLACKLIST: ![[GLOB_3]] = !{%struct.PODWithCtorAndDtor* {{.*}}, i1 false, i1 
false}


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


r301225 - [asan] Disable ASan global-GC depending on the target and compiler flags.

2017-04-24 Thread Evgeniy Stepanov via cfe-commits
Author: eugenis
Date: Mon Apr 24 14:34:12 2017
New Revision: 301225

URL: http://llvm.org/viewvc/llvm-project?rev=301225&view=rev
Log:
[asan] Disable ASan global-GC depending on the target and compiler flags.

Added:
cfe/trunk/test/CodeGen/asan-globals-gc.cpp
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=301225&r1=301224&r2=301225&view=diff
==
--- cfe/trunk/lib/CodeGen/BackendUtil.cpp (original)
+++ cfe/trunk/lib/CodeGen/BackendUtil.cpp Mon Apr 24 14:34:12 2017
@@ -129,16 +129,20 @@ public:
 // that we add to the PassManagerBuilder.
 class PassManagerBuilderWrapper : public PassManagerBuilder {
 public:
-  PassManagerBuilderWrapper(const CodeGenOptions &CGOpts,
+  PassManagerBuilderWrapper(const Triple &TargetTriple,
+const CodeGenOptions &CGOpts,
 const LangOptions &LangOpts)
-  : PassManagerBuilder(), CGOpts(CGOpts), LangOpts(LangOpts) {}
+  : PassManagerBuilder(), TargetTriple(TargetTriple), CGOpts(CGOpts),
+LangOpts(LangOpts) {}
+  const Triple &getTargetTriple() const { return TargetTriple; }
   const CodeGenOptions &getCGOpts() const { return CGOpts; }
   const LangOptions &getLangOpts() const { return LangOpts; }
+
 private:
+  const Triple &TargetTriple;
   const CodeGenOptions &CGOpts;
   const LangOptions &LangOpts;
 };
-
 }
 
 static void addObjCARCAPElimPass(const PassManagerBuilder &Builder, 
PassManagerBase &PM) {
@@ -185,16 +189,36 @@ static void addSanitizerCoveragePass(con
   PM.add(createSanitizerCoverageModulePass(Opts));
 }
 
+// Check if ASan should use GC-friendly instrumentation for globals.
+// First of all, there is no point if -fdata-sections is off (expect for MachO,
+// where this is not a factor). Also, on ELF this feature requires an assembler
+// extension that only works with -integrated-as at the moment.
+static bool asanUseGlobalsGC(const Triple &T, const CodeGenOptions &CGOpts) {
+  switch (T.getObjectFormat()) {
+  case Triple::MachO:
+return true;
+  case Triple::COFF:
+return CGOpts.DataSections;
+  case Triple::ELF:
+return CGOpts.DataSections && !CGOpts.DisableIntegratedAS;
+  default:
+return false;
+  }
+}
+
 static void addAddressSanitizerPasses(const PassManagerBuilder &Builder,
   legacy::PassManagerBase &PM) {
   const PassManagerBuilderWrapper &BuilderWrapper =
   static_cast(Builder);
+  const Triple &T = BuilderWrapper.getTargetTriple();
   const CodeGenOptions &CGOpts = BuilderWrapper.getCGOpts();
   bool Recover = CGOpts.SanitizeRecover.has(SanitizerKind::Address);
   bool UseAfterScope = CGOpts.SanitizeAddressUseAfterScope;
+  bool UseGlobalsGC = asanUseGlobalsGC(T, CGOpts);
   PM.add(createAddressSanitizerFunctionPass(/*CompileKernel*/ false, Recover,
 UseAfterScope));
-  PM.add(createAddressSanitizerModulePass(/*CompileKernel*/false, Recover));
+  PM.add(createAddressSanitizerModulePass(/*CompileKernel*/ false, Recover,
+  UseGlobalsGC));
 }
 
 static void addKernelAddressSanitizerPasses(const PassManagerBuilder &Builder,
@@ -436,8 +460,6 @@ void EmitAssemblyHelper::CreatePasses(le
   if (CodeGenOpts.DisableLLVMPasses)
 return;
 
-  PassManagerBuilderWrapper PMBuilder(CodeGenOpts, LangOpts);
-
   // Figure out TargetLibraryInfo.  This needs to be added to MPM and FPM
   // manually (and not via PMBuilder), since some passes (eg. InstrProfiling)
   // are inserted before PMBuilder ones - they'd get the default-constructed
@@ -446,6 +468,8 @@ void EmitAssemblyHelper::CreatePasses(le
   std::unique_ptr TLII(
   createTLII(TargetTriple, CodeGenOpts));
 
+  PassManagerBuilderWrapper PMBuilder(TargetTriple, CodeGenOpts, LangOpts);
+
   // At O0 and O1 we only run the always inliner which is more efficient. At
   // higher optimization levels we run the normal inliner.
   if (CodeGenOpts.OptimizationLevel <= 1) {

Added: cfe/trunk/test/CodeGen/asan-globals-gc.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/asan-globals-gc.cpp?rev=301225&view=auto
==
--- cfe/trunk/test/CodeGen/asan-globals-gc.cpp (added)
+++ cfe/trunk/test/CodeGen/asan-globals-gc.cpp Mon Apr 24 14:34:12 2017
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -fsanitize=address -emit-llvm -o - -triple 
x86_64-windows-msvc %s | FileCheck %s --check-prefix=WITHOUT-GC
+// RUN: %clang_cc1 -fsanitize=address -emit-llvm -o - -triple 
x86_64-windows-msvc -fdata-sections %s | FileCheck %s --check-prefix=WITH-GC
+
+int global;
+
+// WITH-GC-NOT: call void @__asan_register_globals
+// WITHOUT-GC: call void @__asan_register_globals


___
cfe-commits ma

r301374 - [asan] Unconditionally enable GC of globals on COFF.

2017-04-25 Thread Evgeniy Stepanov via cfe-commits
Author: eugenis
Date: Tue Apr 25 19:51:06 2017
New Revision: 301374

URL: http://llvm.org/viewvc/llvm-project?rev=301374&view=rev
Log:
[asan] Unconditionally enable GC of globals on COFF.

This change restores pre-r301225 behavior, where linker GC compatible global
instrumentation was used on COFF targets disregarding -f(no-)data-sections 
and/or
/Gw flags.

This instrumentation puts each global in a COMDAT with an ASan descriptor for 
that global.
It effectively enables -fdata-sections, but limits it to ASan-instrumented 
globals.

Modified:
cfe/trunk/lib/CodeGen/BackendUtil.cpp
cfe/trunk/test/CodeGen/asan-globals-gc.cpp

Modified: cfe/trunk/lib/CodeGen/BackendUtil.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/BackendUtil.cpp?rev=301374&r1=301373&r2=301374&view=diff
==
--- cfe/trunk/lib/CodeGen/BackendUtil.cpp (original)
+++ cfe/trunk/lib/CodeGen/BackendUtil.cpp Tue Apr 25 19:51:06 2017
@@ -196,9 +196,8 @@ static void addSanitizerCoveragePass(con
 static bool asanUseGlobalsGC(const Triple &T, const CodeGenOptions &CGOpts) {
   switch (T.getObjectFormat()) {
   case Triple::MachO:
-return true;
   case Triple::COFF:
-return CGOpts.DataSections;
+return true;
   case Triple::ELF:
 return CGOpts.DataSections && !CGOpts.DisableIntegratedAS;
   default:

Modified: cfe/trunk/test/CodeGen/asan-globals-gc.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/asan-globals-gc.cpp?rev=301374&r1=301373&r2=301374&view=diff
==
--- cfe/trunk/test/CodeGen/asan-globals-gc.cpp (original)
+++ cfe/trunk/test/CodeGen/asan-globals-gc.cpp Tue Apr 25 19:51:06 2017
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsanitize=address -emit-llvm -o - -triple 
x86_64-windows-msvc %s | FileCheck %s --check-prefix=WITHOUT-GC
+// RUN: %clang_cc1 -fsanitize=address -emit-llvm -o - -triple 
x86_64-windows-msvc %s | FileCheck %s --check-prefix=WITH-GC
 // RUN: %clang_cc1 -fsanitize=address -emit-llvm -o - -triple 
x86_64-windows-msvc -fdata-sections %s | FileCheck %s --check-prefix=WITH-GC
 
 int global;


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


r302590 - Remove unnecessary calls to MakeArgString.

2017-05-09 Thread Evgeniy Stepanov via cfe-commits
Author: eugenis
Date: Tue May  9 16:57:39 2017
New Revision: 302590

URL: http://llvm.org/viewvc/llvm-project?rev=302590&view=rev
Log:
Remove unnecessary calls to MakeArgString.

Modified:
cfe/trunk/lib/Driver/SanitizerArgs.cpp
cfe/trunk/lib/Driver/ToolChains/Arch/Mips.cpp

Modified: cfe/trunk/lib/Driver/SanitizerArgs.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/SanitizerArgs.cpp?rev=302590&r1=302589&r2=302590&view=diff
==
--- cfe/trunk/lib/Driver/SanitizerArgs.cpp (original)
+++ cfe/trunk/lib/Driver/SanitizerArgs.cpp Tue May  9 16:57:39 2017
@@ -633,7 +633,7 @@ void SanitizerArgs::addArgs(const ToolCh
 std::make_pair(CoverageNoPrune, "-fsanitize-coverage-no-prune")};
   for (auto F : CoverageFlags) {
 if (CoverageFeatures & F.first)
-  CmdArgs.push_back(Args.MakeArgString(F.second));
+  CmdArgs.push_back(F.second);
   }
 
   if (TC.getTriple().isOSWindows() && needsUbsanRt()) {
@@ -686,7 +686,7 @@ void SanitizerArgs::addArgs(const ToolCh
  llvm::utostr(MsanTrackOrigins)));
 
   if (MsanUseAfterDtor)
-CmdArgs.push_back(Args.MakeArgString("-fsanitize-memory-use-after-dtor"));
+CmdArgs.push_back("-fsanitize-memory-use-after-dtor");
 
   // FIXME: Pass these parameters as function attributes, not as -llvm flags.
   if (!TsanMemoryAccess) {
@@ -705,17 +705,17 @@ void SanitizerArgs::addArgs(const ToolCh
   }
 
   if (CfiCrossDso)
-CmdArgs.push_back(Args.MakeArgString("-fsanitize-cfi-cross-dso"));
+CmdArgs.push_back("-fsanitize-cfi-cross-dso");
 
   if (Stats)
-CmdArgs.push_back(Args.MakeArgString("-fsanitize-stats"));
+CmdArgs.push_back("-fsanitize-stats");
 
   if (AsanFieldPadding)
 CmdArgs.push_back(Args.MakeArgString("-fsanitize-address-field-padding=" +
  llvm::utostr(AsanFieldPadding)));
 
   if (AsanUseAfterScope)
-
CmdArgs.push_back(Args.MakeArgString("-fsanitize-address-use-after-scope"));
+CmdArgs.push_back("-fsanitize-address-use-after-scope");
 
   // MSan: Workaround for PR16386.
   // ASan: This is mainly to help LSan with cases such as
@@ -723,7 +723,7 @@ void SanitizerArgs::addArgs(const ToolCh
   // We can't make this conditional on -fsanitize=leak, as that flag shouldn't
   // affect compilation.
   if (Sanitizers.has(Memory) || Sanitizers.has(Address))
-CmdArgs.push_back(Args.MakeArgString("-fno-assume-sane-operator-new"));
+CmdArgs.push_back("-fno-assume-sane-operator-new");
 
   // Require -fvisibility= flag on non-Windows when compiling if vptr CFI is
   // enabled.

Modified: cfe/trunk/lib/Driver/ToolChains/Arch/Mips.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Arch/Mips.cpp?rev=302590&r1=302589&r2=302590&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Arch/Mips.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Arch/Mips.cpp Tue May  9 16:57:39 2017
@@ -282,18 +282,18 @@ void mips::getMIPSTargetFeatures(const D
   if (Arg *A = Args.getLastArg(options::OPT_mfp32, options::OPT_mfpxx,
options::OPT_mfp64)) {
 if (A->getOption().matches(options::OPT_mfp32))
-  Features.push_back(Args.MakeArgString("-fp64"));
+  Features.push_back("-fp64");
 else if (A->getOption().matches(options::OPT_mfpxx)) {
-  Features.push_back(Args.MakeArgString("+fpxx"));
-  Features.push_back(Args.MakeArgString("+nooddspreg"));
+  Features.push_back("+fpxx");
+  Features.push_back("+nooddspreg");
 } else
-  Features.push_back(Args.MakeArgString("+fp64"));
+  Features.push_back("+fp64");
   } else if (mips::shouldUseFPXX(Args, Triple, CPUName, ABIName, FloatABI)) {
-Features.push_back(Args.MakeArgString("+fpxx"));
-Features.push_back(Args.MakeArgString("+nooddspreg"));
+Features.push_back("+fpxx");
+Features.push_back("+nooddspreg");
   } else if (mips::isFP64ADefault(Triple, CPUName)) {
-Features.push_back(Args.MakeArgString("+fp64"));
-Features.push_back(Args.MakeArgString("+nooddspreg"));
+Features.push_back("+fp64");
+Features.push_back("+nooddspreg");
   }
 
   AddTargetFeature(Args, Features, options::OPT_mno_odd_spreg,


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


r302591 - [asan] A clang flag to enable ELF globals-gc.

2017-05-09 Thread Evgeniy Stepanov via cfe-commits
Author: eugenis
Date: Tue May  9 16:57:43 2017
New Revision: 302591

URL: http://llvm.org/viewvc/llvm-project?rev=302591&view=rev
Log:
[asan] A clang flag to enable ELF globals-gc.

This feature is subtly broken when the linker is gold 2.26 or
earlier. See the following bug for details:
  https://sourceware.org/bugzilla/show_bug.cgi?id=19002

Since the decision needs to be made at compilation time, we can not
test the linker version. The flag is off by default on ELF targets,
and on otherwise.

Modified:
cfe/trunk/include/clang/Driver/Options.td
cfe/trunk/include/clang/Driver/SanitizerArgs.h
cfe/trunk/include/clang/Frontend/CodeGenOptions.def
cfe/trunk/lib/CodeGen/BackendUtil.cpp
cfe/trunk/lib/Driver/SanitizerArgs.cpp
cfe/trunk/lib/Frontend/CompilerInvocation.cpp
cfe/trunk/test/CodeGen/asan-globals-gc.cpp
cfe/trunk/test/Driver/fsanitize.c

Modified: cfe/trunk/include/clang/Driver/Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=302591&r1=302590&r2=302591&view=diff
==
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Tue May  9 16:57:43 2017
@@ -827,6 +827,9 @@ def fno_sanitize_address_use_after_scope
Group,
Flags<[CoreOption, DriverOption]>,
HelpText<"Disable use-after-scope 
detection in AddressSanitizer">;
+def fsanitize_address_globals_dead_stripping : Flag<["-"], 
"fsanitize-address-globals-dead-stripping">,
+Group,
+HelpText<"Enable linker dead stripping 
of globals in AddressSanitizer">;
 def fsanitize_recover : Flag<["-"], "fsanitize-recover">, Group;
 def fno_sanitize_recover : Flag<["-"], "fno-sanitize-recover">,
Flags<[CoreOption, DriverOption]>,

Modified: cfe/trunk/include/clang/Driver/SanitizerArgs.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/SanitizerArgs.h?rev=302591&r1=302590&r2=302591&view=diff
==
--- cfe/trunk/include/clang/Driver/SanitizerArgs.h (original)
+++ cfe/trunk/include/clang/Driver/SanitizerArgs.h Tue May  9 16:57:43 2017
@@ -35,6 +35,7 @@ class SanitizerArgs {
   int AsanFieldPadding = 0;
   bool AsanSharedRuntime = false;
   bool AsanUseAfterScope = true;
+  bool AsanGlobalsDeadStripping = false;
   bool LinkCXXRuntimes = false;
   bool NeedPIE = false;
   bool Stats = false;

Modified: cfe/trunk/include/clang/Frontend/CodeGenOptions.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/CodeGenOptions.def?rev=302591&r1=302590&r2=302591&view=diff
==
--- cfe/trunk/include/clang/Frontend/CodeGenOptions.def (original)
+++ cfe/trunk/include/clang/Frontend/CodeGenOptions.def Tue May  9 16:57:43 2017
@@ -137,6 +137,8 @@ CODEGENOPT(StructPathTBAA, 1, 0) ///
 CODEGENOPT(SaveTempLabels, 1, 0) ///< Save temporary labels.
 CODEGENOPT(SanitizeAddressUseAfterScope , 1, 0) ///< Enable use-after-scope 
detection
 ///< in AddressSanitizer
+CODEGENOPT(SanitizeAddressGlobalsDeadStripping, 1, 0) ///< Enable linker dead 
stripping
+  ///< of globals in 
AddressSanitizer
 CODEGENOPT(SanitizeMemoryTrackOrigins, 2, 0) ///< Enable tracking origins in
  ///< MemorySanitizer
 CODEGENOPT(SanitizeMemoryUseAfterDtor, 1, 0) ///< Enable use-after-delete 
detection

Modified: cfe/trunk/lib/CodeGen/BackendUtil.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/BackendUtil.cpp?rev=302591&r1=302590&r2=302591&view=diff
==
--- cfe/trunk/lib/CodeGen/BackendUtil.cpp (original)
+++ cfe/trunk/lib/CodeGen/BackendUtil.cpp Tue May  9 16:57:43 2017
@@ -194,6 +194,8 @@ static void addSanitizerCoveragePass(con
 // where this is not a factor). Also, on ELF this feature requires an assembler
 // extension that only works with -integrated-as at the moment.
 static bool asanUseGlobalsGC(const Triple &T, const CodeGenOptions &CGOpts) {
+  if (!CGOpts.SanitizeAddressGlobalsDeadStripping)
+return false;
   switch (T.getObjectFormat()) {
   case Triple::MachO:
   case Triple::COFF:

Modified: cfe/trunk/lib/Driver/SanitizerArgs.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/SanitizerArgs.cpp?rev=302591&r1=302590&r2=302591&view=diff
==
--- cfe/trunk/lib/Driver/SanitizerArgs.cpp (original)
+++ cfe/trunk/lib/Driver/SanitizerArgs.cpp Tue May  9 16:57:43

r302594 - Fix clang_cl argument in fsanitize.c driver test.

2017-05-09 Thread Evgeniy Stepanov via cfe-commits
Author: eugenis
Date: Tue May  9 17:28:57 2017
New Revision: 302594

URL: http://llvm.org/viewvc/llvm-project?rev=302594&view=rev
Log:
Fix clang_cl argument in fsanitize.c driver test.

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

Modified: cfe/trunk/test/Driver/fsanitize.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/fsanitize.c?rev=302594&r1=302593&r2=302594&view=diff
==
--- cfe/trunk/test/Driver/fsanitize.c (original)
+++ cfe/trunk/test/Driver/fsanitize.c Tue May  9 17:28:57 2017
@@ -128,8 +128,8 @@
 
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=address 
-fsanitize-address-globals-dead-stripping %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-ASAN-GLOBALS
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=address %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-NO-ASAN-GLOBALS
-// RUN: %clang_cl -target x86_64-windows-msvc -fsanitize=address 
-fsanitize-address-globals-dead-stripping -### -- %s 2>&1 | FileCheck %s 
--check-prefix=CHECK-ASAN-GLOBALS
-// RUN: %clang_cl -target x86_64-windows-msvc -fsanitize=address -### -- %s 
2>&1 | FileCheck %s --check-prefix=CHECK-ASAN-GLOBALS
+// RUN: %clang_cl --target=x86_64-windows-msvc -fsanitize=address 
-fsanitize-address-globals-dead-stripping -### -- %s 2>&1 | FileCheck %s 
--check-prefix=CHECK-ASAN-GLOBALS
+// RUN: %clang_cl --target=x86_64-windows-msvc -fsanitize=address -### -- %s 
2>&1 | FileCheck %s --check-prefix=CHECK-ASAN-GLOBALS
 // CHECK-ASAN-GLOBALS: -cc1{{.*}}-fsanitize-address-globals-dead-stripping
 // CHECK-NO-ASAN-GLOBALS-NOT: 
-cc1{{.*}}-fsanitize-address-globals-dead-stripping
 


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


r303114 - [asan] One more test for -fsanitize-address-globals-dead-stripping.

2017-05-15 Thread Evgeniy Stepanov via cfe-commits
Author: eugenis
Date: Mon May 15 15:43:48 2017
New Revision: 303114

URL: http://llvm.org/viewvc/llvm-project?rev=303114&view=rev
Log:
[asan] One more test for -fsanitize-address-globals-dead-stripping.

Added:
cfe/trunk/test/CodeGen/asan-no-globals-no-comdat.cpp

Added: cfe/trunk/test/CodeGen/asan-no-globals-no-comdat.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/asan-no-globals-no-comdat.cpp?rev=303114&view=auto
==
--- cfe/trunk/test/CodeGen/asan-no-globals-no-comdat.cpp (added)
+++ cfe/trunk/test/CodeGen/asan-no-globals-no-comdat.cpp Mon May 15 15:43:48 
2017
@@ -0,0 +1,11 @@
+// Test that on Linux asan constructor is placed in a comdat iff globals-gc is 
on.
+// Even if there are no globals in the module.
+
+// RUN: %clang_cc1 -fsanitize=address 
-fsanitize-address-globals-dead-stripping -emit-llvm -o - -triple x86_64-linux 
%s | FileCheck %s --check-prefix=WITHOUT-GC
+// RUN: %clang_cc1 -fsanitize=address 
-fsanitize-address-globals-dead-stripping -fdata-sections -emit-llvm -o - 
-triple x86_64-linux %s | FileCheck %s --check-prefix=WITH-GC
+// RUN: %clang_cc1 -fsanitize=address 
-fsanitize-address-globals-dead-stripping -fno-integrated-as -fdata-sections 
-emit-llvm -o - -triple x86_64-linux %s | FileCheck %s --check-prefix=WITHOUT-GC
+// RUN: %clang_cc1 -fsanitize=address 
-fsanitize-address-globals-dead-stripping -fno-integrated-as -emit-llvm -o - 
-triple x86_64-linux %s | FileCheck %s --check-prefix=WITHOUT-GC
+// RUN: %clang_cc1 -fsanitize=address -fdata-sections -emit-llvm -o - -triple 
x86_64-linux %s | FileCheck %s --check-prefix=WITHOUT-GC
+
+// WITH-GC: define internal void @asan.module_ctor() comdat {
+// WITHOUT-GC: define internal void @asan.module_ctor() {


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


[PATCH] D25928: [cfi] Enable cfi-icall on ARM and AArch64.

2016-10-24 Thread Evgeniy Stepanov via cfe-commits
eugenis created this revision.
eugenis added a reviewer: pcc.
eugenis added a subscriber: cfe-commits.
eugenis set the repository for this revision to rL LLVM.
Herald added subscribers: srhines, danalbert, tberghammer, rengolin, aemerson.

Backend support added in https://reviews.llvm.org/D25927


Repository:
  rL LLVM

https://reviews.llvm.org/D25928

Files:
  lib/Driver/ToolChain.cpp
  test/Driver/fsanitize.c


Index: test/Driver/fsanitize.c
===
--- test/Driver/fsanitize.c
+++ test/Driver/fsanitize.c
@@ -328,6 +328,10 @@
 // RUN: %clang -target x86_64-linux-gnu -fvisibility=hidden 
-fsanitize=cfi-unrelated-cast -flto -c %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-CFI-UCAST
 // RUN: %clang -target x86_64-linux-gnu -flto -fvisibility=hidden 
-fsanitize=cfi-nvcall -c %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-CFI-NVCALL
 // RUN: %clang -target x86_64-linux-gnu -flto -fvisibility=hidden 
-fsanitize=cfi-vcall -c %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-CFI-VCALL
+// RUN: %clang -target arm-linux-gnu -fvisibility=hidden -fsanitize=cfi -flto 
-c %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-CFI
+// RUN: %clang -target aarch64-linux-gnu -fvisibility=hidden -fsanitize=cfi 
-flto -c %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-CFI
+// RUN: %clang -target arm-linux-android -fvisibility=hidden -fsanitize=cfi 
-flto -c %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-CFI
+// RUN: %clang -target aarch64-linux-android -fvisibility=hidden 
-fsanitize=cfi -flto -c %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-CFI
 // CHECK-CFI: 
-emit-llvm-bc{{.*}}-fsanitize=cfi-derived-cast,cfi-icall,cfi-unrelated-cast,cfi-nvcall,cfi-vcall
 // CHECK-CFI-DCAST: -emit-llvm-bc{{.*}}-fsanitize=cfi-derived-cast
 // CHECK-CFI-UCAST: -emit-llvm-bc{{.*}}-fsanitize=cfi-unrelated-cast
Index: lib/Driver/ToolChain.cpp
===
--- lib/Driver/ToolChain.cpp
+++ lib/Driver/ToolChain.cpp
@@ -698,6 +698,8 @@
   CFICastStrict | UnsignedIntegerOverflow | LocalBounds;
   if (getTriple().getArch() == llvm::Triple::x86 ||
   getTriple().getArch() == llvm::Triple::x86_64 ||
+  getTriple().getArch() == llvm::Triple::arm ||
+  getTriple().getArch() == llvm::Triple::aarch64 ||
   getTriple().getArch() == llvm::Triple::wasm32 ||
   getTriple().getArch() == llvm::Triple::wasm64)
 Res |= CFIICall;


Index: test/Driver/fsanitize.c
===
--- test/Driver/fsanitize.c
+++ test/Driver/fsanitize.c
@@ -328,6 +328,10 @@
 // RUN: %clang -target x86_64-linux-gnu -fvisibility=hidden -fsanitize=cfi-unrelated-cast -flto -c %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-CFI-UCAST
 // RUN: %clang -target x86_64-linux-gnu -flto -fvisibility=hidden -fsanitize=cfi-nvcall -c %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-CFI-NVCALL
 // RUN: %clang -target x86_64-linux-gnu -flto -fvisibility=hidden -fsanitize=cfi-vcall -c %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-CFI-VCALL
+// RUN: %clang -target arm-linux-gnu -fvisibility=hidden -fsanitize=cfi -flto -c %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-CFI
+// RUN: %clang -target aarch64-linux-gnu -fvisibility=hidden -fsanitize=cfi -flto -c %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-CFI
+// RUN: %clang -target arm-linux-android -fvisibility=hidden -fsanitize=cfi -flto -c %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-CFI
+// RUN: %clang -target aarch64-linux-android -fvisibility=hidden -fsanitize=cfi -flto -c %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-CFI
 // CHECK-CFI: -emit-llvm-bc{{.*}}-fsanitize=cfi-derived-cast,cfi-icall,cfi-unrelated-cast,cfi-nvcall,cfi-vcall
 // CHECK-CFI-DCAST: -emit-llvm-bc{{.*}}-fsanitize=cfi-derived-cast
 // CHECK-CFI-UCAST: -emit-llvm-bc{{.*}}-fsanitize=cfi-unrelated-cast
Index: lib/Driver/ToolChain.cpp
===
--- lib/Driver/ToolChain.cpp
+++ lib/Driver/ToolChain.cpp
@@ -698,6 +698,8 @@
   CFICastStrict | UnsignedIntegerOverflow | LocalBounds;
   if (getTriple().getArch() == llvm::Triple::x86 ||
   getTriple().getArch() == llvm::Triple::x86_64 ||
+  getTriple().getArch() == llvm::Triple::arm ||
+  getTriple().getArch() == llvm::Triple::aarch64 ||
   getTriple().getArch() == llvm::Triple::wasm32 ||
   getTriple().getArch() == llvm::Triple::wasm64)
 Res |= CFIICall;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D26164: [cfi] Fix missing !type annotation.

2016-10-31 Thread Evgeniy Stepanov via cfe-commits
eugenis created this revision.
eugenis added a reviewer: pcc.
eugenis added a subscriber: cfe-commits.
eugenis set the repository for this revision to rL LLVM.

CFI (only in the cross-dso mode) fails to set !type annotations when
a function is used before it is defined.


Repository:
  rL LLVM

https://reviews.llvm.org/D26164

Files:
  lib/CodeGen/CodeGenModule.cpp
  test/CodeGen/cfi-icall-cross-dso2.c


Index: test/CodeGen/cfi-icall-cross-dso2.c
===
--- /dev/null
+++ test/CodeGen/cfi-icall-cross-dso2.c
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux -O1 \
+// RUN:   -fsanitize=cfi-icall -fsanitize-cfi-cross-dso \
+// RUN:   -emit-llvm -o - %s | FileCheck %s
+
+// CHECK: define void @f() {{.*}} !type !{{.*}} !type !{{.*}}
+void f(void);
+void (*pf)(void) = f;
+void f(void) { }
Index: lib/CodeGen/CodeGenModule.cpp
===
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -928,6 +928,10 @@
 if (F->getAlignment() < 2 && isa(D))
   F->setAlignment(2);
   }
+
+  // In the cross-dso CFI mode, we want !type attributes on definitions only.
+  if (CodeGenOpts.SanitizeCfiCrossDso)
+CreateFunctionTypeMetadata(dyn_cast(D), F);
 }
 
 void CodeGenModule::SetCommonAttributes(const Decl *D,
@@ -1010,10 +1014,6 @@
 
   // Additionally, if building with cross-DSO support...
   if (CodeGenOpts.SanitizeCfiCrossDso) {
-// Don't emit entries for function declarations. In cross-DSO mode these 
are
-// handled with better precision at run time.
-if (!FD->hasBody())
-  return;
 // Skip available_externally functions. They won't be codegen'ed in the
 // current module anyway.
 if (getContext().GetGVALinkageForFunction(FD) == GVA_AvailableExternally)
@@ -1086,7 +1086,10 @@
 if (MD->isVirtual())
   F->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
 
-  CreateFunctionTypeMetadata(FD, F);
+  // Don't emit entries for function declarations in the cross-DSO mode. This
+  // is handled with better precision by the receiving DSO.
+  if (!CodeGenOpts.SanitizeCfiCrossDso)
+CreateFunctionTypeMetadata(FD, F);
 }
 
 void CodeGenModule::addUsedGlobal(llvm::GlobalValue *GV) {


Index: test/CodeGen/cfi-icall-cross-dso2.c
===
--- /dev/null
+++ test/CodeGen/cfi-icall-cross-dso2.c
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux -O1 \
+// RUN:   -fsanitize=cfi-icall -fsanitize-cfi-cross-dso \
+// RUN:   -emit-llvm -o - %s | FileCheck %s
+
+// CHECK: define void @f() {{.*}} !type !{{.*}} !type !{{.*}}
+void f(void);
+void (*pf)(void) = f;
+void f(void) { }
Index: lib/CodeGen/CodeGenModule.cpp
===
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -928,6 +928,10 @@
 if (F->getAlignment() < 2 && isa(D))
   F->setAlignment(2);
   }
+
+  // In the cross-dso CFI mode, we want !type attributes on definitions only.
+  if (CodeGenOpts.SanitizeCfiCrossDso)
+CreateFunctionTypeMetadata(dyn_cast(D), F);
 }
 
 void CodeGenModule::SetCommonAttributes(const Decl *D,
@@ -1010,10 +1014,6 @@
 
   // Additionally, if building with cross-DSO support...
   if (CodeGenOpts.SanitizeCfiCrossDso) {
-// Don't emit entries for function declarations. In cross-DSO mode these are
-// handled with better precision at run time.
-if (!FD->hasBody())
-  return;
 // Skip available_externally functions. They won't be codegen'ed in the
 // current module anyway.
 if (getContext().GetGVALinkageForFunction(FD) == GVA_AvailableExternally)
@@ -1086,7 +1086,10 @@
 if (MD->isVirtual())
   F->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
 
-  CreateFunctionTypeMetadata(FD, F);
+  // Don't emit entries for function declarations in the cross-DSO mode. This
+  // is handled with better precision by the receiving DSO.
+  if (!CodeGenOpts.SanitizeCfiCrossDso)
+CreateFunctionTypeMetadata(FD, F);
 }
 
 void CodeGenModule::addUsedGlobal(llvm::GlobalValue *GV) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D26164: [cfi] Fix missing !type annotation.

2016-10-31 Thread Evgeniy Stepanov via cfe-commits
eugenis updated this revision to Diff 76489.

Repository:
  rL LLVM

https://reviews.llvm.org/D26164

Files:
  lib/CodeGen/CodeGenModule.cpp
  test/CodeGen/cfi-icall-cross-dso2.c


Index: test/CodeGen/cfi-icall-cross-dso2.c
===
--- /dev/null
+++ test/CodeGen/cfi-icall-cross-dso2.c
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux -O1 -fblocks \
+// RUN:   -fsanitize=cfi-icall -fsanitize-cfi-cross-dso \
+// RUN:   -emit-llvm -o - %s | FileCheck %s
+
+// CHECK: define void @f() {{.*}} !type !{{.*}} !type !{{.*}}
+void f(void);
+void (*pf)(void) = f;
+void f(void) { }
+
+// Check that we do not crash on non-FunctionDecl definitions.
+void (^g)(void) = ^{};
Index: lib/CodeGen/CodeGenModule.cpp
===
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -928,6 +928,11 @@
 if (F->getAlignment() < 2 && isa(D))
   F->setAlignment(2);
   }
+
+  // In the cross-dso CFI mode, we want !type attributes on definitions only.
+  if (CodeGenOpts.SanitizeCfiCrossDso)
+if (auto *FD = dyn_cast(D))
+  CreateFunctionTypeMetadata(FD, F);
 }
 
 void CodeGenModule::SetCommonAttributes(const Decl *D,
@@ -1010,10 +1015,6 @@
 
   // Additionally, if building with cross-DSO support...
   if (CodeGenOpts.SanitizeCfiCrossDso) {
-// Don't emit entries for function declarations. In cross-DSO mode these 
are
-// handled with better precision at run time.
-if (!FD->hasBody())
-  return;
 // Skip available_externally functions. They won't be codegen'ed in the
 // current module anyway.
 if (getContext().GetGVALinkageForFunction(FD) == GVA_AvailableExternally)
@@ -1086,7 +1087,10 @@
 if (MD->isVirtual())
   F->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
 
-  CreateFunctionTypeMetadata(FD, F);
+  // Don't emit entries for function declarations in the cross-DSO mode. This
+  // is handled with better precision by the receiving DSO.
+  if (!CodeGenOpts.SanitizeCfiCrossDso)
+CreateFunctionTypeMetadata(FD, F);
 }
 
 void CodeGenModule::addUsedGlobal(llvm::GlobalValue *GV) {


Index: test/CodeGen/cfi-icall-cross-dso2.c
===
--- /dev/null
+++ test/CodeGen/cfi-icall-cross-dso2.c
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux -O1 -fblocks \
+// RUN:   -fsanitize=cfi-icall -fsanitize-cfi-cross-dso \
+// RUN:   -emit-llvm -o - %s | FileCheck %s
+
+// CHECK: define void @f() {{.*}} !type !{{.*}} !type !{{.*}}
+void f(void);
+void (*pf)(void) = f;
+void f(void) { }
+
+// Check that we do not crash on non-FunctionDecl definitions.
+void (^g)(void) = ^{};
Index: lib/CodeGen/CodeGenModule.cpp
===
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -928,6 +928,11 @@
 if (F->getAlignment() < 2 && isa(D))
   F->setAlignment(2);
   }
+
+  // In the cross-dso CFI mode, we want !type attributes on definitions only.
+  if (CodeGenOpts.SanitizeCfiCrossDso)
+if (auto *FD = dyn_cast(D))
+  CreateFunctionTypeMetadata(FD, F);
 }
 
 void CodeGenModule::SetCommonAttributes(const Decl *D,
@@ -1010,10 +1015,6 @@
 
   // Additionally, if building with cross-DSO support...
   if (CodeGenOpts.SanitizeCfiCrossDso) {
-// Don't emit entries for function declarations. In cross-DSO mode these are
-// handled with better precision at run time.
-if (!FD->hasBody())
-  return;
 // Skip available_externally functions. They won't be codegen'ed in the
 // current module anyway.
 if (getContext().GetGVALinkageForFunction(FD) == GVA_AvailableExternally)
@@ -1086,7 +1087,10 @@
 if (MD->isVirtual())
   F->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
 
-  CreateFunctionTypeMetadata(FD, F);
+  // Don't emit entries for function declarations in the cross-DSO mode. This
+  // is handled with better precision by the receiving DSO.
+  if (!CodeGenOpts.SanitizeCfiCrossDso)
+CreateFunctionTypeMetadata(FD, F);
 }
 
 void CodeGenModule::addUsedGlobal(llvm::GlobalValue *GV) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r285650 - [cfi] Fix missing !type annotation.

2016-10-31 Thread Evgeniy Stepanov via cfe-commits
Author: eugenis
Date: Mon Oct 31 17:28:10 2016
New Revision: 285650

URL: http://llvm.org/viewvc/llvm-project?rev=285650&view=rev
Log:
[cfi] Fix missing !type annotation.

CFI (only in the cross-dso mode) fails to set !type annotations when
a function is used before it is defined.

Added:
cfe/trunk/test/CodeGen/cfi-icall-cross-dso2.c
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=285650&r1=285649&r2=285650&view=diff
==
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Mon Oct 31 17:28:10 2016
@@ -929,6 +929,11 @@ void CodeGenModule::SetLLVMFunctionAttri
 if (F->getAlignment() < 2 && isa(D))
   F->setAlignment(2);
   }
+
+  // In the cross-dso CFI mode, we want !type attributes on definitions only.
+  if (CodeGenOpts.SanitizeCfiCrossDso)
+if (auto *FD = dyn_cast(D))
+  CreateFunctionTypeMetadata(FD, F);
 }
 
 void CodeGenModule::SetCommonAttributes(const Decl *D,
@@ -1011,10 +1016,6 @@ void CodeGenModule::CreateFunctionTypeMe
 
   // Additionally, if building with cross-DSO support...
   if (CodeGenOpts.SanitizeCfiCrossDso) {
-// Don't emit entries for function declarations. In cross-DSO mode these 
are
-// handled with better precision at run time.
-if (!FD->hasBody())
-  return;
 // Skip available_externally functions. They won't be codegen'ed in the
 // current module anyway.
 if (getContext().GetGVALinkageForFunction(FD) == GVA_AvailableExternally)
@@ -1087,7 +1088,10 @@ void CodeGenModule::SetFunctionAttribute
 if (MD->isVirtual())
   F->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
 
-  CreateFunctionTypeMetadata(FD, F);
+  // Don't emit entries for function declarations in the cross-DSO mode. This
+  // is handled with better precision by the receiving DSO.
+  if (!CodeGenOpts.SanitizeCfiCrossDso)
+CreateFunctionTypeMetadata(FD, F);
 }
 
 void CodeGenModule::addUsedGlobal(llvm::GlobalValue *GV) {

Added: cfe/trunk/test/CodeGen/cfi-icall-cross-dso2.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/cfi-icall-cross-dso2.c?rev=285650&view=auto
==
--- cfe/trunk/test/CodeGen/cfi-icall-cross-dso2.c (added)
+++ cfe/trunk/test/CodeGen/cfi-icall-cross-dso2.c Mon Oct 31 17:28:10 2016
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux -O1 -fblocks \
+// RUN:   -fsanitize=cfi-icall -fsanitize-cfi-cross-dso \
+// RUN:   -emit-llvm -o - %s | FileCheck %s
+
+// CHECK: define void @f() {{.*}} !type !{{.*}} !type !{{.*}}
+void f(void);
+void (*pf)(void) = f;
+void f(void) { }
+
+// Check that we do not crash on non-FunctionDecl definitions.
+void (^g)(void) = ^{};


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


[PATCH] D26164: [cfi] Fix missing !type annotation.

2016-10-31 Thread Evgeniy Stepanov via cfe-commits
eugenis closed this revision.
eugenis added a comment.

thanks!
r285650


Repository:
  rL LLVM

https://reviews.llvm.org/D26164



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


[PATCH] D26354: Use -fsanitize-recover instead of -mllvm -msan-keep-going: clang.

2016-11-07 Thread Evgeniy Stepanov via cfe-commits
eugenis accepted this revision.
eugenis added a comment.
This revision is now accepted and ready to land.

LGTM

It appears that this code is not testable in clang. There is a compiler-rt test 
in https://reviews.llvm.org/D26355.


https://reviews.llvm.org/D26354



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


r286148 - Use -fsanitize-recover instead of -mllvm -msan-keep-going: clang.

2016-11-07 Thread Evgeniy Stepanov via cfe-commits
Author: eugenis
Date: Mon Nov  7 15:02:11 2016
New Revision: 286148

URL: http://llvm.org/viewvc/llvm-project?rev=286148&view=rev
Log:
Use -fsanitize-recover instead of -mllvm -msan-keep-going: clang.

Summary: Use -fsanitize-recover instead of -mllvm -msan-keep-going: pass 
-fsanitize-recover value to msan.

Reviewers: eugenis

Subscribers: cfe-commits

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

Patch by Aleksey Shlyapnikov.

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=286148&r1=286147&r2=286148&view=diff
==
--- cfe/trunk/lib/CodeGen/BackendUtil.cpp (original)
+++ cfe/trunk/lib/CodeGen/BackendUtil.cpp Mon Nov  7 15:02:11 2016
@@ -200,7 +200,9 @@ static void addMemorySanitizerPass(const
   const PassManagerBuilderWrapper &BuilderWrapper =
   static_cast(Builder);
   const CodeGenOptions &CGOpts = BuilderWrapper.getCGOpts();
-  PM.add(createMemorySanitizerPass(CGOpts.SanitizeMemoryTrackOrigins));
+  int TrackOrigins = CGOpts.SanitizeMemoryTrackOrigins;
+  bool Recover = CGOpts.SanitizeRecover.has(SanitizerKind::Memory);
+  PM.add(createMemorySanitizerPass(TrackOrigins, Recover));
 
   // MemorySanitizer inserts complex instrumentation that mostly follows
   // the logic of the original code, but operates on "shadow" values.


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


[PATCH] D26385: Define __ANDROID_API__ for all Android builds.

2016-11-08 Thread Evgeniy Stepanov via cfe-commits
eugenis added a comment.

This is a good change, but I don't think it is the right fix for PR30940. 
Instead of handling this in the NDK, we should change *::getIRStackGuard to 
fallback to __stack_chk_guard when targeting an old version.


https://reviews.llvm.org/D26385



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


[PATCH] D26385: Define __ANDROID_API__ for all Android builds.

2016-11-08 Thread Evgeniy Stepanov via cfe-commits
eugenis accepted this revision.
eugenis added a reviewer: eugenis.
eugenis added a comment.

LGTM


https://reviews.llvm.org/D26385



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


[PATCH] D26461: Tread TSan LLVM flags to driver: add TSan controlling flags to clang.

2016-11-09 Thread Evgeniy Stepanov via cfe-commits
eugenis added inline comments.



Comment at: lib/Frontend/CompilerInvocation.cpp:735
+   OPT_fno_sanitize_thread_data_races,
+   Opts.SanitizeThreadDataRaces);
+  Opts.SanitizeThreadStackTraces =

It seems common to hardcode the default option value here.
The same in SanitizerArgs.cpp.


https://reviews.llvm.org/D26461



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


[PATCH] D26461: Tread TSan LLVM flags to driver: add TSan controlling flags to clang.

2016-11-09 Thread Evgeniy Stepanov via cfe-commits
eugenis added a comment.

Oh, and this needs a test. See test/Driver/fsanitize.c (search for 
-fsanitize-address-use-after-scope as an example).


https://reviews.llvm.org/D26461



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


[PATCH] D26461: Tread TSan LLVM flags to driver: add TSan controlling flags to clang.

2016-11-09 Thread Evgeniy Stepanov via cfe-commits
eugenis added inline comments.



Comment at: lib/Frontend/CompilerInvocation.cpp:735
+   OPT_fno_sanitize_thread_data_races,
+   Opts.SanitizeThreadDataRaces);
+  Opts.SanitizeThreadStackTraces =

alekseyshl wrote:
> eugenis wrote:
> > It seems common to hardcode the default option value here.
> > The same in SanitizerArgs.cpp.
> True, but the default value for these flags is already mentioned in more than 
> one place, why not to try to reduce the complexity?
I guess I don't mind either way.


https://reviews.llvm.org/D26461



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


[PATCH] D26461: Tread TSan LLVM flags to driver: add TSan controlling flags to clang.

2016-11-09 Thread Evgeniy Stepanov via cfe-commits
eugenis added inline comments.



Comment at: test/Driver/fsanitize.c:288
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=thread 
-fsanitize-thread-data-races -fno-sanitize-thread-data-races %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-TSAN-DATA-RACES-OFF
+// CHECK-TSAN-DATA-RACES-BOTH-OFF: -cc1{{.*}}-fno-sanitize-thread-data-races
+

did you mean CHECK-TSAN-DATA-RACES-BOTH-NOT?



https://reviews.llvm.org/D26461



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


[PATCH] D26491: Define __ANDROID_API__ when specified as part of an Android target.

2016-11-10 Thread Evgeniy Stepanov via cfe-commits
eugenis accepted this revision.
eugenis added a reviewer: eugenis.
eugenis added a comment.

Looks great!


https://reviews.llvm.org/D26491



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


r286613 - [cfi] Enable cfi-icall on ARM and AArch64.

2016-11-11 Thread Evgeniy Stepanov via cfe-commits
Author: eugenis
Date: Fri Nov 11 12:49:49 2016
New Revision: 286613

URL: http://llvm.org/viewvc/llvm-project?rev=286613&view=rev
Log:
[cfi] Enable cfi-icall on ARM and AArch64.

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

Modified: cfe/trunk/lib/Driver/ToolChain.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChain.cpp?rev=286613&r1=286612&r2=286613&view=diff
==
--- cfe/trunk/lib/Driver/ToolChain.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChain.cpp Fri Nov 11 12:49:49 2016
@@ -708,6 +708,8 @@ SanitizerMask ToolChain::getSupportedSan
   CFICastStrict | UnsignedIntegerOverflow | LocalBounds;
   if (getTriple().getArch() == llvm::Triple::x86 ||
   getTriple().getArch() == llvm::Triple::x86_64 ||
+  getTriple().getArch() == llvm::Triple::arm ||
+  getTriple().getArch() == llvm::Triple::aarch64 ||
   getTriple().getArch() == llvm::Triple::wasm32 ||
   getTriple().getArch() == llvm::Triple::wasm64)
 Res |= CFIICall;

Modified: cfe/trunk/test/Driver/fsanitize.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/fsanitize.c?rev=286613&r1=286612&r2=286613&view=diff
==
--- cfe/trunk/test/Driver/fsanitize.c (original)
+++ cfe/trunk/test/Driver/fsanitize.c Fri Nov 11 12:49:49 2016
@@ -328,6 +328,10 @@
 // RUN: %clang -target x86_64-linux-gnu -fvisibility=hidden 
-fsanitize=cfi-unrelated-cast -flto -c %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-CFI-UCAST
 // RUN: %clang -target x86_64-linux-gnu -flto -fvisibility=hidden 
-fsanitize=cfi-nvcall -c %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-CFI-NVCALL
 // RUN: %clang -target x86_64-linux-gnu -flto -fvisibility=hidden 
-fsanitize=cfi-vcall -c %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-CFI-VCALL
+// RUN: %clang -target arm-linux-gnu -fvisibility=hidden -fsanitize=cfi -flto 
-c %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-CFI
+// RUN: %clang -target aarch64-linux-gnu -fvisibility=hidden -fsanitize=cfi 
-flto -c %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-CFI
+// RUN: %clang -target arm-linux-android -fvisibility=hidden -fsanitize=cfi 
-flto -c %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-CFI
+// RUN: %clang -target aarch64-linux-android -fvisibility=hidden 
-fsanitize=cfi -flto -c %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-CFI
 // CHECK-CFI: 
-emit-llvm-bc{{.*}}-fsanitize=cfi-derived-cast,cfi-icall,cfi-unrelated-cast,cfi-nvcall,cfi-vcall
 // CHECK-CFI-DCAST: -emit-llvm-bc{{.*}}-fsanitize=cfi-derived-cast
 // CHECK-CFI-UCAST: -emit-llvm-bc{{.*}}-fsanitize=cfi-unrelated-cast


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


[PATCH] D26461: Tread TSan LLVM flags to driver: add TSan controlling flags to clang.

2016-11-11 Thread Evgeniy Stepanov via cfe-commits
eugenis added inline comments.



Comment at: lib/Frontend/CompilerInvocation.cpp:732
   Args.hasArg(OPT_fsanitize_coverage_trace_pc_guard);
+  Opts.SanitizeThreadMemoryAccess =
+  Args.hasFlag(OPT_fsanitize_thread_memory_access,

It looks like lib/Frontend changes are no longer necessary.


https://reviews.llvm.org/D26461



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


[PATCH] D26461: Tread TSan LLVM flags to driver: add TSan controlling flags to clang.

2016-11-11 Thread Evgeniy Stepanov via cfe-commits
eugenis accepted this revision.
eugenis added a comment.

LGTM


https://reviews.llvm.org/D26461



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


r286669 - Tread TSan LLVM flags to driver: add TSan controlling flags to clang.

2016-11-11 Thread Evgeniy Stepanov via cfe-commits
Author: eugenis
Date: Fri Nov 11 17:17:36 2016
New Revision: 286669

URL: http://llvm.org/viewvc/llvm-project?rev=286669&view=rev
Log:
Tread TSan LLVM flags to driver: add TSan controlling flags to clang.

Summary:
New clang flags, all default to true:
-f[no-]sanitize-thread-data-races
-f[no-]sanitize-thread-stack-traces
-f[no-]sanitize-thread-atomics

Reviewers: dvyukov, pcc, eugenis

Subscribers: pcc, cfe-commits

Patch by Alex Shlyapnikov.

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

Modified:
cfe/trunk/include/clang/Driver/Options.td
cfe/trunk/include/clang/Driver/SanitizerArgs.h
cfe/trunk/lib/Driver/SanitizerArgs.cpp
cfe/trunk/test/Driver/fsanitize.c

Modified: cfe/trunk/include/clang/Driver/Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=286669&r1=286668&r2=286669&view=diff
==
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Fri Nov 11 17:17:36 2016
@@ -728,6 +728,24 @@ def fsanitize_stats : Flag<["-"], "fsani
 def fno_sanitize_stats : Flag<["-"], "fno-sanitize-stats">,
  Group, Flags<[CC1Option]>,
  HelpText<"Disable sanitizer statistics 
gathering.">;
+def fsanitize_thread_memory_access : Flag<["-"], 
"fsanitize-thread-memory-access">,
+ Group,
+ HelpText<"Enable memory access 
instrumentation in ThreadSanitizer (default)">;
+def fno_sanitize_thread_memory_access : Flag<["-"], 
"fno-sanitize-thread-memory-access">,
+Group,
+HelpText<"Disable memory access 
instrumentation in ThreadSanitizer">;
+def fsanitize_thread_func_entry_exit : Flag<["-"], 
"fsanitize-thread-func-entry-exit">,
+   Group,
+   HelpText<"Enable function entry/exit 
instrumentation in ThreadSanitizer (default)">;
+def fno_sanitize_thread_func_entry_exit : Flag<["-"], 
"fno-sanitize-thread-func-entry-exit">,
+  Group,
+  HelpText<"Disable function 
entry/exit instrumentation in ThreadSanitizer">;
+def fsanitize_thread_atomics : Flag<["-"], "fsanitize-thread-atomics">,
+   Group,
+   HelpText<"Enable atomic operations 
instrumentation in ThreadSanitizer (default)">;
+def fno_sanitize_thread_atomics : Flag<["-"], "fno-sanitize-thread-atomics">,
+  Group,
+  HelpText<"Disable atomic operations 
instrumentation in ThreadSanitizer">;
 def fsanitize_undefined_strip_path_components_EQ : Joined<["-"], 
"fsanitize-undefined-strip-path-components=">,
   Group, Flags<[CC1Option]>, MetaVarName<"">,
   HelpText<"Strip (or keep only, if negative) a given number of path 
components "

Modified: cfe/trunk/include/clang/Driver/SanitizerArgs.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/SanitizerArgs.h?rev=286669&r1=286668&r2=286669&view=diff
==
--- cfe/trunk/include/clang/Driver/SanitizerArgs.h (original)
+++ cfe/trunk/include/clang/Driver/SanitizerArgs.h Fri Nov 11 17:17:36 2016
@@ -38,6 +38,9 @@ class SanitizerArgs {
   bool LinkCXXRuntimes = false;
   bool NeedPIE = false;
   bool Stats = false;
+  bool TsanMemoryAccess = true;
+  bool TsanFuncEntryExit = true;
+  bool TsanAtomics = true;
 
  public:
   /// Parses the sanitizer arguments from an argument list.

Modified: cfe/trunk/lib/Driver/SanitizerArgs.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/SanitizerArgs.cpp?rev=286669&r1=286668&r2=286669&view=diff
==
--- cfe/trunk/lib/Driver/SanitizerArgs.cpp (original)
+++ cfe/trunk/lib/Driver/SanitizerArgs.cpp Fri Nov 11 17:17:36 2016
@@ -437,6 +437,18 @@ SanitizerArgs::SanitizerArgs(const ToolC
  TC.getTriple().getArch() == llvm::Triple::x86_64);
   }
 
+  if (AllAddedKinds & Thread) {
+TsanMemoryAccess = 
Args.hasFlag(options::OPT_fsanitize_thread_memory_access,
+
options::OPT_fno_sanitize_thread_memory_access,
+TsanMemoryAccess);
+TsanFuncEntryExit = 
Args.hasFlag(options::OPT_fsanitize_thread_func_entry_exit,
+ 
options::OPT_fno_sanitize_thread_func_entry_exit,
+ TsanFuncEntryExit);
+TsanAtomics = Args.hasFlag(options::OPT_fsanitize_thread_atomics,
+   options::OPT_fno_sanitize_thread_atomics,
+   TsanAtomics);
+  }
+
   if (AllAddedKinds &

[PATCH] D26461: Tread TSan LLVM flags to driver: add TSan controlling flags to clang.

2016-11-11 Thread Evgeniy Stepanov via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL286669: Tread TSan LLVM flags to driver: add TSan 
controlling flags to clang. (authored by eugenis).

Changed prior to commit:
  https://reviews.llvm.org/D26461?vs=77667&id=77683#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D26461

Files:
  cfe/trunk/include/clang/Driver/Options.td
  cfe/trunk/include/clang/Driver/SanitizerArgs.h
  cfe/trunk/lib/Driver/SanitizerArgs.cpp
  cfe/trunk/test/Driver/fsanitize.c

Index: cfe/trunk/include/clang/Driver/Options.td
===
--- cfe/trunk/include/clang/Driver/Options.td
+++ cfe/trunk/include/clang/Driver/Options.td
@@ -728,6 +728,24 @@
 def fno_sanitize_stats : Flag<["-"], "fno-sanitize-stats">,
  Group, Flags<[CC1Option]>,
  HelpText<"Disable sanitizer statistics gathering.">;
+def fsanitize_thread_memory_access : Flag<["-"], "fsanitize-thread-memory-access">,
+ Group,
+ HelpText<"Enable memory access instrumentation in ThreadSanitizer (default)">;
+def fno_sanitize_thread_memory_access : Flag<["-"], "fno-sanitize-thread-memory-access">,
+Group,
+HelpText<"Disable memory access instrumentation in ThreadSanitizer">;
+def fsanitize_thread_func_entry_exit : Flag<["-"], "fsanitize-thread-func-entry-exit">,
+   Group,
+   HelpText<"Enable function entry/exit instrumentation in ThreadSanitizer (default)">;
+def fno_sanitize_thread_func_entry_exit : Flag<["-"], "fno-sanitize-thread-func-entry-exit">,
+  Group,
+  HelpText<"Disable function entry/exit instrumentation in ThreadSanitizer">;
+def fsanitize_thread_atomics : Flag<["-"], "fsanitize-thread-atomics">,
+   Group,
+   HelpText<"Enable atomic operations instrumentation in ThreadSanitizer (default)">;
+def fno_sanitize_thread_atomics : Flag<["-"], "fno-sanitize-thread-atomics">,
+  Group,
+  HelpText<"Disable atomic operations instrumentation in ThreadSanitizer">;
 def fsanitize_undefined_strip_path_components_EQ : Joined<["-"], "fsanitize-undefined-strip-path-components=">,
   Group, Flags<[CC1Option]>, MetaVarName<"">,
   HelpText<"Strip (or keep only, if negative) a given number of path components "
Index: cfe/trunk/include/clang/Driver/SanitizerArgs.h
===
--- cfe/trunk/include/clang/Driver/SanitizerArgs.h
+++ cfe/trunk/include/clang/Driver/SanitizerArgs.h
@@ -38,6 +38,9 @@
   bool LinkCXXRuntimes = false;
   bool NeedPIE = false;
   bool Stats = false;
+  bool TsanMemoryAccess = true;
+  bool TsanFuncEntryExit = true;
+  bool TsanAtomics = true;
 
  public:
   /// Parses the sanitizer arguments from an argument list.
Index: cfe/trunk/test/Driver/fsanitize.c
===
--- cfe/trunk/test/Driver/fsanitize.c
+++ cfe/trunk/test/Driver/fsanitize.c
@@ -278,6 +278,35 @@
 // RUN: %clang -target i386-apple-tvossimulator -fsanitize=thread %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-TSAN-I386-TVOSSIMULATOR
 // CHECK-TSAN-I386-TVOSSIMULATOR: unsupported option '-fsanitize=thread' for target 'i386-apple-tvossimulator'
 
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=thread -fsanitize-thread-memory-access %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-TSAN-MEMORY-ACCESS
+// CHECK-TSAN-MEMORY-ACCESS-NOT: -cc1{{.*}}tsan-instrument-memory-accesses=0
+// CHECK-TSAN-MEMORY-ACCESS-NOT: -cc1{{.*}}tsan-instrument-memintrinsics=0
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=thread -fno-sanitize-thread-memory-access %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-TSAN-MEMORY-ACCESS-OFF
+// CHECK-TSAN-MEMORY-ACCESS-OFF: -cc1{{.*}}tsan-instrument-memory-accesses=0{{.*}}tsan-instrument-memintrinsics=0
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=thread -fno-sanitize-thread-memory-access -fsanitize-thread-memory-access %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-TSAN-MEMORY-ACCESS-BOTH
+// CHECK-TSAN-MEMORY-ACCESS-BOTH-NOT: -cc1{{.*}}tsan-instrument-memory-accesses=0
+// CHECK-TSAN-MEMORY-ACCESS-BOTH-NOT: -cc1{{.*}}tsan-instrument-memintrinsics=0
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=thread -fsanitize-thread-memory-access -fno-sanitize-thread-memory-access %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-TSAN-MEMORY-ACCESS-BOTH-OFF
+// CHECK-TSAN-MEMORY-ACCESS-BOTH-OFF: -cc1{{.*}}tsan-instrument-memory-accesses=0{{.*}}tsan-instrument-memintrinsics=0
+
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=thread -fsanitize-thread-func-entry-exit 

Re: [PATCH] D12712: Implementation and testing for poisoning vtable ptr in dtor.

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


Comment at: lib/CodeGen/CGClass.cpp:1671
@@ -1670,1 +1670,3 @@
 
+  ASTContext &Context = CGF.getContext();
+  // Poison vtable and vtable ptr if they exist for this class.

You are poisoning the vtable pointer in the base destructor.
Isn't that too early?
For example, in the following case the vptr would be poisoned before ~A, right?
https://github.com/google/sanitizers/wiki/ThreadSanitizerPopularDataRaces#data-race-on-vptr



http://reviews.llvm.org/D12712



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


Re: [PATCH] D12712: Implementation and testing for poisoning vtable ptr in dtor.

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


Comment at: lib/CodeGen/CGClass.cpp:1685
@@ +1684,3 @@
+// function
+Poison(CGF, VTablePtr, PoisonSize);
+  }

Did you mean to move this chunk to the other cleanup class?
Is there a test that would fail if vptr is prematurely poisoned? There should 
be one (it's ok if it is only in compiler-rt, this could be hard to test with 
lit over IR).



http://reviews.llvm.org/D12712



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


Re: [PATCH] D12712: Implementation and testing for poisoning vtable ptr in dtor.

2015-09-10 Thread Evgeniy Stepanov via cfe-commits
eugenis added a comment.

So, this can not be moved to the complete destructor because that would fail to 
poisons vptrs of the base classes. On the other hand, the current 
implementation is a bit wasteful, as it can poison the same pointer multiple 
times when it is shared by the derived class and the first base.

Maybe skip poisoning if the first base (or whatever is at offset 0 in the 
record layout) is a dynamic class with non-trivial destructor?



Comment at: lib/CodeGen/CGClass.cpp:1652
@@ +1651,3 @@
+
+ static void Poison(CodeGenFunction &CGF, llvm::Value *OffsetPtr,
+CharUnits::QuantityType PoisonSize);

If it's a global function, it should have a more descriptive name, like 
EmitSanitizerDtorCallback.
OffsetPtr => just Ptr
And move the body of the function to this line to avoid unnecessary 
redeclaration.


Comment at: test/CodeGenCXX/sanitize-dtor-derived-class.cpp:67
@@ -63,3 +66,3 @@
 // CHECK: call void {{.*}}BaseD2Ev
-// CHECK-NOT: call void @__sanitizer_dtor_callback
+// CHECK: call void @__sanitizer_dtor_callback
 // CHECK: ret void

Check that this poisons exactly 8 bytes.


http://reviews.llvm.org/D12712



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


Re: [PATCH] D12712: Implementation and testing for poisoning vtable ptr in dtor.

2015-09-10 Thread Evgeniy Stepanov via cfe-commits
eugenis added inline comments.


Comment at: lib/CodeGen/CGClass.cpp:1652
@@ +1651,3 @@
+
+ static void Poison(CodeGenFunction &CGF, llvm::Value *OffsetPtr,
+CharUnits::QuantityType PoisonSize);

nmusgrave wrote:
> eugenis wrote:
> > If it's a global function, it should have a more descriptive name, like 
> > EmitSanitizerDtorCallback.
> > OffsetPtr => just Ptr
> > And move the body of the function to this line to avoid unnecessary 
> > redeclaration.
> It's inside of a namespace- is it still global?
In a sense. This namespace is not only about sanitizers, so Poison is ambiguous.


http://reviews.llvm.org/D12712



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


Re: [PATCH] D12087: always_inline codegen rewrite

2015-09-10 Thread Evgeniy Stepanov via cfe-commits
eugenis added a comment.

I'm going to commit this tomorrow unless someone speaks up.


Repository:
  rL LLVM

http://reviews.llvm.org/D12087



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


Re: [PATCH] D12087: always_inline codegen rewrite

2015-09-11 Thread Evgeniy Stepanov via cfe-commits
eugenis updated this revision to Diff 34578.
eugenis added a comment.

rebase, fix a merge conflict


Repository:
  rL LLVM

http://reviews.llvm.org/D12087

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

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

r247465 - Always_inline codegen rewrite.

2015-09-11 Thread Evgeniy Stepanov via cfe-commits
Author: eugenis
Date: Fri Sep 11 15:29:07 2015
New Revision: 247465

URL: http://llvm.org/viewvc/llvm-project?rev=247465&view=rev
Log:
Always_inline codegen rewrite.

Current implementation may end up emitting an undefined reference for
an "inline __attribute__((always_inline))" function by generating an
"available_externally alwaysinline" IR function for it and then failing to
inline all the calls. This happens when a call to such function is in dead
code. As the inliner is an SCC pass, it does not process dead code.

Libc++ relies on the compiler never emitting such undefined reference.

With this patch, we emit a pair of
1. internal alwaysinline definition (called F.alwaysinline)
2a. A stub F() { musttail call F.alwaysinline }
  -- or, depending on the linkage --
2b. A declaration of F.

The frontend ensures that F.inlinefunction is only used for direct
calls, and the stub is used for everything else (taking the address of
the function, really). Declaration (2b) is emitted in the case when
"inline" is meant for inlining only (like __gnu_inline__ and some
other cases).

This approach, among other nice properties, ensures that alwaysinline
functions are always internal, making it impossible for a direct call
to such function to produce an undefined symbol reference.

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

Added:
cfe/trunk/test/CodeGen/always_inline-unused.c
cfe/trunk/test/CodeGen/always_inline-wrappers.c
cfe/trunk/test/CodeGenCXX/alwaysinline.cpp
Modified:
cfe/trunk/lib/CodeGen/CGCXX.cpp
cfe/trunk/lib/CodeGen/CGClass.cpp
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
cfe/trunk/lib/CodeGen/CodeGenModule.h
cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
cfe/trunk/test/CodeGen/always-inline.c
cfe/trunk/test/CodeGen/always_inline.c
cfe/trunk/test/CodeGen/function-attributes.c
cfe/trunk/test/CodeGen/pr9614.c
cfe/trunk/test/Frontend/optimization-remark-line-directive.c
cfe/trunk/test/Frontend/optimization-remark.c
cfe/trunk/test/Modules/cxx-irgen.cpp

Modified: cfe/trunk/lib/CodeGen/CGCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCXX.cpp?rev=247465&r1=247464&r2=247465&view=diff
==
--- cfe/trunk/lib/CodeGen/CGCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCXX.cpp Fri Sep 11 15:29:07 2015
@@ -109,6 +109,9 @@ bool CodeGenModule::TryEmitBaseDestructo
   D->getType()->getAs()->getCallConv())
 return true;
 
+  if (BaseD->hasAttr())
+return true;
+
   return TryEmitDefinitionAsAlias(GlobalDecl(D, Dtor_Base),
   GlobalDecl(BaseD, Dtor_Base),
   false);
@@ -161,14 +164,7 @@ bool CodeGenModule::TryEmitDefinitionAsA
 
   // Instead of creating as alias to a linkonce_odr, replace all of the uses
   // of the aliasee.
-  if (llvm::GlobalValue::isDiscardableIfUnused(Linkage) &&
- (TargetLinkage != llvm::GlobalValue::AvailableExternallyLinkage ||
-  !TargetDecl.getDecl()->hasAttr())) {
-// FIXME: An extern template instantiation will create functions with
-// linkage "AvailableExternally". In libc++, some classes also define
-// members with attribute "AlwaysInline" and expect no reference to
-// be generated. It is desirable to reenable this optimisation after
-// corresponding LLVM changes.
+  if (llvm::GlobalValue::isDiscardableIfUnused(Linkage)) {
 Replacements[MangledName] = Aliasee;
 return false;
   }

Modified: cfe/trunk/lib/CodeGen/CGClass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGClass.cpp?rev=247465&r1=247464&r2=247465&view=diff
==
--- cfe/trunk/lib/CodeGen/CGClass.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGClass.cpp Fri Sep 11 15:29:07 2015
@@ -1557,7 +1557,7 @@ void CodeGenFunction::EmitDestructorBody
 // -fapple-kext must inline any call to this dtor into
 // the caller's body.
 if (getLangOpts().AppleKext)
-  CurFn->addFnAttr(llvm::Attribute::AlwaysInline);
+  CGM.AddAlwaysInlineFunction(CurFn);
 
 break;
   }

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp?rev=247465&r1=247464&r2=247465&view=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp Fri Sep 11 15:29:07 2015
@@ -2114,7 +2114,7 @@ emitTaskPrivateMappingFunction(CodeGenMo
   ".omp_task_privates_map.", &CGM.getModule());
   CGM.SetLLVMFunctionAttributes(/*D=*/nullptr, TaskPrivatesMapFnInfo,
 TaskPrivatesMap);
-  TaskPrivatesMap->addFnAttr(llvm::Attribute::AlwaysInline);
+  CGM.AddAlwaysInlineFunction(TaskPrivatesMap);
   CodeGenFunction CGF(C

Re: [PATCH] D12087: always_inline codegen rewrite

2015-09-11 Thread Evgeniy Stepanov via cfe-commits
eugenis closed this revision.
eugenis added a comment.

r247465, thanks for the review!


Repository:
  rL LLVM

http://reviews.llvm.org/D12087



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


r247473 - Specify target triple in alwaysinline tests.

2015-09-11 Thread Evgeniy Stepanov via cfe-commits
Author: eugenis
Date: Fri Sep 11 16:10:12 2015
New Revision: 247473

URL: http://llvm.org/viewvc/llvm-project?rev=247473&view=rev
Log:
Specify target triple in alwaysinline tests.

This should fix the tests on Windows (failing due to mangling differencies).

Modified:
cfe/trunk/test/CodeGen/always_inline.c
cfe/trunk/test/CodeGenCXX/alwaysinline.cpp

Modified: cfe/trunk/test/CodeGen/always_inline.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/always_inline.c?rev=247473&r1=247472&r2=247473&view=diff
==
--- cfe/trunk/test/CodeGen/always_inline.c (original)
+++ cfe/trunk/test/CodeGen/always_inline.c Fri Sep 11 16:10:12 2015
@@ -1,5 +1,5 @@
-// RUN: %clang -emit-llvm -S -o - %s | FileCheck %s
-// RUN: %clang -mllvm -disable-llvm-optzns -emit-llvm -S -o - %s | FileCheck 
%s --check-prefix=CHECK-NO-OPTZNS
+// RUN: %clang -target x86_64-pc-linux-gnu -emit-llvm -S -o - %s | FileCheck %s
+// RUN: %clang -target x86_64-pc-linux-gnu -mllvm -disable-llvm-optzns 
-emit-llvm -S -o - %s | FileCheck %s --check-prefix=CHECK-NO-OPTZNS
 
 //static int f0() { 
 static int __attribute__((always_inline)) f0() { 

Modified: cfe/trunk/test/CodeGenCXX/alwaysinline.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/alwaysinline.cpp?rev=247473&r1=247472&r2=247473&view=diff
==
--- cfe/trunk/test/CodeGenCXX/alwaysinline.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/alwaysinline.cpp Fri Sep 11 16:10:12 2015
@@ -1,10 +1,10 @@
 // Test different kinds of alwaysinline *structor definitions.
 
-// RUN: %clang_cc1 -disable-llvm-optzns -emit-llvm %s -o - | FileCheck %s 
--check-prefix=CHECK
-// RUN: %clang_cc1 -disable-llvm-optzns -emit-llvm %s -o - | FileCheck %s 
--check-prefix=CHECK-CALL
+// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -disable-llvm-optzns -emit-llvm 
%s -o - | FileCheck %s --check-prefix=CHECK
+// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -disable-llvm-optzns -emit-llvm 
%s -o - | FileCheck %s --check-prefix=CHECK-CALL
 
-// RUN: %clang_cc1 -mconstructor-aliases -disable-llvm-optzns -emit-llvm %s -o 
- | FileCheck %s --check-prefix=CHECK
-// RUN: %clang_cc1 -mconstructor-aliases -disable-llvm-optzns -emit-llvm %s -o 
- | FileCheck %s --check-prefix=CHECK-CALL
+// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -mconstructor-aliases 
-disable-llvm-optzns -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK
+// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -mconstructor-aliases 
-disable-llvm-optzns -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK-CALL
 
 struct A1 {
   __attribute__((__always_inline__)) A1() {}


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


r247491 - Revert "Specify target triple in alwaysinline tests."

2015-09-11 Thread Evgeniy Stepanov via cfe-commits
Author: eugenis
Date: Fri Sep 11 18:48:37 2015
New Revision: 247491

URL: http://llvm.org/viewvc/llvm-project?rev=247491&view=rev
Log:
Revert "Specify target triple in alwaysinline tests."
Revert "Always_inline codegen rewrite."

Breaks gdb & lldb tests.
Breaks on Fedora 22 x86_64.

Removed:
cfe/trunk/test/CodeGen/always_inline-unused.c
cfe/trunk/test/CodeGen/always_inline-wrappers.c
cfe/trunk/test/CodeGenCXX/alwaysinline.cpp
Modified:
cfe/trunk/lib/CodeGen/CGCXX.cpp
cfe/trunk/lib/CodeGen/CGClass.cpp
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
cfe/trunk/lib/CodeGen/CodeGenModule.h
cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
cfe/trunk/test/CodeGen/always-inline.c
cfe/trunk/test/CodeGen/always_inline.c
cfe/trunk/test/CodeGen/function-attributes.c
cfe/trunk/test/CodeGen/pr9614.c
cfe/trunk/test/Frontend/optimization-remark-line-directive.c
cfe/trunk/test/Frontend/optimization-remark.c
cfe/trunk/test/Modules/cxx-irgen.cpp

Modified: cfe/trunk/lib/CodeGen/CGCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCXX.cpp?rev=247491&r1=247490&r2=247491&view=diff
==
--- cfe/trunk/lib/CodeGen/CGCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCXX.cpp Fri Sep 11 18:48:37 2015
@@ -109,9 +109,6 @@ bool CodeGenModule::TryEmitBaseDestructo
   D->getType()->getAs()->getCallConv())
 return true;
 
-  if (BaseD->hasAttr())
-return true;
-
   return TryEmitDefinitionAsAlias(GlobalDecl(D, Dtor_Base),
   GlobalDecl(BaseD, Dtor_Base),
   false);
@@ -164,7 +161,14 @@ bool CodeGenModule::TryEmitDefinitionAsA
 
   // Instead of creating as alias to a linkonce_odr, replace all of the uses
   // of the aliasee.
-  if (llvm::GlobalValue::isDiscardableIfUnused(Linkage)) {
+  if (llvm::GlobalValue::isDiscardableIfUnused(Linkage) &&
+ (TargetLinkage != llvm::GlobalValue::AvailableExternallyLinkage ||
+  !TargetDecl.getDecl()->hasAttr())) {
+// FIXME: An extern template instantiation will create functions with
+// linkage "AvailableExternally". In libc++, some classes also define
+// members with attribute "AlwaysInline" and expect no reference to
+// be generated. It is desirable to reenable this optimisation after
+// corresponding LLVM changes.
 Replacements[MangledName] = Aliasee;
 return false;
   }

Modified: cfe/trunk/lib/CodeGen/CGClass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGClass.cpp?rev=247491&r1=247490&r2=247491&view=diff
==
--- cfe/trunk/lib/CodeGen/CGClass.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGClass.cpp Fri Sep 11 18:48:37 2015
@@ -1557,7 +1557,7 @@ void CodeGenFunction::EmitDestructorBody
 // -fapple-kext must inline any call to this dtor into
 // the caller's body.
 if (getLangOpts().AppleKext)
-  CGM.AddAlwaysInlineFunction(CurFn);
+  CurFn->addFnAttr(llvm::Attribute::AlwaysInline);
 
 break;
   }

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp?rev=247491&r1=247490&r2=247491&view=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp Fri Sep 11 18:48:37 2015
@@ -2114,7 +2114,7 @@ emitTaskPrivateMappingFunction(CodeGenMo
   ".omp_task_privates_map.", &CGM.getModule());
   CGM.SetLLVMFunctionAttributes(/*D=*/nullptr, TaskPrivatesMapFnInfo,
 TaskPrivatesMap);
-  CGM.AddAlwaysInlineFunction(TaskPrivatesMap);
+  TaskPrivatesMap->addFnAttr(llvm::Attribute::AlwaysInline);
   CodeGenFunction CGF(CGM);
   CGF.disableDebugInfo();
   CGF.StartFunction(GlobalDecl(), C.VoidTy, TaskPrivatesMap,

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=247491&r1=247490&r2=247491&view=diff
==
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Fri Sep 11 18:48:37 2015
@@ -448,103 +448,6 @@ void CodeGenModule::Release() {
   EmitVersionIdentMetadata();
 
   EmitTargetMetadata();
-
-  RewriteAlwaysInlineFunctions();
-}
-
-void CodeGenModule::AddAlwaysInlineFunction(llvm::Function *Fn) {
-  AlwaysInlineFunctions.push_back(Fn);
-}
-
-/// Find all uses of GV that are not direct calls or invokes.
-static void FindNonDirectCallUses(llvm::GlobalValue *GV,
-  llvm::SmallVectorImpl *Uses) {
-  llvm::GlobalValue::use_iterator UI = GV->use_begin(), E = GV->use_end();
-  for (; UI != E;) {
-llvm::Use &U = *UI;
-++UI;
-
-llvm::C

Re: [PATCH] D12087: always_inline codegen rewrite

2015-09-11 Thread Evgeniy Stepanov via cfe-commits
eugenis updated this revision to Diff 34610.
eugenis added a comment.

Fixed the debug info problem.


Repository:
  rL LLVM

http://reviews.llvm.org/D12087

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

Index: test/Modules/cxx-irgen.cpp
===
--- test/Modules/cxx-irgen.cpp
+++ test/Modules/cxx-irgen.cpp
@@ -26,14 +26,14 @@
   };
 }
 
-// CHECK-DAG: define available_externally hidden {{.*}}{{signext i32|i32}} @_ZN1SIiE1gEv({{.*}} #[[ALWAYS_INLINE:.*]] align
+// CHECK-DAG: define internal i32 @_ZN1SIiE1gEv.alwaysinline() #[[ALWAYS_INLINE:.*]] align
 int a = S::g();
 
 int b = h();
 
 // CHECK-DAG: define linkonce_odr {{.*}}{{signext i32|i32}} @_Z3minIiET_S0_S0_(i32
 int c = min(1, 2);
-// CHECK: define available_externally {{.*}}{{signext i32|i32}} @_ZN1SIiE1fEv({{.*}} #[[ALWAYS_INLINE]] align
+// CHECK-DAG: define internal {{.*}}{{signext i32|i32}} @_ZN1SIiE1fEv.alwaysinline() #[[ALWAYS_INLINE]] align
 
 namespace ImplicitSpecialMembers {
   // CHECK-LABEL: define {{.*}} @_ZN22ImplicitSpecialMembers1BC2ERKS0_(
Index: test/Frontend/optimization-remark.c
===
--- test/Frontend/optimization-remark.c
+++ test/Frontend/optimization-remark.c
@@ -32,6 +32,8 @@
 // CHECK-NOT: !llvm.dbg.cu = !{
 
 int foo(int x, int y) __attribute__((always_inline));
+// expected-remark@+2 {{foo.alwaysinline should always be inlined}}
+// expected-remark@+1 {{foo.alwaysinline inlined into foo}}
 int foo(int x, int y) { return x + y; }
 
 float foz(int x, int y) __attribute__((noinline));
@@ -45,7 +47,7 @@
 // expected-remark@+5 {{foz will not be inlined into bar}}
 // expected-remark@+4 {{foz should never be inlined}}
 // expected-remark@+3 {{foz will not be inlined into bar}}
-// expected-remark@+2 {{foo should always be inlined}}
-// expected-remark@+1 {{foo inlined into bar}}
+// expected-remark@+2 {{foo.alwaysinline should always be inlined}}
+// expected-remark@+1 {{foo.alwaysinline inlined into bar}}
   return foo(j, j - 2) * foz(j - 2, j);
 }
Index: test/Frontend/optimization-remark-line-directive.c
===
--- test/Frontend/optimization-remark-line-directive.c
+++ test/Frontend/optimization-remark-line-directive.c
@@ -5,8 +5,9 @@
 // RUN: %clang_cc1 %s -Rpass=inline -gline-tables-only -dwarf-column-info -emit-llvm-only -verify
 
 int foo(int x, int y) __attribute__((always_inline));
+// expected-remark@+1 {{foo.alwaysinline inlined into foo}}
 int foo(int x, int y) { return x + y; }
 
-// expected-remark@+2 {{foo inlined into bar}} expected-note@+2 {{could not determine the original source location for /bad/path/to/original.c:1230:25}}
+// expected-remark@+2 {{foo.alwaysinline inlined into bar}} expected-note@+2 {{could not determine the original source location for /bad/path/to/original.c:1230:25}}
 #line 1230 "/bad/path/to/original.c"
 int bar(int j) { return foo(j, j - 2); }
Index: test/CodeGenCXX/alwaysinline.cpp
===
--- /dev/null
+++ test/CodeGenCXX/alwaysinline.cpp
@@ -0,0 +1,68 @@
+// Test different kinds of alwaysinline *structor definitions.
+
+// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -disable-llvm-optzns -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK
+// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -disable-llvm-optzns -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK-CALL
+
+// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -mconstructor-aliases -disable-llvm-optzns -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK
+// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -mconstructor-aliases -disable-llvm-optzns -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK-CALL
+
+struct A1 {
+  __attribute__((__always_inline__)) A1() {}
+  __attribute__((__always_inline__)) ~A1() {}
+};
+
+void g1() {
+  A1 a1;
+}
+
+struct A2 {
+  inline __attribute__((__always_inline__)) A2() {}
+  inline __attribute__((__always_inline__)) ~A2() {}
+};
+
+void g2() {
+  A2 a2;
+}
+
+struct A3 {
+  inline __attribute__((gnu_inline, __always_inline__)) A3() {}
+  inline __attribute__((gnu_inline, __always_inline__)) ~A3() {}
+};
+
+void g3() {
+  A3 a3;
+}
+
+// CHECK-DAG: define internal void @_ZN2A1C1Ev.alwaysinline(%struct.A1* %this) unnamed_addr #[[AI:[01-9]+]]
+// CHECK-DAG: define internal void @_ZN2A1C2Ev.alwaysinline(%struct.A1* %this) unnamed_addr #[[AI]]
+// CHECK-DAG: define interna

Re: [PATCH] D12087: always_inline codegen rewrite

2015-09-11 Thread Evgeniy Stepanov via cfe-commits
eugenis added inline comments.


Comment at: lib/CodeGen/CodeGenModule.cpp:543
@@ +542,3 @@
+  if (Fn->isUsedByMetadata())
+llvm::ValueAsMetadata::handleRAUW(Fn, StubFn);
+}

As the comment says.
W/o this, the debug info for .alwaysinline instructions is attached to the 
.alwaysinline function, which gets deleted before codegen, and we end up with 
DI as if it is just a declaration (no low/high pc, etc).



Repository:
  rL LLVM

http://reviews.llvm.org/D12087



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


r247494 - Always_inline codegen rewrite.

2015-09-11 Thread Evgeniy Stepanov via cfe-commits
Author: eugenis
Date: Fri Sep 11 20:07:37 2015
New Revision: 247494

URL: http://llvm.org/viewvc/llvm-project?rev=247494&view=rev
Log:
Always_inline codegen rewrite.

Current implementation may end up emitting an undefined reference for
an "inline __attribute__((always_inline))" function by generating an
"available_externally alwaysinline" IR function for it and then failing to
inline all the calls. This happens when a call to such function is in dead
code. As the inliner is an SCC pass, it does not process dead code.

Libc++ relies on the compiler never emitting such undefined reference.

With this patch, we emit a pair of
1. internal alwaysinline definition (called F.alwaysinline)
2a. A stub F() { musttail call F.alwaysinline }
  -- or, depending on the linkage --
2b. A declaration of F.

The frontend ensures that F.inlinefunction is only used for direct
calls, and the stub is used for everything else (taking the address of
the function, really). Declaration (2b) is emitted in the case when
"inline" is meant for inlining only (like __gnu_inline__ and some
other cases).

This approach, among other nice properties, ensures that alwaysinline
functions are always internal, making it impossible for a direct call
to such function to produce an undefined symbol reference.

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

Added:
cfe/trunk/test/CodeGen/always_inline-unused.c
cfe/trunk/test/CodeGen/always_inline-wrappers.c
cfe/trunk/test/CodeGenCXX/alwaysinline.cpp
Modified:
cfe/trunk/lib/CodeGen/CGCXX.cpp
cfe/trunk/lib/CodeGen/CGClass.cpp
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
cfe/trunk/lib/CodeGen/CodeGenModule.h
cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
cfe/trunk/test/CodeGen/always-inline.c
cfe/trunk/test/CodeGen/always_inline.c
cfe/trunk/test/CodeGen/function-attributes.c
cfe/trunk/test/CodeGen/pr9614.c
cfe/trunk/test/Frontend/optimization-remark-line-directive.c
cfe/trunk/test/Frontend/optimization-remark.c
cfe/trunk/test/Modules/cxx-irgen.cpp

Modified: cfe/trunk/lib/CodeGen/CGCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCXX.cpp?rev=247494&r1=247493&r2=247494&view=diff
==
--- cfe/trunk/lib/CodeGen/CGCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCXX.cpp Fri Sep 11 20:07:37 2015
@@ -109,6 +109,9 @@ bool CodeGenModule::TryEmitBaseDestructo
   D->getType()->getAs()->getCallConv())
 return true;
 
+  if (BaseD->hasAttr())
+return true;
+
   return TryEmitDefinitionAsAlias(GlobalDecl(D, Dtor_Base),
   GlobalDecl(BaseD, Dtor_Base),
   false);
@@ -161,14 +164,7 @@ bool CodeGenModule::TryEmitDefinitionAsA
 
   // Instead of creating as alias to a linkonce_odr, replace all of the uses
   // of the aliasee.
-  if (llvm::GlobalValue::isDiscardableIfUnused(Linkage) &&
- (TargetLinkage != llvm::GlobalValue::AvailableExternallyLinkage ||
-  !TargetDecl.getDecl()->hasAttr())) {
-// FIXME: An extern template instantiation will create functions with
-// linkage "AvailableExternally". In libc++, some classes also define
-// members with attribute "AlwaysInline" and expect no reference to
-// be generated. It is desirable to reenable this optimisation after
-// corresponding LLVM changes.
+  if (llvm::GlobalValue::isDiscardableIfUnused(Linkage)) {
 Replacements[MangledName] = Aliasee;
 return false;
   }

Modified: cfe/trunk/lib/CodeGen/CGClass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGClass.cpp?rev=247494&r1=247493&r2=247494&view=diff
==
--- cfe/trunk/lib/CodeGen/CGClass.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGClass.cpp Fri Sep 11 20:07:37 2015
@@ -1557,7 +1557,7 @@ void CodeGenFunction::EmitDestructorBody
 // -fapple-kext must inline any call to this dtor into
 // the caller's body.
 if (getLangOpts().AppleKext)
-  CurFn->addFnAttr(llvm::Attribute::AlwaysInline);
+  CGM.AddAlwaysInlineFunction(CurFn);
 
 break;
   }

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp?rev=247494&r1=247493&r2=247494&view=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp Fri Sep 11 20:07:37 2015
@@ -2114,7 +2114,7 @@ emitTaskPrivateMappingFunction(CodeGenMo
   ".omp_task_privates_map.", &CGM.getModule());
   CGM.SetLLVMFunctionAttributes(/*D=*/nullptr, TaskPrivatesMapFnInfo,
 TaskPrivatesMap);
-  TaskPrivatesMap->addFnAttr(llvm::Attribute::AlwaysInline);
+  CGM.AddAlwaysInlineFunction(TaskPrivatesMap);
   CodeGenFunction CGF(C

Re: [PATCH] D12087: always_inline codegen rewrite

2015-09-11 Thread Evgeniy Stepanov via cfe-commits
eugenis added a comment.

second attempt in r247494


Repository:
  rL LLVM

http://reviews.llvm.org/D12087



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


r247620 - Revert "Always_inline codegen rewrite" and 2 follow-ups.

2015-09-14 Thread Evgeniy Stepanov via cfe-commits
Author: eugenis
Date: Mon Sep 14 16:35:16 2015
New Revision: 247620

URL: http://llvm.org/viewvc/llvm-project?rev=247620&view=rev
Log:
Revert "Always_inline codegen rewrite" and 2 follow-ups.

Revert "Update cxx-irgen.cpp test to allow signext in alwaysinline functions."
Revert "[CodeGen] Remove wrapper-free always_inline functions from COMDATs"
Revert "Always_inline codegen rewrite."

Reason for revert: PR24793.

Removed:
cfe/trunk/test/CodeGen/always_inline-unused.c
cfe/trunk/test/CodeGen/always_inline-wrappers.c
cfe/trunk/test/CodeGenCXX/alwaysinline.cpp
Modified:
cfe/trunk/lib/CodeGen/CGCXX.cpp
cfe/trunk/lib/CodeGen/CGClass.cpp
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
cfe/trunk/lib/CodeGen/CodeGenModule.h
cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
cfe/trunk/test/CodeGen/always-inline.c
cfe/trunk/test/CodeGen/always_inline.c
cfe/trunk/test/CodeGen/function-attributes.c
cfe/trunk/test/CodeGen/pr9614.c
cfe/trunk/test/Frontend/optimization-remark-line-directive.c
cfe/trunk/test/Frontend/optimization-remark.c
cfe/trunk/test/Modules/cxx-irgen.cpp

Modified: cfe/trunk/lib/CodeGen/CGCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCXX.cpp?rev=247620&r1=247619&r2=247620&view=diff
==
--- cfe/trunk/lib/CodeGen/CGCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCXX.cpp Mon Sep 14 16:35:16 2015
@@ -109,9 +109,6 @@ bool CodeGenModule::TryEmitBaseDestructo
   D->getType()->getAs()->getCallConv())
 return true;
 
-  if (BaseD->hasAttr())
-return true;
-
   return TryEmitDefinitionAsAlias(GlobalDecl(D, Dtor_Base),
   GlobalDecl(BaseD, Dtor_Base),
   false);
@@ -164,7 +161,14 @@ bool CodeGenModule::TryEmitDefinitionAsA
 
   // Instead of creating as alias to a linkonce_odr, replace all of the uses
   // of the aliasee.
-  if (llvm::GlobalValue::isDiscardableIfUnused(Linkage)) {
+  if (llvm::GlobalValue::isDiscardableIfUnused(Linkage) &&
+ (TargetLinkage != llvm::GlobalValue::AvailableExternallyLinkage ||
+  !TargetDecl.getDecl()->hasAttr())) {
+// FIXME: An extern template instantiation will create functions with
+// linkage "AvailableExternally". In libc++, some classes also define
+// members with attribute "AlwaysInline" and expect no reference to
+// be generated. It is desirable to reenable this optimisation after
+// corresponding LLVM changes.
 Replacements[MangledName] = Aliasee;
 return false;
   }

Modified: cfe/trunk/lib/CodeGen/CGClass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGClass.cpp?rev=247620&r1=247619&r2=247620&view=diff
==
--- cfe/trunk/lib/CodeGen/CGClass.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGClass.cpp Mon Sep 14 16:35:16 2015
@@ -1557,7 +1557,7 @@ void CodeGenFunction::EmitDestructorBody
 // -fapple-kext must inline any call to this dtor into
 // the caller's body.
 if (getLangOpts().AppleKext)
-  CGM.AddAlwaysInlineFunction(CurFn);
+  CurFn->addFnAttr(llvm::Attribute::AlwaysInline);
 
 break;
   }

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp?rev=247620&r1=247619&r2=247620&view=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp Mon Sep 14 16:35:16 2015
@@ -2114,7 +2114,7 @@ emitTaskPrivateMappingFunction(CodeGenMo
   ".omp_task_privates_map.", &CGM.getModule());
   CGM.SetLLVMFunctionAttributes(/*D=*/nullptr, TaskPrivatesMapFnInfo,
 TaskPrivatesMap);
-  CGM.AddAlwaysInlineFunction(TaskPrivatesMap);
+  TaskPrivatesMap->addFnAttr(llvm::Attribute::AlwaysInline);
   CodeGenFunction CGF(CGM);
   CGF.disableDebugInfo();
   CGF.StartFunction(GlobalDecl(), C.VoidTy, TaskPrivatesMap,

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=247620&r1=247619&r2=247620&view=diff
==
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Mon Sep 14 16:35:16 2015
@@ -448,113 +448,6 @@ void CodeGenModule::Release() {
   EmitVersionIdentMetadata();
 
   EmitTargetMetadata();
-
-  RewriteAlwaysInlineFunctions();
-}
-
-void CodeGenModule::AddAlwaysInlineFunction(llvm::Function *Fn) {
-  AlwaysInlineFunctions.push_back(Fn);
-}
-
-/// Find all uses of GV that are not direct calls or invokes.
-static void FindNonDirectCallUses(llvm::GlobalValue *GV,
-  llvm::SmallVectorImpl *Uses) {
-  llvm::Globa

Re: [PATCH] D12712: Implementation and testing for poisoning vtable ptr in dtor.

2015-09-15 Thread Evgeniy Stepanov via cfe-commits
eugenis accepted this revision.
eugenis added a comment.
This revision is now accepted and ready to land.

LGTM


http://reviews.llvm.org/D12712



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


Re: [PATCH] D11963: Create a __config_site file to capture configuration decisions.

2015-09-16 Thread Evgeniy Stepanov via cfe-commits
eugenis added a comment.

Hi Eric, have you had a chance to take another look at this? It is blocking 
http://reviews.llvm.org/D11740.


http://reviews.llvm.org/D11963



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


[PATCH] D13122: Enable SafeStack on all Linux platforms

2015-09-23 Thread Evgeniy Stepanov via cfe-commits
eugenis created this revision.
eugenis added reviewers: samsonov, pcc.
eugenis added a subscriber: cfe-commits.
eugenis set the repository for this revision to rL LLVM.

I don't see the point in limiting it to x86/x86_64 in the driver. It is only 
slightly less broken on x86 than on other platforms.

Repository:
  rL LLVM

http://reviews.llvm.org/D13122

Files:
  lib/Driver/ToolChains.cpp

Index: lib/Driver/ToolChains.cpp
===
--- lib/Driver/ToolChains.cpp
+++ lib/Driver/ToolChains.cpp
@@ -3800,6 +3800,7 @@
   Res |= SanitizerKind::Address;
   Res |= SanitizerKind::KernelAddress;
   Res |= SanitizerKind::Vptr;
+  Res |= SanitizerKind::SafeStack;
   if (IsX86_64 || IsMIPS64 || IsAArch64)
 Res |= SanitizerKind::DataFlow;
   if (IsX86_64 || IsMIPS64)
@@ -3810,7 +3811,6 @@
 Res |= SanitizerKind::Memory;
   if (IsX86 || IsX86_64) {
 Res |= SanitizerKind::Function;
-Res |= SanitizerKind::SafeStack;
   }
   return Res;
 }


Index: lib/Driver/ToolChains.cpp
===
--- lib/Driver/ToolChains.cpp
+++ lib/Driver/ToolChains.cpp
@@ -3800,6 +3800,7 @@
   Res |= SanitizerKind::Address;
   Res |= SanitizerKind::KernelAddress;
   Res |= SanitizerKind::Vptr;
+  Res |= SanitizerKind::SafeStack;
   if (IsX86_64 || IsMIPS64 || IsAArch64)
 Res |= SanitizerKind::DataFlow;
   if (IsX86_64 || IsMIPS64)
@@ -3810,7 +3811,6 @@
 Res |= SanitizerKind::Memory;
   if (IsX86 || IsX86_64) {
 Res |= SanitizerKind::Function;
-Res |= SanitizerKind::SafeStack;
   }
   return Res;
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r248518 - Enable SafeStack on all Linux platforms.

2015-09-24 Thread Evgeniy Stepanov via cfe-commits
Author: eugenis
Date: Thu Sep 24 12:22:46 2015
New Revision: 248518

URL: http://llvm.org/viewvc/llvm-project?rev=248518&view=rev
Log:
Enable SafeStack on all Linux platforms.

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

Modified: cfe/trunk/lib/Driver/ToolChains.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains.cpp?rev=248518&r1=248517&r2=248518&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains.cpp Thu Sep 24 12:22:46 2015
@@ -3800,6 +3800,7 @@ SanitizerMask Linux::getSupportedSanitiz
   Res |= SanitizerKind::Address;
   Res |= SanitizerKind::KernelAddress;
   Res |= SanitizerKind::Vptr;
+  Res |= SanitizerKind::SafeStack;
   if (IsX86_64 || IsMIPS64 || IsAArch64)
 Res |= SanitizerKind::DataFlow;
   if (IsX86_64 || IsMIPS64)
@@ -3810,7 +3811,6 @@ SanitizerMask Linux::getSupportedSanitiz
 Res |= SanitizerKind::Memory;
   if (IsX86 || IsX86_64) {
 Res |= SanitizerKind::Function;
-Res |= SanitizerKind::SafeStack;
   }
   return Res;
 }

Modified: cfe/trunk/test/Driver/fsanitize.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/fsanitize.c?rev=248518&r1=248517&r2=248518&view=diff
==
--- cfe/trunk/test/Driver/fsanitize.c (original)
+++ cfe/trunk/test/Driver/fsanitize.c Thu Sep 24 12:22:46 2015
@@ -282,6 +282,8 @@
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=address,safe-stack -### %s 
2>&1 | FileCheck %s -check-prefix=SP-ASAN
 // RUN: %clang -target x86_64-linux-gnu -fstack-protector 
-fsanitize=safe-stack -### %s 2>&1 | FileCheck %s -check-prefix=SP
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=safe-stack 
-fstack-protector-all -### %s 2>&1 | FileCheck %s -check-prefix=SP
+// RUN: %clang -target arm-linux-androideabi -fsanitize=safe-stack -### %s 
2>&1 | FileCheck %s -check-prefix=SP
+// RUN: %clang -target aarch64-linux-android -fsanitize=safe-stack -### %s 
2>&1 | FileCheck %s -check-prefix=SP
 // SP-NOT: stack-protector
 // SP: "-fsanitize=safe-stack"
 // SP-ASAN-NOT: stack-protector


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


Re: [PATCH] D13122: Enable SafeStack on all Linux platforms

2015-09-24 Thread Evgeniy Stepanov via cfe-commits
eugenis added a comment.

Thanks, committed as r248518 with a test.


Repository:
  rL LLVM

http://reviews.llvm.org/D13122



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


Re: [PATCH] D12502: [libcxx] Better constain tuples constructors -- Fix PR23256 and PR22806

2015-10-02 Thread Evgeniy Stepanov via cfe-commits
eugenis added a comment.

FYI, I ran some tests and did not find any regressions and also confirmed that 
this change fixes the problem PR23256 was minimized from.
Thanks for working on this!


http://reviews.llvm.org/D12502



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


Re: [PATCH] D13407: [libcxx] Capture configuration information when installing the libc++ headers

2015-10-06 Thread Evgeniy Stepanov via cfe-commits
eugenis added a comment.

Looks great!



Comment at: include/CMakeLists.txt:31
@@ +30,3 @@
+# by  prepending __config_site to the current __config header.
+# TODO(EricWF) Is it portable to use "cat" and ">>"?
+add_custom_command(OUTPUT ${LIBCXX_BINARY_DIR}/__generated_config

I don't think >> would work on windows.
Do you really need __generated_config to be created at build time (as opposed 
to configure time)? You could use file(read) and file(append) then.



http://reviews.llvm.org/D13407



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


Re: [PATCH] D13407: [libcxx] Capture configuration information when installing the libc++ headers

2015-10-06 Thread Evgeniy Stepanov via cfe-commits
eugenis added inline comments.


Comment at: include/CMakeLists.txt:31
@@ +30,3 @@
+# by  prepending __config_site to the current __config header.
+# TODO(EricWF) Is it portable to use "cat" and ">>"?
+add_custom_command(OUTPUT ${LIBCXX_BINARY_DIR}/__generated_config

EricWF wrote:
> eugenis wrote:
> > I don't think >> would work on windows.
> > Do you really need __generated_config to be created at build time (as 
> > opposed to configure time)? You could use file(read) and file(append) then.
> > 
> I would strongly prefer the file got generated at build time so that it 
> contains any changes made in the source tree. Any other behavior is developer 
> hostile and non-obvious. In order to keep the installed headers consistent we 
> need to do this. Although I hope there is a better way to achieve this.
Right, good point. Then you could go back to the approach in D11963 where you 
called cmake in a custom command with a small script that used file(*) commands.



http://reviews.llvm.org/D13407



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


Re: [PATCH] D13407: [libcxx] Capture configuration information when installing the libc++ headers

2015-10-06 Thread Evgeniy Stepanov via cfe-commits
eugenis added a comment.

In http://reviews.llvm.org/D13407#261228, @EricWF wrote:

> Use `type` instead of `cat` on windows as suggested by @rnk. @eugenis does 
> this address your concern?


Absolutely!
LGTM


http://reviews.llvm.org/D13407



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


[PATCH] D12087: always_inline codegen rewrite

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

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

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

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

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

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

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


Repository:
  rL LLVM

http://reviews.llvm.org/D12087

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

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

Re: [PATCH] D12087: always_inline codegen rewrite

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

http://reviews.llvm.org/D12087

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

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

Re: [PATCH] D12087: always_inline codegen rewrite

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

http://reviews.llvm.org/D12087

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

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

Re: [PATCH] D12087: always_inline codegen rewrite

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


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

Good catch.


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

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


http://reviews.llvm.org/D12087



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


Re: [PATCH] D12087: always_inline codegen rewrite

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

http://reviews.llvm.org/D12087

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

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

Re: [PATCH] D12087: always_inline codegen rewrite

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


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

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


http://reviews.llvm.org/D12087



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


r245344 - [sanitizer] Add -lutil to static runtime link flags.

2015-08-18 Thread Evgeniy Stepanov via cfe-commits
Author: eugenis
Date: Tue Aug 18 15:36:11 2015
New Revision: 245344

URL: http://llvm.org/viewvc/llvm-project?rev=245344&view=rev
Log:
[sanitizer] Add -lutil to static runtime link flags.

This is needed to prevent breakage of -Wl,-as-needed link when
interceptors for functions in libutil are added. See PR15823.

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

Modified: cfe/trunk/lib/Driver/Tools.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=245344&r1=245343&r2=245344&view=diff
==
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Tue Aug 18 15:36:11 2015
@@ -2498,6 +2498,7 @@ static void linkSanitizerRuntimeDeps(con
   CmdArgs.push_back("--no-as-needed");
   CmdArgs.push_back("-lpthread");
   CmdArgs.push_back("-lrt");
+  CmdArgs.push_back("-lutil");
   CmdArgs.push_back("-lm");
   // There's no libdl on FreeBSD.
   if (TC.getTriple().getOS() != llvm::Triple::FreeBSD)

Modified: cfe/trunk/test/Driver/sanitizer-ld.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/sanitizer-ld.c?rev=245344&r1=245343&r2=245344&view=diff
==
--- cfe/trunk/test/Driver/sanitizer-ld.c (original)
+++ cfe/trunk/test/Driver/sanitizer-ld.c Tue Aug 18 15:36:11 2015
@@ -14,6 +14,7 @@
 // CHECK-ASAN-LINUX-NOT: "-export-dynamic"
 // CHECK-ASAN-LINUX: "-lpthread"
 // CHECK-ASAN-LINUX: "-lrt"
+// CHECK-ASAN-LINUX: "-lutil"
 // CHECK-ASAN-LINUX: "-ldl"
 
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
@@ -29,6 +30,7 @@
 // CHECK-SHARED-ASAN-LINUX: "-whole-archive" 
"{{.*}}libclang_rt.asan-preinit-i386.a" "-no-whole-archive"
 // CHECK-SHARED-ASAN-LINUX-NOT: "-lpthread"
 // CHECK-SHARED-ASAN-LINUX-NOT: "-lrt"
+// CHECK-SHARED-ASAN-LINUX-NOT: "-lutil"
 // CHECK-SHARED-ASAN-LINUX-NOT: "-ldl"
 // CHECK-SHARED-ASAN-LINUX-NOT: "-export-dynamic"
 // CHECK-SHARED-ASAN-LINUX-NOT: "--dynamic-list"
@@ -46,6 +48,7 @@
 // CHECK-DSO-SHARED-ASAN-LINUX: libclang_rt.asan-i386.so"
 // CHECK-DSO-SHARED-ASAN-LINUX-NOT: "-lpthread"
 // CHECK-DSO-SHARED-ASAN-LINUX-NOT: "-lrt"
+// CHECK-DSO-SHARED-ASAN-LINUX-NOT: "-lutil"
 // CHECK-DSO-SHARED-ASAN-LINUX-NOT: "-ldl"
 // CHECK-DSO-SHARED-ASAN-LINUX-NOT: "-export-dynamic"
 // CHECK-DSO-SHARED-ASAN-LINUX-NOT: "--dynamic-list"
@@ -65,6 +68,7 @@
 // CHECK-ASAN-FREEBSD: "-export-dynamic"
 // CHECK-ASAN-FREEBSD: "-lpthread"
 // CHECK-ASAN-FREEBSD: "-lrt"
+// CHECK-ASAN-FREEBSD: "-lutil"
 
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
 // RUN: -target i386-unknown-freebsd -fsanitize=address \
@@ -90,6 +94,7 @@
 // CHECK-ASAN-LINUX-CXX: stdc++
 // CHECK-ASAN-LINUX-CXX: "-lpthread"
 // CHECK-ASAN-LINUX-CXX: "-lrt"
+// CHECK-ASAN-LINUX-CXX: "-lutil"
 // CHECK-ASAN-LINUX-CXX: "-ldl"
 
 // RUN: %clang -no-canonical-prefixes %s -### -o /dev/null -fsanitize=address \
@@ -167,6 +172,7 @@
 // CHECK-TSAN-LINUX-CXX: stdc++
 // CHECK-TSAN-LINUX-CXX: "-lpthread"
 // CHECK-TSAN-LINUX-CXX: "-lrt"
+// CHECK-TSAN-LINUX-CXX: "-lutil"
 // CHECK-TSAN-LINUX-CXX: "-ldl"
 
 // RUN: %clangxx -no-canonical-prefixes %s -### -o %t.o 2>&1 \
@@ -185,6 +191,7 @@
 // CHECK-MSAN-LINUX-CXX: stdc++
 // CHECK-MSAN-LINUX-CXX: "-lpthread"
 // CHECK-MSAN-LINUX-CXX: "-lrt"
+// CHECK-MSAN-LINUX-CXX: "-lutil"
 // CHECK-MSAN-LINUX-CXX: "-ldl"
 
 // RUN: %clang -fsanitize=undefined %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


Re: [PATCH] D12022: Refactored dtor sanitizing into EHScopeStack

2015-08-19 Thread Evgeniy Stepanov via cfe-commits
eugenis added a comment.

+cfe-commits


http://reviews.llvm.org/D12022



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


Re: [PATCH] D12022: Refactored dtor sanitizing into EHScopeStack

2015-08-19 Thread Evgeniy Stepanov via cfe-commits
eugenis added a comment.

The test for virtual base that you added effectively disables the aliasing 
test, because Derived now has non-trivial members.
Move it to a separate file.



Comment at: test/CodeGenCXX/sanitize-dtor-repress-aliasing.cpp:38
@@ +37,3 @@
+// Declaration of virtual function table
+// CHECK: $_ZTV7Derived = comdat any
+

I don't think this is interesting.



Comment at: test/CodeGenCXX/sanitize-dtor-repress-aliasing.cpp:47
@@ +46,3 @@
+// CHECK: ret void
+
+// CHECK-LABEL: define {{.*}}ZN7DerivedD0Ev

That's a lot of checks.
How about:
// CHECK-LABEL: define {{.*}}ZN7DerivedD1Ev
// CHECK-NOT: ret void
// CHECK: call void {{.*}}ZN7DerivedD2Ev
// CHECK-NOT: ret void
// CHECK: call void {{.*}}ZN11VirtualBaseD2Ev
// CHECK: ret void

And the same in ZN7DerivedD2Ev.
And remove all other destructors.



http://reviews.llvm.org/D12022



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


r245619 - Revert r245344.

2015-08-20 Thread Evgeniy Stepanov via cfe-commits
Author: eugenis
Date: Thu Aug 20 16:47:16 2015
New Revision: 245619

URL: http://llvm.org/viewvc/llvm-project?rev=245619&view=rev
Log:
Revert r245344.

That change is causing strange test failures on Fedora 22 (PR24503),
and it does not have any effect with Gold linker anyway (PR15823,
https://sourceware.org/bugzilla/show_bug.cgi?id=18859).

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

Modified: cfe/trunk/lib/Driver/Tools.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=245619&r1=245618&r2=245619&view=diff
==
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Thu Aug 20 16:47:16 2015
@@ -2484,7 +2484,6 @@ static void linkSanitizerRuntimeDeps(con
   CmdArgs.push_back("--no-as-needed");
   CmdArgs.push_back("-lpthread");
   CmdArgs.push_back("-lrt");
-  CmdArgs.push_back("-lutil");
   CmdArgs.push_back("-lm");
   // There's no libdl on FreeBSD.
   if (TC.getTriple().getOS() != llvm::Triple::FreeBSD)

Modified: cfe/trunk/test/Driver/sanitizer-ld.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/sanitizer-ld.c?rev=245619&r1=245618&r2=245619&view=diff
==
--- cfe/trunk/test/Driver/sanitizer-ld.c (original)
+++ cfe/trunk/test/Driver/sanitizer-ld.c Thu Aug 20 16:47:16 2015
@@ -14,7 +14,6 @@
 // CHECK-ASAN-LINUX-NOT: "-export-dynamic"
 // CHECK-ASAN-LINUX: "-lpthread"
 // CHECK-ASAN-LINUX: "-lrt"
-// CHECK-ASAN-LINUX: "-lutil"
 // CHECK-ASAN-LINUX: "-ldl"
 
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
@@ -30,7 +29,6 @@
 // CHECK-SHARED-ASAN-LINUX: "-whole-archive" 
"{{.*}}libclang_rt.asan-preinit-i386.a" "-no-whole-archive"
 // CHECK-SHARED-ASAN-LINUX-NOT: "-lpthread"
 // CHECK-SHARED-ASAN-LINUX-NOT: "-lrt"
-// CHECK-SHARED-ASAN-LINUX-NOT: "-lutil"
 // CHECK-SHARED-ASAN-LINUX-NOT: "-ldl"
 // CHECK-SHARED-ASAN-LINUX-NOT: "-export-dynamic"
 // CHECK-SHARED-ASAN-LINUX-NOT: "--dynamic-list"
@@ -48,7 +46,6 @@
 // CHECK-DSO-SHARED-ASAN-LINUX: libclang_rt.asan-i386.so"
 // CHECK-DSO-SHARED-ASAN-LINUX-NOT: "-lpthread"
 // CHECK-DSO-SHARED-ASAN-LINUX-NOT: "-lrt"
-// CHECK-DSO-SHARED-ASAN-LINUX-NOT: "-lutil"
 // CHECK-DSO-SHARED-ASAN-LINUX-NOT: "-ldl"
 // CHECK-DSO-SHARED-ASAN-LINUX-NOT: "-export-dynamic"
 // CHECK-DSO-SHARED-ASAN-LINUX-NOT: "--dynamic-list"
@@ -68,7 +65,6 @@
 // CHECK-ASAN-FREEBSD: "-export-dynamic"
 // CHECK-ASAN-FREEBSD: "-lpthread"
 // CHECK-ASAN-FREEBSD: "-lrt"
-// CHECK-ASAN-FREEBSD: "-lutil"
 
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
 // RUN: -target i386-unknown-freebsd -fsanitize=address \
@@ -94,7 +90,6 @@
 // CHECK-ASAN-LINUX-CXX: stdc++
 // CHECK-ASAN-LINUX-CXX: "-lpthread"
 // CHECK-ASAN-LINUX-CXX: "-lrt"
-// CHECK-ASAN-LINUX-CXX: "-lutil"
 // CHECK-ASAN-LINUX-CXX: "-ldl"
 
 // RUN: %clang -no-canonical-prefixes %s -### -o /dev/null -fsanitize=address \
@@ -172,7 +167,6 @@
 // CHECK-TSAN-LINUX-CXX: stdc++
 // CHECK-TSAN-LINUX-CXX: "-lpthread"
 // CHECK-TSAN-LINUX-CXX: "-lrt"
-// CHECK-TSAN-LINUX-CXX: "-lutil"
 // CHECK-TSAN-LINUX-CXX: "-ldl"
 
 // RUN: %clangxx -no-canonical-prefixes %s -### -o %t.o 2>&1 \
@@ -191,7 +185,6 @@
 // CHECK-MSAN-LINUX-CXX: stdc++
 // CHECK-MSAN-LINUX-CXX: "-lpthread"
 // CHECK-MSAN-LINUX-CXX: "-lrt"
-// CHECK-MSAN-LINUX-CXX: "-lutil"
 // CHECK-MSAN-LINUX-CXX: "-ldl"
 
 // RUN: %clang -fsanitize=undefined %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


Re: [PATCH] D12022: Refactored dtor sanitizing into EHScopeStack

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


Comment at: lib/CodeGen/CGCXX.cpp:41
@@ +40,3 @@
+  if (getCodeGenOpts().SanitizeMemoryUseAfterDtor && Layout.getFieldCount() > 0
+  && HasTrivialDestructorBody(Context, D->getParent(), D->getParent())) {
+return true;

I'm not sure this is correct. It says not to use an alias if D has trivial 
body. Should not it be the other way around?


http://reviews.llvm.org/D12022



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


Re: [PATCH] D12022: Refactored dtor sanitizing into EHScopeStack

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


Comment at: lib/CodeGen/CGClass.cpp:1578
@@ +1577,3 @@
+if (CGF.CGM.FieldHasTrivialDestructorBody(Context, Field) ||
+Field->getType()->isPointerType()) {
+  // Start sanitizing at this field

Why do you need to special-case pointers?


http://reviews.llvm.org/D12022



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


Re: [PATCH] D12022: Refactored dtor sanitizing into EHScopeStack

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


Comment at: lib/CodeGen/CGCXX.cpp:44
@@ +43,3 @@
+  // destructors.
+  const ASTRecordLayout &Layout = Context.getASTRecordLayout(D->getParent());
+

This is unused.


Comment at: lib/CodeGen/CGCXX.cpp:47
@@ +46,3 @@
+  if (getCodeGenOpts().SanitizeMemoryUseAfterDtor &&
+  Layout.getFieldCount() > 0 && HasTrivialField(*this, D))
+return true;

This is unnecessary:
 Layout.getFieldCount() > 0


Comment at: lib/CodeGen/CGCXX.cpp:134
@@ +133,3 @@
+  //  an alias, unless this class owns no members.
+  if (getCodeGenOpts().SanitizeMemoryUseAfterDtor)
+return true;

This function is called from TryEmitBaseDestructorAsAlias.
This check is stronger than the one in the calling function, so that one has no 
effect.
Maybe move the check to this function?


Comment at: lib/CodeGen/CGClass.cpp:1355
@@ -1357,1 +1354,3 @@
+static bool CanSkipVTablePointerInitialization(CodeGenFunction &CGF,
+   ASTContext &Context,
const CXXDestructorDecl *Dtor) {

Remove context from arguments, use CGF.getContext()
Consider making this a method of CodegenFunction



Comment at: lib/CodeGen/CGClass.cpp:1489
@@ -1541,2 +1488,3 @@
 llvm::Value *ShouldDeleteCondition;
+
   public:

extra line


Comment at: lib/CodeGen/CGClass.cpp:1500
@@ -1553,1 +1499,3 @@
+  llvm::Value *ShouldCallDelete =
+  CGF.Builder.CreateIsNull(ShouldDeleteCondition);
   CGF.Builder.CreateCondBr(ShouldCallDelete, continueBB, callDeleteBB);

unrelated changes


Comment at: lib/CodeGen/CGClass.cpp:1728
@@ -1660,1 +1727,3 @@
 
+  EHStack.pushCleanup(NormalCleanup, DD);
+

1. Only do this if sanitizing.
2. I think this needs to be NormalAndEHCleanup


http://reviews.llvm.org/D12022



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


Re: [PATCH] D12022: Refactored dtor sanitizing into EHScopeStack

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


Comment at: lib/CodeGen/CGCXX.cpp:31
@@ -30,1 +30,3 @@
 
+static bool HasTrivialField(CodeGenModule &CGM, const CXXDestructorDecl *D) {
+  for (const auto *Field : D->getParent()->fields())

I think this should be called "HasFieldWithTrivialDestructor".
Also, pass D->getParent() to this function instead of D.


http://reviews.llvm.org/D12022



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


Re: [PATCH] D11740: ABI versioning macros for libc++

2015-08-26 Thread Evgeniy Stepanov via cfe-commits
eugenis removed rL LLVM as the repository for this revision.
eugenis updated this revision to Diff 33246.
eugenis added a comment.

Introduced cmake options for specifying the desired ABI version.
ABI version affects library soname and include path (include/c++/vN).
Baked ABI version into the headers (autogenerated __config_version) so that, 
ex. with -I/usr/include/c++/v2 you get major abi version=2 w/o additional -D 
settings.

Clang support for selecting vN include path is coming as a separate change.


http://reviews.llvm.org/D11740

Files:
  CMakeLists.txt
  docs/Abi.rst
  docs/BuildingLibcxx.rst
  include/CMakeLists.txt
  include/__config
  include/__config_version.cmake
  include/string
  lib/CMakeLists.txt

Index: lib/CMakeLists.txt
===
--- lib/CMakeLists.txt
+++ lib/CMakeLists.txt
@@ -129,8 +129,8 @@
 COMPILE_FLAGS "${LIBCXX_COMPILE_FLAGS}"
 LINK_FLAGS"${LIBCXX_LINK_FLAGS}"
 OUTPUT_NAME   "c++"
-VERSION   "1.0"
-SOVERSION "1"
+VERSION   "${LIBCXX_ABI_MAJOR_VERSION}.${LIBCXX_ABI_MINOR_VERSION}"
+SOVERSION "${LIBCXX_ABI_MAJOR_VERSION}"
   )
 
 install(TARGETS cxx
Index: include/string
===
--- include/string
+++ include/string
@@ -1185,7 +1185,7 @@
 #pragma warning( pop )
 #endif // _LIBCPP_MSVC
 
-#ifdef _LIBCPP_ALTERNATE_STRING_LAYOUT
+#ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
 
 template 
 struct __padding
@@ -1198,7 +1198,7 @@
 {
 };
 
-#endif  // _LIBCPP_ALTERNATE_STRING_LAYOUT
+#endif  // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
 
 template
 class _LIBCPP_TYPE_VIS_ONLY basic_string
@@ -1234,7 +1234,7 @@
 
 private:
 
-#ifdef _LIBCPP_ALTERNATE_STRING_LAYOUT
+#ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
 
 struct __long
 {
@@ -1294,7 +1294,7 @@
 value_type __data_[__min_cap];
 };
 
-#endif  // _LIBCPP_ALTERNATE_STRING_LAYOUT
+#endif  // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
 
 union __ulx{__long __lx; __short __lxx;};
 
@@ -1696,7 +1696,7 @@
 const allocator_type& __alloc() const _NOEXCEPT
 {return __r_.second();}
 
-#ifdef _LIBCPP_ALTERNATE_STRING_LAYOUT
+#ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
 
 _LIBCPP_INLINE_VISIBILITY
 void __set_short_size(size_type __s) _NOEXCEPT
@@ -1714,7 +1714,7 @@
 {return __r_.first().__s.__size_;}
 #   endif
 
-#else  // _LIBCPP_ALTERNATE_STRING_LAYOUT
+#else  // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
 
 _LIBCPP_INLINE_VISIBILITY
 void __set_short_size(size_type __s) _NOEXCEPT
@@ -1732,7 +1732,7 @@
 {return __r_.first().__s.__size_ >> 1;}
 #   endif
 
-#endif  // _LIBCPP_ALTERNATE_STRING_LAYOUT
+#endif  // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
 
 _LIBCPP_INLINE_VISIBILITY
 void __set_long_size(size_type __s) _NOEXCEPT
Index: include/__config_version.cmake
===
--- include/__config_version.cmake
+++ include/__config_version.cmake
@@ -0,0 +1,19 @@
+// -*- C++ -*-
+//===--- __config_version -===//
+//
+// 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.
+//
+//===--===//
+
+#ifndef _LIBCPP_CONFIG_VERSION
+#define _LIBCPP_CONFIG_VERSION
+
+#define _LIBCPP_ABI_MAJOR_VERSION ${LIBCXX_ABI_MAJOR_VERSION}
+#define _LIBCPP_ABI_MINOR_VERSION ${LIBCXX_ABI_MINOR_VERSION}
+
+#define _LIBCPP_ABI_VERSION (_LIBCPP_ABI_MAJOR_VERSION * 100 + _LIBCPP_ABI_MINOR_VERSION)
+
+#endif
Index: include/__config
===
--- include/__config
+++ include/__config
@@ -11,6 +11,8 @@
 #ifndef _LIBCPP_CONFIG
 #define _LIBCPP_CONFIG
 
+#include <__config_version>
+
 #if !defined(_MSC_VER) || defined(__clang__)
 #pragma GCC system_header
 #endif
@@ -23,12 +25,14 @@
 
 #define _LIBCPP_VERSION 3800
 
-#define _LIBCPP_ABI_VERSION 1
+#if _LIBCPP_ABI_VERSION >= 200
+#define _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
+#endif
 
 #define _LIBCPP_CONCAT1(_LIBCPP_X,_LIBCPP_Y) _LIBCPP_X##_LIBCPP_Y
 #define _LIBCPP_CONCAT(_LIBCPP_X,_LIBCPP_Y) _LIBCPP_CONCAT1(_LIBCPP_X,_LIBCPP_Y)
 
-#define _LIBCPP_NAMESPACE _LIBCPP_CONCAT(__,_LIBCPP_ABI_VERSION)
+#define _LIBCPP_NAMESPACE _LIBCPP_CONCAT(__,_LIBCPP_ABI_MAJOR_VERSION)
 
 
 #ifndef __has_attribute
@@ -230,9 +234,10 @@
 
 #if defined(__clang__)
 
-#if defined(__APPLE__) && !defined(__i386__) && !defined(__x86_64__) &&\
-!defined(__arm__)
-#define _LIBCPP_ALTERNATE_STRING_LAYOUT
+#if (defined(__APPLE__) && !defined(__i386__) && !defined(__x86_64__) &&   \
+ !defined(__arm__)) || \
+defined(_LIBCPP_ALTERNATE_STRING_LAYOUT)
+#define _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
 #endif
 
 #if __has_feature

Re: [PATCH] D11740: ABI versioning macros for libc++

2015-08-26 Thread Evgeniy Stepanov via cfe-commits
eugenis added a comment.

> How long is a major and minor ABI version supported?


We don't want to bump major version too often, and we want to support both +1 
and -1 of the current major version, along with all possible minor versions.

> When is the major and minor ABI version bumped?


See Abi.rst for very brief description.

> How will maintaining multiple ABI versions affect code complexity and 
> maintainability?


I'm not sure how to answer this. Depends on the feature in question. The logic 
of selecting features based on the ABI version number should not cause any 
maintenance burden by itself.

> Should bumping the ABI major version bump the SO version?

>  Should bumping the ABI major version change the include path from 
> include/c++/v1 to include/c++/v2? What kind of clang support do we need to do 
> this?


I've implemented both. We might not need this support now, but it could be 
useful at the point of v1->v2 migration.


http://reviews.llvm.org/D11740



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


[PATCH] D12382: Extend linux header search to find libc++ headers in c++/vN for any N.

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

This goes with the ABI versioning support in libc++ in 
http://reviews.llvm.org/D11740

Repository:
  rL LLVM

http://reviews.llvm.org/D12382

Files:
  lib/Driver/ToolChains.cpp
  test/Driver/Inputs/basic_linux_libcxxv2_tree/usr/bin/.keep
  test/Driver/Inputs/basic_linux_libcxxv2_tree/usr/include/c++/v2/.keep
  test/Driver/Inputs/basic_linux_libcxxv2_tree/usr/lib/.keep
  test/Driver/linux-header-search.cpp

Index: test/Driver/linux-header-search.cpp
===
--- test/Driver/linux-header-search.cpp
+++ test/Driver/linux-header-search.cpp
@@ -26,6 +26,29 @@
 // CHECK-BASIC-LIBCXX-INSTALL: "-internal-isystem" 
"[[SYSROOT]]/usr/bin/../include/c++/v1"
 // CHECK-BASIC-LIBCXX-INSTALL: "-internal-isystem" 
"[[SYSROOT]]/usr/local/include"
 //
+// RUN: %clang -no-canonical-prefixes %s -### -fsyntax-only 2>&1 \
+// RUN: -target x86_64-unknown-linux-gnu \
+// RUN: -stdlib=libc++ \
+// RUN: -ccc-install-dir %S/Inputs/basic_linux_tree/usr/bin \
+// RUN: --sysroot=%S/Inputs/basic_linux_libcxxv2_tree \
+// RUN: --gcc-toolchain="" \
+// RUN:   | FileCheck --check-prefix=CHECK-BASIC-LIBCXXV2-SYSROOT %s
+// CHECK-BASIC-LIBCXXV2-SYSROOT: "{{[^"]*}}clang{{[^"]*}}" "-cc1"
+// CHECK-BASIC-LIBCXXV2-SYSROOT: "-isysroot" "[[SYSROOT:[^"]+]]"
+// CHECK-BASIC-LIBCXXV2-SYSROOT: "-internal-isystem" 
"[[SYSROOT]]/usr/include/c++/v2"
+// CHECK-BASIC-LIBCXXV2-SYSROOT: "-internal-isystem" 
"[[SYSROOT]]/usr/local/include"
+// RUN: %clang -no-canonical-prefixes %s -### -fsyntax-only 2>&1 \
+// RUN: -target x86_64-unknown-linux-gnu \
+// RUN: -stdlib=libc++ \
+// RUN: -ccc-install-dir %S/Inputs/basic_linux_libcxxv2_tree/usr/bin \
+// RUN: --sysroot=%S/Inputs/basic_linux_libcxxv2_tree \
+// RUN: --gcc-toolchain="" \
+// RUN:   | FileCheck --check-prefix=CHECK-BASIC-LIBCXXV2-INSTALL %s
+// CHECK-BASIC-LIBCXXV2-INSTALL: "{{[^"]*}}clang{{[^"]*}}" "-cc1"
+// CHECK-BASIC-LIBCXXV2-INSTALL: "-isysroot" "[[SYSROOT:[^"]+]]"
+// CHECK-BASIC-LIBCXXV2-INSTALL: "-internal-isystem" 
"[[SYSROOT]]/usr/bin/../include/c++/v2"
+// CHECK-BASIC-LIBCXXV2-INSTALL: "-internal-isystem" 
"[[SYSROOT]]/usr/local/include"
+//
 // Test a very broken version of multiarch that shipped in Ubuntu 11.04.
 // RUN: %clang -no-canonical-prefixes %s -### -fsyntax-only 2>&1 \
 // RUN: -target i386-unknown-linux \
Index: lib/Driver/ToolChains.cpp
===
--- lib/Driver/ToolChains.cpp
+++ lib/Driver/ToolChains.cpp
@@ -3532,6 +3532,25 @@
   return true;
 }
 
+static std::string DetectLibcxxIncludePath(const std::string &base) {
+  std::error_code EC;
+  int MaxVersion = 0;
+  std::string MaxVersionString = "";
+  for (llvm::sys::fs::directory_iterator LI(base, EC), LE; !EC && LI != LE;
+   LI = LI.increment(EC)) {
+StringRef VersionText = llvm::sys::path::filename(LI->path());
+int Version;
+if (VersionText[0] == 'v' &&
+!VersionText.slice(1, StringRef::npos).getAsInteger(10, Version)) {
+  if (Version > MaxVersion) {
+MaxVersion = Version;
+MaxVersionString = VersionText;
+  }
+}
+  }
+  return MaxVersion ? base + "/" + MaxVersionString : "";
+}
+
 void Linux::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs,
  ArgStringList &CC1Args) const {
   if (DriverArgs.hasArg(options::OPT_nostdlibinc) ||
@@ -3544,14 +3563,14 @@
 // The primary location is within the Clang installation.
 // FIXME: We shouldn't hard code 'v1' here to make Clang future proof 
to
 // newer ABI versions.
-getDriver().Dir + "/../include/c++/v1",
+DetectLibcxxIncludePath(getDriver().Dir + "/../include/c++"),
 
 // We also check the system as for a long time this is the only place
 // Clang looked.
 // FIXME: We should really remove this. It doesn't make any sense.
-getDriver().SysRoot + "/usr/include/c++/v1"};
+DetectLibcxxIncludePath(getDriver().SysRoot + "/usr/include/c++")};
 for (const auto &IncludePath : LibCXXIncludePathCandidates) {
-  if (!llvm::sys::fs::exists(IncludePath))
+  if (IncludePath.empty() || !llvm::sys::fs::exists(IncludePath))
 continue;
   // Add the first candidate that exists.
   addSystemInclude(DriverArgs, CC1Args, IncludePath);


Index: test/Driver/linux-header-search.cpp
===
--- test/Driver/linux-header-search.cpp
+++ test/Driver/linux-header-search.cpp
@@ -26,6 +26,29 @@
 // CHECK-BASIC-LIBCXX-INSTALL: "-internal-isystem" "[[SYSROOT]]/usr/bin/../include/c++/v1"
 // CHECK-BASIC-LIBCXX-INSTALL: "-internal-isystem" "[[SYSROOT]]/usr/local/include"
 //
+// RUN: %clang -no-canonical-prefix

[PATCH] D12384: Libc++abi: find libc++ headers w/o find_path

2015-08-26 Thread Evgeniy Stepanov via cfe-commits
eugenis created this revision.
eugenis added reviewers: EricWF, mclow.lists.
eugenis added a subscriber: cfe-commits.
eugenis set the repository for this revision to rL LLVM.

With http://reviews.llvm.org/D11740, libc++ headers can not be used from the 
libc++ source directly, because they include an auto-generated header with ABI 
version numbers.

This change makes libc++abi pick up the headers in the binary dir. Because of 
cmake inclusion order, those headers are not ready yet when libc++abi 
CMakeLists is executed, and can not be found with find_path. Hardcode the path 
to the headers instead.


Repository:
  rL LLVM

http://reviews.llvm.org/D12384

Files:
  CMakeLists.txt

Index: CMakeLists.txt
===
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -119,6 +119,7 @@
 set(LIBCXXABI_GCC_TOOLCHAIN "" CACHE STRING "GCC toolchain for cross 
compiling.")
 set(LIBCXXABI_SYSROOT "" CACHE STRING "Sysroot for cross compiling.")
 set(LIBCXXABI_LIBCXX_LIBRARY_PATH "" CACHE STRING "The path to libc++ 
library.")
+set(LIBCXX_ABI_MAJOR_VERSION 1 CACHE STRING "Major ABI version of libc++.")
 
 # Default to building a shared library so that the default options still test
 # the libc++abi that is being built. There are two problems with testing a
@@ -133,15 +134,21 @@
   message(FATAL_ERROR "libc++abi must be built as either a shared or static 
library.")
 endif()
 
-find_path(
-  LIBCXXABI_LIBCXX_INCLUDES
-  vector
-  PATHS ${LIBCXXABI_LIBCXX_INCLUDES}
-${LIBCXXABI_LIBCXX_PATH}/include
-${CMAKE_BINARY_DIR}/${LIBCXXABI_LIBCXX_INCLUDES}
-${LLVM_MAIN_SRC_DIR}/projects/libcxx/include
-${LLVM_INCLUDE_DIR}/c++/v1
-  )
+if (NOT "${LLVM_MAIN_SRC_DIR}" STREQUAL "")
+  # When building as part of LLVM, libc++ headers will end up under
+  # ${CMAKE_BINARY_DIR}. They are not there yet, so we can not use find_path.
+  set(LIBCXXABI_LIBCXX_INCLUDES
+${CMAKE_BINARY_DIR}/include/c++/v${LIBCXX_ABI_MAJOR_VERSION})
+else()
+  find_path(
+LIBCXXABI_LIBCXX_INCLUDES
+vector
+PATHS ${LIBCXXABI_LIBCXX_INCLUDES}
+  ${CMAKE_BINARY_DIR}/include/c++/v${LIBCXX_ABI_MAJOR_VERSION}
+  ${CMAKE_BINARY_DIR}/${LIBCXXABI_LIBCXX_INCLUDES}
+  ${LLVM_INCLUDE_DIR}/c++/v${LIBCXX_ABI_MAJOR_VERSION}
+)
+endif()
 
 set(LIBCXXABI_LIBCXX_INCLUDES "${LIBCXXABI_LIBCXX_INCLUDES}" CACHE PATH
 "Specify path to libc++ includes." FORCE)


Index: CMakeLists.txt
===
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -119,6 +119,7 @@
 set(LIBCXXABI_GCC_TOOLCHAIN "" CACHE STRING "GCC toolchain for cross compiling.")
 set(LIBCXXABI_SYSROOT "" CACHE STRING "Sysroot for cross compiling.")
 set(LIBCXXABI_LIBCXX_LIBRARY_PATH "" CACHE STRING "The path to libc++ library.")
+set(LIBCXX_ABI_MAJOR_VERSION 1 CACHE STRING "Major ABI version of libc++.")
 
 # Default to building a shared library so that the default options still test
 # the libc++abi that is being built. There are two problems with testing a
@@ -133,15 +134,21 @@
   message(FATAL_ERROR "libc++abi must be built as either a shared or static library.")
 endif()
 
-find_path(
-  LIBCXXABI_LIBCXX_INCLUDES
-  vector
-  PATHS ${LIBCXXABI_LIBCXX_INCLUDES}
-${LIBCXXABI_LIBCXX_PATH}/include
-${CMAKE_BINARY_DIR}/${LIBCXXABI_LIBCXX_INCLUDES}
-${LLVM_MAIN_SRC_DIR}/projects/libcxx/include
-${LLVM_INCLUDE_DIR}/c++/v1
-  )
+if (NOT "${LLVM_MAIN_SRC_DIR}" STREQUAL "")
+  # When building as part of LLVM, libc++ headers will end up under
+  # ${CMAKE_BINARY_DIR}. They are not there yet, so we can not use find_path.
+  set(LIBCXXABI_LIBCXX_INCLUDES
+${CMAKE_BINARY_DIR}/include/c++/v${LIBCXX_ABI_MAJOR_VERSION})
+else()
+  find_path(
+LIBCXXABI_LIBCXX_INCLUDES
+vector
+PATHS ${LIBCXXABI_LIBCXX_INCLUDES}
+  ${CMAKE_BINARY_DIR}/include/c++/v${LIBCXX_ABI_MAJOR_VERSION}
+  ${CMAKE_BINARY_DIR}/${LIBCXXABI_LIBCXX_INCLUDES}
+  ${LLVM_INCLUDE_DIR}/c++/v${LIBCXX_ABI_MAJOR_VERSION}
+)
+endif()
 
 set(LIBCXXABI_LIBCXX_INCLUDES "${LIBCXXABI_LIBCXX_INCLUDES}" CACHE PATH
 "Specify path to libc++ includes." FORCE)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D12382: Extend linux header search to find libc++ headers in c++/vN for any N.

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

http://reviews.llvm.org/D12382

Files:
  lib/Driver/ToolChains.cpp
  test/Driver/Inputs/basic_linux_libcxxv2_tree/usr/bin/.keep
  test/Driver/Inputs/basic_linux_libcxxv2_tree/usr/include/c++/v2/.keep
  test/Driver/Inputs/basic_linux_libcxxv2_tree/usr/lib/.keep
  test/Driver/linux-header-search.cpp

Index: test/Driver/linux-header-search.cpp
===
--- test/Driver/linux-header-search.cpp
+++ test/Driver/linux-header-search.cpp
@@ -26,6 +26,29 @@
 // CHECK-BASIC-LIBCXX-INSTALL: "-internal-isystem" 
"[[SYSROOT]]/usr/bin/../include/c++/v1"
 // CHECK-BASIC-LIBCXX-INSTALL: "-internal-isystem" 
"[[SYSROOT]]/usr/local/include"
 //
+// RUN: %clang -no-canonical-prefixes %s -### -fsyntax-only 2>&1 \
+// RUN: -target x86_64-unknown-linux-gnu \
+// RUN: -stdlib=libc++ \
+// RUN: -ccc-install-dir %S/Inputs/basic_linux_tree/usr/bin \
+// RUN: --sysroot=%S/Inputs/basic_linux_libcxxv2_tree \
+// RUN: --gcc-toolchain="" \
+// RUN:   | FileCheck --check-prefix=CHECK-BASIC-LIBCXXV2-SYSROOT %s
+// CHECK-BASIC-LIBCXXV2-SYSROOT: "{{[^"]*}}clang{{[^"]*}}" "-cc1"
+// CHECK-BASIC-LIBCXXV2-SYSROOT: "-isysroot" "[[SYSROOT:[^"]+]]"
+// CHECK-BASIC-LIBCXXV2-SYSROOT: "-internal-isystem" 
"[[SYSROOT]]/usr/include/c++/v2"
+// CHECK-BASIC-LIBCXXV2-SYSROOT: "-internal-isystem" 
"[[SYSROOT]]/usr/local/include"
+// RUN: %clang -no-canonical-prefixes %s -### -fsyntax-only 2>&1 \
+// RUN: -target x86_64-unknown-linux-gnu \
+// RUN: -stdlib=libc++ \
+// RUN: -ccc-install-dir %S/Inputs/basic_linux_libcxxv2_tree/usr/bin \
+// RUN: --sysroot=%S/Inputs/basic_linux_libcxxv2_tree \
+// RUN: --gcc-toolchain="" \
+// RUN:   | FileCheck --check-prefix=CHECK-BASIC-LIBCXXV2-INSTALL %s
+// CHECK-BASIC-LIBCXXV2-INSTALL: "{{[^"]*}}clang{{[^"]*}}" "-cc1"
+// CHECK-BASIC-LIBCXXV2-INSTALL: "-isysroot" "[[SYSROOT:[^"]+]]"
+// CHECK-BASIC-LIBCXXV2-INSTALL: "-internal-isystem" 
"[[SYSROOT]]/usr/bin/../include/c++/v2"
+// CHECK-BASIC-LIBCXXV2-INSTALL: "-internal-isystem" 
"[[SYSROOT]]/usr/local/include"
+//
 // Test a very broken version of multiarch that shipped in Ubuntu 11.04.
 // RUN: %clang -no-canonical-prefixes %s -### -fsyntax-only 2>&1 \
 // RUN: -target i386-unknown-linux \
Index: lib/Driver/ToolChains.cpp
===
--- lib/Driver/ToolChains.cpp
+++ lib/Driver/ToolChains.cpp
@@ -3532,6 +3532,25 @@
   return true;
 }
 
+static std::string DetectLibcxxIncludePath(StringRef base) {
+  std::error_code EC;
+  int MaxVersion = 0;
+  std::string MaxVersionString = "";
+  for (llvm::sys::fs::directory_iterator LI(base, EC), LE; !EC && LI != LE;
+   LI = LI.increment(EC)) {
+StringRef VersionText = llvm::sys::path::filename(LI->path());
+int Version;
+if (VersionText[0] == 'v' &&
+!VersionText.slice(1, StringRef::npos).getAsInteger(10, Version)) {
+  if (Version > MaxVersion) {
+MaxVersion = Version;
+MaxVersionString = VersionText;
+  }
+}
+  }
+  return MaxVersion ? (base + "/" + MaxVersionString).str() : "";
+}
+
 void Linux::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs,
  ArgStringList &CC1Args) const {
   if (DriverArgs.hasArg(options::OPT_nostdlibinc) ||
@@ -3542,16 +3561,14 @@
   if (GetCXXStdlibType(DriverArgs) == ToolChain::CST_Libcxx) {
 const std::string LibCXXIncludePathCandidates[] = {
 // The primary location is within the Clang installation.
-// FIXME: We shouldn't hard code 'v1' here to make Clang future proof 
to
-// newer ABI versions.
-getDriver().Dir + "/../include/c++/v1",
+DetectLibcxxIncludePath(getDriver().Dir + "/../include/c++"),
 
 // We also check the system as for a long time this is the only place
 // Clang looked.
 // FIXME: We should really remove this. It doesn't make any sense.
-getDriver().SysRoot + "/usr/include/c++/v1"};
+DetectLibcxxIncludePath(getDriver().SysRoot + "/usr/include/c++")};
 for (const auto &IncludePath : LibCXXIncludePathCandidates) {
-  if (!llvm::sys::fs::exists(IncludePath))
+  if (IncludePath.empty() || !llvm::sys::fs::exists(IncludePath))
 continue;
   // Add the first candidate that exists.
   addSystemInclude(DriverArgs, CC1Args, IncludePath);


Index: test/Driver/linux-header-search.cpp
===
--- test/Driver/linux-header-search.cpp
+++ test/Driver/linux-header-search.cpp
@@ -26,6 +26,29 @@
 // CHECK-BASIC-LIBCXX-INSTALL: "-internal-isystem" "[[SYSROOT]]/usr/bin/../include/c++/v1"
 // CHECK-BASIC-LIBCXX-INSTALL: "-internal-isystem" "[[SYSROOT]]/usr/local/include"
 //
+// RUN: %clang -no-canonical-prefixes %s -### -fsyntax-only 2>&1 \
+// RUN: -target x86_64-unknown-

Re: [PATCH] D12382: Extend linux header search to find libc++ headers in c++/vN for any N.

2015-08-26 Thread Evgeniy Stepanov via cfe-commits
eugenis marked 2 inline comments as done.
eugenis added a comment.

http://reviews.llvm.org/D12382



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


  1   2   3   4   >