[clang] 34ba1c0 - [NFC] [Serialization] Emit Name for DECL_EXPORT

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

Author: Chuanqi Xu
Date: 2024-05-28T14:27:48+08:00
New Revision: 34ba1c043af0c3bbcbc1c9e66fbcc6509e4b8e9d

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

LOG: [NFC] [Serialization] Emit Name for DECL_EXPORT

Added: 


Modified: 
clang/lib/Serialization/ASTWriter.cpp
clang/test/Modules/no-implicit-declarations.cppm

Removed: 




diff  --git a/clang/lib/Serialization/ASTWriter.cpp 
b/clang/lib/Serialization/ASTWriter.cpp
index a85cd94fd5b5a..dd548fabfd955 100644
--- a/clang/lib/Serialization/ASTWriter.cpp
+++ b/clang/lib/Serialization/ASTWriter.cpp
@@ -1049,6 +1049,7 @@ void ASTWriter::WriteBlockInfoBlock() {
   RECORD(DECL_UNRESOLVED_USING_VALUE);
   RECORD(DECL_UNRESOLVED_USING_TYPENAME);
   RECORD(DECL_LINKAGE_SPEC);
+  RECORD(DECL_EXPORT);
   RECORD(DECL_CXX_RECORD);
   RECORD(DECL_CXX_METHOD);
   RECORD(DECL_CXX_CONSTRUCTOR);

diff  --git a/clang/test/Modules/no-implicit-declarations.cppm 
b/clang/test/Modules/no-implicit-declarations.cppm
index 319d3a432ea23..79c3c5e76f63e 100644
--- a/clang/test/Modules/no-implicit-declarations.cppm
+++ b/clang/test/Modules/no-implicit-declarations.cppm
@@ -17,7 +17,7 @@ export int a = 43;
 // CHECK:  https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

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


@@ -61,6 +61,9 @@ class MCTargetOptions {
 
   bool Dwarf64 : 1;
 
+  // Use CREL relocation format for ELF.
+  bool Crel = false;

MaskRay wrote:

If LLVM adopts https://llvm.org/docs/Proposals/VariableNames.html , I'd like to 
use `crel` instead of `cRel`. But with the capitalized naming, I'd prefer 
`Crel`. This makes many functions' names `xxxCrels` align better with `xxxRels`.

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


[clang] [clang][dataflow] Rewrite `getReferencedDecls()` with a `RecursiveASTVisitor`. (PR #93461)

2024-05-27 Thread via cfe-commits

martinboehme wrote:

CI breakage (infinite-instantiation.test) seems to be unrelated.

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


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

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

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


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

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


@@ -0,0 +1,88 @@
+//===--- CIRGenAction.cpp - LLVM Code generation Frontend Action -===//
+//
+// 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/CIRFrontendAction/CIRGenAction.h"
+#include "clang/CIR/CIRGenerator.h"
+#include "clang/Frontend/CompilerInstance.h"
+
+#include "mlir/IR/MLIRContext.h"
+#include "mlir/IR/OwningOpRef.h"
+
+using namespace cir;
+using namespace clang;
+
+namespace cir {
+
+class CIRGenConsumer : public clang::ASTConsumer {
+
+  virtual void anchor();
+
+  [[maybe_unused]] CIRGenAction::OutputType action;
+
+  [[maybe_unused]] DiagnosticsEngine &diagnosticsEngine;
+  [[maybe_unused]] const HeaderSearchOptions &headerSearchOptions;
+  [[maybe_unused]] const CodeGenOptions &codeGenOptions;
+  [[maybe_unused]] const TargetOptions &targetOptions;
+  [[maybe_unused]] const LangOptions &langOptions;
+  [[maybe_unused]] const FrontendOptions &feOptions;
+
+  std::unique_ptr outputStream;
+
+  [[maybe_unused]] ASTContext *astContext{nullptr};
+  IntrusiveRefCntPtr FS;
+  std::unique_ptr gen;
+
+public:
+  CIRGenConsumer(CIRGenAction::OutputType action,
+ DiagnosticsEngine &diagnosticsEngine,
+ IntrusiveRefCntPtr VFS,
+ const HeaderSearchOptions &headerSearchOptions,
+ const CodeGenOptions &codeGenOptions,
+ const TargetOptions &targetOptions,
+ const LangOptions &langOptions,
+ const FrontendOptions &feOptions,
+ std::unique_ptr os)
+  : action(action), diagnosticsEngine(diagnosticsEngine),
+headerSearchOptions(headerSearchOptions),
+codeGenOptions(codeGenOptions), targetOptions(targetOptions),
+langOptions(langOptions), feOptions(feOptions),
+outputStream(std::move(os)), FS(VFS),
+gen(std::make_unique(diagnosticsEngine, std::move(VFS),
+   codeGenOptions)) {}
+
+  bool HandleTopLevelDecl(DeclGroupRef D) override {
+gen->HandleTopLevelDecl(D);
+return true;
+  }
+};
+} // namespace cir
+
+void CIRGenConsumer::anchor() {}
+
+CIRGenAction::CIRGenAction(OutputType act, mlir::MLIRContext *mlirContext)
+: mlirContext(mlirContext ? mlirContext : new mlir::MLIRContext),
+  action(act) {}
+
+CIRGenAction::~CIRGenAction() { mlirModule.release(); }
+
+std::unique_ptr
+CIRGenAction::CreateASTConsumer(CompilerInstance &ci, StringRef inputFile) {
+  auto out = ci.takeOutputStream();
+
+  auto Result = std::make_unique(
+  action, ci.getDiagnostics(), &ci.getVirtualFileSystem(),
+  ci.getHeaderSearchOpts(), ci.getCodeGenOpts(), ci.getTargetOpts(),
+  ci.getLangOpts(), ci.getFrontendOpts(), std::move(out));
+  cgConsumer = Result.get();
+
+  return std::move(Result);

ChuanqiXu9 wrote:

It may be pessimizing move
```suggestion
  return Result;
```

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


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

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


@@ -0,0 +1,59 @@
+//===- CIRGenerator.h - CIR Generation from Clang AST 
-===//
+//
+// 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 declares a simple interface to perform CIR generation from Clang
+// AST
+//
+//===--===//
+
+#ifndef CLANG_CIRGENERATOR_H_
+#define CLANG_CIRGENERATOR_H_
+
+#include "clang/AST/ASTConsumer.h"
+#include "clang/AST/DeclGroup.h"
+#include "clang/Basic/CodeGenOptions.h"
+#include "clang/Basic/Diagnostic.h"
+
+#include "llvm/ADT/IntrusiveRefCntPtr.h"
+#include "llvm/Support/VirtualFileSystem.h"
+
+#include 
+
+namespace mlir {
+class MLIRContext;
+} // namespace mlir
+namespace cir {
+class CIRGenModule;
+
+class CIRGenerator : public clang::ASTConsumer {
+  virtual void anchor();
+  clang::DiagnosticsEngine &Diags;
+  clang::ASTContext *astCtx;
+  llvm::IntrusiveRefCntPtr
+  fs; // Only used for debug info.
+
+  const clang::CodeGenOptions codeGenOpts; // Intentionally copied in.

ChuanqiXu9 wrote:

It may be helpful to  add a comment to explain why this is intentionally copied 
in?

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


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

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


@@ -0,0 +1,61 @@
+//=== CIRGenAction.h - CIR Code Generation Frontend Action -*- C++ 
-*--===//

ChuanqiXu9 wrote:

Should we move this header to `CIR` or `FrontendAction`? Currently it lives in 
`CIRFrontendAction` but its implementation file lives in `FrontendAction`

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


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

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


@@ -42,6 +47,14 @@ CreateFrontendBaseAction(CompilerInstance &CI) {
   StringRef Action("unknown");
   (void)Action;
 
+  auto UseCIR = CI.getFrontendOpts().UseClangIRPipeline;
+  auto Act = CI.getFrontendOpts().ProgramAction;
+  auto EmitsCIR = Act == EmitCIR;
+
+  if (!UseCIR && EmitsCIR)
+llvm::report_fatal_error(
+"-emit-cir and -emit-cir-only only valid when using -fclangir");

ChuanqiXu9 wrote:

What is `-emit-cir-only`? Should we remove that?

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


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

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


@@ -0,0 +1,88 @@
+//===--- CIRGenAction.cpp - LLVM Code generation Frontend Action -===//
+//
+// 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/CIRFrontendAction/CIRGenAction.h"
+#include "clang/CIR/CIRGenerator.h"
+#include "clang/Frontend/CompilerInstance.h"
+
+#include "mlir/IR/MLIRContext.h"
+#include "mlir/IR/OwningOpRef.h"
+
+using namespace cir;
+using namespace clang;
+
+namespace cir {
+
+class CIRGenConsumer : public clang::ASTConsumer {
+
+  virtual void anchor();
+
+  [[maybe_unused]] CIRGenAction::OutputType action;
+
+  [[maybe_unused]] DiagnosticsEngine &diagnosticsEngine;
+  [[maybe_unused]] const HeaderSearchOptions &headerSearchOptions;
+  [[maybe_unused]] const CodeGenOptions &codeGenOptions;
+  [[maybe_unused]] const TargetOptions &targetOptions;
+  [[maybe_unused]] const LangOptions &langOptions;
+  [[maybe_unused]] const FrontendOptions &feOptions;
+
+  std::unique_ptr outputStream;
+
+  [[maybe_unused]] ASTContext *astContext{nullptr};
+  IntrusiveRefCntPtr FS;
+  std::unique_ptr gen;
+
+public:
+  CIRGenConsumer(CIRGenAction::OutputType action,
+ DiagnosticsEngine &diagnosticsEngine,
+ IntrusiveRefCntPtr VFS,
+ const HeaderSearchOptions &headerSearchOptions,
+ const CodeGenOptions &codeGenOptions,
+ const TargetOptions &targetOptions,
+ const LangOptions &langOptions,
+ const FrontendOptions &feOptions,
+ std::unique_ptr os)
+  : action(action), diagnosticsEngine(diagnosticsEngine),
+headerSearchOptions(headerSearchOptions),
+codeGenOptions(codeGenOptions), targetOptions(targetOptions),
+langOptions(langOptions), feOptions(feOptions),
+outputStream(std::move(os)), FS(VFS),
+gen(std::make_unique(diagnosticsEngine, std::move(VFS),
+   codeGenOptions)) {}
+
+  bool HandleTopLevelDecl(DeclGroupRef D) override {
+gen->HandleTopLevelDecl(D);
+return true;
+  }
+};
+} // namespace cir
+
+void CIRGenConsumer::anchor() {}
+
+CIRGenAction::CIRGenAction(OutputType act, mlir::MLIRContext *mlirContext)
+: mlirContext(mlirContext ? mlirContext : new mlir::MLIRContext),
+  action(act) {}
+
+CIRGenAction::~CIRGenAction() { mlirModule.release(); }
+
+std::unique_ptr
+CIRGenAction::CreateASTConsumer(CompilerInstance &ci, StringRef inputFile) {
+  auto out = ci.takeOutputStream();
+
+  auto Result = std::make_unique(
+  action, ci.getDiagnostics(), &ci.getVirtualFileSystem(),
+  ci.getHeaderSearchOpts(), ci.getCodeGenOpts(), ci.getTargetOpts(),
+  ci.getLangOpts(), ci.getFrontendOpts(), std::move(out));
+  cgConsumer = Result.get();

ChuanqiXu9 wrote:

If I read correctly, `cgConsumer` is only used here? I guess it is needed in 
following patches. But slightly odd.

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


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

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

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


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

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

https://github.com/ChuanqiXu9 commented:

BTW, it will be helpful to create subscribing team to help people to get 
informed in time. (I just saw the patch accidently.)

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


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

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

MaskRay wrote:

> > @MaskRay Got it.
> > The problem with that solution is that if you use --target you won't get 
> > the correct arch. This would be a problem for any cross compilation. For 
> > example, say you cross compile from zLinux (which wouldn't have the config 
> > file), the arch would be arch8. And if you cross compiled from z/OS (with 
> > the config file) to zLinux then the default arch would be arch10. Both of 
> > these would be incorrect.
> > We also use the config files for installation specific information. It is 
> > common for users to have their own config files. If we require that the 
> > option be in the config file then we would be creating a very error prone 
> > situation.
> > We need to be able to change the arch default based on the target triple.
> 
> Sorry for the late reply. Such driver defaults via cmake variable would make 
> testing brittle. Users expect that `check-clang` pass regardless of the cmake 
> variable setting. If a test changes behavior due to different `-march=`, 
> there are a few choices:
> 
> * add a `REQUIRES: zos-new-default-march` directive
> * hard code a `-march=`
> 
> Neither is immediately noticeable. In the past clang/test/Driver has had many 
> such tests that require fixup. We have tried removing some unnecessary 
> `CLANG_DEFAULT_*`.

I just realized that https://reviews.llvm.org/D75914 added 
`CLANG_SYSTEMZ_DEFAULT_ARCH` for Ubuntu. @xnox @uweigand 

I think we want to avoid such CMake options/clang `config.h`

As an alternative, if the clang executable is at `/tmp/Rel/bin/clang`, you can 
add `/tmp/Rel/bin/s390x-unknown-linux-gnu.cfg` with content `-march=z13`.

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


[clang] [clang/www/get_started.html] Use newer `cmake` syntax (PR #93503)

2024-05-27 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Samuel Marks (SamuelMarks)


Changes



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


1 Files Affected:

- (modified) clang/www/get_started.html (+8-8) 


``diff
diff --git a/clang/www/get_started.html b/clang/www/get_started.html
index 8e4d36640be73..1068246c23cc7 100755
--- a/clang/www/get_started.html
+++ b/clang/www/get_started.html
@@ -67,15 +67,13 @@ On Unix-like Systems
   Build LLVM and Clang:
   
 cd llvm-project
-mkdir build (in-tree build is not supported)
-cd build
 This builds both LLVM and Clang in release mode. Alternatively, if
 you need a debug build, switch Release to Debug. See
 https://llvm.org/docs/CMake.html#frequently-used-cmake-variables";>frequently
 used cmake variables
 for more options.
 
-cmake -DLLVM_ENABLE_PROJECTS=clang -DCMAKE_BUILD_TYPE=Release -G 
"Unix Makefiles" ../llvm
-make
+cmake -DLLVM_ENABLE_PROJECTS=clang -DCMAKE_BUILD_TYPE=Release -G 
"Unix Makefiles" -S ./llvm -B ./build
+cmake --build ./build
 Note: For subsequent Clang development, you can just run
 make clang.
 CMake allows you to generate project files for several IDEs: Xcode,
@@ -156,11 +154,9 @@ Using Visual Studio
   Run CMake to generate the Visual Studio solution and project files:
   
 cd llvm-project
-mkdir build (for building without polluting the source 
dir)
-cd build
 
   If you are using Visual Studio 2019:
-  cmake -DLLVM_ENABLE_PROJECTS=clang -G "Visual Studio 16 2019" -A x64 
-Thost=x64 ..\llvm
+  cmake -DLLVM_ENABLE_PROJECTS=clang -G "Visual Studio 16 2019" -A x64 
-Thost=x64 -S .\llvm -B .\build
   -Thost=x64 is required, since the 32-bit linker will run out of 
memory.
 
 To generate x86 binaries instead of x64, pass -A Win32.
@@ -170,7 +166,7 @@ Using Visual Studio
build directory.
   
   
-  Build Clang:
+  Build Clang (from Visual Studio's GUI):
   
 Open LLVM.sln in Visual Studio.
 Build the "clang" project for just the compiler driver and front end, 
or
@@ -182,6 +178,10 @@ Using Visual Studio
   See 
  Hacking on clang - Testing using Visual Studio on Windows for 
information
  on running regression tests on Windows.
+  Build Clang (from command-line using `cmake`)
+  
+  cmake --build .\build
+  
 
 
 Using Ninja alongside Visual Studio

``




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


[clang] [clang/www/get_started.html] Use newer `cmake` syntax (PR #93503)

2024-05-27 Thread via cfe-commits

github-actions[bot] wrote:



Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be
notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this 
page.

If this is not working for you, it is probably because you do not have write
permissions for the repository. In which case you can instead tag reviewers by
name in a comment by using `@` followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review
by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate
is once a week. Please remember that you are asking for valuable time from 
other developers.

If you have further questions, they may be answered by the [LLVM GitHub User 
Guide](https://llvm.org/docs/GitHub.html).

You can also ask questions in a comment on this PR, on the [LLVM 
Discord](https://discord.com/invite/xS7Z362) or on the 
[forums](https://discourse.llvm.org/).

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


[clang] [clang/www/get_started.html] Use newer `cmake` syntax (PR #93503)

2024-05-27 Thread Samuel Marks via cfe-commits

https://github.com/SamuelMarks created 
https://github.com/llvm/llvm-project/pull/93503

None

>From bcdc355e9585e35f128a1b3ec71655d47bbf6986 Mon Sep 17 00:00:00 2001
From: Samuel Marks <807580+samuelma...@users.noreply.github.com>
Date: Tue, 28 May 2024 00:49:37 -0400
Subject: [PATCH] [clang/www/get_started.html] Use newer `cmake` syntax (that
 also supports Windows)

---
 clang/www/get_started.html | 16 
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/clang/www/get_started.html b/clang/www/get_started.html
index 8e4d36640be73..1068246c23cc7 100755
--- a/clang/www/get_started.html
+++ b/clang/www/get_started.html
@@ -67,15 +67,13 @@ On Unix-like Systems
   Build LLVM and Clang:
   
 cd llvm-project
-mkdir build (in-tree build is not supported)
-cd build
 This builds both LLVM and Clang in release mode. Alternatively, if
 you need a debug build, switch Release to Debug. See
 https://llvm.org/docs/CMake.html#frequently-used-cmake-variables";>frequently
 used cmake variables
 for more options.
 
-cmake -DLLVM_ENABLE_PROJECTS=clang -DCMAKE_BUILD_TYPE=Release -G 
"Unix Makefiles" ../llvm
-make
+cmake -DLLVM_ENABLE_PROJECTS=clang -DCMAKE_BUILD_TYPE=Release -G 
"Unix Makefiles" -S ./llvm -B ./build
+cmake --build ./build
 Note: For subsequent Clang development, you can just run
 make clang.
 CMake allows you to generate project files for several IDEs: Xcode,
@@ -156,11 +154,9 @@ Using Visual Studio
   Run CMake to generate the Visual Studio solution and project files:
   
 cd llvm-project
-mkdir build (for building without polluting the source 
dir)
-cd build
 
   If you are using Visual Studio 2019:
-  cmake -DLLVM_ENABLE_PROJECTS=clang -G "Visual Studio 16 2019" -A x64 
-Thost=x64 ..\llvm
+  cmake -DLLVM_ENABLE_PROJECTS=clang -G "Visual Studio 16 2019" -A x64 
-Thost=x64 -S .\llvm -B .\build
   -Thost=x64 is required, since the 32-bit linker will run out of 
memory.
 
 To generate x86 binaries instead of x64, pass -A Win32.
@@ -170,7 +166,7 @@ Using Visual Studio
build directory.
   
   
-  Build Clang:
+  Build Clang (from Visual Studio's GUI):
   
 Open LLVM.sln in Visual Studio.
 Build the "clang" project for just the compiler driver and front end, 
or
@@ -182,6 +178,10 @@ Using Visual Studio
   See 
  Hacking on clang - Testing using Visual Studio on Windows for 
information
  on running regression tests on Windows.
+  Build Clang (from command-line using `cmake`)
+  
+  cmake --build .\build
+  
 
 
 Using Ninja alongside Visual Studio

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


[clang] cc1: Report an error for multiple actions unless separated by -main-file-name (PR #91140)

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

MaskRay wrote:

> I don't really understand the rationale for this, and it's kind of annoying. 
> Most of the compiler's flags behave in the "last one wins" fashion (such as 
> `-O2` and `-O0`) and it's always been convenient to add the flag you want at 
> the end. Why treat action flags any differently? Also, even if this is 
> worthwhile for some reason I haven't considered, why is it an error rather 
> than a warning?

@bogner Some action options are shared between driver and cc1 but the behaviors 
could be quite different. See my example in the description.

```
%clang_cc1 -S -emit-llvm a.c # -S is overridden
%clang_cc1 -emit-llvm -S a.c # -emit-llvm is overridden
%clang_cc1 -fsyntax-only -S a.c  # -fsyntax-only is overridden
```

The strictness helps ensure that `%clang_cc1` tests do not have misleading, 
overridden action options.

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


[clang-tools-extra] 988cee7 - [unittest] Fix target triple

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

Author: Fangrui Song
Date: 2024-05-27T20:29:52-07:00
New Revision: 988cee7f96d6ba56dd465b9b2f3cfade3b6e2a3f

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

LOG: [unittest] Fix target triple

Added: 


Modified: 
clang-tools-extra/clangd/unittests/ClangdTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/unittests/ClangdTests.cpp 
b/clang-tools-extra/clangd/unittests/ClangdTests.cpp
index 864337b98f446..c324643498d94 100644
--- a/clang-tools-extra/clangd/unittests/ClangdTests.cpp
+++ b/clang-tools-extra/clangd/unittests/ClangdTests.cpp
@@ -392,7 +392,7 @@ TEST(ClangdServerTest, SearchLibDir) {
   ErrorCheckingCallbacks DiagConsumer;
   MockCompilationDatabase CDB;
   CDB.ExtraClangFlags.insert(CDB.ExtraClangFlags.end(),
- {"-xc++", "-target", "x86_64-linux-unknown",
+ {"-xc++", "--target=x86_64-unknown-linux-gnu",
   "-m64", "--gcc-toolchain=/randomusr",
   "-stdlib=libstdc++"});
   ClangdServer Server(CDB, FS, ClangdServer::optsForTest(), &DiagConsumer);



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


[clang] [llvm] pull (PR #93500)

2024-05-27 Thread via cfe-commits

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


[clang] [llvm] pull (PR #93500)

2024-05-27 Thread via cfe-commits

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


[clang] [llvm] pull (PR #93500)

2024-05-27 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-llvm-support

@llvm/pr-subscribers-clang

Author: cratelschen (cratelschen)


Changes



---

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


7 Files Affected:

- (modified) clang/include/clang/Frontend/CompilerInstance.h (+13-23) 
- (modified) clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp (+74-44) 
- (modified) clang/tools/driver/cc1_main.cpp (+6-5) 
- (modified) clang/tools/driver/driver.cpp (+25-9) 
- (added) kick-off.md (+8) 
- (modified) llvm/CMakeLists.txt (+37) 
- (modified) llvm/include/llvm/Support/TargetSelect.h (+104-97) 


``diff
diff --git a/clang/include/clang/Frontend/CompilerInstance.h 
b/clang/include/clang/Frontend/CompilerInstance.h
index 3464654284f19..109ccd2dc03a8 100644
--- a/clang/include/clang/Frontend/CompilerInstance.h
+++ b/clang/include/clang/Frontend/CompilerInstance.h
@@ -35,7 +35,7 @@ namespace llvm {
 class raw_fd_ostream;
 class Timer;
 class TimerGroup;
-}
+} // namespace llvm
 
 namespace clang {
 class ASTContext;
@@ -58,6 +58,7 @@ class SourceManager;
 class TargetInfo;
 enum class DisableValidationForModuleKind;
 
+// Cratels: CompilerInstance是一个工具类来持有单例的 Clang compiler对象。
 /// CompilerInstance - Helper class for managing a single instance of the Clang
 /// compiler.
 ///
@@ -204,6 +205,7 @@ class CompilerInstance : public ModuleLoader {
 
   CompilerInstance(const CompilerInstance &) = delete;
   void operator=(const CompilerInstance &) = delete;
+
 public:
   explicit CompilerInstance(
   std::shared_ptr PCHContainerOps =
@@ -270,9 +272,7 @@ class CompilerInstance : public ModuleLoader {
 
   /// Set the flag indicating whether we should (re)build the global
   /// module index.
-  void setBuildGlobalModuleIndex(bool Build) {
-BuildGlobalModuleIndex = Build;
-  }
+  void setBuildGlobalModuleIndex(bool Build) { BuildGlobalModuleIndex = Build; 
}
 
   /// @}
   /// @name Forwarding Methods
@@ -280,9 +280,7 @@ class CompilerInstance : public ModuleLoader {
 
   AnalyzerOptions &getAnalyzerOpts() { return Invocation->getAnalyzerOpts(); }
 
-  CodeGenOptions &getCodeGenOpts() {
-return Invocation->getCodeGenOpts();
-  }
+  CodeGenOptions &getCodeGenOpts() { return Invocation->getCodeGenOpts(); }
   const CodeGenOptions &getCodeGenOpts() const {
 return Invocation->getCodeGenOpts();
   }
@@ -308,9 +306,7 @@ class CompilerInstance : public ModuleLoader {
 return Invocation->getFileSystemOpts();
   }
 
-  FrontendOptions &getFrontendOpts() {
-return Invocation->getFrontendOpts();
-  }
+  FrontendOptions &getFrontendOpts() { return Invocation->getFrontendOpts(); }
   const FrontendOptions &getFrontendOpts() const {
 return Invocation->getFrontendOpts();
   }
@@ -350,9 +346,7 @@ class CompilerInstance : public ModuleLoader {
 return Invocation->getPreprocessorOutputOpts();
   }
 
-  TargetOptions &getTargetOpts() {
-return Invocation->getTargetOpts();
-  }
+  TargetOptions &getTargetOpts() { return Invocation->getTargetOpts(); }
   const TargetOptions &getTargetOpts() const {
 return Invocation->getTargetOpts();
   }
@@ -394,9 +388,7 @@ class CompilerInstance : public ModuleLoader {
   void setVerboseOutputStream(std::unique_ptr Value);
 
   /// Get the current stream for verbose output.
-  raw_ostream &getVerboseOutputStream() {
-return *VerboseOutputStream;
-  }
+  raw_ostream &getVerboseOutputStream() { return *VerboseOutputStream; }
 
   /// @}
   /// @name Target Info
@@ -574,8 +566,8 @@ class CompilerInstance : public ModuleLoader {
   void setASTReader(IntrusiveRefCntPtr Reader);
 
   std::shared_ptr getModuleDepCollector() const;
-  void setModuleDepCollector(
-  std::shared_ptr Collector);
+  void
+  setModuleDepCollector(std::shared_ptr Collector);
 
   std::shared_ptr getPCHContainerOperations() const {
 return ThePCHContainerOperations;
@@ -701,11 +693,9 @@ class CompilerInstance : public ModuleLoader {
   /// used by some diagnostics printers (for logging purposes only).
   ///
   /// \return The new object on success, or null on failure.
-  static IntrusiveRefCntPtr
-  createDiagnostics(DiagnosticOptions *Opts,
-DiagnosticConsumer *Client = nullptr,
-bool ShouldOwnClient = true,
-const CodeGenOptions *CodeGenOpts = nullptr);
+  static IntrusiveRefCntPtr createDiagnostics(
+  DiagnosticOptions *Opts, DiagnosticConsumer *Client = nullptr,
+  bool ShouldOwnClient = true, const CodeGenOptions *CodeGenOpts = 
nullptr);
 
   /// Create the file manager and replace any existing one with it.
   ///
diff --git a/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp 
b/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
index f85f0365616f9..134799a38a2c3 100644
--- a/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
+++ b/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
@@ -43,24 +43,38 @@ CreateFrontendBaseAction(Compiler

[clang] [llvm] pull (PR #93500)

2024-05-27 Thread via cfe-commits

github-actions[bot] wrote:



Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be
notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this 
page.

If this is not working for you, it is probably because you do not have write
permissions for the repository. In which case you can instead tag reviewers by
name in a comment by using `@` followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review
by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate
is once a week. Please remember that you are asking for valuable time from 
other developers.

If you have further questions, they may be answered by the [LLVM GitHub User 
Guide](https://llvm.org/docs/GitHub.html).

You can also ask questions in a comment on this PR, on the [LLVM 
Discord](https://discord.com/invite/xS7Z362) or on the 
[forums](https://discourse.llvm.org/).

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


[clang] [llvm] pull (PR #93500)

2024-05-27 Thread via cfe-commits

https://github.com/cratelschen created 
https://github.com/llvm/llvm-project/pull/93500

None

>From 421aa0371f834b6ebfad204c85f65695f8de2ae7 Mon Sep 17 00:00:00 2001
From: CratelsChen 
Date: Wed, 10 Apr 2024 19:54:19 +0800
Subject: [PATCH 1/6] =?UTF-8?q?=E6=96=B0=E5=A2=9E=20kickoff=20=E6=96=87?=
 =?UTF-8?q?=E6=A1=A3?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 kick-off.md | 8 
 1 file changed, 8 insertions(+)
 create mode 100644 kick-off.md

diff --git a/kick-off.md b/kick-off.md
new file mode 100644
index 0..97084536fe1eb
--- /dev/null
+++ b/kick-off.md
@@ -0,0 +1,8 @@
+# configuration
+> cmake -S llvm -B build -G Ninja -DCMAKE_BUILD_TYPE=Debug
+
+LLVM的工程很大,源码的源头一般认为是 llvm 文件夹,可以看到这里也是从其开始寻找 cmake 文件的。
+当前要求配置时必须制定 build 类型。
+
+# build
+> cmake --build build

>From 443a75daed4a0642e0e8799cf54ac1379a4ae9b9 Mon Sep 17 00:00:00 2001
From: CratelsChen 
Date: Wed, 10 Apr 2024 22:13:29 +0800
Subject: [PATCH 2/6] add comments for cmake file

---
 llvm/CMakeLists.txt | 21 +
 1 file changed, 21 insertions(+)

diff --git a/llvm/CMakeLists.txt b/llvm/CMakeLists.txt
index d511376e18ba5..2efcb5a0f1a0b 100644
--- a/llvm/CMakeLists.txt
+++ b/llvm/CMakeLists.txt
@@ -1,24 +1,45 @@
+# -S 指定目录为 llvm 时,cmake 就会从当前路径中查找 CMakeLists.txt 并执行
+#
+# 项目入口处
+#
 # See docs/CMake.html for instructions about how to build LLVM with CMake.
 
+# 指定当前工程支持的 cmake 语法的最小版本。该之前的语法旧语法就不再支持了。
 cmake_minimum_required(VERSION 3.20.0)
 
+# 设置变量LLVM_COMMON_CMAKE_UTILS执行外层 cmake 文件夹的路径。
+# 该路径下面的 Modules 文件夹下有很多 .cmake 文件后续可能会用。
 set(LLVM_COMMON_CMAKE_UTILS ${CMAKE_CURRENT_SOURCE_DIR}/../cmake)
+message(${LLVM_COMMON_CMAKE_UTILS})
+
+message("将 policy 文件引入当前 cmake 文件")
 include(${LLVM_COMMON_CMAKE_UTILS}/Modules/CMakePolicy.cmake
   NO_POLICY_SCOPE)
 
 # Builds with custom install names and installation rpath setups may not work
 # in the build tree. Allow these cases to use CMake's default build tree
 # behavior by setting `LLVM_NO_INSTALL_NAME_DIR_FOR_BUILD_TREE` to do this.
+# 定义 option:LLVM_NO_INSTALL_NAME_DIR_FOR_BUILD_TREE,允许开发者在 build 的时候通过-DOPTION 
设置不同的值来影响编译过程。
 option(LLVM_NO_INSTALL_NAME_DIR_FOR_BUILD_TREE "If set, use CMake's default 
build tree install name directory logic (Darwin only)" OFF)
+
+# 将缓存的变量标记为高级变量。其中,高级变量指的是那些在CMake 
GUI中,只有当“显示高级选项”被打开时才会被显示的变量。如果CLEAR是第一个选项,参数中的高级变量将变回
+# 
非高级变量。如果FORCE是第一个选项,参数中的变量会被提升为高级变量。如果两者都未出现,新的变量会被标记为高级变量;如果这个变量已经是高级/非高级状态的话,它将会维
+# 持原状。该命令在脚本中无效
+# 高级选项通常是那些不经常使用的选项,或者对大多数用户来说可能不重要的选项。
 mark_as_advanced(LLVM_NO_INSTALL_NAME_DIR_FOR_BUILD_TREE)
 if(NOT LLVM_NO_INSTALL_NAME_DIR_FOR_BUILD_TREE)
   set(CMAKE_BUILD_WITH_INSTALL_NAME_DIR ON)
 endif()
 
+message("将 LLVM 的版本信息引入")
 include(${LLVM_COMMON_CMAKE_UTILS}/Modules/LLVMVersion.cmake)
 
+# 设置当前目录和子目录的属性
+# 该属性只在当前目录以及其子目录起作用
+# set_property:设置私属性值,在当前作用于起作用
 set_directory_properties(PROPERTIES LLVM_VERSION_MAJOR "${LLVM_VERSION_MAJOR}")
 
+
 if (NOT PACKAGE_VERSION)
   set(PACKAGE_VERSION
 
"${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH}${LLVM_VERSION_SUFFIX}")

>From 7766ae8f97fffe7a592f25d0bdb4abd18133ca90 Mon Sep 17 00:00:00 2001
From: CratelsChen 
Date: Wed, 10 Apr 2024 23:48:32 +0800
Subject: [PATCH 3/6] add comments for cmake file

---
 llvm/CMakeLists.txt | 16 
 1 file changed, 16 insertions(+)

diff --git a/llvm/CMakeLists.txt b/llvm/CMakeLists.txt
index 2efcb5a0f1a0b..8f8cfbcf6a1e9 100644
--- a/llvm/CMakeLists.txt
+++ b/llvm/CMakeLists.txt
@@ -12,6 +12,15 @@ cmake_minimum_required(VERSION 3.20.0)
 set(LLVM_COMMON_CMAKE_UTILS ${CMAKE_CURRENT_SOURCE_DIR}/../cmake)
 message(${LLVM_COMMON_CMAKE_UTILS})
 
+# message的信息种类:
+# (无) = 重要消息;
+#  STATUS = 非重要消息;
+#  WARNING = CMake 警告, 会继续执行;
+#  AUTHOR_WARNING = CMake 警告 (dev), 会继续执行;
+#  SEND_ERROR = CMake 错误, 继续执行,但是会跳过生成的步骤;
+#  FATAL_ERROR = CMake 错误, 终止所有处理过程;
+
+
 message("将 policy 文件引入当前 cmake 文件")
 include(${LLVM_COMMON_CMAKE_UTILS}/Modules/CMakePolicy.cmake
   NO_POLICY_SCOPE)
@@ -50,6 +59,7 @@ if(NOT DEFINED LLVM_SHLIB_SYMBOL_VERSION)
   set(LLVM_SHLIB_SYMBOL_VERSION 
"LLVM_${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}")
 endif()
 
+# 如果在 windows 平台下使用生成器Visual Studio,输出 warning 信息
 if ((CMAKE_GENERATOR MATCHES "Visual Studio") AND (MSVC_TOOLSET_VERSION LESS 
142) AND (CMAKE_GENERATOR_TOOLSET STREQUAL ""))
   message(WARNING "Visual Studio generators use the x86 host compiler by "
   "default, even for 64-bit targets. This can result in linker 
"
@@ -57,16 +67,19 @@ if ((CMAKE_GENERATOR MATCHES "Visual Studio") AND 
(MSVC_TOOLSET_VERSION LESS 142
   "host compiler, pass -Thost=x64 on the CMake command line.")
 endif()
 
+# 如果在 MacOS 平台下使用生成器XCode,且不是苹果的芯片架构,设置架构信息为x86_64
 if (CMAKE_GENERATOR STREQUAL "Xcode" AND NOT CMAKE_OSX_ARCHITECTURES)
   # Some CMake features like object libraries get confused if you don't
   # explicitly specify an architecture setting with the Xcode generator.
   set(CMAKE_OSX_ARCHITECTURES "x86_64")

[clang] [CodeGen] Hidden visibility for prof version var (PR #93496)

2024-05-27 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-codegen

Author: None (gulfemsavrun)


Changes

This patch adds hidden visibility to the variable
that is used by the single byte counters mode in
source-based code coverage.

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


1 Files Affected:

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


``diff
diff --git a/clang/lib/CodeGen/CodeGenPGO.cpp b/clang/lib/CodeGen/CodeGenPGO.cpp
index 76704c4d7be4a..db8e6f55302ad 100644
--- a/clang/lib/CodeGen/CodeGenPGO.cpp
+++ b/clang/lib/CodeGen/CodeGenPGO.cpp
@@ -1340,7 +1340,7 @@ void CodeGenPGO::setProfileVersion(llvm::Module &M) {
 llvm::APInt(64, ProfileVersion)),
 VarName);
 
-
IRLevelVersionVariable->setVisibility(llvm::GlobalValue::DefaultVisibility);
+IRLevelVersionVariable->setVisibility(llvm::GlobalValue::HiddenVisibility);
 llvm::Triple TT(M.getTargetTriple());
 if (TT.supportsCOMDAT()) {
   IRLevelVersionVariable->setLinkage(llvm::GlobalValue::ExternalLinkage);

``




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


[clang] [CodeGen] Hidden visibility for prof version var (PR #93496)

2024-05-27 Thread via cfe-commits

https://github.com/gulfemsavrun created 
https://github.com/llvm/llvm-project/pull/93496

This patch adds hidden visibility to the variable
that is used by the single byte counters mode in
source-based code coverage.

>From 1e0625be05a30118eeadd1d65df675da4cddc313 Mon Sep 17 00:00:00 2001
From: Gulfem Savrun Yeniceri 
Date: Tue, 28 May 2024 00:04:25 +
Subject: [PATCH] [CodeGen] Hidden visibility for prof version var

This patch adds hidden visibility to the variable
that is used by the single byte counters mode in
source-based code coverage.
---
 clang/lib/CodeGen/CodeGenPGO.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/CodeGen/CodeGenPGO.cpp b/clang/lib/CodeGen/CodeGenPGO.cpp
index 76704c4d7be4a..db8e6f55302ad 100644
--- a/clang/lib/CodeGen/CodeGenPGO.cpp
+++ b/clang/lib/CodeGen/CodeGenPGO.cpp
@@ -1340,7 +1340,7 @@ void CodeGenPGO::setProfileVersion(llvm::Module &M) {
 llvm::APInt(64, ProfileVersion)),
 VarName);
 
-
IRLevelVersionVariable->setVisibility(llvm::GlobalValue::DefaultVisibility);
+IRLevelVersionVariable->setVisibility(llvm::GlobalValue::HiddenVisibility);
 llvm::Triple TT(M.getTargetTriple());
 if (TT.supportsCOMDAT()) {
   IRLevelVersionVariable->setLinkage(llvm::GlobalValue::ExternalLinkage);

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


[clang] a4f75ec - [C++20] [Modules] Don't record implicitly declarations to BMI by default (#93459)

2024-05-27 Thread via cfe-commits

Author: Chuanqi Xu
Date: 2024-05-28T09:36:30+08:00
New Revision: a4f75ec730ee573fc35a51264a907b1f05b53e3b

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

LOG: [C++20] [Modules] Don't record implicitly declarations to BMI by default 
(#93459)

I found we may insert unused implciit declarations like AArch SVE
declarations by default on AArch64 due to we will insert that by
default. But it should be completely redundant and this patch tries to
remove that.

Added: 
clang/test/Modules/no-implicit-declarations.cppm

Modified: 
clang/lib/Serialization/ASTWriter.cpp

Removed: 




diff  --git a/clang/lib/Serialization/ASTWriter.cpp 
b/clang/lib/Serialization/ASTWriter.cpp
index 00b0e48083217..a85cd94fd5b5a 100644
--- a/clang/lib/Serialization/ASTWriter.cpp
+++ b/clang/lib/Serialization/ASTWriter.cpp
@@ -5037,6 +5037,14 @@ void ASTWriter::PrepareWritingSpecialDecls(Sema 
&SemaRef) {
 continue;
 }
 
+// If we're writing C++ named modules, don't emit declarations which are
+// not from modules by default. They may be built in declarations (be
+// handled above) or implcit declarations (see the implementation of
+// `Sema::Initialize()` for example).
+if (isWritingStdCXXNamedModules() && !D->getOwningModule() &&
+D->isImplicit())
+  continue;
+
 GetDeclRef(D);
   }
 
@@ -6197,8 +6205,9 @@ bool ASTWriter::wasDeclEmitted(const Decl *D) const {
 return true;
 
   bool Emitted = DeclIDs.contains(D);
-  assert((Emitted || GeneratingReducedBMI) &&
- "The declaration can only be omitted in reduced BMI.");
+  assert((Emitted || (!D->getOwningModule() && isWritingStdCXXNamedModules()) 
||
+  GeneratingReducedBMI) &&
+ "The declaration within modules can only be omitted in reduced BMI.");
   return Emitted;
 }
 

diff  --git a/clang/test/Modules/no-implicit-declarations.cppm 
b/clang/test/Modules/no-implicit-declarations.cppm
new file mode 100644
index 0..319d3a432ea23
--- /dev/null
+++ b/clang/test/Modules/no-implicit-declarations.cppm
@@ -0,0 +1,26 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+//
+// RUN: %clang_cc1 -std=c++20 %s -emit-module-interface -o %t/a.pcm
+// RUN: llvm-bcanalyzer --dump --disable-histogram --show-binary-blobs 
%t/a.pcm > %t/a.dump
+// RUN: cat %t/a.dump | FileCheck %s
+//
+// RUN: %clang_cc1 -std=c++20 %s -emit-reduced-module-interface -o %t/a.pcm
+// RUN: llvm-bcanalyzer --dump --disable-histogram --show-binary-blobs 
%t/a.pcm > %t/a.dump
+// RUN: cat %t/a.dump | FileCheck %s
+
+export module a;
+// Contain something at least to make sure the compiler won't
+// optimize this out.
+export int a = 43;
+
+// CHECK:  



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


[clang] [C++20] [Modules] Don't record implicitly declarations to BMI by default (PR #93459)

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

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


[clang] [clang] Be const-correct with all uses of `Module *`. (PR #93493)

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

ChuanqiXu9 wrote:

> > Can you make sure that at every place this PR touches `const` makes sense? 
> > I found out recently that we can be quite good at pretending that something 
> > is `const`, all the way down until we realize we need a `const_cast`, 
> > because modification is required in that one place.
> 
> I'm not quite sure I understand the question. This PR doesn't add any 
> `const_cast`, and `const` is checked by the compiler so a successful build 
> shows that we're never modifying something declared `const`. What additional 
> work are you wanting?

The question is that it may be fine to be `const` today but it becomes not the 
case later. So we may have to make const  function back to non-const function 
again. So one style to do such things is to understand that the new `const` 
decorated places are meant to be `const`. Otherwise I'll suggest to only mark 
the places that need to be change by the following patch as `const`.

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


[clang] [clang-tools-extra] [libcxx] [clang][Modules] Remove unnecessary includes of `Module.h` (PR #93417)

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


@@ -159,7 +159,8 @@ class APINotesManager {
   ArrayRef getCurrentModuleReaders() const {
 bool HasPublic = CurrentModuleReaders[ReaderKind::Public];
 bool HasPrivate = CurrentModuleReaders[ReaderKind::Private];
-assert((!HasPrivate || HasPublic) && "private module requires public 
module");
+assert((!HasPrivate || HasPublic) &&
+   "private module requires public module");

ChuanqiXu9 wrote:

Yes, we prefer to format the changed line only. Otherwise the backporting may 
be problematic. And git blaming will be harder.

One possible way maybe:

> git diff -U0 --no-color --relative HEAD^ | 
> clang/tools/clang-format/clang-format-diff.py -p1 -i

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


[clang] [Clang][AArch64][ARM]: Fix Inefficient loads/stores of _BitInt(N) (PR #93495)

2024-05-27 Thread Hassnaa Hamdi via cfe-commits

https://github.com/hassnaaHamdi updated 
https://github.com/llvm/llvm-project/pull/93495

>From 6b7cc14e5dcca7416c549bd156585e2a61d4d883 Mon Sep 17 00:00:00 2001
From: Hassnaa Hamdi 
Date: Tue, 28 May 2024 01:04:00 +
Subject: [PATCH] [Clang][AArch64][ARM]: Fix Inefficient loads/stores of
 _BitInt(N)

- Update clang codegen for loads/stores to read/write the legal in-memory 
representation for _BitInt(N <= 128) and _BitInt(N <= 64).
- AArch64: for _BitInt(N <= 128) the machine type is the smallest (un)signed 
fundamental integral data types.
- ARM: for _BitInt(N <= 64) the machine type is the smallest (un)signed 
fundamental integral data types.
So, Loads and Stores will be as following:
N - bit-precise integer size as declared
M - number of bits in the representation, M >= N
Loads
%u = load iM, ptr %p
%v = trunc iM %u to iN
Stores
%u = Xext iN %v to iM
store iM %u, ptr %p
where Xext is zext or sext on ARM, depending on C type, and zext for AArch64.

These changes are according to the ABI documentation for:
ARM: https://github.com/ARM-software/abi-aa/blob/main/aapcs32/aapcs32.rst
AArch64: https://github.com/ARM-software/abi-aa/blob/main/aapcs64/aapcs64.rst
Change-Id: I03d675afb4e749b00fef075aa10923682232dd79

Change-Id: I4beac3b92e06506606c8ee57866507a62ba42fba
---
 clang/include/clang/Basic/TargetInfo.h |  5 +++
 clang/lib/Basic/Targets/AArch64.cpp| 10 +
 clang/lib/Basic/Targets/AArch64.h  |  2 +
 clang/lib/Basic/Targets/ARM.cpp| 16 
 clang/lib/Basic/Targets/ARM.h  |  4 ++
 clang/lib/CodeGen/CGExpr.cpp   | 17 +++-
 clang/lib/CodeGen/CodeGenTypes.cpp |  4 ++
 clang/test/CodeGen/AArch64/BitInt.c| 35 +
 clang/test/CodeGen/Arm/BitInt.c| 36 +
 clang/test/CodeGen/attr-noundef.cpp|  6 +--
 clang/test/CodeGen/builtins-bitint.c   | 54 ++
 11 files changed, 161 insertions(+), 28 deletions(-)
 create mode 100644 clang/test/CodeGen/AArch64/BitInt.c
 create mode 100644 clang/test/CodeGen/Arm/BitInt.c

diff --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index 8a6511b9ced83..f627e6cdd8983 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -667,6 +667,11 @@ class TargetInfo : public TransferrableTargetInfo,
 return false;
   }
 
+  // Different targets may support different machine type width for the _BitInt
+  virtual unsigned getBitIntLegalWidth(unsigned Width) const { return Width; }
+
+  virtual bool isBitIntSignExtended(bool IsSigned) const { return false; }
+
   // Different targets may support a different maximum width for the _BitInt
   // type, depending on what operations are supported.
   virtual size_t getMaxBitIntWidth() const {
diff --git a/clang/lib/Basic/Targets/AArch64.cpp 
b/clang/lib/Basic/Targets/AArch64.cpp
index 5db1ce78c657f..b583e2617bb17 100644
--- a/clang/lib/Basic/Targets/AArch64.cpp
+++ b/clang/lib/Basic/Targets/AArch64.cpp
@@ -221,6 +221,16 @@ bool AArch64TargetInfo::validateTarget(DiagnosticsEngine 
&Diags) const {
   return true;
 }
 
+unsigned AArch64TargetInfo::getBitIntLegalWidth(unsigned Width) const {
+  unsigned IntegralSizes[] = {32, 64, 128};
+  const unsigned ARR_SZ = sizeof(IntegralSizes) / sizeof(unsigned);
+  for (unsigned I = 0; I < ARR_SZ; I++) {
+if (IntegralSizes[I] > Width)
+  return IntegralSizes[I];
+  }
+  return Width;
+}
+
 bool AArch64TargetInfo::validateBranchProtection(StringRef Spec, StringRef,
  BranchProtectionInfo &BPI,
  StringRef &Err) const {
diff --git a/clang/lib/Basic/Targets/AArch64.h 
b/clang/lib/Basic/Targets/AArch64.h
index 12fb50286f751..89c6af00e628c 100644
--- a/clang/lib/Basic/Targets/AArch64.h
+++ b/clang/lib/Basic/Targets/AArch64.h
@@ -202,6 +202,8 @@ class LLVM_LIBRARY_VISIBILITY AArch64TargetInfo : public 
TargetInfo {
   bool hasBitIntType() const override { return true; }
 
   bool validateTarget(DiagnosticsEngine &Diags) const override;
+
+  unsigned getBitIntLegalWidth(unsigned Width) const override;
 };
 
 class LLVM_LIBRARY_VISIBILITY AArch64leTargetInfo : public AArch64TargetInfo {
diff --git a/clang/lib/Basic/Targets/ARM.cpp b/clang/lib/Basic/Targets/ARM.cpp
index 7423626d7c3cb..cf274a71dd2b6 100644
--- a/clang/lib/Basic/Targets/ARM.cpp
+++ b/clang/lib/Basic/Targets/ARM.cpp
@@ -1344,6 +1344,22 @@ int ARMTargetInfo::getEHDataRegisterNumber(unsigned 
RegNo) const {
 
 bool ARMTargetInfo::hasSjLjLowering() const { return true; }
 
+unsigned ARMTargetInfo::getBitIntLegalWidth(unsigned Width) const {
+  unsigned IntegralSizes[] = {32, 64};
+  const unsigned ARR_SZ = sizeof(IntegralSizes) / sizeof(unsigned);
+  for (unsigned I = 0; I < ARR_SZ; I++) {
+if (IntegralSizes[I] > Width)
+  return IntegralSizes[I];
+  }
+  return Width;
+}
+
+bool ARMTargetInfo::isBitIntSignExtended(bool IsSigned) const {
+  if (IsSigned

[clang] [Clang][AArch64][ARM]: Fix Inefficient loads/stores of _BitInt(N) (PR #93495)

2024-05-27 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Hassnaa Hamdi (hassnaaHamdi)


Changes

- Update clang codegen for loads/stores to read/write the legal in-memory 
representation for _BitInt(N <= 128) and _BitInt(N <= 64).
- AArch64: for _BitInt(N <= 128) the machine type is the smallest (un)signed 
fundamental integral data types.
- ARM: for _BitInt(N <= 64) the machine type is the smallest (un)signed 
fundamental integral data types.
- So, Loads and Stores will be as following:
N - bit-precise integer size as declared
M - number of bits in the representation, M >= N
```
Loads
%u = load iM, ptr %p
%v = trunc iM %u to iN
```
```
Stores
%u = Xext iN %v to iM
store iM %u, ptr %p
where Xext is zext or sext on ARM, depending on C type, and zext for AArch64.
```

These changes are according to the ABI documentation for: 
ARM: https://github.com/ARM-software/abi-aa/blob/main/aapcs32/aapcs32.rst 
AArch64: https://github.com/ARM-software/abi-aa/blob/main/aapcs64/aapcs64.rst 

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


11 Files Affected:

- (modified) clang/include/clang/Basic/TargetInfo.h (+9) 
- (modified) clang/lib/Basic/Targets/AArch64.cpp (+10) 
- (modified) clang/lib/Basic/Targets/AArch64.h (+2) 
- (modified) clang/lib/Basic/Targets/ARM.cpp (+16) 
- (modified) clang/lib/Basic/Targets/ARM.h (+4) 
- (modified) clang/lib/CodeGen/CGExpr.cpp (+16-1) 
- (modified) clang/lib/CodeGen/CodeGenTypes.cpp (+3) 
- (added) clang/test/CodeGen/AArch64/BitInt.c (+35) 
- (added) clang/test/CodeGen/Arm/BitInt.c (+36) 
- (modified) clang/test/CodeGen/attr-noundef.cpp (+3-3) 
- (modified) clang/test/CodeGen/builtins-bitint.c (+30-24) 


``diff
diff --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index 8a6511b9ced83..92b03e8d6bdbc 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -667,6 +667,15 @@ class TargetInfo : public TransferrableTargetInfo,
 return false;
   }
 
+  // Different targets may support different machine type width for the _BitInt
+  virtual unsigned getBitIntLegalWidth(unsigned Width) const {
+return Width;
+  }
+
+  virtual bool isBitIntSignExtended(bool IsSigned) const {
+return false;
+  }
+
   // Different targets may support a different maximum width for the _BitInt
   // type, depending on what operations are supported.
   virtual size_t getMaxBitIntWidth() const {
diff --git a/clang/lib/Basic/Targets/AArch64.cpp 
b/clang/lib/Basic/Targets/AArch64.cpp
index 5db1ce78c657f..a5d66cb44b566 100644
--- a/clang/lib/Basic/Targets/AArch64.cpp
+++ b/clang/lib/Basic/Targets/AArch64.cpp
@@ -221,6 +221,16 @@ bool AArch64TargetInfo::validateTarget(DiagnosticsEngine 
&Diags) const {
   return true;
 }
 
+unsigned AArch64TargetInfo::getBitIntLegalWidth(unsigned Width) const {
+  unsigned IntegralSizes[] = {32, 64, 128};
+  const unsigned ARR_SZ = sizeof(IntegralSizes) / sizeof(unsigned);
+  for (unsigned I = 0; I < ARR_SZ; I ++) {
+if (IntegralSizes[I] > Width)
+  return IntegralSizes[I];
+  }
+  return Width;
+}
+
 bool AArch64TargetInfo::validateBranchProtection(StringRef Spec, StringRef,
  BranchProtectionInfo &BPI,
  StringRef &Err) const {
diff --git a/clang/lib/Basic/Targets/AArch64.h 
b/clang/lib/Basic/Targets/AArch64.h
index 12fb50286f751..89c6af00e628c 100644
--- a/clang/lib/Basic/Targets/AArch64.h
+++ b/clang/lib/Basic/Targets/AArch64.h
@@ -202,6 +202,8 @@ class LLVM_LIBRARY_VISIBILITY AArch64TargetInfo : public 
TargetInfo {
   bool hasBitIntType() const override { return true; }
 
   bool validateTarget(DiagnosticsEngine &Diags) const override;
+
+  unsigned getBitIntLegalWidth(unsigned Width) const override;
 };
 
 class LLVM_LIBRARY_VISIBILITY AArch64leTargetInfo : public AArch64TargetInfo {
diff --git a/clang/lib/Basic/Targets/ARM.cpp b/clang/lib/Basic/Targets/ARM.cpp
index 7423626d7c3cb..a074bafacc25f 100644
--- a/clang/lib/Basic/Targets/ARM.cpp
+++ b/clang/lib/Basic/Targets/ARM.cpp
@@ -1344,6 +1344,22 @@ int ARMTargetInfo::getEHDataRegisterNumber(unsigned 
RegNo) const {
 
 bool ARMTargetInfo::hasSjLjLowering() const { return true; }
 
+unsigned ARMTargetInfo::getBitIntLegalWidth(unsigned Width) const {
+  unsigned IntegralSizes[] = {32, 64};
+  const unsigned ARR_SZ = sizeof(IntegralSizes) / sizeof(unsigned);
+  for (unsigned I = 0; I < ARR_SZ; I ++) {
+if (IntegralSizes[I] > Width)
+  return IntegralSizes[I];
+  }
+  return Width;
+}
+
+bool ARMTargetInfo::isBitIntSignExtended(bool IsSigned) const {
+if (IsSigned)
+  return true;
+return false;
+}
+
 ARMleTargetInfo::ARMleTargetInfo(const llvm::Triple &Triple,
  const TargetOptions &Opts)
 : ARMTargetInfo(Triple, Opts) {}
diff --git a/clang/lib/Basic/Targets/ARM.h b/clang/lib/Basic/Targets/ARM.h
index df9855a52e61c..679c29e786cc9 100644
--- a/clang/lib/Ba

[clang] [Clang][AArch64][ARM]: Fix Inefficient loads/stores of _BitInt(N) (PR #93495)

2024-05-27 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-backend-aarch64

@llvm/pr-subscribers-backend-arm

Author: Hassnaa Hamdi (hassnaaHamdi)


Changes

- Update clang codegen for loads/stores to read/write the legal in-memory 
representation for _BitInt(N <= 128) and _BitInt(N <= 64).
- AArch64: for _BitInt(N <= 128) the machine type is the smallest (un)signed 
fundamental integral data types.
- ARM: for _BitInt(N <= 64) the machine type is the smallest (un)signed 
fundamental integral data types.
- So, Loads and Stores will be as following:
N - bit-precise integer size as declared
M - number of bits in the representation, M >= N
```
Loads
%u = load iM, ptr %p
%v = trunc iM %u to iN
```
```
Stores
%u = Xext iN %v to iM
store iM %u, ptr %p
where Xext is zext or sext on ARM, depending on C type, and zext for AArch64.
```

These changes are according to the ABI documentation for: 
ARM: https://github.com/ARM-software/abi-aa/blob/main/aapcs32/aapcs32.rst 
AArch64: https://github.com/ARM-software/abi-aa/blob/main/aapcs64/aapcs64.rst 

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


11 Files Affected:

- (modified) clang/include/clang/Basic/TargetInfo.h (+9) 
- (modified) clang/lib/Basic/Targets/AArch64.cpp (+10) 
- (modified) clang/lib/Basic/Targets/AArch64.h (+2) 
- (modified) clang/lib/Basic/Targets/ARM.cpp (+16) 
- (modified) clang/lib/Basic/Targets/ARM.h (+4) 
- (modified) clang/lib/CodeGen/CGExpr.cpp (+16-1) 
- (modified) clang/lib/CodeGen/CodeGenTypes.cpp (+3) 
- (added) clang/test/CodeGen/AArch64/BitInt.c (+35) 
- (added) clang/test/CodeGen/Arm/BitInt.c (+36) 
- (modified) clang/test/CodeGen/attr-noundef.cpp (+3-3) 
- (modified) clang/test/CodeGen/builtins-bitint.c (+30-24) 


``diff
diff --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index 8a6511b9ced83..92b03e8d6bdbc 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -667,6 +667,15 @@ class TargetInfo : public TransferrableTargetInfo,
 return false;
   }
 
+  // Different targets may support different machine type width for the _BitInt
+  virtual unsigned getBitIntLegalWidth(unsigned Width) const {
+return Width;
+  }
+
+  virtual bool isBitIntSignExtended(bool IsSigned) const {
+return false;
+  }
+
   // Different targets may support a different maximum width for the _BitInt
   // type, depending on what operations are supported.
   virtual size_t getMaxBitIntWidth() const {
diff --git a/clang/lib/Basic/Targets/AArch64.cpp 
b/clang/lib/Basic/Targets/AArch64.cpp
index 5db1ce78c657f..a5d66cb44b566 100644
--- a/clang/lib/Basic/Targets/AArch64.cpp
+++ b/clang/lib/Basic/Targets/AArch64.cpp
@@ -221,6 +221,16 @@ bool AArch64TargetInfo::validateTarget(DiagnosticsEngine 
&Diags) const {
   return true;
 }
 
+unsigned AArch64TargetInfo::getBitIntLegalWidth(unsigned Width) const {
+  unsigned IntegralSizes[] = {32, 64, 128};
+  const unsigned ARR_SZ = sizeof(IntegralSizes) / sizeof(unsigned);
+  for (unsigned I = 0; I < ARR_SZ; I ++) {
+if (IntegralSizes[I] > Width)
+  return IntegralSizes[I];
+  }
+  return Width;
+}
+
 bool AArch64TargetInfo::validateBranchProtection(StringRef Spec, StringRef,
  BranchProtectionInfo &BPI,
  StringRef &Err) const {
diff --git a/clang/lib/Basic/Targets/AArch64.h 
b/clang/lib/Basic/Targets/AArch64.h
index 12fb50286f751..89c6af00e628c 100644
--- a/clang/lib/Basic/Targets/AArch64.h
+++ b/clang/lib/Basic/Targets/AArch64.h
@@ -202,6 +202,8 @@ class LLVM_LIBRARY_VISIBILITY AArch64TargetInfo : public 
TargetInfo {
   bool hasBitIntType() const override { return true; }
 
   bool validateTarget(DiagnosticsEngine &Diags) const override;
+
+  unsigned getBitIntLegalWidth(unsigned Width) const override;
 };
 
 class LLVM_LIBRARY_VISIBILITY AArch64leTargetInfo : public AArch64TargetInfo {
diff --git a/clang/lib/Basic/Targets/ARM.cpp b/clang/lib/Basic/Targets/ARM.cpp
index 7423626d7c3cb..a074bafacc25f 100644
--- a/clang/lib/Basic/Targets/ARM.cpp
+++ b/clang/lib/Basic/Targets/ARM.cpp
@@ -1344,6 +1344,22 @@ int ARMTargetInfo::getEHDataRegisterNumber(unsigned 
RegNo) const {
 
 bool ARMTargetInfo::hasSjLjLowering() const { return true; }
 
+unsigned ARMTargetInfo::getBitIntLegalWidth(unsigned Width) const {
+  unsigned IntegralSizes[] = {32, 64};
+  const unsigned ARR_SZ = sizeof(IntegralSizes) / sizeof(unsigned);
+  for (unsigned I = 0; I < ARR_SZ; I ++) {
+if (IntegralSizes[I] > Width)
+  return IntegralSizes[I];
+  }
+  return Width;
+}
+
+bool ARMTargetInfo::isBitIntSignExtended(bool IsSigned) const {
+if (IsSigned)
+  return true;
+return false;
+}
+
 ARMleTargetInfo::ARMleTargetInfo(const llvm::Triple &Triple,
  const TargetOptions &Opts)
 : ARMTargetInfo(Triple, Opts) {}
diff --git a/clang/lib/Basic/Targets/ARM.h b/clang/lib/Basic/Targets/ARM.h
index df9855a52e6

[clang] [Clang][AArch64][ARM]: Fix Inefficient loads/stores of _BitInt(N) (PR #93495)

2024-05-27 Thread Hassnaa Hamdi via cfe-commits

https://github.com/hassnaaHamdi created 
https://github.com/llvm/llvm-project/pull/93495

- Update clang codegen for loads/stores to read/write the legal in-memory 
representation for _BitInt(N <= 128) and _BitInt(N <= 64).
- AArch64: for _BitInt(N <= 128) the machine type is the smallest (un)signed 
fundamental integral data types.
- ARM: for _BitInt(N <= 64) the machine type is the smallest (un)signed 
fundamental integral data types.
- So, Loads and Stores will be as following:
N - bit-precise integer size as declared
M - number of bits in the representation, M >= N
```
Loads
%u = load iM, ptr %p
%v = trunc iM %u to iN
```
```
Stores
%u = Xext iN %v to iM
store iM %u, ptr %p
where Xext is zext or sext on ARM, depending on C type, and zext for AArch64.
```

These changes are according to the ABI documentation for: 
ARM: https://github.com/ARM-software/abi-aa/blob/main/aapcs32/aapcs32.rst 
AArch64: https://github.com/ARM-software/abi-aa/blob/main/aapcs64/aapcs64.rst 

>From 0e5229575f851343d87154c1e22242ada17c084d Mon Sep 17 00:00:00 2001
From: Hassnaa Hamdi 
Date: Tue, 28 May 2024 01:04:00 +
Subject: [PATCH] [Clang][AArch64][ARM]: Fix Inefficient loads/stores of
 _BitInt(N)

- Update clang codegen for loads/stores to read/write the legal in-memory 
representation for _BitInt(N <= 128) and _BitInt(N <= 64).
- AArch64: for _BitInt(N <= 128) the machine type is the smallest (un)signed 
fundamental integral data types.
- ARM: for _BitInt(N <= 64) the machine type is the smallest (un)signed 
fundamental integral data types.
So, Loads and Stores will be as following:
N - bit-precise integer size as declared
M - number of bits in the representation, M >= N
Loads
%u = load iM, ptr %p
%v = trunc iM %u to iN
Stores
%u = Xext iN %v to iM
store iM %u, ptr %p
where Xext is zext or sext on ARM, depending on C type, and zext for AArch64.

These changes are according to the ABI documentation for:
ARM: https://github.com/ARM-software/abi-aa/blob/main/aapcs32/aapcs32.rst
AArch64: https://github.com/ARM-software/abi-aa/blob/main/aapcs64/aapcs64.rst
Change-Id: I03d675afb4e749b00fef075aa10923682232dd79

Change-Id: I4beac3b92e06506606c8ee57866507a62ba42fba
---
 clang/include/clang/Basic/TargetInfo.h |  9 +
 clang/lib/Basic/Targets/AArch64.cpp| 10 +
 clang/lib/Basic/Targets/AArch64.h  |  2 +
 clang/lib/Basic/Targets/ARM.cpp| 16 
 clang/lib/Basic/Targets/ARM.h  |  4 ++
 clang/lib/CodeGen/CGExpr.cpp   | 17 +++-
 clang/lib/CodeGen/CodeGenTypes.cpp |  3 ++
 clang/test/CodeGen/AArch64/BitInt.c| 35 +
 clang/test/CodeGen/Arm/BitInt.c| 36 +
 clang/test/CodeGen/attr-noundef.cpp|  6 +--
 clang/test/CodeGen/builtins-bitint.c   | 54 ++
 11 files changed, 164 insertions(+), 28 deletions(-)
 create mode 100644 clang/test/CodeGen/AArch64/BitInt.c
 create mode 100644 clang/test/CodeGen/Arm/BitInt.c

diff --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index 8a6511b9ced83..92b03e8d6bdbc 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -667,6 +667,15 @@ class TargetInfo : public TransferrableTargetInfo,
 return false;
   }
 
+  // Different targets may support different machine type width for the _BitInt
+  virtual unsigned getBitIntLegalWidth(unsigned Width) const {
+return Width;
+  }
+
+  virtual bool isBitIntSignExtended(bool IsSigned) const {
+return false;
+  }
+
   // Different targets may support a different maximum width for the _BitInt
   // type, depending on what operations are supported.
   virtual size_t getMaxBitIntWidth() const {
diff --git a/clang/lib/Basic/Targets/AArch64.cpp 
b/clang/lib/Basic/Targets/AArch64.cpp
index 5db1ce78c657f..a5d66cb44b566 100644
--- a/clang/lib/Basic/Targets/AArch64.cpp
+++ b/clang/lib/Basic/Targets/AArch64.cpp
@@ -221,6 +221,16 @@ bool AArch64TargetInfo::validateTarget(DiagnosticsEngine 
&Diags) const {
   return true;
 }
 
+unsigned AArch64TargetInfo::getBitIntLegalWidth(unsigned Width) const {
+  unsigned IntegralSizes[] = {32, 64, 128};
+  const unsigned ARR_SZ = sizeof(IntegralSizes) / sizeof(unsigned);
+  for (unsigned I = 0; I < ARR_SZ; I ++) {
+if (IntegralSizes[I] > Width)
+  return IntegralSizes[I];
+  }
+  return Width;
+}
+
 bool AArch64TargetInfo::validateBranchProtection(StringRef Spec, StringRef,
  BranchProtectionInfo &BPI,
  StringRef &Err) const {
diff --git a/clang/lib/Basic/Targets/AArch64.h 
b/clang/lib/Basic/Targets/AArch64.h
index 12fb50286f751..89c6af00e628c 100644
--- a/clang/lib/Basic/Targets/AArch64.h
+++ b/clang/lib/Basic/Targets/AArch64.h
@@ -202,6 +202,8 @@ class LLVM_LIBRARY_VISIBILITY AArch64TargetInfo : public 
TargetInfo {
   bool hasBitIntType() const override { return true; }
 
   bool validateTarget(DiagnosticsEngine &Diags) cons

[clang] [clang-format] Fix a bug in formatting goto labels in macros (PR #92494)

2024-05-27 Thread via cfe-commits

llvmbot wrote:

/pull-request llvm/llvm-project#93494

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


[clang] [clang-format] Fix a bug in formatting goto labels in macros (PR #92494)

2024-05-27 Thread Owen Pan via cfe-commits

owenca wrote:

/cherry-pick d89f20058b45e3836527e816af7ed7372e1d554d

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


[clang] [clang-format] Fix a bug in formatting goto labels in macros (PR #92494)

2024-05-27 Thread Owen Pan via cfe-commits

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


[clang] [compiler-rt] [llvm] [openmp] [PGO][Offload] Profile profraw generation for GPU instrumentation #76587 (PR #93365)

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

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

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

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

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

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

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

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

[clang] [llvm] [llvm] Add triples for managarm (PR #87845)

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

MaskRay wrote:

#78065 for Hurd is a good example for clang testing.

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


[clang] [clang] Be const-correct with all uses of `Module *`. (PR #93493)

2024-05-27 Thread David Stone via cfe-commits

davidstone wrote:

Yes. Is there anything else you want to see in this PR before it can be merged? 
(I don't have merge permissions). This is the type of PR likely to get lots of 
conflicts if it stays open for long, so I'd like to get it wrapped up as fast 
as possible.

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


[clang] 435ea21 - [Driver] Remove unneeded *-linux-gnu after D158183

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

Author: Fangrui Song
Date: 2024-05-27T16:16:30-07:00
New Revision: 435ea21c897f94b5a3777a9f152e4c5bb4a371a3

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

LOG: [Driver] Remove unneeded *-linux-gnu after D158183

As the comment added by a07727199db0525e9d2df41e466a2a1611b3c8e1
suggests, these `*Triples` lists should shrink over time.

https://reviews.llvm.org/D158183 allows *-unknown-linux-gnu to detect
*-linux-gnu. If we additionally allow x86_64-unknown-linux-gnu
-m32/-mx32 to detect x86_64-linux-gnu, we can mostly remove these
*-linux-gnu elements.

Added: 


Modified: 
clang/lib/Driver/ToolChains/Gnu.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Gnu.cpp 
b/clang/lib/Driver/ToolChains/Gnu.cpp
index 9849c59685cca..c0100fed15131 100644
--- a/clang/lib/Driver/ToolChains/Gnu.cpp
+++ b/clang/lib/Driver/ToolChains/Gnu.cpp
@@ -2227,10 +2227,19 @@ void Generic_GCC::GCCInstallationDetector::init(
   SmallVector CandidateBiarchTripleAliases;
   // Add some triples that we want to check first.
   CandidateTripleAliases.push_back(TargetTriple.str());
-  std::string TripleNoVendor = TargetTriple.getArchName().str() + "-" +
-   TargetTriple.getOSAndEnvironmentName().str();
-  if (TargetTriple.getVendor() == llvm::Triple::UnknownVendor)
+  std::string TripleNoVendor, BiarchTripleNoVendor;
+  if (TargetTriple.getVendor() == llvm::Triple::UnknownVendor) {
+StringRef OSEnv = TargetTriple.getOSAndEnvironmentName();
+if (TargetTriple.getEnvironment() == llvm::Triple::GNUX32)
+  OSEnv = "linux-gnu";
+TripleNoVendor = (TargetTriple.getArchName().str() + '-' + OSEnv).str();
 CandidateTripleAliases.push_back(TripleNoVendor);
+if (BiarchVariantTriple.getArch() != llvm::Triple::UnknownArch) {
+  BiarchTripleNoVendor =
+  (BiarchVariantTriple.getArchName().str() + '-' + OSEnv).str();
+  CandidateBiarchTripleAliases.push_back(BiarchTripleNoVendor);
+}
+  }
 
   CollectLibDirsAndTriples(TargetTriple, BiarchVariantTriple, CandidateLibDirs,
CandidateTripleAliases, CandidateBiarchLibDirs,
@@ -2453,11 +2462,9 @@ void 
Generic_GCC::GCCInstallationDetector::AddDefaultGCCPrefixes(
   // lists should shrink over time. Please don't add more elements to *Triples.
   static const char *const AArch64LibDirs[] = {"/lib64", "/lib"};
   static const char *const AArch64Triples[] = {
-  "aarch64-none-linux-gnu", "aarch64-linux-gnu", "aarch64-redhat-linux",
-  "aarch64-suse-linux"};
+  "aarch64-none-linux-gnu", "aarch64-redhat-linux", "aarch64-suse-linux"};
   static const char *const AArch64beLibDirs[] = {"/lib"};
-  static const char *const AArch64beTriples[] = {"aarch64_be-none-linux-gnu",
- "aarch64_be-linux-gnu"};
+  static const char *const AArch64beTriples[] = {"aarch64_be-none-linux-gnu"};
 
   static const char *const ARMLibDirs[] = {"/lib"};
   static const char *const ARMTriples[] = {"arm-linux-gnueabi"};
@@ -2479,20 +2486,19 @@ void 
Generic_GCC::GCCInstallationDetector::AddDefaultGCCPrefixes(
 
   static const char *const X86_64LibDirs[] = {"/lib64", "/lib"};
   static const char *const X86_64Triples[] = {
-  "x86_64-linux-gnu",   "x86_64-unknown-linux-gnu",
-  "x86_64-pc-linux-gnu","x86_64-redhat-linux6E",
-  "x86_64-redhat-linux","x86_64-suse-linux",
-  "x86_64-manbo-linux-gnu", "x86_64-linux-gnu",
-  "x86_64-slackware-linux", "x86_64-unknown-linux",
+  "x86_64-unknown-linux-gnu", "x86_64-pc-linux-gnu",
+  "x86_64-redhat-linux6E","x86_64-redhat-linux",
+  "x86_64-suse-linux","x86_64-manbo-linux-gnu",
+  "x86_64-slackware-linux",   "x86_64-unknown-linux",
   "x86_64-amazon-linux"};
   static const char *const X32Triples[] = {"x86_64-linux-gnux32",
"x86_64-pc-linux-gnux32"};
   static const char *const X32LibDirs[] = {"/libx32", "/lib"};
   static const char *const X86LibDirs[] = {"/lib32", "/lib"};
   static const char *const X86Triples[] = {
-  "i586-linux-gnu",  "i686-linux-gnu","i686-pc-linux-gnu",
-  "i386-redhat-linux6E", "i686-redhat-linux", "i386-redhat-linux",
-  "i586-suse-linux", "i686-montavista-linux",
+  "i686-linux-gnu","i686-pc-linux-gnu", "i386-redhat-linux6E",
+  "i686-redhat-linux", "i386-redhat-linux", "i586-suse-linux",
+  "i686-montavista-linux",
   };
 
   static const char *const LoongArch64LibDirs[] = {"/lib64", "/lib"};
@@ -2500,26 +2506,24 @@ void 
Generic_GCC::GCCInstallationDetector::AddDefaultGCCPrefixes(
   "loongarch64-linux-gnu", "loongarch64-unknown-linux-gnu"};
 
   static const char *const M68kLibDirs[] = {"/lib"};
-  static const cha

[clang] [llvm] [clang][ci] Move libc++ testing into the main PR pipeline (PR #93318)

2024-05-27 Thread Vlad Serebrennikov via cfe-commits


@@ -1,82 +0,0 @@
-#===--===##

Endilll wrote:

I decided to keep it intact out of caution, and asked on Discord instead 
whether this file is still needed.

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


[clang] [llvm] [clang][ci] Move libc++ testing into the main PR pipeline (PR #93318)

2024-05-27 Thread Vlad Serebrennikov via cfe-commits

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


[clang] 1de1ee9 - [clang][ci] Move libc++ testing into the main PR pipeline (#93318)

2024-05-27 Thread via cfe-commits

Author: Vlad Serebrennikov
Date: 2024-05-28T02:25:15+04:00
New Revision: 1de1ee9cbabd641d50c5d2ac416392494b4ed30b

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

LOG: [clang][ci] Move libc++ testing into the main PR pipeline (#93318)

Following the discussion in
https://github.com/llvm/llvm-project/pull/93233#issuecomment-2127920882,
this patch merges `clang-ci` pipeline into main `GitHub Pull Requests`
pipeline. `clang-ci` enables additional test coverage for Clang by
compiling it, and then using it to compile and test libc++, libc++abi,
and libunwind in C++03, C++26, and Clang Modules modes.

Additional work we skip and total time savings we should see:
1. Checking out the repo to generate the clang-ci pipeline (2 minutes)
2. Building Clang (3.5 minutes)
3. Uploading the artifacts once, then downloading them 3 times and
unpacking 3 times (0.5 minutes)

Note that because previously-split jobs for each mode are now under a
single Linux job, it now takes around 8 minutes more see the Linux CI
results despite total time savings.

The primary goal of this patch is to reduce the load of CI by removing
duplicated work. I consider this goal achieved. I could keep the job
parallelism we had (3 libc++ jobs depending on a main Linux job), but I
don't consider it worth the effort and opportunity cost, because
parallelism is not helping once the pool of builders is fully
subscribed.

Added: 


Modified: 
.ci/generate-buildkite-pipeline-premerge
.ci/monolithic-linux.sh

Removed: 
clang/utils/ci/buildkite-pipeline.yml



diff  --git a/.ci/generate-buildkite-pipeline-premerge 
b/.ci/generate-buildkite-pipeline-premerge
index e1c66ac18e7ac..3ed5eb96eceb5 100755
--- a/.ci/generate-buildkite-pipeline-premerge
+++ b/.ci/generate-buildkite-pipeline-premerge
@@ -85,6 +85,22 @@ function compute-projects-to-test() {
   done
 }
 
+function compute-runtimes-to-test() {
+  projects=${@}
+  for project in ${projects}; do
+case ${project} in
+clang)
+  for p in libcxx libcxxabi libunwind; do
+echo $p
+  done
+;;
+*)
+  # Nothing to do
+;;
+esac
+  done
+}
+
 function add-dependencies() {
   projects=${@}
   for project in ${projects}; do
@@ -178,6 +194,15 @@ function check-targets() {
 cross-project-tests)
   echo "check-cross-project"
 ;;
+libcxx)
+  echo "check-cxx"
+;;
+libcxxabi)
+  echo "check-cxxabi"
+;;
+libunwind)
+  echo "check-unwind"
+;;
 lldb)
   echo "check-all" # TODO: check-lldb may not include all the LLDB tests?
 ;;
@@ -207,17 +232,6 @@ if echo "$modified_dirs" | grep -q -E 
"^(libcxx|libcxxabi|libunwind|runtimes|cma
 EOF
 fi
 
-# If clang changed.
-if echo "$modified_dirs" | grep -q -E "^(clang)$"; then
-  cat 

[clang] [clang] Be const-correct with all uses of `Module *`. (PR #93493)

2024-05-27 Thread Vlad Serebrennikov via cfe-commits

Endilll wrote:

Sounds like you have a plan after this PR, which is good. I was worried that 
you're just applying `const` where it doesn't cause issues _today_. Such 
approach to const-correctness has been failing us (it leads to `const_cast`s 
down the usage chain).

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


[clang] dba2aa2 - [clang-format] Add LeftWithLastLine to AlignEscapedNewlines option (#93402)

2024-05-27 Thread via cfe-commits

Author: Owen Pan
Date: 2024-05-27T15:20:58-07:00
New Revision: dba2aa265c5f2ef774c2812cf6ffdea8dd784e09

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

LOG: [clang-format] Add LeftWithLastLine to AlignEscapedNewlines option (#93402)

Closes #92999.

Added: 


Modified: 
clang/docs/ClangFormatStyleOptions.rst
clang/docs/ReleaseNotes.rst
clang/include/clang/Format/Format.h
clang/lib/Format/Format.cpp
clang/lib/Format/WhitespaceManager.cpp
clang/unittests/Format/ConfigParseTest.cpp
clang/unittests/Format/FormatTest.cpp

Removed: 




diff  --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 6d092219877f9..1a7d0e6a05e31 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -1421,13 +1421,21 @@ the configuration (without a prefix: ``Auto``).
 
 .. code-block:: c++
 
-  true:
   #define A   \
 int ; \
 int b;\
 int dd;
 
-  false:
+  * ``ENAS_LeftWithLastLine`` (in configuration: ``LeftWithLastLine``)
+Align escaped newlines as far left as possible, using the last line of
+the preprocessor directive as the reference if it's the longest.
+
+.. code-block:: c++
+
+  #define A \
+int ;   \
+int b;  \
+int dd;
 
   * ``ENAS_Right`` (in configuration: ``Right``)
 Align escaped newlines in the right-most column.

diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 37a664b14fab1..182f8b5824258 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -964,9 +964,10 @@ clang-format
   ``BreakTemplateDeclarations``.
 - ``AlwaysBreakAfterReturnType`` is deprecated and renamed to
   ``BreakAfterReturnType``.
-- Handles Java ``switch`` expressions.
+- Handles Java switch expressions.
 - Adds ``AllowShortCaseExpressionOnASingleLine`` option.
 - Adds ``AlignCaseArrows`` suboption to 
``AlignConsecutiveShortCaseStatements``.
+- Adds ``LeftWithLastLine`` suboption to ``AlignEscapedNewlines``.
 
 libclang
 

diff  --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 274b45d1bc586..eb6647038403d 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -480,15 +480,21 @@ struct FormatStyle {
 ENAS_DontAlign,
 /// Align escaped newlines as far left as possible.
 /// \code
-///   true:
 ///   #define A   \
 /// int ; \
 /// int b;\
 /// int dd;
-///
-///   false:
 /// \endcode
 ENAS_Left,
+/// Align escaped newlines as far left as possible, using the last line of
+/// the preprocessor directive as the reference if it's the longest.
+/// \code
+///   #define A \
+/// int ;   \
+/// int b;  \
+/// int dd;
+/// \endcode
+ENAS_LeftWithLastLine,
 /// Align escaped newlines in the right-most column.
 /// \code
 ///   #define A
  \

diff  --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 9cba0c2614eef..c015e03fa15e7 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -308,6 +308,7 @@ struct 
ScalarEnumerationTraits {
   FormatStyle::EscapedNewlineAlignmentStyle &Value) {
 IO.enumCase(Value, "DontAlign", FormatStyle::ENAS_DontAlign);
 IO.enumCase(Value, "Left", FormatStyle::ENAS_Left);
+IO.enumCase(Value, "LeftWithLastLine", FormatStyle::ENAS_LeftWithLastLine);
 IO.enumCase(Value, "Right", FormatStyle::ENAS_Right);
 
 // For backward compatibility.

diff  --git a/clang/lib/Format/WhitespaceManager.cpp 
b/clang/lib/Format/WhitespaceManager.cpp
index ed06d6098a9f2..50531aee9d597 100644
--- a/clang/lib/Format/WhitespaceManager.cpp
+++ b/clang/lib/Format/WhitespaceManager.cpp
@@ -1245,22 +1245,29 @@ void WhitespaceManager::alignTrailingComments(unsigned 
Start, unsigned End,
 }
 
 void WhitespaceManager::alignEscapedNewlines() {
-  if (Style.AlignEscapedNewlines == FormatStyle::ENAS_DontAlign)
+  const auto Align = Style.AlignEscapedNewlines;
+  if (Align == FormatStyle::ENAS_DontAlign)
 return;
 
-  bool AlignLeft = Style.AlignEscapedNewlines == FormatStyle::ENAS_Left;
-  unsigned MaxEndOfLine = AlignLeft ? 0 : Style.ColumnLimit;
+  const bool WithLastLine = Align == FormatStyle::ENAS_LeftWithLastLine;
+  const bool AlignLeft = Align == FormatStyle::ENAS_Left || WithLastLine;
+  const auto MaxColumn = Style.ColumnLimit;
+  unsigned MaxEndOfLine = AlignLeft ? 0 : MaxColumn;
   unsigned StartOfMacro = 0;
   for (unsigned i =

[clang] [clang-format] Add LeftWithLastLine to AlignEscapedNewlines option (PR #93402)

2024-05-27 Thread Owen Pan via cfe-commits

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


[clang] Code implementing SpacesInParensOptions.ExceptDoubleParentheses logic (PR #93439)

2024-05-27 Thread Owen Pan via cfe-commits

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


[clang] Code implementing SpacesInParensOptions.ExceptDoubleParentheses logic (PR #93439)

2024-05-27 Thread Owen Pan via cfe-commits

https://github.com/owenca updated 
https://github.com/llvm/llvm-project/pull/93439

>From ac03e1506b5ea0d00038501c4f41d5b30c8fa2b3 Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Sun, 26 May 2024 22:01:48 -0700
Subject: [PATCH 1/2] Code implementing the
 SpacesInParensOptions.ExceptDoubleParentheses logic

---
 clang/lib/Format/TokenAnnotator.cpp | 8 
 1 file changed, 8 insertions(+)

diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 7c4c76a91f2c5..c204d107b12b7 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -4346,6 +4346,14 @@ bool TokenAnnotator::spaceRequiredBetween(const 
AnnotatedLine &Line,
Right.is(tok::r_brace) && Right.isNot(BK_Block))) {
 return Style.SpacesInParensOptions.InEmptyParentheses;
   }
+  if (Style.SpacesInParens == FormatStyle::SIPO_Custom &&
+  Style.SpacesInParensOptions.ExceptDoubleParentheses &&
+  ((Left.is(tok::l_paren) && Right.is(tok::l_paren)) ||
+   (Left.is(tok::r_paren) && Right.is(tok::r_paren {
+const auto *Tok = Left.MatchingParen;
+if (Tok && Tok->Previous == Right.MatchingParen)
+  return false;
+  }
   if (Style.SpacesInParensOptions.InConditionalStatements) {
 const FormatToken *LeftParen = nullptr;
 if (Left.is(tok::l_paren))

>From 1e086440c350644ec50a72d1ad3a15d877024ec3 Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Mon, 27 May 2024 15:14:38 -0700
Subject: [PATCH 2/2] Improve the logic.

---
 clang/lib/Format/TokenAnnotator.cpp | 9 +
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index c204d107b12b7..a26900383b256 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -4348,11 +4348,12 @@ bool TokenAnnotator::spaceRequiredBetween(const 
AnnotatedLine &Line,
   }
   if (Style.SpacesInParens == FormatStyle::SIPO_Custom &&
   Style.SpacesInParensOptions.ExceptDoubleParentheses &&
-  ((Left.is(tok::l_paren) && Right.is(tok::l_paren)) ||
-   (Left.is(tok::r_paren) && Right.is(tok::r_paren {
-const auto *Tok = Left.MatchingParen;
-if (Tok && Tok->Previous == Right.MatchingParen)
+  Left.is(tok::r_paren) && Right.is(tok::r_paren)) {
+auto *InnerLParen = Left.MatchingParen;
+if (InnerLParen && InnerLParen->Previous == Right.MatchingParen) {
+  InnerLParen->SpacesRequiredBefore = 0;
   return false;
+}
   }
   if (Style.SpacesInParensOptions.InConditionalStatements) {
 const FormatToken *LeftParen = nullptr;

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


[clang] [clang] Be const-correct with all uses of `Module *`. (PR #93493)

2024-05-27 Thread David Stone via cfe-commits

davidstone wrote:

> Can you make sure that at every place this PR touches `const` makes sense? I 
> found out recently that we can be quite good at pretending that something is 
> `const`, all the way down until we realize we need a `const_cast`, because 
> modification is required in that one place.

To add a little more flavor to my response, this PR is a precursor to a larger 
refactoring of `Module` itself. I plan on making some changes to it that 
require even less mutation for use (in other words, there are places in the 
code that I could not mark `const` in this PR but in the future we will be able 
to). I wanted to get all the trivial `const` stuff correct now so that my 
future changes will be smaller.

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


[clang] [clang] Be const-correct with all uses of `Module *`. (PR #93493)

2024-05-27 Thread David Stone via cfe-commits

davidstone wrote:

> Can you make sure that at every place this PR touches `const` makes sense? I 
> found out recently that we can be quite good at pretending that something is 
> `const`, all the way down until we realize we need a `const_cast`, because 
> modification is required in that one place.

I'm not quite sure I understand the question. This PR doesn't add any 
`const_cast`, and `const` is checked by the compiler so a successful build 
shows that we're never modifying something declared `const`. What additional 
work are you wanting?

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


[clang] [llvm] [llvm] Add triples for managarm (PR #87845)

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

MaskRay wrote:

> [llvm] Add triples for managarm

I suggest that you split the patch into LLVM target triple part and a clang 
part. That's a convention to support new targets.

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


[clang] [clang] Be const-correct with all uses of `Module *`. (PR #93493)

2024-05-27 Thread Vlad Serebrennikov via cfe-commits

Endilll wrote:

Can you make sure that at every place this PR touches `const` makes sense? I 
found out recently that we can be quite good at pretending that something is 
`const`, all the way down until we realize we need a `const_cast`, because 
modification is required in that one place.

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


[clang] [llvm] [llvm] Add triples for managarm (PR #87845)

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

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


[clang] [llvm] [llvm] Add triples for managarm (PR #87845)

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


@@ -279,8 +280,10 @@ class Triple {
 Amplification,
 OpenCL,
 OpenHOS,
+Kernel,
+Mlibc,

MaskRay wrote:

I don't know how Mlibc is intended to be used but LLVM LTO warns about 
differing target triples.

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


[clang] [llvm] [llvm] Add triples for managarm (PR #87845)

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


@@ -279,8 +280,10 @@ class Triple {
 Amplification,
 OpenCL,
 OpenHOS,
+Kernel,

MaskRay wrote:

Why is a generic term `Kernel` added? I am concerned that it would cause 
confusion to users of other OSes.

Does your OS need a different target triple for kernel development? Note that 
almost all other OSes don't make the target triple distinction.

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


[clang] Code implementing SpacesInParensOptions.ExceptDoubleParentheses logic (PR #93439)

2024-05-27 Thread Owen Pan via cfe-commits

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


[clang] Code implementing SpacesInParensOptions.ExceptDoubleParentheses logic (PR #93439)

2024-05-27 Thread Owen Pan via cfe-commits

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


[clang] [llvm] [llvm] Add triples for managarm (PR #87845)

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

MaskRay wrote:

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

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


[clang] [llvm] [llvm] Add triples for managarm (PR #87845)

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


@@ -2562,7 +2566,10 @@ void 
Generic_GCC::GCCInstallationDetector::AddDefaultGCCPrefixes(
   static const char *const RISCV64LibDirs[] = {"/lib64", "/lib"};
   static const char *const RISCV64Triples[] = {"riscv64-unknown-linux-gnu",
"riscv64-linux-gnu",
-   "riscv64-unknown-elf"};
+   "riscv64-unknown-elf",

MaskRay wrote:

L2449 has a comment that we should not add new elements.

The existing ones should be cleaned up as well.

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


[clang] [SystemZ][z/OS] Implement z/OS XPLINK ABI (PR #91384)

2024-05-27 Thread Kai Nacke via cfe-commits


@@ -529,9 +530,379 @@ bool SystemZTargetCodeGenInfo::isVectorTypeBased(const 
Type *Ty,
   return false;
 }
 
+//===--===//
+// z/OS XPLINK ABI Implementation
+//===--===//
+
+namespace {
+
+class ZOSXPLinkABIInfo : public ABIInfo {
+  const unsigned GPRBits = 64;
+  bool HasVector;
+
+public:
+  ZOSXPLinkABIInfo(CodeGenTypes &CGT, bool HV) : ABIInfo(CGT), HasVector(HV) {}
+
+  bool isPromotableIntegerType(QualType Ty) const;
+  bool isCompoundType(QualType Ty) const;
+  bool isVectorArgumentType(QualType Ty) const;
+  bool isFPArgumentType(QualType Ty) const;
+  QualType getSingleElementType(QualType Ty) const;
+  unsigned getMaxAlignFromTypeDefs(QualType Ty) const;
+  std::optional getFPTypeOfComplexLikeType(QualType Ty) const;
+
+  ABIArgInfo classifyReturnType(QualType RetTy) const;
+  ABIArgInfo classifyArgumentType(QualType ArgTy, bool IsNamedArg) const;
+
+  void computeInfo(CGFunctionInfo &FI) const override {
+if (!getCXXABI().classifyReturnType(FI))
+  FI.getReturnInfo() = classifyReturnType(FI.getReturnType());
+
+unsigned NumRequiredArgs = FI.getNumRequiredArgs();
+unsigned ArgNo = 0;
+
+for (auto &I : FI.arguments()) {
+  bool IsNamedArg = ArgNo < NumRequiredArgs;
+  I.info = classifyArgumentType(I.type, IsNamedArg);
+  ++ArgNo;
+}
+  }
+
+  Address EmitVAArg(CodeGenFunction &CGF, Address VAListAddr,
+QualType Ty) const override;
+};
+
+class ZOSXPLinkTargetCodeGenInfo : public TargetCodeGenInfo {
+public:
+  ZOSXPLinkTargetCodeGenInfo(CodeGenTypes &CGT, bool HasVector)
+  : TargetCodeGenInfo(std::make_unique(CGT, HasVector)) {
+SwiftInfo =
+std::make_unique(CGT, /*SwiftErrorInRegister=*/false);
+  }
+};
+
+} // namespace
+
+// Return true if the ABI requires Ty to be passed sign- or zero-
+// extended to 64 bits.
+bool ZOSXPLinkABIInfo::isPromotableIntegerType(QualType Ty) const {
+  // Treat an enum type as its underlying type.
+  if (const EnumType *EnumTy = Ty->getAs())
+Ty = EnumTy->getDecl()->getIntegerType();
+
+  // Promotable integer types are required to be promoted by the ABI.
+  if (getContext().isPromotableIntegerType(Ty))
+return true;
+
+  if (const auto *EIT = Ty->getAs())
+if (EIT->getNumBits() < 64)
+  return true;
+
+  // In addition to the usual promotable integer types, we also need to
+  // extend all 32-bit types, since the ABI requires promotion to 64 bits.
+  if (const BuiltinType *BT = Ty->getAs())
+switch (BT->getKind()) {
+case BuiltinType::Int:
+case BuiltinType::UInt:
+  return true;
+default:
+  break;
+}
+
+  return false;
+}
+
+bool ZOSXPLinkABIInfo::isCompoundType(QualType Ty) const {
+  return (Ty->isAnyComplexType() || Ty->isVectorType() ||
+  isAggregateTypeForABI(Ty));
+}
+
+bool ZOSXPLinkABIInfo::isVectorArgumentType(QualType Ty) const {
+  return (HasVector && Ty->isVectorType() &&
+  getContext().getTypeSize(Ty) <= 128);
+}
+
+bool ZOSXPLinkABIInfo::isFPArgumentType(QualType Ty) const {
+  if (const BuiltinType *BT = Ty->getAs())
+switch (BT->getKind()) {
+case BuiltinType::Float:
+case BuiltinType::Double:
+case BuiltinType::LongDouble:
+  return true;
+default:
+  return false;
+}
+
+  return false;
+}
+
+QualType ZOSXPLinkABIInfo::getSingleElementType(QualType Ty) const {
+  const RecordType *RT = Ty->getAs();
+
+  if (RT && RT->isStructureOrClassType()) {
+const RecordDecl *RD = RT->getDecl();
+QualType Found;
+
+// If this is a C++ record, check the bases first.
+if (const CXXRecordDecl *CXXRD = dyn_cast(RD))
+  if (CXXRD->hasDefinition())
+for (const auto &I : CXXRD->bases()) {
+  QualType Base = I.getType();
+
+  // Empty bases don't affect things either way.
+  if (isEmptyRecord(getContext(), Base, true))
+continue;
+
+  if (!Found.isNull())
+return Ty;
+  Found = getSingleElementType(Base);
+}
+
+// Check the fields.
+for (const auto *FD : RD->fields()) {
+  QualType FT = FD->getType();
+
+  // Ignore empty fields.
+  if (isEmptyField(getContext(), FD, true))
+continue;
+
+  if (!Found.isNull())
+return Ty;
+
+  // Treat single element arrays as the element.
+  while (const ConstantArrayType *AT =
+ getContext().getAsConstantArrayType(FT)) {
+if (AT->getZExtSize() != 1)
+  break;
+FT = AT->getElementType();
+  }
+
+  Found = getSingleElementType(FT);
+}
+
+// Unlike isSingleElementStruct(), trailing padding is allowed.
+if (!Found.isNull())
+  return Found;
+  }
+
+  return Ty;
+}
+
+unsigned ZOSXPLinkABIInfo::getMaxAlignFromTypeDefs(QualType Ty) const {
+  unsigned MaxAlign = 0;
+  while (Ty != Ty.getSingleStepDesugaredType

[clang] [SystemZ][z/OS] Implement z/OS XPLINK ABI (PR #91384)

2024-05-27 Thread Kai Nacke via cfe-commits


@@ -529,9 +530,379 @@ bool SystemZTargetCodeGenInfo::isVectorTypeBased(const 
Type *Ty,
   return false;
 }
 
+//===--===//
+// z/OS XPLINK ABI Implementation
+//===--===//
+
+namespace {
+
+class ZOSXPLinkABIInfo : public ABIInfo {
+  const unsigned GPRBits = 64;
+  bool HasVector;
+
+public:
+  ZOSXPLinkABIInfo(CodeGenTypes &CGT, bool HV) : ABIInfo(CGT), HasVector(HV) {}
+
+  bool isPromotableIntegerType(QualType Ty) const;
+  bool isCompoundType(QualType Ty) const;
+  bool isVectorArgumentType(QualType Ty) const;
+  bool isFPArgumentType(QualType Ty) const;
+  QualType getSingleElementType(QualType Ty) const;
+  unsigned getMaxAlignFromTypeDefs(QualType Ty) const;
+  std::optional getFPTypeOfComplexLikeType(QualType Ty) const;
+
+  ABIArgInfo classifyReturnType(QualType RetTy) const;
+  ABIArgInfo classifyArgumentType(QualType ArgTy, bool IsNamedArg) const;
+
+  void computeInfo(CGFunctionInfo &FI) const override {
+if (!getCXXABI().classifyReturnType(FI))
+  FI.getReturnInfo() = classifyReturnType(FI.getReturnType());
+
+unsigned NumRequiredArgs = FI.getNumRequiredArgs();
+unsigned ArgNo = 0;
+
+for (auto &I : FI.arguments()) {
+  bool IsNamedArg = ArgNo < NumRequiredArgs;
+  I.info = classifyArgumentType(I.type, IsNamedArg);
+  ++ArgNo;
+}
+  }
+
+  Address EmitVAArg(CodeGenFunction &CGF, Address VAListAddr,
+QualType Ty) const override;
+};
+
+class ZOSXPLinkTargetCodeGenInfo : public TargetCodeGenInfo {
+public:
+  ZOSXPLinkTargetCodeGenInfo(CodeGenTypes &CGT, bool HasVector)
+  : TargetCodeGenInfo(std::make_unique(CGT, HasVector)) {
+SwiftInfo =
+std::make_unique(CGT, /*SwiftErrorInRegister=*/false);
+  }
+};
+
+} // namespace
+
+// Return true if the ABI requires Ty to be passed sign- or zero-
+// extended to 64 bits.
+bool ZOSXPLinkABIInfo::isPromotableIntegerType(QualType Ty) const {
+  // Treat an enum type as its underlying type.
+  if (const EnumType *EnumTy = Ty->getAs())
+Ty = EnumTy->getDecl()->getIntegerType();
+
+  // Promotable integer types are required to be promoted by the ABI.
+  if (getContext().isPromotableIntegerType(Ty))
+return true;
+
+  if (const auto *EIT = Ty->getAs())
+if (EIT->getNumBits() < 64)
+  return true;
+
+  // In addition to the usual promotable integer types, we also need to
+  // extend all 32-bit types, since the ABI requires promotion to 64 bits.
+  if (const BuiltinType *BT = Ty->getAs())
+switch (BT->getKind()) {
+case BuiltinType::Int:
+case BuiltinType::UInt:
+  return true;
+default:
+  break;
+}
+
+  return false;
+}
+
+bool ZOSXPLinkABIInfo::isCompoundType(QualType Ty) const {
+  return (Ty->isAnyComplexType() || Ty->isVectorType() ||
+  isAggregateTypeForABI(Ty));
+}
+
+bool ZOSXPLinkABIInfo::isVectorArgumentType(QualType Ty) const {
+  return (HasVector && Ty->isVectorType() &&
+  getContext().getTypeSize(Ty) <= 128);
+}
+
+bool ZOSXPLinkABIInfo::isFPArgumentType(QualType Ty) const {
+  if (const BuiltinType *BT = Ty->getAs())
+switch (BT->getKind()) {
+case BuiltinType::Float:
+case BuiltinType::Double:
+case BuiltinType::LongDouble:
+  return true;
+default:
+  return false;
+}
+
+  return false;
+}
+
+QualType ZOSXPLinkABIInfo::getSingleElementType(QualType Ty) const {
+  const RecordType *RT = Ty->getAs();
+
+  if (RT && RT->isStructureOrClassType()) {
+const RecordDecl *RD = RT->getDecl();
+QualType Found;
+
+// If this is a C++ record, check the bases first.
+if (const CXXRecordDecl *CXXRD = dyn_cast(RD))
+  if (CXXRD->hasDefinition())
+for (const auto &I : CXXRD->bases()) {
+  QualType Base = I.getType();
+
+  // Empty bases don't affect things either way.
+  if (isEmptyRecord(getContext(), Base, true))
+continue;
+
+  if (!Found.isNull())
+return Ty;
+  Found = getSingleElementType(Base);
+}
+
+// Check the fields.
+for (const auto *FD : RD->fields()) {
+  QualType FT = FD->getType();
+
+  // Ignore empty fields.
+  if (isEmptyField(getContext(), FD, true))
+continue;
+
+  if (!Found.isNull())
+return Ty;
+
+  // Treat single element arrays as the element.
+  while (const ConstantArrayType *AT =
+ getContext().getAsConstantArrayType(FT)) {
+if (AT->getZExtSize() != 1)
+  break;
+FT = AT->getElementType();
+  }
+
+  Found = getSingleElementType(FT);
+}
+
+// Unlike isSingleElementStruct(), trailing padding is allowed.
+if (!Found.isNull())
+  return Found;
+  }
+
+  return Ty;
+}
+
+unsigned ZOSXPLinkABIInfo::getMaxAlignFromTypeDefs(QualType Ty) const {
+  unsigned MaxAlign = 0;
+  while (Ty != Ty.getSingleStepDesugaredType

[clang] [SystemZ][z/OS] Implement z/OS XPLINK ABI (PR #91384)

2024-05-27 Thread Kai Nacke via cfe-commits


@@ -529,9 +530,379 @@ bool SystemZTargetCodeGenInfo::isVectorTypeBased(const 
Type *Ty,
   return false;
 }
 
+//===--===//
+// z/OS XPLINK ABI Implementation
+//===--===//
+
+namespace {
+
+class ZOSXPLinkABIInfo : public ABIInfo {
+  const unsigned GPRBits = 64;
+  bool HasVector;
+
+public:
+  ZOSXPLinkABIInfo(CodeGenTypes &CGT, bool HV) : ABIInfo(CGT), HasVector(HV) {}
+
+  bool isPromotableIntegerType(QualType Ty) const;
+  bool isCompoundType(QualType Ty) const;
+  bool isVectorArgumentType(QualType Ty) const;
+  bool isFPArgumentType(QualType Ty) const;
+  QualType getSingleElementType(QualType Ty) const;
+  unsigned getMaxAlignFromTypeDefs(QualType Ty) const;
+  std::optional getFPTypeOfComplexLikeType(QualType Ty) const;
+
+  ABIArgInfo classifyReturnType(QualType RetTy) const;
+  ABIArgInfo classifyArgumentType(QualType ArgTy, bool IsNamedArg) const;
+
+  void computeInfo(CGFunctionInfo &FI) const override {
+if (!getCXXABI().classifyReturnType(FI))
+  FI.getReturnInfo() = classifyReturnType(FI.getReturnType());
+
+unsigned NumRequiredArgs = FI.getNumRequiredArgs();
+unsigned ArgNo = 0;
+
+for (auto &I : FI.arguments()) {
+  bool IsNamedArg = ArgNo < NumRequiredArgs;
+  I.info = classifyArgumentType(I.type, IsNamedArg);
+  ++ArgNo;
+}
+  }
+
+  Address EmitVAArg(CodeGenFunction &CGF, Address VAListAddr,
+QualType Ty) const override;
+};
+
+class ZOSXPLinkTargetCodeGenInfo : public TargetCodeGenInfo {
+public:
+  ZOSXPLinkTargetCodeGenInfo(CodeGenTypes &CGT, bool HasVector)
+  : TargetCodeGenInfo(std::make_unique(CGT, HasVector)) {
+SwiftInfo =
+std::make_unique(CGT, /*SwiftErrorInRegister=*/false);
+  }
+};
+
+} // namespace
+
+// Return true if the ABI requires Ty to be passed sign- or zero-
+// extended to 64 bits.
+bool ZOSXPLinkABIInfo::isPromotableIntegerType(QualType Ty) const {
+  // Treat an enum type as its underlying type.
+  if (const EnumType *EnumTy = Ty->getAs())
+Ty = EnumTy->getDecl()->getIntegerType();
+
+  // Promotable integer types are required to be promoted by the ABI.
+  if (getContext().isPromotableIntegerType(Ty))
+return true;
+
+  if (const auto *EIT = Ty->getAs())
+if (EIT->getNumBits() < 64)
+  return true;
+
+  // In addition to the usual promotable integer types, we also need to
+  // extend all 32-bit types, since the ABI requires promotion to 64 bits.
+  if (const BuiltinType *BT = Ty->getAs())
+switch (BT->getKind()) {
+case BuiltinType::Int:
+case BuiltinType::UInt:
+  return true;
+default:
+  break;
+}
+
+  return false;
+}
+
+bool ZOSXPLinkABIInfo::isCompoundType(QualType Ty) const {
+  return (Ty->isAnyComplexType() || Ty->isVectorType() ||
+  isAggregateTypeForABI(Ty));
+}
+
+bool ZOSXPLinkABIInfo::isVectorArgumentType(QualType Ty) const {
+  return (HasVector && Ty->isVectorType() &&
+  getContext().getTypeSize(Ty) <= 128);
+}
+
+bool ZOSXPLinkABIInfo::isFPArgumentType(QualType Ty) const {
+  if (const BuiltinType *BT = Ty->getAs())
+switch (BT->getKind()) {
+case BuiltinType::Float:
+case BuiltinType::Double:
+case BuiltinType::LongDouble:
+  return true;
+default:
+  return false;
+}
+
+  return false;
+}
+
+QualType ZOSXPLinkABIInfo::getSingleElementType(QualType Ty) const {
+  const RecordType *RT = Ty->getAs();
+
+  if (RT && RT->isStructureOrClassType()) {
+const RecordDecl *RD = RT->getDecl();
+QualType Found;
+
+// If this is a C++ record, check the bases first.
+if (const CXXRecordDecl *CXXRD = dyn_cast(RD))
+  if (CXXRD->hasDefinition())
+for (const auto &I : CXXRD->bases()) {
+  QualType Base = I.getType();
+
+  // Empty bases don't affect things either way.
+  if (isEmptyRecord(getContext(), Base, true))
+continue;
+
+  if (!Found.isNull())
+return Ty;
+  Found = getSingleElementType(Base);
+}
+
+// Check the fields.
+for (const auto *FD : RD->fields()) {
+  QualType FT = FD->getType();
+
+  // Ignore empty fields.
+  if (isEmptyField(getContext(), FD, true))
+continue;
+
+  if (!Found.isNull())
+return Ty;
+
+  // Treat single element arrays as the element.
+  while (const ConstantArrayType *AT =
+ getContext().getAsConstantArrayType(FT)) {
+if (AT->getZExtSize() != 1)
+  break;
+FT = AT->getElementType();
+  }
+
+  Found = getSingleElementType(FT);
+}
+
+// Unlike isSingleElementStruct(), trailing padding is allowed.
+if (!Found.isNull())
+  return Found;
+  }
+
+  return Ty;
+}
+
+unsigned ZOSXPLinkABIInfo::getMaxAlignFromTypeDefs(QualType Ty) const {
+  unsigned MaxAlign = 0;
+  while (Ty != Ty.getSingleStepDesugaredType

[clang] [SystemZ][z/OS] Implement z/OS XPLINK ABI (PR #91384)

2024-05-27 Thread Kai Nacke via cfe-commits

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


[clang] [SystemZ][z/OS] Implement z/OS XPLINK ABI (PR #91384)

2024-05-27 Thread Kai Nacke via cfe-commits


@@ -529,9 +530,379 @@ bool SystemZTargetCodeGenInfo::isVectorTypeBased(const 
Type *Ty,
   return false;
 }
 
+//===--===//
+// z/OS XPLINK ABI Implementation
+//===--===//
+
+namespace {
+
+class ZOSXPLinkABIInfo : public ABIInfo {
+  const unsigned GPRBits = 64;
+  bool HasVector;
+
+public:
+  ZOSXPLinkABIInfo(CodeGenTypes &CGT, bool HV) : ABIInfo(CGT), HasVector(HV) {}
+
+  bool isPromotableIntegerType(QualType Ty) const;
+  bool isCompoundType(QualType Ty) const;
+  bool isVectorArgumentType(QualType Ty) const;
+  bool isFPArgumentType(QualType Ty) const;
+  QualType getSingleElementType(QualType Ty) const;
+  unsigned getMaxAlignFromTypeDefs(QualType Ty) const;
+  std::optional getFPTypeOfComplexLikeType(QualType Ty) const;
+
+  ABIArgInfo classifyReturnType(QualType RetTy) const;
+  ABIArgInfo classifyArgumentType(QualType ArgTy, bool IsNamedArg) const;
+
+  void computeInfo(CGFunctionInfo &FI) const override {
+if (!getCXXABI().classifyReturnType(FI))
+  FI.getReturnInfo() = classifyReturnType(FI.getReturnType());
+
+unsigned NumRequiredArgs = FI.getNumRequiredArgs();
+unsigned ArgNo = 0;
+
+for (auto &I : FI.arguments()) {
+  bool IsNamedArg = ArgNo < NumRequiredArgs;
+  I.info = classifyArgumentType(I.type, IsNamedArg);
+  ++ArgNo;
+}
+  }
+
+  Address EmitVAArg(CodeGenFunction &CGF, Address VAListAddr,
+QualType Ty) const override;
+};
+
+class ZOSXPLinkTargetCodeGenInfo : public TargetCodeGenInfo {
+public:
+  ZOSXPLinkTargetCodeGenInfo(CodeGenTypes &CGT, bool HasVector)
+  : TargetCodeGenInfo(std::make_unique(CGT, HasVector)) {
+SwiftInfo =
+std::make_unique(CGT, /*SwiftErrorInRegister=*/false);
+  }
+};
+
+} // namespace
+
+// Return true if the ABI requires Ty to be passed sign- or zero-
+// extended to 64 bits.
+bool ZOSXPLinkABIInfo::isPromotableIntegerType(QualType Ty) const {
+  // Treat an enum type as its underlying type.
+  if (const EnumType *EnumTy = Ty->getAs())
+Ty = EnumTy->getDecl()->getIntegerType();
+
+  // Promotable integer types are required to be promoted by the ABI.
+  if (getContext().isPromotableIntegerType(Ty))
+return true;
+
+  if (const auto *EIT = Ty->getAs())
+if (EIT->getNumBits() < 64)
+  return true;
+
+  // In addition to the usual promotable integer types, we also need to
+  // extend all 32-bit types, since the ABI requires promotion to 64 bits.
+  if (const BuiltinType *BT = Ty->getAs())
+switch (BT->getKind()) {
+case BuiltinType::Int:
+case BuiltinType::UInt:
+  return true;
+default:
+  break;
+}
+
+  return false;
+}
+
+bool ZOSXPLinkABIInfo::isCompoundType(QualType Ty) const {
+  return (Ty->isAnyComplexType() || Ty->isVectorType() ||
+  isAggregateTypeForABI(Ty));
+}
+
+bool ZOSXPLinkABIInfo::isVectorArgumentType(QualType Ty) const {
+  return (HasVector && Ty->isVectorType() &&
+  getContext().getTypeSize(Ty) <= 128);
+}
+
+bool ZOSXPLinkABIInfo::isFPArgumentType(QualType Ty) const {
+  if (const BuiltinType *BT = Ty->getAs())
+switch (BT->getKind()) {
+case BuiltinType::Float:
+case BuiltinType::Double:
+case BuiltinType::LongDouble:
+  return true;
+default:
+  return false;
+}
+
+  return false;
+}
+
+QualType ZOSXPLinkABIInfo::getSingleElementType(QualType Ty) const {
+  const RecordType *RT = Ty->getAs();
+
+  if (RT && RT->isStructureOrClassType()) {
+const RecordDecl *RD = RT->getDecl();
+QualType Found;
+
+// If this is a C++ record, check the bases first.
+if (const CXXRecordDecl *CXXRD = dyn_cast(RD))
+  if (CXXRD->hasDefinition())
+for (const auto &I : CXXRD->bases()) {
+  QualType Base = I.getType();
+
+  // Empty bases don't affect things either way.
+  if (isEmptyRecord(getContext(), Base, true))
+continue;
+
+  if (!Found.isNull())
+return Ty;
+  Found = getSingleElementType(Base);
+}
+
+// Check the fields.
+for (const auto *FD : RD->fields()) {
+  QualType FT = FD->getType();
+
+  // Ignore empty fields.
+  if (isEmptyField(getContext(), FD, true))
+continue;
+
+  if (!Found.isNull())
+return Ty;
+
+  // Treat single element arrays as the element.
+  while (const ConstantArrayType *AT =
+ getContext().getAsConstantArrayType(FT)) {
+if (AT->getZExtSize() != 1)
+  break;
+FT = AT->getElementType();
+  }
+
+  Found = getSingleElementType(FT);
+}
+
+// Unlike isSingleElementStruct(), trailing padding is allowed.
+if (!Found.isNull())
+  return Found;
+  }
+
+  return Ty;
+}
+
+unsigned ZOSXPLinkABIInfo::getMaxAlignFromTypeDefs(QualType Ty) const {
+  unsigned MaxAlign = 0;
+  while (Ty != Ty.getSingleStepDesugaredType

[clang] [SystemZ][z/OS] Implement z/OS XPLINK ABI (PR #91384)

2024-05-27 Thread Kai Nacke via cfe-commits


@@ -529,9 +530,379 @@ bool SystemZTargetCodeGenInfo::isVectorTypeBased(const 
Type *Ty,
   return false;
 }
 
+//===--===//
+// z/OS XPLINK ABI Implementation
+//===--===//
+
+namespace {
+
+class ZOSXPLinkABIInfo : public ABIInfo {
+  const unsigned GPRBits = 64;
+  bool HasVector;
+
+public:
+  ZOSXPLinkABIInfo(CodeGenTypes &CGT, bool HV) : ABIInfo(CGT), HasVector(HV) {}
+
+  bool isPromotableIntegerType(QualType Ty) const;
+  bool isCompoundType(QualType Ty) const;
+  bool isVectorArgumentType(QualType Ty) const;
+  bool isFPArgumentType(QualType Ty) const;
+  QualType getSingleElementType(QualType Ty) const;
+  unsigned getMaxAlignFromTypeDefs(QualType Ty) const;
+  std::optional getFPTypeOfComplexLikeType(QualType Ty) const;
+
+  ABIArgInfo classifyReturnType(QualType RetTy) const;
+  ABIArgInfo classifyArgumentType(QualType ArgTy, bool IsNamedArg) const;
+
+  void computeInfo(CGFunctionInfo &FI) const override {
+if (!getCXXABI().classifyReturnType(FI))
+  FI.getReturnInfo() = classifyReturnType(FI.getReturnType());
+
+unsigned NumRequiredArgs = FI.getNumRequiredArgs();
+unsigned ArgNo = 0;
+
+for (auto &I : FI.arguments()) {
+  bool IsNamedArg = ArgNo < NumRequiredArgs;
+  I.info = classifyArgumentType(I.type, IsNamedArg);
+  ++ArgNo;
+}
+  }
+
+  Address EmitVAArg(CodeGenFunction &CGF, Address VAListAddr,
+QualType Ty) const override;
+};
+
+class ZOSXPLinkTargetCodeGenInfo : public TargetCodeGenInfo {
+public:
+  ZOSXPLinkTargetCodeGenInfo(CodeGenTypes &CGT, bool HasVector)
+  : TargetCodeGenInfo(std::make_unique(CGT, HasVector)) {
+SwiftInfo =
+std::make_unique(CGT, /*SwiftErrorInRegister=*/false);
+  }
+};
+
+} // namespace
+
+// Return true if the ABI requires Ty to be passed sign- or zero-
+// extended to 64 bits.
+bool ZOSXPLinkABIInfo::isPromotableIntegerType(QualType Ty) const {
+  // Treat an enum type as its underlying type.
+  if (const EnumType *EnumTy = Ty->getAs())
+Ty = EnumTy->getDecl()->getIntegerType();
+
+  // Promotable integer types are required to be promoted by the ABI.
+  if (getContext().isPromotableIntegerType(Ty))
+return true;
+
+  if (const auto *EIT = Ty->getAs())
+if (EIT->getNumBits() < 64)
+  return true;
+
+  // In addition to the usual promotable integer types, we also need to
+  // extend all 32-bit types, since the ABI requires promotion to 64 bits.
+  if (const BuiltinType *BT = Ty->getAs())
+switch (BT->getKind()) {
+case BuiltinType::Int:
+case BuiltinType::UInt:
+  return true;
+default:
+  break;
+}
+
+  return false;
+}
+
+bool ZOSXPLinkABIInfo::isCompoundType(QualType Ty) const {
+  return (Ty->isAnyComplexType() || Ty->isVectorType() ||
+  isAggregateTypeForABI(Ty));
+}
+
+bool ZOSXPLinkABIInfo::isVectorArgumentType(QualType Ty) const {
+  return (HasVector && Ty->isVectorType() &&
+  getContext().getTypeSize(Ty) <= 128);
+}
+
+bool ZOSXPLinkABIInfo::isFPArgumentType(QualType Ty) const {
+  if (const BuiltinType *BT = Ty->getAs())
+switch (BT->getKind()) {
+case BuiltinType::Float:
+case BuiltinType::Double:
+case BuiltinType::LongDouble:
+  return true;
+default:
+  return false;
+}
+
+  return false;
+}
+
+QualType ZOSXPLinkABIInfo::getSingleElementType(QualType Ty) const {
+  const RecordType *RT = Ty->getAs();
+
+  if (RT && RT->isStructureOrClassType()) {
+const RecordDecl *RD = RT->getDecl();
+QualType Found;
+
+// If this is a C++ record, check the bases first.
+if (const CXXRecordDecl *CXXRD = dyn_cast(RD))
+  if (CXXRD->hasDefinition())
+for (const auto &I : CXXRD->bases()) {
+  QualType Base = I.getType();
+
+  // Empty bases don't affect things either way.
+  if (isEmptyRecord(getContext(), Base, true))
+continue;
+
+  if (!Found.isNull())
+return Ty;
+  Found = getSingleElementType(Base);
+}
+
+// Check the fields.
+for (const auto *FD : RD->fields()) {
+  QualType FT = FD->getType();
+
+  // Ignore empty fields.
+  if (isEmptyField(getContext(), FD, true))
+continue;
+
+  if (!Found.isNull())
+return Ty;
+
+  // Treat single element arrays as the element.
+  while (const ConstantArrayType *AT =
+ getContext().getAsConstantArrayType(FT)) {
+if (AT->getZExtSize() != 1)
+  break;
+FT = AT->getElementType();
+  }
+
+  Found = getSingleElementType(FT);
+}
+
+// Unlike isSingleElementStruct(), trailing padding is allowed.
+if (!Found.isNull())
+  return Found;
+  }
+
+  return Ty;
+}
+
+unsigned ZOSXPLinkABIInfo::getMaxAlignFromTypeDefs(QualType Ty) const {
+  unsigned MaxAlign = 0;
+  while (Ty != Ty.getSingleStepDesugaredType

[clang] [SystemZ][z/OS] Implement z/OS XPLINK ABI (PR #91384)

2024-05-27 Thread Kai Nacke via cfe-commits

https://github.com/redstar commented:

Sorry, I left some more comments.
In addition, there is no test involving a union. That is especially interesting 
for the complex-like structures. E.g.
```
union Float2 {
  float a;
  float b;
};

struct Elem {
  float a;
  Float2 b;
};

Elem calc(Elem);
```
A test case involving vector types is also missing.

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


[clang] [SystemZ][z/OS] Implement z/OS XPLINK ABI (PR #91384)

2024-05-27 Thread Kai Nacke via cfe-commits


@@ -529,9 +530,379 @@ bool SystemZTargetCodeGenInfo::isVectorTypeBased(const 
Type *Ty,
   return false;
 }
 
+//===--===//
+// z/OS XPLINK ABI Implementation
+//===--===//
+
+namespace {
+
+class ZOSXPLinkABIInfo : public ABIInfo {
+  const unsigned GPRBits = 64;
+  bool HasVector;
+
+public:
+  ZOSXPLinkABIInfo(CodeGenTypes &CGT, bool HV) : ABIInfo(CGT), HasVector(HV) {}
+
+  bool isPromotableIntegerType(QualType Ty) const;
+  bool isCompoundType(QualType Ty) const;
+  bool isVectorArgumentType(QualType Ty) const;
+  bool isFPArgumentType(QualType Ty) const;
+  QualType getSingleElementType(QualType Ty) const;
+  unsigned getMaxAlignFromTypeDefs(QualType Ty) const;
+  std::optional getFPTypeOfComplexLikeType(QualType Ty) const;
+
+  ABIArgInfo classifyReturnType(QualType RetTy) const;
+  ABIArgInfo classifyArgumentType(QualType ArgTy, bool IsNamedArg) const;
+
+  void computeInfo(CGFunctionInfo &FI) const override {
+if (!getCXXABI().classifyReturnType(FI))
+  FI.getReturnInfo() = classifyReturnType(FI.getReturnType());
+
+unsigned NumRequiredArgs = FI.getNumRequiredArgs();
+unsigned ArgNo = 0;
+
+for (auto &I : FI.arguments()) {
+  bool IsNamedArg = ArgNo < NumRequiredArgs;
+  I.info = classifyArgumentType(I.type, IsNamedArg);
+  ++ArgNo;
+}
+  }
+
+  Address EmitVAArg(CodeGenFunction &CGF, Address VAListAddr,
+QualType Ty) const override;
+};
+
+class ZOSXPLinkTargetCodeGenInfo : public TargetCodeGenInfo {
+public:
+  ZOSXPLinkTargetCodeGenInfo(CodeGenTypes &CGT, bool HasVector)
+  : TargetCodeGenInfo(std::make_unique(CGT, HasVector)) {
+SwiftInfo =
+std::make_unique(CGT, /*SwiftErrorInRegister=*/false);
+  }
+};
+
+} // namespace
+
+// Return true if the ABI requires Ty to be passed sign- or zero-
+// extended to 64 bits.
+bool ZOSXPLinkABIInfo::isPromotableIntegerType(QualType Ty) const {
+  // Treat an enum type as its underlying type.
+  if (const EnumType *EnumTy = Ty->getAs())
+Ty = EnumTy->getDecl()->getIntegerType();
+
+  // Promotable integer types are required to be promoted by the ABI.
+  if (getContext().isPromotableIntegerType(Ty))
+return true;
+
+  if (const auto *EIT = Ty->getAs())
+if (EIT->getNumBits() < 64)
+  return true;
+
+  // In addition to the usual promotable integer types, we also need to
+  // extend all 32-bit types, since the ABI requires promotion to 64 bits.
+  if (const BuiltinType *BT = Ty->getAs())
+switch (BT->getKind()) {
+case BuiltinType::Int:
+case BuiltinType::UInt:
+  return true;
+default:
+  break;
+}
+
+  return false;
+}
+
+bool ZOSXPLinkABIInfo::isCompoundType(QualType Ty) const {
+  return (Ty->isAnyComplexType() || Ty->isVectorType() ||
+  isAggregateTypeForABI(Ty));
+}
+
+bool ZOSXPLinkABIInfo::isVectorArgumentType(QualType Ty) const {
+  return (HasVector && Ty->isVectorType() &&
+  getContext().getTypeSize(Ty) <= 128);
+}
+
+bool ZOSXPLinkABIInfo::isFPArgumentType(QualType Ty) const {
+  if (const BuiltinType *BT = Ty->getAs())
+switch (BT->getKind()) {
+case BuiltinType::Float:
+case BuiltinType::Double:
+case BuiltinType::LongDouble:
+  return true;
+default:
+  return false;
+}
+
+  return false;
+}
+
+QualType ZOSXPLinkABIInfo::getSingleElementType(QualType Ty) const {
+  const RecordType *RT = Ty->getAs();
+
+  if (RT && RT->isStructureOrClassType()) {
+const RecordDecl *RD = RT->getDecl();
+QualType Found;
+
+// If this is a C++ record, check the bases first.
+if (const CXXRecordDecl *CXXRD = dyn_cast(RD))
+  if (CXXRD->hasDefinition())
+for (const auto &I : CXXRD->bases()) {
+  QualType Base = I.getType();
+
+  // Empty bases don't affect things either way.
+  if (isEmptyRecord(getContext(), Base, true))
+continue;
+
+  if (!Found.isNull())
+return Ty;
+  Found = getSingleElementType(Base);
+}
+
+// Check the fields.
+for (const auto *FD : RD->fields()) {
+  QualType FT = FD->getType();
+
+  // Ignore empty fields.
+  if (isEmptyField(getContext(), FD, true))
+continue;
+
+  if (!Found.isNull())
+return Ty;
+
+  // Treat single element arrays as the element.
+  while (const ConstantArrayType *AT =
+ getContext().getAsConstantArrayType(FT)) {
+if (AT->getZExtSize() != 1)
+  break;
+FT = AT->getElementType();
+  }
+
+  Found = getSingleElementType(FT);
+}
+
+// Unlike isSingleElementStruct(), trailing padding is allowed.
+if (!Found.isNull())
+  return Found;
+  }
+
+  return Ty;
+}
+
+unsigned ZOSXPLinkABIInfo::getMaxAlignFromTypeDefs(QualType Ty) const {
+  unsigned MaxAlign = 0;
+  while (Ty != Ty.getSingleStepDesugaredType

[clang] [clang] Be const-correct with all uses of `Module *`. (PR #93493)

2024-05-27 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-debuginfo

Author: David Stone (davidstone)


Changes



---

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


59 Files Affected:

- (modified) clang/include/clang/APINotes/APINotesManager.h (+1-1) 
- (modified) clang/include/clang/AST/ASTContext.h (+4-4) 
- (modified) clang/include/clang/AST/ASTMutationListener.h (+1-1) 
- (modified) clang/include/clang/AST/DeclBase.h (+3-3) 
- (modified) clang/include/clang/Basic/Module.h (+22-22) 
- (modified) clang/include/clang/Frontend/FrontendAction.h (+1-1) 
- (modified) clang/include/clang/Frontend/MultiplexConsumer.h (+1-1) 
- (modified) clang/include/clang/Lex/ExternalPreprocessorSource.h (+1-1) 
- (modified) clang/include/clang/Lex/HeaderSearch.h (+5-5) 
- (modified) clang/include/clang/Lex/MacroInfo.h (+6-6) 
- (modified) clang/include/clang/Lex/ModuleMap.h (+18-16) 
- (modified) clang/include/clang/Lex/PPCallbacks.h (+6-6) 
- (modified) clang/include/clang/Lex/Preprocessor.h (+14-13) 
- (modified) clang/include/clang/Sema/Sema.h (+26-20) 
- (modified) clang/include/clang/Serialization/ASTDeserializationListener.h 
(+1-1) 
- (modified) clang/include/clang/Serialization/ASTReader.h (+2-2) 
- (modified) clang/include/clang/Serialization/ASTWriter.h (+7-7) 
- (modified) clang/lib/APINotes/APINotesManager.cpp (+1-1) 
- (modified) clang/lib/AST/ASTContext.cpp (+4-4) 
- (modified) clang/lib/AST/Decl.cpp (+3-3) 
- (modified) clang/lib/AST/DeclBase.cpp (+1-1) 
- (modified) clang/lib/AST/ItaniumMangle.cpp (+1-1) 
- (modified) clang/lib/AST/ODRDiagsEmitter.cpp (+1-1) 
- (modified) clang/lib/AST/TextNodeDumper.cpp (+2-2) 
- (modified) clang/lib/Basic/Module.cpp (+17-20) 
- (modified) clang/lib/CodeGen/CGDebugInfo.cpp (+2-2) 
- (modified) clang/lib/CodeGen/CGDeclCXX.cpp (+7-7) 
- (modified) clang/lib/CodeGen/CodeGenModule.cpp (+16-15) 
- (modified) clang/lib/CodeGen/CodeGenModule.h (+4-4) 
- (modified) clang/lib/Frontend/CompilerInstance.cpp (+14-11) 
- (modified) clang/lib/Frontend/FrontendAction.cpp (+2-2) 
- (modified) clang/lib/Frontend/FrontendActions.cpp (+3-3) 
- (modified) clang/lib/Frontend/MultiplexConsumer.cpp (+3-3) 
- (modified) clang/lib/Frontend/PrintPreprocessedOutput.cpp (+4-3) 
- (modified) clang/lib/Frontend/Rewrite/InclusionRewriter.cpp (+2-1) 
- (modified) clang/lib/Lex/HeaderSearch.cpp (+8-7) 
- (modified) clang/lib/Lex/MacroInfo.cpp (+1-1) 
- (modified) clang/lib/Lex/ModuleMap.cpp (+37-36) 
- (modified) clang/lib/Lex/PPDirectives.cpp (+4-4) 
- (modified) clang/lib/Lex/PPLexerChange.cpp (+1-1) 
- (modified) clang/lib/Lex/PPMacroExpansion.cpp (+2-2) 
- (modified) clang/lib/Lex/Pragma.cpp (+3-3) 
- (modified) clang/lib/Lex/Preprocessor.cpp (+4-3) 
- (modified) clang/lib/Sema/Sema.cpp (+2-2) 
- (modified) clang/lib/Sema/SemaCodeComplete.cpp (+2-2) 
- (modified) clang/lib/Sema/SemaDecl.cpp (+5-5) 
- (modified) clang/lib/Sema/SemaDeclCXX.cpp (+2-2) 
- (modified) clang/lib/Sema/SemaLookup.cpp (+26-27) 
- (modified) clang/lib/Sema/SemaModule.cpp (+19-20) 
- (modified) clang/lib/Sema/SemaOverload.cpp (+2-2) 
- (modified) clang/lib/Sema/SemaTemplateInstantiate.cpp (+1-1) 
- (modified) clang/lib/Serialization/ASTReader.cpp (+15-16) 
- (modified) clang/lib/Serialization/ASTReaderDecl.cpp (+1-1) 
- (modified) clang/lib/Serialization/ASTWriter.cpp (+10-10) 
- (modified) clang/lib/Serialization/ASTWriterDecl.cpp (+1-1) 
- (modified) clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp (+1-1) 
- (modified) clang/tools/libclang/CIndex.cpp (+6-6) 
- (modified) clang/tools/libclang/CXIndexDataConsumer.cpp (+1-1) 
- (modified) clang/unittests/Sema/SemaNoloadLookupTest.cpp (+1-1) 


``diff
diff --git a/clang/include/clang/APINotes/APINotesManager.h 
b/clang/include/clang/APINotes/APINotesManager.h
index 18375c9e51a17..b559c24b322f2 100644
--- a/clang/include/clang/APINotes/APINotesManager.h
+++ b/clang/include/clang/APINotes/APINotesManager.h
@@ -145,7 +145,7 @@ class APINotesManager {
   ///
   /// \returns a vector of FileEntry where APINotes files are.
   llvm::SmallVector
-  getCurrentModuleAPINotes(Module *M, bool LookInModule,
+  getCurrentModuleAPINotes(const Module *M, bool LookInModule,
ArrayRef SearchPaths);
 
   /// Load Compiled API notes for current module.
diff --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index a1d1d1c51cd41..70d131c12e073 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -462,7 +462,7 @@ class ASTContext : public RefCountedBase {
 
 void resolve(ASTContext &Ctx);
   };
-  llvm::DenseMap ModuleInitializers;
+  llvm::DenseMap ModuleInitializers;
 
   /// This is the top-level (C++20) Named module we are building.
   Module *CurrentCXXNamedModule = nullptr;
@@ -1060,12 +1060,12 @@ class ASTContext : public RefCountedBase {
   /// for a module. This will typically be a global variable (with internal
 

[clang] [clang] Be const-correct with all uses of `Module *`. (PR #93493)

2024-05-27 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: David Stone (davidstone)


Changes



---

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


59 Files Affected:

- (modified) clang/include/clang/APINotes/APINotesManager.h (+1-1) 
- (modified) clang/include/clang/AST/ASTContext.h (+4-4) 
- (modified) clang/include/clang/AST/ASTMutationListener.h (+1-1) 
- (modified) clang/include/clang/AST/DeclBase.h (+3-3) 
- (modified) clang/include/clang/Basic/Module.h (+22-22) 
- (modified) clang/include/clang/Frontend/FrontendAction.h (+1-1) 
- (modified) clang/include/clang/Frontend/MultiplexConsumer.h (+1-1) 
- (modified) clang/include/clang/Lex/ExternalPreprocessorSource.h (+1-1) 
- (modified) clang/include/clang/Lex/HeaderSearch.h (+5-5) 
- (modified) clang/include/clang/Lex/MacroInfo.h (+6-6) 
- (modified) clang/include/clang/Lex/ModuleMap.h (+18-16) 
- (modified) clang/include/clang/Lex/PPCallbacks.h (+6-6) 
- (modified) clang/include/clang/Lex/Preprocessor.h (+14-13) 
- (modified) clang/include/clang/Sema/Sema.h (+26-20) 
- (modified) clang/include/clang/Serialization/ASTDeserializationListener.h 
(+1-1) 
- (modified) clang/include/clang/Serialization/ASTReader.h (+2-2) 
- (modified) clang/include/clang/Serialization/ASTWriter.h (+7-7) 
- (modified) clang/lib/APINotes/APINotesManager.cpp (+1-1) 
- (modified) clang/lib/AST/ASTContext.cpp (+4-4) 
- (modified) clang/lib/AST/Decl.cpp (+3-3) 
- (modified) clang/lib/AST/DeclBase.cpp (+1-1) 
- (modified) clang/lib/AST/ItaniumMangle.cpp (+1-1) 
- (modified) clang/lib/AST/ODRDiagsEmitter.cpp (+1-1) 
- (modified) clang/lib/AST/TextNodeDumper.cpp (+2-2) 
- (modified) clang/lib/Basic/Module.cpp (+17-20) 
- (modified) clang/lib/CodeGen/CGDebugInfo.cpp (+2-2) 
- (modified) clang/lib/CodeGen/CGDeclCXX.cpp (+7-7) 
- (modified) clang/lib/CodeGen/CodeGenModule.cpp (+16-15) 
- (modified) clang/lib/CodeGen/CodeGenModule.h (+4-4) 
- (modified) clang/lib/Frontend/CompilerInstance.cpp (+14-11) 
- (modified) clang/lib/Frontend/FrontendAction.cpp (+2-2) 
- (modified) clang/lib/Frontend/FrontendActions.cpp (+3-3) 
- (modified) clang/lib/Frontend/MultiplexConsumer.cpp (+3-3) 
- (modified) clang/lib/Frontend/PrintPreprocessedOutput.cpp (+4-3) 
- (modified) clang/lib/Frontend/Rewrite/InclusionRewriter.cpp (+2-1) 
- (modified) clang/lib/Lex/HeaderSearch.cpp (+8-7) 
- (modified) clang/lib/Lex/MacroInfo.cpp (+1-1) 
- (modified) clang/lib/Lex/ModuleMap.cpp (+37-36) 
- (modified) clang/lib/Lex/PPDirectives.cpp (+4-4) 
- (modified) clang/lib/Lex/PPLexerChange.cpp (+1-1) 
- (modified) clang/lib/Lex/PPMacroExpansion.cpp (+2-2) 
- (modified) clang/lib/Lex/Pragma.cpp (+3-3) 
- (modified) clang/lib/Lex/Preprocessor.cpp (+4-3) 
- (modified) clang/lib/Sema/Sema.cpp (+2-2) 
- (modified) clang/lib/Sema/SemaCodeComplete.cpp (+2-2) 
- (modified) clang/lib/Sema/SemaDecl.cpp (+5-5) 
- (modified) clang/lib/Sema/SemaDeclCXX.cpp (+2-2) 
- (modified) clang/lib/Sema/SemaLookup.cpp (+26-27) 
- (modified) clang/lib/Sema/SemaModule.cpp (+19-20) 
- (modified) clang/lib/Sema/SemaOverload.cpp (+2-2) 
- (modified) clang/lib/Sema/SemaTemplateInstantiate.cpp (+1-1) 
- (modified) clang/lib/Serialization/ASTReader.cpp (+15-16) 
- (modified) clang/lib/Serialization/ASTReaderDecl.cpp (+1-1) 
- (modified) clang/lib/Serialization/ASTWriter.cpp (+10-10) 
- (modified) clang/lib/Serialization/ASTWriterDecl.cpp (+1-1) 
- (modified) clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp (+1-1) 
- (modified) clang/tools/libclang/CIndex.cpp (+6-6) 
- (modified) clang/tools/libclang/CXIndexDataConsumer.cpp (+1-1) 
- (modified) clang/unittests/Sema/SemaNoloadLookupTest.cpp (+1-1) 


``diff
diff --git a/clang/include/clang/APINotes/APINotesManager.h 
b/clang/include/clang/APINotes/APINotesManager.h
index 18375c9e51a17..b559c24b322f2 100644
--- a/clang/include/clang/APINotes/APINotesManager.h
+++ b/clang/include/clang/APINotes/APINotesManager.h
@@ -145,7 +145,7 @@ class APINotesManager {
   ///
   /// \returns a vector of FileEntry where APINotes files are.
   llvm::SmallVector
-  getCurrentModuleAPINotes(Module *M, bool LookInModule,
+  getCurrentModuleAPINotes(const Module *M, bool LookInModule,
ArrayRef SearchPaths);
 
   /// Load Compiled API notes for current module.
diff --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index a1d1d1c51cd41..70d131c12e073 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -462,7 +462,7 @@ class ASTContext : public RefCountedBase {
 
 void resolve(ASTContext &Ctx);
   };
-  llvm::DenseMap ModuleInitializers;
+  llvm::DenseMap ModuleInitializers;
 
   /// This is the top-level (C++20) Named module we are building.
   Module *CurrentCXXNamedModule = nullptr;
@@ -1060,12 +1060,12 @@ class ASTContext : public RefCountedBase {
   /// for a module. This will typically be a global variable (with internal
   //

[clang] fix(91536): clang 18.1 parser crash (PR #93490)

2024-05-27 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Oleksandr T. (a-tarasyuk)


Changes

Fixes #91536

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


3 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+1) 
- (modified) clang/lib/Sema/SemaExprCXX.cpp (+3-3) 
- (added) clang/test/SemaCXX/invalid-this-in-lambda.cpp (+4) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 37a664b14fab1..055ac980e530d 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -802,6 +802,7 @@ Bug Fixes to C++ Support
 - Fixed a regression introduced in Clang 18 causing a static function 
overloading a non-static function
   with the same parameters not to be diagnosed. (Fixes #GH93456).
 - Clang now diagnoses unexpanded parameter packs in attributes. (Fixes 
#GH93269).
+- Fix an assertion failure when checking invalid ``this`` usage in the wrong 
context. (Fixes #GH91536).
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index d3e9dcb4f4399..6595abbcdda5b 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -1444,10 +1444,10 @@ bool Sema::CheckCXXThisType(SourceLocation Loc, 
QualType Type) {
   //   category are defined within such member functions as they are within
   //   an implicit object member function).
   DeclContext *DC = getFunctionLevelDeclContext();
-  if (const auto *Method = dyn_cast(DC);
-  Method && Method->isExplicitObjectMemberFunction()) {
+  const auto *Method = dyn_cast(DC);
+  if (Method && Method->isExplicitObjectMemberFunction()) {
 Diag(Loc, diag::err_invalid_this_use) << 1;
-  } else if (isLambdaCallWithExplicitObjectParameter(CurContext)) {
+  } else if (Method && isLambdaCallWithExplicitObjectParameter(CurContext)) {
 Diag(Loc, diag::err_invalid_this_use) << 1;
   } else {
 Diag(Loc, diag::err_invalid_this_use) << 0;
diff --git a/clang/test/SemaCXX/invalid-this-in-lambda.cpp 
b/clang/test/SemaCXX/invalid-this-in-lambda.cpp
new file mode 100644
index 0..ae65bda025e23
--- /dev/null
+++ b/clang/test/SemaCXX/invalid-this-in-lambda.cpp
@@ -0,0 +1,4 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
+
+decltype([]()->decltype(this) { }) a; // expected-error {{invalid use of 
'this' outside of a non-static member function}}
+

``




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


[clang] fix(91536): clang 18.1 parser crash (PR #93490)

2024-05-27 Thread Oleksandr T. via cfe-commits

https://github.com/a-tarasyuk created 
https://github.com/llvm/llvm-project/pull/93490

Fixes #91536

>From a20c395f5d44f98363172216256c8ce61e96ffbe Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Mon, 27 May 2024 23:25:53 +0300
Subject: [PATCH] fix(91536): skip explicit 'this' check in non-valid scope

---
 clang/docs/ReleaseNotes.rst   | 1 +
 clang/lib/Sema/SemaExprCXX.cpp| 6 +++---
 clang/test/SemaCXX/invalid-this-in-lambda.cpp | 4 
 3 files changed, 8 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/SemaCXX/invalid-this-in-lambda.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 37a664b14fab1..055ac980e530d 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -802,6 +802,7 @@ Bug Fixes to C++ Support
 - Fixed a regression introduced in Clang 18 causing a static function 
overloading a non-static function
   with the same parameters not to be diagnosed. (Fixes #GH93456).
 - Clang now diagnoses unexpanded parameter packs in attributes. (Fixes 
#GH93269).
+- Fix an assertion failure when checking invalid ``this`` usage in the wrong 
context. (Fixes #GH91536).
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index d3e9dcb4f4399..6595abbcdda5b 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -1444,10 +1444,10 @@ bool Sema::CheckCXXThisType(SourceLocation Loc, 
QualType Type) {
   //   category are defined within such member functions as they are within
   //   an implicit object member function).
   DeclContext *DC = getFunctionLevelDeclContext();
-  if (const auto *Method = dyn_cast(DC);
-  Method && Method->isExplicitObjectMemberFunction()) {
+  const auto *Method = dyn_cast(DC);
+  if (Method && Method->isExplicitObjectMemberFunction()) {
 Diag(Loc, diag::err_invalid_this_use) << 1;
-  } else if (isLambdaCallWithExplicitObjectParameter(CurContext)) {
+  } else if (Method && isLambdaCallWithExplicitObjectParameter(CurContext)) {
 Diag(Loc, diag::err_invalid_this_use) << 1;
   } else {
 Diag(Loc, diag::err_invalid_this_use) << 0;
diff --git a/clang/test/SemaCXX/invalid-this-in-lambda.cpp 
b/clang/test/SemaCXX/invalid-this-in-lambda.cpp
new file mode 100644
index 0..ae65bda025e23
--- /dev/null
+++ b/clang/test/SemaCXX/invalid-this-in-lambda.cpp
@@ -0,0 +1,4 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
+
+decltype([]()->decltype(this) { }) a; // expected-error {{invalid use of 
'this' outside of a non-static member function}}
+

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


[clang] [clang] Macro for constant rounding mode (PR #92699)

2024-05-27 Thread Eli Friedman via cfe-commits

efriedma-quic wrote:

Oh, I somehow thought the macro was part of the spec; reading again, I guess it 
isn't, it's just an attempt to implement the spec.

We probably want some feedback from libc implementers to check if this is what 
they want.  I don't really want to end up in a situation where we end up 
implementing this, but then nobody ends up using it.  Or we end up with two 
almost identical macros for the same thing.

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


[clang] [llvm] [mlir] [Clang][CodeGen] Start migrating away from assuming the Default AS is 0 (PR #88182)

2024-05-27 Thread via cfe-commits


@@ -368,7 +368,8 @@ CodeGenModule::CodeGenModule(ASTContext &C,
   IntTy = llvm::IntegerType::get(LLVMContext, C.getTargetInfo().getIntWidth());
   IntPtrTy = llvm::IntegerType::get(LLVMContext,
 C.getTargetInfo().getMaxPointerWidth());
-  Int8PtrTy = llvm::PointerType::get(LLVMContext, 0);
+  Int8PtrTy = llvm::PointerType::get(LLVMContext,

b-sumner wrote:

The AMDGPU address space mapping is at 
https://llvm.org/docs/AMDGPUUsage.html#address-spaces and address space 0 is 
not private.  The address space for all languages compiled for the AMDGPU 
target is consistent.

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


[clang-tools-extra] [clangd] Add config option to allow detection of unused system headers (PR #87208)

2024-05-27 Thread Vadim D. via cfe-commits

vvd170501 wrote:

Ping. @kadircet, can you merge this, please? Or are additional approvals 
required?

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


[clang] [clang-format] Add LeftWithLastLine to AlignEscapedNewlines option (PR #93402)

2024-05-27 Thread Björn Schäpers via cfe-commits

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

Nice

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


[clang] [clang-format]: Annotate colons found in inline assembly (PR #92617)

2024-05-27 Thread Björn Schäpers via cfe-commits

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


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


[clang] [clang-format] Improve BlockIndent at ColumnLimit (PR #93140)

2024-05-27 Thread Björn Schäpers via cfe-commits


@@ -803,6 +803,46 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState 
&State, bool DryRun,
 return !Tok.Previous->isOneOf(TT_CastRParen, tok::kw_for, tok::kw_while,
   tok::kw_switch);
   };
+  // Detecting functions is brittle. It would be better if we could annotate
+  // the LParen type of functions/calls.
+  const auto IsFunctionDeclParen = [&](const FormatToken &Tok) {
+return Tok.is(tok::l_paren) && Tok.Previous &&
+   (Tok.Previous->is(TT_FunctionDeclarationName) ||
+(Tok.Previous->Previous &&
+ Tok.Previous->Previous->is(tok::coloncolon) &&
+ Tok.Previous->Previous->Previous &&
+ 
Tok.Previous->Previous->Previous->is(TT_FunctionDeclarationName)));
+  };
+  const auto IsFunctionCallParen = [&](const FormatToken &Tok) {
+return Tok.is(tok::l_paren) && Tok.ParameterCount > 0 && Tok.Previous &&
+   Tok.Previous->is(tok::identifier);

HazardyKnusperkeks wrote:

What about lambdas?

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


[clang] [clang-format] Improve BlockIndent at ColumnLimit (PR #93140)

2024-05-27 Thread Björn Schäpers via cfe-commits


@@ -803,6 +803,46 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState 
&State, bool DryRun,
 return !Tok.Previous->isOneOf(TT_CastRParen, tok::kw_for, tok::kw_while,
   tok::kw_switch);
   };
+  // Detecting functions is brittle. It would be better if we could annotate
+  // the LParen type of functions/calls.
+  const auto IsFunctionDeclParen = [&](const FormatToken &Tok) {
+return Tok.is(tok::l_paren) && Tok.Previous &&
+   (Tok.Previous->is(TT_FunctionDeclarationName) ||
+(Tok.Previous->Previous &&
+ Tok.Previous->Previous->is(tok::coloncolon) &&
+ Tok.Previous->Previous->Previous &&
+ 
Tok.Previous->Previous->Previous->is(TT_FunctionDeclarationName)));
+  };
+  const auto IsFunctionCallParen = [&](const FormatToken &Tok) {
+return Tok.is(tok::l_paren) && Tok.ParameterCount > 0 && Tok.Previous &&
+   Tok.Previous->is(tok::identifier);
+  };
+  const auto IsInTemplateString = [&](const FormatToken &Tok) {
+if (!Style.isJavaScript())
+  return false;
+for (const FormatToken *Prev = &Tok; Prev; Prev = Prev->Previous) {
+  if (Prev->is(TT_TemplateString) && Prev->opensScope())
+return true;
+  if (Prev->is(TT_TemplateString) && Prev->closesScope())
+break;
+}
+return false;
+  };
+  const auto IsNotSimpleFunction = [&](const FormatToken &Tok) {

HazardyKnusperkeks wrote:

What is a simple function?

A bit more comments would be nice.

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


[clang] [clang-format] Improve BlockIndent at ColumnLimit (PR #93140)

2024-05-27 Thread Björn Schäpers via cfe-commits


@@ -6157,6 +6157,12 @@ bool TokenAnnotator::canBreakBefore(const AnnotatedLine 
&Line,
 return !(Previous && (Previous->is(tok::kw_for) || Previous->isIf()));
   }
 
+  if (Left.isOneOf(tok::r_paren, TT_TrailingAnnotation) &&

HazardyKnusperkeks wrote:

Is this related?

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


[clang] [llvm] [mlir] [Clang][CodeGen] Start migrating away from assuming the Default AS is 0 (PR #88182)

2024-05-27 Thread Alex Voicu via cfe-commits

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


[clang] [llvm] [mlir] [Clang][CodeGen] Start migrating away from assuming the Default AS is 0 (PR #88182)

2024-05-27 Thread Alex Voicu via cfe-commits


@@ -368,7 +368,8 @@ CodeGenModule::CodeGenModule(ASTContext &C,
   IntTy = llvm::IntegerType::get(LLVMContext, C.getTargetInfo().getIntWidth());
   IntPtrTy = llvm::IntegerType::get(LLVMContext,
 C.getTargetInfo().getMaxPointerWidth());
-  Int8PtrTy = llvm::PointerType::get(LLVMContext, 0);
+  Int8PtrTy = llvm::PointerType::get(LLVMContext,

AlexVlx wrote:

This seems to be an error on ASAN's side, it's relying on non-guaranteed 
behaviour and linking BC emanating from different languages with different AS 
maps. To wit, 0 is private for OCL, so having `llvm.used` and 
`llvm.compiler.used` be global arrays of pointers to private is somewhat 
suspect. I will / should fix `emitUsed` to rely on GlobalsInt8PtrTy, which 
seems like the right thing to do anyway, but whilst that'll make ASAN "work", 
it doesn't make ASAN correct, IMHO.

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


[clang] [clang] Macro for constant rounding mode (PR #92699)

2024-05-27 Thread Joshua Cranmer via cfe-commits

jcranmer-intel wrote:

Overall, I'm not opposed to this patch.

This new macro should probably be mentioned somewhere in the clang user 
documentation.

> The way this requirement is formulated indicates that it could be implemented 
> using preprocessor facility. Such implementation would require a builtin 
> macro that is set in the region where pragma FENV_ROUND is in effect and 
> reflects constant rounding mode.

Has there been any discussion with gcc and libc implementations about how they 
plan to implement this requirement? I'm not entirely convinced this is the best 
approach, especially given that "`printf` and `scanf` families" is on the list 
of functions that need to be affected, and that's a decent amount of functions 
to have to wrap with round-mode-aware-variants.

> This change introduces macro ROUNDING_MODE, which is a string dependent on 
> the constant rounding mode

It expands to an identify, not a string literal, right?

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


[clang] [llvm] [mlir] [Clang][CodeGen] Start migrating away from assuming the Default AS is 0 (PR #88182)

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


@@ -368,7 +368,8 @@ CodeGenModule::CodeGenModule(ASTContext &C,
   IntTy = llvm::IntegerType::get(LLVMContext, C.getTargetInfo().getIntWidth());
   IntPtrTy = llvm::IntegerType::get(LLVMContext,
 C.getTargetInfo().getMaxPointerWidth());
-  Int8PtrTy = llvm::PointerType::get(LLVMContext, 0);
+  Int8PtrTy = llvm::PointerType::get(LLVMContext,

yxsamliu wrote:

This seems to cause regressions for HIP -fsanitize=address.

Basically rocm device library for ASAN is compiled from OpenCL source code, for 
which the default address space is mapped to addr space 5 in IR. Int8PtrTy  is 
used to determine the pointer type in the llvm.compiler.used global array, 
which causes the pointers in that array to be in addr space 5. However, for HIP 
those are in addr space 0. The variable from different bitcode are appended 
together by the linker. The linker checks their type and emits error since they 
do not match.

https://godbolt.org/z/s48fTj7Pv

Before this change, the pointers are in addr space 0 for both HIP and OpenCL, 
therefore no such issue.

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


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

2024-05-27 Thread via cfe-commits

gulfemsavrun wrote:

Ok, thanks for your analysis @aaronmondal!  

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


[clang] nonblocking/nonallocating attributes (was: nolock/noalloc) (PR #84983)

2024-05-27 Thread Doug Wyatt via cfe-commits


@@ -7525,25 +7525,21 @@ static Attr *getCCTypeAttr(ASTContext &Ctx, ParsedAttr 
&Attr) {
 
 std::optional
 Sema::ActOnEffectExpression(Expr *CondExpr, StringRef AttributeName) {
-  auto BadExpr = [&]() {
-Diag(CondExpr->getExprLoc(), diag::err_attribute_argument_type)
-<< ("'" + AttributeName.str() + "'") << AANT_ArgumentIntegerConstant
-<< CondExpr->getSourceRange();
+  if (DiagnoseUnexpandedParameterPack(CondExpr))
 return std::nullopt;
-  };
-
-  if (CondExpr->isTypeDependent() || CondExpr->isValueDependent()) {
-if (CondExpr->containsUnexpandedParameterPack())
-  return BadExpr();
+  if (CondExpr->isTypeDependent() || CondExpr->isValueDependent())
 return FunctionEffectMode::Dependent;
-  }
 
   std::optional ConditionValue =
   CondExpr->getIntegerConstantExpr(Context);
-  if (!ConditionValue)
-return BadExpr();
-  return ConditionValue->getExtValue() ? FunctionEffectMode::True
-   : FunctionEffectMode::False;
+  if (!ConditionValue) {
+Diag(CondExpr->getExprLoc(), diag::err_attribute_argument_type)
+<< ("'" + AttributeName.str() + "'") << AANT_ArgumentIntegerConstant

dougsonos wrote:

I did that, with a FIXME about the inconsistency of that diagnostic.

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


[clang] [llvm] [clang][ci] Move libc++ testing into the main PR pipeline (PR #93318)

2024-05-27 Thread Louis Dionne via cfe-commits


@@ -1,82 +0,0 @@
-#===--===##

ldionne wrote:

`clang/utils/ci/run-buildbot` can be removed too, I think.

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


[clang] [llvm] [clang][ci] Move libc++ testing into the main PR pipeline (PR #93318)

2024-05-27 Thread Louis Dionne via cfe-commits


@@ -54,3 +54,68 @@ cmake -S "${MONOREPO_ROOT}"/llvm -B "${BUILD_DIR}" \
 echo "--- ninja"
 # Targets are not escaped as they are passed as separate arguments.
 ninja -C "${BUILD_DIR}" -k 0 ${targets}
+

ldionne wrote:

It seems that we disagree on the approach taken here. I won't block you from 
merging the patch even though I think it's not the right approach, but I had to 
explain my thoughts on it.

> If you're willing to do the work in a reasonable time (remember we're 
> reducing CI pressure here), you can take over this PR or I can abandon it. I 
> personally had enough of bash scripting to iterate on this immediately.

I can't commit to that, I'm already overcommitted for libc++ work.

Like I said, while I think this is not a great approach, I won't block you from 
going forward with it. It does achieve better overall throughput for the CI 
pipeline, so it's not like this approach has no benefits at all.

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


[clang] nonblocking/nonallocating attributes (was: nolock/noalloc) (PR #84983)

2024-05-27 Thread via cfe-commits


@@ -7525,25 +7525,21 @@ static Attr *getCCTypeAttr(ASTContext &Ctx, ParsedAttr 
&Attr) {
 
 std::optional
 Sema::ActOnEffectExpression(Expr *CondExpr, StringRef AttributeName) {
-  auto BadExpr = [&]() {
-Diag(CondExpr->getExprLoc(), diag::err_attribute_argument_type)
-<< ("'" + AttributeName.str() + "'") << AANT_ArgumentIntegerConstant
-<< CondExpr->getSourceRange();
+  if (DiagnoseUnexpandedParameterPack(CondExpr))
 return std::nullopt;
-  };
-
-  if (CondExpr->isTypeDependent() || CondExpr->isValueDependent()) {
-if (CondExpr->containsUnexpandedParameterPack())
-  return BadExpr();
+  if (CondExpr->isTypeDependent() || CondExpr->isValueDependent())
 return FunctionEffectMode::Dependent;
-  }
 
   std::optional ConditionValue =
   CondExpr->getIntegerConstantExpr(Context);
-  if (!ConditionValue)
-return BadExpr();
-  return ConditionValue->getExtValue() ? FunctionEffectMode::True
-   : FunctionEffectMode::False;
+  if (!ConditionValue) {
+Diag(CondExpr->getExprLoc(), diag::err_attribute_argument_type)
+<< ("'" + AttributeName.str() + "'") << AANT_ArgumentIntegerConstant

Sirraide wrote:

So yeah, honestly, if it’s already inconsistent, then I’d just pass in the name 
w/o quotes here and leave fixing that everywhere to a subsequent pr.

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


[clang] nonblocking/nonallocating attributes (was: nolock/noalloc) (PR #84983)

2024-05-27 Thread via cfe-commits


@@ -7525,25 +7525,21 @@ static Attr *getCCTypeAttr(ASTContext &Ctx, ParsedAttr 
&Attr) {
 
 std::optional
 Sema::ActOnEffectExpression(Expr *CondExpr, StringRef AttributeName) {
-  auto BadExpr = [&]() {
-Diag(CondExpr->getExprLoc(), diag::err_attribute_argument_type)
-<< ("'" + AttributeName.str() + "'") << AANT_ArgumentIntegerConstant
-<< CondExpr->getSourceRange();
+  if (DiagnoseUnexpandedParameterPack(CondExpr))
 return std::nullopt;
-  };
-
-  if (CondExpr->isTypeDependent() || CondExpr->isValueDependent()) {
-if (CondExpr->containsUnexpandedParameterPack())
-  return BadExpr();
+  if (CondExpr->isTypeDependent() || CondExpr->isValueDependent())
 return FunctionEffectMode::Dependent;
-  }
 
   std::optional ConditionValue =
   CondExpr->getIntegerConstantExpr(Context);
-  if (!ConditionValue)
-return BadExpr();
-  return ConditionValue->getExtValue() ? FunctionEffectMode::True
-   : FunctionEffectMode::False;
+  if (!ConditionValue) {
+Diag(CondExpr->getExprLoc(), diag::err_attribute_argument_type)
+<< ("'" + AttributeName.str() + "'") << AANT_ArgumentIntegerConstant

Sirraide wrote:

> passing a string constant

Actually, yes, that is inconsistent; it should be quoted because it is a 
language entity.

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


[clang] nonblocking/nonallocating attributes (was: nolock/noalloc) (PR #84983)

2024-05-27 Thread via cfe-commits


@@ -7525,25 +7525,21 @@ static Attr *getCCTypeAttr(ASTContext &Ctx, ParsedAttr 
&Attr) {
 
 std::optional
 Sema::ActOnEffectExpression(Expr *CondExpr, StringRef AttributeName) {
-  auto BadExpr = [&]() {
-Diag(CondExpr->getExprLoc(), diag::err_attribute_argument_type)
-<< ("'" + AttributeName.str() + "'") << AANT_ArgumentIntegerConstant
-<< CondExpr->getSourceRange();
+  if (DiagnoseUnexpandedParameterPack(CondExpr))
 return std::nullopt;
-  };
-
-  if (CondExpr->isTypeDependent() || CondExpr->isValueDependent()) {
-if (CondExpr->containsUnexpandedParameterPack())
-  return BadExpr();
+  if (CondExpr->isTypeDependent() || CondExpr->isValueDependent())
 return FunctionEffectMode::Dependent;
-  }
 
   std::optional ConditionValue =
   CondExpr->getIntegerConstantExpr(Context);
-  if (!ConditionValue)
-return BadExpr();
-  return ConditionValue->getExtValue() ? FunctionEffectMode::True
-   : FunctionEffectMode::False;
+  if (!ConditionValue) {
+Diag(CondExpr->getExprLoc(), diag::err_attribute_argument_type)
+<< ("'" + AttributeName.str() + "'") << AANT_ArgumentIntegerConstant

Sirraide wrote:

> it would appear that in this case the attribute isn't quoted, which seems 
> inconsistent.

Afaik types that are used to describe names of entities are automatically 
quoted. If you can’t access the name of the attribute or sth in that vein here, 
one option I think would be to get an `IdentifierInfo*` for the name and pass 
that in instead (`getASTContext().Idents.get("foobar")`).

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


[clang] nonblocking/nonallocating attributes (was: nolock/noalloc) (PR #84983)

2024-05-27 Thread Doug Wyatt via cfe-commits


@@ -7525,25 +7525,21 @@ static Attr *getCCTypeAttr(ASTContext &Ctx, ParsedAttr 
&Attr) {
 
 std::optional
 Sema::ActOnEffectExpression(Expr *CondExpr, StringRef AttributeName) {
-  auto BadExpr = [&]() {
-Diag(CondExpr->getExprLoc(), diag::err_attribute_argument_type)
-<< ("'" + AttributeName.str() + "'") << AANT_ArgumentIntegerConstant
-<< CondExpr->getSourceRange();
+  if (DiagnoseUnexpandedParameterPack(CondExpr))
 return std::nullopt;
-  };
-
-  if (CondExpr->isTypeDependent() || CondExpr->isValueDependent()) {
-if (CondExpr->containsUnexpandedParameterPack())
-  return BadExpr();
+  if (CondExpr->isTypeDependent() || CondExpr->isValueDependent())
 return FunctionEffectMode::Dependent;
-  }
 
   std::optional ConditionValue =
   CondExpr->getIntegerConstantExpr(Context);
-  if (!ConditionValue)
-return BadExpr();
-  return ConditionValue->getExtValue() ? FunctionEffectMode::True
-   : FunctionEffectMode::False;
+  if (!ConditionValue) {
+Diag(CondExpr->getExprLoc(), diag::err_attribute_argument_type)
+<< ("'" + AttributeName.str() + "'") << AANT_ArgumentIntegerConstant

dougsonos wrote:

The difficulty here is:
- this is a pre-existing diagnostic; I didn't see a need for a new one just for 
quotes
- the other users  of the pre-existing diagnostic use `<<` with a `ParsedAttr`, 
which apparently quotes the attribute (?), but this function can be called from 
`TreeTransform` (for template instantiation), where there is only a 
`FunctionEffect` (whose name is passed in).

And then there are usages like:
```
Diag(AttrLoc, diag::err_attribute_argument_type)
<< "vector_size" << AANT_ArgumentIntegerConstant
<< SizeExpr->getSourceRange();
```
, passing a string constant; it would appear that in this case the attribute 
isn't quoted, which seems inconsistent.

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


[clang] nonblocking/nonallocating attributes (was: nolock/noalloc) (PR #84983)

2024-05-27 Thread Doug Wyatt via cfe-commits

dougsonos wrote:

> @dougsonos Just merged a pr that diagnoses unexpanded parameter packs when an 
> attribute is parsed, so could you double-check if that call to 
> `DiagnoseUnexpandedParameterPack` is still necessary?

I just re-merged main to the branch and verified that the call to 
`DiagnoseUnexpandedParameterPack` is no longer needed.

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


[clang] [compiler-rt] [llvm] [openmp] [PGO][Offload] Profile profraw generation for GPU instrumentation #76587 (PR #93365)

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

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

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

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

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

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

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

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

[clang] [Clang] Static and explicit object member functions with the same parameter-type-lists (PR #93430)

2024-05-27 Thread via cfe-commits


@@ -7636,7 +7651,16 @@ Sema::AddMethodCandidate(CXXMethodDecl *Method, 
DeclAccessPair FoundDecl,
   // exist for each argument an implicit conversion sequence
   // (13.3.3.1) that converts that argument to the corresponding
   // parameter of F.
-  QualType ParamType = Proto->getParamType(ArgIdx + ExplicitOffset);
+  QualType ParamType;
+  if (CandidateSet.getKind() ==
+  OverloadCandidateSet::CSK_AddressOfOverloadSet &&
+  Method->isImplicitObjectMemberFunction()) {

Sirraide wrote:

>From what I can tell, this function checks this exact condition in several 
>places, so we could maybe put sth. like this at the start of the function
```c++
bool AddImplicitObjectParam = 
CandidateSet.getKind() == OverloadCandidateSet::CSK_AddressOfOverloadSet &&
Method->isImplicitObjectMemberFunction()
```
and use that instead to make it a bit clearer that it’s really the same 
condition.

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


[clang] [Clang] Static and explicit object member functions with the same parameter-type-lists (PR #93430)

2024-05-27 Thread via cfe-commits


@@ -16333,7 +16387,7 @@ ExprResult Sema::FixOverloadedFunctionReference(Expr 
*E, DeclAccessPair Found,
 assert(UnOp->getOpcode() == UO_AddrOf &&
"Can only take the address of an overloaded function");
 if (CXXMethodDecl *Method = dyn_cast(Fn)) {
-  if (Method->isStatic()) {
+  if (!Method->isImplicitObjectMemberFunction()) {
 // Do nothing: static member functions aren't any different
 // from non-member functions.

Sirraide wrote:

nit: maybe update the comment too to indicate that this is also intended to 
handle explicit object member functions.

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


[clang] [Clang] Static and explicit object member functions with the same parameter-type-lists (PR #93430)

2024-05-27 Thread via cfe-commits


@@ -209,6 +209,9 @@ C++23 Feature Support
 - Added a ``__reference_converts_from_temporary`` builtin, completing the 
necessary compiler support for
   `P2255R2: Type trait to determine if a reference binds to a temporary 
`_.
 
+- Implemented `P2797R0: Static and explicit object member functions with the 
same parameter-type-lists `.

Sirraide wrote:

```suggestion
- Implemented `P2797R0: Static and explicit object member functions with the 
same parameter-type-lists `_.
```
I think there should be an underscore there.

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


[clang] [Clang] Static and explicit object member functions with the same parameter-type-lists (PR #93430)

2024-05-27 Thread via cfe-commits


@@ -5834,9 +5852,12 @@ Sema::ConvertArgumentsForCall(CallExpr *Call, Expr *Fn,
 
   // C99 6.5.2.2p7 - the arguments are implicitly converted, as if by
   // assignment, to the types of the corresponding parameter, ...
+
+  bool AddressOf = isParenthetizedAndQualifiedAddressOfExpr(Fn);
   bool HasExplicitObjectParameter =
-  FDecl && FDecl->hasCXXExplicitFunctionObjectParameter();
-  unsigned ExplicitObjectParameterOffset = HasExplicitObjectParameter ? 1 : 0;
+  !AddressOf && FDecl && FDecl->hasCXXExplicitFunctionObjectParameter();
+  unsigned ExplicitObjectParameterOffset =
+  HasExplicitObjectParameter && !AddressOf ? 1 : 0;

Sirraide wrote:

```suggestion
  unsigned ExplicitObjectParameterOffset = HasExplicitObjectParameter ? 1 : 0;
```
This change seems redundant because `HasExplicitObjectParameter` already 
implies `!AddressOf`, right?

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


[clang] [Clang] Static and explicit object member functions with the same parameter-type-lists (PR #93430)

2024-05-27 Thread via cfe-commits


@@ -5813,6 +5813,24 @@ static TypoCorrection TryTypoCorrectionForCall(Sema &S, 
Expr *Fn,
   return TypoCorrection();
 }
 
+static bool isParenthetizedAndQualifiedAddressOfExpr(Expr *Fn) {
+  if (!isa(Fn))
+return false;
+
+  Fn = Fn->IgnoreParens();
+  auto *UO = dyn_cast(Fn);
+  if (!UO)
+return false;
+  assert(cast(Fn)->getOpcode() == UO_AddrOf);

Sirraide wrote:

What about e.g.
```c++
void f() {}
void g() { (*&f)(); }
```
Wouldn’t that run into this assertion here?

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


[clang] [Clang] Static and explicit object member functions with the same parameter-type-lists (PR #93430)

2024-05-27 Thread via cfe-commits

https://github.com/Sirraide commented:

Just a few minor things I noticed

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


[clang] [Clang] Static and explicit object member functions with the same parameter-type-lists (PR #93430)

2024-05-27 Thread via cfe-commits

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


[clang-tools-extra] Update identifier-length.rst (PR #93467)

2024-05-27 Thread Piotr Zegar via cfe-commits

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


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


  1   2   3   >