[PATCH] D149516: [Sema] `setInvalidDecl` for error deduction declaration

2023-05-23 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 updated this revision to Diff 524582.
HerrCai0907 added a comment.

update comment


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149516

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp
  clang/test/CXX/temp/temp.res/temp.local/p3.cpp
  clang/test/Parser/cxx1z-class-template-argument-deduction.cpp
  clang/test/SemaCXX/invalid-deduction-guide-as-template-candidates.cpp

Index: clang/test/SemaCXX/invalid-deduction-guide-as-template-candidates.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/invalid-deduction-guide-as-template-candidates.cpp
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+template  class Foo {}; // expected-note {{candidate template ignored: couldn't infer template argument 'T'}} \
+ // expected-note {{candidate function template not viable: requires 1 argument, but 0 were provided}}
+Foo(); // expected-error {{deduction guide declaration without trailing return type}}
+Foo vs; // expected-error {{no viable constructor or deduction guide for deduction of template arguments of 'Foo'}}
Index: clang/test/Parser/cxx1z-class-template-argument-deduction.cpp
===
--- clang/test/Parser/cxx1z-class-template-argument-deduction.cpp
+++ clang/test/Parser/cxx1z-class-template-argument-deduction.cpp
@@ -241,9 +241,8 @@
 };
 
 struct A2 {
-  template  // expected-note {{non-deducible template parameter 'Ty'}}
+  template 
   B() noexcept(false); // expected-error {{deduction guide must be declared in the same scope as template 'PR49735::B'}} \
-   // expected-error {{deduction guide template contains a template parameter that cannot be deduced}} \
// expected-error {{deduction guide declaration without trailing return type}}
 };
 
Index: clang/test/CXX/temp/temp.res/temp.local/p3.cpp
===
--- clang/test/CXX/temp/temp.res/temp.local/p3.cpp
+++ clang/test/CXX/temp/temp.res/temp.local/p3.cpp
@@ -28,8 +28,7 @@
 
 WebVector(const WebVector& other) { } // expected-error{{undeclared identifier 'T'}} \
 precxx17-error{{a type specifier is required}} \
-cxx17-error{{deduction guide declaration without trailing return type}} \
-cxx17-error{{deduction guide cannot have a function definition}}
+cxx17-error{{deduction guide declaration without trailing return type}}
 
   template 
   WebVector& operator=(const C& other) { } // expected-error{{undeclared identifier 'T'}}
Index: clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp
===
--- clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp
+++ clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp
@@ -173,10 +173,10 @@
 concept g = f::h;
 template 
 concept i = g;
-template  class j { // expected-note {{candidate template ignored}}
+template  class j {
   template 
   requires requires { requires i; }
-  j(); // expected-note {{candidate template ignored}}
+  j();
 };
-template <> j(); // expected-error {{deduction guide declaration without trailing return type}} // expected-error {{no function template}}
+template <> j(); // expected-error {{deduction guide declaration without trailing return type}}
 }
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -11087,8 +11087,8 @@
 /// Check the validity of a declarator that we parsed for a deduction-guide.
 /// These aren't actually declarators in the grammar, so we need to check that
 /// the user didn't specify any pieces that are not part of the deduction-guide
-/// grammar.
-void Sema::CheckDeductionGuideDeclarator(Declarator &D, QualType &R,
+/// grammar. Return true on invalid deduction-guide.
+bool Sema::CheckDeductionGuideDeclarator(Declarator &D, QualType &R,
  StorageClass &SC) {
   TemplateName GuidedTemplate = D.getName().TemplateName.get().get();
   TemplateDecl *GuidedTemplateDecl = GuidedTemplate.getAsTemplateDecl();
@@ -11138,7 +11138,7 @@
   }
 
   if (D.isInvalidType())
-return;
+return true;
 
   // Check the declarator is simple enough.
   bool FoundFunction = false;
@@ -11151,11 +11151,9 @@
   << D.getSourceRange();
   break;
 }
-if (!Chunk.Fun.hasTrailingReturnType()) {
-  Diag(D.getName().get

[clang] eb5902f - [Sema] `setInvalidDecl` for error deduction declaration

2023-05-23 Thread Congcong Cai via cfe-commits

Author: Congcong Cai
Date: 2023-05-23T09:07:05+02:00
New Revision: eb5902ffc97163338bab95d2fd84a953ee76e96f

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

LOG: [Sema] `setInvalidDecl` for error deduction declaration

Fixed: https://github.com/llvm/llvm-project/issues/62408
`setInvalidDecl` for invalid `CXXDeductionGuideDecl` to
avoid crashes during semantic analysis.

Reviewed By: aaron.ballman

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

Added: 
clang/test/SemaCXX/invalid-deduction-guide-as-template-candidates.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaDeclCXX.cpp
clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp
clang/test/CXX/temp/temp.res/temp.local/p3.cpp
clang/test/Parser/cxx1z-class-template-argument-deduction.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 483b2d0110b70..a124617fac8bb 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -397,6 +397,8 @@ Bug Fixes in This Version
 - Fix crash when attempting to perform parenthesized initialization of an
   aggregate with a base class with only non-public constructors.
   (`#62296 `_)
+- Fix crash when handling initialization candidates for invalid deduction 
guide.
+  (`#62408 `_)
 - Fix crash when redefining a variable with an invalid type again with an
   invalid type. (`#62447 `_)
 - Fix a stack overflow issue when evaluating ``consteval`` default arguments.

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index e869117a8ea66..cb38329ca73a5 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -7790,7 +7790,7 @@ class Sema final {
   void CheckConversionDeclarator(Declarator &D, QualType &R,
  StorageClass& SC);
   Decl *ActOnConversionDeclarator(CXXConversionDecl *Conversion);
-  void CheckDeductionGuideDeclarator(Declarator &D, QualType &R,
+  bool CheckDeductionGuideDeclarator(Declarator &D, QualType &R,
  StorageClass &SC);
   void CheckDeductionGuideTemplate(FunctionTemplateDecl *TD);
 

diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index adebfe85be45d..27d76db386f3e 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -9199,8 +9199,8 @@ static FunctionDecl *CreateNewFunctionDecl(Sema &SemaRef, 
Declarator &D,
   SemaRef.Diag(TrailingRequiresClause->getBeginLoc(),
diag::err_trailing_requires_clause_on_deduction_guide)
   << TrailingRequiresClause->getSourceRange();
-SemaRef.CheckDeductionGuideDeclarator(D, R, SC);
-
+if (SemaRef.CheckDeductionGuideDeclarator(D, R, SC))
+  return nullptr;
 return CXXDeductionGuideDecl::Create(SemaRef.Context, DC, D.getBeginLoc(),
  ExplicitSpecifier, NameInfo, R, TInfo,
  D.getEndLoc());

diff  --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index e68afaa61ef1c..150697302c5e1 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -11087,8 +11087,8 @@ struct BadSpecifierDiagnoser {
 /// Check the validity of a declarator that we parsed for a deduction-guide.
 /// These aren't actually declarators in the grammar, so we need to check that
 /// the user didn't specify any pieces that are not part of the deduction-guide
-/// grammar.
-void Sema::CheckDeductionGuideDeclarator(Declarator &D, QualType &R,
+/// grammar. Return true on invalid deduction-guide.
+bool Sema::CheckDeductionGuideDeclarator(Declarator &D, QualType &R,
  StorageClass &SC) {
   TemplateName GuidedTemplate = D.getName().TemplateName.get().get();
   TemplateDecl *GuidedTemplateDecl = GuidedTemplate.getAsTemplateDecl();
@@ -11138,7 +11138,7 @@ void Sema::CheckDeductionGuideDeclarator(Declarator &D, 
QualType &R,
   }
 
   if (D.isInvalidType())
-return;
+return true;
 
   // Check the declarator is simple enough.
   bool FoundFunction = false;
@@ -11151,11 +11151,9 @@ void Sema::CheckDeductionGuideDeclarator(Declarator 
&D, QualType &R,
   << D.getSourceRange();
   break;
 }
-if (!Chunk.Fun.hasTrailingReturnType()) {
-  Diag(D.getName().getBeginLoc(),
+if (!Chunk.Fun.hasTrailingReturnType())
+  return Diag(D.getName().getBeginLoc(),
diag::err_deduction_guide_no_trailing_return_type);
-  break;
-}
 
 //

[PATCH] D149516: [Sema] `setInvalidDecl` for error deduction declaration

2023-05-23 Thread Congcong Cai via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGeb5902ffc971: [Sema] `setInvalidDecl` for error deduction 
declaration (authored by HerrCai0907).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149516

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp
  clang/test/CXX/temp/temp.res/temp.local/p3.cpp
  clang/test/Parser/cxx1z-class-template-argument-deduction.cpp
  clang/test/SemaCXX/invalid-deduction-guide-as-template-candidates.cpp

Index: clang/test/SemaCXX/invalid-deduction-guide-as-template-candidates.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/invalid-deduction-guide-as-template-candidates.cpp
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+template  class Foo {}; // expected-note {{candidate template ignored: couldn't infer template argument 'T'}} \
+ // expected-note {{candidate function template not viable: requires 1 argument, but 0 were provided}}
+Foo(); // expected-error {{deduction guide declaration without trailing return type}}
+Foo vs; // expected-error {{no viable constructor or deduction guide for deduction of template arguments of 'Foo'}}
Index: clang/test/Parser/cxx1z-class-template-argument-deduction.cpp
===
--- clang/test/Parser/cxx1z-class-template-argument-deduction.cpp
+++ clang/test/Parser/cxx1z-class-template-argument-deduction.cpp
@@ -241,9 +241,8 @@
 };
 
 struct A2 {
-  template  // expected-note {{non-deducible template parameter 'Ty'}}
+  template 
   B() noexcept(false); // expected-error {{deduction guide must be declared in the same scope as template 'PR49735::B'}} \
-   // expected-error {{deduction guide template contains a template parameter that cannot be deduced}} \
// expected-error {{deduction guide declaration without trailing return type}}
 };
 
Index: clang/test/CXX/temp/temp.res/temp.local/p3.cpp
===
--- clang/test/CXX/temp/temp.res/temp.local/p3.cpp
+++ clang/test/CXX/temp/temp.res/temp.local/p3.cpp
@@ -28,8 +28,7 @@
 
 WebVector(const WebVector& other) { } // expected-error{{undeclared identifier 'T'}} \
 precxx17-error{{a type specifier is required}} \
-cxx17-error{{deduction guide declaration without trailing return type}} \
-cxx17-error{{deduction guide cannot have a function definition}}
+cxx17-error{{deduction guide declaration without trailing return type}}
 
   template 
   WebVector& operator=(const C& other) { } // expected-error{{undeclared identifier 'T'}}
Index: clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp
===
--- clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp
+++ clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp
@@ -173,10 +173,10 @@
 concept g = f::h;
 template 
 concept i = g;
-template  class j { // expected-note {{candidate template ignored}}
+template  class j {
   template 
   requires requires { requires i; }
-  j(); // expected-note {{candidate template ignored}}
+  j();
 };
-template <> j(); // expected-error {{deduction guide declaration without trailing return type}} // expected-error {{no function template}}
+template <> j(); // expected-error {{deduction guide declaration without trailing return type}}
 }
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -11087,8 +11087,8 @@
 /// Check the validity of a declarator that we parsed for a deduction-guide.
 /// These aren't actually declarators in the grammar, so we need to check that
 /// the user didn't specify any pieces that are not part of the deduction-guide
-/// grammar.
-void Sema::CheckDeductionGuideDeclarator(Declarator &D, QualType &R,
+/// grammar. Return true on invalid deduction-guide.
+bool Sema::CheckDeductionGuideDeclarator(Declarator &D, QualType &R,
  StorageClass &SC) {
   TemplateName GuidedTemplate = D.getName().TemplateName.get().get();
   TemplateDecl *GuidedTemplateDecl = GuidedTemplate.getAsTemplateDecl();
@@ -11138,7 +11138,7 @@
   }
 
   if (D.isInvalidType())
-return;
+return true;
 
   // Check the declarator is simple enough.
   bool FoundFunction = false;
@@ 

[PATCH] D139837: [Clang] Implements CTAD for aggregates P1816R0 and P2082R1

2023-05-23 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added a comment.

Thanks, It's great to have the complete feature in on PR




Comment at: clang/include/clang/Sema/Sema.h:9661
+struct BuildingDeductionGuides {};
+/// Note that we are instantiating an exception specification
+/// of a function template.

Is that comment correct?



Comment at: clang/lib/Sema/SemaDecl.cpp:12637
 
-  if (DirectInit) {
-if (auto *PL = dyn_cast_or_null(Init))
-  DeduceInits = PL->exprs();
-  }
+  auto *PL = dyn_cast_or_null(Init);
+  if (DirectInit && PL)





Comment at: clang/lib/Sema/SemaTemplateInstantiate.cpp:1059-1062
+case CodeSynthesisContext::BuildingDeductionGuides:
+  assert(
+  false &&
+  "failed building deduction guides, add meaningful diagnostics here");

This seems unfinished


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139837

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


[PATCH] D150635: [clangd] Implement end-definition-comment inlay hints

2023-05-23 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

> Though I'm proposing a name like "DeclBlockEnd" to make it clearer

I prefer the current name. DeclBlockEnd is both too long and contains a cryptic 
abbreviation (should be DeclarationBlockEnd). And I don't think distinguishing 
between declaration blocks and flow-control blocks is likely to be helpful.




Comment at: clang-tools-extra/clangd/InlayHints.cpp:783
+// Note this range doesn't include the trailing ';' in type definitions.
+// So we have to add SkippedChars to the end character.
+SourceRange R = D.getSourceRange();

daiyousei-qz wrote:
> sammccall wrote:
> > This is too much arithmetic and fiddly coupling between this function and 
> > shouldHintEndDefinitionComment.
> > 
> > Among other things, it allows for confusion between unicode characters 
> > (UTF-32), clang bytes (UTF-8), and LSP characters (usually UTF-16). And we 
> > do have a bug here: shouldHintEndDefinition provides SkippedChars in clang 
> > bytes, but you add it to end.character below which is in LSP characters.
> > 
> > ---
> > 
> > Let's redesign a little... 
> > 
> > We have a `}` on some line. We want to compute a sensible part of that line 
> > to attach to.
> > A suitable range may not exist, in which case we're going to omit the hint.
> > 
> > - The line consists of text we don't care about , the `}`, and then some 
> > mix of whitespace, "trivial" punctuation, and "nontrivial" chars.
> > - the range should always start at the `}`, since that's what we're really 
> > hinting
> > - to get the hint in the right place, the range should end after the 
> > trivial chars, but before any trailing whitespace
> > - if there are any nontrivial chars, there's no suitable range
> > 
> > so something like:
> > 
> > ```
> > optional findBraceTargetRange(SourceLocation CloseBrace) {
> >   auto [File, Offset] = SM.getDecomposedLoc(SM.getFileLoc(CloseBrace));
> >   if (File != MainFileID) return std::nullopt;
> >   StringRef RestOfLine = 
> > MainFileBuf.substr(Offset).split('\n').first.rtrim();
> >   if (!RestOfLine.consume_front("{")) return;
> >   if (StringRef::npos != Punctuation.find_first_of(" ,;")) return 
> > std::nullopt;
> >   return {offsetToPosition(MainFileBuf, Offset), 
> > offsetToPosition(MainFileBuf, Result.bytes_end() - MainFileBuf.bytes_end()};
> > }
> > ```
> > 
> > and then call from addEndDefinitionComment, the result is LSPRange already.
> Done, also moved min-line and max-length logic to this function. Btw, I think 
> we should avoid `offsetToPosition` as much as possible. It is a large 
> overhead considering inlay hints are recomputed throughout the entire file 
> for each edit. I frequently work with source code that's nearly 1MB large 
> (Yes, I don't think we should have source file this large, but it is what it 
> is).
> also moved min-line and max-length logic to this function

I'd prefer you to move them back. As specified, that function is otherwise 
strictly about examining the textual source code around the closing brace. Now 
it's muddled: it also looks at the opening brace, and does lookups into line 
tables.

You seem to be aiming to optimize an operation that you think is expensive, but 
I don't see any evidence (measurements) that this implementation is actually 
faster or that the difference matters.

> Btw, I think we should avoid offsetToPosition as much as possible

I understand the concern: computing inlay hints is quadratic. However things 
are *universally* done this way in clangd, and diverging here won't 
significantly improve performance but makes the code much harder to understand 
in context.

In practice we haven't found places where overheads that are 
length(file)*length(LSP response) are significant compared to parse times. If 
you have such examples, it would be great to gather & share profiles and 
propose a solution.
I suspect we could maintain some line lookup data structure that gets updated 
when source code updates come in over LSP, or something. But micro-optimizing 
individual codepaths isn't going to get us there: if two offsetToPosition() 
calls are bad, then one is still bad.



Comment at: clang-tools-extra/clangd/InlayHints.cpp:575
+  // Otherwise, the hint shouldn't be shown.
+  std::optional computeBlockEndHintRange(SourceRange BraceRange,
+StringRef OptionalPunctuation) 
{

can you move this function below the related `addBlockEndHint`?



Comment at: clang-tools-extra/clangd/InlayHints.cpp:578
+constexpr unsigned HintMinLineLimit = 2;
+constexpr unsigned HintMaxLengthLimit = 50;
+

We actually already have a configurable inlay hint length limit.
It has the wrong name (`TypeNameLimit`) , but I think we should use it anyway 
(and maybe try to fix the name later).

(I'm not sure making this configurable was a great idea, but given that it 
exists, people will expect it to effe

[PATCH] D151183: [clang][dataflow] Add a `ControlFlowContext::build()` overload taking a `FunctionDecl`.

2023-05-23 Thread Martin Böhme via Phabricator via cfe-commits
mboehme created this revision.
Herald added subscribers: martong, xazax.hun.
Herald added a reviewer: NoQ.
Herald added a project: All.
mboehme requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This is the most common use case, so it makes sense to have a specific overload
for it.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D151183

Files:
  clang/include/clang/Analysis/FlowSensitive/ControlFlowContext.h
  clang/lib/Analysis/FlowSensitive/ControlFlowContext.cpp
  clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
  clang/unittests/Analysis/FlowSensitive/TestingSupport.h
  clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp


Index: clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
@@ -67,8 +67,8 @@
   Stmt *Body = Func->getBody();
   assert(Body != nullptr);
 
-  auto CFCtx = llvm::cantFail(
-  ControlFlowContext::build(*Func, *Body, AST->getASTContext()));
+  auto CFCtx =
+  llvm::cantFail(ControlFlowContext::build(*Func, AST->getASTContext()));
 
   AnalysisT Analysis = MakeAnalysis(AST->getASTContext());
   DataflowAnalysisContext DACtx(std::make_unique());
Index: clang/unittests/Analysis/FlowSensitive/TestingSupport.h
===
--- clang/unittests/Analysis/FlowSensitive/TestingSupport.h
+++ clang/unittests/Analysis/FlowSensitive/TestingSupport.h
@@ -241,8 +241,7 @@
   llvm::errc::invalid_argument, "Could not find the target function.");
 
 // Build the control flow graph for the target function.
-auto MaybeCFCtx =
-ControlFlowContext::build(*Target, *Target->getBody(), Context);
+auto MaybeCFCtx = ControlFlowContext::build(*Target, Context);
 if (!MaybeCFCtx) return MaybeCFCtx.takeError();
 auto &CFCtx = *MaybeCFCtx;
 
Index: clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
===
--- clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
+++ clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
@@ -210,8 +210,8 @@
   if (It != FunctionContexts.end())
 return &It->second;
 
-  if (Stmt *Body = F->getBody()) {
-auto CFCtx = ControlFlowContext::build(*F, *Body, F->getASTContext());
+  if (F->hasBody()) {
+auto CFCtx = ControlFlowContext::build(*F, F->getASTContext());
 // FIXME: Handle errors.
 assert(CFCtx);
 auto Result = FunctionContexts.insert({F, std::move(*CFCtx)});
Index: clang/lib/Analysis/FlowSensitive/ControlFlowContext.cpp
===
--- clang/lib/Analysis/FlowSensitive/ControlFlowContext.cpp
+++ clang/lib/Analysis/FlowSensitive/ControlFlowContext.cpp
@@ -67,6 +67,16 @@
   return BlockReachable;
 }
 
+llvm::Expected
+ControlFlowContext::build(const FunctionDecl &Func, ASTContext &C) {
+  if (!Func.hasBody())
+return llvm::createStringError(
+std::make_error_code(std::errc::invalid_argument),
+"Cannot analyze function without a body");
+
+  return build(Func, *Func.getBody(), C);
+}
+
 llvm::Expected
 ControlFlowContext::build(const Decl &D, Stmt &S, ASTContext &C) {
   if (D.isTemplated())
Index: clang/include/clang/Analysis/FlowSensitive/ControlFlowContext.h
===
--- clang/include/clang/Analysis/FlowSensitive/ControlFlowContext.h
+++ clang/include/clang/Analysis/FlowSensitive/ControlFlowContext.h
@@ -31,6 +31,11 @@
 /// analysis.
 class ControlFlowContext {
 public:
+  /// Builds a ControlFlowContext from a `FunctionDecl`.
+  /// `Func.hasBody()` must be true, and `Func.isTemplated()` must be false.
+  static llvm::Expected build(const FunctionDecl &Func,
+  ASTContext &C);
+
   /// Builds a ControlFlowContext from an AST node. `D` is the function in 
which
   /// `S` resides. `D.isTemplated()` must be false.
   static llvm::Expected build(const Decl &D, Stmt &S,


Index: clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
@@ -67,8 +67,8 @@
   Stmt *Body = Func->getBody();
   assert(Body != nullptr);
 
-  auto CFCtx = llvm::cantFail(
-  ControlFlowContext::build(*Func, *Body, AST->getASTContext()));
+  auto CFCtx =
+  llvm::cantFail(ControlFlowContext::build(*Func, AST->getASTContext()));
 
   AnalysisT Analysis = MakeAnalysis(AST->getASTContext());
   DataflowAnalysisContext DACtx(std::make_unique(

[PATCH] D150427: [AMDGPU] Non hostcall printf support for HIP

2023-05-23 Thread Vikram Hegde via Phabricator via cfe-commits
vikramRH updated this revision to Diff 524590.
vikramRH added a comment.

Handled review comments and rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150427

Files:
  clang/include/clang/Basic/TargetOptions.h
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/CGGPUBuiltin.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/CodeGenHIP/printf_nonhostcall.cpp
  clang/test/Driver/hip-options.hip
  llvm/include/llvm/Transforms/Utils/AMDGPUEmitPrintf.h
  llvm/lib/Transforms/Utils/AMDGPUEmitPrintf.cpp

Index: llvm/lib/Transforms/Utils/AMDGPUEmitPrintf.cpp
===
--- llvm/lib/Transforms/Utils/AMDGPUEmitPrintf.cpp
+++ llvm/lib/Transforms/Utils/AMDGPUEmitPrintf.cpp
@@ -17,6 +17,8 @@
 #include "llvm/Transforms/Utils/AMDGPUEmitPrintf.h"
 #include "llvm/ADT/SparseBitVector.h"
 #include "llvm/Analysis/ValueTracking.h"
+#include "llvm/Support/DataExtractor.h"
+#include "llvm/Support/MD5.h"
 
 using namespace llvm;
 
@@ -179,11 +181,7 @@
 
 // Scan the format string to locate all specifiers, and mark the ones that
 // specify a string, i.e, the "%s" specifier with optional '*' characters.
-static void locateCStrings(SparseBitVector<8> &BV, Value *Fmt) {
-  StringRef Str;
-  if (!getConstantStringInfo(Fmt, Str) || Str.empty())
-return;
-
+static void locateCStrings(SparseBitVector<8> &BV, StringRef Str) {
   static const char ConvSpecifiers[] = "diouxXfFeEgGaAcspn";
   size_t SpecPos = 0;
   // Skip the first argument, the format string.
@@ -207,14 +205,303 @@
   }
 }
 
-Value *llvm::emitAMDGPUPrintfCall(IRBuilder<> &Builder,
-  ArrayRef Args) {
+// helper struct to package the string related data
+struct StringData {
+  std::string Str = "";
+  bool isConst = true;
+  Value *RealSize = nullptr;
+  Value *AlignedSize = nullptr;
+
+  StringData(std::string str, bool IC, Value *RS, Value *AS)
+  : Str(str), isConst(IC), RealSize(RS), AlignedSize(AS) {}
+};
+
+static inline size_t alignUp(size_t Value, uint Alignment) {
+  return (Value + Alignment - 1) & ~(Alignment - 1);
+}
+
+// Calculates frame size required for current printf expansion and allocates
+// space on printf buffer. Printf frame includes following contents
+// [ ControlDWord , format string/Hash , Arguments (each aligned to 8 byte) ]
+static Value *callBufferedPrintfStart(
+IRBuilder<> &Builder, ArrayRef &Args, Value *Fmt,
+bool isConstFmtStr, SparseBitVector<8> &SpecIsCString,
+SmallVectorImpl &StringContents, Value *&ArgSize) {
+  Value *NonConstStrLen = nullptr;
+
+  // First 4 bytes to be reserved for control dword
+  size_t BufSize = 4;
+  if (isConstFmtStr)
+// First 8 bytes of MD5 hash
+BufSize += 8;
+  else {
+auto LenWithNull = getStrlenWithNull(Builder, Fmt);
+
+// Align the computed length to next 8 byte boundary
+auto TempAdd = Builder.CreateAdd(
+LenWithNull, ConstantInt::get(LenWithNull->getType(), 7U));
+NonConstStrLen = Builder.CreateAnd(
+TempAdd, ConstantInt::get(LenWithNull->getType(), ~7U));
+
+StringContents.push_back(
+StringData("", false, LenWithNull, NonConstStrLen));
+  }
+
+  for (size_t i = 1; i < Args.size(); i++) {
+if (SpecIsCString.test(i)) {
+  StringRef ArgStr;
+  if (getConstantStringInfo(Args[i], ArgStr)) {
+auto alignedLen = alignUp(ArgStr.size() + 1, 8);
+StringContents.push_back(
+StringData((ArgStr.str() + '\0'), /*isConst*/ true,
+   /*RealSize*/ nullptr, /*AlignedSize*/ nullptr));
+BufSize += alignedLen;
+  } else {
+auto LenWithNull = getStrlenWithNull(Builder, Args[i]);
+
+// Align the computed length to next 8 byte boundary
+auto TempAdd = Builder.CreateAdd(
+LenWithNull, ConstantInt::get(LenWithNull->getType(), 7U));
+auto LenWithNullAligned = Builder.CreateAnd(
+TempAdd, ConstantInt::get(LenWithNull->getType(), ~7U));
+
+if (NonConstStrLen) {
+  auto Val = Builder.CreateAdd(LenWithNullAligned, NonConstStrLen,
+   "cumulativeAdd");
+  NonConstStrLen = Val;
+} else
+  NonConstStrLen = LenWithNullAligned;
+
+StringContents.push_back(
+StringData("", false, LenWithNull, LenWithNullAligned));
+  }
+} else
+  // We end up expanding non string arguments to 8 bytes
+  BufSize += 8;
+  }
+
+  // calculate final size value to be passed to printf_alloc
+  Value *SizeToReserve = ConstantInt::get(Builder.getInt64Ty(), BufSize, false);
+  SmallVector Alloc_args;
+  if (NonConstStrLen)
+SizeToReserve = Builder.CreateAdd(NonConstStrLen, SizeToReserve);
+
+  ArgSize = Builder.CreateTrunc(SizeToReserve, Builder.getInt32Ty());
+  Alloc_args.push_back(ArgSize);
+
+  // call the printf_alloc function
+  AttributeList Attr = Attr

[PATCH] D151185: [clangd] Store paths as requested in PreambleStatCache

2023-05-23 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet created this revision.
kadircet added a reviewer: hokein.
Herald added a subscriber: arphaman.
Herald added a project: All.
kadircet requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

Underlying FS can store different file names inside the stat response
(e.g. symlinks resolved, absolute paths, dots removed). But we store path names
as requested inside the preamble,
https://github.com/llvm/llvm-project/blob/main/clang/lib/Serialization/ASTWriter.cpp#L1635.

This improves cache hit rates from ~30% to 90% in a build system that uses
symlinks.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D151185

Files:
  clang-tools-extra/clangd/FS.cpp
  clang-tools-extra/clangd/FS.h
  clang-tools-extra/clangd/unittests/FSTests.cpp


Index: clang-tools-extra/clangd/unittests/FSTests.cpp
===
--- clang-tools-extra/clangd/unittests/FSTests.cpp
+++ clang-tools-extra/clangd/unittests/FSTests.cpp
@@ -37,18 +37,19 @@
   std::chrono::system_clock::now(), 0, 0, 1024,
   llvm::sys::fs::file_type::regular_file,
   llvm::sys::fs::all_all);
-  StatCache.update(*FS, S);
+  StatCache.update(*FS, S, "real");
   auto ConsumeFS = StatCache.getConsumingFS(FS);
-  auto Cached = ConsumeFS->status(testPath("fake"));
+  EXPECT_FALSE(ConsumeFS->status(testPath("fake")));
+  auto Cached = ConsumeFS->status(testPath("real"));
   EXPECT_TRUE(Cached);
-  EXPECT_EQ(Cached->getName(), testPath("fake"));
+  EXPECT_EQ(Cached->getName(), testPath("real"));
   EXPECT_EQ(Cached->getUniqueID(), S.getUniqueID());
 
-  // fake and temp/../fake should hit the same cache entry.
+  // real and temp/../real should hit the same cache entry.
   // However, the Status returned reflects the actual path requested.
-  auto CachedDotDot = ConsumeFS->status(testPath("temp/../fake"));
+  auto CachedDotDot = ConsumeFS->status(testPath("temp/../real"));
   EXPECT_TRUE(CachedDotDot);
-  EXPECT_EQ(CachedDotDot->getName(), testPath("temp/../fake"));
+  EXPECT_EQ(CachedDotDot->getName(), testPath("temp/../real"));
   EXPECT_EQ(CachedDotDot->getUniqueID(), S.getUniqueID());
 }
 
Index: clang-tools-extra/clangd/FS.h
===
--- clang-tools-extra/clangd/FS.h
+++ clang-tools-extra/clangd/FS.h
@@ -41,7 +41,8 @@
   /// corresponds to. The stat for the main file will not be cached.
   PreambleFileStatusCache(llvm::StringRef MainFilePath);
 
-  void update(const llvm::vfs::FileSystem &FS, llvm::vfs::Status S);
+  void update(const llvm::vfs::FileSystem &FS, llvm::vfs::Status S,
+  llvm::StringRef File);
 
   /// \p Path is a path stored in preamble.
   std::optional lookup(llvm::StringRef Path) const;
Index: clang-tools-extra/clangd/FS.cpp
===
--- clang-tools-extra/clangd/FS.cpp
+++ clang-tools-extra/clangd/FS.cpp
@@ -11,6 +11,7 @@
 #include "llvm/Support/Path.h"
 #include "llvm/Support/VirtualFileSystem.h"
 #include 
+#include 
 
 namespace clang {
 namespace clangd {
@@ -23,9 +24,10 @@
 }
 
 void PreambleFileStatusCache::update(const llvm::vfs::FileSystem &FS,
- llvm::vfs::Status S) {
+ llvm::vfs::Status S,
+ llvm::StringRef File) {
   // Canonicalize path for later lookup, which is usually by absolute path.
-  llvm::SmallString<32> PathStore(S.getName());
+  llvm::SmallString<32> PathStore(File);
   if (FS.makeAbsolute(PathStore))
 return;
   llvm::sys::path::remove_dots(PathStore, /*remove_dot_dot=*/true);
@@ -72,14 +74,14 @@
   // many times (e.g. code completion) and the repeated status call is
   // likely to be cached in the underlying file system anyway.
   if (auto S = File->get()->status())
-StatCache.update(getUnderlyingFS(), std::move(*S));
+StatCache.update(getUnderlyingFS(), std::move(*S), Path.str());
   return File;
 }
 
 llvm::ErrorOr status(const llvm::Twine &Path) override {
   auto S = getUnderlyingFS().status(Path);
   if (S)
-StatCache.update(getUnderlyingFS(), *S);
+StatCache.update(getUnderlyingFS(), *S, Path.str());
   return S;
 }
 


Index: clang-tools-extra/clangd/unittests/FSTests.cpp
===
--- clang-tools-extra/clangd/unittests/FSTests.cpp
+++ clang-tools-extra/clangd/unittests/FSTests.cpp
@@ -37,18 +37,19 @@
   std::chrono::system_clock::now(), 0, 0, 1024,
   llvm::sys::fs::file_type::regular_file,
   llvm::sys::fs::all_all);
-  StatCache.update(*FS, S);
+  StatCache.update(*FS, S, "real");
   auto ConsumeFS = StatCache.getConsumingFS(FS);
-  auto Cached = ConsumeFS->status(testPath("

[PATCH] D151186: [Driver] Properly handle -pie and -nopie on Fuchsia

2023-05-23 Thread Petr Hosek via Phabricator via cfe-commits
phosek created this revision.
phosek added a reviewer: phosek.
Herald added a subscriber: abrachet.
Herald added a project: All.
phosek requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay.
Herald added a project: clang.

Prior to this patch we would ignore -pie and -nopie options but that
could lead to issues when compiling code that uses either of these
flags.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D151186

Files:
  clang/lib/Driver/ToolChains/Fuchsia.cpp
  clang/test/Driver/fuchsia.c


Index: clang/test/Driver/fuchsia.c
===
--- clang/test/Driver/fuchsia.c
+++ clang/test/Driver/fuchsia.c
@@ -75,6 +75,14 @@
 // RUN: | FileCheck %s -check-prefix=CHECK-RTLIB
 // CHECK-RTLIB: error: invalid runtime library name in argument '-rtlib=libgcc'
 
+// RUN: %clang -### %s --target=x86_64-unknown-fuchsia -pie -fuse-ld=lld 2>&1 \
+// RUN: | FileCheck %s -check-prefix=CHECK-PIE
+// CHECK-PIE: "-pie"
+
+// RUN: %clang -### %s --target=x86_64-unknown-fuchsia -nopie -fuse-ld=lld 
2>&1 \
+// RUN: | FileCheck %s -check-prefix=CHECK-NOPIE
+// CHECK-NOPIE: "-no-pie"
+
 // RUN: %clang -### %s --target=x86_64-unknown-fuchsia -static -fuse-ld=lld 
2>&1 \
 // RUN: | FileCheck %s -check-prefix=CHECK-STATIC
 // CHECK-STATIC: "-Bstatic"
Index: clang/lib/Driver/ToolChains/Fuchsia.cpp
===
--- clang/lib/Driver/ToolChains/Fuchsia.cpp
+++ clang/lib/Driver/ToolChains/Fuchsia.cpp
@@ -71,8 +71,14 @@
   if (!D.SysRoot.empty())
 CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot));
 
-  if (!Args.hasArg(options::OPT_shared) && !Args.hasArg(options::OPT_r))
-CmdArgs.push_back("-pie");
+  if (!Args.hasArg(options::OPT_shared) && !Args.hasArg(options::OPT_r)) {
+Arg *A = Args.getLastArg(options::OPT_pie, options::OPT_no_pie,
+ options::OPT_nopie);
+if (!A || A->getOption().matches(options::OPT_pie))
+  CmdArgs.push_back("-pie");
+else
+  CmdArgs.push_back("-no-pie");
+  }
 
   if (Args.hasArg(options::OPT_rdynamic))
 CmdArgs.push_back("-export-dynamic");


Index: clang/test/Driver/fuchsia.c
===
--- clang/test/Driver/fuchsia.c
+++ clang/test/Driver/fuchsia.c
@@ -75,6 +75,14 @@
 // RUN: | FileCheck %s -check-prefix=CHECK-RTLIB
 // CHECK-RTLIB: error: invalid runtime library name in argument '-rtlib=libgcc'
 
+// RUN: %clang -### %s --target=x86_64-unknown-fuchsia -pie -fuse-ld=lld 2>&1 \
+// RUN: | FileCheck %s -check-prefix=CHECK-PIE
+// CHECK-PIE: "-pie"
+
+// RUN: %clang -### %s --target=x86_64-unknown-fuchsia -nopie -fuse-ld=lld 2>&1 \
+// RUN: | FileCheck %s -check-prefix=CHECK-NOPIE
+// CHECK-NOPIE: "-no-pie"
+
 // RUN: %clang -### %s --target=x86_64-unknown-fuchsia -static -fuse-ld=lld 2>&1 \
 // RUN: | FileCheck %s -check-prefix=CHECK-STATIC
 // CHECK-STATIC: "-Bstatic"
Index: clang/lib/Driver/ToolChains/Fuchsia.cpp
===
--- clang/lib/Driver/ToolChains/Fuchsia.cpp
+++ clang/lib/Driver/ToolChains/Fuchsia.cpp
@@ -71,8 +71,14 @@
   if (!D.SysRoot.empty())
 CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot));
 
-  if (!Args.hasArg(options::OPT_shared) && !Args.hasArg(options::OPT_r))
-CmdArgs.push_back("-pie");
+  if (!Args.hasArg(options::OPT_shared) && !Args.hasArg(options::OPT_r)) {
+Arg *A = Args.getLastArg(options::OPT_pie, options::OPT_no_pie,
+ options::OPT_nopie);
+if (!A || A->getOption().matches(options::OPT_pie))
+  CmdArgs.push_back("-pie");
+else
+  CmdArgs.push_back("-no-pie");
+  }
 
   if (Args.hasArg(options::OPT_rdynamic))
 CmdArgs.push_back("-export-dynamic");
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D151087: [Clang] Permit address space casts with 'reinterpret_cast' in C++

2023-05-23 Thread Bevin Hansson via Phabricator via cfe-commits
ebevhan added a comment.

In D151087#4362059 , @aaron.ballman 
wrote:

> Based on all this, I think we should go with `__addrspace_cast` as a named 
> cast and not allow the conversion through `reinterpret_cast` unless going 
> to/from a `[u]intptr_t`.

I think this sounds good. Most of the building blocks for it should already be 
in place in the form of OpenCL's addrspace_cast. It would remove 
reinterpret_cast's ability to perform safe conversions, though. Could that 
affect something else inadvertently? ICS or SCS?

There are other C++ casts that deal with address spaces today. static_cast can 
also do it when converting from a void pointer, for example. Should it also 
lose the ability?

In D151087#4362135 , @arsenm wrote:

> In D151087#4361237 , @ebevhan wrote:
>
>> What is now a reinterpret_cast? An address space conversion, or a bitcast? 
>> It's not as straightforward as it might seem.
>
> This is the most straightforward part. It's a bitcast.

And because of that, it wouldn't be possible to perform address space 
conversions between such pointers using reinterpret_cast.

In D151087#4362216 , @jhuber6 wrote:

> I'm not sure if casting away an address space is always legal, it's generally 
> what we do in LLVM-IR.

The TR says this:

  There is no requirement that named address spaces (intrinsic or otherwise) be 
subsets of the
  generic address space.

but also what Aaron pasted in his earlier comment:

  A non-null pointer into an address space A can be cast to a pointer into 
another address space B,
  but such a cast is undefined if the source pointer does not point to a 
location in B.

So, according to the report, converting to the generic address space would 
always be valid, but might be undefined. I've never understood why the TR did 
it this way; there's no reason to allow such conversions if we know they are 
undefined at compile time. Conversions that are undecidable (from superset to 
subset) are one thing, but the report makes no validity restrictions on 
converting between disjoint spaces.

Undefined could technically mean "emit an error", but this isn't what Clang 
does today, and lots of tests and probably code depends on it working like that 
now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151087

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


[clang] f5af7d2 - Revert "[clang][ExprConstant] fix __builtin_object_size for flexible array members"

2023-05-23 Thread Krasimir Georgiev via cfe-commits

Author: Krasimir Georgiev
Date: 2023-05-23T07:59:38Z
New Revision: f5af7d2d987b0b16d7a641b7aa9086a75d533944

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

LOG: Revert "[clang][ExprConstant] fix __builtin_object_size for flexible array 
members"

This reverts commit 57c5c1ab2a188b7962c9de5ac0f95e3c7441940a.

Causes an assertion failure: https://reviews.llvm.org/D150892#4363080

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/AST/ExprConstant.cpp
clang/test/CodeGen/object-size.c

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index a124617fac8b..915c9b0cf101 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -51,11 +51,6 @@ C/C++ Language Potentially Breaking Changes
 
 foo: asm goto ("# %0 %1"::"i"(&&foo)::foo);
 
-- ``__builtin_object_size`` and ``__builtin_dynamic_object_size`` now add the
-  ``sizeof`` the elements specified in designated initializers of flexible
-  array members for structs that contain them. This change is more consistent
-  with the behavior of GCC.
-
 C++ Specific Potentially Breaking Changes
 -
 - Clang won't search for coroutine_traits in std::experimental namespace any 
more.
@@ -429,10 +424,6 @@ Bug Fixes in This Version
   (`#61746 `_).
 - Clang `TextNodeDumper` enabled through `-ast-dump` flag no longer evaluates 
the
   initializer of constexpr `VarDecl` if the declaration has a dependent type.
-- Match GCC's behavior for ``__builtin_object_size`` and
-  ``__builtin_dynamic_object_size`` on structs containing flexible array
-  members.
-  (`#62789 `_).
 
 Bug Fixes to Compiler Builtins
 ^^

diff  --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index f1a30da1ff77..ce3c5257e711 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -11733,14 +11733,7 @@ static bool determineEndOffset(EvalInfo &Info, 
SourceLocation ExprLoc,
   auto CheckedHandleSizeof = [&](QualType Ty, CharUnits &Result) {
 if (Ty.isNull() || Ty->isIncompleteType() || Ty->isFunctionType())
   return false;
-bool Ret = HandleSizeof(Info, ExprLoc, Ty, Result);
-if (Ty->isStructureType() &&
-Ty->getAsStructureType()->getDecl()->hasFlexibleArrayMember()) {
-  const auto *VD =
-  cast(LVal.getLValueBase().get());
-  Result += VD->getFlexibleArrayInitChars(Info.Ctx);
-}
-return Ret;
+return HandleSizeof(Info, ExprLoc, Ty, Result);
   };
 
   // We want to evaluate the size of the entire object. This is a valid 
fallback

diff  --git a/clang/test/CodeGen/object-size.c 
b/clang/test/CodeGen/object-size.c
index ac1551343d6f..157926dd719d 100644
--- a/clang/test/CodeGen/object-size.c
+++ b/clang/test/CodeGen/object-size.c
@@ -525,33 +525,6 @@ void test31(void) {
   gi = OBJECT_SIZE_BUILTIN(&dsv[9].snd[0], 1);
 }
 
-// CHECK-LABEL: @test32
-static struct DynStructVar D32 = {
-  .fst = {},
-  .snd = { 0, 1, 2, },
-};
-unsigned long test32(void) {
-  // CHECK: ret i64 19
-  return OBJECT_SIZE_BUILTIN(&D32, 1);
-}
-// CHECK-LABEL: @test33
-static struct DynStructVar D33 = {
-  .fst = {},
-  .snd = {},
-};
-unsigned long test33(void) {
-  // CHECK: ret i64 16
-  return OBJECT_SIZE_BUILTIN(&D33, 1);
-}
-// CHECK-LABEL: @test34
-static struct DynStructVar D34 = {
-  .fst = {},
-};
-unsigned long test34(void) {
-  // CHECK: ret i64 16
-  return OBJECT_SIZE_BUILTIN(&D34, 1);
-}
-
 // CHECK-LABEL: @PR30346
 void PR30346(void) {
   struct sa_family_t {};



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


[PATCH] D151186: [Driver] Properly handle -pie and -nopie on Fuchsia

2023-05-23 Thread Petr Hosek via Phabricator via cfe-commits
phosek updated this revision to Diff 524599.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151186

Files:
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/lib/Driver/ToolChains/CommonArgs.h
  clang/lib/Driver/ToolChains/Fuchsia.cpp
  clang/lib/Driver/ToolChains/Gnu.cpp
  clang/test/Driver/fuchsia.c

Index: clang/test/Driver/fuchsia.c
===
--- clang/test/Driver/fuchsia.c
+++ clang/test/Driver/fuchsia.c
@@ -75,6 +75,14 @@
 // RUN: | FileCheck %s -check-prefix=CHECK-RTLIB
 // CHECK-RTLIB: error: invalid runtime library name in argument '-rtlib=libgcc'
 
+// RUN: %clang -### %s --target=x86_64-unknown-fuchsia -pie -fuse-ld=lld 2>&1 \
+// RUN: | FileCheck %s -check-prefix=CHECK-PIE
+// CHECK-PIE: "-pie"
+
+// RUN: %clang -### %s --target=x86_64-unknown-fuchsia -nopie -fuse-ld=lld 2>&1 \
+// RUN: | FileCheck %s -check-prefix=CHECK-NOPIE
+// CHECK-NOPIE-NOT: "-pie"
+
 // RUN: %clang -### %s --target=x86_64-unknown-fuchsia -static -fuse-ld=lld 2>&1 \
 // RUN: | FileCheck %s -check-prefix=CHECK-STATIC
 // CHECK-STATIC: "-Bstatic"
Index: clang/lib/Driver/ToolChains/Gnu.cpp
===
--- clang/lib/Driver/ToolChains/Gnu.cpp
+++ clang/lib/Driver/ToolChains/Gnu.cpp
@@ -315,37 +315,6 @@
   }
 }
 
-static bool getPIE(const ArgList &Args, const ToolChain &TC) {
-  if (Args.hasArg(options::OPT_shared) || Args.hasArg(options::OPT_static) ||
-  Args.hasArg(options::OPT_r) || Args.hasArg(options::OPT_static_pie))
-return false;
-
-  Arg *A = Args.getLastArg(options::OPT_pie, options::OPT_no_pie,
-   options::OPT_nopie);
-  if (!A)
-return TC.isPIEDefault(Args);
-  return A->getOption().matches(options::OPT_pie);
-}
-
-static bool getStaticPIE(const ArgList &Args, const ToolChain &TC) {
-  bool HasStaticPIE = Args.hasArg(options::OPT_static_pie);
-  // -no-pie is an alias for -nopie. So, handling -nopie takes care of
-  // -no-pie as well.
-  if (HasStaticPIE && Args.hasArg(options::OPT_nopie)) {
-const Driver &D = TC.getDriver();
-const llvm::opt::OptTable &Opts = D.getOpts();
-StringRef StaticPIEName = Opts.getOptionName(options::OPT_static_pie);
-StringRef NoPIEName = Opts.getOptionName(options::OPT_nopie);
-D.Diag(diag::err_drv_cannot_mix_options) << StaticPIEName << NoPIEName;
-  }
-  return HasStaticPIE;
-}
-
-static bool getStatic(const ArgList &Args) {
-  return Args.hasArg(options::OPT_static) &&
-  !Args.hasArg(options::OPT_static_pie);
-}
-
 void tools::gnutools::StaticLibTool::ConstructJob(
 Compilation &C, const JobAction &JA, const InputInfo &Output,
 const InputInfoList &Inputs, const ArgList &Args,
@@ -410,9 +379,9 @@
   const bool isAndroid = ToolChain.getTriple().isAndroid();
   const bool IsIAMCU = ToolChain.getTriple().isOSIAMCU();
   const bool IsVE = ToolChain.getTriple().isVE();
-  const bool IsPIE = getPIE(Args, ToolChain);
-  const bool IsStaticPIE = getStaticPIE(Args, ToolChain);
-  const bool IsStatic = getStatic(Args);
+  const bool IsPIE = isPIE(ToolChain, Args);
+  const bool IsStaticPIE = isStaticPIE(ToolChain, Args);
+  const bool IsStatic = isStatic(Args);
   const bool HasCRTBeginEndFiles =
   ToolChain.getTriple().hasEnvironment() ||
   (ToolChain.getTriple().getVendor() != llvm::Triple::MipsTechnologies);
Index: clang/lib/Driver/ToolChains/Fuchsia.cpp
===
--- clang/lib/Driver/ToolChains/Fuchsia.cpp
+++ clang/lib/Driver/ToolChains/Fuchsia.cpp
@@ -71,7 +71,7 @@
   if (!D.SysRoot.empty())
 CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot));
 
-  if (!Args.hasArg(options::OPT_shared) && !Args.hasArg(options::OPT_r))
+  if (isPIE(ToolChain, Args))
 CmdArgs.push_back("-pie");
 
   if (Args.hasArg(options::OPT_rdynamic))
Index: clang/lib/Driver/ToolChains/CommonArgs.h
===
--- clang/lib/Driver/ToolChains/CommonArgs.h
+++ clang/lib/Driver/ToolChains/CommonArgs.h
@@ -23,6 +23,10 @@
 namespace driver {
 namespace tools {
 
+bool isPIE(const ToolChain &TC, const llvm::opt::ArgList &Args);
+bool isStaticPIE(const ToolChain &TC, const llvm::opt::ArgList &Args);
+bool isStatic(const llvm::opt::ArgList &Args);
+
 void addPathIfExists(const Driver &D, const Twine &Path,
  ToolChain::path_list &Paths);
 
@@ -228,6 +232,9 @@
 void addOpenMPDeviceRTL(const Driver &D, const llvm::opt::ArgList &DriverArgs,
 llvm::opt::ArgStringList &CC1Args,
 StringRef BitcodeSuffix, const llvm::Triple &Triple);
+
+
+
 } // end namespace tools
 } // end namespace driver
 } // end namespace clang
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clan

[PATCH] D151186: [Driver] Properly handle -pie and -nopie on Fuchsia

2023-05-23 Thread Petr Hosek via Phabricator via cfe-commits
phosek updated this revision to Diff 524601.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151186

Files:
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/lib/Driver/ToolChains/CommonArgs.h
  clang/lib/Driver/ToolChains/Fuchsia.cpp
  clang/lib/Driver/ToolChains/Gnu.cpp
  clang/test/Driver/fuchsia.c

Index: clang/test/Driver/fuchsia.c
===
--- clang/test/Driver/fuchsia.c
+++ clang/test/Driver/fuchsia.c
@@ -75,6 +75,14 @@
 // RUN: | FileCheck %s -check-prefix=CHECK-RTLIB
 // CHECK-RTLIB: error: invalid runtime library name in argument '-rtlib=libgcc'
 
+// RUN: %clang -### %s --target=x86_64-unknown-fuchsia -pie -fuse-ld=lld 2>&1 \
+// RUN: | FileCheck %s -check-prefix=CHECK-PIE
+// CHECK-PIE: "-pie"
+
+// RUN: %clang -### %s --target=x86_64-unknown-fuchsia -nopie -fuse-ld=lld 2>&1 \
+// RUN: | FileCheck %s -check-prefix=CHECK-NOPIE
+// CHECK-NOPIE-NOT: "-pie"
+
 // RUN: %clang -### %s --target=x86_64-unknown-fuchsia -static -fuse-ld=lld 2>&1 \
 // RUN: | FileCheck %s -check-prefix=CHECK-STATIC
 // CHECK-STATIC: "-Bstatic"
Index: clang/lib/Driver/ToolChains/Gnu.cpp
===
--- clang/lib/Driver/ToolChains/Gnu.cpp
+++ clang/lib/Driver/ToolChains/Gnu.cpp
@@ -315,37 +315,6 @@
   }
 }
 
-static bool getPIE(const ArgList &Args, const ToolChain &TC) {
-  if (Args.hasArg(options::OPT_shared) || Args.hasArg(options::OPT_static) ||
-  Args.hasArg(options::OPT_r) || Args.hasArg(options::OPT_static_pie))
-return false;
-
-  Arg *A = Args.getLastArg(options::OPT_pie, options::OPT_no_pie,
-   options::OPT_nopie);
-  if (!A)
-return TC.isPIEDefault(Args);
-  return A->getOption().matches(options::OPT_pie);
-}
-
-static bool getStaticPIE(const ArgList &Args, const ToolChain &TC) {
-  bool HasStaticPIE = Args.hasArg(options::OPT_static_pie);
-  // -no-pie is an alias for -nopie. So, handling -nopie takes care of
-  // -no-pie as well.
-  if (HasStaticPIE && Args.hasArg(options::OPT_nopie)) {
-const Driver &D = TC.getDriver();
-const llvm::opt::OptTable &Opts = D.getOpts();
-StringRef StaticPIEName = Opts.getOptionName(options::OPT_static_pie);
-StringRef NoPIEName = Opts.getOptionName(options::OPT_nopie);
-D.Diag(diag::err_drv_cannot_mix_options) << StaticPIEName << NoPIEName;
-  }
-  return HasStaticPIE;
-}
-
-static bool getStatic(const ArgList &Args) {
-  return Args.hasArg(options::OPT_static) &&
-  !Args.hasArg(options::OPT_static_pie);
-}
-
 void tools::gnutools::StaticLibTool::ConstructJob(
 Compilation &C, const JobAction &JA, const InputInfo &Output,
 const InputInfoList &Inputs, const ArgList &Args,
@@ -410,9 +379,9 @@
   const bool isAndroid = ToolChain.getTriple().isAndroid();
   const bool IsIAMCU = ToolChain.getTriple().isOSIAMCU();
   const bool IsVE = ToolChain.getTriple().isVE();
-  const bool IsPIE = getPIE(Args, ToolChain);
-  const bool IsStaticPIE = getStaticPIE(Args, ToolChain);
-  const bool IsStatic = getStatic(Args);
+  const bool IsPIE = isPIE(ToolChain, Args);
+  const bool IsStaticPIE = isStaticPIE(ToolChain, Args);
+  const bool IsStatic = isStatic(Args);
   const bool HasCRTBeginEndFiles =
   ToolChain.getTriple().hasEnvironment() ||
   (ToolChain.getTriple().getVendor() != llvm::Triple::MipsTechnologies);
Index: clang/lib/Driver/ToolChains/Fuchsia.cpp
===
--- clang/lib/Driver/ToolChains/Fuchsia.cpp
+++ clang/lib/Driver/ToolChains/Fuchsia.cpp
@@ -71,7 +71,7 @@
   if (!D.SysRoot.empty())
 CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot));
 
-  if (!Args.hasArg(options::OPT_shared) && !Args.hasArg(options::OPT_r))
+  if (isPIE(ToolChain, Args))
 CmdArgs.push_back("-pie");
 
   if (Args.hasArg(options::OPT_rdynamic))
Index: clang/lib/Driver/ToolChains/CommonArgs.h
===
--- clang/lib/Driver/ToolChains/CommonArgs.h
+++ clang/lib/Driver/ToolChains/CommonArgs.h
@@ -23,6 +23,10 @@
 namespace driver {
 namespace tools {
 
+bool isPIE(const ToolChain &TC, const llvm::opt::ArgList &Args);
+bool isStaticPIE(const ToolChain &TC, const llvm::opt::ArgList &Args);
+bool isStatic(const llvm::opt::ArgList &Args);
+
 void addPathIfExists(const Driver &D, const Twine &Path,
  ToolChain::path_list &Paths);
 
@@ -228,6 +232,9 @@
 void addOpenMPDeviceRTL(const Driver &D, const llvm::opt::ArgList &DriverArgs,
 llvm::opt::ArgStringList &CC1Args,
 StringRef BitcodeSuffix, const llvm::Triple &Triple);
+
+
+
 } // end namespace tools
 } // end namespace driver
 } // end namespace clang
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clan

[PATCH] D151186: [Driver] Properly handle -pie and -nopie on Fuchsia

2023-05-23 Thread Petr Hosek via Phabricator via cfe-commits
phosek updated this revision to Diff 524602.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151186

Files:
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/lib/Driver/ToolChains/CommonArgs.h
  clang/lib/Driver/ToolChains/Fuchsia.cpp
  clang/lib/Driver/ToolChains/Gnu.cpp
  clang/test/Driver/fuchsia.c

Index: clang/test/Driver/fuchsia.c
===
--- clang/test/Driver/fuchsia.c
+++ clang/test/Driver/fuchsia.c
@@ -75,6 +75,14 @@
 // RUN: | FileCheck %s -check-prefix=CHECK-RTLIB
 // CHECK-RTLIB: error: invalid runtime library name in argument '-rtlib=libgcc'
 
+// RUN: %clang -### %s --target=x86_64-unknown-fuchsia -pie -fuse-ld=lld 2>&1 \
+// RUN: | FileCheck %s -check-prefix=CHECK-PIE
+// CHECK-PIE: "-pie"
+
+// RUN: %clang -### %s --target=x86_64-unknown-fuchsia -nopie -fuse-ld=lld 2>&1 \
+// RUN: | FileCheck %s -check-prefix=CHECK-NOPIE
+// CHECK-NOPIE-NOT: "-pie"
+
 // RUN: %clang -### %s --target=x86_64-unknown-fuchsia -static -fuse-ld=lld 2>&1 \
 // RUN: | FileCheck %s -check-prefix=CHECK-STATIC
 // CHECK-STATIC: "-Bstatic"
Index: clang/lib/Driver/ToolChains/Gnu.cpp
===
--- clang/lib/Driver/ToolChains/Gnu.cpp
+++ clang/lib/Driver/ToolChains/Gnu.cpp
@@ -315,37 +315,6 @@
   }
 }
 
-static bool getPIE(const ArgList &Args, const ToolChain &TC) {
-  if (Args.hasArg(options::OPT_shared) || Args.hasArg(options::OPT_static) ||
-  Args.hasArg(options::OPT_r) || Args.hasArg(options::OPT_static_pie))
-return false;
-
-  Arg *A = Args.getLastArg(options::OPT_pie, options::OPT_no_pie,
-   options::OPT_nopie);
-  if (!A)
-return TC.isPIEDefault(Args);
-  return A->getOption().matches(options::OPT_pie);
-}
-
-static bool getStaticPIE(const ArgList &Args, const ToolChain &TC) {
-  bool HasStaticPIE = Args.hasArg(options::OPT_static_pie);
-  // -no-pie is an alias for -nopie. So, handling -nopie takes care of
-  // -no-pie as well.
-  if (HasStaticPIE && Args.hasArg(options::OPT_nopie)) {
-const Driver &D = TC.getDriver();
-const llvm::opt::OptTable &Opts = D.getOpts();
-StringRef StaticPIEName = Opts.getOptionName(options::OPT_static_pie);
-StringRef NoPIEName = Opts.getOptionName(options::OPT_nopie);
-D.Diag(diag::err_drv_cannot_mix_options) << StaticPIEName << NoPIEName;
-  }
-  return HasStaticPIE;
-}
-
-static bool getStatic(const ArgList &Args) {
-  return Args.hasArg(options::OPT_static) &&
-  !Args.hasArg(options::OPT_static_pie);
-}
-
 void tools::gnutools::StaticLibTool::ConstructJob(
 Compilation &C, const JobAction &JA, const InputInfo &Output,
 const InputInfoList &Inputs, const ArgList &Args,
@@ -410,9 +379,9 @@
   const bool isAndroid = ToolChain.getTriple().isAndroid();
   const bool IsIAMCU = ToolChain.getTriple().isOSIAMCU();
   const bool IsVE = ToolChain.getTriple().isVE();
-  const bool IsPIE = getPIE(Args, ToolChain);
-  const bool IsStaticPIE = getStaticPIE(Args, ToolChain);
-  const bool IsStatic = getStatic(Args);
+  const bool IsPIE = isPIE(ToolChain, Args);
+  const bool IsStaticPIE = isStaticPIE(ToolChain, Args);
+  const bool IsStatic = isStatic(Args);
   const bool HasCRTBeginEndFiles =
   ToolChain.getTriple().hasEnvironment() ||
   (ToolChain.getTriple().getVendor() != llvm::Triple::MipsTechnologies);
Index: clang/lib/Driver/ToolChains/Fuchsia.cpp
===
--- clang/lib/Driver/ToolChains/Fuchsia.cpp
+++ clang/lib/Driver/ToolChains/Fuchsia.cpp
@@ -71,7 +71,7 @@
   if (!D.SysRoot.empty())
 CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot));
 
-  if (!Args.hasArg(options::OPT_shared) && !Args.hasArg(options::OPT_r))
+  if (isPIE(ToolChain, Args))
 CmdArgs.push_back("-pie");
 
   if (Args.hasArg(options::OPT_rdynamic))
Index: clang/lib/Driver/ToolChains/CommonArgs.h
===
--- clang/lib/Driver/ToolChains/CommonArgs.h
+++ clang/lib/Driver/ToolChains/CommonArgs.h
@@ -23,6 +23,10 @@
 namespace driver {
 namespace tools {
 
+bool isPIE(const ToolChain &TC, const llvm::opt::ArgList &Args);
+bool isStaticPIE(const ToolChain &TC, const llvm::opt::ArgList &Args);
+bool isStatic(const llvm::opt::ArgList &Args);
+
 void addPathIfExists(const Driver &D, const Twine &Path,
  ToolChain::path_list &Paths);
 
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -146,6 +146,37 @@
   return TargetFeatureArg.getOption().matches(options::OPT_mno_cumode);
 }
 
+bool tools::isPIE(const ToolChain &TC, const ArgList &Args) {
+  if (Args.hasArg(options::OPT_shared) || Args.hasArg(options::OPT_static) 

[PATCH] D149516: [Sema] `setInvalidDecl` for error deduction declaration

2023-05-23 Thread Douglas Yung via Phabricator via cfe-commits
dyung added a comment.

Hi @HerrCai0907, this change is failing on the PS4 linux and PS5 Windows bot. 
Can you take a look? I'm guessing these failures are likely due to the PS4/PS5 
target defaulting to a different C/C++ standard than the rest of clang.

https://lab.llvm.org/buildbot/#/builders/139/builds/41248
https://lab.llvm.org/buildbot/#/builders/216/builds/21637


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149516

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


[PATCH] D150635: [clangd] Implement end-definition-comment inlay hints

2023-05-23 Thread Qingyuan Zheng via Phabricator via cfe-commits
daiyousei-qz added inline comments.



Comment at: clang-tools-extra/clangd/InlayHints.cpp:616
+Position HintStart = sourceLocToPosition(SM, BraceRange.getEnd());
+Position HintEnd = {HintStart.line,
+HintStart.character +

sammccall wrote:
> please don't do this, call sourceLocToPosition unless you have benchmarks 
> showing this is a bottleneck on real-world code.
> 
> `lspLength` and direct manipulation of line/character is unneccesarily subtle.
> (If the performance matters, there's no need to be computing the LSP line of 
> the lbrace at all - we never use it - this is one reason I think this 
> function has the wrong signature)
I argue performance does matter here. I eye-balled inlay hint compute time in 
clangd's output window from vscode. On "./clang/lib/Sema/SemaOpenMP.cpp" which 
is around 1MB, using `sourceLocToPosition` roughly takes around 1250~1350ms. 
However, using two `offsetLocToPosition` usually use 1400~1500ms.  I think 
100ms delta is already a noticeable difference.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150635

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


[PATCH] D151190: [clangd] Do not end inactiveRegions range at position 0 of line

2023-05-23 Thread Nathan Ridge via Phabricator via cfe-commits
nridge created this revision.
nridge added a reviewer: hokein.
Herald added subscribers: kadircet, arphaman.
Herald added a project: All.
nridge requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

This carries over the fix previously made for semantic highlighting
https://reviews.llvm.org/D92148, to the new inactiveRegions
protocol as well.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D151190

Files:
  clang-tools-extra/clangd/ClangdServer.cpp
  clang-tools-extra/clangd/SemanticHighlighting.cpp
  clang-tools-extra/clangd/SourceCode.cpp
  clang-tools-extra/clangd/SourceCode.h
  clang-tools-extra/clangd/unittests/ClangdTests.cpp

Index: clang-tools-extra/clangd/unittests/ClangdTests.cpp
===
--- clang-tools-extra/clangd/unittests/ClangdTests.cpp
+++ clang-tools-extra/clangd/unittests/ClangdTests.cpp
@@ -1342,16 +1342,19 @@
 #undef CMDMACRO
 $inactive3[[#ifdef CMDMACRO
   int inactiveInt2;
-#else]]
-  int activeInt;
-#endif
+#elif PREAMBLEMACRO > 0]]
+  int activeInt1;
+  int activeInt2;
+$inactive4[[#else
+  int inactiveInt3;
+#endif]]
   )cpp");
   Server.addDocument(testPath("foo.cpp"), Source.code());
   ASSERT_TRUE(Server.blockUntilIdleForTest());
   EXPECT_THAT(Callback.FoundInactiveRegions,
-  ElementsAre(ElementsAre(Source.range("inactive1"),
-  Source.range("inactive2"),
-  Source.range("inactive3";
+  ElementsAre(ElementsAre(
+  Source.range("inactive1"), Source.range("inactive2"),
+  Source.range("inactive3"), Source.range("inactive4";
 }
 
 } // namespace
Index: clang-tools-extra/clangd/SourceCode.h
===
--- clang-tools-extra/clangd/SourceCode.h
+++ clang-tools-extra/clangd/SourceCode.h
@@ -72,6 +72,9 @@
 /// FIXME: This should return an error if the location is invalid.
 Position sourceLocToPosition(const SourceManager &SM, SourceLocation Loc);
 
+/// Get the last Position on a given line.
+llvm::Expected endOfLine(llvm::StringRef Code, int Line);
+
 /// Return the file location, corresponding to \p P. Note that one should take
 /// care to avoid comparing the result with expansion locations.
 llvm::Expected sourceLocationInMainFile(const SourceManager &SM,
Index: clang-tools-extra/clangd/SourceCode.cpp
===
--- clang-tools-extra/clangd/SourceCode.cpp
+++ clang-tools-extra/clangd/SourceCode.cpp
@@ -228,6 +228,16 @@
   return P;
 }
 
+llvm::Expected endOfLine(llvm::StringRef Code, int Line) {
+  auto StartOfLine = positionToOffset(Code, Position{Line, 0});
+  if (!StartOfLine)
+return StartOfLine.takeError();
+  StringRef LineText = Code.drop_front(*StartOfLine).take_until([](char C) {
+return C == '\n';
+  });
+  return Position{Line, static_cast(lspLength(LineText))};
+}
+
 bool isSpelledInSource(SourceLocation Loc, const SourceManager &SM) {
   if (Loc.isFileID())
 return true;
Index: clang-tools-extra/clangd/SemanticHighlighting.cpp
===
--- clang-tools-extra/clangd/SemanticHighlighting.cpp
+++ clang-tools-extra/clangd/SemanticHighlighting.cpp
@@ -483,22 +483,15 @@
 for (; It != NonConflicting.end() && It->R.start.line < Line; ++It)
   WithInactiveLines.push_back(std::move(*It));
 // Add a token for the inactive line itself.
-auto StartOfLine = positionToOffset(MainCode, Position{Line, 0});
-if (StartOfLine) {
-  StringRef LineText =
-  MainCode.drop_front(*StartOfLine).take_until([](char C) {
-return C == '\n';
-  });
+auto EndOfLine = endOfLine(MainCode, Line);
+if (EndOfLine) {
   HighlightingToken HT;
   WithInactiveLines.emplace_back();
   WithInactiveLines.back().Kind = HighlightingKind::InactiveCode;
   WithInactiveLines.back().R.start.line = Line;
-  WithInactiveLines.back().R.end.line = Line;
-  WithInactiveLines.back().R.end.character =
-  static_cast(lspLength(LineText));
+  WithInactiveLines.back().R.end = *EndOfLine;
 } else {
-  elog("Failed to convert position to offset: {0}",
-   StartOfLine.takeError());
+  elog("Failed to determine end of line: {0}", EndOfLine.takeError());
 }
 
 // Skip any other tokens on the inactive line. e.g.
Index: clang-tools-extra/clangd/ClangdServer.cpp
===
--- clang-tools-extra/clangd/ClangdServer.cpp
+++ clang-tools-extra/clangd/ClangdServer.cpp
@@ -116,8 +116,26 @@
 ServerCallbacks->onDiagnosticsReady(Path, AST.version(),
  

[PATCH] D150427: [AMDGPU] Non hostcall printf support for HIP

2023-05-23 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added inline comments.



Comment at: llvm/lib/Transforms/Utils/AMDGPUEmitPrintf.cpp:219
+
+static inline size_t alignUp(size_t Value, uint Alignment) {
+  return (Value + Alignment - 1) & ~(Alignment - 1);

MathExtras already has alignTo



Comment at: llvm/lib/Transforms/Utils/AMDGPUEmitPrintf.cpp:390
+  StoreInst *StBuff = Builder.CreateStore(toStore, PtrToStore);
+  LLVM_DEBUG(dbgs() << "inserting store to printf buffer:\n"
+<< *StBuff << '\n');

Remove this newline 



Comment at: llvm/lib/Transforms/Utils/AMDGPUEmitPrintf.cpp:392
+<< *StBuff << '\n');
+  PtrToStore = Builder.CreateGEP(
+  Builder.getInt8Ty(), PtrToStore,

You can use one of the CreateConstGEPs. I also suspect this can be inbounds 



Comment at: llvm/lib/Transforms/Utils/AMDGPUEmitPrintf.cpp:398
+  "PrintBuffNextPtr");
+  LLVM_DEBUG(dbgs() << "inserting gep to the printf buffer:\n"
+<< *PtrToStore << '\n');

Remove this newline



Comment at: llvm/lib/Transforms/Utils/AMDGPUEmitPrintf.cpp:455
+{ArgSize, ConstantInt::get(Int1Ty, IsConstFmtStr ? 1 : 0, false),
+ ConstantInt::get(Int1Ty, 0, false)});
+Builder.CreateStore(valueToStore, Ptr);

There's a getFalse 



Comment at: llvm/lib/Transforms/Utils/AMDGPUEmitPrintf.cpp:480
+  Ptr);
+  Ptr = Builder.CreateGEP(Int8Ty, Ptr, {ConstantInt::get(Int32Ty, 8)});
+} else {

CreateConstGEP


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150427

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


[PATCH] D146757: [Driver] Enable defining multilib flags verbatim

2023-05-23 Thread Petr Hosek via Phabricator via cfe-commits
phosek added a comment.

I apologize about the delayed response. I had time to think about this a bit 
more and it's not really clear to me if we need to preserve the "plus/minus" 
flag syntax. Looking through the history, it seems that it was introduced in 
D2538  without any discussion but I always 
considered it to be confusing and potentially error-prone. Rather than 
supporting two different syntaxes, which introduces more complexity, I'd prefer 
having just one. I can of think of two approaches:

1. Have two separate lists of include and exclude flags.
2. Store flags as a tuple (or a struct?) of string and a tag (that is include 
or exclude).

Do you have any preference between one these two approaches? Can you think of 
alternatives? It's going to take a bit of effort to migrate all the existing 
use cases of the "plus/minus" syntax, but I hope it should be mostly 
mechanical. I'd be happy to help with the migration once we settle on an API.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146757

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


[PATCH] D142932: Multilib YAML parsing

2023-05-23 Thread Petr Hosek via Phabricator via cfe-commits
phosek added inline comments.



Comment at: clang/include/clang/Driver/Multilib.h:150-152
+  bool parseYaml(llvm::MemoryBufferRef,
+ llvm::SourceMgr::DiagHandlerTy = nullptr,
+ void *DiagHandlerCtxt = nullptr);

Rather than `parseYaml` modifying the state of `MultilibSet`, can we instead 
have a static factory method or a standalone function that parses, constructs 
and returns `llvm::Expected`. That's more in line with how we 
handle YAML deserialization elsewhere in LLVM, and also follows the notion of 
`MultilibSet` being immutable.



Comment at: clang/lib/Driver/Multilib.cpp:188
+if (StringRef(V.Dir).starts_with("/"))
+  return "paths must be relative. \"" + V.Dir + "\" starts with \"/\"\n";
+return std::string{};

This is just a nit, but the error messages in this file are inconsistent. 
Sometimes they are full sentences (capitalized, ending with a dot), sometimes 
they are not (not-capitalized, no dot at the end) and in this particular case 
it's a mixture (not-capitalized, ending with a dot, although it seems like dot 
here is only used as a separator). I don't have a strong preference for one 
style over the other, but I think we should pick one and be consistent.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142932

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


[PATCH] D142986: Enable multilib.yaml in the BareMetal ToolChain

2023-05-23 Thread Petr Hosek via Phabricator via cfe-commits
phosek added inline comments.



Comment at: clang/lib/Driver/ToolChains/BareMetal.cpp:180
+  SmallString<128> SysRootDir(D.Dir);
+  llvm::sys::path::append(SysRootDir, "../lib/clang-runtimes");
+

Defer to `llvm::sys::path::append` for joining the path components to ensure 
that the right separator is used.



Comment at: clang/lib/Driver/ToolChains/BareMetal.cpp:183
-  SmallString<128> SysRootDir;
-  llvm::sys::path::append(SysRootDir, getDriver().Dir, "../lib/clang-runtimes",
-  getDriver().getTargetTriple());

I see that this is a pre-existing behavior, but I find it a unfortunate that 
the BareMetal driver is using its own convention. I'd prefer using 
`../sys-root` which the existing convention used by GCC. I'm wondering if this 
is something we can change as part of the transition to the new multilib 
implementation?



Comment at: clang/lib/Driver/ToolChains/BareMetal.cpp:184
+  SmallString<128> MultilibPath(SysRootDir);
+  llvm::sys::path::append(MultilibPath, MULTILIB_YAML_FILENAME);
+

michaelplatings wrote:
> phosek wrote:
> > Rather than hardcoding the filename and the location, which is inflexible, 
> > could we instead provide a command line option to specify the file to use?
> I'm not opposed to that in principle but I'd rather leave that as an option 
> for a future change. At this point, for LLVM Embedded Toolchain for Arm our 
> intent is that users will specify `--sysroot` if they want to use a separate 
> set of multilibs.
Relying on `--sysroot` is fine if you're assembling the sysroot yourself and 
control the content, but when dealing with an existing sysroot it may not be 
possible to add additional files in which case having the ability to specify 
the `.yaml` file may be essential. Having an option also gives more 
flexibility, for example I could imagine having more than one `.yaml` file for 
the same sysroot with different subsets of multilibs.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142986

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


[PATCH] D143075: BareMetal ToolChain multilib layering

2023-05-23 Thread Petr Hosek via Phabricator via cfe-commits
phosek added inline comments.



Comment at: clang/lib/Driver/ToolChains/BareMetal.cpp:228
+
+llvm::SmallVector BareMetal::getOrderedMultilibs() const {
+  // Get multilibs in reverse order because they're ordered most-specific last.

Can you use 
[llvm::reverse](https://github.com/llvm/llvm-project/blob/1d8820c342560a2fbf8e1970b861193ba8137177/llvm/include/llvm/ADT/STLExtras.h#L511)
 instead of allocating an entire new collection?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143075

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


[clang] baeb85b - [Clang] Support more stdio builtins

2023-05-23 Thread Qiu Chaofan via cfe-commits

Author: Qiu Chaofan
Date: 2023-05-23T16:35:25+08:00
New Revision: baeb85b5a99778956117d647b78b55be4f51a129

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

LOG: [Clang] Support more stdio builtins

Add more builtins for stdio functions as in GCC, along with their
mutations under IEEE float128 ABI.

Reviewed By: tuliom

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

Added: 


Modified: 
clang/include/clang/Basic/Builtins.def
clang/lib/CodeGen/CGBuiltin.cpp
clang/test/CodeGen/PowerPC/ppc64-f128-builtins.c

Removed: 




diff  --git a/clang/include/clang/Basic/Builtins.def 
b/clang/include/clang/Basic/Builtins.def
index dea806099efbf..15c69c2786476 100644
--- a/clang/include/clang/Basic/Builtins.def
+++ b/clang/include/clang/Basic/Builtins.def
@@ -557,7 +557,6 @@ BUILTIN(__builtin_assume_aligned, "v*vC*z.", "nctE")
 BUILTIN(__builtin_bcmp, "ivC*vC*z", "FnE")
 BUILTIN(__builtin_bcopy, "vv*v*z", "n")
 BUILTIN(__builtin_bzero, "vv*z", "nF")
-BUILTIN(__builtin_fprintf, "iP*cC*.", "Fp:1:")
 BUILTIN(__builtin_free, "vv*", "nF")
 BUILTIN(__builtin_malloc, "v*z", "nF")
 BUILTIN(__builtin_memchr, "v*vC*iz", "nFE")
@@ -568,7 +567,6 @@ BUILTIN(__builtin_memmove, "v*v*vC*z", "nFE")
 BUILTIN(__builtin_mempcpy, "v*v*vC*z", "nF")
 BUILTIN(__builtin_memset, "v*v*iz", "nF")
 BUILTIN(__builtin_memset_inline, "vv*iIz", "n")
-BUILTIN(__builtin_printf, "icC*.", "Fp:0:")
 BUILTIN(__builtin_stpcpy, "c*c*cC*", "nF")
 BUILTIN(__builtin_stpncpy, "c*c*cC*z", "nF")
 BUILTIN(__builtin_strcasecmp, "icC*cC*", "nF")
@@ -605,10 +603,20 @@ BUILTIN(__builtin_setjmp, "iv**", "j")
 BUILTIN(__builtin_longjmp, "vv**i", "r")
 BUILTIN(__builtin_unwind_init, "v", "")
 BUILTIN(__builtin_eh_return_data_regno, "iIi", "ncE")
-BUILTIN(__builtin_snprintf, "ic*zcC*.", "nFp:2:")
-BUILTIN(__builtin_sprintf, "ic*cC*.", "nFP:1:")
-BUILTIN(__builtin_vsnprintf, "ic*zcC*a", "nFP:2:")
-BUILTIN(__builtin_vsprintf, "ic*cC*a", "nFP:1:")
+BUILTIN(__builtin_fprintf, "iP*RcC*R.", "nFp:1:")
+BUILTIN(__builtin_printf, "icC*R.", "nFp:0:")
+BUILTIN(__builtin_sprintf, "ic*RcC*R.", "nFp:1:")
+BUILTIN(__builtin_snprintf, "ic*RzcC*R.", "nFp:2:")
+BUILTIN(__builtin_vprintf, "icC*Ra", "nFP:0:")
+BUILTIN(__builtin_vfprintf, "iP*RcC*Ra", "nFP:1:")
+BUILTIN(__builtin_vsprintf, "ic*RcC*Ra", "nFP:1:")
+BUILTIN(__builtin_vsnprintf, "ic*RzcC*Ra", "nFP:2:")
+BUILTIN(__builtin_fscanf, "iP*RcC*R.", "Fs:1:")
+BUILTIN(__builtin_scanf, "icC*R.", "Fs:0:")
+BUILTIN(__builtin_sscanf, "icC*RcC*R.", "Fs:1:")
+BUILTIN(__builtin_vfscanf, "iP*RcC*Ra", "FS:1:")
+BUILTIN(__builtin_vscanf, "icC*Ra", "FS:0:")
+BUILTIN(__builtin_vsscanf, "icC*RcC*Ra", "FS:1:")
 BUILTIN(__builtin_thread_pointer, "v*", "nc")
 BUILTIN(__builtin_launder, "v*v*", "ntE")
 LANGBUILTIN(__builtin_is_constant_evaluated, "b", "nE", CXX_LANG)
@@ -637,14 +645,14 @@ BUILTIN(__builtin___strlcpy_chk, "zc*cC*zz", "nF")
 BUILTIN(__builtin___strncat_chk, "c*c*cC*zz", "nF")
 BUILTIN(__builtin___strncpy_chk, "c*c*cC*zz", "nF")
 BUILTIN(__builtin___stpncpy_chk, "c*c*cC*zz", "nF")
-BUILTIN(__builtin___snprintf_chk, "ic*zizcC*.", "Fp:4:")
-BUILTIN(__builtin___sprintf_chk, "ic*izcC*.", "Fp:3:")
-BUILTIN(__builtin___vsnprintf_chk, "ic*zizcC*a", "FP:4:")
-BUILTIN(__builtin___vsprintf_chk, "ic*izcC*a", "FP:3:")
-BUILTIN(__builtin___fprintf_chk, "iP*icC*.", "Fp:2:")
-BUILTIN(__builtin___printf_chk, "iicC*.", "Fp:1:")
-BUILTIN(__builtin___vfprintf_chk, "iP*icC*a", "FP:2:")
-BUILTIN(__builtin___vprintf_chk, "iicC*a", "FP:1:")
+BUILTIN(__builtin___snprintf_chk, "ic*RzizcC*R.", "Fp:4:")
+BUILTIN(__builtin___sprintf_chk, "ic*RizcC*R.", "Fp:3:")
+BUILTIN(__builtin___vsnprintf_chk, "ic*RzizcC*Ra", "FP:4:")
+BUILTIN(__builtin___vsprintf_chk, "ic*RizcC*Ra", "FP:3:")
+BUILTIN(__builtin___fprintf_chk, "iP*RicC*R.", "Fp:2:")
+BUILTIN(__builtin___printf_chk, "iicC*R.", "Fp:1:")
+BUILTIN(__builtin___vfprintf_chk, "iP*RicC*Ra", "FP:2:")
+BUILTIN(__builtin___vprintf_chk, "iicC*Ra", "FP:1:")
 
 BUILTIN(__builtin_unpredictable, "LiLi"   , "nc")
 BUILTIN(__builtin_expect, "LiLiLi"   , "ncE")

diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 736d2332a2f5e..301248d98d20d 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -99,13 +99,29 @@ llvm::Constant *CodeGenModule::getBuiltinLibFunction(const 
FunctionDecl *FD,
 
   // TODO: This list should be expanded or refactored after all GCC-compatible
   // std libcall builtins are implemented.
-  static SmallDenseMap F128Builtins{
+  static SmallDenseMap F128Builtins{
+  {Builtin::BI__builtin___fprintf_chk, "__fprintf_chkieee128"},
+  {Builtin::BI__builtin___printf_chk, "__printf_chkieee128"},
+  {Builtin::BI__builtin___snprintf_chk, "__snprintf_chkieee128"},
+  {Builtin::BI__builtin___sprintf_

[PATCH] D150087: [Clang] Support more stdio builtins

2023-05-23 Thread Qiu Chaofan via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
qiucf marked an inline comment as done.
Closed by commit rGbaeb85b5a997: [Clang] Support more stdio builtins (authored 
by qiucf).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150087

Files:
  clang/include/clang/Basic/Builtins.def
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/PowerPC/ppc64-f128-builtins.c

Index: clang/test/CodeGen/PowerPC/ppc64-f128-builtins.c
===
--- clang/test/CodeGen/PowerPC/ppc64-f128-builtins.c
+++ clang/test/CodeGen/PowerPC/ppc64-f128-builtins.c
@@ -52,6 +52,63 @@
   __builtin_snprintf(buf, 20, "%.Lf", x);
 }
 
+// IEEE128-LABEL: define dso_local void @test_scanf
+// IEEE128: call signext i32 (ptr, ...) @__scanfieee128
+// PPC128-LABEL: define dso_local void @test_scanf
+// PPC128: call signext i32 (ptr, ...) @scanf
+void test_scanf(int *x) {
+  __builtin_scanf("%d", x);
+}
+
+// IEEE128-LABEL: define dso_local void @test_sscanf
+// IEEE128: call signext i32 (ptr, ptr, ...) @__sscanfieee128
+// PPC128-LABEL: define dso_local void @test_sscanf
+// PPC128: call signext i32 (ptr, ptr, ...) @sscanf
+void test_sscanf(int *x) {
+  __builtin_sscanf(buf, "%d", x);
+}
+
+// IEEE128-LABEL: define dso_local void @test_vprintf
+// IEEE128: call signext i32 @__vprintfieee128
+// PPC128-LABEL: define dso_local void @test_vprintf
+// PPC128: call signext i32 @vprintf
+void test_vprintf(const char *fmt, ...) {
+  __builtin_va_list args;
+  __builtin_va_start(args, fmt);
+  __builtin_vprintf(fmt, args);
+  __builtin_va_end(args);
+}
+
+// IEEE128-LABEL: define dso_local void @test_vscanf
+// IEEE128: call signext i32 @__vscanfieee128
+// PPC128-LABEL: define dso_local void @test_vscanf
+// PPC128: call signext i32 @vscanf
+void test_vscanf(const char *fmt, ...) {
+  __builtin_va_list args;
+  __builtin_va_start(args, fmt);
+  __builtin_vscanf(fmt, args);
+  __builtin_va_end(args);
+}
+
+// IEEE128-LABEL: define dso_local void @test_vsscanf
+// IEEE128: call signext i32 @__vsscanfieee128
+// PPC128-LABEL: define dso_local void @test_vsscanf
+// PPC128: call signext i32 @vsscanf
+void test_vsscanf(const char *fmt, ...) {
+  __builtin_va_list args;
+  __builtin_va_start(args, fmt);
+  __builtin_vsscanf(buf, fmt, args);
+  __builtin_va_end(args);
+}
+
+// IEEE128-LABEL: define dso_local void @test_snprintf_chk
+// IEEE128: call signext i32 (ptr, i64, i32, i64, ptr, ...) @__snprintf_chkieee128
+// PPC128-LABEL: define dso_local void @test_snprintf_chk
+// PPC128: call signext i32 (ptr, i64, i32, i64, ptr, ...) @__snprintf_chk
+void test_snprintf_chk(long double x) {
+  __builtin___snprintf_chk(buf, 20, 1, 20, "%.Lf", x);
+}
+
 // GLIBC has special handling of 'nexttoward'
 
 // IEEE128-LABEL: define dso_local fp128 @test_nexttoward
Index: clang/lib/CodeGen/CGBuiltin.cpp
===
--- clang/lib/CodeGen/CGBuiltin.cpp
+++ clang/lib/CodeGen/CGBuiltin.cpp
@@ -99,13 +99,29 @@
 
   // TODO: This list should be expanded or refactored after all GCC-compatible
   // std libcall builtins are implemented.
-  static SmallDenseMap F128Builtins{
+  static SmallDenseMap F128Builtins{
+  {Builtin::BI__builtin___fprintf_chk, "__fprintf_chkieee128"},
+  {Builtin::BI__builtin___printf_chk, "__printf_chkieee128"},
+  {Builtin::BI__builtin___snprintf_chk, "__snprintf_chkieee128"},
+  {Builtin::BI__builtin___sprintf_chk, "__sprintf_chkieee128"},
+  {Builtin::BI__builtin___vfprintf_chk, "__vfprintf_chkieee128"},
+  {Builtin::BI__builtin___vprintf_chk, "__vprintf_chkieee128"},
+  {Builtin::BI__builtin___vsnprintf_chk, "__vsnprintf_chkieee128"},
+  {Builtin::BI__builtin___vsprintf_chk, "__vsprintf_chkieee128"},
+  {Builtin::BI__builtin_fprintf, "__fprintfieee128"},
   {Builtin::BI__builtin_printf, "__printfieee128"},
+  {Builtin::BI__builtin_snprintf, "__snprintfieee128"},
+  {Builtin::BI__builtin_sprintf, "__sprintfieee128"},
+  {Builtin::BI__builtin_vfprintf, "__vfprintfieee128"},
+  {Builtin::BI__builtin_vprintf, "__vprintfieee128"},
   {Builtin::BI__builtin_vsnprintf, "__vsnprintfieee128"},
   {Builtin::BI__builtin_vsprintf, "__vsprintfieee128"},
-  {Builtin::BI__builtin_sprintf, "__sprintfieee128"},
-  {Builtin::BI__builtin_snprintf, "__snprintfieee128"},
-  {Builtin::BI__builtin_fprintf, "__fprintfieee128"},
+  {Builtin::BI__builtin_fscanf, "__fscanfieee128"},
+  {Builtin::BI__builtin_scanf, "__scanfieee128"},
+  {Builtin::BI__builtin_sscanf, "__sscanfieee128"},
+  {Builtin::BI__builtin_vfscanf, "__vfscanfieee128"},
+  {Builtin::BI__builtin_vscanf, "__vscanfieee128"},
+  {Builtin::BI__builtin_vsscanf, "__vsscanfieee128"},
   {Builtin::BI__builtin_nexttowardf128, "__nexttowardieee128"},
   };
 
Index: clang/include/clang/Basic/Builtin

[PATCH] D151192: [clang-tidy] have bugprone-unchecked-optional-access check boost::optional usage

2023-05-23 Thread Giel van Schijndel via Phabricator via cfe-commits
muggenhor created this revision.
Herald added subscribers: carlosgalvezp, xazax.hun.
Herald added a reviewer: NoQ.
Herald added a project: All.
muggenhor requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D151192

Files:
  clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp


Index: clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
===
--- clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
+++ clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
@@ -50,7 +50,8 @@
 
   if (RD.getName() == "optional") {
 if (const auto *N = dyn_cast_or_null(RD.getDeclContext()))
-  return N->isStdNamespace() || isTopLevelNamespaceWithName(*N, "absl");
+  return N->isStdNamespace() || isTopLevelNamespaceWithName(*N, "absl") ||
+ isTopLevelNamespaceWithName(*N, "boost");
 return false;
   }
 


Index: clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
===
--- clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
+++ clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
@@ -50,7 +50,8 @@
 
   if (RD.getName() == "optional") {
 if (const auto *N = dyn_cast_or_null(RD.getDeclContext()))
-  return N->isStdNamespace() || isTopLevelNamespaceWithName(*N, "absl");
+  return N->isStdNamespace() || isTopLevelNamespaceWithName(*N, "absl") ||
+ isTopLevelNamespaceWithName(*N, "boost");
 return false;
   }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D151192: [clang-tidy] have bugprone-unchecked-optional-access check boost::optional usage

2023-05-23 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr2 added a comment.

Could you change the tests to cover the new case? They are here: 
`llvm-project/clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151192

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


[PATCH] D139586: [Clang][C++23] Lifetime extension in range-based for loops

2023-05-23 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added a comment.

@hubert.reinterpretcast I'll try to look at that but unless I'm mistaken,  the 
wording excludes function parameters

> The fourth context is when a temporary object **other than a function 
> parameter** object is created in the for-range-initializer of a range-based 
> for statement. If such a temporary object would otherwise be destroyed at the 
> end of the for-range-initializer full-expression, the object persists for the 
> lifetime of the reference initialized by the for-range-initializer.

I think that invalidates some of your examples?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139586

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


[PATCH] D151087: [Clang] Permit address space casts with 'reinterpret_cast' in C++

2023-05-23 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added a comment.

In D151087#4363503 , @ebevhan wrote:

> In D151087#4362059 , @aaron.ballman 
> wrote:
>
>> Based on all this, I think we should go with `__addrspace_cast` as a named 
>> cast and not allow the conversion through `reinterpret_cast` unless going 
>> to/from a `[u]intptr_t`.
>
> I think this sounds good. Most of the building blocks for it should already 
> be in place in the form of OpenCL's addrspace_cast.

I think having some kind of addrspacecast operator is unavoidable. 
reinterpret_cast needs to lower to something like ptrtoint/inttoptr and isn't 
interchangeable


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151087

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


[PATCH] D146757: [Driver] Enable defining multilib flags verbatim

2023-05-23 Thread Michael Platings via Phabricator via cfe-commits
michaelplatings added a comment.

Funnily enough I had the same thought coming to work this morning that we don't 
need 2 syntaxes. I had an idea that we could only print flags beginning "-" but 
will consider the other options you suggested as well. Thanks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146757

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


[PATCH] D151194: [clang][dataflow] Add support for return values of reference type.

2023-05-23 Thread Martin Böhme via Phabricator via cfe-commits
mboehme created this revision.
Herald added subscribers: martong, xazax.hun.
Herald added a reviewer: NoQ.
Herald added a project: All.
mboehme requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This patch changes the way `Environment::ReturnLoc` is set: Whereas previously
it was set by the caller, it is now set by the callee (obviously, as we
otherwise would not be able to return references).

The patch also introduces `Environment::ReturnVal`, which is used for
non-reference-type return values. This allows these to be handled with the
correct value category semantics; see also https://discourse.llvm.org/t/70086,
which describes the ongoing migration to strict value category semantics.

Depends On D150776 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D151194

Files:
  clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
  clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
  clang/lib/Analysis/FlowSensitive/Transfer.cpp
  clang/unittests/Analysis/FlowSensitive/TransferTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -32,7 +32,9 @@
 using namespace clang;
 using namespace dataflow;
 using namespace test;
+using ::testing::Eq;
 using ::testing::IsNull;
+using ::testing::Ne;
 using ::testing::NotNull;
 using ::testing::UnorderedElementsAre;
 
@@ -4239,13 +4241,33 @@
   {BuiltinOptions{/*.ContextSensitiveOpts=*/std::nullopt}});
 }
 
+TEST(TransferTest, ContextSensitiveReturnReference) {
+  std::string Code = R"(
+class S {};
+S& target(bool b, S &s) {
+  return s;
+  // [[p]]
+}
+  )";
+  runDataflow(
+  Code,
+  [](const llvm::StringMap> &Results,
+ ASTContext &ASTCtx) {
+const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
+
+const ValueDecl *SDecl = findValueDecl(ASTCtx, "s");
+ASSERT_THAT(SDecl, NotNull());
+
+auto *SLoc = Env.getStorageLocation(*SDecl);
+ASSERT_THAT(SLoc, NotNull());
+
+ASSERT_THAT(Env.getReturnStorageLocation(), Eq(SLoc));
+  },
+  {BuiltinOptions{ContextSensitiveOptions{}}});
+}
+
 // This test is a regression test, based on a real crash.
-TEST(TransferTest, ContextSensitiveReturnReferenceFromNonReferenceLvalue) {
-  // This code exercises an unusual code path. If we return an lvalue directly,
-  // the code will catch that it's an l-value based on the `Value`'s kind. If we
-  // pass through a dummy function, the framework won't populate a value at
-  // all. In contrast, this code results in a (fresh) value, but it is not
-  // `ReferenceValue`. This test verifies that we catch this case as well.
+TEST(TransferTest, ContextSensitiveReturnReferenceWithConditionalOperator) {
   std::string Code = R"(
 class S {};
 S& target(bool b, S &s) {
@@ -4260,10 +4282,72 @@
 ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));
 const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
 
+const ValueDecl *SDecl = findValueDecl(ASTCtx, "s");
+ASSERT_THAT(SDecl, NotNull());
+
+auto *SLoc = Env.getStorageLocation(*SDecl);
+ASSERT_THAT(SLoc, NotNull());
+EXPECT_THAT(Env.getValue(*SLoc), NotNull());
+
 auto *Loc = Env.getReturnStorageLocation();
 ASSERT_THAT(Loc, NotNull());
+EXPECT_THAT(Env.getValue(*Loc), NotNull());
+
+// TODO: We would really like to make this stronger assertion, but that
+// doesn't work because we don't propagate values correctly through
+// the conditional operator yet.
+// ASSERT_THAT(Loc, Eq(SLoc));
+  },
+  {BuiltinOptions{ContextSensitiveOptions{}}});
+}
+
+TEST(TransferTest, ContextSensitiveReturnOneOfTwoReferences) {
+  std::string Code = R"(
+class S {};
+S &callee(bool b, S &s1_parm, S &s2_parm) {
+  if (b)
+return s1_parm;
+  else
+return s2_parm;
+}
+void target(bool b) {
+  S s1;
+  S s2;
+  S &return_s1 = s1;
+  S &return_s2 = s2;
+  S &return_dont_know = callee(b, s1, s2);
+  // [[p]]
+}
+  )";
+  runDataflow(
+  Code,
+  [](const llvm::StringMap> &Results,
+ ASTContext &ASTCtx) {
+const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
 
-EXPECT_THAT(Env.getValue(*Loc), IsNull());
+const ValueDecl *S1 = findValueDecl(ASTCtx, "s1");
+ASSERT_THAT(S1, NotNull());
+const ValueDecl *S2 = findValueDecl(ASTCtx, "s2");
+ASSERT_THAT(S2, NotNull());
+const ValueDecl *ReturnS1 = findValueDecl(ASTCtx, "return_s1");
+ASSERT_THAT(ReturnS1, NotNull());
+const ValueDecl *ReturnS2 = findValueDecl(ASTCtx, "return_s2");
+ASSERT_TH

[clang] 71bc3dd - [clang] Add test for CWG2213

2023-05-23 Thread Vlad Serebrennikov via cfe-commits

Author: Vlad Serebrennikov
Date: 2023-05-23T12:44:24+03:00
New Revision: 71bc3dd42e2939a25e4394dbebf6239e3e6403a9

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

LOG: [clang] Add test for CWG2213

[[https://wg21.link/p1787 | P1787]]: CWG2213 is resolved by allowing an 
elaborated-type-specifier to contain a simple-template-id without friend.
Wording: see changes to [dcl.type.elab]]/1.

The gist of the issue is that forward declaration of partial class template 
specialization was disallowed.

Reviewed By: #clang-language-wg, shafik

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

Added: 


Modified: 
clang/test/CXX/drs/dr22xx.cpp
clang/www/cxx_dr_status.html

Removed: 




diff  --git a/clang/test/CXX/drs/dr22xx.cpp b/clang/test/CXX/drs/dr22xx.cpp
index c14c1f1e7c7a9..414925f0d74cc 100644
--- a/clang/test/CXX/drs/dr22xx.cpp
+++ b/clang/test/CXX/drs/dr22xx.cpp
@@ -14,6 +14,14 @@ void f() {
 }
 #endif
 
+namespace dr2213 { // dr2213: yes
+template 
+struct A;
+
+template 
+struct A;
+} // namespace dr2213
+
 namespace dr2229 { // dr2229: 7
 struct AnonBitfieldQualifiers {
   const unsigned : 1; // expected-error {{anonymous bit-field cannot have 
qualifiers}}

diff  --git a/clang/www/cxx_dr_status.html b/clang/www/cxx_dr_status.html
index 6a04e17ecc137..4f687e9bcbdcc 100755
--- a/clang/www/cxx_dr_status.html
+++ b/clang/www/cxx_dr_status.html
@@ -13085,7 +13085,7 @@ C++ defect report implementation 
status
 https://cplusplus.github.io/CWG/issues/2213.html";>2213
 CD6
 Forward declaration of partial specializations
-Unknown
+Yes
   
   
 https://cplusplus.github.io/CWG/issues/2214.html";>2214



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


[PATCH] D151032: [clang] Add test for CWG2213

2023-05-23 Thread Vlad Serebrennikov via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG71bc3dd42e29: [clang] Add test for CWG2213 (authored by 
Endill).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151032

Files:
  clang/test/CXX/drs/dr22xx.cpp
  clang/www/cxx_dr_status.html


Index: clang/www/cxx_dr_status.html
===
--- clang/www/cxx_dr_status.html
+++ clang/www/cxx_dr_status.html
@@ -13085,7 +13085,7 @@
 https://cplusplus.github.io/CWG/issues/2213.html";>2213
 CD6
 Forward declaration of partial specializations
-Unknown
+Yes
   
   
 https://cplusplus.github.io/CWG/issues/2214.html";>2214
Index: clang/test/CXX/drs/dr22xx.cpp
===
--- clang/test/CXX/drs/dr22xx.cpp
+++ clang/test/CXX/drs/dr22xx.cpp
@@ -14,6 +14,14 @@
 }
 #endif
 
+namespace dr2213 { // dr2213: yes
+template 
+struct A;
+
+template 
+struct A;
+} // namespace dr2213
+
 namespace dr2229 { // dr2229: 7
 struct AnonBitfieldQualifiers {
   const unsigned : 1; // expected-error {{anonymous bit-field cannot have 
qualifiers}}


Index: clang/www/cxx_dr_status.html
===
--- clang/www/cxx_dr_status.html
+++ clang/www/cxx_dr_status.html
@@ -13085,7 +13085,7 @@
 https://cplusplus.github.io/CWG/issues/2213.html";>2213
 CD6
 Forward declaration of partial specializations
-Unknown
+Yes
   
   
 https://cplusplus.github.io/CWG/issues/2214.html";>2214
Index: clang/test/CXX/drs/dr22xx.cpp
===
--- clang/test/CXX/drs/dr22xx.cpp
+++ clang/test/CXX/drs/dr22xx.cpp
@@ -14,6 +14,14 @@
 }
 #endif
 
+namespace dr2213 { // dr2213: yes
+template 
+struct A;
+
+template 
+struct A;
+} // namespace dr2213
+
 namespace dr2229 { // dr2229: 7
 struct AnonBitfieldQualifiers {
   const unsigned : 1; // expected-error {{anonymous bit-field cannot have qualifiers}}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 85452b5 - [clang] Add tests for CWG issues 977, 1482, 2516

2023-05-23 Thread Vlad Serebrennikov via cfe-commits

Author: Vlad Serebrennikov
Date: 2023-05-23T12:50:42+03:00
New Revision: 85452b5f9b5aba5bdf0259b7f0d7400362f95535

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

LOG: [clang] Add tests for CWG issues 977, 1482, 2516

CWG977 focus on point of /completeness/ of enums. Wording provided in CWG1482.
CWG1482 and CWG2516 focus on locus (point) of /declaration/. Wording provided 
in CWG2516.

Reviewed By: #clang-language-wg, shafik

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

Added: 


Modified: 
clang/test/CXX/drs/dr14xx.cpp
clang/test/CXX/drs/dr25xx.cpp
clang/test/CXX/drs/dr9xx.cpp
clang/www/cxx_dr_status.html

Removed: 




diff  --git a/clang/test/CXX/drs/dr14xx.cpp b/clang/test/CXX/drs/dr14xx.cpp
index 9d667db9945fd..ea41a03d3587a 100644
--- a/clang/test/CXX/drs/dr14xx.cpp
+++ b/clang/test/CXX/drs/dr14xx.cpp
@@ -488,6 +488,17 @@ namespace dr1479 { // dr1479: yes
   int operator"" _a(const char*, std::size_t = 0); // expected-error {{literal 
operator cannot have a default argument}}
 }
 
+namespace dr1482 { // dr1482: yes
+   // NB: sup 2516, test reused there
+#if __cplusplus >= 201103L
+template  struct S {
+  typedef char I;
+};
+enum E2 : S::I { e };
+// expected-error@-1 {{use of undeclared identifier 'E2'}}
+#endif
+} // namespace dr1482
+
 namespace dr1490 {  // dr1490: 3.7 c++11
   // List-initialization from a string literal
 

diff  --git a/clang/test/CXX/drs/dr25xx.cpp b/clang/test/CXX/drs/dr25xx.cpp
index 28ebda22a8017..b41f026e629f0 100644
--- a/clang/test/CXX/drs/dr25xx.cpp
+++ b/clang/test/CXX/drs/dr25xx.cpp
@@ -1,5 +1,16 @@
 // RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-unknown %s -verify
 
+namespace dr2516 { // dr2516: yes
+   // NB: reusing 1482 test
+#if __cplusplus >= 201103L
+template  struct S {
+  typedef char I;
+};
+enum E2 : S::I { e };
+// expected-error@-1 {{use of undeclared identifier 'E2'}}
+#endif
+} // namespace dr2516
+
 namespace dr2518 { // dr2518: 17
 
 template 

diff  --git a/clang/test/CXX/drs/dr9xx.cpp b/clang/test/CXX/drs/dr9xx.cpp
index 3d45dc8e72d2d..6022b640d1bef 100644
--- a/clang/test/CXX/drs/dr9xx.cpp
+++ b/clang/test/CXX/drs/dr9xx.cpp
@@ -90,6 +90,17 @@ namespace dr974 { // dr974: yes
 #endif
 }
 
+namespace dr977 { // dr977: yes
+enum E { e = E() };
+// expected-error@-1 {{invalid use of incomplete type 'E'}}
+// expected-note@-2 {{definition of 'dr977::E' is not complete until the 
closing '}'}}
+#if __cplusplus >= 201103L
+enum E2 : int { e2 = E2() };
+enum struct E3 { e = static_cast(E3()) };
+enum struct E4 : int { e = static_cast(E4()) };
+#endif
+} // namespace dr977
+
 namespace dr990 { // dr990: 3.5
 #if __cplusplus >= 201103L
   struct A { // expected-note 2{{candidate}}

diff  --git a/clang/www/cxx_dr_status.html b/clang/www/cxx_dr_status.html
index 4f687e9bcbdcc..cf4cdbb19a7e2 100755
--- a/clang/www/cxx_dr_status.html
+++ b/clang/www/cxx_dr_status.html
@@ -5669,7 +5669,7 @@ C++ defect report implementation 
status
 https://cplusplus.github.io/CWG/issues/977.html";>977
 CD3
 When is an enumeration type complete?
-Unknown
+Yes
   
   
 https://cplusplus.github.io/CWG/issues/978.html";>978
@@ -8699,7 +8699,7 @@ C++ defect report implementation 
status
 https://cplusplus.github.io/CWG/issues/1482.html";>1482
 CD3
 Point of declaration of enumeration
-Unknown
+Yes
   
   
 https://cplusplus.github.io/CWG/issues/1483.html";>1483
@@ -14903,7 +14903,7 @@ C++ defect report implementation 
status
 https://cplusplus.github.io/CWG/issues/2516.html";>2516
 DR
 Locus of enum-specifier or opaque-enum-declaration
-Unknown
+Yes
   
   
 https://cplusplus.github.io/CWG/issues/2517.html";>2517



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


[PATCH] D151042: [clang] Add tests for CWG issues 977, 1482, 2516

2023-05-23 Thread Vlad Serebrennikov via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG85452b5f9b5a: [clang] Add tests for CWG issues 977, 1482, 
2516 (authored by Endill).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151042

Files:
  clang/test/CXX/drs/dr14xx.cpp
  clang/test/CXX/drs/dr25xx.cpp
  clang/test/CXX/drs/dr9xx.cpp
  clang/www/cxx_dr_status.html


Index: clang/www/cxx_dr_status.html
===
--- clang/www/cxx_dr_status.html
+++ clang/www/cxx_dr_status.html
@@ -5669,7 +5669,7 @@
 https://cplusplus.github.io/CWG/issues/977.html";>977
 CD3
 When is an enumeration type complete?
-Unknown
+Yes
   
   
 https://cplusplus.github.io/CWG/issues/978.html";>978
@@ -8699,7 +8699,7 @@
 https://cplusplus.github.io/CWG/issues/1482.html";>1482
 CD3
 Point of declaration of enumeration
-Unknown
+Yes
   
   
 https://cplusplus.github.io/CWG/issues/1483.html";>1483
@@ -14903,7 +14903,7 @@
 https://cplusplus.github.io/CWG/issues/2516.html";>2516
 DR
 Locus of enum-specifier or opaque-enum-declaration
-Unknown
+Yes
   
   
 https://cplusplus.github.io/CWG/issues/2517.html";>2517
Index: clang/test/CXX/drs/dr9xx.cpp
===
--- clang/test/CXX/drs/dr9xx.cpp
+++ clang/test/CXX/drs/dr9xx.cpp
@@ -90,6 +90,17 @@
 #endif
 }
 
+namespace dr977 { // dr977: yes
+enum E { e = E() };
+// expected-error@-1 {{invalid use of incomplete type 'E'}}
+// expected-note@-2 {{definition of 'dr977::E' is not complete until the 
closing '}'}}
+#if __cplusplus >= 201103L
+enum E2 : int { e2 = E2() };
+enum struct E3 { e = static_cast(E3()) };
+enum struct E4 : int { e = static_cast(E4()) };
+#endif
+} // namespace dr977
+
 namespace dr990 { // dr990: 3.5
 #if __cplusplus >= 201103L
   struct A { // expected-note 2{{candidate}}
Index: clang/test/CXX/drs/dr25xx.cpp
===
--- clang/test/CXX/drs/dr25xx.cpp
+++ clang/test/CXX/drs/dr25xx.cpp
@@ -1,5 +1,16 @@
 // RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-unknown %s -verify
 
+namespace dr2516 { // dr2516: yes
+   // NB: reusing 1482 test
+#if __cplusplus >= 201103L
+template  struct S {
+  typedef char I;
+};
+enum E2 : S::I { e };
+// expected-error@-1 {{use of undeclared identifier 'E2'}}
+#endif
+} // namespace dr2516
+
 namespace dr2518 { // dr2518: 17
 
 template 
Index: clang/test/CXX/drs/dr14xx.cpp
===
--- clang/test/CXX/drs/dr14xx.cpp
+++ clang/test/CXX/drs/dr14xx.cpp
@@ -488,6 +488,17 @@
   int operator"" _a(const char*, std::size_t = 0); // expected-error {{literal 
operator cannot have a default argument}}
 }
 
+namespace dr1482 { // dr1482: yes
+   // NB: sup 2516, test reused there
+#if __cplusplus >= 201103L
+template  struct S {
+  typedef char I;
+};
+enum E2 : S::I { e };
+// expected-error@-1 {{use of undeclared identifier 'E2'}}
+#endif
+} // namespace dr1482
+
 namespace dr1490 {  // dr1490: 3.7 c++11
   // List-initialization from a string literal
 


Index: clang/www/cxx_dr_status.html
===
--- clang/www/cxx_dr_status.html
+++ clang/www/cxx_dr_status.html
@@ -5669,7 +5669,7 @@
 https://cplusplus.github.io/CWG/issues/977.html";>977
 CD3
 When is an enumeration type complete?
-Unknown
+Yes
   
   
 https://cplusplus.github.io/CWG/issues/978.html";>978
@@ -8699,7 +8699,7 @@
 https://cplusplus.github.io/CWG/issues/1482.html";>1482
 CD3
 Point of declaration of enumeration
-Unknown
+Yes
   
   
 https://cplusplus.github.io/CWG/issues/1483.html";>1483
@@ -14903,7 +14903,7 @@
 https://cplusplus.github.io/CWG/issues/2516.html";>2516
 DR
 Locus of enum-specifier or opaque-enum-declaration
-Unknown
+Yes
   
   
 https://cplusplus.github.io/CWG/issues/2517.html";>2517
Index: clang/test/CXX/drs/dr9xx.cpp
===
--- clang/test/CXX/drs/dr9xx.cpp
+++ clang/test/CXX/drs/dr9xx.cpp
@@ -90,6 +90,17 @@
 #endif
 }
 
+namespace dr977 { // dr977: yes
+enum E { e = E() };
+// expected-error@-1 {{invalid use of incomplete type 'E'}}
+// expected-note@-2 {{definition of 'dr977::E' is not complete until the closing '}'}}
+#if __cplusplus >= 201103L
+enum E2 : int { e2 = E2() };
+enum struct E3 { e = static_cast(E3()) };
+enum struct E4 : int { e = static_cast(E4()) };
+#endif
+} // namespace dr977
+
 namespace dr990 { // dr990: 3.5
 #if __cplusplus >= 201103L
   struct A { // expected-note 2{{candidate}}
Index: clang/test/CXX/drs/dr25xx.cpp
===
--- cl

[PATCH] D150800: [AArch64][FMV] Fix name mangling.

2023-05-23 Thread Daniel Kiss via Phabricator via cfe-commits
danielkiss accepted this revision.
danielkiss added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150800

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


[PATCH] D150867: [AArch64][FMV] Prevent target attribute using for multiversioning.

2023-05-23 Thread Daniel Kiss via Phabricator via cfe-commits
danielkiss accepted this revision.
danielkiss added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150867

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


[PATCH] D150937: [clang-repl] Disable all tests on unsupported platforms

2023-05-23 Thread Jun Zhang via Phabricator via cfe-commits
junaire abandoned this revision.
junaire added a comment.

This isn't an ideal solution after an off-list discussion.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150937

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


[PATCH] D151166: [clangd] Interactive AST matchers with #pragma clang query

2023-05-23 Thread Vlad Serebrennikov via Phabricator via cfe-commits
Endill added a comment.

This is an interesting feature!
There's a related `#pragma clang __debug dump`, that dumps name lookup result 
or a bit of AST for expression you pass to it 
(https://clang.llvm.org/docs/LanguageExtensions.html#debugging-the-compiler). I 
think clangd might be interested to support that pragma as well.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151166

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


[PATCH] D150427: [AMDGPU] Non hostcall printf support for HIP

2023-05-23 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added inline comments.



Comment at: clang/test/CodeGenHIP/printf_nonhostcall.cpp:170-171
+// CHECK-NEXT:[[PRINTBUFFNEXTPTR5:%.*]] = getelementptr i8, ptr 
addrspace(1) [[PRINTBUFFNEXTPTR4]], i32 8
+// CHECK-NEXT:[[TMP13:%.*]] = bitcast double [[TMP4]] to i64
+// CHECK-NEXT:store i64 [[TMP13]], ptr addrspace(1) [[PRINTBUFFNEXTPTR5]], 
align 8
+// CHECK-NEXT:[[PRINTBUFFNEXTPTR6:%.*]] = getelementptr i8, ptr 
addrspace(1) [[PRINTBUFFNEXTPTR5]], i32 8

Just store the double, don't need the bitcast?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150427

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


[PATCH] D148700: [clang] Add support for “regular” keyword attributes

2023-05-23 Thread Richard Sandiford via Phabricator via cfe-commits
rsandifo-arm added a comment.

Hi @erichkeane  and @aaron.ballman.  Does the updated patch look OK?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148700

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


[PATCH] D151197: [Clang][SVE2p1] Add svpsel builtins

2023-05-23 Thread Caroline via Phabricator via cfe-commits
CarolineConcatto created this revision.
Herald added subscribers: kristof.beyls, tschuett.
Herald added a project: All.
CarolineConcatto requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

As described in: https://github.com/ARM-software/acle/pull/257

Patch by : Sander de Smalen


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D151197

Files:
  clang/include/clang/Basic/arm_sve.td
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_psel.c
  clang/test/Sema/aarch64-sve2p1-intrinsics/acle_sve2p1_imm.cpp

Index: clang/test/Sema/aarch64-sve2p1-intrinsics/acle_sve2p1_imm.cpp
===
--- clang/test/Sema/aarch64-sve2p1-intrinsics/acle_sve2p1_imm.cpp
+++ clang/test/Sema/aarch64-sve2p1-intrinsics/acle_sve2p1_imm.cpp
@@ -27,6 +27,28 @@
   svpext_lane_c64_x2(c, 2); // expected-error {{argument value 2 is outside the valid range [0, 1]}}
 }
 
+void test_svpsel_lane_imm() {
+  svpsel_lane_b8(svptrue_b8(),   svptrue_b8(),  0, -1); // expected-error {{argument value 18446744073709551615 is outside the valid range [0, 15]}}
+  svpsel_lane_b16(svptrue_b16(), svptrue_b16(), 0, -1); // expected-error {{argument value 18446744073709551615 is outside the valid range [0, 7]}}
+  svpsel_lane_b32(svptrue_b32(), svptrue_b32(), 0, -1); // expected-error {{argument value 18446744073709551615 is outside the valid range [0, 3]}}
+  svpsel_lane_b64(svptrue_b64(), svptrue_b64(), 0, -1); // expected-error {{argument value 18446744073709551615 is outside the valid range [0, 1]}}
+
+  svpsel_lane_b8(svptrue_b8(),   svptrue_b8(),  0, 16); // expected-error {{argument value 16 is outside the valid range [0, 15]}}
+  svpsel_lane_b16(svptrue_b16(), svptrue_b16(), 0, 8);  // expected-error {{argument value 8 is outside the valid range [0, 7]}}
+  svpsel_lane_b32(svptrue_b32(), svptrue_b32(), 0, 4);  // expected-error {{argument value 4 is outside the valid range [0, 3]}}
+  svpsel_lane_b64(svptrue_b64(), svptrue_b64(), 0, 2);  // expected-error {{argument value 2 is outside the valid range [0, 1]}}
+
+  svpsel_lane_c8(svptrue_c8(),   svptrue_b8(),  0, -1); // expected-error {{argument value 18446744073709551615 is outside the valid range [0, 15]}}
+  svpsel_lane_c16(svptrue_c16(), svptrue_b16(), 0, -1); // expected-error {{argument value 18446744073709551615 is outside the valid range [0, 7]}}
+  svpsel_lane_c32(svptrue_c32(), svptrue_b32(), 0, -1); // expected-error {{argument value 18446744073709551615 is outside the valid range [0, 3]}}
+  svpsel_lane_c64(svptrue_c64(), svptrue_b64(), 0, -1); // expected-error {{argument value 18446744073709551615 is outside the valid range [0, 1]}}
+
+  svpsel_lane_c8(svptrue_c8(),   svptrue_b8(),  0, 16); // expected-error {{argument value 16 is outside the valid range [0, 15]}}
+  svpsel_lane_c16(svptrue_c16(), svptrue_b16(), 0, 8);  // expected-error {{argument value 8 is outside the valid range [0, 7]}}
+  svpsel_lane_c32(svptrue_c32(), svptrue_b32(), 0, 4);  // expected-error {{argument value 4 is outside the valid range [0, 3]}}
+  svpsel_lane_c64(svptrue_c64(), svptrue_b64(), 0, 2);  // expected-error {{argument value 2 is outside the valid range [0, 1]}}
+}
+
 void test_cntp(svcount_t c) {
   svcntp_c8(c, 1);  // expected-error {{argument value 1 is outside the valid range [2, 4]}}
   svcntp_c11(c, 1); // expected-error {{argument value 1 is outside the valid range [2, 4]}}
Index: clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_psel.c
===
--- /dev/null
+++ clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_psel.c
@@ -0,0 +1,164 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// REQUIRES: aarch64-registered-target
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu \
+// RUN:   -target-feature +sve2p1 -S -O1 -Werror -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu \
+// RUN:   -target-feature +sve2p1 -S -O1 -Werror -emit-llvm -o - -x c++ %s | FileCheck %s -check-prefix=CPP-CHECK
+
+#include 
+
+// CHECK-LABEL: @test_svpsel_lane_b8(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = add i32 [[IDX:%.*]], 15
+// CHECK-NEXT:[[TMP1:%.*]] = tail call  @llvm.aarch64.sve.psel.nxv16i1( [[P1:%.*]],  [[P2:%.*]], i32 [[TMP0]])
+// CHECK-NEXT:ret  [[TMP1]]
+//
+// CPP-CHECK-LABEL: @_Z19test_svpsel_lane_b8u10__SVBool_tu10__SVBool_tj(
+// CPP-CHECK-NEXT:  entry:
+// CPP-CHECK-NEXT:[[TMP0:%.*]] = add i32 [[IDX:%.*]], 15
+// CPP-CHECK-NEXT:[[TMP1:%.*]] = tail call  @llvm.aarch64.sve.psel.nxv16i1( [[P1:%.*]],  [[P2:%.*]], i32 [[TMP0]])
+// CPP-CHECK-NEXT:ret  [[TMP1]]
+//
+svbool_t test_svpsel_lane_b8(svbool_t p1, svbool_t p2, uint32_t idx) {
+  return svpsel_lane_b8(p1, p2, idx, 15);
+}
+
+// CHECK-LABEL: @test_svpsel_lane_b16(
+// CHECK-NE

[PATCH] D151192: [clang-tidy] have bugprone-unchecked-optional-access check boost::optional usage

2023-05-23 Thread Giel van Schijndel via Phabricator via cfe-commits
muggenhor added a comment.

Sure. Looking at the test I'm unsure though, are the `optional` implementations 
in there stripped copies of the real implementations? Or just a minimal 
implementation that fits the basic optional interface in the given namespace?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151192

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


[PATCH] D150635: [clangd] Implement end-definition-comment inlay hints

2023-05-23 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

Thanks, I'll try to repro those results.
100ms is significant in absolute terms, but >1s seems unacceptably slow.
I believe VSCode always sends ranges along with latency-sensitive hint 
requests, I think we currently just post-filter. If we propagate the limits 
deeper we should be able to filter much earlier and never hit these codepaths 
at all for 99% of the file.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150635

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


[clang] ea79b3b - Revert "[Sema] `setInvalidDecl` for error deduction declaration"

2023-05-23 Thread Tom Weaver via cfe-commits

Author: Tom Weaver
Date: 2023-05-23T11:44:51+01:00
New Revision: ea79b3bc39700791567796faeeb63d12f49b8c50

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

LOG: Revert "[Sema] `setInvalidDecl` for error deduction declaration"

This reverts commit eb5902ffc97163338bab95d2fd84a953ee76e96f.

Caused buildbot failures on:
  https://lab.llvm.org/buildbot/#/builders/139/builds/41248
  https://lab.llvm.org/buildbot/#/builders/216/builds/21637

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaDeclCXX.cpp
clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp
clang/test/CXX/temp/temp.res/temp.local/p3.cpp
clang/test/Parser/cxx1z-class-template-argument-deduction.cpp

Removed: 
clang/test/SemaCXX/invalid-deduction-guide-as-template-candidates.cpp



diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 915c9b0cf1014..a55e969fa21c1 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -392,8 +392,6 @@ Bug Fixes in This Version
 - Fix crash when attempting to perform parenthesized initialization of an
   aggregate with a base class with only non-public constructors.
   (`#62296 `_)
-- Fix crash when handling initialization candidates for invalid deduction 
guide.
-  (`#62408 `_)
 - Fix crash when redefining a variable with an invalid type again with an
   invalid type. (`#62447 `_)
 - Fix a stack overflow issue when evaluating ``consteval`` default arguments.

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index cb38329ca73a5..e869117a8ea66 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -7790,7 +7790,7 @@ class Sema final {
   void CheckConversionDeclarator(Declarator &D, QualType &R,
  StorageClass& SC);
   Decl *ActOnConversionDeclarator(CXXConversionDecl *Conversion);
-  bool CheckDeductionGuideDeclarator(Declarator &D, QualType &R,
+  void CheckDeductionGuideDeclarator(Declarator &D, QualType &R,
  StorageClass &SC);
   void CheckDeductionGuideTemplate(FunctionTemplateDecl *TD);
 

diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 27d76db386f3e..adebfe85be45d 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -9199,8 +9199,8 @@ static FunctionDecl *CreateNewFunctionDecl(Sema &SemaRef, 
Declarator &D,
   SemaRef.Diag(TrailingRequiresClause->getBeginLoc(),
diag::err_trailing_requires_clause_on_deduction_guide)
   << TrailingRequiresClause->getSourceRange();
-if (SemaRef.CheckDeductionGuideDeclarator(D, R, SC))
-  return nullptr;
+SemaRef.CheckDeductionGuideDeclarator(D, R, SC);
+
 return CXXDeductionGuideDecl::Create(SemaRef.Context, DC, D.getBeginLoc(),
  ExplicitSpecifier, NameInfo, R, TInfo,
  D.getEndLoc());

diff  --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 150697302c5e1..e68afaa61ef1c 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -11087,8 +11087,8 @@ struct BadSpecifierDiagnoser {
 /// Check the validity of a declarator that we parsed for a deduction-guide.
 /// These aren't actually declarators in the grammar, so we need to check that
 /// the user didn't specify any pieces that are not part of the deduction-guide
-/// grammar. Return true on invalid deduction-guide.
-bool Sema::CheckDeductionGuideDeclarator(Declarator &D, QualType &R,
+/// grammar.
+void Sema::CheckDeductionGuideDeclarator(Declarator &D, QualType &R,
  StorageClass &SC) {
   TemplateName GuidedTemplate = D.getName().TemplateName.get().get();
   TemplateDecl *GuidedTemplateDecl = GuidedTemplate.getAsTemplateDecl();
@@ -11138,7 +11138,7 @@ bool Sema::CheckDeductionGuideDeclarator(Declarator &D, 
QualType &R,
   }
 
   if (D.isInvalidType())
-return true;
+return;
 
   // Check the declarator is simple enough.
   bool FoundFunction = false;
@@ -11151,9 +11151,11 @@ bool Sema::CheckDeductionGuideDeclarator(Declarator 
&D, QualType &R,
   << D.getSourceRange();
   break;
 }
-if (!Chunk.Fun.hasTrailingReturnType())
-  return Diag(D.getName().getBeginLoc(),
+if (!Chunk.Fun.hasTrailingReturnType()) {
+  Diag(D.getName().getBeginLoc(),
diag::err_deduction_guide_no_trailing_return_type);
+  break;
+}
 
 // Check that the ret

[PATCH] D150758: [AIX] make integrated-as as default on AIX.

2023-05-23 Thread Esme Yi via Phabricator via cfe-commits
Esme updated this revision to Diff 524641.
Esme added a comment.

Separate the backend changes from this patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150758

Files:
  clang/lib/Driver/ToolChains/AIX.h
  clang/test/Driver/aix-as.c
  clang/test/Driver/aix-integrated-as.c


Index: clang/test/Driver/aix-integrated-as.c
===
--- /dev/null
+++ clang/test/Driver/aix-integrated-as.c
@@ -0,0 +1,17 @@
+// Test integrated-as is called by default on AIX.
+
+// Check powerpc-ibm-aix7.1.0.0, 32-bit.
+// RUN: %clang %s -### -c 2>&1 \
+// RUN: --target=powerpc-ibm-aix7.1.0.0 \
+// RUN:   | FileCheck --check-prefix=CHECK-IAS32 %s
+// CHECK-IAS32-NOT: "-a32"
+// CHECK-IAS32: "-cc1" "-triple" "powerpc-ibm-aix7.1.0.0" "-emit-obj"
+// CHECK-IAS32: "aix-integrated-as.o"
+
+// Check powerpc64-ibm-aix7.1.0.0, 64-bit.
+// RUN: %clang %s -### -c 2>&1 \
+// RUN: --target=powerpc64-ibm-aix7.1.0.0 \
+// RUN:   | FileCheck --check-prefix=CHECK-IAS64 %s
+// CHECK-IAS64-NOT: "-a64"
+// CHECK-IAS64: "-cc1" "-triple" "powerpc64-ibm-aix7.1.0.0" "-emit-obj"
+// CHECK-IAS64: "aix-integrated-as.o"
Index: clang/test/Driver/aix-as.c
===
--- clang/test/Driver/aix-as.c
+++ clang/test/Driver/aix-as.c
@@ -2,7 +2,7 @@
 // only test assembler functionalities in this suite.
 
 // Check powerpc-ibm-aix7.1.0.0, 32-bit.
-// RUN: %clang %s -### -c 2>&1 \
+// RUN: %clang %s -### -c 2>&1 -fno-integrated-as \
 // RUN: --target=powerpc-ibm-aix7.1.0.0 \
 // RUN:   | FileCheck --check-prefix=CHECK-AS32 %s
 // CHECK-AS32-NOT: warning:
@@ -12,7 +12,7 @@
 // CHECK-AS32: "-many" 
 
 // Check powerpc64-ibm-aix7.1.0.0, 64-bit.
-// RUN: %clang %s -### -c 2>&1 \
+// RUN: %clang %s -### -c 2>&1 -fno-integrated-as \
 // RUN: --target=powerpc64-ibm-aix7.1.0.0 \
 // RUN:   | FileCheck --check-prefix=CHECK-AS64 %s
 // CHECK-AS64-NOT: warning:
@@ -22,7 +22,7 @@
 // CHECK-AS64: "-many"
 
 // Check powerpc-ibm-aix7.1.0.0, 32-bit. -Xassembler  option. 
-// RUN: %clang %s -### -c 2>&1 \
+// RUN: %clang %s -### -c 2>&1 -fno-integrated-as \
 // RUN: -Xassembler -w \
 // RUN: --target=powerpc-ibm-aix7.1.0.0 \
 // RUN:   | FileCheck --check-prefix=CHECK-AS32-Xassembler %s
@@ -34,7 +34,7 @@
 // CHECK-AS32-Xassembler: "-w"
 
 // Check powerpc64-ibm-aix7.1.0.0, 64-bit. -Wa,, option.
-// RUN: %clang %s -### -c 2>&1 \
+// RUN: %clang %s -### -c 2>&1 -fno-integrated-as \
 // RUN: -Wa,-v,-w \
 // RUN: --target=powerpc64-ibm-aix7.1.0.0 \
 // RUN:   | FileCheck --check-prefix=CHECK-AS64-Wa %s
@@ -47,7 +47,7 @@
 // CHECK-AS64-Wa: "-w"
 
 // Check powerpc-ibm-aix7.1.0.0, 32-bit. Multiple input files.
-// RUN: %clang -### -c \
+// RUN: %clang -### -c -fno-integrated-as \
 // RUN: %S/Inputs/aix_ppc_tree/dummy0.s \
 // RUN: %S/Inputs/aix_ppc_tree/dummy1.s \
 // RUN: %S/Inputs/aix_ppc_tree/dummy2.s 2>&1 \
@@ -67,8 +67,8 @@
 // Check not passing no-integrated-as flag by default.
 // RUN: %clang %s -### -c 2>&1 --target=powerpc64-ibm-aix7.1.0.0 \
 // RUN:   | FileCheck --check-prefix=CHECK-IAS 
--implicit-check-not=-no-integrated-as %s
+// CHECK-IAS-NOT: "-a64"
 // CHECK-IAS: InstalledDir
-// CHECK-IAS: "-a64"
 
 // Check passing no-integrated-as flag if specified by user.
 // RUN: %clang %s -### -c 2>&1 --target=powerpc64-ibm-aix7.1.0.0 
-fno-integrated-as \
Index: clang/lib/Driver/ToolChains/AIX.h
===
--- clang/lib/Driver/ToolChains/AIX.h
+++ clang/lib/Driver/ToolChains/AIX.h
@@ -68,6 +68,7 @@
   }
   bool isPICDefaultForced() const override { return true; }
   bool HasNativeLLVMSupport() const override { return true; }
+  bool IsIntegratedAssemblerDefault() const override { return true; }
 
   void
   AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,


Index: clang/test/Driver/aix-integrated-as.c
===
--- /dev/null
+++ clang/test/Driver/aix-integrated-as.c
@@ -0,0 +1,17 @@
+// Test integrated-as is called by default on AIX.
+
+// Check powerpc-ibm-aix7.1.0.0, 32-bit.
+// RUN: %clang %s -### -c 2>&1 \
+// RUN: --target=powerpc-ibm-aix7.1.0.0 \
+// RUN:   | FileCheck --check-prefix=CHECK-IAS32 %s
+// CHECK-IAS32-NOT: "-a32"
+// CHECK-IAS32: "-cc1" "-triple" "powerpc-ibm-aix7.1.0.0" "-emit-obj"
+// CHECK-IAS32: "aix-integrated-as.o"
+
+// Check powerpc64-ibm-aix7.1.0.0, 64-bit.
+// RUN: %clang %s -### -c 2>&1 \
+// RUN: --target=powerpc64-ibm-aix7.1.0.0 \
+// RUN:   | FileCheck --check-prefix=CHECK-IAS64 %s
+// CHECK-IAS64-NOT: "-a64"
+// CHECK-IAS64: "-cc1" "-triple" "powerpc64-ibm-aix7.1.0.0" "-emit-obj"
+// CHECK-IAS64: "aix-integrated-as.o"
Index: clang/test/Driver/aix-as.c

[PATCH] D149516: [Sema] `setInvalidDecl` for error deduction declaration

2023-05-23 Thread Tom Weaver via Phabricator via cfe-commits
TWeaver added a comment.

The build bot failures have been going for a while now so I've had to revert 
this until the author can address them, my apologies.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149516

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


[PATCH] D149444: [ARM] Allow codegen for Armv6m eXecute-Only (XO) sections

2023-05-23 Thread Ties Stuij via Phabricator via cfe-commits
stuij added inline comments.



Comment at: llvm/lib/Target/ARM/ARMSubtarget.cpp:434
   // range otherwise.
-  return !NoMovt && hasV8MBaselineOps() &&
+  return !NoMovt && hasV6MOps() &&
  (isTargetWindows() || !OptMinSize || genExecuteOnly());

simonwallis2 wrote:
> simonwallis2 wrote:
> > V6M does not have Movt.
> > At face value, this line looks wrong and leads to about 30 unit test fails.
> > 
> I clarify: there are no test fails with this patch on its own.
> The unit test fails I saw where when building this patch in conjunction with 
> related patch https://reviews.llvm.org/D149443
Correct, this shouldn't be here. Initially it looked like we were going to 
repurpose movt for v6m, but that should have been part of another patch. And 
now it looks like we'll handle v6m immediates separately. In any case I'll 
remove this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149444

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


[PATCH] D151199: [Clang][SVE2.1] Add pfalse builtin

2023-05-23 Thread Caroline via Phabricator via cfe-commits
CarolineConcatto created this revision.
Herald added subscribers: kristof.beyls, tschuett.
Herald added a project: All.
CarolineConcatto requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

As described in: https://github.com/ARM-software/acle/pull/257

Patch by : Sander de Smalen


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D151199

Files:
  clang/include/clang/Basic/arm_sve.td
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_pfalse.c


Index: clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_pfalse.c
===
--- /dev/null
+++ clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_pfalse.c
@@ -0,0 +1,30 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// REQUIRES: aarch64-registered-target
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve2p1 -S 
-disable-O0-optnone -Werror -Wall -emit-llvm -o - %s | opt -S 
-passes=mem2reg,tailcallelim | FileCheck %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve2p1 -S 
-disable-O0-optnone -Werror -Wall -emit-llvm -o - -x c++ %s | opt -S 
-passes=mem2reg,tailcallelim | FileCheck %s -check-prefix=CPP-CHECK
+// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu 
-target-feature +sve2p1 -S -disable-O0-optnone -Werror -Wall -emit-llvm -o - %s 
| opt -S -passes=mem2reg,tailcallelim | FileCheck %s
+// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu 
-target-feature +sve2p1 -S -disable-O0-optnone -Werror -Wall -emit-llvm -o - -x 
c++ %s | opt -S -passes=mem2reg,tailcallelim | FileCheck %s 
-check-prefix=CPP-CHECK
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve2p1 -S 
-disable-O0-optnone -Werror -Wall -o /dev/null %s
+#include 
+
+#ifdef SVE_OVERLOADED_FORMS
+// A simple used,unused... macro, long enough to represent any SVE builtin.
+#define SVE_ACLE_FUNC(A1,A2_UNUSED,A3,A4_UNUSED) A1##A3
+#else
+#define SVE_ACLE_FUNC(A1,A2,A3,A4) A1##A2##A3##A4
+#endif
+
+// CHECK-LABEL: @test_svpfalse_c(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = tail call target("aarch64.svcount") 
@llvm.aarch64.sve.convert.from.svbool.taarch64.svcountt( 
zeroinitializer)
+// CHECK-NEXT:ret target("aarch64.svcount") [[TMP0]]
+//
+// CPP-CHECK-LABEL: @_Z15test_svpfalse_cv(
+// CPP-CHECK-NEXT:  entry:
+// CPP-CHECK-NEXT:[[TMP0:%.*]] = tail call target("aarch64.svcount") 
@llvm.aarch64.sve.convert.from.svbool.taarch64.svcountt( 
zeroinitializer)
+// CPP-CHECK-NEXT:ret target("aarch64.svcount") [[TMP0]]
+//
+svcount_t test_svpfalse_c()
+{
+  return SVE_ACLE_FUNC(svpfalse_c,,,)();
+}
Index: clang/lib/CodeGen/CGBuiltin.cpp
===
--- clang/lib/CodeGen/CGBuiltin.cpp
+++ clang/lib/CodeGen/CGBuiltin.cpp
@@ -9771,6 +9771,13 @@
   case SVE::BI__builtin_sve_svpfalse_b:
 return ConstantInt::getFalse(Ty);
 
+  case SVE::BI__builtin_sve_svpfalse_c: {
+auto SVBoolTy = ScalableVectorType::get(Builder.getInt1Ty(), 16);
+Function *CastToSVCountF =
+CGM.getIntrinsic(Intrinsic::aarch64_sve_convert_from_svbool, Ty);
+return Builder.CreateCall(CastToSVCountF, ConstantInt::getFalse(SVBoolTy));
+  }
+
   case SVE::BI__builtin_sve_svlen_bf16:
   case SVE::BI__builtin_sve_svlen_f16:
   case SVE::BI__builtin_sve_svlen_f32:
Index: clang/include/clang/Basic/arm_sve.td
===
--- clang/include/clang/Basic/arm_sve.td
+++ clang/include/clang/Basic/arm_sve.td
@@ -2115,6 +2115,7 @@
 let TargetGuard = "sve2p1" in {
 def SVFCLAMP   : SInst<"svclamp[_{d}]", "", "hfd", MergeNone, 
"aarch64_sve_fclamp", [], []>;
   def SVPTRUE_COUNT  : SInst<"svptrue_{d}", "}v", "QcQsQiQl", MergeNone, 
"aarch64_sve_ptrue_{d}", [IsOverloadNone], []>;
+def SVPFALSE_COUNT_ALIAS : SInst<"svpfalse_c", "}v", "", MergeNone, "", 
[IsOverloadNone]>;
   def SVCNTP_COUNT : SInst<"svcntp_{d}", "n}i", "QcQsQiQl", MergeNone, 
"aarch64_sve_cntp_{d}", [IsOverloadNone], [ImmCheck<1, ImmCheck2_4_Mul2>]>;
 
 def SVPEXT_SINGLE : SInst<"svpext_lane_{d}", "P}i", "QcQsQiQl", MergeNone, 
"aarch64_sve_pext", [], [ImmCheck<1, ImmCheck0_3>]>;


Index: clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_pfalse.c
===
--- /dev/null
+++ clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_pfalse.c
@@ -0,0 +1,30 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// REQUIRES: aarch64-registered-target
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve2p1 -S -disable-O0-optnone -Werror -Wall -emit-llvm -o - %s | opt -S -passes=mem2reg,tailcallelim | FileCheck %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve2p1 -S -disable-O0-optnone -Werror -Wall -

[PATCH] D151185: [clangd] Store paths as requested in PreambleStatCache

2023-05-23 Thread Haojian Wu via Phabricator via cfe-commits
hokein accepted this revision.
hokein added a comment.
This revision is now accepted and ready to land.

good catch!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151185

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


[PATCH] D151094: [clang] Implement P2564 "consteval must propagate up"

2023-05-23 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon added inline comments.



Comment at: clang/lib/Parse/ParseDecl.cpp:2495
 } else {
+  EnterExpressionEvaluationContext Ctx(
+  Actions, Sema::ExpressionEvaluationContext::PotentiallyEvaluated);

What is the point for an additional expression evaluation context here?



Comment at: clang/lib/Sema/SemaDeclCXX.cpp:2477
+  if (const auto *DR =
+  llvm::dyn_cast(E->getCallee()->IgnoreImplicit());
+  DR && DR->isImmediateEscalating()) {





Comment at: clang/lib/Sema/SemaExpr.cpp:17960
+if (auto *DeclRef =
+dyn_cast(Call->getCallee()->IgnoreImplicit()))
+  DeclRef->setIsImmediateEscalating(true);

`CallExpr::getCallee()` can return `nullptr` for example for indirect calls. 
Probably makes sense to check that it is not `nullptr` before accessing it.



Comment at: clang/lib/Sema/SemaExpr.cpp:17966
+
+  getCurFunction()->FoundImmediateEscalatingExpression = true;
+}

Same is actually for `getCurFunction()`. Can be a `nullptr` if there is no 
function.



Comment at: clang/lib/Sema/SemaExpr.cpp:18202-18203
   for (auto *DR : Rec.ReferenceToConsteval) {
-NamedDecl *ND = cast(DR->getDecl());
-if (auto *MD = llvm::dyn_cast(ND);
+const auto *FD = cast(DR->getDecl());
+const NamedDecl *ND = cast(DR->getDecl());
+if (const auto *MD = llvm::dyn_cast(ND);





Comment at: clang/lib/Sema/SemaExpr.cpp:18204
+const NamedDecl *ND = cast(DR->getDecl());
+if (const auto *MD = llvm::dyn_cast(ND);
 MD && (MD->isLambdaStaticInvoker() || isLambdaCallOperator(MD)))





Comment at: clang/test/SemaCXX/cxx2a-consteval-default-params.cpp:1
 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 %s
 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++23 %s

Should the new behavior only be enabled for c++23?



Comment at: clang/test/SemaCXX/cxx2b-consteval-propagate.cpp:1
+
+// RUN: %clang_cc1 -std=c++2a -emit-llvm-only -Wno-unused-value %s -verify

New line is not needed here, I guess.



Comment at: clang/test/SemaCXX/cxx2b-consteval-propagate.cpp:8
+
+namespace examples {
+

These examples exactly match the ones provided by P2564R3, should they be in a 
separate test in `CXX` directory then?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151094

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


[PATCH] D151200: [Clang][C++20] Error out if parameter types of a defaulted comparion operator are not all the same.

2023-05-23 Thread Jens Massberg via Phabricator via cfe-commits
massberg created this revision.
massberg added a reviewer: usaxena95.
Herald added a project: All.
massberg requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This fixes #62880


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D151200

Files:
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/CXX/class/class.compare/class.compare.default/p1.cpp


Index: clang/test/CXX/class/class.compare/class.compare.default/p1.cpp
===
--- clang/test/CXX/class/class.compare/class.compare.default/p1.cpp
+++ clang/test/CXX/class/class.compare/class.compare.default/p1.cpp
@@ -27,6 +27,14 @@
 bool operator==(const A&) const = default; // expected-error {{comparison 
operator template cannot be defaulted}}
 };
 
+template struct D {
+  C i;
+  friend bool operator==(const D&, D) = default; // expected-error {{must have 
the same type}}
+  friend bool operator>(D, const D&) = default; // expected-error {{must have 
the same type}}
+  friend bool operator<(const D&, const D&) = default;
+  friend bool operator<=(D, D) = default;
+};
+
 template struct Dependent {
   using U = typename T::type;
   bool operator==(U) const = default; // expected-error {{found 'U'}}
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -8626,8 +8626,7 @@
   const ParmVarDecl *KnownParm = nullptr;
   for (const ParmVarDecl *Param : FD->parameters()) {
 QualType ParmTy = Param->getType();
-if (ParmTy->isDependentType())
-  continue;
+
 if (!KnownParm) {
   auto CTy = ParmTy;
   // Is it `T const &`?
@@ -8656,6 +8655,8 @@
   if (Ok) {
 KnownParm = Param;
   } else {
+if (ParmTy->isDependentType())
+  continue;
 // Don't diagnose an implicit 'operator=='; we will have diagnosed the
 // corresponding defaulted 'operator<=>' already.
 if (!FD->isImplicit()) {
@@ -8675,7 +8676,8 @@
 }
 return true;
   }
-} else if (!Context.hasSameType(KnownParm->getType(), ParmTy)) {
+}
+if (KnownParm && !Context.hasSameType(KnownParm->getType(), ParmTy)) {
   Diag(FD->getLocation(), diag::err_defaulted_comparison_param_mismatch)
   << int(DCK) << KnownParm->getType() << KnownParm->getSourceRange()
   << ParmTy << Param->getSourceRange();


Index: clang/test/CXX/class/class.compare/class.compare.default/p1.cpp
===
--- clang/test/CXX/class/class.compare/class.compare.default/p1.cpp
+++ clang/test/CXX/class/class.compare/class.compare.default/p1.cpp
@@ -27,6 +27,14 @@
 bool operator==(const A&) const = default; // expected-error {{comparison operator template cannot be defaulted}}
 };
 
+template struct D {
+  C i;
+  friend bool operator==(const D&, D) = default; // expected-error {{must have the same type}}
+  friend bool operator>(D, const D&) = default; // expected-error {{must have the same type}}
+  friend bool operator<(const D&, const D&) = default;
+  friend bool operator<=(D, D) = default;
+};
+
 template struct Dependent {
   using U = typename T::type;
   bool operator==(U) const = default; // expected-error {{found 'U'}}
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -8626,8 +8626,7 @@
   const ParmVarDecl *KnownParm = nullptr;
   for (const ParmVarDecl *Param : FD->parameters()) {
 QualType ParmTy = Param->getType();
-if (ParmTy->isDependentType())
-  continue;
+
 if (!KnownParm) {
   auto CTy = ParmTy;
   // Is it `T const &`?
@@ -8656,6 +8655,8 @@
   if (Ok) {
 KnownParm = Param;
   } else {
+if (ParmTy->isDependentType())
+  continue;
 // Don't diagnose an implicit 'operator=='; we will have diagnosed the
 // corresponding defaulted 'operator<=>' already.
 if (!FD->isImplicit()) {
@@ -8675,7 +8676,8 @@
 }
 return true;
   }
-} else if (!Context.hasSameType(KnownParm->getType(), ParmTy)) {
+}
+if (KnownParm && !Context.hasSameType(KnownParm->getType(), ParmTy)) {
   Diag(FD->getLocation(), diag::err_defaulted_comparison_param_mismatch)
   << int(DCK) << KnownParm->getType() << KnownParm->getSourceRange()
   << ParmTy << Param->getSourceRange();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D151201: [clang][dataflow] Fix a crash in `getLogicOperatorSubExprValue()`.

2023-05-23 Thread Martin Böhme via Phabricator via cfe-commits
mboehme created this revision.
Herald added subscribers: martong, xazax.hun.
Herald added a reviewer: NoQ.
Herald added a project: All.
mboehme requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This patch adds a test that crashes without the fix.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D151201

Files:
  clang/lib/Analysis/FlowSensitive/Transfer.cpp
  clang/unittests/Analysis/FlowSensitive/TransferTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -5056,6 +5056,20 @@
   });
 }
 
+// Repro for a crash that used to occur with chained short-circuiting logical
+// operators.
+TEST(TransferTest, ChainedLogicalOps) {
+  std::string Code = R"(
+bool target() {
+  return true || false || false || false;
+}
+  )";
+  runDataflow(
+  Code,
+  [](const llvm::StringMap> &Results,
+ ASTContext &ASTCtx) {});
+}
+
 // Repro for a crash that used to occur when we call a `noreturn` function
 // within one of the operands of a `&&` or `||` operator.
 TEST(TransferTest, NoReturnFunctionInsideShortCircuitedBooleanOp) {
Index: clang/lib/Analysis/FlowSensitive/Transfer.cpp
===
--- clang/lib/Analysis/FlowSensitive/Transfer.cpp
+++ clang/lib/Analysis/FlowSensitive/Transfer.cpp
@@ -194,24 +194,13 @@
   auto &Loc = Env.createStorageLocation(*S);
   Env.setStorageLocation(*S, Loc);
 
-  BoolValue *LHSVal = getLogicOperatorSubExprValue(*LHS);
-  // If the LHS was not reachable, this BinaryOperator would also not be
-  // reachable, and we would never get here.
-  assert(LHSVal != nullptr);
-  BoolValue *RHSVal = getLogicOperatorSubExprValue(*RHS);
-  if (RHSVal == nullptr) {
-// If the RHS isn't reachable and we evaluate this BinaryOperator,
-// then the value of the LHS must have triggered the short-circuit
-// logic. This implies that the value of the entire expression must be
-// equal to the value of the LHS.
-Env.setValue(Loc, *LHSVal);
-break;
-  }
+  BoolValue &LHSVal = getLogicOperatorSubExprValue(*LHS);
+  BoolValue &RHSVal = getLogicOperatorSubExprValue(*RHS);
 
   if (S->getOpcode() == BO_LAnd)
-Env.setValue(Loc, Env.makeAnd(*LHSVal, *RHSVal));
+Env.setValue(Loc, Env.makeAnd(LHSVal, RHSVal));
   else
-Env.setValue(Loc, Env.makeOr(*LHSVal, *RHSVal));
+Env.setValue(Loc, Env.makeOr(LHSVal, RHSVal));
   break;
 }
 case BO_NE:
@@ -811,35 +800,29 @@
   }
 
 private:
-  /// If `SubExpr` is reachable, returns a non-null pointer to the value for
-  /// `SubExpr`. If `SubExpr` is not reachable, returns nullptr.
-  BoolValue *getLogicOperatorSubExprValue(const Expr &SubExpr) {
+  /// Returns the value for the sub-expression `SubExpr` of a logic operator.
+  BoolValue &getLogicOperatorSubExprValue(const Expr &SubExpr) {
 // `SubExpr` and its parent logic operator might be part of different basic
 // blocks. We try to access the value that is assigned to `SubExpr` in the
 // corresponding environment.
-const Environment *SubExprEnv = StmtToEnv.getEnvironment(SubExpr);
-if (!SubExprEnv)
-  return nullptr;
-
-if (auto *Val =
-dyn_cast_or_null(SubExprEnv->getValueStrict(SubExpr)))
-  return Val;
-
-if (Env.getValueStrict(SubExpr) == nullptr) {
-  // Sub-expressions that are logic operators are not added in basic blocks
-  // (e.g. see CFG for `bool d = a && (b || c);`). If `SubExpr` is a logic
-  // operator, it may not have been evaluated and assigned a value yet. In
-  // that case, we need to first visit `SubExpr` and then try to get the
-  // value that gets assigned to it.
+if (const Environment *SubExprEnv = StmtToEnv.getEnvironment(SubExpr))
+  if (auto *Val =
+  dyn_cast_or_null(SubExprEnv->getValueStrict(SubExpr)))
+return *Val;
+
+// The sub-expression may lie within a basic block that isn't reachable,
+// even if we need it to evaluate the current (reachable) expression
+// (see https://discourse.llvm.org/t/70775). In this case, visit `SubExpr`
+// within the current environment and then try to get the value that gets
+// assigned to it.
+if (Env.getValueStrict(SubExpr) == nullptr)
   Visit(&SubExpr);
-}
-
 if (auto *Val = dyn_cast_or_null(Env.getValueStrict(SubExpr)))
-  return Val;
+  return *Val;
 
 // If the value of `SubExpr` is still unknown, we create a fresh symbolic
 // boolean value for it.
-return &Env.makeAtomicBoolValue();
+return Env.makeAtomicBoolValue();
   }
 
   // If context sensitivity is enabled, try to analyze the body of the ca

[PATCH] D151192: [clang-tidy] have bugprone-unchecked-optional-access check boost::optional usage

2023-05-23 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr2 added a comment.

The mock optional types in the unit test are just declarations of the API - 
they don't need any implementations (function or method bodies should be 
omitted). But the declarations of classes, methods, and functions should mirror 
the production header closely. There are many seemingly trivial choices one can 
make when designing an API for a complex type like optional - for example, the 
specific choice of constructor overload set members, choosing to implement an 
overload set as a set of concrete functions vs. one function template, SFINAE 
on any functions, additional defaulted template parameters that the user isn't 
supposed to set etc. These differences would be hardly noticeable for the 
majority of "boring" C++ code that uses an optional, but they can be 
detrimental to tooling's ability to identify calls to the relevant APIs.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151192

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


[clang] 5111286 - Reland "Reland [clang-repl] Introduce Value to capture expression results"

2023-05-23 Thread Jun Zhang via cfe-commits

Author: Jun Zhang
Date: 2023-05-23T19:32:31+08:00
New Revision: 5111286f06e1e10f24745007a45a830760f1790c

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

LOG: Reland "Reland [clang-repl] Introduce Value to capture expression results"

This reverts commit 094ab4781262b6cb49d57b0ecdf84b047c879295.

Reland with changing `ParseAndExecute` to `Parse` in
`Interpreter::create`. This avoid creating JIT instance everytime even
if we don't really need them.

This should fixes failures like 
https://lab.llvm.org/buildbot/#/builders/38/builds/11955

The original reverted patch also causes GN bot fails on M1. 
(https://lab.llvm.org/buildbot/#/builders/38/builds/11955)
However, we can't reproduce it so let's reland it and see what happens.
See discussions here: 
https://reviews.llvm.org/rGd71a4e02277a64a9dece591cdf2b34f15c3b19a0

Added: 
clang/include/clang/Interpreter/Value.h
clang/lib/Interpreter/InterpreterUtils.cpp
clang/lib/Interpreter/InterpreterUtils.h
clang/lib/Interpreter/Value.cpp

Modified: 
clang/include/clang/Interpreter/Interpreter.h
clang/lib/Interpreter/CMakeLists.txt
clang/lib/Interpreter/IncrementalParser.cpp
clang/lib/Interpreter/IncrementalParser.h
clang/lib/Interpreter/Interpreter.cpp
clang/tools/clang-repl/CMakeLists.txt
clang/unittests/Interpreter/CMakeLists.txt
clang/unittests/Interpreter/InterpreterTest.cpp

Removed: 




diff  --git a/clang/include/clang/Interpreter/Interpreter.h 
b/clang/include/clang/Interpreter/Interpreter.h
index b3d64458d777c..e680218452d1c 100644
--- a/clang/include/clang/Interpreter/Interpreter.h
+++ b/clang/include/clang/Interpreter/Interpreter.h
@@ -14,14 +14,15 @@
 #ifndef LLVM_CLANG_INTERPRETER_INTERPRETER_H
 #define LLVM_CLANG_INTERPRETER_INTERPRETER_H
 
-#include "clang/Interpreter/PartialTranslationUnit.h"
-
+#include "clang/AST/Decl.h"
 #include "clang/AST/GlobalDecl.h"
+#include "clang/Interpreter/PartialTranslationUnit.h"
+#include "clang/Interpreter/Value.h"
 
+#include "llvm/ADT/DenseMap.h"
 #include "llvm/ExecutionEngine/JITSymbol.h"
 #include "llvm/ExecutionEngine/Orc/Shared/ExecutorAddress.h"
 #include "llvm/Support/Error.h"
-
 #include 
 #include 
 
@@ -54,24 +55,26 @@ class Interpreter {
   Interpreter(std::unique_ptr CI, llvm::Error &Err);
 
   llvm::Error CreateExecutor();
+  unsigned InitPTUSize = 0;
+
+  // This member holds the last result of the value printing. It's a class
+  // member because we might want to access it after more inputs. If no value
+  // printing happens, it's in an invalid state.
+  Value LastValue;
 
 public:
   ~Interpreter();
   static llvm::Expected>
   create(std::unique_ptr CI);
+  const ASTContext &getASTContext() const;
+  ASTContext &getASTContext();
   const CompilerInstance *getCompilerInstance() const;
   llvm::Expected getExecutionEngine();
 
   llvm::Expected Parse(llvm::StringRef Code);
   llvm::Error Execute(PartialTranslationUnit &T);
-  llvm::Error ParseAndExecute(llvm::StringRef Code) {
-auto PTU = Parse(Code);
-if (!PTU)
-  return PTU.takeError();
-if (PTU->TheModule)
-  return Execute(*PTU);
-return llvm::Error::success();
-  }
+  llvm::Error ParseAndExecute(llvm::StringRef Code, Value *V = nullptr);
+  llvm::Expected CompileDtorCall(CXXRecordDecl 
*CXXRD);
 
   /// Undo N previous incremental inputs.
   llvm::Error Undo(unsigned N = 1);
@@ -92,6 +95,23 @@ class Interpreter {
   /// file.
   llvm::Expected
   getSymbolAddressFromLinkerName(llvm::StringRef LinkerName) const;
+
+  enum InterfaceKind { NoAlloc, WithAlloc, CopyArray };
+
+  const llvm::SmallVectorImpl &getValuePrintingInfo() const {
+return ValuePrintingInfo;
+  }
+
+  Expr *SynthesizeExpr(Expr *E);
+
+private:
+  size_t getEffectivePTUSize() const;
+
+  bool FindRuntimeInterface();
+
+  llvm::DenseMap Dtors;
+
+  llvm::SmallVector ValuePrintingInfo;
 };
 } // namespace clang
 

diff  --git a/clang/include/clang/Interpreter/Value.h 
b/clang/include/clang/Interpreter/Value.h
new file mode 100644
index 0..4df4367030ecd
--- /dev/null
+++ b/clang/include/clang/Interpreter/Value.h
@@ -0,0 +1,202 @@
+//===--- Value.h - Definition of interpreter value --*- 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
+//
+//===--===//
+//
+// Value is a lightweight struct that is used for carrying execution results in
+// clang-repl. It's a special runtime that acts like a messager between 
compiled
+// code and interpreted code. This makes it possible to exchange interesting
+// information between the com

[PATCH] D151094: [clang] Implement P2564 "consteval must propagate up"

2023-05-23 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 524656.
cor3ntin marked 7 inline comments as done.
cor3ntin added a comment.

Address some of Mariya's comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151094

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/Decl.h
  clang/include/clang/AST/DeclBase.h
  clang/include/clang/AST/Expr.h
  clang/include/clang/AST/Stmt.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/ScopeInfo.h
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/Decl.cpp
  clang/lib/AST/DeclPrinter.cpp
  clang/lib/AST/Expr.cpp
  clang/lib/AST/ExprConstant.cpp
  clang/lib/AST/TextNodeDumper.cpp
  clang/lib/AST/VTableBuilder.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/Frontend/InitPreprocessor.cpp
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/lib/Sema/ScopeInfo.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaLambda.cpp
  clang/lib/Sema/SemaStmt.cpp
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/lib/Serialization/ASTReaderStmt.cpp
  clang/lib/Serialization/ASTWriterDecl.cpp
  clang/lib/Serialization/ASTWriterStmt.cpp
  clang/test/CodeGenCXX/cxx20-consteval-crash.cpp
  clang/test/SemaCXX/cxx2a-consteval-default-params.cpp
  clang/test/SemaCXX/cxx2a-consteval.cpp
  clang/test/SemaCXX/cxx2b-consteval-propagate.cpp
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -363,7 +363,7 @@
 
   consteval needs to propagate up
   https://wg21.link/P2564R3";>P2564R3 (DR)
-  No
+  Clang 17
 
 
   Lifetime extension in range-based for loops
Index: clang/test/SemaCXX/cxx2b-consteval-propagate.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/cxx2b-consteval-propagate.cpp
@@ -0,0 +1,130 @@
+// RUN: %clang_cc1 -std=c++2a -emit-llvm-only -Wno-unused-value %s -verify
+// RUN: %clang_cc1 -std=c++2b -emit-llvm-only -Wno-unused-value %s -verify
+
+consteval int id(int i) { return i; }
+constexpr char id(char c) { return c; }
+
+namespace examples {
+
+template 
+constexpr int f(T t) { // expected-note {{declared here}}
+return t + id(t);  // expected-note {{'f' is an immediate function because its body contains a call to a consteval function 'id' and that call is not a constant expression}}
+}
+auto a = &f; // ok, f is not an immediate function
+auto b = &f;  // expected-error {{cannot take address of immediate function 'f' outside of an immediate invocation}}
+
+static_assert(f(3) == 6); // ok
+
+template 
+constexpr int g(T t) {// g is not an immediate function
+return t + id(42);// because id(42) is already a constant
+}
+
+template 
+constexpr bool is_not(T t, F f) {
+return not f(t);
+}
+
+consteval bool is_even(int i) { return i % 2 == 0; }
+
+static_assert(is_not(5, is_even));
+
+int x = 0; // expected-note {{declared here}}
+
+template 
+constexpr T h(T t = id(x)) { // expected-note {{read of non-const variable 'x' is not allowed in a constant expression}} \
+ // expected-note {{'hh' is an immediate function because its body contains a call to a consteval function 'id' and that call is not a constant expression}}
+return t;
+}
+
+template 
+constexpr T hh() {   // hh is an immediate function
+return h();
+}
+
+int i = hh(); // expected-error {{call to consteval function 'examples::hh' is not a constant expression}} \
+   // expected-note {{in call to 'hh()'}}
+
+struct A {
+  int x;
+  int y = id(x);
+};
+
+template 
+constexpr int k(int) {
+  return A(42).y;
+}
+
+}
+
+namespace e2{
+template 
+constexpr int f(T t);
+auto a = &f;
+auto b = &f;
+}
+
+namespace forward_declare_constexpr{
+template 
+constexpr int f(T t);
+
+auto a = &f;
+auto b = &f;
+
+template 
+constexpr int f(T t) {
+return id(0);
+}
+}
+
+namespace forward_declare_consteval{
+template 
+constexpr int f(T t);  // expected-note {{'f' defined here}}
+
+auto a = &f;
+auto b = &f; // expected-error {{immediate function 'f' used before it is defined}} \
+  // expected-note {{in instantiation of function template specialization}}
+
+template 
+constexpr int f(T t) {
+return id(t); // expected-note {{'f' is an immediate function because its body contains a call to a consteval function 'id' and that call is not a constant expression}}
+}
+}
+
+namespace constructors {
+consteval int f(int) {
+  return 0;
+}
+struct S {
+  constexpr S(auto i) {
+f(i);
+  }
+};
+constexpr void g(auto i) {
+  [[maybe_unused]] S s{i};
+}
+void test() {
+  g(0);
+}
+}
+
+namespace aggregate {
+consteval int f(int);
+struct S{
+int a = 0;
+int b = f(a);
+};
+
+cons

[PATCH] D146358: [clang][AST] Print name instead of type when diagnosing uninitialized subobject in constexpr variables

2023-05-23 Thread Takuya Shimizu via Phabricator via cfe-commits
hazohelet updated this revision to Diff 524655.
hazohelet added a comment.

The cause of the regression has been fixed in the other patch.
This is a resubmission with rebase to the upstream.


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

https://reviews.llvm.org/D146358

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticASTKinds.td
  clang/lib/AST/ExprConstant.cpp
  clang/lib/AST/Interp/Interp.cpp
  clang/test/AST/Interp/cxx20.cpp
  clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p4.cpp
  clang/test/SemaCXX/constant-expression-cxx2a.cpp
  clang/test/SemaCXX/cxx2a-consteval.cpp

Index: clang/test/SemaCXX/cxx2a-consteval.cpp
===
--- clang/test/SemaCXX/cxx2a-consteval.cpp
+++ clang/test/SemaCXX/cxx2a-consteval.cpp
@@ -761,7 +761,7 @@
 };
 
 S s1; // expected-error {{call to consteval function 'NamespaceScopeConsteval::S::S' is not a constant expression}} \
- expected-note {{subobject of type 'int' is not initialized}}
+ expected-note {{subobject 'Val' is not initialized}}
 
 template 
 struct T {
@@ -770,7 +770,7 @@
 };
 
 T t; // expected-error {{call to consteval function 'NamespaceScopeConsteval::T::T' is not a constant expression}} \
- expected-note {{subobject of type 'int' is not initialized}}
+ expected-note {{subobject 'Val' is not initialized}}
 
 } // namespace NamespaceScopeConsteval
 
Index: clang/test/SemaCXX/constant-expression-cxx2a.cpp
===
--- clang/test/SemaCXX/constant-expression-cxx2a.cpp
+++ clang/test/SemaCXX/constant-expression-cxx2a.cpp
@@ -409,12 +409,12 @@
 b.a.x = 2;
 return b;
   }
-  constexpr B uninit = return_uninit(); // expected-error {{constant expression}} expected-note {{subobject of type 'int' is not initialized}}
+  constexpr B uninit = return_uninit(); // expected-error {{constant expression}} expected-note {{subobject 'y' is not initialized}}
   static_assert(return_uninit().a.x == 2);
   constexpr A return_uninit_struct() {
 B b = {.b = 1};
 b.a.x = 2;
-return b.a; // expected-note {{in call to 'A(b.a)'}} expected-note {{subobject of type 'int' is not initialized}}
+return b.a; // expected-note {{in call to 'A(b.a)'}} expected-note {{subobject 'y' is not initialized}}
   }
   // Note that this is rejected even though return_uninit() is accepted, and
   // return_uninit() copies the same stuff wrapped in a union.
@@ -558,7 +558,7 @@
 }
   };
   constinit X x1(true);
-  constinit X x2(false); // expected-error {{constant initializer}} expected-note {{constinit}} expected-note {{subobject of type 'int' is not initialized}}
+  constinit X x2(false); // expected-error {{constant initializer}} expected-note {{constinit}} expected-note {{subobject 'n' is not initialized}}
 
   struct Y {
 struct Z { int n; }; // expected-note {{here}}
@@ -577,7 +577,7 @@
   };
   // FIXME: This is working around clang not implementing DR2026. With that
   // fixed, we should be able to test this without the injected copy.
-  constexpr Y copy(Y y) { return y; } // expected-note {{in call to 'Y(y)'}} expected-note {{subobject of type 'int' is not initialized}}
+  constexpr Y copy(Y y) { return y; } // expected-note {{in call to 'Y(y)'}} expected-note {{subobject 'n' is not initialized}}
   constexpr Y y1 = copy(Y());
   static_assert(y1.z1.n == 1 && y1.z2.n == 2 && y1.z3.n == 3);
 
Index: clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p4.cpp
===
--- clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p4.cpp
+++ clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p4.cpp
@@ -360,7 +360,7 @@
   // The constructor is still 'constexpr' here, but the result is not intended
   // to be a constant expression. The standard is not clear on how this should
   // work.
-  constexpr V v; // expected-error {{constant expression}} expected-note {{subobject of type 'int' is not initialized}}
+  constexpr V v; // expected-error {{constant expression}} expected-note {{subobject 'y' is not initialized}}
 
   constexpr int k = V().x; // FIXME: ok?
 }
Index: clang/test/AST/Interp/cxx20.cpp
===
--- clang/test/AST/Interp/cxx20.cpp
+++ clang/test/AST/Interp/cxx20.cpp
@@ -143,9 +143,9 @@
 constexpr A() {}
   };
   constexpr A a; // expected-error {{must be initialized by a constant expression}} \
- // expected-note {{subobject of type 'int' is not initialized}} \
+ // expected-note {{subobject 'a' is not initialized}} \
  // ref-error {{must be initialized by a constant expression}} \
- // ref-note {{subobject of type 'int' is not initialized}}
+ // ref-note {{subobject 'a' is not initialized}}
 
 
   class Base {
@@ -161,18 +161,18 @@
 constexpr Derived() : Base() {}   };
 
   co

[clang] 75cce50 - [Driver] Fix test for use of ld from devtoolset (NFC)

2023-05-23 Thread Nikita Popov via cfe-commits

Author: Nikita Popov
Date: 2023-05-23T13:53:17+02:00
New Revision: 75cce50fd2d3869b97d66c280dc2b2c34f9b2818

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

LOG: [Driver] Fix test for use of ld from devtoolset (NFC)

The test added in c5fe10f365247c3dd9416b7ec8bad73a60b5946e contains
some typos in the check lines, due to which it never actually
verified what was intended.

Fix the test by adding the required input tree and adjusting the
check lines appropriately.

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

Added: 
clang/test/Driver/Inputs/rhel_7_tree/opt/rh/devtoolset-7/root/usr/bin/ld

clang/test/Driver/Inputs/rhel_7_tree/opt/rh/devtoolset-7/root/usr/lib/gcc/x86_64-redhat-linux/7/crtbegin.o

clang/test/Driver/Inputs/rhel_7_tree/opt/rh/devtoolset-7/root/usr/lib/gcc/x86_64-redhat-linux/7/crtend.o

Modified: 
clang/test/Driver/linux-ld.c

Removed: 




diff  --git 
a/clang/test/Driver/Inputs/rhel_7_tree/opt/rh/devtoolset-7/root/usr/bin/ld 
b/clang/test/Driver/Inputs/rhel_7_tree/opt/rh/devtoolset-7/root/usr/bin/ld
new file mode 100755
index 0..e69de29bb2d1d

diff  --git 
a/clang/test/Driver/Inputs/rhel_7_tree/opt/rh/devtoolset-7/root/usr/lib/gcc/x86_64-redhat-linux/7/crtbegin.o
 
b/clang/test/Driver/Inputs/rhel_7_tree/opt/rh/devtoolset-7/root/usr/lib/gcc/x86_64-redhat-linux/7/crtbegin.o
new file mode 100644
index 0..e69de29bb2d1d

diff  --git 
a/clang/test/Driver/Inputs/rhel_7_tree/opt/rh/devtoolset-7/root/usr/lib/gcc/x86_64-redhat-linux/7/crtend.o
 
b/clang/test/Driver/Inputs/rhel_7_tree/opt/rh/devtoolset-7/root/usr/lib/gcc/x86_64-redhat-linux/7/crtend.o
new file mode 100644
index 0..e69de29bb2d1d

diff  --git a/clang/test/Driver/linux-ld.c b/clang/test/Driver/linux-ld.c
index 512fccbd6503d..18ad0b9aa07b7 100644
--- a/clang/test/Driver/linux-ld.c
+++ b/clang/test/Driver/linux-ld.c
@@ -1794,12 +1794,11 @@
 // RUN: %clang -### %s -no-pie 2>&1 \
 // RUN: --target=x86_64-unknown-linux-gnu \
 // RUN: 
--gcc-toolchain="%S/Inputs/rhel_7_tree/opt/rh/devtoolset-7/root/usr" \
-// RUN: --sysroot=%S/Inputs/rhel_7_tree \
+// RUN: --sysroot="%S/Inputs/rhel_7_tree/opt/rh/devtoolset-7/root" \
 // RUN:   | FileCheck --check-prefix=CHECK-LD-RHEL7-DTS %s
-// CHECK-LD-RHEL7-DTS: "{{.*}}ld{{(.exe)?}}" "--sysroot=[[SYSROOT:[^"]+]]"
-// CHECK-LD-RHLE7-DTS: Selected GCC installation: 
[[GCC_INSTALL:[[SYSROOT]]/lib/gcc/x86_64-redhat-linux/7]]
+// CHECK-LD-RHEL7-DTS: "-isysroot" "[[SYSROOT:[^"]+]]"
 // CHECK-LD-RHEL7-DTS-NOT: /usr/bin/ld
-// CHECK-LD-RHLE7-DTS: [[GCC_INSTALL]/../../../bin/ld
+// CHECK-LD-RHEL7-DTS: 
[[SYSROOT]]/usr/lib/gcc/x86_64-redhat-linux/7/../../../../bin/ld
 
 // Check whether gcc7 install works fine on Amazon Linux AMI
 // RUN: %clang -### %s -no-pie 2>&1 \



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


[PATCH] D151195: [Driver] Fix test for use of ld from devtoolset

2023-05-23 Thread Nikita Popov via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG75cce50fd2d3: [Driver] Fix test for use of ld from 
devtoolset (NFC) (authored by nikic).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151195

Files:
  clang/test/Driver/Inputs/rhel_7_tree/opt/rh/devtoolset-7/root/usr/bin/ld
  
clang/test/Driver/Inputs/rhel_7_tree/opt/rh/devtoolset-7/root/usr/lib/gcc/x86_64-redhat-linux/7/crtbegin.o
  
clang/test/Driver/Inputs/rhel_7_tree/opt/rh/devtoolset-7/root/usr/lib/gcc/x86_64-redhat-linux/7/crtend.o
  clang/test/Driver/linux-ld.c


Index: clang/test/Driver/linux-ld.c
===
--- clang/test/Driver/linux-ld.c
+++ clang/test/Driver/linux-ld.c
@@ -1794,12 +1794,11 @@
 // RUN: %clang -### %s -no-pie 2>&1 \
 // RUN: --target=x86_64-unknown-linux-gnu \
 // RUN: 
--gcc-toolchain="%S/Inputs/rhel_7_tree/opt/rh/devtoolset-7/root/usr" \
-// RUN: --sysroot=%S/Inputs/rhel_7_tree \
+// RUN: --sysroot="%S/Inputs/rhel_7_tree/opt/rh/devtoolset-7/root" \
 // RUN:   | FileCheck --check-prefix=CHECK-LD-RHEL7-DTS %s
-// CHECK-LD-RHEL7-DTS: "{{.*}}ld{{(.exe)?}}" "--sysroot=[[SYSROOT:[^"]+]]"
-// CHECK-LD-RHLE7-DTS: Selected GCC installation: 
[[GCC_INSTALL:[[SYSROOT]]/lib/gcc/x86_64-redhat-linux/7]]
+// CHECK-LD-RHEL7-DTS: "-isysroot" "[[SYSROOT:[^"]+]]"
 // CHECK-LD-RHEL7-DTS-NOT: /usr/bin/ld
-// CHECK-LD-RHLE7-DTS: [[GCC_INSTALL]/../../../bin/ld
+// CHECK-LD-RHEL7-DTS: 
[[SYSROOT]]/usr/lib/gcc/x86_64-redhat-linux/7/../../../../bin/ld
 
 // Check whether gcc7 install works fine on Amazon Linux AMI
 // RUN: %clang -### %s -no-pie 2>&1 \


Index: clang/test/Driver/linux-ld.c
===
--- clang/test/Driver/linux-ld.c
+++ clang/test/Driver/linux-ld.c
@@ -1794,12 +1794,11 @@
 // RUN: %clang -### %s -no-pie 2>&1 \
 // RUN: --target=x86_64-unknown-linux-gnu \
 // RUN: --gcc-toolchain="%S/Inputs/rhel_7_tree/opt/rh/devtoolset-7/root/usr" \
-// RUN: --sysroot=%S/Inputs/rhel_7_tree \
+// RUN: --sysroot="%S/Inputs/rhel_7_tree/opt/rh/devtoolset-7/root" \
 // RUN:   | FileCheck --check-prefix=CHECK-LD-RHEL7-DTS %s
-// CHECK-LD-RHEL7-DTS: "{{.*}}ld{{(.exe)?}}" "--sysroot=[[SYSROOT:[^"]+]]"
-// CHECK-LD-RHLE7-DTS: Selected GCC installation: [[GCC_INSTALL:[[SYSROOT]]/lib/gcc/x86_64-redhat-linux/7]]
+// CHECK-LD-RHEL7-DTS: "-isysroot" "[[SYSROOT:[^"]+]]"
 // CHECK-LD-RHEL7-DTS-NOT: /usr/bin/ld
-// CHECK-LD-RHLE7-DTS: [[GCC_INSTALL]/../../../bin/ld
+// CHECK-LD-RHEL7-DTS: [[SYSROOT]]/usr/lib/gcc/x86_64-redhat-linux/7/../../../../bin/ld
 
 // Check whether gcc7 install works fine on Amazon Linux AMI
 // RUN: %clang -### %s -no-pie 2>&1 \
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 68baaca - [clang][dataflow] Use `Strict` accessors in comma operator and no-op cast.

2023-05-23 Thread Martin Braenne via cfe-commits

Author: Martin Braenne
Date: 2023-05-23T11:58:00Z
New Revision: 68baaca61dfad1179a61d99cbf0fe23a6894849d

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

LOG: [clang][dataflow] Use `Strict` accessors in comma operator and no-op cast.

This patch is part of the ongoing migration to strict handling of value
categories (see https://discourse.llvm.org/t/70086 for details).

Depends On D150775

Reviewed By: gribozavr2

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

Added: 


Modified: 
clang/lib/Analysis/FlowSensitive/Transfer.cpp

Removed: 




diff  --git a/clang/lib/Analysis/FlowSensitive/Transfer.cpp 
b/clang/lib/Analysis/FlowSensitive/Transfer.cpp
index 838ad934b5fbd..9658f5bcd6a0e 100644
--- a/clang/lib/Analysis/FlowSensitive/Transfer.cpp
+++ b/clang/lib/Analysis/FlowSensitive/Transfer.cpp
@@ -224,8 +224,7 @@ class TransferVisitor : public 
ConstStmtVisitor {
   break;
 }
 case BO_Comma: {
-  if (auto *Loc = Env.getStorageLocation(*RHS, SkipPast::None))
-Env.setStorageLocation(*S, *Loc);
+  propagateValueOrStorageLocation(*RHS, *S, Env);
   break;
 }
 default:
@@ -397,13 +396,9 @@ class TransferVisitor : public 
ConstStmtVisitor {
   // CK_ConstructorConversion, and CK_UserDefinedConversion.
 case CK_NoOp: {
   // FIXME: Consider making `Environment::getStorageLocation` skip noop
-  // expressions (this and other similar expressions in the file) instead 
of
-  // assigning them storage locations.
-  auto *SubExprLoc = Env.getStorageLocation(*SubExpr, SkipPast::None);
-  if (SubExprLoc == nullptr)
-break;
-
-  Env.setStorageLocation(*S, *SubExprLoc);
+  // expressions (this and other similar expressions in the file) instead
+  // of assigning them storage locations.
+  propagateValueOrStorageLocation(*SubExpr, *S, Env);
   break;
 }
 case CK_NullToPointer:



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


[PATCH] D150776: [clang][dataflow] Use `Strict` accessors in comma operator and no-op cast.

2023-05-23 Thread Martin Böhme via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG68baaca61dfa: [clang][dataflow] Use `Strict` accessors in 
comma operator and no-op cast. (authored by mboehme).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150776

Files:
  clang/lib/Analysis/FlowSensitive/Transfer.cpp


Index: clang/lib/Analysis/FlowSensitive/Transfer.cpp
===
--- clang/lib/Analysis/FlowSensitive/Transfer.cpp
+++ clang/lib/Analysis/FlowSensitive/Transfer.cpp
@@ -224,8 +224,7 @@
   break;
 }
 case BO_Comma: {
-  if (auto *Loc = Env.getStorageLocation(*RHS, SkipPast::None))
-Env.setStorageLocation(*S, *Loc);
+  propagateValueOrStorageLocation(*RHS, *S, Env);
   break;
 }
 default:
@@ -397,13 +396,9 @@
   // CK_ConstructorConversion, and CK_UserDefinedConversion.
 case CK_NoOp: {
   // FIXME: Consider making `Environment::getStorageLocation` skip noop
-  // expressions (this and other similar expressions in the file) instead 
of
-  // assigning them storage locations.
-  auto *SubExprLoc = Env.getStorageLocation(*SubExpr, SkipPast::None);
-  if (SubExprLoc == nullptr)
-break;
-
-  Env.setStorageLocation(*S, *SubExprLoc);
+  // expressions (this and other similar expressions in the file) instead
+  // of assigning them storage locations.
+  propagateValueOrStorageLocation(*SubExpr, *S, Env);
   break;
 }
 case CK_NullToPointer:


Index: clang/lib/Analysis/FlowSensitive/Transfer.cpp
===
--- clang/lib/Analysis/FlowSensitive/Transfer.cpp
+++ clang/lib/Analysis/FlowSensitive/Transfer.cpp
@@ -224,8 +224,7 @@
   break;
 }
 case BO_Comma: {
-  if (auto *Loc = Env.getStorageLocation(*RHS, SkipPast::None))
-Env.setStorageLocation(*S, *Loc);
+  propagateValueOrStorageLocation(*RHS, *S, Env);
   break;
 }
 default:
@@ -397,13 +396,9 @@
   // CK_ConstructorConversion, and CK_UserDefinedConversion.
 case CK_NoOp: {
   // FIXME: Consider making `Environment::getStorageLocation` skip noop
-  // expressions (this and other similar expressions in the file) instead of
-  // assigning them storage locations.
-  auto *SubExprLoc = Env.getStorageLocation(*SubExpr, SkipPast::None);
-  if (SubExprLoc == nullptr)
-break;
-
-  Env.setStorageLocation(*S, *SubExprLoc);
+  // expressions (this and other similar expressions in the file) instead
+  // of assigning them storage locations.
+  propagateValueOrStorageLocation(*SubExpr, *S, Env);
   break;
 }
 case CK_NullToPointer:
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D151094: [clang] Implement P2564 "consteval must propagate up"

2023-05-23 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 524660.
cor3ntin added a comment.

Remove unecessary evaluation context.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151094

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/Decl.h
  clang/include/clang/AST/DeclBase.h
  clang/include/clang/AST/Expr.h
  clang/include/clang/AST/Stmt.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/ScopeInfo.h
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/Decl.cpp
  clang/lib/AST/DeclPrinter.cpp
  clang/lib/AST/Expr.cpp
  clang/lib/AST/ExprConstant.cpp
  clang/lib/AST/TextNodeDumper.cpp
  clang/lib/AST/VTableBuilder.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/Frontend/InitPreprocessor.cpp
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/lib/Sema/ScopeInfo.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaLambda.cpp
  clang/lib/Sema/SemaStmt.cpp
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/lib/Serialization/ASTReaderStmt.cpp
  clang/lib/Serialization/ASTWriterDecl.cpp
  clang/lib/Serialization/ASTWriterStmt.cpp
  clang/test/CodeGenCXX/cxx20-consteval-crash.cpp
  clang/test/SemaCXX/cxx2a-consteval-default-params.cpp
  clang/test/SemaCXX/cxx2a-consteval.cpp
  clang/test/SemaCXX/cxx2b-consteval-propagate.cpp
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -363,7 +363,7 @@
 
   consteval needs to propagate up
   https://wg21.link/P2564R3";>P2564R3 (DR)
-  No
+  Clang 17
 
 
   Lifetime extension in range-based for loops
Index: clang/test/SemaCXX/cxx2b-consteval-propagate.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/cxx2b-consteval-propagate.cpp
@@ -0,0 +1,130 @@
+// RUN: %clang_cc1 -std=c++2a -emit-llvm-only -Wno-unused-value %s -verify
+// RUN: %clang_cc1 -std=c++2b -emit-llvm-only -Wno-unused-value %s -verify
+
+consteval int id(int i) { return i; }
+constexpr char id(char c) { return c; }
+
+namespace examples {
+
+template 
+constexpr int f(T t) { // expected-note {{declared here}}
+return t + id(t);  // expected-note {{'f' is an immediate function because its body contains a call to a consteval function 'id' and that call is not a constant expression}}
+}
+auto a = &f; // ok, f is not an immediate function
+auto b = &f;  // expected-error {{cannot take address of immediate function 'f' outside of an immediate invocation}}
+
+static_assert(f(3) == 6); // ok
+
+template 
+constexpr int g(T t) {// g is not an immediate function
+return t + id(42);// because id(42) is already a constant
+}
+
+template 
+constexpr bool is_not(T t, F f) {
+return not f(t);
+}
+
+consteval bool is_even(int i) { return i % 2 == 0; }
+
+static_assert(is_not(5, is_even));
+
+int x = 0; // expected-note {{declared here}}
+
+template 
+constexpr T h(T t = id(x)) { // expected-note {{read of non-const variable 'x' is not allowed in a constant expression}} \
+ // expected-note {{'hh' is an immediate function because its body contains a call to a consteval function 'id' and that call is not a constant expression}}
+return t;
+}
+
+template 
+constexpr T hh() {   // hh is an immediate function
+return h();
+}
+
+int i = hh(); // expected-error {{call to consteval function 'examples::hh' is not a constant expression}} \
+   // expected-note {{in call to 'hh()'}}
+
+struct A {
+  int x;
+  int y = id(x);
+};
+
+template 
+constexpr int k(int) {
+  return A(42).y;
+}
+
+}
+
+namespace e2{
+template 
+constexpr int f(T t);
+auto a = &f;
+auto b = &f;
+}
+
+namespace forward_declare_constexpr{
+template 
+constexpr int f(T t);
+
+auto a = &f;
+auto b = &f;
+
+template 
+constexpr int f(T t) {
+return id(0);
+}
+}
+
+namespace forward_declare_consteval{
+template 
+constexpr int f(T t);  // expected-note {{'f' defined here}}
+
+auto a = &f;
+auto b = &f; // expected-error {{immediate function 'f' used before it is defined}} \
+  // expected-note {{in instantiation of function template specialization}}
+
+template 
+constexpr int f(T t) {
+return id(t); // expected-note {{'f' is an immediate function because its body contains a call to a consteval function 'id' and that call is not a constant expression}}
+}
+}
+
+namespace constructors {
+consteval int f(int) {
+  return 0;
+}
+struct S {
+  constexpr S(auto i) {
+f(i);
+  }
+};
+constexpr void g(auto i) {
+  [[maybe_unused]] S s{i};
+}
+void test() {
+  g(0);
+}
+}
+
+namespace aggregate {
+consteval int f(int);
+struct S{
+int a = 0;
+int b = f(a);
+};
+
+constexpr bool test(auto i) {
+S s{i};

[PATCH] D151042: [clang] Add tests for CWG issues 977, 1482, 2516

2023-05-23 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

This breaks check-clang on windows: http://45.33.8.238/win/78827/step_7.txt

Please take a look and revert for now if it takes a while to fix.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151042

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


[PATCH] D151094: [clang] Implement P2564 "consteval must propagate up"

2023-05-23 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin marked 2 inline comments as done.
cor3ntin added inline comments.



Comment at: clang/include/clang/AST/Decl.h:2391
+
+  bool isImmediateFunction() const;
+

tbaeder wrote:
> Some documentation on the new API would be useful; seems like most calls to 
> `isConsteval()` should be using `isImmediateFunction()` instead?
Yes - I added a comment



Comment at: clang/lib/AST/Decl.cpp:3180
+  // consteval specifier,
+  if (isDefaulted() && !isConsteval())
+return true;

aaron.ballman wrote:
> Should this be looking at `isExplicitlyDefaulted()` instead?
I don't think so - "defaulted" usually does not imply explicit, unless 
explicitly stated. the case would be a member init with an immediately 
escalating expression 



Comment at: clang/lib/Parse/ParseDecl.cpp:2495
 } else {
+  EnterExpressionEvaluationContext Ctx(
+  Actions, Sema::ExpressionEvaluationContext::PotentiallyEvaluated);

Fznamznon wrote:
> What is the point for an additional expression evaluation context here?
Unnecessary, good catch! I think i had to add that in an earlier iteration of 
the patch which checked for immediate escalation in MarkDeclRefReferenced.



Comment at: clang/lib/Sema/SemaExpr.cpp:17966
+
+  getCurFunction()->FoundImmediateEscalatingExpression = true;
+}

Fznamznon wrote:
> Same is actually for `getCurFunction()`. Can be a `nullptr` if there is no 
> function.
There is an assert above , this function should only be called from a function 
scope



Comment at: clang/test/SemaCXX/cxx2a-consteval-default-params.cpp:1
 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 %s
 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++23 %s

Fznamznon wrote:
> Should the new behavior only be enabled for c++23?
Nah, it was voted as a DR


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151094

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


[PATCH] D151133: [clang-tidy] Ignore implicit code in bugprone-branch-clone

2023-05-23 Thread Donát Nagy via Phabricator via cfe-commits
donat.nagy added a comment.

For me it's an unfortunate surprise that Clang Tidy is traversing the concrete 
//template instantiation// (I would've guessed that it's working on the 
original template body), but if that's the observed behavior, then this commit 
is a clean and straightforward fix.

I'd suggest adding another testcase that looks like

  template 
  int branch_clone_in_template(T t) {
if (t) {
  return 42;
} else {
  return 42;
}
  }
  int use_template(int x) {
return branch_clone_in_template(x);
  }

to clarify the behavior on cases where the checker encounters a "real" branch 
clone that happens to be in a template. I think we can/should merge your change 
even if it suppresses these true positives (as it's a self-contained change 
that replaces a serious issue with a minor limitation), but in that case we 
should mark this testcase with a FIXME comment to highlight this low-priority 
followup work. (Of course it's even better if you happen to have a quick idea 
which ensures that the checker can report "real" branch clones even if they 
happen to appear in templates.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151133

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


[PATCH] D151042: [clang] Add tests for CWG issues 977, 1482, 2516

2023-05-23 Thread Vlad Serebrennikov via Phabricator via cfe-commits
Endill added a comment.

In D151042#4364108 , @thakis wrote:

> This breaks check-clang on windows: http://45.33.8.238/win/78827/step_7.txt
>
> Please take a look and revert for now if it takes a while to fix.

It's not hard to fix, but is it just windows? Sorry I'm not too familiar with 
buildbots.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151042

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


[clang] 211055c - AArch64: emit synchronous unwind for Darwin arm64_32 platforms too.

2023-05-23 Thread Tim Northover via cfe-commits

Author: Tim Northover
Date: 2023-05-23T13:15:32+01:00
New Revision: 211055c7443e5594863ec95754e22f66e66aecc5

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

LOG: AArch64: emit synchronous unwind for Darwin arm64_32 platforms too.

Since we're checking the triple directly, arm64_32 shows up differently and was
still getting an attempt at asynchronous unwind that added lots more
`__eh_frame` entries instead of the compact format.

Added: 


Modified: 
clang/lib/Driver/ToolChains/Darwin.cpp
clang/test/Driver/clang-translation.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Darwin.cpp 
b/clang/lib/Driver/ToolChains/Darwin.cpp
index e66606293821..3ab8bc8c8ec9 100644
--- a/clang/lib/Driver/ToolChains/Darwin.cpp
+++ b/clang/lib/Driver/ToolChains/Darwin.cpp
@@ -2941,8 +2941,10 @@ ToolChain::UnwindTableLevel 
MachO::getDefaultUnwindTableLevel(const ArgList &Arg
   (GetExceptionModel(Args) != llvm::ExceptionHandling::SjLj &&
Args.hasFlag(options::OPT_fexceptions, options::OPT_fno_exceptions,
 true)))
-return getArch() == llvm::Triple::aarch64 ? UnwindTableLevel::Synchronous
-  : UnwindTableLevel::Asynchronous;
+return (getArch() == llvm::Triple::aarch64 ||
+getArch() == llvm::Triple::aarch64_32)
+   ? UnwindTableLevel::Synchronous
+   : UnwindTableLevel::Asynchronous;
 
   return UnwindTableLevel::None;
 }

diff  --git a/clang/test/Driver/clang-translation.c 
b/clang/test/Driver/clang-translation.c
index d950d9a4de9b..4e42ab3a9e2e 100644
--- a/clang/test/Driver/clang-translation.c
+++ b/clang/test/Driver/clang-translation.c
@@ -81,6 +81,8 @@
 
 // RUN: %clang -target arm64-apple-ios10 -funwind-tables -### -S %s -arch 
arm64 2>&1 | \
 // RUN: FileCheck -check-prefix=ARM64-APPLE-UNWIND %s
+// RUN: %clang -target arm64_32-apple-watchos8 -funwind-tables -### -S %s 
-arch arm64 2>&1 | \
+// RUN: FileCheck -check-prefix=ARM64-APPLE-UNWIND %s
 // ARM64-APPLE-UNWIND: -funwind-tables=1
 
 // RUN: %clang -target arm64-apple-ios10 -### -ffreestanding -S %s -arch arm64 
2>&1 | \



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


[PATCH] D151042: [clang] Add tests for CWG issues 977, 1482, 2516

2023-05-23 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

On my bots (which cover linux, mac/arm, and windows), it's only failing on the 
windows bot.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151042

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


[PATCH] D151042: [clang] Add tests for CWG issues 977, 1482, 2516

2023-05-23 Thread Vlad Serebrennikov via Phabricator via cfe-commits
Endill added a comment.

All tests pass for me on Linux.
As far as I understand, diagnostics on Windows are not supposed to be different 
given the same `-cc1` flags. Reverting for further investigation.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151042

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


[PATCH] D151094: [clang] Implement P2564 "consteval must propagate up"

2023-05-23 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon added a comment.

Out of curiosity - does something like these examples - 
https://godbolt.org/z/Eqb58Wqoo work as expected?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151094

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


[clang] 70688e8 - Revert "[clang] Add tests for CWG issues 977, 1482, 2516"

2023-05-23 Thread Vlad Serebrennikov via cfe-commits

Author: Vlad Serebrennikov
Date: 2023-05-23T15:29:14+03:00
New Revision: 70688e82e2fd6b486931669b981c18f3830385b5

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

LOG: Revert "[clang] Add tests for CWG issues 977, 1482, 2516"

This reverts commit 85452b5f9b5aba5bdf0259b7f0d7400362f95535.

Added: 


Modified: 
clang/test/CXX/drs/dr14xx.cpp
clang/test/CXX/drs/dr25xx.cpp
clang/test/CXX/drs/dr9xx.cpp
clang/www/cxx_dr_status.html

Removed: 




diff  --git a/clang/test/CXX/drs/dr14xx.cpp b/clang/test/CXX/drs/dr14xx.cpp
index ea41a03d3587a..9d667db9945fd 100644
--- a/clang/test/CXX/drs/dr14xx.cpp
+++ b/clang/test/CXX/drs/dr14xx.cpp
@@ -488,17 +488,6 @@ namespace dr1479 { // dr1479: yes
   int operator"" _a(const char*, std::size_t = 0); // expected-error {{literal 
operator cannot have a default argument}}
 }
 
-namespace dr1482 { // dr1482: yes
-   // NB: sup 2516, test reused there
-#if __cplusplus >= 201103L
-template  struct S {
-  typedef char I;
-};
-enum E2 : S::I { e };
-// expected-error@-1 {{use of undeclared identifier 'E2'}}
-#endif
-} // namespace dr1482
-
 namespace dr1490 {  // dr1490: 3.7 c++11
   // List-initialization from a string literal
 

diff  --git a/clang/test/CXX/drs/dr25xx.cpp b/clang/test/CXX/drs/dr25xx.cpp
index b41f026e629f0..28ebda22a8017 100644
--- a/clang/test/CXX/drs/dr25xx.cpp
+++ b/clang/test/CXX/drs/dr25xx.cpp
@@ -1,16 +1,5 @@
 // RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-unknown %s -verify
 
-namespace dr2516 { // dr2516: yes
-   // NB: reusing 1482 test
-#if __cplusplus >= 201103L
-template  struct S {
-  typedef char I;
-};
-enum E2 : S::I { e };
-// expected-error@-1 {{use of undeclared identifier 'E2'}}
-#endif
-} // namespace dr2516
-
 namespace dr2518 { // dr2518: 17
 
 template 

diff  --git a/clang/test/CXX/drs/dr9xx.cpp b/clang/test/CXX/drs/dr9xx.cpp
index 6022b640d1bef..3d45dc8e72d2d 100644
--- a/clang/test/CXX/drs/dr9xx.cpp
+++ b/clang/test/CXX/drs/dr9xx.cpp
@@ -90,17 +90,6 @@ namespace dr974 { // dr974: yes
 #endif
 }
 
-namespace dr977 { // dr977: yes
-enum E { e = E() };
-// expected-error@-1 {{invalid use of incomplete type 'E'}}
-// expected-note@-2 {{definition of 'dr977::E' is not complete until the 
closing '}'}}
-#if __cplusplus >= 201103L
-enum E2 : int { e2 = E2() };
-enum struct E3 { e = static_cast(E3()) };
-enum struct E4 : int { e = static_cast(E4()) };
-#endif
-} // namespace dr977
-
 namespace dr990 { // dr990: 3.5
 #if __cplusplus >= 201103L
   struct A { // expected-note 2{{candidate}}

diff  --git a/clang/www/cxx_dr_status.html b/clang/www/cxx_dr_status.html
index cf4cdbb19a7e2..4f687e9bcbdcc 100755
--- a/clang/www/cxx_dr_status.html
+++ b/clang/www/cxx_dr_status.html
@@ -5669,7 +5669,7 @@ C++ defect report implementation 
status
 https://cplusplus.github.io/CWG/issues/977.html";>977
 CD3
 When is an enumeration type complete?
-Yes
+Unknown
   
   
 https://cplusplus.github.io/CWG/issues/978.html";>978
@@ -8699,7 +8699,7 @@ C++ defect report implementation 
status
 https://cplusplus.github.io/CWG/issues/1482.html";>1482
 CD3
 Point of declaration of enumeration
-Yes
+Unknown
   
   
 https://cplusplus.github.io/CWG/issues/1483.html";>1483
@@ -14903,7 +14903,7 @@ C++ defect report implementation 
status
 https://cplusplus.github.io/CWG/issues/2516.html";>2516
 DR
 Locus of enum-specifier or opaque-enum-declaration
-Yes
+Unknown
   
   
 https://cplusplus.github.io/CWG/issues/2517.html";>2517



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


[clang-tools-extra] 35ce741 - [clangd] Store paths as requested in PreambleStatCache

2023-05-23 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2023-05-23T14:30:58+02:00
New Revision: 35ce741ef3e3dd9db1da3ea0a06c565cb90f665a

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

LOG: [clangd] Store paths as requested in PreambleStatCache

Underlying FS can store different file names inside the stat response
(e.g. symlinks resolved, absolute paths, dots removed). But we store path names
as requested inside the preamble,
https://github.com/llvm/llvm-project/blob/main/clang/lib/Serialization/ASTWriter.cpp#L1635.

This improves cache hit rates from ~30% to 90% in a build system that uses
symlinks.

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

Added: 


Modified: 
clang-tools-extra/clangd/FS.cpp
clang-tools-extra/clangd/FS.h
clang-tools-extra/clangd/unittests/FSTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/FS.cpp b/clang-tools-extra/clangd/FS.cpp
index 3622d35d9d52..c67636dbf2d4 100644
--- a/clang-tools-extra/clangd/FS.cpp
+++ b/clang-tools-extra/clangd/FS.cpp
@@ -11,6 +11,7 @@
 #include "llvm/Support/Path.h"
 #include "llvm/Support/VirtualFileSystem.h"
 #include 
+#include 
 
 namespace clang {
 namespace clangd {
@@ -23,9 +24,10 @@ 
PreambleFileStatusCache::PreambleFileStatusCache(llvm::StringRef MainFilePath){
 }
 
 void PreambleFileStatusCache::update(const llvm::vfs::FileSystem &FS,
- llvm::vfs::Status S) {
+ llvm::vfs::Status S,
+ llvm::StringRef File) {
   // Canonicalize path for later lookup, which is usually by absolute path.
-  llvm::SmallString<32> PathStore(S.getName());
+  llvm::SmallString<32> PathStore(File);
   if (FS.makeAbsolute(PathStore))
 return;
   llvm::sys::path::remove_dots(PathStore, /*remove_dot_dot=*/true);
@@ -72,14 +74,14 @@ PreambleFileStatusCache::getProducingFS(
   // many times (e.g. code completion) and the repeated status call is
   // likely to be cached in the underlying file system anyway.
   if (auto S = File->get()->status())
-StatCache.update(getUnderlyingFS(), std::move(*S));
+StatCache.update(getUnderlyingFS(), std::move(*S), Path.str());
   return File;
 }
 
 llvm::ErrorOr status(const llvm::Twine &Path) override {
   auto S = getUnderlyingFS().status(Path);
   if (S)
-StatCache.update(getUnderlyingFS(), *S);
+StatCache.update(getUnderlyingFS(), *S, Path.str());
   return S;
 }
 

diff  --git a/clang-tools-extra/clangd/FS.h b/clang-tools-extra/clangd/FS.h
index ea07de24bbae..827b465aed98 100644
--- a/clang-tools-extra/clangd/FS.h
+++ b/clang-tools-extra/clangd/FS.h
@@ -41,7 +41,8 @@ class PreambleFileStatusCache {
   /// corresponds to. The stat for the main file will not be cached.
   PreambleFileStatusCache(llvm::StringRef MainFilePath);
 
-  void update(const llvm::vfs::FileSystem &FS, llvm::vfs::Status S);
+  void update(const llvm::vfs::FileSystem &FS, llvm::vfs::Status S,
+  llvm::StringRef File);
 
   /// \p Path is a path stored in preamble.
   std::optional lookup(llvm::StringRef Path) const;

diff  --git a/clang-tools-extra/clangd/unittests/FSTests.cpp 
b/clang-tools-extra/clangd/unittests/FSTests.cpp
index 81129fec98c2..0b2bc688335d 100644
--- a/clang-tools-extra/clangd/unittests/FSTests.cpp
+++ b/clang-tools-extra/clangd/unittests/FSTests.cpp
@@ -37,18 +37,19 @@ TEST(FSTests, PreambleStatusCache) {
   std::chrono::system_clock::now(), 0, 0, 1024,
   llvm::sys::fs::file_type::regular_file,
   llvm::sys::fs::all_all);
-  StatCache.update(*FS, S);
+  StatCache.update(*FS, S, "real");
   auto ConsumeFS = StatCache.getConsumingFS(FS);
-  auto Cached = ConsumeFS->status(testPath("fake"));
+  EXPECT_FALSE(ConsumeFS->status(testPath("fake")));
+  auto Cached = ConsumeFS->status(testPath("real"));
   EXPECT_TRUE(Cached);
-  EXPECT_EQ(Cached->getName(), testPath("fake"));
+  EXPECT_EQ(Cached->getName(), testPath("real"));
   EXPECT_EQ(Cached->getUniqueID(), S.getUniqueID());
 
-  // fake and temp/../fake should hit the same cache entry.
+  // real and temp/../real should hit the same cache entry.
   // However, the Status returned reflects the actual path requested.
-  auto CachedDotDot = ConsumeFS->status(testPath("temp/../fake"));
+  auto CachedDotDot = ConsumeFS->status(testPath("temp/../real"));
   EXPECT_TRUE(CachedDotDot);
-  EXPECT_EQ(CachedDotDot->getName(), testPath("temp/../fake"));
+  EXPECT_EQ(CachedDotDot->getName(), testPath("temp/../real"));
   EXPECT_EQ(CachedDotDot->getUniqueID(), S.getUniqueID());
 }
 



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

[PATCH] D151185: [clangd] Store paths as requested in PreambleStatCache

2023-05-23 Thread Kadir Cetinkaya via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG35ce741ef3e3: [clangd] Store paths as requested in 
PreambleStatCache (authored by kadircet).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151185

Files:
  clang-tools-extra/clangd/FS.cpp
  clang-tools-extra/clangd/FS.h
  clang-tools-extra/clangd/unittests/FSTests.cpp


Index: clang-tools-extra/clangd/unittests/FSTests.cpp
===
--- clang-tools-extra/clangd/unittests/FSTests.cpp
+++ clang-tools-extra/clangd/unittests/FSTests.cpp
@@ -37,18 +37,19 @@
   std::chrono::system_clock::now(), 0, 0, 1024,
   llvm::sys::fs::file_type::regular_file,
   llvm::sys::fs::all_all);
-  StatCache.update(*FS, S);
+  StatCache.update(*FS, S, "real");
   auto ConsumeFS = StatCache.getConsumingFS(FS);
-  auto Cached = ConsumeFS->status(testPath("fake"));
+  EXPECT_FALSE(ConsumeFS->status(testPath("fake")));
+  auto Cached = ConsumeFS->status(testPath("real"));
   EXPECT_TRUE(Cached);
-  EXPECT_EQ(Cached->getName(), testPath("fake"));
+  EXPECT_EQ(Cached->getName(), testPath("real"));
   EXPECT_EQ(Cached->getUniqueID(), S.getUniqueID());
 
-  // fake and temp/../fake should hit the same cache entry.
+  // real and temp/../real should hit the same cache entry.
   // However, the Status returned reflects the actual path requested.
-  auto CachedDotDot = ConsumeFS->status(testPath("temp/../fake"));
+  auto CachedDotDot = ConsumeFS->status(testPath("temp/../real"));
   EXPECT_TRUE(CachedDotDot);
-  EXPECT_EQ(CachedDotDot->getName(), testPath("temp/../fake"));
+  EXPECT_EQ(CachedDotDot->getName(), testPath("temp/../real"));
   EXPECT_EQ(CachedDotDot->getUniqueID(), S.getUniqueID());
 }
 
Index: clang-tools-extra/clangd/FS.h
===
--- clang-tools-extra/clangd/FS.h
+++ clang-tools-extra/clangd/FS.h
@@ -41,7 +41,8 @@
   /// corresponds to. The stat for the main file will not be cached.
   PreambleFileStatusCache(llvm::StringRef MainFilePath);
 
-  void update(const llvm::vfs::FileSystem &FS, llvm::vfs::Status S);
+  void update(const llvm::vfs::FileSystem &FS, llvm::vfs::Status S,
+  llvm::StringRef File);
 
   /// \p Path is a path stored in preamble.
   std::optional lookup(llvm::StringRef Path) const;
Index: clang-tools-extra/clangd/FS.cpp
===
--- clang-tools-extra/clangd/FS.cpp
+++ clang-tools-extra/clangd/FS.cpp
@@ -11,6 +11,7 @@
 #include "llvm/Support/Path.h"
 #include "llvm/Support/VirtualFileSystem.h"
 #include 
+#include 
 
 namespace clang {
 namespace clangd {
@@ -23,9 +24,10 @@
 }
 
 void PreambleFileStatusCache::update(const llvm::vfs::FileSystem &FS,
- llvm::vfs::Status S) {
+ llvm::vfs::Status S,
+ llvm::StringRef File) {
   // Canonicalize path for later lookup, which is usually by absolute path.
-  llvm::SmallString<32> PathStore(S.getName());
+  llvm::SmallString<32> PathStore(File);
   if (FS.makeAbsolute(PathStore))
 return;
   llvm::sys::path::remove_dots(PathStore, /*remove_dot_dot=*/true);
@@ -72,14 +74,14 @@
   // many times (e.g. code completion) and the repeated status call is
   // likely to be cached in the underlying file system anyway.
   if (auto S = File->get()->status())
-StatCache.update(getUnderlyingFS(), std::move(*S));
+StatCache.update(getUnderlyingFS(), std::move(*S), Path.str());
   return File;
 }
 
 llvm::ErrorOr status(const llvm::Twine &Path) override {
   auto S = getUnderlyingFS().status(Path);
   if (S)
-StatCache.update(getUnderlyingFS(), *S);
+StatCache.update(getUnderlyingFS(), *S, Path.str());
   return S;
 }
 


Index: clang-tools-extra/clangd/unittests/FSTests.cpp
===
--- clang-tools-extra/clangd/unittests/FSTests.cpp
+++ clang-tools-extra/clangd/unittests/FSTests.cpp
@@ -37,18 +37,19 @@
   std::chrono::system_clock::now(), 0, 0, 1024,
   llvm::sys::fs::file_type::regular_file,
   llvm::sys::fs::all_all);
-  StatCache.update(*FS, S);
+  StatCache.update(*FS, S, "real");
   auto ConsumeFS = StatCache.getConsumingFS(FS);
-  auto Cached = ConsumeFS->status(testPath("fake"));
+  EXPECT_FALSE(ConsumeFS->status(testPath("fake")));
+  auto Cached = ConsumeFS->status(testPath("real"));
   EXPECT_TRUE(Cached);
-  EXPECT_EQ(Cached->getName(), testPath("fake"));
+  EXPECT_EQ(Cached->getName(), testPath("real"));
   EXPECT_EQ(Cached->getUniqueID(), S.getUniqueID());
 
-  // fake and temp/../fake should hit the same cache entry.
+  // real and temp/../real shoul

[PATCH] D147844: [clang][Sema]Print diagnostic warning about precedence when integer expression is used without parentheses in an conditional operator expression

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

In D147844#4361956 , @aaron.ballman 
wrote:

> In D147844#4335598 , @dblaikie 
> wrote:
>
>> In D147844#4329497 , 
>> @aaron.ballman wrote:
>>
>>> In general, I think this is incremental progress on the diagnostic 
>>> behavior. However, it's clear that there is room for interpretation on what 
>>> is or is not a false positive diagnostic for this,
>>
>> I hope we can agree on what a false positive is here - when the warning 
>> fires but the code is what the developer intended (ie: the existing code 
>> with the existing language semantics produce the desired result, the "fix" 
>> is to add parentheses that explicitly encode the language's existing 
>> rules/behavior anyway).
>
> I agree with that definition -- that's a useful way to approach this, thank 
> you!
>
>> Not that we don't have warnings that do this - that encourage parens to 
>> reinforce what the language already does to be more explicit/intentional 
>> about it, and in some cases it's not that uncommon that the user will be 
>> adding parens that reinforce the precedence rules anyway.
>
> Yup, which is largely what this patch is about.
>
>> Like, I think all the fixes in libc++, llvm, etc, are false positives? (none 
>> of them found bugs/unintended behavior)
>
> Yes, they all are false positives by the above definition.
>
>> Are there any examples of bugs being found by this warning in a codebase? (& 
>> how many false positives in such a codebase did it also flag?)
>
> This would be good to know, but a bit of a heavy lift to require of 
> @chaitanyav because they were working on this issue 
> (https://github.com/llvm/llvm-project/issues/61943) with a "good first issue" 
> label that is starting to look a bit like it was misleading (sorry about 
> that!). However, if you're able to try compiling some larger projects with 
> your patch applied to see if it spots any bugs in real world code, that would 
> be very helpful!

@aaron.ballman will try this patch on some projects and post the results here

>>> so we should pay close attention to user feedback during the 17.x release 
>>> cycle. If it seems we're getting significant push back, we may need to come 
>>> back and rethink.
>>>
>>> Specifically, I think we've improved the situation for code like this:
>>>
>>>   // `p` is a pointer, `x` is an `int`, and `b` is a `bool`
>>>   p + x ? 1 : 2; // previously didn't warn, now warns
>>>   p + b ? 1 : 2; // always warned
>>>
>>> Does anyone feel we should not move forward with accepting the patch in its 
>>> current form?
>>
>> *goes to look*
>>
>> Mixed feelings - you're right, incremental improvement/adding missed cases 
>> to an existing warning (especially if that warning's already stylistic in 
>> nature) is a lower bar/doesn't necessarily need the false positive 
>> assessment. But it looks like this case might've been intentionally 
>> suppressed in the initial warning implementation? (anyone linked to the 
>> original warning implementation/review/design to check if this was 
>> intentional?)
>
> I tried to chase down where this got added to see what review comments there 
> were, but it seems to predate my involvement (I'm seeing mentions of this in 
> 2011).
>
>> But, yeah, seems marginal enough I don't have strong feelings either way.
>
> Thank you for the opinion! I think pointer + int is a far more common code 
> pattern than pointer + bool, so it makes some sense to me that we would 
> silence the first case while diagnosing the second case. Given the general 
> lack of enthusiasm for the new diagnostics, it may boil down to answering 
> whether this finds any true positives or not.




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147844

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


[PATCH] D151042: [clang] Add tests for CWG issues 977, 1482, 2516

2023-05-23 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

In D151042#4364131 , @Endill wrote:

> All tests pass for me on Linux.
> As far as I understand, diagnostics on Windows are not supposed to be 
> different given the same `-cc1` flags. Reverting for further investigation.

Thanks for the revert. The test also failed on the official llvm win buildbot 
here https://lab.llvm.org/buildbot/#/builders/123 fwiw (but it takes a long 
time to load).

Diagnostics on windows absolutely can be different on windows with the same cc1 
flags. Clang uses the host system's target triple, and for (say) 
x86_64-pc-windows clang runs in MS mode, which enables some cl.exe 
compatibility things.

In fact, you can probably repro the test failure on your linux box if you 
change that test and add locally add `-triple=i386-pc-win32` to the RUN line 
(or maybe the behavior to enable MS extensions based on target lives in the 
driver; in that case you'd have to add `-fms-extensions -fms-compatibility`).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151042

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


[PATCH] D151194: [clang][dataflow] Add support for return values of reference type.

2023-05-23 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel accepted this revision.
ymandel added a comment.
This revision is now accepted and ready to land.

Nice!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151194

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


[PATCH] D147889: [clang-tidy] Improve bugprone-branch-clone with support for fallthrough attribute

2023-05-23 Thread Donát Nagy via Phabricator via cfe-commits
donat.nagy added a comment.

Mostly LGTM, I suggested two cosmetic changes.




Comment at: clang-tools-extra/clang-tidy/bugprone/BranchCloneCheck.cpp:55
+bool TraverseLambdaExpr(LambdaExpr *, DataRecursionQueue * = nullptr) {
+  // Ignore lambdas
+  return true;

Bikeshedding: these comments are very useful, but put them after the return 
statements. The //(meaningful content) / (number of lines)// ratio is already 
abysmal in visitor classes like this, let's try to avoid what we can.



Comment at: clang-tools-extra/clang-tidy/bugprone/BranchCloneCheck.cpp:84
+  for (const Attr *A : S->getAttrs()) {
+if (FallThroughAttr::classof(A))
+  return false;

If I understand it correctly, `Class::classof(Pointer)` is an implementation 
detail of the more flexible and slightly magical `isa(Obj)` utility. The 
clang-tidy codebase contains lots of `isa<>` and only a single direct reference 
to `classof()` so I'd suggest using `isa<>` here for the sake of consistency.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147889

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


[clang] 30b0fdf - [AArch64][FMV] Fix name mangling.

2023-05-23 Thread Pavel Iliin via cfe-commits

Author: Pavel Iliin
Date: 2023-05-23T13:42:55+01:00
New Revision: 30b0fdfff1931c625babe45cbf9405003c48f8a0

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

LOG: [AArch64][FMV] Fix name mangling.

Put features into function version name in increasing priority order.

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

Added: 


Modified: 
clang/lib/CodeGen/CodeGenModule.cpp
clang/test/CodeGen/attr-target-clones-aarch64.c
clang/test/CodeGen/attr-target-version.c
clang/test/CodeGenCXX/attr-target-clones-aarch64.cpp
clang/test/CodeGenCXX/attr-target-version.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 5cd29d3657879..66c2abdb903aa 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -1362,8 +1362,13 @@ static void AppendTargetVersionMangling(const 
CodeGenModule &CGM,
   if (Attr->isDefaultVersion())
 return;
   Out << "._";
+  const TargetInfo &TI = CGM.getTarget();
   llvm::SmallVector Feats;
   Attr->getFeatures(Feats);
+  llvm::stable_sort(Feats, [&TI](const StringRef FeatL, const StringRef FeatR) 
{
+return TI.multiVersionSortPriority(FeatL) <
+   TI.multiVersionSortPriority(FeatR);
+  });
   for (const auto &Feat : Feats) {
 Out << 'M';
 Out << Feat;
@@ -1415,13 +1420,19 @@ static void AppendTargetClonesMangling(const 
CodeGenModule &CGM,
const TargetClonesAttr *Attr,
unsigned VersionIndex,
raw_ostream &Out) {
-  if (CGM.getTarget().getTriple().isAArch64()) {
+  const TargetInfo &TI = CGM.getTarget();
+  if (TI.getTriple().isAArch64()) {
 StringRef FeatureStr = Attr->getFeatureStr(VersionIndex);
 if (FeatureStr == "default")
   return;
 Out << "._";
 SmallVector Features;
 FeatureStr.split(Features, "+");
+llvm::stable_sort(Features,
+  [&TI](const StringRef FeatL, const StringRef FeatR) {
+return TI.multiVersionSortPriority(FeatL) <
+   TI.multiVersionSortPriority(FeatR);
+  });
 for (auto &Feat : Features) {
   Out << 'M';
   Out << Feat;

diff  --git a/clang/test/CodeGen/attr-target-clones-aarch64.c 
b/clang/test/CodeGen/attr-target-clones-aarch64.c
index f61db5f15bf54..4a5e47306c11b 100644
--- a/clang/test/CodeGen/attr-target-clones-aarch64.c
+++ b/clang/test/CodeGen/attr-target-clones-aarch64.c
@@ -32,7 +32,7 @@ inline int __attribute__((target_clones("fp16", 
"sve2-bitperm+fcma", "default"))
 // CHECK: @ftc_inline3.ifunc = weak_odr ifunc i32 (), ptr @ftc_inline3.resolver
 
 // CHECK: Function Attrs: noinline nounwind optnone
-// CHECK-LABEL: @ftc._MaesMlse(
+// CHECK-LABEL: @ftc._MlseMaes(
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:ret i32 0
 // CHECK: Function Attrs: noinline nounwind optnone
@@ -52,7 +52,7 @@ inline int __attribute__((target_clones("fp16", 
"sve2-bitperm+fcma", "default"))
 // CHECK-NEXT:[[TMP3:%.*]] = and i1 true, [[TMP2]]
 // CHECK-NEXT:br i1 [[TMP3]], label [[RESOLVER_RETURN:%.*]], label 
[[RESOLVER_ELSE:%.*]]
 // CHECK:   resolver_return:
-// CHECK-NEXT:ret ptr @ftc._MaesMlse
+// CHECK-NEXT:ret ptr @ftc._MlseMaes
 // CHECK:   resolver_else:
 // CHECK-NEXT:[[TMP4:%.*]] = load i64, ptr @__aarch64_cpu_features, align 8
 // CHECK-NEXT:[[TMP5:%.*]] = and i64 [[TMP4]], 68719476736
@@ -68,7 +68,7 @@ inline int __attribute__((target_clones("fp16", 
"sve2-bitperm+fcma", "default"))
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:ret i32 1
 // CHECK: Function Attrs: noinline nounwind optnone
-// CHECK-LABEL: @ftc_def._Mmemtag2Msha2(
+// CHECK-LABEL: @ftc_def._Msha2Mmemtag2(
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:ret i32 1
 // CHECK: Function Attrs: noinline nounwind optnone
@@ -84,7 +84,7 @@ inline int __attribute__((target_clones("fp16", 
"sve2-bitperm+fcma", "default"))
 // CHECK-NEXT:[[TMP3:%.*]] = and i1 true, [[TMP2]]
 // CHECK-NEXT:br i1 [[TMP3]], label [[RESOLVER_RETURN:%.*]], label 
[[RESOLVER_ELSE:%.*]]
 // CHECK:   resolver_return:
-// CHECK-NEXT:ret ptr @ftc_def._Mmemtag2Msha2
+// CHECK-NEXT:ret ptr @ftc_def._Msha2Mmemtag2
 // CHECK:   resolver_else:
 // CHECK-NEXT:[[TMP4:%.*]] = load i64, ptr @__aarch64_cpu_features, align 8
 // CHECK-NEXT:[[TMP5:%.*]] = and i64 [[TMP4]], 4096
@@ -120,7 +120,7 @@ inline int __attribute__((target_clones("fp16", 
"sve2-bitperm+fcma", "default"))
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:ret i32 3
 // CHECK: Function Attrs: noinline nounwind optnone
-// CHECK-LABEL: @ftc_dup2._McrcMdotprod(
+// CHECK-LABEL: @ftc_dup2._MdotprodMcrc(
 // CHECK-NEXT:  entr

[PATCH] D150800: [AArch64][FMV] Fix name mangling.

2023-05-23 Thread Pavel Iliin via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG30b0fdfff193: [AArch64][FMV] Fix name mangling. (authored by 
ilinpv).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150800

Files:
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/CodeGen/attr-target-clones-aarch64.c
  clang/test/CodeGen/attr-target-version.c
  clang/test/CodeGenCXX/attr-target-clones-aarch64.cpp
  clang/test/CodeGenCXX/attr-target-version.cpp

Index: clang/test/CodeGenCXX/attr-target-version.cpp
===
--- clang/test/CodeGenCXX/attr-target-version.cpp
+++ clang/test/CodeGenCXX/attr-target-version.cpp
@@ -27,7 +27,7 @@
 // CHECK: @_Z3fooi.ifunc = weak_odr ifunc i32 (i32), ptr @_Z3fooi.resolver
 // CHECK: @_Z3foov.ifunc = weak_odr ifunc i32 (), ptr @_Z3foov.resolver
 
-// CHECK-LABEL: @_Z3fooi._Msme-f64f64Mbf16(
+// CHECK-LABEL: @_Z3fooi._Mbf16Msme-f64f64(
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:[[DOTADDR:%.*]] = alloca i32, align 4
 // CHECK-NEXT:store i32 [[TMP0:%.*]], ptr [[DOTADDR]], align 4
@@ -105,7 +105,7 @@
 // CHECK-NEXT:[[TMP3:%.*]] = and i1 true, [[TMP2]]
 // CHECK-NEXT:br i1 [[TMP3]], label [[RESOLVER_RETURN:%.*]], label [[RESOLVER_ELSE:%.*]]
 // CHECK:   resolver_return:
-// CHECK-NEXT:ret ptr @_Z3fooi._Msme-f64f64Mbf16
+// CHECK-NEXT:ret ptr @_Z3fooi._Mbf16Msme-f64f64
 // CHECK:   resolver_else:
 // CHECK-NEXT:ret ptr @_Z3fooi
 // CHECK-LABEL: @_Z3foov.resolver(
Index: clang/test/CodeGenCXX/attr-target-clones-aarch64.cpp
===
--- clang/test/CodeGenCXX/attr-target-clones-aarch64.cpp
+++ clang/test/CodeGenCXX/attr-target-clones-aarch64.cpp
@@ -108,7 +108,7 @@
 // CHECK-NEXT:[[TMP3:%.*]] = and i1 true, [[TMP2]]
 // CHECK-NEXT:br i1 [[TMP3]], label [[RESOLVER_RETURN:%.*]], label [[RESOLVER_ELSE:%.*]]
 // CHECK:   resolver_return:
-// CHECK-NEXT:ret ptr @_ZN7MyClassIssE7foo_tmlEv._Msme-f64f64Mssbs
+// CHECK-NEXT:ret ptr @_ZN7MyClassIssE7foo_tmlEv._MssbsMsme-f64f64
 // CHECK:   resolver_else:
 // CHECK-NEXT:[[TMP4:%.*]] = load i64, ptr @__aarch64_cpu_features, align 8
 // CHECK-NEXT:[[TMP5:%.*]] = and i64 [[TMP4]], 16777216
@@ -128,7 +128,7 @@
 // CHECK-NEXT:[[TMP3:%.*]] = and i1 true, [[TMP2]]
 // CHECK-NEXT:br i1 [[TMP3]], label [[RESOLVER_RETURN:%.*]], label [[RESOLVER_ELSE:%.*]]
 // CHECK:   resolver_return:
-// CHECK-NEXT:ret ptr @_ZN7MyClassIisE7foo_tmlEv._Msme-f64f64Mssbs
+// CHECK-NEXT:ret ptr @_ZN7MyClassIisE7foo_tmlEv._MssbsMsme-f64f64
 // CHECK:   resolver_else:
 // CHECK-NEXT:[[TMP4:%.*]] = load i64, ptr @__aarch64_cpu_features, align 8
 // CHECK-NEXT:[[TMP5:%.*]] = and i64 [[TMP4]], 16777216
@@ -157,7 +157,7 @@
 // CHECK-NEXT:store ptr [[THIS:%.*]], ptr [[THIS_ADDR]], align 8
 // CHECK-NEXT:[[THIS1:%.*]] = load ptr, ptr [[THIS_ADDR]], align 8
 // CHECK-NEXT:ret i32 1
-// CHECK-LABEL: @_ZN7MyClassIssE7foo_tmlEv._Msme-f64f64Mssbs(
+// CHECK-LABEL: @_ZN7MyClassIssE7foo_tmlEv._MssbsMsme-f64f64(
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:[[THIS_ADDR:%.*]] = alloca ptr, align 8
 // CHECK-NEXT:store ptr [[THIS:%.*]], ptr [[THIS_ADDR]], align 8
@@ -175,7 +175,7 @@
 // CHECK-NEXT:store ptr [[THIS:%.*]], ptr [[THIS_ADDR]], align 8
 // CHECK-NEXT:[[THIS1:%.*]] = load ptr, ptr [[THIS_ADDR]], align 8
 // CHECK-NEXT:ret i32 2
-// CHECK-LABEL: @_ZN7MyClassIisE7foo_tmlEv._Msme-f64f64Mssbs(
+// CHECK-LABEL: @_ZN7MyClassIisE7foo_tmlEv._MssbsMsme-f64f64(
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:[[THIS_ADDR:%.*]] = alloca ptr, align 8
 // CHECK-NEXT:store ptr [[THIS:%.*]], ptr [[THIS_ADDR]], align 8
Index: clang/test/CodeGen/attr-target-version.c
===
--- clang/test/CodeGen/attr-target-version.c
+++ clang/test/CodeGen/attr-target-version.c
@@ -119,7 +119,7 @@
 // CHECK-LABEL: @fmv(
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:ret i32 0
-// CHECK-LABEL: @fmv_one._Mls64Msimd(
+// CHECK-LABEL: @fmv_one._MsimdMls64(
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:ret i32 1
 // CHECK-LABEL: @fmv_one._Mdpb(
@@ -137,7 +137,7 @@
 // CHECK-LABEL: @fmv_two._Mdgh(
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:ret i32 3
-// CHECK-LABEL: @fmv_two._Mfp16Msimd(
+// CHECK-LABEL: @fmv_two._MsimdMfp16(
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:ret i32 4
 // CHECK-LABEL: @fmv_two(
@@ -229,10 +229,10 @@
 // CHECK-NEXT:ret ptr @fmv
 // CHECK-LABEL: @fmv_one.resolver(
 // CHECK-NEXT:  resolver_entry:
-// CHECK-NEXT:ret ptr @fmv_one._Mls64Msimd
+// CHECK-NEXT:ret ptr @fmv_one._MsimdMls64
 // CHECK-LABEL: @fmv_two.resolver(
 // CHECK-NEXT:  resolver_entry:
-// CHECK-NEXT:ret ptr @fmv_two._Mfp16Msimd
+// CHECK-NEXT:ret ptr @fmv_two._MsimdMfp16
 // CHECK-LABEL: @fmv_e(
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:   

[PATCH] D150875: Make dereferencing a void* a hard-error instead of warn-as-error

2023-05-23 Thread Erich Keane via Phabricator via cfe-commits
erichkeane updated this revision to Diff 524667.
erichkeane added a comment.

Fix tests + Aaron's formatting request.  Guess I forgot to upload this last 
night!


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

https://reviews.llvm.org/D150875

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaExpr.cpp
  clang/test/CXX/temp/temp.decls/temp.class/temp.mem.func/p1inst.cpp
  clang/test/SemaCXX/decl-expr-ambiguity.cpp
  clang/test/SemaCXX/disallow_void_deref.cpp
  clang/test/SemaCXX/reinterpret-cast.cpp

Index: clang/test/SemaCXX/reinterpret-cast.cpp
===
--- clang/test/SemaCXX/reinterpret-cast.cpp
+++ clang/test/SemaCXX/reinterpret-cast.cpp
@@ -214,11 +214,11 @@
   (void)*reinterpret_cast(v_ptr);
 
   // Casting to void pointer
-  (void)*reinterpret_cast(&a); // expected-error {{ISO C++ does not allow}}
-  (void)*reinterpret_cast(&b); // expected-error {{ISO C++ does not allow}}
-  (void)*reinterpret_cast(&l); // expected-error {{ISO C++ does not allow}}
-  (void)*reinterpret_cast(&d); // expected-error {{ISO C++ does not allow}}
-  (void)*reinterpret_cast(&f); // expected-error {{ISO C++ does not allow}}
+  (void)*reinterpret_cast(&a); // expected-error {{indirection not permitted on operand of type 'void *'}}
+  (void)*reinterpret_cast(&b); // expected-error {{indirection not permitted on operand of type 'void *'}}
+  (void)*reinterpret_cast(&l); // expected-error {{indirection not permitted on operand of type 'void *'}}
+  (void)*reinterpret_cast(&d); // expected-error {{indirection not permitted on operand of type 'void *'}}
+  (void)*reinterpret_cast(&f); // expected-error {{indirection not permitted on operand of type 'void *'}}
 }
 
 void reinterpret_cast_allowlist () {
Index: clang/test/SemaCXX/disallow_void_deref.cpp
===
--- clang/test/SemaCXX/disallow_void_deref.cpp
+++ clang/test/SemaCXX/disallow_void_deref.cpp
@@ -1,8 +1,7 @@
-// RUN: %clang_cc1 -fsyntax-only -verify=enabled,sfinae -std=c++20 %s
-// RUN: %clang_cc1 -fsyntax-only -verify=sfinae -std=c++20 -Wno-void-ptr-dereference %s
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 %s
 
 void f(void* p) {
-  (void)*p; // enabled-error{{ISO C++ does not allow indirection on operand of type 'void *'}}
+  (void)*p; // expected-error{{indirection not permitted on operand of type 'void *'}}
 }
 
 template
@@ -11,6 +10,6 @@
 };
 
 static_assert(deref);
-// sfinae-error@-1{{static assertion failed}}
-// sfinae-note@-2{{because 'void *' does not satisfy 'deref'}}
-// sfinae-note@#FAILED_REQ{{because '*t' would be invalid: ISO C++ does not allow indirection on operand of type 'void *'}}
+// expected-error@-1{{static assertion failed}}
+// expected-note@-2{{because 'void *' does not satisfy 'deref'}}
+// expected-note@#FAILED_REQ{{because '*t' would be invalid: indirection not permitted on operand of type 'void *'}}
Index: clang/test/SemaCXX/decl-expr-ambiguity.cpp
===
--- clang/test/SemaCXX/decl-expr-ambiguity.cpp
+++ clang/test/SemaCXX/decl-expr-ambiguity.cpp
@@ -35,7 +35,7 @@
   extern T f3();
   __typeof(*T()) f4(); // expected-warning {{empty parentheses interpreted as a function declaration}} expected-note {{replace parentheses with an initializer}}
   typedef void *V;
-  __typeof(*V()) f5(); // expected-error {{ISO C++ does not allow indirection on operand of type 'V' (aka 'void *')}}
+  __typeof(*V()) f5(); // expected-error {{indirection not permitted on operand of type 'V' (aka 'void *')}}
   T multi1,
 multi2(); // expected-warning {{empty parentheses interpreted as a function declaration}} expected-note {{replace parentheses with an initializer}}
   T(d)[5]; // expected-error {{redefinition of 'd'}}
Index: clang/test/CXX/temp/temp.decls/temp.class/temp.mem.func/p1inst.cpp
===
--- clang/test/CXX/temp/temp.decls/temp.class/temp.mem.func/p1inst.cpp
+++ clang/test/CXX/temp/temp.decls/temp.class/temp.mem.func/p1inst.cpp
@@ -8,7 +8,7 @@
 
 template
 void X0::f(T *t, const U &u) {
-  *t = u; // expected-error{{indirection on operand of type 'void *'}} expected-error{{not assignable}}
+  *t = u; // expected-error{{indirection not permitted on operand of type 'void *'}} expected-error{{not assignable}}
 }
 
 void test_f(X0 xfi, X0 xvi, float *fp, void *vp, int i) {
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -14957,7 +14957,7 @@
 //   be a pointer to an object type, or a pointer to a function type
 LangOptions LO = S.getLangOpts();
 if (LO.CPlusPlus)
-  S.Diag(OpLoc, diag::ext_typecheck_indirection_through_void_pointer_cpp)
+  S.Diag(OpLoc, diag::err_typecheck_indirection_thro

[PATCH] D150953: [Clang][SVE2.1] Add clang support for prototypes using svcount_t

2023-05-23 Thread David Sherwood via Phabricator via cfe-commits
david-arm accepted this revision.
david-arm added a comment.
This revision is now accepted and ready to land.

LGTM!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150953

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


[PATCH] D151121: [Clang][UBSan] Fix the crash caused by __builtin_assume_aligned with -no-opaque-pointers enabled

2023-05-23 Thread Yurong via Phabricator via cfe-commits
yronglin updated this revision to Diff 524673.
yronglin added a comment.

Try fix test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151121

Files:
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/catch-alignment-assumption-array.c
  
clang/test/CodeGen/catch-alignment-assumption-builtin_assume_aligned-polymorphism-no-opaque-ptr.cpp

Index: clang/test/CodeGen/catch-alignment-assumption-builtin_assume_aligned-polymorphism-no-opaque-ptr.cpp
===
--- /dev/null
+++ clang/test/CodeGen/catch-alignment-assumption-builtin_assume_aligned-polymorphism-no-opaque-ptr.cpp
@@ -0,0 +1,61 @@
+// RUN: %clang_cc1 -no-opaque-pointers -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s
+// RUN: %clang_cc1 -no-opaque-pointers -fsanitize=alignment -fno-sanitize-recover=alignment -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s -implicit-check-not="call void @__ubsan_handle_alignment_assumption" --check-prefixes=CHECK,CHECK-SANITIZE,CHECK-SANITIZE-ANYRECOVER,CHECK-SANITIZE-NORECOVER,CHECK-SANITIZE-UNREACHABLE
+// RUN: %clang_cc1 -no-opaque-pointers -fsanitize=alignment -fsanitize-recover=alignment -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s -implicit-check-not="call void @__ubsan_handle_alignment_assumption" --check-prefixes=CHECK,CHECK-SANITIZE,CHECK-SANITIZE-ANYRECOVER,CHECK-SANITIZE-RECOVER
+// RUN: %clang_cc1 -no-opaque-pointers -fsanitize=alignment -fsanitize-trap=alignment -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s -implicit-check-not="call void @__ubsan_handle_alignment_assumption" --check-prefixes=CHECK,CHECK-SANITIZE,CHECK-SANITIZE-TRAP,CHECK-SANITIZE-UNREACHABLE
+
+// CHECK-SANITIZE-ANYRECOVER: @[[CHAR:.*]] = {{.*}} c"'B *'\00" }
+// CHECK-SANITIZE-ANYRECOVER: @[[LINE_100_ALIGNMENT_ASSUMPTION:.*]] = {{.*}}, i32 100, i32 35 }, {{.*}} @[[CHAR]] }
+
+struct A { int n; };
+struct B { int n; };
+struct C : A, B {};
+
+void *f(C *c) {
+  // CHECK: define {{.*}} i8* @{{.*}}(%struct.C* noundef %[[C:.*]]) {{.*}} {
+  // CHECK-NEXT:[[ENTRY:.*]]:
+  // CHECK-NEXT:  %[[C_ADDR:.*]] = alloca %struct.C*
+  // CHECK-NEXT:  store  %struct.C* %[[C]], %struct.C** %[[C_ADDR]]
+  // CHECK-NEXT:  %[[C_RELOAD:.*]] = load %struct.C*, %struct.C** %[[C_ADDR]]
+  // CHECK-NEXT:  %[[IS_NULL:.*]] = icmp eq %struct.C* %[[C_RELOAD]], null
+  // CHECK-NEXT:  br i1 %[[IS_NULL]], label %[[CAST_END:[^,]+]], label %[[CAST_NOT_NULL:[^,]+]]
+  // CHECK: [[CAST_NOT_NULL]]:
+  // CHECK-NOSANITIZE-NEXT:   %[[ADD_PTR:.*]] = getelementptr inbounds i8, ptr %[[C_RELOAD]], i64 4
+  // CHECK-NOSANITIZE-NEXT:   br label %[[CAST_END]]
+  // CHECK-SANITIZE-NEXT: %[[PTRTOINT:.*]] = ptrtoint %struct.C* %[[C_RELOAD]] to i64
+  // CHECK-SANITIZE-NEXT: %[[MASKEDPTR:.*]] = and i64 %[[PTRTOINT]], 3
+  // CHECK-SANITIZE-NEXT: %[[MASKCOND:.*]] = icmp eq i64 %[[MASKEDPTR]], 0
+  // CHECK-SANITIZE-NEXT: br i1 %[[MASKCOND]], label %[[CONT:[^,]+]], label %[[HANDLER_TYPE_MISMATCH:[^,]+]]
+  // CHECK-SANITIZE:[[HANDLER_TYPE_MISMATCH]]:
+  // CHECK-SANITIZE-NORECOVER-NEXT:   call void @__ubsan_handle_type_mismatch_v1_abort(
+  // CHECK-SANITIZE-RECOVER-NEXT: call void @__ubsan_handle_type_mismatch_v1(
+  // CHECK-SANITIZE-TRAP-NEXT:call void @llvm.ubsantrap(
+  // CHECK-SANITIZE-UNREACHABLE-NEXT: unreachable
+  // CHECK-SANITIZE:[[CONT]]:
+  // CHECK-SANITIZE-NEXT: %[[CONT_BITCAST:.*]] = bitcast %struct.C* %0 to i8*
+  // CHECK-SANITIZE-NEXT: %[[ADD_PTR:.*]] = getelementptr inbounds i8, i8* %[[CONT_BITCAST]], i64 4
+  // CHECK-SANITIZE-NEXT: %[[CONT_BITCAST1:.*]] = bitcast i8* %[[ADD_PTR]] to %struct.B*
+  // CHECK-SANITIZE-NEXT: br label %[[CAST_END]]
+  // CHECK: [[CAST_END]]:
+  // CHECK-NOSANITIZE-NEXT:   %[[CAST_RESULT:.*]] = phi %struct.B* [ %[[CONT_BITCAST1]], %[[CAST_NOT_NULL]] ], [ null, %[[ENTRY]] ]
+  // CHECK-NOSANITIZE-NEXT:   call void @llvm.assume(i1 true) [ "align"(ptr %[[CAST_RESULT]], i64 8) ]
+  // CHECK-NOSANITIZE-NEXT:   ret ptr %[[CAST_RESULT]]
+  // CHECK-NOSANITIZE-NEXT:  }
+  // CHECK-SANITIZE-NEXT: %[[CAST_RESULT:.*]] = phi %struct.B* [ %[[CONT_BITCAST1]], %[[CONT]] ], [ null, %[[ENTRY]] ]
+  // CHECK-SANITIZE-NEXT: %[[CAST_RESULT1:.*]] = bitcast %struct.B* %[[CAST_RESULT]] to i8*
+  // CHECK-SANITIZE-NEXT: %[[PTRINT:.*]] = ptrtoint i8* %[[CAST_R

[PATCH] D151094: [clang] Implement P2564 "consteval must propagate up"

2023-05-23 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 524674.
cor3ntin marked 2 inline comments as done.
cor3ntin added a comment.

Improve diagnostic message for immediate calls and add Mariya's examples


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151094

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/Decl.h
  clang/include/clang/AST/DeclBase.h
  clang/include/clang/AST/Expr.h
  clang/include/clang/AST/Stmt.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/ScopeInfo.h
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/Decl.cpp
  clang/lib/AST/DeclPrinter.cpp
  clang/lib/AST/Expr.cpp
  clang/lib/AST/ExprConstant.cpp
  clang/lib/AST/TextNodeDumper.cpp
  clang/lib/AST/VTableBuilder.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/Frontend/InitPreprocessor.cpp
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/lib/Sema/ScopeInfo.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaLambda.cpp
  clang/lib/Sema/SemaStmt.cpp
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/lib/Serialization/ASTReaderStmt.cpp
  clang/lib/Serialization/ASTWriterDecl.cpp
  clang/lib/Serialization/ASTWriterStmt.cpp
  clang/test/CodeGenCXX/cxx20-consteval-crash.cpp
  clang/test/SemaCXX/cxx2a-consteval-default-params.cpp
  clang/test/SemaCXX/cxx2a-consteval.cpp
  clang/test/SemaCXX/cxx2b-consteval-propagate.cpp
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -363,7 +363,7 @@
 
   consteval needs to propagate up
   https://wg21.link/P2564R3";>P2564R3 (DR)
-  No
+  Clang 17
 
 
   Lifetime extension in range-based for loops
Index: clang/test/SemaCXX/cxx2b-consteval-propagate.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/cxx2b-consteval-propagate.cpp
@@ -0,0 +1,152 @@
+// RUN: %clang_cc1 -std=c++2a -emit-llvm-only -Wno-unused-value %s -verify
+// RUN: %clang_cc1 -std=c++2b -emit-llvm-only -Wno-unused-value %s -verify
+
+consteval int id(int i) { return i; }
+constexpr char id(char c) { return c; }
+
+template 
+constexpr int f(T t) { // expected-note {{declared here}}
+return t + id(t);  // expected-note 2{{'f' is an immediate function because its body contains a call to a consteval function 'id' and that call is not a constant expression}}
+}
+
+namespace examples {
+
+auto a = &f; // ok, f is not an immediate function
+auto b = &f;  // expected-error {{cannot take address of immediate function 'f' outside of an immediate invocation}}
+
+static_assert(f(3) == 6); // ok
+
+template 
+constexpr int g(T t) {// g is not an immediate function
+return t + id(42);// because id(42) is already a constant
+}
+
+template 
+constexpr bool is_not(T t, F f) {
+return not f(t);
+}
+
+consteval bool is_even(int i) { return i % 2 == 0; }
+
+static_assert(is_not(5, is_even));
+
+int x = 0; // expected-note {{declared here}}
+
+template 
+constexpr T h(T t = id(x)) { // expected-note {{read of non-const variable 'x' is not allowed in a constant expression}} \
+ // expected-note {{'hh' is an immediate function because its body contains a call to a consteval function 'id' and that call is not a constant expression}}
+return t;
+}
+
+template 
+constexpr T hh() {   // hh is an immediate function
+return h();
+}
+
+int i = hh(); // expected-error {{call to immediate function 'examples::hh' is not a constant expression}} \
+   // expected-note {{in call to 'hh()'}}
+
+struct A {
+  int x;
+  int y = id(x);
+};
+
+template 
+constexpr int k(int) {
+  return A(42).y;
+}
+
+}
+
+namespace nested {
+
+template 
+constexpr int fdupe(T t) {
+return id(t);
+}
+
+struct a {
+  constexpr a(int) { }
+};
+
+a aa(fdupe((f(7;
+
+template 
+constexpr int foo(T t); // expected-note {{declared here}}
+
+a bb(f(foo(7))); // expected-error{{call to immediate function 'f' is not a constant expression}} \
+   // expected-note{{undefined function 'foo' cannot be used in a constant expression}}
+
+}
+
+namespace e2{
+template 
+constexpr int f(T t);
+auto a = &f;
+auto b = &f;
+}
+
+namespace forward_declare_constexpr{
+template 
+constexpr int f(T t);
+
+auto a = &f;
+auto b = &f;
+
+template 
+constexpr int f(T t) {
+return id(0);
+}
+}
+
+namespace forward_declare_consteval{
+template 
+constexpr int f(T t);  // expected-note {{'f' defined here}}
+
+auto a = &f;
+auto b = &f; // expected-error {{immediate function 'f' used before it is defined}} \
+  // expected-note {{in instantiation of function template specialization}}
+
+template 
+constexpr int f(T t) {
+ret

[PATCH] D151094: [clang] Implement P2564 "consteval must propagate up"

2023-05-23 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added a comment.

In D151094#4364133 , @Fznamznon wrote:

> Out of curiosity - does something like these examples - 
> https://godbolt.org/z/Eqb58Wqoo work as expected?

Yes! I added those as tests, thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151094

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


[PATCH] D151094: [clang] Implement P2564 "consteval must propagate up"

2023-05-23 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin marked an inline comment as done.
cor3ntin added inline comments.



Comment at: clang/test/SemaCXX/cxx2b-consteval-propagate.cpp:8
+
+namespace examples {
+

Fznamznon wrote:
> These examples exactly match the ones provided by P2564R3, should they be in 
> a separate test in `CXX` directory then?
I don't have a string preference, should we move the paper examples? the whole 
file?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151094

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


[PATCH] D148700: [clang] Add support for “regular” keyword attributes

2023-05-23 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

This basically LGTM, but we should add documentation to the internals manual 
too: https://clang.llvm.org/docs/InternalsManual.html#spellings




Comment at: clang/lib/AST/TypePrinter.cpp:1724-1727
+  if (T->getAttrKind() == attr::ArmStreaming) {
+OS << "__arm_streaming";
+return;
+  }

rsandifo-arm wrote:
> aaron.ballman wrote:
> > This seems like something that tablegen should automatically handle more 
> > generally for these attributes.
> I wondered about trying to use tablegen for 
> TypePrinter::printAttributedAfter, but decided against it. 
>  RegularKeyword is really a spelling-level classification rather than an 
> attribute-level classification, and in general, an attribute could have both 
> GNU and RegularKeyword spellings. In contrast, printAttributedAfter is only 
> given the attribute kind and the type that results from applying the 
> attribute. AFAIK, it doesn't have access to the original attribute spelling. 
> This means that some attribute-specific or type-specific knowledge might be 
> needed to print the attribute in the best way.
Yeah, we've run into this problem a number of times. Ultimately, we should 
retain what spelling the user used because that's salient information for the 
AST (for example, doing AST matching looking for an `AlignedAttr` attribute 
where the spelling used matters for the intended semantics. But that's not 
something you need to address.



Comment at: clang/lib/Sema/SemaDeclAttr.cpp:5262
+  case ParsedAttr::AT_ArmStreaming:
+CC = CC_C; // Placeholder until real SME support is added.
+break;




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148700

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


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

2023-05-23 Thread Phoebe Wang via Phabricator via cfe-commits
pengfei added a comment.

LGTM.


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

https://reviews.llvm.org/D150913

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


[PATCH] D150953: [Clang][SVE2.1] Add clang support for prototypes using svcount_t

2023-05-23 Thread Sander de Smalen via Phabricator via cfe-commits
sdesmalen added inline comments.



Comment at: clang/include/clang/Basic/Builtins.def:42
 //  q -> Scalable vector, followed by the number of elements and the base type.
+//  Q -> AArch64 svcount_t builtin type.
 //  E -> ext_vector, followed by the number of elements and the base type.

Can we make 'Q' something to mean 'target type' and then use a second letter to 
clarify which exact target type it is, e.g.

  // Q -> target builtin type, followed by a character to distinguish the 
builtin type
  //   Qa -> AArch64 svcount_t builtin type.

That should make it more extensible for other target types in the future.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150953

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


[PATCH] D149948: [include-cleaner] Treat references to nested types implicit

2023-05-23 Thread Haojian Wu via Phabricator via cfe-commits
hokein accepted this revision.
hokein added a comment.
This revision is now accepted and ready to land.

thanks, this solution makes sense!




Comment at: clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp:361
+  struct Derived : public Base {};)cpp",
+   "void fun() { Derived::^a x; }");
+  testWalk("struct Base { struct $implicit^a {}; };",

Maybe add a test for two-level nested specifier (`Derived2::Derived1::a x`)?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149948

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


[PATCH] D123649: Allow flexible array initialization in C++.

2023-05-23 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D123649#4362756 , @efriedma wrote:

> In D123649#4362418 , @aaron.ballman 
> wrote:
>
>> In D123649#4362402 , @efriedma 
>> wrote:
>>
>>> The assertion is correct; without it, your code is getting miscompiled.
>>
>> The assertion may be correct in its intent, but we still should not be 
>> asserting in practice: https://godbolt.org/z/cs5bhvPGr
>
> I wasn't trying to suggest our behavior is correct here, just that the 
> assertion is correctly indicating an underlying issue with the generated IR.

Ah, sorry! I misunderstood. :-)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123649

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


[PATCH] D150875: Make dereferencing a void* a hard-error instead of warn-as-error

2023-05-23 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

I did the llvm-test-suite build, and have a handful of linker issues (because 
I've not built libclang, and don't have some newer GCC library for some float16 
commands), but everythign builds at least.  If necessary, I can try to make 
sure it all builds, but I hope/suspect this is sufficient.


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

https://reviews.llvm.org/D150875

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


[PATCH] D150875: Make dereferencing a void* a hard-error instead of warn-as-error

2023-05-23 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

Fantastic! Presuming precommit CI comes back green this time, LGTM.


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

https://reviews.llvm.org/D150875

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


[PATCH] D151081: [Clang][SVE2.1] Add svpext builtins

2023-05-23 Thread Sander de Smalen via Phabricator via cfe-commits
sdesmalen added inline comments.



Comment at: clang/include/clang/Basic/arm_sve.td:64
+// 2,3,4: array of vectors
+// .: indicator for multi-vector modifier that will follow(eg.:2.x)
 // v: void

`s/follow(eg.:2.x)/follow (e.g. 2.x)/`



Comment at: clang/lib/CodeGen/CGBuiltin.cpp:9466
 
+Value *CodeGenFunction::FormMultiVectorResult(Value *Call) {
+  // Multi-vector results should be broken up into a single (wide) result

Please add `SVE` to the name, i.e. `FormSVEMultiVectorResult`

That said, if Call is not a multi-vector builtin then it just returns the 
result value. So perhaps this is better named `FormSVEBuiltinResult()` ?



Comment at: clang/lib/CodeGen/CGBuiltin.cpp:9466
 
+Value *CodeGenFunction::FormMultiVectorResult(Value *Call) {
+  // Multi-vector results should be broken up into a single (wide) result

sdesmalen wrote:
> Please add `SVE` to the name, i.e. `FormSVEMultiVectorResult`
> 
> That said, if Call is not a multi-vector builtin then it just returns the 
> result value. So perhaps this is better named `FormSVEBuiltinResult()` ?
Can you add a doxygen comment to this function describing what it does?



Comment at: clang/lib/CodeGen/CGBuiltin.cpp:9469-9471
+  if (auto *StructTy = dyn_cast(Call->getType())) {
+if (auto *VTy =
+dyn_cast(StructTy->getTypeAtIndex(0U))) {

Can you implement this with an early exit, e.g.

  auto *StructTy = dyn_cast(Call->getType());
  if (!StructTy)
return Call;

  auto *VTy = dyn_cast(StructTy->getTypeAtIndex(0U));
  if (!VTy)
return Call;

  ...



Comment at: clang/utils/TableGen/SveEmitter.cpp:843
+  case '.':
+llvm_unreachable(". should never be a type");
+break;

nit: "is never a type in itself" ?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151081

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


[PATCH] D150966: [clang] Don't define predefined macros multiple times

2023-05-23 Thread John Brawn via Phabricator via cfe-commits
john.brawn updated this revision to Diff 524686.
john.brawn added a comment.

Add VE test.


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

https://reviews.llvm.org/D150966

Files:
  clang/lib/Basic/Targets/AArch64.cpp
  clang/lib/Basic/Targets/ARM.cpp
  clang/lib/Basic/Targets/AVR.cpp
  clang/lib/Basic/Targets/CSKY.cpp
  clang/lib/Basic/Targets/Hexagon.cpp
  clang/lib/Basic/Targets/Le64.cpp
  clang/lib/Basic/Targets/MSP430.cpp
  clang/lib/Basic/Targets/OSTargets.h
  clang/lib/Basic/Targets/RISCV.cpp
  clang/lib/Basic/Targets/VE.cpp
  clang/lib/Frontend/InitPreprocessor.cpp
  clang/test/Preprocessor/init-ve.c
  clang/test/Preprocessor/predefined-macros-no-warnings.c

Index: clang/test/Preprocessor/predefined-macros-no-warnings.c
===
--- /dev/null
+++ clang/test/Preprocessor/predefined-macros-no-warnings.c
@@ -0,0 +1,199 @@
+// Check that the predefined macros don't contain anything that causes a
+// warning, which needs -Wsystem-headers to detect as the predefined macros
+// are in the  file which is treated as a system header and so has
+// warnings suppressed by default.
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple arc
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple xcore
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple hexagon
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple hexagon-linux
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple lanai
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple aarch64_32-darwin
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple aarch64
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple aarch64-darwin
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple aarch64-cloudabi
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple aarch64-freebsd
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple aarch64-fuchsia
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple aarch64-linux
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple aarch64-linux-openhos
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple aarch64-netbsd
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple aarch64-openbsd
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple aarch64-win32-gnu
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple aarch64-win32-msvc
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple aarch64_be
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple aarch64_be-freebsd
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple aarch64_be-fuchsia
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple aarch64_be-linux
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple aarch64_be-netbsd
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple arm
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple arm-darwin
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple arm-cloudabi
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple arm-freebsd
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple arm-fuchsia
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple arm-linux
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple arm-linux-openhos
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple arm-liteos
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple arm-netbsd
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple arm-openbsd
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple arm-rtems
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple arm-nacl
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple arm-win32-cygnus
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple arm-win32-gnu
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple arm-win32-itanium
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple arm-win32-msvc
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple armeb
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple armeb-linux
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple armeb-freebsd
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple armeb-netbsd
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple armeb-openbsd
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple armeb-rtems
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple a

[PATCH] D150966: [clang] Don't define predefined macros multiple times

2023-05-23 Thread John Brawn via Phabricator via cfe-commits
john.brawn marked an inline comment as done.
john.brawn added inline comments.



Comment at: clang/lib/Basic/Targets/AArch64.cpp:241-242
   Builder.defineMacro("__ARM_FEATURE_QRDMX", "1");
-  Builder.defineMacro("__ARM_FEATURE_ATOMICS", "1");
-  Builder.defineMacro("__ARM_FEATURE_CRC32", "1");
 }

aaron.ballman wrote:
> john.brawn wrote:
> > aaron.ballman wrote:
> > > Hmm, is this correct?
> > > 
> > > `__ARM_FEATURE_ATOMICS` is defined in one other place, but it's 
> > > conditionally defined: 
> > > https://github.com/llvm/llvm-project/blob/11926e6149d2a68ecb0652b248efe6890c163846/clang/lib/Basic/Targets/AArch64.cpp#L475
> > > 
> > > and `__ARM_FEATURE_CRC32` is defined in two places, both conditional: 
> > > https://github.com/llvm/llvm-project/blob/11926e6149d2a68ecb0652b248efe6890c163846/clang/lib/Basic/Targets/AArch64.cpp#L422
> > >  and 
> > > https://github.com/llvm/llvm-project/blob/11926e6149d2a68ecb0652b248efe6890c163846/clang/lib/Basic/Targets/ARM.cpp#L747
> > > 
> > > 
> > AArch64TargetInfo::setArchFeatures sets HasCRC and HasLSE to true for >= 
> > 8.1. This does mean that if you do `-march=armv8.1-a+nocrc` then the 
> > current behaviour is that __ARM_FEATURE_CRC32 is defined but the behaviour 
> > with this patch is that it's not defined, but the new behaviour is correct 
> > as we shouldn't be defining it in that case.
> Ah, okay! I think it's worth adding a test case for that scenario to show 
> we've made a bugfix here, not just an NFC change.
Actually I went and double-checked and I'm wrong, `-march=armv8.N+nowhatever` 
doesn't cause __ARM_FEATURE_WHATEVER to be undefined. Which seems wrong, but 
it's beyond the scope of this patch.



Comment at: clang/lib/Basic/Targets/VE.cpp:30-32
-  Builder.defineMacro("unix", "1");
-  Builder.defineMacro("__unix__", "1");
-  Builder.defineMacro("__linux__", "1");

aaron.ballman wrote:
> john.brawn wrote:
> > aaron.ballman wrote:
> > > Shouldn't this be calling `DefineStd(Builder, "unix", Opts);` like all 
> > > the others?
> > Only the OS target should be defining OS-related macros, and in 
> > AllocateTarget in Targets.cpp VETargetInfo is hardcoded to always use 
> > LinuxTargetInfo, which calls `DefineStd(Builder, "unix", Opts);`.
> Hmmm, we still have calls to this outside of `getOSDefines()` though?
> 
> https://github.com/llvm/llvm-project/blob/main/clang/lib/Basic/Targets/ARM.cpp#L1400
> https://github.com/llvm/llvm-project/blob/main/clang/lib/Basic/Targets/Le64.cpp#L28
> https://github.com/llvm/llvm-project/blob/main/clang/lib/Basic/Targets/X86.h#L634
> https://github.com/llvm/llvm-project/blob/main/clang/lib/Basic/Targets/X86.h#L907
> 
> should those also be changing (perhaps in a follow-up)?
Most of these are TargetInfos that combine OS plus target, e.g. 
CygwinARMTargetInfo is both Cygwin OS and ARM Target. The only exception is 
Le64, and I have no idea if it's correct or not for it to be doing that.


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

https://reviews.llvm.org/D150966

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


[PATCH] D150635: [clangd] Implement end-definition-comment inlay hints

2023-05-23 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clang-tools-extra/clangd/InlayHints.cpp:616
+Position HintStart = sourceLocToPosition(SM, BraceRange.getEnd());
+Position HintEnd = {HintStart.line,
+HintStart.character +

daiyousei-qz wrote:
> sammccall wrote:
> > please don't do this, call sourceLocToPosition unless you have benchmarks 
> > showing this is a bottleneck on real-world code.
> > 
> > `lspLength` and direct manipulation of line/character is unneccesarily 
> > subtle.
> > (If the performance matters, there's no need to be computing the LSP line 
> > of the lbrace at all - we never use it - this is one reason I think this 
> > function has the wrong signature)
> I argue performance does matter here. I eye-balled inlay hint compute time in 
> clangd's output window from vscode. On "./clang/lib/Sema/SemaOpenMP.cpp" 
> which is around 1MB, using `sourceLocToPosition` roughly takes around 
> 1250~1350ms. However, using two `offsetLocToPosition` usually use 
> 1400~1500ms.  I think 100ms delta is already a noticeable difference.
I'm unable to reproduce these results. After verifying EndBlock hints work in 
an editor:

```
$ bin/clangd --check=../clang/lib/Sema/SemaOpenMP.cpp
I[15:50:26.357] clangd version 17.0.0
I[15:50:26.358] Features: linux+debug-tidy
...
 I[15:50:26.358] Testing on source file 
/usr/local/google/home/sammccall/src/llvm-project/clang/lib/Sema/SemaOpenMP.cpp
...
I[15:50:26.428] Building preamble...
I[15:50:31.097] Indexing headers...
I[15:50:32.027] Built preamble of size 53468188 for file 
/usr/local/google/home/sammccall/src/llvm-project/clang/lib/Sema/SemaOpenMP.cpp 
version null in 5.60 seconds
I[15:50:32.032] Building AST...
I[15:50:38.857] Indexing AST...
I[15:50:38.975] Building inlay hints
I[15:50:38.993] Building semantic highlighting
I[15:50:39.050] Testing features at each token (may be slow in large files)
...
```

So that's 18ms for inlay hints after 5.6 seconds to parse the preamble and 6 
seconds to parse the main file. (This is a debug build, opt must be faster).

This is on a fairly powerful machine, but surely it can't be 1000x faster than 
yours - something else must be going on.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150635

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


[PATCH] D148785: -fsanitize=function: use type hashes instead of RTTI objects

2023-05-23 Thread Hans Wennborg via Phabricator via cfe-commits
hans added a comment.

This broke the tests on Mac, see e.g. 
https://green.lab.llvm.org/green/job/clang-stage1-RA/34396/consoleFull (or 
http://crbug.com/1447928)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148785

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


[PATCH] D146358: [clang][AST] Print name instead of type when diagnosing uninitialized subobject in constexpr variables

2023-05-23 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.

In D146358#4364058 , @hazohelet wrote:

> The cause of the regression has been fixed in the other patch.
> This is a resubmission with rebase to the upstream.

LGTM, feel free to land again. I believe the failing precommit CI test is 
unrelated to the changes here, but please keep an eye on the post-commit bots 
just in case.


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

https://reviews.llvm.org/D146358

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


[PATCH] D151042: [clang] Add tests for CWG issues 977, 1482, 2516

2023-05-23 Thread Vlad Serebrennikov via Phabricator via cfe-commits
Endill added a comment.

In D151042#4364149 , @thakis wrote:

> In fact, you can probably repro the test failure on your linux box if you 
> change that test and add locally add -triple=i386-pc-win32 to the RUN line

You're right, MSVC-specific triple make the issue reproduce on my Linux box. 
Thank you!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151042

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


[clang] 28776d5 - [Driver] Try to fix linux-ld.c test with DEFAULT_LINKER set (NFC)

2023-05-23 Thread Nikita Popov via cfe-commits

Author: Nikita Popov
Date: 2023-05-23T16:05:27+02:00
New Revision: 28776d501cad38d56b8e05ba1ec5044c88901d7a

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

LOG: [Driver] Try to fix linux-ld.c test with DEFAULT_LINKER set (NFC)

The test fails on the clang-ppc64le-rhel build bot, which has
DEFAULT_LINKER set and an ld.lld binary in the LLVM build directory.

Added: 


Modified: 
clang/test/Driver/linux-ld.c

Removed: 




diff  --git a/clang/test/Driver/linux-ld.c b/clang/test/Driver/linux-ld.c
index 18ad0b9aa07b..287750ac2046 100644
--- a/clang/test/Driver/linux-ld.c
+++ b/clang/test/Driver/linux-ld.c
@@ -1791,7 +1791,7 @@
 // CHECK-LD-GENTOO-X32: "-lc"
 // CHECK-LD-GENTOO-X32: "-lgcc" "--as-needed" "-lgcc_s" "--no-as-needed"
 
-// RUN: %clang -### %s -no-pie 2>&1 \
+// RUN: %clang -### %s -no-pie -fuse-ld=ld 2>&1 \
 // RUN: --target=x86_64-unknown-linux-gnu \
 // RUN: 
--gcc-toolchain="%S/Inputs/rhel_7_tree/opt/rh/devtoolset-7/root/usr" \
 // RUN: --sysroot="%S/Inputs/rhel_7_tree/opt/rh/devtoolset-7/root" \



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


[clang] 7586aea - [NFC][CLANG] Fix static code analyzer concerns with dereference null return value

2023-05-23 Thread via cfe-commits

Author: Manna, Soumi
Date: 2023-05-23T07:10:44-07:00
New Revision: 7586aeab7ad3fb035752eea89fd2bb895de21143

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

LOG: [NFC][CLANG] Fix static code analyzer concerns with dereference null 
return value

Reported by Static Code Analyzer Tool, Coverity:

Inside "SemaExprMember.cpp" file, in 
clang::Sema::BuildMemberReferenceExpr(clang::Expr *, clang::QualType, 
clang::SourceLocation, bool, clang::CXXScopeSpec &, clang::SourceLocation, 
clang::NamedDecl *, clang::DeclarationNameInfo const &, 
clang::TemplateArgumentListInfo const *, clang::Scope const *, 
clang::Sema::ActOnMemberAccessExtraArgs *): Return value of function which 
returns null is dereferenced without checking

  //Condition !Base, taking true branch.
  if (!Base) {
TypoExpr *TE = nullptr;
QualType RecordTy = BaseType;

 //Condition IsArrow, taking true branch.
 if (IsArrow) RecordTy = RecordTy->castAs()->getPointeeType();
//returned_null: getAs returns nullptr (checked 279 out of 294 times).
//Condition TemplateArgs != NULL, taking true branch.

 //Dereference null return value (NULL_RETURNS)
 //dereference: Dereferencing a pointer that might be nullptr 
RecordTy->getAs() when calling LookupMemberExprInRecord.
 if (LookupMemberExprInRecord(
   *this, R, nullptr, RecordTy->getAs(), OpLoc, IsArrow,
   SS, TemplateArgs != nullptr, TemplateKWLoc, TE))
return ExprError();
 if (TE)
   return TE;

This patch uses castAs instead of getAs which will assert if the type doesn't 
match.

Reviewed By: erichkeane

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

Added: 


Modified: 
clang/lib/Sema/SemaExprMember.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaExprMember.cpp 
b/clang/lib/Sema/SemaExprMember.cpp
index 60b9b013d3f2..3d14ca3859bb 100644
--- a/clang/lib/Sema/SemaExprMember.cpp
+++ b/clang/lib/Sema/SemaExprMember.cpp
@@ -767,7 +767,7 @@ Sema::BuildMemberReferenceExpr(Expr *Base, QualType 
BaseType,
 QualType RecordTy = BaseType;
 if (IsArrow) RecordTy = RecordTy->castAs()->getPointeeType();
 if (LookupMemberExprInRecord(
-*this, R, nullptr, RecordTy->getAs(), OpLoc, IsArrow,
+*this, R, nullptr, RecordTy->castAs(), OpLoc, IsArrow,
 SS, TemplateArgs != nullptr, TemplateKWLoc, TE))
   return ExprError();
 if (TE)



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


  1   2   3   >