[PATCH] D134105: [Docs] Add a link that refers to C++ standard modules in Clang modules doc

2022-09-17 Thread Jun Zhang via Phabricator via cfe-commits
junaire added a comment.

F24597444: image.png 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134105

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


[PATCH] D134105: [Docs] Add a link that refers to C++ standard modules in Clang modules doc

2022-09-17 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 461040.
junaire added a comment.

I bet now it rendered correctly.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134105

Files:
  clang/docs/Modules.rst


Index: clang/docs/Modules.rst
===
--- clang/docs/Modules.rst
+++ clang/docs/Modules.rst
@@ -102,6 +102,11 @@
 =
 To enable modules, pass the command-line flag ``-fmodules``. This will make 
any modules-enabled software libraries available as modules as well as 
introducing any modules-specific syntax. Additional `command-line parameters`_ 
are described in a separate section later.
 
+Standard C++ Modules
+
+.. note::
+  This pages mainly talks about the Clang modules extension and describes some 
general module properties and semantics. Please refer to 
`StandardCPlusPlusModules `_ if you're looking 
for standard C++ modules.
+
 Objective-C Import declaration
 --
 Objective-C provides syntax for importing a module via an *@import 
declaration*, which imports the named module:


Index: clang/docs/Modules.rst
===
--- clang/docs/Modules.rst
+++ clang/docs/Modules.rst
@@ -102,6 +102,11 @@
 =
 To enable modules, pass the command-line flag ``-fmodules``. This will make any modules-enabled software libraries available as modules as well as introducing any modules-specific syntax. Additional `command-line parameters`_ are described in a separate section later.
 
+Standard C++ Modules
+
+.. note::
+  This pages mainly talks about the Clang modules extension and describes some general module properties and semantics. Please refer to `StandardCPlusPlusModules `_ if you're looking for standard C++ modules.
+
 Objective-C Import declaration
 --
 Objective-C provides syntax for importing a module via an *@import declaration*, which imports the named module:
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D133737: [HLSL] [clang] Add vector version of abs for HLSL

2022-09-17 Thread Xiang Li via Phabricator via cfe-commits
python3kgae updated this revision to Diff 461039.
python3kgae added a comment.

Only allow redecl custom type checking builtin for HLSL.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133737

Files:
  clang/lib/AST/ASTContext.cpp
  clang/lib/Headers/hlsl/hlsl_intrinsics.h
  clang/test/CodeGenHLSL/builtins/abs.hlsl

Index: clang/test/CodeGenHLSL/builtins/abs.hlsl
===
--- clang/test/CodeGenHLSL/builtins/abs.hlsl
+++ clang/test/CodeGenHLSL/builtins/abs.hlsl
@@ -1,57 +1,138 @@
 // RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \
 // RUN:   dxil-pc-shadermodel6.3-library %s -fnative-half-type \
-// RUN:   -emit-llvm -disable-llvm-passes -o - | FileCheck %s
+// RUN:   -emit-llvm -disable-llvm-passes -O3 -o - | FileCheck %s
 // RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \
 // RUN:   dxil-pc-shadermodel6.3-library %s -emit-llvm -disable-llvm-passes \
-// RUN:   -o - | FileCheck %s --check-prefix=NO_HALF
+// RUN:   -D__HLSL_ENABLE_16_BIT -o - | FileCheck %s --check-prefix=NO_HALF
 
 
-float abs_float(float X) {
-  return abs(X);
+// CHECK: define noundef signext i16 @
+// FIXME: int16_t is promoted to i32 now. Change to abs.i16 once it is fixed.
+// CHECK: call i32 @llvm.abs.i32(
+int16_t test_abs_int16_t ( int16_t p0 ) {
+  return abs ( p0 );
 }
-
-// CHECK: define noundef float @"?abs_float@@YAMM@Z"(
-// CHECK: call float @llvm.fabs.f32(float %0)
-
-double abs_double(double X) {
-  return abs(X);
+// CHECK: define noundef <2 x i16> @
+// CHECK: call <2 x i16> @llvm.abs.v2i16(
+int16_t2 test_abs_int16_t2 ( int16_t2 p0 ) {
+  return abs ( p0 );
 }
-
-// CHECK: define noundef double @"?abs_double@@YANN@Z"(
-// CHECK: call double @llvm.fabs.f64(double %0)
-
-half abs_half(half X) {
-  return abs(X);
+// CHECK: define noundef <3 x i16> @
+// CHECK: call <3 x i16> @llvm.abs.v3i16(
+int16_t3 test_abs_int16_t3 ( int16_t3 p0 ) {
+  return abs ( p0 );
 }
-
-// CHECK: define noundef half @"?abs_half@@YA$f16@$f16@@Z"(
-// CHECK: call half @llvm.fabs.f16(half %0)
-// NO_HALF: define noundef float @"?abs_half@@YA$halff@$halff@@Z"(
+// CHECK: define noundef <4 x i16> @
+// CHECK: call <4 x i16> @llvm.abs.v4i16(
+int16_t4 test_abs_int16_t4 ( int16_t4 p0 ) {
+  return abs ( p0 );
+}
+// CHECK: define noundef half @
+// CHECK: call half @llvm.fabs.f16(
+// NO_HALF: define noundef float @"?test_abs_half@@YA$halff@$halff@@Z"(
 // NO_HALF: call float @llvm.fabs.f32(float %0)
-
-int abs_int(int X) {
-  return abs(X);
+half test_abs_half ( half p0 ) {
+  return abs ( p0 );
 }
-
-// NO_HALF: define noundef i32 @"?abs_int@@YAHH@Z"(i32
-// CHECK: define noundef i32 @"?abs_int@@YAHH@Z"(i32
-// CHECK: [[A_ADDR:%.*]] = alloca i32, align 4
-// CHECK-NEXT:store i32 [[A:%.*]], ptr [[A_ADDR]], align 4
-// CHECK-NEXT:[[TMP0:%.*]] = load i32, ptr [[A_ADDR]], align 4
-// CHECK-NEXT:[[NEG:%.*]] = sub nsw i32 0, [[TMP0]]
-// CHECK-NEXT:[[ABSCOND:%.*]] = icmp slt i32 [[TMP0]], 0
-// CHECK-NEXT:[[ABS:%.*]] = select i1 [[ABSCOND]], i32 [[NEG]], i32 [[TMP0]]
-// CHECK-NEXT:ret i32 [[ABS]]
-
-int64_t abs_int64(int64_t X) {
-  return abs(X);
+// CHECK: define noundef <2 x half> @
+// CHECK: call <2 x half> @llvm.fabs.v2f16(
+// NO_HALF: define noundef <2 x float> @"?test_abs_half2@@YAT?$__vector@$halff@$01@__clang@@T12@@Z"(
+// NO_HALF: call <2 x float> @llvm.fabs.v2f32(
+half2 test_abs_half2 ( half2 p0 ) {
+  return abs ( p0 );
+}
+// CHECK: define noundef <3 x half> @
+// CHECK: call <3 x half> @llvm.fabs.v3f16(
+// NO_HALF: define noundef <3 x float> @"?test_abs_half3@@YAT?$__vector@$halff@$02@__clang@@T12@@Z"(
+// NO_HALF: call <3 x float> @llvm.fabs.v3f32(
+half3 test_abs_half3 ( half3 p0 ) {
+  return abs ( p0 );
+}
+// CHECK: define noundef <4 x half> @
+// CHECK: call <4 x half> @llvm.fabs.v4f16(
+// NO_HALF: define noundef <4 x float> @"?test_abs_half4@@YAT?$__vector@$halff@$03@__clang@@T12@@Z"(
+// NO_HALF: call <4 x float> @llvm.fabs.v4f32(
+half4 test_abs_half4 ( half4 p0 ) {
+  return abs ( p0 );
+}
+// CHECK: define noundef i32 @
+// CHECK: call i32 @llvm.abs.i32(
+// NO_HALF: define noundef i32 @"?test_abs_int@@YAHH@Z"
+int test_abs_int ( int p0 ) {
+  return abs ( p0 );
+}
+// CHECK: define noundef <2 x i32> @
+// CHECK: call <2 x i32> @llvm.abs.v2i32(
+int2 test_abs_int2 ( int2 p0 ) {
+  return abs ( p0 );
+}
+// CHECK: define noundef <3 x i32> @
+// CHECK: call <3 x i32> @llvm.abs.v3i32(
+int3 test_abs_int3 ( int3 p0 ) {
+  return abs ( p0 );
+}
+// CHECK: define noundef <4 x i32> @
+// CHECK: call <4 x i32> @llvm.abs.v4i32(
+int4 test_abs_int4 ( int4 p0 ) {
+  return abs ( p0 );
+}
+// CHECK: define noundef float @
+// CHECK: call float @llvm.fabs.f32(
+float test_abs_float ( float p0 ) {
+  return abs ( p0 );
+}
+// CHECK: define noundef <2 x float> @
+// CHECK: call <2 x float> @llvm.fabs.v2f32(
+float2 t

[PATCH] D82087: AMDGPU/clang: Add builtins for llvm.amdgcn.ballot

2022-09-17 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert added a comment.
Herald added a subscriber: kosarev.
Herald added a project: All.

Can we land this? I'd like to use the new intrinsics as I don't understand the 
old ones.


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

https://reviews.llvm.org/D82087

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


[PATCH] D132990: [Clang] Fix compat diagnostic to detect a nontype template parameter has a placeholder type using getContainedAutoType()

2022-09-17 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added inline comments.



Comment at: clang/docs/ReleaseNotes.rst:149-151
+- Fix C++17 compatibibility warning that checks for use of auto in template
+  parameters so that it atually has an AutoType before attempting to call
+  getContainedAutoType(). This Fixes

'compatibility' mispelled.

Though since this is a user facing document, I would try to give a less 
mechanical / less local explanation of the problem.




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

https://reviews.llvm.org/D132990

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


[PATCH] D132990: [Clang] Fix compat diagnostic to detect a nontype template parameter has a placeholder type using getContainedAutoType()

2022-09-17 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik updated this revision to Diff 461033.
shafik added a comment.

- Add release notes.


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

https://reviews.llvm.org/D132990

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaTemplate.cpp
  clang/test/SemaTemplate/gh57362.cpp
  clang/test/SemaTemplate/temp_arg_nontype_diagnostic_cxx17.cpp


Index: clang/test/SemaTemplate/temp_arg_nontype_diagnostic_cxx17.cpp
===
--- /dev/null
+++ clang/test/SemaTemplate/temp_arg_nontype_diagnostic_cxx17.cpp
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++17 -Wpre-c++17-compat %s
+
+template  // expected-warning {{non-type template parameters 
declared with 'decltype(auto)' are incompatible with C++ standards before 
C++17}}
+struct B{};
+
+template  // expected-warning {{non-type template parameters declared 
with 'auto' are incompatible with C++ standards before C++17}}
+struct A{};
Index: clang/test/SemaTemplate/gh57362.cpp
===
--- /dev/null
+++ clang/test/SemaTemplate/gh57362.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 -Wpre-c++17-compat %s
+// expected-no-diagnostics
+
+namespace GH57362 {
+template 
+class TemplateClass {};
+
+template  // ok, no diagnostic expected
+void func() {}
+}
Index: clang/lib/Sema/SemaTemplate.cpp
===
--- clang/lib/Sema/SemaTemplate.cpp
+++ clang/lib/Sema/SemaTemplate.cpp
@@ -1531,11 +1531,11 @@
 
   CheckValidDeclSpecifiers();
 
-  if (TInfo->getType()->isUndeducedType()) {
-Diag(D.getIdentifierLoc(),
- diag::warn_cxx14_compat_template_nontype_parm_auto_type)
-  << QualType(TInfo->getType()->getContainedAutoType(), 0);
-  }
+  if (const auto *T = TInfo->getType()->getContainedDeducedType())
+if (isa(T))
+  Diag(D.getIdentifierLoc(),
+   diag::warn_cxx14_compat_template_nontype_parm_auto_type)
+  << QualType(TInfo->getType()->getContainedAutoType(), 0);
 
   assert(S->isTemplateParamScope() &&
  "Non-type template parameter not in template parameter scope!");
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -146,6 +146,12 @@
 - A SubstTemplateTypeParmType can now represent the pack index for a
   substitution from an expanded pack.
   `Issue 56099 `_
+- Fix C++17 compatibibility warning that checks for use of auto in template
+  parameters so that it atually has an AutoType before attempting to call
+  getContainedAutoType(). This Fixes
+  `Issue 57369 `_
+  `Issue 57643 `_
+  `Issue 57793 `_
 
 
 Improvements to Clang's diagnostics


Index: clang/test/SemaTemplate/temp_arg_nontype_diagnostic_cxx17.cpp
===
--- /dev/null
+++ clang/test/SemaTemplate/temp_arg_nontype_diagnostic_cxx17.cpp
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++17 -Wpre-c++17-compat %s
+
+template  // expected-warning {{non-type template parameters declared with 'decltype(auto)' are incompatible with C++ standards before C++17}}
+struct B{};
+
+template  // expected-warning {{non-type template parameters declared with 'auto' are incompatible with C++ standards before C++17}}
+struct A{};
Index: clang/test/SemaTemplate/gh57362.cpp
===
--- /dev/null
+++ clang/test/SemaTemplate/gh57362.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 -Wpre-c++17-compat %s
+// expected-no-diagnostics
+
+namespace GH57362 {
+template 
+class TemplateClass {};
+
+template  // ok, no diagnostic expected
+void func() {}
+}
Index: clang/lib/Sema/SemaTemplate.cpp
===
--- clang/lib/Sema/SemaTemplate.cpp
+++ clang/lib/Sema/SemaTemplate.cpp
@@ -1531,11 +1531,11 @@
 
   CheckValidDeclSpecifiers();
 
-  if (TInfo->getType()->isUndeducedType()) {
-Diag(D.getIdentifierLoc(),
- diag::warn_cxx14_compat_template_nontype_parm_auto_type)
-  << QualType(TInfo->getType()->getContainedAutoType(), 0);
-  }
+  if (const auto *T = TInfo->getType()->getContainedDeducedType())
+if (isa(T))
+  Diag(D.getIdentifierLoc(),
+   diag::warn_cxx14_compat_template_nontype_parm_auto_type)
+  << QualType(TInfo->getType()->getContainedAutoType(), 0);
 
   assert(S->isTemplateParamScope() &&
  "Non-type template parameter not in template parameter scope!");
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/Rel

[PATCH] D134115: [clang] Store in exprs the deduced arguments for function calls.

2022-09-17 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov created this revision.
Herald added a subscriber: martong.
Herald added a reviewer: shafik.
Herald added a reviewer: aaron.ballman.
Herald added a reviewer: NoQ.
Herald added a project: All.
mizvekov requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

WIP - Not ready for review

Signed-off-by: Matheus Izvekov 

Depends on D134113 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D134115

Files:
  clang/include/clang/AST/ASTImporter.h
  clang/include/clang/AST/Expr.h
  clang/include/clang/Sema/Overload.h
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/Expr.cpp
  clang/lib/Analysis/BodyFarm.cpp
  clang/lib/Sema/SemaCast.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaExprMember.cpp
  clang/lib/Sema/SemaInit.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTReaderStmt.cpp
  clang/lib/Serialization/ASTWriterStmt.cpp

Index: clang/lib/Serialization/ASTWriterStmt.cpp
===
--- clang/lib/Serialization/ASTWriterStmt.cpp
+++ clang/lib/Serialization/ASTWriterStmt.cpp
@@ -911,6 +911,10 @@
   Record.push_back(E->hadMultipleCandidates());
   Record.push_back(E->isNonOdrUse());
   Record.AddSourceLocation(E->getOperatorLoc());
+  if (E->Deduced)
+Record.AddTemplateArgumentList(E->Deduced);
+  else
+Record.push_back(0);
 
   if (HasFoundDecl) {
 DeclAccessPair FoundDecl = E->getFoundDecl();
Index: clang/lib/Serialization/ASTReaderStmt.cpp
===
--- clang/lib/Serialization/ASTReaderStmt.cpp
+++ clang/lib/Serialization/ASTReaderStmt.cpp
@@ -1027,6 +1027,7 @@
   E->MemberExprBits.HadMultipleCandidates = Record.readInt();
   E->MemberExprBits.NonOdrUseReason = Record.readInt();
   E->MemberExprBits.OperatorLoc = Record.readSourceLocation();
+  E->Deduced = Record.readTemplateArgumentList();
 
   if (HasQualifier || HasFoundDecl) {
 DeclAccessPair FoundDecl;
Index: clang/lib/Serialization/ASTReader.cpp
===
--- clang/lib/Serialization/ASTReader.cpp
+++ clang/lib/Serialization/ASTReader.cpp
@@ -8847,6 +8847,15 @@
 TemplArgs.push_back(readTemplateArgument(Canonicalize));
 }
 
+const TemplateArgumentList *
+ASTRecordReader::readTemplateArgumentList(bool Canonicalize) {
+  SmallVector Args;
+  readTemplateArgumentList(Args, Canonicalize);
+  if (Args.size() == 0)
+return nullptr;
+  return TemplateArgumentList::CreateCopy(getContext(), Args);
+}
+
 /// Read a UnresolvedSet structure.
 void ASTRecordReader::readUnresolvedSet(LazyASTUnresolvedSet &Set) {
   unsigned NumDecls = readInt();
Index: clang/lib/Sema/SemaTemplateDeduction.cpp
===
--- clang/lib/Sema/SemaTemplateDeduction.cpp
+++ clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -3740,6 +3740,11 @@
   if (R.IsAddressOfOperand)
 TDF |= TDF_IgnoreQualifiers;
 
+  // Gather the explicit template arguments, if any.
+  TemplateArgumentListInfo ExplicitTemplateArgs;
+  if (Ovl->hasExplicitTemplateArgs())
+Ovl->copyTemplateArgumentsInto(ExplicitTemplateArgs);
+
   // C++0x [temp.deduct.call]p6:
   //   When P is a function type, pointer to function type, or pointer
   //   to member function type:
@@ -3749,8 +3754,9 @@
   !ParamType->isMemberFunctionPointerType()) {
 if (Ovl->hasExplicitTemplateArgs()) {
   // But we can still look for an explicit specialization.
-  if (FunctionDecl *ExplicitSpec
-= S.ResolveSingleFunctionTemplateSpecialization(Ovl))
+  if (FunctionDecl *ExplicitSpec =
+  S.ResolveSingleFunctionTemplateSpecialization(
+  Ovl, ExplicitTemplateArgs))
 return GetTypeOfFunction(S, R, ExplicitSpec);
 }
 
@@ -3762,10 +3768,6 @@
 return {};
   }
 
-  // Gather the explicit template arguments, if any.
-  TemplateArgumentListInfo ExplicitTemplateArgs;
-  if (Ovl->hasExplicitTemplateArgs())
-Ovl->copyTemplateArgumentsInto(ExplicitTemplateArgs);
   QualType Match;
   for (UnresolvedSetIterator I = Ovl->decls_begin(),
  E = Ovl->decls_end(); I != E; ++I) {
Index: clang/lib/Sema/SemaTemplate.cpp
===
--- clang/lib/Sema/SemaTemplate.cpp
+++ clang/lib/Sema/SemaTemplate.cpp
@@ -7475,7 +7475,7 @@
 if (DiagnoseUseOfDecl(Fn, Arg->getBeginLoc()))
   return ExprError();
 
-Arg = FixOverloadedFunctionReference(Arg, FoundResult, Fn);
+Arg = FixOverloadedFunctionReference(Arg, FoundResult, Fn, nullptr);
 ArgType = Arg->getType();
   } else
 return ExprError();
@@ -752

[PATCH] D134057: [clang][Interp] Start implementing record types

2022-09-17 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added inline comments.



Comment at: clang/lib/AST/Interp/ByteCodeExprGen.cpp:316
+  // Base above gives us a pointer on the stack.
+  const auto *FD = dyn_cast(Member);
+  assert(FD);

tbaeder wrote:
> erichkeane wrote:
> > I THINK Member is a ValueDecl because it could be a member function, right? 
> >  So forcing it to be a FieldDecl here is likely not valid.  Perhaps in the 
> > 'non-FieldDecl' case we could jsut return false for now?
> > 
> > ALSO, don't do a dyn_cast followed by an assert, `cast` will do the assert 
> > for you.
> Right, I was just trying to limit the code to the subset I've implemented for 
> now. I can try to make it more defensive.
Also I believe this can also be an `IndirectFieldDecl` (anonymous union 
members) or a `ValueDecl` for static data members. 

Maybe outline what is left to fill in a comment?



Comment at: clang/lib/AST/Interp/ByteCodeExprGen.cpp:673
+  if (Optional T = classify(Init->getType())) {
+if (!this->emitDupPtr(Initializer))
+  return false;

This section of code looks duplicated w/ the above, can it be factored out or 
will they diverge as you fill in more details?



Comment at: clang/test/AST/Interp/records.cpp:7
+
+struct Ints {
+  int a = 20;

How about also have a field that is a struct and initializing that.

Also using initializer lists in in class member initializers and also 
designated initializers as well. 

I am not sure if unions works yet but anon union members as well.


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

https://reviews.llvm.org/D134057

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


[PATCH] D134103: [clang-format] Skip token annotation in passes that don't need it

2022-09-17 Thread Owen Pan via Phabricator via cfe-commits
owenpan added inline comments.



Comment at: clang/lib/Format/Format.cpp:3276
   Passes.emplace_back([&](const Environment &Env) {
-return BracesInserter(Env, Expanded).process();
+return BracesInserter(Env, Expanded).process(/*SkipsAnnotation=*/true);
   });

HazardyKnusperkeks wrote:
> Superfluous s here and in all comments. :)
Thanks! Will fix them before landing.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134103

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


[PATCH] D133643: [analyzer] Cleanup some artifacts from non-POD array evaluation

2022-09-17 Thread Domján Dániel via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG6931d311eaf4: [analyzer] Cleanup some artifacts from non-POD 
array evaluation (authored by isuckatcs).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133643

Files:
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
  clang/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp

Index: clang/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
===
--- clang/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
+++ clang/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
@@ -222,6 +222,26 @@
   return 0;
 }
 
+ProgramStateRef ExprEngine::removeStateTraitsUsedForArrayEvaluation(
+ProgramStateRef State, const CXXConstructExpr *E,
+const LocationContext *LCtx) {
+
+  assert(LCtx && "Location context must be provided!");
+
+  if (E) {
+if (getPendingInitLoop(State, E, LCtx))
+  State = removePendingInitLoop(State, E, LCtx);
+
+if (getIndexOfElementToConstruct(State, E, LCtx))
+  State = removeIndexOfElementToConstruct(State, E, LCtx);
+  }
+
+  if (getPendingArrayDestruction(State, LCtx))
+State = removePendingArrayDestruction(State, LCtx);
+
+  return State;
+}
+
 /// The call exit is simulated with a sequence of nodes, which occur between
 /// CallExitBegin and CallExitEnd. The following operations occur between the
 /// two program points:
@@ -268,9 +288,6 @@
 
   auto ThisVal = svalBuilder.getCXXThis(DtorDecl->getParent(), calleeCtx);
   state = state->killBinding(ThisVal);
-
-  if (!ShouldRepeatCall)
-state = removePendingArrayDestruction(state, callerCtx);
 }
   }
 
@@ -304,14 +321,6 @@
   state = state->BindExpr(CCE, callerCtx, ThisV);
 
   ShouldRepeatCall = shouldRepeatCtorCall(state, CCE, callerCtx);
-
-  if (!ShouldRepeatCall) {
-if (getIndexOfElementToConstruct(state, CCE, callerCtx))
-  state = removeIndexOfElementToConstruct(state, CCE, callerCtx);
-
-if (getPendingInitLoop(state, CCE, callerCtx))
-  state = removePendingInitLoop(state, CCE, callerCtx);
-  }
 }
 
 if (const auto *CNE = dyn_cast(CE)) {
@@ -330,6 +339,11 @@
 }
   }
 
+  if (!ShouldRepeatCall) {
+state = removeStateTraitsUsedForArrayEvaluation(
+state, dyn_cast_or_null(CE), callerCtx);
+  }
+
   // Step 3: BindedRetNode -> CleanedNodes
   // If we can find a statement and a block in the inlined function, run remove
   // dead bindings before returning from the call. This is important to ensure
@@ -1151,7 +1165,7 @@
 
   // Check if we're inside an ArrayInitLoopExpr, and it's sufficiently small.
   if (auto Size = getPendingInitLoop(State, CE, LCtx))
-return *Size <= AMgr.options.maxBlockVisitOnPath;
+return shouldInlineArrayDestruction(*Size);
 
   return false;
 }
@@ -1246,7 +1260,12 @@
 }
   }
 
-  // If we can't inline it, handle the return value and invalidate the regions.
+  // If we can't inline it, clean up the state traits used only if the function
+  // is inlined.
+  State = removeStateTraitsUsedForArrayEvaluation(
+  State, dyn_cast_or_null(E), Call->getLocationContext());
+
+  // Also handle the return value and invalidate the regions.
   conservativeEvalCall(*Call, Bldr, Pred, State);
 }
 
Index: clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
===
--- clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
+++ clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
@@ -970,6 +970,11 @@
const CXXConstructExpr *E,
const LocationContext *LCtx);
 
+  static ProgramStateRef
+  removeStateTraitsUsedForArrayEvaluation(ProgramStateRef State,
+  const CXXConstructExpr *E,
+  const LocationContext *LCtx);
+
   /// Store the location of a C++ object corresponding to a statement
   /// until the statement is actually encountered. For example, if a DeclStmt
   /// has CXXConstructExpr as its initializer, the object would be considered
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 6931d31 - [analyzer] Cleanup some artifacts from non-POD array evaluation

2022-09-17 Thread via cfe-commits

Author: isuckatcs
Date: 2022-09-17T22:46:27+02:00
New Revision: 6931d311eaf483b35d5428ef6db15c0ba9e49840

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

LOG: [analyzer] Cleanup some artifacts from non-POD array evaluation

Most of the state traits used for non-POD array evaluation were
only cleaned up if the ctors/dtors were inlined, since the cleanup
happened in ExprEngine::processCallExit(). This patch makes sure
they are removed even if said functions are not inlined.

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

Added: 


Modified: 
clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
clang/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp

Removed: 




diff  --git 
a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h 
b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
index aafeb5e39acb4..a905f9097750d 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
@@ -970,6 +970,11 @@ class ExprEngine {
const CXXConstructExpr *E,
const LocationContext *LCtx);
 
+  static ProgramStateRef
+  removeStateTraitsUsedForArrayEvaluation(ProgramStateRef State,
+  const CXXConstructExpr *E,
+  const LocationContext *LCtx);
+
   /// Store the location of a C++ object corresponding to a statement
   /// until the statement is actually encountered. For example, if a DeclStmt
   /// has CXXConstructExpr as its initializer, the object would be considered

diff  --git a/clang/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp 
b/clang/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
index 953b819baa303..dbfded29c1ae4 100644
--- a/clang/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
+++ b/clang/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
@@ -222,6 +222,26 @@ static unsigned getElementCountOfArrayBeingDestructed(
   return 0;
 }
 
+ProgramStateRef ExprEngine::removeStateTraitsUsedForArrayEvaluation(
+ProgramStateRef State, const CXXConstructExpr *E,
+const LocationContext *LCtx) {
+
+  assert(LCtx && "Location context must be provided!");
+
+  if (E) {
+if (getPendingInitLoop(State, E, LCtx))
+  State = removePendingInitLoop(State, E, LCtx);
+
+if (getIndexOfElementToConstruct(State, E, LCtx))
+  State = removeIndexOfElementToConstruct(State, E, LCtx);
+  }
+
+  if (getPendingArrayDestruction(State, LCtx))
+State = removePendingArrayDestruction(State, LCtx);
+
+  return State;
+}
+
 /// The call exit is simulated with a sequence of nodes, which occur between
 /// CallExitBegin and CallExitEnd. The following operations occur between the
 /// two program points:
@@ -268,9 +288,6 @@ void ExprEngine::processCallExit(ExplodedNode *CEBNode) {
 
   auto ThisVal = svalBuilder.getCXXThis(DtorDecl->getParent(), calleeCtx);
   state = state->killBinding(ThisVal);
-
-  if (!ShouldRepeatCall)
-state = removePendingArrayDestruction(state, callerCtx);
 }
   }
 
@@ -304,14 +321,6 @@ void ExprEngine::processCallExit(ExplodedNode *CEBNode) {
   state = state->BindExpr(CCE, callerCtx, ThisV);
 
   ShouldRepeatCall = shouldRepeatCtorCall(state, CCE, callerCtx);
-
-  if (!ShouldRepeatCall) {
-if (getIndexOfElementToConstruct(state, CCE, callerCtx))
-  state = removeIndexOfElementToConstruct(state, CCE, callerCtx);
-
-if (getPendingInitLoop(state, CCE, callerCtx))
-  state = removePendingInitLoop(state, CCE, callerCtx);
-  }
 }
 
 if (const auto *CNE = dyn_cast(CE)) {
@@ -330,6 +339,11 @@ void ExprEngine::processCallExit(ExplodedNode *CEBNode) {
 }
   }
 
+  if (!ShouldRepeatCall) {
+state = removeStateTraitsUsedForArrayEvaluation(
+state, dyn_cast_or_null(CE), callerCtx);
+  }
+
   // Step 3: BindedRetNode -> CleanedNodes
   // If we can find a statement and a block in the inlined function, run remove
   // dead bindings before returning from the call. This is important to ensure
@@ -1151,7 +1165,7 @@ bool ExprEngine::shouldInlineArrayConstruction(const 
ProgramStateRef State,
 
   // Check if we're inside an ArrayInitLoopExpr, and it's sufficiently small.
   if (auto Size = getPendingInitLoop(State, CE, LCtx))
-return *Size <= AMgr.options.maxBlockVisitOnPath;
+return shouldInlineArrayDestruction(*Size);
 
   return false;
 }
@@ -1246,7 +1260,12 @@ void ExprEngine::defaultEvalCall(NodeBuilder &Bldr, 
ExplodedNode *Pred,
 }
   }
 
-  // If we can't inline it, handle the return value and invalidate the regions.
+  // If we can't inli

[clang] 8009d23 - [clang] Don't include SetVector.h (NFC)

2022-09-17 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2022-09-17T13:36:13-07:00
New Revision: 8009d236e5ed3225f31364198f8dd2f4ae6a8691

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

LOG: [clang] Don't include SetVector.h (NFC)

Added: 


Modified: 
clang/lib/AST/CXXInheritance.cpp
clang/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp

Removed: 




diff  --git a/clang/lib/AST/CXXInheritance.cpp 
b/clang/lib/AST/CXXInheritance.cpp
index 96a6f344be7c9..1abbe8139ae99 100644
--- a/clang/lib/AST/CXXInheritance.cpp
+++ b/clang/lib/AST/CXXInheritance.cpp
@@ -22,7 +22,6 @@
 #include "clang/Basic/LLVM.h"
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/STLExtras.h"
-#include "llvm/ADT/SetVector.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/iterator_range.h"
 #include "llvm/Support/Casting.h"

diff  --git a/clang/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp 
b/clang/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp
index 9ee6ef4f9519f..4618d17577dd8 100644
--- a/clang/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp
+++ b/clang/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp
@@ -15,7 +15,6 @@
 #include "clang/StaticAnalyzer/Core/AnalyzerOptions.h"
 #include "clang/StaticAnalyzer/Core/CheckerManager.h"
 #include "llvm/ADT/STLExtras.h"
-#include "llvm/ADT/SetVector.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/DynamicLibrary.h"



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


[PATCH] D133659: [Clang] P1169R4: static operator()

2022-09-17 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson updated this revision to Diff 461026.
royjacobson added a comment.

Added tests for 'this' lambda captures and for the pre-cxx2b compatability 
warnings.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133659

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/OperatorKinds.def
  clang/include/clang/Sema/DeclSpec.h
  clang/include/clang/Sema/Sema.h
  clang/lib/Frontend/InitPreprocessor.cpp
  clang/lib/Parse/ParseExprCXX.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaLambda.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/lib/Sema/TreeTransform.h
  clang/test/CXX/over/over.match/over.match.best/over.best.ics/p6.cpp
  clang/test/CXX/over/over.oper/p7.cpp
  clang/test/CodeGenCXX/cxx2b-static-call-operator.cpp
  clang/test/Parser/cxx2b-lambdas-ext-warns.cpp
  clang/test/Parser/cxx2b-lambdas.cpp
  clang/test/SemaCXX/lambda-unevaluated.cpp
  clang/test/SemaCXX/overloaded-operator-decl.cpp
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -1481,7 +1481,7 @@
 
   static operator()
   https://wg21.link/P1169R4";>P1169R4
-  No
+  Clang 16
 
 
   Extended floating-point types and standard names
Index: clang/test/SemaCXX/overloaded-operator-decl.cpp
===
--- clang/test/SemaCXX/overloaded-operator-decl.cpp
+++ clang/test/SemaCXX/overloaded-operator-decl.cpp
@@ -51,7 +51,7 @@
 
 namespace PR14120 {
   struct A {
-static void operator()(int& i) { ++i; } // expected-error{{overloaded 'operator()' cannot be a static member function}}
+static void operator()(int& i) { ++i; } // expected-error{{overloaded 'operator()' cannot be declared static}}
   };
   void f() {
 int i = 0;
Index: clang/test/SemaCXX/lambda-unevaluated.cpp
===
--- clang/test/SemaCXX/lambda-unevaluated.cpp
+++ clang/test/SemaCXX/lambda-unevaluated.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -std=c++20 %s -verify
+// RUN: %clang_cc1 -std=c++2b %s -verify
 
 
 template  struct Nothing {};
@@ -120,3 +121,28 @@
 void foo(decltype(+[](T) {}) lambda, T param);
 static_assert(!__is_same(decltype(foo), void));
 } // namespace GH51641
+
+#if __cplusplus > 202002L
+namespace StaticLambdas {
+template  struct Nothing {};
+Nothing<[]() static { return 0; }()> nothing;
+
+template  struct NothingT {};
+Nothing<[]() static { return 0; }> nothingT;
+
+template 
+concept True = [] static { return true; }();
+static_assert(True);
+
+static_assert(sizeof([] static { return 0; }));
+static_assert(sizeof([] static { return 0; }()));
+
+void f()  noexcept(noexcept([] static { return 0; }()));
+
+using a = decltype([] static { return 0; });
+using b = decltype([] static { return 0; }());
+using c = decltype([]() static noexcept(noexcept([] { return 0; }())) { return 0; });
+using d = decltype(sizeof([] static { return 0; }));
+
+}
+#endif
Index: clang/test/Parser/cxx2b-lambdas.cpp
===
--- clang/test/Parser/cxx2b-lambdas.cpp
+++ clang/test/Parser/cxx2b-lambdas.cpp
@@ -38,3 +38,31 @@
 auto XL4 = [] requires true {}; // expected-error{{expected body}}
 auto XL5 = [] requires true requires true {}; // expected-error{{expected body}}
 auto XL6 = [] requires true noexcept requires true {}; // expected-error{{expected body}}
+
+auto XL7 = []() static static {}; // expected-error {{cannot appear multiple times}}
+auto XL8 = []() static mutable {}; // expected-error {{cannot be both mutable and static}}
+auto XL9 = []() static consteval {};
+auto XL10 = []() static constexpr {};
+
+auto XL11 = [] static {};
+auto XL12 = []() static {};
+auto XL13 = []() static extern {};  // expected-error {{expected body of lambda expression}}
+auto XL14 = []() extern {};  // expected-error {{expected body of lambda expression}}
+
+
+void static_captures() {
+  int x;
+  auto SC1 = [&]() static {}; // expected-error {{a static lambda cannot have any captures}} // expected-note {{captures declared here}}
+  auto SC4 = [x]() static {}; // expected-error {{a static lambda cannot have any captures}} // expected-note {{captures declared here}}
+  auto SC2 = [&x]() static {}; // expected-error {{a static lambda cannot have any captures}} // expected-note {{captures declared here}}
+  auto SC3 = [y=x]() static {}; // expected-error {{a static lambda cannot have any captures}} // expected-note {{captures declared here}}
+  auto SC5 = [&y = x]() static {}; // expected-error {{a static lambda cannot have any captures}} // expected-note {{captures declared here}}
+  auto SC6 = [=]() static {}; /

[PATCH] D132285: [Clang][LoongArch] Implement ABI lowering

2022-09-17 Thread Renato Golin via Phabricator via cfe-commits
rengolin accepted this revision.
rengolin added a comment.
This revision is now accepted and ready to land.

I can't vouch for your ABI correctness, but you seem to have a lot of tests 
covering what you claim to have implemented, so looks good to me.

Thanks for opening an issue for RISC-V.

Clang's TargetInfo.cpp is really large, perhaps we should think about splitting 
it across different targets, but definitely NOT for this review.

Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132285

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


[PATCH] D133920: [X86][fastcall][vectorcall] Move capability check before free register update

2022-09-17 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added a comment.

Thanks, I have more comments, sorry I didn't add them on the first review.




Comment at: clang/lib/CodeGen/TargetInfo.cpp:1785
 
-  if (State.CC == llvm::CallingConv::X86_FastCall ||
-  State.CC == llvm::CallingConv::X86_VectorCall ||
-  State.CC == llvm::CallingConv::X86_RegCall) {
-if (getContext().getTypeSize(Ty) > 32)
-  return false;
+  if (!IsPtrOrInt && State.CC == llvm::CallingConv::X86_RegCall)
+return false;

I see, no intended behavior change for regcall.



Comment at: clang/lib/CodeGen/TargetInfo.cpp:1788-1791
+  if (IsMCUABI)
+return false;
 
   return true;

Seems like this can be simplified to:
  // Return true to apply inreg to all legal parameters except on for MCU 
targets.
  return !IsMCUABI;



Comment at: clang/test/CodeGen/mangle-windows.c:50
 void __fastcall f9(long long a, char b, char c, short d) {}
-// CHECK: define dso_local x86_fastcallcc void @"\01@f9@20"(i64 noundef %a, i8 
noundef signext %b, i8 noundef signext %c, i16 noundef signext %d)
+// CHECK: define dso_local x86_fastcallcc void @"\01@f9@20"(i64 noundef %a, i8 
inreg noundef signext %b, i8 inreg noundef signext %c, i16 noundef signext %d)
 // X64: define dso_local void @f9(

This file is intended to test the C mangling. Most of the other tests don't 
look at the IR prototype. I think a better home for both tests is:
../clang/test/CodeGen/stdcall-fastcall.c
../clang/test/CodeGen/vectorcall.c

Do we already have coverage for this case for regcall? Please ensure we have 
coverage or add it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133920

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


[PATCH] D133874: [clang] Implement sugar retention for converted template arguments

2022-09-17 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov edited the summary of this revision.
mizvekov updated this revision to Diff 461018.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133874

Files:
  clang/include/clang/Sema/Sema.h
  clang/include/clang/Sema/TemplateDeduction.h
  clang/lib/Sema/SemaLookup.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/test/SemaCXX/ppc-pair-mma-types.cpp
  clang/test/SemaTemplate/make_integer_seq.cpp

Index: clang/test/SemaTemplate/make_integer_seq.cpp
===
--- clang/test/SemaTemplate/make_integer_seq.cpp
+++ clang/test/SemaTemplate/make_integer_seq.cpp
@@ -53,7 +53,9 @@
 // CHECK-NEXT: |-TemplateArgument type 'int':'int'
 // CHECK-NEXT: | `-SubstTemplateTypeParmType 0x{{[0-9A-Fa-f]+}} 'int' sugar typename depth 0 index 1
 // CHECK-NEXT: |   |-BuiltinTemplate 0x{{[0-9A-Fa-f]+}} '__make_integer_seq'
-// CHECK-NEXT: |   `-BuiltinType 0x{{[0-9A-Fa-f]+}} 'int'
+// CHECK-NEXT: |   `-SubstTemplateTypeParmType 0x{{[0-9A-Fa-f]+}} 'int' sugar class depth 0 index 0 B1
+// CHECK-NEXT: | |-TypeAliasTemplate 0x{{[0-9A-Fa-f]+}} 'B'
+// CHECK-NEXT: | `-BuiltinType 0x{{[0-9A-Fa-f]+}} 'int'
 // CHECK-NEXT: |-TemplateArgument expr
 // CHECK-NEXT: | `-ConstantExpr 0x{{[0-9A-Fa-f]+}}  'int'
 // CHECK-NEXT: |   |-value: Int 0
@@ -63,7 +65,7 @@
 
 template  class S, class T, int N> struct C {
   using test3 = __make_integer_seq;
-//  CHECK: |-TypeAliasDecl 0x{{[0-9A-Fa-f]+}}  col:9 test3 '__make_integer_seq':'__make_integer_seq'
+//  CHECK: |-TypeAliasDecl 0x{{[0-9A-Fa-f]+}}  col:9 test3 '__make_integer_seq':'__make_integer_seq'
 // CHECK-NEXT:   `-ElaboratedType 0x{{[0-9A-Fa-f]+}} '__make_integer_seq' sugar dependent
 // CHECK-NEXT: `-TemplateSpecializationType 0x{{[0-9A-Fa-f]+}} '__make_integer_seq' sugar dependent alias __make_integer_seq
 // CHECK-NEXT:   |-TemplateArgument template S
@@ -82,7 +84,7 @@
 // CHECK-NEXT: `-DeclRefExpr 0x{{[0-9A-Fa-f]+}}  'int' NonTypeTemplateParm 0x{{[0-9A-Fa-f]+}} 'N' 'int'
 
   using test4 = __make_integer_seq;
-//  CHECK: |-TypeAliasDecl 0x{{[0-9A-Fa-f]+}}  col:9 test4 '__make_integer_seq':'__make_integer_seq'
+//  CHECK: |-TypeAliasDecl 0x{{[0-9A-Fa-f]+}}  col:9 test4 '__make_integer_seq':'__make_integer_seq'
 // CHECK-NEXT:   `-ElaboratedType 0x{{[0-9A-Fa-f]+}} '__make_integer_seq' sugar dependent
 // CHECK-NEXT: `-TemplateSpecializationType 0x{{[0-9A-Fa-f]+}} '__make_integer_seq' sugar dependent alias __make_integer_seq
 // CHECK-NEXT:   |-TemplateArgument template A
@@ -101,7 +103,7 @@
 // CHECK-NEXT: `-IntegerLiteral 0x{{[0-9A-Fa-f]+}}  'int' 1
 
   using test5 = __make_integer_seq;
-//  CHECK: `-TypeAliasDecl 0x{{[0-9A-Fa-f]+}}  col:9 test5 '__make_integer_seq':'__make_integer_seq'
+//  CHECK: `-TypeAliasDecl 0x{{[0-9A-Fa-f]+}}  col:9 test5 '__make_integer_seq':'__make_integer_seq'
 // CHECK-NEXT:   `-ElaboratedType 0x{{[0-9A-Fa-f]+}} '__make_integer_seq' sugar dependent
 // CHECK-NEXT: `-TemplateSpecializationType 0x{{[0-9A-Fa-f]+}} '__make_integer_seq' sugar dependent alias __make_integer_seq
 // CHECK-NEXT:   |-TemplateArgument template A
Index: clang/test/SemaCXX/ppc-pair-mma-types.cpp
===
--- clang/test/SemaCXX/ppc-pair-mma-types.cpp
+++ clang/test/SemaCXX/ppc-pair-mma-types.cpp
@@ -85,8 +85,8 @@
 
   // template argument
   template 
-  void testVQTemplate(T v, T *p) { // expected-note {{candidate template ignored: substitution failure [with T = __vector_quad]: invalid use of PPC MMA type}} \
- expected-note {{candidate template ignored: substitution failure [with T = __vector_quad]: invalid use of PPC MMA type}}
+  void testVQTemplate(T v, T *p) { // expected-note {{candidate template ignored: substitution failure [with T = vq_t]: invalid use of PPC MMA type}} \
+  expected-note {{candidate template ignored: substitution failure [with T = __vector_quad]: invalid use of PPC MMA type}}
 *(p + 1) = v;
   }
 
@@ -276,8 +276,8 @@
 
   // template argument
   template 
-  void testVPTemplate(T v, T *p) { // expected-note {{candidate template ignored: substitution failure [with T = __vector_pair]: invalid use of PPC MMA type}} \
- expected-note {{candidate template ignored: substitution failure [with T = __vector_pair]: invalid use of PPC MMA type}}
+  void testVPTemplate(T v, T *p) { // expected-note {{candidate template ignored: substitution failure [with T = vp_t]: invalid use of PPC MMA type}} \
+

[PATCH] D131858: [clang] Track the templated entity in type substitution.

2022-09-17 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov updated this revision to Diff 461017.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131858

Files:
  clang-tools-extra/clang-tidy/hicpp/ExceptionBaseclassCheck.cpp
  clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp
  clang-tools-extra/clangd/AST.cpp
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/ASTNodeTraverser.h
  clang/include/clang/AST/JSONNodeDumper.h
  clang/include/clang/AST/TextNodeDumper.h
  clang/include/clang/AST/Type.h
  clang/include/clang/AST/TypeProperties.td
  clang/include/clang/Sema/Template.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/ASTStructuralEquivalence.cpp
  clang/lib/AST/JSONNodeDumper.cpp
  clang/lib/AST/ODRHash.cpp
  clang/lib/AST/TextNodeDumper.cpp
  clang/lib/AST/Type.cpp
  clang/lib/AST/TypePrinter.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/SemaTemplateVariadic.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTReaderDecl.cpp
  clang/lib/Serialization/ASTWriterDecl.cpp
  clang/lib/StaticAnalyzer/Checkers/MismatchedIteratorChecker.cpp
  clang/test/AST/ast-dump-openmp-begin-declare-variant_reference.cpp
  clang/test/AST/ast-dump-template-decls.cpp
  clang/test/AST/deduction-guides.cpp
  clang/test/SemaTemplate/deduction-guide.cpp
  clang/test/SemaTemplate/make_integer_seq.cpp
  clang/test/SemaTemplate/type_pack_element.cpp
  libcxx/DELETE.ME

Index: libcxx/DELETE.ME
===
--- /dev/null
+++ libcxx/DELETE.ME
@@ -0,0 +1 @@
+D131858
Index: clang/test/SemaTemplate/type_pack_element.cpp
===
--- clang/test/SemaTemplate/type_pack_element.cpp
+++ clang/test/SemaTemplate/type_pack_element.cpp
@@ -11,14 +11,13 @@
 // CHECK-NEXT:   | `-IntegerLiteral 0x{{[0-9A-Fa-f]+}}  'int' 0
 // CHECK-NEXT:   |-TemplateArgument type 'int'
 // CHECK-NEXT:   | `-BuiltinType 0x{{[0-9A-Fa-f]+}} 'int'
-// CHECK-NEXT:   `-SubstTemplateTypeParmType 0x{{[0-9A-Fa-f]+}} 'int' sugar pack_index 0
-// CHECK-NEXT: |-TemplateTypeParmType 0x{{[0-9A-Fa-f]+}} 'auto' dependent depth 0 index 1
-// CHECK-NEXT: | `-TemplateTypeParm 0x{{[0-9A-Fa-f]+}} ''
+// CHECK-NEXT:   `-SubstTemplateTypeParmType 0x{{[0-9A-Fa-f]+}} 'int' sugar typename depth 0 index 1 ... pack_index 0
+// CHECK-NEXT: |-BuiltinTemplate 0x{{[0-9A-Fa-f]+}} '__type_pack_element'
 // CHECK-NEXT: `-BuiltinType 0x{{[0-9A-Fa-f]+}} 'int'
 
 template struct A {
   using test2 = __type_pack_element;
-//  CHECK: |-TypeAliasDecl 0x{{[0-9A-Fa-f]+}}  col:9 test2 '__type_pack_element':'__type_pack_element'
+//  CHECK: |-TypeAliasDecl 0x{{[0-9A-Fa-f]+}}  col:9 test2 '__type_pack_element':'__type_pack_element'
 // CHECK-NEXT:   `-ElaboratedType 0x{{[0-9A-Fa-f]+}} '__type_pack_element' sugar dependent
 // CHECK-NEXT: `-TemplateSpecializationType 0x{{[0-9A-Fa-f]+}} '__type_pack_element' sugar dependent alias __type_pack_element
 // CHECK-NEXT:   |-TemplateArgument expr
@@ -38,7 +37,7 @@
 // CHECK-NEXT:   `-TemplateTypeParmType 0x{{[0-9A-Fa-f]+}} 'type-parameter-0-1' dependent contains_unexpanded_pack depth 0 index 1 pack
 
   using test3 = __type_pack_element<0, Ts...>;
-//  CHECK: |-TypeAliasDecl 0x{{[0-9A-Fa-f]+}}  col:9 test3 '__type_pack_element<0, Ts...>':'__type_pack_element<0, type-parameter-0-1...>'
+//  CHECK: |-TypeAliasDecl 0x{{[0-9A-Fa-f]+}}  col:9 test3 '__type_pack_element<0, Ts...>':'__type_pack_element<0, type-parameter-0-1...>'
 // CHECK-NEXT:   `-ElaboratedType 0x{{[0-9A-Fa-f]+}} '__type_pack_element<0, Ts...>' sugar dependent
 // CHECK-NEXT: `-TemplateSpecializationType 0x{{[0-9A-Fa-f]+}} '__type_pack_element<0, Ts...>' sugar dependent alias __type_pack_element
 // CHECK-NEXT:   |-TemplateArgument expr
@@ -58,7 +57,7 @@
 // CHECK-NEXT:   `-TemplateTypeParmType 0x{{[0-9A-Fa-f]+}} 'type-parameter-0-1' dependent contains_unexpanded_pack depth 0 index 1 pack
 
   using test4 = __type_pack_element;
-//  CHECK: `-TypeAliasDecl 0x{{[0-9A-Fa-f]+}}  col:9 test4 '__type_pack_element':'__type_pack_element'
+//  CHECK: `-TypeAliasDecl 0x{{[0-9A-Fa-f]+}}  col:9 test4 '__type_pack_element':'__type_pack_element'
 // CHECK-NEXT:   `-ElaboratedType 0x{{[0-9A-Fa-f]+}} '__type_pack_element' sugar dependent
 // CHECK-NEXT: `-TemplateSpecializationType 0x{{[0-9A-Fa-f]+}} '__type_pack_element' sugar dependent alias __type_pack_element
 // CHECK-NEXT:   |-TemplateArgument expr
Index: clang/test/SemaTemplate/make_integer_seq.cpp
===
--- clang/test/SemaTemplate/make_inte

[PATCH] D132816: [clang] AST: SubstTemplateTypeParmType support for non-canonical underlying type

2022-09-17 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov edited the summary of this revision.
mizvekov updated this revision to Diff 461016.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132816

Files:
  clang/include/clang/AST/Type.h
  clang/include/clang/AST/TypeProperties.td
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/Type.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Sema/TreeTransform.h
  clang/test/AST/ast-dump-template-decls.cpp

Index: clang/test/AST/ast-dump-template-decls.cpp
===
--- clang/test/AST/ast-dump-template-decls.cpp
+++ clang/test/AST/ast-dump-template-decls.cpp
@@ -162,3 +162,22 @@
 // CHECK:  SubstTemplateTypeParmType 0x{{[^ ]*}} 'short' sugar pack_index 0
 // CHECK-NEXT: TemplateTypeParmType 0x{{[^ ]*}} 'U' dependent contains_unexpanded_pack depth 0 index 0 pack
 } // namespace PR56099
+
+namespace subst_default_argument {
+template class A {};
+template> class D1, class D2> using D = D1;
+
+template class E {};
+using test1 = D;
+// CHECK:  TypeAliasDecl 0x{{[^ ]*}}  col:7 test1 'D':'subst_default_argument::E>'
+// CHECK:  TemplateSpecializationType 0x{{[^ ]*}} 'A' sugar A
+// CHECK-NEXT: |-TemplateArgument type 'int':'int'
+// CHECK-NEXT: | `-SubstTemplateTypeParmType 0x{{[^ ]*}} 'int' sugar
+// CHECK-NEXT: |   |-TemplateTypeParmType 0x{{[^ ]*}} 'C1' dependent depth 1 index 0
+// CHECK-NEXT: |   | `-TemplateTypeParm 0x{{[^ ]*}} 'C1'
+// CHECK-NEXT: |   `-SubstTemplateTypeParmType 0x{{[^ ]*}} 'int' sugar
+// CHECK-NEXT: | |-TemplateTypeParmType 0x{{[^ ]*}} 'type-parameter-0-1' dependent depth 0 index 1
+// CHECK-NEXT: | `-BuiltinType 0x{{[^ ]*}} 'int'
+// CHECK-NEXT: `-RecordType 0x{{[^ ]*}} 'subst_default_argument::A'
+// CHECK-NEXT:   `-ClassTemplateSpecialization 0x{{[^ ]*}} 'A'
+} // namespace subst_default_argument
Index: clang/lib/Sema/TreeTransform.h
===
--- clang/lib/Sema/TreeTransform.h
+++ clang/lib/Sema/TreeTransform.h
@@ -6408,8 +6408,6 @@
   if (Replacement.isNull())
 return QualType();
 
-  // Always canonicalize the replacement type.
-  Replacement = SemaRef.Context.getCanonicalType(Replacement);
   QualType Result = SemaRef.Context.getSubstTemplateTypeParmType(
   T->getReplacedParameter(), Replacement, T->getPackIndex());
 
Index: clang/lib/Sema/SemaTemplate.cpp
===
--- clang/lib/Sema/SemaTemplate.cpp
+++ clang/lib/Sema/SemaTemplate.cpp
@@ -3511,8 +3511,7 @@
 0, IndexReplaced, false,
 cast(TPL->getParam(IndexReplaced)));
 return SemaRef.Context.getSubstTemplateTypeParmType(
-cast(TTP), Replacement.getCanonicalType(),
-PackIndexReplaced);
+cast(TTP), Replacement, PackIndexReplaced);
   };
 
   switch (BTD->getBuiltinTemplateKind()) {
Index: clang/lib/AST/Type.cpp
===
--- clang/lib/AST/Type.cpp
+++ clang/lib/AST/Type.cpp
@@ -3659,10 +3659,16 @@
 }
 
 SubstTemplateTypeParmType::SubstTemplateTypeParmType(
-const TemplateTypeParmType *Param, QualType Canon,
+const TemplateTypeParmType *Param, QualType Replacement,
 Optional PackIndex)
-: Type(SubstTemplateTypeParm, Canon, Canon->getDependence()),
+: Type(SubstTemplateTypeParm, Replacement.getCanonicalType(),
+   Replacement->getDependence()),
   Replaced(Param) {
+  SubstTemplateTypeParmTypeBits.HasNonCanonicalUnderlyingType =
+  Replacement != getCanonicalTypeInternal();
+  if (SubstTemplateTypeParmTypeBits.HasNonCanonicalUnderlyingType)
+*getTrailingObjects() = Replacement;
+
   SubstTemplateTypeParmTypeBits.PackIndex = PackIndex ? *PackIndex + 1 : 0;
 }
 
Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -1534,8 +1534,7 @@
 return ToReplacementTypeOrErr.takeError();
 
   return Importer.getToContext().getSubstTemplateTypeParmType(
-  *ReplacedOrErr, ToReplacementTypeOrErr->getCanonicalType(),
-  T->getPackIndex());
+  *ReplacedOrErr, *ToReplacementTypeOrErr, T->getPackIndex());
 }
 
 ExpectedType ASTNodeImporter::VisitSubstTemplateTypeParmPackType(
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -4782,9 +4782,6 @@
 ASTContext::getSubstTemplateTypeParmType(const TemplateTypeParmType *Parm,
  QualType Replacement,
  Optional PackIndex) const {
-  assert(Replacement.isCanonical()
- && "replacement types must always be canonical");
-
   llvm::FoldingSetNodeID ID;
   SubstTemplateTypeParmType::Profile(ID, Parm, Replacement, PackIndex);
 

[PATCH] D133468: [clang] Implement divergence for TypedefType and UsingType

2022-09-17 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov edited the summary of this revision.
mizvekov updated this revision to Diff 461015.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133468

Files:
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/JSONNodeDumper.h
  clang/include/clang/AST/Type.h
  clang/include/clang/AST/TypeProperties.td
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/ASTStructuralEquivalence.cpp
  clang/lib/AST/JSONNodeDumper.cpp
  clang/lib/AST/TextNodeDumper.cpp
  clang/lib/AST/Type.cpp
  clang/test/SemaCXX/sugar-common-types.cpp

Index: clang/test/SemaCXX/sugar-common-types.cpp
===
--- clang/test/SemaCXX/sugar-common-types.cpp
+++ clang/test/SemaCXX/sugar-common-types.cpp
@@ -112,3 +112,22 @@
 C2 auto t26_3 = (::SB1){};
 N t26 = 0 ? t26_1 : t26_2; // expected-error {{from 'SB1' (aka 'SS1')}}
 N t27 = 0 ? t26_1 : t26_3; // expected-error {{from 'SB1' (aka 'SS1')}}
+
+using RPB1 = X1*;
+using RPX1 = RPB1;
+using RPB1 = Y1*; // redeclared
+using RPY1 = RPB1;
+N t28 = *(RPB1){}; // expected-error {{lvalue of type 'Y1' (aka 'int')}}
+auto t29 = 0 ? (RPX1){} : (RPY1){};
+N t30 = t29;  // expected-error {{lvalue of type 'RPB1' (aka 'int *')}}
+N t31 = *t29; // expected-error {{lvalue of type 'B1' (aka 'int')}}
+
+namespace A { using type1 = X1*; };
+namespace C { using A::type1; };
+using UPX1 = C::type1;
+namespace A { using type1 = Y1*; };  // redeclared
+namespace C { using A::type1; }; // redeclared
+using UPY1 = C::type1;
+auto t32 = 0 ? (UPX1){} : (UPY1){};
+N t33 = t32;  // expected-error {{lvalue of type 'C::type1' (aka 'int *')}}
+N t34 = *t32; // expected-error {{lvalue of type 'B1' (aka 'int')}}
Index: clang/lib/AST/Type.cpp
===
--- clang/lib/AST/Type.cpp
+++ clang/lib/AST/Type.cpp
@@ -3434,25 +3434,34 @@
 }
 
 TypedefType::TypedefType(TypeClass tc, const TypedefNameDecl *D,
- QualType underlying, QualType can)
-: Type(tc, can, toSemanticDependence(underlying->getDependence())),
+ QualType Underlying, QualType can)
+: Type(tc, can, toSemanticDependence(can->getDependence())),
   Decl(const_cast(D)) {
   assert(!isa(can) && "Invalid canonical type");
+  TypedefBits.isDivergent = !Underlying.isNull();
+  if (isDivergent())
+*reinterpret_cast(this + 1) = Underlying;
 }
 
 QualType TypedefType::desugar() const {
-  return getDecl()->getUnderlyingType();
+  return isDivergent() ? *getTrailingObjects()
+   : Decl->getUnderlyingType();
 }
 
 UsingType::UsingType(const UsingShadowDecl *Found, QualType Underlying,
  QualType Canon)
-: Type(Using, Canon, toSemanticDependence(Underlying->getDependence())),
+: Type(Using, Canon, toSemanticDependence(Canon->getDependence())),
   Found(const_cast(Found)) {
-  assert(Underlying == getUnderlyingType());
+  UsingBits.isDivergent = !Underlying.isNull();
+  if (isDivergent())
+*reinterpret_cast(this + 1) = Underlying;
 }
 
 QualType UsingType::getUnderlyingType() const {
-  return QualType(cast(Found->getTargetDecl())->getTypeForDecl(), 0);
+  return isDivergent()
+ ? *getTrailingObjects()
+ : QualType(
+   cast(Found->getTargetDecl())->getTypeForDecl(), 0);
 }
 
 QualType MacroQualifiedType::desugar() const { return getUnderlyingType(); }
Index: clang/lib/AST/TextNodeDumper.cpp
===
--- clang/lib/AST/TextNodeDumper.cpp
+++ clang/lib/AST/TextNodeDumper.cpp
@@ -1543,10 +1543,14 @@
 
 void TextNodeDumper::VisitUsingType(const UsingType *T) {
   dumpDeclRef(T->getFoundDecl());
+  if (T->isDivergent())
+OS << " divergent";
 }
 
 void TextNodeDumper::VisitTypedefType(const TypedefType *T) {
   dumpDeclRef(T->getDecl());
+  if (T->isDivergent())
+OS << " divergent";
 }
 
 void TextNodeDumper::VisitUnaryTransformType(const UnaryTransformType *T) {
Index: clang/lib/AST/JSONNodeDumper.cpp
===
--- clang/lib/AST/JSONNodeDumper.cpp
+++ clang/lib/AST/JSONNodeDumper.cpp
@@ -531,6 +531,14 @@
 
 void JSONNodeDumper::VisitTypedefType(const TypedefType *TT) {
   JOS.attribute("decl", createBareDeclRef(TT->getDecl()));
+  if (TT->isDivergent())
+JOS.attribute("type", createQualType(TT->desugar()));
+}
+
+void JSONNodeDumper::VisitUsingType(const UsingType *TT) {
+  JOS.attribute("decl", createBareDeclRef(TT->getFoundDecl()));
+  if (TT->isDivergent())
+JOS.attribute("type", createQualType(TT->desugar()));
 }
 
 void JSONNodeDumper::VisitFunctionType(const FunctionType *T) {
Index: clang/lib/AST/ASTStructuralEquivalence.cpp
===
--- clang/lib/AST/ASTStructuralEquivalence.cpp
+++ clang/lib/AST

[PATCH] D133436: Ground work for cuda-related checks in clang-tidy

2022-09-17 Thread Bartłomiej Cieślar via Phabricator via cfe-commits
barcisz added inline comments.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/stddef.h:12
+
+using size_t = long long unsigned;
+

njames93 wrote:
> If this is all the file is used for, and it's only used for this one test 
> file, can probably remove this header and inline the definition.
> I also feel this definition may be fragile on certain platforms.
I wanted to add it in a separate header for future proofness; as for the 
definition, I cannot really use uint64_t here since I cannot include the real 
stddef.h


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133436

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


[PATCH] D133942: Clang tidy utility to generate a fix hint for a subsequent expression to the existing one

2022-09-17 Thread Bartłomiej Cieślar via Phabricator via cfe-commits
barcisz added a comment.

In D133942#3797449 , @njames93 wrote:

> How does this handle pathological cases like the statement being the 
> iteration-expression of a for loop, or a init-statement in an 
> if/switch/range-for loop. The documentation looks like it tries to explain 
> that, but it doesn't do a great job IMHO.

It doesn't really, it's mostly meant for cases where we know that the statement 
will be in the body and it's only added in the utils because it's needed for 
D133956 , but I can just move it to inside 
the check if you believe that it won't be as useful for the general case. The 
reason I want to preserve the statement to which the comments relate to is 
because if I put the new statement/macro invocation right after the current 
statement then the formatted will move the comments to the new line with the 
new statement instead of keeping them in the same line as the current statement 
(and in case of macros I'm not sure if it will even move it to the next line at 
all)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133942

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


[PATCH] D133993: [HLSL] Remove global ctor/dtor variable for non-lib profile.

2022-09-17 Thread Xiang Li via Phabricator via cfe-commits
python3kgae updated this revision to Diff 461014.
python3kgae added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133993

Files:
  clang/lib/CodeGen/CGHLSLRuntime.cpp
  clang/lib/CodeGen/CGHLSLRuntime.h
  clang/test/CodeGenHLSL/GlobalConstructorFunction.hlsl
  clang/test/CodeGenHLSL/GlobalConstructorLib.hlsl
  clang/test/CodeGenHLSL/GlobalConstructors.hlsl
  clang/test/CodeGenHLSL/GlobalDestructors.hlsl

Index: clang/test/CodeGenHLSL/GlobalDestructors.hlsl
===
--- clang/test/CodeGenHLSL/GlobalDestructors.hlsl
+++ clang/test/CodeGenHLSL/GlobalDestructors.hlsl
@@ -39,6 +39,9 @@
   Wag();
 }
 
+// Make sure global variable for ctors/dtors removed.
+// CHECK-NOT:@llvm.global_ctors
+// CHECK-NOT:@llvm.global_dtors
 //CHECK:  define void @main()
 //CHECK-NEXT: entry:
 //CHECK-NEXT:   call void @_GLOBAL__sub_I_GlobalDestructors.hlsl()
Index: clang/test/CodeGenHLSL/GlobalConstructors.hlsl
===
--- clang/test/CodeGenHLSL/GlobalConstructors.hlsl
+++ clang/test/CodeGenHLSL/GlobalConstructors.hlsl
@@ -5,6 +5,9 @@
 [numthreads(1,1,1)]
 void main(unsigned GI : SV_GroupIndex) {}
 
+// Make sure global variable for ctors/dtors removed.
+// CHECK-NOT:@llvm.global_ctors
+// CHECK-NOT:@llvm.global_dtors
 //CHECK:  define void @main()
 //CHECK-NEXT: entry:
 //CHECK-NEXT:   call void @_GLOBAL__sub_I_GlobalConstructors.hlsl()
Index: clang/test/CodeGenHLSL/GlobalConstructorLib.hlsl
===
--- clang/test/CodeGenHLSL/GlobalConstructorLib.hlsl
+++ clang/test/CodeGenHLSL/GlobalConstructorLib.hlsl
@@ -1,5 +1,8 @@
 // RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -S -emit-llvm -disable-llvm-passes %s -o - | FileCheck %s
 
+// Make sure global variable for ctors exist for lib profile.
+// CHECK:@llvm.global_ctors
+
 RWBuffer Buffer;
 
 [shader("compute")]
Index: clang/test/CodeGenHLSL/GlobalConstructorFunction.hlsl
===
--- clang/test/CodeGenHLSL/GlobalConstructorFunction.hlsl
+++ clang/test/CodeGenHLSL/GlobalConstructorFunction.hlsl
@@ -17,6 +17,10 @@
 [numthreads(1,1,1)]
 void main(unsigned GI : SV_GroupIndex) {}
 
+// Make sure global variable for ctors/dtors removed.
+// CHECK-NOT:@llvm.global_ctors
+// CHECK-NOT:@llvm.global_dtors
+
 //CHECK: define void @main()
 //CHECK-NEXT: entry:
 //CHECK-NEXT:   call void @"?call_me_first@@YAXXZ"()
Index: clang/lib/CodeGen/CGHLSLRuntime.h
===
--- clang/lib/CodeGen/CGHLSLRuntime.h
+++ clang/lib/CodeGen/CGHLSLRuntime.h
@@ -22,6 +22,7 @@
 namespace llvm {
 class GlobalVariable;
 class Function;
+class Triple;
 } // namespace llvm
 namespace clang {
 class VarDecl;
@@ -46,7 +47,7 @@
   virtual ~CGHLSLRuntime() {}
 
   void annotateHLSLResource(const VarDecl *D, llvm::GlobalVariable *GV);
-  void generateGlobalCtorDtorCalls();
+  void generateGlobalCtorDtorCalls(llvm::Triple &T);
 
   void finishCodeGen();
 
Index: clang/lib/CodeGen/CGHLSLRuntime.cpp
===
--- clang/lib/CodeGen/CGHLSLRuntime.cpp
+++ clang/lib/CodeGen/CGHLSLRuntime.cpp
@@ -60,7 +60,7 @@
   if (T.getArch() == Triple::ArchType::dxil)
 addDxilValVersion(TargetOpts.DxilValidatorVersion, M);
 
-  generateGlobalCtorDtorCalls();
+  generateGlobalCtorDtorCalls(T);
   if (CGM.getCodeGenOpts().OptimizationLevel == 0)
 addDisableOptimizations(M);
 }
@@ -180,7 +180,7 @@
   }
 }
 
-void CGHLSLRuntime::generateGlobalCtorDtorCalls() {
+void CGHLSLRuntime::generateGlobalCtorDtorCalls(Triple &T) {
   llvm::Module &M = CGM.getModule();
   SmallVector CtorFns;
   SmallVector DtorFns;
@@ -202,4 +202,13 @@
 for (auto *Fn : DtorFns)
   B.CreateCall(FunctionCallee(Fn));
   }
+
+  // No need to keep global ctors/dtors for non-lib profile after call to
+  // ctors/dtors added for entry.
+  if (T.getEnvironment() != Triple::EnvironmentType::Library) {
+if (auto *GV = M.getNamedGlobal("llvm.global_ctors"))
+  GV->eraseFromParent();
+if (auto *GV = M.getNamedGlobal("llvm.global_dtors"))
+  GV->eraseFromParent();
+  }
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D133942: Clang tidy utility to generate a fix hint for a subsequent expression to the existing one

2022-09-17 Thread Bartłomiej Cieślar via Phabricator via cfe-commits
barcisz added a comment.

In D133942#3797449 , @njames93 wrote:

> It would also be nice to add in some unittests to demonstrate that braces are 
> currently inserted etc.

Right sorry, forgot to port unit tests, will do that swiftly


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133942

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


[PATCH] D133948: [clang][C++20] Fix clang/clangd assert/crash after compilation errors

2022-09-17 Thread Dmitry Polukhin via Phabricator via cfe-commits
DmitryPolukhin added a comment.

In D133948#3793085 , @aaron.ballman 
wrote:

> LGTM! Please add a release note for the fix when you land the changes.

Thank you for prompt review! Release notes update in D134112 
.
Also I found existing issues about this crash 
https://github.com/llvm/llvm-project/issues/53628.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133948

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


[PATCH] D134112: [clang] Update ReleaseNotes about a crash fix (Issue 53628)

2022-09-17 Thread Dmitry Polukhin via Phabricator via cfe-commits
DmitryPolukhin created this revision.
DmitryPolukhin added reviewers: aaron.ballman, Tyker.
Herald added a project: All.
DmitryPolukhin requested review of this revision.
Herald added a project: clang.

Update ReleaseNotes about a crash fix (Issue 53628)

Test Plan: none


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D134112

Files:
  clang/docs/ReleaseNotes.rst


Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -146,6 +146,9 @@
 - A SubstTemplateTypeParmType can now represent the pack index for a
   substitution from an expanded pack.
   `Issue 56099 `_
+- Fixed a crash in C++20 mode in Clang and Clangd when compile source
+  with compilation errors.
+  `Issue 53628 `_
 
 
 Improvements to Clang's diagnostics


Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -146,6 +146,9 @@
 - A SubstTemplateTypeParmType can now represent the pack index for a
   substitution from an expanded pack.
   `Issue 56099 `_
+- Fixed a crash in C++20 mode in Clang and Clangd when compile source
+  with compilation errors.
+  `Issue 53628 `_
 
 
 Improvements to Clang's diagnostics
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D133887: [Clang] Support label at end of compound statement

2022-09-17 Thread Evgeny Shulgin 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 rG510383626fe1: [Clang] Support label at end of compound 
statement (authored by Izaron).

Changed prior to commit:
  https://reviews.llvm.org/D133887?vs=461006&id=461008#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133887

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/lib/Parse/ParseStmt.cpp
  clang/test/AST/ast-dump-stmt.c
  clang/test/Parser/c2x-label.c
  clang/test/Parser/cxx2b-label.cpp
  clang/test/Parser/switch-recovery.cpp
  clang/www/c_status.html
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -1456,7 +1456,7 @@
 
   Labels at the end of compound statements
   https://wg21.link/P2324R2";>P2324R2
-  No
+  Clang 16
 
 
   Delimited escape sequences
Index: clang/www/c_status.html
===
--- clang/www/c_status.html
+++ clang/www/c_status.html
@@ -763,7 +763,7 @@
 
   Free positioning of labels inside compound statements
   https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2508.pdf";>N2508
-  No
+  Clang 16
 
 
   Clarification request for C17 example of undefined behavior
Index: clang/test/Parser/switch-recovery.cpp
===
--- clang/test/Parser/switch-recovery.cpp
+++ clang/test/Parser/switch-recovery.cpp
@@ -160,14 +160,14 @@
 void missing_statement_case(int x) {
   switch (x) {
 case 1:
-case 0: // expected-error {{label at end of compound statement: expected statement}}
+case 0: // expected-error {{label at end of switch compound statement: expected statement}}
   }
 }
 
 void missing_statement_default(int x) {
   switch (x) {
 case 0:
-default: // expected-error {{label at end of compound statement: expected statement}}
+default: // expected-error {{label at end of switch compound statement: expected statement}}
   }
 }
 
@@ -179,7 +179,7 @@
 void pr19022_1a(int x) {
   switch(x) {
   case 1  // expected-error{{expected ':' after 'case'}} \
-  // expected-error{{label at end of compound statement: expected statement}}
+  // expected-error{{label at end of switch compound statement: expected statement}}
   }
 }
 
Index: clang/test/Parser/cxx2b-label.cpp
===
--- /dev/null
+++ clang/test/Parser/cxx2b-label.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -fsyntax-only -verify=expected,cxx2b -std=c++2b -Wpre-c++2b-compat %s
+// RUN: %clang_cc1 -fsyntax-only -verify=expected,cxx20 -std=c++20 %s
+
+void foo() {
+label1:
+int x;
+label2:
+x = 1;
+label3: label4: label5:
+} // cxx20-warning {{label at end of compound statement is a C++2b extension}} \
+ cxx2b-warning {{label at end of compound statement is incompatible with C++ standards before C++2b}}
Index: clang/test/Parser/c2x-label.c
===
--- /dev/null
+++ clang/test/Parser/c2x-label.c
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c17 -Wc2x-compat -verify=c17 %s
+// RUN: %clang_cc1 -fsyntax-only -std=c2x -Wpre-c2x-compat -verify=c2x %s
+
+void foo() {
+int x;
+label1:
+x = 1;
+label2: label3: label4:
+} // c17-warning {{label at end of compound statement is a C2x extension}} \
+ c2x-warning {{label at end of compound statement is incompatible with C standards before C2x}}
Index: clang/test/AST/ast-dump-stmt.c
===
--- clang/test/AST/ast-dump-stmt.c
+++ clang/test/AST/ast-dump-stmt.c
@@ -161,6 +161,10 @@
   // CHECK-NEXT: ImplicitCastExpr
   // CHECK-NEXT: ImplicitCastExpr
   // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}}  'void *' lvalue Var 0x{{[^ ]*}} 'ptr' 'void *'
+
+label3:
+  // CHECK-NEXT: LabelStmt 0x{{[^ ]*}}  'label3'
+  // CHECK-NEXT: NullStmt 0x{{[^ ]*}} 
 }
 
 void TestSwitch(int i) {
Index: clang/lib/Parse/ParseStmt.cpp
===
--- clang/lib/Parse/ParseStmt.cpp
+++ clang/lib/Parse/ParseStmt.cpp
@@ -679,9 +679,12 @@
 
 /// ParseLabeledStatement - We have an identifier and a ':' after it.
 ///
+///   label:
+/// identifier ':'
+/// [GNU]   identifier ':' attributes[opt]
+///
 ///   labeled-statement:
-/// identifier ':' statement
-/// [GNU]   identifier ':' attributes[opt] statement
+/// label statement
 ///
 StmtResult Parser::ParseLabeledStatement(ParsedAttributes &Attrs,
  ParsedStmtContext StmtCtx) {
@@ -725,6 +728,20 @@
 }
   }
 
+  // The label m

[clang] 5103836 - [Clang] Support label at end of compound statement

2022-09-17 Thread Evgeny Shulgin via cfe-commits

Author: Evgeny Shulgin
Date: 2022-09-17T15:34:56Z
New Revision: 510383626fe146e49ae5fa036638e543ce71e5d9

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

LOG: [Clang] Support label at end of compound statement

Implements paper P2324R2
https://wg21.link/p2324r2
https://github.com/cplusplus/papers/issues/1006

Reviewed By: cor3ntin

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

Added: 
clang/test/Parser/c2x-label.c
clang/test/Parser/cxx2b-label.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticParseKinds.td
clang/lib/Parse/ParseStmt.cpp
clang/test/AST/ast-dump-stmt.c
clang/test/Parser/switch-recovery.cpp
clang/www/c_status.html
clang/www/cxx_status.html

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 240228a6d5e7..403d50b1c9d4 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -269,6 +269,9 @@ C2x Feature Support
   so the [[maybe_unused]] attribute may be applied to a label to silence an
   ``-Wunused-label`` warning.
 
+- Implemented `WG14 N508 
`_,
+  so labels can placed everywhere inside a compound statement.
+
 C++ Language Changes in Clang
 -
 - Implemented DR692, DR1395 and DR1432. Use the ``-fclang-abi-compat=15`` 
option
@@ -313,6 +316,8 @@ C++20 Feature Support
 C++2b Feature Support
 ^
 
+- Support label at end of compound statement (`P2324 
`_).
+
 CUDA/HIP Language Changes in Clang
 --
 

diff  --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 84504b15764b..0293c2c03b52 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -295,8 +295,20 @@ def note_missing_selector_name : Note<
 def note_force_empty_selector_name : Note<
   "or insert whitespace before ':' to use %0 as parameter name "
   "and have an empty entry in the selector">;
-def err_label_end_of_compound_statement : Error<
-  "label at end of compound statement: expected statement">;
+def err_switch_label_end_of_compound_statement : Error<
+  "label at end of switch compound statement: expected statement">;
+def ext_c_label_end_of_compound_statement : ExtWarn<
+  "label at end of compound statement is a C2x extension">,
+   InGroup;
+def ext_cxx_label_end_of_compound_statement : ExtWarn<
+  "label at end of compound statement is a C++2b extension">,
+   InGroup;
+def warn_c2x_compat_label_end_of_compound_statement : Warning<
+  "label at end of compound statement is incompatible with C standards before 
C2x">,
+  InGroup, DefaultIgnore;
+def warn_cxx20_compat_label_end_of_compound_statement : Warning<
+  "label at end of compound statement is incompatible with C++ standards 
before C++2b">,
+  InGroup, DefaultIgnore;
 def err_address_of_label_outside_fn : Error<
   "use of address-of-label extension outside of a function body">;
 def err_asm_operand_wide_string_literal : Error<

diff  --git a/clang/lib/Parse/ParseStmt.cpp b/clang/lib/Parse/ParseStmt.cpp
index d785c393fef9..1a3363604a33 100644
--- a/clang/lib/Parse/ParseStmt.cpp
+++ b/clang/lib/Parse/ParseStmt.cpp
@@ -679,9 +679,12 @@ StmtResult Parser::ParseSEHLeaveStatement() {
 
 /// ParseLabeledStatement - We have an identifier and a ':' after it.
 ///
+///   label:
+/// identifier ':'
+/// [GNU]   identifier ':' attributes[opt]
+///
 ///   labeled-statement:
-/// identifier ':' statement
-/// [GNU]   identifier ':' attributes[opt] statement
+/// label statement
 ///
 StmtResult Parser::ParseLabeledStatement(ParsedAttributes &Attrs,
  ParsedStmtContext StmtCtx) {
@@ -725,6 +728,20 @@ StmtResult Parser::ParseLabeledStatement(ParsedAttributes 
&Attrs,
 }
   }
 
+  // The label may have no statement following it
+  if (SubStmt.isUnset() && Tok.is(tok::r_brace)) {
+if (getLangOpts().CPlusPlus) {
+  Diag(Tok, getLangOpts().CPlusPlus2b
+? diag::warn_cxx20_compat_label_end_of_compound_statement
+: diag::ext_cxx_label_end_of_compound_statement);
+} else {
+  Diag(Tok, getLangOpts().C2x
+? diag::warn_c2x_compat_label_end_of_compound_statement
+: diag::ext_c_label_end_of_compound_statement);
+}
+SubStmt = Actions.ActOnNullStmt(ColonLoc);
+  }
+
   // If we've not parsed a statement yet, parse one now.
   if (!SubStmt.isInvalid() && !SubStmt.isUsable())
 SubStmt = ParseStatement(nullptr, StmtCtx);
@@ -873,8 +890,8 @@ StmtResult Parser::ParseCaseSta

[PATCH] D133887: [Clang] Support label at end of compound statement

2022-09-17 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin accepted this revision as: cor3ntin.
cor3ntin added a comment.
This revision is now accepted and ready to land.

Thanks.
This LGTM now


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133887

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


[PATCH] D133948: [clang][C++20] Fix clang/clangd assert/crash after compilation errors

2022-09-17 Thread Dmitry Polukhin via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG133b6d7db90d: [clang][C++20] Fix clang/clangd assert/crash 
after compilation errors (authored by DmitryPolukhin).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133948

Files:
  clang/lib/Sema/SemaExpr.cpp
  clang/test/SemaCXX/remove-nested-immediate-invocation-crash.cpp


Index: clang/test/SemaCXX/remove-nested-immediate-invocation-crash.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/remove-nested-immediate-invocation-crash.cpp
@@ -0,0 +1,11 @@
+// RUN: not %clang_cc1 -fsyntax-only -verify -std=gnu++20 -ferror-limit 19 %s
+// Creduced test case for the crash in RemoveNestedImmediateInvocation after 
compliation errros.
+
+a, class b {   template < typename c>  
   consteval b(c
+} template  using d = b;
+auto e(d<>) -> int:;
+}
+f
+}
+g() {
+auto h = "":(::i(e(h))
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -17624,9 +17624,13 @@
 Transformer.AllowSkippingFirstCXXConstructExpr = false;
 
   ExprResult Res = Transformer.TransformExpr(It->getPointer()->getSubExpr());
-  assert(Res.isUsable());
-  Res = SemaRef.MaybeCreateExprWithCleanups(Res);
-  It->getPointer()->setSubExpr(Res.get());
+  // The result may not be usable in case of previous compilation errors.
+  // In this case evaluation of the expression may result in crash so just
+  // don't do anything further with the result.
+  if (Res.isUsable()) {
+Res = SemaRef.MaybeCreateExprWithCleanups(Res);
+It->getPointer()->setSubExpr(Res.get());
+  }
 }
 
 static void


Index: clang/test/SemaCXX/remove-nested-immediate-invocation-crash.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/remove-nested-immediate-invocation-crash.cpp
@@ -0,0 +1,11 @@
+// RUN: not %clang_cc1 -fsyntax-only -verify -std=gnu++20 -ferror-limit 19 %s
+// Creduced test case for the crash in RemoveNestedImmediateInvocation after compliation errros.
+
+a, class b {   template < typename c> consteval b(c
+} template  using d = b;
+auto e(d<>) -> int:;
+}
+f
+}
+g() {
+auto h = "":(::i(e(h))
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -17624,9 +17624,13 @@
 Transformer.AllowSkippingFirstCXXConstructExpr = false;
 
   ExprResult Res = Transformer.TransformExpr(It->getPointer()->getSubExpr());
-  assert(Res.isUsable());
-  Res = SemaRef.MaybeCreateExprWithCleanups(Res);
-  It->getPointer()->setSubExpr(Res.get());
+  // The result may not be usable in case of previous compilation errors.
+  // In this case evaluation of the expression may result in crash so just
+  // don't do anything further with the result.
+  if (Res.isUsable()) {
+Res = SemaRef.MaybeCreateExprWithCleanups(Res);
+It->getPointer()->setSubExpr(Res.get());
+  }
 }
 
 static void
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 133b6d7 - [clang][C++20] Fix clang/clangd assert/crash after compilation errors

2022-09-17 Thread Dmitry Polukhin via cfe-commits

Author: Dmitry Polukhin
Date: 2022-09-17T07:37:19-07:00
New Revision: 133b6d7db90d9b52b01e8e09e1aa8fb8d2da0f9d

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

LOG: [clang][C++20] Fix clang/clangd assert/crash after compilation errors

After compilation errors, expression a transformation result may not be usable.
It triggers an assert in RemoveNestedImmediateInvocation and SIGSEGV in case of
builds without asserts. This issue significantly affects clangd because source
may not be valid during typing. Tests cases that I attached was reduce from huge
C++ translation unit.

Test Plan: check-clang

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

Added: 
clang/test/SemaCXX/remove-nested-immediate-invocation-crash.cpp

Modified: 
clang/lib/Sema/SemaExpr.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index e53c88b283b8..b49b7ce45cf4 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -17624,9 +17624,13 @@ static void RemoveNestedImmediateInvocation(
 Transformer.AllowSkippingFirstCXXConstructExpr = false;
 
   ExprResult Res = Transformer.TransformExpr(It->getPointer()->getSubExpr());
-  assert(Res.isUsable());
-  Res = SemaRef.MaybeCreateExprWithCleanups(Res);
-  It->getPointer()->setSubExpr(Res.get());
+  // The result may not be usable in case of previous compilation errors.
+  // In this case evaluation of the expression may result in crash so just
+  // don't do anything further with the result.
+  if (Res.isUsable()) {
+Res = SemaRef.MaybeCreateExprWithCleanups(Res);
+It->getPointer()->setSubExpr(Res.get());
+  }
 }
 
 static void

diff  --git a/clang/test/SemaCXX/remove-nested-immediate-invocation-crash.cpp 
b/clang/test/SemaCXX/remove-nested-immediate-invocation-crash.cpp
new file mode 100644
index ..26faf2bc1c06
--- /dev/null
+++ b/clang/test/SemaCXX/remove-nested-immediate-invocation-crash.cpp
@@ -0,0 +1,11 @@
+// RUN: not %clang_cc1 -fsyntax-only -verify -std=gnu++20 -ferror-limit 19 %s
+// Creduced test case for the crash in RemoveNestedImmediateInvocation after 
compliation errros.
+
+a, class b {   template < typename c>  
   consteval b(c
+} template  using d = b;
+auto e(d<>) -> int:;
+}
+f
+}
+g() {
+auto h = "":(::i(e(h))



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


[PATCH] D133887: [Clang] Support label at end of compound statement

2022-09-17 Thread Evgeny Shulgin via Phabricator via cfe-commits
Izaron updated this revision to Diff 461006.
Izaron added a comment.

Fix diagnostics for C. Thanks to @cor3ntin and @aaron.ballman!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133887

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/lib/Parse/ParseStmt.cpp
  clang/test/AST/ast-dump-stmt.c
  clang/test/Parser/c2x-label.c
  clang/test/Parser/cxx2b-label.cpp
  clang/test/Parser/switch-recovery.cpp
  clang/www/c_status.html
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -1456,7 +1456,7 @@
 
   Labels at the end of compound statements
   https://wg21.link/P2324R2";>P2324R2
-  No
+  Clang 16
 
 
   Delimited escape sequences
Index: clang/www/c_status.html
===
--- clang/www/c_status.html
+++ clang/www/c_status.html
@@ -763,7 +763,7 @@
 
   Free positioning of labels inside compound statements
   https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2508.pdf";>N2508
-  No
+  Clang 16
 
 
   Clarification request for C17 example of undefined behavior
Index: clang/test/Parser/switch-recovery.cpp
===
--- clang/test/Parser/switch-recovery.cpp
+++ clang/test/Parser/switch-recovery.cpp
@@ -160,14 +160,14 @@
 void missing_statement_case(int x) {
   switch (x) {
 case 1:
-case 0: // expected-error {{label at end of compound statement: expected statement}}
+case 0: // expected-error {{label at end of switch compound statement: expected statement}}
   }
 }
 
 void missing_statement_default(int x) {
   switch (x) {
 case 0:
-default: // expected-error {{label at end of compound statement: expected statement}}
+default: // expected-error {{label at end of switch compound statement: expected statement}}
   }
 }
 
@@ -179,7 +179,7 @@
 void pr19022_1a(int x) {
   switch(x) {
   case 1  // expected-error{{expected ':' after 'case'}} \
-  // expected-error{{label at end of compound statement: expected statement}}
+  // expected-error{{label at end of switch compound statement: expected statement}}
   }
 }
 
Index: clang/test/Parser/cxx2b-label.cpp
===
--- /dev/null
+++ clang/test/Parser/cxx2b-label.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -fsyntax-only -verify=expected,cxx2b -std=c++2b -Wpre-c++2b-compat %s
+// RUN: %clang_cc1 -fsyntax-only -verify=expected,cxx20 -std=c++20 %s
+
+void foo() {
+label1:
+int x;
+label2:
+x = 1;
+label3: label4: label5:
+} // cxx20-warning {{label at end of compound statement is a C++2b extension}} \
+ cxx2b-warning {{label at end of compound statement is incompatible with C++ standards before C++2b}}
Index: clang/test/Parser/c2x-label.c
===
--- /dev/null
+++ clang/test/Parser/c2x-label.c
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c17 -Wc2x-compat -verify=c17 %s
+// RUN: %clang_cc1 -fsyntax-only -std=c2x -Wpre-c2x-compat -verify=c2x %s
+
+void foo() {
+int x;
+label1:
+x = 1;
+label2: label3: label4:
+} // c17-warning {{label at end of compound statement is a C2x extension}} \
+ c2x-warning {{label at end of compound statement is incompatible with C standards before C2x}}
Index: clang/test/AST/ast-dump-stmt.c
===
--- clang/test/AST/ast-dump-stmt.c
+++ clang/test/AST/ast-dump-stmt.c
@@ -161,6 +161,10 @@
   // CHECK-NEXT: ImplicitCastExpr
   // CHECK-NEXT: ImplicitCastExpr
   // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}}  'void *' lvalue Var 0x{{[^ ]*}} 'ptr' 'void *'
+
+label3:
+  // CHECK-NEXT: LabelStmt 0x{{[^ ]*}}  'label3'
+  // CHECK-NEXT: NullStmt 0x{{[^ ]*}} 
 }
 
 void TestSwitch(int i) {
Index: clang/lib/Parse/ParseStmt.cpp
===
--- clang/lib/Parse/ParseStmt.cpp
+++ clang/lib/Parse/ParseStmt.cpp
@@ -679,9 +679,12 @@
 
 /// ParseLabeledStatement - We have an identifier and a ':' after it.
 ///
+///   label:
+/// identifier ':'
+/// [GNU]   identifier ':' attributes[opt]
+///
 ///   labeled-statement:
-/// identifier ':' statement
-/// [GNU]   identifier ':' attributes[opt] statement
+/// label statement
 ///
 StmtResult Parser::ParseLabeledStatement(ParsedAttributes &Attrs,
  ParsedStmtContext StmtCtx) {
@@ -725,6 +728,20 @@
 }
   }
 
+  // The label may have no statement following it
+  if (SubStmt.isUnset() && Tok.is(tok::r_brace)) {
+if (getLangOpts().CPlusPlus) {
+  Diag(Tok, getLangOpts().CPlusPlus2b
+? 

[PATCH] D133887: [Clang] Support label at end of compound statement

2022-09-17 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added a comment.

In D133887#3797614 , @Izaron wrote:

>> Why checking getLangOpts().C99 instead of just C
>
> There is no `getLangOpts().C`. Here are possible C/C++ opt flags:
> https://github.com/llvm/llvm-project/blob/7914e53e312074828293356f569d190ac6eae3bd/clang/include/clang/Basic/LangOptions.def#L86-L100
> I have no understanding why there is no `getLangOpts().C` flag. Maybe the C89 
> standard is a subset of all other C/C++/ObjC standards, so we don't need the 
> flag?..

I missed that.
Yes, i think the way do that is to check `!getLangOpts().CPlusPlus`

>> Whyt no compatibility warning in C23 mode
>
> @aaron.ballman said so in https://reviews.llvm.org/D133887#3793027
>
>   It should definitely be without warning in C23 mode and give an extension 
> warning in earlier modes.
>
> I don't know much about extension/incompatible warnings policy (when to apply 
> and not apply them), could you please help me to figure this out with Aaron? 😃

I checked with Aaron, he meant no warning _by default_, but there should 
definitely be an extension warning. exact same thing as C++.
Sorry for the confusion.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133887

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


[PATCH] D133887: [Clang] Support label at end of compound statement

2022-09-17 Thread Evgeny Shulgin via Phabricator via cfe-commits
Izaron added a comment.

> Why checking getLangOpts().C99 instead of just C

There is no `getLangOpts().C`. Here are possible C/C++ opt flags:
https://github.com/llvm/llvm-project/blob/7914e53e312074828293356f569d190ac6eae3bd/clang/include/clang/Basic/LangOptions.def#L86-L100
I have no understanding why there is no `getLangOpts().C` flag. Maybe the C89 
standard is a subset of all other C/C++/ObjC standards, so we don't need the 
flag?..

> Whyt no compatibility warning in C23 mode

@aaron.ballman said so in https://reviews.llvm.org/D133887#3793027

  It should definitely be without warning in C23 mode and give an extension 
warning in earlier modes.

I don't know much about extension/incompatible warnings policy (when to apply 
and not apply them), could you please help me to figure this out with Aaron? 😃


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133887

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


[PATCH] D133436: Ground work for cuda-related checks in clang-tidy

2022-09-17 Thread Nathan James via Phabricator via cfe-commits
njames93 added inline comments.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/stddef.h:12
+
+using size_t = long long unsigned;
+

If this is all the file is used for, and it's only used for this one test file, 
can probably remove this header and inline the definition.
I also feel this definition may be fragile on certain platforms.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133436

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


[PATCH] D122078: [clang-tidy] Ignore concepts in `misc-redundant-expression`

2022-09-17 Thread Evgeny Shulgin via Phabricator via cfe-commits
Izaron updated this revision to Diff 461003.
Izaron added a comment.

Fix test with `count 0`, thanks to @njames93 !


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122078

Files:
  clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/test/clang-tidy/checkers/misc/redundant-expression-cxx20.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/misc/redundant-expression-cxx20.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/misc/redundant-expression-cxx20.cpp
@@ -0,0 +1,14 @@
+// RUN: clang-tidy %s -checks=-*,misc-redundant-expression -- -std=c++20 | count 0
+
+// Note: this test expects no diagnostics, but FileCheck cannot handle that,
+// hence the use of | count 0.
+
+namespace concepts {
+// redundant expressions inside concepts make sense, ignore them
+template 
+concept TestConcept = requires(I i) {
+  {i - i};
+  {i && i};
+  {i ? i : i};
+};
+} // namespace concepts
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -149,6 +149,12 @@
   copy assignment operators with nonstandard return types. The check is restricted to
   c++11-or-later.
 
+- Improved :doc:`misc-redundant-expression `
+  check.
+
+  The check now skips concept definitions since redundant expressions still make sense
+  inside them.
+
 Removed checks
 ^^
 
Index: clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp
===
--- clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp
+++ clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp
@@ -10,6 +10,7 @@
 #include "../utils/Matchers.h"
 #include "../utils/OptionsUtils.h"
 #include "clang/AST/ASTContext.h"
+#include "clang/AST/ExprConcepts.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/Basic/LLVM.h"
 #include "clang/Basic/SourceLocation.h"
@@ -440,6 +441,8 @@
   return Node.isIntegerConstantExpr(Finder->getASTContext());
 }
 
+AST_MATCHER(Expr, isRequiresExpr) { return isa(Node); }
+
 AST_MATCHER(BinaryOperator, operandsAreEquivalent) {
   return areEquivalentExpr(Node.getLHS(), Node.getRHS());
 }
@@ -858,6 +861,7 @@
 
   const auto BannedIntegerLiteral =
   integerLiteral(expandedByMacro(KnownBannedMacroNames));
+  const auto BannedAncestor = expr(isRequiresExpr());
 
   // Binary with equivalent operands, like (X != 2 && X != 2).
   Finder->addMatcher(
@@ -873,7 +877,8 @@
unless(hasType(realFloatingPointType())),
unless(hasEitherOperand(hasType(realFloatingPointType(,
unless(hasLHS(AnyLiteralExpr)),
-   unless(hasDescendant(BannedIntegerLiteral)))
+   unless(hasDescendant(BannedIntegerLiteral)),
+   unless(hasAncestor(BannedAncestor)))
.bind("binary")),
   this);
 
@@ -886,7 +891,8 @@
  unless(isInTemplateInstantiation()),
  unless(binaryOperatorIsInMacro()),
  // TODO: if the banned macros are themselves duplicated
- unless(hasDescendant(BannedIntegerLiteral)))
+ unless(hasDescendant(BannedIntegerLiteral)),
+ unless(hasAncestor(BannedAncestor)))
   .bind("nested-duplicates"),
   this);
 
@@ -896,7 +902,8 @@
conditionalOperator(expressionsAreEquivalent(),
// Filter noisy false positives.
unless(conditionalOperatorIsInMacro()),
-   unless(isInTemplateInstantiation()))
+   unless(isInTemplateInstantiation()),
+   unless(hasAncestor(BannedAncestor)))
.bind("cond")),
   this);
 
@@ -909,7 +916,8 @@
 ">=", "&&", "||", "="),
parametersAreEquivalent(),
// Filter noisy false positives.
-   unless(isMacro()), unless(isInTemplateInstantiation()))
+   unless(isMacro()), unless(isInTemplateInstantiation()),
+   unless(hasAncestor(BannedAncestor)))
.bind("call")),
   this);
 
@@ -919,7 +927,8 @@
   hasAnyOverloadedOperatorName("|", "&", "||", "&&", "^"),
   nestedParametersAreEquivalent(), argumentCountIs(2),
   // Filter noisy false positives.
-  unless(isMacro()), unless(isInTemplateInstantiation()))
+  unless(isMacro()), unless(isInTemplateInstantiation()),
+  unless(hasAncestor(BannedAncestor)))
   .b

[PATCH] D130793: [clang-tidy] adjust treating of array-of-pointers when 'AnalyzePointers' is deactivated

2022-09-17 Thread Nathan James via Phabricator via cfe-commits
njames93 accepted this revision.
njames93 added a comment.
This revision is now accepted and ready to land.

LGTM, just with one small testing nit




Comment at: 
clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-values.cpp:533
+  int *np_local0[2] = {nullptr, nullptr};
+  // CHECK-NOT-FIXES: int * const np_local0[2]
+  

This not fixes line is pretty redundant, and unstable. If you really want to 
ensure no fix was generated, you can do a check-fixes with the original line 
contents. But as there is no warning generated here there shouldn't be a need 
to check for any fix behaviour, same goes below.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130793

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


[PATCH] D133887: [Clang] Support label at end of compound statement

2022-09-17 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added inline comments.



Comment at: clang/lib/Parse/ParseStmt.cpp:738
+} else if (getLangOpts().C99 && !getLangOpts().C2x) {
+  Diag(Tok, diag::ext_c_label_end_of_compound_statement);
+}

I do not understand this. Why checking `getLangOpts().C99`  instead of just C? 
Whyt no compatibility warning in C23 mode?
I think the code should look very similar for both C++ and C


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133887

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


[PATCH] D133853: [AST] Add msvc-specific C++11 attributes

2022-09-17 Thread Richard Dzenis via Phabricator via cfe-commits
RIscRIpt added a comment.

In D133853#3795579 , @aaron.ballman 
wrote:

> but my suggestion is to only support `[[msvc::constexpr]]` with the semantic 
> meaning of `constexpr`

Sounds good to me.

> It's a good question as to whether we want to support that only when passing 
> `-fms-extensions` or not (it seems like a generally useful attribute); we 
> don't do the same for GNU attributes, but maybe we don't want to follow that 
> pattern? This will be the first attribute we add with the `msvc` vendor 
> namespace.

IMO, this attribute is a clearly Microsoft's extension, thus it should be 
available only when `-fms-extensions` are enabled.

> If you find there's a good reason to upstream the other ones, we can 
> certainly consider it.

I don't see any good reason for other attributes to be added.

> FWIW, one Microsoft-specific attribute I know people have been asking about 
> is `[[msvc::no_unique_address]]`

Thanks for letting me know.

The current patch is my first attempt to contribute to LLVM; I am afraid it 
would take me some effort to implement semantics of 
`[[msvc::no_unique_address]]`, so I'd like to focus only on 
`[[msvc::constexpr]]` in current patch.

In D133853#3795598 , @erichkeane 
wrote:

> A functional `msvc::constexpr` would be acceptable, however, I'm having a 
> difficult time figuring out the purpose of it, it seems like it is just a 
> 'constexpr keyword' replacement?

I don't know how it works internally, but judging by its behavior - yes it's a 
`constexpr` replacement with some extended functionality (my guess is that they 
wanted to do some constexpr magic, and staying compatible with the standard at 
the same time), and there's a few information available online:

> Merged an MSVC-specific attribute, allowing the compiler to improve its 
> handling of constexpr dynamic allocation and constexpr unique_ptr. [1]



>   // Determine if we should use [[msvc::constexpr]] to allow for "extended 
> constexpr" in Visual C++. [2]

Browsing MSVC `14.33.31629` include headers I can see that this attribute is 
mostly used in `operator new` functions: either as a decorator of the function 
or the return statement.

I guess the best way to make this attribute compatible with MSVC would be ask 
someone at Microsoft, but I'm not sure who to reach out.

Meanwhile I'll adjust current patch to focus only `[[msvc::constexpr]]` 
attribute.

> I believe the 'unknown attribute' warning for them is superior to an ignored 
> attribute.

By the way, I'd like to take opportunity and ask what do you think of adding 
clang-specific compiler flag, which would add all unknown attributes to the AST 
in a string form (e.g. `[[attr1]] -> AST::UnknownAttr{"attr1"}`? Would you be 
interested in such patch?

[1] https://github.com/microsoft/STL/wiki/Changelog

[2] `14.33.31629\include\vcruntime.h`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133853

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


[PATCH] D122078: [clang-tidy] Ignore concepts in `misc-redundant-expression`

2022-09-17 Thread Nathan James via Phabricator via cfe-commits
njames93 added a comment.

In D122078#3797519 , @Izaron wrote:

> The new file was failing with message
>
>   CHECK-FIXES, CHECK-MESSAGES or CHECK-NOTES not found in the input
>
> So I had to add an additional urrelevant check.
> I added a check for consteval function (there were no such tests previously).

You don't need the unrelated tests, you can use a special run line that will 
check that no warnings are emitted.
`// RUN: clang-tidy %s --checks=-*,misc-redundant-expression -- | count 0`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122078

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


[PATCH] D133887: [Clang] Support label at end of compound statement

2022-09-17 Thread Evgeny Shulgin via Phabricator via cfe-commits
Izaron updated this revision to Diff 461002.
Izaron added a comment.

Add diagnostics for C language


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133887

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/lib/Parse/ParseStmt.cpp
  clang/test/AST/ast-dump-stmt.c
  clang/test/Parser/c2x-label.c
  clang/test/Parser/cxx2b-label.cpp
  clang/test/Parser/switch-recovery.cpp
  clang/www/c_status.html
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -1456,7 +1456,7 @@
 
   Labels at the end of compound statements
   https://wg21.link/P2324R2";>P2324R2
-  No
+  Clang 16
 
 
   Delimited escape sequences
Index: clang/www/c_status.html
===
--- clang/www/c_status.html
+++ clang/www/c_status.html
@@ -763,7 +763,7 @@
 
   Free positioning of labels inside compound statements
   https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2508.pdf";>N2508
-  No
+  Clang 16
 
 
   Clarification request for C17 example of undefined behavior
Index: clang/test/Parser/switch-recovery.cpp
===
--- clang/test/Parser/switch-recovery.cpp
+++ clang/test/Parser/switch-recovery.cpp
@@ -160,14 +160,14 @@
 void missing_statement_case(int x) {
   switch (x) {
 case 1:
-case 0: // expected-error {{label at end of compound statement: expected statement}}
+case 0: // expected-error {{label at end of switch compound statement: expected statement}}
   }
 }
 
 void missing_statement_default(int x) {
   switch (x) {
 case 0:
-default: // expected-error {{label at end of compound statement: expected statement}}
+default: // expected-error {{label at end of switch compound statement: expected statement}}
   }
 }
 
@@ -179,7 +179,7 @@
 void pr19022_1a(int x) {
   switch(x) {
   case 1  // expected-error{{expected ':' after 'case'}} \
-  // expected-error{{label at end of compound statement: expected statement}}
+  // expected-error{{label at end of switch compound statement: expected statement}}
   }
 }
 
Index: clang/test/Parser/cxx2b-label.cpp
===
--- /dev/null
+++ clang/test/Parser/cxx2b-label.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -fsyntax-only -verify=expected,cxx2b -std=c++2b -Wpre-c++2b-compat %s
+// RUN: %clang_cc1 -fsyntax-only -verify=expected,cxx20 -std=c++20 %s
+
+void foo() {
+label1:
+int x;
+label2:
+x = 1;
+label3: label4: label5:
+} // cxx20-warning {{label at end of compound statement is a C++2b extension}} \
+ cxx2b-warning {{label at end of compound statement is incompatible with C++ standards before C++2b}}
Index: clang/test/Parser/c2x-label.c
===
--- /dev/null
+++ clang/test/Parser/c2x-label.c
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c17 -Wc2x-compat -verify=c17 %s
+// RUN: %clang_cc1 -fsyntax-only -std=c2x -Wpre-c2x-compat -verify=c2x %s
+
+// c2x-no-diagnostics
+
+void foo() {
+int x;
+label1:
+x = 1;
+label2: label3: label4:
+} // c17-warning {{label at end of compound statement is a C2x extension}}
Index: clang/test/AST/ast-dump-stmt.c
===
--- clang/test/AST/ast-dump-stmt.c
+++ clang/test/AST/ast-dump-stmt.c
@@ -161,6 +161,10 @@
   // CHECK-NEXT: ImplicitCastExpr
   // CHECK-NEXT: ImplicitCastExpr
   // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}}  'void *' lvalue Var 0x{{[^ ]*}} 'ptr' 'void *'
+
+label3:
+  // CHECK-NEXT: LabelStmt 0x{{[^ ]*}}  'label3'
+  // CHECK-NEXT: NullStmt 0x{{[^ ]*}} 
 }
 
 void TestSwitch(int i) {
Index: clang/lib/Parse/ParseStmt.cpp
===
--- clang/lib/Parse/ParseStmt.cpp
+++ clang/lib/Parse/ParseStmt.cpp
@@ -679,9 +679,12 @@
 
 /// ParseLabeledStatement - We have an identifier and a ':' after it.
 ///
+///   label:
+/// identifier ':'
+/// [GNU]   identifier ':' attributes[opt]
+///
 ///   labeled-statement:
-/// identifier ':' statement
-/// [GNU]   identifier ':' attributes[opt] statement
+/// label statement
 ///
 StmtResult Parser::ParseLabeledStatement(ParsedAttributes &Attrs,
  ParsedStmtContext StmtCtx) {
@@ -725,6 +728,18 @@
 }
   }
 
+  // The label may have no statement following it
+  if (SubStmt.isUnset() && Tok.is(tok::r_brace)) {
+if (getLangOpts().CPlusPlus) {
+  Diag(Tok, getLangOpts().CPlusPlus2b
+? diag::warn_cxx20_compat_label_end_of_compound_statement
+: diag::ext_cxx_label_end_of_comp

[PATCH] D134103: [clang-format] Skip token annotation in passes that don't need it

2022-09-17 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks accepted this revision.
HazardyKnusperkeks added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/lib/Format/Format.cpp:3276
   Passes.emplace_back([&](const Environment &Env) {
-return BracesInserter(Env, Expanded).process();
+return BracesInserter(Env, Expanded).process(/*SkipsAnnotation=*/true);
   });

Superfluous s here and in all comments. :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134103

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


[PATCH] D134042: [clang-format] Fix alignment in #else preprocessor blocks

2022-09-17 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks accepted this revision.
HazardyKnusperkeks added a comment.
This revision is now accepted and ready to land.

Looks good, please wait for other reviewers.




Comment at: clang/unittests/Format/FormatTest.cpp:5747
+TEST_F(FormatTest, FormatAlignInsidePreprocessorElseBlock) {
+  FormatStyle Style = getLLVMStyleWithColumns(40);
+  Style.AlignConsecutiveAssignments.Enabled = true;

Why limit the columns?


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

https://reviews.llvm.org/D134042

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


[PATCH] D134057: [clang][Interp] Start implementing record types

2022-09-17 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 461001.

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

https://reviews.llvm.org/D134057

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/ByteCodeExprGen.h
  clang/lib/AST/Interp/ByteCodeStmtGen.cpp
  clang/lib/AST/Interp/Interp.h
  clang/lib/AST/Interp/Record.h
  clang/test/AST/Interp/records.cpp
  clang/test/AST/Interp/references.cpp

Index: clang/test/AST/Interp/references.cpp
===
--- clang/test/AST/Interp/references.cpp
+++ clang/test/AST/Interp/references.cpp
@@ -83,9 +83,9 @@
   S s{1, 2};
 
   int &j = s.i;
-  j += 10;
+  j = j + 10;
 
   return j;
 }
 // FIXME: Should be accepted.
-static_assert(RefToMemberExpr() == 11, ""); // expected-error {{not an integral constant expression}}
+static_assert(RefToMemberExpr() == 11, "");
Index: clang/test/AST/Interp/records.cpp
===
--- /dev/null
+++ clang/test/AST/Interp/records.cpp
@@ -0,0 +1,88 @@
+// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -verify %s
+// RUN: %clang_cc1 -verify=ref %s
+
+// ref-no-diagnostics
+// expected-no-diagnostics
+
+struct Ints {
+  int a = 20;
+  int b = 30;
+  bool c = true;
+
+  static const int five = 5;
+  static constexpr int getFive() {
+return five;
+  }
+
+  constexpr int getTen() const {
+return 10;
+  }
+};
+
+constexpr Ints getInts() {
+  return {64, 128, true};
+}
+
+static_assert(Ints::getFive() == 5, "");
+
+constexpr Ints ints;
+static_assert(ints.a == 20, "");
+static_assert(ints.b == 30, "");
+static_assert(ints.c, "");
+static_assert(ints.getTen() == 10, "");
+
+constexpr Ints ints2{-20, -30, false};
+static_assert(ints2.a == -20, "");
+static_assert(ints2.b == -30, "");
+static_assert(!ints2.c, "");
+
+constexpr Ints ints3 = getInts();
+static_assert(ints3.a == 64, "");
+static_assert(ints3.b == 128, "");
+static_assert(ints3.c, "");
+
+
+// FIXME: Implement initialization by DeclRefExpr.
+//constexpr Ints ints4 = ints3;  TODO
+
+
+
+struct Ints2 {
+  int a = 10;
+  int b;
+};
+// FIXME: Broken in the new constant interpreter.
+//   Should be rejected, but without asan errors.
+//constexpr Ints2 ints2;
+
+class C {
+  public:
+int a;
+int b;
+
+  constexpr C() : a(100), b(200) {}
+};
+
+constexpr C c;
+static_assert(c.a == 100, "");
+static_assert(c.b == 200, "");
+
+constexpr int getB() {
+  C c;
+  int &j = c.b;
+
+  j = j * 2;
+
+  return c.b;
+}
+static_assert(getB() == 400, "");
+
+constexpr int getA(const C &c) {
+  return c.a;
+}
+static_assert(getA(c) == 100, "");
+
+constexpr const C* getPointer() {
+  return &c;
+}
+static_assert(getPointer()->a == 100, "");
Index: clang/lib/AST/Interp/Record.h
===
--- clang/lib/AST/Interp/Record.h
+++ clang/lib/AST/Interp/Record.h
@@ -67,6 +67,7 @@
   }
 
   unsigned getNumFields() const { return Fields.size(); }
+  const Field *getField(unsigned I) const { return &Fields[I]; }
   Field *getField(unsigned I) { return &Fields[I]; }
 
   using const_base_iter = BaseList::const_iterator;
Index: clang/lib/AST/Interp/Interp.h
===
--- clang/lib/AST/Interp/Interp.h
+++ clang/lib/AST/Interp/Interp.h
@@ -492,6 +492,9 @@
   return true;
 }
 
+/// 1) Pops the value from the stack
+/// 2) Pops a pointer from the stack
+/// 3) Writes the value to field I of the pointer
 template ::T>
 bool InitField(InterpState &S, CodePtr OpPC, uint32_t I) {
   const T &Value = S.Stk.pop();
Index: clang/lib/AST/Interp/ByteCodeStmtGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeStmtGen.cpp
+++ clang/lib/AST/Interp/ByteCodeStmtGen.cpp
@@ -94,10 +94,6 @@
   // Classify the return type.
   ReturnType = this->classify(F->getReturnType());
 
-  // Set up fields and context if a constructor.
-  if (auto *MD = dyn_cast(F))
-return this->bail(MD);
-
   if (auto *Body = F->getBody())
 if (!visitStmt(Body))
   return false;
Index: clang/lib/AST/Interp/ByteCodeExprGen.h
===
--- clang/lib/AST/Interp/ByteCodeExprGen.h
+++ clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -71,6 +71,7 @@
   bool VisitBinaryOperator(const BinaryOperator *E);
   bool VisitCXXDefaultArgExpr(const CXXDefaultArgExpr *E);
   bool VisitCallExpr(const CallExpr *E);
+  bool VisitCXXDefaultInitExpr(const CXXDefaultInitExpr *E);
   bool VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *E);
   bool VisitCXXNullPtrLiteralExpr(const CXXNullPtrLiteralExpr *E);
   bool VisitUnaryOperator(const UnaryOperator *E);
@@ -81,6 +82,7 @@
   bool VisitInitListExpr(const InitListExpr *E);
   bool VisitConstantExpr(const ConstantExpr *E);
   bool VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *E);
+  bool VisitMemberExpr(const MemberExpr *E);
 
 protect

[PATCH] D134057: [clang][Interp] Start implementing record types

2022-09-17 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 460998.

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

https://reviews.llvm.org/D134057

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/ByteCodeExprGen.h
  clang/lib/AST/Interp/ByteCodeStmtGen.cpp
  clang/lib/AST/Interp/Interp.h
  clang/lib/AST/Interp/Record.h
  clang/test/AST/Interp/records.cpp
  clang/test/AST/Interp/references.cpp

Index: clang/test/AST/Interp/references.cpp
===
--- clang/test/AST/Interp/references.cpp
+++ clang/test/AST/Interp/references.cpp
@@ -83,9 +83,9 @@
   S s{1, 2};
 
   int &j = s.i;
-  j += 10;
+  j = j + 10;
 
   return j;
 }
 // FIXME: Should be accepted.
-static_assert(RefToMemberExpr() == 11, ""); // expected-error {{not an integral constant expression}}
+static_assert(RefToMemberExpr() == 11, "");
Index: clang/test/AST/Interp/records.cpp
===
--- /dev/null
+++ clang/test/AST/Interp/records.cpp
@@ -0,0 +1,88 @@
+// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -verify %s
+// RUN: %clang_cc1 -verify=ref %s
+
+// ref-no-diagnostics
+// expected-no-diagnostics
+
+struct Ints {
+  int a = 20;
+  int b = 30;
+  bool c = true;
+
+  static const int five = 5;
+  static constexpr int getFive() {
+return five;
+  }
+
+  constexpr int getTen() const {
+return 10;
+  }
+};
+
+constexpr Ints getInts() {
+  return {64, 128, true};
+}
+
+static_assert(Ints::getFive() == 5, "");
+
+constexpr Ints ints;
+static_assert(ints.a == 20, "");
+static_assert(ints.b == 30, "");
+static_assert(ints.c, "");
+static_assert(ints.getTen() == 10, "");
+
+constexpr Ints ints2{-20, -30, false};
+static_assert(ints2.a == -20, "");
+static_assert(ints2.b == -30, "");
+static_assert(!ints2.c, "");
+
+constexpr Ints ints3 = getInts();
+static_assert(ints3.a == 64, "");
+static_assert(ints3.b == 128, "");
+static_assert(ints3.c, "");
+
+
+// FIXME: Implement initialization by DeclRefExpr.
+//constexpr Ints ints4 = ints3;  TODO
+
+
+
+struct Ints2 {
+  int a = 10;
+  int b;
+};
+// FIXME: Broken in the new constant interpreter.
+//   Should be rejected, but without asan errors.
+//constexpr Ints2 ints2;
+
+class C {
+  public:
+int a;
+int b;
+
+  constexpr C() : a(100), b(200) {}
+};
+
+constexpr C c;
+static_assert(c.a == 100, "");
+static_assert(c.b == 200, "");
+
+constexpr int getB() {
+  C c;
+  int &j = c.b;
+
+  j = j * 2;
+
+  return c.b;
+}
+static_assert(getB() == 400, "");
+
+constexpr int getA(const C &c) {
+  return c.a;
+}
+static_assert(getA(c) == 100, "");
+
+constexpr const C* getPointer() {
+  return &c;
+}
+static_assert(getPointer()->a == 100, "");
Index: clang/lib/AST/Interp/Record.h
===
--- clang/lib/AST/Interp/Record.h
+++ clang/lib/AST/Interp/Record.h
@@ -67,6 +67,7 @@
   }
 
   unsigned getNumFields() const { return Fields.size(); }
+  const Field *getField(unsigned I) const { return &Fields[I]; }
   Field *getField(unsigned I) { return &Fields[I]; }
 
   using const_base_iter = BaseList::const_iterator;
Index: clang/lib/AST/Interp/Interp.h
===
--- clang/lib/AST/Interp/Interp.h
+++ clang/lib/AST/Interp/Interp.h
@@ -492,6 +492,9 @@
   return true;
 }
 
+/// 1) Pops the value from the stack
+/// 2) Pops a pointer from the stack
+/// 3) Writes the value to field I of the pointer
 template ::T>
 bool InitField(InterpState &S, CodePtr OpPC, uint32_t I) {
   const T &Value = S.Stk.pop();
Index: clang/lib/AST/Interp/ByteCodeStmtGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeStmtGen.cpp
+++ clang/lib/AST/Interp/ByteCodeStmtGen.cpp
@@ -94,10 +94,6 @@
   // Classify the return type.
   ReturnType = this->classify(F->getReturnType());
 
-  // Set up fields and context if a constructor.
-  if (auto *MD = dyn_cast(F))
-return this->bail(MD);
-
   if (auto *Body = F->getBody())
 if (!visitStmt(Body))
   return false;
Index: clang/lib/AST/Interp/ByteCodeExprGen.h
===
--- clang/lib/AST/Interp/ByteCodeExprGen.h
+++ clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -71,6 +71,7 @@
   bool VisitBinaryOperator(const BinaryOperator *E);
   bool VisitCXXDefaultArgExpr(const CXXDefaultArgExpr *E);
   bool VisitCallExpr(const CallExpr *E);
+  bool VisitCXXDefaultInitExpr(const CXXDefaultInitExpr *E);
   bool VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *E);
   bool VisitCXXNullPtrLiteralExpr(const CXXNullPtrLiteralExpr *E);
   bool VisitUnaryOperator(const UnaryOperator *E);
@@ -81,6 +82,7 @@
   bool VisitInitListExpr(const InitListExpr *E);
   bool VisitConstantExpr(const ConstantExpr *E);
   bool VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *E);
+  bool VisitMemberExpr(const MemberExpr *E);
 
 protect

[clang] 7772624 - Add code examples to the potentially breaking changes

2022-09-17 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2022-09-17T08:44:13-04:00
New Revision: 7772624f3bac5499b36da8a20d5d73fcbc6f8683

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

LOG: Add code examples to the potentially breaking changes

It may help users to better understand the change by showing them a
contrived code example which demonstrates the difference in behavior.

Added: 


Modified: 
clang/docs/ReleaseNotes.rst

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index e81be2808fbd..240228a6d5e7 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -44,21 +44,40 @@ code bases.
 
 - Clang will now correctly diagnose as ill-formed a constant expression where 
an
   enum without a fixed underlying type is set to a value outside the range of
-  the enumeration's values. Due to the extended period of time this bug was
-  present in major C++ implementations (including Clang), this error has the
-  ability to be downgraded into a warning (via:
-  ``-Wno-error=enum-constexpr-conversion``) to provide a transition period for
-  users. This diagnostic is expected to turn into an error-only diagnostic in
-  the next Clang release. Fixes
-  `Issue 50055: `_.
+  the enumeration's values.
+
+  .. code-block:: c++
+
+enum E { Zero, One, Two, Three, Four };
+constexpr E Val1 = (E)3;  // Ok
+constexpr E Val2 = (E)7;  // Ok
+constexpr E Val3 = (E)8;  // Now diagnosed as out of the range [0, 7]
+constexpr E Val4 = (E)-1; // Now diagnosed as out of the range [0, 7]
+
+  Due to the extended period of time this bug was present in major C++
+  implementations (including Clang), this error has the ability to be
+  downgraded into a warning (via: ``-Wno-error=enum-constexpr-conversion``) to
+  provide a transition period for users. This diagnostic is expected to turn
+  into an error-only diagnostic in the next Clang release. Fixes
+  `Issue 50055 `_.
+
 - ``-Wincompatible-function-pointer-types`` now defaults to an error in all C
   language modes. It may be downgraded to a warning with
   ``-Wno-error=incompatible-function-pointer-types`` or disabled entirely with
-  ``-Wno-implicit-function-pointer-types``. *NOTE* We recommend that projects
-  using configure scripts verify the results do not change before/after setting
+  ``-Wno-implicit-function-pointer-types``.
+
+  **NOTE:** We recommend that projects using configure scripts verify that the
+  results do not change before/after setting
   ``-Werror=incompatible-function-pointer-types`` to avoid incompatibility with
   Clang 16.
 
+  .. code-block:: c
+
+void func(const int *i);
+void other(void) {
+  void (*fp)(int *) = func; // Previously a warning, now a downgradable 
error.
+}
+
 
 What's New in Clang |release|?
 ==



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


[clang] aa9a656 - Fix release note formatting and style; NFC

2022-09-17 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2022-09-17T08:21:33-04:00
New Revision: aa9a656b03c28386e367f69ceb311c94d62ac1ab

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

LOG: Fix release note formatting and style; NFC

Uses double backticks where appropriate, changes some instances of
GH12345 to be Issue 12345, etc.

Added: 


Modified: 
clang/docs/ReleaseNotes.rst

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 4c251d1dc6ed..e81be2808fbd 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -62,7 +62,6 @@ code bases.
 
 What's New in Clang |release|?
 ==
-
 Some of the major new features and improvements to Clang are listed
 here. Generic improvements to Clang as a whole or to its underlying
 infrastructure are described first, followed by language-specific
@@ -154,9 +153,10 @@ Improvements to Clang's diagnostics
   supports both c and c++ language.
 - When diagnosing multi-level pack expansions of mismatched lengths, Clang will
   now, in most cases, be able to point to the relevant outer parameter.
-- no_sanitize("...") on a global variable for known but not relevant sanitizers
-  is now just a warning. It now says that this will be ignored instead of
-  incorrectly saying no_sanitize only applies to functions and methods.
+- ``no_sanitize("...")`` on a global variable for known but not relevant
+  sanitizers is now just a warning. It now says that this will be ignored
+  instead of incorrectly saying no_sanitize only applies to functions and
+  methods.
 - No longer mention ``reinterpet_cast`` in the invalid constant expression
   diagnostic note when in C mode.
 - Clang will now give a more suitale diagnostic for declaration of block
@@ -233,16 +233,16 @@ Windows Support
 
 AIX Support
 ---
-* When using `-shared`, the clang driver now invokes llvm-nm to create an
+* When using ``-shared``, the clang driver now invokes llvm-nm to create an
   export list if the user doesn't specify one via linker flag or pass an
   alternative export control option.
 
 C Language Changes in Clang
 ---
-
 - Adjusted ``-Wformat`` warnings according to `WG14 N2562 
`_.
-  Clang will now consider default argument promotions in printf, and remove 
unnecessary warnings.
-  Especially ``int`` argument with specifier ``%hhd`` and ``%hd``.
+  Clang will now consider default argument promotions in ``printf``, and remove
+  unnecessary warnings. Especially ``int`` argument with specifier ``%hhd`` and
+  ``%hd``.
 
 C2x Feature Support
 ---
@@ -252,7 +252,6 @@ C2x Feature Support
 
 C++ Language Changes in Clang
 -
-
 - Implemented DR692, DR1395 and DR1432. Use the ``-fclang-abi-compat=15`` 
option
   to get the old partial ordering behavior regarding packs.
 - Clang's default C++/ObjC++ standard is now ``gnu++17`` instead of 
``gnu++14``.
@@ -262,38 +261,35 @@ C++ Language Changes in Clang
 
 C++20 Feature Support
 ^
-
 - Support capturing structured bindings in lambdas
   (`P1091R3 `_ and `P1381R1 
`).
-  This fixes issues `GH52720 
`_,
-  `GH54300 `_,
-  `GH54301 `_,
-  and `GH49430 `_.
+  This fixes issues `Issue 52720 
`_,
+  `Issue 54300 `_,
+  `Issue 54301 `_,
+  and `Issue 49430 `_.
 - Consider explicitly defaulted constexpr/consteval special member function
   template instantiation to be constexpr/consteval even though a call to such
   a function cannot appear in a constant expression.
   (C++14 [dcl.constexpr]p6 (CWG DR647/CWG DR1358))
 - Correctly defer dependent immediate function invocations until template 
instantiation.
-  This fixes `GH55601 `_.
+  This fixes `Issue 55601 
`_.
 - Implemented "Conditionally Trivial Special Member Functions" (`P0848 
`_).
   Note: The handling of deleted functions is not yet compliant, as Clang
   does not implement `DR1496 
`_
   and `DR1734 
`_.
 - Class member variables are now in scope when parsing

[clang] 1b2efe8 - Fix this test to be more robust

2022-09-17 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2022-09-17T08:06:16-04:00
New Revision: 1b2efe8d87b30052de944f0153d3833046b80604

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

LOG: Fix this test to be more robust

The test is failing because it lacks a target triple, so the number of
diagnostics differs between Windows and Linux targets.

This should correct the issue found by:
https://lab.llvm.org/buildbot/#/builders/109/builds/46804

Added: 


Modified: 
clang/test/CXX/drs/dr4xx.cpp

Removed: 




diff  --git a/clang/test/CXX/drs/dr4xx.cpp b/clang/test/CXX/drs/dr4xx.cpp
index 4995e4de65d3..2bf6133f8ad2 100644
--- a/clang/test/CXX/drs/dr4xx.cpp
+++ b/clang/test/CXX/drs/dr4xx.cpp
@@ -1013,7 +1013,7 @@ namespace dr483 { // dr483: yes
 int check4[__LONG_MAX__ >= 2147483647 ? 1 : -1];
 int check5[__LONG_LONG_MAX__ >= 9223372036854775807 ? 1 : -1];
 #if __cplusplus < 201103L
-// expected-error@-2 2{{extension}}
+// expected-error@-2 1+{{extension}}
 #endif
   }
   namespace cstdint {



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


[clang] 5d92d0b - Correctly diagnose use of long long literals w/o a suffix

2022-09-17 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2022-09-17T07:55:10-04:00
New Revision: 5d92d0b0f86c2c4e0c6ebd7b1e2113337fec041d

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

LOG: Correctly diagnose use of long long literals w/o a suffix

We would diagnose use of `long long` as an extension in C89 and C++98
modes when the user spelled the type `long long` or used the `LL`
literal suffix, but failed to diagnose when the literal had no suffix
but required a `long long` to represent the value.

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaExpr.cpp
clang/test/C/drs/dr2xx.c
clang/test/CXX/drs/dr4xx.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ccc3204edd2d2..4c251d1dc6ed7 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -168,6 +168,10 @@ Improvements to Clang's diagnostics
   conditional operator, and for most binary operations. Type sugar is combined
   in a way that strips the sugar which is 
diff erent between terms, and preserves
   those which are common.
+- Correctly diagnose use of an integer literal without a suffix whose
+  underlying type is ``long long`` or ``unsigned long long`` as an extension in
+  C89 mode . Clang previously only diagnosed if the literal had an explicit
+  ``LL`` suffix.
 
 Non-comprehensive list of changes in this release
 -

diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 348eaad3dee94..e53c88b283b87 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -3937,16 +3937,6 @@ ExprResult Sema::ActOnNumericConstant(const Token &Tok, 
Scope *UDLScope) {
   } else {
 QualType Ty;
 
-// 'long long' is a C99 or C++11 feature.
-if (!getLangOpts().C99 && Literal.isLongLong) {
-  if (getLangOpts().CPlusPlus)
-Diag(Tok.getLocation(),
- getLangOpts().CPlusPlus11 ?
- diag::warn_cxx98_compat_longlong : diag::ext_cxx11_longlong);
-  else
-Diag(Tok.getLocation(), diag::ext_c99_longlong);
-}
-
 // 'z/uz' literals are a C++2b feature.
 if (Literal.isSizeT)
   Diag(Tok.getLocation(), getLangOpts().CPlusPlus
@@ -4113,6 +4103,15 @@ ExprResult Sema::ActOnNumericConstant(const Token &Tok, 
Scope *UDLScope) {
   else if (AllowUnsigned)
 Ty = Context.UnsignedLongLongTy;
   Width = LongLongSize;
+
+  // 'long long' is a C99 or C++11 feature, whether the literal
+  // explicitly specified 'long long' or we needed the extra width.
+  if (getLangOpts().CPlusPlus)
+Diag(Tok.getLocation(), getLangOpts().CPlusPlus11
+? diag::warn_cxx98_compat_longlong
+: diag::ext_cxx11_longlong);
+  else if (!getLangOpts().C99)
+Diag(Tok.getLocation(), diag::ext_c99_longlong);
 }
   }
 

diff  --git a/clang/test/C/drs/dr2xx.c b/clang/test/C/drs/dr2xx.c
index 6b87aace6a910..95d8eefaa2a99 100644
--- a/clang/test/C/drs/dr2xx.c
+++ b/clang/test/C/drs/dr2xx.c
@@ -448,9 +448,11 @@ void dr298(void) {
   /* FIXME: These uses of the constants need a pedantic warning in C89 mode;
* we've picked a type that does not exist in C89.
*/
-  (void)_Generic(9223372036854775808, /* expected-warning {{integer 
literal is too large to be represented in a signed integer type, interpreting 
as unsigned}} */
+  (void)_Generic(9223372036854775808, /* expected-warning {{integer 
literal is too large to be represented in a signed integer type, interpreting 
as unsigned}}
+ c89only-warning {{'long long' is 
an extension when C99 mode is not enabled}}
+   */
  unsigned long long : 1); /* c89only-warning {{'long long' is 
an extension when C99 mode is not enabled}} */
-  (void)_Generic(9223372036854775807,
+  (void)_Generic(9223372036854775807, /* c89only-warning {{'long long' is 
an extension when C99 mode is not enabled}} */
  long long : 1);  /* c89only-warning {{'long long' is 
an extension when C99 mode is not enabled}} */
 }
 #endif /* __LLONG_WIDTH__ == 64 && __LONG_WIDTH__ < 64 */

diff  --git a/clang/test/CXX/drs/dr4xx.cpp b/clang/test/CXX/drs/dr4xx.cpp
index 16957dd9d0e39..4995e4de65d3f 100644
--- a/clang/test/CXX/drs/dr4xx.cpp
+++ b/clang/test/CXX/drs/dr4xx.cpp
@@ -1013,7 +1013,7 @@ namespace dr483 { // dr483: yes
 int check4[__LONG_MAX__ >= 2147483647 ? 1 : -1];
 int check5[__LONG_LONG_MAX__ >= 9223372036854775807 ? 1 : -1];
 #if __cplusplus < 201103L
-// expected-error@-2 {{extension}}
+// expected-error@-2 2{{ext

[PATCH] D133920: [X86][fastcall] Move capability check before free register update

2022-09-17 Thread Phoebe Wang via Phabricator via cfe-commits
pengfei updated this revision to Diff 460991.
pengfei marked 2 inline comments as done.
pengfei added a comment.

Address review comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133920

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/CodeGen/TargetInfo.cpp
  clang/test/CodeGen/mangle-windows.c


Index: clang/test/CodeGen/mangle-windows.c
===
--- clang/test/CodeGen/mangle-windows.c
+++ clang/test/CodeGen/mangle-windows.c
@@ -47,7 +47,7 @@
 // X64: define dso_local void @f8(
 
 void __fastcall f9(long long a, char b, char c, short d) {}
-// CHECK: define dso_local x86_fastcallcc void @"\01@f9@20"(i64 noundef %a, i8 
noundef signext %b, i8 noundef signext %c, i16 noundef signext %d)
+// CHECK: define dso_local x86_fastcallcc void @"\01@f9@20"(i64 noundef %a, i8 
inreg noundef signext %b, i8 inreg noundef signext %c, i16 noundef signext %d)
 // X64: define dso_local void @f9(
 
 void f12(void) {}
@@ -81,3 +81,6 @@
 void __vectorcall v6(char a, char b) {}
 // CHECK: define dso_local x86_vectorcallcc void @"\01v6@@8"(
 // X64: define dso_local x86_vectorcallcc void @"\01v6@@16"(
+
+void __vectorcall v7(long long a, char b, char c, short d) {}
+// CHECK: define dso_local x86_vectorcallcc void @"\01v7@@20"(i64 noundef %a, 
i8 inreg noundef signext %b, i8 inreg noundef signext %c, i16 noundef signext 
%d)
Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -1771,21 +1771,22 @@
 }
 
 bool X86_32ABIInfo::shouldPrimitiveUseInReg(QualType Ty, CCState &State) const 
{
-  if (!updateFreeRegs(Ty, State))
+  bool IsPtrOrInt = (getContext().getTypeSize(Ty) <= 32) &&
+(Ty->isIntegralOrEnumerationType() || Ty->isPointerType() 
||
+ Ty->isReferenceType());
+
+  if (!IsPtrOrInt && (State.CC == llvm::CallingConv::X86_FastCall ||
+  State.CC == llvm::CallingConv::X86_VectorCall))
 return false;
 
-  if (IsMCUABI)
+  if (!updateFreeRegs(Ty, State))
 return false;
 
-  if (State.CC == llvm::CallingConv::X86_FastCall ||
-  State.CC == llvm::CallingConv::X86_VectorCall ||
-  State.CC == llvm::CallingConv::X86_RegCall) {
-if (getContext().getTypeSize(Ty) > 32)
-  return false;
+  if (!IsPtrOrInt && State.CC == llvm::CallingConv::X86_RegCall)
+return false;
 
-return (Ty->isIntegralOrEnumerationType() || Ty->isPointerType() ||
-Ty->isReferenceType());
-  }
+  if (IsMCUABI)
+return false;
 
   return true;
 }
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -277,6 +277,7 @@
 
 
 - Support ``-mindirect-branch-cs-prefix`` for call and jmp to indirect thunk.
+- Fix 32-bit ``__fastcall`` and ``__vectorcall`` ABI mismatch with MSVC.
 
 DWARF Support in Clang
 --


Index: clang/test/CodeGen/mangle-windows.c
===
--- clang/test/CodeGen/mangle-windows.c
+++ clang/test/CodeGen/mangle-windows.c
@@ -47,7 +47,7 @@
 // X64: define dso_local void @f8(
 
 void __fastcall f9(long long a, char b, char c, short d) {}
-// CHECK: define dso_local x86_fastcallcc void @"\01@f9@20"(i64 noundef %a, i8 noundef signext %b, i8 noundef signext %c, i16 noundef signext %d)
+// CHECK: define dso_local x86_fastcallcc void @"\01@f9@20"(i64 noundef %a, i8 inreg noundef signext %b, i8 inreg noundef signext %c, i16 noundef signext %d)
 // X64: define dso_local void @f9(
 
 void f12(void) {}
@@ -81,3 +81,6 @@
 void __vectorcall v6(char a, char b) {}
 // CHECK: define dso_local x86_vectorcallcc void @"\01v6@@8"(
 // X64: define dso_local x86_vectorcallcc void @"\01v6@@16"(
+
+void __vectorcall v7(long long a, char b, char c, short d) {}
+// CHECK: define dso_local x86_vectorcallcc void @"\01v7@@20"(i64 noundef %a, i8 inreg noundef signext %b, i8 inreg noundef signext %c, i16 noundef signext %d)
Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -1771,21 +1771,22 @@
 }
 
 bool X86_32ABIInfo::shouldPrimitiveUseInReg(QualType Ty, CCState &State) const {
-  if (!updateFreeRegs(Ty, State))
+  bool IsPtrOrInt = (getContext().getTypeSize(Ty) <= 32) &&
+(Ty->isIntegralOrEnumerationType() || Ty->isPointerType() ||
+ Ty->isReferenceType());
+
+  if (!IsPtrOrInt && (State.CC == llvm::CallingConv::X86_FastCall ||
+  State.CC == llvm::CallingConv::X86_VectorCall))
 return false;
 
-  if (IsMCUABI)
+  if (!updateFreeRegs(Ty, State))
 return false;
 
-  if (State.CC == llvm::Callin

[PATCH] D122078: [clang-tidy] Ignore concepts in `misc-redundant-expression`

2022-09-17 Thread Evgeny Shulgin via Phabricator via cfe-commits
Izaron updated this revision to Diff 460990.
Izaron added a comment.

The new file was failing with message

  CHECK-FIXES, CHECK-MESSAGES or CHECK-NOTES not found in the input

So I had to add an additional urrelevant check.
I added a check for consteval function (there were no such tests previously).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122078

Files:
  clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/test/clang-tidy/checkers/misc/redundant-expression-cxx20.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/misc/redundant-expression-cxx20.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/misc/redundant-expression-cxx20.cpp
@@ -0,0 +1,17 @@
+// RUN: %check_clang_tidy %s misc-redundant-expression -std=c++20 %t -- -- -fno-delayed-template-parsing
+
+consteval int TestOperatorConfusion(int X) {
+  X = (X << 8) & 0xff;
+  // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: ineffective bitwise and operation
+  return X;
+}
+
+namespace concepts {
+// redundant expressions inside concepts make sense, ignore them
+template 
+concept TestConcept = requires(I i) {
+  {i - i};
+  {i && i};
+  {i ? i : i};
+};
+} // namespace concepts
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -149,6 +149,12 @@
   copy assignment operators with nonstandard return types. The check is restricted to
   c++11-or-later.
 
+- Improved :doc:`misc-redundant-expression `
+  check.
+
+  The check now skips concept definitions since redundant expressions still make sense
+  inside them.
+
 Removed checks
 ^^
 
Index: clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp
===
--- clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp
+++ clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp
@@ -10,6 +10,7 @@
 #include "../utils/Matchers.h"
 #include "../utils/OptionsUtils.h"
 #include "clang/AST/ASTContext.h"
+#include "clang/AST/ExprConcepts.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/Basic/LLVM.h"
 #include "clang/Basic/SourceLocation.h"
@@ -440,6 +441,8 @@
   return Node.isIntegerConstantExpr(Finder->getASTContext());
 }
 
+AST_MATCHER(Expr, isRequiresExpr) { return isa(Node); }
+
 AST_MATCHER(BinaryOperator, operandsAreEquivalent) {
   return areEquivalentExpr(Node.getLHS(), Node.getRHS());
 }
@@ -858,6 +861,7 @@
 
   const auto BannedIntegerLiteral =
   integerLiteral(expandedByMacro(KnownBannedMacroNames));
+  const auto BannedAncestor = expr(isRequiresExpr());
 
   // Binary with equivalent operands, like (X != 2 && X != 2).
   Finder->addMatcher(
@@ -873,7 +877,8 @@
unless(hasType(realFloatingPointType())),
unless(hasEitherOperand(hasType(realFloatingPointType(,
unless(hasLHS(AnyLiteralExpr)),
-   unless(hasDescendant(BannedIntegerLiteral)))
+   unless(hasDescendant(BannedIntegerLiteral)),
+   unless(hasAncestor(BannedAncestor)))
.bind("binary")),
   this);
 
@@ -886,7 +891,8 @@
  unless(isInTemplateInstantiation()),
  unless(binaryOperatorIsInMacro()),
  // TODO: if the banned macros are themselves duplicated
- unless(hasDescendant(BannedIntegerLiteral)))
+ unless(hasDescendant(BannedIntegerLiteral)),
+ unless(hasAncestor(BannedAncestor)))
   .bind("nested-duplicates"),
   this);
 
@@ -896,7 +902,8 @@
conditionalOperator(expressionsAreEquivalent(),
// Filter noisy false positives.
unless(conditionalOperatorIsInMacro()),
-   unless(isInTemplateInstantiation()))
+   unless(isInTemplateInstantiation()),
+   unless(hasAncestor(BannedAncestor)))
.bind("cond")),
   this);
 
@@ -909,7 +916,8 @@
 ">=", "&&", "||", "="),
parametersAreEquivalent(),
// Filter noisy false positives.
-   unless(isMacro()), unless(isInTemplateInstantiation()))
+   unless(isMacro()), unless(isInTemplateInstantiation()),
+   unless(hasAncestor(BannedAncestor)))
.bind("call")),
   this);
 
@@ -919,7 +927,8 @@
   hasAnyOverloadedOperatorName("|", "&", "||", "&&", "^"),
   nestedParametersAreEquiva

[PATCH] D109621: [clang] [Driver] Fall back to default.cfg when calling clang w/o prefix

2022-09-17 Thread Michał Górny via Phabricator via cfe-commits
mgorny added a comment.

As an example, we are currently installing the following set of executables + 
symlinks for clang in Gentoo on amd64 with full multilib:

  lrwxrwxrwx 1 root root8 Sep 17 12:31 /usr/lib/llvm/16/bin/clang -> 
clang-16
  lrwxrwxrwx 1 root root   10 Sep 17 12:31 /usr/lib/llvm/16/bin/clang++ -> 
clang++-16
  lrwxrwxrwx 1 root root8 Sep 17 12:31 /usr/lib/llvm/16/bin/clang++-16 -> 
clang-16
  -rwxr-xr-x 1 root root 170K Sep 17 12:31 /usr/lib/llvm/16/bin/clang-16
  lrwxrwxrwx 1 root root   11 Sep 17 12:31 /usr/lib/llvm/16/bin/clang-cl -> 
clang-cl-16
  lrwxrwxrwx 1 root root8 Sep 17 12:31 /usr/lib/llvm/16/bin/clang-cl-16 -> 
clang-16
  lrwxrwxrwx 1 root root   12 Sep 17 12:31 /usr/lib/llvm/16/bin/clang-cpp -> 
clang-cpp-16
  lrwxrwxrwx 1 root root8 Sep 17 12:31 /usr/lib/llvm/16/bin/clang-cpp-16 -> 
clang-16
  lrwxrwxrwx 1 root root   26 Sep 17 12:31 
/usr/lib/llvm/16/bin/i686-pc-linux-gnu-clang -> i686-pc-linux-gnu-clang-16
  lrwxrwxrwx 1 root root   28 Sep 17 12:31 
/usr/lib/llvm/16/bin/i686-pc-linux-gnu-clang++ -> i686-pc-linux-gnu-clang++-16
  lrwxrwxrwx 1 root root   10 Sep 17 12:31 
/usr/lib/llvm/16/bin/i686-pc-linux-gnu-clang++-16 -> clang++-16
  lrwxrwxrwx 1 root root8 Sep 17 12:31 
/usr/lib/llvm/16/bin/i686-pc-linux-gnu-clang-16 -> clang-16
  lrwxrwxrwx 1 root root   29 Sep 17 12:31 
/usr/lib/llvm/16/bin/i686-pc-linux-gnu-clang-cl -> i686-pc-linux-gnu-clang-cl-16
  lrwxrwxrwx 1 root root   11 Sep 17 12:31 
/usr/lib/llvm/16/bin/i686-pc-linux-gnu-clang-cl-16 -> clang-cl-16
  lrwxrwxrwx 1 root root   30 Sep 17 12:31 
/usr/lib/llvm/16/bin/i686-pc-linux-gnu-clang-cpp -> 
i686-pc-linux-gnu-clang-cpp-16
  lrwxrwxrwx 1 root root   12 Sep 17 12:31 
/usr/lib/llvm/16/bin/i686-pc-linux-gnu-clang-cpp-16 -> clang-cpp-16
  lrwxrwxrwx 1 root root   28 Sep 17 12:31 
/usr/lib/llvm/16/bin/x86_64-pc-linux-gnu-clang -> x86_64-pc-linux-gnu-clang-16
  lrwxrwxrwx 1 root root   30 Sep 17 12:31 
/usr/lib/llvm/16/bin/x86_64-pc-linux-gnu-clang++ -> 
x86_64-pc-linux-gnu-clang++-16
  lrwxrwxrwx 1 root root   10 Sep 17 12:31 
/usr/lib/llvm/16/bin/x86_64-pc-linux-gnu-clang++-16 -> clang++-16
  lrwxrwxrwx 1 root root8 Sep 17 12:31 
/usr/lib/llvm/16/bin/x86_64-pc-linux-gnu-clang-16 -> clang-16
  lrwxrwxrwx 1 root root   31 Sep 17 12:31 
/usr/lib/llvm/16/bin/x86_64-pc-linux-gnu-clang-cl -> 
x86_64-pc-linux-gnu-clang-cl-16
  lrwxrwxrwx 1 root root   11 Sep 17 12:31 
/usr/lib/llvm/16/bin/x86_64-pc-linux-gnu-clang-cl-16 -> clang-cl-16
  lrwxrwxrwx 1 root root   32 Sep 17 12:31 
/usr/lib/llvm/16/bin/x86_64-pc-linux-gnu-clang-cpp -> 
x86_64-pc-linux-gnu-clang-cpp-16
  lrwxrwxrwx 1 root root   12 Sep 17 12:31 
/usr/lib/llvm/16/bin/x86_64-pc-linux-gnu-clang-cpp-16 -> clang-cpp-16
  lrwxrwxrwx 1 root root   31 Sep 17 12:31 
/usr/lib/llvm/16/bin/x86_64-pc-linux-gnux32-clang -> 
x86_64-pc-linux-gnux32-clang-16
  lrwxrwxrwx 1 root root   33 Sep 17 12:31 
/usr/lib/llvm/16/bin/x86_64-pc-linux-gnux32-clang++ -> 
x86_64-pc-linux-gnux32-clang++-16
  lrwxrwxrwx 1 root root   10 Sep 17 12:31 
/usr/lib/llvm/16/bin/x86_64-pc-linux-gnux32-clang++-16 -> clang++-16
  lrwxrwxrwx 1 root root8 Sep 17 12:31 
/usr/lib/llvm/16/bin/x86_64-pc-linux-gnux32-clang-16 -> clang-16
  lrwxrwxrwx 1 root root   34 Sep 17 12:31 
/usr/lib/llvm/16/bin/x86_64-pc-linux-gnux32-clang-cl -> 
x86_64-pc-linux-gnux32-clang-cl-16
  lrwxrwxrwx 1 root root   11 Sep 17 12:31 
/usr/lib/llvm/16/bin/x86_64-pc-linux-gnux32-clang-cl-16 -> clang-cl-16
  lrwxrwxrwx 1 root root   35 Sep 17 12:31 
/usr/lib/llvm/16/bin/x86_64-pc-linux-gnux32-clang-cpp -> 
x86_64-pc-linux-gnux32-clang-cpp-16
  lrwxrwxrwx 1 root root   12 Sep 17 12:31 
/usr/lib/llvm/16/bin/x86_64-pc-linux-gnux32-clang-cpp-16 -> clang-cpp-16

…and we can cover all of them using four config files:

  -rw-r--r-- 1 root root  0 Sep 17 13:30 default.cfg
  lrwxrwxrwx 1 root root 11 Sep 17 12:31 i686-pc-linux-gnu.cfg -> default.cfg
  lrwxrwxrwx 1 root root 11 Sep 17 12:31 x86_64-pc-linux-gnu.cfg -> default.cfg
  lrwxrwxrwx 1 root root 11 Sep 17 12:31 x86_64-pc-linux-gnux32.cfg -> 
default.cfg


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

https://reviews.llvm.org/D109621

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


[PATCH] D130793: [clang-tidy] adjust treating of array-of-pointers when 'AnalyzePointers' is deactivated

2022-09-17 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth marked an inline comment as done.
JonasToth added a comment.

ping @njames93 :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130793

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


[PATCH] D133887: [Clang] Support label at end of compound statement

2022-09-17 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added a comment.

In D133887#3797491 , @Izaron wrote:

>> It should definitely be without warning in C23 mode and give an extension 
>> warning in earlier modes.
>
> @aaron.ballman we have this extension warning for pre-C++23:
>
>   def ext_label_end_of_compound_statement : ExtWarn<
> "label at end of compound statement is a C++2b extension">,
>  InGroup;
>
> Should I add a new warning for pre-C23? We could have two warnings for each 
> language:
>
>   ext_cxx_label_end_of_compound_statement
>   ext_c_label_end_of_compound_statement

I think that's reasonable, yes - given that we need different warning groups


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133887

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


[PATCH] D134105: [Docs] Add a link that refers to C++ standard modules in Clang modules doc

2022-09-17 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added a comment.

Thanks. I wanted to do this. I suggest to do the change in later sections. 
Since the document talks more than the clang modules extension. It also 
describes some general module properties and semantics.  It is a pretty 
document and from my point of view, it shouldn be helpful for people who desire 
C++20 Modules to read this (at least the sections in the frontend).

BTW, have you tested to generate the document?




Comment at: clang/docs/Modules.rst:104
 To enable modules, pass the command-line flag ``-fmodules``. This will make 
any modules-enabled software libraries available as modules as well as 
introducing any modules-specific syntax. Additional `command-line parameters`_ 
are described in a separate section later.
 
 Objective-C Import declaration




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134105

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


[PATCH] D133887: [Clang] Support label at end of compound statement

2022-09-17 Thread Evgeny Shulgin via Phabricator via cfe-commits
Izaron added a comment.

> It should definitely be without warning in C23 mode and give an extension 
> warning in earlier modes.

@aaron.ballman we have this extension warning for pre-C++23:

  def ext_label_end_of_compound_statement : ExtWarn<
"label at end of compound statement is a C++2b extension">,
 InGroup;

Should I add a new warning for pre-C23? We could have two warnings for each 
language:

  ext_cxx_label_end_of_compound_statement
  ext_c_label_end_of_compound_statement


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133887

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


[PATCH] D133887: [Clang] Support label at end of compound statement

2022-09-17 Thread Evgeny Shulgin via Phabricator via cfe-commits
Izaron updated this revision to Diff 460987.
Izaron added a comment.

Change C2x implementation status and C2x release notes

Add an AST test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133887

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/lib/Parse/ParseStmt.cpp
  clang/test/AST/ast-dump-stmt.c
  clang/test/Parser/cxx2b-label.cpp
  clang/test/Parser/switch-recovery.cpp
  clang/www/c_status.html
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -1456,7 +1456,7 @@
 
   Labels at the end of compound statements
   https://wg21.link/P2324R2";>P2324R2
-  No
+  Clang 16
 
 
   Delimited escape sequences
Index: clang/www/c_status.html
===
--- clang/www/c_status.html
+++ clang/www/c_status.html
@@ -763,7 +763,7 @@
 
   Free positioning of labels inside compound statements
   https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2508.pdf";>N2508
-  No
+  Clang 16
 
 
   Clarification request for C17 example of undefined behavior
Index: clang/test/Parser/switch-recovery.cpp
===
--- clang/test/Parser/switch-recovery.cpp
+++ clang/test/Parser/switch-recovery.cpp
@@ -160,14 +160,14 @@
 void missing_statement_case(int x) {
   switch (x) {
 case 1:
-case 0: // expected-error {{label at end of compound statement: expected statement}}
+case 0: // expected-error {{label at end of switch compound statement: expected statement}}
   }
 }
 
 void missing_statement_default(int x) {
   switch (x) {
 case 0:
-default: // expected-error {{label at end of compound statement: expected statement}}
+default: // expected-error {{label at end of switch compound statement: expected statement}}
   }
 }
 
@@ -179,7 +179,7 @@
 void pr19022_1a(int x) {
   switch(x) {
   case 1  // expected-error{{expected ':' after 'case'}} \
-  // expected-error{{label at end of compound statement: expected statement}}
+  // expected-error{{label at end of switch compound statement: expected statement}}
   }
 }
 
Index: clang/test/Parser/cxx2b-label.cpp
===
--- /dev/null
+++ clang/test/Parser/cxx2b-label.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -fsyntax-only -verify=expected,cxx2b -std=c++2b -Wpre-c++2b-compat %s
+// RUN: %clang_cc1 -fsyntax-only -verify=expected,cxx20 -std=c++20 %s
+
+void foo() {
+label1:
+int x;
+label2:
+x = 1;
+label3: label4: label5:
+} // cxx20-warning {{label at end of compound statement is a C++2b extension}} \
+ cxx2b-warning {{label at end of compound statement is incompatible with C++ standards before C++2b}}
Index: clang/test/AST/ast-dump-stmt.c
===
--- clang/test/AST/ast-dump-stmt.c
+++ clang/test/AST/ast-dump-stmt.c
@@ -161,6 +161,10 @@
   // CHECK-NEXT: ImplicitCastExpr
   // CHECK-NEXT: ImplicitCastExpr
   // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}}  'void *' lvalue Var 0x{{[^ ]*}} 'ptr' 'void *'
+
+label3:
+  // CHECK-NEXT: LabelStmt 0x{{[^ ]*}}  'label3'
+  // CHECK-NEXT: NullStmt 0x{{[^ ]*}} 
 }
 
 void TestSwitch(int i) {
Index: clang/lib/Parse/ParseStmt.cpp
===
--- clang/lib/Parse/ParseStmt.cpp
+++ clang/lib/Parse/ParseStmt.cpp
@@ -679,9 +679,12 @@
 
 /// ParseLabeledStatement - We have an identifier and a ':' after it.
 ///
+///   label:
+/// identifier ':'
+/// [GNU]   identifier ':' attributes[opt]
+///
 ///   labeled-statement:
-/// identifier ':' statement
-/// [GNU]   identifier ':' attributes[opt] statement
+/// label statement
 ///
 StmtResult Parser::ParseLabeledStatement(ParsedAttributes &Attrs,
  ParsedStmtContext StmtCtx) {
@@ -725,6 +728,14 @@
 }
   }
 
+  // The label may have no statement following it
+  if (SubStmt.isUnset() && Tok.is(tok::r_brace)) {
+Diag(Tok, getLangOpts().CPlusPlus2b
+  ? diag::warn_cxx20_compat_label_end_of_compound_statement
+  : diag::ext_label_end_of_compound_statement);
+SubStmt = Actions.ActOnNullStmt(ColonLoc);
+  }
+
   // If we've not parsed a statement yet, parse one now.
   if (!SubStmt.isInvalid() && !SubStmt.isUsable())
 SubStmt = ParseStatement(nullptr, StmtCtx);
@@ -873,8 +884,8 @@
 // another parsing error, so avoid producing extra diagnostics.
 if (ColonLoc.isValid()) {
   SourceLocation AfterColonLoc = PP.getLocForEndOfToken(ColonLoc);
-  Diag(AfterColonLoc, diag::err_label_end_of_compound_statement)
-<< FixItHint::CreateInsert

[PATCH] D133942: Clang tidy utility to generate a fix hint for a subsequent expression to the existing one

2022-09-17 Thread Nathan James via Phabricator via cfe-commits
njames93 requested changes to this revision.
njames93 added a comment.
This revision now requires changes to proceed.

There's some merit in this, like wrapping the previous statement in braces.. 
However, clang-tidy should not focus on the formatting aspect as we have 
clang-format built in to address formatting decisions, and any special 
formatting you do in here would likely be undone by the users configuration.
It would also be nice to add in some unittests to demonstrate that braces are 
currently inserted etc.

How does this handle pathological cases like the statement being the 
iteration-expression of a for loop, or a init-statement in an 
if/switch/range-for loop. The documentation looks like it tries to explain 
that, but it doesn't do a great job IMHO.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133942

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


[PATCH] D134105: [Docs] Add a link that refers to C++ standard modules in Clang modules doc

2022-09-17 Thread Jun Zhang via Phabricator via cfe-commits
junaire created this revision.
junaire added a reviewer: ChuanqiXu.
Herald added a project: All.
junaire requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Currently there're two pages that both talk about "Modules" in clang, but
they're different. The one that describes C++ standard modules explicitly
spells out the difference but the other one which targeting Clang modules
doesn't.

This patch adds a link that refers to the C++ standard modules
one in Clang modules doc, as you usually got the later page when
googling. I believe this will make newcomers less confused.

Signed-off-by: Jun Zhang 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D134105

Files:
  clang/docs/Modules.rst


Index: clang/docs/Modules.rst
===
--- clang/docs/Modules.rst
+++ clang/docs/Modules.rst
@@ -7,6 +7,8 @@
 
 Introduction
 
+This pages mainly talks about Clang Modules, please refer to .. 
_StandardCPlusPlusModules: StandardCPlusPlusModules.html if you're looking for 
standard C++ modules.
+
 Most software is built using a number of software libraries, including 
libraries supplied by the platform, internal libraries built as part of the 
software itself to provide structure, and third-party libraries. For each 
library, one needs to access both its interface (API) and its implementation. 
In the C family of languages, the interface to a library is accessed by 
including the appropriate header files(s):
 
 .. code-block:: c


Index: clang/docs/Modules.rst
===
--- clang/docs/Modules.rst
+++ clang/docs/Modules.rst
@@ -7,6 +7,8 @@
 
 Introduction
 
+This pages mainly talks about Clang Modules, please refer to .. _StandardCPlusPlusModules: StandardCPlusPlusModules.html if you're looking for standard C++ modules.
+
 Most software is built using a number of software libraries, including libraries supplied by the platform, internal libraries built as part of the software itself to provide structure, and third-party libraries. For each library, one needs to access both its interface (API) and its implementation. In the C family of languages, the interface to a library is accessed by including the appropriate header files(s):
 
 .. code-block:: c
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D133801: Extraction of a matcher for an unused value from an expression from the bugprone-unused-return-value check

2022-09-17 Thread Nathan James via Phabricator via cfe-commits
njames93 added a comment.

I feel like this matcher could do with some unit testing. I'd say create a test 
file in `clang-tools-extra/unittests/clang-tidy/MatchersTest.cpp`




Comment at: clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp:145
 
   auto UnusedInCompoundStmt =
   compoundStmt(forEach(MatchedCallExpr),

Can all these be removed now?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133801

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


[PATCH] D133982: [clangd] Improve inlay hints of things expanded from macros

2022-09-17 Thread Nathan Ridge via Phabricator via cfe-commits
nridge accepted this revision.
nridge added a comment.
This revision is now accepted and ready to land.

Thanks for fixing!




Comment at: clang-tools-extra/clangd/InlayHints.cpp:281
 
-  void addReturnTypeHint(FunctionDecl *D, SourceLocation Loc) {
+  void addReturnTypeHint(FunctionDecl *D, SourceRange Range) {
 auto *AT = D->getReturnType()->getContainedAutoType();

Is this change related to the fix?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133982

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


[PATCH] D132913: [HLSL] Preserve vec3 for HLSL.

2022-09-17 Thread Xiang Li via Phabricator via cfe-commits
python3kgae marked an inline comment as done.
python3kgae added inline comments.



Comment at: clang/test/CodeGenHLSL/float3.hlsl:1
+// RUN: %clang --driver-mode=dxc -Tlib_6_7 -fcgl  -Fo - %s | FileCheck %s
+

tahonermann wrote:
> Does this need to use driver mode? That is odd for a code gen test.
Nice catch.
Fixed with 
https://github.com/llvm/llvm-project/commit/8b2f8b309885e872ad98af381ee5459716955877

Thanks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132913

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


[clang] 8b2f8b3 - [NFC} update CodeGenHLSL tests to use cc1 instead of driver-mode

2022-09-17 Thread Xiang Li via cfe-commits

Author: Xiang Li
Date: 2022-09-17T00:11:44-07:00
New Revision: 8b2f8b309885e872ad98af381ee5459716955877

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

LOG: [NFC} update CodeGenHLSL tests to use cc1 instead of driver-mode

Added: 


Modified: 
clang/test/CodeGenHLSL/basic_types.hlsl
clang/test/CodeGenHLSL/entry.hlsl
clang/test/CodeGenHLSL/float3.hlsl
clang/test/CodeGenHLSL/half.hlsl
clang/test/CodeGenHLSL/shader_type_attr.hlsl

Removed: 




diff  --git a/clang/test/CodeGenHLSL/basic_types.hlsl 
b/clang/test/CodeGenHLSL/basic_types.hlsl
index f76e134743e54..d26d94910c2d8 100644
--- a/clang/test/CodeGenHLSL/basic_types.hlsl
+++ b/clang/test/CodeGenHLSL/basic_types.hlsl
@@ -1,10 +1,19 @@
-// RUN: %clang_dxc  -Tlib_6_7 -fcgl -Fo - %s | FileCheck %s
+// RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \
+// RUN:   dxil-pc-shadermodel6.3-library %s -fnative-half-type \
+// RUN:   -emit-llvm -disable-llvm-passes -o - | FileCheck %s
 
-// FIXME: check 16bit types once enable-16bit-types is ready.
 
+// CHECK:"?uint16_t_Val@@3GA" = global i16 0, align 2
+// CHECK:"?int16_t_Val@@3FA" = global i16 0, align 2
 // CHECK:"?uint_Val@@3IA" = global i32 0, align 4
 // CHECK:"?uint64_t_Val@@3KA" = global i64 0, align 8
 // CHECK:"?int64_t_Val@@3JA" = global i64 0, align 8
+// CHECK:"?int16_t2_Val@@3T?$__vector@F$01@__clang@@A" = global <2 x i16> 
zeroinitializer, align 4
+// CHECK:"?int16_t3_Val@@3T?$__vector@F$02@__clang@@A" = global <3 x i16> 
zeroinitializer, align 8
+// CHECK:"?int16_t4_Val@@3T?$__vector@F$03@__clang@@A" = global <4 x i16> 
zeroinitializer, align 8
+// CHECK:"?uint16_t2_Val@@3T?$__vector@G$01@__clang@@A" = global <2 x i16> 
zeroinitializer, align 4
+// CHECK:"?uint16_t3_Val@@3T?$__vector@G$02@__clang@@A" = global <3 x i16> 
zeroinitializer, align 8
+// CHECK:"?uint16_t4_Val@@3T?$__vector@G$03@__clang@@A" = global <4 x i16> 
zeroinitializer, align 8
 // CHECK:"?int2_Val@@3T?$__vector@H$01@__clang@@A" = global <2 x i32> 
zeroinitializer, align 8
 // CHECK:"?int3_Val@@3T?$__vector@H$02@__clang@@A" = global <3 x i32> 
zeroinitializer, align 16
 // CHECK:"?int4_Val@@3T?$__vector@H$03@__clang@@A" = global <4 x i32> 
zeroinitializer, align 16
@@ -17,6 +26,9 @@
 // CHECK:"?uint64_t2_Val@@3T?$__vector@K$01@__clang@@A" = global <2 x i64> 
zeroinitializer, align 16
 // CHECK:"?uint64_t3_Val@@3T?$__vector@K$02@__clang@@A" = global <3 x i64> 
zeroinitializer, align 32
 // CHECK:"?uint64_t4_Val@@3T?$__vector@K$03@__clang@@A" = global <4 x i64> 
zeroinitializer, align 32
+// CHECK:"?half2_Val@@3T?$__vector@$f16@$01@__clang@@A" = global <2 x half> 
zeroinitializer, align 4
+// CHECK:"?half3_Val@@3T?$__vector@$f16@$02@__clang@@A" = global <3 x half> 
zeroinitializer, align 8
+// CHECK:"?half4_Val@@3T?$__vector@$f16@$03@__clang@@A" = global <4 x half> 
zeroinitializer, align 8
 // CHECK:"?float2_Val@@3T?$__vector@M$01@__clang@@A" = global <2 x float> 
zeroinitializer, align 8
 // CHECK:"?float3_Val@@3T?$__vector@M$02@__clang@@A" = global <3 x float> 
zeroinitializer, align 16
 // CHECK:"?float4_Val@@3T?$__vector@M$03@__clang@@A" = global <4 x float> 
zeroinitializer, align 16

diff  --git a/clang/test/CodeGenHLSL/entry.hlsl 
b/clang/test/CodeGenHLSL/entry.hlsl
index 1a1a507358246..9757a2be582fb 100644
--- a/clang/test/CodeGenHLSL/entry.hlsl
+++ b/clang/test/CodeGenHLSL/entry.hlsl
@@ -1,4 +1,6 @@
-// RUN: %clang --driver-mode=dxc -Tcs_6_1 -Efoo -fcgl  -Fo - %s | FileCheck %s
+// RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \
+// RUN:   dxil-pc-shadermodel6.3-compute %s -hlsl-entry foo \
+// RUN:   -emit-llvm -disable-llvm-passes -o - | FileCheck %s
 
 // Make sure not mangle entry.
 // CHECK:define void @foo()

diff  --git a/clang/test/CodeGenHLSL/float3.hlsl 
b/clang/test/CodeGenHLSL/float3.hlsl
index 4adda8dee1214..63379349d9bd7 100644
--- a/clang/test/CodeGenHLSL/float3.hlsl
+++ b/clang/test/CodeGenHLSL/float3.hlsl
@@ -1,4 +1,6 @@
-// RUN: %clang --driver-mode=dxc -Tlib_6_7 -fcgl  -Fo - %s | FileCheck %s
+// RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \
+// RUN:   dxil-pc-shadermodel6.3-library %s -fnative-half-type \
+// RUN:   -emit-llvm -disable-llvm-passes -o - | FileCheck %s
 
 // Make sure float3 is not changed into float4.
 // CHECK:<3 x float> @"?foo@@YAT?$__vector@M$02@__clang@@T12@@Z"(<3 x float> 
noundef %[[PARAM:[0-9a-zA-Z]+]])

diff  --git a/clang/test/CodeGenHLSL/half.hlsl 
b/clang/test/CodeGenHLSL/half.hlsl
index 90ef77f4bec54..e83a6fc715b8a 100644
--- a/clang/test/CodeGenHLSL/half.hlsl
+++ b/clang/test/CodeGenHLSL/half.hlsl
@@ -1,5 +1,11 @@
-// RUN: %clang_dxc -Tlib_6_7 -fcgl  -Fo - %s | FileCheck %s 
--check-prefix=FLOAT
-// RUN: %clang_dxc -Tlib_6_7 -enable-16bit-types -fcgl  -Fo 

[PATCH] D122078: [clang-tidy] Ignore concepts in `misc-redundant-expression`

2022-09-17 Thread Evgeny Shulgin via Phabricator via cfe-commits
Izaron updated this revision to Diff 460976.
Izaron added a comment.

Created redundant-expression-cxx20.cpp


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122078

Files:
  clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/test/clang-tidy/checkers/misc/redundant-expression-cxx20.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/misc/redundant-expression-cxx20.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/misc/redundant-expression-cxx20.cpp
@@ -0,0 +1,11 @@
+// RUN: %check_clang_tidy %s misc-redundant-expression -std=c++20 %t -- -- -fno-delayed-template-parsing
+
+namespace concepts {
+// redundant expressions inside concepts make sense, ignore them
+template 
+concept TestConcept = requires(I i) {
+  {i - i};
+  {i && i};
+  {i ? i : i};
+};
+} // namespace concepts
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -149,6 +149,12 @@
   copy assignment operators with nonstandard return types. The check is restricted to
   c++11-or-later.
 
+- Improved :doc:`misc-redundant-expression `
+  check.
+
+  The check now skips concept definitions since redundant expressions still make sense
+  inside them.
+
 Removed checks
 ^^
 
Index: clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp
===
--- clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp
+++ clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp
@@ -10,6 +10,7 @@
 #include "../utils/Matchers.h"
 #include "../utils/OptionsUtils.h"
 #include "clang/AST/ASTContext.h"
+#include "clang/AST/ExprConcepts.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/Basic/LLVM.h"
 #include "clang/Basic/SourceLocation.h"
@@ -440,6 +441,8 @@
   return Node.isIntegerConstantExpr(Finder->getASTContext());
 }
 
+AST_MATCHER(Expr, isRequiresExpr) { return isa(Node); }
+
 AST_MATCHER(BinaryOperator, operandsAreEquivalent) {
   return areEquivalentExpr(Node.getLHS(), Node.getRHS());
 }
@@ -858,6 +861,7 @@
 
   const auto BannedIntegerLiteral =
   integerLiteral(expandedByMacro(KnownBannedMacroNames));
+  const auto BannedAncestor = expr(isRequiresExpr());
 
   // Binary with equivalent operands, like (X != 2 && X != 2).
   Finder->addMatcher(
@@ -873,7 +877,8 @@
unless(hasType(realFloatingPointType())),
unless(hasEitherOperand(hasType(realFloatingPointType(,
unless(hasLHS(AnyLiteralExpr)),
-   unless(hasDescendant(BannedIntegerLiteral)))
+   unless(hasDescendant(BannedIntegerLiteral)),
+   unless(hasAncestor(BannedAncestor)))
.bind("binary")),
   this);
 
@@ -886,7 +891,8 @@
  unless(isInTemplateInstantiation()),
  unless(binaryOperatorIsInMacro()),
  // TODO: if the banned macros are themselves duplicated
- unless(hasDescendant(BannedIntegerLiteral)))
+ unless(hasDescendant(BannedIntegerLiteral)),
+ unless(hasAncestor(BannedAncestor)))
   .bind("nested-duplicates"),
   this);
 
@@ -896,7 +902,8 @@
conditionalOperator(expressionsAreEquivalent(),
// Filter noisy false positives.
unless(conditionalOperatorIsInMacro()),
-   unless(isInTemplateInstantiation()))
+   unless(isInTemplateInstantiation()),
+   unless(hasAncestor(BannedAncestor)))
.bind("cond")),
   this);
 
@@ -909,7 +916,8 @@
 ">=", "&&", "||", "="),
parametersAreEquivalent(),
// Filter noisy false positives.
-   unless(isMacro()), unless(isInTemplateInstantiation()))
+   unless(isMacro()), unless(isInTemplateInstantiation()),
+   unless(hasAncestor(BannedAncestor)))
.bind("call")),
   this);
 
@@ -919,7 +927,8 @@
   hasAnyOverloadedOperatorName("|", "&", "||", "&&", "^"),
   nestedParametersAreEquivalent(), argumentCountIs(2),
   // Filter noisy false positives.
-  unless(isMacro()), unless(isInTemplateInstantiation()))
+  unless(isMacro()), unless(isInTemplateInstantiation()),
+  unless(hasAncestor(BannedAncestor)))
   .bind("nested-duplicates"),
   this);
 
@@ -936,7 +945,8 @@

[PATCH] D134057: [clang][Interp] Start implementing record types

2022-09-17 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 460975.

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

https://reviews.llvm.org/D134057

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/ByteCodeExprGen.h
  clang/lib/AST/Interp/ByteCodeStmtGen.cpp
  clang/lib/AST/Interp/Interp.h
  clang/lib/AST/Interp/Record.h
  clang/test/AST/Interp/records.cpp
  clang/test/AST/Interp/references.cpp

Index: clang/test/AST/Interp/references.cpp
===
--- clang/test/AST/Interp/references.cpp
+++ clang/test/AST/Interp/references.cpp
@@ -83,9 +83,9 @@
   S s{1, 2};
 
   int &j = s.i;
-  j += 10;
+  j = j + 10;
 
   return j;
 }
 // FIXME: Should be accepted.
-static_assert(RefToMemberExpr() == 11, ""); // expected-error {{not an integral constant expression}}
+static_assert(RefToMemberExpr() == 11, "");
Index: clang/test/AST/Interp/records.cpp
===
--- /dev/null
+++ clang/test/AST/Interp/records.cpp
@@ -0,0 +1,54 @@
+// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -verify %s
+// RUN: %clang_cc1 -verify=ref %s
+
+// expected-no-diagnostics
+// ref-no-diagnostics
+
+struct Ints {
+  int a = 20;
+  int b = 30;
+  bool c = true;
+
+  static const int five = 5;
+  static constexpr int getFive() {
+return five;
+  }
+
+  constexpr int getTen() const {
+return 10;
+  }
+};
+
+static_assert(Ints::getFive() == 5, "");
+
+constexpr Ints ints;
+static_assert(ints.a == 20, "");
+static_assert(ints.b == 30, "");
+static_assert(ints.c, "");
+static_assert(ints.getTen() == 10, "");
+
+constexpr Ints ints2{-20, -30, false};
+static_assert(ints2.a == -20, "");
+static_assert(ints2.b == -30, "");
+static_assert(!ints2.c, "");
+
+
+struct Ints2 {
+  int a = 10;
+  int b;
+};
+// FIXME: Broken in the new constant interpreter.
+//   Should be rejected, but without asan errors.
+//constexpr Ints2 ints2;
+
+class C {
+  public:
+int a;
+int b;
+
+  constexpr C() : a(100), b(200) {}
+};
+
+constexpr C c;
+static_assert(c.a == 100, "");
+static_assert(c.b == 200, "");
Index: clang/lib/AST/Interp/Record.h
===
--- clang/lib/AST/Interp/Record.h
+++ clang/lib/AST/Interp/Record.h
@@ -67,6 +67,7 @@
   }
 
   unsigned getNumFields() const { return Fields.size(); }
+  const Field *getField(unsigned I) const { return &Fields[I]; }
   Field *getField(unsigned I) { return &Fields[I]; }
 
   using const_base_iter = BaseList::const_iterator;
Index: clang/lib/AST/Interp/Interp.h
===
--- clang/lib/AST/Interp/Interp.h
+++ clang/lib/AST/Interp/Interp.h
@@ -492,6 +492,9 @@
   return true;
 }
 
+/// 1) Pops the value from the stack
+/// 2) Pops a pointer from the stack
+/// 3) Writes the value to field I of the pointer
 template ::T>
 bool InitField(InterpState &S, CodePtr OpPC, uint32_t I) {
   const T &Value = S.Stk.pop();
Index: clang/lib/AST/Interp/ByteCodeStmtGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeStmtGen.cpp
+++ clang/lib/AST/Interp/ByteCodeStmtGen.cpp
@@ -94,10 +94,6 @@
   // Classify the return type.
   ReturnType = this->classify(F->getReturnType());
 
-  // Set up fields and context if a constructor.
-  if (auto *MD = dyn_cast(F))
-return this->bail(MD);
-
   if (auto *Body = F->getBody())
 if (!visitStmt(Body))
   return false;
Index: clang/lib/AST/Interp/ByteCodeExprGen.h
===
--- clang/lib/AST/Interp/ByteCodeExprGen.h
+++ clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -71,6 +71,7 @@
   bool VisitBinaryOperator(const BinaryOperator *E);
   bool VisitCXXDefaultArgExpr(const CXXDefaultArgExpr *E);
   bool VisitCallExpr(const CallExpr *E);
+  bool VisitCXXDefaultInitExpr(const CXXDefaultInitExpr *E);
   bool VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *E);
   bool VisitCXXNullPtrLiteralExpr(const CXXNullPtrLiteralExpr *E);
   bool VisitUnaryOperator(const UnaryOperator *E);
@@ -81,6 +82,7 @@
   bool VisitInitListExpr(const InitListExpr *E);
   bool VisitConstantExpr(const ConstantExpr *E);
   bool VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *E);
+  bool VisitMemberExpr(const MemberExpr *E);
 
 protected:
   bool visitExpr(const Expr *E) override;
@@ -138,6 +140,8 @@
   bool visitInitializer(const Expr *E);
   /// Compiles an array initializer.
   bool visitArrayInitializer(const Expr *Initializer);
+  /// Compiles a record initializer.
+  bool visitRecordInitializer(const Expr *Initializer);
 
   /// Visits an expression and converts it to a boolean.
   bool visitBool(const Expr *E);
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -303

[PATCH] D133934: [clang][Interp] Handle sizeof() expressions

2022-09-17 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder marked an inline comment as done.
tbaeder added a comment.

@erichkeane Anything else still missing here?


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

https://reviews.llvm.org/D133934

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