[clang] 070acb1 - [Driver][ARM] parse version of arm/thumb architecture correctly

2020-07-01 Thread Daniel Kiss via cfe-commits

Author: Daniel Kiss
Date: 2020-07-01T12:13:52+02:00
New Revision: 070acb1d1e51ffd289a46b8f93e993635d0053b7

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

LOG: [Driver][ARM] parse version of arm/thumb architecture correctly

Summary:
If you execute the following commandline multiple times, the behavior was not 
always the same:
  clang++ --target=thumbv7em-none-windows-eabi-coff -march=armv7-m 
-mcpu=cortex-m7 -o temp.obj -c -x c++ empty.cpp

Most of the time the compilation succeeded, but sometimes clang reported this 
error:
  clang++: error: the target architecture 'thumbv7em' is not supported by the 
target 'thumbv7em-none-windows-eabi'

The cause of the inconsistent behavior was the uninitialized variable Version.

With these commandline arguments, the variable Version was not set by 
getAsInteger(),
because it cannot parse a number from the substring "7em" (of "thumbv7em").
To get a consistent behaviour, it's enough to initialize the variable Version 
to zero.
Zero is smaller than 7, so the comparison will be true.
Then the command always fails with the error message seen above.

By using consumeInteger() instead of getAsInteger() we get 7 from the substring 
"7em"
and the command does not fail.

Reviewers: compnerd, danielkiss

Reviewed By: danielkiss

Subscribers: danielkiss, kristof.beyls, cfe-commits

Tags: #clang

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

Added: 
clang/test/Driver/windows-thumbv7em.cpp

Modified: 
clang/lib/Driver/ToolChains/Clang.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 9db6bbadf566..a2cc84805c9c 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -4041,9 +4041,10 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
   if (Triple.isOSWindows() && (Triple.getArch() == llvm::Triple::arm ||
Triple.getArch() == llvm::Triple::thumb)) {
 unsigned Offset = Triple.getArch() == llvm::Triple::arm ? 4 : 6;
-unsigned Version;
-Triple.getArchName().substr(Offset).getAsInteger(10, Version);
-if (Version < 7)
+unsigned Version = 0;
+bool Failure =
+Triple.getArchName().substr(Offset).consumeInteger(10, Version);
+if (Failure || Version < 7)
   D.Diag(diag::err_target_unsupported_arch) << Triple.getArchName()
 << TripleStr;
   }

diff  --git a/clang/test/Driver/windows-thumbv7em.cpp 
b/clang/test/Driver/windows-thumbv7em.cpp
new file mode 100644
index ..5d7c00b31fd1
--- /dev/null
+++ b/clang/test/Driver/windows-thumbv7em.cpp
@@ -0,0 +1,8 @@
+// RUN: %clang -target thumb-none-windows-eabi-coff -mcpu=cortex-m7 -### -c %s 
2>&1 \
+// RUN: | FileCheck %s --check-prefix CHECK-V7
+// CHECK-V7-NOT: error: the target architecture 'thumbv7em' is not supported 
by the target 'thumbv7em-none-windows-eabi'
+
+// RUN: %clang -target thumb-none-windows-eabi-coff -mcpu=cortex-m1 -### -c %s 
2>&1 \
+// RUN: | FileCheck %s --check-prefix CHECK-V6
+// CHECK-V6: error: the target architecture 'thumbv6m' is not supported by the 
target 'thumbv6m-none-windows-eabi'
+



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


[libunwind] 9c3f6fb - [libunwind] Make the test depend on the libunwind explicitly.

2020-08-03 Thread Daniel Kiss via cfe-commits

Author: Daniel Kiss
Date: 2020-08-03T09:46:23+02:00
New Revision: 9c3f6fb68807c8100797b001c0621ae0c9a6d1fc

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

LOG: [libunwind] Make the test depend on the libunwind explicitly.

Before this patch the `ninja check-unwind` won't rebuild the unwind library.

Reviewed By: jroelofs

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

Added: 


Modified: 
libunwind/test/CMakeLists.txt

Removed: 




diff  --git a/libunwind/test/CMakeLists.txt b/libunwind/test/CMakeLists.txt
index 794a59f58f84a..2b945e6eff762 100644
--- a/libunwind/test/CMakeLists.txt
+++ b/libunwind/test/CMakeLists.txt
@@ -32,4 +32,4 @@ configure_lit_site_cfg(
 
 add_lit_testsuite(check-unwind "Running libunwind tests"
   ${CMAKE_CURRENT_BINARY_DIR}
-  DEPENDS ${LIBUNWIND_TEST_DEPS})
+  DEPENDS unwind ${LIBUNWIND_TEST_DEPS})



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


[clang] b0343a3 - Support the min of module flags when linking, use for AArch64 BTI/PAC-RET

2022-04-13 Thread Daniel Kiss via cfe-commits

Author: Daniel Kiss
Date: 2022-04-13T09:31:51+02:00
New Revision: b0343a38a5910e980bb031e4014655d77cd0c162

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

LOG: Support the min of module flags when linking, use for AArch64 BTI/PAC-RET

LTO objects might compiled with different `mbranch-protection` flags which will 
cause an error in the linker.
Such a setup is allowed in the normal build with this change that is possible.

Reviewed By: pcc

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

Added: 
llvm/test/Bitcode/upgrade-branch-protection.ll
llvm/test/LTO/AArch64/Inputs/foo.ll
llvm/test/LTO/AArch64/link-branch-target-enforcement.ll
llvm/test/LTO/AArch64/lit.local.cfg

Modified: 
clang/lib/CodeGen/CodeGenModule.cpp
clang/test/CodeGen/aarch64-sign-return-address.c
clang/test/CodeGen/arm-branch-protection-attr-2.c
clang/test/Frontend/arm-ignore-branch-protection-option.c
llvm/include/llvm/IR/Module.h
llvm/lib/IR/AutoUpgrade.cpp
llvm/lib/IR/Verifier.cpp
llvm/lib/Linker/IRMover.cpp
llvm/test/CodeGen/AArch64/debug-info-sve-dbg-declare.mir
llvm/test/CodeGen/AArch64/live-debugvalues-sve.mir
llvm/test/CodeGen/AArch64/memsize-remarks.ll
llvm/test/CodeGen/AArch64/note-gnu-property-pac-bti-0.ll
llvm/test/CodeGen/AArch64/note-gnu-property-pac-bti-1.ll
llvm/test/CodeGen/AArch64/note-gnu-property-pac-bti-2.ll
llvm/test/CodeGen/AArch64/note-gnu-property-pac-bti-3.ll
llvm/test/CodeGen/AArch64/note-gnu-property-pac-bti-4.ll
llvm/test/CodeGen/AArch64/pacbti-llvm-generated-funcs-2.ll
llvm/test/CodeGen/AArch64/pacbti-module-attrs.ll
llvm/test/CodeGen/AArch64/setjmp-bti-no-enforcement.ll
llvm/test/CodeGen/AArch64/setjmp-bti-outliner.ll
llvm/test/CodeGen/AArch64/setjmp-bti.ll
llvm/test/CodeGen/ARM/pacbti-module-attrs.ll
llvm/test/CodeGen/ARM/setjmp-bti-basic.ll
llvm/test/CodeGen/ARM/setjmp-bti-outliner.ll
llvm/test/CodeGen/Thumb2/LowOverheadLoops/skip-vpt-debug.mir
llvm/test/CodeGen/Thumb2/bti-const-island-multiple-jump-tables.mir
llvm/test/CodeGen/Thumb2/bti-const-island.mir
llvm/test/CodeGen/Thumb2/bti-entry-blocks.ll
llvm/test/CodeGen/Thumb2/bti-indirect-branches.ll
llvm/test/CodeGen/Thumb2/bti-jump-table.mir
llvm/test/CodeGen/Thumb2/bti-outliner-1.ll
llvm/test/CodeGen/Thumb2/bti-outliner-2.ll
llvm/test/CodeGen/Thumb2/bti-outliner-cost-1.ll
llvm/test/CodeGen/Thumb2/bti-outliner-cost-2.ll
llvm/test/CodeGen/Thumb2/bti-pac-replace-1.mir
llvm/test/CodeGen/Thumb2/bti-pac-replace-2.ll
llvm/test/CodeGen/Thumb2/pacbti-m-basic.ll
llvm/test/CodeGen/Thumb2/pacbti-m-indirect-tail-call.ll
llvm/test/CodeGen/Thumb2/pacbti-m-outliner-1.ll
llvm/test/CodeGen/Thumb2/pacbti-m-outliner-2.ll
llvm/test/CodeGen/Thumb2/pacbti-m-outliner-3.ll
llvm/test/CodeGen/Thumb2/pacbti-m-outliner-4.ll
llvm/test/CodeGen/Thumb2/pacbti-m-outliner-5.ll
llvm/test/CodeGen/Thumb2/pacbti-m-overalign.ll
llvm/test/CodeGen/Thumb2/pacbti-m-unsupported-arch.ll
llvm/test/CodeGen/Thumb2/pacbti-m-varargs-1.ll
llvm/test/CodeGen/Thumb2/pacbti-m-varargs-2.ll
llvm/test/CodeGen/Thumb2/pacbti-m-vla.ll
llvm/test/DebugInfo/AArch64/debugline-endsequence.ll
llvm/test/Instrumentation/InstrProfiling/debug-info-correlate-coverage.ll
llvm/test/Instrumentation/InstrProfiling/debug-info-correlate.ll
llvm/test/Verifier/module-flags-1.ll

Removed: 




diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 4efcc8447d81b..b251a4a7df3d2 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -729,7 +729,10 @@ void CodeGenModule::Release() {
   // attributes, but we use module metadata to emit build attributes. This is
   // needed for LTO, where the function attributes are inside bitcode
   // serialised into a global variable by the time build attributes are
-  // emitted, so we can't access them.
+  // emitted, so we can't access them. LTO objects could be compiled with
+  // 
diff erent flags therefore module flags are set to "Min" behavior to achieve
+  // the same end result of the normal build where e.g BTI is off if any object
+  // doesn't support it.
   if (Context.getTargetInfo().hasFeature("ptrauth") &&
   LangOpts.getSignReturnAddressScope() !=
   LangOptions::SignReturnAddressScopeKind::None)
@@ -743,16 +746,16 @@ void CodeGenModule::Release() {
   Arch == llvm::Triple::arm || Arch == llvm::Triple::armeb ||
   Arch == llvm::Triple::aarch64 || Arch == llvm::Triple::aarch64_32 ||
   Arch == llvm::Triple::aarch64_be) {
-getModule().addModuleFlag(llvm::Module::Error, "branch-target-enforcement",
+getModule().addModuleFlag(llvm::Mod

[libunwind] f326df3 - [libunwind][AArch64] Fix _Unwind_ForcedUnwind via sigreturn.

2022-04-28 Thread Daniel Kiss via cfe-commits

Author: Daniel Kiss
Date: 2022-04-28T18:41:38+02:00
New Revision: f326df34bc179e41ea17d31e1ffba4a479e45589

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

LOG: [libunwind][AArch64] Fix _Unwind_ForcedUnwind via sigreturn.

When the sigreturn trampoline is found the unw_proc_info_t.end_ip need to be 
set to
indicate a stack frame is found.

Reviewed By: cjdb, #libunwind, MaskRay

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

Added: 
libcxxabi/test/forced_unwind4.pass.cpp

Modified: 
libunwind/src/UnwindCursor.hpp

Removed: 




diff  --git a/libcxxabi/test/forced_unwind4.pass.cpp 
b/libcxxabi/test/forced_unwind4.pass.cpp
new file mode 100644
index 0..53a0121da92e4
--- /dev/null
+++ b/libcxxabi/test/forced_unwind4.pass.cpp
@@ -0,0 +1,50 @@
+// -*- C++ -*-
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+// REQUIRES: linux && target={{aarch64-.+}}
+
+// pthread_cancel in case of glibc calls _Unwind_ForcedUnwind from a signal on
+// the child_thread. This test ensures sigretrun is handled correctly (see:
+// UnwindCursor::setInfoForSigReturn).
+
+#include 
+#include 
+#include 
+#include 
+
+using namespace std::chrono_literals;
+
+std::condition_variable cv;
+std::mutex cv_m;
+bool thread_ready = false;
+
+static void* test(void* arg) {
+  (void)arg;
+  thread_ready = true;
+  cv.notify_all();
+
+  // This must be a pthread cancellation point.
+  while (1)
+sleep(100);
+
+  return (void*)1;
+}
+
+int main() {
+  pthread_t child_thread;
+  std::unique_lock lk(cv_m);
+  pthread_create(&child_thread, 0, test, (void*)0);
+
+  if (!cv.wait_for(lk, 100ms, [] { return thread_ready; }))
+return -1;
+
+  pthread_cancel(child_thread);
+  pthread_join(child_thread, NULL);
+  return 0;
+}

diff  --git a/libunwind/src/UnwindCursor.hpp b/libunwind/src/UnwindCursor.hpp
index dd849b781753e..29ded5c4e78ed 100644
--- a/libunwind/src/UnwindCursor.hpp
+++ b/libunwind/src/UnwindCursor.hpp
@@ -2606,6 +2606,8 @@ bool UnwindCursor::setInfoForSigReturn(Registers_arm64 &) {
   if (_addressSpace.get32(pc) == 0xd2801168 &&
   _addressSpace.get32(pc + 4) == 0xd401) {
 _info = {};
+_info.start_ip = pc;
+_info.end_ip = pc + 4;
 _isSigReturn = true;
 return true;
   }



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


[libunwind] f6366ef - [libunwind][AArch64] Add support for DWARF expression for RA_SIGN_STATE.

2022-05-13 Thread Daniel Kiss via cfe-commits

Author: Daniel Kiss
Date: 2022-05-13T10:05:59+02:00
New Revision: f6366ef7f4f3cf1182fd70e0c50a9fa54374b612

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

LOG: [libunwind][AArch64] Add support for DWARF expression for RA_SIGN_STATE.

Program may set the RA_SIGN_STATE pseudo register by expressions.
Libunwind expected only the DW_CFA_AARCH64_negate_ra_state could change the 
value
of the register which leads to runtime errors on PAC enabled systems.
In the recent version of the aadwarf64[1] a limitation is added[2] to forbid 
the mixing the
DW_CFA_AARCH64_negate_ra_state with other DWARF Register Rule Instructions.

[1] https://github.com/ARM-software/abi-aa/releases/tag/2022Q1
[2] https://github.com/ARM-software/abi-aa/pull/129

Reviewed By: #libunwind, MaskRay

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

Added: 
libunwind/test/aarch64.ra_sign_state.pass.cpp

Modified: 
libunwind/src/DwarfInstructions.hpp

Removed: 




diff  --git a/libunwind/src/DwarfInstructions.hpp 
b/libunwind/src/DwarfInstructions.hpp
index ab83b0c87acdc..865a489526047 100644
--- a/libunwind/src/DwarfInstructions.hpp
+++ b/libunwind/src/DwarfInstructions.hpp
@@ -72,6 +72,10 @@ class DwarfInstructions {
 assert(0 && "getCFA(): unknown location");
 __builtin_unreachable();
   }
+#if defined(_LIBUNWIND_TARGET_AARCH64)
+  static bool getRA_SIGN_STATE(A &addressSpace, R registers, pint_t cfa,
+   PrologInfo &prolog);
+#endif
 };
 
 template 
@@ -166,6 +170,21 @@ v128 DwarfInstructions::getSavedVectorRegister(
   }
   _LIBUNWIND_ABORT("unsupported restore location for vector register");
 }
+#if defined(_LIBUNWIND_TARGET_AARCH64)
+template 
+bool DwarfInstructions::getRA_SIGN_STATE(A &addressSpace, R registers,
+   pint_t cfa, PrologInfo &prolog) 
{
+  pint_t raSignState;
+  auto regloc = prolog.savedRegisters[UNW_AARCH64_RA_SIGN_STATE];
+  if (regloc.location == CFI_Parser::kRegisterUnused)
+raSignState = regloc.value;
+  else
+raSignState = getSavedRegister(addressSpace, registers, cfa, regloc);
+
+  // Only bit[0] is meaningful.
+  return raSignState & 0x01;
+}
+#endif
 
 template 
 int DwarfInstructions::stepWithDwarf(A &addressSpace, pint_t pc,
@@ -235,7 +254,7 @@ int DwarfInstructions::stepWithDwarf(A &addressSpace, 
pint_t pc,
   // restored. autia1716 is used instead of autia as autia1716 assembles
   // to a NOP on pre-v8.3a architectures.
   if ((R::getArch() == REGISTERS_ARM64) &&
-  prolog.savedRegisters[UNW_AARCH64_RA_SIGN_STATE].value &&
+  getRA_SIGN_STATE(addressSpace, registers, cfa, prolog) &&
   returnAddress != 0) {
 #if !defined(_LIBUNWIND_IS_NATIVE_ONLY)
 return UNW_ECROSSRASIGNING;

diff  --git a/libunwind/test/aarch64.ra_sign_state.pass.cpp 
b/libunwind/test/aarch64.ra_sign_state.pass.cpp
new file mode 100644
index 0..1e09c936d664b
--- /dev/null
+++ b/libunwind/test/aarch64.ra_sign_state.pass.cpp
@@ -0,0 +1,63 @@
+// -*- C++ -*-
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+// REQUIRES: linux && target={{aarch64-.+}}
+
+// This test ensures the .cfi_negate_ra_state the RA_SIGN_STATE pseudo register
+// could be set directly set by a DWARF expression and the unwinder handles it
+// correctly. The two directives can't be mixed in one CIE/FDE sqeuence.
+
+#include 
+
+__attribute__((noinline, target("branch-protection=pac-ret+leaf")))
+void bar() {
+  // ".cfi_negate_ra_state" is emitted by the compiler.
+  throw 1;
+}
+
+__attribute__((noinline, target("branch-protection=none")))
+void foo() {
+  // Here a DWARF expression sets RA_SIGN_STATE.
+  // The LR is signed manually and stored on the stack.
+  asm volatile(
+  ".cfi_escape 0x16,"// DW_CFA_val_expression
+"34,"// REG_34(RA_SIGN_STATE)
+ "1,"// expression_length(1)
+"0x31\n" // DW_OP_lit1
+  "add sp, sp, 16\n" // Restore SP's value before the stack frame is
+ // created.
+  "paciasp\n"// Sign the LR.
+  "str lr, [sp, -0x8]\n" // Overwrite LR on the stack.
+  "sub sp, sp, 16\n" // Restore SP's value.
+  );
+  bar();
+  _Exit(-1);
+}
+
+__attribute__((noinline, target("branch-protection=pac-ret")))
+void bazz() {
+  // ".cfi_negate_ra_state" is emitted by the compiler.
+  try {
+foo();
+  } catch (int i) {
+

[libunwind] fd86423 - Revert "[libunwind][AArch64] Add support for DWARF expression for RA_SIGN_STATE."

2022-05-15 Thread Daniel Kiss via cfe-commits

Author: Daniel Kiss
Date: 2022-05-15T21:42:07+02:00
New Revision: fd864238fca1435cb1ceffdca0d4294cf3419ac7

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

LOG: Revert "[libunwind][AArch64] Add support for DWARF expression for 
RA_SIGN_STATE."

This reverts commit f6366ef7f4f3cf1182fd70e0c50a9fa54374b612.

Added: 


Modified: 
libunwind/src/DwarfInstructions.hpp

Removed: 
libunwind/test/aarch64.ra_sign_state.pass.cpp



diff  --git a/libunwind/src/DwarfInstructions.hpp 
b/libunwind/src/DwarfInstructions.hpp
index a4fac5afa9b82..ab83b0c87acdc 100644
--- a/libunwind/src/DwarfInstructions.hpp
+++ b/libunwind/src/DwarfInstructions.hpp
@@ -72,10 +72,6 @@ class DwarfInstructions {
 assert(0 && "getCFA(): unknown location");
 __builtin_unreachable();
   }
-#if defined(_LIBUNWIND_TARGET_AARCH64)
-  static bool getRA_SIGN_STATE(A &addressSpace, R registers, pint_t cfa,
-   PrologInfo &prolog);
-#endif
 };
 
 template 
@@ -170,21 +166,6 @@ v128 DwarfInstructions::getSavedVectorRegister(
   }
   _LIBUNWIND_ABORT("unsupported restore location for vector register");
 }
-#if defined(_LIBUNWIND_TARGET_AARCH64)
-template 
-bool DwarfInstructions::getRA_SIGN_STATE(A &addressSpace, R registers,
-   pint_t cfa, PrologInfo &prolog) 
{
-  pint_t raSignState;
-  auto regloc = prolog.savedRegisters[UNW_AARCH64_RA_SIGN_STATE];
-  if (regloc.location == CFI_Parser::kRegisterUnused)
-raSignState = static_cast(regloc.value);
-  else
-raSignState = getSavedRegister(addressSpace, registers, cfa, regloc);
-
-  // Only bit[0] is meaningful.
-  return raSignState & 0x01;
-}
-#endif
 
 template 
 int DwarfInstructions::stepWithDwarf(A &addressSpace, pint_t pc,
@@ -254,7 +235,7 @@ int DwarfInstructions::stepWithDwarf(A &addressSpace, 
pint_t pc,
   // restored. autia1716 is used instead of autia as autia1716 assembles
   // to a NOP on pre-v8.3a architectures.
   if ((R::getArch() == REGISTERS_ARM64) &&
-  getRA_SIGN_STATE(addressSpace, registers, cfa, prolog) &&
+  prolog.savedRegisters[UNW_AARCH64_RA_SIGN_STATE].value &&
   returnAddress != 0) {
 #if !defined(_LIBUNWIND_IS_NATIVE_ONLY)
 return UNW_ECROSSRASIGNING;

diff  --git a/libunwind/test/aarch64.ra_sign_state.pass.cpp 
b/libunwind/test/aarch64.ra_sign_state.pass.cpp
deleted file mode 100644
index 1e09c936d664b..0
--- a/libunwind/test/aarch64.ra_sign_state.pass.cpp
+++ /dev/null
@@ -1,63 +0,0 @@
-// -*- C++ -*-
-//===--===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===--===//
-
-// REQUIRES: linux && target={{aarch64-.+}}
-
-// This test ensures the .cfi_negate_ra_state the RA_SIGN_STATE pseudo register
-// could be set directly set by a DWARF expression and the unwinder handles it
-// correctly. The two directives can't be mixed in one CIE/FDE sqeuence.
-
-#include 
-
-__attribute__((noinline, target("branch-protection=pac-ret+leaf")))
-void bar() {
-  // ".cfi_negate_ra_state" is emitted by the compiler.
-  throw 1;
-}
-
-__attribute__((noinline, target("branch-protection=none")))
-void foo() {
-  // Here a DWARF expression sets RA_SIGN_STATE.
-  // The LR is signed manually and stored on the stack.
-  asm volatile(
-  ".cfi_escape 0x16,"// DW_CFA_val_expression
-"34,"// REG_34(RA_SIGN_STATE)
- "1,"// expression_length(1)
-"0x31\n" // DW_OP_lit1
-  "add sp, sp, 16\n" // Restore SP's value before the stack frame is
- // created.
-  "paciasp\n"// Sign the LR.
-  "str lr, [sp, -0x8]\n" // Overwrite LR on the stack.
-  "sub sp, sp, 16\n" // Restore SP's value.
-  );
-  bar();
-  _Exit(-1);
-}
-
-__attribute__((noinline, target("branch-protection=pac-ret")))
-void bazz() {
-  // ".cfi_negate_ra_state" is emitted by the compiler.
-  try {
-foo();
-  } catch (int i) {
-if (i == 1)
-  throw i;
-throw 2;
-  }
-}
-
-int main() {
-  try {
-bazz();
-  } catch (int i) {
-if (i == 1)
-  _Exit(0);
-  }
-  return -1;
-}



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


[libunwind] c218fd3 - [libunwind][AArch64] Add support for DWARF expression for RA_SIGN_STATE.

2022-05-18 Thread Daniel Kiss via cfe-commits

Author: Daniel Kiss
Date: 2022-05-18T17:56:16+02:00
New Revision: c218fd3d7d3764eb123c8429bbcd33bacfe2e633

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

LOG: [libunwind][AArch64] Add support for DWARF expression for RA_SIGN_STATE.

Program may set the RA_SIGN_STATE pseudo register by expressions.
Libunwind expected only the DW_CFA_AARCH64_negate_ra_state could change the 
value
of the register which leads to runtime errors on PAC enabled systems.
In the recent version of the aadwarf64[1] a limitation is added[2] to forbid 
the mixing the
DW_CFA_AARCH64_negate_ra_state with other DWARF Register Rule Instructions.

[1] https://github.com/ARM-software/abi-aa/releases/tag/2022Q1
[2] https://github.com/ARM-software/abi-aa/pull/129

Reviewed By: #libunwind, MaskRay

Differential Revision: https://reviews.llvm.org/D123692
Reland: test moved because it depends on exceptions.

Added: 
libcxxabi/test/native/AArch64/ra_sign_state.pass.cpp

Modified: 
libunwind/src/DwarfInstructions.hpp

Removed: 




diff  --git a/libcxxabi/test/native/AArch64/ra_sign_state.pass.cpp 
b/libcxxabi/test/native/AArch64/ra_sign_state.pass.cpp
new file mode 100644
index ..1e09c936d664
--- /dev/null
+++ b/libcxxabi/test/native/AArch64/ra_sign_state.pass.cpp
@@ -0,0 +1,63 @@
+// -*- C++ -*-
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+// REQUIRES: linux && target={{aarch64-.+}}
+
+// This test ensures the .cfi_negate_ra_state the RA_SIGN_STATE pseudo register
+// could be set directly set by a DWARF expression and the unwinder handles it
+// correctly. The two directives can't be mixed in one CIE/FDE sqeuence.
+
+#include 
+
+__attribute__((noinline, target("branch-protection=pac-ret+leaf")))
+void bar() {
+  // ".cfi_negate_ra_state" is emitted by the compiler.
+  throw 1;
+}
+
+__attribute__((noinline, target("branch-protection=none")))
+void foo() {
+  // Here a DWARF expression sets RA_SIGN_STATE.
+  // The LR is signed manually and stored on the stack.
+  asm volatile(
+  ".cfi_escape 0x16,"// DW_CFA_val_expression
+"34,"// REG_34(RA_SIGN_STATE)
+ "1,"// expression_length(1)
+"0x31\n" // DW_OP_lit1
+  "add sp, sp, 16\n" // Restore SP's value before the stack frame is
+ // created.
+  "paciasp\n"// Sign the LR.
+  "str lr, [sp, -0x8]\n" // Overwrite LR on the stack.
+  "sub sp, sp, 16\n" // Restore SP's value.
+  );
+  bar();
+  _Exit(-1);
+}
+
+__attribute__((noinline, target("branch-protection=pac-ret")))
+void bazz() {
+  // ".cfi_negate_ra_state" is emitted by the compiler.
+  try {
+foo();
+  } catch (int i) {
+if (i == 1)
+  throw i;
+throw 2;
+  }
+}
+
+int main() {
+  try {
+bazz();
+  } catch (int i) {
+if (i == 1)
+  _Exit(0);
+  }
+  return -1;
+}

diff  --git a/libunwind/src/DwarfInstructions.hpp 
b/libunwind/src/DwarfInstructions.hpp
index ab83b0c87acd..865a48952604 100644
--- a/libunwind/src/DwarfInstructions.hpp
+++ b/libunwind/src/DwarfInstructions.hpp
@@ -72,6 +72,10 @@ class DwarfInstructions {
 assert(0 && "getCFA(): unknown location");
 __builtin_unreachable();
   }
+#if defined(_LIBUNWIND_TARGET_AARCH64)
+  static bool getRA_SIGN_STATE(A &addressSpace, R registers, pint_t cfa,
+   PrologInfo &prolog);
+#endif
 };
 
 template 
@@ -166,6 +170,21 @@ v128 DwarfInstructions::getSavedVectorRegister(
   }
   _LIBUNWIND_ABORT("unsupported restore location for vector register");
 }
+#if defined(_LIBUNWIND_TARGET_AARCH64)
+template 
+bool DwarfInstructions::getRA_SIGN_STATE(A &addressSpace, R registers,
+   pint_t cfa, PrologInfo &prolog) 
{
+  pint_t raSignState;
+  auto regloc = prolog.savedRegisters[UNW_AARCH64_RA_SIGN_STATE];
+  if (regloc.location == CFI_Parser::kRegisterUnused)
+raSignState = regloc.value;
+  else
+raSignState = getSavedRegister(addressSpace, registers, cfa, regloc);
+
+  // Only bit[0] is meaningful.
+  return raSignState & 0x01;
+}
+#endif
 
 template 
 int DwarfInstructions::stepWithDwarf(A &addressSpace, pint_t pc,
@@ -235,7 +254,7 @@ int DwarfInstructions::stepWithDwarf(A &addressSpace, 
pint_t pc,
   // restored. autia1716 is used instead of autia as autia1716 assembles
   // to a NOP on pre-v8.3a architectures.
   if ((R::getArch() == REGISTERS_ARM64) &&
-  

[libunwind] d3a6f57 - [libunwind] Remove -Wsign-conversion warning

2022-05-19 Thread Daniel Kiss via cfe-commits

Author: Daniel Kiss
Date: 2022-05-19T09:41:42+02:00
New Revision: d3a6f5739130409602edac1b6588613c458d7321

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

LOG: [libunwind] Remove -Wsign-conversion warning

Reland after dependent change reland.

Added: 


Modified: 
libunwind/src/DwarfInstructions.hpp

Removed: 




diff  --git a/libunwind/src/DwarfInstructions.hpp 
b/libunwind/src/DwarfInstructions.hpp
index 865a489526047..a4fac5afa9b82 100644
--- a/libunwind/src/DwarfInstructions.hpp
+++ b/libunwind/src/DwarfInstructions.hpp
@@ -177,7 +177,7 @@ bool DwarfInstructions::getRA_SIGN_STATE(A 
&addressSpace, R registers,
   pint_t raSignState;
   auto regloc = prolog.savedRegisters[UNW_AARCH64_RA_SIGN_STATE];
   if (regloc.location == CFI_Parser::kRegisterUnused)
-raSignState = regloc.value;
+raSignState = static_cast(regloc.value);
   else
 raSignState = getSavedRegister(addressSpace, registers, cfa, regloc);
 



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


[clang] AArch64: add __builtin_arm_trap (PR #85054)

2024-03-13 Thread Daniel Kiss via cfe-commits

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

Maybe a line or two in the `clang/docs/LanguageExtensions.rst` would be useful.

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


[clang] [FMV] Emit the resolver along with the default version definition. (PR #84405)

2024-03-14 Thread Daniel Kiss via cfe-commits

DanielKristofKiss wrote:

I'd like to support FMV in existing codebases as lean as possible, so the 
default version attribute would be optional to write as not all 
version/toolchain will support it. smallest possible codebase change to 
introduce multi versioning:

```c
 int foo(void);

+ #ifdef __HAVE_FUNCTION_MULTI_VERSIONING
+ int __attribute__((target_version("feature"))) foo(void);
+ #endif
```

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


[clang] [lld] [llvm] [ARM][AArch64] Change module flags values. (PR #84804)

2024-03-19 Thread Daniel Kiss via cfe-commits

https://github.com/DanielKristofKiss updated 
https://github.com/llvm/llvm-project/pull/84804

>From e0596b2e216c041cfeb63faa8cf6d31a2601934f Mon Sep 17 00:00:00 2001
From: Daniel Kiss 
Date: Fri, 8 Mar 2024 15:06:28 +0100
Subject: [PATCH 1/2] [LLVM] Autoupgrade function attributes from Module
 attributes.

Refactoring #82763 to cache module attributes.
---
 lld/test/ELF/lto/aarch64_inline.ll| 51 +++
 llvm/include/llvm/IR/AutoUpgrade.h|  3 ++
 llvm/lib/IR/AutoUpgrade.cpp   | 47 +
 llvm/lib/Linker/IRMover.cpp   | 10 
 .../AArch64/link-branch-target-enforcement.ll |  3 ++
 .../LTO/AArch64/link-sign-return-address.ll   | 43 
 llvm/test/Linker/link-arm-and-thumb.ll|  6 +--
 7 files changed, 160 insertions(+), 3 deletions(-)
 create mode 100644 lld/test/ELF/lto/aarch64_inline.ll
 create mode 100644 llvm/test/LTO/AArch64/link-sign-return-address.ll

diff --git a/lld/test/ELF/lto/aarch64_inline.ll 
b/lld/test/ELF/lto/aarch64_inline.ll
new file mode 100644
index 00..781c283bc56a3e
--- /dev/null
+++ b/lld/test/ELF/lto/aarch64_inline.ll
@@ -0,0 +1,51 @@
+; REQUIRES: aarch64
+;; Test verifies inlining happens cross module when module flags are upgraded
+;; by the thin-lto linker/IRMover.
+;; Regression test for #82763
+
+; RUN: split-file %s %t
+; RUN: opt -thinlto-bc -thinlto-split-lto-unit -unified-lto %t/foo.s -o 
%t/foo.o
+; RUN: opt -thinlto-bc -thinlto-split-lto-unit -unified-lto %t/main.s -o 
%t/main.o
+; RUN: ld.lld -O2 --lto=thin --entry=main %t/main.o %t/foo.o -o %t/exe
+; RUN: llvm-objdump -d %t/exe | FileCheck %s
+
+
+; CHECK-LABEL:  :
+; CHECK-NEXT: pacibsp
+; CHECK-NEXT: mov w0, #0x22
+; CHECK-NEXT: autibsp
+; CHECK-NEXT: ret
+
+;--- foo.s
+target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
+target triple = "aarch64-unknown-linux-gnu"
+
+define dso_local noundef i32 @foo() local_unnamed_addr #0 {
+entry:
+  ret i32 34
+}
+
+attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn 
memory(none) }
+!llvm.module.flags = !{!0, !1, !2, !3 }
+!0 = !{i32 8, !"branch-target-enforcement", i32 1}
+!1 = !{i32 8, !"sign-return-address", i32 1}
+!2 = !{i32 8, !"sign-return-address-all", i32 1}
+!3 = !{i32 8, !"sign-return-address-with-bkey", i32 1}
+
+;--- main.s
+target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
+target triple = "aarch64-unknown-linux-gnu"
+
+declare i32 @foo();
+
+define i32 @main() {
+entry:
+  %1 = call i32 @foo()
+  ret i32 %1
+}
+
+!llvm.module.flags = !{!0, !1, !2, !3 }
+!0 = !{i32 8, !"branch-target-enforcement", i32 1}
+!1 = !{i32 8, !"sign-return-address", i32 1}
+!2 = !{i32 8, !"sign-return-address-all", i32 1}
+!3 = !{i32 8, !"sign-return-address-with-bkey", i32 1}
diff --git a/llvm/include/llvm/IR/AutoUpgrade.h 
b/llvm/include/llvm/IR/AutoUpgrade.h
index 152f781ffa9b30..1ef32bcb121bec 100644
--- a/llvm/include/llvm/IR/AutoUpgrade.h
+++ b/llvm/include/llvm/IR/AutoUpgrade.h
@@ -88,6 +88,9 @@ namespace llvm {
   /// info. Return true if module is modified.
   bool UpgradeDebugInfo(Module &M);
 
+  /// Copies module attributes to the functions in the module.
+  void CopyModuleAttrToFunctions(Module &M);
+
   /// Check whether a string looks like an old loop attachment tag.
   inline bool mayBeOldLoopAttachmentTag(StringRef Name) {
 return Name.starts_with("llvm.vectorizer.");
diff --git a/llvm/lib/IR/AutoUpgrade.cpp b/llvm/lib/IR/AutoUpgrade.cpp
index be0abb4b71dae2..ed7699c113584b 100644
--- a/llvm/lib/IR/AutoUpgrade.cpp
+++ b/llvm/lib/IR/AutoUpgrade.cpp
@@ -5178,6 +5178,53 @@ void llvm::UpgradeFunctionAttributes(Function &F) {
 Arg.removeAttrs(AttributeFuncs::typeIncompatible(Arg.getType()));
 }
 
+// Check if the module attribute is present and not zero.
+static bool isModuleAttributeSet(Module &M, const StringRef &ModAttr) {
+  const auto *Attr =
+  mdconst::extract_or_null(M.getModuleFlag(ModAttr));
+  return Attr && !Attr->isZero();
+}
+
+// Check if the function attribute is not present and set it.
+static void SetFunctionAttrIfNotSet(Function &F, StringRef FnAttrName,
+StringRef Value) {
+  if (!F.hasFnAttribute(FnAttrName))
+F.addFnAttr(FnAttrName, Value);
+}
+
+void llvm::CopyModuleAttrToFunctions(Module &M) {
+  Triple T(M.getTargetTriple());
+  if (!T.isThumb() && !T.isARM() && !T.isAArch64())
+return;
+
+  StringRef SignTypeValue = "none";
+  if (isModuleAttributeSet(M, "sign-return-address-all"))
+SignTypeValue = "all";
+  else if (isModuleAttributeSet(M, "sign-return-address"))
+SignTypeValue = "non-leaf";
+
+  StringRef BTEValue =
+  isModuleAttributeSet(M, "branch-target-enforcement") ? "true" : "false";
+  StringRef BPPLValue =
+  isModuleAttributeSet(M, "branch-protection-pauth-lr") ? "true" : "false";
+  StringRef GCSValue =
+  isModuleAttributeSet(M, "guarded-control-st

[clang] [Clang][ARM][AArch64] Alway emit protection attributes for functions. (PR #82819)

2024-03-19 Thread Daniel Kiss via cfe-commits


@@ -1398,6 +1400,42 @@ class TargetInfo : public TransferrableTargetInfo,
   }
   llvm_unreachable("Unexpected SignReturnAddressKeyKind");
 }
+
+  public:
+BranchProtectionInfo() = default;

DanielKristofKiss wrote:

We need the default constructor:
e.g 
https://github.com/llvm/llvm-project/blob/main/clang/lib/Sema/SemaDeclAttr.cpp#L3481
 
https://github.com/llvm/llvm-project/blob/main/clang/lib/CodeGen/Targets/ARM.cpp#L144

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


[clang] [Clang][ARM][AArch64] Alway emit protection attributes for functions. (PR #82819)

2024-03-19 Thread Daniel Kiss via cfe-commits

DanielKristofKiss wrote:

> This still has "foo"="true" style function attributes, which are problematic. 
> Is the plan to change that?

Can be changed to just "foo" just makes the function/module attribute importer 
more complicated to handle the old IR.

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


[clang] [llvm] [Clang][ARM][AArch64] Alway emit protection attributes for functions. (PR #82819)

2024-03-19 Thread Daniel Kiss via cfe-commits

https://github.com/DanielKristofKiss updated 
https://github.com/llvm/llvm-project/pull/82819

>From 5973486010ffe387789e8129d53a2b9d0cc4ca69 Mon Sep 17 00:00:00 2001
From: Daniel Kiss 
Date: Mon, 22 Jan 2024 11:33:15 +0100
Subject: [PATCH] Emit attributes for functions always.

Branch protection, sign return address, guarded control stack flags are
only emitted as module flags if not specified per function.

The inliner might inline functions with different set of flags as it
doesn't see the flags.

In case of LTO build the module flags get merged with the `min` rule which means
if one of the modules is not build with PAC/BTI then the features will be turned
off on all functions due to the functions takes the branch-protection and
sign-return-address features from the module flags. The sign-return-address is
function level option therefore it is expected functions from files that are
compiled with -mbranch-protection=pac-ret to be protected but in LTO case this
might not happen. This patch adds the flags to functions in case of an LTO build
therefore they don't need to rely on the module flag.
---
 clang/include/clang/Basic/TargetInfo.h| 44 +--
 clang/lib/CodeGen/Targets/AArch64.cpp | 43 ++
 clang/lib/CodeGen/Targets/ARM.cpp |  8 ++--
 .../CodeGen/aarch64-branch-protection-attr.c  | 26 +--
 .../CodeGen/aarch64-sign-return-address.c | 12 +++--
 clang/test/CodeGen/aarch64-targetattr.c   |  2 +-
 .../CodeGen/arm-branch-protection-attr-1.c| 12 ++---
 .../CodeGen/arm-branch-protection-attr-2.c| 13 --
 .../test/Frontend/arm-branch-protection-lto.c | 22 ++
 .../SelectionDAG/SelectionDAGBuilder.cpp  | 12 +
 llvm/lib/IR/Verifier.cpp  | 21 -
 llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp |  6 +--
 .../AArch64/AArch64MachineFunctionInfo.cpp| 39 +++-
 .../lib/Target/ARM/ARMMachineFunctionInfo.cpp | 22 +-
 llvm/lib/Transforms/IPO/LowerTypeTests.cpp|  6 ++-
 ...ranch-target-enforcement-indirect-calls.ll | 18 
 .../CodeGen/AArch64/bti-branch-relaxation.ll  |  2 +-
 llvm/test/CodeGen/AArch64/kcfi-bti.ll |  7 +--
 ...machine-outliner-2fixup-blr-terminator.mir |  2 +-
 .../CodeGen/AArch64/machine-outliner-bti.mir  |  2 +-
 .../AArch64/machine-outliner-outline-bti.ll   |  4 +-
 .../AArch64/note-gnu-property-pac-bti-0.ll|  2 +-
 .../AArch64/note-gnu-property-pac-bti-4.ll|  4 +-
 .../AArch64/pacbti-llvm-generated-funcs-1.ll  |  4 +-
 .../AArch64/pacbti-llvm-generated-funcs-2.ll  |  4 +-
 .../CodeGen/AArch64/pacbti-module-attrs.ll| 12 ++---
 .../AArch64/patchable-function-entry-bti.ll   | 10 ++---
 .../CodeGen/AArch64/setjmp-bti-outliner.ll| 15 +++
 llvm/test/CodeGen/AArch64/setjmp-bti.ll   |  6 +--
 .../AArch64/sign-return-address-pauth-lr.ll   | 36 +++
 .../CodeGen/AArch64/sign-return-address.ll|  8 ++--
 llvm/test/CodeGen/AArch64/wineh-bti.ll|  7 +--
 llvm/test/CodeGen/AArch64/wineh-pac.ll|  7 +--
 llvm/test/CodeGen/ARM/setjmp-bti-basic.ll |  5 +--
 llvm/test/CodeGen/ARM/setjmp-bti-outliner.ll  |  7 +--
 llvm/test/CodeGen/Thumb2/bti-entry-blocks.ll  |  7 +--
 .../CodeGen/Thumb2/bti-indirect-branches.ll   |  9 ++--
 llvm/test/CodeGen/Thumb2/bti-outliner-1.ll|  9 ++--
 llvm/test/CodeGen/Thumb2/bti-outliner-2.ll| 12 ++---
 .../CodeGen/Thumb2/bti-outliner-cost-2.ll |  6 +--
 .../test/CodeGen/Thumb2/bti-pac-replace-1.mir |  8 +---
 llvm/test/CodeGen/Thumb2/bti-pac-replace-2.ll |  7 +--
 llvm/test/CodeGen/Thumb2/jump-table-bti.ll| 10 ++---
 llvm/test/CodeGen/Thumb2/pacbti-m-basic.ll|  6 +--
 .../Thumb2/pacbti-m-indirect-tail-call.ll |  2 +-
 .../CodeGen/Thumb2/pacbti-m-outliner-1.ll |  2 +-
 .../CodeGen/Thumb2/pacbti-m-outliner-3.ll |  2 +-
 .../CodeGen/Thumb2/pacbti-m-outliner-4.ll |  6 +--
 .../CodeGen/Thumb2/pacbti-m-outliner-5.ll |  4 +-
 .../test/CodeGen/Thumb2/pacbti-m-overalign.ll |  2 +-
 .../test/CodeGen/Thumb2/pacbti-m-stack-arg.ll |  4 +-
 .../Thumb2/pacbti-m-unsupported-arch.ll   |  8 +---
 .../test/CodeGen/Thumb2/pacbti-m-varargs-1.ll |  4 +-
 .../test/CodeGen/Thumb2/pacbti-m-varargs-2.ll |  4 +-
 llvm/test/CodeGen/Thumb2/pacbti-m-vla.ll  |  2 +-
 .../AArch64/link-branch-target-enforcement.ll |  2 +-
 .../Inline/inline-sign-return-address.ll  | 13 +++---
 .../LowerTypeTests/function-arm-thumb.ll  |  2 +-
 .../LowerTypeTests/function-thumb-bti.ll  |  4 +-
 .../Transforms/LowerTypeTests/function.ll |  4 +-
 60 files changed, 277 insertions(+), 312 deletions(-)
 create mode 100644 clang/test/Frontend/arm-branch-protection-lto.c

diff --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index 374595edd2ce4a..5f6f5bbba8e56a 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -32,7 +32,9 @@
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/St

[clang] [llvm] [Clang][ARM][AArch64] Alway emit protection attributes for functions. (PR #82819)

2024-03-19 Thread Daniel Kiss via cfe-commits

DanielKristofKiss wrote:

#83154 merged into this one as no test would pass without that.
todo:
update #83153  with the new semantic.
#84494 and #84804 to be merged into 1 PR  and add support this semantic.

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


[clang] [llvm] [Clang][ARM][AArch64] Alway emit protection attributes for functions. (PR #82819)

2024-03-19 Thread Daniel Kiss via cfe-commits

https://github.com/DanielKristofKiss updated 
https://github.com/llvm/llvm-project/pull/82819

>From 5973486010ffe387789e8129d53a2b9d0cc4ca69 Mon Sep 17 00:00:00 2001
From: Daniel Kiss 
Date: Mon, 22 Jan 2024 11:33:15 +0100
Subject: [PATCH 1/2] Emit attributes for functions always.

Branch protection, sign return address, guarded control stack flags are
only emitted as module flags if not specified per function.

The inliner might inline functions with different set of flags as it
doesn't see the flags.

In case of LTO build the module flags get merged with the `min` rule which means
if one of the modules is not build with PAC/BTI then the features will be turned
off on all functions due to the functions takes the branch-protection and
sign-return-address features from the module flags. The sign-return-address is
function level option therefore it is expected functions from files that are
compiled with -mbranch-protection=pac-ret to be protected but in LTO case this
might not happen. This patch adds the flags to functions in case of an LTO build
therefore they don't need to rely on the module flag.
---
 clang/include/clang/Basic/TargetInfo.h| 44 +--
 clang/lib/CodeGen/Targets/AArch64.cpp | 43 ++
 clang/lib/CodeGen/Targets/ARM.cpp |  8 ++--
 .../CodeGen/aarch64-branch-protection-attr.c  | 26 +--
 .../CodeGen/aarch64-sign-return-address.c | 12 +++--
 clang/test/CodeGen/aarch64-targetattr.c   |  2 +-
 .../CodeGen/arm-branch-protection-attr-1.c| 12 ++---
 .../CodeGen/arm-branch-protection-attr-2.c| 13 --
 .../test/Frontend/arm-branch-protection-lto.c | 22 ++
 .../SelectionDAG/SelectionDAGBuilder.cpp  | 12 +
 llvm/lib/IR/Verifier.cpp  | 21 -
 llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp |  6 +--
 .../AArch64/AArch64MachineFunctionInfo.cpp| 39 +++-
 .../lib/Target/ARM/ARMMachineFunctionInfo.cpp | 22 +-
 llvm/lib/Transforms/IPO/LowerTypeTests.cpp|  6 ++-
 ...ranch-target-enforcement-indirect-calls.ll | 18 
 .../CodeGen/AArch64/bti-branch-relaxation.ll  |  2 +-
 llvm/test/CodeGen/AArch64/kcfi-bti.ll |  7 +--
 ...machine-outliner-2fixup-blr-terminator.mir |  2 +-
 .../CodeGen/AArch64/machine-outliner-bti.mir  |  2 +-
 .../AArch64/machine-outliner-outline-bti.ll   |  4 +-
 .../AArch64/note-gnu-property-pac-bti-0.ll|  2 +-
 .../AArch64/note-gnu-property-pac-bti-4.ll|  4 +-
 .../AArch64/pacbti-llvm-generated-funcs-1.ll  |  4 +-
 .../AArch64/pacbti-llvm-generated-funcs-2.ll  |  4 +-
 .../CodeGen/AArch64/pacbti-module-attrs.ll| 12 ++---
 .../AArch64/patchable-function-entry-bti.ll   | 10 ++---
 .../CodeGen/AArch64/setjmp-bti-outliner.ll| 15 +++
 llvm/test/CodeGen/AArch64/setjmp-bti.ll   |  6 +--
 .../AArch64/sign-return-address-pauth-lr.ll   | 36 +++
 .../CodeGen/AArch64/sign-return-address.ll|  8 ++--
 llvm/test/CodeGen/AArch64/wineh-bti.ll|  7 +--
 llvm/test/CodeGen/AArch64/wineh-pac.ll|  7 +--
 llvm/test/CodeGen/ARM/setjmp-bti-basic.ll |  5 +--
 llvm/test/CodeGen/ARM/setjmp-bti-outliner.ll  |  7 +--
 llvm/test/CodeGen/Thumb2/bti-entry-blocks.ll  |  7 +--
 .../CodeGen/Thumb2/bti-indirect-branches.ll   |  9 ++--
 llvm/test/CodeGen/Thumb2/bti-outliner-1.ll|  9 ++--
 llvm/test/CodeGen/Thumb2/bti-outliner-2.ll| 12 ++---
 .../CodeGen/Thumb2/bti-outliner-cost-2.ll |  6 +--
 .../test/CodeGen/Thumb2/bti-pac-replace-1.mir |  8 +---
 llvm/test/CodeGen/Thumb2/bti-pac-replace-2.ll |  7 +--
 llvm/test/CodeGen/Thumb2/jump-table-bti.ll| 10 ++---
 llvm/test/CodeGen/Thumb2/pacbti-m-basic.ll|  6 +--
 .../Thumb2/pacbti-m-indirect-tail-call.ll |  2 +-
 .../CodeGen/Thumb2/pacbti-m-outliner-1.ll |  2 +-
 .../CodeGen/Thumb2/pacbti-m-outliner-3.ll |  2 +-
 .../CodeGen/Thumb2/pacbti-m-outliner-4.ll |  6 +--
 .../CodeGen/Thumb2/pacbti-m-outliner-5.ll |  4 +-
 .../test/CodeGen/Thumb2/pacbti-m-overalign.ll |  2 +-
 .../test/CodeGen/Thumb2/pacbti-m-stack-arg.ll |  4 +-
 .../Thumb2/pacbti-m-unsupported-arch.ll   |  8 +---
 .../test/CodeGen/Thumb2/pacbti-m-varargs-1.ll |  4 +-
 .../test/CodeGen/Thumb2/pacbti-m-varargs-2.ll |  4 +-
 llvm/test/CodeGen/Thumb2/pacbti-m-vla.ll  |  2 +-
 .../AArch64/link-branch-target-enforcement.ll |  2 +-
 .../Inline/inline-sign-return-address.ll  | 13 +++---
 .../LowerTypeTests/function-arm-thumb.ll  |  2 +-
 .../LowerTypeTests/function-thumb-bti.ll  |  4 +-
 .../Transforms/LowerTypeTests/function.ll |  4 +-
 60 files changed, 277 insertions(+), 312 deletions(-)
 create mode 100644 clang/test/Frontend/arm-branch-protection-lto.c

diff --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index 374595edd2ce4a..5f6f5bbba8e56a 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -32,7 +32,9 @@
 #include "llvm/ADT/StringRef.h"
 #include "llvm/AD

[clang] [llvm] [Clang][ARM][AArch64] Alway emit protection attributes for functions. (PR #82819)

2024-03-20 Thread Daniel Kiss via cfe-commits

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


[clang] [llvm] [Clang][ARM][AArch64] Alway emit protection attributes for functions. (PR #82819)

2024-03-20 Thread Daniel Kiss via cfe-commits


@@ -2314,7 +2314,7 @@ void Verifier::verifyFunctionAttrs(FunctionType *FT, 
AttributeList Attrs,
 
   if (auto A = Attrs.getFnAttr("sign-return-address"); A.isValid()) {
 StringRef S = A.getValueAsString();
-if (S != "none" && S != "all" && S != "non-leaf")

DanielKristofKiss wrote:

This isn't right, to support\import the old format the old values and nothing 
need to accepted here.

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


[clang] [llvm] [Clang][ARM][AArch64] Alway emit protection attributes for functions. (PR #82819)

2024-03-21 Thread Daniel Kiss via cfe-commits

https://github.com/DanielKristofKiss updated 
https://github.com/llvm/llvm-project/pull/82819

>From 28e7b4e10208991790f0c7b1e225831714a47572 Mon Sep 17 00:00:00 2001
From: Daniel Kiss 
Date: Mon, 22 Jan 2024 11:33:15 +0100
Subject: [PATCH] Emit attributes for functions always.

Branch protection, sign return address, guarded control stack flags are
only emitted as module flags if not specified per function.

The inliner might inline functions with different set of flags as it
doesn't see the flags.

In case of LTO build the module flags get merged with the `min` rule which means
if one of the modules is not build with PAC/BTI then the features will be turned
off on all functions due to the functions takes the branch-protection and
sign-return-address features from the module flags. The sign-return-address is
function level option therefore it is expected functions from files that are
compiled with -mbranch-protection=pac-ret to be protected but in LTO case this
might not happen. This patch adds the flags to functions in case of an LTO build
therefore they don't need to rely on the module flag.
---
 clang/include/clang/Basic/TargetInfo.h| 44 +--
 clang/lib/CodeGen/Targets/AArch64.cpp | 43 ++
 clang/lib/CodeGen/Targets/ARM.cpp |  8 ++--
 .../CodeGen/aarch64-branch-protection-attr.c  | 26 +--
 .../CodeGen/aarch64-sign-return-address.c | 12 +++--
 clang/test/CodeGen/aarch64-targetattr.c   |  2 +-
 .../CodeGen/arm-branch-protection-attr-1.c| 12 ++---
 .../CodeGen/arm-branch-protection-attr-2.c| 13 --
 .../test/Frontend/arm-branch-protection-lto.c | 22 ++
 .../SelectionDAG/SelectionDAGBuilder.cpp  | 12 +
 llvm/lib/IR/Verifier.cpp  | 20 -
 llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp |  6 +--
 .../AArch64/AArch64MachineFunctionInfo.cpp| 37 ++--
 .../lib/Target/ARM/ARMMachineFunctionInfo.cpp | 22 +-
 llvm/lib/Transforms/IPO/LowerTypeTests.cpp|  6 ++-
 ...ranch-target-enforcement-indirect-calls.ll | 18 
 .../CodeGen/AArch64/bti-branch-relaxation.ll  |  2 +-
 llvm/test/CodeGen/AArch64/kcfi-bti.ll |  7 +--
 ...machine-outliner-2fixup-blr-terminator.mir |  2 +-
 .../CodeGen/AArch64/machine-outliner-bti.mir  |  2 +-
 .../AArch64/machine-outliner-outline-bti.ll   |  4 +-
 .../AArch64/note-gnu-property-pac-bti-0.ll|  2 +-
 .../AArch64/note-gnu-property-pac-bti-4.ll|  4 +-
 .../AArch64/pacbti-llvm-generated-funcs-1.ll  |  4 +-
 .../AArch64/pacbti-llvm-generated-funcs-2.ll  |  4 +-
 .../CodeGen/AArch64/pacbti-module-attrs.ll| 12 ++---
 .../AArch64/patchable-function-entry-bti.ll   | 10 ++---
 .../CodeGen/AArch64/setjmp-bti-outliner.ll| 15 +++
 llvm/test/CodeGen/AArch64/setjmp-bti.ll   |  6 +--
 .../AArch64/sign-return-address-pauth-lr.ll   | 36 +++
 .../CodeGen/AArch64/sign-return-address.ll|  8 ++--
 llvm/test/CodeGen/AArch64/wineh-bti.ll|  7 +--
 llvm/test/CodeGen/AArch64/wineh-pac.ll|  7 +--
 llvm/test/CodeGen/ARM/setjmp-bti-basic.ll |  5 +--
 llvm/test/CodeGen/ARM/setjmp-bti-outliner.ll  |  7 +--
 llvm/test/CodeGen/Thumb2/bti-entry-blocks.ll  |  7 +--
 .../CodeGen/Thumb2/bti-indirect-branches.ll   |  9 ++--
 llvm/test/CodeGen/Thumb2/bti-outliner-1.ll|  9 ++--
 llvm/test/CodeGen/Thumb2/bti-outliner-2.ll| 12 ++---
 .../CodeGen/Thumb2/bti-outliner-cost-2.ll |  6 +--
 .../test/CodeGen/Thumb2/bti-pac-replace-1.mir |  8 +---
 llvm/test/CodeGen/Thumb2/bti-pac-replace-2.ll |  7 +--
 llvm/test/CodeGen/Thumb2/jump-table-bti.ll| 10 ++---
 llvm/test/CodeGen/Thumb2/pacbti-m-basic.ll|  6 +--
 .../Thumb2/pacbti-m-indirect-tail-call.ll |  2 +-
 .../CodeGen/Thumb2/pacbti-m-outliner-1.ll |  2 +-
 .../CodeGen/Thumb2/pacbti-m-outliner-3.ll |  2 +-
 .../CodeGen/Thumb2/pacbti-m-outliner-4.ll |  6 +--
 .../CodeGen/Thumb2/pacbti-m-outliner-5.ll |  4 +-
 .../test/CodeGen/Thumb2/pacbti-m-overalign.ll |  2 +-
 .../test/CodeGen/Thumb2/pacbti-m-stack-arg.ll |  4 +-
 .../Thumb2/pacbti-m-unsupported-arch.ll   |  8 +---
 .../test/CodeGen/Thumb2/pacbti-m-varargs-1.ll |  4 +-
 .../test/CodeGen/Thumb2/pacbti-m-varargs-2.ll |  4 +-
 llvm/test/CodeGen/Thumb2/pacbti-m-vla.ll  |  2 +-
 .../AArch64/link-branch-target-enforcement.ll |  2 +-
 .../Inline/inline-sign-return-address.ll  | 13 +++---
 .../LowerTypeTests/function-arm-thumb.ll  |  2 +-
 .../LowerTypeTests/function-thumb-bti.ll  |  4 +-
 .../Transforms/LowerTypeTests/function.ll |  4 +-
 llvm/test/Verifier/branch-prot-attrs.ll   |  7 ++-
 61 files changed, 281 insertions(+), 312 deletions(-)
 create mode 100644 clang/test/Frontend/arm-branch-protection-lto.c

diff --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index 374595edd2ce4a..5f6f5bbba8e56a 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -32,7 +32,9 @@

[clang] [lld] [llvm] [ARM][AArch64] BTI,GCS,PAC Module flag update. (PR #86212)

2024-03-21 Thread Daniel Kiss via cfe-commits

https://github.com/DanielKristofKiss created 
https://github.com/llvm/llvm-project/pull/86212

Module flag is used to indicate the feature to be propagated to the function. 
As now the frontend emits all attributes accordingly let's help the auto 
upgrade to only do work when old and new bitcodes are merged.

Depends on #82819 and #86031

>From 33d8277d188f82847d914273be2379151dd33d41 Mon Sep 17 00:00:00 2001
From: Daniel Kiss 
Date: Fri, 8 Mar 2024 15:06:28 +0100
Subject: [PATCH] BTI,GCS,PAC Module flag update.

Module flag is used to indicate the feature to be propagated to the
function. As now the frontend emits all attributes accoringly let's
help the automerger to only do work when old and new bitcodes are
merged.
Autoupgrade function attributes from Module attributes when needed.
---
 clang/lib/CodeGen/CodeGenModule.cpp   |  19 ++--
 .../CodeGen/aarch64-sign-return-address.c |  12 +--
 .../CodeGen/arm-branch-protection-attr-2.c|   8 +-
 .../arm-ignore-branch-protection-option.c |   2 +-
 lld/test/ELF/lto/aarch64_inline.ll|  73 +
 llvm/include/llvm/IR/AutoUpgrade.h|   3 +
 llvm/lib/AsmParser/LLParser.cpp   |   1 +
 llvm/lib/Bitcode/Reader/BitcodeReader.cpp |   2 +
 llvm/lib/IR/AutoUpgrade.cpp   | 100 +
 llvm/lib/Linker/IRMover.cpp   |  10 ++
 llvm/lib/Target/ARM/ARMAsmPrinter.cpp |   2 +-
 llvm/lib/Transforms/IPO/LowerTypeTests.cpp|   2 +-
 .../CodeGen/Thumb2/pacbti-m-outliner-5.ll |   2 +-
 llvm/test/LTO/AArch64/Inputs/foo.ll   |  16 ---
 llvm/test/LTO/AArch64/TestInputs/bar.ll   |  35 ++
 llvm/test/LTO/AArch64/TestInputs/foo.ll   |  38 +++
 llvm/test/LTO/AArch64/TestInputs/old.ll   |  46 
 .../AArch64/link-branch-target-enforcement.ll |   5 +-
 .../LTO/AArch64/link-sign-return-address.ll   | 102 ++
 llvm/test/Linker/link-arm-and-thumb.ll|   6 +-
 20 files changed, 444 insertions(+), 40 deletions(-)
 create mode 100644 lld/test/ELF/lto/aarch64_inline.ll
 delete mode 100644 llvm/test/LTO/AArch64/Inputs/foo.ll
 create mode 100644 llvm/test/LTO/AArch64/TestInputs/bar.ll
 create mode 100644 llvm/test/LTO/AArch64/TestInputs/foo.ll
 create mode 100644 llvm/test/LTO/AArch64/TestInputs/old.ll
 create mode 100644 llvm/test/LTO/AArch64/link-sign-return-address.ll

diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index cb153066b28dd1..1acc0510256268 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -1173,22 +1173,29 @@ void CodeGenModule::Release() {
   "tag-stack-memory-buildattr", 1);
 
   if (T.isARM() || T.isThumb() || T.isAArch64()) {
+// Previously 1 is used and meant for the backed to derive the function
+// attribute form it. 2 now means function attributes already set for all
+// functions in this module, so no need to propagate those from the module
+// flag. Value is only used in case of LTO module merge because the backend
+// will see all required function attribute set already. Value is used
+// before modules got merged. Any posive value means the feature is active
+// and required binary markings need to be emit accordingly.
 if (LangOpts.BranchTargetEnforcement)
   getModule().addModuleFlag(llvm::Module::Min, "branch-target-enforcement",
-1);
+2);
 if (LangOpts.BranchProtectionPAuthLR)
   getModule().addModuleFlag(llvm::Module::Min, 
"branch-protection-pauth-lr",
-1);
+2);
 if (LangOpts.GuardedControlStack)
-  getModule().addModuleFlag(llvm::Module::Min, "guarded-control-stack", 1);
+  getModule().addModuleFlag(llvm::Module::Min, "guarded-control-stack", 2);
 if (LangOpts.hasSignReturnAddress())
-  getModule().addModuleFlag(llvm::Module::Min, "sign-return-address", 1);
+  getModule().addModuleFlag(llvm::Module::Min, "sign-return-address", 2);
 if (LangOpts.isSignReturnAddressScopeAll())
   getModule().addModuleFlag(llvm::Module::Min, "sign-return-address-all",
-1);
+2);
 if (!LangOpts.isSignReturnAddressWithAKey())
   getModule().addModuleFlag(llvm::Module::Min,
-"sign-return-address-with-bkey", 1);
+"sign-return-address-with-bkey", 2);
   }
 
   if (CodeGenOpts.StackClashProtector)
diff --git a/clang/test/CodeGen/aarch64-sign-return-address.c 
b/clang/test/CodeGen/aarch64-sign-return-address.c
index 8bc54b1a56c38c..35c56889e07071 100644
--- a/clang/test/CodeGen/aarch64-sign-return-address.c
+++ b/clang/test/CodeGen/aarch64-sign-return-address.c
@@ -22,17 +22,17 @@
 // NONE-NOT:  !"branch-target-enforcement"
 // ALL-NOT:   !"branch-target-enforcement"
 // PAR

[clang] [lld] [llvm] [ARM][AArch64] Change module flags values. (PR #84804)

2024-03-21 Thread Daniel Kiss via cfe-commits

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


[clang] [llvm] [Clang][ARM][AArch64] Alway emit protection attributes for functions. (PR #82819)

2024-03-21 Thread Daniel Kiss via cfe-commits

DanielKristofKiss wrote:

#86212 Deals with the import of the "true"/"false" values in the attributes.

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


[clang] [lld] [llvm] [ARM][AArch64] Change module flags values. (PR #84804)

2024-03-21 Thread Daniel Kiss via cfe-commits

DanielKristofKiss wrote:

superseded by #86212

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


[clang] [lld] [llvm] [ARM][AArch64] BTI,GCS,PAC Module flag update. (PR #86212)

2024-03-22 Thread Daniel Kiss via cfe-commits

https://github.com/DanielKristofKiss updated 
https://github.com/llvm/llvm-project/pull/86212

>From 33d8277d188f82847d914273be2379151dd33d41 Mon Sep 17 00:00:00 2001
From: Daniel Kiss 
Date: Fri, 8 Mar 2024 15:06:28 +0100
Subject: [PATCH 1/2] BTI,GCS,PAC Module flag update.

Module flag is used to indicate the feature to be propagated to the
function. As now the frontend emits all attributes accoringly let's
help the automerger to only do work when old and new bitcodes are
merged.
Autoupgrade function attributes from Module attributes when needed.
---
 clang/lib/CodeGen/CodeGenModule.cpp   |  19 ++--
 .../CodeGen/aarch64-sign-return-address.c |  12 +--
 .../CodeGen/arm-branch-protection-attr-2.c|   8 +-
 .../arm-ignore-branch-protection-option.c |   2 +-
 lld/test/ELF/lto/aarch64_inline.ll|  73 +
 llvm/include/llvm/IR/AutoUpgrade.h|   3 +
 llvm/lib/AsmParser/LLParser.cpp   |   1 +
 llvm/lib/Bitcode/Reader/BitcodeReader.cpp |   2 +
 llvm/lib/IR/AutoUpgrade.cpp   | 100 +
 llvm/lib/Linker/IRMover.cpp   |  10 ++
 llvm/lib/Target/ARM/ARMAsmPrinter.cpp |   2 +-
 llvm/lib/Transforms/IPO/LowerTypeTests.cpp|   2 +-
 .../CodeGen/Thumb2/pacbti-m-outliner-5.ll |   2 +-
 llvm/test/LTO/AArch64/Inputs/foo.ll   |  16 ---
 llvm/test/LTO/AArch64/TestInputs/bar.ll   |  35 ++
 llvm/test/LTO/AArch64/TestInputs/foo.ll   |  38 +++
 llvm/test/LTO/AArch64/TestInputs/old.ll   |  46 
 .../AArch64/link-branch-target-enforcement.ll |   5 +-
 .../LTO/AArch64/link-sign-return-address.ll   | 102 ++
 llvm/test/Linker/link-arm-and-thumb.ll|   6 +-
 20 files changed, 444 insertions(+), 40 deletions(-)
 create mode 100644 lld/test/ELF/lto/aarch64_inline.ll
 delete mode 100644 llvm/test/LTO/AArch64/Inputs/foo.ll
 create mode 100644 llvm/test/LTO/AArch64/TestInputs/bar.ll
 create mode 100644 llvm/test/LTO/AArch64/TestInputs/foo.ll
 create mode 100644 llvm/test/LTO/AArch64/TestInputs/old.ll
 create mode 100644 llvm/test/LTO/AArch64/link-sign-return-address.ll

diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index cb153066b28dd1..1acc0510256268 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -1173,22 +1173,29 @@ void CodeGenModule::Release() {
   "tag-stack-memory-buildattr", 1);
 
   if (T.isARM() || T.isThumb() || T.isAArch64()) {
+// Previously 1 is used and meant for the backed to derive the function
+// attribute form it. 2 now means function attributes already set for all
+// functions in this module, so no need to propagate those from the module
+// flag. Value is only used in case of LTO module merge because the backend
+// will see all required function attribute set already. Value is used
+// before modules got merged. Any posive value means the feature is active
+// and required binary markings need to be emit accordingly.
 if (LangOpts.BranchTargetEnforcement)
   getModule().addModuleFlag(llvm::Module::Min, "branch-target-enforcement",
-1);
+2);
 if (LangOpts.BranchProtectionPAuthLR)
   getModule().addModuleFlag(llvm::Module::Min, 
"branch-protection-pauth-lr",
-1);
+2);
 if (LangOpts.GuardedControlStack)
-  getModule().addModuleFlag(llvm::Module::Min, "guarded-control-stack", 1);
+  getModule().addModuleFlag(llvm::Module::Min, "guarded-control-stack", 2);
 if (LangOpts.hasSignReturnAddress())
-  getModule().addModuleFlag(llvm::Module::Min, "sign-return-address", 1);
+  getModule().addModuleFlag(llvm::Module::Min, "sign-return-address", 2);
 if (LangOpts.isSignReturnAddressScopeAll())
   getModule().addModuleFlag(llvm::Module::Min, "sign-return-address-all",
-1);
+2);
 if (!LangOpts.isSignReturnAddressWithAKey())
   getModule().addModuleFlag(llvm::Module::Min,
-"sign-return-address-with-bkey", 1);
+"sign-return-address-with-bkey", 2);
   }
 
   if (CodeGenOpts.StackClashProtector)
diff --git a/clang/test/CodeGen/aarch64-sign-return-address.c 
b/clang/test/CodeGen/aarch64-sign-return-address.c
index 8bc54b1a56c38c..35c56889e07071 100644
--- a/clang/test/CodeGen/aarch64-sign-return-address.c
+++ b/clang/test/CodeGen/aarch64-sign-return-address.c
@@ -22,17 +22,17 @@
 // NONE-NOT:  !"branch-target-enforcement"
 // ALL-NOT:   !"branch-target-enforcement"
 // PART-NOT:  !"branch-target-enforcement"
-// BTE:   !{i32 8, !"branch-target-enforcement", i32 1}
+// BTE:   !{i32 8, !"branch-target-enforcement", i32 2}
 // B-KEY-NOT: !"branch-target-enforcement"
 
 // NONE-NOT:  !"sign-return-address"

[libunwind] 23bef7e - [libunwind] Support for leaf function unwinding.

2020-09-16 Thread Daniel Kiss via cfe-commits

Author: Daniel Kiss
Date: 2020-09-16T23:53:36+02:00
New Revision: 23bef7ee9923b1262326981960397e8cd95d6923

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

LOG: [libunwind] Support for leaf function unwinding.

Unwinding leaf function is useful in cases when the backtrace finds a
leaf function for example when it caused a signal.
This patch also add the support for the DW_CFA_undefined because it marks
the end of the frames.

Ryan Prichard provided code for the tests.

Reviewed By: #libunwind, mstorsjo

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

Added: 
libunwind/test/signal_unwind.pass.cpp
libunwind/test/unwind_leaffunction.pass.cpp

Modified: 
libunwind/src/DwarfInstructions.hpp
libunwind/src/DwarfParser.hpp
libunwind/test/lit.site.cfg.in

Removed: 




diff  --git a/libunwind/src/DwarfInstructions.hpp 
b/libunwind/src/DwarfInstructions.hpp
index ee98f538d437..c39cabe1f783 100644
--- a/libunwind/src/DwarfInstructions.hpp
+++ b/libunwind/src/DwarfInstructions.hpp
@@ -93,7 +93,8 @@ typename A::pint_t DwarfInstructions::getSavedRegister(
 
   case CFI_Parser::kRegisterInRegister:
 return registers.getRegister((int)savedReg.value);
-
+  case CFI_Parser::kRegisterUndefined:
+return 0;
   case CFI_Parser::kRegisterUnused:
   case CFI_Parser::kRegisterOffsetFromCFA:
 // FIX ME
@@ -117,6 +118,7 @@ double DwarfInstructions::getSavedFloatRegister(
 
   case CFI_Parser::kRegisterIsExpression:
   case CFI_Parser::kRegisterUnused:
+  case CFI_Parser::kRegisterUndefined:
   case CFI_Parser::kRegisterOffsetFromCFA:
   case CFI_Parser::kRegisterInRegister:
 // FIX ME
@@ -140,6 +142,7 @@ v128 DwarfInstructions::getSavedVectorRegister(
 
   case CFI_Parser::kRegisterIsExpression:
   case CFI_Parser::kRegisterUnused:
+  case CFI_Parser::kRegisterUndefined:
   case CFI_Parser::kRegisterOffsetFromCFA:
   case CFI_Parser::kRegisterInRegister:
 // FIX ME
@@ -190,6 +193,10 @@ int DwarfInstructions::stepWithDwarf(A 
&addressSpace, pint_t pc,
 prolog.savedRegisters[i]));
   else
 return UNW_EBADREG;
+} else if (i == (int)cieInfo.returnAddressRegister) {
+// Leaf function keeps the return address in register and there is 
no
+// explicit intructions how to restore it.
+returnAddress = 
registers.getRegister(cieInfo.returnAddressRegister);
 }
   }
 

diff  --git a/libunwind/src/DwarfParser.hpp b/libunwind/src/DwarfParser.hpp
index c98c4f92a6ad..1ce2cf2943a2 100644
--- a/libunwind/src/DwarfParser.hpp
+++ b/libunwind/src/DwarfParser.hpp
@@ -69,6 +69,7 @@ class CFI_Parser {
   };
   enum RegisterSavedWhere {
 kRegisterUnused,
+kRegisterUndefined,
 kRegisterInCFA,
 kRegisterOffsetFromCFA,
 kRegisterInRegister,
@@ -503,7 +504,7 @@ bool CFI_Parser::parseInstructions(A &addressSpace, 
pint_t instructions,
 "malformed DW_CFA_undefined DWARF unwind, reg too big");
 return false;
   }
-  results->setRegisterLocation(reg, kRegisterUnused, initialState);
+  results->setRegisterLocation(reg, kRegisterUndefined, initialState);
   _LIBUNWIND_TRACE_DWARF("DW_CFA_undefined(reg=%" PRIu64 ")\n", reg);
   break;
 case DW_CFA_same_value:

diff  --git a/libunwind/test/lit.site.cfg.in b/libunwind/test/lit.site.cfg.in
index 8ff770fe29bc..84dae3c2bfb0 100644
--- a/libunwind/test/lit.site.cfg.in
+++ b/libunwind/test/lit.site.cfg.in
@@ -44,6 +44,10 @@ config.test_source_root = 
os.path.join(config.libunwind_src_root, 'test')
 # Allow expanding substitutions that are based on other substitutions
 config.recursiveExpansionLimit = 10
 
+# Make symbols available in the tests.
+config.test_compiler_flags += " -funwind-tables "
+config.test_linker_flags += " -Wl,--export-dynamic "
+
 # Infer the test_exec_root from the build directory.
 config.test_exec_root = os.path.join(config.libunwind_obj_root, 'test')
 

diff  --git a/libunwind/test/signal_unwind.pass.cpp 
b/libunwind/test/signal_unwind.pass.cpp
new file mode 100644
index ..295dd75bb726
--- /dev/null
+++ b/libunwind/test/signal_unwind.pass.cpp
@@ -0,0 +1,44 @@
+// -*- C++ -*-
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+// Ensure that the unwinder can cope with the signal handler.
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+_Unwind_Reason_Code frame_handler(s

[clang] 95e43f8 - [AArch64] Add -mmark-bti-property flag.

2020-09-16 Thread Daniel Kiss via cfe-commits

Author: Daniel Kiss
Date: 2020-09-17T00:24:14+02:00
New Revision: 95e43f84b7b9c61011aece7583c0367297dd67d8

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

LOG: [AArch64] Add -mmark-bti-property flag.

Writing the .note.gnu.property manually is error prone and hard to
maintain in the assembly files.
The -mmark-bti-property is for the assembler to emit the section with the
GNU_PROPERTY_AARCH64_FEATURE_1_BTI. To be used when C/C++ is compiled
with -mbranch-protection=bti.

This patch refactors the .note.gnu.property handling.

Reviewed By: chill, nickdesaulniers

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

Added: 
clang/test/Driver/arm64-markbti.S

Modified: 
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/Clang.cpp
llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
llvm/lib/Target/AArch64/MCTargetDesc/AArch64TargetStreamer.cpp
llvm/lib/Target/AArch64/MCTargetDesc/AArch64TargetStreamer.h

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 5b39ea513b24..d7c2496b8a5d 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2385,6 +2385,9 @@ def mfix_cortex_a53_835769 : Flag<["-"], 
"mfix-cortex-a53-835769">,
 def mno_fix_cortex_a53_835769 : Flag<["-"], "mno-fix-cortex-a53-835769">,
   Group,
   HelpText<"Don't workaround Cortex-A53 erratum 835769 (AArch64 only)">;
+def mmark_bti_property : Flag<["-"], "mmark-bti-property">,
+  Group,
+  HelpText<"Add .note.gnu.property with BTI to assembly files (AArch64 only)">;
 foreach i = {1-31} in
   def ffixed_x#i : Flag<["-"], "ffixed-x"#i>, Group,
 HelpText<"Reserve the x"#i#" register (AArch64/RISC-V only)">;

diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 51056960761d..e13ffe67af89 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -7018,6 +7018,15 @@ void ClangAs::ConstructJob(Compilation &C, const 
JobAction &JA,
 }
 break;
 
+  case llvm::Triple::aarch64:
+  case llvm::Triple::aarch64_32:
+  case llvm::Triple::aarch64_be:
+if (Args.hasArg(options::OPT_mmark_bti_property)) {
+  CmdArgs.push_back("-mllvm");
+  CmdArgs.push_back("-aarch64-mark-bti-property");
+}
+break;
+
   case llvm::Triple::riscv32:
   case llvm::Triple::riscv64:
 AddRISCVTargetArgs(Args, CmdArgs);

diff  --git a/clang/test/Driver/arm64-markbti.S 
b/clang/test/Driver/arm64-markbti.S
new file mode 100644
index ..68c81d31afa3
--- /dev/null
+++ b/clang/test/Driver/arm64-markbti.S
@@ -0,0 +1,24 @@
+// When -mmark-bti-property is passed the generated file object gets BTI 
marking.
+// RUN: %clang -target arm64-linux-none -mmark-bti-property -c -o - %s | 
llvm-readobj -n - | FileCheck -check-prefix=CHECK  -check-prefix=CHECK_GEN %s
+// RUN: %clang -target arm64-linux-none -DNOTE_PRESENT -c %s -o - | 
llvm-readobj -n - | FileCheck -check-prefix=CHECK  -check-prefix=CHECK_PRESET %s
+// RUN: %clang -target arm64-linux-none -mmark-bti-property -DNOTE_PRESENT -c 
%s -o - | llvm-readobj -n - | FileCheck -check-prefix=CHECK  
-check-prefix=CHECK_PRESET %s
+// RUN: %clang -target arm64-linux-none -mmark-bti-property -DNOTE_PRESENT -c 
%s -o - 2>&1 |  FileCheck -check-prefix=CHECK_WARNING %s
+//
+// CHECK_WARNING: The .note.gnu.property is not emitted because it is already 
present.
+// CHECK: Name: .note.gnu.property
+// CHECK: Type: NT_GNU_PROPERTY_TYPE_0
+// CHECK_GEN: aarch64 feature: BTI
+// CHECK_PRESET: aarch64 feature: BTI, PAC
+
+#ifdef NOTE_PRESENT
+  .section .note.gnu.property, "a";
+  .balign 8;
+  .long 4;
+  .long 0x10;
+  .long 0x5
+  .asciz "GNU"
+  .long 0xc000
+  .long 4
+  .long 3
+  .long 0
+#endif

diff  --git a/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp 
b/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
index 8cbd60d74970..30ac7f4c0d2e 100644
--- a/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
+++ b/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
@@ -223,26 +223,9 @@ void AArch64AsmPrinter::emitStartOfAsmFile(Module &M) {
 return;
 
   // Emit a .note.gnu.property section with the flags.
-  MCSection *Cur = OutStreamer->getCurrentSectionOnly();
-  MCSection *Nt = MMI->getContext().getELFSection(
-  ".note.gnu.property", ELF::SHT_NOTE, ELF::SHF_ALLOC);
-  OutStreamer->SwitchSection(Nt);
-
-  // Emit the note header.
-  emitAlignment(Align(8));
-  OutStreamer->emitInt32(4); // data size for "GNU\0"
-  OutStreamer->emitInt32(4 * 4); // Elf_Prop size
-  OutStreamer->emitInt32(ELF::NT_GNU_PROPERTY_TYPE_0);
-  OutStreamer->emitBytes(StringRef("GNU", 4)); // note name
-
-  // Emit the PAC/BTI properties.
-  OutStreamer->emitInt32(ELF::GNU_PROPERTY_AARCH64_FEATURE_1_

[clang] f70baaf - [AArch64] Add -mmark-bti-property flag.

2020-09-16 Thread Daniel Kiss via cfe-commits

Author: Daniel Kiss
Date: 2020-09-17T01:18:36+02:00
New Revision: f70baaf71f62ba8623b3522345527271add74f6b

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

LOG: [AArch64] Add -mmark-bti-property flag.

Writing the .note.gnu.property manually is error prone and hard to
maintain in the assembly files.
The -mmark-bti-property is for the assembler to emit the section with the
GNU_PROPERTY_AARCH64_FEATURE_1_BTI. To be used when C/C++ is compiled
with -mbranch-protection=bti.

This patch refactors the .note.gnu.property handling.

Reviewed By: chill, nickdesaulniers

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

Reland with test dependency on aarch64 target.

Added: 
clang/test/Driver/arm64-markbti.S

Modified: 
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/Clang.cpp
llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
llvm/lib/Target/AArch64/MCTargetDesc/AArch64TargetStreamer.cpp
llvm/lib/Target/AArch64/MCTargetDesc/AArch64TargetStreamer.h

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 5b39ea513b24..d7c2496b8a5d 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2385,6 +2385,9 @@ def mfix_cortex_a53_835769 : Flag<["-"], 
"mfix-cortex-a53-835769">,
 def mno_fix_cortex_a53_835769 : Flag<["-"], "mno-fix-cortex-a53-835769">,
   Group,
   HelpText<"Don't workaround Cortex-A53 erratum 835769 (AArch64 only)">;
+def mmark_bti_property : Flag<["-"], "mmark-bti-property">,
+  Group,
+  HelpText<"Add .note.gnu.property with BTI to assembly files (AArch64 only)">;
 foreach i = {1-31} in
   def ffixed_x#i : Flag<["-"], "ffixed-x"#i>, Group,
 HelpText<"Reserve the x"#i#" register (AArch64/RISC-V only)">;

diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 51056960761d..e13ffe67af89 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -7018,6 +7018,15 @@ void ClangAs::ConstructJob(Compilation &C, const 
JobAction &JA,
 }
 break;
 
+  case llvm::Triple::aarch64:
+  case llvm::Triple::aarch64_32:
+  case llvm::Triple::aarch64_be:
+if (Args.hasArg(options::OPT_mmark_bti_property)) {
+  CmdArgs.push_back("-mllvm");
+  CmdArgs.push_back("-aarch64-mark-bti-property");
+}
+break;
+
   case llvm::Triple::riscv32:
   case llvm::Triple::riscv64:
 AddRISCVTargetArgs(Args, CmdArgs);

diff  --git a/clang/test/Driver/arm64-markbti.S 
b/clang/test/Driver/arm64-markbti.S
new file mode 100644
index ..8eeed74810d2
--- /dev/null
+++ b/clang/test/Driver/arm64-markbti.S
@@ -0,0 +1,26 @@
+// REQUIRES: aarch64-registered-target
+
+// When -mmark-bti-property is passed the generated file object gets BTI 
marking.
+// RUN: %clang -target arm64-linux-none -mmark-bti-property -c -o - %s | 
llvm-readobj -n - | FileCheck -check-prefix=CHECK  -check-prefix=CHECK_GEN %s
+// RUN: %clang -target arm64-linux-none -DNOTE_PRESENT -c %s -o - | 
llvm-readobj -n - | FileCheck -check-prefix=CHECK  -check-prefix=CHECK_PRESET %s
+// RUN: %clang -target arm64-linux-none -mmark-bti-property -DNOTE_PRESENT -c 
%s -o - | llvm-readobj -n - | FileCheck -check-prefix=CHECK  
-check-prefix=CHECK_PRESET %s
+// RUN: %clang -target arm64-linux-none -mmark-bti-property -DNOTE_PRESENT -c 
%s -o - 2>&1 |  FileCheck -check-prefix=CHECK_WARNING %s
+//
+// CHECK_WARNING: The .note.gnu.property is not emitted because it is already 
present.
+// CHECK: Name: .note.gnu.property
+// CHECK: Type: NT_GNU_PROPERTY_TYPE_0
+// CHECK_GEN: aarch64 feature: BTI
+// CHECK_PRESET: aarch64 feature: BTI, PAC
+
+#ifdef NOTE_PRESENT
+  .section .note.gnu.property, "a";
+  .balign 8;
+  .long 4;
+  .long 0x10;
+  .long 0x5
+  .asciz "GNU"
+  .long 0xc000
+  .long 4
+  .long 3
+  .long 0
+#endif

diff  --git a/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp 
b/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
index 8cbd60d74970..30ac7f4c0d2e 100644
--- a/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
+++ b/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
@@ -223,26 +223,9 @@ void AArch64AsmPrinter::emitStartOfAsmFile(Module &M) {
 return;
 
   // Emit a .note.gnu.property section with the flags.
-  MCSection *Cur = OutStreamer->getCurrentSectionOnly();
-  MCSection *Nt = MMI->getContext().getELFSection(
-  ".note.gnu.property", ELF::SHT_NOTE, ELF::SHF_ALLOC);
-  OutStreamer->SwitchSection(Nt);
-
-  // Emit the note header.
-  emitAlignment(Align(8));
-  OutStreamer->emitInt32(4); // data size for "GNU\0"
-  OutStreamer->emitInt32(4 * 4); // Elf_Prop size
-  OutStreamer->emitInt32(ELF::NT_GNU_PROPERTY_TYPE_0);
-  OutStreamer->emitBytes(StringRef("GNU", 4)); // note name
-
-  // E

[clang] 60e244f - Revert "[AArch64] Add -mmark-bti-property flag."

2020-09-16 Thread Daniel Kiss via cfe-commits

Author: Daniel Kiss
Date: 2020-09-17T01:17:23+02:00
New Revision: 60e244f82c1f97c1b7d65c06d2b0b4f634f8d696

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

LOG: Revert "[AArch64] Add -mmark-bti-property flag."

This reverts commit 95e43f84b7b9c61011aece7583c0367297dd67d8.

Added: 


Modified: 
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/Clang.cpp
llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
llvm/lib/Target/AArch64/MCTargetDesc/AArch64TargetStreamer.cpp
llvm/lib/Target/AArch64/MCTargetDesc/AArch64TargetStreamer.h

Removed: 
clang/test/Driver/arm64-markbti.S



diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index d7c2496b8a5d..5b39ea513b24 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2385,9 +2385,6 @@ def mfix_cortex_a53_835769 : Flag<["-"], 
"mfix-cortex-a53-835769">,
 def mno_fix_cortex_a53_835769 : Flag<["-"], "mno-fix-cortex-a53-835769">,
   Group,
   HelpText<"Don't workaround Cortex-A53 erratum 835769 (AArch64 only)">;
-def mmark_bti_property : Flag<["-"], "mmark-bti-property">,
-  Group,
-  HelpText<"Add .note.gnu.property with BTI to assembly files (AArch64 only)">;
 foreach i = {1-31} in
   def ffixed_x#i : Flag<["-"], "ffixed-x"#i>, Group,
 HelpText<"Reserve the x"#i#" register (AArch64/RISC-V only)">;

diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index e13ffe67af89..51056960761d 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -7018,15 +7018,6 @@ void ClangAs::ConstructJob(Compilation &C, const 
JobAction &JA,
 }
 break;
 
-  case llvm::Triple::aarch64:
-  case llvm::Triple::aarch64_32:
-  case llvm::Triple::aarch64_be:
-if (Args.hasArg(options::OPT_mmark_bti_property)) {
-  CmdArgs.push_back("-mllvm");
-  CmdArgs.push_back("-aarch64-mark-bti-property");
-}
-break;
-
   case llvm::Triple::riscv32:
   case llvm::Triple::riscv64:
 AddRISCVTargetArgs(Args, CmdArgs);

diff  --git a/clang/test/Driver/arm64-markbti.S 
b/clang/test/Driver/arm64-markbti.S
deleted file mode 100644
index 68c81d31afa3..
--- a/clang/test/Driver/arm64-markbti.S
+++ /dev/null
@@ -1,24 +0,0 @@
-// When -mmark-bti-property is passed the generated file object gets BTI 
marking.
-// RUN: %clang -target arm64-linux-none -mmark-bti-property -c -o - %s | 
llvm-readobj -n - | FileCheck -check-prefix=CHECK  -check-prefix=CHECK_GEN %s
-// RUN: %clang -target arm64-linux-none -DNOTE_PRESENT -c %s -o - | 
llvm-readobj -n - | FileCheck -check-prefix=CHECK  -check-prefix=CHECK_PRESET %s
-// RUN: %clang -target arm64-linux-none -mmark-bti-property -DNOTE_PRESENT -c 
%s -o - | llvm-readobj -n - | FileCheck -check-prefix=CHECK  
-check-prefix=CHECK_PRESET %s
-// RUN: %clang -target arm64-linux-none -mmark-bti-property -DNOTE_PRESENT -c 
%s -o - 2>&1 |  FileCheck -check-prefix=CHECK_WARNING %s
-//
-// CHECK_WARNING: The .note.gnu.property is not emitted because it is already 
present.
-// CHECK: Name: .note.gnu.property
-// CHECK: Type: NT_GNU_PROPERTY_TYPE_0
-// CHECK_GEN: aarch64 feature: BTI
-// CHECK_PRESET: aarch64 feature: BTI, PAC
-
-#ifdef NOTE_PRESENT
-  .section .note.gnu.property, "a";
-  .balign 8;
-  .long 4;
-  .long 0x10;
-  .long 0x5
-  .asciz "GNU"
-  .long 0xc000
-  .long 4
-  .long 3
-  .long 0
-#endif

diff  --git a/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp 
b/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
index 30ac7f4c0d2e..8cbd60d74970 100644
--- a/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
+++ b/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
@@ -223,9 +223,26 @@ void AArch64AsmPrinter::emitStartOfAsmFile(Module &M) {
 return;
 
   // Emit a .note.gnu.property section with the flags.
-  if (auto *TS = static_cast(
-  OutStreamer->getTargetStreamer()))
-TS->emitNoteSection(Flags);
+  MCSection *Cur = OutStreamer->getCurrentSectionOnly();
+  MCSection *Nt = MMI->getContext().getELFSection(
+  ".note.gnu.property", ELF::SHT_NOTE, ELF::SHF_ALLOC);
+  OutStreamer->SwitchSection(Nt);
+
+  // Emit the note header.
+  emitAlignment(Align(8));
+  OutStreamer->emitInt32(4); // data size for "GNU\0"
+  OutStreamer->emitInt32(4 * 4); // Elf_Prop size
+  OutStreamer->emitInt32(ELF::NT_GNU_PROPERTY_TYPE_0);
+  OutStreamer->emitBytes(StringRef("GNU", 4)); // note name
+
+  // Emit the PAC/BTI properties.
+  OutStreamer->emitInt32(ELF::GNU_PROPERTY_AARCH64_FEATURE_1_AND);
+  OutStreamer->emitInt32(4); // data size
+  OutStreamer->emitInt32(Flags); // data
+  OutStreamer->emitInt32(0); // pad
+
+  OutStreamer->endSection(Nt);
+  OutStreamer->SwitchSection(Cur);
 }
 
 void AArch64AsmPrinter::

[libunwind] 5831adb - Revert "[libunwind] Support for leaf function unwinding."

2020-09-18 Thread Daniel Kiss via cfe-commits

Author: Daniel Kiss
Date: 2020-09-18T11:37:54+02:00
New Revision: 5831adb8c38f3fd1b17ff52984c514fc32e893f6

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

LOG: Revert "[libunwind] Support for leaf function unwinding."

This reverts commit 23bef7ee9923b1262326981960397e8cd95d6923.

Added: 


Modified: 
libunwind/src/DwarfInstructions.hpp
libunwind/src/DwarfParser.hpp
libunwind/test/lit.site.cfg.in

Removed: 
libunwind/test/signal_unwind.pass.cpp
libunwind/test/unwind_leaffunction.pass.cpp



diff  --git a/libunwind/src/DwarfInstructions.hpp 
b/libunwind/src/DwarfInstructions.hpp
index c39cabe1f783..ee98f538d437 100644
--- a/libunwind/src/DwarfInstructions.hpp
+++ b/libunwind/src/DwarfInstructions.hpp
@@ -93,8 +93,7 @@ typename A::pint_t DwarfInstructions::getSavedRegister(
 
   case CFI_Parser::kRegisterInRegister:
 return registers.getRegister((int)savedReg.value);
-  case CFI_Parser::kRegisterUndefined:
-return 0;
+
   case CFI_Parser::kRegisterUnused:
   case CFI_Parser::kRegisterOffsetFromCFA:
 // FIX ME
@@ -118,7 +117,6 @@ double DwarfInstructions::getSavedFloatRegister(
 
   case CFI_Parser::kRegisterIsExpression:
   case CFI_Parser::kRegisterUnused:
-  case CFI_Parser::kRegisterUndefined:
   case CFI_Parser::kRegisterOffsetFromCFA:
   case CFI_Parser::kRegisterInRegister:
 // FIX ME
@@ -142,7 +140,6 @@ v128 DwarfInstructions::getSavedVectorRegister(
 
   case CFI_Parser::kRegisterIsExpression:
   case CFI_Parser::kRegisterUnused:
-  case CFI_Parser::kRegisterUndefined:
   case CFI_Parser::kRegisterOffsetFromCFA:
   case CFI_Parser::kRegisterInRegister:
 // FIX ME
@@ -193,10 +190,6 @@ int DwarfInstructions::stepWithDwarf(A 
&addressSpace, pint_t pc,
 prolog.savedRegisters[i]));
   else
 return UNW_EBADREG;
-} else if (i == (int)cieInfo.returnAddressRegister) {
-// Leaf function keeps the return address in register and there is 
no
-// explicit intructions how to restore it.
-returnAddress = 
registers.getRegister(cieInfo.returnAddressRegister);
 }
   }
 

diff  --git a/libunwind/src/DwarfParser.hpp b/libunwind/src/DwarfParser.hpp
index 86c0522afd3f..fb943edfdb7e 100644
--- a/libunwind/src/DwarfParser.hpp
+++ b/libunwind/src/DwarfParser.hpp
@@ -69,7 +69,6 @@ class CFI_Parser {
   };
   enum RegisterSavedWhere {
 kRegisterUnused,
-kRegisterUndefined,
 kRegisterInCFA,
 kRegisterOffsetFromCFA,
 kRegisterInRegister,
@@ -506,7 +505,7 @@ bool CFI_Parser::parseInstructions(A &addressSpace, 
pint_t instructions,
 "malformed DW_CFA_undefined DWARF unwind, reg too big");
 return false;
   }
-  results->setRegisterLocation(reg, kRegisterUndefined, initialState);
+  results->setRegisterLocation(reg, kRegisterUnused, initialState);
   _LIBUNWIND_TRACE_DWARF("DW_CFA_undefined(reg=%" PRIu64 ")\n", reg);
   break;
 case DW_CFA_same_value:

diff  --git a/libunwind/test/lit.site.cfg.in b/libunwind/test/lit.site.cfg.in
index 84dae3c2bfb0..8ff770fe29bc 100644
--- a/libunwind/test/lit.site.cfg.in
+++ b/libunwind/test/lit.site.cfg.in
@@ -44,10 +44,6 @@ config.test_source_root = 
os.path.join(config.libunwind_src_root, 'test')
 # Allow expanding substitutions that are based on other substitutions
 config.recursiveExpansionLimit = 10
 
-# Make symbols available in the tests.
-config.test_compiler_flags += " -funwind-tables "
-config.test_linker_flags += " -Wl,--export-dynamic "
-
 # Infer the test_exec_root from the build directory.
 config.test_exec_root = os.path.join(config.libunwind_obj_root, 'test')
 

diff  --git a/libunwind/test/signal_unwind.pass.cpp 
b/libunwind/test/signal_unwind.pass.cpp
deleted file mode 100644
index 295dd75bb726..
--- a/libunwind/test/signal_unwind.pass.cpp
+++ /dev/null
@@ -1,44 +0,0 @@
-// -*- C++ -*-
-//===--===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===--===//
-
-// Ensure that the unwinder can cope with the signal handler.
-
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-
-_Unwind_Reason_Code frame_handler(struct _Unwind_Context* ctx, void* arg) {
-  (void)arg;
-  Dl_info info = { 0, 0, 0, 0 };
-  assert(dladdr((void*)_Unwind_GetIP(ctx), &info));
-
-  // Unwind util the main is reached, above frames deeped on the platfrom and 
architecture.
-  if(info.dli_sname && !strcmp("main", 

[libunwind] 22b615a - [libunwind] Support for leaf function unwinding.

2020-09-18 Thread Daniel Kiss via cfe-commits

Author: Daniel Kiss
Date: 2020-09-18T15:09:42+02:00
New Revision: 22b615a96593f13109a27cabfd1764ec4f558c7a

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

LOG: [libunwind] Support for leaf function unwinding.

Unwinding leaf function is useful in cases when the backtrace finds a
leaf function for example when it caused a signal.
This patch also add the support for the DW_CFA_undefined because it marks
the end of the frames.

Ryan Prichard provided code for the tests.

Reviewed By: #libunwind, mstorsjo

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

Reland with limit the test to the x86_64-linux target.

Added: 
libunwind/test/signal_unwind.pass.cpp
libunwind/test/unwind_leaffunction.pass.cpp

Modified: 
libunwind/src/DwarfInstructions.hpp
libunwind/src/DwarfParser.hpp
libunwind/test/lit.site.cfg.in

Removed: 




diff  --git a/libunwind/src/DwarfInstructions.hpp 
b/libunwind/src/DwarfInstructions.hpp
index ee98f538d437..c39cabe1f783 100644
--- a/libunwind/src/DwarfInstructions.hpp
+++ b/libunwind/src/DwarfInstructions.hpp
@@ -93,7 +93,8 @@ typename A::pint_t DwarfInstructions::getSavedRegister(
 
   case CFI_Parser::kRegisterInRegister:
 return registers.getRegister((int)savedReg.value);
-
+  case CFI_Parser::kRegisterUndefined:
+return 0;
   case CFI_Parser::kRegisterUnused:
   case CFI_Parser::kRegisterOffsetFromCFA:
 // FIX ME
@@ -117,6 +118,7 @@ double DwarfInstructions::getSavedFloatRegister(
 
   case CFI_Parser::kRegisterIsExpression:
   case CFI_Parser::kRegisterUnused:
+  case CFI_Parser::kRegisterUndefined:
   case CFI_Parser::kRegisterOffsetFromCFA:
   case CFI_Parser::kRegisterInRegister:
 // FIX ME
@@ -140,6 +142,7 @@ v128 DwarfInstructions::getSavedVectorRegister(
 
   case CFI_Parser::kRegisterIsExpression:
   case CFI_Parser::kRegisterUnused:
+  case CFI_Parser::kRegisterUndefined:
   case CFI_Parser::kRegisterOffsetFromCFA:
   case CFI_Parser::kRegisterInRegister:
 // FIX ME
@@ -190,6 +193,10 @@ int DwarfInstructions::stepWithDwarf(A 
&addressSpace, pint_t pc,
 prolog.savedRegisters[i]));
   else
 return UNW_EBADREG;
+} else if (i == (int)cieInfo.returnAddressRegister) {
+// Leaf function keeps the return address in register and there is 
no
+// explicit intructions how to restore it.
+returnAddress = 
registers.getRegister(cieInfo.returnAddressRegister);
 }
   }
 

diff  --git a/libunwind/src/DwarfParser.hpp b/libunwind/src/DwarfParser.hpp
index fb943edfdb7e..86c0522afd3f 100644
--- a/libunwind/src/DwarfParser.hpp
+++ b/libunwind/src/DwarfParser.hpp
@@ -69,6 +69,7 @@ class CFI_Parser {
   };
   enum RegisterSavedWhere {
 kRegisterUnused,
+kRegisterUndefined,
 kRegisterInCFA,
 kRegisterOffsetFromCFA,
 kRegisterInRegister,
@@ -505,7 +506,7 @@ bool CFI_Parser::parseInstructions(A &addressSpace, 
pint_t instructions,
 "malformed DW_CFA_undefined DWARF unwind, reg too big");
 return false;
   }
-  results->setRegisterLocation(reg, kRegisterUnused, initialState);
+  results->setRegisterLocation(reg, kRegisterUndefined, initialState);
   _LIBUNWIND_TRACE_DWARF("DW_CFA_undefined(reg=%" PRIu64 ")\n", reg);
   break;
 case DW_CFA_same_value:

diff  --git a/libunwind/test/lit.site.cfg.in b/libunwind/test/lit.site.cfg.in
index 8ff770fe29bc..84dae3c2bfb0 100644
--- a/libunwind/test/lit.site.cfg.in
+++ b/libunwind/test/lit.site.cfg.in
@@ -44,6 +44,10 @@ config.test_source_root = 
os.path.join(config.libunwind_src_root, 'test')
 # Allow expanding substitutions that are based on other substitutions
 config.recursiveExpansionLimit = 10
 
+# Make symbols available in the tests.
+config.test_compiler_flags += " -funwind-tables "
+config.test_linker_flags += " -Wl,--export-dynamic "
+
 # Infer the test_exec_root from the build directory.
 config.test_exec_root = os.path.join(config.libunwind_obj_root, 'test')
 

diff  --git a/libunwind/test/signal_unwind.pass.cpp 
b/libunwind/test/signal_unwind.pass.cpp
new file mode 100644
index ..5955c1b14055
--- /dev/null
+++ b/libunwind/test/signal_unwind.pass.cpp
@@ -0,0 +1,45 @@
+// -*- C++ -*-
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+// Ensure that the unwinder can cope with the signal handler.
+// REQUIRES: x86_64-linux
+
+#include 
+#include 
+#include 
+#include 
+#include 

[libunwind] e7b8d37 - [libunwind] LIBUNWIND_REMEMBER_HEAP_ALLOC to cmake.

2020-11-11 Thread Daniel Kiss via cfe-commits

Author: Daniel Kiss
Date: 2020-11-11T11:21:17+01:00
New Revision: e7b8d3776f36beb9b73cd0f7c81fdc4b832b6df3

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

LOG: [libunwind] LIBUNWIND_REMEMBER_HEAP_ALLOC to cmake.

Missed it originally in https://reviews.llvm.org/D85005.

Reviewed By: gargaroff

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

Added: 


Modified: 
libunwind/CMakeLists.txt

Removed: 




diff  --git a/libunwind/CMakeLists.txt b/libunwind/CMakeLists.txt
index d7e13b78a9c9..e344263173b0 100644
--- a/libunwind/CMakeLists.txt
+++ b/libunwind/CMakeLists.txt
@@ -69,6 +69,7 @@ option(LIBUNWIND_USE_COMPILER_RT "Use compiler-rt instead of 
libgcc" OFF)
 option(LIBUNWIND_INCLUDE_DOCS "Build the libunwind documentation." 
${LLVM_INCLUDE_DOCS})
 option(LIBUNWIND_IS_BAREMETAL "Build libunwind for baremetal targets." OFF)
 option(LIBUNWIND_USE_FRAME_HEADER_CACHE "Cache frame headers for unwinding. 
Requires locking dl_iterate_phdr." OFF)
+option(LIBUNWIND_REMEMBER_HEAP_ALLOC "Use heap instead of the stack for 
.cfi_remember_state." OFF)
 
 set(LIBUNWIND_LIBDIR_SUFFIX "${LLVM_LIBDIR_SUFFIX}" CACHE STRING
 "Define suffix of library directory name (32/64)")
@@ -312,6 +313,10 @@ if(LIBUNWIND_USE_FRAME_HEADER_CACHE)
   add_compile_definitions(_LIBUNWIND_USE_FRAME_HEADER_CACHE)
 endif()
 
+if(LIBUNWIND_REMEMBER_HEAP_ALLOC)
+  add_compile_definitions(_LIBUNWIND_REMEMBER_HEAP_ALLOC)
+endif()
+
 # This is the _ONLY_ place where add_definitions is called.
 if (MSVC)
   add_definitions(-D_CRT_SECURE_NO_WARNINGS)



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


[libunwind] f34ae1b - [AArch64] Add v8.5 Branch Target Identification support.

2020-09-29 Thread Daniel Kiss via cfe-commits

Author: Daniel Kiss
Date: 2020-09-29T15:51:01+02:00
New Revision: f34ae1b9de68152de037fd3e394d196b997c4296

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

LOG: [AArch64] Add v8.5 Branch Target Identification support.

The .note.gnu.property must be in the assembly file to indicate the
support for BTI otherwise BTI will be disabled for the whole library.
__unw_getcontext and libunwind::Registers_arm64::jumpto() may be called
indirectly therefore they should start with a landing pad.

Reviewed By: tamas.petz, #libunwind, compnerd

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

Added: 


Modified: 
libunwind/src/assembly.h

Removed: 




diff  --git a/libunwind/src/assembly.h b/libunwind/src/assembly.h
index 4cf179e13edc..3b1e6e6d01d7 100644
--- a/libunwind/src/assembly.h
+++ b/libunwind/src/assembly.h
@@ -48,6 +48,24 @@
 #define PPC64_OPD2
 #endif
 
+#if defined(__ARM_FEATURE_BTI_DEFAULT)
+  .pushsection ".note.gnu.property", "a" SEPARATOR 
\
+  .balign 8 SEPARATOR  
\
+  .long 4 SEPARATOR
\
+  .long 0x10 SEPARATOR 
\
+  .long 0x5 SEPARATOR  
\
+  .asciz "GNU" SEPARATOR   
\
+  .long 0xc000 SEPARATOR /* GNU_PROPERTY_AARCH64_FEATURE_1_AND */  
\
+  .long 4 SEPARATOR
\
+  .long 3 SEPARATOR /* GNU_PROPERTY_AARCH64_FEATURE_1_BTI AND */   
\
+/* GNU_PROPERTY_AARCH64_FEATURE_1_PAC */   
\
+  .long 0 SEPARATOR
\
+  .popsection SEPARATOR
+#define AARCH64_BTI  bti c
+#else
+#define AARCH64_BTI
+#endif
+
 #define GLUE2(a, b) a ## b
 #define GLUE(a, b) GLUE2(a, b)
 #define SYMBOL_NAME(name) GLUE(__USER_LABEL_PREFIX__, name)
@@ -144,7 +162,8 @@
   SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR  
\
   PPC64_OPD1   
\
   SYMBOL_NAME(name):   
\
-  PPC64_OPD2
+  PPC64_OPD2   
\
+  AARCH64_BTI
 
 #if defined(__arm__)
 #if !defined(__ARM_ARCH)



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


[libunwind] 05598e3 - [libunwind] Fix linker flag handling in the tests.

2020-10-29 Thread Daniel Kiss via cfe-commits

Author: Daniel Kiss
Date: 2020-10-29T14:02:44+01:00
New Revision: 05598e3d3047cf028cc3e61f3268ff7d999e5f26

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

LOG: [libunwind] Fix linker flag handling in the tests.

--export-dynamic is not always available on all targets.
-funwind-tables was a duplicate in the lit.site.cfg.in.

Reviewed By: ldionne

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

Added: 


Modified: 
libunwind/test/libunwind/test/config.py
libunwind/test/lit.site.cfg.in

Removed: 




diff  --git a/libunwind/test/libunwind/test/config.py 
b/libunwind/test/libunwind/test/config.py
index 977f9a0fb3f9..9231860fc622 100644
--- a/libunwind/test/libunwind/test/config.py
+++ b/libunwind/test/libunwind/test/config.py
@@ -43,6 +43,9 @@ def configure_compile_flags(self):
 # Stack unwinding tests need unwinding tables and these are not
 # generated by default on all Targets.
 self.cxx.compile_flags += ['-funwind-tables']
+# Make symbols available in the tests.
+if 'linux' in self.config.target_triple:
+self.cxx.link_flags += ['-Wl,--export-dynamic']
 if not self.get_lit_bool('enable_threads', True):
 self.cxx.compile_flags += ['-D_LIBUNWIND_HAS_NO_THREADS']
 self.config.available_features.add('libunwind-no-threads')

diff  --git a/libunwind/test/lit.site.cfg.in b/libunwind/test/lit.site.cfg.in
index 84dae3c2bfb0..8ff770fe29bc 100644
--- a/libunwind/test/lit.site.cfg.in
+++ b/libunwind/test/lit.site.cfg.in
@@ -44,10 +44,6 @@ config.test_source_root = 
os.path.join(config.libunwind_src_root, 'test')
 # Allow expanding substitutions that are based on other substitutions
 config.recursiveExpansionLimit = 10
 
-# Make symbols available in the tests.
-config.test_compiler_flags += " -funwind-tables "
-config.test_linker_flags += " -Wl,--export-dynamic "
-
 # Infer the test_exec_root from the build directory.
 config.test_exec_root = os.path.join(config.libunwind_obj_root, 'test')
 



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


[libunwind] 1d7786d - [libunwind] Support DW_CFA_remember/restore_state without heap allocation.

2020-10-30 Thread Daniel Kiss via cfe-commits

Author: Daniel Kiss
Date: 2020-10-30T17:45:20+01:00
New Revision: 1d7786d45f48b4793baf4e4b903c4476f56ffc94

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

LOG: [libunwind] Support DW_CFA_remember/restore_state without heap allocation.

This patch just reorganises the code to make possible to use alloca
instead of malloc. This makes possible to use 
`.cfi_remember_state`/`.cfi_restore_state` on
platforms without heap allocation.
Also it will be safe to backtrace/unwind faults related to the allocator behind 
malloc.
`_LIBUNWIND_REMEMBER_HEAP_ALLOC ` option reenables the heap usage for 
`.cfi_remember_state`/`.cfi_restore_state`.
Define _LIBUNWIND_REMEMBER_STACK_ALLOC to force stack allocation.

Reviewed By: #libunwind, mstorsjo

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

Added: 


Modified: 
libunwind/src/DwarfParser.hpp
libunwind/src/config.h

Removed: 




diff  --git a/libunwind/src/DwarfParser.hpp b/libunwind/src/DwarfParser.hpp
index 86c0522afd3f..4bfd0451ed5a 100644
--- a/libunwind/src/DwarfParser.hpp
+++ b/libunwind/src/DwarfParser.hpp
@@ -135,6 +135,24 @@ class CFI_Parser {
 PrologInfo info;
   };
 
+  struct RememberStack {
+PrologInfoStackEntry *entry;
+RememberStack() : entry(nullptr) {}
+~RememberStack() {
+#if defined(_LIBUNWIND_REMEMBER_CLEANUP_NEEDED)
+  // Clean up rememberStack. Even in the case where every
+  // DW_CFA_remember_state is paired with a DW_CFA_restore_state,
+  // parseInstructions can skip restore opcodes if it reaches the target PC
+  // and stops interpreting, so we have to make sure we don't leak memory.
+  while (entry) {
+PrologInfoStackEntry *next = entry->next;
+_LIBUNWIND_REMEMBER_FREE(entry);
+entry = next;
+  }
+#endif
+}
+  };
+
   static bool findFDE(A &addressSpace, pint_t pc, pint_t ehSectionStart,
   uintptr_t sectionLength, pint_t fdeHint, FDE_Info 
*fdeInfo,
   CIE_Info *cieInfo);
@@ -145,13 +163,6 @@ class CFI_Parser {
int arch, PrologInfo *results);
 
   static const char *parseCIE(A &addressSpace, pint_t cie, CIE_Info *cieInfo);
-
-private:
-  static bool parseInstructions(A &addressSpace, pint_t instructions,
-pint_t instructionsEnd, const CIE_Info 
&cieInfo,
-pint_t pcoffset,
-PrologInfoStackEntry *&rememberStack, int arch,
-PrologInfo *results);
 };
 
 /// Parse a FDE into a CIE_Info and an FDE_Info
@@ -394,418 +405,415 @@ bool CFI_Parser::parseFDEInstructions(A 
&addressSpace,
  const FDE_Info &fdeInfo,
  const CIE_Info &cieInfo, pint_t 
upToPC,
  int arch, PrologInfo *results) {
-  PrologInfoStackEntry *rememberStack = NULL;
-
-  // parse CIE then FDE instructions
-  bool returnValue =
-  parseInstructions(addressSpace, cieInfo.cieInstructions,
-cieInfo.cieStart + cieInfo.cieLength, cieInfo,
-(pint_t)(-1), rememberStack, arch, results) &&
-  parseInstructions(addressSpace, fdeInfo.fdeInstructions,
-fdeInfo.fdeStart + fdeInfo.fdeLength, cieInfo,
-upToPC - fdeInfo.pcStart, rememberStack, arch, 
results);
-
-#if !defined(_LIBUNWIND_NO_HEAP)
-  // Clean up rememberStack. Even in the case where every DW_CFA_remember_state
-  // is paired with a DW_CFA_restore_state, parseInstructions can skip restore
-  // opcodes if it reaches the target PC and stops interpreting, so we have to
-  // make sure we don't leak memory.
-  while (rememberStack) {
-PrologInfoStackEntry *next = rememberStack->next;
-free(rememberStack);
-rememberStack = next;
-  }
-#endif
-
-  return returnValue;
-}
+  // Alloca is used for the allocation of the rememberStack entries. It removes
+  // the dependency on new/malloc but the below for loop can not be refactored
+  // into functions. Entry could be saved during the processing of a CIE and
+  // restored by an FDE.
+  RememberStack rememberStack;
+
+  struct ParseInfo {
+pint_t instructions;
+pint_t instructionsEnd;
+pint_t pcoffset;
+  };
 
-/// "run" the DWARF instructions
-template 
-bool CFI_Parser::parseInstructions(A &addressSpace, pint_t instructions,
-  pint_t instructionsEnd,
-  const CIE_Info &cieInfo, pint_t pcoffset,
-  PrologInfoStackEntry *&rememberStack,
-  int arch, PrologInfo *results) {
-  pint_t p = instructions;
-  

[clang] 801ab71 - [ARM][AArch64] SLSHardening: make non-comdat thunks possible

2021-05-20 Thread Daniel Kiss via cfe-commits

Author: Daniel Kiss
Date: 2021-05-20T17:07:05+02:00
New Revision: 801ab71032e157eb7bcd38efeb6486742a7c53bb

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

LOG: [ARM][AArch64] SLSHardening: make non-comdat thunks possible

Linker scripts might not handle COMDAT sections. SLSHardeing adds
new section for each __llvm_slsblr_thunk_xN. This new option allows
the generation of the thunks into the normal text section to handle these
exceptional cases.
,comdat or ,noncomdat can be added to harden-sls to control the codegen.
-mharden-sls=[all|retbr|blr],nocomdat.

Reviewed By: kristof.beyls

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

Added: 


Modified: 
clang/lib/Driver/ToolChains/Arch/AArch64.cpp
clang/lib/Driver/ToolChains/Arch/ARM.cpp
clang/test/Driver/sls-hardening-options.c
llvm/include/llvm/CodeGen/IndirectThunks.h
llvm/lib/Target/AArch64/AArch64.td
llvm/lib/Target/AArch64/AArch64SLSHardening.cpp
llvm/lib/Target/AArch64/AArch64Subtarget.h
llvm/lib/Target/ARM/ARM.td
llvm/lib/Target/ARM/ARMSLSHardening.cpp
llvm/lib/Target/ARM/ARMSubtarget.h
llvm/test/CodeGen/AArch64/speculation-hardening-sls.ll
llvm/test/CodeGen/ARM/speculation-hardening-sls.ll

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Arch/AArch64.cpp 
b/clang/lib/Driver/ToolChains/Arch/AArch64.cpp
index 4ce797f9bc73..503685ab533a 100644
--- a/clang/lib/Driver/ToolChains/Arch/AArch64.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/AArch64.cpp
@@ -235,11 +235,17 @@ void aarch64::getAArch64TargetFeatures(const Driver &D,
 StringRef Scope = A->getValue();
 bool EnableRetBr = false;
 bool EnableBlr = false;
-if (Scope != "none" && Scope != "all") {
+bool DisableComdat = false;
+if (Scope != "none") {
   SmallVector Opts;
   Scope.split(Opts, ",");
   for (auto Opt : Opts) {
 Opt = Opt.trim();
+if (Opt == "all") {
+  EnableBlr = true;
+  EnableRetBr = true;
+  continue;
+}
 if (Opt == "retbr") {
   EnableRetBr = true;
   continue;
@@ -248,19 +254,27 @@ void aarch64::getAArch64TargetFeatures(const Driver &D,
   EnableBlr = true;
   continue;
 }
+if (Opt == "comdat") {
+  DisableComdat = false;
+  continue;
+}
+if (Opt == "nocomdat") {
+  DisableComdat = true;
+  continue;
+}
 D.Diag(diag::err_invalid_sls_hardening)
 << Scope << A->getAsString(Args);
 break;
   }
-} else if (Scope == "all") {
-  EnableRetBr = true;
-  EnableBlr = true;
 }
 
 if (EnableRetBr)
   Features.push_back("+harden-sls-retbr");
 if (EnableBlr)
   Features.push_back("+harden-sls-blr");
+if (DisableComdat) {
+  Features.push_back("+harden-sls-nocomdat");
+}
   }
 
   // En/disable crc

diff  --git a/clang/lib/Driver/ToolChains/Arch/ARM.cpp 
b/clang/lib/Driver/ToolChains/Arch/ARM.cpp
index 16d72e5367f5..4ab547fabe43 100644
--- a/clang/lib/Driver/ToolChains/Arch/ARM.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/ARM.cpp
@@ -796,11 +796,17 @@ void arm::getARMTargetFeatures(const Driver &D, const 
llvm::Triple &Triple,
 StringRef Scope = A->getValue();
 bool EnableRetBr = false;
 bool EnableBlr = false;
-if (Scope != "none" && Scope != "all") {
+bool DisableComdat = false;
+if (Scope != "none") {
   SmallVector Opts;
   Scope.split(Opts, ",");
   for (auto Opt : Opts) {
 Opt = Opt.trim();
+if (Opt == "all") {
+  EnableBlr = true;
+  EnableRetBr = true;
+  continue;
+}
 if (Opt == "retbr") {
   EnableRetBr = true;
   continue;
@@ -809,13 +815,18 @@ void arm::getARMTargetFeatures(const Driver &D, const 
llvm::Triple &Triple,
   EnableBlr = true;
   continue;
 }
+if (Opt == "comdat") {
+  DisableComdat = false;
+  continue;
+}
+if (Opt == "nocomdat") {
+  DisableComdat = true;
+  continue;
+}
 D.Diag(diag::err_invalid_sls_hardening)
 << Scope << A->getAsString(Args);
 break;
   }
-} else if (Scope == "all") {
-  EnableRetBr = true;
-  EnableBlr = true;
 }
 
 if (EnableRetBr || EnableBlr)
@@ -827,6 +838,9 @@ void arm::getARMTargetFeatures(const Driver &D, const 
llvm::Triple &Triple,
   Features.push_back("+harden-sls-retbr");
 if (EnableBlr)
   Features.push_back("+harden-sls-blr");
+if (DisableComdat) {
+  Features.push_back("+harden-sls-nocomdat");
+}
   }
 
 }

diff  --git a/clang/test/Driver/sls-hardening-options.c 
b/clang/test/Driver/sls-hardening-options.c
index c48b6

[libunwind] 77aa9ca - [libunwind] Support cfi_undefined and cfi_register for float registers.

2021-09-27 Thread Daniel Kiss via cfe-commits

Author: Daniel Kiss
Date: 2021-09-27T12:04:02+02:00
New Revision: 77aa9ca92ae4732f5f92e580e14bb4d757f6b364

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

LOG:  [libunwind] Support cfi_undefined and cfi_register for float registers.

During a backtrace the `.cfi_undefined` for a float register causes an assert 
in libunwind.

Reviewed By: MaskRay

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

Added: 
libunwind/test/floatregister.pass.cpp

Modified: 
libunwind/src/DwarfInstructions.hpp

Removed: 




diff  --git a/libunwind/src/DwarfInstructions.hpp 
b/libunwind/src/DwarfInstructions.hpp
index 60b242e0c143..53baf6a148f3 100644
--- a/libunwind/src/DwarfInstructions.hpp
+++ b/libunwind/src/DwarfInstructions.hpp
@@ -115,12 +115,13 @@ double DwarfInstructions::getSavedFloatRegister(
 return addressSpace.getDouble(
 evaluateExpression((pint_t)savedReg.value, addressSpace,
 registers, cfa));
-
+  case CFI_Parser::kRegisterInRegister:
+return registers.getFloatRegister((int)savedReg.value);
+  case CFI_Parser::kRegisterUndefined:
+return 0.0;
   case CFI_Parser::kRegisterIsExpression:
   case CFI_Parser::kRegisterUnused:
-  case CFI_Parser::kRegisterUndefined:
   case CFI_Parser::kRegisterOffsetFromCFA:
-  case CFI_Parser::kRegisterInRegister:
 // FIX ME
 break;
   }

diff  --git a/libunwind/test/floatregister.pass.cpp 
b/libunwind/test/floatregister.pass.cpp
new file mode 100644
index ..64107e6d490b
--- /dev/null
+++ b/libunwind/test/floatregister.pass.cpp
@@ -0,0 +1,51 @@
+// -*- C++ -*-
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+// REQUIRES: linux && target={{aarch64-.+}}
+
+// Basic test for float registers number are accepted.
+
+#include 
+#include 
+#include 
+#include 
+
+_Unwind_Reason_Code frame_handler(struct _Unwind_Context *ctx, void *arg) {
+  (void)arg;
+  Dl_info info = {0, 0, 0, 0};
+
+  // Unwind util the main is reached, above frames depend on the platform and
+  // architecture.
+  if (dladdr(reinterpret_cast(_Unwind_GetIP(ctx)), &info) &&
+  info.dli_sname && !strcmp("main", info.dli_sname))
+_Exit(0);
+
+  return _URC_NO_REASON;
+}
+
+__attribute__((noinline)) void foo() {
+  // Provide some CFI directives that instructs the unwinder where given
+  // float register is.
+#if defined(__aarch64__)
+  // DWARF register number for V0-V31 registers are 64-95.
+  // Previous value of V0 is saved at offset 0 from CFA.
+  asm volatile(".cfi_offset 64, 0");
+  // From now on the previous value of register can't be restored anymore.
+  asm volatile(".cfi_undefined 65");
+  asm volatile(".cfi_undefined 95");
+  // Previous value of V2 is in V30.
+  asm volatile(".cfi_register  66, 94");
+#endif
+  _Unwind_Backtrace(frame_handler, NULL);
+}
+
+int main() {
+  foo();
+  return -2;
+}



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


[libunwind] 532783f - [libunwind] Fix cfi_register for float registers.

2021-10-01 Thread Daniel Kiss via cfe-commits

Author: Daniel Kiss
Date: 2021-10-01T16:51:51+02:00
New Revision: 532783f9e1e65c7bd48b1592d2376e9dd47c5a73

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

LOG: [libunwind] Fix cfi_register for float registers.

Fixes D110144.
registers.getFloatRegister is not const in ARM therefor can't be called here.

Reviewed By: mstorsjo, #libunwind

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

Added: 


Modified: 
libunwind/src/DwarfInstructions.hpp

Removed: 




diff  --git a/libunwind/src/DwarfInstructions.hpp 
b/libunwind/src/DwarfInstructions.hpp
index 53baf6a148f33..b58c51bb7a604 100644
--- a/libunwind/src/DwarfInstructions.hpp
+++ b/libunwind/src/DwarfInstructions.hpp
@@ -115,10 +115,12 @@ double DwarfInstructions::getSavedFloatRegister(
 return addressSpace.getDouble(
 evaluateExpression((pint_t)savedReg.value, addressSpace,
 registers, cfa));
-  case CFI_Parser::kRegisterInRegister:
-return registers.getFloatRegister((int)savedReg.value);
   case CFI_Parser::kRegisterUndefined:
 return 0.0;
+  case CFI_Parser::kRegisterInRegister:
+#ifndef _LIBUNWIND_TARGET_ARM
+return registers.getFloatRegister((int)savedReg.value);
+#endif
   case CFI_Parser::kRegisterIsExpression:
   case CFI_Parser::kRegisterUnused:
   case CFI_Parser::kRegisterOffsetFromCFA:



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


[libunwind] 9ed1c7e - [Unwind] Split unwind.h

2021-08-11 Thread Daniel Kiss via cfe-commits

Author: Daniel Kiss
Date: 2021-08-11T10:15:51+02:00
New Revision: 9ed1c7e4964382b95a5886279c0dfc7147a57b17

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

LOG: [Unwind] Split unwind.h

Moving Itanium and ArmEHABI specific implementations to dedicated files.
This is a NFC patch.

Reviewed By: MaskRay

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

Added: 
libunwind/include/unwind_arm_ehabi.h
libunwind/include/unwind_itanium.h

Modified: 
libunwind/include/unwind.h
libunwind/src/CMakeLists.txt

Removed: 




diff  --git a/libunwind/include/unwind.h b/libunwind/include/unwind.h
index 1d3444cd83b46..e8d114854325c 100644
--- a/libunwind/include/unwind.h
+++ b/libunwind/include/unwind.h
@@ -56,211 +56,15 @@ typedef enum {
 typedef struct _Unwind_Context _Unwind_Context;   // opaque
 
 #if defined(_LIBUNWIND_ARM_EHABI)
-typedef uint32_t _Unwind_State;
-
-static const _Unwind_State _US_VIRTUAL_UNWIND_FRAME   = 0;
-static const _Unwind_State _US_UNWIND_FRAME_STARTING  = 1;
-static const _Unwind_State _US_UNWIND_FRAME_RESUME= 2;
-static const _Unwind_State _US_ACTION_MASK= 3;
-/* Undocumented flag for force unwinding. */
-static const _Unwind_State _US_FORCE_UNWIND   = 8;
-
-typedef uint32_t _Unwind_EHT_Header;
-
-struct _Unwind_Control_Block;
-typedef struct _Unwind_Control_Block _Unwind_Control_Block;
-typedef struct _Unwind_Control_Block _Unwind_Exception; /* Alias */
-
-struct _Unwind_Control_Block {
-  uint64_t exception_class;
-  void (*exception_cleanup)(_Unwind_Reason_Code, _Unwind_Control_Block*);
-
-  /* Unwinder cache, private fields for the unwinder's use */
-  struct {
-uint32_t reserved1; /* init reserved1 to 0, then don't touch */
-uint32_t reserved2;
-uint32_t reserved3;
-uint32_t reserved4;
-uint32_t reserved5;
-  } unwinder_cache;
-
-  /* Propagation barrier cache (valid after phase 1): */
-  struct {
-uint32_t sp;
-uint32_t bitpattern[5];
-  } barrier_cache;
-
-  /* Cleanup cache (preserved over cleanup): */
-  struct {
-uint32_t bitpattern[4];
-  } cleanup_cache;
-
-  /* Pr cache (for pr's benefit): */
-  struct {
-uint32_t fnstart; /* function start address */
-_Unwind_EHT_Header* ehtp; /* pointer to EHT entry header word */
-uint32_t additional;
-uint32_t reserved1;
-  } pr_cache;
-
-  long long int :0; /* Enforce the 8-byte alignment */
-} __attribute__((__aligned__(8)));
-
-typedef _Unwind_Reason_Code (*_Unwind_Stop_Fn)
-  (_Unwind_State state,
-   _Unwind_Exception* exceptionObject,
-   struct _Unwind_Context* context);
-
-typedef _Unwind_Reason_Code (*_Unwind_Personality_Fn)(
-_Unwind_State state, _Unwind_Exception *exceptionObject,
-struct _Unwind_Context *context);
-#else
-struct _Unwind_Context;   // opaque
-struct _Unwind_Exception; // forward declaration
-typedef struct _Unwind_Exception _Unwind_Exception;
-
-struct _Unwind_Exception {
-  uint64_t exception_class;
-  void (*exception_cleanup)(_Unwind_Reason_Code reason,
-_Unwind_Exception *exc);
-#if defined(__SEH__) && !defined(__USING_SJLJ_EXCEPTIONS__)
-  uintptr_t private_[6];
+#include "unwind_arm_ehabi.h"
 #else
-  uintptr_t private_1; // non-zero means forced unwind
-  uintptr_t private_2; // holds sp that phase1 found for phase2 to use
-#endif
-#if __SIZEOF_POINTER__ == 4
-  // The implementation of _Unwind_Exception uses an attribute mode on the
-  // above fields which has the side effect of causing this whole struct to
-  // round up to 32 bytes in size (48 with SEH). To be more explicit, we add
-  // pad fields added for binary compatibility.
-  uint32_t reserved[3];
-#endif
-  // The Itanium ABI requires that _Unwind_Exception objects are "double-word
-  // aligned".  GCC has interpreted this to mean "use the maximum useful
-  // alignment for the target"; so do we.
-} __attribute__((__aligned__));
-
-typedef _Unwind_Reason_Code (*_Unwind_Stop_Fn)
-(int version,
- _Unwind_Action actions,
- uint64_t exceptionClass,
- _Unwind_Exception* exceptionObject,
- struct _Unwind_Context* context,
- void* stop_parameter );
-
-typedef _Unwind_Reason_Code (*_Unwind_Personality_Fn)(
-int version, _Unwind_Action actions, uint64_t exceptionClass,
-_Unwind_Exception *exceptionObject, struct _Unwind_Context *context);
+#include "unwind_itanium.h"
 #endif
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
-//
-// The following are the base functions documented by the C++ ABI
-//
-#ifdef __USING_SJLJ_EXCEPTIONS__
-extern _Unwind_Reason_Code
-_Unwind_SjLj_RaiseException(_Unwind_Exception *exception_object);
-extern void _Unwind_SjLj_Resume(_Unwind_Exception *exception_object);
-#else
-extern _Unwind_Reason_Code
-_Unwind_RaiseException(_Unwind_E

[libunwind] db126ae - [Arm][Unwind][libc++abi] Add _Unwind_ForcedUnwind to EHABI.

2021-08-11 Thread Daniel Kiss via cfe-commits

Author: Daniel Kiss
Date: 2021-08-11T10:15:53+02:00
New Revision: db126ae243cd70e4f68fd50a7c619740e90e1dc6

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

LOG: [Arm][Unwind][libc++abi] Add _Unwind_ForcedUnwind to EHABI.

_Unwind_ForcedUnwind is not mandated by the EHABI but for compatibilty
reasons adding so the interface to higher layers would be the same.
Dropping EHABI specific _Unwind_Stop_Fn definition since it is not defined by 
EHABI.

Reviewed By: MaskRay

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

Added: 
libunwind/test/forceunwind.pass.cpp

Modified: 
libcxxabi/src/cxa_personality.cpp
libcxxabi/test/forced_unwind1.pass.cpp
libcxxabi/test/forced_unwind2.pass.cpp
libunwind/include/unwind.h
libunwind/include/unwind_arm_ehabi.h
libunwind/include/unwind_itanium.h
libunwind/src/Unwind-EHABI.cpp
libunwind/src/UnwindLevel1-gcc-ext.c

Removed: 




diff  --git a/libcxxabi/src/cxa_personality.cpp 
b/libcxxabi/src/cxa_personality.cpp
index a4f81d74735f1..d63741b19b3dc 100644
--- a/libcxxabi/src/cxa_personality.cpp
+++ b/libcxxabi/src/cxa_personality.cpp
@@ -1109,7 +1109,14 @@ __gxx_personality_v0(_Unwind_State state,
 // Either we didn't do a phase 1 search (due to forced unwinding), or
 //  phase 1 reported no catching-handlers.
 // Search for a (non-catching) cleanup
-scan_eh_tab(results, _UA_CLEANUP_PHASE, native_exception, 
unwind_exception, context);
+if (is_force_unwinding)
+  scan_eh_tab(
+  results,
+  static_cast<_Unwind_Action>(_UA_CLEANUP_PHASE | 
_UA_FORCE_UNWIND),
+  native_exception, unwind_exception, context);
+else
+  scan_eh_tab(results, _UA_CLEANUP_PHASE, native_exception,
+  unwind_exception, context);
 if (results.reason == _URC_HANDLER_FOUND)
 {
 // Found a non-catching handler

diff  --git a/libcxxabi/test/forced_unwind1.pass.cpp 
b/libcxxabi/test/forced_unwind1.pass.cpp
index 69f93ffaacc0c..b6963a0242996 100644
--- a/libcxxabi/test/forced_unwind1.pass.cpp
+++ b/libcxxabi/test/forced_unwind1.pass.cpp
@@ -20,11 +20,6 @@
 #include 
 #include <__cxxabi_config.h>
 
-#if defined(_LIBCXXABI_ARM_EHABI)
-int main(int, char**) {
-  return 0;
-}
-#else
 static int bits = 0;
 
 struct C {
@@ -84,4 +79,3 @@ int main(int, char**) {
   test();
   return bits != 15;
 }
-#endif

diff  --git a/libcxxabi/test/forced_unwind2.pass.cpp 
b/libcxxabi/test/forced_unwind2.pass.cpp
index cb527581687a1..037f0499282f6 100644
--- a/libcxxabi/test/forced_unwind2.pass.cpp
+++ b/libcxxabi/test/forced_unwind2.pass.cpp
@@ -21,11 +21,6 @@
 #include 
 #include <__cxxabi_config.h>
 
-#if defined(_LIBCXXABI_ARM_EHABI)
-int main(int, char**) {
-  return 0;
-}
-#else
 template 
 struct Stop;
 
@@ -64,4 +59,3 @@ int main(int, char**) {
   }
   abort();
 }
-#endif

diff  --git a/libunwind/include/unwind.h b/libunwind/include/unwind.h
index e8d114854325c..87c3cf6c804ec 100644
--- a/libunwind/include/unwind.h
+++ b/libunwind/include/unwind.h
@@ -61,6 +61,14 @@ typedef struct _Unwind_Context _Unwind_Context;   // opaque
 #include "unwind_itanium.h"
 #endif
 
+typedef _Unwind_Reason_Code (*_Unwind_Stop_Fn)
+(int version,
+ _Unwind_Action actions,
+ uint64_t exceptionClass,
+ _Unwind_Exception* exceptionObject,
+ struct _Unwind_Context* context,
+ void* stop_parameter);
+
 #ifdef __cplusplus
 extern "C" {
 #endif

diff  --git a/libunwind/include/unwind_arm_ehabi.h 
b/libunwind/include/unwind_arm_ehabi.h
index 58444d14eb8dc..5ad0887225605 100644
--- a/libunwind/include/unwind_arm_ehabi.h
+++ b/libunwind/include/unwind_arm_ehabi.h
@@ -26,7 +26,7 @@ typedef uint32_t _Unwind_EHT_Header;
 
 struct _Unwind_Control_Block;
 typedef struct _Unwind_Control_Block _Unwind_Control_Block;
-typedef struct _Unwind_Control_Block _Unwind_Exception; /* Alias */
+#define _Unwind_Exception _Unwind_Control_Block /* Alias */
 
 struct _Unwind_Control_Block {
   uint64_t exception_class;
@@ -63,11 +63,6 @@ struct _Unwind_Control_Block {
   long long int :0; /* Enforce the 8-byte alignment */
 } __attribute__((__aligned__(8)));
 
-typedef _Unwind_Reason_Code (*_Unwind_Stop_Fn)
-  (_Unwind_State state,
-   _Unwind_Exception* exceptionObject,
-   struct _Unwind_Context* context);
-
 typedef _Unwind_Reason_Code (*_Unwind_Personality_Fn)(
 _Unwind_State state, _Unwind_Exception *exceptionObject,
 struct _Unwind_Context *context);

diff  --git a/libunwind/include/unwind_itanium.h 
b/libunwind/include/unwind_itanium.h
index 1e1389c7f0da0..eeb45f6228323 100644
--- a/libunwind/include/unwind_itanium.h
+++ b/libunwind/include/unwind_itanium.h
@@ -39,14 +39,6 @@ struct _Unwind_Exception {
   // alignment fo

[libunwind] 6b6d344 - [libunwind] Compile with -Wunused-but-set-variable

2021-08-11 Thread Daniel Kiss via cfe-commits

Author: Daniel Kiss
Date: 2021-08-11T10:15:54+02:00
New Revision: 6b6d3447317673015f62206b2669c2d0a74132dc

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

LOG: [libunwind] Compile with -Wunused-but-set-variable

-Wunused-but-set-variable triggers a warning even the block of code is 
effectively dead.

Reviewed By: MaskRay

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

Added: 


Modified: 
libunwind/CMakeLists.txt
libunwind/src/Unwind-EHABI.cpp
libunwind/src/Unwind-seh.cpp
libunwind/src/UnwindLevel1.c

Removed: 




diff  --git a/libunwind/CMakeLists.txt b/libunwind/CMakeLists.txt
index b1ef11bf7327..a73f5b0c7bdf 100644
--- a/libunwind/CMakeLists.txt
+++ b/libunwind/CMakeLists.txt
@@ -191,6 +191,7 @@ add_compile_flags_if_supported(-Wsign-compare)
 add_compile_flags_if_supported(-Wsign-conversion)
 add_compile_flags_if_supported(-Wstrict-aliasing=2)
 add_compile_flags_if_supported(-Wstrict-overflow=4)
+add_compile_flags_if_supported(-Wunused-but-set-variable)
 add_compile_flags_if_supported(-Wunused-parameter)
 add_compile_flags_if_supported(-Wunused-variable)
 add_compile_flags_if_supported(-Wwrite-strings)

diff  --git a/libunwind/src/Unwind-EHABI.cpp b/libunwind/src/Unwind-EHABI.cpp
index ba6064d3ef00..a564fd5240dd 100644
--- a/libunwind/src/Unwind-EHABI.cpp
+++ b/libunwind/src/Unwind-EHABI.cpp
@@ -463,6 +463,7 @@ unwind_phase1(unw_context_t *uc, unw_cursor_t *cursor, 
_Unwind_Exception *except
   return _URC_FATAL_PHASE1_ERROR;
 }
 
+#ifndef NDEBUG
 // When tracing, print state information.
 if (_LIBUNWIND_TRACING_UNWINDING) {
   char functionBuf[512];
@@ -481,6 +482,7 @@ unwind_phase1(unw_context_t *uc, unw_cursor_t *cursor, 
_Unwind_Exception *except
   frameInfo.start_ip, functionName,
   frameInfo.lsda, frameInfo.handler);
 }
+#endif
 
 // If there is a personality routine, ask it if it will want to stop at
 // this frame.
@@ -582,6 +584,7 @@ static _Unwind_Reason_Code unwind_phase2(unw_context_t *uc, 
unw_cursor_t *cursor
   return _URC_FATAL_PHASE2_ERROR;
 }
 
+#ifndef NDEBUG
 // When tracing, print state information.
 if (_LIBUNWIND_TRACING_UNWINDING) {
   char functionBuf[512];
@@ -598,6 +601,7 @@ static _Unwind_Reason_Code unwind_phase2(unw_context_t *uc, 
unw_cursor_t *cursor
   functionName, sp, frameInfo.lsda,
   frameInfo.handler);
 }
+#endif
 
 // If there is a personality routine, tell it we are unwinding.
 if (frameInfo.handler != 0) {
@@ -689,6 +693,7 @@ unwind_phase2_forced(unw_context_t *uc, unw_cursor_t 
*cursor,
   return _URC_FATAL_PHASE2_ERROR;
 }
 
+#ifndef NDEBUG
 // When tracing, print state information.
 if (_LIBUNWIND_TRACING_UNWINDING) {
   char functionBuf[512];
@@ -704,6 +709,7 @@ unwind_phase2_forced(unw_context_t *uc, unw_cursor_t 
*cursor,
   (void *)exception_object, frameInfo.start_ip, functionName,
   frameInfo.lsda, frameInfo.handler);
 }
+#endif
 
 // Call stop function at each frame.
 _Unwind_Action action =

diff  --git a/libunwind/src/Unwind-seh.cpp b/libunwind/src/Unwind-seh.cpp
index 6e2b4e73e41e..5a6a719730c8 100644
--- a/libunwind/src/Unwind-seh.cpp
+++ b/libunwind/src/Unwind-seh.cpp
@@ -244,6 +244,7 @@ unwind_phase2_forced(unw_context_t *uc,
   return _URC_FATAL_PHASE2_ERROR;
 }
 
+#ifndef NDEBUG
 // When tracing, print state information.
 if (_LIBUNWIND_TRACING_UNWINDING) {
   char functionBuf[512];
@@ -259,6 +260,7 @@ unwind_phase2_forced(unw_context_t *uc,
   (void *)exception_object, frameInfo.start_ip, functionName,
   frameInfo.lsda, frameInfo.handler);
 }
+#endif
 
 // Call stop function at each frame.
 _Unwind_Action action =

diff  --git a/libunwind/src/UnwindLevel1.c b/libunwind/src/UnwindLevel1.c
index 68e5e48b8c05..8b8797fb88ad 100644
--- a/libunwind/src/UnwindLevel1.c
+++ b/libunwind/src/UnwindLevel1.c
@@ -68,6 +68,7 @@ unwind_phase1(unw_context_t *uc, unw_cursor_t *cursor, 
_Unwind_Exception *except
   return _URC_FATAL_PHASE1_ERROR;
 }
 
+#ifndef NDEBUG
 // When tracing, print state information.
 if (_LIBUNWIND_TRACING_UNWINDING) {
   char functionBuf[512];
@@ -85,6 +86,7 @@ unwind_phase1(unw_context_t *uc, unw_cursor_t *cursor, 
_Unwind_Exception *except
   (void *)exception_object, pc, frameInfo.start_ip, functionName,
   frameInfo.lsda, frameInfo.handler);
 }
+#endif
 
 // If there is a personality routine, ask it if it will want to stop at
 // this frame.
@@ -167,6 +169,7 @@ unwind_phase2(unw_context_t *uc, unw_cursor_t *cursor, 
_Unwind_Exception *except
   return _URC_FATAL_PHASE2_ERROR;
 }
 
+#ifndef NDEBUG
 // When tracing, print state

[libunwind] 632acec - [libunwind][ARM] Handle end of stack during unwind

2021-11-26 Thread Daniel Kiss via cfe-commits

Author: Daniel Kiss
Date: 2021-11-26T13:26:49+01:00
New Revision: 632acec73776c4d6f7073d6de04ed6b8bfd36e6d

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

LOG: [libunwind][ARM] Handle end of stack during unwind

When unwind step reaches the end of the stack that means the force unwind 
should notify the stop function.
This is not an error, it could mean just the thread is cleaned up completely.

Reviewed By: #libunwind, mstorsjo

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

Added: 
libcxxabi/test/forced_unwind3.pass.cpp

Modified: 
libcxxabi/src/cxa_personality.cpp
libunwind/src/Unwind-EHABI.cpp

Removed: 




diff  --git a/libcxxabi/src/cxa_personality.cpp 
b/libcxxabi/src/cxa_personality.cpp
index ccad45979db2a..f6e135f137c09 100644
--- a/libcxxabi/src/cxa_personality.cpp
+++ b/libcxxabi/src/cxa_personality.cpp
@@ -1004,9 +1004,14 @@ extern "C" _Unwind_Reason_Code 
__gnu_unwind_frame(_Unwind_Exception*,
 static _Unwind_Reason_Code continue_unwind(_Unwind_Exception* unwind_exception,
_Unwind_Context* context)
 {
-if (__gnu_unwind_frame(unwind_exception, context) != _URC_OK)
-return _URC_FAILURE;
+  switch (__gnu_unwind_frame(unwind_exception, context)) {
+  case _URC_OK:
 return _URC_CONTINUE_UNWIND;
+  case _URC_END_OF_STACK:
+return _URC_END_OF_STACK;
+  default:
+return _URC_FAILURE;
+  }
 }
 
 // ARM register names

diff  --git a/libcxxabi/test/forced_unwind3.pass.cpp 
b/libcxxabi/test/forced_unwind3.pass.cpp
new file mode 100644
index 0..3bcc7978aeab8
--- /dev/null
+++ b/libcxxabi/test/forced_unwind3.pass.cpp
@@ -0,0 +1,79 @@
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+// Let's run ForcedUnwind until it reaches end of the stack, this test 
simulates
+// what pthread_cancel does.
+
+// UNSUPPORTED: c++03
+// UNSUPPORTED: libcxxabi-no-threads
+// UNSUPPORTED: no-exceptions
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include <__cxxabi_config.h>
+
+// TODO: dump version back to 14 once clang is updated on the CI.
+#if defined(_LIBCXXABI_ARM_EHABI) && defined(__clang__) && __clang_major__ < 15
+// _Unwind_ForcedUnwind is not available or broken before version 14.
+int main(int, char**) { return 0; }
+
+#else
+static bool destructorCalled = false;
+
+struct myClass {
+  myClass() {}
+  ~myClass() {
+assert(destructorCalled == false);
+destructorCalled = true;
+  };
+};
+
+template 
+struct Stop;
+
+template 
+struct Stop {
+  // The third argument of _Unwind_Stop_Fn is uint64_t in Itanium C++ ABI/LLVM
+  // libunwind while _Unwind_Exception_Class in libgcc.
+  typedef typename std::tuple_element<2, std::tuple>::type type;
+
+  static _Unwind_Reason_Code stop(int, _Unwind_Action actions, type, struct 
_Unwind_Exception*, struct _Unwind_Context*,
+  void*) {
+if (actions & _UA_END_OF_STACK) {
+  assert(destructorCalled == true);
+  exit(0);
+}
+return _URC_NO_REASON;
+  }
+};
+
+static void forced_unwind() {
+  _Unwind_Exception* exc = new _Unwind_Exception;
+  memset(&exc->exception_class, 0, sizeof(exc->exception_class));
+  exc->exception_cleanup = 0;
+  _Unwind_ForcedUnwind(exc, Stop<_Unwind_Stop_Fn>::stop, 0);
+  abort();
+}
+
+__attribute__((__noinline__)) static void test() {
+  myClass c{};
+  forced_unwind();
+  abort();
+}
+
+int main(int, char**) {
+  std::thread t{test};
+  t.join();
+  return -1;
+}
+#endif

diff  --git a/libunwind/src/Unwind-EHABI.cpp b/libunwind/src/Unwind-EHABI.cpp
index d3577c9f7cf8d..5959d2a25fead 100644
--- a/libunwind/src/Unwind-EHABI.cpp
+++ b/libunwind/src/Unwind-EHABI.cpp
@@ -187,9 +187,14 @@ static _Unwind_Reason_Code unwindOneFrame(_Unwind_State 
state,
   if (result != _URC_CONTINUE_UNWIND)
 return result;
 
-  if (__unw_step(reinterpret_cast(context)) != 
UNW_STEP_SUCCESS)
+  switch (__unw_step(reinterpret_cast(context))) {
+  case UNW_STEP_SUCCESS:
+return _URC_CONTINUE_UNWIND;
+  case UNW_STEP_END:
+return _URC_END_OF_STACK;
+  default:
 return _URC_FAILURE;
-  return _URC_CONTINUE_UNWIND;
+  }
 }
 
 // Generates mask discriminator for _Unwind_VRS_Pop, e.g. for _UVRSC_CORE /
@@ -678,12 +683,13 @@ static _Unwind_Reason_Code
 unwind_phase2_forced(unw_context_t *uc, unw_cursor_t *cursor,
  _Unwind_Exception *exception_object, _Unwind_Stop_Fn stop,
  void *stop_p

[clang] 09aaf19 - [AArch64] Make ACLE intrinsics always available part MTE

2022-10-18 Thread Daniel Kiss via cfe-commits

Author: Daniel Kiss
Date: 2022-10-18T10:35:40+02:00
New Revision: 09aaf190d93393d9e29d29a033cc3979589c5e84

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

LOG: [AArch64] Make ACLE intrinsics always available part MTE

Make MTE intrinsics available in function scope too.
Followup from D133359.

Reviewed By: dmgreen

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

Added: 


Modified: 
clang/include/clang/Basic/BuiltinsAArch64.def
clang/lib/Headers/arm_acle.h
clang/test/CodeGen/arm64-mte.c
clang/test/Sema/builtins-arm64-mte.c

Removed: 




diff  --git a/clang/include/clang/Basic/BuiltinsAArch64.def 
b/clang/include/clang/Basic/BuiltinsAArch64.def
index e6e375bc2b83a..bc8ab4eade91a 100644
--- a/clang/include/clang/Basic/BuiltinsAArch64.def
+++ b/clang/include/clang/Basic/BuiltinsAArch64.def
@@ -59,15 +59,15 @@ TARGET_BUILTIN(__builtin_arm_crc32d, "UiUiWUi", "nc", "crc")
 TARGET_BUILTIN(__builtin_arm_crc32cd, "UiUiWUi", "nc", "crc")
 
 // Memory Tagging Extensions (MTE)
-BUILTIN(__builtin_arm_irg, "v*v*Ui", "t")
-BUILTIN(__builtin_arm_addg, "v*v*Ui", "t")
-BUILTIN(__builtin_arm_gmi, "Uiv*Ui", "t")
-BUILTIN(__builtin_arm_ldg, "v*v*", "t")
-BUILTIN(__builtin_arm_stg, "vv*", "t")
-BUILTIN(__builtin_arm_subp, "Uiv*v*", "t")
+TARGET_BUILTIN(__builtin_arm_irg, "v*v*Ui", "t", "mte")
+TARGET_BUILTIN(__builtin_arm_addg, "v*v*Ui", "t", "mte")
+TARGET_BUILTIN(__builtin_arm_gmi, "Uiv*Ui", "t", "mte")
+TARGET_BUILTIN(__builtin_arm_ldg, "v*v*", "t", "mte")
+TARGET_BUILTIN(__builtin_arm_stg, "vv*", "t", "mte")
+TARGET_BUILTIN(__builtin_arm_subp, "Uiv*v*", "t", "mte")
 
 // Memory Operations
-BUILTIN(__builtin_arm_mops_memset_tag, "v*v*iz", "")
+TARGET_BUILTIN(__builtin_arm_mops_memset_tag, "v*v*iz", "", "mte,mops")
 
 // Memory barrier
 BUILTIN(__builtin_arm_dmb, "vUi", "nc")

diff  --git a/clang/lib/Headers/arm_acle.h b/clang/lib/Headers/arm_acle.h
index d73b6bf82d699..b30010274392c 100644
--- a/clang/lib/Headers/arm_acle.h
+++ b/clang/lib/Headers/arm_acle.h
@@ -722,17 +722,15 @@ __arm_st64bv0(void *__addr, data512_t __value) {
 #define __arm_wsrf64(sysreg, v) __arm_wsr64(sysreg, 
__builtin_bit_cast(uint64_t, v))
 
 /* Memory Tagging Extensions (MTE) Intrinsics */
-#if defined(__ARM_FEATURE_MEMORY_TAGGING) && __ARM_FEATURE_MEMORY_TAGGING
+#if defined(__ARM_64BIT_STATE) && __ARM_64BIT_STATE
 #define __arm_mte_create_random_tag(__ptr, __mask)  __builtin_arm_irg(__ptr, 
__mask)
 #define __arm_mte_increment_tag(__ptr, __tag_offset)  
__builtin_arm_addg(__ptr, __tag_offset)
 #define __arm_mte_exclude_tag(__ptr, __excluded)  __builtin_arm_gmi(__ptr, 
__excluded)
 #define __arm_mte_get_tag(__ptr) __builtin_arm_ldg(__ptr)
 #define __arm_mte_set_tag(__ptr) __builtin_arm_stg(__ptr)
 #define __arm_mte_ptr
diff (__ptra, __ptrb) __builtin_arm_subp(__ptra, __ptrb)
-#endif
 
 /* Memory Operations Intrinsics */
-#if defined(__ARM_FEATURE_MOPS) && __ARM_FEATURE_MOPS && 
defined(__ARM_FEATURE_MEMORY_TAGGING) && __ARM_FEATURE_MEMORY_TAGGING
 #define __arm_mops_memset_tag(__tagged_address, __value, __size)\
   __builtin_arm_mops_memset_tag(__tagged_address, __value, __size)
 #endif

diff  --git a/clang/test/CodeGen/arm64-mte.c b/clang/test/CodeGen/arm64-mte.c
index 12b568b2ece76..1c65d6a626dda 100644
--- a/clang/test/CodeGen/arm64-mte.c
+++ b/clang/test/CodeGen/arm64-mte.c
@@ -1,9 +1,17 @@
 // Test memory tagging extension intrinsics
 // RUN: %clang_cc1 -triple aarch64-none-linux-eabi -target-feature +mte -O3 -S 
-emit-llvm -o - %s  | FileCheck %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-eabi -DMTE -O3 -S -emit-llvm -o 
- %s  | FileCheck %s
 #include 
 #include 
 
+#ifdef MTE
+#define attribute  __attribute__((target("mte")))
+#else
+#define attribute
+#endif
+
 // CHECK-LABEL: define{{.*}} ptr @create_tag1
+attribute
 int *create_tag1(int *a, unsigned b) {
 // CHECK: [[T1:%[0-9]+]] = zext i32 %b to i64
 // CHECK: [[T2:%[0-9]+]] = tail call ptr @llvm.aarch64.irg(ptr %a, i64 [[T1]])
@@ -11,6 +19,7 @@ int *create_tag1(int *a, unsigned b) {
 }
 
 // CHECK-LABEL: define{{.*}} ptr @create_tag2
+attribute
 short *create_tag2(short *a, unsigned b) {
 // CHECK: [[T1:%[0-9]+]] = zext i32 %b to i64
 // CHECK: [[T2:%[0-9]+]] = tail call ptr @llvm.aarch64.irg(ptr %a, i64 [[T1]])
@@ -18,6 +27,7 @@ short *create_tag2(short *a, unsigned b) {
 }
 
 // CHECK-LABEL: define{{.*}} ptr @create_tag3
+attribute
 char *create_tag3(char *a, unsigned b) {
 // CHECK: [[T1:%[0-9]+]] = zext i32 %b to i64
 // CHECK: [[T2:%[0-9]+]] = tail call ptr @llvm.aarch64.irg(ptr %a, i64 [[T1]])
@@ -26,18 +36,21 @@ char *create_tag3(char *a, unsigned b) {
 }
 
 // CHECK-LABEL: define{{.*}} ptr @increment_tag1
+attribute
 char *increment_tag1(char *a) {
 // CHECK: call ptr @llvm.aarch64.addg(ptr %a, i64 3)
 return __

[clang] a175d8b - Revert "[AArch64] Make ACLE intrinsics always available part MTE"

2022-10-18 Thread Daniel Kiss via cfe-commits

Author: Daniel Kiss
Date: 2022-10-18T10:45:32+02:00
New Revision: a175d8b1772f729b2caf95a1b755cb9a59563e21

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

LOG: Revert "[AArch64] Make ACLE intrinsics always available part MTE"

This reverts commit 09aaf190d93393d9e29d29a033cc3979589c5e84.

Added: 


Modified: 
clang/include/clang/Basic/BuiltinsAArch64.def
clang/lib/Headers/arm_acle.h
clang/test/CodeGen/arm64-mte.c
clang/test/Sema/builtins-arm64-mte.c

Removed: 




diff  --git a/clang/include/clang/Basic/BuiltinsAArch64.def 
b/clang/include/clang/Basic/BuiltinsAArch64.def
index bc8ab4eade91a..e6e375bc2b83a 100644
--- a/clang/include/clang/Basic/BuiltinsAArch64.def
+++ b/clang/include/clang/Basic/BuiltinsAArch64.def
@@ -59,15 +59,15 @@ TARGET_BUILTIN(__builtin_arm_crc32d, "UiUiWUi", "nc", "crc")
 TARGET_BUILTIN(__builtin_arm_crc32cd, "UiUiWUi", "nc", "crc")
 
 // Memory Tagging Extensions (MTE)
-TARGET_BUILTIN(__builtin_arm_irg, "v*v*Ui", "t", "mte")
-TARGET_BUILTIN(__builtin_arm_addg, "v*v*Ui", "t", "mte")
-TARGET_BUILTIN(__builtin_arm_gmi, "Uiv*Ui", "t", "mte")
-TARGET_BUILTIN(__builtin_arm_ldg, "v*v*", "t", "mte")
-TARGET_BUILTIN(__builtin_arm_stg, "vv*", "t", "mte")
-TARGET_BUILTIN(__builtin_arm_subp, "Uiv*v*", "t", "mte")
+BUILTIN(__builtin_arm_irg, "v*v*Ui", "t")
+BUILTIN(__builtin_arm_addg, "v*v*Ui", "t")
+BUILTIN(__builtin_arm_gmi, "Uiv*Ui", "t")
+BUILTIN(__builtin_arm_ldg, "v*v*", "t")
+BUILTIN(__builtin_arm_stg, "vv*", "t")
+BUILTIN(__builtin_arm_subp, "Uiv*v*", "t")
 
 // Memory Operations
-TARGET_BUILTIN(__builtin_arm_mops_memset_tag, "v*v*iz", "", "mte,mops")
+BUILTIN(__builtin_arm_mops_memset_tag, "v*v*iz", "")
 
 // Memory barrier
 BUILTIN(__builtin_arm_dmb, "vUi", "nc")

diff  --git a/clang/lib/Headers/arm_acle.h b/clang/lib/Headers/arm_acle.h
index b30010274392c..d73b6bf82d699 100644
--- a/clang/lib/Headers/arm_acle.h
+++ b/clang/lib/Headers/arm_acle.h
@@ -722,15 +722,17 @@ __arm_st64bv0(void *__addr, data512_t __value) {
 #define __arm_wsrf64(sysreg, v) __arm_wsr64(sysreg, 
__builtin_bit_cast(uint64_t, v))
 
 /* Memory Tagging Extensions (MTE) Intrinsics */
-#if defined(__ARM_64BIT_STATE) && __ARM_64BIT_STATE
+#if defined(__ARM_FEATURE_MEMORY_TAGGING) && __ARM_FEATURE_MEMORY_TAGGING
 #define __arm_mte_create_random_tag(__ptr, __mask)  __builtin_arm_irg(__ptr, 
__mask)
 #define __arm_mte_increment_tag(__ptr, __tag_offset)  
__builtin_arm_addg(__ptr, __tag_offset)
 #define __arm_mte_exclude_tag(__ptr, __excluded)  __builtin_arm_gmi(__ptr, 
__excluded)
 #define __arm_mte_get_tag(__ptr) __builtin_arm_ldg(__ptr)
 #define __arm_mte_set_tag(__ptr) __builtin_arm_stg(__ptr)
 #define __arm_mte_ptr
diff (__ptra, __ptrb) __builtin_arm_subp(__ptra, __ptrb)
+#endif
 
 /* Memory Operations Intrinsics */
+#if defined(__ARM_FEATURE_MOPS) && __ARM_FEATURE_MOPS && 
defined(__ARM_FEATURE_MEMORY_TAGGING) && __ARM_FEATURE_MEMORY_TAGGING
 #define __arm_mops_memset_tag(__tagged_address, __value, __size)\
   __builtin_arm_mops_memset_tag(__tagged_address, __value, __size)
 #endif

diff  --git a/clang/test/CodeGen/arm64-mte.c b/clang/test/CodeGen/arm64-mte.c
index 1c65d6a626dda..12b568b2ece76 100644
--- a/clang/test/CodeGen/arm64-mte.c
+++ b/clang/test/CodeGen/arm64-mte.c
@@ -1,17 +1,9 @@
 // Test memory tagging extension intrinsics
 // RUN: %clang_cc1 -triple aarch64-none-linux-eabi -target-feature +mte -O3 -S 
-emit-llvm -o - %s  | FileCheck %s
-// RUN: %clang_cc1 -triple aarch64-none-linux-eabi -DMTE -O3 -S -emit-llvm -o 
- %s  | FileCheck %s
 #include 
 #include 
 
-#ifdef MTE
-#define attribute  __attribute__((target("mte")))
-#else
-#define attribute
-#endif
-
 // CHECK-LABEL: define{{.*}} ptr @create_tag1
-attribute
 int *create_tag1(int *a, unsigned b) {
 // CHECK: [[T1:%[0-9]+]] = zext i32 %b to i64
 // CHECK: [[T2:%[0-9]+]] = tail call ptr @llvm.aarch64.irg(ptr %a, i64 [[T1]])
@@ -19,7 +11,6 @@ int *create_tag1(int *a, unsigned b) {
 }
 
 // CHECK-LABEL: define{{.*}} ptr @create_tag2
-attribute
 short *create_tag2(short *a, unsigned b) {
 // CHECK: [[T1:%[0-9]+]] = zext i32 %b to i64
 // CHECK: [[T2:%[0-9]+]] = tail call ptr @llvm.aarch64.irg(ptr %a, i64 [[T1]])
@@ -27,7 +18,6 @@ short *create_tag2(short *a, unsigned b) {
 }
 
 // CHECK-LABEL: define{{.*}} ptr @create_tag3
-attribute
 char *create_tag3(char *a, unsigned b) {
 // CHECK: [[T1:%[0-9]+]] = zext i32 %b to i64
 // CHECK: [[T2:%[0-9]+]] = tail call ptr @llvm.aarch64.irg(ptr %a, i64 [[T1]])
@@ -36,21 +26,18 @@ char *create_tag3(char *a, unsigned b) {
 }
 
 // CHECK-LABEL: define{{.*}} ptr @increment_tag1
-attribute
 char *increment_tag1(char *a) {
 // CHECK: call ptr @llvm.aarch64.addg(ptr %a, i64 3)
 return __arm_mte_increment_tag(a,3);
 }
 
 // CHECK-LABEL: define{{.*}} ptr @increment_tag2
-

[clang] 0d0ca64 - [AArch64] Make ACLE intrinsics always available part MTE

2022-10-18 Thread Daniel Kiss via cfe-commits

Author: Daniel Kiss
Date: 2022-10-18T11:03:02+02:00
New Revision: 0d0ca64356ff1a9e3427660732da033a14521e5b

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

LOG: [AArch64] Make ACLE intrinsics always available part MTE

Make MTE intrinsics available in function scope too.
Followup from D133359.

Reviewed By: dmgreen

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

Added: 


Modified: 
clang/include/clang/Basic/BuiltinsAArch64.def
clang/lib/Headers/arm_acle.h
clang/test/CodeGen/aarch64-mops.c
clang/test/CodeGen/arm64-mte.c
clang/test/Sema/builtins-arm64-mte.c

Removed: 




diff  --git a/clang/include/clang/Basic/BuiltinsAArch64.def 
b/clang/include/clang/Basic/BuiltinsAArch64.def
index e6e375bc2b83a..bc8ab4eade91a 100644
--- a/clang/include/clang/Basic/BuiltinsAArch64.def
+++ b/clang/include/clang/Basic/BuiltinsAArch64.def
@@ -59,15 +59,15 @@ TARGET_BUILTIN(__builtin_arm_crc32d, "UiUiWUi", "nc", "crc")
 TARGET_BUILTIN(__builtin_arm_crc32cd, "UiUiWUi", "nc", "crc")
 
 // Memory Tagging Extensions (MTE)
-BUILTIN(__builtin_arm_irg, "v*v*Ui", "t")
-BUILTIN(__builtin_arm_addg, "v*v*Ui", "t")
-BUILTIN(__builtin_arm_gmi, "Uiv*Ui", "t")
-BUILTIN(__builtin_arm_ldg, "v*v*", "t")
-BUILTIN(__builtin_arm_stg, "vv*", "t")
-BUILTIN(__builtin_arm_subp, "Uiv*v*", "t")
+TARGET_BUILTIN(__builtin_arm_irg, "v*v*Ui", "t", "mte")
+TARGET_BUILTIN(__builtin_arm_addg, "v*v*Ui", "t", "mte")
+TARGET_BUILTIN(__builtin_arm_gmi, "Uiv*Ui", "t", "mte")
+TARGET_BUILTIN(__builtin_arm_ldg, "v*v*", "t", "mte")
+TARGET_BUILTIN(__builtin_arm_stg, "vv*", "t", "mte")
+TARGET_BUILTIN(__builtin_arm_subp, "Uiv*v*", "t", "mte")
 
 // Memory Operations
-BUILTIN(__builtin_arm_mops_memset_tag, "v*v*iz", "")
+TARGET_BUILTIN(__builtin_arm_mops_memset_tag, "v*v*iz", "", "mte,mops")
 
 // Memory barrier
 BUILTIN(__builtin_arm_dmb, "vUi", "nc")

diff  --git a/clang/lib/Headers/arm_acle.h b/clang/lib/Headers/arm_acle.h
index d73b6bf82d699..b30010274392c 100644
--- a/clang/lib/Headers/arm_acle.h
+++ b/clang/lib/Headers/arm_acle.h
@@ -722,17 +722,15 @@ __arm_st64bv0(void *__addr, data512_t __value) {
 #define __arm_wsrf64(sysreg, v) __arm_wsr64(sysreg, 
__builtin_bit_cast(uint64_t, v))
 
 /* Memory Tagging Extensions (MTE) Intrinsics */
-#if defined(__ARM_FEATURE_MEMORY_TAGGING) && __ARM_FEATURE_MEMORY_TAGGING
+#if defined(__ARM_64BIT_STATE) && __ARM_64BIT_STATE
 #define __arm_mte_create_random_tag(__ptr, __mask)  __builtin_arm_irg(__ptr, 
__mask)
 #define __arm_mte_increment_tag(__ptr, __tag_offset)  
__builtin_arm_addg(__ptr, __tag_offset)
 #define __arm_mte_exclude_tag(__ptr, __excluded)  __builtin_arm_gmi(__ptr, 
__excluded)
 #define __arm_mte_get_tag(__ptr) __builtin_arm_ldg(__ptr)
 #define __arm_mte_set_tag(__ptr) __builtin_arm_stg(__ptr)
 #define __arm_mte_ptr
diff (__ptra, __ptrb) __builtin_arm_subp(__ptra, __ptrb)
-#endif
 
 /* Memory Operations Intrinsics */
-#if defined(__ARM_FEATURE_MOPS) && __ARM_FEATURE_MOPS && 
defined(__ARM_FEATURE_MEMORY_TAGGING) && __ARM_FEATURE_MEMORY_TAGGING
 #define __arm_mops_memset_tag(__tagged_address, __value, __size)\
   __builtin_arm_mops_memset_tag(__tagged_address, __value, __size)
 #endif

diff  --git a/clang/test/CodeGen/aarch64-mops.c 
b/clang/test/CodeGen/aarch64-mops.c
index f7efb1635185d..c0f151837c751 100644
--- a/clang/test/CodeGen/aarch64-mops.c
+++ b/clang/test/CodeGen/aarch64-mops.c
@@ -1,77 +1,68 @@
 // RUN: %clang_cc1 -triple aarch64-arm-unknown-eabi -Wno-int-conversion 
-target-feature +mops -target-feature +mte -w -S -emit-llvm -o - %s  | 
FileCheck --check-prefix=CHECK-MOPS   %s
-// RUN: %clang_cc1 -triple aarch64-arm-unknown-eabi -Wno-int-conversion 
-target-feature +mops -Wno-implicit-function-declaration -w -S -emit-llvm -o - 
%s  | FileCheck --check-prefix=CHECK-NOMOPS %s
-// RUN: %clang_cc1 -triple aarch64-arm-unknown-eabi -Wno-int-conversion 
-Wno-implicit-function-declaration -target-feature +mte -w -S -emit-llvm -o - 
%s  | FileCheck --check-prefix=CHECK-NOMOPS %s
-// RUN: %clang_cc1 -triple aarch64-arm-unknown-eabi -Wno-int-conversion 
-Wno-implicit-function-declaration -w -S -emit-llvm -o - %s  | FileCheck 
--check-prefix=CHECK-NOMOPS %s
+// RUN: not %clang_cc1 -triple aarch64-arm-unknown-eabi -Wno-int-conversion 
-target-feature +mops -Wno-implicit-function-declaration -w -S -emit-llvm -o - 
%s 2>&1  | FileCheck --check-prefix=CHECK-NOMOPS %s
+// RUN: not %clang_cc1 -triple aarch64-arm-unknown-eabi -Wno-int-conversion 
-Wno-implicit-function-declaration -target-feature +mte -w -S -emit-llvm -o - 
%s 2>&1 | FileCheck --check-prefix=CHECK-NOMOPS %s
+// RUN: not %clang_cc1 -triple aarch64-arm-unknown-eabi -Wno-int-conversion 
-Wno-implicit-function-declaration -w -S -emit-llvm -o - %s 2>&1 | FileCheck 
--check-prefix=CHECK-NOMOPS %s
 

[clang] 7e1a873 - [Arm][AArch64] Make getArchFeatures to use TargetParser.def

2022-09-23 Thread Daniel Kiss via cfe-commits

Author: Daniel Kiss
Date: 2022-09-23T10:25:37+02:00
New Revision: 7e1a87387209252dec5902925a232467db951db6

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

LOG: [Arm][AArch64] Make getArchFeatures to use TargetParser.def

Prefixing the the SubArch with plus sign makes the ArchFeature name.

Reviewed By: DavidSpickett

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

Added: 


Modified: 
clang/test/Driver/arch.c
clang/test/Driver/arm-cortex-cpus-1.c
clang/test/Driver/arm-cortex-cpus-2.c
clang/test/Driver/arm-features.c
clang/test/Driver/arm-target-as-march-mcpu.s
llvm/include/llvm/Support/AArch64TargetParser.def
llvm/include/llvm/Support/AArch64TargetParser.h
llvm/include/llvm/Support/ARMTargetParser.def
llvm/include/llvm/Support/ARMTargetParser.h
llvm/lib/Support/AArch64TargetParser.cpp
llvm/unittests/Support/TargetParserTest.cpp

Removed: 




diff  --git a/clang/test/Driver/arch.c b/clang/test/Driver/arch.c
index f113c1dfa5c27..09afc6a6455b7 100644
--- a/clang/test/Driver/arch.c
+++ b/clang/test/Driver/arch.c
@@ -2,4 +2,4 @@
 // RUN: %clang -target armv8a-unknown-linux-gnueabi -S -emit-llvm %s -o - | 
FileCheck %s --check-prefix=V8
 
 // V7: target triple = "armv7-unknown-linux-gnueabi"
-// V8: target triple = "armv8-unknown-linux-gnueabi"
+// V8: target triple = "armv8a-unknown-linux-gnueabi"

diff  --git a/clang/test/Driver/arm-cortex-cpus-1.c 
b/clang/test/Driver/arm-cortex-cpus-1.c
index 7b6c203b53b80..bfdf4d1515793 100644
--- a/clang/test/Driver/arm-cortex-cpus-1.c
+++ b/clang/test/Driver/arm-cortex-cpus-1.c
@@ -148,7 +148,7 @@
 // RUN: %clang -target armv8a -mlittle-endian -### -c %s 2>&1 | FileCheck 
-check-prefix=CHECK-V8A %s
 // RUN: %clang -target arm -march=armv8a -mlittle-endian -### -c %s 2>&1 | 
FileCheck -check-prefix=CHECK-V8A %s
 // RUN: %clang -target arm -march=armv8-a -mlittle-endian -### -c %s 2>&1 | 
FileCheck -check-prefix=CHECK-V8A %s
-// CHECK-V8A: "-cc1"{{.*}} "-triple" "armv8-{{.*}}" "-target-cpu" "generic"
+// CHECK-V8A: "-cc1"{{.*}} "-triple" "armv8a-{{.*}}" "-target-cpu" "generic"
 
 // RUN: %clang -target armv8r-linux-gnueabi -### -c %s 2>&1 | FileCheck 
-check-prefix=CHECK-V8R %s
 // RUN: %clang -target arm -march=armv8r -### -c %s 2>&1 | FileCheck 
-check-prefix=CHECK-V8R %s
@@ -181,7 +181,7 @@
 // RUN: %clang -mcpu=generic -target armv8a -mlittle-endian -### -c %s 2>&1 | 
FileCheck -check-prefix=CHECK-V8A-GENERIC %s
 // RUN: %clang -mcpu=generic -target arm -march=armv8a -mlittle-endian -### -c 
%s 2>&1 | FileCheck -check-prefix=CHECK-V8A-GENERIC %s
 // RUN: %clang -mcpu=generic -target arm -march=armv8-a -mlittle-endian -### 
-c %s 2>&1 | FileCheck -check-prefix=CHECK-V8A-GENERIC %s
-// CHECK-V8A-GENERIC: "-cc1"{{.*}} "-triple" "armv8-{{.*}}" "-target-cpu" 
"generic"
+// CHECK-V8A-GENERIC: "-cc1"{{.*}} "-triple" "armv8a-{{.*}}" "-target-cpu" 
"generic"
 
 // RUN: %clang -target armebv8 -### -c %s 2>&1 | FileCheck 
-check-prefix=CHECK-BE-V8A %s
 // RUN: %clang -target armeb -march=armebv8 -### -c %s 2>&1 | FileCheck 
-check-prefix=CHECK-BE-V8A %s
@@ -193,7 +193,7 @@
 // RUN: %clang -target armv8a -mbig-endian -### -c %s 2>&1 | FileCheck 
-check-prefix=CHECK-BE-V8A %s
 // RUN: %clang -target arm -march=armebv8a -mbig-endian -### -c %s 2>&1 | 
FileCheck -check-prefix=CHECK-BE-V8A %s
 // RUN: %clang -target arm -march=armebv8-a -mbig-endian -### -c %s 2>&1 | 
FileCheck -check-prefix=CHECK-BE-V8A %s
-// CHECK-BE-V8A: "-cc1"{{.*}} "-triple" "armebv8-{{.*}}" "-target-cpu" 
"generic"
+// CHECK-BE-V8A: "-cc1"{{.*}} "-triple" "armebv8a-{{.*}}" "-target-cpu" 
"generic"
 
 // RUN: %clang -target armv8 -mthumb -### -c %s 2>&1 | FileCheck 
-check-prefix=CHECK-V8A-THUMB %s
 // RUN: %clang -target arm -march=armv8 -mthumb -### -c %s 2>&1 | FileCheck 
-check-prefix=CHECK-V8A-THUMB %s
@@ -203,7 +203,7 @@
 // RUN: %clang -target arm -march=armv8 -mlittle-endian -mthumb -### -c %s 
2>&1 | FileCheck -check-prefix=CHECK-V8A-THUMB %s
 // RUN: %clang -target armv8a -mlittle-endian -mthumb -### -c %s 2>&1 | 
FileCheck -check-prefix=CHECK-V8A-THUMB %s
 // RUN: %clang -target arm -march=armv8a -mlittle-endian -mthumb -### -c %s 
2>&1 | FileCheck -check-prefix=CHECK-V8A-THUMB %s
-// CHECK-V8A-THUMB: "-cc1"{{.*}} "-triple" "thumbv8-{{.*}}" "-target-cpu" 
"generic"
+// CHECK-V8A-THUMB: "-cc1"{{.*}} "-triple" "thumbv8a-{{.*}}" "-target-cpu" 
"generic"
 
 // RUN: %clang -target armebv8 -mthumb -### -c %s 2>&1 | FileCheck 
-check-prefix=CHECK-BE-V8A-THUMB %s
 // RUN: %clang -target armeb -march=armebv8 -mthumb -### -c %s 2>&1 | 
FileCheck -check-prefix=CHECK-BE-V8A-THUMB %s
@@ -213,7 +213,7 @@
 // RUN: %clang -target arm -march=armebv8 -mbig-endian -mthumb -### -c %s 2>&1 
| FileCheck -check-prefix=CHECK-BE-V8A-THUMB %s
 // R

[clang] 712de9d - [AArch64] Add all predecessor archs in target info

2022-09-27 Thread Daniel Kiss via cfe-commits

Author: Daniel Kiss
Date: 2022-09-27T10:23:21+02:00
New Revision: 712de9d1716c010e895a578ad86cbd47680a4fdd

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

LOG: [AArch64] Add all predecessor archs in target info

A given function is compatible with all previous arch versions.
To avoid compering values of the attribute this logic adds all predecessor
architecture values.

Reviewed By: dmgreen, DavidSpickett

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

Added: 
clang/test/CodeGen/aarch64-subarch-compatbility.c

Modified: 
clang/lib/Basic/Targets/AArch64.cpp
clang/lib/Basic/Targets/AArch64.h
llvm/include/llvm/Support/AArch64TargetParser.def
llvm/include/llvm/Support/AArch64TargetParser.h
llvm/lib/Support/AArch64TargetParser.cpp
llvm/unittests/Support/TargetParserTest.cpp

Removed: 




diff  --git a/clang/lib/Basic/Targets/AArch64.cpp 
b/clang/lib/Basic/Targets/AArch64.cpp
index e8745402b58f..604c7bbb8153 100644
--- a/clang/lib/Basic/Targets/AArch64.cpp
+++ b/clang/lib/Basic/Targets/AArch64.cpp
@@ -529,6 +529,22 @@ bool AArch64TargetInfo::hasFeature(StringRef Feature) 
const {
 .Default(false);
 }
 
+void AArch64TargetInfo::setFeatureEnabled(llvm::StringMap &Features,
+  StringRef Name, bool Enabled) const {
+  Features[Name] = Enabled;
+  llvm::AArch64::ArchKind AK = llvm::AArch64::getSubArchArchKind(Name);
+  // Add all previous architecture versions.
+  // In case of v9.x the v8.x counterparts are added too.
+  if ("9" == getArchVersionString(AK))
+for (llvm::AArch64::ArchKind I = llvm::AArch64::convertV9toV8(AK);
+ I != llvm::AArch64::ArchKind::INVALID; --I)
+  Features[llvm::AArch64::getSubArch(I)] = Enabled;
+
+  for (llvm::AArch64::ArchKind I = --AK; I != llvm::AArch64::ArchKind::INVALID;
+   --I)
+Features[llvm::AArch64::getSubArch(I)] = Enabled;
+}
+
 bool AArch64TargetInfo::handleTargetFeatures(std::vector 
&Features,
  DiagnosticsEngine &Diags) {
   FPU = FPUMode;
@@ -620,31 +636,32 @@ bool 
AArch64TargetInfo::handleTargetFeatures(std::vector &Features,
   HasSM4 = true;
 if (Feature == "+strict-align")
   HasUnaligned = false;
-if (Feature == "+v8a")
+// All predecessor archs are added but select the latest one for ArchKind.
+if (Feature == "+v8a" && ArchKind < llvm::AArch64::ArchKind::ARMV8A)
   ArchKind = llvm::AArch64::ArchKind::ARMV8A;
-if (Feature == "+v8.1a")
+if (Feature == "+v8.1a" && ArchKind < llvm::AArch64::ArchKind::ARMV8_1A)
   ArchKind = llvm::AArch64::ArchKind::ARMV8_1A;
-if (Feature == "+v8.2a")
+if (Feature == "+v8.2a" && ArchKind < llvm::AArch64::ArchKind::ARMV8_2A)
   ArchKind = llvm::AArch64::ArchKind::ARMV8_2A;
-if (Feature == "+v8.3a")
+if (Feature == "+v8.3a" && ArchKind < llvm::AArch64::ArchKind::ARMV8_3A)
   ArchKind = llvm::AArch64::ArchKind::ARMV8_3A;
-if (Feature == "+v8.4a")
+if (Feature == "+v8.4a" && ArchKind < llvm::AArch64::ArchKind::ARMV8_4A)
   ArchKind = llvm::AArch64::ArchKind::ARMV8_4A;
-if (Feature == "+v8.5a")
+if (Feature == "+v8.5a" && ArchKind < llvm::AArch64::ArchKind::ARMV8_5A)
   ArchKind = llvm::AArch64::ArchKind::ARMV8_5A;
-if (Feature == "+v8.6a")
+if (Feature == "+v8.6a" && ArchKind < llvm::AArch64::ArchKind::ARMV8_6A)
   ArchKind = llvm::AArch64::ArchKind::ARMV8_6A;
-if (Feature == "+v8.7a")
+if (Feature == "+v8.7a" && ArchKind < llvm::AArch64::ArchKind::ARMV8_7A)
   ArchKind = llvm::AArch64::ArchKind::ARMV8_7A;
-if (Feature == "+v8.8a")
+if (Feature == "+v8.8a" && ArchKind < llvm::AArch64::ArchKind::ARMV8_8A)
   ArchKind = llvm::AArch64::ArchKind::ARMV8_8A;
-if (Feature == "+v9a")
+if (Feature == "+v9a" && ArchKind < llvm::AArch64::ArchKind::ARMV9A)
   ArchKind = llvm::AArch64::ArchKind::ARMV9A;
-if (Feature == "+v9.1a")
+if (Feature == "+v9.1a" && ArchKind < llvm::AArch64::ArchKind::ARMV9_1A)
   ArchKind = llvm::AArch64::ArchKind::ARMV9_1A;
-if (Feature == "+v9.2a")
+if (Feature == "+v9.2a" && ArchKind < llvm::AArch64::ArchKind::ARMV9_2A)
   ArchKind = llvm::AArch64::ArchKind::ARMV9_2A;
-if (Feature == "+v9.3a")
+if (Feature == "+v9.3a" && ArchKind < llvm::AArch64::ArchKind::ARMV9_3A)
   ArchKind = llvm::AArch64::ArchKind::ARMV9_3A;
 if (Feature == "+v8r")
   ArchKind = llvm::AArch64::ArchKind::ARMV8R;

diff  --git a/clang/lib/Basic/Targets/AArch64.h 
b/clang/lib/Basic/Targets/AArch64.h
index 1930092c248b..302cab409745 100644
--- a/clang/lib/Basic/Targets/AArch64.h
+++ b/clang/lib/Basic/Targets/AArch64.h
@@ -114,6 +114,8 @@ class LLVM_LIBRARY_VISIBILITY AArch64TargetInfo : public 
TargetInfo {
   g

[clang] 30b67c6 - [AArch64] Make ACLE intrinsics always available part1

2022-10-14 Thread Daniel Kiss via cfe-commits

Author: Daniel Kiss
Date: 2022-10-14T17:23:11+02:00
New Revision: 30b67c677c6baf0d6ef6c3051cf270133c43e4d2

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

LOG: [AArch64] Make ACLE intrinsics always available part1

A given arch feature might enabled by a pragma or a function attribute so in 
this cases would be nice to use intrinsics.
Today GCC offers the intrinsics without the march flag[1].
PR[2] for ACLE to clarify the intention and remove the need for -march flag for 
a given intrinsics.

This is going to be more useful when D127812 lands.

[1] https://godbolt.org/z/bxcMhav3z
[2] https://github.com/ARM-software/acle/pull/214

Reviewed By: dmgreen

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

Added: 


Modified: 
clang/include/clang/Basic/BuiltinsAArch64.def
clang/lib/Headers/arm_acle.h
clang/test/CodeGen/arm_acle.c
clang/test/CodeGen/builtins-arm64.c

Removed: 




diff  --git a/clang/include/clang/Basic/BuiltinsAArch64.def 
b/clang/include/clang/Basic/BuiltinsAArch64.def
index 036df7435bfb..e6e375bc2b83 100644
--- a/clang/include/clang/Basic/BuiltinsAArch64.def
+++ b/clang/include/clang/Basic/BuiltinsAArch64.def
@@ -74,7 +74,7 @@ BUILTIN(__builtin_arm_dmb, "vUi", "nc")
 BUILTIN(__builtin_arm_dsb, "vUi", "nc")
 BUILTIN(__builtin_arm_isb, "vUi", "nc")
 
-BUILTIN(__builtin_arm_jcvt, "Zid", "nc")
+TARGET_BUILTIN(__builtin_arm_jcvt, "Zid", "nc", "v8.3a")
 
 // Prefetch
 BUILTIN(__builtin_arm_prefetch, "vvC*UiUiUiUi", "nc")
@@ -107,24 +107,24 @@ BUILTIN(__builtin_arm_tcancel, "vWUIi", "n")
 BUILTIN(__builtin_arm_ttest, "WUi", "nc")
 
 // Armv8.5-A FP rounding intrinsics
-BUILTIN(__builtin_arm_rint32zf, "ff", "")
-BUILTIN(__builtin_arm_rint32z, "dd", "")
-BUILTIN(__builtin_arm_rint64zf, "ff", "")
-BUILTIN(__builtin_arm_rint64z, "dd", "")
-BUILTIN(__builtin_arm_rint32xf, "ff", "")
-BUILTIN(__builtin_arm_rint32x, "dd", "")
-BUILTIN(__builtin_arm_rint64xf, "ff", "")
-BUILTIN(__builtin_arm_rint64x, "dd", "")
+TARGET_BUILTIN(__builtin_arm_rint32zf, "ff", "", "v8.5a")
+TARGET_BUILTIN(__builtin_arm_rint32z, "dd", "", "v8.5a")
+TARGET_BUILTIN(__builtin_arm_rint64zf, "ff", "", "v8.5a")
+TARGET_BUILTIN(__builtin_arm_rint64z, "dd", "", "v8.5a")
+TARGET_BUILTIN(__builtin_arm_rint32xf, "ff", "", "v8.5a")
+TARGET_BUILTIN(__builtin_arm_rint32x, "dd", "", "v8.5a")
+TARGET_BUILTIN(__builtin_arm_rint64xf, "ff", "", "v8.5a")
+TARGET_BUILTIN(__builtin_arm_rint64x, "dd", "", "v8.5a")
 
 // Armv8.5-A Random number generation intrinsics
-BUILTIN(__builtin_arm_rndr,   "iWUi*", "n")
-BUILTIN(__builtin_arm_rndrrs, "iWUi*", "n")
+TARGET_BUILTIN(__builtin_arm_rndr,   "iWUi*", "n", "rand")
+TARGET_BUILTIN(__builtin_arm_rndrrs, "iWUi*", "n", "rand")
 
 // Armv8.7-A load/store 64-byte intrinsics
-BUILTIN(__builtin_arm_ld64b, "vvC*WUi*", "n")
-BUILTIN(__builtin_arm_st64b, "vv*WUiC*", "n")
-BUILTIN(__builtin_arm_st64bv, "WUiv*WUiC*", "n")
-BUILTIN(__builtin_arm_st64bv0, "WUiv*WUiC*", "n")
+TARGET_BUILTIN(__builtin_arm_ld64b, "vvC*WUi*", "n", "ls64")
+TARGET_BUILTIN(__builtin_arm_st64b, "vv*WUiC*", "n", "ls64")
+TARGET_BUILTIN(__builtin_arm_st64bv, "WUiv*WUiC*", "n", "ls64")
+TARGET_BUILTIN(__builtin_arm_st64bv0, "WUiv*WUiC*", "n", "ls64")
 
 TARGET_HEADER_BUILTIN(_BitScanForward, "UcUNi*UNi", "nh", "intrin.h", 
ALL_MS_LANGUAGES, "")
 TARGET_HEADER_BUILTIN(_BitScanReverse, "UcUNi*UNi", "nh", "intrin.h", 
ALL_MS_LANGUAGES, "")

diff  --git a/clang/lib/Headers/arm_acle.h b/clang/lib/Headers/arm_acle.h
index ed3fc1de1fd4..d73b6bf82d69 100644
--- a/clang/lib/Headers/arm_acle.h
+++ b/clang/lib/Headers/arm_acle.h
@@ -589,122 +589,123 @@ __smusdx(int16x2_t __a, int16x2_t __b) {
 #endif
 
 /* 9.7 CRC32 intrinsics */
-#if defined(__ARM_FEATURE_CRC32) && __ARM_FEATURE_CRC32
-static __inline__ uint32_t __attribute__((__always_inline__, __nodebug__))
+#if (defined(__ARM_FEATURE_CRC32) && __ARM_FEATURE_CRC32) ||   
\
+(defined(__ARM_64BIT_STATE) && __ARM_64BIT_STATE)
+static __inline__ uint32_t __attribute__((__always_inline__, __nodebug__, 
target("crc")))
 __crc32b(uint32_t __a, uint8_t __b) {
   return __builtin_arm_crc32b(__a, __b);
 }
 
-static __inline__ uint32_t __attribute__((__always_inline__, __nodebug__))
+static __inline__ uint32_t __attribute__((__always_inline__, __nodebug__, 
target("crc")))
 __crc32h(uint32_t __a, uint16_t __b) {
   return __builtin_arm_crc32h(__a, __b);
 }
 
-static __inline__ uint32_t __attribute__((__always_inline__, __nodebug__))
+static __inline__ uint32_t __attribute__((__always_inline__, __nodebug__, 
target("crc")))
 __crc32w(uint32_t __a, uint32_t __b) {
   return __builtin_arm_crc32w(__a, __b);
 }
 
-static __inline__ uint32_t __attribute__((__always_inline__, __nodebug__))
+static __inline__ uint32_t __attribute__((__always_inline__, __n

[clang] c4fa504 - [AArch64] Enable libm vectorized functions via SLEEF

2023-01-20 Thread Daniel Kiss via cfe-commits

Author: Daniel Kiss
Date: 2023-01-20T18:52:38+01:00
New Revision: c4fa504f797f68297c252dc91a24c7d37c1de4df

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

LOG: [AArch64] Enable libm vectorized functions via SLEEF

It enables trigonometry functions vectorization via SLEEF: http://sleef.org/.

  - A new vectorization library enum is added to TargetLibraryInfo.h: SLEEF.
  - A new option is added to TargetLibraryInfoImpl - ClVectorLibrary: SLEEF.
  - A comprehensive test case is included in this changeset.
  - A new vectorization library argument is added to -fveclib: -fveclib=SLEEF.

Trigonometry functions that are vectorized by sleef:
acos
asin
atan
atanh
cos
cosh
exp
exp2
exp10
lgamma
log10
log2
log
sin
sinh
sqrt
tan
tanh
tgamma

Co-authored-by: Stefan Teleman

Reviewed By: paulwalker-arm

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

Added: 
llvm/test/Transforms/LoopVectorize/AArch64/sleef-calls-aarch64.ll

Modified: 
clang/include/clang/Basic/CodeGenOptions.h
clang/include/clang/Driver/Options.td
clang/lib/CodeGen/BackendUtil.cpp
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/autocomplete.c
clang/test/Driver/fveclib.c
llvm/include/llvm/Analysis/TargetLibraryInfo.h
llvm/include/llvm/Analysis/VecFuncs.def
llvm/lib/Analysis/TargetLibraryInfo.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/CodeGenOptions.h 
b/clang/include/clang/Basic/CodeGenOptions.h
index 4cc0d05d177b3..4175fe3072ab8 100644
--- a/clang/include/clang/Basic/CodeGenOptions.h
+++ b/clang/include/clang/Basic/CodeGenOptions.h
@@ -60,6 +60,7 @@ class CodeGenOptions : public CodeGenOptionsBase {
 LIBMVEC,   // GLIBC vector math library.
 MASSV, // IBM MASS vector library.
 SVML,  // Intel short vector math library.
+SLEEF, // SLEEF SIMD Library for Evaluating Elementary 
Functions.
 Darwin_libsystem_m // Use Darwin's libsytem_m vector functions.
   };
 

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index ec7b5bfa1554a..343cc77a18c43 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2473,9 +2473,9 @@ def fno_experimental_isel : Flag<["-"], 
"fno-experimental-isel">, Group;
 def fveclib : Joined<["-"], "fveclib=">, Group, Flags<[CC1Option]>,
 HelpText<"Use the given vector functions library">,
-Values<"Accelerate,libmvec,MASSV,SVML,Darwin_libsystem_m,none">,
+Values<"Accelerate,libmvec,MASSV,SVML,SLEEF,Darwin_libsystem_m,none">,
 NormalizedValuesScope<"CodeGenOptions">,
-NormalizedValues<["Accelerate", "LIBMVEC", "MASSV", "SVML",
+NormalizedValues<["Accelerate", "LIBMVEC", "MASSV", "SVML", "SLEEF",
   "Darwin_libsystem_m", "NoLibrary"]>,
 MarshallingInfoEnum, "NoLibrary">;
 def fno_lax_vector_conversions : Flag<["-"], "fno-lax-vector-conversions">, 
Group,

diff  --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 937a8dc40667e..ecc727d6dd281 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -271,27 +271,28 @@ static TargetLibraryInfoImpl *createTLII(llvm::Triple 
&TargetTriple,
 
   switch (CodeGenOpts.getVecLib()) {
   case CodeGenOptions::Accelerate:
-
TLII->addVectorizableFunctionsFromVecLib(TargetLibraryInfoImpl::Accelerate);
+TLII->addVectorizableFunctionsFromVecLib(TargetLibraryInfoImpl::Accelerate,
+ TargetTriple);
 break;
   case CodeGenOptions::LIBMVEC:
-switch(TargetTriple.getArch()) {
-  default:
-break;
-  case llvm::Triple::x86_64:
-TLII->addVectorizableFunctionsFromVecLib
-(TargetLibraryInfoImpl::LIBMVEC_X86);
-break;
-}
+
TLII->addVectorizableFunctionsFromVecLib(TargetLibraryInfoImpl::LIBMVEC_X86,
+ TargetTriple);
 break;
   case CodeGenOptions::MASSV:
-TLII->addVectorizableFunctionsFromVecLib(TargetLibraryInfoImpl::MASSV);
+TLII->addVectorizableFunctionsFromVecLib(TargetLibraryInfoImpl::MASSV,
+ TargetTriple);
 break;
   case CodeGenOptions::SVML:
-TLII->addVectorizableFunctionsFromVecLib(TargetLibraryInfoImpl::SVML);
+TLII->addVectorizableFunctionsFromVecLib(TargetLibraryInfoImpl::SVML,
+ TargetTriple);
+break;
+  case CodeGenOptions::SLEEF:
+
TLII->addVectorizableFunctionsFromVecLib(TargetLibraryInfoImpl::SLEEFGNUABI,
+ TargetTriple);
 break;
   case CodeGenOptions::Darwin_libsystem_m:
 TLII->addVectorizableFunctionsFromVecLib(
-

[clang] 1ef3de6 - Disable sanitizer's on ifunc resolvers.

2023-08-14 Thread Daniel Kiss via cfe-commits

Author: Daniel Kiss
Date: 2023-08-14T20:56:55+02:00
New Revision: 1ef3de6b09f6b21a383fc7cf1ce1283df738015a

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

LOG: Disable sanitizer's on ifunc resolvers.

Resolvers are running before the module is initialised which leads to
crashes due to the santizer is not yet initialised.

Fixes #40287

Reviewed By: hctim

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

Added: 


Modified: 
clang/lib/CodeGen/CodeGenModule.cpp
clang/test/CodeGen/ifunc.c

Removed: 




diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 1c48d3b2ace93b..3a79dec5359260 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -5832,7 +5832,9 @@ void CodeGenModule::emitIFuncDefinition(GlobalDecl GD) {
 Entry->eraseFromParent();
   } else
 GIF->setName(MangledName);
-
+  if (auto *F = dyn_cast(Resolver)) {
+F->addFnAttr(llvm::Attribute::DisableSanitizerInstrumentation);
+  }
   SetCommonAttributes(GD, GIF);
 }
 

diff  --git a/clang/test/CodeGen/ifunc.c b/clang/test/CodeGen/ifunc.c
index 64f7f3d4ec65ce..0b0a0549620f8b 100644
--- a/clang/test/CodeGen/ifunc.c
+++ b/clang/test/CodeGen/ifunc.c
@@ -1,5 +1,8 @@
 // RUN: %clang_cc1 -triple i386-unknown-linux-gnu -emit-llvm -o - %s | 
FileCheck %s
 // RUN: %clang_cc1 -triple i386-unknown-linux-gnu -O2 -emit-llvm -o - %s | 
FileCheck %s
+// RUN: %clang_cc1 -triple i386-unknown-linux-gnu -fsanitize=thread -O2 
-emit-llvm -o - %s | FileCheck %s --check-prefix=SAN
+// RUN: %clang_cc1 -triple i386-unknown-linux-gnu -fsanitize=address -O2 
-emit-llvm -o - %s | FileCheck %s --check-prefix=SAN
+// RUN: %clang_cc1 -triple i386-unknown-linux-gnu -fsanitize=memory -O2 
-emit-llvm -o - %s | FileCheck %s --check-prefix=SAN
 
 int foo(int) __attribute__ ((ifunc("foo_ifunc")));
 
@@ -39,3 +42,11 @@ void* goo_ifunc(void) {
 
 // CHECK: call i32 @foo(i32
 // CHECK: call void @goo()
+
+// SAN: define internal nonnull ptr @foo_ifunc() #[[#FOO_IFUNC:]] {
+
+// SAN: define dso_local noalias ptr @goo_ifunc() #[[#GOO_IFUNC:]] {
+
+// SAN-DAG: attributes #[[#FOO_IFUNC]] = {{{.*}} 
disable_sanitizer_instrumentation {{.*}}
+
+// SAN-DAG: attributes #[[#GOO_IFUNC]] = {{{.*}} 
disable_sanitizer_instrumentation {{.*}}



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


[clang] 7314aea - [clang] Move branch-protection from CodeGenOptions to LangOptions

2020-04-02 Thread Daniel Kiss via cfe-commits

Author: Daniel Kiss
Date: 2020-04-02T10:31:52+02:00
New Revision: 7314aea5a42d33f9f5af5d158d8892e88072764e

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

LOG: [clang] Move branch-protection from CodeGenOptions to  LangOptions

Summary:
Reason: the option has an effect on preprocessing.

Also see thread: http://lists.llvm.org/pipermail/cfe-dev/2020-March/065014.html

Reviewers: chill, efriedma

Reviewed By: efriedma

Subscribers: efriedma, danielkiss, cfe-commits, kristof.beyls

Tags: #clang

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

Added: 


Modified: 
clang/include/clang/Basic/CodeGenOptions.def
clang/include/clang/Basic/CodeGenOptions.h
clang/include/clang/Basic/LangOptions.def
clang/include/clang/Basic/LangOptions.h
clang/include/clang/Basic/TargetInfo.h
clang/lib/AST/PrintfFormatString.cpp
clang/lib/Basic/Targets/AArch64.cpp
clang/lib/CodeGen/CGDeclCXX.cpp
clang/lib/CodeGen/TargetInfo.cpp
clang/lib/Frontend/CompilerInvocation.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/CodeGenOptions.def 
b/clang/include/clang/Basic/CodeGenOptions.def
index a62cf5e729db..0faa013ac497 100644
--- a/clang/include/clang/Basic/CodeGenOptions.def
+++ b/clang/include/clang/Basic/CodeGenOptions.def
@@ -387,10 +387,6 @@ CODEGENOPT(ForceEmitVTables, 1, 0)
 /// Whether to emit an address-significance table into the object file.
 CODEGENOPT(Addrsig, 1, 0)
 
-ENUM_CODEGENOPT(SignReturnAddress, SignReturnAddressScope, 2, 
SignReturnAddressScope::None)
-ENUM_CODEGENOPT(SignReturnAddressKey, SignReturnAddressKeyValue, 1, 
SignReturnAddressKeyValue::AKey)
-CODEGENOPT(BranchTargetEnforcement, 1, 0)
-
 /// Whether to emit unused static constants.
 CODEGENOPT(KeepStaticConsts, 1, 0)
 
@@ -400,4 +396,3 @@ CODEGENOPT(ForceAAPCSBitfieldLoad, 1, 0)
 #undef CODEGENOPT
 #undef ENUM_CODEGENOPT
 #undef VALUE_CODEGENOPT
-

diff  --git a/clang/include/clang/Basic/CodeGenOptions.h 
b/clang/include/clang/Basic/CodeGenOptions.h
index d435bebcdcf9..60d418688710 100644
--- a/clang/include/clang/Basic/CodeGenOptions.h
+++ b/clang/include/clang/Basic/CodeGenOptions.h
@@ -110,14 +110,6 @@ class CodeGenOptions : public CodeGenOptionsBase {
 Embed_Marker// Embed a marker as a placeholder for bitcode.
   };
 
-  enum class SignReturnAddressScope {
-None,// No signing for any function
-NonLeaf, // Sign the return address of functions that spill LR
-All  // Sign the return address of all functions
-  };
-
-  enum class SignReturnAddressKeyValue { AKey, BKey };
-
   enum class FramePointerKind {
 None,// Omit all frame pointers.
 NonLeaf, // Keep non-leaf frame pointers.

diff  --git a/clang/include/clang/Basic/LangOptions.def 
b/clang/include/clang/Basic/LangOptions.def
index 6152e227d599..51dc87b0b671 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -353,6 +353,12 @@ LANGOPT(RegisterStaticDestructors, 1, 1, "Register C++ 
static destructors")
 
 COMPATIBLE_VALUE_LANGOPT(MaxTokens, 32, 0, "Max number of tokens per TU or 0")
 
+ENUM_LANGOPT(SignReturnAddressScope, SignReturnAddressScopeKind, 2, 
SignReturnAddressScopeKind::None,
+ "Scope of return address signing")
+ENUM_LANGOPT(SignReturnAddressKey, SignReturnAddressKeyKind, 1, 
SignReturnAddressKeyKind::AKey,
+ "Key used for return address signing")
+LANGOPT(BranchTargetEnforcement, 1, 0, "Branch-target enforcement enabled")
+
 #undef LANGOPT
 #undef COMPATIBLE_LANGOPT
 #undef BENIGN_LANGOPT

diff  --git a/clang/include/clang/Basic/LangOptions.h 
b/clang/include/clang/Basic/LangOptions.h
index 524ae9a822f4..090263342401 100644
--- a/clang/include/clang/Basic/LangOptions.h
+++ b/clang/include/clang/Basic/LangOptions.h
@@ -229,6 +229,22 @@ class LangOptions : public LangOptionsBase {
 All,
   };
 
+  enum class SignReturnAddressScopeKind {
+/// No signing for any function.
+None,
+/// Sign the return address of functions that spill LR.
+NonLeaf,
+/// Sign the return address of all functions,
+All
+  };
+
+  enum class SignReturnAddressKeyKind {
+/// Return address signing uses APIA key.
+AKey,
+/// Return address signing uses APIB key.
+BKey
+  };
+
 public:
   /// Set of enabled sanitizers.
   SanitizerSet Sanitize;

diff  --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index 5edfa0e4e0c7..ab4795404071 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -16,7 +16,7 @@
 
 #include "clang/Basic/AddressSpaces.h"
 #include "clang/Basic/LLVM.h"
-#include "clang/Basic/CodeGenOptions.h"
+#include "clang/Basic/LangOptions.h"
 #include "clang/Basic/Specifiers.h"
 #in

[clang] 37ced5a - [clang][AARCH64] Add __ARM_FEATURE_{PAC, BTI}_DEFAULT defines

2020-04-02 Thread Daniel Kiss via cfe-commits

Author: Daniel Kiss
Date: 2020-04-02T12:54:21+02:00
New Revision: 37ced5a571066c11548c672f354c6091f5903991

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

LOG: [clang][AARCH64] Add __ARM_FEATURE_{PAC, BTI}_DEFAULT  defines

Summary:
As defined by Arm C Language Extensions (ACLE) these macro defines
should be set to specific values depending on -mbranch-protection.

Reviewers: chill

Reviewed By: chill

Subscribers: danielkiss, cfe-commits, kristof.beyls

Tags: #clang

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

Added: 


Modified: 
clang/include/clang/Basic/LangOptions.h
clang/lib/Basic/Targets/AArch64.cpp
clang/test/Preprocessor/aarch64-target-features.c

Removed: 




diff  --git a/clang/include/clang/Basic/LangOptions.h 
b/clang/include/clang/Basic/LangOptions.h
index 090263342401..0a0cbaf80ae8 100644
--- a/clang/include/clang/Basic/LangOptions.h
+++ b/clang/include/clang/Basic/LangOptions.h
@@ -367,6 +367,21 @@ class LangOptions : public LangOptionsBase {
 
   /// Return the OpenCL C or C++ version as a VersionTuple.
   VersionTuple getOpenCLVersionTuple() const;
+
+  /// Check if return address signing is enabled.
+  bool hasSignReturnAddress() const {
+return getSignReturnAddressScope() != SignReturnAddressScopeKind::None;
+  }
+
+  /// Check if return address signing uses AKey.
+  bool isSignReturnAddressWithAKey() const {
+return getSignReturnAddressKey() == SignReturnAddressKeyKind::AKey;
+  }
+
+  /// Check if leaf functions are also signed.
+  bool isSignReturnAddressScopeAll() const {
+return getSignReturnAddressScope() == SignReturnAddressScopeKind::All;
+  }
 };
 
 /// Floating point control options

diff  --git a/clang/lib/Basic/Targets/AArch64.cpp 
b/clang/lib/Basic/Targets/AArch64.cpp
index f70a53457613..8ceb7f2b515e 100644
--- a/clang/lib/Basic/Targets/AArch64.cpp
+++ b/clang/lib/Basic/Targets/AArch64.cpp
@@ -283,6 +283,27 @@ void AArch64TargetInfo::getTargetDefines(const LangOptions 
&Opts,
   if ((FPU & NeonMode) && HasFP16FML)
 Builder.defineMacro("__ARM_FEATURE_FP16FML", "1");
 
+  if (Opts.hasSignReturnAddress()) {
+// Bitmask:
+// 0: Protection using the A key
+// 1: Protection using the B key
+// 2: Protection including leaf functions
+unsigned Value = 0;
+
+if (Opts.isSignReturnAddressWithAKey())
+  Value |= (1 << 0);
+else
+  Value |= (1 << 1);
+
+if (Opts.isSignReturnAddressScopeAll())
+  Value |= (1 << 2);
+
+Builder.defineMacro("__ARM_FEATURE_PAC_DEFAULT", std::to_string(Value));
+  }
+
+  if (Opts.BranchTargetEnforcement)
+Builder.defineMacro("__ARM_FEATURE_BTI_DEFAULT", "1");
+
   switch (ArchKind) {
   default:
 break;

diff  --git a/clang/test/Preprocessor/aarch64-target-features.c 
b/clang/test/Preprocessor/aarch64-target-features.c
index c62c82a0c96a..9cb12f8afb32 100644
--- a/clang/test/Preprocessor/aarch64-target-features.c
+++ b/clang/test/Preprocessor/aarch64-target-features.c
@@ -39,6 +39,8 @@
 // CHECK-NOT: __ARM_SIZEOF_WCHAR_T 2
 // CHECK-NOT: __ARM_FEATURE_SVE
 // CHECK-NOT: __ARM_FEATURE_DOTPROD
+// CHECK-NOT: __ARM_FEATURE_PAC_DEFAULT
+// CHECK-NOT: __ARM_FEATURE_BTI_DEFAULT
 
 // RUN: %clang -target aarch64-none-linux-gnu -march=armv8-a+crypto -x c -E 
-dM %s -o - | FileCheck --check-prefix=CHECK-CRYPTO %s
 // RUN: %clang -target arm64-none-linux-gnu -march=armv8-a+crypto -x c -E -dM 
%s -o - | FileCheck --check-prefix=CHECK-CRYPTO %s
@@ -334,3 +336,33 @@
 // == Check Memory Tagging Extensions (MTE).
 // RUN: %clang -target arm64-none-linux-gnu -march=armv8.5-a+memtag -x c -E 
-dM %s -o - 2>&1 | FileCheck -check-prefix=CHECK-MEMTAG %s
 // CHECK-MEMTAG: __ARM_FEATURE_MEMORY_TAGGING 1
+
+// == Check Pointer Authentication Extension (PAuth).
+// RUN: %clang -target arm64-none-linux-gnu -march=armv8-a -x c -E -dM %s -o - 
| FileCheck -check-prefix=CHECK-PAUTH-OFF %s
+// RUN: %clang -target arm64-none-linux-gnu -march=armv8.5-a -x c -E -dM %s -o 
- | FileCheck -check-prefix=CHECK-PAUTH-OFF %s
+// RUN: %clang -target arm64-none-linux-gnu -march=armv8-a 
-mbranch-protection=none -x c -E -dM %s -o - | FileCheck 
-check-prefix=CHECK-PAUTH-OFF %s
+// RUN: %clang -target arm64-none-linux-gnu -march=armv8-a 
-mbranch-protection=bti -x c -E -dM %s -o - | FileCheck 
-check-prefix=CHECK-PAUTH-OFF %s
+// RUN: %clang -target arm64-none-linux-gnu -march=armv8-a 
-mbranch-protection=standard -x c -E -dM %s -o - | FileCheck 
-check-prefix=CHECK-PAUTH %s
+// RUN: %clang -target arm64-none-linux-gnu -march=armv8-a 
-mbranch-protection=pac-ret -x c -E -dM %s -o - | FileCheck 
-check-prefix=CHECK-PAUTH %s
+// RUN: %clang -target arm64-none-linux-gnu -march=armv8-a 
-mbranch-protection=pac-ret+b-key -x c -E -dM %s -o - | FileCheck 

[clang] d75e70d - [AArch64] Add preserve_all calling convention.

2023-04-28 Thread Daniel Kiss via cfe-commits

Author: Daniel Kiss
Date: 2023-04-28T14:55:38+02:00
New Revision: d75e70d7ae1f84cea71f0be5fbee836bdc22138a

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

LOG: [AArch64] Add preserve_all calling convention.

Clang accepts preserve_all for AArch64 while it is missing form the backed.

Fixes #58145

Reviewed By: efriedma

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

Added: 
llvm/test/CodeGen/AArch64/arm64-preserve-all.ll
llvm/test/CodeGen/AArch64/preserve.ll
llvm/test/CodeGen/AArch64/tailcall-ccmismatch2.ll

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/AttrDocs.td
llvm/docs/LangRef.rst
llvm/docs/ReleaseNotes.rst
llvm/lib/Target/AArch64/AArch64CallingConvention.td
llvm/lib/Target/AArch64/AArch64FrameLowering.cpp
llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp
llvm/lib/Target/AArch64/GISel/AArch64CallLowering.cpp
llvm/lib/Target/ARM/ARMISelLowering.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index a61e6615b9371..87db8cedd6a7b 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -432,6 +432,9 @@ Arm and AArch64 Support
  // int a = foo(); int* b = bar();
  asm("ands %w[a], %w[a], #3" : [a] "+r"(a), "=@cceq"(*b));
 
+- Fix a crash when ``preserve_all`` calling convention is used on AArch64.
+  `Issue 58145 `_
+
 Windows Support
 ^^^
 

diff  --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index dae12624a822b..0a0afe619ec2c 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -5182,6 +5182,9 @@ apply for values returned in callee-saved registers.
   R11. R11 can be used as a scratch register. Floating-point registers
   (XMMs/YMMs) are not preserved and need to be saved by the caller.
 
+- On AArch64 the callee preserve all general purpose registers, except X0-X8 
and
+  X16-X18.
+
 The idea behind this convention is to support calls to runtime functions
 that have a hot path and a cold path. The hot path is usually a small piece
 of code that doesn't use many registers. The cold path might need to call out 
to
@@ -5222,6 +5225,10 @@ returned in callee-saved registers.
   R11. R11 can be used as a scratch register. Furthermore it also preserves
   all floating-point registers (XMMs/YMMs).
 
+- On AArch64 the callee preserve all general purpose registers, except X0-X8 
and
+  X16-X18. Furthermore it also preserves lower 128 bits of V8-V31 SIMD - 
floating
+  point registers.
+
 The idea behind this convention is to support calls to runtime functions
 that don't need to call out to any other functions.
 

diff  --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst
index a0d012d3a14f5..48e658d08e7b3 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -370,6 +370,9 @@ added in the future:
   Floating-point registers (XMMs/YMMs) are not preserved and need to be
   saved by the caller.
 
+- On AArch64 the callee preserve all general purpose registers, except 
X0-X8
+  and X16-X18.
+
 The idea behind this convention is to support calls to runtime functions
 that have a hot path and a cold path. The hot path is usually a small piece
 of code that doesn't use many registers. The cold path might need to call 
out to
@@ -404,6 +407,10 @@ added in the future:
   R11. R11 can be used as a scratch register. Furthermore it also preserves
   all floating-point registers (XMMs/YMMs).
 
+- On AArch64 the callee preserve all general purpose registers, except 
X0-X8
+  and X16-X18. Furthermore it also preserves lower 128 bits of V8-V31 SIMD 
-
+  floating point registers.
+
 The idea behind this convention is to support calls to runtime functions
 that don't need to call out to any other functions.
 

diff  --git a/llvm/docs/ReleaseNotes.rst b/llvm/docs/ReleaseNotes.rst
index c5bf6cbeb6fde..334365fa0a8a4 100644
--- a/llvm/docs/ReleaseNotes.rst
+++ b/llvm/docs/ReleaseNotes.rst
@@ -84,6 +84,7 @@ Changes to the AArch64 Backend
 
 * Added Assembly Support for the 2022 A-profile extensions FEAT_GCS (Guarded
   Control Stacks), FEAT_CHK (Check Feature Status), and FEAT_ATS1A.
+* Support for preserve_all calling convention is added.
 
 Changes to the AMDGPU Backend
 -

diff  --git a/llvm/lib/Target/AArch64/AArch64CallingConvention.td 
b/llvm/lib/Target/AArch64/AArch64CallingConvention.td
index 853975c6193d9..ce087be79202e 100644
--- a/llvm/lib/Target/AArch64/AArch64CallingConvention.td
+++ b/llvm/lib/Target/AArch64/AArch64CallingConvention.td
@@ -489,6 +489,9 @@ def CS

[clang] cfd4422 - [AArch64] Add __ARM_FEATURE_BTI and __ARM_FEATURE_PAUTH

2022-12-07 Thread Daniel Kiss via cfe-commits

Author: Daniel Kiss
Date: 2022-12-07T14:52:55+01:00
New Revision: cfd44221e3e1783c0f44d5b1694dfbe84187246a

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

LOG: [AArch64] Add __ARM_FEATURE_BTI and __ARM_FEATURE_PAUTH

Macros are added to ACLE[1] and already added to ARM but these two are missing 
from AArch64.

[1] 
https://github.com/ARM-software/acle/blob/main/main/acle.md#changes-between-acle-q3-2021-and-acle-q4-2021

Reviewed By: chill

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

Added: 


Modified: 
clang/lib/Basic/Targets/AArch64.cpp
clang/test/Preprocessor/aarch64-target-features.c

Removed: 




diff  --git a/clang/lib/Basic/Targets/AArch64.cpp 
b/clang/lib/Basic/Targets/AArch64.cpp
index c5fce62bc501f..1abe646f88bfd 100644
--- a/clang/lib/Basic/Targets/AArch64.cpp
+++ b/clang/lib/Basic/Targets/AArch64.cpp
@@ -199,6 +199,7 @@ void AArch64TargetInfo::getTargetDefinesARMV83A(const 
LangOptions &Opts,
 MacroBuilder &Builder) const {
   Builder.defineMacro("__ARM_FEATURE_COMPLEX", "1");
   Builder.defineMacro("__ARM_FEATURE_JCVT", "1");
+  Builder.defineMacro("__ARM_FEATURE_PAUTH", "1");
   // Also include the Armv8.2 defines
   getTargetDefinesARMV82A(Opts, Builder);
 }
@@ -212,6 +213,7 @@ void AArch64TargetInfo::getTargetDefinesARMV84A(const 
LangOptions &Opts,
 void AArch64TargetInfo::getTargetDefinesARMV85A(const LangOptions &Opts,
 MacroBuilder &Builder) const {
   Builder.defineMacro("__ARM_FEATURE_FRINT", "1");
+  Builder.defineMacro("__ARM_FEATURE_BTI", "1");
   // Also include the Armv8.4 defines
   getTargetDefinesARMV84A(Opts, Builder);
 }
@@ -385,6 +387,9 @@ void AArch64TargetInfo::getTargetDefines(const LangOptions 
&Opts,
 Builder.defineMacro("__ARM_FEATURE_SM4", "1");
   }
 
+  if (HasPAuth)
+Builder.defineMacro("__ARM_FEATURE_PAUTH", "1");
+
   if (HasUnaligned)
 Builder.defineMacro("__ARM_FEATURE_UNALIGNED", "1");
 

diff  --git a/clang/test/Preprocessor/aarch64-target-features.c 
b/clang/test/Preprocessor/aarch64-target-features.c
index 40ea003a85848..53b6644ef12e6 100644
--- a/clang/test/Preprocessor/aarch64-target-features.c
+++ b/clang/test/Preprocessor/aarch64-target-features.c
@@ -461,6 +461,7 @@
 // == Check Pointer Authentication Extension (PAuth).
 // RUN: %clang -target arm64-none-linux-gnu -march=armv8-a -x c -E -dM %s -o - 
| FileCheck -check-prefix=CHECK-PAUTH-OFF %s
 // RUN: %clang -target arm64-none-linux-gnu -march=armv8.5-a -x c -E -dM %s -o 
- | FileCheck -check-prefix=CHECK-PAUTH-OFF %s
+// RUN: %clang -target arm64-none-linux-gnu -march=armv8-a+pauth 
-mbranch-protection=none -x c -E -dM %s -o - | FileCheck 
-check-prefix=CHECK-PAUTH-ON %s
 // RUN: %clang -target arm64-none-linux-gnu -march=armv8-a 
-mbranch-protection=none -x c -E -dM %s -o - | FileCheck 
-check-prefix=CHECK-PAUTH-OFF %s
 // RUN: %clang -target arm64-none-linux-gnu -march=armv8-a 
-mbranch-protection=bti -x c -E -dM %s -o - | FileCheck 
-check-prefix=CHECK-PAUTH-OFF %s
 // RUN: %clang -target arm64-none-linux-gnu -march=armv8-a 
-mbranch-protection=standard -x c -E -dM %s -o - | FileCheck 
-check-prefix=CHECK-PAUTH %s
@@ -473,6 +474,7 @@
 // CHECK-PAUTH-BKEY: #define __ARM_FEATURE_PAC_DEFAULT 2
 // CHECK-PAUTH-ALL:  #define __ARM_FEATURE_PAC_DEFAULT 5
 // CHECK-PAUTH-BKEY-ALL: #define __ARM_FEATURE_PAC_DEFAULT 6
+// CHECK-PAUTH-ON:   #define __ARM_FEATURE_PAUTH 1
 
 // == Check Branch Target Identification (BTI).
 // RUN: %clang -target arm64-none-linux-gnu -march=armv8-a -x c -E -dM %s -o - 
| FileCheck -check-prefix=CHECK-BTI-OFF %s
@@ -560,10 +562,12 @@
 // RUN: %clang -target aarch64-arm-none-eabi -march=armv9.2-a -x c -E -dM %s 
-o - | FileCheck 
--check-prefixes=CHECK-V81-OR-LATER,CHECK-V83-OR-LATER,CHECK-V85-OR-LATER %s
 // RUN: %clang -target aarch64-arm-none-eabi -march=armv9.3-a -x c -E -dM %s 
-o - | FileCheck 
--check-prefixes=CHECK-V81-OR-LATER,CHECK-V83-OR-LATER,CHECK-V85-OR-LATER %s
 // CHECK-V81-OR-LATER: __ARM_FEATURE_ATOMICS 1
+// CHECK-V85-OR-LATER: __ARM_FEATURE_BTI 1
 // CHECK-V83-OR-LATER: __ARM_FEATURE_COMPLEX 1
 // CHECK-V81-OR-LATER: __ARM_FEATURE_CRC32 1
 // CHECK-V85-OR-LATER: __ARM_FEATURE_FRINT 1
 // CHECK-V83-OR-LATER: __ARM_FEATURE_JCVT 1
+// CHECK-V83-OR-LATER: __ARM_FEATURE_PAUTH 1
 // CHECK-V81-OR-LATER: __ARM_FEATURE_QRDMX 1
 // CHECK-BEFORE-V83-NOT: __ARM_FEATURE_COMPLEX 1
 // CHECK-BEFORE-V83-NOT: __ARM_FEATURE_JCVT 1



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


[clang] 7925e28 - Revert "[AArch64] Add __ARM_FEATURE_BTI and __ARM_FEATURE_PAUTH"

2022-12-07 Thread Daniel Kiss via cfe-commits

Author: Daniel Kiss
Date: 2022-12-07T15:19:31+01:00
New Revision: 7925e2828e3290f2851f29aec66c882597f8bc61

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

LOG: Revert "[AArch64] Add __ARM_FEATURE_BTI and __ARM_FEATURE_PAUTH"

This reverts commit cfd44221e3e1783c0f44d5b1694dfbe84187246a.

Added: 


Modified: 
clang/lib/Basic/Targets/AArch64.cpp
clang/test/Preprocessor/aarch64-target-features.c

Removed: 




diff  --git a/clang/lib/Basic/Targets/AArch64.cpp 
b/clang/lib/Basic/Targets/AArch64.cpp
index 1abe646f88bfd..c5fce62bc501f 100644
--- a/clang/lib/Basic/Targets/AArch64.cpp
+++ b/clang/lib/Basic/Targets/AArch64.cpp
@@ -199,7 +199,6 @@ void AArch64TargetInfo::getTargetDefinesARMV83A(const 
LangOptions &Opts,
 MacroBuilder &Builder) const {
   Builder.defineMacro("__ARM_FEATURE_COMPLEX", "1");
   Builder.defineMacro("__ARM_FEATURE_JCVT", "1");
-  Builder.defineMacro("__ARM_FEATURE_PAUTH", "1");
   // Also include the Armv8.2 defines
   getTargetDefinesARMV82A(Opts, Builder);
 }
@@ -213,7 +212,6 @@ void AArch64TargetInfo::getTargetDefinesARMV84A(const 
LangOptions &Opts,
 void AArch64TargetInfo::getTargetDefinesARMV85A(const LangOptions &Opts,
 MacroBuilder &Builder) const {
   Builder.defineMacro("__ARM_FEATURE_FRINT", "1");
-  Builder.defineMacro("__ARM_FEATURE_BTI", "1");
   // Also include the Armv8.4 defines
   getTargetDefinesARMV84A(Opts, Builder);
 }
@@ -387,9 +385,6 @@ void AArch64TargetInfo::getTargetDefines(const LangOptions 
&Opts,
 Builder.defineMacro("__ARM_FEATURE_SM4", "1");
   }
 
-  if (HasPAuth)
-Builder.defineMacro("__ARM_FEATURE_PAUTH", "1");
-
   if (HasUnaligned)
 Builder.defineMacro("__ARM_FEATURE_UNALIGNED", "1");
 

diff  --git a/clang/test/Preprocessor/aarch64-target-features.c 
b/clang/test/Preprocessor/aarch64-target-features.c
index 53b6644ef12e6..40ea003a85848 100644
--- a/clang/test/Preprocessor/aarch64-target-features.c
+++ b/clang/test/Preprocessor/aarch64-target-features.c
@@ -461,7 +461,6 @@
 // == Check Pointer Authentication Extension (PAuth).
 // RUN: %clang -target arm64-none-linux-gnu -march=armv8-a -x c -E -dM %s -o - 
| FileCheck -check-prefix=CHECK-PAUTH-OFF %s
 // RUN: %clang -target arm64-none-linux-gnu -march=armv8.5-a -x c -E -dM %s -o 
- | FileCheck -check-prefix=CHECK-PAUTH-OFF %s
-// RUN: %clang -target arm64-none-linux-gnu -march=armv8-a+pauth 
-mbranch-protection=none -x c -E -dM %s -o - | FileCheck 
-check-prefix=CHECK-PAUTH-ON %s
 // RUN: %clang -target arm64-none-linux-gnu -march=armv8-a 
-mbranch-protection=none -x c -E -dM %s -o - | FileCheck 
-check-prefix=CHECK-PAUTH-OFF %s
 // RUN: %clang -target arm64-none-linux-gnu -march=armv8-a 
-mbranch-protection=bti -x c -E -dM %s -o - | FileCheck 
-check-prefix=CHECK-PAUTH-OFF %s
 // RUN: %clang -target arm64-none-linux-gnu -march=armv8-a 
-mbranch-protection=standard -x c -E -dM %s -o - | FileCheck 
-check-prefix=CHECK-PAUTH %s
@@ -474,7 +473,6 @@
 // CHECK-PAUTH-BKEY: #define __ARM_FEATURE_PAC_DEFAULT 2
 // CHECK-PAUTH-ALL:  #define __ARM_FEATURE_PAC_DEFAULT 5
 // CHECK-PAUTH-BKEY-ALL: #define __ARM_FEATURE_PAC_DEFAULT 6
-// CHECK-PAUTH-ON:   #define __ARM_FEATURE_PAUTH 1
 
 // == Check Branch Target Identification (BTI).
 // RUN: %clang -target arm64-none-linux-gnu -march=armv8-a -x c -E -dM %s -o - 
| FileCheck -check-prefix=CHECK-BTI-OFF %s
@@ -562,12 +560,10 @@
 // RUN: %clang -target aarch64-arm-none-eabi -march=armv9.2-a -x c -E -dM %s 
-o - | FileCheck 
--check-prefixes=CHECK-V81-OR-LATER,CHECK-V83-OR-LATER,CHECK-V85-OR-LATER %s
 // RUN: %clang -target aarch64-arm-none-eabi -march=armv9.3-a -x c -E -dM %s 
-o - | FileCheck 
--check-prefixes=CHECK-V81-OR-LATER,CHECK-V83-OR-LATER,CHECK-V85-OR-LATER %s
 // CHECK-V81-OR-LATER: __ARM_FEATURE_ATOMICS 1
-// CHECK-V85-OR-LATER: __ARM_FEATURE_BTI 1
 // CHECK-V83-OR-LATER: __ARM_FEATURE_COMPLEX 1
 // CHECK-V81-OR-LATER: __ARM_FEATURE_CRC32 1
 // CHECK-V85-OR-LATER: __ARM_FEATURE_FRINT 1
 // CHECK-V83-OR-LATER: __ARM_FEATURE_JCVT 1
-// CHECK-V83-OR-LATER: __ARM_FEATURE_PAUTH 1
 // CHECK-V81-OR-LATER: __ARM_FEATURE_QRDMX 1
 // CHECK-BEFORE-V83-NOT: __ARM_FEATURE_COMPLEX 1
 // CHECK-BEFORE-V83-NOT: __ARM_FEATURE_JCVT 1



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


[clang] 7d40baa - [AArch64] Add __ARM_FEATURE_BTI and __ARM_FEATURE_PAUTH

2022-12-07 Thread Daniel Kiss via cfe-commits

Author: Daniel Kiss
Date: 2022-12-07T16:30:16+01:00
New Revision: 7d40baa82b1f272f68de63f3c4f68d970bdcd6ed

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

LOG: [AArch64] Add __ARM_FEATURE_BTI and __ARM_FEATURE_PAUTH

Macros are added to ACLE[1] and already added to ARM but these two are missing 
from AArch64.

[1] 
https://github.com/ARM-software/acle/blob/main/main/acle.md#changes-between-acle-q3-2021-and-acle-q4-2021

Reviewed By: chill

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

Added: 


Modified: 
clang/lib/Basic/Targets/AArch64.cpp
clang/test/Preprocessor/aarch64-target-features.c

Removed: 




diff  --git a/clang/lib/Basic/Targets/AArch64.cpp 
b/clang/lib/Basic/Targets/AArch64.cpp
index c5fce62bc501f..89ad602b591f5 100644
--- a/clang/lib/Basic/Targets/AArch64.cpp
+++ b/clang/lib/Basic/Targets/AArch64.cpp
@@ -199,6 +199,7 @@ void AArch64TargetInfo::getTargetDefinesARMV83A(const 
LangOptions &Opts,
 MacroBuilder &Builder) const {
   Builder.defineMacro("__ARM_FEATURE_COMPLEX", "1");
   Builder.defineMacro("__ARM_FEATURE_JCVT", "1");
+  Builder.defineMacro("__ARM_FEATURE_PAUTH", "1");
   // Also include the Armv8.2 defines
   getTargetDefinesARMV82A(Opts, Builder);
 }
@@ -212,6 +213,7 @@ void AArch64TargetInfo::getTargetDefinesARMV84A(const 
LangOptions &Opts,
 void AArch64TargetInfo::getTargetDefinesARMV85A(const LangOptions &Opts,
 MacroBuilder &Builder) const {
   Builder.defineMacro("__ARM_FEATURE_FRINT", "1");
+  Builder.defineMacro("__ARM_FEATURE_BTI", "1");
   // Also include the Armv8.4 defines
   getTargetDefinesARMV84A(Opts, Builder);
 }
@@ -385,6 +387,9 @@ void AArch64TargetInfo::getTargetDefines(const LangOptions 
&Opts,
 Builder.defineMacro("__ARM_FEATURE_SM4", "1");
   }
 
+  if (HasPAuth)
+Builder.defineMacro("__ARM_FEATURE_PAUTH", "1");
+
   if (HasUnaligned)
 Builder.defineMacro("__ARM_FEATURE_UNALIGNED", "1");
 
@@ -601,6 +606,7 @@ bool 
AArch64TargetInfo::handleTargetFeatures(std::vector &Features,
   HasMOPS = false;
   HasD128 = false;
   HasRCPC = false;
+  HasPAuth = false;
 
   ArchKind = llvm::AArch64::ArchKind::INVALID;
 

diff  --git a/clang/test/Preprocessor/aarch64-target-features.c 
b/clang/test/Preprocessor/aarch64-target-features.c
index 40ea003a85848..53b6644ef12e6 100644
--- a/clang/test/Preprocessor/aarch64-target-features.c
+++ b/clang/test/Preprocessor/aarch64-target-features.c
@@ -461,6 +461,7 @@
 // == Check Pointer Authentication Extension (PAuth).
 // RUN: %clang -target arm64-none-linux-gnu -march=armv8-a -x c -E -dM %s -o - 
| FileCheck -check-prefix=CHECK-PAUTH-OFF %s
 // RUN: %clang -target arm64-none-linux-gnu -march=armv8.5-a -x c -E -dM %s -o 
- | FileCheck -check-prefix=CHECK-PAUTH-OFF %s
+// RUN: %clang -target arm64-none-linux-gnu -march=armv8-a+pauth 
-mbranch-protection=none -x c -E -dM %s -o - | FileCheck 
-check-prefix=CHECK-PAUTH-ON %s
 // RUN: %clang -target arm64-none-linux-gnu -march=armv8-a 
-mbranch-protection=none -x c -E -dM %s -o - | FileCheck 
-check-prefix=CHECK-PAUTH-OFF %s
 // RUN: %clang -target arm64-none-linux-gnu -march=armv8-a 
-mbranch-protection=bti -x c -E -dM %s -o - | FileCheck 
-check-prefix=CHECK-PAUTH-OFF %s
 // RUN: %clang -target arm64-none-linux-gnu -march=armv8-a 
-mbranch-protection=standard -x c -E -dM %s -o - | FileCheck 
-check-prefix=CHECK-PAUTH %s
@@ -473,6 +474,7 @@
 // CHECK-PAUTH-BKEY: #define __ARM_FEATURE_PAC_DEFAULT 2
 // CHECK-PAUTH-ALL:  #define __ARM_FEATURE_PAC_DEFAULT 5
 // CHECK-PAUTH-BKEY-ALL: #define __ARM_FEATURE_PAC_DEFAULT 6
+// CHECK-PAUTH-ON:   #define __ARM_FEATURE_PAUTH 1
 
 // == Check Branch Target Identification (BTI).
 // RUN: %clang -target arm64-none-linux-gnu -march=armv8-a -x c -E -dM %s -o - 
| FileCheck -check-prefix=CHECK-BTI-OFF %s
@@ -560,10 +562,12 @@
 // RUN: %clang -target aarch64-arm-none-eabi -march=armv9.2-a -x c -E -dM %s 
-o - | FileCheck 
--check-prefixes=CHECK-V81-OR-LATER,CHECK-V83-OR-LATER,CHECK-V85-OR-LATER %s
 // RUN: %clang -target aarch64-arm-none-eabi -march=armv9.3-a -x c -E -dM %s 
-o - | FileCheck 
--check-prefixes=CHECK-V81-OR-LATER,CHECK-V83-OR-LATER,CHECK-V85-OR-LATER %s
 // CHECK-V81-OR-LATER: __ARM_FEATURE_ATOMICS 1
+// CHECK-V85-OR-LATER: __ARM_FEATURE_BTI 1
 // CHECK-V83-OR-LATER: __ARM_FEATURE_COMPLEX 1
 // CHECK-V81-OR-LATER: __ARM_FEATURE_CRC32 1
 // CHECK-V85-OR-LATER: __ARM_FEATURE_FRINT 1
 // CHECK-V83-OR-LATER: __ARM_FEATURE_JCVT 1
+// CHECK-V83-OR-LATER: __ARM_FEATURE_PAUTH 1
 // CHECK-V81-OR-LATER: __ARM_FEATURE_QRDMX 1
 // CHECK-BEFORE-V83-NOT: __ARM_FEATURE_COMPLEX 1
 // CHECK-BEFORE-V83-NOT: __ARM_FEATURE_JCVT 1




[clang] 218b77c - [AArch64][NFC] Move hasFeature fields initiations to the declaration

2022-12-09 Thread Daniel Kiss via cfe-commits

Author: Daniel Kiss
Date: 2022-12-09T16:23:26+01:00
New Revision: 218b77c85057e8aae153edcedfe365061270e70c

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

LOG: [AArch64][NFC] Move hasFeature fields initiations to the declaration

hasFeature fields need to be initialised to false. Easy to miss as missed for 
hasPAuth and hasFlagM.
Maybe the code less error prone like this.

Reviewed By: chill

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

Added: 


Modified: 
clang/lib/Basic/Targets/AArch64.cpp
clang/lib/Basic/Targets/AArch64.h

Removed: 




diff  --git a/clang/lib/Basic/Targets/AArch64.cpp 
b/clang/lib/Basic/Targets/AArch64.cpp
index 89ad602b591f5..90a83f62574fc 100644
--- a/clang/lib/Basic/Targets/AArch64.cpp
+++ b/clang/lib/Basic/Targets/AArch64.cpp
@@ -579,37 +579,6 @@ void 
AArch64TargetInfo::setFeatureEnabled(llvm::StringMap &Features,
 
 bool AArch64TargetInfo::handleTargetFeatures(std::vector 
&Features,
  DiagnosticsEngine &Diags) {
-  FPU = FPUMode;
-  HasCRC = false;
-  HasAES = false;
-  HasSHA2 = false;
-  HasSHA3 = false;
-  HasSM4 = false;
-  HasUnaligned = true;
-  HasFullFP16 = false;
-  HasDotProd = false;
-  HasFP16FML = false;
-  HasMTE = false;
-  HasTME = false;
-  HasLS64 = false;
-  HasRandGen = false;
-  HasMatMul = false;
-  HasBFloat16 = false;
-  HasSVE2 = false;
-  HasSVE2AES = false;
-  HasSVE2SHA3 = false;
-  HasSVE2SM4 = false;
-  HasSVE2BitPerm = false;
-  HasMatmulFP64 = false;
-  HasMatmulFP32 = false;
-  HasLSE = false;
-  HasMOPS = false;
-  HasD128 = false;
-  HasRCPC = false;
-  HasPAuth = false;
-
-  ArchKind = llvm::AArch64::ArchKind::INVALID;
-
   for (const auto &Feature : Features) {
 if (Feature == "+neon")
   FPU |= NeonMode;

diff  --git a/clang/lib/Basic/Targets/AArch64.h 
b/clang/lib/Basic/Targets/AArch64.h
index 1791e462139f3..b971c56ec9cda 100644
--- a/clang/lib/Basic/Targets/AArch64.h
+++ b/clang/lib/Basic/Targets/AArch64.h
@@ -27,36 +27,36 @@ class LLVM_LIBRARY_VISIBILITY AArch64TargetInfo : public 
TargetInfo {
 
   enum FPUModeEnum { FPUMode, NeonMode = (1 << 0), SveMode = (1 << 1) };
 
-  unsigned FPU;
-  bool HasCRC;
-  bool HasAES;
-  bool HasSHA2;
-  bool HasSHA3;
-  bool HasSM4;
-  bool HasUnaligned;
-  bool HasFullFP16;
-  bool HasDotProd;
-  bool HasFP16FML;
-  bool HasMTE;
-  bool HasTME;
-  bool HasPAuth;
-  bool HasLS64;
-  bool HasRandGen;
-  bool HasMatMul;
-  bool HasSVE2;
-  bool HasSVE2AES;
-  bool HasSVE2SHA3;
-  bool HasSVE2SM4;
-  bool HasSVE2BitPerm;
-  bool HasMatmulFP64;
-  bool HasMatmulFP32;
-  bool HasLSE;
-  bool HasFlagM;
-  bool HasMOPS;
-  bool HasD128;
-  bool HasRCPC;
-
-  llvm::AArch64::ArchKind ArchKind;
+  unsigned FPU = FPUMode;
+  bool HasCRC = false;
+  bool HasAES = false;
+  bool HasSHA2 = false;
+  bool HasSHA3 = false;
+  bool HasSM4 = false;
+  bool HasUnaligned = true;
+  bool HasFullFP16 = false;
+  bool HasDotProd = false;
+  bool HasFP16FML = false;
+  bool HasMTE = false;
+  bool HasTME = false;
+  bool HasPAuth = false;
+  bool HasLS64 = false;
+  bool HasRandGen = false;
+  bool HasMatMul = false;
+  bool HasSVE2 = false;
+  bool HasSVE2AES = false;
+  bool HasSVE2SHA3 = false;
+  bool HasSVE2SM4 = false;
+  bool HasSVE2BitPerm = false;
+  bool HasMatmulFP64 = false;
+  bool HasMatmulFP32 = false;
+  bool HasLSE = false;
+  bool HasFlagM = false;
+  bool HasMOPS = false;
+  bool HasD128 = false;
+  bool HasRCPC = false;
+
+  llvm::AArch64::ArchKind ArchKind = llvm::AArch64::ArchKind::INVALID;
 
   static const Builtin::Info BuiltinInfo[];
 



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


[clang] [llvm] [PAC][Driver] Implement `-mbranch-protection=pauthabi` option (PR #97237)

2024-07-05 Thread Daniel Kiss via cfe-commits


@@ -1537,11 +1570,16 @@ static void CollectARMPACBTIOptions(const ToolChain 
&TC, const ArgList &Args,
 if (!isAArch64 && PBP.Key == "b_key")
   D.Diag(diag::warn_unsupported_branch_protection)
   << "b-key" << A->getAsString(Args);
+if (!isAArch64 && PBP.HasPauthABI)
+  D.Diag(diag::warn_unsupported_branch_protection)
+  << "pauthabi" << A->getAsString(Args);
 Scope = PBP.Scope;
 Key = PBP.Key;
 BranchProtectionPAuthLR = PBP.BranchProtectionPAuthLR;
 IndirectBranches = PBP.BranchTargetEnforcement;
 GuardedControlStack = PBP.GuardedControlStack;
+if (isAArch64 && PBP.HasPauthABI)

DanielKristofKiss wrote:

FYI - I'm going to change the `sign-return-address` and variants to be a 
function flag. (#82819) 

`bti` - All `BRA*` and `BLRA*` instructions set the `PSTATE.BTYPE`.  I prefer 
to check the [pseudo 
code](https://developer.arm.com/documentation/ddi0602/2022-06/Base-Instructions/BLRAA--BLRAAZ--BLRAB--BLRABZ--Branch-with-Link-to-Register--with-pointer-authentication-
 )for this things (see BTypeNext)

IMHO `pauthabi+bti` makes sense as they are complementary while other option 
are overlapping. We can introduce this combination later. 

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


[clang] [llvm] [Clang][ARM][AArch64] Alway emit protection attributes for functions. (PR #82819)

2024-07-08 Thread Daniel Kiss via cfe-commits

DanielKristofKiss wrote:

I'm planning to merge this and subsequent patches this week, please let me know 
if you any more concerns. Thanks!

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


[clang] [Clang][ARM] Make CRC and DSP intrinsics always available. (PR #107417)

2024-09-05 Thread Daniel Kiss via cfe-commits

https://github.com/DanielKristofKiss created 
https://github.com/llvm/llvm-project/pull/107417

Both feature has target feature so can be checked if the usage is valid.


>From 9dadc9bffc40e02dff9ef6a1d79968c8980892f4 Mon Sep 17 00:00:00 2001
From: Daniel Kiss 
Date: Thu, 5 Sep 2024 16:42:43 +0200
Subject: [PATCH] [Clang][ARM] Make CRC and DSP intrinsics always available.

Both feature has target feature so can be checked if the usage is valid.
---
 clang/lib/Headers/arm_acle.h  | 39 +-
 clang/test/CodeGen/arm_acle.c | 76 +--
 2 files changed, 91 insertions(+), 24 deletions(-)

diff --git a/clang/lib/Headers/arm_acle.h b/clang/lib/Headers/arm_acle.h
index 1518b0c4c8428f..b1dc90f84ad36f 100644
--- a/clang/lib/Headers/arm_acle.h
+++ b/clang/lib/Headers/arm_acle.h
@@ -264,28 +264,28 @@ __rbitl(unsigned long __t) {
 }
 
 /* 8.3 16-bit multiplications */
-#if defined(__ARM_FEATURE_DSP) && __ARM_FEATURE_DSP
-static __inline__ int32_t __attribute__((__always_inline__,__nodebug__))
+#if defined(__ARM_32BIT_STATE) && __ARM_32BIT_STATE
+static __inline__ int32_t __attribute__((__always_inline__,__nodebug__, 
target("dsp")))
 __smulbb(int32_t __a, int32_t __b) {
   return __builtin_arm_smulbb(__a, __b);
 }
-static __inline__ int32_t __attribute__((__always_inline__,__nodebug__))
+static __inline__ int32_t __attribute__((__always_inline__,__nodebug__, 
target("dsp")))
 __smulbt(int32_t __a, int32_t __b) {
   return __builtin_arm_smulbt(__a, __b);
 }
-static __inline__ int32_t __attribute__((__always_inline__,__nodebug__))
+static __inline__ int32_t __attribute__((__always_inline__,__nodebug__, 
target("dsp")))
 __smultb(int32_t __a, int32_t __b) {
   return __builtin_arm_smultb(__a, __b);
 }
-static __inline__ int32_t __attribute__((__always_inline__,__nodebug__))
+static __inline__ int32_t __attribute__((__always_inline__,__nodebug__, 
target("dsp")))
 __smultt(int32_t __a, int32_t __b) {
   return __builtin_arm_smultt(__a, __b);
 }
-static __inline__ int32_t __attribute__((__always_inline__,__nodebug__))
+static __inline__ int32_t __attribute__((__always_inline__,__nodebug__, 
target("dsp")))
 __smulwb(int32_t __a, int32_t __b) {
   return __builtin_arm_smulwb(__a, __b);
 }
-static __inline__ int32_t __attribute__((__always_inline__,__nodebug__))
+static __inline__ int32_t __attribute__((__always_inline__,__nodebug__, 
target("dsp")))
 __smulwt(int32_t __a, int32_t __b) {
   return __builtin_arm_smulwt(__a, __b);
 }
@@ -304,46 +304,46 @@ __smulwt(int32_t __a, int32_t __b) {
 #endif
 
 /* 8.4.2 Saturating addition and subtraction intrinsics */
-#if defined(__ARM_FEATURE_DSP) && __ARM_FEATURE_DSP
-static __inline__ int32_t __attribute__((__always_inline__, __nodebug__))
+#if defined(__ARM_32BIT_STATE) && __ARM_32BIT_STATE
+static __inline__ int32_t __attribute__((__always_inline__, __nodebug__, 
target("dsp")))
 __qadd(int32_t __t, int32_t __v) {
   return __builtin_arm_qadd(__t, __v);
 }
 
-static __inline__ int32_t __attribute__((__always_inline__, __nodebug__))
+static __inline__ int32_t __attribute__((__always_inline__, __nodebug__, 
target("dsp")))
 __qsub(int32_t __t, int32_t __v) {
   return __builtin_arm_qsub(__t, __v);
 }
 
-static __inline__ int32_t __attribute__((__always_inline__, __nodebug__))
+static __inline__ int32_t __attribute__((__always_inline__, __nodebug__, 
target("dsp")))
 __qdbl(int32_t __t) {
   return __builtin_arm_qadd(__t, __t);
 }
 #endif
 
 /* 8.4.3 Accumulating multiplications */
-#if defined(__ARM_FEATURE_DSP) && __ARM_FEATURE_DSP
-static __inline__ int32_t __attribute__((__always_inline__, __nodebug__))
+#if defined(__ARM_32BIT_STATE) && __ARM_32BIT_STATE
+static __inline__ int32_t __attribute__((__always_inline__, __nodebug__, 
target("dsp")))
 __smlabb(int32_t __a, int32_t __b, int32_t __c) {
   return __builtin_arm_smlabb(__a, __b, __c);
 }
-static __inline__ int32_t __attribute__((__always_inline__, __nodebug__))
+static __inline__ int32_t __attribute__((__always_inline__, __nodebug__, 
target("dsp")))
 __smlabt(int32_t __a, int32_t __b, int32_t __c) {
   return __builtin_arm_smlabt(__a, __b, __c);
 }
-static __inline__ int32_t __attribute__((__always_inline__, __nodebug__))
+static __inline__ int32_t __attribute__((__always_inline__, __nodebug__, 
target("dsp")))
 __smlatb(int32_t __a, int32_t __b, int32_t __c) {
   return __builtin_arm_smlatb(__a, __b, __c);
 }
-static __inline__ int32_t __attribute__((__always_inline__, __nodebug__))
+static __inline__ int32_t __attribute__((__always_inline__, __nodebug__, 
target("dsp")))
 __smlatt(int32_t __a, int32_t __b, int32_t __c) {
   return __builtin_arm_smlatt(__a, __b, __c);
 }
-static __inline__ int32_t __attribute__((__always_inline__, __nodebug__))
+static __inline__ int32_t __attribute__((__always_inline__, __nodebug__, 
target("dsp")))
 __smlawb(int32_t __a, int32_t __b, int32_t __c) {
   return __builtin_arm_smlawb(__a, __b, __c);
 }
-static __inline__ int32_t __attribute__((__al

[clang] [Clang][ARM] Make CRC and DSP intrinsics always available. (PR #107417)

2024-09-06 Thread Daniel Kiss via cfe-commits

DanielKristofKiss wrote:

Clang-format failure is expected as I kept intentionally the format to match 
with the rest of the file.

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


[clang] [Arm][AArch64][Clang] Respect function's branch protection attributes. (PR #101978)

2024-08-09 Thread Daniel Kiss via cfe-commits

https://github.com/DanielKristofKiss updated 
https://github.com/llvm/llvm-project/pull/101978

>From 4afadb9122c982c63f2b067661548a2c063590a5 Mon Sep 17 00:00:00 2001
From: Daniel Kiss 
Date: Mon, 5 Aug 2024 13:01:06 +0200
Subject: [PATCH 1/2] [Arm][AArch64][Clang] Respect function's branch
 protection attributes.

Default attributes assigned to all functions according to the command line
parameters. Some functions might have their own attributes and we need to set
or remove attributes accordingly.
---
 clang/lib/CodeGen/TargetInfo.cpp  | 25 ---
 clang/lib/CodeGen/TargetInfo.h|  3 +++
 .../CodeGen/aarch64-branch-protection-attr.c  | 13 +-
 .../CodeGen/arm-branch-protection-attr-1.c|  6 +
 4 files changed, 43 insertions(+), 4 deletions(-)

diff --git a/clang/lib/CodeGen/TargetInfo.cpp b/clang/lib/CodeGen/TargetInfo.cpp
index 38faa50cf19cf2..ec05db0ecfac58 100644
--- a/clang/lib/CodeGen/TargetInfo.cpp
+++ b/clang/lib/CodeGen/TargetInfo.cpp
@@ -209,9 +209,28 @@ llvm::Value *TargetCodeGenInfo::createEnqueuedBlockKernel(
 
 void TargetCodeGenInfo::setBranchProtectionFnAttributes(
 const TargetInfo::BranchProtectionInfo &BPI, llvm::Function &F) {
-  llvm::AttrBuilder FuncAttrs(F.getContext());
-  setBranchProtectionFnAttributes(BPI, FuncAttrs);
-  F.addFnAttrs(FuncAttrs);
+  if (BPI.SignReturnAddr != LangOptions::SignReturnAddressScopeKind::None) {
+F.addFnAttr("sign-return-address", BPI.getSignReturnAddrStr());
+F.addFnAttr("sign-return-address-key", BPI.getSignKeyStr());
+  } else {
+if (F.hasFnAttribute("sign-return-address"))
+  F.removeFnAttr("sign-return-address");
+if (F.hasFnAttribute("sign-return-address-key"))
+  F.removeFnAttr("sign-return-address-key");
+  }
+
+  auto AddRemoveAttributeAsSet = [&](bool Set, const StringRef &ModAttr) {
+if (Set)
+  F.addFnAttr(ModAttr);
+else if (F.hasFnAttribute(ModAttr))
+  F.removeFnAttr(ModAttr);
+  };
+
+  AddRemoveAttributeAsSet(BPI.BranchTargetEnforcement,
+  "branch-target-enforcement");
+  AddRemoveAttributeAsSet(BPI.BranchProtectionPAuthLR,
+  "branch-protection-pauth-lr");
+  AddRemoveAttributeAsSet(BPI.GuardedControlStack, "guarded-control-stack");
 }
 
 void TargetCodeGenInfo::setBranchProtectionFnAttributes(
diff --git a/clang/lib/CodeGen/TargetInfo.h b/clang/lib/CodeGen/TargetInfo.h
index 8f17c053f4783f..639717bd9580d0 100644
--- a/clang/lib/CodeGen/TargetInfo.h
+++ b/clang/lib/CodeGen/TargetInfo.h
@@ -418,10 +418,13 @@ class TargetCodeGenInfo {
 return nullptr;
   }
 
+  // Set the Branch Protection Attributes of the Function accordingly to the
+  // BPI. Might remove attributes if contradicts with the pass request.
   static void
   setBranchProtectionFnAttributes(const TargetInfo::BranchProtectionInfo &BPI,
   llvm::Function &F);
 
+  // Add the Branch Protection Attributes of the FuncAttrs.
   static void
   setBranchProtectionFnAttributes(const TargetInfo::BranchProtectionInfo &BPI,
   llvm::AttrBuilder &FuncAttrs);
diff --git a/clang/test/CodeGen/aarch64-branch-protection-attr.c 
b/clang/test/CodeGen/aarch64-branch-protection-attr.c
index e7ae7fb1570c95..c66bce1bee6d36 100644
--- a/clang/test/CodeGen/aarch64-branch-protection-attr.c
+++ b/clang/test/CodeGen/aarch64-branch-protection-attr.c
@@ -1,6 +1,18 @@
 // REQUIRES: aarch64-registered-target
 // RUN: %clang_cc1 -triple aarch64 -emit-llvm  -target-cpu generic 
-target-feature +v8.5a %s -o - \
 // RUN:   | FileCheck %s --check-prefix=CHECK
+// RUN: %clang_cc1 -triple aarch64 -emit-llvm  -target-cpu generic 
-target-feature +v8.5a -mbranch-target-enforce %s -o - \
+// RUN:   | FileCheck %s --check-prefix=CHECK
+// RUN: %clang_cc1 -triple aarch64 -emit-llvm  -target-cpu generic 
-target-feature +v8.5a -mguarded-control-stack %s -o - \
+// RUN:   | FileCheck %s --check-prefix=CHECK
+// RUN: %clang_cc1 -triple aarch64 -emit-llvm  -target-cpu generic 
-target-feature +v8.5a -msign-return-address=non-leaf 
-msign-return-address-key=a_key %s -o - \
+// RUN:   | FileCheck %s --check-prefix=CHECK
+// RUN: %clang_cc1 -triple aarch64 -emit-llvm  -target-cpu generic 
-target-feature +v8.5a -msign-return-address=all 
-msign-return-address-key=b_key %s -o - \
+// RUN:   | FileCheck %s --check-prefix=CHECK
+// RUN: %clang_cc1 -triple aarch64 -emit-llvm  -target-cpu generic 
-target-feature +v8.5a -mbranch-protection-pauth-lr -msign-return-address=all 
-msign-return-address-key=a_key %s -o - \
+// RUN:   | FileCheck %s --check-prefix=CHECK
+// RUN: %clang_cc1 -triple aarch64 -emit-llvm  -target-cpu generic 
-target-feature +v8.5a -mguarded-control-stack -mbranch-target-enforce 
-mbranch-protection-pauth-lr -msign-return-address=

[clang] [Arm][AArch64][Clang] Respect function's branch protection attributes. (PR #101978)

2024-08-09 Thread Daniel Kiss via cfe-commits


@@ -209,9 +209,28 @@ llvm::Value *TargetCodeGenInfo::createEnqueuedBlockKernel(
 
 void TargetCodeGenInfo::setBranchProtectionFnAttributes(
 const TargetInfo::BranchProtectionInfo &BPI, llvm::Function &F) {
-  llvm::AttrBuilder FuncAttrs(F.getContext());
-  setBranchProtectionFnAttributes(BPI, FuncAttrs);
-  F.addFnAttrs(FuncAttrs);
+  if (BPI.SignReturnAddr != LangOptions::SignReturnAddressScopeKind::None) {
+F.addFnAttr("sign-return-address", BPI.getSignReturnAddrStr());
+F.addFnAttr("sign-return-address-key", BPI.getSignKeyStr());
+  } else {
+if (F.hasFnAttribute("sign-return-address"))
+  F.removeFnAttr("sign-return-address");
+if (F.hasFnAttribute("sign-return-address-key"))
+  F.removeFnAttr("sign-return-address-key");
+  }
+
+  auto AddRemoveAttributeAsSet = [&](bool Set, const StringRef &ModAttr) {
+if (Set)
+  F.addFnAttr(ModAttr);
+else if (F.hasFnAttribute(ModAttr))
+  F.removeFnAttr(ModAttr);
+  };
+
+  AddRemoveAttributeAsSet(BPI.BranchTargetEnforcement,
+  "branch-target-enforcement");
+  AddRemoveAttributeAsSet(BPI.BranchProtectionPAuthLR,
+  "branch-protection-pauth-lr");
+  AddRemoveAttributeAsSet(BPI.GuardedControlStack, "guarded-control-stack");
 }
 
 void TargetCodeGenInfo::setBranchProtectionFnAttributes(

DanielKristofKiss wrote:

Thanks for the concern. I added more comments and renamed the AttrBuilder 
version to make it more distinct.

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


[clang] [Arm][AArch64][Clang] Respect function's branch protection attributes. (PR #101978)

2024-08-09 Thread Daniel Kiss via cfe-commits

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


[clang] [Arm][AArch64][Clang] Respect function's branch protection attributes. (PR #101978)

2024-08-09 Thread Daniel Kiss via cfe-commits

DanielKristofKiss wrote:

/cherry-pick 9e9fa00

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


[clang] [clang][AArch64] Add validation for Global Register Variable. (PR #94271)

2024-06-11 Thread Daniel Kiss via cfe-commits

https://github.com/DanielKristofKiss updated 
https://github.com/llvm/llvm-project/pull/94271

>From a8dabc508583ffb12982549d1bfb86cf6845c957 Mon Sep 17 00:00:00 2001
From: Daniel Kiss 
Date: Sun, 21 Apr 2024 16:14:25 +0200
Subject: [PATCH] [AArch64] Add validation for Global Register Variable.

Fixes: #76426
---
 clang/lib/Basic/Targets/AArch64.cpp   | 12 
 clang/lib/Basic/Targets/AArch64.h |  3 +++
 clang/test/Driver/aarch64-fixed-register-global.c | 12 
 clang/test/Sema/aarch64-fixed-global-register.c   |  4 
 4 files changed, 31 insertions(+)
 create mode 100644 clang/test/Driver/aarch64-fixed-register-global.c
 create mode 100644 clang/test/Sema/aarch64-fixed-global-register.c

diff --git a/clang/lib/Basic/Targets/AArch64.cpp 
b/clang/lib/Basic/Targets/AArch64.cpp
index 5db1ce78c657f..2e6f78bf4de18 100644
--- a/clang/lib/Basic/Targets/AArch64.cpp
+++ b/clang/lib/Basic/Targets/AArch64.cpp
@@ -221,6 +221,18 @@ bool AArch64TargetInfo::validateTarget(DiagnosticsEngine 
&Diags) const {
   return true;
 }
 
+bool AArch64TargetInfo::validateGlobalRegisterVariable(
+StringRef RegName, unsigned RegSize, bool &HasSizeMismatch) const {
+  if ((RegName == "sp") || RegName.starts_with("x")) {
+HasSizeMismatch = RegSize != 64;
+return true;
+  } else if (RegName.starts_with("w")) {
+HasSizeMismatch = RegSize != 32;
+return true;
+  }
+  return false;
+}
+
 bool AArch64TargetInfo::validateBranchProtection(StringRef Spec, StringRef,
  BranchProtectionInfo &BPI,
  StringRef &Err) const {
diff --git a/clang/lib/Basic/Targets/AArch64.h 
b/clang/lib/Basic/Targets/AArch64.h
index 12fb50286f751..22d7c420d5510 100644
--- a/clang/lib/Basic/Targets/AArch64.h
+++ b/clang/lib/Basic/Targets/AArch64.h
@@ -202,6 +202,9 @@ class LLVM_LIBRARY_VISIBILITY AArch64TargetInfo : public 
TargetInfo {
   bool hasBitIntType() const override { return true; }
 
   bool validateTarget(DiagnosticsEngine &Diags) const override;
+
+  bool validateGlobalRegisterVariable(StringRef RegName, unsigned RegSize,
+  bool &HasSizeMismatch) const override;
 };
 
 class LLVM_LIBRARY_VISIBILITY AArch64leTargetInfo : public AArch64TargetInfo {
diff --git a/clang/test/Driver/aarch64-fixed-register-global.c 
b/clang/test/Driver/aarch64-fixed-register-global.c
new file mode 100644
index 0..7b1fb118fcdf7
--- /dev/null
+++ b/clang/test/Driver/aarch64-fixed-register-global.c
@@ -0,0 +1,12 @@
+// Check that -ffixed register handled for globals.
+// Regression test for #76426
+// RUN: %clang --target=aarch64-none-gnu -ffixed-x15 -### %s 2>&1 | FileCheck 
%s
+// CHECK-NOT: fatal error: error in backend: Invalid register name "x15".
+register int i1 __asm__("x15");
+
+int foo() {
+  return i1;
+}
+int main() {
+  return foo();
+}
diff --git a/clang/test/Sema/aarch64-fixed-global-register.c 
b/clang/test/Sema/aarch64-fixed-global-register.c
new file mode 100644
index 0..9b4a422d8c1b2
--- /dev/null
+++ b/clang/test/Sema/aarch64-fixed-global-register.c
@@ -0,0 +1,4 @@
+// RUN: %clang_cc1 -triple aarch64-unknown-none-gnu %s -verify -fsyntax-only
+
+register char i1 __asm__ ("x15"); // expected-error {{size of register 'x15' 
does not match variable size}}
+register long long l2 __asm__ ("w14"); // expected-error {{size of register 
'w14' does not match variable size}}

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


[clang] [clang][AArch64] Add validation for Global Register Variable. (PR #94271)

2024-06-11 Thread Daniel Kiss via cfe-commits


@@ -0,0 +1,13 @@
+// Check that -ffixed register handled for globals.
+// Regression test for #76426
+// RUN: %clang --target=aarch64-none-gnu -ffixed-x15 -### %s 2>&1 | FileCheck 
%s
+// CHECK-NOT: fatal error: error in backend: Invalid register name "x15".

DanielKristofKiss wrote:

Right! I'd keep the bugreport as is for regression test but added a new tests 
for the reg check.

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


[clang] [clang][AArch64] Add validation for Global Register Variable. (PR #94271)

2024-06-16 Thread Daniel Kiss via cfe-commits

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


[clang] [clang][AArch64][FMV] Stop emitting alias to ifunc. (PR #96221)

2024-06-20 Thread Daniel Kiss via cfe-commits

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


[clang] [clang][AArch64][FMV] Stop emitting alias to ifunc. (PR #96221)

2024-06-20 Thread Daniel Kiss via cfe-commits

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

Second the relnote otherwise LGTM.

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


[clang] [llvm] [AArch64] Fix argument passing in reserved registers for preserve_nonecc (PR #96259)

2024-06-20 Thread Daniel Kiss via cfe-commits

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

LGTM, Thanks!

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


[clang] [llvm] [AArch64] Support preserve_none calling convention (PR #91046)

2024-05-31 Thread Daniel Kiss via cfe-commits

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

Thanks for the PR, just NITS otherwise LGTM

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


[clang] [llvm] [AArch64] Support preserve_none calling convention (PR #91046)

2024-05-31 Thread Daniel Kiss via cfe-commits


@@ -7949,9 +7966,10 @@ AArch64TargetLowering::LowerCall(CallLoweringInfo &CLI,
   ++NumTailCalls;
   }
 
-  if (!IsTailCall && CLI.CB && CLI.CB->isMustTailCall())
+  if (!IsTailCall && CLI.CB && CLI.CB->isMustTailCall()) {

DanielKristofKiss wrote:

if with 1 statement doesn't need braces.

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


[clang] [llvm] [AArch64] Support preserve_none calling convention (PR #91046)

2024-05-31 Thread Daniel Kiss via cfe-commits


@@ -494,6 +494,32 @@ def CC_AArch64_GHC : CallingConv<[
   CCIfType<[i64], CCAssignToReg<[X19, X20, X21, X22, X23, X24, X25, X26, X27, 
X28]>>
 ]>;
 
+let Entry = 1 in
+def CC_AArch64_Preserve_None : CallingConv<[
+// We can pass arguments in all general registers, except:
+// - X8, used for sret
+// - X16/X17, used by the linker as IP0/IP1
+// - X18, used for the 'nest' parameter

DanielKristofKiss wrote:

X18 is the `Platform Register`

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


[clang] [llvm] [AArch64] Support preserve_none calling convention (PR #91046)

2024-05-31 Thread Daniel Kiss via cfe-commits

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


[clang] [llvm] [AArch64] Support preserve_none calling convention (PR #91046)

2024-05-31 Thread Daniel Kiss via cfe-commits


@@ -0,0 +1,92 @@
+; RUN: sed -e "s/RETTYPE/void/;s/RETVAL//" %s | llc 
-mtriple=aarch64-apple-darwin | FileCheck --check-prefixes=ALL %s
+; RUN: sed -e "s/RETTYPE/i32/;s/RETVAL/undef/" %s | llc 
-mtriple=aarch64-apple-darwin | FileCheck --check-prefixes=ALL %s
+; RUN: sed -e "s/RETTYPE/\{i64\,i64\}/;s/RETVAL/undef/" %s | llc 
-mtriple=aarch64-apple-darwin | FileCheck --check-prefixes=ALL %s
+; RUN: sed -e "s/RETTYPE/double/;s/RETVAL/0./" %s | llc 
-mtriple=aarch64-apple-darwin | FileCheck --check-prefixes=ALL,DOUBLE %s
+
+; We don't need to save registers before using them inside preserve_none 
function.
+define preserve_nonecc RETTYPE @preserve_nonecc1(i64, i64, double, double) 
nounwind {
+entry:
+;ALL-LABEL:   preserve_nonecc1
+;ALL: ; %bb.0:
+;ALL-NEXT:InlineAsm Start
+;ALL-NEXT:InlineAsm End
+;DOUBLE-NEXT: movi d0, #
+;ALL-NEXT:ret
+  call void asm sideeffect "", 
"~{x0},~{x1},~{x2},~{x3},~{x4},~{x5},~{x6},~{x7},~{x8},~{x9},~{x10},~{x11},~{x12},~{x13},~{x14},~{x15},~{x16},~{x17},~{x19},~{x20},~{x21},~{x22},~{x23},~{x24},~{x25},~{x26},~{x27},~{x28},~{d0},~{d1},~{d2},~{d3},~{d4},~{d5},~{d6},~{d7},~{d8},~{d9},~{d10},~{d11},~{d12},~{d13},~{d14},~{d15},~{d16}"()
+  ret RETTYPE RETVAL
+}
+
+; When calling a preserve_none function, all live registers must be saved and
+; restored around the function call.
+declare preserve_nonecc RETTYPE @bar(i64, i64, double, double)

DanielKristofKiss wrote:

NIT: maybe easier to follow like:

```suggestion
declare preserve_nonecc RETTYPE @preserve_nonecc2(i64, i64, double, double)
define void @bar() nounwind {
```

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


[clang] [AArch64] Add validation for Global Register Variable. (PR #94271)

2024-06-03 Thread Daniel Kiss via cfe-commits

https://github.com/DanielKristofKiss created 
https://github.com/llvm/llvm-project/pull/94271

Fixes: #76426

>From cda747d06c2d363c6c0c7f7d72825d119240ac5a Mon Sep 17 00:00:00 2001
From: Daniel Kiss 
Date: Sun, 21 Apr 2024 16:14:25 +0200
Subject: [PATCH] [AArch64] Add validation for Global Register Variable.

Fixes: #76426
---
 clang/lib/Basic/Targets/AArch64.h | 12 
 clang/test/Driver/aarch64-fixed-register-global.c | 13 +
 2 files changed, 25 insertions(+)
 create mode 100644 clang/test/Driver/aarch64-fixed-register-global.c

diff --git a/clang/lib/Basic/Targets/AArch64.h 
b/clang/lib/Basic/Targets/AArch64.h
index 12fb50286f751..9165865029900 100644
--- a/clang/lib/Basic/Targets/AArch64.h
+++ b/clang/lib/Basic/Targets/AArch64.h
@@ -202,6 +202,18 @@ class LLVM_LIBRARY_VISIBILITY AArch64TargetInfo : public 
TargetInfo {
   bool hasBitIntType() const override { return true; }
 
   bool validateTarget(DiagnosticsEngine &Diags) const override;
+
+  bool validateGlobalRegisterVariable(StringRef RegName, unsigned RegSize,
+  bool &HasSizeMismatch) const override {
+if (RegName.equals("sp") || RegName.starts_with("x")) {
+  HasSizeMismatch = RegSize != 64;
+  return true;
+} else if (RegName.starts_with("w")) {
+  HasSizeMismatch = RegSize != 32;
+  return true;
+}
+return false;
+  }
 };
 
 class LLVM_LIBRARY_VISIBILITY AArch64leTargetInfo : public AArch64TargetInfo {
diff --git a/clang/test/Driver/aarch64-fixed-register-global.c 
b/clang/test/Driver/aarch64-fixed-register-global.c
new file mode 100644
index 0..6a05228277cd6
--- /dev/null
+++ b/clang/test/Driver/aarch64-fixed-register-global.c
@@ -0,0 +1,13 @@
+// Check that -ffixed register handled for globals.
+// Regression test for #76426
+// RUN: %clang --target=aarch64-none-gnu -ffixed-x15 -### %s 2>&1 | FileCheck 
%s
+// CHECK-NOT: fatal error: error in backend: Invalid register name "x15".
+
+register int i1 __asm__("x15");
+
+int foo() {
+  return i1;
+}
+int main() {
+  return foo();
+}

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


[clang] [llvm] [PAC][Driver] Support `pauthtest` ABI for AArch64 Linux triples (PR #97237)

2024-07-19 Thread Daniel Kiss via cfe-commits


@@ -0,0 +1,4 @@
+// RUN: %clang --target=aarch64-linux-pauthtest   
--sysroot=%S/Inputs/multilib_aarch64_linux_tree -### -c %s 2>&1 | FileCheck %s

DanielKristofKiss wrote:

Looks this is not used: 
"clang/test/Driver/Inputs/multilib_aarch64_linux_tree/usr/include/aarch64-linux-gnu/.keep"
BTW we could just add to the test:
`rm -rf %t.dir && mkdir -p 
%t.dir/multilib_aarch64_linux_tree/usr/include/aarch64-linux-gnu/ &&  mkdir -p 
%t.dir/multilib_aarch64_linux_tree/usr/include/aarch64-linux-pauthtest/` 

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


[libunwind] [libunwind] Undefined behaviour pointer arithmetic with null pointer (PR #98648)

2024-07-19 Thread Daniel Kiss via cfe-commits

https://github.com/DanielKristofKiss updated 
https://github.com/llvm/llvm-project/pull/98648

>From 240add341b2c0a1be3d1ebf21938e70e51669126 Mon Sep 17 00:00:00 2001
From: Daniel Kiss 
Date: Fri, 12 Jul 2024 15:56:40 +0200
Subject: [PATCH 1/2] [libunwind] Fix ubsan issue

---
 libunwind/src/UnwindCursor.hpp | 9 +++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/libunwind/src/UnwindCursor.hpp b/libunwind/src/UnwindCursor.hpp
index 2ec60e4c123d5..01a61cea53ffa 100644
--- a/libunwind/src/UnwindCursor.hpp
+++ b/libunwind/src/UnwindCursor.hpp
@@ -230,8 +230,13 @@ void DwarfFDECache::iterateCacheEntries(void (*func)(
 }
 #endif // defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)
 
-
-#define arrayoffsetof(type, index, field) ((size_t)(&((type *)0)[index].field))
+template 
+__attribute__((no_sanitize("undefined"))) static inline size_t
+_arrayoffsetof(int index, FIELD TYPE::*field) {
+  return ((size_t)(&(((TYPE *)0)[index].*field)));
+}
+#define arrayoffsetof(type, index, field)  
\
+  _arrayoffsetof(index, &type::field)
 
 #if defined(_LIBUNWIND_SUPPORT_COMPACT_UNWIND)
 template  class UnwindSectionHeader {

>From a9f5774e9847082ce16f2a04e8a4d4ce456dfc62 Mon Sep 17 00:00:00 2001
From: Daniel Kiss 
Date: Fri, 12 Jul 2024 20:59:48 +0200
Subject: [PATCH 2/2] Simplify the code.

---
 libunwind/src/UnwindCursor.hpp | 7 +--
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/libunwind/src/UnwindCursor.hpp b/libunwind/src/UnwindCursor.hpp
index 01a61cea53ffa..1fa95b4ebee19 100644
--- a/libunwind/src/UnwindCursor.hpp
+++ b/libunwind/src/UnwindCursor.hpp
@@ -230,13 +230,8 @@ void DwarfFDECache::iterateCacheEntries(void (*func)(
 }
 #endif // defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)
 
-template 
-__attribute__((no_sanitize("undefined"))) static inline size_t
-_arrayoffsetof(int index, FIELD TYPE::*field) {
-  return ((size_t)(&(((TYPE *)0)[index].*field)));
-}
 #define arrayoffsetof(type, index, field)  
\
-  _arrayoffsetof(index, &type::field)
+  (sizeof(type) * (index) + offsetof(type, field))
 
 #if defined(_LIBUNWIND_SUPPORT_COMPACT_UNWIND)
 template  class UnwindSectionHeader {

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


[libunwind] [libunwind] Undefined behaviour pointer arithmetic with null pointer (PR #98648)

2024-07-19 Thread Daniel Kiss via cfe-commits

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


[clang] [llvm] [ARM][AArch64] BTI, GCS, PAC Module flag update. (PR #86212)

2024-07-21 Thread Daniel Kiss via cfe-commits

https://github.com/DanielKristofKiss updated 
https://github.com/llvm/llvm-project/pull/86212

>From f2f3356da08d68dab4431f49d0921515560e4927 Mon Sep 17 00:00:00 2001
From: Daniel Kiss 
Date: Fri, 8 Mar 2024 15:06:28 +0100
Subject: [PATCH] BTI,GCS,PAC Module flag update.

Module flag is used to indicate the feature to be propagated to the
function. As now the frontend emits all attributes accoringly let's
help the automerger to only do work when old and new bitcodes are
merged.
Autoupgrade function attributes from Module attributes when needed.
---
 clang/lib/CodeGen/CodeGenModule.cpp   |  19 ++--
 .../CodeGen/aarch64-sign-return-address.c |  12 +--
 .../CodeGen/arm-branch-protection-attr-2.c|   8 +-
 .../arm-ignore-branch-protection-option.c |   2 +-
 llvm/include/llvm/IR/AutoUpgrade.h|   3 +
 llvm/lib/AsmParser/LLParser.cpp   |   1 +
 llvm/lib/Bitcode/Reader/BitcodeReader.cpp |   2 +
 llvm/lib/IR/AutoUpgrade.cpp   | 100 +
 llvm/lib/Linker/IRMover.cpp   |  10 ++
 llvm/lib/Target/ARM/ARMAsmPrinter.cpp |   2 +-
 llvm/lib/Transforms/IPO/LowerTypeTests.cpp|   2 +-
 .../test/Bitcode/upgrade-branch-protection.ll |  15 +--
 .../CodeGen/Thumb2/pacbti-m-outliner-5.ll |   2 +-
 llvm/test/LTO/AArch64/Inputs/foo.ll   |  16 ---
 llvm/test/LTO/AArch64/TestInputs/bar.ll   |  35 ++
 llvm/test/LTO/AArch64/TestInputs/foo.ll   |  38 +++
 llvm/test/LTO/AArch64/TestInputs/old.ll   |  46 
 .../AArch64/link-branch-target-enforcement.ll |   5 +-
 .../LTO/AArch64/link-sign-return-address.ll   | 102 ++
 llvm/test/Linker/link-arm-and-thumb.ll|   6 +-
 llvm/test/ThinLTO/AArch64/aarch64_inline.ll   |  86 +++
 llvm/test/ThinLTO/AArch64/lit.local.cfg   |   2 +
 22 files changed, 468 insertions(+), 46 deletions(-)
 delete mode 100644 llvm/test/LTO/AArch64/Inputs/foo.ll
 create mode 100644 llvm/test/LTO/AArch64/TestInputs/bar.ll
 create mode 100644 llvm/test/LTO/AArch64/TestInputs/foo.ll
 create mode 100644 llvm/test/LTO/AArch64/TestInputs/old.ll
 create mode 100644 llvm/test/LTO/AArch64/link-sign-return-address.ll
 create mode 100644 llvm/test/ThinLTO/AArch64/aarch64_inline.ll
 create mode 100644 llvm/test/ThinLTO/AArch64/lit.local.cfg

diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 227813ad44e8b..6efc2283535f3 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -1176,22 +1176,29 @@ void CodeGenModule::Release() {
   "tag-stack-memory-buildattr", 1);
 
   if (T.isARM() || T.isThumb() || T.isAArch64()) {
+// Previously 1 is used and meant for the backed to derive the function
+// attribute form it. 2 now means function attributes already set for all
+// functions in this module, so no need to propagate those from the module
+// flag. Value is only used in case of LTO module merge because the backend
+// will see all required function attribute set already. Value is used
+// before modules got merged. Any posive value means the feature is active
+// and required binary markings need to be emit accordingly.
 if (LangOpts.BranchTargetEnforcement)
   getModule().addModuleFlag(llvm::Module::Min, "branch-target-enforcement",
-1);
+2);
 if (LangOpts.BranchProtectionPAuthLR)
   getModule().addModuleFlag(llvm::Module::Min, 
"branch-protection-pauth-lr",
-1);
+2);
 if (LangOpts.GuardedControlStack)
-  getModule().addModuleFlag(llvm::Module::Min, "guarded-control-stack", 1);
+  getModule().addModuleFlag(llvm::Module::Min, "guarded-control-stack", 2);
 if (LangOpts.hasSignReturnAddress())
-  getModule().addModuleFlag(llvm::Module::Min, "sign-return-address", 1);
+  getModule().addModuleFlag(llvm::Module::Min, "sign-return-address", 2);
 if (LangOpts.isSignReturnAddressScopeAll())
   getModule().addModuleFlag(llvm::Module::Min, "sign-return-address-all",
-1);
+2);
 if (!LangOpts.isSignReturnAddressWithAKey())
   getModule().addModuleFlag(llvm::Module::Min,
-"sign-return-address-with-bkey", 1);
+"sign-return-address-with-bkey", 2);
 
 if (getTriple().isOSLinux()) {
   assert(getTriple().isOSBinFormatELF());
diff --git a/clang/test/CodeGen/aarch64-sign-return-address.c 
b/clang/test/CodeGen/aarch64-sign-return-address.c
index 8bc54b1a56c38..35c56889e0707 100644
--- a/clang/test/CodeGen/aarch64-sign-return-address.c
+++ b/clang/test/CodeGen/aarch64-sign-return-address.c
@@ -22,17 +22,17 @@
 // NONE-NOT:  !"branch-target-enforcement"
 // ALL-NOT:   !"branch-target-enforcement"
 // PART-NOT:  !"branch-target-enfor

[clang] [llvm] [Clang][ARM][AArch64] Alway emit protection attributes for functions. (PR #82819)

2024-07-10 Thread Daniel Kiss via cfe-commits

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


[clang] [Clang][ARM][AArch64] Add branch protection attributes to the defaults. (PR #83277)

2024-07-10 Thread Daniel Kiss via cfe-commits

https://github.com/DanielKristofKiss updated 
https://github.com/llvm/llvm-project/pull/83277

>From c421b6b9c167e82cedc5db2a67f47d3ba12deba9 Mon Sep 17 00:00:00 2001
From: Daniel Kiss 
Date: Wed, 28 Feb 2024 15:18:31 +0100
Subject: [PATCH 1/5] Add branch protection attributes to the defaults.

These attributes are no longer inherited from the module flags,
therefore need to be added for synthetic functions.
---
 clang/lib/CodeGen/CGCall.cpp  | 16 ++
 .../CodeGenCXX/arm64-generated-fn-attr.cpp| 30 +++
 2 files changed, 46 insertions(+)
 create mode 100644 clang/test/CodeGenCXX/arm64-generated-fn-attr.cpp

diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 13f68237b464d..5b59c77353675 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -2022,6 +2022,22 @@ static void getTrivialDefaultFunctionAttributes(
 std::tie(Var, Value) = Attr.split('=');
 FuncAttrs.addAttribute(Var, Value);
   }
+
+  TargetInfo::BranchProtectionInfo BPI(LangOpts);
+
+  if (BPI.SignReturnAddr != LangOptions::SignReturnAddressScopeKind::None) {
+FuncAttrs.addAttribute("sign-return-address", BPI.getSignReturnAddrStr());
+FuncAttrs.addAttribute(
+"sign-return-address-key",
+BPI.SignKey == LangOptions::SignReturnAddressKeyKind::AKey ? "a_key"
+   : "b_key");
+  }
+  if (BPI.BranchTargetEnforcement)
+FuncAttrs.addAttribute("branch-target-enforcement", "true");
+  if (BPI.BranchProtectionPAuthLR)
+FuncAttrs.addAttribute("branch-protection-pauth-lr", "true");
+  if (BPI.GuardedControlStack)
+FuncAttrs.addAttribute("guarded-control-stack", "true");
 }
 
 /// Merges `target-features` from \TargetOpts and \F, and sets the result in
diff --git a/clang/test/CodeGenCXX/arm64-generated-fn-attr.cpp 
b/clang/test/CodeGenCXX/arm64-generated-fn-attr.cpp
new file mode 100644
index 0..8daf44abd4f91
--- /dev/null
+++ b/clang/test/CodeGenCXX/arm64-generated-fn-attr.cpp
@@ -0,0 +1,30 @@
+// RUN: %clang_cc1 -triple aarch64-none-none -mbranch-target-enforce 
-msign-return-address=all -fcxx-exceptions -fexceptions -emit-llvm %s -o - | 
FileCheck %s --check-prefixes=CHECK
+
+// Check that functions generated by clang have the correct attributes
+
+class Example {
+public:
+  Example();
+  int fn();
+};
+
+// Initialization of var1 causes __cxx_global_var_init and __tls_init to be 
generated
+thread_local Example var1;
+extern thread_local Example var2;
+extern void fn();
+
+int testfn() noexcept {
+  // Calling fn in a noexcept function causes __clang_call_terminate to be 
generated
+  fn();
+  // Use of var1 and var2 causes TLS wrapper functions to be generated
+  return var1.fn() + var2.fn();
+}
+
+// CHECK: define {{.*}} @__cxx_global_var_init() [[ATTR1:#[0-9]+]]
+// CHECK: define {{.*}} @__clang_call_terminate({{.*}}) [[ATTR2:#[0-9]+]]
+// CHECK: define {{.*}} @_ZTW4var1() [[ATTR1]]
+// CHECK: define {{.*}} @_ZTW4var2() [[ATTR1]]
+// CHECK: define {{.*}} @__tls_init() [[ATTR1]]
+
+// CHECK: attributes [[ATTR1]] = { 
{{.*}}"branch-target-enforcement"="true"{{.*}}"sign-return-address"="all" 
"sign-return-address-key"="a_key"
+// CHECK: attributes [[ATTR2]] = { 
{{.*}}"branch-target-enforcement"="true"{{.*}}"sign-return-address"="all" 
"sign-return-address-key"="a_key"

>From 3e46bfa6bcd8a0cce142a4e1254c89ff68174117 Mon Sep 17 00:00:00 2001
From: Daniel Kiss 
Date: Wed, 28 Feb 2024 17:38:49 +0100
Subject: [PATCH 2/5] fixup! [Clang][Arm][AArch64] Add branch protection
 attributes to the defaults.

---
 clang/lib/CodeGen/CGCall.cpp | 5 +
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 5b59c77353675..58ccd3d181ccd 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -2027,10 +2027,7 @@ static void getTrivialDefaultFunctionAttributes(
 
   if (BPI.SignReturnAddr != LangOptions::SignReturnAddressScopeKind::None) {
 FuncAttrs.addAttribute("sign-return-address", BPI.getSignReturnAddrStr());
-FuncAttrs.addAttribute(
-"sign-return-address-key",
-BPI.SignKey == LangOptions::SignReturnAddressKeyKind::AKey ? "a_key"
-   : "b_key");
+FuncAttrs.addAttribute("sign-return-address-key", BPI.getSignKeyStr());
   }
   if (BPI.BranchTargetEnforcement)
 FuncAttrs.addAttribute("branch-target-enforcement", "true");

>From 054515d8b3b50b3efc792db9dfe4c9e61fa2507d Mon Sep 17 00:00:00 2001
From: Daniel Kiss 
Date: Mon, 4 Mar 2024 17:31:31 +0100
Subject: [PATCH 3/5] Move TargetInfo changes over.

Dropping restrictions on the member functions.
---
 clang/include/clang/Basic/TargetInfo.h | 43 +++---
 1 file changed, 39 insertions(+), 4 deletions(-)

diff --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index 76

[clang] [llvm] Revert "[Clang][ARM][AArch64] Alway emit protection attributes for functions." (PR #98284)

2024-07-10 Thread Daniel Kiss via cfe-commits

https://github.com/DanielKristofKiss created 
https://github.com/llvm/llvm-project/pull/98284

Reverts llvm/llvm-project#82819

>From 74e9e20f0338824eecea0f27d9c1336676a60d3d Mon Sep 17 00:00:00 2001
From: Daniel Kiss 
Date: Wed, 10 Jul 2024 10:21:36 +0200
Subject: [PATCH] =?UTF-8?q?Revert=20"[Clang][ARM][AArch64]=20Alway=20emit?=
 =?UTF-8?q?=20protection=20attributes=20for=20functions.=E2=80=A6"?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This reverts commit e15d67cfc2e5775cc79281aa860f3ad3be628f39.
---
 clang/include/clang/Basic/TargetInfo.h| 44 ++-
 clang/lib/CodeGen/Targets/AArch64.cpp | 43 --
 clang/lib/CodeGen/Targets/ARM.cpp |  8 ++--
 .../CodeGen/aarch64-branch-protection-attr.c  | 26 +--
 .../CodeGen/aarch64-sign-return-address.c | 12 ++---
 .../CodeGen/arm-branch-protection-attr-1.c| 12 ++---
 .../CodeGen/arm-branch-protection-attr-2.c| 13 ++
 .../test/Frontend/arm-branch-protection-lto.c | 24 --
 .../SelectionDAG/SelectionDAGBuilder.cpp  | 12 -
 llvm/lib/IR/Verifier.cpp  | 20 +
 llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp |  6 +--
 .../AArch64/AArch64MachineFunctionInfo.cpp| 37 ++--
 .../lib/Target/ARM/ARMMachineFunctionInfo.cpp | 22 +-
 llvm/lib/Transforms/IPO/LowerTypeTests.cpp|  6 +--
 ...ranch-target-enforcement-indirect-calls.ll | 18 
 .../CodeGen/AArch64/bti-branch-relaxation.ll  |  2 +-
 llvm/test/CodeGen/AArch64/kcfi-bti.ll |  7 ++-
 ...machine-outliner-2fixup-blr-terminator.mir |  2 +-
 .../CodeGen/AArch64/machine-outliner-bti.mir  |  2 +-
 .../AArch64/machine-outliner-outline-bti.ll   |  4 +-
 .../AArch64/note-gnu-property-pac-bti-0.ll|  2 +-
 .../AArch64/note-gnu-property-pac-bti-4.ll|  4 +-
 .../AArch64/pacbti-llvm-generated-funcs-1.ll  |  4 +-
 .../AArch64/pacbti-llvm-generated-funcs-2.ll  | 10 +++--
 .../CodeGen/AArch64/pacbti-module-attrs.ll| 12 ++---
 .../AArch64/patchable-function-entry-bti.ll   | 10 ++---
 .../CodeGen/AArch64/setjmp-bti-outliner.ll| 15 ---
 llvm/test/CodeGen/AArch64/setjmp-bti.ll   |  6 ++-
 .../AArch64/sign-return-address-pauth-lr.ll   | 36 ---
 .../CodeGen/AArch64/sign-return-address.ll|  8 ++--
 llvm/test/CodeGen/AArch64/wineh-bti.ll|  7 ++-
 llvm/test/CodeGen/AArch64/wineh-pac.ll|  7 ++-
 llvm/test/CodeGen/ARM/setjmp-bti-basic.ll |  5 ++-
 llvm/test/CodeGen/ARM/setjmp-bti-outliner.ll  |  7 ++-
 llvm/test/CodeGen/Thumb2/bti-entry-blocks.ll  |  7 ++-
 .../CodeGen/Thumb2/bti-indirect-branches.ll   |  9 ++--
 llvm/test/CodeGen/Thumb2/bti-outliner-1.ll|  9 ++--
 llvm/test/CodeGen/Thumb2/bti-outliner-2.ll| 12 +++--
 .../CodeGen/Thumb2/bti-outliner-cost-2.ll |  6 ++-
 .../test/CodeGen/Thumb2/bti-pac-replace-1.mir |  8 +++-
 llvm/test/CodeGen/Thumb2/bti-pac-replace-2.ll |  7 ++-
 llvm/test/CodeGen/Thumb2/jump-table-bti.ll| 10 ++---
 llvm/test/CodeGen/Thumb2/pacbti-m-basic.ll|  6 +--
 .../Thumb2/pacbti-m-indirect-tail-call.ll |  2 +-
 .../CodeGen/Thumb2/pacbti-m-outliner-1.ll |  2 +-
 .../CodeGen/Thumb2/pacbti-m-outliner-3.ll |  2 +-
 .../CodeGen/Thumb2/pacbti-m-outliner-4.ll |  6 +--
 .../CodeGen/Thumb2/pacbti-m-outliner-5.ll |  4 +-
 .../test/CodeGen/Thumb2/pacbti-m-overalign.ll |  2 +-
 .../test/CodeGen/Thumb2/pacbti-m-stack-arg.ll |  4 +-
 .../Thumb2/pacbti-m-unsupported-arch.ll   |  8 +++-
 .../test/CodeGen/Thumb2/pacbti-m-varargs-1.ll |  4 +-
 .../test/CodeGen/Thumb2/pacbti-m-varargs-2.ll |  4 +-
 llvm/test/CodeGen/Thumb2/pacbti-m-vla.ll  |  2 +-
 .../AArch64/link-branch-target-enforcement.ll |  2 +-
 .../Inline/inline-sign-return-address.ll  | 13 +++---
 .../LowerTypeTests/function-arm-thumb.ll  |  2 +-
 .../LowerTypeTests/function-thumb-bti.ll  |  4 +-
 .../Transforms/LowerTypeTests/function.ll |  4 +-
 llvm/test/Verifier/branch-prot-attrs.ll   | 16 +--
 60 files changed, 316 insertions(+), 292 deletions(-)
 delete mode 100644 clang/test/Frontend/arm-branch-protection-lto.c

diff --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index 1f208b40f92cb..9b0ae2102e098 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -32,9 +32,7 @@
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/StringSet.h"
 #include "llvm/Frontend/OpenMP/OMPGridValues.h"
-#include "llvm/IR/Attributes.h"
 #include "llvm/IR/DerivedTypes.h"
-#include "llvm/IR/Function.h"
 #include "llvm/Support/DataTypes.h"
 #include "llvm/Support/Error.h"
 #include "llvm/Support/VersionTuple.h"
@@ -1402,15 +1400,15 @@ class TargetInfo : public TransferrableTargetInfo,
 return true;
   }
 
-  class BranchProtectionInfo {
-  public:
+  struct BranchProtectionInfo {
 LangOptions::SignReturnAddressScopeKind SignReturnAddr;
 LangOptions::SignReturnAddressKeyKind Si

[clang] [llvm] Revert "[Clang][ARM][AArch64] Alway emit protection attributes for functions." (PR #98284)

2024-07-10 Thread Daniel Kiss via cfe-commits

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


[clang] 1782810 - [Clang][ARM][AArch64] Alway emit protection attributes for functions. (#82819)

2024-07-10 Thread Daniel Kiss via cfe-commits

Author: Daniel Kiss
Date: 2024-07-10T11:32:41+02:00
New Revision: 1782810b8440144a0141c24192acbaeb55a1545d

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

LOG: [Clang][ARM][AArch64] Alway emit protection attributes for functions. 
(#82819)

So far branch protection, sign return address, guarded control stack
attributes are
only emitted as module flags to indicate the functions need to be
generated with
those features.
The problem is in case of an LTO build the module flags are merged with
the `min`
rule which means if one of the module is not build with sign return
address then the features
will be turned off for all functions. Due to the functions take the
branch-protection and
sign-return-address features from the module flags. The
sign-return-address is
function level option therefore it is expected functions from files that
is
compiled with -mbranch-protection=pac-ret to be protected.
The inliner might inline functions with different set of flags as it
doesn't consider
the module flags.

This patch adds the attributes to all functions and drops the checking
of the module flags
for the code generation.
Module flag is still used for generating the ELF markers.
Also drops the "true"/"false" values from the
branch-protection-enforcement,
branch-protection-pauth-lr, guarded-control-stack attributes as presence
of the
attribute means it is on absence means off and no other option.

Releand with test fixes.

Added: 
clang/test/Frontend/arm-branch-protection-lto.c

Modified: 
clang/include/clang/Basic/TargetInfo.h
clang/lib/CodeGen/Targets/AArch64.cpp
clang/lib/CodeGen/Targets/ARM.cpp
clang/test/CodeGen/aarch64-branch-protection-attr.c
clang/test/CodeGen/aarch64-sign-return-address.c
clang/test/CodeGen/aarch64-targetattr.c
clang/test/CodeGen/arm-branch-protection-attr-1.c
clang/test/CodeGen/arm-branch-protection-attr-2.c
llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
llvm/lib/IR/Verifier.cpp
llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
llvm/lib/Target/AArch64/AArch64MachineFunctionInfo.cpp
llvm/lib/Target/ARM/ARMMachineFunctionInfo.cpp
llvm/lib/Transforms/IPO/LowerTypeTests.cpp
llvm/test/CodeGen/AArch64/branch-target-enforcement-indirect-calls.ll
llvm/test/CodeGen/AArch64/bti-branch-relaxation.ll
llvm/test/CodeGen/AArch64/kcfi-bti.ll
llvm/test/CodeGen/AArch64/machine-outliner-2fixup-blr-terminator.mir
llvm/test/CodeGen/AArch64/machine-outliner-bti.mir
llvm/test/CodeGen/AArch64/machine-outliner-outline-bti.ll
llvm/test/CodeGen/AArch64/note-gnu-property-pac-bti-0.ll
llvm/test/CodeGen/AArch64/note-gnu-property-pac-bti-4.ll
llvm/test/CodeGen/AArch64/pacbti-llvm-generated-funcs-1.ll
llvm/test/CodeGen/AArch64/pacbti-llvm-generated-funcs-2.ll
llvm/test/CodeGen/AArch64/pacbti-module-attrs.ll
llvm/test/CodeGen/AArch64/patchable-function-entry-bti.ll
llvm/test/CodeGen/AArch64/setjmp-bti-outliner.ll
llvm/test/CodeGen/AArch64/setjmp-bti.ll
llvm/test/CodeGen/AArch64/sign-return-address-pauth-lr.ll
llvm/test/CodeGen/AArch64/sign-return-address.ll
llvm/test/CodeGen/AArch64/wineh-bti.ll
llvm/test/CodeGen/AArch64/wineh-pac.ll
llvm/test/CodeGen/ARM/setjmp-bti-basic.ll
llvm/test/CodeGen/ARM/setjmp-bti-outliner.ll
llvm/test/CodeGen/Thumb2/bti-entry-blocks.ll
llvm/test/CodeGen/Thumb2/bti-indirect-branches.ll
llvm/test/CodeGen/Thumb2/bti-outliner-1.ll
llvm/test/CodeGen/Thumb2/bti-outliner-2.ll
llvm/test/CodeGen/Thumb2/bti-outliner-cost-2.ll
llvm/test/CodeGen/Thumb2/bti-pac-replace-1.mir
llvm/test/CodeGen/Thumb2/bti-pac-replace-2.ll
llvm/test/CodeGen/Thumb2/jump-table-bti.ll
llvm/test/CodeGen/Thumb2/pacbti-m-basic.ll
llvm/test/CodeGen/Thumb2/pacbti-m-indirect-tail-call.ll
llvm/test/CodeGen/Thumb2/pacbti-m-outliner-1.ll
llvm/test/CodeGen/Thumb2/pacbti-m-outliner-3.ll
llvm/test/CodeGen/Thumb2/pacbti-m-outliner-4.ll
llvm/test/CodeGen/Thumb2/pacbti-m-outliner-5.ll
llvm/test/CodeGen/Thumb2/pacbti-m-overalign.ll
llvm/test/CodeGen/Thumb2/pacbti-m-stack-arg.ll
llvm/test/CodeGen/Thumb2/pacbti-m-unsupported-arch.ll
llvm/test/CodeGen/Thumb2/pacbti-m-varargs-1.ll
llvm/test/CodeGen/Thumb2/pacbti-m-varargs-2.ll
llvm/test/CodeGen/Thumb2/pacbti-m-vla.ll
llvm/test/LTO/AArch64/link-branch-target-enforcement.ll
llvm/test/Transforms/Inline/inline-sign-return-address.ll
llvm/test/Transforms/LowerTypeTests/function-arm-thumb.ll
llvm/test/Transforms/LowerTypeTests/function-thumb-bti.ll
llvm/test/Transforms/LowerTypeTests/function.ll
llvm/test/Verifier/branch-prot-attrs.ll

Removed: 




diff  --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index

[clang] [Clang][ARM] Call constructor on BranchTargetInfo. (PR #98307)

2024-07-10 Thread Daniel Kiss via cfe-commits

https://github.com/DanielKristofKiss created 
https://github.com/llvm/llvm-project/pull/98307

Otherwise members will be uninitialised.

>From 4e10c95c390e519853428f424cd655379d99c61c Mon Sep 17 00:00:00 2001
From: Daniel Kiss 
Date: Wed, 10 Jul 2024 13:58:52 +0200
Subject: [PATCH] [Clang][ARM] Call constructor on BranchTargetInfo.

Otherwise members will be uninitialised.
---
 clang/lib/CodeGen/Targets/ARM.cpp | 2 +-
 clang/lib/Sema/SemaDeclAttr.cpp   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/lib/CodeGen/Targets/ARM.cpp 
b/clang/lib/CodeGen/Targets/ARM.cpp
index d449b97cdc685..93fea94a77248 100644
--- a/clang/lib/CodeGen/Targets/ARM.cpp
+++ b/clang/lib/CodeGen/Targets/ARM.cpp
@@ -141,7 +141,7 @@ class ARMTargetCodeGenInfo : public TargetCodeGenInfo {
   ParsedTargetAttr Attr =
   CGM.getTarget().parseTargetAttr(TA->getFeaturesStr());
   if (!Attr.BranchProtection.empty()) {
-TargetInfo::BranchProtectionInfo BPI;
+TargetInfo::BranchProtectionInfo BPI{};
 StringRef DiagMsg;
 StringRef Arch =
 Attr.CPU.empty() ? CGM.getTarget().getTargetOpts().CPU : Attr.CPU;
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 73a85ff39667b..f2cd46d1e7c93 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -2991,7 +2991,7 @@ bool Sema::checkTargetAttr(SourceLocation LiteralLoc, 
StringRef AttrStr) {
  << Unsupported << None << CurFeature << Target;
   }
 
-  TargetInfo::BranchProtectionInfo BPI;
+  TargetInfo::BranchProtectionInfo BPI{};
   StringRef DiagMsg;
   if (ParsedAttrs.BranchProtection.empty())
 return false;

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


[clang] [Clang][ARM] Call constructor on BranchTargetInfo. (PR #98307)

2024-07-10 Thread Daniel Kiss via cfe-commits

https://github.com/DanielKristofKiss updated 
https://github.com/llvm/llvm-project/pull/98307

>From 4e10c95c390e519853428f424cd655379d99c61c Mon Sep 17 00:00:00 2001
From: Daniel Kiss 
Date: Wed, 10 Jul 2024 13:58:52 +0200
Subject: [PATCH 1/2] [Clang][ARM] Call constructor on BranchTargetInfo.

Otherwise members will be uninitialised.
---
 clang/lib/CodeGen/Targets/ARM.cpp | 2 +-
 clang/lib/Sema/SemaDeclAttr.cpp   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/lib/CodeGen/Targets/ARM.cpp 
b/clang/lib/CodeGen/Targets/ARM.cpp
index d449b97cdc685..93fea94a77248 100644
--- a/clang/lib/CodeGen/Targets/ARM.cpp
+++ b/clang/lib/CodeGen/Targets/ARM.cpp
@@ -141,7 +141,7 @@ class ARMTargetCodeGenInfo : public TargetCodeGenInfo {
   ParsedTargetAttr Attr =
   CGM.getTarget().parseTargetAttr(TA->getFeaturesStr());
   if (!Attr.BranchProtection.empty()) {
-TargetInfo::BranchProtectionInfo BPI;
+TargetInfo::BranchProtectionInfo BPI{};
 StringRef DiagMsg;
 StringRef Arch =
 Attr.CPU.empty() ? CGM.getTarget().getTargetOpts().CPU : Attr.CPU;
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 73a85ff39667b..f2cd46d1e7c93 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -2991,7 +2991,7 @@ bool Sema::checkTargetAttr(SourceLocation LiteralLoc, 
StringRef AttrStr) {
  << Unsupported << None << CurFeature << Target;
   }
 
-  TargetInfo::BranchProtectionInfo BPI;
+  TargetInfo::BranchProtectionInfo BPI{};
   StringRef DiagMsg;
   if (ParsedAttrs.BranchProtection.empty())
 return false;

>From 4dfab4b3e6dca97ddc0348bcfbea7609170a3078 Mon Sep 17 00:00:00 2001
From: Daniel Kiss 
Date: Wed, 10 Jul 2024 16:01:47 +0200
Subject: [PATCH 2/2] Initialize members from the constructor.

---
 clang/include/clang/Basic/TargetInfo.h | 9 -
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index 1f208b40f92cb..079c71d10525f 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -1434,7 +1434,14 @@ class TargetInfo : public TransferrableTargetInfo,
 }
 
   public:
-BranchProtectionInfo() = default;
+BranchProtectionInfo() {
+  SignReturnAddr = LangOptions::SignReturnAddressScopeKind::None;
+  SignKey = LangOptions::SignReturnAddressKeyKind::AKey;
+  BranchTargetEnforcement = false;
+  BranchProtectionPAuthLR = false;
+  GuardedControlStack = false;
+};
+
 BranchProtectionInfo(const LangOptions &LangOpts) {
   SignReturnAddr =
   LangOpts.hasSignReturnAddress()

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


[clang] [Clang][ARM] Call constructor on BranchTargetInfo. (PR #98307)

2024-07-10 Thread Daniel Kiss via cfe-commits

DanielKristofKiss wrote:

Let's initialise everything from both of the constructors (as it was in an 
early version of the original patches)



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


[clang] [llvm] [Clang][ARM][AArch64] Alway emit protection attributes for functions. (PR #82819)

2024-07-10 Thread Daniel Kiss via cfe-commits


@@ -32,7 +32,9 @@
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/StringSet.h"
 #include "llvm/Frontend/OpenMP/OMPGridValues.h"
+#include "llvm/IR/Attributes.h"
 #include "llvm/IR/DerivedTypes.h"
+#include "llvm/IR/Function.h"

DanielKristofKiss wrote:

Addressed here https://github.com/llvm/llvm-project/pull/98329

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


[clang] [NFC][Clang] Move functions of BranchProtectionInfo out of line (PR #98329)

2024-07-10 Thread Daniel Kiss via cfe-commits

https://github.com/DanielKristofKiss created 
https://github.com/llvm/llvm-project/pull/98329

Also let's add const to the setFnAttributes.

>From b1e113f76b289aa8a7d4459314a0dbffb313cb51 Mon Sep 17 00:00:00 2001
From: Daniel Kiss 
Date: Wed, 10 Jul 2024 16:23:11 +0200
Subject: [PATCH] [NFC][Clang] Move functions of BranchProtectionInfo out of
 line.

Also let's add const to the setFnAttributes.
---
 clang/include/clang/Basic/TargetInfo.h | 20 ++--
 clang/lib/Basic/TargetInfo.cpp | 20 
 2 files changed, 22 insertions(+), 18 deletions(-)

diff --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index 1f208b40f92cb..5a6a0cdbd316a 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -34,7 +34,6 @@
 #include "llvm/Frontend/OpenMP/OMPGridValues.h"
 #include "llvm/IR/Attributes.h"
 #include "llvm/IR/DerivedTypes.h"
-#include "llvm/IR/Function.h"
 #include "llvm/Support/DataTypes.h"
 #include "llvm/Support/Error.h"
 #include "llvm/Support/VersionTuple.h"
@@ -1450,24 +1449,9 @@ class TargetInfo : public TransferrableTargetInfo,
   GuardedControlStack = LangOpts.GuardedControlStack;
 }
 
-void setFnAttributes(llvm::Function &F) {
-  llvm::AttrBuilder FuncAttrs(F.getContext());
-  setFnAttributes(FuncAttrs);
-  F.addFnAttrs(FuncAttrs);
-}
+void setFnAttributes(llvm::Function &F) const;
 
-void setFnAttributes(llvm::AttrBuilder &FuncAttrs) {
-  if (SignReturnAddr != LangOptions::SignReturnAddressScopeKind::None) {
-FuncAttrs.addAttribute("sign-return-address", getSignReturnAddrStr());
-FuncAttrs.addAttribute("sign-return-address-key", getSignKeyStr());
-  }
-  if (BranchTargetEnforcement)
-FuncAttrs.addAttribute("branch-target-enforcement");
-  if (BranchProtectionPAuthLR)
-FuncAttrs.addAttribute("branch-protection-pauth-lr");
-  if (GuardedControlStack)
-FuncAttrs.addAttribute("guarded-control-stack");
-}
+void setFnAttributes(llvm::AttrBuilder &FuncAttrs) const;
   };
 
   /// Determine if the Architecture in this TargetInfo supports branch
diff --git a/clang/lib/Basic/TargetInfo.cpp b/clang/lib/Basic/TargetInfo.cpp
index 29f5cd14e46e1..a99ddd081ae28 100644
--- a/clang/lib/Basic/TargetInfo.cpp
+++ b/clang/lib/Basic/TargetInfo.cpp
@@ -18,6 +18,7 @@
 #include "clang/Basic/LangOptions.h"
 #include "llvm/ADT/APFloat.h"
 #include "llvm/ADT/STLExtras.h"
+#include "llvm/IR/Function.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/TargetParser/TargetParser.h"
 #include 
@@ -1005,3 +1006,22 @@ void TargetInfo::copyAuxTarget(const TargetInfo *Aux) {
   auto *Src = static_cast(Aux);
   *Target = *Src;
 }
+
+void TargetInfo::BranchProtectionInfo::setFnAttributes(llvm::Function &F) 
const {
+  llvm::AttrBuilder FuncAttrs(F.getContext());
+  setFnAttributes(FuncAttrs);
+  F.addFnAttrs(FuncAttrs);
+}
+
+void  TargetInfo::BranchProtectionInfo::setFnAttributes(llvm::AttrBuilder 
&FuncAttrs) const {
+  if (SignReturnAddr != LangOptions::SignReturnAddressScopeKind::None) {
+FuncAttrs.addAttribute("sign-return-address", getSignReturnAddrStr());
+FuncAttrs.addAttribute("sign-return-address-key", getSignKeyStr());
+  }
+  if (BranchTargetEnforcement)
+FuncAttrs.addAttribute("branch-target-enforcement");
+  if (BranchProtectionPAuthLR)
+FuncAttrs.addAttribute("branch-protection-pauth-lr");
+  if (GuardedControlStack)
+FuncAttrs.addAttribute("guarded-control-stack");
+}

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


[clang] [Clang][ARM][AArch64] Add branch protection attributes to the defaults. (PR #83277)

2024-07-10 Thread Daniel Kiss via cfe-commits

https://github.com/DanielKristofKiss updated 
https://github.com/llvm/llvm-project/pull/83277

>From c421b6b9c167e82cedc5db2a67f47d3ba12deba9 Mon Sep 17 00:00:00 2001
From: Daniel Kiss 
Date: Wed, 28 Feb 2024 15:18:31 +0100
Subject: [PATCH 1/6] Add branch protection attributes to the defaults.

These attributes are no longer inherited from the module flags,
therefore need to be added for synthetic functions.
---
 clang/lib/CodeGen/CGCall.cpp  | 16 ++
 .../CodeGenCXX/arm64-generated-fn-attr.cpp| 30 +++
 2 files changed, 46 insertions(+)
 create mode 100644 clang/test/CodeGenCXX/arm64-generated-fn-attr.cpp

diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 13f68237b464d..5b59c77353675 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -2022,6 +2022,22 @@ static void getTrivialDefaultFunctionAttributes(
 std::tie(Var, Value) = Attr.split('=');
 FuncAttrs.addAttribute(Var, Value);
   }
+
+  TargetInfo::BranchProtectionInfo BPI(LangOpts);
+
+  if (BPI.SignReturnAddr != LangOptions::SignReturnAddressScopeKind::None) {
+FuncAttrs.addAttribute("sign-return-address", BPI.getSignReturnAddrStr());
+FuncAttrs.addAttribute(
+"sign-return-address-key",
+BPI.SignKey == LangOptions::SignReturnAddressKeyKind::AKey ? "a_key"
+   : "b_key");
+  }
+  if (BPI.BranchTargetEnforcement)
+FuncAttrs.addAttribute("branch-target-enforcement", "true");
+  if (BPI.BranchProtectionPAuthLR)
+FuncAttrs.addAttribute("branch-protection-pauth-lr", "true");
+  if (BPI.GuardedControlStack)
+FuncAttrs.addAttribute("guarded-control-stack", "true");
 }
 
 /// Merges `target-features` from \TargetOpts and \F, and sets the result in
diff --git a/clang/test/CodeGenCXX/arm64-generated-fn-attr.cpp 
b/clang/test/CodeGenCXX/arm64-generated-fn-attr.cpp
new file mode 100644
index 0..8daf44abd4f91
--- /dev/null
+++ b/clang/test/CodeGenCXX/arm64-generated-fn-attr.cpp
@@ -0,0 +1,30 @@
+// RUN: %clang_cc1 -triple aarch64-none-none -mbranch-target-enforce 
-msign-return-address=all -fcxx-exceptions -fexceptions -emit-llvm %s -o - | 
FileCheck %s --check-prefixes=CHECK
+
+// Check that functions generated by clang have the correct attributes
+
+class Example {
+public:
+  Example();
+  int fn();
+};
+
+// Initialization of var1 causes __cxx_global_var_init and __tls_init to be 
generated
+thread_local Example var1;
+extern thread_local Example var2;
+extern void fn();
+
+int testfn() noexcept {
+  // Calling fn in a noexcept function causes __clang_call_terminate to be 
generated
+  fn();
+  // Use of var1 and var2 causes TLS wrapper functions to be generated
+  return var1.fn() + var2.fn();
+}
+
+// CHECK: define {{.*}} @__cxx_global_var_init() [[ATTR1:#[0-9]+]]
+// CHECK: define {{.*}} @__clang_call_terminate({{.*}}) [[ATTR2:#[0-9]+]]
+// CHECK: define {{.*}} @_ZTW4var1() [[ATTR1]]
+// CHECK: define {{.*}} @_ZTW4var2() [[ATTR1]]
+// CHECK: define {{.*}} @__tls_init() [[ATTR1]]
+
+// CHECK: attributes [[ATTR1]] = { 
{{.*}}"branch-target-enforcement"="true"{{.*}}"sign-return-address"="all" 
"sign-return-address-key"="a_key"
+// CHECK: attributes [[ATTR2]] = { 
{{.*}}"branch-target-enforcement"="true"{{.*}}"sign-return-address"="all" 
"sign-return-address-key"="a_key"

>From 3e46bfa6bcd8a0cce142a4e1254c89ff68174117 Mon Sep 17 00:00:00 2001
From: Daniel Kiss 
Date: Wed, 28 Feb 2024 17:38:49 +0100
Subject: [PATCH 2/6] fixup! [Clang][Arm][AArch64] Add branch protection
 attributes to the defaults.

---
 clang/lib/CodeGen/CGCall.cpp | 5 +
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 5b59c77353675..58ccd3d181ccd 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -2027,10 +2027,7 @@ static void getTrivialDefaultFunctionAttributes(
 
   if (BPI.SignReturnAddr != LangOptions::SignReturnAddressScopeKind::None) {
 FuncAttrs.addAttribute("sign-return-address", BPI.getSignReturnAddrStr());
-FuncAttrs.addAttribute(
-"sign-return-address-key",
-BPI.SignKey == LangOptions::SignReturnAddressKeyKind::AKey ? "a_key"
-   : "b_key");
+FuncAttrs.addAttribute("sign-return-address-key", BPI.getSignKeyStr());
   }
   if (BPI.BranchTargetEnforcement)
 FuncAttrs.addAttribute("branch-target-enforcement", "true");

>From 054515d8b3b50b3efc792db9dfe4c9e61fa2507d Mon Sep 17 00:00:00 2001
From: Daniel Kiss 
Date: Mon, 4 Mar 2024 17:31:31 +0100
Subject: [PATCH 3/6] Move TargetInfo changes over.

Dropping restrictions on the member functions.
---
 clang/include/clang/Basic/TargetInfo.h | 43 +++---
 1 file changed, 39 insertions(+), 4 deletions(-)

diff --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index 76

[clang] [Clang][ARM][AArch64] Add branch protection attributes to the defaults. (PR #83277)

2024-07-10 Thread Daniel Kiss via cfe-commits

https://github.com/DanielKristofKiss updated 
https://github.com/llvm/llvm-project/pull/83277

>From 0c3118713387246dc1c503f3792ba5af82e6b5eb Mon Sep 17 00:00:00 2001
From: Daniel Kiss 
Date: Wed, 28 Feb 2024 15:18:31 +0100
Subject: [PATCH 1/6] Add branch protection attributes to the defaults.

These attributes are no longer inherited from the module flags,
therefore need to be added for synthetic functions.
---
 clang/lib/CodeGen/CGCall.cpp  | 16 ++
 .../CodeGenCXX/arm64-generated-fn-attr.cpp| 30 +++
 2 files changed, 46 insertions(+)
 create mode 100644 clang/test/CodeGenCXX/arm64-generated-fn-attr.cpp

diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 7e7b2b395f7d6..7b93f6d2dded1 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -2030,6 +2030,22 @@ static void getTrivialDefaultFunctionAttributes(
 std::tie(Var, Value) = Attr.split('=');
 FuncAttrs.addAttribute(Var, Value);
   }
+
+  TargetInfo::BranchProtectionInfo BPI(LangOpts);
+
+  if (BPI.SignReturnAddr != LangOptions::SignReturnAddressScopeKind::None) {
+FuncAttrs.addAttribute("sign-return-address", BPI.getSignReturnAddrStr());
+FuncAttrs.addAttribute(
+"sign-return-address-key",
+BPI.SignKey == LangOptions::SignReturnAddressKeyKind::AKey ? "a_key"
+   : "b_key");
+  }
+  if (BPI.BranchTargetEnforcement)
+FuncAttrs.addAttribute("branch-target-enforcement", "true");
+  if (BPI.BranchProtectionPAuthLR)
+FuncAttrs.addAttribute("branch-protection-pauth-lr", "true");
+  if (BPI.GuardedControlStack)
+FuncAttrs.addAttribute("guarded-control-stack", "true");
 }
 
 /// Merges `target-features` from \TargetOpts and \F, and sets the result in
diff --git a/clang/test/CodeGenCXX/arm64-generated-fn-attr.cpp 
b/clang/test/CodeGenCXX/arm64-generated-fn-attr.cpp
new file mode 100644
index 0..8daf44abd4f91
--- /dev/null
+++ b/clang/test/CodeGenCXX/arm64-generated-fn-attr.cpp
@@ -0,0 +1,30 @@
+// RUN: %clang_cc1 -triple aarch64-none-none -mbranch-target-enforce 
-msign-return-address=all -fcxx-exceptions -fexceptions -emit-llvm %s -o - | 
FileCheck %s --check-prefixes=CHECK
+
+// Check that functions generated by clang have the correct attributes
+
+class Example {
+public:
+  Example();
+  int fn();
+};
+
+// Initialization of var1 causes __cxx_global_var_init and __tls_init to be 
generated
+thread_local Example var1;
+extern thread_local Example var2;
+extern void fn();
+
+int testfn() noexcept {
+  // Calling fn in a noexcept function causes __clang_call_terminate to be 
generated
+  fn();
+  // Use of var1 and var2 causes TLS wrapper functions to be generated
+  return var1.fn() + var2.fn();
+}
+
+// CHECK: define {{.*}} @__cxx_global_var_init() [[ATTR1:#[0-9]+]]
+// CHECK: define {{.*}} @__clang_call_terminate({{.*}}) [[ATTR2:#[0-9]+]]
+// CHECK: define {{.*}} @_ZTW4var1() [[ATTR1]]
+// CHECK: define {{.*}} @_ZTW4var2() [[ATTR1]]
+// CHECK: define {{.*}} @__tls_init() [[ATTR1]]
+
+// CHECK: attributes [[ATTR1]] = { 
{{.*}}"branch-target-enforcement"="true"{{.*}}"sign-return-address"="all" 
"sign-return-address-key"="a_key"
+// CHECK: attributes [[ATTR2]] = { 
{{.*}}"branch-target-enforcement"="true"{{.*}}"sign-return-address"="all" 
"sign-return-address-key"="a_key"

>From 0e2a9e129bcb4f569a443494b9266ae482c73c94 Mon Sep 17 00:00:00 2001
From: Daniel Kiss 
Date: Wed, 28 Feb 2024 17:38:49 +0100
Subject: [PATCH 2/6] fixup! [Clang][Arm][AArch64] Add branch protection
 attributes to the defaults.

---
 clang/lib/CodeGen/CGCall.cpp | 5 +
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 7b93f6d2dded1..131666d732b3d 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -2035,10 +2035,7 @@ static void getTrivialDefaultFunctionAttributes(
 
   if (BPI.SignReturnAddr != LangOptions::SignReturnAddressScopeKind::None) {
 FuncAttrs.addAttribute("sign-return-address", BPI.getSignReturnAddrStr());
-FuncAttrs.addAttribute(
-"sign-return-address-key",
-BPI.SignKey == LangOptions::SignReturnAddressKeyKind::AKey ? "a_key"
-   : "b_key");
+FuncAttrs.addAttribute("sign-return-address-key", BPI.getSignKeyStr());
   }
   if (BPI.BranchTargetEnforcement)
 FuncAttrs.addAttribute("branch-target-enforcement", "true");

>From 735d24d5fe8bb4f37d87cb2345cbe45d53b1ba42 Mon Sep 17 00:00:00 2001
From: Daniel Kiss 
Date: Mon, 4 Mar 2024 17:31:31 +0100
Subject: [PATCH 3/6] Move TargetInfo changes over.

Dropping restrictions on the member functions.
---
 clang/include/clang/Basic/TargetInfo.h | 15 ---
 1 file changed, 15 deletions(-)

diff --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index 1f208b40f92cb..d8075ee97972e 1

[clang] [Clang][ARM][AArch64] Add branch protection attributes to the defaults. (PR #83277)

2024-07-10 Thread Daniel Kiss via cfe-commits

DanielKristofKiss wrote:

Sorry for the force push, need to be rebased. NFC since last review round.

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


[clang] [Clang][ARM] Call constructor on BranchTargetInfo. (PR #98307)

2024-07-10 Thread Daniel Kiss via cfe-commits


@@ -141,7 +141,7 @@ class ARMTargetCodeGenInfo : public TargetCodeGenInfo {
   ParsedTargetAttr Attr =
   CGM.getTarget().parseTargetAttr(TA->getFeaturesStr());
   if (!Attr.BranchProtection.empty()) {
-TargetInfo::BranchProtectionInfo BPI;
+TargetInfo::BranchProtectionInfo BPI{};

DanielKristofKiss wrote:

Right, now unnecessary, maybe more stylish.

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


[clang] [Clang][ARM] Call constructor on BranchTargetInfo. (PR #98307)

2024-07-10 Thread Daniel Kiss via cfe-commits

https://github.com/DanielKristofKiss updated 
https://github.com/llvm/llvm-project/pull/98307

>From 4e10c95c390e519853428f424cd655379d99c61c Mon Sep 17 00:00:00 2001
From: Daniel Kiss 
Date: Wed, 10 Jul 2024 13:58:52 +0200
Subject: [PATCH 1/3] [Clang][ARM] Call constructor on BranchTargetInfo.

Otherwise members will be uninitialised.
---
 clang/lib/CodeGen/Targets/ARM.cpp | 2 +-
 clang/lib/Sema/SemaDeclAttr.cpp   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/lib/CodeGen/Targets/ARM.cpp 
b/clang/lib/CodeGen/Targets/ARM.cpp
index d449b97cdc685..93fea94a77248 100644
--- a/clang/lib/CodeGen/Targets/ARM.cpp
+++ b/clang/lib/CodeGen/Targets/ARM.cpp
@@ -141,7 +141,7 @@ class ARMTargetCodeGenInfo : public TargetCodeGenInfo {
   ParsedTargetAttr Attr =
   CGM.getTarget().parseTargetAttr(TA->getFeaturesStr());
   if (!Attr.BranchProtection.empty()) {
-TargetInfo::BranchProtectionInfo BPI;
+TargetInfo::BranchProtectionInfo BPI{};
 StringRef DiagMsg;
 StringRef Arch =
 Attr.CPU.empty() ? CGM.getTarget().getTargetOpts().CPU : Attr.CPU;
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 73a85ff39667b..f2cd46d1e7c93 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -2991,7 +2991,7 @@ bool Sema::checkTargetAttr(SourceLocation LiteralLoc, 
StringRef AttrStr) {
  << Unsupported << None << CurFeature << Target;
   }
 
-  TargetInfo::BranchProtectionInfo BPI;
+  TargetInfo::BranchProtectionInfo BPI{};
   StringRef DiagMsg;
   if (ParsedAttrs.BranchProtection.empty())
 return false;

>From 4dfab4b3e6dca97ddc0348bcfbea7609170a3078 Mon Sep 17 00:00:00 2001
From: Daniel Kiss 
Date: Wed, 10 Jul 2024 16:01:47 +0200
Subject: [PATCH 2/3] Initialize members from the constructor.

---
 clang/include/clang/Basic/TargetInfo.h | 9 -
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index 1f208b40f92cb..079c71d10525f 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -1434,7 +1434,14 @@ class TargetInfo : public TransferrableTargetInfo,
 }
 
   public:
-BranchProtectionInfo() = default;
+BranchProtectionInfo() {
+  SignReturnAddr = LangOptions::SignReturnAddressScopeKind::None;
+  SignKey = LangOptions::SignReturnAddressKeyKind::AKey;
+  BranchTargetEnforcement = false;
+  BranchProtectionPAuthLR = false;
+  GuardedControlStack = false;
+};
+
 BranchProtectionInfo(const LangOptions &LangOpts) {
   SignReturnAddr =
   LangOpts.hasSignReturnAddress()

>From ba9ef1fd741f9213b958e299a11021c27e591c4b Mon Sep 17 00:00:00 2001
From: Daniel Kiss 
Date: Wed, 10 Jul 2024 17:19:40 +0200
Subject: [PATCH 3/3] move initilizers

---
 clang/include/clang/Basic/TargetInfo.h | 12 +---
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index 079c71d10525f..cf7628553647c 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -1434,13 +1434,11 @@ class TargetInfo : public TransferrableTargetInfo,
 }
 
   public:
-BranchProtectionInfo() {
-  SignReturnAddr = LangOptions::SignReturnAddressScopeKind::None;
-  SignKey = LangOptions::SignReturnAddressKeyKind::AKey;
-  BranchTargetEnforcement = false;
-  BranchProtectionPAuthLR = false;
-  GuardedControlStack = false;
-};
+BranchProtectionInfo()
+: SignReturnAddr(LangOptions::SignReturnAddressScopeKind::None),
+  SignKey(LangOptions::SignReturnAddressKeyKind::AKey),
+  BranchTargetEnforcement(false), BranchProtectionPAuthLR(false),
+  GuardedControlStack(false) {}
 
 BranchProtectionInfo(const LangOptions &LangOpts) {
   SignReturnAddr =

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


[clang] [Clang][ARM] Call constructor on BranchTargetInfo. (PR #98307)

2024-07-10 Thread Daniel Kiss via cfe-commits


@@ -1434,7 +1434,14 @@ class TargetInfo : public TransferrableTargetInfo,
 }
 
   public:
-BranchProtectionInfo() = default;
+BranchProtectionInfo() {
+  SignReturnAddr = LangOptions::SignReturnAddressScopeKind::None;
+  SignKey = LangOptions::SignReturnAddressKeyKind::AKey;
+  BranchTargetEnforcement = false;
+  BranchProtectionPAuthLR = false;
+  GuardedControlStack = false;
+};

DanielKristofKiss wrote:

right, added and clang-formated.

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


[clang] [llvm] [Clang][ARM][AArch64] Alway emit protection attributes for functions. (PR #82819)

2024-07-10 Thread Daniel Kiss via cfe-commits

DanielKristofKiss wrote:

> It looks like there's still a failure related to this patch on current main 
> AFAICT (MSAN finds a use of uninitialized value): 
> https://lab.llvm.org/buildbot/#/builders/169/builds/852/steps/12/logs/stdio
> 
Thanks, already noticed and addressed here: #98307



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


[clang] [NFC][Clang] Move functions of BranchProtectionInfo out of line (PR #98329)

2024-07-10 Thread Daniel Kiss via cfe-commits

https://github.com/DanielKristofKiss updated 
https://github.com/llvm/llvm-project/pull/98329

>From b1e113f76b289aa8a7d4459314a0dbffb313cb51 Mon Sep 17 00:00:00 2001
From: Daniel Kiss 
Date: Wed, 10 Jul 2024 16:23:11 +0200
Subject: [PATCH 1/2] [NFC][Clang] Move functions of BranchProtectionInfo out
 of line.

Also let's add const to the setFnAttributes.
---
 clang/include/clang/Basic/TargetInfo.h | 20 ++--
 clang/lib/Basic/TargetInfo.cpp | 20 
 2 files changed, 22 insertions(+), 18 deletions(-)

diff --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index 1f208b40f92cb..5a6a0cdbd316a 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -34,7 +34,6 @@
 #include "llvm/Frontend/OpenMP/OMPGridValues.h"
 #include "llvm/IR/Attributes.h"
 #include "llvm/IR/DerivedTypes.h"
-#include "llvm/IR/Function.h"
 #include "llvm/Support/DataTypes.h"
 #include "llvm/Support/Error.h"
 #include "llvm/Support/VersionTuple.h"
@@ -1450,24 +1449,9 @@ class TargetInfo : public TransferrableTargetInfo,
   GuardedControlStack = LangOpts.GuardedControlStack;
 }
 
-void setFnAttributes(llvm::Function &F) {
-  llvm::AttrBuilder FuncAttrs(F.getContext());
-  setFnAttributes(FuncAttrs);
-  F.addFnAttrs(FuncAttrs);
-}
+void setFnAttributes(llvm::Function &F) const;
 
-void setFnAttributes(llvm::AttrBuilder &FuncAttrs) {
-  if (SignReturnAddr != LangOptions::SignReturnAddressScopeKind::None) {
-FuncAttrs.addAttribute("sign-return-address", getSignReturnAddrStr());
-FuncAttrs.addAttribute("sign-return-address-key", getSignKeyStr());
-  }
-  if (BranchTargetEnforcement)
-FuncAttrs.addAttribute("branch-target-enforcement");
-  if (BranchProtectionPAuthLR)
-FuncAttrs.addAttribute("branch-protection-pauth-lr");
-  if (GuardedControlStack)
-FuncAttrs.addAttribute("guarded-control-stack");
-}
+void setFnAttributes(llvm::AttrBuilder &FuncAttrs) const;
   };
 
   /// Determine if the Architecture in this TargetInfo supports branch
diff --git a/clang/lib/Basic/TargetInfo.cpp b/clang/lib/Basic/TargetInfo.cpp
index 29f5cd14e46e1..a99ddd081ae28 100644
--- a/clang/lib/Basic/TargetInfo.cpp
+++ b/clang/lib/Basic/TargetInfo.cpp
@@ -18,6 +18,7 @@
 #include "clang/Basic/LangOptions.h"
 #include "llvm/ADT/APFloat.h"
 #include "llvm/ADT/STLExtras.h"
+#include "llvm/IR/Function.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/TargetParser/TargetParser.h"
 #include 
@@ -1005,3 +1006,22 @@ void TargetInfo::copyAuxTarget(const TargetInfo *Aux) {
   auto *Src = static_cast(Aux);
   *Target = *Src;
 }
+
+void TargetInfo::BranchProtectionInfo::setFnAttributes(llvm::Function &F) 
const {
+  llvm::AttrBuilder FuncAttrs(F.getContext());
+  setFnAttributes(FuncAttrs);
+  F.addFnAttrs(FuncAttrs);
+}
+
+void  TargetInfo::BranchProtectionInfo::setFnAttributes(llvm::AttrBuilder 
&FuncAttrs) const {
+  if (SignReturnAddr != LangOptions::SignReturnAddressScopeKind::None) {
+FuncAttrs.addAttribute("sign-return-address", getSignReturnAddrStr());
+FuncAttrs.addAttribute("sign-return-address-key", getSignKeyStr());
+  }
+  if (BranchTargetEnforcement)
+FuncAttrs.addAttribute("branch-target-enforcement");
+  if (BranchProtectionPAuthLR)
+FuncAttrs.addAttribute("branch-protection-pauth-lr");
+  if (GuardedControlStack)
+FuncAttrs.addAttribute("guarded-control-stack");
+}

>From 4ecad898afea255f22c23babed20da305cbd43eb Mon Sep 17 00:00:00 2001
From: Daniel Kiss 
Date: Wed, 10 Jul 2024 18:02:21 +0200
Subject: [PATCH 2/2] clangformnat

---
 clang/lib/Basic/TargetInfo.cpp | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Basic/TargetInfo.cpp b/clang/lib/Basic/TargetInfo.cpp
index a99ddd081ae28..cc4b79b4334af 100644
--- a/clang/lib/Basic/TargetInfo.cpp
+++ b/clang/lib/Basic/TargetInfo.cpp
@@ -1007,13 +1007,15 @@ void TargetInfo::copyAuxTarget(const TargetInfo *Aux) {
   *Target = *Src;
 }
 
-void TargetInfo::BranchProtectionInfo::setFnAttributes(llvm::Function &F) 
const {
+void TargetInfo::BranchProtectionInfo::setFnAttributes(
+llvm::Function &F) const {
   llvm::AttrBuilder FuncAttrs(F.getContext());
   setFnAttributes(FuncAttrs);
   F.addFnAttrs(FuncAttrs);
 }
 
-void  TargetInfo::BranchProtectionInfo::setFnAttributes(llvm::AttrBuilder 
&FuncAttrs) const {
+void TargetInfo::BranchProtectionInfo::setFnAttributes(
+llvm::AttrBuilder &FuncAttrs) const {
   if (SignReturnAddr != LangOptions::SignReturnAddressScopeKind::None) {
 FuncAttrs.addAttribute("sign-return-address", getSignReturnAddrStr());
 FuncAttrs.addAttribute("sign-return-address-key", getSignKeyStr());

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


[clang] [NFC][Clang] Move functions of BranchProtectionInfo out of line (PR #98329)

2024-07-10 Thread Daniel Kiss via cfe-commits

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


[clang] Revert "[NFC][Clang] Move functions of BranchProtectionInfo out of line" (PR #98437)

2024-07-10 Thread Daniel Kiss via cfe-commits

https://github.com/DanielKristofKiss created 
https://github.com/llvm/llvm-project/pull/98437

Reverts llvm/llvm-project#98329

>From 9a74d0613287e7ae86c305b0250e188e3c3de6c3 Mon Sep 17 00:00:00 2001
From: Daniel Kiss 
Date: Thu, 11 Jul 2024 08:37:25 +0200
Subject: [PATCH] Revert "[NFC][Clang] Move functions of BranchProtectionInfo
 out of line (#98329)"

This reverts commit 4710e0f498cb661ca17c99cb174616102fcad923.
---
 clang/include/clang/Basic/TargetInfo.h | 23 +++
 clang/lib/Basic/TargetInfo.cpp | 22 --
 2 files changed, 19 insertions(+), 26 deletions(-)

diff --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index 6afa354353e3c..cf7628553647c 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -32,7 +32,9 @@
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/StringSet.h"
 #include "llvm/Frontend/OpenMP/OMPGridValues.h"
+#include "llvm/IR/Attributes.h"
 #include "llvm/IR/DerivedTypes.h"
+#include "llvm/IR/Function.h"
 #include "llvm/Support/DataTypes.h"
 #include "llvm/Support/Error.h"
 #include "llvm/Support/VersionTuple.h"
@@ -45,8 +47,6 @@
 
 namespace llvm {
 struct fltSemantics;
-class Function;
-class AttrBuilder;
 }
 
 namespace clang {
@@ -1455,9 +1455,24 @@ class TargetInfo : public TransferrableTargetInfo,
   GuardedControlStack = LangOpts.GuardedControlStack;
 }
 
-void setFnAttributes(llvm::Function &F) const;
+void setFnAttributes(llvm::Function &F) {
+  llvm::AttrBuilder FuncAttrs(F.getContext());
+  setFnAttributes(FuncAttrs);
+  F.addFnAttrs(FuncAttrs);
+}
 
-void setFnAttributes(llvm::AttrBuilder &FuncAttrs) const;
+void setFnAttributes(llvm::AttrBuilder &FuncAttrs) {
+  if (SignReturnAddr != LangOptions::SignReturnAddressScopeKind::None) {
+FuncAttrs.addAttribute("sign-return-address", getSignReturnAddrStr());
+FuncAttrs.addAttribute("sign-return-address-key", getSignKeyStr());
+  }
+  if (BranchTargetEnforcement)
+FuncAttrs.addAttribute("branch-target-enforcement");
+  if (BranchProtectionPAuthLR)
+FuncAttrs.addAttribute("branch-protection-pauth-lr");
+  if (GuardedControlStack)
+FuncAttrs.addAttribute("guarded-control-stack");
+}
   };
 
   /// Determine if the Architecture in this TargetInfo supports branch
diff --git a/clang/lib/Basic/TargetInfo.cpp b/clang/lib/Basic/TargetInfo.cpp
index cc4b79b4334af..29f5cd14e46e1 100644
--- a/clang/lib/Basic/TargetInfo.cpp
+++ b/clang/lib/Basic/TargetInfo.cpp
@@ -18,7 +18,6 @@
 #include "clang/Basic/LangOptions.h"
 #include "llvm/ADT/APFloat.h"
 #include "llvm/ADT/STLExtras.h"
-#include "llvm/IR/Function.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/TargetParser/TargetParser.h"
 #include 
@@ -1006,24 +1005,3 @@ void TargetInfo::copyAuxTarget(const TargetInfo *Aux) {
   auto *Src = static_cast(Aux);
   *Target = *Src;
 }
-
-void TargetInfo::BranchProtectionInfo::setFnAttributes(
-llvm::Function &F) const {
-  llvm::AttrBuilder FuncAttrs(F.getContext());
-  setFnAttributes(FuncAttrs);
-  F.addFnAttrs(FuncAttrs);
-}
-
-void TargetInfo::BranchProtectionInfo::setFnAttributes(
-llvm::AttrBuilder &FuncAttrs) const {
-  if (SignReturnAddr != LangOptions::SignReturnAddressScopeKind::None) {
-FuncAttrs.addAttribute("sign-return-address", getSignReturnAddrStr());
-FuncAttrs.addAttribute("sign-return-address-key", getSignKeyStr());
-  }
-  if (BranchTargetEnforcement)
-FuncAttrs.addAttribute("branch-target-enforcement");
-  if (BranchProtectionPAuthLR)
-FuncAttrs.addAttribute("branch-protection-pauth-lr");
-  if (GuardedControlStack)
-FuncAttrs.addAttribute("guarded-control-stack");
-}

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


  1   2   >