[PATCH] D136658: [clang-format] Move InsertBraces unit tests out of FormatTest.cpp

2022-10-26 Thread Owen Pan via Phabricator via cfe-commits
owenpan added a comment.

In D136658#3883372 , @rymiel wrote:

> Is the intent here to somewhat reduce the 30k line behemoth of FormatTest.cpp?

See https://reviews.llvm.org/D136437#3877250 for the motivation.

In D136658#3883511 , 
@HazardyKnusperkeks wrote:

> In D136658#3883372 , @rymiel wrote:
>
>> Is the intent here to somewhat reduce the 30k line behemoth of 
>> FormatTest.cpp?
>
> I'm all in for that! (And will provide a first patch soonish.)

Next I'll move `RemoveBraces` tests out of FormatTest.cpp in another patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136658

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


[PATCH] D136336: [clang-format] Mark pragma region lines as StringLiterals

2022-10-26 Thread Owen Pan via Phabricator via cfe-commits
owenpan added inline comments.



Comment at: clang/lib/Format/TokenAnnotator.cpp:1345
   while (CurrentToken) {
-if (IsMark || CurrentToken->Previous->is(TT_BinaryOperator))
+if (IsMarkOrRegion || CurrentToken->Previous->is(TT_BinaryOperator)) {
   CurrentToken->setType(TT_ImplicitStringLiteral);

thieta wrote:
> HazardyKnusperkeks wrote:
> > This shouldn't be here. There is no closing brace for this, or am I missing 
> > something?
> No you are right it was a miss in the rebase. But it's fixed on main now. 
Probably caused by https://github.com/llvm/llvm-project/issues/58161, which was 
fixed in 37e754e5801c.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136336

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


[PATCH] D126903: [clang] Add support for __builtin_memset_inline

2022-10-26 Thread Tobias Hieta via Phabricator via cfe-commits
thieta added a comment.

We have been building a two stage clang and our internal projects with this 
version of rpmalloc and clang 15.x a while now and I haven't see the issue you 
see @aganea. I don't think this patch is the problem as @efriedma suggested, 
could be in rpmalloc but since I have used this successfully already I am not 
sure about that either.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126903

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


[PATCH] D128440: [WebAssembly] Initial support for reference type funcref in clang

2022-10-26 Thread Paulo Matos via Phabricator via cfe-commits
pmatos updated this revision to Diff 470734.
pmatos added a comment.

Updated this revision on top of D122215 .


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128440

Files:
  clang/include/clang/AST/Type.h
  clang/include/clang/Basic/AddressSpaces.h
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/BuiltinsWebAssembly.def
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/TokenKinds.def
  clang/include/clang/Parse/Parser.h
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/Type.cpp
  clang/lib/AST/TypePrinter.cpp
  clang/lib/Basic/Targets/DirectX.h
  clang/lib/Basic/Targets/NVPTX.h
  clang/lib/Basic/Targets/SPIR.h
  clang/lib/Basic/Targets/TCE.h
  clang/lib/Basic/Targets/WebAssembly.h
  clang/lib/Basic/Targets/X86.h
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/TargetInfo.cpp
  clang/lib/CodeGen/TargetInfo.h
  clang/lib/Format/FormatToken.h
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseTentative.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/CodeGen/WebAssembly/wasm-funcref.c
  clang/test/SemaTemplate/address_space-dependent.cpp

Index: clang/test/SemaTemplate/address_space-dependent.cpp
===
--- clang/test/SemaTemplate/address_space-dependent.cpp
+++ clang/test/SemaTemplate/address_space-dependent.cpp
@@ -43,7 +43,7 @@
 
 template 
 void tooBig() {
-  __attribute__((address_space(I))) int *bounds; // expected-error {{address space is larger than the maximum supported (8388587)}}
+  __attribute__((address_space(I))) int *bounds; // expected-error {{address space is larger than the maximum supported (8388586)}}
 }
 
 template 
@@ -101,7 +101,7 @@
   car<1, 2, 3>(); // expected-note {{in instantiation of function template specialization 'car<1, 2, 3>' requested here}}
   HasASTemplateFields<1> HASTF;
   neg<-1>(); // expected-note {{in instantiation of function template specialization 'neg<-1>' requested here}}
-  correct<0x7FFFEA>();
+  correct<0x7FFFE9>();
   tooBig<8388650>(); // expected-note {{in instantiation of function template specialization 'tooBig<8388650L>' requested here}}
 
   __attribute__((address_space(1))) char *x;
Index: clang/test/CodeGen/WebAssembly/wasm-funcref.c
===
--- /dev/null
+++ clang/test/CodeGen/WebAssembly/wasm-funcref.c
@@ -0,0 +1,84 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// RUN: %clang_cc1 -triple wasm32 -target-feature +reference-types -o - -emit-llvm %s | FileCheck %s
+
+typedef void (*__funcref funcref_t)();
+typedef int (*__funcref fn_funcref_t)(int);
+typedef int (*fn_t)(int);
+
+// Null funcref builtin call
+// CHECK-LABEL: @get_null(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = call ptr addrspace(20) @llvm.wasm.ref.null.func()
+// CHECK-NEXT:ret ptr addrspace(20) [[TMP0]]
+//
+funcref_t get_null() {
+  return __builtin_wasm_ref_null_func();
+}
+
+// Call to null funcref builtin but requires cast since
+// default return value for builtin is a funcref with function type () -> ().
+// CHECK-LABEL: @get_null_ii(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = call ptr addrspace(20) @llvm.wasm.ref.null.func()
+// CHECK-NEXT:ret ptr addrspace(20) [[TMP0]]
+//
+fn_funcref_t get_null_ii() {
+  return (fn_funcref_t) __builtin_wasm_ref_null_func();
+}
+
+// Identity function for funcref.
+// CHECK-LABEL: @identity(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[FN_ADDR:%.*]] = alloca ptr addrspace(20), align 4
+// CHECK-NEXT:store ptr addrspace(20) [[FN:%.*]], ptr [[FN_ADDR]], align 4
+// CHECK-NEXT:[[TMP0:%.*]] = load ptr addrspace(20), ptr [[FN_ADDR]], align 4
+// CHECK-NEXT:ret ptr addrspace(20) [[TMP0]]
+//
+funcref_t identity(funcref_t fn) {
+  return fn;
+}
+
+void helper(funcref_t);
+
+// Pass funcref ref as an argument to a helper function.
+// CHECK-LABEL: @handle(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[FN_ADDR:%.*]] = alloca ptr addrspace(20), align 4
+// CHECK-NEXT:store ptr addrspace(20) [[FN:%.*]], ptr [[FN_ADDR]], align 4
+// CHECK-NEXT:[[TMP0:%.*]] = load ptr addrspace(20), ptr [[FN_ADDR]], align 4
+// CHECK-NEXT:call void @helper(ptr addrspace(20) noundef [[TMP0]])
+// CHECK-NEXT:ret i32 0
+//
+int handle(funcref_t fn) {
+  helper(fn);
+  return 0;
+}
+
+// Return funcref from function pointer.
+// CHECK-LABEL: @get_ref(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[FNPTR_ADDR:%.*]] = alloca ptr, align 4
+// CHECK-NEXT:store ptr [[FNPTR:%.*]], ptr [[FNPTR_ADDR]], align 4
+// CHECK-NEXT:[[TMP0:%.*]] = load ptr, ptr [[FNPTR_ADDR]], align 4
+// CHECK-NEXT:[[TMP1:%.*]] = addrspacecast ptr [[TMP0]] to ptr addrspace(20

[PATCH] D136744: [Clang] perform "maximum TLS alignment" check for template instantiation

2022-10-26 Thread Yuanfang Chen via Phabricator via cfe-commits
ychen created this revision.
ychen added reviewers: probinson, mizvekov.
Herald added a project: All.
ychen requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

follow up d30e2eefc3cf8dfd2210aefd62f13a6e7c011b43


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D136744

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/test/Sema/tls_alignment.cpp

Index: clang/test/Sema/tls_alignment.cpp
===
--- clang/test/Sema/tls_alignment.cpp
+++ clang/test/Sema/tls_alignment.cpp
@@ -58,27 +58,34 @@
bar5.some_data[5];
 }
 
-
-// Verify alignment check where a dependent type is involved.
-// The check is (correctly) not performed on "t", but the check still is
-// performed on the structure as a whole once it has been instantiated.
-
 template struct templated_tls {
 static __thread T t;
 T other_t __attribute__(( aligned(64) ));
 };
-__thread templated_tls blah; // expected-error{{alignment (64) of thread-local variable}}
-
-int blag() {
-return blah.other_t * 2;
-}
+ __thread templated_tls blah; // expected-error{{alignment (64) of thread-local variable}}
 
-
-// Verify alignment check where the alignment is a template parameter.
-// The check is only performed during instantiation.
 template 
 struct S {
+  struct alignas(64) B {};
+  struct alignas(N) C {};
+  static inline void f() {
+thread_local B b; // expected-error{{alignment (64) of thread-local variable}}
+thread_local C c; // expected-error{{alignment (64) of thread-local variable}}
+  }
+  template static inline thread_local int b alignas(J) = J; // expected-error{{alignment (64) of thread-local variable}}
   static int __thread __attribute__((aligned(N))) x; // expected-error{{alignment (64) of thread-local variable}}
 };
 
-S<64> s_instance; // expected-note{{in instantiation of template class 'S<64>' requested here}}
+int blag() {
+// Verify alignment check where the alignment is a template parameter.
+// The check is only performed during instantiation.
+S<64> s_instance; // expected-note{{in instantiation of template class 'S<64>' requested here}}
+
+// Verify alignment for dependent local variables.
+S<64>::f(); // expected-note{{in instantiation of member function 'S<64>::f' requested here}}
+
+// Verify alignment check where a dependent type is involved.
+// The check is (correctly) not performed on "t", but the check still is
+// performed on the structure as a whole once it has been instantiated.
+return blah.other_t * 2 + S<64>::b<64>; // expected-note{{in instantiation of static data member 'S<64>::b' requested here}}
+}
Index: clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -1179,6 +1179,9 @@
   if (Var->isStaticLocal())
 SemaRef.CheckStaticLocalForDllExport(Var);
 
+  if (Var->getTLSKind())
+SemaRef.CheckThreadLocalForLargeAlignment(Var);
+
   return Var;
 }
 
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -14032,6 +14032,29 @@
   }
 }
 
+void Sema::CheckThreadLocalForLargeAlignment(VarDecl *VD) {
+  assert(VD->getTLSKind());
+
+  if (!Context.getTargetInfo().isTLSSupported())
+return;
+
+  // Perform TLS alignment check here after attributes attached to the variable
+  // which may affect the alignment have been processed. Only perform the check
+  // if the target has a maximum TLS alignment (zero means no constraints).
+  if (unsigned MaxAlign = Context.getTargetInfo().getMaxTLSAlign()) {
+// Protect the check so that it's not performed on dependent types and
+// dependent alignments (we can't determine the alignment in that case).
+if (!VD->hasDependentAlignment()) {
+  CharUnits MaxAlignChars = Context.toCharUnitsFromBits(MaxAlign);
+  if (Context.getDeclAlign(VD) > MaxAlignChars) {
+Diag(VD->getLocation(), diag::err_tls_var_aligned_over_maximum)
+<< (unsigned)Context.getDeclAlign(VD).getQuantity() << VD
+<< (unsigned)MaxAlignChars.getQuantity();
+  }
+}
+  }
+}
+
 /// FinalizeDeclaration - called by ParseDeclarationAfterDeclarator to perform
 /// any semantic actions necessary after any initializer has been attached.
 void Sema::FinalizeDeclaration(Decl *ThisDecl) {
@@ -14075,25 +14098,12 @@
 
   checkAttributesAfterMerging(*this, *VD);
 
-  // Perform TLS alignment check here after attributes attached to the variable
-  // which may affect the alignment have been processed. Only perform the check
-  // if the target has a maximum TLS alignment (zero means no constraints).
-  if (unsigned MaxAlign = Con

[PATCH] D136564: [clang] Instantiate NTTPs and template default arguments with sugar

2022-10-26 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added a comment.

In D136564#3884470 , @glandium wrote:

> This broke building Firefox with:
>
>   In file included from Unified_cpp_dom_canvas0.cpp:65:
>   /tmp/gecko/dom/canvas/ClientWebGLContext.cpp:355:19: error: call to deleted 
> function 'IdByMethod'
> const auto id = IdByMethod();
> ^~
>   /tmp/gecko/dom/canvas/ClientWebGLContext.cpp:438:3: note: in instantiation 
> of function template specialization 'mozilla::ClientWebGLContext::Run (mozilla::HostWebGLContext::*)(unsigned long, mozilla::layers::TextureType, 
> bool, const mozilla::webgl::SwapChainOptions &) const, 
> &mozilla::HostWebGLContext::Present, unsigned long, const 
> mozilla::layers::TextureType &, const bool &, 
> mozilla::webgl::SwapChainOptions &>' requested here
> Run(xrFb ? xrFb->mId : 0, type, webvr, asyncOptions);
> ^
>   /tmp/gecko/dom/canvas/WebGLMethodDispatcher.h:20:8: note: candidate 
> function [with MethodT = void (mozilla::HostWebGLContext::*)(unsigned long, 
> mozilla::layers::TextureType, bool, const mozilla::webgl::SwapChainOptions &) 
> const, Method = &mozilla::HostWebGLContext::Present] has been explicitly 
> deleted
>   size_t IdByMethod() = delete;
>  ^
>   In file included from Unified_cpp_dom_canvas0.cpp:65:
>   /tmp/gecko/dom/canvas/ClientWebGLContext.cpp:355:19: error: call to deleted 
> function 'IdByMethod'
> const auto id = IdByMethod();
> ^~
>   /tmp/gecko/dom/canvas/ClientWebGLContext.cpp:447:3: note: in instantiation 
> of function template specialization 'mozilla::ClientWebGLContext::Run (mozilla::HostWebGLContext::*)(unsigned long, mozilla::layers::TextureType, 
> const mozilla::webgl::SwapChainOptions &) const, 
> &mozilla::HostWebGLContext::CopyToSwapChain, unsigned long, const 
> mozilla::layers::TextureType &, mozilla::webgl::SwapChainOptions &>' 
> requested here
> Run(fb ? fb->mId : 0, texType, asyncOptions);
> ^
>   /tmp/gecko/dom/canvas/WebGLMethodDispatcher.h:20:8: note: candidate 
> function [with MethodT = void (mozilla::HostWebGLContext::*)(unsigned long, 
> mozilla::layers::TextureType, const mozilla::webgl::SwapChainOptions &) 
> const, Method = &mozilla::HostWebGLContext::CopyToSwapChain] has been 
> explicitly deleted
>   size_t IdByMethod() = delete;
>  ^
>
> (etc.)

Thanks for reporting. Do you have preprocessed source + cc1 flags to reproduce 
it, so I can have a look?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136564

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


[PATCH] D133874: [clang] Changes to produce sugared converted template arguments

2022-10-26 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added a comment.

In D133874#3884468 , @glandium wrote:

> This broke building Firefox with:

Thanks for reporting. Do you have preprocessed source + cc1 flags to reproduce 
it, so I can have a look?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133874

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


[clang] 31074f5 - Revert "[clang] Instantiate concepts with sugared template arguments"

2022-10-26 Thread Matheus Izvekov via cfe-commits

Author: Matheus Izvekov
Date: 2022-10-26T10:14:14+02:00
New Revision: 31074f5ec2bc89c2a1e3ae0dd94aff87741416b0

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

LOG: Revert "[clang] Instantiate concepts with sugared template arguments"

This reverts commit d0a6de59c78010118fea811514e03ed9f400215a.

Added: 


Modified: 
clang/lib/Sema/SemaConcept.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/lib/Sema/SemaTemplate.cpp
clang/lib/Sema/SemaTemplateDeduction.cpp
clang/lib/Serialization/ASTReaderDecl.cpp
clang/test/AST/ast-dump-concepts.cpp
clang/test/CXX/expr/expr.prim/expr.prim.req/compound-requirement.cpp
clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp
clang/test/CXX/expr/expr.prim/expr.prim.req/simple-requirement.cpp
clang/test/CXX/expr/expr.prim/expr.prim.req/type-requirement.cpp
clang/test/CXX/temp/temp.constr/temp.constr.normal/p1.cpp
clang/test/CXX/temp/temp.param/p10-2a.cpp
clang/test/SemaTemplate/cxx2a-constraint-caching.cpp
clang/test/SemaTemplate/instantiate-requires-expr.cpp
clang/test/SemaTemplate/pr52970.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp
index ff1f650a52084..83b23b249d4e8 100644
--- a/clang/lib/Sema/SemaConcept.cpp
+++ b/clang/lib/Sema/SemaConcept.cpp
@@ -1077,7 +1077,7 @@ static bool substituteParameterMappings(Sema &S, 
NormalizedConstraint &N,
   TemplateArgumentList TAL{TemplateArgumentList::OnStack,
CSE->getTemplateArguments()};
   MultiLevelTemplateArgumentList MLTAL = S.getTemplateInstantiationArgs(
-  CSE->getNamedConcept(), /*Final=*/true, &TAL,
+  CSE->getNamedConcept(), /*Final=*/false, &TAL,
   /*RelativeToPrimary=*/true,
   /*Pattern=*/nullptr,
   /*ForConstraintInstantiation=*/true);

diff  --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index bb9cfe30e5d4d..25eeab370eeb8 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -1475,57 +1475,53 @@ Sema::BuildCXXTypeConstructExpr(TypeSourceInfo *TInfo,
   // C++2b:
   //   Otherwise, if the type contains a placeholder type, it is replaced by 
the
   //   type determined by placeholder type deduction.
-  if (const DeducedType *Deduced = Ty->getContainedDeducedType();
-  Deduced && !Deduced->isDeduced()) {
-if (isa(Deduced)) {
-  Ty = DeduceTemplateSpecializationFromInitializer(TInfo, Entity, Kind,
-   Exprs);
-  if (Ty.isNull())
-return ExprError();
-  Entity = InitializedEntity::InitializeTemporary(TInfo, Ty);
-} else {
-  assert(isa(Deduced));
-  MultiExprArg Inits = Exprs;
-  if (ListInitialization) {
-auto *ILE = cast(Exprs[0]);
-Inits = MultiExprArg(ILE->getInits(), ILE->getNumInits());
-  }
-
-  if (Inits.empty())
-return ExprError(
-Diag(TyBeginLoc, diag::err_auto_expr_init_no_expression)
-<< Ty << FullRange);
-  if (Inits.size() > 1) {
-Expr *FirstBad = Inits[1];
-return ExprError(Diag(FirstBad->getBeginLoc(),
-  diag::err_auto_expr_init_multiple_expressions)
- << Ty << FullRange);
-  }
-  if (getLangOpts().CPlusPlus2b) {
-if (Ty->getAs())
-  Diag(TyBeginLoc, diag::warn_cxx20_compat_auto_expr) << FullRange;
-  }
-  Expr *Deduce = Inits[0];
-  if (isa(Deduce))
-return ExprError(
-Diag(Deduce->getBeginLoc(), diag::err_auto_expr_init_paren_braces)
-<< ListInitialization << Ty << FullRange);
-  QualType DeducedType;
-  TemplateDeductionInfo Info(Deduce->getExprLoc());
-  TemplateDeductionResult Result =
-  DeduceAutoType(TInfo->getTypeLoc(), Deduce, DeducedType, Info);
-  if (Result != TDK_Success && Result != TDK_AlreadyDiagnosed)
-return ExprError(Diag(TyBeginLoc, 
diag::err_auto_expr_deduction_failure)
- << Ty << Deduce->getType() << FullRange
- << Deduce->getSourceRange());
-  if (DeducedType.isNull()) {
-assert(Result == TDK_AlreadyDiagnosed);
-return ExprError();
-  }
+  DeducedType *Deduced = Ty->getContainedDeducedType();
+  if (Deduced && isa(Deduced)) {
+Ty = DeduceTemplateSpecializationFromInitializer(TInfo, Entity,
+ Kind, Exprs);
+if (Ty.isNull())
+  return ExprError();
+Entity = InitializedEntity::InitializeTemporary(TInfo, Ty);
+  } else if (Deduced) {
+MultiExprArg Inits = Exprs;
+if (ListInitialization) {
+  auto *ILE = cast(Exprs[0]);
+  Inits = MultiExprArg(ILE->getInits(), ILE->getNumI

[clang-tools-extra] a58d83b - Revert "[clang] Instantiate alias templates with sugar"

2022-10-26 Thread Matheus Izvekov via cfe-commits

Author: Matheus Izvekov
Date: 2022-10-26T10:14:21+02:00
New Revision: a58d83b2c97cd480a8533b11b86c7cd709c48176

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

LOG: Revert "[clang] Instantiate alias templates with sugar"

This reverts commit 4c44c91ad980304c5cca3792115349e68cfafd2b.

Added: 


Modified: 
clang-tools-extra/clangd/unittests/HoverTests.cpp
clang/lib/Sema/SemaTemplate.cpp
clang/test/AST/ast-dump-template-decls.cpp
clang/test/CXX/temp/temp.deduct.guide/p3.cpp
clang/test/Misc/diag-template-diffing.cpp
clang/test/SemaCXX/sizeless-1.cpp
clang/test/SemaTemplate/make_integer_seq.cpp
clang/test/SemaTemplate/temp_arg_nontype.cpp

lldb/test/API/commands/expression/import-std-module/shared_ptr/TestSharedPtrFromStdModule.py

lldb/test/API/commands/expression/import-std-module/weak_ptr-dbg-info-content/TestDbgInfoContentWeakPtrFromStdModule.py

lldb/test/API/commands/expression/import-std-module/weak_ptr/TestWeakPtrFromStdModule.py

Removed: 




diff  --git a/clang-tools-extra/clangd/unittests/HoverTests.cpp 
b/clang-tools-extra/clangd/unittests/HoverTests.cpp
index 8bca0dc974539..9f64defaf898f 100644
--- a/clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ b/clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -1067,7 +1067,7 @@ class Foo final {})cpp";
  HI.LocalScope = "";
  HI.Kind = index::SymbolKind::TypeAlias;
  HI.Definition = "template  using AA = A";
- HI.Type = {"A", "T"};
+ HI.Type = {"A", "type-parameter-0-0"}; // FIXME: should be 'T'
  HI.TemplateParameters = {{{"typename"}, std::string("T"), 
llvm::None}};
}},
   {// Constant array

diff  --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index c5a86486b2dea..37eaa2a5795aa 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -3854,8 +3854,8 @@ QualType Sema::CheckTemplateIdType(TemplateName Name,
 
 // Only substitute for the innermost template argument list.
 MultiLevelTemplateArgumentList TemplateArgLists;
-TemplateArgLists.addOuterTemplateArguments(Template, SugaredConverted,
-   /*Final=*/true);
+TemplateArgLists.addOuterTemplateArguments(Template, CanonicalConverted,
+   /*Final=*/false);
 TemplateArgLists.addOuterRetainedLevels(
 AliasTemplate->getTemplateParameters()->getDepth());
 

diff  --git a/clang/test/AST/ast-dump-template-decls.cpp 
b/clang/test/AST/ast-dump-template-decls.cpp
index 3bc0357d1b51f..49760d17c7f22 100644
--- a/clang/test/AST/ast-dump-template-decls.cpp
+++ b/clang/test/AST/ast-dump-template-decls.cpp
@@ -120,6 +120,8 @@ using type2 = typename C::type1;
 // CHECK-NEXT: TemplateArgument type 'void'
 // CHECK-NEXT: BuiltinType 0x{{[^ ]*}} 'void'
 // CHECK-NEXT: FunctionProtoType 0x{{[^ ]*}} 'void (int)' cdecl
+// CHECK-NEXT: SubstTemplateTypeParmType 0x{{[^ ]*}} 'void' sugar class depth 
0 index 0 U
+// CHECK-NEXT: TypeAliasTemplate 0x{{[^ ]*}} 'type1'
 // CHECK-NEXT: BuiltinType 0x{{[^ ]*}} 'void'
 // CHECK-NEXT: SubstTemplateTypeParmType 0x{{[^ ]*}} 'int' sugar class depth 0 
index 0 T
 // CHECK-NEXT: ClassTemplateSpecialization 0x{{[^ ]*}} 'C'
@@ -127,24 +129,38 @@ using type2 = typename C::type1;
 } // namespace PR55886
 
 namespace PR56099 {
+template  struct Y;
+template  using Z = Y;
+template  struct foo {
+  template  using bind = Z;
+};
+using t1 = foo::bind;
+// CHECK:  TemplateSpecializationType 0x{{[^ ]*}} 'Y' sugar Y
+// CHECK:  SubstTemplateTypeParmType 0x{{[^ ]*}} 'char' sugar typename 
depth 0 index 0 ... Bs pack_index 3
+// CHECK-NEXT: TypeAliasTemplate 0x{{[^ ]*}} 'Z'
+// CHECK:  SubstTemplateTypeParmType 0x{{[^ ]*}} 'float' sugar typename 
depth 0 index 0 ... Bs pack_index 2
+// CHECK-NEXT: TypeAliasTemplate 0x{{[^ ]*}} 'Z'
+// CHECK:  SubstTemplateTypeParmType 0x{{[^ ]*}} 'int' sugar typename 
depth 0 index 0 ... Bs pack_index 1
+// CHECK-NEXT: TypeAliasTemplate 0x{{[^ ]*}} 'Z'
+// CHECK:  SubstTemplateTypeParmType 0x{{[^ ]*}} 'short' sugar typename 
depth 0 index 0 ... Bs pack_index 0
+// CHECK-NEXT: TypeAliasTemplate 0x{{[^ ]*}} 'Z'
+
 template  struct D {
-  template  struct bind {
-using bound_type = int(int (*...p)(T, U));
-  };
+  template  using B = int(int (*...p)(T, U));
 };
-template struct D::bind;
-// CHECK:  TypeAliasDecl 0x{{[^ ]*}}  col:11 
bound_type 'int (int (*)(float, int), int (*)(char, short))'
+using t2 = D::B;
+// CHECK:  TemplateSpecializationType 0x{{[^ ]*}} 'B' sugar 
alias B
 // CHECK:  FunctionProtoType 0x{{[^ ]*}} 'int (int (*)(float, int), int 
(*)(char, short))' cdecl
 // CHECK:  FunctionProtoType 0x{{[^ ]*}} 'int (float, in

[clang] 8383c2a - Revert "[clang] Implement sugared substitution changes to infrastructure"

2022-10-26 Thread Matheus Izvekov via cfe-commits

Author: Matheus Izvekov
Date: 2022-10-26T10:14:31+02:00
New Revision: 8383c2a435ecf9a86dc8f903a3d0b0b561422eeb

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

LOG: Revert "[clang] Implement sugared substitution changes to infrastructure"

This reverts commit c4c2a3c65684e062efcd101a957c6cae0a304a7a.

Added: 


Modified: 
clang/include/clang/AST/ASTContext.h
clang/include/clang/AST/PropertiesBase.td
clang/include/clang/AST/TemplateName.h
clang/include/clang/AST/Type.h
clang/include/clang/AST/TypeProperties.td
clang/include/clang/Sema/Sema.h
clang/include/clang/Sema/Template.h
clang/lib/AST/ASTContext.cpp
clang/lib/AST/ASTImporter.cpp
clang/lib/AST/TemplateName.cpp
clang/lib/AST/Type.cpp
clang/lib/Sema/SemaConcept.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/lib/Sema/SemaTemplate.cpp
clang/lib/Sema/SemaTemplateDeduction.cpp
clang/lib/Sema/SemaTemplateInstantiate.cpp
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
clang/lib/Sema/SemaType.cpp
clang/lib/Sema/TreeTransform.h
clang/lib/Sema/TypeLocBuilder.cpp
clang/lib/Sema/TypeLocBuilder.h
clang/test/SemaTemplate/nested-name-spec-template.cpp

Removed: 




diff  --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index 2a21f2d1f37ee..a6b3301f2a73a 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -1621,7 +1621,7 @@ class ASTContext : public RefCountedBase {
 Decl *AssociatedDecl, unsigned Index,
 Optional PackIndex) const;
   QualType getSubstTemplateTypeParmPackType(Decl *AssociatedDecl,
-unsigned Index, bool Final,
+unsigned Index,
 const TemplateArgument &ArgPack);
 
   QualType
@@ -2207,8 +2207,7 @@ class ASTContext : public RefCountedBase {
 Optional PackIndex) 
const;
   TemplateName getSubstTemplateTemplateParmPack(const TemplateArgument 
&ArgPack,
 Decl *AssociatedDecl,
-unsigned Index,
-bool Final) const;
+unsigned Index) const;
 
   enum GetBuiltinTypeError {
 /// No error

diff  --git a/clang/include/clang/AST/PropertiesBase.td 
b/clang/include/clang/AST/PropertiesBase.td
index f952b08502db1..9fe80440953f4 100644
--- a/clang/include/clang/AST/PropertiesBase.td
+++ b/clang/include/clang/AST/PropertiesBase.td
@@ -730,11 +730,8 @@ let Class = PropertyTypeCase in {
   def : Property<"index", UInt32> {
 let Read = [{ parm->getIndex() }];
   }
-  def : Property<"final", Bool> {
-let Read = [{ parm->getFinal() }];
-  }
   def : Creator<[{
-return ctx.getSubstTemplateTemplateParmPack(argumentPack, associatedDecl, 
index, final);
+return ctx.getSubstTemplateTemplateParmPack(argumentPack, associatedDecl, 
index);
   }]>;
 }
 

diff  --git a/clang/include/clang/AST/TemplateName.h 
b/clang/include/clang/AST/TemplateName.h
index 82bbe72d22e58..25aa991d3b841 100644
--- a/clang/include/clang/AST/TemplateName.h
+++ b/clang/include/clang/AST/TemplateName.h
@@ -139,24 +139,25 @@ class OverloadedTemplateStorage : public 
UncommonTemplateNameStorage {
 class SubstTemplateTemplateParmPackStorage : public 
UncommonTemplateNameStorage,
  public llvm::FoldingSetNode {
   const TemplateArgument *Arguments;
-  llvm::PointerIntPair AssociatedDeclAndFinal;
+  Decl *AssociatedDecl;
 
 public:
   SubstTemplateTemplateParmPackStorage(ArrayRef ArgPack,
-   Decl *AssociatedDecl, unsigned Index,
-   bool Final);
+   Decl *AssociatedDecl, unsigned Index)
+  : UncommonTemplateNameStorage(SubstTemplateTemplateParmPack, Index,
+ArgPack.size()),
+Arguments(ArgPack.data()), AssociatedDecl(AssociatedDecl) {
+assert(AssociatedDecl != nullptr);
+  }
 
   /// A template-like entity which owns the whole pattern being substituted.
   /// This will own a set of template parameters.
-  Decl *getAssociatedDecl() const;
+  Decl *getAssociatedDecl() const { return AssociatedDecl; }
 
   /// Returns the index of the replaced parameter in the associated 
declaration.
   /// This should match the result of `getParameterPack()->getIndex()`.
   unsigned getIndex() const { return Bits.Index; }
 
-  // When true the substitution will be 'Final' (subst node won't 

[clang] 434a238 - Revert "[clang] Perform sugared substitution of builtin templates"

2022-10-26 Thread Matheus Izvekov via cfe-commits

Author: Matheus Izvekov
Date: 2022-10-26T10:14:37+02:00
New Revision: 434a238a4247f37ab42dece0913ab1e007564db9

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

LOG: Revert "[clang] Perform sugared substitution of builtin templates"

This reverts commit e5d9e802e50dd55a326e31a0d562e5263b208f3b.

Added: 


Modified: 
clang/lib/Sema/SemaTemplate.cpp
clang/test/SemaTemplate/make_integer_seq.cpp
clang/test/SemaTemplate/type_pack_element.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 9c22fd91dd0ff..86c7ce1b8ee8a 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -3577,11 +3577,18 @@ void Sema::NoteAllFoundTemplates(TemplateName Name) {
 
 static QualType
 checkBuiltinTemplateIdType(Sema &SemaRef, BuiltinTemplateDecl *BTD,
-   ArrayRef Converted,
+   const SmallVectorImpl &Converted,
SourceLocation TemplateLoc,
TemplateArgumentListInfo &TemplateArgs) {
   ASTContext &Context = SemaRef.getASTContext();
 
+  // Wrap the type in substitution sugar.
+  auto getSubstType = [&](QualType Replacement, unsigned IndexReplaced,
+  Optional PackIndexReplaced) {
+return SemaRef.Context.getSubstTemplateTypeParmType(
+Replacement, BTD, IndexReplaced, PackIndexReplaced);
+  };
+
   switch (BTD->getBuiltinTemplateKind()) {
   case BTK__make_integer_seq: {
 // Specializations of __make_integer_seq are treated like
@@ -3604,18 +3611,19 @@ checkBuiltinTemplateIdType(Sema &SemaRef, 
BuiltinTemplateDecl *BTD,
 TemplateArgumentListInfo SyntheticTemplateArgs;
 // The type argument, wrapped in substitution sugar, gets reused as the
 // first template argument in the synthetic template argument list.
+QualType SyntheticType = getSubstType(OrigType, 1, None);
 SyntheticTemplateArgs.addArgument(
-TemplateArgumentLoc(TemplateArgument(OrigType),
+TemplateArgumentLoc(TemplateArgument(SyntheticType),
 SemaRef.Context.getTrivialTypeSourceInfo(
-OrigType, TemplateArgs[1].getLocation(;
+SyntheticType, 
TemplateArgs[1].getLocation(;
 
 if (llvm::APSInt NumArgs = NumArgsArg.getAsIntegral(); NumArgs >= 0) {
   // Expand N into 0 ... N-1.
   for (llvm::APSInt I(NumArgs.getBitWidth(), NumArgs.isUnsigned());
I < NumArgs; ++I) {
-TemplateArgument TA(Context, I, OrigType);
+TemplateArgument TA(Context, I, SyntheticType);
 
SyntheticTemplateArgs.addArgument(SemaRef.getTrivialTemplateArgumentLoc(
-TA, OrigType, TemplateArgs[2].getLocation()));
+TA, SyntheticType, TemplateArgs[2].getLocation()));
   }
 } else {
   // C++14 [inteseq.make]p1:
@@ -3625,10 +3633,13 @@ checkBuiltinTemplateIdType(Sema &SemaRef, 
BuiltinTemplateDecl *BTD,
   return QualType();
 }
 
+// Wrap the template in substitution sugar.
+TemplateName TN = SemaRef.Context.getSubstTemplateTemplateParm(
+Converted[0].getAsTemplate(), BTD, 0, None);
+
 // The first template argument will be reused as the template decl that
 // our synthetic template arguments will be applied to.
-return SemaRef.CheckTemplateIdType(Converted[0].getAsTemplate(),
-   TemplateLoc, SyntheticTemplateArgs);
+return SemaRef.CheckTemplateIdType(TN, TemplateLoc, SyntheticTemplateArgs);
   }
 
   case BTK__type_pack_element:
@@ -3655,7 +3666,8 @@ checkBuiltinTemplateIdType(Sema &SemaRef, 
BuiltinTemplateDecl *BTD,
 
 // We simply return the type at index `Index`.
 int64_t N = Index.getExtValue();
-return Ts.getPackAsArray()[N].getAsType();
+return getSubstType(Ts.getPackAsArray()[N].getAsType(), 1,
+Ts.pack_size() - 1 - N);
   }
   llvm_unreachable("unexpected BuiltinTemplateDecl!");
 }
@@ -3903,7 +3915,7 @@ QualType Sema::CheckTemplateIdType(TemplateName Name,
   return QualType();
 }
   } else if (auto *BTD = dyn_cast(Template)) {
-CanonType = checkBuiltinTemplateIdType(*this, BTD, SugaredConverted,
+CanonType = checkBuiltinTemplateIdType(*this, BTD, CanonicalConverted,
TemplateLoc, TemplateArgs);
   } else if (Name.isDependent() ||
  TemplateSpecializationType::anyDependentTemplateArguments(

diff  --git a/clang/test/SemaTemplate/make_integer_seq.cpp 
b/clang/test/SemaTemplate/make_integer_seq.cpp
index b51eed59961e2..576169e20e148 100644
--- a/clang/test/SemaTemplate/make_integer_seq.cpp
+++ b/clang/test/SemaTemplate/make_integer_seq.cpp
@@ -14,18 +1

[clang] a88ebd4 - Revert "[clang] Instantiate NTTPs and template default arguments with sugar"

2022-10-26 Thread Matheus Izvekov via cfe-commits

Author: Matheus Izvekov
Date: 2022-10-26T10:14:27+02:00
New Revision: a88ebd405da67b4cebf094c5a56f9aed97875423

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

LOG: Revert "[clang] Instantiate NTTPs and template default arguments with 
sugar"

This reverts commit 2560c1266993af6e6c15900ce673c6db23132f8b.

Added: 


Modified: 
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaTemplate.cpp
clang/lib/Sema/SemaTemplateDeduction.cpp
clang/test/AST/ast-dump-template-decls.cpp
clang/test/CXX/drs/dr3xx.cpp
clang/test/CXX/expr/expr.const/p3-0x.cpp
clang/test/Misc/diag-template-diffing.cpp
clang/test/SemaTemplate/instantiation-default-1.cpp
clang/test/SemaTemplate/make_integer_seq.cpp

Removed: 




diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 37ad78f3d7969..d0757f874303f 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -8199,11 +8199,14 @@ class Sema final {
 SourceLocation TemplateLoc,
 Declarator &D);
 
-  TemplateArgumentLoc SubstDefaultTemplateArgumentIfAvailable(
-  TemplateDecl *Template, SourceLocation TemplateLoc,
-  SourceLocation RAngleLoc, Decl *Param,
-  ArrayRef SugaredConverted,
-  ArrayRef CanonicalConverted, bool &HasDefaultArg);
+  TemplateArgumentLoc
+  SubstDefaultTemplateArgumentIfAvailable(TemplateDecl *Template,
+  SourceLocation TemplateLoc,
+  SourceLocation RAngleLoc,
+  Decl *Param,
+  SmallVectorImpl
+&Converted,
+  bool &HasDefaultArg);
 
   /// Specifies the context in which a particular template
   /// argument is being checked.

diff  --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 37eaa2a5795aa..73c681035b161 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -5261,25 +5261,27 @@ bool Sema::CheckTemplateTypeArgument(
 /// \param Converted the list of template arguments provided for template
 /// parameters that precede \p Param in the template parameter list.
 /// \returns the substituted template argument, or NULL if an error occurred.
-static TypeSourceInfo *SubstDefaultTemplateArgument(
-Sema &SemaRef, TemplateDecl *Template, SourceLocation TemplateLoc,
-SourceLocation RAngleLoc, TemplateTypeParmDecl *Param,
-ArrayRef SugaredConverted,
-ArrayRef CanonicalConverted) {
+static TypeSourceInfo *
+SubstDefaultTemplateArgument(Sema &SemaRef,
+ TemplateDecl *Template,
+ SourceLocation TemplateLoc,
+ SourceLocation RAngleLoc,
+ TemplateTypeParmDecl *Param,
+ SmallVectorImpl &Converted) {
   TypeSourceInfo *ArgType = Param->getDefaultArgumentInfo();
 
   // If the argument type is dependent, instantiate it now based
   // on the previously-computed template arguments.
   if (ArgType->getType()->isInstantiationDependentType()) {
-Sema::InstantiatingTemplate Inst(SemaRef, TemplateLoc, Param, Template,
- SugaredConverted,
+Sema::InstantiatingTemplate Inst(SemaRef, TemplateLoc,
+ Param, Template, Converted,
  SourceRange(TemplateLoc, RAngleLoc));
 if (Inst.isInvalid())
   return nullptr;
 
 // Only substitute for the innermost template argument list.
-MultiLevelTemplateArgumentList TemplateArgLists(Template, SugaredConverted,
-/*Final=*/true);
+MultiLevelTemplateArgumentList TemplateArgLists(Template, Converted,
+/*Final=*/false);
 for (unsigned i = 0, e = Param->getDepth(); i != e; ++i)
   TemplateArgLists.addOuterTemplateArguments(None);
 
@@ -5318,20 +5320,22 @@ static TypeSourceInfo *SubstDefaultTemplateArgument(
 /// parameters that precede \p Param in the template parameter list.
 ///
 /// \returns the substituted template argument, or NULL if an error occurred.
-static ExprResult SubstDefaultTemplateArgument(
-Sema &SemaRef, TemplateDecl *Template, SourceLocation TemplateLoc,
-SourceLocation RAngleLoc, NonTypeTemplateParmDecl *Param,
-ArrayRef SugaredConverted,
-ArrayRef CanonicalConverted) {
-  Sema::InstantiatingTemplate Inst(SemaRef, TemplateLoc, Param, Template,
-   SugaredConverted,
+static ExprResult

[PATCH] D136664: [CMake] Support building crt with the bootstrapping build

2022-10-26 Thread Petr Hosek via Phabricator via cfe-commits
phosek added a comment.

In D136664#3882989 , @smeenai wrote:

> I might be missing it, but I don't see `crt` depending on `builtins` (or vice 
> versa). If there is actually no dep, could we build them together in a single 
> configure, instead of needing to add another one for crt? If there is a dep 
> and I missed it, then this LGTM.

There is no dependency because `crt` and `builtins` aren't dependent on each 
other. We could build them in a single configure, but we would another top 
level `CMakeLists.txt`. Do you have any suggestions for where that should live?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136664

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


[PATCH] D136746: [mlir] Saturation arithmetic intrinsics

2022-10-26 Thread Omri Bloch via Phabricator via cfe-commits
omri123 created this revision.
omri123 added reviewers: ftynse, gysit, llvm-commits, cfe-commits.
Herald added subscribers: zero9178, bzcheeseman, awarzynski, sdasgup3, 
wenzhicui, wrengr, cota, teijeong, rdzhabarov, tatianashp, msifontes, jurahul, 
Kayjukh, grosul1, Joonsoo, liufengdb, aartbik, mgester, arpith-jacob, 
antiagainst, shauheen, rriddle, mehdi_amini.
Herald added a project: All.
omri123 requested review of this revision.
Herald added a reviewer: nicolasvasilache.
Herald added subscribers: stephenneuendorffer, nicolasvasilache.
Herald added a reviewer: dcaballe.
Herald added a project: MLIR.

Add the following saturation arithmetic llvm intrinsic ops: sadd.sat, uadd.sat, 
ssub.sat, usub.sat


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D136746

Files:
  mlir/include/mlir/Dialect/LLVMIR/LLVMIntrinsicOps.td
  mlir/test/Target/LLVMIR/Import/intrinsic.ll
  mlir/test/Target/LLVMIR/llvmir-intrinsics.mlir

Index: mlir/test/Target/LLVMIR/llvmir-intrinsics.mlir
===
--- mlir/test/Target/LLVMIR/llvmir-intrinsics.mlir
+++ mlir/test/Target/LLVMIR/llvmir-intrinsics.mlir
@@ -428,6 +428,42 @@
   llvm.return
 }

+// CHECK-LABEL: @sadd_sat_test
+llvm.func @sadd_sat_test(%arg0: i32, %arg1: i32, %arg2: vector<8xi32>, %arg3: vector<8xi32>) {
+  // CHECK: call i32 @llvm.sadd.sat.i32
+  "llvm.intr.sadd.sat"(%arg0, %arg1) : (i32, i32) -> i32
+  // CHECK: call <8 x i32> @llvm.sadd.sat.v8i32
+  "llvm.intr.sadd.sat"(%arg2, %arg3) : (vector<8xi32>, vector<8xi32>) -> vector<8xi32>
+  llvm.return
+}
+
+// CHECK-LABEL: @uadd_sat_test
+llvm.func @uadd_sat_test(%arg0: i32, %arg1: i32, %arg2: vector<8xi32>, %arg3: vector<8xi32>) {
+  // CHECK: call i32 @llvm.uadd.sat.i32
+  "llvm.intr.uadd.sat"(%arg0, %arg1) : (i32, i32) -> i32
+  // CHECK: call <8 x i32> @llvm.uadd.sat.v8i32
+  "llvm.intr.uadd.sat"(%arg2, %arg3) : (vector<8xi32>, vector<8xi32>) -> vector<8xi32>
+  llvm.return
+}
+
+// CHECK-LABEL: @ssub_sat_test
+llvm.func @ssub_sat_test(%arg0: i32, %arg1: i32, %arg2: vector<8xi32>, %arg3: vector<8xi32>) {
+  // CHECK: call i32 @llvm.ssub.sat.i32
+  "llvm.intr.ssub.sat"(%arg0, %arg1) : (i32, i32) -> i32
+  // CHECK: call <8 x i32> @llvm.ssub.sat.v8i32
+  "llvm.intr.ssub.sat"(%arg2, %arg3) : (vector<8xi32>, vector<8xi32>) -> vector<8xi32>
+  llvm.return
+}
+
+// CHECK-LABEL: @usub_sat_test
+llvm.func @usub_sat_test(%arg0: i32, %arg1: i32, %arg2: vector<8xi32>, %arg3: vector<8xi32>) {
+  // CHECK: call i32 @llvm.usub.sat.i32
+  "llvm.intr.usub.sat"(%arg0, %arg1) : (i32, i32) -> i32
+  // CHECK: call <8 x i32> @llvm.usub.sat.v8i32
+  "llvm.intr.usub.sat"(%arg2, %arg3) : (vector<8xi32>, vector<8xi32>) -> vector<8xi32>
+  llvm.return
+}
+
 // CHECK-LABEL: @coro_id
 llvm.func @coro_id(%arg0: i32, %arg1: !llvm.ptr) {
   // CHECK: call token @llvm.coro.id
@@ -770,6 +806,14 @@
 // CHECK-DAG: declare { <8 x i32>, <8 x i1> } @llvm.usub.with.overflow.v8i32(<8 x i32>, <8 x i32>) #0
 // CHECK-DAG: declare { i32, i1 } @llvm.umul.with.overflow.i32(i32, i32)
 // CHECK-DAG: declare { <8 x i32>, <8 x i1> } @llvm.umul.with.overflow.v8i32(<8 x i32>, <8 x i32>) #0
+// CHECK-DAG: declare i32 @llvm.sadd.sat.i32(i32, i32) #0
+// CHECK-DAG: declare <8 x i32> @llvm.sadd.sat.v8i32(<8 x i32>, <8 x i32>) #0
+// CHECK-DAG: declare i32 @llvm.uadd.sat.i32(i32, i32) #0
+// CHECK-DAG: declare <8 x i32> @llvm.uadd.sat.v8i32(<8 x i32>, <8 x i32>) #0
+// CHECK-DAG: declare i32 @llvm.ssub.sat.i32(i32, i32) #0
+// CHECK-DAG: declare <8 x i32> @llvm.ssub.sat.v8i32(<8 x i32>, <8 x i32>) #0
+// CHECK-DAG: declare i32 @llvm.usub.sat.i32(i32, i32) #0
+// CHECK-DAG: declare <8 x i32> @llvm.usub.sat.v8i32(<8 x i32>, <8 x i32>) #0
 // CHECK-DAG: declare token @llvm.coro.id(i32, ptr readnone, ptr nocapture readonly, ptr)
 // CHECK-DAG: declare ptr @llvm.coro.begin(token, ptr writeonly)
 // CHECK-DAG: declare i64 @llvm.coro.size.i64()
Index: mlir/test/Target/LLVMIR/Import/intrinsic.ll
===
--- mlir/test/Target/LLVMIR/Import/intrinsic.ll
+++ mlir/test/Target/LLVMIR/Import/intrinsic.ll
@@ -372,6 +372,42 @@
   ret void
 }

+; CHECK-LABEL:  llvm.func @sadd_sat_test
+define void @sadd_sat_test(i32 %0, i32 %1, <8 x i32> %2, <8 x i32> %3) {
+  ; CHECK: "llvm.intr.sadd.sat"(%{{.*}}, %{{.*}}) : (i32, i32) -> i32
+  %5 = call i32 @llvm.sadd.sat.i32(i32 %0, i32 %1)
+  ; CHECK: "llvm.intr.sadd.sat"(%{{.*}}, %{{.*}}) : (vector<8xi32>, vector<8xi32>) -> vector<8xi32>
+  %6 = call <8 x i32> @llvm.sadd.sat.v8i32(<8 x i32> %2, <8 x i32> %3)
+  ret void
+}
+
+; CHECK-LABEL:  llvm.func @uadd_sat_test
+define void @uadd_sat_test(i32 %0, i32 %1, <8 x i32> %2, <8 x i32> %3) {
+  ; CHECK: "llvm.intr.uadd.sat"(%{{.*}}, %{{.*}}) : (i32, i32) -> i32
+  %5 = call i32 @llvm.uadd.sat.i32(i32 %0, i32 %1)
+  ; CHECK: "llvm.intr.uadd.sat"(%{{.*}}, %{{.*}}) : (vector<8xi32>, vector<8xi32>) -> vector<8xi32>
+  %6 = call <8 x i32> @llvm.uadd.sat.v8i32(<8 x i32> %2, 

[PATCH] D134128: Resubmit an implemention for constrained template template parameters [P0857R0 Part B]

2022-10-26 Thread Liming Liu via Phabricator via cfe-commits
lime updated this revision to Diff 470739.
lime added a comment.

Solve the format issue further.


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

https://reviews.llvm.org/D134128

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Parse/ParseTemplate.cpp
  clang/lib/Sema/SemaConcept.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/test/CXX/temp/temp.arg/temp.arg.template/p3-2a.cpp
  clang/test/SemaTemplate/concepts.cpp
  clang/www/cxx_status.html
  libcxx/DELETE.ME

Index: libcxx/DELETE.ME
===
--- /dev/null
+++ libcxx/DELETE.ME
@@ -0,0 +1 @@
+D134128
Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -912,11 +912,7 @@
 

 https://wg21.link/p0857r0";>P0857R0
-
-  Partial
-Constraining template template parameters is not yet supported.
-  
-
+Clang 16
   

 https://wg21.link/p1084r2";>P1084R2
Index: clang/test/SemaTemplate/concepts.cpp
===
--- clang/test/SemaTemplate/concepts.cpp
+++ clang/test/SemaTemplate/concepts.cpp
@@ -61,9 +61,9 @@
 
   // FIXME: This is valid under P0857R0.
   template concept C = true;
-  template requires C typename U> struct X {}; // expected-error {{requires 'class'}} expected-error 0+{{}}
+  template requires C typename U> struct X {};
   template requires C struct Y {};
-  X xy; // expected-error {{no template named 'X'}}
+  X xy;
 }
 
 namespace PR50306 {
Index: clang/test/CXX/temp/temp.arg/temp.arg.template/p3-2a.cpp
===
--- clang/test/CXX/temp/temp.arg/temp.arg.template/p3-2a.cpp
+++ clang/test/CXX/temp/temp.arg/temp.arg.template/p3-2a.cpp
@@ -1,22 +1,27 @@
 // RUN:  %clang_cc1 -std=c++2a -frelaxed-template-template-args -verify %s
 
-template concept C = T::f();
-// expected-note@-1{{similar constraint}}
+template concept C = T::f(); // #C
 template concept D = C && T::g();
-template concept F = T::f();
-// expected-note@-1{{similar constraint expressions not considered equivalent}}
-template class P> struct S1 { }; // expected-note 2{{'P' declared here}}
+template concept F = T::f(); // #F
+template class P> struct S1 { }; // #S1
 
 template struct X { };
 
-template struct Y { }; // expected-note{{'Y' declared here}}
+template struct Y { }; // #Y
 template struct Z { };
-template struct W { }; // expected-note{{'W' declared here}}
-
+template struct W { }; // #W
 S1 s11;
-S1 s12; // expected-error{{template template argument 'Y' is more constrained than template template parameter 'P'}}
+S1 s12;
+// expected-error@-1 {{template template argument 'Y' is more constrained than template template parameter 'P'}}
+// expected-note@#S1 {{'P' declared here}}
+// expected-note@#Y {{'Y' declared here}}
 S1 s13;
-S1 s14; // expected-error{{template template argument 'W' is more constrained than template template parameter 'P'}}
+S1 s14;
+// expected-error@-1 {{template template argument 'W' is more constrained than template template parameter 'P'}}
+// expected-note@#S1 {{'P' declared here}}
+// expected-note@#W {{'W' declared here}}
+// expected-note@#F 1-2{{similar constraint expressions not considered equivalent}}
+// expected-note@#C 1-2{{similar constraint}}
 
 template class P> struct S2 { };
 
@@ -32,3 +37,25 @@
 
 using s31 = S3;
 using s32 = S3;
+
+template requires C class P> struct S4 { }; // #S4
+
+S4 s41;
+S4 s42;
+// expected-error@-1 {{template template argument 'Y' is more constrained than template template parameter 'P'}}
+// expected-note@#S4 {{'P' declared here}}
+// expected-note@#Y {{'Y' declared here}}
+S4 s43;
+S4 s44;
+// expected-error@-1 {{template template argument 'W' is more constrained than template template parameter 'P'}}
+// expected-note@#S4 {{'P' declared here}}
+// expected-note@#W {{'W' declared here}}
+
+template requires C typename U> struct S5 {
+  template static U V;
+};
+
+struct Nothing {};
+
+// FIXME: Wait the standard to clarify the intent.
+template<> template<> Z S5::V;
Index: clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -4097,8 +4097,10 @@
 
 TemplateParameterList *
 Sema::SubstTemplateParams(TemplateParameterList *Params, DeclContext *Owner,
-  const MultiLevelTemplateArgumentList &TemplateArgs) {
+  const MultiLevelTemplateArgumentList &TemplateArgs,
+  bool EvaluateConstraints) {
   TemplateDeclInstantiator Instantiator(*this, Owner, TemplateArgs);
+  Ins

[PATCH] D126903: [clang] Add support for __builtin_memset_inline

2022-10-26 Thread Clement Courbet via Phabricator via cfe-commits
courbet added a comment.

I think there's a bug in the code though:

  // If this is memset, we just need to see if the offset is valid in the size
// of the memset..
if (MI->getIntrinsicID() == Intrinsic::memset)

should really be:

  // If this is memset, we just need to see if the offset is valid in the size
// of the memset..
if (isa(MI))




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126903

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


[clang-tools-extra] d2135df - [clangd] Hover: Only drop UsingDecl instead of BaseUsingDecl

2022-10-26 Thread Tom Praschan via cfe-commits

Author: Tom Praschan
Date: 2022-10-26T12:51:36+02:00
New Revision: d2135df4b5fb7eb5ca9135318adc3e20536301c0

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

LOG: [clangd] Hover: Only drop UsingDecl instead of BaseUsingDecl

Since https://reviews.llvm.org/D135506 it's sufficient to only drop UsingDecl 
here

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

Added: 


Modified: 
clang-tools-extra/clangd/Hover.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/Hover.cpp 
b/clang-tools-extra/clangd/Hover.cpp
index b587d9c5f1e76..555cefd7d07fe 100644
--- a/clang-tools-extra/clangd/Hover.cpp
+++ b/clang-tools-extra/clangd/Hover.cpp
@@ -1017,7 +1017,7 @@ const NamedDecl *pickDeclToUse(llvm::ArrayRef Candidates) {
   // which isn't really useful for Hover. So use the other one,
   // which in this example would be the actual declaration of foo.
   if (Candidates.size() <= 2) {
-if (llvm::isa(Candidates.front()))
+if (llvm::isa(Candidates.front()))
   return Candidates.back();
 return Candidates.front();
   }
@@ -1029,7 +1029,7 @@ const NamedDecl *pickDeclToUse(llvm::ArrayRef Candidates) {
   // we actually want to show the using declaration,
   // it's not clear which declaration to pick otherwise.
   auto BaseDecls = llvm::make_filter_range(Candidates, [](const NamedDecl *D) {
-return llvm::isa(D);
+return llvm::isa(D);
   });
   if (std::distance(BaseDecls.begin(), BaseDecls.end()) == 1)
 return *BaseDecls.begin();



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


[PATCH] D135536: [clangd] Hover: Only drop UsingDecl instead of BaseUsingDecl

2022-10-26 Thread Tom Praschan 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 rGd2135df4b5fb: [clangd] Hover: Only drop UsingDecl instead of 
BaseUsingDecl (authored by tom-anders).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135536

Files:
  clang-tools-extra/clangd/Hover.cpp


Index: clang-tools-extra/clangd/Hover.cpp
===
--- clang-tools-extra/clangd/Hover.cpp
+++ clang-tools-extra/clangd/Hover.cpp
@@ -1017,7 +1017,7 @@
   // which isn't really useful for Hover. So use the other one,
   // which in this example would be the actual declaration of foo.
   if (Candidates.size() <= 2) {
-if (llvm::isa(Candidates.front()))
+if (llvm::isa(Candidates.front()))
   return Candidates.back();
 return Candidates.front();
   }
@@ -1029,7 +1029,7 @@
   // we actually want to show the using declaration,
   // it's not clear which declaration to pick otherwise.
   auto BaseDecls = llvm::make_filter_range(Candidates, [](const NamedDecl *D) {
-return llvm::isa(D);
+return llvm::isa(D);
   });
   if (std::distance(BaseDecls.begin(), BaseDecls.end()) == 1)
 return *BaseDecls.begin();


Index: clang-tools-extra/clangd/Hover.cpp
===
--- clang-tools-extra/clangd/Hover.cpp
+++ clang-tools-extra/clangd/Hover.cpp
@@ -1017,7 +1017,7 @@
   // which isn't really useful for Hover. So use the other one,
   // which in this example would be the actual declaration of foo.
   if (Candidates.size() <= 2) {
-if (llvm::isa(Candidates.front()))
+if (llvm::isa(Candidates.front()))
   return Candidates.back();
 return Candidates.front();
   }
@@ -1029,7 +1029,7 @@
   // we actually want to show the using declaration,
   // it's not clear which declaration to pick otherwise.
   auto BaseDecls = llvm::make_filter_range(Candidates, [](const NamedDecl *D) {
-return llvm::isa(D);
+return llvm::isa(D);
   });
   if (std::distance(BaseDecls.begin(), BaseDecls.end()) == 1)
 return *BaseDecls.begin();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D136746: [mlir] Saturation arithmetic intrinsics

2022-10-26 Thread Tobias Gysi via Phabricator via cfe-commits
gysit added inline comments.



Comment at: mlir/include/mlir/Dialect/LLVMIR/LLVMIntrinsicOps.td:150-153
 }

+// Saturation Arithmetic Intrinsics.
+
+def LLVM_SAddSat

nit: There are quite a lot of changes in the diff for things that seemingly did 
not change (e.g. the overflow ops or the memove memset tests). Could it be your 
editor inserts tabs instead of spaces?



Comment at: mlir/include/mlir/Dialect/LLVMIR/LLVMIntrinsicOps.td:173
 //
 // Coroutine intrinsics.
 //

Nice! 

I have just landed a revision that makes the type constraints for llvm 
intrinsics more precise (https://reviews.llvm.org/D136360). Can you update your 
newly added intrinsics to have more accurate type constraints as well (e.g. 
AnySignlessInteger instead of just LLVM_Type)? I think they may be best defined 
by deriving from LLVM_BinarySameArgsIntrOpI since they take two arguments and 
return one result of the same type if I am not mistaken:

```
def LLVM_SMaxOp : LLVM_BinarySameArgsIntrOpI<"sadd.sat">;
def LLVM_SMaxOp : LLVM_BinarySameArgsIntrOpI<"ssub.sat">;
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136746

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


[PATCH] D134128: Resubmit an implemention for constrained template template parameters [P0857R0 Part B]

2022-10-26 Thread Liming Liu via Phabricator via cfe-commits
lime updated this revision to Diff 470746.
lime added a comment.

Solve the conflicts.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134128

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Parse/ParseTemplate.cpp
  clang/lib/Sema/SemaConcept.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/test/CXX/temp/temp.arg/temp.arg.template/p3-2a.cpp
  clang/test/SemaTemplate/concepts.cpp
  clang/www/cxx_status.html
  libcxx/DELETE.ME

Index: libcxx/DELETE.ME
===
--- /dev/null
+++ libcxx/DELETE.ME
@@ -0,0 +1 @@
+D134128
Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -912,11 +912,7 @@
 

 https://wg21.link/p0857r0";>P0857R0
-
-  Partial
-Constraining template template parameters is not yet supported.
-  
-
+Clang 16
   

 https://wg21.link/p1084r2";>P1084R2
Index: clang/test/SemaTemplate/concepts.cpp
===
--- clang/test/SemaTemplate/concepts.cpp
+++ clang/test/SemaTemplate/concepts.cpp
@@ -61,9 +61,9 @@
 
   // FIXME: This is valid under P0857R0.
   template concept C = true;
-  template requires C typename U> struct X {}; // expected-error {{requires 'class'}} expected-error 0+{{}}
+  template requires C typename U> struct X {};
   template requires C struct Y {};
-  X xy; // expected-error {{no template named 'X'}}
+  X xy;
 }
 
 namespace PR50306 {
Index: clang/test/CXX/temp/temp.arg/temp.arg.template/p3-2a.cpp
===
--- clang/test/CXX/temp/temp.arg/temp.arg.template/p3-2a.cpp
+++ clang/test/CXX/temp/temp.arg/temp.arg.template/p3-2a.cpp
@@ -1,22 +1,27 @@
 // RUN:  %clang_cc1 -std=c++2a -frelaxed-template-template-args -verify %s
 
-template concept C = T::f();
-// expected-note@-1{{similar constraint}}
+template concept C = T::f(); // #C
 template concept D = C && T::g();
-template concept F = T::f();
-// expected-note@-1{{similar constraint expressions not considered equivalent}}
-template class P> struct S1 { }; // expected-note 2{{'P' declared here}}
+template concept F = T::f(); // #F
+template class P> struct S1 { }; // #S1
 
 template struct X { };
 
-template struct Y { }; // expected-note{{'Y' declared here}}
+template struct Y { }; // #Y
 template struct Z { };
-template struct W { }; // expected-note{{'W' declared here}}
-
+template struct W { }; // #W
 S1 s11;
-S1 s12; // expected-error{{template template argument 'Y' is more constrained than template template parameter 'P'}}
+S1 s12;
+// expected-error@-1 {{template template argument 'Y' is more constrained than template template parameter 'P'}}
+// expected-note@#S1 {{'P' declared here}}
+// expected-note@#Y {{'Y' declared here}}
 S1 s13;
-S1 s14; // expected-error{{template template argument 'W' is more constrained than template template parameter 'P'}}
+S1 s14;
+// expected-error@-1 {{template template argument 'W' is more constrained than template template parameter 'P'}}
+// expected-note@#S1 {{'P' declared here}}
+// expected-note@#W {{'W' declared here}}
+// expected-note@#F 1-2{{similar constraint expressions not considered equivalent}}
+// expected-note@#C 1-2{{similar constraint}}
 
 template class P> struct S2 { };
 
@@ -32,3 +37,25 @@
 
 using s31 = S3;
 using s32 = S3;
+
+template requires C class P> struct S4 { }; // #S4
+
+S4 s41;
+S4 s42;
+// expected-error@-1 {{template template argument 'Y' is more constrained than template template parameter 'P'}}
+// expected-note@#S4 {{'P' declared here}}
+// expected-note@#Y {{'Y' declared here}}
+S4 s43;
+S4 s44;
+// expected-error@-1 {{template template argument 'W' is more constrained than template template parameter 'P'}}
+// expected-note@#S4 {{'P' declared here}}
+// expected-note@#W {{'W' declared here}}
+
+template requires C typename U> struct S5 {
+  template static U V;
+};
+
+struct Nothing {};
+
+// FIXME: Wait the standard to clarify the intent.
+template<> template<> Z S5::V;
Index: clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -4098,8 +4098,10 @@
 
 TemplateParameterList *
 Sema::SubstTemplateParams(TemplateParameterList *Params, DeclContext *Owner,
-  const MultiLevelTemplateArgumentList &TemplateArgs) {
+  const MultiLevelTemplateArgumentList &TemplateArgs,
+  bool EvaluateConstraints) {
   TemplateDeclInstantiator Instantiator(*this, 

[PATCH] D126903: [clang] Add support for __builtin_memset_inline

2022-10-26 Thread Guillaume Chatelet via Phabricator via cfe-commits
gchatelet added a comment.

In D126903#3884873 , @courbet wrote:

> I think there's a bug in the code though:
>
>   // If this is memset, we just need to see if the offset is valid in the size
> // of the memset..
> if (MI->getIntrinsicID() == Intrinsic::memset)
>
> should really be:
>
>   // If this is memset, we just need to see if the offset is valid in the size
> // of the memset..
> if (isa(MI))

Yes this seems a likely culprit 
.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126903

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


[PATCH] D133874: [clang] Changes to produce sugared converted template arguments

2022-10-26 Thread Mike Hommey via Phabricator via cfe-commits
glandium added a comment.

I'm running it through creduce (as well as the one for D136564 
. It's going to take a little while. Thank 
you for the revert.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133874

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


[PATCH] D133698: [clang][dataflow] Implement transferBranch

2022-10-26 Thread Gabor Marton via Phabricator via cfe-commits
martong marked 9 inline comments as done.
martong added a comment.

Thanks for the assiduous review @ymandel !




Comment at: 
clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp:78-79
 public:
-  TerminatorVisitor(const StmtToEnvMap &StmtToEnv, Environment &Env,
+  // The return type of the visit functions.
+  using RetTy = std::pair;
+  TerminatorVisitor(TypeErasedDataflowAnalysis &Analysis,

ymandel wrote:
> please lift this out and define it as a struct. then, refer to it by name on 
> line 76.  that will improve the readability of the code and provide a way to 
> document explicitly the role of the two fields.
Ok, I hoisted this to be `TerminatorVisitorRetTy`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133698

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


[PATCH] D133698: [clang][dataflow] Implement transferBranch

2022-10-26 Thread Gabor Marton via Phabricator via cfe-commits
martong updated this revision to Diff 470748.
martong marked an inline comment as done.
martong added a comment.

- Address ymandel's comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133698

Files:
  clang/include/clang/Analysis/FlowSensitive/DataflowAnalysis.h
  clang/include/clang/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.h
  clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
  clang/unittests/Analysis/FlowSensitive/CMakeLists.txt
  clang/unittests/Analysis/FlowSensitive/TestingSupport.h
  clang/unittests/Analysis/FlowSensitive/TransferBranchTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/TransferBranchTest.cpp
===
--- /dev/null
+++ clang/unittests/Analysis/FlowSensitive/TransferBranchTest.cpp
@@ -0,0 +1,114 @@
+//===- unittests/Analysis/FlowSensitive/SignAnalysisTest.cpp --===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+//  This file defines a test for the transferBranch function of the
+//  TypeErasedDataflowAnalysis.
+//
+//===--===//
+
+#include "TestingSupport.h"
+#include "clang/Analysis/FlowSensitive/DataflowAnalysis.h"
+#include "clang/Tooling/Tooling.h"
+#include "llvm/ADT/Optional.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Testing/Support/Annotations.h"
+#include "llvm/Testing/Support/Error.h"
+#include "gtest/gtest.h"
+
+namespace clang::dataflow::test {
+namespace {
+
+using namespace ast_matchers;
+
+struct TestLattice {
+  llvm::Optional Branch;
+  static TestLattice bottom() { return {}; }
+
+  // Does not matter for this test, but we must provide some definition of join.
+  LatticeJoinEffect join(const TestLattice &Other) {
+return LatticeJoinEffect::Unchanged;
+  }
+  friend bool operator==(const TestLattice &Lhs, const TestLattice &Rhs) {
+return Lhs.Branch == Rhs.Branch;
+  }
+};
+
+class TestPropagationAnalysis
+: public DataflowAnalysis {
+public:
+  explicit TestPropagationAnalysis(ASTContext &Context)
+  : DataflowAnalysis(Context) {}
+  static TestLattice initialElement() { return TestLattice::bottom(); }
+  void transfer(const CFGElement *, TestLattice &, Environment &) {}
+  void transferBranch(bool Branch, const Stmt *S, TestLattice &L,
+  Environment &Env) {
+L.Branch = Branch;
+  }
+};
+
+using ::testing::UnorderedElementsAre;
+
+template 
+void runDataflow(llvm::StringRef Code, Matcher Match,
+ LangStandard::Kind Std = LangStandard::lang_cxx17,
+ llvm::StringRef TargetFun = "fun") {
+  using ast_matchers::hasName;
+  ASSERT_THAT_ERROR(
+  checkDataflow(
+  AnalysisInputs(
+  Code, hasName(TargetFun),
+  [](ASTContext &C, Environment &) {
+return TestPropagationAnalysis(C);
+  })
+  .withASTBuildArgs(
+  {"-fsyntax-only", "-fno-delayed-template-parsing",
+   "-std=" +
+   std::string(LangStandard::getLangStandardForKind(Std)
+   .getName())}),
+  /*VerifyResults=*/Match),
+  llvm::Succeeded());
+}
+
+template 
+const LatticeT &getLatticeAtAnnotation(
+const llvm::StringMap> &AnnotationStates,
+llvm::StringRef Annotation) {
+  auto It = AnnotationStates.find(Annotation);
+  assert(It != AnnotationStates.end());
+  return It->getValue().Lattice;
+}
+
+TEST(TransferBranchTest, IfElse) {
+  std::string Code = R"(
+void fun(int a) {
+  if (a > 0) {
+(void)1;
+// [[p]]
+  } else {
+(void)0;
+// [[q]]
+  }
+}
+  )";
+  runDataflow(
+  Code,
+  [](const llvm::StringMap> &Results,
+ const AnalysisOutputs &) {
+ASSERT_THAT(Results.keys(), UnorderedElementsAre("p", "q"));
+
+const TestLattice &LP = getLatticeAtAnnotation(Results, "p");
+EXPECT_THAT(LP.Branch, Optional(true));
+
+const TestLattice &LQ = getLatticeAtAnnotation(Results, "q");
+EXPECT_THAT(LQ.Branch, Optional(false));
+  },
+  LangStandard::lang_cxx17);
+}
+
+} // namespace
+} // namespace clang::dataflow::test
Index: clang/unittests/Analysis/FlowSensitive/TestingSupport.h
===
--- clang/unittests/Analysis/FlowSensitive/TestingSupport.h
+++ clang/unittests/Analysis/FlowSensitive/TestingSupport.h
@@ -344,6 +344,7 @@
 llvm::any_cast(&State.Lattice.Value);
 auto [_, InsertSuccess] =
 AnnotationStates.insert({It->second, StateT{*Lattice, State.Env}});
+(void)_;
 

[PATCH] D133874: [clang] Changes to produce sugared converted template arguments

2022-10-26 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added a comment.

In D133874#3884904 , @glandium wrote:

> I'm running it through creduce (as well as the one for D136564 
> . It's going to take a little while. Thank 
> you for the revert.

That's very helpful, thank you!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133874

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


[PATCH] D136694: [clang][Interp] Check that constructor calls initialize all record fields

2022-10-26 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 470750.

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

https://reviews.llvm.org/D136694

Files:
  clang/lib/AST/Interp/Descriptor.cpp
  clang/lib/AST/Interp/Interp.cpp
  clang/lib/AST/Interp/Interp.h
  clang/lib/AST/Interp/InterpFrame.cpp
  clang/test/AST/Interp/cxx20.cpp
  clang/test/AST/Interp/records.cpp

Index: clang/test/AST/Interp/records.cpp
===
--- clang/test/AST/Interp/records.cpp
+++ clang/test/AST/Interp/records.cpp
@@ -279,7 +279,9 @@
// ref-note {{declared here}} \
// expected-error {{must be initialized by a constant expression}}
   static_assert(D.Val == 0, ""); // ref-error {{not an integral constant expression}} \
- // ref-note {{initializer of 'D' is not a constant expression}}
+ // ref-note {{initializer of 'D' is not a constant expression}} \
+ // expected-error {{not an integral constant expression}} \
+ // expected-note {{read of object outside its lifetime}}
 
   struct AnotherBase {
 int Val;
Index: clang/test/AST/Interp/cxx20.cpp
===
--- clang/test/AST/Interp/cxx20.cpp
+++ clang/test/AST/Interp/cxx20.cpp
@@ -80,3 +80,36 @@
 }
 static_assert(f());
 #endif
+
+
+namespace UninitializedFields {
+  class A {
+  public:
+int a; // expected-note {{subobject declared here}} \
+   // ref-note {{subobject declared here}}
+constexpr A() {}
+  };
+  constexpr A a; // expected-error {{must be initialized by a constant expression}} \
+ // expected-note {{subobject of type 'int' is not initialized}} \
+ // ref-error {{must be initialized by a constant expression}} \
+ // ref-note {{subobject of type 'int' is not initialized}}
+
+
+  class Base {
+  public:
+bool b;
+int a; // expected-note {{subobject declared here}} \
+   // ref-note {{subobject declared here}}
+constexpr Base() : b(true) {}
+  };
+
+  class Derived : public Base {
+  public:
+constexpr Derived() : Base() {} // expected-note {{subobject of type 'int' is not initialized}}
+  };
+
+constexpr Derived D; // expected-error {{must be initialized by a constant expression}} \\
+ // expected-note {{in call to 'Derived()'}} \
+ // ref-error {{must be initialized by a constant expression}} \
+ // ref-note {{subobject of type 'int' is not initialized}}
+};
Index: clang/lib/AST/Interp/InterpFrame.cpp
===
--- clang/lib/AST/Interp/InterpFrame.cpp
+++ clang/lib/AST/Interp/InterpFrame.cpp
@@ -61,8 +61,6 @@
 }
 
 InterpFrame::~InterpFrame() {
-  if (Func && Func->isConstructor() && This.isBaseClass())
-This.initialize();
   for (auto &Param : Params)
 S.deallocate(reinterpret_cast(Param.second.get()));
 }
Index: clang/lib/AST/Interp/Interp.h
===
--- clang/lib/AST/Interp/Interp.h
+++ clang/lib/AST/Interp/Interp.h
@@ -96,6 +96,9 @@
 bool CheckFloatResult(InterpState &S, CodePtr OpPC, APFloat::opStatus Status,
   const Floating &Result);
 
+/// Checks that all fields are initialized after a constructor call.
+bool CheckCtorCall(InterpState &S, CodePtr OpPC, const Pointer &This);
+
 /// Checks if Div/Rem operation on LHS and RHS is valid.
 template 
 bool CheckDivRem(InterpState &S, CodePtr OpPC, const T &LHS, const T &RHS) {
@@ -1338,7 +1341,9 @@
 
 inline bool Call(InterpState &S, CodePtr &PC, const Function *Func) {
   auto NewFrame = std::make_unique(S, Func, PC);
+  Pointer ThisPtr;
   if (Func->hasThisPointer()) {
+ThisPtr = NewFrame->getThis();
 if (!CheckInvoke(S, PC, NewFrame->getThis())) {
   return false;
 }
@@ -1355,6 +1360,13 @@
   if (Interpret(S, CallResult)) {
 NewFrame.release(); // Frame was delete'd already.
 assert(S.Current == FrameBefore);
+
+// For constructors, check that all fields have been initialized.
+if (Func->isConstructor()) {
+  if (!CheckCtorCall(S, PC, ThisPtr))
+return false;
+}
+
 return true;
   }
 
Index: clang/lib/AST/Interp/Interp.cpp
===
--- clang/lib/AST/Interp/Interp.cpp
+++ clang/lib/AST/Interp/Interp.cpp
@@ -435,6 +435,38 @@
   return true;
 }
 
+static bool CheckFieldsInitialized(InterpState &S, CodePtr OpPC,
+   const Pointer &BasePtr, const Record *R) {
+  assert(R);
+  bool Result = true;
+  // Check all fields of this record are initialized.
+  for (const Record::Field &F : R->fields()) {
+Pointer FieldPtr = BasePtr.atField(F.Offset);
+QualType FieldType = FieldPtr.getType();
+
+  

[PATCH] D129531: [clang][C++20] P0960R3: Allow initializing aggregates from a parenthesized list of values

2022-10-26 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added inline comments.



Comment at: clang/lib/Serialization/ASTReaderStmt.cpp:2179
+  for (unsigned I = 0; I < E->NumExprs; I++)
+E->getTrailingObjects()[I] = Record.readSubExpr();
+}

ayzhao wrote:
> ilya-biryukov wrote:
> > FYI: I think this is where the crash comes from.
> > We should allocate the trailing objects first.
> > E.g. see how `PragmaCommentDecl::CreateDeserialized` does this.
> This sounds like it could be the solution - thanks for looking at it!
> 
> Currently, I'm working on the refactor that shafik@ suggested, which was to 
> inherit from `InitListExpr`. Hopefully, that refactor will fix this issue as 
> `InitListExpr` stores it's subexpressions in a class member instead of using 
> `llvm::TrailingObjects`.
Are we trying to share code between two implementations? If so, I suggest to 
consider alternatives, e.g. creating a new base class and inheriting both 
`InitListExpr` and `CXXParentInitListExpr` to share the common code.

Inheriting `CXXParentInitListExpr` from `InitListExpr` breaks [Liskov 
substitution 
principle](https://en.wikipedia.org/wiki/Liskov_substitution_principle) and 
will likely to lead to bugs that are hard to chase.  `InitListExpr` is widely 
used and means`{}`. `CXXParenInitListExpr` is not `{}` and we do not know in 
advance which code is going to work for both and which code is only valid for 
`{}`. Reviewing all callsites that use `InitListExpr` does not seem plausible. 
Note that in addition to Clang, there are also uses in ast-matchers and in 
clang-tidy checks (quite a few of those are downstream).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129531

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


[PATCH] D136723: [include-cleaner] Record main-file macro occurences and includes

2022-10-26 Thread Haojian Wu via Phabricator via cfe-commits
hokein added a comment.

Left a few initial comments, it looks roughly good to me (for the macro-usage 
case, I might miss some historical context there, I think we come to an 
agreement that what this patch proposes is the designed behavior).




Comment at: 
clang-tools-extra/include-cleaner/include/clang-include-cleaner/Record.h:75
+//  - for a logical file like , we check Spelled
+llvm::SmallVector match(Header H) const;
+

sammccall wrote:
> in the prototype I reimplemented this function in clangd, but I expect we can 
> just reuse the RecordedIncludes class instead, copying from clangd's includes 
> list is cheap.
> 
> (That's one argument for putting this in a different header, which I can do 
> already if you prefer)
that's an interesting idea, but we need to do it carefully because of 
`FileEntry*`, the `Include` structure has a filed of `FileEntry*`, it is not 
feasible for clangd to propagate it (clangd's `Inclusion` doesn't have it, 
instead it uses a `HeaderID` which is based on the `fs::UniqueID` to identify a 
physical file).

But I think this is not something we should worry about at the moment, and the 
current interfaces look quite good.



Comment at: 
clang-tools-extra/include-cleaner/include/clang-include-cleaner/Record.h:79
+std::vector All;
+llvm::StringMap> BySpelling;
+llvm::DenseMap> ByFile;

nit: worth a comment mentioning the unsigned is the index of `All`.



Comment at: 
clang-tools-extra/include-cleaner/include/clang-include-cleaner/Types.h:118
+  const FileEntry *Resolved = nullptr; // e.g. /path/to/c++/v1/vector
+  SourceLocation Location; // of hash in #include 
+  unsigned Line = 0;   // 1-based line number for #include

nit: HashLoc seems clearer than `Location`.

And it looks like `Location` and `Line` feels somewhat redundant -- we can get 
the Line loc from the `Location` with `SourceManager`. But I think it is fair 
to hold both, Line is an important property of the include, which will probably 
widely used.



Comment at: clang-tools-extra/include-cleaner/unittests/RecordTest.cpp:159
+#define Y X
+int one = x;
+  )cpp");

why using a lower case `x` here?



Comment at: clang-tools-extra/include-cleaner/unittests/RecordTest.cpp:167
+
+int one = ^X;
+int uno = $exp^LATE; // a ref in LATE's expansion

this is a redef error with the one defined in the header, I think it is not 
intended, rename it?



Comment at: clang-tools-extra/include-cleaner/unittests/RecordTest.cpp:180
+  Inputs.ExtraFiles["header.h"] = Header.code();
+  Inputs.ErrorOK = true; // missing header
+  auto AST = build();

IIUC, ErrorOK is irrelevant, and should be removed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136723

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


[clang] aa12a48 - [analyzer] Fix assertion failure with conflicting prototype calls

2022-10-26 Thread Balazs Benics via cfe-commits

Author: Balazs Benics
Date: 2022-10-26T11:27:01+02:00
New Revision: aa12a48c8223aafafa45fb1e6e9ea49dc18a62d2

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

LOG: [analyzer] Fix assertion failure with conflicting prototype calls

It turns out we can reach the `Init.castAs()`
expression with other kinds of SVals. Such as by `nonloc::ConcreteInt`
in this example: https://godbolt.org/z/s4fdxrcs9

```lang=C++
int buffer[10];
void b();
void top() {
  b(&buffer);
}
void b(int *c) {
  *c = 42; // would crash
}
```
In this example, we try to store `42` to the `Elem{buffer, 0}`.

This situation can appear if the CallExpr refers to a function
declaration without prototype. In such cases, the engine will pick the
redecl of the referred function decl which has function body, hence has
a function prototype.

This weird situation will have an interesting effect to the AST, such as
the argument at the callsite will miss a cast, which would cast the
`int (*)[10]` expression into `int *`, which means that when we evaluate
the `*c = 42` expression, we want to bind `42` to an array, causing the
crash.

Look at the AST of the callsite with and without the function prototype:
https://godbolt.org/z/Gncebcbdb
The only difference is that without the proper function prototype, we
will not have the `ImplicitCastExpr` `BitCasting` from `int (*)[10]`
to `int *` to match the expected type of the parameter declaration.

In this patch, I'm proposing to emit a cast in the mentioned edge-case,
to bind the argument value of the expected type to the parameter.

I'm only proposing this if the runtime definition has exactly the same
number of parameters as the callsite feeds it by arguments.
If that's not the case, I believe, we are better off by binding `Unknown`
to those parameters.

Reviewed By: martong

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

Added: 


Modified: 
clang/lib/StaticAnalyzer/Core/CallEvent.cpp
clang/test/Analysis/region-store.c

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Core/CallEvent.cpp 
b/clang/lib/StaticAnalyzer/Core/CallEvent.cpp
index a8b49adfb4c9a..94ab3245e47b5 100644
--- a/clang/lib/StaticAnalyzer/Core/CallEvent.cpp
+++ b/clang/lib/StaticAnalyzer/Core/CallEvent.cpp
@@ -424,6 +424,38 @@ static SVal processArgument(SVal Value, const Expr 
*ArgumentExpr,
   return Value;
 }
 
+/// Cast the argument value to the type of the parameter at the function
+/// declaration.
+/// Returns the argument value if it didn't need a cast.
+/// Or returns the cast argument if it needed a cast.
+/// Or returns 'Unknown' if it would need a cast but the callsite and the
+/// runtime definition don't match in terms of argument and parameter count.
+static SVal castArgToParamTypeIfNeeded(const CallEvent &Call, unsigned ArgIdx,
+   SVal ArgVal, SValBuilder &SVB) {
+  const FunctionDecl *RTDecl =
+  Call.getRuntimeDefinition().getDecl()->getAsFunction();
+  const auto *CallExprDecl = dyn_cast_or_null(Call.getDecl());
+
+  if (!RTDecl || !CallExprDecl)
+return ArgVal;
+
+  // The function decl of the Call (in the AST) will not have any parameter
+  // declarations, if it was 'only' declared without a prototype. However, the
+  // engine will find the appropriate runtime definition - basically a
+  // redeclaration, which has a function body (and a function prototype).
+  if (CallExprDecl->hasPrototype() || !RTDecl->hasPrototype())
+return ArgVal;
+
+  // Only do this cast if the number arguments at the callsite matches with
+  // the parameters at the runtime definition.
+  if (Call.getNumArgs() != RTDecl->getNumParams())
+return UnknownVal();
+
+  const Expr *ArgExpr = Call.getArgExpr(ArgIdx);
+  const ParmVarDecl *Param = RTDecl->getParamDecl(ArgIdx);
+  return SVB.evalCast(ArgVal, Param->getType(), ArgExpr->getType());
+}
+
 static void addParameterValuesToBindings(const StackFrameContext *CalleeCtx,
  CallEvent::BindingsTy &Bindings,
  SValBuilder &SVB,
@@ -449,12 +481,18 @@ static void addParameterValuesToBindings(const 
StackFrameContext *CalleeCtx,
 // which makes getArgSVal() fail and return UnknownVal.
 SVal ArgVal = Call.getArgSVal(Idx);
 const Expr *ArgExpr = Call.getArgExpr(Idx);
-if (!ArgVal.isUnknown()) {
-  Loc ParamLoc = SVB.makeLoc(
-  MRMgr.getParamVarRegion(Call.getOriginExpr(), Idx, CalleeCtx));
-  Bindings.push_back(
-  std::make_pair(ParamLoc, processArgument(ArgVal, ArgExpr, *I, SVB)));
-}
+
+if (ArgVal.isUnknown())
+  continue;
+
+// Cast the argument value to match the type of the parameter in some
+// edge-cases.
+ArgVal = castArgToParamTypeIfNeeded(Call, Idx, ArgVa

[PATCH] D136162: [analyzer] Fix assertion failure with conflicting prototype calls

2022-10-26 Thread Balázs Benics via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGaa12a48c8223: [analyzer] Fix assertion failure with 
conflicting prototype calls (authored by steakhal).

Changed prior to commit:
  https://reviews.llvm.org/D136162?vs=469234&id=470756#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136162

Files:
  clang/lib/StaticAnalyzer/Core/CallEvent.cpp
  clang/test/Analysis/region-store.c

Index: clang/test/Analysis/region-store.c
===
--- clang/test/Analysis/region-store.c
+++ clang/test/Analysis/region-store.c
@@ -1,7 +1,12 @@
-// RUN: %clang_analyze_cc1 -analyzer-checker=core,unix,debug.ExprInspection -verify -analyzer-config eagerly-assume=false %s
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,unix,debug.ExprInspection \
+// RUN:-verify -analyzer-config eagerly-assume=false -std=c99 %s \
+// RUN:-Wno-implicit-function-declaration
 
 int printf(const char *restrict,...);
 
+void clang_analyzer_eval(int);
+void clang_analyzer_dump(int*);
+
 // Testing core functionality of the region store.
 // radar://10127782
 int compoundLiteralTest(void) {
@@ -39,7 +44,6 @@
   return l.mem; // no-warning
 }
 
-void clang_analyzer_eval(int);
 void testConstraintOnRegionOffset(int *values, int length, int i){
   if (values[1] == 4) {
 values[i] = 5;
@@ -54,3 +58,24 @@
 clang_analyzer_eval(values[0] == 4);// expected-warning {{UNKNOWN}}
   }
 }
+
+int buffer[10];
+void b(); // expected-warning {{a function declaration without a prototype is deprecated in all versions of C and is treated as a zero-parameter prototype in C2x, conflicting with a subsequent definition}}
+void missingPrototypeCallsiteMatchingArgsAndParams() {
+  // expected-warning@+1 {{passing arguments to 'b' without a prototype is deprecated in all versions of C and is not supported in C2x}}
+  b(&buffer);
+}
+void b(int *c) { // expected-note {{conflicting prototype is here}}
+  clang_analyzer_dump(c); // expected-warning {{&Element{buffer,0 S64b,int}}}
+  *c = 42; // no-crash
+}
+
+void c(); // expected-warning {{a function declaration without a prototype is deprecated in all versions of C and is treated as a zero-parameter prototype in C2x, conflicting with a subsequent definition}}
+void missingPrototypeCallsiteMismatchingArgsAndParams() {
+  // expected-warning@+1 {{passing arguments to 'c' without a prototype is deprecated in all versions of C and is not supported in C2x}}
+  c(&buffer, &buffer);
+}
+void c(int *c) { // expected-note {{conflicting prototype is here}}
+  clang_analyzer_dump(c); // expected-warning {{Unknown}}
+  *c = 42; // no-crash
+}
Index: clang/lib/StaticAnalyzer/Core/CallEvent.cpp
===
--- clang/lib/StaticAnalyzer/Core/CallEvent.cpp
+++ clang/lib/StaticAnalyzer/Core/CallEvent.cpp
@@ -424,6 +424,38 @@
   return Value;
 }
 
+/// Cast the argument value to the type of the parameter at the function
+/// declaration.
+/// Returns the argument value if it didn't need a cast.
+/// Or returns the cast argument if it needed a cast.
+/// Or returns 'Unknown' if it would need a cast but the callsite and the
+/// runtime definition don't match in terms of argument and parameter count.
+static SVal castArgToParamTypeIfNeeded(const CallEvent &Call, unsigned ArgIdx,
+   SVal ArgVal, SValBuilder &SVB) {
+  const FunctionDecl *RTDecl =
+  Call.getRuntimeDefinition().getDecl()->getAsFunction();
+  const auto *CallExprDecl = dyn_cast_or_null(Call.getDecl());
+
+  if (!RTDecl || !CallExprDecl)
+return ArgVal;
+
+  // The function decl of the Call (in the AST) will not have any parameter
+  // declarations, if it was 'only' declared without a prototype. However, the
+  // engine will find the appropriate runtime definition - basically a
+  // redeclaration, which has a function body (and a function prototype).
+  if (CallExprDecl->hasPrototype() || !RTDecl->hasPrototype())
+return ArgVal;
+
+  // Only do this cast if the number arguments at the callsite matches with
+  // the parameters at the runtime definition.
+  if (Call.getNumArgs() != RTDecl->getNumParams())
+return UnknownVal();
+
+  const Expr *ArgExpr = Call.getArgExpr(ArgIdx);
+  const ParmVarDecl *Param = RTDecl->getParamDecl(ArgIdx);
+  return SVB.evalCast(ArgVal, Param->getType(), ArgExpr->getType());
+}
+
 static void addParameterValuesToBindings(const StackFrameContext *CalleeCtx,
  CallEvent::BindingsTy &Bindings,
  SValBuilder &SVB,
@@ -449,12 +481,18 @@
 // which makes getArgSVal() fail and return UnknownVal.
 SVal ArgVal = Call.getArgSVal(Idx);
 const Expr *ArgExpr = Call.getArgExpr(Idx);
-if (!ArgVal.isUnknown()) {
-  Loc ParamLoc = SVB.makeLoc(
-  MRMgr.getP

[PATCH] D136684: [clang][ASTImporter] Remove use of ParentMapContext.

2022-10-26 Thread Balázs Kéri via Phabricator via cfe-commits
balazske added a comment.

This is really a NFC-like change but not NFC because it has visible effects of 
removing some crashes. I could not produce a test that provokes the wrong case 
(when `getParents` returns an empty list). Is it enough to have no new test 
here? If we can get a test for the crash it needs more investigation to check 
if `RecursiveASTVisitor` works correct and probably a fix at other place.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136684

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


[PATCH] D136751: [clang][Interp] This pointers are writable in constructors

2022-10-26 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder created this revision.
tbaeder added reviewers: aaron.ballman, erichkeane, tahonermann, shafik.
Herald added a project: All.
tbaeder requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This is a c++20 extension as far as I know.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D136751

Files:
  clang/lib/AST/Interp/Interp.cpp
  clang/lib/AST/Interp/Pointer.h
  clang/test/AST/Interp/cxx20.cpp


Index: clang/test/AST/Interp/cxx20.cpp
===
--- clang/test/AST/Interp/cxx20.cpp
+++ clang/test/AST/Interp/cxx20.cpp
@@ -113,3 +113,20 @@
  // ref-error {{must be initialized by a constant 
expression}} \
  // ref-note {{subobject of type 'int' is not initialized}}
 };
+
+namespace ConstThis {
+  class Foo {
+const int T = 12; // expected-note {{declared const here}} \
+  // ref-note {{declared const here}}
+int a;
+  public:
+constexpr Foo() {
+  this->a = 10;
+  T = 13; // expected-error {{cannot assign to non-static data member 'T' 
with const-qualified type}} \
+  // ref-error {{cannot assign to non-static data member 'T' with 
const-qualified type}}
+}
+  };
+  constexpr Foo F; // expected-error {{must be initialized by a constant 
expression}} \
+   // ref-error {{must be initialized by a constant 
expression}}
+
+};
Index: clang/lib/AST/Interp/Pointer.h
===
--- clang/lib/AST/Interp/Pointer.h
+++ clang/lib/AST/Interp/Pointer.h
@@ -282,6 +282,8 @@
   /// Returns the number of elements.
   unsigned getNumElems() const { return getSize() / elemSize(); }
 
+  Block *block() const { return Pointee; }
+
   /// Returns the index into an array.
   int64_t getIndex() const {
 if (isElementPastEnd())
Index: clang/lib/AST/Interp/Interp.cpp
===
--- clang/lib/AST/Interp/Interp.cpp
+++ clang/lib/AST/Interp/Interp.cpp
@@ -261,6 +261,14 @@
 return true;
   }
 
+  const Function *Func = S.Current->getFunction();
+  if (Func && Func->isConstructor()) {
+// The This pointer is writable in constructors, even if
+// isConst() returns true.
+if (Ptr.block() == S.Current->getThis().block())
+  return true;
+  }
+
   const QualType Ty = Ptr.getType();
   const SourceInfo &Loc = S.Current->getSource(OpPC);
   S.FFDiag(Loc, diag::note_constexpr_modify_const_type) << Ty;


Index: clang/test/AST/Interp/cxx20.cpp
===
--- clang/test/AST/Interp/cxx20.cpp
+++ clang/test/AST/Interp/cxx20.cpp
@@ -113,3 +113,20 @@
  // ref-error {{must be initialized by a constant expression}} \
  // ref-note {{subobject of type 'int' is not initialized}}
 };
+
+namespace ConstThis {
+  class Foo {
+const int T = 12; // expected-note {{declared const here}} \
+  // ref-note {{declared const here}}
+int a;
+  public:
+constexpr Foo() {
+  this->a = 10;
+  T = 13; // expected-error {{cannot assign to non-static data member 'T' with const-qualified type}} \
+  // ref-error {{cannot assign to non-static data member 'T' with const-qualified type}}
+}
+  };
+  constexpr Foo F; // expected-error {{must be initialized by a constant expression}} \
+   // ref-error {{must be initialized by a constant expression}}
+
+};
Index: clang/lib/AST/Interp/Pointer.h
===
--- clang/lib/AST/Interp/Pointer.h
+++ clang/lib/AST/Interp/Pointer.h
@@ -282,6 +282,8 @@
   /// Returns the number of elements.
   unsigned getNumElems() const { return getSize() / elemSize(); }
 
+  Block *block() const { return Pointee; }
+
   /// Returns the index into an array.
   int64_t getIndex() const {
 if (isElementPastEnd())
Index: clang/lib/AST/Interp/Interp.cpp
===
--- clang/lib/AST/Interp/Interp.cpp
+++ clang/lib/AST/Interp/Interp.cpp
@@ -261,6 +261,14 @@
 return true;
   }
 
+  const Function *Func = S.Current->getFunction();
+  if (Func && Func->isConstructor()) {
+// The This pointer is writable in constructors, even if
+// isConst() returns true.
+if (Ptr.block() == S.Current->getThis().block())
+  return true;
+  }
+
   const QualType Ty = Ptr.getType();
   const SourceInfo &Loc = S.Current->getSource(OpPC);
   S.FFDiag(Loc, diag::note_constexpr_modify_const_type) << Ty;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D134637: clang-tblgen build: avoid duplicate inclusion of libLLVMSupport

2022-10-26 Thread Nicolai Hähnle via Phabricator via cfe-commits
nhaehnle added a comment.

Ping^2 after ~a week.

The previous discussion seemed quite favorable, so is this just a case of 
everybody being too afraid to say "Yes" because this is a dark corner that few 
people ever look at? ;)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134637

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


[PATCH] D134637: clang-tblgen build: avoid duplicate inclusion of libLLVMSupport

2022-10-26 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo accepted this revision.
mstorsjo added a comment.
This revision is now accepted and ready to land.

LGTM, this looks reasonable to me. (Although wait a little bit more if someone 
else responds to the ping this time...)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134637

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


[PATCH] D135938: [X86] Add AVX-VNNI-INT8 instructions.

2022-10-26 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon added inline comments.



Comment at: clang/include/clang/Basic/BuiltinsX86.def:2098
 
+TARGET_BUILTIN(__builtin_ia32_vpdpbssd128, "V4iV4iV4iV4i", "ncV:128:", 
"avxvnniint8")
+TARGET_BUILTIN(__builtin_ia32_vpdpbssd256, "V8iV8iV8iV8i", "ncV:256:", 
"avxvnniint8")

Add ' AVX-VNNI-INT8' title comment like we have for other intrinsic sets



Comment at: clang/include/clang/Basic/BuiltinsX86.def:2111
+TARGET_BUILTIN(__builtin_ia32_vpdpbuuds128, "V4iV4iV4iV4i", "ncV:128:", 
"avxvnniint8")
+TARGET_BUILTIN(__builtin_ia32_vpdpbuuds256, "V8iV8iV8iV8i", "ncV:256:", 
"avxvnniint8")
 TARGET_HEADER_BUILTIN(_InterlockedAnd64, "WiWiD*Wi", "nh", "intrin.h", 
ALL_MS_LANGUAGES, "")

Move these earlier with the other vnni builtins



Comment at: llvm/lib/Target/X86/X86ISelLowering.h:592
+VPDPBSSD,
+VPDPBSSDS,
+

Do we actually need these? Are you intending to add DAG combines for these?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135938

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


[PATCH] D136539: [Lex] Bring back the magic number 50 in updateConsecutiveMacroArgTokens.

2022-10-26 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 470764.
hokein added a comment.

upload the full reland version.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136539

Files:
  clang/lib/Lex/TokenLexer.cpp
  clang/test/Lexer/update_consecutive_macro_address_space.c

Index: clang/test/Lexer/update_consecutive_macro_address_space.c
===
--- /dev/null
+++ clang/test/Lexer/update_consecutive_macro_address_space.c
@@ -0,0 +1,36 @@
+// RUN: %clang -cc1 -print-stats %s 2>&1 | FileCheck %s
+// CHECK: 6 local SLocEntry's allocated
+//
+// Verify that the macro arg expansion is split to two file ids, we have 6 file
+// ids rather than 5:
+//   0: invalid file id
+//   1: main file
+//   2: builtin file
+//   3: macro expansion for X
+//   4: macro arg expansions for 1
+//   5: macro arg expansions for == 2
+#define X(x) (int)(x);
+void func() {
+  X(1
+/*/
+/*/
+/*/
+/*/
+/*/
+/*/
+/*/
+/*/
+/*/
+/*/
+/*/
+/*/
+/*/
+/*/
+/*/
+/*/
+/*/
+/*/
+/*/
+/*/
+== 2);
+}
Index: clang/lib/Lex/TokenLexer.cpp
===
--- clang/lib/Lex/TokenLexer.cpp
+++ clang/lib/Lex/TokenLexer.cpp
@@ -25,6 +25,7 @@
 #include "clang/Lex/Token.h"
 #include "clang/Lex/VariadicMacroSupport.h"
 #include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/iterator_range.h"
@@ -984,65 +985,71 @@
 /// \arg begin_tokens will be updated to a position past all the found
 /// consecutive tokens.
 static void updateConsecutiveMacroArgTokens(SourceManager &SM,
-SourceLocation InstLoc,
+SourceLocation ExpandLoc,
 Token *&begin_tokens,
 Token * end_tokens) {
-  assert(begin_tokens < end_tokens);
-
-  SourceLocation FirstLoc = begin_tokens->getLocation();
-  SourceLocation CurLoc = FirstLoc;
-
-  // Compare the source location offset of tokens and group together tokens that
-  // are close, even if their locations point to different FileIDs. e.g.
-  //
-  //  |bar|  foo | cake   |  (3 tokens from 3 consecutive FileIDs)
-  //  ^^
-  //  |bar   foo   cake| (one SLocEntry chunk for all tokens)
-  //
-  // we can perform this "merge" since the token's spelling location depends
-  // on the relative offset.
-
-  Token *NextTok = begin_tokens + 1;
-  for (; NextTok < end_tokens; ++NextTok) {
-SourceLocation NextLoc = NextTok->getLocation();
-if (CurLoc.isFileID() != NextLoc.isFileID())
-  break; // Token from different kind of FileID.
-
-SourceLocation::IntTy RelOffs;
-if (!SM.isInSameSLocAddrSpace(CurLoc, NextLoc, &RelOffs))
-  break; // Token from different local/loaded location.
-// Check that token is not before the previous token or more than 50
-// "characte

[clang] 11c1d8b - [Lex] Bring back the magic number 50 in updateConsecutiveMacroArgTokens.

2022-10-26 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2022-10-26T12:03:21+02:00
New Revision: 11c1d8b7fd82b32b37db47bcd8eac813b9667b5c

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

LOG: [Lex] Bring back the magic number 50 in updateConsecutiveMacroArgTokens.

This patch is a reland of 74e4f778cf16cbf7163b5c6de6027a43f5e9169f and
f83347b0bedb22ea676861c8e4e2ed9c31371ade with the removed 50 trick back.

The magic number 50 was removed in D134942, as a behavior change for
performance reason.

While it reduces the number of SLocEntry, it increases the usage of
SourceLocation address space usage, which is critical for compiling
large TU.

This fixes a regression caused in D134942 -- clang failed to compile one of
our internal files, complaining the file is too large to process because clang
runs out of source location space (we spend 40% more address space!)

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

Added: 
clang/test/Lexer/update_consecutive_macro_address_space.c

Modified: 
clang/lib/Lex/TokenLexer.cpp

Removed: 




diff  --git a/clang/lib/Lex/TokenLexer.cpp b/clang/lib/Lex/TokenLexer.cpp
index efda6d0046fa1..0d141c662b95f 100644
--- a/clang/lib/Lex/TokenLexer.cpp
+++ b/clang/lib/Lex/TokenLexer.cpp
@@ -25,6 +25,7 @@
 #include "clang/Lex/Token.h"
 #include "clang/Lex/VariadicMacroSupport.h"
 #include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/iterator_range.h"
@@ -984,65 +985,71 @@ TokenLexer::getExpansionLocForMacroDefLoc(SourceLocation 
loc) const {
 /// \arg begin_tokens will be updated to a position past all the found
 /// consecutive tokens.
 static void updateConsecutiveMacroArgTokens(SourceManager &SM,
-SourceLocation InstLoc,
+SourceLocation ExpandLoc,
 Token *&begin_tokens,
 Token * end_tokens) {
-  assert(begin_tokens < end_tokens);
-
-  SourceLocation FirstLoc = begin_tokens->getLocation();
-  SourceLocation CurLoc = FirstLoc;
-
-  // Compare the source location offset of tokens and group together tokens 
that
-  // are close, even if their locations point to 
diff erent FileIDs. e.g.
-  //
-  //  |bar|  foo | cake   |  (3 tokens from 3 consecutive FileIDs)
-  //  ^^
-  //  |bar   foo   cake| (one SLocEntry chunk for all tokens)
-  //
-  // we can perform this "merge" since the token's spelling location depends
-  // on the relative offset.
-
-  Token *NextTok = begin_tokens + 1;
-  for (; NextTok < end_tokens; ++NextTok) {
-SourceLocation NextLoc = NextTok->getLocation();
-if (CurLoc.isFileID() != NextLoc.isFileID())
-  break; // Token from 
diff erent kind of FileID.
-
-SourceLocation::IntTy RelOffs;
-if (!SM.isInSameSLocAddrSpace(CurLoc, NextLoc, &RelOffs))
-  break; // Token from 
diff erent local/loaded location.
-// Check that token is not before the previous token or more than 50
-// "characters" away.
-if (RelOffs < 0 || RelOffs > 50)
-  break;
-
-if (CurLoc.isMacroID() && !SM.isWrittenInSameFile(CurLoc, NextLoc))
-  break; // Token from a 
diff erent macro.
-
-CurLoc = NextLoc;
+  assert(begin_tokens + 1 < end_tokens);
+  SourceLocation BeginLoc = begin_tokens->getLocation();
+  llvm::MutableArrayRef All(begin_tokens, end_tokens);
+  llvm::MutableArrayRef Partition;
+
+  auto NearLast = [&, Last = BeginLoc](SourceLocation Loc) mutable {
+// The maximum distance between two consecutive tokens in a partition.
+// This is an important trick to avoid using too much SourceLocation 
address
+// space!
+static constexpr SourceLocation::IntTy MaxDistance = 50;
+auto Distance = Loc.getRawEncoding() - Last.getRawEncoding();
+Last = Loc;
+return Distance <= MaxDistance;
+  };
+
+  // Partition the tokens by their FileID.
+  // This is a hot function, and calling getFileID can be expensive, the
+  // implementation is optimized by reducing the number of getFileID.
+  if (BeginLoc.isFileID()) {
+// Consecutive tokens not written in macros must be from the same file.
+// (Neither #include nor eof can occur inside a macro argument.)
+Partition = All.take_while([&](const Token &T) {
+  return T.getLocation().isFileID() && NearLast(T.getLocation());
+});
+  } else {
+// Call getFileID once to calculate the bounds, and use the cheaper
+// sourcelocation-against-bounds comparison.
+FileID BeginFID = SM.getFileID(BeginLoc);
+SourceLocation Limit =
+SM.getComposedLoc(BeginFID, SM.getFileIDSize(BeginFID));
+Partition = All.take_while([&](const Token &T) {
+ 

[PATCH] D136539: [Lex] Bring back the magic number 50 in updateConsecutiveMacroArgTokens.

2022-10-26 Thread Haojian Wu via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG11c1d8b7fd82: [Lex] Bring back the magic number 50 in 
updateConsecutiveMacroArgTokens. (authored by hokein).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136539

Files:
  clang/lib/Lex/TokenLexer.cpp
  clang/test/Lexer/update_consecutive_macro_address_space.c

Index: clang/test/Lexer/update_consecutive_macro_address_space.c
===
--- /dev/null
+++ clang/test/Lexer/update_consecutive_macro_address_space.c
@@ -0,0 +1,36 @@
+// RUN: %clang -cc1 -print-stats %s 2>&1 | FileCheck %s
+// CHECK: 6 local SLocEntry's allocated
+//
+// Verify that the macro arg expansion is split to two file ids, we have 6 file
+// ids rather than 5:
+//   0: invalid file id
+//   1: main file
+//   2: builtin file
+//   3: macro expansion for X
+//   4: macro arg expansions for 1
+//   5: macro arg expansions for == 2
+#define X(x) (int)(x);
+void func() {
+  X(1
+/*/
+/*/
+/*/
+/*/
+/*/
+/*/
+/*/
+/*/
+/*/
+/*/
+/*/
+/*/
+/*/
+/*/
+/*/
+/*/
+/*/
+/*/
+/*/
+/*/
+== 2);
+}
Index: clang/lib/Lex/TokenLexer.cpp
===
--- clang/lib/Lex/TokenLexer.cpp
+++ clang/lib/Lex/TokenLexer.cpp
@@ -25,6 +25,7 @@
 #include "clang/Lex/Token.h"
 #include "clang/Lex/VariadicMacroSupport.h"
 #include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/iterator_range.h"
@@ -984,65 +985,71 @@
 /// \arg begin_tokens will be updated to a position past all the found
 /// consecutive tokens.
 static void updateConsecutiveMacroArgTokens(SourceManager &SM,
-SourceLocation InstLoc,
+SourceLocation ExpandLoc,
 Token *&begin_tokens,
 Token * end_tokens) {
-  assert(begin_tokens < end_tokens);
-
-  SourceLocation FirstLoc = begin_tokens->getLocation();
-  SourceLocation CurLoc = FirstLoc;
-
-  // Compare the source location offset of tokens and group together tokens that
-  // are close, even if their locations point to different FileIDs. e.g.
-  //
-  //  |bar|  foo | cake   |  (3 tokens from 3 consecutive FileIDs)
-  //  ^^
-  //  |bar   foo   cake| (one SLocEntry chunk for all tokens)
-  //
-  // we can perform this "merge" since the token's spelling location depends
-  // on the relative offset.
-
-  Token *NextTok = begin_tokens + 1;
-  for (; NextTok < end_tokens; ++NextTok) {
-SourceLocation NextLoc = NextTok->getLocation();
-if (CurLoc.isFileID() != NextLoc.isFileID())
-  break; // Token from different kind of FileID.
-
-SourceL

[PATCH] D135583: [LLVM] Use DWARFv4 bitfields when tuning for GDB

2022-10-26 Thread David Spickett via Phabricator via cfe-commits
DavidSpickett updated this revision to Diff 470766.
DavidSpickett added a comment.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

- Test that linux DWARFv4 uses data_bit_offset and that adding GDB tuning does 
not change that.
- Add release notes for clang and llvm.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135583

Files:
  clang/docs/ReleaseNotes.rst
  llvm/docs/ReleaseNotes.rst
  llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
  llvm/test/DebugInfo/X86/bitfields-dwarf4.ll
  llvm/test/DebugInfo/X86/packed_bitfields.ll


Index: llvm/test/DebugInfo/X86/packed_bitfields.ll
===
--- llvm/test/DebugInfo/X86/packed_bitfields.ll
+++ llvm/test/DebugInfo/X86/packed_bitfields.ll
@@ -1,7 +1,5 @@
 ; RUN: llc -dwarf-version=2 -mtriple x86_64-apple-macosx -O0 -filetype=obj -o 
%t_2_le.o %s
 ; RUN: llvm-dwarfdump -v -debug-info %t_2_le.o | FileCheck %s
-; RUN: llc -dwarf-version=4 -debugger-tune=gdb -mtriple x86_64-apple-macosx 
-O0 -filetype=obj -o %t_4_le.o %s
-; RUN: llvm-dwarfdump -v -debug-info %t_4_le.o | FileCheck %s
 
 ; Produced at -O0 from:
 ; struct {
Index: llvm/test/DebugInfo/X86/bitfields-dwarf4.ll
===
--- llvm/test/DebugInfo/X86/bitfields-dwarf4.ll
+++ llvm/test/DebugInfo/X86/bitfields-dwarf4.ll
@@ -1,8 +1,9 @@
 ; RUN: llc -mtriple x86_64-apple-macosx -O0 -filetype=obj -o - %s \
 ; RUN: | llvm-dwarfdump -v -debug-info - | FileCheck %s
 ; RUN: llc -mtriple x86_64-gnu-linux -O0 -filetype=obj -o - %s \
-; RUN: | llvm-dwarfdump -v -debug-info - | FileCheck %s --check-prefix=LINUX
-; LINUX-NOT: DW_AT_data_bit_offset
+; RUN: | llvm-dwarfdump -v -debug-info - | FileCheck %s
+; RUN: llc -mtriple x86_64-gnu-linux -O0 -debugger-tune=gdb -filetype=obj -o - 
%s \
+; RUN: | llvm-dwarfdump -v -debug-info - | FileCheck %s
 ;
 ; Generated from:
 ;   #include 
Index: llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
===
--- llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
+++ llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
@@ -428,8 +428,7 @@
   // https://sourceware.org/bugzilla/show_bug.cgi?id=11616
   UseGNUTLSOpcode = tuneForGDB() || DwarfVersion < 3;
 
-  // GDB does not fully support the DWARF 4 representation for bitfields.
-  UseDWARF2Bitfields = (DwarfVersion < 4) || tuneForGDB();
+  UseDWARF2Bitfields = (DwarfVersion < 4);
 
   // The DWARF v5 string offsets table has - possibly shared - contributions
   // from each compile and type unit each preceded by a header. The string
Index: llvm/docs/ReleaseNotes.rst
===
--- llvm/docs/ReleaseNotes.rst
+++ llvm/docs/ReleaseNotes.rst
@@ -177,7 +177,12 @@
 Changes to the Debug Info
 -
 
-During this release ...
+Previously when emitting DWARFv4 and tuning for GDB, llc would use DWARFv2's
+``DW_AT_bit_offset`` and ``DW_AT_data_member_location``. llc now uses DWARFv4's
+``DW_AT_data_bit_offset`` regardless of tuning.
+
+Support for ``DW_AT_data_bit_offset`` was added in GDB 8.0. For earlier 
versions,
+you can use llc's ``-dwarf-version=3`` option to emit compatible DWARF.
 
 Changes to the LLVM tools
 -
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -616,6 +616,13 @@
 DWARF Support in Clang
 --
 
+Previously when emitting DWARFv4 and tuning for GDB, Clang would use DWARFv2's
+``DW_AT_bit_offset`` and ``DW_AT_data_member_location``. Clang now uses 
DWARFv4's
+``DW_AT_data_bit_offset`` regardless of tuning.
+
+Support for ``DW_AT_data_bit_offset`` was added in GDB 8.0. For earlier 
versions,
+you can use the ``-gdwarf-3`` option to emit compatible DWARF.
+
 Arm and AArch64 Support in Clang
 
 


Index: llvm/test/DebugInfo/X86/packed_bitfields.ll
===
--- llvm/test/DebugInfo/X86/packed_bitfields.ll
+++ llvm/test/DebugInfo/X86/packed_bitfields.ll
@@ -1,7 +1,5 @@
 ; RUN: llc -dwarf-version=2 -mtriple x86_64-apple-macosx -O0 -filetype=obj -o %t_2_le.o %s
 ; RUN: llvm-dwarfdump -v -debug-info %t_2_le.o | FileCheck %s
-; RUN: llc -dwarf-version=4 -debugger-tune=gdb -mtriple x86_64-apple-macosx -O0 -filetype=obj -o %t_4_le.o %s
-; RUN: llvm-dwarfdump -v -debug-info %t_4_le.o | FileCheck %s
 
 ; Produced at -O0 from:
 ; struct {
Index: llvm/test/DebugInfo/X86/bitfields-dwarf4.ll
===
--- llvm/test/DebugInfo/X86/bitfields-dwarf4.ll
+++ llvm/test/DebugInfo/X86/bitfields-dwarf4.ll
@@ -1,8 +1,9 @@
 ; RUN: llc -mtriple x86_64-apple-macosx -O0 -filetype=obj -o - %s \
 ; RUN: | llvm-dwarfdu

[PATCH] D135930: [X86] Add AVX-NE-CONVERT instructions.

2022-10-26 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon added a comment.

Possibly rename the x86-64-* test files to *-64 (and *-32 equivalent) so that 
the 32/64 bit files are closer together for tracking (and to help avoid bitrot).




Comment at: clang/lib/Headers/immintrin.h:257
 
+/* FIXME: Change these When _Float16 type is supported */
+#if defined(__AVXNECONVERT__) && defined(__AVX512FP16__)

pengfei wrote:
> FreddyYe wrote:
> > pengfei wrote:
> > > craig.topper wrote:
> > > > Is this FIXME still relevant? Don't we support _Float16 with SSE2 now?
> > > _Float16 is supported with SSE2, but maybe we need to move `__m128h`, 
> > > `__m256h` out of avx512fp16intrin.h
> > Yes. This is a redundant FIXME.
> I have moved FP16/BF16 vector types out of original header files. rGe0fb01e9
> There should be no dependency to FP16 and BF16 feature now.
Update to this?
```
#if !(defined(_MSC_VER) || defined(__SCE__)) || __has_feature(modules) ||  \
(defined(__AVXNECONVERT__) && defined(__AVX512FP16__))
```



Comment at: llvm/test/MC/X86/x86-64-avx-ne-convert-att.s:1
+// RUN: llvm-mc -triple x86_64-unknown-unknown --show-encoding %s | FileCheck 
%s
+

x86-64-avx-ne-convert-intel.s ?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135930

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


[PATCH] D126903: [clang] Add support for __builtin_memset_inline

2022-10-26 Thread Guillaume Chatelet via Phabricator via cfe-commits
gchatelet added a comment.

It should be fixed now @aganea . Can you check?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126903

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


[PATCH] D131469: [Clang] change default storing path of `-ftime-trace`

2022-10-26 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added inline comments.



Comment at: clang/lib/Driver/Driver.cpp:4531-4548
+// Get linking executable file's parent path as TracePath's parent path,
+// default is ".". Filename may be determined and added into TracePath 
then.
+//
+// e.g. executable file's path: /usr/local/a.out
+//  its parent's path:  /usr/local
+for (auto &J : C.getJobs()) {
+  if (J.getSource().getKind() == Action::LinkJobClass) {

Maetveis wrote:
> Instead of looking for linking jobs, to determine the folder to store the 
> traces, you could use the output location from `-o ` (if specified).
> This is already available in `Driver::BuildJobs` as `FinalOutput` (see on 
> line 4605), it will be `nullptr` if no `-o` option was given.
Looks like this was not addressed.
I would suspect, not doing so will break **The** most common use case
of separately compiling sources and then linking them together, does it not?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131469

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


[PATCH] D136746: [mlir] Saturation arithmetic intrinsics

2022-10-26 Thread Omri Bloch via Phabricator via cfe-commits
omri123 updated this revision to Diff 470775.
omri123 added a comment.

Thanks for your comments! In this revision I fixed the diff and updated the 
intrinsics to use `LLVM_BinarySameArgsIntrOpI`.


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

https://reviews.llvm.org/D136746

Files:
  mlir/include/mlir/Dialect/LLVMIR/LLVMIntrinsicOps.td
  mlir/test/Target/LLVMIR/Import/intrinsic.ll
  mlir/test/Target/LLVMIR/llvmir-intrinsics.mlir

Index: mlir/test/Target/LLVMIR/llvmir-intrinsics.mlir
===
--- mlir/test/Target/LLVMIR/llvmir-intrinsics.mlir
+++ mlir/test/Target/LLVMIR/llvmir-intrinsics.mlir
@@ -428,6 +428,42 @@
   llvm.return
 }
 
+// CHECK-LABEL: @sadd_sat_test
+llvm.func @sadd_sat_test(%arg0: i32, %arg1: i32, %arg2: vector<8xi32>, %arg3: vector<8xi32>) {
+  // CHECK: call i32 @llvm.sadd.sat.i32
+  "llvm.intr.sadd.sat"(%arg0, %arg1) : (i32, i32) -> i32
+  // CHECK: call <8 x i32> @llvm.sadd.sat.v8i32
+  "llvm.intr.sadd.sat"(%arg2, %arg3) : (vector<8xi32>, vector<8xi32>) -> vector<8xi32>
+  llvm.return
+}
+
+// CHECK-LABEL: @uadd_sat_test
+llvm.func @uadd_sat_test(%arg0: i32, %arg1: i32, %arg2: vector<8xi32>, %arg3: vector<8xi32>) {
+  // CHECK: call i32 @llvm.uadd.sat.i32
+  "llvm.intr.uadd.sat"(%arg0, %arg1) : (i32, i32) -> i32
+  // CHECK: call <8 x i32> @llvm.uadd.sat.v8i32
+  "llvm.intr.uadd.sat"(%arg2, %arg3) : (vector<8xi32>, vector<8xi32>) -> vector<8xi32>
+  llvm.return
+}
+
+// CHECK-LABEL: @ssub_sat_test
+llvm.func @ssub_sat_test(%arg0: i32, %arg1: i32, %arg2: vector<8xi32>, %arg3: vector<8xi32>) {
+  // CHECK: call i32 @llvm.ssub.sat.i32
+  "llvm.intr.ssub.sat"(%arg0, %arg1) : (i32, i32) -> i32
+  // CHECK: call <8 x i32> @llvm.ssub.sat.v8i32
+  "llvm.intr.ssub.sat"(%arg2, %arg3) : (vector<8xi32>, vector<8xi32>) -> vector<8xi32>
+  llvm.return
+}
+
+// CHECK-LABEL: @usub_sat_test
+llvm.func @usub_sat_test(%arg0: i32, %arg1: i32, %arg2: vector<8xi32>, %arg3: vector<8xi32>) {
+  // CHECK: call i32 @llvm.usub.sat.i32
+  "llvm.intr.usub.sat"(%arg0, %arg1) : (i32, i32) -> i32
+  // CHECK: call <8 x i32> @llvm.usub.sat.v8i32
+  "llvm.intr.usub.sat"(%arg2, %arg3) : (vector<8xi32>, vector<8xi32>) -> vector<8xi32>
+  llvm.return
+}
+
 // CHECK-LABEL: @coro_id
 llvm.func @coro_id(%arg0: i32, %arg1: !llvm.ptr) {
   // CHECK: call token @llvm.coro.id
@@ -770,6 +806,14 @@
 // CHECK-DAG: declare { <8 x i32>, <8 x i1> } @llvm.usub.with.overflow.v8i32(<8 x i32>, <8 x i32>) #0
 // CHECK-DAG: declare { i32, i1 } @llvm.umul.with.overflow.i32(i32, i32)
 // CHECK-DAG: declare { <8 x i32>, <8 x i1> } @llvm.umul.with.overflow.v8i32(<8 x i32>, <8 x i32>) #0
+// CHECK-DAG: declare i32 @llvm.sadd.sat.i32(i32, i32) #0
+// CHECK-DAG: declare <8 x i32> @llvm.sadd.sat.v8i32(<8 x i32>, <8 x i32>) #0
+// CHECK-DAG: declare i32 @llvm.uadd.sat.i32(i32, i32) #0
+// CHECK-DAG: declare <8 x i32> @llvm.uadd.sat.v8i32(<8 x i32>, <8 x i32>) #0
+// CHECK-DAG: declare i32 @llvm.ssub.sat.i32(i32, i32) #0
+// CHECK-DAG: declare <8 x i32> @llvm.ssub.sat.v8i32(<8 x i32>, <8 x i32>) #0
+// CHECK-DAG: declare i32 @llvm.usub.sat.i32(i32, i32) #0
+// CHECK-DAG: declare <8 x i32> @llvm.usub.sat.v8i32(<8 x i32>, <8 x i32>) #0
 // CHECK-DAG: declare token @llvm.coro.id(i32, ptr readnone, ptr nocapture readonly, ptr)
 // CHECK-DAG: declare ptr @llvm.coro.begin(token, ptr writeonly)
 // CHECK-DAG: declare i64 @llvm.coro.size.i64()
Index: mlir/test/Target/LLVMIR/Import/intrinsic.ll
===
--- mlir/test/Target/LLVMIR/Import/intrinsic.ll
+++ mlir/test/Target/LLVMIR/Import/intrinsic.ll
@@ -372,6 +372,42 @@
   ret void
 }
 
+; CHECK-LABEL:  llvm.func @sadd_sat_test
+define void @sadd_sat_test(i32 %0, i32 %1, <8 x i32> %2, <8 x i32> %3) {
+  ; CHECK: "llvm.intr.sadd.sat"(%{{.*}}, %{{.*}}) : (i32, i32) -> i32
+  %5 = call i32 @llvm.sadd.sat.i32(i32 %0, i32 %1)
+  ; CHECK: "llvm.intr.sadd.sat"(%{{.*}}, %{{.*}}) : (vector<8xi32>, vector<8xi32>) -> vector<8xi32>
+  %6 = call <8 x i32> @llvm.sadd.sat.v8i32(<8 x i32> %2, <8 x i32> %3)
+  ret void
+}
+
+; CHECK-LABEL:  llvm.func @uadd_sat_test
+define void @uadd_sat_test(i32 %0, i32 %1, <8 x i32> %2, <8 x i32> %3) {
+  ; CHECK: "llvm.intr.uadd.sat"(%{{.*}}, %{{.*}}) : (i32, i32) -> i32
+  %5 = call i32 @llvm.uadd.sat.i32(i32 %0, i32 %1)
+  ; CHECK: "llvm.intr.uadd.sat"(%{{.*}}, %{{.*}}) : (vector<8xi32>, vector<8xi32>) -> vector<8xi32>
+  %6 = call <8 x i32> @llvm.uadd.sat.v8i32(<8 x i32> %2, <8 x i32> %3)
+  ret void
+}
+
+; CHECK-LABEL:  llvm.func @ssub_sat_test
+define void @ssub_sat_test(i32 %0, i32 %1, <8 x i32> %2, <8 x i32> %3) {
+  ; CHECK: "llvm.intr.ssub.sat"(%{{.*}}, %{{.*}}) : (i32, i32) -> i32
+  %5 = call i32 @llvm.ssub.sat.i32(i32 %0, i32 %1)
+  ; CHECK: "llvm.intr.ssub.sat"(%{{.*}}, %{{.*}}) : (vector<8xi32>, vector<8xi32>) -> vector<8xi32>
+  %6 = call <8 x i32> @llvm.ssub.sat.v8i32(<8 x i32> %2, <8 x i32> %3)
+  ret void
+}
+
+; CHECK-LABEL:  llvm.fun

[PATCH] D135750: [clang][Interp] Track initialization state of local variables

2022-10-26 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 470724.

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

https://reviews.llvm.org/D135750

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/ByteCodeStmtGen.cpp
  clang/lib/AST/Interp/Context.cpp
  clang/lib/AST/Interp/Descriptor.cpp
  clang/lib/AST/Interp/Descriptor.h
  clang/lib/AST/Interp/EvalEmitter.cpp
  clang/lib/AST/Interp/Interp.h
  clang/lib/AST/Interp/InterpBlock.h
  clang/lib/AST/Interp/InterpFrame.cpp
  clang/lib/AST/Interp/InterpFrame.h
  clang/lib/AST/Interp/Pointer.cpp
  clang/lib/AST/Interp/Pointer.h
  clang/lib/AST/Interp/Program.cpp
  clang/lib/AST/Interp/Program.h
  clang/test/AST/Interp/cxx20.cpp
  clang/test/AST/Interp/loops.cpp

Index: clang/test/AST/Interp/loops.cpp
===
--- clang/test/AST/Interp/loops.cpp
+++ clang/test/AST/Interp/loops.cpp
@@ -5,6 +5,7 @@
 
 // ref-no-diagnostics
 // expected-no-diagnostics
+// expected-cpp20-no-diagnostics
 
 namespace WhileLoop {
   constexpr int f() {
@@ -165,8 +166,6 @@
   static_assert(f5(true) == 8, "");
   static_assert(f5(false) == 5, "");
 
-  /// FIXME: This should be accepted in C++20 but is currently being rejected
-  ///   because the variable declaration doesn't have an initializier.
 #if __cplusplus >= 202002L
   constexpr int f6() {
 int i;
@@ -176,7 +175,7 @@
 } while (true);
 return i;
   }
-  static_assert(f6() == 5, ""); // expected-cpp20-error {{not an integral constant}}
+  static_assert(f6() == 5, "");
 #endif
 
 #if 0
Index: clang/test/AST/Interp/cxx20.cpp
===
--- clang/test/AST/Interp/cxx20.cpp
+++ clang/test/AST/Interp/cxx20.cpp
@@ -52,33 +52,27 @@
 }
 static_assert(pointerAssign2() == 12, "");
 
-
 constexpr int unInitLocal() {
   int a;
-  return a; // ref-note{{read of uninitialized object}}
+  return a; // ref-note {{read of uninitialized object}} \
+// expected-note {{read of object outside its lifetime}}
+// FIXME: ^^^ Wrong diagnostic.
 }
-static_assert(unInitLocal() == 0, ""); // expected-error {{not an integral constant expression}} \
-   // ref-error {{not an integral constant expression}} \
-   // ref-note {{in call to 'unInitLocal()'}}
-
-/// TODO: The example above is correctly rejected by the new constexpr
-///   interpreter, but for the wrong reasons. We don't reject it because
-///   it is an uninitialized read, we reject it simply because
-///   the local variable does not have an initializer.
-///
-///   The code below should be accepted but is also being rejected
-///   right now.
-#if 0
+static_assert(unInitLocal() == 0, ""); // ref-error {{not an integral constant expression}} \
+   // ref-note {{in call to 'unInitLocal()'}} \
+   // expected-error {{not an integral constant expression}} \
+   // expected-note {{in call to 'unInitLocal()'}} \
+
 constexpr int initializedLocal() {
   int a;
-  int b;
-
   a = 20;
   return a;
 }
 static_assert(initializedLocal() == 20);
 
-/// Similar here, but the uninitialized local is passed as a function parameter.
+#if 0
+// FIXME: This code should be rejected because we pass an uninitialized value
+//   as a function parameter.
 constexpr int inc(int a) { return a + 1; }
 constexpr int f() {
 int i;
Index: clang/lib/AST/Interp/Program.h
===
--- clang/lib/AST/Interp/Program.h
+++ clang/lib/AST/Interp/Program.h
@@ -104,18 +104,20 @@
   Record *getOrCreateRecord(const RecordDecl *RD);
 
   /// Creates a descriptor for a primitive type.
-  Descriptor *createDescriptor(const DeclTy &D, PrimType Type,
-   bool IsConst = false,
-   bool IsTemporary = false,
-   bool IsMutable = false) {
-return allocateDescriptor(D, Type, IsConst, IsTemporary, IsMutable);
+  Descriptor *createDescriptor(
+  const DeclTy &D, PrimType Type,
+  Descriptor::MetadataSize MDSize = Descriptor::MetadataSize{0},
+  bool IsConst = false, bool IsTemporary = false, bool IsMutable = false) {
+return allocateDescriptor(D, Type, MDSize, IsConst, IsTemporary, IsMutable);
   }
 
   /// Creates a descriptor for a composite type.
-  Descriptor *createDescriptor(const DeclTy &D, const Type *Ty,
-   bool IsConst = false, bool IsTemporary = false,
-   bool IsMutable = false,
-   const Expr *Init = nullptr);
+  Descriptor *createDescriptor(
+  const DeclTy &D, const Type *Ty,
+  Descriptor::MetadataSize MDSize = Descriptor::MetadataSize{0},
+  // size_t MetadataSize = 0,
+  bool IsConst = false, bool IsTemporary = false, bool Is

[PATCH] D136746: [mlir] Saturation arithmetic intrinsics

2022-10-26 Thread Tobias Gysi via Phabricator via cfe-commits
gysit added a comment.

Looks good from my side modulo the nit comment. Let's wait for @ftynse (the 
code owner) for the final approval.




Comment at: mlir/test/Target/LLVMIR/Import/intrinsic.ll:778
+declare i32 @llvm.usub.sat.i32(i32, i32)
+declare <8 x i32> @llvm.usub.sat.v8i32(<8 x i32>, <8 x i32>) #0
 declare token @llvm.coro.id(i32, i8* readnone, i8* nocapture readonly, i8*)

nit: the #0 seems unnecessary.


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

https://reviews.llvm.org/D136746

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


[PATCH] D136746: [mlir] Saturation arithmetic intrinsics

2022-10-26 Thread Tobias Gysi via Phabricator via cfe-commits
gysit added inline comments.



Comment at: mlir/include/mlir/Dialect/LLVMIR/LLVMIntrinsicOps.td:179
+def LLVM_SAddSat : LLVM_BinarySameArgsIntrOpI<"sadd.sat">;
+def LLVM_SAddSat : LLVM_BinarySameArgsIntrOpI<"uadd.sat">;
+def LLVM_SAddSat : LLVM_BinarySameArgsIntrOpI<"ssub.sat">;

Ah I missed that one. The Op names need to differ of course LLVM_SAddSat, 
LLVM_UAddSat, etc.


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

https://reviews.llvm.org/D136746

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


[PATCH] D136746: [mlir] Saturation arithmetic intrinsics

2022-10-26 Thread Alex Zinenko via Phabricator via cfe-commits
ftynse added inline comments.



Comment at: mlir/include/mlir/Dialect/LLVMIR/LLVMIntrinsicOps.td:179
+def LLVM_SAddSat : LLVM_BinarySameArgsIntrOpI<"sadd.sat">;
+def LLVM_SAddSat : LLVM_BinarySameArgsIntrOpI<"uadd.sat">;
+def LLVM_SAddSat : LLVM_BinarySameArgsIntrOpI<"ssub.sat">;

gysit wrote:
> Ah I missed that one. The Op names need to differ of course LLVM_SAddSat, 
> LLVM_UAddSat, etc.
Indeed, this is breaking the tests.



Comment at: mlir/test/Target/LLVMIR/llvmir-intrinsics.mlir:809-816
+// CHECK-DAG: declare i32 @llvm.sadd.sat.i32(i32, i32) #0
+// CHECK-DAG: declare <8 x i32> @llvm.sadd.sat.v8i32(<8 x i32>, <8 x i32>) #0
+// CHECK-DAG: declare i32 @llvm.uadd.sat.i32(i32, i32) #0
+// CHECK-DAG: declare <8 x i32> @llvm.uadd.sat.v8i32(<8 x i32>, <8 x i32>) #0
+// CHECK-DAG: declare i32 @llvm.ssub.sat.i32(i32, i32) #0
+// CHECK-DAG: declare <8 x i32> @llvm.ssub.sat.v8i32(<8 x i32>, <8 x i32>) #0
+// CHECK-DAG: declare i32 @llvm.usub.sat.i32(i32, i32) #0

Nit: I'd rather remove the `#0` matadata because the `0` is transient. I see 
some cases above also match for that, but it is a mistake that makes tests 
fragile.


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

https://reviews.llvm.org/D136746

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


[PATCH] D134128: Resubmit an implemention for constrained template template parameters [P0857R0 Part B]

2022-10-26 Thread Liming Liu via Phabricator via cfe-commits
lime updated this revision to Diff 470779.
lime added a comment.

The previous update for conflicts lacks a comma, and the comma was added.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134128

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Parse/ParseTemplate.cpp
  clang/lib/Sema/SemaConcept.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/test/CXX/temp/temp.arg/temp.arg.template/p3-2a.cpp
  clang/test/SemaTemplate/concepts.cpp
  clang/www/cxx_status.html
  libcxx/DELETE.ME

Index: libcxx/DELETE.ME
===
--- /dev/null
+++ libcxx/DELETE.ME
@@ -0,0 +1 @@
+D134128
Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -912,11 +912,7 @@
 

 https://wg21.link/p0857r0";>P0857R0
-
-  Partial
-Constraining template template parameters is not yet supported.
-  
-
+Clang 16
   

 https://wg21.link/p1084r2";>P1084R2
Index: clang/test/SemaTemplate/concepts.cpp
===
--- clang/test/SemaTemplate/concepts.cpp
+++ clang/test/SemaTemplate/concepts.cpp
@@ -61,9 +61,9 @@
 
   // FIXME: This is valid under P0857R0.
   template concept C = true;
-  template requires C typename U> struct X {}; // expected-error {{requires 'class'}} expected-error 0+{{}}
+  template requires C typename U> struct X {};
   template requires C struct Y {};
-  X xy; // expected-error {{no template named 'X'}}
+  X xy;
 }
 
 namespace PR50306 {
Index: clang/test/CXX/temp/temp.arg/temp.arg.template/p3-2a.cpp
===
--- clang/test/CXX/temp/temp.arg/temp.arg.template/p3-2a.cpp
+++ clang/test/CXX/temp/temp.arg/temp.arg.template/p3-2a.cpp
@@ -1,22 +1,27 @@
 // RUN:  %clang_cc1 -std=c++2a -frelaxed-template-template-args -verify %s
 
-template concept C = T::f();
-// expected-note@-1{{similar constraint}}
+template concept C = T::f(); // #C
 template concept D = C && T::g();
-template concept F = T::f();
-// expected-note@-1{{similar constraint expressions not considered equivalent}}
-template class P> struct S1 { }; // expected-note 2{{'P' declared here}}
+template concept F = T::f(); // #F
+template class P> struct S1 { }; // #S1
 
 template struct X { };
 
-template struct Y { }; // expected-note{{'Y' declared here}}
+template struct Y { }; // #Y
 template struct Z { };
-template struct W { }; // expected-note{{'W' declared here}}
-
+template struct W { }; // #W
 S1 s11;
-S1 s12; // expected-error{{template template argument 'Y' is more constrained than template template parameter 'P'}}
+S1 s12;
+// expected-error@-1 {{template template argument 'Y' is more constrained than template template parameter 'P'}}
+// expected-note@#S1 {{'P' declared here}}
+// expected-note@#Y {{'Y' declared here}}
 S1 s13;
-S1 s14; // expected-error{{template template argument 'W' is more constrained than template template parameter 'P'}}
+S1 s14;
+// expected-error@-1 {{template template argument 'W' is more constrained than template template parameter 'P'}}
+// expected-note@#S1 {{'P' declared here}}
+// expected-note@#W {{'W' declared here}}
+// expected-note@#F 1-2{{similar constraint expressions not considered equivalent}}
+// expected-note@#C 1-2{{similar constraint}}
 
 template class P> struct S2 { };
 
@@ -32,3 +37,25 @@
 
 using s31 = S3;
 using s32 = S3;
+
+template requires C class P> struct S4 { }; // #S4
+
+S4 s41;
+S4 s42;
+// expected-error@-1 {{template template argument 'Y' is more constrained than template template parameter 'P'}}
+// expected-note@#S4 {{'P' declared here}}
+// expected-note@#Y {{'Y' declared here}}
+S4 s43;
+S4 s44;
+// expected-error@-1 {{template template argument 'W' is more constrained than template template parameter 'P'}}
+// expected-note@#S4 {{'P' declared here}}
+// expected-note@#W {{'W' declared here}}
+
+template requires C typename U> struct S5 {
+  template static U V;
+};
+
+struct Nothing {};
+
+// FIXME: Wait the standard to clarify the intent.
+template<> template<> Z S5::V;
Index: clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -4098,8 +4098,10 @@
 
 TemplateParameterList *
 Sema::SubstTemplateParams(TemplateParameterList *Params, DeclContext *Owner,
-  const MultiLevelTemplateArgumentList &TemplateArgs) {
+  const MultiLevelTemplateArgumentList &TemplateArgs,
+  bool EvaluateConstraint

[PATCH] D136746: [mlir] Saturation arithmetic intrinsics

2022-10-26 Thread Omri Bloch via Phabricator via cfe-commits
omri123 updated this revision to Diff 470780.
omri123 added a comment.

Thanks again! In this revision I fixed both issues mentioned above (removed 
`#0` from tests and renamed the tblgen definitions)


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

https://reviews.llvm.org/D136746

Files:
  mlir/include/mlir/Dialect/LLVMIR/LLVMIntrinsicOps.td
  mlir/test/Target/LLVMIR/Import/intrinsic.ll
  mlir/test/Target/LLVMIR/llvmir-intrinsics.mlir

Index: mlir/test/Target/LLVMIR/llvmir-intrinsics.mlir
===
--- mlir/test/Target/LLVMIR/llvmir-intrinsics.mlir
+++ mlir/test/Target/LLVMIR/llvmir-intrinsics.mlir
@@ -428,6 +428,42 @@
   llvm.return
 }
 
+// CHECK-LABEL: @sadd_sat_test
+llvm.func @sadd_sat_test(%arg0: i32, %arg1: i32, %arg2: vector<8xi32>, %arg3: vector<8xi32>) {
+  // CHECK: call i32 @llvm.sadd.sat.i32
+  "llvm.intr.sadd.sat"(%arg0, %arg1) : (i32, i32) -> i32
+  // CHECK: call <8 x i32> @llvm.sadd.sat.v8i32
+  "llvm.intr.sadd.sat"(%arg2, %arg3) : (vector<8xi32>, vector<8xi32>) -> vector<8xi32>
+  llvm.return
+}
+
+// CHECK-LABEL: @uadd_sat_test
+llvm.func @uadd_sat_test(%arg0: i32, %arg1: i32, %arg2: vector<8xi32>, %arg3: vector<8xi32>) {
+  // CHECK: call i32 @llvm.uadd.sat.i32
+  "llvm.intr.uadd.sat"(%arg0, %arg1) : (i32, i32) -> i32
+  // CHECK: call <8 x i32> @llvm.uadd.sat.v8i32
+  "llvm.intr.uadd.sat"(%arg2, %arg3) : (vector<8xi32>, vector<8xi32>) -> vector<8xi32>
+  llvm.return
+}
+
+// CHECK-LABEL: @ssub_sat_test
+llvm.func @ssub_sat_test(%arg0: i32, %arg1: i32, %arg2: vector<8xi32>, %arg3: vector<8xi32>) {
+  // CHECK: call i32 @llvm.ssub.sat.i32
+  "llvm.intr.ssub.sat"(%arg0, %arg1) : (i32, i32) -> i32
+  // CHECK: call <8 x i32> @llvm.ssub.sat.v8i32
+  "llvm.intr.ssub.sat"(%arg2, %arg3) : (vector<8xi32>, vector<8xi32>) -> vector<8xi32>
+  llvm.return
+}
+
+// CHECK-LABEL: @usub_sat_test
+llvm.func @usub_sat_test(%arg0: i32, %arg1: i32, %arg2: vector<8xi32>, %arg3: vector<8xi32>) {
+  // CHECK: call i32 @llvm.usub.sat.i32
+  "llvm.intr.usub.sat"(%arg0, %arg1) : (i32, i32) -> i32
+  // CHECK: call <8 x i32> @llvm.usub.sat.v8i32
+  "llvm.intr.usub.sat"(%arg2, %arg3) : (vector<8xi32>, vector<8xi32>) -> vector<8xi32>
+  llvm.return
+}
+
 // CHECK-LABEL: @coro_id
 llvm.func @coro_id(%arg0: i32, %arg1: !llvm.ptr) {
   // CHECK: call token @llvm.coro.id
@@ -770,6 +806,14 @@
 // CHECK-DAG: declare { <8 x i32>, <8 x i1> } @llvm.usub.with.overflow.v8i32(<8 x i32>, <8 x i32>) #0
 // CHECK-DAG: declare { i32, i1 } @llvm.umul.with.overflow.i32(i32, i32)
 // CHECK-DAG: declare { <8 x i32>, <8 x i1> } @llvm.umul.with.overflow.v8i32(<8 x i32>, <8 x i32>) #0
+// CHECK-DAG: declare i32 @llvm.sadd.sat.i32(i32, i32)
+// CHECK-DAG: declare <8 x i32> @llvm.sadd.sat.v8i32(<8 x i32>, <8 x i32>)
+// CHECK-DAG: declare i32 @llvm.uadd.sat.i32(i32, i32)
+// CHECK-DAG: declare <8 x i32> @llvm.uadd.sat.v8i32(<8 x i32>, <8 x i32>)
+// CHECK-DAG: declare i32 @llvm.ssub.sat.i32(i32, i32)
+// CHECK-DAG: declare <8 x i32> @llvm.ssub.sat.v8i32(<8 x i32>, <8 x i32>)
+// CHECK-DAG: declare i32 @llvm.usub.sat.i32(i32, i32)
+// CHECK-DAG: declare <8 x i32> @llvm.usub.sat.v8i32(<8 x i32>, <8 x i32>)
 // CHECK-DAG: declare token @llvm.coro.id(i32, ptr readnone, ptr nocapture readonly, ptr)
 // CHECK-DAG: declare ptr @llvm.coro.begin(token, ptr writeonly)
 // CHECK-DAG: declare i64 @llvm.coro.size.i64()
Index: mlir/test/Target/LLVMIR/Import/intrinsic.ll
===
--- mlir/test/Target/LLVMIR/Import/intrinsic.ll
+++ mlir/test/Target/LLVMIR/Import/intrinsic.ll
@@ -372,6 +372,42 @@
   ret void
 }
 
+; CHECK-LABEL:  llvm.func @sadd_sat_test
+define void @sadd_sat_test(i32 %0, i32 %1, <8 x i32> %2, <8 x i32> %3) {
+  ; CHECK: "llvm.intr.sadd.sat"(%{{.*}}, %{{.*}}) : (i32, i32) -> i32
+  %5 = call i32 @llvm.sadd.sat.i32(i32 %0, i32 %1)
+  ; CHECK: "llvm.intr.sadd.sat"(%{{.*}}, %{{.*}}) : (vector<8xi32>, vector<8xi32>) -> vector<8xi32>
+  %6 = call <8 x i32> @llvm.sadd.sat.v8i32(<8 x i32> %2, <8 x i32> %3)
+  ret void
+}
+
+; CHECK-LABEL:  llvm.func @uadd_sat_test
+define void @uadd_sat_test(i32 %0, i32 %1, <8 x i32> %2, <8 x i32> %3) {
+  ; CHECK: "llvm.intr.uadd.sat"(%{{.*}}, %{{.*}}) : (i32, i32) -> i32
+  %5 = call i32 @llvm.uadd.sat.i32(i32 %0, i32 %1)
+  ; CHECK: "llvm.intr.uadd.sat"(%{{.*}}, %{{.*}}) : (vector<8xi32>, vector<8xi32>) -> vector<8xi32>
+  %6 = call <8 x i32> @llvm.uadd.sat.v8i32(<8 x i32> %2, <8 x i32> %3)
+  ret void
+}
+
+; CHECK-LABEL:  llvm.func @ssub_sat_test
+define void @ssub_sat_test(i32 %0, i32 %1, <8 x i32> %2, <8 x i32> %3) {
+  ; CHECK: "llvm.intr.ssub.sat"(%{{.*}}, %{{.*}}) : (i32, i32) -> i32
+  %5 = call i32 @llvm.ssub.sat.i32(i32 %0, i32 %1)
+  ; CHECK: "llvm.intr.ssub.sat"(%{{.*}}, %{{.*}}) : (vector<8xi32>, vector<8xi32>) -> vector<8xi32>
+  %6 = call <8 x i32> @llvm.ssub.sat.v8i32(<8 x i32> %2, <8 x i32> %3)
+  ret void
+}
+
+; CHECK-LABEL:  llvm.func @usub_sat_test
+de

[PATCH] D136746: [mlir] Saturation arithmetic intrinsics

2022-10-26 Thread Alex Zinenko via Phabricator via cfe-commits
ftynse accepted this revision.
ftynse added a comment.
This revision is now accepted and ready to land.

Please wait for the tests to pass before submitting.


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

https://reviews.llvm.org/D136746

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


[PATCH] D126903: [clang] Add support for __builtin_memset_inline

2022-10-26 Thread Alexandre Ganea via Phabricator via cfe-commits
aganea added a comment.

In D126903#3885114 , @gchatelet wrote:

> It should be fixed now @aganea . Can you check?

Works now, thanks again for the quick response. Should D136752 
 be cherry-picked into the 15.0 branch?

In D126903#3884748 , @thieta wrote:

> We have been building a two stage clang and our internal projects with this 
> version of rpmalloc and clang 15.x a while now and I haven't see the issue 
> you see @aganea. I don't think this patch is the problem as @efriedma 
> suggested, could be in rpmalloc but since I have used this successfully 
> already I am not sure about that either.

Is your internal build using the rpmalloc develop branch?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126903

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


[PATCH] D136533: [clang] Fix missing diagnostic of declaration use when accessing TypeDecls through typename access

2022-10-26 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added a subscriber: ldionne.
mizvekov added a comment.

In D136533#3884364 , @glandium wrote:

> (And specifically, FuzzerFork.cpp doesn't use any of those declared things. 
> Its only sin is to `#include `, which happens to have /some/ methods 
> (std::filesystem-related) only available on macos 10.15+.)
>
> Edit: Corollary: anything that `#include `, builds with C++17 or 
> more, and wants to support macos < 10.15, is broken by this patch.

Nonetheless, it seems libc++ uses a deprecated declaration from it's own 
headers.

@ldionne FYI, we may have a libc++ issue here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136533

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


[PATCH] D136744: [Clang] perform "maximum TLS alignment" check for template instantiation

2022-10-26 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov accepted this revision.
mizvekov added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/lib/Sema/SemaDecl.cpp:14038-14039
+
+  if (!Context.getTargetInfo().isTLSSupported())
+return;
+

Is this needed? It seems `getMaxTLSAlign()` will return 0 in that case anyway.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136744

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


[PATCH] D136120: [Clang] follow-up D128745, remove ClangABICompat checks

2022-10-26 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.

LGTM, thank you!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136120

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


[PATCH] D133698: [clang][dataflow] Implement transferBranch

2022-10-26 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel accepted this revision.
ymandel added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/unittests/Analysis/FlowSensitive/TransferBranchTest.cpp:73
+   .getName())}),
+  /*VerifyResults=*/Match),
+  llvm::Succeeded());

nit: maybe just rename the parameter to `VerifyResults` (and then no need for 
the comment)?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133698

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


[PATCH] D136568: [Clang] Support constexpr builtin ilogb

2022-10-26 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a subscriber: hubert.reinterpretcast.
aaron.ballman added a comment.

In D136568#3880711 , @jcranmer-intel 
wrote:

> FWIW, I would be slightly wary of relying on cppreference as definitive for 
> niche semantic issues like this, although it is correct in this case. C2x is 
> actually pretty well-organized in Annex F, and enumerates most of the corner 
> cases specifically in every function.

+1 to this point; the edge cases are pretty tricky and the standard is the 
source of truth for how we should be implementing this stuff.




Comment at: clang/lib/AST/ExprConstant.cpp:12452
+int Ilogb;
+if (APFloat::opStatus St = ilogb(F, Ilogb); !isConstantOpStatus(St))
+  return false;

jcranmer-intel wrote:
> `long double` is `ppc_fp128` on at least some PPC targets, and while I'm not 
> entirely certain of what `ilogb` properly returns in the corner cases of the 
> `ppc_fp128`, I'm not entirely confident that the implementation of `APFloat` 
> is correct in those cases. I'd like someone with PPC background to comment in 
> here.
Paging @hubert.reinterpretcast for help finding a good person to comment on the 
PPC questions.



Comment at: llvm/include/llvm/ADT/APFloat.h:450-454
   /// For special APFloat values, this returns special error codes:
   ///
   ///   NaN -> \c IEK_NaN
   ///   0   -> \c IEK_Zero
   ///   Inf -> \c IEK_Inf

Is this part of the comment still accurate?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136568

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


[PATCH] D136532: [clang][Interp] Implement left and right shifts

2022-10-26 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/test/AST/Interp/shifts.cpp:57
+//c >>= 99; // expected-warning {{shift count >= width of type}}
+//c <<= CHAR_BIT; // expected-warning {{shift count >= width of type}}
+//c >>= CHAR_BIT; // expected-warning {{shift count >= width of type}}

shafik wrote:
> aaron.ballman wrote:
> > tbaeder wrote:
> > > shafik wrote:
> > > > This is not correct, the operands go through integral promotions first 
> > > > and the result is the promoted type of the left operand see [dcl.shift 
> > > > p1](https://eel.is/c++draft/expr.shift#1).
> > > > 
> > > > Also see godbolt: https://godbolt.org/z/7qzKjojMb
> > > Hmm, this is copy-pasted from `test/SemaCXX/shift.cpp`.
> > FWIW, I agree with Shafik -- you can also see the casts in the AST: 
> > https://godbolt.org/z/97dqr1TEs
> This weird, you can see this is indeed valid in a constant expression: 
> https://godbolt.org/z/W33janMxv
> 
> but we do obtain that diagnostic and I think I see what it is saying, that 
> the result type is 8bit but the shift is larger than that type even though 
> the operation is being done on the promoted type. I feel like the diagnostic 
> is not great but could be improved to make it better.
> 
> wdyt @aaron.ballman 
> This weird, you can see this is indeed valid in a constant expression: 
> https://godbolt.org/z/W33janMxv

Yes, because of the integral promotion of `c` to `int`.

> but we do obtain that diagnostic and I think I see what it is saying, that 
> the result type is 8bit but the shift is larger than that type even though 
> the operation is being done on the promoted type. I feel like the diagnostic 
> is not great but could be improved to make it better.

I think it's telling the programmer that something strange is happening here. 
Yes, it's well-defined because of integral promotions, but it still looks like 
suspect code. We could say "width of the unpromoted type" but that might make 
the diagnostic more confusing for non-language lawyer folks.


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

https://reviews.llvm.org/D136532

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


[PATCH] D134128: Resubmit an implemention for constrained template template parameters [P0857R0 Part B]

2022-10-26 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

Still need release notes!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134128

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


[PATCH] D134453: Disambiguate type names when printing NTTP types

2022-10-26 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D134453#3880794 , @mizvekov wrote:

> In D134453#3880729 , @dblaikie 
> wrote:
>
>> I think we should restrict the discussion in this review to being only about 
>> the case where we have the canonical type (acknowledging that there's 
>> broader work to reduce the number of cases where that is what we have to 
>> deal with).
>
> I agree that we can leave that aside for this patch.

+1 :-)

>> When you say "for reasonably small objects" are you suggesting this patch/an 
>> nearish-term solution to the original problem presented here (`t1<{}>` with 
>> no info about the type of the NTTP) should include some heuristic to judge 
>> "reasonably small objects" and choose a different rendering in that case?
>
> I don't think we necessarily have to do something about that from the start, 
> but it's probably a problem that is going to come up at some point.
> We are trying to render the whole structure of a class type in one line of 
> diagnostic, seems like this breaks new ground.
>
>> OK, I'm not sure what to make of this, though - "the expression that 
>> initializes the NTTP" is something we don't have, right? Just the value, I 
>> think, at this point? So we're trying to pick some kind of rendering for 
>> that value - is it just the outer type and then braces and values (Using the 
>> "bad"/difficult case of nested subobjects - `t1{{3}, {4}}`) or with nested 
>> types (`t1{t2{3}, t3{4]}`) or with member names (`t1{.v1 = {.v2 = 3}, .v3 = 
>> {.v4 = 4}}`) or both (`t1{.v1 = t2{.v2 = 3}, .v3 = t3{.v4 = 4}}`).
>>
>> I guess you meant the first, `t1{{3}, {4}}`? OK, so I think you're agreeing 
>> with what I would prefer/outlined in 
>> https://reviews.llvm.org/D134453#3871251 (which isn't where this review was 
>> going when @aaron.ballman roped you in, it was going towards fully explicit 
>> (`t1{t2{3}, t3{4}}`))
>
> I am a bit torn actually, something like `t1{.name = "Bar"}` does look better 
> ideally, but it's probably more prone to bad corner cases. Will probably not 
> work well for tuples.

I also think this form will get chatty in practice. It's not that uncommon for 
real world code to have quite a few members in a structure, so I could see 
`t1{.name = "Bar"}` being reasonable while `t1{.name = "Bar", .age = 183, 
.height = -12, .weight = 1.2f, .eye_color = Eyes::Chartreuse, .smell = 
Smells::LikeTeenSpirit }` being a far less reasonable thing to print. That 
said, we could perhaps have a cut point so we print with the member names if 
there's < N of them and print without member names otherwise. But I'm not 
certain it's worth it.

> The second option, `t1{{3}, {4}}`, looks more well-rounded.

I can live with this approach if folks think it's the better way to go. But my 
concern still remains that the user has no idea what's being constructed by 
`{3}` or `{4}` without tracking down which constructor of `t1` is being called. 
Because of overloads, `std::initializer_list`, and conversion operators (and 
the fact that C++ initialization rules are a bit of a disaster), I think this 
can be unobvious sometimes without including type names. That said, after 
playing around a bit, I think those times might involve more contorted code 
than others are worried about, and so maybe it's not worth worrying about those 
cases. The fact that Clang is the only C++ compiler that doesn't print full 
type information makes me wary though. My thinking is that it's always more 
frustrating to have not enough information in a diagnostic than too much 
information (both are problems in their own ways though).

> The fully explicit `t1{t2{3}, t3{4}}` option seems like it would be both less 
> readable and also even more prone to bad corner cases than the first (field 
> names) option.

I can understand it being less readable for deep nesting situations, but I do 
not see why it would be prone to bad corner cases -- it's the most explicit 
form we can write (and matches the behavior of all other C++ compilers, from 
what we can tell).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134453

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


[PATCH] D136668: [clang][dataflow] Add initial sign analysis

2022-10-26 Thread Gabor Marton via Phabricator via cfe-commits
martong marked 13 inline comments as done.
martong added a comment.

In D136668#3883241 , @ymandel wrote:

> Nice!!  Just nits.
>
> At a high level, I'm a little concerned about this as a demo, since I 
> wouldn't recommend this implementation in practice  (for various reasons, 
> e.g. I would encode with 2 booleans since there are only 3 values). But, I 
> think this approach has the advantage of clarity over optimized approaches. 
> It might be worth pointing this out in comments at places where you made a 
> decision for purposes of clarity/readability, if any come to mind.

Okay, thanks again for the review! I've changed the comments for the file, 
where I describe these reasons about using 3 booleans.




Comment at: clang/unittests/Analysis/FlowSensitive/SignAnalysisTest.cpp:183
+break;
+  case BO_NE: // Noop.
+break;

ymandel wrote:
> why not? its a test, so not necessary, just curious to know why you're 
> leaving this out.
This was my thought process: There is nothing that we can say about `b` if `a` 
is positive. Because `b` can still be either negative, positive, or even zero. 
Similar reasoning goes to the case when `a` is negative. 

However, we could have an implication if `a` is zero, namely that `b` is either 
positive or negative. But I think implications with `or` are not useful, they 
should be then rather expressed in the lattice. So, we should rather have a new 
boolean value like PosOrNeg, but I've found that too complicated for this demo.



Comment at: clang/unittests/Analysis/FlowSensitive/SignAnalysisTest.cpp:396
+
+// FIXME add this to testing support.
+template 

ymandel wrote:
> It doesn't appear to be used.
Yes, good catch, it's been left here for some older version of the 
implementation. I removed it now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136668

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


[PATCH] D136668: [clang][dataflow] Add initial sign analysis

2022-10-26 Thread Gabor Marton via Phabricator via cfe-commits
martong updated this revision to Diff 470796.
martong marked 2 inline comments as done.
martong added a comment.

- Address ymandel's comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136668

Files:
  clang/unittests/Analysis/FlowSensitive/CMakeLists.txt
  clang/unittests/Analysis/FlowSensitive/SignAnalysisTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/SignAnalysisTest.cpp
===
--- /dev/null
+++ clang/unittests/Analysis/FlowSensitive/SignAnalysisTest.cpp
@@ -0,0 +1,982 @@
+//===- unittests/Analysis/FlowSensitive/SignAnalysisTest.cpp --===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+//  This file defines a simplistic version of Sign Analysis as a demo of a
+//  forward, monotonic dataflow analysis. The implementation uses 3 boolean
+//  values to represent the sign lattice (negative, zero, positive). In
+//  practice, 2 booleans would be enough, however, this approach has the
+//  advantage of clarity over the optimized solution.
+//
+//===--===//
+
+#include "TestingSupport.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Analysis/FlowSensitive/CFGMatchSwitch.h"
+#include "clang/Analysis/FlowSensitive/DataflowAnalysis.h"
+#include "clang/Analysis/FlowSensitive/NoopLattice.h"
+#include "llvm/ADT/Optional.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Testing/Support/Annotations.h"
+#include "llvm/Testing/Support/Error.h"
+#include "gtest/gtest.h"
+#include 
+
+namespace {
+
+using namespace clang;
+using namespace dataflow;
+using namespace ast_matchers;
+using namespace test;
+using ::testing::UnorderedElementsAre;
+
+enum class Sign : int { Negative, Zero, Positive };
+
+Sign getSign(int64_t V) {
+  return V == 0 ? Sign::Zero : (V < 0 ? Sign::Negative : Sign::Positive);
+}
+
+using LatticeTransferState = TransferState;
+
+constexpr char kVar[] = "var";
+
+void initNegative(Value &Val, Environment &Env) {
+  Val.setProperty("neg", Env.getBoolLiteralValue(true));
+  Val.setProperty("zero", Env.getBoolLiteralValue(false));
+  Val.setProperty("pos", Env.getBoolLiteralValue(false));
+}
+void initPositive(Value &Val, Environment &Env) {
+  Val.setProperty("neg", Env.getBoolLiteralValue(false));
+  Val.setProperty("zero", Env.getBoolLiteralValue(false));
+  Val.setProperty("pos", Env.getBoolLiteralValue(true));
+}
+void initZero(Value &Val, Environment &Env) {
+  Val.setProperty("neg", Env.getBoolLiteralValue(false));
+  Val.setProperty("zero", Env.getBoolLiteralValue(true));
+  Val.setProperty("pos", Env.getBoolLiteralValue(false));
+}
+
+// The boolean properties that are associated to a Value. If a property is not
+// set then these are null pointers, otherwise, the pointed BoolValues are
+// owned by the Environment.
+struct SignProperties {
+  BoolValue *Neg, *Zero, *Pos;
+};
+void setSignProperties(Value &Val, const SignProperties &Ps) {
+  Val.setProperty("neg", *Ps.Neg);
+  Val.setProperty("zero", *Ps.Zero);
+  Val.setProperty("pos", *Ps.Pos);
+}
+SignProperties initUnknown(Value &Val, Environment &Env) {
+  SignProperties Ps{&Env.makeAtomicBoolValue(), &Env.makeAtomicBoolValue(),
+&Env.makeAtomicBoolValue()};
+  setSignProperties(Val, Ps);
+  return Ps;
+}
+SignProperties getSignProperties(const Value &Val, const Environment &Env) {
+  return {dyn_cast_or_null(Val.getProperty("neg")),
+  dyn_cast_or_null(Val.getProperty("zero")),
+  dyn_cast_or_null(Val.getProperty("pos"))};
+}
+
+void transferUninitializedInt(const DeclStmt *D,
+  const MatchFinder::MatchResult &M,
+  LatticeTransferState &State) {
+  const auto *Var = M.Nodes.getNodeAs(kVar);
+  assert(Var != nullptr);
+  const StorageLocation *Loc =
+  State.Env.getStorageLocation(*Var, SkipPast::None);
+  Value *Val = State.Env.getValue(*Loc);
+  initUnknown(*Val, State.Env);
+}
+
+// Get the Value (1), the properties for the operand (2), and the properties
+// for the unary operator (3). The return value is a tuple of (1,2,3).
+//
+// The returned Value (1) is a nullptr, if there is no Value associated to the
+// operand of the unary operator, or if the properties are not set for that
+// operand.
+// Other than that, new sign properties are created for the Value of the
+// unary operator and a new Value is created for the unary operator itself if
+// it hadn't have any previously.
+std::tuple
+getValueAndSignProperties(const UnaryOperator *UO,
+  const MatchFinder::MatchResult &M,
+ 

[PATCH] D134453: Disambiguate type names when printing NTTP types

2022-10-26 Thread Nenad Mikša via Phabricator via cfe-commits
DoDoENT added a comment.

> My thinking is that it's always more frustrating to have not enough 
> information in a diagnostic than too much information (both are problems in 
> their own ways though).
> ...
> I can understand it being less readable for deep nesting situations, but I do 
> not see why it would be prone to bad corner cases -- it's the most explicit 
> form we can write (and matches the behavior of all other C++ compilers, from 
> what we can tell).

I agree with @aaron.ballman. There is no ideal solution here, and I would too 
prefer to have too much information rather than not enough. GCC and MSVC are 
quite fine with printing full type names and it's up to IDE's and good editors 
and CI log parsers to parse that and present in a possibly better format.

If others would agree with that as well, I'll be happy to remove the policy 
from my PR completely and simply make clang print full explicit types always, 
just like GCC and MSVC do.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134453

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


[PATCH] D135097: Remove redundant option '-menable-unsafe-fp-math'.

2022-10-26 Thread Zahira Ammarguellat via Phabricator via cfe-commits
zahiraam added inline comments.



Comment at: clang/lib/CodeGen/CGCall.cpp:1865-1869
+if ((LangOpts.FastMath ||
+ !LangOpts.FastMath && LangOpts.AllowFPReassoc && LangOpts.AllowRecip 
&&
+ !LangOpts.FiniteMathOnly && LangOpts.NoSignedZero &&
+ LangOpts.ApproxFunc) &&
+LangOpts.getDefaultFPContractMode() != 
LangOptions::FPModeKind::FPM_Off)

michele.scandale wrote:
> michele.scandale wrote:
> > zahiraam wrote:
> > > michele.scandale wrote:
> > > > If I look at the clang driver code, `-funsafe-math-optimizations` is 
> > > > specified on the CC1 command line if
> > > > ```
> > > > !MathErrno && AssociativeMath && ReciprocalMath && !SignedZeros && 
> > > > ApproxFunc && !TrappingMath
> > > > ```
> > > > is true.
> > > > This means that it shouldn't matter the value of the floating point 
> > > > contraction, or whether infs/nans are honored or not.
> > > > 
> > > > Was there another issue that this specific part of the change addresses?
> > > This is to make sure that if we are using -ffast-math or 
> > > -funsafe-math-optimization along with -ffp-contract=off, fma instructions 
> > > are not generated.  In this case the function shouldn't be marked with 
> > > the unsafe-fp-math attribute.
> > > This is to make sure that if we are using -ffast-math or 
> > > -funsafe-math-optimization along with -ffp-contract=off, fma instructions 
> > > are not generated.  In this case the function shouldn't be marked with 
> > > the unsafe-fp-math attribute.
> > 
> > If I understand correctly this is because the function attribute 
> > `unsafe-fp-math` from backends perspective allow any kind of contraction?
> > If so, shouldn't then this be valid only when the fp-contraction mode is 
> > `fast`, given that `on` means that only in-statement contraction is 
> > allowed, and clang handles that by generating `llvm.fmuladd` to lower 
> > expressions like `a * b + c` in given statement?
> > 
> > What about the `!LangOpts.FiniteMathOnly` part? I'd would think this 
> > shouldn't be checked at all as there are separate function attributes for 
> > infs and nans.
> > This is to make sure that if we are using -ffast-math or 
> > -funsafe-math-optimization along with -ffp-contract=off, fma instructions 
> > are not generated.  In this case the function shouldn't be marked with the 
> > unsafe-fp-math attribute.
> 
> 
> > This is to make sure that if we are using -ffast-math or 
> > -funsafe-math-optimization along with -ffp-contract=off, fma instructions 
> > are not generated.  In this case the function shouldn't be marked with the 
> > unsafe-fp-math attribute.
> 
> If I understand correctly this is because the function attribute 
> `unsafe-fp-math` from backends perspective allow any kind of contraction?
That's correct.

> If so, shouldn't then this be valid only when the fp-contraction mode is 
> `fast`, given that `on` means that only in-statement contraction is allowed, 
> and clang handles that by generating `llvm.fmuladd` to lower expressions like 
> `a * b + c` in given statement?
> 
> What about the `!LangOpts.FiniteMathOnly` part? I'd would think this 
> shouldn't be checked at all as there are separate function attributes for 
> infs and nans.

when ffp-contract=on is used with no safe optimizations along with it, the 
attribute unsafe-fp-math is not set but tryEmitMulAdd will return an FMulAdd. 
Please keep in mind that this logic hasn't really changed. The only thing that 
was done was to explicitly expand the operations of unsafe optimizations in the 
original condition.




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135097

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


[clang] 93ce23a - [clang][dataflow] Add initial sign analysis

2022-10-26 Thread Gabor Marton via cfe-commits

Author: Gabor Marton
Date: 2022-10-26T15:13:22+02:00
New Revision: 93ce23adb548240f3907e7dc0690a82cce060a96

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

LOG: [clang][dataflow] Add initial sign analysis

This patch adds an initial implementation for sign analysis, with the
following lattice (T: top, N: negative, Z: zero, P: positive, B: bottom):
  T
/ | \
N Z P
\ | /
  B
The lattice is implemented with `BoolValue` properties attached to other
`Value`s.

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

Added: 
clang/unittests/Analysis/FlowSensitive/SignAnalysisTest.cpp

Modified: 
clang/unittests/Analysis/FlowSensitive/CMakeLists.txt

Removed: 




diff  --git a/clang/unittests/Analysis/FlowSensitive/CMakeLists.txt 
b/clang/unittests/Analysis/FlowSensitive/CMakeLists.txt
index 0ab80440ce7d9..434d71ca11e79 100644
--- a/clang/unittests/Analysis/FlowSensitive/CMakeLists.txt
+++ b/clang/unittests/Analysis/FlowSensitive/CMakeLists.txt
@@ -12,12 +12,13 @@ add_clang_unittest(ClangAnalysisFlowSensitiveTests
   MapLatticeTest.cpp
   MatchSwitchTest.cpp
   MultiVarConstantPropagationTest.cpp
+  SignAnalysisTest.cpp
   SingleVarConstantPropagationTest.cpp
+  SolverTest.cpp
   TestingSupport.cpp
   TestingSupportTest.cpp
   TransferTest.cpp
   TypeErasedDataflowAnalysisTest.cpp
-  SolverTest.cpp
   UncheckedOptionalAccessModelTest.cpp
   ValueTest.cpp
   )

diff  --git a/clang/unittests/Analysis/FlowSensitive/SignAnalysisTest.cpp 
b/clang/unittests/Analysis/FlowSensitive/SignAnalysisTest.cpp
new file mode 100644
index 0..8eb9cf9ccc3bd
--- /dev/null
+++ b/clang/unittests/Analysis/FlowSensitive/SignAnalysisTest.cpp
@@ -0,0 +1,982 @@
+//===- unittests/Analysis/FlowSensitive/SignAnalysisTest.cpp --===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+//  This file defines a simplistic version of Sign Analysis as a demo of a
+//  forward, monotonic dataflow analysis. The implementation uses 3 boolean
+//  values to represent the sign lattice (negative, zero, positive). In
+//  practice, 2 booleans would be enough, however, this approach has the
+//  advantage of clarity over the optimized solution.
+//
+//===--===//
+
+#include "TestingSupport.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Analysis/FlowSensitive/CFGMatchSwitch.h"
+#include "clang/Analysis/FlowSensitive/DataflowAnalysis.h"
+#include "clang/Analysis/FlowSensitive/NoopLattice.h"
+#include "llvm/ADT/Optional.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Testing/Support/Annotations.h"
+#include "llvm/Testing/Support/Error.h"
+#include "gtest/gtest.h"
+#include 
+
+namespace {
+
+using namespace clang;
+using namespace dataflow;
+using namespace ast_matchers;
+using namespace test;
+using ::testing::UnorderedElementsAre;
+
+enum class Sign : int { Negative, Zero, Positive };
+
+Sign getSign(int64_t V) {
+  return V == 0 ? Sign::Zero : (V < 0 ? Sign::Negative : Sign::Positive);
+}
+
+using LatticeTransferState = TransferState;
+
+constexpr char kVar[] = "var";
+
+void initNegative(Value &Val, Environment &Env) {
+  Val.setProperty("neg", Env.getBoolLiteralValue(true));
+  Val.setProperty("zero", Env.getBoolLiteralValue(false));
+  Val.setProperty("pos", Env.getBoolLiteralValue(false));
+}
+void initPositive(Value &Val, Environment &Env) {
+  Val.setProperty("neg", Env.getBoolLiteralValue(false));
+  Val.setProperty("zero", Env.getBoolLiteralValue(false));
+  Val.setProperty("pos", Env.getBoolLiteralValue(true));
+}
+void initZero(Value &Val, Environment &Env) {
+  Val.setProperty("neg", Env.getBoolLiteralValue(false));
+  Val.setProperty("zero", Env.getBoolLiteralValue(true));
+  Val.setProperty("pos", Env.getBoolLiteralValue(false));
+}
+
+// The boolean properties that are associated to a Value. If a property is not
+// set then these are null pointers, otherwise, the pointed BoolValues are
+// owned by the Environment.
+struct SignProperties {
+  BoolValue *Neg, *Zero, *Pos;
+};
+void setSignProperties(Value &Val, const SignProperties &Ps) {
+  Val.setProperty("neg", *Ps.Neg);
+  Val.setProperty("zero", *Ps.Zero);
+  Val.setProperty("pos", *Ps.Pos);
+}
+SignProperties initUnknown(Value &Val, Environment &Env) {
+  SignProperties Ps{&Env.makeAtomicBoolValue(), &Env.makeAtomicBoolValue(),
+&Env.makeAtomicBoolValue()};
+  setSignProperties(Val, Ps);
+  return Ps;
+}
+SignProperties getSignProperties(const Valu

[PATCH] D136668: [clang][dataflow] Add initial sign analysis

2022-10-26 Thread Gabor Marton 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 rG93ce23adb548: [clang][dataflow] Add initial sign analysis 
(authored by martong).

Changed prior to commit:
  https://reviews.llvm.org/D136668?vs=470796&id=470801#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136668

Files:
  clang/unittests/Analysis/FlowSensitive/CMakeLists.txt
  clang/unittests/Analysis/FlowSensitive/SignAnalysisTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/SignAnalysisTest.cpp
===
--- /dev/null
+++ clang/unittests/Analysis/FlowSensitive/SignAnalysisTest.cpp
@@ -0,0 +1,982 @@
+//===- unittests/Analysis/FlowSensitive/SignAnalysisTest.cpp --===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+//  This file defines a simplistic version of Sign Analysis as a demo of a
+//  forward, monotonic dataflow analysis. The implementation uses 3 boolean
+//  values to represent the sign lattice (negative, zero, positive). In
+//  practice, 2 booleans would be enough, however, this approach has the
+//  advantage of clarity over the optimized solution.
+//
+//===--===//
+
+#include "TestingSupport.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Analysis/FlowSensitive/CFGMatchSwitch.h"
+#include "clang/Analysis/FlowSensitive/DataflowAnalysis.h"
+#include "clang/Analysis/FlowSensitive/NoopLattice.h"
+#include "llvm/ADT/Optional.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Testing/Support/Annotations.h"
+#include "llvm/Testing/Support/Error.h"
+#include "gtest/gtest.h"
+#include 
+
+namespace {
+
+using namespace clang;
+using namespace dataflow;
+using namespace ast_matchers;
+using namespace test;
+using ::testing::UnorderedElementsAre;
+
+enum class Sign : int { Negative, Zero, Positive };
+
+Sign getSign(int64_t V) {
+  return V == 0 ? Sign::Zero : (V < 0 ? Sign::Negative : Sign::Positive);
+}
+
+using LatticeTransferState = TransferState;
+
+constexpr char kVar[] = "var";
+
+void initNegative(Value &Val, Environment &Env) {
+  Val.setProperty("neg", Env.getBoolLiteralValue(true));
+  Val.setProperty("zero", Env.getBoolLiteralValue(false));
+  Val.setProperty("pos", Env.getBoolLiteralValue(false));
+}
+void initPositive(Value &Val, Environment &Env) {
+  Val.setProperty("neg", Env.getBoolLiteralValue(false));
+  Val.setProperty("zero", Env.getBoolLiteralValue(false));
+  Val.setProperty("pos", Env.getBoolLiteralValue(true));
+}
+void initZero(Value &Val, Environment &Env) {
+  Val.setProperty("neg", Env.getBoolLiteralValue(false));
+  Val.setProperty("zero", Env.getBoolLiteralValue(true));
+  Val.setProperty("pos", Env.getBoolLiteralValue(false));
+}
+
+// The boolean properties that are associated to a Value. If a property is not
+// set then these are null pointers, otherwise, the pointed BoolValues are
+// owned by the Environment.
+struct SignProperties {
+  BoolValue *Neg, *Zero, *Pos;
+};
+void setSignProperties(Value &Val, const SignProperties &Ps) {
+  Val.setProperty("neg", *Ps.Neg);
+  Val.setProperty("zero", *Ps.Zero);
+  Val.setProperty("pos", *Ps.Pos);
+}
+SignProperties initUnknown(Value &Val, Environment &Env) {
+  SignProperties Ps{&Env.makeAtomicBoolValue(), &Env.makeAtomicBoolValue(),
+&Env.makeAtomicBoolValue()};
+  setSignProperties(Val, Ps);
+  return Ps;
+}
+SignProperties getSignProperties(const Value &Val, const Environment &Env) {
+  return {dyn_cast_or_null(Val.getProperty("neg")),
+  dyn_cast_or_null(Val.getProperty("zero")),
+  dyn_cast_or_null(Val.getProperty("pos"))};
+}
+
+void transferUninitializedInt(const DeclStmt *D,
+  const MatchFinder::MatchResult &M,
+  LatticeTransferState &State) {
+  const auto *Var = M.Nodes.getNodeAs(kVar);
+  assert(Var != nullptr);
+  const StorageLocation *Loc =
+  State.Env.getStorageLocation(*Var, SkipPast::None);
+  Value *Val = State.Env.getValue(*Loc);
+  initUnknown(*Val, State.Env);
+}
+
+// Get the Value (1), the properties for the operand (2), and the properties
+// for the unary operator (3). The return value is a tuple of (1,2,3).
+//
+// The returned Value (1) is a nullptr, if there is no Value associated to the
+// operand of the unary operator, or if the properties are not set for that
+// operand.
+// Other than that, new sign properties are created for the Value of the
+// unary operator and a new Value is created for the unary operator i

[PATCH] D134128: [P0857R0 Part B] Resubmit an implemention for constrained template template parameters

2022-10-26 Thread Liming Liu via Phabricator via cfe-commits
lime updated this revision to Diff 470800.
lime retitled this revision from "Resubmit an implemention for constrained 
template template parameters [P0857R0 Part B]" to "[P0857R0 Part B] Resubmit an 
implemention for constrained template template parameters".
lime added a comment.

Update release notes as required.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134128

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Sema/Sema.h
  clang/lib/Parse/ParseTemplate.cpp
  clang/lib/Sema/SemaConcept.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/test/CXX/temp/temp.arg/temp.arg.template/p3-2a.cpp
  clang/test/SemaTemplate/concepts.cpp
  clang/www/cxx_status.html
  libcxx/DELETE.ME

Index: libcxx/DELETE.ME
===
--- /dev/null
+++ libcxx/DELETE.ME
@@ -0,0 +1 @@
+D134128
Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -912,11 +912,7 @@
 

 https://wg21.link/p0857r0";>P0857R0
-
-  Partial
-Constraining template template parameters is not yet supported.
-  
-
+Clang 16
   

 https://wg21.link/p1084r2";>P1084R2
Index: clang/test/SemaTemplate/concepts.cpp
===
--- clang/test/SemaTemplate/concepts.cpp
+++ clang/test/SemaTemplate/concepts.cpp
@@ -61,9 +61,9 @@
 
   // FIXME: This is valid under P0857R0.
   template concept C = true;
-  template requires C typename U> struct X {}; // expected-error {{requires 'class'}} expected-error 0+{{}}
+  template requires C typename U> struct X {};
   template requires C struct Y {};
-  X xy; // expected-error {{no template named 'X'}}
+  X xy;
 }
 
 namespace PR50306 {
Index: clang/test/CXX/temp/temp.arg/temp.arg.template/p3-2a.cpp
===
--- clang/test/CXX/temp/temp.arg/temp.arg.template/p3-2a.cpp
+++ clang/test/CXX/temp/temp.arg/temp.arg.template/p3-2a.cpp
@@ -1,22 +1,27 @@
 // RUN:  %clang_cc1 -std=c++2a -frelaxed-template-template-args -verify %s
 
-template concept C = T::f();
-// expected-note@-1{{similar constraint}}
+template concept C = T::f(); // #C
 template concept D = C && T::g();
-template concept F = T::f();
-// expected-note@-1{{similar constraint expressions not considered equivalent}}
-template class P> struct S1 { }; // expected-note 2{{'P' declared here}}
+template concept F = T::f(); // #F
+template class P> struct S1 { }; // #S1
 
 template struct X { };
 
-template struct Y { }; // expected-note{{'Y' declared here}}
+template struct Y { }; // #Y
 template struct Z { };
-template struct W { }; // expected-note{{'W' declared here}}
-
+template struct W { }; // #W
 S1 s11;
-S1 s12; // expected-error{{template template argument 'Y' is more constrained than template template parameter 'P'}}
+S1 s12;
+// expected-error@-1 {{template template argument 'Y' is more constrained than template template parameter 'P'}}
+// expected-note@#S1 {{'P' declared here}}
+// expected-note@#Y {{'Y' declared here}}
 S1 s13;
-S1 s14; // expected-error{{template template argument 'W' is more constrained than template template parameter 'P'}}
+S1 s14;
+// expected-error@-1 {{template template argument 'W' is more constrained than template template parameter 'P'}}
+// expected-note@#S1 {{'P' declared here}}
+// expected-note@#W {{'W' declared here}}
+// expected-note@#F 1-2{{similar constraint expressions not considered equivalent}}
+// expected-note@#C 1-2{{similar constraint}}
 
 template class P> struct S2 { };
 
@@ -32,3 +37,25 @@
 
 using s31 = S3;
 using s32 = S3;
+
+template requires C class P> struct S4 { }; // #S4
+
+S4 s41;
+S4 s42;
+// expected-error@-1 {{template template argument 'Y' is more constrained than template template parameter 'P'}}
+// expected-note@#S4 {{'P' declared here}}
+// expected-note@#Y {{'Y' declared here}}
+S4 s43;
+S4 s44;
+// expected-error@-1 {{template template argument 'W' is more constrained than template template parameter 'P'}}
+// expected-note@#S4 {{'P' declared here}}
+// expected-note@#W {{'W' declared here}}
+
+template requires C typename U> struct S5 {
+  template static U V;
+};
+
+struct Nothing {};
+
+// FIXME: Wait the standard to clarify the intent.
+template<> template<> Z S5::V;
Index: clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -4098,8 +4098,10 @@
 
 TemplateParameterList *
 Sema::SubstTemplateParams(TemplateParameterList *Params, DeclContext *Owner,
-  

[PATCH] D134128: [P0857R0 Part B] Resubmit an implemention for constrained template template parameters

2022-10-26 Thread Erich Keane via Phabricator via cfe-commits
erichkeane accepted this revision.
erichkeane added a comment.

I'm happy with this once the release-note is clarified and all libcxx 
pre-commit works with it.




Comment at: clang/docs/ReleaseNotes.rst:554
+- Implemented `P0857R0 
`_,
+  which words for constrained lambdas and constrained template 
*template-parameter*\s.
 

I'm not sure what you're trying to say here?  Is there just a typo that I'm 
missing that makes this perfectly clear? 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134128

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


[PATCH] D134128: [P0857R0 Part B] Resubmit an implemention for constrained template template parameters

2022-10-26 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

ALSO: When you commit this: please try to use a more descriptive commit 
message, more similar to what I posted in Phab originally.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134128

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


[PATCH] D134453: Disambiguate type names when printing NTTP types

2022-10-26 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added a comment.

In D134453#3885423 , @aaron.ballman 
wrote:

> I can live with this approach if folks think it's the better way to go. But 
> my concern still remains that the user has no idea what's being constructed 
> by `{3}` or `{4}` without tracking down which constructor of `t1` is being 
> called. Because of overloads, `std::initializer_list`, and conversion 
> operators (and the fact that C++ initialization rules are a bit of a 
> disaster), I think this can be unobvious sometimes without including type 
> names. That said, after playing around a bit, I think those times might 
> involve more contorted code than others are worried about, and so maybe it's 
> not worth worrying about those cases. The fact that Clang is the only C++ 
> compiler that doesn't print full type information makes me wary though. My 
> thinking is that it's always more frustrating to have not enough information 
> in a diagnostic than too much information (both are problems in their own 
> ways though).

I think the problem here is that since we don't have the as-written argument, 
we just have the converted argument which is an APValue with the state of the 
object.
I don't think we can in general, starting from the state, figure out which 
constructor would produce that state.

So we might print it with a syntax as if the class was a simple pod type, even 
though that might produce a completely different result if used in practice.
I don't think we can do much better without having the actual expression used.

That might be a point in favor of the designated-initializer style with the 
field names, that should never produce the wrong result if copy-pasted back to 
code.

> I can understand it being less readable for deep nesting situations, but I do 
> not see why it would be prone to bad corner cases -- it's the most explicit 
> form we can write (and matches the behavior of all other C++ compilers, from 
> what we can tell).

The types of the fields might be internal, or otherwise too distant from user 
code.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134453

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


[PATCH] D133698: [clang][dataflow] Implement transferBranch

2022-10-26 Thread Gabor Marton via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
martong marked an inline comment as done.
Closed by commit rGbb72d0dde29e: [clang][dataflow] Implement transferBranch 
(authored by martong).

Changed prior to commit:
  https://reviews.llvm.org/D133698?vs=470748&id=470802#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133698

Files:
  clang/include/clang/Analysis/FlowSensitive/DataflowAnalysis.h
  clang/include/clang/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.h
  clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
  clang/unittests/Analysis/FlowSensitive/CMakeLists.txt
  clang/unittests/Analysis/FlowSensitive/TestingSupport.h
  clang/unittests/Analysis/FlowSensitive/TransferBranchTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/TransferBranchTest.cpp
===
--- /dev/null
+++ clang/unittests/Analysis/FlowSensitive/TransferBranchTest.cpp
@@ -0,0 +1,114 @@
+//===- unittests/Analysis/FlowSensitive/SignAnalysisTest.cpp --===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+//  This file defines a test for the transferBranch function of the
+//  TypeErasedDataflowAnalysis.
+//
+//===--===//
+
+#include "TestingSupport.h"
+#include "clang/Analysis/FlowSensitive/DataflowAnalysis.h"
+#include "clang/Tooling/Tooling.h"
+#include "llvm/ADT/Optional.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Testing/Support/Annotations.h"
+#include "llvm/Testing/Support/Error.h"
+#include "gtest/gtest.h"
+
+namespace clang::dataflow::test {
+namespace {
+
+using namespace ast_matchers;
+
+struct TestLattice {
+  llvm::Optional Branch;
+  static TestLattice bottom() { return {}; }
+
+  // Does not matter for this test, but we must provide some definition of join.
+  LatticeJoinEffect join(const TestLattice &Other) {
+return LatticeJoinEffect::Unchanged;
+  }
+  friend bool operator==(const TestLattice &Lhs, const TestLattice &Rhs) {
+return Lhs.Branch == Rhs.Branch;
+  }
+};
+
+class TestPropagationAnalysis
+: public DataflowAnalysis {
+public:
+  explicit TestPropagationAnalysis(ASTContext &Context)
+  : DataflowAnalysis(Context) {}
+  static TestLattice initialElement() { return TestLattice::bottom(); }
+  void transfer(const CFGElement *, TestLattice &, Environment &) {}
+  void transferBranch(bool Branch, const Stmt *S, TestLattice &L,
+  Environment &Env) {
+L.Branch = Branch;
+  }
+};
+
+using ::testing::UnorderedElementsAre;
+
+template 
+void runDataflow(llvm::StringRef Code, Matcher VerifyResults,
+ LangStandard::Kind Std = LangStandard::lang_cxx17,
+ llvm::StringRef TargetFun = "fun") {
+  using ast_matchers::hasName;
+  ASSERT_THAT_ERROR(
+  checkDataflow(
+  AnalysisInputs(
+  Code, hasName(TargetFun),
+  [](ASTContext &C, Environment &) {
+return TestPropagationAnalysis(C);
+  })
+  .withASTBuildArgs(
+  {"-fsyntax-only", "-fno-delayed-template-parsing",
+   "-std=" +
+   std::string(LangStandard::getLangStandardForKind(Std)
+   .getName())}),
+  VerifyResults),
+  llvm::Succeeded());
+}
+
+template 
+const LatticeT &getLatticeAtAnnotation(
+const llvm::StringMap> &AnnotationStates,
+llvm::StringRef Annotation) {
+  auto It = AnnotationStates.find(Annotation);
+  assert(It != AnnotationStates.end());
+  return It->getValue().Lattice;
+}
+
+TEST(TransferBranchTest, IfElse) {
+  std::string Code = R"(
+void fun(int a) {
+  if (a > 0) {
+(void)1;
+// [[p]]
+  } else {
+(void)0;
+// [[q]]
+  }
+}
+  )";
+  runDataflow(
+  Code,
+  [](const llvm::StringMap> &Results,
+ const AnalysisOutputs &) {
+ASSERT_THAT(Results.keys(), UnorderedElementsAre("p", "q"));
+
+const TestLattice &LP = getLatticeAtAnnotation(Results, "p");
+EXPECT_THAT(LP.Branch, Optional(true));
+
+const TestLattice &LQ = getLatticeAtAnnotation(Results, "q");
+EXPECT_THAT(LQ.Branch, Optional(false));
+  },
+  LangStandard::lang_cxx17);
+}
+
+} // namespace
+} // namespace clang::dataflow::test
Index: clang/unittests/Analysis/FlowSensitive/TestingSupport.h
===
--- clang/unittests/Analysis/FlowSensitive/TestingSupport.h
+++ clang/unittests/Analysis/FlowSensitive/TestingSupport.h
@@ -344,6 +344,7 @@
 llvm::any_

[clang] bb72d0d - [clang][dataflow] Implement transferBranch

2022-10-26 Thread Gabor Marton via cfe-commits

Author: Gabor Marton
Date: 2022-10-26T15:24:55+02:00
New Revision: bb72d0dde29edc2f240ab3d3650544251795ef9f

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

LOG: [clang][dataflow] Implement transferBranch

This patch introduces `transferBranch`, which Applies the analysis
transfer function for a given edge from a CFG block of a conditional
statement.

RFC:
https://discourse.llvm.org/t/rfc-clang-dataflow-signanalysis-edgetransfer-branchtransfer/65220

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

Added: 
clang/unittests/Analysis/FlowSensitive/TransferBranchTest.cpp

Modified: 
clang/include/clang/Analysis/FlowSensitive/DataflowAnalysis.h
clang/include/clang/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.h
clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
clang/unittests/Analysis/FlowSensitive/CMakeLists.txt
clang/unittests/Analysis/FlowSensitive/TestingSupport.h

Removed: 




diff  --git a/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysis.h 
b/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysis.h
index 6184f22f786c7..52844302b8532 100644
--- a/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysis.h
+++ b/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysis.h
@@ -32,6 +32,16 @@
 namespace clang {
 namespace dataflow {
 
+template >
+struct HasTransferBranchFor : std::false_type {};
+
+template 
+struct HasTransferBranchFor<
+AnalysisT, LatticeT,
+std::void_t().transferBranch(
+std::declval(), std::declval(),
+std::declval(), std::declval()))>>
+: std::true_type {};
 /// Base class template for dataflow analyses built on a single lattice type.
 ///
 /// Requirements:
@@ -101,6 +111,17 @@ class DataflowAnalysis : public TypeErasedDataflowAnalysis 
{
 static_cast(this)->transfer(Element, L, Env);
   }
 
+  void transferBranchTypeErased(bool Branch, const Stmt *Stmt,
+TypeErasedLattice &E, Environment &Env) final {
+if constexpr (HasTransferBranchFor::value) {
+  Lattice &L = llvm::any_cast(E.Value);
+  static_cast(this)->transferBranch(Branch, Stmt, L, Env);
+}
+// Silence unused parameter warnings.
+(void)Branch;
+(void)Stmt;
+  }
+
 private:
   ASTContext &Context;
 };

diff  --git 
a/clang/include/clang/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.h 
b/clang/include/clang/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.h
index c7dccc36a6a2f..fe8b431ef1579 100644
--- a/clang/include/clang/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.h
+++ b/clang/include/clang/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.h
@@ -84,6 +84,14 @@ class TypeErasedDataflowAnalysis : public 
Environment::ValueModel {
   virtual void transferTypeErased(const CFGElement *, TypeErasedLattice &,
   Environment &) = 0;
 
+  /// Applies the analysis transfer function for a given edge from a CFG block
+  /// of a conditional statement.
+  /// @param Stmt The condition which is responsible for the split in the CFG.
+  /// @param Branch True if the edge goes to the basic block where the
+  /// condition is true.
+  virtual void transferBranchTypeErased(bool Branch, const Stmt *,
+TypeErasedLattice &, Environment &) = 
0;
+
   /// If the built-in transfer functions (which model the heap and stack in the
   /// `Environment`) are to be applied, returns the options to be passed to
   /// them. Otherwise returns empty.

diff  --git a/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp 
b/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
index b85a72a8a7b71..ec6a8a3d2e525 100644
--- a/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
+++ b/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
@@ -69,54 +69,64 @@ static int blockIndexInPredecessor(const CFGBlock &Pred,
   return BlockPos - Pred.succ_begin();
 }
 
+// The return type of the visit functions in TerminatorVisitor. The first
+// element represents the terminator expression (that is the conditional
+// expression in case of a path split in the CFG). The second element
+// represents whether the condition was true or false.
+using TerminatorVisitorRetTy = std::pair;
+
 /// Extends the flow condition of an environment based on a terminator
 /// statement.
-class TerminatorVisitor : public ConstStmtVisitor {
+class TerminatorVisitor
+: public ConstStmtVisitor {
 public:
-  TerminatorVisitor(const StmtToEnvMap &StmtToEnv, Environment &Env,
+  TerminatorVisitor(TypeErasedDataflowAnalysis &Analysis,
+const StmtToEnvMap &StmtToEnv, Environment &Env,
 int BlockSuccIdx, TransferOptions TransferOpts)
-  : StmtToEnv(Stmt

[PATCH] D133698: [clang][dataflow] Implement transferBranch

2022-10-26 Thread Gabor Marton via Phabricator via cfe-commits
martong added inline comments.



Comment at: clang/unittests/Analysis/FlowSensitive/TransferBranchTest.cpp:73
+   .getName())}),
+  /*VerifyResults=*/Match),
+  llvm::Succeeded());

ymandel wrote:
> nit: maybe just rename the parameter to `VerifyResults` (and then no need for 
> the comment)?
Good idea, I've renamed it within the commit.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133698

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


[PATCH] D135360: [clang][analyzer] Add some more functions to StreamChecker and StdLibraryFunctionsChecker.

2022-10-26 Thread Balázs Kéri via Phabricator via cfe-commits
balazske added a comment.

If we look only at the C standard we can not tell much about if the functions 
should set `errno`. It seems that setting `errno` is totally 
implementation-dependent, except for a few functions that mention `errno`. 
These are `fgetpos`, `fsetpos`, `ftell` and should set `errno` to a positive 
value on error (but there is no guarantee that value of `errno` is preserved if 
no error occurs). And `errno` is always positive. This is different than what 
the checker currently does (with the new patches). Probably this should be a 
discourse question?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135360

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


[PATCH] D136684: [clang][ASTImporter] Remove use of ParentMapContext.

2022-10-26 Thread Gabor Marton via Phabricator via cfe-commits
martong added a comment.

In D136684#3884983 , @balazske wrote:

> This is really a NFC-like change but not NFC because it has visible effects 
> of removing some crashes. I could not produce a test that provokes the wrong 
> case (when `getParents` returns an empty list). Is it enough to have no new 
> test here? If we can get a test for the crash it needs more investigation to 
> check if `RecursiveASTVisitor` works correct and probably a fix at other 
> place.

In my opinion, this case a very rare case when the change is justified even 
without the tests. Of course, it would be better if you had a test that is a 
minimal reproducer for the crash you are talking about. But, since you remove a 
sub-optimal infrastructural element, that is the parent map, which relies on 
the mentioned `RecursiveASTVisitor`, I don't think that we need to hunt down 
bugs for those components that you just dumped out from the ASTImporter code.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136684

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


[PATCH] D136568: [Clang] Support constexpr builtin ilogb

2022-10-26 Thread Evgeny Shulgin via Phabricator via cfe-commits
Izaron added inline comments.



Comment at: clang/lib/AST/ExprConstant.cpp:12452
+int Ilogb;
+if (APFloat::opStatus St = ilogb(F, Ilogb); !isConstantOpStatus(St))
+  return false;

aaron.ballman wrote:
> jcranmer-intel wrote:
> > `long double` is `ppc_fp128` on at least some PPC targets, and while I'm 
> > not entirely certain of what `ilogb` properly returns in the corner cases 
> > of the `ppc_fp128`, I'm not entirely confident that the implementation of 
> > `APFloat` is correct in those cases. I'd like someone with PPC background 
> > to comment in here.
> Paging @hubert.reinterpretcast for help finding a good person to comment on 
> the PPC questions.
@jcranmer-intel constexpr evaluation is quite machine-/target-independent. 
Clang evaluates it based on its **internal** representation of float variables.

[[ 
https://github.com/llvm/llvm-project/blob/2e5bf4da99a2f8d3d4bb4f1a4d1ed968a01e8f02/llvm/include/llvm/ADT/APFloat.h#L1256
 | int ilogb ]] uses `Arg.getIEEE()`, that [[ 
https://github.com/llvm/llvm-project/blob/2e5bf4da99a2f8d3d4bb4f1a4d1ed968a01e8f02/llvm/include/llvm/ADT/APFloat.h#L819-L825
 | returns Clang's internal float representation ]].

Whichever float semantics is being used, [[ 
https://github.com/llvm/llvm-project/blob/2e5bf4da99a2f8d3d4bb4f1a4d1ed968a01e8f02/llvm/lib/Support/APFloat.cpp#L54-L61
 | minExponent and maxExponent are representable as APFloatBase::ExponentType 
]], which is `int32_t`:
```
/// A signed type to represent a floating point numbers unbiased exponent.
typedef int32_t ExponentType;
```

We already use `int ilogb` in some constexpr evaluation code: [[ 
https://github.com/llvm/llvm-project/blob/2e5bf4da99a2f8d3d4bb4f1a4d1ed968a01e8f02/clang/lib/AST/ExprConstant.cpp#L14592
 | link ]], it is working correct because it is working on Clang's float 
representations.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136568

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


[PATCH] D135360: [clang][analyzer] Add some more functions to StreamChecker and StdLibraryFunctionsChecker.

2022-10-26 Thread Gabor Marton via Phabricator via cfe-commits
martong added a comment.

In D135360#3885494 , @balazske wrote:

> If we look only at the C standard we can not tell much about if the functions 
> should set `errno`. It seems that setting `errno` is totally 
> implementation-dependent, except for a few functions that mention `errno`. 
> These are `fgetpos`, `fsetpos`, `ftell` and should set `errno` to a positive 
> value on error (but there is no guarantee that value of `errno` is preserved 
> if no error occurs). And `errno` is always positive. This is different than 
> what the checker currently does (with the new patches). Probably this should 
> be a discourse question?

Okay then, I think it is worth to have a discourse question. But you could ask 
the wider "Clang" community, so I would not post the question as something that 
is related strictly to the static analyzer.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135360

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


[PATCH] D136080: [flang] Add -ffp-contract option processing

2022-10-26 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski added a comment.

Added Clang reviewers who touched the definition of `--fp-contract` most 
recently. Mostly for visibility, but lets give them at least a couple of days 
to take a look at the changes in Options.td.


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

https://reviews.llvm.org/D136080

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


[PATCH] D126903: [clang] Add support for __builtin_memset_inline

2022-10-26 Thread Guillaume Chatelet via Phabricator via cfe-commits
gchatelet added a comment.

In D126903#3885269 , @aganea wrote:

> In D126903#3885114 , @gchatelet 
> wrote:
>
>> It should be fixed now @aganea . Can you check?
>
> Works now, thanks again for the quick response. Should D136752 
>  be cherry-picked into the 15.0 branch?

Yes done here : https://github.com/llvm/llvm-project/issues/58627


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126903

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


[PATCH] D136554: [WIP] Implement CWG2631

2022-10-26 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 470808.
cor3ntin added a comment.

Cleanup, add comments and tests.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136554

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/ExprCXX.h
  clang/include/clang/AST/Stmt.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/ExprCXX.cpp
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTReaderStmt.cpp
  clang/lib/Serialization/ASTWriterStmt.cpp
  clang/test/CXX/class/class.local/p1-0x.cpp
  clang/test/CodeGenCXX/default-arguments-with-immediate.cpp
  clang/test/PCH/default-argument-with-immediate-calls.cpp
  clang/test/SemaCXX/cxx2a-consteval-default-params.cpp

Index: clang/test/SemaCXX/cxx2a-consteval-default-params.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/cxx2a-consteval-default-params.cpp
@@ -0,0 +1,52 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++2b %s
+
+
+consteval int undefined();  // expected-note 4{{declared here}}
+
+void check_lambdas_unused(
+int a = []
+{
+return undefined();  // expected-error {{not a constant expression}} \
+ // expected-note  {{undefined function 'undefined'}}
+}(),
+int b = [](int no_error = undefined()) {
+return no_error;
+}(0),
+int c = [](int defaulted = undefined()) {
+return defaulted;
+}()
+) {}
+
+int check_lambdas_used(
+int b = [](int no_error = undefined()) {
+return no_error;
+}(0),
+int c = [](int defaulted = undefined()) { // expected-error {{not a constant expression}} \
+  // expected-note  {{declared here}} \
+  // expected-note  {{undefined function 'undefined'}}
+return defaulted;
+}()  // expected-note {{in the default initalizer of 'defaulted'}}
+) {
+return 0;
+}
+
+int test_check_lambdas_used = check_lambdas_used();
+
+struct UnusedInitWithLambda {
+int a = [] {
+return undefined();  // expected-error {{not a constant expression}} \
+ // expected-note  {{undefined function 'undefined'}}
+}();
+int b = [](int no_error = undefined()) {
+return no_error;
+}();
+};
+
+struct InitWithLambda {
+int b = [](int error = undefined()) { // expected-error {{not a constant expression}} \
+  // expected-note  {{declared here}} \
+  // expected-note  {{undefined function 'undefined'}}
+return error;
+}(); // expected-note {{in the default initalizer of 'error'}}
+} i; // expected-note {{in implicit default constructor}}
Index: clang/test/PCH/default-argument-with-immediate-calls.cpp
===
--- /dev/null
+++ clang/test/PCH/default-argument-with-immediate-calls.cpp
@@ -0,0 +1,34 @@
+// RUN: %clang_cc1 -std=c++20 -emit-pch %s -o %t
+// RUN: %clang_cc1 -std=c++20 -include-pch %t -verify %s
+// expected-no-diagnostics
+
+#ifndef HEADER_INCLUDED
+#define HEADER_INCLUDED
+
+consteval int immediate();
+int regular_function() {
+return 0;
+}
+
+struct S {
+  int a = immediate() + regular_function();
+};
+
+int f(int arg = immediate()) {
+return arg;
+}
+
+#else
+
+consteval int immediate() {
+return 0;
+}
+
+void test() {
+f(0);
+f();
+S s{0};
+S t{0};
+}
+
+#endif
Index: clang/test/CodeGenCXX/default-arguments-with-immediate.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/default-arguments-with-immediate.cpp
@@ -0,0 +1,55 @@
+// RUN: %clang_cc1 -std=c++2a -triple x86_64-elf-gnu %s -emit-llvm -o - | FileCheck %s
+
+
+consteval int immediate() {return 0;}
+static int ext();
+void f(int a = immediate() + ext());
+
+void test_function() {
+f();
+f(0);
+// CHECK: call noundef i32 @_ZL3extv()
+// CHECK: add
+// CHECK: call {{.*}} @_Z1fi
+// CHECK: call {{.*}} @_Z1fi
+}
+
+static constexpr int not_immediate();
+struct A {
+int a = immediate() + not_immediate();
+};
+
+// CHECK: define {{.*}} i32 @_ZL3extv()
+
+void test_member() {
+// CHECK: call void @_ZN1AC2Ev
+A defaulted;
+// CHECK-NOT: call void @_ZN1AC2Ev
+A provided{0};
+}
+
+// CHECK: define {{.*}} void @_ZN1AC2Ev{{.*}}
+// CHECK: %call = call noundef i32 @_ZL13not_immediatev()
+
+int never_referenced() {return 42;};
+
+
+namespace not_used {
+
+struct A {
+int a = immediate() + never_referenced();
+};
+void f(int a = immediate() + never_referenced());
+
+void g() {
+A a{0};
+f(0)

[PATCH] D136554: Implement CWG2631

2022-10-26 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added a comment.

This is working towards, but not yet fixing source_location.
Subsequent patches are needed 
https://github.com/llvm/llvm-project/issues/56379#issuecomment-1288213743




Comment at: clang/lib/Sema/SemaDeclCXX.cpp:15601
 
-ExprResult Sema::BuildCXXDefaultInitExpr(SourceLocation Loc, FieldDecl *Field) 
{
-  assert(Field->hasInClassInitializer());

Note: This was moved in the same file as `BuildCXXDefaultArgExpr` as they use 
some of the same utilities


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136554

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


[PATCH] D136746: [mlir] Saturation arithmetic intrinsics

2022-10-26 Thread Omri Bloch via Phabricator via cfe-commits
omri123 added a comment.

Thanks! Submitting.


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

https://reviews.llvm.org/D136746

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


[clang] e044824 - [Lex] Stop allocating/deallocating MacroInfo on a linked list. NFC

2022-10-26 Thread Sam McCall via cfe-commits

Author: Sam McCall
Date: 2022-10-26T16:24:25+02:00
New Revision: e0448245671342ad4f0431aeabef8d575cfd80f5

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

LOG: [Lex] Stop allocating/deallocating MacroInfo on a linked list. NFC

This list was originally used for to make sure MacroInfo's clever memory
management got called (1f1e4bdbf7815c), but that was
simplified in 73a29662b9bf640a and 1f1e4bdbf7815c, and there's nothing left.

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

Added: 


Modified: 
clang/include/clang/Lex/MacroInfo.h
clang/include/clang/Lex/Preprocessor.h
clang/lib/Lex/PPDirectives.cpp
clang/lib/Lex/Preprocessor.cpp

Removed: 




diff  --git a/clang/include/clang/Lex/MacroInfo.h 
b/clang/include/clang/Lex/MacroInfo.h
index 1947bc8fc509e..dc7ddb1a5939e 100644
--- a/clang/include/clang/Lex/MacroInfo.h
+++ b/clang/include/clang/Lex/MacroInfo.h
@@ -117,9 +117,8 @@ class MacroInfo {
   /// Whether this macro was used as header guard.
   bool UsedForHeaderGuard : 1;
 
-  // Only the Preprocessor gets to create and destroy these.
+  // Only the Preprocessor gets to create these.
   MacroInfo(SourceLocation DefLoc);
-  ~MacroInfo() = default;
 
 public:
   /// Return the location that the macro was defined at.

diff  --git a/clang/include/clang/Lex/Preprocessor.h 
b/clang/include/clang/Lex/Preprocessor.h
index 98596e563e9ee..2c0f8f3a632ff 100644
--- a/clang/include/clang/Lex/Preprocessor.h
+++ b/clang/include/clang/Lex/Preprocessor.h
@@ -1011,15 +1011,6 @@ class Preprocessor {
   /// invoked (at which point the last position is popped).
   std::vector BacktrackPositions;
 
-  struct MacroInfoChain {
-MacroInfo MI;
-MacroInfoChain *Next;
-  };
-
-  /// MacroInfos are managed as a chain for easy disposal.  This is the head
-  /// of that list.
-  MacroInfoChain *MIChainHead = nullptr;
-
   /// True if \p Preprocessor::SkipExcludedConditionalBlock() is running.
   /// This is used to guard against calling this function recursively.
   ///

diff  --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp
index 4a43cfdb0448c..3fc0606d62b9a 100644
--- a/clang/lib/Lex/PPDirectives.cpp
+++ b/clang/lib/Lex/PPDirectives.cpp
@@ -57,9 +57,8 @@ using namespace clang;
 
//===--===//
 
 MacroInfo *Preprocessor::AllocateMacroInfo(SourceLocation L) {
-  auto *MIChain = new (BP) MacroInfoChain{L, MIChainHead};
-  MIChainHead = MIChain;
-  return &MIChain->MI;
+  static_assert(std::is_trivially_destructible_v, "");
+  return new (BP) MacroInfo(L);
 }
 
 DefMacroDirective *Preprocessor::AllocateDefMacroDirective(MacroInfo *MI,

diff  --git a/clang/lib/Lex/Preprocessor.cpp b/clang/lib/Lex/Preprocessor.cpp
index 1cc1dc310d46c..3b11a7a58b681 100644
--- a/clang/lib/Lex/Preprocessor.cpp
+++ b/clang/lib/Lex/Preprocessor.cpp
@@ -165,12 +165,6 @@ Preprocessor::~Preprocessor() {
 
   IncludeMacroStack.clear();
 
-  // Destroy any macro definitions.
-  while (MacroInfoChain *I = MIChainHead) {
-MIChainHead = I->Next;
-I->~MacroInfoChain();
-  }
-
   // Free any cached macro expanders.
   // This populates MacroArgCache, so all TokenLexers need to be destroyed
   // before the code below that frees up the MacroArgCache list.



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


[PATCH] D136725: [Lex] Stop allocating/deallocating MacroInfo on a linked list. NFC

2022-10-26 Thread Sam McCall via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe04482456713: [Lex] Stop allocating/deallocating MacroInfo 
on a linked list. NFC (authored by sammccall).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136725

Files:
  clang/include/clang/Lex/MacroInfo.h
  clang/include/clang/Lex/Preprocessor.h
  clang/lib/Lex/PPDirectives.cpp
  clang/lib/Lex/Preprocessor.cpp


Index: clang/lib/Lex/Preprocessor.cpp
===
--- clang/lib/Lex/Preprocessor.cpp
+++ clang/lib/Lex/Preprocessor.cpp
@@ -165,12 +165,6 @@
 
   IncludeMacroStack.clear();
 
-  // Destroy any macro definitions.
-  while (MacroInfoChain *I = MIChainHead) {
-MIChainHead = I->Next;
-I->~MacroInfoChain();
-  }
-
   // Free any cached macro expanders.
   // This populates MacroArgCache, so all TokenLexers need to be destroyed
   // before the code below that frees up the MacroArgCache list.
Index: clang/lib/Lex/PPDirectives.cpp
===
--- clang/lib/Lex/PPDirectives.cpp
+++ clang/lib/Lex/PPDirectives.cpp
@@ -57,9 +57,8 @@
 
//===--===//
 
 MacroInfo *Preprocessor::AllocateMacroInfo(SourceLocation L) {
-  auto *MIChain = new (BP) MacroInfoChain{L, MIChainHead};
-  MIChainHead = MIChain;
-  return &MIChain->MI;
+  static_assert(std::is_trivially_destructible_v, "");
+  return new (BP) MacroInfo(L);
 }
 
 DefMacroDirective *Preprocessor::AllocateDefMacroDirective(MacroInfo *MI,
Index: clang/include/clang/Lex/Preprocessor.h
===
--- clang/include/clang/Lex/Preprocessor.h
+++ clang/include/clang/Lex/Preprocessor.h
@@ -1011,15 +1011,6 @@
   /// invoked (at which point the last position is popped).
   std::vector BacktrackPositions;
 
-  struct MacroInfoChain {
-MacroInfo MI;
-MacroInfoChain *Next;
-  };
-
-  /// MacroInfos are managed as a chain for easy disposal.  This is the head
-  /// of that list.
-  MacroInfoChain *MIChainHead = nullptr;
-
   /// True if \p Preprocessor::SkipExcludedConditionalBlock() is running.
   /// This is used to guard against calling this function recursively.
   ///
Index: clang/include/clang/Lex/MacroInfo.h
===
--- clang/include/clang/Lex/MacroInfo.h
+++ clang/include/clang/Lex/MacroInfo.h
@@ -117,9 +117,8 @@
   /// Whether this macro was used as header guard.
   bool UsedForHeaderGuard : 1;
 
-  // Only the Preprocessor gets to create and destroy these.
+  // Only the Preprocessor gets to create these.
   MacroInfo(SourceLocation DefLoc);
-  ~MacroInfo() = default;
 
 public:
   /// Return the location that the macro was defined at.


Index: clang/lib/Lex/Preprocessor.cpp
===
--- clang/lib/Lex/Preprocessor.cpp
+++ clang/lib/Lex/Preprocessor.cpp
@@ -165,12 +165,6 @@
 
   IncludeMacroStack.clear();
 
-  // Destroy any macro definitions.
-  while (MacroInfoChain *I = MIChainHead) {
-MIChainHead = I->Next;
-I->~MacroInfoChain();
-  }
-
   // Free any cached macro expanders.
   // This populates MacroArgCache, so all TokenLexers need to be destroyed
   // before the code below that frees up the MacroArgCache list.
Index: clang/lib/Lex/PPDirectives.cpp
===
--- clang/lib/Lex/PPDirectives.cpp
+++ clang/lib/Lex/PPDirectives.cpp
@@ -57,9 +57,8 @@
 //===--===//
 
 MacroInfo *Preprocessor::AllocateMacroInfo(SourceLocation L) {
-  auto *MIChain = new (BP) MacroInfoChain{L, MIChainHead};
-  MIChainHead = MIChain;
-  return &MIChain->MI;
+  static_assert(std::is_trivially_destructible_v, "");
+  return new (BP) MacroInfo(L);
 }
 
 DefMacroDirective *Preprocessor::AllocateDefMacroDirective(MacroInfo *MI,
Index: clang/include/clang/Lex/Preprocessor.h
===
--- clang/include/clang/Lex/Preprocessor.h
+++ clang/include/clang/Lex/Preprocessor.h
@@ -1011,15 +1011,6 @@
   /// invoked (at which point the last position is popped).
   std::vector BacktrackPositions;
 
-  struct MacroInfoChain {
-MacroInfo MI;
-MacroInfoChain *Next;
-  };
-
-  /// MacroInfos are managed as a chain for easy disposal.  This is the head
-  /// of that list.
-  MacroInfoChain *MIChainHead = nullptr;
-
   /// True if \p Preprocessor::SkipExcludedConditionalBlock() is running.
   /// This is used to guard against calling this function recursively.
   ///
Index: clang/include/clang/Lex/MacroInfo.h
===
--- clang/include/clang/Lex/MacroInfo.h
+++ clang/include/clang/Lex/MacroInfo.h
@@ -117,9 +117,8

[clang] a688b5f - [clang][ASTImporter] Remove use of ParentMapContext.

2022-10-26 Thread Balázs Kéri via cfe-commits

Author: Balázs Kéri
Date: 2022-10-26T16:25:10+02:00
New Revision: a688b5f92a17dccbad411b41e254addfbd4d2852

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

LOG: [clang][ASTImporter] Remove use of ParentMapContext.

Function 'isAncestorDeclContextOf' was using 'ParentMapContext' for
looking up parent of statement nodes. There may be cases (bugs?) with
ParentMapContext when parents of specific statements are not found.
This leads to 'ASTImporter' infinite import loops when function
'hasAutoReturnTypeDeclaredInside' returns false incorrectly.
A real case was found but could not be reproduced with test code.
Use of 'ParentMapContext' is now removed and changed to a more safe
(currently) method by searching for declarations in statements
and find parent of these declarations. The new code was tested on
a number of projects and no related crash was found.

Reviewed By: martong

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

Added: 


Modified: 
clang/lib/AST/ASTImporter.cpp

Removed: 




diff  --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index 0606c5ca0785..bfe21cc9f11d 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -34,7 +34,6 @@
 #include "clang/AST/LambdaCapture.h"
 #include "clang/AST/NestedNameSpecifier.h"
 #include "clang/AST/OperationKinds.h"
-#include "clang/AST/ParentMapContext.h"
 #include "clang/AST/Stmt.h"
 #include "clang/AST/StmtCXX.h"
 #include "clang/AST/StmtObjC.h"
@@ -3230,16 +3229,19 @@ static bool isAncestorDeclContextOf(const DeclContext 
*DC, const Decl *D) {
   return false;
 }
 
-// Returns true if the statement S has a parent declaration that has a
-// DeclContext that is inside (or equal to) DC. In a specific use case if DC is
-// a FunctionDecl, check if statement S resides in the body of the function.
+// Check if there is a declaration that has 'DC' as parent context and is
+// referenced from statement 'S' or one of its children. The search is done in
+// BFS order through children of 'S'.
 static bool isAncestorDeclContextOf(const DeclContext *DC, const Stmt *S) {
-  ParentMapContext &ParentC = DC->getParentASTContext().getParentMapContext();
-  DynTypedNodeList Parents = ParentC.getParents(*S);
-  while (!Parents.empty()) {
-if (const Decl *PD = Parents.begin()->get())
-  return isAncestorDeclContextOf(DC, PD);
-Parents = ParentC.getParents(*Parents.begin());
+  SmallVector ToProcess;
+  ToProcess.push_back(S);
+  while (!ToProcess.empty()) {
+const Stmt *CurrentS = ToProcess.pop_back_val();
+ToProcess.append(CurrentS->child_begin(), CurrentS->child_end());
+if (const auto *DeclRef = dyn_cast(CurrentS))
+  if (const Decl *D = DeclRef->getDecl())
+if (isAncestorDeclContextOf(DC, D))
+  return true;
   }
   return false;
 }



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


[PATCH] D136684: [clang][ASTImporter] Remove use of ParentMapContext.

2022-10-26 Thread Balázs Kéri via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa688b5f92a17: [clang][ASTImporter] Remove use of 
ParentMapContext. (authored by balazske).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136684

Files:
  clang/lib/AST/ASTImporter.cpp


Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -34,7 +34,6 @@
 #include "clang/AST/LambdaCapture.h"
 #include "clang/AST/NestedNameSpecifier.h"
 #include "clang/AST/OperationKinds.h"
-#include "clang/AST/ParentMapContext.h"
 #include "clang/AST/Stmt.h"
 #include "clang/AST/StmtCXX.h"
 #include "clang/AST/StmtObjC.h"
@@ -3230,16 +3229,19 @@
   return false;
 }
 
-// Returns true if the statement S has a parent declaration that has a
-// DeclContext that is inside (or equal to) DC. In a specific use case if DC is
-// a FunctionDecl, check if statement S resides in the body of the function.
+// Check if there is a declaration that has 'DC' as parent context and is
+// referenced from statement 'S' or one of its children. The search is done in
+// BFS order through children of 'S'.
 static bool isAncestorDeclContextOf(const DeclContext *DC, const Stmt *S) {
-  ParentMapContext &ParentC = DC->getParentASTContext().getParentMapContext();
-  DynTypedNodeList Parents = ParentC.getParents(*S);
-  while (!Parents.empty()) {
-if (const Decl *PD = Parents.begin()->get())
-  return isAncestorDeclContextOf(DC, PD);
-Parents = ParentC.getParents(*Parents.begin());
+  SmallVector ToProcess;
+  ToProcess.push_back(S);
+  while (!ToProcess.empty()) {
+const Stmt *CurrentS = ToProcess.pop_back_val();
+ToProcess.append(CurrentS->child_begin(), CurrentS->child_end());
+if (const auto *DeclRef = dyn_cast(CurrentS))
+  if (const Decl *D = DeclRef->getDecl())
+if (isAncestorDeclContextOf(DC, D))
+  return true;
   }
   return false;
 }


Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -34,7 +34,6 @@
 #include "clang/AST/LambdaCapture.h"
 #include "clang/AST/NestedNameSpecifier.h"
 #include "clang/AST/OperationKinds.h"
-#include "clang/AST/ParentMapContext.h"
 #include "clang/AST/Stmt.h"
 #include "clang/AST/StmtCXX.h"
 #include "clang/AST/StmtObjC.h"
@@ -3230,16 +3229,19 @@
   return false;
 }
 
-// Returns true if the statement S has a parent declaration that has a
-// DeclContext that is inside (or equal to) DC. In a specific use case if DC is
-// a FunctionDecl, check if statement S resides in the body of the function.
+// Check if there is a declaration that has 'DC' as parent context and is
+// referenced from statement 'S' or one of its children. The search is done in
+// BFS order through children of 'S'.
 static bool isAncestorDeclContextOf(const DeclContext *DC, const Stmt *S) {
-  ParentMapContext &ParentC = DC->getParentASTContext().getParentMapContext();
-  DynTypedNodeList Parents = ParentC.getParents(*S);
-  while (!Parents.empty()) {
-if (const Decl *PD = Parents.begin()->get())
-  return isAncestorDeclContextOf(DC, PD);
-Parents = ParentC.getParents(*Parents.begin());
+  SmallVector ToProcess;
+  ToProcess.push_back(S);
+  while (!ToProcess.empty()) {
+const Stmt *CurrentS = ToProcess.pop_back_val();
+ToProcess.append(CurrentS->child_begin(), CurrentS->child_end());
+if (const auto *DeclRef = dyn_cast(CurrentS))
+  if (const Decl *D = DeclRef->getDecl())
+if (isAncestorDeclContextOf(DC, D))
+  return true;
   }
   return false;
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 82a5081 - [analyzer][StdLibraryFunctionsChecker] Add NoteTags for applied arg

2022-10-26 Thread Gabor Marton via cfe-commits

Author: Gabor Marton
Date: 2022-10-26T16:33:25+02:00
New Revision: 82a50812f7e539b69fb8031bee9c823e5290d1c9

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

LOG: [analyzer][StdLibraryFunctionsChecker] Add NoteTags for applied arg
constraints

In this patch I add a new NoteTag for each applied argument constraint.
This way, any other checker that reports a bug - where the applied
constraint is relevant - will display the corresponding note. With this
change we provide more information for the users to understand some
bug reports easier.

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

Reviewed By: NoQ

Added: 
clang/test/Analysis/std-c-library-functions-arg-constraints-note-tags.cpp

Modified: 
clang/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp
clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
clang/test/Analysis/std-c-library-functions-arg-constraints-notes.cpp
clang/test/Analysis/std-c-library-functions-arg-constraints.c

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp
index 195a5fa977438..f9efcc5d9 100644
--- a/clang/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp
@@ -115,7 +115,8 @@ bool ExprInspectionChecker::evalCall(const CallEvent &Call,
   .Case("clang_analyzer_hashDump",
 &ExprInspectionChecker::analyzerHashDump)
   .Case("clang_analyzer_denote", 
&ExprInspectionChecker::analyzerDenote)
-  .Case("clang_analyzer_express",
+  .Case("clang_analyzer_express", // This also marks the argument as
+  // interesting.
 &ExprInspectionChecker::analyzerExpress)
   .StartsWith("clang_analyzer_isTainted",
   &ExprInspectionChecker::analyzerIsTainted)
@@ -530,14 +531,14 @@ void ExprInspectionChecker::analyzerExpress(const 
CallExpr *CE,
   SVal ArgVal = C.getSVal(CE->getArg(0));
   SymbolRef Sym = ArgVal.getAsSymbol();
   if (!Sym) {
-reportBug("Not a symbol", C);
+reportBug("Not a symbol", C, ArgVal);
 return;
   }
 
   SymbolExpressor V(C.getState());
   auto Str = V.Visit(Sym);
   if (!Str) {
-reportBug("Unable to express", C);
+reportBug("Unable to express", C, ArgVal);
 return;
   }
 

diff  --git a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
index 25e80545154ee..c5fa43ac23d1e 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
@@ -134,9 +134,18 @@ class StdLibraryFunctionsChecker
 
 virtual StringRef getName() const = 0;
 
+// Represents that in which context do we require a description of the
+// constraint.
+enum class DescriptionKind {
+  // The constraint is violated.
+  Violation,
+  // We assume that the constraint is satisfied.
+  Assumption
+};
+
 // Give a description that explains the constraint to the user. Used when
 // the bug is reported.
-virtual std::string describe(ProgramStateRef State,
+virtual std::string describe(DescriptionKind DK, ProgramStateRef State,
  const Summary &Summary) const {
   // There are some descendant classes that are not used as argument
   // constraints, e.g. ComparisonConstraint. In that case we can safely
@@ -174,7 +183,7 @@ class StdLibraryFunctionsChecker
 RangeConstraint(ArgNo ArgN, RangeKind Kind, const IntRangeVector &Ranges)
 : ValueConstraint(ArgN), Kind(Kind), Ranges(Ranges) {}
 
-std::string describe(ProgramStateRef State,
+std::string describe(DescriptionKind DK, ProgramStateRef State,
  const Summary &Summary) const override;
 
 const IntRangeVector &getRanges() const { return Ranges; }
@@ -244,7 +253,7 @@ class StdLibraryFunctionsChecker
 bool CannotBeNull = true;
 
   public:
-std::string describe(ProgramStateRef State,
+std::string describe(DescriptionKind DK, ProgramStateRef State,
  const Summary &Summary) const override;
 StringRef getName() const override { return "NonNull"; }
 ProgramStateRef apply(ProgramStateRef State, const CallEvent &Call,
@@ -316,7 +325,7 @@ class StdLibraryFunctionsChecker
   return Result;
 }
 
-std::string describe(ProgramStateRef State,
+std::string describe(DescriptionKind DK, ProgramStateRef State,
  const Summary &Summary) const override;
 
 ProgramStateRef apply(ProgramStateRef State, const CallEvent &Call

[PATCH] D101526: [analyzer][StdLibraryFunctionsChecker] Add NoteTags for applied arg constraints

2022-10-26 Thread Gabor Marton via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
martong marked an inline comment as done.
Closed by commit rG82a50812f7e5: [analyzer][StdLibraryFunctionsChecker] Add 
NoteTags for applied arg (authored by martong).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101526

Files:
  clang/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
  clang/test/Analysis/std-c-library-functions-arg-constraints-note-tags.cpp
  clang/test/Analysis/std-c-library-functions-arg-constraints-notes.cpp
  clang/test/Analysis/std-c-library-functions-arg-constraints.c

Index: clang/test/Analysis/std-c-library-functions-arg-constraints.c
===
--- clang/test/Analysis/std-c-library-functions-arg-constraints.c
+++ clang/test/Analysis/std-c-library-functions-arg-constraints.c
@@ -239,6 +239,7 @@
   // State split should not happen here. I.e. x == 1 should not be evaluated
   // FALSE.
   __two_constrained_args(x, y);
+  //NOTE! Because of the second `clang_analyzer_eval` call we have two bug
   clang_analyzer_eval(x == 1); // \
   // report-warning{{TRUE}} \
   // bugpath-warning{{TRUE}} \
@@ -252,7 +253,6 @@
 int __arg_constrained_twice(int);
 void test_multiple_constraints_on_same_arg(int x) {
   __arg_constrained_twice(x);
-  // Check that both constraints are applied and only one branch is there.
   clang_analyzer_eval(x < 1 || x > 2); // \
   // report-warning{{TRUE}} \
   // bugpath-warning{{TRUE}} \
Index: clang/test/Analysis/std-c-library-functions-arg-constraints-notes.cpp
===
--- clang/test/Analysis/std-c-library-functions-arg-constraints-notes.cpp
+++ clang/test/Analysis/std-c-library-functions-arg-constraints-notes.cpp
@@ -15,7 +15,7 @@
 int __not_null(int *);
 void test_not_null(int *x) {
   __not_null(nullptr); // \
-  // expected-note{{The 1st arg should not be NULL}} \
+  // expected-note{{The 1st argument should not be NULL}} \
   // expected-warning{{}}
 }
 
@@ -29,21 +29,21 @@
   case 1: {
 char buf[9];
 __buf_size_arg_constraint_concrete(buf); // \
-// expected-note{{The size of the 1st arg should be equal to or less than the value of 10}} \
+// expected-note{{The size of the 1st argument should be equal to or greater than the value of 10}} \
 // expected-warning{{}}
 break;
   }
   case 2: {
 char buf[3];
 __buf_size_arg_constraint(buf, 4); // \
-// expected-note{{The size of the 1st arg should be equal to or less than the value of the 2nd arg}} \
+// expected-note{{The size of the 1st argument should be equal to or greater than the value of the 2nd arg}} \
 // expected-warning{{}}
 break;
   }
   case 3: {
 char buf[3];
 __buf_size_arg_constraint_mul(buf, 4, 2); // \
-// expected-note{{The size of the 1st arg should be equal to or less than the value of the 2nd arg times the 3rd arg}} \
+// expected-note{{The size of the 1st argument should be equal to or greater than the value of the 2nd argument times the 3rd argument}} \
 // expected-warning{{}}
 break;
   }
@@ -56,7 +56,7 @@
 int __range_1_2__4_5(int);// [1, 2], [4, 5]
 void test_range(int x) {
 __single_val_1(2); // \
-// expected-note{{The 1st arg should be within the range [1, 1]}} \
+// expected-note{{The 1st argument should be within the range [1, 1]}} \
 // expected-warning{{}}
 }
 // Do more specific check against the range strings.
Index: clang/test/Analysis/std-c-library-functions-arg-constraints-note-tags.cpp
===
--- /dev/null
+++ clang/test/Analysis/std-c-library-functions-arg-constraints-note-tags.cpp
@@ -0,0 +1,51 @@
+// RUN: %clang_analyze_cc1 %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=apiModeling.StdCLibraryFunctions \
+// RUN:   -analyzer-checker=alpha.unix.StdCLibraryFunctionArgs \
+// RUN:   -analyzer-checker=debug.StdCLibraryFunctionsTester \
+// RUN:   -analyzer-config apiModeling.StdCLibraryFunctions:DisplayLoadedSummaries=true \
+// RUN:   -analyzer-checker=debug.ExprInspection \
+// RUN:   -analyzer-config eagerly-assume=false \
+// RUN:   -triple i686-unknown-linux \
+// RUN:   -analyzer-output=text \
+// RUN:   -verify
+
+template 
+void clang_analyzer_express(T x);
+void clang_analyzer_eval(bool);
+int clang_analyzer_getExtent(void *);
+
+
+// Check NotNullConstraint assumption notes.
+int __not_null(int *);
+int test_not_null_note(int *x, int y) {
+  __not_null(x);  // expected-note{{Assuming the 1st argument is not NULL}}
+  if (x)  // expected-note{{'x' is non-null}} \
+  // expected-note{{Taking true branch}}
+if (!y)   // expected-note{{Assuming '

[PATCH] D101526: [analyzer][StdLibraryFunctionsChecker] Add NoteTags for applied arg constraints

2022-10-26 Thread Gabor Marton via Phabricator via cfe-commits
martong added a comment.

In D101526#3883871 , @NoQ wrote:

> Looks great to me, thanks!!

Thanks for the review!




Comment at: 
clang/test/Analysis/std-c-library-functions-arg-constraints-notes.cpp:32-33
 __buf_size_arg_constraint_concrete(buf); // \
-// expected-note{{The size of the 1st arg should be equal to or less than 
the value of 10}} \
+// expected-note{{The size of the 1st argument should be equal to or 
greater than the value of 10}} \
 // expected-warning{{}}
 break;

NoQ wrote:
> The warning is the same as the note here right?
> 
> Our warnings traditionally describe the problem (the 1st argument *is* less 
> than 10, and this *is* bad because...), not how things "should" be. I guess 
> we can think more about that later.
No, actually, the warning is different, it does not contain the text "should 
be". In this case this is it:
```
 Line 31: Function argument constraint is not satisfied, constraint: BufferSize 
[alpha.unix.StdCLibraryFunctionArgs]
```
And then the notes basically further explain how the constraint is not 
satisfied.

I did not put the check for the warnings here because this test file is 
responsible for checking the notes only, hence it has the name 
`std-c-library-functions-arg-constraints-notes.cpp`.
The warnings are directly tested in 
`std-c-library-functions-arg-constraints.c`, however, I have to admit, probably 
we should have even more specific checks for the warning messages there.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101526

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


[PATCH] D136568: [Clang] Support constexpr builtin ilogb

2022-10-26 Thread Joshua Cranmer via Phabricator via cfe-commits
jcranmer-intel added inline comments.



Comment at: clang/lib/AST/ExprConstant.cpp:12452
+int Ilogb;
+if (APFloat::opStatus St = ilogb(F, Ilogb); !isConstantOpStatus(St))
+  return false;

Izaron wrote:
> aaron.ballman wrote:
> > jcranmer-intel wrote:
> > > `long double` is `ppc_fp128` on at least some PPC targets, and while I'm 
> > > not entirely certain of what `ilogb` properly returns in the corner cases 
> > > of the `ppc_fp128`, I'm not entirely confident that the implementation of 
> > > `APFloat` is correct in those cases. I'd like someone with PPC background 
> > > to comment in here.
> > Paging @hubert.reinterpretcast for help finding a good person to comment on 
> > the PPC questions.
> @jcranmer-intel constexpr evaluation is quite machine-/target-independent. 
> Clang evaluates it based on its **internal** representation of float 
> variables.
> 
> [[ 
> https://github.com/llvm/llvm-project/blob/2e5bf4da99a2f8d3d4bb4f1a4d1ed968a01e8f02/llvm/include/llvm/ADT/APFloat.h#L1256
>  | int ilogb ]] uses `Arg.getIEEE()`, that [[ 
> https://github.com/llvm/llvm-project/blob/2e5bf4da99a2f8d3d4bb4f1a4d1ed968a01e8f02/llvm/include/llvm/ADT/APFloat.h#L819-L825
>  | returns Clang's internal float representation ]].
> 
> Whichever float semantics is being used, [[ 
> https://github.com/llvm/llvm-project/blob/2e5bf4da99a2f8d3d4bb4f1a4d1ed968a01e8f02/llvm/lib/Support/APFloat.cpp#L54-L61
>  | minExponent and maxExponent are representable as APFloatBase::ExponentType 
> ]], which is `int32_t`:
> ```
> /// A signed type to represent a floating point numbers unbiased exponent.
> typedef int32_t ExponentType;
> ```
> 
> We already use `int ilogb` in some constexpr evaluation code: [[ 
> https://github.com/llvm/llvm-project/blob/2e5bf4da99a2f8d3d4bb4f1a4d1ed968a01e8f02/clang/lib/AST/ExprConstant.cpp#L14592
>  | link ]], it is working correct because it is working on Clang's float 
> representations.
> We already use `int ilogb` in some constexpr evaluation code: [[ 
> https://github.com/llvm/llvm-project/blob/2e5bf4da99a2f8d3d4bb4f1a4d1ed968a01e8f02/clang/lib/AST/ExprConstant.cpp#L14592
>  | link ]], it is working correct because it is working on Clang's float 
> representations.

`APFloat::getIEEE()`, if I'm following it correctly, only returns the details 
of the high double in `ppc_fp128` floats, and I'm not sufficiently well-versed 
in the `ppc_fp128` format to establish whether or not the low double comes into 
play here. glibc seems to think that the low double comes into play in at least 
one case: 
https://github.com/bminor/glibc/blob/30891f35fa7da832b66d80d0807610df361851f3/sysdeps/ieee754/ldbl-128ibm/e_ilogbl.c


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136568

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


[PATCH] D134128: [P0857R0 Part B] Resubmit an implemention for constrained template template parameters

2022-10-26 Thread Liming Liu via Phabricator via cfe-commits
lime updated this revision to Diff 470816.
lime added a comment.

Update commit message, and remove the "for" in release notes, which should make 
the phrase correct in grammar.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134128

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Sema/Sema.h
  clang/lib/Parse/ParseTemplate.cpp
  clang/lib/Sema/SemaConcept.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/test/CXX/temp/temp.arg/temp.arg.template/p3-2a.cpp
  clang/test/SemaTemplate/concepts.cpp
  clang/www/cxx_status.html
  libcxx/DELETE.ME

Index: libcxx/DELETE.ME
===
--- /dev/null
+++ libcxx/DELETE.ME
@@ -0,0 +1 @@
+D134128
Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -912,11 +912,7 @@
 

 https://wg21.link/p0857r0";>P0857R0
-
-  Partial
-Constraining template template parameters is not yet supported.
-  
-
+Clang 16
   

 https://wg21.link/p1084r2";>P1084R2
Index: clang/test/SemaTemplate/concepts.cpp
===
--- clang/test/SemaTemplate/concepts.cpp
+++ clang/test/SemaTemplate/concepts.cpp
@@ -61,9 +61,9 @@
 
   // FIXME: This is valid under P0857R0.
   template concept C = true;
-  template requires C typename U> struct X {}; // expected-error {{requires 'class'}} expected-error 0+{{}}
+  template requires C typename U> struct X {};
   template requires C struct Y {};
-  X xy; // expected-error {{no template named 'X'}}
+  X xy;
 }
 
 namespace PR50306 {
Index: clang/test/CXX/temp/temp.arg/temp.arg.template/p3-2a.cpp
===
--- clang/test/CXX/temp/temp.arg/temp.arg.template/p3-2a.cpp
+++ clang/test/CXX/temp/temp.arg/temp.arg.template/p3-2a.cpp
@@ -1,22 +1,27 @@
 // RUN:  %clang_cc1 -std=c++2a -frelaxed-template-template-args -verify %s
 
-template concept C = T::f();
-// expected-note@-1{{similar constraint}}
+template concept C = T::f(); // #C
 template concept D = C && T::g();
-template concept F = T::f();
-// expected-note@-1{{similar constraint expressions not considered equivalent}}
-template class P> struct S1 { }; // expected-note 2{{'P' declared here}}
+template concept F = T::f(); // #F
+template class P> struct S1 { }; // #S1
 
 template struct X { };
 
-template struct Y { }; // expected-note{{'Y' declared here}}
+template struct Y { }; // #Y
 template struct Z { };
-template struct W { }; // expected-note{{'W' declared here}}
-
+template struct W { }; // #W
 S1 s11;
-S1 s12; // expected-error{{template template argument 'Y' is more constrained than template template parameter 'P'}}
+S1 s12;
+// expected-error@-1 {{template template argument 'Y' is more constrained than template template parameter 'P'}}
+// expected-note@#S1 {{'P' declared here}}
+// expected-note@#Y {{'Y' declared here}}
 S1 s13;
-S1 s14; // expected-error{{template template argument 'W' is more constrained than template template parameter 'P'}}
+S1 s14;
+// expected-error@-1 {{template template argument 'W' is more constrained than template template parameter 'P'}}
+// expected-note@#S1 {{'P' declared here}}
+// expected-note@#W {{'W' declared here}}
+// expected-note@#F 1-2{{similar constraint expressions not considered equivalent}}
+// expected-note@#C 1-2{{similar constraint}}
 
 template class P> struct S2 { };
 
@@ -32,3 +37,25 @@
 
 using s31 = S3;
 using s32 = S3;
+
+template requires C class P> struct S4 { }; // #S4
+
+S4 s41;
+S4 s42;
+// expected-error@-1 {{template template argument 'Y' is more constrained than template template parameter 'P'}}
+// expected-note@#S4 {{'P' declared here}}
+// expected-note@#Y {{'Y' declared here}}
+S4 s43;
+S4 s44;
+// expected-error@-1 {{template template argument 'W' is more constrained than template template parameter 'P'}}
+// expected-note@#S4 {{'P' declared here}}
+// expected-note@#W {{'W' declared here}}
+
+template requires C typename U> struct S5 {
+  template static U V;
+};
+
+struct Nothing {};
+
+// FIXME: Wait the standard to clarify the intent.
+template<> template<> Z S5::V;
Index: clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -4098,8 +4098,10 @@
 
 TemplateParameterList *
 Sema::SubstTemplateParams(TemplateParameterList *Params, DeclContext *Owner,
-  const MultiLevelTemplateArgumentList &TemplateArgs) {
+  const MultiLevelTemplateArgumentLi

[PATCH] D136723: [include-cleaner] Record main-file macro occurences and includes

2022-10-26 Thread Sam McCall via Phabricator via cfe-commits
sammccall updated this revision to Diff 470818.
sammccall marked 5 inline comments as done.
sammccall added a comment.

address comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136723

Files:
  clang-tools-extra/include-cleaner/include/clang-include-cleaner/Record.h
  clang-tools-extra/include-cleaner/include/clang-include-cleaner/Types.h
  clang-tools-extra/include-cleaner/lib/Record.cpp
  clang-tools-extra/include-cleaner/lib/Types.cpp
  clang-tools-extra/include-cleaner/unittests/RecordTest.cpp

Index: clang-tools-extra/include-cleaner/unittests/RecordTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/RecordTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/RecordTest.cpp
@@ -8,13 +8,19 @@
 
 #include "clang-include-cleaner/Record.h"
 #include "clang/Frontend/FrontendAction.h"
+#include "clang/Frontend/FrontendActions.h"
 #include "clang/Testing/TestAST.h"
+#include "clang/Tooling/Inclusions/StandardLibrary.h"
+#include "llvm/Support/VirtualFileSystem.h"
 #include "llvm/Support/raw_ostream.h"
+#include "llvm/Testing/Support/Annotations.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 
 namespace clang::include_cleaner {
 namespace {
+using testing::ElementsAre;
+using testing::ElementsAreArray;
 
 // Matches a Decl* if it is a NamedDecl with the given name.
 MATCHER_P(Named, N, "") {
@@ -88,5 +94,144 @@
   EXPECT_THAT(Recorded.Roots, testing::ElementsAre(Named("x")));
 }
 
+class RecordPPTest : public ::testing::Test {
+protected:
+  TestInputs Inputs;
+  RecordedPP Recorded;
+
+  RecordPPTest() {
+struct RecordAction : public PreprocessOnlyAction {
+  RecordedPP &Out;
+  RecordAction(RecordedPP &Out) : Out(Out) {}
+
+  void ExecuteAction() override {
+auto &PP = getCompilerInstance().getPreprocessor();
+PP.addPPCallbacks(Out.record(PP));
+PreprocessOnlyAction::ExecuteAction();
+  }
+};
+Inputs.MakeAction = [this] {
+  return std::make_unique(Recorded);
+};
+  }
+
+  TestAST build() { return TestAST(Inputs); }
+};
+
+// Matches an Include with a particular spelling.
+MATCHER_P(spelled, S, "") { return arg.Spelled == S; }
+
+TEST_F(RecordPPTest, CapturesIncludes) {
+  llvm::Annotations MainFile(R"cpp(
+$H^#include "./header.h"
+$M^#include "missing.h"
+  )cpp");
+  Inputs.Code = MainFile.code();
+  Inputs.ExtraFiles["header.h"] = "";
+  Inputs.ErrorOK = true; // missing header
+  auto AST = build();
+
+  ASSERT_THAT(
+  Recorded.Includes.all(),
+  testing::ElementsAre(spelled("./header.h"), spelled("missing.h")));
+
+  auto &H = Recorded.Includes.all().front();
+  EXPECT_EQ(H.Line, 2u);
+  EXPECT_EQ(H.HashLocation,
+AST.sourceManager().getComposedLoc(
+AST.sourceManager().getMainFileID(), MainFile.point("H")));
+  EXPECT_EQ(H.Resolved, AST.fileManager().getFile("header.h").get());
+
+  auto &M = Recorded.Includes.all().back();
+  EXPECT_EQ(M.Line, 3u);
+  EXPECT_EQ(M.HashLocation,
+AST.sourceManager().getComposedLoc(
+AST.sourceManager().getMainFileID(), MainFile.point("M")));
+  EXPECT_EQ(M.Resolved, nullptr);
+}
+
+TEST_F(RecordPPTest, CapturesMacroRefs) {
+  llvm::Annotations Header(R"cpp(
+#define $def^X 1
+
+// Refs, but not in main file.
+#define Y X
+int one = X;
+  )cpp");
+  llvm::Annotations MainFile(R"cpp(
+#define EARLY X // not a ref, no definition
+#include "header.h"
+#define LATE ^X
+#define LATE2 ^X // a ref even if not expanded
+
+int uno = ^X;
+int jeden = $exp^LATE; // a ref in LATE's expansion
+
+#define IDENT(X) X // not a ref, shadowed
+int eins = IDENT(^X);
+
+#undef ^X
+// Not refs, rather a new macro with the same name.
+#define X 2
+int two = X;
+  )cpp");
+  Inputs.Code = MainFile.code();
+  Inputs.ExtraFiles["header.h"] = Header.code();
+  auto AST = build();
+  const auto &SM = AST.sourceManager();
+
+  SourceLocation Def = SM.getComposedLoc(
+  SM.translateFile(AST.fileManager().getFile("header.h").get()),
+  Header.point("def"));
+  ASSERT_NE(Recorded.MacroReferences.size(), 0u);
+  Symbol OrigX = Recorded.MacroReferences.front().Symbol;
+  EXPECT_EQ("X", OrigX.macro().Name->getName());
+  EXPECT_EQ(Def, OrigX.macro().Definition);
+
+  std::vector RefOffsets;
+  std::vector ExpOffsets; // Expansion locs of refs in macro locs.
+  std::vector RefMacroLocs;
+  for (const auto &Ref : Recorded.MacroReferences) {
+if (Ref.Symbol == OrigX) {
+  auto [FID, Off] = SM.getDecomposedLoc(Ref.RefLocation);
+  if (FID == SM.getMainFileID()) {
+RefOffsets.push_back(Off);
+  } else if (Ref.RefLocation.isMacroID() &&
+ SM.isWrittenInMainFile(SM.getExpansionLoc(Ref.RefLocation))) {
+ExpOffsets.push_back(
+SM.getDecomposedExpansionLoc(Ref.RefLocation).seco

[clang] a504ddc - [analyzer] Initialize regions returned by CXXNew to undefined

2022-10-26 Thread Kristóf Umann via cfe-commits

Author: Kristóf Umann
Date: 2022-10-26T17:22:12+02:00
New Revision: a504ddc8bf9d5c406ea88b84b8495d7aae200d4c

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

LOG: [analyzer] Initialize regions returned by CXXNew to undefined

Discourse mail:
https://discourse.llvm.org/t/analyzer-why-do-we-suck-at-modeling-c-dynamic-memory/65667

malloc() returns a piece of uninitialized dynamic memory. We were (almost)
always able to model this behaviour. Its C++ counterpart, operator new is a
lot more complex, because it allows for initialization, the most complicated of 
which is the usage of constructors.

We gradually became better in modeling constructors, but for some reason, most
likely for reasons lost in history, we never actually modeled the case when the
memory returned by operator new was just simply uninitialized. This patch
(attempts) to fix this tiny little error.

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

Added: 


Modified: 
clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
clang/test/Analysis/NewDelete-checker-test.cpp
clang/test/Analysis/cxx-member-initializer-const-field.cpp
clang/test/Analysis/new-ctor-conservative.cpp
clang/test/Analysis/new-ctor-recursive.cpp
clang/test/Analysis/new.cpp
clang/test/Analysis/placement-new.cpp
clang/test/Analysis/reinterpret-cast.cpp
clang/test/Analysis/uninit-const.cpp

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp 
b/clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
index 476afc598ac6c..38c8896b10ba7 100644
--- a/clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
+++ b/clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
@@ -10,15 +10,16 @@
 //
 
//===--===//
 
-#include "clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h"
-#include "clang/Analysis/ConstructionContext.h"
 #include "clang/AST/DeclCXX.h"
-#include "clang/AST/StmtCXX.h"
 #include "clang/AST/ParentMap.h"
+#include "clang/AST/StmtCXX.h"
+#include "clang/Analysis/ConstructionContext.h"
 #include "clang/Basic/PrettyStackTrace.h"
 #include "clang/StaticAnalyzer/Core/CheckerManager.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/SVals.h"
 
 using namespace clang;
 using namespace ento;
@@ -953,6 +954,11 @@ void ExprEngine::VisitCXXNewAllocatorCall(const CXXNewExpr 
*CNE,
 // skip it for now.
 ProgramStateRef State = I->getState();
 SVal RetVal = State->getSVal(CNE, LCtx);
+// [basic.stc.dynamic.allocation] (on the return value of an allocation
+// function):
+// "The order, contiguity, and initial value of storage allocated by
+// successive calls to an allocation function are unspecified."
+State = State->bindDefaultInitial(RetVal, UndefinedVal{}, LCtx);
 
 // If this allocation function is not declared as non-throwing, failures
 // /must/ be signalled by exceptions, and thus the return value will never

diff  --git a/clang/test/Analysis/NewDelete-checker-test.cpp 
b/clang/test/Analysis/NewDelete-checker-test.cpp
index 5a06c8327f717..1100b49e84d3a 100644
--- a/clang/test/Analysis/NewDelete-checker-test.cpp
+++ b/clang/test/Analysis/NewDelete-checker-test.cpp
@@ -385,7 +385,11 @@ class DerefClass{
 public:
   int *x;
   DerefClass() {}
-  ~DerefClass() {*x = 1;}
+  ~DerefClass() {
+int i = 0;
+x = &i;
+*x = 1;
+  }
 };
 
 void testDoubleDeleteClassInstance() {

diff  --git a/clang/test/Analysis/cxx-member-initializer-const-field.cpp 
b/clang/test/Analysis/cxx-member-initializer-const-field.cpp
index f0abbddbc4441..98076124d82b7 100644
--- a/clang/test/Analysis/cxx-member-initializer-const-field.cpp
+++ b/clang/test/Analysis/cxx-member-initializer-const-field.cpp
@@ -10,7 +10,7 @@ struct WithConstructor {
   WithConstructor(int *x) : ptr(x) {}
 
   static auto compliant() {
-WithConstructor c(new int);
+WithConstructor c(new int{});
 return *(c.ptr); // no warning
   }
 
@@ -28,7 +28,7 @@ struct RegularAggregate {
   int *const ptr = nullptr;
 
   static int compliant() {
-RegularAggregate c{new int};
+RegularAggregate c{new int{}};
 return *(c.ptr); // no warning
   }
 

diff  --git a/clang/test/Analysis/new-ctor-conservative.cpp 
b/clang/test/Analysis/new-ctor-conservative.cpp
index bcc33fb8f8970..1fcb6708e43e1 100644
--- a/clang/test/Analysis/new-ctor-conservative.cpp
+++ b/clang/test/Analysis/new-ctor-conservative.cpp
@@ -14,9 +14,12 @@ void checkConstructorInlining() {
   clang_analyzer_eval(s->x == 1); // expected-warning{{TRUE}}
 }
 
-void checkNewPOD() {
+void check

[PATCH] D135375: [analyzer] Initialize regions returned by CXXNew to undefined

2022-10-26 Thread Kristóf Umann via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Szelethus marked an inline comment as done.
Closed by commit rGa504ddc8bf9d: [analyzer] Initialize regions returned by 
CXXNew to undefined (authored by Szelethus).

Changed prior to commit:
  https://reviews.llvm.org/D135375?vs=465779&id=470821#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135375

Files:
  clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
  clang/test/Analysis/NewDelete-checker-test.cpp
  clang/test/Analysis/cxx-member-initializer-const-field.cpp
  clang/test/Analysis/new-ctor-conservative.cpp
  clang/test/Analysis/new-ctor-recursive.cpp
  clang/test/Analysis/new.cpp
  clang/test/Analysis/placement-new.cpp
  clang/test/Analysis/reinterpret-cast.cpp
  clang/test/Analysis/uninit-const.cpp

Index: clang/test/Analysis/uninit-const.cpp
===
--- clang/test/Analysis/uninit-const.cpp
+++ clang/test/Analysis/uninit-const.cpp
@@ -21,9 +21,11 @@
 
 int f10(void) {
   int *ptr;
-
-  ptr = new int; //
-  if(*ptr) {
+ // FIXME: The message is misleading -- we should state that
+ // a pointer to an uninitialized value is stored.
+  ptr = new int; // expected-note{{Storing uninitialized value}}
+  if(*ptr) { // expected-warning{{Branch condition evaluates to a garbage value [core.uninitialized.Branch]}}
+ // expected-note@-1 {{Branch condition evaluates to a garbage value}}
 doStuff4(*ptr);
   }
   delete ptr;
@@ -32,10 +34,12 @@
 
 int f9(void) {
   int *ptr;
-
-  ptr = new int; //
-
-  doStuff_uninit(ptr); // no warning
+ // FIXME: The message is misleading -- we should state that
+ // a pointer to an uninitialized value is stored.
+  ptr = new int; // expected-note{{Storing uninitialized value}}
+ // expected-note@-1{{Value assigned to 'ptr'}}
+  doStuff_uninit(ptr); // expected-warning{{1st function call argument is a pointer to uninitialized value [core.CallAndMessage]}}
+   // expected-note@-1{{1st function call argument is a pointer to uninitialized value}}
   delete ptr;
   return 0;
 }
Index: clang/test/Analysis/reinterpret-cast.cpp
===
--- clang/test/Analysis/reinterpret-cast.cpp
+++ clang/test/Analysis/reinterpret-cast.cpp
@@ -77,15 +77,11 @@
   class Derived : public Base {};
 
   void test() {
-	Derived* p;
-	*(reinterpret_cast(&p)) = new C;
-	p->f();
-
-// We should still be able to do some reasoning about bindings.
-p->x = 42;
-clang_analyzer_eval(p->x == 42); // expected-warning{{TRUE}}
+Derived* p;
+*(reinterpret_cast(&p)) = new C;
+p->f(); // expected-warning{{Called function pointer is an uninitialized pointer value [core.CallAndMessage]}}
   };
-}
+} // namespace PR15345
 
 int trackpointer_std_addressof() {
   int x;
Index: clang/test/Analysis/placement-new.cpp
===
--- clang/test/Analysis/placement-new.cpp
+++ clang/test/Analysis/placement-new.cpp
@@ -112,6 +112,10 @@
 namespace testHeapAllocatedBuffer {
 void g2() {
   char *buf = new char[2]; // expected-note {{'buf' initialized here}}
+   // FIXME: The message is misleading -- we should
+   // state that a pointer to an uninitialized value
+   // is stored.
+   // expected-note@-4{{Storing uninitialized value}}
   long *lp = ::new (buf) long; // expected-warning{{Storage provided to placement new is only 2 bytes, whereas the allocated type requires 8 bytes}} expected-note 1 {{}}
   (void)lp;
 }
Index: clang/test/Analysis/new.cpp
===
--- clang/test/Analysis/new.cpp
+++ clang/test/Analysis/new.cpp
@@ -177,15 +177,10 @@
   clang_analyzer_eval(p.y == 2); // expected-warning{{TRUE}}
 }
 
-//
-// Incorrectly-modelled behavior
-//
-
 int testNoInitialization() {
   int *n = new int;
 
-  // Should warn that *n is uninitialized.
-  if (*n) { // no-warning
+  if (*n) { // expected-warning{{Branch condition evaluates to a garbage value [core.uninitialized.Branch]}}
 delete n;
 return 0;
   }
@@ -193,6 +188,10 @@
   return 1;
 }
 
+//===--===//
+// Incorrectly-modelled behavior.
+//===--===//
+
 int testNoInitializationPlacement() {
   int n;
   new (&n) int;
Index: clang/test/Analysis/new-ctor-recursive.cpp
===
--- clang/test/Analysis/new-ctor-recursive.cpp
+++ clang/test/Analysis/new-ctor-recursive.cpp
@@ -51,11

[PATCH] D127910: [Clang][AArch64] Add SME C intrinsics for load and store

2022-10-26 Thread David Sherwood via Phabricator via cfe-commits
david-arm added a comment.

Hi @sagarkulkarni19, just a gentle ping to see if you are still planning to do 
more work on this patch?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127910

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


[PATCH] D133698: [clang][dataflow] Implement transferBranch

2022-10-26 Thread Gabor Marton via Phabricator via cfe-commits
martong added inline comments.



Comment at: clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp:165
 
+  TypeErasedDataflowAnalysis &Analysis;
   const StmtToEnvMap &StmtToEnv;

Actually, this member is not used, I am not sure why was this added. Anyway, I 
am removing this in a follow up commit.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133698

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


[PATCH] D136103: OpenMP asynchronous memory copy support

2022-10-26 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert accepted this revision.
jdoerfert added a comment.

LG, thanks for all the changes.


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

https://reviews.llvm.org/D136103

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


[clang] 5bd142c - [clang][dataflow] Remove unused 'Analysis' field from 'TerminatorVisitor'

2022-10-26 Thread Gabor Marton via cfe-commits

Author: Gabor Marton
Date: 2022-10-26T17:28:56+02:00
New Revision: 5bd142ca265d8243ecebb63ffed0c7afd3abf440

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

LOG: [clang][dataflow] Remove unused 'Analysis' field from 'TerminatorVisitor'

This is to silence the warning: private field 'Analysis' is not used

Added: 


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

Removed: 




diff  --git a/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp 
b/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
index ec6a8a3d2e525..11ebf4e986f62 100644
--- a/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
+++ b/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
@@ -80,10 +80,9 @@ using TerminatorVisitorRetTy = std::pair;
 class TerminatorVisitor
 : public ConstStmtVisitor {
 public:
-  TerminatorVisitor(TypeErasedDataflowAnalysis &Analysis,
-const StmtToEnvMap &StmtToEnv, Environment &Env,
+  TerminatorVisitor(const StmtToEnvMap &StmtToEnv, Environment &Env,
 int BlockSuccIdx, TransferOptions TransferOpts)
-  : Analysis(Analysis), StmtToEnv(StmtToEnv), Env(Env),
+  : StmtToEnv(StmtToEnv), Env(Env),
 BlockSuccIdx(BlockSuccIdx), TransferOpts(TransferOpts) {}
 
   TerminatorVisitorRetTy VisitIfStmt(const IfStmt *S) {
@@ -162,7 +161,6 @@ class TerminatorVisitor
 return {&Cond, ConditionValue};
   }
 
-  TypeErasedDataflowAnalysis &Analysis;
   const StmtToEnvMap &StmtToEnv;
   Environment &Env;
   int BlockSuccIdx;
@@ -255,7 +253,7 @@ computeBlockInputState(const CFGBlock &Block, 
AnalysisContext &AC) {
   if (const Stmt *PredTerminatorStmt = Pred->getTerminatorStmt()) {
 const StmtToEnvMapImpl StmtToEnv(AC.CFCtx, AC.BlockStates);
 auto [Cond, CondValue] =
-TerminatorVisitor(Analysis, StmtToEnv, PredState.Env,
+TerminatorVisitor(StmtToEnv, PredState.Env,
   blockIndexInPredecessor(*Pred, Block),
   *BuiltinTransferOpts)
 .Visit(PredTerminatorStmt);



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


[PATCH] D133698: [clang][dataflow] Implement transferBranch

2022-10-26 Thread Gabor Marton via Phabricator via cfe-commits
martong added inline comments.



Comment at: clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp:165
 
+  TypeErasedDataflowAnalysis &Analysis;
   const StmtToEnvMap &StmtToEnv;

martong wrote:
> Actually, this member is not used, I am not sure why was this added. Anyway, 
> I am removing this in a follow up commit.
https://github.com/llvm/llvm-project/commit/5bd142ca265d8243ecebb63ffed0c7afd3abf440


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133698

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


[PATCH] D136080: [flang] Add -ffp-contract option processing

2022-10-26 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski added a comment.

Thanks for all the updates, Tom! I have a few more suggestions.

From the summary:

> implement these pragmas

Could you explain what pragmas you are referring to here? (i.e. Clang pragmas 
for C and C++ + link)

> gfortran uses "fast" by default

For our future self, could you add a link as well?




Comment at: clang/include/clang/Driver/Options.td:1925
   " | fast-honor-pragmas (fuses across statements unless diectated by 
pragmas)."
-  " Default is 'fast' for CUDA, 'fast-honor-pragmas' for HIP, and 'on' 
otherwise.">,
+  " Default is 'fast' for CUDA, 'fast-honor-pragmas' for HIP, 'off' for flang, 
and 'on' otherwise.">,
+  HelpText<"Form fused FP ops (e.g. FMAs)">,

I still think that we shouldn't be making references to Flang in Clang 
documentation. And this `DocBrief` is only used by Clang. Also, "flang" is 
problematic - what do you mean by "flang"?



Comment at: clang/lib/Driver/ToolChains/Flang.cpp:91-98
+} else if (Val.equals("fast-honor-pragmas")) {
+  D.Diag(diag::warn_drv_unsupported_option_for_flang)
+  << Val << A->getOption().getName() << "fast";
+  FPContract = "fast";
+} else if (Val.equals("on")) {
+  D.Diag(diag::warn_drv_unsupported_option_for_flang)
+  << Val << A->getOption().getName() << "off";

Some "unsupported" options are treated as errors and some are warnings. I think 
that for the sake of consistency it would be better to keep them all as errors. 
Also, why not use `Val` instead of e.g. "off"?


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

https://reviews.llvm.org/D136080

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


[PATCH] D136474: [CodeView][clang] Disable emitting command line into CodeView by default and add flag to enable

2022-10-26 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added a comment.

In D136474#3884248 , @thakis wrote:

>> This is true, but the cc1 flag isn't inherently non-deterministic. I would 
>> prefer to fix the determinism bugs instead of adding flags and more 
>> divergence.
>
> See https://reviews.llvm.org/D136474#3875546

I read that, and I'm indicating that I don't agree. Chromium's requirements are 
driven by its particular usage of a cross-compiling distributed build system, 
which may not represent the average user's needs. Ubisoft's use case is also 
somewhat specialized, but IMO we really ought to write down the command line in 
the debug info. IMO it's useful. Sorry I don't have time to construct a more 
persuasive argument.

If you are still set on this course and don't want to try to address the 
determinism other ways, this flag seems fine to me, but I don't think it should 
be the default behavior. Does that provide a way forward?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136474

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


  1   2   3   >