[clang] [clang][driver] Support `-x` for all languages in CL mode (PR #89772)

2024-05-23 Thread Fangrui Song via cfe-commits

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


[clang] [llvm] [PowerPC] Support -fpatchable-function-entry (PR #92997)

2024-05-23 Thread Fangrui Song via cfe-commits

MaskRay wrote:

> So PPC64 can use ELFv2 for `Triple::OpenBSD`. We probably want to diagnose 
> this OS for PPC64, since with ELFv2 we might emit separate local and global 
> entry points which means only certain values can be passed to 
> `-fpatchable-function-entry` option.

This patch matches the intended end result: NOPs before the global entry and 
after the local entry.

The current way GCC handles `N,M` where M>0 is undesired and will hopefully be 
soon changed: https://gcc.gnu.org/pipermail/gcc-patches/2024-May/651025.html , 
matching what I suggested in 2022: 
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99888#c5

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


[clang] [llvm] [PowerPC] Support -fpatchable-function-entry (PR #92997)

2024-05-23 Thread Fangrui Song via cfe-commits

https://github.com/MaskRay requested changes to this pull request.


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


[clang] [llvm] [PowerPC] Support -fpatchable-function-entry (PR #92997)

2024-05-23 Thread Fangrui Song via cfe-commits


@@ -0,0 +1,49 @@
+; RUN: llc -mtriple=powerpc-unknown-linux-gnu %s -o - | FileCheck %s 
--check-prefixes=CHECK,PPC32

MaskRay wrote:

`-mtriple=powerpc`. Prefer a generic ELF triple to a Linux specific one.

Suggest 2 RUN lines, `powerpc` and `powerpc64le`, to catch both 32-bit/64-bit 
and LE/BE.

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


[clang] [llvm] [PowerPC] Support -fpatchable-function-entry (PR #92997)

2024-05-23 Thread Fangrui Song via cfe-commits


@@ -6681,7 +6681,9 @@ void Clang::ConstructJob(Compilation , const JobAction 
,
 StringRef S0 = A->getValue(), S = S0;
 unsigned Size, Offset = 0;
 if (!Triple.isAArch64() && !Triple.isLoongArch() && !Triple.isRISCV() &&
-!Triple.isX86())
+!Triple.isX86() &&
+!(!Triple.isOSAIX() && (Triple.getArch() == llvm::Triple::ppc ||

MaskRay wrote:

little-endian variants (ppcle ppc64le) are omitted here.

Use `isPPC`

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


[clang] [llvm] [PowerPC] Support -fpatchable-function-entry (PR #92997)

2024-05-23 Thread Fangrui Song via cfe-commits


@@ -6,15 +6,20 @@
 // RUN: %clang -target loongarch64 %s -fpatchable-function-entry=1,0 -c -### 
2>&1 | FileCheck %s
 // RUN: %clang -target riscv32 %s -fpatchable-function-entry=1,0 -c -### 2>&1 
| FileCheck %s
 // RUN: %clang -target riscv64 %s -fpatchable-function-entry=1,0 -c -### 2>&1 
| FileCheck %s
+// RUN: %clang -target powerpc-unknown-linux-gnu %s 
-fpatchable-function-entry=1,0 -c -### 2>&1 | FileCheck %s

MaskRay wrote:

Use `--target=` for new tests. `-target ` has been deprecated for a long time

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


[clang] [llvm] [PowerPC] Support -fpatchable-function-entry (PR #92997)

2024-05-23 Thread Fangrui Song via cfe-commits


@@ -0,0 +1,49 @@
+; RUN: llc -mtriple=powerpc-unknown-linux-gnu %s -o - | FileCheck %s 
--check-prefixes=CHECK,PPC32
+; RUN: llc -mtriple=powerpc64-unknown-linux-gnu %s -o - | FileCheck %s 
--check-prefixes=CHECK,PPC64
+
+define void @f0() {
+; CHECK-LABEL: f0:
+; CHECK-NOT:   nop
+; CHECK:   # %bb.0:
+; CHECK-NEXT:blr
+; CHECK-NOT:   .section__patchable_function_entries
+  ret void
+}
+
+define void @f1() "patchable-function-entry"="0" {
+; CHECK-LABEL: f1:
+; CHECK-NOT:   nop
+; CHECK:   # %bb.0:
+; CHECK-NEXT:blr
+; CHECK-NOT:   .section__patchable_function_entries
+  ret void
+}
+
+define void @f2() "patchable-function-entry"="1" {
+; CHECK-LABEL: f2:
+; CHECK-LABEL-NEXT:  .Lfunc_begin2:
+; CHECK:   # %bb.0:
+; CHECK-NEXT:nop
+; CHECK-NEXT:blr
+; CHECK:   .section__patchable_function_entries
+; PPC32:   .p2align2, 0x0
+; PPC64:   .p2align3, 0x0
+; PPC32-NEXT:  .long   .Lfunc_begin2
+; PPC64-NEXT:  .quad   .Lfunc_begin2
+  ret void
+}
+
+define void @f3() "patchable-function-entry"="1" 
"patchable-function-prefix"="2" {
+; CHECK-LABEL: .Ltmp0:
+; CHECK-COUNT-2: nop
+; CHECK-LABEL: f3:

MaskRay wrote:

Test addis/addi, instructions at the global entry point.

Per https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99888#c5 `#c8` and `#15`, GCC 
will change the current strategy to match us :)

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


[clang] [llvm] [PowerPC] Support -fpatchable-function-entry (PR #92997)

2024-05-23 Thread Fangrui Song via cfe-commits


@@ -0,0 +1,4 @@
+// RUN: %clang_cc1 -triple powerpc64-ibm-aix-xcoff -fsyntax-only -verify %s
+
+// expected-error@+1 {{'patchable_function_entry' attribute is not yet 
supported on AIX}}
+__attribute__((patchable_function_entry(0))) void f();

MaskRay wrote:

Some test directory adopt `rm -rf %t && split-file %s %t && cd %t` 
(https://llvm.org/docs/TestingGuide.html#extra-files)

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


[clang] [llvm] [PowerPC] Support -fpatchable-function-entry (PR #92997)

2024-05-23 Thread Fangrui Song via cfe-commits

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


[clang] d03e56b - [Driver] Simplify -f[no-]sized-deallocation forwarding. NFC

2024-05-23 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2024-05-23T16:03:46-07:00
New Revision: d03e56b27cd992e29482a21d88693f626f3dfffb

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

LOG: [Driver] Simplify -f[no-]sized-deallocation forwarding. NFC

Added: 


Modified: 
clang/lib/Driver/ToolChains/Clang.cpp
llvm/include/llvm/Option/ArgList.h

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 588f0c511cd2e..18de8781e894a 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -7265,13 +7265,8 @@ void Clang::ConstructJob(Compilation , const JobAction 
,
 
   // -fsized-deallocation is on by default in C++14 onwards and otherwise off
   // by default.
-  if (Arg *A = Args.getLastArg(options::OPT_fsized_deallocation,
-   options::OPT_fno_sized_deallocation)) {
-if (A->getOption().matches(options::OPT_fno_sized_deallocation))
-  CmdArgs.push_back("-fno-sized-deallocation");
-else
-  CmdArgs.push_back("-fsized-deallocation");
-  }
+  Args.addLastArg(CmdArgs, options::OPT_fsized_deallocation,
+  options::OPT_fno_sized_deallocation);
 
   // -faligned-allocation is on by default in C++17 onwards and otherwise off
   // by default.

diff  --git a/llvm/include/llvm/Option/ArgList.h 
b/llvm/include/llvm/Option/ArgList.h
index fcde68e0b7fe8..09812f976d016 100644
--- a/llvm/include/llvm/Option/ArgList.h
+++ b/llvm/include/llvm/Option/ArgList.h
@@ -319,11 +319,15 @@ class ArgList {
   }
 
   /// Render only the last argument match \p Id0, if present.
-  template
-  void AddLastArg(ArgStringList , OptSpecifiers ...Ids) const {
+  template 
+  void addLastArg(ArgStringList , OptSpecifiers... Ids) const {
 if (Arg *A = getLastArg(Ids...)) // Calls claim() on all Ids's Args.
   A->render(*this, Output);
   }
+  template 
+  void AddLastArg(ArgStringList , OptSpecifiers... Ids) const {
+addLastArg(Output, Ids...);
+  }
 
   /// AddAllArgsExcept - Render all arguments matching any of the given ids
   /// and not matching any of the excluded ids.



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


[clang] [compiler-rt] [lldb] [llvm] [Support] Remove terminfo dependency (PR #92865)

2024-05-23 Thread Fangrui Song via cfe-commits

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


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


[clang] [z/OS] Set the default arch for z/OS to be arch10 (PR #89854)

2024-05-23 Thread Fangrui Song via cfe-commits


@@ -11,6 +11,8 @@
 //
 
//===--===//
 
+#include "clang/Config/config.h"

MaskRay wrote:

If SystemZ.h uses CLANG_SYSTEMZ_DEFAULT_ARCH, that file should have `#include 
"clang/Config/config.h"` as IWYU

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


[clang] [compiler-rt] [libc] [libclc] [libcxxabi] [lld] [lldb] [llvm] [mlir] Add clarifying parenthesis around non-trivial conditions in ternary expressions. (PR #90391)

2024-05-22 Thread Fangrui Song via cfe-commits


@@ -801,7 +801,7 @@ static OutputDesc 
*addInputSec(StringMap> ,
   auto *firstIsec = cast(
   cast(sec->commands[0])->sectionBases[0]);
   OutputSection *firstIsecOut =
-  firstIsec->flags & SHF_LINK_ORDER

MaskRay wrote:

A CppCheck issue may or may not be useful for the project. Projects have 
different code styles. Applying a random static analyzer report may not be 
useful.

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


[clang] [z/OS] Set the default arch for z/OS to be arch10 (PR #89854)

2024-05-22 Thread Fangrui Song via cfe-commits


@@ -10,6 +10,8 @@
 //
 
//===--===//
 
+#include "clang/Config/config.h"

MaskRay wrote:

unneeded include

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


[clang] [z/OS] Set the default arch for z/OS to be arch10 (PR #89854)

2024-05-22 Thread Fangrui Song via cfe-commits


@@ -11,6 +11,8 @@
 //
 
//===--===//
 
+#include "clang/Config/config.h"

MaskRay wrote:

unneeded include

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


[clang] [lldb] [llvm] Remove some `try_compile` CMake checks for compiler flags (PR #92953)

2024-05-21 Thread Fangrui Song via cfe-commits

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

Great  

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


[clang] [llvm] [CodeGen] Assign SHT_LLVM_LTO to .llvm.lto section (PR #92856)

2024-05-21 Thread Fangrui Song via cfe-commits

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


[clang] [llvm] [CodeGen] Assign SHT_LLVM_LTO to .llvm.lto section (PR #92856)

2024-05-21 Thread Fangrui Song via cfe-commits

MaskRay wrote:

Oh, I didn't know #92820! Thanks. Landing...

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


[clang] [llvm] [CodeGen] Assign SHT_LLVM_LTO to .llvm.lto section (PR #92856)

2024-05-20 Thread Fangrui Song via cfe-commits

MaskRay wrote:

@ilovepi I just realized that the FatLTO LLVM patch did not incorporate 
https://reviews.llvm.org/D153215 . I thought it did... Hope this is not too 
late.

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


[clang] [llvm] [CodeGen] Assign SHT_LLVM_LTO to .llvm.lto section (PR #92856)

2024-05-20 Thread Fangrui Song via cfe-commits

https://github.com/MaskRay created 
https://github.com/llvm/llvm-project/pull/92856

This follows up to SHT_LLVM_LTO (https://reviews.llvm.org/D153215) and
resolves the comment of the FatLTO patch
https://reviews.llvm.org/D146776#4430626


>From fdf70f50de2d51223f3f04b2db4913360ded3469 Mon Sep 17 00:00:00 2001
From: Fangrui Song 
Date: Mon, 20 May 2024 22:08:41 -0700
Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?=
 =?UTF-8?q?l=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.5-bogner
---
 clang/test/CodeGen/fat-lto-objects.c  | 2 +-
 llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp | 2 ++
 llvm/test/CodeGen/X86/fat-lto-section.ll  | 2 +-
 3 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/clang/test/CodeGen/fat-lto-objects.c 
b/clang/test/CodeGen/fat-lto-objects.c
index b50567c024fc8..36a73684e7bfe 100644
--- a/clang/test/CodeGen/fat-lto-objects.c
+++ b/clang/test/CodeGen/fat-lto-objects.c
@@ -62,7 +62,7 @@
 
 // ELF: .llvm.lto
 
-//  ASM: .section.llvm.lto,"e",@progbits
+//  ASM: .section.llvm.lto,"e",@llvm_lto
 // ASM-NEXT: .Lllvm.embedded.object:
 // ASM-NEXT:.asciz  "BC
 // ASM-NEXT: .size   .Lllvm.embedded.object
diff --git a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp 
b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
index 3e1897ce670a6..0fc915d89f6c0 100644
--- a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
+++ b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
@@ -523,6 +523,8 @@ static unsigned getELFSectionType(StringRef Name, 
SectionKind K) {
 
   if (hasPrefix(Name, ".llvm.offloading"))
 return ELF::SHT_LLVM_OFFLOADING;
+  if (Name == ".llvm.lto")
+return ELF::SHT_LLVM_LTO;
 
   if (K.isBSS() || K.isThreadBSS())
 return ELF::SHT_NOBITS;
diff --git a/llvm/test/CodeGen/X86/fat-lto-section.ll 
b/llvm/test/CodeGen/X86/fat-lto-section.ll
index 30c56229a0e2a..f3ca8436affb4 100644
--- a/llvm/test/CodeGen/X86/fat-lto-section.ll
+++ b/llvm/test/CodeGen/X86/fat-lto-section.ll
@@ -5,6 +5,6 @@
 ; RUN:   | FileCheck %s --check-prefix=EXCLUDE
 
 ; EXCLUDE: Name   Type {{.*}} ES Flg Lk Inf Al
-; EXCLUDE: .llvm.lto  PROGBITS {{.*}} 00   E  0   0  1
+; EXCLUDE: .llvm.lto  LLVM_LTO {{.*}} 00   E  0   0  1
 
 @a = global i32 1

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


[clang] [llvm] [mlir] Use StringRef::find_first_of(char), etc (NFC) (PR #92841)

2024-05-20 Thread Fangrui Song via cfe-commits

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


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


[clang] [compiler-rt] [compiler-rt] Realtime Sanitizer: Introduce RADSan backend (PR #92460)

2024-05-20 Thread Fangrui Song via cfe-commits

MaskRay wrote:

https://discourse.llvm.org/t/rfc-nolock-and-noalloc-attributes/76837/75 
contains a discussion about the subproject name.
Do you have opinions? @llvm/pr-subscribers-sanitizer @compnerd @petrhosek  
@isanbard

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


[clang] [Offload] Do not pass `-fcf-protection=` for offloading (PR #88402)

2024-05-20 Thread Fangrui Song via cfe-commits


@@ -0,0 +1,39 @@
+// Check that -fcf-protection does not get passed to the device-side

MaskRay wrote:

We also have unsupported-option-gpu.c to test various ignored options for GPU.

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


[clang] [llvm] [MC] Make UseAssemblerInfoForParsing mostly true (PR #91082)

2024-05-20 Thread Fangrui Song via cfe-commits

MaskRay wrote:

> @MaskRay It looks like the new version still causes large compile-time 
> regressions for sqlite3 debug builds: 
> http://llvm-compile-time-tracker.com/compare.php?from=7529fe2e92e79eef22a528a7168e4dd777d6e9bd=9500a5d02e23f9b43294e5f662ac099f8989c0e4=instructions:u
>  It's smaller than before (2% instead of 4%) but still there.

Thanks for the report. 245491a9f384e4c53421196533c2a2b693efaf8d should fix the 
regression.

---

Related to the poor performance of MCAssembler based constant folding
(see `bool MCExpr::evaluateAsAbsolute(int64_t , const MCAssembler *Asm) 
const` and
`AttemptToFoldSymbolOffsetDifference`),
commit 9500a5d02e23f9b43294e5f662ac099f8989c0e4 caused -O0 -g compile time 
regression.

9500a5d02e23f9b43294e5f662ac099f8989c0e4 special cased .eh_frame FDE emitting. 
We need a special case for .debug_* emitting as well to mitigate the rest 
regression.

---

The MCAssembler based constant folding strategy should be improved to remove 
the two special cases.


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


[clang] [clang] Introduce `SemaRISCV` (PR #92682)

2024-05-20 Thread Fangrui Song via cfe-commits


@@ -1,12 +1,12 @@
-//==- SemaRISCVVectorLookup.cpp - Name Lookup for RISC-V Vector Intrinsic -==//
+//==--- SemaRISCV.cpp --- RISC-V target-specific routines 
--==//

MaskRay wrote:

The prevailing style starts with `//===-` or `//===--`

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


[clang] [clang] Introduce `SemaRISCV` (PR #92682)

2024-05-20 Thread Fangrui Song via cfe-commits

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


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


[clang] [clang] Introduce `SemaRISCV` (PR #92682)

2024-05-20 Thread Fangrui Song via cfe-commits

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


[clang] [clang] Introduce `SemaRISCV` (PR #92682)

2024-05-20 Thread Fangrui Song via cfe-commits

MaskRay wrote:

Nice refactoring! Pushing a prerequisite commit first with `git mv 
SemaRISCVVectorLookup.cpp SemaRISCV.cpp` should make git recognize this as a 
file rename. This PR can be changed to rebase on that precommit.

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


[clang] [compiler-rt] [compiler-rt] Realtime Sanitizer: Introduce RADSan backend (PR #92460)

2024-05-20 Thread Fangrui Song via cfe-commits


@@ -0,0 +1,106 @@
+//===--- radsan_context.cpp - Realtime Sanitizer --*- 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
+//
+//===--===//
+//
+//===--===//
+
+#include 
+
+#include 
+
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+
+using namespace __sanitizer;
+
+namespace detail {
+
+static pthread_key_t Key;

MaskRay wrote:

Yes, `variable_name` and `FunctionName`.. Sorry if this change may take a while.
asan/hwasan/lsan are good examples to follow.



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


[clang] [clang] Use SmallString::str (NFC) (PR #92717)

2024-05-20 Thread Fangrui Song via cfe-commits

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


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


[clang] 9500a5d - [MC] Make UseAssemblerInfoForParsing mostly true

2024-05-20 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2024-05-19T23:35:15-07:00
New Revision: 9500a5d02e23f9b43294e5f662ac099f8989c0e4

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

LOG: [MC] Make UseAssemblerInfoForParsing mostly true

Commit 6c0665e22174d474050e85ca367424f6e02476be
(https://reviews.llvm.org/D45164) enabled certain constant expression
evaluation for `MCObjectStreamer` at parse time (e.g. `.if` directives,
see llvm/test/MC/AsmParser/assembler-expressions.s).

`getUseAssemblerInfoForParsing` was added to make `clang -c` handling
inline assembly similar to `MCAsmStreamer` (e.g. `llvm-mc -filetype=asm`),
where such expression folding (related to
`AttemptToFoldSymbolOffsetDifference`) is unavailable.

I believe this is overly conservative. We can make some parse-time
expression folding work for `clang -c` even if `clang -S` would still
report an error, a MCAsmStreamer issue (we cannot print `.if`
directives) that should not restrict the functionality of
MCObjectStreamer.

```
% cat b.cc
asm(R"(
.pushsection .text,"ax"
.globl _start; _start: ret
.if . -_start == 1
  ret
.endif
.popsection
)");
% gcc -S b.cc && gcc -c b.cc
% clang -S -fno-integrated-as b.cc # succeeded

% clang -c b.cc # succeeded with this patch
% clang -S b.cc # still failed
:4:5: error: expected absolute expression
4 | .if . -_start == 1
  | ^
1 error generated.
```

However, removing `getUseAssemblerInfoForParsing` would make
MCDwarfFrameEmitter::Emit (for .eh_frame FDE) slow (~4% compile time
regression for sqlite3.c amalgamation) due to expensive
`AttemptToFoldSymbolOffsetDifference`. For now, make
`UseAssemblerInfoForParsing` false in MCDwarfFrameEmitter::Emit.

Close #62520
Link: 
https://discourse.llvm.org/t/rfc-clang-assembly-object-equivalence-for-files-with-inline-assembly/78841

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

Added: 


Modified: 
clang/tools/driver/cc1as_main.cpp
llvm/include/llvm/MC/MCStreamer.h
llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp
llvm/lib/MC/MCDwarf.cpp
llvm/lib/MC/MCObjectStreamer.cpp
llvm/lib/MC/MCStreamer.cpp
llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp
llvm/lib/Target/SPIRV/SPIRVAsmPrinter.cpp
llvm/test/MC/AsmParser/assembler-expressions-inlineasm.ll
llvm/tools/llvm-mc/llvm-mc.cpp
llvm/tools/llvm-ml/llvm-ml.cpp

Removed: 




diff  --git a/clang/tools/driver/cc1as_main.cpp 
b/clang/tools/driver/cc1as_main.cpp
index 86afe22fac24c..4eb753a7297a9 100644
--- a/clang/tools/driver/cc1as_main.cpp
+++ b/clang/tools/driver/cc1as_main.cpp
@@ -576,9 +576,6 @@ static bool ExecuteAssemblerImpl(AssemblerInvocation ,
 Str.get()->emitZeros(1);
   }
 
-  // Assembly to object compilation should leverage assembly info.
-  Str->setUseAssemblerInfoForParsing(true);
-
   bool Failed = false;
 
   std::unique_ptr Parser(

diff  --git a/llvm/include/llvm/MC/MCStreamer.h 
b/llvm/include/llvm/MC/MCStreamer.h
index 69867620e1bf8..b7468cf70a664 100644
--- a/llvm/include/llvm/MC/MCStreamer.h
+++ b/llvm/include/llvm/MC/MCStreamer.h
@@ -245,7 +245,7 @@ class MCStreamer {
   /// requires.
   unsigned NextWinCFIID = 0;
 
-  bool UseAssemblerInfoForParsing;
+  bool UseAssemblerInfoForParsing = true;
 
   /// Is the assembler allowed to insert padding automatically?  For
   /// correctness reasons, we sometimes need to ensure instructions aren't
@@ -296,6 +296,8 @@ class MCStreamer {
 
   MCContext () const { return Context; }
 
+  // MCObjectStreamer has an MCAssembler and allows more expression folding at
+  // parse time.
   virtual MCAssembler *getAssemblerPtr() { return nullptr; }
 
   void setUseAssemblerInfoForParsing(bool v) { UseAssemblerInfoForParsing = v; 
}

diff  --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp 
b/llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp
index d0ef3e5a19391..08e3c208ba4d3 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp
@@ -102,9 +102,6 @@ void AsmPrinter::emitInlineAsm(StringRef Str, const 
MCSubtargetInfo ,
   std::unique_ptr Parser(
   createMCAsmParser(SrcMgr, OutContext, *OutStreamer, *MAI, BufNum));
 
-  // Do not use assembler-level information for parsing inline assembly.
-  OutStreamer->setUseAssemblerInfoForParsing(false);
-
   // We create a new MCInstrInfo here since we might be at the module level
   // and not have a MachineFunction to initialize the TargetInstrInfo from and
   // we only need MCInstrInfo for asm parsing. We create one unconditionally

diff  --git a/llvm/lib/MC/MCDwarf.cpp b/llvm/lib/MC/MCDwarf.cpp
index 2ee0c3eb27b92..aba4071e6b910 100644
--- a/llvm/lib/MC/MCDwarf.cpp
+++ b/llvm/lib/MC/MCDwarf.cpp
@@ -1910,6 +1910,11 @@ void 

[clang] [llvm] [MC] Make UseAssemblerInfoForParsing mostly true (PR #91082)

2024-05-20 Thread Fangrui Song via cfe-commits

MaskRay wrote:

Removing `getUseAssemblerInfoForParsing` would make MCDwarfFrameEmitter::Emit 
(for .eh_frame FDE) slow (~4% compile time regression for sqlite3.c 
amalgamation) due to expensive `AttemptToFoldSymbolOffsetDifference`. For now, 
make `UseAssemblerInfoForParsing` false in MCDwarfFrameEmitter::Emit.

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


[clang] [llvm] [MC] Make UseAssemblerInfoForParsing mostly true (PR #91082)

2024-05-20 Thread Fangrui Song via cfe-commits

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


[clang] [compiler-rt] [compiler-rt] Realtime Sanitizer: Introduce RADSan backend (PR #92460)

2024-05-19 Thread Fangrui Song via cfe-commits


@@ -0,0 +1,71 @@
+# -*- Python -*-
+
+import os
+
+# Setup config name.
+config.name = "RADSAN" + config.name_suffix
+
+# Setup source root.
+config.test_source_root = os.path.dirname(__file__)

MaskRay wrote:

`msan`, `lsan`, `gwp_asan` places lit tests directly under the directory, while 
some use `TestCases/`. Avoiding `TestCases` is preferred. Is the lit set up to 
avoid `TestCases`?

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


[clang] [compiler-rt] [compiler-rt] Realtime Sanitizer: Introduce RADSan backend (PR #92460)

2024-05-19 Thread Fangrui Song via cfe-commits


@@ -0,0 +1,413 @@
+//===--- radsan_interceptors.cpp - Realtime Sanitizer --*- 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
+//
+//===--===//
+//
+//===--===//
+
+#include "radsan/radsan_interceptors.h"
+
+#include "sanitizer_common/sanitizer_platform.h"
+#include "sanitizer_common/sanitizer_platform_interceptors.h"
+
+#include "interception/interception.h"
+#include "radsan/radsan_context.h"
+
+#if !SANITIZER_LINUX && !SANITIZER_APPLE
+#error Sorry, radsan does not yet support this platform
+#endif
+
+#if SANITIZER_APPLE
+#include 
+#include 
+#endif
+
+#if SANITIZER_INTERCEPT_MEMALIGN || SANITIZER_INTERCEPT_PVALLOC
+#include 
+#endif
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+using namespace __sanitizer;
+
+namespace radsan {
+void ExpectNotRealtime(const char *InterceptedFunctionName) {
+  GetContextForThisThread().ExpectNotRealtime(InterceptedFunctionName);
+}
+} // namespace radsan
+
+/*

MaskRay wrote:

Avoid `/*` in C++ files

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


[clang] [compiler-rt] [compiler-rt] Realtime Sanitizer: Introduce RADSan backend (PR #92460)

2024-05-19 Thread Fangrui Song via cfe-commits


@@ -0,0 +1,38 @@
+//===--- radsan_context.h - Realtime Sanitizer --*- 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
+//
+//===--===//
+//
+//===--===//
+
+#pragma once
+
+namespace radsan {

MaskRay wrote:

`__radsan` to avoid conflicts with user programs

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


[clang] [compiler-rt] [compiler-rt] Realtime Sanitizer: Introduce RADSan backend (PR #92460)

2024-05-19 Thread Fangrui Song via cfe-commits


@@ -0,0 +1,52 @@
+//===--- radsan_stack.cpp - Realtime Sanitizer --*- 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
+//
+//===--===//
+//
+//===--===//
+
+#include 
+#include 
+
+using namespace __sanitizer;
+
+// We must define our own implementation of this method for our runtime.
+// This one is just copied from UBSan.
+
+namespace __sanitizer {
+void BufferedStackTrace::UnwindImpl(uptr pc, uptr bp, void *context,
+bool request_fast, u32 max_depth) {
+  uptr top = 0;
+  uptr bottom = 0;
+  GetThreadStackTopAndBottom(false, , );
+  bool fast = StackTrace::WillUseFastUnwind(request_fast);
+  Unwind(max_depth, pc, bp, context, top, bottom, fast);
+}
+} // namespace __sanitizer
+
+namespace {
+void SetGlobalStackTraceFormat() {
+  SetCommonFlagsDefaults();
+  CommonFlags cf;
+  cf.CopyFrom(*common_flags());
+  cf.stack_trace_format = "DEFAULT";
+  cf.external_symbolizer_path = GetEnv("RADSAN_SYMBOLIZER_PATH");
+  OverrideCommonFlags(cf);
+}
+} // namespace
+
+namespace radsan {
+void PrintStackTrace() {

MaskRay wrote:

https://llvm.org/docs/CodingStandards.html#use-namespace-qualifiers-to-implement-previously-declared-functions

`void radsan::PrintStackTrace`

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


[clang] [compiler-rt] [compiler-rt] Realtime Sanitizer: Introduce RADSan backend (PR #92460)

2024-05-19 Thread Fangrui Song via cfe-commits


@@ -0,0 +1,106 @@
+//===--- radsan_context.cpp - Realtime Sanitizer --*- 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
+//
+//===--===//
+//
+//===--===//
+
+#include 
+
+#include 
+
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+
+using namespace __sanitizer;
+
+namespace detail {
+
+static pthread_key_t Key;

MaskRay wrote:

Avoid `VariableName` in new compiler-rt code.

Use the recommended `variable_name` like asan/hwasan/lsan. Some new compiler-rt 
subprojects used `Variable` as cargo culting llvm/ and clang/, which is a pity 
(you can also read https://llvm.org/docs/Proposals/VariableNames.html for more 
history)

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


[clang] [compiler-rt] [compiler-rt] Realtime Sanitizer: Introduce RADSan backend (PR #92460)

2024-05-19 Thread Fangrui Song via cfe-commits


@@ -0,0 +1,50 @@
+//===--- radsan.h - Realtime Sanitizer --*- 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
+//
+//===--===//
+//
+//===--===//
+
+#pragma once
+
+#include "sanitizer_common/sanitizer_internal_defs.h"
+
+extern "C" {
+
+/**  Initialise radsan interceptors.
+
+  A call to this method is added to the preinit array on Linux systems.
+*/
+SANITIZER_INTERFACE_ATTRIBUTE void radsan_init();
+
+/** Enter real-time context.
+
+  When in a real-time context, RADSan interceptors will error if realtime
+  violations are detected. Calls to this method are injected at the code
+  generation stage when RADSan is enabled.
+*/
+SANITIZER_INTERFACE_ATTRIBUTE void radsan_realtime_enter();

MaskRay wrote:

Use `__*` names to avoid conflicts with user code. Use `//`.

If there are user APIs, define them at `include/sanitizer/*_interface.h`

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


[clang] [compiler-rt] [compiler-rt] Realtime Sanitizer: Introduce RADSan backend (PR #92460)

2024-05-19 Thread Fangrui Song via cfe-commits


@@ -0,0 +1,52 @@
+//===--- radsan_stack.cpp - Realtime Sanitizer --*- 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
+//
+//===--===//
+//
+//===--===//
+
+#include 
+#include 
+
+using namespace __sanitizer;
+
+// We must define our own implementation of this method for our runtime.
+// This one is just copied from UBSan.
+
+namespace __sanitizer {
+void BufferedStackTrace::UnwindImpl(uptr pc, uptr bp, void *context,
+bool request_fast, u32 max_depth) {
+  uptr top = 0;
+  uptr bottom = 0;
+  GetThreadStackTopAndBottom(false, , );
+  bool fast = StackTrace::WillUseFastUnwind(request_fast);
+  Unwind(max_depth, pc, bp, context, top, bottom, fast);
+}
+} // namespace __sanitizer
+
+namespace {
+void SetGlobalStackTraceFormat() {

MaskRay wrote:

https://llvm.org/docs/CodingStandards.html#anonymous-namespaces

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


[clang] [compiler-rt] [compiler-rt] Realtime Sanitizer: Introduce RADSan backend (PR #92460)

2024-05-19 Thread Fangrui Song via cfe-commits


@@ -0,0 +1,71 @@
+# -*- Python -*-

MaskRay wrote:

Delete

Some older `lit.cfg.py` files might use this because previously they were named 
`lit.cfg`

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


[clang] [compiler-rt] [compiler-rt] Realtime Sanitizer: Introduce RADSan backend (PR #92460)

2024-05-19 Thread Fangrui Song via cfe-commits


@@ -1382,6 +1382,10 @@ collectSanitizerRuntimes(const ToolChain , const 
ArgList ,
   StaticRuntimes.push_back("asan_cxx");
   }
 
+  if (!SanArgs.needsSharedRt() && SanArgs.needsRadsanRt()) {
+StaticRuntimes.push_back("radsan");
+  }

MaskRay wrote:

I have some notes at 
https://maskray.me/blog/2023-01-08-all-about-sanitizer-interceptors#static-runtime

Nit: we omit braces in this single-line statement case 
https://llvm.org/docs/CodingStandards.html#don-t-use-braces-on-simple-single-statement-bodies-of-if-else-loop-statements

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


[clang] [clang-tools-extra] [clang] Use operator==(StringRef, StringRef) (NFC) (PR #92708)

2024-05-19 Thread Fangrui Song via cfe-commits

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

LGTM with a nit

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


[clang] [clang-tools-extra] [clang] Use operator==(StringRef, StringRef) (NFC) (PR #92708)

2024-05-19 Thread Fangrui Song via cfe-commits


@@ -435,9 +435,8 @@ static std::string replaceDotDot(StringRef Path) {
   llvm::sys::path::const_iterator B = llvm::sys::path::begin(Path),
 E = llvm::sys::path::end(Path);
   while (B != E) {
-if (B->compare(".") == 0) {
-}
-else if (B->compare("..") == 0)
+if (*B == ".") {
+} else if (*B == "..")
   llvm::sys::path::remove_filename(Buffer);
 else

MaskRay wrote:

Refactor this to `else if (*B != ".")`

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


[clang] [llvm] [MC,llvm-readobj,yaml2obj] Support CREL relocation format (PR #91280)

2024-05-19 Thread Fangrui Song via cfe-commits


@@ -0,0 +1,100 @@
+# RUN: llvm-mc -filetype=obj -crel -triple=x86_64 %s -o %t.o
+# RUN: llvm-readelf -Sr -x .crelrodata2 -x .crelrodata16 %t.o | FileCheck %s
+
+# RUN: %if aarch64-registered-target %{ llvm-mc -filetype=obj -crel 
-triple=aarch64_be %s -o %t.be.o %}
+# RUN: %if aarch64-registered-target %{ llvm-readelf -r %t.be.o | FileCheck %s 
--check-prefix=A64BE %}
+
+# CHECK:  [ 4] .data PROGBITS   {{.*}} 
08 00  WA  0   0  1
+# CHECK-NEXT: [ 5] .crel.dataCREL   {{.*}} 
2a 01   I 14   4  1
+# CHECK-NEXT: [ 6] .rodata   PROGBITS   {{.*}} 
2b 00   A  0   0  1
+# CHECK-NEXT: [ 7] .crel.rodata  CREL   {{.*}} 
10 01   I 14   6  1
+# CHECK-NEXT: [ 8] rodata2   PROGBITS   {{.*}} 
08 00   A  0   0  1
+# CHECK-NEXT: [ 9] .crelrodata2  CREL   {{.*}} 
05 01   I 14   8  1
+# CHECK-NEXT: [10] rodata16  PROGBITS   {{.*}} 
10 00   A  0   0  1
+# CHECK-NEXT: [11] .crelrodata16 CREL   {{.*}} 
04 01   I 14  10  1
+# CHECK-NEXT: [12] noalloc   PROGBITS   {{.*}} 
04 00  0   0  1
+# CHECK-NEXT: [13] .crelnoalloc  CREL   {{.*}} 
05 01   I 14  12  1
+# CHECK-NEXT: [14] .symtab   SYMTAB
+
+# CHECK:  Relocation section '.crel.data' at offset {{.*}} contains 7 
entries:
+# CHECK-NEXT: Offset Info Type   
Symbol's Value  Symbol's Name + Addend
+# CHECK-NEXT:   {{.*}}   R_X86_64_NONE  
 a0 + 0
+# CHECK-NEXT: 0001  {{.*}}   R_X86_64_NONE  
 a1 - 1
+# CHECK-NEXT: 0002  {{.*}}   R_X86_64_NONE  
 a2 - 1
+# CHECK-NEXT: 0003  {{.*}}   R_X86_64_32
 a3 + 4000
+# CHECK-NEXT: 0004  {{.*}}   R_X86_64_64
 a0 - 8000
+# CHECK-NEXT: 0005  {{.*}}   R_X86_64_64
 a1 + 7fff
+# CHECK-NEXT: 0005  {{.*}}   R_X86_64_32
 a1 - 1
+# CHECK-EMPTY:
+# CHECK-NEXT: Relocation section '.crel.rodata' at offset {{.*}} contains 4 
entries:
+# CHECK-NEXT: Offset Info Type   
Symbol's Value  Symbol's Name + Addend
+# CHECK-NEXT:   {{.*}}   R_X86_64_PC32  
 foo + 0
+# CHECK-NEXT: 000f  {{.*}}   R_X86_64_PC32  
 foo + 3f
+# CHECK-NEXT: 001f  {{.*}}   R_X86_64_PC64  
 foo + 7f
+# CHECK-NEXT: 0027  {{.*}}   R_X86_64_PC32  
 _start - 1f81
+# CHECK-EMPTY:
+# CHECK-NEXT: Relocation section '.crelrodata2' at offset {{.*}} contains 2 
entries:
+# CHECK-NEXT: Offset Info Type   
Symbol's Value  Symbol's Name + Addend
+# CHECK-NEXT: 0002  {{.*}}   R_X86_64_32
 .data + 0
+# CHECK-NEXT: 0008  {{.*}}   R_X86_64_32
 .data + 0
+# CHECK-EMPTY:
+# CHECK-NEXT: Relocation section '.crelrodata16' at offset {{.*}} contains 1 
entries:
+# CHECK-NEXT: Offset Info Type   
Symbol's Value  Symbol's Name + Addend
+# CHECK-NEXT: 0008  {{.*}}   R_X86_64_64
 rodata16 + 0
+# CHECK-EMPTY:
+# CHECK-NEXT: Relocation section '.crelnoalloc' at offset {{.*}} contains 1 
entries:
+# CHECK-NEXT: Offset Info Type   
Symbol's Value  Symbol's Name + Addend
+# CHECK-NEXT:   {{.*}}   R_X86_64_32
 .text + 4
+
+## count * 8 + 4 + shift = 2*8+4+1 = 21
+# CHECK:  Hex dump of section '.crelrodata2':
+# CHECK-NEXT: 0x 150b020a 18 .
+## count * 8 + 4 + shift = 1*8+4+3 = 15
+# CHECK:  Hex dump of section '.crelrodata16':
+# CHECK-NEXT: 0x 0f0b0301 .
+
+# A64BE:    {{.*}}   R_AARCH64_NONE 
 a0 + 0
+# A64BE-NEXT: 0001  {{.*}}   R_AARCH64_NONE 
 a1 - 1
+# A64BE-NEXT: 0002  {{.*}}   R_AARCH64_NONE 
 a2 - 1
+# A64BE-NEXT: 0003  {{.*}}   R_AARCH64_ABS32
 a3 + 4000
+# A64BE-NEXT: 0004  {{.*}}   R_AARCH64_ABS64
 a0 - 8000
+# A64BE-NEXT: 0005  {{.*}}   R_AARCH64_ABS64
 a1 + 7fff
+# A64BE-NEXT: 0005  {{.*}}   

[clang] [llvm] [MC,llvm-readobj,yaml2obj] Support CREL relocation format (PR #91280)

2024-05-19 Thread Fangrui Song via cfe-commits


@@ -1278,29 +1285,69 @@ void ELFState::writeSectionContent(
   if (!Section.Relocations)
 return;
 
+  const bool IsCrel = Section.Type == llvm::ELF::SHT_CREL;
   const bool IsRela = Section.Type == llvm::ELF::SHT_RELA;
+  typename ELFT::uint OffsetMask = 8, Offset = 0, Addend = 0;
+  uint32_t Symidx = 0, Type = 0;
+  uint64_t CurrentOffset = CBA.getOffset();
+  if (IsCrel)
+for (const ELFYAML::Relocation  : *Section.Relocations)
+  OffsetMask |= Rel.Offset;
+  const int Shift = llvm::countr_zero(OffsetMask);
+  if (IsCrel)
+CBA.writeULEB128(Section.Relocations->size() * 8 + 4 + Shift);
   for (const ELFYAML::Relocation  : *Section.Relocations) {
 const bool IsDynamic = Section.Link && (*Section.Link == ".dynsym");
-unsigned SymIdx =
+uint32_t CurSymidx =
 Rel.Symbol ? toSymbolIndex(*Rel.Symbol, Section.Name, IsDynamic) : 0;
-if (IsRela) {
+if (IsCrel) {

MaskRay wrote:

I've thought about an abstraction. However, the variable and `toSymbolIndex` 
mechanism are different, making me feel that code sharing would be cumbersome...

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


[clang] [llvm] [MC,llvm-readobj,yaml2obj] Support CREL relocation format (PR #91280)

2024-05-19 Thread Fangrui Song via cfe-commits


@@ -3840,14 +3849,15 @@ void GNUELFDumper::printRelRelaReloc(const 
Relocation ,
 
 template 
 static void printRelocHeaderFields(formatted_raw_ostream , unsigned SType,
-   const typename ELFT::Ehdr ) {
+   const typename ELFT::Ehdr ,
+   uint64_t CrelHdr = 0) {
   bool IsRela = SType == ELF::SHT_RELA || SType == ELF::SHT_ANDROID_RELA;
   if (ELFT::Is64Bits)
 OS << "Offset Info Type   Symbol's 
"
   "Value  Symbol's Name";
   else
 OS << " Offset InfoTypeSym. Value  Symbol's Name";
-  if (IsRela)
+  if (IsRela || (SType == ELF::SHT_CREL && (CrelHdr & 4)))

MaskRay wrote:

Defined `CREL_HDR_ADDEND` and used it here

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


[clang] [llvm] [MC,llvm-readobj,yaml2obj] Support CREL relocation format (PR #91280)

2024-05-19 Thread Fangrui Song via cfe-commits


@@ -86,6 +86,8 @@ DYNAMIC_TAG(RELRSZ, 35)  // Size of Relr relocation table.
 DYNAMIC_TAG(RELR, 36)// Address of relocation table (Relr entries).
 DYNAMIC_TAG(RELRENT, 37) // Size of a Relr relocation entry.
 
+DYNAMIC_TAG(CREL,  38)   // CREL relocation table
+

MaskRay wrote:

The commit message mentions:

> Without linker/dynamic loader concern, there is even less concern for people 
> unintentionally using this.

I tentatively think it is not worth the trouble to avoid the generic range.

> Although not strictly necessary a CREL Size (CRELSZ?) could be useful for a 
> consumer to read all the CRELs into memory without having to read the header 
> first to find the size. Again not worth doing unless we have a definite need 
> for it.

I've thought about this but believe CRELSZ is not so necessary.

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


[clang] [llvm] [MC,llvm-readobj,yaml2obj] Support CREL relocation format (PR #91280)

2024-05-19 Thread Fangrui Song via cfe-commits


@@ -32,12 +32,17 @@ FileHeader:
 # RUN: --match-full-lines --check-prefixes=GNU-RELOCS,GNU-PLTRELA
 
 # LLVM-RELOCS:  Dynamic Relocations {
+# LLVM-RELOCS-NEXT:   0x8 R_X86_64_64 foo 0x0
 # LLVM-RELOCS-NEXT:   0x1 R_X86_64_NONE foo 0x0
 # LLVM-RELOCS-NEXT:   0x2 R_X86_64_NONE foo
-# LLVM-RELOCS-NEXT:   0x4 R_X86_64_RELATIVE
+# LLVM-RELOCS-NEXT:   0x4 R_X86_64_RELATIVE -

MaskRay wrote:

llvm-readobj (LLVM style) displays `-` when the symbol index is 0.
This line in the absence of the patch contains a `-` as well.

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


[clang] [llvm] [MC,llvm-readobj,yaml2obj] Support CREL relocation format (PR #91280)

2024-05-19 Thread Fangrui Song via cfe-commits


@@ -123,6 +123,12 @@ class ContiguousBlobAccumulator {
 return encodeULEB128(Val, OS);
   }
 
+  unsigned writeSLEB128(int64_t Val) {
+if (!checkLimit(10))

MaskRay wrote:

Yes, LEB128 representing 64-bit integer needs at most 10 bytes.
I added a change detector test to `relocation-crel.yaml` to catch the case.



The limit in writeULEB128 is incorrect, which can be fixed separately.

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


[clang] [llvm] [MC,llvm-readobj,yaml2obj] Support CREL relocation format (PR #91280)

2024-05-19 Thread Fangrui Song via cfe-commits


@@ -0,0 +1,18 @@
+# REQUIRES: powerpc-registered-target
+## Test CREL for a 32-bit big-endian target.

MaskRay wrote:

Thanks for the suggestion. Changed ppc to arm.

For static relocations, the RELA form is exclusively used as recommended 
toolchain practice.

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


[clang] [llvm] [MC,llvm-readobj,yaml2obj] Support CREL relocation format (PR #91280)

2024-05-19 Thread Fangrui Song via cfe-commits


@@ -934,10 +943,51 @@ void ELFWriter::WriteSecHdrEntry(uint32_t Name, uint32_t 
Type, uint64_t Flags,
   WriteWord(EntrySize); // sh_entsize
 }
 
+template 
+static void encodeCrel(ArrayRef Relocs, raw_ostream ) {
+  uint OffsetMask = 8, Offset = 0, Addend = 0;
+  uint32_t Symidx = 0, Type = 0;
+  // hdr & 4 indicates 3 flag bits in delta offset and flags members.
+  for (unsigned i = 0, e = Relocs.size(); i != e; ++i)

MaskRay wrote:

Fixed

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


[clang] [llvm] [MC,llvm-readobj,yaml2obj] Support CREL relocation format (PR #91280)

2024-05-19 Thread Fangrui Song via cfe-commits


@@ -1278,29 +1285,69 @@ void ELFState::writeSectionContent(
   if (!Section.Relocations)
 return;
 
+  const bool IsCrel = Section.Type == llvm::ELF::SHT_CREL;
   const bool IsRela = Section.Type == llvm::ELF::SHT_RELA;
+  typename ELFT::uint OffsetMask = 8, Offset = 0, Addend = 0;
+  uint32_t Symidx = 0, Type = 0;
+  uint64_t CurrentOffset = CBA.getOffset();
+  if (IsCrel)

MaskRay wrote:

The comments in ELFObjectWriter.cpp and ELFEmitter.cpp are the same. The one in 
ELFEmitter.cpp is indended more, leading to a difference in text wrapping.

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


[clang] [llvm] [MC,llvm-readobj,yaml2obj] Support CREL relocation format (PR #91280)

2024-05-19 Thread Fangrui Song via cfe-commits

https://github.com/MaskRay updated 
https://github.com/llvm/llvm-project/pull/91280

>From a0cfafb82db825512b0ca44778fa9d4bb435563d Mon Sep 17 00:00:00 2001
From: Fangrui Song 
Date: Mon, 6 May 2024 15:37:50 -0700
Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?=
 =?UTF-8?q?l=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.5-bogner
---
 clang/include/clang/Basic/CodeGenOptions.def  |   1 +
 .../clang/Basic/DiagnosticDriverKinds.td  |   3 +
 clang/include/clang/Driver/Options.td |   3 +
 clang/lib/CodeGen/BackendUtil.cpp |   1 +
 clang/lib/Driver/ToolChains/Clang.cpp |  18 ++
 clang/lib/Driver/ToolChains/CommonArgs.cpp|  21 ++
 clang/test/Driver/crel.c  |  24 +++
 clang/test/Misc/cc1as-crel.s  |   6 +
 clang/tools/driver/cc1as_main.cpp |   6 +
 .../include/llvm/BinaryFormat/DynamicTags.def |   2 +
 llvm/include/llvm/BinaryFormat/ELF.h  |   1 +
 llvm/include/llvm/MC/MCTargetOptions.h|   3 +
 .../llvm/MC/MCTargetOptionsCommandFlags.h |   1 +
 llvm/include/llvm/Object/ELF.h|   5 +
 llvm/include/llvm/Object/ELFObjectFile.h  |  70 ++-
 llvm/include/llvm/Object/ELFTypes.h   |  25 +++
 llvm/lib/MC/ELFObjectWriter.cpp   | 110 ---
 llvm/lib/MC/MCTargetOptionsCommandFlags.cpp   |   6 +
 llvm/lib/Object/ELF.cpp   |  63 ++
 llvm/lib/ObjectYAML/ELFEmitter.cpp|  60 +-
 llvm/lib/ObjectYAML/ELFYAML.cpp   |   2 +
 llvm/test/MC/ELF/crel-32.s|  16 ++
 llvm/test/MC/ELF/crel.s   | 100 ++
 llvm/test/tools/llvm-readobj/ELF/crel.test| 180 ++
 .../tools/llvm-readobj/ELF/dynamic-reloc.test |  31 ++-
 .../llvm-readobj/ELF/relocation-errors.test   |  19 +-
 .../yaml2obj/ELF/dynamic-relocations.yaml |   5 +-
 .../yaml2obj/ELF/reloc-sec-entry-size.yaml|   5 +
 .../tools/yaml2obj/ELF/relocation-crel.yaml   |  63 ++
 .../ELF/relocation-missing-symbol.yaml|   3 +-
 .../tools/yaml2obj/ELF/relocation-type.yaml   |   4 +-
 llvm/tools/llvm-readobj/ELFDumper.cpp |  81 +++-
 32 files changed, 883 insertions(+), 55 deletions(-)
 create mode 100644 clang/test/Driver/crel.c
 create mode 100644 clang/test/Misc/cc1as-crel.s
 create mode 100644 llvm/test/MC/ELF/crel-32.s
 create mode 100644 llvm/test/MC/ELF/crel.s
 create mode 100644 llvm/test/tools/llvm-readobj/ELF/crel.test
 create mode 100644 llvm/test/tools/yaml2obj/ELF/relocation-crel.yaml

diff --git a/clang/include/clang/Basic/CodeGenOptions.def 
b/clang/include/clang/Basic/CodeGenOptions.def
index 340b08dd7e2a3..3229f77eef1fc 100644
--- a/clang/include/clang/Basic/CodeGenOptions.def
+++ b/clang/include/clang/Basic/CodeGenOptions.def
@@ -36,6 +36,7 @@ VALUE_CODEGENOPT(Name, Bits, Default)
 #endif
 
 CODEGENOPT(DisableIntegratedAS, 1, 0) ///< -no-integrated-as
+CODEGENOPT(Crel, 1, 0) ///< -Wa,--crel
 CODEGENOPT(RelaxELFRelocations, 1, 1) ///< -Wa,-mrelax-relocations={yes,no}
 CODEGENOPT(AsmVerbose, 1, 0) ///< -dA, -fverbose-asm.
 CODEGENOPT(PreserveAsmComments, 1, 1) ///< -dA, -fno-preserve-as-comments.
diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index 9781fcaa4ff5e..e9cea8967c133 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -809,6 +809,9 @@ def warn_drv_missing_multilib : Warning<
 def note_drv_available_multilibs : Note<
   "available multilibs are:%0">;
 
+def err_drv_experimental_crel : Error<
+  "-Wa,--experimental-crel must be specified to use -Wa,--crel. CREL is 
experimental and takes a non-standard section type code">;
+
 def warn_android_unversioned_fallback : Warning<
   "Using unversioned Android target directory %0 for target %1. Unversioned"
   " directories will not be used in Clang 19. Provide a versioned directory"
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index c9f7c4e5f718b..55f0c9aff6a49 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -6958,6 +6958,9 @@ def massembler_no_warn : Flag<["-"], 
"massembler-no-warn">,
 def massembler_fatal_warnings : Flag<["-"], "massembler-fatal-warnings">,
   HelpText<"Make assembler warnings fatal">,
   MarshallingInfoFlag>;
+def crel : Flag<["--"], "crel">,
+  HelpText<"Enable CREL relocation format (ELF only)">,
+  MarshallingInfoFlag>;
 def mrelax_relocations_no : Flag<["-"], "mrelax-relocations=no">,
 HelpText<"Disable x86 relax relocations">,
 MarshallingInfoNegativeFlag>;
diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 22c3f8642ad8e..ed37085d69ac5 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ 

[clang] e2db08f - [test] Use conventional -emit-llvm-only

2024-05-17 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2024-05-17T14:42:48-07:00
New Revision: e2db08f8f1a7dd37cd18705164f0c1188707e5b6

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

LOG: [test] Use conventional -emit-llvm-only

Similar to a6d7828f4c50c1ec7b0b5f61fe59d7a768175dcc

Added: 


Modified: 
clang/test/Sema/aarch64-sme2-intrinsics/acle_sme2_add_sub_za16.c

Removed: 




diff  --git a/clang/test/Sema/aarch64-sme2-intrinsics/acle_sme2_add_sub_za16.c 
b/clang/test/Sema/aarch64-sme2-intrinsics/acle_sme2_add_sub_za16.c
index fb43bc6337086..4a3a5a86a668b 100644
--- a/clang/test/Sema/aarch64-sme2-intrinsics/acle_sme2_add_sub_za16.c
+++ b/clang/test/Sema/aarch64-sme2-intrinsics/acle_sme2_add_sub_za16.c
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme -verify 
-emit-llvm %s
+// RUN: %clang_cc1 -triple aarch64 -target-feature +sme -verify 
-emit-llvm-only %s
 
 // REQUIRES: aarch64-registered-target
 



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


[clang] [llvm] [AArch64] Add intrinsics for multi-vector to ZA array vector accumulators (PR #91606)

2024-05-17 Thread Fangrui Song via cfe-commits


@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme -verify 
-emit-llvm %s

MaskRay wrote:

`-emit-llvm-only` is more conventional when the output is unneeded.

In our internal build system, PWD is read-only and `-emit-llvm` would cause a 
failure.
I changed this to `-emit-llvm-only` and changed `aarch64-none-linux-gnu` (none 
is sometimes used as an OS) to `aarch64` (generic ELF) to indicate that the 
behavior does not require Linux.

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


[clang] [CodeGen] Support arrays with initializers of 64-bit size (PR #92473)

2024-05-17 Thread Fangrui Song via cfe-commits

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


[clang] [z/OS] Set the default arch for z/OS to be arch10 (PR #89854)

2024-05-17 Thread Fangrui Song via cfe-commits

MaskRay wrote:

> @MaskRay Got it.
> 
> The problem with that solution is that if you use --target you won't get the 
> correct arch. This would be a problem for any cross compilation. For example, 
> say you cross compile from zLinux (which wouldn't have the config file), the 
> arch would be arch8. And if you cross compiled from z/OS (with the config 
> file) to zLinux then the default arch would be arch10. Both of these would be 
> incorrect.
> 
> We also use the config files for installation specific information. It is 
> common for users to have their own config files. If we require that the 
> option be in the config file then we would be creating a very error prone 
> situation.
> 
> We need to be able to change the arch default based on the target triple.

Sorry for the late reply. Such driver defaults via cmake variable would make 
testing brittle. Users expect that `check-clang` pass regardless of the cmake 
variable setting. If a test changes behavior due to different `-march=`, there 
are a few choices:

* add a `REQUIRES: zos-new-default-march` directive
* hard code a `-march=`

Neither is immediately noticeable. In the past clang/test/Driver has had many 
such tests that require fixup. We have tried removing some unnecessary 
`CLANG_DEFAULT_*`.

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


[clang] [CodeGen] Support arrays with initializers of 64-bit size (PR #92473)

2024-05-16 Thread Fangrui Song via cfe-commits


@@ -949,11 +949,11 @@ tryEmitGlobalCompoundLiteral(ConstantEmitter ,
 
 static llvm::Constant *
 EmitArrayConstant(CodeGenModule , llvm::ArrayType *DesiredType,
-  llvm::Type *CommonElementType, unsigned ArrayBound,
+  llvm::Type *CommonElementType, uint64_t ArrayBound,
   SmallVectorImpl ,
   llvm::Constant *Filler) {
   // Figure out how long the initial prefix of non-zero elements is.
-  unsigned NonzeroLength = ArrayBound;
+  uint64_t NonzeroLength = ArrayBound;
   if (Elements.size() < NonzeroLength && Filler->isNullValue())
 NonzeroLength = Elements.size();
   if (NonzeroLength == Elements.size()) {

MaskRay wrote:

Thanks for catching this. Fixed and added a test.

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


[clang] [CodeGen] Support arrays with initializers of 64-bit size (PR #92473)

2024-05-16 Thread Fangrui Song via cfe-commits

https://github.com/MaskRay updated 
https://github.com/llvm/llvm-project/pull/92473

>From fec942ed085d2a4004a6cefcb7fdf20a4b062ca3 Mon Sep 17 00:00:00 2001
From: Fangrui Song 
Date: Thu, 16 May 2024 16:24:01 -0700
Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?=
 =?UTF-8?q?l=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.5-bogner
---
 clang/lib/CodeGen/CGExprConstant.cpp | 12 ++--
 clang/lib/Sema/SemaInit.cpp  |  4 ++--
 clang/test/CodeGen/array-init.c  |  7 +++
 3 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/clang/lib/CodeGen/CGExprConstant.cpp 
b/clang/lib/CodeGen/CGExprConstant.cpp
index 94962091116af..ce57279a6eb65 100644
--- a/clang/lib/CodeGen/CGExprConstant.cpp
+++ b/clang/lib/CodeGen/CGExprConstant.cpp
@@ -393,7 +393,7 @@ bool ConstantAggregateBuilder::split(size_t Index, 
CharUnits Hint) {
 
 static llvm::Constant *
 EmitArrayConstant(CodeGenModule , llvm::ArrayType *DesiredType,
-  llvm::Type *CommonElementType, unsigned ArrayBound,
+  llvm::Type *CommonElementType, uint64_t ArrayBound,
   SmallVectorImpl ,
   llvm::Constant *Filler);
 
@@ -949,11 +949,11 @@ tryEmitGlobalCompoundLiteral(ConstantEmitter ,
 
 static llvm::Constant *
 EmitArrayConstant(CodeGenModule , llvm::ArrayType *DesiredType,
-  llvm::Type *CommonElementType, unsigned ArrayBound,
+  llvm::Type *CommonElementType, uint64_t ArrayBound,
   SmallVectorImpl ,
   llvm::Constant *Filler) {
   // Figure out how long the initial prefix of non-zero elements is.
-  unsigned NonzeroLength = ArrayBound;
+  uint64_t NonzeroLength = ArrayBound;
   if (Elements.size() < NonzeroLength && Filler->isNullValue())
 NonzeroLength = Elements.size();
   if (NonzeroLength == Elements.size()) {
@@ -1252,12 +1252,12 @@ class ConstExprEmitter
   llvm::Constant *EmitArrayInitialization(const InitListExpr *ILE, QualType T) 
{
 auto *CAT = CGM.getContext().getAsConstantArrayType(ILE->getType());
 assert(CAT && "can't emit array init for non-constant-bound array");
-unsigned NumInitElements = ILE->getNumInits();
-unsigned NumElements = CAT->getZExtSize();
+const uint64_t NumElements = CAT->getZExtSize();
 
 // Initialising an array requires us to automatically
 // initialise any elements that have not been initialised explicitly
-unsigned NumInitableElts = std::min(NumInitElements, NumElements);
+uint64_t NumInitableElts =
+std::min(ILE->getNumInits(), NumElements);
 
 QualType EltType = CAT->getElementType();
 
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 2177972f3af2c..353e911c5cc33 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -876,7 +876,7 @@ InitListChecker::FillInEmptyInitializations(const 
InitializedEntity ,
 
   InitializedEntity ElementEntity = Entity;
   unsigned NumInits = ILE->getNumInits();
-  unsigned NumElements = NumInits;
+  uint64_t NumElements = NumInits;
   if (const ArrayType *AType = SemaRef.Context.getAsArrayType(ILE->getType())) 
{
 ElementType = AType->getElementType();
 if (const auto *CAType = dyn_cast(AType))
@@ -896,7 +896,7 @@ InitListChecker::FillInEmptyInitializations(const 
InitializedEntity ,
 ElementType = ILE->getType();
 
   bool SkipEmptyInitChecks = false;
-  for (unsigned Init = 0; Init != NumElements; ++Init) {
+  for (uint64_t Init = 0; Init != NumElements; ++Init) {
 if (hadError)
   return;
 
diff --git a/clang/test/CodeGen/array-init.c b/clang/test/CodeGen/array-init.c
index 62e87edc29741..9075df68c7358 100644
--- a/clang/test/CodeGen/array-init.c
+++ b/clang/test/CodeGen/array-init.c
@@ -13,3 +13,10 @@ void testConstArrayInits(void)
   const int a2[5] = {0,0,0};
   const int a3[5] = {0};
 }
+
+/// https://github.com/llvm/llvm-project/issues/57353
+// CHECK: @big_char ={{.*}} global <{ i8, [4294967295 x i8] }> <{ i8 1, 
[4294967295 x i8] zeroinitializer }>
+char big_char[4294967296] = {1};
+
+// CHECK: @big_int ={{.*}} global <{ i32, [2147483647 x i32] }> <{ i32 1, 
[2147483647 x i32] zeroinitializer }>
+int big_int[0x2 >> 2] = {1};

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


[clang] [CodeGen] Support arrays with initializers of 64-bit size (PR #92473)

2024-05-16 Thread Fangrui Song via cfe-commits

https://github.com/MaskRay created 
https://github.com/llvm/llvm-project/pull/92473

Based on @OfekShochat's https://reviews.llvm.org/D133648

init.c is the primary test for array initialization, but it uses a
32-bit triple, which would lead to an "array is too large" error. Add
the new test to array-init.c instead.

Fix #57353


>From fec942ed085d2a4004a6cefcb7fdf20a4b062ca3 Mon Sep 17 00:00:00 2001
From: Fangrui Song 
Date: Thu, 16 May 2024 16:24:01 -0700
Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?=
 =?UTF-8?q?l=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.5-bogner
---
 clang/lib/CodeGen/CGExprConstant.cpp | 12 ++--
 clang/lib/Sema/SemaInit.cpp  |  4 ++--
 clang/test/CodeGen/array-init.c  |  7 +++
 3 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/clang/lib/CodeGen/CGExprConstant.cpp 
b/clang/lib/CodeGen/CGExprConstant.cpp
index 94962091116af..ce57279a6eb65 100644
--- a/clang/lib/CodeGen/CGExprConstant.cpp
+++ b/clang/lib/CodeGen/CGExprConstant.cpp
@@ -393,7 +393,7 @@ bool ConstantAggregateBuilder::split(size_t Index, 
CharUnits Hint) {
 
 static llvm::Constant *
 EmitArrayConstant(CodeGenModule , llvm::ArrayType *DesiredType,
-  llvm::Type *CommonElementType, unsigned ArrayBound,
+  llvm::Type *CommonElementType, uint64_t ArrayBound,
   SmallVectorImpl ,
   llvm::Constant *Filler);
 
@@ -949,11 +949,11 @@ tryEmitGlobalCompoundLiteral(ConstantEmitter ,
 
 static llvm::Constant *
 EmitArrayConstant(CodeGenModule , llvm::ArrayType *DesiredType,
-  llvm::Type *CommonElementType, unsigned ArrayBound,
+  llvm::Type *CommonElementType, uint64_t ArrayBound,
   SmallVectorImpl ,
   llvm::Constant *Filler) {
   // Figure out how long the initial prefix of non-zero elements is.
-  unsigned NonzeroLength = ArrayBound;
+  uint64_t NonzeroLength = ArrayBound;
   if (Elements.size() < NonzeroLength && Filler->isNullValue())
 NonzeroLength = Elements.size();
   if (NonzeroLength == Elements.size()) {
@@ -1252,12 +1252,12 @@ class ConstExprEmitter
   llvm::Constant *EmitArrayInitialization(const InitListExpr *ILE, QualType T) 
{
 auto *CAT = CGM.getContext().getAsConstantArrayType(ILE->getType());
 assert(CAT && "can't emit array init for non-constant-bound array");
-unsigned NumInitElements = ILE->getNumInits();
-unsigned NumElements = CAT->getZExtSize();
+const uint64_t NumElements = CAT->getZExtSize();
 
 // Initialising an array requires us to automatically
 // initialise any elements that have not been initialised explicitly
-unsigned NumInitableElts = std::min(NumInitElements, NumElements);
+uint64_t NumInitableElts =
+std::min(ILE->getNumInits(), NumElements);
 
 QualType EltType = CAT->getElementType();
 
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 2177972f3af2c..353e911c5cc33 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -876,7 +876,7 @@ InitListChecker::FillInEmptyInitializations(const 
InitializedEntity ,
 
   InitializedEntity ElementEntity = Entity;
   unsigned NumInits = ILE->getNumInits();
-  unsigned NumElements = NumInits;
+  uint64_t NumElements = NumInits;
   if (const ArrayType *AType = SemaRef.Context.getAsArrayType(ILE->getType())) 
{
 ElementType = AType->getElementType();
 if (const auto *CAType = dyn_cast(AType))
@@ -896,7 +896,7 @@ InitListChecker::FillInEmptyInitializations(const 
InitializedEntity ,
 ElementType = ILE->getType();
 
   bool SkipEmptyInitChecks = false;
-  for (unsigned Init = 0; Init != NumElements; ++Init) {
+  for (uint64_t Init = 0; Init != NumElements; ++Init) {
 if (hadError)
   return;
 
diff --git a/clang/test/CodeGen/array-init.c b/clang/test/CodeGen/array-init.c
index 62e87edc29741..9075df68c7358 100644
--- a/clang/test/CodeGen/array-init.c
+++ b/clang/test/CodeGen/array-init.c
@@ -13,3 +13,10 @@ void testConstArrayInits(void)
   const int a2[5] = {0,0,0};
   const int a3[5] = {0};
 }
+
+/// https://github.com/llvm/llvm-project/issues/57353
+// CHECK: @big_char ={{.*}} global <{ i8, [4294967295 x i8] }> <{ i8 1, 
[4294967295 x i8] zeroinitializer }>
+char big_char[4294967296] = {1};
+
+// CHECK: @big_int ={{.*}} global <{ i32, [2147483647 x i32] }> <{ i32 1, 
[2147483647 x i32] zeroinitializer }>
+int big_int[0x2 >> 2] = {1};

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


[clang] 9a7f54b - [clang-fuzzer-dictionary] Skip EmptySpellingName after #89358

2024-05-16 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2024-05-16T11:53:15-07:00
New Revision: 9a7f54ba4878c4e66c99430b52d8c014ab7b2a03

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

LOG: [clang-fuzzer-dictionary] Skip EmptySpellingName after #89358

The dictionary entry `=""` is invalid.

Added: 


Modified: 
clang/tools/clang-fuzzer/dictionary/dictionary.c

Removed: 




diff  --git a/clang/tools/clang-fuzzer/dictionary/dictionary.c 
b/clang/tools/clang-fuzzer/dictionary/dictionary.c
index 90490477f70c8..de1defb236acc 100644
--- a/clang/tools/clang-fuzzer/dictionary/dictionary.c
+++ b/clang/tools/clang-fuzzer/dictionary/dictionary.c
@@ -21,6 +21,8 @@
 
 static void emit(const char *Name, const char *Spelling) {
   static char Hex[] = "0123456789abcdef";
+  // Skip EmptySpellingName for IsDeducible.
+  if (!Name[0]) return;
 
   printf("%s=\"", Name);
   unsigned char C;



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


[clang] [llvm] [MC] Remove UseAssemblerInfoForParsing (PR #91082)

2024-05-15 Thread Fangrui Song via cfe-commits

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


[clang] [llvm] [MC] Remove UseAssemblerInfoForParsing (PR #91082)

2024-05-15 Thread Fangrui Song via cfe-commits

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


[clang] [llvm] [MC] Remove UseAssemblerInfoForParsing (PR #91082)

2024-05-15 Thread Fangrui Song via cfe-commits

https://github.com/MaskRay updated 
https://github.com/llvm/llvm-project/pull/91082

>From 7e36c4d9f736b9b2eff29e565d22e01c29744c1e Mon Sep 17 00:00:00 2001
From: Fangrui Song 
Date: Sat, 4 May 2024 13:10:21 -0700
Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?=
 =?UTF-8?q?l=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.5-bogner
---
 clang/tools/driver/cc1as_main.cpp|  3 ---
 llvm/include/llvm/MC/MCStreamer.h|  7 ++-
 .../CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp   |  3 ---
 llvm/lib/MC/MCObjectStreamer.cpp |  9 +
 llvm/lib/MC/MCStreamer.cpp   |  2 +-
 llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp  |  7 ++-
 llvm/lib/Target/SPIRV/SPIRVAsmPrinter.cpp|  3 ---
 .../AsmParser/assembler-expressions-inlineasm.ll | 16 ++--
 llvm/tools/llvm-mc/llvm-mc.cpp   |  3 ---
 llvm/tools/llvm-ml/llvm-ml.cpp   |  3 ---
 10 files changed, 16 insertions(+), 40 deletions(-)

diff --git a/clang/tools/driver/cc1as_main.cpp 
b/clang/tools/driver/cc1as_main.cpp
index 86afe22fac24c..4eb753a7297a9 100644
--- a/clang/tools/driver/cc1as_main.cpp
+++ b/clang/tools/driver/cc1as_main.cpp
@@ -576,9 +576,6 @@ static bool ExecuteAssemblerImpl(AssemblerInvocation ,
 Str.get()->emitZeros(1);
   }
 
-  // Assembly to object compilation should leverage assembly info.
-  Str->setUseAssemblerInfoForParsing(true);
-
   bool Failed = false;
 
   std::unique_ptr Parser(
diff --git a/llvm/include/llvm/MC/MCStreamer.h 
b/llvm/include/llvm/MC/MCStreamer.h
index 69867620e1bf8..50986e6bde886 100644
--- a/llvm/include/llvm/MC/MCStreamer.h
+++ b/llvm/include/llvm/MC/MCStreamer.h
@@ -245,8 +245,6 @@ class MCStreamer {
   /// requires.
   unsigned NextWinCFIID = 0;
 
-  bool UseAssemblerInfoForParsing;
-
   /// Is the assembler allowed to insert padding automatically?  For
   /// correctness reasons, we sometimes need to ensure instructions aren't
   /// separated in unexpected ways.  At the moment, this feature is only
@@ -296,11 +294,10 @@ class MCStreamer {
 
   MCContext () const { return Context; }
 
+  // MCObjectStreamer has an MCAssembler and allows more expression folding at
+  // parse time.
   virtual MCAssembler *getAssemblerPtr() { return nullptr; }
 
-  void setUseAssemblerInfoForParsing(bool v) { UseAssemblerInfoForParsing = v; 
}
-  bool getUseAssemblerInfoForParsing() { return UseAssemblerInfoForParsing; }
-
   MCTargetStreamer *getTargetStreamer() {
 return TargetStreamer.get();
   }
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp 
b/llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp
index d0ef3e5a19391..08e3c208ba4d3 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp
@@ -102,9 +102,6 @@ void AsmPrinter::emitInlineAsm(StringRef Str, const 
MCSubtargetInfo ,
   std::unique_ptr Parser(
   createMCAsmParser(SrcMgr, OutContext, *OutStreamer, *MAI, BufNum));
 
-  // Do not use assembler-level information for parsing inline assembly.
-  OutStreamer->setUseAssemblerInfoForParsing(false);
-
   // We create a new MCInstrInfo here since we might be at the module level
   // and not have a MachineFunction to initialize the TargetInstrInfo from and
   // we only need MCInstrInfo for asm parsing. We create one unconditionally
diff --git a/llvm/lib/MC/MCObjectStreamer.cpp b/llvm/lib/MC/MCObjectStreamer.cpp
index d2da5d0d3f90f..a9003a164b306 100644
--- a/llvm/lib/MC/MCObjectStreamer.cpp
+++ b/llvm/lib/MC/MCObjectStreamer.cpp
@@ -40,14 +40,7 @@ MCObjectStreamer::MCObjectStreamer(MCContext ,
 
 MCObjectStreamer::~MCObjectStreamer() = default;
 
-// AssemblerPtr is used for evaluation of expressions and causes
-// difference between asm and object outputs. Return nullptr to in
-// inline asm mode to limit divergence to assembly inputs.
-MCAssembler *MCObjectStreamer::getAssemblerPtr() {
-  if (getUseAssemblerInfoForParsing())
-return Assembler.get();
-  return nullptr;
-}
+MCAssembler *MCObjectStreamer::getAssemblerPtr() { return Assembler.get(); }
 
 void MCObjectStreamer::addPendingLabel(MCSymbol* S) {
   MCSection *CurSection = getCurrentSectionOnly();
diff --git a/llvm/lib/MC/MCStreamer.cpp b/llvm/lib/MC/MCStreamer.cpp
index 176d55aa890be..199d865ea3496 100644
--- a/llvm/lib/MC/MCStreamer.cpp
+++ b/llvm/lib/MC/MCStreamer.cpp
@@ -93,7 +93,7 @@ void MCTargetStreamer::emitAssignment(MCSymbol *Symbol, const 
MCExpr *Value) {}
 
 MCStreamer::MCStreamer(MCContext )
 : Context(Ctx), CurrentWinFrameInfo(nullptr),
-  CurrentProcWinFrameInfoStartIndex(0), UseAssemblerInfoForParsing(false) {
+  CurrentProcWinFrameInfoStartIndex(0) {
   SectionStack.push_back(std::pair());
 }
 
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp 
b/llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp
index 

[clang] [llvm] [MC] Remove UseAssemblerInfoForParsing (PR #91082)

2024-05-14 Thread Fangrui Song via cfe-commits

MaskRay wrote:

> > Thanks for the additional context. My main concern is that we're undoing 
> > the consensus of [reviews.llvm.org/D45164](https://reviews.llvm.org/D45164) 
> > which if I've understood the comments properly was "There is a reasonable 
> > expectation that compiled (not assembled) code should be identical, or at 
> > least as close to the assembly output.
> > I'm not hugely concerned about that personally as I don't think there are 
> > any written guarantees and I come from a background of a toolchain that 
> > didn't come close to that (assembler output was disassembled from object 
> > file), however there were some strong opinions on the original change.
> > Do we have any strong opinions from the other reviewers?
> > If there is a RFC I suggest that it would be entitled something like "[RFC] 
> > Clang assembly/object equivalence for files with inline assembly". If it is 
> > worded in such a way that this is needed for the kernel and we want to 
> > check for community input then if there is no response then we can go ahead.
> 
> Thanks for the suggestion. I created 
> [discourse.llvm.org/t/rfc-clang-assembly-object-equivalence-for-files-with-inline-assembly/78841](https://discourse.llvm.org/t/rfc-clang-assembly-object-equivalence-for-files-with-inline-assembly/78841)

So far there has only been one reply from @efriedma-quic . Shall we go ahead?

> I care less about error messages than outright miscompiles.

We don't have miscompiles, just the difference in whether a `.if` construct can 
be assembled.

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


[clang-tools-extra] 4cfe347 - [clangd] Fix -Wunused-but-set-variable after #82396

2024-05-14 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2024-05-14T12:58:49-07:00
New Revision: 4cfe347c107485aab6bd003f99ab06aac242b0fd

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

LOG: [clangd] Fix -Wunused-but-set-variable after #82396

Added: 


Modified: 
clang-tools-extra/clangd/refactor/Rename.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/refactor/Rename.cpp 
b/clang-tools-extra/clangd/refactor/Rename.cpp
index 75b30e66d6376..c0fc4453a3fcc 100644
--- a/clang-tools-extra/clangd/refactor/Rename.cpp
+++ b/clang-tools-extra/clangd/refactor/Rename.cpp
@@ -1090,11 +1090,10 @@ llvm::Expected rename(const RenameInputs 
) {
 return MainFileRenameEdit.takeError();
 
   llvm::DenseSet RenamedRanges;
-  if (const auto *MD = dyn_cast()) {
+  if (!isa(RenameDecl)) {
 // TODO: Insert the ranges from the ObjCMethodDecl/ObjCMessageExpr selector
 // pieces which are being renamed. This will require us to make changes to
 // locateDeclAt to preserve this AST node.
-  } else {
 RenamedRanges.insert(CurrentIdentifier);
   }
 



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


[clang] [Clang][Sema] Earlier type checking for builtin unary operators (PR #90500)

2024-05-14 Thread Fangrui Song via cfe-commits

MaskRay wrote:

> This seems to [break 
> something](https://lab.llvm.org/buildbot/#/builders/121/builds/41631) in 
> LLVM... investigating

I've also noticed a stage-2-build issue. 

```
  llvm::any_of(LHS->users(),
[&](auto *U) {
  return U != I &&
 !(U->hasOneUser() && *U->users().begin() == I);
}) ||
```

```
llvm/lib/Transforms/Scalar/NaryReassociate.cpp:610:32: error: comparison of 
distinct pointer types ('auto *' and 'Instruction *')
  610 |   return U != I &&
  |  ~ ^  ~
```

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


[clang] [CIR] Build out AST consumer patterns to reach the entry point into CIRGen (PR #91007)

2024-05-14 Thread Fangrui Song via cfe-commits

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


[clang] [CIR] Build out AST consumer patterns to reach the entry point into CIRGen (PR #91007)

2024-05-14 Thread Fangrui Song via cfe-commits

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


[clang] [CIR] Build out AST consumer patterns to reach the entry point into CIRGen (PR #91007)

2024-05-14 Thread Fangrui Song via cfe-commits


@@ -2900,7 +2900,7 @@ defm clangir : BoolFOption<"clangir",
   PosFlag,
   NegFlag LLVM 
pipeline to compile">,
   BothFlags<[], [ClangOption, CC1Option], "">>;
-def emit_cir : Flag<["-"], "emit-cir">, Visibility<[CC1Option]>,
+def emit_cir : Flag<["-"], "emit-cir">, Visibility<[ClangOption, CC1Option]>,

MaskRay wrote:

> Notably, -emit-llvm-bc does the wrong thing in all cases. clang -Xclang 
> -emit-llvm-bc hello.c does the wrong thing and emits an executable. clang 
> -Xclang -emit-llvm -S hello.c also does the wrong thing and emits a file 
> named hello.s that is actually llvm bitcode.

The description of #91140 might be useful.

You need `-S` or `-c` to disable linking. Then `-c -Xclang -emit-cir` can be 
used to override the assumed action passed by clangDriver to cc1.

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


[clang] [clang-tools-extra] [flang] [llvm] [mlir] [polly] [test]: fix filecheck annotation typos (PR #91854)

2024-05-13 Thread Fangrui Song via cfe-commits

MaskRay wrote:

> Ideally FileCheck should prefix commands with some tag to distinguish 
> comments from filecheck annotations, like
> `--command-tag=@` and use as `@CHECK: xxx`, `@MYCHECK-NEXT: yyy`, etc. Making 
> typo\error in both prefix and command tag will be harder, i guess. That way 
> tool can immediately fail if can see command tag with unknown 
> prefix\directive, without silently guessing that this is comment and skipping.

I remember I have seen quite a few FileCheck and lit improvement proposals. 
While some have been implemented, others are still under consideration.
You might be interested in some threads that you can find by searching for 
`FileCheck @jh7370` and `FileCheck @pogo59` on https://discourse.llvm.org/ .


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


[clang] [clang-tools-extra] [flang] [llvm] [mlir] [polly] [test]: fix filecheck annotation typos (PR #91854)

2024-05-13 Thread Fangrui Song via cfe-commits

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

Some CHECK prefixes are auto-generated by llvm/utils/update_*_test_checks.py.
Let's say my build directory is `/tmp/Rel` while my source is at `~/llvm`, use
```
PATH=/tmp/Rel/bin:$PATH ~/llvm/llvm/utils/update_any_test_checks.py path/to/test
```

to re-generate tests.
(It seems that some stale comments might not be removed. I haven't read these 
scripts for a long time.)

Perhaps revert changes to files that cause failures and possibly keep just 
`llvm/` in this PR.

Feel free to raise a post on https://discourse.llvm.org/ and possibly refer to 
https://discourse.llvm.org/t/rfc-improving-filecheck/54962 (a previous post 
about these typos in tests).
Thank you so much for cleaning up these tests!


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


[clang] [clang-tools-extra] [flang] [llvm] [mlir] [polly] [test]: fix filecheck annotation typos (PR #91854)

2024-05-13 Thread Fangrui Song via cfe-commits

MaskRay wrote:

The previous failures reported by `buildkite/github-pull-requests Pending` were 
genuine. I have fixed them separately.

When doing large scale cleanups, it might make sense to partition them, e.g. 
llvm/ (clang/ & clang-tools-extra/) mlir/ in different PRs. The number of files 
will be smaller and github web UI will not make the page too slow to load. The 
active contributors in these components are largely disjoint and they may not 
be confident to approve the whole PR.

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


[clang] [llvm] [RISCV] Teach .option arch to support experimental extensions. (PR #89727)

2024-05-13 Thread Fangrui Song via cfe-commits

MaskRay wrote:

The clang/test/Driver codegen tests might have been removed. Note: 
clang/test/Driver is to test how clangDriver passes options to cc1, not for 
sema/codegen/etc.

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


[clang] a6d7828 - [test] Use conventional -emit-llvm-only

2024-05-13 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2024-05-13T12:53:16-07:00
New Revision: a6d7828f4c50c1ec7b0b5f61fe59d7a768175dcc

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

LOG: [test] Use conventional -emit-llvm-only

This avoids 'Permission denied' when PWD is read-only.
While here, change the triple from a Linux one to a generic ELF one.

Added: 


Modified: 
clang/test/Sema/aarch64-sme2-intrinsics/acle_sme2_fmlas16.c
clang/test/Sema/aarch64-sme2-intrinsics/acle_sme2_mopa_nonwide.c

Removed: 




diff  --git a/clang/test/Sema/aarch64-sme2-intrinsics/acle_sme2_fmlas16.c 
b/clang/test/Sema/aarch64-sme2-intrinsics/acle_sme2_fmlas16.c
index b1582569971d4..66aba36ff68ad 100644
--- a/clang/test/Sema/aarch64-sme2-intrinsics/acle_sme2_fmlas16.c
+++ b/clang/test/Sema/aarch64-sme2-intrinsics/acle_sme2_fmlas16.c
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme -verify 
-emit-llvm %s
+// RUN: %clang_cc1 -triple aarch64 -target-feature +sme -verify 
-emit-llvm-only %s
 
 // REQUIRES: aarch64-registered-target
 
@@ -87,4 +87,4 @@ void test_imm(uint32_t slice, svfloat16_t zm, svfloat16x2_t 
zn2,svfloat16x4_t zn
   svmls_lane_za16_bf16_vg1x2(slice, bzn2, bzm, -1);
   // expected-error@+1 {{argument value 18446744073709551615 is outside the 
valid range [0, 7]}}
   svmls_lane_za16_bf16_vg1x4(slice, bzn4, bzm, -1);
-}
\ No newline at end of file
+}

diff  --git a/clang/test/Sema/aarch64-sme2-intrinsics/acle_sme2_mopa_nonwide.c 
b/clang/test/Sema/aarch64-sme2-intrinsics/acle_sme2_mopa_nonwide.c
index 201ad4b8ff7f0..1331bf2050b71 100644
--- a/clang/test/Sema/aarch64-sme2-intrinsics/acle_sme2_mopa_nonwide.c
+++ b/clang/test/Sema/aarch64-sme2-intrinsics/acle_sme2_mopa_nonwide.c
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme -verify 
-emit-llvm %s
+// RUN: %clang_cc1 -triple aarch64 -target-feature +sme -verify 
-emit-llvm-only %s
 
 // REQUIRES: aarch64-registered-target
 



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


[clang] [clang-tools-extra] [flang] [lld] [llvm] [mlir] [polly] [test]: fix filecheck annotation typos (PR #91854)

2024-05-12 Thread Fangrui Song via cfe-commits


@@ -45,10 +45,10 @@
 # RUN: ld.lld -Ttext 0x201000 %t.o -o %t4
 # RUN: llvm-readelf -S -l %t4 | FileCheck %s --check-prefix=USER3
 # USER3: .text   PROGBITS 00201000 001000 01
-# USER3-NEX: .rodata PROGBITS 00202000 002000 08
-# USER3-NEX: .aw PROGBITS 00203000 003000 08
-# USER3-NEX: .data   PROGBITS 00203008 003008 08
-# USER3-NEX: .bssNOBITS   00203010 003010 08
+# USER3-NEXT: .rodata PROGBITS 00202000 002000 08

MaskRay wrote:

The test would fail.

I fixed this by adding `-z separate-loadable-segments`.

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


[clang] [clang] Use StringRef::operator== instead of StringRef::equals (NFC) (PR #91844)

2024-05-11 Thread Fangrui Song via cfe-commits

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


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


[clang] df88d61 - [Driver] Remove unused getInstalledDir

2024-05-10 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2024-05-10T19:15:17-07:00
New Revision: df88d610ab10c1e3f22d7f5daf3794158972c584

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

LOG: [Driver] Remove unused getInstalledDir

The uses have been removed by commit 2b5cd8be3af43e5aa5b76b6aeb1edd3141b803ca

Added: 


Modified: 
clang/include/clang/Driver/Driver.h

Removed: 




diff  --git a/clang/include/clang/Driver/Driver.h 
b/clang/include/clang/Driver/Driver.h
index 2ffc52bcb7ad3..cc1538372d5f8 100644
--- a/clang/include/clang/Driver/Driver.h
+++ b/clang/include/clang/Driver/Driver.h
@@ -424,11 +424,6 @@ class Driver {
 return ClangExecutable.c_str();
   }
 
-  /// Get the path to where the clang executable was installed.
-  const char *getInstalledDir() const {
-return Dir.c_str();
-  }
-
   bool isSaveTempsEnabled() const { return SaveTemps != SaveTempsNone; }
   bool isSaveTempsObj() const { return SaveTemps == SaveTempsObj; }
 



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


[clang] [UEFI] X86_64 UEFI Clang Driver (PR #76838)

2024-05-10 Thread Fangrui Song via cfe-commits


@@ -819,6 +819,43 @@ class LLVM_LIBRARY_VISIBILITY X86_64TargetInfo : public 
X86TargetInfo {
   }
 };
 
+// x86-64 UEFI target
+class LLVM_LIBRARY_VISIBILITY UEFIX86_64TargetInfo
+: public UEFITargetInfo {
+public:
+  UEFIX86_64TargetInfo(const llvm::Triple , const TargetOptions )
+  : UEFITargetInfo(Triple, Opts) {

MaskRay wrote:

Still waiting for a calling convention test

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


[clang] [UEFI] X86_64 UEFI Clang Driver (PR #76838)

2024-05-10 Thread Fangrui Song via cfe-commits

MaskRay wrote:

Some older toolchains were probably contributed with a lot of 
`CmdArgs.push_back` uncovered by tests. They are not good examples to follow. 
For new toolchains, we do want all constructed `CmdArgs.push_back` to be 
covered. This allows refactoring by someone who is unfamiliar with your usage 
pattern.

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


[clang] [Driver] Clean up fp-contract handling in clang driver (PR #91271)

2024-05-10 Thread Fangrui Song via cfe-commits


@@ -238,3 +238,17 @@
 // RUN: %clang -### -fno-unsafe-math-optimizations -funsafe-math-optimizations 
\
 // RUN: -ffp-contract=off -c %s 2>&1 | FileCheck --check-prefix=CHECK-FPC-OFF 
%s
 
+// RUN: %clang -### -funsafe-math-optimizations -ffp-contract=off -c %s 2>&1 \

MaskRay wrote:

Some folks prefer `git merge origin/main` while some just use `git rebase 
origin/main` and force push.

I am fine with either style, but someone really dislike force push (perhaps not 
for such a trivial change).

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


[clang] [test] Move RISCV tests to clang/test/CodeGen/RISCV/ (PR #91783)

2024-05-10 Thread Fangrui Song via cfe-commits

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


[clang] [test] Move RISCV tests to clang/test/CodeGen/RISCV/ (PR #91783)

2024-05-10 Thread Fangrui Song via cfe-commits

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


[clang] [test] Move RISCV tests to clang/test/CodeGen/RISCV/ (PR #91783)

2024-05-10 Thread Fangrui Song via cfe-commits

https://github.com/MaskRay created 
https://github.com/llvm/llvm-project/pull/91783

None

>From 79c0d400fee943f794ed38965cec0c8b0d2dffef Mon Sep 17 00:00:00 2001
From: Fangrui Song 
Date: Fri, 10 May 2024 11:00:14 -0700
Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?=
 =?UTF-8?q?l=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.5-bogner
---
 .../attr-rvv-vector-bits-bitcast.c}   | 0
 .../attr-rvv-vector-bits-call.c}  | 0
 .../attr-rvv-vector-bits-cast.c}  | 0
 .../attr-rvv-vector-bits-codegen.c}   | 0
 .../attr-rvv-vector-bits-globals.c}   | 0
 .../attr-rvv-vector-bits-types.c} | 0
 clang/test/CodeGen/{ => RISCV}/riscv32-ilp32d-abi.cpp | 0
 .../{riscv-rvv-vls-arith-ops.c => RISCV/rvv-vls-arith-ops.c}  | 0
 .../{riscv-rvv-vls-bitwise-ops.c => RISCV/rvv-vls-bitwise-ops.c}  | 0
 .../{riscv-rvv-vls-compare-ops.c => RISCV/rvv-vls-compare-ops.c}  | 0
 .../{riscv-rvv-vls-shift-ops.c => RISCV/rvv-vls-shift-ops.c}  | 0
 .../rvv-vls-subscript-ops.c}  | 0
 .../vector-bits-vscale-range.c}   | 0
 13 files changed, 0 insertions(+), 0 deletions(-)
 rename clang/test/CodeGen/{attr-riscv-rvv-vector-bits-bitcast.c => 
RISCV/attr-rvv-vector-bits-bitcast.c} (100%)
 rename clang/test/CodeGen/{attr-riscv-rvv-vector-bits-call.c => 
RISCV/attr-rvv-vector-bits-call.c} (100%)
 rename clang/test/CodeGen/{attr-riscv-rvv-vector-bits-cast.c => 
RISCV/attr-rvv-vector-bits-cast.c} (100%)
 rename clang/test/CodeGen/{attr-riscv-rvv-vector-bits-codegen.c => 
RISCV/attr-rvv-vector-bits-codegen.c} (100%)
 rename clang/test/CodeGen/{attr-riscv-rvv-vector-bits-globals.c => 
RISCV/attr-rvv-vector-bits-globals.c} (100%)
 rename clang/test/CodeGen/{attr-riscv-rvv-vector-bits-types.c => 
RISCV/attr-rvv-vector-bits-types.c} (100%)
 rename clang/test/CodeGen/{ => RISCV}/riscv32-ilp32d-abi.cpp (100%)
 rename clang/test/CodeGen/{riscv-rvv-vls-arith-ops.c => 
RISCV/rvv-vls-arith-ops.c} (100%)
 rename clang/test/CodeGen/{riscv-rvv-vls-bitwise-ops.c => 
RISCV/rvv-vls-bitwise-ops.c} (100%)
 rename clang/test/CodeGen/{riscv-rvv-vls-compare-ops.c => 
RISCV/rvv-vls-compare-ops.c} (100%)
 rename clang/test/CodeGen/{riscv-rvv-vls-shift-ops.c => 
RISCV/rvv-vls-shift-ops.c} (100%)
 rename clang/test/CodeGen/{riscv-rvv-vls-subscript-ops.c => 
RISCV/rvv-vls-subscript-ops.c} (100%)
 rename clang/test/CodeGen/{riscv-vector-bits-vscale-range.c => 
RISCV/vector-bits-vscale-range.c} (100%)

diff --git a/clang/test/CodeGen/attr-riscv-rvv-vector-bits-bitcast.c 
b/clang/test/CodeGen/RISCV/attr-rvv-vector-bits-bitcast.c
similarity index 100%
rename from clang/test/CodeGen/attr-riscv-rvv-vector-bits-bitcast.c
rename to clang/test/CodeGen/RISCV/attr-rvv-vector-bits-bitcast.c
diff --git a/clang/test/CodeGen/attr-riscv-rvv-vector-bits-call.c 
b/clang/test/CodeGen/RISCV/attr-rvv-vector-bits-call.c
similarity index 100%
rename from clang/test/CodeGen/attr-riscv-rvv-vector-bits-call.c
rename to clang/test/CodeGen/RISCV/attr-rvv-vector-bits-call.c
diff --git a/clang/test/CodeGen/attr-riscv-rvv-vector-bits-cast.c 
b/clang/test/CodeGen/RISCV/attr-rvv-vector-bits-cast.c
similarity index 100%
rename from clang/test/CodeGen/attr-riscv-rvv-vector-bits-cast.c
rename to clang/test/CodeGen/RISCV/attr-rvv-vector-bits-cast.c
diff --git a/clang/test/CodeGen/attr-riscv-rvv-vector-bits-codegen.c 
b/clang/test/CodeGen/RISCV/attr-rvv-vector-bits-codegen.c
similarity index 100%
rename from clang/test/CodeGen/attr-riscv-rvv-vector-bits-codegen.c
rename to clang/test/CodeGen/RISCV/attr-rvv-vector-bits-codegen.c
diff --git a/clang/test/CodeGen/attr-riscv-rvv-vector-bits-globals.c 
b/clang/test/CodeGen/RISCV/attr-rvv-vector-bits-globals.c
similarity index 100%
rename from clang/test/CodeGen/attr-riscv-rvv-vector-bits-globals.c
rename to clang/test/CodeGen/RISCV/attr-rvv-vector-bits-globals.c
diff --git a/clang/test/CodeGen/attr-riscv-rvv-vector-bits-types.c 
b/clang/test/CodeGen/RISCV/attr-rvv-vector-bits-types.c
similarity index 100%
rename from clang/test/CodeGen/attr-riscv-rvv-vector-bits-types.c
rename to clang/test/CodeGen/RISCV/attr-rvv-vector-bits-types.c
diff --git a/clang/test/CodeGen/riscv32-ilp32d-abi.cpp 
b/clang/test/CodeGen/RISCV/riscv32-ilp32d-abi.cpp
similarity index 100%
rename from clang/test/CodeGen/riscv32-ilp32d-abi.cpp
rename to clang/test/CodeGen/RISCV/riscv32-ilp32d-abi.cpp
diff --git a/clang/test/CodeGen/riscv-rvv-vls-arith-ops.c 
b/clang/test/CodeGen/RISCV/rvv-vls-arith-ops.c
similarity index 100%
rename from clang/test/CodeGen/riscv-rvv-vls-arith-ops.c
rename to clang/test/CodeGen/RISCV/rvv-vls-arith-ops.c
diff --git a/clang/test/CodeGen/riscv-rvv-vls-bitwise-ops.c 

[clang] [lld] [llvm] [RISCV] Support .note.gnu.property for enable Zicfiss and Zicfilp extension (PR #77414)

2024-05-10 Thread Fangrui Song via cfe-commits


@@ -0,0 +1,29 @@
+// When -march with zicfiss0p4 or zicfilp0p4 add GNU property to file object

MaskRay wrote:

This directory is for driver tests. Codegen tests should use `%clang_cc1` and 
be moved elsewhere (e.g. test/CodeGen)

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


[clang] [Driver] Clean up fp-contract handling in clang driver (PR #91271)

2024-05-10 Thread Fangrui Song via cfe-commits


@@ -238,3 +238,17 @@
 // RUN: %clang -### -fno-unsafe-math-optimizations -funsafe-math-optimizations 
\
 // RUN: -ffp-contract=off -c %s 2>&1 | FileCheck --check-prefix=CHECK-FPC-OFF 
%s
 
+// RUN: %clang -### -funsafe-math-optimizations -ffp-contract=off -c %s 2>&1 \

MaskRay wrote:

I just went ahead and added a bunch of `-Werror` to previous lines in 
514d80b4feea3c788c1b0821959e96f63c8b8f3d

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


[clang] [lld] [llvm] [RISCV] Support .note.gnu.property for enable Zicfiss and Zicfilp extension (PR #77414)

2024-05-10 Thread Fangrui Song via cfe-commits

MaskRay wrote:

Unless `lld/test/ELF` tests will get a failure, the `lld/` part should ideally 
be dropped from this PR.
lld folks (like I) might not notice this patch if there is just a `[RISCV]` tag.

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


[clang] 514d80b - [Driver, test] Add -Werror to -ffp-contract/-ffp-model tests

2024-05-10 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2024-05-10T10:49:52-07:00
New Revision: 514d80b4feea3c788c1b0821959e96f63c8b8f3d

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

LOG: [Driver,test] Add -Werror to -ffp-contract/-ffp-model tests

Test that these combinations do not lead to a warning.

-funsafe-math-optimizations -ffp-contract=off
and
-ffast-math -ffp-contract=off

may issue a warning after #91271.

Added: 


Modified: 
clang/test/Driver/fp-contract.c
clang/test/Driver/fp-model.c

Removed: 




diff  --git a/clang/test/Driver/fp-contract.c b/clang/test/Driver/fp-contract.c
index 660f67fad3ccb..e2691dc211cc3 100644
--- a/clang/test/Driver/fp-contract.c
+++ b/clang/test/Driver/fp-contract.c
@@ -10,112 +10,112 @@
 // RUN: %clang -### -fno-fast-math -c %s 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-FPC-ON %s
 
-// RUN: %clang -### -ffast-math -ffp-contract=on -c %s 2>&1 \
+// RUN: %clang -### -Werror -ffast-math -ffp-contract=on -c %s 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-FPC-ON %s
 // CHECK-FPC-ON:   "-ffp-contract=on"
 
-// RUN: %clang -### -ffast-math -ffp-contract=off -c %s 2>&1 \
+// RUN: %clang -### -Werror -ffast-math -ffp-contract=off -c %s 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-FPC-OFF %s
 // CHECK-FPC-OFF:  "-ffp-contract=off"
 
-// RUN: %clang -### -ffast-math -ffp-contract=fast -c %s 2>&1 \
+// RUN: %clang -### -Werror -ffast-math -ffp-contract=fast -c %s 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-FPC-FAST %s
 
-// RUN: %clang -### -ffast-math -ffp-contract=fast-honor-pragmas -c %s 2>&1 \
+// RUN: %clang -### -Werror -ffast-math -ffp-contract=fast-honor-pragmas -c %s 
2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-FPC-FAST-HONOR %s
 // CHECK-FPC-FAST-HONOR: "-ffp-contract=fast-honor-pragmas"
 
-// RUN: %clang -### -ffp-contract=fast -ffast-math -c %s 2>&1 \
+// RUN: %clang -### -Werror -ffp-contract=fast -ffast-math -c %s 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-FPC-FAST %s
-// RUN: %clang -### -ffp-contract=on -ffast-math -c %s 2>&1 \
+// RUN: %clang -### -Werror -ffp-contract=on -ffast-math -c %s 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-FPC-FAST %s
-// RUN: %clang -### -ffp-contract=off -ffast-math -c %s 2>&1 \
+// RUN: %clang -### -Werror -ffp-contract=off -ffast-math -c %s 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-FPC-FAST %s
 
-// RUN: %clang -### -ffp-contract=fast -fno-fast-math -c %s 2>&1 \
+// RUN: %clang -### -Werror -ffp-contract=fast -fno-fast-math -c %s 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-FPC-FAST %s
-// RUN: %clang -### -ffp-contract=on -fno-fast-math -c %s 2>&1 \
+// RUN: %clang -### -Werror -ffp-contract=on -fno-fast-math -c %s 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-FPC-ON %s
-// RUN: %clang -### -ffp-contract=off -fno-fast-math -c %s 2>&1 \
+// RUN: %clang -### -Werror -ffp-contract=off -fno-fast-math -c %s 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-FPC-OFF %s
 
 
-// RUN: %clang -### -ffast-math -ffp-contract=fast -ffp-contract=on -c %s 2>&1 
\
+// RUN: %clang -### -Werror -ffast-math -ffp-contract=fast -ffp-contract=on -c 
%s 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-FPC-ON %s
 
-// RUN: %clang -### -ffast-math -ffp-contract=on -ffp-contract=off -c %s 2>&1 \
+// RUN: %clang -### -Werror -ffast-math -ffp-contract=on -ffp-contract=off -c 
%s 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-FPC-OFF %s
 
-// RUN: %clang -### -ffast-math -ffp-contract=on -ffp-contract=fast -c %s 2>&1 
\
+// RUN: %clang -### -Werror -ffast-math -ffp-contract=on -ffp-contract=fast -c 
%s 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-FPC-FAST %s
 
-// RUN: %clang -### -ffast-math -ffp-contract=off -ffp-contract=on -c %s 2>&1 \
+// RUN: %clang -### -Werror -ffast-math -ffp-contract=off -ffp-contract=on -c 
%s 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-FPC-ON %s
 
-// RUN: %clang -### -ffast-math -ffp-contract=off -ffp-contract=fast \
+// RUN: %clang -### -Werror -ffast-math -ffp-contract=off -ffp-contract=fast \
 // RUN: -c %s 2>&1 | FileCheck --check-prefix=CHECK-FPC-FAST %s
 
-// RUN: %clang -### -ffast-math -ffp-contract=on -fno-fast-math -c %s 2>&1 \
+// RUN: %clang -### -Werror -ffast-math -ffp-contract=on -fno-fast-math -c %s 
2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-FPC-ON %s
 
-// RUN: %clang -### -ffast-math -ffp-contract=off -fno-fast-math -c %s 2>&1 \
+// RUN: %clang -### -Werror -ffast-math -ffp-contract=off -fno-fast-math -c %s 
2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-FPC-OFF %s
 
-// RUN: %clang -### -ffast-math -ffp-contract=fast -fno-fast-math -c %s 2>&1 \
+// RUN: %clang -### -Werror -ffast-math -ffp-contract=fast -fno-fast-math -c 
%s 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-FPC-FAST %s
 

[clang] [Driver] Clean up fp-contract handling in clang driver (PR #91271)

2024-05-10 Thread Fangrui Song via cfe-commits


@@ -2751,6 +2751,7 @@ static void RenderFloatingPointOptions(const ToolChain 
, const Driver ,
   // If one wasn't given by the user, don't pass it here.
   StringRef FPContract;
   StringRef LastSeenFfpContractOption;
+  StringRef LastFpContractOverrideOption;

MaskRay wrote:

`Overridden` seems more appropriate, but the variable name will become too long.
I wonder whether `Last` can be removed. It's clear from the type that this can 
only hold one option name.

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


[clang] [Driver] Clean up fp-contract handling in clang driver (PR #91271)

2024-05-10 Thread Fangrui Song via cfe-commits


@@ -238,3 +238,17 @@
 // RUN: %clang -### -fno-unsafe-math-optimizations -funsafe-math-optimizations 
\
 // RUN: -ffp-contract=off -c %s 2>&1 | FileCheck --check-prefix=CHECK-FPC-OFF 
%s
 
+// RUN: %clang -### -funsafe-math-optimizations -ffp-contract=off -c %s 2>&1 \

MaskRay wrote:

L161 has similar `-funsafe-math-optimizations -ffp-contract=off` checks. The 
test can be folded there.

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


[clang] [llvm] [MC,llvm-readobj,yaml2obj] Support CREL relocation format (PR #91280)

2024-05-10 Thread Fangrui Song via cfe-commits

https://github.com/MaskRay updated 
https://github.com/llvm/llvm-project/pull/91280

>From a0cfafb82db825512b0ca44778fa9d4bb435563d Mon Sep 17 00:00:00 2001
From: Fangrui Song 
Date: Mon, 6 May 2024 15:37:50 -0700
Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?=
 =?UTF-8?q?l=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.5-bogner
---
 clang/include/clang/Basic/CodeGenOptions.def  |   1 +
 .../clang/Basic/DiagnosticDriverKinds.td  |   3 +
 clang/include/clang/Driver/Options.td |   3 +
 clang/lib/CodeGen/BackendUtil.cpp |   1 +
 clang/lib/Driver/ToolChains/Clang.cpp |  18 ++
 clang/lib/Driver/ToolChains/CommonArgs.cpp|  21 ++
 clang/test/Driver/crel.c  |  24 +++
 clang/test/Misc/cc1as-crel.s  |   6 +
 clang/tools/driver/cc1as_main.cpp |   6 +
 .../include/llvm/BinaryFormat/DynamicTags.def |   2 +
 llvm/include/llvm/BinaryFormat/ELF.h  |   1 +
 llvm/include/llvm/MC/MCTargetOptions.h|   3 +
 .../llvm/MC/MCTargetOptionsCommandFlags.h |   1 +
 llvm/include/llvm/Object/ELF.h|   5 +
 llvm/include/llvm/Object/ELFObjectFile.h  |  70 ++-
 llvm/include/llvm/Object/ELFTypes.h   |  25 +++
 llvm/lib/MC/ELFObjectWriter.cpp   | 110 ---
 llvm/lib/MC/MCTargetOptionsCommandFlags.cpp   |   6 +
 llvm/lib/Object/ELF.cpp   |  63 ++
 llvm/lib/ObjectYAML/ELFEmitter.cpp|  60 +-
 llvm/lib/ObjectYAML/ELFYAML.cpp   |   2 +
 llvm/test/MC/ELF/crel-32.s|  16 ++
 llvm/test/MC/ELF/crel.s   | 100 ++
 llvm/test/tools/llvm-readobj/ELF/crel.test| 180 ++
 .../tools/llvm-readobj/ELF/dynamic-reloc.test |  31 ++-
 .../llvm-readobj/ELF/relocation-errors.test   |  19 +-
 .../yaml2obj/ELF/dynamic-relocations.yaml |   5 +-
 .../yaml2obj/ELF/reloc-sec-entry-size.yaml|   5 +
 .../tools/yaml2obj/ELF/relocation-crel.yaml   |  63 ++
 .../ELF/relocation-missing-symbol.yaml|   3 +-
 .../tools/yaml2obj/ELF/relocation-type.yaml   |   4 +-
 llvm/tools/llvm-readobj/ELFDumper.cpp |  81 +++-
 32 files changed, 883 insertions(+), 55 deletions(-)
 create mode 100644 clang/test/Driver/crel.c
 create mode 100644 clang/test/Misc/cc1as-crel.s
 create mode 100644 llvm/test/MC/ELF/crel-32.s
 create mode 100644 llvm/test/MC/ELF/crel.s
 create mode 100644 llvm/test/tools/llvm-readobj/ELF/crel.test
 create mode 100644 llvm/test/tools/yaml2obj/ELF/relocation-crel.yaml

diff --git a/clang/include/clang/Basic/CodeGenOptions.def 
b/clang/include/clang/Basic/CodeGenOptions.def
index 340b08dd7e2a3..3229f77eef1fc 100644
--- a/clang/include/clang/Basic/CodeGenOptions.def
+++ b/clang/include/clang/Basic/CodeGenOptions.def
@@ -36,6 +36,7 @@ VALUE_CODEGENOPT(Name, Bits, Default)
 #endif
 
 CODEGENOPT(DisableIntegratedAS, 1, 0) ///< -no-integrated-as
+CODEGENOPT(Crel, 1, 0) ///< -Wa,--crel
 CODEGENOPT(RelaxELFRelocations, 1, 1) ///< -Wa,-mrelax-relocations={yes,no}
 CODEGENOPT(AsmVerbose, 1, 0) ///< -dA, -fverbose-asm.
 CODEGENOPT(PreserveAsmComments, 1, 1) ///< -dA, -fno-preserve-as-comments.
diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index 9781fcaa4ff5e..e9cea8967c133 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -809,6 +809,9 @@ def warn_drv_missing_multilib : Warning<
 def note_drv_available_multilibs : Note<
   "available multilibs are:%0">;
 
+def err_drv_experimental_crel : Error<
+  "-Wa,--experimental-crel must be specified to use -Wa,--crel. CREL is 
experimental and takes a non-standard section type code">;
+
 def warn_android_unversioned_fallback : Warning<
   "Using unversioned Android target directory %0 for target %1. Unversioned"
   " directories will not be used in Clang 19. Provide a versioned directory"
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index c9f7c4e5f718b..55f0c9aff6a49 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -6958,6 +6958,9 @@ def massembler_no_warn : Flag<["-"], 
"massembler-no-warn">,
 def massembler_fatal_warnings : Flag<["-"], "massembler-fatal-warnings">,
   HelpText<"Make assembler warnings fatal">,
   MarshallingInfoFlag>;
+def crel : Flag<["--"], "crel">,
+  HelpText<"Enable CREL relocation format (ELF only)">,
+  MarshallingInfoFlag>;
 def mrelax_relocations_no : Flag<["-"], "mrelax-relocations=no">,
 HelpText<"Disable x86 relax relocations">,
 MarshallingInfoNegativeFlag>;
diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 22c3f8642ad8e..ed37085d69ac5 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ 

[clang] [llvm] [MC,llvm-readobj,yaml2obj] Support CREL relocation format (PR #91280)

2024-05-10 Thread Fangrui Song via cfe-commits


@@ -1142,6 +1193,13 @@ ELFObjectFile::getRela(DataRefImpl Rela) const {
   return *Ret;
 }
 
+template 

MaskRay wrote:

Changes to this file are for llvm-objdump support. The use patterns ensure that 
`Crels` will be populated.

I've added the assert to https://github.com/MaskRay/llvm-project/tree/demo-crel 

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


[clang] [llvm] [MC,llvm-readobj,yaml2obj] Support CREL relocation format (PR #91280)

2024-05-10 Thread Fangrui Song via cfe-commits


@@ -292,6 +293,9 @@ template  class ELFObjectFile : public 
ELFObjectFileBase {
   const Elf_Shdr *DotSymtabSec = nullptr; // Symbol table section.
   const Elf_Shdr *DotSymtabShndxSec = nullptr; // SHT_SYMTAB_SHNDX section.
 
+  // Hold CREL relocations for SectionRef::relocations().
+  mutable SmallVector, 0> Crels;

MaskRay wrote:

To the best of my knowledge, ELFObjectFile is not used by multi-threading. The 
`mutable` member is not nice, which is to comply with the interface requirement 
by `llvm-objdump -r/-R`.

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


[clang] [llvm] [MC,llvm-readobj,yaml2obj] Support CREL relocation format (PR #91280)

2024-05-10 Thread Fangrui Song via cfe-commits


@@ -446,6 +450,7 @@ template  class ELFObjectFile : public 
ELFObjectFileBase {
 
   const Elf_Rel *getRel(DataRefImpl Rel) const;
   const Elf_Rela *getRela(DataRefImpl Rela) const;
+  Elf_Crel getCrel(DataRefImpl Rel) const;

MaskRay wrote:

renamed

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


[clang] [llvm] [MC,llvm-readobj,yaml2obj] Support CREL relocation format (PR #91280)

2024-05-10 Thread Fangrui Song via cfe-commits


@@ -321,6 +321,11 @@ class ELFFile {
 
   std::vector decode_relrs(Elf_Relr_Range relrs) const;
 
+  uint64_t crelHeader(ArrayRef Content) const;
+  using RelsOrRelas = std::pair, std::vector>;

MaskRay wrote:

Yes, `std::pair<` instead of an exclusive or is for convenience.

This is a type alias in a class (ELFFile) used by llvm-readobj. lld/ELF doesn't 
use this class, and the name collision should be fine.

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


[clang] [llvm] [MC,llvm-readobj,yaml2obj] Support CREL relocation format (PR #91280)

2024-05-10 Thread Fangrui Song via cfe-commits


@@ -1117,9 +1166,11 @@ void ELFObjectFile::getRelocationTypeName(
 template 
 Expected
 ELFObjectFile::getRelocationAddend(DataRefImpl Rel) const {
-  if (getRelSection(Rel)->sh_type != ELF::SHT_RELA)
-return createError("Section is not SHT_RELA");
-  return (int64_t)getRela(Rel)->r_addend;
+  if (getRelSection(Rel)->sh_type == ELF::SHT_RELA)
+return (int64_t)getRela(Rel)->r_addend;
+  if (getRelSection(Rel)->sh_type == ELF::SHT_CREL)

MaskRay wrote:

I have reverted this file. Sorry for leaving it in the initial patch.

This code is used by `.getAddend()` in the files (not core binary utilities).

* llvm/lib/Object/RelocationResolver.cpp
* llvm/lib/XRay/InstrumentationMap.cpp
* llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp

Since they are all for static relocations, we can assume `r_addend`.
However, I agree that having an error checking would be nice.


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


[clang] [Driver] Use StringRef::operator== instead of StringRef::equals (NFC) (PR #91698)

2024-05-09 Thread Fangrui Song via cfe-commits

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


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


[clang] [clang][driver] Support `-x` for all languages in CL mode (PR #89772)

2024-05-09 Thread Fangrui Song via cfe-commits

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


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


[clang] [llvm] [MC,llvm-readobj,yaml2obj] Support CREL relocation format (PR #91280)

2024-05-09 Thread Fangrui Song via cfe-commits

MaskRay wrote:

> I think it would be useful to nominate a source as the canonical reference 
> for the specification which is updated along with any implementation changes. 
> I think 
> [discourse.llvm.org/t/rfc-crel-a-compact-relocation-format-for-elf/77600/3](https://discourse.llvm.org/t/rfc-crel-a-compact-relocation-format-for-elf/77600/3)
>  is a good starting point.
> 
> Possible examples:
> 
> * A patch to the LLVM documentation.
> * A blog-post that is kept up to date with the implementation.
> * A discourse post that is updated.

Thanks. I frequently update my blog posts and 
https://maskray.me/blog/2024-03-09-a-compact-relocation-format-for-elf#crel-relocation-format
 will be kept up to date.

However, I feel not so good to name my personal website. Then, 
https://discourse.llvm.org/t/rfc-crel-a-compact-relocation-format-for-elf/77600/3
 should serve the purpose well. discourse.llvm.org posts become non-editable 
after a period of time. I'll need to make further applies if changes are made.

> Link: 
> [discourse.llvm.org/t/rfc-crel-a-compact-relocation-format-for-elf/77600](https://discourse.llvm.org/t/rfc-crel-a-compact-relocation-format-for-elf/77600)

I can edit the link to append `/3` to refer to the specification.

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


  1   2   3   4   5   6   7   8   9   10   >