[clang] [Clang][Sema] Add a test for move ctor calling for a base class. NFC (PR #97164)

2024-07-19 Thread Pavel Samolysov via cfe-commits

samolisov wrote:

Gentle ping.

I've addressed all the comments (thank you, @vitalybuka).

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


[clang] [clang] Implement P2582R1: CTAD from inherited constructors (PR #98788)

2024-07-19 Thread via cfe-commits

https://github.com/antangelo updated 
https://github.com/llvm/llvm-project/pull/98788

>From 3f0dfdfdbad3921da42be23fb0bbf1f1f00a42fb Mon Sep 17 00:00:00 2001
From: antangelo 
Date: Sat, 1 Jun 2024 13:15:40 -0400
Subject: [PATCH 1/4] [clang] Implement P2582R1: CTAD from inherited
 constructors

---
 clang/docs/ReleaseNotes.rst   |   2 +
 clang/include/clang/AST/DeclCXX.h |  36 +-
 .../clang/Basic/DiagnosticSemaKinds.td|   4 +
 clang/lib/AST/ASTImporter.cpp |   8 +-
 clang/lib/AST/DeclCXX.cpp |  10 +-
 clang/lib/Sema/SemaOverload.cpp   |  67 +++
 clang/lib/Sema/SemaTemplate.cpp   | 389 --
 .../lib/Sema/SemaTemplateInstantiateDecl.cpp  |   3 +-
 clang/lib/Serialization/ASTReaderDecl.cpp |   2 +
 clang/lib/Serialization/ASTWriterDecl.cpp |   2 +
 .../SemaCXX/cxx23-ctad-inherited-ctors.cpp| 260 
 clang/unittests/AST/ASTImporterTest.cpp   |  43 ++
 clang/www/cxx_status.html |   2 +-
 13 files changed, 786 insertions(+), 42 deletions(-)
 create mode 100644 clang/test/SemaCXX/cxx23-ctad-inherited-ctors.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 5dc0f8b7e0bbb..b6924f61814fb 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -263,6 +263,8 @@ C++23 Feature Support
 - Implemented `P2797R0: Static and explicit object member functions with the 
same parameter-type-lists `_.
   This completes the support for "deducing this".
 
+- Implemented `P2582R1: Wording for class template argument deduction from 
inherited constructors `_.
+
 C++2c Feature Support
 ^
 
diff --git a/clang/include/clang/AST/DeclCXX.h 
b/clang/include/clang/AST/DeclCXX.h
index fb52ac804849d..c8e74f32b2ccb 100644
--- a/clang/include/clang/AST/DeclCXX.h
+++ b/clang/include/clang/AST/DeclCXX.h
@@ -1957,10 +1957,14 @@ class CXXDeductionGuideDecl : public FunctionDecl {
 ExplicitSpecifier ES,
 const DeclarationNameInfo &NameInfo, QualType T,
 TypeSourceInfo *TInfo, SourceLocation EndLocation,
-CXXConstructorDecl *Ctor, DeductionCandidate Kind)
+CXXConstructorDecl *Ctor, DeductionCandidate Kind,
+CXXDeductionGuideDecl *GeneratedFrom,
+bool IsGeneratedFromInheritedConstructor)
   : FunctionDecl(CXXDeductionGuide, C, DC, StartLoc, NameInfo, T, TInfo,
  SC_None, false, false, ConstexprSpecKind::Unspecified),
-Ctor(Ctor), ExplicitSpec(ES) {
+Ctor(Ctor), ExplicitSpec(ES),
+SourceDeductionGuide(GeneratedFrom,
+ IsGeneratedFromInheritedConstructor) {
 if (EndLocation.isValid())
   setRangeEnd(EndLocation);
 setDeductionCandidateKind(Kind);
@@ -1968,6 +1972,11 @@ class CXXDeductionGuideDecl : public FunctionDecl {
 
   CXXConstructorDecl *Ctor;
   ExplicitSpecifier ExplicitSpec;
+  // The deduction guide, if any, that this deduction guide was generated from,
+  // in the case of alias template deduction or CTAD from inherited
+  // constructors. The bool member indicates whether this deduction guide is
+  // generated from an inherited constructor.
+  llvm::PointerIntPair SourceDeductionGuide;
   void setExplicitSpecifier(ExplicitSpecifier ES) { ExplicitSpec = ES; }
 
 public:
@@ -1979,7 +1988,9 @@ class CXXDeductionGuideDecl : public FunctionDecl {
  ExplicitSpecifier ES, const DeclarationNameInfo &NameInfo, QualType T,
  TypeSourceInfo *TInfo, SourceLocation EndLocation,
  CXXConstructorDecl *Ctor = nullptr,
- DeductionCandidate Kind = DeductionCandidate::Normal);
+ DeductionCandidate Kind = DeductionCandidate::Normal,
+ CXXDeductionGuideDecl *SourceDG = nullptr,
+ bool IsGeneratedFromInheritedConstructor = false);
 
   static CXXDeductionGuideDecl *CreateDeserialized(ASTContext &C,
GlobalDeclID ID);
@@ -1999,6 +2010,25 @@ class CXXDeductionGuideDecl : public FunctionDecl {
   /// this is an implicit deduction guide.
   CXXConstructorDecl *getCorrespondingConstructor() const { return Ctor; }
 
+  /// Get the deduction guide from which this deduction guide was generated,
+  /// if it was generated as part of alias template deduction or from an
+  /// inherited constructor.
+  CXXDeductionGuideDecl *getSourceDeductionGuide() const {
+return SourceDeductionGuide.getPointer();
+  }
+
+  void setSourceDeductionGuide(CXXDeductionGuideDecl *DG) {
+SourceDeductionGuide.setPointer(DG);
+  }
+
+  bool isGeneratedFromInheritedConstructor() const {
+return SourceDeductionGuide.getInt();
+  }
+
+  void setGeneratedFromInheritedConstructor(bool G = true) {
+SourceDeductionGuide.setInt(G);
+  }
+
   void setD

[clang] [clang] Implement P2582R1: CTAD from inherited constructors (PR #98788)

2024-07-19 Thread via cfe-commits


@@ -2157,17 +2157,19 @@ CXXDeductionGuideDecl *CXXDeductionGuideDecl::Create(
 ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
 ExplicitSpecifier ES, const DeclarationNameInfo &NameInfo, QualType T,
 TypeSourceInfo *TInfo, SourceLocation EndLocation, CXXConstructorDecl 
*Ctor,
-DeductionCandidate Kind) {
-  return new (C, DC) CXXDeductionGuideDecl(C, DC, StartLoc, ES, NameInfo, T,
-   TInfo, EndLocation, Ctor, Kind);
+DeductionCandidate Kind, CXXDeductionGuideDecl *SourceDG,
+bool IsGeneratedFromInheritedConstructor) {
+  return new (C, DC) CXXDeductionGuideDecl(
+  C, DC, StartLoc, ES, NameInfo, T, TInfo, EndLocation, Ctor, Kind,
+  SourceDG, IsGeneratedFromInheritedConstructor);
 }
 
 CXXDeductionGuideDecl *
 CXXDeductionGuideDecl::CreateDeserialized(ASTContext &C, GlobalDeclID ID) {
   return new (C, ID) CXXDeductionGuideDecl(
   C, nullptr, SourceLocation(), ExplicitSpecifier(), DeclarationNameInfo(),
   QualType(), nullptr, SourceLocation(), nullptr,
-  DeductionCandidate::Normal);
+  DeductionCandidate::Normal, nullptr, false);

antangelo wrote:

Thanks, I've updated those arguments as you suggested. Do you want me to also 
update the others, or just those two new ones?

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


[clang] [clang] Implement P2582R1: CTAD from inherited constructors (PR #98788)

2024-07-19 Thread via cfe-commits


@@ -980,19 +986,69 @@ getRHSTemplateDeclAndArgs(Sema &SemaRef, 
TypeAliasTemplateDecl *AliasTemplate) {
   return {Template, AliasRhsTemplateArgs};
 }
 
+// Build the type for a deduction guide generated from an inherited constructor
+// [over.match.class.deduct]p1.10:
+// ... the set contains the guides of A with the return type R
+// of each guide replaced with `typename CC::type` ...
+std::pair
+buildInheritedConstructorDeductionGuideType(
+Sema &SemaRef, TypeSourceInfo *DerivedClassMapperType,
+TemplateDecl *DeducingTemplate, TypeSourceInfo *SourceGuideTSI) {
+  auto &Context = SemaRef.Context;
+  const auto *FPT = SourceGuideTSI->getType()->getAs();
+  assert(FPT && "Source Guide type should be a FunctionProtoType");
+
+  // This substitution can fail in cases where the source return type
+  // is not dependent and the derived class is not deducible
+  Sema::SFINAETrap Trap(SemaRef);
+
+  MultiLevelTemplateArgumentList Args;
+  Args.addOuterTemplateArguments(DeducingTemplate,
+ TemplateArgument(FPT->getReturnType()), 
false);
+  Args.addOuterRetainedLevels(DeducingTemplate->getTemplateDepth());
+  TypeSourceInfo *ReturnTypeTSI =
+  SemaRef.SubstType(DerivedClassMapperType, Args,
+DeducingTemplate->getBeginLoc(), DeclarationName());
+  if (!ReturnTypeTSI || Trap.hasErrorOccurred())
+return {nullptr, QualType()};
+  const QualType &ReturnType = ReturnTypeTSI->getType();

antangelo wrote:

Thanks, replaced this with a copy.

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


[clang] [clang] Implement P2582R1: CTAD from inherited constructors (PR #98788)

2024-07-19 Thread via cfe-commits


@@ -1254,8 +1341,221 @@ void DeclareImplicitDeductionGuidesForTypeAlias(
 ->getDeductionCandidateKind() == DeductionCandidate::Aggregate)
   continue;
 
-BuildDeductionGuideForTypeAlias(SemaRef, AliasTemplate, F, Loc);
+BuildDeductionGuideForTypeAlias(SemaRef, AliasTemplate, F, Loc,
+DeducingTemplate, DerivedClassMapperType);
+  }
+}
+
+void DeclareImplicitDeductionGuidesFromInheritedConstructors(
+Sema &SemaRef, TemplateDecl *Template, ClassTemplateDecl *Pattern,
+const CXXBaseSpecifier &Base, unsigned BaseIdx) {
+  auto &Context = SemaRef.Context;
+  DeclContext *DC = Template->getDeclContext();
+  const auto *BaseTST = Base.getType()->getAs();
+  if (!BaseTST)
+return;
+
+  TemplateDecl *BaseTD = BaseTST->getTemplateName().getAsTemplateDecl();
+  if (!BaseTD)
+return;
+
+  // Subsitute any parameters with default arguments not present in the base,
+  // since partial specializations cannot have default parameters
+  TemplateParameterList *TemplateTPL = Pattern->getTemplateParameters();
+  auto BaseDeducedTemplateParams =
+  TemplateParamsReferencedInTemplateArgumentList(
+  TemplateTPL, BaseTST->template_arguments());
+  SmallVector PartialSpecParams;
+  SmallVector SubstArgs;
+  PartialSpecParams.reserve(TemplateTPL->size());
+  SubstArgs.reserve(TemplateTPL->size());
+  LocalInstantiationScope Scope(SemaRef);
+  for (unsigned I = 0, N = TemplateTPL->size(); I < N; ++I) {
+NamedDecl *Param = TemplateTPL->getParam(I);
+if (!BaseDeducedTemplateParams.contains(I)) {
+  if (auto *TTP = dyn_cast(Param);
+  TTP && TTP->hasDefaultArgument()) {
+SubstArgs.push_back(TTP->getDefaultArgument().getArgument());
+continue;
+  }
+
+  if (auto *NTTP = dyn_cast(Param);
+  NTTP && NTTP->hasDefaultArgument()) {
+SubstArgs.push_back(NTTP->getDefaultArgument().getArgument());
+continue;
+  }
+
+  if (auto *TTP = dyn_cast(Param);
+  TTP && TTP->hasDefaultArgument()) {
+SubstArgs.push_back(TTP->getDefaultArgument().getArgument());
+continue;
+  }
+
+  // We have a template parameter that is not present in the base
+  // and does not have a default argument. We create the deduction
+  // guide anyway to display a diagnostic.
+}
+
+MultiLevelTemplateArgumentList Args;
+Args.setKind(TemplateSubstitutionKind::Rewrite);
+Args.addOuterTemplateArguments(SubstArgs);
+Args.addOuterRetainedLevels(Template->getTemplateDepth());
+
+NamedDecl *NewParam = transformTemplateParameter(
+SemaRef, DC, Param, Args, PartialSpecParams.size(),
+Template->getTemplateDepth());
+if (!NewParam)
+  return;
+
+PartialSpecParams.push_back(NewParam);
+SubstArgs.push_back(Context.getInjectedTemplateArg(NewParam));
   }
+
+  Expr *RequiresClause = nullptr;
+  MultiLevelTemplateArgumentList Args;
+  Args.setKind(TemplateSubstitutionKind::Rewrite);
+  Args.addOuterTemplateArguments(SubstArgs);
+  Args.addOuterRetainedLevels(Template->getTemplateDepth());
+  if (Expr *TemplateRC = TemplateTPL->getRequiresClause()) {
+ExprResult E = SemaRef.SubstExpr(TemplateRC, Args);
+if (E.isInvalid())
+  return;
+RequiresClause = E.getAs();
+  }
+  auto *PartialSpecTPL = TemplateParameterList::Create(
+  Context, TemplateTPL->getTemplateLoc(), TemplateTPL->getLAngleLoc(),
+  PartialSpecParams, TemplateTPL->getRAngleLoc(), RequiresClause);
+
+  // [over.match.class.deduct]p1.10
+  // Let A be an alias template whose template parameter list is that of
+  // [Template] and whose defining-type-id is [Base] ...
+  auto *TransformedBase =
+  SemaRef.SubstType(Base.getTypeSourceInfo(), Args, Base.getBaseTypeLoc(),
+DeclarationName(), true);
+  auto *BaseAD = TypeAliasDecl::Create(
+  Context, DC, SourceLocation(), Base.getBaseTypeLoc(),
+  TransformedBase->getType().getBaseTypeIdentifier(), TransformedBase);
+  std::string AliasDeclName =
+  (Twine("__ctad_alias_") + BaseTD->getName() + "_to_" +
+   Template->getName() + "_" + Twine(BaseIdx))
+  .str();
+  IdentifierInfo *AliasIdentifier = &Context.Idents.get(AliasDeclName);
+  auto *BaseATD = TypeAliasTemplateDecl::Create(
+  Context, DC, Base.getBaseTypeLoc(), DeclarationName(AliasIdentifier),
+  PartialSpecTPL, BaseAD);
+  BaseAD->setDescribedAliasTemplate(BaseATD);
+  BaseAD->setImplicit();
+  BaseATD->setImplicit();
+
+  DC->addDecl(BaseATD);
+
+  // ... given a class template `template  class CC;`
+  // whose primary template is not defined ...
+  auto *TParam = TemplateTypeParmDecl::Create(
+  Context, DC, SourceLocation(), SourceLocation(),
+  Template->getTemplateDepth(), 0, nullptr, false, false);
+  auto *MapperTPL = TemplateParameterList::Create(
+  Context, SourceLocation(), SourceLocation(),
+  ArrayRef(TParam), SourceLocation(), nullptr);
--

[clang] c248d05 - [Clang] make SVE types known to device targets too (#99446)

2024-07-19 Thread via cfe-commits

Author: Emanuele Rocca
Date: 2024-07-19T08:25:38+01:00
New Revision: c248d05c6807baba34ff4fb254176e300922ea72

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

LOG: [Clang] make SVE types known to device targets too (#99446)

For the purpose of preprocessing and declarations in header files,
ensure clang accepts SVE types for both device and host targets.

Co-authored-by: Sander De Smalen 

Added: 


Modified: 
clang/lib/AST/ASTContext.cpp
clang/lib/Sema/Sema.cpp
clang/test/PCH/aarch64-sve-types.c

Removed: 




diff  --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index a8e599f7ebe04..98ce88eb6a9fd 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -1384,7 +1384,8 @@ void ASTContext::InitBuiltinTypes(const TargetInfo 
&Target,
 #include "clang/Basic/OpenCLExtensionTypes.def"
   }
 
-  if (Target.hasAArch64SVETypes()) {
+  if (Target.hasAArch64SVETypes() ||
+  (AuxTarget && AuxTarget->hasAArch64SVETypes())) {
 #define SVE_TYPE(Name, Id, SingletonId) \
 InitBuiltinType(SingletonId, BuiltinType::Id);
 #include "clang/Basic/AArch64SVEACLETypes.def"

diff  --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index 46417964f0896..2e989f0ba6fe4 100644
--- a/clang/lib/Sema/Sema.cpp
+++ b/clang/lib/Sema/Sema.cpp
@@ -469,7 +469,9 @@ void Sema::Initialize() {
 #include "clang/Basic/OpenCLExtensionTypes.def"
   }
 
-  if (Context.getTargetInfo().hasAArch64SVETypes()) {
+  if (Context.getTargetInfo().hasAArch64SVETypes() ||
+  (Context.getAuxTargetInfo() &&
+   Context.getAuxTargetInfo()->hasAArch64SVETypes())) {
 #define SVE_TYPE(Name, Id, SingletonId) \
 addImplicitTypedef(Name, Context.SingletonId);
 #include "clang/Basic/AArch64SVEACLETypes.def"

diff  --git a/clang/test/PCH/aarch64-sve-types.c 
b/clang/test/PCH/aarch64-sve-types.c
index 4c4549af0b6d6..249618c3a9708 100644
--- a/clang/test/PCH/aarch64-sve-types.c
+++ b/clang/test/PCH/aarch64-sve-types.c
@@ -1,6 +1,8 @@
 // RUN: %clang_cc1 -triple aarch64-linux-gnu -emit-pch -o %t %s
 // RUN: %clang_cc1 -triple aarch64-linux-gnu -include-pch %t \
 // RUN:   -fsyntax-only -verify %s
+// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -aux-triple aarch64-linux-gnu \
+// RUN:   -x hip-cpp-output -emit-pch -o %t %s
 
 // expected-no-diagnostics
 



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


[clang] [Clang] make SVE types known to device targets too (PR #99446)

2024-07-19 Thread Sander de Smalen via cfe-commits

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


[clang] [Clang] make SVE types known to device targets too (PR #99446)

2024-07-19 Thread via cfe-commits

github-actions[bot] wrote:



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

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

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

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

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

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


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


[clang] [clang] Fix static analyzer concerns in #embed code (PR #99331)

2024-07-19 Thread Mariya Podchishchaeva via cfe-commits

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


[clang] c813667 - [clang] Fix static analyzer concerns in #embed code (#99331)

2024-07-19 Thread via cfe-commits

Author: Mariya Podchishchaeva
Date: 2024-07-19T09:33:35+02:00
New Revision: c81366709574bb95bad86011a44e80a7f97f2c56

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

LOG: [clang] Fix static analyzer concerns in #embed code (#99331)

1. Dead code in `LookupEmbedFile`. The loop always exited on the first
iteration. This was also causing a bug of not checking all directories
provided by `--embed-dir`.

2. Use of uninitialized variable `CurTok` in `LexEmbedParameters`. It
was used to initialize the field which seems to be unused. Removed
unused field, this way `CurTok` should be initialized by Lex method.

Added: 
clang/test/Preprocessor/embed_search_paths.c

Modified: 
clang/include/clang/Lex/PPEmbedParameters.h
clang/lib/Lex/PPDirectives.cpp

Removed: 




diff  --git a/clang/include/clang/Lex/PPEmbedParameters.h 
b/clang/include/clang/Lex/PPEmbedParameters.h
index 51bf908524e7a..c4fb8d02f6f35 100644
--- a/clang/include/clang/Lex/PPEmbedParameters.h
+++ b/clang/include/clang/Lex/PPEmbedParameters.h
@@ -75,7 +75,6 @@ struct LexEmbedParametersResult {
   std::optional MaybeIfEmptyParam;
   std::optional MaybePrefixParam;
   std::optional MaybeSuffixParam;
-  SourceRange ParamRange;
   int UnrecognizedParams;
 
   size_t PrefixTokenCount() const {

diff  --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp
index a53540b12dee6..4e77df9ec444c 100644
--- a/clang/lib/Lex/PPDirectives.cpp
+++ b/clang/lib/Lex/PPDirectives.cpp
@@ -1137,7 +1137,9 @@ Preprocessor::LookupEmbedFile(StringRef Filename, bool 
isAngled, bool OpenFile,
 SeparateComponents(LookupPath, Entry, Filename, false);
 llvm::Expected ShouldBeEntry =
 FM.getFileRef(LookupPath, OpenFile);
-return llvm::expectedToOptional(std::move(ShouldBeEntry));
+if (ShouldBeEntry)
+  return llvm::expectedToOptional(std::move(ShouldBeEntry));
+llvm::consumeError(ShouldBeEntry.takeError());
   }
   return std::nullopt;
 }
@@ -3624,12 +3626,10 @@ Preprocessor::LexEmbedParameters(Token &CurTok, bool 
ForHasEmbed) {
   LexEmbedParametersResult Result{};
   SmallVector ParameterTokens;
   tok::TokenKind EndTokenKind = ForHasEmbed ? tok::r_paren : tok::eod;
-  Result.ParamRange = {CurTok.getLocation(), CurTok.getLocation()};
 
   auto DiagMismatchedBracesAndSkipToEOD =
   [&](tok::TokenKind Expected,
   std::pair Matches) {
-Result.ParamRange.setEnd(CurTok.getEndLoc());
 Diag(CurTok, diag::err_expected) << Expected;
 Diag(Matches.second, diag::note_matching) << Matches.first;
 if (CurTok.isNot(tok::eod))
@@ -3638,7 +3638,6 @@ Preprocessor::LexEmbedParameters(Token &CurTok, bool 
ForHasEmbed) {
 
   auto ExpectOrDiagAndSkipToEOD = [&](tok::TokenKind Kind) {
 if (CurTok.isNot(Kind)) {
-  Result.ParamRange.setEnd(CurTok.getEndLoc());
   Diag(CurTok, diag::err_expected) << Kind;
   if (CurTok.isNot(tok::eod))
 DiscardUntilEndOfDirective(CurTok);
@@ -3872,7 +3871,6 @@ Preprocessor::LexEmbedParameters(Token &CurTok, bool 
ForHasEmbed) {
   }
 }
   }
-  Result.ParamRange.setEnd(CurTok.getLocation());
   return Result;
 }
 

diff  --git a/clang/test/Preprocessor/embed_search_paths.c 
b/clang/test/Preprocessor/embed_search_paths.c
new file mode 100644
index 0..5cc1bbf9f87a9
--- /dev/null
+++ b/clang/test/Preprocessor/embed_search_paths.c
@@ -0,0 +1,4 @@
+// RUN: %clang_cc1 -std=c23 %s -E -verify --embed-dir=%S --embed-dir=%S/Inputs
+// expected-no-diagnostics
+
+#embed 



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


[clang] [clang] Limit alignment for emitted vectors (PR #98629)

2024-07-19 Thread Mariya Podchishchaeva via cfe-commits

Fznamznon wrote:

Closing since https://github.com/llvm/llvm-project/pull/99257 fixed the problem 
without side effects. Thank you very much @efriedma-quic 

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


[clang] [clang][dataflow] Handle CXXInheritedCtorInitExpr in ResultObjectVisitor. (PR #99616)

2024-07-19 Thread Pasquale Riello via cfe-commits

https://github.com/Pask00 created 
https://github.com/llvm/llvm-project/pull/99616


`CXXInheritedCtorInitExpr` is another of the node kinds that should be 
considered an "original initializer". An assertion failure in 
`assert(Children.size() == 1)` happens without this fix.

>From 0c26f09117baa36308bf58fed0ac40794b04ce74 Mon Sep 17 00:00:00 2001
From: Pasquale Riello 
Date: Fri, 19 Jul 2024 08:34:14 +
Subject: [PATCH] [clang][dataflow] Handle CXXInheritedCtorInitExpr in
 ResultObjectVisitor.

`CXXInheritedCtorInitExpr` is another of the node kinds that should be 
considered an "original initializer". An assertion failure in 
`assert(Children.size() == 1)` happens without this fix.
---
 .../FlowSensitive/DataflowEnvironment.cpp |  2 +-
 .../FlowSensitive/DataflowEnvironmentTest.cpp | 40 +++
 2 files changed, 41 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp 
b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
index f734168e647bd..3307981ce7e0f 100644
--- a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -416,7 +416,7 @@ class ResultObjectVisitor : public 
AnalysisASTVisitor {
 // below them can initialize the same object (or part of it).
 if (isa(E) || isa(E) || isa(E) ||
 isa(E) || isa(E) ||
-isa(E) ||
+isa(E) || isa(E) ||
 // We treat `BuiltinBitCastExpr` as an "original initializer" too as
 // it may not even be casting from a record type -- and even if it is,
 // the two objects are in general of unrelated type.
diff --git a/clang/unittests/Analysis/FlowSensitive/DataflowEnvironmentTest.cpp 
b/clang/unittests/Analysis/FlowSensitive/DataflowEnvironmentTest.cpp
index a4ac597bb06d6..8481026f7c1fc 100644
--- a/clang/unittests/Analysis/FlowSensitive/DataflowEnvironmentTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/DataflowEnvironmentTest.cpp
@@ -442,6 +442,46 @@ TEST_F(EnvironmentTest, 
CXXDefaultInitExprResultObjIsWrappedExprResultObj) {
 &Env.getResultObjectLocation(*DefaultInit->getExpr()));
 }
 
+TEST_F(EnvironmentTest, ResultObjectLocationForInheritedCtorInitExpr) {
+  using namespace ast_matchers;
+
+  std::string Code = R"(
+struct Base {
+  Base(int b) {}
+};
+struct Derived : Base {
+  using Base::Base;
+};
+
+Derived d = Derived(0);
+  )";
+
+  auto Unit =
+  tooling::buildASTFromCodeWithArgs(Code, {"-fsyntax-only", "-std=c++20"});
+  auto &Context = Unit->getASTContext();
+
+  ASSERT_EQ(Context.getDiagnostics().getClient()->getNumErrors(), 0U);
+
+  auto Results =
+  match(cxxConstructorDecl(
+hasAnyConstructorInitializer(cxxCtorInitializer(
+withInitializer(expr().bind("inherited_ctor_init_expr")
+.bind("ctor"),
+Context);
+  const auto *Constructor = selectFirst("ctor", Results);
+  const auto *InheritedCtorInit =
+  selectFirst("inherited_ctor_init_expr", 
Results);
+
+  // Verify that `inherited_ctor_init_expr` has no children.
+  ASSERT_EQ(InheritedCtorInit->child_begin(), InheritedCtorInit->child_end());
+
+  Environment Env(DAContext, *Constructor);
+  Env.initialize();
+
+  RecordStorageLocation &Loc = Env.getResultObjectLocation(*InheritedCtorInit);
+  ASSERT_NE(&Loc, nullptr);
+}
+
 TEST_F(EnvironmentTest, Stmt) {
   using namespace ast_matchers;
 

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


[clang] [clang][dataflow] Handle CXXInheritedCtorInitExpr in ResultObjectVisitor. (PR #99616)

2024-07-19 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/99616
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][dataflow] Handle CXXInheritedCtorInitExpr in ResultObjectVisitor. (PR #99616)

2024-07-19 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang-analysis

@llvm/pr-subscribers-clang

Author: Pasquale Riello (Pask00)


Changes


`CXXInheritedCtorInitExpr` is another of the node kinds that should be 
considered an "original initializer". An assertion failure in 
`assert(Children.size() == 1)` happens without this fix.

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


2 Files Affected:

- (modified) clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp (+1-1) 
- (modified) clang/unittests/Analysis/FlowSensitive/DataflowEnvironmentTest.cpp 
(+40) 


``diff
diff --git a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp 
b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
index f734168e647bd..3307981ce7e0f 100644
--- a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -416,7 +416,7 @@ class ResultObjectVisitor : public 
AnalysisASTVisitor {
 // below them can initialize the same object (or part of it).
 if (isa(E) || isa(E) || isa(E) ||
 isa(E) || isa(E) ||
-isa(E) ||
+isa(E) || isa(E) ||
 // We treat `BuiltinBitCastExpr` as an "original initializer" too as
 // it may not even be casting from a record type -- and even if it is,
 // the two objects are in general of unrelated type.
diff --git a/clang/unittests/Analysis/FlowSensitive/DataflowEnvironmentTest.cpp 
b/clang/unittests/Analysis/FlowSensitive/DataflowEnvironmentTest.cpp
index a4ac597bb06d6..8481026f7c1fc 100644
--- a/clang/unittests/Analysis/FlowSensitive/DataflowEnvironmentTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/DataflowEnvironmentTest.cpp
@@ -442,6 +442,46 @@ TEST_F(EnvironmentTest, 
CXXDefaultInitExprResultObjIsWrappedExprResultObj) {
 &Env.getResultObjectLocation(*DefaultInit->getExpr()));
 }
 
+TEST_F(EnvironmentTest, ResultObjectLocationForInheritedCtorInitExpr) {
+  using namespace ast_matchers;
+
+  std::string Code = R"(
+struct Base {
+  Base(int b) {}
+};
+struct Derived : Base {
+  using Base::Base;
+};
+
+Derived d = Derived(0);
+  )";
+
+  auto Unit =
+  tooling::buildASTFromCodeWithArgs(Code, {"-fsyntax-only", "-std=c++20"});
+  auto &Context = Unit->getASTContext();
+
+  ASSERT_EQ(Context.getDiagnostics().getClient()->getNumErrors(), 0U);
+
+  auto Results =
+  match(cxxConstructorDecl(
+hasAnyConstructorInitializer(cxxCtorInitializer(
+withInitializer(expr().bind("inherited_ctor_init_expr")
+.bind("ctor"),
+Context);
+  const auto *Constructor = selectFirst("ctor", Results);
+  const auto *InheritedCtorInit =
+  selectFirst("inherited_ctor_init_expr", 
Results);
+
+  // Verify that `inherited_ctor_init_expr` has no children.
+  ASSERT_EQ(InheritedCtorInit->child_begin(), InheritedCtorInit->child_end());
+
+  Environment Env(DAContext, *Constructor);
+  Env.initialize();
+
+  RecordStorageLocation &Loc = Env.getResultObjectLocation(*InheritedCtorInit);
+  ASSERT_NE(&Loc, nullptr);
+}
+
 TEST_F(EnvironmentTest, Stmt) {
   using namespace ast_matchers;
 

``




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


[clang] [ExprConstant] Handle shift overflow the same way as other kinds of overflow (PR #99579)

2024-07-19 Thread Shafik Yaghmour via cfe-commits

https://github.com/shafik commented:

I think I am bit surprised more tests are not affected by this change 
considering you modified the handling in several places. It seems we should be 
adding more test coverage with this change.

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


[clang-tools-extra] [clang-tidy][cppcoreguidelines-missing-std-forward] Do not warn when the parameter is used in a `static_cast`. (PR #99477)

2024-07-19 Thread Clement Courbet via cfe-commits

legrosbuffle wrote:

Thanks for the comments. I went for a disabled-by-default option as that seems 
to be the consensus.

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


[clang] Fix diagnostics-dsym.test on mac-arm64 (PR #99399)

2024-07-19 Thread via cfe-commits

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


[clang] [PAC] Authenticate function pointers in UBSan type checks (PR #99590)

2024-07-19 Thread Daniil Kovalev via cfe-commits

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


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


[clang] [flang] [Flang-new][OpenMP] Add bitcode files for AMD GPU OpenMP (PR #96742)

2024-07-19 Thread Dominik Adamski via cfe-commits


@@ -333,6 +333,9 @@ void Flang::AddAMDGPUTargetArgs(const ArgList &Args,
 StringRef Val = A->getValue();
 CmdArgs.push_back(Args.MakeArgString("-mcode-object-version=" + Val));
   }
+
+  const ToolChain &TC = getToolChain();
+  TC.addClangTargetOptions(Args, CmdArgs, Action::OffloadKind::OFK_OpenMP);

DominikAdamski wrote:

I asked question on flang-compiler slack (openmp/openacc channel). If I get no 
response, I will raise question on Flang technical community call on Monday.

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


[clang] [flang] [Flang-new][OpenMP] Add bitcode files for AMD GPU OpenMP (PR #96742)

2024-07-19 Thread Dominik Adamski via cfe-commits

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


[clang] [compiler-rt] [libcxx] [libunwind] [llvm] [openmp] [cmake] switch to CMake's native `check_{compiler,linker}_flag` (PR #96171)

2024-07-19 Thread Ryan Prichard via cfe-commits

rprichard wrote:

Sorry, I didn't notice the ping until just now.

The CMake feature testing seems broken, on Android at least. Here's a 
representative error from 
`build/android-ndk-21-def-x86/CMakeFiles/CMakeError.log`:

```
Performing C++ SOURCE FILE Test CXX_SUPPORTS_NOSTDLIBXX_FLAG failed with the 
following output:
Change Dir: /llvm/build/android-ndk-21-def-x86/CMakeFiles/CMakeTmp

Run Build Command(s):/usr/local/bin/ninja cmTC_80129 && [1/2] Building CXX 
object CMakeFiles/cmTC_80129.dir/src.cxx.o
[2/2] Linking CXX executable cmTC_80129
FAILED: cmTC_80129 
: && /opt/android/clang/clang-current/bin/clang++ --target=i686-linux-android21 
--sysroot=/opt/android/ndk/sysroot --start-no-unused-arguments --unwindlib=none 
--end-no-unused-arguments  CMakeFiles/cmTC_80129.dir/src.cxx.o -o cmTC_80129   
&& :
ld.lld: error: unable to find library -lc++
clang++: error: linker command failed with exit code 1 (use -v to see 
invocation)
ninja: build stopped: subcommand failed.


Source file was:
int main() { return 0; }
```

It's trying to see if `-nostdlib++` is supported, but I don't see that flag 
being passed in the `clang++` command line that CMake uses. In any case, CMake 
tries  to build a C++ program, which fails because libc++ doesn't exist yet.

It seems that the Android support in the Dockerfile is broken after a refactor 
last year. I have some changes that get it working again. BuildKite is still 
successfully running Android tests as of today, so I think it's using an old 
image.


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


[clang] Fix diagnostics-dsym.test on mac-arm64 (PR #99399)

2024-07-19 Thread Cyndy Ishida via cfe-commits

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

Thank you for looking into & resolving this again! 

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


[clang] 39185da - [Clang][AArch64] Add missing SME/SVE2.1 feature macros (#98285)

2024-07-19 Thread via cfe-commits

Author: SpencerAbson
Date: 2024-07-19T09:54:52+01:00
New Revision: 39185da16228efb4a09a30d6825a6f508c4755a3

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

LOG: [Clang][AArch64] Add missing SME/SVE2.1 feature macros (#98285)

The 2022 SME2.1and SVE2.1 feature macros are missing from Clang. Passing
'-target-feature +sve2p1' and 'target-feature +sme2p1' should prompt
Clang to define __ARM_FEATURE_SVE2p1 and __ARM_FEATURE_SME2p1
respectively, including their prerequisits..

This patch includes __ARM_FEATURE_SVE2p1 and __ARM_FEATURE_SME2p1, plus
a clang preprocessor test for each. It also ensures that the Clang macro
builder is used in a consistent fashion across Targets/AArch64.cpp.

The specification for SVE2.1 is documented in the latest (2024 Q1) ACLE
release: https://github.com/ARM-software/acle/releases . SME2p1 is not
yet featured in ACLE documentation but its features are described under
https://developer.arm.com/documentation/ddi0487/latest/

Added: 


Modified: 
clang/lib/Basic/Targets/AArch64.cpp
clang/lib/Basic/Targets/AArch64.h
clang/test/Preprocessor/aarch64-target-features.c

Removed: 




diff  --git a/clang/lib/Basic/Targets/AArch64.cpp 
b/clang/lib/Basic/Targets/AArch64.cpp
index 2692ddec26ff4..6349fcf3dadd7 100644
--- a/clang/lib/Basic/Targets/AArch64.cpp
+++ b/clang/lib/Basic/Targets/AArch64.cpp
@@ -449,6 +449,9 @@ void AArch64TargetInfo::getTargetDefines(const LangOptions 
&Opts,
   if (HasSVE2)
 Builder.defineMacro("__ARM_FEATURE_SVE2", "1");
 
+  if (HasSVE2p1)
+Builder.defineMacro("__ARM_FEATURE_SVE2p1", "1");
+
   if (HasSVE2 && HasSVE2AES)
 Builder.defineMacro("__ARM_FEATURE_SVE2_AES", "1");
 
@@ -467,8 +470,15 @@ void AArch64TargetInfo::getTargetDefines(const LangOptions 
&Opts,
   }
 
   if (HasSME2) {
-Builder.defineMacro("__ARM_FEATURE_SME");
-Builder.defineMacro("__ARM_FEATURE_SME2");
+Builder.defineMacro("__ARM_FEATURE_SME", "1");
+Builder.defineMacro("__ARM_FEATURE_SME2", "1");
+Builder.defineMacro("__ARM_FEATURE_LOCALLY_STREAMING", "1");
+  }
+
+  if (HasSME2p1) {
+Builder.defineMacro("__ARM_FEATURE_SME", "1");
+Builder.defineMacro("__ARM_FEATURE_SME2", "1");
+Builder.defineMacro("__ARM_FEATURE_SME2p1", "1");
 Builder.defineMacro("__ARM_FEATURE_LOCALLY_STREAMING", "1");
   }
 
@@ -739,8 +749,10 @@ bool AArch64TargetInfo::hasFeature(StringRef Feature) 
const {
   .Case("sve2-bitperm", FPU & SveMode && HasSVE2BitPerm)
   .Case("sve2-sha3", FPU & SveMode && HasSVE2SHA3)
   .Case("sve2-sm4", FPU & SveMode && HasSVE2SM4)
+  .Case("sve2p1", FPU & SveMode && HasSVE2p1)
   .Case("sme", HasSME)
   .Case("sme2", HasSME2)
+  .Case("sme2p1", HasSME2p1)
   .Case("sme-f64f64", HasSMEF64F64)
   .Case("sme-i16i64", HasSMEI16I64)
   .Case("sme-fa64", HasSMEFA64)
@@ -816,6 +828,13 @@ bool 
AArch64TargetInfo::handleTargetFeatures(std::vector &Features,
   HasFullFP16 = true;
   HasSVE2 = true;
 }
+if (Feature == "+sve2p1") {
+  FPU |= NeonMode;
+  FPU |= SveMode;
+  HasFullFP16 = true;
+  HasSVE2 = true;
+  HasSVE2p1 = true;
+}
 if (Feature == "+sve2-aes") {
   FPU |= NeonMode;
   FPU |= SveMode;
@@ -867,6 +886,13 @@ bool 
AArch64TargetInfo::handleTargetFeatures(std::vector &Features,
   HasBFloat16 = true;
   HasFullFP16 = true;
 }
+if (Feature == "+sme2p1") {
+  HasSME = true;
+  HasSME2 = true;
+  HasSME2p1 = true;
+  HasBFloat16 = true;
+  HasFullFP16 = true;
+}
 if (Feature == "+sme-f64f64") {
   HasSME = true;
   HasSMEF64F64 = true;

diff  --git a/clang/lib/Basic/Targets/AArch64.h 
b/clang/lib/Basic/Targets/AArch64.h
index 71510fe289510..7bdf5a2b4106e 100644
--- a/clang/lib/Basic/Targets/AArch64.h
+++ b/clang/lib/Basic/Targets/AArch64.h
@@ -49,6 +49,7 @@ class LLVM_LIBRARY_VISIBILITY AArch64TargetInfo : public 
TargetInfo {
   bool HasMatMul = false;
   bool HasBFloat16 = false;
   bool HasSVE2 = false;
+  bool HasSVE2p1 = false;
   bool HasSVE2AES = false;
   bool HasSVE2SHA3 = false;
   bool HasSVE2SM4 = false;
@@ -70,6 +71,7 @@ class LLVM_LIBRARY_VISIBILITY AArch64TargetInfo : public 
TargetInfo {
   bool HasSME2 = false;
   bool HasSMEF64F64 = false;
   bool HasSMEI16I64 = false;
+  bool HasSME2p1 = false;
   bool HasSB = false;
   bool HasPredRes = false;
   bool HasSSBS = false;

diff  --git a/clang/test/Preprocessor/aarch64-target-features.c 
b/clang/test/Preprocessor/aarch64-target-features.c
index 71cc36acf3f0e..87bd3e142d2c4 100644
--- a/clang/test/Preprocessor/aarch64-target-features.c
+++ b/clang/test/Preprocessor/aarch64-target-features.c
@@ -236,6 +236,15 @@
 // RUN: %clang -target aarch64-none-linux-gnu -march=armv9-a+sve2-bitperm -x c 
-E -dM %s 

[clang] [Clang][AArch64] Add missing SME/SVE2.1 feature macros (PR #98285)

2024-07-19 Thread via cfe-commits

github-actions[bot] wrote:



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

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

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

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

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

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


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


[clang] [llvm] [openmp] [Clang][OpenMP] Add interchange directive (PR #93022)

2024-07-19 Thread Michael Kruse via cfe-commits

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


[clang] [flang] [Flang-new][OpenMP] Add bitcode files for AMD GPU OpenMP (PR #96742)

2024-07-19 Thread Dominik Adamski via cfe-commits

DominikAdamski wrote:

> > Would it be possible for you to investigate that? It really shouldn't be 
> > required if we can't help it.
> 
> +1

Fixed in PR https://github.com/llvm/llvm-project/pull/99002

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


[clang] [Clang] [WIP] Added builtin_alloca right Address Space for OpenCL (PR #95750)

2024-07-19 Thread Vikash Gupta via cfe-commits

vg0204 wrote:

PING!

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


[clang-tools-extra] Ensure functions are anchored in the global namespace (for cert-err-33) (PR #99380)

2024-07-19 Thread via cfe-commits

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


[clang] [test][PAC][clang] Add missing tests against linux triples (PR #99482)

2024-07-19 Thread Daniil Kovalev via cfe-commits

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


[clang-tools-extra] [clang-tidy][cppcoreguidelines-missing-std-forward] Do not warn when the parameter is used in a `static_cast`. (PR #99477)

2024-07-19 Thread Clement Courbet via cfe-commits

https://github.com/legrosbuffle updated 
https://github.com/llvm/llvm-project/pull/99477

>From b423b26cba90288912b3377c39ab4207c9fc95dc Mon Sep 17 00:00:00 2001
From: Clement Courbet 
Date: Thu, 18 Jul 2024 11:47:56 +
Subject: [PATCH 1/2] [clang-tidy][cppcoreguidelines-missing-std-forward] Do
 not warn when the parameter is used in a `static_cast`.

This provides a way to inform the check that we're intending to use an
the forwarding reference as a specific reference category

Fixes #99474.
---
 .../MissingStdForwardCheck.cpp  |  8 ++--
 clang-tools-extra/docs/ReleaseNotes.rst |  5 +
 .../cppcoreguidelines/missing-std-forward.rst   |  3 +++
 .../cppcoreguidelines/missing-std-forward.cpp   | 17 +
 4 files changed, 31 insertions(+), 2 deletions(-)

diff --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/MissingStdForwardCheck.cpp 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/MissingStdForwardCheck.cpp
index bbb35228ce47f..726e9fffc628b 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/MissingStdForwardCheck.cpp
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/MissingStdForwardCheck.cpp
@@ -129,6 +129,9 @@ void MissingStdForwardCheck::registerMatchers(MatchFinder 
*Finder) {
   unless(anyOf(hasAncestor(typeLoc()),
hasAncestor(expr(hasUnevaluatedContext());
 
+  auto StaticCast = cxxStaticCastExpr(
+  hasSourceExpression(declRefExpr(to(equalsBoundNode("param");
+
   Finder->addMatcher(
   parmVarDecl(
   parmVarDecl().bind("param"), hasIdentifier(),
@@ -136,8 +139,9 @@ void MissingStdForwardCheck::registerMatchers(MatchFinder 
*Finder) {
   hasAncestor(functionDecl().bind("func")),
   hasAncestor(functionDecl(
   isDefinition(), equalsBoundNode("func"), ToParam,
-  unless(anyOf(isDeleted(),
-   hasDescendant(std::move(ForwardCallMatcher))),
+  unless(anyOf(isDeleted(), hasDescendant(expr(
+
anyOf(std::move(ForwardCallMatcher),
+  
std::move(StaticCast),
   this);
 }
 
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index a23483e6df6d2..c3f41811fa7d7 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -518,6 +518,11 @@ Changes in existing checks
   usages of ``std::string_view::compare``. Added a `StringLikeClasses` option
   to detect usages of ``compare`` method in custom string-like classes.
 
+- Improved :doc:`cppcoreguidelines-missing-std-forward
+  ` check to allow
+  using ``static_cast`` to explicitly convey the intention of using a
+  forwarding reference as an lvalue reference.
+
 Removed checks
 ^^
 
diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/missing-std-forward.rst
 
b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/missing-std-forward.rst
index 0c311b59a5d5a..12765b45088de 100644
--- 
a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/missing-std-forward.rst
+++ 
b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/missing-std-forward.rst
@@ -38,3 +38,6 @@ Example:
 This check implements `F.19
 `_
 from the C++ Core Guidelines.
+
+Users who want to use the forwarding reference as an lvalue reference can 
convey
+the intention by using ``static_cast(t)``.
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/missing-std-forward.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/missing-std-forward.cpp
index 8116db58c937d..519d2822948bb 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/missing-std-forward.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/missing-std-forward.cpp
@@ -211,3 +211,20 @@ template
 void unused_argument3(F&& _) {}
 
 } // namespace unused_arguments
+
+namespace escape_hatch {
+
+template
+void used_as_lvalue_on_purpose(T&& t) {
+  static_cast(t);
+  static_cast(t);
+}
+
+template
+void used_as_rvalue_on_purpose(T&& t) {
+  static_cast(t);
+  // Typically used as another spelling for `std::forward`.
+  static_cast(t);
+}
+
+}

>From 64f957fead4d409e0835a6f032330f73983b975f Mon Sep 17 00:00:00 2001
From: Clement Courbet 
Date: Fri, 19 Jul 2024 08:20:30 +
Subject: [PATCH 2/2] Add a check option to ignore `static_cast`s.

---
 .../MissingStdForwardCheck.cpp|  6 ++--
 clang-tools-extra/docs/ReleaseNotes.rst   |  8 ++---
 .../cppcoreguidelines/missing-std-forward.rst | 12 ++--
 .../missing-std-forward-casts.cpp | 29 +++
 .../cppcoreguidelines/missing-std-forward.cpp | 15 +++---
 5 files changed, 49 insertions(+), 21 deletions(-)
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/cppcor

[clang] [llvm] [clang] Support -Wa, options -mmsa and -mno-msa (PR #99615)

2024-07-19 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-driver

Author: None (yingopq)


Changes



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


6 Files Affected:

- (modified) clang/include/clang/Basic/CodeGenOptions.def (+2) 
- (modified) clang/include/clang/Driver/Options.td (+6-2) 
- (modified) clang/lib/CodeGen/BackendUtil.cpp (+2) 
- (modified) clang/lib/Driver/ToolChains/Clang.cpp (+4) 
- (modified) clang/tools/driver/cc1as_main.cpp (+10) 
- (modified) llvm/include/llvm/MC/MCTargetOptions.h (+3) 


``diff
diff --git a/clang/include/clang/Basic/CodeGenOptions.def 
b/clang/include/clang/Basic/CodeGenOptions.def
index f671b780bcbeb..1d84be7520422 100644
--- a/clang/include/clang/Basic/CodeGenOptions.def
+++ b/clang/include/clang/Basic/CodeGenOptions.def
@@ -178,6 +178,8 @@ CODEGENOPT(MergeAllConstants , 1, 1) ///< Merge identical 
constants.
 CODEGENOPT(MergeFunctions, 1, 0) ///< Set when -fmerge-functions is 
enabled.
 CODEGENOPT(NoCommon  , 1, 0) ///< Set when -fno-common or C++ is 
enabled.
 CODEGENOPT(NoExecStack   , 1, 0) ///< Set when -Wa,--noexecstack is 
enabled.
+CODEGENOPT(Msa   , 1, 0) ///< Set when -Wa,-mmsa is enabled.
+CODEGENOPT(NoMsa , 1, 0) ///< Set when -Wa,-mno-msa is enabled.
 CODEGENOPT(FatalWarnings , 1, 0) ///< Set when -Wa,--fatal-warnings is
  ///< enabled.
 CODEGENOPT(NoWarn, 1, 0) ///< Set when -Wa,--no-warn is enabled.
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 12b20fe04675b..0d5c68fc3a0d0 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5337,9 +5337,13 @@ def mmadd4 : Flag<["-"], "mmadd4">, 
Group,
 def mno_madd4 : Flag<["-"], "mno-madd4">, Group,
   HelpText<"Disable the generation of 4-operand madd.s, madd.d and related 
instructions.">;
 def mmsa : Flag<["-"], "mmsa">, Group,
-  HelpText<"Enable MSA ASE (MIPS only)">;
+  Visibility<[ClangOption, CC1AsOption]>,
+  HelpText<"Enable MSA ASE (MIPS only)">,
+  MarshallingInfoFlag>;
 def mno_msa : Flag<["-"], "mno-msa">, Group,
-  HelpText<"Disable MSA ASE (MIPS only)">;
+  Visibility<[ClangOption, CC1AsOption]>,
+  HelpText<"Disable MSA ASE (MIPS only)">,
+  MarshallingInfoFlag>;
 def mmt : Flag<["-"], "mmt">, Group,
   HelpText<"Enable MT ASE (MIPS only)">;
 def mno_mt : Flag<["-"], "mno-mt">, Group,
diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index e765bbf637a66..6901a6d88313f 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -463,6 +463,8 @@ static bool initTargetOptions(DiagnosticsEngine &Diags,
   ? llvm::MCTargetOptions::DisableDwarfDirectory
   : llvm::MCTargetOptions::EnableDwarfDirectory;
   Options.MCOptions.MCNoExecStack = CodeGenOpts.NoExecStack;
+  Options.MCOptions.MCMsa = CodeGenOpts.Msa;
+  Options.MCOptions.MCNoMsa = CodeGenOpts.NoMsa;
   Options.MCOptions.MCIncrementalLinkerCompatible =
   CodeGenOpts.IncrementalLinkerCompatible;
   Options.MCOptions.MCFatalWarnings = CodeGenOpts.FatalWarnings;
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 1fd6fba210042..e4a2d4e84bdca 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -2630,6 +2630,10 @@ static void 
CollectArgsForIntegratedAssembler(Compilation &C,
 CmdArgs.push_back("-massembler-no-warn");
   } else if (Value == "--noexecstack") {
 UseNoExecStack = true;
+  } else if (Value == "-mmsa") {
+CmdArgs.push_back("-mmsa");
+  } else if (Value == "-mno-msa") {
+CmdArgs.push_back("-mno-msa");
   } else if (Value.starts_with("-compress-debug-sections") ||
  Value.starts_with("--compress-debug-sections") ||
  Value == "-nocompress-debug-sections" ||
diff --git a/clang/tools/driver/cc1as_main.cpp 
b/clang/tools/driver/cc1as_main.cpp
index ec93f092713f5..4bca886714a63 100644
--- a/clang/tools/driver/cc1as_main.cpp
+++ b/clang/tools/driver/cc1as_main.cpp
@@ -168,6 +168,10 @@ struct AssemblerInvocation {
 
   LLVM_PREFERRED_TYPE(bool)
   unsigned Crel : 1;
+  LLVM_PREFERRED_TYPE(bool)
+  unsigned Msa : 1;
+  LLVM_PREFERRED_TYPE(bool)
+  unsigned NoMsa : 1;
 
   /// The name of the relocation model to use.
   std::string RelocationModel;
@@ -211,6 +215,8 @@ struct AssemblerInvocation {
 EmitDwarfUnwind = EmitDwarfUnwindType::Default;
 EmitCompactUnwindNonCanonical = false;
 Crel = false;
+Msa = 0;
+NoMsa = 0;
   }
 
   static bool CreateFromArgs(AssemblerInvocation &Res,
@@ -382,6 +388,8 @@ bool 
AssemblerInvocation::CreateFromArgs(AssemblerInvocation &Opts,
   Opts.EmitCompactUnwindNonCanonical =
   Args.hasArg(OPT_femit_compact_unwind_non_canonical);
   Opts.Crel = Args.hasArg(OPT_crel);
+  Opts.Msa = Args.hasArg(OPT_mmsa);
+  Opts.NoMsa = Args.hasArg(OPT_

[clang] [clang] Limit alignment for emitted vectors (PR #98629)

2024-07-19 Thread Mariya Podchishchaeva via cfe-commits

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


[clang] [flang] [Flang-new][OpenMP] Add bitcode files for AMD GPU OpenMP (PR #96742)

2024-07-19 Thread Dominik Adamski via cfe-commits


@@ -8024,7 +8024,7 @@ def source_date_epoch : Separate<["-"], 
"source-date-epoch">,
 // CUDA Options
 
//===--===//
 
-let Visibility = [CC1Option] in {
+let Visibility = [CC1Option, FC1Option] in {

DominikAdamski wrote:

PR https://github.com/llvm/llvm-project/pull/99002 removes adding 
`-fcuda-is-device` option for OpenMP AMDGPU in clang. In consequence we don't 
need to add `-fcuda-is-device` flag for Flang.

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


[clang] 2df9fd7 - Fix diagnostics-dsym.test on mac-arm64 (#99399)

2024-07-19 Thread via cfe-commits

Author: Haowei
Date: 2024-07-19T00:03:12-07:00
New Revision: 2df9fd7edb73c1c2b27bda433ae0795bc8076dd3

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

LOG: Fix diagnostics-dsym.test on mac-arm64 (#99399)

The check ordering of diagnostics-dsym.test is wrong and it causes
test failure when running on mac-arm64 machine. This patch fixes it.

Added: 


Modified: 
clang/test/InstallAPI/diagnostics-dsym.test

Removed: 




diff  --git a/clang/test/InstallAPI/diagnostics-dsym.test 
b/clang/test/InstallAPI/diagnostics-dsym.test
index 42fa67a1f9b1e..b8433653c3f76 100644
--- a/clang/test/InstallAPI/diagnostics-dsym.test
+++ b/clang/test/InstallAPI/diagnostics-dsym.test
@@ -19,8 +19,8 @@
 ; RUN: --verify-mode=Pedantic 2>&1 | FileCheck %s
 
 ; CHECK: violations found for arm64 
-; CHECK: foo.c:5:0: error: no declaration found for exported symbol 'bar' in 
dynamic library
-; CHECK: foo.c:1:0: error: no declaration found for exported symbol 'foo' in 
dynamic library
+; CHECK-DAG: foo.c:5:0: error: no declaration found for exported symbol 'bar' 
in dynamic library
+; CHECK-DAG: foo.c:1:0: error: no declaration found for exported symbol 'foo' 
in dynamic library
 
 ;--- foo.c
 int foo(void) {



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


[clang] e5df657 - [Sema] Fix assertion error in Sema::FindInstantiatedDecl (#96509)

2024-07-19 Thread via cfe-commits

Author: Alejandro Álvarez Ayllón
Date: 2024-07-19T11:00:30+02:00
New Revision: e5df657bbf38f8fcd9dd8c9e79262ca184f2598b

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

LOG: [Sema] Fix assertion error in Sema::FindInstantiatedDecl (#96509)

...when looking for a template instantiation with a non-type parameter of
unknown type and with a default value.

This can happen when a template non-type parameter has a broken
expression that gets replaced by a `RecoveryExpr`.

Added: 
clang/test/SemaCXX/instantiate-template-broken-nontype-default.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index b0afadfa8d324..4efdb076ba768 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -857,6 +857,9 @@ Bug Fixes in This Version
 
 - ``typeof_unqual`` now properly removes type qualifiers from arrays and their 
element types. (#GH92667)
 
+- Fixed an assertion failure when a template non-type parameter contains
+  an invalid expression.
+
 Bug Fixes to Compiler Builtins
 ^^
 

diff  --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp 
b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 01432301633ed..97161febc15f7 100644
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -6229,7 +6229,12 @@ NamedDecl *Sema::FindInstantiatedDecl(SourceLocation 
Loc, NamedDecl *D,
   getTrivialTemplateArgumentLoc(UnpackedArg, QualType(), Loc));
   }
   QualType T = CheckTemplateIdType(TemplateName(TD), Loc, Args);
-  if (T.isNull())
+  // We may get a non-null type with errors, in which case
+  // `getAsCXXRecordDecl` will return `nullptr`. For instance, this
+  // happens when one of the template arguments is an invalid
+  // expression. We return early to avoid triggering the assertion
+  // about the `CodeSynthesisContext`.
+  if (T.isNull() || T->containsErrors())
 return nullptr;
   CXXRecordDecl *SubstRecord = T->getAsCXXRecordDecl();
 

diff  --git 
a/clang/test/SemaCXX/instantiate-template-broken-nontype-default.cpp 
b/clang/test/SemaCXX/instantiate-template-broken-nontype-default.cpp
new file mode 100644
index 0..eb798e5887bda
--- /dev/null
+++ b/clang/test/SemaCXX/instantiate-template-broken-nontype-default.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s
+
+constexpr Missing a = 0; // expected-error {{unknown type name 'Missing'}}
+
+template < typename T, Missing b = a> // expected-error {{unknown type name 
'Missing'}}
+class Klass { // expected-note {{candidate template ignored: could not match 
'Klass' against 'int'}} \
+ expected-note {{implicit deduction guide declared as 
'template ()> Klass(Klass) -> 
Klass'}}
+  Klass(T);   // expected-note {{candidate template ignored: substitution 
failure [with T = int, b = ()]}} \
+ expected-note {{implicit deduction guide declared as 
'template ()> Klass(T) -> Klass'}}
+};
+
+Klass foo{5}; // no-crash \
+ expected-error {{no viable constructor or deduction guide for 
deduction of template arguments of 'Klass'}}
+



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


[clang] [Sema] Fix assertion error in Sema::FindInstantiatedDecl (PR #96509)

2024-07-19 Thread via cfe-commits
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?Message-ID:
In-Reply-To: 


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


[clang] [llvm] [clang] Support -Wa, options -mmsa and -mno-msa (PR #99615)

2024-07-19 Thread via cfe-commits

https://github.com/yingopq created 
https://github.com/llvm/llvm-project/pull/99615

None

>From 1ef0b65fd7adc7a588de6d818eb1e6ab532a3869 Mon Sep 17 00:00:00 2001
From: Ying Huang 
Date: Fri, 19 Jul 2024 04:19:09 -0400
Subject: [PATCH] [clang] Support -Wa, options -mmsa and -mno-msa

---
 clang/include/clang/Basic/CodeGenOptions.def |  2 ++
 clang/include/clang/Driver/Options.td|  8 ++--
 clang/lib/CodeGen/BackendUtil.cpp|  2 ++
 clang/lib/Driver/ToolChains/Clang.cpp|  4 
 clang/tools/driver/cc1as_main.cpp| 10 ++
 llvm/include/llvm/MC/MCTargetOptions.h   |  3 +++
 6 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/clang/include/clang/Basic/CodeGenOptions.def 
b/clang/include/clang/Basic/CodeGenOptions.def
index f671b780bcbeb..1d84be7520422 100644
--- a/clang/include/clang/Basic/CodeGenOptions.def
+++ b/clang/include/clang/Basic/CodeGenOptions.def
@@ -178,6 +178,8 @@ CODEGENOPT(MergeAllConstants , 1, 1) ///< Merge identical 
constants.
 CODEGENOPT(MergeFunctions, 1, 0) ///< Set when -fmerge-functions is 
enabled.
 CODEGENOPT(NoCommon  , 1, 0) ///< Set when -fno-common or C++ is 
enabled.
 CODEGENOPT(NoExecStack   , 1, 0) ///< Set when -Wa,--noexecstack is 
enabled.
+CODEGENOPT(Msa   , 1, 0) ///< Set when -Wa,-mmsa is enabled.
+CODEGENOPT(NoMsa , 1, 0) ///< Set when -Wa,-mno-msa is enabled.
 CODEGENOPT(FatalWarnings , 1, 0) ///< Set when -Wa,--fatal-warnings is
  ///< enabled.
 CODEGENOPT(NoWarn, 1, 0) ///< Set when -Wa,--no-warn is enabled.
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 12b20fe04675b..0d5c68fc3a0d0 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5337,9 +5337,13 @@ def mmadd4 : Flag<["-"], "mmadd4">, 
Group,
 def mno_madd4 : Flag<["-"], "mno-madd4">, Group,
   HelpText<"Disable the generation of 4-operand madd.s, madd.d and related 
instructions.">;
 def mmsa : Flag<["-"], "mmsa">, Group,
-  HelpText<"Enable MSA ASE (MIPS only)">;
+  Visibility<[ClangOption, CC1AsOption]>,
+  HelpText<"Enable MSA ASE (MIPS only)">,
+  MarshallingInfoFlag>;
 def mno_msa : Flag<["-"], "mno-msa">, Group,
-  HelpText<"Disable MSA ASE (MIPS only)">;
+  Visibility<[ClangOption, CC1AsOption]>,
+  HelpText<"Disable MSA ASE (MIPS only)">,
+  MarshallingInfoFlag>;
 def mmt : Flag<["-"], "mmt">, Group,
   HelpText<"Enable MT ASE (MIPS only)">;
 def mno_mt : Flag<["-"], "mno-mt">, Group,
diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index e765bbf637a66..6901a6d88313f 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -463,6 +463,8 @@ static bool initTargetOptions(DiagnosticsEngine &Diags,
   ? llvm::MCTargetOptions::DisableDwarfDirectory
   : llvm::MCTargetOptions::EnableDwarfDirectory;
   Options.MCOptions.MCNoExecStack = CodeGenOpts.NoExecStack;
+  Options.MCOptions.MCMsa = CodeGenOpts.Msa;
+  Options.MCOptions.MCNoMsa = CodeGenOpts.NoMsa;
   Options.MCOptions.MCIncrementalLinkerCompatible =
   CodeGenOpts.IncrementalLinkerCompatible;
   Options.MCOptions.MCFatalWarnings = CodeGenOpts.FatalWarnings;
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 1fd6fba210042..e4a2d4e84bdca 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -2630,6 +2630,10 @@ static void 
CollectArgsForIntegratedAssembler(Compilation &C,
 CmdArgs.push_back("-massembler-no-warn");
   } else if (Value == "--noexecstack") {
 UseNoExecStack = true;
+  } else if (Value == "-mmsa") {
+CmdArgs.push_back("-mmsa");
+  } else if (Value == "-mno-msa") {
+CmdArgs.push_back("-mno-msa");
   } else if (Value.starts_with("-compress-debug-sections") ||
  Value.starts_with("--compress-debug-sections") ||
  Value == "-nocompress-debug-sections" ||
diff --git a/clang/tools/driver/cc1as_main.cpp 
b/clang/tools/driver/cc1as_main.cpp
index ec93f092713f5..4bca886714a63 100644
--- a/clang/tools/driver/cc1as_main.cpp
+++ b/clang/tools/driver/cc1as_main.cpp
@@ -168,6 +168,10 @@ struct AssemblerInvocation {
 
   LLVM_PREFERRED_TYPE(bool)
   unsigned Crel : 1;
+  LLVM_PREFERRED_TYPE(bool)
+  unsigned Msa : 1;
+  LLVM_PREFERRED_TYPE(bool)
+  unsigned NoMsa : 1;
 
   /// The name of the relocation model to use.
   std::string RelocationModel;
@@ -211,6 +215,8 @@ struct AssemblerInvocation {
 EmitDwarfUnwind = EmitDwarfUnwindType::Default;
 EmitCompactUnwindNonCanonical = false;
 Crel = false;
+Msa = 0;
+NoMsa = 0;
   }
 
   static bool CreateFromArgs(AssemblerInvocation &Res,
@@ -382,6 +388,8 @@ bool 
AssemblerInvocation::CreateFromArgs(AssemblerInvocation &Opts,
   Opts.EmitCompactUnwindNonCanonical =
   Args.hasArg(OPT_fem

[clang] a1d77ca - [test][PAC][clang] Add missing tests against linux triples (#99482)

2024-07-19 Thread via cfe-commits

Author: Daniil Kovalev
Date: 2024-07-19T09:47:47+03:00
New Revision: a1d77caaabbb5279b734c061dab36b2138ec476d

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

LOG: [test][PAC][clang] Add missing tests against linux triples (#99482)

Enhance tests introduced in #94056, #96992, #98276 and #98847 by adding
RUN and CHECK lines against linux triples.

Added: 


Modified: 
clang/test/CodeGen/ptrauth-function-lvalue-cast-disc.c
clang/test/CodeGen/ptrauth-function-type-discriminator-cast.c
clang/test/CodeGen/ptrauth-function-type-discriminator.c
clang/test/CodeGen/ptrauth-ubsan-vptr.cpp
clang/test/CodeGenCXX/ptrauth-explicit-vtable-pointer-control.cpp
clang/test/CodeGenCXX/ptrauth-rtti-layout.cpp
clang/test/CodeGenCXX/ptrauth-static-destructors.cpp
clang/test/CodeGenCXX/ptrauth-throw.cpp
clang/test/CodeGenCXX/ptrauth-thunks.cpp
clang/test/CodeGenCXX/ptrauth-virtual-function.cpp
clang/test/CodeGenCXX/ptrauth-vtable-virtual-inheritance-thunk.cpp
clang/test/CodeGenCXX/ubsan-vtable-checks.cpp

clang/test/SemaCXX/ptrauth-incomplete-virtual-member-function-return-arg-type.cpp
clang/test/SemaCXX/vtable_pointer_authentication_attribute.cpp

Removed: 




diff  --git a/clang/test/CodeGen/ptrauth-function-lvalue-cast-disc.c 
b/clang/test/CodeGen/ptrauth-function-lvalue-cast-disc.c
index 7d76649e2e49c..40bba99478192 100644
--- a/clang/test/CodeGen/ptrauth-function-lvalue-cast-disc.c
+++ b/clang/test/CodeGen/ptrauth-function-lvalue-cast-disc.c
@@ -1,12 +1,14 @@
 // RUN: %clang_cc1 %s -triple arm64e-apple-ios13 -fptrauth-calls 
-fptrauth-intrinsics -emit-llvm -o- 
-fptrauth-function-pointer-type-discrimination | FileCheck -check-prefixes 
CHECK,TYPE %s
+// RUN: %clang_cc1 %s -triple aarch64-linux-gnu  -fptrauth-calls 
-fptrauth-intrinsics -emit-llvm -o- 
-fptrauth-function-pointer-type-discrimination | FileCheck -check-prefixes 
CHECK,TYPE %s
 // RUN: %clang_cc1 %s -triple arm64e-apple-ios13 -fptrauth-calls 
-fptrauth-intrinsics -emit-llvm -o- | FileCheck -check-prefixes CHECK,ZERO %s
+// RUN: %clang_cc1 %s -triple aarch64-linux-gnu  -fptrauth-calls 
-fptrauth-intrinsics -emit-llvm -o- | FileCheck -check-prefixes CHECK,ZERO %s
 
 typedef void (*fptr_t)(void);
 
 char *cptr;
 void (*fptr)(void);
 
-// CHECK-LABEL: define void @test1
+// CHECK-LABEL: define{{.*}} void @test1
 void test1() {
   // TYPE: [[LOAD:%.*]] = load ptr, ptr @cptr
   // TYPE: [[TOINT:%.*]] = ptrtoint ptr [[LOAD]] to i64
@@ -17,7 +19,7 @@ void test1() {
   (*(fptr_t)cptr)();
 }
 
-// CHECK-LABEL: define i8 @test2
+// CHECK-LABEL: define{{.*}} i8 @test2
 char test2() {
   return *(char *)fptr;
 
@@ -35,7 +37,7 @@ char test2() {
   // ZERO-NOT: @llvm.ptrauth.resign
 }
 
-// CHECK-LABEL: define void @test4
+// CHECK-LABEL: define{{.*}} void @test4
 void test4() {
   (*((fptr_t)(&*((char *)(&*(fptr_t)cptr)();
 
@@ -49,7 +51,7 @@ void test4() {
 }
 
 void *vptr;
-// CHECK-LABEL: define void @test5
+// CHECK-LABEL: define{{.*}} void @test5
 void test5() {
   vptr = &*(char *)fptr;
 

diff  --git a/clang/test/CodeGen/ptrauth-function-type-discriminator-cast.c 
b/clang/test/CodeGen/ptrauth-function-type-discriminator-cast.c
index cdf9ee4907525..1a1dce6f4a66e 100644
--- a/clang/test/CodeGen/ptrauth-function-type-discriminator-cast.c
+++ b/clang/test/CodeGen/ptrauth-function-type-discriminator-cast.c
@@ -1,6 +1,20 @@
-// RUN: %clang_cc1 %s -fptrauth-function-pointer-type-discrimination -triple 
arm64e-apple-ios13 -fptrauth-calls -fptrauth-intrinsics -disable-llvm-passes 
-emit-llvm -o- | FileCheck %s --check-prefixes=CHECK,TYPE
-// RUN: %clang_cc1 %s -triple arm64e-apple-ios13 -fptrauth-calls 
-fptrauth-intrinsics -disable-llvm-passes -emit-llvm -o- | FileCheck %s 
--check-prefixes=CHECK,ZERO
-// RUN: %clang_cc1 -xc++ %s -fptrauth-function-pointer-type-discrimination 
-triple arm64e-apple-ios13 -fptrauth-calls -fptrauth-intrinsics 
-disable-llvm-passes -emit-llvm -o- | FileCheck %s 
--check-prefixes=CHECK,CHECKCXX,TYPE,TYPECXX
+// RUN: %clang_cc1 %s -fptrauth-function-pointer-type-discrimination -triple 
arm64e-apple-ios13 -fptrauth-calls -fptrauth-intrinsics \
+// RUN:   -disable-llvm-passes -emit-llvm -o-   | FileCheck %s 
--check-prefixes=CHECK,TYPE
+
+// RUN: %clang_cc1 %s -fptrauth-function-pointer-type-discrimination -triple 
aarch64-linux-gnu  -fptrauth-calls -fptrauth-intrinsics \
+// RUN:   -disable-llvm-passes -emit-llvm -o-   | FileCheck %s 
--check-prefixes=CHECK,TYPE
+
+// RUN: %clang_cc1 %s-triple 
arm64e-apple-ios13 -fptrauth-calls -fptrauth-intrinsics \
+// RUN:   -disable-llvm-passes -emit-llvm -o-   | FileCheck %s 
--check-prefixes=CHECK,ZERO
+
+// RUN: %clang_cc1 %s

[clang-tools-extra] [clang-tidy][cppcoreguidelines-missing-std-forward] Do not warn when the parameter is used in a `static_cast`. (PR #99477)

2024-07-19 Thread Clement Courbet via cfe-commits


@@ -129,15 +129,19 @@ void MissingStdForwardCheck::registerMatchers(MatchFinder 
*Finder) {
   unless(anyOf(hasAncestor(typeLoc()),
hasAncestor(expr(hasUnevaluatedContext());
 
+  auto StaticCast = cxxStaticCastExpr(
+  hasSourceExpression(declRefExpr(to(equalsBoundNode("param");

legrosbuffle wrote:

Unfortunately at that point the cast is a `CK_Dependent` cast. I don't think we 
can get any kind type information from those casts, but I might be wrong.

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


[clang] [Clang][AArch64] Add missing SME/SVE2.1 feature macros (PR #98285)

2024-07-19 Thread via cfe-commits

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


[clang] [clang][analyzer] MmapWriteExecChecker improvements (PR #97078)

2024-07-19 Thread Balázs Kéri via cfe-commits


@@ -21,30 +21,55 @@
 #include "clang/StaticAnalyzer/Core/PathSensitive/CallDescription.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerHelpers.h"
 
 using namespace clang;
 using namespace ento;
 
 namespace {
-class MmapWriteExecChecker : public Checker {
+class MmapWriteExecChecker
+: public Checker {
   CallDescription MmapFn{CDM::CLibrary, {"mmap"}, 6};
   CallDescription MprotectFn{CDM::CLibrary, {"mprotect"}, 3};
-  static int ProtWrite;
-  static int ProtExec;
-  static int ProtRead;
   const BugType BT{this, "W^X check fails, Write Exec prot flags set",
"Security"};
 
+  mutable bool FlagsInitialized = false;
+  mutable int ProtRead = 0x01;
+  mutable int ProtWrite = 0x02;
+  mutable int ProtExec = 0x04;
+
 public:
+  void checkBeginFunction(CheckerContext &C) const;
   void checkPreCall(const CallEvent &Call, CheckerContext &C) const;
+
   int ProtExecOv;
   int ProtReadOv;
 };
 }
 
-int MmapWriteExecChecker::ProtWrite = 0x02;
-int MmapWriteExecChecker::ProtExec  = 0x04;
-int MmapWriteExecChecker::ProtRead  = 0x01;
+void MmapWriteExecChecker::checkBeginFunction(CheckerContext &C) const {
+  if (FlagsInitialized)
+return;
+
+  FlagsInitialized = true;
+
+  const std::optional FoundProtRead =
+  tryExpandAsInteger("PROT_READ", C.getPreprocessor());
+  const std::optional FoundProtWrite =
+  tryExpandAsInteger("PROT_WRITE", C.getPreprocessor());
+  const std::optional FoundProtExec =
+  tryExpandAsInteger("PROT_EXEC", C.getPreprocessor());
+  if (FoundProtRead && FoundProtWrite && FoundProtExec) {
+ProtRead = *FoundProtRead;
+ProtWrite = *FoundProtWrite;
+ProtExec = *FoundProtExec;
+  } else {
+// FIXME: Are these useful?
+ProtRead = ProtReadOv;
+ProtExec = ProtExecOv;

balazske wrote:

My problem was that why is `PROT_WRITE` missing. If the flags are specified it 
is meaningful only to pass all 3 values, otherwise it may cause malfunction of 
the checker. From the test file it looks like that this is only used to swap 
values of `PROT_EXEC` and `PROT_READ`, probably some platforms need this 
specific change. But then a single option `SwapDefaultReadExecFlags` would be 
more useful. I could add a third option for `PROT_WRITE` or remove all of these.

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


[clang] [Clang][AArch64] Add missing SME/SVE2.1 feature macros (PR #98285)

2024-07-19 Thread via cfe-commits

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


[clang] [NFC] [Clang] Some core issues have changed status from tentatively ready -> ready / review (PR #97200)

2024-07-19 Thread via cfe-commits


@@ -153,6 +153,8 @@ void g() {
 namespace cwg2881 { // cwg2881: 19 ready 2024-06-26
 
 #if __cplusplus >= 202302L
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Winaccessible-base"

Sirraide wrote:

This seems rather strange to me. Why are we turning off diagnostics in a test?

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


[clang] [libcxx] [Clang] Add __common_type builtin (PR #99473)

2024-07-19 Thread Nikolas Klauser via cfe-commits

https://github.com/philnik777 updated 
https://github.com/llvm/llvm-project/pull/99473

>From 22513d53967ac32ae4112499c33c7c481b52b2fd Mon Sep 17 00:00:00 2001
From: Nikolas Klauser 
Date: Tue, 16 Jul 2024 14:48:10 +0200
Subject: [PATCH] [Clang] Add __common_type builtin

---
 clang/include/clang/AST/ASTContext.h  |  11 ++
 clang/include/clang/AST/DeclID.h  |   5 +-
 clang/include/clang/Basic/Builtins.h  |   5 +-
 clang/include/clang/Sema/Sema.h   |   4 +
 clang/lib/AST/ASTContext.cpp  |   8 +
 clang/lib/AST/ASTImporter.cpp |   3 +
 clang/lib/AST/DeclTemplate.cpp|  53 ++
 clang/lib/Lex/PPMacroExpansion.cpp|   1 +
 clang/lib/Sema/SemaChecking.cpp   |   8 +
 clang/lib/Sema/SemaLookup.cpp |   4 +
 clang/lib/Sema/SemaTemplate.cpp   | 159 +-
 clang/lib/Serialization/ASTReader.cpp |   3 +
 clang/test/SemaCXX/type-trait-common-type.cpp | 125 ++
 libcxx/include/__type_traits/common_type.h|  10 ++
 14 files changed, 396 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/SemaCXX/type-trait-common-type.cpp

diff --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index 608bd90fcc3ff..d02e742297898 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -399,6 +399,9 @@ class ASTContext : public RefCountedBase {
   /// The identifier '__type_pack_element'.
   mutable IdentifierInfo *TypePackElementName = nullptr;
 
+  /// The identifier '__common_type'.
+  mutable IdentifierInfo *CommonTypeName = nullptr;
+
   QualType ObjCConstantStringType;
   mutable RecordDecl *CFConstantStringTagDecl = nullptr;
   mutable TypedefDecl *CFConstantStringTypeDecl = nullptr;
@@ -606,6 +609,7 @@ class ASTContext : public RefCountedBase {
   mutable ExternCContextDecl *ExternCContext = nullptr;
   mutable BuiltinTemplateDecl *MakeIntegerSeqDecl = nullptr;
   mutable BuiltinTemplateDecl *TypePackElementDecl = nullptr;
+  mutable BuiltinTemplateDecl *CommonTypeDecl = nullptr;
 
   /// The associated SourceManager object.
   SourceManager &SourceMgr;
@@ -1107,6 +,7 @@ class ASTContext : public RefCountedBase {
   ExternCContextDecl *getExternCContextDecl() const;
   BuiltinTemplateDecl *getMakeIntegerSeqDecl() const;
   BuiltinTemplateDecl *getTypePackElementDecl() const;
+  BuiltinTemplateDecl *getCommonTypeDecl() const;
 
   // Builtin Types.
   CanQualType VoidTy;
@@ -1984,6 +1989,12 @@ class ASTContext : public RefCountedBase {
 return TypePackElementName;
   }
 
+  IdentifierInfo *getCommonTypeName() const {
+if (!CommonTypeName)
+  CommonTypeName = &Idents.get("__common_type");
+return CommonTypeName;
+  }
+
   /// Retrieve the Objective-C "instancetype" type, if already known;
   /// otherwise, returns a NULL type;
   QualType getObjCInstanceType() {
diff --git a/clang/include/clang/AST/DeclID.h b/clang/include/clang/AST/DeclID.h
index e5e27389fac60..875e9a72b3951 100644
--- a/clang/include/clang/AST/DeclID.h
+++ b/clang/include/clang/AST/DeclID.h
@@ -84,13 +84,16 @@ enum PredefinedDeclIDs {
 
   /// The internal '__type_pack_element' template.
   PREDEF_DECL_TYPE_PACK_ELEMENT_ID = 17,
+
+  /// The internal '__common_type' template.
+  PREDEF_DECL_COMMON_TYPE_ID = 18,
 };
 
 /// The number of declaration IDs that are predefined.
 ///
 /// For more information about predefined declarations, see the
 /// \c PredefinedDeclIDs type and the PREDEF_DECL_*_ID constants.
-const unsigned int NUM_PREDEF_DECL_IDS = 18;
+const unsigned int NUM_PREDEF_DECL_IDS = 19;
 
 /// GlobalDeclID means DeclID in the current ASTContext and LocalDeclID means
 /// DeclID specific to a certain ModuleFile. Specially, in ASTWriter, the
diff --git a/clang/include/clang/Basic/Builtins.h 
b/clang/include/clang/Basic/Builtins.h
index e85ec5b2dca14..4353b72f71383 100644
--- a/clang/include/clang/Basic/Builtins.h
+++ b/clang/include/clang/Basic/Builtins.h
@@ -309,7 +309,10 @@ enum BuiltinTemplateKind : int {
   BTK__make_integer_seq,
 
   /// This names the __type_pack_element BuiltinTemplateDecl.
-  BTK__type_pack_element
+  BTK__type_pack_element,
+
+  /// This names the __common_type BuiltinTemplateDecl.
+  BTK__common_type,
 };
 
 } // end namespace clang
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 3cb1aa935fe46..5c7945c4c5c58 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -2282,6 +2282,10 @@ class Sema final : public SemaBase {
   /// Check to see if a given expression could have '.c_str()' called on it.
   bool hasCStrMethod(const Expr *E);
 
+  // Check whether a type member 'Type::Name' exists, and if yes, return the
+  // type. If there is no type, the QualType is null
+  QualType getTypeMember(StringRef Name, QualType Type);
+
   /// Diagnose pointers that are always non-null.
   /// \param E the 

[clang] [libc] [libcxx] [libc][libcxx] Support for building libc++ against LLVM libc (PR #99287)

2024-07-19 Thread Petr Hosek via cfe-commits

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


[clang] [Clang] [docs] [MSVC] Add sections on `__forceinline` and intrinsic behaviour differences between Clang and MSVC (PR #99426)

2024-07-19 Thread Max Winkler via cfe-commits


@@ -154,3 +154,133 @@ a hint suggesting how to fix the problem.
 As of this writing, Clang is able to compile a simple ATL hello world
 application.  There are still issues parsing WRL headers for modern Windows 8

MaxEW707 wrote:

Ya its on my todo list to clean this up and to add more details around ABI 
and/or name mangling support.

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


[clang] 3b78dfa - [libc][libcxx] Support for building libc++ against LLVM libc (#99287)

2024-07-19 Thread via cfe-commits

Author: Petr Hosek
Date: 2024-07-18T22:17:42-07:00
New Revision: 3b78dfa10c4b77581cc29c4510aefe919ae660ba

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

LOG: [libc][libcxx] Support for building libc++ against LLVM libc (#99287)

Provide an option to build libc++ against LLVM libc and set the CMake
compile and link options appropriately when the option is enabled.

Added: 
libcxx/cmake/Modules/HandleLibC.cmake

Modified: 
clang/cmake/caches/Fuchsia-stage2.cmake
libcxx/CMakeLists.txt
libcxx/cmake/config-ix.cmake
libcxx/include/CMakeLists.txt
libcxx/src/CMakeLists.txt

Removed: 




diff  --git a/clang/cmake/caches/Fuchsia-stage2.cmake 
b/clang/cmake/caches/Fuchsia-stage2.cmake
index 73ebd36c28496..0218f0b21eb28 100644
--- a/clang/cmake/caches/Fuchsia-stage2.cmake
+++ b/clang/cmake/caches/Fuchsia-stage2.cmake
@@ -339,6 +339,7 @@ foreach(target 
armv6m-unknown-eabi;armv7m-unknown-eabi;armv8m.main-unknown-eabi)
   set(RUNTIMES_${target}_LIBCXX_ENABLE_SHARED OFF CACHE BOOL "")
   set(RUNTIMES_${target}_LIBCXX_ENABLE_STATIC ON CACHE BOOL "")
   set(RUNTIMES_${target}_LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS ON CACHE BOOL "")
+  set(RUNTIMES_${target}_LIBCXX_LIBC "llvm-libc" CACHE STRING "")
   set(RUNTIMES_${target}_LIBCXX_ENABLE_FILESYSTEM OFF CACHE BOOL "")
   set(RUNTIMES_${target}_LIBCXX_ENABLE_RANDOM_DEVICE OFF CACHE BOOL "")
   set(RUNTIMES_${target}_LIBCXX_ENABLE_LOCALIZATION OFF CACHE BOOL "")
@@ -389,6 +390,7 @@ foreach(target riscv32-unknown-elf)
   set(RUNTIMES_${target}_LIBCXX_ENABLE_SHARED OFF CACHE BOOL "")
   set(RUNTIMES_${target}_LIBCXX_ENABLE_STATIC ON CACHE BOOL "")
   set(RUNTIMES_${target}_LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS ON CACHE BOOL "")
+  set(RUNTIMES_${target}_LIBCXX_LIBC "llvm-libc" CACHE STRING "")
   set(RUNTIMES_${target}_LIBCXX_ENABLE_FILESYSTEM OFF CACHE BOOL "")
   set(RUNTIMES_${target}_LIBCXX_ENABLE_RANDOM_DEVICE OFF CACHE BOOL "")
   set(RUNTIMES_${target}_LIBCXX_ENABLE_LOCALIZATION OFF CACHE BOOL "")

diff  --git a/libcxx/CMakeLists.txt b/libcxx/CMakeLists.txt
index 155f81a74a974..332816b15260a 100644
--- a/libcxx/CMakeLists.txt
+++ b/libcxx/CMakeLists.txt
@@ -212,6 +212,14 @@ set(LIBCXX_ABI_DEFINES "" CACHE STRING "A semicolon 
separated list of ABI macros
 set(LIBCXX_EXTRA_SITE_DEFINES "" CACHE STRING "Extra defines to add into 
__config_site")
 option(LIBCXX_USE_COMPILER_RT "Use compiler-rt instead of libgcc" OFF)
 
+# C Library options ---
+
+set(LIBCXX_SUPPORTED_C_LIBRARIES system llvm-libc)
+set(LIBCXX_LIBC "system" CACHE STRING "Specify C library to use. Supported 
values are ${LIBCXX_SUPPORTED_C_LIBRARIES}.")
+if (NOT "${LIBCXX_LIBC}" IN_LIST LIBCXX_SUPPORTED_C_LIBRARIES)
+  message(FATAL_ERROR "Unsupported C library: '${LIBCXX_CXX_ABI}'. Supported 
values are ${LIBCXX_SUPPORTED_C_LIBRARIES}.")
+endif()
+
 # ABI Library options -
 if (MSVC)
   set(LIBCXX_DEFAULT_ABI_LIBRARY "vcruntime")
@@ -495,6 +503,7 @@ endif()
 # Setup Compiler Flags
 
#===
 
+include(HandleLibC) # Setup the C library flags
 include(HandleLibCXXABI) # Setup the ABI library flags
 
 # FIXME(EricWF): See the FIXME on LIBCXX_ENABLE_PEDANTIC.

diff  --git a/libcxx/cmake/Modules/HandleLibC.cmake 
b/libcxx/cmake/Modules/HandleLibC.cmake
new file mode 100644
index 0..1b0564ae6fcc6
--- /dev/null
+++ b/libcxx/cmake/Modules/HandleLibC.cmake
@@ -0,0 +1,39 @@
+#===
+# Define targets for linking against the selected C library
+#
+# After including this file, the following targets are defined:
+# - libcxx-libc-headers: An interface target that allows getting access to the
+#headers of the selected C library.
+# - libcxx-libc-shared: A target representing the selected shared C library.
+# - libcxx-libc-static: A target representing the selected static C library.
+#===
+
+# Link against a system-provided libc
+if (LIBCXX_LIBC STREQUAL "system")
+  add_library(libcxx-libc-headers INTERFACE)
+
+  add_library(libcxx-libc-static INTERFACE)
+  add_library(libcxx-libc-shared INTERFACE)
+
+# Link against the in-tree LLVM libc
+elseif (LIBCXX_LIBC STREQUAL "llvm-libc")
+  add_library(libcxx-libc-headers INTERFACE)
+  target_link_libraries(libcxx-libc-headers INTERFACE libc-headers)
+  if(CXX_SUPPORTS_NOSTDLIBINC_FLAG)
+target_compile_options(libcxx-libc-headers INTERFACE "-nostdlibinc")
+  endif()
+
+  add_library(libcxx-libc-static INTERFACE)
+  if (TARGET libc)
+target_link_libraries(libcxx-libc-

[clang] [NFC] [Clang] Some core issues have changed status from tentatively ready -> ready / review (PR #97200)

2024-07-19 Thread via cfe-commits

https://github.com/Sirraide commented:

The CWG2881 tests LGTM except for one comment.

Imo it’d be better for e.g. @Endilll to approve the pr as a whole since I don’t 
have much experience experience w/ managing DR-related tests.

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


[clang] [NFC] [Clang] Some core issues have changed status from tentatively ready -> ready / review (PR #97200)

2024-07-19 Thread via cfe-commits

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


[clang] [clang] Implement P2582R1: CTAD from inherited constructors (PR #98788)

2024-07-19 Thread Matheus Izvekov via cfe-commits


@@ -1254,8 +1341,221 @@ void DeclareImplicitDeductionGuidesForTypeAlias(
 ->getDeductionCandidateKind() == DeductionCandidate::Aggregate)
   continue;
 
-BuildDeductionGuideForTypeAlias(SemaRef, AliasTemplate, F, Loc);
+BuildDeductionGuideForTypeAlias(SemaRef, AliasTemplate, F, Loc,
+DeducingTemplate, DerivedClassMapperType);
+  }
+}
+
+void DeclareImplicitDeductionGuidesFromInheritedConstructors(
+Sema &SemaRef, TemplateDecl *Template, ClassTemplateDecl *Pattern,
+const CXXBaseSpecifier &Base, unsigned BaseIdx) {
+  auto &Context = SemaRef.Context;
+  DeclContext *DC = Template->getDeclContext();
+  const auto *BaseTST = Base.getType()->getAs();
+  if (!BaseTST)
+return;
+
+  TemplateDecl *BaseTD = BaseTST->getTemplateName().getAsTemplateDecl();
+  if (!BaseTD)
+return;
+
+  // Subsitute any parameters with default arguments not present in the base,
+  // since partial specializations cannot have default parameters
+  TemplateParameterList *TemplateTPL = Pattern->getTemplateParameters();
+  auto BaseDeducedTemplateParams =
+  TemplateParamsReferencedInTemplateArgumentList(
+  TemplateTPL, BaseTST->template_arguments());
+  SmallVector PartialSpecParams;
+  SmallVector SubstArgs;
+  PartialSpecParams.reserve(TemplateTPL->size());
+  SubstArgs.reserve(TemplateTPL->size());
+  LocalInstantiationScope Scope(SemaRef);
+  for (unsigned I = 0, N = TemplateTPL->size(); I < N; ++I) {
+NamedDecl *Param = TemplateTPL->getParam(I);
+if (!BaseDeducedTemplateParams.contains(I)) {
+  if (auto *TTP = dyn_cast(Param);
+  TTP && TTP->hasDefaultArgument()) {
+SubstArgs.push_back(TTP->getDefaultArgument().getArgument());
+continue;
+  }
+
+  if (auto *NTTP = dyn_cast(Param);
+  NTTP && NTTP->hasDefaultArgument()) {
+SubstArgs.push_back(NTTP->getDefaultArgument().getArgument());
+continue;
+  }
+
+  if (auto *TTP = dyn_cast(Param);
+  TTP && TTP->hasDefaultArgument()) {
+SubstArgs.push_back(TTP->getDefaultArgument().getArgument());
+continue;
+  }
+
+  // We have a template parameter that is not present in the base
+  // and does not have a default argument. We create the deduction
+  // guide anyway to display a diagnostic.
+}
+
+MultiLevelTemplateArgumentList Args;
+Args.setKind(TemplateSubstitutionKind::Rewrite);
+Args.addOuterTemplateArguments(SubstArgs);
+Args.addOuterRetainedLevels(Template->getTemplateDepth());
+
+NamedDecl *NewParam = transformTemplateParameter(
+SemaRef, DC, Param, Args, PartialSpecParams.size(),
+Template->getTemplateDepth());
+if (!NewParam)
+  return;
+
+PartialSpecParams.push_back(NewParam);
+SubstArgs.push_back(Context.getInjectedTemplateArg(NewParam));
   }
+
+  Expr *RequiresClause = nullptr;
+  MultiLevelTemplateArgumentList Args;
+  Args.setKind(TemplateSubstitutionKind::Rewrite);
+  Args.addOuterTemplateArguments(SubstArgs);
+  Args.addOuterRetainedLevels(Template->getTemplateDepth());
+  if (Expr *TemplateRC = TemplateTPL->getRequiresClause()) {
+ExprResult E = SemaRef.SubstExpr(TemplateRC, Args);
+if (E.isInvalid())
+  return;
+RequiresClause = E.getAs();
+  }
+  auto *PartialSpecTPL = TemplateParameterList::Create(
+  Context, TemplateTPL->getTemplateLoc(), TemplateTPL->getLAngleLoc(),
+  PartialSpecParams, TemplateTPL->getRAngleLoc(), RequiresClause);
+
+  // [over.match.class.deduct]p1.10
+  // Let A be an alias template whose template parameter list is that of
+  // [Template] and whose defining-type-id is [Base] ...
+  auto *TransformedBase =
+  SemaRef.SubstType(Base.getTypeSourceInfo(), Args, Base.getBaseTypeLoc(),
+DeclarationName(), true);
+  auto *BaseAD = TypeAliasDecl::Create(
+  Context, DC, SourceLocation(), Base.getBaseTypeLoc(),
+  TransformedBase->getType().getBaseTypeIdentifier(), TransformedBase);
+  std::string AliasDeclName =
+  (Twine("__ctad_alias_") + BaseTD->getName() + "_to_" +
+   Template->getName() + "_" + Twine(BaseIdx))
+  .str();
+  IdentifierInfo *AliasIdentifier = &Context.Idents.get(AliasDeclName);
+  auto *BaseATD = TypeAliasTemplateDecl::Create(
+  Context, DC, Base.getBaseTypeLoc(), DeclarationName(AliasIdentifier),
+  PartialSpecTPL, BaseAD);
+  BaseAD->setDescribedAliasTemplate(BaseATD);
+  BaseAD->setImplicit();
+  BaseATD->setImplicit();
+
+  DC->addDecl(BaseATD);
+
+  // ... given a class template `template  class CC;`
+  // whose primary template is not defined ...
+  auto *TParam = TemplateTypeParmDecl::Create(
+  Context, DC, SourceLocation(), SourceLocation(),
+  Template->getTemplateDepth(), 0, nullptr, false, false);
+  auto *MapperTPL = TemplateParameterList::Create(
+  Context, SourceLocation(), SourceLocation(),
+  ArrayRef(TParam), SourceLocation(), nullptr);
--

[clang] [Clang][Sema] Disallow applying `onwership_returns` to functions that return non-pointers (PR #99564)

2024-07-19 Thread via cfe-commits

https://github.com/Sirraide commented:

The implementation in and of itself lgtm, except for two minor comments.

That said, I have never heard of this attribute before, and our documentation 
seems to be rather lacking in this respect. Maybe @AaronBallman has an idea as 
to who might know more about this...

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


[clang] [Clang][Sema] Disallow applying `onwership_returns` to functions that return non-pointers (PR #99564)

2024-07-19 Thread via cfe-commits

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


[clang] [Clang][Sema] Disallow applying `onwership_returns` to functions that return non-pointers (PR #99564)

2024-07-19 Thread via cfe-commits


@@ -1308,6 +1308,10 @@ Crash and bug fixes
 Improvements
 
 
+- Improved handling of ``__attribute__((ownership_returns(class, idx)))``. Now 
clang
+  reports an error if attribute is attached to a function that returns 
non-pointer
+  value

Sirraide wrote:

```suggestion
- Improved the handling of the `ownership_returns` attribute. Now, Clang 
reports an 
  error if the attribute is attached to a function that returns a non-pointer 
value. 
  Fixes (#GH99501)
```

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


[clang] [Clang][Sema] Disallow applying `onwership_returns` to functions that return non-pointers (PR #99564)

2024-07-19 Thread via cfe-commits


@@ -1481,6 +1481,17 @@ static void handleOwnershipAttr(Sema &S, Decl *D, const 
ParsedAttr &AL) {
 break;
   }
 
+  // Allow only pointers to be return type for functions with ownership_takes
+  // attribute. This matches with current OwnershipAttr::Takes semantics
+  if (K == OwnershipAttr::Returns) {

Sirraide wrote:

This comment seems to be talking about `ownership_takes`, and not 
`ownership_returns`?

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


[clang] [llvm] Reapply "Add source file name for template instantiations in -ftime-trace" (PR #99545)

2024-07-19 Thread Ilya Biryukov via cfe-commits

ilya-biryukov wrote:

This still fails on Windows, see the buildkite errors.
I believe the `filename(..., style::posix)` does not do what you intend, it 
actually assumes the inputs are in posix format, which is not the case on 
Windows. You want to use the native style

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


[clang] [llvm] Reapply "Add source file name for template instantiations in -ftime-trace" (PR #99545)

2024-07-19 Thread Ilya Biryukov via cfe-commits


@@ -60,13 +75,29 @@ bool compileFromString(StringRef Code, StringRef Standard, 
StringRef FileName) {
   return Compiler.ExecuteAction(Action);
 }
 
+std::string GetMetadata(json::Object *Event) {
+  std::string Metadata;
+  llvm::raw_string_ostream OS(Metadata);
+  if (json::Object *Args = Event->getObject("args")) {
+if (auto Detail = Args->getString("detail"))
+  OS << Detail;
+if (auto File = Args->getString("file"))
+  OS << ", "
+ << llvm::sys::path::filename(File->str(),

ilya-biryukov wrote:

Could you add a comment that explains that we do this to make the tests outputs 
the same between Windows and Linux?

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


[clang-tools-extra] [clangd] fix crash in include cleaner (PR #99514)

2024-07-19 Thread Yuxuan Shui via cfe-commits

https://github.com/yshui updated https://github.com/llvm/llvm-project/pull/99514

>From 6e5d8d8e04678d80b3139c6d6129da88df57c945 Mon Sep 17 00:00:00 2001
From: Yuxuan Shui 
Date: Thu, 18 Jul 2024 16:07:45 +0100
Subject: [PATCH] [clangd] [IncludeCleaner] Use correct file ID

---
 clang-tools-extra/clangd/CollectMacros.cpp  | 10 +-
 clang-tools-extra/clangd/CollectMacros.h|  1 +
 clang-tools-extra/clangd/IncludeCleaner.cpp |  2 +-
 3 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/clang-tools-extra/clangd/CollectMacros.cpp 
b/clang-tools-extra/clangd/CollectMacros.cpp
index c5ba8d903ba48..83f145d25a5a6 100644
--- a/clang-tools-extra/clangd/CollectMacros.cpp
+++ b/clang-tools-extra/clangd/CollectMacros.cpp
@@ -19,9 +19,8 @@ namespace clang {
 namespace clangd {
 
 Range MacroOccurrence::toRange(const SourceManager &SM) const {
-  auto MainFile = SM.getMainFileID();
   return halfOpenToRange(
-  SM, syntax::FileRange(MainFile, StartOffset, EndOffset).toCharRange(SM));
+  SM, syntax::FileRange(FID, StartOffset, EndOffset).toCharRange(SM));
 }
 
 void CollectMainFileMacros::add(const Token &MacroNameTok, const MacroInfo *MI,
@@ -34,12 +33,13 @@ void CollectMainFileMacros::add(const Token &MacroNameTok, 
const MacroInfo *MI,
 
   auto Name = MacroNameTok.getIdentifierInfo()->getName();
   Out.Names.insert(Name);
-  size_t Start = SM.getFileOffset(Loc);
+  auto [FID, Start] = SM.getDecomposedLoc(Loc);
   size_t End = SM.getFileOffset(MacroNameTok.getEndLoc());
   if (auto SID = getSymbolID(Name, MI, SM))
-Out.MacroRefs[SID].push_back({Start, End, IsDefinition, InIfCondition});
+Out.MacroRefs[SID].push_back(
+{FID, Start, End, IsDefinition, InIfCondition});
   else
-Out.UnknownMacros.push_back({Start, End, IsDefinition, InIfCondition});
+Out.UnknownMacros.push_back({FID, Start, End, IsDefinition, 
InIfCondition});
 }
 
 void CollectMainFileMacros::FileChanged(SourceLocation Loc, FileChangeReason,
diff --git a/clang-tools-extra/clangd/CollectMacros.h 
b/clang-tools-extra/clangd/CollectMacros.h
index e3900c08e5df7..4de49b1be3408 100644
--- a/clang-tools-extra/clangd/CollectMacros.h
+++ b/clang-tools-extra/clangd/CollectMacros.h
@@ -24,6 +24,7 @@ namespace clangd {
 
 struct MacroOccurrence {
   // Half-open range (end offset is exclusive) inside the main file.
+  FileID FID;
   size_t StartOffset;
   size_t EndOffset;
 
diff --git a/clang-tools-extra/clangd/IncludeCleaner.cpp 
b/clang-tools-extra/clangd/IncludeCleaner.cpp
index dc5b7ec95db5f..a739286abbf3d 100644
--- a/clang-tools-extra/clangd/IncludeCleaner.cpp
+++ b/clang-tools-extra/clangd/IncludeCleaner.cpp
@@ -302,7 +302,7 @@ collectMacroReferences(ParsedAST &AST) {
   std::vector Macros;
   for (const auto &[_, Refs] : AST.getMacros().MacroRefs) {
 for (const auto &Ref : Refs) {
-  auto Loc = SM.getComposedLoc(SM.getMainFileID(), Ref.StartOffset);
+  auto Loc = SM.getComposedLoc(Ref.FID, Ref.StartOffset);
   const auto *Tok = AST.getTokens().spelledTokenContaining(Loc);
   if (!Tok)
 continue;

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


[clang] [llvm] [CVP] Infer range return attribute (PR #99620)

2024-07-19 Thread Nikita Popov via cfe-commits

https://github.com/nikic created https://github.com/llvm/llvm-project/pull/99620

We already infer this in IPSCCP, but as that pass runs very early, it cannot 
make use of simplifications (in particular post-inline simplifications).

This fixes most cases from https://github.com/llvm/llvm-project/issues/98946 
(everything apart from f2 where the assume is dropped).

(Draft because there is a significant compile-time regression in lencod ThinLTO 
that I should take a look at first: 
http://llvm-compile-time-tracker.com/compare.php?from=a1d77caaabbb5279b734c061dab36b2138ec476d&to=66f84aa164ca7c42e02c4b1c3ba1b4fb71d6220e&stat=instructions%3Au)

>From 9756800f3f5cbba0f84e2e7b551c2a45b3e70fc9 Mon Sep 17 00:00:00 2001
From: Nikita Popov 
Date: Fri, 19 Jul 2024 11:02:56 +0200
Subject: [PATCH] [CVP] Infer range return attribute

We already infer this in IPSCCP, but as that pass runs very
early, it cannot make use of simplifications (in particular
post-inline simplifications).

This fixes most cases from https://github.com/llvm/llvm-project/issues/98946
(everything apart from f2 where the assume is dropped).
---
 clang/test/CodeGen/attr-counted-by.c  |  8 ++---
 .../Scalar/CorrelatedValuePropagation.cpp | 12 +++
 .../CorrelatedValuePropagation/add.ll |  2 +-
 .../CorrelatedValuePropagation/basic.ll   | 10 +++---
 .../cond-using-block-value.ll |  2 +-
 .../CorrelatedValuePropagation/select.ll  |  6 ++--
 .../CorrelatedValuePropagation/vectors.ll | 34 +--
 7 files changed, 43 insertions(+), 31 deletions(-)

diff --git a/clang/test/CodeGen/attr-counted-by.c 
b/clang/test/CodeGen/attr-counted-by.c
index 32db136076d7d..0fd3d4cc85f83 100644
--- a/clang/test/CodeGen/attr-counted-by.c
+++ b/clang/test/CodeGen/attr-counted-by.c
@@ -639,7 +639,7 @@ void test6(struct anon_struct *p, int index) {
   p->array[index] = __builtin_dynamic_object_size(p->array, 1);
 }
 
-// SANITIZE-WITH-ATTR-LABEL: define dso_local i64 @test6_bdos(
+// SANITIZE-WITH-ATTR-LABEL: define dso_local range(i64 0, -3) i64 @test6_bdos(
 // SANITIZE-WITH-ATTR-SAME: ptr nocapture noundef readonly [[P:%.*]]) 
local_unnamed_addr #[[ATTR2]] {
 // SANITIZE-WITH-ATTR-NEXT:  entry:
 // SANITIZE-WITH-ATTR-NEXT:[[DOT_COUNTED_BY_GEP:%.*]] = getelementptr 
inbounds i8, ptr [[P]], i64 8
@@ -649,7 +649,7 @@ void test6(struct anon_struct *p, int index) {
 // SANITIZE-WITH-ATTR-NEXT:[[TMP1:%.*]] = select i1 [[DOTINV]], i64 0, i64 
[[TMP0]]
 // SANITIZE-WITH-ATTR-NEXT:ret i64 [[TMP1]]
 //
-// NO-SANITIZE-WITH-ATTR-LABEL: define dso_local i64 @test6_bdos(
+// NO-SANITIZE-WITH-ATTR-LABEL: define dso_local range(i64 0, -3) i64 
@test6_bdos(
 // NO-SANITIZE-WITH-ATTR-SAME: ptr nocapture noundef readonly [[P:%.*]]) 
local_unnamed_addr #[[ATTR2]] {
 // NO-SANITIZE-WITH-ATTR-NEXT:  entry:
 // NO-SANITIZE-WITH-ATTR-NEXT:[[DOT_COUNTED_BY_GEP:%.*]] = getelementptr 
inbounds i8, ptr [[P]], i64 8
@@ -955,7 +955,7 @@ void test10(struct union_of_fams *p, int index) {
   p->bytes[index] = (unsigned char)__builtin_dynamic_object_size(p->bytes, 1);
 }
 
-// SANITIZE-WITH-ATTR-LABEL: define dso_local range(i64 -2147483648, 
2147483648) i64 @test10_bdos(
+// SANITIZE-WITH-ATTR-LABEL: define dso_local range(i64 0, 2147483648) i64 
@test10_bdos(
 // SANITIZE-WITH-ATTR-SAME: ptr nocapture noundef readonly [[P:%.*]]) 
local_unnamed_addr #[[ATTR2]] {
 // SANITIZE-WITH-ATTR-NEXT:  entry:
 // SANITIZE-WITH-ATTR-NEXT:[[DOT_COUNTED_BY_GEP:%.*]] = getelementptr 
inbounds i8, ptr [[P]], i64 8
@@ -964,7 +964,7 @@ void test10(struct union_of_fams *p, int index) {
 // SANITIZE-WITH-ATTR-NEXT:[[TMP0:%.*]] = zext nneg i32 [[NARROW]] to i64
 // SANITIZE-WITH-ATTR-NEXT:ret i64 [[TMP0]]
 //
-// NO-SANITIZE-WITH-ATTR-LABEL: define dso_local range(i64 -2147483648, 
2147483648) i64 @test10_bdos(
+// NO-SANITIZE-WITH-ATTR-LABEL: define dso_local range(i64 0, 2147483648) i64 
@test10_bdos(
 // NO-SANITIZE-WITH-ATTR-SAME: ptr nocapture noundef readonly [[P:%.*]]) 
local_unnamed_addr #[[ATTR2]] {
 // NO-SANITIZE-WITH-ATTR-NEXT:  entry:
 // NO-SANITIZE-WITH-ATTR-NEXT:[[DOT_COUNTED_BY_GEP:%.*]] = getelementptr 
inbounds i8, ptr [[P]], i64 8
diff --git a/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp 
b/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
index 95de8eceb6be5..c34fb0746931e 100644
--- a/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
+++ b/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
@@ -1283,6 +1283,18 @@ static bool runImpl(Function &F, LazyValueInfo *LVI, 
DominatorTree *DT,
 RI->replaceUsesOfWith(RetVal, C);
 BBChanged = true;
   }
+  // Infer range attribute on return value.
+  if (RetVal->getType()->isIntOrIntVectorTy()) {
+ConstantRange CR = LVI->getConstantRange(RetVal, RI,
+ /*UndefAllowed=*/false);
+if (!CR.isFullSet()) {
+  Attribute RangeAttr = F.getRetAtt

[clang] [llvm] [CVP] Infer range return attribute (PR #99620)

2024-07-19 Thread Nikita Popov via cfe-commits

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


[clang] [libcxx] [Clang] Add __common_type builtin (PR #99473)

2024-07-19 Thread Nikolas Klauser via cfe-commits

https://github.com/philnik777 updated 
https://github.com/llvm/llvm-project/pull/99473

>From d11417d4addd7a5da5436e9fb406748a3059e17c Mon Sep 17 00:00:00 2001
From: Nikolas Klauser 
Date: Tue, 16 Jul 2024 14:48:10 +0200
Subject: [PATCH] [Clang] Add __common_type builtin

---
 clang/include/clang/AST/ASTContext.h  |  11 ++
 clang/include/clang/AST/DeclID.h  |   5 +-
 clang/include/clang/Basic/Builtins.h  |   5 +-
 clang/include/clang/Sema/Sema.h   |   4 +
 clang/lib/AST/ASTContext.cpp  |   7 +
 clang/lib/AST/ASTImporter.cpp |   3 +
 clang/lib/AST/DeclTemplate.cpp|  53 ++
 clang/lib/Lex/PPMacroExpansion.cpp|   1 +
 clang/lib/Sema/SemaChecking.cpp   |   8 +
 clang/lib/Sema/SemaLookup.cpp |   4 +
 clang/lib/Sema/SemaTemplate.cpp   | 160 +-
 clang/lib/Serialization/ASTReader.cpp |   3 +
 clang/lib/Serialization/ASTWriter.cpp |   2 +
 clang/test/SemaCXX/type-trait-common-type.cpp | 125 ++
 libcxx/include/__type_traits/common_type.h|  16 +-
 15 files changed, 401 insertions(+), 6 deletions(-)
 create mode 100644 clang/test/SemaCXX/type-trait-common-type.cpp

diff --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index 608bd90fcc3ff..d02e742297898 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -399,6 +399,9 @@ class ASTContext : public RefCountedBase {
   /// The identifier '__type_pack_element'.
   mutable IdentifierInfo *TypePackElementName = nullptr;
 
+  /// The identifier '__common_type'.
+  mutable IdentifierInfo *CommonTypeName = nullptr;
+
   QualType ObjCConstantStringType;
   mutable RecordDecl *CFConstantStringTagDecl = nullptr;
   mutable TypedefDecl *CFConstantStringTypeDecl = nullptr;
@@ -606,6 +609,7 @@ class ASTContext : public RefCountedBase {
   mutable ExternCContextDecl *ExternCContext = nullptr;
   mutable BuiltinTemplateDecl *MakeIntegerSeqDecl = nullptr;
   mutable BuiltinTemplateDecl *TypePackElementDecl = nullptr;
+  mutable BuiltinTemplateDecl *CommonTypeDecl = nullptr;
 
   /// The associated SourceManager object.
   SourceManager &SourceMgr;
@@ -1107,6 +,7 @@ class ASTContext : public RefCountedBase {
   ExternCContextDecl *getExternCContextDecl() const;
   BuiltinTemplateDecl *getMakeIntegerSeqDecl() const;
   BuiltinTemplateDecl *getTypePackElementDecl() const;
+  BuiltinTemplateDecl *getCommonTypeDecl() const;
 
   // Builtin Types.
   CanQualType VoidTy;
@@ -1984,6 +1989,12 @@ class ASTContext : public RefCountedBase {
 return TypePackElementName;
   }
 
+  IdentifierInfo *getCommonTypeName() const {
+if (!CommonTypeName)
+  CommonTypeName = &Idents.get("__common_type");
+return CommonTypeName;
+  }
+
   /// Retrieve the Objective-C "instancetype" type, if already known;
   /// otherwise, returns a NULL type;
   QualType getObjCInstanceType() {
diff --git a/clang/include/clang/AST/DeclID.h b/clang/include/clang/AST/DeclID.h
index e5e27389fac60..875e9a72b3951 100644
--- a/clang/include/clang/AST/DeclID.h
+++ b/clang/include/clang/AST/DeclID.h
@@ -84,13 +84,16 @@ enum PredefinedDeclIDs {
 
   /// The internal '__type_pack_element' template.
   PREDEF_DECL_TYPE_PACK_ELEMENT_ID = 17,
+
+  /// The internal '__common_type' template.
+  PREDEF_DECL_COMMON_TYPE_ID = 18,
 };
 
 /// The number of declaration IDs that are predefined.
 ///
 /// For more information about predefined declarations, see the
 /// \c PredefinedDeclIDs type and the PREDEF_DECL_*_ID constants.
-const unsigned int NUM_PREDEF_DECL_IDS = 18;
+const unsigned int NUM_PREDEF_DECL_IDS = 19;
 
 /// GlobalDeclID means DeclID in the current ASTContext and LocalDeclID means
 /// DeclID specific to a certain ModuleFile. Specially, in ASTWriter, the
diff --git a/clang/include/clang/Basic/Builtins.h 
b/clang/include/clang/Basic/Builtins.h
index e85ec5b2dca14..4353b72f71383 100644
--- a/clang/include/clang/Basic/Builtins.h
+++ b/clang/include/clang/Basic/Builtins.h
@@ -309,7 +309,10 @@ enum BuiltinTemplateKind : int {
   BTK__make_integer_seq,
 
   /// This names the __type_pack_element BuiltinTemplateDecl.
-  BTK__type_pack_element
+  BTK__type_pack_element,
+
+  /// This names the __common_type BuiltinTemplateDecl.
+  BTK__common_type,
 };
 
 } // end namespace clang
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 3cb1aa935fe46..5c7945c4c5c58 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -2282,6 +2282,10 @@ class Sema final : public SemaBase {
   /// Check to see if a given expression could have '.c_str()' called on it.
   bool hasCStrMethod(const Expr *E);
 
+  // Check whether a type member 'Type::Name' exists, and if yes, return the
+  // type. If there is no type, the QualType is null
+  QualType getTypeMember(StringRef Name, QualType Type);
+
   /// Diagnose 

[clang] [llvm] Reapply "Add source file name for template instantiations in -ftime-trace" (PR #99545)

2024-07-19 Thread Utkarsh Saxena via cfe-commits

https://github.com/usx95 updated https://github.com/llvm/llvm-project/pull/99545

>From 1047bd2fad795c33c6d228ed117b75025422ddb9 Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Thu, 18 Jul 2024 17:52:10 +
Subject: [PATCH 1/3] Reapply "Add source file name for template instantiations
 in -ftime-trace" (#99534)

This reverts commit 04bcd74df73af6fed16bfd0d6784fc0aec582bc0.
---
 a-abfdec1d.o.tmp  |   0
 clang/docs/ReleaseNotes.rst   |   3 +
 clang/include/clang/Driver/Options.td |   4 +
 .../include/clang/Frontend/FrontendOptions.h  |   8 +-
 clang/lib/Driver/ToolChains/Clang.cpp |   1 +
 clang/lib/Sema/SemaTemplateInstantiate.cpp|  11 +-
 .../lib/Sema/SemaTemplateInstantiateDecl.cpp  |  11 +-
 clang/test/Driver/ftime-trace-sections.cpp|   2 +-
 clang/test/Driver/ftime-trace.cpp |  39 +++---
 clang/tools/driver/cc1_main.cpp   |   3 +-
 clang/unittests/Support/TimeProfilerTest.cpp  | 121 ++
 llvm/include/llvm/Support/TimeProfiler.h  |  23 +++-
 llvm/lib/Support/TimeProfiler.cpp |  61 +++--
 13 files changed, 223 insertions(+), 64 deletions(-)
 create mode 100644 a-abfdec1d.o.tmp

diff --git a/a-abfdec1d.o.tmp b/a-abfdec1d.o.tmp
new file mode 100644
index 0..e69de29bb2d1d
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index e0e86af257a19..971df672b6ca1 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -736,6 +736,9 @@ Improvements to Clang's time-trace
 - Clang now specifies that using ``auto`` in a lambda parameter is a C++14 
extension when
   appropriate. (`#46059: 
`_).
 
+- Clang now adds source file infomation for template instantiations as 
``event["args"]["filename"]``. This
+  added behind an option ``-ftime-trace-verbose``. This is expected to 
increase the size of trace by 2-3 times.
+
 Improvements to Coverage Mapping
 
 
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 1675e435d210c..d3068c1b30a7a 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3988,6 +3988,10 @@ def ftime_trace_granularity_EQ : Joined<["-"], 
"ftime-trace-granularity=">, Grou
   HelpText<"Minimum time granularity (in microseconds) traced by time 
profiler">,
   Visibility<[ClangOption, CC1Option, CLOption, DXCOption]>,
   MarshallingInfoInt, "500u">;
+def ftime_trace_verbose : Joined<["-"], "ftime-trace-verbose">, Group,
+  HelpText<"Make time trace capture verbose event details (e.g. source 
filenames). This can increase the size of the output by 2-3 times">,
+  Visibility<[ClangOption, CC1Option, CLOption, DXCOption]>,
+  MarshallingInfoFlag>;
 def ftime_trace_EQ : Joined<["-"], "ftime-trace=">, Group,
   HelpText<"Similar to -ftime-trace. Specify the JSON file or a directory 
which will contain the JSON file">,
   Visibility<[ClangOption, CC1Option, CLOption, DXCOption]>,
diff --git a/clang/include/clang/Frontend/FrontendOptions.h 
b/clang/include/clang/Frontend/FrontendOptions.h
index 5e5034fe01eb5..8241925c98476 100644
--- a/clang/include/clang/Frontend/FrontendOptions.h
+++ b/clang/include/clang/Frontend/FrontendOptions.h
@@ -580,6 +580,11 @@ class FrontendOptions {
   /// Minimum time granularity (in microseconds) traced by time profiler.
   unsigned TimeTraceGranularity;
 
+  /// Make time trace capture verbose event details (e.g. source filenames).
+  /// This can increase the size of the output by 2-3 times.
+  LLVM_PREFERRED_TYPE(bool)
+  unsigned TimeTraceVerbose : 1;
+
   /// Path which stores the output files for -ftime-trace
   std::string TimeTracePath;
 
@@ -601,7 +606,8 @@ class FrontendOptions {
 EmitSymbolGraph(false), EmitExtensionSymbolGraphs(false),
 EmitSymbolGraphSymbolLabelsForTesting(false),
 EmitPrettySymbolGraphs(false), GenReducedBMI(false),
-UseClangIRPipeline(false), TimeTraceGranularity(500) {}
+UseClangIRPipeline(false), TimeTraceGranularity(500),
+TimeTraceVerbose(false) {}
 
   /// getInputKindForExtension - Return the appropriate input kind for a file
   /// extension. For example, "c" would return Language::C.
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 1fd6fba210042..6b33301d36401 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -6754,6 +6754,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
   if (const char *Name = C.getTimeTraceFile(&JA)) {
 CmdArgs.push_back(Args.MakeArgString("-ftime-trace=" + Twine(Name)));
 Args.AddLastArg(CmdArgs, options::OPT_ftime_trace_granularity_EQ);
+Args.AddLastArg(CmdArgs, options::OPT_ftime_trace_verbose);
   }
 
   if (Arg *A = Args.getLastArg(options::OPT_ftrapv_handler_EQ)) {
diff --git a/clang/lib/Se

[clang] [llvm] Reapply "Add source file name for template instantiations in -ftime-trace" (PR #99545)

2024-07-19 Thread Utkarsh Saxena via cfe-commits


@@ -60,13 +75,29 @@ bool compileFromString(StringRef Code, StringRef Standard, 
StringRef FileName) {
   return Compiler.ExecuteAction(Action);
 }
 
+std::string GetMetadata(json::Object *Event) {
+  std::string Metadata;
+  llvm::raw_string_ostream OS(Metadata);
+  if (json::Object *Args = Event->getObject("args")) {
+if (auto Detail = Args->getString("detail"))
+  OS << Detail;
+if (auto File = Args->getString("file"))
+  OS << ", "
+ << llvm::sys::path::filename(File->str(),

usx95 wrote:

Done.

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


[clang] 5a45fed - [clang][NFC] Fix typo in `-Ofast` deprecation warning

2024-07-19 Thread Vlad Serebrennikov via cfe-commits

Author: Vlad Serebrennikov
Date: 2024-07-19T12:43:52+03:00
New Revision: 5a45fed188dce2ae6c4da23ba61c9b8df87f08f4

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

LOG: [clang][NFC] Fix typo in `-Ofast` deprecation warning

A follow-up for #98736

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticDriverKinds.td
clang/include/clang/Driver/Options.td
clang/test/Driver/Ofast.c

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index 26a9792e6a608..3d8240f8357b4 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -445,7 +445,7 @@ def 
warn_drv_deprecated_arg_no_relaxed_template_template_args : Warning<
   "argument '-fno-relaxed-template-template-args' is deprecated">,
   InGroup;
 def warn_drv_deprecated_arg_ofast : Warning<
-  "argument '-Ofast' is deprecated; use '-O3 -ffast math' for the same 
behavior,"
+  "argument '-Ofast' is deprecated; use '-O3 -ffast-math' for the same 
behavior,"
   " or '-O3' to enable only conforming optimizations">,
   InGroup;
 def warn_drv_deprecated_custom : Warning<

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 12b20fe04675b..fecfa2f3c7dba 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -932,7 +932,7 @@ def O_flag : Flag<["-"], "O">, Visibility<[ClangOption, 
CC1Option, FC1Option]>,
   Alias, AliasArgs<["1"]>;
 def Ofast : Joined<["-"], "Ofast">, Group,
   Visibility<[ClangOption, CC1Option, FlangOption]>,
-  HelpText<"Deprecated; use '-O3 -ffast math' for the same behavior,"
+  HelpText<"Deprecated; use '-O3 -ffast-math' for the same behavior,"
   " or '-O3' to enable only conforming optimizations">;
 def P : Flag<["-"], "P">,
   Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>,

diff  --git a/clang/test/Driver/Ofast.c b/clang/test/Driver/Ofast.c
index 4c63caf9865d5..91de296a4c3ff 100644
--- a/clang/test/Driver/Ofast.c
+++ b/clang/test/Driver/Ofast.c
@@ -10,7 +10,7 @@
 // RUN: %clang -Ofast -fno-strict-aliasing -### %s 2>&1 | FileCheck 
-check-prefix=CHECK-OFAST-NO-STRICT-ALIASING %s
 // RUN: %clang -Ofast -fno-vectorize -### %s 2>&1 | FileCheck 
-check-prefix=CHECK-OFAST-NO-VECTORIZE %s
 
-// CHECK-OFAST: use '-O3 -ffast math' for the same behavior, or '-O3' to 
enable only conforming optimizations
+// CHECK-OFAST: use '-O3 -ffast-math' for the same behavior, or '-O3' to 
enable only conforming optimizations
 // CHECK-OFAST: -cc1
 // CHECK-OFAST-NOT: -relaxed-aliasing
 // CHECK-OFAST: -ffast-math
@@ -25,21 +25,21 @@
 // CHECK-OFAST-O2-NOT: -Ofast
 // CHECK-OFAST-O2: -vectorize-loops
 
-// CHECK-OFAST-NO-FAST-MATH: use '-O3 -ffast math' for the same behavior, or 
'-O3' to enable only conforming optimizations
+// CHECK-OFAST-NO-FAST-MATH: use '-O3 -ffast-math' for the same behavior, or 
'-O3' to enable only conforming optimizations
 // CHECK-OFAST-NO-FAST-MATH: -cc1
 // CHECK-OFAST-NO-FAST-MATH-NOT: -relaxed-aliasing
 // CHECK-OFAST-NO-FAST-MATH-NOT: -ffast-math
 // CHECK-OFAST-NO-FAST-MATH: -Ofast
 // CHECK-OFAST-NO-FAST-MATH: -vectorize-loops
 
-// CHECK-OFAST-NO-STRICT-ALIASING: use '-O3 -ffast math' for the same 
behavior, or '-O3' to enable only conforming optimizations
+// CHECK-OFAST-NO-STRICT-ALIASING: use '-O3 -ffast-math' for the same 
behavior, or '-O3' to enable only conforming optimizations
 // CHECK-OFAST-NO-STRICT-ALIASING: -cc1
 // CHECK-OFAST-NO-STRICT-ALIASING: -relaxed-aliasing
 // CHECK-OFAST-NO-STRICT-ALIASING: -ffast-math
 // CHECK-OFAST-NO-STRICT-ALIASING: -Ofast
 // CHECK-OFAST-NO-STRICT-ALIASING: -vectorize-loops
 
-// CHECK-OFAST-NO-VECTORIZE: use '-O3 -ffast math' for the same behavior, or 
'-O3' to enable only conforming optimizations
+// CHECK-OFAST-NO-VECTORIZE: use '-O3 -ffast-math' for the same behavior, or 
'-O3' to enable only conforming optimizations
 // CHECK-OFAST-NO-VECTORIZE: -cc1
 // CHECK-OFAST-NO-VECTORIZE-NOT: -relaxed-aliasing
 // CHECK-OFAST-NO-VECTORIZE: -ffast-math



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


[clang] [clang] Add deprecation warning for `-Ofast` driver option (PR #98736)

2024-07-19 Thread Vlad Serebrennikov via cfe-commits


@@ -442,6 +442,10 @@ def warn_drv_deprecated_arg : Warning<
 def warn_drv_deprecated_arg_no_relaxed_template_template_args : Warning<
   "argument '-fno-relaxed-template-template-args' is deprecated">,
   InGroup;
+def warn_drv_deprecated_arg_ofast : Warning<
+  "argument '-Ofast' is deprecated; use '-O3 -ffast math' for the same 
behavior,"

Endilll wrote:

Thank you for letting me know. Fixed in 5a45fed188dce2ae6c4da23ba61c9b8df87f08f4

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


[clang] [clang] Add `std::span` to the default gsl pointer annotation list. (PR #99622)

2024-07-19 Thread Haojian Wu via cfe-commits

https://github.com/hokein created 
https://github.com/llvm/llvm-project/pull/99622

None

>From 0fdc7b5dd850c522a7b485d7b6ba8a890739e604 Mon Sep 17 00:00:00 2001
From: Haojian Wu 
Date: Fri, 19 Jul 2024 11:42:44 +0200
Subject: [PATCH] [clang] Add `std::span` to the default gsl pointer annotation
 list.

---
 clang/lib/Sema/SemaAttr.cpp | 1 +
 1 file changed, 1 insertion(+)

diff --git a/clang/lib/Sema/SemaAttr.cpp b/clang/lib/Sema/SemaAttr.cpp
index aaabd989c5c9f..5a7f12c7689d4 100644
--- a/clang/lib/Sema/SemaAttr.cpp
+++ b/clang/lib/Sema/SemaAttr.cpp
@@ -193,6 +193,7 @@ void Sema::inferGslOwnerPointerAttribute(CXXRecordDecl 
*Record) {
   "basic_string_view",
   "reference_wrapper",
   "regex_iterator",
+  "span",
   };
 
   if (!Record->getIdentifier())

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


[clang] [clang] Add `std::span` to the default gsl pointer annotation list. (PR #99622)

2024-07-19 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Haojian Wu (hokein)


Changes



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


1 Files Affected:

- (modified) clang/lib/Sema/SemaAttr.cpp (+1) 


``diff
diff --git a/clang/lib/Sema/SemaAttr.cpp b/clang/lib/Sema/SemaAttr.cpp
index aaabd989c5c9f..5a7f12c7689d4 100644
--- a/clang/lib/Sema/SemaAttr.cpp
+++ b/clang/lib/Sema/SemaAttr.cpp
@@ -193,6 +193,7 @@ void Sema::inferGslOwnerPointerAttribute(CXXRecordDecl 
*Record) {
   "basic_string_view",
   "reference_wrapper",
   "regex_iterator",
+  "span",
   };
 
   if (!Record->getIdentifier())

``




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


[clang] [clang] Add `std::span` to the default gsl pointer annotation list. (PR #99622)

2024-07-19 Thread Gábor Horváth via cfe-commits

https://github.com/Xazax-hun approved this pull request.

LGTM!

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


[clang] [clang] Add `std::span` to the default gsl pointer annotation list. (PR #99622)

2024-07-19 Thread Gábor Horváth via cfe-commits

Xazax-hun wrote:

Hmm. Can/should we also make these const?

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


[clang] [llvm] [CVP] Infer range return attribute (PR #99620)

2024-07-19 Thread Nikita Popov via cfe-commits

https://github.com/nikic updated https://github.com/llvm/llvm-project/pull/99620

>From 23bdf84091020df916441b3ed2d2cc74f4059e37 Mon Sep 17 00:00:00 2001
From: Nikita Popov 
Date: Fri, 19 Jul 2024 11:02:56 +0200
Subject: [PATCH] [CVP] Infer range return attribute

We already infer this in IPSCCP, but as that pass runs very
early, it cannot make use of simplifications (in particular
post-inline simplifications).

This fixes most cases from https://github.com/llvm/llvm-project/issues/98946
(everything apart from f2 where the assume is dropped).
---
 clang/test/CodeGen/attr-counted-by.c  |  8 +-
 .../Scalar/CorrelatedValuePropagation.cpp | 18 +
 .../CorrelatedValuePropagation/add.ll |  2 +-
 .../CorrelatedValuePropagation/ashr.ll|  8 +-
 .../CorrelatedValuePropagation/basic.ll   | 78 +--
 .../cond-using-block-value.ll |  2 +-
 .../CorrelatedValuePropagation/select.ll  |  8 +-
 .../CorrelatedValuePropagation/vectors.ll | 44 +--
 8 files changed, 93 insertions(+), 75 deletions(-)

diff --git a/clang/test/CodeGen/attr-counted-by.c 
b/clang/test/CodeGen/attr-counted-by.c
index 32db136076d7d..0fd3d4cc85f83 100644
--- a/clang/test/CodeGen/attr-counted-by.c
+++ b/clang/test/CodeGen/attr-counted-by.c
@@ -639,7 +639,7 @@ void test6(struct anon_struct *p, int index) {
   p->array[index] = __builtin_dynamic_object_size(p->array, 1);
 }
 
-// SANITIZE-WITH-ATTR-LABEL: define dso_local i64 @test6_bdos(
+// SANITIZE-WITH-ATTR-LABEL: define dso_local range(i64 0, -3) i64 @test6_bdos(
 // SANITIZE-WITH-ATTR-SAME: ptr nocapture noundef readonly [[P:%.*]]) 
local_unnamed_addr #[[ATTR2]] {
 // SANITIZE-WITH-ATTR-NEXT:  entry:
 // SANITIZE-WITH-ATTR-NEXT:[[DOT_COUNTED_BY_GEP:%.*]] = getelementptr 
inbounds i8, ptr [[P]], i64 8
@@ -649,7 +649,7 @@ void test6(struct anon_struct *p, int index) {
 // SANITIZE-WITH-ATTR-NEXT:[[TMP1:%.*]] = select i1 [[DOTINV]], i64 0, i64 
[[TMP0]]
 // SANITIZE-WITH-ATTR-NEXT:ret i64 [[TMP1]]
 //
-// NO-SANITIZE-WITH-ATTR-LABEL: define dso_local i64 @test6_bdos(
+// NO-SANITIZE-WITH-ATTR-LABEL: define dso_local range(i64 0, -3) i64 
@test6_bdos(
 // NO-SANITIZE-WITH-ATTR-SAME: ptr nocapture noundef readonly [[P:%.*]]) 
local_unnamed_addr #[[ATTR2]] {
 // NO-SANITIZE-WITH-ATTR-NEXT:  entry:
 // NO-SANITIZE-WITH-ATTR-NEXT:[[DOT_COUNTED_BY_GEP:%.*]] = getelementptr 
inbounds i8, ptr [[P]], i64 8
@@ -955,7 +955,7 @@ void test10(struct union_of_fams *p, int index) {
   p->bytes[index] = (unsigned char)__builtin_dynamic_object_size(p->bytes, 1);
 }
 
-// SANITIZE-WITH-ATTR-LABEL: define dso_local range(i64 -2147483648, 
2147483648) i64 @test10_bdos(
+// SANITIZE-WITH-ATTR-LABEL: define dso_local range(i64 0, 2147483648) i64 
@test10_bdos(
 // SANITIZE-WITH-ATTR-SAME: ptr nocapture noundef readonly [[P:%.*]]) 
local_unnamed_addr #[[ATTR2]] {
 // SANITIZE-WITH-ATTR-NEXT:  entry:
 // SANITIZE-WITH-ATTR-NEXT:[[DOT_COUNTED_BY_GEP:%.*]] = getelementptr 
inbounds i8, ptr [[P]], i64 8
@@ -964,7 +964,7 @@ void test10(struct union_of_fams *p, int index) {
 // SANITIZE-WITH-ATTR-NEXT:[[TMP0:%.*]] = zext nneg i32 [[NARROW]] to i64
 // SANITIZE-WITH-ATTR-NEXT:ret i64 [[TMP0]]
 //
-// NO-SANITIZE-WITH-ATTR-LABEL: define dso_local range(i64 -2147483648, 
2147483648) i64 @test10_bdos(
+// NO-SANITIZE-WITH-ATTR-LABEL: define dso_local range(i64 0, 2147483648) i64 
@test10_bdos(
 // NO-SANITIZE-WITH-ATTR-SAME: ptr nocapture noundef readonly [[P:%.*]]) 
local_unnamed_addr #[[ATTR2]] {
 // NO-SANITIZE-WITH-ATTR-NEXT:  entry:
 // NO-SANITIZE-WITH-ATTR-NEXT:[[DOT_COUNTED_BY_GEP:%.*]] = getelementptr 
inbounds i8, ptr [[P]], i64 8
diff --git a/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp 
b/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
index 95de8eceb6be5..df899495b8c0c 100644
--- a/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
+++ b/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
@@ -1207,6 +1207,11 @@ static bool processAnd(BinaryOperator *BinOp, 
LazyValueInfo *LVI) {
 static bool runImpl(Function &F, LazyValueInfo *LVI, DominatorTree *DT,
 const SimplifyQuery &SQ) {
   bool FnChanged = false;
+  std::optional RetRange;
+  if (F.getReturnType()->isIntOrIntVectorTy())
+RetRange =
+ConstantRange::getEmpty(F.getReturnType()->getScalarSizeInBits());
+
   // Visiting in a pre-order depth-first traversal causes us to simplify early
   // blocks before querying later blocks (which require us to analyze early
   // blocks).  Eagerly simplifying shallow blocks means there is strictly less
@@ -1277,6 +1282,11 @@ static bool runImpl(Function &F, LazyValueInfo *LVI, 
DominatorTree *DT,
   // constant folding the return values of callees.
   auto *RetVal = RI->getReturnValue();
   if (!RetVal) break; // handle "ret void"
+  if (RetRange && !RetRange->isFullSet())
+RetRange =
+RetRange->unionWith(LVI->getConstan

[clang] [WIP][CLANG][AArch64] Add the modal 8 bit floating-point scalar type (PR #97277)

2024-07-19 Thread via cfe-commits

https://github.com/CarolineConcatto updated 
https://github.com/llvm/llvm-project/pull/97277

>From fbeca5c357b1a5589757bbb2cac8208f8c9027ab Mon Sep 17 00:00:00 2001
From: Caroline Concatto 
Date: Mon, 24 Jun 2024 09:59:24 +
Subject: [PATCH 1/3] [WIP][CLANG][AArch64] Add the  modal 8 bit floating-point
 scalar type

ARM ACLE PR#323[1] adds new modal types for 8-bit floating point intrinsic.

>From the PR#323:
```
ACLE defines the `__fpm8` type, which can be used for the E5M2 and E4M3
8-bit floating-point formats. It is a storage and interchange only type
with no arithmetic operations other than intrinsic calls.


The type should be an opaque type and its format in undefined in Clang.
Only defined in the backend by a status/format register, for AArch64 the FPMR.

This patch is an attempt to the add the fpm8_t scalar type.
It has a parser and codegen for the new scalar type.

The patch it is lowering to and 8bit unsigned as it has no format.
But maybe we should add another opaque type.

[1]  https://github.com/ARM-software/acle/pull/323
---
 clang/include/clang/AST/ASTContext.h  |  1 +
 clang/include/clang/AST/BuiltinTypes.def  |  4 +
 clang/include/clang/AST/Type.h|  5 +
 clang/include/clang/Basic/Specifiers.h|  1 +
 clang/include/clang/Basic/TokenKinds.def  |  1 +
 clang/include/clang/Sema/DeclSpec.h   |  1 +
 .../include/clang/Serialization/ASTBitCodes.h |  4 +-
 clang/lib/AST/ASTContext.cpp  |  7 ++
 clang/lib/AST/ItaniumMangle.cpp   |  1 +
 clang/lib/AST/Type.cpp|  2 +
 clang/lib/AST/TypeLoc.cpp |  1 +
 clang/lib/CodeGen/CodeGenTypes.cpp|  4 +-
 clang/lib/CodeGen/ItaniumCXXABI.cpp   |  1 +
 clang/lib/Index/USRGeneration.cpp |  1 +
 clang/lib/Lex/Lexer.cpp   |  1 +
 clang/lib/Parse/ParseDecl.cpp |  7 ++
 clang/lib/Parse/ParseExpr.cpp |  1 +
 clang/lib/Parse/ParseExprCXX.cpp  |  3 +
 clang/lib/Parse/ParseTentative.cpp|  2 +
 clang/lib/Sema/DeclSpec.cpp   |  3 +
 clang/lib/Sema/SemaTemplateVariadic.cpp   |  1 +
 clang/lib/Sema/SemaType.cpp   |  3 +
 clang/lib/Serialization/ASTCommon.cpp |  3 +
 clang/test/AST/fpm8_opaque.cpp| 91 +++
 clang/test/CodeGen/fpm8_opaque.c  | 24 +
 25 files changed, 171 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/AST/fpm8_opaque.cpp
 create mode 100644 clang/test/CodeGen/fpm8_opaque.c

diff --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index 53ece996769a8..532ec05ab90a6 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -1115,6 +1115,7 @@ class ASTContext : public RefCountedBase {
   CanQualType SatShortFractTy, SatFractTy, SatLongFractTy;
   CanQualType SatUnsignedShortFractTy, SatUnsignedFractTy,
   SatUnsignedLongFractTy;
+  CanQualType Fpm8Ty;
   CanQualType HalfTy; // [OpenCL 6.1.1.1], ARM NEON
   CanQualType BFloat16Ty;
   CanQualType Float16Ty; // C11 extension ISO/IEC TS 18661-3
diff --git a/clang/include/clang/AST/BuiltinTypes.def 
b/clang/include/clang/AST/BuiltinTypes.def
index 444be4311a743..0c1cccf4f73b8 100644
--- a/clang/include/clang/AST/BuiltinTypes.def
+++ b/clang/include/clang/AST/BuiltinTypes.def
@@ -221,6 +221,10 @@ FLOATING_TYPE(Float128, Float128Ty)
 // '__ibm128'
 FLOATING_TYPE(Ibm128, Ibm128Ty)
 
+
+// '__fpm8'
+UNSIGNED_TYPE(Fpm8, Fpm8Ty)
+
 //===- Language-specific types 
===//
 
 // This is the type of C++0x 'nullptr'.
diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index fab233b62d8d1..9f835b8459847 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -2492,6 +2492,7 @@ class alignas(TypeAlignment) Type : public 
ExtQualsTypeCommonBase {
   bool isDoubleType() const;
   bool isBFloat16Type() const;
   bool isFloat128Type() const;
+  bool isFpm8Type() const;
   bool isIbm128Type() const;
   bool isRealType() const; // C99 6.2.5p17 (real floating + integer)
   bool isArithmeticType() const;   // C99 6.2.5p18 (integer + floating)
@@ -7944,6 +7945,10 @@ inline bool Type::isBFloat16Type() const {
   return isSpecificBuiltinType(BuiltinType::BFloat16);
 }
 
+inline bool Type::isFpm8Type() const {
+  return isSpecificBuiltinType(BuiltinType::Fpm8);
+}
+
 inline bool Type::isFloat128Type() const {
   return isSpecificBuiltinType(BuiltinType::Float128);
 }
diff --git a/clang/include/clang/Basic/Specifiers.h 
b/clang/include/clang/Basic/Specifiers.h
index fb11e8212f8b6..b4db94d273949 100644
--- a/clang/include/clang/Basic/Specifiers.h
+++ b/clang/include/clang/Basic/Specifiers.h
@@ -68,6 +68,7 @@ namespace clang {
 TST_Accum,   // ISO/IEC JTC1 SC22 WG14 N1169 Extension
 TST_Fract,
 TST_BFloat16,
+TST_Fpm8,
   

[clang] [clang][ARM64EC] Add support for hybrid_patchable attribute. (PR #99478)

2024-07-19 Thread Jacek Caban via cfe-commits

https://github.com/cjacek updated 
https://github.com/llvm/llvm-project/pull/99478

>From 31584aa0b95dd88df8518bf334fb3e24086b1bdb Mon Sep 17 00:00:00 2001
From: Jacek Caban 
Date: Fri, 3 May 2024 00:27:20 +0200
Subject: [PATCH] [clang][ARM64EC] Add support for hybrid_patchable attribute.

---
 clang/docs/ReleaseNotes.rst   |  3 ++
 clang/include/clang/Basic/Attr.td |  9 +
 clang/include/clang/Basic/AttrDocs.td | 10 ++
 .../clang/Basic/DiagnosticSemaKinds.td|  3 ++
 clang/lib/CodeGen/CodeGenFunction.cpp |  3 ++
 clang/lib/Sema/SemaDecl.cpp   |  5 +++
 clang/lib/Sema/SemaDeclAttr.cpp   |  3 ++
 clang/test/CodeGen/arm64ec-hybrid-patchable.c | 34 +++
 ...a-attribute-supported-attributes-list.test |  1 +
 9 files changed, 71 insertions(+)
 create mode 100644 clang/test/CodeGen/arm64ec-hybrid-patchable.c

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 4efdb076ba768..1c5153f2ecdf6 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -614,6 +614,9 @@ Attribute Changes in Clang
   The attributes declare constraints about a function's behavior pertaining to 
blocking and
   heap memory allocation.
 
+- The ``hybrid_patchable`` attribute is now supported on ARM64EC targets. It 
can be used to specify
+  that a function requires an additional x86-64 thunk, which may be patched at 
runtime.
+
 Improvements to Clang's diagnostics
 ---
 - Clang now emits an error instead of a warning for ``-Wundefined-internal``
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 1293d0ddbc117..7bfda7182a778 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -477,6 +477,9 @@ def TargetELF : TargetSpec {
 def TargetELFOrMachO : TargetSpec {
   let ObjectFormats = ["ELF", "MachO"];
 }
+def TargetWindowsArm64EC : TargetSpec {
+  let CustomCode = [{ Target.getTriple().isWindowsArm64EC() }];
+}
 
 def TargetSupportsInitPriority : TargetSpec {
   let CustomCode = [{ !Target.getTriple().isOSzOS() }];
@@ -4027,6 +4030,12 @@ def SelectAny : InheritableAttr {
   let SimpleHandler = 1;
 }
 
+def HybridPatchable : InheritableAttr, 
TargetSpecificAttr {
+  let Spellings = [Declspec<"hybrid_patchable">, Clang<"hybrid_patchable">];
+  let Subjects = SubjectList<[Function]>;
+  let Documentation = [HybridPatchableDocs];
+}
+
 def Thread : Attr {
   let Spellings = [Declspec<"thread">];
   let LangOpts = [MicrosoftExt];
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 09cf4f80bd999..4d0d49edace26 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -5984,6 +5984,16 @@ For more information see
 or `msvc documentation `_.
 }]; }
 
+def HybridPatchableDocs : Documentation {
+  let Category = DocCatFunction;
+  let Content = [{
+The ``hybrid_patchable`` attribute declares an ARM64EC function with an 
additional
+x86-64 thunk, which may be patched at runtime.
+
+For more information see
+`ARM64EC ABI documentation 
`_.
+}]; }
+
 def WebAssemblyExportNameDocs : Documentation {
   let Category = DocCatFunction;
   let Content = [{
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index d60f32674ca3a..6cb81e4f36118 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3671,6 +3671,9 @@ def err_attribute_weak_static : Error<
   "weak declaration cannot have internal linkage">;
 def err_attribute_selectany_non_extern_data : Error<
   "'selectany' can only be applied to data items with external linkage">;
+def warn_attribute_hybrid_patchable_non_extern : Warning<
+  "'hybrid_patchable' is ignored on functions without external linkage">,
+  InGroup;
 def err_declspec_thread_on_thread_variable : Error<
   "'__declspec(thread)' applied to variable that already has a "
   "thread-local storage specifier">;
diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp 
b/clang/lib/CodeGen/CodeGenFunction.cpp
index 551db09165dbe..99527cf902d55 100644
--- a/clang/lib/CodeGen/CodeGenFunction.cpp
+++ b/clang/lib/CodeGen/CodeGenFunction.cpp
@@ -989,6 +989,9 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, QualType 
RetTy,
   if (D && D->hasAttr())
 Fn->addFnAttr(llvm::Attribute::NoProfile);
 
+  if (D && D->hasAttr())
+Fn->addFnAttr(llvm::Attribute::HybridPatchable);
+
   if (D) {
 // Function attributes take precedence over command line flags.
 if (auto *A = D->getAttr()) {
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index bb25a0b3a45ae..f60cc78be4f92 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -6890,6 +6890,1

[clang] [clang] Fix assertion failure in `injectEmbedTokens` (PR #99624)

2024-07-19 Thread Mariya Podchishchaeva via cfe-commits

https://github.com/Fznamznon created 
https://github.com/llvm/llvm-project/pull/99624

It seems for C++ lexer has some caching ability which doesn't expect injecting 
"new" tokens in the middle of the cache. Technically #embed tokens are not 
completely new since they have already been read from the file and there was 
#embed annotation token in this place, so set `reinject` flag for them to 
silence assertion.

>From 4922e1d4de5ccc9e645b151eb923440573e85fae Mon Sep 17 00:00:00 2001
From: "Podchishchaeva, Mariya" 
Date: Fri, 19 Jul 2024 02:56:38 -0700
Subject: [PATCH] [clang] Fix assertion failure in `injectEmbedTokens`

It seems for C++ lexer has some caching ability which doesn't expect
injecting "new" tokens in the middle of the cache. Technically #embed
tokens are not completely new since they have already been read from the
file and there was #embed annotation token in this place, so set
`reinject` flag for them to silence assertion.
---
 clang/lib/Parse/ParseExpr.cpp   | 2 +-
 clang/test/Preprocessor/embed_weird.cpp | 8 
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Parse/ParseExpr.cpp b/clang/lib/Parse/ParseExpr.cpp
index 3d7c58e5b3c3c..a12c375c8d48c 100644
--- a/clang/lib/Parse/ParseExpr.cpp
+++ b/clang/lib/Parse/ParseExpr.cpp
@@ -3597,7 +3597,7 @@ void Parser::injectEmbedTokens() {
 I += 2;
   }
   PP.EnterTokenStream(std::move(Toks), /*DisableMacroExpansion=*/true,
-  /*IsReinject=*/false);
+  /*IsReinject=*/true);
   ConsumeAnyToken(/*ConsumeCodeCompletionTok=*/true);
 }
 
diff --git a/clang/test/Preprocessor/embed_weird.cpp 
b/clang/test/Preprocessor/embed_weird.cpp
index cc73a88e5a657..f533230111b43 100644
--- a/clang/test/Preprocessor/embed_weird.cpp
+++ b/clang/test/Preprocessor/embed_weird.cpp
@@ -115,3 +115,11 @@ void f1() {
   };
 }
 #endif
+
+static_assert(_Generic(
+#embed __FILE__ limit(1)
+  , int : 1, default : 0));
+
+static_assert(alignof(typeof(
+#embed __FILE__ limit(1)
+)) == alignof(int));

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


[clang] [CLANG][AArch64] Add the modal 8 bit floating-point scalar type (PR #97277)

2024-07-19 Thread via cfe-commits

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


[clang] [clang] Fix assertion failure in `injectEmbedTokens` (PR #99624)

2024-07-19 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Mariya Podchishchaeva (Fznamznon)


Changes

It seems for C++ lexer has some caching ability which doesn't expect injecting 
"new" tokens in the middle of the cache. Technically #embed tokens are not 
completely new since they have already been read from the file and there was 
#embed annotation token in this place, so set `reinject` flag for them to 
silence assertion.

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


2 Files Affected:

- (modified) clang/lib/Parse/ParseExpr.cpp (+1-1) 
- (modified) clang/test/Preprocessor/embed_weird.cpp (+8) 


``diff
diff --git a/clang/lib/Parse/ParseExpr.cpp b/clang/lib/Parse/ParseExpr.cpp
index 3d7c58e5b3c3c..a12c375c8d48c 100644
--- a/clang/lib/Parse/ParseExpr.cpp
+++ b/clang/lib/Parse/ParseExpr.cpp
@@ -3597,7 +3597,7 @@ void Parser::injectEmbedTokens() {
 I += 2;
   }
   PP.EnterTokenStream(std::move(Toks), /*DisableMacroExpansion=*/true,
-  /*IsReinject=*/false);
+  /*IsReinject=*/true);
   ConsumeAnyToken(/*ConsumeCodeCompletionTok=*/true);
 }
 
diff --git a/clang/test/Preprocessor/embed_weird.cpp 
b/clang/test/Preprocessor/embed_weird.cpp
index cc73a88e5a657..f533230111b43 100644
--- a/clang/test/Preprocessor/embed_weird.cpp
+++ b/clang/test/Preprocessor/embed_weird.cpp
@@ -115,3 +115,11 @@ void f1() {
   };
 }
 #endif
+
+static_assert(_Generic(
+#embed __FILE__ limit(1)
+  , int : 1, default : 0));
+
+static_assert(alignof(typeof(
+#embed __FILE__ limit(1)
+)) == alignof(int));

``




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


[clang] [clang] Fix assertion failure in `injectEmbedTokens` (PR #99624)

2024-07-19 Thread via cfe-commits

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


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


[clang] [clang][ARM64EC] Add support for hybrid_patchable attribute. (PR #99478)

2024-07-19 Thread Jacek Caban via cfe-commits


@@ -4027,6 +4030,12 @@ def SelectAny : InheritableAttr {
   let SimpleHandler = 1;
 }
 
+def HybridPatchable : DeclOrTypeAttr, TargetSpecificAttr {
+  let Spellings = [Declspec<"hybrid_patchable">, GCC<"hybrid_patchable">];

cjacek wrote:

Yes, I was thinking mostly about `__attribute__((hybrid_patchable))` as it's 
the form that mingw will mostly likely want to use, so I meant `GNU`. `Clang` 
sounds good to me if proffered, I changed that and added a test for it.

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


[clang] [clang][ARM64EC] Add support for hybrid_patchable attribute. (PR #99478)

2024-07-19 Thread Jacek Caban via cfe-commits


@@ -477,6 +477,9 @@ def TargetELF : TargetSpec {
 def TargetELFOrMachO : TargetSpec {
   let ObjectFormats = ["ELF", "MachO"];
 }
+def TargetArm64EC : TargetSpec {

cjacek wrote:

I renamed it to `TargetWindowsArm64EC` in the new version.

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


[clang] [NFC] [Clang] Some core issues have changed status from tentatively ready -> ready / review (PR #97200)

2024-07-19 Thread Vlad Serebrennikov via cfe-commits


@@ -153,6 +153,8 @@ void g() {
 namespace cwg2881 { // cwg2881: 19 ready 2024-06-26
 
 #if __cplusplus >= 202302L
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Winaccessible-base"

Endilll wrote:

Yes, we shouldn't be using `#pragma clang diagnostic` in DR tests. I'll get rid 
of the few that are left.
If a diagnostic (ideally) should not be emitted, match it and leave a FIXME. If 
diagnostic is correct, you can try to change the test in a way that doesn't 
trigger it, but it's not required.

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


[clang] [clang][ARM64EC] Add support for hybrid_patchable attribute. (PR #99478)

2024-07-19 Thread Jacek Caban via cfe-commits


@@ -4027,6 +4030,12 @@ def SelectAny : InheritableAttr {
   let SimpleHandler = 1;
 }
 
+def HybridPatchable : DeclOrTypeAttr, TargetSpecificAttr {

cjacek wrote:

Right, I don't remember why I did it like that. I changed it in the new version.

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


[clang] [clang][ARM64EC] Add support for hybrid_patchable attribute. (PR #99478)

2024-07-19 Thread Jacek Caban via cfe-commits


@@ -6886,6 +6886,13 @@ static void checkAttributesAfterMerging(Sema &S, 
NamedDecl &ND) {
 }
   }
 
+  if (HybridPatchableAttr *Attr = ND.getAttr()) {
+if (!ND.isExternallyVisible()) {
+  S.Diag(Attr->getLocation(),
+ diag::warn_attribute_hybrid_patchable_non_extern);
+  ND.dropAttr();

cjacek wrote:

Good point, it was a copoy&paste typo. Actually, we don't really need it as 
LLVM part ignores the attribute for static functions itself. I removed that 
line and left only diagnostics part here to slightly simplify the code.

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


[clang] [NFC] [Clang] Some core issues have changed status from tentatively ready -> ready / review (PR #97200)

2024-07-19 Thread Vlad Serebrennikov via cfe-commits

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


[clang] [Clang] [WIP] Added builtin_alloca right Address Space for OpenCL (PR #95750)

2024-07-19 Thread Matt Arsenault via cfe-commits


@@ -1981,6 +1981,23 @@ static bool OpenCLBuiltinToAddr(Sema &S, unsigned 
BuiltinID, CallExpr *Call) {
   return false;
 }
 
+// In OpenCL, __builtin_alloca_* should return a pointer to address space
+// that corresponds to the stack address space i.e private address space.
+static bool OpenCLBuiltinAllocaAddrSpace(Sema &S, CallExpr *TheCall) {
+  QualType RT = TheCall->getType();
+  if (!RT->isPointerType() || RT->getPointeeType().hasAddressSpace())
+return true;
+
+  if (S.getLangOpts().OpenCL) {

arsenm wrote:

Instead could only conditionally call the function if S.getLangOpts().OpenCL

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


[clang] [Clang] [WIP] Added builtin_alloca right Address Space for OpenCL (PR #95750)

2024-07-19 Thread Matt Arsenault via cfe-commits


@@ -1981,6 +1981,29 @@ static bool OpenCLBuiltinToAddr(Sema &S, unsigned 
BuiltinID, CallExpr *Call) {
   return false;
 }
 
+// In OpenCL, __builtin_alloca_* should return a pointer to address space
+// that corresponds to the stack address space i.e private address space.
+static bool OpenCLBuiltinAllocaAddrSpace(Sema &S, CallExpr *TheCall) {

arsenm wrote:

This rename wasn't done. Also should start with lowercase letter 

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


[clang] [Clang] [WIP] Added builtin_alloca right Address Space for OpenCL (PR #95750)

2024-07-19 Thread Matt Arsenault via cfe-commits


@@ -1981,6 +1981,23 @@ static bool OpenCLBuiltinToAddr(Sema &S, unsigned 
BuiltinID, CallExpr *Call) {
   return false;
 }
 
+// In OpenCL, __builtin_alloca_* should return a pointer to address space
+// that corresponds to the stack address space i.e private address space.
+static bool OpenCLBuiltinAllocaAddrSpace(Sema &S, CallExpr *TheCall) {
+  QualType RT = TheCall->getType();
+  if (!RT->isPointerType() || RT->getPointeeType().hasAddressSpace())
+return true;

arsenm wrote:

This could be an assert since you're only calling for the specific set of 
builtins 

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


[clang] [clang] Add `std::span` to the default gsl pointer annotation list. (PR #99622)

2024-07-19 Thread Haojian Wu via cfe-commits

hokein wrote:

> Hmm. Can/should we also make these const?

Yes, I will change them in a follow-up patch.

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


[clang] 42a7c42 - [clang] Add `std::span` to the default gsl pointer annotation list. (#99622)

2024-07-19 Thread via cfe-commits

Author: Haojian Wu
Date: 2024-07-19T13:03:40+02:00
New Revision: 42a7c424b65050c5522e7055ab1486b572d86b69

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

LOG: [clang] Add `std::span` to the default gsl pointer annotation list. 
(#99622)

Added: 


Modified: 
clang/lib/Sema/SemaAttr.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaAttr.cpp b/clang/lib/Sema/SemaAttr.cpp
index aaabd989c5c9f..5a7f12c7689d4 100644
--- a/clang/lib/Sema/SemaAttr.cpp
+++ b/clang/lib/Sema/SemaAttr.cpp
@@ -193,6 +193,7 @@ void Sema::inferGslOwnerPointerAttribute(CXXRecordDecl 
*Record) {
   "basic_string_view",
   "reference_wrapper",
   "regex_iterator",
+  "span",
   };
 
   if (!Record->getIdentifier())



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


[clang] [clang] Add `std::span` to the default gsl pointer annotation list. (PR #99622)

2024-07-19 Thread Haojian Wu via cfe-commits

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


[clang] e404eed - [clang] Add the `const` to all default lists in SemaAttr.cpp, NFC

2024-07-19 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2024-07-19T13:13:01+02:00
New Revision: e404eed24bebd5e3e04fc153eb330bae7d92107f

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

LOG: [clang] Add the `const` to all default lists in SemaAttr.cpp, NFC

Address the comment in 
https://github.com/llvm/llvm-project/pull/99622#issuecomment-2238800532

Added: 


Modified: 
clang/lib/Sema/SemaAttr.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaAttr.cpp b/clang/lib/Sema/SemaAttr.cpp
index 5a7f12c7689d4..b0c239678d0b0 100644
--- a/clang/lib/Sema/SemaAttr.cpp
+++ b/clang/lib/Sema/SemaAttr.cpp
@@ -117,7 +117,7 @@ void Sema::inferGslPointerAttribute(NamedDecl *ND,
   if (!Parent)
 return;
 
-  static llvm::StringSet<> Containers{
+  static const llvm::StringSet<> Containers{
   "array",
   "basic_string",
   "deque",
@@ -137,9 +137,9 @@ void Sema::inferGslPointerAttribute(NamedDecl *ND,
   "unordered_multimap",
   };
 
-  static llvm::StringSet<> Iterators{"iterator", "const_iterator",
- "reverse_iterator",
- "const_reverse_iterator"};
+  static const llvm::StringSet<> Iterators{"iterator", "const_iterator",
+   "reverse_iterator",
+   "const_reverse_iterator"};
 
   if (Parent->isInStdNamespace() && Iterators.count(ND->getName()) &&
   Containers.count(Parent->getName()))
@@ -165,7 +165,7 @@ void Sema::inferGslPointerAttribute(TypedefNameDecl *TD) {
 }
 
 void Sema::inferGslOwnerPointerAttribute(CXXRecordDecl *Record) {
-  static llvm::StringSet<> StdOwners{
+  static const llvm::StringSet<> StdOwners{
   "any",
   "array",
   "basic_regex",
@@ -189,7 +189,7 @@ void Sema::inferGslOwnerPointerAttribute(CXXRecordDecl 
*Record) {
   "unordered_multimap",
   "variant",
   };
-  static llvm::StringSet<> StdPointers{
+  static const llvm::StringSet<> StdPointers{
   "basic_string_view",
   "reference_wrapper",
   "regex_iterator",
@@ -217,7 +217,7 @@ void Sema::inferGslOwnerPointerAttribute(CXXRecordDecl 
*Record) {
 }
 
 void Sema::inferNullableClassAttribute(CXXRecordDecl *CRD) {
-  static llvm::StringSet<> Nullable{
+  static const llvm::StringSet<> Nullable{
   "auto_ptr", "shared_ptr", "unique_ptr", "exception_ptr",
   "coroutine_handle", "function",   "move_only_function",
   };



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


[clang] [BoundsSafety] Add `-fexperimental-bounds-safety` CC1 and language option and use it to tweak `counted_by`'s semantics (PR #92623)

2024-07-19 Thread Dan Liew via cfe-commits

https://github.com/delcypher updated 
https://github.com/llvm/llvm-project/pull/92623

>From 4af270878cb243832f5aeb47c785efa263ba8c78 Mon Sep 17 00:00:00 2001
From: Dan Liew 
Date: Fri, 17 May 2024 17:15:48 -0700
Subject: [PATCH] [Bounds Safety] Add `-fexperimental-bounds-safety` CC1 and
 language option and use it to tweak `counted_by`'s semantics

This adds the `-fexperimental-bounds-safety` CC1 and corresponding
language option. This language option enables "-fbounds-safety" which
is a bounds-safety extension for C that is being incrementally
upstreamed.

This CC1 flag is not exposed as a driver flag yet because most of the
implementation isn't upstream yet.

The language option is used to make a small semantic change to how the
`counted_by` attribute is treated. Without
`-fexperimental-bounds-safety` the attribute is allowed (but emits a
warning) on a flexible array member where the element type is a struct
with a flexible array member. With the flag this situation is an error.

E.g.

```
struct has_unannotated_FAM {
  int count;
  char buffer[];
};

struct buffer_of_structs_with_unnannotated_FAM {
  int count;
  // Forbidden with `-fexperimental-bounds-safety`
  struct has_unannotated_FAM Arr[] __counted_by(count);
};
```

The above code **should always** be an error. However, when #90786 was
originally landed (which allowed `counted_by` to be used on pointers in
structs) it exposed an issue in code in the Linux kernel that was using
the `counted_by` attribute incorrectly (see
https://github.com/llvm/llvm-project/pull/90786#issuecomment-2118416515)
which was now caught by a new error diagnostic in the PR. To unbreak the
build of the Linux kernel the error diagnostic was temporarily
downgraded to be a warning to give the kernel authors time to fix their
code.

This downgrading of the error diagnostic to a warning is a departure
from the intended semantics of `-fbounds-safety` so in order to have
both behaviors (error and warning) it is necessary for Clang to actually
have a notion of `-fbounds-safety` being on vs off.

rdar://125400392
---
 clang/include/clang/Basic/LangOptions.def |  3 ++
 clang/include/clang/Driver/Options.td |  8 
 clang/lib/Sema/SemaDeclAttr.cpp   |  2 +-
 .../Sema/attr-counted-by-bounds-safety-vlas.c | 37 +++
 4 files changed, 49 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/Sema/attr-counted-by-bounds-safety-vlas.c

diff --git a/clang/include/clang/Basic/LangOptions.def 
b/clang/include/clang/Basic/LangOptions.def
index 5ad9c1f24b7c5..a6f36b23f07dc 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -520,6 +520,9 @@ BENIGN_LANGOPT(CheckNew, 1, 0, "Do not assume C++ operator 
new may not return NU
 BENIGN_LANGOPT(CheckConstexprFunctionBodies, 1, 1,
"Emit diagnostics for a constexpr function body that can never "
"be used in a constant expression.")
+
+LANGOPT(BoundsSafety, 1, 0, "Bounds safety extension for C")
+
 #undef LANGOPT
 #undef COMPATIBLE_LANGOPT
 #undef BENIGN_LANGOPT
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index fecfa2f3c7dba..5229940ec8258 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1911,6 +1911,14 @@ def fapinotes_swift_version : Joined<["-"], 
"fapinotes-swift-version=">,
   MetaVarName<"">,
   HelpText<"Specify the Swift version to use when filtering API notes">;
 
+defm bounds_safety : BoolFOption<
+  "experimental-bounds-safety",
+  LangOpts<"BoundsSafety">, DefaultFalse,
+  PosFlag,
+  NegFlag,
+  BothFlags<[], [CC1Option],
+  " experimental bounds safety extension for C">>;
+
 defm addrsig : BoolFOption<"addrsig",
   CodeGenOpts<"Addrsig">, DefaultFalse,
   PosFlag,
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 41295bfb3b94f..f2f3bfcd09035 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -5948,7 +5948,7 @@ CheckCountedByAttrOnField(Sema &S, FieldDecl *FD, Expr *E,
   } else if (PointeeTy->isFunctionType()) {
 InvalidTypeKind = CountedByInvalidPointeeTypeKind::FUNCTION;
   } else if (PointeeTy->isStructureTypeWithFlexibleArrayMember()) {
-if (FieldTy->isArrayType()) {
+if (FieldTy->isArrayType() && !S.getLangOpts().BoundsSafety) {
   // This is a workaround for the Linux kernel that has already adopted
   // `counted_by` on a FAM where the pointee is a struct with a FAM. This
   // should be an error because computing the bounds of the array cannot be
diff --git a/clang/test/Sema/attr-counted-by-bounds-safety-vlas.c 
b/clang/test/Sema/attr-counted-by-bounds-safety-vlas.c
new file mode 100644
index 0..7d9c9a90880ff
--- /dev/null
+++ b/clang/test/Sema/attr-counted-by-bounds-safety-vlas.c
@@ -0,0 +1,37 @@
+// RUN: %clang_cc1 -fsyntax-only -fexperimental-bounds-safety -verify %s
+//
+// This is a porti

[clang] [BoundsSafety] Add `-fexperimental-bounds-safety` CC1 and language option and use it to tweak `counted_by`'s semantics (PR #92623)

2024-07-19 Thread Dan Liew via cfe-commits

delcypher wrote:

@AaronBallman Thanks for approving. I've rebased this patch and tweaked the 
commit message to give the context for this change. Landing now.

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


[clang] [clang][NFC] Move Bounds Safety Sema code to `SemaBoundsSafety.cpp` (PR #99330)

2024-07-19 Thread Dan Liew via cfe-commits

https://github.com/delcypher updated 
https://github.com/llvm/llvm-project/pull/99330

>From 951a2a3bdf2857e789cf484caf9c27633a715cc8 Mon Sep 17 00:00:00 2001
From: Dan Liew 
Date: Wed, 17 Jul 2024 14:53:52 +0100
Subject: [PATCH] [Bounds Safety][NFC] Move Bounds Safety Sema code to
 `SemaBoundsSafety.cpp`

This patch adds a new `SemaBoundsSafety.cpp` source file and moves the
existing `CheckCountedByAttrOnField` function and related helper
functions and types from `SemaDeclAttr.cpp` into the new source file.
The `CheckCountedByAttrOnField` function is now a method on the Sema
class and now has doxygen comments.

The goal behind this refactor is to clearly separate the
`-fbounds-safety` Sema code from everything else.

Although `counted_by(_or_null)` and `sized_by(_or_null)` attributes have
a meaning outside of `-fbounds-safety` it seems reasonable to also have
the Sema logic live in `SemaBoundsSafety.cpp` since the intention is
that the attributes will have the same semantics (but not necessarily
the same enforcement).

As `-fbounds-safety` is upstreamed additional Sema checks will be
added to `SemaBoundsSafety.cpp`.

rdar://131777237
---
 clang/include/clang/Sema/Sema.h |  38 ++
 clang/lib/Sema/CMakeLists.txt   |   1 +
 clang/lib/Sema/SemaBoundsSafety.cpp | 193 
 clang/lib/Sema/SemaDeclAttr.cpp | 177 +
 4 files changed, 233 insertions(+), 176 deletions(-)
 create mode 100644 clang/lib/Sema/SemaBoundsSafety.cpp

diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 3cb1aa935fe46..d638d31e050dc 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -15051,6 +15051,44 @@ class Sema final : public SemaBase {
   void ProcessAPINotes(Decl *D);
 
   ///@}
+
+  //
+  //
+  // -
+  //
+  //
+
+  /// \name Bounds Safety
+  /// Implementations are in SemaBoundsSafety.cpp
+  ///@{
+public:
+  /// Check if applying the specified attribute variant from the "counted by"
+  /// family of attributes to FieldDecl \p FD is semantically valid. If
+  /// semantically invalid diagnostics will be emitted explaining the problems.
+  ///
+  /// \param FD The FieldDecl to apply the attribute to
+  /// \param E The count expression on the attribute
+  /// \param[out] Decls If the attribute is semantically valid \p Decls
+  /// is populated with TypeCoupledDeclRefInfo objects, each
+  /// describing Decls referred to in \p E.
+  /// \param CountInBytes If true the attribute is from the "sized_by" family 
of
+  /// attributes. If the false the attribute is from
+  /// "counted_by" family of attributes.
+  /// \param OrNull If true the attribute is from the "_or_null" suffixed 
family
+  ///   of attributes. If false the attribute does not have the
+  ///   suffix.
+  ///
+  /// Together \p CountInBytes and \p OrNull decide the attribute variant. E.g.
+  /// \p CountInBytes and \p OrNull both being true indicates the
+  /// `counted_by_or_null` attribute.
+  ///
+  /// \returns false iff semantically valid.
+  bool CheckCountedByAttrOnField(
+  FieldDecl *FD, Expr *E,
+  llvm::SmallVectorImpl &Decls, bool CountInBytes,
+  bool OrNull);
+
+  ///@}
 };
 
 DeductionFailureInfo
diff --git a/clang/lib/Sema/CMakeLists.txt b/clang/lib/Sema/CMakeLists.txt
index 5934c8c30daf9..2cee4f5ef6e99 100644
--- a/clang/lib/Sema/CMakeLists.txt
+++ b/clang/lib/Sema/CMakeLists.txt
@@ -36,6 +36,7 @@ add_clang_library(clangSema
   SemaAvailability.cpp
   SemaBPF.cpp
   SemaBase.cpp
+  SemaBoundsSafety.cpp
   SemaCXXScopeSpec.cpp
   SemaCast.cpp
   SemaChecking.cpp
diff --git a/clang/lib/Sema/SemaBoundsSafety.cpp 
b/clang/lib/Sema/SemaBoundsSafety.cpp
new file mode 100644
index 0..290c820938898
--- /dev/null
+++ b/clang/lib/Sema/SemaBoundsSafety.cpp
@@ -0,0 +1,193 @@
+//===-- SemaBoundsSafety.cpp - Bounds Safety specific routines-*- 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
+//
+//===--===//
+/// \file
+/// This file declares semantic analysis functions specific to 
`-fbounds-safety`
+/// (Bounds Safety) and also its attributes when used without `-fbounds-safety`
+/// (e.g. `counted_by`)
+///
+//===--===//
+#include "clang/Sema/Sema.h"
+
+namespace clang {
+
+static CountAttributedType::DynamicCountPointerKind
+getCountAttrKind(bool CountInBytes, bool OrNull) {
+  if (CountInBytes)
+return OrNull ? CountAttributedType::SizedByOrNull
+  : CountAttributedType::SizedBy;
+  return OrNull ? CountAttributedType::CountedByOr

[clang] [clang][NFC] Move Bounds Safety Sema code to `SemaBoundsSafety.cpp` (PR #99330)

2024-07-19 Thread Dan Liew via cfe-commits

delcypher wrote:

Rebased due to the conflict caused by landing #92623

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


[clang] 176bf50 - [clang][NFC] Move Bounds Safety Sema code to `SemaBoundsSafety.cpp` (#99330)

2024-07-19 Thread via cfe-commits

Author: Dan Liew
Date: 2024-07-19T13:06:26+01:00
New Revision: 176bf50cd244505e38f8838a55568060dd3913e8

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

LOG: [clang][NFC] Move Bounds Safety Sema code to `SemaBoundsSafety.cpp` 
(#99330)

This patch adds a new `SemaBoundsSafety.cpp` source file and moves the
existing `CheckCountedByAttrOnField` function and related helper
functions and types from `SemaDeclAttr.cpp` into the new source file.
The `CheckCountedByAttrOnField` function is now a method on the Sema
class and now has doxygen comments.

The goal behind this refactor is to clearly separate the
`-fbounds-safety` Sema code from everything else.

Although `counted_by(_or_null)` and `sized_by(_or_null)` attributes have
a meaning outside of `-fbounds-safety` it seems reasonable to also have
the Sema logic live in `SemaBoundsSafety.cpp` since the intention is
that the attributes will have the same semantics (but not necessarily
the same enforcement).

As `-fbounds-safety` is upstreamed additional Sema checks will be added
to `SemaBoundsSafety.cpp`.

rdar://131777237

Added: 
clang/lib/Sema/SemaBoundsSafety.cpp

Modified: 
clang/include/clang/Sema/Sema.h
clang/lib/Sema/CMakeLists.txt
clang/lib/Sema/SemaDeclAttr.cpp

Removed: 




diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 3cb1aa935fe46..d638d31e050dc 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -15051,6 +15051,44 @@ class Sema final : public SemaBase {
   void ProcessAPINotes(Decl *D);
 
   ///@}
+
+  //
+  //
+  // -
+  //
+  //
+
+  /// \name Bounds Safety
+  /// Implementations are in SemaBoundsSafety.cpp
+  ///@{
+public:
+  /// Check if applying the specified attribute variant from the "counted by"
+  /// family of attributes to FieldDecl \p FD is semantically valid. If
+  /// semantically invalid diagnostics will be emitted explaining the problems.
+  ///
+  /// \param FD The FieldDecl to apply the attribute to
+  /// \param E The count expression on the attribute
+  /// \param[out] Decls If the attribute is semantically valid \p Decls
+  /// is populated with TypeCoupledDeclRefInfo objects, each
+  /// describing Decls referred to in \p E.
+  /// \param CountInBytes If true the attribute is from the "sized_by" family 
of
+  /// attributes. If the false the attribute is from
+  /// "counted_by" family of attributes.
+  /// \param OrNull If true the attribute is from the "_or_null" suffixed 
family
+  ///   of attributes. If false the attribute does not have the
+  ///   suffix.
+  ///
+  /// Together \p CountInBytes and \p OrNull decide the attribute variant. E.g.
+  /// \p CountInBytes and \p OrNull both being true indicates the
+  /// `counted_by_or_null` attribute.
+  ///
+  /// \returns false iff semantically valid.
+  bool CheckCountedByAttrOnField(
+  FieldDecl *FD, Expr *E,
+  llvm::SmallVectorImpl &Decls, bool CountInBytes,
+  bool OrNull);
+
+  ///@}
 };
 
 DeductionFailureInfo

diff  --git a/clang/lib/Sema/CMakeLists.txt b/clang/lib/Sema/CMakeLists.txt
index 5934c8c30daf9..2cee4f5ef6e99 100644
--- a/clang/lib/Sema/CMakeLists.txt
+++ b/clang/lib/Sema/CMakeLists.txt
@@ -36,6 +36,7 @@ add_clang_library(clangSema
   SemaAvailability.cpp
   SemaBPF.cpp
   SemaBase.cpp
+  SemaBoundsSafety.cpp
   SemaCXXScopeSpec.cpp
   SemaCast.cpp
   SemaChecking.cpp

diff  --git a/clang/lib/Sema/SemaBoundsSafety.cpp 
b/clang/lib/Sema/SemaBoundsSafety.cpp
new file mode 100644
index 0..290c820938898
--- /dev/null
+++ b/clang/lib/Sema/SemaBoundsSafety.cpp
@@ -0,0 +1,193 @@
+//===-- SemaBoundsSafety.cpp - Bounds Safety specific routines-*- 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
+//
+//===--===//
+/// \file
+/// This file declares semantic analysis functions specific to 
`-fbounds-safety`
+/// (Bounds Safety) and also its attributes when used without `-fbounds-safety`
+/// (e.g. `counted_by`)
+///
+//===--===//
+#include "clang/Sema/Sema.h"
+
+namespace clang {
+
+static CountAttributedType::DynamicCountPointerKind
+getCountAttrKind(bool CountInBytes, bool OrNull) {
+  if (CountInBytes)
+return OrNull ? CountAttributedType::SizedByOrNull
+  : CountAttributedType::SizedBy;
+  return OrNull ? CountAttributedType::CountedByOrNull
+

[clang] [clang][NFC] Move Bounds Safety Sema code to `SemaBoundsSafety.cpp` (PR #99330)

2024-07-19 Thread Dan Liew via cfe-commits

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


[clang] [clang] Fix underlying type of EmbedExpr (PR #99050)

2024-07-19 Thread Mariya Podchishchaeva via cfe-commits

Fznamznon wrote:

> The one with alignof/typeof asserts for C++ (not for C) and I'd like to make 
> a fix and add this test in a separate PR

Posted https://github.com/llvm/llvm-project/pull/99624 to fix the assertion

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


[clang] [libcxx] [Clang] Add __common_type builtin (PR #99473)

2024-07-19 Thread Nikolas Klauser via cfe-commits

https://github.com/philnik777 updated 
https://github.com/llvm/llvm-project/pull/99473

>From f034248ddb55ff2184662e0558c078f8109c0e00 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser 
Date: Tue, 16 Jul 2024 14:48:10 +0200
Subject: [PATCH] [Clang] Add __common_type builtin

---
 clang/include/clang/AST/ASTContext.h  |  11 ++
 clang/include/clang/AST/DeclID.h  |   5 +-
 clang/include/clang/Basic/Builtins.h  |   5 +-
 clang/include/clang/Sema/Sema.h   |   4 +
 clang/lib/AST/ASTContext.cpp  |   7 +
 clang/lib/AST/ASTImporter.cpp |   3 +
 clang/lib/AST/DeclTemplate.cpp|  53 ++
 clang/lib/Lex/PPMacroExpansion.cpp|   1 +
 clang/lib/Sema/SemaChecking.cpp   |   8 +
 clang/lib/Sema/SemaLookup.cpp |   4 +
 clang/lib/Sema/SemaTemplate.cpp   | 160 +-
 clang/lib/Serialization/ASTReader.cpp |   3 +
 clang/lib/Serialization/ASTWriter.cpp |   2 +
 clang/test/SemaCXX/type-trait-common-type.cpp | 126 ++
 libcxx/include/__type_traits/common_type.h|  16 +-
 libcxx/include/module.modulemap   |   2 +
 16 files changed, 404 insertions(+), 6 deletions(-)
 create mode 100644 clang/test/SemaCXX/type-trait-common-type.cpp

diff --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index 608bd90fcc3ff..d02e742297898 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -399,6 +399,9 @@ class ASTContext : public RefCountedBase {
   /// The identifier '__type_pack_element'.
   mutable IdentifierInfo *TypePackElementName = nullptr;
 
+  /// The identifier '__common_type'.
+  mutable IdentifierInfo *CommonTypeName = nullptr;
+
   QualType ObjCConstantStringType;
   mutable RecordDecl *CFConstantStringTagDecl = nullptr;
   mutable TypedefDecl *CFConstantStringTypeDecl = nullptr;
@@ -606,6 +609,7 @@ class ASTContext : public RefCountedBase {
   mutable ExternCContextDecl *ExternCContext = nullptr;
   mutable BuiltinTemplateDecl *MakeIntegerSeqDecl = nullptr;
   mutable BuiltinTemplateDecl *TypePackElementDecl = nullptr;
+  mutable BuiltinTemplateDecl *CommonTypeDecl = nullptr;
 
   /// The associated SourceManager object.
   SourceManager &SourceMgr;
@@ -1107,6 +,7 @@ class ASTContext : public RefCountedBase {
   ExternCContextDecl *getExternCContextDecl() const;
   BuiltinTemplateDecl *getMakeIntegerSeqDecl() const;
   BuiltinTemplateDecl *getTypePackElementDecl() const;
+  BuiltinTemplateDecl *getCommonTypeDecl() const;
 
   // Builtin Types.
   CanQualType VoidTy;
@@ -1984,6 +1989,12 @@ class ASTContext : public RefCountedBase {
 return TypePackElementName;
   }
 
+  IdentifierInfo *getCommonTypeName() const {
+if (!CommonTypeName)
+  CommonTypeName = &Idents.get("__common_type");
+return CommonTypeName;
+  }
+
   /// Retrieve the Objective-C "instancetype" type, if already known;
   /// otherwise, returns a NULL type;
   QualType getObjCInstanceType() {
diff --git a/clang/include/clang/AST/DeclID.h b/clang/include/clang/AST/DeclID.h
index e5e27389fac60..875e9a72b3951 100644
--- a/clang/include/clang/AST/DeclID.h
+++ b/clang/include/clang/AST/DeclID.h
@@ -84,13 +84,16 @@ enum PredefinedDeclIDs {
 
   /// The internal '__type_pack_element' template.
   PREDEF_DECL_TYPE_PACK_ELEMENT_ID = 17,
+
+  /// The internal '__common_type' template.
+  PREDEF_DECL_COMMON_TYPE_ID = 18,
 };
 
 /// The number of declaration IDs that are predefined.
 ///
 /// For more information about predefined declarations, see the
 /// \c PredefinedDeclIDs type and the PREDEF_DECL_*_ID constants.
-const unsigned int NUM_PREDEF_DECL_IDS = 18;
+const unsigned int NUM_PREDEF_DECL_IDS = 19;
 
 /// GlobalDeclID means DeclID in the current ASTContext and LocalDeclID means
 /// DeclID specific to a certain ModuleFile. Specially, in ASTWriter, the
diff --git a/clang/include/clang/Basic/Builtins.h 
b/clang/include/clang/Basic/Builtins.h
index e85ec5b2dca14..4353b72f71383 100644
--- a/clang/include/clang/Basic/Builtins.h
+++ b/clang/include/clang/Basic/Builtins.h
@@ -309,7 +309,10 @@ enum BuiltinTemplateKind : int {
   BTK__make_integer_seq,
 
   /// This names the __type_pack_element BuiltinTemplateDecl.
-  BTK__type_pack_element
+  BTK__type_pack_element,
+
+  /// This names the __common_type BuiltinTemplateDecl.
+  BTK__common_type,
 };
 
 } // end namespace clang
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 3cb1aa935fe46..5c7945c4c5c58 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -2282,6 +2282,10 @@ class Sema final : public SemaBase {
   /// Check to see if a given expression could have '.c_str()' called on it.
   bool hasCStrMethod(const Expr *E);
 
+  // Check whether a type member 'Type::Name' exists, and if yes, return the
+  // type. If there is no type, the QualType is null
+  QualType getTypeMe

[clang] [clang] Fix underlying type of EmbedExpr (PR #99050)

2024-07-19 Thread Aaron Ballman via cfe-commits

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

LGTM!

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


[clang] [clang] Diagnose use of deprecated template alias (PR #97619)

2024-07-19 Thread Aaron Ballman via cfe-commits

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

LGTM!

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


[clang] 7122b70 - [clang] Fix underlying type of EmbedExpr (#99050)

2024-07-19 Thread via cfe-commits

Author: Mariya Podchishchaeva
Date: 2024-07-19T14:24:05+02:00
New Revision: 7122b70cfc8e23a069410215c363da76d842bda4

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

LOG: [clang] Fix underlying type of EmbedExpr (#99050)

This patch makes remaining cases of #embed to emit int type since there
is an agreement to do that for C. C++ is being discussed, but in general
we don't want to produce different types for C and C++.

Added: 
clang/test/Preprocessor/Inputs/big_char.txt

Modified: 
clang/lib/AST/Expr.cpp
clang/lib/Sema/SemaInit.cpp
clang/test/Preprocessor/embed_codegen.cpp
clang/test/Preprocessor/embed_weird.cpp

Removed: 




diff  --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index 6af1b5683e08b..9d5b8167d0ee6 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -2376,7 +2376,7 @@ APValue SourceLocExpr::EvaluateInContext(const ASTContext 
&Ctx,
 EmbedExpr::EmbedExpr(const ASTContext &Ctx, SourceLocation Loc,
  EmbedDataStorage *Data, unsigned Begin,
  unsigned NumOfElements)
-: Expr(EmbedExprClass, Ctx.UnsignedCharTy, VK_PRValue, OK_Ordinary),
+: Expr(EmbedExprClass, Ctx.IntTy, VK_PRValue, OK_Ordinary),
   EmbedKeywordLoc(Loc), Ctx(&Ctx), Data(Data), Begin(Begin),
   NumOfElements(NumOfElements) {
   setDependence(ExprDependence::None);

diff  --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 17435afab03f4..dc2ba039afe7f 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -2016,7 +2016,7 @@ canInitializeArrayWithEmbedDataString(ArrayRef 
ExprList,
   if (InitType->isArrayType()) {
 const ArrayType *InitArrayType = InitType->getAsArrayTypeUnsafe();
 QualType InitElementTy = InitArrayType->getElementType();
-QualType EmbedExprElementTy = EE->getType();
+QualType EmbedExprElementTy = EE->getDataStringLiteral()->getType();
 const bool TypesMatch =
 Context.typesAreCompatible(InitElementTy, EmbedExprElementTy) ||
 (InitElementTy->isCharType() && EmbedExprElementTy->isCharType());

diff  --git a/clang/test/Preprocessor/Inputs/big_char.txt 
b/clang/test/Preprocessor/Inputs/big_char.txt
new file mode 100644
index 0..ce542efaa5124
--- /dev/null
+++ b/clang/test/Preprocessor/Inputs/big_char.txt
@@ -0,0 +1 @@
+ÿ
\ No newline at end of file

diff  --git a/clang/test/Preprocessor/embed_codegen.cpp 
b/clang/test/Preprocessor/embed_codegen.cpp
index 2cf14d8d6a15d..5baab9b59a9c1 100644
--- a/clang/test/Preprocessor/embed_codegen.cpp
+++ b/clang/test/Preprocessor/embed_codegen.cpp
@@ -14,9 +14,9 @@ int ca[] = {
 };
 
 // CHECK: %arrayinit.element = getelementptr inbounds i32, ptr %notca, i64 1
-// CHECK: store i8 106, ptr %arrayinit.element, align 4
+// CHECK: store i32 106, ptr %arrayinit.element, align 4
 // CHECK: %arrayinit.element1 = getelementptr inbounds i32, ptr %notca, i64 2
-// CHECK: store i8 107, ptr %arrayinit.element1, align 4
+// CHECK: store i32 107, ptr %arrayinit.element1, align 4
 int notca[] = {
 a
 #embed  prefix(,)
@@ -75,9 +75,9 @@ constexpr struct T t[] = {
 // CHECK:  %arrayinit.element7 = getelementptr inbounds %struct.T, ptr %tnonc, 
i64 1
 // CHECK:  call void @llvm.memset.p0.i64(ptr align 4 %arrayinit.element7, i8 
0, i64 20, i1 false)
 // CHECK:  %arr8 = getelementptr inbounds %struct.T, ptr %arrayinit.element7, 
i32 0, i32 0
-// CHECK:  store i8 106, ptr %arr8, align 4
+// CHECK:  store i32 106, ptr %arr8, align 4
 // CHECK:  %arrayinit.element9 = getelementptr inbounds i32, ptr %arr8, i64 1
-// CHECK:  store i8 107, ptr %arrayinit.element9, align 4
+// CHECK:  store i32 107, ptr %arrayinit.element9, align 4
 struct T tnonc[] = {
   a, 300, 1, 2, 3
 #embed  prefix(,)

diff  --git a/clang/test/Preprocessor/embed_weird.cpp 
b/clang/test/Preprocessor/embed_weird.cpp
index cc73a88e5a657..6eb2923152f15 100644
--- a/clang/test/Preprocessor/embed_weird.cpp
+++ b/clang/test/Preprocessor/embed_weird.cpp
@@ -115,3 +115,14 @@ void f1() {
   };
 }
 #endif
+
+struct HasChar {
+  signed char ch;
+};
+
+constexpr struct HasChar c = {
+#embed "Inputs/big_char.txt" // cxx-error {{constant expression evaluates to 
255 which cannot be narrowed to type 'signed char'}} \
+cxx-note {{insert an explicit cast to silence 
this issue}} \
+c-error {{constexpr initializer evaluates to 
255 which is not exactly representable in type 'signed char'}}
+
+};



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


[clang] [clang] Fix underlying type of EmbedExpr (PR #99050)

2024-07-19 Thread Mariya Podchishchaeva via cfe-commits

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


  1   2   3   4   5   >