[clang] [rtsan][NFC] Add documentation link to Function Effects (PR #113979)

2024-10-28 Thread Florian Mayer via cfe-commits

https://github.com/fmayer approved this pull request.


https://github.com/llvm/llvm-project/pull/113979
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [rtsan][NFC] Add documentation link to Function Effects (PR #113979)

2024-10-28 Thread Florian Mayer via cfe-commits


@@ -11,11 +11,16 @@ RealtimeSanitizer (a.k.a. RTSan) is a real-time safety 
testing tool for C and C+
 projects. RTSan can be used to detect real-time violations, i.e. calls to 
methods
 that are not safe for use in functions with deterministic run time 
requirements.
 RTSan considers any function marked with the ``[[clang::nonblocking]]`` 
attribute
-to be a real-time function. If RTSan detects a call to ``malloc``, ``free``,
-``pthread_mutex_lock``, or anything else that could have a non-deterministic
-execution time in a function marked ``[[clang::nonblocking]]``
+to be a real-time function. At run-time, if RTSan detects a call to 
``malloc``, 
+``free``, ``pthread_mutex_lock``, or anything else that could have a 
+non-deterministic execution time in a function marked 
``[[clang::nonblocking]]``

fmayer wrote:

> or anything else that could have a non-deterministic execution time

that sounds like a guarantee. Isn't it more things that we _know_ to have a 
non-deterministic runtime

https://github.com/llvm/llvm-project/pull/113979
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [rtsan][asan] NFC Fix hyperlink to CMake doc (PR #113931)

2024-10-28 Thread Florian Mayer via cfe-commits

https://github.com/fmayer approved this pull request.


https://github.com/llvm/llvm-project/pull/113931
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [FlowSensitive] Allow to dump nested RecordStorageLocation (PR #112457)

2024-10-24 Thread Florian Mayer via cfe-commits

https://github.com/fmayer closed 
https://github.com/llvm/llvm-project/pull/112457
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [rtsan][NFC] Documentation of suppression flag (PR #112727)

2024-10-23 Thread Florian Mayer via cfe-commits

https://github.com/fmayer approved this pull request.


https://github.com/llvm/llvm-project/pull/112727
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [FlowSensitive] Allow to dump nested RecordStorageLocation (PR #112457)

2024-10-23 Thread Florian Mayer via cfe-commits

fmayer wrote:

> I think this is the right change.
> 
> What I don't understand, though, is why you were getting an assert failure 
> before. (Which line is the assertion on that failed?) I would have thought if 
> you don't dump the nested record, you just get less information. Apparently 
> not so?

Because the first line of `Env.getValue` is


  assert(!isa(Loc));
```

https://github.com/llvm/llvm-project/pull/112457
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [FlowSensitive] Allow to dump nested RecordStorageLocation (PR #112457)

2024-10-22 Thread Florian Mayer via cfe-commits

fmayer wrote:

> I would suggest a brief comment explaining the choice not to filter.

I'm not sure I understand. There wasn't a choice to filter before, there was 
just the (incorrect) assumption that we don't have nested 
`RecordStorageLocation`, leading to a crash.

https://github.com/llvm/llvm-project/pull/112457
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [MTE] Apply alignment / size in AsmPrinter rather than IR (PR #111918)

2024-10-21 Thread Florian Mayer via cfe-commits


@@ -764,11 +764,18 @@ void AsmPrinter::emitGlobalVariable(const GlobalVariable 
*GV) {
 
   const DataLayout &DL = GV->getDataLayout();
   uint64_t Size = DL.getTypeAllocSize(GV->getValueType());
+  if (GV->isTagged())
+Size = alignTo(Size, 16);

fmayer wrote:

We don't need the padding to be initialized to anything in particular, the code 
shouldn't use it (other than its tag memory)

https://github.com/llvm/llvm-project/pull/111918
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [MTE] Apply alignment / size in AsmPrinter rather than IR (PR #111918)

2024-10-21 Thread Florian Mayer via cfe-commits


@@ -764,11 +764,18 @@ void AsmPrinter::emitGlobalVariable(const GlobalVariable 
*GV) {
 
   const DataLayout &DL = GV->getDataLayout();
   uint64_t Size = DL.getTypeAllocSize(GV->getValueType());
+  if (GV->isTagged())
+Size = alignTo(Size, 16);
 
   // If the alignment is specified, we *must* obey it.  Overaligning a global
   // with a specified alignment is a prompt way to break globals emitted to
   // sections and expected to be contiguous (e.g. ObjC metadata).
-  const Align Alignment = getGVAlignment(GV, DL);
+  Align Alignment = getGVAlignment(GV, DL);
+  if (GV->isTagged() && Alignment < 16) {

fmayer wrote:

Yes, but I think it's nicer for this and the Size change to be in the same 
place.

https://github.com/llvm/llvm-project/pull/111918
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [rtsan][NFC] Documentation of suppression flag (PR #112727)

2024-10-17 Thread Florian Mayer via cfe-commits


@@ -194,12 +198,43 @@ Some issues with flags can be debugged using the 
``verbosity=$NUM`` flag:
misspelled_flag
...
 
-Disabling
--
+Disabling and suppressing
+-
 
-In some circumstances, you may want to suppress error reporting in a specific 
scope.
+There are multiple ways to suppress error reporting when using 
RealtimeSanitizer.
 
-In C++, this is achieved via  ``__rtsan::ScopedDisabler``. Within the scope 
where the ``ScopedDisabler`` object is instantiated, all sanitizer error 
reports are suppressed. This suppression applies to the current scope as well 
as all invoked functions, including any functions called transitively.
+In general, ``ScopedDisabler`` should be preferred, as it is the most 
performant.
+
+.. list-table:: Suppression methods
+   :widths: 30 15 15 10 70
+   :header-rows: 1
+
+   * - Suppression method
+ - Specified at?
+ - Scope
+ - Run-time cost
+ - Description
+   * - ``ScopedDisabler``
+ - Compile-time
+ - Stack
+ - Very low
+ - Suppresses all sanitizer error reports in the current scope and all 
invoked functions.
+   * - ``function-name-matches`` suppression
+ - Run-time
+ - Single function
+ - Medium
+ - Suppresses intercepted and ``[[clang::blocking]]`` function calls by 
name.
+   * - ``call-stack-contains`` suppression
+ - Run-time
+ - Stack
+ - High
+ - Suppresses any stack trace contaning the specified pattern.
+
+
+``ScopedDisabler``
+##
+
+At compile time, RealtimeSanitizer may be disabled for a scope using 
``__rtsan::ScopedDisabler``. Within the scope where the ``ScopedDisabler`` 
object is instantiated, all sanitizer error reports are suppressed. This 
suppression applies to the current scope as well as all invoked functions, 
including any functions called transitively.

fmayer wrote:

for explicit completeness, specify that this is thread-local (which I guess it 
is)?

https://github.com/llvm/llvm-project/pull/112727
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [rtsan][NFC] Documentation of suppression flag (PR #112727)

2024-10-17 Thread Florian Mayer via cfe-commits


@@ -194,12 +198,43 @@ Some issues with flags can be debugged using the 
``verbosity=$NUM`` flag:
misspelled_flag
...
 
-Disabling
--
+Disabling and suppressing
+-
 
-In some circumstances, you may want to suppress error reporting in a specific 
scope.
+There are multiple ways to suppress error reporting when using 
RealtimeSanitizer.
 
-In C++, this is achieved via  ``__rtsan::ScopedDisabler``. Within the scope 
where the ``ScopedDisabler`` object is instantiated, all sanitizer error 
reports are suppressed. This suppression applies to the current scope as well 
as all invoked functions, including any functions called transitively.
+In general, ``ScopedDisabler`` should be preferred, as it is the most 
performant.
+
+.. list-table:: Suppression methods
+   :widths: 30 15 15 10 70
+   :header-rows: 1
+
+   * - Suppression method
+ - Specified at?
+ - Scope
+ - Run-time cost
+ - Description
+   * - ``ScopedDisabler``
+ - Compile-time
+ - Stack
+ - Very low
+ - Suppresses all sanitizer error reports in the current scope and all 
invoked functions.

fmayer wrote:

> sanitizer error reports

should this specify that this is about RTSan specifically?

https://github.com/llvm/llvm-project/pull/112727
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [rtsan][NFC] Documentation of suppression flag (PR #112727)

2024-10-17 Thread Florian Mayer via cfe-commits


@@ -194,12 +198,43 @@ Some issues with flags can be debugged using the 
``verbosity=$NUM`` flag:
misspelled_flag
...
 
-Disabling
--
+Disabling and suppressing
+-
 
-In some circumstances, you may want to suppress error reporting in a specific 
scope.
+There are multiple ways to suppress error reporting when using 
RealtimeSanitizer.
 
-In C++, this is achieved via  ``__rtsan::ScopedDisabler``. Within the scope 
where the ``ScopedDisabler`` object is instantiated, all sanitizer error 
reports are suppressed. This suppression applies to the current scope as well 
as all invoked functions, including any functions called transitively.
+In general, ``ScopedDisabler`` should be preferred, as it is the most 
performant.
+
+.. list-table:: Suppression methods
+   :widths: 30 15 15 10 70
+   :header-rows: 1
+
+   * - Suppression method
+ - Specified at?
+ - Scope
+ - Run-time cost
+ - Description
+   * - ``ScopedDisabler``
+ - Compile-time
+ - Stack
+ - Very low

fmayer wrote:

I would also not add too many implementation details into the public 
documentation. It's unlikely to be useful, not unlikely to be wrong at some 
point in the future when the implementation changes.

https://github.com/llvm/llvm-project/pull/112727
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [FlowSensitive] Allow to dump nested RecordStorageLocation (PR #112457)

2024-10-15 Thread Florian Mayer via cfe-commits

fmayer wrote:

An example dump that is now possible but crashed before
![image](https://github.com/user-attachments/assets/21e4ce35-4bf2-41dd-9a65-32dedb82723a)


https://github.com/llvm/llvm-project/pull/112457
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [FlowSensitive] Allow to dump nested RecordStorageLocation (PR #112457)

2024-10-15 Thread Florian Mayer via cfe-commits

https://github.com/fmayer created 
https://github.com/llvm/llvm-project/pull/112457

We have an internal analysis that uses them, and the HTML dump would
fail on the assertion.


>From 4264fe1dfed3fc54f339ad4a769d76158c5ee7d5 Mon Sep 17 00:00:00 2001
From: Florian Mayer 
Date: Tue, 15 Oct 2024 17:49:25 -0700
Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?=
 =?UTF-8?q?l=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.4
---
 clang/lib/Analysis/FlowSensitive/HTMLLogger.cpp | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/clang/lib/Analysis/FlowSensitive/HTMLLogger.cpp 
b/clang/lib/Analysis/FlowSensitive/HTMLLogger.cpp
index a36cb41a63dfb1..557df218837941 100644
--- a/clang/lib/Analysis/FlowSensitive/HTMLLogger.cpp
+++ b/clang/lib/Analysis/FlowSensitive/HTMLLogger.cpp
@@ -133,8 +133,7 @@ class ModelDumper {
   for (const auto &Child : RLoc->children())
 JOS.attributeObject("f:" + Child.first->getNameAsString(), [&] {
   if (Child.second)
-if (Value *Val = Env.getValue(*Child.second))
-  dump(*Val);
+dump(*Child.second);
 });
 
   for (const auto &SyntheticField : RLoc->synthetic_fields())

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


[clang] [llvm] [MTE] Apply alignment / size in AsmPrinter rather than IR (PR #111918)

2024-10-15 Thread Florian Mayer via cfe-commits

https://github.com/fmayer updated 
https://github.com/llvm/llvm-project/pull/111918

>From 3a962270521aa7b48b64e5ac5fa0edb900990023 Mon Sep 17 00:00:00 2001
From: Florian Mayer 
Date: Thu, 10 Oct 2024 16:05:50 -0700
Subject: [PATCH 1/4] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20in?=
 =?UTF-8?q?itial=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.4
---
 clang/lib/CodeGen/SanitizerMetadata.cpp   |  45 -
 llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp|   7 +-
 llvm/lib/Target/AArch64/AArch64.h |   2 -
 .../Target/AArch64/AArch64GlobalsTagging.cpp  | 155 --
 .../Target/AArch64/AArch64TargetMachine.cpp   |   2 -
 llvm/lib/Target/AArch64/CMakeLists.txt|   1 -
 .../llvm/lib/Target/AArch64/BUILD.gn  |   1 -
 7 files changed, 46 insertions(+), 167 deletions(-)
 delete mode 100644 llvm/lib/Target/AArch64/AArch64GlobalsTagging.cpp

diff --git a/clang/lib/CodeGen/SanitizerMetadata.cpp 
b/clang/lib/CodeGen/SanitizerMetadata.cpp
index 5b212a163611dc..784d9061647f5c 100644
--- a/clang/lib/CodeGen/SanitizerMetadata.cpp
+++ b/clang/lib/CodeGen/SanitizerMetadata.cpp
@@ -34,6 +34,37 @@ static SanitizerMask 
expandKernelSanitizerMasks(SanitizerMask Mask) {
   return Mask;
 }
 
+static bool shouldTagGlobal(const llvm::GlobalVariable &G) {
+  // For now, don't instrument constant data, as it'll be in .rodata anyway. It
+  // may be worth instrumenting these in future to stop them from being used as
+  // gadgets.
+  if (G.getName().starts_with("llvm.") || G.isThreadLocal() || G.isConstant())
+return false;
+
+  // Globals can be placed implicitly or explicitly in sections. There's two
+  // different types of globals that meet this criteria that cause problems:
+  //  1. Function pointers that are going into various init arrays (either
+  // explicitly through `__attribute__((section()))` or implicitly
+  // through `__attribute__((constructor)))`, such as ".(pre)init(_array)",
+  // ".fini(_array)", ".ctors", and ".dtors". These function pointers end 
up
+  // overaligned and overpadded, making iterating over them problematic, 
and
+  // each function pointer is individually tagged (so the iteration over
+  // them causes SIGSEGV/MTE[AS]ERR).
+  //  2. Global variables put into an explicit section, where the section's 
name
+  // is a valid C-style identifier. The linker emits a `__start_` and
+  // `__stop_` symbol for the section, so that you can iterate over
+  // globals within this section. Unfortunately, again, these globals would
+  // be tagged and so iteration causes SIGSEGV/MTE[AS]ERR.
+  //
+  // To mitigate both these cases, and because specifying a section is rare
+  // outside of these two cases, disable MTE protection for globals in any
+  // section.
+  if (G.hasSection())
+return false;
+
+  return true;
+}
+
 void SanitizerMetadata::reportGlobal(llvm::GlobalVariable *GV,
  SourceLocation Loc, StringRef Name,
  QualType Ty,
@@ -60,11 +91,15 @@ void SanitizerMetadata::reportGlobal(llvm::GlobalVariable 
*GV,
   Meta.NoHWAddress |= CGM.isInNoSanitizeList(
   FsanitizeArgument.Mask & SanitizerKind::HWAddress, GV, Loc, Ty);
 
-  Meta.Memtag |=
-  static_cast(FsanitizeArgument.Mask & SanitizerKind::MemtagGlobals);
-  Meta.Memtag &= !NoSanitizeAttrSet.hasOneOf(SanitizerKind::MemTag);
-  Meta.Memtag &= !CGM.isInNoSanitizeList(
-  FsanitizeArgument.Mask & SanitizerKind::MemTag, GV, Loc, Ty);
+  if (shouldTagGlobal(*GV)) {
+Meta.Memtag |=
+static_cast(FsanitizeArgument.Mask & 
SanitizerKind::MemtagGlobals);
+Meta.Memtag &= !NoSanitizeAttrSet.hasOneOf(SanitizerKind::MemTag);
+Meta.Memtag &= !CGM.isInNoSanitizeList(
+FsanitizeArgument.Mask & SanitizerKind::MemTag, GV, Loc, Ty);
+  } else {
+Meta.Memtag = false;
+  }
 
   Meta.IsDynInit = IsDynInit && !Meta.NoAddress &&
FsanitizeArgument.has(SanitizerKind::Address) &&
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp 
b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index 3a8cde7330efc0..6a2817f417d30d 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -764,11 +764,16 @@ void AsmPrinter::emitGlobalVariable(const GlobalVariable 
*GV) {
 
   const DataLayout &DL = GV->getDataLayout();
   uint64_t Size = DL.getTypeAllocSize(GV->getValueType());
+  if (GV->isTagged()) Size = alignTo(Size, 16);
 
   // If the alignment is specified, we *must* obey it.  Overaligning a global
   // with a specified alignment is a prompt way to break globals emitted to
   // sections and expected to be contiguous (e.g. ObjC metadata).
-  const Align Alignment = getGVAlignment(GV, DL);
+  Align Alignment = getGVAlignment(GV, DL);
+  if (GV->isTagged() && Alignment < 16) {
+assert(!GV->hasSection());
+Alignment = Al

[clang] [llvm] [MTE] Apply alignment / size in AsmPrinter rather than IR (PR #111918)

2024-10-15 Thread Florian Mayer via cfe-commits


@@ -764,11 +764,17 @@ void AsmPrinter::emitGlobalVariable(const GlobalVariable 
*GV) {
 
   const DataLayout &DL = GV->getDataLayout();
   uint64_t Size = DL.getTypeAllocSize(GV->getValueType());
+  if (GV->isTagged())
+Size = alignTo(Size, 16);
 
   // If the alignment is specified, we *must* obey it.  Overaligning a global
   // with a specified alignment is a prompt way to break globals emitted to
   // sections and expected to be contiguous (e.g. ObjC metadata).
-  const Align Alignment = getGVAlignment(GV, DL);
+  Align Alignment = getGVAlignment(GV, DL);
+  if (GV->isTagged() && Alignment < 16) {
+assert(!GV->hasSection());

fmayer wrote:

I guess people could manually do this, so we should error out in a different 
way.

https://github.com/llvm/llvm-project/pull/111918
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [MTE] Apply alignment / size in AsmPrinter rather than IR (PR #111918)

2024-10-15 Thread Florian Mayer via cfe-commits


@@ -764,11 +764,17 @@ void AsmPrinter::emitGlobalVariable(const GlobalVariable 
*GV) {
 
   const DataLayout &DL = GV->getDataLayout();
   uint64_t Size = DL.getTypeAllocSize(GV->getValueType());
+  if (GV->isTagged())
+Size = alignTo(Size, 16);
 
   // If the alignment is specified, we *must* obey it.  Overaligning a global
   // with a specified alignment is a prompt way to break globals emitted to
   // sections and expected to be contiguous (e.g. ObjC metadata).
-  const Align Alignment = getGVAlignment(GV, DL);
+  Align Alignment = getGVAlignment(GV, DL);
+  if (GV->isTagged() && Alignment < 16) {
+assert(!GV->hasSection());

fmayer wrote:

It is in `shouldTagGlobal`

https://github.com/llvm/llvm-project/pull/111918
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [MTE] Apply alignment / size in AsmPrinter rather than IR (PR #111918)

2024-10-14 Thread Florian Mayer via cfe-commits

https://github.com/fmayer ready_for_review 
https://github.com/llvm/llvm-project/pull/111918
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [NFC] [MTE] Use aarch64-linux-android34 for globals test (PR #112050)

2024-10-14 Thread Florian Mayer via cfe-commits

https://github.com/fmayer closed 
https://github.com/llvm/llvm-project/pull/112050
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [NFC] [MTE] Use aarch64-linux-android34 for globals test (PR #112050)

2024-10-14 Thread Florian Mayer via cfe-commits

https://github.com/fmayer updated 
https://github.com/llvm/llvm-project/pull/112050

>From 78e91cb54bed6ee8deda61a054776bbd3102d79d Mon Sep 17 00:00:00 2001
From: Florian Mayer 
Date: Fri, 11 Oct 2024 14:28:59 -0700
Subject: [PATCH 1/2] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20in?=
 =?UTF-8?q?itial=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.4
---
 clang/test/CodeGen/memtag-globals.cpp | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/clang/test/CodeGen/memtag-globals.cpp 
b/clang/test/CodeGen/memtag-globals.cpp
index b4f5dc0d7dcf04..d1252cdcd67a15 100644
--- a/clang/test/CodeGen/memtag-globals.cpp
+++ b/clang/test/CodeGen/memtag-globals.cpp
@@ -1,12 +1,15 @@
-// RUN: %clang_cc1 -include %S/Inputs/sanitizer-extra-source.cpp \
+// RUN: %clang_cc1 -triple aarch64-linux-android34 \
+// RUN:   -include %S/Inputs/sanitizer-extra-source.cpp \
 // RUN:   -fsanitize-ignorelist=%S/Inputs/sanitizer-ignorelist-global.txt \
 // RUN:   -fsanitize=memtag-globals -emit-llvm -o - %s | FileCheck %s
 
-// RUN: %clang_cc1 -include %S/Inputs/sanitizer-extra-source.cpp \
+// RUN: %clang_cc1 -triple aarch64-linux-android34 \
+// RUN:-include %S/Inputs/sanitizer-extra-source.cpp \
 // RUN:   -fsanitize-ignorelist=%S/Inputs/sanitizer-ignorelist-src.txt \
 // RUN:   -fsanitize=memtag-globals -emit-llvm -o - %s | \
 // RUN:   FileCheck %s --check-prefix=IGNORELIST
 
+
 int global;
 int __attribute__((no_sanitize("memtag"))) attributed_global;
 int __attribute__((disable_sanitizer_instrumentation)) 
disable_instrumentation_global;

>From b04074e4f05cb7ea89d3701f277af9262dfeb522 Mon Sep 17 00:00:00 2001
From: Florian Mayer 
Date: Fri, 11 Oct 2024 14:31:31 -0700
Subject: [PATCH 2/2] fmt

Created using spr 1.3.4
---
 clang/test/CodeGen/memtag-globals.cpp | 1 -
 1 file changed, 1 deletion(-)

diff --git a/clang/test/CodeGen/memtag-globals.cpp 
b/clang/test/CodeGen/memtag-globals.cpp
index d1252cdcd67a15..ae2d32ae8a56d9 100644
--- a/clang/test/CodeGen/memtag-globals.cpp
+++ b/clang/test/CodeGen/memtag-globals.cpp
@@ -9,7 +9,6 @@
 // RUN:   -fsanitize=memtag-globals -emit-llvm -o - %s | \
 // RUN:   FileCheck %s --check-prefix=IGNORELIST
 
-
 int global;
 int __attribute__((no_sanitize("memtag"))) attributed_global;
 int __attribute__((disable_sanitizer_instrumentation)) 
disable_instrumentation_global;

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


[clang] [NFC] [MTE] Use aarch64-linux-android34 for globals test (PR #112050)

2024-10-11 Thread Florian Mayer via cfe-commits

https://github.com/fmayer updated 
https://github.com/llvm/llvm-project/pull/112050

>From 78e91cb54bed6ee8deda61a054776bbd3102d79d Mon Sep 17 00:00:00 2001
From: Florian Mayer 
Date: Fri, 11 Oct 2024 14:28:59 -0700
Subject: [PATCH 1/2] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20in?=
 =?UTF-8?q?itial=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.4
---
 clang/test/CodeGen/memtag-globals.cpp | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/clang/test/CodeGen/memtag-globals.cpp 
b/clang/test/CodeGen/memtag-globals.cpp
index b4f5dc0d7dcf04..d1252cdcd67a15 100644
--- a/clang/test/CodeGen/memtag-globals.cpp
+++ b/clang/test/CodeGen/memtag-globals.cpp
@@ -1,12 +1,15 @@
-// RUN: %clang_cc1 -include %S/Inputs/sanitizer-extra-source.cpp \
+// RUN: %clang_cc1 -triple aarch64-linux-android34 \
+// RUN:   -include %S/Inputs/sanitizer-extra-source.cpp \
 // RUN:   -fsanitize-ignorelist=%S/Inputs/sanitizer-ignorelist-global.txt \
 // RUN:   -fsanitize=memtag-globals -emit-llvm -o - %s | FileCheck %s
 
-// RUN: %clang_cc1 -include %S/Inputs/sanitizer-extra-source.cpp \
+// RUN: %clang_cc1 -triple aarch64-linux-android34 \
+// RUN:-include %S/Inputs/sanitizer-extra-source.cpp \
 // RUN:   -fsanitize-ignorelist=%S/Inputs/sanitizer-ignorelist-src.txt \
 // RUN:   -fsanitize=memtag-globals -emit-llvm -o - %s | \
 // RUN:   FileCheck %s --check-prefix=IGNORELIST
 
+
 int global;
 int __attribute__((no_sanitize("memtag"))) attributed_global;
 int __attribute__((disable_sanitizer_instrumentation)) 
disable_instrumentation_global;

>From b04074e4f05cb7ea89d3701f277af9262dfeb522 Mon Sep 17 00:00:00 2001
From: Florian Mayer 
Date: Fri, 11 Oct 2024 14:31:31 -0700
Subject: [PATCH 2/2] fmt

Created using spr 1.3.4
---
 clang/test/CodeGen/memtag-globals.cpp | 1 -
 1 file changed, 1 deletion(-)

diff --git a/clang/test/CodeGen/memtag-globals.cpp 
b/clang/test/CodeGen/memtag-globals.cpp
index d1252cdcd67a15..ae2d32ae8a56d9 100644
--- a/clang/test/CodeGen/memtag-globals.cpp
+++ b/clang/test/CodeGen/memtag-globals.cpp
@@ -9,7 +9,6 @@
 // RUN:   -fsanitize=memtag-globals -emit-llvm -o - %s | \
 // RUN:   FileCheck %s --check-prefix=IGNORELIST
 
-
 int global;
 int __attribute__((no_sanitize("memtag"))) attributed_global;
 int __attribute__((disable_sanitizer_instrumentation)) 
disable_instrumentation_global;

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


[clang] [NFC] [MTE] Use aarch64-linux-android34 for globals test (PR #112050)

2024-10-11 Thread Florian Mayer via cfe-commits

https://github.com/fmayer created 
https://github.com/llvm/llvm-project/pull/112050

It doesn't make a difference currently, but MTE globals are only
supported on Android, so that's the more natural target to use.


>From 78e91cb54bed6ee8deda61a054776bbd3102d79d Mon Sep 17 00:00:00 2001
From: Florian Mayer 
Date: Fri, 11 Oct 2024 14:28:59 -0700
Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?=
 =?UTF-8?q?l=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.4
---
 clang/test/CodeGen/memtag-globals.cpp | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/clang/test/CodeGen/memtag-globals.cpp 
b/clang/test/CodeGen/memtag-globals.cpp
index b4f5dc0d7dcf04..d1252cdcd67a15 100644
--- a/clang/test/CodeGen/memtag-globals.cpp
+++ b/clang/test/CodeGen/memtag-globals.cpp
@@ -1,12 +1,15 @@
-// RUN: %clang_cc1 -include %S/Inputs/sanitizer-extra-source.cpp \
+// RUN: %clang_cc1 -triple aarch64-linux-android34 \
+// RUN:   -include %S/Inputs/sanitizer-extra-source.cpp \
 // RUN:   -fsanitize-ignorelist=%S/Inputs/sanitizer-ignorelist-global.txt \
 // RUN:   -fsanitize=memtag-globals -emit-llvm -o - %s | FileCheck %s
 
-// RUN: %clang_cc1 -include %S/Inputs/sanitizer-extra-source.cpp \
+// RUN: %clang_cc1 -triple aarch64-linux-android34 \
+// RUN:-include %S/Inputs/sanitizer-extra-source.cpp \
 // RUN:   -fsanitize-ignorelist=%S/Inputs/sanitizer-ignorelist-src.txt \
 // RUN:   -fsanitize=memtag-globals -emit-llvm -o - %s | \
 // RUN:   FileCheck %s --check-prefix=IGNORELIST
 
+
 int global;
 int __attribute__((no_sanitize("memtag"))) attributed_global;
 int __attribute__((disable_sanitizer_instrumentation)) 
disable_instrumentation_global;

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


[clang] [llvm] [MTE] Apply alignment / size in AsmPrinter rather than IR (PR #111918)

2024-10-11 Thread Florian Mayer via cfe-commits

https://github.com/fmayer updated 
https://github.com/llvm/llvm-project/pull/111918

>From 3a962270521aa7b48b64e5ac5fa0edb900990023 Mon Sep 17 00:00:00 2001
From: Florian Mayer 
Date: Thu, 10 Oct 2024 16:05:50 -0700
Subject: [PATCH 1/4] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20in?=
 =?UTF-8?q?itial=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.4
---
 clang/lib/CodeGen/SanitizerMetadata.cpp   |  45 -
 llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp|   7 +-
 llvm/lib/Target/AArch64/AArch64.h |   2 -
 .../Target/AArch64/AArch64GlobalsTagging.cpp  | 155 --
 .../Target/AArch64/AArch64TargetMachine.cpp   |   2 -
 llvm/lib/Target/AArch64/CMakeLists.txt|   1 -
 .../llvm/lib/Target/AArch64/BUILD.gn  |   1 -
 7 files changed, 46 insertions(+), 167 deletions(-)
 delete mode 100644 llvm/lib/Target/AArch64/AArch64GlobalsTagging.cpp

diff --git a/clang/lib/CodeGen/SanitizerMetadata.cpp 
b/clang/lib/CodeGen/SanitizerMetadata.cpp
index 5b212a163611dc..784d9061647f5c 100644
--- a/clang/lib/CodeGen/SanitizerMetadata.cpp
+++ b/clang/lib/CodeGen/SanitizerMetadata.cpp
@@ -34,6 +34,37 @@ static SanitizerMask 
expandKernelSanitizerMasks(SanitizerMask Mask) {
   return Mask;
 }
 
+static bool shouldTagGlobal(const llvm::GlobalVariable &G) {
+  // For now, don't instrument constant data, as it'll be in .rodata anyway. It
+  // may be worth instrumenting these in future to stop them from being used as
+  // gadgets.
+  if (G.getName().starts_with("llvm.") || G.isThreadLocal() || G.isConstant())
+return false;
+
+  // Globals can be placed implicitly or explicitly in sections. There's two
+  // different types of globals that meet this criteria that cause problems:
+  //  1. Function pointers that are going into various init arrays (either
+  // explicitly through `__attribute__((section()))` or implicitly
+  // through `__attribute__((constructor)))`, such as ".(pre)init(_array)",
+  // ".fini(_array)", ".ctors", and ".dtors". These function pointers end 
up
+  // overaligned and overpadded, making iterating over them problematic, 
and
+  // each function pointer is individually tagged (so the iteration over
+  // them causes SIGSEGV/MTE[AS]ERR).
+  //  2. Global variables put into an explicit section, where the section's 
name
+  // is a valid C-style identifier. The linker emits a `__start_` and
+  // `__stop_` symbol for the section, so that you can iterate over
+  // globals within this section. Unfortunately, again, these globals would
+  // be tagged and so iteration causes SIGSEGV/MTE[AS]ERR.
+  //
+  // To mitigate both these cases, and because specifying a section is rare
+  // outside of these two cases, disable MTE protection for globals in any
+  // section.
+  if (G.hasSection())
+return false;
+
+  return true;
+}
+
 void SanitizerMetadata::reportGlobal(llvm::GlobalVariable *GV,
  SourceLocation Loc, StringRef Name,
  QualType Ty,
@@ -60,11 +91,15 @@ void SanitizerMetadata::reportGlobal(llvm::GlobalVariable 
*GV,
   Meta.NoHWAddress |= CGM.isInNoSanitizeList(
   FsanitizeArgument.Mask & SanitizerKind::HWAddress, GV, Loc, Ty);
 
-  Meta.Memtag |=
-  static_cast(FsanitizeArgument.Mask & SanitizerKind::MemtagGlobals);
-  Meta.Memtag &= !NoSanitizeAttrSet.hasOneOf(SanitizerKind::MemTag);
-  Meta.Memtag &= !CGM.isInNoSanitizeList(
-  FsanitizeArgument.Mask & SanitizerKind::MemTag, GV, Loc, Ty);
+  if (shouldTagGlobal(*GV)) {
+Meta.Memtag |=
+static_cast(FsanitizeArgument.Mask & 
SanitizerKind::MemtagGlobals);
+Meta.Memtag &= !NoSanitizeAttrSet.hasOneOf(SanitizerKind::MemTag);
+Meta.Memtag &= !CGM.isInNoSanitizeList(
+FsanitizeArgument.Mask & SanitizerKind::MemTag, GV, Loc, Ty);
+  } else {
+Meta.Memtag = false;
+  }
 
   Meta.IsDynInit = IsDynInit && !Meta.NoAddress &&
FsanitizeArgument.has(SanitizerKind::Address) &&
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp 
b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index 3a8cde7330efc0..6a2817f417d30d 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -764,11 +764,16 @@ void AsmPrinter::emitGlobalVariable(const GlobalVariable 
*GV) {
 
   const DataLayout &DL = GV->getDataLayout();
   uint64_t Size = DL.getTypeAllocSize(GV->getValueType());
+  if (GV->isTagged()) Size = alignTo(Size, 16);
 
   // If the alignment is specified, we *must* obey it.  Overaligning a global
   // with a specified alignment is a prompt way to break globals emitted to
   // sections and expected to be contiguous (e.g. ObjC metadata).
-  const Align Alignment = getGVAlignment(GV, DL);
+  Align Alignment = getGVAlignment(GV, DL);
+  if (GV->isTagged() && Alignment < 16) {
+assert(!GV->hasSection());
+Alignment = Al

[clang] [llvm] [MTE] Apply alignment / size in AsmPrinter rather than IR (PR #111918)

2024-10-11 Thread Florian Mayer via cfe-commits

https://github.com/fmayer updated 
https://github.com/llvm/llvm-project/pull/111918

>From 3a962270521aa7b48b64e5ac5fa0edb900990023 Mon Sep 17 00:00:00 2001
From: Florian Mayer 
Date: Thu, 10 Oct 2024 16:05:50 -0700
Subject: [PATCH 1/3] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20in?=
 =?UTF-8?q?itial=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.4
---
 clang/lib/CodeGen/SanitizerMetadata.cpp   |  45 -
 llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp|   7 +-
 llvm/lib/Target/AArch64/AArch64.h |   2 -
 .../Target/AArch64/AArch64GlobalsTagging.cpp  | 155 --
 .../Target/AArch64/AArch64TargetMachine.cpp   |   2 -
 llvm/lib/Target/AArch64/CMakeLists.txt|   1 -
 .../llvm/lib/Target/AArch64/BUILD.gn  |   1 -
 7 files changed, 46 insertions(+), 167 deletions(-)
 delete mode 100644 llvm/lib/Target/AArch64/AArch64GlobalsTagging.cpp

diff --git a/clang/lib/CodeGen/SanitizerMetadata.cpp 
b/clang/lib/CodeGen/SanitizerMetadata.cpp
index 5b212a163611dc..784d9061647f5c 100644
--- a/clang/lib/CodeGen/SanitizerMetadata.cpp
+++ b/clang/lib/CodeGen/SanitizerMetadata.cpp
@@ -34,6 +34,37 @@ static SanitizerMask 
expandKernelSanitizerMasks(SanitizerMask Mask) {
   return Mask;
 }
 
+static bool shouldTagGlobal(const llvm::GlobalVariable &G) {
+  // For now, don't instrument constant data, as it'll be in .rodata anyway. It
+  // may be worth instrumenting these in future to stop them from being used as
+  // gadgets.
+  if (G.getName().starts_with("llvm.") || G.isThreadLocal() || G.isConstant())
+return false;
+
+  // Globals can be placed implicitly or explicitly in sections. There's two
+  // different types of globals that meet this criteria that cause problems:
+  //  1. Function pointers that are going into various init arrays (either
+  // explicitly through `__attribute__((section()))` or implicitly
+  // through `__attribute__((constructor)))`, such as ".(pre)init(_array)",
+  // ".fini(_array)", ".ctors", and ".dtors". These function pointers end 
up
+  // overaligned and overpadded, making iterating over them problematic, 
and
+  // each function pointer is individually tagged (so the iteration over
+  // them causes SIGSEGV/MTE[AS]ERR).
+  //  2. Global variables put into an explicit section, where the section's 
name
+  // is a valid C-style identifier. The linker emits a `__start_` and
+  // `__stop_` symbol for the section, so that you can iterate over
+  // globals within this section. Unfortunately, again, these globals would
+  // be tagged and so iteration causes SIGSEGV/MTE[AS]ERR.
+  //
+  // To mitigate both these cases, and because specifying a section is rare
+  // outside of these two cases, disable MTE protection for globals in any
+  // section.
+  if (G.hasSection())
+return false;
+
+  return true;
+}
+
 void SanitizerMetadata::reportGlobal(llvm::GlobalVariable *GV,
  SourceLocation Loc, StringRef Name,
  QualType Ty,
@@ -60,11 +91,15 @@ void SanitizerMetadata::reportGlobal(llvm::GlobalVariable 
*GV,
   Meta.NoHWAddress |= CGM.isInNoSanitizeList(
   FsanitizeArgument.Mask & SanitizerKind::HWAddress, GV, Loc, Ty);
 
-  Meta.Memtag |=
-  static_cast(FsanitizeArgument.Mask & SanitizerKind::MemtagGlobals);
-  Meta.Memtag &= !NoSanitizeAttrSet.hasOneOf(SanitizerKind::MemTag);
-  Meta.Memtag &= !CGM.isInNoSanitizeList(
-  FsanitizeArgument.Mask & SanitizerKind::MemTag, GV, Loc, Ty);
+  if (shouldTagGlobal(*GV)) {
+Meta.Memtag |=
+static_cast(FsanitizeArgument.Mask & 
SanitizerKind::MemtagGlobals);
+Meta.Memtag &= !NoSanitizeAttrSet.hasOneOf(SanitizerKind::MemTag);
+Meta.Memtag &= !CGM.isInNoSanitizeList(
+FsanitizeArgument.Mask & SanitizerKind::MemTag, GV, Loc, Ty);
+  } else {
+Meta.Memtag = false;
+  }
 
   Meta.IsDynInit = IsDynInit && !Meta.NoAddress &&
FsanitizeArgument.has(SanitizerKind::Address) &&
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp 
b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index 3a8cde7330efc0..6a2817f417d30d 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -764,11 +764,16 @@ void AsmPrinter::emitGlobalVariable(const GlobalVariable 
*GV) {
 
   const DataLayout &DL = GV->getDataLayout();
   uint64_t Size = DL.getTypeAllocSize(GV->getValueType());
+  if (GV->isTagged()) Size = alignTo(Size, 16);
 
   // If the alignment is specified, we *must* obey it.  Overaligning a global
   // with a specified alignment is a prompt way to break globals emitted to
   // sections and expected to be contiguous (e.g. ObjC metadata).
-  const Align Alignment = getGVAlignment(GV, DL);
+  Align Alignment = getGVAlignment(GV, DL);
+  if (GV->isTagged() && Alignment < 16) {
+assert(!GV->hasSection());
+Alignment = Al

[clang] [llvm] [MTE] Apply alignment / size in AsmPrinter rather than IR (PR #111918)

2024-10-10 Thread Florian Mayer via cfe-commits

https://github.com/fmayer edited 
https://github.com/llvm/llvm-project/pull/111918
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [MTE] Apply alignment / size in linker rather than IR (PR #111918)

2024-10-10 Thread Florian Mayer via cfe-commits

https://github.com/fmayer edited 
https://github.com/llvm/llvm-project/pull/111918
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] Apply alignment / size in linker rather than IR (PR #111918)

2024-10-10 Thread Florian Mayer via cfe-commits

https://github.com/fmayer updated 
https://github.com/llvm/llvm-project/pull/111918

>From 3a962270521aa7b48b64e5ac5fa0edb900990023 Mon Sep 17 00:00:00 2001
From: Florian Mayer 
Date: Thu, 10 Oct 2024 16:05:50 -0700
Subject: [PATCH 1/2] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20in?=
 =?UTF-8?q?itial=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.4
---
 clang/lib/CodeGen/SanitizerMetadata.cpp   |  45 -
 llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp|   7 +-
 llvm/lib/Target/AArch64/AArch64.h |   2 -
 .../Target/AArch64/AArch64GlobalsTagging.cpp  | 155 --
 .../Target/AArch64/AArch64TargetMachine.cpp   |   2 -
 llvm/lib/Target/AArch64/CMakeLists.txt|   1 -
 .../llvm/lib/Target/AArch64/BUILD.gn  |   1 -
 7 files changed, 46 insertions(+), 167 deletions(-)
 delete mode 100644 llvm/lib/Target/AArch64/AArch64GlobalsTagging.cpp

diff --git a/clang/lib/CodeGen/SanitizerMetadata.cpp 
b/clang/lib/CodeGen/SanitizerMetadata.cpp
index 5b212a163611dc..784d9061647f5c 100644
--- a/clang/lib/CodeGen/SanitizerMetadata.cpp
+++ b/clang/lib/CodeGen/SanitizerMetadata.cpp
@@ -34,6 +34,37 @@ static SanitizerMask 
expandKernelSanitizerMasks(SanitizerMask Mask) {
   return Mask;
 }
 
+static bool shouldTagGlobal(const llvm::GlobalVariable &G) {
+  // For now, don't instrument constant data, as it'll be in .rodata anyway. It
+  // may be worth instrumenting these in future to stop them from being used as
+  // gadgets.
+  if (G.getName().starts_with("llvm.") || G.isThreadLocal() || G.isConstant())
+return false;
+
+  // Globals can be placed implicitly or explicitly in sections. There's two
+  // different types of globals that meet this criteria that cause problems:
+  //  1. Function pointers that are going into various init arrays (either
+  // explicitly through `__attribute__((section()))` or implicitly
+  // through `__attribute__((constructor)))`, such as ".(pre)init(_array)",
+  // ".fini(_array)", ".ctors", and ".dtors". These function pointers end 
up
+  // overaligned and overpadded, making iterating over them problematic, 
and
+  // each function pointer is individually tagged (so the iteration over
+  // them causes SIGSEGV/MTE[AS]ERR).
+  //  2. Global variables put into an explicit section, where the section's 
name
+  // is a valid C-style identifier. The linker emits a `__start_` and
+  // `__stop_` symbol for the section, so that you can iterate over
+  // globals within this section. Unfortunately, again, these globals would
+  // be tagged and so iteration causes SIGSEGV/MTE[AS]ERR.
+  //
+  // To mitigate both these cases, and because specifying a section is rare
+  // outside of these two cases, disable MTE protection for globals in any
+  // section.
+  if (G.hasSection())
+return false;
+
+  return true;
+}
+
 void SanitizerMetadata::reportGlobal(llvm::GlobalVariable *GV,
  SourceLocation Loc, StringRef Name,
  QualType Ty,
@@ -60,11 +91,15 @@ void SanitizerMetadata::reportGlobal(llvm::GlobalVariable 
*GV,
   Meta.NoHWAddress |= CGM.isInNoSanitizeList(
   FsanitizeArgument.Mask & SanitizerKind::HWAddress, GV, Loc, Ty);
 
-  Meta.Memtag |=
-  static_cast(FsanitizeArgument.Mask & SanitizerKind::MemtagGlobals);
-  Meta.Memtag &= !NoSanitizeAttrSet.hasOneOf(SanitizerKind::MemTag);
-  Meta.Memtag &= !CGM.isInNoSanitizeList(
-  FsanitizeArgument.Mask & SanitizerKind::MemTag, GV, Loc, Ty);
+  if (shouldTagGlobal(*GV)) {
+Meta.Memtag |=
+static_cast(FsanitizeArgument.Mask & 
SanitizerKind::MemtagGlobals);
+Meta.Memtag &= !NoSanitizeAttrSet.hasOneOf(SanitizerKind::MemTag);
+Meta.Memtag &= !CGM.isInNoSanitizeList(
+FsanitizeArgument.Mask & SanitizerKind::MemTag, GV, Loc, Ty);
+  } else {
+Meta.Memtag = false;
+  }
 
   Meta.IsDynInit = IsDynInit && !Meta.NoAddress &&
FsanitizeArgument.has(SanitizerKind::Address) &&
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp 
b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index 3a8cde7330efc0..6a2817f417d30d 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -764,11 +764,16 @@ void AsmPrinter::emitGlobalVariable(const GlobalVariable 
*GV) {
 
   const DataLayout &DL = GV->getDataLayout();
   uint64_t Size = DL.getTypeAllocSize(GV->getValueType());
+  if (GV->isTagged()) Size = alignTo(Size, 16);
 
   // If the alignment is specified, we *must* obey it.  Overaligning a global
   // with a specified alignment is a prompt way to break globals emitted to
   // sections and expected to be contiguous (e.g. ObjC metadata).
-  const Align Alignment = getGVAlignment(GV, DL);
+  Align Alignment = getGVAlignment(GV, DL);
+  if (GV->isTagged() && Alignment < 16) {
+assert(!GV->hasSection());
+Alignment = Al

[clang] [llvm] Apply alignment / size in linker rather than IR (PR #111918)

2024-10-10 Thread Florian Mayer via cfe-commits

https://github.com/fmayer created 
https://github.com/llvm/llvm-project/pull/111918

This greatly simplifies the code, and makes sure no optimizations are
applied that assume the bigger alignment or size, which could be
incorrect if we link together with non-instrumented code.


>From 3a962270521aa7b48b64e5ac5fa0edb900990023 Mon Sep 17 00:00:00 2001
From: Florian Mayer 
Date: Thu, 10 Oct 2024 16:05:50 -0700
Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?=
 =?UTF-8?q?l=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.4
---
 clang/lib/CodeGen/SanitizerMetadata.cpp   |  45 -
 llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp|   7 +-
 llvm/lib/Target/AArch64/AArch64.h |   2 -
 .../Target/AArch64/AArch64GlobalsTagging.cpp  | 155 --
 .../Target/AArch64/AArch64TargetMachine.cpp   |   2 -
 llvm/lib/Target/AArch64/CMakeLists.txt|   1 -
 .../llvm/lib/Target/AArch64/BUILD.gn  |   1 -
 7 files changed, 46 insertions(+), 167 deletions(-)
 delete mode 100644 llvm/lib/Target/AArch64/AArch64GlobalsTagging.cpp

diff --git a/clang/lib/CodeGen/SanitizerMetadata.cpp 
b/clang/lib/CodeGen/SanitizerMetadata.cpp
index 5b212a163611dc..784d9061647f5c 100644
--- a/clang/lib/CodeGen/SanitizerMetadata.cpp
+++ b/clang/lib/CodeGen/SanitizerMetadata.cpp
@@ -34,6 +34,37 @@ static SanitizerMask 
expandKernelSanitizerMasks(SanitizerMask Mask) {
   return Mask;
 }
 
+static bool shouldTagGlobal(const llvm::GlobalVariable &G) {
+  // For now, don't instrument constant data, as it'll be in .rodata anyway. It
+  // may be worth instrumenting these in future to stop them from being used as
+  // gadgets.
+  if (G.getName().starts_with("llvm.") || G.isThreadLocal() || G.isConstant())
+return false;
+
+  // Globals can be placed implicitly or explicitly in sections. There's two
+  // different types of globals that meet this criteria that cause problems:
+  //  1. Function pointers that are going into various init arrays (either
+  // explicitly through `__attribute__((section()))` or implicitly
+  // through `__attribute__((constructor)))`, such as ".(pre)init(_array)",
+  // ".fini(_array)", ".ctors", and ".dtors". These function pointers end 
up
+  // overaligned and overpadded, making iterating over them problematic, 
and
+  // each function pointer is individually tagged (so the iteration over
+  // them causes SIGSEGV/MTE[AS]ERR).
+  //  2. Global variables put into an explicit section, where the section's 
name
+  // is a valid C-style identifier. The linker emits a `__start_` and
+  // `__stop_` symbol for the section, so that you can iterate over
+  // globals within this section. Unfortunately, again, these globals would
+  // be tagged and so iteration causes SIGSEGV/MTE[AS]ERR.
+  //
+  // To mitigate both these cases, and because specifying a section is rare
+  // outside of these two cases, disable MTE protection for globals in any
+  // section.
+  if (G.hasSection())
+return false;
+
+  return true;
+}
+
 void SanitizerMetadata::reportGlobal(llvm::GlobalVariable *GV,
  SourceLocation Loc, StringRef Name,
  QualType Ty,
@@ -60,11 +91,15 @@ void SanitizerMetadata::reportGlobal(llvm::GlobalVariable 
*GV,
   Meta.NoHWAddress |= CGM.isInNoSanitizeList(
   FsanitizeArgument.Mask & SanitizerKind::HWAddress, GV, Loc, Ty);
 
-  Meta.Memtag |=
-  static_cast(FsanitizeArgument.Mask & SanitizerKind::MemtagGlobals);
-  Meta.Memtag &= !NoSanitizeAttrSet.hasOneOf(SanitizerKind::MemTag);
-  Meta.Memtag &= !CGM.isInNoSanitizeList(
-  FsanitizeArgument.Mask & SanitizerKind::MemTag, GV, Loc, Ty);
+  if (shouldTagGlobal(*GV)) {
+Meta.Memtag |=
+static_cast(FsanitizeArgument.Mask & 
SanitizerKind::MemtagGlobals);
+Meta.Memtag &= !NoSanitizeAttrSet.hasOneOf(SanitizerKind::MemTag);
+Meta.Memtag &= !CGM.isInNoSanitizeList(
+FsanitizeArgument.Mask & SanitizerKind::MemTag, GV, Loc, Ty);
+  } else {
+Meta.Memtag = false;
+  }
 
   Meta.IsDynInit = IsDynInit && !Meta.NoAddress &&
FsanitizeArgument.has(SanitizerKind::Address) &&
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp 
b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index 3a8cde7330efc0..6a2817f417d30d 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -764,11 +764,16 @@ void AsmPrinter::emitGlobalVariable(const GlobalVariable 
*GV) {
 
   const DataLayout &DL = GV->getDataLayout();
   uint64_t Size = DL.getTypeAllocSize(GV->getValueType());
+  if (GV->isTagged()) Size = alignTo(Size, 16);
 
   // If the alignment is specified, we *must* obey it.  Overaligning a global
   // with a specified alignment is a prompt way to break globals emitted to
   // sections and expected to be contiguous (e.g. ObjC metadata).

[clang] [llvm] [sanitizer] Document AddressSanitizer security considerations (PR #100937)

2024-10-08 Thread Florian Mayer via cfe-commits

https://github.com/fmayer closed 
https://github.com/llvm/llvm-project/pull/100937
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [sanitizer] Document AddressSanitizer security considerations (PR #100937)

2024-10-08 Thread Florian Mayer via cfe-commits

https://github.com/fmayer approved this pull request.


https://github.com/llvm/llvm-project/pull/100937
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [sanitizer] Document AddressSanitizer security considerations (PR #100937)

2024-10-07 Thread Florian Mayer via cfe-commits

https://github.com/fmayer approved this pull request.


https://github.com/llvm/llvm-project/pull/100937
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][rtsan] Add sanitize_realtime_unsafe attr to [[clang::blocking]] function IR (PR #111055)

2024-10-03 Thread Florian Mayer via cfe-commits

https://github.com/fmayer approved this pull request.


https://github.com/llvm/llvm-project/pull/111055
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][rtsan] Add sanitize_realtime_unsafe attr to [[clang::blocking]] function IR (PR #111055)

2024-10-03 Thread Florian Mayer via cfe-commits

fmayer wrote:

> > > With the function effects warnings (as errors) activated, blocking 
> > > functions cannot be called from non-blocking functions, and this is 
> > > enforced at compile time. The purpose of this series of PRs is to 
> > > introduce similar functionality into RealtimeSanitizer, so that it can 
> > > make the equivalent check at run time.
> > 
> > 
> > What is the reason we need to check something again at runtime that was 
> > already checked at compile-time? In case people didn't `-Werror` the 
> > warning?
> 
> Yes indeed - that's one of a few scenarios where we believe this is needed:
> 
> * the user didn't compile with `-Werror`,
> * the user didn't compile with `-Wfunction-effects` (i.e. no checking at 
> compile time happens),
> * the `[[clang::blocking]]` function is called deep within the call stack of 
> a higher-level `[[clang::nonblocking]]` function, or maybe even
> * the `[[clang::blocking]]` function is pre-compiled in a different library 
> to what the user is compiling.
> 
> RTSan differs from the performance constraints attributes in that it only 
> flags violations that happen at run time, in contrast to flagging those that 
> _could_ happen at compile time. In this scenario, if a `[[clang::blocking]]` 
> call exists somewhere in the code within a `[[clang::nonblocking]]` function, 
> rtsan does not consider it a violation until it's called. Depending on the 
> user's needs they may consider this either good or bad - there are pros and 
> cons to it, of course. RTSan takes an "innocent until proven guilty" 
> approach, whereas performance constraints are more pessimistically "guilty 
> until proven innocent" - and we think both are very useful.
> 
> One of the design goals of the works was that these systems should be able to 
> be used easily together, or separately, and that they should have analogous 
> functionalities where possible. Hope that makes some sense!

Thanks for confirming. Optionally mention this somewhere in a comment in the 
code for future reference.

https://github.com/llvm/llvm-project/pull/111055
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][rtsan] Add sanitize_realtime_unsafe attr to [[clang::blocking]] function IR (PR #111055)

2024-10-03 Thread Florian Mayer via cfe-commits

fmayer wrote:

>  With the function effects warnings (as errors) activated, blocking functions 
> cannot be called from non-blocking functions, and this is enforced at compile 
> time. The purpose of this series of PRs is to introduce similar functionality 
> into RealtimeSanitizer, so that it can make the equivalent check at run time.

What is the reason we need to check something again at runtime that was already 
checked at compile-time? In case people didn't `-Werror` the warning?

https://github.com/llvm/llvm-project/pull/111055
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [sanitizer] Document AddressSanitizer security considerations (PR #100937)

2024-09-30 Thread Florian Mayer via cfe-commits

https://github.com/fmayer approved this pull request.

LGTM % vitaly's comment

https://github.com/llvm/llvm-project/pull/100937
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [rtsan] Update docs to include run-time flags (PR #110296)

2024-09-27 Thread Florian Mayer via cfe-commits

https://github.com/fmayer approved this pull request.


https://github.com/llvm/llvm-project/pull/110296
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [rtsan] Update docs to include run-time flags (PR #110296)

2024-09-27 Thread Florian Mayer via cfe-commits


@@ -84,6 +84,75 @@ non-zero exit code.
 #14 0x0001958960dc  ()
 #15 0x2f557ffc  ()
 
+Run-time flags
+--
+
+RealtimeSanitizer supports a number of run-time flags, which can be specified 
in the ``RTSAN_OPTIONS`` environment variable:
+
+.. code-block:: console
+
+   % RTSAN_OPTIONS=option_1=true:path_option_2="/some/file.txt" ./a.out
+   ...
+
+Or at compile-time by overloading the symbol ``__rtsan_default_options``:

fmayer wrote:

Do users care that this is overriding a weak symbol?

https://github.com/llvm/llvm-project/pull/110296
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [rtsan] Update docs to include run-time flags (PR #110296)

2024-09-27 Thread Florian Mayer via cfe-commits


@@ -84,6 +84,75 @@ non-zero exit code.
 #14 0x0001958960dc  ()
 #15 0x2f557ffc  ()
 
+Run-time flags
+--
+
+RealtimeSanitizer supports a number of run-time flags, which can be specified 
in the ``RTSAN_OPTIONS`` environment variable:
+
+.. code-block:: console
+
+   % RTSAN_OPTIONS=option_1=true:path_option_2="/some/file.txt" ./a.out
+   ...
+
+Or at compile-time by overloading the symbol ``__rtsan_default_options``:

fmayer wrote:

should we just add `__attribute__((__visibility__("default")))` for good 
measure? because i think if someone adds `-fvisibility=hidden` it won't work 
without this?

https://github.com/llvm/llvm-project/pull/110296
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [rtsan] Update docs to include run-time flags (PR #110296)

2024-09-27 Thread Florian Mayer via cfe-commits


@@ -84,6 +84,75 @@ non-zero exit code.
 #14 0x0001958960dc  ()
 #15 0x2f557ffc  ()
 
+Run-time flags
+--
+
+RealtimeSanitizer supports a number of run-time flags, which can be specified 
in the ``RTSAN_OPTIONS`` environment variable:
+
+.. code-block:: console
+
+   % RTSAN_OPTIONS=option_1=true:path_option_2="/some/file.txt" ./a.out
+   ...
+
+Or at compile-time by overloading the symbol ``__rtsan_default_options``:

fmayer wrote:

I don't think "overload" is technically the correct term. "provide"? Should we 
talk about visibility?

https://github.com/llvm/llvm-project/pull/110296
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [rtsan] Update docs to include run-time flags (PR #110296)

2024-09-27 Thread Florian Mayer via cfe-commits


@@ -84,6 +84,75 @@ non-zero exit code.
 #14 0x0001958960dc  ()
 #15 0x2f557ffc  ()
 
+Run-time flags
+--
+
+RealtimeSanitizer supports a number of run-time flags, which can be specified 
in the ``RTSAN_OPTIONS`` environment variable:
+
+.. code-block:: console
+
+   % RTSAN_OPTIONS=option_1=true:path_option_2="/some/file.txt" ./a.out
+   ...
+
+Or at compiler time by overloading the symbol ``__rtsan_default_options``:

fmayer wrote:

compile-time? 

https://github.com/llvm/llvm-project/pull/110296
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-tools-extra] [clang] Extend diagnose_if to accept more detailed warning information (PR #70976)

2024-09-25 Thread Florian Mayer via cfe-commits


@@ -489,13 +485,7 @@ static DiagnosticIDs::Level toLevel(diag::Severity SV) {
 DiagnosticIDs::Level
 DiagnosticIDs::getDiagnosticLevel(unsigned DiagID, SourceLocation Loc,
   const DiagnosticsEngine &Diag) const {
-  // Handle custom diagnostics, which cannot be mapped.

fmayer wrote:

I agree, let's revert if this is causing problems.

https://github.com/llvm/llvm-project/pull/70976
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] modernize-use-nullptr matches "NULL" in templates (PR #109169)

2024-09-25 Thread Florian Mayer via cfe-commits

https://github.com/fmayer closed 
https://github.com/llvm/llvm-project/pull/109169
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] modernize-use-nullptr matches "NULL" in templates (PR #109169)

2024-09-19 Thread Florian Mayer via cfe-commits

https://github.com/fmayer approved this pull request.


https://github.com/llvm/llvm-project/pull/109169
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] modernize-use-nullptr matches "NULL" in templates (PR #109169)

2024-09-19 Thread Florian Mayer via cfe-commits


@@ -84,6 +84,29 @@ void test_macro_expansion4() {
 #undef MY_NULL
 }
 
+template  struct pear {
+  // If you say __null (or NULL), we assume that T will always be a pointer

fmayer wrote:

Thanks, otherwise this comment will only cause confusion.

https://github.com/llvm/llvm-project/pull/109169
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] modernize-use-nullptr matches "NULL" in templates (PR #109169)

2024-09-19 Thread Florian Mayer via cfe-commits


@@ -84,6 +84,29 @@ void test_macro_expansion4() {
 #undef MY_NULL
 }
 
+template  struct pear {
+  // If you say __null (or NULL), we assume that T will always be a pointer

fmayer wrote:

Sorry, the implication of my comment was: explain why in a comment, because 
future readers will not know that.

https://github.com/llvm/llvm-project/pull/109169
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] modernize-use-nullptr matches "NULL" in templates (PR #109169)

2024-09-19 Thread Florian Mayer via cfe-commits


@@ -84,6 +84,29 @@ void test_macro_expansion4() {
 #undef MY_NULL
 }
 
+template  struct pear {
+  // If you say __null (or NULL), we assume that T will always be a pointer

fmayer wrote:

why are we only testing one of those?

https://github.com/llvm/llvm-project/pull/109169
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] modernize-use-nullptr matches "NULL" in templates (PR #109169)

2024-09-19 Thread Florian Mayer via cfe-commits


@@ -84,6 +84,28 @@ void test_macro_expansion4() {
 #undef MY_NULL
 }
 
+template  struct pear {
+  // If you say __null (or NULL), we assume that T will always be a pointer
+  // type, so we suggest replacing it with nullptr.
+  void f() { x = __null; }
+  // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: use nullptr 
[modernize-use-nullptr]
+  // CHECK-FIXES: x = nullptr;
+
+  // But if you say 0, we allow the possibility that T can be used with 
integral
+  // and pointer types, and "0" is an acceptable initializer (even if "{}" 
might
+  // be even better).
+  void g() { y = 0; }

fmayer wrote:

I would drop the FIXES one, because that could conceivably match something from 
a later test.

https://github.com/llvm/llvm-project/pull/109169
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] modernize-use-nullptr matches "NULL" in templates (PR #109169)

2024-09-19 Thread Florian Mayer via cfe-commits


@@ -84,6 +84,28 @@ void test_macro_expansion4() {
 #undef MY_NULL
 }
 
+template  struct pear {
+  // If you say __null (or NULL), we assume that T will always be a pointer
+  // type, so we suggest replacing it with nullptr.
+  void f() { x = __null; }
+  // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: use nullptr 
[modernize-use-nullptr]
+  // CHECK-FIXES: x = nullptr;
+
+  // But if you say 0, we allow the possibility that T can be used with 
integral
+  // and pointer types, and "0" is an acceptable initializer (even if "{}" 
might
+  // be even better).
+  void g() { y = 0; }

fmayer wrote:

I would do `// CHECK-MESSAGES-NOT: :[[@LINE-1]]`

https://github.com/llvm/llvm-project/pull/109169
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] modernize-use-nullptr matches "NULL" in templates (PR #109169)

2024-09-19 Thread Florian Mayer via cfe-commits


@@ -84,6 +84,28 @@ void test_macro_expansion4() {
 #undef MY_NULL
 }
 
+template  struct pear {
+  // If you say __null (or NULL), we assume that T will always be a pointer
+  // type, so we suggest replacing it with nullptr.
+  void f() { x = __null; }
+  // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: use nullptr 
[modernize-use-nullptr]
+  // CHECK-FIXES: x = nullptr;
+
+  // But if you say 0, we allow the possibility that T can be used with 
integral
+  // and pointer types, and "0" is an acceptable initializer (even if "{}" 
might
+  // be even better).
+  void g() { y = 0; }

fmayer wrote:

add the line? otherwise it might match something later by accident

https://github.com/llvm/llvm-project/pull/109169
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] modernize-use-nullptr matches "NULL" in templates (PR #109169)

2024-09-19 Thread Florian Mayer via cfe-commits


@@ -84,6 +84,28 @@ void test_macro_expansion4() {
 #undef MY_NULL
 }
 
+template  struct pear {
+  // If you say __null (or NULL), we assume that T will always be a pointer
+  // type, so we suggest replacing it with nullptr.
+  void f() { x = __null; }
+  // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: use nullptr 
[modernize-use-nullptr]
+  // CHECK-FIXES: x = nullptr;
+
+  // But if you say 0, we allow the possibility that T can be used with 
integral
+  // and pointer types, and "0" is an acceptable initializer (even if "{}" 
might
+  // be even better).
+  void g() { y = 0; }

fmayer wrote:

`CHECK-MESSAGES-NOT`?

https://github.com/llvm/llvm-project/pull/109169
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] modernize-use-nullptr matches "NULL" in templates (PR #109169)

2024-09-18 Thread Florian Mayer via cfe-commits


@@ -84,6 +84,14 @@ void test_macro_expansion4() {
 #undef MY_NULL
 }
 
+template  struct pear {
+  T x;
+};
+void test_templated() {
+  pear p = { NULL };

fmayer wrote:

Doesn't this need some `CHECK` or `CHECK-NOT`?

https://github.com/llvm/llvm-project/pull/109169
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Revert "[clang] Silence GCC warnings about control reaching end of non void function" (PR #108646)

2024-09-13 Thread Florian Mayer via cfe-commits

https://github.com/fmayer closed 
https://github.com/llvm/llvm-project/pull/108646
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] e1bd974 - Revert "Reapply "[clang] Extend diagnose_if to accept more detailed warning information (#70976)" (#108453)"

2024-09-13 Thread Florian Mayer via cfe-commits

Author: Florian Mayer
Date: 2024-09-13T15:01:33-07:00
New Revision: e1bd9740faa62c11cc785a7b70ec1ad17e286bd1

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

LOG: Revert "Reapply "[clang] Extend diagnose_if to accept more detailed 
warning information (#70976)" (#108453)"

This reverts commit e7f782e7481cea23ef452a75607d3d61f5bd0d22.

This had UBSan failures:

[--] 1 test from ConfigCompileTests
[ RUN  ] ConfigCompileTests.DiagnosticSuppression
Config fragment: compiling :0 -> 0x7B8366E2F7D8 (trusted=false)
/usr/local/google/home/fmayer/large/llvm-project/llvm/include/llvm/ADT/IntrusiveRefCntPtr.h:203:33:
 runtime error: reference binding to null pointer of type 'clang::DiagnosticIDs'

UndefinedBehaviorSanitizer: undefined-behavior 
/usr/local/google/home/fmayer/large/llvm-project/llvm/include/llvm/ADT/IntrusiveRefCntPtr.h:203:33

Pull Request: https://github.com/llvm/llvm-project/pull/108645

Added: 


Modified: 
clang-tools-extra/clangd/Diagnostics.cpp
clang-tools-extra/clangd/Diagnostics.h
clang-tools-extra/clangd/ParsedAST.cpp
clang-tools-extra/clangd/Preamble.cpp
clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp
clang/include/clang/Basic/Attr.td
clang/include/clang/Basic/Diagnostic.h
clang/include/clang/Basic/DiagnosticCategories.h
clang/include/clang/Basic/DiagnosticIDs.h
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Basic/Diagnostic.cpp
clang/lib/Basic/DiagnosticIDs.cpp
clang/lib/Frontend/LogDiagnosticPrinter.cpp
clang/lib/Frontend/SerializedDiagnosticPrinter.cpp
clang/lib/Frontend/TextDiagnosticPrinter.cpp
clang/lib/Sema/Sema.cpp
clang/lib/Sema/SemaCUDA.cpp
clang/lib/Sema/SemaDeclAttr.cpp
clang/lib/Sema/SemaOverload.cpp
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
clang/lib/Serialization/ASTReader.cpp
clang/lib/Serialization/ASTWriter.cpp
clang/lib/StaticAnalyzer/Core/TextDiagnostics.cpp
clang/test/Sema/diagnose_if.c
clang/tools/diagtool/ListWarnings.cpp
clang/tools/diagtool/ShowEnabledWarnings.cpp
clang/tools/libclang/CXStoredDiagnostic.cpp
flang/lib/Frontend/TextDiagnosticPrinter.cpp

Removed: 
clang/test/SemaCXX/diagnose_if-warning-group.cpp



diff  --git a/clang-tools-extra/clangd/Diagnostics.cpp 
b/clang-tools-extra/clangd/Diagnostics.cpp
index 552dd36b6900bf..d5eca083eb6512 100644
--- a/clang-tools-extra/clangd/Diagnostics.cpp
+++ b/clang-tools-extra/clangd/Diagnostics.cpp
@@ -579,17 +579,7 @@ std::vector StoreDiags::take(const 
clang::tidy::ClangTidyContext *Tidy) {
   for (auto &Diag : Output) {
 if (const char *ClangDiag = getDiagnosticCode(Diag.ID)) {
   // Warnings controlled by -Wfoo are better recognized by that name.
-  const StringRef Warning = [&] {
-if (OrigSrcMgr) {
-  return OrigSrcMgr->getDiagnostics()
-  .getDiagnosticIDs()
-  ->getWarningOptionForDiag(Diag.ID);
-}
-if (!DiagnosticIDs::IsCustomDiag(Diag.ID))
-  return DiagnosticIDs{}.getWarningOptionForDiag(Diag.ID);
-return StringRef{};
-  }();
-
+  StringRef Warning = DiagnosticIDs::getWarningOptionForDiag(Diag.ID);
   if (!Warning.empty()) {
 Diag.Name = ("-W" + Warning).str();
   } else {
@@ -906,23 +896,20 @@ void StoreDiags::flushLastDiag() {
   Output.push_back(std::move(*LastDiag));
 }
 
-bool isDiagnosticSuppressed(const clang::Diagnostic &Diag,
-const llvm::StringSet<> &Suppress,
-const LangOptions &LangOpts) {
+bool isBuiltinDiagnosticSuppressed(unsigned ID,
+   const llvm::StringSet<> &Suppress,
+   const LangOptions &LangOpts) {
   // Don't complain about header-only stuff in mainfiles if it's a header.
   // FIXME: would be cleaner to suppress in clang, once we decide whether the
   //behavior should be to silently-ignore or respect the pragma.
-  if (Diag.getID() == diag::pp_pragma_sysheader_in_main_file &&
-  LangOpts.IsHeaderFile)
+  if (ID == diag::pp_pragma_sysheader_in_main_file && LangOpts.IsHeaderFile)
 return true;
 
-  if (const char *CodePtr = getDiagnosticCode(Diag.getID())) {
+  if (const char *CodePtr = getDiagnosticCode(ID)) {
 if (Suppress.contains(normalizeSuppressedCode(CodePtr)))
   return true;
   }
-  StringRef Warning =
-  Diag.getDiags()->getDiagnosticIDs()->getWarningOptionForDiag(
-  Diag.getID());
+  StringRef Warning = DiagnosticIDs::getWarningOptionForDiag(ID);
   if (!Warning.empty() && Suppress.contains(Warning))
 return true;
   return false;

diff  --git a/clang-tools-extra/clangd/Diagnostics.h 
b/clang-tools-extra/clangd/Diagnostics.h
index c45

[clang] e1bd974 - Revert "Reapply "[clang] Extend diagnose_if to accept more detailed warning information (#70976)" (#108453)"

2024-09-13 Thread Florian Mayer via cfe-commits

Author: Florian Mayer
Date: 2024-09-13T15:01:33-07:00
New Revision: e1bd9740faa62c11cc785a7b70ec1ad17e286bd1

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

LOG: Revert "Reapply "[clang] Extend diagnose_if to accept more detailed 
warning information (#70976)" (#108453)"

This reverts commit e7f782e7481cea23ef452a75607d3d61f5bd0d22.

This had UBSan failures:

[--] 1 test from ConfigCompileTests
[ RUN  ] ConfigCompileTests.DiagnosticSuppression
Config fragment: compiling :0 -> 0x7B8366E2F7D8 (trusted=false)
/usr/local/google/home/fmayer/large/llvm-project/llvm/include/llvm/ADT/IntrusiveRefCntPtr.h:203:33:
 runtime error: reference binding to null pointer of type 'clang::DiagnosticIDs'

UndefinedBehaviorSanitizer: undefined-behavior 
/usr/local/google/home/fmayer/large/llvm-project/llvm/include/llvm/ADT/IntrusiveRefCntPtr.h:203:33

Pull Request: https://github.com/llvm/llvm-project/pull/108645

Added: 


Modified: 
clang-tools-extra/clangd/Diagnostics.cpp
clang-tools-extra/clangd/Diagnostics.h
clang-tools-extra/clangd/ParsedAST.cpp
clang-tools-extra/clangd/Preamble.cpp
clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp
clang/include/clang/Basic/Attr.td
clang/include/clang/Basic/Diagnostic.h
clang/include/clang/Basic/DiagnosticCategories.h
clang/include/clang/Basic/DiagnosticIDs.h
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Basic/Diagnostic.cpp
clang/lib/Basic/DiagnosticIDs.cpp
clang/lib/Frontend/LogDiagnosticPrinter.cpp
clang/lib/Frontend/SerializedDiagnosticPrinter.cpp
clang/lib/Frontend/TextDiagnosticPrinter.cpp
clang/lib/Sema/Sema.cpp
clang/lib/Sema/SemaCUDA.cpp
clang/lib/Sema/SemaDeclAttr.cpp
clang/lib/Sema/SemaOverload.cpp
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
clang/lib/Serialization/ASTReader.cpp
clang/lib/Serialization/ASTWriter.cpp
clang/lib/StaticAnalyzer/Core/TextDiagnostics.cpp
clang/test/Sema/diagnose_if.c
clang/tools/diagtool/ListWarnings.cpp
clang/tools/diagtool/ShowEnabledWarnings.cpp
clang/tools/libclang/CXStoredDiagnostic.cpp
flang/lib/Frontend/TextDiagnosticPrinter.cpp

Removed: 
clang/test/SemaCXX/diagnose_if-warning-group.cpp



diff  --git a/clang-tools-extra/clangd/Diagnostics.cpp 
b/clang-tools-extra/clangd/Diagnostics.cpp
index 552dd36b6900bf..d5eca083eb6512 100644
--- a/clang-tools-extra/clangd/Diagnostics.cpp
+++ b/clang-tools-extra/clangd/Diagnostics.cpp
@@ -579,17 +579,7 @@ std::vector StoreDiags::take(const 
clang::tidy::ClangTidyContext *Tidy) {
   for (auto &Diag : Output) {
 if (const char *ClangDiag = getDiagnosticCode(Diag.ID)) {
   // Warnings controlled by -Wfoo are better recognized by that name.
-  const StringRef Warning = [&] {
-if (OrigSrcMgr) {
-  return OrigSrcMgr->getDiagnostics()
-  .getDiagnosticIDs()
-  ->getWarningOptionForDiag(Diag.ID);
-}
-if (!DiagnosticIDs::IsCustomDiag(Diag.ID))
-  return DiagnosticIDs{}.getWarningOptionForDiag(Diag.ID);
-return StringRef{};
-  }();
-
+  StringRef Warning = DiagnosticIDs::getWarningOptionForDiag(Diag.ID);
   if (!Warning.empty()) {
 Diag.Name = ("-W" + Warning).str();
   } else {
@@ -906,23 +896,20 @@ void StoreDiags::flushLastDiag() {
   Output.push_back(std::move(*LastDiag));
 }
 
-bool isDiagnosticSuppressed(const clang::Diagnostic &Diag,
-const llvm::StringSet<> &Suppress,
-const LangOptions &LangOpts) {
+bool isBuiltinDiagnosticSuppressed(unsigned ID,
+   const llvm::StringSet<> &Suppress,
+   const LangOptions &LangOpts) {
   // Don't complain about header-only stuff in mainfiles if it's a header.
   // FIXME: would be cleaner to suppress in clang, once we decide whether the
   //behavior should be to silently-ignore or respect the pragma.
-  if (Diag.getID() == diag::pp_pragma_sysheader_in_main_file &&
-  LangOpts.IsHeaderFile)
+  if (ID == diag::pp_pragma_sysheader_in_main_file && LangOpts.IsHeaderFile)
 return true;
 
-  if (const char *CodePtr = getDiagnosticCode(Diag.getID())) {
+  if (const char *CodePtr = getDiagnosticCode(ID)) {
 if (Suppress.contains(normalizeSuppressedCode(CodePtr)))
   return true;
   }
-  StringRef Warning =
-  Diag.getDiags()->getDiagnosticIDs()->getWarningOptionForDiag(
-  Diag.getID());
+  StringRef Warning = DiagnosticIDs::getWarningOptionForDiag(ID);
   if (!Warning.empty() && Suppress.contains(Warning))
 return true;
   return false;

diff  --git a/clang-tools-extra/clangd/Diagnostics.h 
b/clang-tools-extra/clangd/Diagnostics.h
index c45

[clang] f885e02 - Revert "[clang] Silence GCC warnings about control reaching end of non void function"

2024-09-13 Thread Florian Mayer via cfe-commits

Author: Florian Mayer
Date: 2024-09-13T15:01:27-07:00
New Revision: f885e02cf7cac1b08cab4cd526773420076029dd

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

LOG: Revert "[clang] Silence GCC warnings about control reaching end of non 
void function"

This reverts commit 90a2e0bb423629b7e70f4b91adb44851199dd5ea.

Reverting parent CL

Pull Request: https://github.com/llvm/llvm-project/pull/108646

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticIDs.h
clang/lib/Sema/SemaOverload.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticIDs.h 
b/clang/include/clang/Basic/DiagnosticIDs.h
index daad66f499538f..2402996ece5c94 100644
--- a/clang/include/clang/Basic/DiagnosticIDs.h
+++ b/clang/include/clang/Basic/DiagnosticIDs.h
@@ -18,7 +18,6 @@
 #include "clang/Basic/LLVM.h"
 #include "llvm/ADT/IntrusiveRefCntPtr.h"
 #include "llvm/ADT/StringRef.h"
-#include "llvm/Support/ErrorHandling.h"
 #include 
 #include 
 
@@ -311,7 +310,6 @@ class DiagnosticIDs : public RefCountedBase {
 return {diag::Severity::Fatal, std::string(Message), CLASS_ERROR,
 /*ShowInSystemHeader*/ true};
   }
-  llvm_unreachable("Fully covered switch above!");
 }());
   }
 

diff  --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 382630ed674107..d3e009a658f0e8 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -7331,7 +7331,6 @@ static bool diagnoseDiagnoseIfAttrsWith(Sema &S, const 
NamedDecl *ND,
 case DiagnoseIfAttr::DS_error:
   return diag::Severity::Error;
 }
-llvm_unreachable("Fully covered switch above!");
   };
 
   for (const auto *DIA : llvm::make_range(WarningBegin, Attrs.end()))



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


[clang] Revert "[clang] Silence GCC warnings about control reaching end of non void function" (PR #108646)

2024-09-13 Thread Florian Mayer via cfe-commits

https://github.com/fmayer created 
https://github.com/llvm/llvm-project/pull/108646

This reverts commit 90a2e0bb423629b7e70f4b91adb44851199dd5ea.

Reverting parent CL


>From 6bc1ea84e078d01546286e6443d761e2a685902d Mon Sep 17 00:00:00 2001
From: Florian Mayer 
Date: Fri, 13 Sep 2024 14:02:14 -0700
Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?=
 =?UTF-8?q?l=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.4
---
 clang/include/clang/Basic/DiagnosticIDs.h | 2 --
 clang/lib/Sema/SemaOverload.cpp   | 1 -
 2 files changed, 3 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticIDs.h 
b/clang/include/clang/Basic/DiagnosticIDs.h
index daad66f499538f..2402996ece5c94 100644
--- a/clang/include/clang/Basic/DiagnosticIDs.h
+++ b/clang/include/clang/Basic/DiagnosticIDs.h
@@ -18,7 +18,6 @@
 #include "clang/Basic/LLVM.h"
 #include "llvm/ADT/IntrusiveRefCntPtr.h"
 #include "llvm/ADT/StringRef.h"
-#include "llvm/Support/ErrorHandling.h"
 #include 
 #include 
 
@@ -311,7 +310,6 @@ class DiagnosticIDs : public RefCountedBase {
 return {diag::Severity::Fatal, std::string(Message), CLASS_ERROR,
 /*ShowInSystemHeader*/ true};
   }
-  llvm_unreachable("Fully covered switch above!");
 }());
   }
 
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 382630ed674107..d3e009a658f0e8 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -7331,7 +7331,6 @@ static bool diagnoseDiagnoseIfAttrsWith(Sema &S, const 
NamedDecl *ND,
 case DiagnoseIfAttr::DS_error:
   return diag::Severity::Error;
 }
-llvm_unreachable("Fully covered switch above!");
   };
 
   for (const auto *DIA : llvm::make_range(WarningBegin, Attrs.end()))

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


[clang] [clang-tools-extra] [flang] Reapply "[clang] Extend diagnose_if to accept more detailed warning information (#70976)" (PR #108453)

2024-09-13 Thread Florian Mayer via cfe-commits

fmayer wrote:

This caused a UBSan violation: 
```
[--] 1 test from ConfigCompileTests
[ RUN  ] ConfigCompileTests.DiagnosticSuppression
Config fragment: compiling :0 -> 0x7B8366E2F7D8 (trusted=false)
/usr/local/google/home/fmayer/large/llvm-project/llvm/include/llvm/ADT/IntrusiveRefCntPtr.h:203:33:
 runtime error: reference binding to null pointer of type 'clang::DiagnosticIDs'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior 
/usr/local/google/home/fmayer/large/llvm-project/llvm/include/llvm/ADT/IntrusiveRefCntPtr.h:203:33
 

--
exit: 1
--
```

https://github.com/llvm/llvm-project/pull/108453
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [compiler-rt] [UBSan] Diagnose assumption violation (PR #104741)

2024-09-09 Thread Florian Mayer via cfe-commits

fmayer wrote:

LGTM, but would like @vitalybuka to also take a quick look.

https://github.com/llvm/llvm-project/pull/104741
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Delay sanitizer args parsing. (PR #107280)

2024-09-04 Thread Florian Mayer via cfe-commits

fmayer wrote:

super-nit: add `[sanitizers]` and remove `.` from commit message?

https://github.com/llvm/llvm-project/pull/107280
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Delay sanitizer args parsing. (PR #107280)

2024-09-04 Thread Florian Mayer via cfe-commits

https://github.com/fmayer approved this pull request.


https://github.com/llvm/llvm-project/pull/107280
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] Revert "Reapply "[HWASan] remove incorrectly inferred attributes" (#106622)" (PR #106758)

2024-08-30 Thread Florian Mayer via cfe-commits

https://github.com/fmayer closed 
https://github.com/llvm/llvm-project/pull/106758
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] Reapply "[HWASan] remove incorrectly inferred attributes" (#106622) (PR #106624)

2024-08-29 Thread Florian Mayer via cfe-commits

https://github.com/fmayer closed 
https://github.com/llvm/llvm-project/pull/106624
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [compiler-rt] [clang][compiler-rt][test] Removed dirname command substitutions from tests (PR #105754)

2024-08-23 Thread Florian Mayer via cfe-commits

https://github.com/fmayer approved this pull request.

LGTM for the hwasan test.

https://github.com/llvm/llvm-project/pull/105754
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [compiler-rt] [clang][compiler-rt][test] Removed dirname command substitutions from tests (PR #105754)

2024-08-23 Thread Florian Mayer via cfe-commits


@@ -1,8 +1,9 @@
-// RUN: %clang_hwasan -Wl,--build-id -g %s -o %t
-// RUN: echo '[{"prefix": "'"$(realpath $(dirname %s))"'/", "link": 
"http://test.invalid/{file}:{line}"}]' > %t.linkify
-// RUN: %env_hwasan_opts=symbolize=0 not %run %t 2>&1 | hwasan_symbolize 
--html --symbols $(dirname %t) --index | FileCheck %s
-// RUN: %env_hwasan_opts=symbolize=0 not %run %t 2>&1 | hwasan_symbolize 
--html --linkify %t.linkify --symbols $(dirname %t) --index | FileCheck 
--check-prefixes=CHECK,LINKIFY %s
-// RUN: %env_hwasan_opts=symbolize=0 not %run %t 2>&1 | hwasan_symbolize 
--symbols $(dirname %t) --index | FileCheck %s
+// RUN: rm -rf %t && mkdir -p %t
+// RUN: %clang_hwasan -Wl,--build-id -g %s -o %t/symbolize.exe

fmayer wrote:

`symbolize.exe` is a bit of a confusing name. `hwasan_symbolize_test`?

https://github.com/llvm/llvm-project/pull/105754
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [sanitizer] Document AddressSanitizer security considerations (PR #100937)

2024-08-13 Thread Florian Mayer via cfe-commits


@@ -313,6 +313,14 @@ Limitations
   usually expected.
 * Static linking of executables is not supported.
 
+Security Considerations
+===
+
+AddressSanitizer is a bug detection tool and is not meant to be linked

fmayer wrote:

nit: maybe "its runtime is not meant to be linked?"

https://github.com/llvm/llvm-project/pull/100937
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [sanitizer] Document AddressSanitizer security considerations (PR #100937)

2024-08-12 Thread Florian Mayer via cfe-commits

fmayer wrote:

> ⚠️ We detected that you are using a GitHub private e-mail address to 
> contribute to the repo. Please turn off [Keep my email addresses 
> private](https://github.com/settings/emails) setting in your account. See 
> [LLVM 
> Discourse](https://discourse.llvm.org/t/hidden-emails-on-github-should-we-do-something-about-it)
>  for more information.

@bigb4ng please do this. Thank you

https://github.com/llvm/llvm-project/pull/100937
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [sanitizer] Document AddressSanitizer security considerations (PR #100937)

2024-08-07 Thread Florian Mayer via cfe-commits

https://github.com/fmayer approved this pull request.


https://github.com/llvm/llvm-project/pull/100937
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [compiler-rt] [ubsan] Display correct runtime messages for negative _BitInt (PR #93612)

2024-06-20 Thread Florian Mayer via cfe-commits

fmayer wrote:

Breakage looks related: https://lab.llvm.org/buildbot/#/builders/72/builds/265

```
FAIL: UBSan-MemorySanitizer-powerpc64le :: TestCases/Integer/bit-int.c (4716 of 
4745)
 TEST 'UBSan-MemorySanitizer-powerpc64le :: 
TestCases/Integer/bit-int.c' FAILED 
Exit Code: 1

Command Output (stderr):
--
RUN: at line 1: 
/home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/build_gcc/./bin/clang
  -fsanitize=memory  -m64 -fno-function-sections  -Wno-constant-conversion 
-Wno-array-bounds -Wno-division-by-zero -Wno-shift-negative-value 
-Wno-shift-count-negative -Wno-int-to-pointer-cast -O0 
-fsanitize=alignment,array-bounds,bool,float-cast-overflow,implicit-integer-sign-change,implicit-signed-integer-truncation,implicit-unsigned-integer-truncation,integer-divide-by-zero,nonnull-attribute,null,nullability-arg,nullability-assign,nullability-return,pointer-overflow,returns-nonnull-attribute,shift-base,shift-exponent,signed-integer-overflow,unreachable,unsigned-integer-overflow,unsigned-shift-base,vla-bound
 
/home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm-project/compiler-rt/test/ubsan/TestCases/Integer/bit-int.c
 -o 
/home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/build_g
 
cc/runtimes/runtimes-bins/compiler-rt/test/ubsan/MemorySanitizer-powerpc64le/TestCases/Integer/Output/bit-int.c.tmp1
 &&  
/home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/build_gcc/runtimes/runtimes-bins/compiler-rt/test/ubsan/MemorySanitizer-powerpc64le/TestCases/Integer/Output/bit-int.c.tmp1
 2>&1 | FileCheck 
/home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm-project/compiler-rt/test/ubsan/TestCases/Integer/bit-int.c
 --check-prefix=RUNTIME
+ 
/home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/build_gcc/./bin/clang
 -fsanitize=memory -m64 -fno-function-sections -Wno-constant-conversion 
-Wno-array-bounds -Wno-division-by-zero -Wno-shift-negative-value 
-Wno-shift-count-negative -Wno-int-to-pointer-cast -O0 
-fsanitize=alignment,array-bounds,bool,float-cast-overflow,implicit-integer-sign-change,implicit-signed-integer-truncation,implicit-unsigned-integer-truncation,integer-divide-by-zero,nonnull-attribute,null,nullability-arg,nullability-assign,nullability-return,pointer-overflow,returns-nonnull-attribute,shift-base,shift-exponent,signed-integer-overflow,unreachable,unsigned-integer-overflow,unsigned-shift-base,vla-bound
 
/home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm-project/compiler-rt/test/ubsan/TestCases/Integer/bit-int.c
 -o 
/home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/build_gcc/runtimes/runti
 
mes-bins/compiler-rt/test/ubsan/MemorySanitizer-powerpc64le/TestCases/Integer/Output/bit-int.c.tmp1
+ 
/home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/build_gcc/runtimes/runtimes-bins/compiler-rt/test/ubsan/MemorySanitizer-powerpc64le/TestCases/Integer/Output/bit-int.c.tmp1
+ FileCheck 
/home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm-project/compiler-rt/test/ubsan/TestCases/Integer/bit-int.c
 --check-prefix=RUNTIME
/home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm-project/compiler-rt/test/ubsan/TestCases/Integer/bit-int.c:93:14:
 error: RUNTIME: expected string not found in input
 // RUNTIME: {{.*}}bit-int.c:[[@LINE-1]]:24: runtime error: left shift of 
negative value -1
 ^
:25:206: note: scanning from here
/home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm-project/compiler-rt/test/ubsan/TestCases/Integer/bit-int.c:86:21:
 runtime error: shift exponent -1 is negative


 ^
:25:206: note: with "@LINE-1" equal to "92"
/home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm-project/compiler-rt/test/ubsan/TestCases/Integer/bit-int.c:86:21:
 runtime error: shift exponent -1 is negative


 ^
:33:252: note: possible intended match here
SUMMARY: MemorySanitizer: use-of-uninitialized-value 
(/home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/build_gcc/runtimes/runtimes-bins/compiler-rt/test/ubsan/MemorySanitizer-powerpc64le/TestCases/Integer/Output/bit-int.c.tmp1+0xe6d64)
 in shift_exponent
  

[clang] Revert "Bump the DWARF version number to 5 on Darwin." (PR #95325)

2024-06-12 Thread Florian Mayer via cfe-commits

https://github.com/fmayer closed https://github.com/llvm/llvm-project/pull/95325
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Revert "Bump the DWARF version number to 5 on Darwin." (PR #95325)

2024-06-12 Thread Florian Mayer via cfe-commits

https://github.com/fmayer created 
https://github.com/llvm/llvm-project/pull/95325

Reverts llvm/llvm-project#95164

This broke a buildbot: https://lab.llvm.org/buildbot/#/builders/37/builds/35987

>From fc671bbb1ceb94f8aac63bc0e4963e5894bc660e Mon Sep 17 00:00:00 2001
From: Florian Mayer 
Date: Wed, 12 Jun 2024 15:50:03 -0700
Subject: [PATCH] Revert "Bump the DWARF version number to 5 on Darwin.
 (#95164)"

This reverts commit 8f6acd973a38da6dce45faa676cbb51da37f72e5.
---
 clang/lib/Driver/ToolChains/Darwin.cpp | 12 +---
 clang/test/Driver/debug-options.c  | 27 +-
 2 files changed, 2 insertions(+), 37 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Darwin.cpp 
b/clang/lib/Driver/ToolChains/Darwin.cpp
index ca75a622b061e..ed5737915aa96 100644
--- a/clang/lib/Driver/ToolChains/Darwin.cpp
+++ b/clang/lib/Driver/ToolChains/Darwin.cpp
@@ -1257,17 +1257,7 @@ unsigned DarwinClang::GetDefaultDwarfVersion() const {
   if ((isTargetMacOSBased() && isMacosxVersionLT(10, 11)) ||
   (isTargetIOSBased() && isIPhoneOSVersionLT(9)))
 return 2;
-  // Default to use DWARF 4 on OS X 10.11 - macOS 14 / iOS 9 - iOS 17.
-  if ((isTargetMacOSBased() && isMacosxVersionLT(15)) ||
-  (isTargetIOSBased() && isIPhoneOSVersionLT(18)) ||
-  (isTargetWatchOSBased() && TargetVersion < llvm::VersionTuple(11)) ||
-  (isTargetXROS() && TargetVersion < llvm::VersionTuple(2)) ||
-  (isTargetDriverKit() && TargetVersion < llvm::VersionTuple(24)) ||
-  (isTargetMacOSBased() &&
-   TargetVersion.empty()) || // apple-darwin, no version.
-  (TargetPlatform == llvm::Triple::BridgeOS))
-return 4;
-  return 5;
+  return 4;
 }
 
 void MachO::AddLinkRuntimeLib(const ArgList &Args, ArgStringList &CmdArgs,
diff --git a/clang/test/Driver/debug-options.c 
b/clang/test/Driver/debug-options.c
index 0a665f7017d63..07f6ca9e3902f 100644
--- a/clang/test/Driver/debug-options.c
+++ b/clang/test/Driver/debug-options.c
@@ -68,32 +68,7 @@
 // RUN: %clang -### -c -g %s -target x86_64-apple-driverkit19.0 2>&1 \
 // RUN: | FileCheck -check-prefix=G_STANDALONE \
 // RUN: -check-prefix=G_DWARF4 %s
-// RUN: %clang -### -c -g %s -target x86_64-apple-macosx15 2>&1 \
-// RUN: | FileCheck -check-prefix=G_STANDALONE \
-// RUN: -check-prefix=G_DWARF5 %s
-// RUN: %clang -### -c -g %s -target arm64-apple-ios17.0 2>&1 \
-// RUN: | FileCheck -check-prefix=G_STANDALONE \
-// RUN: -check-prefix=G_DWARF4 %s
-// RUN: %clang -### -c -g %s -target arm64-apple-ios18.0 2>&1 \
-// RUN: | FileCheck -check-prefix=G_STANDALONE \
-// RUN: -check-prefix=G_DWARF5 %s
-// RUN: %clang -### -c -g %s -target arm64_32-apple-watchos11 2>&1 \
-// RUN: | FileCheck -check-prefix=G_STANDALONE \
-// RUN: -check-prefix=G_DWARF5 %s
-// RUN: %clang -### -c -g %s -target arm64-apple-tvos18.0 2>&1 \
-// RUN: | FileCheck -check-prefix=G_STANDALONE \
-// RUN: -check-prefix=G_DWARF5 %s
-// RUN: %clang -### -c -g %s -target x86_64-apple-driverkit24.0 2>&1 \
-// RUN: | FileCheck -check-prefix=G_STANDALONE \
-// RUN: -check-prefix=G_DWARF5 %s
-// RUN: %clang -### -c -g %s -target arm64-apple-xros1 2>&1 \
-// RUN: | FileCheck -check-prefix=G_STANDALONE \
-// RUN: -check-prefix=G_DWARF4 %s
-// RUN: %clang -### -c -g %s -target arm64-apple-xros2 2>&1 \
-// RUN: | FileCheck -check-prefix=G_STANDALONE \
-// RUN: -check-prefix=G_DWARF5 %s
-//
-// RUN: %clang -### -c -fsave-optimization-record %s\
+// RUN: %clang -### -c -fsave-optimization-record %s \
 // RUN:-target x86_64-apple-darwin 2>&1 \
 // RUN: | FileCheck -check-prefix=GLTO_ONLY %s
 // RUN: %clang -### -c -g -fsave-optimization-record %s \

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


[clang] Bump the DWARF version number to 5 on Darwin. (PR #95164)

2024-06-12 Thread Florian Mayer via cfe-commits

fmayer wrote:

This broke our buildbot: 
https://lab.llvm.org/buildbot/#/builders/37/builds/35987

```
FAILED: 
tools/clang/lib/Driver/CMakeFiles/obj.clangDriver.dir/ToolChains/Darwin.cpp.o 
CCACHE_CPP2=yes CCACHE_HASHDIR=yes /usr/bin/ccache 
/b/sanitizer-x86_64-linux/build/llvm_build0/bin/clang++ -DGTEST_HAS_RTTI=0 
-D_DEBUG -D_GLIBCXX_ASSERTIONS -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS 
-D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS 
-I/b/sanitizer-x86_64-linux/build/build_symbolizer/tools/clang/lib/Driver 
-I/b/sanitizer-x86_64-linux/build/llvm-project/clang/lib/Driver 
-I/b/sanitizer-x86_64-linux/build/llvm-project/clang/include 
-I/b/sanitizer-x86_64-linux/build/build_symbolizer/tools/clang/include 
-I/b/sanitizer-x86_64-linux/build/build_symbolizer/include 
-I/b/sanitizer-x86_64-linux/build/llvm-project/llvm/include -fPIC 
-fno-semantic-interposition -fvisibility-inlines-hidden -Werror 
-Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra 
-Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers 
-pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough 
-Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor 
-Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion 
-Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color 
-ffunction-sections -fdata-sections -fno-common -Woverloaded-virtual 
-Wno-nested-anon-types -O3 -DNDEBUG -std=c++17  -fno-exceptions -funwind-tables 
-fno-rtti -UNDEBUG -MD -MT 
tools/clang/lib/Driver/CMakeFiles/obj.clangDriver.dir/ToolChains/Darwin.cpp.o 
-MF 
tools/clang/lib/Driver/CMakeFiles/obj.clangDriver.dir/ToolChains/Darwin.cpp.o.d 
-o 
tools/clang/lib/Driver/CMakeFiles/obj.clangDriver.dir/ToolChains/Darwin.cpp.o 
-c 
/b/sanitizer-x86_64-linux/build/llvm-project/clang/lib/Driver/ToolChains/Darwin.cpp
/b/sanitizer-x86_64-linux/build/llvm-project/clang/lib/Driver/ToolChains/Darwin.cpp:1268:23:
 error: comparison of different enumeration types ('DarwinPlatformKind' and 
'llvm::Triple::OSType') [-Werror,-Wenum-compare]
 1268 |   (TargetPlatform == llvm::Triple::BridgeOS))
  |~~ ^  ~~
/b/sanitizer-x86_64-linux/build/llvm-project/clang/lib/Driver/ToolChains/Darwin.cpp:1268:23:
 error: result of comparison of constant 'BridgeOS' (28) with expression of 
type 'DarwinPlatformKind' is always false 
[-Werror,-Wtautological-constant-out-of-range-compare]
 1268 |   (TargetPlatform == llvm::Triple::BridgeOS))
  |~~ ^  ~~
2 errors generated.
ninja: build stopped: subcommand failed.

```

https://github.com/llvm/llvm-project/pull/95164
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-tools-extra] Revert "✨ [Sema, Lex, Parse] Preprocessor embed in C and C++ (and Obj-C and Obj-C++ by-proxy)" (PR #95299)

2024-06-12 Thread Florian Mayer via cfe-commits

https://github.com/fmayer approved this pull request.


https://github.com/llvm/llvm-project/pull/95299
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-tools-extra] [libcxx] Revert "[clang] Enable sized deallocation by default in C++14 onwards (#83774)" (PR #90299)

2024-04-26 Thread Florian Mayer via cfe-commits

https://github.com/fmayer approved this pull request.


https://github.com/llvm/llvm-project/pull/90299
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-tools-extra] Revert "[clang analysis] ExprMutationAnalyzer avoid infinite recursion for recursive forwarding reference" (PR #88765)

2024-04-15 Thread Florian Mayer via cfe-commits

https://github.com/fmayer closed https://github.com/llvm/llvm-project/pull/88765
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-tools-extra] Revert "[clang analysis] ExprMutationAnalyzer avoid infinite recursion for recursive forwarding reference" (PR #88765)

2024-04-15 Thread Florian Mayer via cfe-commits

https://github.com/fmayer created 
https://github.com/llvm/llvm-project/pull/88765

Reverts llvm/llvm-project#87954

Broke sanitizer bots, e.g. 
https://lab.llvm.org/buildbot/#/builders/239/builds/6587/steps/10/logs/stdio

>From 82b9a06f73df5301ffd950775055304124f63e02 Mon Sep 17 00:00:00 2001
From: Florian Mayer 
Date: Mon, 15 Apr 2024 10:46:21 -0700
Subject: [PATCH] =?UTF-8?q?Revert=20"[clang=20analysis]=20ExprMutationAnal?=
 =?UTF-8?q?yzer=20avoid=20infinite=20recursion=20for=20re=E2=80=A6"?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This reverts commit 8095b9ce6bf5831a14c72028920708f38d13d0c3.
---
 clang-tools-extra/docs/ReleaseNotes.rst   |  4 ---
 .../misc/const-correctness-templates.cpp  | 15 --
 .../Analysis/Analyses/ExprMutationAnalyzer.h  | 28 +
 clang/lib/Analysis/ExprMutationAnalyzer.cpp   | 22 +-
 .../Analysis/ExprMutationAnalyzerTest.cpp | 30 ---
 5 files changed, 15 insertions(+), 84 deletions(-)

diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 7095c56fe6..4dfbd8ca49ab9b 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -221,10 +221,6 @@ Changes in existing checks
   ` check by replacing the local
   option `HeaderFileExtensions` by the global option of the same name.
 
-- Improved :doc:`misc-const-correctness
-  ` check by avoiding infinite 
recursion
-  for recursive forwarding reference.
-
 - Improved :doc:`misc-definitions-in-headers
   ` check by replacing the local
   option `HeaderFileExtensions` by the global option of the same name.
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-templates.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-templates.cpp
index 248374a71dd40b..9da468128743e9 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-templates.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-templates.cpp
@@ -58,18 +58,3 @@ void concatenate3(Args... args)
 (..., (stream << args));
 }
 } // namespace gh70323
-
-namespace gh60895 {
-
-template  void f1(T &&a);
-template  void f2(T &&a);
-template  void f1(T &&a) { f2(a); }
-template  void f2(T &&a) { f1(a); }
-void f() {
-  int x = 0;
-  // CHECK-MESSAGES:[[@LINE-1]]:3: warning: variable 'x' of type 'int' can be 
declared 'const'
-  // CHECK-FIXES: int const x = 0;
-  f1(x);
-}
-
-} // namespace gh60895
diff --git a/clang/include/clang/Analysis/Analyses/ExprMutationAnalyzer.h 
b/clang/include/clang/Analysis/Analyses/ExprMutationAnalyzer.h
index c4e5d0badb8e58..1ceef944fbc34e 100644
--- a/clang/include/clang/Analysis/Analyses/ExprMutationAnalyzer.h
+++ b/clang/include/clang/Analysis/Analyses/ExprMutationAnalyzer.h
@@ -8,10 +8,11 @@
 #ifndef LLVM_CLANG_ANALYSIS_ANALYSES_EXPRMUTATIONANALYZER_H
 #define LLVM_CLANG_ANALYSIS_ANALYSES_EXPRMUTATIONANALYZER_H
 
+#include 
+
 #include "clang/AST/AST.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
 #include "llvm/ADT/DenseMap.h"
-#include 
 
 namespace clang {
 
@@ -21,15 +22,8 @@ class FunctionParmMutationAnalyzer;
 /// a given statement.
 class ExprMutationAnalyzer {
 public:
-  friend class FunctionParmMutationAnalyzer;
-  struct Cache {
-llvm::SmallDenseMap>
-FuncParmAnalyzer;
-  };
-
   ExprMutationAnalyzer(const Stmt &Stm, ASTContext &Context)
-  : ExprMutationAnalyzer(Stm, Context, std::make_shared()) {}
+  : Stm(Stm), Context(Context) {}
 
   bool isMutated(const Expr *Exp) { return findMutation(Exp) != nullptr; }
   bool isMutated(const Decl *Dec) { return findMutation(Dec) != nullptr; }
@@ -51,11 +45,6 @@ class ExprMutationAnalyzer {
   using MutationFinder = const Stmt *(ExprMutationAnalyzer::*)(const Expr *);
   using ResultMap = llvm::DenseMap;
 
-  ExprMutationAnalyzer(const Stmt &Stm, ASTContext &Context,
-   std::shared_ptr CrossAnalysisCache)
-  : Stm(Stm), Context(Context),
-CrossAnalysisCache(std::move(CrossAnalysisCache)) {}
-
   const Stmt *findMutationMemoized(const Expr *Exp,
llvm::ArrayRef Finders,
ResultMap &MemoizedResults);
@@ -80,7 +69,9 @@ class ExprMutationAnalyzer {
 
   const Stmt &Stm;
   ASTContext &Context;
-  std::shared_ptr CrossAnalysisCache;
+  llvm::DenseMap>
+  FuncParmAnalyzer;
   ResultMap Results;
   ResultMap PointeeResults;
 };
@@ -89,12 +80,7 @@ class ExprMutationAnalyzer {
 // params.
 class FunctionParmMutationAnalyzer {
 public:
-  FunctionParmMutationAnalyzer(const FunctionDecl &Func, ASTContext &Context)
-  : FunctionParmMutationAnalyzer(
-Func, Context, std::make_shared()) {}
-  FunctionParmMutationAnalyzer(
-  const FunctionDecl &Func, ASTContext &Context,
-  std::shared_ptr CrossAnalysisCache);
+  FunctionParmMutationAnalyzer(const FunctionDecl &Func, AS

[clang] [clang-tools-extra] [clang analysis] ExprMutationAnalyzer avoid infinite recursion for recursive forwarding reference (PR #87954)

2024-04-15 Thread Florian Mayer via cfe-commits

fmayer wrote:

This broke the sanitizer bots, e.g. 
https://lab.llvm.org/buildbot/#/builders/239/builds/6587/steps/10/logs/stdio

```
[==] Running 2 tests from 1 test suite.
[--] Global test environment set-up.
[--] 2 tests from ExprMutationAnalyzerTest
[ RUN  ] ExprMutationAnalyzerTest.UnresolvedOperator
[   OK ] ExprMutationAnalyzerTest.UnresolvedOperator (59 ms)
[ RUN  ] ExprMutationAnalyzerTest.ReproduceFailureMinimal
input.cc:1:166: warning: unqualified call to 'std::forward' 
[-Wunqualified-std-cast-call]
1 | namespace std {template  T &forward(T &A) { return 
static_cast(A); }template  struct __bind {  T f;  template  __bind(T v, V &&) : f(forward(v)) {}};}void f() {  int x = 42;  auto Lambda 
= [] {};  std::__bind(Lambda, x);}
  | 

 ^
  | 

 std::
input.cc:1:230: note: in instantiation of function template specialization 
'std::__bind<(lambda at input.cc:1:222)>::__bind' requested here
1 | namespace std {template  T &forward(T &A) { return 
static_cast(A); }template  struct __bind {  T f;  template  __bind(T v, V &&) : f(forward(v)) {}};}void f() {  int x = 42;  auto Lambda 
= [] {};  std::__bind(Lambda, x);}
  | 

 ^
[   OK ] ExprMutationAnalyzerTest.ReproduceFailureMinimal (46 ms)
[--] 2 tests from ExprMutationAnalyzerTest (106 ms total)
[--] Global test environment tear-down
[==] 2 tests from 1 test suite ran. (107 ms total)
[  PASSED  ] 2 tests.
=
==946027==ERROR: LeakSanitizer: detected memory leaks
Indirect leak of 1024 byte(s) in 1 object(s) allocated from:
#0 0xc90ddce4 in operator new(unsigned long, std::align_val_t) 
/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/compiler-rt/lib/asan/asan_new_delete.cpp:98:3
#1 0xca15f590 in allocateBuckets 
/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/include/llvm/ADT/DenseMap.h:899:9
#2 0xca15f590 in llvm::DenseMap, 
llvm::detail::DenseMapPair>::grow(unsigned int) 
/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/include/llvm/ADT/DenseMap.h:833:5
#3 0xca15f428 in grow 
/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/include/llvm/ADT/DenseMap.h:564:36
#4 0xca15f428 in InsertIntoBucketImpl 
/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/include/llvm/ADT/DenseMap.h
#5 0xca15f428 in llvm::detail::DenseMapPair* llvm::DenseMapBase, llvm::detail::DenseMapPair>, clang::ParmVarDecl const*, clang::Stmt const*, 
llvm::DenseMapInfo, 
llvm::detail::DenseMapPair>::InsertIntoBucket(llvm::detail::DenseMapPair*, clang::ParmVarDecl const* const&) 
/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/include/llvm/ADT/DenseMap.h:574:17
#6 0xca104ee8 in FindAndConstruct 
/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/include/llvm/ADT/DenseMap.h:353:13
#7 0xca104ee8 in operator[] 
/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/include/llvm/ADT/DenseMap.h:357:12
#8 0xca104ee8 in 
clang::FunctionParmMutationAnalyzer::findMutation(clang::ParmVarDecl const*) 
/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/clang/lib/Analysis/ExprMutationAnalyzer.cpp:685:3
#9 0xca0f64d4 in 
clang::ExprMutationAnalyzer::findFunctionArgMutation(clang::Expr const*) 
/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/clang/lib/Analysis/ExprMutationAnalyzer.cpp:645:23
#10 0xca0d5b30 in 
clang::ExprMutationAnalyzer::findMutationMemoized(clang::Expr const*, 
llvm::ArrayRef, llvm::DenseMap, 
llvm::detail::DenseMapPair>&) 
/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/clang/lib/Analysis/ExprMutationAnalyzer.cpp:237:25
#11 0xca0d5864 in clang::ExprMutationAnalyzer::findMutation(clang::Expr 
const*) 
/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/clang/lib/Analysis/ExprMutationAnalyzer.cpp:203:10
#12 0xc9176f08 in isMutated 
/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/clang/include/clang/Analysis/Analyses/ExprMutationAnalyzer.h:34:44
#13 0xc9176f08 in clang::(anonymous 
namespace)::isMutated(llvm::SmallVectorImpl 
const&, clang::ASTUnit*) 
/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp:57:57
#14 0xc91c2980 in 
clang::ExprMuta

[clang] [clang-tools-extra] [compiler-rt] [libcxx] [lld] [lldb] [llvm] [mlir] Fix SyntaxWarning messages from python 3.12 (PR #86806)

2024-03-27 Thread Florian Mayer via cfe-commits




fmayer wrote:

LGTM, verified the two strings are the same

```
>>> r"^(.*) \(in (.*)\) \((.*:\d*)\)$" == "^(.*) \(in (.*)\) \((.*:\d*)\)$"
True
>>> "^( *#([0-9]+) *)(0x[0-9a-f]+) *(?:in *.+)? *\((.*)\+(0x[0-9a-f]+)\)" == 
>>> r"^( *#([0-9]+) *)(0x[0-9a-f]+) *(?:in *.+)? *\((.*)\+(0x[0-9a-f]+)\)"
```

https://github.com/llvm/llvm-project/pull/86806
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-tools-extra] [compiler-rt] [flang] [lld] [lldb] [llvm] [mlir] [openmp] [pstl] Finally formalise our defacto line-ending policy (PR #86318)

2024-03-25 Thread Florian Mayer via cfe-commits

fmayer wrote:

> . The point of this patch is not to lambast developers or interfere with 
> their local setups; it's to get the line-ending issues out of the way for 
> good so they can focus on what they do best.

Fair enough. I don't think it will fully make them go away for good, as you 
mentioned "[...] except for specific cases like .bat files or tests for parsers 
that need to accept such sequences." Something somewhere is bound to work 
before the transformation, and no longer after. It's possible that that will be 
more rare, though I would say 100 reverts in all of LLVM history isn't really 
that much either, all things considered.

> And, given what I quoted above, it's not about faith - it's about historical 
> evidence that this is a problem.

I am not saying this isn't a problem at all, but how often has anyone done a 
one line change and caused a 50k diff, and submitted it without noticing?

https://github.com/llvm/llvm-project/pull/86318
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-tools-extra] [compiler-rt] [flang] [lld] [lldb] [llvm] [mlir] [openmp] [pstl] Finally formalise our defacto line-ending policy (PR #86318)

2024-03-25 Thread Florian Mayer via cfe-commits

fmayer wrote:

> That wish is fine until you start working with others.

Do we actually have that little faith in developers that we think they will 
check in a 50k line diff?

https://github.com/llvm/llvm-project/pull/86318
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-tools-extra] [compiler-rt] [flang] [lld] [lldb] [llvm] [mlir] [openmp] [pstl] Finally formalise our defacto line-ending policy (PR #86318)

2024-03-25 Thread Florian Mayer via cfe-commits

fmayer wrote:

I don't have a strong opinion, but fundamentally I would prefer if the source 
control system stored exactly the files I have in my checkout, not mess with 
them in any way. I understand there are practical concerns, but a linter for 
unexpected CRLF would maybe be an option?

https://github.com/llvm/llvm-project/pull/86318
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-repl] Pass triple to IncrementalCompilerBuilder as explicit argument (PR #84174)

2024-03-06 Thread Florian Mayer via cfe-commits

fmayer wrote:

This triggers the leak detector in our HWASan build bot

```
Note: This is test shard 1 of 23.
[==] Running 1 test from 1 test suite.
[--] Global test environment set-up.
[--] 1 test from IncrementalCompilerBuilder
[ RUN  ] IncrementalCompilerBuilder.SetCompilerArgs
[   OK ] IncrementalCompilerBuilder.SetCompilerArgs (12 ms)
[--] 1 test from IncrementalCompilerBuilder (12 ms total)
[--] Global test environment tear-down
[==] 1 test from 1 test suite ran. (12 ms total)
[  PASSED  ] 1 test.
=
==2996657==ERROR: LeakSanitizer: detected memory leaks
Direct leak of 33 byte(s) in 1 object(s) allocated from:
#0 0xc1507a9c in operator new(unsigned long) 
/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/compiler-rt/lib/hwasan/hwasan_new_delete.cpp:64:3
#1 0xc2593884 in operator new(unsigned long, (anonymous 
namespace)::NamedBufferAlloc const&) 
/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/lib/Support/MemoryBuffer.cpp:82:35
#2 0xc2593550 in llvm::MemoryBuffer::getMemBuffer(llvm::StringRef, 
llvm::StringRef, bool) 
/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/lib/Support/MemoryBuffer.cpp:124:15
#3 0xc39509d4 in CreateCI 
/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/clang/lib/Interpreter/Interpreter.cpp:111:28
#4 0xc39509d4 in 
clang::IncrementalCompilerBuilder::create(std::__1::basic_string, std::__1::allocator>, std::__1::vector>&) 
/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/clang/lib/Interpreter/Interpreter.cpp:178:10
#5 0xc3953298 in clang::IncrementalCompilerBuilder::CreateCpp() 
/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/clang/lib/Interpreter/Interpreter.cpp:189:10
#6 0xc1509c10 in (anonymous 
namespace)::IncrementalCompilerBuilder_SetCompilerArgs_Test::TestBody() 
/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/clang/unittests/Interpreter/IncrementalCompilerBuilderTest.cpp:24:25
#7 0xc273ec98 in HandleExceptionsInMethodIfSupported 
/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/third-party/unittest/googletest/src/gtest.cc
#8 0xc273ec98 in testing::Test::Run() 
/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/third-party/unittest/googletest/src/gtest.cc:2687:5
#9 0xc2742074 in testing::TestInfo::Run() 
/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/third-party/unittest/googletest/src/gtest.cc:2836:11
#10 0xc2744284 in testing::TestSuite::Run() 
/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/third-party/unittest/googletest/src/gtest.cc:3015:30
#11 0xc276ac1c in testing::internal::UnitTestImpl::RunAllTests() 
/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/third-party/unittest/googletest/src/gtest.cc:5920:44
#12 0xc27695e8 in 
HandleExceptionsInMethodIfSupported 
/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/third-party/unittest/googletest/src/gtest.cc
#13 0xc27695e8 in testing::UnitTest::Run() 
/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/third-party/unittest/googletest/src/gtest.cc:5484:10
#14 0xc2700288 in RUN_ALL_TESTS 
/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/third-party/unittest/googletest/include/gtest/gtest.h:2317:73
#15 0xc2700288 in main 
/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/third-party/unittest/UnitTestMain/TestMain.cpp:55:10
#16 0x98856dbc  (/lib/aarch64-linux-gnu/libc.so.6+0x26dbc) (BuildId: 
b3e2fd825ee86277a10a2c20b9fc836b101a2b7f)
#17 0x98856e94 in __libc_start_main 
(/lib/aarch64-linux-gnu/libc.so.6+0x26e94) (BuildId: 
b3e2fd825ee86277a10a2c20b9fc836b101a2b7f)
#18 0xc14cf22c in _start 
(/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/tools/clang/unittests/Interpreter/ClangReplInterpreterTests+0x3fdf22c)
SUMMARY: HWAddressSanitizer: 33 byte(s) leaked in 1 allocation(s).
libc++abi: Pure virtual function called!
--
exit: -6
--

Testing:  0.. 10.. 20
FAIL: Clang-Unit :: Interpreter/./ClangReplInterpreterTests/1/23 (19683 of 
78329)
 TEST 'Clang-Unit :: 
Interpreter/./ClangReplInterpreterTests/1/23' FAILED 
Script(shard):
--
GTEST_OUTPUT=json:/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/tools/clang/unittests/Interpreter/./ClangReplInterpreterTests-Clang-Unit-2413105-1-23.json
 GTEST_SHUFFLE=0 GTEST_TOTAL_SHARDS=23 GTEST_SHARD_INDEX=1 
/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/tools/clang/unittests/Interpreter/./ClangReplInterpreterTests
--
Note: This is test shard 2 of 23.
[==] Running 1 test from 1 test suite.
[--] Global test environment set-up.
[--] 1 test from IncrementalCompile

[libcxx] [llvm] [lld] [flang] [clang] [lldb] [libc] [libcxxabi] [msan] Unpoison indirect outputs for userspace using llvm.memset.* (PR #79924)

2024-01-30 Thread Florian Mayer via cfe-commits

https://github.com/fmayer approved this pull request.


https://github.com/llvm/llvm-project/pull/79924
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [compiler-rt] [NFC] Size and element numbers are often swapped when calling calloc (PR #79081)

2024-01-23 Thread Florian Mayer via cfe-commits

https://github.com/fmayer closed https://github.com/llvm/llvm-project/pull/79081
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[compiler-rt] [clang] [NFC] Size and element numbers are often swapped when calling calloc (PR #79081)

2024-01-22 Thread Florian Mayer via cfe-commits

https://github.com/fmayer approved this pull request.


https://github.com/llvm/llvm-project/pull/79081
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] hurd: Fix build with -Werror,-Wswitch (PR #78520)

2024-01-17 Thread Florian Mayer via cfe-commits

https://github.com/fmayer approved this pull request.

Is there a reason you put this first? Otherwise IMO it is slightly neater to 
put it last.

https://github.com/llvm/llvm-project/pull/78520
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] hurd: Fix build with -Werror,-Wswitch (PR #78520)

2024-01-17 Thread Florian Mayer via cfe-commits

fmayer wrote:

Drive-by: is the `llvm_unreachable` actually unreachable? I.e. we never call 
this function with this case? Otherwise we are introducing UB in `NDEBUG` builds

```
/// In NDEBUG builds, if the platform does not support a builtin unreachable
/// then we call an internal LLVM runtime function. Otherwise the behavior is
/// controlled by the CMake flag
///   -DLLVM_UNREACHABLE_OPTIMIZE
/// * When "ON" (default) llvm_unreachable() becomes an optimizer hint
///   that the current location is not supposed to be reachable: the hint
///   turns such code path into undefined behavior.  On compilers that don't
///   support such hints, prints a reduced message instead and aborts the
///   program.
```

https://github.com/llvm/llvm-project/pull/78520
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] Hurd: Add x86_64 support (PR #78065)

2024-01-17 Thread Florian Mayer via cfe-commits

fmayer wrote:

This broke Sanitizer bots:


```
[5/25] Building CXX object 
tools/clang/lib/Driver/CMakeFiles/obj.clangDriver.dir/ToolChains/Hurd.cpp.o
FAILED: 
tools/clang/lib/Driver/CMakeFiles/obj.clangDriver.dir/ToolChains/Hurd.cpp.o 
CCACHE_CPP2=yes CCACHE_HASHDIR=yes /usr/bin/ccache 
/b/sanitizer-aarch64-linux/build/llvm_build0/bin/clang++ -DGTEST_HAS_RTTI=0 
-D_DEBUG -D_GLIBCXX_ASSERTIONS -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS 
-D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS 
-I/b/sanitizer-aarch64-linux/build/build_symbolizer/tools/clang/lib/Driver 
-I/b/sanitizer-aarch64-linux/build/llvm-project/clang/lib/Driver 
-I/b/sanitizer-aarch64-linux/build/llvm-project/clang/include 
-I/b/sanitizer-aarch64-linux/build/build_symbolizer/tools/clang/include 
-I/b/sanitizer-aarch64-linux/build/build_symbolizer/include 
-I/b/sanitizer-aarch64-linux/build/llvm-project/llvm/include -fPIC 
-fno-semantic-interposition -fvisibility-inlines-hidden -Werror 
-Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra 
-Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers 
-pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough 
-Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor 
-Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion 
-Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color 
-ffunction-sections -fdata-sections -fno-common -Woverloaded-virtual 
-Wno-nested-anon-types -O3 -DNDEBUG  -fno-exceptions -funwind-tables -fno-rtti 
-UNDEBUG -std=c++17 -MD -MT 
tools/clang/lib/Driver/CMakeFiles/obj.clangDriver.dir/ToolChains/Hurd.cpp.o -MF 
tools/clang/lib/Driver/CMakeFiles/obj.clangDriver.dir/ToolChains/Hurd.cpp.o.d 
-o tools/clang/lib/Driver/CMakeFiles/obj.clangDriver.dir/ToolChains/Hurd.cpp.o 
-c 
/b/sanitizer-aarch64-linux/build/llvm-project/clang/lib/Driver/ToolChains/Hurd.cpp
/b/sanitizer-aarch64-linux/build/llvm-project/clang/lib/Driver/ToolChains/Hurd.cpp:137:11:
 error: 60 enumeration values not handled in switch: 'UnknownArch', 'arm', 
'armeb'... [-Werror,-Wswitch]
  137 |   switch (getArch()) {
  |   ^
1 error generated.
```

https://github.com/llvm/llvm-project/pull/78065
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [llvm] [clang] [AMDGPU] Reapply 'Sign extend simm16 in setreg intrinsic' (PR #78492)

2024-01-17 Thread Florian Mayer via cfe-commits

https://github.com/fmayer approved this pull request.


https://github.com/llvm/llvm-project/pull/78492
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [libcxx] [lld] [flang] [compiler-rt] [libc] [clang-tools-extra] [clang] [hwasan] Workaround unsupported AssignmentTrackingPass (PR #76547)

2024-01-02 Thread Florian Mayer via cfe-commits

https://github.com/fmayer approved this pull request.

LGTM, but maybe be more explicit in the commit message how we work around this.

https://github.com/llvm/llvm-project/pull/76547
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libc] [clang] [openmp] [flang] [libcxx] [llvm] [compiler-rt] [lldb] [mlir] [hwasan] Classify stack overflow, and use after scope (PR #76133)

2023-12-21 Thread Florian Mayer via cfe-commits

https://github.com/fmayer approved this pull request.


https://github.com/llvm/llvm-project/pull/76133
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [openmp] [libc] [compiler-rt] [lldb] [mlir] [flang] [libcxx] [clang] [hwasan] Classify stack overflow, and use after scope (PR #76133)

2023-12-21 Thread Florian Mayer via cfe-commits

https://github.com/fmayer commented:

Remove this comment?

Line 780

```
// TODO(fmayer): figure out how to distinguish use-after-return and
// stack-buffer-overflow.
```

https://github.com/llvm/llvm-project/pull/76133
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [openmp] [libc] [compiler-rt] [lldb] [mlir] [flang] [libcxx] [clang] [hwasan] Classify stack overflow, and use after scope (PR #76133)

2023-12-21 Thread Florian Mayer via cfe-commits


@@ -221,29 +221,55 @@ static void PrintStackAllocations(const 
StackAllocationsRingBuffer *sa,
   for (LocalInfo &local : frame.locals) {
 if (!local.has_frame_offset || !local.has_size || 
!local.has_tag_offset)
   continue;
+if (!(local.name && internal_strlen(local.name)) &&
+!(local.function_name && internal_strlen(local.name)) &&
+!(local.decl_file && internal_strlen(local.decl_file)))
+  continue;
 tag_t obj_tag = base_tag ^ local.tag_offset;
 if (obj_tag != addr_tag)
   continue;
-// Calculate the offset from the object address to the faulting
-// address. Because we only store bits 4-19 of FP (bits 0-3 are
-// guaranteed to be zero), the calculation is performed mod 2^20 and 
may
-// harmlessly underflow if the address mod 2^20 is below the object
-// address.
-uptr obj_offset =
-(untagged_addr - fp - local.frame_offset) & (kRecordFPModulus - 1);
-if (obj_offset >= local.size)
-  continue;
+uptr local_beg = (fp + local.frame_offset) |

fmayer wrote:

 I am confused by this. Could you add a comment as on the LHS? Why isn't the 
`local_beg` not just `fp + local.frame_offset`?

https://github.com/llvm/llvm-project/pull/76133
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [libcxx] [lldb] [flang] [openmp] [mlir] [libc] [compiler-rt] [hwasan] Classify stack overflow, and use after scope (PR #76133)

2023-12-21 Thread Florian Mayer via cfe-commits


@@ -221,29 +221,55 @@ static void PrintStackAllocations(const 
StackAllocationsRingBuffer *sa,
   for (LocalInfo &local : frame.locals) {
 if (!local.has_frame_offset || !local.has_size || 
!local.has_tag_offset)
   continue;
+if (!(local.name && internal_strlen(local.name)) &&
+!(local.function_name && internal_strlen(local.name)) &&
+!(local.decl_file && internal_strlen(local.decl_file)))
+  continue;
 tag_t obj_tag = base_tag ^ local.tag_offset;
 if (obj_tag != addr_tag)
   continue;
-// Calculate the offset from the object address to the faulting
-// address. Because we only store bits 4-19 of FP (bits 0-3 are
-// guaranteed to be zero), the calculation is performed mod 2^20 and 
may
-// harmlessly underflow if the address mod 2^20 is below the object
-// address.
-uptr obj_offset =
-(untagged_addr - fp - local.frame_offset) & (kRecordFPModulus - 1);
-if (obj_offset >= local.size)
-  continue;
+uptr local_beg = (fp + local.frame_offset) |
+ (untagged_addr & ~(uptr(kRecordFPModulus) - 1));
+uptr local_end = local_beg + local.size;
+
 if (!found_local) {
   Printf("\nPotentially referenced stack objects:\n");
   found_local = true;
 }
+
+uptr offset;
+const char *whence;
+const char *cause;
+if (local_beg <= untagged_addr && untagged_addr < local_end) {
+  offset = untagged_addr - local_beg;
+  whence = "inside";
+  cause = "use-after-scope";
+} else if (untagged_addr >= local_end) {
+  offset = untagged_addr - local_end;
+  whence = "after";
+  cause = "stack-buffer-overflow";
+} else {
+  offset = local_beg - untagged_addr;
+  whence = "before";
+  cause = "stack-buffer-overflow";
+}
+Decorator d;
+Printf("%s", d.Error());
+Printf("Cause: %s\n", cause);
+Printf("%s", d.Default());
+Printf("%s", d.Location());
+Printf("%p is located %zd bytes %s a %zd-byte region [%p,%p)\n",
+   untagged_addr, offset, whence, local_end - local_beg, local_beg,
+   local_end);
+Printf("%s", d.Allocation());
 StackTracePrinter::GetOrInit()->RenderSourceLocation(

fmayer wrote:

FYI the offline symbolizer has this output format

```
self.print('')
self.print('Potentially referenced stack object:')
self.print('  %d bytes inside a variable "%s" in stack frame of 
function "%s"' % (obj_offset, local[2], local[0]))
self.print('  at %s' % (local[1],))
```

https://github.com/llvm/llvm-project/pull/76133
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [lldb] [mlir] [libc] [compiler-rt] [flang] [clang] [openmp] [hwasan] Respect strip_path_prefix printing locals (PR #76132)

2023-12-21 Thread Florian Mayer via cfe-commits

https://github.com/fmayer approved this pull request.

Lgtm thanks

https://github.com/llvm/llvm-project/pull/76132
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [compiler-rt] [hwasan] Separate sections in report (PR #76130)

2023-12-21 Thread Florian Mayer via cfe-commits

https://github.com/fmayer approved this pull request.


https://github.com/llvm/llvm-project/pull/76130
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[compiler-rt] [clang] [hwasan] Separate sections in report (PR #76130)

2023-12-21 Thread Florian Mayer via cfe-commits

fmayer wrote:

LGTM. Could you explain in the description why we are doing this?

https://github.com/llvm/llvm-project/pull/76130
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 043d03d - Revert "Reland "Fix __cfi_check not aligned to 4k on relocatable files with no executable code""

2023-08-04 Thread Florian Mayer via cfe-commits

Author: Florian Mayer
Date: 2023-08-04T14:24:26-07:00
New Revision: 043d03d25bd7eadef66685de298342b35fe6b466

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

LOG: Revert "Reland "Fix __cfi_check not aligned to 4k on relocatable files 
with no executable code""

Broke sanitizer build bots

This reverts commit b82c2b9ac2baae0f2a9dd65770cfb37fdc2a80a9.

Added: 


Modified: 
clang/lib/CodeGen/CGExpr.cpp
clang/test/CodeGen/cfi-check-fail.c

Removed: 




diff  --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 07e204387804c8..0aadaeaba69f3d 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -3431,12 +3431,14 @@ void CodeGenFunction::EmitCfiCheckStub() {
   llvm::Function *F = llvm::Function::Create(
   llvm::FunctionType::get(VoidTy, {Int64Ty, Int8PtrTy, Int8PtrTy}, false),
   llvm::GlobalValue::WeakAnyLinkage, "__cfi_check", M);
-  F->setAlignment(llvm::Align(4096));
   CGM.setDSOLocal(F);
   llvm::BasicBlock *BB = llvm::BasicBlock::Create(Ctx, "entry", F);
-  // CrossDSOCFI pass is not executed if there is no executable code.
-  SmallVector Args{F->getArg(2), F->getArg(1)};
-  llvm::CallInst::Create(M->getFunction("__cfi_check_fail"), Args, "", BB);
+  // 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);
 }
 
@@ -3530,6 +3532,9 @@ void CodeGenFunction::EmitCfiCheckFail() {
   }
 
   FinishFunction();
+  // The only reference to this function will be created during LTO link.
+  // Make sure it survives until then.
+  CGM.addUsedGlobal(F);
 }
 
 void CodeGenFunction::EmitUnreachable(SourceLocation Loc) {

diff  --git a/clang/test/CodeGen/cfi-check-fail.c 
b/clang/test/CodeGen/cfi-check-fail.c
index 2f12cee9dec602..a4d940641090e5 100644
--- a/clang/test/CodeGen/cfi-check-fail.c
+++ b/clang/test/CodeGen/cfi-check-fail.c
@@ -72,7 +72,7 @@ void caller(void (*f)(void)) {
 // CHECK: [[CONT5]]:
 // CHECK:   ret void
 
-// CHECK: define weak void @__cfi_check(i64 %[[TYPE:.*]], ptr %[[ADDR:.*]], 
ptr %[[DATA:.*]]) align 4096
+// CHECK: define weak void @__cfi_check(i64 %0, ptr %1, ptr %2)
 // CHECK-NOT: }
-// CHECK: call void @__cfi_check_fail(ptr %[[DATA]], ptr %[[ADDR]])
+// CHECK: call void @llvm.trap()
 // CHECK-NEXT: ret void



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


[clang] a2684ac - [HWASan] use hwasan linker for Android 14+

2023-05-26 Thread Florian Mayer via cfe-commits

Author: Florian Mayer
Date: 2023-05-26T14:25:46-07:00
New Revision: a2684acfb61d40f441e240035d7f1ba50da637c8

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

LOG: [HWASan] use hwasan linker for Android 14+

This will allow to compile binaries that use hwasan to run on a
non-HWASan system image.

Reviewed By: pcc

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

Added: 


Modified: 
clang/lib/Driver/ToolChains/Linux.cpp
clang/test/Driver/linux-ld.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Linux.cpp 
b/clang/lib/Driver/ToolChains/Linux.cpp
index 853ff99d9fe59..920da6e4bfd49 100644
--- a/clang/lib/Driver/ToolChains/Linux.cpp
+++ b/clang/lib/Driver/ToolChains/Linux.cpp
@@ -426,9 +426,17 @@ std::string Linux::getDynamicLinker(const ArgList &Args) 
const {
 
   const Distro Distro(getDriver().getVFS(), Triple);
 
-  if (Triple.isAndroid())
+  if (Triple.isAndroid()) {
+if (getSanitizerArgs(Args).needsHwasanRt() &&
+!Triple.isAndroidVersionLT(34) && Triple.isArch64Bit()) {
+  // On Android 14 and newer, there is a special linker_hwasan64 that
+  // allows to run HWASan binaries on non-HWASan system images. This
+  // is also available on HWASan system images, so we can just always
+  // use that instead.
+  return "/system/bin/linker_hwasan64";
+}
 return Triple.isArch64Bit() ? "/system/bin/linker64" : 
"/system/bin/linker";
-
+  }
   if (Triple.isMusl()) {
 std::string ArchName;
 bool IsArm = false;

diff  --git a/clang/test/Driver/linux-ld.c b/clang/test/Driver/linux-ld.c
index 287750ac20469..d4e3bf95d6813 100644
--- a/clang/test/Driver/linux-ld.c
+++ b/clang/test/Driver/linux-ld.c
@@ -1259,6 +1259,22 @@
 // CHECK-ANDROID-32: "-dynamic-linker" "/system/bin/linker"
 // CHECK-ANDROID-64: "-dynamic-linker" "/system/bin/linker64"
 //
+// Test that Android 14 and newer use linker_hwasan64 for hwasan builds
+// RUN: %clang -### %s -no-pie 2>&1 \
+// RUN: -fsanitize=hwaddress \
+// RUN: --target=x86_64-linux-android33 \
+// RUN: --gcc-toolchain="" \
+// RUN: --sysroot=%S/Inputs/basic_android_tree/sysroot \
+// RUN:   | FileCheck --check-prefix=CHECK-ANDROID-OLD %s
+// RUN: %clang -### %s -no-pie 2>&1 \
+// RUN: -fsanitize=hwaddress \
+// RUN: --target=x86_64-linux-android34 \
+// RUN: --gcc-toolchain="" \
+// RUN: --sysroot=%S/Inputs/basic_android_tree/sysroot \
+// RUN:   | FileCheck --check-prefix=CHECK-ANDROID-NEW %s
+// CHECK-ANDROID-OLD: "-dynamic-linker" "/system/bin/linker64"
+// CHECK-ANDROID-NEW: "-dynamic-linker" "/system/bin/linker_hwasan64"
+//
 // Test that -pthread does not add -lpthread on Android.
 // RUN: %clang -### %s -no-pie 2>&1 \
 // RUN: --target=arm-linux-androideabi -pthread \



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


[libunwind] f5c9931 - [libunwind] Fix compile error with CROSS_UNWINDING

2022-09-30 Thread Florian Mayer via cfe-commits

Author: Florian Mayer
Date: 2022-09-30T12:04:19-07:00
New Revision: f5c9931fefcab8de07a6c08c39b582fa58859dc9

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

LOG: [libunwind] Fix compile error with CROSS_UNWINDING

Reviewed By: #libunwind, MaskRay, mgorny

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

Added: 


Modified: 
libunwind/src/DwarfInstructions.hpp

Removed: 




diff  --git a/libunwind/src/DwarfInstructions.hpp 
b/libunwind/src/DwarfInstructions.hpp
index 1901c8a8aee7d..27432be56133b 100644
--- a/libunwind/src/DwarfInstructions.hpp
+++ b/libunwind/src/DwarfInstructions.hpp
@@ -202,7 +202,10 @@ int DwarfInstructions::stepWithDwarf(A 
&addressSpace, pint_t pc,
   pint_t cfa = getCFA(addressSpace, prolog, registers);
 
   (void)stage2;
-#if defined(_LIBUNWIND_TARGET_AARCH64)
+  // __unw_step_stage2 is not used for cross unwinding, so we use
+  // __aarch64__ rather than LIBUNWIND_TARGET_AARCH64 to make sure we are
+  // building for AArch64 natively.
+#if defined(__aarch64__)
   if (stage2 && cieInfo.mteTaggedFrame) {
 pint_t sp = registers.getSP();
 pint_t p = sp;



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


[libunwind] a315338 - [libunwind] Handle G in personality string

2022-09-21 Thread Florian Mayer via cfe-commits

Author: Florian Mayer
Date: 2022-09-21T14:13:32-07:00
New Revision: a3153381af48b2e704750255a704748a13c4c4de

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

LOG: [libunwind] Handle G in personality string

Tested with the following program:

```
static volatile int* x = nullptr;

void throws()  __attribute__((noinline)) {
  if (getpid() == 0)
return;
  throw "error";
}

void maybe_throws()  __attribute__((noinline)) {
  volatile int y = 1;
  x = &y;
  throws();
  y = 2;
}

int main(int argc, char** argv) {
  int y;
  try {
maybe_throws();
  } catch (const char* e) {
//printf("Caught\n");
  }
  y = *x;
  printf("%d\n", y); // should be MTE failure.
  return 0;
}
```

Built using `clang++ -c -O2 -target aarch64-linux -fexceptions 
-march=armv8-a+memtag -fsanitize=memtag-heap,memtag-stack`

Currently only Android implements runtime support for MTE stack tagging.

Without this change, we crash on `__cxa_get_globals` when trying to catch
the exception (because the stack frame __cxa_get_globals frame will fail due
to tags left behind on the stack). With this change, we crash on the `y = *x;`
as expected, because the stack frame has been untagged, but the pointer hasn't.

Reviewed By: #libunwind, compnerd, MaskRay

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

Added: 


Modified: 
libunwind/src/DwarfInstructions.hpp
libunwind/src/DwarfParser.hpp
libunwind/src/UnwindCursor.hpp
libunwind/src/UnwindLevel1.c
libunwind/src/libunwind.cpp

Removed: 




diff  --git a/libunwind/src/DwarfInstructions.hpp 
b/libunwind/src/DwarfInstructions.hpp
index f81f96ce5a36d..1901c8a8aee7d 100644
--- a/libunwind/src/DwarfInstructions.hpp
+++ b/libunwind/src/DwarfInstructions.hpp
@@ -35,7 +35,7 @@ class DwarfInstructions {
   typedef typename A::sint_t sint_t;
 
   static int stepWithDwarf(A &addressSpace, pint_t pc, pint_t fdeStart,
-   R ®isters, bool &isSignalFrame);
+   R ®isters, bool &isSignalFrame, bool stage2);
 
 private:
 
@@ -190,7 +190,7 @@ bool DwarfInstructions::getRA_SIGN_STATE(A 
&addressSpace, R registers,
 template 
 int DwarfInstructions::stepWithDwarf(A &addressSpace, pint_t pc,
pint_t fdeStart, R ®isters,
-   bool &isSignalFrame) {
+   bool &isSignalFrame, bool stage2) {
   FDE_Info fdeInfo;
   CIE_Info cieInfo;
   if (CFI_Parser::decodeFDE(addressSpace, fdeStart, &fdeInfo,
@@ -201,7 +201,35 @@ int DwarfInstructions::stepWithDwarf(A 
&addressSpace, pint_t pc,
   // get pointer to cfa (architecture specific)
   pint_t cfa = getCFA(addressSpace, prolog, registers);
 
-   // restore registers that DWARF says were saved
+  (void)stage2;
+#if defined(_LIBUNWIND_TARGET_AARCH64)
+  if (stage2 && cieInfo.mteTaggedFrame) {
+pint_t sp = registers.getSP();
+pint_t p = sp;
+// AArch64 doesn't require the value of SP to be 16-byte aligned at
+// all times, only at memory accesses and public interfaces [1]. Thus,
+// a signal could arrive at a point where SP is not aligned properly.
+// In that case, the kernel fixes up [2] the signal frame, but we
+// still have a misaligned SP in the previous frame. If that signal
+// handler caused stack unwinding, we would have an unaligned SP.
+// We do not need to fix up the CFA, as that is the SP at a "public
+// interface".
+// [1]:
+// 
https://github.com/ARM-software/abi-aa/blob/main/aapcs64/aapcs64.rst#622the-stack
+// [2]:
+// 
https://github.com/torvalds/linux/blob/1930a6e739c4b4a654a69164dbe39e554d228915/arch/arm64/kernel/signal.c#L718
+p &= ~0xfULL;
+// CFA is the bottom of the current stack frame.
+for (; p < cfa; p += 16) {
+  __asm__ __volatile__(".arch_extension memtag\n"
+   "stg %[Ptr], [%[Ptr]]\n"
+   :
+   : [Ptr] "r"(p)
+   : "memory");
+}
+  }
+#endif
+  // restore registers that DWARF says were saved
   R newRegisters = registers;
 
   // Typically, the CFA is the stack pointer at the call site in

diff  --git a/libunwind/src/DwarfParser.hpp b/libunwind/src/DwarfParser.hpp
index 0240334eaa73f..0682942ce1379 100644
--- a/libunwind/src/DwarfParser.hpp
+++ b/libunwind/src/DwarfParser.hpp
@@ -51,6 +51,7 @@ class CFI_Parser {
 uint8_t   returnAddressRegister;
 #if defined(_LIBUNWIND_TARGET_AARCH64)
 bool  addressesSignedWithBKey;
+bool  mteTaggedFrame;
 #endif
   };
 
@@ -325,6 +326,7 @@ const char *CFI_Parser::parseCIE(A &

  1   2   >