[clang] [clang-tools-extra] [libcxx] [clang] improved preservation of template keyword (PR #133610)

2025-04-07 Thread Devon Loehr via cfe-commits

DKLoehr wrote:

I ended up with the following reproducer:
```
template  struct S {
  template 
using Arg = T::template Arg;
  void f(Arg);
  void f(Arg);
};
```

Running this with `clang++ repro.cc -fsyntax-only -std=c++20` yields
```
repro.cc:5:8: error: class member cannot be redeclared
5 |   void f(Arg);
  |^
repro.cc:4:8: note: previous declaration is here
4 |   void f(Arg);
  |^
```

The same error occurs regardless of which types are inside the < >.

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


[clang-tools-extra] [clang-doc][NFC] refactor out file helpers (PR #134298)

2025-04-07 Thread Paul Kirth via cfe-commits


@@ -0,0 +1,72 @@
+//===-- FileHelpersClangDoc.cpp - File Helpers ---*- 
C++-*-===//

ilovepi wrote:

Apparently, we don't use that line anymore. 
https://llvm.org/docs/CodingStandards.html#file-headers

Was brought up here when I saw this the first time: 
https://github.com/llvm/llvm-project/pull/111487#discussion_r2028191191

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


[clang-tools-extra] [clang-doc][NFC] refactor out file helpers (PR #134298)

2025-04-07 Thread Paul Kirth via cfe-commits

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


[clang] [HLSL] Implement the dst HLSL Function (PR #133828)

2025-04-07 Thread Ashley Coleman via cfe-commits


@@ -0,0 +1,57 @@
+// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple 
dxil-pc-shadermodel6.2-library %s -fnative-half-type -emit-llvm 
-disable-llvm-passes -o - | FileCheck %s
+
+
+// CHECK-LABEL: linkonce_odr noundef nofpclass(nan inf) <4 x float> 
@_ZN4hlsl8__detail8dst_implIfEEDv4_T_S3_S3_(
+// CHECK-SAME: <4 x float> noundef nofpclass(nan inf) [[P:%.*]], <4 x float> 
noundef nofpclass(nan inf) [[Q:%.*]]) #[[ATTR0:[0-9]+]] { 
+// CHECK: [[VECEXT:%.*]] = extractelement <4 x float> [[PADDR:%.*]], i32 1
+// CHECK: [[VECEXT1:%.*]] = extractelement <4 x float> [[QADDR:%.*]], i32 1
+// CHECK: [[MULRES:%.*]] = fmul reassoc nnan ninf nsz arcp afn float 
[[VECEXT]], [[VECEXT1]]

V-FEXrt wrote:

Not as confident here, but I think it also applies. 

We care about `fmul`, `float`, `vecext`, and `vecext1` so we should only check 
those things

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


[clang] [OpenACC][CIR] Basic infrastructure for OpenACC lowering (PR #134717)

2025-04-07 Thread Erich Keane via cfe-commits

https://github.com/erichkeane updated 
https://github.com/llvm/llvm-project/pull/134717

>From 0c0892e5142e2d0f687c091cb55ea14c97c975eb Mon Sep 17 00:00:00 2001
From: erichkeane 
Date: Mon, 7 Apr 2025 08:07:18 -0700
Subject: [PATCH 1/3] [OpenACC][CIR] Basic infrastructure for OpenACC lowering

This is the first of a few patches that will do infrastructure work to
enable the OpenACC lowering via the OpenACC dialect.

At the moment this just gets the various function calls that will end up
generating OpenACC, plus some tests to validate that we're doing the
diagnostics in OpenACC specific locations.

Additionally, this adds Stmt and Decl files for CIRGen.
---
 clang/include/clang/AST/DeclOpenACC.h |  2 +
 clang/include/clang/AST/GlobalDecl.h  |  3 +
 .../clang/Basic/DiagnosticDriverKinds.td  |  5 +
 clang/lib/AST/DeclOpenACC.cpp |  5 +
 clang/lib/CIR/CodeGen/CIRGenDecl.cpp  |  7 ++
 clang/lib/CIR/CodeGen/CIRGenFunction.h| 30 ++
 clang/lib/CIR/CodeGen/CIRGenModule.cpp| 12 +++
 clang/lib/CIR/CodeGen/CIRGenModule.h  |  2 +
 clang/lib/CIR/CodeGen/CIRGenOpenACCDecl.cpp   | 33 +++
 clang/lib/CIR/CodeGen/CIRGenOpenACCStmt.cpp   | 91 +++
 clang/lib/CIR/CodeGen/CIRGenStmt.cpp  | 25 -
 clang/lib/CIR/CodeGen/CMakeLists.txt  |  2 +
 clang/lib/Frontend/CompilerInvocation.cpp | 49 ++
 .../openacc-not-implemented-global.cpp|  6 ++
 .../openacc-not-implemented.cpp   | 20 
 clang/test/Driver/openacc-no-cir.c|  6 ++
 16 files changed, 293 insertions(+), 5 deletions(-)
 create mode 100644 clang/lib/CIR/CodeGen/CIRGenOpenACCDecl.cpp
 create mode 100644 clang/lib/CIR/CodeGen/CIRGenOpenACCStmt.cpp
 create mode 100644 
clang/test/CIR/CodeGenOpenACC/openacc-not-implemented-global.cpp
 create mode 100644 clang/test/CIR/CodeGenOpenACC/openacc-not-implemented.cpp
 create mode 100644 clang/test/Driver/openacc-no-cir.c

diff --git a/clang/include/clang/AST/DeclOpenACC.h 
b/clang/include/clang/AST/DeclOpenACC.h
index 26cf721561fb1..8c612fbf1ec07 100644
--- a/clang/include/clang/AST/DeclOpenACC.h
+++ b/clang/include/clang/AST/DeclOpenACC.h
@@ -59,6 +59,8 @@ class OpenACCConstructDecl : public Decl {
   }
 
   ArrayRef clauses() const { return Clauses; }
+  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
+  static bool classofKind(Kind K);
 };
 
 class OpenACCDeclareDecl final
diff --git a/clang/include/clang/AST/GlobalDecl.h 
b/clang/include/clang/AST/GlobalDecl.h
index 386693cabb1fb..8bf2eb2a5b78f 100644
--- a/clang/include/clang/AST/GlobalDecl.h
+++ b/clang/include/clang/AST/GlobalDecl.h
@@ -17,6 +17,7 @@
 #include "clang/AST/Attr.h"
 #include "clang/AST/DeclCXX.h"
 #include "clang/AST/DeclObjC.h"
+#include "clang/AST/DeclOpenACC.h"
 #include "clang/AST/DeclOpenMP.h"
 #include "clang/AST/DeclTemplate.h"
 #include "clang/Basic/ABI.h"
@@ -86,6 +87,8 @@ class GlobalDecl {
   GlobalDecl(const ObjCMethodDecl *D) { Init(D); }
   GlobalDecl(const OMPDeclareReductionDecl *D) { Init(D); }
   GlobalDecl(const OMPDeclareMapperDecl *D) { Init(D); }
+  GlobalDecl(const OpenACCRoutineDecl *D) { Init(D); }
+  GlobalDecl(const OpenACCDeclareDecl *D) { Init(D); }
   GlobalDecl(const CXXConstructorDecl *D, CXXCtorType Type) : Value(D, Type) {}
   GlobalDecl(const CXXDestructorDecl *D, CXXDtorType Type) : Value(D, Type) {}
   GlobalDecl(const VarDecl *D, DynamicInitKind StubKind)
diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index df24cca49aaae..3f671c88f3148 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -849,4 +849,9 @@ def warn_missing_include_dirs : Warning<
 
 def err_drv_malformed_warning_suppression_mapping : Error<
   "failed to process suppression mapping file '%0': %1">;
+
+def warn_drv_openacc_without_cir
+: Warning<"OpenACC directives will result in no runtime behavior, use "
+  "-fclangir to enable runtime effect">,
+  InGroup;
 }
diff --git a/clang/lib/AST/DeclOpenACC.cpp b/clang/lib/AST/DeclOpenACC.cpp
index 760c08d21cccd..e0fe7be8fc1a3 100644
--- a/clang/lib/AST/DeclOpenACC.cpp
+++ b/clang/lib/AST/DeclOpenACC.cpp
@@ -17,6 +17,11 @@
 
 using namespace clang;
 
+bool OpenACCConstructDecl::classofKind(Kind K) {
+  return OpenACCDeclareDecl::classofKind(K) ||
+ OpenACCRoutineDecl::classofKind(K);
+}
+
 OpenACCDeclareDecl *
 OpenACCDeclareDecl::Create(ASTContext &Ctx, DeclContext *DC,
SourceLocation StartLoc, SourceLocation DirLoc,
diff --git a/clang/lib/CIR/CodeGen/CIRGenDecl.cpp 
b/clang/lib/CIR/CodeGen/CIRGenDecl.cpp
index 5b832b463e752..d0eb648683e8c 100644
--- a/clang/lib/CIR/CodeGen/CIRGenDecl.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenDecl.cpp
@@ -15,6 +15,7 @@
 #include "mlir/IR/Location.h"
 #include "clang/AST/Attr.h"
 #include "clang/AST/Decl.h"
+#include 

[clang] [HLSL] Implement the `lit` intrinsic (PR #134171)

2025-04-07 Thread Deric C. via cfe-commits

Icohedron wrote:

In my opinion, we should just define `lit` without templates, thereby following 
Clang's overload resolution rules and allowing implicit vector truncation. 
Overload resolution and implicit vector truncation are behaviors that should be 
consistent across the language. To me, it feels wrong to have special-case 
behavior on language-defining features implemented/overridden on a per-function 
basis.

Implicit vector truncation is also an area that needs addressing as a problem 
with the language, rather than being a special-case behavior handled by each 
function's implementation. Again, a compiler warning would go a long way to 
addressing problems where implicit truncation may not be intended by the 
programmer.
```
warning: implicit truncation of vector type [-Wconversion]
```
Or maybe implicit truncation should be removed from the language entirely (for 
202y perhaps)?

If you can make the behavior consistent with DXC under all cases with some 
special implementation in hlsl_compat_overloads for 202x, then you can do that, 
but I don't think we should be writing an implementation that matches DXC now 
and then rewrite it entirely again when we swap to 202y that makes the language 
more consistent (which is one of our goals for HLSL's future, right?)

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


[clang] [HLSL] Implement the `lit` intrinsic (PR #134171)

2025-04-07 Thread Deric C. via cfe-commits


@@ -280,6 +280,22 @@ constexpr bool4 isinf(double4 V) { return 
isinf((float4)V); }
 _DXC_COMPAT_TERNARY_DOUBLE_OVERLOADS(lerp)
 _DXC_COMPAT_TERNARY_INTEGER_OVERLOADS(lerp)
 
+//===--===//
+// lit builtins overloads
+//===--===//
+
+template 
+constexpr __detail::enable_if_t<__detail::is_arithmetic::Value &&
+(__detail::is_same::value ||

Icohedron wrote:

I don't understand why `lit(bool,bool,bool)` isn't ambiguous.

C++ doesn't have half types, but defining two functions 
`lit(float,float,float)` and `lit(double,double,double)` and then calling 
`lit(bool,bool,bool)` results in a compilation error `error: call to 'lit' is 
ambiguous` as seen here: https://godbolt.org/z/Y3ThTfEs9
Is there special case handling for overload resolution implemented for HLSL?

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


[clang] [clang][modules] Name the module map files on PCM file conflict (PR #134475)

2025-04-07 Thread Cyndy Ishida via cfe-commits


@@ -6067,14 +6062,21 @@ llvm::Error ASTReader::ReadSubmoduleBlock(ModuleFile &F,
 if (OptionalFileEntryRef CurFile = CurrentModule->getASTFile()) {
   // Don't emit module relocation error if we have -fno-validate-pch
   if (!bool(PP.getPreprocessorOpts().DisablePCHOrModuleValidation &
-DisableValidationForModuleKind::Module) &&
-  CurFile != F.File) {
-auto ConflictError =
-PartialDiagnostic(diag::err_module_file_conflict,
-  ContextObj->DiagAllocator)
+DisableValidationForModuleKind::Module)) {
+assert(CurFile != F.File && "ModuleManager did not de-duplicate");
+
+Diag(diag::err_module_file_conflict)
 << CurrentModule->getTopLevelModuleName() << CurFile->getName()
 << F.File.getName();
-return DiagnosticError::create(CurrentImportLoc, ConflictError);
+
+auto CurModMapFile =
+ModMap.getContainingModuleMapFile(CurrentModule);
+auto ModMapFile = FileMgr.getOptionalFileRef(F.ModuleMapPath);
+if (CurModMapFile && ModMapFile && CurModMapFile != ModMapFile)

cyndyishida wrote:

When do the file references return false in practice? If the file was deleted 
or something during the build? If so, so it may still be helpful to print out 
where the modulemap was expected to be (or where it was when the module was 
created)

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


[clang] Move CodeGen cuda.h to Inputs from include (PR #134706)

2025-04-07 Thread via cfe-commits

github-actions[bot] wrote:



@calewis 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 receive 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/134706
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [CIR] Upstream initial function call support (PR #134673)

2025-04-07 Thread Sirui Mu via cfe-commits

https://github.com/Lancern created 
https://github.com/llvm/llvm-project/pull/134673

This PR upstreams initial support for making function calls in CIR. Function 
arguments and return values are not included to keep the patch small for review.

Related to #132487

>From 82f6ce93ca22dd778173100231523706e2739546 Mon Sep 17 00:00:00 2001
From: Sirui Mu 
Date: Mon, 7 Apr 2025 22:54:49 +0800
Subject: [PATCH] [CIR] Upstream initial function call support

---
 .../CIR/Dialect/Builder/CIRBaseBuilder.h  | 13 +++
 clang/include/clang/CIR/Dialect/IR/CIROps.td  | 37 +++
 .../clang/CIR/Interfaces/CIROpInterfaces.td   |  9 ++
 clang/include/clang/CIR/MissingFeatures.h | 24 +
 clang/lib/CIR/CodeGen/CIRGenCall.cpp  | 95 ++
 clang/lib/CIR/CodeGen/CIRGenCall.h| 58 +++
 clang/lib/CIR/CodeGen/CIRGenExpr.cpp  | 97 +++
 clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp| 13 +++
 clang/lib/CIR/CodeGen/CIRGenFunction.h| 20 
 clang/lib/CIR/CodeGen/CIRGenFunctionInfo.h| 34 +++
 clang/lib/CIR/CodeGen/CIRGenModule.cpp| 13 ++-
 clang/lib/CIR/CodeGen/CIRGenModule.h  |  6 ++
 clang/lib/CIR/CodeGen/CIRGenTypes.cpp | 30 ++
 clang/lib/CIR/CodeGen/CIRGenTypes.h   | 11 +++
 clang/lib/CIR/CodeGen/CMakeLists.txt  |  1 +
 clang/lib/CIR/Dialect/IR/CIRDialect.cpp   | 81 
 clang/test/CIR/CodeGen/call.cpp   |  9 ++
 17 files changed, 550 insertions(+), 1 deletion(-)
 create mode 100644 clang/lib/CIR/CodeGen/CIRGenCall.cpp
 create mode 100644 clang/lib/CIR/CodeGen/CIRGenFunctionInfo.h
 create mode 100644 clang/test/CIR/CodeGen/call.cpp

diff --git a/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h 
b/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h
index c1e93fe790c08..dda3ecf492506 100644
--- a/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h
+++ b/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h
@@ -201,6 +201,19 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
 return create(loc, base.getType(), base, stride);
   }
 
+  
//======//
+  // Call operators
+  
//======//
+
+  cir::CallOp createCallOp(mlir::Location loc, mlir::SymbolRefAttr callee) {
+auto op = create(loc, callee);
+return op;
+  }
+
+  cir::CallOp createCallOp(mlir::Location loc, cir::FuncOp callee) {
+return createCallOp(loc, mlir::SymbolRefAttr::get(callee));
+  }
+
   
//======//
   // Cast/Conversion Operators
   
//======//
diff --git a/clang/include/clang/CIR/Dialect/IR/CIROps.td 
b/clang/include/clang/CIR/Dialect/IR/CIROps.td
index 609e60ca74b49..aa805ee4108da 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIROps.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIROps.td
@@ -1242,6 +1242,43 @@ def FuncOp : CIR_Op<"func", [
   let hasVerifier = 1;
 }
 
+//===--===//
+// CallOp
+//===--===//
+
+class CIR_CallOp extra_traits = []>
+: Op,
+  DeclareOpInterfaceMethods])> {
+  let hasCustomAssemblyFormat = 1;
+  let skipDefaultBuilders = 1;
+  let hasVerifier = 0;
+
+  dag commonArgs = (ins FlatSymbolRefAttr:$callee);
+}
+
+def CallOp : CIR_CallOp<"call", [NoRegionArguments]> {
+  let summary = "call a function";
+  let description = [{
+The `cir.call` operation represents a direct call to a function that is
+within the same symbol scope as the call. The callee is encoded as a symbol
+reference attribute named `callee`.
+
+Example:
+
+```mlir
+%0 = cir.call @foo()
+```
+  }];
+
+  let arguments = commonArgs;
+
+  let builders = [OpBuilder<(ins "mlir::SymbolRefAttr":$callee), [{
+  $_state.addAttribute("callee", callee);
+}]>];
+}
+
 
//===--===//
 // UnreachableOp
 
//===--===//
diff --git a/clang/include/clang/CIR/Interfaces/CIROpInterfaces.td 
b/clang/include/clang/CIR/Interfaces/CIROpInterfaces.td
index 39ef402c59e43..c6c6356118ac6 100644
--- a/clang/include/clang/CIR/Interfaces/CIROpInterfaces.td
+++ b/clang/include/clang/CIR/Interfaces/CIROpInterfaces.td
@@ -15,8 +15,17 @@
 
 include "mlir/IR/OpBase.td"
 include "mlir/IR/SymbolInterfaces.td"
+include "mlir/Interfaces/CallInterfaces.td"
 
 let cppNamespace = "::cir" in {
+  // The CIRCallOpInterface must be used instead of CallOpInterface when 
looking
+  // at arguments and other bits of CallOp. This creates a level of abstraction
+  // that's useful for handling indirect calls and other details.
+  def CIRCallOpI

[clang] [Clang] Unify 'nvptx-arch' and 'amdgpu-arch' into 'offload-arch' (PR #134713)

2025-04-07 Thread Shilei Tian via cfe-commits


@@ -0,0 +1,78 @@
+//===- OffloadArch.cpp - list available GPUs *- 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 "clang/Basic/Version.h"
+#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/Path.h"
+
+using namespace llvm;
+
+static cl::opt Help("h", cl::desc("Alias for -help"), cl::Hidden);
+
+// Mark all our options with this category.
+static cl::OptionCategory OffloadArchCategory("amdgpu-arch options");
+
+cl::opt Verbose("verbose", cl::desc("Enable verbose output"),
+  cl::init(false), cl::cat(OffloadArchCategory));
+
+cl::opt AMDGPU("amdgpu-only", cl::desc("Print only AMD GPUs"),
+ cl::init(false), cl::cat(OffloadArchCategory));
+
+cl::opt NVPTX("nvptx-only", cl::desc("Print only NVIDIA GPUs"),
+cl::init(false), cl::cat(OffloadArchCategory));
+
+static void PrintVersion(raw_ostream &OS) {
+  OS << clang::getClangToolFullVersion("offload-arch") << '\n';
+}
+
+int printGPUsByKFD();
+int printGPUsByHIP();
+int printGPUsByCUDA();
+
+int printAMD() {
+#ifndef _WIN32
+  if (!printGPUsByKFD())
+return 0;
+#endif
+
+  return printGPUsByHIP();
+}
+
+int printNVIDIA() { return printGPUsByCUDA(); }
+
+int main(int argc, char *argv[]) {
+  cl::HideUnrelatedOptions(OffloadArchCategory);
+
+  cl::SetVersionPrinter(PrintVersion);
+  cl::ParseCommandLineOptions(
+  argc, argv,
+  "A tool to detect the presence of offloading devices on the system. \n\n"
+  "The tool will output each detected GPU architecture separated by a\n"
+  "newline character. If multiple GPUs of the same architecture are 
found\n"
+  "a string will be printed for each\n");
+
+  if (Help) {
+cl::PrintHelpMessage();
+return 0;
+  }
+
+  // If this was invoked from the legacy symlinks provide the same behavior.
+  bool AMDGPUOnly = AMDGPU || sys::path::filename(argv[0]) == "amdgpu-arch";

shiltian wrote:

Maybe add some sort of things like `-###` and then print the command?

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


[clang] [Clang][OpenCL][AMDGPU] Allow a kernel to call another kernel (PR #115821)

2025-04-07 Thread via cfe-commits

github-actions[bot] wrote:



@lalaniket8 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 receive 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/115821
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [CIR] Upstream ArraySubscriptExpr for fixed size array (PR #134536)

2025-04-07 Thread Andy Kaylor via cfe-commits


@@ -232,6 +233,161 @@ LValue CIRGenFunction::emitUnaryOpLValue(const 
UnaryOperator *e) {
   llvm_unreachable("Unknown unary operator kind!");
 }
 
+/// If the specified expr is a simple decay from an array to pointer,
+/// return the array subexpression.
+/// FIXME: this could be abstracted into a common AST helper.
+static const Expr *isSimpleArrayDecayOperand(const Expr *e) {
+  // If this isn't just an array->pointer decay, bail out.
+  const auto *castExpr = dyn_cast(e);
+  if (!castExpr || castExpr->getCastKind() != CK_ArrayToPointerDecay)
+return nullptr;
+
+  // If this is a decay from variable width array, bail out.
+  const Expr *subExpr = castExpr->getSubExpr();
+  if (subExpr->getType()->isVariableArrayType())
+return nullptr;
+
+  return subExpr;
+}
+
+static mlir::IntegerAttr getConstantIndexOrNull(mlir::Value idx) {
+  // TODO(cir): should we consider using MLIRs IndexType instead of 
IntegerAttr?
+  if (auto constantOp = dyn_cast(idx.getDefiningOp()))
+return mlir::dyn_cast(constantOp.getValue());
+  return {};
+}
+
+static CharUnits getArrayElementAlign(CharUnits arrayAlign, mlir::Value idx,
+  CharUnits eltSize) {
+  // If we have a constant index, we can use the exact offset of the
+  // element we're accessing.
+  const mlir::IntegerAttr constantIdx = getConstantIndexOrNull(idx);
+  if (constantIdx) {
+const CharUnits offset = constantIdx.getValue().getZExtValue() * eltSize;
+return arrayAlign.alignmentAtOffset(offset);
+  }
+  // Otherwise, use the worst-case alignment for any element.
+  return arrayAlign.alignmentOfArrayElement(eltSize);
+}
+
+static QualType getFixedSizeElementType(const ASTContext &astContext,
+const VariableArrayType *vla) {
+  QualType eltType;
+  do {
+eltType = vla->getElementType();
+  } while ((vla = astContext.getAsVariableArrayType(eltType)));
+  return eltType;
+}
+
+static mlir::Value
+emitArraySubscriptPtr(CIRGenFunction &cgf, mlir::Location beginLoc,
+  mlir::Location endLoc, mlir::Value ptr, mlir::Type eltTy,
+  ArrayRef indices, bool inbounds,
+  bool signedIndices, bool shouldDecay,
+  const llvm::Twine &name = "arrayidx") {
+  if (indices.size() > 1) {
+cgf.cgm.errorNYI("emitArraySubscriptPtr: handle multiple indices");
+return {};
+  }
+
+  const mlir::Value idx = indices.back();
+  CIRGenModule &cgm = cgf.getCIRGenModule();
+  // TODO(cir): LLVM codegen emits in bound gep check here, is there anything
+  // that would enhance tracking this later in CIR?
+  if (inbounds)
+assert(!cir::MissingFeatures::emitCheckedInBoundsGEP() && "NYI");
+  return cgm.getBuilder().getArrayElement(beginLoc, endLoc, ptr, eltTy, idx,
+  shouldDecay);
+}
+
+static Address emitArraySubscriptPtr(
+CIRGenFunction &cgf, mlir::Location beginLoc, mlir::Location endLoc,
+Address addr, ArrayRef indices, QualType eltType,
+bool inbounds, bool signedIndices, mlir::Location loc, bool shouldDecay,
+QualType *arrayType = nullptr, const Expr *base = nullptr,
+const llvm::Twine &name = "arrayidx") {
+
+  // Determine the element size of the statically-sized base.  This is
+  // the thing that the indices are expressed in terms of.
+  if (const VariableArrayType *vla =
+  cgf.getContext().getAsVariableArrayType(eltType)) {
+eltType = getFixedSizeElementType(cgf.getContext(), vla);
+  }
+
+  // We can use that to compute the best alignment of the element.
+  const CharUnits eltSize = cgf.getContext().getTypeSizeInChars(eltType);
+  const CharUnits eltAlign =
+  getArrayElementAlign(addr.getAlignment(), indices.back(), eltSize);
+
+  mlir::Value eltPtr;
+  const mlir::IntegerAttr lastIndex = getConstantIndexOrNull(indices.back());
+  if (!lastIndex) {
+eltPtr = emitArraySubscriptPtr(cgf, beginLoc, endLoc, addr.getPointer(),
+   addr.getElementType(), indices, inbounds,
+   signedIndices, shouldDecay, name);
+  }
+  const mlir::Type elementType = cgf.convertTypeForMem(eltType);
+  return Address(eltPtr, elementType, eltAlign);
+}
+
+LValue
+CIRGenFunction::emitArraySubscriptExpr(const clang::ArraySubscriptExpr *e) {
+  if (e->getBase()->getType()->isVectorType() &&
+  !isa(e->getBase())) {
+cgm.errorNYI(e->getSourceRange(), "emitArraySubscriptExpr: VectorType");
+return {};

andykaylor wrote:

Can we emit a dummy value of the element type here and in the other NYI cases?

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


[clang] [CodeGen] Change placeholder from `undef` to `poison` (PR #134731)

2025-04-07 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-codegen

Author: Pedro Lobo (pedroclobo)


Changes

Fill default values of a map with `poison` instead of `undef`. There should be 
no functional difference as the default values are overridden later.

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


1 Files Affected:

- (modified) clang/lib/CodeGen/MicrosoftCXXABI.cpp (+1-1) 


``diff
diff --git a/clang/lib/CodeGen/MicrosoftCXXABI.cpp 
b/clang/lib/CodeGen/MicrosoftCXXABI.cpp
index ba5f74f153d59..7bef436302526 100644
--- a/clang/lib/CodeGen/MicrosoftCXXABI.cpp
+++ b/clang/lib/CodeGen/MicrosoftCXXABI.cpp
@@ -370,7 +370,7 @@ class MicrosoftCXXABI : public CGCXXABI {
 MicrosoftVTableContext &VTContext = CGM.getMicrosoftVTableContext();
 unsigned NumEntries = 1 + SrcRD->getNumVBases();
 SmallVector Map(NumEntries,
- llvm::UndefValue::get(CGM.IntTy));
+ llvm::PoisonValue::get(CGM.IntTy));
 Map[0] = llvm::ConstantInt::get(CGM.IntTy, 0);
 bool AnyDifferent = false;
 for (const auto &I : SrcRD->vbases()) {

``




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


[clang] [HLSL] Implement the dst HLSL Function (PR #133828)

2025-04-07 Thread via cfe-commits

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


[clang] [llvm] [DirectX] Use scalar arguments for @llvm.dx.dot intrinsics (PR #134570)

2025-04-07 Thread Farzon Lotfi via cfe-commits


@@ -185,8 +186,14 @@ static Value *expandFloatDotIntrinsic(CallInst *Orig, 
Value *A, Value *B) {
 /* gen_crash_diag=*/false);
 return nullptr;
   }
-  return Builder.CreateIntrinsic(ATy->getScalarType(), DotIntrinsic,
- ArrayRef{A, B}, nullptr, "dot");
+
+  SmallVector Args;
+  for (int I = 0; I < NumElts; ++I)

farzonl wrote:

Now that we had the new DirectX target builtins I had another thought on how to 
do this that would elimate our convert one intrinsic to another intrinsic trick 
we are doing here. Just expose dot2, dot3, and dot4 in the frontend. If we are 
comfortable with doing scalarization in the frontend for dot2add then does it 
make sense to do that for these fdot cases?

Downside is we would need sema check for these 3 new cases which seems like 
overkill and maybe disqualifies this idea.

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


[clang] [llvm] [NVPTX] Add builtins and intrinsics for conversions of new FP types (PR #134345)

2025-04-07 Thread Srinivasa Ravi via cfe-commits


@@ -580,6 +580,15 @@ def __nvvm_f2bf16_rz : 
NVPTXBuiltinSMAndPTX<"__bf16(float)", SM_80, PTX70>;
 def __nvvm_f2bf16_rz_relu : NVPTXBuiltinSMAndPTX<"__bf16(float)", SM_80, 
PTX70>;
 
 def __nvvm_f2tf32_rna : NVPTXBuiltinSMAndPTX<"int32_t(float)", SM_80, PTX70>;
+def __nvvm_f2tf32_rna_satfinite : NVPTXBuiltinSMAndPTX<"int32_t(float)", 
SM_89, PTX81>;

Wolfram70 wrote:

Updated the summary and description, thanks!

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


[clang] [llvm] [NVPTX] Add builtins and intrinsics for conversions of new FP types (PR #134345)

2025-04-07 Thread Srinivasa Ravi via cfe-commits

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


[clang] [llvm] [NVPTX] Add builtins and intrinsics for conversions of new FP types (PR #134345)

2025-04-07 Thread Srinivasa Ravi via cfe-commits


@@ -703,6 +703,53 @@ let hasSideEffects = false in {
   defm CVT_to_tf32_rz_satf : CVT_TO_TF32<"rz.satfinite", [hasPTX<86>, 
hasSM<100>]>;
   defm CVT_to_tf32_rn_relu_satf  : CVT_TO_TF32<"rn.relu.satfinite", 
[hasPTX<86>, hasSM<100>]>;
   defm CVT_to_tf32_rz_relu_satf  : CVT_TO_TF32<"rz.relu.satfinite", 
[hasPTX<86>, hasSM<100>]>;
+
+  // FP6 conversions.
+  multiclass CVT_TO_F6X2 {
+def _f32 :
+  NVPTXInst<(outs Int16Regs:$dst),
+(ins Float32Regs:$src1, Float32Regs:$src2, CvtMode:$mode),
+!strconcat("cvt${mode:base}.satfinite${mode:relu}.",
+F6Name, "x2.f32 \t$dst, $src1, $src2;"), []>;
+  }
+
+  defm CVT_e2m3x2 : CVT_TO_F6X2<"e2m3">;
+  defm CVT_e3m2x2 : CVT_TO_F6X2<"e3m2">;
+
+  class CVT_f16x2_fp6 :
+NVPTXInst<(outs Int32Regs:$dst),
+  (ins Int16Regs:$src, CvtMode:$mode),
+  !strconcat("cvt${mode:base}${mode:relu}.f16x2.",
+  F6Name, "x2 \t$dst, $src;"), []>;

Wolfram70 wrote:

Fixed in the latest revision.

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


[clang] [HLSL] Implement the `lit` intrinsic (PR #134171)

2025-04-07 Thread Kaitlin Peng via cfe-commits

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


[clang] [CIR] Upstream ArraySubscriptExpr for fixed size array (PR #134536)

2025-04-07 Thread Andy Kaylor via cfe-commits


@@ -232,6 +233,161 @@ LValue CIRGenFunction::emitUnaryOpLValue(const 
UnaryOperator *e) {
   llvm_unreachable("Unknown unary operator kind!");
 }
 
+/// If the specified expr is a simple decay from an array to pointer,
+/// return the array subexpression.
+/// FIXME: this could be abstracted into a common AST helper.
+static const Expr *isSimpleArrayDecayOperand(const Expr *e) {

andykaylor wrote:

```suggestion
static const Expr *getSimpleArrayDecayOperand(const Expr *e) {
```
Functions starting with "is" should return bool. Since that's not what we want 
here, the name shouldn't suggest it is.

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


[clang] [CodeGen] Change placeholder from `undef` to `poison` (PR #134731)

2025-04-07 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Pedro Lobo (pedroclobo)


Changes

Fill default values of a map with `poison` instead of `undef`. There should be 
no functional difference as the default values are overridden later.

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


1 Files Affected:

- (modified) clang/lib/CodeGen/MicrosoftCXXABI.cpp (+1-1) 


``diff
diff --git a/clang/lib/CodeGen/MicrosoftCXXABI.cpp 
b/clang/lib/CodeGen/MicrosoftCXXABI.cpp
index ba5f74f153d59..7bef436302526 100644
--- a/clang/lib/CodeGen/MicrosoftCXXABI.cpp
+++ b/clang/lib/CodeGen/MicrosoftCXXABI.cpp
@@ -370,7 +370,7 @@ class MicrosoftCXXABI : public CGCXXABI {
 MicrosoftVTableContext &VTContext = CGM.getMicrosoftVTableContext();
 unsigned NumEntries = 1 + SrcRD->getNumVBases();
 SmallVector Map(NumEntries,
- llvm::UndefValue::get(CGM.IntTy));
+ llvm::PoisonValue::get(CGM.IntTy));
 Map[0] = llvm::ConstantInt::get(CGM.IntTy, 0);
 bool AnyDifferent = false;
 for (const auto &I : SrcRD->vbases()) {

``




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


[clang] [RFC] Initial implementation of P2719 (PR #113510)

2025-04-07 Thread Oliver Hunt via cfe-commits

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


[clang] [llvm] [mlir] [MLIR][OpenMP] Add codegen for teams reductions (PR #133310)

2025-04-07 Thread Jan Leyonberg via cfe-commits

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


[clang] [Clang] Unify 'nvptx-arch' and 'amdgpu-arch' into 'offload-arch' (PR #134713)

2025-04-07 Thread Joseph Huber via cfe-commits

https://github.com/jhuber6 updated 
https://github.com/llvm/llvm-project/pull/134713

>From e44db82f3abe7c1d23c2b49094c92a890127ffc7 Mon Sep 17 00:00:00 2001
From: Joseph Huber 
Date: Mon, 7 Apr 2025 14:37:22 -0500
Subject: [PATCH 1/6] [Clang] Unify 'nvptx-arch' and 'amdgpu-arch' into
 'offload-arch'

Summary:
These two tools do the same thing, we should unify them into a single
tool. We create symlinks for backward compatiblity and provide a way to
get the old vendor specific behavior with `--amdgpu-only` and
`--nvptx-only`.
---
 clang/tools/CMakeLists.txt|  3 +-
 clang/tools/amdgpu-arch/AMDGPUArch.cpp| 56 -
 clang/tools/amdgpu-arch/CMakeLists.txt| 13 
 clang/tools/nvptx-arch/CMakeLists.txt | 12 ---
 .../AMDGPUArchByHIP.cpp   |  0
 .../AMDGPUArchByKFD.cpp   |  0
 clang/tools/offload-arch/CMakeLists.txt   |  8 ++
 .../NVPTXArch.cpp | 26 +--
 clang/tools/offload-arch/OffloadArch.cpp  | 78 +++
 9 files changed, 88 insertions(+), 108 deletions(-)
 delete mode 100644 clang/tools/amdgpu-arch/AMDGPUArch.cpp
 delete mode 100644 clang/tools/amdgpu-arch/CMakeLists.txt
 delete mode 100644 clang/tools/nvptx-arch/CMakeLists.txt
 rename clang/tools/{amdgpu-arch => offload-arch}/AMDGPUArchByHIP.cpp (100%)
 rename clang/tools/{amdgpu-arch => offload-arch}/AMDGPUArchByKFD.cpp (100%)
 create mode 100644 clang/tools/offload-arch/CMakeLists.txt
 rename clang/tools/{nvptx-arch => offload-arch}/NVPTXArch.cpp (80%)
 create mode 100644 clang/tools/offload-arch/OffloadArch.cpp

diff --git a/clang/tools/CMakeLists.txt b/clang/tools/CMakeLists.txt
index e3557c1328d53..9634eb12080c8 100644
--- a/clang/tools/CMakeLists.txt
+++ b/clang/tools/CMakeLists.txt
@@ -50,5 +50,4 @@ add_llvm_external_project(clang-tools-extra extra)
 # libclang may require clang-tidy in clang-tools-extra.
 add_clang_subdirectory(libclang)
 
-add_clang_subdirectory(amdgpu-arch)
-add_clang_subdirectory(nvptx-arch)
+add_clang_subdirectory(offload-arch)
diff --git a/clang/tools/amdgpu-arch/AMDGPUArch.cpp 
b/clang/tools/amdgpu-arch/AMDGPUArch.cpp
deleted file mode 100644
index 86f3e31f47bbc..0
--- a/clang/tools/amdgpu-arch/AMDGPUArch.cpp
+++ /dev/null
@@ -1,56 +0,0 @@
-//===- AMDGPUArch.cpp - list AMDGPU installed --*- 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
-//
-//===--===//
-//
-// This file implements a tool for detecting name of AMDGPU installed in 
system.
-// This tool is used by AMDGPU OpenMP and HIP driver.
-//
-//===--===//
-
-#include "clang/Basic/Version.h"
-#include "llvm/Support/CommandLine.h"
-
-using namespace llvm;
-
-static cl::opt Help("h", cl::desc("Alias for -help"), cl::Hidden);
-
-// Mark all our options with this category.
-static cl::OptionCategory AMDGPUArchCategory("amdgpu-arch options");
-
-cl::opt Verbose("verbose", cl::desc("Enable verbose output"),
-  cl::init(false), cl::cat(AMDGPUArchCategory));
-
-static void PrintVersion(raw_ostream &OS) {
-  OS << clang::getClangToolFullVersion("amdgpu-arch") << '\n';
-}
-
-int printGPUsByKFD();
-int printGPUsByHIP();
-
-int main(int argc, char *argv[]) {
-  cl::HideUnrelatedOptions(AMDGPUArchCategory);
-
-  cl::SetVersionPrinter(PrintVersion);
-  cl::ParseCommandLineOptions(
-  argc, argv,
-  "A tool to detect the presence of AMDGPU devices on the system. \n\n"
-  "The tool will output each detected GPU architecture separated by a\n"
-  "newline character. If multiple GPUs of the same architecture are 
found\n"
-  "a string will be printed for each\n");
-
-  if (Help) {
-cl::PrintHelpMessage();
-return 0;
-  }
-
-#ifndef _WIN32
-  if (!printGPUsByKFD())
-return 0;
-#endif
-
-  return printGPUsByHIP();
-}
diff --git a/clang/tools/amdgpu-arch/CMakeLists.txt 
b/clang/tools/amdgpu-arch/CMakeLists.txt
deleted file mode 100644
index c4c8de614565a..0
--- a/clang/tools/amdgpu-arch/CMakeLists.txt
+++ /dev/null
@@ -1,13 +0,0 @@
-# 
//===--===//
-# //
-# // Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
-# // See https://llvm.org/LICENSE.txt for details.
-# // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-# //
-# 
//===--===//
-
-set(LLVM_LINK_COMPONENTS Support)
-
-add_clang_tool(amdgpu-arch AMDGPUArch.cpp AMDGPUArchByKFD.cpp 
AMDGPUArchByHIP.cpp)
-
-target_link_libraries(amdgpu-arch PRIVATE clangBasic)
diff --git a/clang/tools/nvptx-arch/CMakeLists.txt 
b/clang/tools/nvptx-

[clang] bdd0870 - [clang][bytecode] Fix various issues with multidimensional arrays (#134628)

2025-04-07 Thread via cfe-commits

Author: Timm Baeder
Date: 2025-04-08T05:48:55+02:00
New Revision: bdd087023f02fb377302595bf7f61e9cae8adb71

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

LOG: [clang][bytecode] Fix various issues with multidimensional arrays (#134628)

This issue is very convoluted, but in essence, in the new version:

For a Pointer P that points to the root of a multidimensional, primitive
array:

`P.narrow()` does nothing.
`P.atIndex(0)` points `P[0]`
`P.atIndex(0).atIndex(0)` is the same as `P.atIndex(0)` (as before)
`P.atIndex(0).narrow().atIndex(0)` points to `P[0][0]`
`P.atIndex(0).narrow().narrow()` is the same as `P.atIndex(0).narrow()`.

Added: 


Modified: 
clang/lib/AST/ByteCode/Compiler.cpp
clang/lib/AST/ByteCode/Interp.h
clang/lib/AST/ByteCode/Pointer.h
clang/test/AST/ByteCode/arrays.cpp

Removed: 




diff  --git a/clang/lib/AST/ByteCode/Compiler.cpp 
b/clang/lib/AST/ByteCode/Compiler.cpp
index 021acbd798646..dd246f7ef74fc 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -6148,7 +6148,8 @@ bool Compiler::VisitUnaryOperator(const 
UnaryOperator *E) {
 
 if (!this->visit(SubExpr))
   return false;
-if (classifyPrim(SubExpr) == PT_Ptr && !E->getType()->isArrayType())
+
+if (classifyPrim(SubExpr) == PT_Ptr)
   return this->emitNarrowPtr(E);
 return true;
 

diff  --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h
index 6fe1d4b1f95ae..ee69cea039990 100644
--- a/clang/lib/AST/ByteCode/Interp.h
+++ b/clang/lib/AST/ByteCode/Interp.h
@@ -2059,8 +2059,11 @@ bool OffsetHelper(InterpState &S, CodePtr OpPC, const T 
&Offset,
   // useful thing we can do. Any other index has been diagnosed before and
   // we don't get here.
   if (Result == 0 && Ptr.isOnePastEnd()) {
-S.Stk.push(Ptr.asBlockPointer().Pointee,
-Ptr.asBlockPointer().Base);
+if (Ptr.getFieldDesc()->isArray())
+  S.Stk.push(Ptr.atIndex(0));
+else
+  S.Stk.push(Ptr.asBlockPointer().Pointee,
+  Ptr.asBlockPointer().Base);
 return true;
   }
 
@@ -2677,8 +2680,16 @@ inline bool ArrayElemPtr(InterpState &S, CodePtr OpPC) {
   return false;
   }
 
-  if (!OffsetHelper(S, OpPC, Offset, Ptr))
-return false;
+  if (Offset.isZero()) {
+if (Ptr.getFieldDesc()->isArray() && Ptr.getIndex() == 0) {
+  S.Stk.push(Ptr.atIndex(0));
+} else {
+  S.Stk.push(Ptr);
+}
+  } else {
+if (!OffsetHelper(S, OpPC, Offset, Ptr))
+  return false;
+  }
 
   return NarrowPtr(S, OpPC);
 }
@@ -2693,8 +2704,16 @@ inline bool ArrayElemPtrPop(InterpState &S, CodePtr 
OpPC) {
   return false;
   }
 
-  if (!OffsetHelper(S, OpPC, Offset, Ptr))
-return false;
+  if (Offset.isZero()) {
+if (Ptr.getFieldDesc()->isArray() && Ptr.getIndex() == 0) {
+  S.Stk.push(Ptr.atIndex(0));
+} else {
+  S.Stk.push(Ptr);
+}
+  } else {
+if (!OffsetHelper(S, OpPC, Offset, Ptr))
+  return false;
+  }
 
   return NarrowPtr(S, OpPC);
 }

diff  --git a/clang/lib/AST/ByteCode/Pointer.h 
b/clang/lib/AST/ByteCode/Pointer.h
index 988237d39fff4..64af5ed9b0a5d 100644
--- a/clang/lib/AST/ByteCode/Pointer.h
+++ b/clang/lib/AST/ByteCode/Pointer.h
@@ -200,37 +200,28 @@ class Pointer {
 if (isZero() || isUnknownSizeArray())
   return *this;
 
+unsigned Base = asBlockPointer().Base;
 // Pointer to an array of base types - enter block.
-if (asBlockPointer().Base == RootPtrMark)
+if (Base == RootPtrMark)
   return Pointer(asBlockPointer().Pointee, sizeof(InlineDescriptor),
  Offset == 0 ? Offset : PastEndMark);
 
 // Pointer is one past end - magic offset marks that.
 if (isOnePastEnd())
-  return Pointer(asBlockPointer().Pointee, asBlockPointer().Base,
- PastEndMark);
-
-// Primitive arrays are a bit special since they do not have inline
-// descriptors. If Offset != Base, then the pointer already points to
-// an element and there is nothing to do. Otherwise, the pointer is
-// adjusted to the first element of the array.
-if (inPrimitiveArray()) {
-  if (Offset != asBlockPointer().Base)
+  return Pointer(asBlockPointer().Pointee, Base, PastEndMark);
+
+if (Offset != Base) {
+  // If we're pointing to a primitive array element, there's nothing to do.
+  if (inPrimitiveArray())
 return *this;
-  return Pointer(asBlockPointer().Pointee, asBlockPointer().Base,
- Offset + sizeof(InitMapPtr));
+  // Pointer is to a composite array element - enter it.
+  if (Offset != Base)
+return Pointer(asBlockPointer().Pointee, Offset, Offset);
 }
 
-// Pointer is to a field or array element - enter it.

[clang] [Clang] Unify 'nvptx-arch' and 'amdgpu-arch' into 'offload-arch' (PR #134713)

2025-04-07 Thread Joseph Huber via cfe-commits


@@ -0,0 +1,78 @@
+//===- OffloadArch.cpp - list available GPUs *- 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 "clang/Basic/Version.h"
+#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/Path.h"
+
+using namespace llvm;
+
+static cl::opt Help("h", cl::desc("Alias for -help"), cl::Hidden);
+
+// Mark all our options with this category.
+static cl::OptionCategory OffloadArchCategory("amdgpu-arch options");
+
+cl::opt Verbose("verbose", cl::desc("Enable verbose output"),
+  cl::init(false), cl::cat(OffloadArchCategory));
+
+cl::opt AMDGPU("amdgpu-only", cl::desc("Print only AMD GPUs"),
+ cl::init(false), cl::cat(OffloadArchCategory));
+
+cl::opt NVPTX("nvptx-only", cl::desc("Print only NVIDIA GPUs"),
+cl::init(false), cl::cat(OffloadArchCategory));
+
+static void PrintVersion(raw_ostream &OS) {
+  OS << clang::getClangToolFullVersion("offload-arch") << '\n';
+}
+
+int printGPUsByKFD();
+int printGPUsByHIP();
+int printGPUsByCUDA();
+
+int printAMD() {
+#ifndef _WIN32
+  if (!printGPUsByKFD())
+return 0;
+#endif
+
+  return printGPUsByHIP();
+}
+
+int printNVIDIA() { return printGPUsByCUDA(); }
+
+int main(int argc, char *argv[]) {
+  cl::HideUnrelatedOptions(OffloadArchCategory);
+
+  cl::SetVersionPrinter(PrintVersion);
+  cl::ParseCommandLineOptions(
+  argc, argv,
+  "A tool to detect the presence of offloading devices on the system. \n\n"
+  "The tool will output each detected GPU architecture separated by a\n"
+  "newline character. If multiple GPUs of the same architecture are 
found\n"
+  "a string will be printed for each\n");
+
+  if (Help) {
+cl::PrintHelpMessage();
+return 0;
+  }
+
+  // If this was invoked from the legacy symlinks provide the same behavior.
+  bool AMDGPUOnly = AMDGPU || sys::path::filename(argv[0]) == "amdgpu-arch";

jhuber6 wrote:

It's not visible there, it's internal.

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


[clang] [clang][bytecode] Fix various issues with multidimensional arrays (PR #134628)

2025-04-07 Thread Timm Baeder via cfe-commits

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


[clang] [Clang] [NFC] Tablegen component diags headers (PR #134777)

2025-04-07 Thread via cfe-commits

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

The component diagnostic headers (i.e. `DiagnosticAST.h` and friends) all 
follow the same format, and there’s enough of them (and in them) to where 
updating all of them has become rather tedious (at least it was for me while 
working on #132348), so this patch instead generates all of them (or rather 
their contents) via Tablegen.

Also, it seems that `%enum_select` currently woudln’t work in 
`DiagnosticCommonKinds.td` because the infrastructure for that was missing from 
`DiagnosticIDs.h`; this patch should fix that as well.

>From f0fbca3a798b8c0317f704c47845deffd2dc6b74 Mon Sep 17 00:00:00 2001
From: Sirraide 
Date: Tue, 8 Apr 2025 05:21:08 +0200
Subject: [PATCH] [Clang] [NFC] Tablegen component diags headers

---
 clang/include/clang/Basic/CMakeLists.txt  |  5 ++
 clang/include/clang/Basic/DiagnosticAST.h | 40 +--
 .../include/clang/Basic/DiagnosticAnalysis.h  | 39 +-
 clang/include/clang/Basic/DiagnosticComment.h | 40 +--
 clang/include/clang/Basic/DiagnosticCrossTU.h | 40 +--
 clang/include/clang/Basic/DiagnosticDriver.h  | 40 +--
 .../include/clang/Basic/DiagnosticFrontend.h  | 40 +--
 clang/include/clang/Basic/DiagnosticIDs.h | 28 ++
 .../clang/Basic/DiagnosticInstallAPI.h| 38 +-
 clang/include/clang/Basic/DiagnosticLex.h | 39 +-
 clang/include/clang/Basic/DiagnosticParse.h   | 40 +--
 .../clang/Basic/DiagnosticRefactoring.h   | 40 +--
 clang/include/clang/Basic/DiagnosticSema.h| 41 +--
 .../clang/Basic/DiagnosticSerialization.h | 40 +--
 .../TableGen/ClangDiagnosticsEmitter.cpp  | 51 +++
 clang/utils/TableGen/TableGen.cpp |  6 +++
 clang/utils/TableGen/TableGenBackends.h   |  2 +
 17 files changed, 81 insertions(+), 488 deletions(-)

diff --git a/clang/include/clang/Basic/CMakeLists.txt 
b/clang/include/clang/Basic/CMakeLists.txt
index 4d5e1eaa3facb..265ea1fc06494 100644
--- a/clang/include/clang/Basic/CMakeLists.txt
+++ b/clang/include/clang/Basic/CMakeLists.txt
@@ -13,6 +13,11 @@ macro(clang_diag_gen component)
 -gen-clang-diags-compat-ids -clang-component=${component}
 SOURCE Diagnostic.td
 TARGET ClangDiagnostic${component}CompatIDs)
+
+  clang_tablegen(Diagnostic${component}Interface.inc
+-gen-clang-diags-iface -clang-component=${component}
+SOURCE Diagnostic.td
+TARGET ClangDiagnostic${component}Interface)
 endmacro(clang_diag_gen)
 
 clang_diag_gen(Analysis)
diff --git a/clang/include/clang/Basic/DiagnosticAST.h 
b/clang/include/clang/Basic/DiagnosticAST.h
index 41e2598f7cc3b..be9e303d92629 100644
--- a/clang/include/clang/Basic/DiagnosticAST.h
+++ b/clang/include/clang/Basic/DiagnosticAST.h
@@ -10,44 +10,6 @@
 #define LLVM_CLANG_BASIC_DIAGNOSTICAST_H
 
 #include "clang/Basic/Diagnostic.h"
-
-namespace clang {
-namespace diag {
-enum {
-#define DIAG(ENUM, FLAGS, DEFAULT_MAPPING, DESC, GROUP, SFINAE, NOWERROR,  
\
- SHOWINSYSHEADER, SHOWINSYSMACRO, DEFERRABLE, CATEGORY)
\
-  ENUM,
-#define ASTSTART
-#include "clang/Basic/DiagnosticASTKinds.inc"
-#undef DIAG
-  NUM_BUILTIN_AST_DIAGNOSTICS
-};
-
-#define DIAG_ENUM(ENUM_NAME)   
\
-  namespace ENUM_NAME {
\
-  enum {
-#define DIAG_ENUM_ITEM(IDX, NAME) NAME = IDX,
-#define DIAG_ENUM_END()
\
-  }
\
-  ;
\
-  }
-#include "clang/Basic/DiagnosticASTEnums.inc"
-#undef DIAG_ENUM_END
-#undef DIAG_ENUM_ITEM
-#undef DIAG_ENUM
-} // end namespace diag
-
-namespace diag_compat {
-#define DIAG_COMPAT_IDS_BEGIN() enum {
-#define DIAG_COMPAT_IDS_END()  
\
-  }
\
-  ;
-#define DIAG_COMPAT_ID(IDX, NAME, ...) NAME = IDX,
-#include "clang/Basic/DiagnosticASTCompatIDs.inc"
-#undef DIAG_COMPAT_ID
-#undef DIAG_COMPAT_IDS_BEGIN
-#undef DIAG_COMPAT_IDS_END
-} // end namespace diag_compat
-} // end namespace clang
+#include "clang/Basic/DiagnosticASTInterface.inc"
 
 #endif // LLVM_CLANG_BASIC_DIAGNOSTICAST_H
diff --git a/clang/include/clang/Basic/DiagnosticAnalysis.h 
b/clang/include/clang/Basic/DiagnosticAnalysis.h
index 5ead092b946c5..8e2635ffbd78d 100644
--- a/clang/include/clang/Basic/DiagnosticAnalysis.h
+++ b/clang/include/clang/Basic/DiagnosticAnalysis.h
@@ -10,43 +10,6 @@
 #define LLVM_CLANG_BASIC_DIAGNOSTICANALYSIS_H
 
 #include "clang/Basic/Diagnostic.h"
-
-namespace clang {
-namespace diag {
-enum {
-#define DIAG(ENUM, FLAGS, DEFAULT_MAPPING, DESC, GROUP, SFINAE, NOWERR

[clang] [Clang] [NFC] Tablegen component diags headers (PR #134777)

2025-04-07 Thread via cfe-commits

Sirraide wrote:

> ⚠️ C/C++ code formatter, clang-format found issues in your code. ⚠️
> 
> You can test this locally with the following command:
> View the diff from clang-format here.

clang-format seems to be having a stroke here. It’s suggesting indenting 
`namespace clang {` and everything in it even though it’s a top-level namespace 
defintion. I think this might be because the rest of the file is already quite 
weirdly formatted: the `namespace diag { ... }` block above the `#include` line 
is indented even though we don’t usually do that (anymore), which might be 
confusing it.

I think we should just ignore this because it’d probably take reformatting the 
entire file (or at least everything before the `#include` that this patch adds) 
to fix this.

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


[clang] [Clang][CodeGen] Respect -fwrapv-pointer when emitting struct GEPs (PR #134269)

2025-04-07 Thread Shafik Yaghmour via cfe-commits

https://github.com/shafik commented:

This makes sense to me but this is not my area.

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


[clang] fb9915a - [clang][bytecode] Fix emitDestruction() for dummy descriptors (#134665)

2025-04-07 Thread via cfe-commits

Author: Timm Baeder
Date: 2025-04-08T06:00:35+02:00
New Revision: fb9915a3918e3a9659a7f2825ee35bada3a2baf1

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

LOG: [clang][bytecode] Fix emitDestruction() for dummy descriptors (#134665)

This might happen if the referenced declaration is invalid and thus gets
a dummy descriptor. We ran into an assertion later on.

Added: 


Modified: 
clang/lib/AST/ByteCode/Compiler.cpp
clang/test/AST/ByteCode/cxx17.cpp

Removed: 




diff  --git a/clang/lib/AST/ByteCode/Compiler.cpp 
b/clang/lib/AST/ByteCode/Compiler.cpp
index dd246f7ef74fc..db87ea1b6016f 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -6801,6 +6801,10 @@ bool Compiler::emitDestruction(const Descriptor 
*Desc,
   assert(!Desc->isPrimitive());
   assert(!Desc->isPrimitiveArray());
 
+  // Can happen if the decl is invalid.
+  if (Desc->isDummy())
+return true;
+
   // Arrays.
   if (Desc->isArray()) {
 const Descriptor *ElemDesc = Desc->ElemDesc;

diff  --git a/clang/test/AST/ByteCode/cxx17.cpp 
b/clang/test/AST/ByteCode/cxx17.cpp
index ecb8a395520a0..9453906579f04 100644
--- a/clang/test/AST/ByteCode/cxx17.cpp
+++ b/clang/test/AST/ByteCode/cxx17.cpp
@@ -125,3 +125,14 @@ namespace constant {
   }
   static_assert(f());
 }
+
+
+template  struct i; // both-note {{template is declared here}}
+template <> struct i<0> {};
+
+template  constexpr auto c() {
+  i g; // both-error {{implicit instantiation of undefined template 'i<1>'}}
+  return 0;
+}
+
+auto y = c<1>(); // both-note {{in instantiation of function template 
specialization 'c<1>' requested here}}



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


[clang] [CIR] Upstream ArraySubscriptExpr for fixed size array (PR #134536)

2025-04-07 Thread Andy Kaylor via cfe-commits


@@ -198,6 +198,19 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy {
 
 return create(loc, cir::BinOpKind::Div, lhs, rhs);
   }
+
+  /// Create a cir.ptr_stride operation to get access to an array element.
+  /// idx is the index of the element to access, shouldDecay is true if the

andykaylor wrote:

```suggestion
  /// \p idx is the index of the element to access, \p shouldDecay is true if 
the
```

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


[clang] [Clang] Unify 'nvptx-arch' and 'amdgpu-arch' into 'offload-arch' (PR #134713)

2025-04-07 Thread Matt Arsenault via cfe-commits

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


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


[clang] [llvm] [HLSL][RootSignature] Add infastructure to parse parameters (PR #133800)

2025-04-07 Thread Finn Plummer via cfe-commits


@@ -89,37 +88,178 @@ bool RootSignatureParser::parseDescriptorTableClause() {
   CurToken.TokKind == TokenKind::kw_UAV ||
   CurToken.TokKind == TokenKind::kw_Sampler) &&
  "Expects to only be invoked starting at given keyword");
+  TokenKind ParamKind = CurToken.TokKind; // retain for diagnostics
 
   DescriptorTableClause Clause;
-  switch (CurToken.TokKind) {
+  TokenKind ExpectedRegister;
+  switch (ParamKind) {
   default:
 llvm_unreachable("Switch for consumed token was not provided");
   case TokenKind::kw_CBV:
 Clause.Type = ClauseType::CBuffer;
+ExpectedRegister = TokenKind::bReg;
 break;
   case TokenKind::kw_SRV:
 Clause.Type = ClauseType::SRV;
+ExpectedRegister = TokenKind::tReg;
 break;
   case TokenKind::kw_UAV:
 Clause.Type = ClauseType::UAV;
+ExpectedRegister = TokenKind::uReg;
 break;
   case TokenKind::kw_Sampler:
 Clause.Type = ClauseType::Sampler;
+ExpectedRegister = TokenKind::sReg;
 break;
   }
 
   if (consumeExpectedToken(TokenKind::pu_l_paren, diag::err_expected_after,
-   CurToken.TokKind))
+   ParamKind))
 return true;
 
-  if (consumeExpectedToken(TokenKind::pu_r_paren, diag::err_expected_after,
-   CurToken.TokKind))
+  llvm::SmallDenseMap Params = {
+  {ExpectedRegister, &Clause.Register},
+  {TokenKind::kw_space, &Clause.Space},
+  };
+  llvm::SmallDenseSet Mandatory = {
+  ExpectedRegister,
+  };
+
+  if (parseParams(Params, Mandatory))
+return true;
+
+  if (consumeExpectedToken(TokenKind::pu_r_paren,
+   diag::err_hlsl_unexpected_end_of_params,
+   /*param of=*/ParamKind))
 return true;
 
   Elements.push_back(Clause);
   return false;
 }
 
+// Helper struct defined to use the overloaded notation of std::visit.
+template  struct ParseParamTypeMethods : Ts... {
+  using Ts::operator()...;
+};
+template 
+ParseParamTypeMethods(Ts...) -> ParseParamTypeMethods;
+
+bool RootSignatureParser::parseParam(ParamType Ref) {
+  return std::visit(
+  ParseParamTypeMethods{
+  [this](Register *X) -> bool { return parseRegister(X); },
+  [this](uint32_t *X) -> bool {
+return consumeExpectedToken(TokenKind::pu_equal,
+diag::err_expected_after,
+CurToken.TokKind) ||
+   parseUIntParam(X);
+  },
+  },
+  Ref);
+}
+
+bool RootSignatureParser::parseParams(
+llvm::SmallDenseMap &Params,
+llvm::SmallDenseSet &Mandatory) {
+
+  // Initialize a vector of possible keywords
+  SmallVector Keywords;
+  for (auto Pair : Params)
+Keywords.push_back(Pair.first);
+
+  // Keep track of which keywords have been seen to report duplicates
+  llvm::SmallDenseSet Seen;
+
+  while (tryConsumeExpectedToken(Keywords)) {
+if (Seen.contains(CurToken.TokKind)) {
+  getDiags().Report(CurToken.TokLoc, diag::err_hlsl_rootsig_repeat_param)
+  << CurToken.TokKind;
+  return true;
+}
+Seen.insert(CurToken.TokKind);
+
+if (parseParam(Params[CurToken.TokKind]))
+  return true;
+
+if (!tryConsumeExpectedToken(TokenKind::pu_comma))
+  break;
+  }
+
+  bool AllMandatoryDefined = true;
+  for (auto Kind : Mandatory) {
+bool SeenParam = Seen.contains(Kind);
+if (!SeenParam) {
+  getDiags().Report(CurToken.TokLoc, diag::err_hlsl_rootsig_missing_param)
+  << Kind;
+}
+AllMandatoryDefined &= SeenParam;
+  }
+
+  return !AllMandatoryDefined;
+}
+
+bool RootSignatureParser::parseUIntParam(uint32_t *X) {
+  assert(CurToken.TokKind == TokenKind::pu_equal &&
+ "Expects to only be invoked starting at given keyword");
+  tryConsumeExpectedToken(TokenKind::pu_plus);
+  return consumeExpectedToken(TokenKind::int_literal, diag::err_expected_after,
+  CurToken.TokKind) ||
+ handleUIntLiteral(X);
+}
+
+bool RootSignatureParser::parseRegister(Register *Register) {
+  assert((CurToken.TokKind == TokenKind::bReg ||
+  CurToken.TokKind == TokenKind::tReg ||
+  CurToken.TokKind == TokenKind::uReg ||
+  CurToken.TokKind == TokenKind::sReg) &&
+ "Expects to only be invoked starting at given keyword");
+
+  switch (CurToken.TokKind) {
+  default:
+llvm_unreachable("Switch for consumed token was not provided");
+  case TokenKind::bReg:
+Register->ViewType = RegisterType::BReg;
+break;
+  case TokenKind::tReg:
+Register->ViewType = RegisterType::TReg;
+break;
+  case TokenKind::uReg:
+Register->ViewType = RegisterType::UReg;
+break;
+  case TokenKind::sReg:
+Register->ViewType = RegisterType::SReg;
+break;
+  }
+
+  if (handleUIntLiteral(&Register->Number))
+return true; // propogate NumericLiteralParser error
+
+  return false;
+}
+
+bool RootSignatureParser::handleUIntLiteral(uin

[clang] [HLSL] Desugar ConstantArrayType when calculating cbuffer field layout (PR #134683)

2025-04-07 Thread Farzon Lotfi via cfe-commits

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


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


[clang] [clang-format] Add 'cl' to enable OpenCL kernel file formatting (PR #134529)

2025-04-07 Thread Owen Pan via cfe-commits

owenca wrote:

> > I feel like there are more places where this needs to be addressed if we 
> > are going to add it.
> 
> I added support in language detection for OpenCL in 
> [88c1174](https://github.com/llvm/llvm-project/commit/88c11747fcc8db1921dfd8f73c9330c662f7fd91).
>  It returns C language since OpenCL is based on C99 and C11 with 
> restrictions, see 
> https://registry.khronos.org/OpenCL/specs/3.0-unified/html/OpenCL_C.html

OpenCL is formatted as C++ now. Do we really need to change that? See #132832 
for potential problems.

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


[clang-tools-extra] [clang-tidy] Use --match-full-lines instead of --strict-whitespace in check_clang_tidy (PR #133756)

2025-04-07 Thread Nicolas van Kempen via cfe-commits

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


[clang] [HLSL] Implement the `lit` intrinsic (PR #134171)

2025-04-07 Thread Deric C. via cfe-commits


@@ -280,6 +280,22 @@ constexpr bool4 isinf(double4 V) { return 
isinf((float4)V); }
 _DXC_COMPAT_TERNARY_DOUBLE_OVERLOADS(lerp)
 _DXC_COMPAT_TERNARY_INTEGER_OVERLOADS(lerp)
 
+//===--===//
+// lit builtins overloads
+//===--===//
+
+template 
+constexpr __detail::enable_if_t<__detail::is_arithmetic::Value &&
+(__detail::is_same::value ||

Icohedron wrote:

It actually is ambiguous and there isn't special-case handling for overload 
resolution for HLSL under Clang. I was confused because earlier I thought it 
was said that defining lit without using templates eliminated the ambiguous 
call error. I can see that it actually does not eliminate the ambiguous call 
error: see https://hlsl.godbolt.org/z/KxMYe877x
```c++
_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
const inline half4 lit(half A, half B, half M) { return lit_impl(A, B, M); }
const inline float4 lit(float A, float B, float M) { return lit_impl(A, B, M); }

export float4 test(bool A, bool B, bool C) {
return lit(A,B,C);
}
```
Clang HLSL fails to compile this program and reports an ambiguous call to lit:
```
:19:12: error: call to 'lit' is ambiguous
   19 | return lit(A,B,C);
  |  
```

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


[clang-tools-extra] [clang-doc][NFC] refactor out file helpers (PR #134298)

2025-04-07 Thread Daniel Thornburgh via cfe-commits


@@ -0,0 +1,72 @@
+//===-- FileHelpersClangDoc.cpp - File Helpers ---*- 
C++-*-===//

mysterymath wrote:

The filename in this comment should match the actual filename.

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


[clang] [Clang] Unify 'nvptx-arch' and 'amdgpu-arch' into 'offload-arch' (PR #134713)

2025-04-07 Thread Joseph Huber via cfe-commits


@@ -0,0 +1,78 @@
+//===- OffloadArch.cpp - list available GPUs *- 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 "clang/Basic/Version.h"
+#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/Path.h"
+
+using namespace llvm;
+
+static cl::opt Help("h", cl::desc("Alias for -help"), cl::Hidden);
+
+// Mark all our options with this category.
+static cl::OptionCategory OffloadArchCategory("amdgpu-arch options");
+
+cl::opt Verbose("verbose", cl::desc("Enable verbose output"),
+  cl::init(false), cl::cat(OffloadArchCategory));
+
+cl::opt AMDGPU("amdgpu-only", cl::desc("Print only AMD GPUs"),
+ cl::init(false), cl::cat(OffloadArchCategory));
+
+cl::opt NVPTX("nvptx-only", cl::desc("Print only NVIDIA GPUs"),
+cl::init(false), cl::cat(OffloadArchCategory));
+
+static void PrintVersion(raw_ostream &OS) {
+  OS << clang::getClangToolFullVersion("offload-arch") << '\n';
+}
+
+int printGPUsByKFD();
+int printGPUsByHIP();
+int printGPUsByCUDA();
+
+int printAMD() {
+#ifndef _WIN32
+  if (!printGPUsByKFD())
+return 0;
+#endif
+
+  return printGPUsByHIP();
+}
+
+int printNVIDIA() { return printGPUsByCUDA(); }
+
+int main(int argc, char *argv[]) {
+  cl::HideUnrelatedOptions(OffloadArchCategory);
+
+  cl::SetVersionPrinter(PrintVersion);
+  cl::ParseCommandLineOptions(
+  argc, argv,
+  "A tool to detect the presence of offloading devices on the system. \n\n"
+  "The tool will output each detected GPU architecture separated by a\n"
+  "newline character. If multiple GPUs of the same architecture are 
found\n"
+  "a string will be printed for each\n");
+
+  if (Help) {
+cl::PrintHelpMessage();
+return 0;
+  }
+
+  // If this was invoked from the legacy symlinks provide the same behavior.
+  bool AMDGPUOnly = AMDGPU || sys::path::filename(argv[0]) == "amdgpu-arch";

jhuber6 wrote:

Good point, I can update it but I wouldn't know how to test it.

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


[clang] [llvm] [DirectX] Implement UseNativeLowPrecision shader flag analysis (PR #134288)

2025-04-07 Thread Finn Plummer via cfe-commits

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


[clang-tools-extra] 5aae0ee - [clang-tidy] give dummy path when create ClangTidyContext (#134670)

2025-04-07 Thread via cfe-commits

Author: Congcong Cai
Date: 2025-04-08T10:47:39+08:00
New Revision: 5aae0ee660ffdae057d7c5c0e851b5620586d042

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

LOG: [clang-tidy] give dummy path when create ClangTidyContext (#134670)

#121323 changed the way the absolute path is computed. Empty file name
will cause absolute path ignore current folder.
This patch add "dummy" file name to avoid this issue
Fixed: #134502

Added: 


Modified: 
clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp 
b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
index abd6d7b4cd60f..731141a545a48 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
@@ -167,8 +167,8 @@ ClangTidyContext::ClangTidyContext(
   AllowEnablingAnalyzerAlphaCheckers(AllowEnablingAnalyzerAlphaCheckers),
   EnableModuleHeadersParsing(EnableModuleHeadersParsing) {
   // Before the first translation unit we can get errors related to 
command-line
-  // parsing, use empty string for the file name in this case.
-  setCurrentFile("");
+  // parsing, use dummy string for the file name in this case.
+  setCurrentFile("dummy");
 }
 
 ClangTidyContext::~ClangTidyContext() = default;



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


[clang] [clang] consistently quote expressions in diagnostics (PR #134769)

2025-04-07 Thread Younan Zhang via cfe-commits

https://github.com/zyn0217 commented:

Thanks for working productively.


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


[clang] [clang] Add `__bf16` Type Support Macros With Literal Suffix Support (PR #134214)

2025-04-07 Thread Aaron Ballman via cfe-commits

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


[clang] [Clang] add ext warning for missing return in 'main' for C89 mode (PR #134617)

2025-04-07 Thread Aaron Ballman via cfe-commits


@@ -16232,7 +16232,9 @@ Decl *Sema::ActOnFinishFunctionBody(Decl *dcl, Stmt 
*Body,
 
   // If the function implicitly returns zero (like 'main') or is naked,
   // don't complain about missing return statements.
-  if (FD->hasImplicitReturnZero() || FD->hasAttr())
+  if ((FD->hasImplicitReturnZero() &&
+   (getLangOpts().CPlusPlus || getLangOpts().C99 || !FD->isMain())) ||

AaronBallman wrote:

Oh I see what's going on, thank you for the explanation. Then I think all 
that's needed here is a comment saying something along the lines of: Clang 
implicitly returns 0 in C89 mode, but that's an extension, so we need to 
perform the check in that case to ensure we emit the expected extension warning 
in C89 mode.

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


[clang] [clang][doc]: Merge entries with duplicate content. (PR #134089)

2025-04-07 Thread Aaron Ballman via cfe-commits

AaronBallman wrote:

Ugh, the issue was on my end. I downloaded the changes, rebuilt the 
documentation... and skipped the step where I rebuild clang-tblgen. When I do 
things properly, it works (shocking, I know).

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


[clang] [clang][doc]: Merge entries with duplicate content. (PR #134089)

2025-04-07 Thread Erich Keane via cfe-commits

erichkeane wrote:

Yeah, LGTM.  Thank you!

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


[clang] [Clang] Unify 'nvptx-arch' and 'amdgpu-arch' into 'offload-arch' (PR #134713)

2025-04-07 Thread Matt Arsenault via cfe-commits


@@ -0,0 +1,78 @@
+//===- OffloadArch.cpp - list available GPUs *- 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 "clang/Basic/Version.h"
+#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/Path.h"
+
+using namespace llvm;
+
+static cl::opt Help("h", cl::desc("Alias for -help"), cl::Hidden);
+
+// Mark all our options with this category.
+static cl::OptionCategory OffloadArchCategory("amdgpu-arch options");
+
+cl::opt Verbose("verbose", cl::desc("Enable verbose output"),
+  cl::init(false), cl::cat(OffloadArchCategory));
+
+cl::opt AMDGPU("amdgpu-only", cl::desc("Print only AMD GPUs"),
+ cl::init(false), cl::cat(OffloadArchCategory));
+
+cl::opt NVPTX("nvptx-only", cl::desc("Print only NVIDIA GPUs"),
+cl::init(false), cl::cat(OffloadArchCategory));

arsenm wrote:

The way that will work is we will have 10 of these things, and be unable to 
rename the flag. Just start with it 

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


[clang] [llvm] [HIP][HIPSTDPAR][NFC] Re-order & adapt `hipstdpar` specific passes (PR #134753)

2025-04-07 Thread Matt Arsenault via cfe-commits

https://github.com/arsenm commented:

Needs test 

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


[clang] [clang][DependencyScanning] Track dependencies from prebuilt modules to determine IsInStableDir (PR #132237)

2025-04-07 Thread Cyndy Ishida via cfe-commits

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

>From 3aaaf3371215de0f214836da32f862518f223760 Mon Sep 17 00:00:00 2001
From: Cyndy Ishida 
Date: Wed, 12 Mar 2025 21:26:36 -0700
Subject: [PATCH 1/2] [clang][DependencyScanning] Track dependencies from
 prebuilt modules to determine IsInStableDir

When a module is being scanned, it can depend on modules that have
already been built from a pch dependency. When this happens, the
pcm files are reused for the module dependencies. When this is the case,
check if input files recorded from the PCMs come from the provided stable 
directories transitively,
since the scanner will not have access to the full set of file dependencies 
from prebuilt modules.
---
 clang/include/clang/Serialization/ASTReader.h |  11 ++
 .../DependencyScanning/ModuleDepCollector.h   |  59 -
 clang/lib/Frontend/FrontendActions.cpp|   7 +-
 clang/lib/Serialization/ASTReader.cpp |   6 +-
 .../DependencyScanningWorker.cpp  | 112 +++---
 .../DependencyScanning/ModuleDepCollector.cpp |  89 --
 .../prebuilt-modules-in-stable-dirs.c |  24 +++-
 7 files changed, 237 insertions(+), 71 deletions(-)

diff --git a/clang/include/clang/Serialization/ASTReader.h 
b/clang/include/clang/Serialization/ASTReader.h
index 57ae4aa104d9a..617ac23984b60 100644
--- a/clang/include/clang/Serialization/ASTReader.h
+++ b/clang/include/clang/Serialization/ASTReader.h
@@ -237,6 +237,17 @@ class ASTReaderListener {
 return true;
   }
 
+  /// Overloaded member function of \c visitInputFile that should
+  /// be defined when the input file contains both the virtual and external
+  /// paths, for example when deserializing input files from AST files.
+  ///
+  /// \returns true to continue receiving the next input file, false to stop.
+  virtual bool visitInputFile(StringRef FilenameAsRequested, StringRef 
Filename,
+  bool isSystem, bool isOverridden,
+  bool isExplicitModule) {
+return true;
+  }
+
   /// Returns true if this \c ASTReaderListener wants to receive the
   /// imports of the AST file via \c visitImport, false otherwise.
   virtual bool needsImportVisitation() const { return false; }
diff --git 
a/clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h 
b/clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
index ed150b467e3a1..ce5e67d2624d9 100644
--- a/clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
+++ b/clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
@@ -33,6 +33,7 @@ namespace dependencies {
 
 class DependencyActionController;
 class DependencyConsumer;
+class PrebuiltModuleASTAttrs;
 
 /// Modular dependency that has already been built prior to the dependency 
scan.
 struct PrebuiltModuleDep {
@@ -46,6 +47,47 @@ struct PrebuiltModuleDep {
 ModuleMapFile(M->PresumedModuleMapFile) {}
 };
 
+/// Attributes loaded from AST files of prebuilt modules collected prior to
+/// ModuleDepCollector creation.
+using PrebuiltModulesAttrsMap = llvm::StringMap;
+class PrebuiltModuleASTAttrs {
+public:
+  /// When a module is discovered to not be in stable directories, traverse &
+  /// update all modules that depend on it.
+  void
+  updateDependentsNotInStableDirs(PrebuiltModulesAttrsMap &PrebuiltModulesMap);
+
+  /// Read-only access to whether the module is made up of dependencies in
+  /// stable directories.
+  bool isInStableDir() const { return IsInStableDirs; }
+
+  /// Read-only access to vfs map files.
+  const llvm::StringSet<> &getVFS() const { return VFSMap; }
+
+  /// Update the VFSMap to the one discovered from serializing the AST file.
+  void setVFS(llvm::StringSet<> &&VFS) { VFSMap = std::move(VFS); }
+
+  /// Add a direct dependent module file, so it can be updated if the current
+  /// module is from stable directores.
+  void addDependent(StringRef ModuleFile) {
+ModuleFileDependents.insert(ModuleFile);
+  }
+
+  /// Update whether the prebuilt module resolves entirely in a stable
+  /// directories.
+  void setInStableDir(bool V = false) {
+// Cannot reset attribute once it's false.
+if (!IsInStableDirs)
+  return;
+IsInStableDirs = V;
+  }
+
+private:
+  llvm::StringSet<> VFSMap;
+  bool IsInStableDirs = true;
+  std::set ModuleFileDependents;
+};
+
 /// This is used to identify a specific module.
 struct ModuleID {
   /// The name of the module. This may include `:` for C++20 module partitions,
@@ -171,8 +213,6 @@ struct ModuleDeps {
   BuildInfo;
 };
 
-using PrebuiltModuleVFSMapT = llvm::StringMap>;
-
 class ModuleDepCollector;
 
 /// Callback that records textual includes and direct modular includes/imports
@@ -242,7 +282,7 @@ class ModuleDepCollector final : public DependencyCollector 
{
  CompilerInstance &ScanInstance, DependencyConsumer &C,
  DependencyActionController &Controlle

[clang] [CIR] Upstream ArraySubscriptExpr for fixed size array (PR #134536)

2025-04-07 Thread Andy Kaylor via cfe-commits


@@ -232,6 +233,161 @@ LValue CIRGenFunction::emitUnaryOpLValue(const 
UnaryOperator *e) {
   llvm_unreachable("Unknown unary operator kind!");
 }
 
+/// If the specified expr is a simple decay from an array to pointer,
+/// return the array subexpression.
+/// FIXME: this could be abstracted into a common AST helper.
+static const Expr *isSimpleArrayDecayOperand(const Expr *e) {
+  // If this isn't just an array->pointer decay, bail out.
+  const auto *castExpr = dyn_cast(e);
+  if (!castExpr || castExpr->getCastKind() != CK_ArrayToPointerDecay)
+return nullptr;
+
+  // If this is a decay from variable width array, bail out.
+  const Expr *subExpr = castExpr->getSubExpr();
+  if (subExpr->getType()->isVariableArrayType())
+return nullptr;
+
+  return subExpr;
+}
+
+static mlir::IntegerAttr getConstantIndexOrNull(mlir::Value idx) {
+  // TODO(cir): should we consider using MLIRs IndexType instead of 
IntegerAttr?
+  if (auto constantOp = dyn_cast(idx.getDefiningOp()))
+return mlir::dyn_cast(constantOp.getValue());
+  return {};
+}
+
+static CharUnits getArrayElementAlign(CharUnits arrayAlign, mlir::Value idx,
+  CharUnits eltSize) {
+  // If we have a constant index, we can use the exact offset of the
+  // element we're accessing.
+  const mlir::IntegerAttr constantIdx = getConstantIndexOrNull(idx);
+  if (constantIdx) {
+const CharUnits offset = constantIdx.getValue().getZExtValue() * eltSize;
+return arrayAlign.alignmentAtOffset(offset);
+  }
+  // Otherwise, use the worst-case alignment for any element.
+  return arrayAlign.alignmentOfArrayElement(eltSize);
+}
+
+static QualType getFixedSizeElementType(const ASTContext &astContext,
+const VariableArrayType *vla) {
+  QualType eltType;
+  do {
+eltType = vla->getElementType();
+  } while ((vla = astContext.getAsVariableArrayType(eltType)));
+  return eltType;
+}
+
+static mlir::Value
+emitArraySubscriptPtr(CIRGenFunction &cgf, mlir::Location beginLoc,
+  mlir::Location endLoc, mlir::Value ptr, mlir::Type eltTy,
+  ArrayRef indices, bool inbounds,
+  bool signedIndices, bool shouldDecay,
+  const llvm::Twine &name = "arrayidx") {
+  if (indices.size() > 1) {
+cgf.cgm.errorNYI("emitArraySubscriptPtr: handle multiple indices");
+return {};

andykaylor wrote:

It might be nice to emit a null pointer as a dummy value to avoid crashing the 
compiler when this case is hit.

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


[clang] [CIR] Upstream ArraySubscriptExpr for fixed size array (PR #134536)

2025-04-07 Thread Andy Kaylor via cfe-commits


@@ -232,6 +233,161 @@ LValue CIRGenFunction::emitUnaryOpLValue(const 
UnaryOperator *e) {
   llvm_unreachable("Unknown unary operator kind!");
 }
 
+/// If the specified expr is a simple decay from an array to pointer,
+/// return the array subexpression.
+/// FIXME: this could be abstracted into a common AST helper.
+static const Expr *isSimpleArrayDecayOperand(const Expr *e) {
+  // If this isn't just an array->pointer decay, bail out.
+  const auto *castExpr = dyn_cast(e);
+  if (!castExpr || castExpr->getCastKind() != CK_ArrayToPointerDecay)
+return nullptr;
+
+  // If this is a decay from variable width array, bail out.
+  const Expr *subExpr = castExpr->getSubExpr();
+  if (subExpr->getType()->isVariableArrayType())
+return nullptr;
+
+  return subExpr;
+}
+
+static mlir::IntegerAttr getConstantIndexOrNull(mlir::Value idx) {
+  // TODO(cir): should we consider using MLIRs IndexType instead of 
IntegerAttr?
+  if (auto constantOp = dyn_cast(idx.getDefiningOp()))
+return mlir::dyn_cast(constantOp.getValue());
+  return {};
+}
+
+static CharUnits getArrayElementAlign(CharUnits arrayAlign, mlir::Value idx,
+  CharUnits eltSize) {
+  // If we have a constant index, we can use the exact offset of the
+  // element we're accessing.
+  const mlir::IntegerAttr constantIdx = getConstantIndexOrNull(idx);
+  if (constantIdx) {
+const CharUnits offset = constantIdx.getValue().getZExtValue() * eltSize;
+return arrayAlign.alignmentAtOffset(offset);
+  }
+  // Otherwise, use the worst-case alignment for any element.
+  return arrayAlign.alignmentOfArrayElement(eltSize);
+}
+
+static QualType getFixedSizeElementType(const ASTContext &astContext,
+const VariableArrayType *vla) {
+  QualType eltType;
+  do {
+eltType = vla->getElementType();
+  } while ((vla = astContext.getAsVariableArrayType(eltType)));
+  return eltType;
+}
+
+static mlir::Value
+emitArraySubscriptPtr(CIRGenFunction &cgf, mlir::Location beginLoc,
+  mlir::Location endLoc, mlir::Value ptr, mlir::Type eltTy,
+  ArrayRef indices, bool inbounds,
+  bool signedIndices, bool shouldDecay,
+  const llvm::Twine &name = "arrayidx") {
+  if (indices.size() > 1) {
+cgf.cgm.errorNYI("emitArraySubscriptPtr: handle multiple indices");
+return {};
+  }
+
+  const mlir::Value idx = indices.back();
+  CIRGenModule &cgm = cgf.getCIRGenModule();
+  // TODO(cir): LLVM codegen emits in bound gep check here, is there anything
+  // that would enhance tracking this later in CIR?
+  if (inbounds)
+assert(!cir::MissingFeatures::emitCheckedInBoundsGEP() && "NYI");
+  return cgm.getBuilder().getArrayElement(beginLoc, endLoc, ptr, eltTy, idx,
+  shouldDecay);
+}
+
+static Address emitArraySubscriptPtr(
+CIRGenFunction &cgf, mlir::Location beginLoc, mlir::Location endLoc,
+Address addr, ArrayRef indices, QualType eltType,
+bool inbounds, bool signedIndices, mlir::Location loc, bool shouldDecay,
+QualType *arrayType = nullptr, const Expr *base = nullptr,
+const llvm::Twine &name = "arrayidx") {
+
+  // Determine the element size of the statically-sized base.  This is
+  // the thing that the indices are expressed in terms of.
+  if (const VariableArrayType *vla =
+  cgf.getContext().getAsVariableArrayType(eltType)) {
+eltType = getFixedSizeElementType(cgf.getContext(), vla);
+  }
+
+  // We can use that to compute the best alignment of the element.
+  const CharUnits eltSize = cgf.getContext().getTypeSizeInChars(eltType);
+  const CharUnits eltAlign =
+  getArrayElementAlign(addr.getAlignment(), indices.back(), eltSize);
+
+  mlir::Value eltPtr;
+  const mlir::IntegerAttr lastIndex = getConstantIndexOrNull(indices.back());
+  if (!lastIndex) {
+eltPtr = emitArraySubscriptPtr(cgf, beginLoc, endLoc, addr.getPointer(),
+   addr.getElementType(), indices, inbounds,
+   signedIndices, shouldDecay, name);
+  }
+  const mlir::Type elementType = cgf.convertTypeForMem(eltType);
+  return Address(eltPtr, elementType, eltAlign);
+}
+
+LValue
+CIRGenFunction::emitArraySubscriptExpr(const clang::ArraySubscriptExpr *e) {
+  if (e->getBase()->getType()->isVectorType() &&
+  !isa(e->getBase())) {
+cgm.errorNYI(e->getSourceRange(), "emitArraySubscriptExpr: VectorType");
+return {};
+  }
+
+  if (isa(e->getBase())) {
+cgm.errorNYI(e->getSourceRange(),
+ "emitArraySubscriptExpr: ExtVectorElementExpr");
+return {};
+  }
+
+  if (getContext().getAsVariableArrayType(e->getType())) {
+cgm.errorNYI(e->getSourceRange(),
+ "emitArraySubscriptExpr: VariableArrayType");
+return {};
+  }
+
+  if (e->getType()->getAs()) {
+cgm.errorNYI(e->getSourceRange(), "emitArraySubscriptExpr: 
ObjCObjectType");

[clang] [CIR] Upstream ArraySubscriptExpr for fixed size array (PR #134536)

2025-04-07 Thread Andy Kaylor via cfe-commits


@@ -198,6 +198,19 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy {
 
 return create(loc, cir::BinOpKind::Div, lhs, rhs);
   }
+
+  /// Create a cir.ptr_stride operation to get access to an array element.
+  /// idx is the index of the element to access, shouldDecay is true if the
+  /// result should decay to a pointer to the element type.
+  mlir::Value getArrayElement(mlir::Location arrayLocBegin,
+  mlir::Location arrayLocEnd, mlir::Value arrayPtr,
+  mlir::Type eltTy, mlir::Value idx,
+  bool shouldDecay);
+
+  /// Returns a decayed pointer to the first element of the array
+  /// pointed to by arrayPtr.

andykaylor wrote:

```suggestion
  /// pointed to by \p arrayPtr.
```

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


[clang] [CIR] Upstream ArraySubscriptExpr for fixed size array (PR #134536)

2025-04-07 Thread Andy Kaylor via cfe-commits


@@ -157,6 +157,15 @@ class ScalarExprEmitter : public 
StmtVisitor {
 
   mlir::Value VisitCastExpr(CastExpr *e);
 
+  mlir::Value VisitArraySubscriptExpr(ArraySubscriptExpr *e) {
+if (e->getBase()->getType()->isVectorType()) {
+  assert(!cir::MissingFeatures::scalableVectors() &&

andykaylor wrote:

```suggestion
  assert(!cir::MissingFeatures::scalableVectors());
```
The second part of this assert isn't necessary.

This does still need an errorNYI for vector types and a return without falling 
through to the call below. Vector types in general are handled in the incubator 
and not covered by the missing features assert here.

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


[clang] [CIR] Upstream ArraySubscriptExpr for fixed size array (PR #134536)

2025-04-07 Thread Andy Kaylor via cfe-commits


@@ -232,6 +233,161 @@ LValue CIRGenFunction::emitUnaryOpLValue(const 
UnaryOperator *e) {
   llvm_unreachable("Unknown unary operator kind!");
 }
 
+/// If the specified expr is a simple decay from an array to pointer,
+/// return the array subexpression.
+/// FIXME: this could be abstracted into a common AST helper.
+static const Expr *isSimpleArrayDecayOperand(const Expr *e) {
+  // If this isn't just an array->pointer decay, bail out.
+  const auto *castExpr = dyn_cast(e);
+  if (!castExpr || castExpr->getCastKind() != CK_ArrayToPointerDecay)
+return nullptr;
+
+  // If this is a decay from variable width array, bail out.
+  const Expr *subExpr = castExpr->getSubExpr();
+  if (subExpr->getType()->isVariableArrayType())
+return nullptr;
+
+  return subExpr;
+}
+
+static mlir::IntegerAttr getConstantIndexOrNull(mlir::Value idx) {
+  // TODO(cir): should we consider using MLIRs IndexType instead of 
IntegerAttr?
+  if (auto constantOp = dyn_cast(idx.getDefiningOp()))
+return mlir::dyn_cast(constantOp.getValue());
+  return {};
+}
+
+static CharUnits getArrayElementAlign(CharUnits arrayAlign, mlir::Value idx,
+  CharUnits eltSize) {
+  // If we have a constant index, we can use the exact offset of the
+  // element we're accessing.
+  const mlir::IntegerAttr constantIdx = getConstantIndexOrNull(idx);
+  if (constantIdx) {
+const CharUnits offset = constantIdx.getValue().getZExtValue() * eltSize;
+return arrayAlign.alignmentAtOffset(offset);
+  }
+  // Otherwise, use the worst-case alignment for any element.
+  return arrayAlign.alignmentOfArrayElement(eltSize);
+}
+
+static QualType getFixedSizeElementType(const ASTContext &astContext,
+const VariableArrayType *vla) {
+  QualType eltType;
+  do {
+eltType = vla->getElementType();
+  } while ((vla = astContext.getAsVariableArrayType(eltType)));
+  return eltType;
+}
+
+static mlir::Value
+emitArraySubscriptPtr(CIRGenFunction &cgf, mlir::Location beginLoc,
+  mlir::Location endLoc, mlir::Value ptr, mlir::Type eltTy,

andykaylor wrote:

The fact that `eltTy` and `indicies` are in a different order here than in the 
function below is bothersome. It made it harder to spot the significant 
difference between the two signatures.

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


[clang] [CIR] Upstream ArraySubscriptExpr for fixed size array (PR #134536)

2025-04-07 Thread Andy Kaylor via cfe-commits


@@ -29,8 +29,15 @@ int f[5] = {1, 2};
 
 void func() {
   int arr[10];
-
   // CHECK: %[[ARR:.*]] = cir.alloca !cir.array, 
!cir.ptr>, ["arr"]
+
+  int e = arr[1];

andykaylor wrote:

Can you add a test case for `arr[0]`? That's a special case in terms of 
resulting LLVM IR, but is still represented as an explicit ptr_stride in CIR.

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


[clang] [CIR] Upstream ArraySubscriptExpr for fixed size array (PR #134536)

2025-04-07 Thread Andy Kaylor via cfe-commits


@@ -232,6 +233,161 @@ LValue CIRGenFunction::emitUnaryOpLValue(const 
UnaryOperator *e) {
   llvm_unreachable("Unknown unary operator kind!");
 }
 
+/// If the specified expr is a simple decay from an array to pointer,
+/// return the array subexpression.
+/// FIXME: this could be abstracted into a common AST helper.
+static const Expr *isSimpleArrayDecayOperand(const Expr *e) {
+  // If this isn't just an array->pointer decay, bail out.
+  const auto *castExpr = dyn_cast(e);
+  if (!castExpr || castExpr->getCastKind() != CK_ArrayToPointerDecay)
+return nullptr;
+
+  // If this is a decay from variable width array, bail out.
+  const Expr *subExpr = castExpr->getSubExpr();
+  if (subExpr->getType()->isVariableArrayType())
+return nullptr;
+
+  return subExpr;
+}
+
+static mlir::IntegerAttr getConstantIndexOrNull(mlir::Value idx) {
+  // TODO(cir): should we consider using MLIRs IndexType instead of 
IntegerAttr?
+  if (auto constantOp = dyn_cast(idx.getDefiningOp()))
+return mlir::dyn_cast(constantOp.getValue());
+  return {};
+}
+
+static CharUnits getArrayElementAlign(CharUnits arrayAlign, mlir::Value idx,
+  CharUnits eltSize) {
+  // If we have a constant index, we can use the exact offset of the
+  // element we're accessing.
+  const mlir::IntegerAttr constantIdx = getConstantIndexOrNull(idx);
+  if (constantIdx) {
+const CharUnits offset = constantIdx.getValue().getZExtValue() * eltSize;
+return arrayAlign.alignmentAtOffset(offset);

andykaylor wrote:

Do we have a test case where this would return something different than 
`alignmentOfArrayElement(eltSize)`?

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


[clang] [CIR] Upstream ArraySubscriptExpr for fixed size array (PR #134536)

2025-04-07 Thread Andy Kaylor via cfe-commits


@@ -232,6 +233,161 @@ LValue CIRGenFunction::emitUnaryOpLValue(const 
UnaryOperator *e) {
   llvm_unreachable("Unknown unary operator kind!");
 }
 
+/// If the specified expr is a simple decay from an array to pointer,
+/// return the array subexpression.
+/// FIXME: this could be abstracted into a common AST helper.
+static const Expr *isSimpleArrayDecayOperand(const Expr *e) {
+  // If this isn't just an array->pointer decay, bail out.
+  const auto *castExpr = dyn_cast(e);
+  if (!castExpr || castExpr->getCastKind() != CK_ArrayToPointerDecay)
+return nullptr;
+
+  // If this is a decay from variable width array, bail out.
+  const Expr *subExpr = castExpr->getSubExpr();
+  if (subExpr->getType()->isVariableArrayType())
+return nullptr;
+
+  return subExpr;
+}
+
+static mlir::IntegerAttr getConstantIndexOrNull(mlir::Value idx) {
+  // TODO(cir): should we consider using MLIRs IndexType instead of 
IntegerAttr?
+  if (auto constantOp = dyn_cast(idx.getDefiningOp()))
+return mlir::dyn_cast(constantOp.getValue());

andykaylor wrote:

Does this ever return non-null? I would expect the constantOp to have a 
`cir::IntAttr` rather than an `mlir::IntegerAttr`. I'm not sure the former can 
be cast to the latter.

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


[clang] [HLSL] Implement the `lit` intrinsic (PR #134171)

2025-04-07 Thread Kaitlin Peng via cfe-commits

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


[clang] [CodeGen] Change placeholder from `undef` to `poison` (PR #134731)

2025-04-07 Thread Pedro Lobo via cfe-commits

https://github.com/pedroclobo created 
https://github.com/llvm/llvm-project/pull/134731

Fill default values of a map with `poison` instead of `undef`. There should be 
no functional difference as the default values are overridden later.

>From de69ee35e12babf55f6a0212200431bf75340dc4 Mon Sep 17 00:00:00 2001
From: Pedro Lobo 
Date: Mon, 7 Apr 2025 21:55:23 +0100
Subject: [PATCH] [CodeGen] Change placeholder from `undef` to `poison`

Fill default values of a map with `poison` instead of `undef`.
There should be no functional difference as the default values are
overridden later.
---
 clang/lib/CodeGen/MicrosoftCXXABI.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/CodeGen/MicrosoftCXXABI.cpp 
b/clang/lib/CodeGen/MicrosoftCXXABI.cpp
index ba5f74f153d59..7bef436302526 100644
--- a/clang/lib/CodeGen/MicrosoftCXXABI.cpp
+++ b/clang/lib/CodeGen/MicrosoftCXXABI.cpp
@@ -370,7 +370,7 @@ class MicrosoftCXXABI : public CGCXXABI {
 MicrosoftVTableContext &VTContext = CGM.getMicrosoftVTableContext();
 unsigned NumEntries = 1 + SrcRD->getNumVBases();
 SmallVector Map(NumEntries,
- llvm::UndefValue::get(CGM.IntTy));
+ llvm::PoisonValue::get(CGM.IntTy));
 Map[0] = llvm::ConstantInt::get(CGM.IntTy, 0);
 bool AnyDifferent = false;
 for (const auto &I : SrcRD->vbases()) {

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


[clang] [clang][doc]: Merge entries with duplicate content. (PR #134089)

2025-04-07 Thread Aaron Ballman via cfe-commits

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

LGTM! What do you think @erichkeane?

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


[clang] [HLSL] Make it possible to assign an array from a cbuffer (PR #134174)

2025-04-07 Thread Sarah Spall via cfe-commits

https://github.com/spall updated 
https://github.com/llvm/llvm-project/pull/134174

>From 5d81a4b7b034dd5999feb6ab37537270d6bae2a8 Mon Sep 17 00:00:00 2001
From: Sarah Spall 
Date: Wed, 2 Apr 2025 12:04:18 -0700
Subject: [PATCH] compare unqualified canonical types and add an hlsl array
 rvalue cast

---
 clang/lib/Sema/SemaExprCXX.cpp  | 14 ++---
 clang/lib/Sema/SemaOverload.cpp | 10 ++--
 clang/test/CodeGenHLSL/ArrayAssignable.hlsl | 63 -
 3 files changed, 70 insertions(+), 17 deletions(-)

diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index fa492bc124abd..dd4887c0b2878 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -4418,19 +4418,13 @@ Sema::PerformImplicitConversion(Expr *From, QualType 
ToType,
   case ICK_HLSL_Array_RValue:
 if (ToType->isArrayParameterType()) {
   FromType = Context.getArrayParameterType(FromType);
-  From = ImpCastExprToType(From, FromType, CK_HLSLArrayRValue, VK_PRValue,
-   /*BasePath=*/nullptr, CCK)
- .get();
-} else { // FromType must be ArrayParameterType
-  assert(FromType->isArrayParameterType() &&
- "FromType must be ArrayParameterType in ICK_HLSL_Array_RValue \
-  if it is not ToType");
+} else if (FromType->isArrayParameterType()) {
   const ArrayParameterType *APT = cast(FromType);
   FromType = APT->getConstantArrayType(Context);
-  From = ImpCastExprToType(From, FromType, CK_HLSLArrayRValue, VK_PRValue,
-   /*BasePath=*/nullptr, CCK)
- .get();
 }
+From = ImpCastExprToType(From, FromType, CK_HLSLArrayRValue, VK_PRValue,
+ /*BasePath=*/nullptr, CCK)
+   .get();
 break;
 
   case ICK_Function_To_Pointer:
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 1802f8f4e1f91..d282fe50e49f1 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -2268,17 +2268,15 @@ static bool IsStandardConversion(Sema &S, Expr* From, 
QualType ToType,
 // handling here.
 if (ToType->isArrayParameterType()) {
   FromType = S.Context.getArrayParameterType(FromType);
-  SCS.First = ICK_HLSL_Array_RValue;
 } else if (FromType->isArrayParameterType()) {
   const ArrayParameterType *APT = cast(FromType);
   FromType = APT->getConstantArrayType(S.Context);
-  SCS.First = ICK_HLSL_Array_RValue;
-} else {
-  SCS.First = ICK_Identity;
 }
 
-if (S.Context.getCanonicalType(FromType) !=
-S.Context.getCanonicalType(ToType))
+SCS.First = ICK_HLSL_Array_RValue;
+
+if (FromType.getCanonicalType().getUnqualifiedType() !=
+ToType.getCanonicalType().getUnqualifiedType())
   return false;
 
 SCS.setAllToTypes(ToType);
diff --git a/clang/test/CodeGenHLSL/ArrayAssignable.hlsl 
b/clang/test/CodeGenHLSL/ArrayAssignable.hlsl
index e2ff2de68ed99..723d521596baf 100644
--- a/clang/test/CodeGenHLSL/ArrayAssignable.hlsl
+++ b/clang/test/CodeGenHLSL/ArrayAssignable.hlsl
@@ -1,4 +1,23 @@
-// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -emit-llvm 
-disable-llvm-passes -o - %s | FileCheck %s --enable-var-scope
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library 
-finclude-default-header -emit-llvm -disable-llvm-passes -o - %s | FileCheck %s
+
+struct S {
+  int x;
+  float f;
+};
+
+// CHECK: [[CBLayout:%.*]] = type <{ [2 x float], [2 x <4 x i32>], [2 x [2 x 
i32]], [1 x target("dx.Layout", %S, 8, 0, 4)] }>
+// CHECK: @CBArrays.cb = global target("dx.CBuffer", target("dx.Layout", 
[[CBLayout]], 136, 0, 32, 64, 128))
+// CHECK: @c1 = external addrspace(2) global [2 x float], align 4
+// CHECK: @c2 = external addrspace(2) global [2 x <4 x i32>], align 16
+// CHECK: @c3 = external addrspace(2) global [2 x [2 x i32]], align 4
+// CHECK: @c4 = external addrspace(2) global [1 x target("dx.Layout", %S, 8, 
0, 4)], align 4
+
+cbuffer CBArrays {
+  float c1[2];
+  int4 c2[2];
+  int c3[2][2];
+  S c4[1];
+}
 
 // CHECK-LABEL: define void {{.*}}arr_assign1
 // CHECK: [[Arr:%.*]] = alloca [2 x i32], align 4
@@ -116,3 +135,45 @@ void arr_assign7() {
   int Arr2[2][2] = {{0, 0}, {1, 1}};
   (Arr = Arr2)[0] = {6, 6};
 }
+
+// Verify you can assign from a cbuffer array
+
+// CHECK-LABEL: define void {{.*}}arr_assign8
+// CHECK: [[C:%.*]] = alloca [2 x float], align 4
+// CHECK-NEXT: call void @llvm.memcpy.p0.p0.i32(ptr align 4 [[C]], ptr align 4 
{{.*}}, i32 8, i1 false)
+// CHECK-NEXT: call void @llvm.memcpy.p0.p2.i32(ptr align 4 [[C]], ptr 
addrspace(2) align 4 @c1, i32 8, i1 false)
+// CHECK-NEXT: ret void
+void arr_assign8() {
+  float C[2] = {1.0, 2.0};
+  C = c1;
+}
+
+// CHECK-LABEL: define void {{.*}}arr_assign9
+// CHECK: [[C:%.*]] = alloca [2 x <4 x i32>], align 16
+// CHECK-NEXT: call void @llvm.memcpy.p0.p0.i32(ptr align 16 [[C]], ptr align 
16 {{.*}}, i32 32, i1 fal

[clang] [HLSL] Make it possible to assign an array from a cbuffer (PR #134174)

2025-04-07 Thread Sarah Spall via cfe-commits

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


[clang-tools-extra] 15750a0 - [clang-tidy] Use --match-full-lines instead of --strict-whitespace in check_clang_tidy (#133756)

2025-04-07 Thread via cfe-commits

Author: Nicolas van Kempen
Date: 2025-04-07T16:34:07-04:00
New Revision: 15750a0ab2356bea9544b70a72edce421060086e

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

LOG: [clang-tidy] Use --match-full-lines instead of --strict-whitespace in 
check_clang_tidy (#133756)

See Discourse post here:
https://discourse.llvm.org/t/rfc-using-match-full-lines-in-clang-tidy-tests/85553

I've added `--match-partial-fixes` to all tests that were failing,
unless I noticed the fix was quick and trivial.

Added: 


Modified: 
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/test/clang-tidy/check_clang_tidy.py
clang-tools-extra/test/clang-tidy/checkers/abseil/duration-addition.cpp
clang-tools-extra/test/clang-tidy/checkers/abseil/duration-comparison.cpp

clang-tools-extra/test/clang-tidy/checkers/abseil/duration-conversion-cast.cpp
clang-tools-extra/test/clang-tidy/checkers/abseil/duration-factory-float.cpp
clang-tools-extra/test/clang-tidy/checkers/abseil/duration-factory-scale.cpp
clang-tools-extra/test/clang-tidy/checkers/abseil/duration-subtraction.cpp

clang-tools-extra/test/clang-tidy/checkers/abseil/duration-unnecessary-conversion.cpp
clang-tools-extra/test/clang-tidy/checkers/abseil/redundant-strcat-calls.cpp
clang-tools-extra/test/clang-tidy/checkers/abseil/time-comparison.cpp
clang-tools-extra/test/clang-tidy/checkers/abseil/time-subtraction.cpp

clang-tools-extra/test/clang-tidy/checkers/abseil/upgrade-duration-conversions.cpp
clang-tools-extra/test/clang-tidy/checkers/altera/struct-pack-align.cpp
clang-tools-extra/test/clang-tidy/checkers/android/cloexec-memfd-create.cpp
clang-tools-extra/test/clang-tidy/checkers/android/cloexec-open.cpp
clang-tools-extra/test/clang-tidy/checkers/android/cloexec-socket.cpp

clang-tools-extra/test/clang-tidy/checkers/bugprone/incorrect-enable-shared-from-this.cpp

clang-tools-extra/test/clang-tidy/checkers/bugprone/move-forwarding-reference.cpp

clang-tools-extra/test/clang-tidy/checkers/bugprone/not-null-terminated-result-in-initialization-strlen.c

clang-tools-extra/test/clang-tidy/checkers/bugprone/not-null-terminated-result-memcpy-safe-cxx.cpp

clang-tools-extra/test/clang-tidy/checkers/bugprone/not-null-terminated-result-strlen.c

clang-tools-extra/test/clang-tidy/checkers/bugprone/not-null-terminated-result-wcslen.cpp
clang-tools-extra/test/clang-tidy/checkers/bugprone/posix-return.cpp
clang-tools-extra/test/clang-tidy/checkers/bugprone/standalone-empty.cpp
clang-tools-extra/test/clang-tidy/checkers/bugprone/stringview-nullptr.cpp

clang-tools-extra/test/clang-tidy/checkers/bugprone/suspicious-string-compare.cpp
clang-tools-extra/test/clang-tidy/checkers/bugprone/swapped-arguments.cpp

clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/prefer-member-initializer.cpp

clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-bounds-constant-array-index.cpp

clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-type-member-init-use-assignment.cpp

clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-type-member-init.cpp

clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/virtual-class-destructor.cpp

clang-tools-extra/test/clang-tidy/checkers/google/build-explicit-make-pair.cpp
clang-tools-extra/test/clang-tidy/checkers/google/objc-avoid-nsobject-new.m

clang-tools-extra/test/clang-tidy/checkers/google/upgrade-googletest-case.cpp

clang-tools-extra/test/clang-tidy/checkers/llvm/prefer-isa-or-dyn-cast-in-conditionals.cpp

clang-tools-extra/test/clang-tidy/checkers/llvm/prefer-register-over-unsigned.cpp

clang-tools-extra/test/clang-tidy/checkers/llvm/prefer-register-over-unsigned2.cpp

clang-tools-extra/test/clang-tidy/checkers/llvm/prefer-register-over-unsigned3.cpp
clang-tools-extra/test/clang-tidy/checkers/llvm/twine-local.cpp

clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-pointer-as-pointers.cpp

clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-pointer-as-values.cpp

clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-templates.cpp

clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-values-before-cxx23.cpp
clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-values.cpp
clang-tools-extra/test/clang-tidy/checkers/misc/definitions-in-headers.hpp
clang-tools-extra/test/clang-tidy/checkers/misc/unused-parameters.cpp
clang-tools-extra/test/clang-tidy/checkers/modernize/avoid-bind.cpp

clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp
clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp

clang-tools-extra/test/clang-tidy/checkers/modernize/loop-co

[clang] [clang] consistently quote expressions in diagnostics (PR #134769)

2025-04-07 Thread Younan Zhang via cfe-commits

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


[clang-tools-extra] [clang-tidy] give dummy path when create ClangTidyContext (PR #134670)

2025-04-07 Thread Congcong Cai via cfe-commits

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


[clang-tools-extra] [clang-tidy] give dummy path when create ClangTidyContext (PR #134670)

2025-04-07 Thread Congcong Cai via cfe-commits

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


[clang] [clang][modules] Guard against bad -fmodule-file mappings (#132059) (PR #133462)

2025-04-07 Thread Naveen Seth Hanig via cfe-commits

https://github.com/naveen-seth updated 
https://github.com/llvm/llvm-project/pull/133462

>From 957a45312767a40b513bfd4f545c23fda9c4866f Mon Sep 17 00:00:00 2001
From: naveen-seth 
Date: Tue, 8 Apr 2025 00:56:14 +
Subject: [PATCH] [clang][modules] Guard against bad -fmodule-file mappings
 (#132059)

[clang][modules] Guard against invalid -fmodule-file mappings

Fixes #132059.

Providing incorrect mappings via `-fmodule-file==`
can cause the compiler to crash when loading a module that imports an
incorrectly mapped module.

The crash occurs during AST body deserialization when the compiler
attempts to resolve remappings using the `ModuleFile` from the
incorrectly mapped module's BMI file.
The cause is an invalid access into an incorrectly loaded
`ModuleFile`.

This commit fixes the issue by verifying the identity of the imported
module.
---
 clang/lib/Serialization/ASTReader.cpp | 12 +
 clang/test/Modules/fmodule-file-mismatch.cppm | 48 +++
 2 files changed, 60 insertions(+)
 create mode 100644 clang/test/Modules/fmodule-file-mismatch.cppm

diff --git a/clang/lib/Serialization/ASTReader.cpp 
b/clang/lib/Serialization/ASTReader.cpp
index 0cd2cedb48dd9..2f1627d234a4e 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -3318,6 +3318,18 @@ ASTReader::ReadControlBlock(ModuleFile &F,
 Loaded, StoredSize, StoredModTime,
 StoredSignature, Capabilities);
 
+  // Check the AST we just read from ImportedFile contains a different
+  // module than we expected (ImportedName). This can occur for C++20
+  // Modules when given a mismatch via -fmodule-file==
+  if (IsImportingStdCXXModule) {
+if (const auto *Imported =
+getModuleManager().lookupByFileName(ImportedFile);
+Imported != nullptr && Imported->ModuleName != ImportedName) {
+  Diag(diag::err_failed_to_find_module_file) << ImportedName;
+  Result = Missing;
+}
+  }
+
   // If we diagnosed a problem, produce a backtrace.
   bool recompilingFinalized = Result == OutOfDate &&
   (Capabilities & ARR_OutOfDate) &&
diff --git a/clang/test/Modules/fmodule-file-mismatch.cppm 
b/clang/test/Modules/fmodule-file-mismatch.cppm
new file mode 100644
index 0..351f3f4295bf0
--- /dev/null
+++ b/clang/test/Modules/fmodule-file-mismatch.cppm
@@ -0,0 +1,48 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: cd %t
+
+// Related to issue #132059
+
+// Precompile the module dependencies correctly 
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface a.cppm -o a.pcm
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface b.cppm -o b.pcm \
+// RUN: -fmodule-file=A=a.pcm
+
+// Verify that providing incorrect mappings via
+// `-fmodule-file==` does not crash the compiler when 
loading
+// a module that imports the incorrectly mapped module.
+// RUN: not %clang_cc1 -std=c++20 main1.cpp -fmodule-file=A=b.pcm
+
+//--- a.cppm
+export module A;
+
+export int a() {
+  return 41;
+}
+
+//--- b.cppm
+export module B;
+import A;
+
+export int b() {
+  return a() + 1;
+}
+
+//--- main1.cpp
+import A;
+
+int main() {
+  return a();
+}
+
+// Test again for the case where the BMI is first loaded correctly
+// RUN: not %clang_cc1 -std=c++20 main2.cpp-fmodule-file=B=b.pcm \
+// RUN: -fmodule-file=A=b.pcm
+
+//--- main2.cpp
+import B;
+
+int main() {
+  return b();
+}

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


[clang] [SYCL] Basic code generation for SYCL kernel caller offload entry point functions. (PR #133030)

2025-04-07 Thread Tom Honermann via cfe-commits


@@ -12816,6 +12816,15 @@ bool ASTContext::DeclMustBeEmitted(const Decl *D) {
 if (!FD->doesThisDeclarationHaveABody())
   return FD->doesDeclarationForceExternallyVisibleDefinition();
 
+// Function definitions with the sycl_kernel_entry_point attribute are
+// required during device compilation so that SYCL kernel caller offload
+// entry points are emitted.
+if (LangOpts.SYCLIsDevice && FD->hasAttr())
+  return true;
+
+// FIXME: Functions declared with SYCL_EXTERNAL are required during

tahonermann wrote:

Such a test will have to wait. Filtering to prevent symbols from being emitted 
is not yet in place and there are a few existing tests that are dependent on 
such symbols being emitted during device compilation; presumably 
unintentionally. One of the next two PRs will add such filtering and remove/fix 
such tests. Additionally, an attribute to support `SYCL_EXTERNAL` does not yet 
exist upstream, so there is no syntax that can currently be used to write such 
a test.

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


[clang] [Clang] Unify 'nvptx-arch' and 'amdgpu-arch' into 'offload-arch' (PR #134713)

2025-04-07 Thread Joseph Huber via cfe-commits

https://github.com/jhuber6 updated 
https://github.com/llvm/llvm-project/pull/134713

>From e44db82f3abe7c1d23c2b49094c92a890127ffc7 Mon Sep 17 00:00:00 2001
From: Joseph Huber 
Date: Mon, 7 Apr 2025 14:37:22 -0500
Subject: [PATCH 1/2] [Clang] Unify 'nvptx-arch' and 'amdgpu-arch' into
 'offload-arch'

Summary:
These two tools do the same thing, we should unify them into a single
tool. We create symlinks for backward compatiblity and provide a way to
get the old vendor specific behavior with `--amdgpu-only` and
`--nvptx-only`.
---
 clang/tools/CMakeLists.txt|  3 +-
 clang/tools/amdgpu-arch/AMDGPUArch.cpp| 56 -
 clang/tools/amdgpu-arch/CMakeLists.txt| 13 
 clang/tools/nvptx-arch/CMakeLists.txt | 12 ---
 .../AMDGPUArchByHIP.cpp   |  0
 .../AMDGPUArchByKFD.cpp   |  0
 clang/tools/offload-arch/CMakeLists.txt   |  8 ++
 .../NVPTXArch.cpp | 26 +--
 clang/tools/offload-arch/OffloadArch.cpp  | 78 +++
 9 files changed, 88 insertions(+), 108 deletions(-)
 delete mode 100644 clang/tools/amdgpu-arch/AMDGPUArch.cpp
 delete mode 100644 clang/tools/amdgpu-arch/CMakeLists.txt
 delete mode 100644 clang/tools/nvptx-arch/CMakeLists.txt
 rename clang/tools/{amdgpu-arch => offload-arch}/AMDGPUArchByHIP.cpp (100%)
 rename clang/tools/{amdgpu-arch => offload-arch}/AMDGPUArchByKFD.cpp (100%)
 create mode 100644 clang/tools/offload-arch/CMakeLists.txt
 rename clang/tools/{nvptx-arch => offload-arch}/NVPTXArch.cpp (80%)
 create mode 100644 clang/tools/offload-arch/OffloadArch.cpp

diff --git a/clang/tools/CMakeLists.txt b/clang/tools/CMakeLists.txt
index e3557c1328d53..9634eb12080c8 100644
--- a/clang/tools/CMakeLists.txt
+++ b/clang/tools/CMakeLists.txt
@@ -50,5 +50,4 @@ add_llvm_external_project(clang-tools-extra extra)
 # libclang may require clang-tidy in clang-tools-extra.
 add_clang_subdirectory(libclang)
 
-add_clang_subdirectory(amdgpu-arch)
-add_clang_subdirectory(nvptx-arch)
+add_clang_subdirectory(offload-arch)
diff --git a/clang/tools/amdgpu-arch/AMDGPUArch.cpp 
b/clang/tools/amdgpu-arch/AMDGPUArch.cpp
deleted file mode 100644
index 86f3e31f47bbc..0
--- a/clang/tools/amdgpu-arch/AMDGPUArch.cpp
+++ /dev/null
@@ -1,56 +0,0 @@
-//===- AMDGPUArch.cpp - list AMDGPU installed --*- 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
-//
-//===--===//
-//
-// This file implements a tool for detecting name of AMDGPU installed in 
system.
-// This tool is used by AMDGPU OpenMP and HIP driver.
-//
-//===--===//
-
-#include "clang/Basic/Version.h"
-#include "llvm/Support/CommandLine.h"
-
-using namespace llvm;
-
-static cl::opt Help("h", cl::desc("Alias for -help"), cl::Hidden);
-
-// Mark all our options with this category.
-static cl::OptionCategory AMDGPUArchCategory("amdgpu-arch options");
-
-cl::opt Verbose("verbose", cl::desc("Enable verbose output"),
-  cl::init(false), cl::cat(AMDGPUArchCategory));
-
-static void PrintVersion(raw_ostream &OS) {
-  OS << clang::getClangToolFullVersion("amdgpu-arch") << '\n';
-}
-
-int printGPUsByKFD();
-int printGPUsByHIP();
-
-int main(int argc, char *argv[]) {
-  cl::HideUnrelatedOptions(AMDGPUArchCategory);
-
-  cl::SetVersionPrinter(PrintVersion);
-  cl::ParseCommandLineOptions(
-  argc, argv,
-  "A tool to detect the presence of AMDGPU devices on the system. \n\n"
-  "The tool will output each detected GPU architecture separated by a\n"
-  "newline character. If multiple GPUs of the same architecture are 
found\n"
-  "a string will be printed for each\n");
-
-  if (Help) {
-cl::PrintHelpMessage();
-return 0;
-  }
-
-#ifndef _WIN32
-  if (!printGPUsByKFD())
-return 0;
-#endif
-
-  return printGPUsByHIP();
-}
diff --git a/clang/tools/amdgpu-arch/CMakeLists.txt 
b/clang/tools/amdgpu-arch/CMakeLists.txt
deleted file mode 100644
index c4c8de614565a..0
--- a/clang/tools/amdgpu-arch/CMakeLists.txt
+++ /dev/null
@@ -1,13 +0,0 @@
-# 
//===--===//
-# //
-# // Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
-# // See https://llvm.org/LICENSE.txt for details.
-# // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-# //
-# 
//===--===//
-
-set(LLVM_LINK_COMPONENTS Support)
-
-add_clang_tool(amdgpu-arch AMDGPUArch.cpp AMDGPUArchByKFD.cpp 
AMDGPUArchByHIP.cpp)
-
-target_link_libraries(amdgpu-arch PRIVATE clangBasic)
diff --git a/clang/tools/nvptx-arch/CMakeLists.txt 
b/clang/tools/nvptx-

[clang] [OpenMP 6.0 ]Codegen for Reduction over private variables with reduction clause (PR #134709)

2025-04-07 Thread CHANDRA GHALE via cfe-commits

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


[clang] [clang-format] Add 'cl' to enable OpenCL kernel file formatting (PR #134529)

2025-04-07 Thread Wenju He via cfe-commits

https://github.com/wenju-he updated 
https://github.com/llvm/llvm-project/pull/134529

>From ac389b8b92fbb77c8884515d8f7293b4af17dfa5 Mon Sep 17 00:00:00 2001
From: Wenju He 
Date: Sun, 6 Apr 2025 18:30:42 +0800
Subject: [PATCH 1/3] [clang-format] Add 'cl' to enable OpenCL kernel file
 formatting

---
 clang/tools/clang-format/git-clang-format | 1 +
 1 file changed, 1 insertion(+)

diff --git a/clang/tools/clang-format/git-clang-format 
b/clang/tools/clang-format/git-clang-format
index 85eff4761e289..ba324b14ab80d 100755
--- a/clang/tools/clang-format/git-clang-format
+++ b/clang/tools/clang-format/git-clang-format
@@ -126,6 +126,7 @@ def main():
 "pb.txt",
 "textproto",
 "asciipb",  # TextProto
+"cl", # OpenCL
 ]
 )
 

>From 88c11747fcc8db1921dfd8f73c9330c662f7fd91 Mon Sep 17 00:00:00 2001
From: Wenju He 
Date: Mon, 7 Apr 2025 16:17:39 -0700
Subject: [PATCH 2/3] return C language format style for OpenCL

---
 clang/lib/Format/Format.cpp   | 5 +
 clang/test/Format/dump-config-opencl-stdin.cl | 7 +++
 clang/test/Format/lit.local.cfg   | 3 ++-
 clang/unittests/Format/FormatTest.cpp | 3 +++
 4 files changed, 17 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/Format/dump-config-opencl-stdin.cl

diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 226d39f635676..0565d6d46eb32 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -4094,6 +4094,9 @@ static FormatStyle::LanguageKind 
getLanguageByFileName(StringRef FileName) {
   FileName.ends_with_insensitive(".vh")) {
 return FormatStyle::LK_Verilog;
   }
+  // OpenCL is based on C99 and C11.
+  if (FileName.ends_with(".cl"))
+return FormatStyle::LK_C;
   return FormatStyle::LK_Cpp;
 }
 
@@ -4121,6 +4124,8 @@ static FormatStyle::LanguageKind 
getLanguageByComment(const Environment &Env) {
   return FormatStyle::LK_Cpp;
 if (Text == "ObjC")
   return FormatStyle::LK_ObjC;
+if (Text == "OpenCL")
+  return FormatStyle::LK_C;
   }
 
   return FormatStyle::LK_None;
diff --git a/clang/test/Format/dump-config-opencl-stdin.cl 
b/clang/test/Format/dump-config-opencl-stdin.cl
new file mode 100644
index 0..d02a3fb287a42
--- /dev/null
+++ b/clang/test/Format/dump-config-opencl-stdin.cl
@@ -0,0 +1,7 @@
+// RUN: clang-format -assume-filename=foo.cl -dump-config | FileCheck %s
+
+// RUN: clang-format -dump-config - < %s | FileCheck %s
+
+// CHECK: Language: C
+
+void foo() {}
diff --git a/clang/test/Format/lit.local.cfg b/clang/test/Format/lit.local.cfg
index b060c79226cbd..3717ee0dac577 100644
--- a/clang/test/Format/lit.local.cfg
+++ b/clang/test/Format/lit.local.cfg
@@ -20,7 +20,8 @@ config.suffixes = [
 ".textpb",
 ".asciipb",
 ".td",
-".test"
+".test",
+".cl"
 ]
 
 # AIX 'diff' command doesn't support --strip-trailing-cr, but the internal
diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 69c9ee1d1dcb2..146ec9e0a1616 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -25187,6 +25187,9 @@ TEST_F(FormatTest, GetLanguageByComment) {
   EXPECT_EQ(FormatStyle::LK_ObjC,
 guessLanguage("foo.h", "// clang-format Language: ObjC\n"
"int i;"));
+  EXPECT_EQ(FormatStyle::LK_C,
+guessLanguage("foo.h", "// clang-format Language: OpenCL\n"
+   "int i;"));
 }
 
 TEST_F(FormatTest, TypenameMacros) {

>From 69825a4bd73df7bdfaf21c52880ed1441c1d4d6b Mon Sep 17 00:00:00 2001
From: Wenju He 
Date: Mon, 7 Apr 2025 23:48:38 -0700
Subject: [PATCH 3/3] Revert "return C language format style for OpenCL"

This reverts commit 88c11747fcc8db1921dfd8f73c9330c662f7fd91.
---
 clang/lib/Format/Format.cpp   | 5 -
 clang/test/Format/dump-config-opencl-stdin.cl | 7 ---
 clang/test/Format/lit.local.cfg   | 3 +--
 clang/unittests/Format/FormatTest.cpp | 3 ---
 4 files changed, 1 insertion(+), 17 deletions(-)
 delete mode 100644 clang/test/Format/dump-config-opencl-stdin.cl

diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 0565d6d46eb32..226d39f635676 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -4094,9 +4094,6 @@ static FormatStyle::LanguageKind 
getLanguageByFileName(StringRef FileName) {
   FileName.ends_with_insensitive(".vh")) {
 return FormatStyle::LK_Verilog;
   }
-  // OpenCL is based on C99 and C11.
-  if (FileName.ends_with(".cl"))
-return FormatStyle::LK_C;
   return FormatStyle::LK_Cpp;
 }
 
@@ -4124,8 +4121,6 @@ static FormatStyle::LanguageKind 
getLanguageByComment(const Environment &Env) {
   return FormatStyle::LK_Cpp;
 if (Text == "ObjC")
   return FormatStyle::LK_ObjC;
-if (Text == "OpenCL")
-  return FormatStyle::LK_C;
   }
 
   return FormatStyle

[clang] [clang-format] Add 'cl' to enable OpenCL kernel file formatting (PR #134529)

2025-04-07 Thread Wenju He via cfe-commits

wenju-he wrote:

> > > I feel like there are more places where this needs to be addressed if we 
> > > are going to add it.
> > 
> > 
> > I added support in language detection for OpenCL in 
> > [88c1174](https://github.com/llvm/llvm-project/commit/88c11747fcc8db1921dfd8f73c9330c662f7fd91).
> >  It returns C language since OpenCL is based on C99 and C11 with 
> > restrictions, see 
> > https://registry.khronos.org/OpenCL/specs/3.0-unified/html/OpenCL_C.html
> 
> OpenCL is formatted as C++ now. Do we really need to change that? See #132832 
> for potential problems.

reverted. Thanks. Default should be better if it works better.

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


[clang-tools-extra] [clang-tidy] Avoid diagnosing std::array initializations for modernize-use-designated-initializers (PR #134774)

2025-04-07 Thread Carlos Galvez via cfe-commits

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

We should fix `IgnoreSingleElementAggregates` instead.

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


[clang-tools-extra] [clang-tidy] Avoid diagnosing std::array initializations for modernize-use-designated-initializers (PR #134774)

2025-04-07 Thread Carlos Galvez via cfe-commits

carlosgalvezp wrote:

Actually, it seems to me that `IgnoreSingleElementAggregates` should already be 
handling this situation. If it doesn't, there's a bug there that should be 
fixed, instead of patching it for `std::array`?

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


[clang-tools-extra] [clang-tidy] Avoid diagnosing std::array initializations for modernize-use-designated-initializers (PR #134774)

2025-04-07 Thread Carlos Galvez via cfe-commits


@@ -119,13 +119,18 @@ 
UseDesignatedInitializersCheck::UseDesignatedInitializersCheck(
 void UseDesignatedInitializersCheck::registerMatchers(MatchFinder *Finder) {
   const auto HasBaseWithFields =
   hasAnyBase(hasType(cxxRecordDecl(has(fieldDecl();
+
+  // see #133715
+  const auto IsSTLArray =
+  hasType(qualType(hasDeclaration(recordDecl(hasName("::std::array");

carlosgalvezp wrote:

I can imagine this issue can trigger on other similar cases, for example if one 
creates their own `std::array` class.

Can we make this a bit more generic, for example not warn of 1) the class is an 
aggregate and 2) it contains only one member and 3) that member is an array 
type?

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


[clang] [Clang][Sema] Fix -Whigher-precision-for-complex-division (PR #131477)

2025-04-07 Thread Mészáros Gergely via cfe-commits

Maetveis wrote:

Rebased to fix conflict.
Ping @Sirraide

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


[clang] Add more tests for _Countof (PR #133333)

2025-04-07 Thread Aaron Ballman via cfe-commits


@@ -121,10 +150,14 @@ void test_typedefs() {
   static_assert(_Countof(*x) == 12);
 }
 
-void test_zero_size_arrays() {
+void test_zero_size_arrays(int n) {
   int array[0]; // expected-warning {{zero size arrays are an extension}}
   static_assert(_Countof(array) == 0);
   static_assert(_Countof(int[0]) == 0); // expected-warning {{zero size arrays 
are an extension}}
+  int multi_array[0][n]; // expected-warning {{zero size arrays are an 
extension}}

AaronBallman wrote:

Note, currently we don't issue a zero-sized array extension warning for this 
case: https://godbolt.org/z/78W8cr9o5 (seems like a preexisting bug)

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


[clang] Add more tests for _Countof (PR #133333)

2025-04-07 Thread Aaron Ballman via cfe-commits


@@ -144,3 +177,13 @@ void test_compound_literals() {
   static_assert(_Countof((int[2]){}) == 2);
   static_assert(_Countof((int[]){1, 2, 3, 4}) == 4);   
 }
+
+static int test_f1();
+static int test_f2();  // expected-warning {{never defined}}

AaronBallman wrote:

Pretty sure this would be `function 'test_f2' has internal linkage but is not 
defined`

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


[clang] [Clang] Use "syncscope" instead of "synchscope". NFC. (PR #134616)

2025-04-07 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clang-codegen

Author: Jay Foad (jayfoad)


Changes

This matches the spelling of the keyword in LLVM IR.


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


6 Files Affected:

- (modified) clang/include/clang/AST/Expr.h (+1-1) 
- (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (+1-1) 
- (modified) clang/include/clang/Basic/SyncScope.h (+19-19) 
- (modified) clang/lib/CodeGen/CGAtomic.cpp (+4-4) 
- (modified) clang/lib/Sema/SemaChecking.cpp (+1-1) 
- (modified) clang/test/SemaOpenCL/atomic-ops.cl (+1-1) 


``diff
diff --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h
index 08e34fdf2aa2f..dedbff5944af8 100644
--- a/clang/include/clang/AST/Expr.h
+++ b/clang/include/clang/AST/Expr.h
@@ -6757,7 +6757,7 @@ class PseudoObjectExpr final
 /// and corresponding __opencl_atomic_* for OpenCL 2.0.
 /// All of these instructions take one primary pointer, at least one memory
 /// order. The instructions for which getScopeModel returns non-null value
-/// take one synch scope.
+/// take one sync scope.
 class AtomicExpr : public Expr {
 public:
   enum AtomicOp {
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 393bfecf9a36b..12c1d89ef0e14 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -9075,7 +9075,7 @@ def err_atomic_op_needs_atomic_int : Error<
 def warn_atomic_op_has_invalid_memory_order : Warning<
   "%select{|success |failure }0memory order argument to atomic operation is 
invalid">,
   InGroup>;
-def err_atomic_op_has_invalid_synch_scope : Error<
+def err_atomic_op_has_invalid_sync_scope : Error<
   "synchronization scope argument to atomic operation is invalid">;
 def warn_atomic_implicit_seq_cst : Warning<
   "implicit use of sequentially-consistent atomic may incur stronger memory 
barriers than necessary">,
diff --git a/clang/include/clang/Basic/SyncScope.h 
b/clang/include/clang/Basic/SyncScope.h
index 45beff41afa11..5a8d2a7dd02e5 100644
--- a/clang/include/clang/Basic/SyncScope.h
+++ b/clang/include/clang/Basic/SyncScope.h
@@ -21,17 +21,17 @@
 
 namespace clang {
 
-/// Defines synch scope values used internally by clang.
+/// Defines sync scope values used internally by clang.
 ///
 /// The enum values start from 0 and are contiguous. They are mainly used for
-/// enumerating all supported synch scope values and mapping them to LLVM
-/// synch scopes. Their numerical values may be different from the 
corresponding
-/// synch scope enums used in source languages.
+/// enumerating all supported sync scope values and mapping them to LLVM
+/// sync scopes. Their numerical values may be different from the corresponding
+/// sync scope enums used in source languages.
 ///
-/// In atomic builtin and expressions, language-specific synch scope enums are
+/// In atomic builtin and expressions, language-specific sync scope enums are
 /// used. Currently only OpenCL memory scope enums are supported and assumed
 /// to be used by all languages. However, in the future, other languages may
-/// define their own set of synch scope enums. The language-specific synch 
scope
+/// define their own set of sync scope enums. The language-specific sync scope
 /// values are represented by class AtomicScopeModel and its derived classes.
 ///
 /// To add a new enum value:
@@ -88,31 +88,31 @@ inline llvm::StringRef getAsString(SyncScope S) {
   case SyncScope::OpenCLSubGroup:
 return "opencl_subgroup";
   }
-  llvm_unreachable("Invalid synch scope");
+  llvm_unreachable("Invalid sync scope");
 }
 
 /// Defines the kind of atomic scope models.
 enum class AtomicScopeModelKind { None, OpenCL, HIP, Generic };
 
-/// Defines the interface for synch scope model.
+/// Defines the interface for sync scope model.
 class AtomicScopeModel {
 public:
   virtual ~AtomicScopeModel() {}
-  /// Maps language specific synch scope values to internal
+  /// Maps language specific sync scope values to internal
   /// SyncScope enum.
   virtual SyncScope map(unsigned S) const = 0;
 
-  /// Check if the compile-time constant synch scope value
+  /// Check if the compile-time constant sync scope value
   /// is valid.
   virtual bool isValid(unsigned S) const = 0;
 
-  /// Get all possible synch scope values that might be
+  /// Get all possible sync scope values that might be
   /// encountered at runtime for the current language.
   virtual ArrayRef getRuntimeValues() const = 0;
 
   /// If atomic builtin function is called with invalid
-  /// synch scope value at runtime, it will fall back to a valid
-  /// synch scope value returned by this function.
+  /// sync scope value at runtime, it will fall back to a valid
+  /// sync scope value returned by this function.
   virtual unsigned getFallBackValue() const = 0;
 
   /// Create an atomic scope model by AtomicScopeModelKind.
@

[clang] [Clang][ARM] Ensure FPU Features are parsed when targeting `cc1as` (PR #134612)

2025-04-07 Thread Jack Styles via cfe-commits

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


[clang] [Clang] [ARM] Ensure FPU Features are collected when using the Clang Assembler (PR #134366)

2025-04-07 Thread Martin Storsjö via cfe-commits


@@ -0,0 +1,8 @@
+// Ensure that we can assemble NEON by just specifying an armv7
+// Apple or Windows target.
+
+// REQUIRES: arm-registered-target
+// RUN: %clang -c -target armv7-apple-darwin -o /dev/null %s
+// RUN: %clang -c -target armv7-windows -o /dev/null %s

mstorsjo wrote:

No, the downstream patch doesn't need to update these tests; the whole point of 
the code added in #122095 is to make sure that NEON still does get enabled by 
default for the windows/darwin targets. (I just retested building your PR 
134612 together with that downstream patch, and those tests still pass.)

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


[clang] [Clang] [ARM] Ensure FPU Features are collected when using the Clang Assembler (PR #134366)

2025-04-07 Thread Jack Styles via cfe-commits


@@ -0,0 +1,8 @@
+// Ensure that we can assemble NEON by just specifying an armv7
+// Apple or Windows target.
+
+// REQUIRES: arm-registered-target
+// RUN: %clang -c -target armv7-apple-darwin -o /dev/null %s
+// RUN: %clang -c -target armv7-windows -o /dev/null %s

Stylie777 wrote:

Ah yes ok I am with you. 

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


[clang] [RFC] Initial implementation of P2719 (PR #113510)

2025-04-07 Thread via cfe-commits

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


[clang] [flang] [driver] Generalize the code that adds the path of libflang_rt.runtime.a. (PR #134362)

2025-04-07 Thread Daniel Chen via cfe-commits

DanielCChen wrote:

> I would generally prefer if we could avoid having driver behavior depend on 
> the existance of files, but the linker would also pick an existing file as 
> well.

Agreed. The `if (static exists) - else if (shared exists)` logic in this PR is 
temporary until we have the compiler option to allow users to choose which one 
to link.

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


[clang] [clang][driver] Suppress gnu-line-marker when saving temps (PR #134621)

2025-04-07 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (macurtis-amd)


Changes

When passing `-save-temps` to clang, the generated preprocessed output uses gnu 
line markers. This unexpectedly triggers gnu-line-marker warnings when used 
with `-Weverything` or `-pedantic`. Even worse, compilation fails if `-Werror` 
is used.

This change suppresses gnu-line-marker warnings when invoking clang with input 
from a preprocessor job and the user has not otherwise explictly specified 
`-Wgnu-line-marker` somewhere on the command line. Note that this does apply to 
user provided preprocessed files.

fixes #63802

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


2 Files Affected:

- (modified) clang/lib/Driver/ToolChains/Clang.cpp (+27) 
- (modified) clang/test/Driver/save-temps.c (+16) 


``diff
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 70489adf01c94..36cfcecbabe98 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -28,6 +28,7 @@
 #include "clang/Basic/CLWarnings.h"
 #include "clang/Basic/CharInfo.h"
 #include "clang/Basic/CodeGenOptions.h"
+#include "clang/Basic/DiagnosticLex.h"
 #include "clang/Basic/HeaderInclude.h"
 #include "clang/Basic/LangOptions.h"
 #include "clang/Basic/MakeSupport.h"
@@ -67,6 +68,8 @@
 #include "llvm/TargetParser/RISCVTargetParser.h"
 #include 
 
+#include "/home/macurtis/mcc/src/MCC-PRINT.h"
+
 using namespace clang::driver;
 using namespace clang::driver::tools;
 using namespace clang;
@@ -5077,6 +5080,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
   const InputInfo &Input =
   IsExtractAPI ? ExtractAPIPlaceholderInput : Inputs[0];
 
+  bool hasPreprocessorJobInput = false;
   InputInfoList ExtractAPIInputs;
   InputInfoList HostOffloadingInputs;
   const InputInfo *CudaDeviceInput = nullptr;
@@ -5101,6 +5105,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
 } else {
   llvm_unreachable("unexpectedly given multiple inputs");
 }
+hasPreprocessorJobInput |=
+I.getAction()->getKind() == Action::PreprocessJobClass;
   }
 
   const llvm::Triple *AuxTriple =
@@ -6506,6 +6512,27 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
   Args.AddLastArg(CmdArgs, options::OPT_pedantic_errors);
   Args.AddLastArg(CmdArgs, options::OPT_w);
 
+  // Possibly suppress gnu-line-marker diagnostics. This suppresses spurious
+  // warnings or errors when using '-save-temps' with, for example, '-Werror
+  // -Weverything' or '-pedantic'.
+  if (hasPreprocessorJobInput &&
+  !D.getDiags().isIgnored(diag::ext_pp_gnu_line_directive,
+  SourceLocation())) {
+auto IDs = D.getDiags().getDiagnosticIDs();
+StringRef gnuLineMarker =
+IDs->getWarningOptionForDiag(diag::ext_pp_gnu_line_directive);
+
+// If for some reason the user has explicitly specified -Wgnu-line-marker,
+// they are on their own.
+bool hasGnuLineMarker = false;
+for (std::string &V : Args.getAllArgValues(options::OPT_W_Joined)) {
+  if ((hasGnuLineMarker = V == gnuLineMarker))
+break;
+}
+if (!hasGnuLineMarker)
+  CmdArgs.push_back(Args.MakeArgString("-Wno-" + gnuLineMarker));
+  }
+
   Args.addOptInFlag(CmdArgs, options::OPT_ffixed_point,
 options::OPT_fno_fixed_point);
 
diff --git a/clang/test/Driver/save-temps.c b/clang/test/Driver/save-temps.c
index b0cfa4fd814a8..48a590700076e 100644
--- a/clang/test/Driver/save-temps.c
+++ b/clang/test/Driver/save-temps.c
@@ -90,3 +90,19 @@
 // CHECK-SAVE-TEMPS-CMSE: -cc1as
 // CHECK-SAVE-TEMPS-CMSE: +8msecext
 // CHECK-SAVE-TEMPS-CMSE-NOT: '+cmse' is not a recognized feature for this 
target (ignoring feature)
+
+// RUN: %clang -target x86_64-unknown-linux-gnu -Werror -pedantic -save-temps 
%s -### 2>&1 \
+// RUN:   | FileCheck %s -check-prefix=CHECK-SAVE-TEMPS-GLM-000
+// CHECK-SAVE-TEMPS-GLM-000: "-o" "save-temps.i"
+// CHECK-SAVE-TEMPS-GLM-000: "-pedantic" "-Wno-gnu-line-marker"{{.*}} "-x" 
"cpp-output" "save-temps.i"
+
+// RUN: %clang -target x86_64-unknown-linux-gnu -Werror -Weverything 
-save-temps %s -### 2>&1 \
+// RUN:   | FileCheck %s -check-prefix=CHECK-SAVE-TEMPS-GLM-001
+// CHECK-SAVE-TEMPS-GLM-001: "-o" "save-temps.i"
+// CHECK-SAVE-TEMPS-GLM-001: "-Weverything" "-Wno-gnu-line-marker"{{.*}} "-x" 
"cpp-output" "save-temps.i"
+
+// RUN: %clang -target x86_64-unknown-linux-gnu -Werror -Weverything 
-Wgnu-line-marker -save-temps %s -### 2>&1 \
+// RUN:   | FileCheck %s -check-prefix=CHECK-SAVE-TEMPS-GLM-002
+// RUN: %clang -target x86_64-unknown-linux-gnu -Werror -Weverything 
-save-temps -x cpp-output %s -### 2>&1 \
+// RUN:   | FileCheck %s -check-prefix=CHECK-SAVE-TEMPS-GLM-002
+// CHECK-SAVE-TEMPS-GLM-002-NOT: "-Wno-gnu-line-marker"

``




https://github.com/llvm/llvm-project/pull/134621
___
cfe-commits mailing list

[clang] [Clang][ARM] Ensure FPU Features are parsed when targeting `cc1as` (PR #134612)

2025-04-07 Thread David Spickett via cfe-commits


@@ -679,20 +679,17 @@ llvm::ARM::FPUKind arm::getARMTargetFeatures(const Driver 
&D,
 CPUArgFPUKind != llvm::ARM::FK_INVALID ? CPUArgFPUKind : 
ArchArgFPUKind;
 (void)llvm::ARM::getFPUFeatures(FPUKind, Features);
   } else {
-bool Generic = true;
-if (!ForAS) {
-  std::string CPU = arm::getARMTargetCPU(CPUName, ArchName, Triple);
-  if (CPU != "generic")
-Generic = false;
-  llvm::ARM::ArchKind ArchKind =
-  arm::getLLVMArchKindForARM(CPU, ArchName, Triple);
-  FPUKind = llvm::ARM::getDefaultFPU(CPU, ArchKind);
-  (void)llvm::ARM::getFPUFeatures(FPUKind, Features);
-}
+std::string CPU = arm::getARMTargetCPU(CPUName, ArchName, Triple);
+bool Generic = CPU == "generic";
 if (Generic && (Triple.isOSWindows() || Triple.isOSDarwin()) &&
 getARMSubArchVersionNumber(Triple) >= 7) {
   FPUKind = llvm::ARM::parseFPU("neon");
   (void)llvm::ARM::getFPUFeatures(FPUKind, Features);
+} else {
+  llvm::ARM::ArchKind ArchKind =
+  arm::getLLVMArchKindForARM(CPU, ArchName, Triple);
+  FPUKind = llvm::ARM::getDefaultFPU(CPU, ArchKind);
+  (void)llvm::ARM::getFPUFeatures(FPUKind, Features);

DavidSpickett wrote:

Could move this line after the if, given that it always gets called, it's just 
the value of FPUKind that changes between branches.

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


[clang] [Clang] add ext warning for missing return in 'main' for C89 mode (PR #134617)

2025-04-07 Thread Aaron Ballman via cfe-commits

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


[clang] [Clang] add ext warning for missing return in 'main' for C89 mode (PR #134617)

2025-04-07 Thread Aaron Ballman via cfe-commits


@@ -0,0 +1,6 @@
+/* RUN: %clang_cc1 -std=c89 -fsyntax-only -verify -pedantic 
-Wno-strict-prototypes %s

AaronBallman wrote:

Can you also add RUN lines for: `-Wmain-return-type` (enables diagnostic), 
`-pedantic -Wno-main-return-type` (disables diagnostic), and `` (disables 
diagnostic)?

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


[clang] [clang][CodeComplete] Use HeuristicResolver in getAsRecordDecl() (PR #130473)

2025-04-07 Thread Younan Zhang via cfe-commits

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


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


[clang] [clang] fix RecursiveASTVisitor traversal from type to decl (PR #132551)

2025-04-07 Thread Andrey Ali Khan Bolshakov via cfe-commits

bolshakov-a wrote:

Thanks, it becomes now clearer for me. However, I'm still not succeeded in 
making this code really working, because the default version of 
`TraverseDecltypeType` doesn't traverse the underlying desugared type:
https://github.com/llvm/llvm-project/blob/be6ccc98f38227db02164f17bfaf0ac86d800e4a/clang/include/clang/AST/RecursiveASTVisitor.h#L1101-L1102
But, maybe, if someone provides his own version of `TraverseDecltypeType` in 
his visitor, then this may become useful...

My primary concern is that one may think that `NestedNameSpecifier` node is now 
always inserted between `MemberPointerType` and its class type node, but it may 
be not the case, and under very specific conditions.

By the way, it looks strange for me that `int Typedef::*` is not considered as 
a sugar.

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


[clang] [HLSL] Implement the `lit` intrinsic (PR #134171)

2025-04-07 Thread Farzon Lotfi via cfe-commits

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


[clang] [C23] Implement WG14 N3037 (PR #132939)

2025-04-07 Thread Erich Keane via cfe-commits

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


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


[clang] [C23] Implement WG14 N3037 (PR #132939)

2025-04-07 Thread Erich Keane via cfe-commits


@@ -450,6 +453,41 @@ class StmtComparer {
 };
 } // namespace
 
+static bool
+CheckStructurallyEquivalentAttributes(StructuralEquivalenceContext &Context,
+  const Decl *D1, const Decl *D2,
+  const Decl *PrimaryDecl = nullptr) {
+  // If either declaration has an attribute on it, we treat the declarations
+  // as not being structurally equivalent.
+  // FIXME: this should be handled on a case-by-case basis via tablegen in
+  // Attr.td. There are multiple cases to consider: one declation with the
+  // attribute, another without it; different attribute syntax|spellings for
+  // the same semantic attribute, differences in attribute arguments, order
+  // in which attributes are applied, how to merge attributes if the types are
+  // structurally equivalent, etc.
+  const Attr *D1Attr = nullptr, *D2Attr = nullptr;

erichkeane wrote:

TBH it might be nice to 'as a framework' factor this in a way to allow ONE 
hard-coded attribute to be equivalent.  We could pick something harmless (like 
`deprecated`).

So this instead of "any attribute present" becomes "any unsupported/thought of 
attribute" (of which we've only thought of 1 harmless one).

THOUGH in the case of `deprecated`, we probably want to warn that the 2nd one 
is ignored...

so maybe... eh.

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


[clang] [Clang] add ext warning for missing return in 'main' for C89 mode (PR #134617)

2025-04-07 Thread Oleksandr T. via cfe-commits


@@ -16232,7 +16232,9 @@ Decl *Sema::ActOnFinishFunctionBody(Decl *dcl, Stmt 
*Body,
 
   // If the function implicitly returns zero (like 'main') or is naked,
   // don't complain about missing return statements.
-  if (FD->hasImplicitReturnZero() || FD->hasAttr())
+  if ((FD->hasImplicitReturnZero() &&
+   (getLangOpts().CPlusPlus || getLangOpts().C99 || !FD->isMain())) ||

a-tarasyuk wrote:

Since the declaration has `hasImplicitReturnZero`, analysis will be explicitly 
disabled for this case, and the following check won't apply

https://github.com/llvm/llvm-project/blob/8fddef8483dc9eb569580ffd13695b8f54d3c058/clang/lib/Sema/AnalysisBasedWarnings.cpp#L2738

https://github.com/llvm/llvm-project/blob/8fddef8483dc9eb569580ffd13695b8f54d3c058/clang/lib/Sema/AnalysisBasedWarnings.cpp#L2748


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


[clang] [clang][bytecode] Fix various issues with multidimensional arrarys (PR #134628)

2025-04-07 Thread Timm Baeder via cfe-commits

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

>From 150ff13e9336aaeffa38804037ac99ea8ba71e3e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Sun, 6 Apr 2025 13:15:43 +0200
Subject: [PATCH] [clang][bytecode] Fix various issues with multidimensional
 arrarys

This issue is very convulted, but in essence, in the new version:

For a Pointer P that points to the root of a multidimensional,
primitive array:

P.narrow() does nothing.
P.atIndex(0) points P[0]
P.atIndex(0).atIndex(0) is the same as P.atIndex(0) (as before)
P.atIndex(0).narrow().atIndex(0) points to P[0][0]
---
 clang/lib/AST/ByteCode/Compiler.cpp |  3 +-
 clang/lib/AST/ByteCode/Interp.h | 35 
 clang/lib/AST/ByteCode/Pointer.h| 35 +---
 clang/test/AST/ByteCode/arrays.cpp  | 84 -
 4 files changed, 124 insertions(+), 33 deletions(-)

diff --git a/clang/lib/AST/ByteCode/Compiler.cpp 
b/clang/lib/AST/ByteCode/Compiler.cpp
index 021acbd798646..dd246f7ef74fc 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -6148,7 +6148,8 @@ bool Compiler::VisitUnaryOperator(const 
UnaryOperator *E) {
 
 if (!this->visit(SubExpr))
   return false;
-if (classifyPrim(SubExpr) == PT_Ptr && !E->getType()->isArrayType())
+
+if (classifyPrim(SubExpr) == PT_Ptr)
   return this->emitNarrowPtr(E);
 return true;
 
diff --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h
index 6fe1d4b1f95ae..b1427f9b50b8d 100644
--- a/clang/lib/AST/ByteCode/Interp.h
+++ b/clang/lib/AST/ByteCode/Interp.h
@@ -2059,8 +2059,11 @@ bool OffsetHelper(InterpState &S, CodePtr OpPC, const T 
&Offset,
   // useful thing we can do. Any other index has been diagnosed before and
   // we don't get here.
   if (Result == 0 && Ptr.isOnePastEnd()) {
-S.Stk.push(Ptr.asBlockPointer().Pointee,
-Ptr.asBlockPointer().Base);
+if (Ptr.getFieldDesc()->isArray())
+  S.Stk.push(Ptr.atIndex(0));
+else
+  S.Stk.push(Ptr.asBlockPointer().Pointee,
+  Ptr.asBlockPointer().Base);
 return true;
   }
 
@@ -2071,9 +2074,7 @@ bool OffsetHelper(InterpState &S, CodePtr OpPC, const T 
&Offset,
 template ::T>
 bool AddOffset(InterpState &S, CodePtr OpPC) {
   const T &Offset = S.Stk.pop();
-  Pointer Ptr = S.Stk.pop();
-  if (Ptr.isBlockPointer())
-Ptr = Ptr.expand();
+  const Pointer &Ptr = S.Stk.pop();
   return OffsetHelper(S, OpPC, Offset, Ptr,
/*IsPointerArith=*/true);
 }
@@ -2677,8 +2678,16 @@ inline bool ArrayElemPtr(InterpState &S, CodePtr OpPC) {
   return false;
   }
 
-  if (!OffsetHelper(S, OpPC, Offset, Ptr))
-return false;
+  if (Offset.isZero()) {
+if (Ptr.getFieldDesc()->isArray() && Ptr.getIndex() == 0) {
+  S.Stk.push(Ptr.atIndex(0));
+} else {
+  S.Stk.push(Ptr);
+}
+  } else {
+if (!OffsetHelper(S, OpPC, Offset, Ptr))
+  return false;
+  }
 
   return NarrowPtr(S, OpPC);
 }
@@ -2693,8 +2702,16 @@ inline bool ArrayElemPtrPop(InterpState &S, CodePtr 
OpPC) {
   return false;
   }
 
-  if (!OffsetHelper(S, OpPC, Offset, Ptr))
-return false;
+  if (Offset.isZero()) {
+if (Ptr.getFieldDesc()->isArray() && Ptr.getIndex() == 0) {
+  S.Stk.push(Ptr.atIndex(0));
+} else {
+  S.Stk.push(Ptr);
+}
+  } else {
+if (!OffsetHelper(S, OpPC, Offset, Ptr))
+  return false;
+  }
 
   return NarrowPtr(S, OpPC);
 }
diff --git a/clang/lib/AST/ByteCode/Pointer.h b/clang/lib/AST/ByteCode/Pointer.h
index 988237d39fff4..64af5ed9b0a5d 100644
--- a/clang/lib/AST/ByteCode/Pointer.h
+++ b/clang/lib/AST/ByteCode/Pointer.h
@@ -200,37 +200,28 @@ class Pointer {
 if (isZero() || isUnknownSizeArray())
   return *this;
 
+unsigned Base = asBlockPointer().Base;
 // Pointer to an array of base types - enter block.
-if (asBlockPointer().Base == RootPtrMark)
+if (Base == RootPtrMark)
   return Pointer(asBlockPointer().Pointee, sizeof(InlineDescriptor),
  Offset == 0 ? Offset : PastEndMark);
 
 // Pointer is one past end - magic offset marks that.
 if (isOnePastEnd())
-  return Pointer(asBlockPointer().Pointee, asBlockPointer().Base,
- PastEndMark);
-
-// Primitive arrays are a bit special since they do not have inline
-// descriptors. If Offset != Base, then the pointer already points to
-// an element and there is nothing to do. Otherwise, the pointer is
-// adjusted to the first element of the array.
-if (inPrimitiveArray()) {
-  if (Offset != asBlockPointer().Base)
+  return Pointer(asBlockPointer().Pointee, Base, PastEndMark);
+
+if (Offset != Base) {
+  // If we're pointing to a primitive array element, there's nothing to do.
+  if (inPrimitiveArray())
 return *this;
-  return Pointer(asBlockPointer().Pointee, asBlockPointer().Base,
- 

[clang] Ensure FPU Features are parsed when targeting `cc1as` (PR #134612)

2025-04-07 Thread Jack Styles via cfe-commits

https://github.com/Stylie777 created 
https://github.com/llvm/llvm-project/pull/134612

Previously, `cc1as` did not consider the Features that can be included from a 
target's FPU. This could lead to a situation where assembly files could not 
compile as cc1as did not know if a feature was supported.

With this change, all the features for the FPU will be passed to `cc1as` as 
`-target-feature` lines. By making this change, it will enable `+nosimd` to be 
functional, worked on in #130623, and fix a regression introduced in 
8fa0f0efce5fb81eb422e6d7eec74c66dafef4a3 so armv7s-apple0darwin targets can 
utilise VFPv4 correctly.

Co-authored-by: Martin Storsjö 

>From a5b81d22fef03a87f37b9f7c461f464a1c245df4 Mon Sep 17 00:00:00 2001
From: Jack Styles 
Date: Fri, 7 Mar 2025 15:49:00 +
Subject: [PATCH 1/2] [Clang] [ARM] Ensure FPU Features are collected when
 using the Clang Assembler
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Previously, FPU features were not collected when forming a list
of features for the Assembler.

This fixes a regression from 8fa0f0efce5fb81eb422e6d7eec74c66dafef4a3,
which caused VFPv4 to be unavailable if assembling for an
armv7s-apple-darwin target.

Co-authored-by: Martin Storsjö 
---
 clang/docs/ReleaseNotes.rst  |  4 ++
 clang/lib/Driver/ToolChains/Arch/ARM.cpp | 17 
 clang/test/Driver/arm-fpu-selection.s| 32 +++
 clang/test/Driver/armv7-default-neon.s   |  8 
 clang/test/Driver/armv7s-default-vfpv4.s |  6 +++
 clang/test/Driver/armv8.1m.main.s| 51 
 6 files changed, 92 insertions(+), 26 deletions(-)
 create mode 100644 clang/test/Driver/arm-fpu-selection.s
 create mode 100644 clang/test/Driver/armv7-default-neon.s
 create mode 100644 clang/test/Driver/armv7s-default-vfpv4.s

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 5217e04b5e83f..8908af9a80a40 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -38,6 +38,9 @@ Potentially Breaking Changes
 - Fix missing diagnostics for uses of declarations when performing typename 
access,
   such as when performing member access on a '[[deprecated]]' type alias.
   (#GH58547)
+- For ARM targets, when using cc1as, the features included in the selected CPU 
or
+  Arch's FPU are now loaded and utilized. If you wish not to use a specific 
feature,
+  this will need appending to the command line used.
 
 C/C++ Language Potentially Breaking Changes
 ---
@@ -463,6 +466,7 @@ X86 Support
 
 Arm and AArch64 Support
 ^^^
+- For ARM targets, cc1as now considers the FPU's features for the selected CPU 
or Arch.
 
 Android Support
 ^^^
diff --git a/clang/lib/Driver/ToolChains/Arch/ARM.cpp 
b/clang/lib/Driver/ToolChains/Arch/ARM.cpp
index e50cb3836f2c9..ff0e52aa285b1 100644
--- a/clang/lib/Driver/ToolChains/Arch/ARM.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/ARM.cpp
@@ -679,20 +679,17 @@ llvm::ARM::FPUKind arm::getARMTargetFeatures(const Driver 
&D,
 CPUArgFPUKind != llvm::ARM::FK_INVALID ? CPUArgFPUKind : 
ArchArgFPUKind;
 (void)llvm::ARM::getFPUFeatures(FPUKind, Features);
   } else {
-bool Generic = true;
-if (!ForAS) {
-  std::string CPU = arm::getARMTargetCPU(CPUName, ArchName, Triple);
-  if (CPU != "generic")
-Generic = false;
-  llvm::ARM::ArchKind ArchKind =
-  arm::getLLVMArchKindForARM(CPU, ArchName, Triple);
-  FPUKind = llvm::ARM::getDefaultFPU(CPU, ArchKind);
-  (void)llvm::ARM::getFPUFeatures(FPUKind, Features);
-}
+std::string CPU = arm::getARMTargetCPU(CPUName, ArchName, Triple);
+bool Generic = CPU == "generic";
 if (Generic && (Triple.isOSWindows() || Triple.isOSDarwin()) &&
 getARMSubArchVersionNumber(Triple) >= 7) {
   FPUKind = llvm::ARM::parseFPU("neon");
   (void)llvm::ARM::getFPUFeatures(FPUKind, Features);
+} else {
+  llvm::ARM::ArchKind ArchKind =
+  arm::getLLVMArchKindForARM(CPU, ArchName, Triple);
+  FPUKind = llvm::ARM::getDefaultFPU(CPU, ArchKind);
+  (void)llvm::ARM::getFPUFeatures(FPUKind, Features);
 }
   }
 
diff --git a/clang/test/Driver/arm-fpu-selection.s 
b/clang/test/Driver/arm-fpu-selection.s
new file mode 100644
index 0..c40e0f5b25852
--- /dev/null
+++ b/clang/test/Driver/arm-fpu-selection.s
@@ -0,0 +1,32 @@
+// REQUIRES: arm-registered-target
+// Ensures that when targeting an ARM target with an Asm file, clang
+// collects the features from the FPU. This is critical in the
+// activation of NEON for supported targets. The Cortex-R52 will be
+// used and tested for VFP and NEON Support
+
+// RUN: %clang -target arm-none-eabi -mcpu=cortex-r52 -c %s -o /dev/null | 
count 0
+// RUN: %clang -target arm-none-eabi -mcpu=cortex-r52 -c %s -o /dev/null -### 
2>&1 | FileCheck --check-prefix=CHECK-TARGET-FEATURES %s
+
+// Check that NEON and VFPV5 have

[clang] Ensure FPU Features are parsed when targeting `cc1as` (PR #134612)

2025-04-07 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-arm

Author: Jack Styles (Stylie777)


Changes

Previously, `cc1as` did not consider the Features that can be included from a 
target's FPU. This could lead to a situation where assembly files could not 
compile as cc1as did not know if a feature was supported.

With this change, all the features for the FPU will be passed to `cc1as` as 
`-target-feature` lines. By making this change, it will enable `+nosimd` to be 
functional, worked on in #130623, and fix a regression introduced in 
8fa0f0efce5fb81eb422e6d7eec74c66dafef4a3 so armv7s-apple0darwin targets can 
utilise VFPv4 correctly.

Co-authored-by: Martin Storsjö 

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


6 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+4) 
- (modified) clang/lib/Driver/ToolChains/Arch/ARM.cpp (+7-10) 
- (added) clang/test/Driver/arm-fpu-selection.s (+32) 
- (added) clang/test/Driver/armv7-default-neon.s (+12) 
- (added) clang/test/Driver/armv7s-default-vfpv4.s (+9) 
- (modified) clang/test/Driver/armv8.1m.main.s (+35-16) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 5217e04b5e83f..acbb2f435c864 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -38,6 +38,9 @@ Potentially Breaking Changes
 - Fix missing diagnostics for uses of declarations when performing typename 
access,
   such as when performing member access on a '[[deprecated]]' type alias.
   (#GH58547)
+- For ARM targets, when using cc1as, the features included in the selected CPU 
or
+  Architecture's FPU are now loaded and utilized. If you wish not to use a 
specific feature,
+  the relevant ``+no`` option will need to be amended to the command line 
option.
 
 C/C++ Language Potentially Breaking Changes
 ---
@@ -463,6 +466,7 @@ X86 Support
 
 Arm and AArch64 Support
 ^^^
+- For ARM targets, cc1as now considers the FPU's features for the selected CPU 
or Arch.
 
 Android Support
 ^^^
diff --git a/clang/lib/Driver/ToolChains/Arch/ARM.cpp 
b/clang/lib/Driver/ToolChains/Arch/ARM.cpp
index e50cb3836f2c9..ff0e52aa285b1 100644
--- a/clang/lib/Driver/ToolChains/Arch/ARM.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/ARM.cpp
@@ -679,20 +679,17 @@ llvm::ARM::FPUKind arm::getARMTargetFeatures(const Driver 
&D,
 CPUArgFPUKind != llvm::ARM::FK_INVALID ? CPUArgFPUKind : 
ArchArgFPUKind;
 (void)llvm::ARM::getFPUFeatures(FPUKind, Features);
   } else {
-bool Generic = true;
-if (!ForAS) {
-  std::string CPU = arm::getARMTargetCPU(CPUName, ArchName, Triple);
-  if (CPU != "generic")
-Generic = false;
-  llvm::ARM::ArchKind ArchKind =
-  arm::getLLVMArchKindForARM(CPU, ArchName, Triple);
-  FPUKind = llvm::ARM::getDefaultFPU(CPU, ArchKind);
-  (void)llvm::ARM::getFPUFeatures(FPUKind, Features);
-}
+std::string CPU = arm::getARMTargetCPU(CPUName, ArchName, Triple);
+bool Generic = CPU == "generic";
 if (Generic && (Triple.isOSWindows() || Triple.isOSDarwin()) &&
 getARMSubArchVersionNumber(Triple) >= 7) {
   FPUKind = llvm::ARM::parseFPU("neon");
   (void)llvm::ARM::getFPUFeatures(FPUKind, Features);
+} else {
+  llvm::ARM::ArchKind ArchKind =
+  arm::getLLVMArchKindForARM(CPU, ArchName, Triple);
+  FPUKind = llvm::ARM::getDefaultFPU(CPU, ArchKind);
+  (void)llvm::ARM::getFPUFeatures(FPUKind, Features);
 }
   }
 
diff --git a/clang/test/Driver/arm-fpu-selection.s 
b/clang/test/Driver/arm-fpu-selection.s
new file mode 100644
index 0..c40e0f5b25852
--- /dev/null
+++ b/clang/test/Driver/arm-fpu-selection.s
@@ -0,0 +1,32 @@
+// REQUIRES: arm-registered-target
+// Ensures that when targeting an ARM target with an Asm file, clang
+// collects the features from the FPU. This is critical in the
+// activation of NEON for supported targets. The Cortex-R52 will be
+// used and tested for VFP and NEON Support
+
+// RUN: %clang -target arm-none-eabi -mcpu=cortex-r52 -c %s -o /dev/null | 
count 0
+// RUN: %clang -target arm-none-eabi -mcpu=cortex-r52 -c %s -o /dev/null -### 
2>&1 | FileCheck --check-prefix=CHECK-TARGET-FEATURES %s
+
+// Check that NEON and VFPV5 have been activated when using Cortex-R52 when 
using cc1as
+// CHECK-TARGET-FEATURES: "-target-feature" "+vfp2sp"
+// CHECK-TARGET-FEATURES: "-target-feature" "+vfp3"
+// CHECK-TARGET-FEATURES: "-target-feature" "+fp-armv8"
+// CHECK-TARGET-FEATURES: "-target-feature" "+fp-armv8d16"
+// CHECK-TARGET-FEATURES: "-target-feature" "+fp-armv8d16sp"
+// CHECK-TARGET-FEATURES: "-target-feature" "+fp-armv8sp"
+// CHECK-TARGET-FEATURES: "-target-feature" "+neon"
+
+  vadd.f32 s0, s1, s2
+  vadd.f64 d0, d1, d2
+  vcvt.u32.f32 s0, s0, #1
+  vcvt.u32.f64 d0, d0, #1
+  vcvtb.f32.f16 s0, s1
+  vcvtb.f64.f16 d0, s1
+  vfma.f32 s0, s1, s2
+  vfma.f64 d0, d1, d2
+  vcvta.u32.f32 s0, s1
+  v

[clang] [Clang] [ARM] Ensure FPU Features are collected when using the Clang Assembler (PR #134366)

2025-04-07 Thread Jack Styles via cfe-commits

Stylie777 wrote:

I have created https://github.com/llvm/llvm-project/pull/134612 so I will now 
close this PR.

@DavidSpickett your comments for the Release Notes have been worked on in the 
new PR.

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


  1   2   3   4   >