[PATCH] D150913: [Clang][BFloat16] Upgrade __bf16 to arithmetic type, change mangling, and extend excess precision support.

2023-05-26 Thread Phoebe Wang via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe62175736551: [Clang][BFloat16] Upgrade __bf16 to arithmetic 
type, change mangling, and… (authored by codemzs, committed by pengfei).

Changed prior to commit:
  https://reviews.llvm.org/D150913?vs=526072=526243#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150913

Files:
  clang/docs/LanguageExtensions.rst
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/FPOptions.def
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Basic/TargetInfo.h
  clang/include/clang/Driver/Options.td
  clang/lib/AST/Type.cpp
  clang/lib/Basic/TargetInfo.cpp
  clang/lib/Basic/Targets/AMDGPU.h
  clang/lib/Basic/Targets/ARM.cpp
  clang/lib/Basic/Targets/NVPTX.h
  clang/lib/Basic/Targets/X86.cpp
  clang/lib/Basic/Targets/X86.h
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Sema/SemaCast.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/test/CodeGen/X86/avx512bf16-error.c
  clang/test/CodeGen/X86/bfloat-mangle.cpp
  clang/test/CodeGen/X86/bfloat16.cpp
  clang/test/CodeGen/X86/fexcess-precision-bfloat16.c
  clang/test/CodeGenCUDA/amdgpu-bf16.cu
  clang/test/CodeGenCUDA/bf16.cu
  clang/test/Driver/fexcess-precision.c
  clang/test/Sema/arm-bf16-forbidden-ops.c
  clang/test/Sema/arm-bf16-forbidden-ops.cpp
  clang/test/Sema/arm-bfloat.cpp
  clang/test/SemaCUDA/amdgpu-bf16.cu
  clang/test/SemaCUDA/bf16.cu

Index: clang/test/SemaCUDA/bf16.cu
===
--- clang/test/SemaCUDA/bf16.cu
+++ clang/test/SemaCUDA/bf16.cu
@@ -2,32 +2,32 @@
 // REQUIRES: x86-registered-target
 
 // RUN: %clang_cc1 "-triple" "x86_64-unknown-linux-gnu" "-aux-triple" "nvptx64-nvidia-cuda" \
-// RUN:"-target-cpu" "x86-64" -fsyntax-only -verify=scalar %s
+// RUN:"-target-cpu" "x86-64" -fsyntax-only -verify=scalar -Wno-unused %s
 // RUN: %clang_cc1 "-aux-triple" "x86_64-unknown-linux-gnu" "-triple" "nvptx64-nvidia-cuda" \
-// RUN:-fcuda-is-device "-aux-target-cpu" "x86-64" -fsyntax-only -verify=scalar %s
+// RUN:-fcuda-is-device "-aux-target-cpu" "x86-64" -fsyntax-only -verify=scalar -Wno-unused %s
 
 #include "Inputs/cuda.h"
 
 __device__ void test(bool b, __bf16 *out, __bf16 in) {
   __bf16 bf16 = in; // No error on using the type itself.
 
-  bf16 + bf16; // scalar-error {{invalid operands to binary expression ('__bf16' and '__bf16')}}
-  bf16 - bf16; // scalar-error {{invalid operands to binary expression ('__bf16' and '__bf16')}}
-  bf16 * bf16; // scalar-error {{invalid operands to binary expression ('__bf16' and '__bf16')}}
-  bf16 / bf16; // scalar-error {{invalid operands to binary expression ('__bf16' and '__bf16')}}
+  bf16 + bf16;
+  bf16 - bf16;
+  bf16 * bf16;
+  bf16 / bf16;
 
   __fp16 fp16;
 
-  bf16 + fp16; // scalar-error {{invalid operands to binary expression ('__bf16' and '__fp16')}}
-  fp16 + bf16; // scalar-error {{invalid operands to binary expression ('__fp16' and '__bf16')}}
-  bf16 - fp16; // scalar-error {{invalid operands to binary expression ('__bf16' and '__fp16')}}
-  fp16 - bf16; // scalar-error {{invalid operands to binary expression ('__fp16' and '__bf16')}}
-  bf16 * fp16; // scalar-error {{invalid operands to binary expression ('__bf16' and '__fp16')}}
-  fp16 * bf16; // scalar-error {{invalid operands to binary expression ('__fp16' and '__bf16')}}
-  bf16 / fp16; // scalar-error {{invalid operands to binary expression ('__bf16' and '__fp16')}}
-  fp16 / bf16; // scalar-error {{invalid operands to binary expression ('__fp16' and '__bf16')}}
+  bf16 + fp16;
+  fp16 + bf16;
+  bf16 - fp16;
+  fp16 - bf16;
+  bf16 * fp16;
+  fp16 * bf16;
+  bf16 / fp16;
+  fp16 / bf16;
   bf16 = fp16; // scalar-error {{assigning to '__bf16' from incompatible type '__fp16'}}
   fp16 = bf16; // scalar-error {{assigning to '__fp16' from incompatible type '__bf16'}}
-  bf16 + (b ? fp16 : bf16); // scalar-error {{incompatible operand types ('__fp16' and '__bf16')}}
+  bf16 + (b ? fp16 : bf16);
   *out = bf16;
 }
Index: clang/test/SemaCUDA/amdgpu-bf16.cu
===
--- clang/test/SemaCUDA/amdgpu-bf16.cu
+++ clang/test/SemaCUDA/amdgpu-bf16.cu
@@ -1,13 +1,8 @@
 // REQUIRES: amdgpu-registered-target
 // REQUIRES: x86-registered-target
 
-// RUN: %clang_cc1 "-triple" "x86_64-unknown-linux-gnu" "-aux-triple" "amdgcn-amd-amdhsa"\
-// RUN:"-target-cpu" "x86-64" -fsyntax-only -verify=amdgcn %s
-// RUN: %clang_cc1 "-aux-triple" "x86_64-unknown-linux-gnu" "-triple" "amdgcn-amd-amdhsa"\
-// RUN:-fcuda-is-device "-aux-target-cpu" "x86-64" -fsyntax-only -verify=amdgcn %s
-
 // RUN: %clang_cc1 "-aux-triple" "x86_64-unknown-linux-gnu" "-triple" "r600-unknown-unknown"\
-// RUN:

[clang] e621757 - [Clang][BFloat16] Upgrade __bf16 to arithmetic type, change mangling, and extend excess precision support

2023-05-26 Thread Phoebe Wang via cfe-commits

Author: M. Zeeshan Siddiqui
Date: 2023-05-27T13:33:50+08:00
New Revision: e62175736551abf40a3410bc246f58e650eb8158

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

LOG: [Clang][BFloat16] Upgrade __bf16 to arithmetic type, change mangling, and 
extend excess precision support

Pursuant to discussions at
https://discourse.llvm.org/t/rfc-c-23-p1467r9-extended-floating-point-types-and-standard-names/70033/22,
this commit enhances the handling of the __bf16 type in Clang.
- Firstly, it upgrades __bf16 from a storage-only type to an arithmetic
  type.
- Secondly, it changes the mangling of __bf16 to DF16b on all
  architectures except ARM. This change has been made in
  accordance with the finalization of the mangling for the
  std::bfloat16_t type, as discussed at
  https://github.com/itanium-cxx-abi/cxx-abi/pull/147.
- Finally, this commit extends the existing excess precision support to
  the __bf16 type. This applies to hardware architectures that do not
  natively support bfloat16 arithmetic.
Appropriate tests have been added to verify the effects of these
changes and ensure no regressions in other areas of the compiler.

Reviewed By: rjmccall, pengfei, zahiraam

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

Added: 
clang/test/CodeGen/X86/bfloat16.cpp
clang/test/CodeGen/X86/fexcess-precision-bfloat16.c

Modified: 
clang/docs/LanguageExtensions.rst
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Basic/FPOptions.def
clang/include/clang/Basic/LangOptions.def
clang/include/clang/Basic/TargetInfo.h
clang/include/clang/Driver/Options.td
clang/lib/AST/Type.cpp
clang/lib/Basic/TargetInfo.cpp
clang/lib/Basic/Targets/AMDGPU.h
clang/lib/Basic/Targets/ARM.cpp
clang/lib/Basic/Targets/NVPTX.h
clang/lib/Basic/Targets/X86.cpp
clang/lib/Basic/Targets/X86.h
clang/lib/CodeGen/CGExprScalar.cpp
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Sema/SemaCast.cpp
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaOverload.cpp
clang/test/CodeGen/X86/avx512bf16-error.c
clang/test/CodeGen/X86/bfloat-mangle.cpp
clang/test/CodeGenCUDA/amdgpu-bf16.cu
clang/test/CodeGenCUDA/bf16.cu
clang/test/Driver/fexcess-precision.c
clang/test/Sema/arm-bfloat.cpp
clang/test/SemaCUDA/amdgpu-bf16.cu
clang/test/SemaCUDA/bf16.cu

Removed: 
clang/test/Sema/arm-bf16-forbidden-ops.c
clang/test/Sema/arm-bf16-forbidden-ops.cpp



diff  --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index d881568b13994..e5b725e15d089 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -774,61 +774,88 @@ The matrix type extension supports explicit casts. 
Implicit type conversion betw
 Half-Precision Floating Point
 =
 
-Clang supports three half-precision (16-bit) floating point types: ``__fp16``,
-``_Float16`` and ``__bf16``.  These types are supported in all language modes.
-
-``__fp16`` is supported on every target, as it is purely a storage format; see 
below.
-``_Float16`` is currently only supported on the following targets, with further
-targets pending ABI standardization:
-
-* 32-bit ARM
-* 64-bit ARM (AArch64)
-* AMDGPU
-* SPIR
-* X86 (see below)
-
-On X86 targets, ``_Float16`` is supported as long as SSE2 is available, which
-includes all 64-bit and all recent 32-bit processors. When the target supports
-AVX512-FP16, ``_Float16`` arithmetic is performed using that native support.
-Otherwise, ``_Float16`` arithmetic is performed by promoting to ``float``,
-performing the operation, and then truncating to ``_Float16``. When doing this
-emulation, Clang defaults to following the C standard's rules for excess
-precision arithmetic, which avoids intermediate truncations within statements
-and may generate 
diff erent results from a strict operation-by-operation
-emulation.
-
-``_Float16`` will be supported on more targets as they define ABIs for it.
-
-``__bf16`` is purely a storage format; it is currently only supported on the 
following targets:
-
-* 32-bit ARM
-* 64-bit ARM (AArch64)
-* X86 (see below)
-
-On X86 targets, ``__bf16`` is supported as long as SSE2 is available, which
-includes all 64-bit and all recent 32-bit processors.
-
-``__fp16`` is a storage and interchange format only.  This means that values of
-``__fp16`` are immediately promoted to (at least) ``float`` when used in 
arithmetic
-operations, so that e.g. the result of adding two ``__fp16`` values has type 
``float``.
-The behavior of ``__fp16`` is specified by the Arm C Language Extensions 
(`ACLE `_).
-Clang uses the ``binary16`` format from IEEE 754-2008 for ``__fp16``, not the 
ARM

[PATCH] D151609: [Driver] Remove unused class ForceSuccessCommand

2023-05-26 Thread Kazu Hirata via Phabricator via cfe-commits
kazu created this revision.
Herald added a project: All.
kazu requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay.
Herald added a project: clang.

The last use was removed by:

  commit 6625680a581c5e29c53d9f58d864cc6cd3cd05f6
  Author: Hans Wennborg 
  Date:   Tue Feb 2 14:10:26 2021 +0100


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D151609

Files:
  clang/include/clang/Driver/Job.h
  clang/lib/Driver/Job.cpp


Index: clang/lib/Driver/Job.cpp
===
--- clang/lib/Driver/Job.cpp
+++ clang/lib/Driver/Job.cpp
@@ -449,30 +449,6 @@
   "The CC1Command doesn't support changing the environment vars!");
 }
 
-ForceSuccessCommand::ForceSuccessCommand(
-const Action _, const Tool _,
-ResponseFileSupport ResponseSupport, const char *Executable_,
-const llvm::opt::ArgStringList _, ArrayRef Inputs,
-ArrayRef Outputs)
-: Command(Source_, Creator_, ResponseSupport, Executable_, Arguments_,
-  Inputs, Outputs) {}
-
-void ForceSuccessCommand::Print(raw_ostream , const char *Terminator,
-bool Quote, CrashReportInfo *CrashInfo) const {
-  Command::Print(OS, "", Quote, CrashInfo);
-  OS << " || (exit 0)" << Terminator;
-}
-
-int ForceSuccessCommand::Execute(ArrayRef> Redirects,
- std::string *ErrMsg,
- bool *ExecutionFailed) const {
-  int Status = Command::Execute(Redirects, ErrMsg, ExecutionFailed);
-  (void)Status;
-  if (ExecutionFailed)
-*ExecutionFailed = false;
-  return 0;
-}
-
 void JobList::Print(raw_ostream , const char *Terminator, bool Quote,
 CrashReportInfo *CrashInfo) const {
   for (const auto  : *this)
Index: clang/include/clang/Driver/Job.h
===
--- clang/include/clang/Driver/Job.h
+++ clang/include/clang/Driver/Job.h
@@ -258,23 +258,6 @@
   void setEnvironment(llvm::ArrayRef NewEnvironment) override;
 };
 
-/// Like Command, but always pretends that the wrapped command succeeded.
-class ForceSuccessCommand : public Command {
-public:
-  ForceSuccessCommand(const Action _, const Tool _,
-  ResponseFileSupport ResponseSupport,
-  const char *Executable_,
-  const llvm::opt::ArgStringList _,
-  ArrayRef Inputs,
-  ArrayRef Outputs = std::nullopt);
-
-  void Print(llvm::raw_ostream , const char *Terminator, bool Quote,
- CrashReportInfo *CrashInfo = nullptr) const override;
-
-  int Execute(ArrayRef> Redirects, std::string 
*ErrMsg,
-  bool *ExecutionFailed) const override;
-};
-
 /// JobList - A sequence of jobs to perform.
 class JobList {
 public:


Index: clang/lib/Driver/Job.cpp
===
--- clang/lib/Driver/Job.cpp
+++ clang/lib/Driver/Job.cpp
@@ -449,30 +449,6 @@
   "The CC1Command doesn't support changing the environment vars!");
 }
 
-ForceSuccessCommand::ForceSuccessCommand(
-const Action _, const Tool _,
-ResponseFileSupport ResponseSupport, const char *Executable_,
-const llvm::opt::ArgStringList _, ArrayRef Inputs,
-ArrayRef Outputs)
-: Command(Source_, Creator_, ResponseSupport, Executable_, Arguments_,
-  Inputs, Outputs) {}
-
-void ForceSuccessCommand::Print(raw_ostream , const char *Terminator,
-bool Quote, CrashReportInfo *CrashInfo) const {
-  Command::Print(OS, "", Quote, CrashInfo);
-  OS << " || (exit 0)" << Terminator;
-}
-
-int ForceSuccessCommand::Execute(ArrayRef> Redirects,
- std::string *ErrMsg,
- bool *ExecutionFailed) const {
-  int Status = Command::Execute(Redirects, ErrMsg, ExecutionFailed);
-  (void)Status;
-  if (ExecutionFailed)
-*ExecutionFailed = false;
-  return 0;
-}
-
 void JobList::Print(raw_ostream , const char *Terminator, bool Quote,
 CrashReportInfo *CrashInfo) const {
   for (const auto  : *this)
Index: clang/include/clang/Driver/Job.h
===
--- clang/include/clang/Driver/Job.h
+++ clang/include/clang/Driver/Job.h
@@ -258,23 +258,6 @@
   void setEnvironment(llvm::ArrayRef NewEnvironment) override;
 };
 
-/// Like Command, but always pretends that the wrapped command succeeded.
-class ForceSuccessCommand : public Command {
-public:
-  ForceSuccessCommand(const Action _, const Tool _,
-  ResponseFileSupport ResponseSupport,
-  const char *Executable_,
-  const llvm::opt::ArgStringList _,
-  ArrayRef Inputs,
-  ArrayRef Outputs = std::nullopt);
-
-  void Print(llvm::raw_ostream , const char *Terminator, bool Quote,
- CrashReportInfo *CrashInfo = 

[PATCH] D151608: [Sema] Remove unused function getFloat128Identifier

2023-05-26 Thread Kazu Hirata via Phabricator via cfe-commits
kazu created this revision.
Herald added a project: All.
kazu requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

The last use was removed by:

  commit bb1ea2d6139a72340b426e114510c46d938645a6
  Author: Nemanja Ivanovic 
  Date:   Mon May 9 08:52:33 2016 +


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D151608

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/Sema.cpp


Index: clang/lib/Sema/Sema.cpp
===
--- clang/lib/Sema/Sema.cpp
+++ clang/lib/Sema/Sema.cpp
@@ -219,7 +219,7 @@
   ArgumentPackSubstitutionIndex(-1), CurrentInstantiationScope(nullptr),
   DisableTypoCorrection(false), TyposCorrected(0), AnalysisWarnings(*this),
   ThreadSafetyDeclCache(nullptr), VarDataSharingAttributesStack(nullptr),
-  CurScope(nullptr), Ident_super(nullptr), Ident___float128(nullptr) {
+  CurScope(nullptr), Ident_super(nullptr) {
   assert(pp.TUKind == TUKind);
   TUScope = nullptr;
   isConstantEvaluatedOverride = false;
@@ -2685,12 +2685,6 @@
   return Ident_super;
 }
 
-IdentifierInfo *Sema::getFloat128Identifier() const {
-  if (!Ident___float128)
-Ident___float128 = ("__float128");
-  return Ident___float128;
-}
-
 void Sema::PushCapturedRegionScope(Scope *S, CapturedDecl *CD, RecordDecl *RD,
CapturedRegionKind K,
unsigned OpenMPCaptureLevel) {
Index: clang/include/clang/Sema/Sema.h
===
--- clang/include/clang/Sema/Sema.h
+++ clang/include/clang/Sema/Sema.h
@@ -13764,7 +13764,6 @@
   Scope *CurScope;
 
   mutable IdentifierInfo *Ident_super;
-  mutable IdentifierInfo *Ident___float128;
 
   /// Nullability type specifiers.
   IdentifierInfo *Ident__Nonnull = nullptr;
@@ -13813,7 +13812,6 @@
   }
 
   IdentifierInfo *getSuperIdentifier() const;
-  IdentifierInfo *getFloat128Identifier() const;
 
   ObjCContainerDecl *getObjCDeclContext() const;
 


Index: clang/lib/Sema/Sema.cpp
===
--- clang/lib/Sema/Sema.cpp
+++ clang/lib/Sema/Sema.cpp
@@ -219,7 +219,7 @@
   ArgumentPackSubstitutionIndex(-1), CurrentInstantiationScope(nullptr),
   DisableTypoCorrection(false), TyposCorrected(0), AnalysisWarnings(*this),
   ThreadSafetyDeclCache(nullptr), VarDataSharingAttributesStack(nullptr),
-  CurScope(nullptr), Ident_super(nullptr), Ident___float128(nullptr) {
+  CurScope(nullptr), Ident_super(nullptr) {
   assert(pp.TUKind == TUKind);
   TUScope = nullptr;
   isConstantEvaluatedOverride = false;
@@ -2685,12 +2685,6 @@
   return Ident_super;
 }
 
-IdentifierInfo *Sema::getFloat128Identifier() const {
-  if (!Ident___float128)
-Ident___float128 = ("__float128");
-  return Ident___float128;
-}
-
 void Sema::PushCapturedRegionScope(Scope *S, CapturedDecl *CD, RecordDecl *RD,
CapturedRegionKind K,
unsigned OpenMPCaptureLevel) {
Index: clang/include/clang/Sema/Sema.h
===
--- clang/include/clang/Sema/Sema.h
+++ clang/include/clang/Sema/Sema.h
@@ -13764,7 +13764,6 @@
   Scope *CurScope;
 
   mutable IdentifierInfo *Ident_super;
-  mutable IdentifierInfo *Ident___float128;
 
   /// Nullability type specifiers.
   IdentifierInfo *Ident__Nonnull = nullptr;
@@ -13813,7 +13812,6 @@
   }
 
   IdentifierInfo *getSuperIdentifier() const;
-  IdentifierInfo *getFloat128Identifier() const;
 
   ObjCContainerDecl *getObjCDeclContext() const;
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D151607: [AST] Remove unused function removeLocalCVRQualifiers

2023-05-26 Thread Kazu Hirata via Phabricator via cfe-commits
kazu created this revision.
Herald added a project: All.
kazu requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

The last use was removed by:

  commit 0eb06cb3aa2700508c20da28f22ff91e7b82a436
  Author: Roy Jacobson 
  Date:   Tue Mar 14 21:25:54 2023 +0200


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D151607

Files:
  clang/include/clang/AST/Type.h


Index: clang/include/clang/AST/Type.h
===
--- clang/include/clang/AST/Type.h
+++ clang/include/clang/AST/Type.h
@@ -948,7 +948,6 @@
   void removeLocalConst();
   void removeLocalVolatile();
   void removeLocalRestrict();
-  void removeLocalCVRQualifiers(unsigned Mask);
 
   void removeLocalFastQualifiers() { Value.setInt(0); }
   void removeLocalFastQualifiers(unsigned Mask) {
@@ -6781,15 +6780,6 @@
   removeLocalFastQualifiers(Qualifiers::Volatile);
 }
 
-inline void QualType::removeLocalCVRQualifiers(unsigned Mask) {
-  assert(!(Mask & ~Qualifiers::CVRMask) && "mask has non-CVR bits");
-  static_assert((int)Qualifiers::CVRMask == (int)Qualifiers::FastMask,
-"Fast bits differ from CVR bits!");
-
-  // Fast path: we don't need to touch the slow qualifiers.
-  removeLocalFastQualifiers(Mask);
-}
-
 /// Check if this type has any address space qualifier.
 inline bool QualType::hasAddressSpace() const {
   return getQualifiers().hasAddressSpace();


Index: clang/include/clang/AST/Type.h
===
--- clang/include/clang/AST/Type.h
+++ clang/include/clang/AST/Type.h
@@ -948,7 +948,6 @@
   void removeLocalConst();
   void removeLocalVolatile();
   void removeLocalRestrict();
-  void removeLocalCVRQualifiers(unsigned Mask);
 
   void removeLocalFastQualifiers() { Value.setInt(0); }
   void removeLocalFastQualifiers(unsigned Mask) {
@@ -6781,15 +6780,6 @@
   removeLocalFastQualifiers(Qualifiers::Volatile);
 }
 
-inline void QualType::removeLocalCVRQualifiers(unsigned Mask) {
-  assert(!(Mask & ~Qualifiers::CVRMask) && "mask has non-CVR bits");
-  static_assert((int)Qualifiers::CVRMask == (int)Qualifiers::FastMask,
-"Fast bits differ from CVR bits!");
-
-  // Fast path: we don't need to touch the slow qualifiers.
-  removeLocalFastQualifiers(Mask);
-}
-
 /// Check if this type has any address space qualifier.
 inline bool QualType::hasAddressSpace() const {
   return getQualifiers().hasAddressSpace();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D147307: [clang] Do not require GNUInlineAttr for inline builtins

2023-05-26 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added a comment.

This PR seems related to this crash: 
https://github.com/llvm/llvm-project/issues/62958


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147307

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


[PATCH] D151606: [NFC][CLANG] Fix Static Code Analyzer Concerns with bad bit right shift operation in getNVPTXLaneID()

2023-05-26 Thread Soumi Manna via Phabricator via cfe-commits
Manna created this revision.
Manna added a reviewer: tahonermann.
Herald added subscribers: mattd, gchakrabarti, asavonic, manas, ASDenysPetrov, 
dkrupp, donat.nagy, Szelethus, a.sidorin, baloghadamsoftware.
Herald added a project: All.
Manna requested review of this revision.
Herald added a project: clang.

In getNVPTXLaneID(CodeGenFunction &), the value of LaneIDBits is 4294967295 
since function call 
llvm::Log2_32(CGF->getTarget()->getGridValue().GV_Warp_Size) might return 
4294967295.

  unsigned LaneIDBits =
   llvm::Log2_32(CGF.getTarget().getGridValue().GV_Warp_Size);
  unsigned LaneIDMask = ~0u >> (32u - LaneIDBits); 
  
  `

The shift amount (32U - LaneIDBits) might be 33, So it has undefined behavior 
for right shifting by more than 31 bits.

This patch adds an assert to guard the LaneIDBits overflow issue with  
LaneIDMask value.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D151606

Files:
  clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp


Index: clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
===
--- clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
+++ clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
@@ -528,6 +528,8 @@
   CGBuilderTy  = CGF.Builder;
   unsigned LaneIDBits =
   llvm::Log2_32(CGF.getTarget().getGridValue().GV_Warp_Size);
+  assert((32U - LaneIDBits) <= 33 &&
+ "Invalid LaneIDBits size in NVPTX device.");
   unsigned LaneIDMask = ~0u >> (32u - LaneIDBits);
   auto  = static_cast(CGF.CGM.getOpenMPRuntime());
   return Bld.CreateAnd(RT.getGPUThreadID(CGF), Bld.getInt32(LaneIDMask),


Index: clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
===
--- clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
+++ clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
@@ -528,6 +528,8 @@
   CGBuilderTy  = CGF.Builder;
   unsigned LaneIDBits =
   llvm::Log2_32(CGF.getTarget().getGridValue().GV_Warp_Size);
+  assert((32U - LaneIDBits) <= 33 &&
+ "Invalid LaneIDBits size in NVPTX device.");
   unsigned LaneIDMask = ~0u >> (32u - LaneIDBits);
   auto  = static_cast(CGF.CGM.getOpenMPRuntime());
   return Bld.CreateAnd(RT.getGPUThreadID(CGF), Bld.getInt32(LaneIDMask),
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 273303a - [Sema] Remove unused declaration startLambdaDefinition

2023-05-26 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2023-05-26T20:19:23-07:00
New Revision: 273303ad66a32e5e599bef5ee18c3a9f589e530d

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

LOG: [Sema] Remove unused declaration startLambdaDefinition

The corresponding function definition was removed by:

  commit 93d7002dc4644b0a6f15a998dff0d55c72012e87
  Author: Corentin Jabot 
  Date:   Sun Feb 6 22:58:43 2022 +0100

Added: 


Modified: 
clang/include/clang/Sema/Sema.h

Removed: 




diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 26b717439e83..7447755ef2df 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -7115,14 +7115,6 @@ class Sema final {
  unsigned LambdaDependencyKind,
  LambdaCaptureDefault CaptureDefault);
 
-  /// Start the definition of a lambda expression.
-  CXXMethodDecl *
-  startLambdaDefinition(CXXRecordDecl *Class, SourceRange IntroducerRange,
-TypeSourceInfo *MethodType, SourceLocation EndLoc,
-ArrayRef Params,
-ConstexprSpecKind ConstexprKind, StorageClass SC,
-Expr *TrailingRequiresClause);
-
   /// Number lambda for linkage purposes if necessary.
   void handleLambdaNumbering(CXXRecordDecl *Class, CXXMethodDecl *Method,
  std::optional



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


[clang-tools-extra] 7961848 - [clangd] Remove unused declaration onCallHierarchyOutgoingCalls

2023-05-26 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2023-05-26T20:19:22-07:00
New Revision: 796184854c4db285bef503a4e57cd6c5aa54fa5d

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

LOG: [clangd] Remove unused declaration onCallHierarchyOutgoingCalls

The corresponding function definition was removed by:

  commit 1a929525e86a20d0b3455a400d0dbed40b325a13
  Author: Kadir Cetinkaya 
  Date:   Tue Dec 21 17:06:40 2021 +0100

Added: 


Modified: 
clang-tools-extra/clangd/ClangdLSPServer.h

Removed: 




diff  --git a/clang-tools-extra/clangd/ClangdLSPServer.h 
b/clang-tools-extra/clangd/ClangdLSPServer.h
index 33c8d221f9bd4..332ff680438ad 100644
--- a/clang-tools-extra/clangd/ClangdLSPServer.h
+++ b/clang-tools-extra/clangd/ClangdLSPServer.h
@@ -151,9 +151,6 @@ class ClangdLSPServer : private ClangdServer::Callbacks,
   void onCallHierarchyIncomingCalls(
   const CallHierarchyIncomingCallsParams &,
   Callback>);
-  void onCallHierarchyOutgoingCalls(
-  const CallHierarchyOutgoingCallsParams &,
-  Callback>);
   void onClangdInlayHints(const InlayHintsParams &,
   Callback);
   void onInlayHint(const InlayHintsParams &, Callback>);



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


[clang] 54ab4b3 - [CodeGen] Remove unused declarations emitNonSPMDParallelCall and emitSPMDParallelCall

2023-05-26 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2023-05-26T20:07:52-07:00
New Revision: 54ab4b3a2847127590cebdf17bc83288b7f03158

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

LOG: [CodeGen] Remove unused declarations emitNonSPMDParallelCall and 
emitSPMDParallelCall

The corresponding function definitions were removed by:

  commit a2dbfb6b72db19ed851464160ef7539b50d43894
  Author: Giorgis Georgakoudis 
  Date:   Wed Apr 21 11:41:31 2021 -0700

Added: 


Modified: 
clang/lib/CodeGen/CGOpenMPRuntimeGPU.h

Removed: 




diff  --git a/clang/lib/CodeGen/CGOpenMPRuntimeGPU.h 
b/clang/lib/CodeGen/CGOpenMPRuntimeGPU.h
index a1384f660356..5ef4ce1cfd09 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntimeGPU.h
+++ b/clang/lib/CodeGen/CGOpenMPRuntimeGPU.h
@@ -110,37 +110,6 @@ class CGOpenMPRuntimeGPU : public CGOpenMPRuntime {
   bool IsOffloadEntry,
   const RegionCodeGenTy ) override;
 
-  /// Emits code for parallel or serial call of the \a OutlinedFn with
-  /// variables captured in a record which address is stored in \a
-  /// CapturedStruct.
-  /// This call is for the Non-SPMD Execution Mode.
-  /// \param OutlinedFn Outlined function to be run in parallel threads. Type 
of
-  /// this function is void(*)(kmp_int32 *, kmp_int32, struct context_vars*).
-  /// \param CapturedVars A pointer to the record with the references to
-  /// variables used in \a OutlinedFn function.
-  /// \param IfCond Condition in the associated 'if' clause, if it was
-  /// specified, nullptr otherwise.
-  void emitNonSPMDParallelCall(CodeGenFunction , SourceLocation Loc,
-   llvm::Value *OutlinedFn,
-   ArrayRef CapturedVars,
-   const Expr *IfCond);
-
-  /// Emits code for parallel or serial call of the \a OutlinedFn with
-  /// variables captured in a record which address is stored in \a
-  /// CapturedStruct.
-  /// This call is for a parallel directive within an SPMD target directive.
-  /// \param OutlinedFn Outlined function to be run in parallel threads. Type 
of
-  /// this function is void(*)(kmp_int32 *, kmp_int32, struct context_vars*).
-  /// \param CapturedVars A pointer to the record with the references to
-  /// variables used in \a OutlinedFn function.
-  /// \param IfCond Condition in the associated 'if' clause, if it was
-  /// specified, nullptr otherwise.
-  ///
-  void emitSPMDParallelCall(CodeGenFunction , SourceLocation Loc,
-llvm::Function *OutlinedFn,
-ArrayRef CapturedVars,
-const Expr *IfCond);
-
 protected:
   /// Check if the default location must be constant.
   /// Constant for NVPTX for better optimization.



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


[clang] 8078e77 - [AST] Remove unused declaration enumerateVFPtrs

2023-05-26 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2023-05-26T20:07:51-07:00
New Revision: 8078e776c3c51a2c6620cc1f0d8493a3cc9f8a4e

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

LOG: [AST] Remove unused declaration enumerateVFPtrs

The corresponding function definition was removed by:

  commit 9c6e9e313d61284f3d7fa46c86b6f999c8a1adea
  Author: Reid Kleckner 
  Date:   Thu Feb 27 19:40:09 2014 +

Added: 


Modified: 
clang/include/clang/AST/VTableBuilder.h

Removed: 




diff  --git a/clang/include/clang/AST/VTableBuilder.h 
b/clang/include/clang/AST/VTableBuilder.h
index e451f3f861b79..1bf7d0467aa3f 100644
--- a/clang/include/clang/AST/VTableBuilder.h
+++ b/clang/include/clang/AST/VTableBuilder.h
@@ -563,8 +563,6 @@ class MicrosoftVTableContext : public VTableContextBase {
   llvm::DenseMap>
   VBaseInfo;
 
-  void enumerateVFPtrs(const CXXRecordDecl *ForClass, VPtrInfoVector );
-
   void computeVTableRelatedInformation(const CXXRecordDecl *RD) override;
 
   void dumpMethodLocations(const CXXRecordDecl *RD,



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


[clang] ee15c1f - [Sema] Remove unused declaration ConvertIntegerToTypeWarnOnOverflow

2023-05-26 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2023-05-26T20:07:49-07:00
New Revision: ee15c1fa84c2245866b0a202e896928621401f71

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

LOG: [Sema] Remove unused declaration ConvertIntegerToTypeWarnOnOverflow

The corresponding function definition was removed by:

  commit 077d083b4dd12538fc824d5784d455da0d86a1ea
  Author: Richard Smith 
  Date:   Mon Aug 4 00:40:48 2014 +

Added: 


Modified: 
clang/include/clang/Sema/Sema.h

Removed: 




diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 6f5fa86dc9ccc..26b717439e832 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -12941,13 +12941,6 @@ class Sema final {
   /// CheckCXXBooleanCondition - Returns true if conversion to bool is invalid.
   ExprResult CheckCXXBooleanCondition(Expr *CondExpr, bool IsConstexpr = 
false);
 
-  /// ConvertIntegerToTypeWarnOnOverflow - Convert the specified APInt to have
-  /// the specified width and sign.  If an overflow occurs, detect it and emit
-  /// the specified diagnostic.
-  void ConvertIntegerToTypeWarnOnOverflow(llvm::APSInt ,
-  unsigned NewWidth, bool NewSign,
-  SourceLocation Loc, unsigned DiagID);
-
   /// Checks that the Objective-C declaration is declared in the global scope.
   /// Emits an error and marks the declaration as invalid if it's not declared
   /// in the global scope.



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


[clang] 0286b47 - [Driver] Remove redundant -z special case. NFC

2023-05-26 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2023-05-26T19:39:19-07:00
New Revision: 0286b47ae03356853736986f91f85c67115611ae

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

LOG: [Driver] Remove redundant -z special case. NFC

Added: 


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

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 8854d13da98f..1ed93ba8b61b 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -299,13 +299,8 @@ void tools::AddLinkerInputs(const ToolChain , const 
InputInfoList ,
   TC.AddCXXStdlibLibArgs(Args, CmdArgs);
 else if (A.getOption().matches(options::OPT_Z_reserved_lib_cckext))
   TC.AddCCKextLibArgs(Args, CmdArgs);
-else if (A.getOption().matches(options::OPT_z)) {
-  // Pass -z prefix for gcc linker compatibility.
-  A.claim();
-  A.render(Args, CmdArgs);
-} else {
+else
   A.renderAsInput(Args, CmdArgs);
-}
   }
 }
 



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


[PATCH] D151589: [lld] add context-sensitive PGO options for MachO

2023-05-26 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay accepted this revision as: MaskRay.
MaskRay added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/lib/Driver/ToolChains/CommonArgs.cpp:1356
 
+Arg *tools::getLastCSProfileGenerateArg(const ArgList ) {
+  auto *CSPGOGenerateArg = Args.getLastArg(options::OPT_fcs_profile_generate,

Similar code in Clang.cpp `addPGOAndCoverageFlags` can be replaced by this 
function.



Comment at: clang/lib/Driver/ToolChains/Darwin.cpp:459
+  llvm::sys::path::append(Path, "default_%m.profraw");
+  CmdArgs.push_back(Args.MakeArgString("--cs-profile-generate"));
+  CmdArgs.push_back(Args.MakeArgString(Twine("--cs-profile-path=") + 
Path));

String literal doesn't need `MakeArgString`



Comment at: clang/test/Driver/cspgo-lto.c:8
+
+// RUN: %clang -target apple-arm64-ios -### %t.o -flto=thin -fuse-ld=lld 
-fprofile-use 2>&1 | FileCheck %s --check-prefix=DARWIN-USE1
+// RUN: %clang -target apple-arm64-ios -### %t.o -flto=thin -fuse-ld=lld 
-fprofile-use=a.profdata 2>&1 | FileCheck %s --check-prefix=DARWIN-USE2

Prefer `--target=` to deprecated/legacy (since clang 3.x) `-target `



Comment at: lld/MachO/Driver.cpp:1640
   config->strictAutoLink = args.hasArg(OPT_strict_auto_link);
+  config->csProfileGenerate = args.hasArg(OPT_cs_profile_generate);
+  config->csProfilePath = args.getLastArgValue(OPT_cs_profile_path);

This needs a `lld/test/MachO` test. The ELF patch unfortunately doesn't add a 
test and I failed to notice it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151589

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


[clang] af7aea3 - [Driver][test] Replace legacy -target with --target=

2023-05-26 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2023-05-26T19:01:39-07:00
New Revision: af7aea365a2ae8dc51938a614353e1586072ef83

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

LOG: [Driver][test] Replace legacy -target with --target=

Added: 


Modified: 
clang/test/Driver/cspgo-lto.c
clang/test/Driver/cuda-no-pgo-or-coverage.cu
clang/test/Driver/darwin-ld-lto-lld.c
clang/test/Driver/darwin-ld-lto.c
clang/test/Driver/gold-lto-samplepgo.c
clang/test/Driver/lto-dwo.c
clang/test/Driver/lto-jobs.c
clang/test/Driver/lto-unit.c
clang/test/Driver/lto.c
clang/test/Driver/lto.cu
clang/test/Driver/memtag-stack_lto.c
clang/test/Driver/mingw-lto.c
clang/test/Driver/split-lto-unit.c

Removed: 




diff  --git a/clang/test/Driver/cspgo-lto.c b/clang/test/Driver/cspgo-lto.c
index 52d4f2487b0d..d793400889d8 100644
--- a/clang/test/Driver/cspgo-lto.c
+++ b/clang/test/Driver/cspgo-lto.c
@@ -1,6 +1,6 @@
 // RUN: touch %t.o
 //
-// RUN: %clang -target x86_64-unknown-linux -### %t.o -flto=thin \
+// RUN: %clang --target=x86_64-unknown-linux -### %t.o -flto=thin \
 // RUN:   -fprofile-use 2>&1 | FileCheck %s
 
 // CHECK: -plugin-opt=cs-profile-path=default.profdata

diff  --git a/clang/test/Driver/cuda-no-pgo-or-coverage.cu 
b/clang/test/Driver/cuda-no-pgo-or-coverage.cu
index 15bc0100e3dc..01449fe7ae83 100644
--- a/clang/test/Driver/cuda-no-pgo-or-coverage.cu
+++ b/clang/test/Driver/cuda-no-pgo-or-coverage.cu
@@ -2,23 +2,23 @@
 // compilation.
 //
 //
-// XRUN: %clang -### -target x86_64-linux-gnu -c --cuda-gpu-arch=sm_20 \
+// XRUN: %clang -### --target=x86_64-linux-gnu -c --cuda-gpu-arch=sm_20 \
 // XRUN:   -fprofile-generate %s 2>&1 | \
 // XRUN:   FileCheck --check-prefixes=CHECK,PROF %s
 //
-// RUN: %clang -### -target x86_64-linux-gnu -c --cuda-gpu-arch=sm_20 \
+// RUN: %clang -### --target=x86_64-linux-gnu -c --cuda-gpu-arch=sm_20 \
 // RUN:   -fprofile-instr-generate %s 2>&1 | \
 // RUN:   FileCheck --check-prefixes=CHECK,PROF %s
 //
-// RUN: %clang -### -target x86_64-linux-gnu -c --cuda-gpu-arch=sm_20 \
+// RUN: %clang -### --target=x86_64-linux-gnu -c --cuda-gpu-arch=sm_20 \
 // RUN:   -coverage %s 2>&1 | \
 // RUN:   FileCheck --check-prefixes=CHECK,GCOV %s
 //
-// RUN: %clang -### -target x86_64-linux-gnu -c --cuda-gpu-arch=sm_20 \
+// RUN: %clang -### --target=x86_64-linux-gnu -c --cuda-gpu-arch=sm_20 \
 // RUN:   -ftest-coverage %s 2>&1 | \
 // RUN:   FileCheck --check-prefixes=CHECK,GCOV %s
 //
-// RUN: %clang -### -target x86_64-linux-gnu -c --cuda-gpu-arch=sm_20   \
+// RUN: %clang -### --target=x86_64-linux-gnu -c --cuda-gpu-arch=sm_20   \
 // RUN:   -fprofile-instr-generate -fcoverage-mapping %s 2>&1 | \
 // RUN:   FileCheck --check-prefixes=CHECK,PROF %s
 //

diff  --git a/clang/test/Driver/darwin-ld-lto-lld.c 
b/clang/test/Driver/darwin-ld-lto-lld.c
index 2d1ed86ebcda..2f44cad534b1 100644
--- a/clang/test/Driver/darwin-ld-lto-lld.c
+++ b/clang/test/Driver/darwin-ld-lto-lld.c
@@ -5,13 +5,13 @@
 // test doesn't require that.)
 
 // Check that -object_lto_path is passed correctly to ld64
-// RUN: %clang -fuse-ld=lld -B%S/Inputs/lld -target x86_64-apple-darwin10 \
+// RUN: %clang -fuse-ld=lld -B%S/Inputs/lld --target=x86_64-apple-darwin10 \
 // RUN: %s -flto=full -### 2>&1 \
 // RUN: | FileCheck -check-prefix=FULL_LTO_OBJECT_PATH %s
 // FULL_LTO_OBJECT_PATH: {{ld(.exe)?"}}
 // FULL_LTO_OBJECT_PATH-SAME: "-object_path_lto"
 // FULL_LTO_OBJECT_PATH-SAME: {{cc\-[a-zA-Z0-9_]+.o}}"
-// RUN: %clang -fuse-ld=lld -B%S/Inputs/lld -target x86_64-apple-darwin10 \
+// RUN: %clang -fuse-ld=lld -B%S/Inputs/lld --target=x86_64-apple-darwin10 \
 // RUN: %s -flto=thin -### 2>&1 \
 // RUN: | FileCheck -check-prefix=THIN_LTO_OBJECT_PATH %s
 // THIN_LTO_OBJECT_PATH: {{ld(.exe)?"}}

diff  --git a/clang/test/Driver/darwin-ld-lto.c 
b/clang/test/Driver/darwin-ld-lto.c
index 2e049769b0cd..386a8edecbe4 100644
--- a/clang/test/Driver/darwin-ld-lto.c
+++ b/clang/test/Driver/darwin-ld-lto.c
@@ -5,7 +5,7 @@
 // RUN: mkdir -p %t/bin
 // RUN: mkdir -p %t/lib
 // RUN: touch %t/lib/libLTO.dylib
-// RUN: %clang -fuse-ld= -target x86_64-apple-darwin10 -### %s \
+// RUN: %clang -fuse-ld= --target=x86_64-apple-darwin10 -### %s \
 // RUN:   -ccc-install-dir %t/bin -mlinker-version=133 2> %t.log
 // RUN: FileCheck -check-prefix=LINK_LTOLIB_PATH %s -input-file %t.log
 //
@@ -14,19 +14,19 @@
 
 // Also pass -lto_library even if the file doesn't exist; if it's needed at
 // link time, ld will complain instead.
-// RUN: %clang -fuse-ld= -target x86_64-apple-darwin10 -### %s \
+// RUN: %clang -fuse-ld= --target=x86_64-apple-darwin10 -### %s \
 // RUN:   -ccc-install-dir %S/dummytestdir -mlinker-version=133 2> %t.log
 // RUN: FileCheck -check-prefix=LINK_LTOLIB_PATH %s 

[PATCH] D151503: [CUDA] correctly install cuda_wrappers/bits/shared_ptr_base.h

2023-05-26 Thread Artem Belevich via Phabricator via cfe-commits
tra added inline comments.



Comment at: clang/lib/Headers/CMakeLists.txt:516
   COMPONENT cuda-resource-headers)
 
 install(

qiongsiwu1 wrote:
> qiongsiwu1 wrote:
> > tra wrote:
> > > qiongsiwu1 wrote:
> > > > Do we need an install target for `${cuda_wrapper_bits_files}` for the 
> > > > `cuda-resource-headers` component as well? It seems to be the case 
> > > > because this patch is treating `${cuda_wrapper_bits_files}` as part of 
> > > > `cuda-resource-headers`.
> > > > 
> > > > ```
> > > > add_header_target("cuda-resource-headers" 
> > > > "${cuda_files};${cuda_wrapper_files};${cuda_wrapper_bits_files}")
> > > > ```
> > > > 
> > > > 
> > > I'm not sure I understand the question. Are you saying that a separate 
> > > `install()` for the 'bits' is not necessary and we could just install all 
> > > headers with a single `install` above?
> > > 
> > > If that's the case, then, AFAICT, the answer is that we do need a 
> > > separate `install`. 
> > > `install(FILES)` does not preserve the directory structure and dumps all 
> > > files listed in `FILES`, regardless if they are in different directories 
> > > into the same DESTINATION directory.
> > > That is exactly the problem this patch is intended to fix. We do need to 
> > > place the file under `cuda_wrappers/bits/` directory and that's why we 
> > > have separate `install(DESTINATION 
> > > ${header_install_dir}/cuda_wrappers/bits)` here.
> > > 
> > > `install(DIRECTORY)` would presumably preserve the source directory 
> > > structure, but we lose per-file granularity. It may work for the files 
> > > under cuda_wrappers for now, but I think there's some merit in explicitly 
> > > controlling which headers we ship and where we put them. While we do have 
> > > 1:1 mapping between the source tree and install tree, it may not always 
> > > be the case.
> > > 
> > > 
> > > 
> > Ah sorry for the confusion. 
> > 
> > > Are you saying that a separate install() for the 'bits' is not necessary 
> > > and we could just install all headers with a single install above?
> > 
> > No I am trying to say the opposite. I am suggesting we //add// the separate 
> > install target as a component of `clang-resource-headers` //and// as a 
> > component of `cuda-resource-headers`, as shown in the code change suggested 
> > in the comment above. I am not suggesting any code form this patch to be 
> > removed. The `cuda-resource-headers` can be used to install the cuda 
> > related headers only, in the case when a user do not want to install all 
> > the headers (e.g. if a user only want to install support for Intel and 
> > Nvidia headers, but not the PowerPC headers, the user can select 
> > `core-resource-headers`, `x86_files` and `cuda-resource-headers` during a 
> > distribution build/install). I think without the code change suggested 
> > above, if a user select to install `cuda-resource-headers` only without 
> > specifying `clang-resource-headers`, we will miss the file 
> > `cuda_wrappers/bits/shared_ptr_base.h`. 
> Sorry I made a typo in the previous comment. I meant `x86-resource-headers` 
> when I said `x86_files`. 
I think understand now.
`cmake -DCOMPONENT=cuda-resource-headers -P ./cmake_install.cmake` indeed does 
not install the bits component.

I've added the install with `COMPONENT clang-resource-headers` and verified 
that the bits header is installed during individual component installation.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151503

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


[PATCH] D151503: [CUDA] correctly install cuda_wrappers/bits/shared_ptr_base.h

2023-05-26 Thread Artem Belevich via Phabricator via cfe-commits
tra updated this revision to Diff 526227.
tra added a comment.

Verified that install works correctly with
individual component installations:

  cmake -DCOMPONENT=cuda-resource-headers -P ./cmake_install.cmake
  cmake -DCOMPONENT=clang-resource-headers -P ./cmake_install.cmake


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151503

Files:
  clang/lib/Headers/CMakeLists.txt


Index: clang/lib/Headers/CMakeLists.txt
===
--- clang/lib/Headers/CMakeLists.txt
+++ clang/lib/Headers/CMakeLists.txt
@@ -267,6 +267,9 @@
   cuda_wrappers/cmath
   cuda_wrappers/complex
   cuda_wrappers/new
+)
+
+set(cuda_wrapper_bits_files
   cuda_wrappers/bits/shared_ptr_base.h
 )
 
@@ -328,7 +331,8 @@
 
 
 # Copy header files from the source directory to the build directory
-foreach( f ${files} ${cuda_wrapper_files} ${ppc_wrapper_files} 
${openmp_wrapper_files} ${hlsl_files})
+foreach( f ${files} ${cuda_wrapper_files} ${cuda_wrapper_bits_files}
+   ${ppc_wrapper_files} ${openmp_wrapper_files} ${hlsl_files})
   copy_header_to_output_dir(${CMAKE_CURRENT_SOURCE_DIR} ${f})
 endforeach( f )
 
@@ -405,6 +409,7 @@
  "arm-resource-headers"
  "aarch64-resource-headers"
  "cuda-resource-headers"
+ "cuda-resource-bits-headers"
  "hexagon-resource-headers"
  "hip-resource-headers"
  "hlsl-resource-headers"
@@ -429,7 +434,8 @@
 # Architecture/platform specific targets
 add_header_target("arm-resource-headers" 
"${arm_only_files};${arm_only_generated_files}")
 add_header_target("aarch64-resource-headers" 
"${aarch64_only_files};${aarch64_only_generated_files}")
-add_header_target("cuda-resource-headers" 
"${cuda_files};${cuda_wrapper_files}")
+add_header_target("cuda-resource-headers" 
"${cuda_files};${cuda_wrapper_files};${cuda_wrapper_bits_files}")
+add_header_target("cuda-resource-bits-headers" "${cuda_wrapper_bits_files}")
 add_header_target("hexagon-resource-headers" "${hexagon_files}")
 add_header_target("hip-resource-headers" "${hip_files}")
 add_header_target("loongarch-resource-headers" "${loongarch_files}")
@@ -463,6 +469,11 @@
   DESTINATION ${header_install_dir}/cuda_wrappers
   COMPONENT clang-resource-headers)
 
+install(
+  FILES ${cuda_wrapper_bits_files}
+  DESTINATION ${header_install_dir}/cuda_wrappers/bits
+  COMPONENT clang-resource-headers)
+
 install(
   FILES ${ppc_wrapper_files}
   DESTINATION ${header_install_dir}/ppc_wrappers
@@ -505,6 +516,12 @@
   EXCLUDE_FROM_ALL
   COMPONENT cuda-resource-headers)
 
+install(
+  FILES ${cuda_wrapper_bits_files}
+  DESTINATION ${header_install_dir}/cuda_wrappers/bits
+  EXCLUDE_FROM_ALL
+  COMPONENT cuda-resource-headers)
+
 install(
   FILES ${cuda_files}
   DESTINATION ${header_install_dir}
@@ -650,6 +667,9 @@
   add_llvm_install_targets(install-cuda-resource-headers
DEPENDS cuda-resource-headers
COMPONENT cuda-resource-headers)
+  add_llvm_install_targets(install-cuda-resource-bits-headers
+   DEPENDS cuda-resource-bits-headers
+   COMPONENT cuda-resource-headers)
   add_llvm_install_targets(install-hexagon-resource-headers
DEPENDS hexagon-resource-headers
COMPONENT hexagon-resource-headers)


Index: clang/lib/Headers/CMakeLists.txt
===
--- clang/lib/Headers/CMakeLists.txt
+++ clang/lib/Headers/CMakeLists.txt
@@ -267,6 +267,9 @@
   cuda_wrappers/cmath
   cuda_wrappers/complex
   cuda_wrappers/new
+)
+
+set(cuda_wrapper_bits_files
   cuda_wrappers/bits/shared_ptr_base.h
 )
 
@@ -328,7 +331,8 @@
 
 
 # Copy header files from the source directory to the build directory
-foreach( f ${files} ${cuda_wrapper_files} ${ppc_wrapper_files} ${openmp_wrapper_files} ${hlsl_files})
+foreach( f ${files} ${cuda_wrapper_files} ${cuda_wrapper_bits_files}
+   ${ppc_wrapper_files} ${openmp_wrapper_files} ${hlsl_files})
   copy_header_to_output_dir(${CMAKE_CURRENT_SOURCE_DIR} ${f})
 endforeach( f )
 
@@ -405,6 +409,7 @@
  "arm-resource-headers"
  "aarch64-resource-headers"
  "cuda-resource-headers"
+ "cuda-resource-bits-headers"
  "hexagon-resource-headers"
  "hip-resource-headers"
  "hlsl-resource-headers"
@@ -429,7 +434,8 @@
 # Architecture/platform specific targets
 add_header_target("arm-resource-headers" "${arm_only_files};${arm_only_generated_files}")
 add_header_target("aarch64-resource-headers" "${aarch64_only_files};${aarch64_only_generated_files}")
-add_header_target("cuda-resource-headers" "${cuda_files};${cuda_wrapper_files}")
+add_header_target("cuda-resource-headers" 

[clang] f354e97 - [MemProf] Clean up MemProf instrumentation pass invocation

2023-05-26 Thread Teresa Johnson via cfe-commits

Author: Teresa Johnson
Date: 2023-05-26T17:38:49-07:00
New Revision: f354e971b09c244147ff59eb65b34487755598c0

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

LOG: [MemProf] Clean up MemProf instrumentation pass invocation

First, removes the invocation of the memprof instrumentation passes from
the end of the module simplification pass builder, where it doesn't
really belong. However, it turns out that this was never being invoked,
as it is guarded by an internal option not used anywhere (even tests).

These passes are actually added via clang under the -fmemory-profile
option. Changed this to add via the EP callback interface, similar to
the sanitizer passes. They are added to the EP for the end of the
optimization pipeline, which is roughly where they were being added
already (end of the pre-LTO link pipelines and non-LTO optimization
pipeline).

Ideally we should plumb the output file through to LLVM and set it up
there, so I have added a TODO.

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

Added: 


Modified: 
clang/lib/CodeGen/BackendUtil.cpp
llvm/lib/Passes/PassBuilderPipelines.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index d62d00a156f1c..d4498ebaf8dea 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -992,6 +992,16 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
 MPM.addPass(InstrProfiling(*Options, false));
   });
 
+// TODO: Consider passing the MemoryProfileOutput to the pass builder via
+// the PGOOptions, and set this up there.
+if (!CodeGenOpts.MemoryProfileOutput.empty()) {
+  PB.registerOptimizerLastEPCallback(
+  [](ModulePassManager , OptimizationLevel Level) {
+MPM.addPass(createModuleToFunctionPassAdaptor(MemProfilerPass()));
+MPM.addPass(ModuleMemProfilerPass());
+  });
+}
+
 if (IsThinLTO) {
   MPM = PB.buildThinLTOPreLinkDefaultPipeline(Level);
 } else if (IsLTO) {
@@ -999,11 +1009,6 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
 } else {
   MPM = PB.buildPerModuleDefaultPipeline(Level);
 }
-
-if (!CodeGenOpts.MemoryProfileOutput.empty()) {
-  MPM.addPass(createModuleToFunctionPassAdaptor(MemProfilerPass()));
-  MPM.addPass(ModuleMemProfilerPass());
-}
   }
 
   // Add a verifier pass if requested. We don't have to do this if the action

diff  --git a/llvm/lib/Passes/PassBuilderPipelines.cpp 
b/llvm/lib/Passes/PassBuilderPipelines.cpp
index 05bb4596b988c..34d3b9d7467e8 100644
--- a/llvm/lib/Passes/PassBuilderPipelines.cpp
+++ b/llvm/lib/Passes/PassBuilderPipelines.cpp
@@ -155,9 +155,6 @@ static cl::opt
 cl::Hidden,
 cl::desc("Enable inline deferral during PGO"));
 
-static cl::opt EnableMemProfiler("enable-mem-prof", cl::Hidden,
-   cl::desc("Enable memory profiler"));
-
 static cl::opt EnableModuleInliner("enable-module-inliner",
  cl::init(false), cl::Hidden,
  cl::desc("Enable module inliner"));
@@ -1122,11 +1119,6 @@ 
PassBuilder::buildModuleSimplificationPipeline(OptimizationLevel Level,
   MPM.addPass(GlobalOptPass());
   MPM.addPass(GlobalDCEPass());
 
-  if (EnableMemProfiler && Phase != ThinOrFullLTOPhase::ThinLTOPreLink) {
-MPM.addPass(createModuleToFunctionPassAdaptor(MemProfilerPass()));
-MPM.addPass(ModuleMemProfilerPass());
-  }
-
   return MPM;
 }
 



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


[PATCH] D151593: [MemProf] Clean up MemProf instrumentation pass invocation

2023-05-26 Thread Teresa Johnson via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf354e971b09c: [MemProf] Clean up MemProf instrumentation 
pass invocation (authored by tejohnson).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151593

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  llvm/lib/Passes/PassBuilderPipelines.cpp


Index: llvm/lib/Passes/PassBuilderPipelines.cpp
===
--- llvm/lib/Passes/PassBuilderPipelines.cpp
+++ llvm/lib/Passes/PassBuilderPipelines.cpp
@@ -155,9 +155,6 @@
 cl::Hidden,
 cl::desc("Enable inline deferral during PGO"));
 
-static cl::opt EnableMemProfiler("enable-mem-prof", cl::Hidden,
-   cl::desc("Enable memory profiler"));
-
 static cl::opt EnableModuleInliner("enable-module-inliner",
  cl::init(false), cl::Hidden,
  cl::desc("Enable module inliner"));
@@ -1122,11 +1119,6 @@
   MPM.addPass(GlobalOptPass());
   MPM.addPass(GlobalDCEPass());
 
-  if (EnableMemProfiler && Phase != ThinOrFullLTOPhase::ThinLTOPreLink) {
-MPM.addPass(createModuleToFunctionPassAdaptor(MemProfilerPass()));
-MPM.addPass(ModuleMemProfilerPass());
-  }
-
   return MPM;
 }
 
Index: clang/lib/CodeGen/BackendUtil.cpp
===
--- clang/lib/CodeGen/BackendUtil.cpp
+++ clang/lib/CodeGen/BackendUtil.cpp
@@ -992,6 +992,16 @@
 MPM.addPass(InstrProfiling(*Options, false));
   });
 
+// TODO: Consider passing the MemoryProfileOutput to the pass builder via
+// the PGOOptions, and set this up there.
+if (!CodeGenOpts.MemoryProfileOutput.empty()) {
+  PB.registerOptimizerLastEPCallback(
+  [](ModulePassManager , OptimizationLevel Level) {
+MPM.addPass(createModuleToFunctionPassAdaptor(MemProfilerPass()));
+MPM.addPass(ModuleMemProfilerPass());
+  });
+}
+
 if (IsThinLTO) {
   MPM = PB.buildThinLTOPreLinkDefaultPipeline(Level);
 } else if (IsLTO) {
@@ -999,11 +1009,6 @@
 } else {
   MPM = PB.buildPerModuleDefaultPipeline(Level);
 }
-
-if (!CodeGenOpts.MemoryProfileOutput.empty()) {
-  MPM.addPass(createModuleToFunctionPassAdaptor(MemProfilerPass()));
-  MPM.addPass(ModuleMemProfilerPass());
-}
   }
 
   // Add a verifier pass if requested. We don't have to do this if the action


Index: llvm/lib/Passes/PassBuilderPipelines.cpp
===
--- llvm/lib/Passes/PassBuilderPipelines.cpp
+++ llvm/lib/Passes/PassBuilderPipelines.cpp
@@ -155,9 +155,6 @@
 cl::Hidden,
 cl::desc("Enable inline deferral during PGO"));
 
-static cl::opt EnableMemProfiler("enable-mem-prof", cl::Hidden,
-   cl::desc("Enable memory profiler"));
-
 static cl::opt EnableModuleInliner("enable-module-inliner",
  cl::init(false), cl::Hidden,
  cl::desc("Enable module inliner"));
@@ -1122,11 +1119,6 @@
   MPM.addPass(GlobalOptPass());
   MPM.addPass(GlobalDCEPass());
 
-  if (EnableMemProfiler && Phase != ThinOrFullLTOPhase::ThinLTOPreLink) {
-MPM.addPass(createModuleToFunctionPassAdaptor(MemProfilerPass()));
-MPM.addPass(ModuleMemProfilerPass());
-  }
-
   return MPM;
 }
 
Index: clang/lib/CodeGen/BackendUtil.cpp
===
--- clang/lib/CodeGen/BackendUtil.cpp
+++ clang/lib/CodeGen/BackendUtil.cpp
@@ -992,6 +992,16 @@
 MPM.addPass(InstrProfiling(*Options, false));
   });
 
+// TODO: Consider passing the MemoryProfileOutput to the pass builder via
+// the PGOOptions, and set this up there.
+if (!CodeGenOpts.MemoryProfileOutput.empty()) {
+  PB.registerOptimizerLastEPCallback(
+  [](ModulePassManager , OptimizationLevel Level) {
+MPM.addPass(createModuleToFunctionPassAdaptor(MemProfilerPass()));
+MPM.addPass(ModuleMemProfilerPass());
+  });
+}
+
 if (IsThinLTO) {
   MPM = PB.buildThinLTOPreLinkDefaultPipeline(Level);
 } else if (IsLTO) {
@@ -999,11 +1009,6 @@
 } else {
   MPM = PB.buildPerModuleDefaultPipeline(Level);
 }
-
-if (!CodeGenOpts.MemoryProfileOutput.empty()) {
-  MPM.addPass(createModuleToFunctionPassAdaptor(MemProfilerPass()));
-  MPM.addPass(ModuleMemProfilerPass());
-}
   }
 
   // Add a verifier pass if requested. We don't have to do this if the action
___
cfe-commits mailing list
cfe-commits@lists.llvm.org

[PATCH] D144911: adding bf16 support to NVPTX

2023-05-26 Thread Artem Belevich via Phabricator via cfe-commits
tra added a comment.

Here's a rough proof-of-concept patch coalescing i16/f16/bf16 to use the same 
Int16Regs register class: https://reviews.llvm.org/D151601

The changes are largely mechanical, replacing `%h` -> `%rs` in the tests and 
eliminating special cases we previously had for Float16Registers. I'll extend 
the patch to v2f16/Int32Regs next week.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144911

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


[PATCH] D151576: Fix runtime crash inside __kmpc_init_allocator

2023-05-26 Thread Ron Lieberman via Phabricator via cfe-commits
ronlieb added a comment.

apologies, i just realized its a new test that you xfailed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151576

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


[PATCH] D151576: Fix runtime crash inside __kmpc_init_allocator

2023-05-26 Thread Ron Lieberman via Phabricator via cfe-commits
ronlieb added a comment.

i think the extra two failures are not related to you patch. so ignore  comment 
about these
libomptarget :: amdgcn-amd-amdhsa :: jit/empty_kernel_lvl1.c
libomptarget :: amdgcn-amd-amdhsa :: jit/empty_kernel_lvl2.c


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151576

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


[PATCH] D151503: [CUDA] correctly install cuda_wrappers/bits/shared_ptr_base.h

2023-05-26 Thread Qiongsi Wu via Phabricator via cfe-commits
qiongsiwu1 added inline comments.



Comment at: clang/lib/Headers/CMakeLists.txt:516
   COMPONENT cuda-resource-headers)
 
 install(

qiongsiwu1 wrote:
> tra wrote:
> > qiongsiwu1 wrote:
> > > Do we need an install target for `${cuda_wrapper_bits_files}` for the 
> > > `cuda-resource-headers` component as well? It seems to be the case 
> > > because this patch is treating `${cuda_wrapper_bits_files}` as part of 
> > > `cuda-resource-headers`.
> > > 
> > > ```
> > > add_header_target("cuda-resource-headers" 
> > > "${cuda_files};${cuda_wrapper_files};${cuda_wrapper_bits_files}")
> > > ```
> > > 
> > > 
> > I'm not sure I understand the question. Are you saying that a separate 
> > `install()` for the 'bits' is not necessary and we could just install all 
> > headers with a single `install` above?
> > 
> > If that's the case, then, AFAICT, the answer is that we do need a separate 
> > `install`. 
> > `install(FILES)` does not preserve the directory structure and dumps all 
> > files listed in `FILES`, regardless if they are in different directories 
> > into the same DESTINATION directory.
> > That is exactly the problem this patch is intended to fix. We do need to 
> > place the file under `cuda_wrappers/bits/` directory and that's why we have 
> > separate `install(DESTINATION ${header_install_dir}/cuda_wrappers/bits)` 
> > here.
> > 
> > `install(DIRECTORY)` would presumably preserve the source directory 
> > structure, but we lose per-file granularity. It may work for the files 
> > under cuda_wrappers for now, but I think there's some merit in explicitly 
> > controlling which headers we ship and where we put them. While we do have 
> > 1:1 mapping between the source tree and install tree, it may not always be 
> > the case.
> > 
> > 
> > 
> Ah sorry for the confusion. 
> 
> > Are you saying that a separate install() for the 'bits' is not necessary 
> > and we could just install all headers with a single install above?
> 
> No I am trying to say the opposite. I am suggesting we //add// the separate 
> install target as a component of `clang-resource-headers` //and// as a 
> component of `cuda-resource-headers`, as shown in the code change suggested 
> in the comment above. I am not suggesting any code form this patch to be 
> removed. The `cuda-resource-headers` can be used to install the cuda related 
> headers only, in the case when a user do not want to install all the headers 
> (e.g. if a user only want to install support for Intel and Nvidia headers, 
> but not the PowerPC headers, the user can select `core-resource-headers`, 
> `x86_files` and `cuda-resource-headers` during a distribution build/install). 
> I think without the code change suggested above, if a user select to install 
> `cuda-resource-headers` only without specifying `clang-resource-headers`, we 
> will miss the file `cuda_wrappers/bits/shared_ptr_base.h`. 
Sorry I made a typo in the previous comment. I meant `x86-resource-headers` 
when I said `x86_files`. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151503

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


[PATCH] D151503: [CUDA] correctly install cuda_wrappers/bits/shared_ptr_base.h

2023-05-26 Thread Qiongsi Wu via Phabricator via cfe-commits
qiongsiwu1 added inline comments.



Comment at: clang/lib/Headers/CMakeLists.txt:516
   COMPONENT cuda-resource-headers)
 
 install(

tra wrote:
> qiongsiwu1 wrote:
> > Do we need an install target for `${cuda_wrapper_bits_files}` for the 
> > `cuda-resource-headers` component as well? It seems to be the case because 
> > this patch is treating `${cuda_wrapper_bits_files}` as part of 
> > `cuda-resource-headers`.
> > 
> > ```
> > add_header_target("cuda-resource-headers" 
> > "${cuda_files};${cuda_wrapper_files};${cuda_wrapper_bits_files}")
> > ```
> > 
> > 
> I'm not sure I understand the question. Are you saying that a separate 
> `install()` for the 'bits' is not necessary and we could just install all 
> headers with a single `install` above?
> 
> If that's the case, then, AFAICT, the answer is that we do need a separate 
> `install`. 
> `install(FILES)` does not preserve the directory structure and dumps all 
> files listed in `FILES`, regardless if they are in different directories into 
> the same DESTINATION directory.
> That is exactly the problem this patch is intended to fix. We do need to 
> place the file under `cuda_wrappers/bits/` directory and that's why we have 
> separate `install(DESTINATION ${header_install_dir}/cuda_wrappers/bits)` here.
> 
> `install(DIRECTORY)` would presumably preserve the source directory 
> structure, but we lose per-file granularity. It may work for the files under 
> cuda_wrappers for now, but I think there's some merit in explicitly 
> controlling which headers we ship and where we put them. While we do have 1:1 
> mapping between the source tree and install tree, it may not always be the 
> case.
> 
> 
> 
Ah sorry for the confusion. 

> Are you saying that a separate install() for the 'bits' is not necessary and 
> we could just install all headers with a single install above?

No I am trying to say the opposite. I am suggesting we //add// the separate 
install target as a component of `clang-resource-headers` //and// as a 
component of `cuda-resource-headers`, as shown in the code change suggested in 
the comment above. I am not suggesting any code form this patch to be removed. 
The `cuda-resource-headers` can be used to install the cuda related headers 
only, in the case when a user do not want to install all the headers (e.g. if a 
user only want to install support for Intel and Nvidia headers, but not the 
PowerPC headers, the user can select `core-resource-headers`, `x86_files` and 
`cuda-resource-headers` during a distribution build/install). I think without 
the code change suggested above, if a user select to install 
`cuda-resource-headers` only without specifying `clang-resource-headers`, we 
will miss the file `cuda_wrappers/bits/shared_ptr_base.h`. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151503

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


[PATCH] D151576: Fix runtime crash inside __kmpc_init_allocator

2023-05-26 Thread Ron Lieberman via Phabricator via cfe-commits
ronlieb added a comment.

observing failure in our amdgpu buildbot , 3 tests
see: https://lab.llvm.org/staging/#/builders/247/builds/947

7: __tgt_target_table *__tgt_rtl_load_binary(int32_t, __tgt_device_image *): 
Assertion `Table != nullptr && "Invalid table"' failed.

if you have a quick fix, please apply, otherwise please revert and fix.
if you need someone to work with on our end, let me know.

also , i see you marked one test unsupported, but it seems like it should be 
reported.
please consult with us to see if there is a better solution than instantly 
xfailing the test.

also i see two additional failures

  libomptarget :: amdgcn-amd-amdhsa :: jit/empty_kernel_lvl1.c
  libomptarget :: amdgcn-amd-amdhsa :: jit/empty_kernel_lvl2.c


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151576

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


[PATCH] D151578: [Format/ObjC] Support NS_ASSUME_NONNULL_BEGIN and FOUNDATION_EXPORT in ObjC language guesser

2023-05-26 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay accepted this revision.
MyDeveloperDay added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151578

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


[PATCH] D151593: [MemProf] Clean up MemProf instrumentation pass invocation

2023-05-26 Thread Snehasish Kumar via Phabricator via cfe-commits
snehasish accepted this revision.
snehasish added a comment.

lgtm


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151593

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


[PATCH] D144911: adding bf16 support to NVPTX

2023-05-26 Thread Artem Belevich via Phabricator via cfe-commits
tra added inline comments.



Comment at: llvm/include/llvm/IR/IntrinsicsNVVM.td:604
   def int_nvvm_f # operation # variant :
 ClangBuiltin,
 DefaultAttrsIntrinsic<[llvm_i16_ty], [llvm_i16_ty, llvm_i16_ty],

tra wrote:
> Availability of these new instructions is conditional on specific CUDA 
> version and the GPU variant we're compiling for,
> Such builtins are normally implemented on the clang size as a 
> `TARGET_BUILTIN()` with appropriate constraints.
> 
> Without that `ClangBuiltin` may automatically add enough glue to make them 
> available in clang unconditionally, which would result in compiler crashing 
> if a user tries to use one of those builtins with a wrong GPU or CUDA 
> version. We want to emit a diagnostics, not cause a compiler crash.
> 
> Usually such related LLVM and clang changes should be part of the same patch.
> 
> This applies to the new intrinsic variants added below, too.
I do not think it's is done. 

Can you check what happens if you try to call any of bf16 builtins while 
compiling for sm_60? Ideally we should produce a sensible error that the 
builtin is not available.

I suspect we will fail in LLVM when we'll fail to lower the intrinsic, ot in 
nvptx if we've managed to lower it to an instruction unsupported by sm_60.



Comment at: llvm/lib/Target/NVPTX/NVPTXISelDAGToDAG.cpp:1297-1304
 if (EltVT == MVT::f16 && N->getValueType(0) == MVT::v2f16) {
   assert(NumElts % 2 == 0 && "Vector must have even number of elements");
   EltVT = MVT::v2f16;
   NumElts /= 2;
+} else if (EltVT == MVT::bf16 && N->getValueType(0) == MVT::v2bf16) {
+  assert(NumElts % 2 == 0 && "Vector must have even number of elements");
+  EltVT = MVT::v2bf16;

These could be collapsed into 
```
if ((EltVT == MVT::f16 && N->getValueType(0) == MVT::v2f16) || 
 (EltVT == MVT::bf16 && N->getValueType(0) == MVT::v2bf16) ) {
  assert(NumElts % 2 == 0 && "Vector must have even number of elements");
  EltVT = N->getValueType(0);
  NumElts /= 2;
}
```



Comment at: llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp:147-153
+  switch (VT.SimpleTy) {
+  default:
+return false;
+  case MVT::v2f16:
+  case MVT::v2bf16:
+return true;
+  }

It can be simplified to just `return (VT.SimpleTy == MVT::v2f16 || VT.SimpleTy 
== MVT::v2bf16);`




Comment at: llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp:156
+
+static bool Isf16Orbf16Type(MVT VT) {
+  switch (VT.SimpleTy) {

ditto.



Comment at: llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp:623
 
+  for (const auto  : {ISD::FADD, ISD::FMUL, ISD::FSUB, ISD::FMA}) {
+setBF16OperationAction(Op, MVT::bf16, Legal, Promote);

Fold it into the loop above.



Comment at: llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp:699
   }
+  for (const auto  : {ISD::FMINNUM, ISD::FMAXNUM}) {
+setBF16OperationAction(Op, MVT::bf16, GetMinMaxAction(Promote), Promote);

Fold into the loop processing `{ISD::FMINNUM, ISD::FMAXNUM}` above.

Also, do we want/need to add bf16 handling for `{ISD::FMINIMUM, ISD::FMAXIMUM}` 
too?

The LLVM's choice of constants `FMINIMUM` vs `FMINNUM` is rather unfortunate -- 
it's so easy to misread one for another.



Comment at: llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp:700-703
+setBF16OperationAction(Op, MVT::bf16, GetMinMaxAction(Promote), Promote);
+setBF16OperationAction(Op, MVT::v2bf16, GetMinMaxAction(Expand), Expand);
+setBF16OperationAction(Op, MVT::bf16, GetMinMaxAction(Expand), Expand);
+setBF16OperationAction(Op, MVT::v2bf16, GetMinMaxAction(Expand), Expand);

I'm not sure what's going on here. Should it be Promote for bf16 and Expand for 
v2bf16? Why do we have two other entries, one of them trying to Expand bf16?



Comment at: llvm/lib/Target/NVPTX/NVPTXRegisterInfo.td:65-66
+def Float16x2Regs : NVPTXRegClass<[v2f16], 32, (add (sequence "HH%u", 0, 4))>;
+def BFloat16Regs : NVPTXRegClass<[bf16], 16, (add (sequence "H%u", 0, 4))>;
+def BFloat16x2Regs : NVPTXRegClass<[v2bf16], 32, (add (sequence "HH%u", 0, 
4))>;
 def Float32Regs : NVPTXRegClass<[f32], 32, (add (sequence "F%u", 0, 4))>;

I suspect this may be a problem.

What PTX do we end up generating if we have a function that needs to use both 
f16 and bf16 registers? I suspect we may end up with defining conflicting sets 
of registers.

I still do not think that we need a spearate register class for bf16 and both 
bf16 and fp16 should be using a generic opaque 16/32 bit register types (or, 
even better, generic Int16/Int32 registers. 

RegClass accepts multiple type values, so it may be as simple as using `def 
Int16Regs : NVPTXRegClass<[i16,f16,bf16], 16, (add (sequence "RS%u", 0, 4))>;` 
and adjusting existing use cases.

That should probably be done as a separate 

[clang] a419ec4 - Fix runtime crash inside __kmpc_init_allocator

2023-05-26 Thread Jennifer Yu via cfe-commits

Author: Jennifer Yu
Date: 2023-05-26T16:03:01-07:00
New Revision: a419ec4f256d279c91746a3962dd6dd2da45c304

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

LOG: Fix runtime crash inside __kmpc_init_allocator

It seems load of traits.addr should be passed in runtime call.  Currently
the load of load traits.addr gets passed cause runtime to fail.

To fix this, skip the call to EmitLoadOfScalar for extra load.

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

Added: 
openmp/libomptarget/test/mapping/target_uses_allocator.c

Modified: 
clang/lib/CodeGen/CGOpenMPRuntime.cpp
clang/test/OpenMP/target_parallel_for_simd_uses_allocators_codegen.cpp
clang/test/OpenMP/target_parallel_for_uses_allocators_codegen.cpp
clang/test/OpenMP/target_parallel_uses_allocators_codegen.cpp
clang/test/OpenMP/target_simd_uses_allocators_codegen.cpp

clang/test/OpenMP/target_teams_distribute_parallel_for_simd_uses_allocators_codegen.cpp

clang/test/OpenMP/target_teams_distribute_parallel_for_uses_allocators_codegen.cpp
clang/test/OpenMP/target_teams_distribute_simd_uses_allocators_codegen.cpp
clang/test/OpenMP/target_teams_distribute_uses_allocators_codegen.cpp
clang/test/OpenMP/target_teams_uses_allocators_codegen.cpp
clang/test/OpenMP/target_uses_allocators.c
clang/test/OpenMP/target_uses_allocators_codegen.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index ff6d1d4ed869f..1f1db83378233 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -6034,8 +6034,7 @@ void 
CGOpenMPRuntime::emitUsesAllocatorsInit(CodeGenFunction ,
   AllocatorTraitsLVal = CGF.MakeAddrLValue(Addr, CGF.getContext().VoidPtrTy,
AllocatorTraitsLVal.getBaseInfo(),
AllocatorTraitsLVal.getTBAAInfo());
-  llvm::Value *Traits =
-  CGF.EmitLoadOfScalar(AllocatorTraitsLVal, AllocatorTraits->getExprLoc());
+  llvm::Value *Traits = Addr.getPointer();
 
   llvm::Value *AllocatorVal =
   CGF.EmitRuntimeCall(OMPBuilder.getOrCreateRuntimeFunction(

diff  --git 
a/clang/test/OpenMP/target_parallel_for_simd_uses_allocators_codegen.cpp 
b/clang/test/OpenMP/target_parallel_for_simd_uses_allocators_codegen.cpp
index 2bcd9e7221f4d..c471c3c78cf30 100644
--- a/clang/test/OpenMP/target_parallel_for_simd_uses_allocators_codegen.cpp
+++ b/clang/test/OpenMP/target_parallel_for_simd_uses_allocators_codegen.cpp
@@ -79,8 +79,7 @@ void foo() {
 // CHECK: [[TRAITS_ADDR_REF:%.+]] = alloca ptr,
 // CHECK: [[MY_ALLOCATOR_ADDR:%.+]] = alloca i64,
 // CHECK: [[TRAITS_ADDR:%.+]] = load ptr, ptr [[TRAITS_ADDR_REF]],
-// CHECK: [[TRAITS:%.+]] = load ptr, ptr [[TRAITS_ADDR]],
-// CHECK: [[ALLOCATOR:%.+]] = call ptr @__kmpc_init_allocator(i32 %{{.+}}, ptr 
null, i32 10, ptr [[TRAITS]])
+// CHECK: [[ALLOCATOR:%.+]] = call ptr @__kmpc_init_allocator(i32 %{{.+}}, ptr 
null, i32 10, ptr [[TRAITS_ADDR]])
 // CHECK: [[CONV:%.+]] = ptrtoint ptr [[ALLOCATOR]] to i64
 // CHECK: store i64 [[CONV]], ptr [[MY_ALLOCATOR_ADDR]],
 

diff  --git a/clang/test/OpenMP/target_parallel_for_uses_allocators_codegen.cpp 
b/clang/test/OpenMP/target_parallel_for_uses_allocators_codegen.cpp
index 03a5f9f3b7287..3a11323ee2d6d 100644
--- a/clang/test/OpenMP/target_parallel_for_uses_allocators_codegen.cpp
+++ b/clang/test/OpenMP/target_parallel_for_uses_allocators_codegen.cpp
@@ -79,8 +79,7 @@ void foo() {
 // CHECK: [[TRAITS_ADDR_REF:%.+]] = alloca ptr,
 // CHECK: [[MY_ALLOCATOR_ADDR:%.+]] = alloca i64,
 // CHECK: [[TRAITS_ADDR:%.+]] = load ptr, ptr [[TRAITS_ADDR_REF]],
-// CHECK: [[TRAITS:%.+]] = load ptr, ptr [[TRAITS_ADDR]],
-// CHECK: [[ALLOCATOR:%.+]] = call ptr @__kmpc_init_allocator(i32 %{{.+}}, ptr 
null, i32 10, ptr [[TRAITS]])
+// CHECK: [[ALLOCATOR:%.+]] = call ptr @__kmpc_init_allocator(i32 %{{.+}}, ptr 
null, i32 10, ptr [[TRAITS_ADDR]])
 // CHECK: [[CONV:%.+]] = ptrtoint ptr [[ALLOCATOR]] to i64
 // CHECK: store i64 [[CONV]], ptr [[MY_ALLOCATOR_ADDR]],
 

diff  --git a/clang/test/OpenMP/target_parallel_uses_allocators_codegen.cpp 
b/clang/test/OpenMP/target_parallel_uses_allocators_codegen.cpp
index faa44d2da50bd..51c5f9219c6c4 100644
--- a/clang/test/OpenMP/target_parallel_uses_allocators_codegen.cpp
+++ b/clang/test/OpenMP/target_parallel_uses_allocators_codegen.cpp
@@ -78,8 +78,7 @@ void foo() {
 // CHECK: [[TRAITS_ADDR_REF:%.+]] = alloca ptr,
 // CHECK: [[MY_ALLOCATOR_ADDR:%.+]] = alloca i64,
 // CHECK: [[TRAITS_ADDR:%.+]] = load ptr, ptr [[TRAITS_ADDR_REF]],
-// CHECK: [[TRAITS:%.+]] = load ptr, ptr [[TRAITS_ADDR]],
-// CHECK: [[ALLOCATOR:%.+]] = call ptr @__kmpc_init_allocator(i32 %{{.+}}, ptr 
null, i32 10, ptr [[TRAITS]])
+// 

[PATCH] D151576: Fix runtime crash inside __kmpc_init_allocator

2023-05-26 Thread Jennifer Yu via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa419ec4f256d: Fix runtime crash inside __kmpc_init_allocator 
(authored by jyu2).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151576

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/test/OpenMP/target_parallel_for_simd_uses_allocators_codegen.cpp
  clang/test/OpenMP/target_parallel_for_uses_allocators_codegen.cpp
  clang/test/OpenMP/target_parallel_uses_allocators_codegen.cpp
  clang/test/OpenMP/target_simd_uses_allocators_codegen.cpp
  
clang/test/OpenMP/target_teams_distribute_parallel_for_simd_uses_allocators_codegen.cpp
  
clang/test/OpenMP/target_teams_distribute_parallel_for_uses_allocators_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_simd_uses_allocators_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_uses_allocators_codegen.cpp
  clang/test/OpenMP/target_teams_uses_allocators_codegen.cpp
  clang/test/OpenMP/target_uses_allocators.c
  clang/test/OpenMP/target_uses_allocators_codegen.cpp
  openmp/libomptarget/test/mapping/target_uses_allocator.c

Index: openmp/libomptarget/test/mapping/target_uses_allocator.c
===
--- /dev/null
+++ openmp/libomptarget/test/mapping/target_uses_allocator.c
@@ -0,0 +1,56 @@
+// RUN: %libomptarget-compile-run-and-check-generic
+
+#include 
+#include 
+
+#define N 1024
+
+int test_omp_aligned_alloc_on_device() {
+  int errors = 0;
+
+  omp_memspace_handle_t memspace = omp_default_mem_space;
+  omp_alloctrait_t traits[2] = {{omp_atk_alignment, 64}, {omp_atk_access, 64}};
+  omp_allocator_handle_t alloc =
+  omp_init_allocator(omp_default_mem_space, 1, traits);
+
+#pragma omp target map(tofrom : errors) uses_allocators(alloc(traits))
+  {
+int *x;
+int not_correct_array_values = 0;
+
+x = (int *)omp_aligned_alloc(64, N * sizeof(int), alloc);
+if (x == NULL) {
+  errors++;
+} else {
+#pragma omp parallel for simd simdlen(16) aligned(x : 64)
+  for (int i = 0; i < N; i++) {
+x[i] = i;
+  }
+
+#pragma omp parallel for simd simdlen(16) aligned(x : 64)
+  for (int i = 0; i < N; i++) {
+if (x[i] != i) {
+#pragma omp atomic write
+  not_correct_array_values = 1;
+}
+  }
+  if (not_correct_array_values) {
+errors++;
+  }
+  omp_free(x, alloc);
+}
+  }
+
+  omp_destroy_allocator(alloc);
+
+  return errors;
+}
+
+int main() {
+  int errors = 0;
+  if (test_omp_aligned_alloc_on_device())
+printf("FAILE\n");
+  else
+// CHECK: PASSED
+printf("PASSED\n");
+}
Index: clang/test/OpenMP/target_uses_allocators_codegen.cpp
===
--- clang/test/OpenMP/target_uses_allocators_codegen.cpp
+++ clang/test/OpenMP/target_uses_allocators_codegen.cpp
@@ -78,8 +78,7 @@
 // CHECK: [[TRAITS_ADDR_REF:%.+]] = alloca ptr,
 // CHECK: [[MY_ALLOCATOR_ADDR:%.+]] = alloca i64,
 // CHECK: [[TRAITS_ADDR:%.+]] = load ptr, ptr [[TRAITS_ADDR_REF]],
-// CHECK: [[TRAITS:%.+]] = load ptr, ptr [[TRAITS_ADDR]],
-// CHECK: [[ALLOCATOR:%.+]] = call ptr @__kmpc_init_allocator(i32 %{{.+}}, ptr null, i32 10, ptr [[TRAITS]])
+// CHECK: [[ALLOCATOR:%.+]] = call ptr @__kmpc_init_allocator(i32 %{{.+}}, ptr null, i32 10, ptr [[TRAITS_ADDR]])
 // CHECK: [[CONV:%.+]] = ptrtoint ptr [[ALLOCATOR]] to i64
 // CHECK: store i64 [[CONV]], ptr [[MY_ALLOCATOR_ADDR]],
 
Index: clang/test/OpenMP/target_uses_allocators.c
===
--- clang/test/OpenMP/target_uses_allocators.c
+++ clang/test/OpenMP/target_uses_allocators.c
@@ -132,8 +132,7 @@
 // CHECK: [[TRAITS_ADDR_REF:%.+]] = alloca ptr,
 // CHECK: [[MY_ALLOCATOR_ADDR:%.+]] = alloca i64,
 // CHECK: [[TRAITS_ADDR:%.+]] = load ptr, ptr [[TRAITS_ADDR_REF]],
-// CHECK: [[TRAITS:%.+]] = load ptr, ptr [[TRAITS_ADDR]],
-// CHECK: [[ALLOCATOR:%.+]] = call ptr @__kmpc_init_allocator(i32 %{{.+}}, ptr null, i32 10, ptr [[TRAITS]])
+// CHECK: [[ALLOCATOR:%.+]] = call ptr @__kmpc_init_allocator(i32 %{{.+}}, ptr null, i32 10, ptr [[TRAITS_ADDR]])
 // CHECK: [[CONV:%.+]] = ptrtoint ptr [[ALLOCATOR]] to i64
 // CHECK: store i64 [[CONV]], ptr [[MY_ALLOCATOR_ADDR]],
 
Index: clang/test/OpenMP/target_teams_uses_allocators_codegen.cpp
===
--- clang/test/OpenMP/target_teams_uses_allocators_codegen.cpp
+++ clang/test/OpenMP/target_teams_uses_allocators_codegen.cpp
@@ -78,8 +78,7 @@
 // CHECK: [[TRAITS_ADDR_REF:%.+]] = alloca ptr,
 // CHECK: [[MY_ALLOCATOR_ADDR:%.+]] = alloca i64,
 // CHECK: [[TRAITS_ADDR:%.+]] = load ptr, ptr [[TRAITS_ADDR_REF]],
-// CHECK: [[TRAITS:%.+]] = load ptr, ptr [[TRAITS_ADDR]],
-// CHECK: [[ALLOCATOR:%.+]] = call ptr @__kmpc_init_allocator(i32 %{{.+}}, ptr null, i32 10, ptr 

[PATCH] D151593: [MemProf] Clean up MemProf instrumentation pass invocation

2023-05-26 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson added inline comments.



Comment at: clang/lib/CodeGen/BackendUtil.cpp:995
 
+// TODO: Consider passing the MemoryProfileOutput to the pass builder via
+// the PGOOptions, and set this up there.

vitalybuka wrote:
> tejohnson wrote:
> > vitalybuka wrote:
> > > if this is registerOptimizerLastEPCallback, it can be next to other 
> > > sanitizers, in addSanitizers()
> > It could be, but while it uses the sanitizer common support, it isn't 
> > logically a sanitizer. Is there an advantage to setting it up there?
> no advantages.
> it has runtime similar to sanitizer, so I rather thing about this as 
> sanitizer :)
> 
Ok thanks. I think I would prefer to keep it separate, and hopefully soon 
address the TODO here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151593

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


[PATCH] D151587: [clang][ConstantEmitter] have tryEmitPrivateForVarInit try ConstExprEmitter fast-path first

2023-05-26 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added inline comments.



Comment at: clang/lib/CodeGen/CGExprConstant.cpp:1324
 // This is a string literal initializing an array in an initializer.
-return CGM.GetConstantArrayFromStringLiteral(E);
+return E->isLValue() ?
+  CGM.GetAddrOfConstantStringFromLiteral(E).getPointer() :

Maybe we should have a separate ConstExprEmitterLValue... trying to handle both 
LValues and RValues on the same codepath has been problematic in the past.  
It's very easy for code to get confused what it's actually trying to emit.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151587

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


[PATCH] D138499: [clangd] Extract Function: add hoisting support

2023-05-26 Thread Julian Schmidt via Phabricator via cfe-commits
5chmidti added a comment.

Ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138499

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


[PATCH] D151584: [clang][modules] NFCI: Use `DirectoryEntryRef` for umbrella directory

2023-05-26 Thread Jan Svoboda via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGd6e617c8efab: [clang][modules] NFCI: Use `DirectoryEntryRef` 
for umbrella directory (authored by jansvoboda11).

Changed prior to commit:
  https://reviews.llvm.org/D151584?vs=526175=526213#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151584

Files:
  clang/include/clang/Basic/Module.h
  clang/include/clang/Lex/ModuleMap.h
  clang/lib/Basic/Module.cpp
  clang/lib/Lex/ModuleMap.cpp
  clang/lib/Lex/PPLexerChange.cpp
  clang/lib/Serialization/ASTReader.cpp

Index: clang/lib/Serialization/ASTReader.cpp
===
--- clang/lib/Serialization/ASTReader.cpp
+++ clang/lib/Serialization/ASTReader.cpp
@@ -5750,7 +5750,8 @@
   // See comments in SUBMODULE_UMBRELLA_HEADER
   std::string Dirname = std::string(Blob);
   ResolveImportedPath(F, Dirname);
-  if (auto Umbrella = PP.getFileManager().getDirectory(Dirname)) {
+  if (auto Umbrella =
+  PP.getFileManager().getOptionalDirectoryRef(Dirname)) {
 if (!CurrentModule->getUmbrellaDirAsWritten()) {
   // FIXME: NameAsWritten
   ModMap.setUmbrellaDirAsWritten(CurrentModule, *Umbrella, Blob, "");
Index: clang/lib/Lex/PPLexerChange.cpp
===
--- clang/lib/Lex/PPLexerChange.cpp
+++ clang/lib/Lex/PPLexerChange.cpp
@@ -298,7 +298,7 @@
 return;
 
   ModuleMap  = getHeaderSearchInfo().getModuleMap();
-  const DirectoryEntry *Dir = Mod.getEffectiveUmbrellaDir();
+  OptionalDirectoryEntryRef Dir = Mod.getEffectiveUmbrellaDir();
   llvm::vfs::FileSystem  = FileMgr.getVirtualFileSystem();
   std::error_code EC;
   for (llvm::vfs::recursive_directory_iterator Entry(FS, Dir->getName(), EC),
@@ -318,7 +318,7 @@
 if (!ModMap.isHeaderInUnavailableModule(*Header)) {
   // Find the relative path that would access this header.
   SmallString<128> RelativePath;
-  computeRelativePath(FileMgr, Dir, *Header, RelativePath);
+  computeRelativePath(FileMgr, *Dir, *Header, RelativePath);
   Diag(ExpectedHeadersLoc, diag::warn_uncovered_module_header)
   << Mod.getFullModuleName() << RelativePath;
 }
Index: clang/lib/Lex/ModuleMap.cpp
===
--- clang/lib/Lex/ModuleMap.cpp
+++ clang/lib/Lex/ModuleMap.cpp
@@ -1186,9 +1186,9 @@
 }
 
 void ModuleMap::setUmbrellaDirAsWritten(
-Module *Mod, const DirectoryEntry *UmbrellaDir, const Twine ,
+Module *Mod, DirectoryEntryRef UmbrellaDir, const Twine ,
 const Twine ) {
-  Mod->Umbrella = UmbrellaDir;
+  Mod->Umbrella = ();
   Mod->UmbrellaAsWritten = NameAsWritten.str();
   Mod->UmbrellaRelativeToRootModuleDirectory =
   PathRelativeToRootModuleDirectory.str();
@@ -2515,16 +2515,14 @@
   }
 
   // Look for this file.
-  const DirectoryEntry *Dir = nullptr;
+  OptionalDirectoryEntryRef Dir;
   if (llvm::sys::path::is_absolute(DirName)) {
-if (auto D = SourceMgr.getFileManager().getDirectory(DirName))
-  Dir = *D;
+Dir = SourceMgr.getFileManager().getOptionalDirectoryRef(DirName);
   } else {
 SmallString<128> PathName;
 PathName = Directory->getName();
 llvm::sys::path::append(PathName, DirName);
-if (auto D = SourceMgr.getFileManager().getDirectory(PathName))
-  Dir = *D;
+Dir = SourceMgr.getFileManager().getOptionalDirectoryRef(PathName);
   }
 
   if (!Dir) {
@@ -2558,7 +2556,7 @@
 return;
   }
 
-  if (Module *OwningModule = Map.UmbrellaDirs[Dir]) {
+  if (Module *OwningModule = Map.UmbrellaDirs[*Dir]) {
 Diags.Report(UmbrellaLoc, diag::err_mmap_umbrella_clash)
   << OwningModule->getFullModuleName();
 HadError = true;
@@ -2566,7 +2564,7 @@
   }
 
   // Record this umbrella directory.
-  Map.setUmbrellaDirAsWritten(ActiveModule, Dir, DirNameAsWritten, DirName);
+  Map.setUmbrellaDirAsWritten(ActiveModule, *Dir, DirNameAsWritten, DirName);
 }
 
 /// Parse a module export declaration.
Index: clang/lib/Basic/Module.cpp
===
--- clang/lib/Basic/Module.cpp
+++ clang/lib/Basic/Module.cpp
@@ -263,12 +263,12 @@
   return nameParts.empty();
 }
 
-const DirectoryEntry *Module::getEffectiveUmbrellaDir() const {
+OptionalDirectoryEntryRef Module::getEffectiveUmbrellaDir() const {
   if (const auto *ME = Umbrella.dyn_cast())
 return FileEntryRef(*ME).getDir();
-  if (const auto *ME = Umbrella.dyn_cast())
-return ME;
-  return nullptr;
+  if (const auto *ME = Umbrella.dyn_cast())
+return DirectoryEntryRef(*ME);
+  return std::nullopt;
 }
 
 void Module::addTopHeader(const FileEntry *File) {
Index: clang/include/clang/Lex/ModuleMap.h

[clang] d6e617c - [clang][modules] NFCI: Use `DirectoryEntryRef` for umbrella directory

2023-05-26 Thread Jan Svoboda via cfe-commits

Author: Jan Svoboda
Date: 2023-05-26T15:30:28-07:00
New Revision: d6e617c8efab582121e0a0a9d539652bdfd544da

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

LOG: [clang][modules] NFCI: Use `DirectoryEntryRef` for umbrella directory

This removes some deprecated uses of `DirectoryEntry::getName()`.

Depends on D151581.

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

Added: 


Modified: 
clang/include/clang/Basic/Module.h
clang/include/clang/Lex/ModuleMap.h
clang/lib/Basic/Module.cpp
clang/lib/Lex/ModuleMap.cpp
clang/lib/Lex/PPLexerChange.cpp
clang/lib/Serialization/ASTReader.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/Module.h 
b/clang/include/clang/Basic/Module.h
index b9105441b6b6..128e2adc189b 100644
--- a/clang/include/clang/Basic/Module.h
+++ b/clang/include/clang/Basic/Module.h
@@ -156,7 +156,8 @@ class alignas(8) Module {
   std::string PresumedModuleMapFile;
 
   /// The umbrella header or directory.
-  llvm::PointerUnion
+  llvm::PointerUnion
   Umbrella;
 
   /// The module signature.
@@ -252,9 +253,9 @@ class alignas(8) Module {
   struct DirectoryName {
 std::string NameAsWritten;
 std::string PathRelativeToRootModuleDirectory;
-const DirectoryEntry *Entry;
+OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr Entry;
 
-explicit operator bool() { return Entry; }
+explicit operator bool() { return Entry.has_value(); }
   };
 
   /// The headers that are part of this module.
@@ -653,9 +654,11 @@ class alignas(8) Module {
 
   /// Retrieve the umbrella directory as written.
   DirectoryName getUmbrellaDirAsWritten() const {
-if (const auto *ME = Umbrella.dyn_cast())
+if (const auto *ME =
+Umbrella.dyn_cast())
   return DirectoryName{UmbrellaAsWritten,
-   UmbrellaRelativeToRootModuleDirectory, ME};
+   UmbrellaRelativeToRootModuleDirectory,
+   DirectoryEntryRef(*ME)};
 return DirectoryName{};
   }
 
@@ -670,13 +673,7 @@ class alignas(8) Module {
   /// Get the effective umbrella directory for this module: either the one
   /// explicitly written in the module map file, or the parent of the umbrella
   /// header.
-  const DirectoryEntry *getEffectiveUmbrellaDir() const;
-
-  /// Determine whether this module has an umbrella directory that is
-  /// not based on an umbrella header.
-  bool hasUmbrellaDir() const {
-return Umbrella && Umbrella.is();
-  }
+  OptionalDirectoryEntryRef getEffectiveUmbrellaDir() const;
 
   /// Add a top-level header associated with this module.
   void addTopHeader(const FileEntry *File);

diff  --git a/clang/include/clang/Lex/ModuleMap.h 
b/clang/include/clang/Lex/ModuleMap.h
index bd7e4e6ff8fe..92697fe7deaa 100644
--- a/clang/include/clang/Lex/ModuleMap.h
+++ b/clang/include/clang/Lex/ModuleMap.h
@@ -699,7 +699,7 @@ class ModuleMap {
  const Twine );
 
   /// Sets the umbrella directory of the given module to the given directory.
-  void setUmbrellaDirAsWritten(Module *Mod, const DirectoryEntry *UmbrellaDir,
+  void setUmbrellaDirAsWritten(Module *Mod, DirectoryEntryRef UmbrellaDir,
const Twine ,
const Twine );
 

diff  --git a/clang/lib/Basic/Module.cpp b/clang/lib/Basic/Module.cpp
index e0bce04412a2..3df376a32e53 100644
--- a/clang/lib/Basic/Module.cpp
+++ b/clang/lib/Basic/Module.cpp
@@ -263,12 +263,12 @@ bool Module::fullModuleNameIs(ArrayRef 
nameParts) const {
   return nameParts.empty();
 }
 
-const DirectoryEntry *Module::getEffectiveUmbrellaDir() const {
+OptionalDirectoryEntryRef Module::getEffectiveUmbrellaDir() const {
   if (const auto *ME = Umbrella.dyn_cast())
 return FileEntryRef(*ME).getDir();
-  if (const auto *ME = Umbrella.dyn_cast())
-return ME;
-  return nullptr;
+  if (const auto *ME = Umbrella.dyn_cast())
+return DirectoryEntryRef(*ME);
+  return std::nullopt;
 }
 
 void Module::addTopHeader(const FileEntry *File) {

diff  --git a/clang/lib/Lex/ModuleMap.cpp b/clang/lib/Lex/ModuleMap.cpp
index 9bc1ccd02eb1..0db7ebff2917 100644
--- a/clang/lib/Lex/ModuleMap.cpp
+++ b/clang/lib/Lex/ModuleMap.cpp
@@ -1186,9 +1186,9 @@ void ModuleMap::setUmbrellaHeaderAsWritten(
 }
 
 void ModuleMap::setUmbrellaDirAsWritten(
-Module *Mod, const DirectoryEntry *UmbrellaDir, const Twine ,
+Module *Mod, DirectoryEntryRef UmbrellaDir, const Twine ,
 const Twine ) {
-  Mod->Umbrella = UmbrellaDir;
+  Mod->Umbrella = ();
   Mod->UmbrellaAsWritten = NameAsWritten.str();
   Mod->UmbrellaRelativeToRootModuleDirectory =
   PathRelativeToRootModuleDirectory.str();
@@ -2515,16 +2515,14 @@ void 
ModuleMapParser::parseUmbrellaDirDecl(SourceLocation 

[clang] 89d71c1 - [Driver] Reject AIX-specific link options on non-AIX targets

2023-05-26 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2023-05-26T15:30:23-07:00
New Revision: 89d71c1efa85656b54bcd79b4278bc67690480e1

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

LOG: [Driver] Reject AIX-specific link options on non-AIX targets

Follow-up to D106688 and D146431.

-b leads to a -Wunused-command-line-argument warning instead of an error
without linking phase.
-mxcoff-build-id= leads to a -Wunused-command-line-argument warning instead of
an error.

Added: 
clang/test/Driver/aix-link-options-on-non-aix.c

Modified: 
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Driver/ToolChains/CommonArgs.cpp
clang/test/Driver/Xlinker-args.c

Removed: 
clang/test/Driver/unsupported-target-K.c



diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index e1adff4e0751c..2fd07b3864a38 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -6370,10 +6370,14 @@ void Clang::ConstructJob(Compilation , const 
JobAction ,
 }
   }
 
-  if (Arg *A = Args.getLastArgNoClaim(options::OPT_K);
-  A && !TC.getTriple().isOSAIX())
-D.Diag(diag::err_drv_unsupported_opt_for_target)
-<< A->getAsString(Args) << TripleStr;
+  // Reject AIX-specific link options on other targets.
+  if (!TC.getTriple().isOSAIX()) {
+for (const Arg *A : Args.filtered(options::OPT_b, options::OPT_K,
+  options::OPT_mxcoff_build_id_EQ)) {
+  D.Diag(diag::err_drv_unsupported_opt_for_target)
+  << A->getSpelling() << TripleStr;
+}
+  }
 
   if (Args.getLastArg(options::OPT_fapple_kext) ||
   (Args.hasArg(options::OPT_mkernel) && types::isCXX(InputType)))

diff  --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 4a11be78f37f4..8854d13da98f3 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -303,15 +303,6 @@ void tools::AddLinkerInputs(const ToolChain , const 
InputInfoList ,
   // Pass -z prefix for gcc linker compatibility.
   A.claim();
   A.render(Args, CmdArgs);
-} else if (A.getOption().matches(options::OPT_b)) {
-  const llvm::Triple  = TC.getTriple();
-  if (!T.isOSAIX()) {
-TC.getDriver().Diag(diag::err_drv_unsupported_opt_for_target)
-<< A.getSpelling() << T.str();
-  }
-  // Pass -b prefix for AIX linker.
-  A.claim();
-  A.render(Args, CmdArgs);
 } else {
   A.renderAsInput(Args, CmdArgs);
 }

diff  --git a/clang/test/Driver/Xlinker-args.c 
b/clang/test/Driver/Xlinker-args.c
index ad59e0beee22b..b2a913e7cef62 100644
--- a/clang/test/Driver/Xlinker-args.c
+++ b/clang/test/Driver/Xlinker-args.c
@@ -21,16 +21,11 @@
 // RUN:   -b one -b two %s 2> %t
 // RUN: FileCheck -check-prefix=AIX < %t %s
 
-// RUN: %clang -target powerpc-unknown-linux -### \
-// RUN:   -b one %s 2> %t
-// RUN: FileCheck -check-prefix=NOT-AIX < %t %s
-
 // DARWIN-NOT: --no-demangle
 // DARWIN: "one" "two" "three" "four" "-z" "five" "-r"
 // LINUX: "--no-demangle" "-e" "_start" "one" "two" "three" "four" "-z" "five" 
"-r" {{.*}} "-T" "a.lds"
 // MINGW: "--no-demangle"
 // AIX: "-b" "one" "-b" "two"
-// NOT-AIX: error: unsupported option '-b' for target 'powerpc-unknown-linux'
 
 // Check that we forward '-Xlinker' and '-Wl,' on Windows.
 // RUN: %clang -target i686-pc-win32 -fuse-ld=link -### \

diff  --git a/clang/test/Driver/aix-link-options-on-non-aix.c 
b/clang/test/Driver/aix-link-options-on-non-aix.c
new file mode 100644
index 0..d44137a8c5d64
--- /dev/null
+++ b/clang/test/Driver/aix-link-options-on-non-aix.c
@@ -0,0 +1,10 @@
+/// AIX-specific link options are rejected for other targets.
+// RUN: %clang -### --target=powerpc64-unknown-linux-gnu \
+// RUN:   --sysroot %S/Inputs/aix_ppc_tree --unwindlib=libunwind 
--rtlib=compiler-rt \
+// RUN:   -b one -K -mxcoff-build-id=a %s 2>&1 | FileCheck %s 
--implicit-check-not=error:
+// RUN: %clang -### --target=powerpc64-unknown-linux-gnu -c \
+// RUN:   --sysroot %S/Inputs/aix_ppc_tree --unwindlib=libunwind 
--rtlib=compiler-rt \
+// RUN:   -b one -K -mxcoff-build-id=a %s 2>&1 | FileCheck %s 
--implicit-check-not=error:
+// CHECK: error: unsupported option '-b' for target '{{.*}}'
+// CHECK: error: unsupported option '-K' for target '{{.*}}'
+// CHECK: error: unsupported option '-mxcoff-build-id=' for target '{{.*}}'

diff  --git a/clang/test/Driver/unsupported-target-K.c 
b/clang/test/Driver/unsupported-target-K.c
deleted file mode 100644
index 8b9a6f529c326..0
--- a/clang/test/Driver/unsupported-target-K.c
+++ /dev/null
@@ -1,8 +0,0 @@
-// Check powerpc64-unknown-linux-gnu. -K not supported.
-// RUN: %clang %s 2>&1 -### \
-// RUN:

[PATCH] D151593: [MemProf] Clean up MemProf instrumentation pass invocation

2023-05-26 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka accepted this revision.
vitalybuka added a comment.
This revision is now accepted and ready to land.

Either way is fine


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151593

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


[PATCH] D151593: [MemProf] Clean up MemProf instrumentation pass invocation

2023-05-26 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka added inline comments.



Comment at: clang/lib/CodeGen/BackendUtil.cpp:995
 
+// TODO: Consider passing the MemoryProfileOutput to the pass builder via
+// the PGOOptions, and set this up there.

tejohnson wrote:
> vitalybuka wrote:
> > if this is registerOptimizerLastEPCallback, it can be next to other 
> > sanitizers, in addSanitizers()
> It could be, but while it uses the sanitizer common support, it isn't 
> logically a sanitizer. Is there an advantage to setting it up there?
no advantages.
it has runtime similar to sanitizer, so I rather thing about this as sanitizer 
:)



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151593

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


[PATCH] D151587: [clang][ConstantEmitter] have tryEmitPrivateForVarInit try ConstExprEmitter fast-path first

2023-05-26 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers updated this revision to Diff 526210.
nickdesaulniers added a comment.

- fix string literals; still WIP


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151587

Files:
  clang/lib/CodeGen/CGExprConstant.cpp
  clang/test/CodeGenCXX/const-init-cxx1y.cpp
  clang/test/CodeGenCXX/designated-init.cpp
  clang/test/CodeGenOpenCL/amdgpu-nullptr.cl

Index: clang/test/CodeGenOpenCL/amdgpu-nullptr.cl
===
--- clang/test/CodeGenOpenCL/amdgpu-nullptr.cl
+++ clang/test/CodeGenOpenCL/amdgpu-nullptr.cl
@@ -57,7 +57,7 @@
 // CHECK: @fold_generic ={{.*}} local_unnamed_addr addrspace(1) global ptr null, align 8
 generic int *fold_generic = (global int*)(generic float*)(private char*)0;
 
-// CHECK: @fold_priv ={{.*}} local_unnamed_addr addrspace(1) global ptr addrspace(5) addrspacecast (ptr null to ptr addrspace(5)), align 4
+// CHECK: @fold_priv = local_unnamed_addr addrspace(1) global ptr addrspace(5) addrspacecast (ptr addrspace(1) null to ptr addrspace(5)), align 4
 private short *fold_priv = (private short*)(generic int*)(global void*)0;
 
 // CHECK: @fold_priv_arith ={{.*}} local_unnamed_addr addrspace(1) global ptr addrspace(5) inttoptr (i32 9 to ptr addrspace(5)), align 4
Index: clang/test/CodeGenCXX/designated-init.cpp
===
--- clang/test/CodeGenCXX/designated-init.cpp
+++ clang/test/CodeGenCXX/designated-init.cpp
@@ -4,7 +4,8 @@
 struct A { int x, y[3]; };
 struct B { A a; };
 
-// CHECK: @b ={{.*}} global %{{[^ ]*}} { %{{[^ ]*}} { i32 1, [3 x i32] [i32 2, i32 5, i32 4] } }
+// CHECK: @b = global %struct.B zeroinitializer, align 4
+
 B b = {(A){1, 2, 3, 4}, .a.y[1] = 5};
 
 union U {
@@ -19,10 +20,10 @@
   C c;
 };
 
-// CHECK: @d1 = {{.*}} { i32 1, [3 x %[[U:.*]]] [%[[U]] { i32 2 }, %[[U]] { i32 5 }, %[[U]] { i32 4 }] }
+// CHECK: @d1 = global %struct.D zeroinitializer, align 4
 D d1 = {(C){1, {{.n=2}, {.f=3}, {.n=4}}}, .c.u[1].n = 5};
 
-// CHECK: @d2 = {{.*}} { i32 1, { %[[U]], float, %[[U]] } { %[[U]] { i32 2 }, float 5.{{0*}}e+00, %[[U]] { i32 4 } } }
+// CHECK: @d2 = global %struct.D zeroinitializer, align 4
 D d2 = {(C){1, 2, 3, 4}, .c.u[1].f = 5};
 
 struct Bitfield {
@@ -34,7 +35,7 @@
   int n;
   Bitfield b;
 };
-// CHECK: @bitfield = {{.*}} { i32 1, { i8, i8, [2 x i8] } { i8 42, i8 2, [2 x i8] undef } }
+// CHECK: @bitfield = global %struct.WithBitfield zeroinitializer, align 4
 WithBitfield bitfield = {1, (Bitfield){2, 3, 4}, .b.b = 5};
 
 struct String {
@@ -43,7 +44,7 @@
 struct WithString {
   String str;
 };
-// CHECK: @string = {{.*}} [12 x i8] c"Hello World\00" } }
+// CHECK: @string = global %struct.WithString zeroinitializer, align 1
 WithString string = {(String){"hello world"}, .str.buffer[0] = 'H', .str.buffer[6] = 'W'};
 
 struct LargeArray {
@@ -52,7 +53,7 @@
 struct WithLargeArray {
   LargeArray arr;
 };
-// CHECK: @large ={{.*}} global { { <{ [11 x i32], [4085 x i32] }> } } { { <{ [11 x i32], [4085 x i32] }> } { <{ [11 x i32], [4085 x i32] }> <{ [11 x i32] [i32 1, i32 2, i32 3, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 10], [4085 x i32] zeroinitializer }> } }
+// CHECK: @large = global %struct.WithLargeArray zeroinitializer, align 4
 WithLargeArray large = {(LargeArray){1, 2, 3}, .arr.arr[10] = 10};
 
 union OverwritePaddingWithBitfield {
@@ -62,5 +63,6 @@
 struct WithOverwritePaddingWithBitfield {
   OverwritePaddingWithBitfield a;
 };
-// CHECK: @overwrite_padding ={{.*}} global { { i8, i8 } } { { i8, i8 } { i8 3, i8 1 } }
+// CHECK: @overwrite_padding = global %struct.WithOverwritePaddingWithBitfield zeroinitializer, align 1
+
 WithOverwritePaddingWithBitfield overwrite_padding = {(OverwritePaddingWithBitfield){1}, .a.bitfield = 3};
Index: clang/test/CodeGenCXX/const-init-cxx1y.cpp
===
--- clang/test/CodeGenCXX/const-init-cxx1y.cpp
+++ clang/test/CodeGenCXX/const-init-cxx1y.cpp
@@ -34,8 +34,8 @@
   // 'c.temporary', not the value as modified by the partial evaluation within
   // the initialization of 'c.x'.
   A c = { 10, (++c.temporary, b.x) };
+  // CHECK: @_ZN21ModifyStaticTemporary1cE = global %"struct.ModifyStaticTemporary::A" zeroinitializer
   // CHECK: @_ZGRN21ModifyStaticTemporary1cE_ = internal global i32 10
-  // CHECK: @_ZN21ModifyStaticTemporary1cE ={{.*}} global {{.*}} zeroinitializer
 }
 
 // CHECK: @_ZGRN28VariableTemplateWithConstRef1iIvEE_ = linkonce_odr constant i32 5, align 4
Index: clang/lib/CodeGen/CGExprConstant.cpp
===
--- clang/lib/CodeGen/CGExprConstant.cpp
+++ clang/lib/CodeGen/CGExprConstant.cpp
@@ -1211,15 +1211,6 @@
 return Visit(DIE->getExpr(), T);
   }
 
-  llvm::Constant *VisitExprWithCleanups(ExprWithCleanups *E, QualType T) {
-return Visit(E->getSubExpr(), T);
-  }
-
-  

[PATCH] D151593: [MemProf] Clean up MemProf instrumentation pass invocation

2023-05-26 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson added inline comments.



Comment at: clang/lib/CodeGen/BackendUtil.cpp:995
 
+// TODO: Consider passing the MemoryProfileOutput to the pass builder via
+// the PGOOptions, and set this up there.

vitalybuka wrote:
> if this is registerOptimizerLastEPCallback, it can be next to other 
> sanitizers, in addSanitizers()
It could be, but while it uses the sanitizer common support, it isn't logically 
a sanitizer. Is there an advantage to setting it up there?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151593

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


[PATCH] D151593: [MemProf] Clean up MemProf instrumentation pass invocation

2023-05-26 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka added inline comments.



Comment at: clang/lib/CodeGen/BackendUtil.cpp:995
 
+// TODO: Consider passing the MemoryProfileOutput to the pass builder via
+// the PGOOptions, and set this up there.

if this is registerOptimizerLastEPCallback, it can be next to other sanitizers, 
in addSanitizers()


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151593

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


[PATCH] D151584: [clang][modules] NFCI: Use `DirectoryEntryRef` for umbrella directory

2023-05-26 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 added inline comments.



Comment at: clang/include/clang/Basic/Module.h:160
+  llvm::PointerUnion
   Umbrella;

benlangmuir wrote:
> Would it make sense to implement `PointerLikeTypeTraits` for 
> FileEntryRef/DirectoryEntryRef so you don't need to use the MapEntry 
> explicitly?
It would. I'll do that in a follow-up.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151584

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


[PATCH] D151581: [clang][modules] NFCI: Distinguish as-written and effective umbrella directories

2023-05-26 Thread Jan Svoboda via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG924912956ed5: [clang][modules] NFCI: Distinguish as-written 
and effective umbrella directories (authored by jansvoboda11).
Herald added a project: clang-tools-extra.

Changed prior to commit:
  https://reviews.llvm.org/D151581?vs=526158=526208#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151581

Files:
  clang-tools-extra/modularize/CoverageChecker.cpp
  clang-tools-extra/modularize/ModularizeUtilities.cpp
  clang/include/clang/Basic/Module.h
  clang/include/clang/Lex/ModuleMap.h
  clang/lib/Basic/Module.cpp
  clang/lib/Frontend/FrontendAction.cpp
  clang/lib/Lex/ModuleMap.cpp
  clang/lib/Lex/PPLexerChange.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp

Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -2846,11 +2846,12 @@
 }
 
 // Emit the umbrella header, if there is one.
-if (auto UmbrellaHeader = Mod->getUmbrellaHeader()) {
+if (Module::Header UmbrellaHeader = Mod->getUmbrellaHeaderAsWritten()) {
   RecordData::value_type Record[] = {SUBMODULE_UMBRELLA_HEADER};
   Stream.EmitRecordWithBlob(UmbrellaAbbrev, Record,
 UmbrellaHeader.NameAsWritten);
-} else if (auto UmbrellaDir = Mod->getUmbrellaDir()) {
+} else if (Module::DirectoryName UmbrellaDir =
+   Mod->getUmbrellaDirAsWritten()) {
   RecordData::value_type Record[] = {SUBMODULE_UMBRELLA_DIR};
   Stream.EmitRecordWithBlob(UmbrellaDirAbbrev, Record,
 UmbrellaDir.NameAsWritten);
Index: clang/lib/Serialization/ASTReader.cpp
===
--- clang/lib/Serialization/ASTReader.cpp
+++ clang/lib/Serialization/ASTReader.cpp
@@ -5713,9 +5713,9 @@
   std::string Filename = std::string(Blob);
   ResolveImportedPath(F, Filename);
   if (auto Umbrella = PP.getFileManager().getOptionalFileRef(Filename)) {
-if (!CurrentModule->getUmbrellaHeader()) {
+if (!CurrentModule->getUmbrellaHeaderAsWritten()) {
   // FIXME: NameAsWritten
-  ModMap.setUmbrellaHeader(CurrentModule, *Umbrella, Blob, "");
+  ModMap.setUmbrellaHeaderAsWritten(CurrentModule, *Umbrella, Blob, "");
 }
 // Note that it's too late at this point to return out of date if the
 // name from the PCM doesn't match up with the one in the module map,
@@ -5751,9 +5751,9 @@
   std::string Dirname = std::string(Blob);
   ResolveImportedPath(F, Dirname);
   if (auto Umbrella = PP.getFileManager().getDirectory(Dirname)) {
-if (!CurrentModule->getUmbrellaDir()) {
+if (!CurrentModule->getUmbrellaDirAsWritten()) {
   // FIXME: NameAsWritten
-  ModMap.setUmbrellaDir(CurrentModule, *Umbrella, Blob, "");
+  ModMap.setUmbrellaDirAsWritten(CurrentModule, *Umbrella, Blob, "");
 }
   }
   break;
Index: clang/lib/Lex/PPLexerChange.cpp
===
--- clang/lib/Lex/PPLexerChange.cpp
+++ clang/lib/Lex/PPLexerChange.cpp
@@ -282,14 +282,14 @@
 
 static void collectAllSubModulesWithUmbrellaHeader(
 const Module , SmallVectorImpl ) {
-  if (Mod.getUmbrellaHeader())
+  if (Mod.getUmbrellaHeaderAsWritten())
 SubMods.push_back();
   for (auto *M : Mod.submodules())
 collectAllSubModulesWithUmbrellaHeader(*M, SubMods);
 }
 
 void Preprocessor::diagnoseMissingHeaderInUmbrellaDir(const Module ) {
-  const Module::Header  = Mod.getUmbrellaHeader();
+  Module::Header UmbrellaHeader = Mod.getUmbrellaHeaderAsWritten();
   assert(UmbrellaHeader.Entry && "Module must use umbrella header");
   const FileID  = SourceMgr.translateFile(UmbrellaHeader.Entry);
   SourceLocation ExpectedHeadersLoc = SourceMgr.getLocForEndOfFile(File);
@@ -298,7 +298,7 @@
 return;
 
   ModuleMap  = getHeaderSearchInfo().getModuleMap();
-  const DirectoryEntry *Dir = Mod.getUmbrellaDir().Entry;
+  const DirectoryEntry *Dir = Mod.getEffectiveUmbrellaDir();
   llvm::vfs::FileSystem  = FileMgr.getVirtualFileSystem();
   std::error_code EC;
   for (llvm::vfs::recursive_directory_iterator Entry(FS, Dir->getName(), EC),
Index: clang/lib/Lex/ModuleMap.cpp
===
--- clang/lib/Lex/ModuleMap.cpp
+++ clang/lib/Lex/ModuleMap.cpp
@@ -266,7 +266,8 @@
   << UmbrellaMod->getFullModuleName();
   else
 // Record this umbrella header.
-setUmbrellaHeader(Mod, *File, Header.FileName, RelativePathName.str());
+setUmbrellaHeaderAsWritten(Mod, *File, Header.FileName,
+   

[clang] 9249129 - [clang][modules] NFCI: Distinguish as-written and effective umbrella directories

2023-05-26 Thread Jan Svoboda via cfe-commits

Author: Jan Svoboda
Date: 2023-05-26T15:14:16-07:00
New Revision: 924912956ed570e433440108cc50bd0ee65605b5

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

LOG: [clang][modules] NFCI: Distinguish as-written and effective umbrella 
directories

For modules with umbrellas, we track how they were written in the module map. 
Unfortunately, the getter for the umbrella directory conflates the "as written" 
directory and the "effective" directory (either the written one or the parent 
of the written umbrella header).

This patch makes the distinction between "as written" and "effective" umbrella 
directories clearer. No functional change intended.

Reviewed By: benlangmuir

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

Added: 


Modified: 
clang-tools-extra/modularize/CoverageChecker.cpp
clang-tools-extra/modularize/ModularizeUtilities.cpp
clang/include/clang/Basic/Module.h
clang/include/clang/Lex/ModuleMap.h
clang/lib/Basic/Module.cpp
clang/lib/Frontend/FrontendAction.cpp
clang/lib/Lex/ModuleMap.cpp
clang/lib/Lex/PPLexerChange.cpp
clang/lib/Serialization/ASTReader.cpp
clang/lib/Serialization/ASTWriter.cpp

Removed: 




diff  --git a/clang-tools-extra/modularize/CoverageChecker.cpp 
b/clang-tools-extra/modularize/CoverageChecker.cpp
index 900a88df68ca2..83c39e495c31a 100644
--- a/clang-tools-extra/modularize/CoverageChecker.cpp
+++ b/clang-tools-extra/modularize/CoverageChecker.cpp
@@ -207,15 +207,16 @@ void CoverageChecker::collectModuleHeaders() {
 // FIXME: Doesn't collect files from umbrella header.
 bool CoverageChecker::collectModuleHeaders(const Module ) {
 
-  if (const FileEntry *UmbrellaHeader = Mod.getUmbrellaHeader().Entry) {
+  if (const FileEntry *UmbrellaHeader =
+  Mod.getUmbrellaHeaderAsWritten().Entry) {
 // Collect umbrella header.
 ModuleMapHeadersSet.insert(ModularizeUtilities::getCanonicalPath(
   UmbrellaHeader->getName()));
 // Preprocess umbrella header and collect the headers it references.
 if (!collectUmbrellaHeaderHeaders(UmbrellaHeader->getName()))
   return false;
-  }
-  else if (const DirectoryEntry *UmbrellaDir = Mod.getUmbrellaDir().Entry) {
+  } else if (const DirectoryEntry *UmbrellaDir =
+ Mod.getUmbrellaDirAsWritten().Entry) {
 // Collect headers in umbrella directory.
 if (!collectUmbrellaHeaders(UmbrellaDir->getName()))
   return false;

diff  --git a/clang-tools-extra/modularize/ModularizeUtilities.cpp 
b/clang-tools-extra/modularize/ModularizeUtilities.cpp
index e3f9a6eba8f6a..a7cadf818664a 100644
--- a/clang-tools-extra/modularize/ModularizeUtilities.cpp
+++ b/clang-tools-extra/modularize/ModularizeUtilities.cpp
@@ -349,14 +349,15 @@ bool ModularizeUtilities::collectModuleHeaders(const 
clang::Module ) {
   for (auto *Submodule : Mod.submodules())
 collectModuleHeaders(*Submodule);
 
-  if (const FileEntry *UmbrellaHeader = Mod.getUmbrellaHeader().Entry) {
+  if (const FileEntry *UmbrellaHeader =
+  Mod.getUmbrellaHeaderAsWritten().Entry) {
 std::string HeaderPath = getCanonicalPath(UmbrellaHeader->getName());
 // Collect umbrella header.
 HeaderFileNames.push_back(HeaderPath);
 
 // FUTURE: When needed, umbrella header header collection goes here.
-  }
-  else if (const DirectoryEntry *UmbrellaDir = Mod.getUmbrellaDir().Entry) {
+  } else if (const DirectoryEntry *UmbrellaDir =
+ Mod.getUmbrellaDirAsWritten().Entry) {
 // If there normal headers, assume these are umbrellas and skip collection.
 if (Mod.Headers->size() == 0) {
   // Collect headers in umbrella directory.

diff  --git a/clang/include/clang/Basic/Module.h 
b/clang/include/clang/Basic/Module.h
index 7ed9a2b2ca386..b9105441b6b62 100644
--- a/clang/include/clang/Basic/Module.h
+++ b/clang/include/clang/Basic/Module.h
@@ -651,19 +651,27 @@ class alignas(8) Module {
 getTopLevelModule()->ASTFile = File;
   }
 
-  /// Retrieve the directory for which this module serves as the
-  /// umbrella.
-  DirectoryName getUmbrellaDir() const;
+  /// Retrieve the umbrella directory as written.
+  DirectoryName getUmbrellaDirAsWritten() const {
+if (const auto *ME = Umbrella.dyn_cast())
+  return DirectoryName{UmbrellaAsWritten,
+   UmbrellaRelativeToRootModuleDirectory, ME};
+return DirectoryName{};
+  }
 
-  /// Retrieve the header that serves as the umbrella header for this
-  /// module.
-  Header getUmbrellaHeader() const {
-if (auto *ME = Umbrella.dyn_cast())
+  /// Retrieve the umbrella header as written.
+  Header getUmbrellaHeaderAsWritten() const {
+if (const auto *ME = Umbrella.dyn_cast())
   return Header{UmbrellaAsWritten, UmbrellaRelativeToRootModuleDirectory,
   

[PATCH] D151594: [clang-tidy] Optimize misc-confusable-identifiers

2023-05-26 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL created this revision.
PiotrZSL added reviewers: serge-sans-paille, carlosgalvezp, njames93.
Herald added a subscriber: xazax.hun.
Herald added a project: All.
PiotrZSL requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

This is final optimization for this check. Main
improvements comes from changing a logic order
in mayShadow function, to first validate result
of mayShadowImpl, then search primary context in
a vectors. Secondary improvement comes from excluding
all implicit code by using TK_IgnoreUnlessSpelledInSource.
All other changes are just cosmetic improvements.

Tested on Cataclysm-DDA open source project, result in
check execution time reduction from 3682 seconds to
100 seconds (~0.25s per TU). That's 97.2% reduction for
this change alone. Resulting in cumulative improvement for
this check around -99.6%, finally bringing this check
into a cheap category.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D151594

Files:
  clang-tools-extra/clang-tidy/misc/ConfusableIdentifierCheck.cpp
  clang-tools-extra/clang-tidy/misc/ConfusableIdentifierCheck.h

Index: clang-tools-extra/clang-tidy/misc/ConfusableIdentifierCheck.h
===
--- clang-tools-extra/clang-tidy/misc/ConfusableIdentifierCheck.h
+++ clang-tools-extra/clang-tidy/misc/ConfusableIdentifierCheck.h
@@ -26,6 +26,10 @@
 
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult ) override;
+  void onEndOfTranslationUnit() override;
+  std::optional getCheckTraversalKind() const override {
+return TK_IgnoreUnlessSpelledInSource;
+  }
 
   struct ContextInfo {
 const DeclContext *PrimaryContext;
Index: clang-tools-extra/clang-tidy/misc/ConfusableIdentifierCheck.cpp
===
--- clang-tools-extra/clang-tidy/misc/ConfusableIdentifierCheck.cpp
+++ clang-tools-extra/clang-tidy/misc/ConfusableIdentifierCheck.cpp
@@ -11,6 +11,7 @@
 
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Lex/Preprocessor.h"
+#include "llvm/ADT/SmallString.h"
 #include "llvm/Support/ConvertUTF.h"
 
 namespace {
@@ -45,14 +46,13 @@
 // We're skipping 1. and 3. for the sake of simplicity, but this can lead to
 // false positive.
 
-static std::string skeleton(StringRef Name) {
+static llvm::SmallString<64U> skeleton(StringRef Name) {
   using namespace llvm;
-  std::string SName = Name.str();
-  std::string Skeleton;
-  Skeleton.reserve(1 + Name.size());
+  SmallString<64U> Skeleton;
+  Skeleton.reserve(1U + Name.size());
 
-  const char *Curr = SName.c_str();
-  const char *End = Curr + SName.size();
+  const char *Curr = Name.data();
+  const char *End = Curr + Name.size();
   while (Curr < End) {
 
 const char *Prev = Curr;
@@ -99,8 +99,6 @@
 
 static bool isMemberOf(const ConfusableIdentifierCheck::ContextInfo *DC0,
const ConfusableIdentifierCheck::ContextInfo *DC1) {
-  if (DC0->Bases.empty())
-return false;
   return llvm::is_contained(DC1->Bases, DC0->PrimaryContext);
 }
 
@@ -117,16 +115,20 @@
   const ConfusableIdentifierCheck::ContextInfo *DC0,
   const NamedDecl *ND1,
   const ConfusableIdentifierCheck::ContextInfo *DC1) {
-  if (!DC0->Bases.empty() && ND1->getAccess() != AS_private &&
-  isMemberOf(DC1, DC0))
-return true;
-  if (!DC1->Bases.empty() && ND0->getAccess() != AS_private &&
-  isMemberOf(DC0, DC1))
-return true;
 
-  return enclosesContext(DC0, DC1) &&
- (mayShadowImpl(ND0, ND1) || mayShadowImpl(DC0->NonTransparentContext,
-   DC1->NonTransparentContext));
+  if (!DC0->Bases.empty() && !DC1->Bases.empty()) {
+if (ND1->getAccess() != AS_private && isMemberOf(DC1, DC0))
+  return true;
+
+if (ND0->getAccess() != AS_private && isMemberOf(DC0, DC1))
+  return true;
+  }
+
+  if (!mayShadowImpl(DC0->NonTransparentContext, DC1->NonTransparentContext) &&
+  !mayShadowImpl(ND0, ND1))
+return false;
+
+  return enclosesContext(DC0, DC1);
 }
 
 const ConfusableIdentifierCheck::ContextInfo *
@@ -172,26 +174,41 @@
 
 void ConfusableIdentifierCheck::check(
 const ast_matchers::MatchFinder::MatchResult ) {
-  if (const auto *ND = Result.Nodes.getNodeAs("nameddecl")) {
-if (IdentifierInfo *NDII = ND->getIdentifier()) {
-  const ContextInfo *Info = getContextInfo(ND->getDeclContext());
-  StringRef NDName = NDII->getName();
-  llvm::SmallVector  = Mapper[skeleton(NDName)];
-  for (const Entry  : Mapped) {
-const IdentifierInfo *ONDII = E.Declaration->getIdentifier();
-if (mayShadow(ND, Info, E.Declaration, E.Info)) {
-  StringRef ONDName = ONDII->getName();
-  if (ONDName != NDName) {
-diag(ND->getLocation(), "%0 is 

[PATCH] D151593: [MemProf] Clean up MemProf instrumentation pass invocation

2023-05-26 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson created this revision.
tejohnson added a reviewer: snehasish.
Herald added subscribers: ormris, hiraditya.
Herald added a project: All.
tejohnson requested review of this revision.
Herald added projects: clang, LLVM.

First, removes the invocation of the memprof instrumentation passes from
the end of the module simplification pass builder, where it doesn't
really belong. However, it turns out that this was never being invoked,
as it is guarded by an internal option not used anywhere (even tests).

These passes are actually added via clang under the -fmemory-profile
option. Changed this to add via the EP callback interface, similar to
the sanitizer passes. They are added to the EP for the end of the
optimization pipeline, which is roughly where they were being added
already (end of the pre-LTO link pipelines and non-LTO optimization
pipeline).

Ideally we should plumb the output file through to LLVM and set it up
there, so I have added a TODO.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D151593

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  llvm/lib/Passes/PassBuilderPipelines.cpp


Index: llvm/lib/Passes/PassBuilderPipelines.cpp
===
--- llvm/lib/Passes/PassBuilderPipelines.cpp
+++ llvm/lib/Passes/PassBuilderPipelines.cpp
@@ -155,9 +155,6 @@
 cl::Hidden,
 cl::desc("Enable inline deferral during PGO"));
 
-static cl::opt EnableMemProfiler("enable-mem-prof", cl::Hidden,
-   cl::desc("Enable memory profiler"));
-
 static cl::opt EnableModuleInliner("enable-module-inliner",
  cl::init(false), cl::Hidden,
  cl::desc("Enable module inliner"));
@@ -1122,11 +1119,6 @@
   MPM.addPass(GlobalOptPass());
   MPM.addPass(GlobalDCEPass());
 
-  if (EnableMemProfiler && Phase != ThinOrFullLTOPhase::ThinLTOPreLink) {
-MPM.addPass(createModuleToFunctionPassAdaptor(MemProfilerPass()));
-MPM.addPass(ModuleMemProfilerPass());
-  }
-
   return MPM;
 }
 
Index: clang/lib/CodeGen/BackendUtil.cpp
===
--- clang/lib/CodeGen/BackendUtil.cpp
+++ clang/lib/CodeGen/BackendUtil.cpp
@@ -992,6 +992,16 @@
 MPM.addPass(InstrProfiling(*Options, false));
   });
 
+// TODO: Consider passing the MemoryProfileOutput to the pass builder via
+// the PGOOptions, and set this up there.
+if (!CodeGenOpts.MemoryProfileOutput.empty()) {
+  PB.registerOptimizerLastEPCallback(
+  [](ModulePassManager , OptimizationLevel Level) {
+MPM.addPass(createModuleToFunctionPassAdaptor(MemProfilerPass()));
+MPM.addPass(ModuleMemProfilerPass());
+  });
+}
+
 if (IsThinLTO) {
   MPM = PB.buildThinLTOPreLinkDefaultPipeline(Level);
 } else if (IsLTO) {
@@ -999,11 +1009,6 @@
 } else {
   MPM = PB.buildPerModuleDefaultPipeline(Level);
 }
-
-if (!CodeGenOpts.MemoryProfileOutput.empty()) {
-  MPM.addPass(createModuleToFunctionPassAdaptor(MemProfilerPass()));
-  MPM.addPass(ModuleMemProfilerPass());
-}
   }
 
   // Add a verifier pass if requested. We don't have to do this if the action


Index: llvm/lib/Passes/PassBuilderPipelines.cpp
===
--- llvm/lib/Passes/PassBuilderPipelines.cpp
+++ llvm/lib/Passes/PassBuilderPipelines.cpp
@@ -155,9 +155,6 @@
 cl::Hidden,
 cl::desc("Enable inline deferral during PGO"));
 
-static cl::opt EnableMemProfiler("enable-mem-prof", cl::Hidden,
-   cl::desc("Enable memory profiler"));
-
 static cl::opt EnableModuleInliner("enable-module-inliner",
  cl::init(false), cl::Hidden,
  cl::desc("Enable module inliner"));
@@ -1122,11 +1119,6 @@
   MPM.addPass(GlobalOptPass());
   MPM.addPass(GlobalDCEPass());
 
-  if (EnableMemProfiler && Phase != ThinOrFullLTOPhase::ThinLTOPreLink) {
-MPM.addPass(createModuleToFunctionPassAdaptor(MemProfilerPass()));
-MPM.addPass(ModuleMemProfilerPass());
-  }
-
   return MPM;
 }
 
Index: clang/lib/CodeGen/BackendUtil.cpp
===
--- clang/lib/CodeGen/BackendUtil.cpp
+++ clang/lib/CodeGen/BackendUtil.cpp
@@ -992,6 +992,16 @@
 MPM.addPass(InstrProfiling(*Options, false));
   });
 
+// TODO: Consider passing the MemoryProfileOutput to the pass builder via
+// the PGOOptions, and set this up there.
+if (!CodeGenOpts.MemoryProfileOutput.empty()) {
+  PB.registerOptimizerLastEPCallback(
+  [](ModulePassManager , OptimizationLevel Level) {
+MPM.addPass(createModuleToFunctionPassAdaptor(MemProfilerPass()));
+

[PATCH] D151589: [lld] add context-sensitive PGO options for MachO

2023-05-26 Thread Ellis Hoag via Phabricator via cfe-commits
ellis created this revision.
Herald added subscribers: wlei, ormris, wenlei, steven_wu, hiraditya.
Herald added projects: lld-macho, All.
Herald added a reviewer: lld-macho.
ellis added reviewers: int3, tejohnson, xur.
ellis updated this revision to Diff 526199.
ellis added a comment.
ellis edited the summary of this revision.
ellis edited the summary of this revision.
ellis edited the summary of this revision.
ellis published this revision for review.
Herald added subscribers: cfe-commits, MaskRay.
Herald added a project: clang.

Only pass flags when using lld


Enable support for CSPGO for lld MachO targets.

Since lld MachO does not support `-plugin-opt=`, we need to create the 
`--cs-profile-generate` and `--cs-profile-path=` options and propagate them in 
`Darwin.cpp`. These flags are not supported by ld64.

Also outline code into `getLastCSProfileGenerateArg()` to share between 
`CommonArgs.cpp` and `Darwin.cpp`.

CSPGO is already implemented for ELF (https://reviews.llvm.org/D56675) and COFF 
(https://reviews.llvm.org/D98763).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D151589

Files:
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/lib/Driver/ToolChains/CommonArgs.h
  clang/lib/Driver/ToolChains/Darwin.cpp
  clang/test/Driver/cspgo-lto.c
  lld/MachO/Config.h
  lld/MachO/Driver.cpp
  lld/MachO/LTO.cpp
  lld/MachO/Options.td

Index: lld/MachO/Options.td
===
--- lld/MachO/Options.td
+++ lld/MachO/Options.td
@@ -124,6 +124,10 @@
 def check_category_conflicts : Flag<["--"], "check-category-conflicts">,
 HelpText<"Check for conflicts between category & class methods">,
 Group;
+def cs_profile_generate: Flag<["--"], "cs-profile-generate">,
+HelpText<"Perform context senstive PGO instrumentation">, Group;
+def cs_profile_path: Joined<["--"], "cs-profile-path=">,
+HelpText<"Context sensitive profile file path">, Group;
 
 // This is a complete Options.td compiled from Apple's ld(1) manpage
 // dated 2018-03-07 and cross checked with ld64 source code in repo
Index: lld/MachO/LTO.cpp
===
--- lld/MachO/LTO.cpp
+++ lld/MachO/LTO.cpp
@@ -68,6 +68,8 @@
 
   c.TimeTraceEnabled = config->timeTraceEnabled;
   c.TimeTraceGranularity = config->timeTraceGranularity;
+  c.CSIRProfile = std::string(config->csProfilePath);
+  c.RunCSIRInstr = config->csProfileGenerate;
   c.OptLevel = config->ltoo;
   c.CGOptLevel = config->ltoCgo;
   if (config->saveTemps)
Index: lld/MachO/Driver.cpp
===
--- lld/MachO/Driver.cpp
+++ lld/MachO/Driver.cpp
@@ -1637,6 +1637,8 @@
   for (const Arg *arg : args.filtered(OPT_ignore_auto_link_option))
 config->ignoreAutoLinkOptions.insert(arg->getValue());
   config->strictAutoLink = args.hasArg(OPT_strict_auto_link);
+  config->csProfileGenerate = args.hasArg(OPT_cs_profile_generate);
+  config->csProfilePath = args.getLastArgValue(OPT_cs_profile_path);
 
   for (const Arg *arg : args.filtered(OPT_alias)) {
 config->aliasedSymbols.push_back(
Index: lld/MachO/Config.h
===
--- lld/MachO/Config.h
+++ lld/MachO/Config.h
@@ -206,6 +206,8 @@
   // so use a vector instead of a map.
   std::vector sectionAlignments;
   std::vector segmentProtections;
+  bool csProfileGenerate = false;
+  llvm::StringRef csProfilePath;
 
   bool callGraphProfileSort = false;
   llvm::StringRef printSymbolOrder;
Index: clang/test/Driver/cspgo-lto.c
===
--- clang/test/Driver/cspgo-lto.c
+++ clang/test/Driver/cspgo-lto.c
@@ -4,3 +4,17 @@
 // RUN:   -fprofile-use 2>&1 | FileCheck %s
 
 // CHECK: -plugin-opt=cs-profile-path=default.profdata
+
+// RUN: %clang -target apple-arm64-ios -### %t.o -flto=thin -fuse-ld=lld -fprofile-use 2>&1 | FileCheck %s --check-prefix=DARWIN-USE1
+// RUN: %clang -target apple-arm64-ios -### %t.o -flto=thin -fuse-ld=lld -fprofile-use=a.profdata 2>&1 | FileCheck %s --check-prefix=DARWIN-USE2
+
+// DARWIN-USE1: "--cs-profile-path=default.profdata"
+// DARWIN-USE2: "--cs-profile-path=a.profdata"
+
+// RUN: %clang -target apple-arm64-ios -### %t.o -flto=thin -fuse-ld=lld -fcs-profile-generate 2>&1 | FileCheck %s --check-prefix=DARWIN-GEN1
+// RUN: %clang -target apple-arm64-ios -### %t.o -flto=thin -fuse-ld=lld -fcs-profile-generate=/dump/here 2>&1 | FileCheck %s --check-prefix=DARWIN-GEN2
+
+// DARWIN-GEN1: "--cs-profile-generate"
+// DARWIN-GEN1-SAME: "--cs-profile-path=default_%m.profraw"
+// DARWIN-GEN2: "--cs-profile-generate"
+// DARWIN-GEN2-SAME: "--cs-profile-path=/dump/here/default_%m.profraw"
Index: clang/lib/Driver/ToolChains/Darwin.cpp
===
--- clang/lib/Driver/ToolChains/Darwin.cpp
+++ clang/lib/Driver/ToolChains/Darwin.cpp
@@ -449,6 +449,23 @@
   

[PATCH] D148793: [WIP][clang-tidy] Implement an include-cleaner check.

2023-05-26 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp:42
+
+struct MissingIncludeInfo {
+  SourceLocation SymRefLocation;

let's put this struct into anon namespace



Comment at: clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp:48
+void IncludeCleanerCheck::registerMatchers(MatchFinder *Finder) {
+  if (!getLangOpts().CPlusPlus)
+return;

in theory this is not enough to disable the check for objc++, it'll have both 
objc and cplusplus set. so we should check `ObjC` is false (there's no need to 
disable it for `c`, right?)

nit: we can also override ` isLanguageVersionSupported` to disable check for 
non-c++.



Comment at: clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp:67
+  for (const auto  : IgnoreHeaders)
+IgnoreHeadersRegex.push_back(llvm::Regex{Header});
+  return IgnoreHeadersRegex;

let's make sure we're only going to match suffixes by appending `$` to the 
`Header` here.

also before pushing into `IgnoreHeadersRegex` can you verify the regex 
`isValid` and report a diagnostic via `configurationDiag` if regex is invalid.



Comment at: clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp:72
+void IncludeCleanerCheck::check(const MatchFinder::MatchResult ) {
+  const auto IgnoreHeadersRegex = parseIgnoreHeaderOptions(IgnoreHeadersOpt);
+  const SourceManager *SM = Result.SourceManager;

`check` is performed only once for this check so it doesn't matter, but it 
might be better to perform this in constructor and store as class state to make 
sure we're only parsing options and creating the regexes once (also possibly 
reporting diagnostics once). as regex creation is actually expensive



Comment at: clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp:83
+  continue;
+MainFileDecls.push_back(const_cast(D));
+  }

instead of `const_cast` here, you can just drop the `const` in `const auto *D` 
in `for` loop variable



Comment at: clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp:107
+  IgnoreHeadersRegex, [](const llvm::Regex ) {
+return R.match(llvm::StringRef(Spelled).trim("\"<>"));
+  }))

we're running this against spelled include of the file, not resolved path.

we should instead use the spelling + trimmed version for verbatim/standard 
headers and use `FileEntry::tryGetRealPathName` for phyiscal headers. we can 
even do the filtering before spelling the header to not spell redundantly.



Comment at: clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.h:48
+  HeaderSearch *HS;
+  llvm::StringRef IgnoreHeadersOpt;
+};

let's make a full copy here and store a `std::string` instead, as reference 
from options might become dangling. also the copy is cheap, we do that once per 
check instantiation.



Comment at: clang-tools-extra/docs/clang-tidy/checks/misc/include-cleaner.rst:15
+
+   A comma-separated list of header files that should be ignored during the 
+   analysis. The option allows for regular expressions. E.g., `foo/.*` disables




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148793

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


[PATCH] D151388: [HWASan] use hwasan linker for Android 14+

2023-05-26 Thread Florian Mayer via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa2684acfb61d: [HWASan] use hwasan linker for Android 14+ 
(authored by fmayer).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151388

Files:
  clang/lib/Driver/ToolChains/Linux.cpp
  clang/test/Driver/linux-ld.c


Index: clang/test/Driver/linux-ld.c
===
--- clang/test/Driver/linux-ld.c
+++ clang/test/Driver/linux-ld.c
@@ -1259,6 +1259,22 @@
 // CHECK-ANDROID-32: "-dynamic-linker" "/system/bin/linker"
 // CHECK-ANDROID-64: "-dynamic-linker" "/system/bin/linker64"
 //
+// Test that Android 14 and newer use linker_hwasan64 for hwasan builds
+// RUN: %clang -### %s -no-pie 2>&1 \
+// RUN: -fsanitize=hwaddress \
+// RUN: --target=x86_64-linux-android33 \
+// RUN: --gcc-toolchain="" \
+// RUN: --sysroot=%S/Inputs/basic_android_tree/sysroot \
+// RUN:   | FileCheck --check-prefix=CHECK-ANDROID-OLD %s
+// RUN: %clang -### %s -no-pie 2>&1 \
+// RUN: -fsanitize=hwaddress \
+// RUN: --target=x86_64-linux-android34 \
+// RUN: --gcc-toolchain="" \
+// RUN: --sysroot=%S/Inputs/basic_android_tree/sysroot \
+// RUN:   | FileCheck --check-prefix=CHECK-ANDROID-NEW %s
+// CHECK-ANDROID-OLD: "-dynamic-linker" "/system/bin/linker64"
+// CHECK-ANDROID-NEW: "-dynamic-linker" "/system/bin/linker_hwasan64"
+//
 // Test that -pthread does not add -lpthread on Android.
 // RUN: %clang -### %s -no-pie 2>&1 \
 // RUN: --target=arm-linux-androideabi -pthread \
Index: clang/lib/Driver/ToolChains/Linux.cpp
===
--- clang/lib/Driver/ToolChains/Linux.cpp
+++ clang/lib/Driver/ToolChains/Linux.cpp
@@ -426,9 +426,17 @@
 
   const Distro Distro(getDriver().getVFS(), Triple);
 
-  if (Triple.isAndroid())
+  if (Triple.isAndroid()) {
+if (getSanitizerArgs(Args).needsHwasanRt() &&
+!Triple.isAndroidVersionLT(34) && Triple.isArch64Bit()) {
+  // On Android 14 and newer, there is a special linker_hwasan64 that
+  // allows to run HWASan binaries on non-HWASan system images. This
+  // is also available on HWASan system images, so we can just always
+  // use that instead.
+  return "/system/bin/linker_hwasan64";
+}
 return Triple.isArch64Bit() ? "/system/bin/linker64" : 
"/system/bin/linker";
-
+  }
   if (Triple.isMusl()) {
 std::string ArchName;
 bool IsArm = false;


Index: clang/test/Driver/linux-ld.c
===
--- clang/test/Driver/linux-ld.c
+++ clang/test/Driver/linux-ld.c
@@ -1259,6 +1259,22 @@
 // CHECK-ANDROID-32: "-dynamic-linker" "/system/bin/linker"
 // CHECK-ANDROID-64: "-dynamic-linker" "/system/bin/linker64"
 //
+// Test that Android 14 and newer use linker_hwasan64 for hwasan builds
+// RUN: %clang -### %s -no-pie 2>&1 \
+// RUN: -fsanitize=hwaddress \
+// RUN: --target=x86_64-linux-android33 \
+// RUN: --gcc-toolchain="" \
+// RUN: --sysroot=%S/Inputs/basic_android_tree/sysroot \
+// RUN:   | FileCheck --check-prefix=CHECK-ANDROID-OLD %s
+// RUN: %clang -### %s -no-pie 2>&1 \
+// RUN: -fsanitize=hwaddress \
+// RUN: --target=x86_64-linux-android34 \
+// RUN: --gcc-toolchain="" \
+// RUN: --sysroot=%S/Inputs/basic_android_tree/sysroot \
+// RUN:   | FileCheck --check-prefix=CHECK-ANDROID-NEW %s
+// CHECK-ANDROID-OLD: "-dynamic-linker" "/system/bin/linker64"
+// CHECK-ANDROID-NEW: "-dynamic-linker" "/system/bin/linker_hwasan64"
+//
 // Test that -pthread does not add -lpthread on Android.
 // RUN: %clang -### %s -no-pie 2>&1 \
 // RUN: --target=arm-linux-androideabi -pthread \
Index: clang/lib/Driver/ToolChains/Linux.cpp
===
--- clang/lib/Driver/ToolChains/Linux.cpp
+++ clang/lib/Driver/ToolChains/Linux.cpp
@@ -426,9 +426,17 @@
 
   const Distro Distro(getDriver().getVFS(), Triple);
 
-  if (Triple.isAndroid())
+  if (Triple.isAndroid()) {
+if (getSanitizerArgs(Args).needsHwasanRt() &&
+!Triple.isAndroidVersionLT(34) && Triple.isArch64Bit()) {
+  // On Android 14 and newer, there is a special linker_hwasan64 that
+  // allows to run HWASan binaries on non-HWASan system images. This
+  // is also available on HWASan system images, so we can just always
+  // use that instead.
+  return "/system/bin/linker_hwasan64";
+}
 return Triple.isArch64Bit() ? "/system/bin/linker64" : "/system/bin/linker";
-
+  }
   if (Triple.isMusl()) {
 std::string ArchName;
 bool IsArm = false;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] a2684ac - [HWASan] use hwasan linker for Android 14+

2023-05-26 Thread Florian Mayer via cfe-commits

Author: Florian Mayer
Date: 2023-05-26T14:25:46-07:00
New Revision: a2684acfb61d40f441e240035d7f1ba50da637c8

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

LOG: [HWASan] use hwasan linker for Android 14+

This will allow to compile binaries that use hwasan to run on a
non-HWASan system image.

Reviewed By: pcc

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

Added: 


Modified: 
clang/lib/Driver/ToolChains/Linux.cpp
clang/test/Driver/linux-ld.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Linux.cpp 
b/clang/lib/Driver/ToolChains/Linux.cpp
index 853ff99d9fe59..920da6e4bfd49 100644
--- a/clang/lib/Driver/ToolChains/Linux.cpp
+++ b/clang/lib/Driver/ToolChains/Linux.cpp
@@ -426,9 +426,17 @@ std::string Linux::getDynamicLinker(const ArgList ) 
const {
 
   const Distro Distro(getDriver().getVFS(), Triple);
 
-  if (Triple.isAndroid())
+  if (Triple.isAndroid()) {
+if (getSanitizerArgs(Args).needsHwasanRt() &&
+!Triple.isAndroidVersionLT(34) && Triple.isArch64Bit()) {
+  // On Android 14 and newer, there is a special linker_hwasan64 that
+  // allows to run HWASan binaries on non-HWASan system images. This
+  // is also available on HWASan system images, so we can just always
+  // use that instead.
+  return "/system/bin/linker_hwasan64";
+}
 return Triple.isArch64Bit() ? "/system/bin/linker64" : 
"/system/bin/linker";
-
+  }
   if (Triple.isMusl()) {
 std::string ArchName;
 bool IsArm = false;

diff  --git a/clang/test/Driver/linux-ld.c b/clang/test/Driver/linux-ld.c
index 287750ac20469..d4e3bf95d6813 100644
--- a/clang/test/Driver/linux-ld.c
+++ b/clang/test/Driver/linux-ld.c
@@ -1259,6 +1259,22 @@
 // CHECK-ANDROID-32: "-dynamic-linker" "/system/bin/linker"
 // CHECK-ANDROID-64: "-dynamic-linker" "/system/bin/linker64"
 //
+// Test that Android 14 and newer use linker_hwasan64 for hwasan builds
+// RUN: %clang -### %s -no-pie 2>&1 \
+// RUN: -fsanitize=hwaddress \
+// RUN: --target=x86_64-linux-android33 \
+// RUN: --gcc-toolchain="" \
+// RUN: --sysroot=%S/Inputs/basic_android_tree/sysroot \
+// RUN:   | FileCheck --check-prefix=CHECK-ANDROID-OLD %s
+// RUN: %clang -### %s -no-pie 2>&1 \
+// RUN: -fsanitize=hwaddress \
+// RUN: --target=x86_64-linux-android34 \
+// RUN: --gcc-toolchain="" \
+// RUN: --sysroot=%S/Inputs/basic_android_tree/sysroot \
+// RUN:   | FileCheck --check-prefix=CHECK-ANDROID-NEW %s
+// CHECK-ANDROID-OLD: "-dynamic-linker" "/system/bin/linker64"
+// CHECK-ANDROID-NEW: "-dynamic-linker" "/system/bin/linker_hwasan64"
+//
 // Test that -pthread does not add -lpthread on Android.
 // RUN: %clang -### %s -no-pie 2>&1 \
 // RUN: --target=arm-linux-androideabi -pthread \



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


[PATCH] D151388: [HWASan] use hwasan linker for Android 14+

2023-05-26 Thread Peter Collingbourne via Phabricator via cfe-commits
pcc accepted this revision.
pcc added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151388

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


[PATCH] D151503: [CUDA] correctly install cuda_wrappers/bits/shared_ptr_base.h

2023-05-26 Thread Artem Belevich via Phabricator via cfe-commits
tra added inline comments.



Comment at: clang/lib/Headers/CMakeLists.txt:516
   COMPONENT cuda-resource-headers)
 
 install(

qiongsiwu1 wrote:
> Do we need an install target for `${cuda_wrapper_bits_files}` for the 
> `cuda-resource-headers` component as well? It seems to be the case because 
> this patch is treating `${cuda_wrapper_bits_files}` as part of 
> `cuda-resource-headers`.
> 
> ```
> add_header_target("cuda-resource-headers" 
> "${cuda_files};${cuda_wrapper_files};${cuda_wrapper_bits_files}")
> ```
> 
> 
I'm not sure I understand the question. Are you saying that a separate 
`install()` for the 'bits' is not necessary and we could just install all 
headers with a single `install` above?

If that's the case, then, AFAICT, the answer is that we do need a separate 
`install`. 
`install(FILES)` does not preserve the directory structure and dumps all files 
listed in `FILES`, regardless if they are in different directories into the 
same DESTINATION directory.
That is exactly the problem this patch is intended to fix. We do need to place 
the file under `cuda_wrappers/bits/` directory and that's why we have separate 
`install(DESTINATION ${header_install_dir}/cuda_wrappers/bits)` here.

`install(DIRECTORY)` would presumably preserve the source directory structure, 
but we lose per-file granularity. It may work for the files under cuda_wrappers 
for now, but I think there's some merit in explicitly controlling which headers 
we ship and where we put them. While we do have 1:1 mapping between the source 
tree and install tree, it may not always be the case.





Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151503

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


[PATCH] D151584: [clang][modules] NFCI: Use `DirectoryEntryRef` for umbrella directory

2023-05-26 Thread Ben Langmuir via Phabricator via cfe-commits
benlangmuir accepted this revision.
benlangmuir added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/include/clang/Basic/Module.h:160
+  llvm::PointerUnion
   Umbrella;

Would it make sense to implement `PointerLikeTypeTraits` for 
FileEntryRef/DirectoryEntryRef so you don't need to use the MapEntry explicitly?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151584

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


[PATCH] D151587: [clang][ConstantEmitter] have tryEmitPrivateForVarInit try ConstExprEmitter fast-path first

2023-05-26 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers updated this revision to Diff 526195.
nickdesaulniers added a comment.
Herald added subscribers: kerbowa, jvesely.

- one more test fix


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151587

Files:
  clang/lib/CodeGen/CGExprConstant.cpp
  clang/test/CodeGenCXX/const-init-cxx1y.cpp
  clang/test/CodeGenCXX/designated-init.cpp
  clang/test/CodeGenOpenCL/amdgpu-nullptr.cl

Index: clang/test/CodeGenOpenCL/amdgpu-nullptr.cl
===
--- clang/test/CodeGenOpenCL/amdgpu-nullptr.cl
+++ clang/test/CodeGenOpenCL/amdgpu-nullptr.cl
@@ -57,7 +57,7 @@
 // CHECK: @fold_generic ={{.*}} local_unnamed_addr addrspace(1) global ptr null, align 8
 generic int *fold_generic = (global int*)(generic float*)(private char*)0;
 
-// CHECK: @fold_priv ={{.*}} local_unnamed_addr addrspace(1) global ptr addrspace(5) addrspacecast (ptr null to ptr addrspace(5)), align 4
+// CHECK: @fold_priv = local_unnamed_addr addrspace(1) global ptr addrspace(5) addrspacecast (ptr addrspace(1) null to ptr addrspace(5)), align 4
 private short *fold_priv = (private short*)(generic int*)(global void*)0;
 
 // CHECK: @fold_priv_arith ={{.*}} local_unnamed_addr addrspace(1) global ptr addrspace(5) inttoptr (i32 9 to ptr addrspace(5)), align 4
Index: clang/test/CodeGenCXX/designated-init.cpp
===
--- clang/test/CodeGenCXX/designated-init.cpp
+++ clang/test/CodeGenCXX/designated-init.cpp
@@ -4,7 +4,8 @@
 struct A { int x, y[3]; };
 struct B { A a; };
 
-// CHECK: @b ={{.*}} global %{{[^ ]*}} { %{{[^ ]*}} { i32 1, [3 x i32] [i32 2, i32 5, i32 4] } }
+// CHECK: @b = global %struct.B zeroinitializer, align 4
+
 B b = {(A){1, 2, 3, 4}, .a.y[1] = 5};
 
 union U {
@@ -19,10 +20,10 @@
   C c;
 };
 
-// CHECK: @d1 = {{.*}} { i32 1, [3 x %[[U:.*]]] [%[[U]] { i32 2 }, %[[U]] { i32 5 }, %[[U]] { i32 4 }] }
+// CHECK: @d1 = global %struct.D zeroinitializer, align 4
 D d1 = {(C){1, {{.n=2}, {.f=3}, {.n=4}}}, .c.u[1].n = 5};
 
-// CHECK: @d2 = {{.*}} { i32 1, { %[[U]], float, %[[U]] } { %[[U]] { i32 2 }, float 5.{{0*}}e+00, %[[U]] { i32 4 } } }
+// CHECK: @d2 = global %struct.D zeroinitializer, align 4
 D d2 = {(C){1, 2, 3, 4}, .c.u[1].f = 5};
 
 struct Bitfield {
@@ -34,7 +35,7 @@
   int n;
   Bitfield b;
 };
-// CHECK: @bitfield = {{.*}} { i32 1, { i8, i8, [2 x i8] } { i8 42, i8 2, [2 x i8] undef } }
+// CHECK: @bitfield = global %struct.WithBitfield zeroinitializer, align 4
 WithBitfield bitfield = {1, (Bitfield){2, 3, 4}, .b.b = 5};
 
 struct String {
@@ -43,7 +44,7 @@
 struct WithString {
   String str;
 };
-// CHECK: @string = {{.*}} [12 x i8] c"Hello World\00" } }
+// CHECK: @string = global %struct.WithString zeroinitializer, align 1
 WithString string = {(String){"hello world"}, .str.buffer[0] = 'H', .str.buffer[6] = 'W'};
 
 struct LargeArray {
@@ -52,7 +53,7 @@
 struct WithLargeArray {
   LargeArray arr;
 };
-// CHECK: @large ={{.*}} global { { <{ [11 x i32], [4085 x i32] }> } } { { <{ [11 x i32], [4085 x i32] }> } { <{ [11 x i32], [4085 x i32] }> <{ [11 x i32] [i32 1, i32 2, i32 3, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 10], [4085 x i32] zeroinitializer }> } }
+// CHECK: @large = global %struct.WithLargeArray zeroinitializer, align 4
 WithLargeArray large = {(LargeArray){1, 2, 3}, .arr.arr[10] = 10};
 
 union OverwritePaddingWithBitfield {
@@ -62,5 +63,6 @@
 struct WithOverwritePaddingWithBitfield {
   OverwritePaddingWithBitfield a;
 };
-// CHECK: @overwrite_padding ={{.*}} global { { i8, i8 } } { { i8, i8 } { i8 3, i8 1 } }
+// CHECK: @overwrite_padding = global %struct.WithOverwritePaddingWithBitfield zeroinitializer, align 1
+
 WithOverwritePaddingWithBitfield overwrite_padding = {(OverwritePaddingWithBitfield){1}, .a.bitfield = 3};
Index: clang/test/CodeGenCXX/const-init-cxx1y.cpp
===
--- clang/test/CodeGenCXX/const-init-cxx1y.cpp
+++ clang/test/CodeGenCXX/const-init-cxx1y.cpp
@@ -34,8 +34,8 @@
   // 'c.temporary', not the value as modified by the partial evaluation within
   // the initialization of 'c.x'.
   A c = { 10, (++c.temporary, b.x) };
+  // CHECK: @_ZN21ModifyStaticTemporary1cE = global %"struct.ModifyStaticTemporary::A" zeroinitializer
   // CHECK: @_ZGRN21ModifyStaticTemporary1cE_ = internal global i32 10
-  // CHECK: @_ZN21ModifyStaticTemporary1cE ={{.*}} global {{.*}} zeroinitializer
 }
 
 // CHECK: @_ZGRN28VariableTemplateWithConstRef1iIvEE_ = linkonce_odr constant i32 5, align 4
Index: clang/lib/CodeGen/CGExprConstant.cpp
===
--- clang/lib/CodeGen/CGExprConstant.cpp
+++ clang/lib/CodeGen/CGExprConstant.cpp
@@ -1211,15 +1211,6 @@
 return Visit(DIE->getExpr(), T);
   }
 
-  llvm::Constant *VisitExprWithCleanups(ExprWithCleanups *E, QualType T) {
-return 

[PATCH] D151586: [clang][modules] NFCI: Extract optionality out of `Module::{Header,DirectoryName}`

2023-05-26 Thread Ben Langmuir via Phabricator via cfe-commits
benlangmuir accepted this revision.
benlangmuir added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/lib/Basic/Module.cpp:486
 
-  if (Header H = getWrittenUmbrellaHeader()) {
+  if (auto H = getWrittenUmbrellaHeader()) {
 OS.indent(Indent + 2);

These are on the edge, but I think I would lean towards spelling the typename 
here since it's not obvious from the name of the API what exactly it would be


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151586

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


[PATCH] D151383: [clang-tidy] Check for specific return types on all functions

2023-05-26 Thread NagaChaitanya Vellanki via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG785b30b8a33a: [clang-tidy] Check for specific return types 
on all functions (authored by chaitanyav).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151383

Files:
  clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/bugprone/unused-return-value.rst
  clang-tools-extra/test/clang-tidy/checkers/bugprone/unused-return-value.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone/unused-return-value.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone/unused-return-value.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone/unused-return-value.cpp
@@ -52,6 +52,9 @@
   bool empty() const noexcept;
 };
 
+class error_code {
+};
+
 // the check should be able to match std lib calls even if the functions are
 // declared inside inline namespaces
 inline namespace v1 {
@@ -72,6 +75,10 @@
 
 void useFuture(const std::future );
 
+std::error_code errorFunc() {
+return std::error_code();
+}
+
 void warning() {
   std::async(increment, 42);
   // CHECK-NOTES: [[@LINE-1]]:3: warning: the value returned by this function should be used
@@ -185,6 +192,10 @@
 // CHECK-NOTES: [[@LINE-1]]:5: warning: the value {{.*}} should be used
 // CHECK-NOTES: [[@LINE-2]]:5: note: cast {{.*}} this warning
   }
+
+  errorFunc();
+  // CHECK-NOTES: [[@LINE-1]]:3: warning: the value {{.*}} should be used
+  // CHECK-NOTES: [[@LINE-2]]:3: note: cast {{.*}} this warning
 }
 
 void noWarning() {
@@ -209,6 +220,8 @@
   std::vector VecNoWarning;
   auto VecEmptyRetval = VecNoWarning.empty();
 
+  (void) errorFunc();
+
   // test using the return value in different kinds of expressions
   useFuture(std::async(increment, 42));
   std::launder()->f();
Index: clang-tools-extra/docs/clang-tidy/checks/bugprone/unused-return-value.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/bugprone/unused-return-value.rst
+++ clang-tools-extra/docs/clang-tidy/checks/bugprone/unused-return-value.rst
@@ -46,5 +46,11 @@
  return value often indicates that the programmer confused the function with
  ``clear()``.
 
+.. option:: CheckedReturnTypes
+
+   Semicolon-separated list of function return types to check.
+   By default the following function return types are checked:
+   `::std::error_code`, `::std::expected`, `::boost::system::error_code`, `::abseil::Status`
+
 `cert-err33-c <../cert/err33-c.html>`_ is an alias of this check that checks a
 fixed and large set of standard library functions.
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -248,6 +248,10 @@
   constructor initializers. Correctly handle constructor arguments as being
   sequenced when constructor call is written as list-initialization.
 
+- Extend :doc:`bugprone-unused-return-value
+  ` check to check for all functions
+  with specified return types using the ``CheckedReturnTypes`` option.
+
 - Deprecated :doc:`cert-dcl21-cpp
   ` check.
 
Index: clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.h
===
--- clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.h
+++ clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.h
@@ -27,6 +27,7 @@
 
 private:
   std::string CheckedFunctions;
+  const std::vector CheckedReturnTypes;
 };
 
 } // namespace clang::tidy::bugprone
Index: clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
@@ -7,6 +7,7 @@
 //===--===//
 
 #include "UnusedReturnValueCheck.h"
+#include "../utils/Matchers.h"
 #include "../utils/OptionsUtils.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
@@ -27,7 +28,6 @@
   return InnerMatcher.matches(InstantiatedFrom ? *InstantiatedFrom : Node,
   Finder, Builder);
 }
-
 } // namespace
 
 UnusedReturnValueCheck::UnusedReturnValueCheck(llvm::StringRef Name,
@@ -124,19 +124,30 @@
"::sigismember;"
"::strcasecmp;"
"::strsignal;"
-   "::ttyname")) {}
+   "::ttyname")),
+  

[clang-tools-extra] 785b30b - [clang-tidy] Check for specific return types on all functions

2023-05-26 Thread NagaChaitanya Vellanki via cfe-commits

Author: NagaChaitanya Vellanki
Date: 2023-05-26T13:59:18-07:00
New Revision: 785b30b8a33a394a677b1b8ce35c66ba482db169

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

LOG: [clang-tidy] Check for specific return types on all functions

Extend the check to all functions with return types like
 std::error_code, std::expected, boost::system::error_code, 
abseil::Status...

 Resolves issue https://github.com/llvm/llvm-project/issues/62884

Reviewed By: PiotrZSL

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

Added: 


Modified: 
clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.h
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/docs/clang-tidy/checks/bugprone/unused-return-value.rst
clang-tools-extra/test/clang-tidy/checkers/bugprone/unused-return-value.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
index 6049569b5f581..f8139381d7e01 100644
--- a/clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
@@ -7,6 +7,7 @@
 
//===--===//
 
 #include "UnusedReturnValueCheck.h"
+#include "../utils/Matchers.h"
 #include "../utils/OptionsUtils.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
@@ -27,7 +28,6 @@ AST_MATCHER_P(FunctionDecl, isInstantiatedFrom, 
Matcher,
   return InnerMatcher.matches(InstantiatedFrom ? *InstantiatedFrom : Node,
   Finder, Builder);
 }
-
 } // namespace
 
 UnusedReturnValueCheck::UnusedReturnValueCheck(llvm::StringRef Name,
@@ -124,19 +124,30 @@ 
UnusedReturnValueCheck::UnusedReturnValueCheck(llvm::StringRef Name,
"::sigismember;"
"::strcasecmp;"
"::strsignal;"
-   "::ttyname")) {}
+   "::ttyname")),
+  CheckedReturnTypes(utils::options::parseStringList(
+  Options.get("CheckedReturnTypes", "::std::error_code;"
+"::std::expected;"
+"::boost::system::error_code;"
+"::abseil::Status"))) {}
 
 void UnusedReturnValueCheck::storeOptions(ClangTidyOptions::OptionMap ) {
   Options.store(Opts, "CheckedFunctions", CheckedFunctions);
+  Options.store(Opts, "CheckedReturnTypes",
+utils::options::serializeStringList(CheckedReturnTypes));
 }
 
 void UnusedReturnValueCheck::registerMatchers(MatchFinder *Finder) {
   auto FunVec = utils::options::parseStringList(CheckedFunctions);
+
   auto MatchedCallExpr = expr(ignoringImplicit(ignoringParenImpCasts(
   callExpr(callee(functionDecl(
// Don't match void overloads of checked functions.
unless(returns(voidType())),
-   isInstantiatedFrom(hasAnyName(FunVec)
+   anyOf(isInstantiatedFrom(hasAnyName(FunVec)),
+ returns(hasCanonicalType(hasDeclaration(
+ namedDecl(matchers::matchesAnyListedName(
+ CheckedReturnTypes)
   .bind("match";
 
   auto UnusedInCompoundStmt =

diff  --git a/clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.h 
b/clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.h
index f16815b0f839e..15881e12ca0c3 100644
--- a/clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.h
+++ b/clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.h
@@ -27,6 +27,7 @@ class UnusedReturnValueCheck : public ClangTidyCheck {
 
 private:
   std::string CheckedFunctions;
+  const std::vector CheckedReturnTypes;
 };
 
 } // namespace clang::tidy::bugprone

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 980be4869ead8..1eb8c5ba4b71b 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -248,6 +248,10 @@ Changes in existing checks
   constructor initializers. Correctly handle constructor arguments as being
   sequenced when constructor call is written as list-initialization.
 
+- Extend :doc:`bugprone-unused-return-value
+  ` check to check for all 
functions
+  with specified return types using the ``CheckedReturnTypes`` option.
+
 - Deprecated :doc:`cert-dcl21-cpp
   ` check.
 

diff  --git 

[PATCH] D151581: [clang][modules] NFCI: Distinguish written/effective umbrella directories

2023-05-26 Thread Ben Langmuir via Phabricator via cfe-commits
benlangmuir accepted this revision.
benlangmuir added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/include/clang/Basic/Module.h:655
+  /// Retrieve the explicitly written umbrella directory for this module.
+  DirectoryName getWrittenUmbrellaDir() const {
+if (const auto *ME = Umbrella.dyn_cast())

Nit: I would prefer we use the same `...AsWritten` naming scheme for these 
methods that we use for the `UmbrellaAsWritten` field.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151581

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


[PATCH] D151587: [clang][ConstantEmitter] have tryEmitPrivateForVarInit try ConstExprEmitter fast-path first

2023-05-26 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers updated this revision to Diff 526192.
nickdesaulniers added a comment.

- also remove VisitExprWithCleanups, down to two outstanding test failures


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151587

Files:
  clang/lib/CodeGen/CGExprConstant.cpp
  clang/test/CodeGenCXX/const-init-cxx1y.cpp
  clang/test/CodeGenCXX/designated-init.cpp

Index: clang/test/CodeGenCXX/designated-init.cpp
===
--- clang/test/CodeGenCXX/designated-init.cpp
+++ clang/test/CodeGenCXX/designated-init.cpp
@@ -4,7 +4,8 @@
 struct A { int x, y[3]; };
 struct B { A a; };
 
-// CHECK: @b ={{.*}} global %{{[^ ]*}} { %{{[^ ]*}} { i32 1, [3 x i32] [i32 2, i32 5, i32 4] } }
+// CHECK: @b = global %struct.B zeroinitializer, align 4
+
 B b = {(A){1, 2, 3, 4}, .a.y[1] = 5};
 
 union U {
@@ -19,10 +20,10 @@
   C c;
 };
 
-// CHECK: @d1 = {{.*}} { i32 1, [3 x %[[U:.*]]] [%[[U]] { i32 2 }, %[[U]] { i32 5 }, %[[U]] { i32 4 }] }
+// CHECK: @d1 = global %struct.D zeroinitializer, align 4
 D d1 = {(C){1, {{.n=2}, {.f=3}, {.n=4}}}, .c.u[1].n = 5};
 
-// CHECK: @d2 = {{.*}} { i32 1, { %[[U]], float, %[[U]] } { %[[U]] { i32 2 }, float 5.{{0*}}e+00, %[[U]] { i32 4 } } }
+// CHECK: @d2 = global %struct.D zeroinitializer, align 4
 D d2 = {(C){1, 2, 3, 4}, .c.u[1].f = 5};
 
 struct Bitfield {
@@ -34,7 +35,7 @@
   int n;
   Bitfield b;
 };
-// CHECK: @bitfield = {{.*}} { i32 1, { i8, i8, [2 x i8] } { i8 42, i8 2, [2 x i8] undef } }
+// CHECK: @bitfield = global %struct.WithBitfield zeroinitializer, align 4
 WithBitfield bitfield = {1, (Bitfield){2, 3, 4}, .b.b = 5};
 
 struct String {
@@ -43,7 +44,7 @@
 struct WithString {
   String str;
 };
-// CHECK: @string = {{.*}} [12 x i8] c"Hello World\00" } }
+// CHECK: @string = global %struct.WithString zeroinitializer, align 1
 WithString string = {(String){"hello world"}, .str.buffer[0] = 'H', .str.buffer[6] = 'W'};
 
 struct LargeArray {
@@ -52,7 +53,7 @@
 struct WithLargeArray {
   LargeArray arr;
 };
-// CHECK: @large ={{.*}} global { { <{ [11 x i32], [4085 x i32] }> } } { { <{ [11 x i32], [4085 x i32] }> } { <{ [11 x i32], [4085 x i32] }> <{ [11 x i32] [i32 1, i32 2, i32 3, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 10], [4085 x i32] zeroinitializer }> } }
+// CHECK: @large = global %struct.WithLargeArray zeroinitializer, align 4
 WithLargeArray large = {(LargeArray){1, 2, 3}, .arr.arr[10] = 10};
 
 union OverwritePaddingWithBitfield {
@@ -62,5 +63,6 @@
 struct WithOverwritePaddingWithBitfield {
   OverwritePaddingWithBitfield a;
 };
-// CHECK: @overwrite_padding ={{.*}} global { { i8, i8 } } { { i8, i8 } { i8 3, i8 1 } }
+// CHECK: @overwrite_padding = global %struct.WithOverwritePaddingWithBitfield zeroinitializer, align 1
+
 WithOverwritePaddingWithBitfield overwrite_padding = {(OverwritePaddingWithBitfield){1}, .a.bitfield = 3};
Index: clang/test/CodeGenCXX/const-init-cxx1y.cpp
===
--- clang/test/CodeGenCXX/const-init-cxx1y.cpp
+++ clang/test/CodeGenCXX/const-init-cxx1y.cpp
@@ -34,8 +34,8 @@
   // 'c.temporary', not the value as modified by the partial evaluation within
   // the initialization of 'c.x'.
   A c = { 10, (++c.temporary, b.x) };
+  // CHECK: @_ZN21ModifyStaticTemporary1cE = global %"struct.ModifyStaticTemporary::A" zeroinitializer
   // CHECK: @_ZGRN21ModifyStaticTemporary1cE_ = internal global i32 10
-  // CHECK: @_ZN21ModifyStaticTemporary1cE ={{.*}} global {{.*}} zeroinitializer
 }
 
 // CHECK: @_ZGRN28VariableTemplateWithConstRef1iIvEE_ = linkonce_odr constant i32 5, align 4
Index: clang/lib/CodeGen/CGExprConstant.cpp
===
--- clang/lib/CodeGen/CGExprConstant.cpp
+++ clang/lib/CodeGen/CGExprConstant.cpp
@@ -1211,15 +1211,6 @@
 return Visit(DIE->getExpr(), T);
   }
 
-  llvm::Constant *VisitExprWithCleanups(ExprWithCleanups *E, QualType T) {
-return Visit(E->getSubExpr(), T);
-  }
-
-  llvm::Constant *VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E,
-QualType T) {
-return Visit(E->getSubExpr(), T);
-  }
-
   llvm::Constant *EmitArrayInitialization(InitListExpr *ILE, QualType T) {
 auto *CAT = CGM.getContext().getAsConstantArrayType(ILE->getType());
 assert(CAT && "can't emit array init for non-constant-bound array");
@@ -1657,18 +1648,6 @@
 
   // Try to emit the initializer.  Note that this can allow some things that
   // are not allowed by tryEmitPrivateForMemory alone.
-  if (APValue *value = D.evaluateValue())
-return tryEmitPrivateForMemory(*value, destType);
-
-  // FIXME: Implement C++11 [basic.start.init]p2: if the initializer of a
-  // reference is a constant expression, and the reference binds to a temporary,
-  // then constant initialization is performed. ConstExprEmitter will
-  // incorrectly 

[PATCH] D151590: [Driver] Add ClangFlags::TargetSpecific to simplify err_drv_unsupported_opt_for_target processing

2023-05-26 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay created this revision.
MaskRay added reviewers: aaron.ballman, jansvoboda11, pengfei, power-llvm-team.
Herald added subscribers: jrtc27, fedor.sergeev, nemanjai, jyknight.
Herald added a project: All.
MaskRay requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

clang/lib/Driver/ToolChains/Clang.cpp has a lot of fragments like the following:

  if (const Arg *A = Args.getLastArg(...)) {
if (Triple is xxx)
  A->render(Args, CmdArgs);
else
  D.Diag(diag::err_drv_unsupported_opt_for_target) << ...;
  }

The problem is more apparent with a recent surge of AIX-specific options.

Introduce the TargetSpecific flag so that we can move the target-specific
options to ToolChains/*.cpp and ToolChains/Arch/*.cpp and overload the
warn_drv_unused_argument mechanism to give an err_drv_unsupported_opt_for_target
error.

Migrate -march=/-mcpu= and some AIX-specific options to use this simplified 
pattern.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D151590

Files:
  clang/include/clang/Driver/Options.h
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChains/AIX.cpp
  clang/lib/Driver/ToolChains/AIX.h
  clang/lib/Driver/ToolChains/Arch/PPC.cpp
  clang/lib/Driver/ToolChains/Arch/Sparc.cpp
  clang/lib/Driver/ToolChains/Clang.cpp

Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -6142,23 +6142,6 @@
 }
   }
 
-  if (const Arg *A = Args.getLastArg(options::OPT_mignore_xcoff_visibility)) {
-if (Triple.isOSAIX())
-  CmdArgs.push_back("-mignore-xcoff-visibility");
-else
-  D.Diag(diag::err_drv_unsupported_opt_for_target)
-  << A->getAsString(Args) << TripleStr;
-  }
-
-  if (const Arg *A =
-  Args.getLastArg(options::OPT_mdefault_visibility_export_mapping_EQ)) {
-if (Triple.isOSAIX())
-  A->render(Args, CmdArgs);
-else
-  D.Diag(diag::err_drv_unsupported_opt_for_target)
-  << A->getAsString(Args) << TripleStr;
-  }
-
   if (Args.hasFlag(options::OPT_fvisibility_inlines_hidden,
 options::OPT_fno_visibility_inlines_hidden, false))
 CmdArgs.push_back("-fvisibility-inlines-hidden");
@@ -6967,10 +6950,6 @@
   Args.addOptInFlag(CmdArgs, options::OPT_fapple_pragma_pack,
 options::OPT_fno_apple_pragma_pack);
 
-  if (Args.hasFlag(options::OPT_fxl_pragma_pack,
-   options::OPT_fno_xl_pragma_pack, RawTriple.isOSAIX()))
-CmdArgs.push_back("-fxl-pragma-pack");
-
   // Remarks can be enabled with any of the `-f.*optimization-record.*` flags.
   if (willEmitRemarks(Args) && checkRemarksOptions(D, Args, Triple))
 renderRemarksOptions(Args, CmdArgs, Triple, Input, Output, JA);
Index: clang/lib/Driver/ToolChains/Arch/Sparc.cpp
===
--- clang/lib/Driver/ToolChains/Arch/Sparc.cpp
+++ clang/lib/Driver/ToolChains/Arch/Sparc.cpp
@@ -118,12 +118,6 @@
 
 std::string sparc::getSparcTargetCPU(const Driver , const ArgList ,
  const llvm::Triple ) {
-  if (const Arg *A = Args.getLastArg(clang::driver::options::OPT_march_EQ)) {
-D.Diag(diag::err_drv_unsupported_opt_for_target)
-<< A->getSpelling() << Triple.getTriple();
-return "";
-  }
-
   if (const Arg *A = Args.getLastArg(clang::driver::options::OPT_mcpu_EQ)) {
 StringRef CPUName = A->getValue();
 if (CPUName == "native") {
Index: clang/lib/Driver/ToolChains/Arch/PPC.cpp
===
--- clang/lib/Driver/ToolChains/Arch/PPC.cpp
+++ clang/lib/Driver/ToolChains/Arch/PPC.cpp
@@ -87,10 +87,6 @@
 /// Get the (LLVM) name of the PowerPC cpu we are targeting.
 std::string ppc::getPPCTargetCPU(const Driver , const ArgList ,
  const llvm::Triple ) {
-  if (const Arg *A = Args.getLastArg(clang::driver::options::OPT_march_EQ)) {
-D.Diag(diag::err_drv_unsupported_opt_for_target)
-<< A->getSpelling() << T.getTriple();
-  }
   if (Arg *A = Args.getLastArg(clang::driver::options::OPT_mcpu_EQ))
 return normalizeCPUName(A->getValue(), T);
   return getPPCGenericTargetCPU(T);
Index: clang/lib/Driver/ToolChains/AIX.h
===
--- clang/lib/Driver/ToolChains/AIX.h
+++ clang/lib/Driver/ToolChains/AIX.h
@@ -80,6 +80,10 @@
   void AddCXXStdlibLibArgs(const llvm::opt::ArgList ,
llvm::opt::ArgStringList ) const override;
 
+  void addClangTargetOptions(
+  const llvm::opt::ArgList , llvm::opt::ArgStringList ,
+  Action::OffloadKind DeviceOffloadingKind) const override;
+
   void addProfileRTLibs(const llvm::opt::ArgList ,
 llvm::opt::ArgStringList ) const override;
 
Index: 

[PATCH] D151587: [clang][ConstantEmitter] have tryEmitPrivateForVarInit try ConstExprEmitter fast-path first

2023-05-26 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers created this revision.
Herald added a project: All.
nickdesaulniers requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

As suggested by @efriedma in:
https://reviews.llvm.org/D76096#4370369

Signed-off-by: Nick Desaulniers 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D151587

Files:
  clang/lib/CodeGen/CGExprConstant.cpp
  clang/test/CodeGenCXX/const-init-cxx1y.cpp
  clang/test/CodeGenCXX/cxx0x-initializer-references.cpp
  clang/test/CodeGenCXX/designated-init.cpp

Index: clang/test/CodeGenCXX/designated-init.cpp
===
--- clang/test/CodeGenCXX/designated-init.cpp
+++ clang/test/CodeGenCXX/designated-init.cpp
@@ -4,7 +4,8 @@
 struct A { int x, y[3]; };
 struct B { A a; };
 
-// CHECK: @b ={{.*}} global %{{[^ ]*}} { %{{[^ ]*}} { i32 1, [3 x i32] [i32 2, i32 5, i32 4] } }
+// CHECK: @b = global %struct.B zeroinitializer, align 4
+
 B b = {(A){1, 2, 3, 4}, .a.y[1] = 5};
 
 union U {
@@ -19,10 +20,10 @@
   C c;
 };
 
-// CHECK: @d1 = {{.*}} { i32 1, [3 x %[[U:.*]]] [%[[U]] { i32 2 }, %[[U]] { i32 5 }, %[[U]] { i32 4 }] }
+// CHECK: @d1 = global %struct.D zeroinitializer, align 4
 D d1 = {(C){1, {{.n=2}, {.f=3}, {.n=4}}}, .c.u[1].n = 5};
 
-// CHECK: @d2 = {{.*}} { i32 1, { %[[U]], float, %[[U]] } { %[[U]] { i32 2 }, float 5.{{0*}}e+00, %[[U]] { i32 4 } } }
+// CHECK: @d2 = global %struct.D zeroinitializer, align 4
 D d2 = {(C){1, 2, 3, 4}, .c.u[1].f = 5};
 
 struct Bitfield {
@@ -34,7 +35,7 @@
   int n;
   Bitfield b;
 };
-// CHECK: @bitfield = {{.*}} { i32 1, { i8, i8, [2 x i8] } { i8 42, i8 2, [2 x i8] undef } }
+// CHECK: @bitfield = global %struct.WithBitfield zeroinitializer, align 4
 WithBitfield bitfield = {1, (Bitfield){2, 3, 4}, .b.b = 5};
 
 struct String {
@@ -43,7 +44,7 @@
 struct WithString {
   String str;
 };
-// CHECK: @string = {{.*}} [12 x i8] c"Hello World\00" } }
+// CHECK: @string = global %struct.WithString zeroinitializer, align 1
 WithString string = {(String){"hello world"}, .str.buffer[0] = 'H', .str.buffer[6] = 'W'};
 
 struct LargeArray {
@@ -52,7 +53,7 @@
 struct WithLargeArray {
   LargeArray arr;
 };
-// CHECK: @large ={{.*}} global { { <{ [11 x i32], [4085 x i32] }> } } { { <{ [11 x i32], [4085 x i32] }> } { <{ [11 x i32], [4085 x i32] }> <{ [11 x i32] [i32 1, i32 2, i32 3, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 10], [4085 x i32] zeroinitializer }> } }
+// CHECK: @large = global %struct.WithLargeArray zeroinitializer, align 4
 WithLargeArray large = {(LargeArray){1, 2, 3}, .arr.arr[10] = 10};
 
 union OverwritePaddingWithBitfield {
@@ -62,5 +63,6 @@
 struct WithOverwritePaddingWithBitfield {
   OverwritePaddingWithBitfield a;
 };
-// CHECK: @overwrite_padding ={{.*}} global { { i8, i8 } } { { i8, i8 } { i8 3, i8 1 } }
+// CHECK: @overwrite_padding = global %struct.WithOverwritePaddingWithBitfield zeroinitializer, align 1
+
 WithOverwritePaddingWithBitfield overwrite_padding = {(OverwritePaddingWithBitfield){1}, .a.bitfield = 3};
Index: clang/test/CodeGenCXX/cxx0x-initializer-references.cpp
===
--- clang/test/CodeGenCXX/cxx0x-initializer-references.cpp
+++ clang/test/CodeGenCXX/cxx0x-initializer-references.cpp
@@ -6,7 +6,7 @@
 const char (_string_ref)[5] = {"hi"};
 
 // This binds directly to a string literal object.
-// CHECK: @nonextended_string_ref ={{.*}} constant ptr @.str
+// CHECK: @nonextended_string_ref = constant [3 x i8] c"hi\00", align 4
 const char (_string_ref)[3] = {"hi"};
 
 namespace reference {
Index: clang/test/CodeGenCXX/const-init-cxx1y.cpp
===
--- clang/test/CodeGenCXX/const-init-cxx1y.cpp
+++ clang/test/CodeGenCXX/const-init-cxx1y.cpp
@@ -23,11 +23,11 @@
   struct A { int & int x; };
   constexpr int f(int ) { r *= 9; return r - 12; }
   A a = { 6, f(a.temporary) };
-  // CHECK: @_ZGRN21ModifyStaticTemporary1aE_ = internal global i32 54
+  // CHECK: @_ZGRN21ModifyStaticTemporary1aE_ = internal global i32 6, align 4
   // CHECK: @_ZN21ModifyStaticTemporary1aE ={{.*}} global {{.*}} ptr @_ZGRN21ModifyStaticTemporary1aE_, i32 42
 
   A b = { 7, ++b.temporary };
-  // CHECK: @_ZGRN21ModifyStaticTemporary1bE_ = internal global i32 8
+  // CHECK: @_ZGRN21ModifyStaticTemporary1bE_ = internal global i32 7, align 4
   // CHECK: @_ZN21ModifyStaticTemporary1bE ={{.*}} global {{.*}} ptr @_ZGRN21ModifyStaticTemporary1bE_, i32 8
 
   // Can't emit all of 'c' as a constant here, so emit the initial value of
Index: clang/lib/CodeGen/CGExprConstant.cpp
===
--- clang/lib/CodeGen/CGExprConstant.cpp
+++ clang/lib/CodeGen/CGExprConstant.cpp
@@ -1215,11 +1215,6 @@
 return Visit(E->getSubExpr(), T);
   }
 
-  llvm::Constant *VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E,
-   

[PATCH] D151586: [clang][modules] NFCI: Extract optionality out of `Module::{Header,DirectoryName}`

2023-05-26 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 created this revision.
jansvoboda11 added reviewers: benlangmuir, bnbarham.
Herald added a subscriber: ributzka.
Herald added a project: All.
jansvoboda11 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Most users of `Module::Header` already assume its `Entry` is populated. Enforce 
this assumption in the type system and handle the only case where this is not 
the case by wrapping the whole struct in `std::optional`. Do the same for 
`Module::DirectoryName`.

Depends on D151584 .


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D151586

Files:
  clang/include/clang/Basic/Module.h
  clang/lib/Basic/Module.cpp
  clang/lib/Frontend/FrontendAction.cpp
  clang/lib/Lex/ModuleMap.cpp
  clang/lib/Lex/PPLexerChange.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp

Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -2849,11 +2849,11 @@
 if (auto UmbrellaHeader = Mod->getWrittenUmbrellaHeader()) {
   RecordData::value_type Record[] = {SUBMODULE_UMBRELLA_HEADER};
   Stream.EmitRecordWithBlob(UmbrellaAbbrev, Record,
-UmbrellaHeader.NameAsWritten);
+UmbrellaHeader->NameAsWritten);
 } else if (auto UmbrellaDir = Mod->getWrittenUmbrellaDir()) {
   RecordData::value_type Record[] = {SUBMODULE_UMBRELLA_DIR};
   Stream.EmitRecordWithBlob(UmbrellaDirAbbrev, Record,
-UmbrellaDir.NameAsWritten);
+UmbrellaDir->NameAsWritten);
 }
 
 // Emit the headers.
Index: clang/lib/Serialization/ASTReader.cpp
===
--- clang/lib/Serialization/ASTReader.cpp
+++ clang/lib/Serialization/ASTReader.cpp
@@ -1973,10 +1973,11 @@
 std::string Filename = std::string(key.Filename);
 if (key.Imported)
   Reader.ResolveImportedPath(M, Filename);
-// FIXME: NameAsWritten
-Module::Header H = {std::string(key.Filename), "",
-FileMgr.getOptionalFileRef(Filename)};
-ModMap.addHeader(Mod, H, HeaderRole, /*Imported*/true);
+if (auto FE = FileMgr.getOptionalFileRef(Filename)) {
+  // FIXME: NameAsWritten
+  Module::Header H = {std::string(key.Filename), "", *FE};
+  ModMap.addHeader(Mod, H, HeaderRole, /*Imported=*/true);
+}
 HFI.isModuleHeader |= ModuleMap::isModular(HeaderRole);
   }
 
Index: clang/lib/Lex/PPLexerChange.cpp
===
--- clang/lib/Lex/PPLexerChange.cpp
+++ clang/lib/Lex/PPLexerChange.cpp
@@ -289,9 +289,9 @@
 }
 
 void Preprocessor::diagnoseMissingHeaderInUmbrellaDir(const Module ) {
-  Module::Header UmbrellaHeader = Mod.getWrittenUmbrellaHeader();
-  assert(UmbrellaHeader.Entry && "Module must use umbrella header");
-  const FileID  = SourceMgr.translateFile(UmbrellaHeader.Entry);
+  auto UmbrellaHeader = Mod.getWrittenUmbrellaHeader();
+  assert(UmbrellaHeader && "Module must use umbrella header");
+  const FileID  = SourceMgr.translateFile(UmbrellaHeader->Entry);
   SourceLocation ExpectedHeadersLoc = SourceMgr.getLocForEndOfFile(File);
   if (getDiagnostics().isIgnored(diag::warn_uncovered_module_header,
  ExpectedHeadersLoc))
Index: clang/lib/Lex/ModuleMap.cpp
===
--- clang/lib/Lex/ModuleMap.cpp
+++ clang/lib/Lex/ModuleMap.cpp
@@ -1291,7 +1291,7 @@
 
   // Notify callbacks that we just added a new header.
   for (const auto  : Callbacks)
-Cb->moduleMapAddHeader(Header.Entry->getName());
+Cb->moduleMapAddHeader(Header.Entry.getName());
 }
 
 OptionalFileEntryRef
@@ -2543,7 +2543,7 @@
 for (llvm::vfs::recursive_directory_iterator I(FS, Dir->getName(), EC), E;
  I != E && !EC; I.increment(EC)) {
   if (auto FE = SourceMgr.getFileManager().getOptionalFileRef(I->path())) {
-Module::Header Header = {"", std::string(I->path()), FE};
+Module::Header Header = {"", std::string(I->path()), *FE};
 Headers.push_back(std::move(Header));
   }
 }
Index: clang/lib/Frontend/FrontendAction.cpp
===
--- clang/lib/Frontend/FrontendAction.cpp
+++ clang/lib/Frontend/FrontendAction.cpp
@@ -365,16 +365,16 @@
   // Note that Module->PrivateHeaders will not be a TopHeader.
 
   if (auto UmbrellaHeader = Module->getWrittenUmbrellaHeader()) {
-Module->addTopHeader(UmbrellaHeader.Entry);
+Module->addTopHeader(UmbrellaHeader->Entry);
 if (Module->Parent)
   // Include the umbrella header for submodules.
-  addHeaderInclude(UmbrellaHeader.PathRelativeToRootModuleDirectory,
+  

[PATCH] D148723: [clang] Restrict Inline Builtin to non-static, non-odr linkage

2023-05-26 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 added a comment.

In D148723#4376946 , 
@serge-sans-paille wrote:

> @jyu2 : could you test that patch in your setup ? Also I can't find the bug 
> id associated with your original bug anymore...

I just submit bug in https://github.com/llvm/llvm-project/issues/62958 and 
assign that to you.


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

https://reviews.llvm.org/D148723

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


[PATCH] D151383: [clang-tidy] Check for specific return types on all functions

2023-05-26 Thread NagaChaitanya Vellanki via Phabricator via cfe-commits
chaitanyav added a comment.

In D151383#4377043 , @PiotrZSL wrote:

> LGTM, you may consider reducing commit message (aka review description by 
> removing example and error from it, and leaving just plain description of a 
> change).

got it, will make sure to remove them from the arc generated commit message.




Comment at: clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp:159
+   anyOf(isInstantiatedFrom(hasAnyName(FunVec)),
+ hasAnyReturnType(RetTypeVec)
   .bind("match";

PiotrZSL wrote:
> Consider:
> 
> hasAnyReturnType -> 
> `returns(hasCanonicalType(hasDeclaration(namedDecl(matchers::matchesAnyListedName(RetTypeVec`
> Note that to use matchesAnyListedName, you should save RetTypeVec  as class 
> member, just to be safe.
I followed the code in ForRangeCopyCheck.cpp and made the changes accordingly.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151383

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


[PATCH] D151383: [clang-tidy] Check for specific return types on all functions

2023-05-26 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL accepted this revision.
PiotrZSL added a comment.

LGTM, you may consider reducing commit message (aka review description by 
removing example and error from it, and leaving just plain description of a 
change).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151383

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


[PATCH] D150430: Implement BufferOverlap check for sprint/snprintf

2023-05-26 Thread Arnaud Bienner via Phabricator via cfe-commits
ArnaudBienner added a comment.

@steakhal did you get a chance to look at my comment?

I would really love to see this merged upstream if you think this could be a 
beneficial change :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150430

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


[PATCH] D151584: [clang][modules] NFCI: Use `DirectoryEntryRef` for umbrella directory

2023-05-26 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 created this revision.
jansvoboda11 added reviewers: benlangmuir, bnbarham.
Herald added a subscriber: ributzka.
Herald added a project: All.
jansvoboda11 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This removes some deprecated uses of `DirectoryEntry::getName()`.

Depends on D151581 .


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D151584

Files:
  clang/include/clang/Basic/Module.h
  clang/include/clang/Lex/ModuleMap.h
  clang/lib/Basic/Module.cpp
  clang/lib/Lex/ModuleMap.cpp
  clang/lib/Lex/PPLexerChange.cpp
  clang/lib/Serialization/ASTReader.cpp

Index: clang/lib/Serialization/ASTReader.cpp
===
--- clang/lib/Serialization/ASTReader.cpp
+++ clang/lib/Serialization/ASTReader.cpp
@@ -5750,7 +5750,8 @@
   // See comments in SUBMODULE_UMBRELLA_HEADER
   std::string Dirname = std::string(Blob);
   ResolveImportedPath(F, Dirname);
-  if (auto Umbrella = PP.getFileManager().getDirectory(Dirname)) {
+  if (auto Umbrella =
+  PP.getFileManager().getOptionalDirectoryRef(Dirname)) {
 if (!CurrentModule->getWrittenUmbrellaDir()) {
   // FIXME: NameAsWritten
   ModMap.setWrittenUmbrellaDir(CurrentModule, *Umbrella, Blob, "");
Index: clang/lib/Lex/PPLexerChange.cpp
===
--- clang/lib/Lex/PPLexerChange.cpp
+++ clang/lib/Lex/PPLexerChange.cpp
@@ -298,7 +298,7 @@
 return;
 
   ModuleMap  = getHeaderSearchInfo().getModuleMap();
-  const DirectoryEntry *Dir = Mod.getEffectiveUmbrellaDir();
+  OptionalDirectoryEntryRef Dir = Mod.getEffectiveUmbrellaDir();
   llvm::vfs::FileSystem  = FileMgr.getVirtualFileSystem();
   std::error_code EC;
   for (llvm::vfs::recursive_directory_iterator Entry(FS, Dir->getName(), EC),
@@ -318,7 +318,7 @@
 if (!ModMap.isHeaderInUnavailableModule(*Header)) {
   // Find the relative path that would access this header.
   SmallString<128> RelativePath;
-  computeRelativePath(FileMgr, Dir, *Header, RelativePath);
+  computeRelativePath(FileMgr, *Dir, *Header, RelativePath);
   Diag(ExpectedHeadersLoc, diag::warn_uncovered_module_header)
   << Mod.getFullModuleName() << RelativePath;
 }
Index: clang/lib/Lex/ModuleMap.cpp
===
--- clang/lib/Lex/ModuleMap.cpp
+++ clang/lib/Lex/ModuleMap.cpp
@@ -1186,9 +1186,9 @@
 }
 
 void ModuleMap::setWrittenUmbrellaDir(
-Module *Mod, const DirectoryEntry *UmbrellaDir, const Twine ,
+Module *Mod, DirectoryEntryRef UmbrellaDir, const Twine ,
 const Twine ) {
-  Mod->Umbrella = UmbrellaDir;
+  Mod->Umbrella = ();
   Mod->UmbrellaAsWritten = NameAsWritten.str();
   Mod->UmbrellaRelativeToRootModuleDirectory =
   PathRelativeToRootModuleDirectory.str();
@@ -2515,16 +2515,14 @@
   }
 
   // Look for this file.
-  const DirectoryEntry *Dir = nullptr;
+  OptionalDirectoryEntryRef Dir;
   if (llvm::sys::path::is_absolute(DirName)) {
-if (auto D = SourceMgr.getFileManager().getDirectory(DirName))
-  Dir = *D;
+Dir = SourceMgr.getFileManager().getOptionalDirectoryRef(DirName);
   } else {
 SmallString<128> PathName;
 PathName = Directory->getName();
 llvm::sys::path::append(PathName, DirName);
-if (auto D = SourceMgr.getFileManager().getDirectory(PathName))
-  Dir = *D;
+Dir = SourceMgr.getFileManager().getOptionalDirectoryRef(PathName);
   }
 
   if (!Dir) {
@@ -2558,7 +2556,7 @@
 return;
   }
 
-  if (Module *OwningModule = Map.UmbrellaDirs[Dir]) {
+  if (Module *OwningModule = Map.UmbrellaDirs[*Dir]) {
 Diags.Report(UmbrellaLoc, diag::err_mmap_umbrella_clash)
   << OwningModule->getFullModuleName();
 HadError = true;
@@ -2566,7 +2564,7 @@
   }
 
   // Record this umbrella directory.
-  Map.setWrittenUmbrellaDir(ActiveModule, Dir, DirNameAsWritten, DirName);
+  Map.setWrittenUmbrellaDir(ActiveModule, *Dir, DirNameAsWritten, DirName);
 }
 
 /// Parse a module export declaration.
Index: clang/lib/Basic/Module.cpp
===
--- clang/lib/Basic/Module.cpp
+++ clang/lib/Basic/Module.cpp
@@ -263,12 +263,12 @@
   return nameParts.empty();
 }
 
-const DirectoryEntry *Module::getEffectiveUmbrellaDir() const {
+OptionalDirectoryEntryRef Module::getEffectiveUmbrellaDir() const {
   if (const auto *ME = Umbrella.dyn_cast())
 return FileEntryRef(*ME).getDir();
-  if (const auto *ME = Umbrella.dyn_cast())
-return ME;
-  return nullptr;
+  if (const auto *ME = Umbrella.dyn_cast())
+return DirectoryEntryRef(*ME);
+  return std::nullopt;
 }
 
 void Module::addTopHeader(const FileEntry *File) {
Index: clang/include/clang/Lex/ModuleMap.h
===
--- 

[PATCH] D151383: [clang-tidy] Check for specific return types on all functions

2023-05-26 Thread NagaChaitanya Vellanki via Phabricator via cfe-commits
chaitanyav updated this revision to Diff 526173.
chaitanyav marked an inline comment as done.
chaitanyav added a comment.

use fully qualified name in code and documentation


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151383

Files:
  clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/bugprone/unused-return-value.rst
  clang-tools-extra/test/clang-tidy/checkers/bugprone/unused-return-value.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone/unused-return-value.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone/unused-return-value.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone/unused-return-value.cpp
@@ -52,6 +52,9 @@
   bool empty() const noexcept;
 };
 
+class error_code {
+};
+
 // the check should be able to match std lib calls even if the functions are
 // declared inside inline namespaces
 inline namespace v1 {
@@ -72,6 +75,10 @@
 
 void useFuture(const std::future );
 
+std::error_code errorFunc() {
+return std::error_code();
+}
+
 void warning() {
   std::async(increment, 42);
   // CHECK-NOTES: [[@LINE-1]]:3: warning: the value returned by this function should be used
@@ -185,6 +192,10 @@
 // CHECK-NOTES: [[@LINE-1]]:5: warning: the value {{.*}} should be used
 // CHECK-NOTES: [[@LINE-2]]:5: note: cast {{.*}} this warning
   }
+
+  errorFunc();
+  // CHECK-NOTES: [[@LINE-1]]:3: warning: the value {{.*}} should be used
+  // CHECK-NOTES: [[@LINE-2]]:3: note: cast {{.*}} this warning
 }
 
 void noWarning() {
@@ -209,6 +220,8 @@
   std::vector VecNoWarning;
   auto VecEmptyRetval = VecNoWarning.empty();
 
+  (void) errorFunc();
+
   // test using the return value in different kinds of expressions
   useFuture(std::async(increment, 42));
   std::launder()->f();
Index: clang-tools-extra/docs/clang-tidy/checks/bugprone/unused-return-value.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/bugprone/unused-return-value.rst
+++ clang-tools-extra/docs/clang-tidy/checks/bugprone/unused-return-value.rst
@@ -46,5 +46,11 @@
  return value often indicates that the programmer confused the function with
  ``clear()``.
 
+.. option:: CheckedReturnTypes
+
+   Semicolon-separated list of function return types to check.
+   By default the following function return types are checked:
+   `::std::error_code`, `::std::expected`, `::boost::system::error_code`, `::abseil::Status`
+
 `cert-err33-c <../cert/err33-c.html>`_ is an alias of this check that checks a
 fixed and large set of standard library functions.
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -248,6 +248,10 @@
   constructor initializers. Correctly handle constructor arguments as being
   sequenced when constructor call is written as list-initialization.
 
+- Extend :doc:`bugprone-unused-return-value
+  ` check to check for all functions
+  with specified return types using the ``CheckedReturnTypes`` option.
+
 - Deprecated :doc:`cert-dcl21-cpp
   ` check.
 
Index: clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.h
===
--- clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.h
+++ clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.h
@@ -27,6 +27,7 @@
 
 private:
   std::string CheckedFunctions;
+  const std::vector CheckedReturnTypes;
 };
 
 } // namespace clang::tidy::bugprone
Index: clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
@@ -7,6 +7,7 @@
 //===--===//
 
 #include "UnusedReturnValueCheck.h"
+#include "../utils/Matchers.h"
 #include "../utils/OptionsUtils.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
@@ -27,7 +28,6 @@
   return InnerMatcher.matches(InstantiatedFrom ? *InstantiatedFrom : Node,
   Finder, Builder);
 }
-
 } // namespace
 
 UnusedReturnValueCheck::UnusedReturnValueCheck(llvm::StringRef Name,
@@ -124,19 +124,30 @@
"::sigismember;"
"::strcasecmp;"
"::strsignal;"
-   "::ttyname")) {}
+   "::ttyname")),
+  

[PATCH] D151503: [CUDA] correctly install cuda_wrappers/bits/shared_ptr_base.h

2023-05-26 Thread Qiongsi Wu via Phabricator via cfe-commits
qiongsiwu1 added inline comments.



Comment at: clang/lib/Headers/CMakeLists.txt:516
   COMPONENT cuda-resource-headers)
 
 install(

Do we need an install target for `${cuda_wrapper_bits_files}` for the 
`cuda-resource-headers` component as well? It seems to be the case because this 
patch is treating `${cuda_wrapper_bits_files}` as part of 
`cuda-resource-headers`.

```
add_header_target("cuda-resource-headers" 
"${cuda_files};${cuda_wrapper_files};${cuda_wrapper_bits_files}")
```




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151503

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


[PATCH] D148723: [clang] Restrict Inline Builtin to non-static, non-odr linkage

2023-05-26 Thread serge via Phabricator via cfe-commits
serge-sans-paille added a comment.

@jyu2 : could you test that patch in your setup ? Also I can't find the bug id 
associated with your original bug anymore...


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

https://reviews.llvm.org/D148723

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


[PATCH] D32199: [TySan] A Type Sanitizer (Clang)

2023-05-26 Thread Florian Hahn via Phabricator via cfe-commits
fhahn updated this revision to Diff 526163.
fhahn added a comment.

Rebased


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D32199

Files:
  clang/include/clang/Basic/Features.def
  clang/include/clang/Basic/Sanitizers.def
  clang/include/clang/Driver/SanitizerArgs.h
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/CodeGen/CGDecl.cpp
  clang/lib/CodeGen/CGDeclCXX.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenTBAA.cpp
  clang/lib/CodeGen/SanitizerMetadata.cpp
  clang/lib/CodeGen/SanitizerMetadata.h
  clang/lib/Driver/SanitizerArgs.cpp
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/lib/Driver/ToolChains/Darwin.cpp
  clang/lib/Driver/ToolChains/Linux.cpp
  clang/test/CodeGen/sanitize-type-attr.cpp
  clang/test/Driver/sanitizer-ld.c

Index: clang/test/Driver/sanitizer-ld.c
===
--- clang/test/Driver/sanitizer-ld.c
+++ clang/test/Driver/sanitizer-ld.c
@@ -268,6 +268,28 @@
 // CHECK-ASAN-MYRIAD-NOT: "-lc"
 // CHECK-ASAN-MYRIAD: libclang_rt.asan-sparcel.a"
 
+// RUN: %clangxx %s -### -o %t.o 2>&1 \
+// RUN: --target=x86_64-unknown-linux -fuse-ld=ld -stdlib=platform -lstdc++ \
+// RUN: -fsanitize=type \
+// RUN: -resource-dir=%S/Inputs/resource_dir \
+// RUN: --sysroot=%S/Inputs/basic_linux_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-TYSAN-LINUX-CXX %s
+//
+// CHECK-TYSAN-LINUX-CXX: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
+// CHECK-TYSAN-LINUX-CXX-NOT: stdc++
+// CHECK-TYSAN-LINUX-CXX: "--whole-archive" "{{.*}}libclang_rt.tysan{{[^.]*}}.a" "--no-whole-archive"
+// CHECK-TYSAN-LINUX-CXX: stdc++
+
+// RUN: %clangxx -fsanitize=type -### %s 2>&1 \
+// RUN: -mmacosx-version-min=10.6 \
+// RUN: --target=x86_64-apple-darwin13.4.0 -fuse-ld=ld -stdlib=platform \
+// RUN: -resource-dir=%S/Inputs/resource_dir \
+// RUN: --sysroot=%S/Inputs/basic_linux_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-TYSAN-DARWIN-CXX %s
+// CHECK-TYSAN-DARWIN-CXX: "{{.*}}ld{{(.exe)?}}"
+// CHECK-TYSAN-DARWIN-CXX: libclang_rt.tysan_osx_dynamic.dylib
+// CHECK-TYSAN-DARWIN-CXX-NOT: -lc++abi
+
 // RUN: %clangxx -### %s 2>&1 \
 // RUN: --target=x86_64-unknown-linux -fuse-ld=ld -stdlib=platform -lstdc++ \
 // RUN: -fsanitize=thread \
Index: clang/test/CodeGen/sanitize-type-attr.cpp
===
--- /dev/null
+++ clang/test/CodeGen/sanitize-type-attr.cpp
@@ -0,0 +1,74 @@
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -o - %s | FileCheck -check-prefix=WITHOUT %s
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -o - %s -fsanitize=type | FileCheck -check-prefix=TYSAN %s
+// RUN: echo "src:%s" | sed -e 's/\\//g' > %t
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -o - %s -fsanitize=type -fsanitize-blacklist=%t | FileCheck -check-prefix=BL %s
+
+// The sanitize_type attribute should be attached to functions
+// when TypeSanitizer is enabled, unless no_sanitize("type") attribute
+// is present.
+
+// WITHOUT:  NoTYSAN1{{.*}}) [[NOATTR:#[0-9]+]]
+// BL:  NoTYSAN1{{.*}}) [[NOATTR:#[0-9]+]]
+// TYSAN:  NoTYSAN1{{.*}}) [[NOATTR:#[0-9]+]]
+__attribute__((no_sanitize("type"))) int NoTYSAN1(int *a) { return *a; }
+
+// WITHOUT:  NoTYSAN2{{.*}}) [[NOATTR]]
+// BL:  NoTYSAN2{{.*}}) [[NOATTR]]
+// TYSAN:  NoTYSAN2{{.*}}) [[NOATTR]]
+__attribute__((no_sanitize("type"))) int NoTYSAN2(int *a);
+int NoTYSAN2(int *a) { return *a; }
+
+// WITHOUT:  NoTYSAN3{{.*}}) [[NOATTR:#[0-9]+]]
+// BL:  NoTYSAN3{{.*}}) [[NOATTR:#[0-9]+]]
+// TYSAN:  NoTYSAN3{{.*}}) [[NOATTR:#[0-9]+]]
+__attribute__((no_sanitize("type"))) int NoTYSAN3(int *a) { return *a; }
+
+// WITHOUT:  TYSANOk{{.*}}) [[NOATTR]]
+// BL:  TYSANOk{{.*}}) [[NOATTR]]
+// TYSAN: TYSANOk{{.*}}) [[WITH:#[0-9]+]]
+int TYSANOk(int *a) { return *a; }
+
+// WITHOUT:  TemplateTYSANOk{{.*}}) [[NOATTR]]
+// BL:  TemplateTYSANOk{{.*}}) [[NOATTR]]
+// TYSAN: TemplateTYSANOk{{.*}}) [[WITH]]
+template 
+int TemplateTYSANOk() { return i; }
+
+// WITHOUT:  TemplateNoTYSAN{{.*}}) [[NOATTR]]
+// BL:  TemplateNoTYSAN{{.*}}) [[NOATTR]]
+// TYSAN: TemplateNoTYSAN{{.*}}) [[NOATTR]]
+template 
+__attribute__((no_sanitize("type"))) int TemplateNoTYSAN() { return i; }
+
+int force_instance = TemplateTYSANOk<42>() + TemplateNoTYSAN<42>();
+
+// Check that __cxx_global_var_init* get the sanitize_type attribute.
+int global1 = 0;
+int global2 = *(int *)((char *) + 1);
+// WITHOUT: @__cxx_global_var_init{{.*}}[[NOATTR:#[0-9]+]]
+// BL: @__cxx_global_var_init{{.*}}[[NOATTR:#[0-9]+]]
+// TYSAN: @__cxx_global_var_init{{.*}}[[WITH:#[0-9]+]]
+
+// Make sure that we don't add globals to the list for which we don't have a
+// specific type description.
+// FIXME: We now have a type description for this type and a global is added. Should it?
+struct SX {
+  int a, b;
+};
+SX sx;
+
+// WITHOUT: attributes 

[PATCH] D151383: [clang-tidy] Check for specific return types on all functions

2023-05-26 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL accepted this revision.
PiotrZSL added inline comments.
This revision is now accepted and ready to land.



Comment at: clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp:129
+  CheckedReturnTypes(utils::options::parseStringList(
+  Options.get("CheckedReturnTypes", "std::error_code;"
+"std::expected;"

good but put those all as fully qualified names (starting with ::) like in 
Checkedfunctions, and align documentation



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/bugprone/unused-return-value.rst:53
+   By default the following function return types are checked:
+   `std::error_code, std::expected, boost::system::error_code, abseil::Status`
+

split this, into `::std::error_code`, `::std::expected`, and so on...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151383

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


[PATCH] D151383: [clang-tidy] Check for specific return types on all functions

2023-05-26 Thread NagaChaitanya Vellanki via Phabricator via cfe-commits
chaitanyav updated this revision to Diff 526159.
chaitanyav marked 4 inline comments as done.
chaitanyav added a comment.

Make changes as per comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151383

Files:
  clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/bugprone/unused-return-value.rst
  clang-tools-extra/test/clang-tidy/checkers/bugprone/unused-return-value.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone/unused-return-value.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone/unused-return-value.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone/unused-return-value.cpp
@@ -52,6 +52,9 @@
   bool empty() const noexcept;
 };
 
+class error_code {
+};
+
 // the check should be able to match std lib calls even if the functions are
 // declared inside inline namespaces
 inline namespace v1 {
@@ -72,6 +75,10 @@
 
 void useFuture(const std::future );
 
+std::error_code errorFunc() {
+return std::error_code();
+}
+
 void warning() {
   std::async(increment, 42);
   // CHECK-NOTES: [[@LINE-1]]:3: warning: the value returned by this function should be used
@@ -185,6 +192,10 @@
 // CHECK-NOTES: [[@LINE-1]]:5: warning: the value {{.*}} should be used
 // CHECK-NOTES: [[@LINE-2]]:5: note: cast {{.*}} this warning
   }
+
+  errorFunc();
+  // CHECK-NOTES: [[@LINE-1]]:3: warning: the value {{.*}} should be used
+  // CHECK-NOTES: [[@LINE-2]]:3: note: cast {{.*}} this warning
 }
 
 void noWarning() {
@@ -209,6 +220,8 @@
   std::vector VecNoWarning;
   auto VecEmptyRetval = VecNoWarning.empty();
 
+  (void) errorFunc();
+
   // test using the return value in different kinds of expressions
   useFuture(std::async(increment, 42));
   std::launder()->f();
Index: clang-tools-extra/docs/clang-tidy/checks/bugprone/unused-return-value.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/bugprone/unused-return-value.rst
+++ clang-tools-extra/docs/clang-tidy/checks/bugprone/unused-return-value.rst
@@ -46,5 +46,11 @@
  return value often indicates that the programmer confused the function with
  ``clear()``.
 
+.. option:: CheckedReturnTypes
+
+   Semicolon-separated list of function return types to check.
+   By default the following function return types are checked:
+   `std::error_code, std::expected, boost::system::error_code, abseil::Status`
+
 `cert-err33-c <../cert/err33-c.html>`_ is an alias of this check that checks a
 fixed and large set of standard library functions.
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -248,6 +248,10 @@
   constructor initializers. Correctly handle constructor arguments as being
   sequenced when constructor call is written as list-initialization.
 
+- Extend :doc:`bugprone-unused-return-value
+  ` check to check for all functions
+  with specified return types using the ``CheckedReturnTypes`` option.
+
 - Deprecated :doc:`cert-dcl21-cpp
   ` check.
 
Index: clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.h
===
--- clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.h
+++ clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.h
@@ -27,6 +27,7 @@
 
 private:
   std::string CheckedFunctions;
+  const std::vector CheckedReturnTypes;
 };
 
 } // namespace clang::tidy::bugprone
Index: clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
@@ -7,6 +7,7 @@
 //===--===//
 
 #include "UnusedReturnValueCheck.h"
+#include "../utils/Matchers.h"
 #include "../utils/OptionsUtils.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
@@ -27,7 +28,6 @@
   return InnerMatcher.matches(InstantiatedFrom ? *InstantiatedFrom : Node,
   Finder, Builder);
 }
-
 } // namespace
 
 UnusedReturnValueCheck::UnusedReturnValueCheck(llvm::StringRef Name,
@@ -124,19 +124,30 @@
"::sigismember;"
"::strcasecmp;"
"::strsignal;"
-   "::ttyname")) {}
+   "::ttyname")),
+  CheckedReturnTypes(utils::options::parseStringList(
+  

[PATCH] D151581: [clang][modules] NFCI: Distinguish written/effective umbrella directories

2023-05-26 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 created this revision.
jansvoboda11 added reviewers: benlangmuir, bnbarham.
Herald added a subscriber: ributzka.
Herald added a project: All.
jansvoboda11 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

For modules with umbrellas, we track how they were written in the module map. 
Unfortunately, the getter for the umbrella directory conflates the "as written" 
directory and the "effective" directory (either the written one or the parent 
of the written umbrella header).

This patch makes the distinction between "as written" and "effective" umbrella 
directories clearer. No functional change intended.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D151581

Files:
  clang/include/clang/Basic/Module.h
  clang/include/clang/Lex/ModuleMap.h
  clang/lib/Basic/Module.cpp
  clang/lib/Frontend/FrontendAction.cpp
  clang/lib/Lex/ModuleMap.cpp
  clang/lib/Lex/PPLexerChange.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp

Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -2846,11 +2846,11 @@
 }
 
 // Emit the umbrella header, if there is one.
-if (auto UmbrellaHeader = Mod->getUmbrellaHeader()) {
+if (auto UmbrellaHeader = Mod->getWrittenUmbrellaHeader()) {
   RecordData::value_type Record[] = {SUBMODULE_UMBRELLA_HEADER};
   Stream.EmitRecordWithBlob(UmbrellaAbbrev, Record,
 UmbrellaHeader.NameAsWritten);
-} else if (auto UmbrellaDir = Mod->getUmbrellaDir()) {
+} else if (auto UmbrellaDir = Mod->getWrittenUmbrellaDir()) {
   RecordData::value_type Record[] = {SUBMODULE_UMBRELLA_DIR};
   Stream.EmitRecordWithBlob(UmbrellaDirAbbrev, Record,
 UmbrellaDir.NameAsWritten);
Index: clang/lib/Serialization/ASTReader.cpp
===
--- clang/lib/Serialization/ASTReader.cpp
+++ clang/lib/Serialization/ASTReader.cpp
@@ -5713,9 +5713,9 @@
   std::string Filename = std::string(Blob);
   ResolveImportedPath(F, Filename);
   if (auto Umbrella = PP.getFileManager().getOptionalFileRef(Filename)) {
-if (!CurrentModule->getUmbrellaHeader()) {
+if (!CurrentModule->getWrittenUmbrellaHeader()) {
   // FIXME: NameAsWritten
-  ModMap.setUmbrellaHeader(CurrentModule, *Umbrella, Blob, "");
+  ModMap.setWrittenUmbrellaHeader(CurrentModule, *Umbrella, Blob, "");
 }
 // Note that it's too late at this point to return out of date if the
 // name from the PCM doesn't match up with the one in the module map,
@@ -5751,9 +5751,9 @@
   std::string Dirname = std::string(Blob);
   ResolveImportedPath(F, Dirname);
   if (auto Umbrella = PP.getFileManager().getDirectory(Dirname)) {
-if (!CurrentModule->getUmbrellaDir()) {
+if (!CurrentModule->getWrittenUmbrellaDir()) {
   // FIXME: NameAsWritten
-  ModMap.setUmbrellaDir(CurrentModule, *Umbrella, Blob, "");
+  ModMap.setWrittenUmbrellaDir(CurrentModule, *Umbrella, Blob, "");
 }
   }
   break;
Index: clang/lib/Lex/PPLexerChange.cpp
===
--- clang/lib/Lex/PPLexerChange.cpp
+++ clang/lib/Lex/PPLexerChange.cpp
@@ -282,14 +282,14 @@
 
 static void collectAllSubModulesWithUmbrellaHeader(
 const Module , SmallVectorImpl ) {
-  if (Mod.getUmbrellaHeader())
+  if (Mod.getWrittenUmbrellaHeader())
 SubMods.push_back();
   for (auto *M : Mod.submodules())
 collectAllSubModulesWithUmbrellaHeader(*M, SubMods);
 }
 
 void Preprocessor::diagnoseMissingHeaderInUmbrellaDir(const Module ) {
-  const Module::Header  = Mod.getUmbrellaHeader();
+  Module::Header UmbrellaHeader = Mod.getWrittenUmbrellaHeader();
   assert(UmbrellaHeader.Entry && "Module must use umbrella header");
   const FileID  = SourceMgr.translateFile(UmbrellaHeader.Entry);
   SourceLocation ExpectedHeadersLoc = SourceMgr.getLocForEndOfFile(File);
@@ -298,7 +298,7 @@
 return;
 
   ModuleMap  = getHeaderSearchInfo().getModuleMap();
-  const DirectoryEntry *Dir = Mod.getUmbrellaDir().Entry;
+  const DirectoryEntry *Dir = Mod.getEffectiveUmbrellaDir();
   llvm::vfs::FileSystem  = FileMgr.getVirtualFileSystem();
   std::error_code EC;
   for (llvm::vfs::recursive_directory_iterator Entry(FS, Dir->getName(), EC),
Index: clang/lib/Lex/ModuleMap.cpp
===
--- clang/lib/Lex/ModuleMap.cpp
+++ clang/lib/Lex/ModuleMap.cpp
@@ -266,7 +266,8 @@
   << UmbrellaMod->getFullModuleName();
   else
 // Record this umbrella header.
-setUmbrellaHeader(Mod, *File, Header.FileName, RelativePathName.str());
+setWrittenUmbrellaHeader(Mod, 

[PATCH] D151578: [Format/ObjC] Support NS_ASSUME_NONNULL_BEGIN and FOUNDATION_EXPORT in ObjC language guesser

2023-05-26 Thread Ben Hamilton via Phabricator via cfe-commits
benhamilton updated this revision to Diff 526154.
benhamilton added a comment.

Add `FOUNDATION_EXTERN` alias for `FOUNDATION_EXPORT` (Apple `#define`s the 
former to the latter).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151578

Files:
  clang/lib/Format/Format.cpp
  clang/test/Format/dump-config-objc-macros.h
  clang/unittests/Format/FormatTestObjC.cpp


Index: clang/unittests/Format/FormatTestObjC.cpp
===
--- clang/unittests/Format/FormatTestObjC.cpp
+++ clang/unittests/Format/FormatTestObjC.cpp
@@ -94,6 +94,26 @@
   ASSERT_TRUE((bool)Style);
   EXPECT_EQ(FormatStyle::LK_ObjC, Style->Language);
 
+  Style = getStyle("{}", "a.h", "none", R"objc(
+NS_ASSUME_NONNULL_BEGIN
+extern int i;
+NS_ASSUME_NONNULL_END
+)objc");
+  ASSERT_TRUE((bool)Style);
+  EXPECT_EQ(FormatStyle::LK_ObjC, Style->Language);
+
+  Style = getStyle("{}", "a.h", "none", R"objc(
+FOUNDATION_EXTERN void DoStuff(void);
+)objc");
+  ASSERT_TRUE((bool)Style);
+  EXPECT_EQ(FormatStyle::LK_ObjC, Style->Language);
+
+  Style = getStyle("{}", "a.h", "none", R"objc(
+FOUNDATION_EXPORT void DoStuff(void);
+)objc");
+  ASSERT_TRUE((bool)Style);
+  EXPECT_EQ(FormatStyle::LK_ObjC, Style->Language);
+
   Style = getStyle("{}", "a.h", "none", "enum Foo {};");
   ASSERT_TRUE((bool)Style);
   EXPECT_EQ(FormatStyle::LK_Cpp, Style->Language);
Index: clang/test/Format/dump-config-objc-macros.h
===
--- /dev/null
+++ clang/test/Format/dump-config-objc-macros.h
@@ -0,0 +1,8 @@
+// RUN: clang-format -dump-config %s | FileCheck %s
+
+// CHECK: Language: ObjC
+NS_ASSUME_NONNULL_BEGIN
+
+FOUNDATION_EXTERN int kConstant;
+
+NS_ASSUME_NONNULL_END
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -2687,6 +2687,8 @@
 "CGSizeMake",
 "CGVector",
 "CGVectorMake",
+"FOUNDATION_EXPORT", // This is an alias for FOUNDATION_EXTERN.
+"FOUNDATION_EXTERN",
 "NSAffineTransform",
 "NSArray",
 "NSAttributedString",
@@ -2743,6 +2745,7 @@
 "NSURLQueryItem",
 "NSUUID",
 "NSValue",
+"NS_ASSUME_NONNULL_BEGIN",
 "UIImage",
 "UIView",
 };


Index: clang/unittests/Format/FormatTestObjC.cpp
===
--- clang/unittests/Format/FormatTestObjC.cpp
+++ clang/unittests/Format/FormatTestObjC.cpp
@@ -94,6 +94,26 @@
   ASSERT_TRUE((bool)Style);
   EXPECT_EQ(FormatStyle::LK_ObjC, Style->Language);
 
+  Style = getStyle("{}", "a.h", "none", R"objc(
+NS_ASSUME_NONNULL_BEGIN
+extern int i;
+NS_ASSUME_NONNULL_END
+)objc");
+  ASSERT_TRUE((bool)Style);
+  EXPECT_EQ(FormatStyle::LK_ObjC, Style->Language);
+
+  Style = getStyle("{}", "a.h", "none", R"objc(
+FOUNDATION_EXTERN void DoStuff(void);
+)objc");
+  ASSERT_TRUE((bool)Style);
+  EXPECT_EQ(FormatStyle::LK_ObjC, Style->Language);
+
+  Style = getStyle("{}", "a.h", "none", R"objc(
+FOUNDATION_EXPORT void DoStuff(void);
+)objc");
+  ASSERT_TRUE((bool)Style);
+  EXPECT_EQ(FormatStyle::LK_ObjC, Style->Language);
+
   Style = getStyle("{}", "a.h", "none", "enum Foo {};");
   ASSERT_TRUE((bool)Style);
   EXPECT_EQ(FormatStyle::LK_Cpp, Style->Language);
Index: clang/test/Format/dump-config-objc-macros.h
===
--- /dev/null
+++ clang/test/Format/dump-config-objc-macros.h
@@ -0,0 +1,8 @@
+// RUN: clang-format -dump-config %s | FileCheck %s
+
+// CHECK: Language: ObjC
+NS_ASSUME_NONNULL_BEGIN
+
+FOUNDATION_EXTERN int kConstant;
+
+NS_ASSUME_NONNULL_END
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -2687,6 +2687,8 @@
 "CGSizeMake",
 "CGVector",
 "CGVectorMake",
+"FOUNDATION_EXPORT", // This is an alias for FOUNDATION_EXTERN.
+"FOUNDATION_EXTERN",
 "NSAffineTransform",
 "NSArray",
 "NSAttributedString",
@@ -2743,6 +2745,7 @@
 "NSURLQueryItem",
 "NSUUID",
 "NSValue",
+"NS_ASSUME_NONNULL_BEGIN",
 "UIImage",
 "UIView",
 };
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D151578: [Format/ObjC] Support NS_ASSUME_NONNULL_BEGIN and FOUNDATION_EXPORT in ObjC language guesser

2023-05-26 Thread Ben Hamilton via Phabricator via cfe-commits
benhamilton updated this revision to Diff 526151.
benhamilton added a comment.

Fix auto-complete-o.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151578

Files:
  clang/lib/Format/Format.cpp
  clang/test/Format/dump-config-objc-macros.h
  clang/unittests/Format/FormatTestObjC.cpp


Index: clang/unittests/Format/FormatTestObjC.cpp
===
--- clang/unittests/Format/FormatTestObjC.cpp
+++ clang/unittests/Format/FormatTestObjC.cpp
@@ -94,6 +94,20 @@
   ASSERT_TRUE((bool)Style);
   EXPECT_EQ(FormatStyle::LK_ObjC, Style->Language);
 
+  Style = getStyle("{}", "a.h", "none", R"objc(
+NS_ASSUME_NONNULL_BEGIN
+extern int i;
+NS_ASSUME_NONNULL_END
+)objc");
+  ASSERT_TRUE((bool)Style);
+  EXPECT_EQ(FormatStyle::LK_ObjC, Style->Language);
+
+  Style = getStyle("{}", "a.h", "none", R"objc(
+FOUNDATION_EXTERN void DoStuff(void);
+)objc");
+  ASSERT_TRUE((bool)Style);
+  EXPECT_EQ(FormatStyle::LK_ObjC, Style->Language);
+
   Style = getStyle("{}", "a.h", "none", "enum Foo {};");
   ASSERT_TRUE((bool)Style);
   EXPECT_EQ(FormatStyle::LK_Cpp, Style->Language);
Index: clang/test/Format/dump-config-objc-macros.h
===
--- /dev/null
+++ clang/test/Format/dump-config-objc-macros.h
@@ -0,0 +1,8 @@
+// RUN: clang-format -dump-config %s | FileCheck %s
+
+// CHECK: Language: ObjC
+NS_ASSUME_NONNULL_BEGIN
+
+FOUNDATION_EXTERN int kConstant;
+
+NS_ASSUME_NONNULL_END
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -2687,6 +2687,7 @@
 "CGSizeMake",
 "CGVector",
 "CGVectorMake",
+"FOUNDATION_EXTERN",
 "NSAffineTransform",
 "NSArray",
 "NSAttributedString",
@@ -2743,6 +2744,7 @@
 "NSURLQueryItem",
 "NSUUID",
 "NSValue",
+"NS_ASSUME_NONNULL_BEGIN",
 "UIImage",
 "UIView",
 };


Index: clang/unittests/Format/FormatTestObjC.cpp
===
--- clang/unittests/Format/FormatTestObjC.cpp
+++ clang/unittests/Format/FormatTestObjC.cpp
@@ -94,6 +94,20 @@
   ASSERT_TRUE((bool)Style);
   EXPECT_EQ(FormatStyle::LK_ObjC, Style->Language);
 
+  Style = getStyle("{}", "a.h", "none", R"objc(
+NS_ASSUME_NONNULL_BEGIN
+extern int i;
+NS_ASSUME_NONNULL_END
+)objc");
+  ASSERT_TRUE((bool)Style);
+  EXPECT_EQ(FormatStyle::LK_ObjC, Style->Language);
+
+  Style = getStyle("{}", "a.h", "none", R"objc(
+FOUNDATION_EXTERN void DoStuff(void);
+)objc");
+  ASSERT_TRUE((bool)Style);
+  EXPECT_EQ(FormatStyle::LK_ObjC, Style->Language);
+
   Style = getStyle("{}", "a.h", "none", "enum Foo {};");
   ASSERT_TRUE((bool)Style);
   EXPECT_EQ(FormatStyle::LK_Cpp, Style->Language);
Index: clang/test/Format/dump-config-objc-macros.h
===
--- /dev/null
+++ clang/test/Format/dump-config-objc-macros.h
@@ -0,0 +1,8 @@
+// RUN: clang-format -dump-config %s | FileCheck %s
+
+// CHECK: Language: ObjC
+NS_ASSUME_NONNULL_BEGIN
+
+FOUNDATION_EXTERN int kConstant;
+
+NS_ASSUME_NONNULL_END
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -2687,6 +2687,7 @@
 "CGSizeMake",
 "CGVector",
 "CGVectorMake",
+"FOUNDATION_EXTERN",
 "NSAffineTransform",
 "NSArray",
 "NSAttributedString",
@@ -2743,6 +2744,7 @@
 "NSURLQueryItem",
 "NSUUID",
 "NSValue",
+"NS_ASSUME_NONNULL_BEGIN",
 "UIImage",
 "UIView",
 };
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D151578: [Format/ObjC] Support NS_ASSUME_NONNULL_BEGIN and FOUNDATION_EXPORT in ObjC language guesser

2023-05-26 Thread Ben Hamilton via Phabricator via cfe-commits
benhamilton created this revision.
benhamilton added a reviewer: MyDeveloperDay.
Herald added projects: All, clang, clang-format.
Herald added a subscriber: cfe-commits.
Herald added reviewers: rymiel, HazardyKnusperkeks, owenpan.
benhamilton requested review of this revision.

This adds to the ObjC language guesser a few more common macros used
in ObjC headers. These can help distinguish ObjC headers which
otherwise lack ObjC types from C++ headers.

Contributed by danblakemore.

Tested:

  New tests included. Ran unit tests with:
  ```
  % cmake -S llvm -B build -G Ninja && \
ninja -C build FormatTests && \
./build/tools/clang/unittests/Format/FormatTests 
--gtest_filter="*FormatTestObjC*"
  
  (snip)
  [--] 24 tests from FormatTestObjC (265 ms total)
  
  [--] Global test environment tear-down
  [==] 26 tests from 2 test suites ran. (270 ms total)
  [  PASSED  ] 26 tests.
  ```


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D151578

Files:
  clang/lib/Format/Format.cpp
  clang/test/Format/dump-config-objc-macros.h
  clang/unittests/Format/FormatTestObjC.cpp


Index: clang/unittests/Format/FormatTestObjC.cpp
===
--- clang/unittests/Format/FormatTestObjC.cpp
+++ clang/unittests/Format/FormatTestObjC.cpp
@@ -94,6 +94,20 @@
   ASSERT_TRUE((bool)Style);
   EXPECT_EQ(FormatStyle::LK_ObjC, Style->Language);
 
+  Style = getStyle("{}", "a.h", "none", R"objc(
+NS_ASSUME_NONNULL_BEGIN
+extern int i;
+NS_ASSUME_NONNULL_END
+)objc");
+  ASSERT_TRUE((bool)Style);
+  EXPECT_EQ(FormatStyle::LK_ObjC, Style->Language);
+
+  Style = getStyle("{}", "a.h", "none", R"objc(
+FOUNDATION_EXTERN void DoStuff(void);
+)objc");
+  ASSERT_TRUE((bool)Style);
+  EXPECT_EQ(FormatStyle::LK_ObjC, Style->Language);
+
   Style = getStyle("{}", "a.h", "none", "enum Foo {};");
   ASSERT_TRUE((bool)Style);
   EXPECT_EQ(FormatStyle::LK_Cpp, Style->Language);
Index: clang/test/Format/dump-config-objc-macros.h
===
--- /dev/null
+++ clang/test/Format/dump-config-objc-macros.h
@@ -0,0 +1,8 @@
+// RUN: clang-format -dump-config %s | FileCheck %s
+
+// CHECK: Language: ObjC
+NS_ASSUME_NONNULL_BEGIN
+
+FOUNDATION_EXPORT int kConstant;
+
+NS_ASSUME_NONNULL_END
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -2687,6 +2687,7 @@
 "CGSizeMake",
 "CGVector",
 "CGVectorMake",
+"FOUNDATION_EXTERN",
 "NSAffineTransform",
 "NSArray",
 "NSAttributedString",
@@ -2743,6 +2744,7 @@
 "NSURLQueryItem",
 "NSUUID",
 "NSValue",
+"NS_ASSUME_NONNULL_BEGIN",
 "UIImage",
 "UIView",
 };


Index: clang/unittests/Format/FormatTestObjC.cpp
===
--- clang/unittests/Format/FormatTestObjC.cpp
+++ clang/unittests/Format/FormatTestObjC.cpp
@@ -94,6 +94,20 @@
   ASSERT_TRUE((bool)Style);
   EXPECT_EQ(FormatStyle::LK_ObjC, Style->Language);
 
+  Style = getStyle("{}", "a.h", "none", R"objc(
+NS_ASSUME_NONNULL_BEGIN
+extern int i;
+NS_ASSUME_NONNULL_END
+)objc");
+  ASSERT_TRUE((bool)Style);
+  EXPECT_EQ(FormatStyle::LK_ObjC, Style->Language);
+
+  Style = getStyle("{}", "a.h", "none", R"objc(
+FOUNDATION_EXTERN void DoStuff(void);
+)objc");
+  ASSERT_TRUE((bool)Style);
+  EXPECT_EQ(FormatStyle::LK_ObjC, Style->Language);
+
   Style = getStyle("{}", "a.h", "none", "enum Foo {};");
   ASSERT_TRUE((bool)Style);
   EXPECT_EQ(FormatStyle::LK_Cpp, Style->Language);
Index: clang/test/Format/dump-config-objc-macros.h
===
--- /dev/null
+++ clang/test/Format/dump-config-objc-macros.h
@@ -0,0 +1,8 @@
+// RUN: clang-format -dump-config %s | FileCheck %s
+
+// CHECK: Language: ObjC
+NS_ASSUME_NONNULL_BEGIN
+
+FOUNDATION_EXPORT int kConstant;
+
+NS_ASSUME_NONNULL_END
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -2687,6 +2687,7 @@
 "CGSizeMake",
 "CGVector",
 "CGVectorMake",
+"FOUNDATION_EXTERN",
 "NSAffineTransform",
 "NSArray",
 "NSAttributedString",
@@ -2743,6 +2744,7 @@
 "NSURLQueryItem",
 "NSUUID",
 "NSValue",
+"NS_ASSUME_NONNULL_BEGIN",
 "UIImage",
 "UIView",
 };
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D151492: Add fastmath attributes to llvm.call_intrinsic

2023-05-26 Thread Jeff Niu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG9346dc6f675e: Add fastmath attributes to llvm.call_intrinsic 
(authored by electriclilies, committed by Mogball).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151492

Files:
  mlir/include/mlir/Dialect/LLVMIR/LLVMIntrinsicOps.td
  mlir/lib/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.cpp
  mlir/test/Dialect/LLVMIR/call-intrin.mlir


Index: mlir/test/Dialect/LLVMIR/call-intrin.mlir
===
--- mlir/test/Dialect/LLVMIR/call-intrin.mlir
+++ mlir/test/Dialect/LLVMIR/call-intrin.mlir
@@ -5,13 +5,13 @@
 // CHECK: declare ptr @malloc(i64)
 // CHECK: declare void @free(ptr)
 // CHECK: define <4 x float> @round_sse41() {
-// CHECK:  %1 = call <4 x float> @llvm.x86.sse41.round.ss(<4 x float> , <4 x float> , i32 1)
+// CHECK:  %1 = call reassoc <4 x float> @llvm.x86.sse41.round.ss(<4 x float> 
, <4 x float> , i32 1)
 // CHECK:  ret <4 x float> %1
 // CHECK: }
 llvm.func @round_sse41() -> vector<4xf32> {
 %0 = llvm.mlir.constant(1 : i32) : i32
 %1 = llvm.mlir.constant(dense<0.2> : vector<4xf32>) : vector<4xf32>
-%res = llvm.call_intrinsic "llvm.x86.sse41.round.ss"(%1, %1, %0) : 
(vector<4xf32>, vector<4xf32>, i32) -> vector<4xf32> {}
+%res = llvm.call_intrinsic "llvm.x86.sse41.round.ss"(%1, %1, %0) : 
(vector<4xf32>, vector<4xf32>, i32) -> vector<4xf32> {fastmathFlags = 
#llvm.fastmath}
 llvm.return %res: vector<4xf32>
 }
 
Index: mlir/lib/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.cpp
===
--- mlir/lib/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.cpp
+++ mlir/lib/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.cpp
@@ -95,7 +95,7 @@
 
 /// Builder for LLVM_CallIntrinsicOp
 static LogicalResult
-convertCallLLVMIntrinsicOp(CallIntrinsicOp , llvm::IRBuilderBase ,
+convertCallLLVMIntrinsicOp(CallIntrinsicOp op, llvm::IRBuilderBase ,
LLVM::ModuleTranslation ) {
   llvm::Module *module = builder.GetInsertBlock()->getModule();
   llvm::Intrinsic::ID id =
@@ -114,6 +114,8 @@
   } else {
 fn = llvm::Intrinsic::getDeclaration(module, id, {});
   }
+  FastmathFlagsInterface itf = op;
+  builder.setFastMathFlags(getFastmathFlags(itf));
 
   auto *inst =
   builder.CreateCall(fn, moduleTranslation.lookupValues(op.getOperands()));
Index: mlir/include/mlir/Dialect/LLVMIR/LLVMIntrinsicOps.td
===
--- mlir/include/mlir/Dialect/LLVMIR/LLVMIntrinsicOps.td
+++ mlir/include/mlir/Dialect/LLVMIR/LLVMIntrinsicOps.td
@@ -867,19 +867,24 @@
 // CallIntrinsicOp
 //======//
 
-def LLVM_CallIntrinsicOp : LLVM_Op<"call_intrinsic"> {
+def LLVM_CallIntrinsicOp
+: LLVM_Op<"call_intrinsic",
+  [DeclareOpInterfaceMethods]> {
   let summary = "Call to an LLVM intrinsic function.";
   let description = [{
 Call the specified llvm intrinsic. If the intrinsic is overloaded, use
 the MLIR function type of this op to determine which intrinsic to call.
 }];
-  let arguments = (ins StrAttr:$intrin, Variadic:$args);
+  let arguments = (ins StrAttr:$intrin, Variadic:$args,
+   DefaultValuedAttr:$fastmathFlags);
   let results = (outs Variadic:$results);
   let llvmBuilder = [{
 return convertCallLLVMIntrinsicOp(op, builder, moduleTranslation);
   }];
   let assemblyFormat = [{
-$intrin `(` $args `)` `:` functional-type($args, $results) attr-dict
+$intrin `(` $args `)` `:` functional-type($args, $results)
+  custom(attr-dict)
   }];
 }
 


Index: mlir/test/Dialect/LLVMIR/call-intrin.mlir
===
--- mlir/test/Dialect/LLVMIR/call-intrin.mlir
+++ mlir/test/Dialect/LLVMIR/call-intrin.mlir
@@ -5,13 +5,13 @@
 // CHECK: declare ptr @malloc(i64)
 // CHECK: declare void @free(ptr)
 // CHECK: define <4 x float> @round_sse41() {
-// CHECK:  %1 = call <4 x float> @llvm.x86.sse41.round.ss(<4 x float> , <4 x float> , i32 1)
+// CHECK:  %1 = call reassoc <4 x float> @llvm.x86.sse41.round.ss(<4 x float> , <4 x float> , i32 1)
 // CHECK:  ret <4 x float> %1
 // CHECK: }
 llvm.func @round_sse41() -> vector<4xf32> {
 %0 = llvm.mlir.constant(1 : i32) : i32
 %1 = llvm.mlir.constant(dense<0.2> : vector<4xf32>) : vector<4xf32>
-%res = llvm.call_intrinsic "llvm.x86.sse41.round.ss"(%1, %1, %0) : (vector<4xf32>, vector<4xf32>, i32) -> vector<4xf32> {}
+%res = llvm.call_intrinsic "llvm.x86.sse41.round.ss"(%1, %1, %0) : (vector<4xf32>, vector<4xf32>, i32) -> vector<4xf32> {fastmathFlags = #llvm.fastmath}
 llvm.return %res: vector<4xf32>
 }
 
Index: mlir/lib/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.cpp

[PATCH] D151477: [clang][ExtractAPI] Refactor serializer to the CRTP

2023-05-26 Thread Erick Velez via Phabricator via cfe-commits
evelez7 updated this revision to Diff 526148.
evelez7 added a comment.

Address review feedback


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151477

Files:
  clang/include/clang/ExtractAPI/Serialization/SerializerBase.h
  clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
  clang/lib/ExtractAPI/CMakeLists.txt
  clang/lib/ExtractAPI/Serialization/SerializerBase.cpp
  clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp

Index: clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
===
--- clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
+++ clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
@@ -14,16 +14,11 @@
 #include "clang/ExtractAPI/Serialization/SymbolGraphSerializer.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/Version.h"
-#include "clang/ExtractAPI/API.h"
-#include "clang/ExtractAPI/APIIgnoresList.h"
 #include "clang/ExtractAPI/DeclarationFragments.h"
-#include "clang/ExtractAPI/Serialization/SerializerBase.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/STLFunctionalExtras.h"
-#include "llvm/ADT/SmallVector.h"
 #include "llvm/Support/Casting.h"
 #include "llvm/Support/Compiler.h"
-#include "llvm/Support/JSON.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/VersionTuple.h"
 #include 
@@ -541,19 +536,16 @@
 Array generateParentContexts(const RecordTy , const APISet ,
  Language Lang) {
   Array ParentContexts;
-  generatePathComponents(Record, API,
- [Lang, ](const PathComponent ) {
-   ParentContexts.push_back(
-   serializeParentContext(PC, Lang));
- });
+  generatePathComponents(
+  Record, API, [Lang, ](const PathComponent ) {
+ParentContexts.push_back(serializeParentContext(PC, Lang));
+  });
 
   return ParentContexts;
 }
 
 } // namespace
 
-void SymbolGraphSerializer::anchor() {}
-
 /// Defines the format version emitted by SymbolGraphSerializer.
 const VersionTuple SymbolGraphSerializer::FormatVersion{0, 5, 3};
 
@@ -670,7 +662,7 @@
   Relationships.emplace_back(std::move(Relationship));
 }
 
-void SymbolGraphSerializer::serializeGlobalFunctionRecord(
+void SymbolGraphSerializer::visitGlobalFunctionRecord(
 const GlobalFunctionRecord ) {
   auto Obj = serializeAPIRecord(Record);
   if (!Obj)
@@ -679,7 +671,7 @@
   Symbols.emplace_back(std::move(*Obj));
 }
 
-void SymbolGraphSerializer::serializeGlobalVariableRecord(
+void SymbolGraphSerializer::visitGlobalVariableRecord(
 const GlobalVariableRecord ) {
   auto Obj = serializeAPIRecord(Record);
   if (!Obj)
@@ -688,7 +680,7 @@
   Symbols.emplace_back(std::move(*Obj));
 }
 
-void SymbolGraphSerializer::serializeEnumRecord(const EnumRecord ) {
+void SymbolGraphSerializer::visitEnumRecord(const EnumRecord ) {
   auto Enum = serializeAPIRecord(Record);
   if (!Enum)
 return;
@@ -697,7 +689,7 @@
   serializeMembers(Record, Record.Constants);
 }
 
-void SymbolGraphSerializer::serializeStructRecord(const StructRecord ) {
+void SymbolGraphSerializer::visitStructRecord(const StructRecord ) {
   auto Struct = serializeAPIRecord(Record);
   if (!Struct)
 return;
@@ -706,7 +698,7 @@
   serializeMembers(Record, Record.Fields);
 }
 
-void SymbolGraphSerializer::serializeObjCContainerRecord(
+void SymbolGraphSerializer::visitObjCContainerRecord(
 const ObjCContainerRecord ) {
   auto ObjCContainer = serializeAPIRecord(Record);
   if (!ObjCContainer)
@@ -743,7 +735,7 @@
   }
 }
 
-void SymbolGraphSerializer::serializeMacroDefinitionRecord(
+void SymbolGraphSerializer::visitMacroDefinitionRecord(
 const MacroDefinitionRecord ) {
   auto Macro = serializeAPIRecord(Record);
 
@@ -758,28 +750,28 @@
   case APIRecord::RK_Unknown:
 llvm_unreachable("Records should have a known kind!");
   case APIRecord::RK_GlobalFunction:
-serializeGlobalFunctionRecord(*cast(Record));
+visitGlobalFunctionRecord(*cast(Record));
 break;
   case APIRecord::RK_GlobalVariable:
-serializeGlobalVariableRecord(*cast(Record));
+visitGlobalVariableRecord(*cast(Record));
 break;
   case APIRecord::RK_Enum:
-serializeEnumRecord(*cast(Record));
+visitEnumRecord(*cast(Record));
 break;
   case APIRecord::RK_Struct:
-serializeStructRecord(*cast(Record));
+visitStructRecord(*cast(Record));
 break;
   case APIRecord::RK_ObjCInterface:
-serializeObjCContainerRecord(*cast(Record));
+visitObjCContainerRecord(*cast(Record));
 break;
   case APIRecord::RK_ObjCProtocol:
-serializeObjCContainerRecord(*cast(Record));
+visitObjCContainerRecord(*cast(Record));
 break;
   case APIRecord::RK_MacroDefinition:
-serializeMacroDefinitionRecord(*cast(Record));
+visitMacroDefinitionRecord(*cast(Record));
 break;
   case 

[PATCH] D151575: [clang][diagnostics] Always show include stacks on errors

2023-05-26 Thread Zenong Zhang via Phabricator via cfe-commits
SlaterLatiao updated this revision to Diff 526144.
SlaterLatiao added a comment.

- Add newline to end of file.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151575

Files:
  clang/lib/Frontend/DiagnosticRenderer.cpp
  clang/test/Misc/Inputs/include-stack-on-error-1.h
  clang/test/Misc/Inputs/include-stack-on-error-2.h
  clang/test/Misc/Inputs/include-stack-on-error-3.h
  clang/test/Misc/include-stack-on-error-1.cpp
  clang/test/Misc/include-stack-on-error-2.cpp


Index: clang/test/Misc/include-stack-on-error-2.cpp
===
--- /dev/null
+++ clang/test/Misc/include-stack-on-error-2.cpp
@@ -0,0 +1,15 @@
+// Test duplicate include stacks that are not on a new error are skipped.
+// RUN: not %clang_cc1 -fsyntax-only -fdiagnostics-show-note-include-stack -I 
%S/Inputs %s 2>&1 | FileCheck %s -check-prefix=NOTESTACK
+
+#include "include-stack-on-error-1.h"
+#include "include-stack-on-error-3.h"
+
+// NOTESTACK:  In file included from
+// NOTESTACK: error: no matching function for call to 'b1'
+// This include should be skipped due to duplicate include location.
+// NOTESTACK-NOT:  In file included from
+// NOTESTACK: note: candidate function not viable
+// NOTESTACK:  In file included from
+// NOTESTACK: error: invalid operands to binary expression
+// NOTESTACK:  In file included from
+// NOTESTACK: note: in instantiation of function template specialization
Index: clang/test/Misc/include-stack-on-error-1.cpp
===
--- /dev/null
+++ clang/test/Misc/include-stack-on-error-1.cpp
@@ -0,0 +1,24 @@
+// Test duplicate include stacks on a new error are not skipped.
+// RUN: not %clang_cc1 -fsyntax-only -I %S/Inputs %s 2>&1 | FileCheck %s 
-check-prefix=STACK
+// RUN: not %clang_cc1 -fsyntax-only -fdiagnostics-show-note-include-stack -I 
%S/Inputs %s 2>&1 | FileCheck %s -check-prefix=NOTESTACK
+
+#include "include-stack-on-error-1.h"
+#include "include-stack-on-error-2.h"
+
+// STACK:  In file included from
+// STACK: error: no matching function for call to 'b1'
+// STACK-NOT:  In file included from
+// STACK: note: candidate function not viable
+// STACK:  In file included from
+// STACK: error: invalid operands to binary expression
+// STACK-NOT:  In file included from
+// STACK: note: in instantiation of function template specialization
+
+// NOTESTACK:  In file included from
+// NOTESTACK: error: no matching function for call to 'b1'
+// NOTESTACK:  In file included from
+// NOTESTACK: note: candidate function not viable
+// NOTESTACK:  In file included from
+// NOTESTACK: error: invalid operands to binary expression
+// NOTESTACK:  In file included from
+// NOTESTACK: note: in instantiation of function template specialization
Index: clang/test/Misc/Inputs/include-stack-on-error-3.h
===
--- /dev/null
+++ clang/test/Misc/Inputs/include-stack-on-error-3.h
@@ -0,0 +1,5 @@
+void b1();
+void c() {
+b1(0);
+b2("0", "0");
+}
Index: clang/test/Misc/Inputs/include-stack-on-error-2.h
===
--- /dev/null
+++ clang/test/Misc/Inputs/include-stack-on-error-2.h
@@ -0,0 +1,4 @@
+void c() {
+b1(0);
+b2("0", "0");
+}
Index: clang/test/Misc/Inputs/include-stack-on-error-1.h
===
--- /dev/null
+++ clang/test/Misc/Inputs/include-stack-on-error-1.h
@@ -0,0 +1,2 @@
+void b1();
+template  void b2(T x, T y) { x + y; }
Index: clang/lib/Frontend/DiagnosticRenderer.cpp
===
--- clang/lib/Frontend/DiagnosticRenderer.cpp
+++ clang/lib/Frontend/DiagnosticRenderer.cpp
@@ -167,6 +167,10 @@
   PLoc.isInvalid() ? FullSourceLoc()
: FullSourceLoc(PLoc.getIncludeLoc(), Loc.getManager());
 
+  // Reset `LastIncludeLoc` on a new error so that the include stacks are
+  // not skipped.
+  if (Level == DiagnosticsEngine::Error)
+LastIncludeLoc = SourceLocation();
   // Skip redundant include stacks altogether.
   if (LastIncludeLoc == IncludeLoc)
 return;


Index: clang/test/Misc/include-stack-on-error-2.cpp
===
--- /dev/null
+++ clang/test/Misc/include-stack-on-error-2.cpp
@@ -0,0 +1,15 @@
+// Test duplicate include stacks that are not on a new error are skipped.
+// RUN: not %clang_cc1 -fsyntax-only -fdiagnostics-show-note-include-stack -I %S/Inputs %s 2>&1 | FileCheck %s -check-prefix=NOTESTACK
+
+#include "include-stack-on-error-1.h"
+#include "include-stack-on-error-3.h"
+
+// NOTESTACK:  In file included from
+// NOTESTACK: error: no matching function for call to 'b1'
+// This include should be skipped due to duplicate include location.
+// NOTESTACK-NOT:  In file included from
+// 

[PATCH] D151572: [clang][ConstantEmitter] have tryEmitPrivate try ConstExprEmitter fast-path first

2023-05-26 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers added a comment.

In D151572#4376697 , @efriedma wrote:

> Did you intentionally skip moving the ConstExprEmitter call in 
> tryEmitPrivateForVarInit?  (VarDecl::evaluateValue calls the constant 
> evaluator.)

Yes, I'll do that in a follow up patch as it results in quite a few test 
failures that I'm looking into now.  Triple check my messages on LLVM Discord. 
;)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151572

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


[PATCH] D151576: Fix runtime crash inside __kmpc_init_allocator

2023-05-26 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev accepted this revision.
ABataev added a comment.
This revision is now accepted and ready to land.

LG


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151576

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


[PATCH] D151576: Fix runtime crash inside __kmpc_init_allocator

2023-05-26 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 created this revision.
jyu2 added reviewers: ABataev, jdoerfert.
jyu2 added projects: OpenMP, clang.
Herald added a project: All.
jyu2 requested review of this revision.
Herald added subscribers: openmp-commits, cfe-commits, jplehr, sstefan1.

It seems load of traits.addr should be passed in runtime call.  Currently
the load of load traits.addr gets passed cause runtime to fail.

To fix this, skip the call to EmitLoadOfScalar for extra load.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D151576

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/test/OpenMP/target_parallel_for_simd_uses_allocators_codegen.cpp
  clang/test/OpenMP/target_parallel_for_uses_allocators_codegen.cpp
  clang/test/OpenMP/target_parallel_uses_allocators_codegen.cpp
  clang/test/OpenMP/target_simd_uses_allocators_codegen.cpp
  
clang/test/OpenMP/target_teams_distribute_parallel_for_simd_uses_allocators_codegen.cpp
  
clang/test/OpenMP/target_teams_distribute_parallel_for_uses_allocators_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_simd_uses_allocators_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_uses_allocators_codegen.cpp
  clang/test/OpenMP/target_teams_uses_allocators_codegen.cpp
  clang/test/OpenMP/target_uses_allocators.c
  clang/test/OpenMP/target_uses_allocators_codegen.cpp
  openmp/libomptarget/test/mapping/target_uses_allocator.c

Index: openmp/libomptarget/test/mapping/target_uses_allocator.c
===
--- /dev/null
+++ openmp/libomptarget/test/mapping/target_uses_allocator.c
@@ -0,0 +1,56 @@
+// RUN: %libomptarget-compile-run-and-check-generic
+
+#include 
+#include 
+
+#define N 1024
+
+int test_omp_aligned_alloc_on_device() {
+  int errors = 0;
+
+  omp_memspace_handle_t memspace = omp_default_mem_space;
+  omp_alloctrait_t traits[2] = {{omp_atk_alignment, 64}, {omp_atk_access, 64}};
+  omp_allocator_handle_t alloc =
+  omp_init_allocator(omp_default_mem_space, 1, traits);
+
+#pragma omp target map(tofrom : errors) uses_allocators(alloc(traits))
+  {
+int *x;
+int not_correct_array_values = 0;
+
+x = (int *)omp_aligned_alloc(64, N * sizeof(int), alloc);
+if (x == NULL) {
+  errors++;
+} else {
+#pragma omp parallel for simd simdlen(16) aligned(x : 64)
+  for (int i = 0; i < N; i++) {
+x[i] = i;
+  }
+
+#pragma omp parallel for simd simdlen(16) aligned(x : 64)
+  for (int i = 0; i < N; i++) {
+if (x[i] != i) {
+#pragma omp atomic write
+  not_correct_array_values = 1;
+}
+  }
+  if (not_correct_array_values) {
+errors++;
+  }
+  omp_free(x, alloc);
+}
+  }
+
+  omp_destroy_allocator(alloc);
+
+  return errors;
+}
+
+int main() {
+  int errors = 0;
+  if (test_omp_aligned_alloc_on_device())
+printf("FAILE\n");
+  else
+// CHECK: PASSED
+printf("PASSED\n");
+}
Index: clang/test/OpenMP/target_uses_allocators_codegen.cpp
===
--- clang/test/OpenMP/target_uses_allocators_codegen.cpp
+++ clang/test/OpenMP/target_uses_allocators_codegen.cpp
@@ -78,8 +78,7 @@
 // CHECK: [[TRAITS_ADDR_REF:%.+]] = alloca ptr,
 // CHECK: [[MY_ALLOCATOR_ADDR:%.+]] = alloca i64,
 // CHECK: [[TRAITS_ADDR:%.+]] = load ptr, ptr [[TRAITS_ADDR_REF]],
-// CHECK: [[TRAITS:%.+]] = load ptr, ptr [[TRAITS_ADDR]],
-// CHECK: [[ALLOCATOR:%.+]] = call ptr @__kmpc_init_allocator(i32 %{{.+}}, ptr null, i32 10, ptr [[TRAITS]])
+// CHECK: [[ALLOCATOR:%.+]] = call ptr @__kmpc_init_allocator(i32 %{{.+}}, ptr null, i32 10, ptr [[TRAITS_ADDR]])
 // CHECK: [[CONV:%.+]] = ptrtoint ptr [[ALLOCATOR]] to i64
 // CHECK: store i64 [[CONV]], ptr [[MY_ALLOCATOR_ADDR]],
 
Index: clang/test/OpenMP/target_uses_allocators.c
===
--- clang/test/OpenMP/target_uses_allocators.c
+++ clang/test/OpenMP/target_uses_allocators.c
@@ -132,8 +132,7 @@
 // CHECK: [[TRAITS_ADDR_REF:%.+]] = alloca ptr,
 // CHECK: [[MY_ALLOCATOR_ADDR:%.+]] = alloca i64,
 // CHECK: [[TRAITS_ADDR:%.+]] = load ptr, ptr [[TRAITS_ADDR_REF]],
-// CHECK: [[TRAITS:%.+]] = load ptr, ptr [[TRAITS_ADDR]],
-// CHECK: [[ALLOCATOR:%.+]] = call ptr @__kmpc_init_allocator(i32 %{{.+}}, ptr null, i32 10, ptr [[TRAITS]])
+// CHECK: [[ALLOCATOR:%.+]] = call ptr @__kmpc_init_allocator(i32 %{{.+}}, ptr null, i32 10, ptr [[TRAITS_ADDR]])
 // CHECK: [[CONV:%.+]] = ptrtoint ptr [[ALLOCATOR]] to i64
 // CHECK: store i64 [[CONV]], ptr [[MY_ALLOCATOR_ADDR]],
 
Index: clang/test/OpenMP/target_teams_uses_allocators_codegen.cpp
===
--- clang/test/OpenMP/target_teams_uses_allocators_codegen.cpp
+++ clang/test/OpenMP/target_teams_uses_allocators_codegen.cpp
@@ -78,8 +78,7 @@
 // CHECK: [[TRAITS_ADDR_REF:%.+]] = alloca ptr,
 // CHECK: [[MY_ALLOCATOR_ADDR:%.+]] = alloca i64,
 // CHECK: [[TRAITS_ADDR:%.+]] = load ptr, ptr [[TRAITS_ADDR_REF]],
-// 

[PATCH] D150446: [analyzer] Check ArraySubscriptExprs in ArrayBoundCheckerV2

2023-05-26 Thread DonĂ¡t Nagy via Phabricator via cfe-commits
donat.nagy added a comment.

@NoQ **Re: ElementRegion hacks:** Your suggestion is very convincing, and I 
agree that while my idea would bring some clarity to some particular issues, 
overall it would just worsen the "chaotic heap of classes" situation. The only 
advantage of my solution is that it would be an incremental change; but it's 
only incrementing the amount of problems, so I think I won't continue working 
on it.

On the other hand, I'd be interested in participating in the implementation of 
your suggestion. Unfortunately I don't have enough capacity to just sit down 
and start coding it; but I could suggest this reorganization as a potential 
thesis topic for a student/intern. (Our team regularly gets interns from Eötvös 
LorĂ¡nd University; if one of them is interested, then perhaps we could tackle 
this issue with me in a mentor / advisor role, and the student creating the 
bulk of the code reorganization commits. These are very far-fetched plans, but 
I'd be glad to see the cleanup that you suggested and I'll try to contribute 
what I can. Of course if you have a more concrete plan for doing this rewrite, 
then instead of intruding I'm happy to help with e.g. reviews.)

**Re: this review:**

> One straightforward implication is that this way [checking 
> PreStmt] we avoid dealing with multiplication/division 
> when calculating offsets.

Unfortunately this is not the case, because the size of the arrays (calculated 
by `clang::ento::getDynamicExtent()` in DynamicExtent.cpp 
) is still 
expressed in bytes ("CharUnits") and we need to multiply the index with 
`sizeof(elemType)` before we can compare it to this value. The distinguishing 
feature of ArrayBoundCheckerV2 is that it has some (ad-hoc but useful) logic 
for reasoning about some multiplications; that part is not changed by this 
commit.

Now that you mention it, I see that it would be //nice// to avoid bothering 
with byte offsets and multiplications in the simple case when we want to take a 
single `int` from an array of `int`s. To achieve this we'd need to introduce 
extent handling functions that measure the size of arrays in number of elements 
(of what kind?) instead of bytes; right now I don't know how difficult would it 
be to achieve that. (As far as I see the extent is usually either a constant 
[that can be readily divided], or it's a freshly conjured symbol... Are those 
symbols used for anything meaningful? Can we ever put an upper bound on them?) 
However this all should probably belong to a separate commit/review/discourse 
thread.

**Re: PreStmt:** That's a very good idea, but I feel that it belongs 
to the "engine level" and it's mostly orthogonal to the behavior this checker. 
My short-term (or at most medium-term) goal is to move this checker out of 
alpha (fix bugs, squash common false positives, improve messages etc.) and here 
I accept the limitation that (like all the currently "stable" checkers) it's 
mostly limited to loop-less code. On a longer term it'd be interesting to work 
on improving the loop handling engine (or just adding a gimmicky "loop 
prediction" ability to this checker); but I don't have concrete plans that far 
ahead.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150446

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


[PATCH] D151575: [clang][diagnostics] Always show include stacks on errors

2023-05-26 Thread Zenong Zhang via Phabricator via cfe-commits
SlaterLatiao created this revision.
Herald added a project: All.
SlaterLatiao requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

- Fixes PR#62001.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D151575

Files:
  clang/lib/Frontend/DiagnosticRenderer.cpp
  clang/test/Misc/Inputs/include-stack-on-error-1.h
  clang/test/Misc/Inputs/include-stack-on-error-2.h
  clang/test/Misc/Inputs/include-stack-on-error-3.h
  clang/test/Misc/include-stack-on-error-1.cpp
  clang/test/Misc/include-stack-on-error-2.cpp


Index: clang/test/Misc/include-stack-on-error-2.cpp
===
--- /dev/null
+++ clang/test/Misc/include-stack-on-error-2.cpp
@@ -0,0 +1,15 @@
+// Test duplicate include stacks that are not on a new error are skipped.
+// RUN: not %clang_cc1 -fsyntax-only -fdiagnostics-show-note-include-stack -I 
%S/Inputs %s 2>&1 | FileCheck %s -check-prefix=NOTESTACK
+
+#include "include-stack-on-error-1.h"
+#include "include-stack-on-error-3.h"
+
+// NOTESTACK:  In file included from
+// NOTESTACK: error: no matching function for call to 'b1'
+// This include should be skipped due to duplicate include location.
+// NOTESTACK-NOT:  In file included from
+// NOTESTACK: note: candidate function not viable
+// NOTESTACK:  In file included from
+// NOTESTACK: error: invalid operands to binary expression
+// NOTESTACK:  In file included from
+// NOTESTACK: note: in instantiation of function template specialization
\ No newline at end of file
Index: clang/test/Misc/include-stack-on-error-1.cpp
===
--- /dev/null
+++ clang/test/Misc/include-stack-on-error-1.cpp
@@ -0,0 +1,25 @@
+// Test duplicate include stacks on a new error are not skipped.
+// RUN: not %clang_cc1 -fsyntax-only -I %S/Inputs %s 2>&1 | FileCheck %s 
-check-prefix=STACK
+// RUN: not %clang_cc1 -fsyntax-only -fdiagnostics-show-note-include-stack -I 
%S/Inputs %s 2>&1 | FileCheck %s -check-prefix=NOTESTACK
+
+#include "include-stack-on-error-1.h"
+#include "include-stack-on-error-2.h"
+
+// STACK:  In file included from
+// STACK: error: no matching function for call to 'b1'
+// STACK-NOT:  In file included from
+// STACK: note: candidate function not viable
+// STACK:  In file included from
+// STACK: error: invalid operands to binary expression
+// STACK-NOT:  In file included from
+// STACK: note: in instantiation of function template specialization
+
+// NOTESTACK:  In file included from
+// NOTESTACK: error: no matching function for call to 'b1'
+// NOTESTACK:  In file included from
+// NOTESTACK: note: candidate function not viable
+// NOTESTACK:  In file included from
+// NOTESTACK: error: invalid operands to binary expression
+// NOTESTACK:  In file included from
+// NOTESTACK: note: in instantiation of function template specialization
+
Index: clang/test/Misc/Inputs/include-stack-on-error-3.h
===
--- /dev/null
+++ clang/test/Misc/Inputs/include-stack-on-error-3.h
@@ -0,0 +1,5 @@
+void b1();
+void c() {
+b1(0);
+b2("0", "0");
+}
\ No newline at end of file
Index: clang/test/Misc/Inputs/include-stack-on-error-2.h
===
--- /dev/null
+++ clang/test/Misc/Inputs/include-stack-on-error-2.h
@@ -0,0 +1,4 @@
+void c() {
+b1(0);
+b2("0", "0");
+}
\ No newline at end of file
Index: clang/test/Misc/Inputs/include-stack-on-error-1.h
===
--- /dev/null
+++ clang/test/Misc/Inputs/include-stack-on-error-1.h
@@ -0,0 +1,2 @@
+void b1();
+template  void b2(T x, T y) { x + y; }
\ No newline at end of file
Index: clang/lib/Frontend/DiagnosticRenderer.cpp
===
--- clang/lib/Frontend/DiagnosticRenderer.cpp
+++ clang/lib/Frontend/DiagnosticRenderer.cpp
@@ -167,6 +167,10 @@
   PLoc.isInvalid() ? FullSourceLoc()
: FullSourceLoc(PLoc.getIncludeLoc(), Loc.getManager());
 
+  // Reset `LastIncludeLoc` on a new error so that the include stacks are
+  // not skipped.
+  if (Level == DiagnosticsEngine::Error)
+LastIncludeLoc = SourceLocation();
   // Skip redundant include stacks altogether.
   if (LastIncludeLoc == IncludeLoc)
 return;


Index: clang/test/Misc/include-stack-on-error-2.cpp
===
--- /dev/null
+++ clang/test/Misc/include-stack-on-error-2.cpp
@@ -0,0 +1,15 @@
+// Test duplicate include stacks that are not on a new error are skipped.
+// RUN: not %clang_cc1 -fsyntax-only -fdiagnostics-show-note-include-stack -I %S/Inputs %s 2>&1 | FileCheck %s -check-prefix=NOTESTACK
+
+#include "include-stack-on-error-1.h"
+#include "include-stack-on-error-3.h"
+
+// NOTESTACK:  In file included from
+// NOTESTACK: error: no matching 

[PATCH] D151572: [clang][ConstantEmitter] have tryEmitPrivate try ConstExprEmitter fast-path first

2023-05-26 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added a comment.

Did you intentionally skip moving the ConstExprEmitter call in 
tryEmitPrivateForVarInit?  (VarDecl::evaluateValue calls the constant 
evaluator.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151572

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


[PATCH] D151572: [clang][ConstantEmitter] have tryEmitPrivate try ConstExprEmitter fast-path first

2023-05-26 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers updated this revision to Diff 526131.
nickdesaulniers added a comment.

- one more style update


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151572

Files:
  clang/lib/CodeGen/CGExprConstant.cpp


Index: clang/lib/CodeGen/CGExprConstant.cpp
===
--- clang/lib/CodeGen/CGExprConstant.cpp
+++ clang/lib/CodeGen/CGExprConstant.cpp
@@ -1657,9 +1657,8 @@
 
   // Try to emit the initializer.  Note that this can allow some things that
   // are not allowed by tryEmitPrivateForMemory alone.
-  if (auto value = D.evaluateValue()) {
+  if (APValue *value = D.evaluateValue())
 return tryEmitPrivateForMemory(*value, destType);
-  }
 
   // FIXME: Implement C++11 [basic.start.init]p2: if the initializer of a
   // reference is a constant expression, and the reference binds to a 
temporary,
@@ -1673,10 +1672,11 @@
   const Expr *E = D.getInit();
   assert(E && "No initializer to emit");
 
-  auto nonMemoryDestType = getNonMemoryType(CGM, destType);
-  auto C =
-ConstExprEmitter(*this).Visit(const_cast(E), nonMemoryDestType);
-  return (C ? emitForMemory(C, destType) : nullptr);
+  QualType nonMemoryDestType = getNonMemoryType(CGM, destType);
+  if (llvm::Constant *C = ConstExprEmitter(*this).Visit(const_cast(E),
+nonMemoryDestType))
+return emitForMemory(C, destType);
+  return nullptr;
 }
 
 llvm::Constant *
@@ -1743,6 +1743,10 @@
 QualType destType) {
   assert(!destType->isVoidType() && "can't emit a void constant");
 
+  if (llvm::Constant *C =
+  ConstExprEmitter(*this).Visit(const_cast(E), destType))
+return C;
+
   Expr::EvalResult Result;
 
   bool Success = false;
@@ -1752,13 +1756,10 @@
   else
 Success = E->EvaluateAsRValue(Result, CGM.getContext(), InConstantContext);
 
-  llvm::Constant *C;
   if (Success && !Result.HasSideEffects)
-C = tryEmitPrivate(Result.Val, destType);
-  else
-C = ConstExprEmitter(*this).Visit(const_cast(E), destType);
+return tryEmitPrivate(Result.Val, destType);
 
-  return C;
+  return nullptr;
 }
 
 llvm::Constant *CodeGenModule::getNullPointer(llvm::PointerType *T, QualType 
QT) {


Index: clang/lib/CodeGen/CGExprConstant.cpp
===
--- clang/lib/CodeGen/CGExprConstant.cpp
+++ clang/lib/CodeGen/CGExprConstant.cpp
@@ -1657,9 +1657,8 @@
 
   // Try to emit the initializer.  Note that this can allow some things that
   // are not allowed by tryEmitPrivateForMemory alone.
-  if (auto value = D.evaluateValue()) {
+  if (APValue *value = D.evaluateValue())
 return tryEmitPrivateForMemory(*value, destType);
-  }
 
   // FIXME: Implement C++11 [basic.start.init]p2: if the initializer of a
   // reference is a constant expression, and the reference binds to a temporary,
@@ -1673,10 +1672,11 @@
   const Expr *E = D.getInit();
   assert(E && "No initializer to emit");
 
-  auto nonMemoryDestType = getNonMemoryType(CGM, destType);
-  auto C =
-ConstExprEmitter(*this).Visit(const_cast(E), nonMemoryDestType);
-  return (C ? emitForMemory(C, destType) : nullptr);
+  QualType nonMemoryDestType = getNonMemoryType(CGM, destType);
+  if (llvm::Constant *C = ConstExprEmitter(*this).Visit(const_cast(E),
+nonMemoryDestType))
+return emitForMemory(C, destType);
+  return nullptr;
 }
 
 llvm::Constant *
@@ -1743,6 +1743,10 @@
 QualType destType) {
   assert(!destType->isVoidType() && "can't emit a void constant");
 
+  if (llvm::Constant *C =
+  ConstExprEmitter(*this).Visit(const_cast(E), destType))
+return C;
+
   Expr::EvalResult Result;
 
   bool Success = false;
@@ -1752,13 +1756,10 @@
   else
 Success = E->EvaluateAsRValue(Result, CGM.getContext(), InConstantContext);
 
-  llvm::Constant *C;
   if (Success && !Result.HasSideEffects)
-C = tryEmitPrivate(Result.Val, destType);
-  else
-C = ConstExprEmitter(*this).Visit(const_cast(E), destType);
+return tryEmitPrivate(Result.Val, destType);
 
-  return C;
+  return nullptr;
 }
 
 llvm::Constant *CodeGenModule::getNullPointer(llvm::PointerType *T, QualType QT) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D150985: [clang] Allow fp in atomic fetch max/min builtins

2023-05-26 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl marked 2 inline comments as done.
yaxunl added a comment.

In D150985#4369279 , @tra wrote:

> As I said, I'm OK with the patch in principle, I just don't know what other 
> factors I may be missing.
>
> Tests seem to be missing for c11 variants of the builtins.

will add test for c11 variants.




Comment at: clang/test/Sema/atomic-ops.c:209
+  __atomic_fetch_min(D, 3, memory_order_seq_cst);
+  __atomic_fetch_max(P, 3, memory_order_seq_cst);
   __atomic_fetch_max(p, 3);   // expected-error {{too few 
arguments to function call, expected 3, have 2}}

tra wrote:
> Is that intentional that we now allow atomic max on a `int **P` ? My 
> understanding that we were supposed to allow additional FP types only.
you are right. here should emit a diag "must be a pointer to integer or 
supported floating point type". will fix.



Comment at: clang/test/SemaOpenCL/atomic-ops.cl:65
+  __opencl_atomic_fetch_min(f, 1, memory_order_seq_cst, 
memory_scope_work_group);
+  __opencl_atomic_fetch_max(f, 1, memory_order_seq_cst, 
memory_scope_work_group);
 

tra wrote:
> We probably want to add tests for `double`, too.
will do


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

https://reviews.llvm.org/D150985

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


[PATCH] D149677: [clang][TypePrinter] Add option to skip over elaborated types

2023-05-26 Thread Eric Li via Phabricator via cfe-commits
li.zhe.hua added inline comments.



Comment at: clang/lib/AST/TypePrinter.cpp:1570
 
+  if (Policy.IgnoreElaboratedQualifiers) {
+printBefore(T->getNamedType(), OS);

aaron.ballman wrote:
> So, effectively, the idea here is: you want the ability to skip printing the 
> elaborated keyword and nested name specifier, and you additionally want to 
> skip use of `ElaboratedTypePolicyRAII` when calling 
> `printBefore()`/`printAfter()` because that forces suppression of tags and 
> scopes?
> 
> I think what I'm struggling with a bit is that this is doing three things at 
> once; one is the elaboration keyword (so we no longer print `typename` or 
> `struct` when `IncludeTagDefinition` is false), another is the nested name 
> specifier (we no longer print the leading foo::bar), and the third is that we 
> no longer suppress tags and scopes when printing the underlying type. That 
> makes it tricky to figure out how to name this thing, but the best I could 
> come up with is: `SuppressElaboration` which isn't really different from 
> `IgnoreElaboration` at all. So I think either of those names is "fine", but 
> I'm still a bit uncomfortable about how complex the interactions are becoming.
> another is the nested name specifier (we no longer print the leading 
> foo::bar), and the third is that we no longer suppress tags and scopes when 
> printing the underlying type

I would say that this is the primary desired behavior of the option. More 
specifically, it's //not// that we don't print the nested name specifier and no 
longer suppress those options, but rather, we print the underlying type with 
the options as specified by the policy. `SuppressTagKeyword`, `SuppressScope`, 
and `FullyQualifiedName` work as expected (from my perspective). The 
interaction with `IncludeTagDefinition` dropping the keyword wasn't explicitly 
intended, but it is still consistent with printing the canonical type (which 
would also drop the keyword).

One last name idea to throw out there, in case it seems worth discussing: 
`DesugarElaboratedTypes`. In that case, I'd probably also move the check up 
above L1559 and we treat the entire `ElaboratedType` as if it did not exist.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149677

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


[PATCH] D149677: [clang][TypePrinter] Add option to skip over elaborated types

2023-05-26 Thread Eric Li via Phabricator via cfe-commits
li.zhe.hua updated this revision to Diff 526128.
li.zhe.hua added a comment.

Switch option name to SuppressElaboration


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149677

Files:
  clang/include/clang/AST/PrettyPrinter.h
  clang/lib/AST/TypePrinter.cpp
  clang/unittests/AST/TypePrinterTest.cpp

Index: clang/unittests/AST/TypePrinterTest.cpp
===
--- clang/unittests/AST/TypePrinterTest.cpp
+++ clang/unittests/AST/TypePrinterTest.cpp
@@ -97,6 +97,33 @@
  "const f *", Clean));
 }
 
+TEST(TypePrinter, SuppressElaboration) {
+  llvm::StringLiteral Code = R"cpp(
+namespace shared {
+namespace a {
+template 
+struct S {};
+}  // namespace a
+namespace b {
+struct Foo {};
+}  // namespace b
+using Alias = a::S;
+}  // namespace shared
+  )cpp";
+
+  auto Matcher = typedefNameDecl(hasName("::shared::Alias"),
+ hasType(qualType().bind("id")));
+  ASSERT_TRUE(PrintedTypeMatches(
+  Code, {}, Matcher, "a::S",
+  [](PrintingPolicy ) { Policy.FullyQualifiedName = true; }));
+  ASSERT_TRUE(PrintedTypeMatches(Code, {}, Matcher,
+ "shared::a::S",
+ [](PrintingPolicy ) {
+   Policy.SuppressElaboration = true;
+   Policy.FullyQualifiedName = true;
+ }));
+}
+
 TEST(TypePrinter, TemplateIdWithNTTP) {
   constexpr char Code[] = R"cpp(
 template 
Index: clang/lib/AST/TypePrinter.cpp
===
--- clang/lib/AST/TypePrinter.cpp
+++ clang/lib/AST/TypePrinter.cpp
@@ -1567,6 +1567,11 @@
 return;
   }
 
+  if (Policy.SuppressElaboration) {
+printBefore(T->getNamedType(), OS);
+return;
+  }
+
   // The tag definition will take care of these.
   if (!Policy.IncludeTagDefinition)
   {
@@ -1586,6 +1591,12 @@
 raw_ostream ) {
   if (Policy.IncludeTagDefinition && T->getOwnedTagDecl())
 return;
+
+  if (Policy.SuppressElaboration) {
+printAfter(T->getNamedType(), OS);
+return;
+  }
+
   ElaboratedTypePolicyRAII PolicyRAII(Policy);
   printAfter(T->getNamedType(), OS);
 }
Index: clang/include/clang/AST/PrettyPrinter.h
===
--- clang/include/clang/AST/PrettyPrinter.h
+++ clang/include/clang/AST/PrettyPrinter.h
@@ -60,14 +60,15 @@
   : Indentation(2), SuppressSpecifiers(false),
 SuppressTagKeyword(LO.CPlusPlus), IncludeTagDefinition(false),
 SuppressScope(false), SuppressUnwrittenScope(false),
-SuppressInlineNamespace(true), SuppressInitializers(false),
-ConstantArraySizeAsWritten(false), AnonymousTagLocations(true),
-SuppressStrongLifetime(false), SuppressLifetimeQualifiers(false),
+SuppressInlineNamespace(true), SuppressElaboration(false),
+SuppressInitializers(false), ConstantArraySizeAsWritten(false),
+AnonymousTagLocations(true), SuppressStrongLifetime(false),
+SuppressLifetimeQualifiers(false),
 SuppressTemplateArgsInCXXConstructors(false),
 SuppressDefaultTemplateArgs(true), Bool(LO.Bool),
 Nullptr(LO.CPlusPlus11 || LO.C2x), NullptrTypeInNamespace(LO.CPlusPlus),
-Restrict(LO.C99), Alignof(LO.CPlusPlus11),
-UnderscoreAlignof(LO.C11), UseVoidForZeroParams(!LO.CPlusPlus),
+Restrict(LO.C99), Alignof(LO.CPlusPlus11), UnderscoreAlignof(LO.C11),
+UseVoidForZeroParams(!LO.CPlusPlus),
 SplitTemplateClosers(!LO.CPlusPlus11), TerseOutput(false),
 PolishForDeclaration(false), Half(LO.Half),
 MSWChar(LO.MicrosoftExt && !LO.WChar), IncludeNewlines(true),
@@ -139,6 +140,10 @@
   /// removed.
   unsigned SuppressInlineNamespace : 1;
 
+  /// Ignore qualifiers and tag keywords as specified by elaborated type sugar,
+  /// instead letting the underlying type print as normal.
+  unsigned SuppressElaboration : 1;
+
   /// Suppress printing of variable initializers.
   ///
   /// This flag is used when printing the loop variable in a for-range
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D151515: [CodeGen] add additional cast when checking call arguments

2023-05-26 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

Yeah, I agree with Eli, there should be a cast here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151515

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


[PATCH] D151051: [clang-tidy] Optimize misc-confusable-identifiers

2023-05-26 Thread Piotr Zegar via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG2a84c635f2a1: [clang-tidy] Optimize 
misc-confusable-identifiers (authored by PiotrZSL).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151051

Files:
  clang-tools-extra/clang-tidy/misc/ConfusableIdentifierCheck.cpp
  clang-tools-extra/clang-tidy/misc/ConfusableIdentifierCheck.h

Index: clang-tools-extra/clang-tidy/misc/ConfusableIdentifierCheck.h
===
--- clang-tools-extra/clang-tidy/misc/ConfusableIdentifierCheck.h
+++ clang-tools-extra/clang-tidy/misc/ConfusableIdentifierCheck.h
@@ -11,6 +11,7 @@
 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_CONFUSABLE_IDENTIFIER_CHECK_H
 
 #include "../ClangTidyCheck.h"
+#include 
 
 namespace clang::tidy::misc {
 
@@ -26,9 +27,23 @@
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult ) override;
 
+  struct ContextInfo {
+const DeclContext *PrimaryContext;
+const DeclContext *NonTransparentContext;
+llvm::SmallVector PrimaryContexts;
+llvm::SmallVector Bases;
+  };
+
 private:
-  std::string skeleton(StringRef);
-  llvm::StringMap> Mapper;
+  struct Entry {
+const NamedDecl *Declaration;
+const ContextInfo *Info;
+  };
+
+  const ContextInfo *getContextInfo(const DeclContext *DC);
+
+  llvm::StringMap> Mapper;
+  std::unordered_map ContextInfos;
 };
 
 } // namespace clang::tidy::misc
Index: clang-tools-extra/clang-tidy/misc/ConfusableIdentifierCheck.cpp
===
--- clang-tools-extra/clang-tidy/misc/ConfusableIdentifierCheck.cpp
+++ clang-tools-extra/clang-tidy/misc/ConfusableIdentifierCheck.cpp
@@ -45,7 +45,7 @@
 // We're skipping 1. and 3. for the sake of simplicity, but this can lead to
 // false positive.
 
-std::string ConfusableIdentifierCheck::skeleton(StringRef Name) {
+static std::string skeleton(StringRef Name) {
   using namespace llvm;
   std::string SName = Name.str();
   std::string Skeleton;
@@ -89,75 +89,107 @@
   return Skeleton;
 }
 
-static bool mayShadowImpl(const NamedDecl *ND0, const NamedDecl *ND1) {
-  const DeclContext *DC0 = ND0->getDeclContext()->getPrimaryContext();
-  const DeclContext *DC1 = ND1->getDeclContext()->getPrimaryContext();
+static bool mayShadowImpl(const DeclContext *DC0, const DeclContext *DC1) {
+  return DC0 && DC0 == DC1;
+}
 
-  if (isa(ND0) || isa(ND0))
-return true;
+static bool mayShadowImpl(const NamedDecl *ND0, const NamedDecl *ND1) {
+  return isa(ND0) || isa(ND1);
+}
 
-  while (DC0->isTransparentContext())
-DC0 = DC0->getParent();
-  while (DC1->isTransparentContext())
-DC1 = DC1->getParent();
+static bool isMemberOf(const ConfusableIdentifierCheck::ContextInfo *DC0,
+   const ConfusableIdentifierCheck::ContextInfo *DC1) {
+  if (DC0->Bases.empty())
+return false;
+  return llvm::is_contained(DC1->Bases, DC0->PrimaryContext);
+}
 
-  if (DC0->Equals(DC1))
+static bool enclosesContext(const ConfusableIdentifierCheck::ContextInfo *DC0,
+const ConfusableIdentifierCheck::ContextInfo *DC1) {
+  if (DC0->PrimaryContext == DC1->PrimaryContext)
 return true;
 
-  return false;
+  return llvm::is_contained(DC0->PrimaryContexts, DC1->PrimaryContext) ||
+ llvm::is_contained(DC1->PrimaryContexts, DC0->PrimaryContext);
 }
 
-static bool isMemberOf(const NamedDecl *ND, const CXXRecordDecl *RD) {
-  const DeclContext *NDParent = ND->getDeclContext();
-  if (!NDParent || !isa(NDParent))
-return false;
-  if (NDParent == RD)
+static bool mayShadow(const NamedDecl *ND0,
+  const ConfusableIdentifierCheck::ContextInfo *DC0,
+  const NamedDecl *ND1,
+  const ConfusableIdentifierCheck::ContextInfo *DC1) {
+  if (!DC0->Bases.empty() && ND1->getAccess() != AS_private &&
+  isMemberOf(DC1, DC0))
 return true;
-  return !RD->forallBases(
-  [NDParent](const CXXRecordDecl *Base) { return NDParent != Base; });
+  if (!DC1->Bases.empty() && ND0->getAccess() != AS_private &&
+  isMemberOf(DC0, DC1))
+return true;
+
+  return enclosesContext(DC0, DC1) &&
+ (mayShadowImpl(ND0, ND1) || mayShadowImpl(DC0->NonTransparentContext,
+   DC1->NonTransparentContext));
 }
 
-static bool mayShadow(const NamedDecl *ND0, const NamedDecl *ND1) {
+const ConfusableIdentifierCheck::ContextInfo *
+ConfusableIdentifierCheck::getContextInfo(const DeclContext *DC) {
+  const DeclContext *PrimaryContext = DC->getPrimaryContext();
+  auto It = ContextInfos.find(PrimaryContext);
+  if (It != ContextInfos.end())
+return >second;
+
+  ContextInfo  = ContextInfos[PrimaryContext];
+  Info.PrimaryContext = PrimaryContext;
+  Info.NonTransparentContext = 

[clang-tools-extra] 2a84c63 - [clang-tidy] Optimize misc-confusable-identifiers

2023-05-26 Thread Piotr Zegar via cfe-commits

Author: Piotr Zegar
Date: 2023-05-26T17:46:13Z
New Revision: 2a84c635f2a1dcb4546a5d751a32eac24103c7e6

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

LOG: [clang-tidy] Optimize misc-confusable-identifiers

Main performance issue in this check were caused by many
calls to getPrimaryContext and constant walk up to declaration
contexts using getParent. Also there were issue with forallBases
that is slow.

Profiled with perf and tested on open-source project Cataclysm-DDA.
Before changes check took 27320 seconds, after changes 3682 seconds.
That's 86.5% reduction. More optimizations are still possible in this
check.

Reviewed By: serge-sans-paille

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

Added: 


Modified: 
clang-tools-extra/clang-tidy/misc/ConfusableIdentifierCheck.cpp
clang-tools-extra/clang-tidy/misc/ConfusableIdentifierCheck.h

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/misc/ConfusableIdentifierCheck.cpp 
b/clang-tools-extra/clang-tidy/misc/ConfusableIdentifierCheck.cpp
index 355e097108030..63ba663aaca9a 100644
--- a/clang-tools-extra/clang-tidy/misc/ConfusableIdentifierCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/ConfusableIdentifierCheck.cpp
@@ -45,7 +45,7 @@ ConfusableIdentifierCheck::~ConfusableIdentifierCheck() = 
default;
 // We're skipping 1. and 3. for the sake of simplicity, but this can lead to
 // false positive.
 
-std::string ConfusableIdentifierCheck::skeleton(StringRef Name) {
+static std::string skeleton(StringRef Name) {
   using namespace llvm;
   std::string SName = Name.str();
   std::string Skeleton;
@@ -89,75 +89,107 @@ std::string ConfusableIdentifierCheck::skeleton(StringRef 
Name) {
   return Skeleton;
 }
 
-static bool mayShadowImpl(const NamedDecl *ND0, const NamedDecl *ND1) {
-  const DeclContext *DC0 = ND0->getDeclContext()->getPrimaryContext();
-  const DeclContext *DC1 = ND1->getDeclContext()->getPrimaryContext();
+static bool mayShadowImpl(const DeclContext *DC0, const DeclContext *DC1) {
+  return DC0 && DC0 == DC1;
+}
 
-  if (isa(ND0) || isa(ND0))
-return true;
+static bool mayShadowImpl(const NamedDecl *ND0, const NamedDecl *ND1) {
+  return isa(ND0) || isa(ND1);
+}
 
-  while (DC0->isTransparentContext())
-DC0 = DC0->getParent();
-  while (DC1->isTransparentContext())
-DC1 = DC1->getParent();
+static bool isMemberOf(const ConfusableIdentifierCheck::ContextInfo *DC0,
+   const ConfusableIdentifierCheck::ContextInfo *DC1) {
+  if (DC0->Bases.empty())
+return false;
+  return llvm::is_contained(DC1->Bases, DC0->PrimaryContext);
+}
 
-  if (DC0->Equals(DC1))
+static bool enclosesContext(const ConfusableIdentifierCheck::ContextInfo *DC0,
+const ConfusableIdentifierCheck::ContextInfo *DC1) 
{
+  if (DC0->PrimaryContext == DC1->PrimaryContext)
 return true;
 
-  return false;
+  return llvm::is_contained(DC0->PrimaryContexts, DC1->PrimaryContext) ||
+ llvm::is_contained(DC1->PrimaryContexts, DC0->PrimaryContext);
 }
 
-static bool isMemberOf(const NamedDecl *ND, const CXXRecordDecl *RD) {
-  const DeclContext *NDParent = ND->getDeclContext();
-  if (!NDParent || !isa(NDParent))
-return false;
-  if (NDParent == RD)
+static bool mayShadow(const NamedDecl *ND0,
+  const ConfusableIdentifierCheck::ContextInfo *DC0,
+  const NamedDecl *ND1,
+  const ConfusableIdentifierCheck::ContextInfo *DC1) {
+  if (!DC0->Bases.empty() && ND1->getAccess() != AS_private &&
+  isMemberOf(DC1, DC0))
 return true;
-  return !RD->forallBases(
-  [NDParent](const CXXRecordDecl *Base) { return NDParent != Base; });
+  if (!DC1->Bases.empty() && ND0->getAccess() != AS_private &&
+  isMemberOf(DC0, DC1))
+return true;
+
+  return enclosesContext(DC0, DC1) &&
+ (mayShadowImpl(ND0, ND1) || mayShadowImpl(DC0->NonTransparentContext,
+   
DC1->NonTransparentContext));
 }
 
-static bool mayShadow(const NamedDecl *ND0, const NamedDecl *ND1) {
+const ConfusableIdentifierCheck::ContextInfo *
+ConfusableIdentifierCheck::getContextInfo(const DeclContext *DC) {
+  const DeclContext *PrimaryContext = DC->getPrimaryContext();
+  auto It = ContextInfos.find(PrimaryContext);
+  if (It != ContextInfos.end())
+return >second;
+
+  ContextInfo  = ContextInfos[PrimaryContext];
+  Info.PrimaryContext = PrimaryContext;
+  Info.NonTransparentContext = PrimaryContext;
+
+  while (Info.NonTransparentContext->isTransparentContext()) {
+Info.NonTransparentContext = Info.NonTransparentContext->getParent();
+if (!Info.NonTransparentContext)
+  break;
+  }
 
-  const DeclContext *DC0 = ND0->getDeclContext()->getPrimaryContext();
-  

[PATCH] D151572: [clang][ConstantEmitter] have tryEmitPrivate try ConstExprEmitter fast-path first

2023-05-26 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers created this revision.
Herald added a project: All.
nickdesaulniers requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

As suggested by @efriedma in:
https://reviews.llvm.org/D76096#4370369

Some minor code style fixes as well in
ConstantEmitter::tryEmitPrivateForVarInit.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D151572

Files:
  clang/lib/CodeGen/CGExprConstant.cpp


Index: clang/lib/CodeGen/CGExprConstant.cpp
===
--- clang/lib/CodeGen/CGExprConstant.cpp
+++ clang/lib/CodeGen/CGExprConstant.cpp
@@ -1656,9 +1656,8 @@
 
   // Try to emit the initializer.  Note that this can allow some things that
   // are not allowed by tryEmitPrivateForMemory alone.
-  if (auto value = D.evaluateValue()) {
+  if (APValue *value = D.evaluateValue())
 return tryEmitPrivateForMemory(*value, destType);
-  }
 
   // FIXME: Implement C++11 [basic.start.init]p2: if the initializer of a
   // reference is a constant expression, and the reference binds to a 
temporary,
@@ -1672,10 +1671,10 @@
   const Expr *E = D.getInit();
   assert(E && "No initializer to emit");
 
-  auto nonMemoryDestType = getNonMemoryType(CGM, destType);
-  auto C =
-ConstExprEmitter(*this).Visit(const_cast(E), nonMemoryDestType);
-  return (C ? emitForMemory(C, destType) : nullptr);
+  QualType nonMemoryDestType = getNonMemoryType(CGM, destType);
+  llvm::Constant *C =
+  ConstExprEmitter(*this).Visit(const_cast(E), nonMemoryDestType);
+  return C ? emitForMemory(C, destType) : nullptr;
 }
 
 llvm::Constant *
@@ -1742,6 +1741,10 @@
 QualType destType) {
   assert(!destType->isVoidType() && "can't emit a void constant");
 
+  if (llvm::Constant *C =
+  ConstExprEmitter(*this).Visit(const_cast(E), destType))
+return C;
+
   Expr::EvalResult Result;
 
   bool Success = false;
@@ -1751,13 +1754,10 @@
   else
 Success = E->EvaluateAsRValue(Result, CGM.getContext(), InConstantContext);
 
-  llvm::Constant *C;
   if (Success && !Result.HasSideEffects)
-C = tryEmitPrivate(Result.Val, destType);
-  else
-C = ConstExprEmitter(*this).Visit(const_cast(E), destType);
+return tryEmitPrivate(Result.Val, destType);
 
-  return C;
+  return nullptr;
 }
 
 llvm::Constant *CodeGenModule::getNullPointer(llvm::PointerType *T, QualType 
QT) {


Index: clang/lib/CodeGen/CGExprConstant.cpp
===
--- clang/lib/CodeGen/CGExprConstant.cpp
+++ clang/lib/CodeGen/CGExprConstant.cpp
@@ -1656,9 +1656,8 @@
 
   // Try to emit the initializer.  Note that this can allow some things that
   // are not allowed by tryEmitPrivateForMemory alone.
-  if (auto value = D.evaluateValue()) {
+  if (APValue *value = D.evaluateValue())
 return tryEmitPrivateForMemory(*value, destType);
-  }
 
   // FIXME: Implement C++11 [basic.start.init]p2: if the initializer of a
   // reference is a constant expression, and the reference binds to a temporary,
@@ -1672,10 +1671,10 @@
   const Expr *E = D.getInit();
   assert(E && "No initializer to emit");
 
-  auto nonMemoryDestType = getNonMemoryType(CGM, destType);
-  auto C =
-ConstExprEmitter(*this).Visit(const_cast(E), nonMemoryDestType);
-  return (C ? emitForMemory(C, destType) : nullptr);
+  QualType nonMemoryDestType = getNonMemoryType(CGM, destType);
+  llvm::Constant *C =
+  ConstExprEmitter(*this).Visit(const_cast(E), nonMemoryDestType);
+  return C ? emitForMemory(C, destType) : nullptr;
 }
 
 llvm::Constant *
@@ -1742,6 +1741,10 @@
 QualType destType) {
   assert(!destType->isVoidType() && "can't emit a void constant");
 
+  if (llvm::Constant *C =
+  ConstExprEmitter(*this).Visit(const_cast(E), destType))
+return C;
+
   Expr::EvalResult Result;
 
   bool Success = false;
@@ -1751,13 +1754,10 @@
   else
 Success = E->EvaluateAsRValue(Result, CGM.getContext(), InConstantContext);
 
-  llvm::Constant *C;
   if (Success && !Result.HasSideEffects)
-C = tryEmitPrivate(Result.Val, destType);
-  else
-C = ConstExprEmitter(*this).Visit(const_cast(E), destType);
+return tryEmitPrivate(Result.Val, destType);
 
-  return C;
+  return nullptr;
 }
 
 llvm::Constant *CodeGenModule::getNullPointer(llvm::PointerType *T, QualType QT) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D151515: [CodeGen] add additional cast when checking call arguments

2023-05-26 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added a comment.

Relevant bit of the AST:

  `-ExprWithCleanups 0xd16a780  'void':'void'
`-CXXOperatorCallExpr 0xd16a678  'void':'void' '()'
  |-ImplicitCastExpr 0xd16a5a8  'void (*)(int (&&)[]) const' 

  | `-DeclRefExpr 0xd16a528  'void (int (&&)[]) const' lvalue 
CXXMethod 0xd14f7f8 'operator()' 'void (int (&&)[]) const'
  |-ImplicitCastExpr 0xd16a5e8  'const (lambda at :5:12)' 
lvalue 
  | `-DeclRefExpr 0xd16a460  '(lambda at :5:12)':'(lambda at 
:5:12)' lvalue Var 0xd14f628 'f' '(lambda at :5:12)':'(lambda at 
:5:12)'
  `-MaterializeTemporaryExpr 0xd16a660  'int[1]' xvalue
`-InitListExpr 0xd16a600  'int[1]'
  `-ImplicitCastExpr 0xd16a640  'int' 
`-DeclRefExpr 0xd16a480  'int' lvalue ParmVar 0xd14f3a8 'a' 
'int'

At first glance, I'd consider this a problem with the AST: there should be a 
no-op cast from `int[1]` to `int[]`.  We generate such a cast for the following:

  void foo(int a) {
auto f = [](int(&&)[]) {};
int aa[1] = {a};
f(static_cast(aa));
  }


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151515

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


[PATCH] D151492: Add fastmath attributes to llvm.call_intrinsic

2023-05-26 Thread Lily Orth-Smith via Phabricator via cfe-commits
electriclilies updated this revision to Diff 526117.
electriclilies added a comment.

fix


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151492

Files:
  mlir/include/mlir/Dialect/LLVMIR/LLVMIntrinsicOps.td
  mlir/lib/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.cpp
  mlir/test/Dialect/LLVMIR/call-intrin.mlir


Index: mlir/test/Dialect/LLVMIR/call-intrin.mlir
===
--- mlir/test/Dialect/LLVMIR/call-intrin.mlir
+++ mlir/test/Dialect/LLVMIR/call-intrin.mlir
@@ -5,13 +5,13 @@
 // CHECK: declare ptr @malloc(i64)
 // CHECK: declare void @free(ptr)
 // CHECK: define <4 x float> @round_sse41() {
-// CHECK:  %1 = call <4 x float> @llvm.x86.sse41.round.ss(<4 x float> , <4 x float> , i32 1)
+// CHECK:  %1 = call reassoc <4 x float> @llvm.x86.sse41.round.ss(<4 x float> 
, <4 x float> , i32 1)
 // CHECK:  ret <4 x float> %1
 // CHECK: }
 llvm.func @round_sse41() -> vector<4xf32> {
 %0 = llvm.mlir.constant(1 : i32) : i32
 %1 = llvm.mlir.constant(dense<0.2> : vector<4xf32>) : vector<4xf32>
-%res = llvm.call_intrinsic "llvm.x86.sse41.round.ss"(%1, %1, %0) : 
(vector<4xf32>, vector<4xf32>, i32) -> vector<4xf32> {}
+%res = llvm.call_intrinsic "llvm.x86.sse41.round.ss"(%1, %1, %0) : 
(vector<4xf32>, vector<4xf32>, i32) -> vector<4xf32> {fastmathFlags = 
#llvm.fastmath}
 llvm.return %res: vector<4xf32>
 }
 
Index: mlir/lib/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.cpp
===
--- mlir/lib/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.cpp
+++ mlir/lib/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.cpp
@@ -95,7 +95,7 @@
 
 /// Builder for LLVM_CallIntrinsicOp
 static LogicalResult
-convertCallLLVMIntrinsicOp(CallIntrinsicOp , llvm::IRBuilderBase ,
+convertCallLLVMIntrinsicOp(CallIntrinsicOp op, llvm::IRBuilderBase ,
LLVM::ModuleTranslation ) {
   llvm::Module *module = builder.GetInsertBlock()->getModule();
   llvm::Intrinsic::ID id =
@@ -114,6 +114,8 @@
   } else {
 fn = llvm::Intrinsic::getDeclaration(module, id, {});
   }
+  FastmathFlagsInterface itf = op;
+  builder.setFastMathFlags(getFastmathFlags(itf));
 
   auto *inst =
   builder.CreateCall(fn, moduleTranslation.lookupValues(op.getOperands()));
Index: mlir/include/mlir/Dialect/LLVMIR/LLVMIntrinsicOps.td
===
--- mlir/include/mlir/Dialect/LLVMIR/LLVMIntrinsicOps.td
+++ mlir/include/mlir/Dialect/LLVMIR/LLVMIntrinsicOps.td
@@ -867,19 +867,24 @@
 // CallIntrinsicOp
 //======//
 
-def LLVM_CallIntrinsicOp : LLVM_Op<"call_intrinsic"> {
+def LLVM_CallIntrinsicOp
+: LLVM_Op<"call_intrinsic",
+  [DeclareOpInterfaceMethods]> {
   let summary = "Call to an LLVM intrinsic function.";
   let description = [{
 Call the specified llvm intrinsic. If the intrinsic is overloaded, use
 the MLIR function type of this op to determine which intrinsic to call.
 }];
-  let arguments = (ins StrAttr:$intrin, Variadic:$args);
+  let arguments = (ins StrAttr:$intrin, Variadic:$args,
+   DefaultValuedAttr:$fastmathFlags);
   let results = (outs Variadic:$results);
   let llvmBuilder = [{
 return convertCallLLVMIntrinsicOp(op, builder, moduleTranslation);
   }];
   let assemblyFormat = [{
-$intrin `(` $args `)` `:` functional-type($args, $results) attr-dict
+$intrin `(` $args `)` `:` functional-type($args, $results)
+  custom(attr-dict)
   }];
 }
 


Index: mlir/test/Dialect/LLVMIR/call-intrin.mlir
===
--- mlir/test/Dialect/LLVMIR/call-intrin.mlir
+++ mlir/test/Dialect/LLVMIR/call-intrin.mlir
@@ -5,13 +5,13 @@
 // CHECK: declare ptr @malloc(i64)
 // CHECK: declare void @free(ptr)
 // CHECK: define <4 x float> @round_sse41() {
-// CHECK:  %1 = call <4 x float> @llvm.x86.sse41.round.ss(<4 x float> , <4 x float> , i32 1)
+// CHECK:  %1 = call reassoc <4 x float> @llvm.x86.sse41.round.ss(<4 x float> , <4 x float> , i32 1)
 // CHECK:  ret <4 x float> %1
 // CHECK: }
 llvm.func @round_sse41() -> vector<4xf32> {
 %0 = llvm.mlir.constant(1 : i32) : i32
 %1 = llvm.mlir.constant(dense<0.2> : vector<4xf32>) : vector<4xf32>
-%res = llvm.call_intrinsic "llvm.x86.sse41.round.ss"(%1, %1, %0) : (vector<4xf32>, vector<4xf32>, i32) -> vector<4xf32> {}
+%res = llvm.call_intrinsic "llvm.x86.sse41.round.ss"(%1, %1, %0) : (vector<4xf32>, vector<4xf32>, i32) -> vector<4xf32> {fastmathFlags = #llvm.fastmath}
 llvm.return %res: vector<4xf32>
 }
 
Index: mlir/lib/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.cpp
===
--- mlir/lib/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.cpp

[PATCH] D151517: Fix wrong error message when compiling C souce code

2023-05-26 Thread Jennifer Yu via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGacb1b4fbb793: Fix wrong error message when compiling C souce 
code: (authored by jyu2).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151517

Files:
  clang/lib/Parse/ParseOpenMP.cpp
  clang/test/OpenMP/target_uses_allocators.c


Index: clang/test/OpenMP/target_uses_allocators.c
===
--- clang/test/OpenMP/target_uses_allocators.c
+++ clang/test/OpenMP/target_uses_allocators.c
@@ -2,6 +2,8 @@
 // RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=50  -triple 
powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu 
-emit-llvm %s -o - | FileCheck %s
 // RUN: %clang_cc1 -fopenmp -fopenmp-version=50 -x c++ -triple 
powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -verify 
-emit-pch -o %t %s
 // RUN: %clang_cc1 -fopenmp -fopenmp-version=50 -x c++ -triple 
powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu 
-include-pch %t %s -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -fopenmp -fopenmp-version=50 -triple 
powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -verify 
-emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp -fopenmp-version=50 -triple 
powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu 
-include-pch %t %s -emit-llvm -o - | FileCheck %s
 
 #ifndef HEADER
 #define HEADER
@@ -19,9 +21,27 @@
   KMP_ALLOCATOR_MAX_HANDLE = __UINTPTR_MAX__
 } omp_allocator_handle_t;
 
+typedef enum omp_alloctrait_key_t { omp_atk_sync_hint = 1,
+omp_atk_alignment = 2,
+omp_atk_access = 3,
+omp_atk_pool_size = 4,
+omp_atk_fallback = 5,
+omp_atk_fb_data = 6,
+omp_atk_pinned = 7,
+omp_atk_partition = 8
+} omp_alloctrait_key_t;
+
+typedef struct omp_alloctrait_t {
+  omp_alloctrait_key_t key;
+  __UINTPTR_TYPE__ value;
+} omp_alloctrait_t;
+
+
 // CHECK: define {{.*}}[[FIE:@.+]]()
 void fie(void) {
   int x;
+  omp_allocator_handle_t my_allocator;
+  omp_alloctrait_t traits[10];
   #pragma omp target uses_allocators(omp_null_allocator) 
allocate(omp_null_allocator: x) firstprivate(x)
   {}
   #pragma omp target uses_allocators(omp_default_mem_alloc) 
allocate(omp_default_mem_alloc: x) firstprivate(x)
@@ -40,6 +60,8 @@
   {}
   #pragma omp target uses_allocators(omp_thread_mem_alloc) 
allocate(omp_thread_mem_alloc: x) firstprivate(x) // expected-warning 
{{allocator with the 'thread' trait access has unspecified behavior on 'target' 
directive}}
   {}
+#pragma omp target uses_allocators(omp_null_allocator, omp_thread_mem_alloc, 
my_allocator(traits))
+  {}
 }
 
 #endif
@@ -106,3 +128,16 @@
 // CHECK-NEXT: %[[#R1:]] = load i32, ptr %x.addr, align 4
 // CHECK-NEXT: store i32 %[[#R1]], ptr %.x..void.addr, align 4
 // CHECK-NEXT: call void @__kmpc_free(i32 %[[#R0]], ptr %.x..void.addr, ptr 
inttoptr (i64 8 to ptr))
+
+// CHECK: [[TRAITS_ADDR_REF:%.+]] = alloca ptr,
+// CHECK: [[MY_ALLOCATOR_ADDR:%.+]] = alloca i64,
+// CHECK: [[TRAITS_ADDR:%.+]] = load ptr, ptr [[TRAITS_ADDR_REF]],
+// CHECK: [[TRAITS:%.+]] = load ptr, ptr [[TRAITS_ADDR]],
+// CHECK: [[ALLOCATOR:%.+]] = call ptr @__kmpc_init_allocator(i32 %{{.+}}, ptr 
null, i32 10, ptr [[TRAITS]])
+// CHECK: [[CONV:%.+]] = ptrtoint ptr [[ALLOCATOR]] to i64
+// CHECK: store i64 [[CONV]], ptr [[MY_ALLOCATOR_ADDR]],
+
+// Destroy allocator upon exit from the region.
+// CHECK: [[ALLOCATOR:%.+]] = load i64, ptr [[MY_ALLOCATOR_ADDR]],
+// CHECK: [[CONV:%.+]] = inttoptr i64 [[ALLOCATOR]] to ptr
+// CHECK: call void @__kmpc_destroy_allocator(i32 %{{.+}}, ptr [[CONV]])
Index: clang/lib/Parse/ParseOpenMP.cpp
===
--- clang/lib/Parse/ParseOpenMP.cpp
+++ clang/lib/Parse/ParseOpenMP.cpp
@@ -3103,8 +3103,13 @@
 return nullptr;
   SmallVector Data;
   do {
+CXXScopeSpec SS;
+Token Replacement;
 ExprResult Allocator =
-getLangOpts().CPlusPlus ? ParseCXXIdExpression() : ParseExpression();
+getLangOpts().CPlusPlus
+? ParseCXXIdExpression()
+: tryParseCXXIdExpression(SS, /*isAddressOfOperand=*/false,
+  Replacement);
 if (Allocator.isInvalid()) {
   SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end,
 StopBeforeMatch);


Index: clang/test/OpenMP/target_uses_allocators.c
===
--- clang/test/OpenMP/target_uses_allocators.c
+++ clang/test/OpenMP/target_uses_allocators.c
@@ -2,6 +2,8 @@
 // RUN: %clang_cc1 -verify 

[clang] acb1b4f - Fix wrong error message when compiling C souce code:

2023-05-26 Thread Jennifer Yu via cfe-commits

Author: Jennifer Yu
Date: 2023-05-26T10:14:52-07:00
New Revision: acb1b4fbb7939faa369337b9b26b960fdc91e4b8

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

LOG: Fix wrong error message when compiling C souce code:
Currently emit error for uses_allocators(alloc(traits)):

called object type 'omp_allocator_handle_t' (aka
'enum omp_allocator_handle_t') is not a function or function pointer

To fix this, since "alloc" is Id expresison(spce 5.2), during the parser
(in ParseOpenMP.cpp), using tryParseCXXIdExpression instead of
ParseExpression for C.

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

Added: 


Modified: 
clang/lib/Parse/ParseOpenMP.cpp
clang/test/OpenMP/target_uses_allocators.c

Removed: 




diff  --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp
index a7db7a1c2582..8c57dc9e071f 100644
--- a/clang/lib/Parse/ParseOpenMP.cpp
+++ b/clang/lib/Parse/ParseOpenMP.cpp
@@ -3103,8 +3103,13 @@ OMPClause 
*Parser::ParseOpenMPUsesAllocatorClause(OpenMPDirectiveKind DKind) {
 return nullptr;
   SmallVector Data;
   do {
+CXXScopeSpec SS;
+Token Replacement;
 ExprResult Allocator =
-getLangOpts().CPlusPlus ? ParseCXXIdExpression() : ParseExpression();
+getLangOpts().CPlusPlus
+? ParseCXXIdExpression()
+: tryParseCXXIdExpression(SS, /*isAddressOfOperand=*/false,
+  Replacement);
 if (Allocator.isInvalid()) {
   SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end,
 StopBeforeMatch);

diff  --git a/clang/test/OpenMP/target_uses_allocators.c 
b/clang/test/OpenMP/target_uses_allocators.c
index f096c4a3f275..566fa51686db 100644
--- a/clang/test/OpenMP/target_uses_allocators.c
+++ b/clang/test/OpenMP/target_uses_allocators.c
@@ -2,6 +2,8 @@
 // RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=50  -triple 
powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu 
-emit-llvm %s -o - | FileCheck %s
 // RUN: %clang_cc1 -fopenmp -fopenmp-version=50 -x c++ -triple 
powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -verify 
-emit-pch -o %t %s
 // RUN: %clang_cc1 -fopenmp -fopenmp-version=50 -x c++ -triple 
powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu 
-include-pch %t %s -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -fopenmp -fopenmp-version=50 -triple 
powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -verify 
-emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp -fopenmp-version=50 -triple 
powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu 
-include-pch %t %s -emit-llvm -o - | FileCheck %s
 
 #ifndef HEADER
 #define HEADER
@@ -19,9 +21,27 @@ typedef enum omp_allocator_handle_t {
   KMP_ALLOCATOR_MAX_HANDLE = __UINTPTR_MAX__
 } omp_allocator_handle_t;
 
+typedef enum omp_alloctrait_key_t { omp_atk_sync_hint = 1,
+omp_atk_alignment = 2,
+omp_atk_access = 3,
+omp_atk_pool_size = 4,
+omp_atk_fallback = 5,
+omp_atk_fb_data = 6,
+omp_atk_pinned = 7,
+omp_atk_partition = 8
+} omp_alloctrait_key_t;
+
+typedef struct omp_alloctrait_t {
+  omp_alloctrait_key_t key;
+  __UINTPTR_TYPE__ value;
+} omp_alloctrait_t;
+
+
 // CHECK: define {{.*}}[[FIE:@.+]]()
 void fie(void) {
   int x;
+  omp_allocator_handle_t my_allocator;
+  omp_alloctrait_t traits[10];
   #pragma omp target uses_allocators(omp_null_allocator) 
allocate(omp_null_allocator: x) firstprivate(x)
   {}
   #pragma omp target uses_allocators(omp_default_mem_alloc) 
allocate(omp_default_mem_alloc: x) firstprivate(x)
@@ -40,6 +60,8 @@ void fie(void) {
   {}
   #pragma omp target uses_allocators(omp_thread_mem_alloc) 
allocate(omp_thread_mem_alloc: x) firstprivate(x) // expected-warning 
{{allocator with the 'thread' trait access has unspecified behavior on 'target' 
directive}}
   {}
+#pragma omp target uses_allocators(omp_null_allocator, omp_thread_mem_alloc, 
my_allocator(traits))
+  {}
 }
 
 #endif
@@ -106,3 +128,16 @@ void fie(void) {
 // CHECK-NEXT: %[[#R1:]] = load i32, ptr %x.addr, align 4
 // CHECK-NEXT: store i32 %[[#R1]], ptr %.x..void.addr, align 4
 // CHECK-NEXT: call void @__kmpc_free(i32 %[[#R0]], ptr %.x..void.addr, ptr 
inttoptr (i64 8 to ptr))
+
+// CHECK: [[TRAITS_ADDR_REF:%.+]] = alloca ptr,
+// CHECK: [[MY_ALLOCATOR_ADDR:%.+]] = alloca i64,
+// CHECK: [[TRAITS_ADDR:%.+]] = load ptr, ptr [[TRAITS_ADDR_REF]],
+// CHECK: [[TRAITS:%.+]] = load ptr, ptr [[TRAITS_ADDR]],
+// CHECK: [[ALLOCATOR:%.+]] = call ptr 

[PATCH] D151492: Add fastmath attributes to llvm.call_intrinsic

2023-05-26 Thread Lily Orth-Smith via Phabricator via cfe-commits
electriclilies updated this revision to Diff 526115.
electriclilies added a comment.

fix test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151492

Files:
  mlir/include/mlir/Dialect/LLVMIR/LLVMIntrinsicOps.td
  mlir/lib/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.cpp
  mlir/test/Dialect/LLVMIR/call-intrin.mlir


Index: mlir/test/Dialect/LLVMIR/call-intrin.mlir
===
--- mlir/test/Dialect/LLVMIR/call-intrin.mlir
+++ mlir/test/Dialect/LLVMIR/call-intrin.mlir
@@ -5,13 +5,13 @@
 // CHECK: declare ptr @malloc(i64)
 // CHECK: declare void @free(ptr)
 // CHECK: define <4 x float> @round_sse41() {
-// CHECK:  %1 = call <4 x float> @llvm.x86.sse41.round.ss(<4 x float> , <4 x float> , i32 1)
+// CHECK:  %1 = call <4 x float> @llvm.x86.sse41.round.ss(<4 x float> , <4 x float> , i32 1) 
{fastmathFlags = #llvm.fastmath}
 // CHECK:  ret <4 x float> %1
 // CHECK: }
 llvm.func @round_sse41() -> vector<4xf32> {
 %0 = llvm.mlir.constant(1 : i32) : i32
 %1 = llvm.mlir.constant(dense<0.2> : vector<4xf32>) : vector<4xf32>
-%res = llvm.call_intrinsic "llvm.x86.sse41.round.ss"(%1, %1, %0) : 
(vector<4xf32>, vector<4xf32>, i32) -> vector<4xf32> {}
+%res = llvm.call_intrinsic "llvm.x86.sse41.round.ss"(%1, %1, %0) : 
(vector<4xf32>, vector<4xf32>, i32) -> vector<4xf32> {fastmathFlags = 
#llvm.fastmath}
 llvm.return %res: vector<4xf32>
 }
 
Index: mlir/lib/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.cpp
===
--- mlir/lib/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.cpp
+++ mlir/lib/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.cpp
@@ -95,7 +95,7 @@
 
 /// Builder for LLVM_CallIntrinsicOp
 static LogicalResult
-convertCallLLVMIntrinsicOp(CallIntrinsicOp , llvm::IRBuilderBase ,
+convertCallLLVMIntrinsicOp(CallIntrinsicOp op, llvm::IRBuilderBase ,
LLVM::ModuleTranslation ) {
   llvm::Module *module = builder.GetInsertBlock()->getModule();
   llvm::Intrinsic::ID id =
@@ -114,6 +114,8 @@
   } else {
 fn = llvm::Intrinsic::getDeclaration(module, id, {});
   }
+  FastmathFlagsInterface itf = op;
+  builder.setFastMathFlags(getFastmathFlags(itf));
 
   auto *inst =
   builder.CreateCall(fn, moduleTranslation.lookupValues(op.getOperands()));
Index: mlir/include/mlir/Dialect/LLVMIR/LLVMIntrinsicOps.td
===
--- mlir/include/mlir/Dialect/LLVMIR/LLVMIntrinsicOps.td
+++ mlir/include/mlir/Dialect/LLVMIR/LLVMIntrinsicOps.td
@@ -867,19 +867,24 @@
 // CallIntrinsicOp
 //======//
 
-def LLVM_CallIntrinsicOp : LLVM_Op<"call_intrinsic"> {
+def LLVM_CallIntrinsicOp
+: LLVM_Op<"call_intrinsic",
+  [DeclareOpInterfaceMethods]> {
   let summary = "Call to an LLVM intrinsic function.";
   let description = [{
 Call the specified llvm intrinsic. If the intrinsic is overloaded, use
 the MLIR function type of this op to determine which intrinsic to call.
 }];
-  let arguments = (ins StrAttr:$intrin, Variadic:$args);
+  let arguments = (ins StrAttr:$intrin, Variadic:$args,
+   DefaultValuedAttr:$fastmathFlags);
   let results = (outs Variadic:$results);
   let llvmBuilder = [{
 return convertCallLLVMIntrinsicOp(op, builder, moduleTranslation);
   }];
   let assemblyFormat = [{
-$intrin `(` $args `)` `:` functional-type($args, $results) attr-dict
+$intrin `(` $args `)` `:` functional-type($args, $results)
+  custom(attr-dict)
   }];
 }
 


Index: mlir/test/Dialect/LLVMIR/call-intrin.mlir
===
--- mlir/test/Dialect/LLVMIR/call-intrin.mlir
+++ mlir/test/Dialect/LLVMIR/call-intrin.mlir
@@ -5,13 +5,13 @@
 // CHECK: declare ptr @malloc(i64)
 // CHECK: declare void @free(ptr)
 // CHECK: define <4 x float> @round_sse41() {
-// CHECK:  %1 = call <4 x float> @llvm.x86.sse41.round.ss(<4 x float> , <4 x float> , i32 1)
+// CHECK:  %1 = call <4 x float> @llvm.x86.sse41.round.ss(<4 x float> , <4 x float> , i32 1) {fastmathFlags = #llvm.fastmath}
 // CHECK:  ret <4 x float> %1
 // CHECK: }
 llvm.func @round_sse41() -> vector<4xf32> {
 %0 = llvm.mlir.constant(1 : i32) : i32
 %1 = llvm.mlir.constant(dense<0.2> : vector<4xf32>) : vector<4xf32>
-%res = llvm.call_intrinsic "llvm.x86.sse41.round.ss"(%1, %1, %0) : (vector<4xf32>, vector<4xf32>, i32) -> vector<4xf32> {}
+%res = llvm.call_intrinsic "llvm.x86.sse41.round.ss"(%1, %1, %0) : (vector<4xf32>, vector<4xf32>, i32) -> vector<4xf32> {fastmathFlags = #llvm.fastmath}
 llvm.return %res: vector<4xf32>
 }
 
Index: mlir/lib/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.cpp
===
--- 

[PATCH] D151515: [CodeGen] add additional cast when checking call arguments

2023-05-26 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added subscribers: efriedma, rjmccall, rnk.
rnk added inline comments.



Comment at: clang/lib/CodeGen/CGCall.cpp:4376
+.getTypePtr()
+->getPointeeOrArrayElementType();
+  const Type *CanonicalArgTy = getContext()

I think this discards too much information about pointer types. I think it 
would treat two pointers with interestingly different qualifiers differently. 
Consider, perhaps, a mismatch in pointer address spaces, which are passed 
differently (think `__ptr32` `__ptr64`).

I think there is probably some other way to get the type of the parameter after 
pointer decay. I would ask @efriedma since he's the current IRGen owner or 
@rjmccall  since I think he may have added this prototype assertion originally, 
I just moved the code around.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151515

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


  1   2   >