[clang-tools-extra] [tidy] add new check bugprone-return-const-ref-from-parameter (PR #89497)

2024-04-22 Thread Danny Mösch via cfe-commits


@@ -112,6 +112,13 @@ New checks
   Detects error-prone Curiously Recurring Template Pattern usage, when the CRTP
   can be constructed outside itself and the derived class.
 
+- New :doc:`bugprone-return-const-ref-from-parameter
+  ` check.
+
+  Detects return statements that return constant reference parameter as 
constant
+  reference. This may cause use-after-free errors if the caller uses xvalue as
+  arguments.

SimplyDanny wrote:

```suggestion
  Detects return statements that return a constant reference parameter as 
constant
  reference. This may cause use-after-free errors if the caller uses xvalues as
  arguments.
```

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


[clang-tools-extra] [tidy] add new check bugprone-return-const-ref-from-parameter (PR #89497)

2024-04-22 Thread Danny Mösch via cfe-commits


@@ -0,0 +1,40 @@
+//===--- ReturnConstRefFromParameterCheck.h - clang-tidy *- 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
+//
+//===--===//
+
+#ifndef 
LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_RETURNCONSTREFFROMPARAMETERCHECK_H
+#define 
LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_RETURNCONSTREFFROMPARAMETERCHECK_H
+
+#include "../ClangTidyCheck.h"
+
+namespace clang::tidy::bugprone {
+
+/// Detects return statements that return constant reference parameter as
+/// constant reference. This may cause use-after-free errors if the caller uses
+/// xvalue as arguments.

SimplyDanny wrote:

```suggestion
/// Detects return statements that return a constant reference parameter as
/// constant reference. This may cause use-after-free errors if the caller uses
/// xvalues as arguments.
```

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


[clang-tools-extra] [tidy] add new check bugprone-return-const-ref-from-parameter (PR #89497)

2024-04-22 Thread Danny Mösch via cfe-commits

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

Only a few more nits from my side.

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


[clang-tools-extra] [tidy] add new check bugprone-return-const-ref-from-parameter (PR #89497)

2024-04-22 Thread Danny Mösch via cfe-commits


@@ -0,0 +1,31 @@
+.. title:: clang-tidy - bugprone-return-const-ref-from-parameter
+
+bugprone-return-const-ref-from-parameter
+
+
+Detects return statements that return a constant reference parameter as 
constant
+reference. This may cause use-after-free errors if the caller uses xvalue as
+arguments.

SimplyDanny wrote:

```suggestion
Detects return statements that return a constant reference parameter as constant
reference. This may cause use-after-free errors if the caller uses xvalues as
arguments.
```

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


[clang-tools-extra] [tidy] add new check bugprone-return-const-ref-from-parameter (PR #89497)

2024-04-22 Thread Danny Mösch via cfe-commits

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


[clang] [llvm] [PowerPC] Tune AIX shared library TLS model at function level (PR #84132)

2024-04-22 Thread Felix via cfe-commits

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


[clang] [clang] Mark ill-formed partial specialization as invalid (PR #89536)

2024-04-22 Thread Vlad Serebrennikov via cfe-commits

https://github.com/Endilll updated 
https://github.com/llvm/llvm-project/pull/89536

>From 58058a88305c7d4c1b1a30d8572ca481889ea3f9 Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov 
Date: Sun, 21 Apr 2024 13:29:39 +0300
Subject: [PATCH 1/2] [clang] Mark ill-formed partial specialization as invalid

Fixes #89374
Solution suggested by @cor3ntin
---
 clang/lib/Sema/SemaTemplate.cpp   |  2 ++
 clang/lib/Sema/SemaTemplateDeduction.cpp  |  3 ++
 .../test/SemaCXX/template-specialization.cpp  | 28 +++
 3 files changed, 33 insertions(+)

diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index d4976f9d0d11d8..2bcbc081750b31 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -9459,6 +9459,7 @@ DeclResult Sema::ActOnClassTemplateSpecialization(
   Diag(TemplateNameLoc, diag::err_partial_spec_fully_specialized)
 << ClassTemplate->getDeclName();
   isPartialSpecialization = false;
+  Invalid = true;
 }
   }
 
@@ -9674,6 +9675,7 @@ DeclResult Sema::ActOnClassTemplateSpecialization(
   if (SkipBody && SkipBody->ShouldSkip)
 return SkipBody->Previous;
 
+  Specialization->setInvalidDecl(Invalid);
   return Specialization;
 }
 
diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp 
b/clang/lib/Sema/SemaTemplateDeduction.cpp
index 0b6375001f5326..c3815bca038554 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -1914,6 +1914,9 @@ static TemplateDeductionResult 
DeduceTemplateArgumentsByTypeMatch(
   if (!S.isCompleteType(Info.getLocation(), A))
 return Result;
 
+  if (getCanonicalRD(A)->isInvalidDecl())
+return Result;
+
   // Reset the incorrectly deduced argument from above.
   Deduced = DeducedOrig;
 
diff --git a/clang/test/SemaCXX/template-specialization.cpp 
b/clang/test/SemaCXX/template-specialization.cpp
index 7b26ff9f5c5ba4..eabb84f2e13d3e 100644
--- a/clang/test/SemaCXX/template-specialization.cpp
+++ b/clang/test/SemaCXX/template-specialization.cpp
@@ -52,3 +52,31 @@ void instantiate() {
 }
 
 }
+
+namespace GH89374 {
+
+struct A {};
+
+template 
+struct MatrixBase { // #GH89374-MatrixBase
+  template 
+  Derived =(const MatrixBase &); // 
#GH89374-copy-assignment
+};
+
+template 
+struct solve_retval;
+
+template 
+struct solve_retval : MatrixBase > {};
+// expected-error@-1 {{partial specialization of 'solve_retval' does not use 
any of its template parameters}}
+
+void ApproximateChebyshev() {
+  MatrixBase c;
+  c = solve_retval();
+  // expected-error@-1 {{no viable overloaded '='}}
+  //   expected-note@#GH89374-copy-assignment {{candidate template ignored: 
could not match 'MatrixBase' against 'solve_retval'}}
+  //   expected-note@#GH89374-MatrixBase {{candidate function (the implicit 
copy assignment operator) not viable: no known conversion from 
'solve_retval' to 'const MatrixBase' for 1st argument}}
+  //   expected-note@#GH89374-MatrixBase {{candidate function (the implicit 
move assignment operator) not viable: no known conversion from 
'solve_retval' to 'MatrixBase' for 1st argument}}
+}
+
+} // namespace GH89374

>From 933dd4d4da75635016bc520d4e0ed7ae96fd372d Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov 
Date: Tue, 23 Apr 2024 08:18:48 +0300
Subject: [PATCH 2/2] Add a release note

---
 clang/docs/ReleaseNotes.rst | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index c44f238e33846b..da1ca7ffcc353d 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -409,6 +409,9 @@ Bug Fixes in This Version
   operator.
   Fixes (#GH83267).
 
+- Fix crash on ill-formed partial specialization with CRTP.
+  Fixes (#GH89374).
+
 - Clang now correctly generates overloads for bit-precise integer types for
   builtin operators in C++. Fixes #GH82998.
 

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


[clang] [llvm] [CodeGen][i386] Move -mregparm storage earlier and fix Runtime calls (PR #89707)

2024-04-22 Thread Kees Cook via cfe-commits

kees wrote:

This needs test cases, which I'll add tomorrow. I just wanted to get the core 
logic up for review before I hit EOD...

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


[clang] [llvm] [CodeGen][i386] Move -mregparm storage earlier and fix Runtime calls (PR #89707)

2024-04-22 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Kees Cook (kees)


Changes

When building the Linux kernel for i386, the -mregparm=3 option is enabled. 
Crashes were observed in the sanitizer handler functions, and the problem was 
found to be mismatched calling convention.

As was fixed in commit c167c0a4dcdb ("[BuildLibCalls] infer inreg param attrs 
from NumRegisterParameters"), call arguments need to be marked as "in register" 
when -mregparm is set. Use the same helper developed there to update the 
function arguments.

Since CreateRuntimeFunction() is actually part of CodeGenModule, storage of the 
-mregparm value is also moved to the constructor, as doing this in Release() is 
too late.

Fixes: https://github.com/llvm/llvm-project/issues/89670

---
Full diff: https://github.com/llvm/llvm-project/pull/89707.diff


3 Files Affected:

- (modified) clang/lib/CodeGen/CodeGenModule.cpp (+7-5) 
- (modified) llvm/include/llvm/Transforms/Utils/BuildLibCalls.h (+3) 
- (modified) llvm/lib/Transforms/Utils/BuildLibCalls.cpp (+1-1) 


``diff
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 0c447b20cef40d..c314cd9e2e9f4c 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -73,6 +73,7 @@
 #include "llvm/Support/xxhash.h"
 #include "llvm/TargetParser/Triple.h"
 #include "llvm/TargetParser/X86TargetParser.h"
+#include "llvm/Transforms/Utils/BuildLibCalls.h"
 #include 
 
 using namespace clang;
@@ -442,6 +443,11 @@ CodeGenModule::CodeGenModule(ASTContext ,
   }
 ModuleNameHash = llvm::getUniqueInternalLinkagePostfix(Path);
   }
+
+  // Record mregparm value now so it is visible through all of codegen.
+  if (Context.getTargetInfo().getTriple().getArch() == llvm::Triple::x86)
+getModule().addModuleFlag(llvm::Module::Error, "NumRegisterParameters",
+  CodeGenOpts.NumRegisterParameters);
 }
 
 CodeGenModule::~CodeGenModule() {}
@@ -980,11 +986,6 @@ void CodeGenModule::Release() {
   NMD->addOperand(MD);
   }
 
-  // Record mregparm value now so it is visible through rest of codegen.
-  if (Context.getTargetInfo().getTriple().getArch() == llvm::Triple::x86)
-getModule().addModuleFlag(llvm::Module::Error, "NumRegisterParameters",
-  CodeGenOpts.NumRegisterParameters);
-
   if (CodeGenOpts.DwarfVersion) {
 getModule().addModuleFlag(llvm::Module::Max, "Dwarf Version",
   CodeGenOpts.DwarfVersion);
@@ -4781,6 +4782,7 @@ CodeGenModule::CreateRuntimeFunction(llvm::FunctionType 
*FTy, StringRef Name,
 }
   }
   setDSOLocal(F);
+  markRegisterParameterAttributes(F);
 }
   }
 
diff --git a/llvm/include/llvm/Transforms/Utils/BuildLibCalls.h 
b/llvm/include/llvm/Transforms/Utils/BuildLibCalls.h
index 9ebb9500777421..a0f2f43e287c71 100644
--- a/llvm/include/llvm/Transforms/Utils/BuildLibCalls.h
+++ b/llvm/include/llvm/Transforms/Utils/BuildLibCalls.h
@@ -62,6 +62,9 @@ namespace llvm {
  LibFunc TheLibFunc, AttributeList AttributeList,
  FunctionType *Invalid, ArgsTy... Args) = delete;
 
+  // Handle -mregparm for the given function.
+  void markRegisterParameterAttributes(Function *F);
+
   /// Check whether the library function is available on target and also that
   /// it in the current Module is a Function with the right type.
   bool isLibFuncEmittable(const Module *M, const TargetLibraryInfo *TLI,
diff --git a/llvm/lib/Transforms/Utils/BuildLibCalls.cpp 
b/llvm/lib/Transforms/Utils/BuildLibCalls.cpp
index ed0ed345435c45..e97506b4bbd95d 100644
--- a/llvm/lib/Transforms/Utils/BuildLibCalls.cpp
+++ b/llvm/lib/Transforms/Utils/BuildLibCalls.cpp
@@ -1255,7 +1255,7 @@ static void setRetExtAttr(Function ,
 }
 
 // Modeled after X86TargetLowering::markLibCallAttributes.
-static void markRegisterParameterAttributes(Function *F) {
+void llvm::markRegisterParameterAttributes(Function *F) {
   if (!F->arg_size() || F->isVarArg())
 return;
 

``




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


[clang] [llvm] [CodeGen][i386] Move -mregparm storage earlier and fix Runtime calls (PR #89707)

2024-04-22 Thread Kees Cook via cfe-commits

https://github.com/kees created https://github.com/llvm/llvm-project/pull/89707

When building the Linux kernel for i386, the -mregparm=3 option is enabled. 
Crashes were observed in the sanitizer handler functions, and the problem was 
found to be mismatched calling convention.

As was fixed in commit c167c0a4dcdb ("[BuildLibCalls] infer inreg param attrs 
from NumRegisterParameters"), call arguments need to be marked as "in register" 
when -mregparm is set. Use the same helper developed there to update the 
function arguments.

Since CreateRuntimeFunction() is actually part of CodeGenModule, storage of the 
-mregparm value is also moved to the constructor, as doing this in Release() is 
too late.

Fixes: https://github.com/llvm/llvm-project/issues/89670

>From c061c8f49f2b916bb5e60ec35d3e448ac13f2b72 Mon Sep 17 00:00:00 2001
From: Kees Cook 
Date: Mon, 22 Apr 2024 17:53:32 -0700
Subject: [PATCH] [CodeGen][i386] Move -mregparm storage earlier and fix
 Runtime calls

When building the Linux kernel for i386, the -mregparm=3 option is
enabled. Crashes were observed in the sanitizer handler functions,
and the problem was found to be mismatched calling convention.

As was fixed in commit c167c0a4dcdb ("[BuildLibCalls] infer inreg param
attrs from NumRegisterParameters"), call arguments need to be marked as
"in register" when -mregparm is set. Use the same helper developed there
to update the function arguments.

Since CreateRuntimeFunction() is actually part of CodeGenModule, storage
of the -mregparm value is also moved to the constructor, as doing this
in Release() is too late.

Fixes: https://github.com/llvm/llvm-project/issues/89670
---
 clang/lib/CodeGen/CodeGenModule.cpp| 12 +++-
 llvm/include/llvm/Transforms/Utils/BuildLibCalls.h |  3 +++
 llvm/lib/Transforms/Utils/BuildLibCalls.cpp|  2 +-
 3 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 0c447b20cef40d..c314cd9e2e9f4c 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -73,6 +73,7 @@
 #include "llvm/Support/xxhash.h"
 #include "llvm/TargetParser/Triple.h"
 #include "llvm/TargetParser/X86TargetParser.h"
+#include "llvm/Transforms/Utils/BuildLibCalls.h"
 #include 
 
 using namespace clang;
@@ -442,6 +443,11 @@ CodeGenModule::CodeGenModule(ASTContext ,
   }
 ModuleNameHash = llvm::getUniqueInternalLinkagePostfix(Path);
   }
+
+  // Record mregparm value now so it is visible through all of codegen.
+  if (Context.getTargetInfo().getTriple().getArch() == llvm::Triple::x86)
+getModule().addModuleFlag(llvm::Module::Error, "NumRegisterParameters",
+  CodeGenOpts.NumRegisterParameters);
 }
 
 CodeGenModule::~CodeGenModule() {}
@@ -980,11 +986,6 @@ void CodeGenModule::Release() {
   NMD->addOperand(MD);
   }
 
-  // Record mregparm value now so it is visible through rest of codegen.
-  if (Context.getTargetInfo().getTriple().getArch() == llvm::Triple::x86)
-getModule().addModuleFlag(llvm::Module::Error, "NumRegisterParameters",
-  CodeGenOpts.NumRegisterParameters);
-
   if (CodeGenOpts.DwarfVersion) {
 getModule().addModuleFlag(llvm::Module::Max, "Dwarf Version",
   CodeGenOpts.DwarfVersion);
@@ -4781,6 +4782,7 @@ CodeGenModule::CreateRuntimeFunction(llvm::FunctionType 
*FTy, StringRef Name,
 }
   }
   setDSOLocal(F);
+  markRegisterParameterAttributes(F);
 }
   }
 
diff --git a/llvm/include/llvm/Transforms/Utils/BuildLibCalls.h 
b/llvm/include/llvm/Transforms/Utils/BuildLibCalls.h
index 9ebb9500777421..a0f2f43e287c71 100644
--- a/llvm/include/llvm/Transforms/Utils/BuildLibCalls.h
+++ b/llvm/include/llvm/Transforms/Utils/BuildLibCalls.h
@@ -62,6 +62,9 @@ namespace llvm {
  LibFunc TheLibFunc, AttributeList AttributeList,
  FunctionType *Invalid, ArgsTy... Args) = delete;
 
+  // Handle -mregparm for the given function.
+  void markRegisterParameterAttributes(Function *F);
+
   /// Check whether the library function is available on target and also that
   /// it in the current Module is a Function with the right type.
   bool isLibFuncEmittable(const Module *M, const TargetLibraryInfo *TLI,
diff --git a/llvm/lib/Transforms/Utils/BuildLibCalls.cpp 
b/llvm/lib/Transforms/Utils/BuildLibCalls.cpp
index ed0ed345435c45..e97506b4bbd95d 100644
--- a/llvm/lib/Transforms/Utils/BuildLibCalls.cpp
+++ b/llvm/lib/Transforms/Utils/BuildLibCalls.cpp
@@ -1255,7 +1255,7 @@ static void setRetExtAttr(Function ,
 }
 
 // Modeled after X86TargetLowering::markLibCallAttributes.
-static void markRegisterParameterAttributes(Function *F) {
+void llvm::markRegisterParameterAttributes(Function *F) {
   if (!F->arg_size() || F->isVarArg())
 return;
 

___
cfe-commits mailing list
cfe-commits@lists.llvm.org

[clang] [lld] [llvm] [RISCV] Split code that tablegen needs out of RISCVISAInfo. (PR #89684)

2024-04-22 Thread Craig Topper via cfe-commits

https://github.com/topperc updated 
https://github.com/llvm/llvm-project/pull/89684

>From c28f21fb93f31661f8313259f0103dc1af44f4a7 Mon Sep 17 00:00:00 2001
From: Craig Topper 
Date: Mon, 22 Apr 2024 13:19:26 -0700
Subject: [PATCH] [RISCV] Split code that tablegen needs out of RISCVISAInfo.

This introduces a new file, RISCVISAUtils.cpp and moves the
reset of RISCVISAInfo to the TargetParser library.

This will allow us to generate part of RISCVISAInfo.cpp using
tablegen.
---
 clang/lib/Basic/Targets/RISCV.h   |  2 +-
 clang/lib/CodeGen/CodeGenModule.cpp   |  2 +-
 clang/lib/Driver/Driver.cpp   |  2 +-
 clang/lib/Driver/ToolChains/Arch/RISCV.cpp|  2 +-
 clang/lib/Driver/ToolChains/Clang.cpp |  2 +-
 clang/lib/Driver/ToolChains/Flang.cpp |  2 +-
 clang/lib/Driver/ToolChains/Gnu.cpp   |  2 +-
 clang/tools/driver/cc1_main.cpp   |  2 +-
 lld/ELF/Arch/RISCV.cpp|  2 +-
 llvm/include/llvm/Support/RISCVISAUtils.h | 42 
 .../{Support => TargetParser}/RISCVISAInfo.h  | 21 +---
 llvm/lib/Object/ELFObjectFile.cpp |  2 +-
 llvm/lib/Support/CMakeLists.txt   |  2 +-
 llvm/lib/Support/RISCVISAUtils.cpp| 88 +
 .../Target/RISCV/AsmParser/RISCVAsmParser.cpp |  2 +-
 .../RISCV/MCTargetDesc/RISCVBaseInfo.cpp  |  1 -
 .../Target/RISCV/MCTargetDesc/RISCVBaseInfo.h |  2 +-
 .../MCTargetDesc/RISCVTargetStreamer.cpp  |  2 +-
 llvm/lib/Target/RISCV/RISCVAsmPrinter.cpp |  2 +-
 llvm/lib/TargetParser/CMakeLists.txt  |  1 +
 .../RISCVISAInfo.cpp  | 96 +++
 llvm/lib/TargetParser/RISCVTargetParser.cpp   |  2 +-
 llvm/unittests/Support/CMakeLists.txt |  1 -
 llvm/unittests/TargetParser/CMakeLists.txt|  1 +
 .../RISCVISAInfoTest.cpp  | 76 +++
 llvm/utils/TableGen/RISCVTargetDefEmitter.cpp |  6 +-
 26 files changed, 204 insertions(+), 161 deletions(-)
 create mode 100644 llvm/include/llvm/Support/RISCVISAUtils.h
 rename llvm/include/llvm/{Support => TargetParser}/RISCVISAInfo.h (86%)
 create mode 100644 llvm/lib/Support/RISCVISAUtils.cpp
 rename llvm/lib/{Support => TargetParser}/RISCVISAInfo.cpp (93%)
 rename llvm/unittests/{Support => TargetParser}/RISCVISAInfoTest.cpp (93%)

diff --git a/clang/lib/Basic/Targets/RISCV.h b/clang/lib/Basic/Targets/RISCV.h
index 78580b5b1c1063..9fa42e75bbfd14 100644
--- a/clang/lib/Basic/Targets/RISCV.h
+++ b/clang/lib/Basic/Targets/RISCV.h
@@ -16,7 +16,7 @@
 #include "clang/Basic/TargetInfo.h"
 #include "clang/Basic/TargetOptions.h"
 #include "llvm/Support/Compiler.h"
-#include "llvm/Support/RISCVISAInfo.h"
+#include "llvm/TargetParser/RISCVISAInfo.h"
 #include "llvm/TargetParser/Triple.h"
 #include 
 
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 0c447b20cef40d..d085e735ecb443 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -68,9 +68,9 @@
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/ConvertUTF.h"
 #include "llvm/Support/ErrorHandling.h"
-#include "llvm/Support/RISCVISAInfo.h"
 #include "llvm/Support/TimeProfiler.h"
 #include "llvm/Support/xxhash.h"
+#include "llvm/TargetParser/RISCVISAInfo.h"
 #include "llvm/TargetParser/Triple.h"
 #include "llvm/TargetParser/X86TargetParser.h"
 #include 
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 0da92001e08c27..76b7b9fdfb4f9b 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -87,12 +87,12 @@
 #include "llvm/Support/PrettyStackTrace.h"
 #include "llvm/Support/Process.h"
 #include "llvm/Support/Program.h"
-#include "llvm/Support/RISCVISAInfo.h"
 #include "llvm/Support/Regex.h"
 #include "llvm/Support/StringSaver.h"
 #include "llvm/Support/VirtualFileSystem.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/TargetParser/Host.h"
+#include "llvm/TargetParser/RISCVISAInfo.h"
 #include  // ::getenv
 #include 
 #include 
diff --git a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp 
b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
index 96b3cc3bb8ffb1..2e2bce8494672f 100644
--- a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
@@ -15,9 +15,9 @@
 #include "clang/Driver/Options.h"
 #include "llvm/Option/ArgList.h"
 #include "llvm/Support/Error.h"
-#include "llvm/Support/RISCVISAInfo.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/TargetParser/Host.h"
+#include "llvm/TargetParser/RISCVISAInfo.h"
 #include "llvm/TargetParser/RISCVTargetParser.h"
 
 using namespace clang::driver;
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 5894a48e0e378b..dc407fd0596f59 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -54,11 +54,11 @@
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
 #include 

[clang] [clang-format] Correctly annotate list init braces of class types (PR #89706)

2024-04-22 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-format

Author: Owen Pan (owenca)


Changes

Fixes #71939.

---
Full diff: https://github.com/llvm/llvm-project/pull/89706.diff


2 Files Affected:

- (modified) clang/lib/Format/UnwrappedLineParser.cpp (+35-6) 
- (modified) clang/unittests/Format/TokenAnnotatorTest.cpp (+60) 


``diff
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index 603268f771ac52..6e4e6901e473f7 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -819,8 +819,11 @@ FormatToken *UnwrappedLineParser::parseBlock(bool 
MustBeDeclaration,
 return IfLBrace;
   }
 
-  if (FormatTok->is(tok::r_brace) && Tok->is(TT_NamespaceLBrace))
-FormatTok->setFinalizedType(TT_NamespaceRBrace);
+  if (FormatTok->is(tok::r_brace)) {
+FormatTok->setBlockKind(BK_Block);
+if (Tok->is(TT_NamespaceLBrace))
+  FormatTok->setFinalizedType(TT_NamespaceRBrace);
+  }
 
   const bool IsFunctionRBrace =
   FormatTok->is(tok::r_brace) && Tok->is(TT_FunctionLBrace);
@@ -3910,6 +3913,8 @@ void UnwrappedLineParser::parseRecord(bool ParseAsExpr) {
   const FormatToken  = *FormatTok;
   nextToken();
 
+  const FormatToken *ClassName = nullptr;
+  bool IsDerived = false;
   auto IsNonMacroIdentifier = [](const FormatToken *Tok) {
 return Tok->is(tok::identifier) && Tok->TokenText != 
Tok->TokenText.upper();
   };
@@ -3934,15 +3939,35 @@ void UnwrappedLineParser::parseRecord(bool ParseAsExpr) 
{
 }
 if (FormatTok->is(tok::l_square) && handleCppAttributes())
   continue;
+const auto *Previous = FormatTok;
 nextToken();
-// We can have macros in between 'class' and the class name.
-if (!IsNonMacroIdentifier(FormatTok->Previous) &&
-FormatTok->is(tok::l_paren)) {
-  parseParens();
+switch (FormatTok->Tok.getKind()) {
+case tok::l_paren:
+  // We can have macros in between 'class' and the class name.
+  if (!IsNonMacroIdentifier(Previous))
+parseParens();
+  break;
+case tok::coloncolon:
+  break;
+default:
+  if (!ClassName && Previous->is(tok::identifier))
+ClassName = Previous;
 }
   }
 
+  auto IsListInitialization = [&] {
+if (!ClassName || IsDerived)
+  return false;
+assert(FormatTok->is(tok::l_brace));
+const auto *Prev = FormatTok->getPreviousNonComment();
+assert(Prev);
+return Prev != ClassName && Prev->is(tok::identifier) &&
+   Prev->isNot(Keywords.kw_final) && tryToParseBracedList();
+  };
+
   if (FormatTok->isOneOf(tok::colon, tok::less)) {
+if (FormatTok->is(tok::colon))
+  IsDerived = true;
 int AngleNestingLevel = 0;
 do {
   if (FormatTok->is(tok::less))
@@ -3955,6 +3980,8 @@ void UnwrappedLineParser::parseRecord(bool ParseAsExpr) {
 break;
   }
   if (FormatTok->is(tok::l_brace)) {
+if (AngleNestingLevel == 0 && IsListInitialization())
+  return;
 calculateBraceTypes(/*ExpectClassBody=*/true);
 if (!tryToParseBracedList())
   break;
@@ -3999,6 +4026,8 @@ void UnwrappedLineParser::parseRecord(bool ParseAsExpr) {
 }
   };
   if (FormatTok->is(tok::l_brace)) {
+if (IsListInitialization())
+  return;
 auto [OpenBraceType, ClosingBraceType] = GetBraceTypes(InitialToken);
 FormatTok->setFinalizedType(OpenBraceType);
 if (ParseAsExpr) {
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index 34999b7376397b..6b8ab441cb46f8 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -2855,6 +2855,66 @@ TEST_F(TokenAnnotatorTest, BraceKind) {
   ASSERT_EQ(Tokens.size(), 18u) << Tokens;
   EXPECT_BRACE_KIND(Tokens[8], BK_BracedInit);
   EXPECT_BRACE_KIND(Tokens[16], BK_BracedInit);
+
+  Tokens = annotate("struct {};");
+  ASSERT_EQ(Tokens.size(), 5u) << Tokens;
+  EXPECT_BRACE_KIND(Tokens[1], BK_Block);
+  EXPECT_BRACE_KIND(Tokens[2], BK_Block);
+
+  Tokens = annotate("struct : Base {};");
+  ASSERT_EQ(Tokens.size(), 7u) << Tokens;
+  EXPECT_BRACE_KIND(Tokens[3], BK_Block);
+  EXPECT_BRACE_KIND(Tokens[4], BK_Block);
+
+  Tokens = annotate("struct Foo {};");
+  ASSERT_EQ(Tokens.size(), 6u) << Tokens;
+  EXPECT_BRACE_KIND(Tokens[2], BK_Block);
+  EXPECT_BRACE_KIND(Tokens[3], BK_Block);
+
+  Tokens = annotate("struct ::Foo {};");
+  ASSERT_EQ(Tokens.size(), 7u) << Tokens;
+  EXPECT_BRACE_KIND(Tokens[3], BK_Block);
+  EXPECT_BRACE_KIND(Tokens[4], BK_Block);
+
+  Tokens = annotate("struct NS::Foo {};");
+  ASSERT_EQ(Tokens.size(), 8u) << Tokens;
+  EXPECT_BRACE_KIND(Tokens[4], BK_Block);
+  EXPECT_BRACE_KIND(Tokens[5], BK_Block);
+
+  Tokens = annotate("struct Foo {};");
+  ASSERT_EQ(Tokens.size(), 9u) << Tokens;
+  EXPECT_BRACE_KIND(Tokens[5], BK_Block);
+  EXPECT_BRACE_KIND(Tokens[6], BK_Block);
+
+  Tokens = annotate("struct Foo final {};");
+  

[clang] [Coverage] Handle array decomposition correctly (PR #88881)

2024-04-22 Thread Andrey Ali Khan Bolshakov via cfe-commits

bolshakov-a wrote:

@efriedma-quic, would it be OK to add "subexpression" visitation with a comment 
that I'm not sure that it is actually needed?

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


[clang] [clang-format] Correctly annotate list init braces of class types (PR #89706)

2024-04-22 Thread Owen Pan via cfe-commits

https://github.com/owenca created 
https://github.com/llvm/llvm-project/pull/89706

Fixes #71939.

>From 0fab05c4ab7ac95d7c08dd23a0441dc28c2ef813 Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Mon, 22 Apr 2024 21:56:31 -0700
Subject: [PATCH] [clang-format] Correctly annotate list init braces of class
 types

Fixes #71939.
---
 clang/lib/Format/UnwrappedLineParser.cpp  | 41 +++--
 clang/unittests/Format/TokenAnnotatorTest.cpp | 60 +++
 2 files changed, 95 insertions(+), 6 deletions(-)

diff --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index 603268f771ac52..6e4e6901e473f7 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -819,8 +819,11 @@ FormatToken *UnwrappedLineParser::parseBlock(bool 
MustBeDeclaration,
 return IfLBrace;
   }
 
-  if (FormatTok->is(tok::r_brace) && Tok->is(TT_NamespaceLBrace))
-FormatTok->setFinalizedType(TT_NamespaceRBrace);
+  if (FormatTok->is(tok::r_brace)) {
+FormatTok->setBlockKind(BK_Block);
+if (Tok->is(TT_NamespaceLBrace))
+  FormatTok->setFinalizedType(TT_NamespaceRBrace);
+  }
 
   const bool IsFunctionRBrace =
   FormatTok->is(tok::r_brace) && Tok->is(TT_FunctionLBrace);
@@ -3910,6 +3913,8 @@ void UnwrappedLineParser::parseRecord(bool ParseAsExpr) {
   const FormatToken  = *FormatTok;
   nextToken();
 
+  const FormatToken *ClassName = nullptr;
+  bool IsDerived = false;
   auto IsNonMacroIdentifier = [](const FormatToken *Tok) {
 return Tok->is(tok::identifier) && Tok->TokenText != 
Tok->TokenText.upper();
   };
@@ -3934,15 +3939,35 @@ void UnwrappedLineParser::parseRecord(bool ParseAsExpr) 
{
 }
 if (FormatTok->is(tok::l_square) && handleCppAttributes())
   continue;
+const auto *Previous = FormatTok;
 nextToken();
-// We can have macros in between 'class' and the class name.
-if (!IsNonMacroIdentifier(FormatTok->Previous) &&
-FormatTok->is(tok::l_paren)) {
-  parseParens();
+switch (FormatTok->Tok.getKind()) {
+case tok::l_paren:
+  // We can have macros in between 'class' and the class name.
+  if (!IsNonMacroIdentifier(Previous))
+parseParens();
+  break;
+case tok::coloncolon:
+  break;
+default:
+  if (!ClassName && Previous->is(tok::identifier))
+ClassName = Previous;
 }
   }
 
+  auto IsListInitialization = [&] {
+if (!ClassName || IsDerived)
+  return false;
+assert(FormatTok->is(tok::l_brace));
+const auto *Prev = FormatTok->getPreviousNonComment();
+assert(Prev);
+return Prev != ClassName && Prev->is(tok::identifier) &&
+   Prev->isNot(Keywords.kw_final) && tryToParseBracedList();
+  };
+
   if (FormatTok->isOneOf(tok::colon, tok::less)) {
+if (FormatTok->is(tok::colon))
+  IsDerived = true;
 int AngleNestingLevel = 0;
 do {
   if (FormatTok->is(tok::less))
@@ -3955,6 +3980,8 @@ void UnwrappedLineParser::parseRecord(bool ParseAsExpr) {
 break;
   }
   if (FormatTok->is(tok::l_brace)) {
+if (AngleNestingLevel == 0 && IsListInitialization())
+  return;
 calculateBraceTypes(/*ExpectClassBody=*/true);
 if (!tryToParseBracedList())
   break;
@@ -3999,6 +4026,8 @@ void UnwrappedLineParser::parseRecord(bool ParseAsExpr) {
 }
   };
   if (FormatTok->is(tok::l_brace)) {
+if (IsListInitialization())
+  return;
 auto [OpenBraceType, ClosingBraceType] = GetBraceTypes(InitialToken);
 FormatTok->setFinalizedType(OpenBraceType);
 if (ParseAsExpr) {
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index 34999b7376397b..6b8ab441cb46f8 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -2855,6 +2855,66 @@ TEST_F(TokenAnnotatorTest, BraceKind) {
   ASSERT_EQ(Tokens.size(), 18u) << Tokens;
   EXPECT_BRACE_KIND(Tokens[8], BK_BracedInit);
   EXPECT_BRACE_KIND(Tokens[16], BK_BracedInit);
+
+  Tokens = annotate("struct {};");
+  ASSERT_EQ(Tokens.size(), 5u) << Tokens;
+  EXPECT_BRACE_KIND(Tokens[1], BK_Block);
+  EXPECT_BRACE_KIND(Tokens[2], BK_Block);
+
+  Tokens = annotate("struct : Base {};");
+  ASSERT_EQ(Tokens.size(), 7u) << Tokens;
+  EXPECT_BRACE_KIND(Tokens[3], BK_Block);
+  EXPECT_BRACE_KIND(Tokens[4], BK_Block);
+
+  Tokens = annotate("struct Foo {};");
+  ASSERT_EQ(Tokens.size(), 6u) << Tokens;
+  EXPECT_BRACE_KIND(Tokens[2], BK_Block);
+  EXPECT_BRACE_KIND(Tokens[3], BK_Block);
+
+  Tokens = annotate("struct ::Foo {};");
+  ASSERT_EQ(Tokens.size(), 7u) << Tokens;
+  EXPECT_BRACE_KIND(Tokens[3], BK_Block);
+  EXPECT_BRACE_KIND(Tokens[4], BK_Block);
+
+  Tokens = annotate("struct NS::Foo {};");
+  ASSERT_EQ(Tokens.size(), 8u) << Tokens;
+  EXPECT_BRACE_KIND(Tokens[4], BK_Block);
+  EXPECT_BRACE_KIND(Tokens[5], BK_Block);
+
+  Tokens = annotate("struct Foo {};");
+  

[clang-tools-extra] [clang-tidy] add check to suggest replacement of nested std::min or std::max with initializer lists (PR #85572)

2024-04-22 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,274 @@
+//===--- MinMaxUseInitializerListCheck.cpp - clang-tidy 
---===//
+//
+// 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 "MinMaxUseInitializerListCheck.h"
+#include "../utils/ASTUtils.h"
+#include "../utils/LexerUtils.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Lex/Lexer.h"
+
+using namespace clang;
+
+namespace {
+
+struct FindArgsResult {
+  const Expr *First;
+  const Expr *Last;
+  const Expr *Compare;
+  SmallVector Args;
+};
+
+} // anonymous namespace
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::modernize {
+
+static FindArgsResult findArgs(const CallExpr *Call) {
+  FindArgsResult Result;
+  Result.First = nullptr;
+  Result.Last = nullptr;
+  Result.Compare = nullptr;
+
+  //   check if the function has initializer list argument
+  if (Call->getNumArgs() < 3) {
+auto ArgIterator = Call->arguments().begin();
+
+const auto *InitListExpr =
+dyn_cast(*ArgIterator);
+const auto *InitList =
+InitListExpr != nullptr
+? dyn_cast(
+  InitListExpr->getSubExpr()->IgnoreImplicit())
+: nullptr;
+
+if (InitList) {
+  Result.Args.append(InitList->inits().begin(), InitList->inits().end());
+  Result.First = *ArgIterator;
+  Result.Last = *ArgIterator;
+
+  // check if there is a comparison argument
+  std::advance(ArgIterator, 1);
+  if (ArgIterator != Call->arguments().end())
+Result.Compare = *ArgIterator;
+
+  return Result;
+}
+  } else {
+// if it has 3 arguments then the last will be the comparison
+Result.Compare = *(std::next(Call->arguments().begin(), 2));
+  }
+
+  if (Result.Compare)
+Result.Args = SmallVector(llvm::drop_end(Call->arguments()));
+  else
+Result.Args = SmallVector(Call->arguments());
+
+  Result.First = Result.Args.front();
+  Result.Last = Result.Args.back();
+
+  return Result;
+}
+
+static SmallVector
+generateReplacements(const MatchFinder::MatchResult ,
+ const CallExpr *TopCall, const FindArgsResult ,
+ const bool IgnoreNonTrivialTypes,
+ const unsigned long IgnoreTrivialTypesOfSizeAbove) {
+  SmallVector FixItHints;
+
+  const QualType ResultType = TopCall->getDirectCallee()
+  ->getReturnType()
+  .getNonReferenceType()
+  .getUnqualifiedType()
+  .getCanonicalType();
+
+  // check if the type is trivial
+  const bool isResultTypeTrivial = 
Match.Context->getBaseElementType(ResultType)
+   .isTrivialType(*Match.Context);
+  const SourceManager  = *Match.SourceManager;
+  const LangOptions  = Match.Context->getLangOpts();
+
+  if ((!isResultTypeTrivial && IgnoreNonTrivialTypes))
+return FixItHints;
+
+  if (isResultTypeTrivial &&
+  // size in bits divided by 8 to get bytes
+  Match.Context->getTypeSize(ResultType) / 8 >
+  IgnoreTrivialTypesOfSizeAbove)
+return FixItHints;
+
+  for (const Expr *Arg : Result.Args) {
+const auto *InnerCall = dyn_cast(Arg->IgnoreParenImpCasts());
+
+// If the argument is not a nested call
+if (!InnerCall) {
+  // check if typecast is required
+  const QualType ArgType = Arg->IgnoreParenImpCasts()
+   ->getType()
+   .getUnqualifiedType()
+   .getCanonicalType();
+
+  if (ArgType == ResultType)
+continue;
+
+  const StringRef ArgText = Lexer::getSourceText(
+  CharSourceRange::getTokenRange(Arg->getSourceRange()), SourceMngr,
+  LanguageOpts);
+
+  Twine Replacement = llvm::Twine("static_cast<")
+  .concat(ResultType.getAsString(LanguageOpts))
+  .concat(">(")
+  .concat(ArgText)
+  .concat(")");

PiotrZSL wrote:

It doesn't mean that other checks are correct. Twine saves only pointer to 
std::string, it doesn't make a copy. Therefore in this case after call to last 
concat result of getAsString will be destroyed, if you would add call to .str() 
at the end of this chain it would be ok, but currently this is just a bug, 
additionally most probably because return type is small, it fit into stack 
memory.

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


[clang] [lld] [llvm] [RISCV] Split code that tablegen needs out of RISCVISAInfo. (PR #89684)

2024-04-22 Thread Pengcheng Wang via cfe-commits

https://github.com/wangpc-pp approved this pull request.

LGTM.

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


[clang] [lld] [llvm] [RISCV] Split code that tablegen needs out of RISCVISAInfo. (PR #89684)

2024-04-22 Thread Craig Topper via cfe-commits

https://github.com/topperc updated 
https://github.com/llvm/llvm-project/pull/89684

>From 7171df42d62ec510627f1fd6526c39c340f2e425 Mon Sep 17 00:00:00 2001
From: Craig Topper 
Date: Mon, 22 Apr 2024 13:19:26 -0700
Subject: [PATCH 1/2] [RISCV] Split code that tablegen needs out of
 RISCVISAInfo.

This introduces a new file, RISCVISAUtils.cpp and moves the
reset of RISCVISAInfo to the TargetParser library.

This will allow us to generate part of RISCVISAInfo.cpp using
tablegen.
---
 clang/lib/Basic/Targets/RISCV.h   |  2 +-
 clang/lib/CodeGen/CodeGenModule.cpp   |  2 +-
 clang/lib/Driver/Driver.cpp   |  2 +-
 clang/lib/Driver/ToolChains/Arch/RISCV.cpp|  2 +-
 clang/lib/Driver/ToolChains/Clang.cpp |  2 +-
 clang/lib/Driver/ToolChains/Flang.cpp |  2 +-
 clang/lib/Driver/ToolChains/Gnu.cpp   |  2 +-
 clang/tools/driver/cc1_main.cpp   |  2 +-
 lld/ELF/Arch/RISCV.cpp|  2 +-
 llvm/include/llvm/Support/RISCVISAUtils.h | 42 
 .../{Support => TargetParser}/RISCVISAInfo.h  | 21 +---
 llvm/lib/Object/ELFObjectFile.cpp |  2 +-
 llvm/lib/Support/CMakeLists.txt   |  2 +-
 llvm/lib/Support/RISCVISAUtils.cpp| 88 +
 .../Target/RISCV/AsmParser/RISCVAsmParser.cpp |  2 +-
 .../RISCV/MCTargetDesc/RISCVBaseInfo.cpp  |  1 -
 .../Target/RISCV/MCTargetDesc/RISCVBaseInfo.h |  2 +-
 .../MCTargetDesc/RISCVTargetStreamer.cpp  |  2 +-
 llvm/lib/Target/RISCV/RISCVAsmPrinter.cpp |  2 +-
 llvm/lib/TargetParser/CMakeLists.txt  |  1 +
 .../RISCVISAInfo.cpp  | 96 +++
 llvm/lib/TargetParser/RISCVTargetParser.cpp   |  2 +-
 llvm/unittests/Support/RISCVISAInfoTest.cpp   | 74 +++---
 llvm/utils/TableGen/RISCVTargetDefEmitter.cpp |  6 +-
 24 files changed, 202 insertions(+), 159 deletions(-)
 create mode 100644 llvm/include/llvm/Support/RISCVISAUtils.h
 rename llvm/include/llvm/{Support => TargetParser}/RISCVISAInfo.h (86%)
 create mode 100644 llvm/lib/Support/RISCVISAUtils.cpp
 rename llvm/lib/{Support => TargetParser}/RISCVISAInfo.cpp (93%)

diff --git a/clang/lib/Basic/Targets/RISCV.h b/clang/lib/Basic/Targets/RISCV.h
index 78580b5b1c1063..9fa42e75bbfd14 100644
--- a/clang/lib/Basic/Targets/RISCV.h
+++ b/clang/lib/Basic/Targets/RISCV.h
@@ -16,7 +16,7 @@
 #include "clang/Basic/TargetInfo.h"
 #include "clang/Basic/TargetOptions.h"
 #include "llvm/Support/Compiler.h"
-#include "llvm/Support/RISCVISAInfo.h"
+#include "llvm/TargetParser/RISCVISAInfo.h"
 #include "llvm/TargetParser/Triple.h"
 #include 
 
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 0c447b20cef40d..d085e735ecb443 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -68,9 +68,9 @@
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/ConvertUTF.h"
 #include "llvm/Support/ErrorHandling.h"
-#include "llvm/Support/RISCVISAInfo.h"
 #include "llvm/Support/TimeProfiler.h"
 #include "llvm/Support/xxhash.h"
+#include "llvm/TargetParser/RISCVISAInfo.h"
 #include "llvm/TargetParser/Triple.h"
 #include "llvm/TargetParser/X86TargetParser.h"
 #include 
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 0da92001e08c27..76b7b9fdfb4f9b 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -87,12 +87,12 @@
 #include "llvm/Support/PrettyStackTrace.h"
 #include "llvm/Support/Process.h"
 #include "llvm/Support/Program.h"
-#include "llvm/Support/RISCVISAInfo.h"
 #include "llvm/Support/Regex.h"
 #include "llvm/Support/StringSaver.h"
 #include "llvm/Support/VirtualFileSystem.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/TargetParser/Host.h"
+#include "llvm/TargetParser/RISCVISAInfo.h"
 #include  // ::getenv
 #include 
 #include 
diff --git a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp 
b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
index 96b3cc3bb8ffb1..2e2bce8494672f 100644
--- a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
@@ -15,9 +15,9 @@
 #include "clang/Driver/Options.h"
 #include "llvm/Option/ArgList.h"
 #include "llvm/Support/Error.h"
-#include "llvm/Support/RISCVISAInfo.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/TargetParser/Host.h"
+#include "llvm/TargetParser/RISCVISAInfo.h"
 #include "llvm/TargetParser/RISCVTargetParser.h"
 
 using namespace clang::driver;
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 5894a48e0e378b..dc407fd0596f59 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -54,11 +54,11 @@
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Process.h"
-#include "llvm/Support/RISCVISAInfo.h"
 #include "llvm/Support/YAMLParser.h"
 #include "llvm/TargetParser/ARMTargetParserCommon.h"
 #include 

[clang] [clang][CodeGen][NFC] Make ConstExprEmitter a ConstStmtVisitor (PR #89041)

2024-04-22 Thread Timm Baeder via cfe-commits

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


[clang] e5f9de8 - [clang][CodeGen][NFC] Make ConstExprEmitter a ConstStmtVisitor (#89041)

2024-04-22 Thread via cfe-commits

Author: Timm Baeder
Date: 2024-04-23T06:04:15+02:00
New Revision: e5f9de89e540b06893709d97f3ce9671071b3df0

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

LOG: [clang][CodeGen][NFC] Make ConstExprEmitter a ConstStmtVisitor (#89041)

No reason for this to not be one. This gets rid of a few const_casts.

Added: 


Modified: 
clang/lib/CodeGen/CGExprConstant.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGExprConstant.cpp 
b/clang/lib/CodeGen/CGExprConstant.cpp
index c924660c5a91c8..94962091116afb 100644
--- a/clang/lib/CodeGen/CGExprConstant.cpp
+++ b/clang/lib/CodeGen/CGExprConstant.cpp
@@ -564,12 +564,13 @@ class ConstStructBuilder {
 
 public:
   static llvm::Constant *BuildStruct(ConstantEmitter ,
- InitListExpr *ILE, QualType StructTy);
+ const InitListExpr *ILE,
+ QualType StructTy);
   static llvm::Constant *BuildStruct(ConstantEmitter ,
  const APValue , QualType ValTy);
   static bool UpdateStruct(ConstantEmitter ,
ConstantAggregateBuilder , CharUnits Offset,
-   InitListExpr *Updater);
+   const InitListExpr *Updater);
 
 private:
   ConstStructBuilder(ConstantEmitter ,
@@ -586,7 +587,7 @@ class ConstStructBuilder {
   bool AppendBitField(const FieldDecl *Field, uint64_t FieldOffset,
   llvm::ConstantInt *InitExpr, bool AllowOverwrite = 
false);
 
-  bool Build(InitListExpr *ILE, bool AllowOverwrite);
+  bool Build(const InitListExpr *ILE, bool AllowOverwrite);
   bool Build(const APValue , const RecordDecl *RD, bool IsPrimaryBase,
  const CXXRecordDecl *VTableClass, CharUnits BaseOffset);
   llvm::Constant *Finalize(QualType Ty);
@@ -635,7 +636,7 @@ bool ConstStructBuilder::AppendBitField(
 static bool EmitDesignatedInitUpdater(ConstantEmitter ,
   ConstantAggregateBuilder ,
   CharUnits Offset, QualType Type,
-  InitListExpr *Updater) {
+  const InitListExpr *Updater) {
   if (Type->isRecordType())
 return ConstStructBuilder::UpdateStruct(Emitter, Const, Offset, Updater);
 
@@ -647,7 +648,7 @@ static bool EmitDesignatedInitUpdater(ConstantEmitter 
,
   llvm::Type *ElemTy = Emitter.CGM.getTypes().ConvertTypeForMem(ElemType);
 
   llvm::Constant *FillC = nullptr;
-  if (Expr *Filler = Updater->getArrayFiller()) {
+  if (const Expr *Filler = Updater->getArrayFiller()) {
 if (!isa(Filler)) {
   FillC = Emitter.tryEmitAbstractForMemory(Filler, ElemType);
   if (!FillC)
@@ -658,7 +659,7 @@ static bool EmitDesignatedInitUpdater(ConstantEmitter 
,
   unsigned NumElementsToUpdate =
   FillC ? CAT->getZExtSize() : Updater->getNumInits();
   for (unsigned I = 0; I != NumElementsToUpdate; ++I, Offset += ElemSize) {
-Expr *Init = nullptr;
+const Expr *Init = nullptr;
 if (I < Updater->getNumInits())
   Init = Updater->getInit(I);
 
@@ -667,7 +668,7 @@ static bool EmitDesignatedInitUpdater(ConstantEmitter 
,
 return false;
 } else if (!Init || isa(Init)) {
   continue;
-} else if (InitListExpr *ChildILE = dyn_cast(Init)) {
+} else if (const auto *ChildILE = dyn_cast(Init)) {
   if (!EmitDesignatedInitUpdater(Emitter, Const, Offset, ElemType,
  ChildILE))
 return false;
@@ -683,7 +684,7 @@ static bool EmitDesignatedInitUpdater(ConstantEmitter 
,
   return true;
 }
 
-bool ConstStructBuilder::Build(InitListExpr *ILE, bool AllowOverwrite) {
+bool ConstStructBuilder::Build(const InitListExpr *ILE, bool AllowOverwrite) {
   RecordDecl *RD = ILE->getType()->castAs()->getDecl();
   const ASTRecordLayout  = CGM.getContext().getASTRecordLayout(RD);
 
@@ -711,7 +712,7 @@ bool ConstStructBuilder::Build(InitListExpr *ILE, bool 
AllowOverwrite) {
 
 // Get the initializer.  A struct can include fields without initializers,
 // we just use explicit null values for them.
-Expr *Init = nullptr;
+const Expr *Init = nullptr;
 if (ElementNo < ILE->getNumInits())
   Init = ILE->getInit(ElementNo++);
 if (Init && isa(Init))
@@ -879,7 +880,7 @@ llvm::Constant *ConstStructBuilder::Finalize(QualType Type) 
{
 }
 
 llvm::Constant *ConstStructBuilder::BuildStruct(ConstantEmitter ,
-InitListExpr *ILE,
+const InitListExpr *ILE,
 QualType ValTy) {
   ConstantAggregateBuilder Const(Emitter.CGM);
   ConstStructBuilder Builder(Emitter, Const, 

[clang-tools-extra] [clang-tidy] add check to suggest replacement of nested std::min or std::max with initializer lists (PR #85572)

2024-04-22 Thread Piotr Zegar via cfe-commits


@@ -47,7 +47,7 @@ class MinMaxUseInitializerListCheck : public ClangTidyCheck {
 
 private:
   bool IgnoreNonTrivialTypes;
-  unsigned long IgnoreTrivialTypesOfSizeAbove;
+  long IgnoreTrivialTypesOfSizeAbove;

PiotrZSL wrote:

why change into signed ? Unsigned were better.

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


[clang-tools-extra] [clang-tidy] add check to suggest replacement of nested std::min or std::max with initializer lists (PR #85572)

2024-04-22 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,50 @@
+.. title:: clang-tidy - modernize-min-max-use-initializer-list
+
+modernize-min-max-use-initializer-list
+==
+
+Replaces nested ``std::min`` and ``std::max`` calls with an initializer list 
+where applicable.
+
+For instance, consider the following code:
+
+.. code-block:: cpp
+
+   int a = std::max(std::max(i, j), k);
+
+The check will transform the above code to:
+
+.. code-block:: cpp
+
+   int a = std::max({i, j, k});
+
+Performance Considerations
+==
+
+While this check simplifies the code and makes it more readable, it may cause 
+performance degradation for non-trivial types due to the need to copy objects 
+into the initializer list.
+
+To avoid this, it is recommended to use `std::ref` or `std::cref` for 
+non-trivial types:
+
+.. code-block:: cpp
+
+   std::string b = std::max({std::ref(i), std::ref(j), std::ref(k)});
+
+Options
+===
+
+.. option:: IncludeStyle
+
+   A string specifying which include-style is used, `llvm` or `google`. Default
+   is `llvm`.
+
+.. option:: IgnoreNonTrivialTypes
+
+   A boolean specifying whether to ignore non-trivial types. Default is `true`.
+
+.. option:: IgnoreTrivialTypesOfSizeAbove
+
+   An integer specifying the size (in bytes) above which trivial types are 
+ignored. Default is `32`.

PiotrZSL wrote:

add 2 spaces at the begining.

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


[clang-tools-extra] [clang-tidy] add check to suggest replacement of nested std::min or std::max with initializer lists (PR #85572)

2024-04-22 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,56 @@
+//===--- MinMaxUseInitializerListCheck.h - clang-tidy ---*- 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
+//
+//===--===//
+
+#ifndef 
LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_MINMAXUSEINITIALIZERLISTCHECK_H
+#define 
LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_MINMAXUSEINITIALIZERLISTCHECK_H
+
+#include "../ClangTidyCheck.h"
+#include "../utils/IncludeInserter.h"
+
+namespace clang::tidy::modernize {
+
+/// Replaces nested ``std::min`` and ``std::max`` calls with an initializer 
list
+/// where applicable.
+///
+/// For example:
+///
+/// \code
+///   int a = std::max(std::max(i, j), k);
+/// \endcode
+///
+/// This code is transformed to:
+///
+/// \code
+///   int a = std::max({i, j, k});
+/// \endcode
+class MinMaxUseInitializerListCheck : public ClangTidyCheck {
+public:
+  MinMaxUseInitializerListCheck(StringRef Name, ClangTidyContext *Context);
+
+  void storeOptions(ClangTidyOptions::OptionMap ) override;
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+  void registerPPCallbacks(const SourceManager , Preprocessor *PP,
+   Preprocessor *ModuleExpanderPP) override;
+  void check(const ast_matchers::MatchFinder::MatchResult ) override;
+
+  bool isLanguageVersionSupported(const LangOptions ) const override {
+return LangOpts.CPlusPlus11;
+  }
+  std::optional getCheckTraversalKind() const override {
+return TK_IgnoreUnlessSpelledInSource;
+  }
+
+private:
+  bool IgnoreNonTrivialTypes;
+  long IgnoreTrivialTypesOfSizeAbove;

PiotrZSL wrote:

why long ? use std::uint64_t

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


[clang-tools-extra] [clang-tidy] add check to suggest replacement of nested std::min or std::max with initializer lists (PR #85572)

2024-04-22 Thread Piotr Zegar via cfe-commits


@@ -80,27 +80,26 @@ static SmallVector
 generateReplacements(const MatchFinder::MatchResult ,
  const CallExpr *TopCall, const FindArgsResult ,
  const bool IgnoreNonTrivialTypes,
- const unsigned long IgnoreTrivialTypesOfSizeAbove) {
+ const long IgnoreTrivialTypesOfSizeAbove) {

PiotrZSL wrote:

avoid using things like long/int. We got std::uint64_t, std::uint32_t for these 
things.

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


[clang] [clang] fix half && bfloat16 convert node expr codegen (PR #89051)

2024-04-22 Thread Pengcheng Wang via cfe-commits


@@ -0,0 +1,194 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 4
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -target-feature +fullbf16 
-S -emit-llvm %s -o - | FileCheck %s

wangpc-pp wrote:

```suggestion
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -target-feature +fullbf16 
-disable-O0-optnone -emit-llvm %s -o - | opt -S -passes=mem2reg | FileCheck %s
```
We can run `mem2reg` to reduce CHECKs.

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


[clang] [lld] [llvm] [RISCV] Split code that tablegen needs out of RISCVISAInfo. (PR #89684)

2024-04-22 Thread Craig Topper via cfe-commits


@@ -1,12 +1,12 @@
-//===-- RISCVISAInfo.cpp - RISC-V Arch String Parser *- C++ 
-*-===//

topperc wrote:

Only header files usually have this comment

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


[clang] [lld] [llvm] [RISCV] Split code that tablegen needs out of RISCVISAInfo. (PR #89684)

2024-04-22 Thread Pengcheng Wang via cfe-commits

https://github.com/wangpc-pp commented:

I think this patch doesn't need to be stacked on #89335.

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


[clang] [lld] [llvm] [RISCV] Split code that tablegen needs out of RISCVISAInfo. (PR #89684)

2024-04-22 Thread Pengcheng Wang via cfe-commits


@@ -1,12 +1,12 @@
-//===-- RISCVISAInfo.cpp - RISC-V Arch String Parser *- C++ 
-*-===//

wangpc-pp wrote:

We shouldn't remove `*- C++ -*` here I think, it's for editors like Emacs.

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


[clang] [lld] [llvm] [RISCV] Split code that tablegen needs out of RISCVISAInfo. (PR #89684)

2024-04-22 Thread Pengcheng Wang via cfe-commits

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


[clang] [MC/DC][Coverage] Workaround for `##` conditions (PR #89573)

2024-04-22 Thread Wentao Zhang via cfe-commits

whentojump wrote:

Hi, thanks for the fix.

I can confirm it addressed your test case (https://godbolt.org/z/sMscqWeq7). 
But unfortunately it doesn't fix the one in my original post of #87000 
([compiler explorer 

[clang] Push immediate function context while transforming lambdas in templates. (PR #89702)

2024-04-22 Thread Daniel M. Katz via cfe-commits

https://github.com/katzdm updated 
https://github.com/llvm/llvm-project/pull/89702

>From ba1c87956f74248467d2f85c20c2f450eef953bd Mon Sep 17 00:00:00 2001
From: Dan Katz 
Date: Mon, 22 Apr 2024 22:39:06 -0400
Subject: [PATCH] Push immediate function context while transforming lambdas in
 templates.

---
 clang/docs/ReleaseNotes.rst|  3 +++
 clang/lib/Sema/TreeTransform.h |  2 ++
 clang/test/SemaCXX/cxx2a-consteval.cpp | 20 
 3 files changed, 25 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 45a9a79739a4eb..0efdcac3c4b8e1 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -420,6 +420,9 @@ Bug Fixes in This Version
 - Fixed a regression in CTAD that a friend declaration that befriends itself 
may cause
   incorrect constraint substitution. (#GH86769).
 
+- Fixed bug in which the body of a consteval lambda within a template was not 
parsed as within an
+  immediate function context.
+
 Bug Fixes to Compiler Builtins
 ^^
 
diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index 284c9173e68ed5..a3ddebb3ca5963 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -14044,6 +14044,8 @@ TreeTransform::TransformLambdaExpr(LambdaExpr 
*E) {
   // FIXME: Sema's lambda-building mechanism expects us to push an expression
   // evaluation context even if we're not transforming the function body.
   getSema().PushExpressionEvaluationContext(
+  E->getCallOperator()->isConsteval() ?
+  Sema::ExpressionEvaluationContext::ImmediateFunctionContext :
   Sema::ExpressionEvaluationContext::PotentiallyEvaluated);
 
   Sema::CodeSynthesisContext C;
diff --git a/clang/test/SemaCXX/cxx2a-consteval.cpp 
b/clang/test/SemaCXX/cxx2a-consteval.cpp
index 192621225a543c..e198074372072d 100644
--- a/clang/test/SemaCXX/cxx2a-consteval.cpp
+++ b/clang/test/SemaCXX/cxx2a-consteval.cpp
@@ -260,6 +260,26 @@ int(*test)(int)  = l1;
 
 }
 
+namespace consteval_lambda_in_template {
+struct S {
+int *value;
+constexpr S(int v) : value(new int {v}) {}
+constexpr ~S() { delete value; }
+};
+consteval S fn() { return S(5); }
+
+template 
+void fn2() {
+(void)[]() consteval -> int {
+  return *(fn().value);  // OK, immediate context
+};
+}
+
+void caller() {
+fn2();
+}
+}
+
 namespace std {
 
 template  struct remove_reference { using type = T; };

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


[clang] Push immediate function context while transforming lambdas in templates. (PR #89702)

2024-04-22 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Daniel M. Katz (katzdm)


Changes

The following program is [accepted](https://godbolt.org/z/oEc34Trh4) by Clang, 
EDG, and MSVC, but rejected by Clang:
```cpp
#include vector

consteval auto fn() { return std::vector {1,2,3}; }

template typename T = int
void fn2() {
(void)[]() consteval {
  for (auto e : fn()) {}
};
}

void caller() {
fn2();
}
```

The stated diagnostic is:
```cpp
source:8:21: error: call to consteval function 'fn' is not a constant 
expression
8 |   for (auto e : fn()) {}
```

The body of the lambda should be evaluated as within an immediate function 
context when the lambda is marked as `consteval`.

---
Full diff: https://github.com/llvm/llvm-project/pull/89702.diff


3 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+3) 
- (modified) clang/lib/Sema/TreeTransform.h (+2) 
- (modified) clang/test/SemaCXX/cxx2a-consteval.cpp (+20) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 45a9a79739a4eb..0efdcac3c4b8e1 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -420,6 +420,9 @@ Bug Fixes in This Version
 - Fixed a regression in CTAD that a friend declaration that befriends itself 
may cause
   incorrect constraint substitution. (#GH86769).
 
+- Fixed bug in which the body of a consteval lambda within a template was not 
parsed as within an
+  immediate function context.
+
 Bug Fixes to Compiler Builtins
 ^^
 
diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index 284c9173e68ed5..a3ddebb3ca5963 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -14044,6 +14044,8 @@ TreeTransform::TransformLambdaExpr(LambdaExpr 
*E) {
   // FIXME: Sema's lambda-building mechanism expects us to push an expression
   // evaluation context even if we're not transforming the function body.
   getSema().PushExpressionEvaluationContext(
+  E->getCallOperator()->isConsteval() ?
+  Sema::ExpressionEvaluationContext::ImmediateFunctionContext :
   Sema::ExpressionEvaluationContext::PotentiallyEvaluated);
 
   Sema::CodeSynthesisContext C;
diff --git a/clang/test/SemaCXX/cxx2a-consteval.cpp 
b/clang/test/SemaCXX/cxx2a-consteval.cpp
index 192621225a543c..b19e25e26c214c 100644
--- a/clang/test/SemaCXX/cxx2a-consteval.cpp
+++ b/clang/test/SemaCXX/cxx2a-consteval.cpp
@@ -260,6 +260,26 @@ int(*test)(int)  = l1;
 
 }
 
+namespace consteval_dependent_lambda {
+struct S {
+int *value;
+constexpr S(int v) : value(new int {v}) {}
+constexpr ~S() { delete value; }
+};
+consteval S fn() { return S(5); }
+
+template 
+void fn2() {
+(void)[]() consteval -> int {
+  return *(fn().value);  // OK, immediate context
+};
+}
+
+void caller() {
+fn2();
+}
+}
+
 namespace std {
 
 template  struct remove_reference { using type = T; };

``




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


[clang] Push immediate function context while transforming lambdas in templates. (PR #89702)

2024-04-22 Thread Daniel M. Katz via cfe-commits

https://github.com/katzdm created 
https://github.com/llvm/llvm-project/pull/89702

The following program is [accepted](https://godbolt.org/z/oEc34Trh4) by Clang, 
EDG, and MSVC, but rejected by Clang:
```cpp
#include 

consteval auto fn() { return std::vector {1,2,3}; }

template 
void fn2() {
(void)[]() consteval {
  for (auto e : fn()) {}
};
}

void caller() {
fn2();
}
```

The stated diagnostic is:
```cpp
:8:21: error: call to consteval function 'fn' is not a constant 
expression
8 |   for (auto e : fn()) {}
```

The body of the lambda should be evaluated as within an immediate function 
context when the lambda is marked as `consteval`.

>From 1db83800ef13fae454709c8ba4a7b80728c7bcbe Mon Sep 17 00:00:00 2001
From: Dan Katz 
Date: Mon, 22 Apr 2024 22:39:06 -0400
Subject: [PATCH] Push immediate function context while transforming lambdas in
 templates.

---
 clang/docs/ReleaseNotes.rst|  3 +++
 clang/lib/Sema/TreeTransform.h |  2 ++
 clang/test/SemaCXX/cxx2a-consteval.cpp | 20 
 3 files changed, 25 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 45a9a79739a4eb..0efdcac3c4b8e1 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -420,6 +420,9 @@ Bug Fixes in This Version
 - Fixed a regression in CTAD that a friend declaration that befriends itself 
may cause
   incorrect constraint substitution. (#GH86769).
 
+- Fixed bug in which the body of a consteval lambda within a template was not 
parsed as within an
+  immediate function context.
+
 Bug Fixes to Compiler Builtins
 ^^
 
diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index 284c9173e68ed5..a3ddebb3ca5963 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -14044,6 +14044,8 @@ TreeTransform::TransformLambdaExpr(LambdaExpr 
*E) {
   // FIXME: Sema's lambda-building mechanism expects us to push an expression
   // evaluation context even if we're not transforming the function body.
   getSema().PushExpressionEvaluationContext(
+  E->getCallOperator()->isConsteval() ?
+  Sema::ExpressionEvaluationContext::ImmediateFunctionContext :
   Sema::ExpressionEvaluationContext::PotentiallyEvaluated);
 
   Sema::CodeSynthesisContext C;
diff --git a/clang/test/SemaCXX/cxx2a-consteval.cpp 
b/clang/test/SemaCXX/cxx2a-consteval.cpp
index 192621225a543c..b19e25e26c214c 100644
--- a/clang/test/SemaCXX/cxx2a-consteval.cpp
+++ b/clang/test/SemaCXX/cxx2a-consteval.cpp
@@ -260,6 +260,26 @@ int(*test)(int)  = l1;
 
 }
 
+namespace consteval_dependent_lambda {
+struct S {
+int *value;
+constexpr S(int v) : value(new int {v}) {}
+constexpr ~S() { delete value; }
+};
+consteval S fn() { return S(5); }
+
+template 
+void fn2() {
+(void)[]() consteval -> int {
+  return *(fn().value);  // OK, immediate context
+};
+}
+
+void caller() {
+fn2();
+}
+}
+
 namespace std {
 
 template  struct remove_reference { using type = T; };

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


[clang-tools-extra] [clang-tidy] add check to suggest replacement of nested std::min or std::max with initializer lists (PR #85572)

2024-04-22 Thread via cfe-commits

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


[clang-tools-extra] [clang-tidy] add check to suggest replacement of nested std::min or std::max with initializer lists (PR #85572)

2024-04-22 Thread via cfe-commits


@@ -0,0 +1,274 @@
+//===--- MinMaxUseInitializerListCheck.cpp - clang-tidy 
---===//
+//
+// 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 "MinMaxUseInitializerListCheck.h"
+#include "../utils/ASTUtils.h"
+#include "../utils/LexerUtils.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Lex/Lexer.h"
+
+using namespace clang;
+
+namespace {
+
+struct FindArgsResult {
+  const Expr *First;
+  const Expr *Last;
+  const Expr *Compare;
+  SmallVector Args;
+};
+
+} // anonymous namespace
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::modernize {
+
+static FindArgsResult findArgs(const CallExpr *Call) {
+  FindArgsResult Result;
+  Result.First = nullptr;
+  Result.Last = nullptr;
+  Result.Compare = nullptr;
+
+  //   check if the function has initializer list argument
+  if (Call->getNumArgs() < 3) {
+auto ArgIterator = Call->arguments().begin();
+
+const auto *InitListExpr =
+dyn_cast(*ArgIterator);
+const auto *InitList =
+InitListExpr != nullptr
+? dyn_cast(
+  InitListExpr->getSubExpr()->IgnoreImplicit())
+: nullptr;
+
+if (InitList) {
+  Result.Args.append(InitList->inits().begin(), InitList->inits().end());
+  Result.First = *ArgIterator;
+  Result.Last = *ArgIterator;
+
+  // check if there is a comparison argument
+  std::advance(ArgIterator, 1);
+  if (ArgIterator != Call->arguments().end())
+Result.Compare = *ArgIterator;
+
+  return Result;
+}
+  } else {
+// if it has 3 arguments then the last will be the comparison
+Result.Compare = *(std::next(Call->arguments().begin(), 2));
+  }
+
+  if (Result.Compare)
+Result.Args = SmallVector(llvm::drop_end(Call->arguments()));
+  else
+Result.Args = SmallVector(Call->arguments());
+
+  Result.First = Result.Args.front();
+  Result.Last = Result.Args.back();
+
+  return Result;
+}
+
+static SmallVector
+generateReplacements(const MatchFinder::MatchResult ,
+ const CallExpr *TopCall, const FindArgsResult ,
+ const bool IgnoreNonTrivialTypes,
+ const unsigned long IgnoreTrivialTypesOfSizeAbove) {
+  SmallVector FixItHints;
+
+  const QualType ResultType = TopCall->getDirectCallee()
+  ->getReturnType()
+  .getNonReferenceType()
+  .getUnqualifiedType()
+  .getCanonicalType();
+
+  // check if the type is trivial
+  const bool isResultTypeTrivial = 
Match.Context->getBaseElementType(ResultType)
+   .isTrivialType(*Match.Context);
+  const SourceManager  = *Match.SourceManager;
+  const LangOptions  = Match.Context->getLangOpts();
+
+  if ((!isResultTypeTrivial && IgnoreNonTrivialTypes))
+return FixItHints;
+
+  if (isResultTypeTrivial &&
+  // size in bits divided by 8 to get bytes
+  Match.Context->getTypeSize(ResultType) / 8 >
+  IgnoreTrivialTypesOfSizeAbove)
+return FixItHints;
+
+  for (const Expr *Arg : Result.Args) {
+const auto *InnerCall = dyn_cast(Arg->IgnoreParenImpCasts());
+
+// If the argument is not a nested call
+if (!InnerCall) {
+  // check if typecast is required
+  const QualType ArgType = Arg->IgnoreParenImpCasts()
+   ->getType()
+   .getUnqualifiedType()
+   .getCanonicalType();
+
+  if (ArgType == ResultType)
+continue;
+
+  const StringRef ArgText = Lexer::getSourceText(
+  CharSourceRange::getTokenRange(Arg->getSourceRange()), SourceMngr,
+  LanguageOpts);
+
+  Twine Replacement = llvm::Twine("static_cast<")
+  .concat(ResultType.getAsString(LanguageOpts))
+  .concat(">(")
+  .concat(ArgText)
+  .concat(")");

sopyb wrote:

Thanks for the heads up! After taking a look at other checks, it seems like it 
would be okay to skip assigning `ResultType.getAsString(LanguageOpts)` to a 
local variable. Storing it locally might  also create some reference lifetime 
issues.

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


[clang] [Modules] No transitive source location change (PR #86912)

2024-04-22 Thread Chuanqi Xu via cfe-commits

ChuanqiXu9 wrote:

@jansvoboda11 @Bigcheese ping

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


[clang] [BoundsSafety] WIP: Make 'counted_by' work for pointer fields; late parsing for 'counted_by' on decl attr position (PR #87596)

2024-04-22 Thread Dan Liew via cfe-commits

delcypher wrote:

@rapidsna I've addressed the "Make it an error to use 'counted_by' on size-less 
types (e.g., forward declared structs)" TODO.

I still need to test this PR properly and write a proper commit message 
explaining what this does.

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


[clang] [BoundsSafety] WIP: Make 'counted_by' work for pointer fields; late parsing for 'counted_by' on decl attr position (PR #87596)

2024-04-22 Thread Dan Liew via cfe-commits

https://github.com/delcypher updated 
https://github.com/llvm/llvm-project/pull/87596

>From b859cf056df24daa85f3fd305ef56f32e0f266ed Mon Sep 17 00:00:00 2001
From: Dan Liew 
Date: Fri, 12 Apr 2024 17:36:19 -0700
Subject: [PATCH 1/2] [Attributes] Support Attributes being declared as
 supporting an experimental late parsing mode "extension"

This patch changes the `LateParsed` field of `Attr` in `Attr.td` to be
an instantiation of the new `LateAttrParseKind` class. The instation can be one 
of the following:

* `LateAttrParsingNever` - Corresponds with the false value of `LateParsed` 
prior to this patch (the default for an attribute).
* `LateAttrParseStandard` - Corresponds with the true value of `LateParsed` 
prior to this patch.
* `LateAttrParseExperimentalExt` - A new mode described below.

`LateAttrParseExperimentalExt` is an experimental extension to
`LateAttrParseStandard`. Essentially this allows
`Parser::ParseGNUAttributes(...)` to distinguish between these cases:

1. Only `LateAttrParseExperimentalExt` attributes should be late parsed.
2. Both `LateAttrParseExperimentalExt` and `LateAttrParseStandard`
  attributes should be late parsed.

Callers (and indirect callers) of `Parser::ParseGNUAttributes(...)`
indicate the desired behavior by setting a flag in the
`LateParsedAttrList` object that is passed to the function.

In addition to the above, a new driver and frontend flag
(`-fexperimental-late-parse-attributes`) with a corresponding LangOpt
(`ExperimentalLateParseAttributes`) is added that changes how
`LateAttrParseExperimentalExt` attributes are parsed.

* When the flag is disabled (default), in cases where only
  `LateAttrParsingExperimentalOnly` late parsing is requested, the
  attribute will be parsed immediately (i.e. **NOT** late parsed). This
  allows the attribute to act just like a `LateAttrParseStandard`
  attribute when the flag is disabled.

* When the flag is enabled, in cases where only
  `LateAttrParsingExperimentalOnly` late parsing is requested, the
  attribute will be late parsed.

The motivation behind this change is to allow the new `counted_by`
attribute (part of `-fbounds-safety`) to support late parsing but
**only** when `-fexperimental-late-parse-attributes` is enabled. This
attribute needs to support late parsing to allow it to refer to fields
later in a struct definition (or function parameters declared later).
However, there isn't a precedent for supporting late attribute parsing
in C so this flag allows the new behavior to exist in Clang but not be
on by default. This behavior was requested as part of the
`-fbounds-safety` RFC process
(https://discourse.llvm.org/t/rfc-enforcing-bounds-safety-in-c-fbounds-safety/70854/68).

This patch doesn't introduce any uses of `LateAttrParseExperimentalExt`.
This will be added for the `counted_by` attribute in a future patch
(https://github.com/llvm/llvm-project/pull/87596). A consequence is the
new behavior added in this patch is not yet testable. Hence, the lack of
tests covering the new behavior.

rdar://125400257
---
 clang/include/clang/Basic/Attr.td |  78 +++---
 clang/include/clang/Basic/LangOptions.def |   1 +
 clang/include/clang/Driver/Options.td |   7 +
 clang/include/clang/Parse/Parser.h|  15 +-
 clang/lib/Driver/ToolChains/Clang.cpp |   3 +
 clang/lib/Parse/ParseDecl.cpp |  42 +-
 .../experimental-late-parse-attributes.c  |  12 ++
 clang/utils/TableGen/ClangAttrEmitter.cpp | 136 +++---
 8 files changed, 251 insertions(+), 43 deletions(-)
 create mode 100644 clang/test/Driver/experimental-late-parse-attributes.c

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index dc87a8c6f022dc..0df80118286c89 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -592,6 +592,48 @@ class AttrSubjectMatcherAggregateRule 
{
 
 def SubjectMatcherForNamed : AttrSubjectMatcherAggregateRule;
 
+// Late Attribute parsing mode enum
+class LateAttrParseKind  {
+  int Kind = val;
+}
+
+// Never late parsed
+def LateAttrParseNever : LateAttrParseKind<0>;
+
+// Standard late attribute parsing
+//
+// This is language dependent. For example:
+//
+// * For C++ enables late parsing of a declaration attributes
+// * For C does not enable late parsing of attributes
+//
+def LateAttrParseStandard: LateAttrParseKind<1>;
+
+// Experimental extension to standard late attribute parsing
+//
+// This extension behaves like `LateAttrParseStandard` but allows
+// late parsing attributes in more contexts.
+//
+// In contexts where `LateAttrParseStandard` attributes are late
+// parsed, `LateAttrParseExperimentalExt` attributes will also
+// be late parsed.
+//
+// In contexts that only late parse `LateAttrParseExperimentalExt` attributes
+// (see `LateParsedAttrList::lateAttrParseExperimentalExtOnly()`)
+//
+// * If `-fexperimental-late-parse-attributes`
+//   

[clang] [llvm] [RISCV] Add processor definition for XiangShan-KunMingHu (PR #89359)

2024-04-22 Thread via cfe-commits


@@ -378,3 +378,30 @@ def XIANGSHAN_NANHU : 
RISCVProcessorModel<"xiangshan-nanhu",
 TuneZExtHFusion,
 TuneZExtWFusion,
 TuneShiftedZExtWFusion]>;
+def XIANGSHAN_KUNMINGHU : RISCVProcessorModel<"xiangshan-kunminghu",
+  NoSchedModel,
+  [Feature64Bit,
+   FeatureStdExtI,
+   FeatureStdExtZicsr,
+   FeatureStdExtZifencei,
+   FeatureStdExtM,
+   FeatureStdExtA,
+   FeatureStdExtF,
+   FeatureStdExtD,
+   FeatureStdExtC,
+   FeatureStdExtZba,
+   FeatureStdExtZbb,
+   FeatureStdExtZbc,
+   FeatureStdExtZbs,
+   FeatureStdExtZkn,
+   FeatureStdExtZksed,
+   FeatureStdExtZksh,
+   FeatureStdExtSvinval,
+   FeatureStdExtZicbom,
+   FeatureStdExtZicboz,
+   FeatureStdExtV,
+   FeatureStdExtZvl128b],
+   [TuneNoDefaultUnroll,

Khao7342 wrote:

We will post this data in the future.

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


[clang] Add support for builtin_verbose_trap (PR #79230)

2024-04-22 Thread Akira Hatanaka via cfe-commits


@@ -3424,6 +3445,26 @@ llvm::DIMacroFile 
*CGDebugInfo::CreateTempMacroFile(llvm::DIMacroFile *Parent,
   return DBuilder.createTempMacroFile(Parent, Line, FName);
 }
 
+llvm::DILocation *CGDebugInfo::CreateTrapFailureMessageFor(

ahatanak wrote:

@dwblaikie 's comment:
https://github.com/llvm/llvm-project/pull/79230#discussion_r1575391593

So the name of the subprogram would be something like `__builtin_trap: 
identifier123 : Argument_must_not_be_null`?

@Michael137 @delcypher is there a reason we cannot use the same prefix 
(`__builtin_trap`, for example)? Does lldb need clang to use different prefixes 
for `-fbounds-safety` and `builtin_verbose_trap`? 


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


[clang] [AIX][TLS][clang] Add -maix-small-local-dynamic-tls clang option (PR #88829)

2024-04-22 Thread Felix via cfe-commits

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


[clang] 16efd2a - [AIX][TLS][clang] Add -maix-small-local-dynamic-tls clang option (#88829)

2024-04-22 Thread via cfe-commits

Author: Felix (Ting Wang)
Date: 2024-04-23T08:44:25+08:00
New Revision: 16efd2a4c4b6a811688e5f623cb04dbd2d0579e8

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

LOG: [AIX][TLS][clang]  Add -maix-small-local-dynamic-tls clang option (#88829)

This patch adds the clang portion of an AIX-specific option to inform
the
compiler that it can use a faster access sequence for the local-dynamic
TLS model (formally named aix-small-local-dynamic-tls).

This patch mainly references Amy's work on small local-exec TLS support.

Added: 
clang/test/Driver/aix-small-local-exec-dynamic-tls.c

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Driver/Options.td
clang/lib/Basic/Targets/PPC.cpp
clang/lib/Basic/Targets/PPC.h
clang/lib/Driver/ToolChains/Arch/PPC.cpp

Removed: 
clang/test/Driver/aix-small-local-exec-tls.c



diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 2b3bafa1c30548..f339fab6e8428f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -659,6 +659,12 @@ CUDA Support
 AIX Support
 ^^^
 
+- Introduced the ``-maix-small-local-dynamic-tls`` option to produce a faster
+  access sequence for local-dynamic TLS variables where the offset from the TLS
+  base is encoded as an immediate operand.
+  This access sequence is not used for TLS variables larger than 32KB, and is
+  currently only supported on 64-bit mode.
+
 WebAssembly Support
 ^^^
 

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 9f86808145d9ab..3c55aceecdde38 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5041,6 +5041,12 @@ def maix_small_local_exec_tls : Flag<["-"], 
"maix-small-local-exec-tls">,
"where the offset from the TLS base is encoded as an "
"immediate operand (AIX 64-bit only). "
"This access sequence is not used for variables larger than 32KB.">;
+def maix_small_local_dynamic_tls : Flag<["-"], "maix-small-local-dynamic-tls">,
+  Group,
+  HelpText<"Produce a faster access sequence for local-dynamic TLS variables "
+   "where the offset from the TLS base is encoded as an "
+   "immediate operand (AIX 64-bit only). "
+   "This access sequence is not used for variables larger than 32KB.">;
 def maix_struct_return : Flag<["-"], "maix-struct-return">,
   Group, Visibility<[ClangOption, CC1Option]>,
   HelpText<"Return all structs in memory (PPC32 only)">,

diff  --git a/clang/lib/Basic/Targets/PPC.cpp b/clang/lib/Basic/Targets/PPC.cpp
index aebe51bfa4daad..d62a7457682eaf 100644
--- a/clang/lib/Basic/Targets/PPC.cpp
+++ b/clang/lib/Basic/Targets/PPC.cpp
@@ -79,6 +79,8 @@ bool 
PPCTargetInfo::handleTargetFeatures(std::vector ,
   HasPrivileged = true;
 } else if (Feature == "+aix-small-local-exec-tls") {
   HasAIXSmallLocalExecTLS = true;
+} else if (Feature == "+aix-small-local-dynamic-tls") {
+  HasAIXSmallLocalDynamicTLS = true;
 } else if (Feature == "+isa-v206-instructions") {
   IsISA2_06 = true;
 } else if (Feature == "+isa-v207-instructions") {
@@ -573,9 +575,10 @@ bool PPCTargetInfo::initFeatureMap(
   // Privileged instructions are off by default.
   Features["privileged"] = false;
 
-  // The code generated by the -maix-small-local-exec-tls option is turned
-  // off by default.
+  // The code generated by the -maix-small-local-[exec|dynamic]-tls option is
+  // turned off by default.
   Features["aix-small-local-exec-tls"] = false;
+  Features["aix-small-local-dynamic-tls"] = false;
 
   Features["spe"] = llvm::StringSwitch(CPU)
 .Case("8548", true)
@@ -713,6 +716,7 @@ bool PPCTargetInfo::hasFeature(StringRef Feature) const {
   .Case("rop-protect", HasROPProtect)
   .Case("privileged", HasPrivileged)
   .Case("aix-small-local-exec-tls", HasAIXSmallLocalExecTLS)
+  .Case("aix-small-local-dynamic-tls", HasAIXSmallLocalDynamicTLS)
   .Case("isa-v206-instructions", IsISA2_06)
   .Case("isa-v207-instructions", IsISA2_07)
   .Case("isa-v30-instructions", IsISA3_0)

diff  --git a/clang/lib/Basic/Targets/PPC.h b/clang/lib/Basic/Targets/PPC.h
index fa2f442e25846d..60bc1dec8f95c6 100644
--- a/clang/lib/Basic/Targets/PPC.h
+++ b/clang/lib/Basic/Targets/PPC.h
@@ -61,6 +61,7 @@ class LLVM_LIBRARY_VISIBILITY PPCTargetInfo : public 
TargetInfo {
   bool HasROPProtect = false;
   bool HasPrivileged = false;
   bool HasAIXSmallLocalExecTLS = false;
+  bool HasAIXSmallLocalDynamicTLS = false;
   bool HasVSX = false;
   bool UseCRBits = false;
   bool HasP8Vector = false;

diff  --git a/clang/lib/Driver/ToolChains/Arch/PPC.cpp 
b/clang/lib/Driver/ToolChains/Arch/PPC.cpp
index 

[clang] [AIX][TLS][clang] Add -maix-small-local-dynamic-tls clang option (PR #88829)

2024-04-22 Thread Felix via cfe-commits

https://github.com/orcguru updated 
https://github.com/llvm/llvm-project/pull/88829

>From 35bf12e2fcb499c8953e4207cea2296d9ddcbf1f Mon Sep 17 00:00:00 2001
From: Ting Wang 
Date: Mon, 15 Apr 2024 21:52:02 -0400
Subject: [PATCH 1/2] Following Amy's b1922e55ab3b35dff99238fd0b74be00df0472e7,
 and d5fe1bd081ec129a1259cccf5171692d87dbd1f3 to add
 -maix-small-local-dynamic-tls clang option.

---
 clang/docs/ReleaseNotes.rst  |  6 +
 clang/include/clang/Driver/Options.td|  6 +
 clang/lib/Basic/Targets/PPC.cpp  |  8 --
 clang/lib/Basic/Targets/PPC.h|  1 +
 clang/lib/Driver/ToolChains/Arch/PPC.cpp | 17 ++--
 clang/test/Driver/aix-small-local-exec-tls.c | 27 +---
 6 files changed, 51 insertions(+), 14 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 45a9a79739a4eb..f79e0b6da853bb 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -634,6 +634,12 @@ CUDA Support
 AIX Support
 ^^^
 
+- Introduced the ``-maix-small-local-dynamic-tls`` option to produce a faster
+  access sequence for local-dynamic TLS variables where the offset from the TLS
+  base is encoded as an immediate operand.
+  This access sequence is not used for TLS variables larger than 32KB, and is
+  currently only supported on 64-bit mode.
+
 WebAssembly Support
 ^^^
 
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 7ac36222644aac..30ceb492183ee3 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5022,6 +5022,12 @@ def maix_small_local_exec_tls : Flag<["-"], 
"maix-small-local-exec-tls">,
"where the offset from the TLS base is encoded as an "
"immediate operand (AIX 64-bit only). "
"This access sequence is not used for variables larger than 32KB.">;
+def maix_small_local_dynamic_tls : Flag<["-"], "maix-small-local-dynamic-tls">,
+  Group,
+  HelpText<"Produce a faster access sequence for local-dynamic TLS variables "
+   "where the offset from the TLS base is encoded as an "
+   "immediate operand (AIX 64-bit only). "
+   "This access sequence is not used for variables larger than 32KB.">;
 def maix_struct_return : Flag<["-"], "maix-struct-return">,
   Group, Visibility<[ClangOption, CC1Option]>,
   HelpText<"Return all structs in memory (PPC32 only)">,
diff --git a/clang/lib/Basic/Targets/PPC.cpp b/clang/lib/Basic/Targets/PPC.cpp
index aebe51bfa4daad..d62a7457682eaf 100644
--- a/clang/lib/Basic/Targets/PPC.cpp
+++ b/clang/lib/Basic/Targets/PPC.cpp
@@ -79,6 +79,8 @@ bool 
PPCTargetInfo::handleTargetFeatures(std::vector ,
   HasPrivileged = true;
 } else if (Feature == "+aix-small-local-exec-tls") {
   HasAIXSmallLocalExecTLS = true;
+} else if (Feature == "+aix-small-local-dynamic-tls") {
+  HasAIXSmallLocalDynamicTLS = true;
 } else if (Feature == "+isa-v206-instructions") {
   IsISA2_06 = true;
 } else if (Feature == "+isa-v207-instructions") {
@@ -573,9 +575,10 @@ bool PPCTargetInfo::initFeatureMap(
   // Privileged instructions are off by default.
   Features["privileged"] = false;
 
-  // The code generated by the -maix-small-local-exec-tls option is turned
-  // off by default.
+  // The code generated by the -maix-small-local-[exec|dynamic]-tls option is
+  // turned off by default.
   Features["aix-small-local-exec-tls"] = false;
+  Features["aix-small-local-dynamic-tls"] = false;
 
   Features["spe"] = llvm::StringSwitch(CPU)
 .Case("8548", true)
@@ -713,6 +716,7 @@ bool PPCTargetInfo::hasFeature(StringRef Feature) const {
   .Case("rop-protect", HasROPProtect)
   .Case("privileged", HasPrivileged)
   .Case("aix-small-local-exec-tls", HasAIXSmallLocalExecTLS)
+  .Case("aix-small-local-dynamic-tls", HasAIXSmallLocalDynamicTLS)
   .Case("isa-v206-instructions", IsISA2_06)
   .Case("isa-v207-instructions", IsISA2_07)
   .Case("isa-v30-instructions", IsISA3_0)
diff --git a/clang/lib/Basic/Targets/PPC.h b/clang/lib/Basic/Targets/PPC.h
index fa2f442e25846d..60bc1dec8f95c6 100644
--- a/clang/lib/Basic/Targets/PPC.h
+++ b/clang/lib/Basic/Targets/PPC.h
@@ -61,6 +61,7 @@ class LLVM_LIBRARY_VISIBILITY PPCTargetInfo : public 
TargetInfo {
   bool HasROPProtect = false;
   bool HasPrivileged = false;
   bool HasAIXSmallLocalExecTLS = false;
+  bool HasAIXSmallLocalDynamicTLS = false;
   bool HasVSX = false;
   bool UseCRBits = false;
   bool HasP8Vector = false;
diff --git a/clang/lib/Driver/ToolChains/Arch/PPC.cpp 
b/clang/lib/Driver/ToolChains/Arch/PPC.cpp
index 5ffe73236205d3..634c096523319d 100644
--- a/clang/lib/Driver/ToolChains/Arch/PPC.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/PPC.cpp
@@ -125,21 +125,22 @@ void ppc::getPPCTargetFeatures(const Driver , const 
llvm::Triple ,
 
   bool UseSeparateSections = 

[clang] [llvm] [mlir] Fix mismatches between function parameter definitions and declarations (PR #89512)

2024-04-22 Thread Troy Butler via cfe-commits

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


[clang] [Clang] Add wraps attribute (for granular integer overflow handling) (PR #86618)

2024-04-22 Thread Justin Stitt via cfe-commits

JustinStitt wrote:

@efriedma-quic said:
> I'm still not happy with the AST representation here. The current 
> representation is likely to cause unpredictable results in edge cases, and 
> compatibility constraints mean whatever result the current version happens to 
> produce for those cases is locked in forever. And there isn't really any good 
> way to mitigate those issues under the current representation.
> 
> I don't want to block progress here, but I think in its current form, we're 
> likely to end up with reported issues we can't fix.

The current design is heavily opt-in. So much so that this isn't just some 
compiler flag that you turn on. You have to go out of your way to design your 
code around this attribute, specifically marking things as wrapping with named 
types, etc.

So I guess the questions are: Is the current description of this attribute not 
clear enough? Do we think users will be confused/surprised by its behavior? 
What edge cases are there (in C)? Can they be fixed right now so we don't have 
these compatibility issues in the future?

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


[clang] Fix -fno-unsafe-math-optimizations behavior (PR #89473)

2024-04-22 Thread Andy Kaylor via cfe-commits

andykaylor wrote:

I've made extensive changes to the fast-math.c test here: 
https://github.com/llvm/llvm-project/pull/89687

That update isn't intended to change any existing behavior. A few things worked 
differently than I expected, but I left the checks consistent with the current 
behavior and added comments where I thought the current behavior was incorrect.

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


[clang] [clang] Set correct FPOptions if attribute 'optnone' presents (PR #85605)

2024-04-22 Thread John McCall via cfe-commits

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

This seems fine.  Is there any existing bookkeeping we no longer need to do if 
we're going to have this RAII object in scope during function parsing?

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


[clang] Fix objc_sel_{name,types} missing an underscore (PR #88713)

2024-04-22 Thread Jonathan Schleifer via cfe-commits

Midar wrote:

These symbols are just used to deduplicate strings: That's why they're hidden 
and in COMDAT. So I don't think it'll break or fix the ABI ;).

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


[clang] fast math test overhaul (PR #89687)

2024-04-22 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Andy Kaylor (andykaylor)


Changes

- Fix -fno-unsafe-math-optimizations behavior
- [WIP] Major change to fast-math.c lit test
- Clean up the checks in the fast-math driver test


---

Patch is 26.79 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/89687.diff


3 Files Affected:

- (modified) clang/docs/UsersManual.rst (-1) 
- (modified) clang/lib/Driver/ToolChains/Clang.cpp (-2) 
- (modified) clang/test/Driver/fast-math.c (+159-174) 


``diff
diff --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index c464bc3a69adc5..2b4155d4b65a48 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -1690,7 +1690,6 @@ floating point semantic models: precise (the default), 
strict, and fast.
* ``-fno-associative-math``
* ``-fno-reciprocal-math``
* ``-fsigned-zeros``
-   * ``-ftrapping-math``
* ``-ffp-contract=on``
* ``-fdenormal-fp-math=ieee``
 
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 456ea74caadb00..0776d095327219 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -3137,8 +3137,6 @@ static void RenderFloatingPointOptions(const ToolChain 
, const Driver ,
   ReciprocalMath = false;
   SignedZeros = true;
   ApproxFunc = false;
-  TrappingMath = true;
-  FPExceptionBehavior = "strict";
 
   // The target may have opted to flush by default, so force IEEE.
   DenormalFPMath = llvm::DenormalMode::getIEEE();
diff --git a/clang/test/Driver/fast-math.c b/clang/test/Driver/fast-math.c
index 882e81fd14d34a..b07d5732932cdb 100644
--- a/clang/test/Driver/fast-math.c
+++ b/clang/test/Driver/fast-math.c
@@ -7,324 +7,309 @@
 // Both of them use gcc driver for as.
 //
 // RUN: %clang -### -fno-honor-infinities -c %s 2>&1 \
-// RUN:   | FileCheck --check-prefix=CHECK-NO-INFS %s
+// RUN:   | FileCheck --check-prefixes=CHECK,NINF,NO-NNAN,NO-FINITE-ONLY %s
 // infinites [sic] is a supported alternative spelling of infinities.
 // RUN: %clang -### -fno-honor-infinites -c %s 2>&1 \
-// RUN:   | FileCheck --check-prefix=CHECK-NO-INFS %s
-// CHECK-NO-INFS: "-cc1"
-// CHECK-NO-INFS: "-menable-no-infs"
+// RUN:   | FileCheck --check-prefixes=CHECK,NINF,NO-NNAN,NO-FINITE-ONLY %s
 //
 // RUN: %clang -### -fno-fast-math -fno-honor-infinities -c %s 2>&1 \
-// RUN:   | FileCheck --check-prefix=CHECK-NO-FAST-MATH-NO-INFS %s
-// CHECK-NO-FAST-MATH-NO-INFS: "-cc1"
-// CHECK-NO-FAST-MATH-NO-INFS: "-menable-no-infs"
+// RUN:   | FileCheck 
--check-prefixes=CHECK,NO-FAST,NINF,NO-NNAN,NO-FINITE-ONLY %s
 //
 // RUN: %clang -### -fno-honor-infinities -fno-fast-math -c %s 2>&1 \
-// RUN:   | FileCheck --check-prefix=CHECK-NO-INFS-NO-FAST-MATH %s
-// CHECK-NO-INFS-NO-FAST-MATH: "-cc1"
-// CHECK-NO-INFS-NO-FAST-MATH-NOT: "-menable-no-infs"
+// RUN:   | FileCheck 
--check-prefixes=CHECK,NO-FAST,NO-NINF,NO-NNAN,NO-FINITE-ONLY %s
 //
 // RUN: %clang -### -fno-signed-zeros -c %s 2>&1 \
-// RUN:   | FileCheck --check-prefix=CHECK-NO-SIGNED-ZEROS %s
-// CHECK-NO-SIGNED-ZEROS: "-cc1"
-// CHECK-NO-SIGNED-ZEROS: "-fno-signed-zeros"
+// RUN:   | FileCheck --check-prefixes=CHECK,NSZ,NOROUNDING %s
 //
 // RUN: %clang -### -fno-fast-math -fno-signed-zeros -c %s 2>&1 \
-// RUN:   | FileCheck --check-prefix=CHECK-NO-FAST-MATH-NO-SIGNED-ZEROS %s
-// CHECK-NO-FAST-MATH-NO-SIGNED-ZEROS: "-cc1"
-// CHECK-NO-FAST-MATH-NO-SIGNED-ZEROS: "-fno-signed-zeros"
+// RUN:   | FileCheck --check-prefixes=CHECK,NO-FAST,NSZ %s
 //
 // RUN: %clang -### -fno-signed-zeros -fno-fast-math -c %s 2>&1 \
-// RUN:   | FileCheck --check-prefix=CHECK-NO-SIGNED-ZEROS-NO-FAST-MATH %s
-// CHECK-NO-SIGNED-ZEROS-NO-FAST-MATH: "-cc1"
-// CHECK-NO-SIGNED-ZEROS-NO-FAST-MATH-NOT: "-fno-signed-zeros"
+// RUN:   | FileCheck --check-prefixes=CHECK,NO-FAST,NO-NSZ,NOROUNDING %s
 //
 // RUN: %clang -### -freciprocal-math -c %s 2>&1 \
-// RUN:   | FileCheck --check-prefix=CHECK-RECIPROCAL-MATH %s
-// CHECK-RECIPROCAL-MATH: "-cc1"
-// CHECK-RECIPROCAL-MATH: "-freciprocal-math"
+// RUN:   | FileCheck --check-prefixes=CHECK,ARCP,NOROUNDING %s
 //
 // RUN: %clang -### -fno-fast-math -freciprocal-math -c %s 2>&1 \
-// RUN:   | FileCheck --check-prefix=CHECK-NO-FAST-MATH-RECIPROCAL-MATH %s
-// CHECK-NO-FAST-MATH-RECIPROCAL-MATH: "-cc1"
-// CHECK-NO-FAST-MATH-RECIPROCAL-MATH: "-freciprocal-math"
+// RUN:   | FileCheck --check-prefixes=CHECK,ARCP,NOROUNDING %s
 //
 // RUN: %clang -### -freciprocal-math -fno-fast-math -c %s 2>&1 \
-// RUN:   | FileCheck --check-prefix=CHECK-RECIPROCAL-MATH-NO-FAST-MATH %s
-// CHECK-RECIPROCAL-MATH-NO-FAST-MATH: "-cc1"
-// CHECK-RECIPROCAL-MATH-NO-FAST-MATH-NOT: "-freciprocal-math"
+// RUN:   | FileCheck --check-prefixes=CHECK,NO-ARCP,NOROUNDING %s
 //
 // RUN: %clang -### -fno-honor-nans -c %s 2>&1 \
-// RUN:   | FileCheck --check-prefix=CHECK-NO-NANS %s
-// CHECK-NO-NANS: "-cc1"
-// CHECK-NO-NANS: 

[clang] fast math test overhaul (PR #89687)

2024-04-22 Thread Andy Kaylor via cfe-commits

https://github.com/andykaylor created 
https://github.com/llvm/llvm-project/pull/89687

- Fix -fno-unsafe-math-optimizations behavior
- [WIP] Major change to fast-math.c lit test
- Clean up the checks in the fast-math driver test


>From 100fc9dfb2b071877d758ce71bddeec693d986da Mon Sep 17 00:00:00 2001
From: Andy Kaylor 
Date: Fri, 19 Apr 2024 16:35:00 -0700
Subject: [PATCH 1/3] Fix -fno-unsafe-math-optimizations behavior

This changes the handling of -fno-unsafe-fp-math to stop having that
option imply -ftrapping-math. In gcc, -fno-unsafe-math-optimizations sets
-ftrapping-math, but that dependency is based on the fact the
-ftrapping-math is enabled by default in gcc. Because clang does not
enabled -ftrapping-math by default, there is no reason for
-fno-unsafe-math-optimizations to set it.

On the other hand, -funsafe-math-optimizations continues to imply
-fno-trapping-math because this option necessarily disables strict
exception semantics.

This fixes https://github.com/llvm/llvm-project/issues/87523
---
 clang/docs/UsersManual.rst|  1 -
 clang/lib/Driver/ToolChains/Clang.cpp |  2 --
 clang/test/Driver/fast-math.c | 24 +---
 3 files changed, 13 insertions(+), 14 deletions(-)

diff --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index c464bc3a69adc5..2b4155d4b65a48 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -1690,7 +1690,6 @@ floating point semantic models: precise (the default), 
strict, and fast.
* ``-fno-associative-math``
* ``-fno-reciprocal-math``
* ``-fsigned-zeros``
-   * ``-ftrapping-math``
* ``-ffp-contract=on``
* ``-fdenormal-fp-math=ieee``
 
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 456ea74caadb00..0776d095327219 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -3137,8 +3137,6 @@ static void RenderFloatingPointOptions(const ToolChain 
, const Driver ,
   ReciprocalMath = false;
   SignedZeros = true;
   ApproxFunc = false;
-  TrappingMath = true;
-  FPExceptionBehavior = "strict";
 
   // The target may have opted to flush by default, so force IEEE.
   DenormalFPMath = llvm::DenormalMode::getIEEE();
diff --git a/clang/test/Driver/fast-math.c b/clang/test/Driver/fast-math.c
index 882e81fd14d34a..ef23f88dd817ea 100644
--- a/clang/test/Driver/fast-math.c
+++ b/clang/test/Driver/fast-math.c
@@ -271,11 +271,11 @@
 // RUN:   2>&1 | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s
 
 // RUN: %clang -### -funsafe-math-optimizations -fno-reciprocal-math -c %s \
-// RUN:   2>&1 | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s
+// RUN:   2>&1 | FileCheck --check-prefix=CHECK-REASSOC-NO-UNSAFE-MATH %s
 // RUN: %clang -### -funsafe-math-optimizations -fsigned-zeros -c %s 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s
 // RUN: %clang -### -funsafe-math-optimizations -ftrapping-math -c %s 2>&1 \
-// RUN:   | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s
+// RUN:   | FileCheck --check-prefix=CHECK-TRAPPING-NO-UNSAFE-MATH %s
 // RUN: %clang -### -funsafe-math-optimizations -fno-unsafe-math-optimizations 
\
 // RUN: -c %s 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s
@@ -283,18 +283,20 @@
 // RUN:   | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s
 
 // RUN: %clang -### -ffast-math -fno-reciprocal-math -c %s 2>&1 \
-// RUN:   | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s
+// RUN:   | FileCheck --check-prefix=CHECK-REASSOC-NO-UNSAFE-MATH %s
 // RUN: %clang -### -ffast-math -fsigned-zeros -c %s 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s
 // RUN: %clang -### -ffast-math -ftrapping-math -c %s 2>&1 \
-// RUN:   | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s
+// RUN:   | FileCheck --check-prefix=CHECK-TRAPPING-NO-UNSAFE-MATH %s
 // RUN: %clang -### -ffast-math -fno-unsafe-math-optimizations -c %s 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s
 
 // CHECK-NO-UNSAFE-MATH: "-cc1"
 // CHECK-NO-UNSAFE-MATH-NOT: "-funsafe-math-optimizations"
-// CHECK-NO_UNSAFE-MATH-NOT: "-mreassociate"
+// CHECK-NO-UNSAFE-MATH-NOT: "-mreassociate"
 // CHECK-NO-UNSAFE-MATH: "-o"
+// CHECK-NO-UNSAFE-MATH-NOT: "-ffp-exception-behavior=strict"
+// CHECK-TRAPPING-NO-UNSAFE-MATH: "-ffp-exception-behavior=strict"
 
 
 // Reassociate is allowed because it does not require reciprocal-math.
@@ -304,8 +306,8 @@
 // RUN:   | FileCheck --check-prefix=CHECK-REASSOC-NO-UNSAFE-MATH %s
 
 // CHECK-REASSOC-NO-UNSAFE-MATH: "-cc1"
-// CHECK-REASSOC-NO_UNSAFE-MATH-NOT: "-funsafe-math-optimizations"
-// CHECK-REASSOC-NO_UNSAFE-MATH: "-mreassociate"
+// CHECK-REASSOC-NO-UNSAFE-MATH-NOT: "-funsafe-math-optimizations"
+// CHECK-REASSOC-NO-UNSAFE-MATH: "-mreassociate"
 // CHECK-REASSOC-NO-UNSAFE-MATH-NOT: "-funsafe-math-optimizations"
 // CHECK-REASSOC-NO-UNSAFE-MATH: "-o"
 
@@ -318,12 +320,12 @@
 
 // RUN: %clang 

[clang] [Clang] Add wraps attribute (for granular integer overflow handling) (PR #86618)

2024-04-22 Thread Justin Stitt via cfe-commits


@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 %s -verify -fsyntax-only -triple x86_64-pc-linux-gnu
+// expected-no-diagnostics
+typedef int __attribute__((wraps)) wrapping_int;
+
+void foo(void) {
+  const wrapping_int A = 1;
+  int D = 2147483647 + A;

JustinStitt wrote:

OK, fixed in 1aa85e159d5768a7059bb35e457af28a3753bf66

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


[clang] [Clang] Add wraps attribute (for granular integer overflow handling) (PR #86618)

2024-04-22 Thread Justin Stitt via cfe-commits

https://github.com/JustinStitt updated 
https://github.com/llvm/llvm-project/pull/86618

>From 50e7b1039e514dacc05bb8cd9ff9a3e3df9ed24d Mon Sep 17 00:00:00 2001
From: Justin Stitt 
Date: Tue, 5 Mar 2024 03:14:49 +
Subject: [PATCH 01/13] implement wraps attribute

Signed-off-by: Justin Stitt 
---
 clang/docs/ReleaseNotes.rst   |  9 +++
 clang/include/clang/AST/Expr.h|  3 +
 clang/include/clang/Basic/Attr.td |  6 ++
 clang/include/clang/Basic/AttrDocs.td | 66 +++
 .../clang/Basic/DiagnosticSemaKinds.td|  3 +
 clang/include/clang/Sema/Sema.h   |  4 ++
 clang/lib/AST/Expr.cpp| 19 ++
 clang/lib/AST/ExprConstant.cpp|  6 +-
 clang/lib/AST/TypePrinter.cpp |  3 +
 clang/lib/CodeGen/CGExprScalar.cpp| 40 +--
 clang/lib/Sema/SemaDeclAttr.cpp   | 12 +++-
 clang/lib/Sema/SemaType.cpp   | 15 +
 clang/test/CodeGen/integer-overflow.c | 56 
 clang/test/CodeGen/unsigned-overflow.c| 63 +++---
 clang/test/Sema/attr-wraps.c  |  9 +++
 15 files changed, 298 insertions(+), 16 deletions(-)
 create mode 100644 clang/test/Sema/attr-wraps.c

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 2b3bafa1c30548..fa7acb894cd76f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -296,6 +296,15 @@ Attribute Changes in Clang
 - Clang now warns that the ``exclude_from_explicit_instantiation`` attribute
   is ignored when applied to a local class or a member thereof.
 
+- Introduced ``__attribute((wraps))__`` which can be added to type or variable
+  declarations. Using an attributed type or variable in an arithmetic
+  expression will define the overflow behavior for that expression as having
+  two's complement wrap-around. These expressions cannot trigger integer
+  overflow warnings or sanitizer warnings. They also cannot be optimized away
+  by some eager UB optimizations.
+
+  This attribute is ignored in C++.
+
 Improvements to Clang's diagnostics
 ---
 - Clang now applies syntax highlighting to the code snippets it
diff --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h
index 2bfefeabc348be..68cd7d7c0fac3b 100644
--- a/clang/include/clang/AST/Expr.h
+++ b/clang/include/clang/AST/Expr.h
@@ -4077,6 +4077,9 @@ class BinaryOperator : public Expr {
   static unsigned sizeOfTrailingObjects(bool HasFPFeatures) {
 return HasFPFeatures * sizeof(FPOptionsOverride);
   }
+
+  /// Do one of the subexpressions have the wraps attribute?
+  bool oneOfWraps(const ASTContext ) const;
 };
 
 /// CompoundAssignOperator - For compound assignments (e.g. +=), we keep
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index dc87a8c6f022dc..06e41fcee206c4 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -4506,3 +4506,9 @@ def CodeAlign: StmtAttr {
 static constexpr int MaximumAlignment = 4096;
   }];
 }
+
+def Wraps : DeclOrTypeAttr {
+  let Spellings = [Clang<"wraps">, CXX11<"", "wraps", 202403>];
+  let Subjects = SubjectList<[Var, TypedefName, Field]>;
+  let Documentation = [WrapsDocs];
+}
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index a0bbe5861c5722..5f6e5a8de79954 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -8057,3 +8057,69 @@ requirement:
   }
   }];
 }
+
+def WrapsDocs : Documentation {
+  let Category = DocCatField;
+  let Content = [{
+This attribute can be used with type or variable declarations to denote that
+arithmetic containing these marked components have defined overflow behavior.
+Specifically, the behavior is defined as being consistent with two's complement
+wrap-around. For the purposes of sanitizers or warnings that concern themselves
+with the definedness of integer arithmetic, they will cease to instrument or
+warn about arithmetic that directly involves a "wrapping" component.
+
+For example, ``-fsanitize=signed-integer-overflow`` or ``-Winteger-overflow``
+will not warn about suspicious overflowing arithmetic -- assuming correct usage
+of the wraps attribute.
+
+This example shows some basic usage of ``__attribute__((wraps))`` on a type
+definition when building with ``-fsanitize=signed-integer-overflow``
+
+.. code-block:: c
+  typedef int __attribute__((wraps)) wrapping_int;
+
+  void foo() {
+wrapping_int a = INT_MAX;
+++a; // no sanitizer warning
+  }
+
+  int main() { foo(); }
+
+In the following example, we use ``__attribute__((wraps))`` on a variable to
+disable overflow instrumentation for arithmetic expressions it appears in. We
+do so with a popular overflow-checking pattern which we might not want to trip
+sanitizers (like ``-fsanitize=unsigned-integer-overflow``).
+

[clang] [Clang] Add wraps attribute (for granular integer overflow handling) (PR #86618)

2024-04-22 Thread Justin Stitt via cfe-commits


@@ -4249,6 +4270,10 @@ Value *ScalarExprEmitter::EmitFixedPointBinOp(const 
BinOpInfo ) {
 Value *ScalarExprEmitter::EmitSub(const BinOpInfo ) {
   // The LHS is always a pointer if either side is.
   if (!op.LHS->getType()->isPointerTy()) {
+if ((op.Ty->isSignedIntegerOrEnumerationType() ||

JustinStitt wrote:

Yep, fixed with 
[872e5d6](https://github.com/llvm/llvm-project/pull/86618/commits/872e5d6a2791c7de1268ff3d0bc090578f42067c)
 alongside a fix to EmitMul

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


[clang] [Clang] Add wraps attribute (for granular integer overflow handling) (PR #86618)

2024-04-22 Thread Justin Stitt via cfe-commits


@@ -4455,6 +4455,14 @@ void Sema::AddAlignValueAttr(Decl *D, const 
AttributeCommonInfo , Expr *E) {
   D->addAttr(::new (Context) AlignValueAttr(Context, CI, E));
 }
 
+static void handleWrapsAttr(Sema , Decl *D, const ParsedAttr ) {
+  S.AddWrapsAttr(D, AL);
+}
+
+void Sema::AddWrapsAttr(Decl *D, const AttributeCommonInfo ) {

JustinStitt wrote:

gotcha, fixed in 
[872e5d6](https://github.com/llvm/llvm-project/pull/86618/commits/872e5d6a2791c7de1268ff3d0bc090578f42067c)

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


[clang] [Clang] Add wraps attribute (for granular integer overflow handling) (PR #86618)

2024-04-22 Thread Justin Stitt via cfe-commits


@@ -4093,6 +4109,11 @@ Value *ScalarExprEmitter::EmitAdd(const BinOpInfo ) {
   op.RHS->getType()->isPointerTy())
 return emitPointerArithmetic(CGF, op, CodeGenFunction::NotSubtraction);
 
+  if ((op.Ty->isSignedIntegerOrEnumerationType() ||

JustinStitt wrote:

fixed in 
[872e5d6](https://github.com/llvm/llvm-project/pull/86618/commits/872e5d6a2791c7de1268ff3d0bc090578f42067c)
 (I went with just removing the early return clauses)

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


[clang] [Clang] Add wraps attribute (for granular integer overflow handling) (PR #86618)

2024-04-22 Thread Justin Stitt via cfe-commits


@@ -2831,6 +2840,9 @@ ScalarExprEmitter::EmitScalarPrePostIncDec(const 
UnaryOperator *E, LValue LV,
   } else if (type->isIntegerType()) {
 QualType promotedType;
 bool canPerformLossyDemotionCheck = false;
+BinOpInfo Ops = (createBinOpInfoFromIncDec(

JustinStitt wrote:

fixed in 
[872e5d6](https://github.com/llvm/llvm-project/pull/86618/commits/872e5d6a2791c7de1268ff3d0bc090578f42067c)

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


[clang] [Clang] Add wraps attribute (for granular integer overflow handling) (PR #86618)

2024-04-22 Thread Justin Stitt via cfe-commits


@@ -156,6 +156,10 @@ struct BinOpInfo {
 }
 return false;
   }
+
+  /// Does the BinaryOperator have the wraps attribute?
+  /// If so, we can ellide overflow sanitizer checks.

JustinStitt wrote:

fixed in 
[872e5d6](https://github.com/llvm/llvm-project/pull/86618/commits/872e5d6a2791c7de1268ff3d0bc090578f42067c)

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


[clang] [Clang] Add wraps attribute (for granular integer overflow handling) (PR #86618)

2024-04-22 Thread Justin Stitt via cfe-commits


@@ -4077,6 +4077,9 @@ class BinaryOperator : public Expr {
   static unsigned sizeOfTrailingObjects(bool HasFPFeatures) {
 return HasFPFeatures * sizeof(FPOptionsOverride);
   }
+
+  /// Do one of the subexpressions have the wraps attribute?

JustinStitt wrote:

fixed in 
[872e5d6](https://github.com/llvm/llvm-project/pull/86618/commits/872e5d6a2791c7de1268ff3d0bc090578f42067c)

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


[clang] [Clang] Add wraps attribute (for granular integer overflow handling) (PR #86618)

2024-04-22 Thread Justin Stitt via cfe-commits

https://github.com/JustinStitt updated 
https://github.com/llvm/llvm-project/pull/86618

>From 50e7b1039e514dacc05bb8cd9ff9a3e3df9ed24d Mon Sep 17 00:00:00 2001
From: Justin Stitt 
Date: Tue, 5 Mar 2024 03:14:49 +
Subject: [PATCH 01/12] implement wraps attribute

Signed-off-by: Justin Stitt 
---
 clang/docs/ReleaseNotes.rst   |  9 +++
 clang/include/clang/AST/Expr.h|  3 +
 clang/include/clang/Basic/Attr.td |  6 ++
 clang/include/clang/Basic/AttrDocs.td | 66 +++
 .../clang/Basic/DiagnosticSemaKinds.td|  3 +
 clang/include/clang/Sema/Sema.h   |  4 ++
 clang/lib/AST/Expr.cpp| 19 ++
 clang/lib/AST/ExprConstant.cpp|  6 +-
 clang/lib/AST/TypePrinter.cpp |  3 +
 clang/lib/CodeGen/CGExprScalar.cpp| 40 +--
 clang/lib/Sema/SemaDeclAttr.cpp   | 12 +++-
 clang/lib/Sema/SemaType.cpp   | 15 +
 clang/test/CodeGen/integer-overflow.c | 56 
 clang/test/CodeGen/unsigned-overflow.c| 63 +++---
 clang/test/Sema/attr-wraps.c  |  9 +++
 15 files changed, 298 insertions(+), 16 deletions(-)
 create mode 100644 clang/test/Sema/attr-wraps.c

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 2b3bafa1c30548..fa7acb894cd76f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -296,6 +296,15 @@ Attribute Changes in Clang
 - Clang now warns that the ``exclude_from_explicit_instantiation`` attribute
   is ignored when applied to a local class or a member thereof.
 
+- Introduced ``__attribute((wraps))__`` which can be added to type or variable
+  declarations. Using an attributed type or variable in an arithmetic
+  expression will define the overflow behavior for that expression as having
+  two's complement wrap-around. These expressions cannot trigger integer
+  overflow warnings or sanitizer warnings. They also cannot be optimized away
+  by some eager UB optimizations.
+
+  This attribute is ignored in C++.
+
 Improvements to Clang's diagnostics
 ---
 - Clang now applies syntax highlighting to the code snippets it
diff --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h
index 2bfefeabc348be..68cd7d7c0fac3b 100644
--- a/clang/include/clang/AST/Expr.h
+++ b/clang/include/clang/AST/Expr.h
@@ -4077,6 +4077,9 @@ class BinaryOperator : public Expr {
   static unsigned sizeOfTrailingObjects(bool HasFPFeatures) {
 return HasFPFeatures * sizeof(FPOptionsOverride);
   }
+
+  /// Do one of the subexpressions have the wraps attribute?
+  bool oneOfWraps(const ASTContext ) const;
 };
 
 /// CompoundAssignOperator - For compound assignments (e.g. +=), we keep
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index dc87a8c6f022dc..06e41fcee206c4 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -4506,3 +4506,9 @@ def CodeAlign: StmtAttr {
 static constexpr int MaximumAlignment = 4096;
   }];
 }
+
+def Wraps : DeclOrTypeAttr {
+  let Spellings = [Clang<"wraps">, CXX11<"", "wraps", 202403>];
+  let Subjects = SubjectList<[Var, TypedefName, Field]>;
+  let Documentation = [WrapsDocs];
+}
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index a0bbe5861c5722..5f6e5a8de79954 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -8057,3 +8057,69 @@ requirement:
   }
   }];
 }
+
+def WrapsDocs : Documentation {
+  let Category = DocCatField;
+  let Content = [{
+This attribute can be used with type or variable declarations to denote that
+arithmetic containing these marked components have defined overflow behavior.
+Specifically, the behavior is defined as being consistent with two's complement
+wrap-around. For the purposes of sanitizers or warnings that concern themselves
+with the definedness of integer arithmetic, they will cease to instrument or
+warn about arithmetic that directly involves a "wrapping" component.
+
+For example, ``-fsanitize=signed-integer-overflow`` or ``-Winteger-overflow``
+will not warn about suspicious overflowing arithmetic -- assuming correct usage
+of the wraps attribute.
+
+This example shows some basic usage of ``__attribute__((wraps))`` on a type
+definition when building with ``-fsanitize=signed-integer-overflow``
+
+.. code-block:: c
+  typedef int __attribute__((wraps)) wrapping_int;
+
+  void foo() {
+wrapping_int a = INT_MAX;
+++a; // no sanitizer warning
+  }
+
+  int main() { foo(); }
+
+In the following example, we use ``__attribute__((wraps))`` on a variable to
+disable overflow instrumentation for arithmetic expressions it appears in. We
+do so with a popular overflow-checking pattern which we might not want to trip
+sanitizers (like ``-fsanitize=unsigned-integer-overflow``).
+

[clang] [lld] [llvm] [RISCV] Split code that tablegen needs out of RISCVISAInfo. (PR #89684)

2024-04-22 Thread Craig Topper via cfe-commits

https://github.com/topperc updated 
https://github.com/llvm/llvm-project/pull/89684

>From fc51e3821787f1ae8dcb344d4def0ef342ae473b Mon Sep 17 00:00:00 2001
From: Craig Topper 
Date: Thu, 18 Apr 2024 16:47:31 -0700
Subject: [PATCH 1/8] [RISCV][TableGen] Generate RISCVTargetParser.inc from the
 new RISCVExtension tblgen information.

Instead of using RISCVISAInfo's extension information, use the
extension found in tblgen after #89326.

We still need to use RISCVISAInfo code to get the sorting rules for
the ISA string.

The ISA string we generate now is not quite the same extension we
had before. No implied extensions are included in the generate string
unless they are explicitly listed in RISCVProcessors.td. This primarily
affects Zicsr being implied by F, V implying Zve*, and Zvl*b implying a
smaller Zvl*b. All of these implication should be picked up when the
string is used by the frontend.

The benefit is that we get a more manageable ISA string for humans to
deal with.

This is a step towards generating RISCVISAInfo's extension list from
tblgen.
---
 llvm/utils/TableGen/RISCVTargetDefEmitter.cpp | 43 ++-
 1 file changed, 23 insertions(+), 20 deletions(-)

diff --git a/llvm/utils/TableGen/RISCVTargetDefEmitter.cpp 
b/llvm/utils/TableGen/RISCVTargetDefEmitter.cpp
index 62916bd62c0119..4f840b4227e45b 100644
--- a/llvm/utils/TableGen/RISCVTargetDefEmitter.cpp
+++ b/llvm/utils/TableGen/RISCVTargetDefEmitter.cpp
@@ -17,34 +17,34 @@
 
 using namespace llvm;
 
-using ISAInfoTy = llvm::Expected>;
-
 // We can generate march string from target features as what has been described
 // in RISC-V ISA specification (version 20191213) 'Chapter 27. ISA Extension
 // Naming Conventions'.
 //
 // This is almost the same as RISCVFeatures::parseFeatureBits, except that we
 // get feature name from feature records instead of feature bits.
-static std::string getMArch(const Record ) {
-  std::vector FeatureVector;
+static void printMArch(raw_ostream , const Record ) {
+  std::map,
+   RISCVISAInfo::ExtensionComparator>
+  Extensions;
   unsigned XLen = 32;
 
   // Convert features to FeatureVector.
   for (auto *Feature : Rec.getValueAsListOfDefs("Features")) {
 StringRef FeatureName = Feature->getValueAsString("Name");
-if (llvm::RISCVISAInfo::isSupportedExtensionFeature(FeatureName))
-  FeatureVector.push_back((Twine("+") + FeatureName).str());
-else if (FeatureName == "64bit")
+if (Feature->isSubClassOf("RISCVExtension")) {
+  unsigned Major = Feature->getValueAsInt("MajorVersion");
+  unsigned Minor = Feature->getValueAsInt("MinorVersion");
+  Extensions.try_emplace(FeatureName.str(), Major, Minor);
+} else if (FeatureName == "64bit")
   XLen = 64;
   }
 
-  ISAInfoTy ISAInfo = llvm::RISCVISAInfo::parseFeatures(XLen, FeatureVector);
-  if (!ISAInfo)
-report_fatal_error("Invalid features");
+  OS << "rv" << XLen;
 
-  // RISCVISAInfo::toString will generate a march string with all the 
extensions
-  // we have added to it.
-  return (*ISAInfo)->toString();
+  ListSeparator LS("_");
+  for (auto const  : Extensions)
+OS << LS << Ext.first << Ext.second.first << 'p' << Ext.second.second;
 }
 
 static void EmitRISCVTargetDef(RecordKeeper , raw_ostream ) {
@@ -54,12 +54,6 @@ static void EmitRISCVTargetDef(RecordKeeper , raw_ostream 
) {
 
   // Iterate on all definition records.
   for (const Record *Rec : RK.getAllDerivedDefinitions("RISCVProcessorModel")) 
{
-std::string MArch = Rec->getValueAsString("DefaultMarch").str();
-
-// Compute MArch from features if we don't specify it.
-if (MArch.empty())
-  MArch = getMArch(*Rec);
-
 bool FastScalarUnalignedAccess =
 any_of(Rec->getValueAsListOfDefs("Features"), [&](auto ) {
   return Feature->getValueAsString("Name") == "unaligned-scalar-mem";
@@ -75,7 +69,16 @@ static void EmitRISCVTargetDef(RecordKeeper , raw_ostream 
) {
 
 OS << "PROC(" << Rec->getName() << ", "
<< "{\"" << Rec->getValueAsString("Name") << "\"}, "
-   << "{\"" << MArch << "\"}, " << FastUnalignedAccess << ")\n";
+   << "{\"";
+
+StringRef MArch = Rec->getValueAsString("DefaultMarch");
+
+// Compute MArch from features if we don't specify it.
+if (MArch.empty())
+  printMArch(OS, *Rec);
+else
+  OS << MArch;
+OS << "\"}, " << FastUnalignedAccess << ")\n";
   }
   OS << "\n#undef PROC\n";
   OS << "\n";

>From 815a63b99de61b8b1fde5a8c831f63d8810134db Mon Sep 17 00:00:00 2001
From: Craig Topper 
Date: Thu, 18 Apr 2024 17:10:50 -0700
Subject: [PATCH 2/8] fixup! clang-format

---
 llvm/utils/TableGen/RISCVTargetDefEmitter.cpp | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/llvm/utils/TableGen/RISCVTargetDefEmitter.cpp 
b/llvm/utils/TableGen/RISCVTargetDefEmitter.cpp
index 4f840b4227e45b..9862a610bab4d7 100644
--- a/llvm/utils/TableGen/RISCVTargetDefEmitter.cpp
+++ b/llvm/utils/TableGen/RISCVTargetDefEmitter.cpp
@@ -67,9 +67,8 @@ 

[clang] [lld] [llvm] [RISCV] Split code that tablegen needs out of RISCVISAInfo. (PR #89684)

2024-04-22 Thread via cfe-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff 92631a4824a91f3268a5716dd3459df8dc6bfb63 
ee9180aff45af55797d2e97c1b65f9c35b5c8a24 -- 
llvm/include/llvm/Support/RISCVISAUtils.h llvm/lib/Support/RISCVISAUtils.cpp 
clang/lib/Basic/Targets/RISCV.h clang/lib/CodeGen/CodeGenModule.cpp 
clang/lib/Driver/Driver.cpp clang/lib/Driver/ToolChains/Arch/RISCV.cpp 
clang/lib/Driver/ToolChains/Clang.cpp clang/lib/Driver/ToolChains/Flang.cpp 
clang/lib/Driver/ToolChains/Gnu.cpp clang/tools/driver/cc1_main.cpp 
lld/ELF/Arch/RISCV.cpp llvm/lib/Object/ELFObjectFile.cpp 
llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp 
llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.cpp 
llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h 
llvm/lib/Target/RISCV/MCTargetDesc/RISCVTargetStreamer.cpp 
llvm/lib/Target/RISCV/RISCVAsmPrinter.cpp 
llvm/lib/TargetParser/RISCVTargetParser.cpp 
llvm/unittests/Support/RISCVISAInfoTest.cpp 
llvm/utils/TableGen/RISCVTargetDefEmitter.cpp 
llvm/include/llvm/TargetParser/RISCVISAInfo.h 
llvm/lib/TargetParser/RISCVISAInfo.cpp
``





View the diff from clang-format here.


``diff
diff --git a/llvm/lib/TargetParser/RISCVISAInfo.cpp 
b/llvm/lib/TargetParser/RISCVISAInfo.cpp
index c103449f80..30fb35ce70 100644
--- a/llvm/lib/TargetParser/RISCVISAInfo.cpp
+++ b/llvm/lib/TargetParser/RISCVISAInfo.cpp
@@ -43,9 +43,8 @@ struct RISCVProfile {
 
 } // end anonymous namespace
 
-static const char *RISCVGImplications[] = {
-  "i", "m", "a", "f", "d", "zicsr", "zifencei"
-};
+static const char *RISCVGImplications[] = {"i", "m", "a",   "f",
+   "d", "zicsr", "zifencei"};
 
 // NOTE: This table should be sorted alphabetically by extension name.
 static const RISCVSupportedExtension SupportedExtensions[] = {
@@ -1018,11 +1017,11 @@ Error RISCVISAInfo::checkDependency() {
 
   if ((HasZcmt || Exts.count("zcmp")) && Exts.count("d") &&
   (HasC || Exts.count("zcd")))
-return createStringError(
-errc::invalid_argument,
-Twine("'") + (HasZcmt ? "zcmt" : "zcmp") +
-"' extension is incompatible with '" + (HasC ? "c" : "zcd") +
-"' extension when 'd' extension is enabled");
+return createStringError(errc::invalid_argument,
+ Twine("'") + (HasZcmt ? "zcmt" : "zcmp") +
+ "' extension is incompatible with '" +
+ (HasC ? "c" : "zcd") +
+ "' extension when 'd' extension is enabled");
 
   if (XLen != 32 && Exts.count("zcf"))
 return createStringError(errc::invalid_argument,
@@ -1217,14 +1216,10 @@ struct CombinedExtsEntry {
 };
 
 static constexpr CombinedExtsEntry CombineIntoExts[] = {
-{{"zk"}, {ImpliedExtsZk}},
-{{"zkn"}, {ImpliedExtsZkn}},
-{{"zks"}, {ImpliedExtsZks}},
-{{"zvkn"}, {ImpliedExtsZvkn}},
-{{"zvknc"}, {ImpliedExtsZvknc}},
-{{"zvkng"}, {ImpliedExtsZvkng}},
-{{"zvks"}, {ImpliedExtsZvks}},
-{{"zvksc"}, {ImpliedExtsZvksc}},
+{{"zk"}, {ImpliedExtsZk}},   {{"zkn"}, {ImpliedExtsZkn}},
+{{"zks"}, {ImpliedExtsZks}}, {{"zvkn"}, {ImpliedExtsZvkn}},
+{{"zvknc"}, {ImpliedExtsZvknc}}, {{"zvkng"}, {ImpliedExtsZvkng}},
+{{"zvks"}, {ImpliedExtsZvks}},   {{"zvksc"}, {ImpliedExtsZvksc}},
 {{"zvksg"}, {ImpliedExtsZvksg}},
 };
 

``




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


[clang] [Clang] Add wraps attribute (for granular integer overflow handling) (PR #86618)

2024-04-22 Thread Justin Stitt via cfe-commits

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


[clang] [Clang] Add wraps attribute (for granular integer overflow handling) (PR #86618)

2024-04-22 Thread Justin Stitt via cfe-commits


@@ -4093,6 +4109,11 @@ Value *ScalarExprEmitter::EmitAdd(const BinOpInfo ) {
   op.RHS->getType()->isPointerTy())
 return emitPointerArithmetic(CGF, op, CodeGenFunction::NotSubtraction);
 
+  if ((op.Ty->isSignedIntegerOrEnumerationType() ||

JustinStitt wrote:

It can't just be flat out removed, if that's what you're asking. An alternative 
would be a few additions to existing if-statements resulting in about the same 
level of readability.

Specifically a diff like this should perform the same:

```diff
diff --git a/clang/lib/CodeGen/CGExprScalar.cpp 
b/clang/lib/CodeGen/CGExprScalar.cpp
index 70b3849240cd..3f6bac748506 100644
--- a/clang/lib/CodeGen/CGExprScalar.cpp
+++ b/clang/lib/CodeGen/CGExprScalar.cpp
@@ -4109,12 +4109,7 @@ Value *ScalarExprEmitter::EmitAdd(const BinOpInfo ) {
   op.RHS->getType()->isPointerTy())
 return emitPointerArithmetic(CGF, op, CodeGenFunction::NotSubtraction);
 
-  if ((op.Ty->isSignedIntegerOrEnumerationType() ||
-   op.Ty->isUnsignedIntegerType()) &&
-  op.hasWrappingOperand())
-return Builder.CreateAdd(op.LHS, op.RHS, "add");
-
-  if (op.Ty->isSignedIntegerOrEnumerationType()) {
+  if (op.Ty->isSignedIntegerOrEnumerationType() && !op.hasWrappingOperand()) {
 switch (CGF.getLangOpts().getSignedOverflowBehavior()) {
 case LangOptions::SOB_Defined:
   if (!CGF.SanOpts.has(SanitizerKind::SignedIntegerOverflow))
@@ -4147,7 +4142,7 @@ Value *ScalarExprEmitter::EmitAdd(const BinOpInfo ) {
 
   if (op.Ty->isUnsignedIntegerType() &&
   CGF.SanOpts.has(SanitizerKind::UnsignedIntegerOverflow) &&
-  !CanElideOverflowCheck(CGF.getContext(), op))
+  !CanElideOverflowCheck(CGF.getContext(), op) && !op.hasWrappingOperand())
 return EmitOverflowCheckedBinOp(op);
 
   if (op.LHS->getType()->isFPOrFPVectorTy()) {

```


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


[clang] [lld] [llvm] [RISCV] Split code that tablegen needs out of RISCVISAInfo. (PR #89684)

2024-04-22 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-lld-elf

Author: Craig Topper (topperc)


Changes

This introduces a new file, RISCVISAUtils.cpp and moves the rest of 
RISCVISAInfo to the TargetParser library.

This will allow us to generate part of RISCVISAInfo.cpp using tablegen.

---

Patch is 43.02 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/89684.diff


25 Files Affected:

- (modified) clang/lib/Basic/Targets/RISCV.h (+1-1) 
- (modified) clang/lib/CodeGen/CodeGenModule.cpp (+1-1) 
- (modified) clang/lib/Driver/Driver.cpp (+1-1) 
- (modified) clang/lib/Driver/ToolChains/Arch/RISCV.cpp (+1-1) 
- (modified) clang/lib/Driver/ToolChains/Clang.cpp (+1-1) 
- (modified) clang/lib/Driver/ToolChains/Flang.cpp (+1-1) 
- (modified) clang/lib/Driver/ToolChains/Gnu.cpp (+1-1) 
- (modified) clang/tools/driver/cc1_main.cpp (+1-1) 
- (modified) lld/ELF/Arch/RISCV.cpp (+1-1) 
- (added) llvm/include/llvm/Support/RISCVISAUtils.h (+42) 
- (renamed) llvm/include/llvm/TargetParser/RISCVISAInfo.h (+4-17) 
- (modified) llvm/lib/Object/ELFObjectFile.cpp (+1-1) 
- (modified) llvm/lib/Support/CMakeLists.txt (+1-1) 
- (added) llvm/lib/Support/RISCVISAUtils.cpp (+88) 
- (modified) llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp (+1-1) 
- (modified) llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.cpp (-1) 
- (modified) llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h (+1-1) 
- (modified) llvm/lib/Target/RISCV/MCTargetDesc/RISCVTargetStreamer.cpp (+1-1) 
- (modified) llvm/lib/Target/RISCV/RISCVAsmPrinter.cpp (+1-1) 
- (modified) llvm/lib/TargetParser/CMakeLists.txt (+1) 
- (renamed) llvm/lib/TargetParser/RISCVISAInfo.cpp (+11-85) 
- (modified) llvm/lib/TargetParser/RISCVTargetParser.cpp (+1-1) 
- (added) llvm/test/TableGen/riscv-target-def.td (+96) 
- (modified) llvm/unittests/Support/RISCVISAInfoTest.cpp (+37-37) 
- (modified) llvm/utils/TableGen/RISCVTargetDefEmitter.cpp (+33-24) 


``diff
diff --git a/clang/lib/Basic/Targets/RISCV.h b/clang/lib/Basic/Targets/RISCV.h
index 78580b5b1c1063..9fa42e75bbfd14 100644
--- a/clang/lib/Basic/Targets/RISCV.h
+++ b/clang/lib/Basic/Targets/RISCV.h
@@ -16,7 +16,7 @@
 #include "clang/Basic/TargetInfo.h"
 #include "clang/Basic/TargetOptions.h"
 #include "llvm/Support/Compiler.h"
-#include "llvm/Support/RISCVISAInfo.h"
+#include "llvm/TargetParser/RISCVISAInfo.h"
 #include "llvm/TargetParser/Triple.h"
 #include 
 
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 0c447b20cef40d..d085e735ecb443 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -68,9 +68,9 @@
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/ConvertUTF.h"
 #include "llvm/Support/ErrorHandling.h"
-#include "llvm/Support/RISCVISAInfo.h"
 #include "llvm/Support/TimeProfiler.h"
 #include "llvm/Support/xxhash.h"
+#include "llvm/TargetParser/RISCVISAInfo.h"
 #include "llvm/TargetParser/Triple.h"
 #include "llvm/TargetParser/X86TargetParser.h"
 #include 
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 0da92001e08c27..76b7b9fdfb4f9b 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -87,12 +87,12 @@
 #include "llvm/Support/PrettyStackTrace.h"
 #include "llvm/Support/Process.h"
 #include "llvm/Support/Program.h"
-#include "llvm/Support/RISCVISAInfo.h"
 #include "llvm/Support/Regex.h"
 #include "llvm/Support/StringSaver.h"
 #include "llvm/Support/VirtualFileSystem.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/TargetParser/Host.h"
+#include "llvm/TargetParser/RISCVISAInfo.h"
 #include  // ::getenv
 #include 
 #include 
diff --git a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp 
b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
index 96b3cc3bb8ffb1..2e2bce8494672f 100644
--- a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
@@ -15,9 +15,9 @@
 #include "clang/Driver/Options.h"
 #include "llvm/Option/ArgList.h"
 #include "llvm/Support/Error.h"
-#include "llvm/Support/RISCVISAInfo.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/TargetParser/Host.h"
+#include "llvm/TargetParser/RISCVISAInfo.h"
 #include "llvm/TargetParser/RISCVTargetParser.h"
 
 using namespace clang::driver;
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index f8a81ee8ab56bc..e43da1e78d9ef5 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -54,11 +54,11 @@
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Process.h"
-#include "llvm/Support/RISCVISAInfo.h"
 #include "llvm/Support/YAMLParser.h"
 #include "llvm/TargetParser/ARMTargetParserCommon.h"
 #include "llvm/TargetParser/Host.h"
 #include "llvm/TargetParser/LoongArchTargetParser.h"
+#include "llvm/TargetParser/RISCVISAInfo.h"
 #include "llvm/TargetParser/RISCVTargetParser.h"
 #include 
 
diff --git 

[clang] [lld] [llvm] [RISCV] Split code that tablegen needs out of RISCVISAInfo. (PR #89684)

2024-04-22 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Craig Topper (topperc)


Changes

This introduces a new file, RISCVISAUtils.cpp and moves the rest of 
RISCVISAInfo to the TargetParser library.

This will allow us to generate part of RISCVISAInfo.cpp using tablegen.

---

Patch is 43.02 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/89684.diff


25 Files Affected:

- (modified) clang/lib/Basic/Targets/RISCV.h (+1-1) 
- (modified) clang/lib/CodeGen/CodeGenModule.cpp (+1-1) 
- (modified) clang/lib/Driver/Driver.cpp (+1-1) 
- (modified) clang/lib/Driver/ToolChains/Arch/RISCV.cpp (+1-1) 
- (modified) clang/lib/Driver/ToolChains/Clang.cpp (+1-1) 
- (modified) clang/lib/Driver/ToolChains/Flang.cpp (+1-1) 
- (modified) clang/lib/Driver/ToolChains/Gnu.cpp (+1-1) 
- (modified) clang/tools/driver/cc1_main.cpp (+1-1) 
- (modified) lld/ELF/Arch/RISCV.cpp (+1-1) 
- (added) llvm/include/llvm/Support/RISCVISAUtils.h (+42) 
- (renamed) llvm/include/llvm/TargetParser/RISCVISAInfo.h (+4-17) 
- (modified) llvm/lib/Object/ELFObjectFile.cpp (+1-1) 
- (modified) llvm/lib/Support/CMakeLists.txt (+1-1) 
- (added) llvm/lib/Support/RISCVISAUtils.cpp (+88) 
- (modified) llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp (+1-1) 
- (modified) llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.cpp (-1) 
- (modified) llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h (+1-1) 
- (modified) llvm/lib/Target/RISCV/MCTargetDesc/RISCVTargetStreamer.cpp (+1-1) 
- (modified) llvm/lib/Target/RISCV/RISCVAsmPrinter.cpp (+1-1) 
- (modified) llvm/lib/TargetParser/CMakeLists.txt (+1) 
- (renamed) llvm/lib/TargetParser/RISCVISAInfo.cpp (+11-85) 
- (modified) llvm/lib/TargetParser/RISCVTargetParser.cpp (+1-1) 
- (added) llvm/test/TableGen/riscv-target-def.td (+96) 
- (modified) llvm/unittests/Support/RISCVISAInfoTest.cpp (+37-37) 
- (modified) llvm/utils/TableGen/RISCVTargetDefEmitter.cpp (+33-24) 


``diff
diff --git a/clang/lib/Basic/Targets/RISCV.h b/clang/lib/Basic/Targets/RISCV.h
index 78580b5b1c1063..9fa42e75bbfd14 100644
--- a/clang/lib/Basic/Targets/RISCV.h
+++ b/clang/lib/Basic/Targets/RISCV.h
@@ -16,7 +16,7 @@
 #include "clang/Basic/TargetInfo.h"
 #include "clang/Basic/TargetOptions.h"
 #include "llvm/Support/Compiler.h"
-#include "llvm/Support/RISCVISAInfo.h"
+#include "llvm/TargetParser/RISCVISAInfo.h"
 #include "llvm/TargetParser/Triple.h"
 #include 
 
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 0c447b20cef40d..d085e735ecb443 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -68,9 +68,9 @@
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/ConvertUTF.h"
 #include "llvm/Support/ErrorHandling.h"
-#include "llvm/Support/RISCVISAInfo.h"
 #include "llvm/Support/TimeProfiler.h"
 #include "llvm/Support/xxhash.h"
+#include "llvm/TargetParser/RISCVISAInfo.h"
 #include "llvm/TargetParser/Triple.h"
 #include "llvm/TargetParser/X86TargetParser.h"
 #include 
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 0da92001e08c27..76b7b9fdfb4f9b 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -87,12 +87,12 @@
 #include "llvm/Support/PrettyStackTrace.h"
 #include "llvm/Support/Process.h"
 #include "llvm/Support/Program.h"
-#include "llvm/Support/RISCVISAInfo.h"
 #include "llvm/Support/Regex.h"
 #include "llvm/Support/StringSaver.h"
 #include "llvm/Support/VirtualFileSystem.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/TargetParser/Host.h"
+#include "llvm/TargetParser/RISCVISAInfo.h"
 #include  // ::getenv
 #include 
 #include 
diff --git a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp 
b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
index 96b3cc3bb8ffb1..2e2bce8494672f 100644
--- a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
@@ -15,9 +15,9 @@
 #include "clang/Driver/Options.h"
 #include "llvm/Option/ArgList.h"
 #include "llvm/Support/Error.h"
-#include "llvm/Support/RISCVISAInfo.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/TargetParser/Host.h"
+#include "llvm/TargetParser/RISCVISAInfo.h"
 #include "llvm/TargetParser/RISCVTargetParser.h"
 
 using namespace clang::driver;
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index f8a81ee8ab56bc..e43da1e78d9ef5 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -54,11 +54,11 @@
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Process.h"
-#include "llvm/Support/RISCVISAInfo.h"
 #include "llvm/Support/YAMLParser.h"
 #include "llvm/TargetParser/ARMTargetParserCommon.h"
 #include "llvm/TargetParser/Host.h"
 #include "llvm/TargetParser/LoongArchTargetParser.h"
+#include "llvm/TargetParser/RISCVISAInfo.h"
 #include "llvm/TargetParser/RISCVTargetParser.h"
 #include 
 
diff --git 

[clang] [lld] [llvm] [RISCV] Split code that tablegen needs out of RISCVISAInfo. (PR #89684)

2024-04-22 Thread Craig Topper via cfe-commits

https://github.com/topperc created 
https://github.com/llvm/llvm-project/pull/89684

This introduces a new file, RISCVISAUtils.cpp and moves the rest of 
RISCVISAInfo to the TargetParser library.

This will allow us to generate part of RISCVISAInfo.cpp using tablegen.

>From fc51e3821787f1ae8dcb344d4def0ef342ae473b Mon Sep 17 00:00:00 2001
From: Craig Topper 
Date: Thu, 18 Apr 2024 16:47:31 -0700
Subject: [PATCH 1/7] [RISCV][TableGen] Generate RISCVTargetParser.inc from the
 new RISCVExtension tblgen information.

Instead of using RISCVISAInfo's extension information, use the
extension found in tblgen after #89326.

We still need to use RISCVISAInfo code to get the sorting rules for
the ISA string.

The ISA string we generate now is not quite the same extension we
had before. No implied extensions are included in the generate string
unless they are explicitly listed in RISCVProcessors.td. This primarily
affects Zicsr being implied by F, V implying Zve*, and Zvl*b implying a
smaller Zvl*b. All of these implication should be picked up when the
string is used by the frontend.

The benefit is that we get a more manageable ISA string for humans to
deal with.

This is a step towards generating RISCVISAInfo's extension list from
tblgen.
---
 llvm/utils/TableGen/RISCVTargetDefEmitter.cpp | 43 ++-
 1 file changed, 23 insertions(+), 20 deletions(-)

diff --git a/llvm/utils/TableGen/RISCVTargetDefEmitter.cpp 
b/llvm/utils/TableGen/RISCVTargetDefEmitter.cpp
index 62916bd62c0119..4f840b4227e45b 100644
--- a/llvm/utils/TableGen/RISCVTargetDefEmitter.cpp
+++ b/llvm/utils/TableGen/RISCVTargetDefEmitter.cpp
@@ -17,34 +17,34 @@
 
 using namespace llvm;
 
-using ISAInfoTy = llvm::Expected>;
-
 // We can generate march string from target features as what has been described
 // in RISC-V ISA specification (version 20191213) 'Chapter 27. ISA Extension
 // Naming Conventions'.
 //
 // This is almost the same as RISCVFeatures::parseFeatureBits, except that we
 // get feature name from feature records instead of feature bits.
-static std::string getMArch(const Record ) {
-  std::vector FeatureVector;
+static void printMArch(raw_ostream , const Record ) {
+  std::map,
+   RISCVISAInfo::ExtensionComparator>
+  Extensions;
   unsigned XLen = 32;
 
   // Convert features to FeatureVector.
   for (auto *Feature : Rec.getValueAsListOfDefs("Features")) {
 StringRef FeatureName = Feature->getValueAsString("Name");
-if (llvm::RISCVISAInfo::isSupportedExtensionFeature(FeatureName))
-  FeatureVector.push_back((Twine("+") + FeatureName).str());
-else if (FeatureName == "64bit")
+if (Feature->isSubClassOf("RISCVExtension")) {
+  unsigned Major = Feature->getValueAsInt("MajorVersion");
+  unsigned Minor = Feature->getValueAsInt("MinorVersion");
+  Extensions.try_emplace(FeatureName.str(), Major, Minor);
+} else if (FeatureName == "64bit")
   XLen = 64;
   }
 
-  ISAInfoTy ISAInfo = llvm::RISCVISAInfo::parseFeatures(XLen, FeatureVector);
-  if (!ISAInfo)
-report_fatal_error("Invalid features");
+  OS << "rv" << XLen;
 
-  // RISCVISAInfo::toString will generate a march string with all the 
extensions
-  // we have added to it.
-  return (*ISAInfo)->toString();
+  ListSeparator LS("_");
+  for (auto const  : Extensions)
+OS << LS << Ext.first << Ext.second.first << 'p' << Ext.second.second;
 }
 
 static void EmitRISCVTargetDef(RecordKeeper , raw_ostream ) {
@@ -54,12 +54,6 @@ static void EmitRISCVTargetDef(RecordKeeper , raw_ostream 
) {
 
   // Iterate on all definition records.
   for (const Record *Rec : RK.getAllDerivedDefinitions("RISCVProcessorModel")) 
{
-std::string MArch = Rec->getValueAsString("DefaultMarch").str();
-
-// Compute MArch from features if we don't specify it.
-if (MArch.empty())
-  MArch = getMArch(*Rec);
-
 bool FastScalarUnalignedAccess =
 any_of(Rec->getValueAsListOfDefs("Features"), [&](auto ) {
   return Feature->getValueAsString("Name") == "unaligned-scalar-mem";
@@ -75,7 +69,16 @@ static void EmitRISCVTargetDef(RecordKeeper , raw_ostream 
) {
 
 OS << "PROC(" << Rec->getName() << ", "
<< "{\"" << Rec->getValueAsString("Name") << "\"}, "
-   << "{\"" << MArch << "\"}, " << FastUnalignedAccess << ")\n";
+   << "{\"";
+
+StringRef MArch = Rec->getValueAsString("DefaultMarch");
+
+// Compute MArch from features if we don't specify it.
+if (MArch.empty())
+  printMArch(OS, *Rec);
+else
+  OS << MArch;
+OS << "\"}, " << FastUnalignedAccess << ")\n";
   }
   OS << "\n#undef PROC\n";
   OS << "\n";

>From 815a63b99de61b8b1fde5a8c831f63d8810134db Mon Sep 17 00:00:00 2001
From: Craig Topper 
Date: Thu, 18 Apr 2024 17:10:50 -0700
Subject: [PATCH 2/7] fixup! clang-format

---
 llvm/utils/TableGen/RISCVTargetDefEmitter.cpp | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/llvm/utils/TableGen/RISCVTargetDefEmitter.cpp 

[clang] Fix objc_sel_{name,types} missing an underscore (PR #88713)

2024-04-22 Thread John McCall via cfe-commits

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


[clang] Fix objc_sel_{name,types} missing an underscore (PR #88713)

2024-04-22 Thread John McCall via cfe-commits

https://github.com/rjmccall commented:

At first, I was worried that this was an ABI break.  Then I noticed the 
internal inconsistency within this single file, and so I became worried that it 
was an ABI *fix*.  But then I noticed that the normal selector-emission code 
actually makes these strings hidden by default, and so now my guess is that the 
uniqueness of these strings is at best an optimization.  Still, it's an 
optimization we should do.

There are actually three differences between the code emission here and the 
code emission in the "primary" paths in `GetConstantSelector` and 
`GetTypeString`:
- the primary path uses an underscore in the symbol name prefix
- the primary path adjusts the symbol name to avoid restricted characters in 
the target object file format
- the primary path generates hidden symbols
My assumption is that, on all three of these points, we should just do what the 
primary path would do.  Please extract common functions as necessary in order 
to reuse the logic.

@davidchisnall, could you verify my reasoning here?

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


[clang] [clang] Fix self-capturing `__block` variables (PR #89475)

2024-04-22 Thread via cfe-commits

ille-apple wrote:

Rebased, because the original version failed CI due to a regression on `main` 
(#89476).

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


[clang] [clang] Fix self-capturing `__block` variables (PR #89475)

2024-04-22 Thread via cfe-commits

https://github.com/ille-apple updated 
https://github.com/llvm/llvm-project/pull/89475

>From 9c61a1d684a15153ea73e2036cdf978ff187c44d Mon Sep 17 00:00:00 2001
From: ille-apple 
Date: Fri, 19 Apr 2024 15:36:44 -0700
Subject: [PATCH] [clang] Fix self-capturing `__block` variables

Clang special-cases `__block` variables whose initializer contains a
block literal that captures the variable itself.  But this special case
doesn't work for variables of record types, causing Clang to emit broken
code.

Fix this by initializing such variables directly on the heap, and add a
warning for when this needs to be done.

rdar://70498802
---
 clang/include/clang/AST/Decl.h|  22 ++-
 .../clang/Basic/DiagnosticSemaKinds.td|   6 +
 clang/lib/AST/Decl.cpp|  13 ++
 clang/lib/CodeGen/CGBlocks.cpp|  81 +++
 clang/lib/CodeGen/CGBlocks.h  |   1 +
 clang/lib/CodeGen/CGDecl.cpp  | 114 +---
 clang/lib/CodeGen/CodeGenFunction.h   |  12 +-
 clang/lib/CodeGen/CodeGenModule.h |   8 +-
 clang/lib/Sema/Sema.cpp   |  65 +
 clang/lib/Serialization/ASTReaderDecl.cpp |   1 +
 clang/lib/Serialization/ASTWriterDecl.cpp |   6 +-
 clang/test/CodeGenCXX/block-capture.cpp   | 127 +-
 12 files changed, 340 insertions(+), 116 deletions(-)

diff --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h
index 8b121896d66d15..dc816786d7f11d 100644
--- a/clang/include/clang/AST/Decl.h
+++ b/clang/include/clang/AST/Decl.h
@@ -1103,6 +1103,11 @@ class VarDecl : public DeclaratorDecl, public 
Redeclarable {
 
 LLVM_PREFERRED_TYPE(bool)
 unsigned IsCXXCondDecl : 1;
+
+/// Whether this is a __block variable that is captured by a block
+/// referenced in its own initializer.
+LLVM_PREFERRED_TYPE(bool)
+unsigned CapturedByOwnInit : 1;
   };
 
   union {
@@ -1588,10 +1593,23 @@ class VarDecl : public DeclaratorDecl, public 
Redeclarable {
   /// escaping block.
   bool isNonEscapingByref() const;
 
-  void setEscapingByref() {
-NonParmVarDeclBits.EscapingByref = true;
+  void setEscapingByref();
+
+  /// Indicates this is a __block variable that is captured by a block
+  /// referenced in its own initializer.
+  bool isCapturedByOwnInit() const {
+return !isa(this) && NonParmVarDeclBits.CapturedByOwnInit;
   }
 
+  void setCapturedByOwnInit() {
+assert(!isa(this));
+NonParmVarDeclBits.CapturedByOwnInit = true;
+  }
+
+  /// Check if this is a __block variable which needs to be initialized
+  /// directly on the heap.
+  bool needsInitOnHeap() const;
+
   bool isCXXCondDecl() const {
 return isa(this) ? false : NonParmVarDeclBits.IsCXXCondDecl;
   }
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 63e951daec7477..859f218c2779de 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -2356,6 +2356,12 @@ def note_var_fixit_add_initialization : Note<
 def note_uninit_fixit_remove_cond : Note<
   "remove the %select{'%1' if its condition|condition if it}0 "
   "is always %select{false|true}2">;
+def warn_implicit_block_var_alloc : Warning<
+  "variable %q0 will be initialized in a heap allocation">,
+  InGroup>, DefaultIgnore;
+def note_because_captured_by_block : Note<
+  "because it is captured by a block used in its own initializer">;
+
 def err_init_incomplete_type : Error<"initialization of incomplete type %0">;
 def err_list_init_in_parens : Error<
   "cannot initialize %select{non-class|reference}0 type %1 with a "
diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index 474e0ccde5bbf7..fda9010ba126d7 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -2680,6 +2680,19 @@ bool VarDecl::isNonEscapingByref() const {
   return hasAttr() && !NonParmVarDeclBits.EscapingByref;
 }
 
+void VarDecl::setEscapingByref() {
+  assert(!isa(this) && hasAttr());
+  NonParmVarDeclBits.EscapingByref = true;
+}
+
+bool VarDecl::needsInitOnHeap() const {
+  // We need direct initialization on the heap for self-capturing __block
+  // variables of types that cause CodeGenFunction::getEvaluationKind to return
+  // TEK_Aggregate.  The only such types that can be captured are records.
+  return isCapturedByOwnInit() &&
+ getType().getAtomicUnqualifiedType()->isRecordType();
+}
+
 bool VarDecl::hasDependentAlignment() const {
   QualType T = getType();
   return T->isDependentType() || T->isUndeducedType() ||
diff --git a/clang/lib/CodeGen/CGBlocks.cpp b/clang/lib/CodeGen/CGBlocks.cpp
index 2742c39965b2c8..4bea057a15a52c 100644
--- a/clang/lib/CodeGen/CGBlocks.cpp
+++ b/clang/lib/CodeGen/CGBlocks.cpp
@@ -45,6 +45,13 @@ CGBlockInfo::CGBlockInfo(const BlockDecl *block, StringRef 
name)
 name = name.substr(1);
 }
 
+BlockByrefHelpers::BlockByrefHelpers(const 

[clang] [Clang][objectsize] Generate object size calculation for sub-objects (PR #86858)

2024-04-22 Thread Bill Wendling via cfe-commits

bwendling wrote:

Friendly ping 2: Electric Boogaloo

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


[clang-tools-extra] [clang-tidy] add check to suggest replacement of nested std::min or std::max with initializer lists (PR #85572)

2024-04-22 Thread via cfe-commits


@@ -0,0 +1,274 @@
+//===--- MinMaxUseInitializerListCheck.cpp - clang-tidy 
---===//
+//
+// 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 "MinMaxUseInitializerListCheck.h"
+#include "../utils/ASTUtils.h"
+#include "../utils/LexerUtils.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Lex/Lexer.h"
+
+using namespace clang;
+
+namespace {
+
+struct FindArgsResult {
+  const Expr *First;
+  const Expr *Last;
+  const Expr *Compare;
+  SmallVector Args;
+};
+
+} // anonymous namespace
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::modernize {
+
+static FindArgsResult findArgs(const CallExpr *Call) {
+  FindArgsResult Result;
+  Result.First = nullptr;
+  Result.Last = nullptr;
+  Result.Compare = nullptr;
+
+  //   check if the function has initializer list argument
+  if (Call->getNumArgs() < 3) {
+auto ArgIterator = Call->arguments().begin();
+
+const auto *InitListExpr =
+dyn_cast(*ArgIterator);
+const auto *InitList =
+InitListExpr != nullptr
+? dyn_cast(
+  InitListExpr->getSubExpr()->IgnoreImplicit())
+: nullptr;
+
+if (InitList) {
+  Result.Args.append(InitList->inits().begin(), InitList->inits().end());
+  Result.First = *ArgIterator;
+  Result.Last = *ArgIterator;
+
+  // check if there is a comparison argument
+  std::advance(ArgIterator, 1);
+  if (ArgIterator != Call->arguments().end())
+Result.Compare = *ArgIterator;
+
+  return Result;
+}
+  } else {
+// if it has 3 arguments then the last will be the comparison
+Result.Compare = *(std::next(Call->arguments().begin(), 2));
+  }
+
+  if (Result.Compare)
+Result.Args = SmallVector(llvm::drop_end(Call->arguments()));
+  else
+Result.Args = SmallVector(Call->arguments());

sopyb wrote:

If I would move it into the if/else. I would have to add another line at the 
very least `Result.Args = SmallVector(Call->arguments())` in the 
other branch so I will not move this into the if/else statement.

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


[clang] [clang-tools-extra] [compiler-rt] [flang] [libc] [libclc] [libcxx] [libcxxabi] [libunwind] [lld] [lldb] [llvm] [mlir] [openmp] [polly] [pstl] Update IDE Folders (PR #89153)

2024-04-22 Thread Jonas Devlieghere via cfe-commits

JDevlieghere wrote:

This looks like a nice improvement for folks using those generators. Even 
though most of these changes look straightforward, it would be a lot easier to 
review if this was broken up per subproject. Is there any reason that's not 
possible? 

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


[clang-tools-extra] [tidy] add new check bugprone-return-const-ref-from-parameter (PR #89497)

2024-04-22 Thread Danny Mösch via cfe-commits


@@ -0,0 +1,34 @@
+//===--- ReturnConstRefFromParameterCheck.cpp - clang-tidy 
===//
+//
+// 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 "ReturnConstRefFromParameterCheck.h"
+#include "../utils/Matchers.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+void ReturnConstRefFromParameterCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(
+  returnStmt(hasReturnValue(declRefExpr(to(parmVarDecl(hasType(
+ hasCanonicalType(matchers::isReferenceToConst(
+  .bind("ret"),
+  this);

SimplyDanny wrote:

I see. Thank you for clarification!

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


[clang] [Clang] Add wraps attribute (for granular integer overflow handling) (PR #86618)

2024-04-22 Thread Bill Wendling via cfe-commits


@@ -4077,6 +4077,9 @@ class BinaryOperator : public Expr {
   static unsigned sizeOfTrailingObjects(bool HasFPFeatures) {
 return HasFPFeatures * sizeof(FPOptionsOverride);
   }
+
+  /// Do one of the subexpressions have the wraps attribute?

bwendling wrote:

s/Do/Does/

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


[clang] [Clang] Add wraps attribute (for granular integer overflow handling) (PR #86618)

2024-04-22 Thread Bill Wendling via cfe-commits


@@ -4249,6 +4270,10 @@ Value *ScalarExprEmitter::EmitFixedPointBinOp(const 
BinOpInfo ) {
 Value *ScalarExprEmitter::EmitSub(const BinOpInfo ) {
   // The LHS is always a pointer if either side is.
   if (!op.LHS->getType()->isPointerTy()) {
+if ((op.Ty->isSignedIntegerOrEnumerationType() ||

bwendling wrote:

Same question here, re-early creation of subtraction.

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


[clang] [Clang] Add wraps attribute (for granular integer overflow handling) (PR #86618)

2024-04-22 Thread Bill Wendling via cfe-commits


@@ -2831,6 +2840,9 @@ ScalarExprEmitter::EmitScalarPrePostIncDec(const 
UnaryOperator *E, LValue LV,
   } else if (type->isIntegerType()) {
 QualType promotedType;
 bool canPerformLossyDemotionCheck = false;
+BinOpInfo Ops = (createBinOpInfoFromIncDec(

bwendling wrote:

You probably don't need parens around the `createBinOpInforFromIncDec` call.

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


[clang] [Clang] Add wraps attribute (for granular integer overflow handling) (PR #86618)

2024-04-22 Thread Bill Wendling via cfe-commits


@@ -4455,6 +4455,14 @@ void Sema::AddAlignValueAttr(Decl *D, const 
AttributeCommonInfo , Expr *E) {
   D->addAttr(::new (Context) AlignValueAttr(Context, CI, E));
 }
 
+static void handleWrapsAttr(Sema , Decl *D, const ParsedAttr ) {
+  S.AddWrapsAttr(D, AL);
+}
+
+void Sema::AddWrapsAttr(Decl *D, const AttributeCommonInfo ) {

bwendling wrote:

It looks like this is called only by `handleWrapsAttr`. Maybe just inline it?

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


[clang] [Clang] Add wraps attribute (for granular integer overflow handling) (PR #86618)

2024-04-22 Thread Bill Wendling via cfe-commits


@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 %s -verify -fsyntax-only -triple x86_64-pc-linux-gnu
+// expected-no-diagnostics
+typedef int __attribute__((wraps)) wrapping_int;
+
+void foo(void) {
+  const wrapping_int A = 1;
+  int D = 2147483647 + A;

bwendling wrote:

How about instead:

```c
int foo(void) {
  const wrapping_int A = 1;
  return 2147483647 + A;
}
```

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


[clang] [Clang] Add wraps attribute (for granular integer overflow handling) (PR #86618)

2024-04-22 Thread Bill Wendling via cfe-commits


@@ -4093,6 +4109,11 @@ Value *ScalarExprEmitter::EmitAdd(const BinOpInfo ) {
   op.RHS->getType()->isPointerTy())
 return emitPointerArithmetic(CGF, op, CodeGenFunction::NotSubtraction);
 
+  if ((op.Ty->isSignedIntegerOrEnumerationType() ||

bwendling wrote:

Is this early-exit necessary, or does the following processing not work?

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


[clang] [Clang] Add wraps attribute (for granular integer overflow handling) (PR #86618)

2024-04-22 Thread Bill Wendling via cfe-commits


@@ -156,6 +156,10 @@ struct BinOpInfo {
 }
 return false;
   }
+
+  /// Does the BinaryOperator have the wraps attribute?
+  /// If so, we can ellide overflow sanitizer checks.

bwendling wrote:

s/ellide/elide/

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


[clang] Add support for builtin_verbose_trap (PR #79230)

2024-04-22 Thread David Blaikie via cfe-commits


@@ -3379,6 +3379,60 @@ Query for this feature with 
``__has_builtin(__builtin_debugtrap)``.
 
 Query for this feature with ``__has_builtin(__builtin_trap)``.
 
+``__builtin_verbose_trap``

dwblaikie wrote:

Ah, OK - that seems like more reason the prefix should be singular. Like we 
shouldn't add a new/distinct prefix for array bounds? Or other things we want 
to error out on - because it'd be an ongoing maintenance problem updating 
consumers like lldb each time we add one? 

So maybe we should have a generic prefix we'll always use (`__builtin_trap`, 
say) and then maybe some identifier after that in a known format (eg: space, 
identifier, space) that can be used? then an error message string?

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


[clang] [Clang] Add wraps attribute (for granular integer overflow handling) (PR #86618)

2024-04-22 Thread Eli Friedman via cfe-commits

efriedma-quic wrote:

I'm still not happy with the AST representation here.  The current 
representation is likely to cause unpredictable results in edge cases, and 
compatibility constraints mean whatever result the current version happens to 
produce for those cases is locked in forever.  And there isn't really any good 
way to mitigate those issues under the current representation.

I don't want to block progress here, but I think in its current form, we're 
likely to end up with reported issues we can't fix.

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


[clang] Add support for builtin_verbose_trap (PR #79230)

2024-04-22 Thread David Blaikie via cfe-commits


@@ -0,0 +1,28 @@
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -fcxx-exceptions -verify %s
+
+#if !__has_builtin(__builtin_verbose_trap)
+#error
+#endif
+
+constexpr char const* constMsg1 = "hello";
+char const* const constMsg2 = "hello";
+char const constMsg3[] = "hello";
+
+template 
+void f(const char * arg) {
+  __builtin_verbose_trap("Argument_must_not_be_null");

dwblaikie wrote:

FWIW, I've seen multiple MB symbol names :) so I probably wouldn't be too 
worried that any user would write a description that's longer than the symbols 
that complex templates can create... 

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


[clang] [clang-tools-extra] [compiler-rt] [flang] [libc] [libclc] [libcxx] [libcxxabi] [libunwind] [lld] [lldb] [llvm] [mlir] [openmp] [polly] [pstl] Update IDE Folders (PR #89153)

2024-04-22 Thread Michael Kruse via cfe-commits


@@ -406,5 +426,13 @@ function(llvm_ExternalProject_Add name source_dir)
   WORKING_DIRECTORY ${BINARY_DIR}
   VERBATIM
   USES_TERMINAL)
+if (ARG_FOLDER)
+  set_target_properties(${target} PROPERTIES FOLDER "${ARG_FOLDER}")
+endif ()
   endforeach()
+
+  #set_target_folder(
+  #  TARGETS ${name} install-${name} ${name}-clobber ${name}-clear 
${name}-clean ${ARG_EXTRA_TARGETS}
+  #  FOLDER "${ARG_FOLDE}"
+  #)

Meinersbur wrote:

thanks

https://github.com/llvm/llvm-project/pull/89153
___
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 16-bit non-widening FMLA/FMLS (PR #88553)

2024-04-22 Thread Hassnaa Hamdi via cfe-commits


@@ -458,6 +458,40 @@ let TargetGuard = "sme2,sme-f64f64" in {
   def SVMLS_LANE_VG1x4_F64 : Inst<"svmls_lane_za64[_{d}]_vg1x4", "vm4di", "d", 
MergeNone, "aarch64_sme_fmls_lane_vg1x4", [IsStreaming, IsInOutZA], 
[ImmCheck<3, ImmCheck0_1>]>;
 }
 
+let TargetGuard = "sme2p1,sme-f16f16" in {
+  def SVMLA_MULTI_VG1x2_F16 : Inst<"svmla_za16[_f16]_vg1x2", "vm22", "h", 
MergeNone, "aarch64_sme_fmla_vg1x2", [IsStreaming, IsInOutZA], []>;
+  def SVMLA_MULTI_VG1x4_F16 : Inst<"svmla_za16[_f16]_vg1x4", "vm44", "h", 
MergeNone, "aarch64_sme_fmla_vg1x4", [IsStreaming, IsInOutZA], []>;
+  def SVMLS_MULTI_VG1x2_F16 : Inst<"svmls_za16[_f16]_vg1x2", "vm22", "h", 
MergeNone, "aarch64_sme_fmls_vg1x2", [IsStreaming, IsInOutZA], []>;
+  def SVMLS_MULTI_VG1x4_F16 : Inst<"svmls_za16[_f16]_vg1x4", "vm44", "h", 
MergeNone, "aarch64_sme_fmls_vg1x4", [IsStreaming, IsInOutZA], []>;
+
+  def SVMLA_SINGLE_VG1x2_F16 : Inst<"svmla[_single]_za16[_f16]_vg1x2", "vm2d", 
"h", MergeNone, "aarch64_sme_fmla_single_vg1x2", [IsStreaming, IsInOutZA], []>;
+  def SVMLA_SINGLE_VG1x4_F16 : Inst<"svmla[_single]_za16[_f16]_vg1x4", "vm4d", 
"h", MergeNone, "aarch64_sme_fmla_single_vg1x4", [IsStreaming, IsInOutZA], []>;
+  def SVMLS_SINGLE_VG1x2_F16 : Inst<"svmls[_single]_za16[_f16]_vg1x2", "vm2d", 
"h", MergeNone, "aarch64_sme_fmls_single_vg1x2", [IsStreaming, IsInOutZA], []>;
+  def SVMLS_SINGLE_VG1x4_F16 : Inst<"svmls[_single]_za16[_f16]_vg1x4", "vm4d", 
"h", MergeNone, "aarch64_sme_fmls_single_vg1x4", [IsStreaming, IsInOutZA], []>;
+
+  def SVMLA_LANE_VG1x2_F16 : Inst<"svmla_lane_za16[_f16]_vg1x2", "vm2di", "h", 
MergeNone, "aarch64_sme_fmla_lane_vg1x2", [IsStreaming, IsInOutZA], 
[ImmCheck<3, ImmCheck0_7>]>;
+  def SVMLA_LANE_VG1x4_F16 : Inst<"svmla_lane_za16[_f16]_vg1x4", "vm4di", "h", 
MergeNone, "aarch64_sme_fmla_lane_vg1x4", [IsStreaming, IsInOutZA], 
[ImmCheck<3, ImmCheck0_7>]>;
+  def SVMLS_LANE_VG1x2_F16 : Inst<"svmls_lane_za16[_f16]_vg1x2", "vm2di", "h", 
MergeNone, "aarch64_sme_fmls_lane_vg1x2", [IsStreaming, IsInOutZA], 
[ImmCheck<3, ImmCheck0_7>]>;
+  def SVMLS_LANE_VG1x4_F16 : Inst<"svmls_lane_za16[_f16]_vg1x4", "vm4di", "h", 
MergeNone, "aarch64_sme_fmls_lane_vg1x4", [IsStreaming, IsInOutZA], 
[ImmCheck<3, ImmCheck0_7>]>;
+}
+
+let TargetGuard = "sme2,b16b16" in {

hassnaaHamdi wrote:

Hi,
According to this sentence in the acle specs:
`__ARM_FEATURE_SME_B16B16 is defined to 1 if there is hardware support for the 
SME2.1 FEAT_B16B16 instructions and if their associated SME intrinsics are 
available.`
I understand that the target guard should be "sme2p1, b16b16", correct ?
If that is not correct, could you please mention where is it specified that we 
should use sme2 not sme2p1 ?

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


[clang] Add support for builtin_verbose_trap (PR #79230)

2024-04-22 Thread Akira Hatanaka via cfe-commits


@@ -3424,6 +3445,26 @@ llvm::DIMacroFile 
*CGDebugInfo::CreateTempMacroFile(llvm::DIMacroFile *Parent,
   return DBuilder.createTempMacroFile(Parent, Line, FName);
 }
 
+llvm::DILocation *CGDebugInfo::CreateTrapFailureMessageFor(

ahatanaka wrote:

OK, I'll make it a parameter then.

I added macro `CLANG_VERBOSE_TRAP_PREFIX` to `ModuleBuilder.h` so that lldb 
wouldn't have to define it too. See 
https://github.com/llvm/llvm-project/pull/80368#discussion_r1481781470.

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


[clang] [clang-tools-extra] [compiler-rt] [flang] [libc] [libclc] [libcxx] [libcxxabi] [libunwind] [lld] [lldb] [llvm] [mlir] [openmp] [polly] [pstl] Update IDE Folders (PR #89153)

2024-04-22 Thread Michael Kruse via cfe-commits


@@ -56,11 +56,13 @@ endfunction()
 # Use provided strip tool instead of the default one.
 #   TARGET_TRIPLE triple
 # Optional target triple to pass to the compiler
+#   FOLDER
+# For IDEs, the Folder to put the targets into.=

Meinersbur wrote:

It's already called FOLDER in 
https://github.com/llvm/llvm-project/blob/main/llvm/cmake/modules/AddLLVM.cmake#L2080-L2083.
 I would prefer to keep it consistent.

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


[clang] Fix -fno-unsafe-math-optimizations behavior (PR #89473)

2024-04-22 Thread Andy Kaylor via cfe-commits

andykaylor wrote:

I've made some minor changes to clean up the LIT test checks for this PR. I 
started to clean up the entire test, but it quickly became obvious that I 
should put that into a separate PR.

I will submit a new PR to clean up the entire fast-math.c test. I have an idea 
that I think will work, hard-coding the order of the math-related flags and 
using a separate prefix for each one plus negative checks. Then the test can 
just use "--check-prefixes=..." to put together the combinations that are 
expected. I think that will be more maintainable and more readable than trying 
to group checks in the more-or-less arbitrary way the test currently does.

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


[clang] Fix -fno-unsafe-math-optimizations behavior (PR #89473)

2024-04-22 Thread Zahira Ammarguellat via cfe-commits


@@ -271,30 +271,32 @@
 // RUN:   2>&1 | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s
 
 // RUN: %clang -### -funsafe-math-optimizations -fno-reciprocal-math -c %s \
-// RUN:   2>&1 | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s
+// RUN:   2>&1 | FileCheck --check-prefix=CHECK-REASSOC-NO-UNSAFE-MATH %s
 // RUN: %clang -### -funsafe-math-optimizations -fsigned-zeros -c %s 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s
 // RUN: %clang -### -funsafe-math-optimizations -ftrapping-math -c %s 2>&1 \
-// RUN:   | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s
+// RUN:   | FileCheck --check-prefix=CHECK-TRAPPING-NO-UNSAFE-MATH %s
 // RUN: %clang -### -funsafe-math-optimizations -fno-unsafe-math-optimizations 
\
 // RUN: -c %s 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s
 // RUN: %clang -### -ffast-math -fno-associative-math -c %s 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s
 
 // RUN: %clang -### -ffast-math -fno-reciprocal-math -c %s 2>&1 \
-// RUN:   | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s
+// RUN:   | FileCheck --check-prefix=CHECK-REASSOC-NO-UNSAFE-MATH %s
 // RUN: %clang -### -ffast-math -fsigned-zeros -c %s 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s
 // RUN: %clang -### -ffast-math -ftrapping-math -c %s 2>&1 \
-// RUN:   | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s
+// RUN:   | FileCheck --check-prefix=CHECK-TRAPPING-NO-UNSAFE-MATH %s
 // RUN: %clang -### -ffast-math -fno-unsafe-math-optimizations -c %s 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s
 
 // CHECK-NO-UNSAFE-MATH: "-cc1"
 // CHECK-NO-UNSAFE-MATH-NOT: "-funsafe-math-optimizations"
-// CHECK-NO_UNSAFE-MATH-NOT: "-mreassociate"

zahiraam wrote:

It looks like the lines with `_` were just ignored! That's bad.

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


[clang] Fix -fno-unsafe-math-optimizations behavior (PR #89473)

2024-04-22 Thread Zahira Ammarguellat via cfe-commits


@@ -318,12 +320,12 @@
 
 // RUN: %clang -### -fassociative-math -freciprocal-math -fno-signed-zeros \
 // RUN: -fno-trapping-math -ftrapping-math -c %s 2>&1 \
-// RUN:   | FileCheck --check-prefix=CHECK-NO-REASSOC-NO-UNSAFE-MATH %s
+// RUN:   | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s
 
 // CHECK-NO-REASSOC-NO-UNSAFE-MATH: "-cc1"
-// CHECK-NO-REASSOC-NO_UNSAFE-MATH-NOT: "-funsafe-math-optimizations"
-// CHECK-NO-REASSOC-NO_UNSAFE-MATH-NOT: "-mreassociate"
-// CHECK-NO-REASSOC-NO_UNSAFE-MATH-NOT: "-funsafe-math-optimizations"
+// CHECK-NO-REASSOC-NO-UNSAFE-MATH-NOT: "-funsafe-math-optimizations"
+// CHECK-NO-REASSOC-NO-UNSAFE-MATH-NOT: "-mreassociate"
+// CHECK-NO-REASSOC-NO-UNSAFE-MATH-NOT: "-funsafe-math-optimizations"

zahiraam wrote:

Yes, I think that should work!

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


[clang] [Clang] Improve testing for the flexible array member (PR #89462)

2024-04-22 Thread Bill Wendling via cfe-commits

https://github.com/bwendling updated 
https://github.com/llvm/llvm-project/pull/89462

>From 2a6b3356a977132459bed84fb4e4add631e181cb Mon Sep 17 00:00:00 2001
From: Bill Wendling 
Date: Fri, 19 Apr 2024 15:06:34 -0700
Subject: [PATCH 1/2] [Clang][NFC] Improve testing for the flexible array
 member

Testing for the name of the flexible array member isn't as robust as
testing the FieldDecl pointers.
---
 clang/lib/CodeGen/CGBuiltin.cpp | 21 -
 clang/lib/CodeGen/CodeGenFunction.h | 12 ++--
 2 files changed, 18 insertions(+), 15 deletions(-)

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 4ab844d206e48a..0d2b5e1b5120ae 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -822,8 +822,9 @@ CodeGenFunction::evaluateOrEmitBuiltinObjectSize(const Expr 
*E, unsigned Type,
   return ConstantInt::get(ResType, ObjectSize, /*isSigned=*/true);
 }
 
-const FieldDecl *CodeGenFunction::FindFlexibleArrayMemberField(
-ASTContext , const RecordDecl *RD, StringRef Name, uint64_t ) {
+const FieldDecl *CodeGenFunction::FindFlexibleArrayMemberFieldAndOffset(
+ASTContext , const RecordDecl *RD, const FieldDecl *FAMDecl,
+uint64_t ) {
   const LangOptions::StrictFlexArraysLevelKind StrictFlexArraysLevel =
   getLangOpts().getStrictFlexArraysLevel();
   uint32_t FieldNo = 0;
@@ -832,7 +833,7 @@ const FieldDecl 
*CodeGenFunction::FindFlexibleArrayMemberField(
 return nullptr;
 
   for (const FieldDecl *FD : RD->fields()) {
-if ((Name.empty() || FD->getNameAsString() == Name) &&
+if ((!FAMDecl || FD == FAMDecl) &&
 Decl::isFlexibleArrayMemberLike(
 Ctx, FD, FD->getType(), StrictFlexArraysLevel,
 /*IgnoreTemplateOrMacroSubstitution=*/true)) {
@@ -843,8 +844,8 @@ const FieldDecl 
*CodeGenFunction::FindFlexibleArrayMemberField(
 
 QualType Ty = FD->getType();
 if (Ty->isRecordType()) {
-  if (const FieldDecl *Field = FindFlexibleArrayMemberField(
-  Ctx, Ty->getAsRecordDecl(), Name, Offset)) {
+  if (const FieldDecl *Field = FindFlexibleArrayMemberFieldAndOffset(
+  Ctx, Ty->getAsRecordDecl(), FAMDecl, Offset)) {
 const ASTRecordLayout  = Ctx.getASTRecordLayout(RD);
 Offset += Layout.getFieldOffset(FieldNo);
 return Field;
@@ -930,12 +931,12 @@ CodeGenFunction::emitFlexibleArrayMemberSize(const Expr 
*E, unsigned Type,
 
   // Get the flexible array member Decl.
   const RecordDecl *OuterRD = nullptr;
-  std::string FAMName;
+  const FieldDecl *FAMDecl = nullptr;
   if (const auto *ME = dyn_cast(Base)) {
 // Check if \p Base is referencing the FAM itself.
 const ValueDecl *VD = ME->getMemberDecl();
 OuterRD = VD->getDeclContext()->getOuterLexicalRecordContext();
-FAMName = VD->getNameAsString();
+FAMDecl = dyn_cast(VD);
   } else if (const auto *DRE = dyn_cast(Base)) {
 // Check if we're pointing to the whole struct.
 QualType Ty = DRE->getDecl()->getType();
@@ -974,9 +975,11 @@ CodeGenFunction::emitFlexibleArrayMemberSize(const Expr 
*E, unsigned Type,
   if (!OuterRD)
 return nullptr;
 
+  // We call FindFlexibleArrayMemberAndOffset even if FAMDecl is non-null to
+  // get its offset.
   uint64_t Offset = 0;
-  const FieldDecl *FAMDecl =
-  FindFlexibleArrayMemberField(Ctx, OuterRD, FAMName, Offset);
+  FAMDecl =
+  FindFlexibleArrayMemberFieldAndOffset(Ctx, OuterRD, FAMDecl, Offset);
   Offset = Ctx.toCharUnitsFromBits(Offset).getQuantity();
 
   if (!FAMDecl || !FAMDecl->getType()->isCountAttributedType())
diff --git a/clang/lib/CodeGen/CodeGenFunction.h 
b/clang/lib/CodeGen/CodeGenFunction.h
index ff1873325d409f..a751649cdb597a 100644
--- a/clang/lib/CodeGen/CodeGenFunction.h
+++ b/clang/lib/CodeGen/CodeGenFunction.h
@@ -3204,12 +3204,12 @@ class CodeGenFunction : public CodeGenTypeCache {
llvm::Value *Index, QualType IndexType,
QualType IndexedType, bool Accessed);
 
-  // Find a struct's flexible array member. It may be embedded inside multiple
-  // sub-structs, but must still be the last field.
-  const FieldDecl *FindFlexibleArrayMemberField(ASTContext ,
-const RecordDecl *RD,
-StringRef Name,
-uint64_t );
+  // Find a struct's flexible array member and get its offset. It may be
+  // embedded inside multiple sub-structs, but must still be the last field.
+  const FieldDecl *
+  FindFlexibleArrayMemberFieldAndOffset(ASTContext , const RecordDecl *RD,
+const FieldDecl *FAMDecl,
+uint64_t );
 
   /// Find the FieldDecl specified in a FAM's "counted_by" attribute. Returns
   /// \p nullptr if either the attribute or the field doesn't exist.

>From a12d8a360b00823fac57e43dd6a05dbe3ee91b53 Mon 

[clang] Add support for builtin_verbose_trap (PR #79230)

2024-04-22 Thread David Blaikie via cfe-commits


@@ -3424,6 +3445,26 @@ llvm::DIMacroFile 
*CGDebugInfo::CreateTempMacroFile(llvm::DIMacroFile *Parent,
   return DBuilder.createTempMacroFile(Parent, Line, FName);
 }
 
+llvm::DILocation *CGDebugInfo::CreateTrapFailureMessageFor(

dwblaikie wrote:

I think I agree with 
https://github.com/llvm/llvm-project/pull/79230/files#r1529429173 then - the 
prefix should be a parameter and I don't think it needs to be a #defined 
constant (CLANG_VERBOSE_TRAP_PREFIX) - and can instead be written as a literal 
in the caller in CGBuiltin.cpp?

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


[clang] Fix -fno-unsafe-math-optimizations behavior (PR #89473)

2024-04-22 Thread Andy Kaylor via cfe-commits

https://github.com/andykaylor updated 
https://github.com/llvm/llvm-project/pull/89473

>From 100fc9dfb2b071877d758ce71bddeec693d986da Mon Sep 17 00:00:00 2001
From: Andy Kaylor 
Date: Fri, 19 Apr 2024 16:35:00 -0700
Subject: [PATCH 1/2] Fix -fno-unsafe-math-optimizations behavior

This changes the handling of -fno-unsafe-fp-math to stop having that
option imply -ftrapping-math. In gcc, -fno-unsafe-math-optimizations sets
-ftrapping-math, but that dependency is based on the fact the
-ftrapping-math is enabled by default in gcc. Because clang does not
enabled -ftrapping-math by default, there is no reason for
-fno-unsafe-math-optimizations to set it.

On the other hand, -funsafe-math-optimizations continues to imply
-fno-trapping-math because this option necessarily disables strict
exception semantics.

This fixes https://github.com/llvm/llvm-project/issues/87523
---
 clang/docs/UsersManual.rst|  1 -
 clang/lib/Driver/ToolChains/Clang.cpp |  2 --
 clang/test/Driver/fast-math.c | 24 +---
 3 files changed, 13 insertions(+), 14 deletions(-)

diff --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index c464bc3a69adc5..2b4155d4b65a48 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -1690,7 +1690,6 @@ floating point semantic models: precise (the default), 
strict, and fast.
* ``-fno-associative-math``
* ``-fno-reciprocal-math``
* ``-fsigned-zeros``
-   * ``-ftrapping-math``
* ``-ffp-contract=on``
* ``-fdenormal-fp-math=ieee``
 
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 456ea74caadb00..0776d095327219 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -3137,8 +3137,6 @@ static void RenderFloatingPointOptions(const ToolChain 
, const Driver ,
   ReciprocalMath = false;
   SignedZeros = true;
   ApproxFunc = false;
-  TrappingMath = true;
-  FPExceptionBehavior = "strict";
 
   // The target may have opted to flush by default, so force IEEE.
   DenormalFPMath = llvm::DenormalMode::getIEEE();
diff --git a/clang/test/Driver/fast-math.c b/clang/test/Driver/fast-math.c
index 882e81fd14d34a..ef23f88dd817ea 100644
--- a/clang/test/Driver/fast-math.c
+++ b/clang/test/Driver/fast-math.c
@@ -271,11 +271,11 @@
 // RUN:   2>&1 | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s
 
 // RUN: %clang -### -funsafe-math-optimizations -fno-reciprocal-math -c %s \
-// RUN:   2>&1 | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s
+// RUN:   2>&1 | FileCheck --check-prefix=CHECK-REASSOC-NO-UNSAFE-MATH %s
 // RUN: %clang -### -funsafe-math-optimizations -fsigned-zeros -c %s 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s
 // RUN: %clang -### -funsafe-math-optimizations -ftrapping-math -c %s 2>&1 \
-// RUN:   | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s
+// RUN:   | FileCheck --check-prefix=CHECK-TRAPPING-NO-UNSAFE-MATH %s
 // RUN: %clang -### -funsafe-math-optimizations -fno-unsafe-math-optimizations 
\
 // RUN: -c %s 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s
@@ -283,18 +283,20 @@
 // RUN:   | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s
 
 // RUN: %clang -### -ffast-math -fno-reciprocal-math -c %s 2>&1 \
-// RUN:   | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s
+// RUN:   | FileCheck --check-prefix=CHECK-REASSOC-NO-UNSAFE-MATH %s
 // RUN: %clang -### -ffast-math -fsigned-zeros -c %s 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s
 // RUN: %clang -### -ffast-math -ftrapping-math -c %s 2>&1 \
-// RUN:   | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s
+// RUN:   | FileCheck --check-prefix=CHECK-TRAPPING-NO-UNSAFE-MATH %s
 // RUN: %clang -### -ffast-math -fno-unsafe-math-optimizations -c %s 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s
 
 // CHECK-NO-UNSAFE-MATH: "-cc1"
 // CHECK-NO-UNSAFE-MATH-NOT: "-funsafe-math-optimizations"
-// CHECK-NO_UNSAFE-MATH-NOT: "-mreassociate"
+// CHECK-NO-UNSAFE-MATH-NOT: "-mreassociate"
 // CHECK-NO-UNSAFE-MATH: "-o"
+// CHECK-NO-UNSAFE-MATH-NOT: "-ffp-exception-behavior=strict"
+// CHECK-TRAPPING-NO-UNSAFE-MATH: "-ffp-exception-behavior=strict"
 
 
 // Reassociate is allowed because it does not require reciprocal-math.
@@ -304,8 +306,8 @@
 // RUN:   | FileCheck --check-prefix=CHECK-REASSOC-NO-UNSAFE-MATH %s
 
 // CHECK-REASSOC-NO-UNSAFE-MATH: "-cc1"
-// CHECK-REASSOC-NO_UNSAFE-MATH-NOT: "-funsafe-math-optimizations"
-// CHECK-REASSOC-NO_UNSAFE-MATH: "-mreassociate"
+// CHECK-REASSOC-NO-UNSAFE-MATH-NOT: "-funsafe-math-optimizations"
+// CHECK-REASSOC-NO-UNSAFE-MATH: "-mreassociate"
 // CHECK-REASSOC-NO-UNSAFE-MATH-NOT: "-funsafe-math-optimizations"
 // CHECK-REASSOC-NO-UNSAFE-MATH: "-o"
 
@@ -318,12 +320,12 @@
 
 // RUN: %clang -### -fassociative-math -freciprocal-math -fno-signed-zeros \
 // RUN: -fno-trapping-math -ftrapping-math -c %s 2>&1 \
-// RUN:   | 

[clang] [llvm] [mlir] [OpenMP] Migrate GPU Reductions CodeGen from Clang to OMPIRBuilder (PR #80343)

2024-04-22 Thread via cfe-commits

shraiysh wrote:

I see. Thanks for the reply.

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


[clang] Add support for builtin_verbose_trap (PR #79230)

2024-04-22 Thread Akira Hatanaka via cfe-commits

https://github.com/ahatanak updated 
https://github.com/llvm/llvm-project/pull/79230

>From 95200f3bb3859738981240a9d8c503a13ede9601 Mon Sep 17 00:00:00 2001
From: Akira Hatanaka 
Date: Tue, 16 Jan 2024 13:18:09 -0800
Subject: [PATCH 01/12] Add support for builtin_verbose_trap

The builtin causes the program to stop its execution abnormally and shows a
human-readable description of the reason for the termination when a debugger is
attached or in a symbolicated crash log.

The motivation for the builtin is explained in the following RFC:

https://discourse.llvm.org/t/rfc-adding-builtin-verbose-trap-string-literal/75845
---
 clang/docs/LanguageExtensions.rst | 49 ++-
 clang/include/clang/AST/Expr.h|  5 ++
 clang/include/clang/Basic/Builtins.td |  6 +++
 .../clang/Basic/DiagnosticSemaKinds.td|  2 +
 clang/lib/AST/ExprConstant.cpp| 18 +--
 clang/lib/CodeGen/CGBuiltin.cpp   | 12 +
 clang/lib/CodeGen/CGDebugInfo.cpp | 42 
 clang/lib/CodeGen/CGDebugInfo.h   | 20 
 clang/lib/Sema/SemaChecking.cpp   | 22 +
 .../CodeGenCXX/debug-info-verbose-trap.cpp| 49 +++
 clang/test/SemaCXX/verbose-trap.cpp   | 28 +++
 11 files changed, 249 insertions(+), 4 deletions(-)
 create mode 100644 clang/test/CodeGenCXX/debug-info-verbose-trap.cpp
 create mode 100644 clang/test/SemaCXX/verbose-trap.cpp

diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 84fc4dee02fa80..1dd8d3bcec920d 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -3467,6 +3467,54 @@ Query for this feature with 
``__has_builtin(__builtin_trap)``.
 
 ``__builtin_arm_trap`` is lowered to the ``llvm.aarch64.break`` builtin, and 
then to ``brk #payload``.
 
+``__builtin_verbose_trap``
+--
+
+``__builtin_verbose_trap`` causes the program to stop its execution abnormally
+and shows a human-readable description of the reason for the termination when a
+debugger is attached or in a symbolicated crash log.
+
+**Syntax**:
+
+.. code-block:: c++
+
+__builtin_verbose_trap(const char *reason)
+
+**Description**
+
+``__builtin_verbose_trap`` is lowered to the ` ``llvm.trap`` 
`_ builtin.
+Additionally, clang emits debug metadata that represents an artificial inline
+frame whose name encodes the string passed to the builtin, prefixed by a 
"magic"
+prefix.
+
+For example, consider the following code:
+
+.. code-block:: c++
+
+void foo(int* p) {
+  if (p == nullptr)
+__builtin_verbose_trap("Argument_must_not_be_null");
+}
+
+The debug metadata would look as if it were produced for the following code:
+
+.. code-block:: c++
+
+__attribute__((always_inline))
+inline void "__llvm_verbose_trap: Argument_must_not_be_null"() {
+  __builtin_trap();
+}
+
+void foo(int* p) {
+  if (p == nullptr)
+"__llvm_verbose_trap: Argument_must_not_be_null"();
+}
+
+However, the LLVM IR would not actually contain a call to the artificial
+function — it only exists in the debug metadata.
+
+Query for this feature with ``__has_builtin(__builtin_verbose_trap)``.
+
 ``__builtin_allow_runtime_check``
 -
 
@@ -3514,7 +3562,6 @@ guarded check. It's unused now. It will enable 
kind-specific lowering in future.
 E.g. a higher hotness cutoff can be used for more expensive kind of check.
 
 Query for this feature with ``__has_builtin(__builtin_allow_runtime_check)``.
-
 ``__builtin_nondeterministic_value``
 
 
diff --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h
index 2bfefeabc348be..9606a5fddd47e3 100644
--- a/clang/include/clang/AST/Expr.h
+++ b/clang/include/clang/AST/Expr.h
@@ -787,6 +787,11 @@ class Expr : public ValueStmt {
  const Expr *PtrExpression, ASTContext ,
  EvalResult ) const;
 
+  /// If the current Expr can be evaluated to a pointer to a null-terminated
+  /// constant string, return the constant string (without the terminating 
null)
+  /// in Result. Return true if it succeeds.
+  bool tryEvaluateString(std::string , ASTContext ) const;
+
   /// Enumeration used to describe the kind of Null pointer constant
   /// returned from \c isNullPointerConstant().
   enum NullPointerConstantKind {
diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index de721a87b3341d..5b3b9d04e576ab 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -1152,6 +1152,12 @@ def Trap : Builtin {
   let Prototype = "void()";
 }
 
+def VerboseTrap : Builtin {
+  let Spellings = ["__builtin_verbose_trap"];
+  let Attributes = [NoThrow, NoReturn];
+  let Prototype = "void(char 

[clang] [C++23] [CLANG] Adding C++23 constexpr math functions: fmin and frexp. (PR #88978)

2024-04-22 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Zahira Ammarguellat (zahiraam)


Changes

Add support for for fmin and frexp.

---
Full diff: https://github.com/llvm/llvm-project/pull/88978.diff


4 Files Affected:

- (modified) clang/include/clang/Basic/Builtins.td (+2-2) 
- (modified) clang/lib/AST/ExprConstant.cpp (+14-1) 
- (added) clang/test/CodeGenCXX/constexpr-math.cpp (+55) 
- (added) clang/test/SemaCXX/constexpr-math.cpp (+57) 


``diff
diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index 52c0dd52c28b11..a35c77286229ff 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -3440,7 +3440,7 @@ def Fmod : FPMathTemplate, LibBuiltin<"math.h"> {
 
 def Frexp : FPMathTemplate, LibBuiltin<"math.h"> {
   let Spellings = ["frexp"];
-  let Attributes = [NoThrow];
+  let Attributes = [NoThrow, Constexpr];
   let Prototype = "T(T, int*)";
   let AddBuiltinPrefixedAlias = 1;
 }
@@ -3618,7 +3618,7 @@ def Fmax : FPMathTemplate, LibBuiltin<"math.h"> {
 
 def Fmin : FPMathTemplate, LibBuiltin<"math.h"> {
   let Spellings = ["fmin"];
-  let Attributes = [NoThrow, Const];
+  let Attributes = [NoThrow, Const, Constexpr];
   let Prototype = "T(T, T)";
   let AddBuiltinPrefixedAlias = 1;
   let OnlyBuiltinPrefixedAliasIsConstexpr = 1;
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 5a36621dc5cce2..1a6abb386071c7 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -2922,7 +2922,7 @@ static bool handleFloatFloatBinOp(EvalInfo , const 
BinaryOperator *E,
   //   If during the evaluation of an expression, the result is not
   //   mathematically defined [...], the behavior is undefined.
   // FIXME: C++ rules require us to not conform to IEEE 754 here.
-  if (LHS.isNaN()) {
+  if (!Info.getLangOpts().CPlusPlus23 && LHS.isNaN()) {
 Info.CCEDiag(E, diag::note_constexpr_float_arithmetic) << LHS.isNaN();
 return Info.noteUndefinedBehavior();
   }
@@ -14547,6 +14547,17 @@ bool FloatExprEvaluator::VisitCallExpr(const CallExpr 
*E) {
   default:
 return false;
 
+  case Builtin::BI__builtin_frexpf:
+  case Builtin::BI__builtin_frexp: {
+LValue Pointer;
+if (!EvaluateFloat(E->getArg(0), Result, Info) ||
+!EvaluatePointer(E->getArg(1), Pointer, Info))
+  return false;
+llvm::RoundingMode RM = getActiveRoundingMode(Info, E);
+int FrexpExp;
+Result = llvm::frexp(Result, FrexpExp, RM);
+return true;
+  }
   case Builtin::BI__builtin_huge_val:
   case Builtin::BI__builtin_huge_valf:
   case Builtin::BI__builtin_huge_vall:
@@ -14638,6 +14649,8 @@ bool FloatExprEvaluator::VisitCallExpr(const CallExpr 
*E) {
 return true;
   }
 
+  case Builtin::BIfmin:
+  case Builtin::BIfminf:
   case Builtin::BI__builtin_fmin:
   case Builtin::BI__builtin_fminf:
   case Builtin::BI__builtin_fminl:
diff --git a/clang/test/CodeGenCXX/constexpr-math.cpp 
b/clang/test/CodeGenCXX/constexpr-math.cpp
new file mode 100644
index 00..ad7b6779a4ae0e
--- /dev/null
+++ b/clang/test/CodeGenCXX/constexpr-math.cpp
@@ -0,0 +1,55 @@
+// RUN: %clang_cc1 -x c++ -triple x86_64-unknown-unknown -std=c++23 \
+// RUN: -DWIN -emit-llvm -o - %s | FileCheck %s --check-prefixes=WIN
+
+// RUN: %clang_cc1 -x c++ -triple x86_64-unknown-unknown -std=c++23 \
+// RUN: -emit-llvm -o - %s | FileCheck %s --check-prefixes=LNX
+
+#ifdef WIN
+#define INFINITY ((float)(1e+300 * 1e+300))
+#define NAN  (-(float)(INFINITY * 0.0F))
+#else
+#define NAN (__builtin_nanf(""))
+#define INFINITY (__builtin_inff())
+#endif
+
+int func()
+{
+  int i;
+
+  // fmin
+  constexpr double f1 = __builtin_fmin(15.24, 1.3);
+  constexpr double f2 = __builtin_fmin(-0.0, +0.0);
+  constexpr double f3 = __builtin_fmin(+0.0, -0.0);
+  constexpr float f4 = __builtin_fminf(NAN, NAN);
+  constexpr float f5 = __builtin_fminf(NAN, -1);
+  constexpr float f6 = __builtin_fminf(-INFINITY, 0);
+  constexpr float f7 = __builtin_fminf(INFINITY, 0);
+
+  // frexp
+  constexpr double f8 = __builtin_frexp(123.45, );
+  constexpr double f9 = __builtin_frexp(0.0, );
+  constexpr double f10 = __builtin_frexp(-0.0, );
+  constexpr double f11 = __builtin_frexpf(NAN, );
+  constexpr double f12 = __builtin_frexpf(-NAN, );
+  constexpr double f13 = __builtin_frexpf(INFINITY, );
+  constexpr double f14 = __builtin_frexpf(INFINITY, );
+
+  return 0;
+}
+
+// CHECK: store double 1.30e+00, ptr {{.*}}
+// CHECK: store double -0.00e+00, ptr {{.*}}
+// CHECK: store double -0.00e+00, ptr {{.*}}
+// WIN: store float 0xFFF8, ptr {{.*}}
+// LNX: store float 0x7FF8, ptr {{.*}}
+// CHECK: store float -1.00e+00, ptr {{.*}}
+// CHECK: store float 0xFFF0, ptr {{.*}}
+
+// CHECK: store double 0x3FEEDCCD, ptr {{.*}}
+// CHECK: store double 0.00e+00, ptr {{.*}}
+// CHECK: store double -0.00e+00, ptr {{.*}}
+// CHECK: store double 0xFFF8, ptr 

[clang] [C++23] [CLANG] Adding C++23 constexpr math functions: fmin and frexp. (PR #88978)

2024-04-22 Thread Zahira Ammarguellat via cfe-commits

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


[clang] [C++23] [CLANG] Adding C++23 constexpr math functions: fmin and frexp. (PR #88978)

2024-04-22 Thread Zahira Ammarguellat via cfe-commits


@@ -2922,7 +2922,7 @@ static bool handleFloatFloatBinOp(EvalInfo , const 
BinaryOperator *E,
   //   If during the evaluation of an expression, the result is not
   //   mathematically defined [...], the behavior is undefined.
   // FIXME: C++ rules require us to not conform to IEEE 754 here.
-  if (LHS.isNaN()) {
+  if (!Info.getLangOpts().CPlusPlus23 && LHS.isNaN()) {

zahiraam wrote:

This is basically to allow calls of __bultin_func(NAN, NAN) to be legal.

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


[clang] [C++23] [CLANG] Adding C++23 constexpr math functions: fmin and frexp. (PR #88978)

2024-04-22 Thread Zahira Ammarguellat via cfe-commits

https://github.com/zahiraam updated 
https://github.com/llvm/llvm-project/pull/88978

>From 3acc848f4fcc68445dfc849f9c6f8d384d3692af Mon Sep 17 00:00:00 2001
From: Zahira Ammarguellat 
Date: Tue, 16 Apr 2024 13:09:58 -0700
Subject: [PATCH 1/2] Adding C23 constexpr math functions fmin and frexp.

---
 clang/include/clang/Basic/Builtins.td |  4 +--
 clang/lib/AST/ExprConstant.cpp| 16 -
 clang/test/CodeGen/constexpr-math.cpp | 51 +++
 3 files changed, 68 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/CodeGen/constexpr-math.cpp

diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index 52c0dd52c28b11..a35c77286229ff 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -3440,7 +3440,7 @@ def Fmod : FPMathTemplate, LibBuiltin<"math.h"> {
 
 def Frexp : FPMathTemplate, LibBuiltin<"math.h"> {
   let Spellings = ["frexp"];
-  let Attributes = [NoThrow];
+  let Attributes = [NoThrow, Constexpr];
   let Prototype = "T(T, int*)";
   let AddBuiltinPrefixedAlias = 1;
 }
@@ -3618,7 +3618,7 @@ def Fmax : FPMathTemplate, LibBuiltin<"math.h"> {
 
 def Fmin : FPMathTemplate, LibBuiltin<"math.h"> {
   let Spellings = ["fmin"];
-  let Attributes = [NoThrow, Const];
+  let Attributes = [NoThrow, Const, Constexpr];
   let Prototype = "T(T, T)";
   let AddBuiltinPrefixedAlias = 1;
   let OnlyBuiltinPrefixedAliasIsConstexpr = 1;
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 5a36621dc5cce2..506621ac7e9c1b 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -2922,7 +2922,7 @@ static bool handleFloatFloatBinOp(EvalInfo , const 
BinaryOperator *E,
   //   If during the evaluation of an expression, the result is not
   //   mathematically defined [...], the behavior is undefined.
   // FIXME: C++ rules require us to not conform to IEEE 754 here.
-  if (LHS.isNaN()) {
+  if (!Info.getLangOpts().CPlusPlus23 && LHS.isNaN()) {
 Info.CCEDiag(E, diag::note_constexpr_float_arithmetic) << LHS.isNaN();
 return Info.noteUndefinedBehavior();
   }
@@ -14547,6 +14547,18 @@ bool FloatExprEvaluator::VisitCallExpr(const CallExpr 
*E) {
   default:
 return false;
 
+  case Builtin::BI__builtin_frexpf:
+  case Builtin::BI__builtin_frexp: {
+LValue Pointer;
+if (!EvaluateFloat(E->getArg(0), Result, Info) ||
+!EvaluatePointer(E->getArg(1), Pointer, Info))
+  return false;
+llvm::RoundingMode RM =
+E->getFPFeaturesInEffect(Info.Ctx.getLangOpts()).getRoundingMode();
+int FrexpExp;
+Result = llvm::frexp(Result, FrexpExp, RM);
+return true;
+  }
   case Builtin::BI__builtin_huge_val:
   case Builtin::BI__builtin_huge_valf:
   case Builtin::BI__builtin_huge_vall:
@@ -14638,6 +14650,8 @@ bool FloatExprEvaluator::VisitCallExpr(const CallExpr 
*E) {
 return true;
   }
 
+  case Builtin::BIfmin:
+  case Builtin::BIfminf:
   case Builtin::BI__builtin_fmin:
   case Builtin::BI__builtin_fminf:
   case Builtin::BI__builtin_fminl:
diff --git a/clang/test/CodeGen/constexpr-math.cpp 
b/clang/test/CodeGen/constexpr-math.cpp
new file mode 100644
index 00..446bf3f4f7a504
--- /dev/null
+++ b/clang/test/CodeGen/constexpr-math.cpp
@@ -0,0 +1,51 @@
+// RUN: %clang_cc1 -x c++ -triple x86_64-unknown-unknown -std=c++23 \
+// RUN: -emit-llvm -o - %s | FileCheck %s
+
+// RUN %clang_cc1 -x c++ -triple x86_64-linux-gnu -emit-llvm -o - %s \
+// RUN -std=c++23
+
+#define INFINITY ((float)(1e+300 * 1e+300))
+#define NAN  (-(float)(INFINITY * 0.0F))
+
+//constexpr double frexp ( double num, int* exp );
+//constexpr float foo ( float num, int* exp );
+
+int func()
+{
+  int i;
+
+  // fmin
+  constexpr double f1 = __builtin_fmin(15.24, 1.3);
+  constexpr double f2 = __builtin_fmin(-0.0, +0.0);
+  constexpr double f3 = __builtin_fmin(+0.0, -0.0);
+  constexpr float f4 = __builtin_fminf(NAN, NAN);
+  constexpr float f5 = __builtin_fminf(NAN, -1);
+  constexpr float f6 = __builtin_fminf(-INFINITY, 0);
+  constexpr float f7 = __builtin_fminf(INFINITY, 0);
+
+  // frexp
+  constexpr double f8 = __builtin_frexp(123.45, );
+  constexpr double f9 = __builtin_frexp(0.0, );
+  constexpr double f10 = __builtin_frexp(-0.0, );
+  constexpr double f11 = __builtin_frexpf(NAN, );
+  constexpr double f12 = __builtin_frexpf(-NAN, );
+  constexpr double f13 = __builtin_frexpf(INFINITY, );
+  constexpr double f14 = __builtin_frexpf(INFINITY, );
+
+  return 0;
+}
+
+// CHECK: store double 1.30e+00, ptr {{.*}}
+// CHECK: store double -0.00e+00, ptr {{.*}}
+// CHECK: store double -0.00e+00, ptr {{.*}}
+// CHECK: store float 0xFFF8, ptr {{.*}}
+// CHECK: store float -1.00e+00, ptr {{.*}}
+// CHECK: store float 0xFFF0, ptr {{.*}}
+
+// CHECK: store double 0x3FEEDCCD, ptr {{.*}}
+// CHECK: store double 0.00e+00, ptr {{.*}}
+// CHECK: store double -0.00e+00, ptr {{.*}}
+// CHECK: 

[clang] [clang] fix half && bfloat16 convert node expr codegen (PR #89051)

2024-04-22 Thread Eli Friedman via cfe-commits

efriedma-quic wrote:

Looks like automation didn't trigger, but:

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

(I'll also wait a bit to give @arsenm a chance to respond.)

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


  1   2   3   4   5   >