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

2024-05-27 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-debuginfo

Author: David Stone (davidstone)


Changes



---

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


59 Files Affected:

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


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

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

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


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

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

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

https://github.com/redstar commented:

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

struct Elem {
  float a;
  Float2 b;
};

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

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


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

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


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

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

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

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


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

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


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

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

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


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

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

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


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

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

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


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

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

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


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

MaskRay wrote:

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

The existing ones should be cleaned up as well.

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


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

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

MaskRay wrote:

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

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


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

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

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


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

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

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


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

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


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

MaskRay wrote:

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

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

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


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

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


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

MaskRay wrote:

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

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


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

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

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


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

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

Endilll wrote:

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

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


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

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

MaskRay wrote:

> [llvm] Add triples for managarm

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

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


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

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

davidstone wrote:

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

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

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


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

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

davidstone wrote:

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

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

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


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

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

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

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

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

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

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

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

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

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


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

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

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


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

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

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


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

2024-05-27 Thread via cfe-commits

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

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

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

Closes #92999.

Added: 


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

Removed: 




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

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

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

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

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

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

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

Endilll wrote:

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

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


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

2024-05-27 Thread via cfe-commits

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

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

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

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

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

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

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

Added: 


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

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



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

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

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

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


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

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


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

Endilll wrote:

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

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


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

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

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

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

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

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

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

Added: 


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

Removed: 




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

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

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

davidstone wrote:

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

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


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

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

MaskRay wrote:

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

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


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

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

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

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

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

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

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

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

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

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

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

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


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

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

owenca wrote:

/cherry-pick d89f20058b45e3836527e816af7ed7372e1d554d

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


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

2024-05-27 Thread via cfe-commits

llvmbot wrote:

/pull-request llvm/llvm-project#93494

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


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

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

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

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

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

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

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

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

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

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

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

2024-05-27 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-backend-aarch64

@llvm/pr-subscribers-backend-arm

Author: Hassnaa Hamdi (hassnaaHamdi)


Changes

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

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

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


11 Files Affected:

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


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

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

2024-05-27 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Hassnaa Hamdi (hassnaaHamdi)


Changes

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

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

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


11 Files Affected:

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


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

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

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

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

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

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

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

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

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

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

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


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

ChuanqiXu9 wrote:

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

One possible way maybe:

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

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


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

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

ChuanqiXu9 wrote:

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

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

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


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

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

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


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

2024-05-27 Thread via cfe-commits

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

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

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

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

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

Modified: 
clang/lib/Serialization/ASTWriter.cpp

Removed: 




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

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



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


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

2024-05-27 Thread via cfe-commits

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

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

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

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

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

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


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

2024-05-27 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-codegen

Author: None (gulfemsavrun)


Changes

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

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


1 Files Affected:

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


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

``




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


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

2024-05-27 Thread via cfe-commits

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

None

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

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

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

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

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

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

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

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

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

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

2024-05-27 Thread via cfe-commits

github-actions[bot] wrote:



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

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

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

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

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

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

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

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


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

2024-05-27 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-llvm-support

@llvm/pr-subscribers-clang

Author: cratelschen (cratelschen)


Changes



---

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


7 Files Affected:

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


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

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

2024-05-27 Thread via cfe-commits

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


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

2024-05-27 Thread via cfe-commits

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


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

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

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

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

LOG: [unittest] Fix target triple

Added: 


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

Removed: 




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



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


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

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

MaskRay wrote:

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

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

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

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

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


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

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

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

None

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

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

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

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


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

2024-05-27 Thread via cfe-commits

github-actions[bot] wrote:



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

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

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

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

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

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

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

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


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

2024-05-27 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Samuel Marks (SamuelMarks)


Changes



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


1 Files Affected:

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


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

``




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


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

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

MaskRay wrote:

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

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

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

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

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


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

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

https://github.com/ChuanqiXu9 commented:

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

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


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

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


@@ -0,0 +1,88 @@
+//===--- CIRGenAction.cpp - LLVM Code generation Frontend Action -===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "clang/CIRFrontendAction/CIRGenAction.h"
+#include "clang/CIR/CIRGenerator.h"
+#include "clang/Frontend/CompilerInstance.h"
+
+#include "mlir/IR/MLIRContext.h"
+#include "mlir/IR/OwningOpRef.h"
+
+using namespace cir;
+using namespace clang;
+
+namespace cir {
+
+class CIRGenConsumer : public clang::ASTConsumer {
+
+  virtual void anchor();
+
+  [[maybe_unused]] CIRGenAction::OutputType action;
+
+  [[maybe_unused]] DiagnosticsEngine &diagnosticsEngine;
+  [[maybe_unused]] const HeaderSearchOptions &headerSearchOptions;
+  [[maybe_unused]] const CodeGenOptions &codeGenOptions;
+  [[maybe_unused]] const TargetOptions &targetOptions;
+  [[maybe_unused]] const LangOptions &langOptions;
+  [[maybe_unused]] const FrontendOptions &feOptions;
+
+  std::unique_ptr outputStream;
+
+  [[maybe_unused]] ASTContext *astContext{nullptr};
+  IntrusiveRefCntPtr FS;
+  std::unique_ptr gen;
+
+public:
+  CIRGenConsumer(CIRGenAction::OutputType action,
+ DiagnosticsEngine &diagnosticsEngine,
+ IntrusiveRefCntPtr VFS,
+ const HeaderSearchOptions &headerSearchOptions,
+ const CodeGenOptions &codeGenOptions,
+ const TargetOptions &targetOptions,
+ const LangOptions &langOptions,
+ const FrontendOptions &feOptions,
+ std::unique_ptr os)
+  : action(action), diagnosticsEngine(diagnosticsEngine),
+headerSearchOptions(headerSearchOptions),
+codeGenOptions(codeGenOptions), targetOptions(targetOptions),
+langOptions(langOptions), feOptions(feOptions),
+outputStream(std::move(os)), FS(VFS),
+gen(std::make_unique(diagnosticsEngine, std::move(VFS),
+   codeGenOptions)) {}
+
+  bool HandleTopLevelDecl(DeclGroupRef D) override {
+gen->HandleTopLevelDecl(D);
+return true;
+  }
+};
+} // namespace cir
+
+void CIRGenConsumer::anchor() {}
+
+CIRGenAction::CIRGenAction(OutputType act, mlir::MLIRContext *mlirContext)
+: mlirContext(mlirContext ? mlirContext : new mlir::MLIRContext),
+  action(act) {}
+
+CIRGenAction::~CIRGenAction() { mlirModule.release(); }
+
+std::unique_ptr
+CIRGenAction::CreateASTConsumer(CompilerInstance &ci, StringRef inputFile) {
+  auto out = ci.takeOutputStream();
+
+  auto Result = std::make_unique(
+  action, ci.getDiagnostics(), &ci.getVirtualFileSystem(),
+  ci.getHeaderSearchOpts(), ci.getCodeGenOpts(), ci.getTargetOpts(),
+  ci.getLangOpts(), ci.getFrontendOpts(), std::move(out));
+  cgConsumer = Result.get();

ChuanqiXu9 wrote:

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

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


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

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

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


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

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


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

ChuanqiXu9 wrote:

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

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


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

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


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

ChuanqiXu9 wrote:

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

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


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

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


@@ -0,0 +1,88 @@
+//===--- CIRGenAction.cpp - LLVM Code generation Frontend Action -===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "clang/CIRFrontendAction/CIRGenAction.h"
+#include "clang/CIR/CIRGenerator.h"
+#include "clang/Frontend/CompilerInstance.h"
+
+#include "mlir/IR/MLIRContext.h"
+#include "mlir/IR/OwningOpRef.h"
+
+using namespace cir;
+using namespace clang;
+
+namespace cir {
+
+class CIRGenConsumer : public clang::ASTConsumer {
+
+  virtual void anchor();
+
+  [[maybe_unused]] CIRGenAction::OutputType action;
+
+  [[maybe_unused]] DiagnosticsEngine &diagnosticsEngine;
+  [[maybe_unused]] const HeaderSearchOptions &headerSearchOptions;
+  [[maybe_unused]] const CodeGenOptions &codeGenOptions;
+  [[maybe_unused]] const TargetOptions &targetOptions;
+  [[maybe_unused]] const LangOptions &langOptions;
+  [[maybe_unused]] const FrontendOptions &feOptions;
+
+  std::unique_ptr outputStream;
+
+  [[maybe_unused]] ASTContext *astContext{nullptr};
+  IntrusiveRefCntPtr FS;
+  std::unique_ptr gen;
+
+public:
+  CIRGenConsumer(CIRGenAction::OutputType action,
+ DiagnosticsEngine &diagnosticsEngine,
+ IntrusiveRefCntPtr VFS,
+ const HeaderSearchOptions &headerSearchOptions,
+ const CodeGenOptions &codeGenOptions,
+ const TargetOptions &targetOptions,
+ const LangOptions &langOptions,
+ const FrontendOptions &feOptions,
+ std::unique_ptr os)
+  : action(action), diagnosticsEngine(diagnosticsEngine),
+headerSearchOptions(headerSearchOptions),
+codeGenOptions(codeGenOptions), targetOptions(targetOptions),
+langOptions(langOptions), feOptions(feOptions),
+outputStream(std::move(os)), FS(VFS),
+gen(std::make_unique(diagnosticsEngine, std::move(VFS),
+   codeGenOptions)) {}
+
+  bool HandleTopLevelDecl(DeclGroupRef D) override {
+gen->HandleTopLevelDecl(D);
+return true;
+  }
+};
+} // namespace cir
+
+void CIRGenConsumer::anchor() {}
+
+CIRGenAction::CIRGenAction(OutputType act, mlir::MLIRContext *mlirContext)
+: mlirContext(mlirContext ? mlirContext : new mlir::MLIRContext),
+  action(act) {}
+
+CIRGenAction::~CIRGenAction() { mlirModule.release(); }
+
+std::unique_ptr
+CIRGenAction::CreateASTConsumer(CompilerInstance &ci, StringRef inputFile) {
+  auto out = ci.takeOutputStream();
+
+  auto Result = std::make_unique(
+  action, ci.getDiagnostics(), &ci.getVirtualFileSystem(),
+  ci.getHeaderSearchOpts(), ci.getCodeGenOpts(), ci.getTargetOpts(),
+  ci.getLangOpts(), ci.getFrontendOpts(), std::move(out));
+  cgConsumer = Result.get();
+
+  return std::move(Result);

ChuanqiXu9 wrote:

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

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


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

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


@@ -0,0 +1,59 @@
+//===- CIRGenerator.h - CIR Generation from Clang AST 
-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This file declares a simple interface to perform CIR generation from Clang
+// AST
+//
+//===--===//
+
+#ifndef CLANG_CIRGENERATOR_H_
+#define CLANG_CIRGENERATOR_H_
+
+#include "clang/AST/ASTConsumer.h"
+#include "clang/AST/DeclGroup.h"
+#include "clang/Basic/CodeGenOptions.h"
+#include "clang/Basic/Diagnostic.h"
+
+#include "llvm/ADT/IntrusiveRefCntPtr.h"
+#include "llvm/Support/VirtualFileSystem.h"
+
+#include 
+
+namespace mlir {
+class MLIRContext;
+} // namespace mlir
+namespace cir {
+class CIRGenModule;
+
+class CIRGenerator : public clang::ASTConsumer {
+  virtual void anchor();
+  clang::DiagnosticsEngine &Diags;
+  clang::ASTContext *astCtx;
+  llvm::IntrusiveRefCntPtr
+  fs; // Only used for debug info.
+
+  const clang::CodeGenOptions codeGenOpts; // Intentionally copied in.

ChuanqiXu9 wrote:

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

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


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

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

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


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

2024-05-27 Thread via cfe-commits

martinboehme wrote:

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

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


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

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


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

MaskRay wrote:

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

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


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

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

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

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

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

Added: 


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

Removed: 




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

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


[clang] f31b197 - [analyzer] Fix a test issue in mingw configurations (#92737)

2024-05-27 Thread via cfe-commits

Author: Martin Storsjö
Date: 2024-05-27T10:18:03+03:00
New Revision: f31b197d9df141effd439de8be51ce24f3e8f200

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

LOG: [analyzer] Fix a test issue in mingw configurations (#92737)

On Windows, long is always 32 bit, thus one can't use long for casting
pointers to integers, on 64 bit architectures.

Instead use long long, which should be large enough.

This avoids errors like "error: cast from pointer to smaller type 'long'
loses information" in this testcase.

This condition only seems to be an error in mingw mode; in MSVC mode
(clang-cl), this is only a warning.

Added: 


Modified: 
clang/unittests/StaticAnalyzer/MemRegionDescriptiveNameTest.cpp

Removed: 




diff  --git a/clang/unittests/StaticAnalyzer/MemRegionDescriptiveNameTest.cpp 
b/clang/unittests/StaticAnalyzer/MemRegionDescriptiveNameTest.cpp
index 03aee56a200f6..b13e7123ee524 100644
--- a/clang/unittests/StaticAnalyzer/MemRegionDescriptiveNameTest.cpp
+++ b/clang/unittests/StaticAnalyzer/MemRegionDescriptiveNameTest.cpp
@@ -90,7 +90,7 @@ void reportDescriptiveName(int *p);
 extern int* ptr;
 extern int array[3];
 void top() {
-  reportDescriptiveName(&array[(long)ptr]);
+  reportDescriptiveName(&array[(long long)ptr]);
 })cpp";
 
   std::string Output;



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


[clang] [analyzer] Fix a test issue in mingw configurations (PR #92737)

2024-05-27 Thread Martin Storsjö via cfe-commits

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


[clang] 0f85b25 - [clang] NFC: add a test case for TemplateName canonical type print issue

2024-05-27 Thread Matheus Izvekov via cfe-commits

Author: Matheus Izvekov
Date: 2024-05-27T04:45:20-03:00
New Revision: 0f85b25f51a3e06c48b3fe8042a3de1cf0e635d7

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

LOG: [clang] NFC: add a test case for TemplateName canonical type print issue

Added: 


Modified: 
clang/test/SemaTemplate/deduction-guide.cpp

Removed: 




diff  --git a/clang/test/SemaTemplate/deduction-guide.cpp 
b/clang/test/SemaTemplate/deduction-guide.cpp
index c38b647e42f4c..91c35d98fbf57 100644
--- a/clang/test/SemaTemplate/deduction-guide.cpp
+++ b/clang/test/SemaTemplate/deduction-guide.cpp
@@ -299,3 +299,34 @@ using AFoo = Foo>;
 // CHECK-NEXT:   `-ParmVarDecl {{.*}} 'G'
 
 AFoo aa(G{});
+
+namespace TTP {
+  template struct A {};
+
+  template struct B {
+template typename TT> B(TT);
+  };
+
+  B b(A{});
+} // namespace TTP
+
+// CHECK-LABEL: Dumping TTP:::
+// CHECK-NEXT:  FunctionTemplateDecl 0x{{.+}} <{{.+}}:[[# @LINE - 7]]:5, 
col:51>
+// CHECK-NEXT:  |-TemplateTypeParmDecl {{.+}} class depth 0 index 0 T{{$}}
+// CHECK-NEXT:  |-TemplateTemplateParmDecl {{.+}} depth 0 index 1 TT{{$}}
+// CHECK-NEXT:  | `-TemplateTypeParmDecl {{.+}} class depth 1 index 0{{$}}
+// CHECK-NEXT:  |-CXXDeductionGuideDecl {{.+}} 'auto () -> B'{{$}}
+// CHECK-NEXT:  | `-ParmVarDecl {{.+}} ''{{$}}
+// CHECK-NEXT:  `-CXXDeductionGuideDecl {{.+}} 'auto (A) -> TTP::B'
+// CHECK-NEXT:|-TemplateArgument type 'int'
+// CHECK-NEXT:| `-BuiltinType {{.+}} 'int'{{$}}
+// CHECK-NEXT:|-TemplateArgument template A
+// CHECK-NEXT:`-ParmVarDecl {{.+}} 'A':'TTP::A'{{$}}
+// CHECK-NEXT:  FunctionProtoType {{.+}} 'auto () -> B' dependent 
trailing_return cdecl{{$}}
+// CHECK-NEXT:  |-InjectedClassNameType {{.+}} 'B' dependent{{$}}
+// CHECK-NEXT:  | `-CXXRecord {{.+}} 'B'{{$}}
+// CHECK-NEXT:  `-ElaboratedType {{.+}} '' sugar dependent{{$}}
+// CHECK-NEXT:`-TemplateSpecializationType {{.+}} '' dependent {{$}}
+// CHECK-NEXT:  `-TemplateArgument type 'T'{{$}}
+// CHECK-NEXT:`-TemplateTypeParmType {{.+}} 'T' dependent depth 0 
index 0{{$}}
+// CHECK-NEXT:  `-TemplateTypeParm {{.+}} 'T'{{$}}



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


[clang] 76b9d38 - [clang][analyzer] PutenvStackArrayChecker: No warning from 'main' (#93299)

2024-05-27 Thread via cfe-commits

Author: Balázs Kéri
Date: 2024-05-27T09:55:10+02:00
New Revision: 76b9d38934572909ffc8c8ef4cd45407f22e6ea7

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

LOG: [clang][analyzer] PutenvStackArrayChecker: No warning from 'main' (#93299)

Added: 


Modified: 
clang/docs/analyzer/checkers.rst
clang/lib/StaticAnalyzer/Checkers/PutenvStackArrayChecker.cpp
clang/test/Analysis/putenv-stack-array.c

Removed: 




diff  --git a/clang/docs/analyzer/checkers.rst 
b/clang/docs/analyzer/checkers.rst
index ac9f0b06f63ba..3a31708a1e9de 100644
--- a/clang/docs/analyzer/checkers.rst
+++ b/clang/docs/analyzer/checkers.rst
@@ -2858,6 +2858,16 @@ The check corresponds to CERT rule
 return putenv(env); // putenv function should not be called with 
stack-allocated string
   }
 
+There is one case where the checker can report a false positive. This is when
+the stack-allocated array is used at `putenv` in a function or code branch that
+does not return (calls `fork` or `exec` like function).
+
+Another special case is if the `putenv` is called from function `main`. Here
+the stack is deallocated at the end of the program and it should be no problem
+to use the stack-allocated string (a multi-threaded program may require more
+attention). The checker does not warn for cases when stack space of `main` is
+used at the `putenv` call.
+
 .. _alpha-security-ReturnPtrRange:
 
 alpha.security.ReturnPtrRange (C)

diff  --git a/clang/lib/StaticAnalyzer/Checkers/PutenvStackArrayChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/PutenvStackArrayChecker.cpp
index d59cebf0aa5cb..bf81d57bf82fd 100644
--- a/clang/lib/StaticAnalyzer/Checkers/PutenvStackArrayChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/PutenvStackArrayChecker.cpp
@@ -44,9 +44,14 @@ void PutenvStackArrayChecker::checkPostCall(const CallEvent 
&Call,
 
   SVal ArgV = Call.getArgSVal(0);
   const Expr *ArgExpr = Call.getArgExpr(0);
-  const MemSpaceRegion *MSR = ArgV.getAsRegion()->getMemorySpace();
 
-  if (!isa(MSR))
+  const auto *SSR =
+  dyn_cast(ArgV.getAsRegion()->getMemorySpace());
+  if (!SSR)
+return;
+  const auto *StackFrameFuncD =
+  dyn_cast_or_null(SSR->getStackFrame()->getDecl());
+  if (StackFrameFuncD && StackFrameFuncD->isMain())
 return;
 
   StringRef ErrorMsg = "The 'putenv' function should not be called with "

diff  --git a/clang/test/Analysis/putenv-stack-array.c 
b/clang/test/Analysis/putenv-stack-array.c
index fbbf93259ab85..f28aed73031d3 100644
--- a/clang/test/Analysis/putenv-stack-array.c
+++ b/clang/test/Analysis/putenv-stack-array.c
@@ -45,6 +45,15 @@ int test_auto_var_subarray() {
   return putenv(env + 100); // expected-warning{{The 'putenv' function should 
not be called with}}
 }
 
+int f_test_auto_var_call(char *env) {
+  return putenv(env); // expected-warning{{The 'putenv' function should not be 
called with}}
+}
+
+int test_auto_var_call() {
+  char env[1024];
+  return f_test_auto_var_call(env);
+}
+
 int test_constant() {
   char *env = "TEST";
   return putenv(env); // no-warning: data is not on the stack
@@ -68,3 +77,14 @@ void test_auto_var_reset() {
   // become invalid.
   putenv((char *)"NAME=anothervalue");
 }
+
+void f_main(char *env) {
+  putenv(env); // no warning: string allocated in stack of 'main'
+}
+
+int main(int argc, char **argv) {
+  char env[] = "NAME=value";
+  putenv(env); // no warning: string allocated in stack of 'main'
+  f_main(env);
+  return 0;
+}



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


[clang] [clang][analyzer] PutenvStackArrayChecker: No warning from 'main' (PR #93299)

2024-05-27 Thread Balázs Kéri via cfe-commits

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


[clang] 7429950 - [clang][CodeComplete] Recurse into the subexpression of deref operator in getApproximateType (#93404)

2024-05-27 Thread via cfe-commits

Author: Younan Zhang
Date: 2024-05-27T15:56:37+08:00
New Revision: 7429950d840b8fec3d9a48d00e612a3240c2be83

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

LOG: [clang][CodeComplete] Recurse into the subexpression of deref operator in 
getApproximateType (#93404)

The issue with the previous implementation bc31be7 was that
getApproximateType could potentially return a null QualType for a
dereferencing operator, which is not what its caller wants.

Added: 


Modified: 
clang/lib/Sema/SemaCodeComplete.cpp
clang/test/CodeCompletion/member-access.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaCodeComplete.cpp 
b/clang/lib/Sema/SemaCodeComplete.cpp
index ad3ca4cc94ca6..cd1c5f9391ccd 100644
--- a/clang/lib/Sema/SemaCodeComplete.cpp
+++ b/clang/lib/Sema/SemaCodeComplete.cpp
@@ -5692,8 +5692,15 @@ QualType getApproximateType(const Expr *E) {
 }
   }
   if (const auto *UO = llvm::dyn_cast(E)) {
-if (UO->getOpcode() == UnaryOperatorKind::UO_Deref)
-  return UO->getSubExpr()->getType()->getPointeeType();
+if (UO->getOpcode() == UnaryOperatorKind::UO_Deref) {
+  // We recurse into the subexpression because it could be of dependent
+  // type.
+  if (auto Pointee = 
getApproximateType(UO->getSubExpr())->getPointeeType();
+  !Pointee.isNull())
+return Pointee;
+  // Our caller expects a non-null result, even though the SubType is
+  // supposed to have a pointee. Fall through to Unresolved anyway.
+}
   }
   return Unresolved;
 }

diff  --git a/clang/test/CodeCompletion/member-access.cpp 
b/clang/test/CodeCompletion/member-access.cpp
index 9f8c21c0bca6d..912f269db6c1a 100644
--- a/clang/test/CodeCompletion/member-access.cpp
+++ b/clang/test/CodeCompletion/member-access.cpp
@@ -367,4 +367,20 @@ class A {
 // CHECK-DEREF-THIS: [#void#]function()
   }
 };
+
+template 
+struct RepeatedField {
+  void Add();
+};
+
+template 
+RepeatedField* MutableRepeatedField() {}
+
+template 
+void Foo() {
+  auto& C = *MutableRepeatedField();
+  C.
+}
+// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:382:5 %s -o - | 
FileCheck -check-prefix=CHECK-DEREF-DEPENDENT %s
+// CHECK-DEREF-DEPENDENT: [#void#]Add()
 }



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


[clang] [clang][CodeComplete] Recurse into the subexpression of deref operator in getApproximateType (PR #93404)

2024-05-27 Thread Younan Zhang via cfe-commits

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


[clang] [clang] Improve ast-dumper text printing of TemplateArgument (PR #93431)

2024-05-27 Thread via cfe-commits

https://github.com/cor3ntin commented:

Thanks!

I think this is an improvement but we probably want to find a better syntax 
than quotes

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


[clang] [clang] Improve ast-dumper text printing of TemplateArgument (PR #93431)

2024-05-27 Thread via cfe-commits

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


[clang] [clang] Improve ast-dumper text printing of TemplateArgument (PR #93431)

2024-05-27 Thread via cfe-commits


@@ -947,6 +947,26 @@ void TextNodeDumper::dumpDeclRef(const Decl *D, StringRef 
Label) {
   });
 }
 
+void TextNodeDumper::dumpTemplateArgument(const TemplateArgument &TA) {
+  llvm::SmallString<128> Str;
+  {
+llvm::raw_svector_ostream SS(Str);
+TA.print(PrintPolicy, SS, /*IncludeType=*/true);
+  }
+  OS << " '" << Str << "'";
+
+  if (TemplateArgument CanonTA = Context->getCanonicalTemplateArgument(TA);
+  !CanonTA.structurallyEquals(TA)) {
+llvm::SmallString<128> CanonStr;
+{
+  llvm::raw_svector_ostream SS(CanonStr);
+  CanonTA.print(PrintPolicy, SS, /*IncludeType=*/true);
+}
+if (CanonStr != Str)
+  OS << ":'" << CanonStr << "'";
+  }

cor3ntin wrote:

Do we have tests for that?

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


[clang] [clang] Improve ast-dumper text printing of TemplateArgument (PR #93431)

2024-05-27 Thread via cfe-commits


@@ -947,6 +947,26 @@ void TextNodeDumper::dumpDeclRef(const Decl *D, StringRef 
Label) {
   });
 }
 
+void TextNodeDumper::dumpTemplateArgument(const TemplateArgument &TA) {
+  llvm::SmallString<128> Str;
+  {
+llvm::raw_svector_ostream SS(Str);
+TA.print(PrintPolicy, SS, /*IncludeType=*/true);
+  }
+  OS << " '" << Str << "'";

cor3ntin wrote:

I'm not sure how i feel about the quotes. It's particularly awkward in the char 
literal case

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


[clang] [clang] Improve ast-dumper text printing of TemplateArgument (PR #93431)

2024-05-27 Thread via cfe-commits


@@ -1086,45 +1106,100 @@ void TextNodeDumper::VisitNullTemplateArgument(const 
TemplateArgument &) {
 
 void TextNodeDumper::VisitTypeTemplateArgument(const TemplateArgument &TA) {
   OS << " type";
-  dumpType(TA.getAsType());
+  dumpTemplateArgument(TA);
 }
 
 void TextNodeDumper::VisitDeclarationTemplateArgument(
 const TemplateArgument &TA) {
   OS << " decl";
+  dumpTemplateArgument(TA);
   dumpDeclRef(TA.getAsDecl());
 }
 
-void TextNodeDumper::VisitNullPtrTemplateArgument(const TemplateArgument &) {
+void TextNodeDumper::VisitNullPtrTemplateArgument(const TemplateArgument &TA) {
   OS << " nullptr";
+  dumpTemplateArgument(TA);
 }
 
 void TextNodeDumper::VisitIntegralTemplateArgument(const TemplateArgument &TA) 
{
-  OS << " integral " << TA.getAsIntegral();
+  OS << " integral";
+  dumpTemplateArgument(TA);
+}
+
+void TextNodeDumper::dumpTemplateName(TemplateName TN) {
+  switch (TN.getKind()) {
+  case TemplateName::Template:
+AddChild([=] { Visit(TN.getAsTemplateDecl()); });
+return;
+  case TemplateName::UsingTemplate: {
+const UsingShadowDecl *USD = TN.getAsUsingShadowDecl();
+AddChild([=] { Visit(USD); });
+AddChild("target", [=] { Visit(USD->getTargetDecl()); });
+return;
+  }
+  case TemplateName::QualifiedTemplate: {
+OS << " qualified";
+const QualifiedTemplateName *QTN = TN.getAsQualifiedTemplateName();
+if (QTN->hasTemplateKeyword())
+  OS << " keyword";
+dumpNestedNameSpecifier(QTN->getQualifier());
+dumpTemplateName(QTN->getUnderlyingTemplate());
+return;
+  }
+  case TemplateName::DependentTemplate: {
+OS << " dependent";
+const DependentTemplateName *DTN = TN.getAsDependentTemplateName();
+dumpNestedNameSpecifier(DTN->getQualifier());
+return;
+  }
+  case TemplateName::SubstTemplateTemplateParm: {
+const SubstTemplateTemplateParmStorage *STS =
+TN.getAsSubstTemplateTemplateParm();
+OS << " subst index " << STS->getIndex();
+if (std::optional PackIndex = STS->getPackIndex())
+  OS << " pack_index " << *PackIndex;
+if (const TemplateTemplateParmDecl *P = STS->getParameter())
+  AddChild("parameter", [=] { Visit(P); });
+dumpDeclRef(STS->getAssociatedDecl(), "associated");
+AddChild("replacement", [=] { dumpTemplateName(STS->getReplacement()); });
+return;
+  }
+  // FIXME: Implement these.
+  case TemplateName::OverloadedTemplate:
+OS << " overloaded";
+return;
+  case TemplateName::AssumedTemplate:
+OS << " assumed";
+return;
+  case TemplateName::SubstTemplateTemplateParmPack:
+OS << " subst_pack";

cor3ntin wrote:

```suggestion
OS << " subst pack";
```

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


[clang] [clang] Improve ast-dumper text printing of TemplateArgument (PR #93431)

2024-05-27 Thread via cfe-commits


@@ -1086,45 +1106,100 @@ void TextNodeDumper::VisitNullTemplateArgument(const 
TemplateArgument &) {
 
 void TextNodeDumper::VisitTypeTemplateArgument(const TemplateArgument &TA) {
   OS << " type";
-  dumpType(TA.getAsType());
+  dumpTemplateArgument(TA);
 }
 
 void TextNodeDumper::VisitDeclarationTemplateArgument(
 const TemplateArgument &TA) {
   OS << " decl";
+  dumpTemplateArgument(TA);
   dumpDeclRef(TA.getAsDecl());
 }
 
-void TextNodeDumper::VisitNullPtrTemplateArgument(const TemplateArgument &) {
+void TextNodeDumper::VisitNullPtrTemplateArgument(const TemplateArgument &TA) {
   OS << " nullptr";
+  dumpTemplateArgument(TA);
 }
 
 void TextNodeDumper::VisitIntegralTemplateArgument(const TemplateArgument &TA) 
{
-  OS << " integral " << TA.getAsIntegral();
+  OS << " integral";
+  dumpTemplateArgument(TA);
+}
+
+void TextNodeDumper::dumpTemplateName(TemplateName TN) {
+  switch (TN.getKind()) {
+  case TemplateName::Template:
+AddChild([=] { Visit(TN.getAsTemplateDecl()); });
+return;
+  case TemplateName::UsingTemplate: {
+const UsingShadowDecl *USD = TN.getAsUsingShadowDecl();
+AddChild([=] { Visit(USD); });
+AddChild("target", [=] { Visit(USD->getTargetDecl()); });
+return;
+  }
+  case TemplateName::QualifiedTemplate: {
+OS << " qualified";
+const QualifiedTemplateName *QTN = TN.getAsQualifiedTemplateName();
+if (QTN->hasTemplateKeyword())
+  OS << " keyword";
+dumpNestedNameSpecifier(QTN->getQualifier());
+dumpTemplateName(QTN->getUnderlyingTemplate());
+return;
+  }
+  case TemplateName::DependentTemplate: {
+OS << " dependent";
+const DependentTemplateName *DTN = TN.getAsDependentTemplateName();
+dumpNestedNameSpecifier(DTN->getQualifier());
+return;
+  }
+  case TemplateName::SubstTemplateTemplateParm: {
+const SubstTemplateTemplateParmStorage *STS =
+TN.getAsSubstTemplateTemplateParm();
+OS << " subst index " << STS->getIndex();
+if (std::optional PackIndex = STS->getPackIndex())
+  OS << " pack_index " << *PackIndex;

cor3ntin wrote:

```suggestion
OS << " subst index " << STS->getIndex();
if (std::optional PackIndex = STS->getPackIndex())
  OS << " pack index " << *PackIndex;
```

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


[clang] [clang][Sema] Don't emit 'declared here' note for builtin functions with no decl in source (PR #93394)

2024-05-27 Thread Mariya Podchishchaeva via cfe-commits

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


[clang] [clang][Sema] Don't emit 'declared here' note for builtin functions with no decl in source (PR #93394)

2024-05-27 Thread Mariya Podchishchaeva via cfe-commits


@@ -5897,6 +5897,16 @@ void Sema::diagnoseTypo(const TypoCorrection &Correction,
 
   NamedDecl *ChosenDecl =
   Correction.isKeyword() ? nullptr : Correction.getFoundDecl();
+
+  // For builtin functions which aren't declared anywhere in source,
+  // don't emit the "declared here" note.
+  if (const auto *FD = dyn_cast_if_present(ChosenDecl);
+  FD && FD->getBuiltinID() &&
+  PrevNote.getDiagID() == diag::note_previous_decl &&
+  Correction.getCorrectionRange().getBegin() == FD->getBeginLoc()) {

Fznamznon wrote:

I wonder if checking location is necessary at all?

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


[clang] [clang][Sema] Don't emit 'declared here' note for builtin functions with no decl in source (PR #93394)

2024-05-27 Thread Mariya Podchishchaeva via cfe-commits

https://github.com/Fznamznon commented:

Could you please add a release note?

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


[clang] [clang] Improve ast-dumper text printing of TemplateArgument (PR #93431)

2024-05-27 Thread Matheus Izvekov via cfe-commits


@@ -947,6 +947,26 @@ void TextNodeDumper::dumpDeclRef(const Decl *D, StringRef 
Label) {
   });
 }
 
+void TextNodeDumper::dumpTemplateArgument(const TemplateArgument &TA) {
+  llvm::SmallString<128> Str;
+  {
+llvm::raw_svector_ostream SS(Str);
+TA.print(PrintPolicy, SS, /*IncludeType=*/true);
+  }
+  OS << " '" << Str << "'";
+
+  if (TemplateArgument CanonTA = Context->getCanonicalTemplateArgument(TA);
+  !CanonTA.structurallyEquals(TA)) {
+llvm::SmallString<128> CanonStr;
+{
+  llvm::raw_svector_ostream SS(CanonStr);
+  CanonTA.print(PrintPolicy, SS, /*IncludeType=*/true);
+}
+if (CanonStr != Str)
+  OS << ":'" << CanonStr << "'";
+  }

mizvekov wrote:

This starts showing up in tests after the improvements in 
https://github.com/llvm/llvm-project/pull/93433,
which is stacked on top of this PR.

Take a look at some of the modified AST tests there.

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


[clang] [clang] Improve ast-dumper text printing of TemplateArgument (PR #93431)

2024-05-27 Thread Matheus Izvekov via cfe-commits


@@ -947,6 +947,26 @@ void TextNodeDumper::dumpDeclRef(const Decl *D, StringRef 
Label) {
   });
 }
 
+void TextNodeDumper::dumpTemplateArgument(const TemplateArgument &TA) {
+  llvm::SmallString<128> Str;
+  {
+llvm::raw_svector_ostream SS(Str);
+TA.print(PrintPolicy, SS, /*IncludeType=*/true);
+  }
+  OS << " '" << Str << "'";

mizvekov wrote:

Yeah, the quotes are what we already do for types, and I think the problem 
shows up there, though of course not as self-evident as here.

I don't think there is a formal solution besides to start escaping the string.

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


[clang] [clang] Improve ast-dumper text printing of TemplateArgument (PR #93431)

2024-05-27 Thread Matheus Izvekov via cfe-commits


@@ -1086,45 +1106,100 @@ void TextNodeDumper::VisitNullTemplateArgument(const 
TemplateArgument &) {
 
 void TextNodeDumper::VisitTypeTemplateArgument(const TemplateArgument &TA) {
   OS << " type";
-  dumpType(TA.getAsType());
+  dumpTemplateArgument(TA);
 }
 
 void TextNodeDumper::VisitDeclarationTemplateArgument(
 const TemplateArgument &TA) {
   OS << " decl";
+  dumpTemplateArgument(TA);
   dumpDeclRef(TA.getAsDecl());
 }
 
-void TextNodeDumper::VisitNullPtrTemplateArgument(const TemplateArgument &) {
+void TextNodeDumper::VisitNullPtrTemplateArgument(const TemplateArgument &TA) {
   OS << " nullptr";
+  dumpTemplateArgument(TA);
 }
 
 void TextNodeDumper::VisitIntegralTemplateArgument(const TemplateArgument &TA) 
{
-  OS << " integral " << TA.getAsIntegral();
+  OS << " integral";
+  dumpTemplateArgument(TA);
+}
+
+void TextNodeDumper::dumpTemplateName(TemplateName TN) {
+  switch (TN.getKind()) {
+  case TemplateName::Template:
+AddChild([=] { Visit(TN.getAsTemplateDecl()); });
+return;
+  case TemplateName::UsingTemplate: {
+const UsingShadowDecl *USD = TN.getAsUsingShadowDecl();
+AddChild([=] { Visit(USD); });
+AddChild("target", [=] { Visit(USD->getTargetDecl()); });
+return;
+  }
+  case TemplateName::QualifiedTemplate: {
+OS << " qualified";
+const QualifiedTemplateName *QTN = TN.getAsQualifiedTemplateName();
+if (QTN->hasTemplateKeyword())
+  OS << " keyword";
+dumpNestedNameSpecifier(QTN->getQualifier());
+dumpTemplateName(QTN->getUnderlyingTemplate());
+return;
+  }
+  case TemplateName::DependentTemplate: {
+OS << " dependent";
+const DependentTemplateName *DTN = TN.getAsDependentTemplateName();
+dumpNestedNameSpecifier(DTN->getQualifier());
+return;
+  }
+  case TemplateName::SubstTemplateTemplateParm: {
+const SubstTemplateTemplateParmStorage *STS =
+TN.getAsSubstTemplateTemplateParm();
+OS << " subst index " << STS->getIndex();
+if (std::optional PackIndex = STS->getPackIndex())
+  OS << " pack_index " << *PackIndex;

mizvekov wrote:

The spelling `pack_index` is already used for the same purpose in the Subst* 
node printers.

The flags in the AST text dumper are separated by spaces, I think this spelling 
could mislead someone to think these are two separate things.

Any other ideas? If we make a change here, we better change the other printer 
as well.

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


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

2024-05-27 Thread via cfe-commits

no92 wrote:

Ping

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


[clang] [clang][Sema] Fix crash when diagnosing candidates with parameter packs (PR #93079)

2024-05-27 Thread kadir çetinkaya via cfe-commits

https://github.com/kadircet updated 
https://github.com/llvm/llvm-project/pull/93079

From d133b1bf63ab8c5408497ef4c2d2d629ebcff8eb Mon Sep 17 00:00:00 2001
From: Kadir Cetinkaya 
Date: Wed, 22 May 2024 19:37:18 +0200
Subject: [PATCH] [clang][Sema] Fix crash when diagnosing candidates with
 parameter packs

Prevent OOB access by not printing target parameter range when there's a
pack in the function parameters.

Fixes https://github.com/llvm/llvm-project/issues/93076.
Fixes https://github.com/llvm/llvm-project/issues/76354.
Fixes https://github.com/llvm/llvm-project/issues/70191.
---
 clang/docs/ReleaseNotes.rst  |  3 ++-
 clang/lib/Sema/SemaOverload.cpp  | 11 +--
 clang/test/SemaCXX/overload-template.cpp | 10 ++
 3 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 825e91876ffce..81b8d42aaa84e 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -734,7 +734,6 @@ Bug Fixes to C++ Support
   from being explicitly specialized for a given implicit instantiation of the 
class template.
 - Fixed a crash when ``this`` is used in a dependent class scope function 
template specialization
   that instantiates to a static member function.
-
 - Fix crash when inheriting from a cv-qualified type. Fixes #GH35603
 - Fix a crash when the using enum declaration uses an anonymous enumeration. 
Fixes (#GH86790).
 - Handled an edge case in ``getFullyPackExpandedSize`` so that we now avoid a 
false-positive diagnostic. (#GH84220)
@@ -796,6 +795,8 @@ Bug Fixes to C++ Support
   Fixes (#GH91308).
 - Fix a crash caused by a regression in the handling of ``source_location``
   in dependent contexts. Fixes (#GH92680).
+- Fixed a crash when diagnosing failed conversions involving template parameter
+  packs. (#GH93076)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 0c89fca8d38eb..86e869c7c72ff 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -13,6 +13,7 @@
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/ASTLambda.h"
 #include "clang/AST/CXXInheritance.h"
+#include "clang/AST/Decl.h"
 #include "clang/AST/DeclCXX.h"
 #include "clang/AST/DeclObjC.h"
 #include "clang/AST/DependenceFlags.h"
@@ -11301,8 +11302,14 @@ static void DiagnoseBadConversion(Sema &S, 
OverloadCandidate *Cand,
   Expr *FromExpr = Conv.Bad.FromExpr;
   QualType FromTy = Conv.Bad.getFromType();
   QualType ToTy = Conv.Bad.getToType();
-  SourceRange ToParamRange =
-  !isObjectArgument ? Fn->getParamDecl(I)->getSourceRange() : 
SourceRange();
+  SourceRange ToParamRange;
+
+  // FIXME: In presence of parameter packs we can't determine parameter range
+  // reliably, as we don't have access to instantiation.
+  bool HasParamPack = llvm::any_of(Fn->parameters().take_front(I),
+   [](const ParmVarDecl *Parm) { return Parm->isParameterPack(); 
});
+  if (!isObjectArgument && !HasParamPack)
+ToParamRange = Fn->getParamDecl(I)->getSourceRange();
 
   if (FromTy == S.Context.OverloadTy) {
 assert(FromExpr && "overload set argument came from implicit argument?");
diff --git a/clang/test/SemaCXX/overload-template.cpp 
b/clang/test/SemaCXX/overload-template.cpp
index 0fe13c479cce2..3277a17e5e450 100644
--- a/clang/test/SemaCXX/overload-template.cpp
+++ b/clang/test/SemaCXX/overload-template.cpp
@@ -58,3 +58,13 @@ namespace overloadCheck{
   }
 }
 #endif
+
+namespace GH93076 {
+template  int b(a..., int); // expected-note-re 3 {{candidate 
function template not viable: no known conversion from 'int ()' to 'int' for 
{{.*}} argument}}
+int d() {
+  (void)b(0, 0, d); // expected-error {{no matching function for 
call to 'b'}}
+  (void)b(0, d, 0); // expected-error {{no matching function for 
call to 'b'}}
+  (void)b(d, 0, 0); // expected-error {{no matching function for 
call to 'b'}}
+  return 0;
+ }
+}

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


[clang] [llvm] [BPF] Fix linking issues in static map initializers (PR #91310)

2024-05-27 Thread Nick Zavaritsky via cfe-commits

mejedi wrote:

Ping.

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


[clang] [compiler-rt] [XRay] Add support for instrumentation of DSOs on x86_64 (PR #90959)

2024-05-27 Thread Sebastian Kreutzer via cfe-commits

sebastiankreutzer wrote:

> @sebastiankreutzer hey, were you able to reach the maintainers of llvm-xray 
> and probe them about its dev status? If yes, can you pls share how to reach 
> them and what did they say?

Unfortunately no, I have no direct contact. It was my impression that none of 
the maintainers are active anymore.

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


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

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


@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -std=c++23 %s -ast-dump | FileCheck --check-prefixes=CXX23 
%s
+
+namespace cwg2771 { // cwg2771: 18
+
+struct A{
+int a;
+void cwg2771(){
+  int* r = &a;

Endilll wrote:

You can use `#pragma clang __debug dump &a` to match less AST in FileCheck.

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


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

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


@@ -240,3 +240,29 @@ void test() {
 }
 }
 #endif
+
+
+#if __cplusplus >= 202302L
+namespace cwg2692 { // cwg2692: 19
+
+ struct A {
+static void f(A); // #cwg2692-1
+void f(this A); // #cwg2692-2
+
+void g();
+  };
+
+  void A::g() {
+(&A::f)(A()); // expected-error {{call to 'f' is ambiguous}}

Endilll wrote:

Follow `// expected-error@-1` style, like the rest of DR tests.

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


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

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


@@ -240,3 +240,29 @@ void test() {
 }
 }
 #endif
+
+
+#if __cplusplus >= 202302L

Endilll wrote:

Move `#if` inside `namespace`.

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


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

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


@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -std=c++23 %s -ast-dump | FileCheck --check-prefixes=CXX23 
%s
+
+namespace cwg2771 { // cwg2771: 18
+
+struct A{
+int a;
+void cwg2771(){
+  int* r = &a;
+}
+};
+// CXX23: CXXMethodDecl{{.+}}cwg2771
+// CXX23-NEXT: CompoundStmt
+// CXX23-NEXT: DeclStmt
+// CXX23-NEXT: VarDecl
+// CXX23-NEXT: UnaryOperator
+// CXX23-NEXT: MemberExpr
+// CXX23-NEXT: CXXThisExpr{{.+}}'cwg2771::A *'
+}

Endilll wrote:

```suggestion
} // namespace cwg2771
```

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


[clang] [clang] Improve ast-dumper text printing of TemplateArgument (PR #93431)

2024-05-27 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov updated 
https://github.com/llvm/llvm-project/pull/93431

>From 86e3852d0501bd24738c094359799c72781ad808 Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Fri, 24 May 2024 12:22:55 -0300
Subject: [PATCH] [clang] Improve ast-dumper text printing of TemplateArgument

This improves and unifies our approach to printing all template
arguments.

The same approach to printing types is extended to all
TemplateArguments: A sugared version is printed in quotes,
followed by printing the canonical form, unless they would print
the same.

Special improvements are done to add more detail to template template
arguments.

It's planned in a future patch to use this improved TemplateName
printer for other places besides TemplateArguments.

Note: The sugared/desugared printing does not show up for
TemplateNames in tests yet, because we do a poor job of preserving
their type sugar. This will be improved in a future patch.
---
 clang/docs/ReleaseNotes.rst   |   2 +
 clang/include/clang/AST/TextNodeDumper.h  |   2 +
 clang/lib/AST/TextNodeDumper.cpp  | 103 +++---
 clang/test/AST/ast-dump-decl.cpp  |  25 +++--
 ...penmp-begin-declare-variant_template_2.cpp |   6 +-
 clang/test/AST/ast-dump-template-name.cpp |  54 +
 clang/test/AST/ast-dump-using-template.cpp|   8 +-
 .../constraints-explicit-instantiation.cpp|   6 +-
 clang/test/OpenMP/align_clause_ast_print.cpp  |   2 +-
 clang/test/OpenMP/generic_loop_ast_print.cpp  |   2 +-
 clang/test/OpenMP/interop_ast_print.cpp   |   2 +-
 clang/test/SemaOpenACC/sub-array-ast.cpp  |   2 +-
 .../aggregate-deduction-candidate.cpp |  18 +--
 clang/test/SemaTemplate/attributes.cpp|  64 +--
 clang/test/SemaTemplate/deduction-guide.cpp   |  19 ++--
 clang/test/SemaTemplate/make_integer_seq.cpp  |  68 +++-
 clang/test/SemaTemplate/type_pack_element.cpp |  20 ++--
 17 files changed, 275 insertions(+), 128 deletions(-)
 create mode 100644 clang/test/AST/ast-dump-template-name.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 825e91876ffce..f7562ce74f4ed 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -98,6 +98,8 @@ ABI Changes in This Version
 AST Dumping Potentially Breaking Changes
 
 
+- The text ast-dumper has improved printing of TemplateArguments.
+
 Clang Frontend Potentially Breaking Changes
 ---
 - Removed support for constructing on-stack ``TemplateArgumentList``\ s; 
interfaces should instead
diff --git a/clang/include/clang/AST/TextNodeDumper.h 
b/clang/include/clang/AST/TextNodeDumper.h
index 1fede6e462e92..63fa16c9ec47c 100644
--- a/clang/include/clang/AST/TextNodeDumper.h
+++ b/clang/include/clang/AST/TextNodeDumper.h
@@ -213,6 +213,8 @@ class TextNodeDumper
   void dumpTemplateSpecializationKind(TemplateSpecializationKind TSK);
   void dumpNestedNameSpecifier(const NestedNameSpecifier *NNS);
   void dumpConceptReference(const ConceptReference *R);
+  void dumpTemplateArgument(const TemplateArgument &TA);
+  void dumpTemplateName(TemplateName TN);
 
   void dumpDeclRef(const Decl *D, StringRef Label = {});
 
diff --git a/clang/lib/AST/TextNodeDumper.cpp b/clang/lib/AST/TextNodeDumper.cpp
index 4a1e94ffe283b..ed343ffb74124 100644
--- a/clang/lib/AST/TextNodeDumper.cpp
+++ b/clang/lib/AST/TextNodeDumper.cpp
@@ -947,6 +947,26 @@ void TextNodeDumper::dumpDeclRef(const Decl *D, StringRef 
Label) {
   });
 }
 
+void TextNodeDumper::dumpTemplateArgument(const TemplateArgument &TA) {
+  llvm::SmallString<128> Str;
+  {
+llvm::raw_svector_ostream SS(Str);
+TA.print(PrintPolicy, SS, /*IncludeType=*/true);
+  }
+  OS << " '" << Str << "'";
+
+  if (TemplateArgument CanonTA = Context->getCanonicalTemplateArgument(TA);
+  !CanonTA.structurallyEquals(TA)) {
+llvm::SmallString<128> CanonStr;
+{
+  llvm::raw_svector_ostream SS(CanonStr);
+  CanonTA.print(PrintPolicy, SS, /*IncludeType=*/true);
+}
+if (CanonStr != Str)
+  OS << ":'" << CanonStr << "'";
+  }
+}
+
 const char *TextNodeDumper::getCommandName(unsigned CommandID) {
   if (Traits)
 return Traits->getCommandInfo(CommandID)->Name;
@@ -1086,45 +1106,100 @@ void TextNodeDumper::VisitNullTemplateArgument(const 
TemplateArgument &) {
 
 void TextNodeDumper::VisitTypeTemplateArgument(const TemplateArgument &TA) {
   OS << " type";
-  dumpType(TA.getAsType());
+  dumpTemplateArgument(TA);
 }
 
 void TextNodeDumper::VisitDeclarationTemplateArgument(
 const TemplateArgument &TA) {
   OS << " decl";
+  dumpTemplateArgument(TA);
   dumpDeclRef(TA.getAsDecl());
 }
 
-void TextNodeDumper::VisitNullPtrTemplateArgument(const TemplateArgument &) {
+void TextNodeDumper::VisitNullPtrTemplateArgument(const TemplateArgument &TA) {
   OS << " nullptr";
+  dumpTemplateArgument(TA);
 }
 
 void TextNodeDumper::VisitIntegralTemplate

[clang] [Sema] Fix an out-of-bounds crash when diagnosing bad conversion for a function with a parameter pack. (PR #92721)

2024-05-27 Thread Haojian Wu via cfe-commits

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


[clang] [Sema] Fix an out-of-bounds crash when diagnosing bad conversion for a function with a parameter pack. (PR #92721)

2024-05-27 Thread Haojian Wu via cfe-commits

https://github.com/hokein updated 
https://github.com/llvm/llvm-project/pull/92721

>From e2dc2cecee5891b88ff4c2e473220cc9fd36df34 Mon Sep 17 00:00:00 2001
From: Haojian Wu 
Date: Sun, 19 May 2024 22:47:14 +0200
Subject: [PATCH 1/2] [Sema] Fix an out-of-bounds crash when diagnosing bad
 conversion for a function with a parameter pack.

---
 clang/docs/ReleaseNotes.rst   |  2 ++
 clang/lib/Sema/SemaOverload.cpp   | 10 --
 clang/test/Misc/diag-overload-cand-ranges.cpp |  8 
 3 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 825e91876ffce..9fd8661949113 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -629,6 +629,8 @@ Bug Fixes in This Version
 - ``__is_array`` and ``__is_bounded_array`` no longer return ``true`` for
   zero-sized arrays. Fixes (#GH54705).
 
+- Fix an out-of-bounds crash when diagnosing bad conversion for a function 
with a parameter pack. 
+
 Bug Fixes to Compiler Builtins
 ^^
 
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 0c89fca8d38eb..a9603e63336ac 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -11301,8 +11301,14 @@ static void DiagnoseBadConversion(Sema &S, 
OverloadCandidate *Cand,
   Expr *FromExpr = Conv.Bad.FromExpr;
   QualType FromTy = Conv.Bad.getFromType();
   QualType ToTy = Conv.Bad.getToType();
-  SourceRange ToParamRange =
-  !isObjectArgument ? Fn->getParamDecl(I)->getSourceRange() : 
SourceRange();
+  SourceRange ToParamRange;
+  if (!isObjectArgument) {
+if (I < Fn->getNumParams())
+  ToParamRange = Fn->getParamDecl(I)->getSourceRange();
+else
+  // parameter pack case.
+  ToParamRange = Fn->parameters().back()->getSourceRange();
+  }
 
   if (FromTy == S.Context.OverloadTy) {
 assert(FromExpr && "overload set argument came from implicit argument?");
diff --git a/clang/test/Misc/diag-overload-cand-ranges.cpp 
b/clang/test/Misc/diag-overload-cand-ranges.cpp
index 080ca484d4b74..06d638d9b719c 100644
--- a/clang/test/Misc/diag-overload-cand-ranges.cpp
+++ b/clang/test/Misc/diag-overload-cand-ranges.cpp
@@ -70,3 +70,11 @@ template  class Type1 {};
 template  void Function1(int zz, Type1 &x, int ww) {}
 
 void Function() { Function1(33, Type1<-42>(), 66); }
+
+// CHECK:  error: no matching function for call to 'b'
+// CHECK:  :{[[@LINE+1]]:41-[[@LINE+1]]:45}: note: {{.*}} no known 
conversion from 'int' to 'ForwardClass' for 3rd argument
+template  void b(T, U...);
+class ForwardClass;
+void NoCrash() {
+  b(1, 1, 0);
+}

>From 4358b43e283cb13dbe4d32fcce3c68b6da15b12a Mon Sep 17 00:00:00 2001
From: Haojian Wu 
Date: Mon, 27 May 2024 09:58:04 +0200
Subject: [PATCH 2/2] review comments

Diagnose on the first parameter pack.
---
 clang/lib/Sema/SemaOverload.cpp   | 12 +---
 clang/test/Misc/diag-overload-cand-ranges.cpp |  6 +-
 2 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index a9603e63336ac..f9a5032e10c2d 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -11305,9 +11305,15 @@ static void DiagnoseBadConversion(Sema &S, 
OverloadCandidate *Cand,
   if (!isObjectArgument) {
 if (I < Fn->getNumParams())
   ToParamRange = Fn->getParamDecl(I)->getSourceRange();
-else
-  // parameter pack case.
-  ToParamRange = Fn->parameters().back()->getSourceRange();
+else {
+  // For the parameter pack case, diagnose on the first pack.
+  for (const auto* ParamDecl : Fn->parameters()) {
+if (ParamDecl->isParameterPack()) {
+  ToParamRange = ParamDecl->getSourceRange();
+  break;
+}
+  }
+}
   }
 
   if (FromTy == S.Context.OverloadTy) {
diff --git a/clang/test/Misc/diag-overload-cand-ranges.cpp 
b/clang/test/Misc/diag-overload-cand-ranges.cpp
index 06d638d9b719c..a70ba0d1b1f77 100644
--- a/clang/test/Misc/diag-overload-cand-ranges.cpp
+++ b/clang/test/Misc/diag-overload-cand-ranges.cpp
@@ -1,4 +1,4 @@
-// RUN: not %clang_cc1 -fsyntax-only -fdiagnostics-print-source-range-info %s 
2>&1 | FileCheck %s --strict-whitespace
+// RUN: not %clang_cc1 -fsyntax-only -fdiagnostics-print-source-range-info 
-std=c++20 %s 2>&1 | FileCheck %s --strict-whitespace
 // CHECK:  error: no matching function
 template  struct mcdata {
   typedef int result_type;
@@ -74,7 +74,11 @@ void Function() { Function1(33, Type1<-42>(), 66); }
 // CHECK:  error: no matching function for call to 'b'
 // CHECK:  :{[[@LINE+1]]:41-[[@LINE+1]]:45}: note: {{.*}} no known 
conversion from 'int' to 'ForwardClass' for 3rd argument
 template  void b(T, U...);
+// CHECK:  error: no matching function for call to 'abbreviated_func'
+// CHECK:  :{[[@LINE+1]]:23-[[@LINE+1]]:30}: note: {{.*}} no known 
conversion from 'int' 

[clang] [Sema] Fix an out-of-bounds crash when diagnosing bad conversion for a function with a parameter pack. (PR #92721)

2024-05-27 Thread Haojian Wu via cfe-commits


@@ -11298,8 +11298,14 @@ static void DiagnoseBadConversion(Sema &S, 
OverloadCandidate *Cand,
   Expr *FromExpr = Conv.Bad.FromExpr;
   QualType FromTy = Conv.Bad.getFromType();
   QualType ToTy = Conv.Bad.getToType();
-  SourceRange ToParamRange =
-  !isObjectArgument ? Fn->getParamDecl(I)->getSourceRange() : 
SourceRange();
+  SourceRange ToParamRange;
+  if (!isObjectArgument) {
+if (I < Fn->getNumParams())
+  ToParamRange = Fn->getParamDecl(I)->getSourceRange();
+else
+  // parameter pack case.

hokein wrote:

Done. 

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


[clang] [Sema] Fix an out-of-bounds crash when diagnosing bad conversion for a function with a parameter pack. (PR #92721)

2024-05-27 Thread Haojian Wu via cfe-commits


@@ -11298,8 +11298,14 @@ static void DiagnoseBadConversion(Sema &S, 
OverloadCandidate *Cand,
   Expr *FromExpr = Conv.Bad.FromExpr;
   QualType FromTy = Conv.Bad.getFromType();
   QualType ToTy = Conv.Bad.getToType();
-  SourceRange ToParamRange =
-  !isObjectArgument ? Fn->getParamDecl(I)->getSourceRange() : 
SourceRange();
+  SourceRange ToParamRange;
+  if (!isObjectArgument) {
+if (I < Fn->getNumParams())
+  ToParamRange = Fn->getParamDecl(I)->getSourceRange();
+else
+  // parameter pack case.
+  ToParamRange = Fn->parameters().back()->getSourceRange();

hokein wrote:

thanks for the test cases. (I wonder if there is a case where we should point 
at the second pack, but I don't come up with one, I think using the first pack 
is probably good enough. Alternatively, we could use the full 
`getParametersSourceRange` range without finding a particular pack, but it 
provides less precise location information).

> Should we put that in a function in FunctionDecl?

Probably not worth, it seems heavy to add a method in FunctionDecl to only fix 
this regression.

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


[clang] [Sema] Fix an out-of-bounds crash when diagnosing bad conversion for a function with a parameter pack. (PR #92721)

2024-05-27 Thread via cfe-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff 7429950d840b8fec3d9a48d00e612a3240c2be83 
4358b43e283cb13dbe4d32fcce3c68b6da15b12a -- clang/lib/Sema/SemaOverload.cpp 
clang/test/Misc/diag-overload-cand-ranges.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index f9a5032e10..21644dd56b 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -11307,7 +11307,7 @@ static void DiagnoseBadConversion(Sema &S, 
OverloadCandidate *Cand,
   ToParamRange = Fn->getParamDecl(I)->getSourceRange();
 else {
   // For the parameter pack case, diagnose on the first pack.
-  for (const auto* ParamDecl : Fn->parameters()) {
+  for (const auto *ParamDecl : Fn->parameters()) {
 if (ParamDecl->isParameterPack()) {
   ToParamRange = ParamDecl->getSourceRange();
   break;

``




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


  1   2   3   >