[clang] ac47588 - [Driver] Add negative option for -fkeep-static-consts

2020-06-03 Thread Shengchen Kan via cfe-commits

Author: Shengchen Kan
Date: 2020-06-03T14:59:14+08:00
New Revision: ac47588bc4ff5927a01ed6fcd269ce86aba52a7c

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

LOG: [Driver] Add negative option for -fkeep-static-consts

Added: 


Modified: 
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/Clang.cpp

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index b807febe1d44..05a9121592ef 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -988,8 +988,7 @@ def fsignaling_math : Flag<["-"], "fsignaling-math">, 
Group;
 def fno_signaling_math : Flag<["-"], "fno-signaling-math">, Group;
 defm jump_tables : OptOutFFlag<"jump-tables", "Use", "Do not use", " jump 
tables for lowering switches">;
 defm force_enable_int128 : OptInFFlag<"force-enable-int128", "Enable", 
"Disable", " support for int128_t type">;
-def fkeep_static_consts : Flag<["-"], "fkeep-static-consts">, Group, 
Flags<[CC1Option]>,
-  HelpText<"Keep static const variables even if unused">;
+defm keep_static_consts : OptInFFlag<"keep-static-consts", "Keep", "Don't 
keep", " static const variables if unused", [DriverOption]>;
 def ffixed_point : Flag<["-"], "ffixed-point">, Group,
Flags<[CC1Option]>, HelpText<"Enable fixed point types">;
 def fno_fixed_point : Flag<["-"], "fno-fixed-point">, Group,

diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index d86fe499d69e..b20048768e44 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -5175,7 +5175,6 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
   Args.AddLastArg(CmdArgs, options::OPT_fno_operator_names);
   Args.AddLastArg(CmdArgs, options::OPT_femulated_tls,
   options::OPT_fno_emulated_tls);
-  Args.AddLastArg(CmdArgs, options::OPT_fkeep_static_consts);
 
   // AltiVec-like language extensions aren't relevant for assembling.
   if (!isa(JA) || Output.getType() != types::TY_PP_Asm)
@@ -6118,6 +6117,10 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
   CmdArgs.push_back("-fforce-enable-int128");
   }
 
+  if (Args.hasFlag(options::OPT_fkeep_static_consts,
+   options::OPT_fno_keep_static_consts, false))
+CmdArgs.push_back("-fkeep-static-consts");
+
   if (Args.hasFlag(options::OPT_fcomplete_member_pointers,
options::OPT_fno_complete_member_pointers, false))
 CmdArgs.push_back("-fcomplete-member-pointers");



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


[PATCH] D81008: [AST] Record SourceLocation for TypoExpr.

2020-06-03 Thread Haojian Wu via Phabricator via cfe-commits
hokein added inline comments.



Comment at: clang/include/clang/AST/Expr.h:6158
 public:
-  TypoExpr(QualType T) : Expr(TypoExprClass, T, VK_LValue, OK_Ordinary) {
+  TypoExpr(QualType T, SourceLocation Start, SourceLocation End)
+  : Expr(TypoExprClass, T, VK_LValue, OK_Ordinary), Start(Start), End(End) 
{

sammccall wrote:
> can we have Start != End in practice?
> 
> Looking at DeclarationNameInfo::getEndLocPrivate(), it seems like this only 
> happens in operators, literal-operators, conversions, 
> constructors/destructors.
> 
> If these don't actually support typo correction maybe we should just use one 
> location?
ah, yes, I missed this.

typo correction only supports identifiers, so Start and End are always the same.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81008



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


[PATCH] D79912: Assignment and Inc/Dec operators wouldn't register as a mutation when Implicit Paren Casts were present

2020-06-03 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr2 accepted this revision.
gribozavr2 added a comment.
This revision is now accepted and ready to land.

Nice find, thank you for the fix!


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

https://reviews.llvm.org/D79912



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


[PATCH] D77168: Add a flag to debug automatic variable initialization

2020-06-03 Thread Luis Lozano via Phabricator via cfe-commits
llozano added a comment.

In D77168#2070083 , @MaskRay wrote:

> In D77168#2070049 , @jcai19 wrote:
>
> > In D77168#2069783 , @MaskRay wrote:
> >
> > > Do we have a mechanism bisecting pragmas? If yes, we can let that tool 
> > > add `#pragma clang attribute push([[clang::uninitialized]], apply_to = 
> > > variable)`
> >
> >
> > Not that I am aware of unfortunately. The whole point of having this patch 
> > is to add the ability to bisect programmatically, along the approach of 
> > using pragma as introduced in https://reviews.llvm.org/D78693.
>
>
> If we have a mechanism bisecting pragmas, this option will not be needed.


I think you are coming late into the discussion. If you read before, We had 
already agreed that having mechanisms for automatic triaging is "very 
compelling". The change suggested here just makes automatic triaging much 
easier at a very low cost.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77168



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


[PATCH] D81019: Syntax tree: ignore implicit expressions at the top level of statements

2020-06-03 Thread Marcel Hlopko via Phabricator via cfe-commits
hlopko accepted this revision.
hlopko added a comment.
This revision is now accepted and ready to land.

LGTM :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81019



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


[PATCH] D81040: Split syntax tree tests into more granular ones

2020-06-03 Thread Marcel Hlopko via Phabricator via cfe-commits
hlopko accepted this revision.
hlopko added a comment.

Thanks for working on this! :)




Comment at: clang/unittests/Tooling/Syntax/TreeTest.cpp:2066
+int func3b(int *);
+int func4(int a, float b);
+int func4a(int, float);

func4 -> func4a
func4a -> func4b?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81040



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


[clang-tools-extra] 65fa0a9 - [clang-tidy] Added MacroDefiniton docs for readability-identifier-naming

2020-06-03 Thread Nathan James via cfe-commits

Author: Nathan James
Date: 2020-06-03T09:23:32+01:00
New Revision: 65fa0a9f7f3e6090e335c14f9edea19358d87613

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

LOG: [clang-tidy] Added MacroDefiniton docs for readability-identifier-naming

Updates the docs to include `MacroDefinition` documentation. The docs are still 
missing `ObjCIVar` however I don't have a clue about how that looks in code. If 
someone wants to show the code block needed for the example I'll add that in 
too.

Reviewed By: aaron.ballman

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

Added: 


Modified: 
clang-tools-extra/docs/clang-tidy/checks/readability-identifier-naming.rst

Removed: 




diff  --git 
a/clang-tools-extra/docs/clang-tidy/checks/readability-identifier-naming.rst 
b/clang-tools-extra/docs/clang-tidy/checks/readability-identifier-naming.rst
index 3d0cbca69f6d..eefa5234fb21 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/readability-identifier-naming.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/readability-identifier-naming.rst
@@ -62,6 +62,7 @@ The following options are describe below:
  - :option:`LocalConstantPointerCase`, :option:`LocalConstantPointerPrefix`, 
:option:`LocalConstantPointerSuffix`
  - :option:`LocalPointerCase`, :option:`LocalPointerPrefix`, 
:option:`LocalPointerSuffix`
  - :option:`LocalVariableCase`, :option:`LocalVariablePrefix`, 
:option:`LocalVariableSuffix`
+ - :option:`MacroDefinitionCase`, :option:`MacroDefinitionPrefix`, 
:option:`MacroDefinitionSuffix`
  - :option:`MemberCase`, :option:`MemberPrefix`, :option:`MemberSuffix`
  - :option:`MethodCase`, :option:`MethodPrefix`, :option:`MethodSuffix`
  - :option:`NamespaceCase`, :option:`NamespacePrefix`, 
:option:`NamespaceSuffix`
@@ -1076,6 +1077,44 @@ After:
 
 void foo() { int pre_local_constant_post; }
 
+.. option:: MacroDefinitionCase
+
+When defined, the check will ensure macro definitions conform to the
+selected casing.
+
+.. option:: MacroDefinitionPrefix
+
+When defined, the check will ensure macro definitions will add the
+prefixed with the given value (regardless of casing).
+
+.. option:: MacroDefinitionSuffix
+
+When defined, the check will ensure macro definitions will add the
+suffix with the given value (regardless of casing).
+
+For example using values of:
+
+   - MacroDefinitionCase of ``lower_case``
+   - MacroDefinitionPrefix of ``pre_``
+   - MacroDefinitionSuffix of ``_post``
+
+Identifies and/or transforms macro definitions as follows:
+
+Before:
+
+.. code-block:: c
+
+#define MY_MacroDefinition
+
+After:
+
+.. code-block:: c
+
+#define pre_my_macro_definition_post
+
+Note: This will not warn on builtin macros or macros defined on the command 
line
+using the ``-D`` flag.
+
 .. option:: MemberCase
 
 When defined, the check will ensure member names conform to the



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


[PATCH] D79912: Assignment and Inc/Dec operators wouldn't register as a mutation when Implicit Paren Casts were present

2020-06-03 Thread Nathan James via Phabricator via cfe-commits
njames93 accepted this revision.
njames93 added a comment.

LGTM, but I wouldn't say no to a test case using `(Limit) -= 1`.


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

https://reviews.llvm.org/D79912



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


[PATCH] D81061: [Analyzer][VLASizeChecker] Fix problem with zero index assumption.

2020-06-03 Thread Balázs Kéri via Phabricator via cfe-commits
balazske created this revision.
Herald added subscribers: cfe-commits, ASDenysPetrov, martong, Charusso, 
gamesh411, dkrupp, donat.nagy, Szelethus, arphaman, mikhail.ramalho, a.sidorin, 
szepet, baloghadamsoftware, xazax.hun.
Herald added a reviewer: Szelethus.
Herald added a project: clang.
balazske added reviewers: vabridgers, NoQ.
balazske added a comment.

There may be still a problem somewhere else. I think assume of "a" and "a==0" 
should have the same results.


See https://bugs.llvm.org/show_bug.cgi?id=46128
The crash was caused by incorect assumptions on `a` and `a + 1`
that resulted in knowing something about `a` (that it is exactly -1)
and only knowing about `a + 1` that it is non-zero.

  "constraints": [
{ "symbol": "reg_$0", "range": "{ [-1, -1] }" },
{ "symbol": "(reg_$0) + 1", "range": "{ [-2147483648, -1], [1, 
2147483647] }" }
  ],

The problem was fixed by replacing plain assume on symbol with assume on
binary operator (test for "a==0" instead of "a").
An additional check was inserted at place of the assertion to prevent
similar crashes.

A test that triggers this last case is missing now.
The added test causes no problem because at start of the second loop
"c" can not be zero because the previous assumption made by the checker
(that did not work correct before the fix).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D81061

Files:
  clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp
  clang/test/Analysis/vla.c


Index: clang/test/Analysis/vla.c
===
--- clang/test/Analysis/vla.c
+++ clang/test/Analysis/vla.c
@@ -137,3 +137,17 @@
   clang_analyzer_eval(clang_analyzer_getExtent(&vla3m) == 2 * x * 4 * 
sizeof(int));
   // expected-warning@-1{{TRUE}}
 }
+
+// https://bugs.llvm.org/show_bug.cgi?id=46128
+// Analyzer doesn't handle more than simple symbolic expressions correct.
+// Just don't crash.
+extern void foo(void);
+int a;
+void b() {
+  int c = a + 1;
+  for (;;) {
+int d[c];
+for (; 0 < c;)
+  foo();
+  }
+} // no-crash
Index: clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp
@@ -122,11 +122,19 @@
   return State;
 
 if (const llvm::APSInt *IndexLVal = SVB.getKnownValue(State, IndexLength)) 
{
+  uint64_t IndexL = IndexLVal->getZExtValue();
+  if (IndexL == 0) {
+// Despite the previous assumptions for non-zero and positiveness,
+// this value might be zero or negative.
+// At least check for zero again.
+// Assume that this is a more exact fact than the previous assumptions
+// (in checkVLAIndexSize), so report error too.
+reportBug(VLA_Zero, SizeE, State, C);
+return nullptr;
+  }
   // Check if the array size will overflow.
   // Size overflow check does not work with symbolic expressions because a
   // overflow situation can not be detected easily.
-  uint64_t IndexL = IndexLVal->getZExtValue();
-  assert(IndexL > 0 && "Index length should have been checked for zero.");
   if (KnownSize <= SizeMax / IndexL) {
 KnownSize *= IndexL;
   } else {
@@ -166,33 +174,33 @@
 return nullptr;
   }
 
-  // Check if the size is zero.
+  QualType SizeTy = SizeE->getType();
   DefinedSVal SizeD = SizeV.castAs();
+  SValBuilder &SVB = C.getSValBuilder();
+  DefinedOrUnknownSVal Zero = SVB.makeZeroVal(SizeTy);
+
+  // Check if the size is zero.
 
-  ProgramStateRef StateNotZero, StateZero;
-  std::tie(StateNotZero, StateZero) = State->assume(SizeD);
+  SVal IsZeroVal = SVB.evalBinOp(State, BO_EQ, SizeD, Zero, SizeTy);
+  if (Optional IsZeroDVal = IsZeroVal.getAs()) {
+ProgramStateRef StateZero, StateNotZero;
 
-  if (StateZero && !StateNotZero) {
-reportBug(VLA_Zero, SizeE, StateZero, C);
-return nullptr;
+std::tie(StateZero, StateNotZero) = State->assume(*IsZeroDVal);
+if (StateZero && !StateNotZero) {
+  reportBug(VLA_Zero, SizeE, State, C);
+  return nullptr;
+}
+State = StateNotZero;
   }
 
-  // From this point on, assume that the size is not zero.
-  State = StateNotZero;
-
   // Check if the size is negative.
-  SValBuilder &SVB = C.getSValBuilder();
-
-  QualType SizeTy = SizeE->getType();
-  DefinedOrUnknownSVal Zero = SVB.makeZeroVal(SizeTy);
 
   SVal LessThanZeroVal = SVB.evalBinOp(State, BO_LT, SizeD, Zero, SizeTy);
   if (Optional LessThanZeroDVal =
   LessThanZeroVal.getAs()) {
-ConstraintManager &CM = C.getConstraintManager();
 ProgramStateRef StatePos, StateNeg;
 
-std::tie(StateNeg, StatePos) = CM.assumeDual(State, *LessThanZeroDVal);
+std::tie(StateNeg, StatePos) = State->assume(*LessThanZeroDVal);
 if (StateNeg && !StatePos) {
   reportBug(VLA_Negative, SizeE, State, C);
   return nullptr;


Index: clang/tes

[PATCH] D80903: [analyzer] Ignore calculated indices of <= 0 in VLASizeChecker

2020-06-03 Thread Balázs Kéri via Phabricator via cfe-commits
balazske added a comment.

Here is an improved fix for the problem: D81061 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80903



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


[PATCH] D81019: Syntax tree: ignore implicit expressions at the top level of statements

2020-06-03 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas accepted this revision.
eduucaldas added inline comments.



Comment at: clang/lib/Tooling/Syntax/BuildTree.cpp:1048
+  syntax::Tree *ChildNode;
+  if (Expr *ChildExpr = dyn_cast(Child)) {
+// This is an expression in a statement position, consume the trailing

I thought this treatement of derived class should be done by 
RecursiveASTVisitor 
This is kinda the task of WalkUpFrom*, unfortunately WalkUpFromThis follows the 
order:
WalkUpFromBase;
VisitThis;

And we would've wanted the opposite order:
VisitThis
WalkUpFromBase



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81019



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


[PATCH] D81061: [Analyzer][VLASizeChecker] Fix problem with zero index assumption.

2020-06-03 Thread Balázs Kéri via Phabricator via cfe-commits
balazske added a comment.

There may be still a problem somewhere else. I think assume of "a" and "a==0" 
should have the same results.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81061



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


[PATCH] D80366: [Analyzer] Add `getReturnValueUnderConstruction()` to `CallEvent`

2020-06-03 Thread Balogh , Ádám via Phabricator via cfe-commits
baloghadamsoftware updated this revision to Diff 268082.
baloghadamsoftware added a comment.

Updated according to the comments.


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

https://reviews.llvm.org/D80366

Files:
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
  clang/lib/StaticAnalyzer/Core/CallEvent.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
  clang/unittests/StaticAnalyzer/CMakeLists.txt
  clang/unittests/StaticAnalyzer/TestReturnValueUnderConstruction.cpp

Index: clang/unittests/StaticAnalyzer/TestReturnValueUnderConstruction.cpp
===
--- /dev/null
+++ clang/unittests/StaticAnalyzer/TestReturnValueUnderConstruction.cpp
@@ -0,0 +1,76 @@
+//===- unittests/StaticAnalyzer/TestReturnValueUnderConstruction.cpp --===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "CheckerRegistration.h"
+#include "clang/StaticAnalyzer/Core/Checker.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
+#include "clang/StaticAnalyzer/Frontend/AnalysisConsumer.h"
+#include "clang/StaticAnalyzer/Frontend/CheckerRegistry.h"
+#include "clang/Tooling/Tooling.h"
+#include "gtest/gtest.h"
+
+namespace clang {
+namespace ento {
+namespace {
+
+class TestReturnValueUnderConstructionChecker
+  : public Checker {
+public:
+  void checkPostCall(const CallEvent &Call, CheckerContext &C) const {
+// We are checking the invocation of `returnC` which returns an object
+// by value.
+const IdentifierInfo *ID = Call.getCalleeIdentifier();
+if (ID->getName() != "returnC")
+  return;
+
+// Since `returnC` returns an object by value, the invocation results
+// in an object of type `C` constructed into variable `c`. Thus the
+// return value of `CallEvent::getReturnValueUnderConstruction()` must
+// be non-empty and has to be a `MemRegion`.
+Optional RetVal =
+  Call.getReturnValueUnderConstruction(C.blockCount());
+ASSERT_TRUE(RetVal);
+ASSERT_TRUE(RetVal->getAsRegion());
+  }
+};
+
+void addTestReturnValueUnderConstructionChecker(
+AnalysisASTConsumer &AnalysisConsumer, AnalyzerOptions &AnOpts) {
+  AnOpts.CheckersAndPackages =
+{{"test.TestReturnValueUnderConstruction", true}};
+  AnalysisConsumer.AddCheckerRegistrationFn([](CheckerRegistry &Registry) {
+  Registry.addChecker(
+  "test.TestReturnValueUnderConstruction", "", "");
+});
+}
+
+TEST(TestReturnValueUnderConstructionChecker,
+ ReturnValueUnderConstructionChecker) {
+  EXPECT_TRUE(runCheckerOnCode(
+  R"(class C {
+ public:
+   C(int nn): n(nn) {}
+   virtual ~C() {}
+ private:
+   int n;
+ };
+
+ C returnC(int m) {
+   C c(m);
+   return c;
+ }
+
+ void foo() {
+   C c = returnC(1); 
+ })"));
+}
+
+} // namespace
+} // namespace ento
+} // namespace clang
Index: clang/unittests/StaticAnalyzer/CMakeLists.txt
===
--- clang/unittests/StaticAnalyzer/CMakeLists.txt
+++ clang/unittests/StaticAnalyzer/CMakeLists.txt
@@ -7,10 +7,11 @@
   AnalyzerOptionsTest.cpp
   CallDescriptionTest.cpp
   CallEventTest.cpp
-  StoreTest.cpp
+  RangeSetTest.cpp
   RegisterCustomCheckersTest.cpp
+  StoreTest.cpp 
   SymbolReaperTest.cpp
-  RangeSetTest.cpp
+  TestReturnValueUnderConstruction.cpp
   )
 
 clang_target_link_libraries(StaticAnalysisTests
Index: clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
===
--- clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
+++ clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
@@ -109,15 +109,14 @@
   return LValue;
 }
 
-std::pair ExprEngine::handleConstructionContext(
+SVal ExprEngine::computeObjectUnderConstruction(
 const Expr *E, ProgramStateRef State, const LocationContext *LCtx,
 const ConstructionContext *CC, EvalCallOptions &CallOpts) {
   SValBuilder &SVB = getSValBuilder();
   MemRegionManager &MRMgr = SVB.getRegionManager();
   ASTContext &ACtx = SVB.getContext();
 
-  // See if we're constructing an existing region by looking at the
-  // current construction context.
+  // Compute the target region by exploring the construction context.
   if (CC) {
 switch (CC->getKind()) {
 case ConstructionContext::CXX17ElidedCopyVariableKind:
@@ -125,13 +124,9 @@

[PATCH] D80877: [clang-tidy] Added MacroDefiniton docs for readability-identifier-naming

2020-06-03 Thread Nathan James via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG65fa0a9f7f3e: [clang-tidy] Added MacroDefiniton docs for 
readability-identifier-naming (authored by njames93).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80877

Files:
  clang-tools-extra/docs/clang-tidy/checks/readability-identifier-naming.rst


Index: 
clang-tools-extra/docs/clang-tidy/checks/readability-identifier-naming.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/readability-identifier-naming.rst
+++ clang-tools-extra/docs/clang-tidy/checks/readability-identifier-naming.rst
@@ -62,6 +62,7 @@
  - :option:`LocalConstantPointerCase`, :option:`LocalConstantPointerPrefix`, 
:option:`LocalConstantPointerSuffix`
  - :option:`LocalPointerCase`, :option:`LocalPointerPrefix`, 
:option:`LocalPointerSuffix`
  - :option:`LocalVariableCase`, :option:`LocalVariablePrefix`, 
:option:`LocalVariableSuffix`
+ - :option:`MacroDefinitionCase`, :option:`MacroDefinitionPrefix`, 
:option:`MacroDefinitionSuffix`
  - :option:`MemberCase`, :option:`MemberPrefix`, :option:`MemberSuffix`
  - :option:`MethodCase`, :option:`MethodPrefix`, :option:`MethodSuffix`
  - :option:`NamespaceCase`, :option:`NamespacePrefix`, 
:option:`NamespaceSuffix`
@@ -1076,6 +1077,44 @@
 
 void foo() { int pre_local_constant_post; }
 
+.. option:: MacroDefinitionCase
+
+When defined, the check will ensure macro definitions conform to the
+selected casing.
+
+.. option:: MacroDefinitionPrefix
+
+When defined, the check will ensure macro definitions will add the
+prefixed with the given value (regardless of casing).
+
+.. option:: MacroDefinitionSuffix
+
+When defined, the check will ensure macro definitions will add the
+suffix with the given value (regardless of casing).
+
+For example using values of:
+
+   - MacroDefinitionCase of ``lower_case``
+   - MacroDefinitionPrefix of ``pre_``
+   - MacroDefinitionSuffix of ``_post``
+
+Identifies and/or transforms macro definitions as follows:
+
+Before:
+
+.. code-block:: c
+
+#define MY_MacroDefinition
+
+After:
+
+.. code-block:: c
+
+#define pre_my_macro_definition_post
+
+Note: This will not warn on builtin macros or macros defined on the command 
line
+using the ``-D`` flag.
+
 .. option:: MemberCase
 
 When defined, the check will ensure member names conform to the


Index: clang-tools-extra/docs/clang-tidy/checks/readability-identifier-naming.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/readability-identifier-naming.rst
+++ clang-tools-extra/docs/clang-tidy/checks/readability-identifier-naming.rst
@@ -62,6 +62,7 @@
  - :option:`LocalConstantPointerCase`, :option:`LocalConstantPointerPrefix`, :option:`LocalConstantPointerSuffix`
  - :option:`LocalPointerCase`, :option:`LocalPointerPrefix`, :option:`LocalPointerSuffix`
  - :option:`LocalVariableCase`, :option:`LocalVariablePrefix`, :option:`LocalVariableSuffix`
+ - :option:`MacroDefinitionCase`, :option:`MacroDefinitionPrefix`, :option:`MacroDefinitionSuffix`
  - :option:`MemberCase`, :option:`MemberPrefix`, :option:`MemberSuffix`
  - :option:`MethodCase`, :option:`MethodPrefix`, :option:`MethodSuffix`
  - :option:`NamespaceCase`, :option:`NamespacePrefix`, :option:`NamespaceSuffix`
@@ -1076,6 +1077,44 @@
 
 void foo() { int pre_local_constant_post; }
 
+.. option:: MacroDefinitionCase
+
+When defined, the check will ensure macro definitions conform to the
+selected casing.
+
+.. option:: MacroDefinitionPrefix
+
+When defined, the check will ensure macro definitions will add the
+prefixed with the given value (regardless of casing).
+
+.. option:: MacroDefinitionSuffix
+
+When defined, the check will ensure macro definitions will add the
+suffix with the given value (regardless of casing).
+
+For example using values of:
+
+   - MacroDefinitionCase of ``lower_case``
+   - MacroDefinitionPrefix of ``pre_``
+   - MacroDefinitionSuffix of ``_post``
+
+Identifies and/or transforms macro definitions as follows:
+
+Before:
+
+.. code-block:: c
+
+#define MY_MacroDefinition
+
+After:
+
+.. code-block:: c
+
+#define pre_my_macro_definition_post
+
+Note: This will not warn on builtin macros or macros defined on the command line
+using the ``-D`` flag.
+
 .. option:: MemberCase
 
 When defined, the check will ensure member names conform to the
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D80366: [Analyzer] Add `getReturnValueUnderConstruction()` to `CallEvent`

2020-06-03 Thread Balogh , Ádám via Phabricator via cfe-commits
baloghadamsoftware marked 9 inline comments as done.
baloghadamsoftware added inline comments.



Comment at: clang/lib/StaticAnalyzer/Core/CallEvent.cpp:552
+
+  Index = StackFrame->getIndex();
+

vsavchenko wrote:
> Szelethus wrote:
> > baloghadamsoftware wrote:
> > > Szelethus wrote:
> > > > This mustn't be serious. `StackFrameContext::getIndex()` has **no 
> > > > comments** at all! So it is an index to the element within a `CFGBlock` 
> > > > to which it also stores a field for??? Ugh. Shouldn't we just have a 
> > > > `getCallSiteCFGElement` or something? Especially since we have 
> > > > `CFGElementRef`s now.
> > > > 
> > > > Would you be so nice to hunt this down please? :)
> > > Do you mean a new `StackFrameContext::getCFGElement()` member function? I 
> > > agree. I can do it, however this technology where we get the block and 
> > > the index separately is used at many places in the code, then it would be 
> > > appropriate to refactor all these places. Even wrose is the backward 
> > > direction, where we look for the CFG element of a statement: we find the 
> > > block from `CFGStmtMap` and then we search for the index **liearly**, 
> > > instrad of storing it in the map as well!!!
> > Nasty. Yeah, I mean not to burden you work refactoring any more then you 
> > feel like doing it, but simply adding a 
> > `StackFrameContext::getCFGElement()` method and using it in this patch 
> > would be nice enough, and some comments to `getIndex()`. But this obviously 
> > isn't a high prio issue.
> +1
> I do believe that clearer interface functions and better segregation of 
> different functionalities will make it much easier for us in the future
I fully agree, but StackFrameContext is not in the StaticAnalyzer part, but the 
Analysis part. I think that should be a separate patch. Who is the code owner 
for that part?



Comment at: clang/lib/StaticAnalyzer/Core/CallEvent.cpp:553
+
+  if(const auto Ctor = (*Block)[Index].getAs()) {
+return Ctor->getConstructionContext();

vsavchenko wrote:
> nit: space after `if`
> 
> And I would also prefer putting `const auto *Ctor`
`Ctor` is not a pointer, but an `llvm::Optional`.


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

https://reviews.llvm.org/D80366



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


[clang] b34b769 - Syntax tree: ignore implicit expressions at the top level of statements

2020-06-03 Thread Dmitri Gribenko via cfe-commits

Author: Dmitri Gribenko
Date: 2020-06-03T10:58:12+02:00
New Revision: b34b7691facd89022e7fee174debdbd2bf7920f3

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

LOG: Syntax tree: ignore implicit expressions at the top level of statements

Summary:
I changed `markStmtChild` to ignore implicit expressions the same way as
`markExprChild` does it already. The test that I modified crashes
without this change.

Reviewers: hlopko, eduucaldas

Reviewed By: hlopko, eduucaldas

Subscribers: gribozavr2, cfe-commits

Tags: #clang

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

Added: 


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

Removed: 




diff  --git a/clang/lib/Tooling/Syntax/BuildTree.cpp 
b/clang/lib/Tooling/Syntax/BuildTree.cpp
index 2b312cdde1d6..1c473d872034 100644
--- a/clang/lib/Tooling/Syntax/BuildTree.cpp
+++ b/clang/lib/Tooling/Syntax/BuildTree.cpp
@@ -1044,17 +1044,18 @@ void syntax::TreeBuilder::markStmtChild(Stmt *Child, 
NodeRole Role) {
   if (!Child)
 return;
 
-  syntax::Tree *ChildNode = Mapping.find(Child);
-  assert(ChildNode != nullptr);
-
-  // This is an expression in a statement position, consume the trailing
-  // semicolon and form an 'ExpressionStatement' node.
-  if (isa(Child)) {
-setRole(ChildNode, NodeRole::ExpressionStatement_expression);
+  syntax::Tree *ChildNode;
+  if (Expr *ChildExpr = dyn_cast(Child)) {
+// This is an expression in a statement position, consume the trailing
+// semicolon and form an 'ExpressionStatement' node.
+markExprChild(ChildExpr, NodeRole::ExpressionStatement_expression);
 ChildNode = new (allocator()) syntax::ExpressionStatement;
 // (!) 'getStmtRange()' ensures this covers a trailing semicolon.
 Pending.foldChildren(Arena, getStmtRange(Child), ChildNode);
+  } else {
+ChildNode = Mapping.find(Child);
   }
+  assert(ChildNode != nullptr);
   setRole(ChildNode, Role);
 }
 

diff  --git a/clang/unittests/Tooling/Syntax/TreeTest.cpp 
b/clang/unittests/Tooling/Syntax/TreeTest.cpp
index a7de4b909cb4..0592d8f44b4e 100644
--- a/clang/unittests/Tooling/Syntax/TreeTest.cpp
+++ b/clang/unittests/Tooling/Syntax/TreeTest.cpp
@@ -705,20 +705,16 @@ void test(int a) {
 }
 
 TEST_P(SyntaxTreeTest, PrefixUnaryOperator) {
-  if (!GetParam().isCXX()) {
-// TODO: Split parts that depend on C++ into a separate test.
-return;
-  }
   expectTreeDumpEqual(
   R"cpp(
-void test(int a, int *ap, bool b) {
+void test(int a, int *ap) {
   --a; ++a;
-  ~a; compl a;
+  ~a;
   -a;
   +a;
   &a;
   *ap;
-  !b; not b;
+  !a;
   __real a; __imag a;
 }
 )cpp",
@@ -740,11 +736,6 @@ void test(int a, int *ap, bool b) {
   |   | `-SimpleDeclarator
   |   |   |-*
   |   |   `-ap
-  |   |-,
-  |   |-SimpleDeclaration
-  |   | |-bool
-  |   | `-SimpleDeclarator
-  |   |   `-b
   |   `-)
   `-CompoundStatement
 |-{
@@ -768,12 +759,6 @@ void test(int a, int *ap, bool b) {
 | `-;
 |-ExpressionStatement
 | |-PrefixUnaryOperatorExpression
-| | |-compl
-| | `-UnknownExpression
-| |   `-a
-| `-;
-|-ExpressionStatement
-| |-PrefixUnaryOperatorExpression
 | | |--
 | | `-UnknownExpression
 | |   `-a
@@ -800,26 +785,67 @@ void test(int a, int *ap, bool b) {
 | |-PrefixUnaryOperatorExpression
 | | |-!
 | | `-UnknownExpression
-| |   `-b
+| |   `-a
 | `-;
 |-ExpressionStatement
 | |-PrefixUnaryOperatorExpression
-| | |-not
+| | |-__real
 | | `-UnknownExpression
-| |   `-b
+| |   `-a
 | `-;
 |-ExpressionStatement
 | |-PrefixUnaryOperatorExpression
-| | |-__real
+| | |-__imag
 | | `-UnknownExpression
 | |   `-a
 | `-;
+`-}
+)txt");
+}
+
+TEST_P(SyntaxTreeTest, PrefixUnaryOperatorCxx) {
+  if (!GetParam().isCXX()) {
+return;
+  }
+  expectTreeDumpEqual(
+  R"cpp(
+void test(int a, bool b) {
+  compl a;
+  not b;
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarator
+  | |-test
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   |-SimpleDeclaration
+  |   | |-int
+  |   | `-SimpleDeclarator
+  |   |   `-a
+  |   |-,
+  |   |-SimpleDeclaration
+  |   | |-bool
+  |   | `-SimpleDeclarator
+  |   |   `-b
+  |   `-)
+  `-CompoundStatement
+|-{
 |-ExpressionStatement
 | |-PrefixUnaryOperatorExpression
-| | |-__imag
+| | |-compl
 | | `-UnknownExpression
 | |   `-a
 | `-;
+|-ExpressionStatement
+| |-PrefixUnaryOperatorExpression
+| | |-not
+| | `-UnknownExpression
+| |   `-b
+| `-;
 `-}
 )txt");
 }



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.o

[PATCH] D81066: [clangd] Populate the parse options to CodeCompletion/SignatureHelp.

2020-06-03 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
hokein added a reviewer: sammccall.
Herald added subscribers: usaxena95, kadircet, arphaman, jkorous, MaskRay, 
ilya-biryukov.
Herald added a project: clang.

A followup of D79938 .


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D81066

Files:
  clang-tools-extra/clangd/ClangdServer.cpp
  clang-tools-extra/clangd/CodeComplete.cpp
  clang-tools-extra/clangd/CodeComplete.h
  clang-tools-extra/clangd/Compiler.h
  clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp

Index: clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
===
--- clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
+++ clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
@@ -117,8 +117,11 @@
   }
   auto Preamble = buildPreamble(testPath(TU.Filename), *CI, Inputs,
 /*InMemory=*/true, /*Callback=*/nullptr);
-  return codeComplete(testPath(TU.Filename), Inputs.CompileCommand,
-  Preamble.get(), TU.Code, Point, Inputs.FS, Opts);
+  ParseInputs ParseInput{Inputs.CompileCommand, Inputs.FS, TU.Code};
+  ParseInput.Opts.BuildRecoveryAST = true;
+  ParseInput.Opts.PreserveRecoveryASTType = true;
+  return codeComplete(testPath(TU.Filename), Point, Preamble.get(), ParseInput,
+  Opts);
 }
 
 // Runs code completion.
@@ -148,8 +151,10 @@
 
   MockFSProvider FS;
   Annotations Test(Text);
-  return codeComplete(FilePath, tooling::CompileCommand(), /*Preamble=*/nullptr,
-  Test.code(), Test.point(), FS.getFileSystem(), Opts);
+  ParseInputs ParseInput{tooling::CompileCommand(), FS.getFileSystem(),
+ Test.code().str()};
+  return codeComplete(FilePath, Test.point(), /*Preamble=*/nullptr, ParseInput,
+  Opts);
 }
 
 Symbol withReferences(int N, Symbol S) {
@@ -753,8 +758,7 @@
   EXPECT_THAT(Results, ElementsAre(Named("ifndef")));
 }
 
-// FIXME: enable it.
-TEST(CompletionTest, DISABLED_CompletionRecoveryASTType) {
+TEST(CompletionTest, CompletionRecoveryASTType) {
   auto Results = completions(R"cpp(
 struct S { int member; };
 S overloaded(int);
@@ -1067,8 +1071,11 @@
 ADD_FAILURE() << "Couldn't build Preamble";
 return {};
   }
-  return signatureHelp(testPath(TU.Filename), Inputs.CompileCommand, *Preamble,
-   Text, Point, Inputs.FS, Index.get());
+  ParseInputs ParseInput{Inputs.CompileCommand, Inputs.FS, Text.str()};
+  ParseInput.Index = Index.get();
+  ParseInput.Opts.BuildRecoveryAST = true;
+  ParseInput.Opts.PreserveRecoveryASTType = true;
+  return signatureHelp(testPath(TU.Filename), Point, *Preamble, ParseInput);
 }
 
 SignatureHelp signatures(llvm::StringRef Text,
@@ -1219,9 +1226,10 @@
 void bar() { foo(^2); })cpp");
   TU.Code = Test.code().str();
   Inputs = TU.inputs();
-  auto Results =
-  signatureHelp(testPath(TU.Filename), Inputs.CompileCommand,
-*EmptyPreamble, TU.Code, Test.point(), Inputs.FS, nullptr);
+
+  ParseInputs ParseInput{Inputs.CompileCommand, Inputs.FS, TU.Code};
+  auto Results = signatureHelp(testPath(TU.Filename), Test.point(),
+   *EmptyPreamble, ParseInput);
   EXPECT_THAT(Results.signatures, ElementsAre(Sig("foo([[int x]]) -> int")));
   EXPECT_EQ(0, Results.activeSignature);
   EXPECT_EQ(0, Results.activeParameter);
Index: clang-tools-extra/clangd/Compiler.h
===
--- clang-tools-extra/clangd/Compiler.h
+++ clang-tools-extra/clangd/Compiler.h
@@ -54,7 +54,7 @@
   bool ForceRebuild = false;
   // Used to recover from diagnostics (e.g. find missing includes for symbol).
   const SymbolIndex *Index = nullptr;
-  ParseOptions Opts;
+  ParseOptions Opts = ParseOptions();
 };
 
 /// Builds compiler invocation that could be used to build AST or preamble.
Index: clang-tools-extra/clangd/CodeComplete.h
===
--- clang-tools-extra/clangd/CodeComplete.h
+++ clang-tools-extra/clangd/CodeComplete.h
@@ -270,21 +270,16 @@
 /// the speculative result is used by code completion (e.g. speculation failed),
 /// the speculative result is not consumed, and `SpecFuzzyFind` is only
 /// destroyed when the async request finishes.
-CodeCompleteResult codeComplete(PathRef FileName,
-const tooling::CompileCommand &Command,
+CodeCompleteResult codeComplete(PathRef FileName, Position Pos,
 const PreambleData *Preamble,
-StringRef Contents, Position Pos,
-IntrusiveRefCntPtr VFS,
+const ParseInputs &ParseInput,
 CodeCompleteOptions Opts,
 SpeculativeFuzzyFind *SpecFuzzyFind = nullptr);
 
 /// Get signature help at a s

[PATCH] D81040: Split syntax tree tests into more granular ones

2020-06-03 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr2 added inline comments.



Comment at: clang/unittests/Tooling/Syntax/TreeTest.cpp:2066
+int func3b(int *);
+int func4(int a, float b);
+int func4a(int, float);

hlopko wrote:
> func4 -> func4a
> func4a -> func4b?
Fixed, thanks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81040



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


[PATCH] D81019: Syntax tree: ignore implicit expressions at the top level of statements

2020-06-03 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr2 added inline comments.



Comment at: clang/lib/Tooling/Syntax/BuildTree.cpp:1048
+  syntax::Tree *ChildNode;
+  if (Expr *ChildExpr = dyn_cast(Child)) {
+// This is an expression in a statement position, consume the trailing

eduucaldas wrote:
> I thought this treatement of derived class should be done by 
> RecursiveASTVisitor 
> This is kinda the task of WalkUpFrom*, unfortunately WalkUpFromThis follows 
> the order:
> WalkUpFromBase;
> VisitThis;
> 
> And we would've wanted the opposite order:
> VisitThis
> WalkUpFromBase
> 
Unfortunately I don't see how to implement this behavior (cheaply) in the 
visitation methods of RecursiveASTVisitor. The crux of the issue is that we are 
inserting a syntax tree node (ExpressionStatement) that does not correspond to 
any semantic AST node. We want to do it for every Expr that appears in a Stmt 
position -- so we need to know the parent node, or in this case, more 
precisely, that this Expr node is in a Stmt position.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81019



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


[PATCH] D81069: [clangd] Don't build diagnostics when preparing AST for a normal action.

2020-06-03 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.
sammccall added a reviewer: kadircet.
Herald added subscribers: cfe-commits, usaxena95, jfb, arphaman, jkorous, 
MaskRay, javed.absar, ilya-biryukov.
Herald added a project: clang.

This saves something like 20% latency on the AST build with a typical load of
clang-tidy checks.
The tradeoff is the AST is never cached for diagnostics, but this is less
latency sensitive and rarely happens anyway.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D81069

Files:
  clang-tools-extra/clangd/ParsedAST.cpp
  clang-tools-extra/clangd/ParsedAST.h
  clang-tools-extra/clangd/TUScheduler.cpp
  clang-tools-extra/clangd/TUScheduler.h
  clang-tools-extra/clangd/test/metrics.test
  clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
  clang-tools-extra/clangd/unittests/PreambleTests.cpp
  clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp
  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
@@ -84,8 +84,9 @@
   auto Preamble = clang::clangd::buildPreamble(testPath(Filename), *CI, Inputs,
/*StoreInMemory=*/true,
/*PreambleCallback=*/nullptr);
-  auto AST = ParsedAST::build(testPath(Filename), Inputs, std::move(CI),
-  Diags.take(), Preamble);
+  auto AST =
+  ParsedAST::build(testPath(Filename), Inputs, std::move(CI),
+   /*ProduceDiagnostics=*/true, Diags.take(), Preamble);
   if (!AST.hasValue()) {
 ADD_FAILURE() << "Failed to build code:\n" << Code;
 llvm_unreachable("Failed to build TestTU!");
Index: clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp
===
--- clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp
+++ clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp
@@ -521,7 +521,6 @@
 }
 
 TEST_F(TUSchedulerTests, EvictedAST) {
-  std::atomic BuiltASTCounter(0);
   auto Opts = optsForTest();
   Opts.AsyncThreadsCount = 1;
   Opts.RetentionPolicy.MaxRetainedASTs = 2;
@@ -532,52 +531,45 @@
 int* a;
 double* b = a;
   )cpp";
-  llvm::StringLiteral OtherSourceContents = R"cpp(
-int* a;
-double* b = a + 0;
-  )cpp";
 
   auto Foo = testPath("foo.cpp");
   auto Bar = testPath("bar.cpp");
   auto Baz = testPath("baz.cpp");
 
-  EXPECT_THAT(Tracer.takeMetric("ast_access_diag", "hit"), SizeIs(0));
-  EXPECT_THAT(Tracer.takeMetric("ast_access_diag", "miss"), SizeIs(0));
-  // Build one file in advance. We will not access it later, so it will be the
-  // one that the cache will evict.
-  updateWithCallback(S, Foo, SourceContents, WantDiagnostics::Yes,
- [&BuiltASTCounter]() { ++BuiltASTCounter; });
+  // Build one file in advance.
+  S.update(Foo, getInputs(Foo, SourceContents.str()), WantDiagnostics::Yes);
   ASSERT_TRUE(S.blockUntilIdle(timeoutSeconds(10)));
-  ASSERT_EQ(BuiltASTCounter.load(), 1);
-  EXPECT_THAT(Tracer.takeMetric("ast_access_diag", "hit"), SizeIs(0));
-  EXPECT_THAT(Tracer.takeMetric("ast_access_diag", "miss"), SizeIs(1));
-
-  // Build two more files. Since we can retain only 2 ASTs, these should be
-  // the ones we see in the cache later.
-  updateWithCallback(S, Bar, SourceContents, WantDiagnostics::Yes,
- [&BuiltASTCounter]() { ++BuiltASTCounter; });
-  updateWithCallback(S, Baz, SourceContents, WantDiagnostics::Yes,
- [&BuiltASTCounter]() { ++BuiltASTCounter; });
+  // AST should be cached after diagnostics are produced.
+  ASSERT_THAT(S.getFilesWithCachedAST(), UnorderedElementsAre(Foo));
+
+  // Build two more files.
+  S.update(Bar, getInputs(Foo, SourceContents.str()), WantDiagnostics::Yes);
+  S.update(Baz, getInputs(Foo, SourceContents.str()), WantDiagnostics::Yes);
   ASSERT_TRUE(S.blockUntilIdle(timeoutSeconds(10)));
-  ASSERT_EQ(BuiltASTCounter.load(), 3);
-  EXPECT_THAT(Tracer.takeMetric("ast_access_diag", "hit"), SizeIs(0));
-  EXPECT_THAT(Tracer.takeMetric("ast_access_diag", "miss"), SizeIs(2));
+  // We can retain only 2 ASTs, Foo should have been evicted.
+  ASSERT_THAT(S.getFilesWithCachedAST(), UnorderedElementsAre(Bar, Baz));
 
-  // Check only the last two ASTs are retained.
+  // No reads yet.
+  EXPECT_THAT(Tracer.takeMetric("ast_access_read", "hit"), SizeIs(0));
+  EXPECT_THAT(Tracer.takeMetric("ast_access_read", "miss"), SizeIs(0));
+
+  // Run action on file in AST cache.
+  S.runWithAST("Cached", Bar,
+   [](llvm::Expected E) { EXPECT_TRUE(bool(E)); });
+  ASSERT_TRUE(S.blockUntilIdle(timeoutSeconds(10)));
+  // Should have hit the cache, same files still present.
   ASSERT_THAT(S.getFilesWithCachedAST(), UnorderedElementsAre(Bar, Baz));
+  EXPECT_THAT(Tracer.takeMetric("ast_access_read", "hit"), S

[PATCH] D81040: Split syntax tree tests into more granular ones

2020-06-03 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr updated this revision to Diff 268100.
gribozavr added a comment.

Refreshing this patch after pushing the patch that this one depends on.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81040

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

Index: clang/unittests/Tooling/Syntax/TreeTest.cpp
===
--- clang/unittests/Tooling/Syntax/TreeTest.cpp
+++ clang/unittests/Tooling/Syntax/TreeTest.cpp
@@ -64,6 +64,11 @@
Language == Lang_CXX17 || Language == Lang_CXX20;
   }
 
+  bool supportsCXXDynamicExceptionSpecification() const {
+return Language == Lang_CXX03 || Language == Lang_CXX11 ||
+   Language == Lang_CXX14;
+  }
+
   bool hasDelayedTemplateParsing() const {
 return Target == "x86_64-pc-win32-msvc";
   }
@@ -851,10 +856,6 @@
 }
 
 TEST_P(SyntaxTreeTest, BinaryOperator) {
-  if (!GetParam().isCXX()) {
-// TODO: Split parts that depend on C++ into a separate test.
-return;
-  }
   expectTreeDumpEqual(
   R"cpp(
 void test(int a) {
@@ -862,15 +863,9 @@
   1 == 2;
   a = 1;
   a <<= 1;
-
-  true || false;
-  true or false;
-
+  1 || 0;
   1 & 2;
-  1 bitand 2;
-
   a ^= 3;
-  a xor_eq 3;
 }
 )cpp",
   R"txt(
@@ -923,42 +918,82 @@
 |-ExpressionStatement
 | |-BinaryOperatorExpression
 | | |-UnknownExpression
-| | | `-true
+| | | `-1
 | | |-||
 | | `-UnknownExpression
-| |   `-false
+| |   `-0
 | `-;
 |-ExpressionStatement
 | |-BinaryOperatorExpression
 | | |-UnknownExpression
-| | | `-true
-| | |-or
+| | | `-1
+| | |-&
 | | `-UnknownExpression
-| |   `-false
+| |   `-2
 | `-;
 |-ExpressionStatement
 | |-BinaryOperatorExpression
 | | |-UnknownExpression
-| | | `-1
-| | |-&
+| | | `-a
+| | |-^=
 | | `-UnknownExpression
-| |   `-2
+| |   `-3
 | `-;
+`-}
+)txt");
+}
+
+TEST_P(SyntaxTreeTest, BinaryOperatorCxx) {
+  if (!GetParam().isCXX()) {
+return;
+  }
+  expectTreeDumpEqual(
+  R"cpp(
+void test(int a) {
+  true || false;
+  true or false;
+  1 bitand 2;
+  a xor_eq 3;
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarator
+  | |-test
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   |-SimpleDeclaration
+  |   | |-int
+  |   | `-SimpleDeclarator
+  |   |   `-a
+  |   `-)
+  `-CompoundStatement
+|-{
 |-ExpressionStatement
 | |-BinaryOperatorExpression
 | | |-UnknownExpression
-| | | `-1
-| | |-bitand
+| | | `-true
+| | |-||
 | | `-UnknownExpression
-| |   `-2
+| |   `-false
 | `-;
 |-ExpressionStatement
 | |-BinaryOperatorExpression
 | | |-UnknownExpression
-| | | `-a
-| | |-^=
+| | | `-true
+| | |-or
 | | `-UnknownExpression
-| |   `-3
+| |   `-false
+| `-;
+|-ExpressionStatement
+| |-BinaryOperatorExpression
+| | |-UnknownExpression
+| | | `-1
+| | |-bitand
+| | `-UnknownExpression
+| |   `-2
 | `-;
 |-ExpressionStatement
 | |-BinaryOperatorExpression
@@ -2017,21 +2052,202 @@
   `-;   )txt");
 }
 
-TEST_P(SyntaxTreeTest, ParameterListsInDeclarators) {
+TEST_P(SyntaxTreeTest, ParametersAndQualifiersInFreeFunctions) {
+  if (!GetParam().isCXX()) {
+return;
+  }
+  expectTreeDumpEqual(
+  R"cpp(
+int func1();
+int func2a(int a);
+int func2b(int);
+int func3a(int *ap);
+int func3b(int *);
+int func4(int a, float b);
+int func4a(int, float);
+  )cpp",
+  R"txt(
+*: TranslationUnit
+|-SimpleDeclaration
+| |-int
+| |-SimpleDeclarator
+| | |-func1
+| | `-ParametersAndQualifiers
+| |   |-(
+| |   `-)
+| `-;
+|-SimpleDeclaration
+| |-int
+| |-SimpleDeclarator
+| | |-func2a
+| | `-ParametersAndQualifiers
+| |   |-(
+| |   |-SimpleDeclaration
+| |   | |-int
+| |   | `-SimpleDeclarator
+| |   |   `-a
+| |   `-)
+| `-;
+|-SimpleDeclaration
+| |-int
+| |-SimpleDeclarator
+| | |-func2b
+| | `-ParametersAndQualifiers
+| |   |-(
+| |   |-SimpleDeclaration
+| |   | `-int
+| |   `-)
+| `-;
+|-SimpleDeclaration
+| |-int
+| |-SimpleDeclarator
+| | |-func3a
+| | `-ParametersAndQualifiers
+| |   |-(
+| |   |-SimpleDeclaration
+| |   | |-int
+| |   | `-SimpleDeclarator
+| |   |   |-*
+| |   |   `-ap
+| |   `-)
+| `-;
+|-SimpleDeclaration
+| |-int
+| |-SimpleDeclarator
+| | |-func3b
+| | `-ParametersAndQualifiers
+| |   |-(
+| |   |-SimpleDeclaration
+| |   | |-int
+| |   | `-SimpleDeclarator
+| |   |   `-*
+| |   `-)
+| `-;
+|-SimpleDeclaration
+| |-int
+| |-SimpleDeclarator
+| | |-func4
+| | `-ParametersAndQualifiers
+| |   |-(
+| |   |-SimpleDeclaration
+| |   | |-int
+| |   | `-SimpleDeclarator
+| |   |   `-a
+| |   |-,
+| |   |-SimpleDeclaration
+| |   | |-float
+| |   | `-SimpleDeclarator
+| |   |   `-b
+| |   `-)
+| `-;
+`-SimpleDeclaration
+  |-int
+  |-SimpleDeclarator
+  | |-func4a
+  | 

[PATCH] D81019: Syntax tree: ignore implicit expressions at the top level of statements

2020-06-03 Thread Dmitri Gribenko via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGb34b7691facd: Syntax tree: ignore implicit expressions at 
the top level of statements (authored by gribozavr).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81019

Files:
  clang/lib/Tooling/Syntax/BuildTree.cpp
  clang/unittests/Tooling/Syntax/TreeTest.cpp

Index: clang/unittests/Tooling/Syntax/TreeTest.cpp
===
--- clang/unittests/Tooling/Syntax/TreeTest.cpp
+++ clang/unittests/Tooling/Syntax/TreeTest.cpp
@@ -705,20 +705,16 @@
 }
 
 TEST_P(SyntaxTreeTest, PrefixUnaryOperator) {
-  if (!GetParam().isCXX()) {
-// TODO: Split parts that depend on C++ into a separate test.
-return;
-  }
   expectTreeDumpEqual(
   R"cpp(
-void test(int a, int *ap, bool b) {
+void test(int a, int *ap) {
   --a; ++a;
-  ~a; compl a;
+  ~a;
   -a;
   +a;
   &a;
   *ap;
-  !b; not b;
+  !a;
   __real a; __imag a;
 }
 )cpp",
@@ -740,11 +736,6 @@
   |   | `-SimpleDeclarator
   |   |   |-*
   |   |   `-ap
-  |   |-,
-  |   |-SimpleDeclaration
-  |   | |-bool
-  |   | `-SimpleDeclarator
-  |   |   `-b
   |   `-)
   `-CompoundStatement
 |-{
@@ -768,12 +759,6 @@
 | `-;
 |-ExpressionStatement
 | |-PrefixUnaryOperatorExpression
-| | |-compl
-| | `-UnknownExpression
-| |   `-a
-| `-;
-|-ExpressionStatement
-| |-PrefixUnaryOperatorExpression
 | | |--
 | | `-UnknownExpression
 | |   `-a
@@ -800,26 +785,67 @@
 | |-PrefixUnaryOperatorExpression
 | | |-!
 | | `-UnknownExpression
-| |   `-b
+| |   `-a
 | `-;
 |-ExpressionStatement
 | |-PrefixUnaryOperatorExpression
-| | |-not
+| | |-__real
 | | `-UnknownExpression
-| |   `-b
+| |   `-a
 | `-;
 |-ExpressionStatement
 | |-PrefixUnaryOperatorExpression
-| | |-__real
+| | |-__imag
 | | `-UnknownExpression
 | |   `-a
 | `-;
+`-}
+)txt");
+}
+
+TEST_P(SyntaxTreeTest, PrefixUnaryOperatorCxx) {
+  if (!GetParam().isCXX()) {
+return;
+  }
+  expectTreeDumpEqual(
+  R"cpp(
+void test(int a, bool b) {
+  compl a;
+  not b;
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarator
+  | |-test
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   |-SimpleDeclaration
+  |   | |-int
+  |   | `-SimpleDeclarator
+  |   |   `-a
+  |   |-,
+  |   |-SimpleDeclaration
+  |   | |-bool
+  |   | `-SimpleDeclarator
+  |   |   `-b
+  |   `-)
+  `-CompoundStatement
+|-{
 |-ExpressionStatement
 | |-PrefixUnaryOperatorExpression
-| | |-__imag
+| | |-compl
 | | `-UnknownExpression
 | |   `-a
 | `-;
+|-ExpressionStatement
+| |-PrefixUnaryOperatorExpression
+| | |-not
+| | `-UnknownExpression
+| |   `-b
+| `-;
 `-}
 )txt");
 }
Index: clang/lib/Tooling/Syntax/BuildTree.cpp
===
--- clang/lib/Tooling/Syntax/BuildTree.cpp
+++ clang/lib/Tooling/Syntax/BuildTree.cpp
@@ -1044,17 +1044,18 @@
   if (!Child)
 return;
 
-  syntax::Tree *ChildNode = Mapping.find(Child);
-  assert(ChildNode != nullptr);
-
-  // This is an expression in a statement position, consume the trailing
-  // semicolon and form an 'ExpressionStatement' node.
-  if (isa(Child)) {
-setRole(ChildNode, NodeRole::ExpressionStatement_expression);
+  syntax::Tree *ChildNode;
+  if (Expr *ChildExpr = dyn_cast(Child)) {
+// This is an expression in a statement position, consume the trailing
+// semicolon and form an 'ExpressionStatement' node.
+markExprChild(ChildExpr, NodeRole::ExpressionStatement_expression);
 ChildNode = new (allocator()) syntax::ExpressionStatement;
 // (!) 'getStmtRange()' ensures this covers a trailing semicolon.
 Pending.foldChildren(Arena, getStmtRange(Child), ChildNode);
+  } else {
+ChildNode = Mapping.find(Child);
   }
+  assert(ChildNode != nullptr);
   setRole(ChildNode, Role);
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] d7d5dd3 - Split syntax tree tests into more granular ones

2020-06-03 Thread Dmitri Gribenko via cfe-commits

Author: Dmitri Gribenko
Date: 2020-06-03T11:17:11+02:00
New Revision: d7d5dd31fc6f05daf4758e1523c86401aa4e3f2a

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

LOG: Split syntax tree tests into more granular ones

Summary:
Doing so allows us to increase test coverage by removing unnecessary
language restrictions.

Reviewers: hlopko, eduucaldas

Reviewed By: hlopko, eduucaldas

Subscribers: gribozavr2, cfe-commits

Tags: #clang

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

Added: 


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

Removed: 




diff  --git a/clang/unittests/Tooling/Syntax/TreeTest.cpp 
b/clang/unittests/Tooling/Syntax/TreeTest.cpp
index 0592d8f44b4e..24943acf733e 100644
--- a/clang/unittests/Tooling/Syntax/TreeTest.cpp
+++ b/clang/unittests/Tooling/Syntax/TreeTest.cpp
@@ -64,6 +64,11 @@ struct TestClangConfig {
Language == Lang_CXX17 || Language == Lang_CXX20;
   }
 
+  bool supportsCXXDynamicExceptionSpecification() const {
+return Language == Lang_CXX03 || Language == Lang_CXX11 ||
+   Language == Lang_CXX14;
+  }
+
   bool hasDelayedTemplateParsing() const {
 return Target == "x86_64-pc-win32-msvc";
   }
@@ -851,10 +856,6 @@ void test(int a, bool b) {
 }
 
 TEST_P(SyntaxTreeTest, BinaryOperator) {
-  if (!GetParam().isCXX()) {
-// TODO: Split parts that depend on C++ into a separate test.
-return;
-  }
   expectTreeDumpEqual(
   R"cpp(
 void test(int a) {
@@ -862,15 +863,9 @@ void test(int a) {
   1 == 2;
   a = 1;
   a <<= 1;
-
-  true || false;
-  true or false;
-
+  1 || 0;
   1 & 2;
-  1 bitand 2;
-
   a ^= 3;
-  a xor_eq 3;
 }
 )cpp",
   R"txt(
@@ -923,42 +918,82 @@ void test(int a) {
 |-ExpressionStatement
 | |-BinaryOperatorExpression
 | | |-UnknownExpression
-| | | `-true
+| | | `-1
 | | |-||
 | | `-UnknownExpression
-| |   `-false
+| |   `-0
 | `-;
 |-ExpressionStatement
 | |-BinaryOperatorExpression
 | | |-UnknownExpression
-| | | `-true
-| | |-or
+| | | `-1
+| | |-&
 | | `-UnknownExpression
-| |   `-false
+| |   `-2
 | `-;
 |-ExpressionStatement
 | |-BinaryOperatorExpression
 | | |-UnknownExpression
-| | | `-1
-| | |-&
+| | | `-a
+| | |-^=
 | | `-UnknownExpression
-| |   `-2
+| |   `-3
 | `-;
+`-}
+)txt");
+}
+
+TEST_P(SyntaxTreeTest, BinaryOperatorCxx) {
+  if (!GetParam().isCXX()) {
+return;
+  }
+  expectTreeDumpEqual(
+  R"cpp(
+void test(int a) {
+  true || false;
+  true or false;
+  1 bitand 2;
+  a xor_eq 3;
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarator
+  | |-test
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   |-SimpleDeclaration
+  |   | |-int
+  |   | `-SimpleDeclarator
+  |   |   `-a
+  |   `-)
+  `-CompoundStatement
+|-{
 |-ExpressionStatement
 | |-BinaryOperatorExpression
 | | |-UnknownExpression
-| | | `-1
-| | |-bitand
+| | | `-true
+| | |-||
 | | `-UnknownExpression
-| |   `-2
+| |   `-false
 | `-;
 |-ExpressionStatement
 | |-BinaryOperatorExpression
 | | |-UnknownExpression
-| | | `-a
-| | |-^=
+| | | `-true
+| | |-or
 | | `-UnknownExpression
-| |   `-3
+| |   `-false
+| `-;
+|-ExpressionStatement
+| |-BinaryOperatorExpression
+| | |-UnknownExpression
+| | | `-1
+| | |-bitand
+| | `-UnknownExpression
+| |   `-2
 | `-;
 |-ExpressionStatement
 | |-BinaryOperatorExpression
@@ -2017,21 +2052,202 @@ void f(int xs[static 10]);
   `-;   )txt");
 }
 
-TEST_P(SyntaxTreeTest, ParameterListsInDeclarators) {
+TEST_P(SyntaxTreeTest, ParametersAndQualifiersInFreeFunctions) {
+  if (!GetParam().isCXX()) {
+return;
+  }
+  expectTreeDumpEqual(
+  R"cpp(
+int func1();
+int func2a(int a);
+int func2b(int);
+int func3a(int *ap);
+int func3b(int *);
+int func4a(int a, float b);
+int func4b(int, float);
+  )cpp",
+  R"txt(
+*: TranslationUnit
+|-SimpleDeclaration
+| |-int
+| |-SimpleDeclarator
+| | |-func1
+| | `-ParametersAndQualifiers
+| |   |-(
+| |   `-)
+| `-;
+|-SimpleDeclaration
+| |-int
+| |-SimpleDeclarator
+| | |-func2a
+| | `-ParametersAndQualifiers
+| |   |-(
+| |   |-SimpleDeclaration
+| |   | |-int
+| |   | `-SimpleDeclarator
+| |   |   `-a
+| |   `-)
+| `-;
+|-SimpleDeclaration
+| |-int
+| |-SimpleDeclarator
+| | |-func2b
+| | `-ParametersAndQualifiers
+| |   |-(
+| |   |-SimpleDeclaration
+| |   | `-int
+| |   `-)
+| `-;
+|-SimpleDeclaration
+| |-int
+| |-SimpleDeclarator
+| | |-func3a
+| | `-ParametersAndQualifiers
+| |   |-(
+| |   |-SimpleDeclaration
+| |   | |-int
+| |   | `-SimpleDeclarator
+| |   |   |-*
+| |   |   `-ap

[PATCH] D81040: Split syntax tree tests into more granular ones

2020-06-03 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr updated this revision to Diff 268104.
gribozavr added a comment.

Address code review comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81040

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

Index: clang/unittests/Tooling/Syntax/TreeTest.cpp
===
--- clang/unittests/Tooling/Syntax/TreeTest.cpp
+++ clang/unittests/Tooling/Syntax/TreeTest.cpp
@@ -64,6 +64,11 @@
Language == Lang_CXX17 || Language == Lang_CXX20;
   }
 
+  bool supportsCXXDynamicExceptionSpecification() const {
+return Language == Lang_CXX03 || Language == Lang_CXX11 ||
+   Language == Lang_CXX14;
+  }
+
   bool hasDelayedTemplateParsing() const {
 return Target == "x86_64-pc-win32-msvc";
   }
@@ -851,10 +856,6 @@
 }
 
 TEST_P(SyntaxTreeTest, BinaryOperator) {
-  if (!GetParam().isCXX()) {
-// TODO: Split parts that depend on C++ into a separate test.
-return;
-  }
   expectTreeDumpEqual(
   R"cpp(
 void test(int a) {
@@ -862,15 +863,9 @@
   1 == 2;
   a = 1;
   a <<= 1;
-
-  true || false;
-  true or false;
-
+  1 || 0;
   1 & 2;
-  1 bitand 2;
-
   a ^= 3;
-  a xor_eq 3;
 }
 )cpp",
   R"txt(
@@ -923,42 +918,82 @@
 |-ExpressionStatement
 | |-BinaryOperatorExpression
 | | |-UnknownExpression
-| | | `-true
+| | | `-1
 | | |-||
 | | `-UnknownExpression
-| |   `-false
+| |   `-0
 | `-;
 |-ExpressionStatement
 | |-BinaryOperatorExpression
 | | |-UnknownExpression
-| | | `-true
-| | |-or
+| | | `-1
+| | |-&
 | | `-UnknownExpression
-| |   `-false
+| |   `-2
 | `-;
 |-ExpressionStatement
 | |-BinaryOperatorExpression
 | | |-UnknownExpression
-| | | `-1
-| | |-&
+| | | `-a
+| | |-^=
 | | `-UnknownExpression
-| |   `-2
+| |   `-3
 | `-;
+`-}
+)txt");
+}
+
+TEST_P(SyntaxTreeTest, BinaryOperatorCxx) {
+  if (!GetParam().isCXX()) {
+return;
+  }
+  expectTreeDumpEqual(
+  R"cpp(
+void test(int a) {
+  true || false;
+  true or false;
+  1 bitand 2;
+  a xor_eq 3;
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarator
+  | |-test
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   |-SimpleDeclaration
+  |   | |-int
+  |   | `-SimpleDeclarator
+  |   |   `-a
+  |   `-)
+  `-CompoundStatement
+|-{
 |-ExpressionStatement
 | |-BinaryOperatorExpression
 | | |-UnknownExpression
-| | | `-1
-| | |-bitand
+| | | `-true
+| | |-||
 | | `-UnknownExpression
-| |   `-2
+| |   `-false
 | `-;
 |-ExpressionStatement
 | |-BinaryOperatorExpression
 | | |-UnknownExpression
-| | | `-a
-| | |-^=
+| | | `-true
+| | |-or
 | | `-UnknownExpression
-| |   `-3
+| |   `-false
+| `-;
+|-ExpressionStatement
+| |-BinaryOperatorExpression
+| | |-UnknownExpression
+| | | `-1
+| | |-bitand
+| | `-UnknownExpression
+| |   `-2
 | `-;
 |-ExpressionStatement
 | |-BinaryOperatorExpression
@@ -2017,21 +2052,202 @@
   `-;   )txt");
 }
 
-TEST_P(SyntaxTreeTest, ParameterListsInDeclarators) {
+TEST_P(SyntaxTreeTest, ParametersAndQualifiersInFreeFunctions) {
+  if (!GetParam().isCXX()) {
+return;
+  }
+  expectTreeDumpEqual(
+  R"cpp(
+int func1();
+int func2a(int a);
+int func2b(int);
+int func3a(int *ap);
+int func3b(int *);
+int func4a(int a, float b);
+int func4b(int, float);
+  )cpp",
+  R"txt(
+*: TranslationUnit
+|-SimpleDeclaration
+| |-int
+| |-SimpleDeclarator
+| | |-func1
+| | `-ParametersAndQualifiers
+| |   |-(
+| |   `-)
+| `-;
+|-SimpleDeclaration
+| |-int
+| |-SimpleDeclarator
+| | |-func2a
+| | `-ParametersAndQualifiers
+| |   |-(
+| |   |-SimpleDeclaration
+| |   | |-int
+| |   | `-SimpleDeclarator
+| |   |   `-a
+| |   `-)
+| `-;
+|-SimpleDeclaration
+| |-int
+| |-SimpleDeclarator
+| | |-func2b
+| | `-ParametersAndQualifiers
+| |   |-(
+| |   |-SimpleDeclaration
+| |   | `-int
+| |   `-)
+| `-;
+|-SimpleDeclaration
+| |-int
+| |-SimpleDeclarator
+| | |-func3a
+| | `-ParametersAndQualifiers
+| |   |-(
+| |   |-SimpleDeclaration
+| |   | |-int
+| |   | `-SimpleDeclarator
+| |   |   |-*
+| |   |   `-ap
+| |   `-)
+| `-;
+|-SimpleDeclaration
+| |-int
+| |-SimpleDeclarator
+| | |-func3b
+| | `-ParametersAndQualifiers
+| |   |-(
+| |   |-SimpleDeclaration
+| |   | |-int
+| |   | `-SimpleDeclarator
+| |   |   `-*
+| |   `-)
+| `-;
+|-SimpleDeclaration
+| |-int
+| |-SimpleDeclarator
+| | |-func4a
+| | `-ParametersAndQualifiers
+| |   |-(
+| |   |-SimpleDeclaration
+| |   | |-int
+| |   | `-SimpleDeclarator
+| |   |   `-a
+| |   |-,
+| |   |-SimpleDeclaration
+| |   | |-float
+| |   | `-SimpleDeclarator
+| |   |   `-b
+| |   `-)
+| `-;
+`-SimpleDeclaration
+  |-int
+  |-SimpleDeclarator
+  | |-func4b
+  | `-ParametersAndQualifiers
+  |   |-(
+  

[PATCH] D78350: [AST] Build recovery expressions by default for C++.

2020-06-03 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 268105.
hokein added a comment.

rebase to master.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78350

Files:
  clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
  clang/include/clang/Basic/LangOptions.def
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/AST/ast-dump-openmp-begin-declare-variant_namespace_1.cpp
  clang/test/CXX/class.access/p4.cpp
  clang/test/CXX/special/class.ctor/p5-0x.cpp
  clang/test/CXX/stmt.stmt/stmt.iter/stmt.ranged/p1.cpp
  clang/test/OpenMP/declare_variant_messages.cpp
  clang/test/OpenMP/target_update_from_messages.cpp
  clang/test/OpenMP/target_update_to_messages.cpp
  clang/test/Parser/objcxx0x-lambda-expressions.mm
  clang/test/Parser/objcxx11-invalid-lambda.cpp
  clang/test/SemaCXX/cast-conversion.cpp
  clang/test/SemaCXX/constant-expression-cxx11.cpp
  clang/test/SemaCXX/constructor-initializer.cpp
  clang/test/SemaCXX/cxx0x-deleted-default-ctor.cpp
  clang/test/SemaCXX/cxx1y-deduced-return-type.cpp
  clang/test/SemaCXX/cxx1z-copy-omission.cpp
  clang/test/SemaCXX/decltype-crash.cpp
  clang/test/SemaCXX/enable_if.cpp
  clang/test/SemaCXX/for-range-dereference.cpp
  clang/test/SemaCXX/recovery-default-init.cpp
  clang/test/SemaCXX/recovery-initializer.cpp
  clang/test/SemaCXX/varargs.cpp
  clang/test/SemaCXX/virtual-base-used.cpp
  clang/test/SemaObjCXX/arc-0x.mm
  clang/test/SemaOpenCLCXX/address-space-references.cl
  clang/test/SemaTemplate/instantiate-function-params.cpp
  clang/test/SemaTemplate/instantiate-init.cpp

Index: clang/test/SemaTemplate/instantiate-init.cpp
===
--- clang/test/SemaTemplate/instantiate-init.cpp
+++ clang/test/SemaTemplate/instantiate-init.cpp
@@ -108,7 +108,7 @@
 integral_c<1> ic1 = array_lengthof(Description::data);
 (void)sizeof(array_lengthof(Description::data));
 
-sizeof(array_lengthof( // expected-error{{no matching function for call to 'array_lengthof'}}
+(void)sizeof(array_lengthof( // expected-error{{no matching function for call to 'array_lengthof'}}
   Description::data // expected-note{{in instantiation of static data member 'PR7985::Description::data' requested here}}
   ));
 
Index: clang/test/SemaTemplate/instantiate-function-params.cpp
===
--- clang/test/SemaTemplate/instantiate-function-params.cpp
+++ clang/test/SemaTemplate/instantiate-function-params.cpp
@@ -3,32 +3,32 @@
 // PR6619
 template struct if_c { };
 template struct if_ {
-  typedef if_c< static_cast(T1::value)> almost_type_; // expected-note 5{{in instantiation}}
+  typedef if_c< static_cast(T1::value)> almost_type_; // expected-note 7{{in instantiation}}
 };
 template  struct wrap_constraints { };
 template  
 inline char has_constraints_(Model* , // expected-note 3{{candidate template ignored}}
-   wrap_constraints* = 0); // expected-note 2{{in instantiation}}
+   wrap_constraints* = 0); // expected-note 4{{in instantiation}}
 
 template  struct not_satisfied {
   static const bool value = sizeof( has_constraints_((Model*)0)  == 1); // expected-error 3{{no matching function}} \
-  // expected-note 2{{while substituting deduced template arguments into function template 'has_constraints_' [with }}
+  // expected-note 4{{while substituting deduced template arguments into function template 'has_constraints_' [with }}
 };
 template  struct requirement_;
 template  struct instantiate {
 };
-template  struct requirement_   : if_<   not_satisfied >::type { // expected-note 5{{in instantiation}}
+template  struct requirement_   : if_<   not_satisfied >::type { // expected-error 3{{no type named 'type' in}} expected-note 7{{in instantiation}}
 };
 template  struct usage_requirements {
 };
 template < typename TT > struct InputIterator{
-typedef  instantiate< & requirement_ x)>::failed> boost_concept_check1; // expected-note {{in instantiation}}
+typedef  instantiate< & requirement_ x)>::failed> boost_concept_check1; // expected-note 2{{in instantiation}}
 };
-template < typename TT > struct ForwardIterator  : InputIterator  { // expected-note {{in instantiation}}
-  typedef instantiate< & requirement_ x)>::failed> boost_concept_check2; // expected-note {{in instantiation}}
+template < typename TT > struct ForwardIterator  : InputIterator  { // expected-note 2{{in instantiation}}
+  typedef instantiate< & requirement_ x)>::failed> boost_concept_check2; // expected-note 2{{in instantiation}}
 
 };
-typedef instantiate< &requirement_ x)>::failed> boost_concept_checkX;// expected-n

[PATCH] D80950: [clang-format] [PR44542,38872] String << String always get a forced newline.

2020-06-03 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added a comment.

In D80950#2069733 , @curdeius wrote:

> The change seems to me technically sound, but I'm not sure of the scope of 
> its effects. There might be users that rely on this behavior. On the other 
> hand, adding an option to keep the old behavior doesn't seem appropriate, and 
> personally I consider the old behavior as a bug.


I also have concerns about my own fix. This will break existing code similar to 
that found in UnwrappedLineParser.cpp that I included here, whilst I also think 
this is a bug, I fear users will complain that we broke compatibility. The fact 
it lacked tests was also a shock given how vigorously that is defended when 
people add new functionality.

One thing that perhaps we could consider is keeping the old odd behavior but 
behind a new configuration option, declaring it an outright bug and removing it 
might just be a more subjective than an objective opinion (if I think about the 
longevity of this 7+year and remove my myopic view that its a bug I can see 
that some code could be made less readable by this change)

What do people think about if we added

  enum ChevronBreakingStyle
  {
  Never,  // at line limit only
  LegacyBetweenStrings, // (current)
  AfterEndOrNewLine,   // we could break on 
endl/std::endl/ends/std::ends/"\n" or any string literal ending with \n
  Always  // like between strings but between all  << types   and  << 
"string"
  }

Even if the default was LegacyBetweenStrings, I think those that are concerned 
about how it currently works would likely be happier to make the change to get 
the behavior they wanted, that way we wouldn't even break anywone.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80950



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


[PATCH] D81040: Split syntax tree tests into more granular ones

2020-06-03 Thread Dmitri Gribenko via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGd7d5dd31fc6f: Split syntax tree tests into more granular 
ones (authored by gribozavr).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81040

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

Index: clang/unittests/Tooling/Syntax/TreeTest.cpp
===
--- clang/unittests/Tooling/Syntax/TreeTest.cpp
+++ clang/unittests/Tooling/Syntax/TreeTest.cpp
@@ -64,6 +64,11 @@
Language == Lang_CXX17 || Language == Lang_CXX20;
   }
 
+  bool supportsCXXDynamicExceptionSpecification() const {
+return Language == Lang_CXX03 || Language == Lang_CXX11 ||
+   Language == Lang_CXX14;
+  }
+
   bool hasDelayedTemplateParsing() const {
 return Target == "x86_64-pc-win32-msvc";
   }
@@ -851,10 +856,6 @@
 }
 
 TEST_P(SyntaxTreeTest, BinaryOperator) {
-  if (!GetParam().isCXX()) {
-// TODO: Split parts that depend on C++ into a separate test.
-return;
-  }
   expectTreeDumpEqual(
   R"cpp(
 void test(int a) {
@@ -862,15 +863,9 @@
   1 == 2;
   a = 1;
   a <<= 1;
-
-  true || false;
-  true or false;
-
+  1 || 0;
   1 & 2;
-  1 bitand 2;
-
   a ^= 3;
-  a xor_eq 3;
 }
 )cpp",
   R"txt(
@@ -923,42 +918,82 @@
 |-ExpressionStatement
 | |-BinaryOperatorExpression
 | | |-UnknownExpression
-| | | `-true
+| | | `-1
 | | |-||
 | | `-UnknownExpression
-| |   `-false
+| |   `-0
 | `-;
 |-ExpressionStatement
 | |-BinaryOperatorExpression
 | | |-UnknownExpression
-| | | `-true
-| | |-or
+| | | `-1
+| | |-&
 | | `-UnknownExpression
-| |   `-false
+| |   `-2
 | `-;
 |-ExpressionStatement
 | |-BinaryOperatorExpression
 | | |-UnknownExpression
-| | | `-1
-| | |-&
+| | | `-a
+| | |-^=
 | | `-UnknownExpression
-| |   `-2
+| |   `-3
 | `-;
+`-}
+)txt");
+}
+
+TEST_P(SyntaxTreeTest, BinaryOperatorCxx) {
+  if (!GetParam().isCXX()) {
+return;
+  }
+  expectTreeDumpEqual(
+  R"cpp(
+void test(int a) {
+  true || false;
+  true or false;
+  1 bitand 2;
+  a xor_eq 3;
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarator
+  | |-test
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   |-SimpleDeclaration
+  |   | |-int
+  |   | `-SimpleDeclarator
+  |   |   `-a
+  |   `-)
+  `-CompoundStatement
+|-{
 |-ExpressionStatement
 | |-BinaryOperatorExpression
 | | |-UnknownExpression
-| | | `-1
-| | |-bitand
+| | | `-true
+| | |-||
 | | `-UnknownExpression
-| |   `-2
+| |   `-false
 | `-;
 |-ExpressionStatement
 | |-BinaryOperatorExpression
 | | |-UnknownExpression
-| | | `-a
-| | |-^=
+| | | `-true
+| | |-or
 | | `-UnknownExpression
-| |   `-3
+| |   `-false
+| `-;
+|-ExpressionStatement
+| |-BinaryOperatorExpression
+| | |-UnknownExpression
+| | | `-1
+| | |-bitand
+| | `-UnknownExpression
+| |   `-2
 | `-;
 |-ExpressionStatement
 | |-BinaryOperatorExpression
@@ -2017,21 +2052,202 @@
   `-;   )txt");
 }
 
-TEST_P(SyntaxTreeTest, ParameterListsInDeclarators) {
+TEST_P(SyntaxTreeTest, ParametersAndQualifiersInFreeFunctions) {
+  if (!GetParam().isCXX()) {
+return;
+  }
+  expectTreeDumpEqual(
+  R"cpp(
+int func1();
+int func2a(int a);
+int func2b(int);
+int func3a(int *ap);
+int func3b(int *);
+int func4a(int a, float b);
+int func4b(int, float);
+  )cpp",
+  R"txt(
+*: TranslationUnit
+|-SimpleDeclaration
+| |-int
+| |-SimpleDeclarator
+| | |-func1
+| | `-ParametersAndQualifiers
+| |   |-(
+| |   `-)
+| `-;
+|-SimpleDeclaration
+| |-int
+| |-SimpleDeclarator
+| | |-func2a
+| | `-ParametersAndQualifiers
+| |   |-(
+| |   |-SimpleDeclaration
+| |   | |-int
+| |   | `-SimpleDeclarator
+| |   |   `-a
+| |   `-)
+| `-;
+|-SimpleDeclaration
+| |-int
+| |-SimpleDeclarator
+| | |-func2b
+| | `-ParametersAndQualifiers
+| |   |-(
+| |   |-SimpleDeclaration
+| |   | `-int
+| |   `-)
+| `-;
+|-SimpleDeclaration
+| |-int
+| |-SimpleDeclarator
+| | |-func3a
+| | `-ParametersAndQualifiers
+| |   |-(
+| |   |-SimpleDeclaration
+| |   | |-int
+| |   | `-SimpleDeclarator
+| |   |   |-*
+| |   |   `-ap
+| |   `-)
+| `-;
+|-SimpleDeclaration
+| |-int
+| |-SimpleDeclarator
+| | |-func3b
+| | `-ParametersAndQualifiers
+| |   |-(
+| |   |-SimpleDeclaration
+| |   | |-int
+| |   | `-SimpleDeclarator
+| |   |   `-*
+| |   `-)
+| `-;
+|-SimpleDeclaration
+| |-int
+| |-SimpleDeclarator
+| | |-func4a
+| | `-ParametersAndQualifiers
+| |   |-(
+| |   |-SimpleDeclaration
+| |   | |-int
+| |   | `-SimpleDeclarator
+| |   |   `-a
+| |   |-,
+| |   |-SimpleDeclaration
+| |   | |-float
+| |   | `-SimpleDeclarator
+| |   |   `-b
+| |   `-)
+| `-;
+`-SimpleDeclaration
+  |-int
+  |-Si

[clang] e6ba0a5 - Fix MSVC "not all control paths return a value" warning. NFC.

2020-06-03 Thread Simon Pilgrim via cfe-commits

Author: Simon Pilgrim
Date: 2020-06-03T11:12:43+01:00
New Revision: e6ba0a55fd39b600f3f431308f4a7e36e48f91ae

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

LOG: Fix MSVC "not all control paths return a value" warning. NFC.

Add llvm_unreachable after switch statement for 
CheckerRegistry::StateFromCmdLine enum

Added: 


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

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp 
b/clang/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp
index f4d5db1e7a4b..401cd1d57bb3 100644
--- a/clang/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp
+++ b/clang/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp
@@ -112,6 +112,7 @@ static StringRef toString(CheckerRegistry::StateFromCmdLine 
Kind) {
   case CheckerRegistry::StateFromCmdLine::State_Unspecified:
 return "Unspecified";
   }
+  llvm_unreachable("Unhandled CheckerRegistry::StateFromCmdLine enum");
 }
 
 LLVM_DUMP_METHOD void



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


[PATCH] D80887: [clang-tidy] ignore builtin varargs from pro-type-vararg-check

2020-06-03 Thread Nathan James via Phabricator via cfe-commits
njames93 updated this revision to Diff 268116.
njames93 added a comment.

Included more builtins.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80887

Files:
  clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeVarargCheck.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-vararg.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-vararg.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-vararg.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-vararg.cpp
@@ -49,3 +49,11 @@
 }
 
 int my_vprintf(const char* format, va_list arg ); // OK to declare function 
taking va_list
+
+void ignoredBuiltinsTest() {
+  (void)__builtin_assume_aligned(0, 8);
+  (void)__builtin_constant_p(0);
+  (void)__builtin_fpclassify(0, 0, 0, 0, 0, 0.f);
+  (void)__builtin_isinf_sign(0.f);
+  (void)__builtin_prefetch(nullptr);
+}
Index: clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeVarargCheck.cpp
===
--- clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeVarargCheck.cpp
+++ clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeVarargCheck.cpp
@@ -18,11 +18,60 @@
 
 const internal::VariadicDynCastAllOfMatcher vAArgExpr;
 
+static constexpr StringRef AllowedVariadics[] = {
+// Disable formatting to prevent squashing the list.
+// clang-format off
+"__builtin_isgreater", 
+"__builtin_isgreaterequal", 
+"__builtin_isless",
+"__builtin_islessequal", 
+"__builtin_islessgreater", 
+"__builtin_isunordered",
+"__builtin_fpclassify", 
+"__builtin_isfinite", 
+"__builtin_isinf",
+"__builtin_isinf_sign", 
+"__builtin_isnan", 
+"__builtin_isnormal",
+"__builtin_signbit", 
+"__builtin_constant_p", 
+"__builtin_classify_type",
+// "__builtin_va_start",
+// "__builtin_stdarg_start",
+"__builtin_assume_aligned", // Documented as variadic to support 
overloading
+// "__builtin_fprintf",
+// "__builtin_printf",
+// "__builtin_snprintf",
+// "__builtin___snprintf_chk",
+// "__builtin___sprintf_chk",
+// "__builtin___fprintf_chk",
+// "__builtin___printf_chk",
+"__builtin_prefetch",  // Documented as variadic to support overloading
+"__builtin_shufflevector", // Documented as variadic but with a defined
+   // number of args based on vector size.
+"__builtin_convertvector", 
+"__builtin_call_with_static_chain",
+"__builtin_annotation", 
+"__builtin_add_overflow", 
+"__builtin_sub_overflow",
+"__builtin_mul_overflow", 
+"__builtin_preserve_access_index",
+"__builtin_nontemporal_store", 
+"__builtin_nontemporal_load",
+// "__builtin_os_log_format_buffer_size",
+// "__builtin_os_log_format",
+// "__builtin_ms_va_start",
+// clang-format on
+};
+
 void ProTypeVarargCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(vAArgExpr().bind("va_use"), this);
 
   Finder->addMatcher(
-  callExpr(callee(functionDecl(isVariadic(.bind("callvararg"), this);
+  callExpr(callee(functionDecl(isVariadic(),
+   unless(hasAnyName(AllowedVariadics)
+  .bind("callvararg"),
+  this);
 }
 
 static bool hasSingleVariadicArgumentWithValue(const CallExpr *C, uint64_t I) {


Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-vararg.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-vararg.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-vararg.cpp
@@ -49,3 +49,11 @@
 }
 
 int my_vprintf(const char* format, va_list arg ); // OK to declare function taking va_list
+
+void ignoredBuiltinsTest() {
+  (void)__builtin_assume_aligned(0, 8);
+  (void)__builtin_constant_p(0);
+  (void)__builtin_fpclassify(0, 0, 0, 0, 0, 0.f);
+  (void)__builtin_isinf_sign(0.f);
+  (void)__builtin_prefetch(nullptr);
+}
Index: clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeVarargCheck.cpp
===
--- clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeVarargCheck.cpp
+++ clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeVarargCheck.cpp
@@ -18,11 +18,60 @@
 
 const internal::VariadicDynCastAllOfMatcher vAArgExpr;
 
+static constexpr StringRef AllowedVariadics[] = {
+// Disable formatting to prevent squashing the list.
+// clang-format off
+"__builtin_isgreater", 
+"__builtin_isgreaterequal", 
+"__builtin_isless",
+"__builtin_islessequal", 
+"__builtin_islessgreater", 
+"__builtin_isunordered",
+"__builtin_fpclassify", 
+"__builtin_isfinite", 
+ 

[clang-tools-extra] add51e1 - [clang-tidy] add new check readability-use-anyofallof

2020-06-03 Thread Matthias Gehre via cfe-commits

Author: Matthias Gehre
Date: 2020-06-03T12:19:06+02:00
New Revision: add51e152aa6dc3aa7a51901a099b2ebe8cfe377

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

LOG: [clang-tidy] add new check readability-use-anyofallof

Summary:
Finds range-based for loops that can be replaced by a call to ``std::any_of`` or
``std::all_of``. In C++ 20 mode, suggests ``std::ranges::any_of`` or
``std::ranges::all_of``.
For now, no fixits are produced.

Reviewers: aaron.ballman, alexfh, hokein

Subscribers: mgorny, xazax.hun, cfe-commits

Tags: #clang

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

Added: 
clang-tools-extra/clang-tidy/readability/UseAnyOfAllOfCheck.cpp
clang-tools-extra/clang-tidy/readability/UseAnyOfAllOfCheck.h
clang-tools-extra/docs/clang-tidy/checks/readability-use-anyofallof.rst

clang-tools-extra/test/clang-tidy/checkers/readability-use-anyofallof-cpp20.cpp
clang-tools-extra/test/clang-tidy/checkers/readability-use-anyofallof.cpp

Modified: 
clang-tools-extra/clang-tidy/readability/CMakeLists.txt
clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/docs/clang-tidy/checks/list.rst

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/readability/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
index 5f674beaa8be..02003a7537f0 100644
--- a/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
@@ -42,8 +42,10 @@ add_clang_library(clangTidyReadabilityModule
   StringCompareCheck.cpp
   UniqueptrDeleteReleaseCheck.cpp
   UppercaseLiteralSuffixCheck.cpp
+  UseAnyOfAllOfCheck.cpp
 
   LINK_LIBS
+  clangAnalysis
   clangAST
   clangASTMatchers
   clangBasic

diff  --git 
a/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp 
b/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
index 5ece15ed2912..5ff5e2022839 100644
--- a/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
@@ -45,6 +45,7 @@
 #include "StringCompareCheck.h"
 #include "UniqueptrDeleteReleaseCheck.h"
 #include "UppercaseLiteralSuffixCheck.h"
+#include "UseAnyOfAllOfCheck.h"
 
 namespace clang {
 namespace tidy {
@@ -125,6 +126,8 @@ class ReadabilityModule : public ClangTidyModule {
 "readability-uniqueptr-delete-release");
 CheckFactories.registerCheck(
 "readability-uppercase-literal-suffix");
+CheckFactories.registerCheck(
+"readability-use-anyofallof");
   }
 };
 

diff  --git a/clang-tools-extra/clang-tidy/readability/UseAnyOfAllOfCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/UseAnyOfAllOfCheck.cpp
new file mode 100644
index ..d3c002f5ad1d
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/readability/UseAnyOfAllOfCheck.cpp
@@ -0,0 +1,109 @@
+//===--- UseAnyOfAllOfCheck.cpp - 
clang-tidy---===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "UseAnyOfAllOfCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Analysis/Analyses/ExprMutationAnalyzer.h"
+#include "clang/Frontend/CompilerInstance.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace {
+/// Matches a Stmt whose parent is a CompoundStmt, and which is directly
+/// followed by a Stmt matching the inner matcher.
+AST_MATCHER_P(Stmt, nextStmt, ast_matchers::internal::Matcher,
+  InnerMatcher) {
+  DynTypedNodeList Parents = Finder->getASTContext().getParents(Node);
+  if (Parents.size() != 1)
+return false;
+
+  auto *C = Parents[0].get();
+  if (!C)
+return false;
+
+  const auto *I = llvm::find(C->body(), &Node);
+  assert(I != C->body_end() && "C is parent of Node");
+  if (++I == C->body_end())
+return false; // Node is last statement.
+
+  return InnerMatcher.matches(**I, Finder, Builder);
+}
+} // namespace
+
+namespace tidy {
+namespace readability {
+
+void UseAnyOfAllOfCheck::registerMatchers(MatchFinder *Finder) {
+  auto returns = [](bool V) {
+return returnStmt(hasReturnValue(cxxBoolLiteral(equals(V;
+  };
+
+  auto returnsButNotTrue =
+  returnStmt(hasReturnValue(unless(cxxBoolLiteral(equals(true);
+  auto returnsButNotFalse =
+  returnStmt(hasReturnValue(unless(cxxBoolLiteral(equals(false);
+
+  Finder->addMatcher(
+  cxxForRangeStmt(
+  nextStmt(returns(false).bind("final_return")),
+

[clang] 8beaba1 - [Clang][AArch64] Capturing proper pointer alignment for Neon vld1 intrinsicts

2020-06-03 Thread Lucas Prates via cfe-commits

Author: Lucas Prates
Date: 2020-06-03T11:39:27+01:00
New Revision: 8beaba13b8a61697008854b82ed3b45377af9d9d

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

LOG: [Clang][AArch64] Capturing proper pointer alignment for Neon vld1 
intrinsicts

Summary:
During CodeGen for AArch64 Neon intrinsics, Clang was incorrectly
assuming all the pointers from which loads were being generated for vld1
intrinsics were aligned according to the intrinsics result type, causing
alignment faults on the code generated by the backend.

This patch updates vld1 intrinsics' CodeGen to properly capture the
correct load alignment based on the type of the pointer provided as
input for the intrinsic.

Reviewers: t.p.northover, ostannard, pcc, efriedma

Reviewed By: ostannard, efriedma

Subscribers: echristo, plotfi, nickdesaulniers, efriedma, kristof.beyls, 
danielkiss, cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang/lib/CodeGen/CGBuiltin.cpp
clang/test/CodeGen/aarch64-neon-intrinsics.c

Removed: 




diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index cf8c8a1669d7..13c24a5d2686 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -8636,7 +8636,27 @@ Value *CodeGenFunction::EmitAArch64BuiltinExpr(unsigned 
BuiltinID,
   assert(Error == ASTContext::GE_None && "Should not codegen an error");
 
   llvm::SmallVector Ops;
+  Address PtrOp0 = Address::invalid();
   for (unsigned i = 0, e = E->getNumArgs() - 1; i != e; i++) {
+if (i == 0) {
+  switch (BuiltinID) {
+  case NEON::BI__builtin_neon_vld1_v:
+  case NEON::BI__builtin_neon_vld1q_v:
+  case NEON::BI__builtin_neon_vld1_dup_v:
+  case NEON::BI__builtin_neon_vld1q_dup_v:
+  case NEON::BI__builtin_neon_vld1_lane_v:
+  case NEON::BI__builtin_neon_vld1q_lane_v:
+  case NEON::BI__builtin_neon_vst1_v:
+  case NEON::BI__builtin_neon_vst1q_v:
+  case NEON::BI__builtin_neon_vst1_lane_v:
+  case NEON::BI__builtin_neon_vst1q_lane_v:
+// Get the alignment for the argument in addition to the value;
+// we'll use it later.
+PtrOp0 = EmitPointerWithAlignment(E->getArg(0));
+Ops.push_back(PtrOp0.getPointer());
+continue;
+  }
+}
 if ((ICEArguments & (1 << i)) == 0) {
   Ops.push_back(EmitScalarExpr(E->getArg(i)));
 } else {
@@ -10337,24 +10357,20 @@ Value 
*CodeGenFunction::EmitAArch64BuiltinExpr(unsigned BuiltinID,
   case NEON::BI__builtin_neon_vld1_v:
   case NEON::BI__builtin_neon_vld1q_v: {
 Ops[0] = Builder.CreateBitCast(Ops[0], llvm::PointerType::getUnqual(VTy));
-auto Alignment = CharUnits::fromQuantity(
-BuiltinID == NEON::BI__builtin_neon_vld1_v ? 8 : 16);
-return Builder.CreateAlignedLoad(VTy, Ops[0], Alignment);
+return Builder.CreateAlignedLoad(VTy, Ops[0], PtrOp0.getAlignment());
   }
   case NEON::BI__builtin_neon_vst1_v:
   case NEON::BI__builtin_neon_vst1q_v:
 Ops[0] = Builder.CreateBitCast(Ops[0], llvm::PointerType::getUnqual(VTy));
 Ops[1] = Builder.CreateBitCast(Ops[1], VTy);
-return Builder.CreateDefaultAlignedStore(Ops[1], Ops[0]);
+return Builder.CreateAlignedStore(Ops[1], Ops[0], PtrOp0.getAlignment());
   case NEON::BI__builtin_neon_vld1_lane_v:
   case NEON::BI__builtin_neon_vld1q_lane_v: {
 Ops[1] = Builder.CreateBitCast(Ops[1], Ty);
 Ty = llvm::PointerType::getUnqual(VTy->getElementType());
 Ops[0] = Builder.CreateBitCast(Ops[0], Ty);
-auto Alignment = CharUnits::fromQuantity(
-BuiltinID == NEON::BI__builtin_neon_vld1_lane_v ? 8 : 16);
-Ops[0] =
-Builder.CreateAlignedLoad(VTy->getElementType(), Ops[0], Alignment);
+Ops[0] = Builder.CreateAlignedLoad(VTy->getElementType(), Ops[0],
+   PtrOp0.getAlignment());
 return Builder.CreateInsertElement(Ops[1], Ops[0], Ops[2], "vld1_lane");
   }
   case NEON::BI__builtin_neon_vld1_dup_v:
@@ -10362,10 +10378,8 @@ Value 
*CodeGenFunction::EmitAArch64BuiltinExpr(unsigned BuiltinID,
 Value *V = UndefValue::get(Ty);
 Ty = llvm::PointerType::getUnqual(VTy->getElementType());
 Ops[0] = Builder.CreateBitCast(Ops[0], Ty);
-auto Alignment = CharUnits::fromQuantity(
-BuiltinID == NEON::BI__builtin_neon_vld1_dup_v ? 8 : 16);
-Ops[0] =
-Builder.CreateAlignedLoad(VTy->getElementType(), Ops[0], Alignment);
+Ops[0] = Builder.CreateAlignedLoad(VTy->getElementType(), Ops[0],
+   PtrOp0.getAlignment());
 llvm::Constant *CI = ConstantInt::get(Int32Ty, 0);
 Ops[0] = Builder.CreateInsertElement(V, Ops[0], CI);
 return EmitNeonSplat(Ops[0], CI);
@@ -10375,8 +10389,8 @@ Value *CodeGenFunc

[PATCH] D77572: [clang-tidy] add new check readability-use-anyofallof

2020-06-03 Thread Matthias Gehre via Phabricator via cfe-commits
mgehre updated this revision to Diff 268120.
mgehre added a comment.

Implemented njames93's comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77572

Files:
  clang-tools-extra/clang-tidy/readability/CMakeLists.txt
  clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tools-extra/clang-tidy/readability/UseAnyOfAllOfCheck.cpp
  clang-tools-extra/clang-tidy/readability/UseAnyOfAllOfCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/docs/clang-tidy/checks/readability-use-anyofallof.rst
  
clang-tools-extra/test/clang-tidy/checkers/readability-use-anyofallof-cpp20.cpp
  clang-tools-extra/test/clang-tidy/checkers/readability-use-anyofallof.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/readability-use-anyofallof.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/readability-use-anyofallof.cpp
@@ -0,0 +1,183 @@
+// RUN: %check_clang_tidy -std=c++14,c++17 %s readability-use-anyofallof %t
+
+bool good_any_of() {
+  int v[] = {1, 2, 3};
+  // CHECK-MESSAGES: :[[@LINE+1]]:3: warning: replace loop by 'std::any_of()' [readability-use-anyofallof]
+  for (int i : v)
+if (i)
+  return true;
+  return false;
+}
+
+bool cond(int i);
+
+bool good_any_of2() {
+  int v[] = {1, 2, 3};
+  for (int i : v) {
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: replace loop by 'std::any_of()'
+int k = i / 2;
+if (cond(k))
+  return true;
+  }
+  return false;
+}
+
+bool good_any_of3() {
+  int v[] = {1, 2, 3};
+  for (int i : v) {
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: replace loop by 'std::any_of()'
+if (i == 3)
+  continue;
+if (i)
+  return true;
+  }
+
+  return false;
+}
+
+bool good_any_of_use_external(int comp) {
+  int v[] = {1, 2, 3};
+  for (int i : v) {
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: replace loop by 'std::any_of()'
+if (i == comp)
+  return true;
+  }
+
+  return false;
+}
+
+bool good_any_of_no_cond() {
+  int v[] = {1, 2, 3};
+  for (int i : v) {
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: replace loop by 'std::any_of()'
+return true; // Not a real loop, but technically can become any_of.
+  }
+
+  return false;
+}
+
+bool good_any_of_local_modification() {
+  int v[] = {1, 2, 3};
+  for (int i : v) {
+int j = i;
+j++; // FIXME: Any non-const use disables check.
+if (j > 3)
+  return true;
+  }
+
+  return false;
+}
+
+bool good_any_of_throw() {
+  int v[] = {1, 2, 3};
+  for (int i : v) {
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: replace loop by 'std::any_of()'
+if (i > 3)
+  return true;
+if (i == 42)
+  throw 0;
+  }
+
+  return false;
+}
+
+bool bad_any_of1() {
+  int v[] = {1, 2, 3};
+  for (int i : v) {
+if (i)
+  return false; // bad constant
+  }
+  return false;
+}
+
+bool bad_any_of2() {
+  int v[] = {1, 2, 3};
+  for (int i : v)
+if (i)
+  return true;
+
+  return true; // bad return
+}
+
+bool bad_any_of3() {
+  int v[] = {1, 2, 3};
+  for (int i : v)
+if (i)
+  return true;
+else
+  return i / 2; // bad return
+
+  return false;
+}
+
+bool bad_any_of_control_flow1() {
+  int v[] = {1, 2, 3};
+  for (int i : v) {
+break; // bad control flow
+if (i)
+  return true;
+  }
+
+  return false;
+}
+
+bool bad_any_of_control_flow2() {
+  int v[] = {1, 2, 3};
+  for (int i : v) {
+goto end; // bad control flow
+if (i)
+  return true;
+  }
+
+  end:
+  return false;
+}
+
+bool bad_any_of4() {
+  return false; // wrong order
+
+  int v[] = {1, 2, 3};
+  for (int i : v) {
+if (i)
+  return true;
+  }
+}
+
+bool bad_any_of5() {
+  int v[] = {1, 2, 3};
+  int j = 0;
+  for (int i : v) {
+j++; // modifications
+if (i)
+  return true;
+  }
+  return false;
+}
+
+bool bad_any_of6() {
+  int v[] = {1, 2, 3};
+  for (int i : v) {
+if (i)
+  return true;
+  }
+  int j = 0; // Statements between loop and return
+  j++;
+  return false;
+}
+
+bool bad_any_of7() {
+  int v[] = {1, 2, 3};
+  for (int i : v) {
+i; // No 'return true' in body.
+  }
+  return false;
+}
+
+bool good_all_of() {
+  int v[] = {1, 2, 3};
+  // CHECK-MESSAGES: :[[@LINE+1]]:3: warning: replace loop by 'std::all_of()' [readability-use-anyofallof]
+  for (int i : v)
+if (i)
+  return false;
+  return true;
+}
Index: clang-tools-extra/test/clang-tidy/checkers/readability-use-anyofallof-cpp20.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/readability-use-anyofallof-cpp20.cpp
@@ -0,0 +1,19 @@
+// RUN: %check_clang_tidy -std=c++2a-or-later %s readability-use-anyofallof %t
+
+bool good_any_of() {
+  int v[] = {1, 2, 3};
+  // CHECK-MESSAGES: :[[@LINE+1]]:3: warning: replace loop by 'std::ranges::any_

[PATCH] D81075: [ASTMatchers] Fix crash with HasName and HasAnyName

2020-06-03 Thread Nathan James via Phabricator via cfe-commits
njames93 created this revision.
njames93 added reviewers: klimek, sbenza.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Fixes crashes caused by matching fully qualified RecordDecls inside Function 
bodies.
See https://bugs.llvm.org/show_bug.cgi?id=43639.
I'm still unsure if this is the desired behaviour though.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D81075

Files:
  clang/include/clang/AST/PrettyPrinter.h
  clang/lib/AST/Decl.cpp
  clang/lib/ASTMatchers/ASTMatchersInternal.cpp
  clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp

Index: clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
@@ -1665,7 +1665,7 @@
   StringRef code =
   "namespace a { void F(int a) { struct S { int m; }; int i; } }";
   EXPECT_TRUE(matches(code, varDecl(hasName("i";
-  EXPECT_FALSE(matches(code, varDecl(hasName("F()::i";
+  EXPECT_FALSE(matches(code, varDecl(hasName("F(int)::i";
 
   EXPECT_TRUE(matches(code, fieldDecl(hasName("m";
   EXPECT_TRUE(matches(code, fieldDecl(hasName("S::m";
@@ -1674,6 +1674,34 @@
   EXPECT_TRUE(matches(code, fieldDecl(hasName("::a::F(int)::S::m";
 }
 
+TEST(Matcher, HasNameSupportsFunctionScopeRecordDecl) {
+  StringRef FuncCode = R"cc(
+void A() {
+  struct B {};
+})cc";
+  EXPECT_TRUE(matches(FuncCode, cxxRecordDecl(hasName("B";
+  EXPECT_TRUE(matches(FuncCode, cxxRecordDecl(hasName("A()::B";
+  EXPECT_TRUE(matches(FuncCode, cxxRecordDecl(hasName("::A()::B";
+  EXPECT_TRUE(notMatches(FuncCode, cxxRecordDecl(hasName("::B";
+
+  StringRef MethodCode = R"cc(
+struct A {
+  void B() {
+struct C {};
+  }
+};)cc";
+
+  EXPECT_TRUE(matches(MethodCode, cxxRecordDecl(hasName("C";
+  EXPECT_TRUE(matches(MethodCode, cxxRecordDecl(hasName("B()::C";
+  EXPECT_TRUE(
+  matches(MethodCode, cxxRecordDecl(hasName("A::B()::C";
+  EXPECT_TRUE(
+  matches(MethodCode, cxxRecordDecl(hasName("::A::B()::C";
+  EXPECT_TRUE(notMatches(MethodCode, cxxRecordDecl(hasName("::C";
+  EXPECT_TRUE(
+  notMatches(MethodCode, cxxRecordDecl(hasName("::B()::C";
+}
+
 TEST(Matcher, HasNameQualifiedSupportsLinkage) {
   // https://bugs.llvm.org/show_bug.cgi?id=42193
   StringRef code = R"cpp(namespace foo { extern "C" void test(); })cpp";
Index: clang/lib/ASTMatchers/ASTMatchersInternal.cpp
===
--- clang/lib/ASTMatchers/ASTMatchersInternal.cpp
+++ clang/lib/ASTMatchers/ASTMatchersInternal.cpp
@@ -571,7 +571,7 @@
   // We are allowed to skip anonymous and inline namespaces if they don't match.
   const DeclContext *Ctx = Node.getDeclContext();
 
-  if (Ctx->isFunctionOrMethod())
+  if (Ctx->isFunctionOrMethod() && !isa(Node))
 return Patterns.foundMatch(/*AllowFullyQualified=*/false);
 
   for (; Ctx; Ctx = Ctx->getParent()) {
@@ -616,13 +616,10 @@
 llvm::SmallString<128> NodeName = StringRef("::");
 llvm::raw_svector_ostream OS(NodeName);
 
-if (SkipUnwritten) {
-  PrintingPolicy Policy = Node.getASTContext().getPrintingPolicy();
-  Policy.SuppressUnwrittenScope = true;
-  Node.printQualifiedName(OS, Policy);
-} else {
-  Node.printQualifiedName(OS);
-}
+PrintingPolicy Policy = Node.getASTContext().getPrintingPolicy();
+Policy.PrintFunctionQualifiedRecords = true;
+Policy.SuppressUnwrittenScope = SkipUnwritten;
+Node.printQualifiedName(OS, Policy);
 
 const StringRef FullName = OS.str();
 
Index: clang/lib/AST/Decl.cpp
===
--- clang/lib/AST/Decl.cpp
+++ clang/lib/AST/Decl.cpp
@@ -1540,7 +1540,8 @@
 
 void NamedDecl::printQualifiedName(raw_ostream &OS,
const PrintingPolicy &P) const {
-  if (getDeclContext()->isFunctionOrMethod()) {
+  if (getDeclContext()->isFunctionOrMethod() &&
+  !(P.PrintFunctionQualifiedRecords && isa(this))) {
 // We do not print '(anonymous)' for function parameters without name.
 printName(OS);
 return;
@@ -1583,7 +1584,8 @@
   Ctx = CI;
   }
 
-  if (Ctx->isFunctionOrMethod())
+  if (Ctx->isFunctionOrMethod() &&
+  !(P.PrintFunctionQualifiedRecords && isa(this)))
 return;
 
   using ContextsTy = SmallVector;
Index: clang/include/clang/AST/PrettyPrinter.h
===
--- clang/include/clang/AST/PrettyPrinter.h
+++ clang/include/clang/AST/PrettyPrinter.h
@@ -63,7 +63,8 @@
 MSWChar(LO.MicrosoftExt && !LO.WChar), IncludeNewlines(true),
 MSVCFormatting(false), ConstantsAsWritten(false),
 SuppressImplicitBase(false), FullyQualifiedName(false),
-PrintCanonicalTypes(false), PrintInjectedClassNameWithArguments(true) {}
+   

[PATCH] D81066: [clangd] Populate the parse options to CodeCompletion/SignatureHelp.

2020-06-03 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added inline comments.
This revision is now accepted and ready to land.



Comment at: clang-tools-extra/clangd/CodeComplete.cpp:1108
+  std::move(CI),
+  !CompletingInPreamble ? &(Input.Preamble.Preamble) : nullptr,
   std::move(ContentsBuffer), std::move(VFS), IgnoreDiags);

this change looks suspicious, really needed?



Comment at: clang-tools-extra/clangd/Compiler.h:57
   const SymbolIndex *Index = nullptr;
-  ParseOptions Opts;
+  ParseOptions Opts = ParseOptions();
 };

this is the default already - only need to do this for scalar types that would 
otherwise have indeterminate default


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81066



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


[PATCH] D80366: [Analyzer] Add `getReturnValueUnderConstruction()` to `CallEvent`

2020-06-03 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added inline comments.



Comment at: clang/lib/StaticAnalyzer/Core/CallEvent.cpp:552
+
+  Index = StackFrame->getIndex();
+

baloghadamsoftware wrote:
> vsavchenko wrote:
> > Szelethus wrote:
> > > baloghadamsoftware wrote:
> > > > Szelethus wrote:
> > > > > This mustn't be serious. `StackFrameContext::getIndex()` has **no 
> > > > > comments** at all! So it is an index to the element within a 
> > > > > `CFGBlock` to which it also stores a field for??? Ugh. Shouldn't we 
> > > > > just have a `getCallSiteCFGElement` or something? Especially since we 
> > > > > have `CFGElementRef`s now.
> > > > > 
> > > > > Would you be so nice to hunt this down please? :)
> > > > Do you mean a new `StackFrameContext::getCFGElement()` member function? 
> > > > I agree. I can do it, however this technology where we get the block 
> > > > and the index separately is used at many places in the code, then it 
> > > > would be appropriate to refactor all these places. Even wrose is the 
> > > > backward direction, where we look for the CFG element of a statement: 
> > > > we find the block from `CFGStmtMap` and then we search for the index 
> > > > **liearly**, instrad of storing it in the map as well!!!
> > > Nasty. Yeah, I mean not to burden you work refactoring any more then you 
> > > feel like doing it, but simply adding a 
> > > `StackFrameContext::getCFGElement()` method and using it in this patch 
> > > would be nice enough, and some comments to `getIndex()`. But this 
> > > obviously isn't a high prio issue.
> > +1
> > I do believe that clearer interface functions and better segregation of 
> > different functionalities will make it much easier for us in the future
> I fully agree, but StackFrameContext is not in the StaticAnalyzer part, but 
> the Analysis part. I think that should be a separate patch. Who is the code 
> owner for that part?
It's us anyway. `StackFrameContext` is essentially analyzer-exclusive but even 
for things like CFG and analysis-based warnings in Clang, there's nobody else 
who maintains them except for the analyzer gang.



Comment at: clang/lib/StaticAnalyzer/Core/CallEvent.cpp:553
+
+  if(const auto Ctor = (*Block)[Index].getAs()) {
+return Ctor->getConstructionContext();

baloghadamsoftware wrote:
> vsavchenko wrote:
> > nit: space after `if`
> > 
> > And I would also prefer putting `const auto *Ctor`
> `Ctor` is not a pointer, but an `llvm::Optional`.
Ah, [[ https://reviews.llvm.org/D33672?id=171506#inline-475812 | classic ]].



Comment at: clang/lib/StaticAnalyzer/Core/CallEvent.cpp:543
+
+  const StackFrameContext *StackFrame = Call.getCalleeStackFrame(BlockCount);
+  if (!StackFrame)

It is clear that the final return value of `getConstructionContext()` does not 
depend on the current block count; in fact the information you're trying to 
obtain is purely syntactic. You probably might as well pass 0 here. As i 
mentioned before, the ideal solution would be to make `CallEvent` carry a 
`CFGElementRef` to begin with (as a replacement for the origin expr), so that 
it didn't need to be recovered like this.

We should absolutely eliminate the `BlockCount` parameter of 
`getReturnValueUnderConstruction()` as well. Checker developers shouldn't 
understand what it is, especially given that it doesn't matter at all which 
value do you pass.


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

https://reviews.llvm.org/D80366



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


[PATCH] D80876: [clang] Default to windows response files when running on windows

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

I don't have strong opinion here as I don't know this topic well (things just 
worked so far).
That said if Clang stops working as a drop-in replacement for GCC with commonly 
used build systems, MSYS2 will have to carry one more patch to bring back old 
behaviour.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80876



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


[PATCH] D77572: [clang-tidy] add new check readability-use-anyofallof

2020-06-03 Thread Matthias Gehre via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGadd51e152aa6: [clang-tidy] add new check 
readability-use-anyofallof (authored by mgehre).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77572

Files:
  clang-tools-extra/clang-tidy/readability/CMakeLists.txt
  clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tools-extra/clang-tidy/readability/UseAnyOfAllOfCheck.cpp
  clang-tools-extra/clang-tidy/readability/UseAnyOfAllOfCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/docs/clang-tidy/checks/readability-use-anyofallof.rst
  
clang-tools-extra/test/clang-tidy/checkers/readability-use-anyofallof-cpp20.cpp
  clang-tools-extra/test/clang-tidy/checkers/readability-use-anyofallof.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/readability-use-anyofallof.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/readability-use-anyofallof.cpp
@@ -0,0 +1,183 @@
+// RUN: %check_clang_tidy -std=c++14,c++17 %s readability-use-anyofallof %t
+
+bool good_any_of() {
+  int v[] = {1, 2, 3};
+  // CHECK-MESSAGES: :[[@LINE+1]]:3: warning: replace loop by 'std::any_of()' [readability-use-anyofallof]
+  for (int i : v)
+if (i)
+  return true;
+  return false;
+}
+
+bool cond(int i);
+
+bool good_any_of2() {
+  int v[] = {1, 2, 3};
+  for (int i : v) {
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: replace loop by 'std::any_of()'
+int k = i / 2;
+if (cond(k))
+  return true;
+  }
+  return false;
+}
+
+bool good_any_of3() {
+  int v[] = {1, 2, 3};
+  for (int i : v) {
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: replace loop by 'std::any_of()'
+if (i == 3)
+  continue;
+if (i)
+  return true;
+  }
+
+  return false;
+}
+
+bool good_any_of_use_external(int comp) {
+  int v[] = {1, 2, 3};
+  for (int i : v) {
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: replace loop by 'std::any_of()'
+if (i == comp)
+  return true;
+  }
+
+  return false;
+}
+
+bool good_any_of_no_cond() {
+  int v[] = {1, 2, 3};
+  for (int i : v) {
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: replace loop by 'std::any_of()'
+return true; // Not a real loop, but technically can become any_of.
+  }
+
+  return false;
+}
+
+bool good_any_of_local_modification() {
+  int v[] = {1, 2, 3};
+  for (int i : v) {
+int j = i;
+j++; // FIXME: Any non-const use disables check.
+if (j > 3)
+  return true;
+  }
+
+  return false;
+}
+
+bool good_any_of_throw() {
+  int v[] = {1, 2, 3};
+  for (int i : v) {
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: replace loop by 'std::any_of()'
+if (i > 3)
+  return true;
+if (i == 42)
+  throw 0;
+  }
+
+  return false;
+}
+
+bool bad_any_of1() {
+  int v[] = {1, 2, 3};
+  for (int i : v) {
+if (i)
+  return false; // bad constant
+  }
+  return false;
+}
+
+bool bad_any_of2() {
+  int v[] = {1, 2, 3};
+  for (int i : v)
+if (i)
+  return true;
+
+  return true; // bad return
+}
+
+bool bad_any_of3() {
+  int v[] = {1, 2, 3};
+  for (int i : v)
+if (i)
+  return true;
+else
+  return i / 2; // bad return
+
+  return false;
+}
+
+bool bad_any_of_control_flow1() {
+  int v[] = {1, 2, 3};
+  for (int i : v) {
+break; // bad control flow
+if (i)
+  return true;
+  }
+
+  return false;
+}
+
+bool bad_any_of_control_flow2() {
+  int v[] = {1, 2, 3};
+  for (int i : v) {
+goto end; // bad control flow
+if (i)
+  return true;
+  }
+
+  end:
+  return false;
+}
+
+bool bad_any_of4() {
+  return false; // wrong order
+
+  int v[] = {1, 2, 3};
+  for (int i : v) {
+if (i)
+  return true;
+  }
+}
+
+bool bad_any_of5() {
+  int v[] = {1, 2, 3};
+  int j = 0;
+  for (int i : v) {
+j++; // modifications
+if (i)
+  return true;
+  }
+  return false;
+}
+
+bool bad_any_of6() {
+  int v[] = {1, 2, 3};
+  for (int i : v) {
+if (i)
+  return true;
+  }
+  int j = 0; // Statements between loop and return
+  j++;
+  return false;
+}
+
+bool bad_any_of7() {
+  int v[] = {1, 2, 3};
+  for (int i : v) {
+i; // No 'return true' in body.
+  }
+  return false;
+}
+
+bool good_all_of() {
+  int v[] = {1, 2, 3};
+  // CHECK-MESSAGES: :[[@LINE+1]]:3: warning: replace loop by 'std::all_of()' [readability-use-anyofallof]
+  for (int i : v)
+if (i)
+  return false;
+  return true;
+}
Index: clang-tools-extra/test/clang-tidy/checkers/readability-use-anyofallof-cpp20.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/readability-use-anyofallof-cpp20.cpp
@@ -0,0 +1,19 @@
+// RUN: %check_clang_tidy -std=c++2a-or-later %s readability-use-anyofallof %t
+
+bool good_any_of() {
+  int v[] = {1, 2, 3};

[clang-tools-extra] fd27401 - attempt to fix build after add51e152aa

2020-06-03 Thread Nico Weber via cfe-commits

Author: Nico Weber
Date: 2020-06-03T06:49:50-04:00
New Revision: fd2740143e626ca32432aac0b51b2880a3b1e0bc

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

LOG: attempt to fix build after add51e152aa

Added: 


Modified: 
clang-tools-extra/clang-tidy/readability/UseAnyOfAllOfCheck.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/readability/UseAnyOfAllOfCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/UseAnyOfAllOfCheck.cpp
index d3c002f5ad1d..165acd40841f 100644
--- a/clang-tools-extra/clang-tidy/readability/UseAnyOfAllOfCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/UseAnyOfAllOfCheck.cpp
@@ -88,7 +88,7 @@ static bool isViableLoop(const CXXForRangeStmt &S, ASTContext 
&Context) {
 }
 
 void UseAnyOfAllOfCheck::check(const MatchFinder::MatchResult &Result) {
-  StringRef Ranges = getLangOpts().CPlusPlus2a ? "::ranges" : "";
+  StringRef Ranges = getLangOpts().CPlusPlus20 ? "::ranges" : "";
 
   if (const auto *S = Result.Nodes.getNodeAs("any_of_loop")) {
 if (!isViableLoop(*S, *Result.Context))



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


[PATCH] D79721: [Clang][AArch64] Capturing proper pointer alignment for Neon vld1 intrinsicts

2020-06-03 Thread Lucas Prates via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG8beaba13b8a6: [Clang][AArch64] Capturing proper pointer 
alignment for Neon vld1 intrinsicts (authored by pratlucas).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79721

Files:
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/aarch64-neon-intrinsics.c

Index: clang/test/CodeGen/aarch64-neon-intrinsics.c
===
--- clang/test/CodeGen/aarch64-neon-intrinsics.c
+++ clang/test/CodeGen/aarch64-neon-intrinsics.c
@@ -8956,7 +8956,7 @@
 
 // CHECK-LABEL: @test_vld1q_u8(
 // CHECK:   [[TMP0:%.*]] = bitcast i8* %a to <16 x i8>*
-// CHECK:   [[TMP1:%.*]] = load <16 x i8>, <16 x i8>* [[TMP0]]
+// CHECK:   [[TMP1:%.*]] = load <16 x i8>, <16 x i8>* [[TMP0]], align 1
 // CHECK:   ret <16 x i8> [[TMP1]]
 uint8x16_t test_vld1q_u8(uint8_t const *a) {
   return vld1q_u8(a);
@@ -8965,7 +8965,7 @@
 // CHECK-LABEL: @test_vld1q_u16(
 // CHECK:   [[TMP0:%.*]] = bitcast i16* %a to i8*
 // CHECK:   [[TMP1:%.*]] = bitcast i8* [[TMP0]] to <8 x i16>*
-// CHECK:   [[TMP2:%.*]] = load <8 x i16>, <8 x i16>* [[TMP1]]
+// CHECK:   [[TMP2:%.*]] = load <8 x i16>, <8 x i16>* [[TMP1]], align 2
 // CHECK:   ret <8 x i16> [[TMP2]]
 uint16x8_t test_vld1q_u16(uint16_t const *a) {
   return vld1q_u16(a);
@@ -8974,7 +8974,7 @@
 // CHECK-LABEL: @test_vld1q_u32(
 // CHECK:   [[TMP0:%.*]] = bitcast i32* %a to i8*
 // CHECK:   [[TMP1:%.*]] = bitcast i8* [[TMP0]] to <4 x i32>*
-// CHECK:   [[TMP2:%.*]] = load <4 x i32>, <4 x i32>* [[TMP1]]
+// CHECK:   [[TMP2:%.*]] = load <4 x i32>, <4 x i32>* [[TMP1]], align 4
 // CHECK:   ret <4 x i32> [[TMP2]]
 uint32x4_t test_vld1q_u32(uint32_t const *a) {
   return vld1q_u32(a);
@@ -8983,7 +8983,7 @@
 // CHECK-LABEL: @test_vld1q_u64(
 // CHECK:   [[TMP0:%.*]] = bitcast i64* %a to i8*
 // CHECK:   [[TMP1:%.*]] = bitcast i8* [[TMP0]] to <2 x i64>*
-// CHECK:   [[TMP2:%.*]] = load <2 x i64>, <2 x i64>* [[TMP1]]
+// CHECK:   [[TMP2:%.*]] = load <2 x i64>, <2 x i64>* [[TMP1]], align 8
 // CHECK:   ret <2 x i64> [[TMP2]]
 uint64x2_t test_vld1q_u64(uint64_t const *a) {
   return vld1q_u64(a);
@@ -8991,7 +8991,7 @@
 
 // CHECK-LABEL: @test_vld1q_s8(
 // CHECK:   [[TMP0:%.*]] = bitcast i8* %a to <16 x i8>*
-// CHECK:   [[TMP1:%.*]] = load <16 x i8>, <16 x i8>* [[TMP0]]
+// CHECK:   [[TMP1:%.*]] = load <16 x i8>, <16 x i8>* [[TMP0]], align 1
 // CHECK:   ret <16 x i8> [[TMP1]]
 int8x16_t test_vld1q_s8(int8_t const *a) {
   return vld1q_s8(a);
@@ -9000,7 +9000,7 @@
 // CHECK-LABEL: @test_vld1q_s16(
 // CHECK:   [[TMP0:%.*]] = bitcast i16* %a to i8*
 // CHECK:   [[TMP1:%.*]] = bitcast i8* [[TMP0]] to <8 x i16>*
-// CHECK:   [[TMP2:%.*]] = load <8 x i16>, <8 x i16>* [[TMP1]]
+// CHECK:   [[TMP2:%.*]] = load <8 x i16>, <8 x i16>* [[TMP1]], align 2
 // CHECK:   ret <8 x i16> [[TMP2]]
 int16x8_t test_vld1q_s16(int16_t const *a) {
   return vld1q_s16(a);
@@ -9009,7 +9009,7 @@
 // CHECK-LABEL: @test_vld1q_s32(
 // CHECK:   [[TMP0:%.*]] = bitcast i32* %a to i8*
 // CHECK:   [[TMP1:%.*]] = bitcast i8* [[TMP0]] to <4 x i32>*
-// CHECK:   [[TMP2:%.*]] = load <4 x i32>, <4 x i32>* [[TMP1]]
+// CHECK:   [[TMP2:%.*]] = load <4 x i32>, <4 x i32>* [[TMP1]], align 4
 // CHECK:   ret <4 x i32> [[TMP2]]
 int32x4_t test_vld1q_s32(int32_t const *a) {
   return vld1q_s32(a);
@@ -9018,7 +9018,7 @@
 // CHECK-LABEL: @test_vld1q_s64(
 // CHECK:   [[TMP0:%.*]] = bitcast i64* %a to i8*
 // CHECK:   [[TMP1:%.*]] = bitcast i8* [[TMP0]] to <2 x i64>*
-// CHECK:   [[TMP2:%.*]] = load <2 x i64>, <2 x i64>* [[TMP1]]
+// CHECK:   [[TMP2:%.*]] = load <2 x i64>, <2 x i64>* [[TMP1]], align 8
 // CHECK:   ret <2 x i64> [[TMP2]]
 int64x2_t test_vld1q_s64(int64_t const *a) {
   return vld1q_s64(a);
@@ -9027,7 +9027,7 @@
 // CHECK-LABEL: @test_vld1q_f16(
 // CHECK:   [[TMP0:%.*]] = bitcast half* %a to i8*
 // CHECK:   [[TMP1:%.*]] = bitcast i8* [[TMP0]] to <8 x half>*
-// CHECK:   [[TMP2:%.*]] = load <8 x half>, <8 x half>* [[TMP1]]
+// CHECK:   [[TMP2:%.*]] = load <8 x half>, <8 x half>* [[TMP1]], align 2
 // CHECK:   ret <8 x half> [[TMP2]]
 float16x8_t test_vld1q_f16(float16_t const *a) {
   return vld1q_f16(a);
@@ -9036,7 +9036,7 @@
 // CHECK-LABEL: @test_vld1q_f32(
 // CHECK:   [[TMP0:%.*]] = bitcast float* %a to i8*
 // CHECK:   [[TMP1:%.*]] = bitcast i8* [[TMP0]] to <4 x float>*
-// CHECK:   [[TMP2:%.*]] = load <4 x float>, <4 x float>* [[TMP1]]
+// CHECK:   [[TMP2:%.*]] = load <4 x float>, <4 x float>* [[TMP1]], align 4
 // CHECK:   ret <4 x float> [[TMP2]]
 float32x4_t test_vld1q_f32(float32_t const *a) {
   return vld1q_f32(a);
@@ -9045,7 +9045,7 @@
 // CHECK-LABEL: @test_vld1q_f64(
 // CHECK:   [[TMP0:%.*]] = bitcast double* %a to i8*
 // CHECK:   [[TMP1:%.*]] = bitcast i8* [[TMP0]] to <2 x double>*
-// CHECK:   [[TMP2:%.*]] = load <2 x double>, <2 x double>* [[TMP1]]
+// CHECK:   [[TMP2:%.*]] = load <2 x double>, 

[PATCH] D81069: [clangd] Don't build diagnostics when preparing AST for a normal action.

2020-06-03 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clang-tools-extra/clangd/ParsedAST.cpp:369
+  Inputs.Index && !BuildDir.getError()) {
 auto Style = getFormatStyleForFile(Filename, Inputs.Contents, VFS.get());
 auto Inserter = std::make_shared(

while here, maybe introduce another span for include fixer initialization ?

as `getFormatStyle` can do IO



Comment at: clang-tools-extra/clangd/ParsedAST.cpp:374
 if (Preamble) {
   for (const auto &Inc : Preamble->Includes.MainFileIncludes)
 Inserter->addExisting(Inc);

umm, actually this is wrong in presence of stale preambles ... we should 
perform patching before initializing include fixer and make use of patched 
includes rather than stale ones.

no action needing, just taking a note for myself.



Comment at: clang-tools-extra/clangd/ParsedAST.cpp:434
   Clang->getASTContext().setTraversalScope(ParsedDecls);
-  {
+  if (CTFinder.hasValue()) {
 // Run the AST-dependent part of the clang-tidy checks.

maybe
```
if (ProduceDiagnostics) {
 assert(CTFinder.hasValue());
...
}
```

to keep it similar to other usages.



Comment at: clang-tools-extra/clangd/TUScheduler.h:113
 /// Indicates whether we reused the prebuilt AST.
+/// FIXME: always false, diagnostics are always built from fresh ASTs.
 bool ReuseAST = false;

why don't we just drop this ? I believe this patch is doing 2 things:
- Don't build diagnostics for read operations
- Don't reuse cached asts for diagnostics

and I think getting rid of `ReuseAST` bit would belong to second one. (unless 
we decide to emit status while building asts for read operations)



Comment at: clang-tools-extra/clangd/unittests/ParsedASTTests.cpp:470
+TEST(ParsedASTTest, NoDiagnostics) {
+  static bool TidyCheckIsError;
+  // A simple clang-tidy check, which we can verify:

nit: initialize to false



Comment at: clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp:540
+  // Build one file in advance.
+  S.update(Foo, getInputs(Foo, SourceContents.str()), WantDiagnostics::Yes);
   ASSERT_TRUE(S.blockUntilIdle(timeoutSeconds(10)));

WantDiags::Auto should be enough here, as we are blocking afterwards. I've 
heard someone is tryin to get rid of those :P



Comment at: clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp:546
+  // Build two more files.
+  S.update(Bar, getInputs(Foo, SourceContents.str()), WantDiagnostics::Yes);
+  S.update(Baz, getInputs(Foo, SourceContents.str()), WantDiagnostics::Yes);

again WantDiags::Auto should do for both



Comment at: clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp:796
   [](std::vector) { ADD_FAILURE() << "Should not be called."; });
   S.runWithAST("touchAST", FooCpp, [](Expected IA) {
 // Make sure the AST was actually built.

is it worth asserting here (or in a new test) that AST.diags() is empty, 
whereas it is non-empty below ? (ofc, after introducing some diags to the code)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81069



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


[PATCH] D80522: [Analyzer] [NFC] Parameter Regions

2020-06-03 Thread Balogh , Ádám via Phabricator via cfe-commits
baloghadamsoftware updated this revision to Diff 268131.
baloghadamsoftware added a comment.

Comment fixed.


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

https://reviews.llvm.org/D80522

Files:
  clang/include/clang/StaticAnalyzer/Checkers/SValExplainer.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/Regions.def
  clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
  clang/lib/StaticAnalyzer/Core/CallEvent.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
  clang/lib/StaticAnalyzer/Core/MemRegion.cpp
  clang/lib/StaticAnalyzer/Core/Store.cpp
  clang/test/Analysis/explain-svals.c
  clang/test/Analysis/explain-svals.cpp
  clang/test/Analysis/explain-svals.m
  clang/unittests/StaticAnalyzer/CMakeLists.txt
  clang/unittests/StaticAnalyzer/ParamRegionTest.cpp

Index: clang/unittests/StaticAnalyzer/ParamRegionTest.cpp
===
--- /dev/null
+++ clang/unittests/StaticAnalyzer/ParamRegionTest.cpp
@@ -0,0 +1,109 @@
+//===- unittests/StaticAnalyzer/ParamRegionTest.cpp ---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "Reusables.h"
+
+#include "clang/Tooling/Tooling.h"
+#include "gtest/gtest.h"
+
+namespace clang {
+namespace ento {
+namespace {
+
+class ParamRegionTestConsumer : public ExprEngineConsumer {
+  void performTest(const Decl *D) {
+StoreManager &StMgr = Eng.getStoreManager();
+MemRegionManager &MRMgr = StMgr.getRegionManager();
+const StackFrameContext *SFC =
+Eng.getAnalysisDeclContextManager().getStackFrame(D);
+
+if (const auto *FD = dyn_cast(D)) {
+  for (const auto *P : FD->parameters()) {
+const TypedValueRegion *Reg = MRMgr.getVarRegion(P, SFC);
+if (SFC->inTopFrame())
+  assert(isa(Reg));
+else
+  assert(isa(Reg));
+  }
+} else if (const auto *CD = dyn_cast(D)) {
+  for (const auto *P : CD->parameters()) {
+const TypedValueRegion *Reg = MRMgr.getVarRegion(P, SFC);
+if (SFC->inTopFrame())
+  assert(isa(Reg));
+else
+  assert(isa(Reg));
+  }
+} else if (const auto *MD = dyn_cast(D)) {
+  for (const auto *P : MD->parameters()) {
+const TypedValueRegion *Reg = MRMgr.getVarRegion(P, SFC);
+if (SFC->inTopFrame())
+  assert(isa(Reg));
+else
+  assert(isa(Reg));
+  }
+}
+  }
+
+public:
+  ParamRegionTestConsumer(CompilerInstance &C) : ExprEngineConsumer(C) {}
+
+  bool HandleTopLevelDecl(DeclGroupRef DG) override {
+for (const auto *D : DG) {
+  performTest(D);
+}
+return true;
+  }
+};
+
+class ParamRegionTestAction : public ASTFrontendAction {
+public:
+  std::unique_ptr CreateASTConsumer(CompilerInstance &Compiler,
+ StringRef File) override {
+return std::make_unique(Compiler);
+  }
+};
+
+TEST(ParamRegion, ParamRegionTest) {
+  EXPECT_TRUE(
+  tooling::runToolOnCode(std::make_unique(),
+ R"(void foo(int n) {
+ auto lambda = [n](int m) {
+   return n + m;
+ };
+
+ int k = lambda(2);
+   }
+
+   void bar(int l) {
+ foo(l);
+   }
+
+   struct S {
+ int n;
+ S(int nn): n(nn) {}
+   };
+
+   void baz(int p) {
+ S s(p);
+   })"));
+  EXPECT_TRUE(
+  tooling::runToolOnCode(std::make_unique(),
+ R"(@interface O
+   + alloc;
+   - initWithInt:(int)q;
+   @end
+
+   void qix(int r) {
+ O *o = [[O alloc] initWithInt:r];
+   })",
+ "input.m"));
+}
+
+} // namespace
+} // namespace ento
+} // namespace clang
Index: clang/unittests/StaticAnalyzer/CMakeLists.txt
===
--- clang/unittests/StaticAnalyzer/CMakeLists.txt
+++ clang/unittests/StaticAnalyzer/CMakeLists.txt
@@ -8,6 +8,7 @@
 

[PATCH] D80522: [Analyzer] [NFC] Parameter Regions

2020-06-03 Thread Balogh , Ádám via Phabricator via cfe-commits
baloghadamsoftware marked 2 inline comments as done.
baloghadamsoftware added inline comments.



Comment at: 
clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h:921
+public:
+  const VarDecl *getDecl() const override = 0;
+

NoQ wrote:
> What's the point of overriding one pure virtual method with another pure 
> virtual method?
To constrain the return value from `Decl` to `VarDecl`. Without this we have 
change all the callers to cast the return value from this function to 
`VarDecl`. It would be ugly.


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

https://reviews.llvm.org/D80522



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


[PATCH] D77572: [clang-tidy] add new check readability-use-anyofallof

2020-06-03 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr2 added a comment.

This change broke the build: 
http://lab.llvm.org:8011/builders/clang-x86_64-debian-fast/builds/29716. The 
build is already fixed by 
https://github.com/llvm/llvm-project/commit/fd2740143e626ca32432aac0b51b2880a3b1e0bc.

Please always run `ninja check-all` before pushing commits. Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77572



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


[PATCH] D80514: [clang-tidy] modernize-use-trailing-return-type support for C++20 concepts and decltype

2020-06-03 Thread Bernhard Manfred Gruber via Phabricator via cfe-commits
bernhardmgruber added a comment.

Ping.

Furthermore: how can I schedule another CI build with the newest version of the 
diff? When I go to the failed build from Harbormaster and I click restart, it 
rebuilds an older version of the diff. Thanks for the info!


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

https://reviews.llvm.org/D80514



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


[PATCH] D81080: [clang-tidy] Compile fix: Change CPlusPlus2a to CPlusPlus20.

2020-06-03 Thread Martin Böhme via Phabricator via cfe-commits
mboehme created this revision.
mboehme added a reviewer: sammccall.
mboehme added a project: clang-tools-extra.
Herald added subscribers: cfe-commits, xazax.hun.
Herald added a project: clang.

The name of the option was changed here:

https://github.com/llvm/llvm-project/commit/6a30894391ca671bab16c505eff30c7819bd8e8e


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D81080

Files:
  clang-tools-extra/clang-tidy/readability/UseAnyOfAllOfCheck.cpp


Index: clang-tools-extra/clang-tidy/readability/UseAnyOfAllOfCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/UseAnyOfAllOfCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/UseAnyOfAllOfCheck.cpp
@@ -88,7 +88,7 @@
 }
 
 void UseAnyOfAllOfCheck::check(const MatchFinder::MatchResult &Result) {
-  StringRef Ranges = getLangOpts().CPlusPlus2a ? "::ranges" : "";
+  StringRef Ranges = getLangOpts().CPlusPlus20 ? "::ranges" : "";
 
   if (const auto *S = Result.Nodes.getNodeAs("any_of_loop")) {
 if (!isViableLoop(*S, *Result.Context))


Index: clang-tools-extra/clang-tidy/readability/UseAnyOfAllOfCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/UseAnyOfAllOfCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/UseAnyOfAllOfCheck.cpp
@@ -88,7 +88,7 @@
 }
 
 void UseAnyOfAllOfCheck::check(const MatchFinder::MatchResult &Result) {
-  StringRef Ranges = getLangOpts().CPlusPlus2a ? "::ranges" : "";
+  StringRef Ranges = getLangOpts().CPlusPlus20 ? "::ranges" : "";
 
   if (const auto *S = Result.Nodes.getNodeAs("any_of_loop")) {
 if (!isViableLoop(*S, *Result.Context))
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D81079: [clangd] Add std::move() to a return statement to please some compilers.

2020-06-03 Thread Martin Böhme via Phabricator via cfe-commits
mboehme created this revision.
mboehme added a reviewer: sammccall.
mboehme added a project: clang-tools-extra.
Herald added subscribers: cfe-commits, usaxena95, kadircet, arphaman, jkorous, 
MaskRay, ilya-biryukov.
Herald added a project: clang.

This has been causing build errors in Swift CI.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D81079

Files:
  clang-tools-extra/clangd/index/FileIndex.cpp


Index: clang-tools-extra/clangd/index/FileIndex.cpp
===
--- clang-tools-extra/clangd/index/FileIndex.cpp
+++ clang-tools-extra/clangd/index/FileIndex.cpp
@@ -201,7 +201,8 @@
 RelB.insert(*Rel);
   }
   IF.Relations = std::move(RelB).build();
-  return IF;
+  // Explicit move here is needed by some compilers.
+  return std::move(IF);
 }
 
 SlabTuple indexMainDecls(ParsedAST &AST) {


Index: clang-tools-extra/clangd/index/FileIndex.cpp
===
--- clang-tools-extra/clangd/index/FileIndex.cpp
+++ clang-tools-extra/clangd/index/FileIndex.cpp
@@ -201,7 +201,8 @@
 RelB.insert(*Rel);
   }
   IF.Relations = std::move(RelB).build();
-  return IF;
+  // Explicit move here is needed by some compilers.
+  return std::move(IF);
 }
 
 SlabTuple indexMainDecls(ParsedAST &AST) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] a2f32bf - [clang][Sema] SequenceChecker: C++17 sequencing rule for call expressions.

2020-06-03 Thread Bruno Ricci via cfe-commits

Author: Bruno Ricci
Date: 2020-06-03T12:35:12+01:00
New Revision: a2f32bfcc7cd6828785011ce90f6e0314d096e89

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

LOG: [clang][Sema] SequenceChecker: C++17 sequencing rule for call expressions.

In C++17 the postfix-expression of a call expression is sequenced before
each expression in the expression-list and any default argument.

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

Reviewed By: rsmith

Added: 


Modified: 
clang/lib/Sema/SemaChecking.cpp
clang/test/SemaCXX/warn-unsequenced.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index c9fa2b993c1e..64df2740145b 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -12928,6 +12928,11 @@ class SequenceChecker : public 
ConstEvaluatedExprVisitor {
   }
 
   void VisitCallExpr(const CallExpr *CE) {
+// FIXME: CXXNewExpr and CXXDeleteExpr implicitly call functions.
+
+if (CE->isUnevaluatedBuiltinCall(Context))
+  return;
+
 // C++11 [intro.execution]p15:
 //   When calling a function [...], every value computation and side effect
 //   associated with any argument expression, or with the postfix 
expression
@@ -12935,10 +12940,41 @@ class SequenceChecker : public 
ConstEvaluatedExprVisitor {
 //   expression or statement in the body of the function [and thus before
 //   the value computation of its result].
 SequencedSubexpression Sequenced(*this);
-SemaRef.runWithSufficientStackSpace(CE->getExprLoc(),
-[&] { Base::VisitCallExpr(CE); });
+SemaRef.runWithSufficientStackSpace(CE->getExprLoc(), [&] {
+  // C++17 [expr.call]p5
+  //   The postfix-expression is sequenced before each expression in the
+  //   expression-list and any default argument. [...]
+  SequenceTree::Seq CalleeRegion;
+  SequenceTree::Seq OtherRegion;
+  if (SemaRef.getLangOpts().CPlusPlus17) {
+CalleeRegion = Tree.allocate(Region);
+OtherRegion = Tree.allocate(Region);
+  } else {
+CalleeRegion = Region;
+OtherRegion = Region;
+  }
+  SequenceTree::Seq OldRegion = Region;
 
-// FIXME: CXXNewExpr and CXXDeleteExpr implicitly call functions.
+  // Visit the callee expression first.
+  Region = CalleeRegion;
+  if (SemaRef.getLangOpts().CPlusPlus17) {
+SequencedSubexpression Sequenced(*this);
+Visit(CE->getCallee());
+  } else {
+Visit(CE->getCallee());
+  }
+
+  // Then visit the argument expressions.
+  Region = OtherRegion;
+  for (const Expr *Argument : CE->arguments())
+Visit(Argument);
+
+  Region = OldRegion;
+  if (SemaRef.getLangOpts().CPlusPlus17) {
+Tree.merge(CalleeRegion);
+Tree.merge(OtherRegion);
+  }
+});
   }
 
   void VisitCXXConstructExpr(const CXXConstructExpr *CCE) {

diff  --git a/clang/test/SemaCXX/warn-unsequenced.cpp 
b/clang/test/SemaCXX/warn-unsequenced.cpp
index 62f725bd0712..84b0f9fd5b2f 100644
--- a/clang/test/SemaCXX/warn-unsequenced.cpp
+++ b/clang/test/SemaCXX/warn-unsequenced.cpp
@@ -15,7 +15,6 @@ struct S {
   int n;
 };
 
-// TODO: Implement the C++17 sequencing rules.
 void test() {
   int a;
   int xs[10];
@@ -256,6 +255,27 @@ void test() {
   p[i++] = (i = 42); // cxx11-warning {{multiple unsequenced modifications to 
'i'}}
   p++[i++] = (i = p ? i++ : i++); // cxx11-warning {{unsequenced modification 
and access to 'p'}}
   // cxx11-warning@-1 {{multiple unsequenced 
modifications to 'i'}}
+
+  (i++, f)(i++, 42); // cxx11-warning {{multiple unsequenced modifications to 
'i'}}
+  (i++ + i++, f)(42, 42); // cxx11-warning {{multiple unsequenced 
modifications to 'i'}}
+  // cxx17-warning@-1 {{multiple unsequenced 
modifications to 'i'}}
+  int (*pf)(int, int);
+  (pf = f)(pf != nullptr, pf != nullptr); // cxx11-warning {{unsequenced 
modification and access to 'pf'}}
+  pf((pf = f) != nullptr, 42); // cxx11-warning {{unsequenced modification and 
access to 'pf'}}
+  f((pf = f, 42), (pf = f, 42)); // cxx11-warning {{multiple unsequenced 
modifications to 'pf'}}
+ // cxx17-warning@-1 {{multiple unsequenced 
modifications to 'pf'}}
+  pf((pf = f) != nullptr, pf == nullptr); // cxx11-warning {{unsequenced 
modification and access to 'pf'}}
+  // cxx17-warning@-1 {{unsequenced 
modification and access to 'pf'}}
+}
+
+namespace PR20819 {
+  struct foo { void bar(int); };
+  foo get_foo(int);
+
+  void g() {
+int a = 0;
+get_foo(a).bar(a++);  // cxx11-warning {{unsequenced modification and 
access to 'a'}}
+  }
 }
 

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

2020-06-03 Thread Simon Moll via Phabricator via cfe-commits
simoll created this revision.
simoll added reviewers: hfinkel, erichkeane, craig.topper, rsandifo-arm, kaz7, 
k-ishizaka.
simoll added a project: clang.
Herald added subscribers: cfe-commits, kristof.beyls.
Herald added a reviewer: rengolin.
simoll updated this revision to Diff 268140.
simoll added a comment.

NFC. Undid stray change.


This patch extends Clang to allow 'bool' as a valid vector element type 
(attribute `vector_size`).

This is the natural type for SIMD masks and facilitates clean vector intrinsic 
declarations.
Vectors of i1 are supported on IR level and below down to many SIMD ISAs, such 
as AVX512, ARM SVE (fixed vector length) and the VE target (NEC SX-Aurora 
TSUBASA).

The RFC on cfe-dev: 
https://lists.llvm.org/pipermail/cfe-dev/2020-May/065434.html


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D81083

Files:
  clang/docs/LanguageExtensions.rst
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/TypePrinter.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/lib/CodeGen/CGRecordLayoutBuilder.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/CodeGen/CodeGenTypes.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/SemaCXX/vector.cpp

Index: clang/test/SemaCXX/vector.cpp
===
--- clang/test/SemaCXX/vector.cpp
+++ clang/test/SemaCXX/vector.cpp
@@ -331,8 +331,7 @@
 typedef __attribute__((ext_vector_type(4))) int vi4;
 const int &reference_to_vec_element = vi4(1).x;
 
-// PR12649
-typedef bool bad __attribute__((__vector_size__(16)));  // expected-error {{invalid vector element type 'bool'}}
+typedef bool good __attribute__((__vector_size__(16)));
 
 namespace Templates {
 template 
@@ -350,9 +349,7 @@
 void Init() {
   const TemplateVectorType::type Works = {};
   const TemplateVectorType::type Works2 = {};
-  // expected-error@#1 {{invalid vector element type 'bool'}}
-  // expected-note@+1 {{in instantiation of template class 'Templates::TemplateVectorType' requested here}}
-  const TemplateVectorType::type NoBool = {};
+  const TemplateVectorType::type BoolWorks = {};
   // expected-error@#1 {{invalid vector element type 'int __attribute__((ext_vector_type(4)))' (vector of 4 'int' values)}}
   // expected-note@+1 {{in instantiation of template class 'Templates::TemplateVectorType' requested here}}
   const TemplateVectorType::type NoComplex = {};
Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -2464,10 +2464,10 @@
 
 QualType Sema::BuildVectorType(QualType CurType, Expr *SizeExpr,
SourceLocation AttrLoc) {
-  // The base type must be integer (not Boolean or enumeration) or float, and
+  // The base type must be boolean or integer (not enumeration) or float, and
   // can't already be a vector.
   if (!CurType->isDependentType() &&
-  (!CurType->isBuiltinType() || CurType->isBooleanType() ||
+  (!CurType->isBuiltinType() ||
(!CurType->isIntegerType() && !CurType->isRealFloatingType( {
 Diag(AttrLoc, diag::err_attribute_invalid_vector_type) << CurType;
 return QualType();
@@ -2496,8 +2496,14 @@
 << SizeExpr->getSourceRange() << "vector";
 return QualType();
   }
-  uint64_t VectorSizeBits = VecSize.getZExtValue() * 8;
-  unsigned TypeSize = static_cast(Context.getTypeSize(CurType));
+
+  uint64_t VectorSizeBits =
+  CurType->isBooleanType()
+  ? VecSize.getZExtValue()
+  : VecSize.getZExtValue() * 8; // FIXME "bitsof(CharUnit)"
+  unsigned TypeSize = CurType->isBooleanType()
+  ? 1
+  : static_cast(Context.getTypeSize(CurType));
 
   if (VectorSizeBits == 0) {
 Diag(AttrLoc, diag::err_attribute_zero_size)
@@ -7549,13 +7555,13 @@
   T = Context.getAdjustedType(T, Wrapped);
 }
 
-/// HandleVectorSizeAttribute - this attribute is only applicable to integral
-/// and float scalars, although arrays, pointers, and function return values are
-/// allowed in conjunction with this construct. Aggregates with this attribute
-/// are invalid, even if they are of the same size as a corresponding scalar.
-/// The raw attribute should contain precisely 1 argument, the vector size for
-/// the variable, measured in bytes. If curType and rawAttr are well formed,
-/// this routine will return a new vector type.
+/// HandleVectorSizeAttribute - this attribute is only applicable to boolean,
+/// integral and float scalars, although arrays, pointers, and function return
+/// values are allowed in conjunction with this construct. Aggregates with this
+/// attribute are invalid, even if they are of the same size as a corresponding
+/// scalar. The raw attribute should conta

[PATCH] D80950: [clang-format] [PR44542,38872] String << String always get a forced newline.

2020-06-03 Thread Marek Kurdej via Phabricator via cfe-commits
curdeius added a comment.

I would have nothing against if you'd added this option and we kept current 
behaviour by default.
The only drawback is the (bit of) complexity it adds bit that seems justified 
to me.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80950



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


[PATCH] D69825: [Clang][Driver] Re-use the calling process instead of creating a new process for the cc1 invocation

2020-06-03 Thread Hans Wennborg via Phabricator via cfe-commits
hans added a comment.

In D69825#2063979 , @dim wrote:

> FWIW, this change causes 
> https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=246630, see in particular 
> https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=246630#c18.
>
> For some reason, not spawning a new process for the cc1 stage can lead to 
> non-reproducible output. The exact cause is not known yet.


Can you share the preprocessed source and compiler command-line for printf.c, 
either on the bug or here?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69825



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


[PATCH] D80536: [clang-tidy][modernize-loop-convert] Make loop var type human readable

2020-06-03 Thread Nathan James via Phabricator via cfe-commits
njames93 accepted this revision.
njames93 added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80536



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


[PATCH] D80887: [clang-tidy] ignore builtin varargs from pro-type-vararg-check

2020-06-03 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: 
clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeVarargCheck.cpp:39
+"__builtin_classify_type",
+// "__builtin_va_start",
+// "__builtin_stdarg_start",

I think we may want to keep this one as it's the builtin for the `va_start` 
macro, which is not variadic.



Comment at: 
clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeVarargCheck.cpp:40
+// "__builtin_va_start",
+// "__builtin_stdarg_start",
+"__builtin_assume_aligned", // Documented as variadic to support 
overloading

Should remove commented-out code from the list.



Comment at: 
clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeVarargCheck.cpp:41
+// "__builtin_stdarg_start",
+"__builtin_assume_aligned", // Documented as variadic to support 
overloading
+// "__builtin_fprintf",

If it's documented as being variadic, I think we want to remove it from the 
list so we warn on its use, right?

From here on down look like things that are not part of any standard, also, so 
we may want to remove them based on that, too.



Comment at: 
clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeVarargCheck.cpp:49
+// "__builtin___printf_chk",
+"__builtin_prefetch",  // Documented as variadic to support overloading
+"__builtin_shufflevector", // Documented as variadic but with a defined

Same here.



Comment at: 
clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeVarargCheck.cpp:63
+// "__builtin_os_log_format",
+// "__builtin_ms_va_start",
+// clang-format on

Except for this one -- I think we may want to keep this one because it's the MS 
version of `va_start`, which is not variadic.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80887



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


[PATCH] D80522: [Analyzer] [NFC] Parameter Regions

2020-06-03 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added inline comments.



Comment at: 
clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h:921
+public:
+  const VarDecl *getDecl() const override = 0;
+

baloghadamsoftware wrote:
> NoQ wrote:
> > What's the point of overriding one pure virtual method with another pure 
> > virtual method?
> To constrain the return value from `Decl` to `VarDecl`. Without this we have 
> change all the callers to cast the return value from this function to 
> `VarDecl`. It would be ugly.
Aha, covariance! Nice!


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

https://reviews.llvm.org/D80522



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


[PATCH] D81061: [Analyzer][VLASizeChecker] Fix problem with zero index assumption.

2020-06-03 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp:127-129
+// Despite the previous assumptions for non-zero and positiveness,
+// this value might be zero or negative.
+// At least check for zero again.

If we aim for a better fix, can we reduce the number of assumptions we make 
from 2 to 1? Like, it's ok if it's imperfect; 1 imperfect assumption is better 
than 2 imperfect assumptions.

The mental model i'm following here is that every path-sensitive bug can be 
thought of as a single formula over symbolic expressions. Eg., division by zero 
is the formula `"$denominator == 0" is definitely true`, double close is 
`"is_closed($file_being_closed)"`, division by tainted value is `"$denominator 
== 0" is possibly true AND "is_tainted($denominator)"`. I'd like you to write 
down the single formula that represents your bug and perform a single assume() 
over that and use the result of such assume as an ultimate source of truth. If 
such assume is not working correctly, let's think how to fix the assume rather 
than pile up more assumes in every checker to manually cross-check each other.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81061



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


[PATCH] D58579: [Sema] SequenceChecker: C++17 sequencing rule for call expressions.

2020-06-03 Thread Bruno Ricci via Phabricator via cfe-commits
riccibruno added a comment.

Great! thanks for the review @rsmith .


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D58579



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


[PATCH] D58579: [Sema] SequenceChecker: C++17 sequencing rule for call expressions.

2020-06-03 Thread Bruno Ricci via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa2f32bfcc7cd: [clang][Sema] SequenceChecker: C++17 
sequencing rule for call expressions. (authored by riccibruno).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D58579

Files:
  clang/lib/Sema/SemaChecking.cpp
  clang/test/SemaCXX/warn-unsequenced.cpp

Index: clang/test/SemaCXX/warn-unsequenced.cpp
===
--- clang/test/SemaCXX/warn-unsequenced.cpp
+++ clang/test/SemaCXX/warn-unsequenced.cpp
@@ -15,7 +15,6 @@
   int n;
 };
 
-// TODO: Implement the C++17 sequencing rules.
 void test() {
   int a;
   int xs[10];
@@ -256,6 +255,27 @@
   p[i++] = (i = 42); // cxx11-warning {{multiple unsequenced modifications to 'i'}}
   p++[i++] = (i = p ? i++ : i++); // cxx11-warning {{unsequenced modification and access to 'p'}}
   // cxx11-warning@-1 {{multiple unsequenced modifications to 'i'}}
+
+  (i++, f)(i++, 42); // cxx11-warning {{multiple unsequenced modifications to 'i'}}
+  (i++ + i++, f)(42, 42); // cxx11-warning {{multiple unsequenced modifications to 'i'}}
+  // cxx17-warning@-1 {{multiple unsequenced modifications to 'i'}}
+  int (*pf)(int, int);
+  (pf = f)(pf != nullptr, pf != nullptr); // cxx11-warning {{unsequenced modification and access to 'pf'}}
+  pf((pf = f) != nullptr, 42); // cxx11-warning {{unsequenced modification and access to 'pf'}}
+  f((pf = f, 42), (pf = f, 42)); // cxx11-warning {{multiple unsequenced modifications to 'pf'}}
+ // cxx17-warning@-1 {{multiple unsequenced modifications to 'pf'}}
+  pf((pf = f) != nullptr, pf == nullptr); // cxx11-warning {{unsequenced modification and access to 'pf'}}
+  // cxx17-warning@-1 {{unsequenced modification and access to 'pf'}}
+}
+
+namespace PR20819 {
+  struct foo { void bar(int); };
+  foo get_foo(int);
+
+  void g() {
+int a = 0;
+get_foo(a).bar(a++);  // cxx11-warning {{unsequenced modification and access to 'a'}}
+  }
 }
 
 namespace members {
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -12928,6 +12928,11 @@
   }
 
   void VisitCallExpr(const CallExpr *CE) {
+// FIXME: CXXNewExpr and CXXDeleteExpr implicitly call functions.
+
+if (CE->isUnevaluatedBuiltinCall(Context))
+  return;
+
 // C++11 [intro.execution]p15:
 //   When calling a function [...], every value computation and side effect
 //   associated with any argument expression, or with the postfix expression
@@ -12935,10 +12940,41 @@
 //   expression or statement in the body of the function [and thus before
 //   the value computation of its result].
 SequencedSubexpression Sequenced(*this);
-SemaRef.runWithSufficientStackSpace(CE->getExprLoc(),
-[&] { Base::VisitCallExpr(CE); });
+SemaRef.runWithSufficientStackSpace(CE->getExprLoc(), [&] {
+  // C++17 [expr.call]p5
+  //   The postfix-expression is sequenced before each expression in the
+  //   expression-list and any default argument. [...]
+  SequenceTree::Seq CalleeRegion;
+  SequenceTree::Seq OtherRegion;
+  if (SemaRef.getLangOpts().CPlusPlus17) {
+CalleeRegion = Tree.allocate(Region);
+OtherRegion = Tree.allocate(Region);
+  } else {
+CalleeRegion = Region;
+OtherRegion = Region;
+  }
+  SequenceTree::Seq OldRegion = Region;
 
-// FIXME: CXXNewExpr and CXXDeleteExpr implicitly call functions.
+  // Visit the callee expression first.
+  Region = CalleeRegion;
+  if (SemaRef.getLangOpts().CPlusPlus17) {
+SequencedSubexpression Sequenced(*this);
+Visit(CE->getCallee());
+  } else {
+Visit(CE->getCallee());
+  }
+
+  // Then visit the argument expressions.
+  Region = OtherRegion;
+  for (const Expr *Argument : CE->arguments())
+Visit(Argument);
+
+  Region = OldRegion;
+  if (SemaRef.getLangOpts().CPlusPlus17) {
+Tree.merge(CalleeRegion);
+Tree.merge(OtherRegion);
+  }
+});
   }
 
   void VisitCXXConstructExpr(const CXXConstructExpr *CCE) {
___
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-06-03 Thread Simon Moll via Phabricator via cfe-commits
simoll updated this revision to Diff 268140.
simoll added a comment.

NFC. Undid stray change.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81083

Files:
  clang/docs/LanguageExtensions.rst
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/TypePrinter.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/lib/CodeGen/CGRecordLayoutBuilder.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/CodeGen/CodeGenTypes.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/SemaCXX/vector.cpp

Index: clang/test/SemaCXX/vector.cpp
===
--- clang/test/SemaCXX/vector.cpp
+++ clang/test/SemaCXX/vector.cpp
@@ -331,8 +331,7 @@
 typedef __attribute__((ext_vector_type(4))) int vi4;
 const int &reference_to_vec_element = vi4(1).x;
 
-// PR12649
-typedef bool bad __attribute__((__vector_size__(16)));  // expected-error {{invalid vector element type 'bool'}}
+typedef bool good __attribute__((__vector_size__(16)));
 
 namespace Templates {
 template 
@@ -350,9 +349,7 @@
 void Init() {
   const TemplateVectorType::type Works = {};
   const TemplateVectorType::type Works2 = {};
-  // expected-error@#1 {{invalid vector element type 'bool'}}
-  // expected-note@+1 {{in instantiation of template class 'Templates::TemplateVectorType' requested here}}
-  const TemplateVectorType::type NoBool = {};
+  const TemplateVectorType::type BoolWorks = {};
   // expected-error@#1 {{invalid vector element type 'int __attribute__((ext_vector_type(4)))' (vector of 4 'int' values)}}
   // expected-note@+1 {{in instantiation of template class 'Templates::TemplateVectorType' requested here}}
   const TemplateVectorType::type NoComplex = {};
Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -2464,10 +2464,10 @@
 
 QualType Sema::BuildVectorType(QualType CurType, Expr *SizeExpr,
SourceLocation AttrLoc) {
-  // The base type must be integer (not Boolean or enumeration) or float, and
+  // The base type must be boolean or integer (not enumeration) or float, and
   // can't already be a vector.
   if (!CurType->isDependentType() &&
-  (!CurType->isBuiltinType() || CurType->isBooleanType() ||
+  (!CurType->isBuiltinType() ||
(!CurType->isIntegerType() && !CurType->isRealFloatingType( {
 Diag(AttrLoc, diag::err_attribute_invalid_vector_type) << CurType;
 return QualType();
@@ -2496,8 +2496,14 @@
 << SizeExpr->getSourceRange() << "vector";
 return QualType();
   }
-  uint64_t VectorSizeBits = VecSize.getZExtValue() * 8;
-  unsigned TypeSize = static_cast(Context.getTypeSize(CurType));
+
+  uint64_t VectorSizeBits =
+  CurType->isBooleanType()
+  ? VecSize.getZExtValue()
+  : VecSize.getZExtValue() * 8; // FIXME "bitsof(CharUnit)"
+  unsigned TypeSize = CurType->isBooleanType()
+  ? 1
+  : static_cast(Context.getTypeSize(CurType));
 
   if (VectorSizeBits == 0) {
 Diag(AttrLoc, diag::err_attribute_zero_size)
@@ -7549,13 +7555,13 @@
   T = Context.getAdjustedType(T, Wrapped);
 }
 
-/// HandleVectorSizeAttribute - this attribute is only applicable to integral
-/// and float scalars, although arrays, pointers, and function return values are
-/// allowed in conjunction with this construct. Aggregates with this attribute
-/// are invalid, even if they are of the same size as a corresponding scalar.
-/// The raw attribute should contain precisely 1 argument, the vector size for
-/// the variable, measured in bytes. If curType and rawAttr are well formed,
-/// this routine will return a new vector type.
+/// HandleVectorSizeAttribute - this attribute is only applicable to boolean,
+/// integral and float scalars, although arrays, pointers, and function return
+/// values are allowed in conjunction with this construct. Aggregates with this
+/// attribute are invalid, even if they are of the same size as a corresponding
+/// scalar. The raw attribute should contain precisely 1 argument, the vector
+/// size for the variable, measured in bytes. If curType and rawAttr are well
+/// formed, this routine will return a new vector type.
 static void HandleVectorSizeAttr(QualType &CurType, const ParsedAttr &Attr,
  Sema &S) {
   // Check the attribute arguments.
Index: clang/lib/Sema/SemaExprCXX.cpp
===
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -5947,7 +5947,8 @@
   } else if (LHSVT || RHSVT) {
 ResultType = CheckVectorOperands(
 LHS, RHS, Que

[PATCH] D81075: [ASTMatchers] Fix crash with HasName and HasAnyName

2020-06-03 Thread Nathan James via Phabricator via cfe-commits
njames93 updated this revision to Diff 268142.
njames93 added a comment.

Fix clang-format error.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81075

Files:
  clang/include/clang/AST/PrettyPrinter.h
  clang/lib/AST/Decl.cpp
  clang/lib/ASTMatchers/ASTMatchersInternal.cpp
  clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp

Index: clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
@@ -1665,7 +1665,7 @@
   StringRef code =
   "namespace a { void F(int a) { struct S { int m; }; int i; } }";
   EXPECT_TRUE(matches(code, varDecl(hasName("i";
-  EXPECT_FALSE(matches(code, varDecl(hasName("F()::i";
+  EXPECT_FALSE(matches(code, varDecl(hasName("F(int)::i";
 
   EXPECT_TRUE(matches(code, fieldDecl(hasName("m";
   EXPECT_TRUE(matches(code, fieldDecl(hasName("S::m";
@@ -1674,6 +1674,31 @@
   EXPECT_TRUE(matches(code, fieldDecl(hasName("::a::F(int)::S::m";
 }
 
+TEST(Matcher, HasNameSupportsFunctionScopeRecordDecl) {
+  StringRef FuncCode = R"cc(
+void A() {
+  struct B {};
+})cc";
+  EXPECT_TRUE(matches(FuncCode, cxxRecordDecl(hasName("B";
+  EXPECT_TRUE(matches(FuncCode, cxxRecordDecl(hasName("A()::B";
+  EXPECT_TRUE(matches(FuncCode, cxxRecordDecl(hasName("::A()::B";
+  EXPECT_TRUE(notMatches(FuncCode, cxxRecordDecl(hasName("::B";
+
+  StringRef MethodCode = R"cc(
+struct A {
+  void B() {
+struct C {};
+  }
+};)cc";
+
+  EXPECT_TRUE(matches(MethodCode, cxxRecordDecl(hasName("C";
+  EXPECT_TRUE(matches(MethodCode, cxxRecordDecl(hasName("B()::C";
+  EXPECT_TRUE(matches(MethodCode, cxxRecordDecl(hasName("A::B()::C";
+  EXPECT_TRUE(matches(MethodCode, cxxRecordDecl(hasName("::A::B()::C";
+  EXPECT_TRUE(notMatches(MethodCode, cxxRecordDecl(hasName("::C";
+  EXPECT_TRUE(notMatches(MethodCode, cxxRecordDecl(hasName("::B()::C";
+}
+
 TEST(Matcher, HasNameQualifiedSupportsLinkage) {
   // https://bugs.llvm.org/show_bug.cgi?id=42193
   StringRef code = R"cpp(namespace foo { extern "C" void test(); })cpp";
Index: clang/lib/ASTMatchers/ASTMatchersInternal.cpp
===
--- clang/lib/ASTMatchers/ASTMatchersInternal.cpp
+++ clang/lib/ASTMatchers/ASTMatchersInternal.cpp
@@ -571,7 +571,7 @@
   // We are allowed to skip anonymous and inline namespaces if they don't match.
   const DeclContext *Ctx = Node.getDeclContext();
 
-  if (Ctx->isFunctionOrMethod())
+  if (Ctx->isFunctionOrMethod() && !isa(Node))
 return Patterns.foundMatch(/*AllowFullyQualified=*/false);
 
   for (; Ctx; Ctx = Ctx->getParent()) {
@@ -616,13 +616,10 @@
 llvm::SmallString<128> NodeName = StringRef("::");
 llvm::raw_svector_ostream OS(NodeName);
 
-if (SkipUnwritten) {
-  PrintingPolicy Policy = Node.getASTContext().getPrintingPolicy();
-  Policy.SuppressUnwrittenScope = true;
-  Node.printQualifiedName(OS, Policy);
-} else {
-  Node.printQualifiedName(OS);
-}
+PrintingPolicy Policy = Node.getASTContext().getPrintingPolicy();
+Policy.PrintFunctionQualifiedRecords = true;
+Policy.SuppressUnwrittenScope = SkipUnwritten;
+Node.printQualifiedName(OS, Policy);
 
 const StringRef FullName = OS.str();
 
Index: clang/lib/AST/Decl.cpp
===
--- clang/lib/AST/Decl.cpp
+++ clang/lib/AST/Decl.cpp
@@ -1540,7 +1540,8 @@
 
 void NamedDecl::printQualifiedName(raw_ostream &OS,
const PrintingPolicy &P) const {
-  if (getDeclContext()->isFunctionOrMethod()) {
+  if (getDeclContext()->isFunctionOrMethod() &&
+  !(P.PrintFunctionQualifiedRecords && isa(this))) {
 // We do not print '(anonymous)' for function parameters without name.
 printName(OS);
 return;
@@ -1583,7 +1584,8 @@
   Ctx = CI;
   }
 
-  if (Ctx->isFunctionOrMethod())
+  if (Ctx->isFunctionOrMethod() &&
+  !(P.PrintFunctionQualifiedRecords && isa(this)))
 return;
 
   using ContextsTy = SmallVector;
Index: clang/include/clang/AST/PrettyPrinter.h
===
--- clang/include/clang/AST/PrettyPrinter.h
+++ clang/include/clang/AST/PrettyPrinter.h
@@ -63,7 +63,8 @@
 MSWChar(LO.MicrosoftExt && !LO.WChar), IncludeNewlines(true),
 MSVCFormatting(false), ConstantsAsWritten(false),
 SuppressImplicitBase(false), FullyQualifiedName(false),
-PrintCanonicalTypes(false), PrintInjectedClassNameWithArguments(true) {}
+PrintCanonicalTypes(false), PrintInjectedClassNameWithArguments(true),
+PrintFunctionQualifiedRecords(false) {}
 
   /// Adjust this printing policy for cases where it's known that we're

[PATCH] D80514: [clang-tidy] modernize-use-trailing-return-type support for C++20 concepts and decltype

2020-06-03 Thread Nathan James via Phabricator via cfe-commits
njames93 added a comment.

In D80514#2070843 , @bernhardmgruber 
wrote:

> Ping.
>
> Furthermore: how can I schedule another CI build with the newest version of 
> the diff? When I go to the failed build from Harbormaster and I click 
> restart, it rebuilds an older version of the diff. Thanks for the info!


The restart build feature is only really useful when something on trunk caused 
the failure and will restart the build with the diff it had when the build was 
first started. The CI should build each time you update the diff, not sure why 
it isn't, but I don't think there is a special way to fix that. As the failure 
was caused by the test cases you could try and run `ninja check-clang-tools` 
from your build directory to ensure things are working, Alternatively if you 
upload another diff it should force a new build.


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

https://reviews.llvm.org/D80514



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


[PATCH] D81086: buildkite is open for beta

2020-06-03 Thread Mikhail Goncharov via Phabricator via cfe-commits
goncharov created this revision.
Herald added subscribers: cfe-commits, usaxena95, kadircet, arphaman, jkorous.
Herald added a project: clang.
goncharov removed subscribers: jkorous, arphaman, kadircet, usaxena95, 
cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D81086

Files:
  clang-tools-extra/clangd/CollectMacros.cpp
  clang-tools-extra/clangd/test/test-uri-posix.test
  clang-tools-extra/clangd/test/test-uri-windows.test


Index: clang-tools-extra/clangd/test/test-uri-windows.test
===
--- clang-tools-extra/clangd/test/test-uri-windows.test
+++ clang-tools-extra/clangd/test/test-uri-windows.test
@@ -4,7 +4,7 @@
 
{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":123,"rootPath":"clangd","capabilities":{},"trace":"off"}}
 ---
 
{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"test:///foo.c","languageId":"c","version":1,"text":"void
 main() {}"}}}
-# CHECK:"uri": "file:///C:/clangd-test/foo.c"
+# CHECK:"uri": "file:///C:/clangd-test/bar.c"
 ---
 {"jsonrpc":"2.0","id":5,"method":"shutdown"}
 ---
Index: clang-tools-extra/clangd/test/test-uri-posix.test
===
--- clang-tools-extra/clangd/test/test-uri-posix.test
+++ clang-tools-extra/clangd/test/test-uri-posix.test
@@ -4,7 +4,7 @@
 
{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":123,"rootPath":"clangd","capabilities":{},"trace":"off"}}
 ---
 
{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"test:///foo.c","languageId":"c","version":1,"text":"void
 main() {}"}}}
-# CHECK:"uri": "file:///clangd-test/foo.c"
+# CHECK:"uri": "file:///clangd-test/baz.c"
 ---
 {"jsonrpc":"2.0","id":5,"method":"shutdown"}
 ---
Index: clang-tools-extra/clangd/CollectMacros.cpp
===
--- clang-tools-extra/clangd/CollectMacros.cpp
+++ clang-tools-extra/clangd/CollectMacros.cpp
@@ -7,8 +7,8 @@
 
//===--===//
 
 #include "CollectMacros.h"
-#include "clang/Basic/SourceLocation.h"
 #include "clang/Lex/Lexer.h"
+#include "clang/Basic/SourceLocation.h"
 
 namespace clang {
 namespace clangd {


Index: clang-tools-extra/clangd/test/test-uri-windows.test
===
--- clang-tools-extra/clangd/test/test-uri-windows.test
+++ clang-tools-extra/clangd/test/test-uri-windows.test
@@ -4,7 +4,7 @@
 {"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":123,"rootPath":"clangd","capabilities":{},"trace":"off"}}
 ---
 {"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"test:///foo.c","languageId":"c","version":1,"text":"void main() {}"}}}
-# CHECK:"uri": "file:///C:/clangd-test/foo.c"
+# CHECK:"uri": "file:///C:/clangd-test/bar.c"
 ---
 {"jsonrpc":"2.0","id":5,"method":"shutdown"}
 ---
Index: clang-tools-extra/clangd/test/test-uri-posix.test
===
--- clang-tools-extra/clangd/test/test-uri-posix.test
+++ clang-tools-extra/clangd/test/test-uri-posix.test
@@ -4,7 +4,7 @@
 {"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":123,"rootPath":"clangd","capabilities":{},"trace":"off"}}
 ---
 {"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"test:///foo.c","languageId":"c","version":1,"text":"void main() {}"}}}
-# CHECK:"uri": "file:///clangd-test/foo.c"
+# CHECK:"uri": "file:///clangd-test/baz.c"
 ---
 {"jsonrpc":"2.0","id":5,"method":"shutdown"}
 ---
Index: clang-tools-extra/clangd/CollectMacros.cpp
===
--- clang-tools-extra/clangd/CollectMacros.cpp
+++ clang-tools-extra/clangd/CollectMacros.cpp
@@ -7,8 +7,8 @@
 //===--===//
 
 #include "CollectMacros.h"
-#include "clang/Basic/SourceLocation.h"
 #include "clang/Lex/Lexer.h"
+#include "clang/Basic/SourceLocation.h"
 
 namespace clang {
 namespace clangd {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D80887: [clang-tidy] ignore builtin varargs from pro-type-vararg-check

2020-06-03 Thread Nathan James via Phabricator via cfe-commits
njames93 updated this revision to Diff 268149.
njames93 marked 3 inline comments as done.
njames93 added a comment.

Add va_start.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80887

Files:
  clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeVarargCheck.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-vararg.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-vararg.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-vararg.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-vararg.cpp
@@ -49,3 +49,11 @@
 }
 
 int my_vprintf(const char* format, va_list arg ); // OK to declare function 
taking va_list
+
+void ignoredBuiltinsTest() {
+  (void)__builtin_assume_aligned(0, 8);
+  (void)__builtin_constant_p(0);
+  (void)__builtin_fpclassify(0, 0, 0, 0, 0, 0.f);
+  (void)__builtin_isinf_sign(0.f);
+  (void)__builtin_prefetch(nullptr);
+}
Index: clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeVarargCheck.cpp
===
--- clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeVarargCheck.cpp
+++ clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeVarargCheck.cpp
@@ -18,11 +18,60 @@
 
 const internal::VariadicDynCastAllOfMatcher vAArgExpr;
 
+static constexpr StringRef AllowedVariadics[] = {
+// Disable formatting to prevent squashing the list.
+// clang-format off
+"__builtin_isgreater", 
+"__builtin_isgreaterequal", 
+"__builtin_isless",
+"__builtin_islessequal", 
+"__builtin_islessgreater", 
+"__builtin_isunordered",
+"__builtin_fpclassify", 
+"__builtin_isfinite", 
+"__builtin_isinf",
+"__builtin_isinf_sign", 
+"__builtin_isnan", 
+"__builtin_isnormal",
+"__builtin_signbit", 
+"__builtin_constant_p", 
+"__builtin_classify_type",
+"__builtin_va_start",
+// "__builtin_stdarg_start",
+"__builtin_assume_aligned", // Documented as variadic to support 
overloading
+// "__builtin_fprintf",
+// "__builtin_printf",
+// "__builtin_snprintf",
+// "__builtin___snprintf_chk",
+// "__builtin___sprintf_chk",
+// "__builtin___fprintf_chk",
+// "__builtin___printf_chk",
+"__builtin_prefetch",  // Documented as variadic to support overloading
+"__builtin_shufflevector", // Documented as variadic but with a defined
+   // number of args based on vector size.
+"__builtin_convertvector", 
+"__builtin_call_with_static_chain",
+"__builtin_annotation", 
+"__builtin_add_overflow", 
+"__builtin_sub_overflow",
+"__builtin_mul_overflow", 
+"__builtin_preserve_access_index",
+"__builtin_nontemporal_store", 
+"__builtin_nontemporal_load",
+// "__builtin_os_log_format_buffer_size",
+// "__builtin_os_log_format",
+"__builtin_ms_va_start",
+// clang-format on
+};
+
 void ProTypeVarargCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(vAArgExpr().bind("va_use"), this);
 
   Finder->addMatcher(
-  callExpr(callee(functionDecl(isVariadic(.bind("callvararg"), this);
+  callExpr(callee(functionDecl(isVariadic(),
+   unless(hasAnyName(AllowedVariadics)
+  .bind("callvararg"),
+  this);
 }
 
 static bool hasSingleVariadicArgumentWithValue(const CallExpr *C, uint64_t I) {


Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-vararg.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-vararg.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-vararg.cpp
@@ -49,3 +49,11 @@
 }
 
 int my_vprintf(const char* format, va_list arg ); // OK to declare function taking va_list
+
+void ignoredBuiltinsTest() {
+  (void)__builtin_assume_aligned(0, 8);
+  (void)__builtin_constant_p(0);
+  (void)__builtin_fpclassify(0, 0, 0, 0, 0, 0.f);
+  (void)__builtin_isinf_sign(0.f);
+  (void)__builtin_prefetch(nullptr);
+}
Index: clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeVarargCheck.cpp
===
--- clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeVarargCheck.cpp
+++ clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeVarargCheck.cpp
@@ -18,11 +18,60 @@
 
 const internal::VariadicDynCastAllOfMatcher vAArgExpr;
 
+static constexpr StringRef AllowedVariadics[] = {
+// Disable formatting to prevent squashing the list.
+// clang-format off
+"__builtin_isgreater", 
+"__builtin_isgreaterequal", 
+"__builtin_isless",
+"__builtin_islessequal", 
+"__builtin_islessgreater", 
+"__builtin_isunordered",
+"__builtin_fpclassify", 
+  

[PATCH] D79781: [OpenCL] Add cl_khr_extended_subgroup extensions

2020-06-03 Thread Piotr Fusik via Phabricator via cfe-commits
PiotrFusik marked 2 inline comments as done.
PiotrFusik added a comment.

> Great! Thanks! Feel free to go ahead and commit this!

Thanks. Can someone commit this for me please? Also to 10.0 if possible?

> Can you please add a link to the bug describing incorrect optimization to 
> this review once you create it.

Sure. Now I'm waiting for my Bugzilla account to be created.




Comment at: clang/include/clang/Basic/OpenCLExtensions.def:68
 OPENCLEXT_INTERNAL(cl_khr_spir, 120, ~0U)
+OPENCLEXT_INTERNAL(cl_khr_subgroup_extended_types, 120, ~0U)
+OPENCLEXT_INTERNAL(cl_khr_subgroup_non_uniform_vote, 120, ~0U)

Anastasia wrote:
> PiotrFusik wrote:
> > Anastasia wrote:
> > > I think it makes sense to allow this extension from the same OpenCL 
> > > version as normal subgroup. However the version listed somewhere in the 
> > > spec?
> > The spec doesn't mention the OpenCL version. Quoting the editor (Ben 
> > Ashbaugh):
> > > My view of OpenCL extensions is that they are "non-versioned" – some 
> > > extensions certainly make more sense for specific OpenCL versions, but if 
> > > an older OpenCL implementation wants to support a newer extension 
> > > (perhaps with some caveats or restrictions), or if a newer OpenCL version 
> > > wants to support an older OpenCL extension for backwards compatibility, 
> > > that should be possible.
> > I agree that matching the version of `cl_khr_subgroups` makes sense. 
> > Updated together with the tests.
> > 
> I would say in upstream Clang we try to follow the commonly accepted and 
> well-documented behavior. We have no capacity to work out what the behavior 
> of every possible customization should be.
> 
> Also, we aim to implement already documented behavior that provides 
> sufficient details to understand how things should be implemented. We can 
> some times decide to deviate the implementation from the existing published 
> documentation for which we should have a good reason and we should document 
> anything that deviates any existing publicly documented feature.
> 
> Ideally OpenCL standard should decide whether extensions are associated with 
> OpenCL versions or not and this should be clearly documented. It would 
> certainly help the implementation as it saves us time to work out what 
> language version should be taken as a base.
> 
> I believe that enabling extensions with incompatible language versions can 
> cause the compiler failures without providing helpful information/diagnostic. 
> Therefore, extensions should be aligned with a certain version of OpenCL C 
> because they might require certain language features to be used. If they only 
> require basic OpenCL language features then I guess it can say the extension 
> is used with any language version starting from 1.0.
Understood. I will check with the spec author. In the unlikely case that the 
minimum OpenCL version turns out to be different from 2.0, I will follow up 
with a fix.


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

https://reviews.llvm.org/D79781



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


[PATCH] D81080: [clang-tidy] Compile fix: Change CPlusPlus2a to CPlusPlus20.

2020-06-03 Thread Martin Böhme via Phabricator via cfe-commits
mboehme added a comment.

Already fixed in

https://github.com/llvm/llvm-project/commit/fd2740143e626ca32432aac0b51b2880a3b1e0bc

Retracting this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81080



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


[PATCH] D81087: Replaced C++2a with C++20 in clang-tools-extra

2020-06-03 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr created this revision.
gribozavr added a reviewer: hlopko.
Herald added subscribers: cfe-commits, usaxena95, kadircet, arphaman, jkorous, 
kbarton, nemanjai.
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D81087

Files:
  clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
  clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
  clang-tools-extra/clangd/unittests/FindTargetTests.cpp
  clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
  clang-tools-extra/docs/clang-tidy/checks/portability-simd-intrinsics.rst
  clang-tools-extra/test/clang-tidy/check_clang_tidy.py
  clang-tools-extra/test/clang-tidy/checkers/cert-mem57-cpp-cpp17.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-member-init-cxx20.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-member-init-cxx2a.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-member-init.cpp
  
clang-tools-extra/test/clang-tidy/checkers/modernize-make-unique-inaccessible-ctors.cpp
  clang-tools-extra/test/clang-tidy/checkers/modernize-raw-string-literal.cpp
  
clang-tools-extra/test/clang-tidy/checkers/modernize-use-default-member-init-bitfield.cpp
  
clang-tools-extra/test/clang-tidy/checkers/modernize-use-default-member-init.cpp
  
clang-tools-extra/test/clang-tidy/checkers/modernize-use-trailing-return-type.cpp
  clang-tools-extra/test/clang-tidy/checkers/performance-no-automatic-move.cpp
  clang-tools-extra/test/clang-tidy/checkers/portability-simd-intrinsics-ppc.cpp
  clang-tools-extra/test/clang-tidy/checkers/portability-simd-intrinsics-x86.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-use-anyofallof-cpp20.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/readability-use-anyofallof-cpp20.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/readability-use-anyofallof-cpp20.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability-use-anyofallof-cpp20.cpp
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy -std=c++2a-or-later %s readability-use-anyofallof %t
+// RUN: %check_clang_tidy -std=c++20-or-later %s readability-use-anyofallof %t
 
 bool good_any_of() {
   int v[] = {1, 2, 3};
Index: clang-tools-extra/test/clang-tidy/checkers/portability-simd-intrinsics-x86.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/portability-simd-intrinsics-x86.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/portability-simd-intrinsics-x86.cpp
@@ -2,7 +2,7 @@
 // RUN:  -config='{CheckOptions: [ \
 // RUN:{key: portability-simd-intrinsics.Suggest, value: 1} \
 // RUN:  ]}' -- -target x86_64
-// FIXME: Fix the checker to work in C++2a mode.
+// FIXME: Fix the checker to work in C++20 mode.
 
 typedef long long __m128i __attribute__((vector_size(16)));
 typedef double __m256 __attribute__((vector_size(32)));
Index: clang-tools-extra/test/clang-tidy/checkers/portability-simd-intrinsics-ppc.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/portability-simd-intrinsics-ppc.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/portability-simd-intrinsics-ppc.cpp
@@ -2,7 +2,7 @@
 // RUN:  -config='{CheckOptions: [ \
 // RUN:{key: portability-simd-intrinsics.Suggest, value: 1} \
 // RUN:  ]}' -- -target ppc64le -maltivec
-// FIXME: Fix the checker to work in C++2a mode.
+// FIXME: Fix the checker to work in C++20 mode.
 
 vector int vec_add(vector int, vector int);
 
Index: clang-tools-extra/test/clang-tidy/checkers/performance-no-automatic-move.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/performance-no-automatic-move.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/performance-no-automatic-move.cpp
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy -std=c++11,c++14,c++17,c++2a %s performance-no-automatic-move %t
+// RUN: %check_clang_tidy -std=c++11-or-later %s performance-no-automatic-move %t
 
 struct Obj {
   Obj();
Index: clang-tools-extra/test/clang-tidy/checkers/modernize-use-trailing-return-type.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/modernize-use-trailing-return-type.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/modernize-use-trailing-return-type.cpp
@@ -1,5 +1,5 @@
 // RUN: %check_clang_tidy -std=c++14,c++17 %s modernize-use-trailing-return-type %t -- -- -fdeclspec -fexceptions
-// FIXME: Fix the checker to work in C++2a mode, it is performing a
+// FIXME: Fix the checker to work in C++20 mode, it is performing a
 // use-of-uninitialized-value.
 
 namespace std {
Index: clang-tools-extra/test/clang-tidy/checkers/modernize-use-default-member-init.cpp
===
--- clang-tools-e

[PATCH] D80887: [clang-tidy] ignore builtin varargs from pro-type-vararg-check

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



Comment at: 
clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeVarargCheck.cpp:40
+// "__builtin_va_start",
+// "__builtin_stdarg_start",
+"__builtin_assume_aligned", // Documented as variadic to support 
overloading

aaron.ballman wrote:
> Should remove commented-out code from the list.
Once we are happy I will remove it, more  a temporary step.



Comment at: 
clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeVarargCheck.cpp:41
+// "__builtin_stdarg_start",
+"__builtin_assume_aligned", // Documented as variadic to support 
overloading
+// "__builtin_fprintf",

aaron.ballman wrote:
> If it's documented as being variadic, I think we want to remove it from the 
> list so we warn on its use, right?
> 
> From here on down look like things that are not part of any standard, also, 
> so we may want to remove them based on that, too.
This function should have this signature if default arguments were allowed.
```
extern void* __builtin_assume_aligned(const void* exp, size_t align, size_t 
misaligned = 0);```



Comment at: 
clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeVarargCheck.cpp:49
+// "__builtin___printf_chk",
+"__builtin_prefetch",  // Documented as variadic to support overloading
+"__builtin_shufflevector", // Documented as variadic but with a defined

aaron.ballman wrote:
> Same here.
Likewise this one should have this signature
```
extern void builtin_prefetch(const void* addr, bool rw = false, unsigned 
locality = 3);```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80887



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


[PATCH] D80940: [clang-format] [PR46159] Linux kernel 'C' code uses 'try' as a variable name, allow clang-format to handle such cases

2020-06-03 Thread Marek Kurdej via Phabricator via cfe-commits
curdeius added a comment.

Nice. Should we test other non-C keywords as well?
Out of curiosity, where does "@try" come from?




Comment at: clang/lib/Format/FormatTokenLexer.cpp:392
+  auto &Try = *(Tokens.end() - 2);
+  auto &Brace = *(Tokens.end() - 1);
+  if (!Try->is(tok::kw_try))

Please rename to something that includes colon or is more general. Just using 
Brace is misleading.



Comment at: clang/lib/Format/FormatTokenLexer.cpp:393
+  auto &Brace = *(Tokens.end() - 1);
+  if (!Try->is(tok::kw_try))
+return false;

Nit: You can move this if above.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80940



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


[clang-tools-extra] c1911fc - Replaced C++2a with C++20 in clang-tools-extra

2020-06-03 Thread Dmitri Gribenko via cfe-commits

Author: Dmitri Gribenko
Date: 2020-06-03T14:54:10+02:00
New Revision: c1911fcb0664417cbf75b11315bdba39bd6d6390

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

LOG: Replaced C++2a with C++20 in clang-tools-extra

Reviewers: hlopko, aaron.ballman

Reviewed By: aaron.ballman

Subscribers: wuzish, aaron.ballman, nemanjai, kbarton, jkorous, arphaman, 
kadircet, usaxena95, cfe-commits

Tags: #clang

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

Added: 

clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-member-init-cxx20.cpp

Modified: 
clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
clang-tools-extra/clangd/unittests/FindTargetTests.cpp
clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
clang-tools-extra/docs/clang-tidy/checks/portability-simd-intrinsics.rst
clang-tools-extra/test/clang-tidy/check_clang_tidy.py
clang-tools-extra/test/clang-tidy/checkers/cert-mem57-cpp-cpp17.cpp

clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-member-init.cpp

clang-tools-extra/test/clang-tidy/checkers/modernize-make-unique-inaccessible-ctors.cpp
clang-tools-extra/test/clang-tidy/checkers/modernize-raw-string-literal.cpp

clang-tools-extra/test/clang-tidy/checkers/modernize-use-default-member-init-bitfield.cpp

clang-tools-extra/test/clang-tidy/checkers/modernize-use-default-member-init.cpp

clang-tools-extra/test/clang-tidy/checkers/modernize-use-trailing-return-type.cpp
clang-tools-extra/test/clang-tidy/checkers/performance-no-automatic-move.cpp

clang-tools-extra/test/clang-tidy/checkers/portability-simd-intrinsics-ppc.cpp

clang-tools-extra/test/clang-tidy/checkers/portability-simd-intrinsics-x86.cpp

clang-tools-extra/test/clang-tidy/checkers/readability-use-anyofallof-cpp20.cpp

Removed: 

clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-member-init-cxx2a.cpp



diff  --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
index 22373439083e..a223d215af1b 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
@@ -454,7 +454,7 @@ void ProTypeMemberInitCheck::checkMissingMemberInitializer(
   return;
 // Don't suggest fixes for enums because we don't know a good default.
 // Don't suggest fixes for bitfields because in-class initialization is not
-// possible until C++2a.
+// possible until C++20.
 if (F->getType()->isEnumeralType() ||
 (!getLangOpts().CPlusPlus20 && F->isBitField()))
   return;

diff  --git a/clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp 
b/clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
index 2b014ac0a69b..dea783f049e3 100644
--- a/clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
+++ b/clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
@@ -441,7 +441,7 @@ TEST_F(DocumentSymbolsTest, DeclarationDefinition) {
 }
 
 TEST_F(DocumentSymbolsTest, Concepts) {
-  CDB.ExtraClangFlags = {"-std=c++2a"};
+  CDB.ExtraClangFlags = {"-std=c++20"};
   std::string FilePath = testPath("foo.cpp");
   addFile(FilePath,
   "template  concept C = requires(T t) { t.foo(); };");

diff  --git a/clang-tools-extra/clangd/unittests/FindTargetTests.cpp 
b/clang-tools-extra/clangd/unittests/FindTargetTests.cpp
index 26fdcd886f62..bf5cc62411b7 100644
--- a/clang-tools-extra/clangd/unittests/FindTargetTests.cpp
+++ b/clang-tools-extra/clangd/unittests/FindTargetTests.cpp
@@ -401,7 +401,7 @@ TEST_F(TargetDeclTest, Concept) {
   t.foo();
 }
   )cpp";
-  Flags.push_back("-std=c++2a");
+  Flags.push_back("-std=c++20");
   EXPECT_DECLS(
   "ConceptSpecializationExpr",
   // FIXME: Should we truncate the pretty-printed form of a concept decl
@@ -642,7 +642,7 @@ class FindExplicitReferencesTest : public ::testing::Test {
 // FIXME: Auto-completion in a template requires disabling delayed template
 // parsing.
 TU.ExtraArgs.push_back("-fno-delayed-template-parsing");
-TU.ExtraArgs.push_back("-std=c++2a");
+TU.ExtraArgs.push_back("-std=c++20");
 TU.ExtraArgs.push_back("-xobjective-c++");
 
 auto AST = TU.build();

diff  --git a/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp 
b/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
index 2b4c306c5163..98080e98ca17 100644
--- a/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
+++ b/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
@@ -115,7 +115,7 @@ void

[PATCH] D80887: [clang-tidy] ignore builtin varargs from pro-type-vararg-check

2020-06-03 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: 
clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeVarargCheck.cpp:40
+// "__builtin_va_start",
+// "__builtin_stdarg_start",
+"__builtin_assume_aligned", // Documented as variadic to support 
overloading

njames93 wrote:
> aaron.ballman wrote:
> > Should remove commented-out code from the list.
> Once we are happy I will remove it, more  a temporary step.
SGTM!



Comment at: 
clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeVarargCheck.cpp:41
+// "__builtin_stdarg_start",
+"__builtin_assume_aligned", // Documented as variadic to support 
overloading
+// "__builtin_fprintf",

njames93 wrote:
> aaron.ballman wrote:
> > If it's documented as being variadic, I think we want to remove it from the 
> > list so we warn on its use, right?
> > 
> > From here on down look like things that are not part of any standard, also, 
> > so we may want to remove them based on that, too.
> This function should have this signature if default arguments were allowed.
> ```
> extern void* __builtin_assume_aligned(const void* exp, size_t align, size_t 
> misaligned = 0);```
Ah, I see now. Makes sense to keep it, but maybe update the comment as 
"documented as variadic to support default parameters".

If you've vetted the other builtins below to see that they're not actually 
variadic, I'm fine leaving them in the list as, btw.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80887



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


[PATCH] D77572: [clang-tidy] add new check readability-use-anyofallof

2020-06-03 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon added a comment.

@mgehre Please can you take at the remaining buildbot failures here : 
http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/builds/68662


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77572



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


[PATCH] D81087: Replaced C++2a with C++20 in clang-tools-extra

2020-06-03 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.
Herald added a subscriber: wuzish.

LGTM!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81087



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


[PATCH] D80450: [CUDA][HIP] Fix implicit HD function resolution

2020-06-03 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added a comment.

ping


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

https://reviews.llvm.org/D80450



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


[PATCH] D79710: [clang][BFloat] add create/set/get/dup intrinsics

2020-06-03 Thread Mikhail Maltsev via Phabricator via cfe-commits
miyuki added inline comments.



Comment at: clang/include/clang/Basic/arm_neon.td:1860
+
+  def VGET_HIGH_BF : NoTestOpInst<"vget_high", ".Q", "b", OP_HI>;
+  def VGET_LOW_BF  : NoTestOpInst<"vget_low", ".Q", "b", OP_LO>;

dmgreen wrote:
> Do you know what InstName = "vmov" does, and is it needed here?
> 
> I'm pretty sure it's a vestige of an earlier implementation of the neon 
> emitter.
It looks like `InstName` was removed from NeonEmitter in
```
commit dee4ab08ba956efd76aa10da46510dcddecceacf
Author: James Molloy 
Date:   Tue Jun 17 13:11:27 2014 +

Rewrite ARM NEON intrinsic emission completely.
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79710



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


[PATCH] D80514: [clang-tidy] modernize-use-trailing-return-type support for C++20 concepts and decltype

2020-06-03 Thread Bernhard Manfred Gruber via Phabricator via cfe-commits
bernhardmgruber updated this revision to Diff 268155.
bernhardmgruber added a comment.

Reuploaded diff in an attempt to trigger a CI build.


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

https://reviews.llvm.org/D80514

Files:
  clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp
  clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.h
  
clang-tools-extra/docs/clang-tidy/checks/modernize-use-trailing-return-type.rst
  
clang-tools-extra/test/clang-tidy/checkers/modernize-use-trailing-return-type-cxx20.cpp
  
clang-tools-extra/test/clang-tidy/checkers/modernize-use-trailing-return-type.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/modernize-use-trailing-return-type.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/modernize-use-trailing-return-type.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/modernize-use-trailing-return-type.cpp
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy -std=c++14,c++17 %s modernize-use-trailing-return-type %t -- -- -fdeclspec -fexceptions
+// RUN: %check_clang_tidy -std=c++14-or-later %s modernize-use-trailing-return-type %t -- -- -fdeclspec -fexceptions
 // FIXME: Fix the checker to work in C++2a mode, it is performing a
 // use-of-uninitialized-value.
 
@@ -11,6 +11,8 @@
 
 class string;
 
+class ostream;
+
 template 
 auto declval() -> T;
 }
@@ -215,18 +217,28 @@
 // CHECK-FIXES: {{^}}auto e13() -> struct A;{{$}}
 
 //
-// decltype (unsupported if top level expression)
+// deduced return types
 //
 
+const auto ded1();
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}}auto ded1() -> const auto;{{$}}
+const auto& ded2();
+// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}}auto ded2() -> const auto&;{{$}}
+
+decltype(auto) ded3();
+// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}}auto ded3() -> decltype(auto);{{$}}
+
+
 decltype(1 + 2) dec1() { return 1 + 2; }
 // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
-// TODO: source range of DecltypeTypeLoc not yet implemented
-// _HECK-FIXES: {{^}}auto dec1() -> decltype(1 + 2) { return 1 + 2; }{{$}}
+// CHECK-FIXES: {{^}}auto dec1() -> decltype(1 + 2) { return 1 + 2; }{{$}}
 template 
 decltype(std::declval(std::declval)) dec2(F f, T t) { return f(t); }
 // CHECK-MESSAGES: :[[@LINE-1]]:44: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
-// TODO: source range of DecltypeTypeLoc not yet implemented
-// _HECK-FIXES: {{^}}auto dec2(F f, T t) -> decltype(std::declval(std::declval)) { return f(t); }{{$}}
+// CHECK-FIXES: {{^}}auto dec2(F f, T t) -> decltype(std::declval(std::declval)) { return f(t); }{{$}}
 template 
 typename decltype(std::declval())::value_type dec3();
 // CHECK-MESSAGES: :[[@LINE-1]]:50: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
@@ -531,6 +543,14 @@
 return {0};
 }
 
+//
+// bug 44206, no rewrite should happen due to collision with parameter name
+//
+
+using std::ostream;
+ostream& operator<<(ostream& ostream, int i);
+// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}}ostream& operator<<(ostream& ostream, int i);{{$}}
 
 //
 // Samples which do not trigger the check
@@ -544,7 +564,6 @@
 template  auto f(T t) -> int;
 
 auto ff();
-decltype(auto) fff();
 
 void c();
 void c(int arg);
Index: clang-tools-extra/test/clang-tidy/checkers/modernize-use-trailing-return-type-cxx20.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/modernize-use-trailing-return-type-cxx20.cpp
@@ -0,0 +1,54 @@
+// RUN: %check_clang_tidy -std=c++20 %s modernize-use-trailing-return-type %t
+
+namespace std {
+template 
+struct is_same { static constexpr auto value = false; };
+
+template 
+struct is_same { static constexpr auto value = true; };
+
+template 
+concept floating_point = std::is_same::value || std::is_same::value || std::is_same::value;
+}
+
+//
+// Concepts
+//
+
+std::floating_point auto con1();
+// CHECK-MESSAGES: :[[@LINE-1]]:26: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}}auto con1() -> std::floating_point auto;{{$}}
+
+std::floating_point auto con1() { return 3.14f; }
+// CHECK-MESSAGES: :[[@LINE-1]]:26: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}}auto con1() -> std::floating_point auto { return 3.14f; }{{$}}

[PATCH] D79237: [CUDA][HIP] Fix constexpr variables for C++17

2020-06-03 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added a comment.

ping


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

https://reviews.llvm.org/D79237



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


[PATCH] D80940: [clang-format] [PR46159] Linux kernel 'C' code uses 'try' as a variable name, allow clang-format to handle such cases

2020-06-03 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added a comment.

> Out of curiosity, where does "@try" come from?

Objective C++ I think


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80940



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


[PATCH] D78374: [Analyzer][StreamChecker] Added evaluation of fread and fwrite.

2020-06-03 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus added a comment.

We can close this now, right?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78374



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


[PATCH] D81087: Replaced C++2a with C++20 in clang-tools-extra

2020-06-03 Thread Dmitri Gribenko via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc1911fcb0664: Replaced C++2a with C++20 in clang-tools-extra 
(authored by gribozavr).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81087

Files:
  clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
  clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
  clang-tools-extra/clangd/unittests/FindTargetTests.cpp
  clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
  clang-tools-extra/docs/clang-tidy/checks/portability-simd-intrinsics.rst
  clang-tools-extra/test/clang-tidy/check_clang_tidy.py
  clang-tools-extra/test/clang-tidy/checkers/cert-mem57-cpp-cpp17.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-member-init-cxx20.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-member-init-cxx2a.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-member-init.cpp
  
clang-tools-extra/test/clang-tidy/checkers/modernize-make-unique-inaccessible-ctors.cpp
  clang-tools-extra/test/clang-tidy/checkers/modernize-raw-string-literal.cpp
  
clang-tools-extra/test/clang-tidy/checkers/modernize-use-default-member-init-bitfield.cpp
  
clang-tools-extra/test/clang-tidy/checkers/modernize-use-default-member-init.cpp
  
clang-tools-extra/test/clang-tidy/checkers/modernize-use-trailing-return-type.cpp
  clang-tools-extra/test/clang-tidy/checkers/performance-no-automatic-move.cpp
  clang-tools-extra/test/clang-tidy/checkers/portability-simd-intrinsics-ppc.cpp
  clang-tools-extra/test/clang-tidy/checkers/portability-simd-intrinsics-x86.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-use-anyofallof-cpp20.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/readability-use-anyofallof-cpp20.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/readability-use-anyofallof-cpp20.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability-use-anyofallof-cpp20.cpp
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy -std=c++2a-or-later %s readability-use-anyofallof %t
+// RUN: %check_clang_tidy -std=c++20-or-later %s readability-use-anyofallof %t
 
 bool good_any_of() {
   int v[] = {1, 2, 3};
Index: clang-tools-extra/test/clang-tidy/checkers/portability-simd-intrinsics-x86.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/portability-simd-intrinsics-x86.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/portability-simd-intrinsics-x86.cpp
@@ -2,7 +2,7 @@
 // RUN:  -config='{CheckOptions: [ \
 // RUN:{key: portability-simd-intrinsics.Suggest, value: 1} \
 // RUN:  ]}' -- -target x86_64
-// FIXME: Fix the checker to work in C++2a mode.
+// FIXME: Fix the checker to work in C++20 mode.
 
 typedef long long __m128i __attribute__((vector_size(16)));
 typedef double __m256 __attribute__((vector_size(32)));
Index: clang-tools-extra/test/clang-tidy/checkers/portability-simd-intrinsics-ppc.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/portability-simd-intrinsics-ppc.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/portability-simd-intrinsics-ppc.cpp
@@ -2,7 +2,7 @@
 // RUN:  -config='{CheckOptions: [ \
 // RUN:{key: portability-simd-intrinsics.Suggest, value: 1} \
 // RUN:  ]}' -- -target ppc64le -maltivec
-// FIXME: Fix the checker to work in C++2a mode.
+// FIXME: Fix the checker to work in C++20 mode.
 
 vector int vec_add(vector int, vector int);
 
Index: clang-tools-extra/test/clang-tidy/checkers/performance-no-automatic-move.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/performance-no-automatic-move.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/performance-no-automatic-move.cpp
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy -std=c++11,c++14,c++17,c++2a %s performance-no-automatic-move %t
+// RUN: %check_clang_tidy -std=c++11-or-later %s performance-no-automatic-move %t
 
 struct Obj {
   Obj();
Index: clang-tools-extra/test/clang-tidy/checkers/modernize-use-trailing-return-type.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/modernize-use-trailing-return-type.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/modernize-use-trailing-return-type.cpp
@@ -1,5 +1,5 @@
 // RUN: %check_clang_tidy -std=c++14,c++17 %s modernize-use-trailing-return-type %t -- -- -fdeclspec -fexceptions
-// FIXME: Fix the checker to work in C++2a mode, it is performing a
+// FIXME: Fix the checker to work in C++20 mode, it is performing a
 // use-of-uninitialized-value.
 
 namespace std {
Index: clang-tools-extra/test/clang-tidy/checkers/modernize-use-default-member-init.cpp
==

[clang] 59e0987 - [OPENMP]Fix PR46170: partial mapping for array sections of data members.

2020-06-03 Thread Alexey Bataev via cfe-commits

Author: Alexey Bataev
Date: 2020-06-03T09:10:20-04:00
New Revision: 59e0987a068ca3842dd2b4ddf2edf001fb1de1b5

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

LOG: [OPENMP]Fix PR46170: partial mapping for array sections of data members.

Summary:
If the data member is mapped as an array section, need to emit the
pointer to the last element of this array section and use this pointer
as the highest element in partial struct data.

Reviewers: jdoerfert

Subscribers: yaxunl, guansong, sstefan1, cfe-commits, caomhin

Tags: #clang

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

Added: 
clang/test/OpenMP/target_map_member_expr_array_section_codegen.cpp

Modified: 
clang/lib/CodeGen/CGOpenMPRuntime.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index 231e4485aaeb..95b4c81baf9d 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -7736,7 +7736,14 @@ class MappableExprsHandler {
   // Update info about the lowest and highest elements for this struct
   if (!PartialStruct.Base.isValid()) {
 PartialStruct.LowestElem = {FieldIndex, LB};
-PartialStruct.HighestElem = {FieldIndex, LB};
+if (IsFinalArraySection) {
+  Address HB =
+  CGF.EmitOMPArraySectionExpr(OASE, /*IsLowerBound=*/false)
+  .getAddress(CGF);
+  PartialStruct.HighestElem = {FieldIndex, HB};
+} else {
+  PartialStruct.HighestElem = {FieldIndex, LB};
+}
 PartialStruct.Base = BP;
   } else if (FieldIndex < PartialStruct.LowestElem.first) {
 PartialStruct.LowestElem = {FieldIndex, LB};

diff  --git 
a/clang/test/OpenMP/target_map_member_expr_array_section_codegen.cpp 
b/clang/test/OpenMP/target_map_member_expr_array_section_codegen.cpp
new file mode 100644
index ..ccdd09235097
--- /dev/null
+++ b/clang/test/OpenMP/target_map_member_expr_array_section_codegen.cpp
@@ -0,0 +1,114 @@
+// RUN: %clang_cc1 -verify -fopenmp -fopenmp-targets=powerpc64le-ibm-linux-gnu 
-x c++ -triple powerpc64le-unknown-unknown -emit-llvm %s -o - | FileCheck %s
+// RUN: %clang_cc1 -fopenmp -fopenmp-targets=powerpc64le-ibm-linux-gnu -x c++ 
-std=c++11 -triple powerpc64le-unknown-unknown -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp -fopenmp-targets=powerpc64le-ibm-linux-gnu -x c++ 
-triple powerpc64le-unknown-unknown -std=c++11 -include-pch %t -verify %s 
-emit-llvm -o - | FileCheck %s
+// expected-no-diagnostics
+#ifndef HEADER
+#define HEADER
+
+// 32 = 0x20 = OMP_MAP_TARGET_PARAM
+// 281474976710656 = 0x1 = OMP_MAP_MEMBER_OF of 1-st element
+// CHECK: [[MAP_ENTER:@.+]] = private unnamed_addr constant [2 x i64] [i64 32, 
i64 281474976710656]
+// 281474976710664 = 0x10008 = OMP_MAP_MEMBER_OF of 1-st element | 
OMP_MAP_DELETE
+// CHECK: [[MAP_EXIT:@.+]] = private unnamed_addr constant [2 x i64] [i64 32, 
i64 281474976710664]
+template 
+struct S {
+  constexpr static int size = 6;
+  T data[size];
+};
+
+template 
+struct maptest {
+  S s;
+  maptest() {
+// CHECK: [[BPTRS:%.+]] = alloca [2 x i8*],
+// CHECK: [[PTRS:%.+]] = alloca [2 x i8*],
+// CHECK: [[SIZES:%.+]] = alloca [2 x i64],
+// CHECK: getelementptr inbounds
+// CHECK: [[S_ADDR:%.+]] = getelementptr inbounds %struct.maptest, 
%struct.maptest* [[THIS:%.+]], i32 0, i32 0
+// CHECK: [[S_DATA_ADDR:%.+]] = getelementptr inbounds %struct.S, 
%struct.S* [[S_ADDR]], i32 0, i32 0
+// CHECK: [[S_DATA_0_ADDR:%.+]] = getelementptr inbounds [6 x float], [6 x 
float]* [[S_DATA_ADDR]], i64 0, i64 0
+
+// SZ = &this->s.data[6]-&this->s.data[0]
+// CHECK: [[S_ADDR:%.+]] = getelementptr inbounds %struct.maptest, 
%struct.maptest* [[THIS]], i32 0, i32 0
+// CHECK: [[S_DATA_ADDR:%.+]] = getelementptr inbounds %struct.S, 
%struct.S* [[S_ADDR]], i32 0, i32 0
+// CHECK: [[S_DATA_5_ADDR:%.+]] = getelementptr inbounds [6 x float], [6 x 
float]* [[S_DATA_ADDR]], i64 0, i64 5
+// CHECK: [[S_DATA_6_ADDR:%.+]] = getelementptr float, float* 
[[S_DATA_5_ADDR]], i32 1
+// CHECK: [[BEG:%.+]] = bitcast float* [[S_DATA_0_ADDR]] to i8*
+// CHECK: [[END:%.+]] = bitcast float* [[S_DATA_6_ADDR]] to i8*
+// CHECK: [[END_BC:%.+]] = ptrtoint i8* [[END]] to i64
+// CHECK: [[BEG_BC:%.+]] = ptrtoint i8* [[BEG]] to i64
+// CHECK: [[DIFF:%.+]] = sub i64 [[END_BC]], [[BEG_BC]]
+// CHECK: [[SZ:%.+]] = sdiv exact i64 [[DIFF]], ptrtoint (i8* 
getelementptr (i8, i8* null, i32 1) to i64)
+
+// Fill mapping arrays
+// CHECK: [[BPTR0:%.+]] = getelementptr inbounds [2 x i8*], [2 x i8*]* 
[[BPTRS]], i32 0, i32 0
+// CHECK: [[BPTR0_THIS:%.+]] = 

[PATCH] D79710: [clang][BFloat] Add create/set/get/dup intrinsics

2020-06-03 Thread Mikhail Maltsev via Phabricator via cfe-commits
miyuki updated this revision to Diff 268162.
miyuki retitled this revision from "[clang][BFloat] add create/set/get/dup 
intrinsics" to "[clang][BFloat] Add create/set/get/dup intrinsics".
miyuki edited the summary of this revision.
miyuki added a comment.

Addressed reviewers' comments.


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

https://reviews.llvm.org/D79710

Files:
  clang/include/clang/Basic/arm_neon.td
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/aarch64-bf16-getset-intrinsics.c
  clang/test/CodeGen/arm-bf16-getset-intrinsics.c

Index: clang/test/CodeGen/arm-bf16-getset-intrinsics.c
===
--- /dev/null
+++ clang/test/CodeGen/arm-bf16-getset-intrinsics.c
@@ -0,0 +1,151 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// RUN: %clang_cc1 -triple aarch64-arm-none-eabi -target-feature +neon -target-feature +bf16 \
+// RUN:  -disable-O0-optnone -emit-llvm %s -o - | opt -S -mem2reg -instcombine | FileCheck %s
+
+#include 
+
+// CHECK-LABEL: @test_vcreate_bf16(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = bitcast i64 [[A:%.*]] to <4 x bfloat>
+// CHECK-NEXT:ret <4 x bfloat> [[TMP0]]
+//
+bfloat16x4_t test_vcreate_bf16(uint64_t a) {
+  return vcreate_bf16(a);
+}
+
+// CHECK-LABEL: @test_vdup_n_bf16(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[VECINIT_I:%.*]] = insertelement <4 x bfloat> undef, bfloat [[V:%.*]], i32 0
+// CHECK-NEXT:[[VECINIT3_I:%.*]] = shufflevector <4 x bfloat> [[VECINIT_I]], <4 x bfloat> undef, <4 x i32> zeroinitializer
+// CHECK-NEXT:ret <4 x bfloat> [[VECINIT3_I]]
+//
+bfloat16x4_t test_vdup_n_bf16(bfloat16_t v) {
+  return vdup_n_bf16(v);
+}
+
+// CHECK-LABEL: @test_vdupq_n_bf16(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[VECINIT_I:%.*]] = insertelement <8 x bfloat> undef, bfloat [[V:%.*]], i32 0
+// CHECK-NEXT:[[VECINIT7_I:%.*]] = shufflevector <8 x bfloat> [[VECINIT_I]], <8 x bfloat> undef, <8 x i32> zeroinitializer
+// CHECK-NEXT:ret <8 x bfloat> [[VECINIT7_I]]
+//
+bfloat16x8_t test_vdupq_n_bf16(bfloat16_t v) {
+  return vdupq_n_bf16(v);
+}
+
+// CHECK-LABEL: @test_vdup_lane_bf16(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[LANE:%.*]] = shufflevector <4 x bfloat> [[V:%.*]], <4 x bfloat> undef, <4 x i32> 
+// CHECK-NEXT:ret <4 x bfloat> [[LANE]]
+//
+bfloat16x4_t test_vdup_lane_bf16(bfloat16x4_t v) {
+  return vdup_lane_bf16(v, 1);
+}
+
+// CHECK-LABEL: @test_vdupq_lane_bf16(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[LANE:%.*]] = shufflevector <4 x bfloat> [[V:%.*]], <4 x bfloat> undef, <8 x i32> 
+// CHECK-NEXT:ret <8 x bfloat> [[LANE]]
+//
+bfloat16x8_t test_vdupq_lane_bf16(bfloat16x4_t v) {
+  return vdupq_lane_bf16(v, 1);
+}
+
+// CHECK-LABEL: @test_vdup_laneq_bf16(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[LANE:%.*]] = shufflevector <8 x bfloat> [[V:%.*]], <8 x bfloat> undef, <4 x i32> 
+// CHECK-NEXT:ret <4 x bfloat> [[LANE]]
+//
+bfloat16x4_t test_vdup_laneq_bf16(bfloat16x8_t v) {
+  return vdup_laneq_bf16(v, 7);
+}
+
+// CHECK-LABEL: @test_vdupq_laneq_bf16(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[LANE:%.*]] = shufflevector <8 x bfloat> [[V:%.*]], <8 x bfloat> undef, <8 x i32> 
+// CHECK-NEXT:ret <8 x bfloat> [[LANE]]
+//
+bfloat16x8_t test_vdupq_laneq_bf16(bfloat16x8_t v) {
+  return vdupq_laneq_bf16(v, 7);
+}
+
+// CHECK-LABEL: @test_vcombine_bf16(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[SHUFFLE_I:%.*]] = shufflevector <4 x bfloat> [[LOW:%.*]], <4 x bfloat> [[HIGH:%.*]], <8 x i32> 
+// CHECK-NEXT:ret <8 x bfloat> [[SHUFFLE_I]]
+//
+bfloat16x8_t test_vcombine_bf16(bfloat16x4_t low, bfloat16x4_t high) {
+  return vcombine_bf16(low, high);
+}
+
+// CHECK-LABEL: @test_vget_high_bf16(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[SHUFFLE_I:%.*]] = shufflevector <8 x bfloat> [[A:%.*]], <8 x bfloat> undef, <4 x i32> 
+// CHECK-NEXT:ret <4 x bfloat> [[SHUFFLE_I]]
+//
+bfloat16x4_t test_vget_high_bf16(bfloat16x8_t a) {
+  return vget_high_bf16(a);
+}
+
+// CHECK-LABEL: @test_vget_low_bf16(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[SHUFFLE_I:%.*]] = shufflevector <8 x bfloat> [[A:%.*]], <8 x bfloat> undef, <4 x i32> 
+// CHECK-NEXT:ret <4 x bfloat> [[SHUFFLE_I]]
+//
+bfloat16x4_t test_vget_low_bf16(bfloat16x8_t a) {
+  return vget_low_bf16(a);
+}
+
+// CHECK-LABEL: @test_vget_lane_bf16(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[DOTCAST1:%.*]] = extractelement <4 x bfloat> [[V:%.*]], i32 1
+// CHECK-NEXT:ret bfloat [[DOTCAST1]]
+//
+bfloat16_t test_vget_lane_bf16(bfloat16x4_t v) {
+  return vget_lane_bf16(v, 1);
+}
+
+// CHECK-LABEL: @test_vgetq_lane_bf16(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[DOTCAST1:%.*]] = extractelement <8 x bfloat> [[V:%.*]], i32 7
+// CHECK-NEXT:ret bfloat [[DOTCAST1]]
+//
+bfloat16_t test_vgetq_lane_bf16(bfloat16x8_t v) {
+  return vgetq_lane_bf16(v, 7);
+}
+
+// CHECK-LABEL: @test_vset_lane_bf16(
+// CHECK-NEXT:  entry:
+// CHECK-NEX

[PATCH] D80947: Add to the Coding Standard our that single-line bodies omit braces

2020-06-03 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added inline comments.



Comment at: llvm/docs/CodingStandards.rst:1573
 
+Don't Use Braces on Simple Single-Statement Bodies of if/else/loop Statements
+^

I would rather just ban single line statements like this and require putting 
them on the next line.

For the case of cases, especially when combined with the style of not indenting 
the cases from the switch, omitting braces is really painful. So many times 
I've produced bad merges and had a hard time figuring out where the double }} 
at the end is necessary. It would be easier to just always use the braces



Comment at: llvm/docs/CodingStandards.rst:1603
+
+  // This should also omit braces.  The for loop contains only a single 
statement,
+  // so it shouldn't have braces.  The if also only contains a single 
statement (the

This loop should use braces. It covers multiple lines. Omitting braces 
invariably just increases diffs/merge conflicts when something else is added to 
the loop body.

This one isn't consistently applied and I've been enforcing the opposite


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

https://reviews.llvm.org/D80947



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


[PATCH] D81066: [clangd] Populate the parse options to CodeCompletion/SignatureHelp.

2020-06-03 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 268164.
hokein marked 2 inline comments as done.
hokein added a comment.

Revert an accident change.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81066

Files:
  clang-tools-extra/clangd/ClangdServer.cpp
  clang-tools-extra/clangd/CodeComplete.cpp
  clang-tools-extra/clangd/CodeComplete.h
  clang-tools-extra/clangd/Compiler.h
  clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp

Index: clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
===
--- clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
+++ clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
@@ -117,8 +117,11 @@
   }
   auto Preamble = buildPreamble(testPath(TU.Filename), *CI, Inputs,
 /*InMemory=*/true, /*Callback=*/nullptr);
-  return codeComplete(testPath(TU.Filename), Inputs.CompileCommand,
-  Preamble.get(), TU.Code, Point, Inputs.FS, Opts);
+  ParseInputs ParseInput{Inputs.CompileCommand, Inputs.FS, TU.Code};
+  ParseInput.Opts.BuildRecoveryAST = true;
+  ParseInput.Opts.PreserveRecoveryASTType = true;
+  return codeComplete(testPath(TU.Filename), Point, Preamble.get(), ParseInput,
+  Opts);
 }
 
 // Runs code completion.
@@ -148,8 +151,10 @@
 
   MockFSProvider FS;
   Annotations Test(Text);
-  return codeComplete(FilePath, tooling::CompileCommand(), /*Preamble=*/nullptr,
-  Test.code(), Test.point(), FS.getFileSystem(), Opts);
+  ParseInputs ParseInput{tooling::CompileCommand(), FS.getFileSystem(),
+ Test.code().str()};
+  return codeComplete(FilePath, Test.point(), /*Preamble=*/nullptr, ParseInput,
+  Opts);
 }
 
 Symbol withReferences(int N, Symbol S) {
@@ -753,8 +758,7 @@
   EXPECT_THAT(Results, ElementsAre(Named("ifndef")));
 }
 
-// FIXME: enable it.
-TEST(CompletionTest, DISABLED_CompletionRecoveryASTType) {
+TEST(CompletionTest, CompletionRecoveryASTType) {
   auto Results = completions(R"cpp(
 struct S { int member; };
 S overloaded(int);
@@ -1067,8 +1071,11 @@
 ADD_FAILURE() << "Couldn't build Preamble";
 return {};
   }
-  return signatureHelp(testPath(TU.Filename), Inputs.CompileCommand, *Preamble,
-   Text, Point, Inputs.FS, Index.get());
+  ParseInputs ParseInput{Inputs.CompileCommand, Inputs.FS, Text.str()};
+  ParseInput.Index = Index.get();
+  ParseInput.Opts.BuildRecoveryAST = true;
+  ParseInput.Opts.PreserveRecoveryASTType = true;
+  return signatureHelp(testPath(TU.Filename), Point, *Preamble, ParseInput);
 }
 
 SignatureHelp signatures(llvm::StringRef Text,
@@ -1219,9 +1226,10 @@
 void bar() { foo(^2); })cpp");
   TU.Code = Test.code().str();
   Inputs = TU.inputs();
-  auto Results =
-  signatureHelp(testPath(TU.Filename), Inputs.CompileCommand,
-*EmptyPreamble, TU.Code, Test.point(), Inputs.FS, nullptr);
+
+  ParseInputs ParseInput{Inputs.CompileCommand, Inputs.FS, TU.Code};
+  auto Results = signatureHelp(testPath(TU.Filename), Test.point(),
+   *EmptyPreamble, ParseInput);
   EXPECT_THAT(Results.signatures, ElementsAre(Sig("foo([[int x]]) -> int")));
   EXPECT_EQ(0, Results.activeSignature);
   EXPECT_EQ(0, Results.activeParameter);
Index: clang-tools-extra/clangd/Compiler.h
===
--- clang-tools-extra/clangd/Compiler.h
+++ clang-tools-extra/clangd/Compiler.h
@@ -54,7 +54,7 @@
   bool ForceRebuild = false;
   // Used to recover from diagnostics (e.g. find missing includes for symbol).
   const SymbolIndex *Index = nullptr;
-  ParseOptions Opts;
+  ParseOptions Opts = ParseOptions();
 };
 
 /// Builds compiler invocation that could be used to build AST or preamble.
Index: clang-tools-extra/clangd/CodeComplete.h
===
--- clang-tools-extra/clangd/CodeComplete.h
+++ clang-tools-extra/clangd/CodeComplete.h
@@ -15,6 +15,7 @@
 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_CODECOMPLETE_H
 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_CODECOMPLETE_H
 
+#include "Compiler.h"
 #include "Headers.h"
 #include "Protocol.h"
 #include "Quality.h"
@@ -270,21 +271,16 @@
 /// the speculative result is used by code completion (e.g. speculation failed),
 /// the speculative result is not consumed, and `SpecFuzzyFind` is only
 /// destroyed when the async request finishes.
-CodeCompleteResult codeComplete(PathRef FileName,
-const tooling::CompileCommand &Command,
+CodeCompleteResult codeComplete(PathRef FileName, Position Pos,
 const PreambleData *Preamble,
-StringRef Contents, Position Pos,
-IntrusiveRefCntPtr VFS,
+const ParseInputs &ParseIn

[PATCH] D81090: [AST][RecoveryExpr] Preserve the AST for invalid class constructions.

2020-06-03 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
hokein added a reviewer: sammccall.
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D81090

Files:
  clang/lib/Sema/SemaExprCXX.cpp
  clang/test/AST/ast-dump-recovery.cpp


Index: clang/test/AST/ast-dump-recovery.cpp
===
--- clang/test/AST/ast-dump-recovery.cpp
+++ clang/test/AST/ast-dump-recovery.cpp
@@ -159,11 +159,18 @@
   // CHECK-NEXT: `-RecoveryExpr {{.*}} contains-errors
   // CHECK-NEXT:  `-InitListExpr
   Bar b2 = {1};
-  // FIXME: preserve the invalid initializer.
-  // CHECK: `-VarDecl {{.*}} b3 'Bar'
+  // CHECK: `-VarDecl {{.*}} b3 'Bar'
+  // CHECK-NEXT:  `-CXXConstructExpr {{.*}}  'Bar' 
contains-errors
+  // CHECK-NEXT:`-ImplicitCastExpr {{.*}}  'const Bar' 
contains-errors
+  // CHECK-NEXT:  `-RecoveryExpr {{.*}} 'Bar' contains-errors lvalue
+  // CHECK-NEXT:`-DeclRefExpr {{.*}} 'x' 'int'
   Bar b3 = Bar(x);
-  // FIXME: preserve the invalid initializer.
-  // CHECK: `-VarDecl {{.*}} b4 'Bar'
+  // CHECK: `-VarDecl {{.*}} b4 'Bar'
+  // CHECK-NEXT:  `-CXXConstructExpr {{.*}}  'Bar' 
contains-errors
+  // CHECK-NEXT:`-ImplicitCastExpr {{.*}} 'const Bar' contains-errors
+  // CHECK-NEXT:  `-RecoveryExpr {{.*}} 'Bar' contains-errors
+  // CHECK-NEXT:`-InitListExpr {{.*}} 'void'
+  // CHECK-NEXT:  `-DeclRefExpr {{.*}} 'x' 'int'
   Bar b4 = Bar{x};
   // CHECK: `-VarDecl {{.*}} b5 'Bar'
   // CHECK-NEXT: `-CXXUnresolvedConstructExpr {{.*}} 'Bar' contains-errors 
'Bar'
@@ -176,6 +183,10 @@
   // CHECK-NEXT:   `-RecoveryExpr {{.*}} contains-errors
   // CHECK-NEXT: `-UnresolvedLookupExpr {{.*}} 'invalid'
   Bar b6 = Bar{invalid()};
+
+  // CHECK: `-RecoveryExpr {{.*}} 'Bar' contains-errors
+  // CHECK-NEXT:  `-IntegerLiteral {{.*}} 'int' 1
+  Bar(1);
 }
 void InitializerForAuto() {
   // CHECK: `-VarDecl {{.*}} invalid a 'auto'
Index: clang/lib/Sema/SemaExprCXX.cpp
===
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -1389,6 +1389,9 @@
   if (!Result.isInvalid() && Result.get()->isInstantiationDependent() &&
   !Result.get()->isTypeDependent())
 Result = CorrectDelayedTyposInExpr(Result.get());
+  if (Result.isInvalid())
+return CreateRecoveryExpr(TInfo->getTypeLoc().getBeginLoc(),
+  RParenOrBraceLoc, exprs, Ty);
   return Result;
 }
 


Index: clang/test/AST/ast-dump-recovery.cpp
===
--- clang/test/AST/ast-dump-recovery.cpp
+++ clang/test/AST/ast-dump-recovery.cpp
@@ -159,11 +159,18 @@
   // CHECK-NEXT: `-RecoveryExpr {{.*}} contains-errors
   // CHECK-NEXT:  `-InitListExpr
   Bar b2 = {1};
-  // FIXME: preserve the invalid initializer.
-  // CHECK: `-VarDecl {{.*}} b3 'Bar'
+  // CHECK: `-VarDecl {{.*}} b3 'Bar'
+  // CHECK-NEXT:  `-CXXConstructExpr {{.*}}  'Bar' contains-errors
+  // CHECK-NEXT:`-ImplicitCastExpr {{.*}}  'const Bar' contains-errors
+  // CHECK-NEXT:  `-RecoveryExpr {{.*}} 'Bar' contains-errors lvalue
+  // CHECK-NEXT:`-DeclRefExpr {{.*}} 'x' 'int'
   Bar b3 = Bar(x);
-  // FIXME: preserve the invalid initializer.
-  // CHECK: `-VarDecl {{.*}} b4 'Bar'
+  // CHECK: `-VarDecl {{.*}} b4 'Bar'
+  // CHECK-NEXT:  `-CXXConstructExpr {{.*}}  'Bar' contains-errors
+  // CHECK-NEXT:`-ImplicitCastExpr {{.*}} 'const Bar' contains-errors
+  // CHECK-NEXT:  `-RecoveryExpr {{.*}} 'Bar' contains-errors
+  // CHECK-NEXT:`-InitListExpr {{.*}} 'void'
+  // CHECK-NEXT:  `-DeclRefExpr {{.*}} 'x' 'int'
   Bar b4 = Bar{x};
   // CHECK: `-VarDecl {{.*}} b5 'Bar'
   // CHECK-NEXT: `-CXXUnresolvedConstructExpr {{.*}} 'Bar' contains-errors 'Bar'
@@ -176,6 +183,10 @@
   // CHECK-NEXT:   `-RecoveryExpr {{.*}} contains-errors
   // CHECK-NEXT: `-UnresolvedLookupExpr {{.*}} 'invalid'
   Bar b6 = Bar{invalid()};
+
+  // CHECK: `-RecoveryExpr {{.*}} 'Bar' contains-errors
+  // CHECK-NEXT:  `-IntegerLiteral {{.*}} 'int' 1
+  Bar(1);
 }
 void InitializerForAuto() {
   // CHECK: `-VarDecl {{.*}} invalid a 'auto'
Index: clang/lib/Sema/SemaExprCXX.cpp
===
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -1389,6 +1389,9 @@
   if (!Result.isInvalid() && Result.get()->isInstantiationDependent() &&
   !Result.get()->isTypeDependent())
 Result = CorrectDelayedTyposInExpr(Result.get());
+  if (Result.isInvalid())
+return CreateRecoveryExpr(TInfo->getTypeLoc().getBeginLoc(),
+  RParenOrBraceLoc, exprs, Ty);
   return Result;
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D81066: [clangd] Populate the parse options to CodeCompletion/SignatureHelp.

2020-06-03 Thread Haojian Wu via Phabricator via cfe-commits
hokein added inline comments.



Comment at: clang-tools-extra/clangd/CodeComplete.cpp:1108
+  std::move(CI),
+  !CompletingInPreamble ? &(Input.Preamble.Preamble) : nullptr,
   std::move(ContentsBuffer), std::move(VFS), IgnoreDiags);

sammccall wrote:
> this change looks suspicious, really needed?
oops, I think this is an accident change, reverted.



Comment at: clang-tools-extra/clangd/Compiler.h:57
   const SymbolIndex *Index = nullptr;
-  ParseOptions Opts;
+  ParseOptions Opts = ParseOptions();
 };

sammccall wrote:
> this is the default already - only need to do this for scalar types that 
> would otherwise have indeterminate default
yeah, exactly, however clang was not happy with the `ParseInputs {Command, FS, 
contents}` usage, it gave `-Wmissing-field-initializers` warning.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81066



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


cfe-commits@lists.llvm.org

2020-06-03 Thread Luke Geeson via Phabricator via cfe-commits
LukeGeeson marked an inline comment as done.
LukeGeeson added inline comments.



Comment at: llvm/test/CodeGen/AArch64/aarch64-bf16-dotprod-intrinsics.ll:4
+; CHECK-LABEL: test_vbfdot_f32
+; CHECK: bfdot   v0.2s, v1.4h, v2.4h
+define <2 x float> @test_vbfdot_f32(<2 x float> %r, <4 x bfloat> %a, <4 x 
bfloat> %b) {

miyuki wrote:
> LukeGeeson wrote:
> > LukeGeeson wrote:
> > > miyuki wrote:
> > > > Would it make sense to check the whole body of the compiled function?
> > > Oops sorry, having all kinds of issues with my commit history here, give 
> > > me a moment to address this
> > I would say it's not worth testing the whole function here, the only code 
> > emitted for each is the instruction mentioned in the `CHECK` and a `ret` 
> > surrounded by lot's of compiler labels and directives that we don't need to 
> > test here
> I meant, just the code from the first BB label to ret (inclusive), without 
> directives. I suggest using `llvm/utils/update_llc_test_checks.py` to 
> generate the checks.
Hopefully this is everything now, please let me know if there is anything else 
:) 


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

https://reviews.llvm.org/D80752



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


cfe-commits@lists.llvm.org

2020-06-03 Thread Luke Geeson via Phabricator via cfe-commits
LukeGeeson updated this revision to Diff 268165.
LukeGeeson added a comment.

ran `llvm/utils/update_llc_test_checks.py` on test to get proper `CHECK`s


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

https://reviews.llvm.org/D80752

Files:
  clang/include/clang/Basic/arm_neon.td
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/aarch64-bf16-dotprod-intrinsics.c
  llvm/include/llvm/IR/IntrinsicsAArch64.td
  llvm/lib/Target/AArch64/AArch64InstrFormats.td
  llvm/lib/Target/AArch64/AArch64InstrInfo.td
  llvm/test/CodeGen/AArch64/aarch64-bf16-dotprod-intrinsics.ll

Index: llvm/test/CodeGen/AArch64/aarch64-bf16-dotprod-intrinsics.ll
===
--- /dev/null
+++ llvm/test/CodeGen/AArch64/aarch64-bf16-dotprod-intrinsics.ll
@@ -0,0 +1,180 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc -mtriple aarch64-arm-none-eabi  -mattr=+bf16 %s -o - | FileCheck %s
+
+define <2 x float> @test_vbfdot_f32(<2 x float> %r, <4 x bfloat> %a, <4 x bfloat> %b) {
+; CHECK-LABEL: test_vbfdot_f32:
+; CHECK:   // %bb.0: // %entry
+; CHECK-NEXT:bfdot v0.2s, v1.4h, v2.4h
+; CHECK-NEXT:ret
+entry:
+  %0 = bitcast <4 x bfloat> %a to <8 x i8>
+  %1 = bitcast <4 x bfloat> %b to <8 x i8>
+  %vbfdot1.i = tail call <2 x float> @llvm.aarch64.neon.bfdot.v2f32.v8i8(<2 x float> %r, <8 x i8> %0, <8 x i8> %1)
+  ret <2 x float> %vbfdot1.i
+}
+
+define <4 x float> @test_vbfdotq_f32(<4 x float> %r, <8 x bfloat> %a, <8 x bfloat> %b) {
+; CHECK-LABEL: test_vbfdotq_f32:
+; CHECK:   // %bb.0: // %entry
+; CHECK-NEXT:bfdot v0.4s, v1.8h, v2.8h
+; CHECK-NEXT:ret
+entry:
+  %0 = bitcast <8 x bfloat> %a to <16 x i8>
+  %1 = bitcast <8 x bfloat> %b to <16 x i8>
+  %vbfdot1.i = tail call <4 x float> @llvm.aarch64.neon.bfdot.v4f32.v16i8(<4 x float> %r, <16 x i8> %0, <16 x i8> %1)
+  ret <4 x float> %vbfdot1.i
+}
+
+define <2 x float> @test_vbfdot_lane_f32(<2 x float> %r, <4 x bfloat> %a, <4 x bfloat> %b) {
+; CHECK-LABEL: test_vbfdot_lane_f32:
+; CHECK:   // %bb.0: // %entry
+; CHECK-NEXT:// kill: def $d2 killed $d2 def $q2
+; CHECK-NEXT:bfdot v0.2s, v1.4h, v2.2h[0]
+; CHECK-NEXT:ret
+entry:
+  %0 = bitcast <4 x bfloat> %b to <2 x float>
+  %shuffle = shufflevector <2 x float> %0, <2 x float> undef, <2 x i32> zeroinitializer
+  %1 = bitcast <4 x bfloat> %a to <8 x i8>
+  %2 = bitcast <2 x float> %shuffle to <8 x i8>
+  %vbfdot1.i = tail call <2 x float> @llvm.aarch64.neon.bfdot.v2f32.v8i8(<2 x float> %r, <8 x i8> %1, <8 x i8> %2)
+  ret <2 x float> %vbfdot1.i
+}
+
+define <4 x float> @test_vbfdotq_laneq_f32(<4 x float> %r, <8 x bfloat> %a, <8 x bfloat> %b) {
+; CHECK-LABEL: test_vbfdotq_laneq_f32:
+; CHECK:   // %bb.0: // %entry
+; CHECK-NEXT:bfdot v0.4s, v1.8h, v2.2h[3]
+; CHECK-NEXT:ret
+entry:
+  %0 = bitcast <8 x bfloat> %b to <4 x float>
+  %shuffle = shufflevector <4 x float> %0, <4 x float> undef, <4 x i32> 
+  %1 = bitcast <8 x bfloat> %a to <16 x i8>
+  %2 = bitcast <4 x float> %shuffle to <16 x i8>
+  %vbfdot1.i = tail call <4 x float> @llvm.aarch64.neon.bfdot.v4f32.v16i8(<4 x float> %r, <16 x i8> %1, <16 x i8> %2)
+  ret <4 x float> %vbfdot1.i
+}
+
+define <2 x float> @test_vbfdot_laneq_f32(<2 x float> %r, <4 x bfloat> %a, <8 x bfloat> %b) {
+; CHECK-LABEL: test_vbfdot_laneq_f32:
+; CHECK:   // %bb.0: // %entry
+; CHECK-NEXT:bfdot v0.2s, v1.4h, v2.2h[3]
+; CHECK-NEXT:ret
+entry:
+  %0 = bitcast <8 x bfloat> %b to <4 x float>
+  %shuffle = shufflevector <4 x float> %0, <4 x float> undef, <2 x i32> 
+  %1 = bitcast <4 x bfloat> %a to <8 x i8>
+  %2 = bitcast <2 x float> %shuffle to <8 x i8>
+  %vbfdot1.i = tail call <2 x float> @llvm.aarch64.neon.bfdot.v2f32.v8i8(<2 x float> %r, <8 x i8> %1, <8 x i8> %2)
+  ret <2 x float> %vbfdot1.i
+}
+
+define <4 x float> @test_vbfdotq_lane_f32(<4 x float> %r, <8 x bfloat> %a, <4 x bfloat> %b) {
+; CHECK-LABEL: test_vbfdotq_lane_f32:
+; CHECK:   // %bb.0: // %entry
+; CHECK-NEXT:// kill: def $d2 killed $d2 def $q2
+; CHECK-NEXT:bfdot v0.4s, v1.8h, v2.2h[0]
+; CHECK-NEXT:ret
+entry:
+  %0 = bitcast <4 x bfloat> %b to <2 x float>
+  %shuffle = shufflevector <2 x float> %0, <2 x float> undef, <4 x i32> zeroinitializer
+  %1 = bitcast <8 x bfloat> %a to <16 x i8>
+  %2 = bitcast <4 x float> %shuffle to <16 x i8>
+  %vbfdot1.i = tail call <4 x float> @llvm.aarch64.neon.bfdot.v4f32.v16i8(<4 x float> %r, <16 x i8> %1, <16 x i8> %2)
+  ret <4 x float> %vbfdot1.i
+}
+
+define <4 x float> @test_vbfmmlaq_f32(<4 x float> %r, <8 x bfloat> %a, <8 x bfloat> %b) {
+; CHECK-LABEL: test_vbfmmlaq_f32:
+; CHECK:   // %bb.0: // %entry
+; CHECK-NEXT:bfmmla v0.4s, v1.8h, v2.8h
+; CHECK-NEXT:ret
+entry:
+  %0 = bitcast <8 x bfloat> %a to <16 x i8>
+  %1 = bitcast <8 x bfloat> %b to <16 x i8>
+  %vbfmmla1.i = tail call <4 x float> @llvm.aarch64.neon.bfmmla.v4f32.v16i8(<4 x float> %r, <16 x i8> %0, <16 x i8> %1)
+  ret <4 x float> %

[PATCH] D81092: Add support for `nullptr` in SyntaxTrees

2020-06-03 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
eduucaldas added a reviewer: gribozavr2.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D81092

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

Index: clang/unittests/Tooling/Syntax/TreeTest.cpp
===
--- clang/unittests/Tooling/Syntax/TreeTest.cpp
+++ clang/unittests/Tooling/Syntax/TreeTest.cpp
@@ -670,6 +670,35 @@
 )txt");
 }
 
+TEST_P(SyntaxTreeTest, CxxNullPtrLiteral) {
+  if (!GetParam().isCXX11OrLater()) {
+return;
+  }
+  expectTreeDumpEqual(
+  R"cpp(
+void test() {
+  nullptr;
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarator
+  | |-test
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   `-)
+  `-CompoundStatement
+|-{
+|-ExpressionStatement
+| |-CxxNullPtrExpression
+| | `-nullptr
+| `-;
+`-}
+)txt");
+}
+
 TEST_P(SyntaxTreeTest, PostfixUnaryOperator) {
   expectTreeDumpEqual(
   R"cpp(
Index: clang/lib/Tooling/Syntax/Nodes.cpp
===
--- clang/lib/Tooling/Syntax/Nodes.cpp
+++ clang/lib/Tooling/Syntax/Nodes.cpp
@@ -18,6 +18,8 @@
 return OS << "TranslationUnit";
   case NodeKind::UnknownExpression:
 return OS << "UnknownExpression";
+  case NodeKind::CxxNullPtrExpression:
+return OS << "CxxNullPtrExpression";
   case NodeKind::PrefixUnaryOperatorExpression:
 return OS << "PrefixUnaryOperatorExpression";
   case NodeKind::PostfixUnaryOperatorExpression:
@@ -116,6 +118,8 @@
 return OS << "IfStatement_elseKeyword";
   case syntax::NodeRole::IfStatement_elseStatement:
 return OS << "IfStatement_elseStatement";
+  case syntax::NodeRole::CxxNullPtrExpression_keyword:
+return OS << "CxxNullPtrExpression_keyword";
   case syntax::NodeRole::UnaryOperatorExpression_operatorToken:
 return OS << "UnaryOperatorExpression_operatorToken";
   case syntax::NodeRole::UnaryOperatorExpression_operand:
@@ -158,6 +162,11 @@
   llvm_unreachable("invalid role");
 }
 
+syntax::Leaf *syntax::CxxNullPtrExpression::nullPtrKeyword() {
+  return llvm::cast_or_null(
+  findChild(syntax::NodeRole::CxxNullPtrExpression_keyword));
+}
+
 syntax::Expression *syntax::BinaryOperatorExpression::lhs() {
   return llvm::cast_or_null(
   findChild(syntax::NodeRole::BinaryOperatorExpression_leftHandSide));
Index: clang/lib/Tooling/Syntax/BuildTree.cpp
===
--- clang/lib/Tooling/Syntax/BuildTree.cpp
+++ clang/lib/Tooling/Syntax/BuildTree.cpp
@@ -608,6 +608,14 @@
 return true;
   }
 
+  bool WalkUpFromCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *S) {
+Builder.markChildToken(S->getLocation(),
+   syntax::NodeRole::CxxNullPtrExpression_keyword);
+Builder.foldNode(Builder.getExprRange(S),
+ new (allocator()) syntax::CxxNullPtrExpression, S);
+return true;
+  }
+
   bool WalkUpFromUnaryOperator(UnaryOperator *S) {
 Builder.markChildToken(
 S->getOperatorLoc(),
Index: clang/include/clang/Tooling/Syntax/Nodes.h
===
--- clang/include/clang/Tooling/Syntax/Nodes.h
+++ clang/include/clang/Tooling/Syntax/Nodes.h
@@ -43,6 +43,7 @@
   PrefixUnaryOperatorExpression,
   PostfixUnaryOperatorExpression,
   BinaryOperatorExpression,
+  CxxNullPtrExpression,
 
   // Statements.
   UnknownStatement,
@@ -112,6 +113,7 @@
   BinaryOperatorExpression_leftHandSide,
   BinaryOperatorExpression_operatorToken,
   BinaryOperatorExpression_rightHandSide,
+  CxxNullPtrExpression_keyword,
   CaseStatement_value,
   IfStatement_thenStatement,
   IfStatement_elseKeyword,
@@ -166,6 +168,16 @@
   }
 };
 
+/// C++11 'nullptr' expression.
+class CxxNullPtrExpression final : public Expression {
+public:
+  CxxNullPtrExpression() : Expression(NodeKind::CxxNullPtrExpression) {}
+  static bool classof(const Node *N) {
+return N->kind() == NodeKind::CxxNullPtrExpression;
+  }
+  syntax::Leaf *nullPtrKeyword();
+};
+
 /// An abstract class for prefix and postfix unary operators.
 class UnaryOperatorExpression : public Expression {
 public:
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D80940: [clang-format] [PR46159] Linux kernel 'C' code uses 'try' as a variable name, allow clang-format to handle such cases

2020-06-03 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay updated this revision to Diff 268163.
MyDeveloperDay added a comment.

Address review comments


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

https://reviews.llvm.org/D80940

Files:
  clang/lib/Format/FormatTokenLexer.cpp
  clang/lib/Format/FormatTokenLexer.h
  clang/unittests/Format/FormatTest.cpp


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -2664,6 +2664,18 @@
   verifyIncompleteFormat("try {} catch (");
 }
 
+TEST_F(FormatTest, FormatTryAsAVariable) {
+  verifyFormat("int try;");
+  verifyFormat("int try, size;");
+  verifyFormat("try = foo();");
+  verifyFormat("if (try < size) {\n  return true;\n}");
+
+  verifyFormat("int catch;");
+  verifyFormat("int catch, size;");
+  verifyFormat("catch = foo();");
+  verifyFormat("if (catch < size) {\n  return true;\n}");
+}
+
 TEST_F(FormatTest, FormatSEHTryCatch) {
   verifyFormat("__try {\n"
"  int a = b * c;\n"
Index: clang/lib/Format/FormatTokenLexer.h
===
--- clang/lib/Format/FormatTokenLexer.h
+++ clang/lib/Format/FormatTokenLexer.h
@@ -56,6 +56,7 @@
   bool tryMergeCSharpNullConditional();
   bool tryTransformCSharpForEach();
   bool tryMergeForEach();
+  bool tryTransformTryUsageForC();
 
   bool tryMergeTokens(ArrayRef Kinds, TokenType NewType);
 
Index: clang/lib/Format/FormatTokenLexer.cpp
===
--- clang/lib/Format/FormatTokenLexer.cpp
+++ clang/lib/Format/FormatTokenLexer.cpp
@@ -76,6 +76,8 @@
 return;
   if (tryMergeForEach())
 return;
+  if (Style.isCpp() && tryTransformTryUsageForC())
+return;
 
   if (Style.isCSharp()) {
 if (tryMergeCSharpKeywordVariables())
@@ -383,6 +385,26 @@
   return true;
 }
 
+bool FormatTokenLexer::tryTransformTryUsageForC() {
+  if (Tokens.size() < 2)
+return false;
+  auto &Try = *(Tokens.end() - 2);
+  if (!Try->is(tok::kw_try))
+return false;
+  auto &Next = *(Tokens.end() - 1);
+  if (Next->isOneOf(tok::l_brace, tok::colon))
+return false;
+
+  if (Tokens.size() > 2) {
+auto &At = *(Tokens.end() - 3);
+if (At->is(tok::at))
+  return false;
+  }
+
+  Try->Tok.setKind(tok::identifier);
+  return true;
+}
+
 bool FormatTokenLexer::tryMergeLessLess() {
   // Merge X,less,less,Y into X,lessless,Y unless X or Y is less.
   if (Tokens.size() < 3)


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -2664,6 +2664,18 @@
   verifyIncompleteFormat("try {} catch (");
 }
 
+TEST_F(FormatTest, FormatTryAsAVariable) {
+  verifyFormat("int try;");
+  verifyFormat("int try, size;");
+  verifyFormat("try = foo();");
+  verifyFormat("if (try < size) {\n  return true;\n}");
+
+  verifyFormat("int catch;");
+  verifyFormat("int catch, size;");
+  verifyFormat("catch = foo();");
+  verifyFormat("if (catch < size) {\n  return true;\n}");
+}
+
 TEST_F(FormatTest, FormatSEHTryCatch) {
   verifyFormat("__try {\n"
"  int a = b * c;\n"
Index: clang/lib/Format/FormatTokenLexer.h
===
--- clang/lib/Format/FormatTokenLexer.h
+++ clang/lib/Format/FormatTokenLexer.h
@@ -56,6 +56,7 @@
   bool tryMergeCSharpNullConditional();
   bool tryTransformCSharpForEach();
   bool tryMergeForEach();
+  bool tryTransformTryUsageForC();
 
   bool tryMergeTokens(ArrayRef Kinds, TokenType NewType);
 
Index: clang/lib/Format/FormatTokenLexer.cpp
===
--- clang/lib/Format/FormatTokenLexer.cpp
+++ clang/lib/Format/FormatTokenLexer.cpp
@@ -76,6 +76,8 @@
 return;
   if (tryMergeForEach())
 return;
+  if (Style.isCpp() && tryTransformTryUsageForC())
+return;
 
   if (Style.isCSharp()) {
 if (tryMergeCSharpKeywordVariables())
@@ -383,6 +385,26 @@
   return true;
 }
 
+bool FormatTokenLexer::tryTransformTryUsageForC() {
+  if (Tokens.size() < 2)
+return false;
+  auto &Try = *(Tokens.end() - 2);
+  if (!Try->is(tok::kw_try))
+return false;
+  auto &Next = *(Tokens.end() - 1);
+  if (Next->isOneOf(tok::l_brace, tok::colon))
+return false;
+
+  if (Tokens.size() > 2) {
+auto &At = *(Tokens.end() - 3);
+if (At->is(tok::at))
+  return false;
+  }
+
+  Try->Tok.setKind(tok::identifier);
+  return true;
+}
+
 bool FormatTokenLexer::tryMergeLessLess() {
   // Merge X,less,less,Y into X,lessless,Y unless X or Y is less.
   if (Tokens.size() < 3)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D81037: [OPENMP]Fix PR46170: partial mapping for array sections of data members.

2020-06-03 Thread Alexey Bataev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG59e0987a068c: [OPENMP]Fix PR46170: partial mapping for array 
sections of data members. (authored by ABataev).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81037

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/test/OpenMP/target_map_member_expr_array_section_codegen.cpp

Index: clang/test/OpenMP/target_map_member_expr_array_section_codegen.cpp
===
--- /dev/null
+++ clang/test/OpenMP/target_map_member_expr_array_section_codegen.cpp
@@ -0,0 +1,114 @@
+// RUN: %clang_cc1 -verify -fopenmp -fopenmp-targets=powerpc64le-ibm-linux-gnu -x c++ -triple powerpc64le-unknown-unknown -emit-llvm %s -o - | FileCheck %s
+// RUN: %clang_cc1 -fopenmp -fopenmp-targets=powerpc64le-ibm-linux-gnu -x c++ -std=c++11 -triple powerpc64le-unknown-unknown -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp -fopenmp-targets=powerpc64le-ibm-linux-gnu -x c++ -triple powerpc64le-unknown-unknown -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s
+// expected-no-diagnostics
+#ifndef HEADER
+#define HEADER
+
+// 32 = 0x20 = OMP_MAP_TARGET_PARAM
+// 281474976710656 = 0x1 = OMP_MAP_MEMBER_OF of 1-st element
+// CHECK: [[MAP_ENTER:@.+]] = private unnamed_addr constant [2 x i64] [i64 32, i64 281474976710656]
+// 281474976710664 = 0x10008 = OMP_MAP_MEMBER_OF of 1-st element | OMP_MAP_DELETE
+// CHECK: [[MAP_EXIT:@.+]] = private unnamed_addr constant [2 x i64] [i64 32, i64 281474976710664]
+template 
+struct S {
+  constexpr static int size = 6;
+  T data[size];
+};
+
+template 
+struct maptest {
+  S s;
+  maptest() {
+// CHECK: [[BPTRS:%.+]] = alloca [2 x i8*],
+// CHECK: [[PTRS:%.+]] = alloca [2 x i8*],
+// CHECK: [[SIZES:%.+]] = alloca [2 x i64],
+// CHECK: getelementptr inbounds
+// CHECK: [[S_ADDR:%.+]] = getelementptr inbounds %struct.maptest, %struct.maptest* [[THIS:%.+]], i32 0, i32 0
+// CHECK: [[S_DATA_ADDR:%.+]] = getelementptr inbounds %struct.S, %struct.S* [[S_ADDR]], i32 0, i32 0
+// CHECK: [[S_DATA_0_ADDR:%.+]] = getelementptr inbounds [6 x float], [6 x float]* [[S_DATA_ADDR]], i64 0, i64 0
+
+// SZ = &this->s.data[6]-&this->s.data[0]
+// CHECK: [[S_ADDR:%.+]] = getelementptr inbounds %struct.maptest, %struct.maptest* [[THIS]], i32 0, i32 0
+// CHECK: [[S_DATA_ADDR:%.+]] = getelementptr inbounds %struct.S, %struct.S* [[S_ADDR]], i32 0, i32 0
+// CHECK: [[S_DATA_5_ADDR:%.+]] = getelementptr inbounds [6 x float], [6 x float]* [[S_DATA_ADDR]], i64 0, i64 5
+// CHECK: [[S_DATA_6_ADDR:%.+]] = getelementptr float, float* [[S_DATA_5_ADDR]], i32 1
+// CHECK: [[BEG:%.+]] = bitcast float* [[S_DATA_0_ADDR]] to i8*
+// CHECK: [[END:%.+]] = bitcast float* [[S_DATA_6_ADDR]] to i8*
+// CHECK: [[END_BC:%.+]] = ptrtoint i8* [[END]] to i64
+// CHECK: [[BEG_BC:%.+]] = ptrtoint i8* [[BEG]] to i64
+// CHECK: [[DIFF:%.+]] = sub i64 [[END_BC]], [[BEG_BC]]
+// CHECK: [[SZ:%.+]] = sdiv exact i64 [[DIFF]], ptrtoint (i8* getelementptr (i8, i8* null, i32 1) to i64)
+
+// Fill mapping arrays
+// CHECK: [[BPTR0:%.+]] = getelementptr inbounds [2 x i8*], [2 x i8*]* [[BPTRS]], i32 0, i32 0
+// CHECK: [[BPTR0_THIS:%.+]] = bitcast i8** [[BPTR0]] to %struct.maptest**
+// CHECK: store %struct.maptest* [[THIS]], %struct.maptest** [[BPTR0_THIS]],
+// CHECK: [[PTR0:%.+]] = getelementptr inbounds [2 x i8*], [2 x i8*]* [[PTRS]], i32 0, i32 0
+// CHECK: [[PTR0_DATA:%.+]] = bitcast i8** [[PTR0]] to float**
+// CHECK: store float* [[S_DATA_0_ADDR]], float** [[PTR0_DATA]],
+// CHECK: [[SIZE0:%.+]] = getelementptr inbounds [2 x i64], [2 x i64]* [[SIZES]], i32 0, i32 0
+// CHECK: store i64 [[SZ]], i64* [[SIZE0]],
+// CHECK: [[BPTR1:%.+]] = getelementptr inbounds [2 x i8*], [2 x i8*]* [[BPTRS]], i32 0, i32 1
+// CHECK: [[BPTR1_THIS:%.+]] = bitcast i8** [[BPTR1]] to %struct.maptest**
+// CHECK: store %struct.maptest* [[THIS]], %struct.maptest** [[BPTR1_THIS]],
+// CHECK: [[PTR1:%.+]] = getelementptr inbounds [2 x i8*], [2 x i8*]* [[PTRS]], i32 0, i32 1
+// CHECK: [[PTR1_DATA:%.+]] = bitcast i8** [[PTR1]] to float**
+// CHECK: store float* [[S_DATA_0_ADDR]], float** [[PTR1_DATA]],
+// CHECK: [[SIZE1:%.+]] = getelementptr inbounds [2 x i64], [2 x i64]* [[SIZES]], i32 0, i32 1
+// CHECK: store i64 24, i64* [[SIZE1]],
+// CHECK: [[BPTR:%.+]] = getelementptr inbounds [2 x i8*], [2 x i8*]* [[BPTRS]], i32 0, i32 0
+// CHECK: [[PTR:%.+]] = getelementptr inbounds [2 x i8*], [2 x i8*]* [[PTRS]], i32 0, i32 0
+// CHECK: [[SIZE:%.+]] = getelementptr inbounds [2 x i64], [2 x i64]* [[SIZES]], i32 0, i32 0
+// CHECK: call void @__tgt_target_data_begin(i64 -1, i32 2, i8** [[BPTR]], i8** [[PTR]], i64* [[SIZE]], i64* getelementptr inbounds ([2 x i64], [2 x i64]* [[M

[PATCH] D80933: [clang-format] [PR46157] Wrong spacing of negative literals with use of operator

2020-06-03 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay updated this revision to Diff 268166.
MyDeveloperDay added a comment.

Ensure no crash when CurrentToken is nullptr


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

https://reviews.llvm.org/D80933

Files:
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/FormatTest.cpp


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -16417,6 +16417,17 @@
   verifyFormat("operator&&(int(&&)(), class Foo);", Style);
 }
 
+TEST_F(FormatTest, OperatorPassedAsAFunctionPtr) {
+  FormatStyle Style = getLLVMStyle();
+  // PR46157
+  verifyFormat("foo(operator+, -42);", Style);
+  verifyFormat("foo(operator++, -42);", Style);
+  verifyFormat("foo(operator--, -42);", Style);
+  verifyFormat("foo(-42, operator--);", Style);
+  verifyFormat("foo(-42, operator, );", Style);
+  verifyFormat("foo(operator, , -42);", Style);
+}
+
 TEST_F(FormatTest, VeryLongNamespaceCommentSplit) {
   // These tests are not in NamespaceFixer because that doesn't
   // test its interaction with line wrapping
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -978,16 +978,18 @@
 if (CurrentToken->isOneOf(tok::star, tok::amp))
   CurrentToken->setType(TT_PointerOrReference);
 consumeToken();
+if (CurrentToken && CurrentToken->is(tok::comma) &&
+CurrentToken->Previous->isNot(tok::kw_operator))
+  break;
 if (CurrentToken && CurrentToken->Previous->isOneOf(
 TT_BinaryOperator, TT_UnaryOperator, 
tok::comma,
 tok::star, tok::arrow, tok::amp, tok::ampamp))
   CurrentToken->Previous->setType(TT_OverloadedOperator);
   }
-  if (CurrentToken) {
+  if (CurrentToken && CurrentToken->is(tok::l_paren))
 CurrentToken->setType(TT_OverloadedOperatorLParen);
-if (CurrentToken->Previous->is(TT_BinaryOperator))
-  CurrentToken->Previous->setType(TT_OverloadedOperator);
-  }
+  if (CurrentToken && CurrentToken->Previous->is(TT_BinaryOperator))
+CurrentToken->Previous->setType(TT_OverloadedOperator);
   break;
 case tok::question:
   if (Tok->is(TT_CSharpNullConditionalLSquare)) {


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -16417,6 +16417,17 @@
   verifyFormat("operator&&(int(&&)(), class Foo);", Style);
 }
 
+TEST_F(FormatTest, OperatorPassedAsAFunctionPtr) {
+  FormatStyle Style = getLLVMStyle();
+  // PR46157
+  verifyFormat("foo(operator+, -42);", Style);
+  verifyFormat("foo(operator++, -42);", Style);
+  verifyFormat("foo(operator--, -42);", Style);
+  verifyFormat("foo(-42, operator--);", Style);
+  verifyFormat("foo(-42, operator, );", Style);
+  verifyFormat("foo(operator, , -42);", Style);
+}
+
 TEST_F(FormatTest, VeryLongNamespaceCommentSplit) {
   // These tests are not in NamespaceFixer because that doesn't
   // test its interaction with line wrapping
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -978,16 +978,18 @@
 if (CurrentToken->isOneOf(tok::star, tok::amp))
   CurrentToken->setType(TT_PointerOrReference);
 consumeToken();
+if (CurrentToken && CurrentToken->is(tok::comma) &&
+CurrentToken->Previous->isNot(tok::kw_operator))
+  break;
 if (CurrentToken && CurrentToken->Previous->isOneOf(
 TT_BinaryOperator, TT_UnaryOperator, tok::comma,
 tok::star, tok::arrow, tok::amp, tok::ampamp))
   CurrentToken->Previous->setType(TT_OverloadedOperator);
   }
-  if (CurrentToken) {
+  if (CurrentToken && CurrentToken->is(tok::l_paren))
 CurrentToken->setType(TT_OverloadedOperatorLParen);
-if (CurrentToken->Previous->is(TT_BinaryOperator))
-  CurrentToken->Previous->setType(TT_OverloadedOperator);
-  }
+  if (CurrentToken && CurrentToken->Previous->is(TT_BinaryOperator))
+CurrentToken->Previous->setType(TT_OverloadedOperator);
   break;
 case tok::question:
   if (Tok->is(TT_CSharpNullConditionalLSquare)) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D80300: [Driver] Add DEFAULT_DYLD_PREFIX and DEFAULT_RPATH to complement DEFAULT_SYSROOT

2020-06-03 Thread Joerg Sonnenberger via Phabricator via cfe-commits
joerg added a comment.

I don't agree with the justification at all, but it also seems that noone else 
cares about the build option creep here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80300



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


[clang-tools-extra] a3220df - [clangd] Add std::move() to a return statement to please some compilers.

2020-06-03 Thread Martin Boehme via cfe-commits

Author: Martin Boehme
Date: 2020-06-03T15:40:01+02:00
New Revision: a3220dffcb1da0cfe3e22a336141c76c78d474b7

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

LOG: [clangd] Add std::move() to a return statement to please some compilers.

This has been causing build errors in Swift CI.

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

Added: 


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

Removed: 




diff  --git a/clang-tools-extra/clangd/index/FileIndex.cpp 
b/clang-tools-extra/clangd/index/FileIndex.cpp
index 79ec1120df98..1a18af1303dd 100644
--- a/clang-tools-extra/clangd/index/FileIndex.cpp
+++ b/clang-tools-extra/clangd/index/FileIndex.cpp
@@ -201,7 +201,8 @@ FileShardedIndex::getShard(llvm::StringRef Uri) const {
 RelB.insert(*Rel);
   }
   IF.Relations = std::move(RelB).build();
-  return IF;
+  // Explicit move here is needed by some compilers.
+  return std::move(IF);
 }
 
 SlabTuple indexMainDecls(ParsedAST &AST) {



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


[clang] 15a1780 - [PowerPC] Replace subtract-from-zero float in version with fneg in PowerPC special fma compiler builtins

2020-06-03 Thread Kevin P. Neal via cfe-commits

Author: Andrew Wock
Date: 2020-06-03T09:45:27-04:00
New Revision: 15a1780a10e3ba4573b8c1e02e24d3f0a785e199

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

LOG: [PowerPC] Replace subtract-from-zero float in version with fneg in PowerPC 
special fma compiler builtins

This is a re-revert with a corrected test.

This patch adds a test for the PowerPC fma compiler builtins, some variations
of which negate inputs and outputs. The code to generate IR for these
builtins was untested before this patch.

Originally, the code used the outdated method of subtracting floating point
values from -0.0 as floating point negation. This patch remedies that.

Patch by: Drew Wock 
Differential Revision: https://reviews.llvm.org/D76949

Added: 
clang/test/CodeGen/builtins-ppc-fma.c

Modified: 
clang/lib/CodeGen/CGBuiltin.cpp
clang/test/CodeGen/builtins-ppc-vsx.c

Removed: 




diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 13c24a5d2686..948d31312bd8 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -14056,7 +14056,6 @@ Value *CodeGenFunction::EmitPPCBuiltinExpr(unsigned 
BuiltinID,
 Value *X = EmitScalarExpr(E->getArg(0));
 Value *Y = EmitScalarExpr(E->getArg(1));
 Value *Z = EmitScalarExpr(E->getArg(2));
-Value *Zero = llvm::ConstantFP::getZeroValueForNegation(ResultType);
 llvm::Function *F = CGM.getIntrinsic(Intrinsic::fma, ResultType);
 switch (BuiltinID) {
   case PPC::BI__builtin_vsx_xvmaddadp:
@@ -14064,17 +14063,14 @@ Value *CodeGenFunction::EmitPPCBuiltinExpr(unsigned 
BuiltinID,
 return Builder.CreateCall(F, {X, Y, Z});
   case PPC::BI__builtin_vsx_xvnmaddadp:
   case PPC::BI__builtin_vsx_xvnmaddasp:
-return Builder.CreateFSub(Zero,
-  Builder.CreateCall(F, {X, Y, Z}), "sub");
+return Builder.CreateFNeg(Builder.CreateCall(F, {X, Y, Z}), "neg");
   case PPC::BI__builtin_vsx_xvmsubadp:
   case PPC::BI__builtin_vsx_xvmsubasp:
-return Builder.CreateCall(F,
-  {X, Y, Builder.CreateFSub(Zero, Z, "sub")});
+return Builder.CreateCall(F, {X, Y, Builder.CreateFNeg(Z, "neg")});
   case PPC::BI__builtin_vsx_xvnmsubadp:
   case PPC::BI__builtin_vsx_xvnmsubasp:
-Value *FsubRes =
-  Builder.CreateCall(F, {X, Y, Builder.CreateFSub(Zero, Z, "sub")});
-return Builder.CreateFSub(Zero, FsubRes, "sub");
+return Builder.CreateFNeg(
+Builder.CreateCall(F, {X, Y, Builder.CreateFNeg(Z, "neg")}), 
"neg");
 }
 llvm_unreachable("Unknown FMA operation");
 return nullptr; // Suppress no-return warning

diff  --git a/clang/test/CodeGen/builtins-ppc-fma.c 
b/clang/test/CodeGen/builtins-ppc-fma.c
new file mode 100644
index ..3f124e8c8299
--- /dev/null
+++ b/clang/test/CodeGen/builtins-ppc-fma.c
@@ -0,0 +1,43 @@
+// RUN: %clang_cc1 -triple powerpc64le-gnu-linux \
+// RUN: -target-feature +altivec -Wall -Wno-unused -Werror -emit-llvm %s -o - 
| FileCheck  \
+// RUN: %s
+
+typedef __attribute__((vector_size(4 * sizeof(float float vec_float;
+typedef __attribute__((vector_size(2 * sizeof(double double vec_double;
+
+volatile vec_double vd;
+volatile vec_float vf;
+
+void test_fma(void) {
+  vf = __builtin_vsx_xvmaddasp(vf, vf, vf);
+  // CHECK: @llvm.fma.v4f32(<4 x float> %{{.*}}, <4 x float> %{{.*}}, <4 x 
float> %{{.*}})
+
+  vd = __builtin_vsx_xvmaddadp(vd, vd, vd);
+  // CHECK: @llvm.fma.v2f64(<2 x double> %{{.*}}, <2 x double> %{{.*}}, <2 x 
double> %{{.*}})
+
+  vf = __builtin_vsx_xvnmaddasp(vf, vf, vf);
+  // CHECK: [[RESULT:%[^ ]+]] = call <4 x float> @llvm.fma.v4f32(<4 x float> 
%{{.*}}, <4 x float> %{{.*}}, <4 x float> %{{.*}})
+  // CHECK: fneg <4 x float> [[RESULT]]
+
+  vd = __builtin_vsx_xvnmaddadp(vd, vd, vd);
+  // CHECK: [[RESULT:%[^ ]+]] = call <2 x double> @llvm.fma.v2f64(<2 x double> 
%{{.*}}, <2 x double> %{{.*}}, <2 x double> %{{.*}})
+  // CHECK: fneg <2 x double> [[RESULT]]
+
+  vf = __builtin_vsx_xvmsubasp(vf, vf, vf);
+  // CHECK: [[RESULT:%[^ ]+]] = fneg <4 x float> %{{.*}}
+  // CHECK: @llvm.fma.v4f32(<4 x float> %{{.*}}, <4 x float> %{{.*}}, <4 x 
float> [[RESULT]])
+
+  vd = __builtin_vsx_xvmsubadp(vd, vd, vd);
+  // CHECK: [[RESULT:%[^ ]+]] = fneg <2 x double> %{{.*}}
+  // CHECK: <2 x double> @llvm.fma.v2f64(<2 x double> %{{.*}}, <2 x double> 
%{{.*}}, <2 x double> [[RESULT]])
+
+  vf = __builtin_vsx_xvnmsubasp(vf, vf, vf);
+  // CHECK: [[RESULT:%[^ ]+]] = fneg <4 x float> %{{.*}}
+  // CHECK: [[RESULT2:%[^ ]+]] = call <4 x float> @llvm.fma.v4f32(<4 x float> 
%{{.*}}, <4 x float> %{{.*}}, <4 x float> [[RESULT]])
+  // CHECK: fneg <4 x float> [[RESULT2]]
+
+  vd = __builtin_vsx_xvnms

[clang] 007098d - Add support for `nullptr` in SyntaxTrees

2020-06-03 Thread Dmitri Gribenko via cfe-commits

Author: Eduardo Caldas
Date: 2020-06-03T15:52:33+02:00
New Revision: 007098d7e6b8cf2cf1f1142908840a378d60c545

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

LOG: Add support for `nullptr` in SyntaxTrees

Reviewers: gribozavr2

Reviewed By: gribozavr2

Subscribers: cfe-commits

Tags: #clang

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

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/TreeTest.cpp

Removed: 




diff  --git a/clang/include/clang/Tooling/Syntax/Nodes.h 
b/clang/include/clang/Tooling/Syntax/Nodes.h
index e240becbf883..ce4dc35977f1 100644
--- a/clang/include/clang/Tooling/Syntax/Nodes.h
+++ b/clang/include/clang/Tooling/Syntax/Nodes.h
@@ -43,6 +43,7 @@ enum class NodeKind : uint16_t {
   PrefixUnaryOperatorExpression,
   PostfixUnaryOperatorExpression,
   BinaryOperatorExpression,
+  CxxNullPtrExpression,
 
   // Statements.
   UnknownStatement,
@@ -112,6 +113,7 @@ enum class NodeRole : uint8_t {
   BinaryOperatorExpression_leftHandSide,
   BinaryOperatorExpression_operatorToken,
   BinaryOperatorExpression_rightHandSide,
+  CxxNullPtrExpression_keyword,
   CaseStatement_value,
   IfStatement_thenStatement,
   IfStatement_elseKeyword,
@@ -166,6 +168,16 @@ class UnknownExpression final : public Expression {
   }
 };
 
+/// C++11 'nullptr' expression.
+class CxxNullPtrExpression final : public Expression {
+public:
+  CxxNullPtrExpression() : Expression(NodeKind::CxxNullPtrExpression) {}
+  static bool classof(const Node *N) {
+return N->kind() == NodeKind::CxxNullPtrExpression;
+  }
+  syntax::Leaf *nullPtrKeyword();
+};
+
 /// An abstract class for prefix and postfix unary operators.
 class UnaryOperatorExpression : public Expression {
 public:

diff  --git a/clang/lib/Tooling/Syntax/BuildTree.cpp 
b/clang/lib/Tooling/Syntax/BuildTree.cpp
index 1c473d872034..dcc7b3e19390 100644
--- a/clang/lib/Tooling/Syntax/BuildTree.cpp
+++ b/clang/lib/Tooling/Syntax/BuildTree.cpp
@@ -608,6 +608,14 @@ class BuildTreeVisitor : public 
RecursiveASTVisitor {
 return true;
   }
 
+  bool WalkUpFromCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *S) {
+Builder.markChildToken(S->getLocation(),
+   syntax::NodeRole::CxxNullPtrExpression_keyword);
+Builder.foldNode(Builder.getExprRange(S),
+ new (allocator()) syntax::CxxNullPtrExpression, S);
+return true;
+  }
+
   bool WalkUpFromUnaryOperator(UnaryOperator *S) {
 Builder.markChildToken(
 S->getOperatorLoc(),

diff  --git a/clang/lib/Tooling/Syntax/Nodes.cpp 
b/clang/lib/Tooling/Syntax/Nodes.cpp
index f0f1a8ed13c2..3311b8df034c 100644
--- a/clang/lib/Tooling/Syntax/Nodes.cpp
+++ b/clang/lib/Tooling/Syntax/Nodes.cpp
@@ -18,6 +18,8 @@ llvm::raw_ostream &syntax::operator<<(llvm::raw_ostream &OS, 
NodeKind K) {
 return OS << "TranslationUnit";
   case NodeKind::UnknownExpression:
 return OS << "UnknownExpression";
+  case NodeKind::CxxNullPtrExpression:
+return OS << "CxxNullPtrExpression";
   case NodeKind::PrefixUnaryOperatorExpression:
 return OS << "PrefixUnaryOperatorExpression";
   case NodeKind::PostfixUnaryOperatorExpression:
@@ -116,6 +118,8 @@ llvm::raw_ostream &syntax::operator<<(llvm::raw_ostream 
&OS, NodeRole R) {
 return OS << "IfStatement_elseKeyword";
   case syntax::NodeRole::IfStatement_elseStatement:
 return OS << "IfStatement_elseStatement";
+  case syntax::NodeRole::CxxNullPtrExpression_keyword:
+return OS << "CxxNullPtrExpression_keyword";
   case syntax::NodeRole::UnaryOperatorExpression_operatorToken:
 return OS << "UnaryOperatorExpression_operatorToken";
   case syntax::NodeRole::UnaryOperatorExpression_operand:
@@ -158,6 +162,11 @@ llvm::raw_ostream &syntax::operator<<(llvm::raw_ostream 
&OS, NodeRole R) {
   llvm_unreachable("invalid role");
 }
 
+syntax::Leaf *syntax::CxxNullPtrExpression::nullPtrKeyword() {
+  return llvm::cast_or_null(
+  findChild(syntax::NodeRole::CxxNullPtrExpression_keyword));
+}
+
 syntax::Expression *syntax::BinaryOperatorExpression::lhs() {
   return llvm::cast_or_null(
   findChild(syntax::NodeRole::BinaryOperatorExpression_leftHandSide));

diff  --git a/clang/unittests/Tooling/Syntax/TreeTest.cpp 
b/clang/unittests/Tooling/Syntax/TreeTest.cpp
index 24943acf733e..b8a188a1a76b 100644
--- a/clang/unittests/Tooling/Syntax/TreeTest.cpp
+++ b/clang/unittests/Tooling/Syntax/TreeTest.cpp
@@ -670,6 +670,35 @@ void test() {
 )txt");
 }
 
+TEST_P(SyntaxTreeTest, CxxNullPtrLiteral) {
+  if (!GetParam().isCXX11OrLater()) {
+return;
+  }
+  expectTreeDumpEqual(
+  R"cpp(
+void test() {
+  nullptr;
+}
+)cpp",
+  R"txt(
+*: Translat

[PATCH] D80900: [clangd] Use different FS in PreambleThread

2020-06-03 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

In D80900#2069566 , @kadircet wrote:

> In D80900#2066327 , @sammccall wrote:
>
> > TL;DR: I think there are three viable paths that we should consider:
> >  A) minimal change: put the FSProvider in ParseInputs
> >  B) this patch, but with more documentation and safety
> >  C) fight to clean up VFS multithreading semantics
> >
> > Assuming we don't want to block on C, I'm not sure whether A or B is 
> > conceptually better. But A is a smaller change and brings side benefits, so 
> > wondering if you see advantages in B.
>
>
> I didn't want to go for A) as I was afraid of satisfying the contract on 
> `FileSystemProvider::getFileSystem`
>
>   /// Context::current() will be the context passed to the clang entrypoint,
>   /// such as addDocument(), and will also be propagated to result callbacks.
>   
>
> As this patch keep the `FileSystemProvider` inside TUScheduler.cpp and we 
> need to ensure context is always the one we received in the entrypoint. 
> Whereas `ParseInputs` is widely
>  passed around, and ensuring that assumption holds might be hard.


That makes sense. However I don't think that contract is conceptually that 
great, having the ideas of "threadsafe FS" and "maybe-context-aware FS" coupled 
together is... weird. The benefit is that it's an easier contract to satisfy.

It's already the case that the context could/should be plumbed through to the 
actual FS operations and other extension points. Things like tracing rely on 
it. I think saying "we always plumb context through to everything" is a better 
contract even if it's a bit stronger than we need and harder to prove 
satisfied. This frees up FileSystemProvider to be the conceptually-simple 
ThreadsafeFS that could be lifted from clangd/support to llvm/support if we 
want.

WDYT?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80900



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


[PATCH] D80947: Add to the Coding Standard our that single-line bodies omit braces

2020-06-03 Thread Erich Keane via Phabricator via cfe-commits
erichkeane marked 5 inline comments as done.
erichkeane added inline comments.



Comment at: llvm/docs/CodingStandards.rst:1573
 
+Don't Use Braces on Simple Single-Statement Bodies of if/else/loop Statements
+^

arsenm wrote:
> I would rather just ban single line statements like this and require putting 
> them on the next line.
> 
> For the case of cases, especially when combined with the style of not 
> indenting the cases from the switch, omitting braces is really painful. So 
> many times I've produced bad merges and had a hard time figuring out where 
> the double }} at the end is necessary. It would be easier to just always use 
> the braces
It is not my intent in this patch to actually change our coding standard, 
simply to codify the rule that we've been enforcing for a decade.



Comment at: llvm/docs/CodingStandards.rst:1603
+
+  // This should also omit braces.  The for loop contains only a single 
statement,
+  // so it shouldn't have braces.  The if also only contains a single 
statement (the

arsenm wrote:
> This loop should use braces. It covers multiple lines. Omitting braces 
> invariably just increases diffs/merge conflicts when something else is added 
> to the loop body.
> 
> This one isn't consistently applied and I've been enforcing the opposite
This is how we've been enforcing the rule however, can you suggest a change to 
the wording that you think would match our current enforcement?


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

https://reviews.llvm.org/D80947



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


[PATCH] D80514: [clang-tidy] modernize-use-trailing-return-type support for C++20 concepts and decltype

2020-06-03 Thread Nathan James via Phabricator via cfe-commits
njames93 added a comment.

In D80514#2071056 , @bernhardmgruber 
wrote:

> Reuploaded diff in an attempt to trigger a CI build.


It's not working, Still no big issue, when its ready to land just the checks 
locally


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

https://reviews.llvm.org/D80514



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


[PATCH] D80936: [OPENMP]Fix PR46146: Do not consider globalized variables as NRVO candidates.

2020-06-03 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev updated this revision to Diff 268177.
ABataev added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80936

Files:
  clang/lib/CodeGen/CGStmt.cpp
  clang/test/OpenMP/nvptx_NRVO_variable.cpp


Index: clang/test/OpenMP/nvptx_NRVO_variable.cpp
===
--- /dev/null
+++ clang/test/OpenMP/nvptx_NRVO_variable.cpp
@@ -0,0 +1,30 @@
+// Test target codegen - host bc file has to be created first.
+// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple powerpc64le-unknown-unknown 
-fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm-bc %s -o %t-ppc-host.bc
+// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple nvptx64-unknown-unknown 
-fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm %s -fopenmp-is-device 
-fopenmp-host-ir-file-path %t-ppc-host.bc -o - | FileCheck %s
+// expected-no-diagnostics
+#ifndef HEADER
+#define HEADER
+
+struct S {
+  int a;
+  S() : a(1) {}
+};
+
+#pragma omp declare target
+void bar(S &);
+// CHECK-LABEL: foo
+S foo() {
+  // CHECK: [[RETVAL:%.+]] = alloca %struct.S,
+  S s;
+  // CHECK: call void @{{.+}}bar{{.+}}(%struct.S* {{.*}}[[S_REF:%.+]])
+  bar(s);
+  // CHECK: [[DEST:%.+]] = bitcast %struct.S* [[RETVAL]] to i8*
+  // CHECK: [[SOURCE:%.+]] = bitcast %struct.S* [[S_REF]] to i8*
+  // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* {{.*}}[[DEST]], i8* 
{{.*}}[[SOURCE]], i64 4, i1 false)
+  // CHECK: [[VAL:%.+]] = load %struct.S, %struct.S* [[RETVAL]],
+  // CHECK: ret %struct.S [[VAL]]
+  return s;
+}
+#pragma omp end declare target
+
+#endif
Index: clang/lib/CodeGen/CGStmt.cpp
===
--- clang/lib/CodeGen/CGStmt.cpp
+++ clang/lib/CodeGen/CGStmt.cpp
@@ -11,6 +11,7 @@
 
//===--===//
 
 #include "CGDebugInfo.h"
+#include "CGOpenMPRuntime.h"
 #include "CodeGenFunction.h"
 #include "CodeGenModule.h"
 #include "TargetInfo.h"
@@ -1106,8 +1107,13 @@
 
   // FIXME: Clean this up by using an LValue for ReturnTemp,
   // EmitStoreThroughLValue, and EmitAnyExpr.
-  if (getLangOpts().ElideConstructors &&
-  S.getNRVOCandidate() && S.getNRVOCandidate()->isNRVOVariable()) {
+  // Check if the NRVO candidate was not globalized in OpenMP mode.
+  if (getLangOpts().ElideConstructors && S.getNRVOCandidate() &&
+  S.getNRVOCandidate()->isNRVOVariable() &&
+  (!getLangOpts().OpenMP ||
+   !CGM.getOpenMPRuntime()
+.getAddressOfLocalVariable(*this, S.getNRVOCandidate())
+.isValid())) {
 // Apply the named return value optimization for this return statement,
 // which means doing nothing: the appropriate result has already been
 // constructed into the NRVO variable.


Index: clang/test/OpenMP/nvptx_NRVO_variable.cpp
===
--- /dev/null
+++ clang/test/OpenMP/nvptx_NRVO_variable.cpp
@@ -0,0 +1,30 @@
+// Test target codegen - host bc file has to be created first.
+// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm-bc %s -o %t-ppc-host.bc
+// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple nvptx64-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o - | FileCheck %s
+// expected-no-diagnostics
+#ifndef HEADER
+#define HEADER
+
+struct S {
+  int a;
+  S() : a(1) {}
+};
+
+#pragma omp declare target
+void bar(S &);
+// CHECK-LABEL: foo
+S foo() {
+  // CHECK: [[RETVAL:%.+]] = alloca %struct.S,
+  S s;
+  // CHECK: call void @{{.+}}bar{{.+}}(%struct.S* {{.*}}[[S_REF:%.+]])
+  bar(s);
+  // CHECK: [[DEST:%.+]] = bitcast %struct.S* [[RETVAL]] to i8*
+  // CHECK: [[SOURCE:%.+]] = bitcast %struct.S* [[S_REF]] to i8*
+  // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* {{.*}}[[DEST]], i8* {{.*}}[[SOURCE]], i64 4, i1 false)
+  // CHECK: [[VAL:%.+]] = load %struct.S, %struct.S* [[RETVAL]],
+  // CHECK: ret %struct.S [[VAL]]
+  return s;
+}
+#pragma omp end declare target
+
+#endif
Index: clang/lib/CodeGen/CGStmt.cpp
===
--- clang/lib/CodeGen/CGStmt.cpp
+++ clang/lib/CodeGen/CGStmt.cpp
@@ -11,6 +11,7 @@
 //===--===//
 
 #include "CGDebugInfo.h"
+#include "CGOpenMPRuntime.h"
 #include "CodeGenFunction.h"
 #include "CodeGenModule.h"
 #include "TargetInfo.h"
@@ -1106,8 +1107,13 @@
 
   // FIXME: Clean this up by using an LValue for ReturnTemp,
   // EmitStoreThroughLValue, and EmitAnyExpr.
-  if (getLangOpts().ElideConstructors &&
-  S.getNRVOCandidate() && S.getNRVOCandidate()->isNRVOVariable()) {
+  // Check if the NRVO candidate was not globalized in OpenMP mode.
+  if (getLangOpts().ElideConstructors && S.getNRVOCandidate() &&
+  S.getNR

[PATCH] D80933: [clang-format] [PR46157] Wrong spacing of negative literals with use of operator

2020-06-03 Thread Marek Kurdej via Phabricator via cfe-commits
curdeius accepted this revision.
curdeius added a comment.
This revision is now accepted and ready to land.

LGTM.
Keep in mind I'm not the code owner, I don't know if another approval is 
required.


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

https://reviews.llvm.org/D80933



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


[PATCH] D80947: Add to the Coding Standard our that single-line bodies omit braces

2020-06-03 Thread Erich Keane via Phabricator via cfe-commits
erichkeane updated this revision to Diff 268175.
erichkeane added a comment.

Apply @hubert.reinterpretcast s spelling.

I'd also like to re-enforce, the purpose of this patch is simply to write down 
the rule that we've been enforcing for years, I don't think we should get novel 
with the rules/change how it has been enforced.  That seems like it would 
require an RFC/llvm-dev discussion instead.


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

https://reviews.llvm.org/D80947

Files:
  llvm/docs/CodingStandards.rst

Index: llvm/docs/CodingStandards.rst
===
--- llvm/docs/CodingStandards.rst
+++ llvm/docs/CodingStandards.rst
@@ -669,15 +669,15 @@
 .. code-block:: c++
 
   // Typically there's no reason to copy.
-  for (const auto &Val : Container) { observe(Val); }
-  for (auto &Val : Container) { Val.change(); }
+  for (const auto &Val : Container) observe(Val);
+  for (auto &Val : Container) Val.change();
 
   // Remove the reference if you really want a new copy.
   for (auto Val : Container) { Val.change(); saveSomewhere(Val); }
 
   // Copy pointers, but make it clear that they're pointers.
-  for (const auto *Ptr : Container) { observe(*Ptr); }
-  for (auto *Ptr : Container) { Ptr->change(); }
+  for (const auto *Ptr : Container) observe(*Ptr);
+  for (auto *Ptr : Container) Ptr->change();
 
 Beware of non-determinism due to ordering of pointers
 ^
@@ -884,7 +884,7 @@
 .. code-block:: c++
 
   Value *doSomething(Instruction *I) {
-// Terminators never need 'something' done to them because ... 
+// Terminators never need 'something' done to them because ...
 if (I->isTerminator())
   return 0;
 
@@ -896,7 +896,7 @@
 // This is really just here for example.
 if (!doOtherThing(I))
   return 0;
-
+
 ... some long code 
   }
 
@@ -1000,7 +1000,7 @@
   Type = Context.getsigjmp_bufType();
 else
   Type = Context.getjmp_bufType();
-
+
 if (Type.isNull()) {
   Error = Signed ? ASTContext::GE_Missing_sigjmp_buf :
ASTContext::GE_Missing_jmp_buf;
@@ -1010,7 +1010,7 @@
 
 The idea is to reduce indentation and the amount of code you have to keep track
 of when reading the code.
-  
+
 Turn Predicate Loops into Predicate Functions
 ^
 
@@ -1081,7 +1081,7 @@
 * **Variable names** should be nouns (as they represent state).  The name should
   be camel case, and start with an upper case letter (e.g. ``Leader`` or
   ``Boats``).
-  
+
 * **Function names** should be verb phrases (as they represent actions), and
   command-like function should be imperative.  The name should be camel case,
   and start with a lower case letter (e.g. ``openFile()`` or ``isFoo()``).
@@ -1091,7 +1091,7 @@
   discriminator for a union, or an indicator of a subclass.  When an enum is
   used for something like this, it should have a ``Kind`` suffix
   (e.g. ``ValueKind``).
-  
+
 * **Enumerators** (e.g. ``enum { Foo, Bar }``) and **public member variables**
   should start with an upper-case letter, just like types.  Unless the
   enumerators are defined in their own small namespace or inside a class,
@@ -1107,7 +1107,7 @@
 MaxSize = 42,
 Density = 12
   };
-  
+
 As an exception, classes that mimic STL classes can have member names in STL's
 style of lower-case words separated by underscores (e.g. ``begin()``,
 ``push_back()``, and ``empty()``). Classes that provide multiple
@@ -1360,7 +1360,7 @@
 The use of ``#include `` in library files is hereby **forbidden**,
 because many common implementations transparently inject a `static constructor`_
 into every translation unit that includes it.
-  
+
 Note that using the other stream headers ( for example) is not
 problematic in this regard --- just . However, ``raw_ostream``
 provides various APIs that are better performing for almost every use than
@@ -1492,7 +1492,7 @@
   public:
 explicit Grokable() { ... }
 virtual ~Grokable() = 0;
-  
+
 ...
 
   };
@@ -1541,8 +1541,8 @@
   };
   } // end anonymous namespace
 
-  static void runHelper() { 
-... 
+  static void runHelper() {
+...
   }
 
   bool StringSort::operator<(const char *RHS) const {
@@ -1570,6 +1570,62 @@
 contrast, when the function is marked static, you don't need to cross-reference
 faraway places in the file to tell that the function is local.
 
+Don't Use Braces on Simple Single-Statement Bodies of if/else/loop Statements
+^
+
+When writing the body of an `if`, `else`, or loop statement, omit the braces to avoid
+unnecessary and otherwise meaningless code. However, braces should be used
+in cases where it significantly improves readability, such as when the single
+statement is accompanied by a comment that loses its meaning if hoist

[PATCH] D80366: [Analyzer] Add `getReturnValueUnderConstruction()` to `CallEvent`

2020-06-03 Thread Balogh , Ádám via Phabricator via cfe-commits
baloghadamsoftware updated this revision to Diff 268176.
baloghadamsoftware marked an inline comment as done.
baloghadamsoftware added a comment.

Updated according to the comments.


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

https://reviews.llvm.org/D80366

Files:
  clang/include/clang/Analysis/AnalysisDeclContext.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
  clang/lib/StaticAnalyzer/Core/CallEvent.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
  clang/unittests/StaticAnalyzer/CMakeLists.txt
  clang/unittests/StaticAnalyzer/TestReturnValueUnderConstruction.cpp

Index: clang/unittests/StaticAnalyzer/TestReturnValueUnderConstruction.cpp
===
--- /dev/null
+++ clang/unittests/StaticAnalyzer/TestReturnValueUnderConstruction.cpp
@@ -0,0 +1,75 @@
+//===- unittests/StaticAnalyzer/TestReturnValueUnderConstruction.cpp --===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "CheckerRegistration.h"
+#include "clang/StaticAnalyzer/Core/Checker.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
+#include "clang/StaticAnalyzer/Frontend/AnalysisConsumer.h"
+#include "clang/StaticAnalyzer/Frontend/CheckerRegistry.h"
+#include "clang/Tooling/Tooling.h"
+#include "gtest/gtest.h"
+
+namespace clang {
+namespace ento {
+namespace {
+
+class TestReturnValueUnderConstructionChecker
+  : public Checker {
+public:
+  void checkPostCall(const CallEvent &Call, CheckerContext &C) const {
+// We are checking the invocation of `returnC` which returns an object
+// by value.
+const IdentifierInfo *ID = Call.getCalleeIdentifier();
+if (ID->getName() != "returnC")
+  return;
+
+// Since `returnC` returns an object by value, the invocation results
+// in an object of type `C` constructed into variable `c`. Thus the
+// return value of `CallEvent::getReturnValueUnderConstruction()` must
+// be non-empty and has to be a `MemRegion`.
+Optional RetVal = Call.getReturnValueUnderConstruction();
+ASSERT_TRUE(RetVal);
+ASSERT_TRUE(RetVal->getAsRegion());
+  }
+};
+
+void addTestReturnValueUnderConstructionChecker(
+AnalysisASTConsumer &AnalysisConsumer, AnalyzerOptions &AnOpts) {
+  AnOpts.CheckersAndPackages =
+{{"test.TestReturnValueUnderConstruction", true}};
+  AnalysisConsumer.AddCheckerRegistrationFn([](CheckerRegistry &Registry) {
+  Registry.addChecker(
+  "test.TestReturnValueUnderConstruction", "", "");
+});
+}
+
+TEST(TestReturnValueUnderConstructionChecker,
+ ReturnValueUnderConstructionChecker) {
+  EXPECT_TRUE(runCheckerOnCode(
+  R"(class C {
+ public:
+   C(int nn): n(nn) {}
+   virtual ~C() {}
+ private:
+   int n;
+ };
+
+ C returnC(int m) {
+   C c(m);
+   return c;
+ }
+
+ void foo() {
+   C c = returnC(1); 
+ })"));
+}
+
+} // namespace
+} // namespace ento
+} // namespace clang
Index: clang/unittests/StaticAnalyzer/CMakeLists.txt
===
--- clang/unittests/StaticAnalyzer/CMakeLists.txt
+++ clang/unittests/StaticAnalyzer/CMakeLists.txt
@@ -7,10 +7,11 @@
   AnalyzerOptionsTest.cpp
   CallDescriptionTest.cpp
   CallEventTest.cpp
-  StoreTest.cpp
+  RangeSetTest.cpp
   RegisterCustomCheckersTest.cpp
+  StoreTest.cpp 
   SymbolReaperTest.cpp
-  RangeSetTest.cpp
+  TestReturnValueUnderConstruction.cpp
   )
 
 clang_target_link_libraries(StaticAnalysisTests
Index: clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
===
--- clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
+++ clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
@@ -109,15 +109,14 @@
   return LValue;
 }
 
-std::pair ExprEngine::handleConstructionContext(
+SVal ExprEngine::computeObjectUnderConstruction(
 const Expr *E, ProgramStateRef State, const LocationContext *LCtx,
 const ConstructionContext *CC, EvalCallOptions &CallOpts) {
   SValBuilder &SVB = getSValBuilder();
   MemRegionManager &MRMgr = SVB.getRegionManager();
   ASTContext &ACtx = SVB.getContext();
 
-  // See if we're constructing an existing region by looking at the
-  // current construction context.
+  // Compute the target region by exploring the construction context.
   if (CC) {
 switch (CC->getKind()

  1   2   3   >