[PATCH] D73441: [clang-tidy] Fix bugprone-use-after-move when move is in noexcept operator

2020-01-26 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr2 added inline comments.



Comment at: clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp:387
+   unless(inDecltypeOrTemplateArg()),
+   unless(hasAncestor(cxxNoexceptExpr(
   .bind("call-move");

Quuxplusone wrote:
> What about `sizeof`, `alignof`, `requires`, `typeid`, and other such 
> unevaluated contexts? Shouldn't there be a common way to spell "this 
> expression is unevaluated"? (I don't know if there is or not.)
+1 to adding handling and tests for other unevaluated contexts.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/bugprone-use-after-move.cpp:1276
+namespace PR44667 {
+#define REQUIRE(expr) (void)(expr);
+struct S {};

Is the macro a necessary part of this test? If not, can it be removed?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73441



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


[PATCH] D72508: [clangd] Support pseudo-obj expr, opaque values, and property references in findExplicitReferences()

2020-01-26 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added inline comments.



Comment at: clang-tools-extra/clangd/FindTarget.cpp:794
+// Not clear why the source expression is skipped by default...
+return RecursiveASTVisitor::TraverseStmt(OVE->getSourceExpr());
+  }

Should this be done by `RecursiveASTVisitor` instead (when 
`shouldVisitImplicitCode()` is false)?

If yes, maybe add a FIXME to this patch and try fixing in `RAV` in a follow-up?



Comment at: clang-tools-extra/clangd/unittests/FindTargetTests.cpp:700
$2^Typedef $3^y;
-   static_cast<$4^Struct*>(0);
+   (void) static_cast<$4^Struct*>(0);
  }

Why is this necessary? Making tests more complicated to avoid warnings does not 
look right. 



Comment at: clang-tools-extra/clangd/unittests/FindTargetTests.cpp:711
  namespace a { namespace b { struct S { typedef int type; }; } }
- void foo() {
+ int foo() {
$0^a::$1^b::$2^S $3^x;

See the comment about making tests more complicated to avoid warnings. Same 
question here and in other instances.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72508



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


[PATCH] D69868: Allow "callbr" to return non-void values

2020-01-26 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

It seems that callbr (with output) will now be similar to a catchpad. It can 
set live-in physical register information. (See 
`test/CodeGen/X86/{seh-catch-all.ll,seh-exception-code.ll,wineh-coreclr.ll,wineh-exceptionpointer.ll}`)
 Is there any caveat doing this? Add @rnk to the attention list as the author 
of rL249492  and rL249786 
...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69868



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


[PATCH] D72820: [FPEnv] Add pragma FP_CONTRACT support under strict FP.

2020-01-26 Thread Pengfei Wang via Phabricator via cfe-commits
pengfei marked an inline comment as done.
pengfei added inline comments.



Comment at: clang/lib/CodeGen/CGExprScalar.cpp:3381
+   "constrained mode");
+FMulAdd = Builder.CreateCall(
+CGF.CGM.getIntrinsic(llvm::Intrinsic::experimental_constrained_fmuladd,

kpn wrote:
> craig.topper wrote:
> > kpn wrote:
> > > craig.topper wrote:
> > > > Doesn't this need to be CreateConstrainedFPCall so that the strictfp 
> > > > attribute is added? That will take care of adding the metadata operands 
> > > > too.
> > > Is this code tested? I ran into a bug yesterday where CreateCall was used 
> > > with a constrained intrinsic and the Instruction class blew up because 
> > > the function signature was wrong. I wasn't passing in the metadata 
> > > arguments.
> > > 
> > > So, yes, it should be, and it would might make sense for the patch to 
> > > have test coverage that catches any other cases of this.
> > This code is copying the metadata arguments from the fmul intrinsic, MulOp. 
> > that’s the getOperand(2) and getOperand(3).
> Ah, yes, thanks. Your comment about the attribute is still valid, though. 
> And, yes, using CreateConstrainedFPCall() is the easiest way to fix the 
> attribute.
Yes, it's the best choice. Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72820



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


[PATCH] D72820: [FPEnv] Add pragma FP_CONTRACT support under strict FP.

2020-01-26 Thread Pengfei Wang via Phabricator via cfe-commits
pengfei updated this revision to Diff 240474.
pengfei added a comment.

Address review comment.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72820

Files:
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/test/CodeGen/constrained-math-builtins.c
  llvm/docs/LangRef.rst
  llvm/include/llvm/CodeGen/BasicTTIImpl.h
  llvm/include/llvm/IR/ConstrainedOps.def
  llvm/include/llvm/IR/Intrinsics.td
  llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
  llvm/test/CodeGen/X86/fp-intrinsics-fma.ll
  llvm/test/TableGen/GlobalISelEmitter-input-discard.td

Index: llvm/test/TableGen/GlobalISelEmitter-input-discard.td
===
--- llvm/test/TableGen/GlobalISelEmitter-input-discard.td
+++ llvm/test/TableGen/GlobalISelEmitter-input-discard.td
@@ -15,7 +15,7 @@
 // GISEL-NEXT: GIM_CheckType, /*MI*/0, /*Op*/2, /*Type*/GILLT_s32,
 // GISEL-NEXT: GIM_CheckType, /*MI*/0, /*Op*/3, /*Type*/GILLT_s32,
 // GISEL-NEXT: GIM_CheckRegBankForClass, /*MI*/0, /*Op*/0, /*RC*/MyTarget::GPR32RegClassID,
-// GISEL-NEXT: // (intrinsic_w_chain:{ *:[i32] } 248:{ *:[iPTR] }, srcvalue:{ *:[i32] }, i32:{ *:[i32] }:$src1)  =>  (FOO:{ *:[i32] } (IMPLICIT_DEF:{ *:[i32] }), GPR32:{ *:[i32] }:$src1)
+// GISEL-NEXT: // (intrinsic_w_chain:{ *:[i32] } 249:{ *:[iPTR] }, srcvalue:{ *:[i32] }, i32:{ *:[i32] }:$src1)  =>  (FOO:{ *:[i32] } (IMPLICIT_DEF:{ *:[i32] }), GPR32:{ *:[i32] }:$src1)
 // GISEL-NEXT: GIR_MakeTempReg, /*TempRegID*/0, /*TypeID*/GILLT_s32,
 // GISEL-NEXT: GIR_BuildMI, /*InsnID*/1, /*Opcode*/TargetOpcode::IMPLICIT_DEF,
 // GISEL-NEXT: GIR_AddTempRegister, /*InsnID*/1, /*TempRegID*/0, /*TempRegFlags*/RegState::Define,
Index: llvm/test/CodeGen/X86/fp-intrinsics-fma.ll
===
--- llvm/test/CodeGen/X86/fp-intrinsics-fma.ll
+++ llvm/test/CodeGen/X86/fp-intrinsics-fma.ll
@@ -3,6 +3,104 @@
 ; RUN: llc -O3 -mtriple=x86_64-pc-linux -mattr=+fma < %s | FileCheck %s --check-prefixes=COMMON,FMA
 ; RUN: llc -O3 -mtriple=x86_64-pc-linux -mattr=+avx512f < %s | FileCheck %s --check-prefixes=COMMON,FMA
 
+; Verify constrained fmul and fadd aren't fused.
+define float @f11(float %0, float %1, float %2) #0 {
+; NOFMA-LABEL: f11:
+; NOFMA:   # %bb.0: # %entry
+; NOFMA-NEXT:mulss %xmm1, %xmm0
+; NOFMA-NEXT:addss %xmm2, %xmm0
+; NOFMA-NEXT:retq
+;
+; FMA-LABEL: f11:
+; FMA:   # %bb.0: # %entry
+; FMA-NEXT:vmulss %xmm1, %xmm0, %xmm0
+; FMA-NEXT:vaddss %xmm2, %xmm0, %xmm0
+; FMA-NEXT:retq
+entry:
+  %3 = call float @llvm.experimental.constrained.fmul.f32(float %0, float %1,
+  metadata !"round.dynamic",
+  metadata !"fpexcept.strict") #0
+  %4 = call float @llvm.experimental.constrained.fadd.f32(float %3, float %2,
+  metadata !"round.dynamic",
+  metadata !"fpexcept.strict") #0
+  ret float %4
+}
+
+; Verify constrained fmul and fadd aren't fused.
+define double @f12(double %0, double %1, double %2) #0 {
+; NOFMA-LABEL: f12:
+; NOFMA:   # %bb.0: # %entry
+; NOFMA-NEXT:mulsd %xmm1, %xmm0
+; NOFMA-NEXT:addsd %xmm2, %xmm0
+; NOFMA-NEXT:retq
+;
+; FMA-LABEL: f12:
+; FMA:   # %bb.0: # %entry
+; FMA-NEXT:vmulsd %xmm1, %xmm0, %xmm0
+; FMA-NEXT:vaddsd %xmm2, %xmm0, %xmm0
+; FMA-NEXT:retq
+entry:
+  %3 = call double @llvm.experimental.constrained.fmul.f64(double %0, double %1,
+   metadata !"round.dynamic",
+   metadata !"fpexcept.strict") #0
+  %4 = call double @llvm.experimental.constrained.fadd.f64(double %3, double %2,
+   metadata !"round.dynamic",
+   metadata !"fpexcept.strict") #0
+  ret double %4
+}
+
+; Verify that fmuladd(3.5) isn't simplified when the rounding mode is
+; unknown.
+define float @f15() #0 {
+; NOFMA-LABEL: f15:
+; NOFMA:   # %bb.0: # %entry
+; NOFMA-NEXT:movss {{.*#+}} xmm1 = mem[0],zero,zero,zero
+; NOFMA-NEXT:movaps %xmm1, %xmm0
+; NOFMA-NEXT:mulss %xmm1, %xmm0
+; NOFMA-NEXT:addss %xmm1, %xmm0
+; NOFMA-NEXT:retq
+;
+; FMA-LABEL: f15:
+; FMA:   # %bb.0: # %entry
+; FMA-NEXT:vmovss {{.*#+}} xmm0 = mem[0],zero,zero,zero
+; FMA-NEXT:vfmadd213ss {{.*#+}} xmm0 = (xmm0 * xmm0) + xmm0
+; FMA-NEXT:retq
+entry:
+  %result = call float @llvm.experimental.constrained.fmuladd.f32(
+   float 3.5,
+   float 3.5,
+   float 3.5,
+   metadata !"round

[PATCH] D72824: [X86] Add combination for fma and fneg on X86 under strict FP.

2020-01-26 Thread Pengfei Wang via Phabricator via cfe-commits
pengfei updated this revision to Diff 240472.
pengfei added a comment.

Rebase and add vector instructions test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72824

Files:
  llvm/lib/Target/X86/X86ISelLowering.cpp
  llvm/lib/Target/X86/X86ISelLowering.h
  llvm/lib/Target/X86/X86InstrAVX512.td
  llvm/lib/Target/X86/X86InstrFMA.td
  llvm/lib/Target/X86/X86InstrFragmentsSIMD.td
  llvm/test/CodeGen/X86/fp-intrinsics-fma.ll

Index: llvm/test/CodeGen/X86/fp-intrinsics-fma.ll
===
--- llvm/test/CodeGen/X86/fp-intrinsics-fma.ll
+++ llvm/test/CodeGen/X86/fp-intrinsics-fma.ll
@@ -1,7 +1,326 @@
 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
 ; RUN: llc -O3 -mtriple=x86_64-pc-linux < %s | FileCheck %s --check-prefixes=COMMON,NOFMA
-; RUN: llc -O3 -mtriple=x86_64-pc-linux -mattr=+fma < %s | FileCheck %s --check-prefixes=COMMON,FMA
-; RUN: llc -O3 -mtriple=x86_64-pc-linux -mattr=+avx512f < %s | FileCheck %s --check-prefixes=COMMON,FMA
+; RUN: llc -O3 -mtriple=x86_64-pc-linux -mattr=+fma < %s | FileCheck %s --check-prefixes=COMMON,FMA,FMA-AVX1
+; RUN: llc -O3 -mtriple=x86_64-pc-linux -mattr=+fma4 < %s | FileCheck %s --check-prefixes=COMMON,FMA4
+; RUN: llc -O3 -mtriple=x86_64-pc-linux -mattr=+avx512f < %s | FileCheck %s --check-prefixes=COMMON,FMA,FMA-AVX512
+
+define float @f1(float %0, float %1, float %2) #0 {
+; NOFMA-LABEL: f1:
+; NOFMA:   # %bb.0: # %entry
+; NOFMA-NEXT:pushq %rax
+; NOFMA-NEXT:.cfi_def_cfa_offset 16
+; NOFMA-NEXT:xorps {{.*}}(%rip), %xmm0
+; NOFMA-NEXT:callq fmaf
+; NOFMA-NEXT:popq %rax
+; NOFMA-NEXT:.cfi_def_cfa_offset 8
+; NOFMA-NEXT:retq
+;
+; FMA-LABEL: f1:
+; FMA:   # %bb.0: # %entry
+; FMA-NEXT:vfnmadd213ss {{.*#+}} xmm0 = -(xmm1 * xmm0) + xmm2
+; FMA-NEXT:retq
+;
+; FMA4-LABEL: f1:
+; FMA4:   # %bb.0: # %entry
+; FMA4-NEXT:vfnmaddss %xmm2, %xmm1, %xmm0, %xmm0
+; FMA4-NEXT:retq
+entry:
+  %3 = fneg float %0
+  %result = call float @llvm.experimental.constrained.fma.f32(float %3, float %1, float %2,
+  metadata !"round.dynamic",
+  metadata !"fpexcept.strict") #0
+  ret float %result
+}
+
+define double @f2(double %0, double %1, double %2) #0 {
+; NOFMA-LABEL: f2:
+; NOFMA:   # %bb.0: # %entry
+; NOFMA-NEXT:pushq %rax
+; NOFMA-NEXT:.cfi_def_cfa_offset 16
+; NOFMA-NEXT:xorps {{.*}}(%rip), %xmm0
+; NOFMA-NEXT:callq fma
+; NOFMA-NEXT:popq %rax
+; NOFMA-NEXT:.cfi_def_cfa_offset 8
+; NOFMA-NEXT:retq
+;
+; FMA-LABEL: f2:
+; FMA:   # %bb.0: # %entry
+; FMA-NEXT:vfnmadd213sd {{.*#+}} xmm0 = -(xmm1 * xmm0) + xmm2
+; FMA-NEXT:retq
+;
+; FMA4-LABEL: f2:
+; FMA4:   # %bb.0: # %entry
+; FMA4-NEXT:vfnmaddsd %xmm2, %xmm1, %xmm0, %xmm0
+; FMA4-NEXT:retq
+entry:
+  %3 = fneg double %0
+  %result = call double @llvm.experimental.constrained.fma.f64(double %3, double %1, double %2,
+   metadata !"round.dynamic",
+   metadata !"fpexcept.strict") #0
+  ret double %result
+}
+
+define float @f3(float %0, float %1, float %2) #0 {
+; NOFMA-LABEL: f3:
+; NOFMA:   # %bb.0: # %entry
+; NOFMA-NEXT:pushq %rax
+; NOFMA-NEXT:.cfi_def_cfa_offset 16
+; NOFMA-NEXT:xorps {{.*}}(%rip), %xmm2
+; NOFMA-NEXT:callq fmaf
+; NOFMA-NEXT:popq %rax
+; NOFMA-NEXT:.cfi_def_cfa_offset 8
+; NOFMA-NEXT:retq
+;
+; FMA-LABEL: f3:
+; FMA:   # %bb.0: # %entry
+; FMA-NEXT:vfmsub213ss {{.*#+}} xmm0 = (xmm1 * xmm0) - xmm2
+; FMA-NEXT:retq
+;
+; FMA4-LABEL: f3:
+; FMA4:   # %bb.0: # %entry
+; FMA4-NEXT:vfmsubss %xmm2, %xmm1, %xmm0, %xmm0
+; FMA4-NEXT:retq
+entry:
+  %3 = fneg float %2
+  %result = call float @llvm.experimental.constrained.fma.f32(float %0, float %1, float %3,
+  metadata !"round.dynamic",
+  metadata !"fpexcept.strict") #0
+  ret float %result
+}
+
+define double @f4(double %0, double %1, double %2) #0 {
+; NOFMA-LABEL: f4:
+; NOFMA:   # %bb.0: # %entry
+; NOFMA-NEXT:pushq %rax
+; NOFMA-NEXT:.cfi_def_cfa_offset 16
+; NOFMA-NEXT:xorps {{.*}}(%rip), %xmm2
+; NOFMA-NEXT:callq fma
+; NOFMA-NEXT:popq %rax
+; NOFMA-NEXT:.cfi_def_cfa_offset 8
+; NOFMA-NEXT:retq
+;
+; FMA-LABEL: f4:
+; FMA:   # %bb.0: # %entry
+; FMA-NEXT:vfmsub213sd {{.*#+}} xmm0 = (xmm1 * xmm0) - xmm2
+; FMA-NEXT:retq
+;
+; FMA4-LABEL: f4:
+; FMA4:   # %bb.0: # %entry
+; FMA4-NEXT:vfmsubsd %xmm2, %xmm1, %xmm0, %xmm0
+; FMA4-NEXT:retq
+entry:
+  %3 = fneg double %2
+  %result = call double @llvm.experimental.constrained.f

[clang] 59d6908 - [NFC] Fix typo in Clang docs

2020-01-26 Thread Qiu Chaofan via cfe-commits

Author: Qiu Chaofan
Date: 2020-01-27T11:37:43+08:00
New Revision: 59d690850eebcd0e37f205bde16edbd4f2a54053

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

LOG: [NFC] Fix typo in Clang docs

Added: 


Modified: 
clang/docs/LibASTMatchersReference.html

Removed: 




diff  --git a/clang/docs/LibASTMatchersReference.html 
b/clang/docs/LibASTMatchersReference.html
index 5bb181b04d3a..bc6501c767ef 100644
--- a/clang/docs/LibASTMatchersReference.html
+++ b/clang/docs/LibASTMatchersReference.html
@@ -50,7 +50,7 @@ AST Matcher Reference
 
 
 Within each category the matchers are ordered by node type they match on.
-Note that if a matcher can match multiple node types, it will it will appear
+Note that if a matcher can match multiple node types, it will appear
 multiple times. This means that by searching for Matcher you can
 find all matchers that can be used to match on Stmt nodes.
 



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


[PATCH] D72675: [Clang][Driver] Fix -ffast-math/-ffp-contract interaction

2020-01-26 Thread Warren Ristow via Phabricator via cfe-commits
wristow added a comment.

About:

>> This is a bit of an oddity in our handling.
> 
> Yes it is!
> 
> This is certainly getting more complicated than I had originally expected. I 
> feel there isn't a clear spec on what we want in terms of whether FMA should 
> be enabled "automatically" at (for example) '-O2', and/or whether it should 
> be enabled by -ffast-math. I'm very willing to make whatever change is needed 
> here, to meet whatever spec we all ultimately agree on.
> 
> So I think this patch should be put on hold until we decide on these wider 
> aspects.

Thinking about this a bit more, one thing that I believe there //is// a clear 
spec on, is that when `-ffp-contract=off` is "the last switch related to FMA", 
then FMA ought to be disabled.  So for example, `-ffast-math -ffp-contract=off` 
should result in FMA being disabled, //irrrspective// of how we decide on the 
"wider aspects" of the spec mentioned above.  (FTR, this inability to enable 
FastMath in general, but explicitly disable FMA, was a problem one of our 
customers reported, which is what initially motivated this patch.)

Note that the points about the "oddity" of "-ffp-contract=fast" being implied 
by the two long sets of switches in this comment 
 are unrelated to the change proposed 
here.  That is, that oddity is the current behavior of Clang.

So one approach we could take is to first fix the problem of when 
`-ffp-contract=off` is the "the last switch related to FMA", it isn't disabling 
FMA in some cases.  And then as a followup, address the oddities that have been 
noted here.  If we decide to take this two-step approach, I'm happy to take on 
the followup work (once we decide what the spec should be).


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

https://reviews.llvm.org/D72675



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


[PATCH] D73439: [ASTMatchers] Add cxxNoexceptExpr AST matcher

2020-01-26 Thread pre-merge checks [bot] via Phabricator via cfe-commits
merge_guards_bot added a comment.

{icon check-circle color=green} Unit tests: pass. 62196 tests passed, 0 failed 
and 815 were skipped.

{icon check-circle color=green} clang-tidy: pass.

{icon check-circle color=green} clang-format: pass.

Build artifacts 
: 
diff.json 
,
 clang-tidy.txt 
,
 clang-format.patch 
,
 CMakeCache.txt 
,
 console-log.txt 
,
 test-results.xml 


//Pre-merge checks is in beta. Report issue 
.
 Please join beta  or enable 
it for your project 
.//


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73439



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


[PATCH] D73441: [clang-tidy] Fix bugprone-use-after-move when move is in noexcept operator

2020-01-26 Thread pre-merge checks [bot] via Phabricator via cfe-commits
merge_guards_bot added a comment.

{icon check-circle color=green} Unit tests: pass. 62199 tests passed, 0 failed 
and 815 were skipped.

{icon check-circle color=green} clang-tidy: pass.

{icon check-circle color=green} clang-format: pass.

Build artifacts 
: 
diff.json 
,
 clang-tidy.txt 
,
 clang-format.patch 
,
 CMakeCache.txt 
,
 console-log.txt 
,
 test-results.xml 


//Pre-merge checks is in beta. Report issue 
.
 Please join beta  or enable 
it for your project 
.//


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73441



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


[PATCH] D73441: [clang-tidy] Fix bugprone-use-after-move when move is in noexcept operator

2020-01-26 Thread Arthur O'Dwyer via Phabricator via cfe-commits
Quuxplusone added inline comments.



Comment at: clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp:387
+   unless(inDecltypeOrTemplateArg()),
+   unless(hasAncestor(cxxNoexceptExpr(
   .bind("call-move");

What about `sizeof`, `alignof`, `requires`, `typeid`, and other such 
unevaluated contexts? Shouldn't there be a common way to spell "this expression 
is unevaluated"? (I don't know if there is or not.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73441



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


[PATCH] D73439: [ASTMatchers] Add cxxNoexceptExpr AST matcher

2020-01-26 Thread Nathan James via Phabricator via cfe-commits
njames93 updated this revision to Diff 240461.
njames93 added a comment.

- Fix typo in documentation


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73439

Files:
  clang/docs/LibASTMatchersReference.html
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/lib/ASTMatchers/ASTMatchersInternal.cpp
  clang/lib/ASTMatchers/Dynamic/Registry.cpp
  clang/lib/Analysis/ExprMutationAnalyzer.cpp
  clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp

Index: clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -679,6 +679,14 @@
   cxxDeleteExpr()));
 }
 
+TEST(Matcher, NoexceptExpression) {
+  StatementMatcher NoExcept = cxxNoexceptExpr();
+  EXPECT_TRUE(matches("void foo(); bool bar = noexcept(foo());", NoExcept));
+  EXPECT_TRUE(
+  matches("void foo() noexcept; bool bar = noexcept(foo());", NoExcept));
+  EXPECT_TRUE(notMatches("void foo() noexcept;", NoExcept));
+}
+
 TEST(Matcher, DefaultArgument) {
   StatementMatcher Arg = cxxDefaultArgExpr();
 
Index: clang/lib/Analysis/ExprMutationAnalyzer.cpp
===
--- clang/lib/Analysis/ExprMutationAnalyzer.cpp
+++ clang/lib/Analysis/ExprMutationAnalyzer.cpp
@@ -43,9 +43,6 @@
   return Node.isPotentiallyEvaluated();
 }
 
-const ast_matchers::internal::VariadicDynCastAllOfMatcher
-cxxNoexceptExpr;
-
 const ast_matchers::internal::VariadicDynCastAllOfMatcher
 genericSelectionExpr;
Index: clang/lib/ASTMatchers/Dynamic/Registry.cpp
===
--- clang/lib/ASTMatchers/Dynamic/Registry.cpp
+++ clang/lib/ASTMatchers/Dynamic/Registry.cpp
@@ -183,6 +183,7 @@
   REGISTER_MATCHER(cxxMemberCallExpr);
   REGISTER_MATCHER(cxxMethodDecl);
   REGISTER_MATCHER(cxxNewExpr);
+  REGISTER_MATCHER(cxxNoexceptExpr);
   REGISTER_MATCHER(cxxNullPtrLiteralExpr);
   REGISTER_MATCHER(cxxOperatorCallExpr);
   REGISTER_MATCHER(cxxRecordDecl);
Index: clang/lib/ASTMatchers/ASTMatchersInternal.cpp
===
--- clang/lib/ASTMatchers/ASTMatchersInternal.cpp
+++ clang/lib/ASTMatchers/ASTMatchersInternal.cpp
@@ -730,6 +730,8 @@
 materializeTemporaryExpr;
 const internal::VariadicDynCastAllOfMatcher cxxNewExpr;
 const internal::VariadicDynCastAllOfMatcher cxxDeleteExpr;
+const internal::VariadicDynCastAllOfMatcher
+cxxNoexceptExpr;
 const internal::VariadicDynCastAllOfMatcher
 arraySubscriptExpr;
 const internal::VariadicDynCastAllOfMatcher
Index: clang/include/clang/ASTMatchers/ASTMatchers.h
===
--- clang/include/clang/ASTMatchers/ASTMatchers.h
+++ clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -1824,6 +1824,20 @@
 extern const internal::VariadicDynCastAllOfMatcher
 cxxDeleteExpr;
 
+/// Matches noexcept expressions.
+///
+/// Given
+/// \code
+///   void nothrow() noexcpet;
+///   void throws();
+///   bool a = noexcept(nothrow())
+///   bool b = noexcept(throws())
+/// \endcode
+/// cxxNoexceptExpr()
+///   matches `noexcept(nothrow())` and `noexcept(throws())`.
+extern const internal::VariadicDynCastAllOfMatcher
+cxxNoexceptExpr;
+
 /// Matches array subscript expressions.
 ///
 /// Given
Index: clang/docs/LibASTMatchersReference.html
===
--- clang/docs/LibASTMatchersReference.html
+++ clang/docs/LibASTMatchersReference.html
@@ -1003,6 +1003,19 @@
 
 
 
+MatcherStmt>cxxNoexceptExprMatcherCXXNoexceptExpr>...
+Matches noexcept expressions.
+
+Given
+  void nothrow() noexcpet;
+  void throws();
+  bool a = noexcept(nothrow())
+  bool b = noexcept(throws())
+cxxNoexceptExpr()
+  matches `noexcept(nothrow())` and `noexcept(throws())`.
+
+
+
 MatcherStmt>cxxNullPtrLiteralExprMatcherCXXNullPtrLiteralExpr>...
 Matches nullptr literal.
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D73439: [ASTMatchers] Add cxxNoexceptExpr AST matcher

2020-01-26 Thread pre-merge checks [bot] via Phabricator via cfe-commits
merge_guards_bot added a comment.

{icon check-circle color=green} Unit tests: pass. 62196 tests passed, 0 failed 
and 815 were skipped.

{icon check-circle color=green} clang-tidy: pass.

{icon check-circle color=green} clang-format: pass.

Build artifacts 
: 
diff.json 
,
 clang-tidy.txt 
,
 clang-format.patch 
,
 CMakeCache.txt 
,
 console-log.txt 
,
 test-results.xml 


//Pre-merge checks is in beta. Report issue 
.
 Please join beta  or enable 
it for your project 
.//


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73439



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


[PATCH] D73441: [clang-tidy] Fix bugprone-use-after-move when move is in noexcept operator

2020-01-26 Thread Nathan James via Phabricator via cfe-commits
njames93 created this revision.
njames93 added reviewers: aaron.ballman, alexfh, JonasToth, hokein, gribozavr2.
Herald added subscribers: cfe-commits, xazax.hun.
Herald added a project: clang.

Fixes noexcept operator misinterpreted as being evaluated 
.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D73441

Files:
  clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-use-after-move.cpp


Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-use-after-move.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-use-after-move.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-use-after-move.cpp
@@ -1271,3 +1271,14 @@
   }
 };
 }
+
+namespace PR44667 {
+#define REQUIRE(expr) (void)(expr);
+struct S {};
+
+void foo() {
+  S s;
+  REQUIRE(noexcept(S{std::move(s)}));
+  S other{std::move(s)};
+}
+} // namespace PR44667
Index: clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp
@@ -8,6 +8,7 @@
 
 #include "UseAfterMoveCheck.h"
 
+#include "clang/ASTMatchers/ASTMatchers.h"
 #include "clang/Analysis/CFG.h"
 #include "clang/Lex/Lexer.h"
 
@@ -382,7 +383,8 @@
hasArgument(0, declRefExpr().bind("arg")),
anyOf(hasAncestor(lambdaExpr().bind("containing-lambda")),
  hasAncestor(functionDecl().bind("containing-func"))),
-   unless(inDecltypeOrTemplateArg()))
+   unless(inDecltypeOrTemplateArg()),
+   unless(hasAncestor(cxxNoexceptExpr(
   .bind("call-move");
 
   Finder->addMatcher(


Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-use-after-move.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-use-after-move.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-use-after-move.cpp
@@ -1271,3 +1271,14 @@
   }
 };
 }
+
+namespace PR44667 {
+#define REQUIRE(expr) (void)(expr);
+struct S {};
+
+void foo() {
+  S s;
+  REQUIRE(noexcept(S{std::move(s)}));
+  S other{std::move(s)};
+}
+} // namespace PR44667
Index: clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp
@@ -8,6 +8,7 @@
 
 #include "UseAfterMoveCheck.h"
 
+#include "clang/ASTMatchers/ASTMatchers.h"
 #include "clang/Analysis/CFG.h"
 #include "clang/Lex/Lexer.h"
 
@@ -382,7 +383,8 @@
hasArgument(0, declRefExpr().bind("arg")),
anyOf(hasAncestor(lambdaExpr().bind("containing-lambda")),
  hasAncestor(functionDecl().bind("containing-func"))),
-   unless(inDecltypeOrTemplateArg()))
+   unless(inDecltypeOrTemplateArg()),
+   unless(hasAncestor(cxxNoexceptExpr(
   .bind("call-move");
 
   Finder->addMatcher(
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D73439: [ASTMatchers] Add cxxNoexceptExpr AST matcher

2020-01-26 Thread Nathan James via Phabricator via cfe-commits
njames93 created this revision.
njames93 added a reviewer: aaron.ballman.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Adds a cxxNoexceptExpr matcher that matches the noexcept operator 
.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D73439

Files:
  clang/docs/LibASTMatchersReference.html
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/lib/ASTMatchers/ASTMatchersInternal.cpp
  clang/lib/ASTMatchers/Dynamic/Registry.cpp
  clang/lib/Analysis/ExprMutationAnalyzer.cpp
  clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp

Index: clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -679,6 +679,14 @@
   cxxDeleteExpr()));
 }
 
+TEST(Matcher, NoexceptExpression) {
+  StatementMatcher NoExcept = cxxNoexceptExpr();
+  EXPECT_TRUE(matches("void foo(); bool bar = noexcept(foo());", NoExcept));
+  EXPECT_TRUE(
+  matches("void foo() noexcept; bool bar = noexcept(foo());", NoExcept));
+  EXPECT_TRUE(notMatches("void foo() noexcept;", NoExcept));
+}
+
 TEST(Matcher, DefaultArgument) {
   StatementMatcher Arg = cxxDefaultArgExpr();
 
Index: clang/lib/Analysis/ExprMutationAnalyzer.cpp
===
--- clang/lib/Analysis/ExprMutationAnalyzer.cpp
+++ clang/lib/Analysis/ExprMutationAnalyzer.cpp
@@ -43,9 +43,6 @@
   return Node.isPotentiallyEvaluated();
 }
 
-const ast_matchers::internal::VariadicDynCastAllOfMatcher
-cxxNoexceptExpr;
-
 const ast_matchers::internal::VariadicDynCastAllOfMatcher
 genericSelectionExpr;
Index: clang/lib/ASTMatchers/Dynamic/Registry.cpp
===
--- clang/lib/ASTMatchers/Dynamic/Registry.cpp
+++ clang/lib/ASTMatchers/Dynamic/Registry.cpp
@@ -183,6 +183,7 @@
   REGISTER_MATCHER(cxxMemberCallExpr);
   REGISTER_MATCHER(cxxMethodDecl);
   REGISTER_MATCHER(cxxNewExpr);
+  REGISTER_MATCHER(cxxNoexceptExpr);
   REGISTER_MATCHER(cxxNullPtrLiteralExpr);
   REGISTER_MATCHER(cxxOperatorCallExpr);
   REGISTER_MATCHER(cxxRecordDecl);
Index: clang/lib/ASTMatchers/ASTMatchersInternal.cpp
===
--- clang/lib/ASTMatchers/ASTMatchersInternal.cpp
+++ clang/lib/ASTMatchers/ASTMatchersInternal.cpp
@@ -730,6 +730,8 @@
 materializeTemporaryExpr;
 const internal::VariadicDynCastAllOfMatcher cxxNewExpr;
 const internal::VariadicDynCastAllOfMatcher cxxDeleteExpr;
+const internal::VariadicDynCastAllOfMatcher
+cxxNoexceptExpr;
 const internal::VariadicDynCastAllOfMatcher
 arraySubscriptExpr;
 const internal::VariadicDynCastAllOfMatcher
Index: clang/include/clang/ASTMatchers/ASTMatchers.h
===
--- clang/include/clang/ASTMatchers/ASTMatchers.h
+++ clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -1824,6 +1824,20 @@
 extern const internal::VariadicDynCastAllOfMatcher
 cxxDeleteExpr;
 
+/// Matches noexcept expressions.
+///
+/// Given
+/// \code
+///   void nothrow() noexcpet;
+///   void throws();
+///   bool a = noexcept(nothrow())
+///   bool b = noexcept(throws())
+/// \endcode
+/// cxxNoexceptExpr()
+///   matches `noexcept(nothrow())` and noexcept(throws())
+extern const internal::VariadicDynCastAllOfMatcher
+cxxNoexceptExpr;
+
 /// Matches array subscript expressions.
 ///
 /// Given
Index: clang/docs/LibASTMatchersReference.html
===
--- clang/docs/LibASTMatchersReference.html
+++ clang/docs/LibASTMatchersReference.html
@@ -1003,6 +1003,19 @@
 
 
 
+MatcherStmt>cxxNoexceptExprMatcherCXXNoexceptExpr>...
+Matches noexcept expressions.
+
+Given
+  void nothrow() noexcpet;
+  void throws();
+  bool a = noexcept(nothrow())
+  bool b = noexcept(throws())
+cxxNoexceptExpr()
+  matches `noexcept(nothrow())` and noexcept(throws())
+
+
+
 MatcherStmt>cxxNullPtrLiteralExprMatcherCXXNullPtrLiteralExpr>...
 Matches nullptr literal.
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2020-01-26 Thread Alexander Lanin via Phabricator via cfe-commits
AlexanderLanin added a comment.

In D54943#1815772 , @0x8000- wrote:

> This generated 56 "const const" declarations, of which 25 were triple const!


I've tried this on ccache (326 fixes, nice!), but some came out as 'const 
const'.
At least in my case I traced it back to having `src/..` and `./src/..` 
within the fixes.yml file.
On first glance these result from having `./src` as an include directory.

After replacing `-I./` with `-I` within compile_commands.json I'm not getting 
`const const` anymore.

Not sure who is at fault here / who should fix it.
But at least in the trivial case of ./ I feel clang-tidy should fix it when it 
writes the yml files?!

This surfaces here simply due to the shire number of files with fixes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D54943



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


[PATCH] D73434: [Sema] Remove a -Wrange warning from -Wall

2020-01-26 Thread Aaron Puchert via Phabricator via cfe-commits
aaronpuchert added a comment.

Looks right to me, but someone else should approve.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73434



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


[clang] 9c24fca - [Concepts] Fix incorrect TemplateArgs for introduction of local parameters

2020-01-26 Thread Saar Raz via cfe-commits

Author: Saar Raz
Date: 2020-01-27T00:59:37+02:00
New Revision: 9c24fca2a33fc0fd059e278bb95c84803dfff9ae

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

LOG: [Concepts] Fix incorrect TemplateArgs for introduction of local parameters

The wrong set of TemplateArgs was being provided to 
addInstantiatedParametersToScope.
Caused bug #44658.

Added: 


Modified: 
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
clang/test/SemaTemplate/instantiate-requires-clause.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp 
b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index fbbab8f00703..2e437cbe44d3 100755
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -4246,18 +4246,17 @@ bool Sema::CheckInstantiatedFunctionTemplateConstraints(
   Sema::ContextRAII savedContext(*this, Decl);
   LocalInstantiationScope Scope(*this);
 
-  MultiLevelTemplateArgumentList MLTAL =
-getTemplateInstantiationArgs(Decl, nullptr, /*RelativeToPrimary*/true);
-
   // If this is not an explicit specialization - we need to get the 
instantiated
   // version of the template arguments and add them to scope for the
   // substitution.
   if (Decl->isTemplateInstantiation()) {
 InstantiatingTemplate Inst(*this, Decl->getPointOfInstantiation(),
 InstantiatingTemplate::ConstraintsCheck{}, Decl->getPrimaryTemplate(),
-MLTAL.getInnermost(), SourceRange());
+TemplateArgs, SourceRange());
 if (Inst.isInvalid())
   return true;
+MultiLevelTemplateArgumentList MLTAL(
+*Decl->getTemplateSpecializationArgs());
 if (addInstantiatedParametersToScope(
 *this, Decl, Decl->getPrimaryTemplate()->getTemplatedDecl(),
 Scope, MLTAL))

diff  --git a/clang/test/SemaTemplate/instantiate-requires-clause.cpp 
b/clang/test/SemaTemplate/instantiate-requires-clause.cpp
index 31cf484d564c..8e9d5bffa906 100644
--- a/clang/test/SemaTemplate/instantiate-requires-clause.cpp
+++ b/clang/test/SemaTemplate/instantiate-requires-clause.cpp
@@ -51,3 +51,10 @@ struct S2 {
 
 static_assert((S2::f(), true));
 
+template
+struct S3 {
+   template requires true
+   static constexpr void f(Args...) { }
+};
+
+static_assert((S3::f(), true));
\ No newline at end of file



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


[clang] a8d096a - [Concepts] Add missing null check to transformConstructor

2020-01-26 Thread Saar Raz via cfe-commits

Author: Saar Raz
Date: 2020-01-27T00:15:42+02:00
New Revision: a8d096aff6b1930ad57bd0c30077d2b4920b5025

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

LOG: [Concepts] Add missing null check to transformConstructor

Caused bug 44671 when transforming a constructor with a type-constraint with no 
explicit template args.

Added: 


Modified: 
clang/lib/Sema/SemaTemplate.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index ba4cd7632f3c..4d38d07a6213 100755
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -2047,12 +2047,14 @@ struct ConvertConstructorToDeductionGuideTransform {
   if (const auto *TC = TTP->getTypeConstraint()) {
 TemplateArgumentListInfo TransformedArgs;
 const auto *ArgsAsWritten = TC->getTemplateArgsAsWritten();
-if (SemaRef.Subst(ArgsAsWritten->getTemplateArgs(),
+if (!ArgsAsWritten ||
+SemaRef.Subst(ArgsAsWritten->getTemplateArgs(),
   ArgsAsWritten->NumTemplateArgs, TransformedArgs,
   Args))
   SemaRef.AttachTypeConstraint(
   TC->getNestedNameSpecifierLoc(), TC->getConceptNameInfo(),
-  TC->getNamedConcept(), &TransformedArgs, NewTTP,
+  TC->getNamedConcept(), ArgsAsWritten ? &TransformedArgs : 
nullptr,
+  NewTTP,
   NewTTP->isParameterPack()
  ? cast(TC->getImmediatelyDeclaredConstraint())
  ->getEllipsisLoc()



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


[PATCH] D72448: [clang-tidy] readability-redundant-string-init now flags redundant initialisation in Field Decls and Constructor Initialisers

2020-01-26 Thread Nathan James via Phabricator via cfe-commits
njames93 marked 2 inline comments as done.
njames93 added inline comments.



Comment at: 
clang-tools-extra/clang-tidy/readability/RedundantStringInitCheck.cpp:58
+  }
+  if (B.isInvalid() || E.isInvalid())
+return llvm::None;

aaron.ballman wrote:
> Should we be worried about macros here?
> 
> It looks a bit like we're ignoring macros entirely for this check, so maybe 
> that can be done as a separate patch instead. The situation I am worried 
> about is:
> ```
> #if SOMETHING
> #define INIT ""
> #else
> #define INIT "haha"
> #endif
> 
> std::string S = INIT;
> ```
I feel that everything in this check needs to check macros, but that's probably 
a follow up patch



Comment at: 
clang-tools-extra/clang-tidy/readability/RedundantStringInitCheck.cpp:110
   namedDecl(
-  varDecl(
-  hasType(hasUnqualifiedDesugaredType(recordType(
-  hasDeclaration(cxxRecordDecl(hasStringTypeName),
-  hasInitializer(expr(ignoringImplicit(anyOf(
-  EmptyStringCtorExpr, EmptyStringCtorExprWithTemporaries)
-  .bind("vardecl"),
+  varDecl(StringType, hasInitializer(EmptyStringInit)).bind("vardecl"),
   unless(parmVarDecl())),

aaron.ballman wrote:
> Should this also match on something like `std::string foo{};` as a redundant 
> init? Similar question for the other cases. (Could be done in a follow-up 
> patch if desired.)
Probably should, however this is not what this patch is about


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72448



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


[PATCH] D73380: [clang] Annotating C++'s `operator new` with more attributes

2020-01-26 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri marked 3 inline comments as done.
lebedev.ri added inline comments.



Comment at: clang/lib/Sema/SemaDecl.cpp:14361
+/// attributes are applied to declarations.
+void Sema::AddKnownFunctionAttributesForReplaceableGlobalAllocationFunction(
+FunctionDecl *FD) {

rsmith wrote:
> lebedev.ri wrote:
> > rsmith wrote:
> > > This should all be done by CodeGen, not by injecting source-level 
> > > attributes.
> > I don't agree, can you explain why this should be done in codegen?
> Generally, it's a design goal for the Clang AST to represent the original 
> program source 
> (http://clang.llvm.org/docs/InternalsManual.html#faithfulness). But I suppose 
> these attributes are all marked "implicit", and it's a good idea to express 
> these hints uniformly to codegen and the static analyzer and so on... OK, I 
> can make peace with doing this here.
> Generally, it's a design goal for the Clang AST to represent the original 
> program source (http://clang.llvm.org/docs/InternalsManual.html#faithfulness).

I fully agree with that goal!

> But I suppose these attributes are all marked "implicit",

Yeah, this was a predefined goal here - they are added implicitly,
therefore in AST we should not pretend that they originate from source code..

> and it's a good idea to express these hints uniformly to codegen and the 
> static analyzer and so on... 

Precisely.

> OK, I can make peace with doing this here.

Okay.



Comment at: clang/lib/Sema/SemaDecl.cpp:14414-14432
+  // C++2a [basic.stc.dynamic.allocation]p3:
+  //   For an allocation function [...], the pointer returned on a successful
+  //   call shall represent the address of storage that is aligned as follows:
+  //   (3.2),(3.3) Otherwise, [...] the storage is aligned for any object
+  //   that does not have new-extended alignment [...].
+  //
+  // NOTE: we intentionally always manifest this basic alignment, because it is

rsmith wrote:
> lebedev.ri wrote:
> > rsmith wrote:
> > > This is incorrect. The pointer returned by `operator new` is only 
> > > suitably aligned for any object that does not have new-extended alignment 
> > > **and is of the requested size**. And the pointer returned by `operator 
> > > new[]` is suitably aligned for any object **that is no larger than the 
> > > requested size**. (These are both different from the rule for `malloc`, 
> > > which does behave as you're suggesting here.) For example:
> > > 
> > > Suppose the default new alignment and the largest fundamental alignment 
> > > are both 16, and we try to allocate 12 bytes. Then:
> > > 
> > >  * `operator new` need only return storage that is 4-byte aligned 
> > > (because that is the largest alignment that can be required by a type `T` 
> > > with `sizeof(T) == 12`)
> > >  * `operator new` need only return storage that is 8-byte aligned 
> > > (because that is the largest alignment that can be required by a type `T` 
> > > with `sizeof(T) <= 12`)
> > >  * `malloc` must return storage that is 16-byte aligned (because that is 
> > > the largest fundamental alignment)
> > So essentially, if we can't evaluate the requested byte count as a 
> > constant/constant range,
> > we must simply give up here, on the most interesting case of variable 
> > allocation size?
> > That is surprisingly extremely pessimizing from C++ :)
> > 
> > 
> The benefit from not requiring all allocations to be padded to a multiple of 
> the largest fundamental alignment is probably worth a lot more than allowing 
> the optimizer to assume a higher alignment for pointers from direct calls to 
> `operator new` with a non-constant argument.
> 
> We can at least look for a constant argument in CodeGen and emit the 
> alignment hint there. (Though it's probably better to do that in the 
> middle-end, since the argument might be reduced to a constant via inlining, 
> especially for uses of `std::allocator` and similar.)
Please correct me if i'm not grasping the pattern correctly:

> Suppose the default new alignment and the largest fundamental alignment are 
> both 16, and we try to allocate 12 bytes. Then:
> * `operator new[]` need only return storage that is 8-byte aligned (because 
> that is the largest alignment that can be required by a type `T` with 
> `sizeof(T) <= 12)`

Because into 12 bytes, the largest fundamental type that fits is `long long 
int` or `double`,
both with size/alignment of 8; and we don't care about the remaining padding, 
if any?

> * `operator new` need only return storage that is 4-byte aligned (because 
> that is the largest alignment that can be required by a type `T` with 
> `sizeof(T) == 12)`

"We have exactly 12 bytes. If we treat this as an array, what is the larges 
type that could be stored into this array, **leaving no padding**?"

> The benefit from not requiring all allocations to be padded to a multiple of 
> the largest fundamental alignment is probably worth a lot more than allowing 
>

[PATCH] D73380: [clang] Annotating C++'s `operator new` with more attributes

2020-01-26 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added inline comments.



Comment at: clang/lib/Sema/SemaDecl.cpp:14361
+/// attributes are applied to declarations.
+void Sema::AddKnownFunctionAttributesForReplaceableGlobalAllocationFunction(
+FunctionDecl *FD) {

lebedev.ri wrote:
> rsmith wrote:
> > This should all be done by CodeGen, not by injecting source-level 
> > attributes.
> I don't agree, can you explain why this should be done in codegen?
Generally, it's a design goal for the Clang AST to represent the original 
program source (http://clang.llvm.org/docs/InternalsManual.html#faithfulness). 
But I suppose these attributes are all marked "implicit", and it's a good idea 
to express these hints uniformly to codegen and the static analyzer and so 
on... OK, I can make peace with doing this here.



Comment at: clang/lib/Sema/SemaDecl.cpp:14414-14432
+  // C++2a [basic.stc.dynamic.allocation]p3:
+  //   For an allocation function [...], the pointer returned on a successful
+  //   call shall represent the address of storage that is aligned as follows:
+  //   (3.2),(3.3) Otherwise, [...] the storage is aligned for any object
+  //   that does not have new-extended alignment [...].
+  //
+  // NOTE: we intentionally always manifest this basic alignment, because it is

lebedev.ri wrote:
> rsmith wrote:
> > This is incorrect. The pointer returned by `operator new` is only suitably 
> > aligned for any object that does not have new-extended alignment **and is 
> > of the requested size**. And the pointer returned by `operator new[]` is 
> > suitably aligned for any object **that is no larger than the requested 
> > size**. (These are both different from the rule for `malloc`, which does 
> > behave as you're suggesting here.) For example:
> > 
> > Suppose the default new alignment and the largest fundamental alignment are 
> > both 16, and we try to allocate 12 bytes. Then:
> > 
> >  * `operator new` need only return storage that is 4-byte aligned (because 
> > that is the largest alignment that can be required by a type `T` with 
> > `sizeof(T) == 12`)
> >  * `operator new` need only return storage that is 8-byte aligned (because 
> > that is the largest alignment that can be required by a type `T` with 
> > `sizeof(T) <= 12`)
> >  * `malloc` must return storage that is 16-byte aligned (because that is 
> > the largest fundamental alignment)
> So essentially, if we can't evaluate the requested byte count as a 
> constant/constant range,
> we must simply give up here, on the most interesting case of variable 
> allocation size?
> That is surprisingly extremely pessimizing from C++ :)
> 
> 
The benefit from not requiring all allocations to be padded to a multiple of 
the largest fundamental alignment is probably worth a lot more than allowing 
the optimizer to assume a higher alignment for pointers from direct calls to 
`operator new` with a non-constant argument.

We can at least look for a constant argument in CodeGen and emit the alignment 
hint there. (Though it's probably better to do that in the middle-end, since 
the argument might be reduced to a constant via inlining, especially for uses 
of `std::allocator` and similar.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73380



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


[PATCH] D73285: [OpenMP][OMPIRBuilder][BugFix] Handle Unreachable Finalization blocks in `parallel` generation

2020-01-26 Thread Fady Ghanim via Phabricator via cfe-commits
fghanim updated this revision to Diff 240451.
fghanim added a comment.

Adding a new unittest for the this fix. Thanks to JDoerfert for Writing and 
providing me with this patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73285

Files:
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
  llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp

Index: llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
===
--- llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
+++ llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
@@ -400,6 +400,78 @@
   EXPECT_EQ(ForkCI->getArgOperand(3), F->arg_begin());
 }
 
+TEST_F(OpenMPIRBuilderTest, ParallelEndless) {
+  using InsertPointTy = OpenMPIRBuilder::InsertPointTy;
+  OpenMPIRBuilder OMPBuilder(*M);
+  OMPBuilder.initialize();
+  F->setName("func");
+  IRBuilder<> Builder(BB);
+
+  OpenMPIRBuilder::LocationDescription Loc({Builder.saveIP(), DL});
+
+  unsigned NumBodiesGenerated = 0;
+  unsigned NumPrivatizedVars = 0;
+  unsigned NumFinalizationPoints = 0;
+
+  BasicBlock *OutlinedBodyBB = nullptr;
+  auto BodyGenCB = [&](InsertPointTy AllocaIP, InsertPointTy CodeGenIP,
+   BasicBlock &ContinuationIP) {
+++NumBodiesGenerated;
+
+auto *OldBB = OutlinedBodyBB = CodeGenIP.getBlock();
+
+// Create an endless loop.
+OldBB->getTerminator()->eraseFromParent();
+BranchInst::Create(OldBB, OldBB);
+
+Builder.ClearInsertionPoint();
+  };
+
+  auto PrivCB = [&](InsertPointTy AllocaIP, InsertPointTy CodeGenIP,
+Value &VPtr, Value *&ReplacementValue) -> InsertPointTy {
+++NumPrivatizedVars;
+return CodeGenIP;
+  };
+
+  auto FiniCB = [&](InsertPointTy CodeGenIP) { ++NumFinalizationPoints; };
+
+  IRBuilder<>::InsertPoint AfterIP =
+  OMPBuilder.CreateParallel(Loc, BodyGenCB, PrivCB, FiniCB, nullptr,
+nullptr, OMP_PROC_BIND_default, false);
+
+  EXPECT_EQ(NumBodiesGenerated, 1U);
+  EXPECT_EQ(NumPrivatizedVars, 0U);
+  EXPECT_EQ(NumFinalizationPoints, 0U);
+
+  Builder.restoreIP(AfterIP);
+  Builder.CreateRetVoid();
+
+  ASSERT_NE(OutlinedBodyBB, nullptr);
+  Function *OutlinedFn = OutlinedBodyBB->getParent();
+  EXPECT_NE(F, OutlinedFn);
+  EXPECT_FALSE(verifyModule(*M));
+  EXPECT_TRUE(OutlinedFn->hasFnAttribute(Attribute::NoUnwind));
+  EXPECT_TRUE(OutlinedFn->hasFnAttribute(Attribute::NoRecurse));
+  EXPECT_TRUE(OutlinedFn->hasParamAttribute(0, Attribute::NoAlias));
+  EXPECT_TRUE(OutlinedFn->hasParamAttribute(1, Attribute::NoAlias));
+
+  EXPECT_TRUE(OutlinedFn->hasInternalLinkage());
+  EXPECT_EQ(OutlinedFn->arg_size(), 2U);
+
+  EXPECT_EQ(OutlinedFn->getNumUses(), 1U);
+  User *Usr = OutlinedFn->user_back();
+  ASSERT_TRUE(isa(Usr));
+  CallInst *ForkCI = dyn_cast(Usr->user_back());
+  ASSERT_NE(ForkCI, nullptr);
+
+  EXPECT_EQ(ForkCI->getCalledFunction()->getName(), "__kmpc_fork_call");
+  EXPECT_EQ(ForkCI->getNumArgOperands(), 3U);
+  EXPECT_TRUE(isa(ForkCI->getArgOperand(0)));
+  EXPECT_EQ(ForkCI->getArgOperand(1),
+ConstantInt::get(Type::getInt32Ty(Ctx), 0U));
+  EXPECT_EQ(ForkCI->getArgOperand(2), Usr);
+}
+
 TEST_F(OpenMPIRBuilderTest, ParallelIfCond) {
   using InsertPointTy = OpenMPIRBuilder::InsertPointTy;
   OpenMPIRBuilder OMPBuilder(*M);
Index: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
===
--- llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -623,6 +623,7 @@
   auto FiniInfo = FinalizationStack.pop_back_val();
   assert(FiniInfo.DK == OMPD_parallel &&
  "Unexpected finalization stack state!");
+
   if (FoundPreFiniBB) {
 // PRegPreFiniBB is reachable. Adjust the finalization stack, verify the
 // adjustment, and call the finalize function a last time to finalize values
@@ -631,10 +632,7 @@
 (void)FiniInfo;
 
 Instruction *PreFiniTI = PRegPreFiniBB->getTerminator();
-assert(PreFiniTI->getNumSuccessors() == 1 &&
-   PreFiniTI->getSuccessor(0)->size() == 1 &&
-   isa(PreFiniTI->getSuccessor(0)->getTerminator()) &&
-   "Unexpected CFG structure!");
+assert(PreFiniTI->getNumSuccessors() == 1 && "Unexpected CFG structure!");
 
 InsertPointTy PreFiniIP(PRegPreFiniBB, PreFiniTI->getIterator());
 FiniCB(PreFiniIP);
@@ -665,7 +663,6 @@
   for (Instruction *I : ToBeDeleted)
 I->eraseFromParent();
 
-  AfterIP.getBlock()->dump();
   return AfterIP;
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 5043962 - [Concepts] Fix parsing of scope specifier in compound-requirements, add more tests for scope specifiers in type-constraints

2020-01-26 Thread Saar Raz via cfe-commits

Author: Saar Raz
Date: 2020-01-26T20:46:53+02:00
New Revision: 5043962dd3150c6ac72b75174b9460a510d1b5c3

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

LOG: [Concepts] Fix parsing of scope specifier in compound-requirements, add 
more tests for scope specifiers in type-constraints

The code for parsing of type-constraints in compound-requirements was not 
adapted for the new TryAnnotateTypeConstraint which
caused compound-requirements with scope specifiers to ignore them.

Also add regression tests for scope specifiers in type-constraints in more 
contexts.

Added: 
clang/test/Parser/cxx2a-abbreviated-templates.cpp

Modified: 
clang/lib/Parse/ParseExprCXX.cpp
clang/test/Parser/cxx2a-concepts-requires-expr.cpp
clang/test/Parser/cxx2a-placeholder-type-constraint.cpp

Removed: 




diff  --git a/clang/lib/Parse/ParseExprCXX.cpp 
b/clang/lib/Parse/ParseExprCXX.cpp
index 73d15cbc20c1..5b604f940ab8 100644
--- a/clang/lib/Parse/ParseExprCXX.cpp
+++ b/clang/lib/Parse/ParseExprCXX.cpp
@@ -3383,25 +3383,6 @@ ExprResult Parser::ParseRequiresExpression() {
   Diag(Tok, diag::err_requires_expr_missing_arrow)
   << FixItHint::CreateInsertion(Tok.getLocation(), "->");
 // Try to parse a 'type-constraint'
-CXXScopeSpec SS;
-if (ParseOptionalCXXScopeSpecifier(SS, ParsedType(),
-   /*EnteringContext=*/false,
-   /*MayBePseudoDestructor=*/nullptr,
-   // If this is not a type-constraint,
-   // then this scope-spec is part of
-   // the typename of a non-type
-   // template parameter
-   /*IsTypename=*/true,
-   /*LastII=*/nullptr,
-   // We won't find concepts in
-   // non-namespaces anyway, so might 
as
-   // well parse this correctly for
-   // possible type names.
-   /*OnlyNamespace=*/false,
-   /*SuppressDiagnostic=*/true)) {
-  SkipUntil(tok::semi, tok::r_brace, SkipUntilFlags::StopBeforeMatch);
-  break;
-}
 if (TryAnnotateTypeConstraint()) {
   SkipUntil(tok::semi, tok::r_brace, SkipUntilFlags::StopBeforeMatch);
   break;
@@ -3411,8 +3392,13 @@ ExprResult Parser::ParseRequiresExpression() {
   SkipUntil(tok::semi, tok::r_brace, SkipUntilFlags::StopBeforeMatch);
   break;
 }
-if (Tok.is(tok::annot_cxxscope))
+CXXScopeSpec SS;
+if (Tok.is(tok::annot_cxxscope)) {
+  
Actions.RestoreNestedNameSpecifierAnnotation(Tok.getAnnotationValue(),
+   
Tok.getAnnotationRange(),
+   SS);
   ConsumeAnnotationToken();
+}
 
 Req = Actions.ActOnCompoundRequirement(
 Expression.get(), NoexceptLoc, SS, takeTemplateIdAnnotation(Tok),

diff  --git a/clang/test/Parser/cxx2a-abbreviated-templates.cpp 
b/clang/test/Parser/cxx2a-abbreviated-templates.cpp
new file mode 100644
index ..e2b3803c807e
--- /dev/null
+++ b/clang/test/Parser/cxx2a-abbreviated-templates.cpp
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -std=c++2a -x c++ %s -verify
+// expected-no-diagnostics
+
+template
+concept C = true;
+
+namespace ns {
+  template
+  concept D = true;
+}
+
+void foo(C auto a,
+ C auto b,
+ ns::D auto c,
+ ns::D auto d,
+ const C auto e,
+ const C auto f,
+ const ns::D auto g,
+ const ns::D auto h);
\ No newline at end of file

diff  --git a/clang/test/Parser/cxx2a-concepts-requires-expr.cpp 
b/clang/test/Parser/cxx2a-concepts-requires-expr.cpp
index 6b4a5d62b407..fa42b0633850 100644
--- a/clang/test/Parser/cxx2a-concepts-requires-expr.cpp
+++ b/clang/test/Parser/cxx2a-concepts-requires-expr.cpp
@@ -108,34 +108,38 @@ bool r29 = requires { { 0 } noexcept C1; };
 
 bool r30 = requires { { 0 } noexcept -> C2; };
 
+namespace ns { template concept C = true; }
+
+bool r31 = requires { { 0 } noexcept -> ns::C; };
+
 template
 T i1 = 0;
 
-bool r31 = requires { requires false, 1; };
+bool r32 = requires { requires false, 1; };
 // expected-error@-1 {{expected ';' at end of requirement}}
 
-bool r32 = requires { 0 noexcept; };
+bool r33 = requires { 0 noexcept; };
 // expected-error@-1 {{'noexcept' can only be used in a compou

[PATCH] D73413: [clang-tidy] Add check to detect external definitions with no header declaration

2020-01-26 Thread Noel Grandin via Phabricator via cfe-commits
grandinj added a comment.

You might want to look at the equivalent LibreOffice checkers, which we have 
been using for some time

https://cgit.freedesktop.org/libreoffice/core/tree/compilerplugins/clang/external.cxx
https://cgit.freedesktop.org/libreoffice/core/tree/compilerplugins/clang/test/external.cxx

https://cgit.freedesktop.org/libreoffice/core/tree/compilerplugins/clang/externandnotdefined.cxx

https://cgit.freedesktop.org/libreoffice/core/tree/compilerplugins/clang/externvar.cxx
https://cgit.freedesktop.org/libreoffice/core/tree/compilerplugins/clang/test/externvar.hxx
https://cgit.freedesktop.org/libreoffice/core/tree/compilerplugins/clang/test/externvar.cxx

As you can see, we are a little less organised :-)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73413



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


[PATCH] D73388: NFC: Implement AST node skipping in ParentMapContext

2020-01-26 Thread Stephen Kelly via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf29204d3: NFC: Implement AST node skipping in 
ParentMapContext (authored by stephenkelly).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73388

Files:
  clang/include/clang/AST/ParentMapContext.h
  clang/lib/AST/ParentMapContext.cpp

Index: clang/lib/AST/ParentMapContext.cpp
===
--- clang/lib/AST/ParentMapContext.cpp
+++ clang/lib/AST/ParentMapContext.cpp
@@ -23,7 +23,7 @@
 
 ParentMapContext::~ParentMapContext() = default;
 
-void ParentMapContext::clear() { Parents.clear(); }
+void ParentMapContext::clear() { Parents.reset(); }
 
 const Expr *ParentMapContext::traverseIgnored(const Expr *E) const {
   return traverseIgnored(const_cast(E));
@@ -116,11 +116,79 @@
 }
   }
 
-  DynTypedNodeList getParents(const ast_type_traits::DynTypedNode &Node) {
-if (Node.getNodeKind().hasPointerIdentity())
-  return getDynNodeFromMap(Node.getMemoizationData(), PointerParents);
+  DynTypedNodeList getParents(ast_type_traits::TraversalKind TK,
+  const ast_type_traits::DynTypedNode &Node) {
+if (Node.getNodeKind().hasPointerIdentity()) {
+  auto ParentList =
+  getDynNodeFromMap(Node.getMemoizationData(), PointerParents);
+  if (ParentList.size() == 1 &&
+  TK == ast_type_traits::TK_IgnoreUnlessSpelledInSource) {
+const auto *E = ParentList[0].get();
+const auto *Child = Node.get();
+if (E && Child)
+  return AscendIgnoreUnlessSpelledInSource(E, Child);
+  }
+  return ParentList;
+}
 return getDynNodeFromMap(Node, OtherParents);
   }
+
+  ast_type_traits::DynTypedNode
+  AscendIgnoreUnlessSpelledInSource(const Expr *E, const Expr *Child) {
+
+auto ShouldSkip = [](const Expr *E, const Expr *Child) {
+  if (isa(E))
+return true;
+
+  if (isa(E))
+return true;
+
+  if (isa(E))
+return true;
+
+  if (isa(E))
+return true;
+
+  if (isa(E))
+return true;
+
+  if (isa(E))
+return true;
+
+  auto SR = Child->getSourceRange();
+
+  if (const auto *C = dyn_cast(E)) {
+if (C->getSourceRange() == SR || !isa(C))
+  return true;
+  }
+
+  if (const auto *C = dyn_cast(E)) {
+if (C->getSourceRange() == SR)
+  return true;
+  }
+
+  if (const auto *C = dyn_cast(E)) {
+if (C->getSourceRange() == SR)
+  return true;
+  }
+  return false;
+};
+
+while (ShouldSkip(E, Child)) {
+  auto It = PointerParents.find(E);
+  if (It == PointerParents.end())
+break;
+  const auto *S = It->second.dyn_cast();
+  if (!S)
+return getSingleDynTypedNodeFromParentMap(It->second);
+  const auto *P = dyn_cast(S);
+  if (!P)
+return ast_type_traits::DynTypedNode::create(*S);
+  Child = E;
+  E = P;
+}
+return ast_type_traits::DynTypedNode::create(*E);
+  }
 };
 
 /// Template specializations to abstract away from pointers and TypeLocs.
@@ -151,8 +219,7 @@
 class ParentMapContext::ParentMap::ASTVisitor
 : public RecursiveASTVisitor {
 public:
-  ASTVisitor(ParentMap &Map, ParentMapContext &MapCtx)
-  : Map(Map), MapCtx(MapCtx) {}
+  ASTVisitor(ParentMap &Map) : Map(Map) {}
 
 private:
   friend class RecursiveASTVisitor;
@@ -222,11 +289,8 @@
   }
 
   bool TraverseStmt(Stmt *StmtNode) {
-Stmt *FilteredNode = StmtNode;
-if (auto *ExprNode = dyn_cast_or_null(FilteredNode))
-  FilteredNode = MapCtx.traverseIgnored(ExprNode);
-return TraverseNode(FilteredNode, FilteredNode,
-[&] { return VisitorBase::TraverseStmt(FilteredNode); },
+return TraverseNode(StmtNode, StmtNode,
+[&] { return VisitorBase::TraverseStmt(StmtNode); },
 &Map.PointerParents);
   }
 
@@ -245,21 +309,18 @@
   }
 
   ParentMap ⤅
-  ParentMapContext &MapCtx;
   llvm::SmallVector ParentStack;
 };
 
 ParentMapContext::ParentMap::ParentMap(ASTContext &Ctx) {
-  ASTVisitor(*this, Ctx.getParentMapContext()).TraverseAST(Ctx);
+  ASTVisitor(*this).TraverseAST(Ctx);
 }
 
 DynTypedNodeList
 ParentMapContext::getParents(const ast_type_traits::DynTypedNode &Node) {
-  std::unique_ptr &P = Parents[Traversal];
-  if (!P)
+  if (!Parents)
 // We build the parent map for the traversal scope (usually whole TU), as
 // hasAncestor can escape any subtree.
-P = std::make_unique(ASTCtx);
-  return P->getParents(Node);
+Parents = std::make_unique(ASTCtx);
+  return Parents->getParents(getTraversalKind(), Node);
 }
-
Index: clang/include/clang/AST/ParentMapContext.h
===
--- clang/include/clang/AST/ParentMapContext.h
+++ clang/include/clang/AST/ParentMapContext.h
@@ 

[clang] f29204d - NFC: Implement AST node skipping in ParentMapContext

2020-01-26 Thread Stephen Kelly via cfe-commits

Author: Stephen Kelly
Date: 2020-01-26T18:35:44Z
New Revision: f29204d397dc5b6fec83df5f2a77aff17173

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

LOG: NFC: Implement AST node skipping in ParentMapContext

Summary:
This allows ASTContext to store only one parent map, rather than storing
an entire parent map for each traversal mode used.

This is therefore a partial revert of commit 0a717d5b (Make it possible
control matcher traversal kind with ASTContext, 2019-12-06).

Reviewers: aaron.ballman, rsmith, rnk

Subscribers: cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang/include/clang/AST/ParentMapContext.h
clang/lib/AST/ParentMapContext.cpp

Removed: 




diff  --git a/clang/include/clang/AST/ParentMapContext.h 
b/clang/include/clang/AST/ParentMapContext.h
index de1f054be168..c0fc5e286a59 100644
--- a/clang/include/clang/AST/ParentMapContext.h
+++ b/clang/include/clang/AST/ParentMapContext.h
@@ -69,7 +69,7 @@ class ParentMapContext {
   ASTContext &ASTCtx;
   class ParentMap;
   ast_type_traits::TraversalKind Traversal = ast_type_traits::TK_AsIs;
-  std::map> Parents;
+  std::unique_ptr Parents;
 };
 
 class TraversalKindScope {

diff  --git a/clang/lib/AST/ParentMapContext.cpp 
b/clang/lib/AST/ParentMapContext.cpp
index 6287bc8c1d72..6a22e687ff57 100644
--- a/clang/lib/AST/ParentMapContext.cpp
+++ b/clang/lib/AST/ParentMapContext.cpp
@@ -23,7 +23,7 @@ ParentMapContext::ParentMapContext(ASTContext &Ctx) : 
ASTCtx(Ctx) {}
 
 ParentMapContext::~ParentMapContext() = default;
 
-void ParentMapContext::clear() { Parents.clear(); }
+void ParentMapContext::clear() { Parents.reset(); }
 
 const Expr *ParentMapContext::traverseIgnored(const Expr *E) const {
   return traverseIgnored(const_cast(E));
@@ -116,11 +116,79 @@ class ParentMapContext::ParentMap {
 }
   }
 
-  DynTypedNodeList getParents(const ast_type_traits::DynTypedNode &Node) {
-if (Node.getNodeKind().hasPointerIdentity())
-  return getDynNodeFromMap(Node.getMemoizationData(), PointerParents);
+  DynTypedNodeList getParents(ast_type_traits::TraversalKind TK,
+  const ast_type_traits::DynTypedNode &Node) {
+if (Node.getNodeKind().hasPointerIdentity()) {
+  auto ParentList =
+  getDynNodeFromMap(Node.getMemoizationData(), PointerParents);
+  if (ParentList.size() == 1 &&
+  TK == ast_type_traits::TK_IgnoreUnlessSpelledInSource) {
+const auto *E = ParentList[0].get();
+const auto *Child = Node.get();
+if (E && Child)
+  return AscendIgnoreUnlessSpelledInSource(E, Child);
+  }
+  return ParentList;
+}
 return getDynNodeFromMap(Node, OtherParents);
   }
+
+  ast_type_traits::DynTypedNode
+  AscendIgnoreUnlessSpelledInSource(const Expr *E, const Expr *Child) {
+
+auto ShouldSkip = [](const Expr *E, const Expr *Child) {
+  if (isa(E))
+return true;
+
+  if (isa(E))
+return true;
+
+  if (isa(E))
+return true;
+
+  if (isa(E))
+return true;
+
+  if (isa(E))
+return true;
+
+  if (isa(E))
+return true;
+
+  auto SR = Child->getSourceRange();
+
+  if (const auto *C = dyn_cast(E)) {
+if (C->getSourceRange() == SR || !isa(C))
+  return true;
+  }
+
+  if (const auto *C = dyn_cast(E)) {
+if (C->getSourceRange() == SR)
+  return true;
+  }
+
+  if (const auto *C = dyn_cast(E)) {
+if (C->getSourceRange() == SR)
+  return true;
+  }
+  return false;
+};
+
+while (ShouldSkip(E, Child)) {
+  auto It = PointerParents.find(E);
+  if (It == PointerParents.end())
+break;
+  const auto *S = It->second.dyn_cast();
+  if (!S)
+return getSingleDynTypedNodeFromParentMap(It->second);
+  const auto *P = dyn_cast(S);
+  if (!P)
+return ast_type_traits::DynTypedNode::create(*S);
+  Child = E;
+  E = P;
+}
+return ast_type_traits::DynTypedNode::create(*E);
+  }
 };
 
 /// Template specializations to abstract away from pointers and TypeLocs.
@@ -151,8 +219,7 @@ createDynTypedNode(const NestedNameSpecifierLoc &Node) {
 class ParentMapContext::ParentMap::ASTVisitor
 : public RecursiveASTVisitor {
 public:
-  ASTVisitor(ParentMap &Map, ParentMapContext &MapCtx)
-  : Map(Map), MapCtx(MapCtx) {}
+  ASTVisitor(ParentMap &Map) : Map(Map) {}
 
 private:
   friend class RecursiveASTVisitor;
@@ -222,11 +289,8 @@ class ParentMapContext::ParentMap::ASTVisitor
   }
 
   bool TraverseStmt(Stmt *StmtNode) {
-Stmt *FilteredNode = StmtNode;
-if (auto *ExprNode = dyn_cast_or_null(FilteredNode))
-  FilteredNode = MapCtx.traverseIgnored(ExprNode);
-  

[PATCH] D73434: [Sema] Remove a -Wrange warning from -Wall

2020-01-26 Thread pre-merge checks [bot] via Phabricator via cfe-commits
merge_guards_bot added a comment.

{icon check-circle color=green} Unit tests: pass. 62197 tests passed, 0 failed 
and 815 were skipped.

{icon check-circle color=green} clang-tidy: pass.

{icon times-circle color=red} clang-format: fail. Please format your changes 
with clang-format by running `git-clang-format HEAD^` or applying this patch 
.

Build artifacts 
: 
diff.json 
,
 clang-tidy.txt 
,
 clang-format.patch 
,
 CMakeCache.txt 
,
 console-log.txt 
,
 test-results.xml 


//Pre-merge checks is in beta. Report issue 
.
 Please join beta  or enable 
it for your project 
.//


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73434



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


[PATCH] D73434: [Sema] Remove a -Wrange warning from -Wall

2020-01-26 Thread Mark de Wever via Phabricator via cfe-commits
Mordante created this revision.
Mordante added reviewers: aaron.ballman, aaronpuchert, rtrieu, xbolva00.
Mordante added a project: clang.

During the review of D73007  Aaron Puchert 
mentioned `warn_for_range_variable_always_copy` shouldn't be part of `-Wall` 
since some coding styles require `for(const auto &bar : bars)`. This warning 
would cause false positives for these users. Based on Aaron's proposal 
refactored the warnings:

- `-Wrange-loop-construct` warns about possibly unintended constructor calls. 
This is part of `-Wall`. It contains
  - `warn_for_range_copy`: loop variable A of type B creates a copy from type C
  - `warn_for_range_const_reference_copy`: loop variable A is initialized with 
a value of a different type resulting in a copy
- `-Wrange-loop-bind-reference` warns about misleading use of reference types. 
This is not part of `-Wall`. It contains
  - `warn_for_range_variable_always_copy`: loop variable A is always a copy 
because the range of type B does not return a reference

Note the patch is intended to be backported to clang 11, thus the release notes 
aren't updated.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D73434

Files:
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/test/Misc/warning-wall.c
  clang/test/SemaCXX/warn-range-loop-analysis.cpp


Index: clang/test/SemaCXX/warn-range-loop-analysis.cpp
===
--- clang/test/SemaCXX/warn-range-loop-analysis.cpp
+++ clang/test/SemaCXX/warn-range-loop-analysis.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -std=c++11 -Wall -Wno-unused -verify %s
+// RUN: %clang_cc1 -fsyntax-only -std=c++11 -Wall -Wrange-loop-bind-reference 
-Wno-unused -verify %s
 // RUN: %clang_cc1 -fsyntax-only -std=c++11 -Wloop-analysis -verify %s
 // RUN: %clang_cc1 -fsyntax-only -std=c++11 -Wrange-loop-analysis -verify %s
 // RUN: %clang_cc1 -fsyntax-only -std=c++11 -Wloop-analysis 
-fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
Index: clang/test/Misc/warning-wall.c
===
--- clang/test/Misc/warning-wall.c
+++ clang/test/Misc/warning-wall.c
@@ -15,14 +15,12 @@
 CHECK-NEXT:  -Wformat-security
 CHECK-NEXT:  -Wformat-y2k
 CHECK-NEXT:  -Wformat-invalid-specifier
+CHECK-NEXT:-Wfor-loop-analysis
 CHECK-NEXT:-Wimplicit
 CHECK-NEXT:  -Wimplicit-function-declaration
 CHECK-NEXT:  -Wimplicit-int
 CHECK-NEXT:-Winfinite-recursion
 CHECK-NEXT:-Wint-in-bool-context
-CHECK-NEXT:-Wloop-analysis
-CHECK-NEXT:  -Wfor-loop-analysis
-CHECK-NEXT:  -Wrange-loop-analysis
 CHECK-NEXT:-Wmismatched-tags
 CHECK-NEXT:-Wmissing-braces
 CHECK-NEXT:-Wmove
@@ -31,6 +29,7 @@
 CHECK-NEXT:  -Wreturn-std-move
 CHECK-NEXT:  -Wself-move
 CHECK-NEXT:-Wmultichar
+CHECK-NEXT:-Wrange-loop-construct
 CHECK-NEXT:-Wreorder
 CHECK-NEXT:  -Wreorder-ctor
 CHECK-NEXT:  -Wreorder-init-list
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -2381,17 +2381,17 @@
   "loop variable %0 "
   "%diff{has type $ but is initialized with type $"
   "| is initialized with a value of a different type}1,2 resulting in a copy">,
-  InGroup, DefaultIgnore;
+  InGroup, DefaultIgnore;
 def note_use_type_or_non_reference : Note<
   "use non-reference type %0 to keep the copy or type %1 to prevent copying">;
 def warn_for_range_variable_always_copy : Warning<
   "loop variable %0 is always a copy because the range of type %1 does not "
   "return a reference">,
-  InGroup, DefaultIgnore;
+  InGroup, DefaultIgnore;
 def note_use_non_reference_type : Note<"use non-reference type %0">;
 def warn_for_range_copy : Warning<
   "loop variable %0 of type %1 creates a copy from type %2">,
-  InGroup, DefaultIgnore;
+  InGroup, DefaultIgnore;
 def note_use_reference_type : Note<"use reference type %0 to prevent copying">;
 def err_objc_for_range_init_stmt : Error<
   "initialization statement is not supported when iterating over Objective-C "
Index: clang/include/clang/Basic/DiagnosticGroups.td
===
--- clang/include/clang/Basic/DiagnosticGroups.td
+++ clang/include/clang/Basic/DiagnosticGroups.td
@@ -384,7 +384,10 @@
 def LiteralRange : DiagGroup<"literal-range">;
 def LocalTypeTemplateArgs : DiagGroup<"local-type-template-args",
   [CXX98CompatLocalTypeTemplateArgs]>;
-def RangeLoopAnalysis : DiagGroup<"range-loop-analysis">;
+def RangeLoopConstruct : DiagGroup<"range-loop-construct">;
+def RangeLoopBindReference : DiagGroup<"range-loop-bind-reference">;
+def RangeLoopAnalysis : DiagGroup<"range-loop-analysis",
+ 

[PATCH] D73007: [Sema] Avoid Wrange-loop-analysis false positives

2020-01-26 Thread Mark de Wever via Phabricator via cfe-commits
Mordante added a comment.

Created D73434 .


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73007



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


[PATCH] D72331: OpaquePtr: add type to inalloca attribute.

2020-01-26 Thread Reid Kleckner via Phabricator via cfe-commits
rnk accepted this revision.
rnk added a comment.

lgtm, thanks!

I remember reading through this last week, but apparently I did not hit send. 
This patch actually prompted me to start working on the replacement for this 
thing.


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

https://reviews.llvm.org/D72331



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


[PATCH] D71966: [Wdocumentation][RFC] Improve identifier's of \param

2020-01-26 Thread Mark de Wever via Phabricator via cfe-commits
Mordante marked 2 inline comments as done.
Mordante added a comment.

So if I understand correctly:

- `getParamNameAsWritten` will become `getArgText`
- The `getParamName` will do the translation from the name in the documentation 
to the name in the current function declaration. If the parameter index is 
invalid the function will fail (with an assertion error) and not fallback to 
call `getArgText`.




Comment at: clang/include/clang-c/Documentation.h:383
 CINDEX_LINKAGE
-CXString clang_ParamCommandComment_getParamName(CXComment Comment);
 

gribozavr2 wrote:
> Mordante wrote:
> > gribozavr2 wrote:
> > > Please don't modify existing APIs in libclang -- it provides a stable API 
> > > and ABI, and what has shipped, can't be changed. New functionality has to 
> > > be exposed as new functions, while old functions should be kept working 
> > > to the extent possible. It means that the resulting API can be subpar, 
> > > but oh well, a stable ABI is a contract of libclang.
> > I thought I had read this API was allowed to change, but required adding 
> > information to the release notes. (I can't find it quickly.)
> > I'll undo the changes to the existing functions and add new functions 
> > instead.
> > I thought I had read this API was allowed to change
> 
> It would be interesting to find that doc. As far as I understand, libclang 
> has a strict API & ABI stability rule.
> 
> > I'll undo the changes to the existing functions and add new functions 
> > instead.
> 
> Thanks!
> 
>> I thought I had read this API was allowed to change
> It would be interesting to find that doc. As far as I understand, libclang 
> has a strict API & ABI stability rule.
My interpretation of http://llvm.org/docs/DeveloperPolicy.html#c-api-changes 
gave me this impression.


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

https://reviews.llvm.org/D71966



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


[PATCH] D73007: [Sema] Avoid Wrange-loop-analysis false positives

2020-01-26 Thread Mark de Wever via Phabricator via cfe-commits
Mordante added a comment.

@aaronpuchert, @aaron.ballman I agree with the proposal, I'll work on a patch.

@hans Once the patch is accepted I'll send you a pull request and an update for 
the release notes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73007



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


[PATCH] D73108: [docs][mips] 10.0 Release notes

2020-01-26 Thread Simon Atanasyan via Phabricator via cfe-commits
atanasyan closed this revision.
atanasyan added a comment.

Closed by commit rG27f93515 
.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73108



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


[PATCH] D65994: Extended FPOptions with new attributes

2020-01-26 Thread Serge Pavlov via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG4aea70ed3292: [FPEnv] Extended FPOptions with new attributes 
(authored by sepavloff).

Changed prior to commit:
  https://reviews.llvm.org/D65994?vs=239893&id=240432#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D65994

Files:
  clang/include/clang/AST/Stmt.h
  clang/include/clang/Basic/LangOptions.h
  clang/include/clang/Sema/Sema.h
  clang/lib/Parse/ParseStmt.cpp
  clang/lib/Sema/SemaAttr.cpp
  clang/lib/Sema/TreeTransform.h

Index: clang/lib/Sema/TreeTransform.h
===
--- clang/lib/Sema/TreeTransform.h
+++ clang/lib/Sema/TreeTransform.h
@@ -9938,7 +9938,7 @@
   RHS.get() == E->getRHS())
 return E;
 
-  Sema::FPContractStateRAII FPContractState(getSema());
+  Sema::FPFeaturesStateRAII FPFeaturesState(getSema());
   getSema().FPFeatures = E->getFPFeatures();
 
   return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
@@ -10464,7 +10464,7 @@
   (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
 return SemaRef.MaybeBindToTemporary(E);
 
-  Sema::FPContractStateRAII FPContractState(getSema());
+  Sema::FPFeaturesStateRAII FPFeaturesState(getSema());
   getSema().FPFeatures = E->getFPFeatures();
 
   return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
Index: clang/lib/Sema/SemaAttr.cpp
===
--- clang/lib/Sema/SemaAttr.cpp
+++ clang/lib/Sema/SemaAttr.cpp
@@ -940,6 +940,14 @@
   }
 }
 
+void Sema::setRoundingMode(LangOptions::FPRoundingModeKind FPR) {
+  FPFeatures.setRoundingMode(FPR);
+}
+
+void Sema::setExceptionMode(LangOptions::FPExceptionModeKind FPE) {
+  FPFeatures.setExceptionMode(FPE);
+}
+
 void Sema::ActOnPragmaFEnvAccess(LangOptions::FEnvAccessModeKind FPC) {
   switch (FPC) {
   case LangOptions::FEA_On:
Index: clang/lib/Parse/ParseStmt.cpp
===
--- clang/lib/Parse/ParseStmt.cpp
+++ clang/lib/Parse/ParseStmt.cpp
@@ -1014,9 +1014,9 @@
 Tok.getLocation(),
 "in compound statement ('{}')");
 
-  // Record the state of the FP_CONTRACT pragma, restore on leaving the
+  // Record the state of the FPFeatures, restore on leaving the
   // compound statement.
-  Sema::FPContractStateRAII SaveFPContractState(Actions);
+  Sema::FPFeaturesStateRAII SaveFPContractState(Actions);
 
   InMessageExpressionRAIIObject InMessage(*this, false);
   BalancedDelimiterTracker T(*this, tok::l_brace);
Index: clang/include/clang/Sema/Sema.h
===
--- clang/include/clang/Sema/Sema.h
+++ clang/include/clang/Sema/Sema.h
@@ -1306,12 +1306,12 @@
   /// should not be used elsewhere.
   void EmitCurrentDiagnostic(unsigned DiagID);
 
-  /// Records and restores the FP_CONTRACT state on entry/exit of compound
+  /// Records and restores the FPFeatures state on entry/exit of compound
   /// statements.
-  class FPContractStateRAII {
+  class FPFeaturesStateRAII {
   public:
-FPContractStateRAII(Sema &S) : S(S), OldFPFeaturesState(S.FPFeatures) {}
-~FPContractStateRAII() { S.FPFeatures = OldFPFeaturesState; }
+FPFeaturesStateRAII(Sema &S) : S(S), OldFPFeaturesState(S.FPFeatures) {}
+~FPFeaturesStateRAII() { S.FPFeatures = OldFPFeaturesState; }
 
   private:
 Sema& S;
@@ -9409,6 +9409,12 @@
   /// \#pragma STDC FENV_ACCESS
   void ActOnPragmaFEnvAccess(LangOptions::FEnvAccessModeKind FPC);
 
+  /// Called to set rounding mode for floating point operations.
+  void setRoundingMode(LangOptions::FPRoundingModeKind);
+
+  /// Called to set exception behavior for floating point operations.
+  void setExceptionMode(LangOptions::FPExceptionModeKind);
+
   /// AddAlignmentAttributesForRecord - Adds any needed alignment attributes to
   /// a the record decl, to handle '\#pragma pack' and '\#pragma options align'.
   void AddAlignmentAttributesForRecord(RecordDecl *RD);
Index: clang/include/clang/Basic/LangOptions.h
===
--- clang/include/clang/Basic/LangOptions.h
+++ clang/include/clang/Basic/LangOptions.h
@@ -357,17 +357,25 @@
 class FPOptions {
 public:
   FPOptions() : fp_contract(LangOptions::FPC_Off),
-fenv_access(LangOptions::FEA_Off) {}
+fenv_access(LangOptions::FEA_Off),
+rounding(LangOptions::FPR_ToNearest),
+exceptions(LangOptions::FPE_Ignore)
+{}
 
   // Used for serializing.
   explicit FPOptions(unsigned I)
   : fp_contract(static_cast(I & 3)),
-fenv_access(static_cast((I >> 2) & 1))
+fenv_access(static_cast((I >> 2) & 1)),
+rounding(static_cast((I >> 3) & 7)),
+exceptions(static_cast((I >> 6) & 3))

[clang] 4aea70e - [FPEnv] Extended FPOptions with new attributes

2020-01-26 Thread Serge Pavlov via cfe-commits

Author: Serge Pavlov
Date: 2020-01-26T21:03:53+07:00
New Revision: 4aea70ed3292f02aa111ff6894805e2613dd81e8

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

LOG: [FPEnv] Extended FPOptions with new attributes

This change added two new attributes, rounding mode and exception
behavior to the structure FPOptions. These attributes allow more
flexible treatment of specific floating point environment than it is
provided by #pragma STDC FENV_ACCESS.

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

Added: 


Modified: 
clang/include/clang/AST/Stmt.h
clang/include/clang/Basic/LangOptions.h
clang/include/clang/Sema/Sema.h
clang/lib/Parse/ParseStmt.cpp
clang/lib/Sema/SemaAttr.cpp
clang/lib/Sema/TreeTransform.h

Removed: 




diff  --git a/clang/include/clang/AST/Stmt.h b/clang/include/clang/AST/Stmt.h
index 253b76941991..0b29857c37e3 100644
--- a/clang/include/clang/AST/Stmt.h
+++ b/clang/include/clang/AST/Stmt.h
@@ -530,7 +530,7 @@ class alignas(void *) Stmt {
 
 /// This is only meaningful for operations on floating point
 /// types and 0 otherwise.
-unsigned FPFeatures : 3;
+unsigned FPFeatures : 8;
 
 SourceLocation OpLoc;
   };
@@ -601,7 +601,7 @@ class alignas(void *) Stmt {
 unsigned OperatorKind : 6;
 
 // Only meaningful for floating point types.
-unsigned FPFeatures : 3;
+unsigned FPFeatures : 8;
   };
 
   class CXXRewrittenBinaryOperatorBitfields {

diff  --git a/clang/include/clang/Basic/LangOptions.h 
b/clang/include/clang/Basic/LangOptions.h
index ae4a4b2b9e87..524ae9a822f4 100644
--- a/clang/include/clang/Basic/LangOptions.h
+++ b/clang/include/clang/Basic/LangOptions.h
@@ -357,17 +357,25 @@ class LangOptions : public LangOptionsBase {
 class FPOptions {
 public:
   FPOptions() : fp_contract(LangOptions::FPC_Off),
-fenv_access(LangOptions::FEA_Off) {}
+fenv_access(LangOptions::FEA_Off),
+rounding(LangOptions::FPR_ToNearest),
+exceptions(LangOptions::FPE_Ignore)
+{}
 
   // Used for serializing.
   explicit FPOptions(unsigned I)
   : fp_contract(static_cast(I & 3)),
-fenv_access(static_cast((I >> 2) & 1))
+fenv_access(static_cast((I >> 2) & 
1)),
+rounding(static_cast((I >> 3) & 7)),
+exceptions(static_cast((I >> 6) & 3))
 {}
 
   explicit FPOptions(const LangOptions &LangOpts)
   : fp_contract(LangOpts.getDefaultFPContractMode()),
-fenv_access(LangOptions::FEA_Off) {}
+fenv_access(LangOptions::FEA_Off),
+rounding(LangOptions::FPR_ToNearest),
+exceptions(LangOptions::FPE_Ignore)
+{}
   // FIXME: Use getDefaultFEnvAccessMode() when available.
 
   bool allowFPContractWithinStatement() const {
@@ -398,14 +406,42 @@ class FPOptions {
 
   void setDisallowFEnvAccess() { fenv_access = LangOptions::FEA_Off; }
 
+  LangOptions::FPRoundingModeKind getRoundingMode() const {
+return static_cast(rounding);
+  }
+
+  void setRoundingMode(LangOptions::FPRoundingModeKind RM) {
+rounding = RM;
+  }
+
+  LangOptions::FPExceptionModeKind getExceptionMode() const {
+return static_cast(exceptions);
+  }
+
+  void setExceptionMode(LangOptions::FPExceptionModeKind EM) {
+exceptions = EM;
+  }
+
+  bool isFPConstrained() const {
+return getRoundingMode() != LangOptions::FPR_ToNearest ||
+   getExceptionMode() != LangOptions::FPE_Ignore ||
+   allowFEnvAccess();
+  }
+
   /// Used to serialize this.
-  unsigned getInt() const { return fp_contract | (fenv_access << 2); }
+  unsigned getInt() const {
+return fp_contract | (fenv_access << 2) | (rounding << 3)
+| (exceptions << 6);
+  }
 
 private:
-  /// Adjust BinaryOperator::FPFeatures to match the total bit-field size
-  /// of these two.
+  /// Adjust BinaryOperatorBitfields::FPFeatures and
+  /// CXXOperatorCallExprBitfields::FPFeatures to match the total bit-field 
size
+  /// of these fields.
   unsigned fp_contract : 2;
   unsigned fenv_access : 1;
+  unsigned rounding : 3;
+  unsigned exceptions : 2;
 };
 
 /// Describes the kind of translation unit being processed.

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 64a6793aa411..5a33e4aa6ffc 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -1306,12 +1306,12 @@ class Sema final {
   /// should not be used elsewhere.
   void EmitCurrentDiagnostic(unsigned DiagID);
 
-  /// Records and restores the FP_CONTRACT state on entry/exit of compound
+  /// Records and restores the FPFeatures state on entry/exit of compound
   /// statements.
-  class FPContractStateRAII {
+  class FPFeaturesStateRAII {
   public:
-FPContractStateRAII(Sema &S) : S(S), OldFP