[PATCH] D89198: [X86] Define __LAHF_SAHF__ if feature 'sahf' is set

2020-10-10 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: clang/lib/Basic/Targets/X86.cpp:564
+  if (HasLAHFSAHF)
+Builder.defineMacro("__LAHF_SAHF__");
   if (HasLZCNT)

craig.topper wrote:
> MaskRay wrote:
> > craig.topper wrote:
> > > craig.topper wrote:
> > > > It looks like gcc may define this always in 32-bit mode?
> > > More confusingly, they define it in 32-bit mode unless -mno-sahf is on 
> > > the command line. Despite 32-bit mode always having LAHF/SAHF 
> > > instructions.
> > I think this means we fail to set sahf for all 32-bit CPUs. GCC 
> > gcc/config/i386/i386-options.c sets OPTION_MASK_ISA_SAHF on all 32-bit CPUs 
> > unless -mno-sahf.
> > 
> > According to 
> > https://git.noc.ruhr-uni-bochum.de/kostea7x/ghidra/-/commit/239106a356ef875a64cc2cfd3fd71b415406?view=parallel
> > some pre-2005 Intel and AMD 64-bit CPUs had problems so 'sahf' is disabled 
> > for some CPUs.
> > 
> The X86Subtarget and X86.td file calls "sahf" as HasLAHFSAHF64. And contains 
> we have this predicate for codegen uses.
> 
> {code}
>   bool hasLAHFSAHF() const { return HasLAHFSAHF64 || !is64Bit(); }
> {code}
> 
> 
> Does -mno-sahf prevent gcc from using LAHF/SAHF in 32-bit mode?
From `gcc/config/i386/i386-options.c sets OPTION_MASK_ISA_SAHF`, I think so, 
but there isn't any codegen test... (like many other components of GCC)

This discrepancy is not a big problem so let's always define it for 32-bit mode 
for now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89198

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


[PATCH] D89198: [X86] Define __LAHF_SAHF__ if feature 'sahf' is set

2020-10-10 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 297441.
MaskRay edited the summary of this revision.
MaskRay added a comment.

Always define __LAHF_SAHF__ in 32-bit mode


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89198

Files:
  clang/lib/Basic/Targets/X86.cpp
  clang/test/Preprocessor/predefined-arch-macros.c

Index: clang/test/Preprocessor/predefined-arch-macros.c
===
--- clang/test/Preprocessor/predefined-arch-macros.c
+++ clang/test/Preprocessor/predefined-arch-macros.c
@@ -3,6 +3,7 @@
 // RUN: %clang -march=i386 -m32 -E -dM %s -o - 2>&1 \
 // RUN: -target i386-unknown-linux \
 // RUN:   | FileCheck -match-full-lines %s -check-prefix=CHECK_I386_M32
+// CHECK_I386_M32: #define __LAHF_SAHF__ 1
 // CHECK_I386_M32: #define __i386 1
 // CHECK_I386_M32: #define __i386__ 1
 // CHECK_I386_M32: #define __tune_i386__ 1
@@ -541,6 +542,7 @@
 // CHECK_CORE_AVX2_M32: #define __F16C__ 1
 // CHECK_CORE_AVX2_M32: #define __FMA__ 1
 // CHECK_CORE_AVX2_M32: #define __INVPCID__ 1
+// CHECK_CORE_AVX2_M32: #define __LAHF_SAHF__ 1
 // CHECK_CORE_AVX2_M32: #define __LZCNT__ 1
 // CHECK_CORE_AVX2_M32: #define __MMX__ 1
 // CHECK_CORE_AVX2_M32: #define __MOVBE__ 1
@@ -572,6 +574,7 @@
 // CHECK_CORE_AVX2_M64: #define __F16C__ 1
 // CHECK_CORE_AVX2_M64: #define __FMA__ 1
 // CHECK_CORE_AVX2_M64: #define __INVPCID__ 1
+// CHECK_CORE_AVX2_M64: #define __LAHF_SAHF__ 1
 // CHECK_CORE_AVX2_M64: #define __LZCNT__ 1
 // CHECK_CORE_AVX2_M64: #define __MMX__ 1
 // CHECK_CORE_AVX2_M64: #define __MOVBE__ 1
@@ -607,6 +610,7 @@
 // CHECK_BROADWELL_M32: #define __F16C__ 1
 // CHECK_BROADWELL_M32: #define __FMA__ 1
 // CHECK_BROADWELL_M32: #define __INVPCID__ 1
+// CHECK_BROADWELL_M32: #define __LAHF_SAHF__ 1
 // CHECK_BROADWELL_M32: #define __LZCNT__ 1
 // CHECK_BROADWELL_M32: #define __MMX__ 1
 // CHECK_BROADWELL_M32: #define __MOVBE__ 1
@@ -641,6 +645,7 @@
 // CHECK_BROADWELL_M64: #define __F16C__ 1
 // CHECK_BROADWELL_M64: #define __FMA__ 1
 // CHECK_BROADWELL_M64: #define __INVPCID__ 1
+// CHECK_BROADWELL_M64: #define __LAHF_SAHF__ 1
 // CHECK_BROADWELL_M64: #define __LZCNT__ 1
 // CHECK_BROADWELL_M64: #define __MMX__ 1
 // CHECK_BROADWELL_M64: #define __MOVBE__ 1
@@ -2515,6 +2520,7 @@
 // RUN:   | FileCheck -match-full-lines %s -check-prefix=CHECK_AMDFAM10_M32
 // CHECK_AMDFAM10_M32: #define __3dNOW_A__ 1
 // CHECK_AMDFAM10_M32: #define __3dNOW__ 1
+// CHECK_AMDFAM10_M32: #define __LAHF_SAHF__ 1
 // CHECK_AMDFAM10_M32: #define __LZCNT__ 1
 // CHECK_AMDFAM10_M32: #define __MMX__ 1
 // CHECK_AMDFAM10_M32: #define __POPCNT__ 1
@@ -2538,6 +2544,7 @@
 // CHECK_AMDFAM10_M64: #define __3dNOW_A__ 1
 // CHECK_AMDFAM10_M64: #define __3dNOW__ 1
 // CHECK_AMDFAM10_M64: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_16 1
+// CHECK_AMDFAM10_M64: #define __LAHF_SAHF__ 1
 // CHECK_AMDFAM10_M64: #define __LZCNT__ 1
 // CHECK_AMDFAM10_M64: #define __MMX__ 1
 // CHECK_AMDFAM10_M64: #define __POPCNT__ 1
@@ -2562,6 +2569,7 @@
 // RUN:   | FileCheck -match-full-lines %s -check-prefix=CHECK_BTVER1_M32
 // CHECK_BTVER1_M32-NOT: #define __3dNOW_A__ 1
 // CHECK_BTVER1_M32-NOT: #define __3dNOW__ 1
+// CHECK_BTVER1_M32: #define __LAHF_SAHF__ 1
 // CHECK_BTVER1_M32: #define __LZCNT__ 1
 // CHECK_BTVER1_M32: #define __MMX__ 1
 // CHECK_BTVER1_M32: #define __POPCNT__ 1
@@ -2584,6 +2592,7 @@
 // RUN:   | FileCheck -match-full-lines %s -check-prefix=CHECK_BTVER1_M64
 // CHECK_BTVER1_M64-NOT: #define __3dNOW_A__ 1
 // CHECK_BTVER1_M64-NOT: #define __3dNOW__ 1
+// CHECK_BTVER1_M64: #define __LAHF_SAHF__ 1
 // CHECK_BTVER1_M64: #define __LZCNT__ 1
 // CHECK_BTVER1_M64: #define __MMX__ 1
 // CHECK_BTVER1_M64: #define __POPCNT__ 1
@@ -3023,6 +3032,7 @@
 // CHECK_ZNVER1_M64-NOT: #define __FMA4__ 1
 // CHECK_ZNVER1_M64: #define __FMA__ 1
 // CHECK_ZNVER1_M64: #define __FSGSBASE__ 1
+// CHECK_ZNVER1_M64: #define __LAHF_SAHF__ 1
 // CHECK_ZNVER1_M64: #define __LZCNT__ 1
 // CHECK_ZNVER1_M64: #define __MMX__ 1
 // CHECK_ZNVER1_M64: #define __MOVBE__ 1
@@ -3073,6 +3083,7 @@
 // CHECK_ZNVER2_M32-NOT: #define __FMA4__ 1
 // CHECK_ZNVER2_M32: #define __FMA__ 1
 // CHECK_ZNVER2_M32: #define __FSGSBASE__ 1
+// CHECK_ZNVER2_M32: #define __LAHF_SAHF__ 1
 // CHECK_ZNVER2_M32: #define __LZCNT__ 1
 // CHECK_ZNVER2_M32: #define __MMX__ 1
 // CHECK_ZNVER2_M32: #define __PCLMUL__ 1
@@ -3122,6 +3133,7 @@
 // CHECK_ZNVER2_M64-NOT: #define __FMA4__ 1
 // CHECK_ZNVER2_M64: #define __FMA__ 1
 // CHECK_ZNVER2_M64: #define __FSGSBASE__ 1
+// CHECK_ZNVER2_M64: #define __LAHF_SAHF__ 1
 // CHECK_ZNVER2_M64: #define __LZCNT__ 1
 // CHECK_ZNVER2_M64: #define __MMX__ 1
 // CHECK_ZNVER2_M64: #define __PCLMUL__ 1
Index: clang/lib/Basic/Targets/X86.cpp
===
--- clang/lib/Basic/Targets/X86.cpp
+++ clang/lib/Basic/Targets/X86.cpp
@@ -560,6 +560,11 @@
   if (HasVPCLMULQDQ)
 

[PATCH] D86671: [clang-tidy] Add new case type to check variables with Hungarian notation

2020-10-10 Thread Douglas Chen via Phabricator via cfe-commits
dougpuob added inline comments.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/readability-identifier-naming-hungarian-notation.cpp:25
+// RUN: {key: readability-identifier-naming.FunctionCase   , value: 
CamelCase },   \
+// RUN: {key: readability-identifier-naming.ClassCase  , value: 
szHungarianNotation }, \
+// RUN: {key: readability-identifier-naming.TypedefCase, value: 
szHungarianNotation }, \

aaron.ballman wrote:
> dougpuob wrote:
> > njames93 wrote:
> > > Class names shouldn't use hungarian notation.
> > OK~ I have classified CheckOptions, and all test cases one by one in the 
> > next diff.
> > 
> > ```
> > // RUN:   -config='{ CheckOptions: [ \
> > // RUN: { key: readability-identifier-naming.ClassMemberCase
> >   , value: szHungarianNotation }, \
> > // RUN: { key: readability-identifier-naming.ConstantCase   
> >   , value: szHungarianNotation }, \
> > // RUN: { key: readability-identifier-naming.ConstantMemberCase 
> >   , value: szHungarianNotation }, \
> > // RUN: { key: readability-identifier-naming.ConstantParameterCase  
> >   , value: szHungarianNotation }, \
> > // RUN: { key: 
> > readability-identifier-naming.ConstantPointerParameterCase , value: 
> > szHungarianNotation }, \
> > // RUN: { key: readability-identifier-naming.ConstexprVariableCase  
> >   , value: szHungarianNotation }, \
> > // RUN: { key: readability-identifier-naming.GlobalConstantCase 
> >   , value: szHungarianNotation }, \
> > // RUN: { key: readability-identifier-naming.GlobalConstantPointerCase  
> >   , value: szHungarianNotation }, \
> > // RUN: { key: readability-identifier-naming.GlobalVariableCase 
> >   , value: szHungarianNotation }, \
> > // RUN: { key: readability-identifier-naming.LocalConstantCase  
> >   , value: szHungarianNotation }, \
> > // RUN: { key: readability-identifier-naming.LocalConstantPointerCase   
> >   , value: szHungarianNotation }, \
> > // RUN: { key: readability-identifier-naming.LocalPointerCase   
> >   , value: szHungarianNotation }, \
> > // RUN: { key: readability-identifier-naming.LocalVariableCase  
> >   , value: szHungarianNotation }, \
> > // RUN: { key: readability-identifier-naming.MemberCase 
> >   , value: szHungarianNotation }, \
> > // RUN: { key: readability-identifier-naming.ParameterCase  
> >   , value: szHungarianNotation }, \
> > // RUN: { key: readability-identifier-naming.PointerParameterCase   
> >   , value: szHungarianNotation }, \
> > // RUN: { key: readability-identifier-naming.PrivateMemberCase  
> >   , value: szHungarianNotation }, \
> > // RUN: { key: readability-identifier-naming.StaticConstantCase 
> >   , value: szHungarianNotation }, \
> > // RUN: { key: readability-identifier-naming.StaticVariableCase 
> >   , value: szHungarianNotation }, \
> > // RUN: { key: readability-identifier-naming.StructCase 
> >   , value: szHungarianNotation }, \
> > // RUN: { key: readability-identifier-naming.UnionCase  
> >   , value: szHungarianNotation }, \
> > // RUN: { key: readability-identifier-naming.VariableCase   
> >   , value: szHungarianNotation }  \
> > // RUN:   ]}'
> > ```
> > Class names shouldn't use hungarian notation.
> 
> That may be debatable as I've definitely seen `C` used as a prefix for class 
> names and `I` used as a prefix for pure virtual class names (interfaces). 
> Doing a quick search on Google brings up evidence that this isn't uncommon.
Agree both of you because I saw them in different projects. I will add this 
feature as an option (default is off, user can enable it in .clang-tidy).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86671

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


[PATCH] D89198: [X86] Define __LAHF_SAHF__ if feature 'sahf' is set

2020-10-10 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added inline comments.



Comment at: clang/lib/Basic/Targets/X86.cpp:564
+  if (HasLAHFSAHF)
+Builder.defineMacro("__LAHF_SAHF__");
   if (HasLZCNT)

MaskRay wrote:
> craig.topper wrote:
> > craig.topper wrote:
> > > It looks like gcc may define this always in 32-bit mode?
> > More confusingly, they define it in 32-bit mode unless -mno-sahf is on the 
> > command line. Despite 32-bit mode always having LAHF/SAHF instructions.
> I think this means we fail to set sahf for all 32-bit CPUs. GCC 
> gcc/config/i386/i386-options.c sets OPTION_MASK_ISA_SAHF on all 32-bit CPUs 
> unless -mno-sahf.
> 
> According to 
> https://git.noc.ruhr-uni-bochum.de/kostea7x/ghidra/-/commit/239106a356ef875a64cc2cfd3fd71b415406?view=parallel
> some pre-2005 Intel and AMD 64-bit CPUs had problems so 'sahf' is disabled 
> for some CPUs.
> 
The X86Subtarget and X86.td file calls "sahf" as HasLAHFSAHF64. And contains we 
have this predicate for codegen uses.

{code}
  bool hasLAHFSAHF() const { return HasLAHFSAHF64 || !is64Bit(); }
{code}


Does -mno-sahf prevent gcc from using LAHF/SAHF in 32-bit mode?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89198

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


[PATCH] D89198: [X86] Define __LAHF_SAHF__ if feature 'sahf' is set

2020-10-10 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: clang/lib/Basic/Targets/X86.cpp:564
+  if (HasLAHFSAHF)
+Builder.defineMacro("__LAHF_SAHF__");
   if (HasLZCNT)

craig.topper wrote:
> craig.topper wrote:
> > It looks like gcc may define this always in 32-bit mode?
> More confusingly, they define it in 32-bit mode unless -mno-sahf is on the 
> command line. Despite 32-bit mode always having LAHF/SAHF instructions.
I think this means we fail to set sahf for all 32-bit CPUs. GCC 
gcc/config/i386/i386-options.c sets OPTION_MASK_ISA_SAHF on all 32-bit CPUs 
unless -mno-sahf.

According to 
https://git.noc.ruhr-uni-bochum.de/kostea7x/ghidra/-/commit/239106a356ef875a64cc2cfd3fd71b415406?view=parallel
some pre-2005 Intel and AMD 64-bit CPUs had problems so 'sahf' is disabled for 
some CPUs.



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89198

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


[PATCH] D89065: [clang] Tweaked fixit for static assert with no message

2020-10-10 Thread Nathan James via Phabricator via cfe-commits
njames93 updated this revision to Diff 297434.
njames93 added a comment.

FixIt now properly generated


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89065

Files:
  clang/lib/Parse/ParseDeclCXX.cpp


Index: clang/lib/Parse/ParseDeclCXX.cpp
===
--- clang/lib/Parse/ParseDeclCXX.cpp
+++ clang/lib/Parse/ParseDeclCXX.cpp
@@ -858,6 +858,16 @@
DeclFromDeclSpec);
 }
 
+static FixItHint getStaticAssertNoMessageFixIt(const Expr *AssertExpr,
+   SourceLocation EndExprLoc) {
+  if (const auto *BO = llvm::dyn_cast_or_null(AssertExpr)) {
+if (BO->getOpcode() == BO_LAnd &&
+llvm::isa(BO->getRHS()->IgnoreImpCasts()))
+  return FixItHint::CreateReplacement(BO->getOperatorLoc(), ",");
+  }
+  return FixItHint::CreateInsertion(EndExprLoc, ", \"\"");
+}
+
 /// ParseStaticAssertDeclaration - Parse C++0x or C11 
static_assert-declaration.
 ///
 /// [C++0x] static_assert-declaration:
@@ -894,12 +904,11 @@
 
   ExprResult AssertMessage;
   if (Tok.is(tok::r_paren)) {
-Diag(Tok, getLangOpts().CPlusPlus17
-  ? diag::warn_cxx14_compat_static_assert_no_message
-  : diag::ext_static_assert_no_message)
-  << (getLangOpts().CPlusPlus17
-  ? FixItHint()
-  : FixItHint::CreateInsertion(Tok.getLocation(), ", \"\""));
+if (getLangOpts().CPlusPlus17)
+  Diag(Tok, diag::warn_cxx14_compat_static_assert_no_message);
+else
+  Diag(Tok, diag::ext_static_assert_no_message)
+  << getStaticAssertNoMessageFixIt(AssertExpr.get(), 
Tok.getLocation());
   } else {
 if (ExpectAndConsume(tok::comma)) {
   SkipUntil(tok::semi);


Index: clang/lib/Parse/ParseDeclCXX.cpp
===
--- clang/lib/Parse/ParseDeclCXX.cpp
+++ clang/lib/Parse/ParseDeclCXX.cpp
@@ -858,6 +858,16 @@
DeclFromDeclSpec);
 }
 
+static FixItHint getStaticAssertNoMessageFixIt(const Expr *AssertExpr,
+   SourceLocation EndExprLoc) {
+  if (const auto *BO = llvm::dyn_cast_or_null(AssertExpr)) {
+if (BO->getOpcode() == BO_LAnd &&
+llvm::isa(BO->getRHS()->IgnoreImpCasts()))
+  return FixItHint::CreateReplacement(BO->getOperatorLoc(), ",");
+  }
+  return FixItHint::CreateInsertion(EndExprLoc, ", \"\"");
+}
+
 /// ParseStaticAssertDeclaration - Parse C++0x or C11 static_assert-declaration.
 ///
 /// [C++0x] static_assert-declaration:
@@ -894,12 +904,11 @@
 
   ExprResult AssertMessage;
   if (Tok.is(tok::r_paren)) {
-Diag(Tok, getLangOpts().CPlusPlus17
-  ? diag::warn_cxx14_compat_static_assert_no_message
-  : diag::ext_static_assert_no_message)
-  << (getLangOpts().CPlusPlus17
-  ? FixItHint()
-  : FixItHint::CreateInsertion(Tok.getLocation(), ", \"\""));
+if (getLangOpts().CPlusPlus17)
+  Diag(Tok, diag::warn_cxx14_compat_static_assert_no_message);
+else
+  Diag(Tok, diag::ext_static_assert_no_message)
+  << getStaticAssertNoMessageFixIt(AssertExpr.get(), Tok.getLocation());
   } else {
 if (ExpectAndConsume(tok::comma)) {
   SkipUntil(tok::semi);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D89198: [X86] Define __LAHF_SAHF__ if feature 'sahf' is set

2020-10-10 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added inline comments.



Comment at: clang/lib/Basic/Targets/X86.cpp:564
+  if (HasLAHFSAHF)
+Builder.defineMacro("__LAHF_SAHF__");
   if (HasLZCNT)

craig.topper wrote:
> It looks like gcc may define this always in 32-bit mode?
More confusingly, they define it in 32-bit mode unless -mno-sahf is on the 
command line. Despite 32-bit mode always having LAHF/SAHF instructions.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89198

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


[PATCH] D89198: [X86] Define __LAHF_SAHF__ if feature 'sahf' is set

2020-10-10 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added inline comments.



Comment at: clang/lib/Basic/Targets/X86.cpp:564
+  if (HasLAHFSAHF)
+Builder.defineMacro("__LAHF_SAHF__");
   if (HasLZCNT)

It looks like gcc may define this always in 32-bit mode?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89198

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


[PATCH] D89197: [X86] Support -march=x86-64-v[234]

2020-10-10 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added a comment.

Don't we need a change to X86.td too?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89197

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


[PATCH] D89194: [clang-tidy] Fix crash in readability-function-cognitive-complexity on weak refs

2020-10-10 Thread Nathan James via Phabricator via cfe-commits
njames93 added inline comments.



Comment at: 
clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp:504
   Finder->addMatcher(
-  functionDecl(
-  allOf(isDefinition(), unless(anyOf(isDefaulted(), isDeleted(),
- isImplicit(), isInstantiated()
+  functionDecl(allOf(isDefinition(),
+ unless(anyOf(isDefaulted(), isDeleted(), isImplicit(),

Not strictly necessary but that `allOf`can be removed. All top level matchers 
are Implicit allOf matchers. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89194

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


[PATCH] D89197: [X86] Support -march=x86-64-v[234]

2020-10-10 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: clang/test/Preprocessor/predefined-arch-macros-x86.c:20
+
+/// TODO: __LAHF_SAHF__
+// X86_64_V2:  #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_16 1

I'll add it after D89198 is accepted.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89197

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


[PATCH] D89198: [X86] Define __LAHF_SAHF__ if feature 'sahf' is set

2020-10-10 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay created this revision.
MaskRay added reviewers: craig.topper, dim, fweimer.
Herald added subscribers: cfe-commits, pengfei.
Herald added a project: clang.
MaskRay requested review of this revision.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D89198

Files:
  clang/lib/Basic/Targets/X86.cpp
  clang/test/Preprocessor/predefined-arch-macros.c

Index: clang/test/Preprocessor/predefined-arch-macros.c
===
--- clang/test/Preprocessor/predefined-arch-macros.c
+++ clang/test/Preprocessor/predefined-arch-macros.c
@@ -541,6 +541,7 @@
 // CHECK_CORE_AVX2_M32: #define __F16C__ 1
 // CHECK_CORE_AVX2_M32: #define __FMA__ 1
 // CHECK_CORE_AVX2_M32: #define __INVPCID__ 1
+// CHECK_CORE_AVX2_M32: #define __LAHF_SAHF__ 1
 // CHECK_CORE_AVX2_M32: #define __LZCNT__ 1
 // CHECK_CORE_AVX2_M32: #define __MMX__ 1
 // CHECK_CORE_AVX2_M32: #define __MOVBE__ 1
@@ -572,6 +573,7 @@
 // CHECK_CORE_AVX2_M64: #define __F16C__ 1
 // CHECK_CORE_AVX2_M64: #define __FMA__ 1
 // CHECK_CORE_AVX2_M64: #define __INVPCID__ 1
+// CHECK_CORE_AVX2_M64: #define __LAHF_SAHF__ 1
 // CHECK_CORE_AVX2_M64: #define __LZCNT__ 1
 // CHECK_CORE_AVX2_M64: #define __MMX__ 1
 // CHECK_CORE_AVX2_M64: #define __MOVBE__ 1
@@ -607,6 +609,7 @@
 // CHECK_BROADWELL_M32: #define __F16C__ 1
 // CHECK_BROADWELL_M32: #define __FMA__ 1
 // CHECK_BROADWELL_M32: #define __INVPCID__ 1
+// CHECK_BROADWELL_M32: #define __LAHF_SAHF__ 1
 // CHECK_BROADWELL_M32: #define __LZCNT__ 1
 // CHECK_BROADWELL_M32: #define __MMX__ 1
 // CHECK_BROADWELL_M32: #define __MOVBE__ 1
@@ -641,6 +644,7 @@
 // CHECK_BROADWELL_M64: #define __F16C__ 1
 // CHECK_BROADWELL_M64: #define __FMA__ 1
 // CHECK_BROADWELL_M64: #define __INVPCID__ 1
+// CHECK_BROADWELL_M64: #define __LAHF_SAHF__ 1
 // CHECK_BROADWELL_M64: #define __LZCNT__ 1
 // CHECK_BROADWELL_M64: #define __MMX__ 1
 // CHECK_BROADWELL_M64: #define __MOVBE__ 1
@@ -2515,6 +2519,7 @@
 // RUN:   | FileCheck -match-full-lines %s -check-prefix=CHECK_AMDFAM10_M32
 // CHECK_AMDFAM10_M32: #define __3dNOW_A__ 1
 // CHECK_AMDFAM10_M32: #define __3dNOW__ 1
+// CHECK_AMDFAM10_M32: #define __LAHF_SAHF__ 1
 // CHECK_AMDFAM10_M32: #define __LZCNT__ 1
 // CHECK_AMDFAM10_M32: #define __MMX__ 1
 // CHECK_AMDFAM10_M32: #define __POPCNT__ 1
@@ -2538,6 +2543,7 @@
 // CHECK_AMDFAM10_M64: #define __3dNOW_A__ 1
 // CHECK_AMDFAM10_M64: #define __3dNOW__ 1
 // CHECK_AMDFAM10_M64: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_16 1
+// CHECK_AMDFAM10_M64: #define __LAHF_SAHF__ 1
 // CHECK_AMDFAM10_M64: #define __LZCNT__ 1
 // CHECK_AMDFAM10_M64: #define __MMX__ 1
 // CHECK_AMDFAM10_M64: #define __POPCNT__ 1
@@ -2562,6 +2568,7 @@
 // RUN:   | FileCheck -match-full-lines %s -check-prefix=CHECK_BTVER1_M32
 // CHECK_BTVER1_M32-NOT: #define __3dNOW_A__ 1
 // CHECK_BTVER1_M32-NOT: #define __3dNOW__ 1
+// CHECK_BTVER1_M32: #define __LAHF_SAHF__ 1
 // CHECK_BTVER1_M32: #define __LZCNT__ 1
 // CHECK_BTVER1_M32: #define __MMX__ 1
 // CHECK_BTVER1_M32: #define __POPCNT__ 1
@@ -2584,6 +2591,7 @@
 // RUN:   | FileCheck -match-full-lines %s -check-prefix=CHECK_BTVER1_M64
 // CHECK_BTVER1_M64-NOT: #define __3dNOW_A__ 1
 // CHECK_BTVER1_M64-NOT: #define __3dNOW__ 1
+// CHECK_BTVER1_M64: #define __LAHF_SAHF__ 1
 // CHECK_BTVER1_M64: #define __LZCNT__ 1
 // CHECK_BTVER1_M64: #define __MMX__ 1
 // CHECK_BTVER1_M64: #define __POPCNT__ 1
@@ -3023,6 +3031,7 @@
 // CHECK_ZNVER1_M64-NOT: #define __FMA4__ 1
 // CHECK_ZNVER1_M64: #define __FMA__ 1
 // CHECK_ZNVER1_M64: #define __FSGSBASE__ 1
+// CHECK_ZNVER1_M64: #define __LAHF_SAHF__ 1
 // CHECK_ZNVER1_M64: #define __LZCNT__ 1
 // CHECK_ZNVER1_M64: #define __MMX__ 1
 // CHECK_ZNVER1_M64: #define __MOVBE__ 1
@@ -3073,6 +3082,7 @@
 // CHECK_ZNVER2_M32-NOT: #define __FMA4__ 1
 // CHECK_ZNVER2_M32: #define __FMA__ 1
 // CHECK_ZNVER2_M32: #define __FSGSBASE__ 1
+// CHECK_ZNVER2_M32: #define __LAHF_SAHF__ 1
 // CHECK_ZNVER2_M32: #define __LZCNT__ 1
 // CHECK_ZNVER2_M32: #define __MMX__ 1
 // CHECK_ZNVER2_M32: #define __PCLMUL__ 1
@@ -3122,6 +3132,7 @@
 // CHECK_ZNVER2_M64-NOT: #define __FMA4__ 1
 // CHECK_ZNVER2_M64: #define __FMA__ 1
 // CHECK_ZNVER2_M64: #define __FSGSBASE__ 1
+// CHECK_ZNVER2_M64: #define __LAHF_SAHF__ 1
 // CHECK_ZNVER2_M64: #define __LZCNT__ 1
 // CHECK_ZNVER2_M64: #define __MMX__ 1
 // CHECK_ZNVER2_M64: #define __PCLMUL__ 1
Index: clang/lib/Basic/Targets/X86.cpp
===
--- clang/lib/Basic/Targets/X86.cpp
+++ clang/lib/Basic/Targets/X86.cpp
@@ -560,6 +560,8 @@
   if (HasVPCLMULQDQ)
 Builder.defineMacro("__VPCLMULQDQ__");
 
+  if (HasLAHFSAHF)
+Builder.defineMacro("__LAHF_SAHF__");
   if (HasLZCNT)
 Builder.defineMacro("__LZCNT__");
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D89197: [X86] Support -march=x86-64-v[234]

2020-10-10 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay created this revision.
MaskRay added reviewers: craig.topper, efriedma, fweimer, RKSimon, spatel.
Herald added subscribers: llvm-commits, cfe-commits, pengfei, jfb, hiraditya.
Herald added projects: clang, LLVM.
MaskRay requested review of this revision.

PR47686. These micro-architecture levels are defined in the x86-64 psABI:

https://gitlab.com/x86-psABIs/x86-64-ABI/-/commit/77566eb03bc6a326811cb7e9

GCC 11 will support these levels.

Note, -mtune=x86-64-v[234] are invalid and __builtin_cpu_is cannot be
used on them.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D89197

Files:
  clang/lib/Basic/Targets/X86.cpp
  clang/lib/Basic/Targets/X86.h
  clang/test/Driver/x86-march.c
  clang/test/Driver/x86-mtune.c
  clang/test/Misc/target-invalid-cpu-note.c
  clang/test/Preprocessor/predefined-arch-macros-x86.c
  clang/test/Preprocessor/predefined-arch-macros.c
  clang/test/Sema/builtin-cpu-supports.c
  llvm/include/llvm/Support/X86TargetParser.h
  llvm/lib/Support/X86TargetParser.cpp

Index: llvm/lib/Support/X86TargetParser.cpp
===
--- llvm/lib/Support/X86TargetParser.cpp
+++ llvm/lib/Support/X86TargetParser.cpp
@@ -137,6 +137,15 @@
 
 // Basic 64-bit capable CPU.
 constexpr FeatureBitset FeaturesX86_64 = FeaturesPentium4 | Feature64BIT;
+constexpr FeatureBitset FeaturesX86_64_V2 = FeaturesX86_64 | FeatureSAHF |
+FeaturePOPCNT | FeatureSSE4_2 |
+FeatureCMPXCHG16B;
+constexpr FeatureBitset FeaturesX86_64_V3 =
+FeaturesX86_64_V2 | FeatureAVX2 | FeatureBMI2 | FeatureFMA | FeatureLZCNT |
+FeatureMOVBE | FeatureXSAVE;
+constexpr FeatureBitset FeaturesX86_64_V4 = FeaturesX86_64_V3 |
+FeatureAVX512BW | FeatureAVX512CD |
+FeatureAVX512DQ | FeatureAVX512VL;
 
 // Intel Core CPUs
 constexpr FeatureBitset FeaturesCore2 =
@@ -383,10 +392,15 @@
   { {"znver2"}, CK_ZNVER2, FEATURE_AVX2, FeaturesZNVER2 },
   // Generic 64-bit processor.
   { {"x86-64"}, CK_x86_64, ~0U, FeaturesX86_64 },
+  { {"x86-64-v2"}, CK_x86_64_v2, ~0U, FeaturesX86_64_V2 },
+  { {"x86-64-v3"}, CK_x86_64_v3, ~0U, FeaturesX86_64_V3 },
+  { {"x86-64-v4"}, CK_x86_64_v4, ~0U, FeaturesX86_64_V4 },
   // Geode processors.
   { {"geode"}, CK_Geode, ~0U, FeaturesGeode },
 };
 
+constexpr const char *NoTuneList[] = {"x86-64-v2", "x86-64-v3", "x86-64-v4"};
+
 X86::CPUKind llvm::X86::parseArchX86(StringRef CPU, bool Only64Bit) {
   for (const auto  : Processors)
 if (P.Name == CPU && (P.Features[FEATURE_64BIT] || !Only64Bit))
@@ -395,6 +409,12 @@
   return CK_None;
 }
 
+X86::CPUKind llvm::X86::parseTuneCPU(StringRef CPU, bool Only64Bit) {
+  if (llvm::is_contained(NoTuneList, CPU))
+return CK_None;
+  return parseArchX86(CPU, Only64Bit);
+}
+
 void llvm::X86::fillValidCPUArchList(SmallVectorImpl ,
  bool Only64Bit) {
   for (const auto  : Processors)
@@ -402,6 +422,14 @@
   Values.emplace_back(P.Name);
 }
 
+void llvm::X86::fillValidTuneCPUList(SmallVectorImpl ,
+ bool Only64Bit) {
+  for (const ProcInfo  : Processors)
+if (!P.Name.empty() && (P.Features[FEATURE_64BIT] || !Only64Bit) &&
+!llvm::is_contained(NoTuneList, P.Name))
+  Values.emplace_back(P.Name);
+}
+
 ProcessorFeatures llvm::X86::getKeyFeature(X86::CPUKind Kind) {
   // FIXME: Can we avoid a linear search here? The table might be sorted by
   // CPUKind so we could binary search?
Index: llvm/include/llvm/Support/X86TargetParser.h
===
--- llvm/include/llvm/Support/X86TargetParser.h
+++ llvm/include/llvm/Support/X86TargetParser.h
@@ -121,17 +121,24 @@
   CK_ZNVER1,
   CK_ZNVER2,
   CK_x86_64,
+  CK_x86_64_v2,
+  CK_x86_64_v3,
+  CK_x86_64_v4,
   CK_Geode,
 };
 
 /// Parse \p CPU string into a CPUKind. Will only accept 64-bit capable CPUs if
 /// \p Only64Bit is true.
 CPUKind parseArchX86(StringRef CPU, bool Only64Bit = false);
+CPUKind parseTuneCPU(StringRef CPU, bool Only64Bit = false);
 
 /// Provide a list of valid CPU names. If \p Only64Bit is true, the list will
 /// only contain 64-bit capable CPUs.
 void fillValidCPUArchList(SmallVectorImpl ,
   bool Only64Bit = false);
+/// Provide a list of valid -mtune names.
+void fillValidTuneCPUList(SmallVectorImpl ,
+  bool Only64Bit = false);
 
 /// Get the key feature prioritizing target multiversioning.
 ProcessorFeatures getKeyFeature(CPUKind Kind);
Index: clang/test/Sema/builtin-cpu-supports.c
===
--- clang/test/Sema/builtin-cpu-supports.c
+++ clang/test/Sema/builtin-cpu-supports.c
@@ -15,6 +15,11 @@
 
   if (__builtin_cpu_is("int")) // expected-error {{invalid cpu name for builtin}}
 a("intel");
+
+  

[PATCH] D88645: [Annotation] Allows annotation to carry some additional constant arguments.

2020-10-10 Thread Tyker via Phabricator via cfe-commits
Tyker added inline comments.



Comment at: clang/lib/CodeGen/CodeGenFunction.cpp:2229-2233
+  SmallVector Args = {
+  AnnotatedVal,
+  Builder.CreateBitCast(CGM.EmitAnnotationString(AnnotationStr), 
Int8PtrTy),
+  Builder.CreateBitCast(CGM.EmitAnnotationUnit(Location), Int8PtrTy),
+  CGM.EmitAnnotationLineNo(Location),

keryell wrote:
> Curious reindenting with mix-and-match of spaces & tabulations?
these are not tabs i believe this is just how phabricator shows indentation 
changes.



Comment at: clang/lib/Sema/SemaDeclAttr.cpp:3693
+if (E->isValueDependent() || E->isTypeDependent() ||
+(CE && CE->hasAPValueResult()))
+  continue;

aaron.ballman wrote:
> What is the rationale for bailing out when the constant expression has an 
> `APValue` result?
the intent was that during nested template instantiation arguement will be 
evaluated as soon as they are neither value nor type dependent and the result 
will be stored in the ConstantExpr. if an arguement has already been evaluated 
in a previous instantiation we don't want to evaluate it again.
but because of SubstExpr ConstantExpr are getting removed so it removed it.



Comment at: clang/lib/Sema/SemaDeclAttr.cpp:3704-3705
+  Result = E->EvaluateAsRValue(Eval, Context, true);
+else
+  Result = E->EvaluateAsLValue(Eval, Context, true);
+

keryell wrote:
> aaron.ballman wrote:
> > Tyker wrote:
> > > aaron.ballman wrote:
> > > > Under what circumstances would we want the constant expressions to be 
> > > > lvalues? I would have guessed you would want to call 
> > > > `Expr::EvaluateAsConstantExpr()` instead of either of these.
> > > Expr::EvaluateAsConstantExpr will evaluate expression in there value 
> > > category.
> > > this can be quite surprising in some situations like:
> > > ```
> > > const int g_i = 0;
> > > [[clang::annotate("test", g_i)]] void t() {} // annotation carries a 
> > > pointer/reference on g_i
> > > [[clang::annotate("test", (int)g_i)]] void t1() {} // annotation carries 
> > > the value 0
> > > [[clang::annotate("test", g_i + 0)]] void t1() {} // annotation carries 
> > > the value 0
> > > 
> > > ```
> > > with EvaluateAsRValue in all of the cases above the annotation will carry 
> > > the value 0.
> > > 
> > > optionally we could wrap expression with an LValue to RValue cast and 
> > > call EvaluateAsConstantExpr this should also work.
> > Thank you for the explanation. I think wrapping with an lvalue to rvalue 
> > conversion may make more sense -- `EvaluateAsRValue()` tries really hard to 
> > get an rvalue out of something even if the standard says that's not okay. 
> > It'll automatically apply the lvalue to rvalue conversion if appropriate, 
> > but it'll also do more than that (such as evaluating side effects).
> This needs some motivating comments and explanations in the code.
> Also the variations on `g_i` annotation above are quite interesting and 
> should appear in the unit tests. I am unsure they are now.
> Perhaps more interesting with other values than `0` in the example. :-)
> I guess we can still use `[[clang::annotate("test", _i)]] void t() {}` to 
> have a pointer on `g_i` and `(int&)g_i` for reference? To add to the unit 
> tests if not already checked.
> 
i changed to use EvaluateAsConstantExpr + LValueToRvalue cast.

> This needs some motivating comments and explanations in the code.
> Also the variations on `g_i` annotation above are quite interesting and 
> should appear in the unit tests. I am unsure they are now.
they are tested not as expressively as above but they are tested.

> Perhaps more interesting with other values than `0` in the example. :-)
> I guess we can still use `[[clang::annotate("test", _i)]] void t() {}` to 
> have a pointer on `g_i`
yes this is how it is working.
> `(int&)g_i` for reference? To add to the unit tests if not already checked.
(int&)g_i has the salve value category and same type as g_i it just has a noop 
cast around it.
pointer an reference are indistinguishable in an APValue the only difference is 
the c++ type of what they represent.
and they are of course lowered to the same thing. so we only need the pointer 
case.



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88645

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


[PATCH] D88645: [Annotation] Allows annotation to carry some additional constant arguments.

2020-10-10 Thread Ronan Keryell via Phabricator via cfe-commits
keryell added a comment.

@erichkeane @alexandre.isoard @Naghasan: any feedback in the context of SYCL & 
HLS C++ about this feature extension?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88645

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


[PATCH] D88659: [FE]Split SuitableAlign into two parts

2020-10-10 Thread Hubert Tong via Phabricator via cfe-commits
hubert.reinterpretcast added a comment.

In D88659#2323631 , @jyknight wrote:

> ISTM that comment may be incorrect. At least, the precedent set by GCC 
> appears to be that BIGGEST_ALIGNMENT and alloca _both_ should follow vector 
> alignment requirements of the selected ISA even when that is greater than any 
> fundamental alignment requirement, and greater than malloc's alignment.

That would make sense. I guess this is really the alloca alignment value then? 
We can change the scope of this patch to simply correct the comment and add 
another patch to update the value on AIX to be 16. Do you believe the change to 
the "definition" of `SuitableAlign` needs a note to the mailing list?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88659

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


[PATCH] D87547: [MinGW][clang-shlib] Build by default on MinGW

2020-10-10 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo added a comment.

In D87547#2323605 , @mati865 wrote:

>> Or maybe even make it into a cmake option?
>
> I've considered it with default to true for unix and false for others but I'm 
> not sure if complicating Clang build options like that is worth it.

Yeah, it does sound a bit like overkill, so something like what you suggested 
above probably is sanest then.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87547

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


[PATCH] D88659: [FE]Split SuitableAlign into two parts

2020-10-10 Thread James Y Knight via Phabricator via cfe-commits
jyknight added a comment.

In D88659#2319636 , 
@hubert.reinterpretcast wrote:

> In D88659#2318203 , @jyknight wrote:
>
>> It seems like on AIX, `__BIGGEST_ALIGNMENT__` should just be set to 16, 
>> then. I'm not sure why you want it to be 8?
>
>
>
>   /// Return the alignment that is suitable for storing any
>   /// object with a fundamental alignment requirement.
>
> Vector types have extended (not fundamental) alignment on AIX, because 
> `malloc` is not guaranteed to return addresses that are 16-byte aligned.

ISTM that comment may be incorrect. At least, the precedent set by GCC appears 
to be that BIGGEST_ALIGNMENT and alloca _both_ should follow vector alignment 
requirements of the selected ISA even when that is greater than any fundamental 
alignment requirement, and greater than malloc's alignment.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88659

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


[PATCH] D89177: [cmake] Add support for multiple distributions

2020-10-10 Thread Saleem Abdulrasool via Phabricator via cfe-commits
compnerd added a comment.

I've not taken a thorough look at the changes, but I am definitely in favour of 
this change (conceptually).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89177

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


[PATCH] D87547: [MinGW][clang-shlib] Build by default on MinGW

2020-10-10 Thread Mateusz Mikuła via Phabricator via cfe-commits
mati865 added a comment.

> Or maybe even make it into a cmake option?

I've considered it as default to true for unix and false for others but I'm not 
sure if complicating Clang build options like that is worth it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87547

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


[PATCH] D89194: [clang-tidy] Fix crash in readability-function-cognitive-complexity on weak refs

2020-10-10 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri accepted this revision.
lebedev.ri added a comment.
This revision is now accepted and ready to land.

Looks good to me, @aaron.ballman ?




Comment at: 
clang-tools-extra/test/clang-tidy/checkers/readability-function-cognitive-complexity.cpp:1017
+
+static void dont_crash_on_weak() 
__attribute__((__weakref__("__dont_crash_on_weak")));





Comment at: 
clang-tools-extra/test/clang-tidy/checkers/readability-function-cognitive-complexity.cpp:1018
+static void dont_crash_on_weak() 
__attribute__((__weakref__("__dont_crash_on_weak")));
\ No newline at end of file


Please do add a newline



Comment at: clang/include/clang/ASTMatchers/ASTMatchers.h:4650
 
+/// Matches weak function declarations.
+///

You also need to regenerate the html docs then


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89194

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


[PATCH] D89194: [clang-tidy] Fix crash in readability-function-cognitive-complexity on weak refs

2020-10-10 Thread Zinovy Nis via Phabricator via cfe-commits
zinovy.nis created this revision.
Herald added subscribers: cfe-commits, lebedev.ri, xazax.hun.
Herald added a reviewer: lebedev.ri.
Herald added a project: clang.
zinovy.nis requested review of this revision.

Assert fires on weak refs like

static void dont_crash_on_weak() 
__attribute__((__weakref__("__dont_crash_on_weak")));

Bug: https://bugs.llvm.org/show_bug.cgi?id=47779


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D89194

Files:
  clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-function-cognitive-complexity.cpp
  clang/include/clang/ASTMatchers/ASTMatchers.h


Index: clang/include/clang/ASTMatchers/ASTMatchers.h
===
--- clang/include/clang/ASTMatchers/ASTMatchers.h
+++ clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -4647,6 +4647,19 @@
   return Node.isDefaulted();
 }
 
+/// Matches weak function declarations.
+///
+/// Given:
+/// \code
+///   void foo() __attribute__((__weakref__("__foo")));
+///   void bar();
+/// \endcode
+/// functionDecl(isWeak())
+///   matches the weak declaration foo, but not bar.
+AST_MATCHER(FunctionDecl, isWeak) {
+  return Node.isWeak();
+}
+
 /// Matches functions that have a dynamic exception specification.
 ///
 /// Given:
Index: 
clang-tools-extra/test/clang-tidy/checkers/readability-function-cognitive-complexity.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/readability-function-cognitive-complexity.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/readability-function-cognitive-complexity.cpp
@@ -1013,3 +1013,5 @@
 
   templatedFunction();
 }
+
+static void dont_crash_on_weak() 
__attribute__((__weakref__("__dont_crash_on_weak")));
\ No newline at end of file
Index: 
clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp
===
--- 
clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp
+++ 
clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp
@@ -501,9 +501,9 @@
 
 void FunctionCognitiveComplexityCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(
-  functionDecl(
-  allOf(isDefinition(), unless(anyOf(isDefaulted(), isDeleted(),
- isImplicit(), isInstantiated()
+  functionDecl(allOf(isDefinition(),
+ unless(anyOf(isDefaulted(), isDeleted(), isImplicit(),
+  isInstantiated(), isWeak()
   .bind("func"),
   this);
 }


Index: clang/include/clang/ASTMatchers/ASTMatchers.h
===
--- clang/include/clang/ASTMatchers/ASTMatchers.h
+++ clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -4647,6 +4647,19 @@
   return Node.isDefaulted();
 }
 
+/// Matches weak function declarations.
+///
+/// Given:
+/// \code
+///   void foo() __attribute__((__weakref__("__foo")));
+///   void bar();
+/// \endcode
+/// functionDecl(isWeak())
+///   matches the weak declaration foo, but not bar.
+AST_MATCHER(FunctionDecl, isWeak) {
+  return Node.isWeak();
+}
+
 /// Matches functions that have a dynamic exception specification.
 ///
 /// Given:
Index: clang-tools-extra/test/clang-tidy/checkers/readability-function-cognitive-complexity.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/readability-function-cognitive-complexity.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability-function-cognitive-complexity.cpp
@@ -1013,3 +1013,5 @@
 
   templatedFunction();
 }
+
+static void dont_crash_on_weak() __attribute__((__weakref__("__dont_crash_on_weak")));
\ No newline at end of file
Index: clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp
@@ -501,9 +501,9 @@
 
 void FunctionCognitiveComplexityCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(
-  functionDecl(
-  allOf(isDefinition(), unless(anyOf(isDefaulted(), isDeleted(),
- isImplicit(), isInstantiated()
+  functionDecl(allOf(isDefinition(),
+ unless(anyOf(isDefaulted(), isDeleted(), isImplicit(),
+  isInstantiated(), isWeak()
   .bind("func"),
   this);
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D87547: [MinGW][clang-shlib] Build by default on MinGW

2020-10-10 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo added a comment.

Out of these, the second (only enable on mingw if libllvm is available) sounds 
sensible to me. Or maybe even make it into a cmake option?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87547

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


[clang] 666ef0d - [AMDGPU] Add gfx602, gfx705, gfx805 targets

2020-10-10 Thread Tim Renouf via cfe-commits

Author: Tim Renouf
Date: 2020-10-10T17:22:22+01:00
New Revision: 666ef0db208bb3880115bdc133e72e954ed55300

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

LOG: [AMDGPU] Add gfx602, gfx705, gfx805 targets

At AMD, in an internal audit of our code, we found some corner cases
where we were not quite differentiating targets enough for some old
hardware. This commit is part of fixing that by adding three new
targets:

* The "Oland" and "Hainan" variants of gfx601 are now split out into
  gfx602. LLPC (in the GPUOpen driver) and other front-ends could use
  that to avoid using the shaderZExport workaround on gfx602.

* One variant of gfx703 is now split out into gfx705. LLPC and other
  front-ends could use that to avoid using the
  shaderSpiCsRegAllocFragmentation workaround on gfx705.

* The "TongaPro" variant of gfx802 is now split out into gfx805.
  TongaPro has a faster 64-bit shift than its former friends in gfx802,
  and a subtarget feature could be set up for that to take advantage of
  it. This commit does not make that change; it just adds the target.

V2: Add clang changes. Put TargetParser list in order.
V3: AMDGCNGPUs table in TargetParser.cpp needs to be in GPUKind order,
so fix the GPUKind order.

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

Change-Id: Ia901a7157eb2f73ccd9f25dbacec38427312377d

Added: 


Modified: 
clang/include/clang/Basic/Cuda.h
clang/lib/Basic/Cuda.cpp
clang/lib/Basic/Targets/AMDGPU.cpp
clang/lib/Basic/Targets/NVPTX.cpp
clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
clang/test/CodeGenOpenCL/amdgpu-features.cl
clang/test/Driver/amdgpu-macros.cl
clang/test/Driver/amdgpu-mcpu.cl
clang/test/Driver/cuda-arch-translation.cu
clang/test/Misc/target-invalid-cpu-note.c
llvm/docs/AMDGPUUsage.rst
llvm/include/llvm/BinaryFormat/ELF.h
llvm/include/llvm/Support/TargetParser.h
llvm/lib/Object/ELFObjectFile.cpp
llvm/lib/ObjectYAML/ELFYAML.cpp
llvm/lib/Support/TargetParser.cpp
llvm/lib/Target/AMDGPU/AMDGPU.td
llvm/lib/Target/AMDGPU/GCNProcessors.td
llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUTargetStreamer.cpp
llvm/test/CodeGen/AMDGPU/directive-amdgcn-target.ll
llvm/test/CodeGen/AMDGPU/elf-header-flags-mach.ll
llvm/test/Object/AMDGPU/elf-header-flags-mach.yaml
llvm/test/tools/llvm-readobj/ELF/amdgpu-elf-headers.test
llvm/tools/llvm-readobj/ELFDumper.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/Cuda.h 
b/clang/include/clang/Basic/Cuda.h
index 93394f31abdc..417d40c28adf 100644
--- a/clang/include/clang/Basic/Cuda.h
+++ b/clang/include/clang/Basic/Cuda.h
@@ -57,14 +57,17 @@ enum class CudaArch {
   SM_80,
   GFX600,
   GFX601,
+  GFX602,
   GFX700,
   GFX701,
   GFX702,
   GFX703,
   GFX704,
+  GFX705,
   GFX801,
   GFX802,
   GFX803,
+  GFX805,
   GFX810,
   GFX900,
   GFX902,

diff  --git a/clang/lib/Basic/Cuda.cpp b/clang/lib/Basic/Cuda.cpp
index 7de42c1b90e5..42a8a097b1fd 100644
--- a/clang/lib/Basic/Cuda.cpp
+++ b/clang/lib/Basic/Cuda.cpp
@@ -73,15 +73,18 @@ CudaArchToStringMap arch_names[] = {
 SM(75),  // Turing
 SM(80),  // Ampere
 GFX(600), // tahiti
-GFX(601), // pitcairn, verde, oland,hainan
+GFX(601), // pitcairn, verde
+GFX(602), // oland, hainan
 GFX(700), // kaveri
 GFX(701), // hawaii
 GFX(702), // 290,290x,R390,R390x
 GFX(703), // kabini mullins
 GFX(704), // bonaire
+GFX(705),
 GFX(801), // carrizo
 GFX(802), // tonga,iceland
 GFX(803), // fiji,polaris10
+GFX(805), // tongapro
 GFX(810), // stoney
 GFX(900), // vega, instinct
 GFX(902), GFX(904), GFX(906), GFX(908), GFX(909),

diff  --git a/clang/lib/Basic/Targets/AMDGPU.cpp 
b/clang/lib/Basic/Targets/AMDGPU.cpp
index ba9be72af971..42db207b9ce5 100644
--- a/clang/lib/Basic/Targets/AMDGPU.cpp
+++ b/clang/lib/Basic/Targets/AMDGPU.cpp
@@ -228,6 +228,7 @@ bool AMDGPUTargetInfo::initFeatureMap(
   Features["gfx9-insts"] = true;
   LLVM_FALLTHROUGH;
 case GK_GFX810:
+case GK_GFX805:
 case GK_GFX803:
 case GK_GFX802:
 case GK_GFX801:
@@ -236,6 +237,7 @@ bool AMDGPUTargetInfo::initFeatureMap(
   Features["dpp"] = true;
   Features["s-memrealtime"] = true;
   LLVM_FALLTHROUGH;
+case GK_GFX705:
 case GK_GFX704:
 case GK_GFX703:
 case GK_GFX702:
@@ -244,6 +246,7 @@ bool AMDGPUTargetInfo::initFeatureMap(
   Features["ci-insts"] = true;
   Features["flat-address-space"] = true;
   LLVM_FALLTHROUGH;
+case GK_GFX602:
 case GK_GFX601:
 case GK_GFX600:
   break;

diff  --git a/clang/lib/Basic/Targets/NVPTX.cpp 
b/clang/lib/Basic/Targets/NVPTX.cpp
index aae89477e97d..3780f1cc250c 100644
--- 

[PATCH] D88916: [AMDGPU] Add gfx602, gfx705, gfx805 targets

2020-10-10 Thread Tim Renouf 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 rG666ef0db208b: [AMDGPU] Add gfx602, gfx705, gfx805 targets 
(authored by tpr).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88916

Files:
  clang/include/clang/Basic/Cuda.h
  clang/lib/Basic/Cuda.cpp
  clang/lib/Basic/Targets/AMDGPU.cpp
  clang/lib/Basic/Targets/NVPTX.cpp
  clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
  clang/test/CodeGenOpenCL/amdgpu-features.cl
  clang/test/Driver/amdgpu-macros.cl
  clang/test/Driver/amdgpu-mcpu.cl
  clang/test/Driver/cuda-arch-translation.cu
  clang/test/Misc/target-invalid-cpu-note.c
  llvm/docs/AMDGPUUsage.rst
  llvm/include/llvm/BinaryFormat/ELF.h
  llvm/include/llvm/Support/TargetParser.h
  llvm/lib/Object/ELFObjectFile.cpp
  llvm/lib/ObjectYAML/ELFYAML.cpp
  llvm/lib/Support/TargetParser.cpp
  llvm/lib/Target/AMDGPU/AMDGPU.td
  llvm/lib/Target/AMDGPU/GCNProcessors.td
  llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUTargetStreamer.cpp
  llvm/test/CodeGen/AMDGPU/directive-amdgcn-target.ll
  llvm/test/CodeGen/AMDGPU/elf-header-flags-mach.ll
  llvm/test/Object/AMDGPU/elf-header-flags-mach.yaml
  llvm/test/tools/llvm-readobj/ELF/amdgpu-elf-headers.test
  llvm/tools/llvm-readobj/ELFDumper.cpp

Index: llvm/tools/llvm-readobj/ELFDumper.cpp
===
--- llvm/tools/llvm-readobj/ELFDumper.cpp
+++ llvm/tools/llvm-readobj/ELFDumper.cpp
@@ -1749,14 +1749,17 @@
   LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_R600_TURKS),
   LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_AMDGCN_GFX600),
   LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_AMDGCN_GFX601),
+  LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_AMDGCN_GFX602),
   LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_AMDGCN_GFX700),
   LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_AMDGCN_GFX701),
   LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_AMDGCN_GFX702),
   LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_AMDGCN_GFX703),
   LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_AMDGCN_GFX704),
+  LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_AMDGCN_GFX705),
   LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_AMDGCN_GFX801),
   LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_AMDGCN_GFX802),
   LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_AMDGCN_GFX803),
+  LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_AMDGCN_GFX805),
   LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_AMDGCN_GFX810),
   LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_AMDGCN_GFX900),
   LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_AMDGCN_GFX902),
Index: llvm/test/tools/llvm-readobj/ELF/amdgpu-elf-headers.test
===
--- llvm/test/tools/llvm-readobj/ELF/amdgpu-elf-headers.test
+++ llvm/test/tools/llvm-readobj/ELF/amdgpu-elf-headers.test
@@ -4,6 +4,9 @@
 # RUN: yaml2obj %s -o %t -DCPU=GFX601
 # RUN: llvm-readobj -h %t | FileCheck %s --match-full-lines -DFILE=%t -DCPU=GFX601 -DFLAGS=0x21
 
+# RUN: yaml2obj %s -o %t -DCPU=GFX602
+# RUN: llvm-readobj -h %t | FileCheck %s --match-full-lines -DFILE=%t -DCPU=GFX602 -DFLAGS=0x3A
+
 # RUN: yaml2obj %s -o %t -DCPU=GFX700
 # RUN: llvm-readobj -h %t | FileCheck %s --match-full-lines -DFILE=%t -DCPU=GFX700 -DFLAGS=0x22
 
@@ -19,6 +22,9 @@
 # RUN: yaml2obj %s -o %t -DCPU=GFX704
 # RUN: llvm-readobj -h %t | FileCheck %s --match-full-lines -DFILE=%t -DCPU=GFX704 -DFLAGS=0x26
 
+# RUN: yaml2obj %s -o %t -DCPU=GFX705
+# RUN: llvm-readobj -h %t | FileCheck %s --match-full-lines -DFILE=%t -DCPU=GFX705 -DFLAGS=0x3B
+
 # RUN: yaml2obj %s -o %t -DCPU=GFX801
 # RUN: llvm-readobj -h %t | FileCheck %s --match-full-lines -DFILE=%t -DCPU=GFX801 -DFLAGS=0x28
 
@@ -28,6 +34,9 @@
 # RUN: yaml2obj %s -o %t -DCPU=GFX803
 # RUN: llvm-readobj -h %t | FileCheck %s --match-full-lines -DFILE=%t -DCPU=GFX803 -DFLAGS=0x2A
 
+# RUN: yaml2obj %s -o %t -DCPU=GFX805
+# RUN: llvm-readobj -h %t | FileCheck %s --match-full-lines -DFILE=%t -DCPU=GFX805 -DFLAGS=0x3C
+
 # RUN: yaml2obj %s -o %t -DCPU=GFX810
 # RUN: llvm-readobj -h %t | FileCheck %s --match-full-lines -DFILE=%t -DCPU=GFX810 -DFLAGS=0x2B
 
Index: llvm/test/Object/AMDGPU/elf-header-flags-mach.yaml
===
--- llvm/test/Object/AMDGPU/elf-header-flags-mach.yaml
+++ llvm/test/Object/AMDGPU/elf-header-flags-mach.yaml
@@ -100,6 +100,15 @@
 # RUN: yaml2obj --docnum=34 %s -o %t.o.34
 # RUN: llvm-readobj -s -file-headers %t.o.34 | FileCheck --check-prefixes=ELF-ALL,ELF-GFX1010 %s
 # RUN: obj2yaml %t.o.34 | FileCheck --check-prefixes=YAML-GFX1010 %s
+# RUN: yaml2obj --docnum=35 %s -o %t.o.35
+# RUN: llvm-readobj -S --file-headers %t.o.35 | FileCheck --check-prefixes=ELF-ALL,ELF-GFX602 %s
+# RUN: obj2yaml %t.o.35 | FileCheck --check-prefixes=YAML-GFX602 %s
+# RUN: yaml2obj --docnum=36 %s -o %t.o.36
+# RUN: llvm-readobj -S --file-headers %t.o.36 | FileCheck --check-prefixes=ELF-ALL,ELF-GFX705 %s
+# 

[PATCH] D78658: [clang][Frontend] Add missing error handling

2020-10-10 Thread LemonBoy via Phabricator via cfe-commits
LemonBoy added a comment.

Ping with some more reviewers, hoping to land this in time for LLVM 99.


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

https://reviews.llvm.org/D78658

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


[PATCH] D89065: [clang] Tweaked fixit for static assert with no message

2020-10-10 Thread Nathan James via Phabricator via cfe-commits
njames93 planned changes to this revision.
njames93 added a comment.

Just noticed this doesn't quite work as expected, will update


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89065

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


[PATCH] D89055: [analyzer] Wrong type cast occures during pointer dereferencing after type punning

2020-10-10 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added a comment.

If you don't mind I would also request some credit in the summary since I've 
spent some time on this as well.
Besides that I don't have much objection about this patch. It's defenately not 
my expertiese.
Good job coming up with the fix though, I had to focus on other things.




Comment at: clang/test/Analysis/string.c:367-373
+void *func_strcpy_no_assertion();
+char ***ptr_strcpy_no_assertion;
+void strcpy_no_assertion() {
+  *(unsigned char **)ptr_strcpy_no_assertion = (unsigned char 
*)(func_strcpy_no_assertion());
+  char c;
+  strcpy(**ptr_strcpy_no_assertion, ); // no-assertion
+}

I would prefer slightly more readbale names.
`func_strcpy_no_assertion()` -> `get_void_ptr()`
`ptr_strcpy_no_assertion ` -> `type_punned_ptr`
`no-assertion` -> `no-crash`
You could also hoist the `char a` as a function parameter to spare a line :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89055

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


[PATCH] D88477: [analyzer] Overwrite cast type in getBinding only if that was null originally

2020-10-10 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added a comment.

In D88477#2319959 , @ASDenysPetrov 
wrote:

> @NoQ @steakhal
>
> Hi, guys.
>
> I've just uploaded a patch for solving this and related D77062 
> . Welcome to review D89055 
> .

Abandoning in favor of D89055 .
@ASDenysPetrov, please try to add the mentioned assertion into the 
`RegionStoreManager::getBinding` to make sure our invariant holds.

About the D77062 , I think any NFC refactor is 
more then welcomed. Let's discuss about that after the fix landed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88477

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


[PATCH] D87547: [MinGW][clang-shlib] Build by default on MinGW

2020-10-10 Thread Mateusz Mikuła via Phabricator via cfe-commits
mati865 added a comment.

> Older versions of lld didn't error out if exceeding the limit, this is fixed 
> in D86701 , unfortunately after the 11 
> branch.

Thanks, I'll backport it for MSYS2 LLVM 11 package.

> With -DLLVM_ENABLE_ASSERTIONS=ON -DCMAKE_C_COMPILER=clang 
> -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_RANLIB_COMPILER=llvm-ranlib 
> -DCMAKE_AR_COMPILER=llvm-ar -DCMAKE_LINKER=ld.lld -DLLVM_ENABLE_LLD=ON 
> libclang-cpp.dll has 65535 exports, seems it got truncated?

After adding `-DLLVM_BUILD_LLVM_DYLIB=ON` libclang-cpp.dll has 37660 exports, 
libLLVM.dll gets truncated.
Considering my previous findings linking libclang-cpp.dll to libLLVM.dll seems 
to reduce amount of exports to safer 30k-40k range.

Possible solutions:

- revert this diff so I carry downstream MSYS2 patch (easy)
- gate building of libclang-cpp.dll for MinGW on `LLVM_BUILD_LLVM_DYLIB=ON` 
(easy)
- export less symbols from libclang-cpp.dll (probably hard or very hard)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87547

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


[PATCH] D88645: [Annotation] Allows annotation to carry some additional constant arguments.

2020-10-10 Thread Tyker via Phabricator via cfe-commits
Tyker updated this revision to Diff 297409.
Tyker marked 11 inline comments as done.
Tyker added a comment.

addressed comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88645

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/ParsedAttr.h
  clang/include/clang/Sema/Sema.h
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenModule.h
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/test/AST/ast-dump-attr.cpp
  clang/test/CodeGen/annotations-field.c
  clang/test/CodeGen/annotations-global.c
  clang/test/CodeGen/annotations-loc.c
  clang/test/CodeGen/annotations-var.c
  clang/test/CodeGenCXX/attr-annotate.cpp
  clang/test/Misc/pragma-attribute-cxx.cpp
  clang/test/Misc/pragma-attribute-objc.m
  clang/test/Parser/access-spec-attrs.cpp
  clang/test/Parser/objc-implementation-attrs.m
  clang/test/Sema/annotate.c
  clang/test/Sema/pragma-attribute.c
  clang/test/SemaCXX/attr-annotate.cpp
  llvm/include/llvm/IR/Intrinsics.td
  llvm/test/Analysis/CostModel/X86/free-intrinsics.ll
  llvm/test/Analysis/CostModel/free-intrinsics-datalayout.ll
  llvm/test/Analysis/CostModel/free-intrinsics-no_info.ll
  llvm/test/CodeGen/Generic/ptr-annotate.ll
  llvm/test/Transforms/InstCombine/assume_inevitable.ll

Index: llvm/test/Transforms/InstCombine/assume_inevitable.ll
===
--- llvm/test/Transforms/InstCombine/assume_inevitable.ll
+++ llvm/test/Transforms/InstCombine/assume_inevitable.ll
@@ -15,7 +15,7 @@
 ; CHECK-NEXT:[[DUMMY_EQ:%.*]] = icmp ugt i32 [[LOADRES]], 42
 ; CHECK-NEXT:tail call void @llvm.assume(i1 [[DUMMY_EQ]])
 ; CHECK-NEXT:[[M_I8:%.*]] = bitcast i64* [[M]] to i8*
-; CHECK-NEXT:[[M_A:%.*]] = call i8* @llvm.ptr.annotation.p0i8(i8* nonnull [[M_I8]], i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str1, i64 0, i64 0), i32 2)
+; CHECK-NEXT:[[M_A:%.*]] = call i8* @llvm.ptr.annotation.p0i8(i8* nonnull [[M_I8]], i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str1, i64 0, i64 0), i32 2, i8* null)
 ; CHECK-NEXT:[[M_X:%.*]] = bitcast i8* [[M_A]] to i64*
 ; CHECK-NEXT:[[OBJSZ:%.*]] = call i64 @llvm.objectsize.i64.p0i8(i8* [[C:%.*]], i1 false, i1 false, i1 false)
 ; CHECK-NEXT:store i64 [[OBJSZ]], i64* [[M_X]], align 4
@@ -44,7 +44,7 @@
   call void @llvm.lifetime.end.p0i8(i64 1, i8* %dummy)
 
   %m_i8 = bitcast i64* %m to i8*
-  %m_a = call i8* @llvm.ptr.annotation.p0i8(i8* %m_i8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str1, i32 0, i32 0), i32 2)
+  %m_a = call i8* @llvm.ptr.annotation.p0i8(i8* %m_i8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str1, i32 0, i32 0), i32 2, i8* null)
   %m_x = bitcast i8* %m_a to i64*
   %objsz = call i64 @llvm.objectsize.i64.p0i8(i8* %c, i1 false)
   store i64 %objsz, i64* %m_x
@@ -64,7 +64,7 @@
 
 declare i64 @llvm.objectsize.i64.p0i8(i8*, i1)
 declare i32 @llvm.annotation.i32(i32, i8*, i8*, i32)
-declare i8* @llvm.ptr.annotation.p0i8(i8*, i8*, i8*, i32)
+declare i8* @llvm.ptr.annotation.p0i8(i8*, i8*, i8*, i32, i8*)
 
 declare void @llvm.lifetime.start.p0i8(i64, i8* nocapture)
 declare void @llvm.lifetime.end.p0i8(i64, i8* nocapture)
Index: llvm/test/CodeGen/Generic/ptr-annotate.ll
===
--- llvm/test/CodeGen/Generic/ptr-annotate.ll
+++ llvm/test/CodeGen/Generic/ptr-annotate.ll
@@ -10,9 +10,9 @@
 define void @foo() {
 entry:
   %m = alloca i8, align 4
-  %0 = call i8* @llvm.ptr.annotation.p0i8(i8* %m, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str1, i32 0, i32 0), i32 2)
+  %0 = call i8* @llvm.ptr.annotation.p0i8(i8* %m, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str1, i32 0, i32 0), i32 2, i8* null)
   store i8 1, i8* %0, align 4
   ret void
 }
 
-declare i8* @llvm.ptr.annotation.p0i8(i8*, i8*, i8*, i32) #1
+declare i8* @llvm.ptr.annotation.p0i8(i8*, i8*, i8*, i32, i8*) #1
Index: llvm/test/Analysis/CostModel/free-intrinsics-no_info.ll
===
--- llvm/test/Analysis/CostModel/free-intrinsics-no_info.ll
+++ llvm/test/Analysis/CostModel/free-intrinsics-no_info.ll
@@ -15,8 +15,8 @@
 ; CHECK-SIZE-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: call void @llvm.lifetime.start.p0i8(i64 1, i8* 

[PATCH] D54943: WIP [clang-tidy] implement const-transformation for cppcoreguidelines-const-correctness

2020-10-10 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth updated this revision to Diff 297407.
JonasToth added a comment.

- fix test RUN line


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D54943

Files:
  clang-tools-extra/clang-tidy/cppcoreguidelines/CMakeLists.txt
  clang-tools-extra/clang-tidy/cppcoreguidelines/ConstCorrectnessCheck.cpp
  clang-tools-extra/clang-tidy/cppcoreguidelines/ConstCorrectnessCheck.h
  clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines-const-correctness.rst
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-const-correctness-cxx17.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-const-correctness-pointer-as-values.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-const-correctness-transform-pointer-as-values.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-const-correctness-transform-values.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-const-correctness-values.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-const-correctness-values.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-const-correctness-values.cpp
@@ -0,0 +1,957 @@
+// RUN: %check_clang_tidy %s cppcoreguidelines-const-correctness %t -- \
+// RUN:   -config="{CheckOptions: [\
+// RUN:   {key: 'cppcoreguidelines-const-correctness.TransformValues', value: 1}, \
+// RUN:   {key: 'cppcoreguidelines-const-correctness.WarnPointersAsValues', value: 0}, \
+// RUN:   {key: 'cppcoreguidelines-const-correctness.TransformPointersAsValues', value: 0}, \
+// RUN:   ]}" -- -fno-delayed-template-parsing
+
+// --- Provide test samples for primitive builtins -
+// - every 'p_*' variable is a 'potential_const_*' variable
+// - every 'np_*' variable is a 'non_potential_const_*' variable
+
+bool global;
+char np_global = 0; // globals can't be known to be const
+
+namespace foo {
+int scoped;
+float np_scoped = 1; // namespace variables are like globals
+} // namespace foo
+
+// Lambdas should be ignored, because they do not follow the normal variable
+// semantic (e.g. the type is only known to the compiler).
+void lambdas() {
+  auto Lambda = [](int i) { return i < 0; };
+}
+
+void some_function(double, wchar_t);
+
+void some_function(double np_arg0, wchar_t np_arg1) {
+  int p_local0 = 2;
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local0' of type 'int' can be declared 'const'
+
+  int np_local0;
+  const int np_local1 = 42;
+
+  unsigned int np_local2 = 3;
+  np_local2 <<= 4;
+
+  int np_local3 = 4;
+  ++np_local3;
+  int np_local4 = 4;
+  np_local4++;
+
+  int np_local5 = 4;
+  --np_local5;
+  int np_local6 = 4;
+  np_local6--;
+}
+
+void nested_scopes() {
+  int p_local0 = 2;
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local0' of type 'int' can be declared 'const'
+  int np_local0 = 42;
+
+  {
+int p_local1 = 42;
+// CHECK-MESSAGES: [[@LINE-1]]:5: warning: variable 'p_local1' of type 'int' can be declared 'const'
+np_local0 *= 2;
+  }
+}
+
+void ignore_reference_to_pointers() {
+  int *np_local0 = nullptr;
+  int *_local1 = np_local0;
+}
+
+void some_lambda_environment_capture_all_by_reference(double np_arg0) {
+  int np_local0 = 0;
+  int p_local0 = 1;
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local0' of type 'int' can be declared 'const'
+
+  int np_local2;
+  const int np_local3 = 2;
+
+  // Capturing all variables by reference prohibits making them const.
+  [&]() { ++np_local0; };
+
+  int p_local1 = 0;
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local1' of type 'int' can be declared 'const'
+}
+
+void some_lambda_environment_capture_all_by_value(double np_arg0) {
+  int np_local0 = 0;
+  int p_local0 = 1;
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local0' of type 'int' can be declared 'const'
+
+  int np_local1;
+  const int np_local2 = 2;
+
+  // Capturing by value has no influence on them.
+  [=]() { (void)p_local0; };
+
+  np_local0 += 10;
+}
+
+void function_inout_pointer(int *inout);
+void function_in_pointer(const int *in);
+
+void some_pointer_taking(int *out) {
+  int np_local0 = 42;
+  const int *const p0_np_local0 = _local0;
+  int *const p1_np_local0 = _local0;
+
+  int np_local1 = 42;
+  const int *const p0_np_local1 = _local1;
+  int *const p1_np_local1 = _local1;
+  *p1_np_local0 = 43;
+
+  int np_local2 = 42;
+  function_inout_pointer(_local2);
+
+  // Prevents const.
+  int np_local3 = 42;
+  out = _local3; // This returns and invalid address, its just about the AST
+
+  int p_local1 = 42;
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local1' of type 'int' can be declared 'const'
+  const int *const p0_p_local1 = _local1;

[clang-tools-extra] 0db08e5 - [clangd] Map bits/stdint-intn.h and bits/stdint-uintn.h to cstdint.

2020-10-10 Thread Benjamin Kramer via cfe-commits

Author: Benjamin Kramer
Date: 2020-10-10T14:13:42+02:00
New Revision: 0db08e59c9d2d3b004ea61f96d823edff283ed25

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

LOG: [clangd] Map bits/stdint-intn.h and bits/stdint-uintn.h to cstdint.

These are private glibc headers containing parts of the implementation
of stdint.h.

Added: 


Modified: 
clang-tools-extra/clangd/index/CanonicalIncludes.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/index/CanonicalIncludes.cpp 
b/clang-tools-extra/clangd/index/CanonicalIncludes.cpp
index 120f121c7278..a63a6bd82a15 100644
--- a/clang-tools-extra/clangd/index/CanonicalIncludes.cpp
+++ b/clang-tools-extra/clangd/index/CanonicalIncludes.cpp
@@ -420,6 +420,8 @@ void CanonicalIncludes::addSystemHeadersMapping(const 
LangOptions ) {
   {"bits/signum.h", ""},
   {"bits/sigset.h", ""},
   {"bits/sigstack.h", ""},
+  {"bits/stdint-intn.h", ""},
+  {"bits/stdint-uintn.h", ""},
   {"bits/stdio_lim.h", ""},
   {"bits/sys_errlist.h", ""},
   {"bits/time.h", ""},



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


[PATCH] D87981: [X86] AMX programming model prototype.

2020-10-10 Thread LuoYuanke via Phabricator via cfe-commits
LuoYuanke added a comment.

ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87981

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


[PATCH] D54943: WIP [clang-tidy] implement const-transformation for cppcoreguidelines-const-correctness

2020-10-10 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth marked an inline comment as done.
JonasToth added inline comments.



Comment at: 
clang-tools-extra/clang-tidy/cppcoreguidelines/ConstCorrectnessCheck.cpp:46
+
+void ConstCorrectnessCheck::registerMatchers(MatchFinder *Finder) {
+  const auto ConstType = hasType(isConstQualified());

aaron.ballman wrote:
> JonasToth wrote:
> > aaron.ballman wrote:
> > > Should this check only fire in C++? I'm sort of on the fence. It's a C++ 
> > > core guideline, so it stands to reason it should be disabled for C code. 
> > > But const-correctness is a thing in C too. WDYT?
> > I do not know all the subtle differences between C and C++ here. Judging 
> > from this: https://stackoverflow.com/questions/5248571/is-there-const-in-c 
> > the current form would not be correct for C for pointers.
> > The assumptions of this check and especially the transformations are done 
> > for C++. I dont see a reason why the value-semantic would not apply for 
> > both.
> > 
> > Maybe there is a way to make the code compatible for both languages. The 
> > easiest solution would probably to not do the 'pointer-as-value' 
> > transformation. This is not that relevant as a feature anyway. I expect not 
> > nearly as much usage of this option as for the others.
> > 
> > In the end of the day i would like to support both C and C++. Right now it 
> > is untested and especially the transformation might break the code. It 
> > should run on both languages though, as there is no language checking.
> > I will add some real world C code-bases for the transformation testing and 
> > see what happens :)
> > Judging from this: 
> > https://stackoverflow.com/questions/5248571/is-there-const-in-c the current 
> > form would not be correct for C for pointers.
> 
> Sure, there may be additional changes needed to support the other oddities of 
> C. I was asking more at the high level.
> 
> > In the end of the day i would like to support both C and C++. Right now it 
> > is untested and especially the transformation might break the code. 
> 
> Another option is for us to restrict the check in its current form to just 
> C++ and then expose a C check from it in a follow-up (likely under a 
> different module than cppcodeguidelines). For instance, CERT has a 
> recommendation (not a rule) about this for C 
> (https://wiki.sei.cmu.edu/confluence/display/c/DCL00-C.+Const-qualify+immutable+objects)
>  and I would not be surprised to find it in other coding standards as well.
Another const check is probably better. The clang-tidy part should be minimal 
effort. I think there isn't alot of duplication either.
We could still think of proper configurability of this check and alias it into 
other modules with proper defaults for C.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D54943

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


[PATCH] D54943: WIP [clang-tidy] implement const-transformation for cppcoreguidelines-const-correctness

2020-10-10 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth updated this revision to Diff 297405.
JonasToth added a comment.

- no delayed template parsing
- adjust release note issue


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D54943

Files:
  clang-tools-extra/clang-tidy/cppcoreguidelines/CMakeLists.txt
  clang-tools-extra/clang-tidy/cppcoreguidelines/ConstCorrectnessCheck.cpp
  clang-tools-extra/clang-tidy/cppcoreguidelines/ConstCorrectnessCheck.h
  clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines-const-correctness.rst
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-const-correctness-cxx17.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-const-correctness-pointer-as-values.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-const-correctness-transform-pointer-as-values.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-const-correctness-transform-values.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-const-correctness-values.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-const-correctness-values.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-const-correctness-values.cpp
@@ -0,0 +1,957 @@
+// RUN: %check_clang_tidy %s cppcoreguidelines-const-correctness %t -- \
+// RUN:   -config="{CheckOptions: [\
+// RUN:   {key: 'cppcoreguidelines-const-correctness.TransformValues', value: 1}, \
+// RUN:   {key: 'cppcoreguidelines-const-correctness.WarnPointersAsValues', value: 0}, \
+// RUN:   {key: 'cppcoreguidelines-const-correctness.TransformPointersAsValues', value: 0}, \
+// RUN:   ]}" -- -- -fno-delayed-template-parsing
+
+// --- Provide test samples for primitive builtins -
+// - every 'p_*' variable is a 'potential_const_*' variable
+// - every 'np_*' variable is a 'non_potential_const_*' variable
+
+bool global;
+char np_global = 0; // globals can't be known to be const
+
+namespace foo {
+int scoped;
+float np_scoped = 1; // namespace variables are like globals
+} // namespace foo
+
+// Lambdas should be ignored, because they do not follow the normal variable
+// semantic (e.g. the type is only known to the compiler).
+void lambdas() {
+  auto Lambda = [](int i) { return i < 0; };
+}
+
+void some_function(double, wchar_t);
+
+void some_function(double np_arg0, wchar_t np_arg1) {
+  int p_local0 = 2;
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local0' of type 'int' can be declared 'const'
+
+  int np_local0;
+  const int np_local1 = 42;
+
+  unsigned int np_local2 = 3;
+  np_local2 <<= 4;
+
+  int np_local3 = 4;
+  ++np_local3;
+  int np_local4 = 4;
+  np_local4++;
+
+  int np_local5 = 4;
+  --np_local5;
+  int np_local6 = 4;
+  np_local6--;
+}
+
+void nested_scopes() {
+  int p_local0 = 2;
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local0' of type 'int' can be declared 'const'
+  int np_local0 = 42;
+
+  {
+int p_local1 = 42;
+// CHECK-MESSAGES: [[@LINE-1]]:5: warning: variable 'p_local1' of type 'int' can be declared 'const'
+np_local0 *= 2;
+  }
+}
+
+void ignore_reference_to_pointers() {
+  int *np_local0 = nullptr;
+  int *_local1 = np_local0;
+}
+
+void some_lambda_environment_capture_all_by_reference(double np_arg0) {
+  int np_local0 = 0;
+  int p_local0 = 1;
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local0' of type 'int' can be declared 'const'
+
+  int np_local2;
+  const int np_local3 = 2;
+
+  // Capturing all variables by reference prohibits making them const.
+  [&]() { ++np_local0; };
+
+  int p_local1 = 0;
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local1' of type 'int' can be declared 'const'
+}
+
+void some_lambda_environment_capture_all_by_value(double np_arg0) {
+  int np_local0 = 0;
+  int p_local0 = 1;
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local0' of type 'int' can be declared 'const'
+
+  int np_local1;
+  const int np_local2 = 2;
+
+  // Capturing by value has no influence on them.
+  [=]() { (void)p_local0; };
+
+  np_local0 += 10;
+}
+
+void function_inout_pointer(int *inout);
+void function_in_pointer(const int *in);
+
+void some_pointer_taking(int *out) {
+  int np_local0 = 42;
+  const int *const p0_np_local0 = _local0;
+  int *const p1_np_local0 = _local0;
+
+  int np_local1 = 42;
+  const int *const p0_np_local1 = _local1;
+  int *const p1_np_local1 = _local1;
+  *p1_np_local0 = 43;
+
+  int np_local2 = 42;
+  function_inout_pointer(_local2);
+
+  // Prevents const.
+  int np_local3 = 42;
+  out = _local3; // This returns and invalid address, its just about the AST
+
+  int p_local1 = 42;
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local1' of type 'int' can be declared 'const'
+ 

[PATCH] D89102: [X86] Add HRESET instruction.

2020-10-10 Thread Pengfei Wang via Phabricator via cfe-commits
pengfei updated this revision to Diff 297402.
pengfei added a comment.

Rebased.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89102

Files:
  clang/docs/ClangCommandLineReference.rst
  clang/include/clang/Driver/Options.td
  clang/lib/Basic/Targets/X86.cpp
  clang/lib/Basic/Targets/X86.h
  clang/lib/Headers/CMakeLists.txt
  clang/lib/Headers/cpuid.h
  clang/lib/Headers/hresetintrin.h
  clang/lib/Headers/immintrin.h
  clang/lib/Headers/x86gprintrin.h
  clang/test/CodeGen/x86-hreset-intrin.c
  clang/test/Driver/x86-target-features.c
  clang/test/Preprocessor/x86_target_features.c
  llvm/docs/ReleaseNotes.rst
  llvm/include/llvm/Support/X86TargetParser.def
  llvm/lib/Support/Host.cpp
  llvm/lib/Support/X86TargetParser.cpp
  llvm/lib/Target/X86/X86.td
  llvm/lib/Target/X86/X86InstrFormats.td
  llvm/lib/Target/X86/X86InstrInfo.td
  llvm/lib/Target/X86/X86Subtarget.h
  llvm/test/MC/Disassembler/X86/x86-32.txt
  llvm/test/MC/Disassembler/X86/x86-64.txt
  llvm/test/MC/X86/x86-32-coverage.s
  llvm/test/MC/X86/x86-64.s

Index: llvm/test/MC/X86/x86-64.s
===
--- llvm/test/MC/X86/x86-64.s
+++ llvm/test/MC/X86/x86-64.s
@@ -2014,3 +2014,7 @@
 // CHECK: tdcall
 // CHECK: encoding: [0x66,0x0f,0x01,0xcc]
 tdcall
+
+// CHECK: hreset
+// CHECK: encoding: [0xf3,0x0f,0x3a,0xf0,0xc0,0x01]
+hreset $1
Index: llvm/test/MC/X86/x86-32-coverage.s
===
--- llvm/test/MC/X86/x86-32-coverage.s
+++ llvm/test/MC/X86/x86-32-coverage.s
@@ -10891,4 +10891,8 @@
 
 // CHECK: tdcall
 // CHECK: encoding: [0x66,0x0f,0x01,0xcc]
-tdcall
\ No newline at end of file
+tdcall
+
+// CHECK: hreset
+// CHECK: encoding: [0xf3,0x0f,0x3a,0xf0,0xc0,0x01]
+hreset $1
Index: llvm/test/MC/Disassembler/X86/x86-64.txt
===
--- llvm/test/MC/Disassembler/X86/x86-64.txt
+++ llvm/test/MC/Disassembler/X86/x86-64.txt
@@ -712,3 +712,6 @@
 
 #CHECK: tdcall
 0x66 0x0f 0x01 0xcc
+
+# CHECK: hreset $1
+0xf3 0x0f 0x3a 0xf0 0xc0 0x01
Index: llvm/test/MC/Disassembler/X86/x86-32.txt
===
--- llvm/test/MC/Disassembler/X86/x86-32.txt
+++ llvm/test/MC/Disassembler/X86/x86-32.txt
@@ -1000,3 +1000,6 @@
 
 #CHECK: tdcall
 0x66 0x0f 0x01 0xcc
+
+# CHECK: hreset $1
+0xf3 0x0f 0x3a 0xf0 0xc0 0x01
Index: llvm/lib/Target/X86/X86Subtarget.h
===
--- llvm/lib/Target/X86/X86Subtarget.h
+++ llvm/lib/Target/X86/X86Subtarget.h
@@ -401,6 +401,9 @@
   /// Processor support key locker wide instructions
   bool HasWIDEKL = false;
 
+  /// Processor supports HRESET instruction
+  bool HasHRESET = false;
+
   /// Processor supports SERIALIZE instruction
   bool HasSERIALIZE = false;
 
@@ -736,6 +739,7 @@
   bool hasENQCMD() const { return HasENQCMD; }
   bool hasKL() const { return HasKL; }
   bool hasWIDEKL() const { return HasWIDEKL; }
+  bool hasHRESET() const { return HasHRESET; }
   bool hasSERIALIZE() const { return HasSERIALIZE; }
   bool hasTSXLDTRK() const { return HasTSXLDTRK; }
   bool useRetpolineIndirectCalls() const { return UseRetpolineIndirectCalls; }
Index: llvm/lib/Target/X86/X86InstrInfo.td
===
--- llvm/lib/Target/X86/X86InstrInfo.td
+++ llvm/lib/Target/X86/X86InstrInfo.td
@@ -971,6 +971,7 @@
 def HasENQCMD: Predicate<"Subtarget->hasENQCMD()">;
 def HasKL: Predicate<"Subtarget->hasKL()">;
 def HasWIDEKL: Predicate<"Subtarget->hasWIDEKL()">;
+def HasHRESET: Predicate<"Subtarget->hasHRESET()">;
 def HasSERIALIZE : Predicate<"Subtarget->hasSERIALIZE()">;
 def HasTSXLDTRK  : Predicate<"Subtarget->hasTSXLDTRK()">;
 def HasAMXTILE   : Predicate<"Subtarget->hasAMXTILE()">;
@@ -2911,6 +2912,13 @@
 def : InstAlias<"clzero\t{%eax|eax}", (CLZERO32r)>, Requires<[Not64BitMode]>;
 def : InstAlias<"clzero\t{%rax|rax}", (CLZERO64r)>, Requires<[In64BitMode]>;
 
+//===--===//
+// HRESET Instruction
+//
+let Uses = [EAX], SchedRW = [WriteSystem] in
+  def HRESET : Ii8<0xF0, MRM_C0, (outs), (ins i32u8imm:$imm), "hreset\t$imm", []>,
+   Requires<[HasHRESET]>, TAXS;
+
 //===--===//
 // SERIALIZE Instruction
 //
Index: llvm/lib/Target/X86/X86InstrFormats.td
===
--- llvm/lib/Target/X86/X86InstrFormats.td
+++ llvm/lib/Target/X86/X86InstrFormats.td
@@ -216,6 +216,7 @@
 class TAPS : TA { Prefix OpPrefix = PS; }
 class TAPD : TA { Prefix OpPrefix = PD; }
 class TAXD : TA { Prefix OpPrefix = XD; }
+class TAXS : TA { Prefix OpPrefix = XS; }
 class VEX{ Encoding OpEnc = EncVEX; }
 class VEX_W{ bit HasVEX_W = 1; }
 

[PATCH] D89148: [SyntaxTree] Artificial use of the Mutations API.

2020-10-10 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas updated this revision to Diff 297398.
eduucaldas added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89148

Files:
  clang/include/clang/Tooling/Syntax/Mutations.h
  clang/lib/Tooling/Syntax/Mutations.cpp
  clang/unittests/Tooling/Syntax/MutationsTest.cpp


Index: clang/unittests/Tooling/Syntax/MutationsTest.cpp
===
--- clang/unittests/Tooling/Syntax/MutationsTest.cpp
+++ clang/unittests/Tooling/Syntax/MutationsTest.cpp
@@ -52,6 +52,16 @@
 EXPECT_FALSE(S->isOriginal())
 << "node removed from tree cannot be marked as original";
   };
+
+  Transformation ParenthesizeRHS = [this](const llvm::Annotations ,
+  TranslationUnit *Root) {
+auto *BOE = cast(
+nodeByRange(Input.range(), Root));
+ASSERT_TRUE(BOE->canModify()) << "cannot remove a statement";
+syntax::parenthesizeRHS(*Arena, BOE);
+EXPECT_FALSE(BOE->isOriginal())
+<< "modified node cannot be marked as original";
+  };
 };
 
 INSTANTIATE_TEST_CASE_P(SyntaxTreeTests, MutationTest,
@@ -71,4 +81,22 @@
   CheckTransformation(RemoveStatement, "void test() { if (1) [[{}]] else {} }",
   "void test() { if (1) ; else {} }");
 }
+
+TEST_P(MutationTest, Parenthesize_RHS) {
+  CheckTransformation(ParenthesizeRHS, R"cpp(void test() { [[1 + 2]]; })cpp",
+  "void test() { 1 + (2); }");
+}
+
+TEST_P(MutationTest, Parenthesize_RHS_MACRO) {
+  CheckTransformation(ParenthesizeRHS, R"cpp(
+#define THENUMBER 42
+void test() {
+  [[1 + (THENUMBER)]];
+})cpp",
+  R"cpp(
+#define THENUMBER 42
+void test() {
+  1 + ((THENUMBER));
+})cpp");
+}
 } // namespace
Index: clang/lib/Tooling/Syntax/Mutations.cpp
===
--- clang/lib/Tooling/Syntax/Mutations.cpp
+++ clang/lib/Tooling/Syntax/Mutations.cpp
@@ -8,6 +8,7 @@
 #include "clang/Tooling/Syntax/Mutations.h"
 #include "clang/Basic/LLVM.h"
 #include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/TokenKinds.h"
 #include "clang/Lex/Token.h"
 #include "clang/Tooling/Core/Replacement.h"
 #include "clang/Tooling/Syntax/BuildTree.h"
@@ -96,3 +97,22 @@
 
   MutationsImpl::replace(S, createEmptyStatement(A));
 }
+
+void syntax::parenthesizeRHS(syntax::Arena ,
+ syntax::BinaryOperatorExpression *BOE) {
+  assert(BOE);
+  assert(BOE->canModify());
+
+  auto *RHS = BOE->getRhs();
+  auto *BeforeRHS = findPrevious(RHS);
+  MutationsImpl::remove(RHS);
+
+  auto *NewRHS =
+  createTree(A,
+ {{createLeaf(A, tok::l_paren), NodeRole::OpenParen},
+  {RHS, NodeRole::SubExpression},
+  {createLeaf(A, tok::r_paren), NodeRole::CloseParen}},
+ NodeKind::ParenExpression);
+
+  MutationsImpl::addAfter(BeforeRHS, NewRHS, NodeRole::RightHandSide);
+}
Index: clang/include/clang/Tooling/Syntax/Mutations.h
===
--- clang/include/clang/Tooling/Syntax/Mutations.h
+++ clang/include/clang/Tooling/Syntax/Mutations.h
@@ -31,6 +31,7 @@
 /// EXPECTS: S->canModify() == true
 void removeStatement(syntax::Arena , syntax::Statement *S);
 
+void parenthesizeRHS(syntax::Arena , syntax::BinaryOperatorExpression *BOE);
 } // namespace syntax
 } // namespace clang
 


Index: clang/unittests/Tooling/Syntax/MutationsTest.cpp
===
--- clang/unittests/Tooling/Syntax/MutationsTest.cpp
+++ clang/unittests/Tooling/Syntax/MutationsTest.cpp
@@ -52,6 +52,16 @@
 EXPECT_FALSE(S->isOriginal())
 << "node removed from tree cannot be marked as original";
   };
+
+  Transformation ParenthesizeRHS = [this](const llvm::Annotations ,
+  TranslationUnit *Root) {
+auto *BOE = cast(
+nodeByRange(Input.range(), Root));
+ASSERT_TRUE(BOE->canModify()) << "cannot remove a statement";
+syntax::parenthesizeRHS(*Arena, BOE);
+EXPECT_FALSE(BOE->isOriginal())
+<< "modified node cannot be marked as original";
+  };
 };
 
 INSTANTIATE_TEST_CASE_P(SyntaxTreeTests, MutationTest,
@@ -71,4 +81,22 @@
   CheckTransformation(RemoveStatement, "void test() { if (1) [[{}]] else {} }",
   "void test() { if (1) ; else {} }");
 }
+
+TEST_P(MutationTest, Parenthesize_RHS) {
+  CheckTransformation(ParenthesizeRHS, R"cpp(void test() { [[1 + 2]]; })cpp",
+  "void test() { 1 + (2); }");
+}
+
+TEST_P(MutationTest, Parenthesize_RHS_MACRO) {
+  CheckTransformation(ParenthesizeRHS, R"cpp(
+#define THENUMBER 42
+void test() {
+  [[1 + (THENUMBER)]];
+})cpp",
+  R"cpp(
+#define THENUMBER 42
+void test() {
+  1 + ((THENUMBER));
+})cpp");
+}
 } // namespace
Index: 

[PATCH] D89147: [SyntaxTree] Improve the signature of `replaceChildRangeLowLevel`.

2020-10-10 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas updated this revision to Diff 297396.
eduucaldas added a comment.

Fix whitespacing


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89147

Files:
  clang/include/clang/Tooling/Syntax/Tree.h
  clang/lib/Tooling/Syntax/Mutations.cpp
  clang/lib/Tooling/Syntax/Tree.cpp

Index: clang/lib/Tooling/Syntax/Tree.cpp
===
--- clang/lib/Tooling/Syntax/Tree.cpp
+++ clang/lib/Tooling/Syntax/Tree.cpp
@@ -92,50 +92,84 @@
   this->FirstChild = Child;
 }
 
-void syntax::Tree::replaceChildRangeLowLevel(Node *BeforeBegin, Node *End,
- Node *New) {
-  assert(!BeforeBegin || BeforeBegin->Parent == this);
+std::vector>
+syntax::Tree::replaceChildRangeLowLevel(
+Node *BeforeBegin, Node *End,
+ArrayRef> NewRange) {
+  assert(!BeforeBegin || BeforeBegin->Parent == this &&
+ "`BeforeBegin` is not a child of `this`");
+  assert(!End || End->Parent == this && "`End` is not a child of `this`");
 
 #ifndef NDEBUG
-  for (auto *N = New; N; N = N->getNextSibling()) {
+  for (const auto  : NewRange) {
+auto *N = NodeAndRole.first;
 assert(N->Parent == nullptr);
-assert(N->getRole() != NodeRole::Detached && "Roles must be set");
-// FIXME: sanity-check the role.
+assert(N->getRole() == NodeRole::Detached && "Roles must not be set");
+
+auto Role = NodeAndRole.second;
+assert(Role != NodeRole::Detached);
   }
+
+  auto Reachable = [](Node *From, Node *N) {
+if (!N)
+  return true;
+for (auto *It = From; It; It = It->NextSibling)
+  if (It == N)
+return true;
+return false;
+  };
+  assert(Reachable(FirstChild, BeforeBegin) &&
+ "`BeforeBegin` is not reachable");
+  assert(Reachable(BeforeBegin ? BeforeBegin->NextSibling : FirstChild, End) &&
+ "`End` is not after `BeforeBegin`");
 #endif
 
-  // Detach old nodes.
-  for (auto *N = !BeforeBegin ? FirstChild : BeforeBegin->getNextSibling();
-   N != End;) {
+  auto GetBegin = [,  = this->FirstChild]() -> Node *& {
+return BeforeBegin ? BeforeBegin->NextSibling : FirstChild;
+  };
+
+  // Extract old nodes.
+  std::vector> ExtractedChildren;
+  for (auto *N = GetBegin(); N != End;) {
 auto *Next = N->NextSibling;
+ExtractedChildren.push_back({N, N->getRole()});
 
 N->setRole(NodeRole::Detached);
 N->Parent = nullptr;
 N->NextSibling = nullptr;
 if (N->Original)
-  traverse(N, [&](Node *C) { C->Original = false; });
+  traverse(N, [](Node *C) { C->Original = false; });
 
 N = Next;
   }
 
-  // Attach new nodes.
-  if (BeforeBegin)
-BeforeBegin->NextSibling = New ? New : End;
-  else
-FirstChild = New ? New : End;
+  // If any modification occurred mark them.
+  if (!ExtractedChildren.empty() || !NewRange.empty())
+for (auto *T = this; T && T->Original; T = T->Parent)
+  T->Original = false;
 
-  if (New) {
-auto *Last = New;
-for (auto *N = New; N != nullptr; N = N->getNextSibling()) {
-  Last = N;
-  N->Parent = this;
-}
-Last->NextSibling = End;
+  // Attach new children to the replaced range.
+
+  if (NewRange.empty()) {
+GetBegin() = End;
+return ExtractedChildren;
+  }
+  GetBegin() = NewRange.front().first;
+  NewRange.back().first->NextSibling = End;
+
+  for (const auto  : NewRange) {
+NodeAndRole.first->setRole(NodeAndRole.second);
+NodeAndRole.first->Parent = this;
+  }
+
+  for (const auto *It = NewRange.begin(); It != std::prev(NewRange.end());
+   ++It) {
+auto *Node = It->first;
+auto *Next = std::next(It)->first;
+Node->NextSibling = Next;
   }
 
-  // Mark the node as modified.
-  for (auto *T = this; T && T->Original; T = T->Parent)
-T->Original = false;
+  return ExtractedChildren;
 }
 
 namespace {
Index: clang/lib/Tooling/Syntax/Mutations.cpp
===
--- clang/lib/Tooling/Syntax/Mutations.cpp
+++ clang/lib/Tooling/Syntax/Mutations.cpp
@@ -23,6 +23,17 @@
 
 using namespace clang;
 
+static syntax::Node *findPrevious(syntax::Node *N) {
+  if (N->getParent()->getFirstChild() == N)
+return nullptr;
+  for (syntax::Node *C = N->getParent()->getFirstChild(); C != nullptr;
+   C = C->getNextSibling()) {
+if (C->getNextSibling() == N)
+  return C;
+  }
+  llvm_unreachable("could not find a child node");
+}
+
 // This class has access to the internals of tree nodes. Its sole purpose is to
 // define helpers that allow implementing the high-level mutation operations.
 class syntax::MutationsImpl {
@@ -30,14 +41,15 @@
   /// Add a new node with a specified role.
   static void addAfter(syntax::Node *Anchor, syntax::Node *New, NodeRole Role) {
 assert(Anchor != nullptr);
+assert(Anchor->Parent != nullptr);
 assert(New->Parent == nullptr);
 assert(New->NextSibling == 

[PATCH] D89147: [SyntaxTree] Improve the signature of `replaceChildRangeLowLevel`.

2020-10-10 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas updated this revision to Diff 297395.
eduucaldas added a comment.

Add role sanity-check. Introduce `GetBegin()`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89147

Files:
  clang/include/clang/Tooling/Syntax/Tree.h
  clang/lib/Tooling/Syntax/Mutations.cpp
  clang/lib/Tooling/Syntax/Tree.cpp

Index: clang/lib/Tooling/Syntax/Tree.cpp
===
--- clang/lib/Tooling/Syntax/Tree.cpp
+++ clang/lib/Tooling/Syntax/Tree.cpp
@@ -92,50 +92,84 @@
   this->FirstChild = Child;
 }
 
-void syntax::Tree::replaceChildRangeLowLevel(Node *BeforeBegin, Node *End,
- Node *New) {
-  assert(!BeforeBegin || BeforeBegin->Parent == this);
+std::vector>
+syntax::Tree::replaceChildRangeLowLevel(
+Node *BeforeBegin, Node *End,
+ArrayRef> NewRange) {
+  assert(!BeforeBegin || BeforeBegin->Parent == this &&
+ "`BeforeBegin` is not a child of `this`");
+  assert(!End || End->Parent == this && "`End` is not a child of `this`");
 
 #ifndef NDEBUG
-  for (auto *N = New; N; N = N->getNextSibling()) {
+  for (const auto  : NewRange) {
+auto *N = NodeAndRole.first;
 assert(N->Parent == nullptr);
-assert(N->getRole() != NodeRole::Detached && "Roles must be set");
-// FIXME: sanity-check the role.
+assert(N->getRole() == NodeRole::Detached && "Roles must not be set");
+
+auto Role = NodeAndRole.second;
+assert(Role != NodeRole::Detached);
   }
+
+  auto Reachable = [](Node *From, Node *N) {
+if (!N)
+  return true;
+for (auto *It = From; It; It = It->NextSibling)
+  if (It == N)
+return true;
+return false;
+  };
+  assert(Reachable(FirstChild, BeforeBegin) &&
+ "`BeforeBegin` is not reachable");
+  assert(Reachable(BeforeBegin ? BeforeBegin->NextSibling : FirstChild, End) &&
+ "`End` is not after `BeforeBegin`");
+
 #endif
 
-  // Detach old nodes.
-  for (auto *N = !BeforeBegin ? FirstChild : BeforeBegin->getNextSibling();
-   N != End;) {
+  auto GetBegin = [,  = this->FirstChild]() -> Node *& {
+return BeforeBegin ? BeforeBegin->NextSibling : FirstChild;
+  };
+
+  // Extract old nodes.
+  std::vector> ExtractedChildren;
+  for (auto *N = GetBegin(); N != End;) {
 auto *Next = N->NextSibling;
+ExtractedChildren.push_back({N, N->getRole()});
 
 N->setRole(NodeRole::Detached);
 N->Parent = nullptr;
 N->NextSibling = nullptr;
 if (N->Original)
-  traverse(N, [&](Node *C) { C->Original = false; });
+  traverse(N, [](Node *C) { C->Original = false; });
 
 N = Next;
   }
 
-  // Attach new nodes.
-  if (BeforeBegin)
-BeforeBegin->NextSibling = New ? New : End;
-  else
-FirstChild = New ? New : End;
+  // If any modification occurred mark this and its ancestors as modified.
+  if (!ExtractedChildren.empty() || !NewRange.empty())
+for (auto *T = this; T && T->Original; T = T->Parent)
+  T->Original = false;
 
-  if (New) {
-auto *Last = New;
-for (auto *N = New; N != nullptr; N = N->getNextSibling()) {
-  Last = N;
-  N->Parent = this;
-}
-Last->NextSibling = End;
+  // Attach new children to the replaced range.
+  if (NewRange.empty()) {
+GetBegin() = End;
+return ExtractedChildren;
+  }
+  GetBegin() = NewRange.front().first;
+  NewRange.back().first->NextSibling = End;
+
+  for (const auto  : NewRange) {
+NodeAndRole.first->setRole(NodeAndRole.second);
+NodeAndRole.first->Parent = this;
+  }
+
+  for (const auto *It = NewRange.begin(); It != std::prev(NewRange.end());
+   ++It) {
+auto *Node = It->first;
+auto *Next = std::next(It)->first;
+Node->NextSibling = Next;
   }
 
-  // Mark the node as modified.
-  for (auto *T = this; T && T->Original; T = T->Parent)
-T->Original = false;
+  return ExtractedChildren;
 }
 
 namespace {
Index: clang/lib/Tooling/Syntax/Mutations.cpp
===
--- clang/lib/Tooling/Syntax/Mutations.cpp
+++ clang/lib/Tooling/Syntax/Mutations.cpp
@@ -23,6 +23,17 @@
 
 using namespace clang;
 
+static syntax::Node *findPrevious(syntax::Node *N) {
+  if (N->getParent()->getFirstChild() == N)
+return nullptr;
+  for (syntax::Node *C = N->getParent()->getFirstChild(); C != nullptr;
+   C = C->getNextSibling()) {
+if (C->getNextSibling() == N)
+  return C;
+  }
+  llvm_unreachable("could not find a child node");
+}
+
 // This class has access to the internals of tree nodes. Its sole purpose is to
 // define helpers that allow implementing the high-level mutation operations.
 class syntax::MutationsImpl {
@@ -30,14 +41,15 @@
   /// Add a new node with a specified role.
   static void addAfter(syntax::Node *Anchor, syntax::Node *New, NodeRole Role) {
 assert(Anchor != nullptr);
+assert(Anchor->Parent != nullptr);
 

[PATCH] D89147: [SyntaxTree] Improve the signature of `replaceChildRangeLowLevel`.

2020-10-10 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas updated this revision to Diff 297389.
eduucaldas added a comment.

Add reachability assertions


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89147

Files:
  clang/include/clang/Tooling/Syntax/Tree.h
  clang/lib/Tooling/Syntax/Mutations.cpp
  clang/lib/Tooling/Syntax/Tree.cpp

Index: clang/lib/Tooling/Syntax/Tree.cpp
===
--- clang/lib/Tooling/Syntax/Tree.cpp
+++ clang/lib/Tooling/Syntax/Tree.cpp
@@ -92,50 +92,87 @@
   this->FirstChild = Child;
 }
 
-void syntax::Tree::replaceChildRangeLowLevel(Node *BeforeBegin, Node *End,
- Node *New) {
-  assert(!BeforeBegin || BeforeBegin->Parent == this);
+std::vector>
+syntax::Tree::replaceChildRangeLowLevel(
+Node *BeforeBegin, Node *End,
+ArrayRef> NewRange) {
+  assert(!BeforeBegin || BeforeBegin->Parent == this &&
+ "`BeforeBegin` is not a child of `this`");
+  assert(!End || End->Parent == this && "`End` is not a child of `this`");
 
 #ifndef NDEBUG
-  for (auto *N = New; N; N = N->getNextSibling()) {
+  for (const auto  : NewRange) {
+auto *N = NodeAndRole.first;
 assert(N->Parent == nullptr);
-assert(N->getRole() != NodeRole::Detached && "Roles must be set");
-// FIXME: sanity-check the role.
+assert(N->getRole() == NodeRole::Detached && "Roles must not be set");
   }
+
+  auto Reachable = [](Node *From, Node *N) {
+if (!N)
+  return true;
+for (auto *It = From; It; It = It->NextSibling)
+  if (It == N)
+return true;
+return false;
+  };
+  assert(Reachable(FirstChild, BeforeBegin) &&
+ "`BeforeBegin` is not reachable");
+  assert(Reachable(BeforeBegin ? BeforeBegin->NextSibling : FirstChild, End) &&
+ "`End` is not after `BeforeBegin`");
+
 #endif
 
-  // Detach old nodes.
-  for (auto *N = !BeforeBegin ? FirstChild : BeforeBegin->getNextSibling();
-   N != End;) {
+  // Extract children to be replaced.
+  std::vector> ExtractedChildren;
+  auto *Begin = BeforeBegin ? BeforeBegin->NextSibling : FirstChild;
+  for (auto *N = Begin; N != End;) {
 auto *Next = N->NextSibling;
+ExtractedChildren.push_back({N, N->getRole()});
 
 N->setRole(NodeRole::Detached);
 N->Parent = nullptr;
 N->NextSibling = nullptr;
+
 if (N->Original)
-  traverse(N, [&](Node *C) { C->Original = false; });
+  traverse(N, [](Node *C) { C->Original = false; });
 
 N = Next;
   }
 
-  // Attach new nodes.
-  if (BeforeBegin)
-BeforeBegin->NextSibling = New ? New : End;
-  else
-FirstChild = New ? New : End;
+  // If any modification occurred mark this and its ancestors as modified.
+  if (!ExtractedChildren.empty() || !NewRange.empty())
+for (auto *T = this; T && T->Original; T = T->Parent)
+  T->Original = false;
 
-  if (New) {
-auto *Last = New;
-for (auto *N = New; N != nullptr; N = N->getNextSibling()) {
-  Last = N;
-  N->Parent = this;
-}
-Last->NextSibling = End;
+  if (NewRange.empty()) {
+BeforeBegin->NextSibling = End;
+return ExtractedChildren;
   }
 
-  // Mark the node as modified.
-  for (auto *T = this; T && T->Original; T = T->Parent)
-T->Original = false;
+  // `NewRange` becomes children of this Tree.
+  for (const auto  : NewRange) {
+NodeAndRole.first->setRole(NodeAndRole.second);
+NodeAndRole.first->Parent = this;
+  }
+
+  // `NewRange` nodes are siblings.
+  for (const auto *It = NewRange.begin(); It != std::prev(NewRange.end());
+   ++It) {
+auto *Node = It->first;
+auto *Next = std::next(It)->first;
+Node->NextSibling = Next;
+  }
+  // Attach new children to the end of the replaced range.
+  NewRange.back().first->NextSibling = End;
+
+  // New children are now the beginning of the replaced range.
+  auto *NewBegin = NewRange.front().first;
+  if (BeforeBegin)
+BeforeBegin->NextSibling = NewBegin;
+  else
+FirstChild = NewBegin;
+
+  return ExtractedChildren;
 }
 
 namespace {
Index: clang/lib/Tooling/Syntax/Mutations.cpp
===
--- clang/lib/Tooling/Syntax/Mutations.cpp
+++ clang/lib/Tooling/Syntax/Mutations.cpp
@@ -23,6 +23,17 @@
 
 using namespace clang;
 
+static syntax::Node *findPrevious(syntax::Node *N) {
+  if (N->getParent()->getFirstChild() == N)
+return nullptr;
+  for (syntax::Node *C = N->getParent()->getFirstChild(); C != nullptr;
+   C = C->getNextSibling()) {
+if (C->getNextSibling() == N)
+  return C;
+  }
+  llvm_unreachable("could not find a child node");
+}
+
 // This class has access to the internals of tree nodes. Its sole purpose is to
 // define helpers that allow implementing the high-level mutation operations.
 class syntax::MutationsImpl {
@@ -30,14 +41,15 @@
   /// Add a new node with a specified role.
   static void addAfter(syntax::Node 

[PATCH] D87547: [MinGW][clang-shlib] Build by default on MinGW

2020-10-10 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo added a comment.

In D87547#2322900 , @mati865 wrote:

> With `-DLLVM_ENABLE_ASSERTIONS=ON -DCMAKE_C_COMPILER=clang 
> -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_RANLIB_COMPILER=llvm-ranlib 
> -DCMAKE_AR_COMPILER=llvm-ar -DCMAKE_LINKER=ld.lld -DLLVM_ENABLE_LLD=ON` 
> libclang-cpp.dll has 65535 exports, seems it got truncated?

Older versions of lld didn't error out if exceeding the limit, this is fixed in 
D86701 , unfortunately after the 11 branch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87547

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


[PATCH] D87528: Enable '#pragma STDC FENV_ACCESS' in frontend cf. D69272 - Work in Progress

2020-10-10 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

The GCC docs seem pretty clear that `-frounding-math` is meant to allow dynamic 
access to the FP environment.  There might be optimizations that are perfectly 
legal with a constant but non-default rounding mode, and there might be some 
flag that only implies that weaker constraint, but `-frounding-math` needs to 
turn `FENV_ACCESS` on by default.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87528

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