[clang] Reland "[clang][modules] Print library module manifest path." (PR #82160)

2024-02-27 Thread Chuanqi Xu via cfe-commits

ChuanqiXu9 wrote:

@mordante if we want this for 18, we need to land and backport it in this week.

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


[clang] [cfi][CodeGen] Call SetLLVMFunctionAttributes{, ForDefinition} on __cf… (PR #78253)

2024-02-27 Thread Pavel Kosov via cfe-commits

kpdev wrote:

@AaronBallman @kongy Hi! Could you please take a look at this patch?

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


[clang] [compiler-rt] [llvm] [InstrFDO][TypeProf] Implement binary instrumentation and profile read/write (PR #66825)

2024-02-27 Thread Mingming Liu via cfe-commits

minglotus-6 wrote:

New changes since last review besides clang-formats
1. Merged profile format change from main branch.
2. In instrumentation pass, emit unsupported warnings for non-ELF object file 
formats. 
- Updated vtable_profile.ll and add vtable_prof_unsupported.ll as test 
cases.

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


[clang] [compiler-rt] [llvm] [InstrFDO][TypeProf] Implement binary instrumentation and profile read/write (PR #66825)

2024-02-27 Thread Mingming Liu via cfe-commits

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


[clang] [Clang][Sema] placement new initializes typedef array with correct size (PR #83124)

2024-02-27 Thread via cfe-commits

https://github.com/mahtohappy updated 
https://github.com/llvm/llvm-project/pull/83124

>From 7f6bbd2a9e5ab162b0efb5c6dcca91e1d83a0bce Mon Sep 17 00:00:00 2001
From: mahtohappy 
Date: Tue, 27 Feb 2024 03:13:51 -0800
Subject: [PATCH] [Clang][Sema] placement new initializes typedef array with
 correct size

---
 clang/lib/Sema/TreeTransform.h| 14 +-
 .../X86/instantiate-new-placement-size.cpp| 19 +++
 2 files changed, 32 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/CodeGen/X86/instantiate-new-placement-size.cpp

diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index 7389a48fe56fcc..0cda78650fcc83 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -12669,6 +12669,19 @@ TreeTransform::TransformCXXNewExpr(CXXNewExpr 
*E) {
 ArraySize = NewArraySize.get();
   }
 
+  // Per C++0x [expr.new]p5, the type being constructed may be a
+  // typedef of an array type.
+  QualType AllocType = AllocTypeInfo->getType();
+  if (ArraySize) {
+if (const ConstantArrayType *Array =
+SemaRef.Context.getAsConstantArrayType(AllocType)) {
+  ArraySize = IntegerLiteral::Create(SemaRef.Context, Array->getSize(),
+ SemaRef.Context.getSizeType(),
+ E->getBeginLoc());
+  AllocType = Array->getElementType();
+}
+  }
+
   // Transform the placement arguments (if any).
   bool ArgumentChanged = false;
   SmallVector PlacementArgs;
@@ -12730,7 +12743,6 @@ TreeTransform::TransformCXXNewExpr(CXXNewExpr 
*E) {
 return E;
   }
 
-  QualType AllocType = AllocTypeInfo->getType();
   if (!ArraySize) {
 // If no array size was specified, but the new expression was
 // instantiated with an array type (e.g., "new T" where T is
diff --git a/clang/test/CodeGen/X86/instantiate-new-placement-size.cpp 
b/clang/test/CodeGen/X86/instantiate-new-placement-size.cpp
new file mode 100644
index 00..042554272a9bf6
--- /dev/null
+++ b/clang/test/CodeGen/X86/instantiate-new-placement-size.cpp
@@ -0,0 +1,19 @@
+// RUN: %clang -S -Xclang -triple=x86_64-unknown-linux-gnu 
-fno-discard-value-names -emit-llvm -o - %s | FileCheck %s
+#include 
+
+// CHECK: call void @llvm.memset.p0.i64(ptr align 1 %x, i8 0, i64 8, i1 false)
+// CHECK: call void @llvm.memset.p0.i64(ptr align 16 %x, i8 0, i64 32, i1 
false)
+template 
+void f()
+{
+typedef TYPE TArray[8];
+
+TArray x;
+new() TArray();
+}
+
+int main()
+{
+f();
+f();
+}

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


[clang] [alpha.webkit.UncountedCallArgsChecker] Allow a variable declaration in a trivial function. (PR #82291)

2024-02-27 Thread Ryosuke Niwa via cfe-commits

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


[clang] 4d04a40 - [alpha.webkit.UncountedCallArgsChecker] Allow a variable declaration in a trivial function. (#82291)

2024-02-27 Thread via cfe-commits

Author: Ryosuke Niwa
Date: 2024-02-27T22:25:55-08:00
New Revision: 4d04a40adb68f284350831911a658715134c66d8

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

LOG: [alpha.webkit.UncountedCallArgsChecker] Allow a variable declaration in a 
trivial function. (#82291)

Added: 


Modified: 
clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
index defd83ec8e179c..01b191ab0eeaf4 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
@@ -310,8 +310,12 @@ class TrivialFunctionAnalysisVisitor
 return true;
   if (isa(decl))
 return true;
-  if (auto *VD = dyn_cast(decl))
-return VD->hasConstantInitialization() && VD->getEvaluatedValue();
+  if (auto *VD = dyn_cast(decl)) {
+if (VD->hasConstantInitialization() && VD->getEvaluatedValue())
+  return true;
+auto *Init = VD->getInit();
+return !Init || Visit(Init);
+  }
 }
 return false;
   }

diff  --git a/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp 
b/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp
index ac16a31293f3de..80a9a263dab140 100644
--- a/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp
+++ b/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp
@@ -199,6 +199,8 @@ class RefCounted {
   bool trivial23() const { return 
OptionSet::fromRaw(v).contains(Flags::Flag1); }
   int trivial24() const { ASSERT(v); return v; }
   unsigned trivial25() const { return __c11_atomic_load((volatile 
_Atomic(unsigned) *), __ATOMIC_RELAXED); }
+  bool trivial26() { bool hasValue = v; return !hasValue; }
+  bool trivial27(int v) { bool value; value = v ? 1 : 0; return value; }
 
   static RefCounted& singleton() {
 static RefCounted s_RefCounted;
@@ -262,6 +264,15 @@ class RefCounted {
 return __c11_atomic_load((volatile _Atomic(unsigned) *)another(), 
__ATOMIC_RELAXED);
   }
 
+  void nonTrivial11() {
+Number num(0.3);
+  }
+
+  bool nonTrivial12() {
+bool val = otherFunction();
+return val;
+  }
+
   unsigned v { 0 };
   Number* number { nullptr };
   Enum enumValue { Enum::Value1 };
@@ -309,6 +320,8 @@ class UnrelatedClass {
 getFieldTrivial().trivial23(); // no-warning
 getFieldTrivial().trivial24(); // no-warning
 getFieldTrivial().trivial25(); // no-warning
+getFieldTrivial().trivial26(); // no-warning
+getFieldTrivial().trivial27(5); // no-warning
 RefCounted::singleton().trivial18(); // no-warning
 RefCounted::singleton().someFunction(); // no-warning
 
@@ -334,6 +347,10 @@ class UnrelatedClass {
 // expected-warning@-1{{Call argument for 'this' parameter is uncounted 
and unsafe}}
 getFieldTrivial().nonTrivial10();
 // expected-warning@-1{{Call argument for 'this' parameter is uncounted 
and unsafe}}
+getFieldTrivial().nonTrivial11();
+// expected-warning@-1{{Call argument for 'this' parameter is uncounted 
and unsafe}}
+getFieldTrivial().nonTrivial12();
+// expected-warning@-1{{Call argument for 'this' parameter is uncounted 
and unsafe}}
   }
 };
 



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


[clang] Disable FTZ/DAZ when compiling shared libraries by default. (PR #80475)

2024-02-27 Thread Matt Arsenault via cfe-commits

arsenm wrote:

> So overall, the practical effect of the `denormal-fp-math` attribute being 
> set incorrectly doesn't appear to matter.

It matters more for AMDGPU, where we need to care because some instructions 
just don't respect denormals. We legalize some operations differently depending 
on the mode 


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


[clang] [compiler-rt] [llvm] [InstrFDO][TypeProf] Implement binary instrumentation and profile read/write (PR #66825)

2024-02-27 Thread Mingming Liu via cfe-commits

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


[clang] [llvm] [transforms] Inline simple variadic functions (PR #81058)

2024-02-27 Thread Matt Arsenault via cfe-commits

https://github.com/arsenm commented:

Title should be rephrased; this doesn't have anything to do with inlining 

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


[clang] [llvm] [AMDGPU] Emit a waitcnt instruction after each memory instruction (PR #79236)

2024-02-27 Thread Tony Tye via cfe-commits

t-tye wrote:

I am not clear why new functions need to be added for this, as I think there 
are existing functions that already do this.

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


[clang] [InstallAPI] Hookup Input files & basic ASTVisitor (PR #82552)

2024-02-27 Thread Cyndy Ishida via cfe-commits

https://github.com/cyndyishida updated 
https://github.com/llvm/llvm-project/pull/82552

>From a7d0c1cf15764ee2ccbeb609fbaf014fdbde81b1 Mon Sep 17 00:00:00 2001
From: Cyndy Ishida 
Date: Wed, 21 Feb 2024 14:56:02 -0800
Subject: [PATCH] [InstallAPI] Hookup Input files & basic ASTVisitor

This patch takes in json files as input to determine that header files to 
process, and in which order, to pass along for CC1 invocations.
This patch also includes an ASTVisitor to collect simple global variables.
---
 clang/include/clang/InstallAPI/Context.h  | 22 -
 clang/include/clang/InstallAPI/Frontend.h | 48 ++
 clang/include/clang/InstallAPI/HeaderFile.h   | 23 +
 clang/include/clang/InstallAPI/Visitor.h  | 51 ++
 clang/lib/InstallAPI/CMakeLists.txt   |  3 +
 clang/lib/InstallAPI/Frontend.cpp | 58 
 clang/lib/InstallAPI/Visitor.cpp  | 94 +++
 clang/test/InstallAPI/basic.test  |  5 +
 clang/test/InstallAPI/variables.test  | 63 +
 .../clang-installapi/ClangInstallAPI.cpp  | 77 +--
 clang/tools/clang-installapi/Options.cpp  | 29 ++
 clang/tools/clang-installapi/Options.h|  8 ++
 12 files changed, 473 insertions(+), 8 deletions(-)
 create mode 100644 clang/include/clang/InstallAPI/Frontend.h
 create mode 100644 clang/include/clang/InstallAPI/Visitor.h
 create mode 100644 clang/lib/InstallAPI/Frontend.cpp
 create mode 100644 clang/lib/InstallAPI/Visitor.cpp
 create mode 100644 clang/test/InstallAPI/variables.test

diff --git a/clang/include/clang/InstallAPI/Context.h 
b/clang/include/clang/InstallAPI/Context.h
index 7d105920734fde..292992908aa129 100644
--- a/clang/include/clang/InstallAPI/Context.h
+++ b/clang/include/clang/InstallAPI/Context.h
@@ -9,6 +9,9 @@
 #ifndef LLVM_CLANG_INSTALLAPI_CONTEXT_H
 #define LLVM_CLANG_INSTALLAPI_CONTEXT_H
 
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/FileManager.h"
+#include "clang/InstallAPI/HeaderFile.h"
 #include "llvm/TextAPI/InterfaceFile.h"
 #include "llvm/TextAPI/RecordVisitor.h"
 #include "llvm/TextAPI/RecordsSlice.h"
@@ -24,8 +27,23 @@ struct InstallAPIContext {
   /// Library attributes that are typically passed as linker inputs.
   llvm::MachO::RecordsSlice::BinaryAttrs BA;
 
-  /// Active target triple to parse.
-  llvm::Triple TargetTriple{};
+  /// All headers that represent a library.
+  HeaderSeq InputHeaders;
+
+  /// Active language mode to parse in.
+  Language LangMode = Language::ObjC;
+
+  /// Active header access type.
+  HeaderType Type = HeaderType::Unknown;
+
+  /// Active TargetSlice for symbol record collection.
+  std::shared_ptr Records;
+
+  /// FileManager for all I/O operations.
+  FileManager *FM = nullptr;
+
+  /// DiagnosticsEngine for all error reporting.
+  DiagnosticsEngine *Diags = nullptr;
 
   /// File Path of output location.
   llvm::StringRef OutputLoc{};
diff --git a/clang/include/clang/InstallAPI/Frontend.h 
b/clang/include/clang/InstallAPI/Frontend.h
new file mode 100644
index 00..7ee87ae028d079
--- /dev/null
+++ b/clang/include/clang/InstallAPI/Frontend.h
@@ -0,0 +1,48 @@
+//===- InstallAPI/Frontend.h ---*- 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
+//
+//===--===//
+///
+/// Top level wrappers for InstallAPI frontend operations.
+///
+//===--===//
+
+#ifndef LLVM_CLANG_INSTALLAPI_FRONTEND_H
+#define LLVM_CLANG_INSTALLAPI_FRONTEND_H
+
+#include "clang/AST/ASTConsumer.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Frontend/FrontendActions.h"
+#include "clang/InstallAPI/Context.h"
+#include "clang/InstallAPI/Visitor.h"
+#include "llvm/ADT/Twine.h"
+#include "llvm/Support/MemoryBuffer.h"
+
+namespace clang {
+namespace installapi {
+
+/// Create a buffer that contains all headers to scan
+/// for global symbols with.
+std::unique_ptr
+createInputBuffer(const InstallAPIContext );
+
+class InstallAPIAction : public ASTFrontendAction {
+public:
+  explicit InstallAPIAction(llvm::MachO::RecordsSlice )
+  : Records(Records) {}
+
+  std::unique_ptr CreateASTConsumer(CompilerInstance ,
+ StringRef InFile) override {
+return std::make_unique(CI.getASTContext(), Records);
+  }
+
+private:
+  llvm::MachO::RecordsSlice 
+};
+} // namespace installapi
+} // namespace clang
+
+#endif // LLVM_CLANG_INSTALLAPI_FRONTEND_H
diff --git a/clang/include/clang/InstallAPI/HeaderFile.h 
b/clang/include/clang/InstallAPI/HeaderFile.h
index fc64a43b3def5c..70e83bbb3e76f6 100644
--- a/clang/include/clang/InstallAPI/HeaderFile.h
+++ 

[clang] [OpenMP] Parse and Sema support for declare target in local scope (PR #83223)

2024-02-27 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Sandeep Kosuri (sandeepkosuri)


Changes

- adds Parse and Sema support for the `declare target` directive inside a 
function scope.

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


5 Files Affected:

- (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (+3) 
- (modified) clang/lib/Parse/ParseOpenMP.cpp (+22-1) 
- (modified) clang/lib/Sema/SemaOpenMP.cpp (+9) 
- (modified) clang/test/OpenMP/declare_target_ast_print.cpp (+19) 
- (modified) clang/test/OpenMP/declare_target_messages.cpp (+9) 


``diff
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index a7f2858477bee6..faa7d1872ae3f1 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -11326,6 +11326,9 @@ def err_omp_device_type_mismatch : Error<
 def err_omp_wrong_device_function_call : Error<
   "function with 'device_type(%0)' is not available on %select{device|host}1">;
 def note_omp_marked_device_type_here : Note<"marked as 'device_type(%0)' 
here">;
+def warn_omp_declare_target_has_local_vars : Warning<
+  "local variable '%0' ignored in 'declare target' directive; ">,
+  InGroup;
 def warn_omp_declare_target_after_first_use : Warning<
   "declaration marked as declare target after first use, it may lead to 
incorrect results">,
   InGroup;
diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp
index bfc31f2653c237..814126e321d3bc 100644
--- a/clang/lib/Parse/ParseOpenMP.cpp
+++ b/clang/lib/Parse/ParseOpenMP.cpp
@@ -2984,8 +2984,29 @@ StmtResult 
Parser::ParseOpenMPDeclarativeOrExecutableDirective(
 OMPDirectiveScope.Exit();
 break;
   }
+  case OMPD_declare_target: {
+SourceLocation DTLoc = ConsumeAnyToken();
+bool HasClauses = Tok.isNot(tok::annot_pragma_openmp_end);
+Sema::DeclareTargetContextInfo DTCI(DKind, DTLoc);
+if (HasClauses)
+  ParseOMPDeclareTargetClauses(DTCI);
+bool HasImplicitMappings =
+!HasClauses || (DTCI.ExplicitlyMapped.empty() && DTCI.Indirect);
+
+if (HasImplicitMappings) {
+  Diag(Tok, diag::err_omp_unexpected_directive)
+  << 1 << getOpenMPDirectiveName(DKind);
+  SkipUntil(tok::annot_pragma_openmp_end);
+  break;
+}
+
+// Skip the last annot_pragma_openmp_end.
+ConsumeAnyToken();
+
+Actions.ActOnFinishedOpenMPDeclareTargetContext(DTCI);
+break;
+  }
   case OMPD_declare_simd:
-  case OMPD_declare_target:
   case OMPD_begin_declare_target:
   case OMPD_end_declare_target:
   case OMPD_requires:
diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 7f75cfc5b54f35..0cd8ff065a3419 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -23352,6 +23352,15 @@ void Sema::ActOnOpenMPDeclareTargetName(NamedDecl *ND, 
SourceLocation Loc,
   isa(ND)) &&
  "Expected variable, function or function template.");
 
+  if (auto *VD = dyn_cast(ND)) {
+// Only global variables can be marked as declare target.
+if (!VD->isFileVarDecl() && !VD->isStaticLocal() &&
+!VD->isStaticDataMember()) {
+  Diag(Loc, diag::warn_omp_declare_target_has_local_vars)
+  << VD->getNameAsString();
+  return;
+}
+  }
   // Diagnose marking after use as it may lead to incorrect diagnosis and
   // codegen.
   if (LangOpts.OpenMP >= 50 &&
diff --git a/clang/test/OpenMP/declare_target_ast_print.cpp 
b/clang/test/OpenMP/declare_target_ast_print.cpp
index 40c5dd299abd96..43cccf763e97c3 100644
--- a/clang/test/OpenMP/declare_target_ast_print.cpp
+++ b/clang/test/OpenMP/declare_target_ast_print.cpp
@@ -360,6 +360,17 @@ int inner_link;
 // CHECK-NEXT: int inner_link;
 // CHECK-NEXT: #pragma omp end declare target
 
+void foo2() { return ;}
+// CHECK: #pragma omp declare target
+// CHECK-NEXT: void foo2() {
+// CHECK-NEXT: return;
+// CHECK-NEXT: }
+
+int x;
+// CHECK: #pragma omp declare target link
+// CHECK-NEXT: int x;
+// CHECK-NEXT: #pragma omp end declare target
+
 int main (int argc, char **argv) {
   foo();
   foo_c();
@@ -367,6 +378,14 @@ int main (int argc, char **argv) {
   test1();
   baz();
   baz();
+
+#if _OPENMP == 202111
+#pragma omp declare target enter(foo2)
+#else
+#pragma omp declare target to (foo2)
+#endif
+
+  #pragma omp declare target link(x)
   return (0);
 }
 
diff --git a/clang/test/OpenMP/declare_target_messages.cpp 
b/clang/test/OpenMP/declare_target_messages.cpp
index cf034aca7c9136..39616bc47b2ccb 100644
--- a/clang/test/OpenMP/declare_target_messages.cpp
+++ b/clang/test/OpenMP/declare_target_messages.cpp
@@ -182,11 +182,20 @@ struct S {
 #pragma omp end declare target
 };
 
+void foo3() {
+  return;
+}
+
+int *y;
+int **w = 
 int main (int argc, char **argv) {
+  int a = 2;
 #pragma omp declare target // expected-error {{unexpected OpenMP directive 
'#pragma omp declare target'}}
   int v;
 #pragma omp end 

[clang] [OpenMP] Parse and Sema support for declare target in local scope (PR #83223)

2024-02-27 Thread Sandeep Kosuri via cfe-commits

https://github.com/sandeepkosuri created 
https://github.com/llvm/llvm-project/pull/83223

- adds Parse and Sema support for the `declare target` directive inside a 
function scope.

>From cbf1b4409e379309ae3d942b3dbec0964b9ee0d1 Mon Sep 17 00:00:00 2001
From: Sandeep Kosuri 
Date: Tue, 27 Feb 2024 23:19:41 -0600
Subject: [PATCH] [OpenMP] Parse and Sema support for declare target in local
 scope

---
 .../clang/Basic/DiagnosticSemaKinds.td|  3 +++
 clang/lib/Parse/ParseOpenMP.cpp   | 23 ++-
 clang/lib/Sema/SemaOpenMP.cpp |  9 
 .../test/OpenMP/declare_target_ast_print.cpp  | 19 +++
 clang/test/OpenMP/declare_target_messages.cpp |  9 
 5 files changed, 62 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index a7f2858477bee6..faa7d1872ae3f1 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -11326,6 +11326,9 @@ def err_omp_device_type_mismatch : Error<
 def err_omp_wrong_device_function_call : Error<
   "function with 'device_type(%0)' is not available on %select{device|host}1">;
 def note_omp_marked_device_type_here : Note<"marked as 'device_type(%0)' 
here">;
+def warn_omp_declare_target_has_local_vars : Warning<
+  "local variable '%0' ignored in 'declare target' directive; ">,
+  InGroup;
 def warn_omp_declare_target_after_first_use : Warning<
   "declaration marked as declare target after first use, it may lead to 
incorrect results">,
   InGroup;
diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp
index bfc31f2653c237..814126e321d3bc 100644
--- a/clang/lib/Parse/ParseOpenMP.cpp
+++ b/clang/lib/Parse/ParseOpenMP.cpp
@@ -2984,8 +2984,29 @@ StmtResult 
Parser::ParseOpenMPDeclarativeOrExecutableDirective(
 OMPDirectiveScope.Exit();
 break;
   }
+  case OMPD_declare_target: {
+SourceLocation DTLoc = ConsumeAnyToken();
+bool HasClauses = Tok.isNot(tok::annot_pragma_openmp_end);
+Sema::DeclareTargetContextInfo DTCI(DKind, DTLoc);
+if (HasClauses)
+  ParseOMPDeclareTargetClauses(DTCI);
+bool HasImplicitMappings =
+!HasClauses || (DTCI.ExplicitlyMapped.empty() && DTCI.Indirect);
+
+if (HasImplicitMappings) {
+  Diag(Tok, diag::err_omp_unexpected_directive)
+  << 1 << getOpenMPDirectiveName(DKind);
+  SkipUntil(tok::annot_pragma_openmp_end);
+  break;
+}
+
+// Skip the last annot_pragma_openmp_end.
+ConsumeAnyToken();
+
+Actions.ActOnFinishedOpenMPDeclareTargetContext(DTCI);
+break;
+  }
   case OMPD_declare_simd:
-  case OMPD_declare_target:
   case OMPD_begin_declare_target:
   case OMPD_end_declare_target:
   case OMPD_requires:
diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 7f75cfc5b54f35..0cd8ff065a3419 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -23352,6 +23352,15 @@ void Sema::ActOnOpenMPDeclareTargetName(NamedDecl *ND, 
SourceLocation Loc,
   isa(ND)) &&
  "Expected variable, function or function template.");
 
+  if (auto *VD = dyn_cast(ND)) {
+// Only global variables can be marked as declare target.
+if (!VD->isFileVarDecl() && !VD->isStaticLocal() &&
+!VD->isStaticDataMember()) {
+  Diag(Loc, diag::warn_omp_declare_target_has_local_vars)
+  << VD->getNameAsString();
+  return;
+}
+  }
   // Diagnose marking after use as it may lead to incorrect diagnosis and
   // codegen.
   if (LangOpts.OpenMP >= 50 &&
diff --git a/clang/test/OpenMP/declare_target_ast_print.cpp 
b/clang/test/OpenMP/declare_target_ast_print.cpp
index 40c5dd299abd96..43cccf763e97c3 100644
--- a/clang/test/OpenMP/declare_target_ast_print.cpp
+++ b/clang/test/OpenMP/declare_target_ast_print.cpp
@@ -360,6 +360,17 @@ int inner_link;
 // CHECK-NEXT: int inner_link;
 // CHECK-NEXT: #pragma omp end declare target
 
+void foo2() { return ;}
+// CHECK: #pragma omp declare target
+// CHECK-NEXT: void foo2() {
+// CHECK-NEXT: return;
+// CHECK-NEXT: }
+
+int x;
+// CHECK: #pragma omp declare target link
+// CHECK-NEXT: int x;
+// CHECK-NEXT: #pragma omp end declare target
+
 int main (int argc, char **argv) {
   foo();
   foo_c();
@@ -367,6 +378,14 @@ int main (int argc, char **argv) {
   test1();
   baz();
   baz();
+
+#if _OPENMP == 202111
+#pragma omp declare target enter(foo2)
+#else
+#pragma omp declare target to (foo2)
+#endif
+
+  #pragma omp declare target link(x)
   return (0);
 }
 
diff --git a/clang/test/OpenMP/declare_target_messages.cpp 
b/clang/test/OpenMP/declare_target_messages.cpp
index cf034aca7c9136..39616bc47b2ccb 100644
--- a/clang/test/OpenMP/declare_target_messages.cpp
+++ b/clang/test/OpenMP/declare_target_messages.cpp
@@ -182,11 +182,20 @@ struct S {
 #pragma omp end declare target
 };
 
+void foo3() {
+  return;
+}
+
+int *y;
+int **w = 
 int main 

[clang] [Clang][Sema] placement new initializes typedef array with correct size (PR #83124)

2024-02-27 Thread via cfe-commits

mahtohappy wrote:

@shafik I'm not aware of which cases it was catching before, I was hoping 
testing will reveal those testcases. I agree with your thinking that we might 
be breaking something and and don't have test coverage for it. I'll leave this 
condition as it is and add a separate check for this issue. It'll be more 
robust solution. 

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


[clang] [Clang][Sema] placement new initializes typedef array with correct size (PR #83124)

2024-02-27 Thread Shafik Yaghmour via cfe-commits

shafik wrote:

Can you explain which cases the `if (!ArraySize)` condition was catching before 
and why the change does not effect those cases? My fear is that we are breaking 
other cases but we don't have test coverage for those cases and we are missing 
those breaks.

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


[clang] [Clang][HTO] Add clang attribute for propagating llvm-level information (PR #83059)

2024-02-27 Thread William Moses via cfe-commits

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


[clang] [Clang][HTO] Add clang attribute for propagating llvm-level information (PR #83059)

2024-02-27 Thread William Moses via cfe-commits

wsmoses wrote:

Hm actually reopening, for some reason the metadata isn't being pushed at O0.

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


[clang] [Clang][DebugInfo] Use CGDebugInfo::createFile in CGDebugInfo::CreateCompileUnit (#83174) (PR #83175)

2024-02-27 Thread David Blaikie via cfe-commits

dwblaikie wrote:

Some test coverage would be good to help demonstrate the issue/fix

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


[clang-tools-extra] [clangd] Add 'apply all clangd fixes' and 'apply all '_' fixes' QuickFixes (PR #79867)

2024-02-27 Thread Tor Shepherd via cfe-commits

https://github.com/torshepherd updated 
https://github.com/llvm/llvm-project/pull/79867

>From 94dee94becb7d79b087e183754602e08a5c4669d Mon Sep 17 00:00:00 2001
From: Tor Shepherd 
Date: Mon, 29 Jan 2024 11:44:25 -0500
Subject: [PATCH] [clangd] Add fix-all CodeActions

---
 clang-tools-extra/clangd/Diagnostics.cpp  |  72 ++-
 clang-tools-extra/clangd/Protocol.h   |  22 +-
 .../clangd/unittests/DiagnosticsTests.cpp | 200 +-
 3 files changed, 227 insertions(+), 67 deletions(-)

diff --git a/clang-tools-extra/clangd/Diagnostics.cpp 
b/clang-tools-extra/clangd/Diagnostics.cpp
index d5eca083eb6512..37ee5cd8fbc7ae 100644
--- a/clang-tools-extra/clangd/Diagnostics.cpp
+++ b/clang-tools-extra/clangd/Diagnostics.cpp
@@ -339,6 +339,72 @@ std::string noteMessage(const Diag , const DiagBase 
,
   return capitalize(std::move(Result));
 }
 
+std::optional
+generateApplyAllFromOption(const llvm::StringRef Name,
+   llvm::ArrayRef AllDiagnostics) {
+  Fix ApplyAll;
+  for (auto *const Diag : AllDiagnostics) {
+for (const auto  : Diag->Fixes)
+  ApplyAll.Edits.insert(ApplyAll.Edits.end(), Fix.Edits.begin(),
+Fix.Edits.end());
+  }
+  llvm::sort(ApplyAll.Edits);
+  ApplyAll.Edits.erase(
+  std::unique(ApplyAll.Edits.begin(), ApplyAll.Edits.end()),
+  ApplyAll.Edits.end());
+  // Skip diagnostic categories that don't have multiple fixes to apply
+  if (ApplyAll.Edits.size() < 2U) {
+return std::nullopt;
+  }
+  ApplyAll.Message = llvm::formatv("apply all '{0}' fixes", Name);
+  return ApplyAll;
+}
+
+std::optional
+generateApplyAllFixesOption(llvm::ArrayRef AllDiagnostics) {
+  Fix ApplyAll;
+  for (auto const  : AllDiagnostics) {
+for (const auto  : Diag.Fixes)
+  ApplyAll.Edits.insert(ApplyAll.Edits.end(), Fix.Edits.begin(),
+Fix.Edits.end());
+  }
+  llvm::sort(ApplyAll.Edits);
+  ApplyAll.Edits.erase(
+  std::unique(ApplyAll.Edits.begin(), ApplyAll.Edits.end()),
+  ApplyAll.Edits.end());
+  if (ApplyAll.Edits.size() < 2U) {
+return std::nullopt;
+  }
+  ApplyAll.Message = "apply all clangd fixes";
+  return ApplyAll;
+}
+
+void appendApplyAlls(std::vector ) {
+  llvm::DenseMap> CategorizedFixes;
+
+  for (auto  : AllDiagnostics) {
+// Keep track of fixable diagnostics for generating "apply all fixes"
+if (!Diag.Fixes.empty()) {
+  if (auto [It, DidEmplace] = CategorizedFixes.try_emplace(
+  Diag.Name, std::vector{});
+  !DidEmplace)
+It->second.emplace_back();
+}
+  }
+
+  auto FixAllClangd = generateApplyAllFixesOption(AllDiagnostics);
+  for (const auto &[Name, DiagsForThisCategory] : CategorizedFixes) {
+auto FixAllForCategory =
+generateApplyAllFromOption(Name, DiagsForThisCategory);
+for (auto *Diag : DiagsForThisCategory) {
+  if (DiagsForThisCategory.size() >= 2U && FixAllForCategory.has_value())
+Diag->Fixes.emplace_back(*FixAllForCategory);
+  if (CategorizedFixes.size() >= 2U && FixAllClangd.has_value())
+Diag->Fixes.emplace_back(*FixAllClangd);
+}
+  }
+}
+
 void setTags(clangd::Diag ) {
   static const auto *DeprecatedDiags = new llvm::DenseSet{
   diag::warn_access_decl_deprecated,
@@ -575,7 +641,8 @@ std::vector StoreDiags::take(const 
clang::tidy::ClangTidyContext *Tidy) {
   // Do not forget to emit a pending diagnostic if there is one.
   flushLastDiag();
 
-  // Fill in name/source now that we have all the context needed to map them.
+  // Fill in name/source now that we have all the context needed to map
+  // them.
   for (auto  : Output) {
 if (const char *ClangDiag = getDiagnosticCode(Diag.ID)) {
   // Warnings controlled by -Wfoo are better recognized by that name.
@@ -619,6 +686,9 @@ std::vector StoreDiags::take(const 
clang::tidy::ClangTidyContext *Tidy) {
   llvm::erase_if(Output, [&](const Diag ) {
 return !SeenDiags.emplace(D.Range, D.Message).second;
   });
+
+  appendApplyAlls(Output);
+
   return std::move(Output);
 }
 
diff --git a/clang-tools-extra/clangd/Protocol.h 
b/clang-tools-extra/clangd/Protocol.h
index 358d4c6feaf87d..113629f138e416 100644
--- a/clang-tools-extra/clangd/Protocol.h
+++ b/clang-tools-extra/clangd/Protocol.h
@@ -257,6 +257,10 @@ inline bool operator==(const TextEdit , const TextEdit 
) {
   return std::tie(L.newText, L.range, L.annotationId) ==
  std::tie(R.newText, R.range, L.annotationId);
 }
+inline bool operator<(const TextEdit , const TextEdit ) {
+  return std::tie(L.newText, L.range, L.annotationId) <
+ std::tie(R.newText, R.range, L.annotationId);
+}
 bool fromJSON(const llvm::json::Value &, TextEdit &, llvm::json::Path);
 llvm::json::Value toJSON(const TextEdit &);
 llvm::raw_ostream <<(llvm::raw_ostream &, const TextEdit &);
@@ -281,7 +285,7 @@ struct TextDocumentEdit {
   /// The text document to change.
   VersionedTextDocumentIdentifier textDocument;
 
-   /// The edits to be 

[clang] [attributes][analyzer] Generalize [[clang::suppress]] to declarations. (PR #80371)

2024-02-27 Thread Artem Dergachev via cfe-commits

haoNoQ wrote:

Yes I like this perspective: "Schrödinger's need-for-pre-commit-approval" isn't 
a great way to communicate  I'll be more clear in the future.

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


[clang] [clang][analyzer]Add C++ polymorphic ptr arithmetic checker (PR #82977)

2024-02-27 Thread Artem Dergachev via cfe-commits

haoNoQ wrote:

Hi! I wonder if path-sensitive analysis is useful here at all. If you simply 
warn every time you see arithmetic performed on a pointer to a class with at 
least one virtual method, wouldn't that be quite accurate most of the time?

At a glance, such operation only makes sense when all subclasses are actually 
of the same size. I'm aware of pretty much exactly one real-world class of this 
kind: static analyzer's own `SVal` lol. You can detect this case by looking at 
one or two derived classes in the AST, to see if they add any new member 
variables. This won't work if base classes aren't visible in the AST, but your 
checker will also not work in this case(?)

I can also think of cases where path sensitivity is useful because it can catch 
cases like
```
Object *Objs;
char *x = reinterpret_cast(Objs);
x += 1;
```
but these aren't exactly the cases we're trying to catch; it's probably easier 
to think of them as a different problem that we can catch separately (invalid 
reinterpretation of a pointer).

So, maybe your checker should be a plain old compiler warning? Compiler 
warnings are great because they're much easier to enable, so they benefit a 
much larger portion of users. An on-by-default compiler warning will be even 
more accessible, and this one can probably be enabled by default? We usually 
prefer implementing checks as compiler warnings when they don't need 
sophisticated analysis (eg. path-sensitivity) or any sort of domain-specific 
knowledge.

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


[clang] [llvm] [RISCV] Remove experimental from Zacas. (PR #83195)

2024-02-27 Thread Craig Topper via cfe-commits

topperc wrote:

> LGTM.
> 
> Will it be in LLVM 18? Or we need more time to examine its robustness?

The bar for LLVM 18 is pretty high at this point. I doubt this qualifies.

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


[clang] [llvm] [RISCV] Remove experimental from Zacas. (PR #83195)

2024-02-27 Thread Wang Pengcheng via cfe-commits

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

LGTM.
Will it be in LLVM 18? Or we need more time to examine its robustness?

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


[clang] [llvm] [X86] Add Support for X86 TLSDESC Relocations (PR #83136)

2024-02-27 Thread Fangrui Song via cfe-commits


@@ -0,0 +1,165 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py 
UTC_ARGS: --version 4
+; RUN: llc < %s -mtriple=i686-unknown-unknown --relocation-model=pic 
-enable-tlsdesc | FileCheck %s --check-prefix=X86
+; RUN: llc < %s -mtriple=x86_64-pc-linux-gnux32 --relocation-model=pic 
-enable-tlsdesc | FileCheck %s --check-prefix=X32
+; RUN: llc < %s -mtriple=x86_64-unknown-unknown --relocation-model=pic 
-enable-tlsdesc | FileCheck %s --check-prefix=X64
+
+@x = thread_local global i32 0, align 4
+@y = internal thread_local global i32 0, align 4

MaskRay wrote:

GCC's x86-64 port assumes that FLAGS_REG and RAX are changed while all other 
registers are preserved.

Ideally, show that some registers are not clobbered.

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


[clang] [llvm] [X86] Add Support for X86 TLSDESC Relocations (PR #83136)

2024-02-27 Thread Fangrui Song via cfe-commits


@@ -18515,17 +18515,17 @@ X86TargetLowering::LowerGlobalAddress(SDValue Op, 
SelectionDAG ) const {
   return LowerGlobalOrExternal(Op, DAG, /*ForCall=*/false);
 }
 
-static SDValue
-GetTLSADDR(SelectionDAG , SDValue Chain, GlobalAddressSDNode *GA,
-   SDValue *InGlue, const EVT PtrVT, unsigned ReturnReg,
-   unsigned char OperandFlags, bool LocalDynamic = false) {
+static SDValue GetTLSADDR(SelectionDAG , SDValue Chain,

MaskRay wrote:

While changing signatures, rename this to `getTLSADDR` (lowerCase)?

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


[clang] [llvm] [X86] Add Support for X86 TLSDESC Relocations (PR #83136)

2024-02-27 Thread Fangrui Song via cfe-commits


@@ -0,0 +1,165 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py 
UTC_ARGS: --version 4
+; RUN: llc < %s -mtriple=i686-unknown-unknown --relocation-model=pic 
-enable-tlsdesc | FileCheck %s --check-prefix=X86

MaskRay wrote:

`-unknown-unknown` can be removed

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


[clang] [InstallAPI] Hookup Input files & basic ASTVisitor (PR #82552)

2024-02-27 Thread Cyndy Ishida via cfe-commits

https://github.com/cyndyishida updated 
https://github.com/llvm/llvm-project/pull/82552

>From b0cc1eeba893c24d5358cb49189da2e287daf972 Mon Sep 17 00:00:00 2001
From: Cyndy Ishida 
Date: Wed, 21 Feb 2024 14:56:02 -0800
Subject: [PATCH 1/2] [InstallAPI] Hookup Input files & basic ASTVisitor

This patch takes in json files as input to determine that header files to 
process, and in which order, to pass along for CC1 invocations.
This patch also includes an ASTVisitor to collect simple global variables.
---
 clang/include/clang/InstallAPI/Context.h  | 22 -
 clang/include/clang/InstallAPI/Frontend.h | 48 ++
 clang/include/clang/InstallAPI/HeaderFile.h   | 23 +
 clang/include/clang/InstallAPI/Visitor.h  | 51 ++
 clang/lib/InstallAPI/CMakeLists.txt   |  3 +
 clang/lib/InstallAPI/Frontend.cpp | 58 
 clang/lib/InstallAPI/Visitor.cpp  | 94 +++
 clang/test/InstallAPI/basic.test  |  5 +
 clang/test/InstallAPI/variables.test  | 63 +
 .../clang-installapi/ClangInstallAPI.cpp  | 78 +--
 clang/tools/clang-installapi/Options.cpp  | 29 ++
 clang/tools/clang-installapi/Options.h|  8 ++
 12 files changed, 474 insertions(+), 8 deletions(-)
 create mode 100644 clang/include/clang/InstallAPI/Frontend.h
 create mode 100644 clang/include/clang/InstallAPI/Visitor.h
 create mode 100644 clang/lib/InstallAPI/Frontend.cpp
 create mode 100644 clang/lib/InstallAPI/Visitor.cpp
 create mode 100644 clang/test/InstallAPI/variables.test

diff --git a/clang/include/clang/InstallAPI/Context.h 
b/clang/include/clang/InstallAPI/Context.h
index 7d105920734fde..292992908aa129 100644
--- a/clang/include/clang/InstallAPI/Context.h
+++ b/clang/include/clang/InstallAPI/Context.h
@@ -9,6 +9,9 @@
 #ifndef LLVM_CLANG_INSTALLAPI_CONTEXT_H
 #define LLVM_CLANG_INSTALLAPI_CONTEXT_H
 
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/FileManager.h"
+#include "clang/InstallAPI/HeaderFile.h"
 #include "llvm/TextAPI/InterfaceFile.h"
 #include "llvm/TextAPI/RecordVisitor.h"
 #include "llvm/TextAPI/RecordsSlice.h"
@@ -24,8 +27,23 @@ struct InstallAPIContext {
   /// Library attributes that are typically passed as linker inputs.
   llvm::MachO::RecordsSlice::BinaryAttrs BA;
 
-  /// Active target triple to parse.
-  llvm::Triple TargetTriple{};
+  /// All headers that represent a library.
+  HeaderSeq InputHeaders;
+
+  /// Active language mode to parse in.
+  Language LangMode = Language::ObjC;
+
+  /// Active header access type.
+  HeaderType Type = HeaderType::Unknown;
+
+  /// Active TargetSlice for symbol record collection.
+  std::shared_ptr Records;
+
+  /// FileManager for all I/O operations.
+  FileManager *FM = nullptr;
+
+  /// DiagnosticsEngine for all error reporting.
+  DiagnosticsEngine *Diags = nullptr;
 
   /// File Path of output location.
   llvm::StringRef OutputLoc{};
diff --git a/clang/include/clang/InstallAPI/Frontend.h 
b/clang/include/clang/InstallAPI/Frontend.h
new file mode 100644
index 00..7ee87ae028d079
--- /dev/null
+++ b/clang/include/clang/InstallAPI/Frontend.h
@@ -0,0 +1,48 @@
+//===- InstallAPI/Frontend.h ---*- 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
+//
+//===--===//
+///
+/// Top level wrappers for InstallAPI frontend operations.
+///
+//===--===//
+
+#ifndef LLVM_CLANG_INSTALLAPI_FRONTEND_H
+#define LLVM_CLANG_INSTALLAPI_FRONTEND_H
+
+#include "clang/AST/ASTConsumer.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Frontend/FrontendActions.h"
+#include "clang/InstallAPI/Context.h"
+#include "clang/InstallAPI/Visitor.h"
+#include "llvm/ADT/Twine.h"
+#include "llvm/Support/MemoryBuffer.h"
+
+namespace clang {
+namespace installapi {
+
+/// Create a buffer that contains all headers to scan
+/// for global symbols with.
+std::unique_ptr
+createInputBuffer(const InstallAPIContext );
+
+class InstallAPIAction : public ASTFrontendAction {
+public:
+  explicit InstallAPIAction(llvm::MachO::RecordsSlice )
+  : Records(Records) {}
+
+  std::unique_ptr CreateASTConsumer(CompilerInstance ,
+ StringRef InFile) override {
+return std::make_unique(CI.getASTContext(), Records);
+  }
+
+private:
+  llvm::MachO::RecordsSlice 
+};
+} // namespace installapi
+} // namespace clang
+
+#endif // LLVM_CLANG_INSTALLAPI_FRONTEND_H
diff --git a/clang/include/clang/InstallAPI/HeaderFile.h 
b/clang/include/clang/InstallAPI/HeaderFile.h
index fc64a43b3def5c..70e83bbb3e76f6 100644
--- a/clang/include/clang/InstallAPI/HeaderFile.h
+++ 

[clang] [Driver][RISCV] Forward --no-relax option to linker for RISC-V on *BS… (PR #83216)

2024-02-27 Thread Brad Smith via cfe-commits

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

>From 4409a37ff160edb3c41c7650c181a5c9a60c397b Mon Sep 17 00:00:00 2001
From: Brad Smith 
Date: Tue, 27 Feb 2024 21:07:09 -0500
Subject: [PATCH] [Driver][RISCV] Forward --no-relax option to linker for
 RISC-V on *BSD and Haiku

Based on https://github.com/llvm/llvm-project/pull/76432
---
 clang/lib/Driver/ToolChains/FreeBSD.cpp | 11 ---
 clang/lib/Driver/ToolChains/Haiku.cpp   |  7 +--
 clang/lib/Driver/ToolChains/NetBSD.cpp  |  5 -
 clang/lib/Driver/ToolChains/OpenBSD.cpp |  6 +-
 4 files changed, 22 insertions(+), 7 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/FreeBSD.cpp 
b/clang/lib/Driver/ToolChains/FreeBSD.cpp
index b7c9e0e51cdb66..9f942d4694c6a2 100644
--- a/clang/lib/Driver/ToolChains/FreeBSD.cpp
+++ b/clang/lib/Driver/ToolChains/FreeBSD.cpp
@@ -133,6 +133,7 @@ void freebsd::Linker::ConstructJob(Compilation , const 
JobAction ,
const char *LinkingOutput) const {
   const auto  = static_cast(getToolChain());
   const Driver  = ToolChain.getDriver();
+  const llvm::Triple  = ToolChain.getTriple();
   const llvm::Triple::ArchType Arch = ToolChain.getArch();
   const bool IsPIE =
   !Args.hasArg(options::OPT_shared) &&
@@ -165,8 +166,7 @@ void freebsd::Linker::ConstructJob(Compilation , const 
JobAction ,
   CmdArgs.push_back("-dynamic-linker");
   CmdArgs.push_back("/libexec/ld-elf.so.1");
 }
-const llvm::Triple  = ToolChain.getTriple();
-if (Arch == llvm::Triple::arm || T.isX86())
+if (Arch == llvm::Triple::arm || Triple.isX86())
   CmdArgs.push_back("--hash-style=both");
 CmdArgs.push_back("--enable-new-dtags");
   }
@@ -212,12 +212,17 @@ void freebsd::Linker::ConstructJob(Compilation , const 
JobAction ,
   case llvm::Triple::riscv64:
 CmdArgs.push_back("-m");
 CmdArgs.push_back("elf64lriscv");
-CmdArgs.push_back("-X");
 break;
   default:
 break;
   }
 
+  if (Triple.isRISCV64()) {
+CmdArgs.push_back("-X");
+if (Args.hasArg(options::OPT_mno_relax))
+  CmdArgs.push_back("--no-relax");
+  }
+
   if (Arg *A = Args.getLastArg(options::OPT_G)) {
 if (ToolChain.getTriple().isMIPS()) {
   StringRef v = A->getValue();
diff --git a/clang/lib/Driver/ToolChains/Haiku.cpp 
b/clang/lib/Driver/ToolChains/Haiku.cpp
index e0d94035823fd3..7db197d198be53 100644
--- a/clang/lib/Driver/ToolChains/Haiku.cpp
+++ b/clang/lib/Driver/ToolChains/Haiku.cpp
@@ -25,7 +25,7 @@ void haiku::Linker::ConstructJob(Compilation , const 
JobAction ,
const char *LinkingOutput) const {
   const auto  = static_cast(getToolChain());
   const Driver  = ToolChain.getDriver();
-  const llvm::Triple::ArchType Arch = ToolChain.getArch();
+  const llvm::Triple  = ToolChain.getTriple();
   const bool Static = Args.hasArg(options::OPT_static);
   const bool Shared = Args.hasArg(options::OPT_shared);
   ArgStringList CmdArgs;
@@ -61,8 +61,11 @@ void haiku::Linker::ConstructJob(Compilation , const 
JobAction ,
   if (!Shared)
 CmdArgs.push_back("--no-undefined");
 
-  if (Arch == llvm::Triple::riscv64)
+  if (Triple.isRISCV64()) {
 CmdArgs.push_back("-X");
+if (Args.hasArg(options::OPT_mno_relax))
+  CmdArgs.push_back("--no-relax");
+  }
 
   assert((Output.isFilename() || Output.isNothing()) && "Invalid output.");
   if (Output.isFilename()) {
diff --git a/clang/lib/Driver/ToolChains/NetBSD.cpp 
b/clang/lib/Driver/ToolChains/NetBSD.cpp
index 240bf5764b9cce..556fc61556461d 100644
--- a/clang/lib/Driver/ToolChains/NetBSD.cpp
+++ b/clang/lib/Driver/ToolChains/NetBSD.cpp
@@ -240,8 +240,11 @@ void netbsd::Linker::ConstructJob(Compilation , const 
JobAction ,
 break;
   }
 
-  if (Triple.isRISCV())
+  if (Triple.isRISCV()) {
 CmdArgs.push_back("-X");
+if (Args.hasArg(options::OPT_mno_relax))
+  CmdArgs.push_back("--no-relax");
+  }
 
   assert((Output.isFilename() || Output.isNothing()) && "Invalid output.");
   if (Output.isFilename()) {
diff --git a/clang/lib/Driver/ToolChains/OpenBSD.cpp 
b/clang/lib/Driver/ToolChains/OpenBSD.cpp
index fd6aa4d7e68447..0a93f713b08af1 100644
--- a/clang/lib/Driver/ToolChains/OpenBSD.cpp
+++ b/clang/lib/Driver/ToolChains/OpenBSD.cpp
@@ -111,6 +111,7 @@ void openbsd::Linker::ConstructJob(Compilation , const 
JobAction ,
const char *LinkingOutput) const {
   const auto  = static_cast(getToolChain());
   const Driver  = ToolChain.getDriver();
+  const llvm::Triple  = ToolChain.getTriple();
   const llvm::Triple::ArchType Arch = ToolChain.getArch();
   const bool Static = Args.hasArg(options::OPT_static);
   const bool Shared = Args.hasArg(options::OPT_shared);
@@ -160,8 +161,11 @@ void openbsd::Linker::ConstructJob(Compilation , const 
JobAction ,
   if (Nopie || Profiling)
 CmdArgs.push_back("-nopie");
 
-  if (Arch == llvm::Triple::riscv64)
+  if (Triple.isRISCV64()) {
 

[clang] [Driver][RISCV] Forward --no-relax option to linker for RISC-V on *BS… (PR #83216)

2024-02-27 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 bfcf7a0707592ccc7fd9e805aeb36c4da3f315a6 
e9dca00cb002d223b4148d648f4f31b4cfc31d63 -- 
clang/lib/Driver/ToolChains/FreeBSD.cpp clang/lib/Driver/ToolChains/Haiku.cpp 
clang/lib/Driver/ToolChains/NetBSD.cpp clang/lib/Driver/ToolChains/OpenBSD.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Driver/ToolChains/Haiku.cpp 
b/clang/lib/Driver/ToolChains/Haiku.cpp
index 6919a8dd0d..7db197d198 100644
--- a/clang/lib/Driver/ToolChains/Haiku.cpp
+++ b/clang/lib/Driver/ToolChains/Haiku.cpp
@@ -64,7 +64,7 @@ void haiku::Linker::ConstructJob(Compilation , const 
JobAction ,
   if (Triple.isRISCV64()) {
 CmdArgs.push_back("-X");
 if (Args.hasArg(options::OPT_mno_relax))
- CmdArgs.push_back("--no-relax");
+  CmdArgs.push_back("--no-relax");
   }
 
   assert((Output.isFilename() || Output.isNothing()) && "Invalid output.");

``




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


[clang] [Driver][RISCV] Forward --no-relax option to linker for RISC-V on *BS… (PR #83216)

2024-02-27 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-driver

Author: Brad Smith (brad0)


Changes

…D and Haiku

Based on https://github.com/llvm/llvm-project/pull/76432

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


4 Files Affected:

- (modified) clang/lib/Driver/ToolChains/FreeBSD.cpp (+8-3) 
- (modified) clang/lib/Driver/ToolChains/Haiku.cpp (+5-2) 
- (modified) clang/lib/Driver/ToolChains/NetBSD.cpp (+4-1) 
- (modified) clang/lib/Driver/ToolChains/OpenBSD.cpp (+5-1) 


``diff
diff --git a/clang/lib/Driver/ToolChains/FreeBSD.cpp 
b/clang/lib/Driver/ToolChains/FreeBSD.cpp
index b7c9e0e51cdb66..9f942d4694c6a2 100644
--- a/clang/lib/Driver/ToolChains/FreeBSD.cpp
+++ b/clang/lib/Driver/ToolChains/FreeBSD.cpp
@@ -133,6 +133,7 @@ void freebsd::Linker::ConstructJob(Compilation , const 
JobAction ,
const char *LinkingOutput) const {
   const auto  = static_cast(getToolChain());
   const Driver  = ToolChain.getDriver();
+  const llvm::Triple  = ToolChain.getTriple();
   const llvm::Triple::ArchType Arch = ToolChain.getArch();
   const bool IsPIE =
   !Args.hasArg(options::OPT_shared) &&
@@ -165,8 +166,7 @@ void freebsd::Linker::ConstructJob(Compilation , const 
JobAction ,
   CmdArgs.push_back("-dynamic-linker");
   CmdArgs.push_back("/libexec/ld-elf.so.1");
 }
-const llvm::Triple  = ToolChain.getTriple();
-if (Arch == llvm::Triple::arm || T.isX86())
+if (Arch == llvm::Triple::arm || Triple.isX86())
   CmdArgs.push_back("--hash-style=both");
 CmdArgs.push_back("--enable-new-dtags");
   }
@@ -212,12 +212,17 @@ void freebsd::Linker::ConstructJob(Compilation , const 
JobAction ,
   case llvm::Triple::riscv64:
 CmdArgs.push_back("-m");
 CmdArgs.push_back("elf64lriscv");
-CmdArgs.push_back("-X");
 break;
   default:
 break;
   }
 
+  if (Triple.isRISCV64()) {
+CmdArgs.push_back("-X");
+if (Args.hasArg(options::OPT_mno_relax))
+  CmdArgs.push_back("--no-relax");
+  }
+
   if (Arg *A = Args.getLastArg(options::OPT_G)) {
 if (ToolChain.getTriple().isMIPS()) {
   StringRef v = A->getValue();
diff --git a/clang/lib/Driver/ToolChains/Haiku.cpp 
b/clang/lib/Driver/ToolChains/Haiku.cpp
index e0d94035823fd3..6919a8dd0dbeaf 100644
--- a/clang/lib/Driver/ToolChains/Haiku.cpp
+++ b/clang/lib/Driver/ToolChains/Haiku.cpp
@@ -25,7 +25,7 @@ void haiku::Linker::ConstructJob(Compilation , const 
JobAction ,
const char *LinkingOutput) const {
   const auto  = static_cast(getToolChain());
   const Driver  = ToolChain.getDriver();
-  const llvm::Triple::ArchType Arch = ToolChain.getArch();
+  const llvm::Triple  = ToolChain.getTriple();
   const bool Static = Args.hasArg(options::OPT_static);
   const bool Shared = Args.hasArg(options::OPT_shared);
   ArgStringList CmdArgs;
@@ -61,8 +61,11 @@ void haiku::Linker::ConstructJob(Compilation , const 
JobAction ,
   if (!Shared)
 CmdArgs.push_back("--no-undefined");
 
-  if (Arch == llvm::Triple::riscv64)
+  if (Triple.isRISCV64()) {
 CmdArgs.push_back("-X");
+if (Args.hasArg(options::OPT_mno_relax))
+ CmdArgs.push_back("--no-relax");
+  }
 
   assert((Output.isFilename() || Output.isNothing()) && "Invalid output.");
   if (Output.isFilename()) {
diff --git a/clang/lib/Driver/ToolChains/NetBSD.cpp 
b/clang/lib/Driver/ToolChains/NetBSD.cpp
index 240bf5764b9cce..556fc61556461d 100644
--- a/clang/lib/Driver/ToolChains/NetBSD.cpp
+++ b/clang/lib/Driver/ToolChains/NetBSD.cpp
@@ -240,8 +240,11 @@ void netbsd::Linker::ConstructJob(Compilation , const 
JobAction ,
 break;
   }
 
-  if (Triple.isRISCV())
+  if (Triple.isRISCV()) {
 CmdArgs.push_back("-X");
+if (Args.hasArg(options::OPT_mno_relax))
+  CmdArgs.push_back("--no-relax");
+  }
 
   assert((Output.isFilename() || Output.isNothing()) && "Invalid output.");
   if (Output.isFilename()) {
diff --git a/clang/lib/Driver/ToolChains/OpenBSD.cpp 
b/clang/lib/Driver/ToolChains/OpenBSD.cpp
index fd6aa4d7e68447..0a93f713b08af1 100644
--- a/clang/lib/Driver/ToolChains/OpenBSD.cpp
+++ b/clang/lib/Driver/ToolChains/OpenBSD.cpp
@@ -111,6 +111,7 @@ void openbsd::Linker::ConstructJob(Compilation , const 
JobAction ,
const char *LinkingOutput) const {
   const auto  = static_cast(getToolChain());
   const Driver  = ToolChain.getDriver();
+  const llvm::Triple  = ToolChain.getTriple();
   const llvm::Triple::ArchType Arch = ToolChain.getArch();
   const bool Static = Args.hasArg(options::OPT_static);
   const bool Shared = Args.hasArg(options::OPT_shared);
@@ -160,8 +161,11 @@ void openbsd::Linker::ConstructJob(Compilation , const 
JobAction ,
   if (Nopie || Profiling)
 CmdArgs.push_back("-nopie");
 
-  if (Arch == llvm::Triple::riscv64)
+  if (Triple.isRISCV64()) {
 CmdArgs.push_back("-X");
+if (Args.hasArg(options::OPT_mno_relax))
+  CmdArgs.push_back("--no-relax");
+  }
 
   assert((Output.isFilename() 

[clang] [Driver][RISCV] Forward --no-relax option to linker for RISC-V on *BS… (PR #83216)

2024-02-27 Thread Brad Smith via cfe-commits

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

…D and Haiku

Based on https://github.com/llvm/llvm-project/pull/76432

>From e9dca00cb002d223b4148d648f4f31b4cfc31d63 Mon Sep 17 00:00:00 2001
From: Brad Smith 
Date: Tue, 27 Feb 2024 21:07:09 -0500
Subject: [PATCH] [Driver][RISCV] Forward --no-relax option to linker for
 RISC-V on *BSD and Haiku

Based on https://github.com/llvm/llvm-project/pull/76432
---
 clang/lib/Driver/ToolChains/FreeBSD.cpp | 11 ---
 clang/lib/Driver/ToolChains/Haiku.cpp   |  7 +--
 clang/lib/Driver/ToolChains/NetBSD.cpp  |  5 -
 clang/lib/Driver/ToolChains/OpenBSD.cpp |  6 +-
 4 files changed, 22 insertions(+), 7 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/FreeBSD.cpp 
b/clang/lib/Driver/ToolChains/FreeBSD.cpp
index b7c9e0e51cdb66..9f942d4694c6a2 100644
--- a/clang/lib/Driver/ToolChains/FreeBSD.cpp
+++ b/clang/lib/Driver/ToolChains/FreeBSD.cpp
@@ -133,6 +133,7 @@ void freebsd::Linker::ConstructJob(Compilation , const 
JobAction ,
const char *LinkingOutput) const {
   const auto  = static_cast(getToolChain());
   const Driver  = ToolChain.getDriver();
+  const llvm::Triple  = ToolChain.getTriple();
   const llvm::Triple::ArchType Arch = ToolChain.getArch();
   const bool IsPIE =
   !Args.hasArg(options::OPT_shared) &&
@@ -165,8 +166,7 @@ void freebsd::Linker::ConstructJob(Compilation , const 
JobAction ,
   CmdArgs.push_back("-dynamic-linker");
   CmdArgs.push_back("/libexec/ld-elf.so.1");
 }
-const llvm::Triple  = ToolChain.getTriple();
-if (Arch == llvm::Triple::arm || T.isX86())
+if (Arch == llvm::Triple::arm || Triple.isX86())
   CmdArgs.push_back("--hash-style=both");
 CmdArgs.push_back("--enable-new-dtags");
   }
@@ -212,12 +212,17 @@ void freebsd::Linker::ConstructJob(Compilation , const 
JobAction ,
   case llvm::Triple::riscv64:
 CmdArgs.push_back("-m");
 CmdArgs.push_back("elf64lriscv");
-CmdArgs.push_back("-X");
 break;
   default:
 break;
   }
 
+  if (Triple.isRISCV64()) {
+CmdArgs.push_back("-X");
+if (Args.hasArg(options::OPT_mno_relax))
+  CmdArgs.push_back("--no-relax");
+  }
+
   if (Arg *A = Args.getLastArg(options::OPT_G)) {
 if (ToolChain.getTriple().isMIPS()) {
   StringRef v = A->getValue();
diff --git a/clang/lib/Driver/ToolChains/Haiku.cpp 
b/clang/lib/Driver/ToolChains/Haiku.cpp
index e0d94035823fd3..6919a8dd0dbeaf 100644
--- a/clang/lib/Driver/ToolChains/Haiku.cpp
+++ b/clang/lib/Driver/ToolChains/Haiku.cpp
@@ -25,7 +25,7 @@ void haiku::Linker::ConstructJob(Compilation , const 
JobAction ,
const char *LinkingOutput) const {
   const auto  = static_cast(getToolChain());
   const Driver  = ToolChain.getDriver();
-  const llvm::Triple::ArchType Arch = ToolChain.getArch();
+  const llvm::Triple  = ToolChain.getTriple();
   const bool Static = Args.hasArg(options::OPT_static);
   const bool Shared = Args.hasArg(options::OPT_shared);
   ArgStringList CmdArgs;
@@ -61,8 +61,11 @@ void haiku::Linker::ConstructJob(Compilation , const 
JobAction ,
   if (!Shared)
 CmdArgs.push_back("--no-undefined");
 
-  if (Arch == llvm::Triple::riscv64)
+  if (Triple.isRISCV64()) {
 CmdArgs.push_back("-X");
+if (Args.hasArg(options::OPT_mno_relax))
+ CmdArgs.push_back("--no-relax");
+  }
 
   assert((Output.isFilename() || Output.isNothing()) && "Invalid output.");
   if (Output.isFilename()) {
diff --git a/clang/lib/Driver/ToolChains/NetBSD.cpp 
b/clang/lib/Driver/ToolChains/NetBSD.cpp
index 240bf5764b9cce..556fc61556461d 100644
--- a/clang/lib/Driver/ToolChains/NetBSD.cpp
+++ b/clang/lib/Driver/ToolChains/NetBSD.cpp
@@ -240,8 +240,11 @@ void netbsd::Linker::ConstructJob(Compilation , const 
JobAction ,
 break;
   }
 
-  if (Triple.isRISCV())
+  if (Triple.isRISCV()) {
 CmdArgs.push_back("-X");
+if (Args.hasArg(options::OPT_mno_relax))
+  CmdArgs.push_back("--no-relax");
+  }
 
   assert((Output.isFilename() || Output.isNothing()) && "Invalid output.");
   if (Output.isFilename()) {
diff --git a/clang/lib/Driver/ToolChains/OpenBSD.cpp 
b/clang/lib/Driver/ToolChains/OpenBSD.cpp
index fd6aa4d7e68447..0a93f713b08af1 100644
--- a/clang/lib/Driver/ToolChains/OpenBSD.cpp
+++ b/clang/lib/Driver/ToolChains/OpenBSD.cpp
@@ -111,6 +111,7 @@ void openbsd::Linker::ConstructJob(Compilation , const 
JobAction ,
const char *LinkingOutput) const {
   const auto  = static_cast(getToolChain());
   const Driver  = ToolChain.getDriver();
+  const llvm::Triple  = ToolChain.getTriple();
   const llvm::Triple::ArchType Arch = ToolChain.getArch();
   const bool Static = Args.hasArg(options::OPT_static);
   const bool Shared = Args.hasArg(options::OPT_shared);
@@ -160,8 +161,11 @@ void openbsd::Linker::ConstructJob(Compilation , const 
JobAction ,
   if (Nopie || Profiling)
 CmdArgs.push_back("-nopie");
 
-  if (Arch == 

[clang] [clang][dataflow] Correctly treat empty initializer lists for unions. (PR #82986)

2024-02-27 Thread Yitzhak Mandelbaum via cfe-commits


@@ -2392,14 +2392,88 @@ TEST(TransferTest, InitListExprAsUnion) {
   } F;
 
  public:
-  constexpr target() : F{nullptr} {}
+  constexpr target() : F{nullptr} {
+int *null = nullptr;
+F.b;  // Make sure we reference 'b' so it is modeled.
+// [[p]]
+  }
 };
   )cc";
   runDataflow(
   Code,
   [](const llvm::StringMap> ,
  ASTContext ) {
-// Just verify that it doesn't crash.
+const Environment  = getEnvironmentAtAnnotation(Results, "p");
+
+auto  = getFieldLoc(
+*Env.getThisPointeeStorageLocation(), "F", ASTCtx);
+auto *AVal = cast(getFieldValue(, "a", ASTCtx, 
Env));
+EXPECT_EQ(AVal, (ASTCtx, Env, "null"));
+EXPECT_EQ(getFieldValue(, "b", ASTCtx, Env), nullptr);
+  });
+}
+
+TEST(TransferTest, EmptyInitListExprForUnion) {
+  // This is a crash repro.
+  std::string Code = R"cc(
+class target {
+  union {
+int *a;
+bool *b;
+  } F;
+
+ public:
+  constexpr target() : F{} {
+int *null = nullptr;
+F.b;  // Make sure we reference 'b' so it is modeled.
+// [[p]]
+  }
+};
+  )cc";
+  runDataflow(
+  Code,
+  [](const llvm::StringMap> ,
+ ASTContext ) {
+const Environment  = getEnvironmentAtAnnotation(Results, "p");
+
+auto  = getFieldLoc(
+*Env.getThisPointeeStorageLocation(), "F", ASTCtx);
+auto *AVal = cast(getFieldValue(, "a", ASTCtx, 
Env));
+EXPECT_EQ(AVal, (ASTCtx, Env, "null"));
+EXPECT_EQ(getFieldValue(, "b", ASTCtx, Env), nullptr);
+  });
+}
+
+TEST(TransferTest, EmptyInitListExprForStruct) {
+  std::string Code = R"cc(
+class target {
+  struct {
+int *a;
+bool *b;
+  } F;
+
+ public:
+  constexpr target() : F{} {
+int *NullIntPtr = nullptr;
+bool *NullBoolPtr = nullptr;
+// [[p]]
+  }
+};
+  )cc";
+  runDataflow(
+  Code,
+  [](const llvm::StringMap> ,
+ ASTContext ) {
+const Environment  = getEnvironmentAtAnnotation(Results, "p");
+
+auto  = getFieldLoc(
+*Env.getThisPointeeStorageLocation(), "F", ASTCtx);
+auto *AVal = cast(getFieldValue(, "a", ASTCtx, 
Env));
+ASSERT_EQ(AVal,

ymand wrote:

why ASSERT (vs EXPECT,  like above)?

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


[clang] [clang][dataflow] Correctly treat empty initializer lists for unions. (PR #82986)

2024-02-27 Thread Yitzhak Mandelbaum via cfe-commits


@@ -2392,14 +2392,88 @@ TEST(TransferTest, InitListExprAsUnion) {
   } F;
 
  public:
-  constexpr target() : F{nullptr} {}
+  constexpr target() : F{nullptr} {
+int *null = nullptr;
+F.b;  // Make sure we reference 'b' so it is modeled.
+// [[p]]
+  }
 };
   )cc";
   runDataflow(
   Code,
   [](const llvm::StringMap> ,
  ASTContext ) {
-// Just verify that it doesn't crash.
+const Environment  = getEnvironmentAtAnnotation(Results, "p");
+
+auto  = getFieldLoc(
+*Env.getThisPointeeStorageLocation(), "F", ASTCtx);
+auto *AVal = cast(getFieldValue(, "a", ASTCtx, 
Env));
+EXPECT_EQ(AVal, (ASTCtx, Env, "null"));
+EXPECT_EQ(getFieldValue(, "b", ASTCtx, Env), nullptr);
+  });
+}
+
+TEST(TransferTest, EmptyInitListExprForUnion) {
+  // This is a crash repro.
+  std::string Code = R"cc(
+class target {
+  union {
+int *a;
+bool *b;
+  } F;
+
+ public:
+  constexpr target() : F{} {
+int *null = nullptr;
+F.b;  // Make sure we reference 'b' so it is modeled.
+// [[p]]
+  }
+};
+  )cc";
+  runDataflow(
+  Code,
+  [](const llvm::StringMap> ,
+ ASTContext ) {
+const Environment  = getEnvironmentAtAnnotation(Results, "p");
+
+auto  = getFieldLoc(
+*Env.getThisPointeeStorageLocation(), "F", ASTCtx);
+auto *AVal = cast(getFieldValue(, "a", ASTCtx, 
Env));

ymand wrote:

Why is `a` set when the initializer is empty? I'm guessing it's because line 
699 in Transfer.cpp uses `front()` and so initializes the first field of the 
union. If so, perhaps say this explicitly in the comment preceding those lines?

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


[clang] [clang][dataflow] Correctly treat empty initializer lists for unions. (PR #82986)

2024-02-27 Thread Yitzhak Mandelbaum via cfe-commits

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


[clang] [clang][dataflow] Correctly treat empty initializer lists for unions. (PR #82986)

2024-02-27 Thread Yitzhak Mandelbaum via cfe-commits

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


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


[clang] [HIP] fix host min/max in header (PR #82956)

2024-02-27 Thread Yaxun Liu via cfe-commits


@@ -1306,15 +1306,73 @@ float min(float __x, float __y) { return 
__builtin_fminf(__x, __y); }
 __DEVICE__
 double min(double __x, double __y) { return __builtin_fmin(__x, __y); }
 
-#if !defined(__HIPCC_RTC__) && !defined(__OPENMP_AMDGCN__)
-__host__ inline static int min(int __arg1, int __arg2) {
-  return __arg1 < __arg2 ? __arg1 : __arg2;
+// Define host min/max functions.
+#if !defined(__HIPCC_RTC__) && !defined(__OPENMP_AMDGCN__) &&  
\
+!defined(__HIP_NO_HOST_MIN_MAX_IN_GLOBAL_NAMESPACE__)
+
+#pragma push_macro("DEFINE_MIN_MAX_FUNCTIONS")
+#pragma push_macro("DEFINE_MIN_MAX_FUNCTIONS")
+#define DEFINE_MIN_MAX_FUNCTIONS(ret_type, type1, type2)   
\
+  inline ret_type min(const type1 __a, const type2 __b) {  
\
+return (__a < __b) ? __a : __b;
\
+  }
\
+  inline ret_type max(const type1 __a, const type2 __b) {  
\
+return (__a > __b) ? __a : __b;
\
+  }
+
+// Define min and max functions for same type comparisons
+DEFINE_MIN_MAX_FUNCTIONS(int, int, int)
+DEFINE_MIN_MAX_FUNCTIONS(unsigned int, unsigned int, unsigned int)
+DEFINE_MIN_MAX_FUNCTIONS(long, long, long)
+DEFINE_MIN_MAX_FUNCTIONS(unsigned long, unsigned long, unsigned long)
+DEFINE_MIN_MAX_FUNCTIONS(long long, long long, long long)
+DEFINE_MIN_MAX_FUNCTIONS(unsigned long long, unsigned long long,
+ unsigned long long)
+
+// CUDA defines host min/max functions with mixed signed/unsgined integer
+// parameters where signed integers are casted to unsigned integers. However,
+// this may not be users' intention. Therefore do not define them by default
+// unless users specify -D__HIP_DEFINE_MIXED_HOST_MIN_MAX__.

yxsamliu wrote:

I reverted this PR due to regression in hipCUB:

https://github.com/ROCm/hipCUB/blob/develop/hipcub/include/hipcub/backend/rocprim/device/device_spmv.hpp#L142

hipCUB/hipcub/include/hipcub/backend/rocprim/device/device_spmv.hpp:142:33: 
error: call to 'min' is ambiguous

it is a call of min(int, unsigned int). The code is likely ported from CUDA.

Probably I need to define those functions with mixed args by default to avoid 
regressions.

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


[clang] [Driver] Allow -fbasic-block-address-map for AArch64 ELF (PR #82662)

2024-02-27 Thread Daniel Hoekwater via cfe-commits

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


[clang] e9e7aea - [Driver] Allow -fbasic-block-address-map for AArch64 ELF (#82662)

2024-02-27 Thread via cfe-commits

Author: Daniel Hoekwater
Date: 2024-02-27T17:34:48-08:00
New Revision: e9e7aeadaf0ce9d66ff352856fd2d1005b0f7d74

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

LOG: [Driver] Allow -fbasic-block-address-map for AArch64 ELF (#82662)

Emitting the basic block address map with
`-fbasic-block-sections=labels` is allowed for AArch64 ELF since
7eaf94fefa1250fc8a46982cea8ce99abacae11f. Allow doing so with
`-fbasic-block-address-map`.

Added: 


Modified: 
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/basic-block-address-map.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 6e1b7e8657d0dc..66c3a237c12117 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -5958,7 +5958,7 @@ void Clang::ConstructJob(Compilation , const JobAction 
,
 
   if (Arg *A = Args.getLastArg(options::OPT_fbasic_block_address_map,
options::OPT_fno_basic_block_address_map)) {
-if (Triple.isX86() && Triple.isOSBinFormatELF()) {
+if ((Triple.isX86() || Triple.isAArch64()) && Triple.isOSBinFormatELF()) {
   if (A->getOption().matches(options::OPT_fbasic_block_address_map))
 A->render(Args, CmdArgs);
 } else {

diff  --git a/clang/test/Driver/basic-block-address-map.c 
b/clang/test/Driver/basic-block-address-map.c
index 022f972b412d6b..12393e8ebfd54e 100644
--- a/clang/test/Driver/basic-block-address-map.c
+++ b/clang/test/Driver/basic-block-address-map.c
@@ -1,8 +1,9 @@
-// RUN: %clang -### -target x86_64 -fbasic-block-address-map %s -S 2>&1 | 
FileCheck -check-prefix=CHECK-PRESENT %s
+// RUN: %clang -### --target=x86_64 -fbasic-block-address-map %s -S 2>&1 | 
FileCheck -check-prefix=CHECK-PRESENT %s
+// RUN: %clang -### --target=aarch64 -fbasic-block-address-map %s -S 2>&1 | 
FileCheck -check-prefix=CHECK-PRESENT %s
 // CHECK-PRESENT: -fbasic-block-address-map
 
-// RUN: %clang -### -target x86_64 -fno-basic-block-address-map %s -S 2>&1 | 
FileCheck %s --check-prefix=CHECK-ABSENT
+// RUN: %clang -### --target=x86_64 -fno-basic-block-address-map %s -S 2>&1 | 
FileCheck %s --check-prefix=CHECK-ABSENT
 // CHECK-ABSENT-NOT: -fbasic-block-address-map
 
-// RUN: not %clang -c -target x86_64-apple-darwin10 -fbasic-block-address-map 
%s -S 2>&1 | FileCheck -check-prefix=CHECK-TRIPLE %s
+// RUN: not %clang -c --target=x86_64-apple-darwin10 -fbasic-block-address-map 
%s -S 2>&1 | FileCheck -check-prefix=CHECK-TRIPLE %s
 // CHECK-TRIPLE: error: unsupported option '-fbasic-block-address-map' for 
target



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


[clang] [Clang][Sema] Fix missing warning when comparing mismatched enums in … (PR #81418)

2024-02-27 Thread Nathan Chancellor via cfe-commits

nathanchance wrote:

For what it's worth, this change adds several instances of 
`-Wenum-enum-conversion` for the Linux kernel: 
https://github.com/ClangBuiltLinux/linux/issues/2002. I assume this is 
intentional given the nature of the change as a whole but neither the tests nor 
the release notes seem to really reflect that. In case it is a bug that this 
change affected that, consider this a report :)

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


[clang] [InstallAPI] Hookup Input files & basic ASTVisitor (PR #82552)

2024-02-27 Thread Cyndy Ishida via cfe-commits

https://github.com/cyndyishida updated 
https://github.com/llvm/llvm-project/pull/82552

>From b0cc1eeba893c24d5358cb49189da2e287daf972 Mon Sep 17 00:00:00 2001
From: Cyndy Ishida 
Date: Wed, 21 Feb 2024 14:56:02 -0800
Subject: [PATCH 1/2] [InstallAPI] Hookup Input files & basic ASTVisitor

This patch takes in json files as input to determine that header files to 
process, and in which order, to pass along for CC1 invocations.
This patch also includes an ASTVisitor to collect simple global variables.
---
 clang/include/clang/InstallAPI/Context.h  | 22 -
 clang/include/clang/InstallAPI/Frontend.h | 48 ++
 clang/include/clang/InstallAPI/HeaderFile.h   | 23 +
 clang/include/clang/InstallAPI/Visitor.h  | 51 ++
 clang/lib/InstallAPI/CMakeLists.txt   |  3 +
 clang/lib/InstallAPI/Frontend.cpp | 58 
 clang/lib/InstallAPI/Visitor.cpp  | 94 +++
 clang/test/InstallAPI/basic.test  |  5 +
 clang/test/InstallAPI/variables.test  | 63 +
 .../clang-installapi/ClangInstallAPI.cpp  | 78 +--
 clang/tools/clang-installapi/Options.cpp  | 29 ++
 clang/tools/clang-installapi/Options.h|  8 ++
 12 files changed, 474 insertions(+), 8 deletions(-)
 create mode 100644 clang/include/clang/InstallAPI/Frontend.h
 create mode 100644 clang/include/clang/InstallAPI/Visitor.h
 create mode 100644 clang/lib/InstallAPI/Frontend.cpp
 create mode 100644 clang/lib/InstallAPI/Visitor.cpp
 create mode 100644 clang/test/InstallAPI/variables.test

diff --git a/clang/include/clang/InstallAPI/Context.h 
b/clang/include/clang/InstallAPI/Context.h
index 7d105920734fde..292992908aa129 100644
--- a/clang/include/clang/InstallAPI/Context.h
+++ b/clang/include/clang/InstallAPI/Context.h
@@ -9,6 +9,9 @@
 #ifndef LLVM_CLANG_INSTALLAPI_CONTEXT_H
 #define LLVM_CLANG_INSTALLAPI_CONTEXT_H
 
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/FileManager.h"
+#include "clang/InstallAPI/HeaderFile.h"
 #include "llvm/TextAPI/InterfaceFile.h"
 #include "llvm/TextAPI/RecordVisitor.h"
 #include "llvm/TextAPI/RecordsSlice.h"
@@ -24,8 +27,23 @@ struct InstallAPIContext {
   /// Library attributes that are typically passed as linker inputs.
   llvm::MachO::RecordsSlice::BinaryAttrs BA;
 
-  /// Active target triple to parse.
-  llvm::Triple TargetTriple{};
+  /// All headers that represent a library.
+  HeaderSeq InputHeaders;
+
+  /// Active language mode to parse in.
+  Language LangMode = Language::ObjC;
+
+  /// Active header access type.
+  HeaderType Type = HeaderType::Unknown;
+
+  /// Active TargetSlice for symbol record collection.
+  std::shared_ptr Records;
+
+  /// FileManager for all I/O operations.
+  FileManager *FM = nullptr;
+
+  /// DiagnosticsEngine for all error reporting.
+  DiagnosticsEngine *Diags = nullptr;
 
   /// File Path of output location.
   llvm::StringRef OutputLoc{};
diff --git a/clang/include/clang/InstallAPI/Frontend.h 
b/clang/include/clang/InstallAPI/Frontend.h
new file mode 100644
index 00..7ee87ae028d079
--- /dev/null
+++ b/clang/include/clang/InstallAPI/Frontend.h
@@ -0,0 +1,48 @@
+//===- InstallAPI/Frontend.h ---*- 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
+//
+//===--===//
+///
+/// Top level wrappers for InstallAPI frontend operations.
+///
+//===--===//
+
+#ifndef LLVM_CLANG_INSTALLAPI_FRONTEND_H
+#define LLVM_CLANG_INSTALLAPI_FRONTEND_H
+
+#include "clang/AST/ASTConsumer.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Frontend/FrontendActions.h"
+#include "clang/InstallAPI/Context.h"
+#include "clang/InstallAPI/Visitor.h"
+#include "llvm/ADT/Twine.h"
+#include "llvm/Support/MemoryBuffer.h"
+
+namespace clang {
+namespace installapi {
+
+/// Create a buffer that contains all headers to scan
+/// for global symbols with.
+std::unique_ptr
+createInputBuffer(const InstallAPIContext );
+
+class InstallAPIAction : public ASTFrontendAction {
+public:
+  explicit InstallAPIAction(llvm::MachO::RecordsSlice )
+  : Records(Records) {}
+
+  std::unique_ptr CreateASTConsumer(CompilerInstance ,
+ StringRef InFile) override {
+return std::make_unique(CI.getASTContext(), Records);
+  }
+
+private:
+  llvm::MachO::RecordsSlice 
+};
+} // namespace installapi
+} // namespace clang
+
+#endif // LLVM_CLANG_INSTALLAPI_FRONTEND_H
diff --git a/clang/include/clang/InstallAPI/HeaderFile.h 
b/clang/include/clang/InstallAPI/HeaderFile.h
index fc64a43b3def5c..70e83bbb3e76f6 100644
--- a/clang/include/clang/InstallAPI/HeaderFile.h
+++ 

[clang] [LLVM][DWARF] Enable pubnames for -glldb when expliti flag is passed (PR #83206)

2024-02-27 Thread Alexander Yermolovich via cfe-commits

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


[clang] Revert "[CLANG][DWARF] Do not emit -ggnu-pubnames for split dwarf version 5." (PR #83214)

2024-02-27 Thread Alexander Yermolovich via cfe-commits

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


[clang] dba2dd2 - Revert "[CLANG][DWARF] Do not emit -ggnu-pubnames for split dwarf version 5." (#83214)

2024-02-27 Thread via cfe-commits

Author: Alexander Yermolovich
Date: 2024-02-27T17:26:06-08:00
New Revision: dba2dd2c487d7bed7ad3b76a67fdfce464f0edbf

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

LOG: Revert "[CLANG][DWARF] Do not emit -ggnu-pubnames for split dwarf version 
5." (#83214)

Reverts llvm/llvm-project#82840

Added: 


Modified: 
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/split-debug.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index dbfc729bba24c7..6e1b7e8657d0dc 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -4479,10 +4479,9 @@ renderDebugOptions(const ToolChain , const Driver , 
const llvm::Triple ,
   options::OPT_gpubnames, options::OPT_gno_pubnames);
   if (DwarfFission != DwarfFissionKind::None ||
   (PubnamesArg && checkDebugInfoOption(PubnamesArg, Args, D, TC)))
-if (DebuggerTuning != llvm::DebuggerKind::LLDB &&
-(!PubnamesArg ||
- (!PubnamesArg->getOption().matches(options::OPT_gno_gnu_pubnames) &&
-  !PubnamesArg->getOption().matches(options::OPT_gno_pubnames
+if (!PubnamesArg ||
+(!PubnamesArg->getOption().matches(options::OPT_gno_gnu_pubnames) &&
+ !PubnamesArg->getOption().matches(options::OPT_gno_pubnames)))
   CmdArgs.push_back(PubnamesArg && PubnamesArg->getOption().matches(
options::OPT_gpubnames)
 ? "-gpubnames"

diff  --git a/clang/test/Driver/split-debug.c b/clang/test/Driver/split-debug.c
index a2a3dc02354503..968f33b4cc035c 100644
--- a/clang/test/Driver/split-debug.c
+++ b/clang/test/Driver/split-debug.c
@@ -124,8 +124,3 @@
 // G1_NOSPLIT: "-debug-info-kind=line-tables-only"
 // G1_NOSPLIT-NOT: "-split-dwarf-file"
 // G1_NOSPLIT-NOT: "-split-dwarf-output"
-
-/// Do not generate -ggnu-pubnames for -glldb
-// RUN: %clang -### -c -target x86_64 -gsplit-dwarf -g -glldb %s 2>&1 | 
FileCheck %s --check-prefixes=GLLDBSPLIT
-
-// GLLDBSPLIT-NOT: "-ggnu-pubnames"



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


[clang] bcbce80 - Revert "[HIP] fix host min/max in header (#82956)"

2024-02-27 Thread Yaxun Liu via cfe-commits

Author: Yaxun (Sam) Liu
Date: 2024-02-27T20:19:07-05:00
New Revision: bcbce807d76a30388b366d14051c5f80e9724dab

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

LOG: Revert "[HIP] fix host min/max in header (#82956)"

This reverts commit 55783bd0f9cfc30aa93c718919dab5419d86a2c6.

Due to regressions in hipCUB.

hipCUB/hipcub/include/hipcub/backend/rocprim/device/device_spmv.hpp:142:33: 
error: call to 'min' is ambiguous

https://github.com/ROCm/hipCUB/blob/develop/hipcub/include/hipcub/backend/rocprim/device/device_spmv.hpp#L142

The ambuguity seems due to missing min(int, unsigned int).

Previously, there is only min(int, int). After the change,
there are min(int, int) and min(unsigned int, unsigned int),
therefore there is ambiguity.

Added: 


Modified: 
clang/lib/Headers/__clang_hip_math.h

Removed: 




diff  --git a/clang/lib/Headers/__clang_hip_math.h 
b/clang/lib/Headers/__clang_hip_math.h
index 34d1de0a060055..11e1e7d032586f 100644
--- a/clang/lib/Headers/__clang_hip_math.h
+++ b/clang/lib/Headers/__clang_hip_math.h
@@ -1306,75 +1306,15 @@ float min(float __x, float __y) { return 
__builtin_fminf(__x, __y); }
 __DEVICE__
 double min(double __x, double __y) { return __builtin_fmin(__x, __y); }
 
-// Define host min/max functions.
-#if !defined(__HIPCC_RTC__) && !defined(__OPENMP_AMDGCN__) &&  
\
-!defined(__HIP_NO_HOST_MIN_MAX_IN_GLOBAL_NAMESPACE__)
-
-#pragma push_macro("DEFINE_MIN_MAX_FUNCTIONS")
-#pragma push_macro("DEFINE_MIN_MAX_FUNCTIONS")
-#define DEFINE_MIN_MAX_FUNCTIONS(ret_type, type1, type2)   
\
-  inline ret_type min(const type1 __a, const type2 __b) {  
\
-return (__a < __b) ? __a : __b;
\
-  }
\
-  inline ret_type max(const type1 __a, const type2 __b) {  
\
-return (__a > __b) ? __a : __b;
\
-  }
-
-// Define min and max functions for same type comparisons
-DEFINE_MIN_MAX_FUNCTIONS(int, int, int)
-DEFINE_MIN_MAX_FUNCTIONS(unsigned int, unsigned int, unsigned int)
-DEFINE_MIN_MAX_FUNCTIONS(long, long, long)
-DEFINE_MIN_MAX_FUNCTIONS(unsigned long, unsigned long, unsigned long)
-DEFINE_MIN_MAX_FUNCTIONS(long long, long long, long long)
-DEFINE_MIN_MAX_FUNCTIONS(unsigned long long, unsigned long long,
- unsigned long long)
-
-// The host min/max functions below accept mixed signed/unsigned integer
-// parameters and perform unsigned comparisons, which may produce unexpected
-// results if a signed integer was passed unintentionally. To avoid this
-// happening silently, these overloaded functions are not defined by default.
-// However, for compatibility with CUDA, they will be defined if users define
-// __HIP_DEFINE_MIXED_HOST_MIN_MAX__.
-#ifdef __HIP_DEFINE_MIXED_HOST_MIN_MAX__
-DEFINE_MIN_MAX_FUNCTIONS(unsigned int, int, unsigned int)
-DEFINE_MIN_MAX_FUNCTIONS(unsigned int, unsigned int, int)
-DEFINE_MIN_MAX_FUNCTIONS(unsigned long, long, unsigned long)
-DEFINE_MIN_MAX_FUNCTIONS(unsigned long, unsigned long, long)
-DEFINE_MIN_MAX_FUNCTIONS(unsigned long long, long long, unsigned long long)
-DEFINE_MIN_MAX_FUNCTIONS(unsigned long long, unsigned long long, long long)
-#endif // ifdef __HIP_DEFINE_MIXED_HOST_MIN_MAX__
-
-// Floating-point comparisons using built-in functions
-inline float min(float const __a, float const __b) {
-  return __builtin_fminf(__a, __b);
-}
-inline double min(double const __a, double const __b) {
-  return __builtin_fmin(__a, __b);
-}
-inline double min(float const __a, double const __b) {
-  return __builtin_fmin(__a, __b);
-}
-inline double min(double const __a, float const __b) {
-  return __builtin_fmin(__a, __b);
+#if !defined(__HIPCC_RTC__) && !defined(__OPENMP_AMDGCN__)
+__host__ inline static int min(int __arg1, int __arg2) {
+  return __arg1 < __arg2 ? __arg1 : __arg2;
 }
 
-inline float max(float const __a, float const __b) {
-  return __builtin_fmaxf(__a, __b);
-}
-inline double max(double const __a, double const __b) {
-  return __builtin_fmax(__a, __b);
-}
-inline double max(float const __a, double const __b) {
-  return __builtin_fmax(__a, __b);
+__host__ inline static int max(int __arg1, int __arg2) {
+  return __arg1 > __arg2 ? __arg1 : __arg2;
 }
-inline double max(double const __a, float const __b) {
-  return __builtin_fmax(__a, __b);
-}
-
-#pragma pop_macro("DEFINE_MIN_MAX_FUNCTIONS")
-
-#endif // !defined(__HIPCC_RTC__) && !defined(__OPENMP_AMDGCN__) &&
-   // !defined(__HIP_NO_HOST_MIN_MAX_IN_GLOBAL_NAMESPACE__)
+#endif // !defined(__HIPCC_RTC__) && !defined(__OPENMP_AMDGCN__)
 #endif
 
 #pragma pop_macro("__DEVICE__")




[clang] Revert "[CLANG][DWARF] Do not emit -ggnu-pubnames for split dwarf version 5." (PR #83214)

2024-02-27 Thread Fangrui Song via cfe-commits

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


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


[clang] [Clang][HTO] Add clang attribute for propagating llvm-level information (PR #83059)

2024-02-27 Thread William Moses via cfe-commits

wsmoses wrote:

Okay, the AnnotateAttr doesn't create LLVM string attributes, it creates LLVM 
metadata, but that should sufice, closing.

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


[clang] [Clang][HTO] Add clang attribute for propagating llvm-level information (PR #83059)

2024-02-27 Thread William Moses via cfe-commits

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


[clang] Revert "[CLANG][DWARF] Do not emit -ggnu-pubnames for split dwarf version 5." (PR #83214)

2024-02-27 Thread via cfe-commits

github-actions[bot] wrote:

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


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


[clang] Revert "[CLANG][DWARF] Do not emit -ggnu-pubnames for split dwarf version 5." (PR #83214)

2024-02-27 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-driver

Author: Alexander Yermolovich (ayermolo)


Changes

Reverts llvm/llvm-project#82840

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


2 Files Affected:

- (modified) clang/lib/Driver/ToolChains/Clang.cpp (+3-4) 
- (modified) clang/test/Driver/split-debug.c (-5) 


``diff
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index dbfc729bba24c76..6e1b7e8657d0dc9 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -4479,10 +4479,9 @@ renderDebugOptions(const ToolChain , const Driver , 
const llvm::Triple ,
   options::OPT_gpubnames, options::OPT_gno_pubnames);
   if (DwarfFission != DwarfFissionKind::None ||
   (PubnamesArg && checkDebugInfoOption(PubnamesArg, Args, D, TC)))
-if (DebuggerTuning != llvm::DebuggerKind::LLDB &&
-(!PubnamesArg ||
- (!PubnamesArg->getOption().matches(options::OPT_gno_gnu_pubnames) &&
-  !PubnamesArg->getOption().matches(options::OPT_gno_pubnames
+if (!PubnamesArg ||
+(!PubnamesArg->getOption().matches(options::OPT_gno_gnu_pubnames) &&
+ !PubnamesArg->getOption().matches(options::OPT_gno_pubnames)))
   CmdArgs.push_back(PubnamesArg && PubnamesArg->getOption().matches(
options::OPT_gpubnames)
 ? "-gpubnames"
diff --git a/clang/test/Driver/split-debug.c b/clang/test/Driver/split-debug.c
index a2a3dc023545034..968f33b4cc035c5 100644
--- a/clang/test/Driver/split-debug.c
+++ b/clang/test/Driver/split-debug.c
@@ -124,8 +124,3 @@
 // G1_NOSPLIT: "-debug-info-kind=line-tables-only"
 // G1_NOSPLIT-NOT: "-split-dwarf-file"
 // G1_NOSPLIT-NOT: "-split-dwarf-output"
-
-/// Do not generate -ggnu-pubnames for -glldb
-// RUN: %clang -### -c -target x86_64 -gsplit-dwarf -g -glldb %s 2>&1 | 
FileCheck %s --check-prefixes=GLLDBSPLIT
-
-// GLLDBSPLIT-NOT: "-ggnu-pubnames"

``




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


[clang] [LLVM][DWARF] Enable pubnames for -glldb when expliti flag is passed (PR #83206)

2024-02-27 Thread Alexander Yermolovich via cfe-commits

ayermolo wrote:

revert https://github.com/llvm/llvm-project/pull/83214

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


[clang] Revert "[CLANG][DWARF] Do not emit -ggnu-pubnames for split dwarf version 5." (PR #83214)

2024-02-27 Thread Alexander Yermolovich via cfe-commits

https://github.com/ayermolo created 
https://github.com/llvm/llvm-project/pull/83214

Reverts llvm/llvm-project#82840

>From 58007120dfbc69ccfdf04ae1eb71b30e3582b435 Mon Sep 17 00:00:00 2001
From: Alexander Yermolovich <43973793+ayerm...@users.noreply.github.com>
Date: Tue, 27 Feb 2024 16:40:45 -0800
Subject: [PATCH] =?UTF-8?q?Revert=20"[CLANG][DWARF]=20Do=20not=20emit=20-g?=
 =?UTF-8?q?gnu-pubnames=20for=20split=20dwarf=20version=205.=20=E2=80=A6"?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This reverts commit b3ae6c205e4afcf1a9f7d7204a659a27ca700237.
---
 clang/lib/Driver/ToolChains/Clang.cpp | 7 +++
 clang/test/Driver/split-debug.c   | 5 -
 2 files changed, 3 insertions(+), 9 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index dbfc729bba24c76..6e1b7e8657d0dc9 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -4479,10 +4479,9 @@ renderDebugOptions(const ToolChain , const Driver , 
const llvm::Triple ,
   options::OPT_gpubnames, options::OPT_gno_pubnames);
   if (DwarfFission != DwarfFissionKind::None ||
   (PubnamesArg && checkDebugInfoOption(PubnamesArg, Args, D, TC)))
-if (DebuggerTuning != llvm::DebuggerKind::LLDB &&
-(!PubnamesArg ||
- (!PubnamesArg->getOption().matches(options::OPT_gno_gnu_pubnames) &&
-  !PubnamesArg->getOption().matches(options::OPT_gno_pubnames
+if (!PubnamesArg ||
+(!PubnamesArg->getOption().matches(options::OPT_gno_gnu_pubnames) &&
+ !PubnamesArg->getOption().matches(options::OPT_gno_pubnames)))
   CmdArgs.push_back(PubnamesArg && PubnamesArg->getOption().matches(
options::OPT_gpubnames)
 ? "-gpubnames"
diff --git a/clang/test/Driver/split-debug.c b/clang/test/Driver/split-debug.c
index a2a3dc023545034..968f33b4cc035c5 100644
--- a/clang/test/Driver/split-debug.c
+++ b/clang/test/Driver/split-debug.c
@@ -124,8 +124,3 @@
 // G1_NOSPLIT: "-debug-info-kind=line-tables-only"
 // G1_NOSPLIT-NOT: "-split-dwarf-file"
 // G1_NOSPLIT-NOT: "-split-dwarf-output"
-
-/// Do not generate -ggnu-pubnames for -glldb
-// RUN: %clang -### -c -target x86_64 -gsplit-dwarf -g -glldb %s 2>&1 | 
FileCheck %s --check-prefixes=GLLDBSPLIT
-
-// GLLDBSPLIT-NOT: "-ggnu-pubnames"

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


[clang] [LLVM][DWARF] Enable pubnames for -glldb when expliti flag is passed (PR #83206)

2024-02-27 Thread Alexander Yermolovich via cfe-commits

ayermolo wrote:

> I don't know if this is correct.
> 
> Maybe just add a triple to the problematic clang invocation for now and have 
> this reviewed by a local expert while trunk isn't broken?

ok

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


[clang] [Clang][DebugInfo] Use CGDebugInfo::createFile in CGDebugInfo::CreateCompileUnit (#83174) (PR #83175)

2024-02-27 Thread Adrian Prantl via cfe-commits


@@ -628,9 +628,8 @@ void CGDebugInfo::CreateCompileUnit() {
   // file was specified with an absolute path.
   if (CSKind)
 CSInfo.emplace(*CSKind, Checksum);
-  llvm::DIFile *CUFile = DBuilder.createFile(
-  remapDIPath(MainFileName), remapDIPath(getCurrentDirname()), CSInfo,
-  getSource(SM, SM.getMainFileID()));
+  llvm::DIFile *CUFile =
+  createFile(MainFileName, CSInfo, getSource(SM, SM.getMainFileID()));

adrian-prantl wrote:

Why is MainFileName no longer being remapped here?

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


[clang] [Clang][DebugInfo] Use CGDebugInfo::createFile in CGDebugInfo::CreateCompileUnit (#83174) (PR #83175)

2024-02-27 Thread Adrian Prantl via cfe-commits

https://github.com/adrian-prantl commented:

Can you add a test for this?

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


[clang] [LLVM][DWARF] Enable pubnames for -glldb when expliti flag is passed (PR #83206)

2024-02-27 Thread Nico Weber via cfe-commits

nico wrote:

I don't know if this is correct.

Maybe just add a triple to the problematic clang invocation for now and have 
this reviewed by a local expert while trunk isn't broken?

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


[clang] [llvm] [Clang] Correct __builtin_dynamic_object_size for subobject types (PR #83204)

2024-02-27 Thread Bill Wendling via cfe-commits

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


[clang] [CLANG][DWARF] Do not emit -ggnu-pubnames for split dwarf version 5. (PR #82840)

2024-02-27 Thread Alexander Yermolovich via cfe-commits

ayermolo wrote:

https://github.com/llvm/llvm-project/pull/83206

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


[clang] [LLVM][DWARF] Enable pubnames for -glldb when expliti flag is passed (PR #83206)

2024-02-27 Thread Alexander Yermolovich via cfe-commits

ayermolo wrote:

Test passes on mac
![image](https://github.com/llvm/llvm-project/assets/43973793/61f4843c-63b3-4bc7-ba1f-67ea41a59c44)


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


[clang] [LLVM][DWARF] Enable pubnames for -glldb when expliti flag is passed (PR #83206)

2024-02-27 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Alexander Yermolovich (ayermolo)


Changes

This is a fix for https://github.com/llvm/llvm-project/pull/82840. On mac
tunning is by default LLDB. If the flag was passed in to clang after that PR it
would not have been passed in by the driver.


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


2 Files Affected:

- (modified) clang/lib/Driver/ToolChains/Clang.cpp (+7-2) 
- (modified) clang/test/Driver/split-debug.c (+5) 


``diff
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index dbfc729bba24c7..7b38450d0720ef 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -4478,8 +4478,12 @@ renderDebugOptions(const ToolChain , const Driver , 
const llvm::Triple ,
   Args.getLastArg(options::OPT_ggnu_pubnames, 
options::OPT_gno_gnu_pubnames,
   options::OPT_gpubnames, options::OPT_gno_pubnames);
   if (DwarfFission != DwarfFissionKind::None ||
-  (PubnamesArg && checkDebugInfoOption(PubnamesArg, Args, D, TC)))
-if (DebuggerTuning != llvm::DebuggerKind::LLDB &&
+  (PubnamesArg && checkDebugInfoOption(PubnamesArg, Args, D, TC))) {
+const bool OptionSet =
+(PubnamesArg &&
+ (PubnamesArg->getOption().matches(options::OPT_gpubnames) ||
+  PubnamesArg->getOption().matches(options::OPT_ggnu_pubnames)));
+if ((DebuggerTuning != llvm::DebuggerKind::LLDB || OptionSet) &&
 (!PubnamesArg ||
  (!PubnamesArg->getOption().matches(options::OPT_gno_gnu_pubnames) &&
   !PubnamesArg->getOption().matches(options::OPT_gno_pubnames
@@ -4487,6 +4491,7 @@ renderDebugOptions(const ToolChain , const Driver , 
const llvm::Triple ,
options::OPT_gpubnames)
 ? "-gpubnames"
 : "-ggnu-pubnames");
+  }
   const auto *SimpleTemplateNamesArg =
   Args.getLastArg(options::OPT_gsimple_template_names,
   options::OPT_gno_simple_template_names);
diff --git a/clang/test/Driver/split-debug.c b/clang/test/Driver/split-debug.c
index a2a3dc02354503..57f3989ed7b510 100644
--- a/clang/test/Driver/split-debug.c
+++ b/clang/test/Driver/split-debug.c
@@ -129,3 +129,8 @@
 // RUN: %clang -### -c -target x86_64 -gsplit-dwarf -g -glldb %s 2>&1 | 
FileCheck %s --check-prefixes=GLLDBSPLIT
 
 // GLLDBSPLIT-NOT: "-ggnu-pubnames"
+
+/// Generate -ggnu-pubnames for -glldb when it is explicitly enabled
+// RUN: %clang -### -c -target x86_64 -gsplit-dwarf -g -glldb -ggnu-pubnames 
%s 2>&1 | FileCheck %s --check-prefixes=GLLDBSPLIT2
+
+// GLLDBSPLIT2: "-ggnu-pubnames"

``




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


[clang] [LLVM][DWARF] Enable pubnames for -glldb when expliti flag is passed (PR #83206)

2024-02-27 Thread Alexander Yermolovich via cfe-commits

https://github.com/ayermolo created 
https://github.com/llvm/llvm-project/pull/83206

This is a fix for https://github.com/llvm/llvm-project/pull/82840. On mac
tunning is by default LLDB. If the flag was passed in to clang after that PR it
would not have been passed in by the driver.


>From c7fb961e3a4dfa404187e62d32490c58977f212a Mon Sep 17 00:00:00 2001
From: Alexander Yermolovich 
Date: Tue, 27 Feb 2024 14:54:22 -0800
Subject: [PATCH] [LLVM][DWARF] Enable pubnames for -glldb when expliti flag is
 passed

This is a fix for https://github.com/llvm/llvm-project/pull/82840. On mac
tunning is by default LLDB. If the flag was passed in to clang after that PR it
would not have been passed in by the driver.
---
 clang/lib/Driver/ToolChains/Clang.cpp | 9 +++--
 clang/test/Driver/split-debug.c   | 5 +
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index dbfc729bba24c7..7b38450d0720ef 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -4478,8 +4478,12 @@ renderDebugOptions(const ToolChain , const Driver , 
const llvm::Triple ,
   Args.getLastArg(options::OPT_ggnu_pubnames, 
options::OPT_gno_gnu_pubnames,
   options::OPT_gpubnames, options::OPT_gno_pubnames);
   if (DwarfFission != DwarfFissionKind::None ||
-  (PubnamesArg && checkDebugInfoOption(PubnamesArg, Args, D, TC)))
-if (DebuggerTuning != llvm::DebuggerKind::LLDB &&
+  (PubnamesArg && checkDebugInfoOption(PubnamesArg, Args, D, TC))) {
+const bool OptionSet =
+(PubnamesArg &&
+ (PubnamesArg->getOption().matches(options::OPT_gpubnames) ||
+  PubnamesArg->getOption().matches(options::OPT_ggnu_pubnames)));
+if ((DebuggerTuning != llvm::DebuggerKind::LLDB || OptionSet) &&
 (!PubnamesArg ||
  (!PubnamesArg->getOption().matches(options::OPT_gno_gnu_pubnames) &&
   !PubnamesArg->getOption().matches(options::OPT_gno_pubnames
@@ -4487,6 +4491,7 @@ renderDebugOptions(const ToolChain , const Driver , 
const llvm::Triple ,
options::OPT_gpubnames)
 ? "-gpubnames"
 : "-ggnu-pubnames");
+  }
   const auto *SimpleTemplateNamesArg =
   Args.getLastArg(options::OPT_gsimple_template_names,
   options::OPT_gno_simple_template_names);
diff --git a/clang/test/Driver/split-debug.c b/clang/test/Driver/split-debug.c
index a2a3dc02354503..57f3989ed7b510 100644
--- a/clang/test/Driver/split-debug.c
+++ b/clang/test/Driver/split-debug.c
@@ -129,3 +129,8 @@
 // RUN: %clang -### -c -target x86_64 -gsplit-dwarf -g -glldb %s 2>&1 | 
FileCheck %s --check-prefixes=GLLDBSPLIT
 
 // GLLDBSPLIT-NOT: "-ggnu-pubnames"
+
+/// Generate -ggnu-pubnames for -glldb when it is explicitly enabled
+// RUN: %clang -### -c -target x86_64 -gsplit-dwarf -g -glldb -ggnu-pubnames 
%s 2>&1 | FileCheck %s --check-prefixes=GLLDBSPLIT2
+
+// GLLDBSPLIT2: "-ggnu-pubnames"

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


[clang] [CLANG][DWARF] Do not emit -ggnu-pubnames for split dwarf version 5. (PR #82840)

2024-02-27 Thread Alexander Yermolovich via cfe-commits

ayermolo wrote:

> It's been a few hours. Time to revert and analyze offline?

I think I have a fix. Just takes forever to setup and build on my laptop to 
test it.
Basically I think mac defaults to LLDB tuning, and test that fails explicitly 
passes the flag in.

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


[clang] [CLANG][DWARF] Do not emit -ggnu-pubnames for split dwarf version 5. (PR #82840)

2024-02-27 Thread Nico Weber via cfe-commits

nico wrote:

It's been a few hours. Time to revert and analyze offline?

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


[clang] [llvm] [Clang] Correct __builtin_dynamic_object_size for subobject types (PR #83204)

2024-02-27 Thread Bill Wendling via cfe-commits

bwendling wrote:

The first PR attempt was here: https://github.com/llvm/llvm-project/pull/78526

It was NACK'ed because it used the LLVM IR representation of the structure, 
which wasn't appropriate. To solve that issue, I chose to expand the 
`llvm.objectsize()` builtin to contain the size and offset of the sub-object, 
which is determined in the front-end.

Note that there are many other things wrong with our 
`__builtin_{dynamic_}object_size` implementations. For one, they perform loads 
of the pointer which isn't necessary and contrary to the idea that the builtins 
don't allow for side-effects. I'll be addressing those issues in future patches.

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


[clang] [llvm] [Clang] Correct __builtin_dynamic_object_size for subobject types (PR #83204)

2024-02-27 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-backend-aarch64

@llvm/pr-subscribers-clang

Author: Bill Wendling (bwendling)


Changes

The second argument of __builtin_dynamic_object_size controls whether it
returns the size of the whole object or the closest surrounding object.
For this struct:

  struct s { 
int  foo;
char bar[2][40];
int  baz;
int  qux;
  };  

  int main(int argc, char **argv) {
struct s f;

  #define report(x) printf(#x ": %zu\n", x)

argc = 1;
report(__builtin_dynamic_object_size(f.bar[argc], 0));
report(__builtin_dynamic_object_size(f.bar[argc], 1));
return 0;
  }

should return:

  __builtin_dynamic_object_size(f.bar[argc], 0): 48
  __builtin_dynamic_object_size(f.bar[argc], 1): 40

determined by the least significant bit of the TYPE.

The LLVM IR isn't sufficient to determine what could be considered a
"sub-object". Instead determine the size / offset info in the front-end
and pass that information along with the intrinsic.

This expands the llvm.objectsize intrinsic to add these three new 
fields:

  - The fifth argument controls which object:
- If false, return the size of the closest surrounding object.
- If true, return the size of the whole object from the pointer.
  - If non-zero and the fifth argument is 'false', the size of the 
sub-object.
  - If non-zero and the fifth argument is 'false', the offset of the 
sub-object.


---

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


45 Files Affected:

- (modified) clang/lib/CodeGen/CGBuiltin.cpp (+163-10) 
- (modified) clang/lib/CodeGen/CGExpr.cpp (+8-3) 
- (modified) clang/test/CodeGen/catch-undef-behavior.c (+1-1) 
- (added) clang/test/CodeGen/object-size-sub-object.c (+311) 
- (modified) clang/test/CodeGen/object-size.c (+549-221) 
- (modified) clang/test/CodeGen/object-size.cpp (+7-7) 
- (modified) clang/test/CodeGen/pass-object-size.c (+3-3) 
- (modified) clang/test/CodeGen/sanitize-recover.c (+1-1) 
- (modified) llvm/docs/LangRef.rst (+34-14) 
- (modified) llvm/include/llvm/Analysis/MemoryBuiltins.h (+9) 
- (modified) llvm/include/llvm/IR/Intrinsics.td (+4-3) 
- (modified) llvm/lib/Analysis/MemoryBuiltins.cpp (+20-4) 
- (modified) llvm/lib/IR/AutoUpgrade.cpp (+63-6) 
- (modified) llvm/lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp (+2-1) 
- (modified) llvm/test/Analysis/CostModel/X86/free-intrinsics.ll (+4-4) 
- (modified) llvm/test/Analysis/CostModel/free-intrinsics-datalayout.ll (+4-4) 
- (modified) llvm/test/Analysis/CostModel/free-intrinsics-no_info.ll (+4-4) 
- (modified) llvm/test/Assembler/auto_upgrade_intrinsics.ll (+4-4) 
- (modified) llvm/test/Bitcode/objectsize-upgrade-7.0.ll (+2-2) 
- (modified) llvm/test/CodeGen/AArch64/GlobalISel/memcpy_chk_no_tail.ll (+2-2) 
- (modified) llvm/test/CodeGen/AArch64/memsize-remarks.ll (+16-16) 
- (modified) llvm/test/CodeGen/AMDGPU/promote-alloca-mem-intrinsics.ll (+4-4) 
- (modified) llvm/test/Other/cgscc-libcall-update.ll (+2-2) 
- (modified) llvm/test/Transforms/InferAddressSpaces/AMDGPU/debug-info.ll 
(+4-4) 
- (modified) llvm/test/Transforms/InferAddressSpaces/AMDGPU/intrinsics.ll 
(+6-6) 
- (modified) llvm/test/Transforms/InferAlignment/propagate-assume.ll (+2-2) 
- (modified) llvm/test/Transforms/Inline/call-intrinsic-objectsize.ll (+3-3) 
- (modified) llvm/test/Transforms/InstCombine/allocsize.ll (+5-5) 
- (modified) llvm/test/Transforms/InstCombine/assume_inevitable.ll (+1-1) 
- (modified) llvm/test/Transforms/InstCombine/builtin-dynamic-object-size.ll 
(+13-13) 
- (modified) llvm/test/Transforms/InstCombine/builtin-object-size-custom-dl.ll 
(+3-3) 
- (modified) 
llvm/test/Transforms/InstCombine/builtin-object-size-strdup-family.ll (+14-10) 
- (modified) llvm/test/Transforms/InstCombine/invoke.ll (+1-1) 
- (modified) llvm/test/Transforms/InstCombine/memset_chk-1.ll (+5-5) 
- (modified) llvm/test/Transforms/InstCombine/objsize.ll (+38-38) 
- (modified) llvm/test/Transforms/InstCombine/stpcpy_chk-1.ll (+4-4) 
- (modified) llvm/test/Transforms/InstCombine/strcpy_chk-1.ll (+5-5) 
- (modified) 
llvm/test/Transforms/LowerConstantIntrinsics/builtin-object-size-load.ll (+2-2) 
- (modified) 
llvm/test/Transforms/LowerConstantIntrinsics/builtin-object-size-phi.ll (+5-5) 
- (modified) 
llvm/test/Transforms/LowerConstantIntrinsics/builtin-object-size-posix-memalign.ll
 (+8-8) 
- (modified) 
llvm/test/Transforms/LowerConstantIntrinsics/constant-intrinsics.ll (+2-2) 
- (modified) 
llvm/test/Transforms/LowerConstantIntrinsics/crash-on-large-allocas.ll (+2-2) 
- (modified) llvm/test/Transforms/LowerConstantIntrinsics/objectsize_basic.ll 
(+18-18) 
- (modified) llvm/test/Transforms/LowerConstantIntrinsics/stale-worklist-phi.ll 
(+2-2) 
- (modified) llvm/test/Transforms/SCCP/issue59602-assume-like-call-users.ll 
(+5-5) 


``diff
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 2d16e7cdc06053..9d8e5671d9d12d 100644
--- 

[clang] [llvm] [MC/DC][Coverage] Loosen the limit of NumConds from 6 (PR #82448)

2024-02-27 Thread Alan Phipps via cfe-commits


@@ -1201,19 +1197,22 @@ void CodeGenPGO::emitMCDCCondBitmapUpdate(CGBuilderTy 
, const Expr *S,
   // Extract the ID of the condition we are setting in the bitmap.
   const auto  = BranchStateIter->second;
   assert(Branch.ID >= 0 && "Condition has no ID!");
+  assert(Branch.DecisionStmt);
 
-  auto *I8PtrTy = llvm::PointerType::getUnqual(CGM.getLLVMContext());
+  // Cancel the emission if the Decision is erased after the allocation.
+  const auto DecisionIter =
+  RegionMCDCState->DecisionByStmt.find(Branch.DecisionStmt);
+  if (DecisionIter == RegionMCDCState->DecisionByStmt.end())
+return;
 
-  // Emit intrinsic that updates a dedicated temporary value on the stack after
-  // a condition is evaluated. After the set of conditions has been updated,
-  // the resulting value is used to update the boolean expression's bitmap.
-  llvm::Value *Args[5] = {llvm::ConstantExpr::getBitCast(FuncNameVar, I8PtrTy),
-  Builder.getInt64(FunctionHash),
-  Builder.getInt32(Branch.ID),
-  MCDCCondBitmapAddr.getPointer(), Val};
-  Builder.CreateCall(
-  CGM.getIntrinsic(llvm::Intrinsic::instrprof_mcdc_condbitmap_update),
-  Args);
+  const auto  = DecisionIter->second.Indices[Branch.ID];
+
+  auto *CurTV = Builder.CreateLoad(MCDCCondBitmapAddr,
+   "mcdc." + Twine(Branch.ID + 1) + ".cur");
+  auto *NewTV = Builder.CreateAdd(CurTV, Builder.getInt32(TVIdxs[true]));
+  NewTV = Builder.CreateSelect(
+  Val, NewTV, Builder.CreateAdd(CurTV, Builder.getInt32(TVIdxs[false])));
+  Builder.CreateStore(NewTV, MCDCCondBitmapAddr);

evodius96 wrote:

Makes sense.  I left enabling atomic operations on tvbitmap update as a TBD.

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


[clang] [llvm] [MC/DC][Coverage] Loosen the limit of NumConds from 6 (PR #82448)

2024-02-27 Thread Alan Phipps via cfe-commits


@@ -983,7 +979,7 @@ void CodeGenPGO::mapRegionCounters(const Decl *D) {
   // for most embedded applications. Setting a maximum value prevents the
   // bitmap footprint from growing too large without the user's knowledge. In
   // the future, this value could be adjusted with a command-line option.
-  unsigned MCDCMaxConditions = (CGM.getCodeGenOpts().MCDCCoverage) ? 6 : 0;
+  unsigned MCDCMaxConditions = (CGM.getCodeGenOpts().MCDCCoverage) ? 32767 : 0;

evodius96 wrote:

I know you will do this later, but I also wanted to echo the desire for a means 
to control the condition limit to warn the user against unintended memory 
footprint expansion, most useful in embedded development contexts.  It may not 
otherwise be obvious to most users what is contributing to larger memory usage. 
We could also override the default in downstream toolchains.

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


[clang] [compiler-rt] [llvm] [InstrProf] Single byte counters in coverage (PR #75425)

2024-02-27 Thread Petr Hosek via cfe-commits


@@ -1282,8 +1283,14 @@ class SegmentBuilder {
   // value for that area.
   // We add counts of the regions of the same kind as the active region
   // to handle the both situations.
-  if (I->Kind == Active->Kind)
-Active->ExecutionCount += I->ExecutionCount;
+  if (I->Kind == Active->Kind) {
+assert(I->HasSingleByteCoverage == Active->HasSingleByteCoverage &&
+   "Regions are generated in different coverage modes");

petrhosek wrote:

This is just a minor nit that I just noticed and could be addressed in some 
follow up change, but in all other `assert` cases the message is not 
capitalized so shouldn't capitalize here either for consistency.

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


[clang] [alpha.webkit.UncountedCallArgsChecker] Allow a variable declaration in a trivial function. (PR #82291)

2024-02-27 Thread Ryosuke Niwa via cfe-commits

https://github.com/rniwa updated https://github.com/llvm/llvm-project/pull/82291

>From 0a8cfb11a601e7a6ec59489b8ac15c40136002b2 Mon Sep 17 00:00:00 2001
From: Ryosuke Niwa 
Date: Sat, 17 Feb 2024 18:12:16 -0800
Subject: [PATCH] [alpha.webkit.UncountedCallArgsChecker] Allow a variable
 declaration in a trivial function.

---
 .../Checkers/WebKit/PtrTypesSemantics.cpp   |  8 ++--
 .../Checkers/WebKit/uncounted-obj-arg.cpp   | 17 +
 2 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
index a7891d2da07c18..09c42434513177 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
@@ -309,8 +309,12 @@ class TrivialFunctionAnalysisVisitor
 return true;
   if (isa(decl))
 return true;
-  if (auto *VD = dyn_cast(decl))
-return VD->hasConstantInitialization() && VD->getEvaluatedValue();
+  if (auto *VD = dyn_cast(decl)) {
+if (VD->hasConstantInitialization() && VD->getEvaluatedValue())
+  return true;
+auto *Init = VD->getInit();
+return !Init || Visit(Init);
+  }
 }
 return false;
   }
diff --git a/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp 
b/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp
index ac16a31293f3de..80a9a263dab140 100644
--- a/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp
+++ b/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp
@@ -199,6 +199,8 @@ class RefCounted {
   bool trivial23() const { return 
OptionSet::fromRaw(v).contains(Flags::Flag1); }
   int trivial24() const { ASSERT(v); return v; }
   unsigned trivial25() const { return __c11_atomic_load((volatile 
_Atomic(unsigned) *), __ATOMIC_RELAXED); }
+  bool trivial26() { bool hasValue = v; return !hasValue; }
+  bool trivial27(int v) { bool value; value = v ? 1 : 0; return value; }
 
   static RefCounted& singleton() {
 static RefCounted s_RefCounted;
@@ -262,6 +264,15 @@ class RefCounted {
 return __c11_atomic_load((volatile _Atomic(unsigned) *)another(), 
__ATOMIC_RELAXED);
   }
 
+  void nonTrivial11() {
+Number num(0.3);
+  }
+
+  bool nonTrivial12() {
+bool val = otherFunction();
+return val;
+  }
+
   unsigned v { 0 };
   Number* number { nullptr };
   Enum enumValue { Enum::Value1 };
@@ -309,6 +320,8 @@ class UnrelatedClass {
 getFieldTrivial().trivial23(); // no-warning
 getFieldTrivial().trivial24(); // no-warning
 getFieldTrivial().trivial25(); // no-warning
+getFieldTrivial().trivial26(); // no-warning
+getFieldTrivial().trivial27(5); // no-warning
 RefCounted::singleton().trivial18(); // no-warning
 RefCounted::singleton().someFunction(); // no-warning
 
@@ -334,6 +347,10 @@ class UnrelatedClass {
 // expected-warning@-1{{Call argument for 'this' parameter is uncounted 
and unsafe}}
 getFieldTrivial().nonTrivial10();
 // expected-warning@-1{{Call argument for 'this' parameter is uncounted 
and unsafe}}
+getFieldTrivial().nonTrivial11();
+// expected-warning@-1{{Call argument for 'this' parameter is uncounted 
and unsafe}}
+getFieldTrivial().nonTrivial12();
+// expected-warning@-1{{Call argument for 'this' parameter is uncounted 
and unsafe}}
   }
 };
 

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


[clang] [compiler-rt] [llvm] [InstrProf] Single byte counters in coverage (PR #75425)

2024-02-27 Thread via cfe-commits

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


[clang] [alpha.webkit.UncountedCallArgsChecker] Allow a variable declaration in a trivial function. (PR #82291)

2024-02-27 Thread Ryosuke Niwa via cfe-commits

rniwa wrote:

Thanks for the review!

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


[clang] [alpha.webkit.UncountedCallArgsChecker] Allow a variable declaration in a trivial function. (PR #82291)

2024-02-27 Thread Artem Dergachev via cfe-commits

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

LGTM, looks straightforward!

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


[clang] [llvm] [HLSL] implementation of lerp intrinsic (PR #83077)

2024-02-27 Thread Farzon Lotfi via cfe-commits

https://github.com/farzonl updated 
https://github.com/llvm/llvm-project/pull/83077

>From d4384c5ac52596eeab512574111e499f230b7db7 Mon Sep 17 00:00:00 2001
From: Farzon Lotfi 
Date: Sun, 25 Feb 2024 20:08:09 -0500
Subject: [PATCH] [HLSL] Implementation  lerp intrinsic This is the start of
 implementing the lerp intrinsic
 
https://learn.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-lerp
 Builtins.td - defines the builtin hlsl_intrinsics.h - defines the lerp api
 DiagnosticSemaKinds.td - needed a new error to be inclusive for more than two
 operands. CGBuiltin.cpp - add the lerp intrinsic lowering SemaChecking.cpp -
 type checks for lerp builtin IntrinsicsDirectX.td - define the lerp intrinsic

this change implements the first half of #70102
---
 clang/include/clang/Basic/Builtins.td |   6 +
 .../clang/Basic/DiagnosticSemaKinds.td|   5 +
 clang/lib/CodeGen/CGBuiltin.cpp   |  37 ++
 clang/lib/Headers/hlsl/hlsl_intrinsics.h  |  36 ++
 clang/lib/Sema/SemaChecking.cpp   |  79 -
 .../CodeGenHLSL/builtins/lerp-builtin.hlsl|  37 ++
 clang/test/CodeGenHLSL/builtins/lerp.hlsl | 105 ++
 clang/test/SemaHLSL/BuiltIns/dot-errors.hlsl  |  28 ++---
 clang/test/SemaHLSL/BuiltIns/lerp-errors.hlsl |  91 +++
 llvm/include/llvm/IR/IntrinsicsDirectX.td |   5 +
 10 files changed, 388 insertions(+), 41 deletions(-)
 create mode 100644 clang/test/CodeGenHLSL/builtins/lerp-builtin.hlsl
 create mode 100644 clang/test/CodeGenHLSL/builtins/lerp.hlsl
 create mode 100644 clang/test/SemaHLSL/BuiltIns/lerp-errors.hlsl

diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index e3432f7925ba14..755ef3631b2856 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -4530,6 +4530,12 @@ def HLSLDotProduct : LangBuiltin<"HLSL_LANG"> {
   let Prototype = "void(...)";
 }
 
+def HLSLLerp : LangBuiltin<"HLSL_LANG"> {
+  let Spellings = ["__builtin_hlsl_lerp"];
+  let Attributes = [NoThrow, Const];
+  let Prototype = "void(...)";
+}
+
 // Builtins for XRay.
 def XRayCustomEvent : Builtin {
   let Spellings = ["__xray_customevent"];
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 57784a4ba2e388..63115d4bd49091 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -10266,6 +10266,11 @@ def err_block_on_vm : Error<
 def err_sizeless_nonlocal : Error<
   "non-local variable with sizeless type %0">;
 
+def err_vec_builtin_non_vector_all : Error<
+ "all arguments to %0 must be vectors">;
+def err_vec_builtin_incompatible_vector_all : Error<
+  "all arguments to %0 must have vectors of the same type">;
+
 def err_vec_builtin_non_vector : Error<
  "first two arguments to %0 must be vectors">;
 def err_vec_builtin_incompatible_vector : Error<
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 54d7451a9d6221..17b7af924e5ff0 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -18006,6 +18006,43 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned 
BuiltinID,
 /*ReturnType*/ T0->getScalarType(), Intrinsic::dx_dot,
 ArrayRef{Op0, Op1}, nullptr, "dx.dot");
   } break;
+  case Builtin::BI__builtin_hlsl_lerp: {
+Value *X = EmitScalarExpr(E->getArg(0));
+Value *Y = EmitScalarExpr(E->getArg(1));
+Value *S = EmitScalarExpr(E->getArg(2));
+llvm::Type *Xty = X->getType();
+llvm::Type *Yty = Y->getType();
+llvm::Type *Sty = S->getType();
+if (!Xty->isVectorTy() && !Yty->isVectorTy() && !Sty->isVectorTy()) {
+  if (Xty->isFloatingPointTy()) {
+auto V = Builder.CreateFSub(Y, X);
+V = Builder.CreateFMul(S, V);
+return Builder.CreateFAdd(X, V, "dx.lerp");
+  }
+  llvm_unreachable("Scalar Lerp is only supported on floats.");
+}
+// A VectorSplat should have happened
+assert(Xty->isVectorTy() && Yty->isVectorTy() && Sty->isVectorTy() &&
+   "Lerp of vector and scalar is not supported.");
+
+[[maybe_unused]] auto *XVecTy =
+E->getArg(0)->getType()->getAs();
+[[maybe_unused]] auto *YVecTy =
+E->getArg(1)->getType()->getAs();
+[[maybe_unused]] auto *SVecTy =
+E->getArg(2)->getType()->getAs();
+// A HLSLVectorTruncation should have happend
+assert(XVecTy->getNumElements() == YVecTy->getNumElements() &&
+   XVecTy->getNumElements() == SVecTy->getNumElements() &&
+   "Lerp requires vectors to be of the same size.");
+assert(XVecTy->getElementType()->isRealFloatingType() &&
+   XVecTy->getElementType() == YVecTy->getElementType() &&
+   XVecTy->getElementType() == SVecTy->getElementType() &&
+   "Lerp requires float vectors to be of the same type.");
+return Builder.CreateIntrinsic(
+ 

[clang] [compiler-rt] [llvm] [InstrProf] Single byte counters in coverage (PR #75425)

2024-02-27 Thread NAKAMURA Takumi via cfe-commits


@@ -1503,38 +1527,53 @@ struct CounterCoverageMappingBuilder
 }
 
 // Create Branch Region around condition.
-createBranchRegion(S->getCond(), BodyCount,
-   subtractCounters(CondCount, BodyCount));
+if (!llvm::EnableSingleByteCoverage)
+  createBranchRegion(S->getCond(), BodyCount,
+ subtractCounters(CondCount, BodyCount));

chapuni wrote:

As far as I have checked, I guess `!EnableSingleByteCoverage` can be sunk into 
`createBranchRegion()` rather than checking from callers.

Sorry for my delayed comment. I didn't notice till merging.

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


[clang] [llvm] [RISCV] Remove experimental from Zacas. (PR #83195)

2024-02-27 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-llvm-support

Author: Craig Topper (topperc)


Changes

Document that we don't use the double compare and swap instructions due to ABI 
concerns.

---

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


15 Files Affected:

- (modified) clang/test/Preprocessor/riscv-target-features.c (+9-9) 
- (modified) llvm/docs/RISCVUsage.rst (+6-3) 
- (modified) llvm/docs/ReleaseNotes.rst (+1) 
- (modified) llvm/lib/Support/RISCVISAInfo.cpp (+1-1) 
- (modified) llvm/lib/Target/RISCV/RISCVFeatures.td (+1-1) 
- (modified) llvm/test/CodeGen/RISCV/atomic-cmpxchg-branch-on-result.ll (+3-3) 
- (modified) llvm/test/CodeGen/RISCV/atomic-cmpxchg.ll (+6-6) 
- (modified) llvm/test/CodeGen/RISCV/atomic-rmw.ll (+6-6) 
- (modified) llvm/test/CodeGen/RISCV/atomic-signext.ll (+2-2) 
- (modified) llvm/test/CodeGen/RISCV/attributes.ll (+2-2) 
- (modified) llvm/test/MC/RISCV/rv32zacas-invalid.s (+1-1) 
- (modified) llvm/test/MC/RISCV/rv32zacas-valid.s (+6-6) 
- (modified) llvm/test/MC/RISCV/rv64zacas-valid.s (+3-3) 
- (modified) llvm/test/MC/RISCV/rvzabha-zacas-valid.s (+6-6) 
- (modified) llvm/unittests/Support/RISCVISAInfoTest.cpp (+1-1) 


``diff
diff --git a/clang/test/Preprocessor/riscv-target-features.c 
b/clang/test/Preprocessor/riscv-target-features.c
index ea81c662044306..df13e0beb16326 100644
--- a/clang/test/Preprocessor/riscv-target-features.c
+++ b/clang/test/Preprocessor/riscv-target-features.c
@@ -75,6 +75,7 @@
 // CHECK-NOT: __riscv_za128rs {{.*$}}
 // CHECK-NOT: __riscv_za64rs {{.*$}}
 // CHECK-NOT: __riscv_zawrs {{.*$}}
+// CHECK-NOT: __riscv_zacas {{.*$}}
 // CHECK-NOT: __riscv_zba {{.*$}}
 // CHECK-NOT: __riscv_zbb {{.*$}}
 // CHECK-NOT: __riscv_zbc {{.*$}}
@@ -166,7 +167,6 @@
 // CHECK-NOT: __riscv_ssqosid{{.*$}}
 // CHECK-NOT: __riscv_supm{{.*$}}
 // CHECK-NOT: __riscv_zaamo {{.*$}}
-// CHECK-NOT: __riscv_zacas {{.*$}}
 // CHECK-NOT: __riscv_zalasr {{.*$}}
 // CHECK-NOT: __riscv_zalrsc {{.*$}}
 // CHECK-NOT: __riscv_zcmop {{.*$}}
@@ -660,6 +660,14 @@
 // RUN:   -o - | FileCheck --check-prefix=CHECK-ZA64RS-EXT %s
 // CHECK-ZA64RS-EXT: __riscv_za64rs 100{{$}}
 
+// RUN: %clang --target=riscv32 \
+// RUN:   -march=rv32i_zacas1p0 -E -dM %s \
+// RUN:   -o - | FileCheck --check-prefix=CHECK-ZACAS-EXT %s
+// RUN: %clang --target=riscv64 \
+// RUN:   -march=rv64i_zacas1p0 -E -dM %s \
+// RUN:   -o - | FileCheck --check-prefix=CHECK-ZACAS-EXT %s
+// CHECK-ZACAS-EXT: __riscv_zacas 100{{$}}
+
 // RUN: %clang --target=riscv32-unknown-linux-gnu \
 // RUN:   -march=rv32izawrs -E -dM %s \
 // RUN:   -o - | FileCheck --check-prefix=CHECK-ZAWRS-EXT %s
@@ -1485,14 +1493,6 @@
 // RUN:   -o - | FileCheck --check-prefix=CHECK-ZAAMO-EXT %s
 // CHECK-ZAAMO-EXT: __riscv_zaamo 2000{{$}}
 
-// RUN: %clang --target=riscv32 -menable-experimental-extensions \
-// RUN:   -march=rv32i_zacas1p0 -E -dM %s \
-// RUN:   -o - | FileCheck --check-prefix=CHECK-ZACAS-EXT %s
-// RUN: %clang --target=riscv64 -menable-experimental-extensions \
-// RUN:   -march=rv64i_zacas1p0 -E -dM %s \
-// RUN:   -o - | FileCheck --check-prefix=CHECK-ZACAS-EXT %s
-// CHECK-ZACAS-EXT: __riscv_zacas 100{{$}}
-
 // RUN: %clang --target=riscv32 -menable-experimental-extensions \
 // RUN:   -march=rv32i_zalasr0p1 -E -dM %s \
 // RUN:   -o - | FileCheck --check-prefix=CHECK-ZALASR-EXT %s
diff --git a/llvm/docs/RISCVUsage.rst b/llvm/docs/RISCVUsage.rst
index ed443596897aea..26bcf7fbf5490c 100644
--- a/llvm/docs/RISCVUsage.rst
+++ b/llvm/docs/RISCVUsage.rst
@@ -117,6 +117,7 @@ on support follow.
  ``V`` Supported
  ``Za128rs``   Supported (`See note 
<#riscv-profiles-extensions-note>`__)
  ``Za64rs``Supported (`See note 
<#riscv-profiles-extensions-note>`__)
+ ``Zacas`` Supported (`See note <#riscv-zacas-note>`__)
  ``Zawrs`` Assembly Support
  ``Zba``   Supported
  ``Zbb``   Supported
@@ -236,6 +237,11 @@ Supported
 ``Za128rs``, ``Za64rs``, ``Zic64b``, ``Ziccamoa``, ``Ziccif``, ``Zicclsm``, 
``Ziccrse``, ``Shcounterenvw``, ``Shgatpa``, ``Shtvala``, ``Shvsatpa``, 
``Shvstvala``, ``Shvstvecd``, ``Ssccptr``, ``Sscounterenw``, ``Ssstateen``, 
``Ssstrict``, ``Sstvala``, ``Sstvecd``, ``Ssu64xl``, ``Svade``, ``Svbare``
   These extensions are defined as part of the `RISC-V Profiles specification 
`__.  They do not 
introduce any new features themselves, but instead describe existing hardware 
features.
 
+  .. _riscv-zacas-note:
+
+``Zacas``
+  amocas.w will be used for i32 cmpxchg on RV32. amocas.d will be used i64 
cmpxchg on RV64. The compiler will not generate amocas.d on RV32 or amocas.q on 
RV64 due to ABI compatibilty. These can only be used in the assembler.
+
 Experimental Extensions
 ===
 
@@ -252,9 +258,6 @@ The primary goal of experimental support is to assist in 
the process of 

[clang] [llvm] [RISCV] Remove experimental from Zacas. (PR #83195)

2024-02-27 Thread Craig Topper via cfe-commits

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

Document that we don't use the double compare and swap instructions due to ABI 
concerns.

>From 8ed68475b43008d9c7baff7f275026cc7ada5993 Mon Sep 17 00:00:00 2001
From: Craig Topper 
Date: Tue, 27 Feb 2024 14:01:52 -0800
Subject: [PATCH] [RISCV] Remove experimental from Zacas.

Document that we don't use the double compare and swap instructions due
to ABI concerns.
---
 .../test/Preprocessor/riscv-target-features.c  | 18 +-
 llvm/docs/RISCVUsage.rst   |  9 ++---
 llvm/docs/ReleaseNotes.rst |  1 +
 llvm/lib/Support/RISCVISAInfo.cpp  |  2 +-
 llvm/lib/Target/RISCV/RISCVFeatures.td |  2 +-
 .../RISCV/atomic-cmpxchg-branch-on-result.ll   |  6 +++---
 llvm/test/CodeGen/RISCV/atomic-cmpxchg.ll  | 12 ++--
 llvm/test/CodeGen/RISCV/atomic-rmw.ll  | 12 ++--
 llvm/test/CodeGen/RISCV/atomic-signext.ll  |  4 ++--
 llvm/test/CodeGen/RISCV/attributes.ll  |  4 ++--
 llvm/test/MC/RISCV/rv32zacas-invalid.s |  2 +-
 llvm/test/MC/RISCV/rv32zacas-valid.s   | 12 ++--
 llvm/test/MC/RISCV/rv64zacas-valid.s   |  6 +++---
 llvm/test/MC/RISCV/rvzabha-zacas-valid.s   | 12 ++--
 llvm/unittests/Support/RISCVISAInfoTest.cpp|  2 +-
 15 files changed, 54 insertions(+), 50 deletions(-)

diff --git a/clang/test/Preprocessor/riscv-target-features.c 
b/clang/test/Preprocessor/riscv-target-features.c
index ea81c662044306..df13e0beb16326 100644
--- a/clang/test/Preprocessor/riscv-target-features.c
+++ b/clang/test/Preprocessor/riscv-target-features.c
@@ -75,6 +75,7 @@
 // CHECK-NOT: __riscv_za128rs {{.*$}}
 // CHECK-NOT: __riscv_za64rs {{.*$}}
 // CHECK-NOT: __riscv_zawrs {{.*$}}
+// CHECK-NOT: __riscv_zacas {{.*$}}
 // CHECK-NOT: __riscv_zba {{.*$}}
 // CHECK-NOT: __riscv_zbb {{.*$}}
 // CHECK-NOT: __riscv_zbc {{.*$}}
@@ -166,7 +167,6 @@
 // CHECK-NOT: __riscv_ssqosid{{.*$}}
 // CHECK-NOT: __riscv_supm{{.*$}}
 // CHECK-NOT: __riscv_zaamo {{.*$}}
-// CHECK-NOT: __riscv_zacas {{.*$}}
 // CHECK-NOT: __riscv_zalasr {{.*$}}
 // CHECK-NOT: __riscv_zalrsc {{.*$}}
 // CHECK-NOT: __riscv_zcmop {{.*$}}
@@ -660,6 +660,14 @@
 // RUN:   -o - | FileCheck --check-prefix=CHECK-ZA64RS-EXT %s
 // CHECK-ZA64RS-EXT: __riscv_za64rs 100{{$}}
 
+// RUN: %clang --target=riscv32 \
+// RUN:   -march=rv32i_zacas1p0 -E -dM %s \
+// RUN:   -o - | FileCheck --check-prefix=CHECK-ZACAS-EXT %s
+// RUN: %clang --target=riscv64 \
+// RUN:   -march=rv64i_zacas1p0 -E -dM %s \
+// RUN:   -o - | FileCheck --check-prefix=CHECK-ZACAS-EXT %s
+// CHECK-ZACAS-EXT: __riscv_zacas 100{{$}}
+
 // RUN: %clang --target=riscv32-unknown-linux-gnu \
 // RUN:   -march=rv32izawrs -E -dM %s \
 // RUN:   -o - | FileCheck --check-prefix=CHECK-ZAWRS-EXT %s
@@ -1485,14 +1493,6 @@
 // RUN:   -o - | FileCheck --check-prefix=CHECK-ZAAMO-EXT %s
 // CHECK-ZAAMO-EXT: __riscv_zaamo 2000{{$}}
 
-// RUN: %clang --target=riscv32 -menable-experimental-extensions \
-// RUN:   -march=rv32i_zacas1p0 -E -dM %s \
-// RUN:   -o - | FileCheck --check-prefix=CHECK-ZACAS-EXT %s
-// RUN: %clang --target=riscv64 -menable-experimental-extensions \
-// RUN:   -march=rv64i_zacas1p0 -E -dM %s \
-// RUN:   -o - | FileCheck --check-prefix=CHECK-ZACAS-EXT %s
-// CHECK-ZACAS-EXT: __riscv_zacas 100{{$}}
-
 // RUN: %clang --target=riscv32 -menable-experimental-extensions \
 // RUN:   -march=rv32i_zalasr0p1 -E -dM %s \
 // RUN:   -o - | FileCheck --check-prefix=CHECK-ZALASR-EXT %s
diff --git a/llvm/docs/RISCVUsage.rst b/llvm/docs/RISCVUsage.rst
index ed443596897aea..26bcf7fbf5490c 100644
--- a/llvm/docs/RISCVUsage.rst
+++ b/llvm/docs/RISCVUsage.rst
@@ -117,6 +117,7 @@ on support follow.
  ``V`` Supported
  ``Za128rs``   Supported (`See note 
<#riscv-profiles-extensions-note>`__)
  ``Za64rs``Supported (`See note 
<#riscv-profiles-extensions-note>`__)
+ ``Zacas`` Supported (`See note <#riscv-zacas-note>`__)
  ``Zawrs`` Assembly Support
  ``Zba``   Supported
  ``Zbb``   Supported
@@ -236,6 +237,11 @@ Supported
 ``Za128rs``, ``Za64rs``, ``Zic64b``, ``Ziccamoa``, ``Ziccif``, ``Zicclsm``, 
``Ziccrse``, ``Shcounterenvw``, ``Shgatpa``, ``Shtvala``, ``Shvsatpa``, 
``Shvstvala``, ``Shvstvecd``, ``Ssccptr``, ``Sscounterenw``, ``Ssstateen``, 
``Ssstrict``, ``Sstvala``, ``Sstvecd``, ``Ssu64xl``, ``Svade``, ``Svbare``
   These extensions are defined as part of the `RISC-V Profiles specification 
`__.  They do not 
introduce any new features themselves, but instead describe existing hardware 
features.
 
+  .. _riscv-zacas-note:
+
+``Zacas``
+  amocas.w will be used for i32 cmpxchg on RV32. amocas.d will be used i64 
cmpxchg on RV64. The compiler will not generate amocas.d on RV32 or amocas.q on 
RV64 due to ABI compatibilty. These can only be 

[clang] [llvm] [HLSL] implementation of lerp intrinsic (PR #83077)

2024-02-27 Thread Farzon Lotfi via cfe-commits

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


[clang] [clang] Implement CTAD for type alias template. (PR #77890)

2024-02-27 Thread Erich Keane via cfe-commits


@@ -2258,6 +2258,94 @@ class ExtractTypeForDeductionGuide
   }
 };
 
+// Build a deduction guide with the specified parameter types.
+FunctionTemplateDecl *
+buildDeductionGuide(Sema , TemplateDecl *OriginalTemplate,
+TemplateParameterList *TemplateParams,
+CXXConstructorDecl *Ctor, ExplicitSpecifier ES,
+TypeSourceInfo *TInfo, SourceLocation LocStart,
+SourceLocation Loc, SourceLocation LocEnd, bool IsImplicit,
+llvm::ArrayRef MaterializedTypedefs = 
{}) {
+  DeclContext *DC = OriginalTemplate->getDeclContext();
+  auto DeductionGuideName =
+  SemaRef.Context.DeclarationNames.getCXXDeductionGuideName(
+  OriginalTemplate);
+
+  DeclarationNameInfo Name(DeductionGuideName, Loc);
+  ArrayRef Params =
+  TInfo->getTypeLoc().castAs().getParams();
+
+  // Build the implicit deduction guide template.
+  auto *Guide =
+  CXXDeductionGuideDecl::Create(SemaRef.Context, DC, LocStart, ES, Name,
+TInfo->getType(), TInfo, LocEnd, Ctor);
+  Guide->setImplicit(IsImplicit);
+  Guide->setParams(Params);
+
+  for (auto *Param : Params)
+Param->setDeclContext(Guide);
+  for (auto *TD : MaterializedTypedefs)
+TD->setDeclContext(Guide);
+
+  auto *GuideTemplate = FunctionTemplateDecl::Create(
+  SemaRef.Context, DC, Loc, DeductionGuideName, TemplateParams, Guide);
+  GuideTemplate->setImplicit(IsImplicit);
+  Guide->setDescribedFunctionTemplate(GuideTemplate);
+
+  if (isa(DC)) {
+Guide->setAccess(AS_public);
+GuideTemplate->setAccess(AS_public);
+  }
+
+  DC->addDecl(GuideTemplate);
+  return GuideTemplate;
+}
+
+// Transform a given template type parameter `TTP`.
+TemplateTypeParmDecl *
+transformTemplateTypeParam(Sema , DeclContext *DC,
+   TemplateTypeParmDecl *TTP,
+   MultiLevelTemplateArgumentList ,
+   unsigned NewDepth, unsigned NewIndex) {
+  // TemplateTypeParmDecl's index cannot be changed after creation, so
+  // substitute it directly.
+  auto *NewTTP = TemplateTypeParmDecl::Create(
+  SemaRef.Context, DC, TTP->getBeginLoc(), TTP->getLocation(), NewDepth,
+  NewIndex, TTP->getIdentifier(), TTP->wasDeclaredWithTypename(),
+  TTP->isParameterPack(), TTP->hasTypeConstraint(),
+  TTP->isExpandedParameterPack()
+  ? std::optional(TTP->getNumExpansionParameters())
+  : std::nullopt);
+  if (const auto *TC = TTP->getTypeConstraint())
+SemaRef.SubstTypeConstraint(NewTTP, TC, Args,
+/*EvaluateConstraint*/ true);

erichkeane wrote:

For the most part, we WANT the 'old' constraint to attach.  All the work to 
instantiate the constraints end up going against the original template.

By doing this constraint evaluation, you're now making substitution failures 
observable way before they are allowed to be observed from the looks of it.

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


[clang] [clang] Implement CTAD for type alias template. (PR #77890)

2024-02-27 Thread Erich Keane via cfe-commits


@@ -10598,10 +10598,36 @@ QualType 
Sema::DeduceTemplateSpecializationFromInitializer(
   if (TemplateName.isDependent())
 return SubstAutoTypeDependent(TSInfo->getType());
 
-  // We can only perform deduction for class templates.
+  // We can only perform deduction for class templates or alias templates.
   auto *Template =
   dyn_cast_or_null(TemplateName.getAsTemplateDecl());
+  TemplateDecl* LookupTemplateDecl = Template;
+  if (!Template && getLangOpts().CPlusPlus20) { // type alias template
+if (auto *AliasTemplate = dyn_cast_or_null(
+TemplateName.getAsTemplateDecl());
+AliasTemplate) {
+  LookupTemplateDecl = AliasTemplate;
+  auto UnderlyingType = AliasTemplate->getTemplatedDecl()
+->getUnderlyingType()
+.getDesugaredType(Context);

erichkeane wrote:

`Desugar` doesn't remove all of the typedefs/etc, and leaves sugar in 
pointees/references.  So this is very likely to end up being an underlying type 
of, for example, `SomeTypedef*`.  Canonical canonicalizes EVERYTHING.

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


[clang] [clang] Implement CTAD for type alias template. (PR #77890)

2024-02-27 Thread Erich Keane via cfe-commits


@@ -10598,10 +10598,36 @@ QualType 
Sema::DeduceTemplateSpecializationFromInitializer(
   if (TemplateName.isDependent())
 return SubstAutoTypeDependent(TSInfo->getType());
 
-  // We can only perform deduction for class templates.
+  // We can only perform deduction for class templates or alias templates.
   auto *Template =
   dyn_cast_or_null(TemplateName.getAsTemplateDecl());
+  TemplateDecl* LookupTemplateDecl = Template;
+  if (!Template && getLangOpts().CPlusPlus20) { // type alias template

erichkeane wrote:

We actually have a TON of those sorts of things: See the warning groups named 
like `CXXPre20Compat`.

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


[clang] [clang][fat-lto-objects] Make module flags match non-FatLTO pipelines (PR #83159)

2024-02-27 Thread Paul Kirth via cfe-commits


@@ -1036,7 +1041,8 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
   if (!actionRequiresCodeGen(Action) && CodeGenOpts.VerifyModule)
 MPM.addPass(VerifierPass());
 
-  if (Action == Backend_EmitBC || Action == Backend_EmitLL) {
+  if (Action == Backend_EmitBC || Action == Backend_EmitLL ||
+  CodeGenOpts.FatLTO) {

ilovepi wrote:

I believe its `Backend_EmitObj` .  I think that gets a little complicated when 
`-S` or `-emit-llvm` is passed, since I think we then select  `Backend_EmitLL` 
or `Backend_EmitBC`. 
https://github.com/llvm/llvm-project/blob/d82e93e7f129d9e8b72570efdf4a15d6ec3d4336/clang/lib/Driver/Driver.cpp#L4770


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


[clang] Turn 'counted_by' into a type attribute and parse it into 'CountAttributedType' (PR #78000)

2024-02-27 Thread Erich Keane via cfe-commits

https://github.com/erichkeane commented:

No additional comments from me, if the other reviewers are happy, I'm happy 
with where this is/is going.

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


[clang] [InstallAPI] Hookup Input files & basic ASTVisitor (PR #82552)

2024-02-27 Thread Cyndy Ishida via cfe-commits

https://github.com/cyndyishida updated 
https://github.com/llvm/llvm-project/pull/82552

>From b0cc1eeba893c24d5358cb49189da2e287daf972 Mon Sep 17 00:00:00 2001
From: Cyndy Ishida 
Date: Wed, 21 Feb 2024 14:56:02 -0800
Subject: [PATCH] [InstallAPI] Hookup Input files & basic ASTVisitor

This patch takes in json files as input to determine that header files to 
process, and in which order, to pass along for CC1 invocations.
This patch also includes an ASTVisitor to collect simple global variables.
---
 clang/include/clang/InstallAPI/Context.h  | 22 -
 clang/include/clang/InstallAPI/Frontend.h | 48 ++
 clang/include/clang/InstallAPI/HeaderFile.h   | 23 +
 clang/include/clang/InstallAPI/Visitor.h  | 51 ++
 clang/lib/InstallAPI/CMakeLists.txt   |  3 +
 clang/lib/InstallAPI/Frontend.cpp | 58 
 clang/lib/InstallAPI/Visitor.cpp  | 94 +++
 clang/test/InstallAPI/basic.test  |  5 +
 clang/test/InstallAPI/variables.test  | 63 +
 .../clang-installapi/ClangInstallAPI.cpp  | 78 +--
 clang/tools/clang-installapi/Options.cpp  | 29 ++
 clang/tools/clang-installapi/Options.h|  8 ++
 12 files changed, 474 insertions(+), 8 deletions(-)
 create mode 100644 clang/include/clang/InstallAPI/Frontend.h
 create mode 100644 clang/include/clang/InstallAPI/Visitor.h
 create mode 100644 clang/lib/InstallAPI/Frontend.cpp
 create mode 100644 clang/lib/InstallAPI/Visitor.cpp
 create mode 100644 clang/test/InstallAPI/variables.test

diff --git a/clang/include/clang/InstallAPI/Context.h 
b/clang/include/clang/InstallAPI/Context.h
index 7d105920734fde..292992908aa129 100644
--- a/clang/include/clang/InstallAPI/Context.h
+++ b/clang/include/clang/InstallAPI/Context.h
@@ -9,6 +9,9 @@
 #ifndef LLVM_CLANG_INSTALLAPI_CONTEXT_H
 #define LLVM_CLANG_INSTALLAPI_CONTEXT_H
 
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/FileManager.h"
+#include "clang/InstallAPI/HeaderFile.h"
 #include "llvm/TextAPI/InterfaceFile.h"
 #include "llvm/TextAPI/RecordVisitor.h"
 #include "llvm/TextAPI/RecordsSlice.h"
@@ -24,8 +27,23 @@ struct InstallAPIContext {
   /// Library attributes that are typically passed as linker inputs.
   llvm::MachO::RecordsSlice::BinaryAttrs BA;
 
-  /// Active target triple to parse.
-  llvm::Triple TargetTriple{};
+  /// All headers that represent a library.
+  HeaderSeq InputHeaders;
+
+  /// Active language mode to parse in.
+  Language LangMode = Language::ObjC;
+
+  /// Active header access type.
+  HeaderType Type = HeaderType::Unknown;
+
+  /// Active TargetSlice for symbol record collection.
+  std::shared_ptr Records;
+
+  /// FileManager for all I/O operations.
+  FileManager *FM = nullptr;
+
+  /// DiagnosticsEngine for all error reporting.
+  DiagnosticsEngine *Diags = nullptr;
 
   /// File Path of output location.
   llvm::StringRef OutputLoc{};
diff --git a/clang/include/clang/InstallAPI/Frontend.h 
b/clang/include/clang/InstallAPI/Frontend.h
new file mode 100644
index 00..7ee87ae028d079
--- /dev/null
+++ b/clang/include/clang/InstallAPI/Frontend.h
@@ -0,0 +1,48 @@
+//===- InstallAPI/Frontend.h ---*- 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
+//
+//===--===//
+///
+/// Top level wrappers for InstallAPI frontend operations.
+///
+//===--===//
+
+#ifndef LLVM_CLANG_INSTALLAPI_FRONTEND_H
+#define LLVM_CLANG_INSTALLAPI_FRONTEND_H
+
+#include "clang/AST/ASTConsumer.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Frontend/FrontendActions.h"
+#include "clang/InstallAPI/Context.h"
+#include "clang/InstallAPI/Visitor.h"
+#include "llvm/ADT/Twine.h"
+#include "llvm/Support/MemoryBuffer.h"
+
+namespace clang {
+namespace installapi {
+
+/// Create a buffer that contains all headers to scan
+/// for global symbols with.
+std::unique_ptr
+createInputBuffer(const InstallAPIContext );
+
+class InstallAPIAction : public ASTFrontendAction {
+public:
+  explicit InstallAPIAction(llvm::MachO::RecordsSlice )
+  : Records(Records) {}
+
+  std::unique_ptr CreateASTConsumer(CompilerInstance ,
+ StringRef InFile) override {
+return std::make_unique(CI.getASTContext(), Records);
+  }
+
+private:
+  llvm::MachO::RecordsSlice 
+};
+} // namespace installapi
+} // namespace clang
+
+#endif // LLVM_CLANG_INSTALLAPI_FRONTEND_H
diff --git a/clang/include/clang/InstallAPI/HeaderFile.h 
b/clang/include/clang/InstallAPI/HeaderFile.h
index fc64a43b3def5c..70e83bbb3e76f6 100644
--- a/clang/include/clang/InstallAPI/HeaderFile.h
+++ 

[clang] [llvm] [openmp] [PGO][OpenMP] Instrumentation for GPU devices (PR #76587)

2024-02-27 Thread Ethan Luis McDonough via cfe-commits

https://github.com/EthanLuisMcDonough updated 
https://github.com/llvm/llvm-project/pull/76587

>From 530eb982b9770190377bb0bd09c5cb715f34d484 Mon Sep 17 00:00:00 2001
From: Ethan Luis McDonough 
Date: Fri, 15 Dec 2023 20:38:38 -0600
Subject: [PATCH 01/18] Add profiling functions to libomptarget

---
 .../include/llvm/Frontend/OpenMP/OMPKinds.def |  3 +++
 openmp/libomptarget/DeviceRTL/CMakeLists.txt  |  2 ++
 .../DeviceRTL/include/Profiling.h | 21 +++
 .../libomptarget/DeviceRTL/src/Profiling.cpp  | 19 +
 4 files changed, 45 insertions(+)
 create mode 100644 openmp/libomptarget/DeviceRTL/include/Profiling.h
 create mode 100644 openmp/libomptarget/DeviceRTL/src/Profiling.cpp

diff --git a/llvm/include/llvm/Frontend/OpenMP/OMPKinds.def 
b/llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
index d22d2a8e948b00..1d887d5cb58127 100644
--- a/llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
+++ b/llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
@@ -503,6 +503,9 @@ __OMP_RTL(__kmpc_barrier_simple_generic, false, Void, 
IdentPtr, Int32)
 __OMP_RTL(__kmpc_warp_active_thread_mask, false, Int64,)
 __OMP_RTL(__kmpc_syncwarp, false, Void, Int64)
 
+__OMP_RTL(__llvm_profile_register_function, false, Void, VoidPtr)
+__OMP_RTL(__llvm_profile_register_names_function, false, Void, VoidPtr, Int64)
+
 __OMP_RTL(__last, false, Void, )
 
 #undef __OMP_RTL
diff --git a/openmp/libomptarget/DeviceRTL/CMakeLists.txt 
b/openmp/libomptarget/DeviceRTL/CMakeLists.txt
index 1ce3e1e40a80ab..55ee15d068c67b 100644
--- a/openmp/libomptarget/DeviceRTL/CMakeLists.txt
+++ b/openmp/libomptarget/DeviceRTL/CMakeLists.txt
@@ -89,6 +89,7 @@ set(include_files
   ${include_directory}/Interface.h
   ${include_directory}/LibC.h
   ${include_directory}/Mapping.h
+  ${include_directory}/Profiling.h
   ${include_directory}/State.h
   ${include_directory}/Synchronization.h
   ${include_directory}/Types.h
@@ -104,6 +105,7 @@ set(src_files
   ${source_directory}/Mapping.cpp
   ${source_directory}/Misc.cpp
   ${source_directory}/Parallelism.cpp
+  ${source_directory}/Profiling.cpp
   ${source_directory}/Reduction.cpp
   ${source_directory}/State.cpp
   ${source_directory}/Synchronization.cpp
diff --git a/openmp/libomptarget/DeviceRTL/include/Profiling.h 
b/openmp/libomptarget/DeviceRTL/include/Profiling.h
new file mode 100644
index 00..68c7744cd60752
--- /dev/null
+++ b/openmp/libomptarget/DeviceRTL/include/Profiling.h
@@ -0,0 +1,21 @@
+//=== Profiling.h - OpenMP interface -- 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 OMPTARGET_DEVICERTL_PROFILING_H
+#define OMPTARGET_DEVICERTL_PROFILING_H
+
+extern "C" {
+
+void __llvm_profile_register_function(void *ptr);
+void __llvm_profile_register_names_function(void *ptr, long int i);
+}
+
+#endif
diff --git a/openmp/libomptarget/DeviceRTL/src/Profiling.cpp 
b/openmp/libomptarget/DeviceRTL/src/Profiling.cpp
new file mode 100644
index 00..799477f5e47d27
--- /dev/null
+++ b/openmp/libomptarget/DeviceRTL/src/Profiling.cpp
@@ -0,0 +1,19 @@
+//===--- Profiling.cpp  C++ 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "Profiling.h"
+
+#pragma omp begin declare target device_type(nohost)
+
+extern "C" {
+
+void __llvm_profile_register_function(void *ptr) {}
+void __llvm_profile_register_names_function(void *ptr, long int i) {}
+}
+
+#pragma omp end declare target

>From fb067d4ffe604fd68cf90b705db1942bce49dbb1 Mon Sep 17 00:00:00 2001
From: Ethan Luis McDonough 
Date: Sat, 16 Dec 2023 01:18:41 -0600
Subject: [PATCH 02/18] Fix PGO instrumentation for GPU targets

---
 clang/lib/CodeGen/CodeGenPGO.cpp  | 10 --
 .../lib/Transforms/Instrumentation/InstrProfiling.cpp | 11 ---
 2 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/clang/lib/CodeGen/CodeGenPGO.cpp b/clang/lib/CodeGen/CodeGenPGO.cpp
index 81bf8ea696b164..edae6885b528ac 100644
--- a/clang/lib/CodeGen/CodeGenPGO.cpp
+++ b/clang/lib/CodeGen/CodeGenPGO.cpp
@@ -959,8 +959,14 @@ void CodeGenPGO::emitCounterIncrement(CGBuilderTy 
, const Stmt *S,
 
   unsigned Counter = (*RegionCounterMap)[S];
 
-  llvm::Value *Args[] = {FuncNameVar,
- Builder.getInt64(FunctionHash),
+  // Make sure that pointer to global is passed in with zero addrspace
+  // This is 

[clang] [clang][test] Add test for incompatible cv-qualified reference types in conversion function template (PR #81950)

2024-02-27 Thread Duo Wang via cfe-commits

wdunicornpro wrote:

@zygoloid Sorry about the abrupt ping but I figured you might have the best 
knowledge about that part of code. Do you have any thoughts on this?

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


[clang] [Clang] [Sema] Handle `this` in `__restrict`-qualified member functions properly (PR #83187)

2024-02-27 Thread via cfe-commits

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


[clang] [clang][test] Add test for incompatible cv-qualified reference types in conversion function template (PR #81950)

2024-02-27 Thread Duo Wang via cfe-commits

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


[clang] [Driver] Allow -fbasic-block-address-map for AArch64 ELF (PR #82662)

2024-02-27 Thread Daniel Hoekwater via cfe-commits

https://github.com/dhoekwater updated 
https://github.com/llvm/llvm-project/pull/82662

>From 11c8f1f843de68c35e8e33f992765df1bbcdbfb9 Mon Sep 17 00:00:00 2001
From: Daniel Hoekwater 
Date: Thu, 22 Feb 2024 17:39:15 +
Subject: [PATCH] [Driver] Allow -fbasic-block-address-map for AArch64 ELF

Emitting the basic block address map with
`-fbasic-block-sections=labels` is allowed for AArch64 ELF since
7eaf94fefa1250fc8a46982cea8ce99abacae11f. Allow doing so with
`-fbasic-block-address-map`.
---
 clang/lib/Driver/ToolChains/Clang.cpp   | 2 +-
 clang/test/Driver/basic-block-address-map.c | 7 ---
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index dbfc729bba24c7..40a75f35900ab7 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -5959,7 +5959,7 @@ void Clang::ConstructJob(Compilation , const JobAction 
,
 
   if (Arg *A = Args.getLastArg(options::OPT_fbasic_block_address_map,
options::OPT_fno_basic_block_address_map)) {
-if (Triple.isX86() && Triple.isOSBinFormatELF()) {
+if ((Triple.isX86() || Triple.isAArch64()) && Triple.isOSBinFormatELF()) {
   if (A->getOption().matches(options::OPT_fbasic_block_address_map))
 A->render(Args, CmdArgs);
 } else {
diff --git a/clang/test/Driver/basic-block-address-map.c 
b/clang/test/Driver/basic-block-address-map.c
index 022f972b412d6b..12393e8ebfd54e 100644
--- a/clang/test/Driver/basic-block-address-map.c
+++ b/clang/test/Driver/basic-block-address-map.c
@@ -1,8 +1,9 @@
-// RUN: %clang -### -target x86_64 -fbasic-block-address-map %s -S 2>&1 | 
FileCheck -check-prefix=CHECK-PRESENT %s
+// RUN: %clang -### --target=x86_64 -fbasic-block-address-map %s -S 2>&1 | 
FileCheck -check-prefix=CHECK-PRESENT %s
+// RUN: %clang -### --target=aarch64 -fbasic-block-address-map %s -S 2>&1 | 
FileCheck -check-prefix=CHECK-PRESENT %s
 // CHECK-PRESENT: -fbasic-block-address-map
 
-// RUN: %clang -### -target x86_64 -fno-basic-block-address-map %s -S 2>&1 | 
FileCheck %s --check-prefix=CHECK-ABSENT
+// RUN: %clang -### --target=x86_64 -fno-basic-block-address-map %s -S 2>&1 | 
FileCheck %s --check-prefix=CHECK-ABSENT
 // CHECK-ABSENT-NOT: -fbasic-block-address-map
 
-// RUN: not %clang -c -target x86_64-apple-darwin10 -fbasic-block-address-map 
%s -S 2>&1 | FileCheck -check-prefix=CHECK-TRIPLE %s
+// RUN: not %clang -c --target=x86_64-apple-darwin10 -fbasic-block-address-map 
%s -S 2>&1 | FileCheck -check-prefix=CHECK-TRIPLE %s
 // CHECK-TRIPLE: error: unsupported option '-fbasic-block-address-map' for 
target

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


[clang] [Driver] Allow -fbasic-block-address-map for AArch64 ELF (PR #82662)

2024-02-27 Thread Daniel Hoekwater via cfe-commits


@@ -1,4 +1,5 @@
 // RUN: %clang -### -target x86_64 -fbasic-block-address-map %s -S 2>&1 | 
FileCheck -check-prefix=CHECK-PRESENT %s
+// RUN: %clang -### -target aarch64 -fbasic-block-address-map %s -S 2>&1 | 
FileCheck -check-prefix=CHECK-PRESENT %s

dhoekwater wrote:

Done!

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


[clang] [CLANG][DWARF] Do not emit -ggnu-pubnames for split dwarf version 5. (PR #82840)

2024-02-27 Thread Alexander Yermolovich via cfe-commits

ayermolo wrote:

> Looks this breaks tests on macOS: http://45.33.8.238/macm1/79435/step_7.txt
> 
> Please take a look and revert for now if it takes a while to fix.



> Looks this breaks tests on macOS: http://45.33.8.238/macm1/79435/step_7.txt
> 
> Please take a look and revert for now if it takes a while to fix.

Looks like it's just one test that checks for -ggnu-pubnames. Let me take a 
look.

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


[clang] [Clang] [Sema] Handle `__restrict`-qualified member functions properly (PR #83187)

2024-02-27 Thread via cfe-commits

Sirraide wrote:

CC @shafik, @AaronBallman 

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


[clang] [Clang] [Sema] Handle `__restrict`-qualified member functions properly (PR #83187)

2024-02-27 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (Sirraide)


Changes

When resolving the type of `this` inside a member function, we were attaching 
all qualifiers present on the member function to the class type and then making 
it a pointer; however, `__restrict`, unlike `const` and `volatile`, needs to be 
attached to the pointer type rather than the pointee type.

This fixes #82941.

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


4 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+3) 
- (modified) clang/lib/AST/DeclCXX.cpp (+13-2) 
- (modified) clang/lib/Sema/SemaExprCXX.cpp (+1-1) 
- (added) clang/test/SemaCXX/restrict-this.cpp (+51) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7e16b9f0c67dbd..d420f572a84487 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -290,6 +290,9 @@ Bug Fixes to C++ Support
   lookup searches the bases of an incomplete class.
 - Fix a crash when an unresolved overload set is encountered on the RHS of a 
``.*`` operator.
   (`#53815 `_)
+- In ``__restrict``-qualified member functions, attach ``__restrict`` to the 
pointer type of
+  ``this`` rather than the pointee type.
+  Fixes (`#82941 `_).
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/AST/DeclCXX.cpp b/clang/lib/AST/DeclCXX.cpp
index 117e802dae2d9d..b4f2327d9c560a 100644
--- a/clang/lib/AST/DeclCXX.cpp
+++ b/clang/lib/AST/DeclCXX.cpp
@@ -2543,8 +2543,19 @@ QualType CXXMethodDecl::getThisType(const 
FunctionProtoType *FPT,
 const CXXRecordDecl *Decl) {
   ASTContext  = Decl->getASTContext();
   QualType ObjectTy = ::getThisObjectType(C, FPT, Decl);
-  return C.getLangOpts().HLSL ? C.getLValueReferenceType(ObjectTy)
-  : C.getPointerType(ObjectTy);
+
+  // Unlike 'const' and 'volatile', a '__restrict' qualifier must be
+  // attached to the pointer type, not the pointee.
+  bool Restrict = FPT->getMethodQuals().hasRestrict();
+  if (Restrict)
+ObjectTy.removeLocalRestrict();
+
+  ObjectTy = C.getLangOpts().HLSL ? C.getLValueReferenceType(ObjectTy)
+  : C.getPointerType(ObjectTy);
+
+  if (Restrict)
+ObjectTy.addRestrict();
+  return ObjectTy;
 }
 
 QualType CXXMethodDecl::getThisType() const {
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 59758d3bd6d1a3..c4750ce78fa9c1 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -1220,7 +1220,7 @@ static QualType adjustCVQualifiersForCXXThisWithinLambda(
 : nullptr;
 }
   }
-  return ASTCtx.getPointerType(ClassType);
+  return ThisTy;
 }
 
 QualType Sema::getCurrentThisType() {
diff --git a/clang/test/SemaCXX/restrict-this.cpp 
b/clang/test/SemaCXX/restrict-this.cpp
new file mode 100644
index 00..8cd89f0f36a76c
--- /dev/null
+++ b/clang/test/SemaCXX/restrict-this.cpp
@@ -0,0 +1,51 @@
+// RUN: %clang_cc1 -verify -fsyntax-only %s
+// expected-no-diagnostics
+
+struct C {
+  void f() __restrict {
+static_assert(__is_same(decltype(this), C *__restrict));
+(void) [this]() {
+  static_assert(__is_same(decltype(this), C *__restrict));
+  (void) [this]() { static_assert(__is_same(decltype(this), C 
*__restrict)); };
+
+  // By-value capture means 'this' is now a different object; do not
+  // make it __restrict.
+  (void) [*this]() { static_assert(__is_same(decltype(this), const C *)); 
};
+  (void) [*this]() mutable { static_assert(__is_same(decltype(this), C 
*)); };
+};
+  }
+};
+
+template  struct TC {
+  void f() __restrict {
+static_assert(__is_same(decltype(this), TC *__restrict));
+(void) [this]() {
+  static_assert(__is_same(decltype(this), TC *__restrict));
+  (void) [this]() { static_assert(__is_same(decltype(this), TC 
*__restrict)); };
+
+  // By-value capture means 'this' is now a different object; do not
+  // make it __restrict.
+  (void) [*this]() { static_assert(__is_same(decltype(this), const TC 
*)); };
+  (void) [*this]() mutable { static_assert(__is_same(decltype(this), 
TC *)); };
+};
+  }
+};
+
+void f() {
+  TC{}.f();
+}
+
+namespace gh82941 {
+void f(int& x) {
+(void)x;
+}
+
+class C {
+int x;
+void g() __restrict;
+};
+
+void C::g() __restrict {
+f(this->x);
+}
+}

``




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


[clang] [Clang] [Sema] Handle `__restrict`-qualified member functions properly (PR #83187)

2024-02-27 Thread via cfe-commits

https://github.com/Sirraide created 
https://github.com/llvm/llvm-project/pull/83187

When resolving the type of `this` inside a member function, we were attaching 
all qualifiers present on the member function to the class type and then making 
it a pointer; however, `__restrict`, unlike `const` and `volatile`, needs to be 
attached to the pointer type rather than the pointee type.

This fixes #82941.

>From e9df22166fd5768e11273446cb9e52953e55cd5d Mon Sep 17 00:00:00 2001
From: Sirraide 
Date: Tue, 27 Feb 2024 22:07:23 +0100
Subject: [PATCH 1/3] [Clang] [Sema] Handle __restrict-qualified member
 functions properly

---
 clang/lib/AST/DeclCXX.cpp| 15 ++--
 clang/lib/Sema/SemaExprCXX.cpp   |  2 +-
 clang/test/SemaCXX/restrict-this.cpp | 51 
 3 files changed, 65 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/SemaCXX/restrict-this.cpp

diff --git a/clang/lib/AST/DeclCXX.cpp b/clang/lib/AST/DeclCXX.cpp
index 117e802dae2d9d..b4f2327d9c560a 100644
--- a/clang/lib/AST/DeclCXX.cpp
+++ b/clang/lib/AST/DeclCXX.cpp
@@ -2543,8 +2543,19 @@ QualType CXXMethodDecl::getThisType(const 
FunctionProtoType *FPT,
 const CXXRecordDecl *Decl) {
   ASTContext  = Decl->getASTContext();
   QualType ObjectTy = ::getThisObjectType(C, FPT, Decl);
-  return C.getLangOpts().HLSL ? C.getLValueReferenceType(ObjectTy)
-  : C.getPointerType(ObjectTy);
+
+  // Unlike 'const' and 'volatile', a '__restrict' qualifier must be
+  // attached to the pointer type, not the pointee.
+  bool Restrict = FPT->getMethodQuals().hasRestrict();
+  if (Restrict)
+ObjectTy.removeLocalRestrict();
+
+  ObjectTy = C.getLangOpts().HLSL ? C.getLValueReferenceType(ObjectTy)
+  : C.getPointerType(ObjectTy);
+
+  if (Restrict)
+ObjectTy.addRestrict();
+  return ObjectTy;
 }
 
 QualType CXXMethodDecl::getThisType() const {
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 59758d3bd6d1a3..c4750ce78fa9c1 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -1220,7 +1220,7 @@ static QualType adjustCVQualifiersForCXXThisWithinLambda(
 : nullptr;
 }
   }
-  return ASTCtx.getPointerType(ClassType);
+  return ThisTy;
 }
 
 QualType Sema::getCurrentThisType() {
diff --git a/clang/test/SemaCXX/restrict-this.cpp 
b/clang/test/SemaCXX/restrict-this.cpp
new file mode 100644
index 00..79c6081f904275
--- /dev/null
+++ b/clang/test/SemaCXX/restrict-this.cpp
@@ -0,0 +1,51 @@
+// RUN: %clang_cc1 -verify -fsyntax-only %s
+// expected-no-diagnostics
+
+struct C {
+  void f() __restrict {
+static_assert(__is_same(decltype(this), C *__restrict));
+(void) [this]() {
+  static_assert(__is_same(decltype(this), C *__restrict));
+  (void) [this]() { static_assert(__is_same(decltype(this), C 
*__restrict)); };
+
+  // By-value capture means 'this' is now a different object; do not
+  // make it __restrict.
+  (void) [*this]() { static_assert(__is_same(decltype(this), const C *)); 
};
+  (void) [*this]() mutable { static_assert(__is_same(decltype(this), C 
*)); };
+};
+  }
+};
+
+template  struct TC {
+  void f() __restrict {
+static_assert(__is_same(decltype(this), TC *__restrict));
+(void) [this]() {
+  static_assert(__is_same(decltype(this), TC *__restrict));
+  (void) [this]() { static_assert(__is_same(decltype(this), TC 
*__restrict)); };
+
+  // By-value capture means 'this' is now a different object; do not
+  // make it __restrict.
+  (void) [*this]() { static_assert(__is_same(decltype(this), const TC 
*)); };
+  (void) [*this]() mutable { static_assert(__is_same(decltype(this), 
TC *)); };
+};
+  }
+};
+
+void f() {
+  TC{}.f();
+}
+
+namespace gh82941 {
+void f(int& x) {
+(void)x;
+}
+
+class C {
+int x;
+void g() __restrict;
+};
+
+void C::g() __restrict {
+f(this->x);
+}
+}
\ No newline at end of file

>From c3031a9699582391e25e1bccd58fad59fbec379b Mon Sep 17 00:00:00 2001
From: Sirraide 
Date: Tue, 27 Feb 2024 22:13:09 +0100
Subject: [PATCH 2/3] [Clang] Update release notes

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

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7e16b9f0c67dbd..d420f572a84487 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -290,6 +290,9 @@ Bug Fixes to C++ Support
   lookup searches the bases of an incomplete class.
 - Fix a crash when an unresolved overload set is encountered on the RHS of a 
``.*`` operator.
   (`#53815 `_)
+- In ``__restrict``-qualified member functions, attach ``__restrict`` to the 
pointer type of
+  ``this`` rather than the pointee type.
+  Fixes (`#82941 `_).
 
 Bug Fixes to AST Handling
 

[clang] [llvm] Modify BoundsSan to improve debuggability (PR #65972)

2024-02-27 Thread Oskar Wirga via cfe-commits

oskarwirga wrote:

> @oskarwirga I'd like to use this feature but without counter, preserving 
> ubsan IDs
> 
> Also I think in the current the counter has limited use: in optimized code, 
> after inlining, it will have a lot of same ids, like 0, 1 from different 
> functions.
> 
> So I propose to undo that part of the patch. WDYT?

So long as the debuggability is preserved so that it is possible to attribute 
crashes to specific lines of code, I am fine! Do you have an alternate 
solution? 

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


[clang] [llvm] Modify BoundsSan to improve debuggability (PR #65972)

2024-02-27 Thread Vitaly Buka via cfe-commits

vitalybuka wrote:

oskarwirga@ I'd like to use this feature but without counter, preserving ubsan 
IDs

Also I think in the current the counter has limited use: in optimized code, 
after inlining, it will have a lot of same ids, like 0, 1 from different 
functions.

So I propose to undo that part of the patch. WDYT?

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


[clang] [CLANG][DWARF] Do not emit -ggnu-pubnames for split dwarf version 5. (PR #82840)

2024-02-27 Thread Nico Weber via cfe-commits

nico wrote:

Looks this breaks tests on macOS: http://45.33.8.238/macm1/79435/step_7.txt

Please take a look and revert for now if it takes a while to fix.

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


[clang] [clang] Extend define-target-os-macros to support XROS. (PR #82833)

2024-02-27 Thread via cfe-commits

github-actions[bot] wrote:



@rohit-rao Congratulations on having your first Pull Request (PR) merged into 
the LLVM Project!

Your changes will be combined with recent changes from other authors, then 
tested
by our [build bots](https://lab.llvm.org/buildbot/). If there is a problem with 
a build, you may recieve a report in an email or a comment on this PR.

Please check whether problems have been caused by your change specifically, as
the builds can include changes from many authors. It is not uncommon for your
change to be included in a build that fails due to someone else's changes, or
infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail 
[here](https://llvm.org/docs/MyFirstTypoFix.html#myfirsttypofix-issues-after-landing-your-pr).

If your change does cause a problem, it may be reverted, or you can revert it 
yourself.
This is a normal part of [LLVM 
development](https://llvm.org/docs/DeveloperPolicy.html#patch-reversion-policy).
 You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are 
working as expected, well done!


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


[clang] [clang] Extend define-target-os-macros to support XROS. (PR #82833)

2024-02-27 Thread Leonard Grey via cfe-commits

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


[clang] e5ed7b6 - [clang] Extend define-target-os-macros to support XROS. (#82833)

2024-02-27 Thread via cfe-commits

Author: rohit-rao
Date: 2024-02-27T15:23:00-05:00
New Revision: e5ed7b6e2fd368b722b6359556cd0125881e7638

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

LOG: [clang] Extend define-target-os-macros to support XROS. (#82833)

Updates the extension feature `define-target-os-macros` to support the
recently-added XROS target (TARGET_OS_VISION).

Added: 


Modified: 
clang/include/clang/Basic/TargetOSMacros.def
clang/test/Driver/fdefine-target-os-macros.c

Removed: 




diff  --git a/clang/include/clang/Basic/TargetOSMacros.def 
b/clang/include/clang/Basic/TargetOSMacros.def
index dfc2e033f6fd0d..58dce330f9c8fd 100644
--- a/clang/include/clang/Basic/TargetOSMacros.def
+++ b/clang/include/clang/Basic/TargetOSMacros.def
@@ -34,18 +34,19 @@ TARGET_OS(TARGET_OS_UNIX, Triple.isOSNetBSD() ||
 TARGET_OS(TARGET_OS_MAC, Triple.isOSDarwin())
 TARGET_OS(TARGET_OS_OSX, Triple.isMacOSX())
 TARGET_OS(TARGET_OS_IPHONE, Triple.isiOS() || Triple.isTvOS() ||
-Triple.isWatchOS())
+Triple.isWatchOS() || Triple.isXROS())
 // Triple::isiOS() also includes tvOS
 TARGET_OS(TARGET_OS_IOS, Triple.getOS() == llvm::Triple::IOS)
 TARGET_OS(TARGET_OS_TV, Triple.isTvOS())
 TARGET_OS(TARGET_OS_WATCH, Triple.isWatchOS())
+TARGET_OS(TARGET_OS_VISION, Triple.isXROS())
 TARGET_OS(TARGET_OS_DRIVERKIT, Triple.isDriverKit())
 TARGET_OS(TARGET_OS_MACCATALYST, Triple.isMacCatalystEnvironment())
 TARGET_OS(TARGET_OS_SIMULATOR, Triple.isSimulatorEnvironment())
 
 // Deprecated Apple target conditionals.
 TARGET_OS(TARGET_OS_EMBEDDED, (Triple.isiOS() || Triple.isTvOS() \
-   || Triple.isWatchOS()) \
+   || Triple.isWatchOS() || Triple.isXROS()) \
&& !Triple.isMacCatalystEnvironment() \
&& !Triple.isSimulatorEnvironment())
 TARGET_OS(TARGET_OS_NANO, Triple.isWatchOS())

diff  --git a/clang/test/Driver/fdefine-target-os-macros.c 
b/clang/test/Driver/fdefine-target-os-macros.c
index d7379dd3d5396b..a4de51e8e7244b 100644
--- a/clang/test/Driver/fdefine-target-os-macros.c
+++ b/clang/test/Driver/fdefine-target-os-macros.c
@@ -12,6 +12,7 @@
 // RUN:-DIOS=0 \
 // RUN:-DTV=0  \
 // RUN:-DWATCH=0   \
+// RUN:-DVISION=0  \
 // RUN:-DDRIVERKIT=0   \
 // RUN:-DMACCATALYST=0 \
 // RUN:-DEMBEDDED=0\
@@ -27,6 +28,7 @@
 // RUN:-DIOS=1 \
 // RUN:-DTV=0  \
 // RUN:-DWATCH=0   \
+// RUN:-DVISION=0  \
 // RUN:-DDRIVERKIT=0   \
 // RUN:-DMACCATALYST=0 \
 // RUN:-DEMBEDDED=1\
@@ -42,6 +44,7 @@
 // RUN:-DIOS=1 \
 // RUN:-DTV=0  \
 // RUN:-DWATCH=0   \
+// RUN:-DVISION=0  \
 // RUN:-DDRIVERKIT=0   \
 // RUN:-DMACCATALYST=1 \
 // RUN:-DEMBEDDED=0\
@@ -57,6 +60,7 @@
 // RUN:-DIOS=1 \
 // RUN:-DTV=0  \
 // RUN:-DWATCH=0   \
+// RUN:-DVISION=0  \
 // RUN:-DDRIVERKIT=0   \
 // RUN:-DMACCATALYST=0 \
 // RUN:-DEMBEDDED=0\
@@ -72,6 +76,7 @@
 // RUN:-DIOS=0 \
 // RUN:-DTV=1  \
 // RUN:-DWATCH=0   \
+// RUN:-DVISION=0  \
 // RUN:-DDRIVERKIT=0   \
 // RUN:-DMACCATALYST=0 \
 // RUN:-DEMBEDDED=1\
@@ -87,6 +92,7 @@
 // RUN:-DIOS=0 \
 // RUN:-DTV=1  \
 // RUN:-DWATCH=0   \
+// RUN:-DVISION=0  \
 // RUN:-DDRIVERKIT=0   \
 // RUN:-DMACCATALYST=0 \
 // RUN:-DEMBEDDED=0\
@@ -102,6 +108,7 @@
 // RUN:-DIOS=0 \
 // RUN:-DTV=0  \
 // RUN:-DWATCH=1   \
+// RUN:-DVISION=0  \
 // RUN:-DDRIVERKIT=0   \
 // RUN:-DMACCATALYST=0 \
 // RUN:-DEMBEDDED=1\
@@ -117,6 +124,39 @@
 // RUN:-DIOS=0 \
 // RUN:-DTV=0  \
 // RUN:-DWATCH=1   \
+// RUN:-DVISION=0  \
+// RUN:-DDRIVERKIT=0   \
+// RUN:-DMACCATALYST=0 \
+// RUN:-DEMBEDDED=0\
+// RUN:-DSIMULATOR=1   \
+// RUN:-DWINDOWS=0   

[clang] [compiler-rt] [llvm] [IRPGO][ValueProfile] Instrument virtual table address that could be used to do virtual table address comparision for indirect-call-promotion. (PR #66825)

2024-02-27 Thread Mingming Liu via cfe-commits

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


  1   2   3   4   >