[PATCH] D85031: [builtins] Unify the softfloat division implementation

2020-08-20 Thread Serge Pavlov via Phabricator via cfe-commits
sepavloff added inline comments.



Comment at: compiler-rt/lib/builtins/fp_div_impl.inc:99
+  //   0 < x0(b) < 1
+  //   abs(x0(b) - 1/b) <= 3/4 - 1/sqrt(2)
+

atrosinenko wrote:
> sepavloff wrote:
> > This estimation is absent from the original comment. Do you have reference 
> > where it came from? Also the original comment states `This is accurate to 
> > about 3.5 binary digits`. Is still true? If yes, it could be worth copying 
> > here.
> This approximation was deduced by writing down the derivative of `f ` "in 
> infinite precision" and finding its root. Then the values of `f` applied to 
> its root, 1.0 and 2.0 were calculated -- as far as I remember, **all of 
> them** were `3/4 - 1/sqrt(2)` or negated - //this is what "minimax 
> polynomial" probably means, that term was just copied from the original 
> implementation :)//.
IIUC, you don't want to put this statement here because you are us not sure it 
is true? Sounds reasonable.



Comment at: compiler-rt/lib/builtins/fp_div_impl.inc:109
+
+#if NUMBER_OF_HALF_ITERATIONS > 0
+  // Starting with (n-1) half-width iterations

atrosinenko wrote:
> sepavloff wrote:
> > It is good optimization. Could you please put a comment shortly describing 
> > the idea of using half-sized temporaries?
> The idea is just "I guess this takes less CPU time and I have managed to 
> prove error bounds for it". :) Specifically, for float128, the rep_t * rep_t 
> multiplication will be emulated with lots of CPU instructions while the lower 
> half contain some noise at that point. This particular optimization did exist 
> in the original implementation for float64 and float128. For float32 it had 
> not much sense, I guess. Still, estimations were calculated for the case of 
> float32 with half-size iterations as it may be useful for MSP430 and other 
> 16-bit targets.
The idea is clear but it require some study of the sources. I would propose to 
add a comment saying:
```
At the first iterations number of significant digits is small, so we may use 
shorter type values. Operations on them are usually faster.
```
or something like that.



Comment at: compiler-rt/lib/builtins/fp_div_impl.inc:130
+// Cannot overflow by construction and is larger than 2 - b*x by at most 
1*Ulp.
+half_rep_t corr_UQ1_hw = 0 /* = 2 */ - ((rep_t)x_UQ0_hw * b_UQ1_hw >> HW);
+// Would be at most [1.]0 after overflow if rounding (0 - x_UQ0_hw * 
b_UQ1_hw) down.

atrosinenko wrote:
> sepavloff wrote:
> > It would be better to put short comment to explain using 0 instead of 2.
> Agree, it was expected to be something like `/* = 2.0 in UQ1.(HW-1) */`. 
> Naming things is especially painful here...
2.0 cannot be represented in UQ1.X. I would add comment line like:
```
Due to wrapping 2.0 in UQ1.X is equivalent to 0.
```
or something similar.



Comment at: compiler-rt/lib/builtins/fp_div_impl.inc:184
+  // x_UQ0 * b_UQ1 = (x_UQ0_hw * 2^HW) * (b_UQ1_hw * 2^HW + blo) - b_UQ1
+  rep_t corr_UQ1 = 0 - (   (rep_t)x_UQ0_hw * b_UQ1_hw
++ ((rep_t)x_UQ0_hw * blo >> HW)

atrosinenko wrote:
> sepavloff wrote:
> > `x_UQ0_hw` and `b_UQ1_hw` are declared inside the conditional block `#if 
> > NUMBER_OF_HALF_ITERATIONS > 0`. Does `NUMBER_OF_FULL_ITERATIONS != 1` 
> > always imply `NUMBER_OF_HALF_ITERATIONS > 0 `?
> > Does NUMBER_OF_FULL_ITERATIONS != 1 always imply NUMBER_OF_HALF_ITERATIONS 
> > > 0 ?
> 
> Hmm... It should imply `== 0`, at first glance... Generally, total number of 
> iterations should be 3 for f32, 4 for f64 and 5 for f128. Then, error bounds 
> are calculated. There are generally only two modes: n-1 half-size iteration + 
> 1 full-size iteration OR n full-size iteration (as one generally has no 
> performance gains from using 16x16-bit multiplications on one hand, and that 
> particular case turned out to require extra rounding, on the other).
I have concern that `x_UQ0_hw` and `x_UQ1_hw` are declared in the block with 
condition `NUMBER_OF_HALF_ITERATIONS > 0` but uses in the other block with 
condition `!USE_NATIVE_FULL_ITERATIONS && NUMBER_OF_HALF_ITERATIONS > 0`, so 
probably there may be a combination of the macros when the variables are used 
but not declared. Maybe it is impossible due to some reason, in this case a 
proper check may be put into the block `#ifdef USE_NATIVE_FULL_ITERATIONS` 
which asserts that `NUMBER_OF_HALF_ITERATIONS > 0`. Otherwise `x_UQ0_hw` and 
`x_UQ1_hw` need to be moved out of the conditional block.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85031

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


[PATCH] D85324: [SystemZ][z/OS] Add z/OS Target and define macros

2020-08-20 Thread Hubert Tong via Phabricator via cfe-commits
hubert.reinterpretcast added inline comments.



Comment at: clang/lib/Basic/Targets/OSTargets.h:743
+Builder.defineMacro("__BFP__");
+// FIXME: __BOOL__ should be defined under strict -std=c89.
+Builder.defineMacro("__BOOL__");

MaskRay wrote:
> What is strict -std=c89? `!Opts.C99` ?
The comment has a typo. The macro should //not// be defined with strict C89 
modes.

> What is strict -std=c89? `!Opts.C99` ?

In the context of this macro, "strict C89" means `!Opts.C99` and the severity 
of `ext_c99_feature` diagnostics is at least an error. This occurs, for 
example, with `-std=gnu89 -Werror=c99-extensions`.



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85324

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


[PATCH] D86329: Fix spelling errors in the doc

2020-08-20 Thread YangZhihui via Phabricator via cfe-commits
YangZhihui created this revision.
YangZhihui added reviewers: rsmith, craig.topper.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
YangZhihui requested review of this revision.

Fix some spelling error in the doc


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D86329

Files:
  clang/docs/ClangCommandLineReference.rst


Index: clang/docs/ClangCommandLineReference.rst
===
--- clang/docs/ClangCommandLineReference.rst
+++ clang/docs/ClangCommandLineReference.rst
@@ -734,7 +734,7 @@
 
 .. option:: -emit-interface-stubs
 
-Generate Inteface Stub Files.
+Generate Interface Stub Files.
 
 .. option:: -emit-llvm
 
@@ -2136,7 +2136,7 @@
 
 .. option:: -fstack-protector, -fno-stack-protector
 
-Enable stack protectors for some functions vulnerable to stack smashing. This 
uses a loose heuristic which considers functions vulnerable if they contain a 
char (or 8bit integer) array or constant sized calls to alloca , which are of 
greater size than ssp-buffer-size (default: 8 bytes). All variable sized calls 
to alloca are considered vulnerable. A function witha stack protector has a 
guard value added to the stack frame that is checked on function exit. The 
guard value must be positioned in the stack frame such that a buffer overflow 
from a vulnerable variable will overwrite the guard value before overwriting 
the function's return address. The reference stack guard value is stored in a 
global variable.
+Enable stack protectors for some functions vulnerable to stack smashing. This 
uses a loose heuristic which considers functions vulnerable if they contain a 
char (or 8bit integer) array or constant sized calls to alloca , which are of 
greater size than ssp-buffer-size (default: 8 bytes). All variable sized calls 
to alloca are considered vulnerable. A function with a stack protector has a 
guard value added to the stack frame that is checked on function exit. The 
guard value must be positioned in the stack frame such that a buffer overflow 
from a vulnerable variable will overwrite the guard value before overwriting 
the function's return address. The reference stack guard value is stored in a 
global variable.
 
 .. option:: -fstack-protector-all
 


Index: clang/docs/ClangCommandLineReference.rst
===
--- clang/docs/ClangCommandLineReference.rst
+++ clang/docs/ClangCommandLineReference.rst
@@ -734,7 +734,7 @@
 
 .. option:: -emit-interface-stubs
 
-Generate Inteface Stub Files.
+Generate Interface Stub Files.
 
 .. option:: -emit-llvm
 
@@ -2136,7 +2136,7 @@
 
 .. option:: -fstack-protector, -fno-stack-protector
 
-Enable stack protectors for some functions vulnerable to stack smashing. This uses a loose heuristic which considers functions vulnerable if they contain a char (or 8bit integer) array or constant sized calls to alloca , which are of greater size than ssp-buffer-size (default: 8 bytes). All variable sized calls to alloca are considered vulnerable. A function witha stack protector has a guard value added to the stack frame that is checked on function exit. The guard value must be positioned in the stack frame such that a buffer overflow from a vulnerable variable will overwrite the guard value before overwriting the function's return address. The reference stack guard value is stored in a global variable.
+Enable stack protectors for some functions vulnerable to stack smashing. This uses a loose heuristic which considers functions vulnerable if they contain a char (or 8bit integer) array or constant sized calls to alloca , which are of greater size than ssp-buffer-size (default: 8 bytes). All variable sized calls to alloca are considered vulnerable. A function with a stack protector has a guard value added to the stack frame that is checked on function exit. The guard value must be positioned in the stack frame such that a buffer overflow from a vulnerable variable will overwrite the guard value before overwriting the function's return address. The reference stack guard value is stored in a global variable.
 
 .. option:: -fstack-protector-all
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D86295: [analyzer] Reorder the layout of MemRegion and cache by hand for optimal size

2020-08-20 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

Heh, nice! Did you try to measure the actual impact of this change on memory 
and/or performance?

I think it'd make perfect sense to keep the offset in a side map. We don't 
compute it for all regions, and for most regions it doesn't need to be computed 
*at all*.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86295

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


[PATCH] D86218: Teach the swift calling convention about _Atomic types

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

Please do this as a very late check rather than the first check.

You need to check for extra atomic padding.  If there's any difference between 
the sizes of the atomic type and its element, just add it as opaque data.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86218

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


[PATCH] D86156: [BFI] Preserve BFI information through loop passes via VH callbacks inside LoopStandardAnalysisResults

2020-08-20 Thread Alina Sbirlea via Phabricator via cfe-commits
asbirlea requested changes to this revision.
asbirlea added a comment.
This revision now requires changes to proceed.

A couple of quick comments, I haven't gone into details yet.

- please split off the changes that are NFCs (deleted spaces) and clang-format 
for ease to review.
- the test changes show a lot of dependencies that overload the loop pipeline. 
If only LICM benefits from it, I'd consider creating a BFI instance for the 
duration of the LICM pass, or only enabling it in loop pipelines that have LICM 
in them (see example comment in one of the tests).




Comment at: llvm/include/llvm/Transforms/Scalar/LoopPassManager.h:278
AM.getResult(F),
+   
(F),
MSSA};

This should not be unconditional. See MSSA approach.



Comment at: llvm/test/Transforms/LoopRotate/pr35210.ll:51
+; MSSA-NEXT: Running analysis: BlockFrequencyAnalysis on f
+; MSSA-NEXT: Running analysis: BranchProbabilityAnalysis on f
 ; MSSA-NEXT: Running analysis: InnerAnalysisManagerProxy{{.*}} on f

e.g. there's no use of creating these for LoopRotate.


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

https://reviews.llvm.org/D86156

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


[clang] fe86dbb - [clang]: Remove assertion which checks explicit declaration

2020-08-20 Thread Richard Smith via cfe-commits

Author: Gousemoodhin Nadaf
Date: 2020-08-20T18:15:43-07:00
New Revision: fe86dbb32da21e1c8c6eb4864a00f61ed3d003a3

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

LOG: [clang]:  Remove assertion which checks explicit declaration

explicit keyword is declared outside of class is invalid, invalid explicit 
declaration is handled inside DiagnoseFunctionSpecifiers() function. To avoid 
compiler crash in case of invalid explicit declaration, remove assertion.

Reviewed By: rsmith

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

Added: 
clang/test/Misc/explicit.cpp

Modified: 
clang/lib/Sema/DeclSpec.cpp

Removed: 




diff  --git a/clang/lib/Sema/DeclSpec.cpp b/clang/lib/Sema/DeclSpec.cpp
index f553b5ca6079..a3f770bb00ad 100644
--- a/clang/lib/Sema/DeclSpec.cpp
+++ b/clang/lib/Sema/DeclSpec.cpp
@@ -1014,9 +1014,6 @@ bool DeclSpec::setFunctionSpecExplicit(SourceLocation Loc,
const char *, unsigned ,
ExplicitSpecifier ExplicitSpec,
SourceLocation CloseParenLoc) {
-  assert((ExplicitSpec.getKind() == ExplicitSpecKind::ResolvedTrue ||
-  ExplicitSpec.getExpr()) &&
- "invalid ExplicitSpecifier");
   // 'explicit explicit' is ok, but warn as this is likely not what the user
   // intended.
   if (hasExplicitSpecifier()) {

diff  --git a/clang/test/Misc/explicit.cpp b/clang/test/Misc/explicit.cpp
new file mode 100644
index ..b544fc437f05
--- /dev/null
+++ b/clang/test/Misc/explicit.cpp
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -std=c++20 %s -verify
+
+int foo ()  {
+  int b;
+  explicit( && b );  // expected-error{{conversion from 'void *' to 'bool' is 
not allowed in a converted constant expression}}
+ // expected-error@-1{{'explicit' can only appear on 
non-static member functions}}
+ // expected-error@-2{{use of undeclared label 'b'}}
+ // expected-warning@-3{{declaration does not declare 
anything}}
+}



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


[PATCH] D83929: [clang]: Remove assertion which checks explicit declaration

2020-08-20 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGfe86dbb32da2: [clang]:  Remove assertion which checks 
explicit declaration (authored by gousemoodhin, committed by rsmith).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83929

Files:
  clang/lib/Sema/DeclSpec.cpp
  clang/test/Misc/explicit.cpp


Index: clang/test/Misc/explicit.cpp
===
--- /dev/null
+++ clang/test/Misc/explicit.cpp
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -std=c++20 %s -verify
+
+int foo ()  {
+  int b;
+  explicit( && b );  // expected-error{{conversion from 'void *' to 'bool' is 
not allowed in a converted constant expression}}
+ // expected-error@-1{{'explicit' can only appear on 
non-static member functions}}
+ // expected-error@-2{{use of undeclared label 'b'}}
+ // expected-warning@-3{{declaration does not declare 
anything}}
+}
Index: clang/lib/Sema/DeclSpec.cpp
===
--- clang/lib/Sema/DeclSpec.cpp
+++ clang/lib/Sema/DeclSpec.cpp
@@ -1014,9 +1014,6 @@
const char *, unsigned ,
ExplicitSpecifier ExplicitSpec,
SourceLocation CloseParenLoc) {
-  assert((ExplicitSpec.getKind() == ExplicitSpecKind::ResolvedTrue ||
-  ExplicitSpec.getExpr()) &&
- "invalid ExplicitSpecifier");
   // 'explicit explicit' is ok, but warn as this is likely not what the user
   // intended.
   if (hasExplicitSpecifier()) {


Index: clang/test/Misc/explicit.cpp
===
--- /dev/null
+++ clang/test/Misc/explicit.cpp
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -std=c++20 %s -verify
+
+int foo ()  {
+  int b;
+  explicit( && b );  // expected-error{{conversion from 'void *' to 'bool' is not allowed in a converted constant expression}}
+ // expected-error@-1{{'explicit' can only appear on non-static member functions}}
+ // expected-error@-2{{use of undeclared label 'b'}}
+ // expected-warning@-3{{declaration does not declare anything}}
+}
Index: clang/lib/Sema/DeclSpec.cpp
===
--- clang/lib/Sema/DeclSpec.cpp
+++ clang/lib/Sema/DeclSpec.cpp
@@ -1014,9 +1014,6 @@
const char *, unsigned ,
ExplicitSpecifier ExplicitSpec,
SourceLocation CloseParenLoc) {
-  assert((ExplicitSpec.getKind() == ExplicitSpecKind::ResolvedTrue ||
-  ExplicitSpec.getExpr()) &&
- "invalid ExplicitSpecifier");
   // 'explicit explicit' is ok, but warn as this is likely not what the user
   // intended.
   if (hasExplicitSpecifier()) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D80263: [HeaderSearch] Fix processing #import-ed headers multiple times with modules enabled.

2020-08-20 Thread Volodymyr Sapsai via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG7ac737e56bee: [HeaderSearch] Fix processing #import-ed 
headers multiple times with modules… (authored by vsapsai).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80263

Files:
  clang/lib/Lex/HeaderSearch.cpp
  
clang/test/Modules/Inputs/import-once/ImportOnce.framework/Headers/ImportOnce.h
  
clang/test/Modules/Inputs/import-once/ImportOnce.framework/Modules/module.modulemap
  
clang/test/Modules/Inputs/import-once/IndirectImporter.framework/Headers/IndirectImporter.h
  
clang/test/Modules/Inputs/import-once/IndirectImporter.framework/Modules/module.modulemap
  clang/test/Modules/Inputs/import-once/Unrelated.framework/Headers/Unrelated.h
  
clang/test/Modules/Inputs/import-once/Unrelated.framework/Modules/module.modulemap
  clang/test/Modules/import-once.m

Index: clang/test/Modules/import-once.m
===
--- /dev/null
+++ clang/test/Modules/import-once.m
@@ -0,0 +1,15 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fmodules -fmodule-name=ImportOnce -fimplicit-module-maps -fmodules-cache-path=%t -F %S/Inputs/import-once %s
+
+// Test #import-ed headers are processed only once, even without header guards.
+// Dependency graph is
+//
+// Unrelated   ImportOnce
+//   ^  ^^
+//\/ |
+//   IndirectImporter|
+// ^ |
+//  \|
+//   import-once.m
+#import 
+#import 
Index: clang/test/Modules/Inputs/import-once/Unrelated.framework/Modules/module.modulemap
===
--- /dev/null
+++ clang/test/Modules/Inputs/import-once/Unrelated.framework/Modules/module.modulemap
@@ -0,0 +1,4 @@
+framework module Unrelated {
+umbrella header "Unrelated.h"
+export *
+}
Index: clang/test/Modules/Inputs/import-once/Unrelated.framework/Headers/Unrelated.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/import-once/Unrelated.framework/Headers/Unrelated.h
@@ -0,0 +1 @@
+void foo(void);
Index: clang/test/Modules/Inputs/import-once/IndirectImporter.framework/Modules/module.modulemap
===
--- /dev/null
+++ clang/test/Modules/Inputs/import-once/IndirectImporter.framework/Modules/module.modulemap
@@ -0,0 +1,4 @@
+framework module IndirectImporter {
+umbrella header "IndirectImporter.h"
+export *
+}
Index: clang/test/Modules/Inputs/import-once/IndirectImporter.framework/Headers/IndirectImporter.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/import-once/IndirectImporter.framework/Headers/IndirectImporter.h
@@ -0,0 +1,2 @@
+#import 
+#import 
Index: clang/test/Modules/Inputs/import-once/ImportOnce.framework/Modules/module.modulemap
===
--- /dev/null
+++ clang/test/Modules/Inputs/import-once/ImportOnce.framework/Modules/module.modulemap
@@ -0,0 +1,4 @@
+framework module ImportOnce {
+  umbrella header "ImportOnce.h"
+  export *
+}
Index: clang/test/Modules/Inputs/import-once/ImportOnce.framework/Headers/ImportOnce.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/import-once/ImportOnce.framework/Headers/ImportOnce.h
@@ -0,0 +1,5 @@
+// No header guards on purpose.
+
+enum SomeSimpleEnum {
+SomeSimpleEnumCase,
+};
Index: clang/lib/Lex/HeaderSearch.cpp
===
--- clang/lib/Lex/HeaderSearch.cpp
+++ clang/lib/Lex/HeaderSearch.cpp
@@ -1167,12 +1167,12 @@
   HeaderFileInfo *HFI = [FE->getUID()];
   // FIXME: Use a generation count to check whether this is really up to date.
   if (ExternalSource && !HFI->Resolved) {
-HFI->Resolved = true;
 auto ExternalHFI = ExternalSource->GetHeaderFileInfo(FE);
-
-HFI = [FE->getUID()];
-if (ExternalHFI.External)
-  mergeHeaderFileInfo(*HFI, ExternalHFI);
+if (ExternalHFI.IsValid) {
+  HFI->Resolved = true;
+  if (ExternalHFI.External)
+mergeHeaderFileInfo(*HFI, ExternalHFI);
+}
   }
 
   HFI->IsValid = true;
@@ -1199,12 +1199,12 @@
 if (!WantExternal && (!HFI->IsValid || HFI->External))
   return nullptr;
 if (!HFI->Resolved) {
-  HFI->Resolved = true;
   auto ExternalHFI = ExternalSource->GetHeaderFileInfo(FE);
-
-  HFI = [FE->getUID()];
-  if (ExternalHFI.External)
-mergeHeaderFileInfo(*HFI, ExternalHFI);
+  if (ExternalHFI.IsValid) {
+HFI->Resolved = true;
+if (ExternalHFI.External)
+  mergeHeaderFileInfo(*HFI, ExternalHFI);
+  }
 }
   } else if (FE->getUID() >= FileInfo.size()) {
 return 

[clang] 7ac737e - [HeaderSearch] Fix processing #import-ed headers multiple times with modules enabled.

2020-08-20 Thread Volodymyr Sapsai via cfe-commits

Author: Volodymyr Sapsai
Date: 2020-08-20T17:41:28-07:00
New Revision: 7ac737e56bee721fb3535006140362c6e08726bb

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

LOG: [HeaderSearch] Fix processing #import-ed headers multiple times with 
modules enabled.

HeaderSearch was marking requested HeaderFileInfo as Resolved only based on
the presence of ExternalSource. As the result, using any module was enough
to set ExternalSource and headers unknown to this module would have
HeaderFileInfo with empty fields, including `isImport = 0`, `NumIncludes = 0`.
Such HeaderFileInfo was preserved without changes regardless of how the
header was used in other modules and caused incorrect result in
`HeaderSearch::ShouldEnterIncludeFile`.

Fix by marking HeaderFileInfo as Resolved only if ExternalSource knows
about this header.

rdar://problem/62126911

Reviewed By: bruno

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

Added: 

clang/test/Modules/Inputs/import-once/ImportOnce.framework/Headers/ImportOnce.h

clang/test/Modules/Inputs/import-once/ImportOnce.framework/Modules/module.modulemap

clang/test/Modules/Inputs/import-once/IndirectImporter.framework/Headers/IndirectImporter.h

clang/test/Modules/Inputs/import-once/IndirectImporter.framework/Modules/module.modulemap

clang/test/Modules/Inputs/import-once/Unrelated.framework/Headers/Unrelated.h

clang/test/Modules/Inputs/import-once/Unrelated.framework/Modules/module.modulemap
clang/test/Modules/import-once.m

Modified: 
clang/lib/Lex/HeaderSearch.cpp

Removed: 




diff  --git a/clang/lib/Lex/HeaderSearch.cpp b/clang/lib/Lex/HeaderSearch.cpp
index 1df28cc07209..3fd43e0e3aad 100644
--- a/clang/lib/Lex/HeaderSearch.cpp
+++ b/clang/lib/Lex/HeaderSearch.cpp
@@ -1167,12 +1167,12 @@ HeaderFileInfo ::getFileInfo(const 
FileEntry *FE) {
   HeaderFileInfo *HFI = [FE->getUID()];
   // FIXME: Use a generation count to check whether this is really up to date.
   if (ExternalSource && !HFI->Resolved) {
-HFI->Resolved = true;
 auto ExternalHFI = ExternalSource->GetHeaderFileInfo(FE);
-
-HFI = [FE->getUID()];
-if (ExternalHFI.External)
-  mergeHeaderFileInfo(*HFI, ExternalHFI);
+if (ExternalHFI.IsValid) {
+  HFI->Resolved = true;
+  if (ExternalHFI.External)
+mergeHeaderFileInfo(*HFI, ExternalHFI);
+}
   }
 
   HFI->IsValid = true;
@@ -1199,12 +1199,12 @@ HeaderSearch::getExistingFileInfo(const FileEntry *FE,
 if (!WantExternal && (!HFI->IsValid || HFI->External))
   return nullptr;
 if (!HFI->Resolved) {
-  HFI->Resolved = true;
   auto ExternalHFI = ExternalSource->GetHeaderFileInfo(FE);
-
-  HFI = [FE->getUID()];
-  if (ExternalHFI.External)
-mergeHeaderFileInfo(*HFI, ExternalHFI);
+  if (ExternalHFI.IsValid) {
+HFI->Resolved = true;
+if (ExternalHFI.External)
+  mergeHeaderFileInfo(*HFI, ExternalHFI);
+  }
 }
   } else if (FE->getUID() >= FileInfo.size()) {
 return nullptr;

diff  --git 
a/clang/test/Modules/Inputs/import-once/ImportOnce.framework/Headers/ImportOnce.h
 
b/clang/test/Modules/Inputs/import-once/ImportOnce.framework/Headers/ImportOnce.h
new file mode 100644
index ..02e3e76bf9e8
--- /dev/null
+++ 
b/clang/test/Modules/Inputs/import-once/ImportOnce.framework/Headers/ImportOnce.h
@@ -0,0 +1,5 @@
+// No header guards on purpose.
+
+enum SomeSimpleEnum {
+SomeSimpleEnumCase,
+};

diff  --git 
a/clang/test/Modules/Inputs/import-once/ImportOnce.framework/Modules/module.modulemap
 
b/clang/test/Modules/Inputs/import-once/ImportOnce.framework/Modules/module.modulemap
new file mode 100644
index ..df12c237818e
--- /dev/null
+++ 
b/clang/test/Modules/Inputs/import-once/ImportOnce.framework/Modules/module.modulemap
@@ -0,0 +1,4 @@
+framework module ImportOnce {
+  umbrella header "ImportOnce.h"
+  export *
+}

diff  --git 
a/clang/test/Modules/Inputs/import-once/IndirectImporter.framework/Headers/IndirectImporter.h
 
b/clang/test/Modules/Inputs/import-once/IndirectImporter.framework/Headers/IndirectImporter.h
new file mode 100644
index ..46b989659457
--- /dev/null
+++ 
b/clang/test/Modules/Inputs/import-once/IndirectImporter.framework/Headers/IndirectImporter.h
@@ -0,0 +1,2 @@
+#import 
+#import 

diff  --git 
a/clang/test/Modules/Inputs/import-once/IndirectImporter.framework/Modules/module.modulemap
 
b/clang/test/Modules/Inputs/import-once/IndirectImporter.framework/Modules/module.modulemap
new file mode 100644
index ..ab5108077605
--- /dev/null
+++ 
b/clang/test/Modules/Inputs/import-once/IndirectImporter.framework/Modules/module.modulemap
@@ -0,0 +1,4 @@
+framework module IndirectImporter {
+umbrella header "IndirectImporter.h"
+export *

[PATCH] D80263: [HeaderSearch] Fix processing #import-ed headers multiple times with modules enabled.

2020-08-20 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai added a comment.

Thanks for the review.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80263

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


[clang] 7092398 - Improve pretty-printing for APValues of void type.

2020-08-20 Thread Richard Smith via cfe-commits

Author: Richard Smith
Date: 2020-08-20T17:14:22-07:00
New Revision: 70923983e54253723600eb2f4cdfb0fbb347a364

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

LOG: Improve pretty-printing for APValues of void type.

No functionality change intended: there doesn't seem to be any way to
cause Clang to print such a value, but they can show up when dumping
APValues from a debugger.

Added: 


Modified: 
clang/lib/AST/APValue.cpp

Removed: 




diff  --git a/clang/lib/AST/APValue.cpp b/clang/lib/AST/APValue.cpp
index f3828bb54c1d..2a8834b4db0c 100644
--- a/clang/lib/AST/APValue.cpp
+++ b/clang/lib/AST/APValue.cpp
@@ -388,6 +388,13 @@ static double GetApproxValue(const llvm::APFloat ) {
 
 void APValue::printPretty(raw_ostream , const ASTContext ,
   QualType Ty) const {
+  // There are no objects of type 'void', but values of this type can be
+  // returned from functions.
+  if (Ty->isVoidType()) {
+Out << "void()";
+return;
+  }
+
   switch (getKind()) {
   case APValue::None:
 Out << "";



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


[clang-tools-extra] efeb65d - Fix up clangd after Clang 038edf6029bafe70b1f7165abe2b0e61ddf506b3.

2020-08-20 Thread Richard Smith via cfe-commits

Author: Richard Smith
Date: 2020-08-20T16:36:25-07:00
New Revision: efeb65d53b88d9c3ac3a185c396efd8db8c9f7d9

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

LOG: Fix up clangd after Clang 038edf6029bafe70b1f7165abe2b0e61ddf506b3.

Now that Clang is able to constant-evaluate void-typed expressions,
disable showing hover-card values for them. It's not useful to say that
an expression cast to void has value '', even if we can
constant-evaluate it to that result!

Added: 


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

Removed: 




diff  --git a/clang-tools-extra/clangd/Hover.cpp 
b/clang-tools-extra/clangd/Hover.cpp
index 8305a4724035..ef9bb536005f 100644
--- a/clang-tools-extra/clangd/Hover.cpp
+++ b/clang-tools-extra/clangd/Hover.cpp
@@ -339,10 +339,11 @@ llvm::Optional printExprValue(const Expr *E,
   }
 
   // Evaluating [[foo]]() as "" isn't useful, and prevents us walking up
-  // to the enclosing call.
+  // to the enclosing call. Evaluating an expression of void type doesn't
+  // produce a meaningful result.
   QualType T = E->getType();
   if (T.isNull() || T->isFunctionType() || T->isFunctionPointerType() ||
-  T->isFunctionReferenceType())
+  T->isFunctionReferenceType() || T->isVoidType())
 return llvm::None;
 
   Expr::EvalResult Constant;
@@ -370,6 +371,10 @@ llvm::Optional printExprValue(const 
SelectionTree::Node *N,
   for (; N; N = N->Parent) {
 // Try to evaluate the first evaluatable enclosing expression.
 if (const Expr *E = N->ASTNode.get()) {
+  // Once we cross an expression of type 'cv void', the evaluated result
+  // has nothing to do with our original cursor position.
+  if (!E->getType().isNull() && E->getType()->isVoidType())
+break;
   if (auto Val = printExprValue(E, Ctx))
 return Val;
 } else if (N->ASTNode.get() || N->ASTNode.get()) {



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


[PATCH] D77925: Revert "[TLI] Per-function fveclib for math library used for vectorization"

2020-08-20 Thread Mehdi AMINI via Phabricator via cfe-commits
mehdi_amini added a comment.

Overall that would likely work for XLA. Something I'd like to mention though in 
response to:

> The veclib type is also tied to the accepted values for -fveclib, which is a 
> list of supported lib,

`-fveclib` is a Clang thing, it shouldn't limit what LLVM does. Of course LLVM 
needs to support Clang, but does not have to inherit the limitation of map 1:1 
to Clang UI.
In particular as a library, it isn't clear why we would make the choice to 
write LLVM VecLib support this way.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77925

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


[PATCH] D86277: [NFC][compiler-rt] Factor out __mulv[sdt]i3 implementations to .inc file

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



Comment at: compiler-rt/lib/builtins/int_mulv_impl.inc:1
-//===-- mulvdi3.c - Implement __mulvdi3 
---===//
+//===-- int_mulv_impl.inc - Implement __mulv[sdt]i3 
---===//
 //

`---*- C++ -*-===//`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86277

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


[PATCH] D85990: [Clang] Fix BZ47169, loader_uninitialized on incomplete types

2020-08-20 Thread Jon Chesterfield via Phabricator via cfe-commits
JonChesterfield added inline comments.



Comment at: clang/test/CodeGenCXX/attr-loader-uninitialized.cpp:34
+
+// CHECK: @templ_int = global %struct.templ undef, align 8
+templ templ_int [[clang::loader_uninitialized]];

This broke 32 bit builds where the pointer is not eight byte aligned. Patched 
by dropping the align from the filecheck pattern in 
3d82c9b6960afe50a76b8c23e9bc42c51d41e767. Credit to Luke Benes for reporting 
the error, thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85990

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


[clang] 3d82c9b - Fix 32 bit build broken by D85990 by dropping align from filecheck pattern

2020-08-20 Thread via cfe-commits

Author: JonChesterfield
Date: 2020-08-20T23:50:33+01:00
New Revision: 3d82c9b6960afe50a76b8c23e9bc42c51d41e767

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

LOG: Fix 32 bit build broken by D85990 by dropping align from filecheck pattern

Added: 


Modified: 
clang/test/CodeGenCXX/attr-loader-uninitialized.cpp

Removed: 




diff  --git a/clang/test/CodeGenCXX/attr-loader-uninitialized.cpp 
b/clang/test/CodeGenCXX/attr-loader-uninitialized.cpp
index 6501a25bf5bc..ec3e84b59023 100644
--- a/clang/test/CodeGenCXX/attr-loader-uninitialized.cpp
+++ b/clang/test/CodeGenCXX/attr-loader-uninitialized.cpp
@@ -31,12 +31,12 @@ double arr2 [[clang::loader_uninitialized]] [4];
 
 template struct templ{T * t;};
 
-// CHECK: @templ_int = global %struct.templ undef, align 8
+// CHECK: @templ_int = global %struct.templ undef
 templ templ_int [[clang::loader_uninitialized]];
 
-// CHECK: @templ_trivial = global %struct.templ.0 undef, align 8
+// CHECK: @templ_trivial = global %struct.templ.0 undef
 templ templ_trivial [[clang::loader_uninitialized]];
 
-// CHECK: @templ_incomplete = global %struct.templ.1 undef, align 8
+// CHECK: @templ_incomplete = global %struct.templ.1 undef
 struct incomplete;
 templ templ_incomplete [[clang::loader_uninitialized]];



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


[clang] 038edf6 - Don't reject uses of void-returning consteval functions.

2020-08-20 Thread Richard Smith via cfe-commits

Author: Richard Smith
Date: 2020-08-20T15:40:09-07:00
New Revision: 038edf6029bafe70b1f7165abe2b0e61ddf506b3

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

LOG: Don't reject uses of void-returning consteval functions.

Added: 


Modified: 
clang/lib/AST/ExprConstant.cpp
clang/test/SemaCXX/consteval-return-void.cpp

Removed: 




diff  --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 2c2dd6a3ef3a..b22797b5c3c0 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -2299,6 +2299,10 @@ static bool
 CheckConstantExpression(EvalInfo , SourceLocation DiagLoc, QualType Type,
 const APValue ,
 Expr::ConstExprUsage Usage = Expr::EvaluateForCodeGen) 
{
+  // Nothing to check for a constant expression of type 'cv void'.
+  if (Type->isVoidType())
+return true;
+
   CheckedTemporaries CheckedTemps;
   return CheckEvaluationResult(CheckEvaluationResultKind::ConstantExpression,
Info, DiagLoc, Type, Value, Usage,

diff  --git a/clang/test/SemaCXX/consteval-return-void.cpp 
b/clang/test/SemaCXX/consteval-return-void.cpp
index 39e1418306f5..da1fd8b7cdf7 100644
--- a/clang/test/SemaCXX/consteval-return-void.cpp
+++ b/clang/test/SemaCXX/consteval-return-void.cpp
@@ -18,3 +18,12 @@ template  constexpr E operator*(E,E);
 template  consteval E operator/(E,E);
 template <> constexpr E operator*(E,E) { return; } // expected-error 
{{non-void constexpr function 'operator*' should return a value}}
 template <> consteval E operator/(E,E) { return; } // expected-error 
{{non-void consteval function 'operator/' should return a value}}
+
+consteval void no_return() {}
+consteval void with_return() { return; }
+consteval void with_return_void() { return void(); }
+void use_void_fn() {
+  no_return();
+  with_return();
+  with_return_void();
+}



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


[PATCH] D86049: RFC: Implement optional exportable wrapper function generation for objc_direct methods.

2020-08-20 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi added a comment.

@lanza I did it as a CodeGen option for now because we don't want anything like 
this to be the default until the ABI is fleshed out.
I think one danger in altering the name of the function to some extent is you 
dont want to clash potentially with user defined C functions.

In D86049#2226507 , @lanza wrote:

>> This change provides a codegen options flag to clang 
>> -fobjc-export-direct-method-wrappers to generate the wrapper functions that 
>> begin with the prefix objc_direct_wrapper and are marked as 
>> attribute__((alwaysinline)). This way within a link unit the wrapper 
>> functions should be inlined away at their call sites, but across a dylib 
>> boundary the wrapper call is used.
>
> I think this needing a flag is a bit magical for what seems like such a 
> simple concept for the ObjC language. There shouldn't need to be a flag to 
> make it work properly.
>
> We have defined more-or-less non-`virtual` methods for ObjC with 
> `objc_direct`. The symbol visibility should behave as a reasonable developer 
> should expect and the front end should communicate it. Requiring a flag is 
> the compiler requiring the developer to understand compiler implementation 
> details for his iOS app to work properly. Currently, clang decides the 
> visibility is hidden but can't communicate this across library boundaries and 
> you end up with confusing link errors for the developer.
>
> There's two routes that make sense in my opinion: library private and class 
> private OR library public and class public.
>
> As per the ABI, I don't know of any reasons why `objc_direct` methods require 
> the standard ObjC `-[class method]` signature since they won't be 
> participating in any part of the ObjectiveC runtime. If that's the case,  a 
> proper underscored symbol name seems like the cleaning and most reasonable 
> fix.




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86049

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


[PATCH] D78902: [Driver] Add output file to properties of Command

2020-08-20 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

What's the advantage?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78902

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


[PATCH] D85528: [analyzer] Fix cast evaluation on scoped enums in ExprEngine

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

It would be nice to have this fix in clang11.
Do you think it's qualified for it?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85528

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


[PATCH] D86154: AMDGPU: Add llvm.amdgcn.{read,readfirst,write}lane2 intrinsics with type overloads

2020-08-20 Thread Nicolai Hähnle via Phabricator via cfe-commits
nhaehnle added a comment.

In D86154#2224272 , @arsenm wrote:

> In D86154#2224270 , @nhaehnle wrote:
>
>> Note that part of my motivation here over D84639 
>>  is to support more general types on the 
>> lane intrinsics, since they also express some semantic content which would 
>> be interesting to be able to express e.g. on descriptors. I wasn't able to 
>> bend the SelectionDAG type legalization to my will, so that's why I instead 
>> "legalize" the intrinsics in the AMDGPUCodeGenPrepare pass.
>
> Don't you just need to handle this in ReplaceNodeResults the same way?

ReplaceNodeResults expects the result type to be changed in semi-magical ways 
during vector type legalization, which is non-obvious since the method can be 
called from different places. I think it *could* be made to work with a lot of 
patience, but it's really a bad interface -- and besides, by doing it in IR we 
reduce code duplication between SelectionDAG and GlobalISel, which is an added 
benefit IMO.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86154

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


[PATCH] D86154: AMDGPU: Add llvm.amdgcn.{read,readfirst,write}lane2 intrinsics with type overloads

2020-08-20 Thread Nicolai Hähnle via Phabricator via cfe-commits
nhaehnle updated this revision to Diff 286898.
nhaehnle added a comment.

Don't duplicate the intrinsics. Rely on D86317 
 to reduce the pain of this
change caused to downstream users.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86154

Files:
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGenOpenCL/builtins-amdgcn.cl
  llvm/include/llvm/IR/IntrinsicsAMDGPU.td
  llvm/lib/Target/AMDGPU/AMDGPUAtomicOptimizer.cpp
  llvm/lib/Target/AMDGPU/AMDGPUCodeGenPrepare.cpp
  llvm/lib/Target/AMDGPU/AMDGPUInstCombineIntrinsic.cpp
  llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
  llvm/lib/Target/AMDGPU/SIInstructions.td
  llvm/test/CodeGen/AMDGPU/GlobalISel/inst-select-amdgcn.readfirstlane.mir
  llvm/test/CodeGen/AMDGPU/llvm.amdgcn.readfirstlane.ll
  llvm/test/CodeGen/AMDGPU/llvm.amdgcn.readlane.ll
  llvm/test/CodeGen/AMDGPU/llvm.amdgcn.writelane.ll
  llvm/test/Transforms/InstCombine/AMDGPU/amdgcn-intrinsics.ll

Index: llvm/test/Transforms/InstCombine/AMDGPU/amdgcn-intrinsics.ll
===
--- llvm/test/Transforms/InstCombine/AMDGPU/amdgcn-intrinsics.ll
+++ llvm/test/Transforms/InstCombine/AMDGPU/amdgcn-intrinsics.ll
@@ -2507,8 +2507,8 @@
 
 define amdgpu_kernel void @readfirstlane_constant(i32 %arg) {
 ; CHECK-LABEL: @readfirstlane_constant(
-; CHECK-NEXT:[[VAR:%.*]] = call i32 @llvm.amdgcn.readfirstlane(i32 [[ARG:%.*]])
-; CHECK-NEXT:store volatile i32 [[VAR]], i32* undef, align 4
+; CHECK-NEXT:[[TMP1:%.*]] = call i32 @llvm.amdgcn.readfirstlane.i32(i32 [[ARG:%.*]])
+; CHECK-NEXT:store volatile i32 [[TMP1]], i32* undef, align 4
 ; CHECK-NEXT:store volatile i32 0, i32* undef, align 4
 ; CHECK-NEXT:store volatile i32 123, i32* undef, align 4
 ; CHECK-NEXT:store volatile i32 ptrtoint (i32* @gv to i32), i32* undef, align 4
@@ -2530,8 +2530,8 @@
 
 define i32 @readfirstlane_idempotent(i32 %arg) {
 ; CHECK-LABEL: @readfirstlane_idempotent(
-; CHECK-NEXT:[[READ0:%.*]] = call i32 @llvm.amdgcn.readfirstlane(i32 [[ARG:%.*]])
-; CHECK-NEXT:ret i32 [[READ0]]
+; CHECK-NEXT:[[TMP1:%.*]] = call i32 @llvm.amdgcn.readfirstlane.i32(i32 [[ARG:%.*]])
+; CHECK-NEXT:ret i32 [[TMP1]]
 ;
   %read0 = call i32 @llvm.amdgcn.readfirstlane(i32 %arg)
   %read1 = call i32 @llvm.amdgcn.readfirstlane(i32 %read0)
@@ -2541,8 +2541,8 @@
 
 define i32 @readfirstlane_readlane(i32 %arg) {
 ; CHECK-LABEL: @readfirstlane_readlane(
-; CHECK-NEXT:[[READ0:%.*]] = call i32 @llvm.amdgcn.readfirstlane(i32 [[ARG:%.*]])
-; CHECK-NEXT:ret i32 [[READ0]]
+; CHECK-NEXT:[[TMP1:%.*]] = call i32 @llvm.amdgcn.readfirstlane.i32(i32 [[ARG:%.*]])
+; CHECK-NEXT:ret i32 [[TMP1]]
 ;
   %read0 = call i32 @llvm.amdgcn.readfirstlane(i32 %arg)
   %read1 = call i32 @llvm.amdgcn.readlane(i32 %read0, i32 0)
@@ -2552,11 +2552,11 @@
 define i32 @readfirstlane_readfirstlane_different_block(i32 %arg) {
 ; CHECK-LABEL: @readfirstlane_readfirstlane_different_block(
 ; CHECK-NEXT:  bb0:
-; CHECK-NEXT:[[READ0:%.*]] = call i32 @llvm.amdgcn.readfirstlane(i32 [[ARG:%.*]])
+; CHECK-NEXT:[[TMP0:%.*]] = call i32 @llvm.amdgcn.readfirstlane.i32(i32 [[ARG:%.*]])
 ; CHECK-NEXT:br label [[BB1:%.*]]
 ; CHECK:   bb1:
-; CHECK-NEXT:[[READ1:%.*]] = call i32 @llvm.amdgcn.readfirstlane(i32 [[READ0]])
-; CHECK-NEXT:ret i32 [[READ1]]
+; CHECK-NEXT:[[TMP1:%.*]] = call i32 @llvm.amdgcn.readfirstlane.i32(i32 [[TMP0]])
+; CHECK-NEXT:ret i32 [[TMP1]]
 ;
 bb0:
   %read0 = call i32 @llvm.amdgcn.readfirstlane(i32 %arg)
@@ -2570,11 +2570,11 @@
 define i32 @readfirstlane_readlane_different_block(i32 %arg) {
 ; CHECK-LABEL: @readfirstlane_readlane_different_block(
 ; CHECK-NEXT:  bb0:
-; CHECK-NEXT:[[READ0:%.*]] = call i32 @llvm.amdgcn.readlane(i32 [[ARG:%.*]], i32 0)
+; CHECK-NEXT:[[TMP0:%.*]] = call i32 @llvm.amdgcn.readlane.i32(i32 [[ARG:%.*]], i32 0)
 ; CHECK-NEXT:br label [[BB1:%.*]]
 ; CHECK:   bb1:
-; CHECK-NEXT:[[READ1:%.*]] = call i32 @llvm.amdgcn.readfirstlane(i32 [[READ0]])
-; CHECK-NEXT:ret i32 [[READ1]]
+; CHECK-NEXT:[[TMP1:%.*]] = call i32 @llvm.amdgcn.readfirstlane.i32(i32 [[TMP0]])
+; CHECK-NEXT:ret i32 [[TMP1]]
 ;
 bb0:
   %read0 = call i32 @llvm.amdgcn.readlane(i32 %arg, i32 0)
@@ -2585,6 +2585,41 @@
   ret i32 %read1
 }
 
+define i32 @readfirstlane_bitcast(float %arg) {
+; CHECK-LABEL: @readfirstlane_bitcast(
+; CHECK-NEXT:[[TMP1:%.*]] = call float @llvm.amdgcn.readfirstlane.f32(float [[ARG:%.*]])
+; CHECK-NEXT:[[TMP2:%.*]] = bitcast float [[TMP1]] to i32
+; CHECK-NEXT:ret i32 [[TMP2]]
+;
+  %bitcast.arg = bitcast float %arg to i32
+  %read = call i32 @llvm.amdgcn.readfirstlane(i32 %bitcast.arg)
+  ret i32 %read
+}
+
+define float @bitcast_readfirstlane_bitcast(float %arg) {
+; CHECK-LABEL: @bitcast_readfirstlane_bitcast(
+; CHECK-NEXT:[[TMP1:%.*]] = call float 

[clang] cff0db0 - [X86] Enable constexpr on POPCNT intrinsics (PR31446)

2020-08-20 Thread Simon Pilgrim via cfe-commits

Author: Simon Pilgrim
Date: 2020-08-20T21:38:04+01:00
New Revision: cff0db08761f310dfebb5b41b307d2c12bda85fc

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

LOG: [X86] Enable constexpr on POPCNT intrinsics (PR31446)

This is a first step patch to enable constexpr support and testing to a large 
number of x86 intrinsics.

All I've done here is provide a DEFAULT_FN_ATTRS_CONSTEXPR variant to our 
existing DEFAULT_FN_ATTRS tag approach that adds constexpr on c++ builds. The 
clang cuda headers do something similar.

I've started with POPCNT mainly as its tiny and are wrappers to generic 
__builtin_* intrinsics which already act as constexpr.

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Headers/popcntintrin.h
clang/test/CodeGen/popcnt-builtins.c

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 03eca8a26843..f97e95a55c0e 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -153,6 +153,12 @@ CUDA Support in Clang
 
 - ...
 
+X86 Support in Clang
+
+
+- The x86 intrinsics ``_mm_popcnt_u32`` and ``_mm_popcnt_u64`` may now be used
+  within constexpr expressions.
+
 Internal API Changes
 
 

diff  --git a/clang/lib/Headers/popcntintrin.h 
b/clang/lib/Headers/popcntintrin.h
index 312901014796..0aa94aecda5b 100644
--- a/clang/lib/Headers/popcntintrin.h
+++ b/clang/lib/Headers/popcntintrin.h
@@ -13,6 +13,12 @@
 /* Define the default attributes for the functions in this file. */
 #define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__, 
__target__("popcnt")))
 
+#if defined(__cplusplus) && (__cplusplus >= 201103L)
+#define __DEFAULT_FN_ATTRS_CONSTEXPR __DEFAULT_FN_ATTRS constexpr
+#else
+#define __DEFAULT_FN_ATTRS_CONSTEXPR __DEFAULT_FN_ATTRS
+#endif
+
 /// Counts the number of bits in the source operand having a value of 1.
 ///
 /// \headerfile 
@@ -23,7 +29,7 @@
 ///An unsigned 32-bit integer operand.
 /// \returns A 32-bit integer containing the number of bits with value 1 in the
 ///source operand.
-static __inline__ int __DEFAULT_FN_ATTRS
+static __inline__ int __DEFAULT_FN_ATTRS_CONSTEXPR
 _mm_popcnt_u32(unsigned int __A)
 {
   return __builtin_popcount(__A);
@@ -40,7 +46,7 @@ _mm_popcnt_u32(unsigned int __A)
 ///An unsigned 64-bit integer operand.
 /// \returns A 64-bit integer containing the number of bits with value 1 in the
 ///source operand.
-static __inline__ long long __DEFAULT_FN_ATTRS
+static __inline__ long long __DEFAULT_FN_ATTRS_CONSTEXPR
 _mm_popcnt_u64(unsigned long long __A)
 {
   return __builtin_popcountll(__A);
@@ -48,5 +54,6 @@ _mm_popcnt_u64(unsigned long long __A)
 #endif /* __x86_64__ */
 
 #undef __DEFAULT_FN_ATTRS
+#undef __DEFAULT_FN_ATTRS_CONSTEXPR
 
 #endif /* __POPCNTINTRIN_H */

diff  --git a/clang/test/CodeGen/popcnt-builtins.c 
b/clang/test/CodeGen/popcnt-builtins.c
index d9e7c5238513..40b786275e93 100644
--- a/clang/test/CodeGen/popcnt-builtins.c
+++ b/clang/test/CodeGen/popcnt-builtins.c
@@ -1,6 +1,7 @@
-// RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin 
-target-feature +popcnt -emit-llvm -o - | FileCheck %s 
--check-prefixes=CHECK,CHECK-POPCNT
-// RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin -emit-llvm -o 
- | FileCheck %s
-
+// RUN: %clang_cc1 -x c -ffreestanding %s -triple=x86_64-apple-darwin 
-target-feature +popcnt -emit-llvm -o - | FileCheck %s 
--check-prefixes=CHECK,CHECK-POPCNT
+// RUN: %clang_cc1 -x c++ -std=c++11 -ffreestanding %s 
-triple=x86_64-apple-darwin -target-feature +popcnt -emit-llvm -o - | FileCheck 
%s --check-prefixes=CHECK,CHECK-POPCNT
+// RUN: %clang_cc1 -x c -ffreestanding %s -triple=x86_64-apple-darwin 
-emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -x c++ -std=c++11 -ffreestanding %s 
-triple=x86_64-apple-darwin -emit-llvm -o - | FileCheck %s
 
 #include 
 
@@ -39,3 +40,16 @@ long long test__popcntq(unsigned long long __X) {
   return __popcntq(__X);
 }
 #endif
+
+// Test constexpr handling.
+#if defined(__cplusplus) && (__cplusplus >= 201103L)
+#if defined(__POPCNT__)
+char ctpop32_0[_mm_popcnt_u32(0x) == 0 ? 1 : -1];
+char ctpop32_1[_mm_popcnt_u32(0x00F0) == 4 ? 1 : -1];
+
+#ifdef __x86_64__
+char ctpop64_0[_mm_popcnt_u64(0xULL) == 0 ? 1 : -1];
+char ctpop64_1[_mm_popcnt_u64(0xF001ULL) == 5 ? 1 : -1];
+#endif
+#endif
+#endif



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


[PATCH] D86229: [X86] Enable constexpr on POPCNT intrinsics (PR31446)

2020-08-20 Thread Simon Pilgrim 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 rGcff0db08761f: [X86] Enable constexpr on POPCNT intrinsics 
(PR31446) (authored by RKSimon).

Changed prior to commit:
  https://reviews.llvm.org/D86229?vs=286861=286894#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86229

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Headers/popcntintrin.h
  clang/test/CodeGen/popcnt-builtins.c


Index: clang/test/CodeGen/popcnt-builtins.c
===
--- clang/test/CodeGen/popcnt-builtins.c
+++ clang/test/CodeGen/popcnt-builtins.c
@@ -1,6 +1,7 @@
-// RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin 
-target-feature +popcnt -emit-llvm -o - | FileCheck %s 
--check-prefixes=CHECK,CHECK-POPCNT
-// RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin -emit-llvm -o 
- | FileCheck %s
-
+// RUN: %clang_cc1 -x c -ffreestanding %s -triple=x86_64-apple-darwin 
-target-feature +popcnt -emit-llvm -o - | FileCheck %s 
--check-prefixes=CHECK,CHECK-POPCNT
+// RUN: %clang_cc1 -x c++ -std=c++11 -ffreestanding %s 
-triple=x86_64-apple-darwin -target-feature +popcnt -emit-llvm -o - | FileCheck 
%s --check-prefixes=CHECK,CHECK-POPCNT
+// RUN: %clang_cc1 -x c -ffreestanding %s -triple=x86_64-apple-darwin 
-emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -x c++ -std=c++11 -ffreestanding %s 
-triple=x86_64-apple-darwin -emit-llvm -o - | FileCheck %s
 
 #include 
 
@@ -39,3 +40,16 @@
   return __popcntq(__X);
 }
 #endif
+
+// Test constexpr handling.
+#if defined(__cplusplus) && (__cplusplus >= 201103L)
+#if defined(__POPCNT__)
+char ctpop32_0[_mm_popcnt_u32(0x) == 0 ? 1 : -1];
+char ctpop32_1[_mm_popcnt_u32(0x00F0) == 4 ? 1 : -1];
+
+#ifdef __x86_64__
+char ctpop64_0[_mm_popcnt_u64(0xULL) == 0 ? 1 : -1];
+char ctpop64_1[_mm_popcnt_u64(0xF001ULL) == 5 ? 1 : -1];
+#endif
+#endif
+#endif
Index: clang/lib/Headers/popcntintrin.h
===
--- clang/lib/Headers/popcntintrin.h
+++ clang/lib/Headers/popcntintrin.h
@@ -13,6 +13,12 @@
 /* Define the default attributes for the functions in this file. */
 #define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__, 
__target__("popcnt")))
 
+#if defined(__cplusplus) && (__cplusplus >= 201103L)
+#define __DEFAULT_FN_ATTRS_CONSTEXPR __DEFAULT_FN_ATTRS constexpr
+#else
+#define __DEFAULT_FN_ATTRS_CONSTEXPR __DEFAULT_FN_ATTRS
+#endif
+
 /// Counts the number of bits in the source operand having a value of 1.
 ///
 /// \headerfile 
@@ -23,7 +29,7 @@
 ///An unsigned 32-bit integer operand.
 /// \returns A 32-bit integer containing the number of bits with value 1 in the
 ///source operand.
-static __inline__ int __DEFAULT_FN_ATTRS
+static __inline__ int __DEFAULT_FN_ATTRS_CONSTEXPR
 _mm_popcnt_u32(unsigned int __A)
 {
   return __builtin_popcount(__A);
@@ -40,7 +46,7 @@
 ///An unsigned 64-bit integer operand.
 /// \returns A 64-bit integer containing the number of bits with value 1 in the
 ///source operand.
-static __inline__ long long __DEFAULT_FN_ATTRS
+static __inline__ long long __DEFAULT_FN_ATTRS_CONSTEXPR
 _mm_popcnt_u64(unsigned long long __A)
 {
   return __builtin_popcountll(__A);
@@ -48,5 +54,6 @@
 #endif /* __x86_64__ */
 
 #undef __DEFAULT_FN_ATTRS
+#undef __DEFAULT_FN_ATTRS_CONSTEXPR
 
 #endif /* __POPCNTINTRIN_H */
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -153,6 +153,12 @@
 
 - ...
 
+X86 Support in Clang
+
+
+- The x86 intrinsics ``_mm_popcnt_u32`` and ``_mm_popcnt_u64`` may now be used
+  within constexpr expressions.
+
 Internal API Changes
 
 


Index: clang/test/CodeGen/popcnt-builtins.c
===
--- clang/test/CodeGen/popcnt-builtins.c
+++ clang/test/CodeGen/popcnt-builtins.c
@@ -1,6 +1,7 @@
-// RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +popcnt -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,CHECK-POPCNT
-// RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin -emit-llvm -o - | FileCheck %s
-
+// RUN: %clang_cc1 -x c -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +popcnt -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,CHECK-POPCNT
+// RUN: %clang_cc1 -x c++ -std=c++11 -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +popcnt -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,CHECK-POPCNT
+// RUN: %clang_cc1 -x c -ffreestanding %s -triple=x86_64-apple-darwin -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -x c++ -std=c++11 -ffreestanding %s -triple=x86_64-apple-darwin -emit-llvm -o - | 

[PATCH] D86089: [flang][driver]Add experimental flang driver and frontend with help screen

2020-08-20 Thread sameeran joshi via Phabricator via cfe-commits
sameeranjoshi added a comment.

Thanks for the work.

A couple of comments on `clang/` related changes:
An `out-of-tree` build with this patch fails for me:
Here's what I did:
I initially used `ENABLE_PROJECTS="clang;mlir"` to build `llvm-project`, I 
didn't build `flang` during this run.

Then I passed following to the cmake when building `flang` as out of tree.

  cmake -G Ninja \
-DCMAKE_BUILD_TYPE=Release \
-DFLANG_ENABLE_WERROR=On \
-DCMAKE_CXX_STANDARD=17 \
-DLLVM_TARGETS_TO_BUILD=host \
-DLLVM_LIT_ARGS=-v \
-D LLVM_DIR=${LLVM_MLIR_CLANG_BUILD}/lib/cmake/llvm \
-D MLIR_DIR=${LLVM_MLIR_CLANG_BUILD}/lib/cmake/mlir \
-DBUILD_FLANG_NEW_DRIVER=ON \
../
  ninja -j16

where `LLVM_MLIR_CLANG_BUILD` points to initially built `llvm-project` .
I see below error message:

  ../lib/Frontend/CompilerInvocation.cpp: In static member function ‘static 
bool flang::CompilerInvocation::CreateFromArgs(flang::CompilerInvocation&, 
llvm::ArrayRef, clang::DiagnosticsEngine&)’:
  ../lib/Frontend/CompilerInvocation.cpp:85:67: error: ‘FlangOption’ is not a 
member of ‘clang::driver::options’
 clang::driver::options::CC1Option | 
clang::driver::options::FlangOption;
 ^~~
  ../lib/Frontend/CompilerInvocation.cpp:85:67: note: suggested alternative: 
‘LastOption’
 clang::driver::options::CC1Option | 
clang::driver::options::FlangOption;
 ^~~
 LastOption

Do you need to add `-DCLANG_DIR` flag, as there seem to be a dependency for 
this patch on clang as libraries?




Comment at: clang/include/clang/Driver/Options.td:60
+// FlangOption - This is considered a "core" Flang option, available in
+// flang mode
+def FlangOption : OptionFlag;

`nit:` a missing period.
// flang mode -> // flang mode.



Comment at: clang/include/clang/Driver/Options.td:2076
 def headerpad__max__install__names : Joined<["-"], 
"headerpad_max_install_names">;
-def help : Flag<["-", "--"], "help">, Flags<[CC1Option,CC1AsOption]>,
+def help : Flag<["-", "--"], "help">, 
Flags<[CC1Option,CC1AsOption,FlangOption]>,
   HelpText<"Display available options">;

`nit:` - A space before `FlangOption`
CC1AsOption,FlangOption -> CC1AsOption, FlangOption



Comment at: clang/include/clang/Driver/Options.td:3019
 // We give --version different semantics from -version.
-def _version : Flag<["--"], "version">, Flags<[CoreOption, CC1Option]>,
+def _version : Flag<["--"], "version">, Flags<[CoreOption, 
CC1Option,FlangOption]>,
   HelpText<"Print version information">;

Same as above.
nit: - A space before `FlangOption`



Comment at: clang/lib/Driver/Driver.cpp:1569
 
+  if (Mode == DriverMode::FlangMode) {
+ExcludedFlagsBitmask |= options::CLOption;

Can `IsFlangMode()` be used instead?



Comment at: clang/lib/Driver/Driver.cpp:1573
+ExcludedFlagsBitmask |= options::CC1Option;
+IncludedFlagsBitmask |= options::FlangOption;
+  } else

In `enum ClangFlags` 
inside File `clang/include/clang/Driver/Options.h`
there are various other options do they need to be considered?
If not, how are they handled?



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86089

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


[PATCH] D86308: Reland [compiler-rt] Compile assembly files as ASM not C

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

Just FWIW, a similar change was made in libunwind earlier 
(c48974ffd7d1676f79d39d3b1e70f07d3a5e2e44 
), which 
then required workarounds for cmake issues on both mingw and macos (see 
b780df052dd2b246a760d00e00f7de9ebdab9d09 
 and 
d4ded05ba851304b26a437896bc3962ef56f62cb 
) to 
reintroduce the code for building the asm code as C.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86308

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


[PATCH] D86308: Reland [compiler-rt] Compile assembly files as ASM not C

2020-08-20 Thread Petr Hosek via Phabricator via cfe-commits
phosek added a comment.

In D86308#2228917 , @tambre wrote:

> I'm pretty sure `add_asm_sources()` has nothing to do. The ASM language is 
> enabled by compiler-rt anyway and CMake can recognize the files as assembly 
> anyway.

Can we remove that function altogether then?

> @teemperor Could you give this a try? If this doesn't work, could you upload 
> the Ninja file for me to investigate? I've never used macOS so the simulators 
> and many architectures at once is quite new to me.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86308

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


[PATCH] D86293: [analyzer] Add modeling of Eq operator in smart ptr

2020-08-20 Thread Nithin VR via Phabricator via cfe-commits
vrnithinkumar updated this revision to Diff 286868.
vrnithinkumar added a comment.

- Add assignment to nullptr case


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86293

Files:
  clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
  clang/test/Analysis/Inputs/system-header-simulator-cxx.h
  clang/test/Analysis/smart-ptr-text-output.cpp
  clang/test/Analysis/smart-ptr.cpp

Index: clang/test/Analysis/smart-ptr.cpp
===
--- clang/test/Analysis/smart-ptr.cpp
+++ clang/test/Analysis/smart-ptr.cpp
@@ -215,8 +215,7 @@
 std::unique_ptr P;
 std::unique_ptr Q;
 Q = std::move(P);
-// TODO: Fix test with expecting warning after '=' operator overloading modeling.
-Q->foo(); // no-warning
+Q->foo(); // expected-warning {{Dereference of null smart pointer 'Q' [alpha.cplusplus.SmartPtr]}}
   }
 }
 
@@ -252,3 +251,61 @@
   P->foo(); // No warning.
   PValid->foo(); // No warning.
 }
+
+void derefOnMovedFromValidPtr() {
+  std::unique_ptr PToMove(new A());
+  std::unique_ptr P;
+  P = std::move(PToMove);
+  PToMove->foo(); // expected-warning {{Dereference of null smart pointer 'PToMove' [alpha.cplusplus.SmartPtr]}}
+}
+
+void derefOnMovedToNullPtr() {
+  std::unique_ptr PToMove(new A());
+  std::unique_ptr P;
+  P = std::move(PToMove); // No note.
+  P->foo(); // No warning.
+}
+
+void derefOnNullPtrGotMovedFromValidPtr() {
+  std::unique_ptr P(new A());
+  std::unique_ptr PToMove;
+  P = std::move(PToMove);
+  P->foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}}
+}
+
+void derefOnMovedFromUnknownPtr(std::unique_ptr PToMove) {
+  std::unique_ptr P;
+  P = std::move(PToMove);
+  P->foo(); // No warning.
+}
+
+void derefOnMovedUnknownPtr(std::unique_ptr PToMove) {
+  std::unique_ptr P;
+  P = std::move(PToMove);
+  PToMove->foo(); // expected-warning {{Dereference of null smart pointer 'PToMove' [alpha.cplusplus.SmartPtr]}}
+}
+
+void derefOnAssignedNullPtrToNullSmartPtr() {
+  std::unique_ptr P;
+  P = nullptr;
+  P->foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}}
+}
+
+void derefOnAssignedZeroToNullSmartPtr() {
+  std::unique_ptr P(new A());
+  P = 0;
+  P->foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}}
+}
+
+void derefOnAssignedNullToUnknowSmartPtr(std::unique_ptr P) {
+  P = nullptr;
+  P->foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}}
+}
+
+std::unique_ptr &();
+
+void drefOnAssignedNullFromMethodPtrValidSmartPtr() {
+  std::unique_ptr P(new A());
+  P = returnRValRefOfUniquePtr();
+  P->foo(); // No warning. 
+}
Index: clang/test/Analysis/smart-ptr-text-output.cpp
===
--- clang/test/Analysis/smart-ptr-text-output.cpp
+++ clang/test/Analysis/smart-ptr-text-output.cpp
@@ -80,7 +80,7 @@
 void derefOnStdSwappedNullPtr() {
   std::unique_ptr P; // expected-note {{Default constructed smart pointer 'P' is null}}
   std::unique_ptr PNull; // expected-note {{Default constructed smart pointer 'PNull' is null}}
-  std::swap(P, PNull); // expected-note@Inputs/system-header-simulator-cxx.h:978 {{Swapped null smart pointer 'PNull' with smart pointer 'P'}}
+  std::swap(P, PNull); // expected-note@Inputs/system-header-simulator-cxx.h:979 {{Swapped null smart pointer 'PNull' with smart pointer 'P'}}
   // expected-note@-1 {{Calling 'swap'}}
   // expected-note@-2 {{Returning from 'swap'}}
   P->foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}}
@@ -109,10 +109,49 @@
   // expected-note@-1{{Dereference of null smart pointer 'P'}}
 }
 
-void noNoteTagsForNonMatchingBugType() {
-  std::unique_ptr P; // No note.
-  std::unique_ptr P1; // No note.
-  P1 = std::move(P); // expected-note {{Smart pointer 'P' of type 'std::unique_ptr' is reset to null when moved from}}
-  P->foo(); // expected-warning {{Dereference of null smart pointer 'P' of type 'std::unique_ptr' [cplusplus.Move]}}
-  // expected-note@-1 {{Dereference of null smart pointer 'P' of type 'std::unique_ptr'}}
+void derefOnMovedFromValidPtr() {
+  std::unique_ptr PToMove(new A());  // expected-note {{Smart pointer 'PToMove' is constructed}}
+  // FIXME: above note should go away once we fix marking region not interested. 
+  std::unique_ptr P;
+  P = std::move(PToMove); // expected-note {{Smart pointer 'PToMove' is null after moved to 'P'}}
+  PToMove->foo(); // expected-warning {{Dereference of null smart pointer 'PToMove' [alpha.cplusplus.SmartPtr]}}
+  // expected-note@-1 {{Dereference of null smart pointer 'PToMove'}}
+}
+
+void derefOnMovedToNullPtr() {
+  std::unique_ptr PToMove(new A());
+  std::unique_ptr P;
+  P = std::move(PToMove); // No note.
+  P->foo(); // No warning.
+}
+
+void 

[PATCH] D82994: [RFC] Instrumenting Clang/LLVM with Perfetto

2020-08-20 Thread Nathan Huckleberry via Phabricator via cfe-commits
Nathan-Huckleberry updated this revision to Diff 286866.
Nathan-Huckleberry added a comment.

- Attach translation unit names to trace processes


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82994

Files:
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Driver/Options.td
  clang/include/clang/Frontend/FrontendOptions.h
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CMakeLists.txt
  clang/lib/CodeGen/CodeGenAction.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInstance.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Lex/CMakeLists.txt
  clang/lib/Parse/CMakeLists.txt
  clang/lib/Parse/ParseAST.cpp
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/lib/Parse/ParseTemplate.cpp
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/lib/Serialization/GlobalModuleIndex.cpp
  clang/tools/clang-shlib/CMakeLists.txt
  clang/tools/driver/cc1_main.cpp
  llvm/cmake/config-ix.cmake
  llvm/cmake/modules/AddPerfetto.cmake
  llvm/include/llvm/Support/PerfettoTracer.h
  llvm/include/llvm/Support/Tracing.h
  llvm/lib/Analysis/LoopPass.cpp
  llvm/lib/IR/CMakeLists.txt
  llvm/lib/IR/LegacyPassManager.cpp
  llvm/lib/Support/CMakeLists.txt
  llvm/lib/Support/PerfettoTracer.cpp

Index: llvm/lib/Support/PerfettoTracer.cpp
===
--- /dev/null
+++ llvm/lib/Support/PerfettoTracer.cpp
@@ -0,0 +1,59 @@
+#ifdef PERFETTO
+#include "llvm/Support/Tracing.h"
+
+using namespace llvm;
+
+bool PerfettoEnabled = false;
+uint64_t PerfettoGranularityNS = 2 * 1000 * 1000;
+SmallVector PerfettoStack;
+
+PerfettoProfiler::PerfettoProfiler(std::unique_ptr os, SmallString<128> Path)
+: OS(std::move(os)) {
+  perfetto::TracingInitArgs args;
+  // The backends determine where trace events are recorded. For this example we
+  // are going to use the in-process tracing service, which only includes in-app
+  // events.
+  args.backends = perfetto::kInProcessBackend;
+
+  perfetto::Tracing::Initialize(args);
+  perfetto::TrackEvent::Register();
+
+  // The trace config defines which types of data sources are enabled for
+  // recording. In this example we just need the "track_event" data source,
+  // which corresponds to the TRACE_EVENT trace points.
+  perfetto::TraceConfig cfg;
+  cfg.add_buffers()->set_size_kb(32384);
+  auto *ds_cfg = cfg.add_data_sources()->mutable_config();
+  ds_cfg->set_name("track_event");
+
+  TracingSession = perfetto::Tracing::NewTrace();
+  TracingSession->Setup(cfg);
+  TracingSession->StartBlocking();
+  PerfettoEnabled = true;
+
+  auto desc = perfetto::ProcessTrack::Current().Serialize();
+  desc.mutable_process()->set_process_name(Path.str().str());
+  perfetto::TrackEvent::SetTrackDescriptor(
+  perfetto::ProcessTrack::Current(), desc);
+}
+
+PerfettoProfiler::~PerfettoProfiler() {
+  // Make sure the last event is closed for this example.
+  perfetto::TrackEvent::Flush();
+  // Stop tracing and read the trace data.
+  TracingSession->StopBlocking();
+  std::vector trace_data(TracingSession->ReadTraceBlocking());
+  // Write the result into a file.
+  // Note: To save memory with longer traces, you can tell Perfetto to write
+  // directly into a file by passing a file descriptor into Setup() above.
+  OS->write(_data[0], trace_data.size());
+  OS->flush();
+}
+
+bool PerfettoTracingEnabled() { return PerfettoEnabled; }
+
+uint64_t PerfettoGetGranularity() { return PerfettoGranularityNS; }
+
+// Reserves internal static storage for our tracing categories.
+PERFETTO_TRACK_EVENT_STATIC_STORAGE();
+#endif
Index: llvm/lib/Support/CMakeLists.txt
===
--- llvm/lib/Support/CMakeLists.txt
+++ llvm/lib/Support/CMakeLists.txt
@@ -122,6 +122,7 @@
   OptimizedStructLayout.cpp
   Optional.cpp
   Parallel.cpp
+  PerfettoTracer.cpp
   PluginLoader.cpp
   PrettyStackTrace.cpp
   RandomNumberGenerator.cpp
Index: llvm/lib/IR/LegacyPassManager.cpp
===
--- llvm/lib/IR/LegacyPassManager.cpp
+++ llvm/lib/IR/LegacyPassManager.cpp
@@ -27,8 +27,8 @@
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/ManagedStatic.h"
 #include "llvm/Support/Mutex.h"
-#include "llvm/Support/TimeProfiler.h"
 #include "llvm/Support/Timer.h"
+#include "llvm/Support/Tracing.h"
 #include "llvm/Support/raw_ostream.h"
 #include 
 #include 
@@ -1463,13 +1463,13 @@
 FunctionSize = F.getInstructionCount();
   }
 
-  llvm::TimeTraceScope FunctionScope("OptFunction", F.getName());
+  LLVM_TRACE_SCOPE("OptFunction", F.getName());
 
   for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
 FunctionPass *FP = getContainedPass(Index);
 

[PATCH] D86310: [X86] Align i128 to 16 bytes in x86-64 datalayout

2020-08-20 Thread Craig Topper via Phabricator via cfe-commits
craig.topper created this revision.
craig.topper added reviewers: efriedma, echristo, RKSimon, spatel.
Herald added subscribers: nikic, dexonsmith, steven_wu, javed.absar, hiraditya, 
dschuff.
Herald added a project: LLVM.
craig.topper requested review of this revision.

This is an attempt at rebooting https://reviews.llvm.org/D28990

I've included AutoUpgrade changes to modify the data layout to satisfy the 
compatible layout check. But this does mean alloca, loads, stores, etc in old 
IR will automatically get this new alignment.

This should fix PR46320.


https://reviews.llvm.org/D86310

Files:
  clang/lib/Basic/Targets/OSTargets.h
  clang/lib/Basic/Targets/X86.h
  clang/test/CodeGen/target-data.c
  llvm/include/llvm/IR/AutoUpgrade.h
  llvm/lib/IR/AutoUpgrade.cpp
  llvm/lib/Target/X86/X86TargetMachine.cpp
  llvm/test/Bitcode/upgrade-datalayout.ll
  llvm/test/Bitcode/upgrade-datalayout3.ll
  llvm/test/CodeGen/X86/atomic-unordered.ll
  llvm/test/CodeGen/X86/bitcast-i256.ll
  llvm/test/CodeGen/X86/catchpad-dynamic-alloca.ll
  llvm/test/CodeGen/X86/implicit-null-check.ll
  llvm/test/CodeGen/X86/legalize-shl-vec.ll
  llvm/test/CodeGen/X86/osx-private-labels.ll
  llvm/test/CodeGen/X86/scheduler-backtracking.ll
  llvm/test/CodeGen/X86/setcc-wide-types.ll
  llvm/test/CodeGen/X86/sret-implicit.ll
  llvm/test/CodeGen/X86/statepoint-vector.ll
  llvm/test/tools/llvm-lto2/X86/pipeline.ll
  llvm/test/tools/llvm-lto2/X86/slp-vectorize-pm.ll
  llvm/test/tools/llvm-lto2/X86/stats-file-option.ll
  llvm/unittests/Bitcode/DataLayoutUpgradeTest.cpp

Index: llvm/unittests/Bitcode/DataLayoutUpgradeTest.cpp
===
--- llvm/unittests/Bitcode/DataLayoutUpgradeTest.cpp
+++ llvm/unittests/Bitcode/DataLayoutUpgradeTest.cpp
@@ -15,23 +15,23 @@
 
 TEST(DataLayoutUpgradeTest, ValidDataLayoutUpgrade) {
   std::string DL1 =
-  UpgradeDataLayoutString("e-m:e-p:32:32-i64:64-f80:128-n8:16:32:64-S128",
+  UpgradeDataLayoutString("e-m:e-p:32:32-i64:64-i128:128-f80:128-n8:16:32:64-S128",
   "x86_64-unknown-linux-gnu");
   std::string DL2 = UpgradeDataLayoutString(
-  "e-m:w-p:32:32-i64:64-f80:32-n8:16:32-S32", "i686-pc-windows-msvc");
+  "e-m:w-p:32:32-i64:64-i128:128-f80:32-n8:16:32-S32", "i686-pc-windows-msvc");
   std::string DL3 = UpgradeDataLayoutString("e-m:o-i64:64-i128:128-n32:64-S128",
 "x86_64-apple-macosx");
   EXPECT_EQ(DL1, "e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:64-i64:64"
- "-f80:128-n8:16:32:64-S128");
+ "-i128:128-f80:128-n8:16:32:64-S128");
   EXPECT_EQ(DL2, "e-m:w-p:32:32-p270:32:32-p271:32:32-p272:64:64-i64:64"
- "-f80:32-n8:16:32-S32");
+ "-i128:128-f80:32-n8:16:32-S32");
   EXPECT_EQ(DL3, "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128"
  "-n32:64-S128");
 }
 
 TEST(DataLayoutUpgradeTest, NoDataLayoutUpgrade) {
   std::string DL1 = UpgradeDataLayoutString(
-  "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32"
+  "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-i128:128:128-f32:32:32"
   "-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128"
   "-n8:16:32:64-S128",
   "x86_64-unknown-linux-gnu");
@@ -40,7 +40,7 @@
 "powerpc64le-unknown-linux-gnu");
   std::string DL4 =
   UpgradeDataLayoutString("e-m:o-i64:64-i128:128-n32:64-S128", "aarch64--");
-  EXPECT_EQ(DL1, "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64"
+  EXPECT_EQ(DL1, "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-i128:128:128"
  "-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64"
  "-f80:128:128-n8:16:32:64-S128");
   EXPECT_EQ(DL2, "e-p:32:32");
@@ -51,9 +51,9 @@
 TEST(DataLayoutUpgradeTest, EmptyDataLayout) {
   std::string DL1 = UpgradeDataLayoutString("", "x86_64-unknown-linux-gnu");
   std::string DL2 = UpgradeDataLayoutString(
-  "e-m:e-p:32:32-i64:64-f80:128-n8:16:32:64-S128", "");
+  "e-m:e-p:32:32-i64:64-i128:128-f80:128-n8:16:32:64-S128", "");
   EXPECT_EQ(DL1, "");
-  EXPECT_EQ(DL2, "e-m:e-p:32:32-i64:64-f80:128-n8:16:32:64-S128");
+  EXPECT_EQ(DL2, "e-m:e-p:32:32-i64:64-i128:128-f80:128-n8:16:32:64-S128");
 }
 
 } // end namespace
Index: llvm/test/tools/llvm-lto2/X86/stats-file-option.ll
===
--- llvm/test/tools/llvm-lto2/X86/stats-file-option.ll
+++ llvm/test/tools/llvm-lto2/X86/stats-file-option.ll
@@ -6,7 +6,7 @@
 ; RUN: llvm-lto2 run %t1.bc -o %t.o -r %t1.bc,patatino,px -stats-file=%t2.stats
 ; RUN: FileCheck --input-file=%t2.stats %s
 
-target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
 target triple = 

[PATCH] D86229: [X86] Enable constexpr on POPCNT intrinsics (PR31446)

2020-08-20 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon updated this revision to Diff 286861.
RKSimon added a comment.

Added constexpr tests - I went for the -ve array size approach as thats the 
approach in clang\test\Sema\constant-builtins-2.c etc.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86229

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Headers/popcntintrin.h
  clang/test/CodeGen/popcnt-builtins.c


Index: clang/test/CodeGen/popcnt-builtins.c
===
--- clang/test/CodeGen/popcnt-builtins.c
+++ clang/test/CodeGen/popcnt-builtins.c
@@ -1,6 +1,7 @@
-// RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin 
-target-feature +popcnt -emit-llvm -o - | FileCheck %s 
--check-prefixes=CHECK,CHECK-POPCNT
-// RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin -emit-llvm -o 
- | FileCheck %s
-
+// RUN: %clang_cc1 -x c -ffreestanding %s -triple=x86_64-apple-darwin 
-target-feature +popcnt -emit-llvm -o - | FileCheck %s 
--check-prefixes=CHECK,CHECK-POPCNT
+// RUN: %clang_cc1 -x c++ -std=c++11 -ffreestanding %s 
-triple=x86_64-apple-darwin -target-feature +popcnt -emit-llvm -o - | FileCheck 
%s --check-prefixes=CHECK,CHECK-POPCNT
+// RUN: %clang_cc1 -x c -ffreestanding %s -triple=x86_64-apple-darwin 
-emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -x c++ -std=c++11 -ffreestanding %s 
-triple=x86_64-apple-darwin -emit-llvm -o - | FileCheck %s
 
 #include 
 
@@ -39,3 +40,17 @@
   return __popcntq(__X);
 }
 #endif
+
+// Test constexpr handling.
+#if defined(__cplusplus) && (__cplusplus >= 201103L)
+#if defined(__POPCNT__)
+char ctpop32_0[_mm_popcnt_u32(0x) == 0 ? 1 : -1];
+char ctpop32_1[_mm_popcnt_u32(0x00F0) == 4 ? 1 : -1];
+
+#ifdef __x86_64__
+char ctpop64_0[_mm_popcnt_u64(0xULL) == 0 ? 1 : -1];
+char ctpop64_1[_mm_popcnt_u64(0xF001ULL) == 5 ? 1 : -1];
+#endif
+#endif
+#endif
+
Index: clang/lib/Headers/popcntintrin.h
===
--- clang/lib/Headers/popcntintrin.h
+++ clang/lib/Headers/popcntintrin.h
@@ -13,6 +13,12 @@
 /* Define the default attributes for the functions in this file. */
 #define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__, 
__target__("popcnt")))
 
+#if defined(__cplusplus) && (__cplusplus >= 201103L)
+#define __DEFAULT_FN_ATTRS_CONSTEXPR __DEFAULT_FN_ATTRS constexpr
+#else
+#define __DEFAULT_FN_ATTRS_CONSTEXPR __DEFAULT_FN_ATTRS
+#endif
+
 /// Counts the number of bits in the source operand having a value of 1.
 ///
 /// \headerfile 
@@ -23,7 +29,7 @@
 ///An unsigned 32-bit integer operand.
 /// \returns A 32-bit integer containing the number of bits with value 1 in the
 ///source operand.
-static __inline__ int __DEFAULT_FN_ATTRS
+static __inline__ int __DEFAULT_FN_ATTRS_CONSTEXPR
 _mm_popcnt_u32(unsigned int __A)
 {
   return __builtin_popcount(__A);
@@ -40,7 +46,7 @@
 ///An unsigned 64-bit integer operand.
 /// \returns A 64-bit integer containing the number of bits with value 1 in the
 ///source operand.
-static __inline__ long long __DEFAULT_FN_ATTRS
+static __inline__ long long __DEFAULT_FN_ATTRS_CONSTEXPR
 _mm_popcnt_u64(unsigned long long __A)
 {
   return __builtin_popcountll(__A);
@@ -48,5 +54,6 @@
 #endif /* __x86_64__ */
 
 #undef __DEFAULT_FN_ATTRS
+#undef __DEFAULT_FN_ATTRS_CONSTEXPR
 
 #endif /* __POPCNTINTRIN_H */
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -153,6 +153,12 @@
 
 - ...
 
+X86 Support in Clang
+
+
+- The x86 intrinsics ``_mm_popcnt_u32`` and ``_mm_popcnt_u64`` may now be used
+  within constexpr expressions.
+
 Internal API Changes
 
 


Index: clang/test/CodeGen/popcnt-builtins.c
===
--- clang/test/CodeGen/popcnt-builtins.c
+++ clang/test/CodeGen/popcnt-builtins.c
@@ -1,6 +1,7 @@
-// RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +popcnt -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,CHECK-POPCNT
-// RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin -emit-llvm -o - | FileCheck %s
-
+// RUN: %clang_cc1 -x c -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +popcnt -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,CHECK-POPCNT
+// RUN: %clang_cc1 -x c++ -std=c++11 -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +popcnt -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,CHECK-POPCNT
+// RUN: %clang_cc1 -x c -ffreestanding %s -triple=x86_64-apple-darwin -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -x c++ -std=c++11 -ffreestanding %s -triple=x86_64-apple-darwin -emit-llvm -o - | FileCheck %s
 
 #include 
 
@@ -39,3 +40,17 @@
   return __popcntq(__X);
 }
 #endif
+
+// Test constexpr handling.
+#if 

[PATCH] D86308: Reland [compiler-rt] Compile assembly files as ASM not C

2020-08-20 Thread Raul Tambre via Phabricator via cfe-commits
tambre added a comment.

I'm pretty sure `add_asm_sources()` has nothing to do. The ASM language is 
enabled by compiler-rt anyway and CMake can recognize the files as assembly 
anyway.

@teemperor Could you give this a try? If this doesn't work, could you upload 
the Ninja file for me to investigate? I've never used macOS so the simulators 
and many architectures at once is quite new to me.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86308

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


[PATCH] D85324: [SystemZ][z/OS] Add z/OS Target and define macros

2020-08-20 Thread Abhina Sree via Phabricator via cfe-commits
abhina.sreeskantharajan marked 3 inline comments as done.
abhina.sreeskantharajan added inline comments.



Comment at: clang/lib/Basic/Targets/OSTargets.h:743
+Builder.defineMacro("__BFP__");
+Builder.defineMacro("__BOOL__");
+Builder.defineMacro("__LONGNAME__");

hubert.reinterpretcast wrote:
> Sorry for not catching this earlier, but this also needs a FIXME re: strict 
> C89.
I've added a comment here.



Comment at: clang/test/Preprocessor/init-zos.c:5
+//
+// S390X-ZOS-CXX:#define _EXT 1
+// S390X-ZOS-C99:#define _ISOC99_SOURCE 1

hubert.reinterpretcast wrote:
> Should this be `GNUXX`?
I agree this is a better name, I've updated the name to your suggestion.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85324

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


[PATCH] D85324: [SystemZ][z/OS] Add z/OS Target and define macros

2020-08-20 Thread Abhina Sree via Phabricator via cfe-commits
abhina.sreeskantharajan updated this revision to Diff 286853.
abhina.sreeskantharajan marked an inline comment as done.
abhina.sreeskantharajan added a comment.

Thanks Hubert, I updated the comments, and also the check-prefix to your 
suggestion.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85324

Files:
  clang/lib/Basic/Targets.cpp
  clang/lib/Basic/Targets/OSTargets.h
  clang/test/Preprocessor/init-zos.c

Index: clang/test/Preprocessor/init-zos.c
===
--- /dev/null
+++ clang/test/Preprocessor/init-zos.c
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 -E -dM -ffreestanding -triple=s390x-none-zos -fno-signed-char < /dev/null | FileCheck -match-full-lines -check-prefix S390X-ZOS %s
+// RUN: %clang_cc1 -x c -std=c99 -E -dM -ffreestanding -triple=s390x-none-zos -fno-signed-char < /dev/null | FileCheck -match-full-lines -check-prefix S390X-ZOS -check-prefix S390X-ZOS-C99 %s
+// RUN: %clang_cc1 -x c++ -std=gnu++14 -E -dM -ffreestanding -triple=s390x-none-zos -fno-signed-char < /dev/null | FileCheck -match-full-lines -check-prefix S390X-ZOS -check-prefix S390X-ZOS-GNUXX %s
+//
+// S390X-ZOS-GNUXX:#define _EXT 1
+// S390X-ZOS-C99:#define _ISOC99_SOURCE 1
+// S390X-ZOS:#define _LONG_LONG 1
+// S390X-ZOS-GNUXX:#define _MI_BUILTIN 1
+// S390X-ZOS:#define _OPEN_DEFAULT 1
+// S390X-ZOS:#define _UNIX03_WITHDRAWN 1
+// S390X-ZOS-GNUXX:#define _XOPEN_SOURCE 600
+// S390X-ZOS:#define __370__ 1
+// S390X-ZOS:#define __64BIT__ 1
+// S390X-ZOS:#define __BFP__ 1
+// S390X-ZOS:#define __BOOL__ 1
+// S390X-ZOS-GNUXX:#define __DLL__ 1
+// S390X-ZOS:#define __LONGNAME__ 1
+// S390X-ZOS:#define __MVS__ 1
+// S390X-ZOS:#define __THW_370__ 1
+// S390X-ZOS:#define __THW_BIG_ENDIAN__ 1
+// S390X-ZOS:#define __TOS_390__ 1
+// S390X-ZOS:#define __TOS_MVS__ 1
+// S390X-ZOS:#define __XPLINK__ 1
+// S390X-ZOS-GNUXX:#define __wchar_t 1
Index: clang/lib/Basic/Targets/OSTargets.h
===
--- clang/lib/Basic/Targets/OSTargets.h
+++ clang/lib/Basic/Targets/OSTargets.h
@@ -727,6 +727,58 @@
   bool defaultsToAIXPowerAlignment() const override { return true; }
 };
 
+// z/OS target
+template 
+class LLVM_LIBRARY_VISIBILITY ZOSTargetInfo : public OSTargetInfo {
+protected:
+  void getOSDefines(const LangOptions , const llvm::Triple ,
+MacroBuilder ) const override {
+// FIXME: _LONG_LONG should not be defined under -std=c89.
+Builder.defineMacro("_LONG_LONG");
+Builder.defineMacro("_OPEN_DEFAULT");
+// _UNIX03_WITHDRAWN is required to build libcxx.
+Builder.defineMacro("_UNIX03_WITHDRAWN");
+Builder.defineMacro("__370__");
+Builder.defineMacro("__BFP__");
+// FIXME: __BOOL__ should be defined under strict -std=c89.
+Builder.defineMacro("__BOOL__");
+Builder.defineMacro("__LONGNAME__");
+Builder.defineMacro("__MVS__");
+Builder.defineMacro("__THW_370__");
+Builder.defineMacro("__THW_BIG_ENDIAN__");
+Builder.defineMacro("__TOS_390__");
+Builder.defineMacro("__TOS_MVS__");
+Builder.defineMacro("__XPLINK__");
+
+if (this->PointerWidth == 64)
+  Builder.defineMacro("__64BIT__");
+
+if (Opts.C99)
+  Builder.defineMacro("_ISOC99_SOURCE");
+
+if (Opts.CPlusPlus) {
+  Builder.defineMacro("__DLL__");
+  // XOPEN_SOURCE=600 is required to build libcxx.
+  Builder.defineMacro("_XOPEN_SOURCE", "600");
+}
+
+if (Opts.GNUMode) {
+  Builder.defineMacro("_MI_BUILTIN");
+  Builder.defineMacro("_EXT");
+}
+
+if (Opts.CPlusPlus && Opts.WChar) {
+  // Macro __wchar_t is defined so that the wchar_t data
+  // type is not declared as a typedef in system headers.
+  Builder.defineMacro("__wchar_t");
+}
+  }
+
+public:
+  ZOSTargetInfo(const llvm::Triple , const TargetOptions )
+  : OSTargetInfo(Triple, Opts) {}
+};
+
 void addWindowsDefines(const llvm::Triple , const LangOptions ,
MacroBuilder );
 
Index: clang/lib/Basic/Targets.cpp
===
--- clang/lib/Basic/Targets.cpp
+++ clang/lib/Basic/Targets.cpp
@@ -450,6 +450,8 @@
 switch (os) {
 case llvm::Triple::Linux:
   return new LinuxTargetInfo(Triple, Opts);
+case llvm::Triple::ZOS:
+  return new ZOSTargetInfo(Triple, Opts);
 default:
   return new SystemZTargetInfo(Triple, Opts);
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D85031: [builtins] Unify the softfloat division implementation

2020-08-20 Thread Anatoly Trosinenko via Phabricator via cfe-commits
atrosinenko added a comment.

//Some general context:// The final goal was to have an explanation why this 
particular number of iteration (3, 4 or 5, depending on type) are enough for 
any `a` and `b` passed as input arguments taking into account errors due to 
particular finite precision computations. Initially, I was trying to just 
"mechanically" unify the three implementations and their comments like this 
. After trying for a 
while, turned out I cannot simply pick the original proof up and add the 
subnormal case. Some of statements were too vague, some seemed not explained 
enough, etc. Then, an attempt was made to re-prove it from scratch with an 
intention for the resulting explanation to be as much self-contained as 
possible. The **implementation**, on the other hand, gathers various features 
of three original functions and some hacks to make it easier to prove.




Comment at: compiler-rt/lib/builtins/fp_div_impl.inc:99
+  //   0 < x0(b) < 1
+  //   abs(x0(b) - 1/b) <= 3/4 - 1/sqrt(2)
+

sepavloff wrote:
> This estimation is absent from the original comment. Do you have reference 
> where it came from? Also the original comment states `This is accurate to 
> about 3.5 binary digits`. Is still true? If yes, it could be worth copying 
> here.
This approximation was deduced by writing down the derivative of `f ` "in 
infinite precision" and finding its root. Then the values of `f` applied to its 
root, 1.0 and 2.0 were calculated -- as far as I remember, **all of them** were 
`3/4 - 1/sqrt(2)` or negated - //this is what "minimax polynomial" probably 
means, that term was just copied from the original implementation :)//.



Comment at: compiler-rt/lib/builtins/fp_div_impl.inc:101-102
+
+  // Then, refine the reciprocal estimate using a Newton-Raphson iteration:
+  // x_{n+1} = x_n * (2 - x_n * b)
+  // Let e_n := x_n - 1/b_hw

sepavloff wrote:
> The original comment states:
> ```
>   // This doubles the number of correct binary digits in the approximation
>   // with each iteration.
> ```
> It is true in this implementation? If yes, it could be worth copying here.
For me this looks too vague. This is probably //approximately true// but I 
don't know how exactly this should be interpreted.



Comment at: compiler-rt/lib/builtins/fp_div_impl.inc:109
+
+#if NUMBER_OF_HALF_ITERATIONS > 0
+  // Starting with (n-1) half-width iterations

sepavloff wrote:
> It is good optimization. Could you please put a comment shortly describing 
> the idea of using half-sized temporaries?
The idea is just "I guess this takes less CPU time and I have managed to prove 
error bounds for it". :) Specifically, for float128, the rep_t * rep_t 
multiplication will be emulated with lots of CPU instructions while the lower 
half contain some noise at that point. This particular optimization did exist 
in the original implementation for float64 and float128. For float32 it had not 
much sense, I guess. Still, estimations were calculated for the case of float32 
with half-size iterations as it may be useful for MSP430 and other 16-bit 
targets.



Comment at: compiler-rt/lib/builtins/fp_div_impl.inc:114
+  // C is (3/4 + 1/sqrt(2)) - 1 truncated to W0 fractional bits as UQ0.HW
+#if defined(SINGLE_PRECISION)
+  const half_rep_t C_hw = HALF_REP_C(0x7504) << (HW - 16);

sepavloff wrote:
> In what cases 16-bit temporaries are used?  `NUMBER_OF_HALF_ITERATIONS` is 
> set to zero in `divsf3.c`.
Agree, this needs to be re-evaluated and some comment should be added at least. 
This could be dead code for now, that was //expected// to speed things up on 
16-bit targets that even lack hardware multiplication sometimes (such as 
MSP430).



Comment at: compiler-rt/lib/builtins/fp_div_impl.inc:130
+// Cannot overflow by construction and is larger than 2 - b*x by at most 
1*Ulp.
+half_rep_t corr_UQ1_hw = 0 /* = 2 */ - ((rep_t)x_UQ0_hw * b_UQ1_hw >> HW);
+// Would be at most [1.]0 after overflow if rounding (0 - x_UQ0_hw * 
b_UQ1_hw) down.

sepavloff wrote:
> It would be better to put short comment to explain using 0 instead of 2.
Agree, it was expected to be something like `/* = 2.0 in UQ1.(HW-1) */`. Naming 
things is especially painful here...



Comment at: compiler-rt/lib/builtins/fp_div_impl.inc:184
+  // x_UQ0 * b_UQ1 = (x_UQ0_hw * 2^HW) * (b_UQ1_hw * 2^HW + blo) - b_UQ1
+  rep_t corr_UQ1 = 0 - (   (rep_t)x_UQ0_hw * b_UQ1_hw
++ ((rep_t)x_UQ0_hw * blo >> HW)

sepavloff wrote:
> `x_UQ0_hw` and `b_UQ1_hw` are declared inside the conditional block `#if 
> NUMBER_OF_HALF_ITERATIONS > 0`. Does `NUMBER_OF_FULL_ITERATIONS != 1` always 
> imply `NUMBER_OF_HALF_ITERATIONS > 0 `?
> Does NUMBER_OF_FULL_ITERATIONS != 1 always imply NUMBER_OF_HALF_ITERATIONS > 

[PATCH] D86308: Reland [compiler-rt] Compile assembly files as ASM not C

2020-08-20 Thread Raul Tambre via Phabricator via cfe-commits
tambre created this revision.
tambre added reviewers: phosek, teemperor.
Herald added subscribers: Sanitizers, cfe-commits, dexonsmith, kristof.beyls, 
mgorny, dberris.
Herald added projects: clang, Sanitizers.
tambre requested review of this revision.

It isn't very wise to pass an assembly file to the compiler and tell it to 
compile as a C file and hope that the compiler recognizes it as assembly 
instead.
Simply don't mark the file as C and CMake will recognize the rest.

[525/634] Building C object 
lib/tsan/CMakeFiles/clang_rt.tsan-aarch64.dir/rtl/tsan_rtl_aarch64.S.o
FAILED: lib/tsan/CMakeFiles/clang_rt.tsan-aarch64.dir/rtl/tsan_rtl_aarch64.S.o
/opt/tooling/drive/host/bin/clang --target=aarch64-linux-gnu 
-I/opt/tooling/drive/llvm/compiler-rt/lib/tsan/.. -isystem 
/opt/tooling/drive/toolchain/opt/drive/toolchain/include -x c -Wall 
-Wno-unused-parameter -fno-lto -fPIC -fno-builtin -fno-exceptions 
-fomit-frame-pointer -funwind-tables -fno-stack-protector 
-fno-sanitize=safe-stack -fvisibility=hidden -fno-lto -O3 -gline-tables-only 
-Wno-gnu -Wno-variadic-macros -Wno-c99-extensions -Wno-non-virtual-dtor -fPIE 
-fno-rtti -Wframe-larger-than=530 -Wglobal-constructors --sysroot=. -MD -MT 
lib/tsan/CMakeFiles/clang_rt.tsan-aarch64.dir/rtl/tsan_rtl_aarch64.S.o -MF 
lib/tsan/CMakeFiles/clang_rt.tsan-aarch64.dir/rtl/tsan_rtl_aarch64.S.o.d -o 
lib/tsan/CMakeFiles/clang_rt.tsan-aarch64.dir/rtl/tsan_rtl_aarch64.S.o -c 
/opt/tooling/drive/llvm/compiler-rt/lib/tsan/rtl/tsan_rtl_aarch64.S
/opt/tooling/drive/llvm/compiler-rt/lib/tsan/rtl/tsan_rtl_aarch64.S:29:1: 
error: expected identifier or '('
.section .text
^
1 error generated.

Additionally fixed Clang not being passed as the assembly compiler for 
compiler-rt runtime build.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D86308

Files:
  clang/runtime/CMakeLists.txt
  compiler-rt/cmake/Modules/AddCompilerRT.cmake


Index: compiler-rt/cmake/Modules/AddCompilerRT.cmake
===
--- compiler-rt/cmake/Modules/AddCompilerRT.cmake
+++ compiler-rt/cmake/Modules/AddCompilerRT.cmake
@@ -109,13 +109,6 @@
 
 function(add_asm_sources output)
   set(${output} ${ARGN} PARENT_SCOPE)
-  # Xcode will try to compile asm files as C ('clang -x c'), and that will 
fail.
-  if (${CMAKE_GENERATOR} STREQUAL "Xcode")
-enable_language(ASM)
-  else()
-# Pass ASM file directly to the C++ compiler.
-set_source_files_properties(${ARGN} PROPERTIES LANGUAGE C)
-  endif()
 endfunction()
 
 macro(set_output_name output name arch)
Index: clang/runtime/CMakeLists.txt
===
--- clang/runtime/CMakeLists.txt
+++ clang/runtime/CMakeLists.txt
@@ -75,6 +75,7 @@
 CMAKE_ARGS ${CLANG_COMPILER_RT_CMAKE_ARGS}
-DCMAKE_C_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang
-DCMAKE_CXX_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang++
+   -DCMAKE_ASM_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM}
-DLLVM_CONFIG_PATH=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-config


Index: compiler-rt/cmake/Modules/AddCompilerRT.cmake
===
--- compiler-rt/cmake/Modules/AddCompilerRT.cmake
+++ compiler-rt/cmake/Modules/AddCompilerRT.cmake
@@ -109,13 +109,6 @@
 
 function(add_asm_sources output)
   set(${output} ${ARGN} PARENT_SCOPE)
-  # Xcode will try to compile asm files as C ('clang -x c'), and that will fail.
-  if (${CMAKE_GENERATOR} STREQUAL "Xcode")
-enable_language(ASM)
-  else()
-# Pass ASM file directly to the C++ compiler.
-set_source_files_properties(${ARGN} PROPERTIES LANGUAGE C)
-  endif()
 endfunction()
 
 macro(set_output_name output name arch)
Index: clang/runtime/CMakeLists.txt
===
--- clang/runtime/CMakeLists.txt
+++ clang/runtime/CMakeLists.txt
@@ -75,6 +75,7 @@
 CMAKE_ARGS ${CLANG_COMPILER_RT_CMAKE_ARGS}
-DCMAKE_C_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang
-DCMAKE_CXX_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang++
+   -DCMAKE_ASM_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM}
-DLLVM_CONFIG_PATH=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-config
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D85692: python bindings: fix DeprecationWarning

2020-08-20 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers added a comment.

In D85692#2227531 , @jdenny wrote:

> Does this mean we officially no longer support python 2, which this change 
> breaks?

Send a patch to support both and I'll approve it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85692

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


[PATCH] D86295: [analyzer] Reorder the layout of MemRegion and cache by hand for optimal size

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

In D86295#2228745 , @xazax.hun wrote:

> But unless you add a comment one will probably replace the offset with an 
> optional as the part of a refactoring.

Sure, I will leave a note.

I was thinking using a PointerIntUnion though. I haven't used it yet, but it's 
mught be a good candidate. What do you think?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86295

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


[PATCH] D86223: [analyzer][z3] Use more elaborate z3 variable names in debug build

2020-08-20 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun added a comment.

In D86223#2228855 , @steakhal wrote:

> I wanted to conditionally, aka. in debug configuration override the base 
> implementation of the SymbolData::getKindStr

I see. Yeah, that does not make much sense. I was thinking about always 
overriding the methods but call them conditionally.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86223

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


[PATCH] D78899: [Driver] Add callback to Command execution

2020-08-20 Thread Serge Pavlov via Phabricator via cfe-commits
sepavloff added a comment.

Ping.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78899

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


[PATCH] D78902: [Driver] Add output file to properties of Command

2020-08-20 Thread Serge Pavlov via Phabricator via cfe-commits
sepavloff added a comment.

Ping.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78902

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


[PATCH] D86223: [analyzer][z3] Use more elaborate z3 variable names in debug build

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

In D86223#2228731 , @xazax.hun wrote:

> In D86223#2227353 , @steakhal wrote:
>
>> Eh, I'm not sure if it worth it to put these into virtual functions - as 
>> conditionally overriding functions is not really a good idea.
>
> I am not sure I follow. What do you mean by conditionally overriding? What is 
> the condition?

I wanted to conditionally, aka. in debug configuration override the base 
implementation of the SymbolData::getKindStr to print return the specific kind 
string. In any other configuration I wanted to indef out the overriding 
functions to let the SymbolData implementation to be triggered.
In that way less macro expansion would have been necessary, resulting in 
cleaner code.

Unfortunately I would have needed even more macros to make the subtype override 
function declarations disappear.

This was the reason that I suggested to leave the current implementation as-is.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86223

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


[PATCH] D77925: Revert "[TLI] Per-function fveclib for math library used for vectorization"

2020-08-20 Thread Wenlei He via Phabricator via cfe-commits
wenlei added a comment.

In D77925#2220177 , @wenlei wrote:

> In D77925#2220169 , @mehdi_amini 
> wrote:
>
>> I rather have a non closed list of veclib: if you just have a map keyed by 
>> string instead of an enum it should just work out?
>
> The veclib type is also tied to the accepted values for `-fveclib`, which is 
> a list of supported lib, anything outside of the list is rejected with error. 
> If you want to allow arbitrary strings as key, it's inconsistent with the 
> restricted/closed values for `-fveclib`. So basically there's no openness 
> from clang/llvm tool, while there was some openness through the libraries. I 
> think by introducing a "Custom" veclib type, we can solve the impedance 
> mismatch there. And in the XLA case, conceptually it's an indeed a custom 
> veclib, right? Functionality-wise, `Custom` should just work for XLA usage 
> too.

@mehdi_amini @tejohnson thoughts on the above?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77925

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


[PATCH] D86229: [X86] Enable constexpr on POPCNT intrinsics (PR31446)

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

Should we test the intrinsics in a constexpr context?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86229

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


[PATCH] D86295: [analyzer] Reorder the layout of MemRegion and cache by hand for optimal size

2020-08-20 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun added a comment.

MemRegion is a popular class to instantiate in the analyzer so it looks good to 
me.
But unless you add a comment one will probably replace the offset with an 
optional as the part of a refactoring.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86295

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


[PATCH] D86223: [analyzer][z3] Use more elaborate z3 variable names in debug build

2020-08-20 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun added a comment.

In D86223#2227353 , @steakhal wrote:

> Eh, I'm not sure if it worth it to put these into virtual functions - as 
> conditionally overriding functions is not really a good idea.

I am not sure I follow. What do you mean by conditionally overriding? What is 
the condition?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86223

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


[PATCH] D85031: [builtins] Unify the softfloat division implementation

2020-08-20 Thread Serge Pavlov via Phabricator via cfe-commits
sepavloff added inline comments.



Comment at: compiler-rt/lib/builtins/fp_div_impl.inc:99
+  //   0 < x0(b) < 1
+  //   abs(x0(b) - 1/b) <= 3/4 - 1/sqrt(2)
+

This estimation is absent from the original comment. Do you have reference 
where it came from? Also the original comment states `This is accurate to about 
3.5 binary digits`. Is still true? If yes, it could be worth copying here.



Comment at: compiler-rt/lib/builtins/fp_div_impl.inc:101-102
+
+  // Then, refine the reciprocal estimate using a Newton-Raphson iteration:
+  // x_{n+1} = x_n * (2 - x_n * b)
+  // Let e_n := x_n - 1/b_hw

The original comment states:
```
  // This doubles the number of correct binary digits in the approximation
  // with each iteration.
```
It is true in this implementation? If yes, it could be worth copying here.



Comment at: compiler-rt/lib/builtins/fp_div_impl.inc:109
+
+#if NUMBER_OF_HALF_ITERATIONS > 0
+  // Starting with (n-1) half-width iterations

It is good optimization. Could you please put a comment shortly describing the 
idea of using half-sized temporaries?



Comment at: compiler-rt/lib/builtins/fp_div_impl.inc:114
+  // C is (3/4 + 1/sqrt(2)) - 1 truncated to W0 fractional bits as UQ0.HW
+#if defined(SINGLE_PRECISION)
+  const half_rep_t C_hw = HALF_REP_C(0x7504) << (HW - 16);

In what cases 16-bit temporaries are used?  `NUMBER_OF_HALF_ITERATIONS` is set 
to zero in `divsf3.c`.



Comment at: compiler-rt/lib/builtins/fp_div_impl.inc:130
+// Cannot overflow by construction and is larger than 2 - b*x by at most 
1*Ulp.
+half_rep_t corr_UQ1_hw = 0 /* = 2 */ - ((rep_t)x_UQ0_hw * b_UQ1_hw >> HW);
+// Would be at most [1.]0 after overflow if rounding (0 - x_UQ0_hw * 
b_UQ1_hw) down.

It would be better to put short comment to explain using 0 instead of 2.



Comment at: compiler-rt/lib/builtins/fp_div_impl.inc:184
+  // x_UQ0 * b_UQ1 = (x_UQ0_hw * 2^HW) * (b_UQ1_hw * 2^HW + blo) - b_UQ1
+  rep_t corr_UQ1 = 0 - (   (rep_t)x_UQ0_hw * b_UQ1_hw
++ ((rep_t)x_UQ0_hw * blo >> HW)

`x_UQ0_hw` and `b_UQ1_hw` are declared inside the conditional block `#if 
NUMBER_OF_HALF_ITERATIONS > 0`. Does `NUMBER_OF_FULL_ITERATIONS != 1` always 
imply `NUMBER_OF_HALF_ITERATIONS > 0 `?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85031

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


[PATCH] D81083: [Clang] Allow "vector_size" applied to Booleans

2020-08-20 Thread Simon Moll via Phabricator via cfe-commits
simoll planned changes to this revision.
simoll marked 6 inline comments as done.
simoll added inline comments.



Comment at: clang/docs/LanguageExtensions.rst:492
+
+The memory representation of a boolean vector is the smallest fitting
+power-of-two integer. The alignment is the alignment of that integer type.  
This

rsandifo-arm wrote:
> It might be worth clarifying this.  With the alignment referring specifically 
> to “integer type”, I wasn't sure what something like:
> 
>   bool __attribute__((vector_size(256)))
> 
> would mean on targets that don't provide 256-byte integer types.  Is the type 
> still 256-byte aligned?
Not exactly: It is the alignment of the corresponding integer type.
For example the following C code:

typedef bool bool256 __attribute__((vector_size(256)));
bool256 P;

gives you (x86_64 host, no machine flags specified):

%P = alloca i2048, align 32



Comment at: clang/include/clang/AST/Type.h:3248
 
+  bool isVectorSizeBoolean() const {
+return (getVectorKind() == VectorKind::GenericVector) &&

rsandifo-arm wrote:
> Maybe isGenericBooleanVector(), so that the terminology is consistent?  Just 
> a suggestion though, not sure if it's an improvement.
I gave it this specific name so where ever it is used, it documents that 
whatever depends on it is specific to vector_size bool. This should be cleaned 
up when a better boolean vector type is introduced.



Comment at: clang/lib/Sema/SemaExpr.cpp:9779
+  return Ty->isBooleanType() ||
+ (Ty->isVectorType() &&
+  Ty->getAs()->getElementType()->isBooleanType());

rsandifo-arm wrote:
> Is this deliberately wider than isVectorSizeBoolean(), or does it amount to 
> the same thing?
That's an artifact. Will narrow this down to `isVectorSizeBoolean()`.



Comment at: clang/lib/Sema/SemaExpr.cpp:11929
  VectorType::GenericVector);
+  else if (TypeSize == Context.getTypeSize(Context.BoolTy))
+return Context.getVectorType(Context.BoolTy, VTy->getNumElements(),

rsandifo-arm wrote:
> In practice, won't this either be a no-op (e.g. for 4-byte-per-bool targets) 
> or always trump the fallback CharTy case?  I wasn't sure why the case was 
> needed.
I guess so. Will remove this case.



Comment at: clang/lib/Sema/SemaExpr.cpp:11956
+  /*AllowBoolConversions*/ getLangOpts().ZVector,
+  /*AllowBooleanOperation*/ false);
   if (vType.isNull())

rsandifo-arm wrote:
> Seems like it might be useful to support comparisons too (with false < true, 
> as for scalars).  E.g. I guess x == y would otherwise need to be written ~(x 
> ^ y), which seems less readable.  Supporting more operators would also help 
> in templated contexts.
Agreed.



Comment at: clang/lib/Sema/SemaExprCXX.cpp:6271
+   /*AllowBoolConversions*/ false,
+   /*AllowBoolOperator*/ false);
 

rsandifo-arm wrote:
> Any reason not to support this for booleans?  ?: seems like a natural 
> operation for all vector element types.
Sure, will allow it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81083

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


[PATCH] D86229: [X86] Enable constexpr on POPCNT intrinsics (PR31446)

2020-08-20 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon updated this revision to Diff 286837.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86229

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Headers/popcntintrin.h
  clang/test/CodeGen/popcnt-builtins.c


Index: clang/test/CodeGen/popcnt-builtins.c
===
--- clang/test/CodeGen/popcnt-builtins.c
+++ clang/test/CodeGen/popcnt-builtins.c
@@ -1,6 +1,7 @@
-// RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin 
-target-feature +popcnt -emit-llvm -o - | FileCheck %s 
--check-prefixes=CHECK,CHECK-POPCNT
-// RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin -emit-llvm -o 
- | FileCheck %s
-
+// RUN: %clang_cc1 -x c -ffreestanding %s -triple=x86_64-apple-darwin 
-target-feature +popcnt -emit-llvm -o - | FileCheck %s 
--check-prefixes=CHECK,CHECK-POPCNT
+// RUN: %clang_cc1 -x c++ -std=c++11 -ffreestanding %s 
-triple=x86_64-apple-darwin -target-feature +popcnt -emit-llvm -o - | FileCheck 
%s --check-prefixes=CHECK,CHECK-POPCNT
+// RUN: %clang_cc1 -x c -ffreestanding %s -triple=x86_64-apple-darwin 
-emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -x c++ -std=c++11 -ffreestanding %s 
-triple=x86_64-apple-darwin -emit-llvm -o - | FileCheck %s
 
 #include 
 
Index: clang/lib/Headers/popcntintrin.h
===
--- clang/lib/Headers/popcntintrin.h
+++ clang/lib/Headers/popcntintrin.h
@@ -13,6 +13,12 @@
 /* Define the default attributes for the functions in this file. */
 #define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__, 
__target__("popcnt")))
 
+#if defined(__cplusplus) && (__cplusplus >= 201103L)
+#define __DEFAULT_FN_ATTRS_CONSTEXPR __DEFAULT_FN_ATTRS constexpr
+#else
+#define __DEFAULT_FN_ATTRS_CONSTEXPR __DEFAULT_FN_ATTRS
+#endif
+
 /// Counts the number of bits in the source operand having a value of 1.
 ///
 /// \headerfile 
@@ -23,7 +29,7 @@
 ///An unsigned 32-bit integer operand.
 /// \returns A 32-bit integer containing the number of bits with value 1 in the
 ///source operand.
-static __inline__ int __DEFAULT_FN_ATTRS
+static __inline__ int __DEFAULT_FN_ATTRS_CONSTEXPR
 _mm_popcnt_u32(unsigned int __A)
 {
   return __builtin_popcount(__A);
@@ -40,7 +46,7 @@
 ///An unsigned 64-bit integer operand.
 /// \returns A 64-bit integer containing the number of bits with value 1 in the
 ///source operand.
-static __inline__ long long __DEFAULT_FN_ATTRS
+static __inline__ long long __DEFAULT_FN_ATTRS_CONSTEXPR
 _mm_popcnt_u64(unsigned long long __A)
 {
   return __builtin_popcountll(__A);
@@ -48,5 +54,6 @@
 #endif /* __x86_64__ */
 
 #undef __DEFAULT_FN_ATTRS
+#undef __DEFAULT_FN_ATTRS_CONSTEXPR
 
 #endif /* __POPCNTINTRIN_H */
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -153,6 +153,12 @@
 
 - ...
 
+X86 Support in Clang
+
+
+- The x86 intrinsics ``_mm_popcnt_u32`` and ``_mm_popcnt_u64`` may now be used
+  within constexpr expressions.
+
 Internal API Changes
 
 


Index: clang/test/CodeGen/popcnt-builtins.c
===
--- clang/test/CodeGen/popcnt-builtins.c
+++ clang/test/CodeGen/popcnt-builtins.c
@@ -1,6 +1,7 @@
-// RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +popcnt -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,CHECK-POPCNT
-// RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin -emit-llvm -o - | FileCheck %s
-
+// RUN: %clang_cc1 -x c -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +popcnt -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,CHECK-POPCNT
+// RUN: %clang_cc1 -x c++ -std=c++11 -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +popcnt -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,CHECK-POPCNT
+// RUN: %clang_cc1 -x c -ffreestanding %s -triple=x86_64-apple-darwin -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -x c++ -std=c++11 -ffreestanding %s -triple=x86_64-apple-darwin -emit-llvm -o - | FileCheck %s
 
 #include 
 
Index: clang/lib/Headers/popcntintrin.h
===
--- clang/lib/Headers/popcntintrin.h
+++ clang/lib/Headers/popcntintrin.h
@@ -13,6 +13,12 @@
 /* Define the default attributes for the functions in this file. */
 #define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__, __target__("popcnt")))
 
+#if defined(__cplusplus) && (__cplusplus >= 201103L)
+#define __DEFAULT_FN_ATTRS_CONSTEXPR __DEFAULT_FN_ATTRS constexpr
+#else
+#define __DEFAULT_FN_ATTRS_CONSTEXPR __DEFAULT_FN_ATTRS
+#endif
+
 /// Counts the number of bits in the source operand having a value of 1.
 ///
 /// \headerfile 
@@ -23,7 +29,7 @@
 ///An unsigned 32-bit integer 

[PATCH] D86229: [X86] Enable constexpr on POPCNT intrinsics (PR31446)

2020-08-20 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon updated this revision to Diff 286835.
RKSimon added a comment.

Added release note entry - this will need to revised as we add more intrinsics, 
so is just an initial placeholder.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86229

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Headers/popcntintrin.h
  clang/test/CodeGen/popcnt-builtins.c


Index: clang/test/CodeGen/popcnt-builtins.c
===
--- clang/test/CodeGen/popcnt-builtins.c
+++ clang/test/CodeGen/popcnt-builtins.c
@@ -1,6 +1,7 @@
-// RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin 
-target-feature +popcnt -emit-llvm -o - | FileCheck %s 
--check-prefixes=CHECK,CHECK-POPCNT
-// RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin -emit-llvm -o 
- | FileCheck %s
-
+// RUN: %clang_cc1 -x c -ffreestanding %s -triple=x86_64-apple-darwin 
-target-feature +popcnt -emit-llvm -o - | FileCheck %s 
--check-prefixes=CHECK,CHECK-POPCNT
+// RUN: %clang_cc1 -x c++ -std=c++11 -ffreestanding %s 
-triple=x86_64-apple-darwin -target-feature +popcnt -emit-llvm -o - | FileCheck 
%s --check-prefixes=CHECK,CHECK-POPCNT
+// RUN: %clang_cc1 -x c -ffreestanding %s -triple=x86_64-apple-darwin 
-emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -x c++ -std=c++11 -ffreestanding %s 
-triple=x86_64-apple-darwin -emit-llvm -o - | FileCheck %s
 
 #include 
 
Index: clang/lib/Headers/popcntintrin.h
===
--- clang/lib/Headers/popcntintrin.h
+++ clang/lib/Headers/popcntintrin.h
@@ -13,6 +13,12 @@
 /* Define the default attributes for the functions in this file. */
 #define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__, 
__target__("popcnt")))
 
+#if defined(__cplusplus) && (__cplusplus >= 201103L)
+#define __DEFAULT_FN_ATTRS_CONSTEXPR __DEFAULT_FN_ATTRS constexpr
+#else
+#define __DEFAULT_FN_ATTRS_CONSTEXPR __DEFAULT_FN_ATTRS
+#endif
+
 /// Counts the number of bits in the source operand having a value of 1.
 ///
 /// \headerfile 
@@ -23,7 +29,7 @@
 ///An unsigned 32-bit integer operand.
 /// \returns A 32-bit integer containing the number of bits with value 1 in the
 ///source operand.
-static __inline__ int __DEFAULT_FN_ATTRS
+static __inline__ int __DEFAULT_FN_ATTRS_CONSTEXPR
 _mm_popcnt_u32(unsigned int __A)
 {
   return __builtin_popcount(__A);
@@ -40,7 +46,7 @@
 ///An unsigned 64-bit integer operand.
 /// \returns A 64-bit integer containing the number of bits with value 1 in the
 ///source operand.
-static __inline__ long long __DEFAULT_FN_ATTRS
+static __inline__ long long __DEFAULT_FN_ATTRS_CONSTEXPR
 _mm_popcnt_u64(unsigned long long __A)
 {
   return __builtin_popcountll(__A);
@@ -48,5 +54,6 @@
 #endif /* __x86_64__ */
 
 #undef __DEFAULT_FN_ATTRS
+#undef __DEFAULT_FN_ATTRS_CONSTEXPR
 
 #endif /* __POPCNTINTRIN_H */
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -153,6 +153,12 @@
 
 - ...
 
+X86 Support in Clang
+
+
+- The x86 intrinsics _mm_popcnt_u32 and _mm_popcnt_u64 may now be used
+  within constexpr expressions.
+
 Internal API Changes
 
 


Index: clang/test/CodeGen/popcnt-builtins.c
===
--- clang/test/CodeGen/popcnt-builtins.c
+++ clang/test/CodeGen/popcnt-builtins.c
@@ -1,6 +1,7 @@
-// RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +popcnt -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,CHECK-POPCNT
-// RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin -emit-llvm -o - | FileCheck %s
-
+// RUN: %clang_cc1 -x c -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +popcnt -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,CHECK-POPCNT
+// RUN: %clang_cc1 -x c++ -std=c++11 -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +popcnt -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,CHECK-POPCNT
+// RUN: %clang_cc1 -x c -ffreestanding %s -triple=x86_64-apple-darwin -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -x c++ -std=c++11 -ffreestanding %s -triple=x86_64-apple-darwin -emit-llvm -o - | FileCheck %s
 
 #include 
 
Index: clang/lib/Headers/popcntintrin.h
===
--- clang/lib/Headers/popcntintrin.h
+++ clang/lib/Headers/popcntintrin.h
@@ -13,6 +13,12 @@
 /* Define the default attributes for the functions in this file. */
 #define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__, __target__("popcnt")))
 
+#if defined(__cplusplus) && (__cplusplus >= 201103L)
+#define __DEFAULT_FN_ATTRS_CONSTEXPR __DEFAULT_FN_ATTRS constexpr
+#else
+#define __DEFAULT_FN_ATTRS_CONSTEXPR __DEFAULT_FN_ATTRS
+#endif
+
 /// Counts the number 

[PATCH] D84414: [RISCV] Support Shadow Call Stack

2020-08-20 Thread Sam Elliott via Phabricator via cfe-commits
lenary added a comment.

In D84414#2186257 , @jrtc27 wrote:

> There is a possibly-compelling argument against using x18: RV32E only gives 
> x0-x15, so would not be able to support the current implementation.

We discussed this on the RISC-V LLVM Sync-up (both this time and on 6 August 
2020 IIRC). The consensus view is: if you're on an rv32e implementation, you're 
potentially too constrained to use a shadow call stack anyway. Even then, LLVM 
doesn't implement the rest of rv32e yet (though there are plans to do so at 
some point, which means we can revisit this change).

Our feeling is that if users have a distinct need to use a different register 
at the moment, they can use a downstream change to LLVM. The fact that we use 
`RISCVABI::getSCSPReg()` should make this fairly easy.

---

If the register choice is the only concern about this work, then I think we can 
probably land it as-is and fixup the register choice if we see major drawbacks 
later. Yes, it's an ABI issue, but on the other hand the shadow call stack is 
not a standard ABI anyway.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84414

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


[PATCH] D86299: [compiler-rt][builtins] Factor out some common bit manipulations

2020-08-20 Thread Anatoly Trosinenko via Phabricator via cfe-commits
atrosinenko created this revision.
atrosinenko added reviewers: howard.hinnant, jfb, vsk, lebedev.ri.
Herald added subscribers: Sanitizers, dexonsmith, dberris.
Herald added a project: Sanitizers.
atrosinenko requested review of this revision.

This patch incapsulates some commonly used hacks in a (hopefully) UB-free 
manner.

Some existing LibCall implementations contain constants like this one:

  const di_int MIN = (di_int)1 << ((int)(sizeof(di_int) * CHAR_BIT) - 1);

UBSan complains on such expressions and that seems to be true positive.

This patch is expected to be NFC except for eliminating some UB. It consists of 
the following parts:

- implementing helpers in `int_types.h`
- replacing some `typedef`s with `#define`s so these type alises can be handled 
by the above machinery
- replacing some constants with these common helper invocations
  - this is expected to be unable to cause any performance regressions as these 
are actually **compile-time** constants
- fixing a couple of UBs in `__neg?i2` LibCalls


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D86299

Files:
  compiler-rt/lib/builtins/fixdfdi.c
  compiler-rt/lib/builtins/fixdfsi.c
  compiler-rt/lib/builtins/fixdfti.c
  compiler-rt/lib/builtins/fixsfdi.c
  compiler-rt/lib/builtins/fixsfsi.c
  compiler-rt/lib/builtins/fixsfti.c
  compiler-rt/lib/builtins/fixtfdi.c
  compiler-rt/lib/builtins/fixtfsi.c
  compiler-rt/lib/builtins/fixtfti.c
  compiler-rt/lib/builtins/fp_fixint_impl.inc
  compiler-rt/lib/builtins/int_mulo_impl.inc
  compiler-rt/lib/builtins/int_mulv_impl.inc
  compiler-rt/lib/builtins/int_types.h
  compiler-rt/lib/builtins/negdi2.c
  compiler-rt/lib/builtins/negti2.c
  compiler-rt/lib/builtins/negvdi2.c
  compiler-rt/lib/builtins/negvsi2.c
  compiler-rt/lib/builtins/negvti2.c

Index: compiler-rt/lib/builtins/negvti2.c
===
--- compiler-rt/lib/builtins/negvti2.c
+++ compiler-rt/lib/builtins/negvti2.c
@@ -19,8 +19,7 @@
 // Effects: aborts if -a overflows
 
 COMPILER_RT_ABI ti_int __negvti2(ti_int a) {
-  const ti_int MIN = (ti_int)1 << ((int)(sizeof(ti_int) * CHAR_BIT) - 1);
-  if (a == MIN)
+  if (a == MIN_SIGNED(ti_int))
 compilerrt_abort();
   return -a;
 }
Index: compiler-rt/lib/builtins/negvsi2.c
===
--- compiler-rt/lib/builtins/negvsi2.c
+++ compiler-rt/lib/builtins/negvsi2.c
@@ -17,8 +17,7 @@
 // Effects: aborts if -a overflows
 
 COMPILER_RT_ABI si_int __negvsi2(si_int a) {
-  const si_int MIN = (si_int)1 << ((int)(sizeof(si_int) * CHAR_BIT) - 1);
-  if (a == MIN)
+  if (a == MIN_SIGNED(si_int))
 compilerrt_abort();
   return -a;
 }
Index: compiler-rt/lib/builtins/negvdi2.c
===
--- compiler-rt/lib/builtins/negvdi2.c
+++ compiler-rt/lib/builtins/negvdi2.c
@@ -17,8 +17,7 @@
 // Effects: aborts if -a overflows
 
 COMPILER_RT_ABI di_int __negvdi2(di_int a) {
-  const di_int MIN = (di_int)1 << ((int)(sizeof(di_int) * CHAR_BIT) - 1);
-  if (a == MIN)
+  if (a == MIN_SIGNED(di_int))
 compilerrt_abort();
   return -a;
 }
Index: compiler-rt/lib/builtins/negti2.c
===
--- compiler-rt/lib/builtins/negti2.c
+++ compiler-rt/lib/builtins/negti2.c
@@ -19,7 +19,7 @@
 COMPILER_RT_ABI ti_int __negti2(ti_int a) {
   // Note: this routine is here for API compatibility; any sane compiler
   // should expand it inline.
-  return -a;
+  return -(tu_int)a;
 }
 
 #endif // CRT_HAS_128BIT
Index: compiler-rt/lib/builtins/negdi2.c
===
--- compiler-rt/lib/builtins/negdi2.c
+++ compiler-rt/lib/builtins/negdi2.c
@@ -17,5 +17,5 @@
 COMPILER_RT_ABI di_int __negdi2(di_int a) {
   // Note: this routine is here for API compatibility; any sane compiler
   // should expand it inline.
-  return -a;
+  return -(du_int)a;
 }
Index: compiler-rt/lib/builtins/int_types.h
===
--- compiler-rt/lib/builtins/int_types.h
+++ compiler-rt/lib/builtins/int_types.h
@@ -1,4 +1,4 @@
-//===-- int_lib.h - configuration header for compiler-rt  -===//
+//===-- int_types.h - type definitions for compiler-rt ===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -37,6 +37,30 @@
 typedef int64_t di_int;
 typedef uint64_t du_int;
 
+// Helpers for standard type aliases to get signed from unsigned and vice versa
+#define AS_SIGNED(type) type##_AS_SIGNED
+#define AS_UNSIGNED(type) type##_AS_UNSIGNED
+#define si_int_AS_SIGNED si_int
+#define su_int_AS_SIGNED si_int
+#define di_int_AS_SIGNED di_int
+#define du_int_AS_SIGNED di_int
+#define ti_int_AS_SIGNED ti_int
+#define tu_int_AS_SIGNED ti_int
+#define si_int_AS_UNSIGNED su_int
+#define 

[PATCH] D86298: [SyntaxTree] Add support for `this`

2020-08-20 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
eduucaldas requested review of this revision.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D86298

Files:
  clang/include/clang/Tooling/Syntax/Nodes.h
  clang/lib/Tooling/Syntax/BuildTree.cpp
  clang/lib/Tooling/Syntax/Nodes.cpp
  clang/unittests/Tooling/Syntax/BuildTreeTest.cpp

Index: clang/unittests/Tooling/Syntax/BuildTreeTest.cpp
===
--- clang/unittests/Tooling/Syntax/BuildTreeTest.cpp
+++ clang/unittests/Tooling/Syntax/BuildTreeTest.cpp
@@ -905,6 +905,68 @@
 )txt"}));
 }
 
+TEST_P(SyntaxTreeTest, This_Simple) {
+  if (!GetParam().isCXX()) {
+return;
+  }
+  EXPECT_TRUE(treeDumpEqualOnAnnotations(
+  R"cpp(
+struct S {
+  S* test(){
+return [[this]];
+  }
+};
+)cpp",
+  {R"txt(
+ThisExpression
+`-this
+)txt"}));
+}
+
+TEST_P(SyntaxTreeTest, This_ExplicitMemberAccess) {
+  if (!GetParam().isCXX()) {
+return;
+  }
+  EXPECT_TRUE(treeDumpEqualOnAnnotations(
+  R"cpp(
+struct S {
+  int a;
+  void test(){
+[[this->a]];
+  }
+};
+)cpp",
+  {R"txt(
+MemberExpression
+|-ThisExpression
+| `-this
+|-->
+`-IdExpression
+  `-UnqualifiedId
+`-a
+)txt"}));
+}
+
+TEST_P(SyntaxTreeTest, This_ImplicitMemberAccess) {
+  if (!GetParam().isCXX()) {
+return;
+  }
+  EXPECT_TRUE(treeDumpEqualOnAnnotations(
+  R"cpp(
+struct S {
+  int a;
+  void test(){
+[[a]];
+  }
+};
+)cpp",
+  {R"txt(
+IdExpression
+`-UnqualifiedId
+  `-a
+)txt"}));
+}
+
 TEST_P(SyntaxTreeTest, ParenExpr) {
   EXPECT_TRUE(treeDumpEqualOnAnnotations(
   R"cpp(
@@ -2099,29 +2161,6 @@
 )txt"}));
 }
 
-TEST_P(SyntaxTreeTest, MemberExpression_Implicit) {
-  if (!GetParam().isCXX()) {
-return;
-  }
-  EXPECT_TRUE(treeDumpEqualOnAnnotations(
-  R"cpp(
-struct S {
-  int a;
-  int test(){
-// FIXME: Remove the `UnknownExpression` wrapping `a`. This
-// `UnknownExpression` comes from an implicit leaf `CXXThisExpr`.
-[[a]];
-  }
-};
-)cpp",
-  {R"txt(
-IdExpression
-`-UnqualifiedId
-  `-UnknownExpression
-`-a
-)txt"}));
-}
-
 TEST_P(SyntaxTreeTest, MemberExpression_VariableTemplate) {
   if (!GetParam().isCXX14OrLater()) {
 return;
Index: clang/lib/Tooling/Syntax/Nodes.cpp
===
--- clang/lib/Tooling/Syntax/Nodes.cpp
+++ clang/lib/Tooling/Syntax/Nodes.cpp
@@ -20,6 +20,8 @@
 return OS << "UnknownExpression";
   case NodeKind::ParenExpression:
 return OS << "ParenExpression";
+  case NodeKind::ThisExpression:
+return OS << "ThisExpression";
   case NodeKind::IntegerLiteralExpression:
 return OS << "IntegerLiteralExpression";
   case NodeKind::CharacterLiteralExpression:
@@ -286,6 +288,11 @@
   return cast_or_null(findChild(syntax::NodeRole::CloseParen));
 }
 
+syntax::Leaf *syntax::ThisExpression::thisKeyword() {
+  return cast_or_null(
+  findChild(syntax::NodeRole::IntroducerKeyword));
+}
+
 syntax::Leaf *syntax::LiteralExpression::literalToken() {
   return cast_or_null(findChild(syntax::NodeRole::LiteralToken));
 }
Index: clang/lib/Tooling/Syntax/BuildTree.cpp
===
--- clang/lib/Tooling/Syntax/BuildTree.cpp
+++ clang/lib/Tooling/Syntax/BuildTree.cpp
@@ -950,6 +950,16 @@
 return true;
   }
 
+  bool WalkUpFromCXXThisExpr(CXXThisExpr *S) {
+if (!S->isImplicit()) {
+  Builder.markChildToken(S->getLocation(),
+ syntax::NodeRole::IntroducerKeyword);
+  Builder.foldNode(Builder.getExprRange(S),
+   new (allocator()) syntax::ThisExpression, S);
+}
+return true;
+  }
+
   bool WalkUpFromParenExpr(ParenExpr *S) {
 Builder.markChildToken(S->getLParen(), syntax::NodeRole::OpenParen);
 Builder.markExprChild(S->getSubExpr(),
Index: clang/include/clang/Tooling/Syntax/Nodes.h
===
--- clang/include/clang/Tooling/Syntax/Nodes.h
+++ clang/include/clang/Tooling/Syntax/Nodes.h
@@ -56,6 +56,7 @@
   StringUserDefinedLiteralExpression,
   IdExpression,
   MemberExpression,
+  ThisExpression,
 
   // Statements.
   UnknownStatement,
@@ -313,6 +314,16 @@
   }
 };
 
+/// Models a this expression `this`. C++ [expr.prim.this]
+class ThisExpression final : public Expression {
+public:
+  ThisExpression() : Expression(NodeKind::ThisExpression) {}
+  static bool classof(const Node *N) {
+return N->kind() == NodeKind::ThisExpression;
+  }
+  Leaf *thisKeyword();
+};
+
 /// Models a parenthesized expression `(E)`. C++ [expr.prim.paren]
 /// e.g. `(3 + 2)` in `a = 1 + (3 + 2);`
 class ParenExpression final : public Expression {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D86065: [SVE] Make ElementCount members private

2020-08-20 Thread David Sherwood via Phabricator via cfe-commits
david-arm added a comment.

Hi @ctetreau, I agree with @efriedma that keeping the two classes distinct for 
now seems best. The reason is I spent quite a lot of time trying to unify these 
classes already and I hit a stumbling block - TypeSize has the ugly uint64_t() 
cast operator, which makes unifying difficult. I didn't want to introduce a 
templated cast operator that ElementCount would then have too. I also tried 
making TypeSize derive from a templated parent, but that was pretty ugly too. 
Perhaps once we've removed the TypeSize -> uint64_t we might be better able to 
consider it?




Comment at: llvm/include/llvm/Support/TypeSize.h:56
 
+  friend bool operator>(const ElementCount , const ElementCount ) {
+assert(LHS.Scalable == RHS.Scalable &&

ctetreau wrote:
> fpetrogalli wrote:
> > I think that @ctetreau is right on 
> > https://reviews.llvm.org/D85794#inline-793909. We should not overload a 
> > comparison operator on this class because the set it represent it cannot be 
> > ordered.
> > 
> > Chris suggests an approach of writing a static function that can be used as 
> > a comparison operator,  so that we can make it explicit of what kind of 
> > comparison we  are doing. 
> In C++, it's common to overload the comparison operators for the purposes of 
> being able to std::sort and use ordered sets. Normally, I would be OK with 
> such usages. However, since `ElementCount` is basically a numeric type, and 
> they only have a partial ordering, I think this is dangerous. I'm concerned 
> that this will result in more bugs whereby somebody didn't remember that 
> vectors can be scalable.
> 
> I don't have a strong opinion what the comparator function should be called, 
> but I strongly prefer that it not be a comparison operator.
Hi @ctetreau, yeah I understand. The reason I chose to use operators was simply 
to be consistent with what we have already in TypeSize. Also, we have existing 
"==" and "!=" operators in ElementCount too, although these are essentially 
testing that two ElementCounts are identically the same or not, i.e. for 2 
given polynomials (a + bx) and (c + dx) we're essentially asking if both a==c 
and b==d.

If I introduce a new comparison function, I'll probably keep the asserts in for 
now, but in general we can do better than simply asserting if something is 
scalable or not. For example, we know that (vscale * 4) is definitely >= 4 
because vscale is at least 1. I'm just not sure if we have that need yet.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86065

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


[PATCH] D86139: [SyntaxTree] Split tests related to Namespace

2020-08-20 Thread Eduardo Caldas 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 rGe4e983e24043: [SyntaxTree] Split tests related to Namespace 
(authored by eduucaldas).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86139

Files:
  clang/unittests/Tooling/Syntax/BuildTreeTest.cpp

Index: clang/unittests/Tooling/Syntax/BuildTreeTest.cpp
===
--- clang/unittests/Tooling/Syntax/BuildTreeTest.cpp
+++ clang/unittests/Tooling/Syntax/BuildTreeTest.cpp
@@ -2454,7 +2454,7 @@
 )txt"));
 }
 
-TEST_P(SyntaxTreeTest, Namespaces) {
+TEST_P(SyntaxTreeTest, Namespace_Nested) {
   if (!GetParam().isCXX()) {
 return;
   }
@@ -2462,9 +2462,6 @@
   R"cpp(
 namespace a { namespace b {} }
 namespace a::b {}
-namespace {}
-
-namespace foo = a;
 )cpp",
   R"txt(
 *: TranslationUnit
@@ -2478,82 +2475,91 @@
 | | |-{
 | | `-}
 | `-}
-|-NamespaceDefinition
-| |-namespace
-| |-a
-| |-::
-| |-b
-| |-{
-| `-}
-|-NamespaceDefinition
-| |-namespace
-| |-{
-| `-}
-`-NamespaceAliasDefinition
+`-NamespaceDefinition
   |-namespace
-  |-foo
-  |-=
   |-a
-  `-;
+  |-::
+  |-b
+  |-{
+  `-}
 )txt"));
 }
 
-TEST_P(SyntaxTreeTest, UsingDirective) {
+TEST_P(SyntaxTreeTest, Namespace_Unnamed) {
   if (!GetParam().isCXX()) {
 return;
   }
   EXPECT_TRUE(treeDumpEqual(
   R"cpp(
-namespace ns {}
-using namespace ::ns;
+namespace {}
 )cpp",
   R"txt(
 *: TranslationUnit
-|-NamespaceDefinition
-| |-namespace
-| |-ns
-| |-{
-| `-}
-`-UsingNamespaceDirective
-  |-using
+`-NamespaceDefinition
   |-namespace
-  |-NestedNameSpecifier
-  | `-::
-  |-ns
-  `-;
+  |-{
+  `-}
 )txt"));
 }
 
+TEST_P(SyntaxTreeTest, Namespace_Alias) {
+  if (!GetParam().isCXX()) {
+return;
+  }
+  EXPECT_TRUE(treeDumpEqualOnAnnotations(
+  R"cpp(
+namespace a {}
+[[namespace foo = a;]]
+)cpp",
+  {R"txt(
+NamespaceAliasDefinition
+|-namespace
+|-foo
+|-=
+|-a
+`-;
+)txt"}));
+}
+
+TEST_P(SyntaxTreeTest, UsingDirective) {
+  if (!GetParam().isCXX()) {
+return;
+  }
+  EXPECT_TRUE(treeDumpEqualOnAnnotations(
+  R"cpp(
+namespace ns {}
+[[using namespace ::ns;]]
+)cpp",
+  {R"txt(
+UsingNamespaceDirective
+|-using
+|-namespace
+|-NestedNameSpecifier
+| `-::
+|-ns
+`-;
+)txt"}));
+}
+
 TEST_P(SyntaxTreeTest, UsingDeclaration) {
   if (!GetParam().isCXX()) {
 return;
   }
-  EXPECT_TRUE(treeDumpEqual(
+  EXPECT_TRUE(treeDumpEqualOnAnnotations(
   R"cpp(
 namespace ns { int a; }
-using ns::a;
+[[using ns::a;]]
 )cpp",
-  R"txt(
-*: TranslationUnit
-|-NamespaceDefinition
-| |-namespace
-| |-ns
-| |-{
-| |-SimpleDeclaration
-| | |-int
-| | |-SimpleDeclarator
-| | | `-a
-| | `-;
-| `-}
-`-UsingDeclaration
-  |-using
-  |-NestedNameSpecifier
-  | |-IdentifierNameSpecifier
-  | | `-ns
-  | `-::
-  |-a
-  `-;
-)txt"));
+  {R"txt(
+UsingDeclaration
+|-using
+|-NestedNameSpecifier
+| |-IdentifierNameSpecifier
+| | `-ns
+| `-::
+|-a
+`-;
+)txt"}));
 }
 
 TEST_P(SyntaxTreeTest, FreeStandingClasses) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] e4e983e - [SyntaxTree] Split tests related to Namespace

2020-08-20 Thread Eduardo Caldas via cfe-commits

Author: Eduardo Caldas
Date: 2020-08-20T15:14:56Z
New Revision: e4e983e240430b3a0dc92402cc940292bd0d263f

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

LOG: [SyntaxTree] Split tests related to Namespace

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

Added: 


Modified: 
clang/unittests/Tooling/Syntax/BuildTreeTest.cpp

Removed: 




diff  --git a/clang/unittests/Tooling/Syntax/BuildTreeTest.cpp 
b/clang/unittests/Tooling/Syntax/BuildTreeTest.cpp
index 2692c1f6ff58..a3e86dac50c5 100644
--- a/clang/unittests/Tooling/Syntax/BuildTreeTest.cpp
+++ b/clang/unittests/Tooling/Syntax/BuildTreeTest.cpp
@@ -2454,7 +2454,7 @@ typedef decltype(sizeof(void *)) size_t;
 )txt"));
 }
 
-TEST_P(SyntaxTreeTest, Namespaces) {
+TEST_P(SyntaxTreeTest, Namespace_Nested) {
   if (!GetParam().isCXX()) {
 return;
   }
@@ -2462,9 +2462,6 @@ TEST_P(SyntaxTreeTest, Namespaces) {
   R"cpp(
 namespace a { namespace b {} }
 namespace a::b {}
-namespace {}
-
-namespace foo = a;
 )cpp",
   R"txt(
 *: TranslationUnit
@@ -2478,82 +2475,91 @@ namespace foo = a;
 | | |-{
 | | `-}
 | `-}
-|-NamespaceDefinition
-| |-namespace
-| |-a
-| |-::
-| |-b
-| |-{
-| `-}
-|-NamespaceDefinition
-| |-namespace
-| |-{
-| `-}
-`-NamespaceAliasDefinition
+`-NamespaceDefinition
   |-namespace
-  |-foo
-  |-=
   |-a
-  `-;
+  |-::
+  |-b
+  |-{
+  `-}
 )txt"));
 }
 
-TEST_P(SyntaxTreeTest, UsingDirective) {
+TEST_P(SyntaxTreeTest, Namespace_Unnamed) {
   if (!GetParam().isCXX()) {
 return;
   }
   EXPECT_TRUE(treeDumpEqual(
   R"cpp(
-namespace ns {}
-using namespace ::ns;
+namespace {}
 )cpp",
   R"txt(
 *: TranslationUnit
-|-NamespaceDefinition
-| |-namespace
-| |-ns
-| |-{
-| `-}
-`-UsingNamespaceDirective
-  |-using
+`-NamespaceDefinition
   |-namespace
-  |-NestedNameSpecifier
-  | `-::
-  |-ns
-  `-;
+  |-{
+  `-}
 )txt"));
 }
 
+TEST_P(SyntaxTreeTest, Namespace_Alias) {
+  if (!GetParam().isCXX()) {
+return;
+  }
+  EXPECT_TRUE(treeDumpEqualOnAnnotations(
+  R"cpp(
+namespace a {}
+[[namespace foo = a;]]
+)cpp",
+  {R"txt(
+NamespaceAliasDefinition
+|-namespace
+|-foo
+|-=
+|-a
+`-;
+)txt"}));
+}
+
+TEST_P(SyntaxTreeTest, UsingDirective) {
+  if (!GetParam().isCXX()) {
+return;
+  }
+  EXPECT_TRUE(treeDumpEqualOnAnnotations(
+  R"cpp(
+namespace ns {}
+[[using namespace ::ns;]]
+)cpp",
+  {R"txt(
+UsingNamespaceDirective
+|-using
+|-namespace
+|-NestedNameSpecifier
+| `-::
+|-ns
+`-;
+)txt"}));
+}
+
 TEST_P(SyntaxTreeTest, UsingDeclaration) {
   if (!GetParam().isCXX()) {
 return;
   }
-  EXPECT_TRUE(treeDumpEqual(
+  EXPECT_TRUE(treeDumpEqualOnAnnotations(
   R"cpp(
 namespace ns { int a; }
-using ns::a;
+[[using ns::a;]]
 )cpp",
-  R"txt(
-*: TranslationUnit
-|-NamespaceDefinition
-| |-namespace
-| |-ns
-| |-{
-| |-SimpleDeclaration
-| | |-int
-| | |-SimpleDeclarator
-| | | `-a
-| | `-;
-| `-}
-`-UsingDeclaration
-  |-using
-  |-NestedNameSpecifier
-  | |-IdentifierNameSpecifier
-  | | `-ns
-  | `-::
-  |-a
-  `-;
-)txt"));
+  {R"txt(
+UsingDeclaration
+|-using
+|-NestedNameSpecifier
+| |-IdentifierNameSpecifier
+| | `-ns
+| `-::
+|-a
+`-;
+)txt"}));
 }
 
 TEST_P(SyntaxTreeTest, FreeStandingClasses) {



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


[PATCH] D86295: [analyzer] Reorder the the layout of MemRegion and cache by hand for optimal size

2020-08-20 Thread Balázs Benics via Phabricator via cfe-commits
steakhal created this revision.
steakhal added reviewers: NoQ, xazax.hun, Szelethus, vsavchenko, ASDenysPetrov.
Herald added subscribers: cfe-commits, martong, Charusso, dkrupp, donat.nagy, 
mikhail.ramalho, a.sidorin, rnkovacs, szepet, baloghadamsoftware, whisperity.
Herald added a project: clang.
steakhal requested review of this revision.

By the time working on the gdb pretty-printers for the Analyzer classes,
I observed that the `MemRegion` class has an inefficient memory layout.

Each and every object which's has a `MemRegion` as a subobject would benefit 
from this change.
We could spare 8 bytes for each case.

As a downside, I had to substitute the `llvm::Optional`, since that alone 
consumes 16 bytes (even if the wrapped object would consume 8 bytes :| ).

Before the patch: `sizeof(MemRegion) == 48`

  (gdb) ptype /o class MemRegion
  /* offset|  size */  type = class clang::ento::MemRegion : public 
llvm::FoldingSetBase::Node {
   private:
  /*   16  | 4 */const clang::ento::MemRegion::Kind kind;
  /* XXX  4-byte hole  */
  /*   24  |24 */class llvm::Optional 
[with T = clang::ento::RegionOffset] {
   private:
  /*   24  |24 */class 
llvm::optional_detail::OptionalStorage [with T = T] {
   private:
  /*   24  |16 */union {
  /* 1 */char empty;
  /*16 */T value;
  
 /* total size (bytes):   16 */
 };
  /*   40  | 1 */bool hasVal;
  
 /* total size (bytes):   24 */
 } Storage;
  
 /* total size (bytes):   24 */
 } cachedOffset;
  
 /* total size (bytes):   48 */
   }

After the patch: `sizeof(MemRegion) == 40`

  (gdb) ptype /o MemRegion
  /* offset|  size */  type = class clang::ento::MemRegion : public 
llvm::FoldingSetBase::Node {
   private:
  /*   16  |16 */class clang::ento::RegionOffset {
   private:
  /*   16  | 8 */const clang::ento::MemRegion *R;
  /*   24  | 8 */int64_t Offset;
   public:
 static const int64_t Symbolic;
  
 /* total size (bytes):   16 */
 } cachedOffset;
  /*   32  | 4 */const clang::ento::MemRegion::Kind kind;
  /*   36  | 1 */bool hasCachedOffset;
  
 /* total size (bytes):   40 */
   }


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D86295

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


Index: clang/lib/StaticAnalyzer/Core/MemRegion.cpp
===
--- clang/lib/StaticAnalyzer/Core/MemRegion.cpp
+++ clang/lib/StaticAnalyzer/Core/MemRegion.cpp
@@ -1579,9 +1579,11 @@
 }
 
 RegionOffset MemRegion::getAsOffset() const {
-  if (!cachedOffset)
+  if (!hasCachedOffset) {
 cachedOffset = calculateOffset(this);
-  return *cachedOffset;
+hasCachedOffset = true;
+  }
+  return cachedOffset;
 }
 
 
//===--===//
Index: clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
===
--- clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
+++ clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
@@ -100,8 +100,9 @@
   };
 
 private:
+  mutable RegionOffset cachedOffset;
   const Kind kind;
-  mutable Optional cachedOffset;
+  mutable bool hasCachedOffset = false;
 
 protected:
   MemRegion(Kind k) : kind(k) {}


Index: clang/lib/StaticAnalyzer/Core/MemRegion.cpp
===
--- clang/lib/StaticAnalyzer/Core/MemRegion.cpp
+++ clang/lib/StaticAnalyzer/Core/MemRegion.cpp
@@ -1579,9 +1579,11 @@
 }
 
 RegionOffset MemRegion::getAsOffset() const {
-  if (!cachedOffset)
+  if (!hasCachedOffset) {
 cachedOffset = calculateOffset(this);
-  return *cachedOffset;
+hasCachedOffset = true;
+  }
+  return cachedOffset;
 }
 
 //===--===//
Index: clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
===
--- clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
+++ clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
@@ -100,8 +100,9 @@
   };
 
 private:
+  mutable RegionOffset 

[PATCH] D86139: [SyntaxTree] Split tests related to Namespace

2020-08-20 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas updated this revision to Diff 286823.
eduucaldas marked 2 inline comments as done.
eduucaldas added a comment.

answer comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86139

Files:
  clang/unittests/Tooling/Syntax/BuildTreeTest.cpp

Index: clang/unittests/Tooling/Syntax/BuildTreeTest.cpp
===
--- clang/unittests/Tooling/Syntax/BuildTreeTest.cpp
+++ clang/unittests/Tooling/Syntax/BuildTreeTest.cpp
@@ -2454,7 +2454,7 @@
 )txt"));
 }
 
-TEST_P(SyntaxTreeTest, Namespaces) {
+TEST_P(SyntaxTreeTest, Namespace_Nested) {
   if (!GetParam().isCXX()) {
 return;
   }
@@ -2462,9 +2462,6 @@
   R"cpp(
 namespace a { namespace b {} }
 namespace a::b {}
-namespace {}
-
-namespace foo = a;
 )cpp",
   R"txt(
 *: TranslationUnit
@@ -2478,82 +2475,91 @@
 | | |-{
 | | `-}
 | `-}
-|-NamespaceDefinition
-| |-namespace
-| |-a
-| |-::
-| |-b
-| |-{
-| `-}
-|-NamespaceDefinition
-| |-namespace
-| |-{
-| `-}
-`-NamespaceAliasDefinition
+`-NamespaceDefinition
   |-namespace
-  |-foo
-  |-=
   |-a
-  `-;
+  |-::
+  |-b
+  |-{
+  `-}
 )txt"));
 }
 
-TEST_P(SyntaxTreeTest, UsingDirective) {
+TEST_P(SyntaxTreeTest, Namespace_Unnamed) {
   if (!GetParam().isCXX()) {
 return;
   }
   EXPECT_TRUE(treeDumpEqual(
   R"cpp(
-namespace ns {}
-using namespace ::ns;
+namespace {}
 )cpp",
   R"txt(
 *: TranslationUnit
-|-NamespaceDefinition
-| |-namespace
-| |-ns
-| |-{
-| `-}
-`-UsingNamespaceDirective
-  |-using
+`-NamespaceDefinition
   |-namespace
-  |-NestedNameSpecifier
-  | `-::
-  |-ns
-  `-;
+  |-{
+  `-}
 )txt"));
 }
 
+TEST_P(SyntaxTreeTest, Namespace_Alias) {
+  if (!GetParam().isCXX()) {
+return;
+  }
+  EXPECT_TRUE(treeDumpEqualOnAnnotations(
+  R"cpp(
+namespace a {}
+[[namespace foo = a;]]
+)cpp",
+  {R"txt(
+NamespaceAliasDefinition
+|-namespace
+|-foo
+|-=
+|-a
+`-;
+)txt"}));
+}
+
+TEST_P(SyntaxTreeTest, UsingDirective) {
+  if (!GetParam().isCXX()) {
+return;
+  }
+  EXPECT_TRUE(treeDumpEqualOnAnnotations(
+  R"cpp(
+namespace ns {}
+[[using namespace ::ns;]]
+)cpp",
+  {R"txt(
+UsingNamespaceDirective
+|-using
+|-namespace
+|-NestedNameSpecifier
+| `-::
+|-ns
+`-;
+)txt"}));
+}
+
 TEST_P(SyntaxTreeTest, UsingDeclaration) {
   if (!GetParam().isCXX()) {
 return;
   }
-  EXPECT_TRUE(treeDumpEqual(
+  EXPECT_TRUE(treeDumpEqualOnAnnotations(
   R"cpp(
 namespace ns { int a; }
-using ns::a;
+[[using ns::a;]]
 )cpp",
-  R"txt(
-*: TranslationUnit
-|-NamespaceDefinition
-| |-namespace
-| |-ns
-| |-{
-| |-SimpleDeclaration
-| | |-int
-| | |-SimpleDeclarator
-| | | `-a
-| | `-;
-| `-}
-`-UsingDeclaration
-  |-using
-  |-NestedNameSpecifier
-  | |-IdentifierNameSpecifier
-  | | `-ns
-  | `-::
-  |-a
-  `-;
-)txt"));
+  {R"txt(
+UsingDeclaration
+|-using
+|-NestedNameSpecifier
+| |-IdentifierNameSpecifier
+| | `-ns
+| `-::
+|-a
+`-;
+)txt"}));
 }
 
 TEST_P(SyntaxTreeTest, FreeStandingClasses) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D86293: [analyzer] Add modeling of Eq operator in smart ptr

2020-08-20 Thread Nithin VR via Phabricator via cfe-commits
vrnithinkumar created this revision.
Herald added subscribers: cfe-commits, steakhal, ASDenysPetrov, martong, 
Charusso, dkrupp, donat.nagy, Szelethus, mikhail.ramalho, a.sidorin, szepet, 
baloghadamsoftware, xazax.hun.
Herald added a project: clang.
vrnithinkumar requested review of this revision.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D86293

Files:
  clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
  clang/test/Analysis/smart-ptr-text-output.cpp
  clang/test/Analysis/smart-ptr.cpp

Index: clang/test/Analysis/smart-ptr.cpp
===
--- clang/test/Analysis/smart-ptr.cpp
+++ clang/test/Analysis/smart-ptr.cpp
@@ -215,8 +215,7 @@
 std::unique_ptr P;
 std::unique_ptr Q;
 Q = std::move(P);
-// TODO: Fix test with expecting warning after '=' operator overloading modeling.
-Q->foo(); // no-warning
+Q->foo(); // expected-warning {{Dereference of null smart pointer 'Q' [alpha.cplusplus.SmartPtr]}}
   }
 }
 
@@ -252,3 +251,36 @@
   P->foo(); // No warning.
   PValid->foo(); // No warning.
 }
+
+void drefOnMovedFromValidPtr() {
+  std::unique_ptr PToMove(new A());
+  std::unique_ptr P;
+  P = std::move(PToMove);
+  PToMove->foo(); // expected-warning {{Dereference of null smart pointer 'PToMove' [alpha.cplusplus.SmartPtr]}}
+}
+
+void drefOnMovedToNullPtr() {
+  std::unique_ptr PToMove(new A());
+  std::unique_ptr P;
+  P = std::move(PToMove); // No note.
+  P->foo(); // No warning.
+}
+
+void derefOnNullPtrGotMovedFromValidPtr() {
+  std::unique_ptr P(new A());
+  std::unique_ptr PToMove;
+  P = std::move(PToMove);
+  P->foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}}
+}
+
+void drefOnMovedFromUnknownPtr(std::unique_ptr PToMove) {
+  std::unique_ptr P;
+  P = std::move(PToMove);
+  P->foo(); // No warning.
+}
+
+void drefOnMovedUnknownPtr(std::unique_ptr PToMove) {
+  std::unique_ptr P;
+  P = std::move(PToMove);
+  PToMove->foo(); // expected-warning {{Dereference of null smart pointer 'PToMove' [alpha.cplusplus.SmartPtr]}}
+}
Index: clang/test/Analysis/smart-ptr-text-output.cpp
===
--- clang/test/Analysis/smart-ptr-text-output.cpp
+++ clang/test/Analysis/smart-ptr-text-output.cpp
@@ -109,10 +109,34 @@
   // expected-note@-1{{Dereference of null smart pointer 'P'}}
 }
 
-void noNoteTagsForNonMatchingBugType() {
-  std::unique_ptr P; // No note.
-  std::unique_ptr P1; // No note.
-  P1 = std::move(P); // expected-note {{Smart pointer 'P' of type 'std::unique_ptr' is reset to null when moved from}}
-  P->foo(); // expected-warning {{Dereference of null smart pointer 'P' of type 'std::unique_ptr' [cplusplus.Move]}}
-  // expected-note@-1 {{Dereference of null smart pointer 'P' of type 'std::unique_ptr'}}
+void drefOnMovedFromValidPtr() {
+  std::unique_ptr PToMove(new A());  // expected-note {{Smart pointer 'PToMove' is constructed}}
+  // FIXME: above note should go away once we fix marking region not interested. 
+  std::unique_ptr P;
+  P = std::move(PToMove); // expected-note {{Smart pointer 'PToMove' is null after moved to 'P'}}
+  PToMove->foo(); // expected-warning {{Dereference of null smart pointer 'PToMove' [alpha.cplusplus.SmartPtr]}}
+  // expected-note@-1 {{Dereference of null smart pointer 'PToMove'}}
+}
+
+void drefOnMovedToNullPtr() {
+  std::unique_ptr PToMove(new A());
+  std::unique_ptr P;
+  P = std::move(PToMove); // No note.
+  P->foo(); // No warning.
+}
+
+void derefOnNullPtrGotMovedFromValidPtr() {
+  std::unique_ptr P(new A()); // expected-note {{Smart pointer 'P' is constructed}}
+  // FIXME: above note should go away once we fix marking region not interested. 
+  std::unique_ptr PToMove; // expected-note {{Default constructed smart pointer 'PToMove' is null}}
+  P = std::move(PToMove); // expected-note {{Smart pointer 'P' is null after a null value moved from 'PToMove'}}
+  P->foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}}
+  // expected-note@-1 {{Dereference of null smart pointer 'P'}}
+}
+
+void drefOnMovedUnknownPtr(std::unique_ptr PToMove) {
+  std::unique_ptr P;
+  P = std::move(PToMove);
+  PToMove->foo(); // expected-warning {{Dereference of null smart pointer 'PToMove' [alpha.cplusplus.SmartPtr]}}
+  // expected-note@-1 {{Dereference of null smart pointer 'PToMove'}}
 }
Index: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
+++ clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
@@ -56,6 +56,7 @@
   void handleReset(const CallEvent , CheckerContext ) const;
   void handleRelease(const CallEvent , CheckerContext ) const;
   void handleSwap(const CallEvent , CheckerContext ) const;
+  bool handleEqOp(const CallEvent , CheckerContext ) const;
 
   using SmartPtrMethodHandlerFn =

[clang] a4ef9e8 - [SyntaxTree] Unify logic for generating `id-expression`

2020-08-20 Thread Eduardo Caldas via cfe-commits

Author: Eduardo Caldas
Date: 2020-08-20T14:57:35Z
New Revision: a4ef9e8643e2f3f8972e19c5b25f4dd81ba03508

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

LOG: [SyntaxTree] Unify logic for generating `id-expression`

Added: 


Modified: 
clang/lib/Tooling/Syntax/BuildTree.cpp

Removed: 




diff  --git a/clang/lib/Tooling/Syntax/BuildTree.cpp 
b/clang/lib/Tooling/Syntax/BuildTree.cpp
index a77149d66207..37d29a270463 100644
--- a/clang/lib/Tooling/Syntax/BuildTree.cpp
+++ b/clang/lib/Tooling/Syntax/BuildTree.cpp
@@ -881,35 +881,46 @@ class BuildTreeVisitor : public 
RecursiveASTVisitor {
 return true;
   }
 
-  bool WalkUpFromMemberExpr(MemberExpr *S) {
-if (auto QualifierLoc = S->getQualifierLoc())
+  syntax::IdExpression *buildIdExpression(NestedNameSpecifierLoc QualifierLoc,
+  SourceLocation TemplateKeywordLoc,
+  SourceRange UnqualifiedIdLoc,
+  ASTPtr From) {
+if (QualifierLoc) {
   Builder.markChild(QualifierLoc, 
syntax::NodeRole::IdExpression_qualifier);
-
-auto TemplateKeywordLoc = S->getTemplateKeywordLoc();
-if (TemplateKeywordLoc.isValid())
-  Builder.markChildToken(TemplateKeywordLoc,
- syntax::NodeRole::TemplateKeyword);
+  if (TemplateKeywordLoc.isValid())
+Builder.markChildToken(TemplateKeywordLoc,
+   syntax::NodeRole::TemplateKeyword);
+}
 
 auto *TheUnqualifiedId = new (allocator()) syntax::UnqualifiedId;
-Builder.foldNode(Builder.getRange(S->getMemberLoc(), S->getEndLoc()),
- TheUnqualifiedId, nullptr);
-
+Builder.foldNode(Builder.getRange(UnqualifiedIdLoc), TheUnqualifiedId,
+ nullptr);
 Builder.markChild(TheUnqualifiedId, syntax::NodeRole::IdExpression_id);
 
+auto IdExpressionBeginLoc =
+QualifierLoc ? QualifierLoc.getBeginLoc() : 
UnqualifiedIdLoc.getBegin();
+
 auto *TheIdExpression = new (allocator()) syntax::IdExpression;
-auto MemberRange =
-Builder.getRange(S->hasQualifier() ? S->getQualifierLoc().getBeginLoc()
-   : S->getMemberLoc(),
- S->getEndLoc());
+Builder.foldNode(
+Builder.getRange(IdExpressionBeginLoc, UnqualifiedIdLoc.getEnd()),
+TheIdExpression, From);
 
+return TheIdExpression;
+  }
+
+  bool WalkUpFromMemberExpr(MemberExpr *S) {
 // For `MemberExpr` with implicit `this->` we generate a simple
 // `id-expression` syntax node, beacuse an implicit `member-expression` is
 // syntactically undistinguishable from an `id-expression`
 if (S->isImplicitAccess()) {
-  Builder.foldNode(MemberRange, TheIdExpression, S);
+  buildIdExpression(S->getQualifierLoc(), S->getTemplateKeywordLoc(),
+SourceRange(S->getMemberLoc(), S->getEndLoc()), S);
   return true;
 }
-Builder.foldNode(MemberRange, TheIdExpression, nullptr);
+
+auto *TheIdExpression = buildIdExpression(
+S->getQualifierLoc(), S->getTemplateKeywordLoc(),
+SourceRange(S->getMemberLoc(), S->getEndLoc()), nullptr);
 
 Builder.markChild(TheIdExpression,
   syntax::NodeRole::MemberExpression_member);
@@ -925,45 +936,17 @@ class BuildTreeVisitor : public 
RecursiveASTVisitor {
   }
 
   bool WalkUpFromDeclRefExpr(DeclRefExpr *S) {
-if (auto QualifierLoc = S->getQualifierLoc())
-  Builder.markChild(QualifierLoc, 
syntax::NodeRole::IdExpression_qualifier);
+buildIdExpression(S->getQualifierLoc(), S->getTemplateKeywordLoc(),
+  SourceRange(S->getLocation(), S->getEndLoc()), S);
 
-auto TemplateKeywordLoc = S->getTemplateKeywordLoc();
-if (TemplateKeywordLoc.isValid())
-  Builder.markChildToken(TemplateKeywordLoc,
- syntax::NodeRole::TemplateKeyword);
-
-auto *unqualifiedId = new (allocator()) syntax::UnqualifiedId;
-
-Builder.foldNode(Builder.getRange(S->getLocation(), S->getEndLoc()),
- unqualifiedId, nullptr);
-
-Builder.markChild(unqualifiedId, syntax::NodeRole::IdExpression_id);
-
-Builder.foldNode(Builder.getExprRange(S),
- new (allocator()) syntax::IdExpression, S);
 return true;
   }
 
   // Same logic as DeclRefExpr.
   bool WalkUpFromDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *S) {
-if (auto QualifierLoc = S->getQualifierLoc())
-  Builder.markChild(QualifierLoc, 
syntax::NodeRole::IdExpression_qualifier);
+buildIdExpression(S->getQualifierLoc(), S->getTemplateKeywordLoc(),
+  SourceRange(S->getLocation(), S->getEndLoc()), S);
 
-

[PATCH] D86227: [SyntaxTree] Add support for `MemberExpression`

2020-08-20 Thread Eduardo Caldas via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGba32915db2ce: [SyntaxTree] Add support for 
`MemberExpression` (authored by eduucaldas).

Changed prior to commit:
  https://reviews.llvm.org/D86227?vs=286811=286820#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86227

Files:
  clang/include/clang/Tooling/Syntax/Nodes.h
  clang/lib/Tooling/Syntax/BuildTree.cpp
  clang/lib/Tooling/Syntax/Nodes.cpp
  clang/unittests/Tooling/Syntax/BuildTreeTest.cpp

Index: clang/unittests/Tooling/Syntax/BuildTreeTest.cpp
===
--- clang/unittests/Tooling/Syntax/BuildTreeTest.cpp
+++ clang/unittests/Tooling/Syntax/BuildTreeTest.cpp
@@ -491,19 +491,20 @@
   operator int();
 };
 void test(X x) {
-  // TODO: Expose `id-expression` from `MemberExpr`
   [[x.operator int()]];
 }
 )cpp",
   {R"txt(
 UnknownExpression
-|-UnknownExpression
+|-MemberExpression
 | |-IdExpression
 | | `-UnqualifiedId
 | |   `-x
 | |-.
-| |-operator
-| `-int
+| `-IdExpression
+|   `-UnqualifiedId
+| |-operator
+| `-int
 |-(
 `-)
 )txt"}));
@@ -542,19 +543,20 @@
   R"cpp(
 struct X { };
 void test(X x) {
-  // TODO: Expose `id-expression` from `MemberExpr`
   [[x.~X()]];
 }
 )cpp",
   {R"txt(
 UnknownExpression
-|-UnknownExpression
+|-MemberExpression
 | |-IdExpression
 | | `-UnqualifiedId
 | |   `-x
 | |-.
-| |-~
-| `-X
+| `-IdExpression
+|   `-UnqualifiedId
+| |-~
+| `-X
 |-(
 `-)
 )txt"}));
@@ -568,18 +570,23 @@
   R"cpp(
 struct X { };
 void test(X x) {
-  // TODO: Expose `id-expression` from `MemberExpr`
+  // FIXME: Make `decltype(x)` a child of `MemberExpression`. It is currently
+  // not because `Expr::getSourceRange()` returns the range of `x.~` for the
+  // `MemberExpr` instead of the expected `x.~decltype(x)`, this is a bug in
+  // clang.
   [[x.~decltype(x)()]];
 }
 )cpp",
   {R"txt(
 UnknownExpression
-|-UnknownExpression
+|-MemberExpression
 | |-IdExpression
 | | `-UnqualifiedId
 | |   `-x
 | |-.
-| `-~
+| `-IdExpression
+|   `-UnqualifiedId
+| `-~
 |-decltype
 |-(
 |-x
@@ -624,6 +631,9 @@
   struct S { };
 }
 void test() {
+  // FIXME: Remove the `UnknownExpression` wrapping `s1` and `s2`. This
+  // `UnknownExpression` comes from a leaf `CXXConstructExpr` in the
+  // ClangAST. We need to ignore leaf implicit nodes.
   [[::n::S s1]];
   [[n::S s2]];
 }
@@ -1756,6 +1766,9 @@
 struct X {
   friend X operator+(X, const X&);
 };
+// FIXME: Remove additional `UnknownExpression` wrapping `x`. For that, ignore
+// implicit copy constructor called on `x`. This should've been ignored already,
+// as we `IgnoreImplicit` when traversing an `Stmt`.
 void test(X x, X y) {
   [[x + y]];
 }
@@ -1961,6 +1974,366 @@
 )txt"}));
 }
 
+TEST_P(SyntaxTreeTest, MemberExpression_SimpleWithDot) {
+  EXPECT_TRUE(treeDumpEqualOnAnnotations(
+  R"cpp(
+struct S {
+  int a;
+};
+void test(struct S s) {
+  [[s.a]];
+}
+)cpp",
+  {R"txt(
+MemberExpression
+|-IdExpression
+| `-UnqualifiedId
+|   `-s
+|-.
+`-IdExpression
+  `-UnqualifiedId
+`-a
+)txt"}));
+}
+
+TEST_P(SyntaxTreeTest, MemberExpression_StaticDataMember) {
+  if (!GetParam().isCXX()) {
+return;
+  }
+  EXPECT_TRUE(treeDumpEqualOnAnnotations(
+  R"cpp(
+struct S {
+  static int a;
+};
+void test(S s) {
+  [[s.a]];
+}
+)cpp",
+  {R"txt(
+MemberExpression
+|-IdExpression
+| `-UnqualifiedId
+|   `-s
+|-.
+`-IdExpression
+  `-UnqualifiedId
+`-a
+)txt"}));
+}
+
+TEST_P(SyntaxTreeTest, MemberExpression_SimpleWithArrow) {
+  EXPECT_TRUE(treeDumpEqualOnAnnotations(
+  R"cpp(
+struct S {
+  int a;
+};
+void test(struct S* sp) {
+  [[sp->a]];
+}
+)cpp",
+  {R"txt(
+MemberExpression
+|-IdExpression
+| `-UnqualifiedId
+|   `-sp
+|-->
+`-IdExpression
+  `-UnqualifiedId
+`-a
+)txt"}));
+}
+
+TEST_P(SyntaxTreeTest, MemberExpression_Chaining) {
+  EXPECT_TRUE(treeDumpEqualOnAnnotations(
+  R"cpp(
+struct S {
+  struct S* next;
+};
+void test(struct S s){
+  [[s.next->next]];
+}
+)cpp",
+  {R"txt(
+MemberExpression
+|-MemberExpression
+| |-IdExpression
+| | `-UnqualifiedId
+| |   `-s
+| |-.
+| `-IdExpression
+|   `-UnqualifiedId
+| `-next
+|-->
+`-IdExpression
+  `-UnqualifiedId
+`-next
+)txt"}));
+}
+
+TEST_P(SyntaxTreeTest, MemberExpression_OperatorFunction) {
+  if (!GetParam().isCXX()) {
+return;
+  }
+  EXPECT_TRUE(treeDumpEqualOnAnnotations(
+  R"cpp(
+struct S {
+  bool operator!();
+};
+void test(S s) {
+  [[s.operator!()]];
+}
+)cpp",
+  {R"txt(
+UnknownExpression
+|-MemberExpression
+| |-IdExpression
+| | `-UnqualifiedId
+| |   `-s
+| |-.
+| `-IdExpression
+|   `-UnqualifiedId
+| |-operator
+| `-!
+|-(
+`-)
+)txt"}));
+}
+
+TEST_P(SyntaxTreeTest, MemberExpression_Implicit) {
+  if (!GetParam().isCXX()) {
+return;
+  }
+  EXPECT_TRUE(treeDumpEqualOnAnnotations(
+  R"cpp(
+struct S {
+  int a;
+  int 

[clang] ba32915 - [SyntaxTree] Add support for `MemberExpression`

2020-08-20 Thread Eduardo Caldas via cfe-commits

Author: Eduardo Caldas
Date: 2020-08-20T14:57:35Z
New Revision: ba32915db2ce78256115a9db7b07bb3806e6364a

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

LOG: [SyntaxTree] Add support for `MemberExpression`

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

Added: 


Modified: 
clang/include/clang/Tooling/Syntax/Nodes.h
clang/lib/Tooling/Syntax/BuildTree.cpp
clang/lib/Tooling/Syntax/Nodes.cpp
clang/unittests/Tooling/Syntax/BuildTreeTest.cpp

Removed: 




diff  --git a/clang/include/clang/Tooling/Syntax/Nodes.h 
b/clang/include/clang/Tooling/Syntax/Nodes.h
index 8e65fa1d8923..8b499bc5ceb9 100644
--- a/clang/include/clang/Tooling/Syntax/Nodes.h
+++ b/clang/include/clang/Tooling/Syntax/Nodes.h
@@ -55,6 +55,7 @@ enum class NodeKind : uint16_t {
   CharUserDefinedLiteralExpression,
   StringUserDefinedLiteralExpression,
   IdExpression,
+  MemberExpression,
 
   // Statements.
   UnknownStatement,
@@ -173,7 +174,10 @@ enum class NodeRole : uint8_t {
   ParametersAndQualifiers_trailingReturn,
   IdExpression_id,
   IdExpression_qualifier,
-  ParenExpression_subExpression
+  ParenExpression_subExpression,
+  MemberExpression_object,
+  MemberExpression_accessToken,
+  MemberExpression_member,
 };
 /// For debugging purposes.
 raw_ostream <<(raw_ostream , NodeRole R);
@@ -322,6 +326,26 @@ class ParenExpression final : public Expression {
   Leaf *closeParen();
 };
 
+/// Models a class member access. C++ [expr.ref]
+/// member-expression:
+///   expression -> template_opt id-expression
+///   expression .  template_opt id-expression
+/// e.g. `x.a`, `xp->a`
+///
+/// Note: An implicit member access inside a class, i.e. `a` instead of
+/// `this->a`, is an `id-expression`.
+class MemberExpression final : public Expression {
+public:
+  MemberExpression() : Expression(NodeKind::MemberExpression) {}
+  static bool classof(const Node *N) {
+return N->kind() == NodeKind::MemberExpression;
+  }
+  Expression *object();
+  Leaf *accessToken();
+  Leaf *templateKeyword();
+  IdExpression *member();
+};
+
 /// Expression for literals. C++ [lex.literal]
 class LiteralExpression : public Expression {
 public:

diff  --git a/clang/lib/Tooling/Syntax/BuildTree.cpp 
b/clang/lib/Tooling/Syntax/BuildTree.cpp
index 11d399730040..a77149d66207 100644
--- a/clang/lib/Tooling/Syntax/BuildTree.cpp
+++ b/clang/lib/Tooling/Syntax/BuildTree.cpp
@@ -881,6 +881,49 @@ class BuildTreeVisitor : public 
RecursiveASTVisitor {
 return true;
   }
 
+  bool WalkUpFromMemberExpr(MemberExpr *S) {
+if (auto QualifierLoc = S->getQualifierLoc())
+  Builder.markChild(QualifierLoc, 
syntax::NodeRole::IdExpression_qualifier);
+
+auto TemplateKeywordLoc = S->getTemplateKeywordLoc();
+if (TemplateKeywordLoc.isValid())
+  Builder.markChildToken(TemplateKeywordLoc,
+ syntax::NodeRole::TemplateKeyword);
+
+auto *TheUnqualifiedId = new (allocator()) syntax::UnqualifiedId;
+Builder.foldNode(Builder.getRange(S->getMemberLoc(), S->getEndLoc()),
+ TheUnqualifiedId, nullptr);
+
+Builder.markChild(TheUnqualifiedId, syntax::NodeRole::IdExpression_id);
+
+auto *TheIdExpression = new (allocator()) syntax::IdExpression;
+auto MemberRange =
+Builder.getRange(S->hasQualifier() ? S->getQualifierLoc().getBeginLoc()
+   : S->getMemberLoc(),
+ S->getEndLoc());
+
+// For `MemberExpr` with implicit `this->` we generate a simple
+// `id-expression` syntax node, beacuse an implicit `member-expression` is
+// syntactically undistinguishable from an `id-expression`
+if (S->isImplicitAccess()) {
+  Builder.foldNode(MemberRange, TheIdExpression, S);
+  return true;
+}
+Builder.foldNode(MemberRange, TheIdExpression, nullptr);
+
+Builder.markChild(TheIdExpression,
+  syntax::NodeRole::MemberExpression_member);
+
+Builder.markExprChild(S->getBase(),
+  syntax::NodeRole::MemberExpression_object);
+Builder.markChildToken(S->getOperatorLoc(),
+   syntax::NodeRole::MemberExpression_accessToken);
+
+Builder.foldNode(Builder.getExprRange(S),
+ new (allocator()) syntax::MemberExpression, S);
+return true;
+  }
+
   bool WalkUpFromDeclRefExpr(DeclRefExpr *S) {
 if (auto QualifierLoc = S->getQualifierLoc())
   Builder.markChild(QualifierLoc, 
syntax::NodeRole::IdExpression_qualifier);

diff  --git a/clang/lib/Tooling/Syntax/Nodes.cpp 
b/clang/lib/Tooling/Syntax/Nodes.cpp
index bf3c3108cb69..e09c8f20f210 100644
--- a/clang/lib/Tooling/Syntax/Nodes.cpp
+++ b/clang/lib/Tooling/Syntax/Nodes.cpp
@@ -126,6 +126,8 @@ raw_ostream 

[PATCH] D83088: Introduce CfgTraits abstraction

2020-08-20 Thread Nicolai Hähnle via Phabricator via cfe-commits
nhaehnle added a comment.

> Based on your description and the DomTree patches, if I understand correctly, 
> the primary motivation is to facilitate writing CFG-representation-agnostic 
> algorithms/analyses (e.g., dominators, divergence, convergence analyses), 
> such that you can later lift the results back to the representation-aware 
> types? If that's correct, I support the overall goal. Having spent probably 
> ~weeks wrangling with domtree templates, this sounds like something that 
> could simplify life a lot and potentially cut down on compilation times & 
> sizes of llvm binaries.

Yes, that is the motivation.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83088

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


[PATCH] D85324: [SystemZ][z/OS] Add z/OS Target and define macros

2020-08-20 Thread Hubert Tong via Phabricator via cfe-commits
hubert.reinterpretcast added inline comments.



Comment at: clang/test/Preprocessor/init-zos.c:5
+//
+// S390X-ZOS-CXX:#define _EXT 1
+// S390X-ZOS-C99:#define _ISOC99_SOURCE 1

Should this be `GNUXX`?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85324

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


[PATCH] D85324: [SystemZ][z/OS] Add z/OS Target and define macros

2020-08-20 Thread Hubert Tong via Phabricator via cfe-commits
hubert.reinterpretcast added inline comments.



Comment at: clang/lib/Basic/Targets/OSTargets.h:736
+MacroBuilder ) const override {
+// FIXME: LONG_LONG should not be defined under -std=c89
+Builder.defineMacro("_LONG_LONG");

Minor nit: Typo.

The FIXME is okay until there's a reason to fix this. The review necessary for 
addressing the FIXME deserves another patch anyway.

The situation between z/OS and AIX is different for this case. On AIX, the C 
ABI compatibility of `imaxdiv_t` is affected. In other words, on AIX, fixing 
this might cause surprising behaviour.



Comment at: clang/lib/Basic/Targets/OSTargets.h:743
+Builder.defineMacro("__BFP__");
+Builder.defineMacro("__BOOL__");
+Builder.defineMacro("__LONGNAME__");

Sorry for not catching this earlier, but this also needs a FIXME re: strict C89.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85324

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


[PATCH] D83048: [LiveDebugValues] 3/4 Add Xclang and CodeGen options for using instr-ref variable locations

2020-08-20 Thread Jeremy Morse via Phabricator via cfe-commits
jmorse updated this revision to Diff 286814.
jmorse added a comment.
Herald added a subscriber: dang.

Add a test for the driver -Xclang option. As far as I understand this, we're 
just checking that the switch is accepted by the driver, not that it does 
anything in particular (please correct me if I'm wrong).


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

https://reviews.llvm.org/D83048

Files:
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Driver/CC1Options.td
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/Driver/debug-var-experimental-switch.c
  llvm/include/llvm/CodeGen/CommandFlags.h
  llvm/include/llvm/Target/TargetOptions.h
  llvm/lib/CodeGen/CommandFlags.cpp
  llvm/lib/CodeGen/LiveDebugValues/LiveDebugValues.cpp

Index: llvm/lib/CodeGen/LiveDebugValues/LiveDebugValues.cpp
===
--- llvm/lib/CodeGen/LiveDebugValues/LiveDebugValues.cpp
+++ llvm/lib/CodeGen/LiveDebugValues/LiveDebugValues.cpp
@@ -12,6 +12,7 @@
 #include "llvm/CodeGen/MachineFrameInfo.h"
 #include "llvm/CodeGen/MachineFunctionPass.h"
 #include "llvm/CodeGen/Passes.h"
+#include "llvm/Target/TargetMachine.h"
 #include "llvm/InitializePasses.h"
 #include "llvm/Pass.h"
 
@@ -40,7 +41,11 @@
   static char ID;
 
   LiveDebugValues();
-  ~LiveDebugValues() { delete TheImpl; }
+  ~LiveDebugValues()
+  {
+if (TheImpl)
+  delete TheImpl;
+  }
 
   /// Calculate the liveness information for the given machine function.
   bool runOnMachineFunction(MachineFunction ) override;
@@ -57,6 +62,7 @@
 
 private:
   LDVImpl *TheImpl;
+  TargetPassConfig *TPC;
 };
 
 char LiveDebugValues::ID = 0;
@@ -69,10 +75,24 @@
 /// Default construct and initialize the pass.
 LiveDebugValues::LiveDebugValues() : MachineFunctionPass(ID) {
   initializeLiveDebugValuesPass(*PassRegistry::getPassRegistry());
-  TheImpl = llvm::makeVarLocBasedLiveDebugValues();
+  TheImpl = nullptr;
 }
 
 bool LiveDebugValues::runOnMachineFunction(MachineFunction ) {
-  auto *TPC = getAnalysisIfAvailable();
+  if (!TheImpl) {
+TPC = getAnalysisIfAvailable();
+
+bool InstrRefBased = false;
+if (TPC) {
+  auto  = TPC->getTM();
+  InstrRefBased = TM.Options.ValueTrackingVariableLocations;
+}
+
+if (InstrRefBased)
+  TheImpl = llvm::makeInstrRefBasedLiveDebugValues();
+else
+  TheImpl = llvm::makeVarLocBasedLiveDebugValues();
+  }
+
   return TheImpl->ExtendRanges(MF, TPC);
 }
Index: llvm/lib/CodeGen/CommandFlags.cpp
===
--- llvm/lib/CodeGen/CommandFlags.cpp
+++ llvm/lib/CodeGen/CommandFlags.cpp
@@ -85,6 +85,7 @@
 CGOPT(bool, EnableAddrsig)
 CGOPT(bool, EmitCallSiteInfo)
 CGOPT(bool, EnableDebugEntryValues)
+CGOPT(bool, ValueTrackingVariableLocations)
 CGOPT(bool, ForceDwarfFrameSection)
 CGOPT(bool, XRayOmitFunctionIndex)
 
@@ -400,6 +401,12 @@
   cl::init(false));
   CGBINDOPT(EnableDebugEntryValues);
 
+  static cl::opt ValueTrackingVariableLocations(
+  "experimental-debug-variable-locations",
+  cl::desc("Use experimental new value-tracking variable locations"),
+  cl::init(false));
+  CGBINDOPT(ValueTrackingVariableLocations);
+
   static cl::opt ForceDwarfFrameSection(
   "force-dwarf-frame-section",
   cl::desc("Always emit a debug frame section."), cl::init(false));
@@ -475,6 +482,7 @@
   Options.EmitAddrsig = getEnableAddrsig();
   Options.EmitCallSiteInfo = getEmitCallSiteInfo();
   Options.EnableDebugEntryValues = getEnableDebugEntryValues();
+  Options.ValueTrackingVariableLocations = getValueTrackingVariableLocations();
   Options.ForceDwarfFrameSection = getForceDwarfFrameSection();
   Options.XRayOmitFunctionIndex = getXRayOmitFunctionIndex();
 
Index: llvm/include/llvm/Target/TargetOptions.h
===
--- llvm/include/llvm/Target/TargetOptions.h
+++ llvm/include/llvm/Target/TargetOptions.h
@@ -127,8 +127,8 @@
   EmitStackSizeSection(false), EnableMachineOutliner(false),
   SupportsDefaultOutlining(false), EmitAddrsig(false),
   EmitCallSiteInfo(false), SupportsDebugEntryValues(false),
-  EnableDebugEntryValues(false), ForceDwarfFrameSection(false),
-  XRayOmitFunctionIndex(false),
+  EnableDebugEntryValues(false), ValueTrackingVariableLocations(false),
+  ForceDwarfFrameSection(false), XRayOmitFunctionIndex(false),
   FPDenormalMode(DenormalMode::IEEE, DenormalMode::IEEE) {}
 
 /// PrintMachineCode - This flag is enabled when the -print-machineinstrs
@@ -291,6 +291,11 @@
 /// production.
 bool ShouldEmitDebugEntryValues() const;
 
+// When set to true, use experimental new debug variable location tracking,
+// which seeks to follow the values of variables rather than their location,
+// post isel.
+unsigned ValueTrackingVariableLocations : 1;
+
   

[PATCH] D86227: [SyntaxTree] Add support for `MemberExpression`

2020-08-20 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas updated this revision to Diff 286811.
eduucaldas marked 2 inline comments as done.
eduucaldas added a comment.

Unify logic for generating `id-expression`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86227

Files:
  clang/include/clang/Tooling/Syntax/Nodes.h
  clang/lib/Tooling/Syntax/BuildTree.cpp
  clang/lib/Tooling/Syntax/Nodes.cpp
  clang/unittests/Tooling/Syntax/BuildTreeTest.cpp

Index: clang/unittests/Tooling/Syntax/BuildTreeTest.cpp
===
--- clang/unittests/Tooling/Syntax/BuildTreeTest.cpp
+++ clang/unittests/Tooling/Syntax/BuildTreeTest.cpp
@@ -491,19 +491,20 @@
   operator int();
 };
 void test(X x) {
-  // TODO: Expose `id-expression` from `MemberExpr`
   [[x.operator int()]];
 }
 )cpp",
   {R"txt(
 UnknownExpression
-|-UnknownExpression
+|-MemberExpression
 | |-IdExpression
 | | `-UnqualifiedId
 | |   `-x
 | |-.
-| |-operator
-| `-int
+| `-IdExpression
+|   `-UnqualifiedId
+| |-operator
+| `-int
 |-(
 `-)
 )txt"}));
@@ -542,19 +543,20 @@
   R"cpp(
 struct X { };
 void test(X x) {
-  // TODO: Expose `id-expression` from `MemberExpr`
   [[x.~X()]];
 }
 )cpp",
   {R"txt(
 UnknownExpression
-|-UnknownExpression
+|-MemberExpression
 | |-IdExpression
 | | `-UnqualifiedId
 | |   `-x
 | |-.
-| |-~
-| `-X
+| `-IdExpression
+|   `-UnqualifiedId
+| |-~
+| `-X
 |-(
 `-)
 )txt"}));
@@ -568,18 +570,23 @@
   R"cpp(
 struct X { };
 void test(X x) {
-  // TODO: Expose `id-expression` from `MemberExpr`
+  // FIXME: Make `decltype(x)` a child of `MemberExpression`. It is currently
+  // not because `Expr::getSourceRange()` returns the range of `x.~` for the
+  // `MemberExpr` instead of the expected `x.~decltype(x)`, this is a bug in
+  // clang.
   [[x.~decltype(x)()]];
 }
 )cpp",
   {R"txt(
 UnknownExpression
-|-UnknownExpression
+|-MemberExpression
 | |-IdExpression
 | | `-UnqualifiedId
 | |   `-x
 | |-.
-| `-~
+| `-IdExpression
+|   `-UnqualifiedId
+| `-~
 |-decltype
 |-(
 |-x
@@ -624,6 +631,9 @@
   struct S { };
 }
 void test() {
+  // FIXME: Remove the `UnknownExpression` wrapping `s1` and `s2`. This
+  // `UnknownExpression` comes from a leaf `CXXConstructExpr` in the
+  // ClangAST. We need to ignore leaf implicit nodes.
   [[::n::S s1]];
   [[n::S s2]];
 }
@@ -1756,6 +1766,9 @@
 struct X {
   friend X operator+(X, const X&);
 };
+// FIXME: Remove additional `UnknownExpression` wrapping `x`. For that, ignore
+// implicit copy constructor called on `x`. This should've been ignored already,
+// as we `IgnoreImplicit` when traversing an `Stmt`.
 void test(X x, X y) {
   [[x + y]];
 }
@@ -1961,6 +1974,366 @@
 )txt"}));
 }
 
+TEST_P(SyntaxTreeTest, MemberExpression_SimpleWithDot) {
+  EXPECT_TRUE(treeDumpEqualOnAnnotations(
+  R"cpp(
+struct S {
+  int a;
+};
+void test(struct S s) {
+  [[s.a]];
+}
+)cpp",
+  {R"txt(
+MemberExpression
+|-IdExpression
+| `-UnqualifiedId
+|   `-s
+|-.
+`-IdExpression
+  `-UnqualifiedId
+`-a
+)txt"}));
+}
+
+TEST_P(SyntaxTreeTest, MemberExpression_StaticDataMember) {
+  if (!GetParam().isCXX()) {
+return;
+  }
+  EXPECT_TRUE(treeDumpEqualOnAnnotations(
+  R"cpp(
+struct S {
+  static int a;
+};
+void test(S s) {
+  [[s.a]];
+}
+)cpp",
+  {R"txt(
+MemberExpression
+|-IdExpression
+| `-UnqualifiedId
+|   `-s
+|-.
+`-IdExpression
+  `-UnqualifiedId
+`-a
+)txt"}));
+}
+
+TEST_P(SyntaxTreeTest, MemberExpression_SimpleWithArrow) {
+  EXPECT_TRUE(treeDumpEqualOnAnnotations(
+  R"cpp(
+struct S {
+  int a;
+};
+void test(struct S* sp) {
+  [[sp->a]];
+}
+)cpp",
+  {R"txt(
+MemberExpression
+|-IdExpression
+| `-UnqualifiedId
+|   `-sp
+|-->
+`-IdExpression
+  `-UnqualifiedId
+`-a
+)txt"}));
+}
+
+TEST_P(SyntaxTreeTest, MemberExpression_Chaining) {
+  EXPECT_TRUE(treeDumpEqualOnAnnotations(
+  R"cpp(
+struct S {
+  struct S* next;
+};
+void test(struct S s){
+  [[s.next->next]];
+}
+)cpp",
+  {R"txt(
+MemberExpression
+|-MemberExpression
+| |-IdExpression
+| | `-UnqualifiedId
+| |   `-s
+| |-.
+| `-IdExpression
+|   `-UnqualifiedId
+| `-next
+|-->
+`-IdExpression
+  `-UnqualifiedId
+`-next
+)txt"}));
+}
+
+TEST_P(SyntaxTreeTest, MemberExpression_OperatorFunction) {
+  if (!GetParam().isCXX()) {
+return;
+  }
+  EXPECT_TRUE(treeDumpEqualOnAnnotations(
+  R"cpp(
+struct S {
+  bool operator!();
+};
+void test(S s) {
+  [[s.operator!()]];
+}
+)cpp",
+  {R"txt(
+UnknownExpression
+|-MemberExpression
+| |-IdExpression
+| | `-UnqualifiedId
+| |   `-s
+| |-.
+| `-IdExpression
+|   `-UnqualifiedId
+| |-operator
+| `-!
+|-(
+`-)
+)txt"}));
+}
+
+TEST_P(SyntaxTreeTest, MemberExpression_Implicit) {
+  if (!GetParam().isCXX()) {
+return;
+  }
+  EXPECT_TRUE(treeDumpEqualOnAnnotations(
+  R"cpp(
+struct S {
+  int a;
+  int test(){
+// FIXME: Remove the `UnknownExpression` wrapping `a`. This
+// 

[PATCH] D86176: [clang-tidy] readability-simplify-boolean-expr detects negated literals

2020-08-20 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: 
clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp:66
+  if (const auto *Negated = Result.Nodes.getNodeAs(Id)) {
+if (Negated->getOpcode() == UO_LNot &&
+isa(Negated->getSubExpr()))

njames93 wrote:
> aaron.ballman wrote:
> > I'd like to see this handled recursively instead so that we properly handle 
> > more esoteric logic (but it still shows up from time to time) like `!!foo`: 
> > https://codesearch.isocpp.org/cgi-bin/cgi_ppsearch?q=%21%21=Search
> > 
> > This is a case where I don't think the simplification should happen -- 
> > e.g., the code is usually subtly incorrect when converted to remove the 
> > `!!`. It's less clear to me whether the same is true for something like 
> > `!!!` being converted to `!`, but that's not a case I'm really worried 
> > about either.
> As this is only looking for boolean literals that shouldn't matter
> `!!true` is identical to `true`.
> I get putting `!!` in front of expressions that aren't boolean has an effect, 
> but we aren't looking for that in this case.
Oh, derp, I saw "SimplifyBooleanExprCheck" and assumed it was simplifying 
arbitrary boolean expressions, not just literals. I am now far less worried 
about supporting this case, it's up to you if you want to do the extra work. 
Thank you for clarifying and sorry for my think-o!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86176

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


[PATCH] D86089: [flang][driver]Add experimental flang driver and frontend with help screen

2020-08-20 Thread Richard Barton via Phabricator via cfe-commits
richard.barton.arm requested changes to this revision.
richard.barton.arm added a comment.

A few specific comments to address here as well as the pre-commit linting ones.




Comment at: clang/lib/Driver/Driver.cpp:1584
 void Driver::PrintVersion(const Compilation , raw_ostream ) const {
+  if (IsFlangMode()) {
+OS << "Flang experimental driver (flang-new)" << '\n';

Instead of this early exit, could we instead of calling getClangFullVersion 
below call getClangToolFullVersion with a different string here?


```
if (IsFlangMode())
  OS >> getClangToolFullVersion("flang-new") << '\n';
else
  OS >> getClangFullVersion();
```

That way, we get the full clang version screen already implemented 'for free' 
and the code is nicer too (IMO)
  



Comment at: flang/CMakeLists.txt:20
 option(LINK_WITH_FIR "Link driver with FIR and LLVM" ON)
+option(BUILD_FLANG_NEW_DRIVER "Build the flang driver frontend" OFF)
 

Generally we should make sure all Flang-specific CMake build configuration 
variables start with FLANG. Suggest this is FLANG_BUILD_NEW_DRIVER or similar.



Comment at: flang/CMakeLists.txt:74
 
+
   if(LINK_WITH_FIR)

Remove



Comment at: flang/test/lit.cfg.py:40
+# exclude the tests for flang_new driver while there are two drivers
+if config.include_flang_new_driver_test == "OFF":
+  config.excludes = ['Inputs', 'CMakeLists.txt', 'README.txt', 'LICENSE.txt', 
'Flang-Driver']

I think it would be cleaner to define config.excludes unconditionally then 
append the Flang-Driver dir if our condition passes.



Comment at: flang/test/lit.cfg.py:64
 tools = [
+  ToolSubst('%flang-new', command=FindTool('flang-new'), unresolved='ignore'),
   ToolSubst('%f18', command=FindTool('f18'),

Rather than always trying to add flang-new and ignoring failure, I think it 
would be better to conditionally add this to `tools` iff we are building the 
new driver and so have `config.include_flang_new_driver_test = "ON"`. This way 
if you are building the new driver and for some reason lit fails to resolve the 
tool then you get a nice error before trying to run tests on a binary that is 
not there.



Comment at: flang/test/lit.site.cfg.py.in:13
 
+# controld the regression test for flang-new driver
+config.include_flang_new_driver_test="@BUILD_FLANG_NEW_DRIVER@"

typo "controld"



Comment at: flang/unittests/CMakeLists.txt:27
+if (BUILD_FLANG_NEW_DRIVER)
+add_subdirectory(Frontend)
+endif()

indentation?



Comment at: llvm/lib/Option/OptTable.cpp:621
+// If `Flags` is empty (i.e. it's an option without any flags) then this is
+// a Clang-only option. If:
+// * we _are not_ in Flang Mode (FlagsToExclude contains FlangMode), then

This is not the sort of change I expect to see in an llvm support library given 
that it seems very clang and flang specific. 

I think this needs to be re-written to be more generic, perhaps tweaking the 
interface to be able to express the logic you want to use for flang and clang.

Why is it not sufficient to call this function unchanged from both flang and 
clang but with a different set of FlagsToInclude/FlagsToExclude passed in using 
this logic to set that on the clang/flang side?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86089

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


[clang] 1ecf120 - [index-while-building] Fix build with -DBUILD_SHARED_LIBS=True

2020-08-20 Thread Alex Bradbury via cfe-commits

Author: Alex Bradbury
Date: 2020-08-20T15:12:56+01:00
New Revision: 1ecf120246e7d3e5c9a9ed1db637914bbf4b5702

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

LOG: [index-while-building] Fix build with -DBUILD_SHARED_LIBS=True

The dependencies in clang/lib/IndexSerialization/CMakeLists.txt were
incomplete, leading to link errors for a -DBUILD_SHARED_LIBS=True build.

Added: 


Modified: 
clang/lib/IndexSerialization/CMakeLists.txt

Removed: 




diff  --git a/clang/lib/IndexSerialization/CMakeLists.txt 
b/clang/lib/IndexSerialization/CMakeLists.txt
index 197059fff4b3..65a5d20d6a92 100644
--- a/clang/lib/IndexSerialization/CMakeLists.txt
+++ b/clang/lib/IndexSerialization/CMakeLists.txt
@@ -1,3 +1,7 @@
+set(LLVM_LINK_COMPONENTS
+  Support
+  )
+
 add_clang_library(clangIndexSerialization
   SerializablePathCollection.cpp
 



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


[PATCH] D86289: [NFC][compiler-rt] Factor out __mulo[sdt]i3 implementations to .inc file

2020-08-20 Thread Anatoly Trosinenko via Phabricator via cfe-commits
atrosinenko created this revision.
atrosinenko added reviewers: MaskRay, kamleshbhalui, luismarques, efriedma, 
aykevl.
Herald added subscribers: Sanitizers, dberris.
Herald added a project: Sanitizers.
atrosinenko requested review of this revision.

The existing implementations are almost identical except for width of the 
integer type.

Factor them out to int_mulo_impl.inc for better maintainability.

The following command may help understanding the changes:

  diff int_mulo_impl.inc \
   <(git show master:./mulosi4.c | sed 's/si_int/fixint_t/g')

The `si` and `di` variants has three lines different (with two of them being 
comments) and `ti` has a bit larger diff.

Note: this patch is almost identical to D86277: [NFC][compiler-rt] Factor out 
__mulv[sdt]i3 implementations to .inc file .


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D86289

Files:
  compiler-rt/lib/builtins/int_mulo_impl.inc
  compiler-rt/lib/builtins/mulodi4.c
  compiler-rt/lib/builtins/mulosi4.c
  compiler-rt/lib/builtins/muloti4.c

Index: compiler-rt/lib/builtins/muloti4.c
===
--- compiler-rt/lib/builtins/muloti4.c
+++ compiler-rt/lib/builtins/muloti4.c
@@ -18,36 +18,11 @@
 
 // Effects: sets *overflow to 1  if a * b overflows
 
+#define fixint_t ti_int
+#include "int_mulo_impl.inc"
+
 COMPILER_RT_ABI ti_int __muloti4(ti_int a, ti_int b, int *overflow) {
-  const int N = (int)(sizeof(ti_int) * CHAR_BIT);
-  const ti_int MIN = (ti_int)1 << (N - 1);
-  const ti_int MAX = ~MIN;
-  *overflow = 0;
-  ti_int result = a * b;
-  if (a == MIN) {
-if (b != 0 && b != 1)
-  *overflow = 1;
-return result;
-  }
-  if (b == MIN) {
-if (a != 0 && a != 1)
-  *overflow = 1;
-return result;
-  }
-  ti_int sa = a >> (N - 1);
-  ti_int abs_a = (a ^ sa) - sa;
-  ti_int sb = b >> (N - 1);
-  ti_int abs_b = (b ^ sb) - sb;
-  if (abs_a < 2 || abs_b < 2)
-return result;
-  if (sa == sb) {
-if (abs_a > MAX / abs_b)
-  *overflow = 1;
-  } else {
-if (abs_a > MIN / -abs_b)
-  *overflow = 1;
-  }
-  return result;
+  return __muloXi4(a, b, overflow);
 }
 
 #endif // CRT_HAS_128BIT
Index: compiler-rt/lib/builtins/mulosi4.c
===
--- compiler-rt/lib/builtins/mulosi4.c
+++ compiler-rt/lib/builtins/mulosi4.c
@@ -10,40 +10,13 @@
 //
 //===--===//
 
-#include "int_lib.h"
+#define fixint_t si_int
+#include "int_mulo_impl.inc"
 
 // Returns: a * b
 
 // Effects: sets *overflow to 1  if a * b overflows
 
 COMPILER_RT_ABI si_int __mulosi4(si_int a, si_int b, int *overflow) {
-  const int N = (int)(sizeof(si_int) * CHAR_BIT);
-  const si_int MIN = (si_int)1 << (N - 1);
-  const si_int MAX = ~MIN;
-  *overflow = 0;
-  si_int result = a * b;
-  if (a == MIN) {
-if (b != 0 && b != 1)
-  *overflow = 1;
-return result;
-  }
-  if (b == MIN) {
-if (a != 0 && a != 1)
-  *overflow = 1;
-return result;
-  }
-  si_int sa = a >> (N - 1);
-  si_int abs_a = (a ^ sa) - sa;
-  si_int sb = b >> (N - 1);
-  si_int abs_b = (b ^ sb) - sb;
-  if (abs_a < 2 || abs_b < 2)
-return result;
-  if (sa == sb) {
-if (abs_a > MAX / abs_b)
-  *overflow = 1;
-  } else {
-if (abs_a > MIN / -abs_b)
-  *overflow = 1;
-  }
-  return result;
+  return __muloXi4(a, b, overflow);
 }
Index: compiler-rt/lib/builtins/mulodi4.c
===
--- compiler-rt/lib/builtins/mulodi4.c
+++ compiler-rt/lib/builtins/mulodi4.c
@@ -10,40 +10,13 @@
 //
 //===--===//
 
-#include "int_lib.h"
+#define fixint_t di_int
+#include "int_mulo_impl.inc"
 
 // Returns: a * b
 
 // Effects: sets *overflow to 1  if a * b overflows
 
 COMPILER_RT_ABI di_int __mulodi4(di_int a, di_int b, int *overflow) {
-  const int N = (int)(sizeof(di_int) * CHAR_BIT);
-  const di_int MIN = (di_int)1 << (N - 1);
-  const di_int MAX = ~MIN;
-  *overflow = 0;
-  di_int result = a * b;
-  if (a == MIN) {
-if (b != 0 && b != 1)
-  *overflow = 1;
-return result;
-  }
-  if (b == MIN) {
-if (a != 0 && a != 1)
-  *overflow = 1;
-return result;
-  }
-  di_int sa = a >> (N - 1);
-  di_int abs_a = (a ^ sa) - sa;
-  di_int sb = b >> (N - 1);
-  di_int abs_b = (b ^ sb) - sb;
-  if (abs_a < 2 || abs_b < 2)
-return result;
-  if (sa == sb) {
-if (abs_a > MAX / abs_b)
-  *overflow = 1;
-  } else {
-if (abs_a > MIN / -abs_b)
-  *overflow = 1;
-  }
-  return result;
+  return __muloXi4(a, b, overflow);
 }
Index: compiler-rt/lib/builtins/int_mulo_impl.inc
===
--- compiler-rt/lib/builtins/int_mulo_impl.inc
+++ compiler-rt/lib/builtins/int_mulo_impl.inc
@@ -1,4 +1,4 @@
-//===-- mulodi4.c - Implement __mulodi4 

[PATCH] D86176: [clang-tidy] readability-simplify-boolean-expr detects negated literals

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



Comment at: 
clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp:66
+  if (const auto *Negated = Result.Nodes.getNodeAs(Id)) {
+if (Negated->getOpcode() == UO_LNot &&
+isa(Negated->getSubExpr()))

aaron.ballman wrote:
> I'd like to see this handled recursively instead so that we properly handle 
> more esoteric logic (but it still shows up from time to time) like `!!foo`: 
> https://codesearch.isocpp.org/cgi-bin/cgi_ppsearch?q=%21%21=Search
> 
> This is a case where I don't think the simplification should happen -- e.g., 
> the code is usually subtly incorrect when converted to remove the `!!`. It's 
> less clear to me whether the same is true for something like `!!!` being 
> converted to `!`, but that's not a case I'm really worried about either.
As this is only looking for boolean literals that shouldn't matter
`!!true` is identical to `true`.
I get putting `!!` in front of expressions that aren't boolean has an effect, 
but we aren't looking for that in this case.



Comment at: 
clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp:74
+internal::BindableMatcher literalOrNegatedBool(bool Value) {
+  return expr(anyOf(cxxBoolLiteral(equals(Value)),
+unaryOperator(hasUnaryOperand(ignoringParenImpCasts(

aaron.ballman wrote:
> Oof, but handling it here may be tricky...
A custom matcher could be made for this that could traverse a `UnaryOperator`



Comment at: 
clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp:289
   }
+  if (const auto *Unary = dyn_cast(Ret->getRetValue())) {
+if (Unary->getOpcode() == UO_LNot) {

aaron.ballman wrote:
> Same here.
This could be easily handled with some recursion.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86176

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


[PATCH] D83174: Teach AttachPreviousImpl to inherit MSInheritanceAttr attribute

2020-08-20 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/test/Modules/Inputs/inherit-attribute/b.h:3
+
+class Foo;
+

Does this forward declaration impact the test? I can't quite tell whether this 
exists to test that the attribute is attached to the non-defining redeclaration 
or not. (One way to make it more clear would be to have a less greedy regex in 
`inherit-attribute.cpp` so we can see the source location where the 
declarations are coming from.)



Comment at: clang/test/Modules/inherit-attribute.cpp:3
+// RUN: %clang_cc1 -fmodules -triple x86_64-pc-windows-msvc-unknown 
-I%S\Inputs\inherit-attribute -fmodules-cache-path=%t \
+// RUN: -fimplicit-module-maps -fmodules-local-submodule-visibility -verify %s 
-ast-dump-all \
+// RUN: | FileCheck %s

You can drop the `-verify` and `// expected-no-diagnostics` as they don't add 
anything to the test coverage.


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

https://reviews.llvm.org/D83174

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


[clang] 2bac004 - Add triples to fixed-point tests which lacked them.

2020-08-20 Thread Bevin Hansson via cfe-commits

Author: Bevin Hansson
Date: 2020-08-20T15:36:15+02:00
New Revision: 2bac004c905dc8db99fd3766678d33aa5a0eec2b

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

LOG: Add triples to fixed-point tests which lacked them.

This caused failures on clang-x390x-linux.

Added: 


Modified: 
clang/test/Frontend/fixed_point_mul.c
clang/test/Frontend/fixed_point_sub.c
clang/test/Frontend/fixed_point_sub_const.c

Removed: 




diff  --git a/clang/test/Frontend/fixed_point_mul.c 
b/clang/test/Frontend/fixed_point_mul.c
index 05d3f77d5a124..777c35c52d4a3 100644
--- a/clang/test/Frontend/fixed_point_mul.c
+++ b/clang/test/Frontend/fixed_point_mul.c
@@ -1,6 +1,6 @@
 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
-// RUN: %clang_cc1 -ffixed-point -S -emit-llvm %s -o - | FileCheck %s 
--check-prefixes=CHECK,SIGNED
-// RUN: %clang_cc1 -ffixed-point -fpadding-on-unsigned-fixed-point -S 
-emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK,UNSIGNED
+// RUN: %clang_cc1 -ffixed-point -triple x86_64-unknown-linux-gnu -S 
-emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK,SIGNED
+// RUN: %clang_cc1 -ffixed-point -triple x86_64-unknown-linux-gnu 
-fpadding-on-unsigned-fixed-point -S -emit-llvm %s -o - | FileCheck %s 
--check-prefixes=CHECK,UNSIGNED
 
 short _Accum sa;
 _Accum a, a2, a3, a4;

diff  --git a/clang/test/Frontend/fixed_point_sub.c 
b/clang/test/Frontend/fixed_point_sub.c
index 4e97f5d1ec589..4d07b4a522572 100644
--- a/clang/test/Frontend/fixed_point_sub.c
+++ b/clang/test/Frontend/fixed_point_sub.c
@@ -1,6 +1,6 @@
 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
-// RUN: %clang_cc1 -ffixed-point -S -emit-llvm %s -o - | FileCheck %s 
--check-prefixes=CHECK,SIGNED
-// RUN: %clang_cc1 -ffixed-point -fpadding-on-unsigned-fixed-point -S 
-emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK,UNSIGNED
+// RUN: %clang_cc1 -ffixed-point -triple x86_64-unknown-linux-gnu -S 
-emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK,SIGNED
+// RUN: %clang_cc1 -ffixed-point -triple x86_64-unknown-linux-gnu 
-fpadding-on-unsigned-fixed-point -S -emit-llvm %s -o - | FileCheck %s 
--check-prefixes=CHECK,UNSIGNED
 
 short _Accum sa;
 _Accum a, a2, a3, a4;

diff  --git a/clang/test/Frontend/fixed_point_sub_const.c 
b/clang/test/Frontend/fixed_point_sub_const.c
index 219ce5a411c1d..dc6ad92ec798d 100644
--- a/clang/test/Frontend/fixed_point_sub_const.c
+++ b/clang/test/Frontend/fixed_point_sub_const.c
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -ffixed-point -S -emit-llvm %s -o - | FileCheck %s 
--check-prefixes=CHECK,SIGNED
-// RUN: %clang_cc1 -ffixed-point -fpadding-on-unsigned-fixed-point -S 
-emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK,UNSIGNED
+// RUN: %clang_cc1 -ffixed-point -triple x86_64-unknown-linux-gnu -S 
-emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK,SIGNED
+// RUN: %clang_cc1 -ffixed-point -triple x86_64-unknown-linux-gnu 
-fpadding-on-unsigned-fixed-point -S -emit-llvm %s -o - | FileCheck %s 
--check-prefixes=CHECK,UNSIGNED
 
 // Subtraction between 
diff erent fixed point types
 short _Accum sa_const = 1.0hk - 2.0hk;



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


[PATCH] D86227: [SyntaxTree] Add support for `MemberExpression`

2020-08-20 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr2 accepted this revision.
gribozavr2 added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/lib/Tooling/Syntax/BuildTree.cpp:911
+  S->getEndLoc()),
+ idExpression, nullptr);
+

eduucaldas wrote:
> gribozavr2 wrote:
> > This code seems largely identical to WalkUpFromDeclRefExpr. (It is also 
> > somewhat difficult to track what is happening because we are creating three 
> > levels of nodes here.) Could we factor out the repeated code?
> I agree.
> However there are some things that change between semantic nodes that produce 
> an `IdExpression`.
> 
> * We may or not have a link from `IdExpression` to the AST.
> * The `SourceRange` for the `UnqualifiedId` is obtained in an ad-hoc manner.
> 
> Taking into these variables we could write a function `buildIdExpression`
> 
> 1. `IdExpression* buildIdExpression(Expr* E, SourceRange UnqualifiedIdLoc, 
> bool shouldLinkToAST);`
> 2. `IdExpression* buildIdExpression(SourceRange QualifierLoc, SourceRange 
> TemplateKwLoc, SourceRange UnqualifiedIdLoc, ASTPtr link);`
> 
> The first option takes into account only the differences that we perceived 
> until now.
> The second option provides a more general approach.
I'd prefer (2), it is less subtle and more explicit.



Comment at: clang/unittests/Tooling/Syntax/BuildTreeTest.cpp:1999
+
+TEST_P(SyntaxTreeTest, MemberExpression_StaticMemberFunction) {
+  if (!GetParam().isCXX()) {




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86227

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


[PATCH] D85706: [compiler-rt] Compile assembly files as ASM not C

2020-08-20 Thread Raphael Isemann via Phabricator via cfe-commits
teemperor added a comment.

I reverted in adf0b8cc70325f027d202139e3ff984c41896b57 
 to get 
the bots green again . Feel free to ping if you need someone to test the patch 
on macOS.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85706

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


[clang] adf0b8c - Revert "[compiler-rt] Compile assembly files as ASM not C"

2020-08-20 Thread Raphael Isemann via cfe-commits

Author: Raphael Isemann
Date: 2020-08-20T15:25:22+02:00
New Revision: adf0b8cc70325f027d202139e3ff984c41896b57

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

LOG: Revert "[compiler-rt] Compile assembly files as ASM not C"

This reverts commit d58fd4e52197d55bf42ca446c8b0ed31b5c2ec1f. This broke
compiler-rt compilation on macOS:

codesign --sign - 
/Users/buildslave/jenkins/workspace/lldb-cmake/lldb-build/lib/clang/12.0.99/lib/darwin/libclang_rt.tsan_ios_dynamic.dylib
ld: warning: ignoring file 
projects/compiler-rt/lib/tsan/CMakeFiles/clang_rt.tsan_ios_dynamic.dir/rtl/tsan_rtl_amd64.S.o,
 building for iOS-arm64 but attempting to link with file built for iOS 
Simulator-x86_64
ld: warning: ignoring file 
projects/compiler-rt/lib/tsan/CMakeFiles/clang_rt.tsan_ios_dynamic.dir/rtl/tsan_rtl_aarch64.S.o,
 building for iOS-arm64 but attempting to link with file built for iOS 
Simulator-x86_64
Undefined symbols for architecture arm64:
  "_wrap__setjmp", referenced from:
  substitution__setjmp in tsan_interceptors_posix.cpp.o
  "_wrap_setjmp", referenced from:
  substitution_setjmp in tsan_interceptors_posix.cpp.o
  "_wrap_sigsetjmp", referenced from:
  substitution_sigsetjmp in tsan_interceptors_posix.cpp.o
ld: symbol(s) not found for architecture arm64

Added: 


Modified: 
clang/runtime/CMakeLists.txt
compiler-rt/cmake/Modules/AddCompilerRT.cmake

Removed: 




diff  --git a/clang/runtime/CMakeLists.txt b/clang/runtime/CMakeLists.txt
index 61bbbf8faedd..e20cc26f60af 100644
--- a/clang/runtime/CMakeLists.txt
+++ b/clang/runtime/CMakeLists.txt
@@ -75,7 +75,6 @@ if(LLVM_BUILD_EXTERNAL_COMPILER_RT AND EXISTS 
${COMPILER_RT_SRC_ROOT}/)
 CMAKE_ARGS ${CLANG_COMPILER_RT_CMAKE_ARGS}
-DCMAKE_C_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang
-DCMAKE_CXX_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang++
-   -DCMAKE_ASM_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM}
-DLLVM_CONFIG_PATH=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-config

diff  --git a/compiler-rt/cmake/Modules/AddCompilerRT.cmake 
b/compiler-rt/cmake/Modules/AddCompilerRT.cmake
index 7063cf89d7ab..efb660818270 100644
--- a/compiler-rt/cmake/Modules/AddCompilerRT.cmake
+++ b/compiler-rt/cmake/Modules/AddCompilerRT.cmake
@@ -109,11 +109,13 @@ endfunction()
 
 function(add_asm_sources output)
   set(${output} ${ARGN} PARENT_SCOPE)
-  # Make sure ASM language is available.
-  # We explicitly mark the source files as ASM, so they don't get passed to the
-  # C/CXX compiler and hopes that it recognizes them as assembly.
-  enable_language(ASM)
-  set_source_files_properties(${ARGN} PROPERTIES LANGUAGE ASM)
+  # Xcode will try to compile asm files as C ('clang -x c'), and that will 
fail.
+  if (${CMAKE_GENERATOR} STREQUAL "Xcode")
+enable_language(ASM)
+  else()
+# Pass ASM file directly to the C++ compiler.
+set_source_files_properties(${ARGN} PROPERTIES LANGUAGE C)
+  endif()
 endfunction()
 
 macro(set_output_name output name arch)



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


[PATCH] D85706: [compiler-rt] Compile assembly files as ASM not C

2020-08-20 Thread Raphael Isemann via Phabricator via cfe-commits
teemperor added a comment.

This broke Green Dragon's compiler-rt builds and also my local compiler-rt 
build. See for example here: 
http://green.lab.llvm.org/green/view/LLDB/job/lldb-cmake/23424/console


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85706

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


[clang-tools-extra] 03ded54 - Fix -allow-enabling-analyzer-alpha-checkers always being passed to run-clang-tidy.py

2020-08-20 Thread Aaron Ballman via cfe-commits

Author: Joachim Priesner
Date: 2020-08-20T09:15:29-04:00
New Revision: 03ded5497a2f458b6af054fa7bac0da0240e7b7a

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

LOG: Fix -allow-enabling-analyzer-alpha-checkers always being passed to 
run-clang-tidy.py

The action='store_true' option of argparse.add_argument implicitly
generates a default value of False if the argument is not specified.
Thus, the allow_enabling_alpha_checkers argument of
get_tidy_invocation is never None.

Added: 


Modified: 
clang-tools-extra/clang-tidy/tool/run-clang-tidy.py

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py 
b/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
index 4272ae0957fe..7e23419cd916 100755
--- a/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
+++ b/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
@@ -84,7 +84,7 @@ def get_tidy_invocation(f, clang_tidy_binary, checks, tmpdir, 
build_path,
 extra_arg, extra_arg_before, quiet, config):
   """Gets a command line for clang-tidy."""
   start = [clang_tidy_binary]
-  if allow_enabling_alpha_checkers is not None:
+  if allow_enabling_alpha_checkers:
 start.append('-allow-enabling-analyzer-alpha-checkers')
   if header_filter is not None:
 start.append('-header-filter=' + header_filter)



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


[PATCH] D86209: [clang-tidy] run-clang-tidy.py: Fix -allow-enabling-analyzer-alpha-checkers always being passed

2020-08-20 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman closed this revision.
aaron.ballman added a comment.

I've commit on your behalf as 03ded5497a2f458b6af054fa7bac0da0240e7b7a 
, thank 
you for the patch!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86209

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


[PATCH] D86209: [clang-tidy] run-clang-tidy.py: Fix -allow-enabling-analyzer-alpha-checkers always being passed

2020-08-20 Thread Joachim Priesner via Phabricator via cfe-commits
jspam added a comment.

Yes please. I am fine with the license agreement, and please use Joachim 
Priesner  as the commit author. Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86209

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


[PATCH] D86227: [SyntaxTree] Add support for `MemberExpression`

2020-08-20 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas marked an inline comment as done.
eduucaldas added inline comments.



Comment at: clang/lib/Tooling/Syntax/BuildTree.cpp:900
+
+auto *unqualifiedId = new (allocator()) syntax::UnqualifiedId;
+Builder.foldNode(Builder.getRange(S->getMemberLoc(), S->getEndLoc()),

gribozavr2 wrote:
> Please make unqualifiedId variable start with the uppercase character. Since 
> it would clash with the type name, you can do `TheUnqualifiedId`, for example.
> 
> Same for `idExpression` below.
I just saw in the style guide the rules for casing.

I didn't expect this to exist because it doesn't seem to be obeyed ^^. For 
instance WalkUpFrom* starts with Upper-case.

I'll follow-up with a patch fixing any style problems of this nature.



Comment at: clang/lib/Tooling/Syntax/BuildTree.cpp:911
+  S->getEndLoc()),
+ idExpression, nullptr);
+

gribozavr2 wrote:
> This code seems largely identical to WalkUpFromDeclRefExpr. (It is also 
> somewhat difficult to track what is happening because we are creating three 
> levels of nodes here.) Could we factor out the repeated code?
I agree.
However there are some things that change between semantic nodes that produce 
an `IdExpression`.

* We may or not have a link from `IdExpression` to the AST.
* The `SourceRange` for the `UnqualifiedId` is obtained in an ad-hoc manner.

Taking into these variables we could write a function `buildIdExpression`

1. `IdExpression* buildIdExpression(Expr* E, SourceRange UnqualifiedIdLoc, bool 
shouldLinkToAST);`
2. `IdExpression* buildIdExpression(SourceRange QualifierLoc, SourceRange 
TemplateKwLoc, SourceRange UnqualifiedIdLoc, ASTPtr link);`

The first option takes into account only the differences that we perceived 
until now.
The second option provides a more general approach.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86227

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


[PATCH] D86227: [SyntaxTree] Add support for `MemberExpression`

2020-08-20 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas updated this revision to Diff 286799.
eduucaldas marked 10 inline comments as done.
eduucaldas added a comment.

Answering comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86227

Files:
  clang/include/clang/Tooling/Syntax/Nodes.h
  clang/lib/Tooling/Syntax/BuildTree.cpp
  clang/lib/Tooling/Syntax/Nodes.cpp
  clang/unittests/Tooling/Syntax/BuildTreeTest.cpp

Index: clang/unittests/Tooling/Syntax/BuildTreeTest.cpp
===
--- clang/unittests/Tooling/Syntax/BuildTreeTest.cpp
+++ clang/unittests/Tooling/Syntax/BuildTreeTest.cpp
@@ -491,19 +491,20 @@
   operator int();
 };
 void test(X x) {
-  // TODO: Expose `id-expression` from `MemberExpr`
   [[x.operator int()]];
 }
 )cpp",
   {R"txt(
 UnknownExpression
-|-UnknownExpression
+|-MemberExpression
 | |-IdExpression
 | | `-UnqualifiedId
 | |   `-x
 | |-.
-| |-operator
-| `-int
+| `-IdExpression
+|   `-UnqualifiedId
+| |-operator
+| `-int
 |-(
 `-)
 )txt"}));
@@ -542,19 +543,20 @@
   R"cpp(
 struct X { };
 void test(X x) {
-  // TODO: Expose `id-expression` from `MemberExpr`
   [[x.~X()]];
 }
 )cpp",
   {R"txt(
 UnknownExpression
-|-UnknownExpression
+|-MemberExpression
 | |-IdExpression
 | | `-UnqualifiedId
 | |   `-x
 | |-.
-| |-~
-| `-X
+| `-IdExpression
+|   `-UnqualifiedId
+| |-~
+| `-X
 |-(
 `-)
 )txt"}));
@@ -568,18 +570,23 @@
   R"cpp(
 struct X { };
 void test(X x) {
-  // TODO: Expose `id-expression` from `MemberExpr`
+  // FIXME: Make `decltype(x)` a child of `MemberExpression`. It is currently
+  // not because `Expr::getSourceRange()` returns the range of `x.~` for the
+  // `MemberExpr` instead of the expected `x.~decltype(x)`, this is a bug in
+  // clang.
   [[x.~decltype(x)()]];
 }
 )cpp",
   {R"txt(
 UnknownExpression
-|-UnknownExpression
+|-MemberExpression
 | |-IdExpression
 | | `-UnqualifiedId
 | |   `-x
 | |-.
-| `-~
+| `-IdExpression
+|   `-UnqualifiedId
+| `-~
 |-decltype
 |-(
 |-x
@@ -624,6 +631,9 @@
   struct S { };
 }
 void test() {
+  // FIXME: Remove the `UnknownExpression` wrapping `s1` and `s2`. This
+  // `UnknownExpression` comes from a leaf `CXXConstructExpr` in the
+  // ClangAST. We need to ignore leaf implicit nodes.
   [[::n::S s1]];
   [[n::S s2]];
 }
@@ -1756,6 +1766,9 @@
 struct X {
   friend X operator+(X, const X&);
 };
+// FIXME: Remove additional `UnknownExpression` wrapping `x`. For that, ignore
+// implicit copy constructor called on `x`. This should've been ignored already,
+// as we `IgnoreImplicit` when traversing an `Stmt`.
 void test(X x, X y) {
   [[x + y]];
 }
@@ -1961,6 +1974,366 @@
 )txt"}));
 }
 
+TEST_P(SyntaxTreeTest, MemberExpression_SimpleWithDot) {
+  EXPECT_TRUE(treeDumpEqualOnAnnotations(
+  R"cpp(
+struct S {
+  int a;
+};
+void test(struct S s) {
+  [[s.a]];
+}
+)cpp",
+  {R"txt(
+MemberExpression
+|-IdExpression
+| `-UnqualifiedId
+|   `-s
+|-.
+`-IdExpression
+  `-UnqualifiedId
+`-a
+)txt"}));
+}
+
+TEST_P(SyntaxTreeTest, MemberExpression_StaticMemberFunction) {
+  if (!GetParam().isCXX()) {
+return;
+  }
+  EXPECT_TRUE(treeDumpEqualOnAnnotations(
+  R"cpp(
+struct S {
+  static int a;
+};
+void test(S s) {
+  [[s.a]];
+}
+)cpp",
+  {R"txt(
+MemberExpression
+|-IdExpression
+| `-UnqualifiedId
+|   `-s
+|-.
+`-IdExpression
+  `-UnqualifiedId
+`-a
+)txt"}));
+}
+
+TEST_P(SyntaxTreeTest, MemberExpression_SimpleWithArrow) {
+  EXPECT_TRUE(treeDumpEqualOnAnnotations(
+  R"cpp(
+struct S {
+  int a;
+};
+void test(struct S* sp) {
+  [[sp->a]];
+}
+)cpp",
+  {R"txt(
+MemberExpression
+|-IdExpression
+| `-UnqualifiedId
+|   `-sp
+|-->
+`-IdExpression
+  `-UnqualifiedId
+`-a
+)txt"}));
+}
+
+TEST_P(SyntaxTreeTest, MemberExpression_Chaining) {
+  EXPECT_TRUE(treeDumpEqualOnAnnotations(
+  R"cpp(
+struct S {
+  struct S* next;
+};
+void test(struct S s){
+  [[s.next->next]];
+}
+)cpp",
+  {R"txt(
+MemberExpression
+|-MemberExpression
+| |-IdExpression
+| | `-UnqualifiedId
+| |   `-s
+| |-.
+| `-IdExpression
+|   `-UnqualifiedId
+| `-next
+|-->
+`-IdExpression
+  `-UnqualifiedId
+`-next
+)txt"}));
+}
+
+TEST_P(SyntaxTreeTest, MemberExpression_OperatorFunction) {
+  if (!GetParam().isCXX()) {
+return;
+  }
+  EXPECT_TRUE(treeDumpEqualOnAnnotations(
+  R"cpp(
+struct S {
+  bool operator!();
+};
+void test(S s) {
+  [[s.operator!()]];
+}
+)cpp",
+  {R"txt(
+UnknownExpression
+|-MemberExpression
+| |-IdExpression
+| | `-UnqualifiedId
+| |   `-s
+| |-.
+| `-IdExpression
+|   `-UnqualifiedId
+| |-operator
+| `-!
+|-(
+`-)
+)txt"}));
+}
+
+TEST_P(SyntaxTreeTest, MemberExpression_Implicit) {
+  if (!GetParam().isCXX()) {
+return;
+  }
+  EXPECT_TRUE(treeDumpEqualOnAnnotations(
+  R"cpp(
+struct S {
+  int a;
+  int test(){
+// FIXME: Remove the `UnknownExpression` wrapping `a`. This
+// `UnknownExpression` comes from an 

[PATCH] D86279: [clangd] Don't crash on `#pragma clang __debug parser_crash`

2020-08-20 Thread Aleksandr Platonov via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG445739826567: [clangd] Dont crash on `#pragma clang 
__debug parser_crash` (authored by ArcsinX).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86279

Files:
  clang-tools-extra/clangd/Compiler.cpp
  clang-tools-extra/clangd/unittests/CompilerTests.cpp


Index: clang-tools-extra/clangd/unittests/CompilerTests.cpp
===
--- clang-tools-extra/clangd/unittests/CompilerTests.cpp
+++ clang-tools-extra/clangd/unittests/CompilerTests.cpp
@@ -51,6 +51,11 @@
   IsEmpty());
 }
 
+TEST(BuildCompilerInvocation, PragmaDebugCrash) {
+  TestTU TU = TestTU::withCode("#pragma clang __debug parser_crash");
+  TU.build(); // no-crash
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/Compiler.cpp
===
--- clang-tools-extra/clangd/Compiler.cpp
+++ clang-tools-extra/clangd/Compiler.cpp
@@ -78,6 +78,8 @@
   CI->getPreprocessorOpts().PCHThroughHeader.clear();
   CI->getPreprocessorOpts().PCHWithHdrStop = false;
   CI->getPreprocessorOpts().PCHWithHdrStopCreate = false;
+  // Don't crash on `#pragma clang __debug parser_crash`
+  CI->getPreprocessorOpts().DisablePragmaDebugCrash = true;
 
   // Recovery expression currently only works for C++.
   if (CI->getLangOpts()->CPlusPlus) {


Index: clang-tools-extra/clangd/unittests/CompilerTests.cpp
===
--- clang-tools-extra/clangd/unittests/CompilerTests.cpp
+++ clang-tools-extra/clangd/unittests/CompilerTests.cpp
@@ -51,6 +51,11 @@
   IsEmpty());
 }
 
+TEST(BuildCompilerInvocation, PragmaDebugCrash) {
+  TestTU TU = TestTU::withCode("#pragma clang __debug parser_crash");
+  TU.build(); // no-crash
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/Compiler.cpp
===
--- clang-tools-extra/clangd/Compiler.cpp
+++ clang-tools-extra/clangd/Compiler.cpp
@@ -78,6 +78,8 @@
   CI->getPreprocessorOpts().PCHThroughHeader.clear();
   CI->getPreprocessorOpts().PCHWithHdrStop = false;
   CI->getPreprocessorOpts().PCHWithHdrStopCreate = false;
+  // Don't crash on `#pragma clang __debug parser_crash`
+  CI->getPreprocessorOpts().DisablePragmaDebugCrash = true;
 
   // Recovery expression currently only works for C++.
   if (CI->getLangOpts()->CPlusPlus) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] 4457398 - [clangd] Don't crash on `#pragma clang __debug parser_crash`

2020-08-20 Thread Aleksandr Platonov via cfe-commits

Author: Aleksandr Platonov
Date: 2020-08-20T15:53:21+03:00
New Revision: 445739826567e5402b558f2c130d76dc916c82ec

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

LOG: [clangd] Don't crash on `#pragma clang __debug parser_crash`

Currently, clangd crashes when opening a file with `#pragma clang __debug 
parser_crash` (e.g. clang/test/Modules/Inputs/crash.h).
This patch disables these crashes.

Reviewed By: kadircet

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

Added: 


Modified: 
clang-tools-extra/clangd/Compiler.cpp
clang-tools-extra/clangd/unittests/CompilerTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/Compiler.cpp 
b/clang-tools-extra/clangd/Compiler.cpp
index 2c7ef471d382..f5875e2a7971 100644
--- a/clang-tools-extra/clangd/Compiler.cpp
+++ b/clang-tools-extra/clangd/Compiler.cpp
@@ -78,6 +78,8 @@ buildCompilerInvocation(const ParseInputs , 
clang::DiagnosticConsumer ,
   CI->getPreprocessorOpts().PCHThroughHeader.clear();
   CI->getPreprocessorOpts().PCHWithHdrStop = false;
   CI->getPreprocessorOpts().PCHWithHdrStopCreate = false;
+  // Don't crash on `#pragma clang __debug parser_crash`
+  CI->getPreprocessorOpts().DisablePragmaDebugCrash = true;
 
   // Recovery expression currently only works for C++.
   if (CI->getLangOpts()->CPlusPlus) {

diff  --git a/clang-tools-extra/clangd/unittests/CompilerTests.cpp 
b/clang-tools-extra/clangd/unittests/CompilerTests.cpp
index 59feb9312d23..45e9bcd9d534 100644
--- a/clang-tools-extra/clangd/unittests/CompilerTests.cpp
+++ b/clang-tools-extra/clangd/unittests/CompilerTests.cpp
@@ -51,6 +51,11 @@ TEST(BuildCompilerInvocation, DropsPCH) {
   IsEmpty());
 }
 
+TEST(BuildCompilerInvocation, PragmaDebugCrash) {
+  TestTU TU = TestTU::withCode("#pragma clang __debug parser_crash");
+  TU.build(); // no-crash
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang



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


[PATCH] D86284: [clangd] Remove useless stderr logging.

2020-08-20 Thread Adam Czachorowski via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG707138d67786: [clangd] Remove useless stderr logging. 
(authored by adamcz).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86284

Files:
  clang-tools-extra/clangd/unittests/TestTU.cpp


Index: clang-tools-extra/clangd/unittests/TestTU.cpp
===
--- clang-tools-extra/clangd/unittests/TestTU.cpp
+++ clang-tools-extra/clangd/unittests/TestTU.cpp
@@ -74,8 +74,6 @@
   ASSERT_FALSE(
   llvm::sys::fs::createUniqueDirectory("module-cache", ModuleCachePath));
   CI.getHeaderSearchOpts().ModuleCachePath = ModuleCachePath.c_str();
-  llvm::errs() << "MC: " << ModuleCachePath << "\n";
-  llvm::errs().flush();
 }
 
 void deleteModuleCache(const std::string ModuleCachePath) {


Index: clang-tools-extra/clangd/unittests/TestTU.cpp
===
--- clang-tools-extra/clangd/unittests/TestTU.cpp
+++ clang-tools-extra/clangd/unittests/TestTU.cpp
@@ -74,8 +74,6 @@
   ASSERT_FALSE(
   llvm::sys::fs::createUniqueDirectory("module-cache", ModuleCachePath));
   CI.getHeaderSearchOpts().ModuleCachePath = ModuleCachePath.c_str();
-  llvm::errs() << "MC: " << ModuleCachePath << "\n";
-  llvm::errs().flush();
 }
 
 void deleteModuleCache(const std::string ModuleCachePath) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] 707138d - [clangd] Remove useless stderr logging.

2020-08-20 Thread Adam Czachorowski via cfe-commits

Author: Adam Czachorowski
Date: 2020-08-20T14:52:04+02:00
New Revision: 707138d677861182083b3c6c3b44b76951fd36ef

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

LOG: [clangd] Remove useless stderr logging.

This was accidentally added in 53b9199a5cdba8a6e294e1fb183f308ec558db22

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

Added: 


Modified: 
clang-tools-extra/clangd/unittests/TestTU.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/unittests/TestTU.cpp 
b/clang-tools-extra/clangd/unittests/TestTU.cpp
index c468642e6338..03254f876721 100644
--- a/clang-tools-extra/clangd/unittests/TestTU.cpp
+++ b/clang-tools-extra/clangd/unittests/TestTU.cpp
@@ -74,8 +74,6 @@ void initializeModuleCache(CompilerInvocation ) {
   ASSERT_FALSE(
   llvm::sys::fs::createUniqueDirectory("module-cache", ModuleCachePath));
   CI.getHeaderSearchOpts().ModuleCachePath = ModuleCachePath.c_str();
-  llvm::errs() << "MC: " << ModuleCachePath << "\n";
-  llvm::errs().flush();
 }
 
 void deleteModuleCache(const std::string ModuleCachePath) {



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


[PATCH] D86284: [clangd] Remove useless stderr logging.

2020-08-20 Thread Adam Czachorowski via Phabricator via cfe-commits
adamcz created this revision.
Herald added subscribers: cfe-commits, usaxena95, kadircet, arphaman, jkorous.
Herald added a project: clang.
adamcz requested review of this revision.
Herald added subscribers: MaskRay, ilya-biryukov.

This was accidentally added in 53b9199a5cdba8a6e294e1fb183f308ec558db22 



Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D86284

Files:
  clang-tools-extra/clangd/unittests/TestTU.cpp


Index: clang-tools-extra/clangd/unittests/TestTU.cpp
===
--- clang-tools-extra/clangd/unittests/TestTU.cpp
+++ clang-tools-extra/clangd/unittests/TestTU.cpp
@@ -74,8 +74,6 @@
   ASSERT_FALSE(
   llvm::sys::fs::createUniqueDirectory("module-cache", ModuleCachePath));
   CI.getHeaderSearchOpts().ModuleCachePath = ModuleCachePath.c_str();
-  llvm::errs() << "MC: " << ModuleCachePath << "\n";
-  llvm::errs().flush();
 }
 
 void deleteModuleCache(const std::string ModuleCachePath) {


Index: clang-tools-extra/clangd/unittests/TestTU.cpp
===
--- clang-tools-extra/clangd/unittests/TestTU.cpp
+++ clang-tools-extra/clangd/unittests/TestTU.cpp
@@ -74,8 +74,6 @@
   ASSERT_FALSE(
   llvm::sys::fs::createUniqueDirectory("module-cache", ModuleCachePath));
   CI.getHeaderSearchOpts().ModuleCachePath = ModuleCachePath.c_str();
-  llvm::errs() << "MC: " << ModuleCachePath << "\n";
-  llvm::errs().flush();
 }
 
 void deleteModuleCache(const std::string ModuleCachePath) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D85923: [clangd] Fix crash-bug in preamble indexing when using modules.

2020-08-20 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clang-tools-extra/clangd/unittests/TestTU.cpp:77
+  CI.getHeaderSearchOpts().ModuleCachePath = ModuleCachePath.c_str();
+  llvm::errs() << "MC: " << ModuleCachePath << "\n";
+  llvm::errs().flush();

errs should probably go away



Comment at: clang-tools-extra/clangd/unittests/TestTU.cpp:96
+  auto ModuleCacheDeleter = llvm::make_scope_exit(
+  std::bind(deleteModuleCache, CI->getHeaderSearchOpts().ModuleCachePath));
   return clang::clangd::buildPreamble(testPath(Filename), *CI, Inputs,

or just `[&]{ deleteModuleCache(...); }` - bind isn't unreadable here, but we 
use it so rarely that it almost feels obscure :-)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85923

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


[PATCH] D86229: [X86] Enable constexpr on POPCNT intrinsics (PR31446)

2020-08-20 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon added a comment.

I think that's everything - I'd prefer to handle the registered target fixes in 
separate commits.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86229

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


[PATCH] D86282: [Fixed Point] Use FixedPointBuilder to codegen fixed-point IR.

2020-08-20 Thread Bevin Hansson via Phabricator via cfe-commits
ebevhan created this revision.
ebevhan added reviewers: leonardchan, rjmccall.
Herald added a subscriber: bjope.
Herald added a project: clang.
ebevhan requested review of this revision.

This changes the methods in CGExprScalar to use
FixedPointBuilder to generate IR for fixed-point
conversions and operations.

Since FixedPointBuilder emits padded operations slightly
differently than the original code, some tests change.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D86282

Files:
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/test/Frontend/fixed_point_add.c
  clang/test/Frontend/fixed_point_div.c
  clang/test/Frontend/fixed_point_mul.c
  clang/test/Frontend/fixed_point_sub.c
  clang/test/Frontend/fixed_point_unary.c

Index: clang/test/Frontend/fixed_point_unary.c
===
--- clang/test/Frontend/fixed_point_unary.c
+++ clang/test/Frontend/fixed_point_unary.c
@@ -148,9 +148,9 @@
 // UNSIGNED-LABEL: @inc_sua(
 // UNSIGNED-NEXT:  entry:
 // UNSIGNED-NEXT:[[TMP0:%.*]] = load i32, i32* @sua, align 4
-// UNSIGNED-NEXT:[[RESIZE:%.*]] = trunc i32 [[TMP0]] to i31
-// UNSIGNED-NEXT:[[TMP1:%.*]] = call i31 @llvm.uadd.sat.i31(i31 [[RESIZE]], i31 32768)
-// UNSIGNED-NEXT:[[RESIZE1:%.*]] = zext i31 [[TMP1]] to i32
+// UNSIGNED-NEXT:[[TMP1:%.*]] = call i32 @llvm.sadd.sat.i32(i32 [[TMP0]], i32 32768)
+// UNSIGNED-NEXT:[[RESIZE:%.*]] = trunc i32 [[TMP1]] to i31
+// UNSIGNED-NEXT:[[RESIZE1:%.*]] = zext i31 [[RESIZE]] to i32
 // UNSIGNED-NEXT:store i32 [[RESIZE1]], i32* @sua, align 4
 // UNSIGNED-NEXT:ret void
 //
@@ -168,9 +168,9 @@
 // UNSIGNED-LABEL: @inc_susa(
 // UNSIGNED-NEXT:  entry:
 // UNSIGNED-NEXT:[[TMP0:%.*]] = load i16, i16* @susa, align 2
-// UNSIGNED-NEXT:[[RESIZE:%.*]] = trunc i16 [[TMP0]] to i15
-// UNSIGNED-NEXT:[[TMP1:%.*]] = call i15 @llvm.uadd.sat.i15(i15 [[RESIZE]], i15 128)
-// UNSIGNED-NEXT:[[RESIZE1:%.*]] = zext i15 [[TMP1]] to i16
+// UNSIGNED-NEXT:[[TMP1:%.*]] = call i16 @llvm.sadd.sat.i16(i16 [[TMP0]], i16 128)
+// UNSIGNED-NEXT:[[RESIZE:%.*]] = trunc i16 [[TMP1]] to i15
+// UNSIGNED-NEXT:[[RESIZE1:%.*]] = zext i15 [[RESIZE]] to i16
 // UNSIGNED-NEXT:store i16 [[RESIZE1]], i16* @susa, align 2
 // UNSIGNED-NEXT:ret void
 //
@@ -188,9 +188,9 @@
 // UNSIGNED-LABEL: @inc_suf(
 // UNSIGNED-NEXT:  entry:
 // UNSIGNED-NEXT:[[TMP0:%.*]] = load i16, i16* @suf, align 2
-// UNSIGNED-NEXT:[[RESIZE:%.*]] = trunc i16 [[TMP0]] to i15
-// UNSIGNED-NEXT:[[TMP1:%.*]] = call i15 @llvm.uadd.sat.i15(i15 [[RESIZE]], i15 -1)
-// UNSIGNED-NEXT:[[RESIZE1:%.*]] = zext i15 [[TMP1]] to i16
+// UNSIGNED-NEXT:[[TMP1:%.*]] = call i16 @llvm.sadd.sat.i16(i16 [[TMP0]], i16 32767)
+// UNSIGNED-NEXT:[[RESIZE:%.*]] = trunc i16 [[TMP1]] to i15
+// UNSIGNED-NEXT:[[RESIZE1:%.*]] = zext i15 [[RESIZE]] to i16
 // UNSIGNED-NEXT:store i16 [[RESIZE1]], i16* @suf, align 2
 // UNSIGNED-NEXT:ret void
 //
@@ -329,9 +329,11 @@
 // UNSIGNED-LABEL: @dec_sua(
 // UNSIGNED-NEXT:  entry:
 // UNSIGNED-NEXT:[[TMP0:%.*]] = load i32, i32* @sua, align 4
-// UNSIGNED-NEXT:[[RESIZE:%.*]] = trunc i32 [[TMP0]] to i31
-// UNSIGNED-NEXT:[[TMP1:%.*]] = call i31 @llvm.usub.sat.i31(i31 [[RESIZE]], i31 32768)
-// UNSIGNED-NEXT:[[RESIZE1:%.*]] = zext i31 [[TMP1]] to i32
+// UNSIGNED-NEXT:[[TMP1:%.*]] = call i32 @llvm.ssub.sat.i32(i32 [[TMP0]], i32 32768)
+// UNSIGNED-NEXT:[[TMP2:%.*]] = icmp slt i32 [[TMP1]], 0
+// UNSIGNED-NEXT:[[SATMIN:%.*]] = select i1 [[TMP2]], i32 0, i32 [[TMP1]]
+// UNSIGNED-NEXT:[[RESIZE:%.*]] = trunc i32 [[SATMIN]] to i31
+// UNSIGNED-NEXT:[[RESIZE1:%.*]] = zext i31 [[RESIZE]] to i32
 // UNSIGNED-NEXT:store i32 [[RESIZE1]], i32* @sua, align 4
 // UNSIGNED-NEXT:ret void
 //
@@ -349,9 +351,11 @@
 // UNSIGNED-LABEL: @dec_susa(
 // UNSIGNED-NEXT:  entry:
 // UNSIGNED-NEXT:[[TMP0:%.*]] = load i16, i16* @susa, align 2
-// UNSIGNED-NEXT:[[RESIZE:%.*]] = trunc i16 [[TMP0]] to i15
-// UNSIGNED-NEXT:[[TMP1:%.*]] = call i15 @llvm.usub.sat.i15(i15 [[RESIZE]], i15 128)
-// UNSIGNED-NEXT:[[RESIZE1:%.*]] = zext i15 [[TMP1]] to i16
+// UNSIGNED-NEXT:[[TMP1:%.*]] = call i16 @llvm.ssub.sat.i16(i16 [[TMP0]], i16 128)
+// UNSIGNED-NEXT:[[TMP2:%.*]] = icmp slt i16 [[TMP1]], 0
+// UNSIGNED-NEXT:[[SATMIN:%.*]] = select i1 [[TMP2]], i16 0, i16 [[TMP1]]
+// UNSIGNED-NEXT:[[RESIZE:%.*]] = trunc i16 [[SATMIN]] to i15
+// UNSIGNED-NEXT:[[RESIZE1:%.*]] = zext i15 [[RESIZE]] to i16
 // UNSIGNED-NEXT:store i16 [[RESIZE1]], i16* @susa, align 2
 // UNSIGNED-NEXT:ret void
 //
@@ -369,9 +373,11 @@
 // UNSIGNED-LABEL: @dec_suf(
 // UNSIGNED-NEXT:  entry:
 // UNSIGNED-NEXT:[[TMP0:%.*]] = load i16, i16* @suf, align 2
-// UNSIGNED-NEXT:[[RESIZE:%.*]] = trunc i16 [[TMP0]] to i15
-// UNSIGNED-NEXT:[[TMP1:%.*]] = call i15 @llvm.usub.sat.i15(i15 [[RESIZE]], i15 -1)
-// UNSIGNED-NEXT:[[RESIZE1:%.*]] 

[clang-tools-extra] 53b9199 - [clangd] Fix crash-bug in preamble indexing when using modules.

2020-08-20 Thread Adam Czachorowski via cfe-commits

Author: Adam Czachorowski
Date: 2020-08-20T14:19:52+02:00
New Revision: 53b9199a5cdba8a6e294e1fb183f308ec558db22

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

LOG: [clangd] Fix crash-bug in preamble indexing when using modules.

When preamble contains #undef, indexing code finds the matching #define
and uses that during indexing. However, it would only look for local
definitions. If the macro was defined in a module, MacroInfo
would be nullptr and clangd would crash.

This change makes clangd ignore any #undef without a matching #define
inside the same TU.

The indexing of macros happens for preamble only, so then #undef must be
in the preamble, which is why we need two .h files in a test.

Note that clangd is currently not ready for module support, but this
brings us one step closer.

This was previously attempted in
4061d9e42cff621462931ac7df9666806c77a237, but had to be reverted due to
broken test. This version fixes that test-only bug by setting a custom module
cache path to avoid re-use of modules across test invocations.

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

Added: 


Modified: 
clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
clang-tools-extra/clangd/unittests/TestFS.h
clang-tools-extra/clangd/unittests/TestTU.cpp
clang-tools-extra/clangd/unittests/TestTU.h
clang/lib/Index/IndexingAction.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp 
b/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
index d89db8f015ce..3940946d8016 100644
--- a/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
+++ b/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
@@ -1623,6 +1623,31 @@ TEST_F(SymbolCollectorTest, MacrosInHeaders) {
   EXPECT_THAT(Symbols,
   UnorderedElementsAre(AllOf(QName("X"), 
ForCodeCompletion(true;
 }
+
+// Regression test for a crash-bug we used to have.
+TEST_F(SymbolCollectorTest, UndefOfModuleMacro) {
+  auto TU = TestTU::withCode(R"cpp(#include "bar.h")cpp");
+  TU.AdditionalFiles["bar.h"] = R"cpp(
+#include "foo.h"
+#undef X
+)cpp";
+  TU.AdditionalFiles["foo.h"] = "#define X 1";
+  TU.AdditionalFiles["module.map"] = R"cpp(
+module foo {
+ header "foo.h"
+ export *
+   }
+   )cpp";
+  TU.ExtraArgs.push_back("-fmodules");
+  TU.ExtraArgs.push_back("-fmodule-map-file=" + testPath("module.map"));
+  TU.OverlayRealFileSystemForModules = true;
+
+  TU.build();
+  // We mostly care about not crashing, but verify that we didn't insert 
garbage
+  // about X too.
+  EXPECT_THAT(TU.headerSymbols(), Not(Contains(QName("X";
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang

diff  --git a/clang-tools-extra/clangd/unittests/TestFS.h 
b/clang-tools-extra/clangd/unittests/TestFS.h
index 7972fe37c7fe..82de319d96cf 100644
--- a/clang-tools-extra/clangd/unittests/TestFS.h
+++ b/clang-tools-extra/clangd/unittests/TestFS.h
@@ -34,12 +34,21 @@ buildTestFS(llvm::StringMap const ,
 class MockFS : public ThreadsafeFS {
 public:
   IntrusiveRefCntPtr viewImpl() const override {
-return buildTestFS(Files, Timestamps);
+auto MemFS = buildTestFS(Files, Timestamps);
+if (!OverlayRealFileSystemForModules)
+  return MemFS;
+llvm::IntrusiveRefCntPtr OverlayFileSystem =
+new llvm::vfs::OverlayFileSystem(llvm::vfs::getRealFileSystem());
+OverlayFileSystem->pushOverlay(MemFS);
+return OverlayFileSystem;
   }
 
   // If relative paths are used, they are resolved with testPath().
   llvm::StringMap Files;
   llvm::StringMap Timestamps;
+  // If true, real file system will be used as fallback for the in-memory one.
+  // This is useful for testing module support.
+  bool OverlayRealFileSystemForModules = false;
 };
 
 // A Compilation database that returns a fixed set of compile flags.

diff  --git a/clang-tools-extra/clangd/unittests/TestTU.cpp 
b/clang-tools-extra/clangd/unittests/TestTU.cpp
index 7d5c29f23393..c468642e6338 100644
--- a/clang-tools-extra/clangd/unittests/TestTU.cpp
+++ b/clang-tools-extra/clangd/unittests/TestTU.cpp
@@ -16,6 +16,7 @@
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Frontend/CompilerInvocation.h"
 #include "clang/Frontend/Utils.h"
+#include "llvm/ADT/ScopeExit.h"
 
 namespace clang {
 namespace clangd {
@@ -54,6 +55,8 @@ ParseInputs TestTU::inputs(MockFS ) const {
   Inputs.CompileCommand.Filename = FullFilename;
   Inputs.CompileCommand.Directory = testRoot();
   Inputs.Contents = Code;
+  if (OverlayRealFileSystemForModules)
+FS.OverlayRealFileSystemForModules = true;
   Inputs.TFS = 
   Inputs.Opts = ParseOptions();
   Inputs.Opts.BuildRecoveryAST = true;
@@ -66,12 +69,31 @@ ParseInputs TestTU::inputs(MockFS ) const {
   return Inputs;
 }
 

[PATCH] D86069: [clang] When loading preamble from AST file, re-export modules in Sema.

2020-08-20 Thread Adam Czachorowski 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 rGbaeff989b050: [clang] When loading preamble from AST file, 
re-export modules in Sema. (authored by adamcz).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86069

Files:
  clang-tools-extra/clangd/unittests/ModulesTests.cpp
  clang/include/clang/Sema/Sema.h
  clang/lib/Serialization/ASTReader.cpp
  clang/test/PCH/Inputs/modules/Foo.h
  clang/test/PCH/preamble-modules.cpp

Index: clang/test/PCH/preamble-modules.cpp
===
--- /dev/null
+++ clang/test/PCH/preamble-modules.cpp
@@ -0,0 +1,15 @@
+// Check that modules included in the preamble remain visible to the rest of the
+// file.
+
+// RUN: rm -rf %t.mcp
+// RUN: %clang_cc1 -emit-pch -o %t.pch %s -fmodules -fmodule-map-file=%S/Inputs/modules/module.modulemap -fmodules-local-submodule-visibility -fmodules-cache-path=%t.mcp
+// RUN: %clang_cc1 -include-pch %t.pch %s -fmodules -fmodule-map-file=%S/Inputs/modules/module.modulemap -fmodules-local-submodule-visibility -fmodules-cache-path=%t.mcp
+
+#ifndef MAIN_FILE
+#define MAIN_FILE
+// Premable section.
+#include "Inputs/modules/Foo.h"
+#else
+// Main section.
+MyType foo;
+#endif
Index: clang/test/PCH/Inputs/modules/Foo.h
===
--- clang/test/PCH/Inputs/modules/Foo.h
+++ clang/test/PCH/Inputs/modules/Foo.h
@@ -1 +1,3 @@
 void make_foo(void);
+
+typedef int MyType;
Index: clang/lib/Serialization/ASTReader.cpp
===
--- clang/lib/Serialization/ASTReader.cpp
+++ clang/lib/Serialization/ASTReader.cpp
@@ -4987,10 +4987,10 @@
 /*ImportLoc=*/Import.ImportLoc);
   if (Import.ImportLoc.isValid())
 PP.makeModuleVisible(Imported, Import.ImportLoc);
-  // FIXME: should we tell Sema to make the module visible too?
+  // This updates visibility for Preprocessor only. For Sema, which can be
+  // nullptr here, we do the same later, in UpdateSema().
 }
   }
-  ImportedModules.clear();
 }
 
 void ASTReader::finalizeForWriting() {
@@ -7943,6 +7943,15 @@
   SemaObj->FpPragmaStack.CurrentPragmaLocation = FpPragmaCurrentLocation;
 }
   }
+
+  // For non-modular AST files, restore visiblity of modules.
+  for (auto  : ImportedModules) {
+if (Import.ImportLoc.isInvalid())
+  continue;
+if (Module *Imported = getSubmodule(Import.ID)) {
+  SemaObj->makeModuleVisible(Imported, Import.ImportLoc);
+}
+  }
 }
 
 IdentifierInfo *ASTReader::get(StringRef Name) {
Index: clang/include/clang/Sema/Sema.h
===
--- clang/include/clang/Sema/Sema.h
+++ clang/include/clang/Sema/Sema.h
@@ -1912,6 +1912,12 @@
 
   bool isModuleVisible(const Module *M, bool ModulePrivate = false);
 
+  // When loading a non-modular PCH files, this is used to restore module
+  // visibility.
+  void makeModuleVisible(Module *Mod, SourceLocation ImportLoc) {
+VisibleModules.setVisible(Mod, ImportLoc);
+  }
+
   /// Determine whether a declaration is visible to name lookup.
   bool isVisible(const NamedDecl *D) {
 return D->isUnconditionallyVisible() || isVisibleSlow(D);
Index: clang-tools-extra/clangd/unittests/ModulesTests.cpp
===
--- clang-tools-extra/clangd/unittests/ModulesTests.cpp
+++ clang-tools-extra/clangd/unittests/ModulesTests.cpp
@@ -26,7 +26,7 @@
 void foo() {}
 )cpp");
   TU.ExtraArgs.push_back("-fmodule-name=M");
-  TU.ExtraArgs.push_back("-fmodule-map-file=m.modulemap");
+  TU.ExtraArgs.push_back("-fmodule-map-file=" + testPath("m.modulemap"));
   TU.AdditionalFiles["Textual.h"] = "void foo();";
   TU.AdditionalFiles["m.modulemap"] = R"modulemap(
 module M {
@@ -39,6 +39,31 @@
   TU.index();
 }
 
+// Verify that visibility of AST nodes belonging to modules, but loaded from
+// preamble PCH, is restored.
+TEST(Modules, PreambleBuildVisibility) {
+  TestTU TU = TestTU::withCode(R"cpp(
+#include "module.h"
+
+foo x;
+)cpp");
+  TU.OverlayRealFileSystemForModules = true;
+  TU.ExtraArgs.push_back("-fmodules");
+  TU.ExtraArgs.push_back("-fmodules-strict-decluse");
+  TU.ExtraArgs.push_back("-Xclang");
+  TU.ExtraArgs.push_back("-fmodules-local-submodule-visibility");
+  TU.ExtraArgs.push_back("-fmodule-map-file=" + testPath("m.modulemap"));
+  TU.AdditionalFiles["module.h"] = R"cpp(
+typedef int foo;
+)cpp";
+  TU.AdditionalFiles["m.modulemap"] = R"modulemap(
+module M {
+  header "module.h"
+}
+)modulemap";
+  EXPECT_TRUE(TU.build().getDiagnostics().empty());
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
___
cfe-commits mailing list

[PATCH] D85923: [clangd] Fix crash-bug in preamble indexing when using modules.

2020-08-20 Thread Adam Czachorowski via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rG53b9199a5cdb: [clangd] Fix crash-bug in preamble indexing 
when using modules. (authored by adamcz).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85923

Files:
  clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
  clang-tools-extra/clangd/unittests/TestFS.h
  clang-tools-extra/clangd/unittests/TestTU.cpp
  clang-tools-extra/clangd/unittests/TestTU.h
  clang/lib/Index/IndexingAction.cpp

Index: clang/lib/Index/IndexingAction.cpp
===
--- clang/lib/Index/IndexingAction.cpp
+++ clang/lib/Index/IndexingAction.cpp
@@ -165,11 +165,20 @@
 static void indexPreprocessorMacros(const Preprocessor ,
 IndexDataConsumer ) {
   for (const auto  : PP.macros())
-if (MacroDirective *MD = M.second.getLatest())
+if (MacroDirective *MD = M.second.getLatest()) {
+  auto *MI = MD->getMacroInfo();
+  // When using modules, it may happen that we find #undef of a macro that
+  // was defined in another module. In such case, MI may be nullptr, since
+  // we only look for macro definitions in the current TU. In that case,
+  // there is nothing to index.
+  if (!MI)
+continue;
+
   DataConsumer.handleMacroOccurrence(
   M.first, MD->getMacroInfo(),
   static_cast(index::SymbolRole::Definition),
   MD->getLocation());
+}
 }
 
 void index::indexASTUnit(ASTUnit , IndexDataConsumer ,
Index: clang-tools-extra/clangd/unittests/TestTU.h
===
--- clang-tools-extra/clangd/unittests/TestTU.h
+++ clang-tools-extra/clangd/unittests/TestTU.h
@@ -66,6 +66,16 @@
   // Simulate a header guard of the header (using an #import directive).
   bool ImplicitHeaderGuard = true;
 
+  // Whether to use overlay the TestFS over the real filesystem. This is
+  // required for use of implicit modules.where the module file is written to
+  // disk and later read back.
+  // FIXME: Change the way reading/writing modules work to allow us to keep them
+  // in memory across multiple clang invocations, at least in tests, to
+  // eliminate the need for real file system here.
+  // Please avoid using this for things other than implicit modules. The plan is
+  // to eliminate this option some day.
+  bool OverlayRealFileSystemForModules = false;
+
   // By default, build() will report Error diagnostics as GTest errors.
   // Suppress this behavior by adding an 'error-ok' comment to the code.
   ParsedAST build() const;
Index: clang-tools-extra/clangd/unittests/TestTU.cpp
===
--- clang-tools-extra/clangd/unittests/TestTU.cpp
+++ clang-tools-extra/clangd/unittests/TestTU.cpp
@@ -16,6 +16,7 @@
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Frontend/CompilerInvocation.h"
 #include "clang/Frontend/Utils.h"
+#include "llvm/ADT/ScopeExit.h"
 
 namespace clang {
 namespace clangd {
@@ -54,6 +55,8 @@
   Inputs.CompileCommand.Filename = FullFilename;
   Inputs.CompileCommand.Directory = testRoot();
   Inputs.Contents = Code;
+  if (OverlayRealFileSystemForModules)
+FS.OverlayRealFileSystemForModules = true;
   Inputs.TFS = 
   Inputs.Opts = ParseOptions();
   Inputs.Opts.BuildRecoveryAST = true;
@@ -66,12 +69,31 @@
   return Inputs;
 }
 
+void initializeModuleCache(CompilerInvocation ) {
+  llvm::SmallString<128> ModuleCachePath;
+  ASSERT_FALSE(
+  llvm::sys::fs::createUniqueDirectory("module-cache", ModuleCachePath));
+  CI.getHeaderSearchOpts().ModuleCachePath = ModuleCachePath.c_str();
+  llvm::errs() << "MC: " << ModuleCachePath << "\n";
+  llvm::errs().flush();
+}
+
+void deleteModuleCache(const std::string ModuleCachePath) {
+  if (!ModuleCachePath.empty()) {
+ASSERT_FALSE(llvm::sys::fs::remove_directories(ModuleCachePath));
+  }
+}
+
 std::shared_ptr TestTU::preamble() const {
   MockFS FS;
   auto Inputs = inputs(FS);
   IgnoreDiagnostics Diags;
   auto CI = buildCompilerInvocation(Inputs, Diags);
   assert(CI && "Failed to build compilation invocation.");
+  if (OverlayRealFileSystemForModules)
+initializeModuleCache(*CI);
+  auto ModuleCacheDeleter = llvm::make_scope_exit(
+  std::bind(deleteModuleCache, CI->getHeaderSearchOpts().ModuleCachePath));
   return clang::clangd::buildPreamble(testPath(Filename), *CI, Inputs,
   /*StoreInMemory=*/true,
   /*PreambleCallback=*/nullptr);
@@ -83,6 +105,11 @@
   StoreDiags Diags;
   auto CI = buildCompilerInvocation(Inputs, Diags);
   assert(CI && "Failed to build compilation invocation.");
+  if (OverlayRealFileSystemForModules)
+initializeModuleCache(*CI);
+  auto 

[clang-tools-extra] baeff98 - [clang] When loading preamble from AST file, re-export modules in Sema.

2020-08-20 Thread Adam Czachorowski via cfe-commits

Author: Adam Czachorowski
Date: 2020-08-20T14:19:52+02:00
New Revision: baeff989b050e0f63412c52c1b8f9d8f3e91f671

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

LOG: [clang] When loading preamble from AST file, re-export modules in Sema.

This addresses a FIXME in ASTReader.

Modules were already re-exported for Preprocessor, but not for Sema.
The result was that, with -fmodules-local-submodule-visibility, all AST
nodes belonging to a module that was loaded in a premable where not
accesible from the main part of the file and a diagnostic recommending
importing those modules would be generated.

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

Added: 
clang/test/PCH/preamble-modules.cpp

Modified: 
clang-tools-extra/clangd/unittests/ModulesTests.cpp
clang/include/clang/Sema/Sema.h
clang/lib/Serialization/ASTReader.cpp
clang/test/PCH/Inputs/modules/Foo.h

Removed: 




diff  --git a/clang-tools-extra/clangd/unittests/ModulesTests.cpp 
b/clang-tools-extra/clangd/unittests/ModulesTests.cpp
index 0098a15f64bb..a10b9e897a48 100644
--- a/clang-tools-extra/clangd/unittests/ModulesTests.cpp
+++ b/clang-tools-extra/clangd/unittests/ModulesTests.cpp
@@ -26,7 +26,7 @@ TEST(Modules, TextualIncludeInPreamble) {
 void foo() {}
 )cpp");
   TU.ExtraArgs.push_back("-fmodule-name=M");
-  TU.ExtraArgs.push_back("-fmodule-map-file=m.modulemap");
+  TU.ExtraArgs.push_back("-fmodule-map-file=" + testPath("m.modulemap"));
   TU.AdditionalFiles["Textual.h"] = "void foo();";
   TU.AdditionalFiles["m.modulemap"] = R"modulemap(
 module M {
@@ -39,6 +39,31 @@ TEST(Modules, TextualIncludeInPreamble) {
   TU.index();
 }
 
+// Verify that visibility of AST nodes belonging to modules, but loaded from
+// preamble PCH, is restored.
+TEST(Modules, PreambleBuildVisibility) {
+  TestTU TU = TestTU::withCode(R"cpp(
+#include "module.h"
+
+foo x;
+)cpp");
+  TU.OverlayRealFileSystemForModules = true;
+  TU.ExtraArgs.push_back("-fmodules");
+  TU.ExtraArgs.push_back("-fmodules-strict-decluse");
+  TU.ExtraArgs.push_back("-Xclang");
+  TU.ExtraArgs.push_back("-fmodules-local-submodule-visibility");
+  TU.ExtraArgs.push_back("-fmodule-map-file=" + testPath("m.modulemap"));
+  TU.AdditionalFiles["module.h"] = R"cpp(
+typedef int foo;
+)cpp";
+  TU.AdditionalFiles["m.modulemap"] = R"modulemap(
+module M {
+  header "module.h"
+}
+)modulemap";
+  EXPECT_TRUE(TU.build().getDiagnostics().empty());
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 49ab94f9df14..84e66b85208e 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -1912,6 +1912,12 @@ class Sema final {
 
   bool isModuleVisible(const Module *M, bool ModulePrivate = false);
 
+  // When loading a non-modular PCH files, this is used to restore module
+  // visibility.
+  void makeModuleVisible(Module *Mod, SourceLocation ImportLoc) {
+VisibleModules.setVisible(Mod, ImportLoc);
+  }
+
   /// Determine whether a declaration is visible to name lookup.
   bool isVisible(const NamedDecl *D) {
 return D->isUnconditionallyVisible() || isVisibleSlow(D);

diff  --git a/clang/lib/Serialization/ASTReader.cpp 
b/clang/lib/Serialization/ASTReader.cpp
index 21cdde9e8455..464bbc662230 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -4987,10 +4987,10 @@ void ASTReader::InitializeContext() {
 /*ImportLoc=*/Import.ImportLoc);
   if (Import.ImportLoc.isValid())
 PP.makeModuleVisible(Imported, Import.ImportLoc);
-  // FIXME: should we tell Sema to make the module visible too?
+  // This updates visibility for Preprocessor only. For Sema, which can be
+  // nullptr here, we do the same later, in UpdateSema().
 }
   }
-  ImportedModules.clear();
 }
 
 void ASTReader::finalizeForWriting() {
@@ -7943,6 +7943,15 @@ void ASTReader::UpdateSema() {
   SemaObj->FpPragmaStack.CurrentPragmaLocation = FpPragmaCurrentLocation;
 }
   }
+
+  // For non-modular AST files, restore visiblity of modules.
+  for (auto  : ImportedModules) {
+if (Import.ImportLoc.isInvalid())
+  continue;
+if (Module *Imported = getSubmodule(Import.ID)) {
+  SemaObj->makeModuleVisible(Imported, Import.ImportLoc);
+}
+  }
 }
 
 IdentifierInfo *ASTReader::get(StringRef Name) {

diff  --git a/clang/test/PCH/Inputs/modules/Foo.h 
b/clang/test/PCH/Inputs/modules/Foo.h
index d661dbccbc33..c93614e0683f 100644
--- a/clang/test/PCH/Inputs/modules/Foo.h
+++ b/clang/test/PCH/Inputs/modules/Foo.h
@@ -1 +1,3 @@
 void make_foo(void);
+
+typedef int MyType;

diff  --git a/clang/test/PCH/preamble-modules.cpp 

[PATCH] D86279: [clangd] Don't crash on `#pragma clang __debug parser_crash`

2020-08-20 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet accepted this revision.
kadircet added a comment.
This revision is now accepted and ready to land.

thanks, lgtm!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86279

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


[PATCH] D86209: [clang-tidy] run-clang-tidy.py: Fix -allow-enabling-analyzer-alpha-checkers always being passed

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

LGTM! Do you need someone to commit on your behalf? If so, please be sure 
you're fine with the license agreement and let us know what name and email 
address you would like associated with the commit. Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86209

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


[PATCH] D86176: [clang-tidy] readability-simplify-boolean-expr detects negated literals

2020-08-20 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: 
clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp:66
+  if (const auto *Negated = Result.Nodes.getNodeAs(Id)) {
+if (Negated->getOpcode() == UO_LNot &&
+isa(Negated->getSubExpr()))

I'd like to see this handled recursively instead so that we properly handle 
more esoteric logic (but it still shows up from time to time) like `!!foo`: 
https://codesearch.isocpp.org/cgi-bin/cgi_ppsearch?q=%21%21=Search

This is a case where I don't think the simplification should happen -- e.g., 
the code is usually subtly incorrect when converted to remove the `!!`. It's 
less clear to me whether the same is true for something like `!!!` being 
converted to `!`, but that's not a case I'm really worried about either.



Comment at: 
clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp:74
+internal::BindableMatcher literalOrNegatedBool(bool Value) {
+  return expr(anyOf(cxxBoolLiteral(equals(Value)),
+unaryOperator(hasUnaryOperand(ignoringParenImpCasts(

Oof, but handling it here may be tricky...



Comment at: 
clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp:289
   }
+  if (const auto *Unary = dyn_cast(Ret->getRetValue())) {
+if (Unary->getOpcode() == UO_LNot) {

Same here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86176

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


[PATCH] D83174: Teach AttachPreviousImpl to inherit MSInheritanceAttr attribute

2020-08-20 Thread Vaibhav Garg via Phabricator via cfe-commits
gargvaibhav64 updated this revision to Diff 286786.
gargvaibhav64 added a comment.

The test is now working properly.


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

https://reviews.llvm.org/D83174

Files:
  clang/lib/Serialization/ASTReaderDecl.cpp
  clang/test/Modules/Inputs/inherit-attribute/a.h
  clang/test/Modules/Inputs/inherit-attribute/b.h
  clang/test/Modules/Inputs/inherit-attribute/c.h
  clang/test/Modules/Inputs/inherit-attribute/module.modulemap
  clang/test/Modules/inherit-attribute.cpp

Index: clang/test/Modules/inherit-attribute.cpp
===
--- /dev/null
+++ clang/test/Modules/inherit-attribute.cpp
@@ -0,0 +1,22 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fmodules -triple x86_64-pc-windows-msvc-unknown -I%S\Inputs\inherit-attribute -fmodules-cache-path=%t \
+// RUN: -fimplicit-module-maps -fmodules-local-submodule-visibility -verify %s -ast-dump-all \
+// RUN: | FileCheck %s
+
+#include "b.h"
+#include "c.h"
+
+class Foo;
+
+Foo f;
+
+// CHECK:   CXXRecordDecl{{.*}}prev{{.*}}Foo
+// CHECK:   {{.*}}`-MSInheritanceAttr{{[^()]*$}}
+
+// CHECK:   CXXRecordDecl{{.*}}prev{{.*}}Foo
+// CHECK:   {{.*}}-MSInheritanceAttr{{[^()]*$}}
+
+// CHECK:   CXXRecordDecl{{.*}}prev{{.*}}Foo
+// CHECK:   {{.*}}`-MSInheritanceAttr{{[^()]*$}}
+
+// expected-no-diagnostics
Index: clang/test/Modules/Inputs/inherit-attribute/module.modulemap
===
--- /dev/null
+++ clang/test/Modules/Inputs/inherit-attribute/module.modulemap
@@ -0,0 +1,3 @@
+module "b" { header "b.h" }
+
+module "c" { header "c.h" }
Index: clang/test/Modules/Inputs/inherit-attribute/c.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/inherit-attribute/c.h
@@ -0,0 +1 @@
+#include "a.h"
Index: clang/test/Modules/Inputs/inherit-attribute/b.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/inherit-attribute/b.h
@@ -0,0 +1,7 @@
+#include "a.h"
+
+class Foo;
+
+void bar() {
+  ::step;
+}
Index: clang/test/Modules/Inputs/inherit-attribute/a.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/inherit-attribute/a.h
@@ -0,0 +1,10 @@
+#ifndef FOO
+#define FOO
+
+class Foo {
+public:
+  void step(int v);
+  Foo();
+};
+
+#endif
Index: clang/lib/Serialization/ASTReaderDecl.cpp
===
--- clang/lib/Serialization/ASTReaderDecl.cpp
+++ clang/lib/Serialization/ASTReaderDecl.cpp
@@ -281,6 +281,9 @@
 static Decl *getMostRecentDeclImpl(...);
 static Decl *getMostRecentDecl(Decl *D);
 
+static void mergeInheritableAttributes(ASTReader , Decl *D,
+   Decl *Previous);
+
 template 
 static void attachPreviousDeclImpl(ASTReader ,
Redeclarable *D, Decl *Previous,
@@ -3531,6 +3534,19 @@
   return ASTDeclReader::getMostRecentDecl(D->getCanonicalDecl());
 }
 
+void ASTDeclReader::mergeInheritableAttributes(ASTReader , Decl *D,
+   Decl *Previous) {
+  InheritableAttr *NewAttr = nullptr;
+  ASTContext  = Reader.getContext();
+  const auto *IA = Previous->getAttr();
+
+  if (IA && !D->hasAttr()) {
+NewAttr = cast(IA->clone(Context));
+NewAttr->setInherited(true);
+D->addAttr(NewAttr);
+  }
+}
+
 template
 void ASTDeclReader::attachPreviousDeclImpl(ASTReader ,
Redeclarable *D,
@@ -3689,6 +3705,12 @@
   if (auto *TD = dyn_cast(D))
 inheritDefaultTemplateArguments(Reader.getContext(),
 cast(Previous), TD);
+
+  // If any of the declaration in the chain contains an Inheritable attribute,
+  // it needs to be added to all the declarations in the redeclarable chain.
+  // FIXME: Only the logic of merging MSInheritableAttr is present, it should
+  // be extended for all inheritable attributes.
+  mergeInheritableAttributes(Reader, D, Previous);
 }
 
 template
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


  1   2   >