[clang] [clang] Additional FP classification functions (PR #69041)

2023-10-15 Thread Serge Pavlov via cfe-commits

https://github.com/spavloff updated 
https://github.com/llvm/llvm-project/pull/69041

>From 1374e323198d7188e688845eb951df4148a1dfd8 Mon Sep 17 00:00:00 2001
From: Serge Pavlov 
Date: Wed, 11 Oct 2023 14:27:26 +0700
Subject: [PATCH 1/5] [clang] Additional FP classification functions

C language standard defined library functions `iszero`, `issignaling`
and `issubnormal`, which did not have counterparts among clang
builtin functions. This change adds new functions:

__builtin_iszero
__builtin_issubnormal
__builtin_issignaling

They provide builtin implementation for the missing standard functions.
---
 clang/docs/ReleaseNotes.rst|  2 ++
 clang/include/clang/Basic/Builtins.def |  3 +++
 clang/lib/CodeGen/CGBuiltin.cpp| 24 
 clang/test/CodeGen/builtins.c  | 15 +++
 4 files changed, 44 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 2d918967e7f0b02..2453804cd7735be 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -621,6 +621,8 @@ Floating Point Support in Clang
 - Add ``__builtin_exp10``, ``__builtin_exp10f``,
   ``__builtin_exp10f16``, ``__builtin_exp10l`` and
   ``__builtin_exp10f128`` builtins.
+- Add ``__builtin_iszero``, ``__builtin_issignaling`` and
+  ``__builtin_issubnormal``.
 
 AST Matchers
 
diff --git a/clang/include/clang/Basic/Builtins.def 
b/clang/include/clang/Basic/Builtins.def
index 6ea8484606cfd5d..ebcb5b45e5bdc23 100644
--- a/clang/include/clang/Basic/Builtins.def
+++ b/clang/include/clang/Basic/Builtins.def
@@ -494,6 +494,9 @@ BUILTIN(__builtin_isinf,  "i.", "FnctE")
 BUILTIN(__builtin_isinf_sign, "i.", "FnctE")
 BUILTIN(__builtin_isnan,  "i.", "FnctE")
 BUILTIN(__builtin_isnormal,   "i.", "FnctE")
+BUILTIN(__builtin_issubnormal,"i.", "FnctE")
+BUILTIN(__builtin_iszero, "i.", "FnctE")
+BUILTIN(__builtin_issignaling,"i.", "FnctE")
 BUILTIN(__builtin_isfpclass,  "i.", "nctE")
 
 // FP signbit builtins
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 8cb7943df9a7822..5d3946a84b6c34a 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -3287,6 +3287,14 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
ConvertType(E->getType(;
   }
 
+  case Builtin::BI__builtin_issignaling: {
+CodeGenFunction::CGFPOptionsRAII FPOptsRAII(*this, E);
+Value *V = EmitScalarExpr(E->getArg(0));
+return RValue::get(
+Builder.CreateZExt(Builder.createIsFPClass(V, FPClassTest::fcSNan),
+   ConvertType(E->getType(;
+  }
+
   case Builtin::BI__builtin_isinf: {
 CodeGenFunction::CGFPOptionsRAII FPOptsRAII(*this, E);
 Value *V = EmitScalarExpr(E->getArg(0));
@@ -3321,6 +3329,22 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
ConvertType(E->getType(;
   }
 
+  case Builtin::BI__builtin_issubnormal: {
+CodeGenFunction::CGFPOptionsRAII FPOptsRAII(*this, E);
+Value *V = EmitScalarExpr(E->getArg(0));
+return RValue::get(
+Builder.CreateZExt(Builder.createIsFPClass(V, 
FPClassTest::fcSubnormal),
+   ConvertType(E->getType(;
+  }
+
+  case Builtin::BI__builtin_iszero: {
+CodeGenFunction::CGFPOptionsRAII FPOptsRAII(*this, E);
+Value *V = EmitScalarExpr(E->getArg(0));
+return RValue::get(
+Builder.CreateZExt(Builder.createIsFPClass(V, FPClassTest::fcZero),
+   ConvertType(E->getType(;
+  }
+
   case Builtin::BI__builtin_isfpclass: {
 Expr::EvalResult Result;
 if (!E->getArg(1)->EvaluateAsInt(Result, CGM.getContext()))
diff --git a/clang/test/CodeGen/builtins.c b/clang/test/CodeGen/builtins.c
index 1b1b2cd6413a344..ce1182b724dcc21 100644
--- a/clang/test/CodeGen/builtins.c
+++ b/clang/test/CodeGen/builtins.c
@@ -64,6 +64,9 @@ int main(void) {
   P(isinf_sign, (1.));
   P(isnan, (1.));
   P(isfinite, (1.));
+  P(iszero, (1.));
+  P(issubnormal, (1.));
+  P(issignaling, (1.));
   P(isfpclass, (1., 1));
 
   // Bitwise & Numeric Functions
@@ -270,6 +273,18 @@ void test_float_builtins(__fp16 *H, float F, double D, 
long double LD) {
   // CHECK: [[TMP:%.*]] = call i1 @llvm.is.fpclass.f32(float {{.*}}, i32 264)
   // CHECK: zext i1 [[TMP]] to i32
 
+  res = __builtin_issubnormal(F);
+  // CHECK: [[TMP:%.*]] = call i1 @llvm.is.fpclass.f32(float {{.*}}, i32 144)
+  // CHECK: zext i1 [[TMP]] to i32
+
+  res = __builtin_iszero(F);
+  // CHECK: [[TMP:%.*]] = call i1 @llvm.is.fpclass.f32(float {{.*}}, i32 96)
+  // CHECK: zext i1 [[TMP]] to i32
+
+  res = __builtin_issignaling(F);
+  // CHECK: [[TMP:%.*]] = call i1 @llvm.is.fpclass.f32(float {{.*}}, i32 1)
+  // CHECK: zext i1 [[TMP]] to i32
+
   res = __builtin_flt_rounds();
   // CHECK: call i32 @llvm.get.rounding(
 }

>From 

[PATCH] D157252: [clang][ExprConst] Handle 0 type size in builtin_memcpy etc.

2023-10-15 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added a comment.

Ping


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157252/new/

https://reviews.llvm.org/D157252

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


[clang] [clang][Diagnostics] Highlight code snippets (PR #66514)

2023-10-15 Thread Timm Baeder via cfe-commits
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= 
Message-ID:
In-Reply-To: 


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


[clang] [clang][Diagnostics] Highlight code snippets (PR #66514)

2023-10-15 Thread Timm Baeder via cfe-commits
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= 
Message-ID:
In-Reply-To: 


https://github.com/tbaederr updated 
https://github.com/llvm/llvm-project/pull/66514

>From 11e7ee626abf9edbcdd2cdcd6ee79f7a0792788c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Fri, 15 Sep 2023 15:51:39 +0200
Subject: [PATCH 01/16] [clang][Diagnostics] Highlight code snippets

Add some primitive syntax highlighting to our code snippet output.
---
 .../clang/Frontend/CodeSnippetHighlighter.h   |  46 +++
 clang/include/clang/Frontend/TextDiagnostic.h |   2 +
 clang/lib/Frontend/CMakeLists.txt |   1 +
 clang/lib/Frontend/CodeSnippetHighlighter.cpp | 120 ++
 clang/lib/Frontend/TextDiagnostic.cpp |  26 
 5 files changed, 195 insertions(+)
 create mode 100644 clang/include/clang/Frontend/CodeSnippetHighlighter.h
 create mode 100644 clang/lib/Frontend/CodeSnippetHighlighter.cpp

diff --git a/clang/include/clang/Frontend/CodeSnippetHighlighter.h 
b/clang/include/clang/Frontend/CodeSnippetHighlighter.h
new file mode 100644
index 000..776954b59e2e1a8
--- /dev/null
+++ b/clang/include/clang/Frontend/CodeSnippetHighlighter.h
@@ -0,0 +1,46 @@
+//===--- CodeSnippetHighlighter.h - Code snippet highlighting ---*- 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_FRONTEND_CODESNIPPETHIGHLIGHTER_H
+#define LLVM_CLANG_FRONTEND_CODESNIPPETHIGHLIGHTER_H
+
+#include "clang/Basic/LangOptions.h"
+#include "llvm/ADT/SmallSet.h"
+#include "llvm/Support/raw_ostream.h"
+#include 
+
+namespace clang {
+
+struct StyleRange {
+  unsigned Start;
+  unsigned End;
+  const enum llvm::raw_ostream::Colors c;
+};
+
+class CodeSnippetHighlighter final {
+public:
+  CodeSnippetHighlighter() = default;
+
+  /// Produce StyleRanges for the given line.
+  /// The returned vector contains non-overlapping style ranges. They are 
sorted
+  /// from beginning of the line to the end.
+  std::vector highlightLine(llvm::StringRef SourceLine,
+const LangOptions );
+
+private:
+  bool Initialized = false;
+  /// Fills Keywords and Literals.
+  void ensureTokenData();
+
+  llvm::SmallSet Keywords;
+  llvm::SmallSet Literals;
+};
+
+} // namespace clang
+
+#endif
diff --git a/clang/include/clang/Frontend/TextDiagnostic.h 
b/clang/include/clang/Frontend/TextDiagnostic.h
index 7eb0ab0cdc9bca8..59fd4d4f9408d48 100644
--- a/clang/include/clang/Frontend/TextDiagnostic.h
+++ b/clang/include/clang/Frontend/TextDiagnostic.h
@@ -15,6 +15,7 @@
 #ifndef LLVM_CLANG_FRONTEND_TEXTDIAGNOSTIC_H
 #define LLVM_CLANG_FRONTEND_TEXTDIAGNOSTIC_H
 
+#include "clang/Frontend/CodeSnippetHighlighter.h"
 #include "clang/Frontend/DiagnosticRenderer.h"
 
 namespace clang {
@@ -33,6 +34,7 @@ namespace clang {
 /// printing coming out of libclang.
 class TextDiagnostic : public DiagnosticRenderer {
   raw_ostream 
+  CodeSnippetHighlighter SnippetHighlighter;
 
 public:
   TextDiagnostic(raw_ostream ,
diff --git a/clang/lib/Frontend/CMakeLists.txt 
b/clang/lib/Frontend/CMakeLists.txt
index 1e5f0a859dfd568..f3547f771593093 100644
--- a/clang/lib/Frontend/CMakeLists.txt
+++ b/clang/lib/Frontend/CMakeLists.txt
@@ -42,6 +42,7 @@ add_clang_library(clangFrontend
   TextDiagnosticPrinter.cpp
   VerifyDiagnosticConsumer.cpp
   InterfaceStubFunctionsConsumer.cpp
+  CodeSnippetHighlighter.cpp
 
   DEPENDS
   ClangDriverOptions
diff --git a/clang/lib/Frontend/CodeSnippetHighlighter.cpp 
b/clang/lib/Frontend/CodeSnippetHighlighter.cpp
new file mode 100644
index 000..829a533ad2692e5
--- /dev/null
+++ b/clang/lib/Frontend/CodeSnippetHighlighter.cpp
@@ -0,0 +1,120 @@
+
+#include "clang/Frontend/CodeSnippetHighlighter.h"
+#include "clang/Basic/DiagnosticOptions.h"
+#include "clang/Basic/SourceManager.h"
+#include "clang/Lex/Lexer.h"
+#include "llvm/Support/raw_ostream.h"
+
+using namespace clang;
+
+void CodeSnippetHighlighter::ensureTokenData() {
+  if (Initialized)
+return;
+
+  // List of keywords, literals and types we want to highlight.
+  // These are best-effort, as is everything we do wrt. highlighting.
+  Keywords.insert("_Static_assert");
+  Keywords.insert("auto");
+  Keywords.insert("concept");
+  Keywords.insert("const");
+  Keywords.insert("consteval");
+  Keywords.insert("constexpr");
+  Keywords.insert("delete");
+  Keywords.insert("do");
+  Keywords.insert("else");
+  

[clang] [AMDGPU] Remove Code Object V3 (PR #67118)

2023-10-15 Thread Matt Arsenault via cfe-commits

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


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


[clang] [clang][ExprConst] Fix crash on uninitialized array subobject (PR #67817)

2023-10-15 Thread via cfe-commits


@@ -404,7 +404,7 @@ bool CheckPure(InterpState , CodePtr OpPC, const 
CXXMethodDecl *MD) {
 static void DiagnoseUninitializedSubobject(InterpState , const SourceInfo 
,
const FieldDecl *SubObjDecl) {
   assert(SubObjDecl && "Subobject declaration does not exist");
-  S.FFDiag(SI, diag::note_constexpr_uninitialized) << SubObjDecl;
+  S.FFDiag(SI, diag::note_constexpr_uninitialized) << true << SubObjDecl;

cor3ntin wrote:

Can you add a comment before true ? and maybe use an integer instead `<< /* of 
type */ 1 << ` - same in other places

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


[clang] [Clang][LoongArch] Support basic fp16, fp128 (PR #68851)

2023-10-15 Thread via cfe-commits

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


[clang] [clang] Additional FP classification functions (PR #69041)

2023-10-15 Thread Serge Pavlov via cfe-commits

https://github.com/spavloff updated 
https://github.com/llvm/llvm-project/pull/69041

>From 1374e323198d7188e688845eb951df4148a1dfd8 Mon Sep 17 00:00:00 2001
From: Serge Pavlov 
Date: Wed, 11 Oct 2023 14:27:26 +0700
Subject: [PATCH 1/4] [clang] Additional FP classification functions

C language standard defined library functions `iszero`, `issignaling`
and `issubnormal`, which did not have counterparts among clang
builtin functions. This change adds new functions:

__builtin_iszero
__builtin_issubnormal
__builtin_issignaling

They provide builtin implementation for the missing standard functions.
---
 clang/docs/ReleaseNotes.rst|  2 ++
 clang/include/clang/Basic/Builtins.def |  3 +++
 clang/lib/CodeGen/CGBuiltin.cpp| 24 
 clang/test/CodeGen/builtins.c  | 15 +++
 4 files changed, 44 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 2d918967e7f0b02..2453804cd7735be 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -621,6 +621,8 @@ Floating Point Support in Clang
 - Add ``__builtin_exp10``, ``__builtin_exp10f``,
   ``__builtin_exp10f16``, ``__builtin_exp10l`` and
   ``__builtin_exp10f128`` builtins.
+- Add ``__builtin_iszero``, ``__builtin_issignaling`` and
+  ``__builtin_issubnormal``.
 
 AST Matchers
 
diff --git a/clang/include/clang/Basic/Builtins.def 
b/clang/include/clang/Basic/Builtins.def
index 6ea8484606cfd5d..ebcb5b45e5bdc23 100644
--- a/clang/include/clang/Basic/Builtins.def
+++ b/clang/include/clang/Basic/Builtins.def
@@ -494,6 +494,9 @@ BUILTIN(__builtin_isinf,  "i.", "FnctE")
 BUILTIN(__builtin_isinf_sign, "i.", "FnctE")
 BUILTIN(__builtin_isnan,  "i.", "FnctE")
 BUILTIN(__builtin_isnormal,   "i.", "FnctE")
+BUILTIN(__builtin_issubnormal,"i.", "FnctE")
+BUILTIN(__builtin_iszero, "i.", "FnctE")
+BUILTIN(__builtin_issignaling,"i.", "FnctE")
 BUILTIN(__builtin_isfpclass,  "i.", "nctE")
 
 // FP signbit builtins
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 8cb7943df9a7822..5d3946a84b6c34a 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -3287,6 +3287,14 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
ConvertType(E->getType(;
   }
 
+  case Builtin::BI__builtin_issignaling: {
+CodeGenFunction::CGFPOptionsRAII FPOptsRAII(*this, E);
+Value *V = EmitScalarExpr(E->getArg(0));
+return RValue::get(
+Builder.CreateZExt(Builder.createIsFPClass(V, FPClassTest::fcSNan),
+   ConvertType(E->getType(;
+  }
+
   case Builtin::BI__builtin_isinf: {
 CodeGenFunction::CGFPOptionsRAII FPOptsRAII(*this, E);
 Value *V = EmitScalarExpr(E->getArg(0));
@@ -3321,6 +3329,22 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
ConvertType(E->getType(;
   }
 
+  case Builtin::BI__builtin_issubnormal: {
+CodeGenFunction::CGFPOptionsRAII FPOptsRAII(*this, E);
+Value *V = EmitScalarExpr(E->getArg(0));
+return RValue::get(
+Builder.CreateZExt(Builder.createIsFPClass(V, 
FPClassTest::fcSubnormal),
+   ConvertType(E->getType(;
+  }
+
+  case Builtin::BI__builtin_iszero: {
+CodeGenFunction::CGFPOptionsRAII FPOptsRAII(*this, E);
+Value *V = EmitScalarExpr(E->getArg(0));
+return RValue::get(
+Builder.CreateZExt(Builder.createIsFPClass(V, FPClassTest::fcZero),
+   ConvertType(E->getType(;
+  }
+
   case Builtin::BI__builtin_isfpclass: {
 Expr::EvalResult Result;
 if (!E->getArg(1)->EvaluateAsInt(Result, CGM.getContext()))
diff --git a/clang/test/CodeGen/builtins.c b/clang/test/CodeGen/builtins.c
index 1b1b2cd6413a344..ce1182b724dcc21 100644
--- a/clang/test/CodeGen/builtins.c
+++ b/clang/test/CodeGen/builtins.c
@@ -64,6 +64,9 @@ int main(void) {
   P(isinf_sign, (1.));
   P(isnan, (1.));
   P(isfinite, (1.));
+  P(iszero, (1.));
+  P(issubnormal, (1.));
+  P(issignaling, (1.));
   P(isfpclass, (1., 1));
 
   // Bitwise & Numeric Functions
@@ -270,6 +273,18 @@ void test_float_builtins(__fp16 *H, float F, double D, 
long double LD) {
   // CHECK: [[TMP:%.*]] = call i1 @llvm.is.fpclass.f32(float {{.*}}, i32 264)
   // CHECK: zext i1 [[TMP]] to i32
 
+  res = __builtin_issubnormal(F);
+  // CHECK: [[TMP:%.*]] = call i1 @llvm.is.fpclass.f32(float {{.*}}, i32 144)
+  // CHECK: zext i1 [[TMP]] to i32
+
+  res = __builtin_iszero(F);
+  // CHECK: [[TMP:%.*]] = call i1 @llvm.is.fpclass.f32(float {{.*}}, i32 96)
+  // CHECK: zext i1 [[TMP]] to i32
+
+  res = __builtin_issignaling(F);
+  // CHECK: [[TMP:%.*]] = call i1 @llvm.is.fpclass.f32(float {{.*}}, i32 1)
+  // CHECK: zext i1 [[TMP]] to i32
+
   res = __builtin_flt_rounds();
   // CHECK: call i32 @llvm.get.rounding(
 }

>From 

[clang] LoongArch fp16,fp128 basic support (PR #68851)

2023-10-15 Thread via cfe-commits

https://github.com/Xinmudotmoe updated 
https://github.com/llvm/llvm-project/pull/68851

>From 2ef1ddfb977da35f31f1f351ac4daf0478fff166 Mon Sep 17 00:00:00 2001
From: xinmu 
Date: Thu, 12 Oct 2023 13:36:34 +0800
Subject: [PATCH 1/3] LoongArch fp16,fp128 basic support

---
 clang/lib/Basic/Targets/LoongArch.h | 2 ++
 clang/test/CodeGen/fp16-ops.c   | 1 +
 llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp | 7 +++
 3 files changed, 10 insertions(+)

diff --git a/clang/lib/Basic/Targets/LoongArch.h 
b/clang/lib/Basic/Targets/LoongArch.h
index ba7fb78ab94cd23..b25857207acdedd 100644
--- a/clang/lib/Basic/Targets/LoongArch.h
+++ b/clang/lib/Basic/Targets/LoongArch.h
@@ -40,6 +40,8 @@ class LLVM_LIBRARY_VISIBILITY LoongArchTargetInfo : public 
TargetInfo {
 SuitableAlign = 128;
 WCharType = SignedInt;
 WIntType = UnsignedInt;
+HasFloat128 = true;
+HasFloat16 = true;
   }
 
   bool setCPU(const std::string ) override {
diff --git a/clang/test/CodeGen/fp16-ops.c b/clang/test/CodeGen/fp16-ops.c
index 0626e0aaed9d0c0..e230011a59402d4 100644
--- a/clang/test/CodeGen/fp16-ops.c
+++ b/clang/test/CodeGen/fp16-ops.c
@@ -2,6 +2,7 @@
 // RUN: %clang_cc1 -emit-llvm -o - -triple arm-none-linux-gnueabi %s | 
FileCheck %s --check-prefix=NOTNATIVE --check-prefix=CHECK
 // RUN: %clang_cc1 -emit-llvm -o - -triple aarch64-none-linux-gnueabi %s | 
FileCheck %s --check-prefix=NOTNATIVE --check-prefix=CHECK
 // RUN: %clang_cc1 -emit-llvm -o - -triple x86_64-linux-gnu %s | FileCheck %s 
--check-prefix=NOTNATIVE --check-prefix=CHECK
+// RUN: %clang_cc1 -emit-llvm -o - -triple loongarch64-linux-gnu %s | 
FileCheck %s --check-prefix=NOTNATIVE --check-prefix=CHECK
 // RUN: %clang_cc1 -emit-llvm -o - -triple arm-none-linux-gnueabi 
-fnative-half-type %s \
 // RUN:   | FileCheck %s --check-prefix=NATIVE-HALF
 // RUN: %clang_cc1 -emit-llvm -o - -triple aarch64-none-linux-gnueabi 
-fnative-half-type %s \
diff --git a/llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp 
b/llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
index 7d01887f24c1597..0295389e1a92e4c 100644
--- a/llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
+++ b/llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
@@ -214,6 +214,13 @@ LoongArchTargetLowering::LoongArchTargetLowering(const 
TargetMachine ,
   setOperationAction(ISD::FRINT, MVT::f64, Legal);
   }
 
+  setOperationAction(ISD::FP16_TO_FP,MVT::f32,   Expand);
+  setOperationAction(ISD::FP_TO_FP16,MVT::f32,   Expand);
+  setTruncStoreAction(MVT::f32, MVT::f16, Expand);
+  setLoadExtAction(ISD::EXTLOAD, MVT::f32, MVT::f16, Expand);
+  setLibcallName(RTLIB::FPEXT_F16_F32, "__extendhfsf2");
+  setLibcallName(RTLIB::FPROUND_F32_F16, "__truncsfhf2");
+
   // Set operations for 'LSX' feature.
 
   if (Subtarget.hasExtLSX())

>From d198dc7d6086fdd918529d6349b33169cbf59624 Mon Sep 17 00:00:00 2001
From: xinmu 
Date: Thu, 12 Oct 2023 18:02:53 +0800
Subject: [PATCH 2/3] fix whitespaces lint

---
 llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp 
b/llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
index 0295389e1a92e4c..f03f09127866483 100644
--- a/llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
+++ b/llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
@@ -214,8 +214,8 @@ LoongArchTargetLowering::LoongArchTargetLowering(const 
TargetMachine ,
   setOperationAction(ISD::FRINT, MVT::f64, Legal);
   }
 
-  setOperationAction(ISD::FP16_TO_FP,MVT::f32,   Expand);
-  setOperationAction(ISD::FP_TO_FP16,MVT::f32,   Expand);
+  setOperationAction(ISD::FP16_TO_FP, MVT::f32, Expand);
+  setOperationAction(ISD::FP_TO_FP16, MVT::f32, Expand);
   setTruncStoreAction(MVT::f32, MVT::f16, Expand);
   setLoadExtAction(ISD::EXTLOAD, MVT::f32, MVT::f16, Expand);
   setLibcallName(RTLIB::FPEXT_F16_F32, "__extendhfsf2");

>From a1739914f8d2017bb6a0141a02ae6c5cf6e9c164 Mon Sep 17 00:00:00 2001
From: xinmu 
Date: Mon, 16 Oct 2023 13:38:43 +0800
Subject: [PATCH 3/3] [Loongarch] add test unit

---
 clang/test/CodeGen/LoongArch/fp16-fp128-ops.c | 93 +++
 clang/test/CodeGen/fp16-ops.c |  1 -
 2 files changed, 93 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/CodeGen/LoongArch/fp16-fp128-ops.c

diff --git a/clang/test/CodeGen/LoongArch/fp16-fp128-ops.c 
b/clang/test/CodeGen/LoongArch/fp16-fp128-ops.c
new file mode 100644
index 000..678a0cf059342c1
--- /dev/null
+++ b/clang/test/CodeGen/LoongArch/fp16-fp128-ops.c
@@ -0,0 +1,93 @@
+// REQUIRES: loongarch-registered-target
+// RUN: %clang_cc1 -emit-llvm -o - -triple loongarch64-linux-gnu %s  \
+// RUN:| FileCheck %s --check-prefix=CHECK
+_Float16 ha1 = 0;
+_Float16 ha2 = 1;
+__float128 qa1 = 0;
+__float128 qa2 = 1;
+__float128 qresult = 0;
+_Float16 hresult;
+float fresult;
+double dresult;
+int status;
+
+void 

[clang] [RISCV] Implement shadow stack on shadow stack mode with Zicfiss. (PR #68075)

2023-10-15 Thread Yeting Kuo via cfe-commits

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


[clang] Remove experimental from Vector Crypto extensions (PR #69000)

2023-10-15 Thread Brandon Wu via cfe-commits

4vtomat wrote:

> Thanks for the patch, some very quick feedback and I'd highlight the first 
> bullet as the most important, as this is potentially a blocker for graduating 
> these extensions from experimental.
> 
> * My big concern with this would be the intrinsics - could you please comment 
> on the status of their standardisation?
> * While doing this change, it would make sense to update the header of 
> RISCVInstrInfoZvk.td. While it doesn't explicitly say it describes an 
> experimental version of the extension, it references 1.0.0-rc1 of the spec 
> while presumably there's now a 1.0.0-final?
> * Please update llvm/docs/RISCVUsage.rst
> * Please add a release note to llvm/docs/ReleaseNotes.rst

Currently I guess we're not finalized yet in 
https://github.com/riscv-non-isa/rvv-intrinsic-doc/pull/234.

> 
> Edit: When committing after review, the commit should be titled something 
> like "[RISCV] Remove experimental from vector crypto extensions".

Oh, thanks, I forgot it~

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


[clang] [clang] Additional FP classification functions (PR #69041)

2023-10-15 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 6e8013a1301ef31f3592035eae2ee08319edd318 
69c7f90dfe21b96f6bc2678b08d9f002b0b0584d -- clang/lib/AST/ExprConstant.cpp 
clang/lib/AST/Interp/Floating.h clang/lib/AST/Interp/InterpBuiltin.cpp 
clang/lib/CodeGen/CGBuiltin.cpp clang/lib/Sema/SemaChecking.cpp 
clang/test/AST/Interp/builtin-functions.cpp clang/test/CodeGen/builtins.c 
clang/test/Sema/constant-builtins-2.c
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/AST/Interp/InterpBuiltin.cpp 
b/clang/lib/AST/Interp/InterpBuiltin.cpp
index 36e16a558d98..87880a4aca48 100644
--- a/clang/lib/AST/Interp/InterpBuiltin.cpp
+++ b/clang/lib/AST/Interp/InterpBuiltin.cpp
@@ -304,7 +304,8 @@ static bool interp__builtin_isnan(InterpState , CodePtr 
OpPC,
 }
 
 static bool interp__builtin_issignaling(InterpState , CodePtr OpPC,
-  const InterpFrame *Frame, const Function *F) 
{
+const InterpFrame *Frame,
+const Function *F) {
   const Floating  = S.Stk.peek();
 
   pushInt(S, Arg.isSignaling());

``




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


[clang] 94d0a3c - [clang][Interp][NFC] Add comments to Descriptor ctors

2023-10-15 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-10-16T06:52:07+02:00
New Revision: 94d0a3c4a8b43759cb896bbbe8bd38e7e02eb70e

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

LOG: [clang][Interp][NFC] Add comments to Descriptor ctors

I can't tell these apart every time I look at them.

Added: 


Modified: 
clang/lib/AST/Interp/Descriptor.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/Descriptor.cpp 
b/clang/lib/AST/Interp/Descriptor.cpp
index 4ecb7466998e705..3990282686fe3d6 100644
--- a/clang/lib/AST/Interp/Descriptor.cpp
+++ b/clang/lib/AST/Interp/Descriptor.cpp
@@ -221,6 +221,7 @@ static BlockMoveFn getMoveArrayPrim(PrimType Type) {
   COMPOSITE_TYPE_SWITCH(Type, return moveArrayTy, return nullptr);
 }
 
+/// Primitives.
 Descriptor::Descriptor(const DeclTy , PrimType Type, MetadataSize MD,
bool IsConst, bool IsTemporary, bool IsMutable)
 : Source(D), ElemSize(primSize(Type)), Size(ElemSize),
@@ -231,6 +232,7 @@ Descriptor::Descriptor(const DeclTy , PrimType Type, 
MetadataSize MD,
   assert(Source && "Missing source");
 }
 
+/// Primitive arrays.
 Descriptor::Descriptor(const DeclTy , PrimType Type, MetadataSize MD,
size_t NumElems, bool IsConst, bool IsTemporary,
bool IsMutable)
@@ -243,6 +245,7 @@ Descriptor::Descriptor(const DeclTy , PrimType Type, 
MetadataSize MD,
   assert(Source && "Missing source");
 }
 
+/// Primitive unknown-size arrays.
 Descriptor::Descriptor(const DeclTy , PrimType Type, bool IsTemporary,
UnknownSize)
 : Source(D), ElemSize(primSize(Type)), Size(UnknownSizeMark), MDSize(0),
@@ -252,6 +255,7 @@ Descriptor::Descriptor(const DeclTy , PrimType Type, bool 
IsTemporary,
   assert(Source && "Missing source");
 }
 
+/// Arrays of composite elements.
 Descriptor::Descriptor(const DeclTy , Descriptor *Elem, MetadataSize MD,
unsigned NumElems, bool IsConst, bool IsTemporary,
bool IsMutable)
@@ -264,6 +268,7 @@ Descriptor::Descriptor(const DeclTy , Descriptor *Elem, 
MetadataSize MD,
   assert(Source && "Missing source");
 }
 
+/// Unknown-size arrays of composite elements.
 Descriptor::Descriptor(const DeclTy , Descriptor *Elem, bool IsTemporary,
UnknownSize)
 : Source(D), ElemSize(Elem->getAllocSize() + sizeof(InlineDescriptor)),
@@ -274,6 +279,7 @@ Descriptor::Descriptor(const DeclTy , Descriptor *Elem, 
bool IsTemporary,
   assert(Source && "Missing source");
 }
 
+/// Composite records.
 Descriptor::Descriptor(const DeclTy , Record *R, MetadataSize MD,
bool IsConst, bool IsTemporary, bool IsMutable)
 : Source(D), ElemSize(std::max(alignof(void *), R->getFullSize())),



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


[clang] [clang][ExprConst] Fix crash on uninitialized array subobject (PR #67817)

2023-10-15 Thread Takuya Shimizu via cfe-commits

https://github.com/hazohelet updated 
https://github.com/llvm/llvm-project/pull/67817

>From acb5d8286335f85732ede8d33ac2529e13a3f61b Mon Sep 17 00:00:00 2001
From: Takuya Shimizu 
Date: Fri, 29 Sep 2023 23:49:11 +0900
Subject: [PATCH 1/3] [clang][ExprConst] Fix crash on uninitialized array
 subobject

https://reviews.llvm.org/D146358 was assuming that all subobjects have
their own name (`SubobjectDecl`), but it was not true for array
elements.

Fixes https://github.com/llvm/llvm-project/issues/67317
---
 clang/include/clang/Basic/DiagnosticASTKinds.td |  2 +-
 clang/lib/AST/ExprConstant.cpp  | 13 +
 clang/lib/AST/Interp/Interp.cpp |  2 +-
 clang/test/SemaCXX/eval-crashes.cpp |  7 +++
 4 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticASTKinds.td 
b/clang/include/clang/Basic/DiagnosticASTKinds.td
index 0019553233fdef6..cebcefff53d18ae 100644
--- a/clang/include/clang/Basic/DiagnosticASTKinds.td
+++ b/clang/include/clang/Basic/DiagnosticASTKinds.td
@@ -69,7 +69,7 @@ def note_consteval_address_accessible : Note<
   "%select{pointer|reference}0 to a consteval declaration "
   "is not a constant expression">;
 def note_constexpr_uninitialized : Note<
-  "subobject %0 is not initialized">;
+  "subobject %select{of type |}0%1 is not initialized">;
 def note_constexpr_uninitialized_base : Note<
   "constructor of base class %0 is not called">;
 def note_constexpr_static_local : Note<
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index e5539dedec02a4b..bfa2837fe746da3 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -2411,10 +2411,15 @@ static bool 
CheckEvaluationResult(CheckEvaluationResultKind CERK,
   const FieldDecl *SubobjectDecl,
   CheckedTemporaries ) {
   if (!Value.hasValue()) {
-assert(SubobjectDecl && "SubobjectDecl shall be non-null");
-Info.FFDiag(DiagLoc, diag::note_constexpr_uninitialized) << SubobjectDecl;
-Info.Note(SubobjectDecl->getLocation(),
-  diag::note_constexpr_subobject_declared_here);
+if (SubobjectDecl) {
+  Info.FFDiag(DiagLoc, diag::note_constexpr_uninitialized)
+  << true << SubobjectDecl;
+  Info.Note(SubobjectDecl->getLocation(),
+diag::note_constexpr_subobject_declared_here);
+} else {
+  // FIXME: We should add a test to check the output of this case.
+  Info.FFDiag(DiagLoc, diag::note_constexpr_uninitialized) << false << 
Type;
+}
 return false;
   }
 
diff --git a/clang/lib/AST/Interp/Interp.cpp b/clang/lib/AST/Interp/Interp.cpp
index a4d6844ebe61722..51bf8f9197ae134 100644
--- a/clang/lib/AST/Interp/Interp.cpp
+++ b/clang/lib/AST/Interp/Interp.cpp
@@ -404,7 +404,7 @@ bool CheckPure(InterpState , CodePtr OpPC, const 
CXXMethodDecl *MD) {
 static void DiagnoseUninitializedSubobject(InterpState , const SourceInfo 
,
const FieldDecl *SubObjDecl) {
   assert(SubObjDecl && "Subobject declaration does not exist");
-  S.FFDiag(SI, diag::note_constexpr_uninitialized) << SubObjDecl;
+  S.FFDiag(SI, diag::note_constexpr_uninitialized) << true << SubObjDecl;
   S.Note(SubObjDecl->getLocation(),
  diag::note_constexpr_subobject_declared_here);
 }
diff --git a/clang/test/SemaCXX/eval-crashes.cpp 
b/clang/test/SemaCXX/eval-crashes.cpp
index 3e59ad31c559da8..ac04b113f99b7aa 100644
--- a/clang/test/SemaCXX/eval-crashes.cpp
+++ b/clang/test/SemaCXX/eval-crashes.cpp
@@ -54,3 +54,10 @@ namespace pr33140_10 {
   int a(const int  = 0);
   bool b() { return a() == a(); }
 }
+
+namespace GH67317 {
+struct array {
+  int ()[2];
+  array() : data(*new int[1][2]) {}
+};
+}

>From cd6fd87b28ffc94a5e45bcc763beec73d6d13e20 Mon Sep 17 00:00:00 2001
From: Takuya Shimizu 
Date: Sat, 30 Sep 2023 00:03:29 +0900
Subject: [PATCH 2/3] Add release note

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

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 52d5b9a3f66d155..12204d0cdc0bc45 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -397,6 +397,8 @@ Bug Fixes in This Version
   operator in C. No longer issuing a confusing diagnostic along the lines of
   "incompatible operand types ('foo' and 'foo')" with extensions such as matrix
   types. Fixes (`#69008 `_)
+- Fix crash from constexpr evaluator evaluating uninitialized arrays as rvalue.
+  Fixes (`#67317 `_)
 
 Bug Fixes to Compiler Builtins
 ^^

>From d49fbc1cb7e596f0c8210739410c24950d46b99e Mon Sep 17 00:00:00 2001
From: Takuya Shimizu 
Date: Mon, 16 Oct 2023 13:43:02 +0900
Subject: [PATCH 3/3] Add test to test the fallbacked output

---
 clang/lib/AST/ExprConstant.cpp   

[clang] [clang][ExprConst] Fix crash on uninitialized array subobject (PR #67817)

2023-10-15 Thread Takuya Shimizu via cfe-commits


@@ -2411,10 +2411,15 @@ static bool 
CheckEvaluationResult(CheckEvaluationResultKind CERK,
   const FieldDecl *SubobjectDecl,
   CheckedTemporaries ) {
   if (!Value.hasValue()) {
-assert(SubobjectDecl && "SubobjectDecl shall be non-null");
-Info.FFDiag(DiagLoc, diag::note_constexpr_uninitialized) << SubobjectDecl;
-Info.Note(SubobjectDecl->getLocation(),
-  diag::note_constexpr_subobject_declared_here);
+if (SubobjectDecl) {
+  Info.FFDiag(DiagLoc, diag::note_constexpr_uninitialized)
+  << true << SubobjectDecl;
+  Info.Note(SubobjectDecl->getLocation(),
+diag::note_constexpr_subobject_declared_here);
+} else {
+  // FIXME: We should add a test to check the output of this case.
+  Info.FFDiag(DiagLoc, diag::note_constexpr_uninitialized) << false << 
Type;

hazohelet wrote:

Finally I found a test case that can check the fallback diagnostic message: 
https://godbolt.org/z/Mc3nPq15n
Clang 16's output is a little weird in that it does not mention `new 
*char[3][1]` part, and this patch's fallback approach inherits this behavior.

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


[clang] [clang] Additional FP classification functions (PR #69041)

2023-10-15 Thread Serge Pavlov via cfe-commits

https://github.com/spavloff updated 
https://github.com/llvm/llvm-project/pull/69041

>From 1374e323198d7188e688845eb951df4148a1dfd8 Mon Sep 17 00:00:00 2001
From: Serge Pavlov 
Date: Wed, 11 Oct 2023 14:27:26 +0700
Subject: [PATCH 1/3] [clang] Additional FP classification functions

C language standard defined library functions `iszero`, `issignaling`
and `issubnormal`, which did not have counterparts among clang
builtin functions. This change adds new functions:

__builtin_iszero
__builtin_issubnormal
__builtin_issignaling

They provide builtin implementation for the missing standard functions.
---
 clang/docs/ReleaseNotes.rst|  2 ++
 clang/include/clang/Basic/Builtins.def |  3 +++
 clang/lib/CodeGen/CGBuiltin.cpp| 24 
 clang/test/CodeGen/builtins.c  | 15 +++
 4 files changed, 44 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 2d918967e7f0b02..2453804cd7735be 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -621,6 +621,8 @@ Floating Point Support in Clang
 - Add ``__builtin_exp10``, ``__builtin_exp10f``,
   ``__builtin_exp10f16``, ``__builtin_exp10l`` and
   ``__builtin_exp10f128`` builtins.
+- Add ``__builtin_iszero``, ``__builtin_issignaling`` and
+  ``__builtin_issubnormal``.
 
 AST Matchers
 
diff --git a/clang/include/clang/Basic/Builtins.def 
b/clang/include/clang/Basic/Builtins.def
index 6ea8484606cfd5d..ebcb5b45e5bdc23 100644
--- a/clang/include/clang/Basic/Builtins.def
+++ b/clang/include/clang/Basic/Builtins.def
@@ -494,6 +494,9 @@ BUILTIN(__builtin_isinf,  "i.", "FnctE")
 BUILTIN(__builtin_isinf_sign, "i.", "FnctE")
 BUILTIN(__builtin_isnan,  "i.", "FnctE")
 BUILTIN(__builtin_isnormal,   "i.", "FnctE")
+BUILTIN(__builtin_issubnormal,"i.", "FnctE")
+BUILTIN(__builtin_iszero, "i.", "FnctE")
+BUILTIN(__builtin_issignaling,"i.", "FnctE")
 BUILTIN(__builtin_isfpclass,  "i.", "nctE")
 
 // FP signbit builtins
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 8cb7943df9a7822..5d3946a84b6c34a 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -3287,6 +3287,14 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
ConvertType(E->getType(;
   }
 
+  case Builtin::BI__builtin_issignaling: {
+CodeGenFunction::CGFPOptionsRAII FPOptsRAII(*this, E);
+Value *V = EmitScalarExpr(E->getArg(0));
+return RValue::get(
+Builder.CreateZExt(Builder.createIsFPClass(V, FPClassTest::fcSNan),
+   ConvertType(E->getType(;
+  }
+
   case Builtin::BI__builtin_isinf: {
 CodeGenFunction::CGFPOptionsRAII FPOptsRAII(*this, E);
 Value *V = EmitScalarExpr(E->getArg(0));
@@ -3321,6 +3329,22 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
ConvertType(E->getType(;
   }
 
+  case Builtin::BI__builtin_issubnormal: {
+CodeGenFunction::CGFPOptionsRAII FPOptsRAII(*this, E);
+Value *V = EmitScalarExpr(E->getArg(0));
+return RValue::get(
+Builder.CreateZExt(Builder.createIsFPClass(V, 
FPClassTest::fcSubnormal),
+   ConvertType(E->getType(;
+  }
+
+  case Builtin::BI__builtin_iszero: {
+CodeGenFunction::CGFPOptionsRAII FPOptsRAII(*this, E);
+Value *V = EmitScalarExpr(E->getArg(0));
+return RValue::get(
+Builder.CreateZExt(Builder.createIsFPClass(V, FPClassTest::fcZero),
+   ConvertType(E->getType(;
+  }
+
   case Builtin::BI__builtin_isfpclass: {
 Expr::EvalResult Result;
 if (!E->getArg(1)->EvaluateAsInt(Result, CGM.getContext()))
diff --git a/clang/test/CodeGen/builtins.c b/clang/test/CodeGen/builtins.c
index 1b1b2cd6413a344..ce1182b724dcc21 100644
--- a/clang/test/CodeGen/builtins.c
+++ b/clang/test/CodeGen/builtins.c
@@ -64,6 +64,9 @@ int main(void) {
   P(isinf_sign, (1.));
   P(isnan, (1.));
   P(isfinite, (1.));
+  P(iszero, (1.));
+  P(issubnormal, (1.));
+  P(issignaling, (1.));
   P(isfpclass, (1., 1));
 
   // Bitwise & Numeric Functions
@@ -270,6 +273,18 @@ void test_float_builtins(__fp16 *H, float F, double D, 
long double LD) {
   // CHECK: [[TMP:%.*]] = call i1 @llvm.is.fpclass.f32(float {{.*}}, i32 264)
   // CHECK: zext i1 [[TMP]] to i32
 
+  res = __builtin_issubnormal(F);
+  // CHECK: [[TMP:%.*]] = call i1 @llvm.is.fpclass.f32(float {{.*}}, i32 144)
+  // CHECK: zext i1 [[TMP]] to i32
+
+  res = __builtin_iszero(F);
+  // CHECK: [[TMP:%.*]] = call i1 @llvm.is.fpclass.f32(float {{.*}}, i32 96)
+  // CHECK: zext i1 [[TMP]] to i32
+
+  res = __builtin_issignaling(F);
+  // CHECK: [[TMP:%.*]] = call i1 @llvm.is.fpclass.f32(float {{.*}}, i32 1)
+  // CHECK: zext i1 [[TMP]] to i32
+
   res = __builtin_flt_rounds();
   // CHECK: call i32 @llvm.get.rounding(
 }

>From 

[clang] [IRPGO] [Draft] Import vtable definitions in ThinTLO and use more efficient vtable comparison sequence with cost-benefit analysis (PR #69141)

2023-10-15 Thread Mingming Liu via cfe-commits

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


[clang] [clang][Interp] Correctly emit destructors for multi-dimensional arrays (PR #69140)

2023-10-15 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)


Changes

We were not taking those into account correctly when emitting destructors. Fix 
that and add tests for it.

Fixes #69115

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


2 Files Affected:

- (modified) clang/lib/AST/Interp/ByteCodeExprGen.cpp (+21-12) 
- (modified) clang/test/AST/Interp/arrays.cpp (+57) 


``diff
diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index e9e20b222d5d34f..122c505078c77ef 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -2661,19 +2661,28 @@ bool 
ByteCodeExprGen::emitRecordDestruction(const Descriptor *Desc) {
   // Arrays.
   if (Desc->isArray()) {
 const Descriptor *ElemDesc = Desc->ElemDesc;
-const Record *ElemRecord = ElemDesc->ElemRecord;
-assert(ElemRecord); // This is not a primitive array.
+assert(ElemDesc);
+
+// Don't need to do anything for these.
+if (ElemDesc->isPrimitiveArray())
+  return this->emitPopPtr(SourceInfo{});
+
+// If this is an array of record types, check if we need
+// to call the element destructors at all. If not, try
+// to save the work.
+if (const Record *ElemRecord = ElemDesc->ElemRecord) {
+  if (const CXXDestructorDecl *Dtor = ElemRecord->getDestructor();
+  !Dtor || Dtor->isTrivial())
+return this->emitPopPtr(SourceInfo{});
+}
 
-if (const CXXDestructorDecl *Dtor = ElemRecord->getDestructor();
-Dtor && !Dtor->isTrivial()) {
-  for (ssize_t I = Desc->getNumElems() - 1; I >= 0; --I) {
-if (!this->emitConstUint64(I, SourceInfo{}))
-  return false;
-if (!this->emitArrayElemPtrUint64(SourceInfo{}))
-  return false;
-if (!this->emitRecordDestruction(Desc->ElemDesc))
-  return false;
-  }
+for (ssize_t I = Desc->getNumElems() - 1; I >= 0; --I) {
+  if (!this->emitConstUint64(I, SourceInfo{}))
+return false;
+  if (!this->emitArrayElemPtrUint64(SourceInfo{}))
+return false;
+  if (!this->emitRecordDestruction(ElemDesc))
+return false;
 }
 return this->emitPopPtr(SourceInfo{});
   }
diff --git a/clang/test/AST/Interp/arrays.cpp b/clang/test/AST/Interp/arrays.cpp
index 281835f828bbd7c..3aa58443089d499 100644
--- a/clang/test/AST/Interp/arrays.cpp
+++ b/clang/test/AST/Interp/arrays.cpp
@@ -1,5 +1,7 @@
 // RUN: %clang_cc1 -fexperimental-new-constant-interpreter -verify %s
+// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -std=c++20 -verify 
%s
 // RUN: %clang_cc1 -verify=ref %s
+// RUN: %clang_cc1 -verify=ref -std=c++20 %s
 
 constexpr int m = 3;
 constexpr const int *foo[][5] = {
@@ -390,3 +392,58 @@ namespace StringZeroFill {
   static_assert(b[4] == '\0', "");
   static_assert(b[5] == '\0', "");
 }
+
+namespace GH69115 {
+  /// This used to crash because we were trying to emit destructors for the
+  /// array.
+  constexpr int foo() {
+int arr[2][2] = {1, 2, 3, 4};
+return 0;
+  }
+  static_assert(foo() == 0, "");
+
+  /// Test that we still emit the destructors for multi-dimensional
+  /// composite arrays.
+#if __cplusplus >= 202002L
+  constexpr void assert(bool C) {
+if (C)
+  return;
+// Invalid in constexpr.
+(void)(1 / 0); // expected-warning {{undefined}} \
+   // ref-warning {{undefined}}
+  }
+
+  class F {
+  public:
+int a;
+int *dtor;
+int 
+constexpr F(int a, int *dtor, int ) : a(a), dtor(dtor), idx(idx) {}
+constexpr ~F() noexcept(false){
+  dtor[idx] = a;
+  ++idx;
+}
+  };
+  constexpr int foo2() {
+int dtorIndices[] = {0, 0, 0, 0};
+int idx = 0;
+
+{
+  F arr[2][2] = {F(1, dtorIndices, idx),
+ F(2, dtorIndices, idx),
+ F(3, dtorIndices, idx),
+ F(4, dtorIndices, idx)};
+}
+
+/// Reverse-reverse order.
+assert(idx == 4);
+assert(dtorIndices[0] == 4);
+assert(dtorIndices[1] == 3);
+assert(dtorIndices[2] == 2);
+assert(dtorIndices[3] == 1);
+
+return 0;
+  }
+  static_assert(foo2() == 0, "");
+#endif
+}

``




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


[clang] [clang][Interp] Correctly emit destructors for multi-dimensional arrays (PR #69140)

2023-10-15 Thread Timm Baeder via cfe-commits

https://github.com/tbaederr created 
https://github.com/llvm/llvm-project/pull/69140

We were not taking those into account correctly when emitting destructors. Fix 
that and add tests for it.

Fixes #69115

>From 9a3a88061790193575dbf76c3ddb2c0566fd6543 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Mon, 16 Oct 2023 06:09:36 +0200
Subject: [PATCH] [clang][Interp] Correctly emit destructors for
 multi-dimensional arrays

We were not taking those into account correctly when emitting
destructors. Fix that and add tests for it.

Fixes #69115
---
 clang/lib/AST/Interp/ByteCodeExprGen.cpp | 33 +-
 clang/test/AST/Interp/arrays.cpp | 57 
 2 files changed, 78 insertions(+), 12 deletions(-)

diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index e9e20b222d5d34f..122c505078c77ef 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -2661,19 +2661,28 @@ bool 
ByteCodeExprGen::emitRecordDestruction(const Descriptor *Desc) {
   // Arrays.
   if (Desc->isArray()) {
 const Descriptor *ElemDesc = Desc->ElemDesc;
-const Record *ElemRecord = ElemDesc->ElemRecord;
-assert(ElemRecord); // This is not a primitive array.
+assert(ElemDesc);
+
+// Don't need to do anything for these.
+if (ElemDesc->isPrimitiveArray())
+  return this->emitPopPtr(SourceInfo{});
+
+// If this is an array of record types, check if we need
+// to call the element destructors at all. If not, try
+// to save the work.
+if (const Record *ElemRecord = ElemDesc->ElemRecord) {
+  if (const CXXDestructorDecl *Dtor = ElemRecord->getDestructor();
+  !Dtor || Dtor->isTrivial())
+return this->emitPopPtr(SourceInfo{});
+}
 
-if (const CXXDestructorDecl *Dtor = ElemRecord->getDestructor();
-Dtor && !Dtor->isTrivial()) {
-  for (ssize_t I = Desc->getNumElems() - 1; I >= 0; --I) {
-if (!this->emitConstUint64(I, SourceInfo{}))
-  return false;
-if (!this->emitArrayElemPtrUint64(SourceInfo{}))
-  return false;
-if (!this->emitRecordDestruction(Desc->ElemDesc))
-  return false;
-  }
+for (ssize_t I = Desc->getNumElems() - 1; I >= 0; --I) {
+  if (!this->emitConstUint64(I, SourceInfo{}))
+return false;
+  if (!this->emitArrayElemPtrUint64(SourceInfo{}))
+return false;
+  if (!this->emitRecordDestruction(ElemDesc))
+return false;
 }
 return this->emitPopPtr(SourceInfo{});
   }
diff --git a/clang/test/AST/Interp/arrays.cpp b/clang/test/AST/Interp/arrays.cpp
index 281835f828bbd7c..3aa58443089d499 100644
--- a/clang/test/AST/Interp/arrays.cpp
+++ b/clang/test/AST/Interp/arrays.cpp
@@ -1,5 +1,7 @@
 // RUN: %clang_cc1 -fexperimental-new-constant-interpreter -verify %s
+// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -std=c++20 -verify 
%s
 // RUN: %clang_cc1 -verify=ref %s
+// RUN: %clang_cc1 -verify=ref -std=c++20 %s
 
 constexpr int m = 3;
 constexpr const int *foo[][5] = {
@@ -390,3 +392,58 @@ namespace StringZeroFill {
   static_assert(b[4] == '\0', "");
   static_assert(b[5] == '\0', "");
 }
+
+namespace GH69115 {
+  /// This used to crash because we were trying to emit destructors for the
+  /// array.
+  constexpr int foo() {
+int arr[2][2] = {1, 2, 3, 4};
+return 0;
+  }
+  static_assert(foo() == 0, "");
+
+  /// Test that we still emit the destructors for multi-dimensional
+  /// composite arrays.
+#if __cplusplus >= 202002L
+  constexpr void assert(bool C) {
+if (C)
+  return;
+// Invalid in constexpr.
+(void)(1 / 0); // expected-warning {{undefined}} \
+   // ref-warning {{undefined}}
+  }
+
+  class F {
+  public:
+int a;
+int *dtor;
+int 
+constexpr F(int a, int *dtor, int ) : a(a), dtor(dtor), idx(idx) {}
+constexpr ~F() noexcept(false){
+  dtor[idx] = a;
+  ++idx;
+}
+  };
+  constexpr int foo2() {
+int dtorIndices[] = {0, 0, 0, 0};
+int idx = 0;
+
+{
+  F arr[2][2] = {F(1, dtorIndices, idx),
+ F(2, dtorIndices, idx),
+ F(3, dtorIndices, idx),
+ F(4, dtorIndices, idx)};
+}
+
+/// Reverse-reverse order.
+assert(idx == 4);
+assert(dtorIndices[0] == 4);
+assert(dtorIndices[1] == 3);
+assert(dtorIndices[2] == 2);
+assert(dtorIndices[3] == 1);
+
+return 0;
+  }
+  static_assert(foo2() == 0, "");
+#endif
+}

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


[clang-tools-extra] [libcxx] Unifying __is_trivial_equality_predicate and __is_trivial_plus_operation into __desugars_to (PR #68642)

2023-10-15 Thread Anton Rydahl via cfe-commits

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


[clang] [libcxx] Unifying __is_trivial_equality_predicate and __is_trivial_plus_operation into __desugars_to (PR #68642)

2023-10-15 Thread Anton Rydahl via cfe-commits

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


[clang-tools-extra] [libcxx] Unifying __is_trivial_equality_predicate and __is_trivial_plus_operation into __desugars_to (PR #68642)

2023-10-15 Thread Anton Rydahl via cfe-commits

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


[clang] [libcxx] Unifying __is_trivial_equality_predicate and __is_trivial_plus_operation into __desugars_to (PR #68642)

2023-10-15 Thread Anton Rydahl via cfe-commits

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


[clang-tools-extra] [libcxx] Unifying __is_trivial_equality_predicate and __is_trivial_plus_operation into __desugars_to (PR #68642)

2023-10-15 Thread Anton Rydahl via cfe-commits


@@ -41,13 +42,12 @@ _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI 
_LIBCPP_CONSTEXPR_SINCE_CXX20 boo
   return true;
 }
 
-template <
-class _Tp,
-class _Up,
-class _BinaryPredicate,
-__enable_if_t<__is_trivial_equality_predicate<_BinaryPredicate, _Tp, 
_Up>::value && !is_volatile<_Tp>::value &&
-  !is_volatile<_Up>::value && 
__libcpp_is_trivially_equality_comparable<_Tp, _Up>::value,
-  int> = 0>
+template < class _Tp,
+   class _Up,
+   class _BinaryPredicate,
+   __enable_if_t<__desugars_to<_BinaryPredicate, equal_to<_Tp> 
>::value && !is_volatile<_Tp>::value &&

AntonRydahl wrote:

Thanks a lot, Louis! I have tried to verify that the patch produces identical 
assembly for the above example compared to the main branch. Just to make sure 
that we are on the same page, this meant that I also had to remove
```
template 
struct __desugars_to, equal_to > : true_type {};
```
since otherwise all equality operators would be considered transparent.

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


[clang] [libcxx] Unifying __is_trivial_equality_predicate and __is_trivial_plus_operation into __desugars_to (PR #68642)

2023-10-15 Thread Anton Rydahl via cfe-commits


@@ -41,13 +42,12 @@ _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI 
_LIBCPP_CONSTEXPR_SINCE_CXX20 boo
   return true;
 }
 
-template <
-class _Tp,
-class _Up,
-class _BinaryPredicate,
-__enable_if_t<__is_trivial_equality_predicate<_BinaryPredicate, _Tp, 
_Up>::value && !is_volatile<_Tp>::value &&
-  !is_volatile<_Up>::value && 
__libcpp_is_trivially_equality_comparable<_Tp, _Up>::value,
-  int> = 0>
+template < class _Tp,
+   class _Up,
+   class _BinaryPredicate,
+   __enable_if_t<__desugars_to<_BinaryPredicate, equal_to<_Tp> 
>::value && !is_volatile<_Tp>::value &&

AntonRydahl wrote:

Thanks a lot, Louis! I have tried to verify that the patch produces identical 
assembly for the above example compared to the main branch. Just to make sure 
that we are on the same page, this meant that I also had to remove
```
template 
struct __desugars_to, equal_to > : true_type {};
```
since otherwise all equality operators would be considered transparent.

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


[clang-tools-extra] [libcxx] Unifying __is_trivial_equality_predicate and __is_trivial_plus_operation into __desugars_to (PR #68642)

2023-10-15 Thread Anton Rydahl via cfe-commits

https://github.com/AntonRydahl updated 
https://github.com/llvm/llvm-project/pull/68642

>From f0d93cc6a5cd485c654ab38221691db038bacc7d Mon Sep 17 00:00:00 2001
From: AntonRydahl 
Date: Mon, 9 Oct 2023 15:13:22 -0700
Subject: [PATCH 1/4] Merged __is_trivial_equality_predicate and
 __is_trivial_plus_operation into __desugars_to

---
 libcxx/include/CMakeLists.txt |  1 -
 libcxx/include/__algorithm/comp.h |  7 ++---
 libcxx/include/__algorithm/equal.h| 22 
 .../cpu_backends/transform_reduce.h   | 23 
 libcxx/include/__functional/operations.h  | 15 +--
 .../include/__functional/ranges_operations.h  |  7 ++---
 .../include/__numeric/pstl_transform_reduce.h |  2 +-
 .../include/__type_traits/operation_traits.h  |  4 +--
 .../include/__type_traits/predicate_traits.h  | 26 ---
 libcxx/include/module.modulemap.in|  1 -
 10 files changed, 40 insertions(+), 68 deletions(-)
 delete mode 100644 libcxx/include/__type_traits/predicate_traits.h

diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index 340353f8ebb41c4..7eb09a06ccd482e 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -813,7 +813,6 @@ set(files
   __type_traits/negation.h
   __type_traits/noexcept_move_assign_container.h
   __type_traits/operation_traits.h
-  __type_traits/predicate_traits.h
   __type_traits/promote.h
   __type_traits/rank.h
   __type_traits/remove_all_extents.h
diff --git a/libcxx/include/__algorithm/comp.h 
b/libcxx/include/__algorithm/comp.h
index 9474536615ffb67..0993c37cce36a6b 100644
--- a/libcxx/include/__algorithm/comp.h
+++ b/libcxx/include/__algorithm/comp.h
@@ -10,8 +10,9 @@
 #define _LIBCPP___ALGORITHM_COMP_H
 
 #include <__config>
+#include <__functional/operations.h>
 #include <__type_traits/integral_constant.h>
-#include <__type_traits/predicate_traits.h>
+#include <__type_traits/operation_traits.h>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #  pragma GCC system_header
@@ -26,8 +27,8 @@ struct __equal_to {
   }
 };
 
-template 
-struct __is_trivial_equality_predicate<__equal_to, _Lhs, _Rhs> : true_type {};
+template <>
+struct __desugars_to<__equal_to, std::equal_to<>> : true_type {};
 
 // The definition is required because __less is part of the ABI, but it's empty
 // because all comparisons should be transparent.
diff --git a/libcxx/include/__algorithm/equal.h 
b/libcxx/include/__algorithm/equal.h
index b69aeff92bb9289..35e82da15e4d058 100644
--- a/libcxx/include/__algorithm/equal.h
+++ b/libcxx/include/__algorithm/equal.h
@@ -15,6 +15,7 @@
 #include <__config>
 #include <__functional/identity.h>
 #include <__functional/invoke.h>
+#include <__functional/operations.h>
 #include <__iterator/distance.h>
 #include <__iterator/iterator_traits.h>
 #include <__string/constexpr_c_functions.h>
@@ -23,7 +24,7 @@
 #include <__type_traits/is_constant_evaluated.h>
 #include <__type_traits/is_equality_comparable.h>
 #include <__type_traits/is_volatile.h>
-#include <__type_traits/predicate_traits.h>
+#include <__type_traits/operation_traits.h>
 #include <__utility/move.h>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
@@ -41,13 +42,12 @@ _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI 
_LIBCPP_CONSTEXPR_SINCE_CXX20 boo
   return true;
 }
 
-template <
-class _Tp,
-class _Up,
-class _BinaryPredicate,
-__enable_if_t<__is_trivial_equality_predicate<_BinaryPredicate, _Tp, 
_Up>::value && !is_volatile<_Tp>::value &&
-  !is_volatile<_Up>::value && 
__libcpp_is_trivially_equality_comparable<_Tp, _Up>::value,
-  int> = 0>
+template < class _Tp,
+   class _Up,
+   class _BinaryPredicate,
+   __enable_if_t<__desugars_to<_BinaryPredicate, 
std::equal_to<>>::value && !is_volatile<_Tp>::value &&
+ !is_volatile<_Up>::value && 
__libcpp_is_trivially_equality_comparable<_Tp, _Up>::value,
+ int> = 0>
 _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 
bool
 __equal_iter_impl(_Tp* __first1, _Tp* __last1, _Up* __first2, 
_BinaryPredicate&) {
   return std::__constexpr_memcmp_equal(__first1, __first2, 
__element_count(__last1 - __first1));
@@ -94,12 +94,12 @@ template ::value && __is_identity<_Proj1>::value &&
+  __enable_if_t<__desugars_to<_Pred, std::equal_to<>>::value && 
__is_identity<_Proj1>::value &&
 __is_identity<_Proj2>::value && 
!is_volatile<_Tp>::value && !is_volatile<_Up>::value &&
 __libcpp_is_trivially_equality_comparable<_Tp, 
_Up>::value,
 int> = 0>
-_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 
bool __equal_impl(
-_Tp* __first1, _Tp* __last1, _Up* __first2, _Up*, _Pred&, _Proj1&, 
_Proj2&) {
+_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 
bool

[clang] [libcxx] Unifying __is_trivial_equality_predicate and __is_trivial_plus_operation into __desugars_to (PR #68642)

2023-10-15 Thread Anton Rydahl via cfe-commits

https://github.com/AntonRydahl updated 
https://github.com/llvm/llvm-project/pull/68642

>From f0d93cc6a5cd485c654ab38221691db038bacc7d Mon Sep 17 00:00:00 2001
From: AntonRydahl 
Date: Mon, 9 Oct 2023 15:13:22 -0700
Subject: [PATCH 1/4] Merged __is_trivial_equality_predicate and
 __is_trivial_plus_operation into __desugars_to

---
 libcxx/include/CMakeLists.txt |  1 -
 libcxx/include/__algorithm/comp.h |  7 ++---
 libcxx/include/__algorithm/equal.h| 22 
 .../cpu_backends/transform_reduce.h   | 23 
 libcxx/include/__functional/operations.h  | 15 +--
 .../include/__functional/ranges_operations.h  |  7 ++---
 .../include/__numeric/pstl_transform_reduce.h |  2 +-
 .../include/__type_traits/operation_traits.h  |  4 +--
 .../include/__type_traits/predicate_traits.h  | 26 ---
 libcxx/include/module.modulemap.in|  1 -
 10 files changed, 40 insertions(+), 68 deletions(-)
 delete mode 100644 libcxx/include/__type_traits/predicate_traits.h

diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index 340353f8ebb41c4..7eb09a06ccd482e 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -813,7 +813,6 @@ set(files
   __type_traits/negation.h
   __type_traits/noexcept_move_assign_container.h
   __type_traits/operation_traits.h
-  __type_traits/predicate_traits.h
   __type_traits/promote.h
   __type_traits/rank.h
   __type_traits/remove_all_extents.h
diff --git a/libcxx/include/__algorithm/comp.h 
b/libcxx/include/__algorithm/comp.h
index 9474536615ffb67..0993c37cce36a6b 100644
--- a/libcxx/include/__algorithm/comp.h
+++ b/libcxx/include/__algorithm/comp.h
@@ -10,8 +10,9 @@
 #define _LIBCPP___ALGORITHM_COMP_H
 
 #include <__config>
+#include <__functional/operations.h>
 #include <__type_traits/integral_constant.h>
-#include <__type_traits/predicate_traits.h>
+#include <__type_traits/operation_traits.h>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #  pragma GCC system_header
@@ -26,8 +27,8 @@ struct __equal_to {
   }
 };
 
-template 
-struct __is_trivial_equality_predicate<__equal_to, _Lhs, _Rhs> : true_type {};
+template <>
+struct __desugars_to<__equal_to, std::equal_to<>> : true_type {};
 
 // The definition is required because __less is part of the ABI, but it's empty
 // because all comparisons should be transparent.
diff --git a/libcxx/include/__algorithm/equal.h 
b/libcxx/include/__algorithm/equal.h
index b69aeff92bb9289..35e82da15e4d058 100644
--- a/libcxx/include/__algorithm/equal.h
+++ b/libcxx/include/__algorithm/equal.h
@@ -15,6 +15,7 @@
 #include <__config>
 #include <__functional/identity.h>
 #include <__functional/invoke.h>
+#include <__functional/operations.h>
 #include <__iterator/distance.h>
 #include <__iterator/iterator_traits.h>
 #include <__string/constexpr_c_functions.h>
@@ -23,7 +24,7 @@
 #include <__type_traits/is_constant_evaluated.h>
 #include <__type_traits/is_equality_comparable.h>
 #include <__type_traits/is_volatile.h>
-#include <__type_traits/predicate_traits.h>
+#include <__type_traits/operation_traits.h>
 #include <__utility/move.h>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
@@ -41,13 +42,12 @@ _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI 
_LIBCPP_CONSTEXPR_SINCE_CXX20 boo
   return true;
 }
 
-template <
-class _Tp,
-class _Up,
-class _BinaryPredicate,
-__enable_if_t<__is_trivial_equality_predicate<_BinaryPredicate, _Tp, 
_Up>::value && !is_volatile<_Tp>::value &&
-  !is_volatile<_Up>::value && 
__libcpp_is_trivially_equality_comparable<_Tp, _Up>::value,
-  int> = 0>
+template < class _Tp,
+   class _Up,
+   class _BinaryPredicate,
+   __enable_if_t<__desugars_to<_BinaryPredicate, 
std::equal_to<>>::value && !is_volatile<_Tp>::value &&
+ !is_volatile<_Up>::value && 
__libcpp_is_trivially_equality_comparable<_Tp, _Up>::value,
+ int> = 0>
 _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 
bool
 __equal_iter_impl(_Tp* __first1, _Tp* __last1, _Up* __first2, 
_BinaryPredicate&) {
   return std::__constexpr_memcmp_equal(__first1, __first2, 
__element_count(__last1 - __first1));
@@ -94,12 +94,12 @@ template ::value && __is_identity<_Proj1>::value &&
+  __enable_if_t<__desugars_to<_Pred, std::equal_to<>>::value && 
__is_identity<_Proj1>::value &&
 __is_identity<_Proj2>::value && 
!is_volatile<_Tp>::value && !is_volatile<_Up>::value &&
 __libcpp_is_trivially_equality_comparable<_Tp, 
_Up>::value,
 int> = 0>
-_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 
bool __equal_impl(
-_Tp* __first1, _Tp* __last1, _Up* __first2, _Up*, _Pred&, _Proj1&, 
_Proj2&) {
+_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 
bool

[clang] [LLVM] Add IRNormalizer Pass (PR #68176)

2023-10-15 Thread Justin Fargnoli via cfe-commits

https://github.com/justinfargnoli updated 
https://github.com/llvm/llvm-project/pull/68176

>From f792a030ac1761a96176332fea906cd2d1826c7b Mon Sep 17 00:00:00 2001
From: justinfargnoli 
Date: Sat, 12 Aug 2023 10:58:45 -0700
Subject: [PATCH 01/19] Add IRCanonicalizer.cpp

---
 llvm/lib/Transforms/Utils/CMakeLists.txt  |   1 +
 llvm/lib/Transforms/Utils/IRCanonicalizer.cpp | 632 ++
 2 files changed, 633 insertions(+)
 create mode 100644 llvm/lib/Transforms/Utils/IRCanonicalizer.cpp

diff --git a/llvm/lib/Transforms/Utils/CMakeLists.txt 
b/llvm/lib/Transforms/Utils/CMakeLists.txt
index a870071f3f641dc..7866e7a8c09c3be 100644
--- a/llvm/lib/Transforms/Utils/CMakeLists.txt
+++ b/llvm/lib/Transforms/Utils/CMakeLists.txt
@@ -34,6 +34,7 @@ add_llvm_component_library(LLVMTransformUtils
   InjectTLIMappings.cpp
   InstructionNamer.cpp
   IntegerDivision.cpp
+  IRCanonicalizer.cpp
   LCSSA.cpp
   LibCallsShrinkWrap.cpp
   Local.cpp
diff --git a/llvm/lib/Transforms/Utils/IRCanonicalizer.cpp 
b/llvm/lib/Transforms/Utils/IRCanonicalizer.cpp
new file mode 100644
index 000..58e2dce0b96685b
--- /dev/null
+++ b/llvm/lib/Transforms/Utils/IRCanonicalizer.cpp
@@ -0,0 +1,632 @@
+//===--- IRCanonicalizer.cpp - IR Canonicalizer 
---===//
+//
+// 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
+//
+//===--===//
+/// \file
+/// This file implements the IRCanonicalizer class which aims to transform LLVM
+/// Modules into a canonical form by reordering and renaming instructions while
+/// preserving the same semantics. The canonicalizer makes it easier to spot
+/// semantic differences while diffing two modules which have undergone
+/// different passes.
+///
+//===--===//
+
+#include "llvm/ADT/SetVector.h"
+#include "llvm/ADT/SmallPtrSet.h"
+#include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/IR/BasicBlock.h"
+#include "llvm/IR/Function.h"
+#include "llvm/IR/IRBuilder.h"
+#include "llvm/IR/InstIterator.h"
+#include "llvm/IR/Module.h"
+#include "llvm/InitializePasses.h"
+#include "llvm/Pass.h"
+#include "llvm/PassRegistry.h"
+#include "llvm/Support/CommandLine.h"
+#include "llvm/Transforms/Utils.h"
+#include 
+#include 
+
+#define DEBUG_TYPE "canon"
+
+using namespace llvm;
+
+namespace {
+/// IRCanonicalizer aims to transform LLVM IR into canonical form.
+class IRCanonicalizer : public FunctionPass {
+public:
+  static char ID;
+
+  /// \name Canonicalizer flags.
+  /// @{
+  /// Preserves original order of instructions.
+  static cl::opt PreserveOrder;
+  /// Renames all instructions (including user-named).
+  static cl::opt RenameAll;
+  /// Folds all regular instructions (including pre-outputs).
+  static cl::opt FoldPreoutputs;
+  /// Sorts and reorders operands in commutative instructions.
+  static cl::opt ReorderOperands;
+  /// @}
+
+  /// Constructor for the IRCanonicalizer.
+  IRCanonicalizer() : FunctionPass(ID) {}
+
+  bool runOnFunction(Function ) override;
+
+private:
+  // Random constant for hashing, so the state isn't zero.
+  const uint64_t MagicHashConstant = 0x6acaa36bef8325c5ULL;
+
+  /// \name Naming.
+  /// @{
+  void nameFunctionArguments(Function );
+  void nameBasicBlocks(Function );
+  void nameInstruction(Instruction *I);
+  void nameAsInitialInstruction(Instruction *I);
+  void nameAsRegularInstruction(Instruction *I);
+  void foldInstructionName(Instruction *I);
+  /// @}
+
+  /// \name Reordering.
+  /// @{
+  void reorderInstructions(SmallVector );
+  void reorderInstruction(Instruction *Used, Instruction *User,
+  SmallPtrSet );
+  void reorderInstructionOperandsByNames(Instruction *I);
+  void reorderPHIIncomingValues(PHINode *PN);
+  /// @}
+
+  /// \name Utility methods.
+  /// @{
+  SmallVector collectOutputInstructions(Function );
+  bool isOutput(const Instruction *I);
+  bool isInitialInstruction(const Instruction *I);
+  bool hasOnlyImmediateOperands(const Instruction *I);
+  SetVector
+  getOutputFootprint(Instruction *I,
+ SmallPtrSet );
+  /// @}
+};
+} // namespace
+
+char IRCanonicalizer::ID = 0;
+static RegisterPass X("canon", "Canonicalize the IR",
+   false /* Only looks at CFG */,
+   false /* Analysis Pass */);
+
+cl::opt IRCanonicalizer::PreserveOrder(
+"preserve-order", cl::Hidden,
+cl::desc("Preserves original instruction order"));
+cl::opt IRCanonicalizer::RenameAll(
+"rename-all", cl::Hidden,
+cl::desc("Renames all instructions (including user-named)"));
+cl::opt IRCanonicalizer::FoldPreoutputs(
+"fold-all", cl::Hidden,
+cl::desc("Folds all regular instructions 

[clang] [RISCV] Implement shadow stack on shadow stack mode with Zicfiss. (PR #68075)

2023-10-15 Thread Yeting Kuo via cfe-commits


@@ -106,9 +111,14 @@ static void emitSCSEpilogue(MachineFunction , 
MachineBasicBlock ,
   CSI, [&](CalleeSavedInfo ) { return CSR.getReg() == RAReg; }))
 return;
 
+  const RISCVInstrInfo *TII = STI.getInstrInfo();
+  if (STI.hasFeature(RISCV::FeatureStdExtZicfiss)) {

yetingk wrote:

> What if we're compiling for a platform that only uses the software shadow 
> stack and does not support the hardware shadow stack even if the CPU supports 
> it?

I think I should move the implement out of `emitSCSEpilogue`/`emitSCSPrologue` 
and enable hardware shadow stack by a new option, like 
`-riscv-hardware-shadow-stack`?

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


[clang] be72dca - [docs] [C++20] [Modules] Mentioning that -fdelayed-template-parsing is not working with modules

2023-10-15 Thread Chuanqi Xu via cfe-commits

Author: Chuanqi Xu
Date: 2023-10-16T10:38:33+08:00
New Revision: be72dca5e3ab3301e6927aca1c0823e382519bb3

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

LOG: [docs] [C++20] [Modules] Mentioning that -fdelayed-template-parsing is not 
working with modules

Catched in https://github.com/llvm/llvm-project/issues/61068.

Add this to the document to avoid further misunderstandings.

Added: 


Modified: 
clang/docs/StandardCPlusPlusModules.rst

Removed: 




diff  --git a/clang/docs/StandardCPlusPlusModules.rst 
b/clang/docs/StandardCPlusPlusModules.rst
index 579431bd9aa3273..8dd86edc64a80ab 100644
--- a/clang/docs/StandardCPlusPlusModules.rst
+++ b/clang/docs/StandardCPlusPlusModules.rst
@@ -686,6 +686,15 @@ the BMI within ``clang-cl.exe``.
 
 This is tracked in: https://github.com/llvm/llvm-project/issues/64118
 
+delayed template parsing is not supported/broken with C++ modules
+~
+
+The feature `-fdelayed-template-parsing` can't work well with C++ modules now.
+Note that this is significant on Windows since the option will be enabled by 
default
+on Windows.
+
+This is tracked in: https://github.com/llvm/llvm-project/issues/61068
+
 Header Units
 
 



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


[clang] [Driver][DragonFly] Fixes for linker path and command-line option handling (PR #69095)

2023-10-15 Thread Brad Smith via cfe-commits

brad0 wrote:

Fix a typo in a comment.

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


[clang] [Driver][DragonFly] Fixes for linker path and command-line option handling (PR #69095)

2023-10-15 Thread Brad Smith via cfe-commits

https://github.com/brad0 updated https://github.com/llvm/llvm-project/pull/69095

>From 1840ed82beb90edcdf8b4eff3de93d595fbc041d Mon Sep 17 00:00:00 2001
From: Brad Smith 
Date: Sun, 15 Oct 2023 04:00:56 -0400
Subject: [PATCH] [Driver][DragonFly] Fixes for linker path and command-line
 option handling

Add in some other linker command line options that the other BSD's
handle and make use of AddFilePathLibArgs().
---
 clang/lib/Driver/ToolChains/DragonFly.cpp | 12 ++--
 clang/test/Driver/dragonfly.c | 10 --
 2 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/DragonFly.cpp 
b/clang/lib/Driver/ToolChains/DragonFly.cpp
index a58983aba5a12f2..a4163a5f595372e 100644
--- a/clang/lib/Driver/ToolChains/DragonFly.cpp
+++ b/clang/lib/Driver/ToolChains/DragonFly.cpp
@@ -56,7 +56,9 @@ void dragonfly::Linker::ConstructJob(Compilation , const 
JobAction ,
  const InputInfoList ,
  const ArgList ,
  const char *LinkingOutput) const {
-  const Driver  = getToolChain().getDriver();
+  const toolchains::DragonFly  =
+  static_cast(getToolChain());
+  const Driver  = ToolChain.getDriver();
   ArgStringList CmdArgs;
 
   if (!D.SysRoot.empty())
@@ -115,16 +117,14 @@ void dragonfly::Linker::ConstructJob(Compilation , 
const JobAction ,
   Args.MakeArgString(getToolChain().GetFilePath("crtbegin.o")));
   }
 
-  Args.addAllArgs(CmdArgs, {options::OPT_L, options::OPT_T_Group});
+  Args.addAllArgs(CmdArgs, {options::OPT_L, options::OPT_T_Group,
+options::OPT_s, options::OPT_t, options::OPT_r});
+  ToolChain.AddFilePathLibArgs(Args, CmdArgs);
 
   AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs, JA);
 
   if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs,
options::OPT_r)) {
-SmallString<128> Dir(D.SysRoot);
-llvm::sys::path::append(Dir, "/usr/lib/gcc80");
-CmdArgs.push_back(Args.MakeArgString("-L" + Dir));
-
 if (!Args.hasArg(options::OPT_static)) {
   CmdArgs.push_back("-rpath");
   CmdArgs.push_back("/usr/lib/gcc80");
diff --git a/clang/test/Driver/dragonfly.c b/clang/test/Driver/dragonfly.c
index 8ba13c41d632c20..11d730f55bd9d69 100644
--- a/clang/test/Driver/dragonfly.c
+++ b/clang/test/Driver/dragonfly.c
@@ -2,7 +2,7 @@
 // RUN: FileCheck -input-file %t.log %s
 
 // CHECK: "-cc1" "-triple" "x86_64-pc-dragonfly"
-// CHECK: ld{{.*}}" "--eh-frame-hdr" "-dynamic-linker" 
"/usr/libexec/ld-elf.so.{{.*}}" "--hash-style=gnu" "--enable-new-dtags" "-o" 
"a.out" "{{.*}}crt1.o" "{{.*}}crti.o" "{{.*}}crtbegin.o" "{{.*}}.o" 
"-L{{.*}}gcc{{.*}}" "-rpath" "{{.*}}gcc{{.*}}" "-lc" "-lgcc" "{{.*}}crtend.o" 
"{{.*}}crtn.o"
+// CHECK: ld{{.*}}" "--eh-frame-hdr" "-dynamic-linker" 
"/usr/libexec/ld-elf.so.{{.*}}" "--hash-style=gnu" "--enable-new-dtags" "-o" 
"a.out" "{{.*}}crt1.o" "{{.*}}crti.o" "{{.*}}crtbegin.o" "-L{{.*}}/../lib" 
"-L/usr/lib" "-L/usr/lib/gcc80" "{{.*}}.o" "-rpath" "{{.*}}gcc80{{.*}}" "-lc" 
"-lgcc" "{{.*}}crtend.o" "{{.*}}crtn.o"
 
 // Check x86_64-unknown-dragonfly, X86_64
 // RUN: %clang -### %s 2>&1 --target=x86_64-unknown-dragonfly \
@@ -15,7 +15,8 @@
 // CHECK-LD-X86_64-SAME: 
"[[SYSROOT]]{{/|}}usr{{/|}}lib{{/|}}crt1.o"
 // CHECK-LD-X86_64-SAME: 
"[[SYSROOT]]{{/|}}usr{{/|}}lib{{/|}}crti.o"
 // CHECK-LD-X86_64-SAME: 
"[[SYSROOT]]{{/|}}usr{{/|}}lib{{/|}}gcc80{{/|}}crtbegin.o"
-// CHECK-LD-X86_64-SAME: 
"-L[[SYSROOT]]{{/|}}usr{{/|}}lib{{/|}}gcc80" "-rpath" 
"/usr/lib/gcc80" "-lc" "-lgcc" "--as-needed" "-lgcc_pic" "--no-as-needed"
+// CHECK-LD-X86_64-SAME: "-L[[SYSROOT]]{{/|}}usr{{/|}}lib" 
"-L[[SYSROOT]]{{/|}}usr{{/|}}lib{{/|}}gcc80"
+// CHECK-LD-X86_64-SAME: "-rpath" "/usr/lib/gcc80" "-lc" "-lgcc" "--as-needed" 
"-lgcc_pic" "--no-as-needed"
 // CHECK-LD-X86_64-SAME: 
"[[SYSROOT]]{{/|}}usr{{/|}}lib{{/|}}gcc80{{/|}}crtend.o"
 // CHECK-LD-X86_64-SAME: 
"[[SYSROOT]]{{/|}}usr{{/|}}lib{{/|}}crtn.o"
 
@@ -26,3 +27,8 @@
 // RELOCATABLE-NOT: "-dynamic-linker"
 // RELOCATABLE-NOT: "-l
 // RELOCATABLE-NOT: {{.*}}crt{{[^./]+}}.o
+
+// Check that the new linker flags are passed to DragonFly
+// RUN: %clang --target=x86_64-unknown-dragonfly -s -t -### %s 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-LD-FLAGS %s
+// CHECK-LD-FLAGS: ld{{.*}}" "{{.*}}" "-s" "-t"

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


[clang] [Driver] Don't pass -Z to ld for ELF platforms (PR #69120)

2023-10-15 Thread Brad Smith via cfe-commits

brad0 wrote:

> Another question is whether we want to use `clang -Z` or `clang -Wl,-Z`. For 
> newer options we probably should recommend `-Wl,` more.

Yes, I was thinking if this is used anywhere via the driver that it could be 
changed to using -Wl.

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


[clang] [X86] Add USER_MSR instructions. (PR #68944)

2023-10-15 Thread Freddy Ye via cfe-commits

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


[clang] 819ac45 - [X86] Add USER_MSR instructions. (#68944)

2023-10-15 Thread via cfe-commits

Author: Freddy Ye
Date: 2023-10-16T10:12:53+08:00
New Revision: 819ac45d1c1b7a2d784b2606c84de46ce714f278

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

LOG: [X86] Add USER_MSR instructions. (#68944)

For more details about this instruction, please refer to the latest ISE
document:
https://www.intel.com/content/www/us/en/develop/download/intel-architecture-instruction-set-extensions-programming-reference.html

Added: 
clang/lib/Headers/usermsrintrin.h
clang/test/CodeGen/X86/usermsr-builtins-error-32.c
clang/test/CodeGen/X86/usermsr-builtins.c
llvm/test/CodeGen/X86/usermsr-intrinsics.ll
llvm/test/MC/Disassembler/X86/usermsr-64.txt
llvm/test/MC/X86/usermsr-64-att.s
llvm/test/MC/X86/usermsr-64-intel.s

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/BuiltinsX86_64.def
clang/include/clang/Driver/Options.td
clang/lib/Basic/Targets/X86.cpp
clang/lib/Basic/Targets/X86.h
clang/lib/Headers/CMakeLists.txt
clang/lib/Headers/x86gprintrin.h
clang/test/Driver/x86-target-features.c
clang/test/Preprocessor/x86_target_features.c
llvm/docs/ReleaseNotes.rst
llvm/include/llvm/IR/IntrinsicsX86.td
llvm/include/llvm/Support/X86DisassemblerDecoderCommon.h
llvm/include/llvm/TargetParser/X86TargetParser.def
llvm/lib/Target/X86/Disassembler/X86Disassembler.cpp
llvm/lib/Target/X86/Disassembler/X86DisassemblerDecoder.h
llvm/lib/Target/X86/MCTargetDesc/X86BaseInfo.h
llvm/lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp
llvm/lib/Target/X86/X86.td
llvm/lib/Target/X86/X86InstrFormats.td
llvm/lib/Target/X86/X86InstrInfo.td
llvm/lib/Target/X86/X86InstrSystem.td
llvm/lib/TargetParser/Host.cpp
llvm/lib/TargetParser/X86TargetParser.cpp
llvm/utils/TableGen/X86DisassemblerTables.cpp
llvm/utils/TableGen/X86DisassemblerTables.h
llvm/utils/TableGen/X86RecognizableInstr.cpp
llvm/utils/TableGen/X86RecognizableInstr.h

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 6d315e9f84ddfe8..52d5b9a3f66d155 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -551,6 +551,9 @@ X86 Support
 
 - Added option ``-m[no-]evex512`` to disable ZMM and 64-bit mask instructions
   for AVX512 features.
+- Support ISA of ``USER_MSR``.
+  * Support intrinsic of ``_urdmsr``.
+  * Support intrinsic of ``_uwrmsr``.
 
 Arm and AArch64 Support
 ^^^

diff  --git a/clang/include/clang/Basic/BuiltinsX86_64.def 
b/clang/include/clang/Basic/BuiltinsX86_64.def
index e5c1fe8b319217e..5e00916d4b25ae3 100644
--- a/clang/include/clang/Basic/BuiltinsX86_64.def
+++ b/clang/include/clang/Basic/BuiltinsX86_64.def
@@ -104,6 +104,9 @@ TARGET_BUILTIN(__builtin_ia32_clui, "v", "n", "uintr")
 TARGET_BUILTIN(__builtin_ia32_stui, "v", "n", "uintr")
 TARGET_BUILTIN(__builtin_ia32_testui, "Uc", "n", "uintr")
 TARGET_BUILTIN(__builtin_ia32_senduipi, "vUWi", "n", "uintr")
+// USERMSR
+TARGET_BUILTIN(__builtin_ia32_urdmsr, "ULLiULLi", "n", "usermsr")
+TARGET_BUILTIN(__builtin_ia32_uwrmsr, "vULLiULLi", "n", "usermsr")
 
 // AMX internal builtin
 TARGET_BUILTIN(__builtin_ia32_tile_loadconfig_internal, "vvC*", "n", 
"amx-tile")

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 54afd652ad3d0fe..640044622fc09ee 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5904,6 +5904,8 @@ def mtsxldtrk : Flag<["-"], "mtsxldtrk">, 
Group;
 def mno_tsxldtrk : Flag<["-"], "mno-tsxldtrk">, Group;
 def muintr : Flag<["-"], "muintr">, Group;
 def mno_uintr : Flag<["-"], "mno-uintr">, Group;
+def musermsr : Flag<["-"], "musermsr">, Group;
+def mno_usermsr : Flag<["-"], "mno-usermsr">, Group;
 def mvaes : Flag<["-"], "mvaes">, Group;
 def mno_vaes : Flag<["-"], "mno-vaes">, Group;
 def mvpclmulqdq : Flag<["-"], "mvpclmulqdq">, Group;

diff  --git a/clang/lib/Basic/Targets/X86.cpp b/clang/lib/Basic/Targets/X86.cpp
index 022d5753135e160..bea5c52a7b8d7c9 100644
--- a/clang/lib/Basic/Targets/X86.cpp
+++ b/clang/lib/Basic/Targets/X86.cpp
@@ -376,6 +376,8 @@ bool 
X86TargetInfo::handleTargetFeatures(std::vector ,
   HasTSXLDTRK = true;
 } else if (Feature == "+uintr") {
   HasUINTR = true;
+} else if (Feature == "+usermsr") {
+  HasUSERMSR = true;
 } else if (Feature == "+crc32") {
   HasCRC32 = true;
 } else if (Feature == "+x87") {
@@ -869,6 +871,8 @@ void X86TargetInfo::getTargetDefines(const LangOptions 
,
 Builder.defineMacro("__TSXLDTRK__");
   if (HasUINTR)
 Builder.defineMacro("__UINTR__");
+  if (HasUSERMSR)
+Builder.defineMacro("__USERMSR__");
   if (HasCRC32)
 Builder.defineMacro("__CRC32__");
 
@@ -1053,6 +1057,7 @@ 

[clang] [Driver] Don't pass -Z to ld for ELF platforms (PR #69120)

2023-10-15 Thread Fangrui Song via cfe-commits

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


[clang] 993e839 - [Driver] Don't pass -Z to ld for ELF platforms (#69120)

2023-10-15 Thread via cfe-commits

Author: Fangrui Song
Date: 2023-10-15T19:12:35-07:00
New Revision: 993e839480449de63aefb1a1ae9142eefed5e7a6

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

LOG: [Driver] Don't pass -Z to ld for ELF platforms (#69120)

-Z is an Apple ld64 option. ELF linkers don't recognize -Z, except
OpenBSD which patched GNU ld to add -Z for zmagic (seems unused)

> -Z Produce 'Standard' executables, disables Writable XOR Executable
features in resulting binaries.

Some `ToolChain`s have -Z due to copy-and-paste mistakes.

Added: 


Modified: 
clang/lib/Driver/ToolChains/BareMetal.cpp
clang/lib/Driver/ToolChains/CSKYToolChain.cpp
clang/lib/Driver/ToolChains/FreeBSD.cpp
clang/lib/Driver/ToolChains/Haiku.cpp
clang/lib/Driver/ToolChains/MinGW.cpp
clang/lib/Driver/ToolChains/NetBSD.cpp
clang/lib/Driver/ToolChains/OpenBSD.cpp
clang/lib/Driver/ToolChains/RISCVToolchain.cpp
clang/test/Driver/openbsd.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/BareMetal.cpp 
b/clang/lib/Driver/ToolChains/BareMetal.cpp
index f363d277a7b71d3..842061c1e1488b0 100644
--- a/clang/lib/Driver/ToolChains/BareMetal.cpp
+++ b/clang/lib/Driver/ToolChains/BareMetal.cpp
@@ -452,9 +452,8 @@ void baremetal::Linker::ConstructJob(Compilation , const 
JobAction ,
 CmdArgs.push_back(Arch == llvm::Triple::aarch64_be ? "-EB" : "-EL");
   }
 
-  Args.addAllArgs(CmdArgs,
-  {options::OPT_L, options::OPT_T_Group, options::OPT_s,
-   options::OPT_t, options::OPT_Z_Flag, options::OPT_r});
+  Args.addAllArgs(CmdArgs, {options::OPT_L, options::OPT_T_Group,
+options::OPT_s, options::OPT_t, options::OPT_r});
 
   TC.AddFilePathLibArgs(Args, CmdArgs);
 

diff  --git a/clang/lib/Driver/ToolChains/CSKYToolChain.cpp 
b/clang/lib/Driver/ToolChains/CSKYToolChain.cpp
index 2bd91e63fdd5a42..0c280347b2af6a1 100644
--- a/clang/lib/Driver/ToolChains/CSKYToolChain.cpp
+++ b/clang/lib/Driver/ToolChains/CSKYToolChain.cpp
@@ -169,9 +169,8 @@ void CSKY::Linker::ConstructJob(Compilation , const 
JobAction ,
 
   Args.AddAllArgs(CmdArgs, options::OPT_L);
   ToolChain.AddFilePathLibArgs(Args, CmdArgs);
-  Args.addAllArgs(CmdArgs,
-  {options::OPT_T_Group, options::OPT_s, options::OPT_t,
-   options::OPT_Z_Flag, options::OPT_r});
+  Args.addAllArgs(CmdArgs, {options::OPT_T_Group, options::OPT_s,
+options::OPT_t, options::OPT_r});
 
   AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs, JA);
 

diff  --git a/clang/lib/Driver/ToolChains/FreeBSD.cpp 
b/clang/lib/Driver/ToolChains/FreeBSD.cpp
index c936fb88d18ccd9..7a61159ba4a7308 100644
--- a/clang/lib/Driver/ToolChains/FreeBSD.cpp
+++ b/clang/lib/Driver/ToolChains/FreeBSD.cpp
@@ -262,9 +262,8 @@ void freebsd::Linker::ConstructJob(Compilation , const 
JobAction ,
 
   Args.AddAllArgs(CmdArgs, options::OPT_L);
   ToolChain.AddFilePathLibArgs(Args, CmdArgs);
-  Args.addAllArgs(CmdArgs,
-  {options::OPT_T_Group, options::OPT_s, options::OPT_t,
-   options::OPT_Z_Flag, options::OPT_r});
+  Args.addAllArgs(CmdArgs, {options::OPT_T_Group, options::OPT_s,
+options::OPT_t, options::OPT_r});
 
   if (D.isUsingLTO()) {
 assert(!Inputs.empty() && "Must have at least one input.");

diff  --git a/clang/lib/Driver/ToolChains/Haiku.cpp 
b/clang/lib/Driver/ToolChains/Haiku.cpp
index c2653a4a2022edf..9f56a0ea5d612d0 100644
--- a/clang/lib/Driver/ToolChains/Haiku.cpp
+++ b/clang/lib/Driver/ToolChains/Haiku.cpp
@@ -80,9 +80,8 @@ void haiku::Linker::ConstructJob(Compilation , const 
JobAction ,
 
CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("init_term_dyn.o")));
   }
 
-  Args.addAllArgs(CmdArgs,
-  {options::OPT_L, options::OPT_T_Group, options::OPT_s,
-   options::OPT_t, options::OPT_Z_Flag, options::OPT_r});
+  Args.addAllArgs(CmdArgs, {options::OPT_L, options::OPT_T_Group,
+options::OPT_s, options::OPT_t, options::OPT_r});
   ToolChain.AddFilePathLibArgs(Args, CmdArgs);
 
   addLinkerCompressDebugSectionsOption(ToolChain, Args, CmdArgs);

diff  --git a/clang/lib/Driver/ToolChains/MinGW.cpp 
b/clang/lib/Driver/ToolChains/MinGW.cpp
index d3d829a8ddbdb95..39d767795445dbe 100644
--- a/clang/lib/Driver/ToolChains/MinGW.cpp
+++ b/clang/lib/Driver/ToolChains/MinGW.cpp
@@ -201,7 +201,6 @@ void tools::MinGW::Linker::ConstructJob(Compilation , 
const JobAction ,
   Args.AddLastArg(CmdArgs, options::OPT_s);
   Args.AddLastArg(CmdArgs, options::OPT_t);
   Args.AddAllArgs(CmdArgs, options::OPT_u_Group);
-  Args.AddLastArg(CmdArgs, options::OPT_Z_Flag);
 
   // Add asan_dynamic as the first import lib before other libs. This allows
   // 

[clang] [Driver] Don't pass -Z to ld for ELF platforms (PR #69120)

2023-10-15 Thread Fangrui Song via cfe-commits

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


[clang] [Driver] Don't pass -Z to ld for ELF platforms (PR #69120)

2023-10-15 Thread Fangrui Song via cfe-commits

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


[clang] [Driver] Don't pass -Z to ld for ELF platforms (PR #69120)

2023-10-15 Thread Fangrui Song via cfe-commits

MaskRay wrote:

> OpenBSD has a -Z flag for our BFD linker.
> 
> `-Z Produce 'Standard' executables, disables Writable XOR Executable features 
> in resulting binaries.`
> 
> [openbsd/src@0abdc37](https://github.com/openbsd/src/commit/0abdc3723b5d33dde698ab941325edec2819c128)
>  
> [openbsd/src@58cb065](https://github.com/openbsd/src/commit/58cb065838343f5d972d625775790ebb89f56d88)
>  
> [openbsd/src@0bd5fc2](https://github.com/openbsd/src/commit/0bd5fc2a33971fd1cca748eda19e75844fa9c27a)
> 
> But it was never ported to our copy of LLD, which is what almost all of our 
> Clang switched archs use, plus I can't seem to find any use of the flag 
> anywhere nowadays.

Thanks for the info! Interesting. I'll update the description.

Another question is whether we want to use `clang -Z` or `clang -Wl,-Z`. For 
newer options we probably should recommend `-Wl,` more.

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


[clang] LoongArch fp16,fp128 basic support (PR #68851)

2023-10-15 Thread via cfe-commits

https://github.com/Xinmudotmoe updated 
https://github.com/llvm/llvm-project/pull/68851

>From 2ef1ddfb977da35f31f1f351ac4daf0478fff166 Mon Sep 17 00:00:00 2001
From: xinmu 
Date: Thu, 12 Oct 2023 13:36:34 +0800
Subject: [PATCH 1/2] LoongArch fp16,fp128 basic support

---
 clang/lib/Basic/Targets/LoongArch.h | 2 ++
 clang/test/CodeGen/fp16-ops.c   | 1 +
 llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp | 7 +++
 3 files changed, 10 insertions(+)

diff --git a/clang/lib/Basic/Targets/LoongArch.h 
b/clang/lib/Basic/Targets/LoongArch.h
index ba7fb78ab94cd23..b25857207acdedd 100644
--- a/clang/lib/Basic/Targets/LoongArch.h
+++ b/clang/lib/Basic/Targets/LoongArch.h
@@ -40,6 +40,8 @@ class LLVM_LIBRARY_VISIBILITY LoongArchTargetInfo : public 
TargetInfo {
 SuitableAlign = 128;
 WCharType = SignedInt;
 WIntType = UnsignedInt;
+HasFloat128 = true;
+HasFloat16 = true;
   }
 
   bool setCPU(const std::string ) override {
diff --git a/clang/test/CodeGen/fp16-ops.c b/clang/test/CodeGen/fp16-ops.c
index 0626e0aaed9d0c0..e230011a59402d4 100644
--- a/clang/test/CodeGen/fp16-ops.c
+++ b/clang/test/CodeGen/fp16-ops.c
@@ -2,6 +2,7 @@
 // RUN: %clang_cc1 -emit-llvm -o - -triple arm-none-linux-gnueabi %s | 
FileCheck %s --check-prefix=NOTNATIVE --check-prefix=CHECK
 // RUN: %clang_cc1 -emit-llvm -o - -triple aarch64-none-linux-gnueabi %s | 
FileCheck %s --check-prefix=NOTNATIVE --check-prefix=CHECK
 // RUN: %clang_cc1 -emit-llvm -o - -triple x86_64-linux-gnu %s | FileCheck %s 
--check-prefix=NOTNATIVE --check-prefix=CHECK
+// RUN: %clang_cc1 -emit-llvm -o - -triple loongarch64-linux-gnu %s | 
FileCheck %s --check-prefix=NOTNATIVE --check-prefix=CHECK
 // RUN: %clang_cc1 -emit-llvm -o - -triple arm-none-linux-gnueabi 
-fnative-half-type %s \
 // RUN:   | FileCheck %s --check-prefix=NATIVE-HALF
 // RUN: %clang_cc1 -emit-llvm -o - -triple aarch64-none-linux-gnueabi 
-fnative-half-type %s \
diff --git a/llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp 
b/llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
index 7d01887f24c1597..0295389e1a92e4c 100644
--- a/llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
+++ b/llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
@@ -214,6 +214,13 @@ LoongArchTargetLowering::LoongArchTargetLowering(const 
TargetMachine ,
   setOperationAction(ISD::FRINT, MVT::f64, Legal);
   }
 
+  setOperationAction(ISD::FP16_TO_FP,MVT::f32,   Expand);
+  setOperationAction(ISD::FP_TO_FP16,MVT::f32,   Expand);
+  setTruncStoreAction(MVT::f32, MVT::f16, Expand);
+  setLoadExtAction(ISD::EXTLOAD, MVT::f32, MVT::f16, Expand);
+  setLibcallName(RTLIB::FPEXT_F16_F32, "__extendhfsf2");
+  setLibcallName(RTLIB::FPROUND_F32_F16, "__truncsfhf2");
+
   // Set operations for 'LSX' feature.
 
   if (Subtarget.hasExtLSX())

>From d198dc7d6086fdd918529d6349b33169cbf59624 Mon Sep 17 00:00:00 2001
From: xinmu 
Date: Thu, 12 Oct 2023 18:02:53 +0800
Subject: [PATCH 2/2] fix whitespaces lint

---
 llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp 
b/llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
index 0295389e1a92e4c..f03f09127866483 100644
--- a/llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
+++ b/llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
@@ -214,8 +214,8 @@ LoongArchTargetLowering::LoongArchTargetLowering(const 
TargetMachine ,
   setOperationAction(ISD::FRINT, MVT::f64, Legal);
   }
 
-  setOperationAction(ISD::FP16_TO_FP,MVT::f32,   Expand);
-  setOperationAction(ISD::FP_TO_FP16,MVT::f32,   Expand);
+  setOperationAction(ISD::FP16_TO_FP, MVT::f32, Expand);
+  setOperationAction(ISD::FP_TO_FP16, MVT::f32, Expand);
   setTruncStoreAction(MVT::f32, MVT::f16, Expand);
   setLoadExtAction(ISD::EXTLOAD, MVT::f32, MVT::f16, Expand);
   setLibcallName(RTLIB::FPEXT_F16_F32, "__extendhfsf2");

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


[clang] [clang][dataflow]Use cast_or_null instead of cast to prevent crash (PR #68510)

2023-10-15 Thread Qizhi Hu via cfe-commits

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


[clang] [clang][dataflow]Use cast_or_null instead cast to prevent crash (PR #68510)

2023-10-15 Thread Qizhi Hu via cfe-commits

jcsxky wrote:

@ymand Could you take a look at this pr?

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


[clang-tools-extra] [X86][RFC] Support AVX10 options (PR #67278)

2023-10-15 Thread Phoebe Wang via cfe-commits

phoebewang wrote:

Ping~

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


[clang] [X86][RFC] Support AVX10 options (PR #67278)

2023-10-15 Thread Phoebe Wang via cfe-commits

phoebewang wrote:

Ping~

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


[clang] [X86][RFC] Support AVX10 options (PR #67278)

2023-10-15 Thread Phoebe Wang via cfe-commits

https://github.com/phoebewang updated 
https://github.com/llvm/llvm-project/pull/67278

>From eaf36c8cac3fe6d9bb3dcb1387b0b4f1febf5ef7 Mon Sep 17 00:00:00 2001
From: Phoebe Wang 
Date: Mon, 25 Sep 2023 10:31:37 +0800
Subject: [PATCH 1/2] [X86][RFC] Support AVX10 options

AVX10 Architecture Specification: 
https://cdrdv2.intel.com/v1/dl/getContent/784267
AVX10 Technical Paper: https://cdrdv2.intel.com/v1/dl/getContent/784343
RFC: https://discourse.llvm.org/t/rfc-design-for-avx10-options-support/73672
---
 clang/docs/ReleaseNotes.rst   |  1 +
 clang/include/clang/Driver/Options.td |  9 +
 clang/lib/Basic/Targets/X86.cpp   | 37 +--
 clang/lib/Basic/Targets/X86.h |  2 +
 clang/lib/Driver/ToolChains/Arch/X86.cpp  | 30 +++
 clang/test/CodeGen/X86/avx512-error.c | 20 +++---
 clang/test/CodeGen/attr-target-x86.c  | 14 +--
 clang/test/CodeGen/target-avx-abi-diag.c  |  4 ++
 clang/test/Driver/x86-target-features.c   | 20 ++
 clang/test/Preprocessor/x86_target_features.c | 14 +++
 llvm/docs/ReleaseNotes.rst|  2 +
 .../llvm/TargetParser/X86TargetParser.def |  2 +
 llvm/lib/Target/X86/X86.td|  8 
 llvm/lib/Target/X86/X86InstrInfo.td   |  2 +
 llvm/lib/TargetParser/Host.cpp|  6 +++
 llvm/lib/TargetParser/X86TargetParser.cpp |  9 +
 16 files changed, 168 insertions(+), 12 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7abcb8d799e09dc..419bab7577cfad4 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -387,6 +387,7 @@ X86 Support
 
 - Added option ``-m[no-]evex512`` to disable ZMM and 64-bit mask instructions
   for AVX512 features.
+- Support ISA of ``AVX10.1``.
 
 Arm and AArch64 Support
 ^^^
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 0f93479170d73bc..dd44333e6cb30a7 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -197,6 +197,9 @@ def m_wasm_Features_Driver_Group : OptionGroup<"">,
 def m_x86_Features_Group : OptionGroup<"">,
Group, Visibility<[ClangOption, CLOption]>,
DocName<"X86">;
+def m_x86_AVX10_Features_Group : OptionGroup<"">,
+ Group, Visibility<[ClangOption, 
CLOption]>,
+ DocName<"X86 AVX10">;
 def m_riscv_Features_Group : OptionGroup<"">,
  Group, DocName<"RISC-V">;
 def m_ve_Features_Group : OptionGroup<"">,
@@ -5693,6 +5696,12 @@ def msse4a : Flag<["-"], "msse4a">, 
Group;
 def mno_sse4a : Flag<["-"], "mno-sse4a">, Group;
 def mavx : Flag<["-"], "mavx">, Group;
 def mno_avx : Flag<["-"], "mno-avx">, Group;
+def mavx10_1_256 : Flag<["-"], "mavx10.1-256">, 
Group;
+def mno_avx10_1_256 : Flag<["-"], "mno-avx10.1-256">, 
Group;
+def mavx10_1_512 : Flag<["-"], "mavx10.1-512">, 
Group;
+def mno_avx10_1_512 : Flag<["-"], "mno-avx10.1-512">, 
Group;
+def mavx10_1 : Flag<["-"], "mavx10.1">, Alias;
+def mno_avx10_1 : Flag<["-"], "mno-avx10.1">, Alias;
 def mavx2 : Flag<["-"], "mavx2">, Group;
 def mno_avx2 : Flag<["-"], "mno-avx2">, Group;
 def mavx512f : Flag<["-"], "mavx512f">, Group;
diff --git a/clang/lib/Basic/Targets/X86.cpp b/clang/lib/Basic/Targets/X86.cpp
index 022d5753135e160..746414181926f7d 100644
--- a/clang/lib/Basic/Targets/X86.cpp
+++ b/clang/lib/Basic/Targets/X86.cpp
@@ -121,6 +121,7 @@ bool X86TargetInfo::initFeatureMap(
   std::vector UpdatedFeaturesVec;
   bool HasEVEX512 = true;
   bool HasAVX512F = false;
+  bool HasAVX10 = false;
   for (const auto  : FeaturesVec) {
 // Expand general-regs-only to -x86, -mmx and -sse
 if (Feature == "+general-regs-only") {
@@ -130,17 +131,35 @@ bool X86TargetInfo::initFeatureMap(
   continue;
 }
 
-if (!HasAVX512F && Feature.substr(0, 7) == "+avx512")
+if (Feature.substr(0, 7) == "+avx10.") {
+  HasAVX10 = true;
   HasAVX512F = true;
-if (HasAVX512F && Feature == "-avx512f")
+  if (Feature.substr(Feature.size() - 3, 3) == "512") {
+HasEVEX512 = true;
+  } else if (Feature.substr(7, 2) == "1-") {
+HasEVEX512 = false;
+  }
+} else if (!HasAVX512F && Feature.substr(0, 7) == "+avx512") {
+  HasAVX512F = true;
+} else if (HasAVX512F && Feature == "-avx512f") {
+  HasAVX512F = false;
+} else if (HasAVX10 && Feature == "-avx10.1-256") {
+  HasAVX10 = false;
   HasAVX512F = false;
-if (HasEVEX512 && Feature == "-evex512")
+} else if (!HasEVEX512 && Feature == "+evex512") {
+  HasEVEX512 = true;
+} else if (HasEVEX512 && Feature == "-avx10.1-512") {
   HasEVEX512 = false;
+} else if (HasEVEX512 && Feature == "-evex512") {
+  HasEVEX512 = false;
+}
 
 UpdatedFeaturesVec.push_back(Feature);
   }
   

[clang-tools-extra] [X86][RFC] Support AVX10 options (PR #67278)

2023-10-15 Thread Phoebe Wang via cfe-commits

https://github.com/phoebewang updated 
https://github.com/llvm/llvm-project/pull/67278

>From eaf36c8cac3fe6d9bb3dcb1387b0b4f1febf5ef7 Mon Sep 17 00:00:00 2001
From: Phoebe Wang 
Date: Mon, 25 Sep 2023 10:31:37 +0800
Subject: [PATCH 1/2] [X86][RFC] Support AVX10 options

AVX10 Architecture Specification: 
https://cdrdv2.intel.com/v1/dl/getContent/784267
AVX10 Technical Paper: https://cdrdv2.intel.com/v1/dl/getContent/784343
RFC: https://discourse.llvm.org/t/rfc-design-for-avx10-options-support/73672
---
 clang/docs/ReleaseNotes.rst   |  1 +
 clang/include/clang/Driver/Options.td |  9 +
 clang/lib/Basic/Targets/X86.cpp   | 37 +--
 clang/lib/Basic/Targets/X86.h |  2 +
 clang/lib/Driver/ToolChains/Arch/X86.cpp  | 30 +++
 clang/test/CodeGen/X86/avx512-error.c | 20 +++---
 clang/test/CodeGen/attr-target-x86.c  | 14 +--
 clang/test/CodeGen/target-avx-abi-diag.c  |  4 ++
 clang/test/Driver/x86-target-features.c   | 20 ++
 clang/test/Preprocessor/x86_target_features.c | 14 +++
 llvm/docs/ReleaseNotes.rst|  2 +
 .../llvm/TargetParser/X86TargetParser.def |  2 +
 llvm/lib/Target/X86/X86.td|  8 
 llvm/lib/Target/X86/X86InstrInfo.td   |  2 +
 llvm/lib/TargetParser/Host.cpp|  6 +++
 llvm/lib/TargetParser/X86TargetParser.cpp |  9 +
 16 files changed, 168 insertions(+), 12 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7abcb8d799e09dc..419bab7577cfad4 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -387,6 +387,7 @@ X86 Support
 
 - Added option ``-m[no-]evex512`` to disable ZMM and 64-bit mask instructions
   for AVX512 features.
+- Support ISA of ``AVX10.1``.
 
 Arm and AArch64 Support
 ^^^
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 0f93479170d73bc..dd44333e6cb30a7 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -197,6 +197,9 @@ def m_wasm_Features_Driver_Group : OptionGroup<"">,
 def m_x86_Features_Group : OptionGroup<"">,
Group, Visibility<[ClangOption, CLOption]>,
DocName<"X86">;
+def m_x86_AVX10_Features_Group : OptionGroup<"">,
+ Group, Visibility<[ClangOption, 
CLOption]>,
+ DocName<"X86 AVX10">;
 def m_riscv_Features_Group : OptionGroup<"">,
  Group, DocName<"RISC-V">;
 def m_ve_Features_Group : OptionGroup<"">,
@@ -5693,6 +5696,12 @@ def msse4a : Flag<["-"], "msse4a">, 
Group;
 def mno_sse4a : Flag<["-"], "mno-sse4a">, Group;
 def mavx : Flag<["-"], "mavx">, Group;
 def mno_avx : Flag<["-"], "mno-avx">, Group;
+def mavx10_1_256 : Flag<["-"], "mavx10.1-256">, 
Group;
+def mno_avx10_1_256 : Flag<["-"], "mno-avx10.1-256">, 
Group;
+def mavx10_1_512 : Flag<["-"], "mavx10.1-512">, 
Group;
+def mno_avx10_1_512 : Flag<["-"], "mno-avx10.1-512">, 
Group;
+def mavx10_1 : Flag<["-"], "mavx10.1">, Alias;
+def mno_avx10_1 : Flag<["-"], "mno-avx10.1">, Alias;
 def mavx2 : Flag<["-"], "mavx2">, Group;
 def mno_avx2 : Flag<["-"], "mno-avx2">, Group;
 def mavx512f : Flag<["-"], "mavx512f">, Group;
diff --git a/clang/lib/Basic/Targets/X86.cpp b/clang/lib/Basic/Targets/X86.cpp
index 022d5753135e160..746414181926f7d 100644
--- a/clang/lib/Basic/Targets/X86.cpp
+++ b/clang/lib/Basic/Targets/X86.cpp
@@ -121,6 +121,7 @@ bool X86TargetInfo::initFeatureMap(
   std::vector UpdatedFeaturesVec;
   bool HasEVEX512 = true;
   bool HasAVX512F = false;
+  bool HasAVX10 = false;
   for (const auto  : FeaturesVec) {
 // Expand general-regs-only to -x86, -mmx and -sse
 if (Feature == "+general-regs-only") {
@@ -130,17 +131,35 @@ bool X86TargetInfo::initFeatureMap(
   continue;
 }
 
-if (!HasAVX512F && Feature.substr(0, 7) == "+avx512")
+if (Feature.substr(0, 7) == "+avx10.") {
+  HasAVX10 = true;
   HasAVX512F = true;
-if (HasAVX512F && Feature == "-avx512f")
+  if (Feature.substr(Feature.size() - 3, 3) == "512") {
+HasEVEX512 = true;
+  } else if (Feature.substr(7, 2) == "1-") {
+HasEVEX512 = false;
+  }
+} else if (!HasAVX512F && Feature.substr(0, 7) == "+avx512") {
+  HasAVX512F = true;
+} else if (HasAVX512F && Feature == "-avx512f") {
+  HasAVX512F = false;
+} else if (HasAVX10 && Feature == "-avx10.1-256") {
+  HasAVX10 = false;
   HasAVX512F = false;
-if (HasEVEX512 && Feature == "-evex512")
+} else if (!HasEVEX512 && Feature == "+evex512") {
+  HasEVEX512 = true;
+} else if (HasEVEX512 && Feature == "-avx10.1-512") {
   HasEVEX512 = false;
+} else if (HasEVEX512 && Feature == "-evex512") {
+  HasEVEX512 = false;
+}
 
 UpdatedFeaturesVec.push_back(Feature);
   }
   

[clang] [Driver] Hook up Haiku PowerPC support (PR #69134)

2023-10-15 Thread Brad Smith via cfe-commits

https://github.com/brad0 updated https://github.com/llvm/llvm-project/pull/69134

>From ed2ff4586a4113e7b967112d700ca8ad56f0afdd Mon Sep 17 00:00:00 2001
From: Brad Smith 
Date: Wed, 11 Oct 2023 19:25:33 -0400
Subject: [PATCH] [Driver] Hook up Haiku PowerPC support

---
 clang/lib/Basic/Targets.cpp| 2 ++
 clang/test/Preprocessor/init.c | 9 +
 2 files changed, 11 insertions(+)

diff --git a/clang/lib/Basic/Targets.cpp b/clang/lib/Basic/Targets.cpp
index 8130f90a276749e..770f33f0efc9de3 100644
--- a/clang/lib/Basic/Targets.cpp
+++ b/clang/lib/Basic/Targets.cpp
@@ -361,6 +361,8 @@ std::unique_ptr AllocateTarget(const 
llvm::Triple ,
 
   case llvm::Triple::ppc:
 switch (os) {
+case llvm::Triple::Haiku:
+  return std::make_unique>(Triple, Opts);
 case llvm::Triple::Linux:
   return std::make_unique>(Triple, Opts);
 case llvm::Triple::FreeBSD:
diff --git a/clang/test/Preprocessor/init.c b/clang/test/Preprocessor/init.c
index 59c5122afe1e4c3..e66ffc9739102a4 100644
--- a/clang/test/Preprocessor/init.c
+++ b/clang/test/Preprocessor/init.c
@@ -1454,6 +1454,15 @@
 // RUN: %clang_cc1 -triple lanai-unknown-unknown -E -dM < /dev/null | 
FileCheck -match-full-lines -check-prefix LANAI %s
 // LANAI: #define __lanai__ 1
 //
+
+// RUN: %clang_cc1 -triple=aarch64-unknown-haiku -E -dM < /dev/null | 
FileCheck -match-full-lines -check-prefix HAIKU %s
+// RUN: %clang_cc1 -triple=arm-unknown-haiku -E -dM < /dev/null | FileCheck 
-match-full-lines -check-prefix HAIKU %s
+// RUN: %clang_cc1 -triple=powerpc-unknown-haiku -E -dM < /dev/null | 
FileCheck -match-full-lines -check-prefix HAIKU %s
+// RUN: %clang_cc1 -triple=riscv64-unknown-haiku -E -dM < /dev/null | 
FileCheck -match-full-lines -check-prefix HAIKU %s
+// RUN: %clang_cc1 -triple=x86_64-unknown-haiku -E -dM < /dev/null | FileCheck 
-match-full-lines -check-prefix HAIKU %s
+// RUN: %clang_cc1 -triple=i386-unknown-haiku -E -dM < /dev/null | FileCheck 
-match-full-lines -check-prefix HAIKU %s
+// HAIKU: #define __HAIKU__ 1
+
 // RUN: %clang_cc1 -E -dM -ffreestanding -triple=amd64-unknown-openbsd6.1 < 
/dev/null | FileCheck -match-full-lines -check-prefix OPENBSD %s
 // RUN: %clang_cc1 -E -dM -ffreestanding -triple=aarch64-unknown-openbsd6.1 < 
/dev/null | FileCheck -match-full-lines -check-prefix OPENBSD %s
 // RUN: %clang_cc1 -E -dM -ffreestanding 
-triple=arm-unknown-openbsd6.1-gnueabi < /dev/null | FileCheck 
-match-full-lines -check-prefix OPENBSD %s

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


[clang] [X86] Add USER_MSR instructions. (PR #68944)

2023-10-15 Thread Phoebe Wang via cfe-commits

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


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


[clang] [Driver] Hook up Haiku PowerPC support (PR #69134)

2023-10-15 Thread Brad Smith via cfe-commits

https://github.com/brad0 created https://github.com/llvm/llvm-project/pull/69134

None

>From 914b3424d93f985c34ddc4180ff6271c8145e4ac Mon Sep 17 00:00:00 2001
From: Brad Smith 
Date: Wed, 11 Oct 2023 19:25:33 -0400
Subject: [PATCH] [Driver] Hook up Haiku PowerPC support

---
 clang/lib/Basic/Targets.cpp| 2 ++
 clang/test/Preprocessor/init.c | 9 +
 2 files changed, 11 insertions(+)

diff --git a/clang/lib/Basic/Targets.cpp b/clang/lib/Basic/Targets.cpp
index 8130f90a276749e..770f33f0efc9de3 100644
--- a/clang/lib/Basic/Targets.cpp
+++ b/clang/lib/Basic/Targets.cpp
@@ -361,6 +361,8 @@ std::unique_ptr AllocateTarget(const 
llvm::Triple ,
 
   case llvm::Triple::ppc:
 switch (os) {
+case llvm::Triple::Haiku:
+  return std::make_unique>(Triple, Opts);
 case llvm::Triple::Linux:
   return std::make_unique>(Triple, Opts);
 case llvm::Triple::FreeBSD:
diff --git a/clang/test/Preprocessor/init.c b/clang/test/Preprocessor/init.c
index 59c5122afe1e4c3..c51de5cff6ad480 100644
--- a/clang/test/Preprocessor/init.c
+++ b/clang/test/Preprocessor/init.c
@@ -1454,6 +1454,15 @@
 // RUN: %clang_cc1 -triple lanai-unknown-unknown -E -dM < /dev/null | 
FileCheck -match-full-lines -check-prefix LANAI %s
 // LANAI: #define __lanai__ 1
 //
+
+// RUN: %clang_cc1 -triple=aarch64-unknown-haiku -E -dM < /dev/null | 
FileCheck -match-full-lines -check-prefix HAIKU %s
+// RUN: %clang_cc1 -triple=arm-unknown-haiku -E -dM < /dev/null | FileCheck 
-match-full-lines -check-prefix HAIKU %s
+// RUN: %clang_cc1 -triple=powerpc-unknown-haiku -E -dM < /dev/null | 
FileCheck -match-full-lines -check-prefix HAIKU %s
+// RUN: %clang_cc1 -triple=riscv64-unknown-haiku -E -dM < /dev/null | 
FileCheck -match-full-lines -check-prefix HAIKU %s
+// RUN: %clang_cc1 -triple=x86-unknown-haiku -E -dM < /dev/null | FileCheck 
-match-full-lines -check-prefix HAIKU %s
+// RUN: %clang_cc1 -triple=x86_64-unknown-haiku -E -dM < /dev/null | FileCheck 
-match-full-lines -check-prefix HAIKU %s
+// HAIKU: #define __HAIKU__ 1
+
 // RUN: %clang_cc1 -E -dM -ffreestanding -triple=amd64-unknown-openbsd6.1 < 
/dev/null | FileCheck -match-full-lines -check-prefix OPENBSD %s
 // RUN: %clang_cc1 -E -dM -ffreestanding -triple=aarch64-unknown-openbsd6.1 < 
/dev/null | FileCheck -match-full-lines -check-prefix OPENBSD %s
 // RUN: %clang_cc1 -E -dM -ffreestanding 
-triple=arm-unknown-openbsd6.1-gnueabi < /dev/null | FileCheck 
-match-full-lines -check-prefix OPENBSD %s

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


[clang] [X86] Add USER_MSR instructions. (PR #68944)

2023-10-15 Thread Freddy Ye via cfe-commits

https://github.com/FreddyLeaf updated 
https://github.com/llvm/llvm-project/pull/68944

>From 2377ab2b9865d8f152996fd38f6b543767f8c2ae Mon Sep 17 00:00:00 2001
From: Freddy Ye 
Date: Wed, 11 Oct 2023 14:09:02 +0800
Subject: [PATCH 1/3] Add USER_MSR instructions.

For more details about this instruction, please refer to the latest ISE 
document: 
https://www.intel.com/content/www/us/en/develop/download/intel-architecture-instruction-set-extensions-programming-reference.html
---
 clang/docs/ReleaseNotes.rst   |  3 +
 clang/include/clang/Basic/BuiltinsX86_64.def  |  3 +
 clang/include/clang/Driver/Options.td |  2 +
 clang/lib/Basic/Targets/X86.cpp   |  6 ++
 clang/lib/Basic/Targets/X86.h |  1 +
 clang/lib/Headers/CMakeLists.txt  |  1 +
 clang/lib/Headers/usermsrintrin.h | 30 +
 clang/lib/Headers/x86gprintrin.h  |  5 ++
 .../CodeGen/X86/usermsr-builtins-error-32.c   | 14 
 clang/test/CodeGen/X86/usermsr-builtins.c | 29 +
 clang/test/Driver/x86-target-features.c   |  5 ++
 clang/test/Preprocessor/x86_target_features.c |  6 ++
 llvm/CMakeLists.txt   |  2 -
 llvm/docs/ReleaseNotes.rst|  1 +
 llvm/include/llvm/IR/IntrinsicsX86.td | 10 ++-
 .../Support/X86DisassemblerDecoderCommon.h|  5 +-
 .../llvm/TargetParser/X86TargetParser.def |  1 +
 .../X86/Disassembler/X86Disassembler.cpp  |  9 +++
 .../X86/Disassembler/X86DisassemblerDecoder.h |  3 +-
 .../lib/Target/X86/MCTargetDesc/X86BaseInfo.h |  3 +-
 .../X86/MCTargetDesc/X86MCCodeEmitter.cpp |  4 ++
 llvm/lib/Target/X86/X86.td|  2 +
 llvm/lib/Target/X86/X86InstrFormats.td|  4 ++
 llvm/lib/Target/X86/X86InstrInfo.td   |  1 +
 llvm/lib/Target/X86/X86InstrSystem.td | 16 +
 llvm/lib/TargetParser/Host.cpp|  1 +
 llvm/lib/TargetParser/X86TargetParser.cpp |  1 +
 llvm/test/CodeGen/X86/usermsr-intrinsics.ll   | 64 +++
 llvm/test/MC/Disassembler/X86/usermsr-64.txt  | 26 
 llvm/test/MC/X86/usermsr-64-att.s | 18 ++
 llvm/test/MC/X86/usermsr-64-intel.s   | 18 ++
 llvm/utils/TableGen/X86DisassemblerTables.cpp |  1 +
 llvm/utils/TableGen/X86DisassemblerTables.h   |  3 +-
 llvm/utils/TableGen/X86RecognizableInstr.cpp  |  1 +
 llvm/utils/TableGen/X86RecognizableInstr.h|  2 +-
 35 files changed, 293 insertions(+), 8 deletions(-)
 create mode 100644 clang/lib/Headers/usermsrintrin.h
 create mode 100644 clang/test/CodeGen/X86/usermsr-builtins-error-32.c
 create mode 100644 clang/test/CodeGen/X86/usermsr-builtins.c
 create mode 100644 llvm/test/CodeGen/X86/usermsr-intrinsics.ll
 create mode 100644 llvm/test/MC/Disassembler/X86/usermsr-64.txt
 create mode 100644 llvm/test/MC/X86/usermsr-64-att.s
 create mode 100644 llvm/test/MC/X86/usermsr-64-intel.s

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 31969201a1cac8c..5300f8458760809 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -538,6 +538,9 @@ X86 Support
 
 - Added option ``-m[no-]evex512`` to disable ZMM and 64-bit mask instructions
   for AVX512 features.
+- Support ISA of ``USER_MSR``.
+  * Support intrinsic of ``_urdmsr``.
+  * Support intrinsic of ``_uwrmsr``.
 
 Arm and AArch64 Support
 ^^^
diff --git a/clang/include/clang/Basic/BuiltinsX86_64.def 
b/clang/include/clang/Basic/BuiltinsX86_64.def
index e5c1fe8b319217e..5e00916d4b25ae3 100644
--- a/clang/include/clang/Basic/BuiltinsX86_64.def
+++ b/clang/include/clang/Basic/BuiltinsX86_64.def
@@ -104,6 +104,9 @@ TARGET_BUILTIN(__builtin_ia32_clui, "v", "n", "uintr")
 TARGET_BUILTIN(__builtin_ia32_stui, "v", "n", "uintr")
 TARGET_BUILTIN(__builtin_ia32_testui, "Uc", "n", "uintr")
 TARGET_BUILTIN(__builtin_ia32_senduipi, "vUWi", "n", "uintr")
+// USERMSR
+TARGET_BUILTIN(__builtin_ia32_urdmsr, "ULLiULLi", "n", "usermsr")
+TARGET_BUILTIN(__builtin_ia32_uwrmsr, "vULLiULLi", "n", "usermsr")
 
 // AMX internal builtin
 TARGET_BUILTIN(__builtin_ia32_tile_loadconfig_internal, "vvC*", "n", 
"amx-tile")
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 3f2058a5d4650ca..f0ee6eba67374d8 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5904,6 +5904,8 @@ def mtsxldtrk : Flag<["-"], "mtsxldtrk">, 
Group;
 def mno_tsxldtrk : Flag<["-"], "mno-tsxldtrk">, Group;
 def muintr : Flag<["-"], "muintr">, Group;
 def mno_uintr : Flag<["-"], "mno-uintr">, Group;
+def musermsr : Flag<["-"], "musermsr">, Group;
+def mno_usermsr : Flag<["-"], "mno-usermsr">, Group;
 def mvaes : Flag<["-"], "mvaes">, Group;
 def mno_vaes : Flag<["-"], "mno-vaes">, Group;
 def mvpclmulqdq : Flag<["-"], "mvpclmulqdq">, Group;
diff --git a/clang/lib/Basic/Targets/X86.cpp b/clang/lib/Basic/Targets/X86.cpp
index 022d5753135e160..bea5c52a7b8d7c9 100644
--- 

[clang-tools-extra] [clang-tidy][modernize-loop-convert]check isDependentSizedArrayType (PR #69062)

2023-10-15 Thread Congcong Cai via cfe-commits

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


[clang-tools-extra] 5ae5af1 - [clang-tidy][modernize-loop-convert]check isDependentSizedArrayType (#69062)

2023-10-15 Thread via cfe-commits

Author: Congcong Cai
Date: 2023-10-16T09:02:53+08:00
New Revision: 5ae5af1d7c60ac10d91573d251c2d81083cd6ada

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

LOG: [clang-tidy][modernize-loop-convert]check isDependentSizedArrayType 
(#69062)

Added: 


Modified: 
clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
index f90d99a8d66069d..8beaa62c78ba0ab 100644
--- a/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
@@ -753,6 +753,7 @@ void LoopConvertCheck::doConversion(
   bool IsCheapToCopy =
   !Descriptor.ElemType.isNull() &&
   Descriptor.ElemType.isTriviallyCopyableType(*Context) &&
+  !Descriptor.ElemType->isDependentSizedArrayType() &&
   // TypeInfo::Width is in bits.
   Context->getTypeInfo(Descriptor.ElemType).Width <= 8 * MaxCopySize;
   bool UseCopy = CanCopy && ((VarNameFromAlias && !AliasVarIsRef) ||

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index c732d4904df13fa..af164d0462d52c1 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -271,7 +271,8 @@ Changes in existing checks
 
 - Improved :doc:`modernize-loop-convert
   ` to support for-loops with
-  iterators initialized by free functions like ``begin``, ``end``, or ``size``.
+  iterators initialized by free functions like ``begin``, ``end``, or ``size``
+  and avoid crash for array of dependent array.
 
 - Improved :doc:`modernize-return-braced-init-list
   ` check to ignore

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp
index 71ae4c46e6a5e95..e2b9336d620f507 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp
@@ -939,4 +939,18 @@ void fundamentalTypesTest() {
   // CHECK-FIXES: for (double Double : Doubles)
 }
 
+template  void _dependenceArrayTest() {
+  unsigned test[3][p];
+  for (unsigned i = 0; i < p; ++i)
+for (unsigned j = 0; j < 3; ++j)
+  printf("%d", test[j][i]);
+  // CHECK-MESSAGES: :[[@LINE-2]]:5: warning: use range-based for loop instead
+  // CHECK-FIXES: (auto & j : test)
+  // CHECK-FIXES: printf("%d", j[i]);
+}
+void dependenceArrayTest() {
+  _dependenceArrayTest<1>();
+  _dependenceArrayTest<2>();
+}
+
 } // namespace PseudoArray



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


[clang] [analyzer] Trust base to derived casts for dynamic types (PR #69057)

2023-10-15 Thread Gábor Horváth via cfe-commits

Xazax-hun wrote:

This patch makes me think whether we actually respect final on methods/classes 
to avoid unnecessary bifurcation on virtual calls. We probably do not. 

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


[clang] [analyzer] Trust base to derived casts for dynamic types (PR #69057)

2023-10-15 Thread Gábor Horváth via cfe-commits

https://github.com/Xazax-hun approved this pull request.

Added some nits inline, overall, it looks good to me.

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


[clang] [analyzer] Trust base to derived casts for dynamic types (PR #69057)

2023-10-15 Thread Gábor Horváth via cfe-commits


@@ -609,9 +617,13 @@ storeWhenMoreInformative(ProgramStateRef , SymbolRef 
Sym,
 /// symbol and the destination type of the cast are unrelated, report an error.
 void DynamicTypePropagation::checkPostStmt(const CastExpr *CE,
CheckerContext ) const {
+  ProgramStateRef State = C.getState();
+  ExplodedNode *AfterTypeProp = dynamicTypePropagationOnCasts(CE, State, C);
+
   if (CE->getCastKind() != CK_BitCast)
 return;
 
+  ASTContext  = C.getASTContext();

Xazax-hun wrote:

Do we need to move this?

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


[clang] [analyzer] Trust base to derived casts for dynamic types (PR #69057)

2023-10-15 Thread Gábor Horváth via cfe-commits


@@ -392,19 +393,26 @@ void DynamicTypePropagation::checkPostCall(const 
CallEvent ,
   }
 }
 
-/// TODO: Handle explicit casts.
-///   Handle C++ casts.
-///
-/// Precondition: the cast is between ObjCObjectPointers.
 ExplodedNode *DynamicTypePropagation::dynamicTypePropagationOnCasts(
 const CastExpr *CE, ProgramStateRef , CheckerContext ) const {
   // We only track type info for regions.
   const MemRegion *ToR = C.getSVal(CE).getAsRegion();
   if (!ToR)
 return C.getPredecessor();
 
-  if (isa(CE))
+  if (CE->getCastKind() == CK_BaseToDerived) {
+bool CastSucceeds = true;
+QualType FromTy = CE->getSubExpr()->getType();
+QualType ToTy = CE->getType();
+ToR = ToR->StripCasts(/*StripBaseAndDerivedCasts=*/true);
+State = setDynamicTypeAndCastInfo(State, ToR, FromTy, ToTy, CastSucceeds);

Xazax-hun wrote:

The value `true` could be inlined with a comment. 

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


[clang] [analyzer] Trust base to derived casts for dynamic types (PR #69057)

2023-10-15 Thread Gábor Horváth via cfe-commits

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


[PATCH] D155850: [HIP][Clang][CodeGen][RFC] Add codegen support for C++ Parallel Algorithm Offload

2023-10-15 Thread Alex Voicu via Phabricator via cfe-commits
AlexVlx updated this revision to Diff 557712.
AlexVlx edited the summary of this revision.
AlexVlx added a comment.

Rebase.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155850/new/

https://reviews.llvm.org/D155850

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CGStmt.cpp
  clang/lib/CodeGen/CMakeLists.txt
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/CodeGenHipStdPar/unannotated-functions-get-emitted.cpp
  clang/test/CodeGenHipStdPar/unsupported-ASM.cpp
  clang/test/CodeGenHipStdPar/unsupported-builtins.cpp

Index: clang/test/CodeGenHipStdPar/unsupported-builtins.cpp
===
--- /dev/null
+++ clang/test/CodeGenHipStdPar/unsupported-builtins.cpp
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -aux-triple x86_64-unknown-linux-gnu \
+// RUN:   --hipstdpar -x hip -emit-llvm -fcuda-is-device -o - %s | FileCheck %s
+
+#define __global__ __attribute__((global))
+
+__global__ void foo() { return __builtin_ia32_pause(); }
+
+// CHECK: declare void @__builtin_ia32_pause__hipstdpar_unsupported()
Index: clang/test/CodeGenHipStdPar/unsupported-ASM.cpp
===
--- /dev/null
+++ clang/test/CodeGenHipStdPar/unsupported-ASM.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -aux-triple x86_64-unknown-linux-gnu \
+// RUN:   --hipstdpar -x hip -emit-llvm -fcuda-is-device -o - %s | FileCheck %s
+
+#define __global__ __attribute__((global))
+
+__global__ void foo(int i) {
+asm ("addl %2, %1; seto %b0" : "=q" (i), "+g" (i) : "r" (i));
+}
+
+// CHECK: declare void @__ASM__hipstdpar_unsupported([{{.*}}])
Index: clang/test/CodeGenHipStdPar/unannotated-functions-get-emitted.cpp
===
--- /dev/null
+++ clang/test/CodeGenHipStdPar/unannotated-functions-get-emitted.cpp
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -x hip -emit-llvm -fcuda-is-device \
+// RUN:   -o - %s | FileCheck --check-prefix=NO-HIPSTDPAR-DEV %s
+
+// RUN: %clang_cc1 --hipstdpar -emit-llvm -fcuda-is-device \
+// RUN:   -o - %s | FileCheck --check-prefix=HIPSTDPAR-DEV %s
+
+#define __device__ __attribute__((device))
+
+// NO-HIPSTDPAR-DEV-NOT: define {{.*}} void @foo({{.*}})
+// HIPSTDPAR-DEV: define {{.*}} void @foo({{.*}})
+extern "C" void foo(float *a, float b) {
+  *a = b;
+}
+
+// NO-HIPSTDPAR-DEV: define {{.*}} void @bar({{.*}})
+// HIPSTDPAR-DEV: define {{.*}} void @bar({{.*}})
+extern "C" __device__ void bar(float *a, float b) {
+  *a = b;
+}
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -3526,7 +3526,7 @@
 GV->setComdat(TheModule.getOrInsertComdat(GV->getName()));
   Emitter.finalize(GV);
 
-  return ConstantAddress(GV, GV->getValueType(), Alignment);
+return ConstantAddress(GV, GV->getValueType(), Alignment);
 }
 
 ConstantAddress CodeGenModule::GetWeakRefReference(const ValueDecl *VD) {
@@ -3585,7 +3585,10 @@
   !Global->hasAttr() &&
   !Global->hasAttr() &&
   !Global->getType()->isCUDADeviceBuiltinSurfaceType() &&
-  !Global->getType()->isCUDADeviceBuiltinTextureType())
+  !Global->getType()->isCUDADeviceBuiltinTextureType() &&
+  !(LangOpts.HIPStdPar &&
+isa(Global) &&
+!Global->hasAttr()))
 return;
 } else {
   // We need to emit host-side 'shadows' for all global
Index: clang/lib/CodeGen/CodeGenFunction.cpp
===
--- clang/lib/CodeGen/CodeGenFunction.cpp
+++ clang/lib/CodeGen/CodeGenFunction.cpp
@@ -2594,10 +2594,15 @@
   std::string MissingFeature;
   llvm::StringMap CallerFeatureMap;
   CGM.getContext().getFunctionFeatureMap(CallerFeatureMap, FD);
+  // When compiling in HipStdPar mode we have to be conservative in rejecting
+  // target specific features in the FE, and defer the possible error to the
+  // AcceleratorCodeSelection pass, wherein iff an unsupported target builtin is
+  // referenced by an accelerator executable function, we emit an error.
+  bool IsHipStdPar = getLangOpts().HIPStdPar && getLangOpts().CUDAIsDevice;
   if (BuiltinID) {
 StringRef FeatureList(CGM.getContext().BuiltinInfo.getRequiredFeatures(BuiltinID));
 if (!Builtin::evaluateRequiredTargetFeatures(
-FeatureList, CallerFeatureMap)) {
+FeatureList, CallerFeatureMap) && !IsHipStdPar) {
   CGM.getDiags().Report(Loc, diag::err_builtin_needs_feature)
   << TargetDecl->getDeclName()
   << FeatureList;
@@ -2630,7 +2635,7 @@
 return false;
   }
   return true;
-}))
+}) && !IsHipStdPar)
   CGM.getDiags().Report(Loc, diag::err_function_needs_feature)
   << FD->getDeclName() << 

[clang-tools-extra] [clang-tidy][modernize-loop-convert]check isDependentSizedArrayType (PR #69062)

2023-10-15 Thread Congcong Cai via cfe-commits

https://github.com/HerrCai0907 updated 
https://github.com/llvm/llvm-project/pull/69062

>From bfeaa2eeaa3d20e1919288bcf1027ec196378236 Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Sun, 15 Oct 2023 00:20:08 +0800
Subject: [PATCH 1/3] [clang-tidy][modernize-loop-convert]check
 isDependentSizedArrayType before resolve type size

---
 .../clang-tidy/modernize/LoopConvertCheck.cpp| 1 +
 clang-tools-extra/docs/ReleaseNotes.rst  | 4 
 .../clang-tidy/checkers/modernize/loop-convert-basic.cpp | 9 +
 3 files changed, 14 insertions(+)

diff --git a/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
index f90d99a8d66069d..8beaa62c78ba0ab 100644
--- a/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
@@ -753,6 +753,7 @@ void LoopConvertCheck::doConversion(
   bool IsCheapToCopy =
   !Descriptor.ElemType.isNull() &&
   Descriptor.ElemType.isTriviallyCopyableType(*Context) &&
+  !Descriptor.ElemType->isDependentSizedArrayType() &&
   // TypeInfo::Width is in bits.
   Context->getTypeInfo(Descriptor.ElemType).Width <= 8 * MaxCopySize;
   bool UseCopy = CanCopy && ((VarNameFromAlias && !AliasVarIsRef) ||
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 03e5dc6f164af2a..ae440210d8a4f2b 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -269,6 +269,10 @@ Changes in existing checks
   ` to support for-loops with
   iterators initialized by free functions like ``begin``, ``end``, or ``size``.
 
+- Improved :doc:`modernize-loop-convert
+   ` to avoid crash dor dependent
+   array.
+
 - Improved :doc:`modernize-return-braced-init-list
   ` check to ignore
   false-positives when constructing the container with ``count`` copies of
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp
index 71ae4c46e6a5e95..8d8144a729bbdee 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp
@@ -939,4 +939,13 @@ void fundamentalTypesTest() {
   // CHECK-FIXES: for (double Double : Doubles)
 }
 
+template  void test() {
+  unsigned int test[3][p];
+  // Initialize to zero
+  for (unsigned int i = 0; i < p; ++i)
+for (unsigned int j = 0; j < 3; ++j) // CHECK-MESSAGES: warning: use 
range-based for loop instead
+  // CHECK-FIXES: (auto & j : test)
+  test[j][i] = 0;
+}
+
 } // namespace PseudoArray

>From 89ddc2510e74b7b7460384860ce691a6784fa82b Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Sun, 15 Oct 2023 09:42:33 +0800
Subject: [PATCH 2/3] fix

---
 clang-tools-extra/docs/ReleaseNotes.rst| 7 ++-
 .../clang-tidy/checkers/modernize/loop-convert-basic.cpp   | 6 --
 2 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index ae440210d8a4f2b..63f9a2418eca5aa 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -267,11 +267,8 @@ Changes in existing checks
 
 - Improved :doc:`modernize-loop-convert
   ` to support for-loops with
-  iterators initialized by free functions like ``begin``, ``end``, or ``size``.
-
-- Improved :doc:`modernize-loop-convert
-   ` to avoid crash dor dependent
-   array.
+  iterators initialized by free functions like ``begin``, ``end``, or ``size``
+  and avoid crash for array of dependent array.
 
 - Improved :doc:`modernize-return-braced-init-list
   ` check to ignore
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp
index 8d8144a729bbdee..2e43bc6ff96e4e5 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp
@@ -943,9 +943,11 @@ template  void test() {
   unsigned int test[3][p];
   // Initialize to zero
   for (unsigned int i = 0; i < p; ++i)
-for (unsigned int j = 0; j < 3; ++j) // CHECK-MESSAGES: warning: use 
range-based for loop instead
-  // CHECK-FIXES: (auto & j : test)
+for (unsigned int j = 0; j < 3; ++j)
   test[j][i] = 0;
+  // CHECK-MESSAGES: :[[@LINE-2]]:5: warning: use range-based for loop instead
+  // CHECK-FIXES: (auto & j : test)
+  // CHECK-FIXES: j[i] = 0;
 }
 
 } // namespace PseudoArray

>From 4980cbfc04ee9475f01695d4fe9de7952b8ce752 Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Mon, 16 Oct 2023 07:57:23 +0800
Subject: [PATCH 3/3] update test

---
 .../checkers/modernize/loop-convert-basic.cpp   | 17 ++---
 1 file 

[clang-tools-extra] [clang-tidy][modernize-loop-convert]check isDependentSizedArrayType (PR #69062)

2023-10-15 Thread Congcong Cai via cfe-commits

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


[clang-tools-extra] [clang-tidy][modernize-loop-convert]check isDependentSizedArrayType (PR #69062)

2023-10-15 Thread Congcong Cai via cfe-commits

https://github.com/HerrCai0907 updated 
https://github.com/llvm/llvm-project/pull/69062

>From bfeaa2eeaa3d20e1919288bcf1027ec196378236 Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Sun, 15 Oct 2023 00:20:08 +0800
Subject: [PATCH 1/3] [clang-tidy][modernize-loop-convert]check
 isDependentSizedArrayType before resolve type size

---
 .../clang-tidy/modernize/LoopConvertCheck.cpp| 1 +
 clang-tools-extra/docs/ReleaseNotes.rst  | 4 
 .../clang-tidy/checkers/modernize/loop-convert-basic.cpp | 9 +
 3 files changed, 14 insertions(+)

diff --git a/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
index f90d99a8d66069d..8beaa62c78ba0ab 100644
--- a/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
@@ -753,6 +753,7 @@ void LoopConvertCheck::doConversion(
   bool IsCheapToCopy =
   !Descriptor.ElemType.isNull() &&
   Descriptor.ElemType.isTriviallyCopyableType(*Context) &&
+  !Descriptor.ElemType->isDependentSizedArrayType() &&
   // TypeInfo::Width is in bits.
   Context->getTypeInfo(Descriptor.ElemType).Width <= 8 * MaxCopySize;
   bool UseCopy = CanCopy && ((VarNameFromAlias && !AliasVarIsRef) ||
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 03e5dc6f164af2a..ae440210d8a4f2b 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -269,6 +269,10 @@ Changes in existing checks
   ` to support for-loops with
   iterators initialized by free functions like ``begin``, ``end``, or ``size``.
 
+- Improved :doc:`modernize-loop-convert
+   ` to avoid crash dor dependent
+   array.
+
 - Improved :doc:`modernize-return-braced-init-list
   ` check to ignore
   false-positives when constructing the container with ``count`` copies of
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp
index 71ae4c46e6a5e95..8d8144a729bbdee 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp
@@ -939,4 +939,13 @@ void fundamentalTypesTest() {
   // CHECK-FIXES: for (double Double : Doubles)
 }
 
+template  void test() {
+  unsigned int test[3][p];
+  // Initialize to zero
+  for (unsigned int i = 0; i < p; ++i)
+for (unsigned int j = 0; j < 3; ++j) // CHECK-MESSAGES: warning: use 
range-based for loop instead
+  // CHECK-FIXES: (auto & j : test)
+  test[j][i] = 0;
+}
+
 } // namespace PseudoArray

>From 89ddc2510e74b7b7460384860ce691a6784fa82b Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Sun, 15 Oct 2023 09:42:33 +0800
Subject: [PATCH 2/3] fix

---
 clang-tools-extra/docs/ReleaseNotes.rst| 7 ++-
 .../clang-tidy/checkers/modernize/loop-convert-basic.cpp   | 6 --
 2 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index ae440210d8a4f2b..63f9a2418eca5aa 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -267,11 +267,8 @@ Changes in existing checks
 
 - Improved :doc:`modernize-loop-convert
   ` to support for-loops with
-  iterators initialized by free functions like ``begin``, ``end``, or ``size``.
-
-- Improved :doc:`modernize-loop-convert
-   ` to avoid crash dor dependent
-   array.
+  iterators initialized by free functions like ``begin``, ``end``, or ``size``
+  and avoid crash for array of dependent array.
 
 - Improved :doc:`modernize-return-braced-init-list
   ` check to ignore
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp
index 8d8144a729bbdee..2e43bc6ff96e4e5 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp
@@ -943,9 +943,11 @@ template  void test() {
   unsigned int test[3][p];
   // Initialize to zero
   for (unsigned int i = 0; i < p; ++i)
-for (unsigned int j = 0; j < 3; ++j) // CHECK-MESSAGES: warning: use 
range-based for loop instead
-  // CHECK-FIXES: (auto & j : test)
+for (unsigned int j = 0; j < 3; ++j)
   test[j][i] = 0;
+  // CHECK-MESSAGES: :[[@LINE-2]]:5: warning: use range-based for loop instead
+  // CHECK-FIXES: (auto & j : test)
+  // CHECK-FIXES: j[i] = 0;
 }
 
 } // namespace PseudoArray

>From 81a9b420f2cd64bf9c33c23fcc793f56bcce8ddb Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Mon, 16 Oct 2023 07:57:23 +0800
Subject: [PATCH 3/3] update test

---
 .../checkers/modernize/loop-convert-basic.cpp   | 13 ++---
 1 file 

[clang] [Driver][DragonFly] Fixes for linker path and command-line option handling (PR #69095)

2023-10-15 Thread Brad Smith via cfe-commits

https://github.com/brad0 updated https://github.com/llvm/llvm-project/pull/69095

>From a8ff33aecfbcb130e4d47fd099e02f5f40f433ea Mon Sep 17 00:00:00 2001
From: Brad Smith 
Date: Sun, 15 Oct 2023 04:00:56 -0400
Subject: [PATCH] [Driver][DragonFly] Fixes for linker path and command-line
 option handling

Add in some other linker command line options that the other BSD's
handle and make use of AddFilePathLibArgs().
---
 clang/lib/Driver/ToolChains/DragonFly.cpp | 12 ++--
 clang/test/Driver/dragonfly.c | 10 --
 2 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/DragonFly.cpp 
b/clang/lib/Driver/ToolChains/DragonFly.cpp
index a58983aba5a12f2..a4163a5f595372e 100644
--- a/clang/lib/Driver/ToolChains/DragonFly.cpp
+++ b/clang/lib/Driver/ToolChains/DragonFly.cpp
@@ -56,7 +56,9 @@ void dragonfly::Linker::ConstructJob(Compilation , const 
JobAction ,
  const InputInfoList ,
  const ArgList ,
  const char *LinkingOutput) const {
-  const Driver  = getToolChain().getDriver();
+  const toolchains::DragonFly  =
+  static_cast(getToolChain());
+  const Driver  = ToolChain.getDriver();
   ArgStringList CmdArgs;
 
   if (!D.SysRoot.empty())
@@ -115,16 +117,14 @@ void dragonfly::Linker::ConstructJob(Compilation , 
const JobAction ,
   Args.MakeArgString(getToolChain().GetFilePath("crtbegin.o")));
   }
 
-  Args.addAllArgs(CmdArgs, {options::OPT_L, options::OPT_T_Group});
+  Args.addAllArgs(CmdArgs, {options::OPT_L, options::OPT_T_Group,
+options::OPT_s, options::OPT_t, options::OPT_r});
+  ToolChain.AddFilePathLibArgs(Args, CmdArgs);
 
   AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs, JA);
 
   if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs,
options::OPT_r)) {
-SmallString<128> Dir(D.SysRoot);
-llvm::sys::path::append(Dir, "/usr/lib/gcc80");
-CmdArgs.push_back(Args.MakeArgString("-L" + Dir));
-
 if (!Args.hasArg(options::OPT_static)) {
   CmdArgs.push_back("-rpath");
   CmdArgs.push_back("/usr/lib/gcc80");
diff --git a/clang/test/Driver/dragonfly.c b/clang/test/Driver/dragonfly.c
index 8ba13c41d632c20..c87b82b3bffd5d2 100644
--- a/clang/test/Driver/dragonfly.c
+++ b/clang/test/Driver/dragonfly.c
@@ -2,7 +2,7 @@
 // RUN: FileCheck -input-file %t.log %s
 
 // CHECK: "-cc1" "-triple" "x86_64-pc-dragonfly"
-// CHECK: ld{{.*}}" "--eh-frame-hdr" "-dynamic-linker" 
"/usr/libexec/ld-elf.so.{{.*}}" "--hash-style=gnu" "--enable-new-dtags" "-o" 
"a.out" "{{.*}}crt1.o" "{{.*}}crti.o" "{{.*}}crtbegin.o" "{{.*}}.o" 
"-L{{.*}}gcc{{.*}}" "-rpath" "{{.*}}gcc{{.*}}" "-lc" "-lgcc" "{{.*}}crtend.o" 
"{{.*}}crtn.o"
+// CHECK: ld{{.*}}" "--eh-frame-hdr" "-dynamic-linker" 
"/usr/libexec/ld-elf.so.{{.*}}" "--hash-style=gnu" "--enable-new-dtags" "-o" 
"a.out" "{{.*}}crt1.o" "{{.*}}crti.o" "{{.*}}crtbegin.o" "-L{{.*}}/../lib" 
"-L/usr/lib" "-L/usr/lib/gcc80" "{{.*}}.o" "-rpath" "{{.*}}gcc80{{.*}}" "-lc" 
"-lgcc" "{{.*}}crtend.o" "{{.*}}crtn.o"
 
 // Check x86_64-unknown-dragonfly, X86_64
 // RUN: %clang -### %s 2>&1 --target=x86_64-unknown-dragonfly \
@@ -15,7 +15,8 @@
 // CHECK-LD-X86_64-SAME: 
"[[SYSROOT]]{{/|}}usr{{/|}}lib{{/|}}crt1.o"
 // CHECK-LD-X86_64-SAME: 
"[[SYSROOT]]{{/|}}usr{{/|}}lib{{/|}}crti.o"
 // CHECK-LD-X86_64-SAME: 
"[[SYSROOT]]{{/|}}usr{{/|}}lib{{/|}}gcc80{{/|}}crtbegin.o"
-// CHECK-LD-X86_64-SAME: 
"-L[[SYSROOT]]{{/|}}usr{{/|}}lib{{/|}}gcc80" "-rpath" 
"/usr/lib/gcc80" "-lc" "-lgcc" "--as-needed" "-lgcc_pic" "--no-as-needed"
+// CHECK-LD-X86_64-SAME: "-L[[SYSROOT]]{{/|}}usr{{/|}}lib" 
"-L[[SYSROOT]]{{/|}}usr{{/|}}lib{{/|}}gcc80"
+// CHECK-LD-X86_64-SAME: "-rpath" "/usr/lib/gcc80" "-lc" "-lgcc" "--as-needed" 
"-lgcc_pic" "--no-as-needed"
 // CHECK-LD-X86_64-SAME: 
"[[SYSROOT]]{{/|}}usr{{/|}}lib{{/|}}gcc80{{/|}}crtend.o"
 // CHECK-LD-X86_64-SAME: 
"[[SYSROOT]]{{/|}}usr{{/|}}lib{{/|}}crtn.o"
 
@@ -26,3 +27,8 @@
 // RELOCATABLE-NOT: "-dynamic-linker"
 // RELOCATABLE-NOT: "-l
 // RELOCATABLE-NOT: {{.*}}crt{{[^./]+}}.o
+
+// Check that the new linker flags are passed to DraonFly
+// RUN: %clang --target=x86_64-unknown-dragonfly -s -t -### %s 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-LD-FLAGS %s
+// CHECK-LD-FLAGS: ld{{.*}}" "{{.*}}" "-s" "-t"

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


[clang] [Driver] Don't pass -Z to ld for ELF platforms (PR #69120)

2023-10-15 Thread Brad Smith via cfe-commits

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


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


[clang] [Driver] Don't pass -Z to ld for ELF platforms (PR #69120)

2023-10-15 Thread Brad Smith via cfe-commits

brad0 wrote:

OpenBSD has a -Z flag for our BFD linker.

```-ZProduce 'Standard' executables, disables Writable XOR Executable 
features in resulting binaries.```

https://github.com/openbsd/src/commit/0abdc3723b5d33dde698ab941325edec2819c128
https://github.com/openbsd/src/commit/58cb065838343f5d972d625775790ebb89f56d88
https://github.com/openbsd/src/commit/0bd5fc2a33971fd1cca748eda19e75844fa9c27a

But it was never ported to our copy of LLD, which is what almost all of our 
Clang switched archs use, plus I can't seem to find any use of the flag 
anywhere nowadays.

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


[clang] [clang] Add /Zc:__STDC__ flag to clang-cl (PR #68690)

2023-10-15 Thread via cfe-commits

https://github.com/xbjfk updated https://github.com/llvm/llvm-project/pull/68690

>From a89bee09fa7564f336886ff0eb76987b939c0c2c Mon Sep 17 00:00:00 2001
From: Reagan Bohan 
Date: Sun, 15 Oct 2023 23:26:02 +
Subject: [PATCH] [clang] Add /Zc:__STDC__ flag to clang-cl

This commit adds the /Zc:__STDC__ argument from MSVC, which defines __STDC__.
This means, alongside stronger feature parity with MSVC,
that things that rely on __STDC__, such as autoconf, can work.
---
 clang/docs/ReleaseNotes.rst   |  3 +++
 clang/include/clang/Basic/LangOptions.def |  2 +-
 clang/include/clang/Driver/Options.td |  7 +++
 clang/lib/Driver/ToolChains/Clang.cpp |  9 -
 clang/lib/Frontend/InitPreprocessor.cpp   |  3 ++-
 clang/test/Driver/cl-zc.cpp   |  9 +
 clang/test/Driver/ms-define-stdc.c| 11 +++
 7 files changed, 41 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/Driver/ms-define-stdc.c

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 2d918967e7f0b02..1932ee0e0661f4e 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -184,6 +184,9 @@ New Compiler Flags
   preserving ``#include`` directives for "system" headers instead of copying
   the preprocessed text to the output. This can greatly reduce the size of the
   preprocessed output, which can be helpful when trying to reduce a test case.
+* ``-fms-define-stdc`` and its clang-cl counterpart ``/Zc:__STDC__``.
+  Matches MSVC behaviour by defining ``__STDC__`` to ``1`` when
+  MSVC compatibility mode is used. It has no effect for C++ code.
 
 Deprecated Compiler Flags
 -
diff --git a/clang/include/clang/Basic/LangOptions.def 
b/clang/include/clang/Basic/LangOptions.def
index c0ea4ecb9806a5b..b170dbd35c7e783 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -282,7 +282,7 @@ LANGOPT(HIPUseNewLaunchAPI, 1, 0, "Use new kernel launching 
API for HIP")
 LANGOPT(OffloadUniformBlock, 1, 0, "Assume that kernels are launched with 
uniform block sizes (default true for CUDA/HIP and false otherwise)")
 LANGOPT(HIPStdPar, 1, 0, "Enable Standard Parallel Algorithm Acceleration for 
HIP (experimental)")
 LANGOPT(HIPStdParInterposeAlloc, 1, 0, "Replace allocations / deallocations 
with HIP RT calls when Standard Parallel Algorithm Acceleration for HIP is 
enabled (Experimental)")
-
+LANGOPT(MSVCEnableStdcMacro , 1, 0, "Define __STDC__ with 
'-fms-compatability'")
 LANGOPT(SizedDeallocation , 1, 0, "sized deallocation")
 LANGOPT(AlignedAllocation , 1, 0, "aligned allocation")
 LANGOPT(AlignedAllocationUnavailable, 1, 0, "aligned allocation functions are 
unavailable")
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index c272a7f1c398aa6..106a1de898764f3 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2821,6 +2821,10 @@ def fms_compatibility : Flag<["-"], 
"fms-compatibility">, Group,
   Visibility<[ClangOption, CC1Option, CLOption]>,
   HelpText<"Enable full Microsoft Visual C++ compatibility">,
   MarshallingInfoFlag>;
+def fms_define_stdc : Flag<["-"], "fms-define-stdc">, Group,
+  Visibility<[ClangOption, CC1Option]>,
+  HelpText<"Define '__STDC__' to '1' in MSVC Compatibility mode">,
+  MarshallingInfoFlag>;
 def fms_extensions : Flag<["-"], "fms-extensions">, Group,
   Visibility<[ClangOption, CC1Option, CLOption]>,
   HelpText<"Accept some non-standard constructs supported by the Microsoft 
compiler">,
@@ -7933,6 +7937,9 @@ def _SLASH_vd : CLJoined<"vd">, HelpText<"Control 
vtordisp placement">,
   Alias;
 def _SLASH_X : CLFlag<"X">,
   HelpText<"Do not add %INCLUDE% to include search path">, Alias;
+def _SLASH_Zc___STDC__ : CLFlag<"Zc:__STDC__">,
+  HelpText<"Define __STDC__">,
+  Alias;
 def _SLASH_Zc_sizedDealloc : CLFlag<"Zc:sizedDealloc">,
   HelpText<"Enable C++14 sized global deallocation functions">,
   Alias;
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index bfd6c5c2864abf7..6f10ecf9dcb3108 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -6744,8 +6744,12 @@ void Clang::ConstructJob(Compilation , const JobAction 
,
   options::OPT_fms_compatibility, options::OPT_fno_ms_compatibility,
   (IsWindowsMSVC && Args.hasFlag(options::OPT_fms_extensions,
  options::OPT_fno_ms_extensions, true)));
-  if (IsMSVCCompat)
+  if (IsMSVCCompat) {
 CmdArgs.push_back("-fms-compatibility");
+if (!types::isCXX(Input.getType()) &&
+Args.hasArg(options::OPT_fms_define_stdc))
+  CmdArgs.push_back("-fms-define-stdc");
+  }
 
   if (Triple.isWindowsMSVCEnvironment() && !D.IsCLMode() &&
   Args.hasArg(options::OPT_fms_runtime_lib_EQ))
@@ -7922,6 +7926,9 @@ void Clang::AddClangCLArgs(const ArgList , types::ID 
InputType,

[clang] [Clang][CMake] Support perf, LBR, and Instrument CLANG_BOLT options (PR #69133)

2023-10-15 Thread Amir Ayupov via cfe-commits

https://github.com/aaupov updated 
https://github.com/llvm/llvm-project/pull/69133

>From 96e644279ccec1970c42cca89c05aac186b872e6 Mon Sep 17 00:00:00 2001
From: Amir Aupov 
Date: Mon, 16 Oct 2023 01:08:28 +0200
Subject: [PATCH] [Clang][CMake] Support perf, LBR, and Instrument CLANG_BOLT
 options

Split up and refactor CLANG_BOLT_INSTRUMENT into support for
perf no-LBR and perf with LBR profiling modes.

Differential Revision: https://reviews.llvm.org/D143617
---
 clang/CMakeLists.txt  | 44 -
 clang/cmake/caches/BOLT.cmake |  2 +-
 clang/utils/perf-training/CMakeLists.txt  | 29 -
 clang/utils/perf-training/bolt.lit.cfg| 53 +---
 .../utils/perf-training/bolt.lit.site.cfg.in  |  2 +
 clang/utils/perf-training/perf-helper.py  | 63 +++
 6 files changed, 167 insertions(+), 26 deletions(-)

diff --git a/clang/CMakeLists.txt b/clang/CMakeLists.txt
index 9b52c58be41e7f7..8f64d95cc394ffe 100644
--- a/clang/CMakeLists.txt
+++ b/clang/CMakeLists.txt
@@ -850,23 +850,38 @@ if (CLANG_ENABLE_BOOTSTRAP)
   endforeach()
 endif()
 
-if (CLANG_BOLT_INSTRUMENT AND NOT LLVM_BUILD_INSTRUMENTED)
+set(CLANG_BOLT "INSTRUMENT" CACHE STRING "Apply BOLT optimization to Clang. \
+  May be specified as Instrument or Perf or LBR to use a particular profiling \
+  mechanism.")
+string(TOUPPER "${CLANG_BOLT}" uppercase_CLANG_BOLT)
+
+if (CLANG_BOLT AND NOT LLVM_BUILD_INSTRUMENTED)
   set(CLANG_PATH ${LLVM_RUNTIME_OUTPUT_INTDIR}/clang)
-  set(CLANG_INSTRUMENTED ${CLANG_PATH}-bolt.inst)
+  set(CLANG_INSTRUMENTED 
${LLVM_RUNTIME_OUTPUT_INTDIR}/${CLANG_BOLT_INSTRUMENTED})
   set(BOLT_FDATA ${CMAKE_CURRENT_BINARY_DIR}/utils/perf-training/prof.fdata)
 
-  # Instrument clang with BOLT
-  add_custom_target(clang-instrumented
-DEPENDS ${CLANG_INSTRUMENTED}
-  )
-  add_custom_command(OUTPUT ${CLANG_INSTRUMENTED}
-DEPENDS clang llvm-bolt
-COMMAND llvm-bolt ${CLANG_PATH} -o ${CLANG_INSTRUMENTED}
-  -instrument --instrumentation-file-append-pid
-  --instrumentation-file=${BOLT_FDATA}
-COMMENT "Instrumenting clang binary with BOLT"
-VERBATIM
-  )
+  # Pass extra flag in no-LBR mode
+  if (uppercase_CLANG_BOLT STREQUAL "PERF")
+set(BOLT_NO_LBR "-nl")
+  endif()
+
+  if (uppercase_CLANG_BOLT STREQUAL "INSTRUMENT")
+# Instrument clang with BOLT
+add_custom_target(clang-instrumented
+  DEPENDS ${CLANG_INSTRUMENTED}
+)
+add_custom_command(OUTPUT ${CLANG_INSTRUMENTED}
+  DEPENDS clang llvm-bolt
+  COMMAND llvm-bolt ${CLANG_PATH} -o ${CLANG_INSTRUMENTED}
+-instrument --instrumentation-file-append-pid
+--instrumentation-file=${BOLT_FDATA}
+  COMMENT "Instrumenting clang binary with BOLT"
+  VERBATIM
+)
+add_custom_target(clang-bolt-training-deps DEPENDS clang-instrumented)
+  else() # perf or LBR
+add_custom_target(clang-bolt-training-deps DEPENDS clang)
+  endif()
 
   # Optimize original (pre-bolt) Clang using the collected profile
   set(CLANG_OPTIMIZED ${CMAKE_CURRENT_BINARY_DIR}/clang.bolt)
@@ -880,6 +895,7 @@ if (CLANG_BOLT_INSTRUMENT AND NOT LLVM_BUILD_INSTRUMENTED)
   -data ${BOLT_FDATA}
   -reorder-blocks=ext-tsp -reorder-functions=hfsort+ -split-functions
   -split-all-cold -split-eh -dyno-stats -icf=1 -use-gnu-stack
+  ${BOLT_NO_LBR}
 COMMAND ${CMAKE_COMMAND} -E rename ${CLANG_OPTIMIZED} $
 COMMENT "Optimizing Clang with BOLT"
 VERBATIM
diff --git a/clang/cmake/caches/BOLT.cmake b/clang/cmake/caches/BOLT.cmake
index 0442f73e5426ac7..eba2346b2f4ca12 100644
--- a/clang/cmake/caches/BOLT.cmake
+++ b/clang/cmake/caches/BOLT.cmake
@@ -1,5 +1,5 @@
 set(CMAKE_BUILD_TYPE Release CACHE STRING "")
-set(CLANG_BOLT_INSTRUMENT ON CACHE BOOL "")
+set(CLANG_BOLT "INSTRUMENT" CACHE STRING "")
 set(CMAKE_EXE_LINKER_FLAGS "-Wl,--emit-relocs,-znow" CACHE STRING "")
 
 set(LLVM_ENABLE_PROJECTS "bolt;clang" CACHE STRING "")
diff --git a/clang/utils/perf-training/CMakeLists.txt 
b/clang/utils/perf-training/CMakeLists.txt
index c6d51863fb1b5c2..48fbee62a8636d1 100644
--- a/clang/utils/perf-training/CMakeLists.txt
+++ b/clang/utils/perf-training/CMakeLists.txt
@@ -62,7 +62,9 @@ if(APPLE AND DTRACE AND NOT LLVM_TOOL_LLVM_DRIVER_BUILD)
 DEPENDS generate-dtrace-logs)
 endif()
 
-if(CLANG_BOLT_INSTRUMENT AND NOT LLVM_BUILD_INSTRUMENTED)
+if(CLANG_BOLT AND NOT LLVM_BUILD_INSTRUMENTED)
+  set(CLANG_BOLT_INSTRUMENTED "clang-bolt.inst" CACHE STRING
+"Name of BOLT-instrumented Clang binary")
   configure_lit_site_cfg(
 ${CMAKE_CURRENT_SOURCE_DIR}/bolt.lit.site.cfg.in
 ${CMAKE_CURRENT_BINARY_DIR}/bolt-fdata/lit.site.cfg
@@ -71,16 +73,37 @@ if(CLANG_BOLT_INSTRUMENT AND NOT LLVM_BUILD_INSTRUMENTED)
   add_lit_testsuite(generate-bolt-fdata "Generating BOLT profile for Clang"
 ${CMAKE_CURRENT_BINARY_DIR}/bolt-fdata/
 EXCLUDE_FROM_CHECK_ALL
-DEPENDS clang-instrumented clear-bolt-fdata
+DEPENDS clang-bolt-training-deps 

[PATCH] D143617: [Clang][CMake] Support perf, LBR, and Instrument CLANG_BOLT options

2023-10-15 Thread Amir Ayupov via Phabricator via cfe-commits
Amir abandoned this revision.
Amir added a comment.

Migrated to https://github.com/llvm/llvm-project/pull/69133


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D143617/new/

https://reviews.llvm.org/D143617

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


[PATCH] D149867: [Clang][M68k] Add Clang support for the new M68k_RTD CC

2023-10-15 Thread Min-Yih Hsu via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGfd4f96290ac9: [Clang][M68k] Add Clang support for the new 
M68k_RTD CC (authored by myhsu).

Changed prior to commit:
  https://reviews.llvm.org/D149867?vs=552596=557711#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149867/new/

https://reviews.llvm.org/D149867

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang-c/Index.h
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/LangOptions.h
  clang/include/clang/Basic/Specifiers.h
  clang/include/clang/Driver/Options.td
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/Type.cpp
  clang/lib/AST/TypePrinter.cpp
  clang/lib/Basic/Targets/M68k.cpp
  clang/lib/Basic/Targets/M68k.h
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/CodeGen/mrtd.c
  clang/test/CodeGenCXX/default_calling_conv.cpp
  clang/test/CodeGenCXX/m68k-rtdcall.cpp
  clang/test/Sema/m68k-rtdcall.c
  clang/test/SemaCXX/m68k-rtdcall.cpp
  clang/tools/libclang/CXType.cpp

Index: clang/tools/libclang/CXType.cpp
===
--- clang/tools/libclang/CXType.cpp
+++ clang/tools/libclang/CXType.cpp
@@ -678,6 +678,7 @@
   TCALLINGCONV(SwiftAsync);
   TCALLINGCONV(PreserveMost);
   TCALLINGCONV(PreserveAll);
+  TCALLINGCONV(M68kRTD);
 case CC_SpirFunction: return CXCallingConv_Unexposed;
 case CC_AMDGPUKernelCall: return CXCallingConv_Unexposed;
 case CC_OpenCLKernel: return CXCallingConv_Unexposed;
Index: clang/test/SemaCXX/m68k-rtdcall.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/m68k-rtdcall.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -triple m68k-linux-gnu -fsyntax-only %s
+
+class A {
+public:
+  void __attribute__((m68k_rtd)) member() {}
+};
+
+void test() {
+  A a;
+  a.member();
+
+  auto f = [](int b) __attribute__((m68k_rtd)) {};
+  f(87);
+};
Index: clang/test/Sema/m68k-rtdcall.c
===
--- /dev/null
+++ clang/test/Sema/m68k-rtdcall.c
@@ -0,0 +1,46 @@
+// RUN: %clang_cc1 -triple m68k-unknown-unknown -mrtd -std=c89 -verify -verify=rtd %s
+// RUN: %clang_cc1 -triple m68k-unknown-unknown -std=c89 -verify -verify=nortd %s
+
+// rtd-error@+2 {{function with no prototype cannot use the m68k_rtd calling convention}}
+void foo(int arg) {
+  bar(arg);
+}
+
+// nortd-note@+4 {{previous declaration is here}}
+// nortd-error@+4 {{function declared 'm68k_rtd' here was previously declared without calling convention}}
+// nortd-note@+4 {{previous declaration is here}}
+// nortd-error@+4 {{function declared 'm68k_rtd' here was previously declared without calling convention}}
+void nonvariadic1(int a, int b, int c);
+void __attribute__((m68k_rtd)) nonvariadic1(int a, int b, int c);
+void nonvariadic2(int a, int b, int c);
+void __attribute__((m68k_rtd)) nonvariadic2(int a, int b, int c) { }
+
+// expected-error@+2 {{variadic function cannot use m68k_rtd calling convention}}
+void variadic(int a, ...);
+void __attribute__((m68k_rtd)) variadic(int a, ...);
+
+// rtd-note@+2 {{previous declaration is here}}
+// rtd-error@+2 {{redeclaration of 'a' with a different type: 'void ((*))(int, int) __attribute__((cdecl))' vs 'void (*)(int, int) __attribute__((m68k_rtd))'}}
+extern void (*a)(int, int);
+__attribute__((cdecl)) extern void (*a)(int, int);
+
+extern void (*b)(int, ...);
+__attribute__((cdecl)) extern void (*b)(int, ...);
+
+// nortd-note@+2 {{previous declaration is here}}
+// nortd-error@+2 {{redeclaration of 'c' with a different type: 'void ((*))(int, int) __attribute__((m68k_rtd))' vs 'void (*)(int, int)'}}
+extern void (*c)(int, int);
+__attribute__((m68k_rtd)) extern void (*c)(int, int);
+
+// expected-error@+2 {{variadic function cannot use m68k_rtd calling convention}}
+extern void (*d)(int, ...);
+__attribute__((m68k_rtd)) extern void (*d)(int, ...);
+
+// expected-warning@+1 {{'m68k_rtd' only applies to function types; type here is 'int'}}
+__attribute__((m68k_rtd)) static int g = 0;
+
+// expected-error@+1 {{'m68k_rtd' attribute takes no arguments}}
+void __attribute__((m68k_rtd("invalid"))) z(int a);
+
+// expected-error@+1 {{function with no prototype cannot use the m68k_rtd calling convention}}
+void __attribute__((m68k_rtd)) e();
Index: clang/test/CodeGenCXX/m68k-rtdcall.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/m68k-rtdcall.cpp
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -triple 

[clang] fd4f962 - [Clang][M68k] Add Clang support for the new M68k_RTD CC

2023-10-15 Thread Min-Yih Hsu via cfe-commits

Author: Min-Yih Hsu
Date: 2023-10-15T16:13:43-07:00
New Revision: fd4f96290ac99bf8b9284d3b32743cac0bb135ea

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

LOG: [Clang][M68k] Add Clang support for the new M68k_RTD CC

This patch adds `CC_M68kRTD`, which will be used on function if either
`__attribute__((m68k_rtd))` is presented or `-mrtd` flag is given.

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

Added: 
clang/test/CodeGenCXX/m68k-rtdcall.cpp
clang/test/Sema/m68k-rtdcall.c
clang/test/SemaCXX/m68k-rtdcall.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang-c/Index.h
clang/include/clang/Basic/Attr.td
clang/include/clang/Basic/AttrDocs.td
clang/include/clang/Basic/LangOptions.h
clang/include/clang/Basic/Specifiers.h
clang/include/clang/Driver/Options.td
clang/lib/AST/ASTContext.cpp
clang/lib/AST/ItaniumMangle.cpp
clang/lib/AST/Type.cpp
clang/lib/AST/TypePrinter.cpp
clang/lib/Basic/Targets/M68k.cpp
clang/lib/Basic/Targets/M68k.h
clang/lib/CodeGen/CGCall.cpp
clang/lib/CodeGen/CGDebugInfo.cpp
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Frontend/CompilerInvocation.cpp
clang/lib/Sema/SemaDeclAttr.cpp
clang/lib/Sema/SemaType.cpp
clang/test/CodeGen/mrtd.c
clang/test/CodeGenCXX/default_calling_conv.cpp
clang/tools/libclang/CXType.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index be7c8bf247f7af5..6d315e9f84ddfe8 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -205,6 +205,10 @@ Modified Compiler Flags
 * ``-frewrite-includes`` now guards the original #include directives with
   ``__CLANG_REWRITTEN_INCLUDES``, and ``__CLANG_REWRITTEN_SYSTEM_INCLUDES`` as
   appropriate.
+* Introducing a new default calling convention for ``-fdefault-calling-conv``:
+  ``rtdcall``. This new default CC only works for M68k and will use the new
+  ``m68k_rtdcc`` CC on every functions that are not variadic. The ``-mrtd``
+  driver/frontend flag has the same effect when targeting M68k.
 
 Removed Compiler Flags
 -

diff  --git a/clang/include/clang-c/Index.h b/clang/include/clang-c/Index.h
index 1b91feabd584c50..64ab3378957c702 100644
--- a/clang/include/clang-c/Index.h
+++ b/clang/include/clang-c/Index.h
@@ -2980,6 +2980,7 @@ enum CXCallingConv {
   CXCallingConv_AArch64VectorCall = 16,
   CXCallingConv_SwiftAsync = 17,
   CXCallingConv_AArch64SVEPCS = 18,
+  CXCallingConv_M68kRTD = 19,
 
   CXCallingConv_Invalid = 100,
   CXCallingConv_Unexposed = 200

diff  --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 5c9eb7b8a981037..5486b36133755cc 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -2805,6 +2805,11 @@ def PreserveAll : DeclOrTypeAttr {
   let Documentation = [PreserveAllDocs];
 }
 
+def M68kRTD: DeclOrTypeAttr {
+  let Spellings = [Clang<"m68k_rtd">];
+  let Documentation = [M68kRTDDocs];
+}
+
 def Target : InheritableAttr {
   let Spellings = [GCC<"target">];
   let Args = [StringArgument<"featuresStr">];

diff  --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 9f9991bdae36155..cbbf69faeb308ad 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -2825,6 +2825,18 @@ See the documentation for `__vectorcall`_ on MSDN for 
more details.
   }];
 }
 
+def M68kRTDDocs : Documentation {
+  let Category = DocCatCallingConvs;
+  let Content = [{
+On M68k targets, this attribute changes the calling convention of a function
+to clear parameters off the stack on return. In other words, callee is
+responsible for cleaning out the stack space allocated for incoming paramters.
+This convention does not support variadic calls or unprototyped functions in C.
+When targeting M68010 or newer CPUs, this calling convention is implemented
+using the `rtd` instruction.
+  }];
+}
+
 def DocCatConsumed : DocumentationCategory<"Consumed Annotation Checking"> {
   let Content = [{
 Clang supports additional attributes for checking basic resource management

diff  --git a/clang/include/clang/Basic/LangOptions.h 
b/clang/include/clang/Basic/LangOptions.h
index e0e95f6d26f4545..20a8ada60e0fe51 100644
--- a/clang/include/clang/Basic/LangOptions.h
+++ b/clang/include/clang/Basic/LangOptions.h
@@ -134,7 +134,8 @@ class LangOptions : public LangOptionsBase {
 DCC_FastCall,
 DCC_StdCall,
 DCC_VectorCall,
-DCC_RegCall
+DCC_RegCall,
+DCC_RtdCall
   };
 
   enum AddrSpaceMapMangling { ASMM_Target, ASMM_On, ASMM_Off };

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

[clang] [Clang][CMake] Support perf, LBR, and Instrument CLANG_BOLT options (PR #69133)

2023-10-15 Thread via cfe-commits

github-actions[bot] wrote:




:warning: Python code formatter, darker found issues in your code. :warning:



You can test this locally with the following command:


``bash
darker --check --diff -r 
7f881a2abe2c3eceeae0272fc41ba0a237770450..3987088f1b6f6b895f7563ad70c97074b0d4ded0
 clang/utils/perf-training/perf-helper.py
``





View the diff from darker here.


``diff
--- perf-helper.py  2023-10-15 23:09:26.00 +
+++ perf-helper.py  2023-10-15 23:14:14.499925 +
@@ -109,13 +109,11 @@
 description="perf2bolt conversion wrapper for perf.data files",
 )
 parser.add_argument("bolt", help="Path to llvm-bolt")
 parser.add_argument("path", help="Path containing perf.data files")
 parser.add_argument("binary", help="Input binary")
-parser.add_argument(
-"--lbr", action="store_true", help="Use LBR perf2bolt mode"
-)
+parser.add_argument("--lbr", action="store_true", help="Use LBR perf2bolt 
mode")
 opts = parser.parse_args(args)
 
 p2b_args = [
 opts.bolt,
 opts.binary,

``




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


[clang] [Clang][CMake] Support perf, LBR, and Instrument CLANG_BOLT options (PR #69133)

2023-10-15 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Amir Ayupov (aaupov)


Changes

Split up and refactor CLANG_BOLT_INSTRUMENT into support for
perf no-LBR and perf with LBR profiling modes.

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


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


6 Files Affected:

- (modified) clang/CMakeLists.txt (+30-14) 
- (modified) clang/cmake/caches/BOLT.cmake (+1-1) 
- (modified) clang/utils/perf-training/CMakeLists.txt (+26-3) 
- (modified) clang/utils/perf-training/bolt.lit.cfg (+45-8) 
- (modified) clang/utils/perf-training/bolt.lit.site.cfg.in (+2) 
- (modified) clang/utils/perf-training/perf-helper.py (+65) 


``diff
diff --git a/clang/CMakeLists.txt b/clang/CMakeLists.txt
index 9b52c58be41e7f7..8f64d95cc394ffe 100644
--- a/clang/CMakeLists.txt
+++ b/clang/CMakeLists.txt
@@ -850,23 +850,38 @@ if (CLANG_ENABLE_BOOTSTRAP)
   endforeach()
 endif()
 
-if (CLANG_BOLT_INSTRUMENT AND NOT LLVM_BUILD_INSTRUMENTED)
+set(CLANG_BOLT "INSTRUMENT" CACHE STRING "Apply BOLT optimization to Clang. \
+  May be specified as Instrument or Perf or LBR to use a particular profiling \
+  mechanism.")
+string(TOUPPER "${CLANG_BOLT}" uppercase_CLANG_BOLT)
+
+if (CLANG_BOLT AND NOT LLVM_BUILD_INSTRUMENTED)
   set(CLANG_PATH ${LLVM_RUNTIME_OUTPUT_INTDIR}/clang)
-  set(CLANG_INSTRUMENTED ${CLANG_PATH}-bolt.inst)
+  set(CLANG_INSTRUMENTED 
${LLVM_RUNTIME_OUTPUT_INTDIR}/${CLANG_BOLT_INSTRUMENTED})
   set(BOLT_FDATA ${CMAKE_CURRENT_BINARY_DIR}/utils/perf-training/prof.fdata)
 
-  # Instrument clang with BOLT
-  add_custom_target(clang-instrumented
-DEPENDS ${CLANG_INSTRUMENTED}
-  )
-  add_custom_command(OUTPUT ${CLANG_INSTRUMENTED}
-DEPENDS clang llvm-bolt
-COMMAND llvm-bolt ${CLANG_PATH} -o ${CLANG_INSTRUMENTED}
-  -instrument --instrumentation-file-append-pid
-  --instrumentation-file=${BOLT_FDATA}
-COMMENT "Instrumenting clang binary with BOLT"
-VERBATIM
-  )
+  # Pass extra flag in no-LBR mode
+  if (uppercase_CLANG_BOLT STREQUAL "PERF")
+set(BOLT_NO_LBR "-nl")
+  endif()
+
+  if (uppercase_CLANG_BOLT STREQUAL "INSTRUMENT")
+# Instrument clang with BOLT
+add_custom_target(clang-instrumented
+  DEPENDS ${CLANG_INSTRUMENTED}
+)
+add_custom_command(OUTPUT ${CLANG_INSTRUMENTED}
+  DEPENDS clang llvm-bolt
+  COMMAND llvm-bolt ${CLANG_PATH} -o ${CLANG_INSTRUMENTED}
+-instrument --instrumentation-file-append-pid
+--instrumentation-file=${BOLT_FDATA}
+  COMMENT "Instrumenting clang binary with BOLT"
+  VERBATIM
+)
+add_custom_target(clang-bolt-training-deps DEPENDS clang-instrumented)
+  else() # perf or LBR
+add_custom_target(clang-bolt-training-deps DEPENDS clang)
+  endif()
 
   # Optimize original (pre-bolt) Clang using the collected profile
   set(CLANG_OPTIMIZED ${CMAKE_CURRENT_BINARY_DIR}/clang.bolt)
@@ -880,6 +895,7 @@ if (CLANG_BOLT_INSTRUMENT AND NOT LLVM_BUILD_INSTRUMENTED)
   -data ${BOLT_FDATA}
   -reorder-blocks=ext-tsp -reorder-functions=hfsort+ -split-functions
   -split-all-cold -split-eh -dyno-stats -icf=1 -use-gnu-stack
+  ${BOLT_NO_LBR}
 COMMAND ${CMAKE_COMMAND} -E rename ${CLANG_OPTIMIZED} $
 COMMENT "Optimizing Clang with BOLT"
 VERBATIM
diff --git a/clang/cmake/caches/BOLT.cmake b/clang/cmake/caches/BOLT.cmake
index 0442f73e5426ac7..eba2346b2f4ca12 100644
--- a/clang/cmake/caches/BOLT.cmake
+++ b/clang/cmake/caches/BOLT.cmake
@@ -1,5 +1,5 @@
 set(CMAKE_BUILD_TYPE Release CACHE STRING "")
-set(CLANG_BOLT_INSTRUMENT ON CACHE BOOL "")
+set(CLANG_BOLT "INSTRUMENT" CACHE STRING "")
 set(CMAKE_EXE_LINKER_FLAGS "-Wl,--emit-relocs,-znow" CACHE STRING "")
 
 set(LLVM_ENABLE_PROJECTS "bolt;clang" CACHE STRING "")
diff --git a/clang/utils/perf-training/CMakeLists.txt 
b/clang/utils/perf-training/CMakeLists.txt
index c6d51863fb1b5c2..48fbee62a8636d1 100644
--- a/clang/utils/perf-training/CMakeLists.txt
+++ b/clang/utils/perf-training/CMakeLists.txt
@@ -62,7 +62,9 @@ if(APPLE AND DTRACE AND NOT LLVM_TOOL_LLVM_DRIVER_BUILD)
 DEPENDS generate-dtrace-logs)
 endif()
 
-if(CLANG_BOLT_INSTRUMENT AND NOT LLVM_BUILD_INSTRUMENTED)
+if(CLANG_BOLT AND NOT LLVM_BUILD_INSTRUMENTED)
+  set(CLANG_BOLT_INSTRUMENTED "clang-bolt.inst" CACHE STRING
+"Name of BOLT-instrumented Clang binary")
   configure_lit_site_cfg(
 ${CMAKE_CURRENT_SOURCE_DIR}/bolt.lit.site.cfg.in
 ${CMAKE_CURRENT_BINARY_DIR}/bolt-fdata/lit.site.cfg
@@ -71,16 +73,37 @@ if(CLANG_BOLT_INSTRUMENT AND NOT LLVM_BUILD_INSTRUMENTED)
   add_lit_testsuite(generate-bolt-fdata "Generating BOLT profile for Clang"
 ${CMAKE_CURRENT_BINARY_DIR}/bolt-fdata/
 EXCLUDE_FROM_CHECK_ALL
-DEPENDS clang-instrumented clear-bolt-fdata
+DEPENDS clang-bolt-training-deps clear-bolt-fdata clear-perf-data
 )
 
   add_custom_target(clear-bolt-fdata
 COMMAND "${Python3_EXECUTABLE}" ${CMAKE_CURRENT_SOURCE_DIR}/perf-helper.py 
clean ${CMAKE_CURRENT_BINARY_DIR} fdata
 

[clang] [Clang][CMake] Support perf, LBR, and Instrument CLANG_BOLT options (PR #69133)

2023-10-15 Thread Amir Ayupov via cfe-commits

https://github.com/aaupov created 
https://github.com/llvm/llvm-project/pull/69133

Split up and refactor CLANG_BOLT_INSTRUMENT into support for
perf no-LBR and perf with LBR profiling modes.

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


>From 3987088f1b6f6b895f7563ad70c97074b0d4ded0 Mon Sep 17 00:00:00 2001
From: Amir Aupov 
Date: Mon, 16 Oct 2023 01:08:28 +0200
Subject: [PATCH] [Clang][CMake] Support perf, LBR, and Instrument CLANG_BOLT
 options

Split up and refactor CLANG_BOLT_INSTRUMENT into support for
perf no-LBR and perf with LBR profiling modes.

Differential Revision: https://reviews.llvm.org/D143617
---
 clang/CMakeLists.txt  | 44 +
 clang/cmake/caches/BOLT.cmake |  2 +-
 clang/utils/perf-training/CMakeLists.txt  | 29 -
 clang/utils/perf-training/bolt.lit.cfg| 53 ---
 .../utils/perf-training/bolt.lit.site.cfg.in  |  2 +
 clang/utils/perf-training/perf-helper.py  | 65 +++
 6 files changed, 169 insertions(+), 26 deletions(-)

diff --git a/clang/CMakeLists.txt b/clang/CMakeLists.txt
index 9b52c58be41e7f7..8f64d95cc394ffe 100644
--- a/clang/CMakeLists.txt
+++ b/clang/CMakeLists.txt
@@ -850,23 +850,38 @@ if (CLANG_ENABLE_BOOTSTRAP)
   endforeach()
 endif()
 
-if (CLANG_BOLT_INSTRUMENT AND NOT LLVM_BUILD_INSTRUMENTED)
+set(CLANG_BOLT "INSTRUMENT" CACHE STRING "Apply BOLT optimization to Clang. \
+  May be specified as Instrument or Perf or LBR to use a particular profiling \
+  mechanism.")
+string(TOUPPER "${CLANG_BOLT}" uppercase_CLANG_BOLT)
+
+if (CLANG_BOLT AND NOT LLVM_BUILD_INSTRUMENTED)
   set(CLANG_PATH ${LLVM_RUNTIME_OUTPUT_INTDIR}/clang)
-  set(CLANG_INSTRUMENTED ${CLANG_PATH}-bolt.inst)
+  set(CLANG_INSTRUMENTED 
${LLVM_RUNTIME_OUTPUT_INTDIR}/${CLANG_BOLT_INSTRUMENTED})
   set(BOLT_FDATA ${CMAKE_CURRENT_BINARY_DIR}/utils/perf-training/prof.fdata)
 
-  # Instrument clang with BOLT
-  add_custom_target(clang-instrumented
-DEPENDS ${CLANG_INSTRUMENTED}
-  )
-  add_custom_command(OUTPUT ${CLANG_INSTRUMENTED}
-DEPENDS clang llvm-bolt
-COMMAND llvm-bolt ${CLANG_PATH} -o ${CLANG_INSTRUMENTED}
-  -instrument --instrumentation-file-append-pid
-  --instrumentation-file=${BOLT_FDATA}
-COMMENT "Instrumenting clang binary with BOLT"
-VERBATIM
-  )
+  # Pass extra flag in no-LBR mode
+  if (uppercase_CLANG_BOLT STREQUAL "PERF")
+set(BOLT_NO_LBR "-nl")
+  endif()
+
+  if (uppercase_CLANG_BOLT STREQUAL "INSTRUMENT")
+# Instrument clang with BOLT
+add_custom_target(clang-instrumented
+  DEPENDS ${CLANG_INSTRUMENTED}
+)
+add_custom_command(OUTPUT ${CLANG_INSTRUMENTED}
+  DEPENDS clang llvm-bolt
+  COMMAND llvm-bolt ${CLANG_PATH} -o ${CLANG_INSTRUMENTED}
+-instrument --instrumentation-file-append-pid
+--instrumentation-file=${BOLT_FDATA}
+  COMMENT "Instrumenting clang binary with BOLT"
+  VERBATIM
+)
+add_custom_target(clang-bolt-training-deps DEPENDS clang-instrumented)
+  else() # perf or LBR
+add_custom_target(clang-bolt-training-deps DEPENDS clang)
+  endif()
 
   # Optimize original (pre-bolt) Clang using the collected profile
   set(CLANG_OPTIMIZED ${CMAKE_CURRENT_BINARY_DIR}/clang.bolt)
@@ -880,6 +895,7 @@ if (CLANG_BOLT_INSTRUMENT AND NOT LLVM_BUILD_INSTRUMENTED)
   -data ${BOLT_FDATA}
   -reorder-blocks=ext-tsp -reorder-functions=hfsort+ -split-functions
   -split-all-cold -split-eh -dyno-stats -icf=1 -use-gnu-stack
+  ${BOLT_NO_LBR}
 COMMAND ${CMAKE_COMMAND} -E rename ${CLANG_OPTIMIZED} $
 COMMENT "Optimizing Clang with BOLT"
 VERBATIM
diff --git a/clang/cmake/caches/BOLT.cmake b/clang/cmake/caches/BOLT.cmake
index 0442f73e5426ac7..eba2346b2f4ca12 100644
--- a/clang/cmake/caches/BOLT.cmake
+++ b/clang/cmake/caches/BOLT.cmake
@@ -1,5 +1,5 @@
 set(CMAKE_BUILD_TYPE Release CACHE STRING "")
-set(CLANG_BOLT_INSTRUMENT ON CACHE BOOL "")
+set(CLANG_BOLT "INSTRUMENT" CACHE STRING "")
 set(CMAKE_EXE_LINKER_FLAGS "-Wl,--emit-relocs,-znow" CACHE STRING "")
 
 set(LLVM_ENABLE_PROJECTS "bolt;clang" CACHE STRING "")
diff --git a/clang/utils/perf-training/CMakeLists.txt 
b/clang/utils/perf-training/CMakeLists.txt
index c6d51863fb1b5c2..48fbee62a8636d1 100644
--- a/clang/utils/perf-training/CMakeLists.txt
+++ b/clang/utils/perf-training/CMakeLists.txt
@@ -62,7 +62,9 @@ if(APPLE AND DTRACE AND NOT LLVM_TOOL_LLVM_DRIVER_BUILD)
 DEPENDS generate-dtrace-logs)
 endif()
 
-if(CLANG_BOLT_INSTRUMENT AND NOT LLVM_BUILD_INSTRUMENTED)
+if(CLANG_BOLT AND NOT LLVM_BUILD_INSTRUMENTED)
+  set(CLANG_BOLT_INSTRUMENTED "clang-bolt.inst" CACHE STRING
+"Name of BOLT-instrumented Clang binary")
   configure_lit_site_cfg(
 ${CMAKE_CURRENT_SOURCE_DIR}/bolt.lit.site.cfg.in
 ${CMAKE_CURRENT_BINARY_DIR}/bolt-fdata/lit.site.cfg
@@ -71,16 +73,37 @@ if(CLANG_BOLT_INSTRUMENT AND NOT LLVM_BUILD_INSTRUMENTED)
   add_lit_testsuite(generate-bolt-fdata "Generating BOLT profile for Clang"
 

[clang] 7f881a2 - [clang-format] Treat AttributeMacro more like __attribute__

2023-10-15 Thread Owen Pan via cfe-commits

Author: Jared Grubb
Date: 2023-10-15T15:58:24-07:00
New Revision: 7f881a2abe2c3eceeae0272fc41ba0a237770450

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

LOG: [clang-format] Treat AttributeMacro more like __attribute__

There are two parts to this fix:
- Annotate the paren after an AttributeMacro as an AttributeLParen.
- Treat an AttributeMacro-without-paren the same as one with a paren.

I added a new test-case to differentiate a macro that is or is-not an
AttributeMacro; also handled whether ColumnLimit is set to infinite (0) or a
finite value, as part of this patch is in ContinuationIndenter.

Closes #68722.

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

Added: 


Modified: 
clang/lib/Format/ContinuationIndenter.cpp
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/FormatTest.cpp
clang/unittests/Format/FormatTestObjC.cpp
clang/unittests/Format/TokenAnnotatorTest.cpp

Removed: 




diff  --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index 91ce825224d7f70..3b28f84fd8417d3 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -1335,6 +1335,8 @@ unsigned ContinuationIndenter::getNewLineColumn(const 
LineState ) {
   if ((PreviousNonComment &&
(PreviousNonComment->ClosesTemplateDeclaration ||
 PreviousNonComment->ClosesRequiresClause ||
+(PreviousNonComment->is(TT_AttributeMacro) &&
+ Current.isNot(tok::l_paren)) ||
 PreviousNonComment->isOneOf(
 TT_AttributeRParen, TT_AttributeSquare, 
TT_FunctionAnnotationRParen,
 TT_JavaAnnotation, TT_LeadingJavaAnnotation))) ||

diff  --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 543c119620bf28f..3dd537272e9dad0 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -4393,8 +4393,10 @@ bool TokenAnnotator::spaceRequiredBefore(const 
AnnotatedLine ,
   return false;
 }
 // Space in __attribute__((attr)) ::type.
-if (Left.is(TT_AttributeRParen) && Right.is(tok::coloncolon))
+if (Left.isOneOf(TT_AttributeRParen, TT_AttributeMacro) &&
+Right.is(tok::coloncolon)) {
   return true;
+}
 
 if (Left.is(tok::kw_operator))
   return Right.is(tok::coloncolon);
@@ -4709,7 +4711,8 @@ bool TokenAnnotator::spaceRequiredBefore(const 
AnnotatedLine ,
   if (Line.Type == LT_ObjCMethodDecl) {
 if (Left.is(TT_ObjCMethodSpecifier))
   return true;
-if (Left.is(tok::r_paren) && canBeObjCSelectorComponent(Right)) {
+if (Left.is(tok::r_paren) && Left.isNot(TT_AttributeRParen) &&
+canBeObjCSelectorComponent(Right)) {
   // Don't space between ')' and  or ')' and 'new'. 'new' is not a
   // keyword in Objective-C, and '+ (instancetype)new;' is a standard class
   // method declaration.
@@ -5222,8 +5225,10 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine 
,
   }
 
   // Ensure wrapping after __attribute__((XX)) and @interface etc.
-  if (Left.is(TT_AttributeRParen) && Right.is(TT_ObjCDecl))
+  if (Left.isOneOf(TT_AttributeRParen, TT_AttributeMacro) &&
+  Right.is(TT_ObjCDecl)) {
 return true;
+  }
 
   if (Left.is(TT_LambdaLBrace)) {
 if (IsFunctionArgument(Left) &&

diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 2ef3c9b299bcad4..963fb8f4d441618 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -11674,6 +11674,9 @@ TEST_F(FormatTest, UnderstandsAttributes) {
   verifyFormat("vector v;", CustomAttrs);
   verifyFormat("vector v;", CustomAttrs);
   verifyFormat("vector v;", CustomAttrs);
+  verifyFormat("__attr1 ::qualified_type f();", CustomAttrs);
+  verifyFormat("__attr1() ::qualified_type f();", CustomAttrs);
+  verifyFormat("__attr1(nodebug) ::qualified_type f();", CustomAttrs);
 
   // Check that these are not parsed as function declarations:
   CustomAttrs.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_None;

diff  --git a/clang/unittests/Format/FormatTestObjC.cpp 
b/clang/unittests/Format/FormatTestObjC.cpp
index a9e5434dfabfbba..84a3d240055ff68 100644
--- a/clang/unittests/Format/FormatTestObjC.cpp
+++ b/clang/unittests/Format/FormatTestObjC.cpp
@@ -1527,7 +1527,10 @@ TEST_F(FormatTestObjC, IfNotUnlikely) {
"  [obj func:arg2];");
 }
 
-TEST_F(FormatTestObjC, Attributes) {
+TEST_F(FormatTestObjC, AttributesOnObjCDecl) {
+  Style.AttributeMacros.push_back("ATTRIBUTE_MACRO");
+
+  // Check '__attribute__' macro directly.
   verifyFormat("__attribute__((objc_subclassing_restricted))\n"
"@interface Foo\n"
"@end");
@@ -1537,6 +1540,215 

[clang] 6c7cf74 - Revert "[clang-format] Treat AttributeMacro more like __attribute__"

2023-10-15 Thread Owen Pan via cfe-commits

Author: Owen Pan
Date: 2023-10-15T15:52:17-07:00
New Revision: 6c7cf74a75572c3cc5d9979f02b67a7357e9c656

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

LOG: Revert "[clang-format] Treat AttributeMacro more like __attribute__"

This reverts commit 6f46bcc609f14121e6942763ba9871f98541ea0e.

Added: 


Modified: 
clang/lib/Format/ContinuationIndenter.cpp
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/FormatTestObjC.cpp
clang/unittests/Format/TokenAnnotatorTest.cpp

Removed: 




diff  --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index 928c30364bfcf61..91ce825224d7f70 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -1336,9 +1336,8 @@ unsigned ContinuationIndenter::getNewLineColumn(const 
LineState ) {
(PreviousNonComment->ClosesTemplateDeclaration ||
 PreviousNonComment->ClosesRequiresClause ||
 PreviousNonComment->isOneOf(
-TT_AttributeRParen, TT_AttributeMacro, TT_AttributeSquare,
-TT_FunctionAnnotationRParen, TT_JavaAnnotation,
-TT_LeadingJavaAnnotation))) ||
+TT_AttributeRParen, TT_AttributeSquare, 
TT_FunctionAnnotationRParen,
+TT_JavaAnnotation, TT_LeadingJavaAnnotation))) ||
   (!Style.IndentWrappedFunctionNames &&
NextNonComment->isOneOf(tok::kw_operator, TT_FunctionDeclarationName))) 
{
 return std::max(CurrentState.LastSpace, CurrentState.Indent);

diff  --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 0c642594053fa39..543c119620bf28f 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -4709,9 +4709,7 @@ bool TokenAnnotator::spaceRequiredBefore(const 
AnnotatedLine ,
   if (Line.Type == LT_ObjCMethodDecl) {
 if (Left.is(TT_ObjCMethodSpecifier))
   return true;
-// Apply this logic for parens that are not function attribute macros.
-if (Left.is(tok::r_paren) && Left.isNot(TT_AttributeRParen) &&
-canBeObjCSelectorComponent(Right)) {
+if (Left.is(tok::r_paren) && canBeObjCSelectorComponent(Right)) {
   // Don't space between ')' and  or ')' and 'new'. 'new' is not a
   // keyword in Objective-C, and '+ (instancetype)new;' is a standard class
   // method declaration.
@@ -5224,10 +5222,8 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine 
,
   }
 
   // Ensure wrapping after __attribute__((XX)) and @interface etc.
-  if (Left.isOneOf(TT_AttributeRParen, TT_AttributeMacro) &&
-  Right.is(TT_ObjCDecl)) {
+  if (Left.is(TT_AttributeRParen) && Right.is(TT_ObjCDecl))
 return true;
-  }
 
   if (Left.is(TT_LambdaLBrace)) {
 if (IsFunctionArgument(Left) &&

diff  --git a/clang/unittests/Format/FormatTestObjC.cpp 
b/clang/unittests/Format/FormatTestObjC.cpp
index 84a3d240055ff68..a9e5434dfabfbba 100644
--- a/clang/unittests/Format/FormatTestObjC.cpp
+++ b/clang/unittests/Format/FormatTestObjC.cpp
@@ -1527,10 +1527,7 @@ TEST_F(FormatTestObjC, IfNotUnlikely) {
"  [obj func:arg2];");
 }
 
-TEST_F(FormatTestObjC, AttributesOnObjCDecl) {
-  Style.AttributeMacros.push_back("ATTRIBUTE_MACRO");
-
-  // Check '__attribute__' macro directly.
+TEST_F(FormatTestObjC, Attributes) {
   verifyFormat("__attribute__((objc_subclassing_restricted))\n"
"@interface Foo\n"
"@end");
@@ -1540,215 +1537,6 @@ TEST_F(FormatTestObjC, AttributesOnObjCDecl) {
   verifyFormat("__attribute__((objc_subclassing_restricted))\n"
"@implementation Foo\n"
"@end");
-
-  // Check AttributeMacro gets treated the same, with or without parentheses.
-  verifyFormat("ATTRIBUTE_MACRO\n"
-   "@interface Foo\n"
-   "@end");
-  verifyFormat("ATTRIBUTE_MACRO(X)\n"
-   "@interface Foo\n"
-   "@end");
-
-  // Indenter also needs to understand multiple attribute macros.
-  // Try each of the three kinds paired with each of the other kind.
-
-  // Column limit, but no reflow.
-  verifyFormat("ATTRIBUTE_MACRO(X) ATTRIBUTE_MACRO\n"
-   "@interface Foo\n"
-   "@end");
-  verifyFormat("ATTRIBUTE_MACRO ATTRIBUTE_MACRO(X)\n"
-   "@interface Foo\n"
-   "@end");
-  verifyFormat("__attribute__((X)) ATTRIBUTE_MACRO\n"
-   "@interface Foo\n"
-   "@end");
-  verifyFormat("ATTRIBUTE_MACRO __attribute__((X))\n"
-   "@interface Foo\n"
-   "@end");
-  verifyFormat("__attribute__((X)) ATTRIBUTE_MACRO(X)\n"
-   "@interface Foo\n"
-   "@end");
-  verifyFormat("ATTRIBUTE_MACRO(X) __attribute__((X))\n"
-   "@interface Foo\n"
-

[PATCH] D145262: [clang-format] Treat AttributeMacros more like __attribute__

2023-10-15 Thread Owen Pan via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG6f46bcc609f1: [clang-format] Treat AttributeMacro more like 
__attribute__ (authored by jaredgrubb, committed by owenpan).

Changed prior to commit:
  https://reviews.llvm.org/D145262?vs=557674=557707#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D145262/new/

https://reviews.llvm.org/D145262

Files:
  clang/lib/Format/ContinuationIndenter.cpp
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/FormatTestObjC.cpp
  clang/unittests/Format/TokenAnnotatorTest.cpp

Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -1795,6 +1795,116 @@
   EXPECT_TOKEN(Tokens[13], tok::arrow, TT_Unknown);
 }
 
+TEST_F(TokenAnnotatorTest, UnderstandsAttributeMacros) {
+  // '__attribute__' has special handling.
+  auto Tokens = annotate("__attribute__(X) void Foo(void);");
+  ASSERT_EQ(Tokens.size(), 11u) << Tokens;
+  EXPECT_TOKEN(Tokens[0], tok::kw___attribute, TT_Unknown);
+  EXPECT_TOKEN(Tokens[1], tok::l_paren, TT_AttributeLParen);
+  EXPECT_TOKEN(Tokens[3], tok::r_paren, TT_AttributeRParen);
+
+  // Generic macro has no special handling in this location.
+  Tokens = annotate("A(X) void Foo(void);");
+  ASSERT_EQ(Tokens.size(), 11u) << Tokens;
+  EXPECT_TOKEN(Tokens[0], tok::identifier, TT_Unknown);
+  EXPECT_TOKEN(Tokens[1], tok::l_paren, TT_Unknown);
+
+  // Add a custom AttributeMacro. Test that it has the same behavior.
+  FormatStyle Style = getLLVMStyle();
+  Style.AttributeMacros.push_back("A");
+
+  // An "AttributeMacro" gets annotated like '__attribute__'.
+  Tokens = annotate("A(X) void Foo(void);", Style);
+  ASSERT_EQ(Tokens.size(), 11u) << Tokens;
+  EXPECT_TOKEN(Tokens[0], tok::identifier, TT_AttributeMacro);
+  EXPECT_TOKEN(Tokens[1], tok::l_paren, TT_AttributeLParen);
+  EXPECT_TOKEN(Tokens[3], tok::r_paren, TT_AttributeRParen);
+}
+
+TEST_F(TokenAnnotatorTest, UnderstandsAttributeMacrosOnObjCDecl) {
+  // '__attribute__' has special handling.
+  auto Tokens = annotate("__attribute__(X) @interface Foo");
+  ASSERT_EQ(Tokens.size(), 8u) << Tokens;
+  EXPECT_TOKEN(Tokens[0], tok::kw___attribute, TT_Unknown);
+  EXPECT_TOKEN(Tokens[1], tok::l_paren, TT_AttributeLParen);
+  EXPECT_TOKEN(Tokens[3], tok::r_paren, TT_AttributeRParen);
+
+  // Generic macro has no special handling in this location.
+  Tokens = annotate("A(X) @interface Foo");
+  ASSERT_EQ(Tokens.size(), 8u) << Tokens;
+  // Note: Don't check token-type as a random token in this position is hard to
+  // reason about.
+  EXPECT_TOKEN_KIND(Tokens[0], tok::identifier);
+  EXPECT_TOKEN_KIND(Tokens[1], tok::l_paren);
+
+  // Add a custom AttributeMacro. Test that it has the same behavior.
+  FormatStyle Style = getLLVMStyle();
+  Style.AttributeMacros.push_back("A");
+
+  // An "AttributeMacro" gets annotated like '__attribute__'.
+  Tokens = annotate("A(X) @interface Foo", Style);
+  ASSERT_EQ(Tokens.size(), 8u) << Tokens;
+  EXPECT_TOKEN(Tokens[0], tok::identifier, TT_AttributeMacro);
+  EXPECT_TOKEN(Tokens[1], tok::l_paren, TT_AttributeLParen);
+  EXPECT_TOKEN(Tokens[3], tok::r_paren, TT_AttributeRParen);
+}
+
+TEST_F(TokenAnnotatorTest, UnderstandsAttributeMacrosOnObjCMethodDecl) {
+  // '__attribute__' has special handling.
+  auto Tokens = annotate("- (id)init __attribute__(X);");
+  ASSERT_EQ(Tokens.size(), 11u) << Tokens;
+  EXPECT_TOKEN(Tokens[5], tok::kw___attribute, TT_Unknown);
+  EXPECT_TOKEN(Tokens[6], tok::l_paren, TT_AttributeLParen);
+  EXPECT_TOKEN(Tokens[8], tok::r_paren, TT_AttributeRParen);
+
+  // Generic macro has no special handling in this location.
+  Tokens = annotate("- (id)init A(X);");
+  ASSERT_EQ(Tokens.size(), 11u) << Tokens;
+  // Note: Don't check token-type as a random token in this position is hard to
+  // reason about.
+  EXPECT_TOKEN_KIND(Tokens[5], tok::identifier);
+  EXPECT_TOKEN_KIND(Tokens[6], tok::l_paren);
+
+  // Add a custom AttributeMacro. Test that it has the same behavior.
+  FormatStyle Style = getLLVMStyle();
+  Style.AttributeMacros.push_back("A");
+
+  // An "AttributeMacro" gets annotated like '__attribute__'.
+  Tokens = annotate("- (id)init A(X);", Style);
+  ASSERT_EQ(Tokens.size(), 11u) << Tokens;
+  EXPECT_TOKEN(Tokens[5], tok::identifier, TT_AttributeMacro);
+  EXPECT_TOKEN(Tokens[6], tok::l_paren, TT_AttributeLParen);
+  EXPECT_TOKEN(Tokens[8], tok::r_paren, TT_AttributeRParen);
+}
+
+TEST_F(TokenAnnotatorTest, UnderstandsAttributeMacrosOnObjCProperty) {
+  // '__attribute__' has special handling.
+  auto Tokens = annotate("@property(weak) id delegate __attribute__(X);");
+  ASSERT_EQ(Tokens.size(), 13u) << Tokens;
+  EXPECT_TOKEN(Tokens[7], tok::kw___attribute, TT_Unknown);
+  EXPECT_TOKEN(Tokens[8], tok::l_paren, TT_AttributeLParen);
+  EXPECT_TOKEN(Tokens[10], 

[clang] 6f46bcc - [clang-format] Treat AttributeMacro more like __attribute__

2023-10-15 Thread Owen Pan via cfe-commits

Author: Jared Grubb
Date: 2023-10-15T15:44:57-07:00
New Revision: 6f46bcc609f14121e6942763ba9871f98541ea0e

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

LOG: [clang-format] Treat AttributeMacro more like __attribute__

There are two parts to this fix:
- Annotate the paren after an AttributeMacro as an AttributeLParen.
- Treat an AttributeMacro-without-paren the same as one with a paren.

I added a new test-case to differentiate a macro that is or is-not an
AttributeMacro; also handled whether ColumnLimit is set to infinite (0) or a
finite value, as part of this patch is in ContinuationIndenter.

Closes #68722.

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

Added: 


Modified: 
clang/lib/Format/ContinuationIndenter.cpp
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/FormatTestObjC.cpp
clang/unittests/Format/TokenAnnotatorTest.cpp

Removed: 




diff  --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index 91ce825224d7f70..928c30364bfcf61 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -1336,8 +1336,9 @@ unsigned ContinuationIndenter::getNewLineColumn(const 
LineState ) {
(PreviousNonComment->ClosesTemplateDeclaration ||
 PreviousNonComment->ClosesRequiresClause ||
 PreviousNonComment->isOneOf(
-TT_AttributeRParen, TT_AttributeSquare, 
TT_FunctionAnnotationRParen,
-TT_JavaAnnotation, TT_LeadingJavaAnnotation))) ||
+TT_AttributeRParen, TT_AttributeMacro, TT_AttributeSquare,
+TT_FunctionAnnotationRParen, TT_JavaAnnotation,
+TT_LeadingJavaAnnotation))) ||
   (!Style.IndentWrappedFunctionNames &&
NextNonComment->isOneOf(tok::kw_operator, TT_FunctionDeclarationName))) 
{
 return std::max(CurrentState.LastSpace, CurrentState.Indent);

diff  --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 543c119620bf28f..0c642594053fa39 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -4709,7 +4709,9 @@ bool TokenAnnotator::spaceRequiredBefore(const 
AnnotatedLine ,
   if (Line.Type == LT_ObjCMethodDecl) {
 if (Left.is(TT_ObjCMethodSpecifier))
   return true;
-if (Left.is(tok::r_paren) && canBeObjCSelectorComponent(Right)) {
+// Apply this logic for parens that are not function attribute macros.
+if (Left.is(tok::r_paren) && Left.isNot(TT_AttributeRParen) &&
+canBeObjCSelectorComponent(Right)) {
   // Don't space between ')' and  or ')' and 'new'. 'new' is not a
   // keyword in Objective-C, and '+ (instancetype)new;' is a standard class
   // method declaration.
@@ -5222,8 +5224,10 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine 
,
   }
 
   // Ensure wrapping after __attribute__((XX)) and @interface etc.
-  if (Left.is(TT_AttributeRParen) && Right.is(TT_ObjCDecl))
+  if (Left.isOneOf(TT_AttributeRParen, TT_AttributeMacro) &&
+  Right.is(TT_ObjCDecl)) {
 return true;
+  }
 
   if (Left.is(TT_LambdaLBrace)) {
 if (IsFunctionArgument(Left) &&

diff  --git a/clang/unittests/Format/FormatTestObjC.cpp 
b/clang/unittests/Format/FormatTestObjC.cpp
index a9e5434dfabfbba..84a3d240055ff68 100644
--- a/clang/unittests/Format/FormatTestObjC.cpp
+++ b/clang/unittests/Format/FormatTestObjC.cpp
@@ -1527,7 +1527,10 @@ TEST_F(FormatTestObjC, IfNotUnlikely) {
"  [obj func:arg2];");
 }
 
-TEST_F(FormatTestObjC, Attributes) {
+TEST_F(FormatTestObjC, AttributesOnObjCDecl) {
+  Style.AttributeMacros.push_back("ATTRIBUTE_MACRO");
+
+  // Check '__attribute__' macro directly.
   verifyFormat("__attribute__((objc_subclassing_restricted))\n"
"@interface Foo\n"
"@end");
@@ -1537,6 +1540,215 @@ TEST_F(FormatTestObjC, Attributes) {
   verifyFormat("__attribute__((objc_subclassing_restricted))\n"
"@implementation Foo\n"
"@end");
+
+  // Check AttributeMacro gets treated the same, with or without parentheses.
+  verifyFormat("ATTRIBUTE_MACRO\n"
+   "@interface Foo\n"
+   "@end");
+  verifyFormat("ATTRIBUTE_MACRO(X)\n"
+   "@interface Foo\n"
+   "@end");
+
+  // Indenter also needs to understand multiple attribute macros.
+  // Try each of the three kinds paired with each of the other kind.
+
+  // Column limit, but no reflow.
+  verifyFormat("ATTRIBUTE_MACRO(X) ATTRIBUTE_MACRO\n"
+   "@interface Foo\n"
+   "@end");
+  verifyFormat("ATTRIBUTE_MACRO ATTRIBUTE_MACRO(X)\n"
+   "@interface Foo\n"
+   "@end");
+  verifyFormat("__attribute__((X)) ATTRIBUTE_MACRO\n"
+   

[clang] [clang] Fix --entry command line option (PR #69114)

2023-10-15 Thread Fangrui Song via cfe-commits


@@ -0,0 +1,5 @@
+// RUN: %clang -### --entry test %s 2>&1 | FileCheck %s

MaskRay wrote:

In the absence of `--target=`, the default target triple 
`LLVM_DEFAULT_TARGET_TRIPLE` is used. The selected `ToolChain` may not run 
AddLinkerInputs to render `-e`.

We should add `--target=` (common choice is a linux triple) and try reusing an 
existing test 
https://maskray.me/blog/2021-08-08-toolchain-testing#i-dont-know-an-existing-test-can-be-enhanced

Perhaps linker-opts.c or Xlinker-args.c

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


[clang] [clang] Fix --entry command line option (PR #69114)

2023-10-15 Thread Fangrui Song via cfe-commits

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

The new option (alias) can be unnamed.

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


[clang] [clang] Fix --entry command line option (PR #69114)

2023-10-15 Thread Sergei Barannikov via cfe-commits

https://github.com/s-barannikov approved this pull request.

Thanks, LGTM
(Please make sure to edit the description before merging so that `git log` does 
not contain irrelevant information.)

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


[clang] [analyzer][NFC] Remove outdated FIXME comment (PR #68211)

2023-10-15 Thread Balazs Benics via cfe-commits

https://github.com/steakhal commented:

LGTM Thanks.

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


[clang] [analyzer] Fix note for member reference (PR #68691)

2023-10-15 Thread Balazs Benics via cfe-commits
=?utf-8?q?G=C3=A1bor?= Spaits,=?utf-8?q?G=C3=A1bor?= Spaits,
=?utf-8?q?G=C3=A1bor?= Spaits
Message-ID:
In-Reply-To: 


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


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


[clang] [analyzer][NFC] Simplifications in ArrayBoundV2 (PR #67572)

2023-10-15 Thread Balazs Benics via cfe-commits


@@ -32,42 +32,72 @@ using namespace taint;
 namespace {
 class ArrayBoundCheckerV2 :
 public Checker {
-  mutable std::unique_ptr BT;
-  mutable std::unique_ptr TaintBT;
+  BugType BT{this, "Out-of-bound access"};
+  BugType TaintBT{this, "Out-of-bound access", categories::TaintedData};
 
-  enum OOB_Kind { OOB_Precedes, OOB_Excedes };
+  enum OOB_Kind { OOB_Precedes, OOB_Exceeds, OOB_Taint };
 
-  void reportOOB(CheckerContext , ProgramStateRef errorState,
- OOB_Kind kind) const;
-  void reportTaintOOB(CheckerContext , ProgramStateRef errorState,
-  SVal TaintedSVal) const;
+  void reportOOB(CheckerContext , ProgramStateRef ErrorState, OOB_Kind Kind,
+ SVal TaintedSVal = UnknownVal()) const;
 
   static bool isFromCtypeMacro(const Stmt *S, ASTContext );
 
 public:
   void checkLocation(SVal l, bool isLoad, const Stmt *S,
  CheckerContext ) const;
 };
+} // anonymous namespace
 
-// FIXME: Eventually replace RegionRawOffset with this class.
-class RegionRawOffsetV2 {
-private:
-  const SubRegion *baseRegion;
-  NonLoc byteOffset;
+/// For a given Location that can be represented as a symbolic expression
+/// Arr[Idx] (or perhaps Arr[Idx1][Idx2] etc.), return the parent memory block
+/// Arr and the distance of Location from the beginning of Arr (expressed in a
+/// NonLoc that specifies the number of CharUnits). Returns nullopt when these
+/// cannot be determined.
+std::optional>
+computeOffset(ProgramStateRef State, SValBuilder , SVal Location) {
+  QualType T = SVB.getArrayIndexType();
+  auto Calc = [, State, T](BinaryOperatorKind Op, NonLoc LHS, NonLoc RHS) {
+// We will use this utility to add and multiply values.
+return SVB.evalBinOpNN(State, Op, LHS, RHS, T).getAs();
+  };
 
-public:
-  RegionRawOffsetV2(const SubRegion *base, NonLoc offset)
-  : baseRegion(base), byteOffset(offset) { assert(base); }
+  const auto *Region = dyn_cast_or_null(Location.getAsRegion());
+  std::optional Offset = std::nullopt;
+
+  while (const auto *ERegion = dyn_cast_or_null(Region)) {
+const auto Index = ERegion->getIndex().getAs();
+if (!Index)
+  return std::nullopt;
+
+QualType ElemType = ERegion->getElementType();
+// If the element is an incomplete type, go no further.
+if (ElemType->isIncompleteType())

steakhal wrote:

How can this be incomplete at this point?
VLAs? I'd appreciate an example in the comment.

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


[clang] [analyzer][NFC] Simplifications in ArrayBoundV2 (PR #67572)

2023-10-15 Thread Balazs Benics via cfe-commits


@@ -32,42 +32,72 @@ using namespace taint;
 namespace {
 class ArrayBoundCheckerV2 :
 public Checker {
-  mutable std::unique_ptr BT;
-  mutable std::unique_ptr TaintBT;
+  BugType BT{this, "Out-of-bound access"};
+  BugType TaintBT{this, "Out-of-bound access", categories::TaintedData};
 
-  enum OOB_Kind { OOB_Precedes, OOB_Excedes };
+  enum OOB_Kind { OOB_Precedes, OOB_Exceeds, OOB_Taint };
 
-  void reportOOB(CheckerContext , ProgramStateRef errorState,
- OOB_Kind kind) const;
-  void reportTaintOOB(CheckerContext , ProgramStateRef errorState,
-  SVal TaintedSVal) const;
+  void reportOOB(CheckerContext , ProgramStateRef ErrorState, OOB_Kind Kind,
+ SVal TaintedSVal = UnknownVal()) const;
 
   static bool isFromCtypeMacro(const Stmt *S, ASTContext );
 
 public:
   void checkLocation(SVal l, bool isLoad, const Stmt *S,
  CheckerContext ) const;
 };
+} // anonymous namespace
 
-// FIXME: Eventually replace RegionRawOffset with this class.
-class RegionRawOffsetV2 {
-private:
-  const SubRegion *baseRegion;
-  NonLoc byteOffset;
+/// For a given Location that can be represented as a symbolic expression
+/// Arr[Idx] (or perhaps Arr[Idx1][Idx2] etc.), return the parent memory block
+/// Arr and the distance of Location from the beginning of Arr (expressed in a
+/// NonLoc that specifies the number of CharUnits). Returns nullopt when these
+/// cannot be determined.
+std::optional>
+computeOffset(ProgramStateRef State, SValBuilder , SVal Location) {
+  QualType T = SVB.getArrayIndexType();
+  auto Calc = [, State, T](BinaryOperatorKind Op, NonLoc LHS, NonLoc RHS) {

steakhal wrote:

How about calling this EvalBinOp?

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


[clang] [analyzer][NFC] Simplifications in ArrayBoundV2 (PR #67572)

2023-10-15 Thread Balazs Benics via cfe-commits


@@ -32,42 +32,72 @@ using namespace taint;
 namespace {
 class ArrayBoundCheckerV2 :
 public Checker {
-  mutable std::unique_ptr BT;
-  mutable std::unique_ptr TaintBT;
+  BugType BT{this, "Out-of-bound access"};
+  BugType TaintBT{this, "Out-of-bound access", categories::TaintedData};
 
-  enum OOB_Kind { OOB_Precedes, OOB_Excedes };
+  enum OOB_Kind { OOB_Precedes, OOB_Exceeds, OOB_Taint };
 
-  void reportOOB(CheckerContext , ProgramStateRef errorState,
- OOB_Kind kind) const;
-  void reportTaintOOB(CheckerContext , ProgramStateRef errorState,
-  SVal TaintedSVal) const;
+  void reportOOB(CheckerContext , ProgramStateRef ErrorState, OOB_Kind Kind,
+ SVal TaintedSVal = UnknownVal()) const;
 
   static bool isFromCtypeMacro(const Stmt *S, ASTContext );
 
 public:
   void checkLocation(SVal l, bool isLoad, const Stmt *S,
  CheckerContext ) const;
 };
+} // anonymous namespace
 
-// FIXME: Eventually replace RegionRawOffset with this class.
-class RegionRawOffsetV2 {
-private:
-  const SubRegion *baseRegion;
-  NonLoc byteOffset;
+/// For a given Location that can be represented as a symbolic expression
+/// Arr[Idx] (or perhaps Arr[Idx1][Idx2] etc.), return the parent memory block
+/// Arr and the distance of Location from the beginning of Arr (expressed in a
+/// NonLoc that specifies the number of CharUnits). Returns nullopt when these
+/// cannot be determined.
+std::optional>
+computeOffset(ProgramStateRef State, SValBuilder , SVal Location) {
+  QualType T = SVB.getArrayIndexType();
+  auto Calc = [, State, T](BinaryOperatorKind Op, NonLoc LHS, NonLoc RHS) {
+// We will use this utility to add and multiply values.
+return SVB.evalBinOpNN(State, Op, LHS, RHS, T).getAs();
+  };
 
-public:
-  RegionRawOffsetV2(const SubRegion *base, NonLoc offset)
-  : baseRegion(base), byteOffset(offset) { assert(base); }
+  const auto *Region = dyn_cast_or_null(Location.getAsRegion());
+  std::optional Offset = std::nullopt;

steakhal wrote:

How about setting this to zero?

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


[clang] [analyzer][NFC] Simplifications in ArrayBoundV2 (PR #67572)

2023-10-15 Thread Balazs Benics via cfe-commits


@@ -32,42 +32,72 @@ using namespace taint;
 namespace {
 class ArrayBoundCheckerV2 :
 public Checker {
-  mutable std::unique_ptr BT;
-  mutable std::unique_ptr TaintBT;
+  BugType BT{this, "Out-of-bound access"};
+  BugType TaintBT{this, "Out-of-bound access", categories::TaintedData};
 
-  enum OOB_Kind { OOB_Precedes, OOB_Excedes };
+  enum OOB_Kind { OOB_Precedes, OOB_Exceeds, OOB_Taint };
 
-  void reportOOB(CheckerContext , ProgramStateRef errorState,
- OOB_Kind kind) const;
-  void reportTaintOOB(CheckerContext , ProgramStateRef errorState,
-  SVal TaintedSVal) const;
+  void reportOOB(CheckerContext , ProgramStateRef ErrorState, OOB_Kind Kind,
+ SVal TaintedSVal = UnknownVal()) const;
 
   static bool isFromCtypeMacro(const Stmt *S, ASTContext );
 
 public:
   void checkLocation(SVal l, bool isLoad, const Stmt *S,
  CheckerContext ) const;
 };
+} // anonymous namespace
 
-// FIXME: Eventually replace RegionRawOffset with this class.
-class RegionRawOffsetV2 {
-private:
-  const SubRegion *baseRegion;
-  NonLoc byteOffset;
+/// For a given Location that can be represented as a symbolic expression
+/// Arr[Idx] (or perhaps Arr[Idx1][Idx2] etc.), return the parent memory block
+/// Arr and the distance of Location from the beginning of Arr (expressed in a
+/// NonLoc that specifies the number of CharUnits). Returns nullopt when these
+/// cannot be determined.
+std::optional>
+computeOffset(ProgramStateRef State, SValBuilder , SVal Location) {
+  QualType T = SVB.getArrayIndexType();
+  auto Calc = [, State, T](BinaryOperatorKind Op, NonLoc LHS, NonLoc RHS) {
+// We will use this utility to add and multiply values.
+return SVB.evalBinOpNN(State, Op, LHS, RHS, T).getAs();
+  };
 
-public:
-  RegionRawOffsetV2(const SubRegion *base, NonLoc offset)
-  : baseRegion(base), byteOffset(offset) { assert(base); }
+  const auto *Region = dyn_cast_or_null(Location.getAsRegion());
+  std::optional Offset = std::nullopt;
+
+  while (const auto *ERegion = dyn_cast_or_null(Region)) {
+const auto Index = ERegion->getIndex().getAs();
+if (!Index)
+  return std::nullopt;
+
+QualType ElemType = ERegion->getElementType();
+// If the element is an incomplete type, go no further.
+if (ElemType->isIncompleteType())
+  return std::nullopt;
+
+// Calculate Delta = Index * sizeof(ElemType).
+NonLoc Size = SVB.makeArrayIndex(
+SVB.getContext().getTypeSizeInChars(ElemType).getQuantity());
+auto Delta = Calc(BO_Mul, *Index, Size);
+if (!Delta)
+  return std::nullopt;
+
+// Perform Offset += Delta, handling the initial nullopt as 0.
+if (!Offset) {
+  Offset = Delta;
+} else {
+  Offset = Calc(BO_Add, *Offset, *Delta);
+  if (!Offset)
+return std::nullopt;
+}

steakhal wrote:

I feel we could simplify the control flow here.
```suggestion
  assert(Offset);
  Offset = Calc(Add, *Offset, *Delta);
  if (!Offset)
return std::nullopt;
```

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


[clang] [analyzer][NFC] Simplifications in ArrayBoundV2 (PR #67572)

2023-10-15 Thread Balazs Benics via cfe-commits

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


[clang] [analyzer][NFC] Simplifications in ArrayBoundV2 (PR #67572)

2023-10-15 Thread Balazs Benics via cfe-commits

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


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


[clang] [Sema] -Wzero-as-null-pointer-constant: don't warn for __null (PR #69126)

2023-10-15 Thread Arseny Kapoulkine via cfe-commits

zeux wrote:

Note: a limitation of this change is that we will still warn on use of `NULL` 
when it is defined as 0, which could be a problem for clang-cl. This could be 
lifted by removing the "NULL" macro name check, but unfortunately that is 
insufficient to detect the use of NULL inside macro expansion (such as 
`MCRO(NULL)` in the test file). Because of this, this change is conservative in 
that it aligns the logic with GCC but doesn't attempt to handle NULL fully. I 
can revise this if this seems like an issue worth addressing here.

This change revises the logic of 
https://github.com/llvm/llvm-project/commit/809df34efc653c6a471f951305a88bd5e675b522
 so
cc @LebedevRI as the author of that adjustment, @nico as the original author, 
and @AaronBallman since this was suggested on Discord.

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


[clang] [Sema] -Wzero-as-null-pointer-constant: don't warn for __null (PR #69126)

2023-10-15 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Arseny Kapoulkine (zeux)


Changes

The implementation of -Wzero-as-null-pointer-constant was done before the 
following fix has been committed to GCC:

https://gcc.gnu.org/git/?p=gcc.git;a=commitdiff;h=752e7593b0f19af233a0b7e72daab8413662b605;hp=298434c916c14e8adca2cab8a746aee29038c5b3

As a result, clang and gcc diverge on the use of `__null` and, consequently, on 
the use of `NULL` on systems like Linux/macOS where `NULL` is defined as 
`__null`.

This is a problem for compatibility between gcc and clang, particularly for 
code bases that support C++98 or for single-source libraries that are 
implemented in C, but compiled as C++ via inclusion into a C++ translation 
unit. Code like this can not be changed to use `nullptr`, as it needs to 
maintain compatibility with C before C23 or C++ before C++11, but warns on the 
use of `NULL` in clang.

The warning `Wzero-as-null-pointer-constant` is still useful with this change, 
as it allows to change `0` to `NULL`, which fixes
gcc warnings and helps the reader distinguish between pointers and 
non-pointers. Users who require a full C++11 modernization pass can still use 
clang-tidy for that purpose.

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


2 Files Affected:

- (modified) clang/lib/Sema/Sema.cpp (+7-1) 
- (modified) clang/test/SemaCXX/warn-zero-nullptr.cpp (+4-4) 


``diff
diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index 67533ccbdf347c7..acb765559e6a8d4 100644
--- a/clang/lib/Sema/Sema.cpp
+++ b/clang/lib/Sema/Sema.cpp
@@ -590,7 +590,11 @@ void Sema::diagnoseZeroToNullptrConversion(CastKind Kind, 
const Expr *E) {
 
   if (Kind != CK_NullToPointer && Kind != CK_NullToMemberPointer)
 return;
-  if (E->IgnoreParenImpCasts()->getType()->isNullPtrType())
+
+  const Expr *EStripped = E->IgnoreParenImpCasts();
+  if (EStripped->getType()->isNullPtrType())
+return;
+  if (isa(EStripped))
 return;
 
   if (Diags.isIgnored(diag::warn_zero_as_null_pointer_constant,
@@ -612,6 +616,8 @@ void Sema::diagnoseZeroToNullptrConversion(CastKind Kind, 
const Expr *E) {
 
   // If it is a macro from system header, and if the macro name is not "NULL",
   // do not warn.
+  // Note that uses of "NULL" will be ignored above on systems that define it
+  // as __null.
   SourceLocation MaybeMacroLoc = E->getBeginLoc();
   if (Diags.getSuppressSystemWarnings() &&
   SourceMgr.isInSystemMacro(MaybeMacroLoc) &&
diff --git a/clang/test/SemaCXX/warn-zero-nullptr.cpp 
b/clang/test/SemaCXX/warn-zero-nullptr.cpp
index 45f05fa5703b1c3..684572f8ef67d05 100644
--- a/clang/test/SemaCXX/warn-zero-nullptr.cpp
+++ b/clang/test/SemaCXX/warn-zero-nullptr.cpp
@@ -16,10 +16,10 @@ int (S::*mp1) = 0; // expected-warning{{zero as null 
pointer constant}}
 void (*fp1)() = 0; // expected-warning{{zero as null pointer constant}}
 void* p1 = 0; // expected-warning{{zero as null pointer constant}}
 
-// NULL is an integer constant expression, so warn on it too:
-void* p2 = __null; // expected-warning{{zero as null pointer constant}}
-void (*fp2)() = __null; // expected-warning{{zero as null pointer constant}}
-int (S::*mp2) = __null; // expected-warning{{zero as null pointer constant}}
+// __null is not treated as an integer constant expression for GCC 
compatibility
+void* p2 = __null;
+void (*fp2)() = __null;
+int (S::*mp2) = __null;
 
 void f0(void* v = MACRO); // expected-warning{{zero as null pointer constant}}
 void f1(void* v = NULL); // expected-warning{{zero as null pointer constant}}

``




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


[clang] [libclang/python] Add missing concept declaration CursorKind (PR #69125)

2023-10-15 Thread Nick Renieris via cfe-commits

VelocityRa wrote:

Pinging @mdfazlay and @AaronBallman for review (sorry if I chose the wrong 
people!)

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


[clang] [Sema] -Wzero-as-null-pointer-constant: don't warn for __null (PR #69126)

2023-10-15 Thread Arseny Kapoulkine via cfe-commits

https://github.com/zeux created https://github.com/llvm/llvm-project/pull/69126

The implementation of -Wzero-as-null-pointer-constant was done before the 
following fix has been committed to GCC:

https://gcc.gnu.org/git/?p=gcc.git;a=commitdiff;h=752e7593b0f19af233a0b7e72daab8413662b605;hp=298434c916c14e8adca2cab8a746aee29038c5b3

As a result, clang and gcc diverge on the use of `__null` and, consequently, on 
the use of `NULL` on systems like Linux/macOS where `NULL` is defined as 
`__null`.

This is a problem for compatibility between gcc and clang, particularly for 
code bases that support C++98 or for single-source libraries that are 
implemented in C, but compiled as C++ via inclusion into a C++ translation 
unit. Code like this can not be changed to use `nullptr`, as it needs to 
maintain compatibility with C before C23 or C++ before C++11, but warns on the 
use of `NULL` in clang.

The warning `Wzero-as-null-pointer-constant` is still useful with this change, 
as it allows to change `0` to `NULL`, which fixes
gcc warnings and helps the reader distinguish between pointers and 
non-pointers. Users who require a full C++11 modernization pass can still use 
clang-tidy for that purpose.

>From 357a21c38c1036a012affc85026fcba376ab7128 Mon Sep 17 00:00:00 2001
From: Arseny Kapoulkine 
Date: Sun, 15 Oct 2023 13:20:31 -0700
Subject: [PATCH] [Sema] -Wzero-as-null-pointer-constant: don't warn for __null

The implementation of -Wzero-as-null-pointer-constant was done before
the following fix has been committed to GCC:

https://gcc.gnu.org/git/?p=gcc.git;a=commitdiff;h=752e7593b0f19af233a0b7e72daab8413662b605;hp=298434c916c14e8adca2cab8a746aee29038c5b3

As a result, clang and gcc diverge on the use of __null and,
consequently, on the use of NULL on systems like Linux/macOS where NULL
is defined as __null.

This is a problem for compatibility between gcc and clang, particularly
for code bases that support C++98 or for single-source libraries that
are implemented in C, but compiled as C++ via inclusion into a C++
translation unit. Code like this can not be changed to use nullptr, as
it needs to maintain compatibility with C before C23 or C++ before
C++11, but warns on the use of NULL.

Note: a limitation of this change is that we will still warn on use of
NULL when it is defined as 0, which could be a problem for clang-cl.
---
 clang/lib/Sema/Sema.cpp  | 8 +++-
 clang/test/SemaCXX/warn-zero-nullptr.cpp | 8 
 2 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index 67533ccbdf347c7..acb765559e6a8d4 100644
--- a/clang/lib/Sema/Sema.cpp
+++ b/clang/lib/Sema/Sema.cpp
@@ -590,7 +590,11 @@ void Sema::diagnoseZeroToNullptrConversion(CastKind Kind, 
const Expr *E) {
 
   if (Kind != CK_NullToPointer && Kind != CK_NullToMemberPointer)
 return;
-  if (E->IgnoreParenImpCasts()->getType()->isNullPtrType())
+
+  const Expr *EStripped = E->IgnoreParenImpCasts();
+  if (EStripped->getType()->isNullPtrType())
+return;
+  if (isa(EStripped))
 return;
 
   if (Diags.isIgnored(diag::warn_zero_as_null_pointer_constant,
@@ -612,6 +616,8 @@ void Sema::diagnoseZeroToNullptrConversion(CastKind Kind, 
const Expr *E) {
 
   // If it is a macro from system header, and if the macro name is not "NULL",
   // do not warn.
+  // Note that uses of "NULL" will be ignored above on systems that define it
+  // as __null.
   SourceLocation MaybeMacroLoc = E->getBeginLoc();
   if (Diags.getSuppressSystemWarnings() &&
   SourceMgr.isInSystemMacro(MaybeMacroLoc) &&
diff --git a/clang/test/SemaCXX/warn-zero-nullptr.cpp 
b/clang/test/SemaCXX/warn-zero-nullptr.cpp
index 45f05fa5703b1c3..684572f8ef67d05 100644
--- a/clang/test/SemaCXX/warn-zero-nullptr.cpp
+++ b/clang/test/SemaCXX/warn-zero-nullptr.cpp
@@ -16,10 +16,10 @@ int (S::*mp1) = 0; // expected-warning{{zero as null 
pointer constant}}
 void (*fp1)() = 0; // expected-warning{{zero as null pointer constant}}
 void* p1 = 0; // expected-warning{{zero as null pointer constant}}
 
-// NULL is an integer constant expression, so warn on it too:
-void* p2 = __null; // expected-warning{{zero as null pointer constant}}
-void (*fp2)() = __null; // expected-warning{{zero as null pointer constant}}
-int (S::*mp2) = __null; // expected-warning{{zero as null pointer constant}}
+// __null is not treated as an integer constant expression for GCC 
compatibility
+void* p2 = __null;
+void (*fp2)() = __null;
+int (S::*mp2) = __null;
 
 void f0(void* v = MACRO); // expected-warning{{zero as null pointer constant}}
 void f1(void* v = NULL); // expected-warning{{zero as null pointer constant}}

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


[clang] [libclang/python] Add missing concept declaration CursorKind (PR #69125)

2023-10-15 Thread Nick Renieris via cfe-commits

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


[clang] [libclang/python] Add missing concept declaration CursorKind (PR #69125)

2023-10-15 Thread Nick Renieris via cfe-commits

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


[clang] [libclang/python] Add missing concept declaration CursorKind (PR #69125)

2023-10-15 Thread Nick Renieris via cfe-commits

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


[clang] [libclang/python] Add missing concept declaration CursorKind (PR #69125)

2023-10-15 Thread Nick Renieris via cfe-commits

https://github.com/VelocityRa created 
https://github.com/llvm/llvm-project/pull/69125

Maps to 
[`CXCursor_ConceptDecl`](https://github.com/llvm/llvm-project/blob/ee8524087c78a673fcf5486ded69ee597a85e0f1/clang/include/clang-c/Index.h#L2716),
 added in ee8524087c78a673fcf5486ded69ee597a85e0f1.

>From 2e67a5edb0371d163e46ec3ce8dd2486a374e2b3 Mon Sep 17 00:00:00 2001
From: Nick Renieris 
Date: Sun, 15 Oct 2023 23:16:30 +0300
Subject: [PATCH] [libclang/python] Add missing concept declaration CursorKind

Maps to `CXCursor_ConceptDecl`, added in ee85240.
---
 clang/bindings/python/clang/cindex.py | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/clang/bindings/python/clang/cindex.py 
b/clang/bindings/python/clang/cindex.py
index ff386d2094a0b88..6a16f3a9ef6e957 100644
--- a/clang/bindings/python/clang/cindex.py
+++ b/clang/bindings/python/clang/cindex.py
@@ -1403,6 +1403,8 @@ def __repr__(self):
 CursorKind.STATIC_ASSERT = CursorKind(602)
 # A friend declaration
 CursorKind.FRIEND_DECL = CursorKind(603)
+# A concept declaration
+CursorKind.CONCEPT_DECL = CursorKind(604)
 
 # A code completion overload candidate.
 CursorKind.OVERLOAD_CANDIDATE = CursorKind(700)

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


[clang] [clang] Add clang::debug_info_type attribute for bitfields (PR #69104)

2023-10-15 Thread Paul T Robinson via cfe-commits

pogo59 wrote:

> Does this issue not apply to other platforms?

There is a deliberate layout/ABI choice that MSVC made ages ago and will never 
change. It will only pack bitfields into the same word if the neighboring 
bitfield declarations have the same base type. This is relatively well known.

That said, being able to attach an enum (or whatever) to the bitfield does seem 
handy, for any target.

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


[PATCH] D137149: Use PassGate from LLVMContext if any otherwise global one

2023-10-15 Thread Valentin Churavy via Phabricator via cfe-commits
vchuravy added a comment.

> We'd need a lot more testing before we can claim to support reusing pipelines.

Sure, but moving pass pipeline state into the context makes it much harder to 
do this kind of testing.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137149/new/

https://reviews.llvm.org/D137149

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


[clang] [Driver] Don't pass -Z to ld for ELF platforms (PR #69120)

2023-10-15 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-risc-v

Author: Fangrui Song (MaskRay)


Changes

-Z is an Apple ld64 option. ELF linkers don't recognize -Z.
Some ToolChains have -Z due to copy-and-paste mistakes.


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


9 Files Affected:

- (modified) clang/lib/Driver/ToolChains/BareMetal.cpp (+2-3) 
- (modified) clang/lib/Driver/ToolChains/CSKYToolChain.cpp (+2-3) 
- (modified) clang/lib/Driver/ToolChains/FreeBSD.cpp (+2-3) 
- (modified) clang/lib/Driver/ToolChains/Haiku.cpp (+2-3) 
- (modified) clang/lib/Driver/ToolChains/MinGW.cpp (-1) 
- (modified) clang/lib/Driver/ToolChains/NetBSD.cpp (+2-3) 
- (modified) clang/lib/Driver/ToolChains/OpenBSD.cpp (+2-3) 
- (modified) clang/lib/Driver/ToolChains/RISCVToolchain.cpp (+2-3) 
- (modified) clang/test/Driver/openbsd.c (-4) 


``diff
diff --git a/clang/lib/Driver/ToolChains/BareMetal.cpp 
b/clang/lib/Driver/ToolChains/BareMetal.cpp
index f363d277a7b71d3..842061c1e1488b0 100644
--- a/clang/lib/Driver/ToolChains/BareMetal.cpp
+++ b/clang/lib/Driver/ToolChains/BareMetal.cpp
@@ -452,9 +452,8 @@ void baremetal::Linker::ConstructJob(Compilation , const 
JobAction ,
 CmdArgs.push_back(Arch == llvm::Triple::aarch64_be ? "-EB" : "-EL");
   }
 
-  Args.addAllArgs(CmdArgs,
-  {options::OPT_L, options::OPT_T_Group, options::OPT_s,
-   options::OPT_t, options::OPT_Z_Flag, options::OPT_r});
+  Args.addAllArgs(CmdArgs, {options::OPT_L, options::OPT_T_Group,
+options::OPT_s, options::OPT_t, options::OPT_r});
 
   TC.AddFilePathLibArgs(Args, CmdArgs);
 
diff --git a/clang/lib/Driver/ToolChains/CSKYToolChain.cpp 
b/clang/lib/Driver/ToolChains/CSKYToolChain.cpp
index 2bd91e63fdd5a42..0c280347b2af6a1 100644
--- a/clang/lib/Driver/ToolChains/CSKYToolChain.cpp
+++ b/clang/lib/Driver/ToolChains/CSKYToolChain.cpp
@@ -169,9 +169,8 @@ void CSKY::Linker::ConstructJob(Compilation , const 
JobAction ,
 
   Args.AddAllArgs(CmdArgs, options::OPT_L);
   ToolChain.AddFilePathLibArgs(Args, CmdArgs);
-  Args.addAllArgs(CmdArgs,
-  {options::OPT_T_Group, options::OPT_s, options::OPT_t,
-   options::OPT_Z_Flag, options::OPT_r});
+  Args.addAllArgs(CmdArgs, {options::OPT_T_Group, options::OPT_s,
+options::OPT_t, options::OPT_r});
 
   AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs, JA);
 
diff --git a/clang/lib/Driver/ToolChains/FreeBSD.cpp 
b/clang/lib/Driver/ToolChains/FreeBSD.cpp
index c936fb88d18ccd9..7a61159ba4a7308 100644
--- a/clang/lib/Driver/ToolChains/FreeBSD.cpp
+++ b/clang/lib/Driver/ToolChains/FreeBSD.cpp
@@ -262,9 +262,8 @@ void freebsd::Linker::ConstructJob(Compilation , const 
JobAction ,
 
   Args.AddAllArgs(CmdArgs, options::OPT_L);
   ToolChain.AddFilePathLibArgs(Args, CmdArgs);
-  Args.addAllArgs(CmdArgs,
-  {options::OPT_T_Group, options::OPT_s, options::OPT_t,
-   options::OPT_Z_Flag, options::OPT_r});
+  Args.addAllArgs(CmdArgs, {options::OPT_T_Group, options::OPT_s,
+options::OPT_t, options::OPT_r});
 
   if (D.isUsingLTO()) {
 assert(!Inputs.empty() && "Must have at least one input.");
diff --git a/clang/lib/Driver/ToolChains/Haiku.cpp 
b/clang/lib/Driver/ToolChains/Haiku.cpp
index c2653a4a2022edf..9f56a0ea5d612d0 100644
--- a/clang/lib/Driver/ToolChains/Haiku.cpp
+++ b/clang/lib/Driver/ToolChains/Haiku.cpp
@@ -80,9 +80,8 @@ void haiku::Linker::ConstructJob(Compilation , const 
JobAction ,
 
CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("init_term_dyn.o")));
   }
 
-  Args.addAllArgs(CmdArgs,
-  {options::OPT_L, options::OPT_T_Group, options::OPT_s,
-   options::OPT_t, options::OPT_Z_Flag, options::OPT_r});
+  Args.addAllArgs(CmdArgs, {options::OPT_L, options::OPT_T_Group,
+options::OPT_s, options::OPT_t, options::OPT_r});
   ToolChain.AddFilePathLibArgs(Args, CmdArgs);
 
   addLinkerCompressDebugSectionsOption(ToolChain, Args, CmdArgs);
diff --git a/clang/lib/Driver/ToolChains/MinGW.cpp 
b/clang/lib/Driver/ToolChains/MinGW.cpp
index d3d829a8ddbdb95..39d767795445dbe 100644
--- a/clang/lib/Driver/ToolChains/MinGW.cpp
+++ b/clang/lib/Driver/ToolChains/MinGW.cpp
@@ -201,7 +201,6 @@ void tools::MinGW::Linker::ConstructJob(Compilation , 
const JobAction ,
   Args.AddLastArg(CmdArgs, options::OPT_s);
   Args.AddLastArg(CmdArgs, options::OPT_t);
   Args.AddAllArgs(CmdArgs, options::OPT_u_Group);
-  Args.AddLastArg(CmdArgs, options::OPT_Z_Flag);
 
   // Add asan_dynamic as the first import lib before other libs. This allows
   // asan to be initialized as early as possible to increase its 
instrumentation
diff --git a/clang/lib/Driver/ToolChains/NetBSD.cpp 
b/clang/lib/Driver/ToolChains/NetBSD.cpp
index 316e4d56c242acc..1c901f70f72ca2e 100644
--- a/clang/lib/Driver/ToolChains/NetBSD.cpp
+++ b/clang/lib/Driver/ToolChains/NetBSD.cpp
@@ -266,9 

[clang] [Driver] Don't pass -Z to ld for ELF platforms (PR #69120)

2023-10-15 Thread Fangrui Song via cfe-commits

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

-Z is an Apple ld64 option. ELF linkers don't recognize -Z.
Some ToolChains have -Z due to copy-and-paste mistakes.


>From f89971279ec678dedd98efcf37398beb98d3f09e Mon Sep 17 00:00:00 2001
From: Fangrui Song 
Date: Sun, 15 Oct 2023 12:04:27 -0700
Subject: [PATCH] [Driver] Don't pass -Z to ld for ELF platforms

-Z is an Apple ld64 option. ELF linkers don't recognize -Z.
Some ToolChains have -Z due to copy-and-paste mistakes.
---
 clang/lib/Driver/ToolChains/BareMetal.cpp  | 5 ++---
 clang/lib/Driver/ToolChains/CSKYToolChain.cpp  | 5 ++---
 clang/lib/Driver/ToolChains/FreeBSD.cpp| 5 ++---
 clang/lib/Driver/ToolChains/Haiku.cpp  | 5 ++---
 clang/lib/Driver/ToolChains/MinGW.cpp  | 1 -
 clang/lib/Driver/ToolChains/NetBSD.cpp | 5 ++---
 clang/lib/Driver/ToolChains/OpenBSD.cpp| 5 ++---
 clang/lib/Driver/ToolChains/RISCVToolchain.cpp | 5 ++---
 clang/test/Driver/openbsd.c| 4 
 9 files changed, 14 insertions(+), 26 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/BareMetal.cpp 
b/clang/lib/Driver/ToolChains/BareMetal.cpp
index f363d277a7b71d3..842061c1e1488b0 100644
--- a/clang/lib/Driver/ToolChains/BareMetal.cpp
+++ b/clang/lib/Driver/ToolChains/BareMetal.cpp
@@ -452,9 +452,8 @@ void baremetal::Linker::ConstructJob(Compilation , const 
JobAction ,
 CmdArgs.push_back(Arch == llvm::Triple::aarch64_be ? "-EB" : "-EL");
   }
 
-  Args.addAllArgs(CmdArgs,
-  {options::OPT_L, options::OPT_T_Group, options::OPT_s,
-   options::OPT_t, options::OPT_Z_Flag, options::OPT_r});
+  Args.addAllArgs(CmdArgs, {options::OPT_L, options::OPT_T_Group,
+options::OPT_s, options::OPT_t, options::OPT_r});
 
   TC.AddFilePathLibArgs(Args, CmdArgs);
 
diff --git a/clang/lib/Driver/ToolChains/CSKYToolChain.cpp 
b/clang/lib/Driver/ToolChains/CSKYToolChain.cpp
index 2bd91e63fdd5a42..0c280347b2af6a1 100644
--- a/clang/lib/Driver/ToolChains/CSKYToolChain.cpp
+++ b/clang/lib/Driver/ToolChains/CSKYToolChain.cpp
@@ -169,9 +169,8 @@ void CSKY::Linker::ConstructJob(Compilation , const 
JobAction ,
 
   Args.AddAllArgs(CmdArgs, options::OPT_L);
   ToolChain.AddFilePathLibArgs(Args, CmdArgs);
-  Args.addAllArgs(CmdArgs,
-  {options::OPT_T_Group, options::OPT_s, options::OPT_t,
-   options::OPT_Z_Flag, options::OPT_r});
+  Args.addAllArgs(CmdArgs, {options::OPT_T_Group, options::OPT_s,
+options::OPT_t, options::OPT_r});
 
   AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs, JA);
 
diff --git a/clang/lib/Driver/ToolChains/FreeBSD.cpp 
b/clang/lib/Driver/ToolChains/FreeBSD.cpp
index c936fb88d18ccd9..7a61159ba4a7308 100644
--- a/clang/lib/Driver/ToolChains/FreeBSD.cpp
+++ b/clang/lib/Driver/ToolChains/FreeBSD.cpp
@@ -262,9 +262,8 @@ void freebsd::Linker::ConstructJob(Compilation , const 
JobAction ,
 
   Args.AddAllArgs(CmdArgs, options::OPT_L);
   ToolChain.AddFilePathLibArgs(Args, CmdArgs);
-  Args.addAllArgs(CmdArgs,
-  {options::OPT_T_Group, options::OPT_s, options::OPT_t,
-   options::OPT_Z_Flag, options::OPT_r});
+  Args.addAllArgs(CmdArgs, {options::OPT_T_Group, options::OPT_s,
+options::OPT_t, options::OPT_r});
 
   if (D.isUsingLTO()) {
 assert(!Inputs.empty() && "Must have at least one input.");
diff --git a/clang/lib/Driver/ToolChains/Haiku.cpp 
b/clang/lib/Driver/ToolChains/Haiku.cpp
index c2653a4a2022edf..9f56a0ea5d612d0 100644
--- a/clang/lib/Driver/ToolChains/Haiku.cpp
+++ b/clang/lib/Driver/ToolChains/Haiku.cpp
@@ -80,9 +80,8 @@ void haiku::Linker::ConstructJob(Compilation , const 
JobAction ,
 
CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("init_term_dyn.o")));
   }
 
-  Args.addAllArgs(CmdArgs,
-  {options::OPT_L, options::OPT_T_Group, options::OPT_s,
-   options::OPT_t, options::OPT_Z_Flag, options::OPT_r});
+  Args.addAllArgs(CmdArgs, {options::OPT_L, options::OPT_T_Group,
+options::OPT_s, options::OPT_t, options::OPT_r});
   ToolChain.AddFilePathLibArgs(Args, CmdArgs);
 
   addLinkerCompressDebugSectionsOption(ToolChain, Args, CmdArgs);
diff --git a/clang/lib/Driver/ToolChains/MinGW.cpp 
b/clang/lib/Driver/ToolChains/MinGW.cpp
index d3d829a8ddbdb95..39d767795445dbe 100644
--- a/clang/lib/Driver/ToolChains/MinGW.cpp
+++ b/clang/lib/Driver/ToolChains/MinGW.cpp
@@ -201,7 +201,6 @@ void tools::MinGW::Linker::ConstructJob(Compilation , 
const JobAction ,
   Args.AddLastArg(CmdArgs, options::OPT_s);
   Args.AddLastArg(CmdArgs, options::OPT_t);
   Args.AddAllArgs(CmdArgs, options::OPT_u_Group);
-  Args.AddLastArg(CmdArgs, options::OPT_Z_Flag);
 
   // Add asan_dynamic as the first import lib before other libs. This allows
   // asan to be initialized as early as possible to increase its 
instrumentation
diff --git 

  1   2   >