Re: r373407 - Emit TypeNodes.def with tblgen.

2019-10-01 Thread John McCall via cfe-commits

On 1 Oct 2019, at 21:31, Nico Weber wrote:
I think that'd be nice; I believe I renamed one .def output with the 
same

history for the same reason a while ago.


r373425

John.



On Tue, Oct 1, 2019 at 9:25 PM John McCall  wrote:


On 1 Oct 2019, at 21:20, Nico Weber wrote:
All other tablegen outputs are called .inc instead of .def. Any 
reason

this
one's different?


This was an existing file; it’s just generated now instead of 
written
in source.  I was deliberately not changing anything about the 
existing

use sites.  That said, I could certainly go rename it as a follow-up
just to re-establish that consistent naming convention.

John.



On Tue, Oct 1, 2019 at 7:10 PM John McCall via cfe-commits <
cfe-commits@lists.llvm.org> wrote:


Author: rjmccall
Date: Tue Oct  1 16:13:03 2019
New Revision: 373407

URL: http://llvm.org/viewvc/llvm-project?rev=373407&view=rev
Log:
Emit TypeNodes.def with tblgen.

The primary goal here is to make the type node hierarchy available 
to

other tblgen backends, although it should also make it easier to
generate
more selective x-macros in the future.

Because tblgen doesn't seem to allow backends to preserve the 
source

order of defs, this is not NFC because it significantly re-orders
IDs.
I've fixed the one (fortunately obvious) place where we relied on
the old order.  Unfortunately, I wasn't able to share code with the
existing AST-node x-macro generators because the x-macro schema we
use
for types is different in a number of ways.  The main loss is that
subclasses aren't ordered together, which doesn't seem important 
for

types because the hierarchy is generally very shallow with little
clustering.

Added:
cfe/trunk/include/clang/Basic/TypeNodes.td
cfe/trunk/utils/TableGen/ClangTypeNodesEmitter.cpp
Removed:
cfe/trunk/include/clang/AST/TypeNodes.def
Modified:
cfe/trunk/include/clang/AST/CMakeLists.txt
cfe/trunk/include/clang/AST/Type.h
cfe/trunk/utils/TableGen/CMakeLists.txt
cfe/trunk/utils/TableGen/TableGen.cpp
cfe/trunk/utils/TableGen/TableGenBackends.h

Modified: cfe/trunk/include/clang/AST/CMakeLists.txt
URL:


http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/CMakeLists.txt?rev=373407&r1=373406&r2=373407&view=diff




==

--- cfe/trunk/include/clang/AST/CMakeLists.txt (original)
+++ cfe/trunk/include/clang/AST/CMakeLists.txt Tue Oct  1 16:13:03
2019
@@ -31,6 +31,10 @@ clang_tablegen(DeclNodes.inc -gen-clang-
   SOURCE ../Basic/DeclNodes.td
   TARGET ClangDeclNodes)

+clang_tablegen(TypeNodes.def -gen-clang-type-nodes
+  SOURCE ../Basic/TypeNodes.td
+  TARGET ClangTypeNodes)
+
 clang_tablegen(CommentNodes.inc -gen-clang-comment-nodes
   SOURCE ../Basic/CommentNodes.td
   TARGET ClangCommentNodes)

Modified: cfe/trunk/include/clang/AST/Type.h
URL:


http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=373407&r1=373406&r2=373407&view=diff




==

--- cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/trunk/include/clang/AST/Type.h Tue Oct  1 16:13:03 2019
@@ -1437,10 +1437,9 @@ class alignas(8) Type : public ExtQualsT
 public:
   enum TypeClass {
 #define TYPE(Class, Base) Class,
-#define LAST_TYPE(Class) TypeLast = Class,
+#define LAST_TYPE(Class) TypeLast = Class
 #define ABSTRACT_TYPE(Class, Base)
 #include "clang/AST/TypeNodes.def"
-TagFirst = Record, TagLast = Enum
   };

 private:
@@ -4436,7 +4435,7 @@ public:
   bool isBeingDefined() const;

   static bool classof(const Type *T) {
-return T->getTypeClass() >= TagFirst && T->getTypeClass() <=
TagLast;
+return T->getTypeClass() == Enum || T->getTypeClass() == 
Record;

   }
 };


Removed: cfe/trunk/include/clang/AST/TypeNodes.def
URL:


http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/TypeNodes.def?rev=373406&view=auto




==

--- cfe/trunk/include/clang/AST/TypeNodes.def (original)
+++ cfe/trunk/include/clang/AST/TypeNodes.def (removed)
@@ -1,135 +0,0 @@
-//===-- TypeNodes.def - Metadata about Type AST nodes 
---*-

C++
-*-===//
-//
-// 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
-//



-//===--===//

-//
-//  This file defines the AST type info database. Each type node 
is
-//  enumerated by providing its name (e.g., "Builtin" or "Enum") 
and

-//  base class (e.g., "Type" or "TagType"). Depending on where in
the
-//  abstract syntax tree the type will show up, the enumeration 
uses

-//  one of five different macros:
-//
-//TYPE(Class, Base) - A type that can show up anywhere in the
AST,
-//and might be dependent, canonical, or non-canonical. All

r373425 - Rename TypeNodes.def to TypeNodes.inc for consistency across all

2019-10-01 Thread John McCall via cfe-commits
Author: rjmccall
Date: Tue Oct  1 23:35:23 2019
New Revision: 373425

URL: http://llvm.org/viewvc/llvm-project?rev=373425&view=rev
Log:
Rename TypeNodes.def to TypeNodes.inc for consistency across all
our autogenerated files.  NFC.

As requested by Nico Weber.

Modified:
cfe/trunk/include/clang/AST/ASTFwd.h
cfe/trunk/include/clang/AST/ASTTypeTraits.h
cfe/trunk/include/clang/AST/CMakeLists.txt
cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
cfe/trunk/include/clang/AST/Type.h
cfe/trunk/include/clang/AST/TypeLoc.h
cfe/trunk/include/clang/AST/TypeLocNodes.def
cfe/trunk/include/clang/AST/TypeVisitor.h
cfe/trunk/lib/AST/ASTContext.cpp
cfe/trunk/lib/AST/ASTDiagnostic.cpp
cfe/trunk/lib/AST/ASTTypeTraits.cpp
cfe/trunk/lib/AST/ExprConstant.cpp
cfe/trunk/lib/AST/ItaniumMangle.cpp
cfe/trunk/lib/AST/MicrosoftMangle.cpp
cfe/trunk/lib/AST/Type.cpp
cfe/trunk/lib/AST/TypePrinter.cpp
cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
cfe/trunk/lib/CodeGen/CodeGenTypes.cpp
cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/lib/Sema/SemaLookup.cpp
cfe/trunk/lib/Sema/SemaTemplate.cpp
cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp
cfe/trunk/lib/Serialization/ASTWriter.cpp

Modified: cfe/trunk/include/clang/AST/ASTFwd.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTFwd.h?rev=373425&r1=373424&r2=373425&view=diff
==
--- cfe/trunk/include/clang/AST/ASTFwd.h (original)
+++ cfe/trunk/include/clang/AST/ASTFwd.h Tue Oct  1 23:35:23 2019
@@ -24,7 +24,7 @@ class Stmt;
 #include "clang/AST/StmtNodes.inc"
 class Type;
 #define TYPE(DERIVED, BASE) class DERIVED##Type;
-#include "clang/AST/TypeNodes.def"
+#include "clang/AST/TypeNodes.inc"
 class CXXCtorInitializer;
 
 } // end namespace clang

Modified: cfe/trunk/include/clang/AST/ASTTypeTraits.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTTypeTraits.h?rev=373425&r1=373424&r2=373425&view=diff
==
--- cfe/trunk/include/clang/AST/ASTTypeTraits.h (original)
+++ cfe/trunk/include/clang/AST/ASTTypeTraits.h Tue Oct  1 23:35:23 2019
@@ -148,7 +148,7 @@ private:
 #include "clang/AST/StmtNodes.inc"
 NKI_Type,
 #define TYPE(DERIVED, BASE) NKI_##DERIVED##Type,
-#include "clang/AST/TypeNodes.def"
+#include "clang/AST/TypeNodes.inc"
 NKI_OMPClause,
 #define OPENMP_CLAUSE(TextualSpelling, Class) NKI_##Class,
 #include "clang/Basic/OpenMPKinds.def"
@@ -205,7 +205,7 @@ KIND_TO_KIND_ID(OMPClause)
 #define STMT(DERIVED, BASE) KIND_TO_KIND_ID(DERIVED)
 #include "clang/AST/StmtNodes.inc"
 #define TYPE(DERIVED, BASE) KIND_TO_KIND_ID(DERIVED##Type)
-#include "clang/AST/TypeNodes.def"
+#include "clang/AST/TypeNodes.inc"
 #define OPENMP_CLAUSE(TextualSpelling, Class) KIND_TO_KIND_ID(Class)
 #include "clang/Basic/OpenMPKinds.def"
 #undef KIND_TO_KIND_ID

Modified: cfe/trunk/include/clang/AST/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/CMakeLists.txt?rev=373425&r1=373424&r2=373425&view=diff
==
--- cfe/trunk/include/clang/AST/CMakeLists.txt (original)
+++ cfe/trunk/include/clang/AST/CMakeLists.txt Tue Oct  1 23:35:23 2019
@@ -31,7 +31,7 @@ clang_tablegen(DeclNodes.inc -gen-clang-
   SOURCE ../Basic/DeclNodes.td
   TARGET ClangDeclNodes)
 
-clang_tablegen(TypeNodes.def -gen-clang-type-nodes
+clang_tablegen(TypeNodes.inc -gen-clang-type-nodes
   SOURCE ../Basic/TypeNodes.td
   TARGET ClangTypeNodes)
 

Modified: cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/RecursiveASTVisitor.h?rev=373425&r1=373424&r2=373425&view=diff
==
--- cfe/trunk/include/clang/AST/RecursiveASTVisitor.h (original)
+++ cfe/trunk/include/clang/AST/RecursiveASTVisitor.h Tue Oct  1 23:35:23 2019
@@ -431,7 +431,7 @@ public:
 // Declare Traverse*() for all concrete Type classes.
 #define ABSTRACT_TYPE(CLASS, BASE)
 #define TYPE(CLASS, BASE) bool Traverse##CLASS##Type(CLASS##Type *T);
-#include "clang/AST/TypeNodes.def"
+#include "clang/AST/TypeNodes.inc"
   // The above header #undefs ABSTRACT_TYPE and TYPE upon exit.
 
   // Define WalkUpFrom*() and empty Visit*() for all Type classes.
@@ -444,7 +444,7 @@ public:
 return true;   
\
   }
\
   bool Visit##CLASS##Type(CLASS##Type *T) { return true; }
-#include "clang/AST/TypeNodes.def"
+#include "clang/AST/TypeNodes.inc"
 
 //  Methods on TypeLocs 
 // FIXME: this currently just calls the matching Type methods
@@ -460,7 +460,7 @@ 

[PATCH] D68055: Add -fgnuc-version= to control __GNUC__ and other GCC macros

2019-10-01 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay accepted this revision.
MaskRay added a comment.

This will make it much easier to test clang's compatibility with GCC, 
especially in projects that heavily use `__GNUC__` or its friends, e.g. glibc :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D68055



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


[PATCH] D68055: Add -fgnuc-version= to control __GNUC__ and other GCC macros

2019-10-01 Thread Jacob Lifshay via Phabricator via cfe-commits
programmerjake added a comment.

The `__GNUG__` macro is defined to be 4 rather than matching `__GNUC__`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D68055



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


[PATCH] D63978: Clang Interface Stubs merger plumbing for Driver

2019-10-01 Thread Saleem Abdulrasool via Phabricator via cfe-commits
compnerd accepted this revision.
compnerd added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/lib/Driver/Driver.cpp:3372
+  if (Phase == phases::IfsMerge) {
+assert(Phase == PL.back() && "merging must be final compilation 
step.");
+MergerInputs.push_back(Current);

plotfi wrote:
> compnerd wrote:
> > Does the interface merging have to be the last step?  I could see interface 
> > merging preceding linking just fine.
> For now I think that's the expedient thing to do. Do you want to change that?
Add a TODO perhaps?



Comment at: clang/lib/Driver/ToolChains/InterfaceStubs.h:14
+#include "clang/Driver/ToolChain.h"
+#include 
+

cishida wrote:
> is this used anywhere? 
Please remove the `using namespace` directive in the header.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63978



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


[PATCH] D68315: [libTooling] Add various Stencil combinators for expressions.

2019-10-01 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel created this revision.
ymandel added a reviewer: gribozavr.
Herald added a project: clang.

This revision adds three new Stencil combinators:

- `expression`, which idiomatically constructs the source for an expression, 
including wrapping the expression's source in parentheses if needed.
- `deref`, which constructs an idiomatic dereferencing expression.
- `addressOf`, which constructs an idiomatic address-taking expression.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D68315

Files:
  clang/include/clang/Tooling/Refactoring/Stencil.h
  clang/lib/Tooling/Refactoring/Stencil.cpp
  clang/unittests/Tooling/StencilTest.cpp

Index: clang/unittests/Tooling/StencilTest.cpp
===
--- clang/unittests/Tooling/StencilTest.cpp
+++ clang/unittests/Tooling/StencilTest.cpp
@@ -20,14 +20,19 @@
 using namespace ast_matchers;
 
 namespace {
+using ::llvm::Failed;
 using ::llvm::HasValue;
+using ::llvm::StringError;
 using ::testing::AllOf;
 using ::testing::Eq;
 using ::testing::HasSubstr;
 using MatchResult = MatchFinder::MatchResult;
 using stencil::access;
+using stencil::addressOf;
 using stencil::cat;
+using stencil::deref;
 using stencil::dPrint;
+using stencil::expression;
 using stencil::ifBound;
 using stencil::run;
 using stencil::text;
@@ -104,7 +109,7 @@
   ADD_FAILURE() << "Expected failure but succeeded: " << *ResultOrErr;
 } else {
   auto Err = llvm::handleErrors(ResultOrErr.takeError(),
-[&Matcher](const llvm::StringError &Err) {
+[&Matcher](const StringError &Err) {
   EXPECT_THAT(Err.getMessage(), Matcher);
 });
   if (Err) {
@@ -183,6 +188,15 @@
   EXPECT_THAT_EXPECTED(Stencil.eval(StmtMatch->Result), HasValue(Expected));
 }
 
+void testFailure(StringRef Id, StringRef Snippet, const Stencil &Stencil,
+ testing::Matcher MessageMatcher) {
+  auto StmtMatch = matchStmt(Snippet, expr().bind(Id));
+  ASSERT_TRUE(StmtMatch);
+  EXPECT_THAT_EXPECTED(Stencil.eval(StmtMatch->Result),
+   Failed(testing::Property(
+   &StringError::getMessage, MessageMatcher)));
+}
+
 TEST_F(StencilTest, SelectionOp) {
   StringRef Id = "id";
   testExpr(Id, "3;", cat(node(Id)), "3");
@@ -198,6 +212,56 @@
   testExpr(Id, "3;", cat(ifBound("other", text("5"), text("7"))), "7");
 }
 
+TEST_F(StencilTest, ExpressionOpNoParens) {
+  StringRef Id = "id";
+  testExpr(Id, "3;", cat(expression(Id)), "3");
+}
+
+// Don't parenthesize a parens expression.
+TEST_F(StencilTest, ExpressionOpNoParensParens) {
+  StringRef Id = "id";
+  testExpr(Id, "(3);", cat(expression(Id)), "(3)");
+}
+
+TEST_F(StencilTest, ExpressionOpBinaryOpParens) {
+  StringRef Id = "id";
+  testExpr(Id, "3+4;", cat(expression(Id)), "(3+4)");
+}
+
+// `expression` shares code with other ops, so we get sufficient coverage of the
+// error handling code with this test. If that changes in the future, more error
+// tests should be added.
+TEST_F(StencilTest, ExpressionOpUnbound) {
+  StringRef Id = "id";
+  testFailure(Id, "3;", cat(expression("ACACA")),
+  AllOf(HasSubstr("ACACA"), HasSubstr("not bound")));
+}
+
+TEST_F(StencilTest, DerefPointer) {
+  StringRef Id = "id";
+  testExpr(Id, "int *x; x;", cat(deref(Id)), "*x");
+}
+
+TEST_F(StencilTest, DerefBinOp) {
+  StringRef Id = "id";
+  testExpr(Id, "int *x; x + 1;", cat(deref(Id)), "*(x + 1)");
+}
+
+TEST_F(StencilTest, DerefAddressExpr) {
+  StringRef Id = "id";
+  testExpr(Id, "int x; &x;", cat(deref(Id)), "x");
+}
+
+TEST_F(StencilTest, AddressOfValue) {
+  StringRef Id = "id";
+  testExpr(Id, "int x; x;", cat(addressOf(Id)), "&x");
+}
+
+TEST_F(StencilTest, AddressOfDerefExpr) {
+  StringRef Id = "id";
+  testExpr(Id, "int *x; *x;", cat(addressOf(Id)), "x");
+}
+
 TEST_F(StencilTest, AccessOpValue) {
   StringRef Snippet = R"cc(
 S x;
Index: clang/lib/Tooling/Refactoring/Stencil.cpp
===
--- clang/lib/Tooling/Refactoring/Stencil.cpp
+++ clang/lib/Tooling/Refactoring/Stencil.cpp
@@ -24,6 +24,7 @@
 using namespace tooling;
 
 using ast_matchers::MatchFinder;
+using ast_type_traits::DynTypedNode;
 using llvm::errc;
 using llvm::Error;
 using llvm::Expected;
@@ -37,7 +38,7 @@
   return static_cast(P);
 }
 
-static llvm::Expected
+static llvm::Expected
 getNode(const ast_matchers::BoundNodes &Nodes, StringRef Id) {
   auto &NodesMap = Nodes.getMap();
   auto It = NodesMap.find(Id);
@@ -60,6 +61,19 @@
   std::string Id;
 };
 
+enum class NodeOperator {
+  Parens,
+  Deref,
+  Address,
+};
+
+// Generic container for stencil operations with a (single) node-id argument.
+struct OperationData {
+  OperationData(NodeOperator Op, std::string Id) : Op(Op), Id(std::move(Id)) {}
+  NodeOperator Op;
+  std::string Id;
+};
+
 // The fragment of co

[PATCH] D68300: [HIP] Add option -fno-link-builtin-bitcode to disable linking device lib

2019-10-01 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl updated this revision to Diff 222746.
yaxunl retitled this revision from "[HIP] Add option 
-fno-hip-link-builtin-bitcode to disable linking device lib" to "[HIP] Add 
option -fno-link-builtin-bitcode to disable linking device lib".
yaxunl added a comment.

change the option name


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

https://reviews.llvm.org/D68300

Files:
  include/clang/Driver/Options.td
  lib/Driver/ToolChains/HIP.cpp
  test/Driver/hip-no-device-libs.hip


Index: test/Driver/hip-no-device-libs.hip
===
--- /dev/null
+++ test/Driver/hip-no-device-libs.hip
@@ -0,0 +1,11 @@
+// REQUIRES: clang-driver
+// REQUIRES: x86-registered-target
+// REQUIRES: amdgpu-registered-target
+
+// RUN: %clang -### -fno-link-builtin-bitcode -target x86_64-linux-gnu \
+// RUN:   -x hip --cuda-gpu-arch=gfx900 \
+// RUN:   %S/Inputs/hip_multiple_inputs/b.hip \
+// RUN: 2>&1 | FileCheck %s
+
+// CHECK-NOT: "-mlink-builtin-bitcode"
+
Index: lib/Driver/ToolChains/HIP.cpp
===
--- lib/Driver/ToolChains/HIP.cpp
+++ lib/Driver/ToolChains/HIP.cpp
@@ -289,6 +289,10 @@
 CC1Args.append({"-fvisibility", "hidden"});
 CC1Args.push_back("-fapply-global-visibility-to-externs");
   }
+
+  if (!DriverArgs.hasFlag(options::OPT_flink_builtin_bitcode,
+  options::OPT_fno_link_builtin_bitcode, true))
+return;
   ArgStringList LibraryPaths;
 
   // Find in --hip-device-lib-path and HIP_LIBRARY_PATH.
Index: include/clang/Driver/Options.td
===
--- include/clang/Driver/Options.td
+++ include/clang/Driver/Options.td
@@ -602,6 +602,9 @@
 def fhip_new_launch_api : Flag<["-"], "fhip-new-launch-api">,
   Flags<[CC1Option]>, HelpText<"Use new kernel launching API for HIP.">;
 def fno_hip_new_launch_api : Flag<["-"], "fno-hip-new-launch-api">;
+def flink_builtin_bitcode : Flag<["-"], "flink-builtin-bitcode">,
+  Flags<[CC1Option]>, HelpText<"Link builtin bitcode for HIP device 
compilation.">;
+def fno_link_builtin_bitcode : Flag<["-"], "fno-link-builtin-bitcode">;
 def libomptarget_nvptx_path_EQ : Joined<["--"], "libomptarget-nvptx-path=">, 
Group,
   HelpText<"Path to libomptarget-nvptx libraries">;
 def dD : Flag<["-"], "dD">, Group, Flags<[CC1Option]>,


Index: test/Driver/hip-no-device-libs.hip
===
--- /dev/null
+++ test/Driver/hip-no-device-libs.hip
@@ -0,0 +1,11 @@
+// REQUIRES: clang-driver
+// REQUIRES: x86-registered-target
+// REQUIRES: amdgpu-registered-target
+
+// RUN: %clang -### -fno-link-builtin-bitcode -target x86_64-linux-gnu \
+// RUN:   -x hip --cuda-gpu-arch=gfx900 \
+// RUN:   %S/Inputs/hip_multiple_inputs/b.hip \
+// RUN: 2>&1 | FileCheck %s
+
+// CHECK-NOT: "-mlink-builtin-bitcode"
+
Index: lib/Driver/ToolChains/HIP.cpp
===
--- lib/Driver/ToolChains/HIP.cpp
+++ lib/Driver/ToolChains/HIP.cpp
@@ -289,6 +289,10 @@
 CC1Args.append({"-fvisibility", "hidden"});
 CC1Args.push_back("-fapply-global-visibility-to-externs");
   }
+
+  if (!DriverArgs.hasFlag(options::OPT_flink_builtin_bitcode,
+  options::OPT_fno_link_builtin_bitcode, true))
+return;
   ArgStringList LibraryPaths;
 
   // Find in --hip-device-lib-path and HIP_LIBRARY_PATH.
Index: include/clang/Driver/Options.td
===
--- include/clang/Driver/Options.td
+++ include/clang/Driver/Options.td
@@ -602,6 +602,9 @@
 def fhip_new_launch_api : Flag<["-"], "fhip-new-launch-api">,
   Flags<[CC1Option]>, HelpText<"Use new kernel launching API for HIP.">;
 def fno_hip_new_launch_api : Flag<["-"], "fno-hip-new-launch-api">;
+def flink_builtin_bitcode : Flag<["-"], "flink-builtin-bitcode">,
+  Flags<[CC1Option]>, HelpText<"Link builtin bitcode for HIP device compilation.">;
+def fno_link_builtin_bitcode : Flag<["-"], "fno-link-builtin-bitcode">;
 def libomptarget_nvptx_path_EQ : Joined<["--"], "libomptarget-nvptx-path=">, Group,
   HelpText<"Path to libomptarget-nvptx libraries">;
 def dD : Flag<["-"], "dD">, Group, Flags<[CC1Option]>,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r373421 - Revert r368237 - Update fix-it hints for std::move warnings.

2019-10-01 Thread Richard Trieu via cfe-commits
Author: rtrieu
Date: Tue Oct  1 19:32:15 2019
New Revision: 373421

URL: http://llvm.org/viewvc/llvm-project?rev=373421&view=rev
Log:
Revert r368237 - Update fix-it hints for std::move warnings.

r368237 attempted to improve fix-its for move warnings, but introduced some
regressions to -Wpessimizing-move.  Revert that change and add the missing
test cases to the pessimizing move test to prevent future regressions.

Modified:
cfe/trunk/lib/Sema/SemaInit.cpp
cfe/trunk/test/SemaCXX/warn-pessmizing-move.cpp
cfe/trunk/test/SemaCXX/warn-redundant-move.cpp

Modified: cfe/trunk/lib/Sema/SemaInit.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=373421&r1=373420&r2=373421&view=diff
==
--- cfe/trunk/lib/Sema/SemaInit.cpp (original)
+++ cfe/trunk/lib/Sema/SemaInit.cpp Tue Oct  1 19:32:15 2019
@@ -7580,34 +7580,27 @@ static void CheckMoveOnConstruction(Sema
   if (!DestType->isRecordType())
 return;
 
-  const CXXConstructExpr *CCE =
-  dyn_cast(InitExpr->IgnoreParens());
-  if (!CCE || CCE->getNumArgs() != 1)
-return;
+  unsigned DiagID = 0;
+  if (IsReturnStmt) {
+const CXXConstructExpr *CCE =
+dyn_cast(InitExpr->IgnoreParens());
+if (!CCE || CCE->getNumArgs() != 1)
+  return;
 
-  if (!CCE->getConstructor()->isCopyOrMoveConstructor())
-return;
+if (!CCE->getConstructor()->isCopyOrMoveConstructor())
+  return;
 
-  InitExpr = CCE->getArg(0)->IgnoreImpCasts();
+InitExpr = CCE->getArg(0)->IgnoreImpCasts();
+  }
 
   // Find the std::move call and get the argument.
   const CallExpr *CE = dyn_cast(InitExpr->IgnoreParens());
   if (!CE || !CE->isCallToStdMove())
 return;
 
-  const Expr *Arg = CE->getArg(0);
-
-  unsigned DiagID = 0;
-
-  if (!IsReturnStmt && !isa(Arg))
-return;
+  const Expr *Arg = CE->getArg(0)->IgnoreImplicit();
 
-  if (isa(Arg)) {
-DiagID = diag::warn_pessimizing_move_on_initialization;
-const Expr *ArgStripped = Arg->IgnoreImplicit()->IgnoreParens();
-if (!ArgStripped->isRValue() || !ArgStripped->getType()->isRecordType())
-  return;
-  } else { // IsReturnStmt
+  if (IsReturnStmt) {
 const DeclRefExpr *DRE = dyn_cast(Arg->IgnoreParenImpCasts());
 if (!DRE || DRE->refersToEnclosingVariableOrCapture())
   return;
@@ -7634,18 +7627,24 @@ static void CheckMoveOnConstruction(Sema
   DiagID = diag::warn_redundant_move_on_return;
 else
   DiagID = diag::warn_pessimizing_move_on_return;
+  } else {
+DiagID = diag::warn_pessimizing_move_on_initialization;
+const Expr *ArgStripped = Arg->IgnoreImplicit()->IgnoreParens();
+if (!ArgStripped->isRValue() || !ArgStripped->getType()->isRecordType())
+  return;
   }
 
   S.Diag(CE->getBeginLoc(), DiagID);
 
   // Get all the locations for a fix-it.  Don't emit the fix-it if any location
   // is within a macro.
-  SourceLocation BeginLoc = CCE->getBeginLoc();
-  if (BeginLoc.isMacroID())
+  SourceLocation CallBegin = CE->getCallee()->getBeginLoc();
+  if (CallBegin.isMacroID())
 return;
   SourceLocation RParen = CE->getRParenLoc();
   if (RParen.isMacroID())
 return;
+  SourceLocation LParen;
   SourceLocation ArgLoc = Arg->getBeginLoc();
 
   // Special testing for the argument location.  Since the fix-it needs the
@@ -7656,16 +7655,14 @@ static void CheckMoveOnConstruction(Sema
 ArgLoc = 
S.getSourceManager().getImmediateExpansionRange(ArgLoc).getBegin();
   }
 
-  SourceLocation LParen = ArgLoc.getLocWithOffset(-1);
   if (LParen.isMacroID())
 return;
-  SourceLocation EndLoc = CCE->getEndLoc();
-  if (EndLoc.isMacroID())
-return;
+
+  LParen = ArgLoc.getLocWithOffset(-1);
 
   S.Diag(CE->getBeginLoc(), diag::note_remove_move)
-  << FixItHint::CreateRemoval(SourceRange(BeginLoc, LParen))
-  << FixItHint::CreateRemoval(SourceRange(RParen, EndLoc));
+  << FixItHint::CreateRemoval(SourceRange(CallBegin, LParen))
+  << FixItHint::CreateRemoval(SourceRange(RParen, RParen));
 }
 
 static void CheckForNullPointerDereference(Sema &S, const Expr *E) {

Modified: cfe/trunk/test/SemaCXX/warn-pessmizing-move.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-pessmizing-move.cpp?rev=373421&r1=373420&r2=373421&view=diff
==
--- cfe/trunk/test/SemaCXX/warn-pessmizing-move.cpp (original)
+++ cfe/trunk/test/SemaCXX/warn-pessmizing-move.cpp Tue Oct  1 19:32:15 2019
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -Wpessimizing-move -std=c++11 -verify %s
+// RUN: %clang_cc1 -fsyntax-only -Wpessimizing-move -std=c++11 -verify %s 
-DUSER_DEFINED
 // RUN: %clang_cc1 -fsyntax-only -Wpessimizing-move -std=c++11 
-fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
 
 // definitions for std::move
@@ -12,7 +13,15 @@ template  typename remove_refer
 }
 }
 
-struct A {};
+struct A {
+#ifdef USER_DEFINED
+  A() {}
+  A(const A

Re: r372681 - Support for DWARF-5 C++ language tags.

2019-10-01 Thread David Blaikie via cfe-commits
This broke gnu_pubnames and other forms of DWARF index of C++ code - fixed
in r373420 (feel free to post-comimt review, etc, of course)

On Mon, Sep 23, 2019 at 5:36 PM Adrian Prantl via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: adrian
> Date: Mon Sep 23 17:38:49 2019
> New Revision: 372681
>
> URL: http://llvm.org/viewvc/llvm-project?rev=372681&view=rev
> Log:
> Support for DWARF-5 C++ language tags.
>
> This patch provides support for DW_LANG_C_plus_plus_11,
> DW_LANG_C_plus_plus_14 tags in the Clang C++ frontend.
>
> Patch by Sourabh Singh Tomar!
> Differential Revision: https://reviews.llvm.org/D67613
>
> Reapplies r372663 after adapting a failing test in the LLDB testsuite.
>
> Modified:
> cfe/trunk/include/clang/AST/DeclCXX.h
> cfe/trunk/lib/AST/DeclPrinter.cpp
> cfe/trunk/lib/AST/JSONNodeDumper.cpp
> cfe/trunk/lib/AST/TextNodeDumper.cpp
> cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
> cfe/trunk/lib/CodeGen/CodeGenModule.cpp
> cfe/trunk/lib/Sema/SemaDeclCXX.cpp
> cfe/trunk/lib/Sema/SemaModule.cpp
> cfe/trunk/test/Modules/ModuleDebugInfo.cpp
>
> Modified: cfe/trunk/include/clang/AST/DeclCXX.h
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclCXX.h?rev=372681&r1=372680&r2=372681&view=diff
>
> ==
> --- cfe/trunk/include/clang/AST/DeclCXX.h (original)
> +++ cfe/trunk/include/clang/AST/DeclCXX.h Mon Sep 23 17:38:49 2019
> @@ -42,6 +42,7 @@
>  #include "llvm/ADT/PointerUnion.h"
>  #include "llvm/ADT/STLExtras.h"
>  #include "llvm/ADT/iterator_range.h"
> +#include "llvm/BinaryFormat/Dwarf.h"
>  #include "llvm/Support/Casting.h"
>  #include "llvm/Support/Compiler.h"
>  #include "llvm/Support/PointerLikeTypeTraits.h"
> @@ -2941,8 +2942,10 @@ public:
>/// ensure a stable ABI for this, we choose the DW_LANG_ encodings
>/// from the dwarf standard.
>enum LanguageIDs {
> -lang_c = /* DW_LANG_C */ 0x0002,
> -lang_cxx = /* DW_LANG_C_plus_plus */ 0x0004
> +lang_c = llvm::dwarf::DW_LANG_C,
> +lang_cxx = llvm::dwarf::DW_LANG_C_plus_plus,
> +lang_cxx_11 = llvm::dwarf::DW_LANG_C_plus_plus_11,
> +lang_cxx_14 = llvm::dwarf::DW_LANG_C_plus_plus_14
>};
>
>  private:
>
> Modified: cfe/trunk/lib/AST/DeclPrinter.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclPrinter.cpp?rev=372681&r1=372680&r2=372681&view=diff
>
> ==
> --- cfe/trunk/lib/AST/DeclPrinter.cpp (original)
> +++ cfe/trunk/lib/AST/DeclPrinter.cpp Mon Sep 23 17:38:49 2019
> @@ -1001,12 +1001,19 @@ void DeclPrinter::VisitCXXRecordDecl(CXX
>
>  void DeclPrinter::VisitLinkageSpecDecl(LinkageSpecDecl *D) {
>const char *l;
> -  if (D->getLanguage() == LinkageSpecDecl::lang_c)
> +  switch (D->getLanguage()) {
> +  case LinkageSpecDecl::lang_c:
>  l = "C";
> -  else {
> -assert(D->getLanguage() == LinkageSpecDecl::lang_cxx &&
> -   "unknown language in linkage specification");
> +break;
> +  case LinkageSpecDecl::lang_cxx_14:
> +l = "C++14";
> +break;
> +  case LinkageSpecDecl::lang_cxx_11:
> +l = "C++11";
> +break;
> +  case LinkageSpecDecl::lang_cxx:
>  l = "C++";
> +break;
>}
>
>Out << "extern \"" << l << "\" ";
>
> Modified: cfe/trunk/lib/AST/JSONNodeDumper.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/JSONNodeDumper.cpp?rev=372681&r1=372680&r2=372681&view=diff
>
> ==
> --- cfe/trunk/lib/AST/JSONNodeDumper.cpp (original)
> +++ cfe/trunk/lib/AST/JSONNodeDumper.cpp Mon Sep 23 17:38:49 2019
> @@ -850,6 +850,12 @@ void JSONNodeDumper::VisitLinkageSpecDec
>switch (LSD->getLanguage()) {
>case LinkageSpecDecl::lang_c: Lang = "C"; break;
>case LinkageSpecDecl::lang_cxx: Lang = "C++"; break;
> +  case LinkageSpecDecl::lang_cxx_11:
> +Lang = "C++11";
> +break;
> +  case LinkageSpecDecl::lang_cxx_14:
> +Lang = "C++14";
> +break;
>}
>JOS.attribute("language", Lang);
>attributeOnlyIfTrue("hasBraces", LSD->hasBraces());
>
> Modified: cfe/trunk/lib/AST/TextNodeDumper.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/TextNodeDumper.cpp?rev=372681&r1=372680&r2=372681&view=diff
>
> ==
> --- cfe/trunk/lib/AST/TextNodeDumper.cpp (original)
> +++ cfe/trunk/lib/AST/TextNodeDumper.cpp Mon Sep 23 17:38:49 2019
> @@ -1766,6 +1766,12 @@ void TextNodeDumper::VisitLinkageSpecDec
>case LinkageSpecDecl::lang_cxx:
>  OS << " C++";
>  break;
> +  case LinkageSpecDecl::lang_cxx_11:
> +OS << " C++11";
> +break;
> +  case LinkageSpecDecl::lang_cxx_14:
> +OS << " C++14";
> +break;
>}
>  }
>
>
> Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CG

Re: r373407 - Emit TypeNodes.def with tblgen.

2019-10-01 Thread Nico Weber via cfe-commits
I think that'd be nice; I believe I renamed one .def output with the same
history for the same reason a while ago.

On Tue, Oct 1, 2019 at 9:25 PM John McCall  wrote:

> On 1 Oct 2019, at 21:20, Nico Weber wrote:
> > All other tablegen outputs are called .inc instead of .def. Any reason
> > this
> > one's different?
>
> This was an existing file; it’s just generated now instead of written
> in source.  I was deliberately not changing anything about the existing
> use sites.  That said, I could certainly go rename it as a follow-up
> just to re-establish that consistent naming convention.
>
> John.
>
> >
> > On Tue, Oct 1, 2019 at 7:10 PM John McCall via cfe-commits <
> > cfe-commits@lists.llvm.org> wrote:
> >
> >> Author: rjmccall
> >> Date: Tue Oct  1 16:13:03 2019
> >> New Revision: 373407
> >>
> >> URL: http://llvm.org/viewvc/llvm-project?rev=373407&view=rev
> >> Log:
> >> Emit TypeNodes.def with tblgen.
> >>
> >> The primary goal here is to make the type node hierarchy available to
> >> other tblgen backends, although it should also make it easier to
> >> generate
> >> more selective x-macros in the future.
> >>
> >> Because tblgen doesn't seem to allow backends to preserve the source
> >> order of defs, this is not NFC because it significantly re-orders
> >> IDs.
> >> I've fixed the one (fortunately obvious) place where we relied on
> >> the old order.  Unfortunately, I wasn't able to share code with the
> >> existing AST-node x-macro generators because the x-macro schema we
> >> use
> >> for types is different in a number of ways.  The main loss is that
> >> subclasses aren't ordered together, which doesn't seem important for
> >> types because the hierarchy is generally very shallow with little
> >> clustering.
> >>
> >> Added:
> >> cfe/trunk/include/clang/Basic/TypeNodes.td
> >> cfe/trunk/utils/TableGen/ClangTypeNodesEmitter.cpp
> >> Removed:
> >> cfe/trunk/include/clang/AST/TypeNodes.def
> >> Modified:
> >> cfe/trunk/include/clang/AST/CMakeLists.txt
> >> cfe/trunk/include/clang/AST/Type.h
> >> cfe/trunk/utils/TableGen/CMakeLists.txt
> >> cfe/trunk/utils/TableGen/TableGen.cpp
> >> cfe/trunk/utils/TableGen/TableGenBackends.h
> >>
> >> Modified: cfe/trunk/include/clang/AST/CMakeLists.txt
> >> URL:
> >>
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/CMakeLists.txt?rev=373407&r1=373406&r2=373407&view=diff
> >>
> >>
> ==
> >> --- cfe/trunk/include/clang/AST/CMakeLists.txt (original)
> >> +++ cfe/trunk/include/clang/AST/CMakeLists.txt Tue Oct  1 16:13:03
> >> 2019
> >> @@ -31,6 +31,10 @@ clang_tablegen(DeclNodes.inc -gen-clang-
> >>SOURCE ../Basic/DeclNodes.td
> >>TARGET ClangDeclNodes)
> >>
> >> +clang_tablegen(TypeNodes.def -gen-clang-type-nodes
> >> +  SOURCE ../Basic/TypeNodes.td
> >> +  TARGET ClangTypeNodes)
> >> +
> >>  clang_tablegen(CommentNodes.inc -gen-clang-comment-nodes
> >>SOURCE ../Basic/CommentNodes.td
> >>TARGET ClangCommentNodes)
> >>
> >> Modified: cfe/trunk/include/clang/AST/Type.h
> >> URL:
> >>
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=373407&r1=373406&r2=373407&view=diff
> >>
> >>
> ==
> >> --- cfe/trunk/include/clang/AST/Type.h (original)
> >> +++ cfe/trunk/include/clang/AST/Type.h Tue Oct  1 16:13:03 2019
> >> @@ -1437,10 +1437,9 @@ class alignas(8) Type : public ExtQualsT
> >>  public:
> >>enum TypeClass {
> >>  #define TYPE(Class, Base) Class,
> >> -#define LAST_TYPE(Class) TypeLast = Class,
> >> +#define LAST_TYPE(Class) TypeLast = Class
> >>  #define ABSTRACT_TYPE(Class, Base)
> >>  #include "clang/AST/TypeNodes.def"
> >> -TagFirst = Record, TagLast = Enum
> >>};
> >>
> >>  private:
> >> @@ -4436,7 +4435,7 @@ public:
> >>bool isBeingDefined() const;
> >>
> >>static bool classof(const Type *T) {
> >> -return T->getTypeClass() >= TagFirst && T->getTypeClass() <=
> >> TagLast;
> >> +return T->getTypeClass() == Enum || T->getTypeClass() == Record;
> >>}
> >>  };
> >>
> >>
> >> Removed: cfe/trunk/include/clang/AST/TypeNodes.def
> >> URL:
> >>
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/TypeNodes.def?rev=373406&view=auto
> >>
> >>
> ==
> >> --- cfe/trunk/include/clang/AST/TypeNodes.def (original)
> >> +++ cfe/trunk/include/clang/AST/TypeNodes.def (removed)
> >> @@ -1,135 +0,0 @@
> >> -//===-- TypeNodes.def - Metadata about Type AST nodes ---*-
> >> C++
> >> -*-===//
> >> -//
> >> -// 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
> >> -//
> >>
> >>
> -//===--===//
>

Re: r373407 - Emit TypeNodes.def with tblgen.

2019-10-01 Thread John McCall via cfe-commits

On 1 Oct 2019, at 21:20, Nico Weber wrote:
All other tablegen outputs are called .inc instead of .def. Any reason 
this

one's different?


This was an existing file; it’s just generated now instead of written
in source.  I was deliberately not changing anything about the existing
use sites.  That said, I could certainly go rename it as a follow-up
just to re-establish that consistent naming convention.

John.



On Tue, Oct 1, 2019 at 7:10 PM John McCall via cfe-commits <
cfe-commits@lists.llvm.org> wrote:


Author: rjmccall
Date: Tue Oct  1 16:13:03 2019
New Revision: 373407

URL: http://llvm.org/viewvc/llvm-project?rev=373407&view=rev
Log:
Emit TypeNodes.def with tblgen.

The primary goal here is to make the type node hierarchy available to
other tblgen backends, although it should also make it easier to 
generate

more selective x-macros in the future.

Because tblgen doesn't seem to allow backends to preserve the source
order of defs, this is not NFC because it significantly re-orders 
IDs.

I've fixed the one (fortunately obvious) place where we relied on
the old order.  Unfortunately, I wasn't able to share code with the
existing AST-node x-macro generators because the x-macro schema we 
use

for types is different in a number of ways.  The main loss is that
subclasses aren't ordered together, which doesn't seem important for
types because the hierarchy is generally very shallow with little
clustering.

Added:
cfe/trunk/include/clang/Basic/TypeNodes.td
cfe/trunk/utils/TableGen/ClangTypeNodesEmitter.cpp
Removed:
cfe/trunk/include/clang/AST/TypeNodes.def
Modified:
cfe/trunk/include/clang/AST/CMakeLists.txt
cfe/trunk/include/clang/AST/Type.h
cfe/trunk/utils/TableGen/CMakeLists.txt
cfe/trunk/utils/TableGen/TableGen.cpp
cfe/trunk/utils/TableGen/TableGenBackends.h

Modified: cfe/trunk/include/clang/AST/CMakeLists.txt
URL:
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/CMakeLists.txt?rev=373407&r1=373406&r2=373407&view=diff

==
--- cfe/trunk/include/clang/AST/CMakeLists.txt (original)
+++ cfe/trunk/include/clang/AST/CMakeLists.txt Tue Oct  1 16:13:03 
2019

@@ -31,6 +31,10 @@ clang_tablegen(DeclNodes.inc -gen-clang-
   SOURCE ../Basic/DeclNodes.td
   TARGET ClangDeclNodes)

+clang_tablegen(TypeNodes.def -gen-clang-type-nodes
+  SOURCE ../Basic/TypeNodes.td
+  TARGET ClangTypeNodes)
+
 clang_tablegen(CommentNodes.inc -gen-clang-comment-nodes
   SOURCE ../Basic/CommentNodes.td
   TARGET ClangCommentNodes)

Modified: cfe/trunk/include/clang/AST/Type.h
URL:
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=373407&r1=373406&r2=373407&view=diff

==
--- cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/trunk/include/clang/AST/Type.h Tue Oct  1 16:13:03 2019
@@ -1437,10 +1437,9 @@ class alignas(8) Type : public ExtQualsT
 public:
   enum TypeClass {
 #define TYPE(Class, Base) Class,
-#define LAST_TYPE(Class) TypeLast = Class,
+#define LAST_TYPE(Class) TypeLast = Class
 #define ABSTRACT_TYPE(Class, Base)
 #include "clang/AST/TypeNodes.def"
-TagFirst = Record, TagLast = Enum
   };

 private:
@@ -4436,7 +4435,7 @@ public:
   bool isBeingDefined() const;

   static bool classof(const Type *T) {
-return T->getTypeClass() >= TagFirst && T->getTypeClass() <= 
TagLast;

+return T->getTypeClass() == Enum || T->getTypeClass() == Record;
   }
 };


Removed: cfe/trunk/include/clang/AST/TypeNodes.def
URL:
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/TypeNodes.def?rev=373406&view=auto

==
--- cfe/trunk/include/clang/AST/TypeNodes.def (original)
+++ cfe/trunk/include/clang/AST/TypeNodes.def (removed)
@@ -1,135 +0,0 @@
-//===-- TypeNodes.def - Metadata about Type AST nodes ---*- 
C++

-*-===//
-//
-// 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
-//

-//===--===//
-//
-//  This file defines the AST type info database. Each type node is
-//  enumerated by providing its name (e.g., "Builtin" or "Enum") and
-//  base class (e.g., "Type" or "TagType"). Depending on where in 
the

-//  abstract syntax tree the type will show up, the enumeration uses
-//  one of five different macros:
-//
-//TYPE(Class, Base) - A type that can show up anywhere in the 
AST,
-//and might be dependent, canonical, or non-canonical. All 
clients

-//will need to understand these types.
-//
-//ABSTRACT_TYPE(Class, Base) - An abstract class that shows up 
in

-//the type hierarchy but has no concrete instances.
-//
-//NON_CANONICAL_TYPE(Class, Base) - A type that can show up
-/

Re: r373407 - Emit TypeNodes.def with tblgen.

2019-10-01 Thread Nico Weber via cfe-commits
All other tablegen outputs are called .inc instead of .def. Any reason this
one's different?

On Tue, Oct 1, 2019 at 7:10 PM John McCall via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: rjmccall
> Date: Tue Oct  1 16:13:03 2019
> New Revision: 373407
>
> URL: http://llvm.org/viewvc/llvm-project?rev=373407&view=rev
> Log:
> Emit TypeNodes.def with tblgen.
>
> The primary goal here is to make the type node hierarchy available to
> other tblgen backends, although it should also make it easier to generate
> more selective x-macros in the future.
>
> Because tblgen doesn't seem to allow backends to preserve the source
> order of defs, this is not NFC because it significantly re-orders IDs.
> I've fixed the one (fortunately obvious) place where we relied on
> the old order.  Unfortunately, I wasn't able to share code with the
> existing AST-node x-macro generators because the x-macro schema we use
> for types is different in a number of ways.  The main loss is that
> subclasses aren't ordered together, which doesn't seem important for
> types because the hierarchy is generally very shallow with little
> clustering.
>
> Added:
> cfe/trunk/include/clang/Basic/TypeNodes.td
> cfe/trunk/utils/TableGen/ClangTypeNodesEmitter.cpp
> Removed:
> cfe/trunk/include/clang/AST/TypeNodes.def
> Modified:
> cfe/trunk/include/clang/AST/CMakeLists.txt
> cfe/trunk/include/clang/AST/Type.h
> cfe/trunk/utils/TableGen/CMakeLists.txt
> cfe/trunk/utils/TableGen/TableGen.cpp
> cfe/trunk/utils/TableGen/TableGenBackends.h
>
> Modified: cfe/trunk/include/clang/AST/CMakeLists.txt
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/CMakeLists.txt?rev=373407&r1=373406&r2=373407&view=diff
>
> ==
> --- cfe/trunk/include/clang/AST/CMakeLists.txt (original)
> +++ cfe/trunk/include/clang/AST/CMakeLists.txt Tue Oct  1 16:13:03 2019
> @@ -31,6 +31,10 @@ clang_tablegen(DeclNodes.inc -gen-clang-
>SOURCE ../Basic/DeclNodes.td
>TARGET ClangDeclNodes)
>
> +clang_tablegen(TypeNodes.def -gen-clang-type-nodes
> +  SOURCE ../Basic/TypeNodes.td
> +  TARGET ClangTypeNodes)
> +
>  clang_tablegen(CommentNodes.inc -gen-clang-comment-nodes
>SOURCE ../Basic/CommentNodes.td
>TARGET ClangCommentNodes)
>
> Modified: cfe/trunk/include/clang/AST/Type.h
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=373407&r1=373406&r2=373407&view=diff
>
> ==
> --- cfe/trunk/include/clang/AST/Type.h (original)
> +++ cfe/trunk/include/clang/AST/Type.h Tue Oct  1 16:13:03 2019
> @@ -1437,10 +1437,9 @@ class alignas(8) Type : public ExtQualsT
>  public:
>enum TypeClass {
>  #define TYPE(Class, Base) Class,
> -#define LAST_TYPE(Class) TypeLast = Class,
> +#define LAST_TYPE(Class) TypeLast = Class
>  #define ABSTRACT_TYPE(Class, Base)
>  #include "clang/AST/TypeNodes.def"
> -TagFirst = Record, TagLast = Enum
>};
>
>  private:
> @@ -4436,7 +4435,7 @@ public:
>bool isBeingDefined() const;
>
>static bool classof(const Type *T) {
> -return T->getTypeClass() >= TagFirst && T->getTypeClass() <= TagLast;
> +return T->getTypeClass() == Enum || T->getTypeClass() == Record;
>}
>  };
>
>
> Removed: cfe/trunk/include/clang/AST/TypeNodes.def
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/TypeNodes.def?rev=373406&view=auto
>
> ==
> --- cfe/trunk/include/clang/AST/TypeNodes.def (original)
> +++ cfe/trunk/include/clang/AST/TypeNodes.def (removed)
> @@ -1,135 +0,0 @@
> -//===-- TypeNodes.def - Metadata about Type AST nodes ---*- C++
> -*-===//
> -//
> -// 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
> -//
>
> -//===--===//
> -//
> -//  This file defines the AST type info database. Each type node is
> -//  enumerated by providing its name (e.g., "Builtin" or "Enum") and
> -//  base class (e.g., "Type" or "TagType"). Depending on where in the
> -//  abstract syntax tree the type will show up, the enumeration uses
> -//  one of five different macros:
> -//
> -//TYPE(Class, Base) - A type that can show up anywhere in the AST,
> -//and might be dependent, canonical, or non-canonical. All clients
> -//will need to understand these types.
> -//
> -//ABSTRACT_TYPE(Class, Base) - An abstract class that shows up in
> -//the type hierarchy but has no concrete instances.
> -//
> -//NON_CANONICAL_TYPE(Class, Base) - A type that can show up
> -//anywhere in the AST but will never be a part of a canonical
> -//type. Clients that only need to deal with canonical t

r373418 - Fix crash on constant-evaluation of pseudo-destruction of a pointer.

2019-10-01 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Tue Oct  1 18:13:57 2019
New Revision: 373418

URL: http://llvm.org/viewvc/llvm-project?rev=373418&view=rev
Log:
Fix crash on constant-evaluation of pseudo-destruction of a pointer.

We got confused and thought we might be pseudo-destroying the pointee
instead.

Modified:
cfe/trunk/lib/AST/ExprConstant.cpp
cfe/trunk/test/SemaCXX/constant-expression-cxx2a.cpp

Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=373418&r1=373417&r2=373418&view=diff
==
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Tue Oct  1 18:13:57 2019
@@ -3997,7 +3997,7 @@ static bool handleIncDec(EvalInfo &Info,
 /// Build an lvalue for the object argument of a member function call.
 static bool EvaluateObjectArgument(EvalInfo &Info, const Expr *Object,
LValue &This) {
-  if (Object->getType()->isPointerType())
+  if (Object->getType()->isPointerType() && Object->isRValue())
 return EvaluatePointer(Object, This, Info);
 
   if (Object->isGLValue())

Modified: cfe/trunk/test/SemaCXX/constant-expression-cxx2a.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/constant-expression-cxx2a.cpp?rev=373418&r1=373417&r2=373418&view=diff
==
--- cfe/trunk/test/SemaCXX/constant-expression-cxx2a.cpp (original)
+++ cfe/trunk/test/SemaCXX/constant-expression-cxx2a.cpp Tue Oct  1 18:13:57 
2019
@@ -1283,6 +1283,15 @@ namespace dtor_call {
 // FIXME: This diagnostic is wrong; the union has no active member now.
 as.b.~A(); // expected-note {{destruction of member 'b' of union with 
active member 'a'}}
   }
+
+  constexpr void destroy_pointer() {
+using T = int*;
+T p;
+// We used to think this was an -> member access because its left-hand side
+// is a pointer. Ensure we don't crash.
+p.~T();
+  }
+  static_assert((destroy_pointer(), true));
 }
 
 namespace temp_dtor {


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


r373416 - Remove TypeNodes.def from the modulemap.

2019-10-01 Thread John McCall via cfe-commits
Author: rjmccall
Date: Tue Oct  1 18:02:27 2019
New Revision: 373416

URL: http://llvm.org/viewvc/llvm-project?rev=373416&view=rev
Log:
Remove TypeNodes.def from the modulemap.

We currently just look for files named in the modulemap in its
associated source directory.  This means that we can't name
generated files, like TypeNodes.def now is, which means we can't
explicitly mark it as textual.  But fortunately that's okay
because (as I understand it) the most important purpose of naming
the header in the modulemap is to ensure that it's not treated as
public, and the search for public headers also only considers
files in the associated source directory.  This isn't an elegant
solution, since among other things it means that a build which
wrote the generated files directly into the source directory would
result in something that wouldn't build as a module, but that's
a problem for all our other generated files as well.

Modified:
cfe/trunk/include/clang/module.modulemap

Modified: cfe/trunk/include/clang/module.modulemap
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/module.modulemap?rev=373416&r1=373415&r2=373416&view=diff
==
--- cfe/trunk/include/clang/module.modulemap (original)
+++ cfe/trunk/include/clang/module.modulemap Tue Oct  1 18:02:27 2019
@@ -20,7 +20,6 @@ module Clang_AST {
   textual header "AST/BuiltinTypes.def"
   textual header "AST/OperationKinds.def"
   textual header "AST/TypeLocNodes.def"
-  textual header "AST/TypeNodes.def"
 
   module * { export * }
 }


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


[PATCH] D67010: [Modules] Move search paths from control block to unhashed control block

2019-10-01 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

This seems reasonable to me, but a test case would be nice.

A mode to validate that header path changes don't change anything would be nice 
(essentially: redo all the header searches with the new set of paths and new 
filesystem and make sure they find the same thing), but doesn't seem urgent. 
(Note that that would catch both the case where the changed header search paths 
affect behavior and also the case where new files have appeared on an existing 
header search path and should be found by the header lookup instead of the 
cached ones.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D67010



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


[PATCH] D67249: [Modules][PCH] Hash input files content

2019-10-01 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith accepted this revision.
rsmith 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/D67249/new/

https://reviews.llvm.org/D67249



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


r373410 - Fix unused variable warning. NFCI.

2019-10-01 Thread Michael Liao via cfe-commits
Author: hliao
Date: Tue Oct  1 17:22:45 2019
New Revision: 373410

URL: http://llvm.org/viewvc/llvm-project?rev=373410&view=rev
Log:
Fix unused variable warning. NFCI.

Modified:
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp?rev=373410&r1=373409&r2=373410&view=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp Tue Oct  1 17:22:45 2019
@@ -7324,10 +7324,10 @@ private:
 return ElemSize;
 
   if (const Expr *LenExpr = OAE->getLength()) {
-llvm::Value *LengthVal = CGF.EmitScalarExpr(OAE->getLength());
-LengthVal = CGF.EmitScalarConversion(
-LengthVal, OAE->getLength()->getType(),
-CGF.getContext().getSizeType(), OAE->getLength()->getExprLoc());
+llvm::Value *LengthVal = CGF.EmitScalarExpr(LenExpr);
+LengthVal = CGF.EmitScalarConversion(LengthVal, LenExpr->getType(),
+ CGF.getContext().getSizeType(),
+ LenExpr->getExprLoc());
 return CGF.Builder.CreateNUWMul(LengthVal, ElemSize);
   }
   assert(!OAE->getLength() && OAE->getColonLoc().isValid() &&


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


[PATCH] D67901: [clangd] Improve semantic highlighting in dependent contexts (fixes #154)

2019-10-01 Thread Nathan Ridge via Phabricator via cfe-commits
nridge added inline comments.



Comment at: clang-tools-extra/clangd/SemanticHighlighting.cpp:219
+  bool VisitDependentNameTypeLoc(DependentNameTypeLoc L) {
+addToken(L.getNameLoc(), HighlightingKind::DependentType);
+return true;

hokein wrote:
> nit: we have `kindForType` for hanlding all types, so I'd move the logic of 
> detecting the dependent type there.
I did try this, but it doesn't quite work, because `VisitTypeLoc` adds the 
highlighting to the `TypeLoc`'s `getBeginLoc()`. For something like `typename 
T::type`, that highlights the `typename` token rather than the `type` token. By 
contrast, here I add the highlighting to the `DependentNameTypeLoc`'s 
`getNameLoc()` which will correctly highlight the `type` token.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D67901



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


[PATCH] D67901: [clangd] Improve semantic highlighting in dependent contexts (fixes #154)

2019-10-01 Thread Nathan Ridge via Phabricator via cfe-commits
nridge updated this revision to Diff 222725.
nridge marked 9 inline comments as done.
nridge added a comment.

Address review comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D67901

Files:
  clang-tools-extra/clangd/SemanticHighlighting.cpp
  clang-tools-extra/clangd/SemanticHighlighting.h
  clang-tools-extra/clangd/test/semantic-highlighting.test
  clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp

Index: clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
===
--- clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
+++ clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
@@ -51,6 +51,9 @@
   {HighlightingKind::StaticField, "StaticField"},
   {HighlightingKind::Method, "Method"},
   {HighlightingKind::StaticMethod, "StaticMethod"},
+  {HighlightingKind::Typedef, "Typedef"},
+  {HighlightingKind::DependentType, "DependentType"},
+  {HighlightingKind::DependentName, "DependentName"},
   {HighlightingKind::TemplateParameter, "TemplateParameter"},
   {HighlightingKind::Primitive, "Primitive"},
   {HighlightingKind::Macro, "Macro"}};
@@ -175,7 +178,7 @@
   }
   template
   struct $Class[[C]] : $Namespace[[abc]]::$Class[[A]]<$TemplateParameter[[T]]> {
-typename $TemplateParameter[[T]]::A* $Field[[D]];
+typename $TemplateParameter[[T]]::$DependentType[[A]]* $Field[[D]];
   };
   $Namespace[[abc]]::$Class[[A]]<$Primitive[[int]]> $Variable[[AA]];
   typedef $Namespace[[abc]]::$Class[[A]]<$Primitive[[int]]> $Class[[AAA]];
@@ -509,6 +512,55 @@
   $Typedef[[Pointer]], $Typedef[[LVReference]], $Typedef[[RVReference]],
   $Typedef[[Array]], $Typedef[[MemberPointer]]);
   };
+)cpp",
+  R"cpp(
+  template 
+  $Primitive[[void]] $Function[[foo]]($TemplateParameter[[T]] $Parameter[[P]]) {
+$DependentName[[bar]]($Parameter[[P]]);
+  }
+)cpp",
+  R"cpp(
+  class $Class[[A]] {
+template 
+$Primitive[[void]] $Method[[bar]]($TemplateParameter[[T]]);
+  };
+
+  template 
+  $Primitive[[void]] $Function[[foo]]($TemplateParameter[[U]] $Parameter[[P]]) {
+$Class[[A]]().$DependentName[[bar]]($Parameter[[P]]);
+  }
+)cpp",
+  R"cpp(
+  struct $Class[[A]] {
+template 
+static $Primitive[[void]] $StaticMethod[[foo]]($TemplateParameter[[T]]);
+  };
+
+  template 
+  struct $Class[[B]] {
+$Primitive[[void]] $Method[[bar]]() {
+  $Class[[A]]::$DependentName[[foo]]($TemplateParameter[[T]]());
+}
+  };
+)cpp",
+  R"cpp(
+  template 
+  $Primitive[[void]] $Function[[foo]](typename $TemplateParameter[[T]]::$DependentType[[Type]]
+= $TemplateParameter[[T]]::$DependentName[[val]]);
+)cpp",
+  R"cpp(
+  template 
+  $Primitive[[void]] $Function[[foo]]($TemplateParameter[[T]] $Parameter[[P]]) {
+$Parameter[[P]].$DependentName[[Field]];
+  }
+)cpp",
+  R"cpp(
+  template 
+  class $Class[[A]] {
+$Primitive[[int]] $Method[[foo]]() {
+  return $TemplateParameter[[T]]::$DependentName[[Field]];
+}
+  };
 )cpp"};
   for (const auto &TestCase : TestCases) {
 checkHighlightings(TestCase);
Index: clang-tools-extra/clangd/test/semantic-highlighting.test
===
--- clang-tools-extra/clangd/test/semantic-highlighting.test
+++ clang-tools-extra/clangd/test/semantic-highlighting.test
@@ -41,6 +41,12 @@
 # CHECK-NEXT:"entity.name.type.typedef.cpp"
 # CHECK-NEXT:  ],
 # CHECK-NEXT:  [
+# CHECK-NEXT:"entity.name.type.dependent.cpp"
+# CHECK-NEXT:  ],
+# CHECK-NEXT:  [
+# CHECK-NEXT:"entity.name.other.dependent.cpp"
+# CHECK-NEXT:  ],
+# CHECK-NEXT:  [
 # CHECK-NEXT:"entity.name.namespace.cpp"
 # CHECK-NEXT:  ],
 # CHECK-NEXT:  [
@@ -61,7 +67,7 @@
 # CHECK-NEXT:"lines": [
 # CHECK-NEXT:  {
 # CHECK-NEXT:"line": 0,
-# CHECK-NEXT:"tokens": "AAADAA4EAAEAAA=="
+# CHECK-NEXT:"tokens": "AAADABAEAAEAAA=="
 # CHECK-NEXT:  }
 # CHECK-NEXT:],
 # CHECK-NEXT:"textDocument": {
@@ -76,11 +82,11 @@
 # CHECK-NEXT:"lines": [
 # CHECK-NEXT:  {
 # CHECK-NEXT:"line": 0,
-# CHECK-NEXT:"tokens": "AAADAA4EAAEAAA=="
+# CHECK-NEXT:"tokens": "AAADABAEAAEAAA=="
 # CHECK-NEXT:  }
 # CHECK-NEXT:  {
 # CHECK-NEXT:"line": 1,
-# CHECK-NEXT:"tokens": "AAADAA4EAAEAAA=="
+# CHECK-NEXT:"tokens": "AAADABAEAAEAAA=="
 # CHECK-NEXT:  }
 # CHECK-NEXT:],
 # CHECK-NEXT:"textDocument": {
@@ 

r373407 - Emit TypeNodes.def with tblgen.

2019-10-01 Thread John McCall via cfe-commits
Author: rjmccall
Date: Tue Oct  1 16:13:03 2019
New Revision: 373407

URL: http://llvm.org/viewvc/llvm-project?rev=373407&view=rev
Log:
Emit TypeNodes.def with tblgen.

The primary goal here is to make the type node hierarchy available to
other tblgen backends, although it should also make it easier to generate
more selective x-macros in the future.

Because tblgen doesn't seem to allow backends to preserve the source
order of defs, this is not NFC because it significantly re-orders IDs.
I've fixed the one (fortunately obvious) place where we relied on
the old order.  Unfortunately, I wasn't able to share code with the
existing AST-node x-macro generators because the x-macro schema we use
for types is different in a number of ways.  The main loss is that
subclasses aren't ordered together, which doesn't seem important for
types because the hierarchy is generally very shallow with little
clustering.

Added:
cfe/trunk/include/clang/Basic/TypeNodes.td
cfe/trunk/utils/TableGen/ClangTypeNodesEmitter.cpp
Removed:
cfe/trunk/include/clang/AST/TypeNodes.def
Modified:
cfe/trunk/include/clang/AST/CMakeLists.txt
cfe/trunk/include/clang/AST/Type.h
cfe/trunk/utils/TableGen/CMakeLists.txt
cfe/trunk/utils/TableGen/TableGen.cpp
cfe/trunk/utils/TableGen/TableGenBackends.h

Modified: cfe/trunk/include/clang/AST/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/CMakeLists.txt?rev=373407&r1=373406&r2=373407&view=diff
==
--- cfe/trunk/include/clang/AST/CMakeLists.txt (original)
+++ cfe/trunk/include/clang/AST/CMakeLists.txt Tue Oct  1 16:13:03 2019
@@ -31,6 +31,10 @@ clang_tablegen(DeclNodes.inc -gen-clang-
   SOURCE ../Basic/DeclNodes.td
   TARGET ClangDeclNodes)
 
+clang_tablegen(TypeNodes.def -gen-clang-type-nodes
+  SOURCE ../Basic/TypeNodes.td
+  TARGET ClangTypeNodes)
+
 clang_tablegen(CommentNodes.inc -gen-clang-comment-nodes
   SOURCE ../Basic/CommentNodes.td
   TARGET ClangCommentNodes)

Modified: cfe/trunk/include/clang/AST/Type.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=373407&r1=373406&r2=373407&view=diff
==
--- cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/trunk/include/clang/AST/Type.h Tue Oct  1 16:13:03 2019
@@ -1437,10 +1437,9 @@ class alignas(8) Type : public ExtQualsT
 public:
   enum TypeClass {
 #define TYPE(Class, Base) Class,
-#define LAST_TYPE(Class) TypeLast = Class,
+#define LAST_TYPE(Class) TypeLast = Class
 #define ABSTRACT_TYPE(Class, Base)
 #include "clang/AST/TypeNodes.def"
-TagFirst = Record, TagLast = Enum
   };
 
 private:
@@ -4436,7 +4435,7 @@ public:
   bool isBeingDefined() const;
 
   static bool classof(const Type *T) {
-return T->getTypeClass() >= TagFirst && T->getTypeClass() <= TagLast;
+return T->getTypeClass() == Enum || T->getTypeClass() == Record;
   }
 };
 

Removed: cfe/trunk/include/clang/AST/TypeNodes.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/TypeNodes.def?rev=373406&view=auto
==
--- cfe/trunk/include/clang/AST/TypeNodes.def (original)
+++ cfe/trunk/include/clang/AST/TypeNodes.def (removed)
@@ -1,135 +0,0 @@
-//===-- TypeNodes.def - Metadata about Type AST nodes ---*- C++ 
-*-===//
-//
-// 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
-//
-//===--===//
-//
-//  This file defines the AST type info database. Each type node is
-//  enumerated by providing its name (e.g., "Builtin" or "Enum") and
-//  base class (e.g., "Type" or "TagType"). Depending on where in the
-//  abstract syntax tree the type will show up, the enumeration uses
-//  one of five different macros:
-//
-//TYPE(Class, Base) - A type that can show up anywhere in the AST,
-//and might be dependent, canonical, or non-canonical. All clients
-//will need to understand these types.
-//
-//ABSTRACT_TYPE(Class, Base) - An abstract class that shows up in
-//the type hierarchy but has no concrete instances.
-//
-//NON_CANONICAL_TYPE(Class, Base) - A type that can show up
-//anywhere in the AST but will never be a part of a canonical
-//type. Clients that only need to deal with canonical types
-//(ignoring, e.g., typedefs and other type aliases used for
-//pretty-printing) can ignore these types.
-//
-//DEPENDENT_TYPE(Class, Base) - A type that will only show up
-//within a C++ template that has not been instantiated, e.g., a
-//type that is always dependent. Clients that do not need to deal
-//with uninstantiated C++ templates can ignore these types.
-//
-//

r373406 - Use scope qualifiers in Clang's tblgen backends to get useful

2019-10-01 Thread John McCall via cfe-commits
Author: rjmccall
Date: Tue Oct  1 16:12:57 2019
New Revision: 373406

URL: http://llvm.org/viewvc/llvm-project?rev=373406&view=rev
Log:
Use scope qualifiers in Clang's tblgen backends to get useful
redeclaration checking.  NFC.

Modified:
cfe/trunk/utils/TableGen/ClangASTNodesEmitter.cpp
cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp
cfe/trunk/utils/TableGen/ClangCommentCommandInfoEmitter.cpp
cfe/trunk/utils/TableGen/ClangCommentHTMLNamedCharacterReferenceEmitter.cpp
cfe/trunk/utils/TableGen/ClangDataCollectorsEmitter.cpp
cfe/trunk/utils/TableGen/ClangDiagnosticsEmitter.cpp
cfe/trunk/utils/TableGen/ClangOpcodesEmitter.cpp
cfe/trunk/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
cfe/trunk/utils/TableGen/ClangOptionDocEmitter.cpp
cfe/trunk/utils/TableGen/ClangSACheckersEmitter.cpp
cfe/trunk/utils/TableGen/NeonEmitter.cpp

Modified: cfe/trunk/utils/TableGen/ClangASTNodesEmitter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/utils/TableGen/ClangASTNodesEmitter.cpp?rev=373406&r1=373405&r2=373406&view=diff
==
--- cfe/trunk/utils/TableGen/ClangASTNodesEmitter.cpp (original)
+++ cfe/trunk/utils/TableGen/ClangASTNodesEmitter.cpp Tue Oct  1 16:12:57 2019
@@ -10,6 +10,8 @@
 //
 
//===--===//
 
+#include "TableGenBackends.h"
+
 #include "llvm/TableGen/Record.h"
 #include "llvm/TableGen/TableGenBackend.h"
 #include 
@@ -173,15 +175,14 @@ void ClangASTNodesEmitter::run(raw_ostre
   OS << "#undef ABSTRACT_" << macroName(Root.getName()) << "\n";
 }
 
-namespace clang {
-void EmitClangASTNodes(RecordKeeper &RK, raw_ostream &OS,
-   const std::string &N, const std::string &S) {
+void clang::EmitClangASTNodes(RecordKeeper &RK, raw_ostream &OS,
+  const std::string &N, const std::string &S) {
   ClangASTNodesEmitter(RK, N, S).run(OS);
 }
 
 // Emits and addendum to a .inc file to enumerate the clang declaration
 // contexts.
-void EmitClangDeclContext(RecordKeeper &Records, raw_ostream &OS) {
+void clang::EmitClangDeclContext(RecordKeeper &Records, raw_ostream &OS) {
   // FIXME: Find a .td file format to allow for this to be represented better.
 
   emitSourceFileHeader("List of AST Decl nodes", OS);
@@ -225,4 +226,3 @@ void EmitClangDeclContext(RecordKeeper &
   OS << "#undef DECL_CONTEXT\n";
   OS << "#undef DECL_CONTEXT_BASE\n";
 }
-} // end namespace clang

Modified: cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp?rev=373406&r1=373405&r2=373406&view=diff
==
--- cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp (original)
+++ cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp Tue Oct  1 16:12:57 2019
@@ -10,6 +10,8 @@
 //
 
//===--===//
 
+#include "TableGenBackends.h"
+
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/DenseSet.h"
@@ -2219,10 +2221,8 @@ static void emitClangAttrThisIsaIdentifi
   OS << "#endif // CLANG_ATTR_THIS_ISA_IDENTIFIER_ARG_LIST\n\n";
 }
 
-namespace clang {
-
 // Emits the class definitions for attributes.
-void EmitClangAttrClass(RecordKeeper &Records, raw_ostream &OS) {
+void clang::EmitClangAttrClass(RecordKeeper &Records, raw_ostream &OS) {
   emitSourceFileHeader("Attribute classes' definitions", OS);
 
   OS << "#ifndef LLVM_CLANG_ATTR_CLASSES_INC\n";
@@ -2491,7 +2491,7 @@ void EmitClangAttrClass(RecordKeeper &Re
 }
 
 // Emits the class method definitions for attributes.
-void EmitClangAttrImpl(RecordKeeper &Records, raw_ostream &OS) {
+void clang::EmitClangAttrImpl(RecordKeeper &Records, raw_ostream &OS) {
   emitSourceFileHeader("Attribute classes' member function definitions", OS);
 
   std::vector Attrs = Records.getAllDerivedDefinitions("Attr");
@@ -2556,8 +2556,6 @@ void EmitClangAttrImpl(RecordKeeper &Rec
   EmitFunc("printPretty(OS, Policy)");
 }
 
-} // end namespace clang
-
 static void emitAttrList(raw_ostream &OS, StringRef Class,
  const std::vector &AttrList) {
   for (auto Cur : AttrList) {

Modified: cfe/trunk/utils/TableGen/ClangCommentCommandInfoEmitter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/utils/TableGen/ClangCommentCommandInfoEmitter.cpp?rev=373406&r1=373405&r2=373406&view=diff
==
--- cfe/trunk/utils/TableGen/ClangCommentCommandInfoEmitter.cpp (original)
+++ cfe/trunk/utils/TableGen/ClangCommentCommandInfoEmitter.cpp Tue Oct  1 
16:12:57 2019
@@ -11,6 +11,8 @@
 //
 
//===--===//
 
+#include "TableGenBackends.h"
+
 #include "llvm/TableGen/Record.h"
 #include "llvm/TableGen/StringMatcher.h"
 #include "

[PATCH] D68284: [HIP] Support -emit-llvm for device compilation

2019-10-01 Thread Artem Belevich via Phabricator via cfe-commits
tra accepted this revision.
tra added a comment.

LGTM.

Does it produce textual IR if used with `-S`?


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

https://reviews.llvm.org/D68284



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


[PATCH] D68300: [HIP] Add option -fno-hip-link-builtin-bitcode to disable linking device lib

2019-10-01 Thread Artem Belevich via Phabricator via cfe-commits
tra added a comment.

The functionality looks generic enough.  Should it be just 
`flink_builtin_bitcode`?


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

https://reviews.llvm.org/D68300



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


[PATCH] D67010: [Modules] Move search paths from control block to unhashed control block

2019-10-01 Thread Bruno Cardoso Lopes via Phabricator via cfe-commits
bruno added a reviewer: v.g.vassilev.
bruno added a comment.

Ping!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D67010



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


[PATCH] D67249: [Modules][PCH] Hash input files content

2019-10-01 Thread Bruno Cardoso Lopes via Phabricator via cfe-commits
bruno added a reviewer: v.g.vassilev.
bruno added a comment.

Ping!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D67249



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


r373400 - [clang][OpenMP][NFC] #include GlobalDecl.h to avoid incomplete class type

2019-10-01 Thread Jordan Rupprecht via cfe-commits
Author: rupprecht
Date: Tue Oct  1 15:30:10 2019
New Revision: 373400

URL: http://llvm.org/viewvc/llvm-project?rev=373400&view=rev
Log:
[clang][OpenMP][NFC] #include GlobalDecl.h to avoid incomplete class type

Modified:
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.h

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntime.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntime.h?rev=373400&r1=373399&r2=373400&view=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntime.h (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntime.h Tue Oct  1 15:30:10 2019
@@ -15,6 +15,7 @@
 
 #include "CGValue.h"
 #include "clang/AST/DeclOpenMP.h"
+#include "clang/AST/GlobalDecl.h"
 #include "clang/AST/Type.h"
 #include "clang/Basic/OpenMPKinds.h"
 #include "clang/Basic/SourceLocation.h"
@@ -36,7 +37,6 @@ class Value;
 
 namespace clang {
 class Expr;
-class GlobalDecl;
 class OMPDependClause;
 class OMPExecutableDirective;
 class OMPLoopDirective;


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


r373398 - CGVTables - silence static analyzer getAs null dereference warnings. NFCI.

2019-10-01 Thread Simon Pilgrim via cfe-commits
Author: rksimon
Date: Tue Oct  1 15:02:46 2019
New Revision: 373398

URL: http://llvm.org/viewvc/llvm-project?rev=373398&view=rev
Log:
CGVTables - silence static analyzer getAs null dereference 
warnings. NFCI.

The static analyzer is warning about potential null dereferences, but we should 
be able to use castAs directly and if not assert will fire 
for us.

Modified:
cfe/trunk/lib/CodeGen/CGVTables.cpp

Modified: cfe/trunk/lib/CodeGen/CGVTables.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGVTables.cpp?rev=373398&r1=373397&r2=373398&view=diff
==
--- cfe/trunk/lib/CodeGen/CGVTables.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGVTables.cpp Tue Oct  1 15:02:46 2019
@@ -157,7 +157,7 @@ CodeGenFunction::GenerateVarArgsThunk(ll
   const CGFunctionInfo &FnInfo,
   GlobalDecl GD, const ThunkInfo &Thunk) {
   const CXXMethodDecl *MD = cast(GD.getDecl());
-  const FunctionProtoType *FPT = MD->getType()->getAs();
+  const FunctionProtoType *FPT = MD->getType()->castAs();
   QualType ResultType = FPT->getReturnType();
 
   // Get the original function
@@ -242,7 +242,6 @@ void CodeGenFunction::StartThunk(llvm::F
   // Build FunctionArgs.
   const CXXMethodDecl *MD = cast(GD.getDecl());
   QualType ThisType = MD->getThisType();
-  const FunctionProtoType *FPT = MD->getType()->getAs();
   QualType ResultType;
   if (IsUnprototyped)
 ResultType = CGM.getContext().VoidTy;
@@ -251,7 +250,7 @@ void CodeGenFunction::StartThunk(llvm::F
   else if (CGM.getCXXABI().hasMostDerivedReturn(GD))
 ResultType = CGM.getContext().VoidPtrTy;
   else
-ResultType = FPT->getReturnType();
+ResultType = MD->getType()->castAs()->getReturnType();
   FunctionArgList FunctionArgs;
 
   // Create the implicit 'this' parameter declaration.


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


r373396 - CGExprAgg - remove duplicate code. NFCI.

2019-10-01 Thread Simon Pilgrim via cfe-commits
Author: rksimon
Date: Tue Oct  1 14:50:30 2019
New Revision: 373396

URL: http://llvm.org/viewvc/llvm-project?rev=373396&view=rev
Log:
CGExprAgg - remove duplicate code. NFCI.

Remove duplicate getAs<> call, avoiding a clang static analyzer null 
dereference warning.

Modified:
cfe/trunk/lib/CodeGen/CGExprAgg.cpp

Modified: cfe/trunk/lib/CodeGen/CGExprAgg.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprAgg.cpp?rev=373396&r1=373395&r2=373396&view=diff
==
--- cfe/trunk/lib/CodeGen/CGExprAgg.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprAgg.cpp Tue Oct  1 14:50:30 2019
@@ -1759,7 +1759,7 @@ static CharUnits GetNumNonZeroBytesInIni
   // referencee.  InitListExprs for unions and arrays can't have references.
   if (const RecordType *RT = E->getType()->getAs()) {
 if (!RT->isUnionType()) {
-  RecordDecl *SD = E->getType()->getAs()->getDecl();
+  RecordDecl *SD = RT->getDecl();
   CharUnits NumNonZeroBytes = CharUnits::Zero();
 
   unsigned ILEElement = 0;


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


[PATCH] D68157: [X86][ABI] Keep empty class argument passing by value compatible with GCC.

2019-10-01 Thread Michael Liao via Phabricator via cfe-commits
hliao added a comment.

PING


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D68157



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


[PATCH] D68300: [HIP] Add option -fno-hip-link-builtin-bitcode to disable linking device lib

2019-10-01 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl created this revision.
yaxunl added a reviewer: tra.

https://reviews.llvm.org/D68300

Files:
  include/clang/Driver/Options.td
  lib/Driver/ToolChains/HIP.cpp
  test/Driver/hip-no-device-libs.hip


Index: test/Driver/hip-no-device-libs.hip
===
--- /dev/null
+++ test/Driver/hip-no-device-libs.hip
@@ -0,0 +1,11 @@
+// REQUIRES: clang-driver
+// REQUIRES: x86-registered-target
+// REQUIRES: amdgpu-registered-target
+
+// RUN: %clang -### -fno-hip-link-builtin-bitcode -target x86_64-linux-gnu \
+// RUN:   -x hip --cuda-gpu-arch=gfx900 \
+// RUN:   %S/Inputs/hip_multiple_inputs/b.hip \
+// RUN: 2>&1 | FileCheck %s
+
+// CHECK-NOT: "-mlink-builtin-bitcode"
+
Index: lib/Driver/ToolChains/HIP.cpp
===
--- lib/Driver/ToolChains/HIP.cpp
+++ lib/Driver/ToolChains/HIP.cpp
@@ -289,6 +289,10 @@
 CC1Args.append({"-fvisibility", "hidden"});
 CC1Args.push_back("-fapply-global-visibility-to-externs");
   }
+
+  if (!DriverArgs.hasFlag(options::OPT_fhip_link_builtin_bitcode,
+  options::OPT_fno_hip_link_builtin_bitcode, true))
+return;
   ArgStringList LibraryPaths;
 
   // Find in --hip-device-lib-path and HIP_LIBRARY_PATH.
Index: include/clang/Driver/Options.td
===
--- include/clang/Driver/Options.td
+++ include/clang/Driver/Options.td
@@ -602,6 +602,9 @@
 def fhip_new_launch_api : Flag<["-"], "fhip-new-launch-api">,
   Flags<[CC1Option]>, HelpText<"Use new kernel launching API for HIP.">;
 def fno_hip_new_launch_api : Flag<["-"], "fno-hip-new-launch-api">;
+def fhip_link_builtin_bitcode : Flag<["-"], "fhip-link-builtin-bitcode">,
+  Flags<[CC1Option]>, HelpText<"Link builtin bitcode for HIP device 
compilation.">;
+def fno_hip_link_builtin_bitcode : Flag<["-"], "fno-hip-link-builtin-bitcode">;
 def libomptarget_nvptx_path_EQ : Joined<["--"], "libomptarget-nvptx-path=">, 
Group,
   HelpText<"Path to libomptarget-nvptx libraries">;
 def dD : Flag<["-"], "dD">, Group, Flags<[CC1Option]>,


Index: test/Driver/hip-no-device-libs.hip
===
--- /dev/null
+++ test/Driver/hip-no-device-libs.hip
@@ -0,0 +1,11 @@
+// REQUIRES: clang-driver
+// REQUIRES: x86-registered-target
+// REQUIRES: amdgpu-registered-target
+
+// RUN: %clang -### -fno-hip-link-builtin-bitcode -target x86_64-linux-gnu \
+// RUN:   -x hip --cuda-gpu-arch=gfx900 \
+// RUN:   %S/Inputs/hip_multiple_inputs/b.hip \
+// RUN: 2>&1 | FileCheck %s
+
+// CHECK-NOT: "-mlink-builtin-bitcode"
+
Index: lib/Driver/ToolChains/HIP.cpp
===
--- lib/Driver/ToolChains/HIP.cpp
+++ lib/Driver/ToolChains/HIP.cpp
@@ -289,6 +289,10 @@
 CC1Args.append({"-fvisibility", "hidden"});
 CC1Args.push_back("-fapply-global-visibility-to-externs");
   }
+
+  if (!DriverArgs.hasFlag(options::OPT_fhip_link_builtin_bitcode,
+  options::OPT_fno_hip_link_builtin_bitcode, true))
+return;
   ArgStringList LibraryPaths;
 
   // Find in --hip-device-lib-path and HIP_LIBRARY_PATH.
Index: include/clang/Driver/Options.td
===
--- include/clang/Driver/Options.td
+++ include/clang/Driver/Options.td
@@ -602,6 +602,9 @@
 def fhip_new_launch_api : Flag<["-"], "fhip-new-launch-api">,
   Flags<[CC1Option]>, HelpText<"Use new kernel launching API for HIP.">;
 def fno_hip_new_launch_api : Flag<["-"], "fno-hip-new-launch-api">;
+def fhip_link_builtin_bitcode : Flag<["-"], "fhip-link-builtin-bitcode">,
+  Flags<[CC1Option]>, HelpText<"Link builtin bitcode for HIP device compilation.">;
+def fno_hip_link_builtin_bitcode : Flag<["-"], "fno-hip-link-builtin-bitcode">;
 def libomptarget_nvptx_path_EQ : Joined<["--"], "libomptarget-nvptx-path=">, Group,
   HelpText<"Path to libomptarget-nvptx libraries">;
 def dD : Flag<["-"], "dD">, Group, Flags<[CC1Option]>,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D68148: [clang-tidy] Rename objc-avoid-spinlock check to darwin-avoid-spinlock

2019-10-01 Thread Stephane Moore via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL373392: [clang-tidy] Rename objc-avoid-spinlock check to 
darwin-avoid-spinlock (authored by stephanemoore, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D68148?vs=53&id=222708#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D68148

Files:
  clang-tools-extra/trunk/clang-tidy/darwin/AvoidSpinlockCheck.cpp
  clang-tools-extra/trunk/clang-tidy/darwin/AvoidSpinlockCheck.h
  clang-tools-extra/trunk/clang-tidy/darwin/CMakeLists.txt
  clang-tools-extra/trunk/clang-tidy/darwin/DarwinTidyModule.cpp
  clang-tools-extra/trunk/clang-tidy/objc/AvoidSpinlockCheck.cpp
  clang-tools-extra/trunk/clang-tidy/objc/AvoidSpinlockCheck.h
  clang-tools-extra/trunk/clang-tidy/objc/CMakeLists.txt
  clang-tools-extra/trunk/clang-tidy/objc/ObjCTidyModule.cpp
  clang-tools-extra/trunk/docs/ReleaseNotes.rst
  clang-tools-extra/trunk/docs/clang-tidy/checks/darwin-avoid-spinlock.rst
  clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst
  clang-tools-extra/trunk/docs/clang-tidy/checks/objc-avoid-spinlock.rst
  clang-tools-extra/trunk/test/clang-tidy/darwin-avoid-spinlock.m
  clang-tools-extra/trunk/test/clang-tidy/objc-avoid-spinlock.m

Index: clang-tools-extra/trunk/docs/ReleaseNotes.rst
===
--- clang-tools-extra/trunk/docs/ReleaseNotes.rst
+++ clang-tools-extra/trunk/docs/ReleaseNotes.rst
@@ -115,6 +115,9 @@
   Now also checks if any calls to ``pthread_*`` functions expect negative return
   values.
 
+- The 'objc-avoid-spinlock' check was renamed to :doc:`darwin-avoid-spinlock
+  `
+
 Improvements to include-fixer
 -
 
Index: clang-tools-extra/trunk/docs/clang-tidy/checks/darwin-avoid-spinlock.rst
===
--- clang-tools-extra/trunk/docs/clang-tidy/checks/darwin-avoid-spinlock.rst
+++ clang-tools-extra/trunk/docs/clang-tidy/checks/darwin-avoid-spinlock.rst
@@ -0,0 +1,15 @@
+.. title:: clang-tidy - darwin-avoid-spinlock
+
+darwin-avoid-spinlock
+=
+
+Finds usages of ``OSSpinlock``, which is deprecated due to potential livelock
+problems. 
+
+This check will detect following function invocations:
+
+- ``OSSpinlockLock``
+- ``OSSpinlockTry``
+- ``OSSpinlockUnlock``
+
+The corresponding information about the problem of ``OSSpinlock``: https://blog.postmates.com/why-spinlocks-are-bad-on-ios-b69fc5221058
Index: clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst
@@ -212,6 +212,7 @@
cppcoreguidelines-pro-type-vararg
cppcoreguidelines-slicing
cppcoreguidelines-special-member-functions
+   darwin-avoid-spinlock
darwin-dispatch-once-nonstatic
fuchsia-default-arguments-calls
fuchsia-default-arguments-declarations
@@ -325,7 +326,6 @@
mpi-buffer-deref
mpi-type-mismatch
objc-avoid-nserror-init
-   objc-avoid-spinlock
objc-forbidden-subclassing
objc-missing-hash
objc-property-declaration
Index: clang-tools-extra/trunk/test/clang-tidy/darwin-avoid-spinlock.m
===
--- clang-tools-extra/trunk/test/clang-tidy/darwin-avoid-spinlock.m
+++ clang-tools-extra/trunk/test/clang-tidy/darwin-avoid-spinlock.m
@@ -0,0 +1,15 @@
+// RUN: %check_clang_tidy %s darwin-avoid-spinlock %t
+
+typedef int OSSpinLock;
+
+@implementation Foo
+- (void)f {
+int i = 1;
+OSSpinlockLock(&i);
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use os_unfair_lock_lock() or dispatch queue APIs instead of the deprecated OSSpinLock [darwin-avoid-spinlock]
+OSSpinlockTry(&i);
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use os_unfair_lock_lock() or dispatch queue APIs instead of the deprecated OSSpinLock [darwin-avoid-spinlock]
+OSSpinlockUnlock(&i);
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use os_unfair_lock_lock() or dispatch queue APIs instead of the deprecated OSSpinLock [darwin-avoid-spinlock]
+}
+@end
Index: clang-tools-extra/trunk/clang-tidy/objc/ObjCTidyModule.cpp
===
--- clang-tools-extra/trunk/clang-tidy/objc/ObjCTidyModule.cpp
+++ clang-tools-extra/trunk/clang-tidy/objc/ObjCTidyModule.cpp
@@ -10,7 +10,6 @@
 #include "../ClangTidyModule.h"
 #include "../ClangTidyModuleRegistry.h"
 #include "AvoidNSErrorInitCheck.h"
-#include "AvoidSpinlockCheck.h"
 #include "ForbiddenSubclassingCheck.h"
 #include "MissingHashCheck.h"
 #include "PropertyDeclarationCheck.h"
@@ -27,8 +26,6 @@
   void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
 CheckFactories.registerCheck(

[clang-tools-extra] r373392 - [clang-tidy] Rename objc-avoid-spinlock check to darwin-avoid-spinlock

2019-10-01 Thread Stephane Moore via cfe-commits
Author: stephanemoore
Date: Tue Oct  1 14:18:40 2019
New Revision: 373392

URL: http://llvm.org/viewvc/llvm-project?rev=373392&view=rev
Log:
[clang-tidy] Rename objc-avoid-spinlock check to darwin-avoid-spinlock

Summary:
OSSpinLock* are Apple/Darwin functions, but were previously located with ObjC 
checks as those were most closely tied to Apple platforms before.

Now that there's a specific Darwin module, relocating the check there.

This change was prepared by running rename_check.py.

Contributed By: mwyman

Reviewers: stephanemoore, dmaclach

Reviewed By: stephanemoore

Subscribers: Eugene.Zelenko, mgorny, xazax.hun, cfe-commits

Tags: #clang-tools-extra, #clang, #llvm

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

Added:
clang-tools-extra/trunk/clang-tidy/darwin/AvoidSpinlockCheck.cpp
clang-tools-extra/trunk/clang-tidy/darwin/AvoidSpinlockCheck.h
clang-tools-extra/trunk/docs/clang-tidy/checks/darwin-avoid-spinlock.rst
clang-tools-extra/trunk/test/clang-tidy/darwin-avoid-spinlock.m
Removed:
clang-tools-extra/trunk/clang-tidy/objc/AvoidSpinlockCheck.cpp
clang-tools-extra/trunk/clang-tidy/objc/AvoidSpinlockCheck.h
clang-tools-extra/trunk/docs/clang-tidy/checks/objc-avoid-spinlock.rst
clang-tools-extra/trunk/test/clang-tidy/objc-avoid-spinlock.m
Modified:
clang-tools-extra/trunk/clang-tidy/darwin/CMakeLists.txt
clang-tools-extra/trunk/clang-tidy/darwin/DarwinTidyModule.cpp
clang-tools-extra/trunk/clang-tidy/objc/CMakeLists.txt
clang-tools-extra/trunk/clang-tidy/objc/ObjCTidyModule.cpp
clang-tools-extra/trunk/docs/ReleaseNotes.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst

Added: clang-tools-extra/trunk/clang-tidy/darwin/AvoidSpinlockCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/darwin/AvoidSpinlockCheck.cpp?rev=373392&view=auto
==
--- clang-tools-extra/trunk/clang-tidy/darwin/AvoidSpinlockCheck.cpp (added)
+++ clang-tools-extra/trunk/clang-tidy/darwin/AvoidSpinlockCheck.cpp Tue Oct  1 
14:18:40 2019
@@ -0,0 +1,36 @@
+//===--- AvoidSpinlockCheck.cpp - 
clang-tidy---===//
+//
+// 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 "AvoidSpinlockCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace darwin {
+
+void AvoidSpinlockCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(
+  callExpr(callee((functionDecl(hasAnyName(
+   "OSSpinlockLock", "OSSpinlockUnlock", "OSSpinlockTry")
+  .bind("spinlock"),
+  this);
+}
+
+void AvoidSpinlockCheck::check(const MatchFinder::MatchResult &Result) {
+  const auto *MatchedExpr = Result.Nodes.getNodeAs("spinlock");
+  diag(MatchedExpr->getBeginLoc(),
+   "use os_unfair_lock_lock() or dispatch queue APIs instead of the "
+   "deprecated OSSpinLock");
+}
+
+}  // namespace darwin
+}  // namespace tidy
+}  // namespace clang

Added: clang-tools-extra/trunk/clang-tidy/darwin/AvoidSpinlockCheck.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/darwin/AvoidSpinlockCheck.h?rev=373392&view=auto
==
--- clang-tools-extra/trunk/clang-tidy/darwin/AvoidSpinlockCheck.h (added)
+++ clang-tools-extra/trunk/clang-tidy/darwin/AvoidSpinlockCheck.h Tue Oct  1 
14:18:40 2019
@@ -0,0 +1,35 @@
+//===--- AvoidSpinlockCheck.h - clang-tidy---*- C++ 
-*-===//
+//
+// 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
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_DARWIN_AVOIDSPINLOCKCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_DARWIN_AVOIDSPINLOCKCHECK_H
+
+#include "../ClangTidyCheck.h"
+
+namespace clang {
+namespace tidy {
+namespace darwin {
+
+/// Finds usages of OSSpinlock, which is deprecated due to potential livelock
+/// problems.
+///
+/// For the user-facing documentation see:
+/// http://clang.llvm.org/extra/clang-tidy/checks/darwin-avoid-spinlock.html
+class AvoidSpinlockCheck : public ClangTidyCheck {
+ public:
+  AvoidSpinlockCheck(StringRef Name, ClangTidyContext *Context)
+  : ClangTidyCheck(Name, Context) {}
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+  void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+};
+
+}  // n

[PATCH] D68117: [DWARF-5] Support for C++11 defaulted, deleted member functions.

2019-10-01 Thread Sourabh Singh Tomar via Phabricator via cfe-commits
SouraVX marked 2 inline comments as done.
SouraVX added a comment.

Will be adding llvm-dwarfdump tests soon.




Comment at: clang/lib/CodeGen/CGDebugInfo.cpp:1608
 
+  if (CGM.getCodeGenOpts().DwarfVersion >= 5) {
+// DWARF-5 support for, defaulted, deleted member functions

aprantl wrote:
> The clang frontend should not be the one making the decision here, if 
> possible it would be better to unconditionally emit this info in LLVM IR and 
> then filter it out in the backend. I could imagine that the PDB backend might 
> find this info useful, too (but I don't know).
Make sense, removed check from frontend.


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

https://reviews.llvm.org/D68117



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


[PATCH] D68117: [DWARF-5] Support for C++11 defaulted, deleted member functions.

2019-10-01 Thread Sourabh Singh Tomar via Phabricator via cfe-commits
SouraVX updated this revision to Diff 222701.
SouraVX added a comment.

Added test cases for debug info Clang frontend.


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

https://reviews.llvm.org/D68117

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/test/CodeGenCXX/dbg-info-all-calls-described.cpp
  clang/test/CodeGenCXX/debug-info-defaulted-in-class.cpp
  clang/test/CodeGenCXX/debug-info-defaulted-out-of-class.cpp
  clang/test/CodeGenCXX/debug-info-deleted.cpp
  clang/test/CodeGenCXX/debug-info-not-defaulted.cpp
  llvm/include/llvm/BinaryFormat/Dwarf.h
  llvm/include/llvm/IR/DebugInfoFlags.def
  llvm/include/llvm/IR/DebugInfoMetadata.h
  llvm/lib/BinaryFormat/Dwarf.cpp
  llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp

Index: llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
===
--- llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
+++ llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
@@ -1296,6 +1296,19 @@
 addFlag(SPDie, dwarf::DW_AT_elemental);
   if (SP->isRecursive())
 addFlag(SPDie, dwarf::DW_AT_recursive);
+  if (DD->getDwarfVersion() >= 5) {
+if (SP->isDefaultedInClass())
+  addUInt(SPDie, dwarf::DW_AT_defaulted, dwarf::DW_FORM_data1,
+  dwarf::DW_DEFAULTED_in_class);
+if (SP->isDefaultedOutOfClass())
+  addUInt(SPDie, dwarf::DW_AT_defaulted, dwarf::DW_FORM_data1,
+  dwarf::DW_DEFAULTED_out_of_class);
+if (SP->isNotDefaulted())
+  addUInt(SPDie, dwarf::DW_AT_defaulted, dwarf::DW_FORM_data1,
+  dwarf::DW_DEFAULTED_no);
+if (SP->isDeleted())
+  addFlag(SPDie, dwarf::DW_AT_deleted);
+  }
 }
 
 void DwarfUnit::constructSubrangeDIE(DIE &Buffer, const DISubrange *SR,
Index: llvm/lib/BinaryFormat/Dwarf.cpp
===
--- llvm/lib/BinaryFormat/Dwarf.cpp
+++ llvm/lib/BinaryFormat/Dwarf.cpp
@@ -271,6 +271,19 @@
   return StringRef();
 }
 
+StringRef llvm::dwarf::DefaultedMemberString(unsigned DefaultedEncodings) {
+  switch (DefaultedEncodings) {
+  // Defaulted Member Encodings codes
+  case DW_DEFAULTED_no:
+return "DW_DEFAULTED_no";
+  case DW_DEFAULTED_in_class:
+return "DW_DEFAULTED_in_class";
+  case DW_DEFAULTED_out_of_class:
+return "DW_DEFAULTED_out_of_class";
+  }
+  return StringRef();
+}
+
 StringRef llvm::dwarf::VisibilityString(unsigned Visibility) {
   switch (Visibility) {
   case DW_VIS_local:
@@ -601,6 +614,8 @@
 return ArrayOrderString(Val);
   case DW_AT_APPLE_runtime_class:
 return LanguageString(Val);
+  case DW_AT_defaulted:
+return DefaultedMemberString(Val);
   }
 
   return StringRef();
Index: llvm/include/llvm/IR/DebugInfoMetadata.h
===
--- llvm/include/llvm/IR/DebugInfoMetadata.h
+++ llvm/include/llvm/IR/DebugInfoMetadata.h
@@ -1758,6 +1758,14 @@
   bool isPure() const { return getSPFlags() & SPFlagPure; }
   bool isElemental() const { return getSPFlags() & SPFlagElemental; }
   bool isRecursive() const { return getSPFlags() & SPFlagRecursive; }
+  bool isDefaultedInClass() const {
+return getSPFlags() & SPFlagDefaultedInClass;
+  }
+  bool isDefaultedOutOfClass() const {
+return getSPFlags() & SPFlagDefaultedOutOfClass;
+  }
+  bool isNotDefaulted() const { return getSPFlags() & SPFlagNotDefaulted; }
+  bool isDeleted() const { return getSPFlags() & SPFlagDeleted; }
 
   /// Check if this is reference-qualified.
   ///
Index: llvm/include/llvm/IR/DebugInfoFlags.def
===
--- llvm/include/llvm/IR/DebugInfoFlags.def
+++ llvm/include/llvm/IR/DebugInfoFlags.def
@@ -88,11 +88,15 @@
 HANDLE_DISP_FLAG((1u << 6), Elemental)
 HANDLE_DISP_FLAG((1u << 7), Recursive)
 HANDLE_DISP_FLAG((1u << 8), MainSubprogram)
+HANDLE_DISP_FLAG((1u << 9), NotDefaulted)
+HANDLE_DISP_FLAG((1u << 10), DefaultedInClass)
+HANDLE_DISP_FLAG((1u << 11), DefaultedOutOfClass)
+HANDLE_DISP_FLAG((1u << 12), Deleted)
 
 #ifdef DISP_FLAG_LARGEST_NEEDED
 // Intended to be used with ADT/BitmaskEnum.h.
 // NOTE: Always must be equal to largest flag, check this when adding new flags.
-HANDLE_DISP_FLAG((1 << 8), Largest)
+HANDLE_DISP_FLAG((1 << 12), Largest)
 #undef DISP_FLAG_LARGEST_NEEDED
 #endif
 
Index: llvm/include/llvm/BinaryFormat/Dwarf.h
===
--- llvm/include/llvm/BinaryFormat/Dwarf.h
+++ llvm/include/llvm/BinaryFormat/Dwarf.h
@@ -411,6 +411,7 @@
 StringRef DecimalSignString(unsigned Sign);
 StringRef EndianityString(unsigned Endian);
 StringRef AccessibilityString(unsigned Access);
+StringRef DefaultedMemberString(unsigned DefaultedEncodings);
 StringRef VisibilityString(unsigned Visibility);
 StringRef VirtualityString(unsigned Virtuality);
 StringRef LanguageString(unsigned Language);
Index: clang/test/CodeGenCXX/debug-info-not-defaulted.cpp
===
---

[PATCH] D53768: Add VerboseOutputStream to CompilerInstance

2019-10-01 Thread Scott Linder via Phabricator via cfe-commits
scott.linder added a comment.

Ping


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

https://reviews.llvm.org/D53768



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


[PATCH] D68296: clang-format: Add ability to wrap braces after multi-line control statements

2019-10-01 Thread Mitchell via Phabricator via cfe-commits
mitchell-stellar created this revision.
mitchell-stellar added reviewers: sammccall, owenpan, reuk.
mitchell-stellar added a project: clang-format.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Change the BraceWrappingFlags' AfterControlStatement from a bool to an enum 
with three values:

- "Never": This is the default, and does not do any brace wrapping after 
control statements.
- "OnlyMultiLine": This only wraps braces after multi-line control statements 
(this really only happens when a ColumnLimit is specified).
- "Always": This always wraps braces after control statements.

The first and last options are backwards-compatible with "false" and "true", 
respectively.

The new "OnlyMultiLine" option is useful for when a wrapped control statement's 
indentation matches the subsequent block's indentation. It makes it easier to 
see at a glance where the control statement ends and where the block's code 
begins. For example:

  if (
foo
&& bar )
  {
baz();
  }

vs.

  if (
foo
&& bar ) {
baz();
  }


Repository:
  rC Clang

https://reviews.llvm.org/D68296

Files:
  clang/include/clang/Format/Format.h
  clang/lib/Format/Format.cpp
  clang/lib/Format/UnwrappedLineFormatter.cpp
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/unittests/Format/FormatTest.cpp
  clang/unittests/Format/FormatTestObjC.cpp

Index: clang/unittests/Format/FormatTestObjC.cpp
===
--- clang/unittests/Format/FormatTestObjC.cpp
+++ clang/unittests/Format/FormatTestObjC.cpp
@@ -207,7 +207,7 @@
"  f();\n"
"}\n");
   Style.BreakBeforeBraces = FormatStyle::BS_Custom;
-  Style.BraceWrapping.AfterControlStatement = true;
+  Style.BraceWrapping.AfterControlStatement = FormatStyle::BWACS_Always;
   verifyFormat("@autoreleasepool\n"
"{\n"
"  f();\n"
@@ -237,7 +237,7 @@
"  f();\n"
"}\n");
   Style.BreakBeforeBraces = FormatStyle::BS_Custom;
-  Style.BraceWrapping.AfterControlStatement = true;
+  Style.BraceWrapping.AfterControlStatement = FormatStyle::BWACS_Always;
   verifyFormat("@synchronized(self)\n"
"{\n"
"  f();\n"
Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -644,7 +644,8 @@
   AllowSimpleBracedStatements.AllowShortIfStatementsOnASingleLine =
   FormatStyle::SIS_WithoutElse;
   AllowSimpleBracedStatements.AllowShortLoopsOnASingleLine = true;
-  AllowSimpleBracedStatements.BraceWrapping.AfterControlStatement = true;
+  AllowSimpleBracedStatements.BraceWrapping.AfterControlStatement =
+  FormatStyle::BWACS_Always;
 
   verifyFormat("if (true) {}", AllowSimpleBracedStatements);
   verifyFormat("if constexpr (true) {}", AllowSimpleBracedStatements);
@@ -1168,7 +1169,7 @@
   Style.AllowShortBlocksOnASingleLine = FormatStyle::SBS_Never;
   Style.BreakBeforeBraces = FormatStyle::BS_Custom;
   Style.BraceWrapping.AfterCaseLabel = true;
-  Style.BraceWrapping.AfterControlStatement = true;
+  Style.BraceWrapping.AfterControlStatement = FormatStyle::BWACS_Always;
   EXPECT_EQ("switch (n)\n"
 "{\n"
 "  case 0:\n"
@@ -1370,7 +1371,7 @@
   Style.AllowShortCaseLabelsOnASingleLine = true;
   Style.BreakBeforeBraces = FormatStyle::BS_Custom;
   Style.BraceWrapping.AfterCaseLabel = true;
-  Style.BraceWrapping.AfterControlStatement = true;
+  Style.BraceWrapping.AfterControlStatement = FormatStyle::BWACS_Always;
   EXPECT_EQ("switch (n)\n"
 "{\n"
 "  case 0:\n"
@@ -1441,6 +1442,126 @@
"}");
 }
 
+TEST_F(FormatTest, MultiLineControlStatements) {
+  FormatStyle Style = getLLVMStyle();
+  Style.BreakBeforeBraces = FormatStyle::BraceBreakingStyle::BS_Custom;
+  Style.BraceWrapping.AfterControlStatement = FormatStyle::BWACS_OnlyMultiLine;
+  Style.ColumnLimit = 20;
+  // Short lines should keep opening brace on same line.
+  EXPECT_EQ("if (foo) {\n"
+"  bar();\n"
+"}",
+format("if(foo){bar();}", Style));
+  EXPECT_EQ("if (foo) {\n"
+"  bar();\n"
+"} else {\n"
+"  baz();\n"
+"}",
+format("if(foo){bar();}else{baz();}", Style));
+  EXPECT_EQ("if (foo && bar) {\n"
+"  baz();\n"
+"}",
+format("if(foo&&bar){baz();}", Style));
+  EXPECT_EQ("if (foo) {\n"
+"  bar();\n"
+"} else if (baz) {\n"
+"  quux();\n"
+"}",
+format("if(foo){bar();}else if(baz){quux();}", Style));
+  EXPECT_EQ(
+  "if (foo) {\n"
+  "  bar();\n"
+  "} else if (baz) {\n"
+  "  quux();\n"
+  "} else {\n"
+  "  foobar();\n"
+  "}",
+  format("if(foo){bar();}else if(baz){quux();}else{foobar();}", Style));
+  EXPECT_EQ("for (

[PATCH] D67079: [analyzer] CastValueChecker: Model inheritance

2019-10-01 Thread Csaba Dabis via Phabricator via cfe-commits
Charusso updated this revision to Diff 222685.
Charusso marked an inline comment as done.
Charusso added a comment.

- Use the TU's Decls instead of the gathered casts' Decls.
- The math is still missing.


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

https://reviews.llvm.org/D67079

Files:
  clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/DynamicCastInfo.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/DynamicType.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/DynamicTypeInfo.h
  clang/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp
  clang/lib/StaticAnalyzer/Core/BugReporter.cpp
  clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
  clang/lib/StaticAnalyzer/Core/DynamicType.cpp
  clang/test/Analysis/cast-value-hierarchy-failures-set.cpp
  clang/test/Analysis/cast-value-hierarchy-succeeds.cpp
  clang/test/Analysis/cast-value-hierarchy.cpp
  clang/test/Analysis/cast-value-notes.cpp
  clang/test/Analysis/cast-value-state-dump.cpp
  clang/test/Analysis/expr-inspection.c

Index: clang/test/Analysis/expr-inspection.c
===
--- clang/test/Analysis/expr-inspection.c
+++ clang/test/Analysis/expr-inspection.c
@@ -38,8 +38,8 @@
 // CHECK-NEXT: { "symbol": "reg_$0", "range": "{ [-2147483648, 13] }" }
 // CHECK-NEXT:   ],
 // CHECK-NEXT:   "dynamic_types": null,
-// CHECK-NEXT:   "dynamic_casts": null,
+// CHECK-NEXT:   "succeeded_casts": null,
+// CHECK-NEXT:   "failed_casts": null,
 // CHECK-NEXT:   "constructing_objects": null,
 // CHECK-NEXT:   "checker_messages": null
 // CHECK-NEXT: }
-
Index: clang/test/Analysis/cast-value-state-dump.cpp
===
--- clang/test/Analysis/cast-value-state-dump.cpp
+++ clang/test/Analysis/cast-value-state-dump.cpp
@@ -8,22 +8,27 @@
 
 namespace clang {
 struct Shape {};
-class Triangle : public Shape {};
-class Circle : public Shape {};
-class Square : public Shape {};
+struct Circle : Shape {};
+struct Square : Shape {};
+struct Octagram : Shape {};
 } // namespace clang
 
 using namespace llvm;
 using namespace clang;
 
 void evalNonNullParamNonNullReturn(const Shape *S) {
+  if (isa(S)) {
+// expected-note@-1 {{Assuming 'S' is not a 'Octagram'}}
+// expected-note@-2 {{Taking false branch}}
+return;
+  }
+
   const auto *C = dyn_cast_or_null(S);
   // expected-note@-1 {{Assuming 'S' is a 'Circle'}}
   // expected-note@-2 {{'C' initialized here}}
 
-  // FIXME: We assumed that 'S' is a 'Circle' therefore it is not a 'Square'.
   if (dyn_cast_or_null(S)) {
-// expected-note@-1 {{Assuming 'S' is not a 'Square'}}
+// expected-note@-1 {{'S' is not a 'Square'}}
 // expected-note@-2 {{Taking false branch}}
 return;
   }
@@ -31,13 +36,18 @@
   clang_analyzer_printState();
 
   // CHECK:  "dynamic_types": [
-  // CHECK-NEXT:   { "region": "SymRegion{reg_$0}", "dyn_type": "const class clang::Circle", "sub_classable": true }
+  // CHECK-NEXT:   { "region": "SymRegion{reg_$0}", "dyn_type": "const struct clang::Circle", "sub_classable": true }
   // CHECK-NEXT: ],
-  // CHECK-NEXT: "dynamic_casts": [
-  // CHECK:{ "region": "SymRegion{reg_$0}", "casts": [
-  // CHECK-NEXT: { "from": "const struct clang::Shape *", "to": "const class clang::Circle *", "kind": "success" },
-  // CHECK-NEXT: { "from": "const struct clang::Shape *", "to": "const class clang::Square *", "kind": "fail" }
+  // CHECK-NEXT: "succeeded_casts": [
+  // CHECK-NEXT:   { "region": "SymRegion{reg_$0}", "casts": [
+  // CHECK-NEXT: "const struct clang::Circle *"
   // CHECK-NEXT:   ]}
+  // CHECK-NEXT: ],
+  // CHECK-NEXT: "failed_casts": [
+  // CHECK-NEXT:   { "region": "SymRegion{reg_$0}", "casts": [
+  // CHECK-NEXT: "const struct clang::Square *", "struct clang::Octagram *"
+  // CHECK-NEXT:   ]}
+  // CHECK-NEXT: ],
 
   (void)(1 / !C);
   // expected-note@-1 {{'C' is non-null}}
Index: clang/test/Analysis/cast-value-notes.cpp
===
--- clang/test/Analysis/cast-value-notes.cpp
+++ clang/test/Analysis/cast-value-notes.cpp
@@ -12,8 +12,8 @@
   template 
   const T *getAs() const;
 };
-class Triangle : public Shape {};
-class Circle : public Shape {};
+struct Triangle : Shape {};
+struct Circle : Shape {};
 } // namespace clang
 
 using namespace llvm;
@@ -37,12 +37,6 @@
 return;
   }
 
-  if (dyn_cast_or_null(C)) {
-// expected-note@-1 {{Assuming 'C' is not a 'Triangle'}}
-// expected-note@-2 {{Taking false branch}}
-return;
-  }
-
   if (isa(C)) {
 // expected-note@-1 {{'C' is not a 'Triangle'}}
 // expected-note@-2 {{Taking false branch}}
@@ -65,14 +59,8 @@
   // expected-note@-1 {{'S' is a 'Circle'}}
   // expected-note@-2 {{'C' initialized here}}
 
-  if (!isa(C)) {
-

[PATCH] D68227: [clang-format] [PR43372] - clang-format shows replacements in DOS files when no replacement is needed

2019-10-01 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL373388: [clang-format] [PR43372] - clang-format shows 
replacements in DOS files when no… (authored by paulhoad, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D68227?vs=222665&id=222683#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D68227

Files:
  cfe/trunk/lib/Format/Format.cpp
  cfe/trunk/unittests/Format/SortImportsTestJava.cpp
  cfe/trunk/unittests/Format/SortIncludesTest.cpp


Index: cfe/trunk/lib/Format/Format.cpp
===
--- cfe/trunk/lib/Format/Format.cpp
+++ cfe/trunk/lib/Format/Format.cpp
@@ -1825,6 +1825,28 @@
   return std::make_pair(CursorIndex, OffsetToEOL);
 }
 
+// Replace all "\r\n" with "\n".
+std::string replaceCRLF(const std::string &Code) {
+  std::string NewCode;
+  size_t Pos = 0, LastPos = 0;
+
+  do {
+Pos = Code.find("\r\n", LastPos);
+if (Pos == LastPos) {
+  LastPos++;
+  continue;
+}
+if (Pos == std::string::npos) {
+  NewCode += Code.substr(LastPos);
+  break;
+}
+NewCode += Code.substr(LastPos, Pos - LastPos) + "\n";
+LastPos = Pos + 2;
+  } while (Pos != std::string::npos);
+
+  return NewCode;
+}
+
 // Sorts and deduplicate a block of includes given by 'Includes' alphabetically
 // adding the necessary replacement to 'Replaces'. 'Includes' must be in strict
 // source order.
@@ -1898,7 +1920,8 @@
 
   // If the #includes are out of order, we generate a single replacement fixing
   // the entire range of blocks. Otherwise, no replacement is generated.
-  if (result == Code.substr(IncludesBeginOffset, IncludesBlockSize))
+  if (replaceCRLF(result) ==
+  replaceCRLF(Code.substr(IncludesBeginOffset, IncludesBlockSize)))
 return;
 
   auto Err = Replaces.add(tooling::Replacement(
@@ -2066,7 +2089,8 @@
 
   // If the imports are out of order, we generate a single replacement fixing
   // the entire block. Otherwise, no replacement is generated.
-  if (result == Code.substr(Imports.front().Offset, ImportsBlockSize))
+  if (replaceCRLF(result) ==
+  replaceCRLF(Code.substr(Imports.front().Offset, ImportsBlockSize)))
 return;
 
   auto Err = Replaces.add(tooling::Replacement(FileName, 
Imports.front().Offset,
@@ -2356,7 +2380,7 @@
 
   auto Env =
   std::make_unique(Code, FileName, Ranges, FirstStartColumn,
- NextStartColumn, LastStartColumn);
+NextStartColumn, LastStartColumn);
   llvm::Optional CurrentCode = None;
   tooling::Replacements Fixes;
   unsigned Penalty = 0;
Index: cfe/trunk/unittests/Format/SortIncludesTest.cpp
===
--- cfe/trunk/unittests/Format/SortIncludesTest.cpp
+++ cfe/trunk/unittests/Format/SortIncludesTest.cpp
@@ -724,6 +724,14 @@
   EXPECT_EQ(Code, sort(Code, "input.h", 0));
 }
 
+TEST_F(SortIncludesTest,
+   DoNotOutputReplacementsForSortedBlocksWithRegroupingWindows) {
+  Style.IncludeBlocks = Style.IBS_Regroup;
+  std::string Code = "#include \"b.h\"\r\n"
+ "\r\n"
+ "#include \r\n";
+  EXPECT_EQ(Code, sort(Code, "input.h", 0));
+}
 
 TEST_F(SortIncludesTest, DoNotRegroupGroupsInGoogleObjCStyle) {
   FmtStyle = getGoogleStyle(FormatStyle::LK_ObjC);
Index: cfe/trunk/unittests/Format/SortImportsTestJava.cpp
===
--- cfe/trunk/unittests/Format/SortImportsTestJava.cpp
+++ cfe/trunk/unittests/Format/SortImportsTestJava.cpp
@@ -285,6 +285,13 @@
   sortIncludes(FmtStyle, Code, GetCodeRange(Code), "input.java").empty());
 }
 
+TEST_F(SortImportsTestJava, NoReplacementsForValidImportsWindows) {
+  std::string Code = "import org.a;\r\n"
+ "import org.b;\r\n";
+  EXPECT_TRUE(
+  sortIncludes(FmtStyle, Code, GetCodeRange(Code), "input.java").empty());
+}
+
 } // end namespace
 } // end namespace format
 } // end namespace clang


Index: cfe/trunk/lib/Format/Format.cpp
===
--- cfe/trunk/lib/Format/Format.cpp
+++ cfe/trunk/lib/Format/Format.cpp
@@ -1825,6 +1825,28 @@
   return std::make_pair(CursorIndex, OffsetToEOL);
 }
 
+// Replace all "\r\n" with "\n".
+std::string replaceCRLF(const std::string &Code) {
+  std::string NewCode;
+  size_t Pos = 0, LastPos = 0;
+
+  do {
+Pos = Code.find("\r\n", LastPos);
+if (Pos == LastPos) {
+  LastPos++;
+  continue;
+}
+if (Pos == std::string::npos) {
+  NewCode += Code.substr(LastPos);
+  break;
+}
+NewCode += Code.substr(LastPos, Pos - LastPos) + "\n";
+LastPos = Pos + 2;
+  } while (Pos != std::string::npos);
+
+  return NewCode;
+}
+
 // Sorts and deduplicate a block of includes 

r373388 - [clang-format] [PR43372] - clang-format shows replacements in DOS files when no replacement is needed

2019-10-01 Thread Paul Hoad via cfe-commits
Author: paulhoad
Date: Tue Oct  1 13:20:22 2019
New Revision: 373388

URL: http://llvm.org/viewvc/llvm-project?rev=373388&view=rev
Log:
[clang-format] [PR43372] - clang-format shows replacements in DOS files when no 
replacement is needed

Summary:
This is a patch to fix PR43372 (https://bugs.llvm.org/show_bug.cgi?id=43372) - 
clang-format can't format file with includes, ( which really keep providing 
replacements for already sorted headers.)

A similar issue was addressed by @krasimir in {D60199}, however, this seemingly 
only prevented the issue when the files being formatted did not contain windows 
line endings (\r\n)

It's possible this is related to 
https://twitter.com/StephanTLavavej/status/1176722938243895296 given who 
@STL_MSFT  works for!

As people often used the existence of replacements to determine if a file needs 
clang-formatting, this is probably pretty important for windows users

There may be a better way of comparing 2 strings and ignoring \r (which appear 
in both Results and Code), I couldn't choose between this idiom or the copy_if 
approach, but I'm happy to change it to whatever people consider more 
performant.

Reviewers: krasimir, klimek, owenpan, ioeric

Reviewed By: krasimir

Subscribers: cfe-commits, STL_MSFT, krasimir

Tags: #clang-format, #clang, #clang-tools-extra

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

Modified:
cfe/trunk/lib/Format/Format.cpp
cfe/trunk/unittests/Format/SortImportsTestJava.cpp
cfe/trunk/unittests/Format/SortIncludesTest.cpp

Modified: cfe/trunk/lib/Format/Format.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=373388&r1=373387&r2=373388&view=diff
==
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Tue Oct  1 13:20:22 2019
@@ -1825,6 +1825,28 @@ FindCursorIndex(const SmallVectorImpl(Code, FileName, Ranges, FirstStartColumn,
- NextStartColumn, LastStartColumn);
+NextStartColumn, LastStartColumn);
   llvm::Optional CurrentCode = None;
   tooling::Replacements Fixes;
   unsigned Penalty = 0;

Modified: cfe/trunk/unittests/Format/SortImportsTestJava.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/SortImportsTestJava.cpp?rev=373388&r1=373387&r2=373388&view=diff
==
--- cfe/trunk/unittests/Format/SortImportsTestJava.cpp (original)
+++ cfe/trunk/unittests/Format/SortImportsTestJava.cpp Tue Oct  1 13:20:22 2019
@@ -285,6 +285,13 @@ TEST_F(SortImportsTestJava, NoReplacemen
   sortIncludes(FmtStyle, Code, GetCodeRange(Code), "input.java").empty());
 }
 
+TEST_F(SortImportsTestJava, NoReplacementsForValidImportsWindows) {
+  std::string Code = "import org.a;\r\n"
+ "import org.b;\r\n";
+  EXPECT_TRUE(
+  sortIncludes(FmtStyle, Code, GetCodeRange(Code), "input.java").empty());
+}
+
 } // end namespace
 } // end namespace format
 } // end namespace clang

Modified: cfe/trunk/unittests/Format/SortIncludesTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/SortIncludesTest.cpp?rev=373388&r1=373387&r2=373388&view=diff
==
--- cfe/trunk/unittests/Format/SortIncludesTest.cpp (original)
+++ cfe/trunk/unittests/Format/SortIncludesTest.cpp Tue Oct  1 13:20:22 2019
@@ -724,6 +724,14 @@ TEST_F(SortIncludesTest, DoNotOutputRepl
   EXPECT_EQ(Code, sort(Code, "input.h", 0));
 }
 
+TEST_F(SortIncludesTest,
+   DoNotOutputReplacementsForSortedBlocksWithRegroupingWindows) {
+  Style.IncludeBlocks = Style.IBS_Regroup;
+  std::string Code = "#include \"b.h\"\r\n"
+ "\r\n"
+ "#include \r\n";
+  EXPECT_EQ(Code, sort(Code, "input.h", 0));
+}
 
 TEST_F(SortIncludesTest, DoNotRegroupGroupsInGoogleObjCStyle) {
   FmtStyle = getGoogleStyle(FormatStyle::LK_ObjC);


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


r373387 - [OPENMP50]Initial codegen for declare variant implementation vendor.

2019-10-01 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Tue Oct  1 13:18:32 2019
New Revision: 373387

URL: http://llvm.org/viewvc/llvm-project?rev=373387&view=rev
Log:
[OPENMP50]Initial codegen for declare variant implementation vendor.

Initial implementation of global aliases emission for the declare
variant pragma with implementation vendor context selector set.

Added:
cfe/trunk/test/OpenMP/declare_variant_implementation_vendor_codegen.cpp
Modified:
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.h
cfe/trunk/lib/CodeGen/CodeGenModule.cpp

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp?rev=373387&r1=373386&r2=373387&view=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp Tue Oct  1 13:18:32 2019
@@ -1264,6 +1264,51 @@ CGOpenMPRuntime::CGOpenMPRuntime(CodeGen
   loadOffloadInfoMetadata();
 }
 
+static bool tryEmitAlias(CodeGenModule &CGM, const GlobalDecl &NewGD,
+ const GlobalDecl &OldGD, llvm::GlobalValue *OrigAddr,
+ bool IsForDefinition) {
+  // Emit at least a definition for the aliasee if the the address of the
+  // original function is requested.
+  if (IsForDefinition || OrigAddr)
+(void)CGM.GetAddrOfGlobal(NewGD);
+  StringRef NewMangledName = CGM.getMangledName(NewGD);
+  llvm::GlobalValue *Addr = CGM.GetGlobalValue(NewMangledName);
+  if (Addr && !Addr->isDeclaration()) {
+const auto *D = cast(OldGD.getDecl());
+const CGFunctionInfo &FI = CGM.getTypes().arrangeGlobalDeclaration(OldGD);
+llvm::Type *DeclTy = CGM.getTypes().GetFunctionType(FI);
+
+// Create a reference to the named value.  This ensures that it is emitted
+// if a deferred decl.
+llvm::GlobalValue::LinkageTypes LT = CGM.getFunctionLinkage(OldGD);
+
+// Create the new alias itself, but don't set a name yet.
+auto *GA =
+llvm::GlobalAlias::create(DeclTy, 0, LT, "", Addr, &CGM.getModule());
+
+if (OrigAddr) {
+  assert(OrigAddr->isDeclaration() && "Expected declaration");
+
+  GA->takeName(OrigAddr);
+  OrigAddr->replaceAllUsesWith(
+  llvm::ConstantExpr::getBitCast(GA, OrigAddr->getType()));
+  OrigAddr->eraseFromParent();
+} else {
+  GA->setName(CGM.getMangledName(OldGD));
+}
+
+// Set attributes which are particular to an alias; this is a
+// specialization of the attributes which may be set on a global function.
+if (D->hasAttr() || D->hasAttr() ||
+D->isWeakImported())
+  GA->setLinkage(llvm::Function::WeakAnyLinkage);
+
+CGM.SetCommonAttributes(OldGD, GA);
+return true;
+  }
+  return false;
+}
+
 void CGOpenMPRuntime::clear() {
   InternalVars.clear();
   // Clean non-target variable declarations possibly used only in debug info.
@@ -1277,6 +1322,14 @@ void CGOpenMPRuntime::clear() {
   continue;
 GV->eraseFromParent();
   }
+  // Emit aliases for the deferred aliasees.
+  for (const auto &Pair : DeferredVariantFunction) {
+StringRef MangledName = CGM.getMangledName(Pair.second.second);
+llvm::GlobalValue *Addr = CGM.GetGlobalValue(MangledName);
+// If not able to emit alias, just emit original declaration.
+(void)tryEmitAlias(CGM, Pair.second.first, Pair.second.second, Addr,
+   /*IsForDefinition=*/false);
+  }
 }
 
 std::string CGOpenMPRuntime::getName(ArrayRef Parts) const {
@@ -11086,6 +11139,80 @@ Address CGOpenMPRuntime::getAddressOfLoc
   return Address(Addr, Align);
 }
 
+/// Checks current context and returns true if it matches the context selector.
+template 
+static bool checkContext(const OMPDeclareVariantAttr *A) {
+  assert(CtxSet != OMPDeclareVariantAttr::CtxSetUnknown &&
+ Ctx != OMPDeclareVariantAttr::CtxUnknown &&
+ "Unknown context selector or context selector set.");
+  return false;
+}
+
+/// Checks for implementation={vendor()} context selector.
+/// \returns true iff ="llvm", false otherwise.
+template <>
+bool checkContext(
+const OMPDeclareVariantAttr *A) {
+  return !A->getImplVendor().compare("llvm");
+}
+
+/// Finds the variant function that matches current context with its context
+/// selector.
+static const FunctionDecl *getDeclareVariantFunction(const FunctionDecl *FD) {
+  if (!FD->hasAttrs() || !FD->hasAttr())
+return FD;
+  // Iterate through all DeclareVariant attributes and check context selectors.
+  SmallVector MatchingAttributes;
+  for (const auto * A : FD->specific_attrs()) {
+switch (A->getCtxSelectorSet()) {
+case OMPDeclareVariantAttr::CtxSetImplementation:
+  switch (A->getCtxSelector()) {
+  case OMPDeclareVariantAttr::CtxVendor:
+if (checkContext(A))
+  MatchingAttributes.push_back(A);
+break;
+  case OMPDeclareVariantAttr::CtxUnknown:
+llvm_unreachable(
+   

[PATCH] D62686: [RISCV] Add support for save/restore of callee-saved registers via libcalls

2019-10-01 Thread Ana Pazos via Phabricator via cfe-commits
apazos added a comment.

Thanks for the patch update. I will launch some new correctness runs.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D62686



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


[PATCH] D67706: [clang][analyzer] Using CallDescription in StreamChecker.

2019-10-01 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp:60-61
 private:
-  void Fopen(CheckerContext &C, const CallExpr *CE) const;
-  void Tmpfile(CheckerContext &C, const CallExpr *CE) const;
-  void Fclose(CheckerContext &C, const CallExpr *CE) const;
-  void Fread(CheckerContext &C, const CallExpr *CE) const;
-  void Fwrite(CheckerContext &C, const CallExpr *CE) const;
-  void Fseek(CheckerContext &C, const CallExpr *CE) const;
-  void Ftell(CheckerContext &C, const CallExpr *CE) const;
-  void Rewind(CheckerContext &C, const CallExpr *CE) const;
-  void Fgetpos(CheckerContext &C, const CallExpr *CE) const;
-  void Fsetpos(CheckerContext &C, const CallExpr *CE) const;
-  void Clearerr(CheckerContext &C, const CallExpr *CE) const;
-  void Feof(CheckerContext &C, const CallExpr *CE) const;
-  void Ferror(CheckerContext &C, const CallExpr *CE) const;
-  void Fileno(CheckerContext &C, const CallExpr *CE) const;
-
-  void OpenFileAux(CheckerContext &C, const CallExpr *CE) const;
-
-  ProgramStateRef CheckNullStream(SVal SV, ProgramStateRef state,
- CheckerContext &C) const;
-  ProgramStateRef CheckDoubleClose(const CallExpr *CE, ProgramStateRef state,
- CheckerContext &C) const;
+  typedef void (StreamChecker::*FnCheck)(const CallEvent &,
+ CheckerContext &) const;
+

Szelethus wrote:
> Prefer using. When I wrote D68165, I spent about 10 minutes figuring out how 
> to do it... Ah, the joys of the C++ syntax.
> ```lang=c++
> using FnCheck = void (StreamChecker::*)(const CallEvent &,
> CheckerContext &) const;
> ```
It's actually very easy to remember, it's just an alien kiss smiley ::*)



Comment at: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp:127-131
+  for (auto P : Call.parameters()) {
+QualType T = P->getType();
+if (!T->isIntegralOrEnumerationType() && !T->isPointerType())
+  return nullptr;
+  }

balazske wrote:
> Szelethus wrote:
> > Szelethus wrote:
> > > balazske wrote:
> > > > Szelethus wrote:
> > > > > I'm not sure why we need this, is it true that *all* stream related 
> > > > > functions return a pointer or a numerical value? Are we actually 
> > > > > checking whether this really is a library function? If so, this looks 
> > > > > pretty arbitrary.
> > > > This comes from code of CStringChecker:
> > > > ```
> > > >   // Pro-actively check that argument types are safe to do arithmetic 
> > > > upon.
> > > >   // We do not want to crash if someone accidentally passes a structure
> > > >   // into, say, a C++ overload of any of these functions. We could not 
> > > > check
> > > >   // that for std::copy because they may have arguments of other types.
> > > > ```
> > > > Still I am not sure that the checker works correct with code that 
> > > > contains similar named but "arbitrary" functions.
> > > Oops, meant to write that ", is it true that *all* stream related 
> > > functions have only pointer or a numerical parameters?".
> > ...and removing this one, or changing it to an assert?
> This can not be an assert because it is possible to have global functions 
> with same name but different signature. The check can be kept to filter out 
> such cases. The wanted stream functions have only integral or enum or pointer 
> arguments.
Clang shouldn't crash even when the library definition is incorrect.



Comment at: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp:156
+void StreamChecker::evalFread(const CallEvent &Call, CheckerContext &C) const {
+  (void)CheckNullStream(Call.getArgSVal(3), C);
 }

Szelethus wrote:
> balazske wrote:
> > Szelethus wrote:
> > > Why the need for `(void)`? `CheckNullSteam` doesn't seem to have an 
> > > `LLVM_NODISCARD` attribute.
> > I wanted to be sure to get no buildbot compile errors (where -Werror is 
> > used).
> They actually break on this?? Let me guess, is it the windows one? :D
I'd rather not discard the return value, but allow callbacks indicate an error 
when something goes wrong, so that to allow them to abort `evalCall()`. 

But more importantly, note how `CheckNullStream` actually returns a 
`ProgramStateRef` that was meant to be transitioned into. Which means that the 
primary execution path actually gets cut off.

So even if buildbots didn't warn on this, i wish they did.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D67706



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


[PATCH] D68193: In openFileForRead don't cache erroneous entries if the error relates to them being directories. Add tests.

2019-10-01 Thread Kousik Kumar via Phabricator via cfe-commits
kousikk updated this revision to Diff 222669.
kousikk added a comment.

Add missed const


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D68193

Files:
  clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h
  clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp

Index: clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
===
--- clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
+++ clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
@@ -15,22 +15,19 @@
 using namespace tooling;
 using namespace dependencies;
 
+
 CachedFileSystemEntry CachedFileSystemEntry::createFileEntry(
-StringRef Filename, llvm::vfs::FileSystem &FS, bool Minimize) {
+llvm::vfs::Status &&Stat, llvm::vfs::FileSystem &FS, bool Minimize) {
   // Load the file and its content from the file system.
+  StringRef Filename = Stat.getName();
   llvm::ErrorOr> MaybeFile =
   FS.openFileForRead(Filename);
   if (!MaybeFile)
 return MaybeFile.getError();
-  llvm::ErrorOr Stat = (*MaybeFile)->status();
-  if (!Stat)
-return Stat.getError();
-  if (Stat->isDirectory())
-return std::make_error_code(std::errc::is_a_directory);
 
   llvm::vfs::File &F = **MaybeFile;
   llvm::ErrorOr> MaybeBuffer =
-  F.getBuffer(Stat->getName());
+  F.getBuffer(Filename);
   if (!MaybeBuffer)
 return MaybeBuffer.getError();
 
@@ -44,7 +41,7 @@
 // if the minimization failed.
 // FIXME: Propage the diagnostic if desired by the client.
 CachedFileSystemEntry Result;
-Result.MaybeStat = std::move(*Stat);
+Result.MaybeStat = Stat;
 Result.Contents.reserve(Buffer->getBufferSize() + 1);
 Result.Contents.append(Buffer->getBufferStart(), Buffer->getBufferEnd());
 // Implicitly null terminate the contents for Clang's lexer.
@@ -55,10 +52,10 @@
 
   CachedFileSystemEntry Result;
   size_t Size = MinimizedFileContents.size();
-  Result.MaybeStat = llvm::vfs::Status(Stat->getName(), Stat->getUniqueID(),
-   Stat->getLastModificationTime(),
-   Stat->getUser(), Stat->getGroup(), Size,
-   Stat->getType(), Stat->getPermissions());
+  Result.MaybeStat = llvm::vfs::Status(Stat.getName(), Stat.getUniqueID(),
+   Stat.getLastModificationTime(),
+   Stat.getUser(), Stat.getGroup(), Size,
+   Stat.getType(), Stat.getPermissions());
   // The contents produced by the minimizer must be null terminated.
   assert(MinimizedFileContents.data()[MinimizedFileContents.size()] == '\0' &&
  "not null terminated contents");
@@ -124,14 +121,11 @@
   return It.first->getValue();
 }
 
-llvm::ErrorOr
-DependencyScanningWorkerFilesystem::status(const Twine &Path) {
-  SmallString<256> OwnedFilename;
-  StringRef Filename = Path.toStringRef(OwnedFilename);
-
-  // Check the local cache first.
-  if (const CachedFileSystemEntry *Entry = getCachedEntry(Filename))
-return Entry->getStatus();
+llvm::ErrorOr
+DependencyScanningWorkerFilesystem::getOrCreateFileSystemEntry(const StringRef Filename) {
+  if (const CachedFileSystemEntry* Entry = getCachedEntry(Filename)) {
+return Entry;
+  }
 
   // FIXME: Handle PCM/PCH files.
   // FIXME: Handle module map files.
@@ -154,7 +148,7 @@
 std::move(*MaybeStatus));
   else
 CacheEntry = CachedFileSystemEntry::createFileEntry(
-Filename, FS, !KeepOriginalSource);
+std::move(*MaybeStatus), FS, !KeepOriginalSource);
 }
 
 Result = &CacheEntry;
@@ -162,7 +156,17 @@
 
   // Store the result in the local cache.
   setCachedEntry(Filename, Result);
-  return Result->getStatus();
+  return Result;
+}
+
+llvm::ErrorOr
+DependencyScanningWorkerFilesystem::status(const Twine &Path) {
+  SmallString<256> OwnedFilename;
+  StringRef Filename = Path.toStringRef(OwnedFilename);
+  const llvm::ErrorOr Result = getOrCreateFileSystemEntry(Filename);
+  if (!Result)
+return Result.getError();
+  return (*Result)->getStatus();
 }
 
 namespace {
@@ -219,36 +223,8 @@
   SmallString<256> OwnedFilename;
   StringRef Filename = Path.toStringRef(OwnedFilename);
 
-  // Check the local cache first.
-  if (const CachedFileSystemEntry *Entry = getCachedEntry(Filename))
-return createFile(Entry, PPSkipMappings);
-
-  // FIXME: Handle PCM/PCH files.
-  // FIXME: Handle module map files.
-
-  bool KeepOriginalSource = IgnoredFiles.count(Filename);
-  DependencyScanningFilesystemSharedCache::SharedFileSystemEntry
-  &SharedCacheEntry = SharedCache.get(Filename);
-  const CachedFileSystemEntry *Result;
-  {
-std::unique_lock LockGuard(SharedCacheEntry.ValueLock);
-CachedFileSystemEntry &Cach

[PATCH] D68227: [clang-format] [PR43372] - clang-format shows replacements in DOS files when no replacement is needed

2019-10-01 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir accepted this revision.
krasimir added a comment.
This revision is now accepted and ready to land.

Thank you!


Repository:
  rC Clang

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

https://reviews.llvm.org/D68227



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


[PATCH] D68193: In openFileForRead don't cache erroneous entries if the error relates to them being directories. Add tests.

2019-10-01 Thread Kousik Kumar via Phabricator via cfe-commits
kousikk added a comment.

In D68193#1688838 , @dexonsmith wrote:

> Sorry for bouncing you around, but I just had a look at the other user of 
> `createFileEntry` and I think the right thing to do is to somehow share the 
> code between `DependencyScanningWorkerFilesystem::status` and this.  I 
> suggest splitting a function out of `status` (called 
> `getOrCreateFileSystemEntry`?) that returns a `CachedFileSystemEntry` (or an 
> error).
>
> The fix I just asked you to make (to only call `stat` once) could be done on 
> `getOrCreateFileSystemEntry` as a follow-up, using 
> `std::unique_ptr` and changing `getFileEntry` to take that 
> instead of a filename.


IIUC, 
`DependencyScanningWorkerFilesystem::status()` and 
`DependencyScanningWorkerFilesystem::openFileForRead()` both inturn call into 
`CachedFileSystemEntry::createFileEntry()`.

Given that, I made `getOrCreateFileEntry()` a private-member of 
`DependencyScanningWorkerFilesystem` and made both these functions use it first.

In a subsequent step, I passed in `llvm::vfs::Status` object to 
`createFileEntry()` instead of `Filename`. I hope this aligns with the 
code-organization you are looking for. Let me know if this aligns with how you 
wanted the code to look (happy to re-write if not).

I also ran it against a canonical set of tests I'm maintaining internally and I 
didn't notice a difference in either performance and didn't get new crashes of 
the tool, so I think there should NOT be any regressions because of this change.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D68193



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


[PATCH] D68193: In openFileForRead don't cache erroneous entries if the error relates to them being directories. Add tests.

2019-10-01 Thread Kousik Kumar via Phabricator via cfe-commits
kousikk updated this revision to Diff 222667.
kousikk marked an inline comment as done.
kousikk added a comment.

Address code-reorg comment


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D68193

Files:
  clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h
  clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp

Index: clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
===
--- clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
+++ clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
@@ -15,22 +15,19 @@
 using namespace tooling;
 using namespace dependencies;
 
+
 CachedFileSystemEntry CachedFileSystemEntry::createFileEntry(
-StringRef Filename, llvm::vfs::FileSystem &FS, bool Minimize) {
+llvm::vfs::Status &&Stat, llvm::vfs::FileSystem &FS, bool Minimize) {
   // Load the file and its content from the file system.
+  StringRef Filename = Stat.getName();
   llvm::ErrorOr> MaybeFile =
   FS.openFileForRead(Filename);
   if (!MaybeFile)
 return MaybeFile.getError();
-  llvm::ErrorOr Stat = (*MaybeFile)->status();
-  if (!Stat)
-return Stat.getError();
-  if (Stat->isDirectory())
-return std::make_error_code(std::errc::is_a_directory);
 
   llvm::vfs::File &F = **MaybeFile;
   llvm::ErrorOr> MaybeBuffer =
-  F.getBuffer(Stat->getName());
+  F.getBuffer(Filename);
   if (!MaybeBuffer)
 return MaybeBuffer.getError();
 
@@ -44,7 +41,7 @@
 // if the minimization failed.
 // FIXME: Propage the diagnostic if desired by the client.
 CachedFileSystemEntry Result;
-Result.MaybeStat = std::move(*Stat);
+Result.MaybeStat = Stat;
 Result.Contents.reserve(Buffer->getBufferSize() + 1);
 Result.Contents.append(Buffer->getBufferStart(), Buffer->getBufferEnd());
 // Implicitly null terminate the contents for Clang's lexer.
@@ -55,10 +52,10 @@
 
   CachedFileSystemEntry Result;
   size_t Size = MinimizedFileContents.size();
-  Result.MaybeStat = llvm::vfs::Status(Stat->getName(), Stat->getUniqueID(),
-   Stat->getLastModificationTime(),
-   Stat->getUser(), Stat->getGroup(), Size,
-   Stat->getType(), Stat->getPermissions());
+  Result.MaybeStat = llvm::vfs::Status(Stat.getName(), Stat.getUniqueID(),
+   Stat.getLastModificationTime(),
+   Stat.getUser(), Stat.getGroup(), Size,
+   Stat.getType(), Stat.getPermissions());
   // The contents produced by the minimizer must be null terminated.
   assert(MinimizedFileContents.data()[MinimizedFileContents.size()] == '\0' &&
  "not null terminated contents");
@@ -124,14 +121,11 @@
   return It.first->getValue();
 }
 
-llvm::ErrorOr
-DependencyScanningWorkerFilesystem::status(const Twine &Path) {
-  SmallString<256> OwnedFilename;
-  StringRef Filename = Path.toStringRef(OwnedFilename);
-
-  // Check the local cache first.
-  if (const CachedFileSystemEntry *Entry = getCachedEntry(Filename))
-return Entry->getStatus();
+llvm::ErrorOr
+DependencyScanningWorkerFilesystem::getOrCreateFileSystemEntry(const StringRef Filename) {
+  if (const CachedFileSystemEntry* Entry = getCachedEntry(Filename)) {
+return Entry;
+  }
 
   // FIXME: Handle PCM/PCH files.
   // FIXME: Handle module map files.
@@ -139,7 +133,7 @@
   bool KeepOriginalSource = IgnoredFiles.count(Filename);
   DependencyScanningFilesystemSharedCache::SharedFileSystemEntry
   &SharedCacheEntry = SharedCache.get(Filename);
-  const CachedFileSystemEntry *Result;
+  CachedFileSystemEntry *Result;
   {
 std::unique_lock LockGuard(SharedCacheEntry.ValueLock);
 CachedFileSystemEntry &CacheEntry = SharedCacheEntry.Value;
@@ -154,7 +148,7 @@
 std::move(*MaybeStatus));
   else
 CacheEntry = CachedFileSystemEntry::createFileEntry(
-Filename, FS, !KeepOriginalSource);
+std::move(*MaybeStatus), FS, !KeepOriginalSource);
 }
 
 Result = &CacheEntry;
@@ -162,7 +156,17 @@
 
   // Store the result in the local cache.
   setCachedEntry(Filename, Result);
-  return Result->getStatus();
+  return Result;
+}
+
+llvm::ErrorOr
+DependencyScanningWorkerFilesystem::status(const Twine &Path) {
+  SmallString<256> OwnedFilename;
+  StringRef Filename = Path.toStringRef(OwnedFilename);
+  const llvm::ErrorOr Result = getOrCreateFileSystemEntry(Filename);
+  if (!Result)
+return Result.getError();
+  return (*Result)->getStatus();
 }
 
 namespace {
@@ -219,36 +223,8 @@
   SmallString<256> OwnedFilename;
   StringRef Filename = Path.toStringRef(OwnedFilename);
 
-  // Check the local cache first.
-  if (const CachedFileSystemEntry *Entry = getCachedEn

[PATCH] D68227: [clang-format] [PR43372] - clang-format shows replacements in DOS files when no replacement is needed

2019-10-01 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay updated this revision to Diff 222665.
MyDeveloperDay set the repository for this revision to rC Clang.
MyDeveloperDay added a project: clang-tools-extra.

Repository:
  rC Clang

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

https://reviews.llvm.org/D68227

Files:
  clang/lib/Format/Format.cpp
  clang/unittests/Format/SortImportsTestJava.cpp
  clang/unittests/Format/SortIncludesTest.cpp


Index: clang/unittests/Format/SortIncludesTest.cpp
===
--- clang/unittests/Format/SortIncludesTest.cpp
+++ clang/unittests/Format/SortIncludesTest.cpp
@@ -724,6 +724,14 @@
   EXPECT_EQ(Code, sort(Code, "input.h", 0));
 }
 
+TEST_F(SortIncludesTest,
+   DoNotOutputReplacementsForSortedBlocksWithRegroupingWindows) {
+  Style.IncludeBlocks = Style.IBS_Regroup;
+  std::string Code = "#include \"b.h\"\r\n"
+ "\r\n"
+ "#include \r\n";
+  EXPECT_EQ(Code, sort(Code, "input.h", 0));
+}
 
 TEST_F(SortIncludesTest, DoNotRegroupGroupsInGoogleObjCStyle) {
   FmtStyle = getGoogleStyle(FormatStyle::LK_ObjC);
Index: clang/unittests/Format/SortImportsTestJava.cpp
===
--- clang/unittests/Format/SortImportsTestJava.cpp
+++ clang/unittests/Format/SortImportsTestJava.cpp
@@ -285,6 +285,13 @@
   sortIncludes(FmtStyle, Code, GetCodeRange(Code), "input.java").empty());
 }
 
+TEST_F(SortImportsTestJava, NoReplacementsForValidImportsWindows) {
+  std::string Code = "import org.a;\r\n"
+ "import org.b;\r\n";
+  EXPECT_TRUE(
+  sortIncludes(FmtStyle, Code, GetCodeRange(Code), "input.java").empty());
+}
+
 } // end namespace
 } // end namespace format
 } // end namespace clang
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -1825,6 +1825,28 @@
   return std::make_pair(CursorIndex, OffsetToEOL);
 }
 
+// Replace all "\r\n" with "\n".
+std::string replaceCRLF(const std::string &Code) {
+  std::string NewCode;
+  size_t Pos = 0, LastPos = 0;
+
+  do {
+Pos = Code.find("\r\n", LastPos);
+if (Pos == LastPos) {
+  LastPos++;
+  continue;
+}
+if (Pos == std::string::npos) {
+  NewCode += Code.substr(LastPos);
+  break;
+}
+NewCode += Code.substr(LastPos, Pos - LastPos) + "\n";
+LastPos = Pos + 2;
+  } while (Pos != std::string::npos);
+
+  return NewCode;
+}
+
 // Sorts and deduplicate a block of includes given by 'Includes' alphabetically
 // adding the necessary replacement to 'Replaces'. 'Includes' must be in strict
 // source order.
@@ -1898,7 +1920,8 @@
 
   // If the #includes are out of order, we generate a single replacement fixing
   // the entire range of blocks. Otherwise, no replacement is generated.
-  if (result == Code.substr(IncludesBeginOffset, IncludesBlockSize))
+  if (replaceCRLF(result) ==
+  replaceCRLF(Code.substr(IncludesBeginOffset, IncludesBlockSize)))
 return;
 
   auto Err = Replaces.add(tooling::Replacement(
@@ -2066,7 +2089,8 @@
 
   // If the imports are out of order, we generate a single replacement fixing
   // the entire block. Otherwise, no replacement is generated.
-  if (result == Code.substr(Imports.front().Offset, ImportsBlockSize))
+  if (replaceCRLF(result) ==
+  replaceCRLF(Code.substr(Imports.front().Offset, ImportsBlockSize)))
 return;
 
   auto Err = Replaces.add(tooling::Replacement(FileName, 
Imports.front().Offset,
@@ -2356,7 +2380,7 @@
 
   auto Env =
   std::make_unique(Code, FileName, Ranges, FirstStartColumn,
- NextStartColumn, LastStartColumn);
+NextStartColumn, LastStartColumn);
   llvm::Optional CurrentCode = None;
   tooling::Replacements Fixes;
   unsigned Penalty = 0;


Index: clang/unittests/Format/SortIncludesTest.cpp
===
--- clang/unittests/Format/SortIncludesTest.cpp
+++ clang/unittests/Format/SortIncludesTest.cpp
@@ -724,6 +724,14 @@
   EXPECT_EQ(Code, sort(Code, "input.h", 0));
 }
 
+TEST_F(SortIncludesTest,
+   DoNotOutputReplacementsForSortedBlocksWithRegroupingWindows) {
+  Style.IncludeBlocks = Style.IBS_Regroup;
+  std::string Code = "#include \"b.h\"\r\n"
+ "\r\n"
+ "#include \r\n";
+  EXPECT_EQ(Code, sort(Code, "input.h", 0));
+}
 
 TEST_F(SortIncludesTest, DoNotRegroupGroupsInGoogleObjCStyle) {
   FmtStyle = getGoogleStyle(FormatStyle::LK_ObjC);
Index: clang/unittests/Format/SortImportsTestJava.cpp
===
--- clang/unittests/Format/SortImportsTestJava.cpp
+++ clang/unittests/Format/SortImportsTestJava.cpp
@@ -285,6 +285,13 @@
   sortIncludes(FmtStyle, Code, GetCodeRange(Code), "input.java").empty());
 }
 
+TEST_F(SortImportsTestJava,

[PATCH] D67940: [BPF] Preserve and make bitfield access relocatable

2019-10-01 Thread Yonghong Song via Phabricator via cfe-commits
yonghong-song abandoned this revision.
yonghong-song added a comment.

We will take a different approach. So abandon this revision.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D67940



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


[PATCH] D68252: [Stats] Add ALWAYS_ENABLED_STATISTIC enabled regardless of LLVM_ENABLE_STATS.

2019-10-01 Thread Daniel Sanders via Phabricator via cfe-commits
dsanders accepted this revision.
dsanders added a comment.
This revision is now accepted and ready to land.

LGTM




Comment at: llvm/include/llvm/ADT/Statistic.h:47
 
-class Statistic {
+class StatisticBase {
 public:

Do we actually need the common base class? I'm thinking that since 
NoopStatistic never registers (and can't because the interfaces to do so 
changed to TrackingStatistic*), then there's a good chance that nothing reads 
DebugType, Name, Desc, Value, Initialized and we might be able to save a little 
memory by eliminating them.


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

https://reviews.llvm.org/D68252



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


Re: r373371 - [Diagnostics] Make -Wenum-compare-conditional off by default

2019-10-01 Thread Dávid Bolvanský via cfe-commits
I fixed it, forgot to run clang semacxx check too.

I am not sure.. I checked github and found case:
https://github.com/ros-industrial-consortium/godel/issues/115

Seems like this is very rare, not worth to make it on..

ut 1. 10. 2019 o 20:19 Nico Weber  napísal(a):
>
> This breaks emaCXX/warn-sign-conversion.cpp -- but see other thread, maybe 
> just revert this for now until we know what we want to do here :)
>
> On Tue, Oct 1, 2019 at 2:10 PM David Bolvansky via cfe-commits 
>  wrote:
>>
>> Author: xbolva00
>> Date: Tue Oct  1 11:12:13 2019
>> New Revision: 373371
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=373371&view=rev
>> Log:
>> [Diagnostics] Make -Wenum-compare-conditional off by default
>>
>> Too many false positives, eg. in Chromium.
>>
>> Modified:
>> cfe/trunk/include/clang/Basic/DiagnosticGroups.td
>> cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
>> cfe/trunk/test/Sema/warn-conditional-emum-types-mismatch.c
>>
>> Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td
>> URL: 
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticGroups.td?rev=373371&r1=373370&r2=373371&view=diff
>> ==
>> --- cfe/trunk/include/clang/Basic/DiagnosticGroups.td (original)
>> +++ cfe/trunk/include/clang/Basic/DiagnosticGroups.td Tue Oct  1 11:12:13 
>> 2019
>> @@ -565,7 +565,7 @@ def SwitchEnum : DiagGroup<"switch-e
>>  def Switch : DiagGroup<"switch">;
>>  def EnumCompareConditional : DiagGroup<"enum-compare-conditional">;
>>  def EnumCompareSwitch : DiagGroup<"enum-compare-switch">;
>> -def EnumCompare   : DiagGroup<"enum-compare", [EnumCompareConditional, 
>> EnumCompareSwitch]>;
>> +def EnumCompare   : DiagGroup<"enum-compare", [EnumCompareSwitch]>;
>>  def ImplicitFallthroughPerFunction :
>>DiagGroup<"implicit-fallthrough-per-function">;
>>  def ImplicitFallthrough  : DiagGroup<"implicit-fallthrough",
>>
>> Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
>> URL: 
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=373371&r1=373370&r2=373371&view=diff
>> ==
>> --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
>> +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Oct  1 11:12:13 
>> 2019
>> @@ -6172,7 +6172,7 @@ def warn_comparison_of_mixed_enum_types
>>  def warn_conditional_mixed_enum_types : Warning<
>>"enumeration type mismatch in conditional expression"
>>"%diff{ ($ and $)|}0,1">,
>> -  InGroup;
>> +  InGroup, DefaultIgnore;
>>  def warn_comparison_of_mixed_enum_types_switch : Warning<
>>"comparison of two values with different enumeration types in switch 
>> statement"
>>"%diff{ ($ and $)|}0,1">,
>>
>> Modified: cfe/trunk/test/Sema/warn-conditional-emum-types-mismatch.c
>> URL: 
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/warn-conditional-emum-types-mismatch.c?rev=373371&r1=373370&r2=373371&view=diff
>> ==
>> --- cfe/trunk/test/Sema/warn-conditional-emum-types-mismatch.c (original)
>> +++ cfe/trunk/test/Sema/warn-conditional-emum-types-mismatch.c Tue Oct  1 
>> 11:12:13 2019
>> @@ -1,9 +1,5 @@
>>  // RUN: %clang_cc1 -x c -fsyntax-only -verify -Wenum-compare-conditional %s
>> -// RUN: %clang_cc1 -x c -fsyntax-only -verify -Wenum-compare %s
>> -// RUN: %clang_cc1 -x c -fsyntax-only -verify  %s
>>  // RUN: %clang_cc1 -x c++ -fsyntax-only -verify -Wenum-compare-conditional 
>> %s
>> -// RUN: %clang_cc1 -x c++ -fsyntax-only -verify -Wenum-compare %s
>> -// RUN: %clang_cc1 -x c++ -fsyntax-only -verify %s
>>
>>  enum ro { A = 0x10 };
>>  enum rw { B = 0xFF };
>>
>>
>> ___
>> cfe-commits mailing list
>> cfe-commits@lists.llvm.org
>> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r373371 - [Diagnostics] Make -Wenum-compare-conditional off by default

2019-10-01 Thread Nico Weber via cfe-commits
This breaks emaCXX/warn-sign-conversion.cpp -- but see other thread, maybe
just revert this for now until we know what we want to do here :)

On Tue, Oct 1, 2019 at 2:10 PM David Bolvansky via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: xbolva00
> Date: Tue Oct  1 11:12:13 2019
> New Revision: 373371
>
> URL: http://llvm.org/viewvc/llvm-project?rev=373371&view=rev
> Log:
> [Diagnostics] Make -Wenum-compare-conditional off by default
>
> Too many false positives, eg. in Chromium.
>
> Modified:
> cfe/trunk/include/clang/Basic/DiagnosticGroups.td
> cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> cfe/trunk/test/Sema/warn-conditional-emum-types-mismatch.c
>
> Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticGroups.td?rev=373371&r1=373370&r2=373371&view=diff
>
> ==
> --- cfe/trunk/include/clang/Basic/DiagnosticGroups.td (original)
> +++ cfe/trunk/include/clang/Basic/DiagnosticGroups.td Tue Oct  1 11:12:13
> 2019
> @@ -565,7 +565,7 @@ def SwitchEnum : DiagGroup<"switch-e
>  def Switch : DiagGroup<"switch">;
>  def EnumCompareConditional : DiagGroup<"enum-compare-conditional">;
>  def EnumCompareSwitch : DiagGroup<"enum-compare-switch">;
> -def EnumCompare   : DiagGroup<"enum-compare",
> [EnumCompareConditional, EnumCompareSwitch]>;
> +def EnumCompare   : DiagGroup<"enum-compare", [EnumCompareSwitch]>;
>  def ImplicitFallthroughPerFunction :
>DiagGroup<"implicit-fallthrough-per-function">;
>  def ImplicitFallthrough  : DiagGroup<"implicit-fallthrough",
>
> Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=373371&r1=373370&r2=373371&view=diff
>
> ==
> --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
> +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Oct  1
> 11:12:13 2019
> @@ -6172,7 +6172,7 @@ def warn_comparison_of_mixed_enum_types
>  def warn_conditional_mixed_enum_types : Warning<
>"enumeration type mismatch in conditional expression"
>"%diff{ ($ and $)|}0,1">,
> -  InGroup;
> +  InGroup, DefaultIgnore;
>  def warn_comparison_of_mixed_enum_types_switch : Warning<
>"comparison of two values with different enumeration types in switch
> statement"
>"%diff{ ($ and $)|}0,1">,
>
> Modified: cfe/trunk/test/Sema/warn-conditional-emum-types-mismatch.c
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/warn-conditional-emum-types-mismatch.c?rev=373371&r1=373370&r2=373371&view=diff
>
> ==
> --- cfe/trunk/test/Sema/warn-conditional-emum-types-mismatch.c (original)
> +++ cfe/trunk/test/Sema/warn-conditional-emum-types-mismatch.c Tue Oct  1
> 11:12:13 2019
> @@ -1,9 +1,5 @@
>  // RUN: %clang_cc1 -x c -fsyntax-only -verify -Wenum-compare-conditional
> %s
> -// RUN: %clang_cc1 -x c -fsyntax-only -verify -Wenum-compare %s
> -// RUN: %clang_cc1 -x c -fsyntax-only -verify  %s
>  // RUN: %clang_cc1 -x c++ -fsyntax-only -verify
> -Wenum-compare-conditional %s
> -// RUN: %clang_cc1 -x c++ -fsyntax-only -verify -Wenum-compare %s
> -// RUN: %clang_cc1 -x c++ -fsyntax-only -verify %s
>
>  enum ro { A = 0x10 };
>  enum rw { B = 0xFF };
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D68284: [HIP] Support -emit-llvm for device compilation

2019-10-01 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl created this revision.
yaxunl added a reviewer: tra.

Sometimes it is useful to compile HIP device code to LLVM BC. It is not 
convenient to use clang -cc1 since
there are lots of options needed.

This patch allows clang driver to compile HIP device code to LLVM BC with 
-emit-llvm -c.


https://reviews.llvm.org/D68284

Files:
  lib/Driver/Driver.cpp
  test/Driver/hip-toolchain-emit-llvm.hip


Index: test/Driver/hip-toolchain-emit-llvm.hip
===
--- /dev/null
+++ test/Driver/hip-toolchain-emit-llvm.hip
@@ -0,0 +1,26 @@
+// REQUIRES: clang-driver
+// REQUIRES: x86-registered-target
+// REQUIRES: amdgpu-registered-target
+
+// RUN: %clang -c -emit-llvm --cuda-device-only -### -target x86_64-linux-gnu \
+// RUN:   -o a.bc -x hip --cuda-gpu-arch=gfx900 \
+// RUN:   --hip-device-lib=lib1.bc \
+// RUN:   --hip-device-lib-path=%S/Inputs/hip_multiple_inputs/lib1 \
+// RUN:   %S/Inputs/hip_multiple_inputs/a.cu \
+// RUN: 2>&1 | FileCheck -check-prefixes=CHECK %s
+
+// CHECK: {{".*clang.*"}} "-cc1" "-triple" "amdgcn-amd-amdhsa"
+// CHECK-SAME: "-aux-triple" "x86_64-unknown-linux-gnu"
+// CHECK-SAME: "-emit-llvm-bc"
+// CHECK-SAME: "-main-file-name" "a.cu" {{.*}} "-target-cpu" "gfx900"
+// CHECK-SAME: "-fcuda-is-device"
+// CHECK-SAME: {{".*lib1.bc"}}
+// CHECK-SAME: "-o" "a.bc"
+// CHECK-SAME: {{".*a.cu"}}
+
+// CHECK-NOT: {{"*.llvm-link"}}
+// CHECK-NOT: {{".*opt"}}
+// CHECK-NOT: {{".*llc"}}
+// CHECK-NOT: {{".*lld"}}
+// CHECK-NOT: {{".*clang-offload-bundler"}}
+// CHECK-NOT: {{".*ld.*"}}
Index: lib/Driver/Driver.cpp
===
--- lib/Driver/Driver.cpp
+++ lib/Driver/Driver.cpp
@@ -2314,6 +2314,7 @@
 /// compilation.
 bool CompileHostOnly = false;
 bool CompileDeviceOnly = false;
+bool EmitLLVM = false;
 
 /// List of GPU architectures to use in this compilation.
 SmallVector GpuArchList;
@@ -2480,6 +2481,8 @@
   CompileDeviceOnly = PartialCompilationArg &&
   PartialCompilationArg->getOption().matches(
   options::OPT_cuda_device_only);
+  EmitLLVM = Args.getLastArg(options::OPT_emit_llvm);
+
 
   // Collect all cuda_gpu_arch parameters, removing duplicates.
   std::set GpuArchs;
@@ -2660,6 +2663,11 @@
   CurPhase == phases::Assemble)
 return ABRT_Success;
 
+  if (EmitLLVM &&
+  (CurPhase == phases::Backend || CurPhase == phases::Assemble ||
+   CurPhase == phases::Link))
+return CompileDeviceOnly ? ABRT_Ignore_Host : ABRT_Success;
+
   assert(((CurPhase == phases::Link && Relocatable) ||
   CudaDeviceActions.size() == GpuArchList.size()) &&
  "Expecting one action per GPU architecture.");


Index: test/Driver/hip-toolchain-emit-llvm.hip
===
--- /dev/null
+++ test/Driver/hip-toolchain-emit-llvm.hip
@@ -0,0 +1,26 @@
+// REQUIRES: clang-driver
+// REQUIRES: x86-registered-target
+// REQUIRES: amdgpu-registered-target
+
+// RUN: %clang -c -emit-llvm --cuda-device-only -### -target x86_64-linux-gnu \
+// RUN:   -o a.bc -x hip --cuda-gpu-arch=gfx900 \
+// RUN:   --hip-device-lib=lib1.bc \
+// RUN:   --hip-device-lib-path=%S/Inputs/hip_multiple_inputs/lib1 \
+// RUN:   %S/Inputs/hip_multiple_inputs/a.cu \
+// RUN: 2>&1 | FileCheck -check-prefixes=CHECK %s
+
+// CHECK: {{".*clang.*"}} "-cc1" "-triple" "amdgcn-amd-amdhsa"
+// CHECK-SAME: "-aux-triple" "x86_64-unknown-linux-gnu"
+// CHECK-SAME: "-emit-llvm-bc"
+// CHECK-SAME: "-main-file-name" "a.cu" {{.*}} "-target-cpu" "gfx900"
+// CHECK-SAME: "-fcuda-is-device"
+// CHECK-SAME: {{".*lib1.bc"}}
+// CHECK-SAME: "-o" "a.bc"
+// CHECK-SAME: {{".*a.cu"}}
+
+// CHECK-NOT: {{"*.llvm-link"}}
+// CHECK-NOT: {{".*opt"}}
+// CHECK-NOT: {{".*llc"}}
+// CHECK-NOT: {{".*lld"}}
+// CHECK-NOT: {{".*clang-offload-bundler"}}
+// CHECK-NOT: {{".*ld.*"}}
Index: lib/Driver/Driver.cpp
===
--- lib/Driver/Driver.cpp
+++ lib/Driver/Driver.cpp
@@ -2314,6 +2314,7 @@
 /// compilation.
 bool CompileHostOnly = false;
 bool CompileDeviceOnly = false;
+bool EmitLLVM = false;
 
 /// List of GPU architectures to use in this compilation.
 SmallVector GpuArchList;
@@ -2480,6 +2481,8 @@
   CompileDeviceOnly = PartialCompilationArg &&
   PartialCompilationArg->getOption().matches(
   options::OPT_cuda_device_only);
+  EmitLLVM = Args.getLastArg(options::OPT_emit_llvm);
+
 
   // Collect all cuda_gpu_arch parameters, removing duplicates.
   std::set GpuArchs;
@@ -2660,6 +2663,11 @@
   CurPhase == phases::Assemble)
 return ABRT_Success;
 
+  if (EmitLLVM &&
+  (CurPhase == phases::Backend || CurPhase == phases::Assemble ||
+   CurPhase == phases::Link))
+return C

r373375 - [NFC] Updated tests after rL373371

2019-10-01 Thread David Bolvansky via cfe-commits
Author: xbolva00
Date: Tue Oct  1 11:18:45 2019
New Revision: 373375

URL: http://llvm.org/viewvc/llvm-project?rev=373375&view=rev
Log:
[NFC] Updated tests after rL373371

Forgot to run check-clang-semacxx.

Modified:
cfe/trunk/test/SemaCXX/warn-sign-conversion.cpp

Modified: cfe/trunk/test/SemaCXX/warn-sign-conversion.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-sign-conversion.cpp?rev=373375&r1=373374&r2=373375&view=diff
==
--- cfe/trunk/test/SemaCXX/warn-sign-conversion.cpp (original)
+++ cfe/trunk/test/SemaCXX/warn-sign-conversion.cpp Tue Oct  1 11:18:45 2019
@@ -70,15 +70,11 @@ namespace test2 {
 int d1 = 1 ? i : Foo::D; // expected-warning {{operand of ? changes 
signedness: 'test2::Foo::Named4' to 'int'}}
 int d2 = 1 ? Foo::D : i; // expected-warning {{operand of ? changes 
signedness: 'test2::Foo::Named4' to 'int'}}
 int d3 = 1 ? B : Foo::D; // expected-warning {{operand of ? changes 
signedness: 'test2::Foo::Named4' to 'int'}}
-// expected-warning@-1 {{enumeration type mismatch in conditional 
expression ('test2::Named2' and 'test2::Foo::Named4')}}
 int d4 = 1 ? Foo::D : B; // expected-warning {{operand of ? changes 
signedness: 'test2::Foo::Named4' to 'int'}}
-// expected-warning@-1 {{enumeration type mismatch in conditional 
expression ('test2::Foo::Named4' and 'test2::Named2')}}
 
 int e1 = 1 ? i : E; // expected-warning {{operand of ? changes signedness: 
'test2::Named5' to 'int'}}
 int e2 = 1 ? E : i; // expected-warning {{operand of ? changes signedness: 
'test2::Named5' to 'int'}}
 int e3 = 1 ? E : B; // expected-warning {{operand of ? changes signedness: 
'test2::Named5' to 'int'}}
-// expected-warning@-1 {{enumeration type mismatch in conditional 
expression ('test2::Named5' and 'test2::Named2')}}
 int e4 = 1 ? B : E; // expected-warning {{operand of ? changes signedness: 
'test2::Named5' to 'int'}}
-// expected-warning@-1 {{enumeration type mismatch in conditional 
expression ('test2::Named2' and 'test2::Named5')}}
   }
 }


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


r373374 - [OPENMP]Fix PR43330: OpenMP target: Mapping of partial arrays fails.

2019-10-01 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Tue Oct  1 11:18:03 2019
New Revision: 373374

URL: http://llvm.org/viewvc/llvm-project?rev=373374&view=rev
Log:
[OPENMP]Fix PR43330: OpenMP target: Mapping of partial arrays fails.

Fixed calculation the size of the array sections.

Modified:
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
cfe/trunk/test/OpenMP/target_map_codegen.cpp

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp?rev=373374&r1=373373&r2=373374&view=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp Tue Oct  1 11:18:03 2019
@@ -7249,9 +7249,11 @@ private:
 OAE->getBase()->IgnoreParenImpCasts())
 .getCanonicalType();
 
-  // If there is no length associated with the expression, that means we
-  // are using the whole length of the base.
-  if (!OAE->getLength() && OAE->getColonLoc().isValid())
+  // If there is no length associated with the expression and lower bound 
is
+  // not specified too, that means we are using the whole length of the
+  // base.
+  if (!OAE->getLength() && OAE->getColonLoc().isValid() &&
+  !OAE->getLowerBound())
 return CGF.getTypeSize(BaseTy);
 
   llvm::Value *ElemSize;
@@ -7265,13 +7267,30 @@ private:
 
   // If we don't have a length at this point, that is because we have an
   // array section with a single element.
-  if (!OAE->getLength())
+  if (!OAE->getLength() && OAE->getColonLoc().isInvalid())
 return ElemSize;
 
-  llvm::Value *LengthVal = CGF.EmitScalarExpr(OAE->getLength());
-  LengthVal =
-  CGF.Builder.CreateIntCast(LengthVal, CGF.SizeTy, /*isSigned=*/false);
-  return CGF.Builder.CreateNUWMul(LengthVal, ElemSize);
+  if (const Expr *LenExpr = OAE->getLength()) {
+llvm::Value *LengthVal = CGF.EmitScalarExpr(OAE->getLength());
+LengthVal = CGF.EmitScalarConversion(
+LengthVal, OAE->getLength()->getType(),
+CGF.getContext().getSizeType(), OAE->getLength()->getExprLoc());
+return CGF.Builder.CreateNUWMul(LengthVal, ElemSize);
+  }
+  assert(!OAE->getLength() && OAE->getColonLoc().isValid() &&
+ OAE->getLowerBound() && "expected array_section[lb:].");
+  // Size = sizetype - lb * elemtype;
+  llvm::Value *LengthVal = CGF.getTypeSize(BaseTy);
+  llvm::Value *LBVal = CGF.EmitScalarExpr(OAE->getLowerBound());
+  LBVal = CGF.EmitScalarConversion(LBVal, OAE->getLowerBound()->getType(),
+   CGF.getContext().getSizeType(),
+   OAE->getLowerBound()->getExprLoc());
+  LBVal = CGF.Builder.CreateNUWMul(LBVal, ElemSize);
+  llvm::Value *Cmp = CGF.Builder.CreateICmpUGT(LengthVal, LBVal);
+  llvm::Value *TrueVal = CGF.Builder.CreateNUWSub(LengthVal, LBVal);
+  LengthVal = CGF.Builder.CreateSelect(
+  Cmp, TrueVal, llvm::ConstantInt::get(CGF.SizeTy, 0));
+  return LengthVal;
 }
 return CGF.getTypeSize(ExprTy);
   }

Modified: cfe/trunk/test/OpenMP/target_map_codegen.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/target_map_codegen.cpp?rev=373374&r1=373373&r2=373374&view=diff
==
--- cfe/trunk/test/OpenMP/target_map_codegen.cpp (original)
+++ cfe/trunk/test/OpenMP/target_map_codegen.cpp Tue Oct  1 11:18:03 2019
@@ -1323,172 +1323,176 @@ void implicit_maps_template_type_capture
 // SIMD-ONLY18-NOT: {{__kmpc|__tgt}}
 #ifdef CK19
 
-// CK19-LABEL: 
@.__omp_offloading_{{.*}}explicit_maps_single{{.*}}_l1510.region_id = weak 
constant i8 0
+// CK19-LABEL: 
@.__omp_offloading_{{.*}}explicit_maps_single{{.*}}_l1514.region_id = weak 
constant i8 0
 // CK19: [[SIZE00:@.+]] = private {{.*}}constant [1 x i64] [i64 4]
 // CK19: [[MTYPE00:@.+]] = private {{.*}}constant [1 x i64] [i64 32]
 
-// CK19-LABEL: 
@.__omp_offloading_{{.*}}explicit_maps_single{{.*}}_l1531.region_id = weak 
constant i8 0
+// CK19-LABEL: 
@.__omp_offloading_{{.*}}explicit_maps_single{{.*}}_l1535.region_id = weak 
constant i8 0
 // CK19: [[SIZE00n:@.+]] = private {{.*}}constant [1 x i64] [i64 4]
 // CK19: [[MTYPE00n:@.+]] = private {{.*}}constant [1 x i64] [i64 32]
 
-// CK19-LABEL: 
@.__omp_offloading_{{.*}}explicit_maps_single{{.*}}_l1553.region_id = weak 
constant i8 0
+// CK19-LABEL: 
@.__omp_offloading_{{.*}}explicit_maps_single{{.*}}_l1557.region_id = weak 
constant i8 0
 // CK19: [[SIZE01:@.+]] = private {{.*}}constant [1 x i64] [i64 400]
 // CK19: [[MTYPE01:@.+]] = private {{.*}}constant [1 x i64] [i64 33]
 
-// CK19-LABEL: 
@.__omp_offloading_{{.*}}explicit_maps_single{{.*}}_l1572.region_id = weak 
constant i8 0
+// CK19-LABEL: 
@.__omp_offloading_{{.*}}explicit_maps_single

Re: r373252 - [Diagnostics] Warn if enumeration type mismatch in conditional expression

2019-10-01 Thread Nico Weber via cfe-commits
Chromium shouldn't be a factor for determining is a warning is on or off by
default. We can easily turn warnings off, and I had done so in
http://crrev.com/http://crrev.com/701604 (as long as warnings have a
dedicated flag -- but that's needed for every large codebase adopting a new
clang). So that's not super relevant -- the bots would've cycled green
anyways.

We should probably write it down, but clang's warning philosophy is that
warnings should be very high-signal. The usual way to prove this is to
build some large open-source codebase with the warning and counting true
and false positives.

Another thing we sometimes say that a warning should be so good that it
should be possible to turn it on by default, and if a warning doesn't meet
that bar, then maybe we shouldn't have it. (There are exceptions.)

ps: To be clear, I appreciate all your work to add warnings a lot! It's
very useful. It's also possible that this warning is useful, but it's not
immediately clear, so there should be some data to back it up.

On Tue, Oct 1, 2019 at 1:59 PM Dávid Bolvanský 
wrote:

> Sorry, answered on phone, missed it. I looked at your buildbots for
> chromium and yeah, so many warnings. I will make it off by default.
>
> ut 1. 10. 2019 o 19:58 Dávid Bolvanský 
> napísal(a):
> >
> > (Not sure if you intentionally didn't reply-all.)
> >
> > Sorry, answered on phone, missed it. I looked at your buildbots for
> > chromium and yeah, so many warnings. I will make it off by default.
> >
> > ut 1. 10. 2019 o 19:17 Nico Weber  napísal(a):
> >
> > >
> > > (Not sure if you intentionally didn't reply-all.)
> > >
> > > We should probably write it down, but clang's warning philosophy is
> that warnings should be very high-signal. The usual way to prove this is to
> build some large open-source codebase with the warning and counting true
> and false positives.
> > >
> > > Just "gcc has it" isn't sufficient motivation – gcc has lots of not so
> good warnings :)
> > >
> > > ps: To be clear, I appreciate all your work to add warnings a lot!
> It's very useful. It's also possible that this warning is useful, but it's
> not immediately clear, so there should be some data to back it up.
> > >
> > > On Tue, Oct 1, 2019 at 12:12 PM Dávid Bolvanský <
> david.bolvan...@gmail.com> wrote:
> > >>
> > >> I hit this bug myself, GCC warned me with -Wenum-compare, Clang was
> silent. Clang “supports” this flag, but failed to catch it. Either Clang
> should not pretend that it supports this flag (and all related
> functionality) or should support it fully. Basically, new warnings will
> show up only for Clang-only environments.
> > >>
> > >> I think the own subgroup is a good compromise for now.  We can still
> make it off by default before next release if we decide so.
> > >>
> > >> Dňa 1. 10. 2019 o 17:56 užívateľ Nico Weber 
> napísal:
> > >>
> > >> 
> > >> Thanks!
> > >>
> > >> Any thoughts on the true positive rate for this warning?
> > >>
> > >> On Tue, Oct 1, 2019 at 11:43 AM Dávid Bolvanský <
> david.bolvan...@gmail.com> wrote:
> > >>>
> > >>> Yeah, I moved this warning into own subgroup in rL373345. Thanks.
> > >>>
> > >>> ut 1. 10. 2019 o 16:24 Nico Weber  napísal(a):
> > >>> >
> > >>> > Can we move this behind a Wenum-compare subgroup, say
> Wenum-compare-type? Our codebase is (well, was) Wenum-compare clean, and
> this new warnings fires pretty often and from a first quick glance the
> warning looks pretty low-signal anyways (*). Maybe the subgroup shouldn't
> even be on by default -- do you have any data on true / false positive rate
> of this?
> > >>> >
> > >>> > (But for starters, just having a way to turn this off is enough.)
> > >>> >
> > >>> > For example, we have a windows common control that's either a
> PGRP_DOWN or a PGRP_UP page control and depending on which you store the
> control state in the same int, then stuff like `return
> extra.inner_spin.spin_up ? UPS_DISABLED : DNS_DISABLED;`.
> > >>> >
> > >>> > On Mon, Sep 30, 2019 at 3:53 PM David Bolvansky via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
> > >>> >>
> > >>> >> Author: xbolva00
> > >>> >> Date: Mon Sep 30 12:55:50 2019
> > >>> >> New Revision: 373252
> > >>> >>
> > >>> >> URL: http://llvm.org/viewvc/llvm-project?rev=373252&view=rev
> > >>> >> Log:
> > >>> >> [Diagnostics] Warn if enumeration type mismatch in conditional
> expression
> > >>> >>
> > >>> >> Summary:
> > >>> >> - Useful warning
> > >>> >> - GCC compatibility (GCC warns in C++ mode)
> > >>> >>
> > >>> >> Reviewers: rsmith, aaron.ballman
> > >>> >>
> > >>> >> Reviewed By: aaron.ballman
> > >>> >>
> > >>> >> Subscribers: cfe-commits
> > >>> >>
> > >>> >> Tags: #clang
> > >>> >>
> > >>> >> Differential Revision: https://reviews.llvm.org/D67919
> > >>> >>
> > >>> >> Added:
> > >>> >> cfe/trunk/test/Sema/warn-conditional-emum-types-mismatch.c
> > >>> >> Modified:
> > >>> >> cfe/trunk/lib/Sema/SemaChecking.cpp
> > >>> >>
> > >>> >> Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
> > >>> >> URL:
>

r373371 - [Diagnostics] Make -Wenum-compare-conditional off by default

2019-10-01 Thread David Bolvansky via cfe-commits
Author: xbolva00
Date: Tue Oct  1 11:12:13 2019
New Revision: 373371

URL: http://llvm.org/viewvc/llvm-project?rev=373371&view=rev
Log:
[Diagnostics] Make -Wenum-compare-conditional off by default

Too many false positives, eg. in Chromium.

Modified:
cfe/trunk/include/clang/Basic/DiagnosticGroups.td
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/test/Sema/warn-conditional-emum-types-mismatch.c

Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticGroups.td?rev=373371&r1=373370&r2=373371&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticGroups.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticGroups.td Tue Oct  1 11:12:13 2019
@@ -565,7 +565,7 @@ def SwitchEnum : DiagGroup<"switch-e
 def Switch : DiagGroup<"switch">;
 def EnumCompareConditional : DiagGroup<"enum-compare-conditional">;
 def EnumCompareSwitch : DiagGroup<"enum-compare-switch">;
-def EnumCompare   : DiagGroup<"enum-compare", [EnumCompareConditional, 
EnumCompareSwitch]>;
+def EnumCompare   : DiagGroup<"enum-compare", [EnumCompareSwitch]>;
 def ImplicitFallthroughPerFunction :
   DiagGroup<"implicit-fallthrough-per-function">;
 def ImplicitFallthrough  : DiagGroup<"implicit-fallthrough",

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=373371&r1=373370&r2=373371&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Oct  1 11:12:13 
2019
@@ -6172,7 +6172,7 @@ def warn_comparison_of_mixed_enum_types
 def warn_conditional_mixed_enum_types : Warning<
   "enumeration type mismatch in conditional expression"
   "%diff{ ($ and $)|}0,1">,
-  InGroup;
+  InGroup, DefaultIgnore;
 def warn_comparison_of_mixed_enum_types_switch : Warning<
   "comparison of two values with different enumeration types in switch 
statement"
   "%diff{ ($ and $)|}0,1">,

Modified: cfe/trunk/test/Sema/warn-conditional-emum-types-mismatch.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/warn-conditional-emum-types-mismatch.c?rev=373371&r1=373370&r2=373371&view=diff
==
--- cfe/trunk/test/Sema/warn-conditional-emum-types-mismatch.c (original)
+++ cfe/trunk/test/Sema/warn-conditional-emum-types-mismatch.c Tue Oct  1 
11:12:13 2019
@@ -1,9 +1,5 @@
 // RUN: %clang_cc1 -x c -fsyntax-only -verify -Wenum-compare-conditional %s
-// RUN: %clang_cc1 -x c -fsyntax-only -verify -Wenum-compare %s
-// RUN: %clang_cc1 -x c -fsyntax-only -verify  %s
 // RUN: %clang_cc1 -x c++ -fsyntax-only -verify -Wenum-compare-conditional %s
-// RUN: %clang_cc1 -x c++ -fsyntax-only -verify -Wenum-compare %s
-// RUN: %clang_cc1 -x c++ -fsyntax-only -verify %s
 
 enum ro { A = 0x10 };
 enum rw { B = 0xFF };


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


Re: r373252 - [Diagnostics] Warn if enumeration type mismatch in conditional expression

2019-10-01 Thread Dávid Bolvanský via cfe-commits
Done. rL373371.

ut 1. 10. 2019 o 19:58 Dávid Bolvanský  napísal(a):
>
> Sorry, answered on phone, missed it. I looked at your buildbots for
> chromium and yeah, so many warnings. I will make it off by default.
>
> ut 1. 10. 2019 o 19:58 Dávid Bolvanský  napísal(a):
> >
> > (Not sure if you intentionally didn't reply-all.)
> >
> > Sorry, answered on phone, missed it. I looked at your buildbots for
> > chromium and yeah, so many warnings. I will make it off by default.
> >
> > ut 1. 10. 2019 o 19:17 Nico Weber  napísal(a):
> >
> > >
> > > (Not sure if you intentionally didn't reply-all.)
> > >
> > > We should probably write it down, but clang's warning philosophy is that 
> > > warnings should be very high-signal. The usual way to prove this is to 
> > > build some large open-source codebase with the warning and counting true 
> > > and false positives.
> > >
> > > Just "gcc has it" isn't sufficient motivation – gcc has lots of not so 
> > > good warnings :)
> > >
> > > ps: To be clear, I appreciate all your work to add warnings a lot! It's 
> > > very useful. It's also possible that this warning is useful, but it's not 
> > > immediately clear, so there should be some data to back it up.
> > >
> > > On Tue, Oct 1, 2019 at 12:12 PM Dávid Bolvanský 
> > >  wrote:
> > >>
> > >> I hit this bug myself, GCC warned me with -Wenum-compare, Clang was 
> > >> silent. Clang “supports” this flag, but failed to catch it. Either Clang 
> > >> should not pretend that it supports this flag (and all related 
> > >> functionality) or should support it fully. Basically, new warnings will 
> > >> show up only for Clang-only environments.
> > >>
> > >> I think the own subgroup is a good compromise for now.  We can still 
> > >> make it off by default before next release if we decide so.
> > >>
> > >> Dňa 1. 10. 2019 o 17:56 užívateľ Nico Weber  
> > >> napísal:
> > >>
> > >> 
> > >> Thanks!
> > >>
> > >> Any thoughts on the true positive rate for this warning?
> > >>
> > >> On Tue, Oct 1, 2019 at 11:43 AM Dávid Bolvanský 
> > >>  wrote:
> > >>>
> > >>> Yeah, I moved this warning into own subgroup in rL373345. Thanks.
> > >>>
> > >>> ut 1. 10. 2019 o 16:24 Nico Weber  napísal(a):
> > >>> >
> > >>> > Can we move this behind a Wenum-compare subgroup, say 
> > >>> > Wenum-compare-type? Our codebase is (well, was) Wenum-compare clean, 
> > >>> > and this new warnings fires pretty often and from a first quick 
> > >>> > glance the warning looks pretty low-signal anyways (*). Maybe the 
> > >>> > subgroup shouldn't even be on by default -- do you have any data on 
> > >>> > true / false positive rate of this?
> > >>> >
> > >>> > (But for starters, just having a way to turn this off is enough.)
> > >>> >
> > >>> > For example, we have a windows common control that's either a 
> > >>> > PGRP_DOWN or a PGRP_UP page control and depending on which you store 
> > >>> > the control state in the same int, then stuff like `return 
> > >>> > extra.inner_spin.spin_up ? UPS_DISABLED : DNS_DISABLED;`.
> > >>> >
> > >>> > On Mon, Sep 30, 2019 at 3:53 PM David Bolvansky via cfe-commits 
> > >>> >  wrote:
> > >>> >>
> > >>> >> Author: xbolva00
> > >>> >> Date: Mon Sep 30 12:55:50 2019
> > >>> >> New Revision: 373252
> > >>> >>
> > >>> >> URL: http://llvm.org/viewvc/llvm-project?rev=373252&view=rev
> > >>> >> Log:
> > >>> >> [Diagnostics] Warn if enumeration type mismatch in conditional 
> > >>> >> expression
> > >>> >>
> > >>> >> Summary:
> > >>> >> - Useful warning
> > >>> >> - GCC compatibility (GCC warns in C++ mode)
> > >>> >>
> > >>> >> Reviewers: rsmith, aaron.ballman
> > >>> >>
> > >>> >> Reviewed By: aaron.ballman
> > >>> >>
> > >>> >> Subscribers: cfe-commits
> > >>> >>
> > >>> >> Tags: #clang
> > >>> >>
> > >>> >> Differential Revision: https://reviews.llvm.org/D67919
> > >>> >>
> > >>> >> Added:
> > >>> >> cfe/trunk/test/Sema/warn-conditional-emum-types-mismatch.c
> > >>> >> Modified:
> > >>> >> cfe/trunk/lib/Sema/SemaChecking.cpp
> > >>> >>
> > >>> >> Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
> > >>> >> URL: 
> > >>> >> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=373252&r1=373251&r2=373252&view=diff
> > >>> >> ==
> > >>> >> --- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
> > >>> >> +++ cfe/trunk/lib/Sema/SemaChecking.cpp Mon Sep 30 12:55:50 2019
> > >>> >> @@ -11308,6 +11308,32 @@ static const IntegerLiteral *getIntegerL
> > >>> >>return IL;
> > >>> >>  }
> > >>> >>
> > >>> >> +static void CheckConditionalWithEnumTypes(Sema &S, SourceLocation 
> > >>> >> Loc,
> > >>> >> +  Expr *LHS, Expr *RHS) {
> > >>> >> +  QualType LHSStrippedType = LHS->IgnoreParenImpCasts()->getType();
> > >>> >> +  QualType RHSStrippedType = RHS->IgnoreParenImpCasts()->getType();
> > >>> >> +
> > >>> >> +  const auto *LHSEnumType = LHSStrippedType->getAs();
> > >>> >> +  if (!LHSEnumType)
> > >>> >>

[PATCH] D64671: [clang-tidy] New check: misc-init-local-variables

2019-10-01 Thread Jussi Pakkanen via Phabricator via cfe-commits
jpakkane added a comment.

In D64671#1688626 , @aaron.ballman 
wrote:

> Do you need someone to commit this on your behalf (sorry for not asking that 
> question sooner)?


Yes, please. I have no rights of any kind, this is in fact my first ever pull 
request to LLVM.


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

https://reviews.llvm.org/D64671



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


[PATCH] D68029: [ThinLTO] Enable index-only WPD from clang

2019-10-01 Thread Teresa Johnson via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL373370: [ThinLTO] Enable index-only WPD from clang (authored 
by tejohnson, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

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

https://reviews.llvm.org/D68029

Files:
  cfe/trunk/lib/Driver/ToolChains/Clang.cpp
  cfe/trunk/test/Driver/split-lto-unit.c


Index: cfe/trunk/test/Driver/split-lto-unit.c
===
--- cfe/trunk/test/Driver/split-lto-unit.c
+++ cfe/trunk/test/Driver/split-lto-unit.c
@@ -6,5 +6,5 @@
 
 // UNIT: "-fsplit-lto-unit"
 // NOUNIT-NOT: "-fsplit-lto-unit"
-// ERROR1: error: invalid argument '-fno-split-lto-unit' not allowed with 
'-fwhole-program-vtables'
+// ERROR1-NOT: error: invalid argument
 // ERROR2: error: invalid argument '-fno-split-lto-unit' not allowed with 
'-fsanitize=cfi'
Index: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
===
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp
@@ -5456,14 +5456,13 @@
 CmdArgs.push_back("-fwhole-program-vtables");
   }
 
-  bool RequiresSplitLTOUnit = WholeProgramVTables || Sanitize.needsLTO();
+  bool DefaultsSplitLTOUnit = WholeProgramVTables || Sanitize.needsLTO();
   bool SplitLTOUnit =
   Args.hasFlag(options::OPT_fsplit_lto_unit,
-   options::OPT_fno_split_lto_unit, RequiresSplitLTOUnit);
-  if (RequiresSplitLTOUnit && !SplitLTOUnit)
-D.Diag(diag::err_drv_argument_not_allowed_with)
-<< "-fno-split-lto-unit"
-<< (WholeProgramVTables ? "-fwhole-program-vtables" : 
"-fsanitize=cfi");
+   options::OPT_fno_split_lto_unit, DefaultsSplitLTOUnit);
+  if (Sanitize.needsLTO() && !SplitLTOUnit)
+D.Diag(diag::err_drv_argument_not_allowed_with) << "-fno-split-lto-unit"
+<< "-fsanitize=cfi";
   if (SplitLTOUnit)
 CmdArgs.push_back("-fsplit-lto-unit");
 


Index: cfe/trunk/test/Driver/split-lto-unit.c
===
--- cfe/trunk/test/Driver/split-lto-unit.c
+++ cfe/trunk/test/Driver/split-lto-unit.c
@@ -6,5 +6,5 @@
 
 // UNIT: "-fsplit-lto-unit"
 // NOUNIT-NOT: "-fsplit-lto-unit"
-// ERROR1: error: invalid argument '-fno-split-lto-unit' not allowed with '-fwhole-program-vtables'
+// ERROR1-NOT: error: invalid argument
 // ERROR2: error: invalid argument '-fno-split-lto-unit' not allowed with '-fsanitize=cfi'
Index: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
===
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp
@@ -5456,14 +5456,13 @@
 CmdArgs.push_back("-fwhole-program-vtables");
   }
 
-  bool RequiresSplitLTOUnit = WholeProgramVTables || Sanitize.needsLTO();
+  bool DefaultsSplitLTOUnit = WholeProgramVTables || Sanitize.needsLTO();
   bool SplitLTOUnit =
   Args.hasFlag(options::OPT_fsplit_lto_unit,
-   options::OPT_fno_split_lto_unit, RequiresSplitLTOUnit);
-  if (RequiresSplitLTOUnit && !SplitLTOUnit)
-D.Diag(diag::err_drv_argument_not_allowed_with)
-<< "-fno-split-lto-unit"
-<< (WholeProgramVTables ? "-fwhole-program-vtables" : "-fsanitize=cfi");
+   options::OPT_fno_split_lto_unit, DefaultsSplitLTOUnit);
+  if (Sanitize.needsLTO() && !SplitLTOUnit)
+D.Diag(diag::err_drv_argument_not_allowed_with) << "-fno-split-lto-unit"
+<< "-fsanitize=cfi";
   if (SplitLTOUnit)
 CmdArgs.push_back("-fsplit-lto-unit");
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r373370 - [ThinLTO] Enable index-only WPD from clang

2019-10-01 Thread Teresa Johnson via cfe-commits
Author: tejohnson
Date: Tue Oct  1 11:08:29 2019
New Revision: 373370

URL: http://llvm.org/viewvc/llvm-project?rev=373370&view=rev
Log:
[ThinLTO] Enable index-only WPD from clang

Summary:
To trigger the index-only Whole Program Devirt support added to LLVM, we
need to be able to specify -fno-split-lto-unit in conjunction with
-fwhole-program-vtables. Keep the default for -fwhole-program-vtables as
-fsplit-lto-unit, but don't error on that option combination.

Reviewers: pcc

Subscribers: mehdi_amini, inglorion, steven_wu, dexonsmith, arphaman, 
cfe-commits

Tags: #clang

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

Modified:
cfe/trunk/lib/Driver/ToolChains/Clang.cpp
cfe/trunk/test/Driver/split-lto-unit.c

Modified: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Clang.cpp?rev=373370&r1=373369&r2=373370&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp Tue Oct  1 11:08:29 2019
@@ -5456,14 +5456,13 @@ void Clang::ConstructJob(Compilation &C,
 CmdArgs.push_back("-fwhole-program-vtables");
   }
 
-  bool RequiresSplitLTOUnit = WholeProgramVTables || Sanitize.needsLTO();
+  bool DefaultsSplitLTOUnit = WholeProgramVTables || Sanitize.needsLTO();
   bool SplitLTOUnit =
   Args.hasFlag(options::OPT_fsplit_lto_unit,
-   options::OPT_fno_split_lto_unit, RequiresSplitLTOUnit);
-  if (RequiresSplitLTOUnit && !SplitLTOUnit)
-D.Diag(diag::err_drv_argument_not_allowed_with)
-<< "-fno-split-lto-unit"
-<< (WholeProgramVTables ? "-fwhole-program-vtables" : 
"-fsanitize=cfi");
+   options::OPT_fno_split_lto_unit, DefaultsSplitLTOUnit);
+  if (Sanitize.needsLTO() && !SplitLTOUnit)
+D.Diag(diag::err_drv_argument_not_allowed_with) << "-fno-split-lto-unit"
+<< "-fsanitize=cfi";
   if (SplitLTOUnit)
 CmdArgs.push_back("-fsplit-lto-unit");
 

Modified: cfe/trunk/test/Driver/split-lto-unit.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/split-lto-unit.c?rev=373370&r1=373369&r2=373370&view=diff
==
--- cfe/trunk/test/Driver/split-lto-unit.c (original)
+++ cfe/trunk/test/Driver/split-lto-unit.c Tue Oct  1 11:08:29 2019
@@ -6,5 +6,5 @@
 
 // UNIT: "-fsplit-lto-unit"
 // NOUNIT-NOT: "-fsplit-lto-unit"
-// ERROR1: error: invalid argument '-fno-split-lto-unit' not allowed with 
'-fwhole-program-vtables'
+// ERROR1-NOT: error: invalid argument
 // ERROR2: error: invalid argument '-fno-split-lto-unit' not allowed with 
'-fsanitize=cfi'


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


Re: r373252 - [Diagnostics] Warn if enumeration type mismatch in conditional expression

2019-10-01 Thread Dávid Bolvanský via cfe-commits
Sorry, answered on phone, missed it. I looked at your buildbots for
chromium and yeah, so many warnings. I will make it off by default.

ut 1. 10. 2019 o 19:58 Dávid Bolvanský  napísal(a):
>
> (Not sure if you intentionally didn't reply-all.)
>
> Sorry, answered on phone, missed it. I looked at your buildbots for
> chromium and yeah, so many warnings. I will make it off by default.
>
> ut 1. 10. 2019 o 19:17 Nico Weber  napísal(a):
>
> >
> > (Not sure if you intentionally didn't reply-all.)
> >
> > We should probably write it down, but clang's warning philosophy is that 
> > warnings should be very high-signal. The usual way to prove this is to 
> > build some large open-source codebase with the warning and counting true 
> > and false positives.
> >
> > Just "gcc has it" isn't sufficient motivation – gcc has lots of not so good 
> > warnings :)
> >
> > ps: To be clear, I appreciate all your work to add warnings a lot! It's 
> > very useful. It's also possible that this warning is useful, but it's not 
> > immediately clear, so there should be some data to back it up.
> >
> > On Tue, Oct 1, 2019 at 12:12 PM Dávid Bolvanský  
> > wrote:
> >>
> >> I hit this bug myself, GCC warned me with -Wenum-compare, Clang was 
> >> silent. Clang “supports” this flag, but failed to catch it. Either Clang 
> >> should not pretend that it supports this flag (and all related 
> >> functionality) or should support it fully. Basically, new warnings will 
> >> show up only for Clang-only environments.
> >>
> >> I think the own subgroup is a good compromise for now.  We can still make 
> >> it off by default before next release if we decide so.
> >>
> >> Dňa 1. 10. 2019 o 17:56 užívateľ Nico Weber  napísal:
> >>
> >> 
> >> Thanks!
> >>
> >> Any thoughts on the true positive rate for this warning?
> >>
> >> On Tue, Oct 1, 2019 at 11:43 AM Dávid Bolvanský 
> >>  wrote:
> >>>
> >>> Yeah, I moved this warning into own subgroup in rL373345. Thanks.
> >>>
> >>> ut 1. 10. 2019 o 16:24 Nico Weber  napísal(a):
> >>> >
> >>> > Can we move this behind a Wenum-compare subgroup, say 
> >>> > Wenum-compare-type? Our codebase is (well, was) Wenum-compare clean, 
> >>> > and this new warnings fires pretty often and from a first quick glance 
> >>> > the warning looks pretty low-signal anyways (*). Maybe the subgroup 
> >>> > shouldn't even be on by default -- do you have any data on true / false 
> >>> > positive rate of this?
> >>> >
> >>> > (But for starters, just having a way to turn this off is enough.)
> >>> >
> >>> > For example, we have a windows common control that's either a PGRP_DOWN 
> >>> > or a PGRP_UP page control and depending on which you store the control 
> >>> > state in the same int, then stuff like `return extra.inner_spin.spin_up 
> >>> > ? UPS_DISABLED : DNS_DISABLED;`.
> >>> >
> >>> > On Mon, Sep 30, 2019 at 3:53 PM David Bolvansky via cfe-commits 
> >>> >  wrote:
> >>> >>
> >>> >> Author: xbolva00
> >>> >> Date: Mon Sep 30 12:55:50 2019
> >>> >> New Revision: 373252
> >>> >>
> >>> >> URL: http://llvm.org/viewvc/llvm-project?rev=373252&view=rev
> >>> >> Log:
> >>> >> [Diagnostics] Warn if enumeration type mismatch in conditional 
> >>> >> expression
> >>> >>
> >>> >> Summary:
> >>> >> - Useful warning
> >>> >> - GCC compatibility (GCC warns in C++ mode)
> >>> >>
> >>> >> Reviewers: rsmith, aaron.ballman
> >>> >>
> >>> >> Reviewed By: aaron.ballman
> >>> >>
> >>> >> Subscribers: cfe-commits
> >>> >>
> >>> >> Tags: #clang
> >>> >>
> >>> >> Differential Revision: https://reviews.llvm.org/D67919
> >>> >>
> >>> >> Added:
> >>> >> cfe/trunk/test/Sema/warn-conditional-emum-types-mismatch.c
> >>> >> Modified:
> >>> >> cfe/trunk/lib/Sema/SemaChecking.cpp
> >>> >>
> >>> >> Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
> >>> >> URL: 
> >>> >> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=373252&r1=373251&r2=373252&view=diff
> >>> >> ==
> >>> >> --- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
> >>> >> +++ cfe/trunk/lib/Sema/SemaChecking.cpp Mon Sep 30 12:55:50 2019
> >>> >> @@ -11308,6 +11308,32 @@ static const IntegerLiteral *getIntegerL
> >>> >>return IL;
> >>> >>  }
> >>> >>
> >>> >> +static void CheckConditionalWithEnumTypes(Sema &S, SourceLocation Loc,
> >>> >> +  Expr *LHS, Expr *RHS) {
> >>> >> +  QualType LHSStrippedType = LHS->IgnoreParenImpCasts()->getType();
> >>> >> +  QualType RHSStrippedType = RHS->IgnoreParenImpCasts()->getType();
> >>> >> +
> >>> >> +  const auto *LHSEnumType = LHSStrippedType->getAs();
> >>> >> +  if (!LHSEnumType)
> >>> >> +return;
> >>> >> +  const auto *RHSEnumType = RHSStrippedType->getAs();
> >>> >> +  if (!RHSEnumType)
> >>> >> +return;
> >>> >> +
> >>> >> +  // Ignore anonymous enums.
> >>> >> +  if (!LHSEnumType->getDecl()->hasNameForLinkage())
> >>> >> +return;
> >>> >> +  if (!RHSEnumType->getDecl()->hasNameForLinkage

[PATCH] D68029: [ThinLTO] Enable index-only WPD from clang

2019-10-01 Thread Peter Collingbourne via Phabricator via cfe-commits
pcc accepted this revision.
pcc added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rC Clang

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

https://reviews.llvm.org/D68029



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


[PATCH] D68029: [ThinLTO] Enable index-only WPD from clang

2019-10-01 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson added a comment.
Herald added a subscriber: hiraditya.

Ping


Repository:
  rC Clang

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

https://reviews.llvm.org/D68029



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


r373348 - [OPENMP]Fix PR43516: Compiler crash with collapse(2) on non-rectangular

2019-10-01 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Tue Oct  1 09:19:10 2019
New Revision: 373348

URL: http://llvm.org/viewvc/llvm-project?rev=373348&view=rev
Log:
[OPENMP]Fix PR43516: Compiler crash with collapse(2) on non-rectangular
loop.

Missed check if the condition is also dependent when building final
expressions for the collapsed loop directives.

Modified:
cfe/trunk/lib/Sema/SemaOpenMP.cpp
cfe/trunk/test/OpenMP/for_codegen.cpp

Modified: cfe/trunk/lib/Sema/SemaOpenMP.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOpenMP.cpp?rev=373348&r1=373347&r2=373348&view=diff
==
--- cfe/trunk/lib/Sema/SemaOpenMP.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOpenMP.cpp Tue Oct  1 09:19:10 2019
@@ -6247,13 +6247,21 @@ Expr *OpenMPIterationSpaceChecker::build
 Expr *OpenMPIterationSpaceChecker::buildPreCond(
 Scope *S, Expr *Cond,
 llvm::MapVector &Captures) const {
+  // Do not build a precondition when the condition/initialization is dependent
+  // to prevent pessimistic early loop exit.
+  // TODO: this can be improved by calculating min/max values but not sure that
+  // it will be very effective.
+  if (CondDependOnLC || InitDependOnLC)
+return SemaRef.PerformImplicitConversion(
+SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get(),
+SemaRef.Context.BoolTy, /*Action=*/Sema::AA_Casting,
+/*AllowExplicit=*/true).get();
+
   // Try to build LB  UB, where  is <, >, <=, or >=.
   Sema::TentativeAnalysisScope Trap(SemaRef);
 
-  ExprResult NewLB =
-  InitDependOnLC ? LB : tryBuildCapture(SemaRef, LB, Captures);
-  ExprResult NewUB =
-  CondDependOnLC ? UB : tryBuildCapture(SemaRef, UB, Captures);
+  ExprResult NewLB = tryBuildCapture(SemaRef, LB, Captures);
+  ExprResult NewUB = tryBuildCapture(SemaRef, UB, Captures);
   if (!NewLB.isUsable() || !NewUB.isUsable())
 return nullptr;
 
@@ -7425,7 +7433,7 @@ checkOpenMPLoop(OpenMPDirectiveKind DKin
   Built.DependentCounters[Cnt] = nullptr;
   Built.DependentInits[Cnt] = nullptr;
   Built.FinalsConditions[Cnt] = nullptr;
-  if (IS.IsNonRectangularLB) {
+  if (IS.IsNonRectangularLB || IS.IsNonRectangularUB) {
 Built.DependentCounters[Cnt] =
 Built.Counters[NestedLoopCount - 1 - IS.LoopDependentIdx];
 Built.DependentInits[Cnt] =

Modified: cfe/trunk/test/OpenMP/for_codegen.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/for_codegen.cpp?rev=373348&r1=373347&r2=373348&view=diff
==
--- cfe/trunk/test/OpenMP/for_codegen.cpp (original)
+++ cfe/trunk/test/OpenMP/for_codegen.cpp Tue Oct  1 09:19:10 2019
@@ -89,23 +89,6 @@ void loop_with_counter_collapse() {
   // CHECK: [[NUM_ITERS_VAL:%.+]] = sub nsw i64 [[MUL]], 1
   // CHECK: store i64 [[NUM_ITERS_VAL]], i64* [[NUM_ITERS:%.+]],
 
-  // Initialization
-  // CHECK: store i32 0, i32* [[I:%.+]],
-  // CHECK: [[I_INIT:%.+]] = load i32, i32* [[I]],
-  // CHECK: store i32 [[I_INIT]], i32* [[J:%.+]],
-
-  // LIFETIME: call void @llvm.lifetime.end
-  // LIFETIME: call void @llvm.lifetime.end
-
-  // Precondition for j counter
-  // CHECK: store i32 0, i32* [[TMP_I:%.+]],
-  // CHECK: [[J_LB_VAL:%.+]] = load i32, i32* [[TMP_I]],
-  // CHECK: [[I_VAL:%.+]] = load i32, i32* [[TMP_I]],
-  // CHECK: [[J_UB_VAL:%.+]] = add nsw i32 4, [[I_VAL]]
-  // CHECK: [[CMP:%.+]] = icmp slt i32 [[J_LB_VAL]], [[J_UB_VAL]]
-  // CHECK: br i1 [[CMP]], label %[[THEN:[^,]+]], label %[[ELSE:[^,]+]]
-
-  // CHECK: [[THEN]]:
   // CHECK: store i64 0, i64* [[LB:%.+]],
   // CHECK: [[NUM_ITERS_VAL:%.+]] = load i64, i64* [[NUM_ITERS]],
   // CHECK: store i64 [[NUM_ITERS_VAL]], i64* [[UB:%.+]],
@@ -633,6 +616,22 @@ void for_with_references() {
 k = cnt;
 }
 
+// CHECK-LABEL: for_with_references_dep_cond
+void for_with_references_dep_cond() {
+// CHECK: [[I:%.+]] = alloca i8,
+// CHECK: [[CNT:%.+]] = alloca i8*,
+// CHECK: [[CNT_PRIV:%.+]] = alloca i8,
+// CHECK: call void @__kmpc_for_static_init_8(
+// CHECK-NOT: load i8, i8* [[CNT]],
+// CHECK: call void @__kmpc_for_static_fini(
+  char i = 0;
+  char &cnt = i;
+#pragma omp for collapse(2)
+  for (cnt = 0; cnt < 2; ++cnt)
+for (int j = 0; j < 4 + cnt; j++)
+k = cnt;
+}
+
 struct Bool {
   Bool(bool b) : b(b) {}
   operator bool() const { return b; }


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


[PATCH] D62686: [RISCV] Add support for save/restore of callee-saved registers via libcalls

2019-10-01 Thread Lewis Revill via Phabricator via cfe-commits
lewis-revill updated this revision to Diff 222612.
lewis-revill added a comment.

Rewrote logic to calculate stack sizes, frame indexes and frame pointer 
offsets. This was necessary to take into account the fact that the save/restore 
lib calls are essentially an opaque section of the stack that is inserted at 
the beginning of the frame, after positive offset objects such as fixed stack 
arguments, but before additional callee saved registers (IE FP registers) and 
negative offset (dynamic) objects. So calculations of the actual offsets of 
these objects must be adjusted accordingly for the stack to function correctly.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D62686

Files:
  clang/lib/Driver/ToolChains/Arch/RISCV.cpp
  clang/test/Driver/riscv-features.c
  llvm/lib/Target/RISCV/RISCV.td
  llvm/lib/Target/RISCV/RISCVFrameLowering.cpp
  llvm/lib/Target/RISCV/RISCVFrameLowering.h
  llvm/lib/Target/RISCV/RISCVMachineFunctionInfo.h
  llvm/lib/Target/RISCV/RISCVRegisterInfo.cpp
  llvm/lib/Target/RISCV/RISCVRegisterInfo.h
  llvm/lib/Target/RISCV/RISCVSubtarget.h
  llvm/test/CodeGen/RISCV/saverestore.ll

Index: llvm/test/CodeGen/RISCV/saverestore.ll
===
--- /dev/null
+++ llvm/test/CodeGen/RISCV/saverestore.ll
@@ -0,0 +1,640 @@
+; RUN: llc -mtriple=riscv32 < %s | FileCheck %s -check-prefix=RV32I
+; RUN: llc -mtriple=riscv64 < %s | FileCheck %s -check-prefix=RV64I
+; RUN: llc -mtriple=riscv32 -mattr=+save-restore < %s | FileCheck %s -check-prefix=RV32I-SR
+; RUN: llc -mtriple=riscv64 -mattr=+save-restore < %s | FileCheck %s -check-prefix=RV64I-SR
+; RUN: llc -mtriple=riscv32 -mattr=+f,+save-restore -target-abi=ilp32f < %s | FileCheck %s -check-prefix=RV32I-FP-SR
+; RUN: llc -mtriple=riscv64 -mattr=+f,+d,+save-restore -target-abi=lp64d < %s | FileCheck %s -check-prefix=RV64I-FP-SR
+
+; Check that the correct save/restore libcalls are generated.
+
+@var0 = global [18 x i32] zeroinitializer
+@var1 = global [24 x i32] zeroinitializer
+@var2 = global [30 x i32] zeroinitializer
+
+define void @callee_saved0() nounwind {
+; RV32I-LABEL: callee_saved0:
+; RV32I: addi sp, sp, -32
+; RV32I-NEXT:sw s0, 28(sp)
+; RV32I-NEXT:sw s1, 24(sp)
+; RV32I-NEXT:sw s2, 20(sp)
+; RV32I-NEXT:sw s3, 16(sp)
+; RV32I-NEXT:sw s4, 12(sp)
+; RV32I: lw s4, 12(sp)
+; RV32I-NEXT:lw s3, 16(sp)
+; RV32I-NEXT:lw s2, 20(sp)
+; RV32I-NEXT:lw s1, 24(sp)
+; RV32I-NEXT:lw s0, 28(sp)
+; RV32I-NEXT:addi sp, sp, 32
+; RV32I-NEXT:ret
+;
+; RV64I-LABEL: callee_saved0:
+; RV64I: addi sp, sp, -48
+; RV64I-NEXT:sd s0, 40(sp)
+; RV64I-NEXT:sd s1, 32(sp)
+; RV64I-NEXT:sd s2, 24(sp)
+; RV64I-NEXT:sd s3, 16(sp)
+; RV64I: ld s4, 8(sp)
+; RV64I-NEXT:ld s3, 16(sp)
+; RV64I-NEXT:ld s2, 24(sp)
+; RV64I-NEXT:ld s1, 32(sp)
+; RV64I-NEXT:ld s0, 40(sp)
+; RV64I-NEXT:addi sp, sp, 48
+; RV64I-NEXT:ret
+;
+; RV32I-SR-LABEL: callee_saved0:
+; RV32I-SR: call t0, __riscv_save_5
+; RV32I-SR: tail __riscv_restore_5
+;
+; RV64I-SR-LABEL: callee_saved0:
+; RV64I-SR: call t0, __riscv_save_5
+; RV64I-SR: tail __riscv_restore_5
+;
+; RV32I-FP-SR-LABEL: callee_saved0:
+; RV32I-FP-SR: call t0, __riscv_save_5
+; RV32I-FP-SR: tail __riscv_restore_5
+;
+; RV64I-FP-SR-LABEL: callee_saved0:
+; RV64I-FP-SR: call t0, __riscv_save_5
+; RV64I-FP-SR: tail __riscv_restore_5
+  %val = load [18 x i32], [18 x i32]* @var0
+  store volatile [18 x i32] %val, [18 x i32]* @var0
+  ret void
+}
+
+define void @callee_saved1() nounwind {
+; RV32I-LABEL: callee_saved1:
+; RV32I: addi sp, sp, -48
+; RV32I-NEXT:sw s0, 44(sp)
+; RV32I-NEXT:sw s1, 40(sp)
+; RV32I-NEXT:sw s2, 36(sp)
+; RV32I-NEXT:sw s3, 32(sp)
+; RV32I-NEXT:sw s4, 28(sp)
+; RV32I-NEXT:sw s5, 24(sp)
+; RV32I-NEXT:sw s6, 20(sp)
+; RV32I-NEXT:sw s7, 16(sp)
+; RV32I-NEXT:sw s8, 12(sp)
+; RV32I-NEXT:sw s9, 8(sp)
+; RV32I-NEXT:sw s10, 4(sp)
+; RV32I: lw s10, 4(sp)
+; RV32I-NEXT:lw s9, 8(sp)
+; RV32I-NEXT:lw s8, 12(sp)
+; RV32I-NEXT:lw s7, 16(sp)
+; RV32I-NEXT:lw s6, 20(sp)
+; RV32I-NEXT:lw s5, 24(sp)
+; RV32I-NEXT:lw s4, 28(sp)
+; RV32I-NEXT:lw s3, 32(sp)
+; RV32I-NEXT:lw s2, 36(sp)
+; RV32I-NEXT:lw s1, 40(sp)
+; RV32I-NEXT:lw s0, 44(sp)
+; RV32I-NEXT:addi sp, sp, 48
+; RV32I-NEXT:ret
+;
+; RV64I-LABEL: callee_saved1:
+; RV64I: addi sp, sp, -96
+; RV64I-NEXT:sd s0, 88(sp)
+; RV64I-NEXT:sd s1, 80(sp)
+; RV64I-NEXT:sd s2, 72(sp)
+; RV64I-NEXT:sd s3, 64(sp)
+; RV64I-NEXT:sd s4, 56(sp)
+; RV64I-NEXT:sd s5, 48(sp)
+; RV64I-NEXT:sd s6, 40(sp)
+; RV64I-NEXT:sd s7, 32(sp)
+; RV64I-NEXT:sd s8, 24(sp)
+; RV64I-NEXT:sd s9, 16(sp)
+; RV64I-NEXT:sd s10, 8(sp)
+; RV64I: ld s10,

Re: r373252 - [Diagnostics] Warn if enumeration type mismatch in conditional expression

2019-10-01 Thread Nico Weber via cfe-commits
Thanks!

Any thoughts on the true positive rate for this warning?

On Tue, Oct 1, 2019 at 11:43 AM Dávid Bolvanský 
wrote:

> Yeah, I moved this warning into own subgroup in rL373345. Thanks.
>
> ut 1. 10. 2019 o 16:24 Nico Weber  napísal(a):
> >
> > Can we move this behind a Wenum-compare subgroup, say
> Wenum-compare-type? Our codebase is (well, was) Wenum-compare clean, and
> this new warnings fires pretty often and from a first quick glance the
> warning looks pretty low-signal anyways (*). Maybe the subgroup shouldn't
> even be on by default -- do you have any data on true / false positive rate
> of this?
> >
> > (But for starters, just having a way to turn this off is enough.)
> >
> > For example, we have a windows common control that's either a PGRP_DOWN
> or a PGRP_UP page control and depending on which you store the control
> state in the same int, then stuff like `return extra.inner_spin.spin_up ?
> UPS_DISABLED : DNS_DISABLED;`.
> >
> > On Mon, Sep 30, 2019 at 3:53 PM David Bolvansky via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
> >>
> >> Author: xbolva00
> >> Date: Mon Sep 30 12:55:50 2019
> >> New Revision: 373252
> >>
> >> URL: http://llvm.org/viewvc/llvm-project?rev=373252&view=rev
> >> Log:
> >> [Diagnostics] Warn if enumeration type mismatch in conditional
> expression
> >>
> >> Summary:
> >> - Useful warning
> >> - GCC compatibility (GCC warns in C++ mode)
> >>
> >> Reviewers: rsmith, aaron.ballman
> >>
> >> Reviewed By: aaron.ballman
> >>
> >> Subscribers: cfe-commits
> >>
> >> Tags: #clang
> >>
> >> Differential Revision: https://reviews.llvm.org/D67919
> >>
> >> Added:
> >> cfe/trunk/test/Sema/warn-conditional-emum-types-mismatch.c
> >> Modified:
> >> cfe/trunk/lib/Sema/SemaChecking.cpp
> >>
> >> Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
> >> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=373252&r1=373251&r2=373252&view=diff
> >>
> ==
> >> --- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
> >> +++ cfe/trunk/lib/Sema/SemaChecking.cpp Mon Sep 30 12:55:50 2019
> >> @@ -11308,6 +11308,32 @@ static const IntegerLiteral *getIntegerL
> >>return IL;
> >>  }
> >>
> >> +static void CheckConditionalWithEnumTypes(Sema &S, SourceLocation Loc,
> >> +  Expr *LHS, Expr *RHS) {
> >> +  QualType LHSStrippedType = LHS->IgnoreParenImpCasts()->getType();
> >> +  QualType RHSStrippedType = RHS->IgnoreParenImpCasts()->getType();
> >> +
> >> +  const auto *LHSEnumType = LHSStrippedType->getAs();
> >> +  if (!LHSEnumType)
> >> +return;
> >> +  const auto *RHSEnumType = RHSStrippedType->getAs();
> >> +  if (!RHSEnumType)
> >> +return;
> >> +
> >> +  // Ignore anonymous enums.
> >> +  if (!LHSEnumType->getDecl()->hasNameForLinkage())
> >> +return;
> >> +  if (!RHSEnumType->getDecl()->hasNameForLinkage())
> >> +return;
> >> +
> >> +  if (S.Context.hasSameUnqualifiedType(LHSStrippedType,
> RHSStrippedType))
> >> +return;
> >> +
> >> +  S.Diag(Loc, diag::warn_conditional_mixed_enum_types)
> >> +  << LHSStrippedType << RHSStrippedType << LHS->getSourceRange()
> >> +  << RHS->getSourceRange();
> >> +}
> >> +
> >>  static void DiagnoseIntInBoolContext(Sema &S, Expr *E) {
> >>E = E->IgnoreParenImpCasts();
> >>SourceLocation ExprLoc = E->getExprLoc();
> >> @@ -11799,6 +11825,8 @@ static void CheckConditionalOperator(Sem
> >>bool Suspicious = false;
> >>CheckConditionalOperand(S, E->getTrueExpr(), T, CC, Suspicious);
> >>CheckConditionalOperand(S, E->getFalseExpr(), T, CC, Suspicious);
> >> +  CheckConditionalWithEnumTypes(S, E->getBeginLoc(), E->getTrueExpr(),
> >> +E->getFalseExpr());
> >>
> >>if (T->isBooleanType())
> >>  DiagnoseIntInBoolContext(S, E);
> >>
> >> Added: cfe/trunk/test/Sema/warn-conditional-emum-types-mismatch.c
> >> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/warn-conditional-emum-types-mismatch.c?rev=373252&view=auto
> >>
> ==
> >> --- cfe/trunk/test/Sema/warn-conditional-emum-types-mismatch.c (added)
> >> +++ cfe/trunk/test/Sema/warn-conditional-emum-types-mismatch.c Mon Sep
> 30 12:55:50 2019
> >> @@ -0,0 +1,39 @@
> >> +// RUN: %clang_cc1 -x c -fsyntax-only -verify -Wenum-compare %s
> >> +// RUN: %clang_cc1 -x c -fsyntax-only -verify  %s
> >> +// RUN: %clang_cc1 -x c++ -fsyntax-only -verify -Wenum-compare %s
> >> +// RUN: %clang_cc1 -x c++ -fsyntax-only -verify %s
> >> +
> >> +enum ro { A = 0x10 };
> >> +enum rw { B = 0xFF };
> >> +enum { C = 0x1A};
> >> +
> >> +enum {
> >> +  STATUS_SUCCESS,
> >> +  STATUS_FAILURE,
> >> +  MAX_BASE_STATUS_CODE
> >> +};
> >> +
> >> +enum ExtendedStatusCodes {
> >> +  STATUS_SOMETHING_INTERESTING = MAX_BASE_STATUS_CODE + 1000,
> >> +};
> >> +
> >> +
> >> +int get_flag(int cond) {
> >> +  return cond ? A : B;
> >

Re: r373252 - [Diagnostics] Warn if enumeration type mismatch in conditional expression

2019-10-01 Thread Dávid Bolvanský via cfe-commits
Yeah, I moved this warning into own subgroup in rL373345. Thanks.

ut 1. 10. 2019 o 16:24 Nico Weber  napísal(a):
>
> Can we move this behind a Wenum-compare subgroup, say Wenum-compare-type? Our 
> codebase is (well, was) Wenum-compare clean, and this new warnings fires 
> pretty often and from a first quick glance the warning looks pretty 
> low-signal anyways (*). Maybe the subgroup shouldn't even be on by default -- 
> do you have any data on true / false positive rate of this?
>
> (But for starters, just having a way to turn this off is enough.)
>
> For example, we have a windows common control that's either a PGRP_DOWN or a 
> PGRP_UP page control and depending on which you store the control state in 
> the same int, then stuff like `return extra.inner_spin.spin_up ? UPS_DISABLED 
> : DNS_DISABLED;`.
>
> On Mon, Sep 30, 2019 at 3:53 PM David Bolvansky via cfe-commits 
>  wrote:
>>
>> Author: xbolva00
>> Date: Mon Sep 30 12:55:50 2019
>> New Revision: 373252
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=373252&view=rev
>> Log:
>> [Diagnostics] Warn if enumeration type mismatch in conditional expression
>>
>> Summary:
>> - Useful warning
>> - GCC compatibility (GCC warns in C++ mode)
>>
>> Reviewers: rsmith, aaron.ballman
>>
>> Reviewed By: aaron.ballman
>>
>> Subscribers: cfe-commits
>>
>> Tags: #clang
>>
>> Differential Revision: https://reviews.llvm.org/D67919
>>
>> Added:
>> cfe/trunk/test/Sema/warn-conditional-emum-types-mismatch.c
>> Modified:
>> cfe/trunk/lib/Sema/SemaChecking.cpp
>>
>> Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
>> URL: 
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=373252&r1=373251&r2=373252&view=diff
>> ==
>> --- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
>> +++ cfe/trunk/lib/Sema/SemaChecking.cpp Mon Sep 30 12:55:50 2019
>> @@ -11308,6 +11308,32 @@ static const IntegerLiteral *getIntegerL
>>return IL;
>>  }
>>
>> +static void CheckConditionalWithEnumTypes(Sema &S, SourceLocation Loc,
>> +  Expr *LHS, Expr *RHS) {
>> +  QualType LHSStrippedType = LHS->IgnoreParenImpCasts()->getType();
>> +  QualType RHSStrippedType = RHS->IgnoreParenImpCasts()->getType();
>> +
>> +  const auto *LHSEnumType = LHSStrippedType->getAs();
>> +  if (!LHSEnumType)
>> +return;
>> +  const auto *RHSEnumType = RHSStrippedType->getAs();
>> +  if (!RHSEnumType)
>> +return;
>> +
>> +  // Ignore anonymous enums.
>> +  if (!LHSEnumType->getDecl()->hasNameForLinkage())
>> +return;
>> +  if (!RHSEnumType->getDecl()->hasNameForLinkage())
>> +return;
>> +
>> +  if (S.Context.hasSameUnqualifiedType(LHSStrippedType, RHSStrippedType))
>> +return;
>> +
>> +  S.Diag(Loc, diag::warn_conditional_mixed_enum_types)
>> +  << LHSStrippedType << RHSStrippedType << LHS->getSourceRange()
>> +  << RHS->getSourceRange();
>> +}
>> +
>>  static void DiagnoseIntInBoolContext(Sema &S, Expr *E) {
>>E = E->IgnoreParenImpCasts();
>>SourceLocation ExprLoc = E->getExprLoc();
>> @@ -11799,6 +11825,8 @@ static void CheckConditionalOperator(Sem
>>bool Suspicious = false;
>>CheckConditionalOperand(S, E->getTrueExpr(), T, CC, Suspicious);
>>CheckConditionalOperand(S, E->getFalseExpr(), T, CC, Suspicious);
>> +  CheckConditionalWithEnumTypes(S, E->getBeginLoc(), E->getTrueExpr(),
>> +E->getFalseExpr());
>>
>>if (T->isBooleanType())
>>  DiagnoseIntInBoolContext(S, E);
>>
>> Added: cfe/trunk/test/Sema/warn-conditional-emum-types-mismatch.c
>> URL: 
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/warn-conditional-emum-types-mismatch.c?rev=373252&view=auto
>> ==
>> --- cfe/trunk/test/Sema/warn-conditional-emum-types-mismatch.c (added)
>> +++ cfe/trunk/test/Sema/warn-conditional-emum-types-mismatch.c Mon Sep 30 
>> 12:55:50 2019
>> @@ -0,0 +1,39 @@
>> +// RUN: %clang_cc1 -x c -fsyntax-only -verify -Wenum-compare %s
>> +// RUN: %clang_cc1 -x c -fsyntax-only -verify  %s
>> +// RUN: %clang_cc1 -x c++ -fsyntax-only -verify -Wenum-compare %s
>> +// RUN: %clang_cc1 -x c++ -fsyntax-only -verify %s
>> +
>> +enum ro { A = 0x10 };
>> +enum rw { B = 0xFF };
>> +enum { C = 0x1A};
>> +
>> +enum {
>> +  STATUS_SUCCESS,
>> +  STATUS_FAILURE,
>> +  MAX_BASE_STATUS_CODE
>> +};
>> +
>> +enum ExtendedStatusCodes {
>> +  STATUS_SOMETHING_INTERESTING = MAX_BASE_STATUS_CODE + 1000,
>> +};
>> +
>> +
>> +int get_flag(int cond) {
>> +  return cond ? A : B;
>> +  #ifdef __cplusplus
>> +  // expected-warning@-2 {{enumeration type mismatch in conditional 
>> expression ('ro' and 'rw')}}
>> +  #else
>> +  // expected-no-diagnostics
>> +  #endif
>> +}
>> +
>> +// In the following cases we purposefully differ from GCC and dont warn 
>> because
>> +// this code pattern is quite sensitive and we dont want to produce so many 
>> false posi

r373345 - [Diagnostics] Move warning into the subgroup (-Wenum-compare-conditional)

2019-10-01 Thread David Bolvansky via cfe-commits
Author: xbolva00
Date: Tue Oct  1 08:44:38 2019
New Revision: 373345

URL: http://llvm.org/viewvc/llvm-project?rev=373345&view=rev
Log:
[Diagnostics] Move warning into the subgroup (-Wenum-compare-conditional)


Modified:
cfe/trunk/include/clang/Basic/DiagnosticGroups.td
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/test/Sema/warn-conditional-emum-types-mismatch.c

Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticGroups.td?rev=373345&r1=373344&r2=373345&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticGroups.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticGroups.td Tue Oct  1 08:44:38 2019
@@ -563,8 +563,9 @@ def CoveredSwitchDefault : DiagGroup<"co
 def SwitchBool : DiagGroup<"switch-bool">;
 def SwitchEnum : DiagGroup<"switch-enum">;
 def Switch : DiagGroup<"switch">;
+def EnumCompareConditional : DiagGroup<"enum-compare-conditional">;
 def EnumCompareSwitch : DiagGroup<"enum-compare-switch">;
-def EnumCompare   : DiagGroup<"enum-compare", [EnumCompareSwitch]>;
+def EnumCompare   : DiagGroup<"enum-compare", [EnumCompareConditional, 
EnumCompareSwitch]>;
 def ImplicitFallthroughPerFunction :
   DiagGroup<"implicit-fallthrough-per-function">;
 def ImplicitFallthrough  : DiagGroup<"implicit-fallthrough",

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=373345&r1=373344&r2=373345&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Oct  1 08:44:38 
2019
@@ -6172,7 +6172,7 @@ def warn_comparison_of_mixed_enum_types
 def warn_conditional_mixed_enum_types : Warning<
   "enumeration type mismatch in conditional expression"
   "%diff{ ($ and $)|}0,1">,
-  InGroup;
+  InGroup;
 def warn_comparison_of_mixed_enum_types_switch : Warning<
   "comparison of two values with different enumeration types in switch 
statement"
   "%diff{ ($ and $)|}0,1">,

Modified: cfe/trunk/test/Sema/warn-conditional-emum-types-mismatch.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/warn-conditional-emum-types-mismatch.c?rev=373345&r1=373344&r2=373345&view=diff
==
--- cfe/trunk/test/Sema/warn-conditional-emum-types-mismatch.c (original)
+++ cfe/trunk/test/Sema/warn-conditional-emum-types-mismatch.c Tue Oct  1 
08:44:38 2019
@@ -1,5 +1,7 @@
+// RUN: %clang_cc1 -x c -fsyntax-only -verify -Wenum-compare-conditional %s
 // RUN: %clang_cc1 -x c -fsyntax-only -verify -Wenum-compare %s
 // RUN: %clang_cc1 -x c -fsyntax-only -verify  %s
+// RUN: %clang_cc1 -x c++ -fsyntax-only -verify -Wenum-compare-conditional %s
 // RUN: %clang_cc1 -x c++ -fsyntax-only -verify -Wenum-compare %s
 // RUN: %clang_cc1 -x c++ -fsyntax-only -verify %s
 


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


[PATCH] D14484: [clang-format] Formatting constructor initializer lists by putting them always on different lines

2019-10-01 Thread Pooya Daravi via Phabricator via cfe-commits
puya added a comment.

> Looking at this I'm wondering if this Isn't at least partially handled by the 
> BreakConstructorInitializersStyle in combination with 
> ConstructorInitializerAllOnOneLineOrOnePerLine style?

I’m fairly certain that’s only true when line is long enough to be broken. In 
which case second one ensures one per line (as opposed to different number of 
initializations per line) and the first one determines the style. They would 
not result in the requestes behavior if the line is not longer than max column. 
(I will double check when I am in front of a computer)


Repository:
  rL LLVM

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

https://reviews.llvm.org/D14484



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


[PATCH] D67901: [clangd] Improve semantic highlighting in dependent contexts (fixes #154)

2019-10-01 Thread Haojian Wu via Phabricator via cfe-commits
hokein added a comment.

In D67901#1687308 , @nridge wrote:

> I do feel strongly that types and non-types should be highlighted 
> differently, so the updated patch adds two new dependent highlightings, one 
> for types and one for variables/functions.


I see your point here, no objection.




Comment at: clang-tools-extra/clangd/SemanticHighlighting.cpp:156
+  bool VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E) {
+if (canHighlightName(E->getName())) {
+  addToken(E->getNameLoc(), HighlightingKind::DependentName);

nit: remove the `{}` and elsewhere, LLVM prefers not adding `{}` if the body 
only contains a single statement.



Comment at: clang-tools-extra/clangd/SemanticHighlighting.cpp:163
+  bool VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E) {
+if (canHighlightName(E->getMemberName())) {
+  addToken(E->getNameLoc(), HighlightingKind::DependentName);

I think we should use `E->getName()` since we are highlighting the `NameLoc` 
below.



Comment at: clang-tools-extra/clangd/SemanticHighlighting.cpp:219
+  bool VisitDependentNameTypeLoc(DependentNameTypeLoc L) {
+addToken(L.getNameLoc(), HighlightingKind::DependentType);
+return true;

nit: we have `kindForType` for hanlding all types, so I'd move the logic of 
detecting the dependent type there.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D67901



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


[PATCH] D67706: [clang][analyzer] Using CallDescription in StreamChecker.

2019-10-01 Thread Balázs Kéri via Phabricator via cfe-commits
balazske marked 2 inline comments as done.
balazske added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp:109-110
 bool StreamChecker::evalCall(const CallEvent &Call, CheckerContext &C) const {
+  if (!Call.isGlobalCFunction())
+return false;
+

Szelethus wrote:
> balazske wrote:
> > Szelethus wrote:
> > > Isn't this redundant with my other inline about parameter types?
> > Probably change to `isInSystemHeader` or use both?
> Actually, this looks fine. How about preserving this...
Should be the "stream functions" always in system header? If no 
`isInSystemHeader` call is used any global function called "fopen" with 2 
arguments is recognized as stream opening function. If it returns a pointer and 
no "fclose" is called on that we will get a resource leak warning for that 
code. (But for this case the user will probably not enable the checker?).



Comment at: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp:127-131
+  for (auto P : Call.parameters()) {
+QualType T = P->getType();
+if (!T->isIntegralOrEnumerationType() && !T->isPointerType())
+  return nullptr;
+  }

Szelethus wrote:
> Szelethus wrote:
> > balazske wrote:
> > > Szelethus wrote:
> > > > I'm not sure why we need this, is it true that *all* stream related 
> > > > functions return a pointer or a numerical value? Are we actually 
> > > > checking whether this really is a library function? If so, this looks 
> > > > pretty arbitrary.
> > > This comes from code of CStringChecker:
> > > ```
> > >   // Pro-actively check that argument types are safe to do arithmetic 
> > > upon.
> > >   // We do not want to crash if someone accidentally passes a structure
> > >   // into, say, a C++ overload of any of these functions. We could not 
> > > check
> > >   // that for std::copy because they may have arguments of other types.
> > > ```
> > > Still I am not sure that the checker works correct with code that 
> > > contains similar named but "arbitrary" functions.
> > Oops, meant to write that ", is it true that *all* stream related functions 
> > have only pointer or a numerical parameters?".
> ...and removing this one, or changing it to an assert?
This can not be an assert because it is possible to have global functions with 
same name but different signature. The check can be kept to filter out such 
cases. The wanted stream functions have only integral or enum or pointer 
arguments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D67706



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


[PATCH] D68273: [clangd] Fix raciness in code completion tests

2019-10-01 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 222618.
kadircet added a comment.

- As discussed offline, making `consumeRequests` take an argument for how many 
requests to receive before returning.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D68273

Files:
  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
@@ -27,6 +27,8 @@
 #include "llvm/Testing/Support/Error.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
+#include 
+#include 
 
 namespace clang {
 namespace clangd {
@@ -1112,8 +1114,10 @@
   bool
   fuzzyFind(const FuzzyFindRequest &Req,
 llvm::function_ref Callback) const override {
-std::lock_guard Lock(Mut);
+std::unique_lock Lock(Mut);
 Requests.push_back(Req);
+++NumRequestsReceived;
+ReceivedRequestCV.notify_one();
 return true;
   }
 
@@ -1131,8 +1135,11 @@
   // isn't used in production code.
   size_t estimateMemoryUsage() const override { return 0; }
 
-  const std::vector consumeRequests() const {
-std::lock_guard Lock(Mut);
+  const std::vector consumeRequests(size_t Num) const {
+std::unique_lock Lock(Mut);
+ReceivedRequestCV.wait(Lock,
+   [this, Num] { return NumRequestsReceived == Num; });
+NumRequestsReceived = 0;
 auto Reqs = std::move(Requests);
 Requests = {};
 return Reqs;
@@ -1140,16 +1147,19 @@
 
 private:
   // We need a mutex to handle async fuzzy find requests.
+  mutable std::condition_variable ReceivedRequestCV;
   mutable std::mutex Mut;
+  mutable size_t NumRequestsReceived = 0;
   mutable std::vector Requests;
 };
 
-std::vector captureIndexRequests(llvm::StringRef Code) {
+std::vector captureIndexRequests(llvm::StringRef Code,
+   size_t Num = 1) {
   clangd::CodeCompleteOptions Opts;
   IndexRequestCollector Requests;
   Opts.Index = &Requests;
   completions(Code, {}, Opts);
-  return Requests.consumeRequests();
+  return Requests.consumeRequests(Num);
 }
 
 TEST(CompletionTest, UnqualifiedIdQuery) {
@@ -2098,18 +2108,15 @@
 
   auto CompleteAtPoint = [&](StringRef P) {
 cantFail(runCodeComplete(Server, File, Test.point(P), Opts));
-// Sleep for a while to make sure asynchronous call (if applicable) is also
-// triggered before callback is invoked.
-std::this_thread::sleep_for(std::chrono::milliseconds(100));
   };
 
   CompleteAtPoint("1");
-  auto Reqs1 = Requests.consumeRequests();
+  auto Reqs1 = Requests.consumeRequests(1);
   ASSERT_EQ(Reqs1.size(), 1u);
   EXPECT_THAT(Reqs1[0].Scopes, UnorderedElementsAre("ns1::"));
 
   CompleteAtPoint("2");
-  auto Reqs2 = Requests.consumeRequests();
+  auto Reqs2 = Requests.consumeRequests(1);
   // Speculation succeeded. Used speculative index result.
   ASSERT_EQ(Reqs2.size(), 1u);
   EXPECT_EQ(Reqs2[0], Reqs1[0]);
@@ -2117,7 +2124,7 @@
   CompleteAtPoint("3");
   // Speculation failed. Sent speculative index request and the new index
   // request after sema.
-  auto Reqs3 = Requests.consumeRequests();
+  auto Reqs3 = Requests.consumeRequests(2);
   ASSERT_EQ(Reqs3.size(), 2u);
 }
 


Index: clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
===
--- clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
+++ clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
@@ -27,6 +27,8 @@
 #include "llvm/Testing/Support/Error.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
+#include 
+#include 
 
 namespace clang {
 namespace clangd {
@@ -1112,8 +1114,10 @@
   bool
   fuzzyFind(const FuzzyFindRequest &Req,
 llvm::function_ref Callback) const override {
-std::lock_guard Lock(Mut);
+std::unique_lock Lock(Mut);
 Requests.push_back(Req);
+++NumRequestsReceived;
+ReceivedRequestCV.notify_one();
 return true;
   }
 
@@ -1131,8 +1135,11 @@
   // isn't used in production code.
   size_t estimateMemoryUsage() const override { return 0; }
 
-  const std::vector consumeRequests() const {
-std::lock_guard Lock(Mut);
+  const std::vector consumeRequests(size_t Num) const {
+std::unique_lock Lock(Mut);
+ReceivedRequestCV.wait(Lock,
+   [this, Num] { return NumRequestsReceived == Num; });
+NumRequestsReceived = 0;
 auto Reqs = std::move(Requests);
 Requests = {};
 return Reqs;
@@ -1140,16 +1147,19 @@
 
 private:
   // We need a mutex to handle async fuzzy find requests.
+  mutable std::condition_variable ReceivedRequestCV;
   mutable std::mutex Mut;
+  mutable size_t NumRequestsReceived = 0;
   mutable std::vector Requests;
 };
 
-std::vector captureIndexRequests(llvm::StringRef Code) {

[PATCH] D68274: [Alignment][Clang][NFC] Add CharUnits::getAsAlign

2019-10-01 Thread Guillaume Chatelet via Phabricator via cfe-commits
gchatelet created this revision.
gchatelet added a reviewer: courbet.
Herald added subscribers: cfe-commits, jholewinski.
Herald added a project: clang.

This is a prerequisite to removing `llvm::GlobalObject::setAlignment(unsigned)`.
This is patch is part of a series to introduce an Alignment type.
See this thread for context: 
http://lists.llvm.org/pipermail/llvm-dev/2019-July/133851.html
See this patch for the introduction of the type: https://reviews.llvm.org/D64790


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D68274

Files:
  clang/include/clang/AST/CharUnits.h
  clang/lib/CodeGen/CGCUDANV.cpp
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CGCleanup.cpp
  clang/lib/CodeGen/CGDecl.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/CodeGen/CGExprAgg.cpp
  clang/lib/CodeGen/CGExprCXX.cpp
  clang/lib/CodeGen/CGExprConstant.cpp
  clang/lib/CodeGen/CGObjCGNU.cpp
  clang/lib/CodeGen/CGObjCMac.cpp
  clang/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/ConstantInitBuilder.cpp
  clang/lib/CodeGen/CoverageMappingGen.cpp
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  clang/lib/CodeGen/MicrosoftCXXABI.cpp
  clang/lib/CodeGen/ObjectFilePCHContainerOperations.cpp

Index: clang/lib/CodeGen/ObjectFilePCHContainerOperations.cpp
===
--- clang/lib/CodeGen/ObjectFilePCHContainerOperations.cpp
+++ clang/lib/CodeGen/ObjectFilePCHContainerOperations.cpp
@@ -279,7 +279,7 @@
 *M, Ty, /*constant*/ true, llvm::GlobalVariable::InternalLinkage, Data,
 "__clang_ast");
 // The on-disk hashtable needs to be aligned.
-ASTSym->setAlignment(8);
+ASTSym->setAlignment(llvm::Align(8));
 
 // Mach-O also needs a segment name.
 if (Triple.isOSBinFormatMachO())
Index: clang/lib/CodeGen/MicrosoftCXXABI.cpp
===
--- clang/lib/CodeGen/MicrosoftCXXABI.cpp
+++ clang/lib/CodeGen/MicrosoftCXXABI.cpp
@@ -2355,7 +2355,7 @@
   /*isConstant=*/false, llvm::GlobalVariable::ExternalLinkage,
   /*Initializer=*/nullptr, VarName,
   /*InsertBefore=*/nullptr, llvm::GlobalVariable::GeneralDynamicTLSModel);
-  GV->setAlignment(Align.getQuantity());
+  GV->setAlignment(Align.getAsAlign());
   return ConstantAddress(GV, Align);
 }
 
@@ -2498,7 +2498,7 @@
  GV->getLinkage(), Zero, GuardName.str());
 GuardVar->setVisibility(GV->getVisibility());
 GuardVar->setDLLStorageClass(GV->getDLLStorageClass());
-GuardVar->setAlignment(GuardAlign.getQuantity());
+GuardVar->setAlignment(GuardAlign.getAsAlign());
 if (GuardVar->isWeakForLinker())
   GuardVar->setComdat(
   CGM.getModule().getOrInsertComdat(GuardVar->getName()));
Index: clang/lib/CodeGen/ItaniumCXXABI.cpp
===
--- clang/lib/CodeGen/ItaniumCXXABI.cpp
+++ clang/lib/CodeGen/ItaniumCXXABI.cpp
@@ -2194,7 +2194,7 @@
 guard->setVisibility(var->getVisibility());
 // If the variable is thread-local, so is its guard variable.
 guard->setThreadLocalMode(var->getThreadLocalMode());
-guard->setAlignment(guardAlignment.getQuantity());
+guard->setAlignment(guardAlignment.getAsAlign());
 
 // The ABI says: "It is suggested that it be emitted in the same COMDAT
 // group as the associated data object." In practice, this doesn't work for
@@ -2547,7 +2547,7 @@
 Guard->setThreadLocal(true);
 
 CharUnits GuardAlign = CharUnits::One();
-Guard->setAlignment(GuardAlign.getQuantity());
+Guard->setAlignment(GuardAlign.getAsAlign());
 
 CodeGenFunction(CGM).GenerateCXXGlobalInitFunc(
 InitFunc, OrderedInits, ConstantAddress(Guard, GuardAlign));
@@ -3479,7 +3479,7 @@
 
   CharUnits Align =
   CGM.getContext().toCharUnitsFromBits(CGM.getTarget().getPointerAlign(0));
-  GV->setAlignment(Align.getQuantity());
+  GV->setAlignment(Align.getAsAlign());
 
   // The Itanium ABI specifies that type_info objects must be globally
   // unique, with one exception: if the type is an incomplete class
Index: clang/lib/CodeGen/CoverageMappingGen.cpp
===
--- clang/lib/CodeGen/CoverageMappingGen.cpp
+++ clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -1442,7 +1442,7 @@
   CovDataVal, llvm::getCoverageMappingVarName());
 
   CovData->setSection(getCoverageSection(CGM));
-  CovData->setAlignment(8);
+  CovData->setAlignment(llvm::Align(8));
 
   // Make sure the data doesn't get deleted.
   CGM.addUsedGlobal(CovData);
Index: clang/lib/CodeGen/ConstantInitBuilder.cpp
===
--- clang/lib/CodeGen/ConstantInitBuilder.cpp
+++ clang/lib/CodeGen/ConstantInitBuilder.cpp
@@ -79,7 +79,7 @@
  /*insert before*/ nullptr,

[PATCH] D68273: [clangd] Fix raciness in code completion tests

2019-10-01 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

This is still racy if there were > 1 request. I wonder if there a better way to 
address this?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D68273



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


[PATCH] D68273: [clangd] Fix raciness in code completion tests

2019-10-01 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet created this revision.
kadircet added reviewers: sammccall, ilya-biryukov.
Herald added subscribers: cfe-commits, usaxena95, arphaman, jkorous, MaskRay.
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D68273

Files:
  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
@@ -27,6 +27,8 @@
 #include "llvm/Testing/Support/Error.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
+#include 
+#include 
 
 namespace clang {
 namespace clangd {
@@ -1112,8 +1114,10 @@
   bool
   fuzzyFind(const FuzzyFindRequest &Req,
 llvm::function_ref Callback) const override {
-std::lock_guard Lock(Mut);
+std::unique_lock Lock(Mut);
 Requests.push_back(Req);
+ReceivedRequest = true;
+ReceivedRequestCV.notify_one();
 return true;
   }
 
@@ -1132,7 +1136,9 @@
   size_t estimateMemoryUsage() const override { return 0; }
 
   const std::vector consumeRequests() const {
-std::lock_guard Lock(Mut);
+std::unique_lock Lock(Mut);
+ReceivedRequestCV.wait(Lock, [this]() { return ReceivedRequest; });
+ReceivedRequest = false;
 auto Reqs = std::move(Requests);
 Requests = {};
 return Reqs;
@@ -1140,7 +1146,9 @@
 
 private:
   // We need a mutex to handle async fuzzy find requests.
+  mutable std::condition_variable ReceivedRequestCV;
   mutable std::mutex Mut;
+  mutable bool ReceivedRequest = false;
   mutable std::vector Requests;
 };
 
@@ -2098,9 +2106,6 @@
 
   auto CompleteAtPoint = [&](StringRef P) {
 cantFail(runCodeComplete(Server, File, Test.point(P), Opts));
-// Sleep for a while to make sure asynchronous call (if applicable) is also
-// triggered before callback is invoked.
-std::this_thread::sleep_for(std::chrono::milliseconds(100));
   };
 
   CompleteAtPoint("1");


Index: clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
===
--- clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
+++ clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
@@ -27,6 +27,8 @@
 #include "llvm/Testing/Support/Error.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
+#include 
+#include 
 
 namespace clang {
 namespace clangd {
@@ -1112,8 +1114,10 @@
   bool
   fuzzyFind(const FuzzyFindRequest &Req,
 llvm::function_ref Callback) const override {
-std::lock_guard Lock(Mut);
+std::unique_lock Lock(Mut);
 Requests.push_back(Req);
+ReceivedRequest = true;
+ReceivedRequestCV.notify_one();
 return true;
   }
 
@@ -1132,7 +1136,9 @@
   size_t estimateMemoryUsage() const override { return 0; }
 
   const std::vector consumeRequests() const {
-std::lock_guard Lock(Mut);
+std::unique_lock Lock(Mut);
+ReceivedRequestCV.wait(Lock, [this]() { return ReceivedRequest; });
+ReceivedRequest = false;
 auto Reqs = std::move(Requests);
 Requests = {};
 return Reqs;
@@ -1140,7 +1146,9 @@
 
 private:
   // We need a mutex to handle async fuzzy find requests.
+  mutable std::condition_variable ReceivedRequestCV;
   mutable std::mutex Mut;
+  mutable bool ReceivedRequest = false;
   mutable std::vector Requests;
 };
 
@@ -2098,9 +2106,6 @@
 
   auto CompleteAtPoint = [&](StringRef P) {
 cantFail(runCodeComplete(Server, File, Test.point(P), Opts));
-// Sleep for a while to make sure asynchronous call (if applicable) is also
-// triggered before callback is invoked.
-std::this_thread::sleep_for(std::chrono::milliseconds(100));
   };
 
   CompleteAtPoint("1");
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r373252 - [Diagnostics] Warn if enumeration type mismatch in conditional expression

2019-10-01 Thread Nico Weber via cfe-commits
Can we move this behind a Wenum-compare subgroup, say Wenum-compare-type?
Our codebase is (well, was) Wenum-compare clean, and this new warnings
fires pretty often and from a first quick glance the warning looks pretty
low-signal anyways (*). Maybe the subgroup shouldn't even be on by default
-- do you have any data on true / false positive rate of this?

(But for starters, just having a way to turn this off is enough.)

For example, we have a windows common control that's either a PGRP_DOWN or
a PGRP_UP page control and depending on which you store the control state
in the same int, then stuff like `return extra.inner_spin.spin_up ?
UPS_DISABLED : DNS_DISABLED;`.

On Mon, Sep 30, 2019 at 3:53 PM David Bolvansky via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: xbolva00
> Date: Mon Sep 30 12:55:50 2019
> New Revision: 373252
>
> URL: http://llvm.org/viewvc/llvm-project?rev=373252&view=rev
> Log:
> [Diagnostics] Warn if enumeration type mismatch in conditional expression
>
> Summary:
> - Useful warning
> - GCC compatibility (GCC warns in C++ mode)
>
> Reviewers: rsmith, aaron.ballman
>
> Reviewed By: aaron.ballman
>
> Subscribers: cfe-commits
>
> Tags: #clang
>
> Differential Revision: https://reviews.llvm.org/D67919
>
> Added:
> cfe/trunk/test/Sema/warn-conditional-emum-types-mismatch.c
> Modified:
> cfe/trunk/lib/Sema/SemaChecking.cpp
>
> Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=373252&r1=373251&r2=373252&view=diff
>
> ==
> --- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaChecking.cpp Mon Sep 30 12:55:50 2019
> @@ -11308,6 +11308,32 @@ static const IntegerLiteral *getIntegerL
>return IL;
>  }
>
> +static void CheckConditionalWithEnumTypes(Sema &S, SourceLocation Loc,
> +  Expr *LHS, Expr *RHS) {
> +  QualType LHSStrippedType = LHS->IgnoreParenImpCasts()->getType();
> +  QualType RHSStrippedType = RHS->IgnoreParenImpCasts()->getType();
> +
> +  const auto *LHSEnumType = LHSStrippedType->getAs();
> +  if (!LHSEnumType)
> +return;
> +  const auto *RHSEnumType = RHSStrippedType->getAs();
> +  if (!RHSEnumType)
> +return;
> +
> +  // Ignore anonymous enums.
> +  if (!LHSEnumType->getDecl()->hasNameForLinkage())
> +return;
> +  if (!RHSEnumType->getDecl()->hasNameForLinkage())
> +return;
> +
> +  if (S.Context.hasSameUnqualifiedType(LHSStrippedType, RHSStrippedType))
> +return;
> +
> +  S.Diag(Loc, diag::warn_conditional_mixed_enum_types)
> +  << LHSStrippedType << RHSStrippedType << LHS->getSourceRange()
> +  << RHS->getSourceRange();
> +}
> +
>  static void DiagnoseIntInBoolContext(Sema &S, Expr *E) {
>E = E->IgnoreParenImpCasts();
>SourceLocation ExprLoc = E->getExprLoc();
> @@ -11799,6 +11825,8 @@ static void CheckConditionalOperator(Sem
>bool Suspicious = false;
>CheckConditionalOperand(S, E->getTrueExpr(), T, CC, Suspicious);
>CheckConditionalOperand(S, E->getFalseExpr(), T, CC, Suspicious);
> +  CheckConditionalWithEnumTypes(S, E->getBeginLoc(), E->getTrueExpr(),
> +E->getFalseExpr());
>
>if (T->isBooleanType())
>  DiagnoseIntInBoolContext(S, E);
>
> Added: cfe/trunk/test/Sema/warn-conditional-emum-types-mismatch.c
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/warn-conditional-emum-types-mismatch.c?rev=373252&view=auto
>
> ==
> --- cfe/trunk/test/Sema/warn-conditional-emum-types-mismatch.c (added)
> +++ cfe/trunk/test/Sema/warn-conditional-emum-types-mismatch.c Mon Sep 30
> 12:55:50 2019
> @@ -0,0 +1,39 @@
> +// RUN: %clang_cc1 -x c -fsyntax-only -verify -Wenum-compare %s
> +// RUN: %clang_cc1 -x c -fsyntax-only -verify  %s
> +// RUN: %clang_cc1 -x c++ -fsyntax-only -verify -Wenum-compare %s
> +// RUN: %clang_cc1 -x c++ -fsyntax-only -verify %s
> +
> +enum ro { A = 0x10 };
> +enum rw { B = 0xFF };
> +enum { C = 0x1A};
> +
> +enum {
> +  STATUS_SUCCESS,
> +  STATUS_FAILURE,
> +  MAX_BASE_STATUS_CODE
> +};
> +
> +enum ExtendedStatusCodes {
> +  STATUS_SOMETHING_INTERESTING = MAX_BASE_STATUS_CODE + 1000,
> +};
> +
> +
> +int get_flag(int cond) {
> +  return cond ? A : B;
> +  #ifdef __cplusplus
> +  // expected-warning@-2 {{enumeration type mismatch in conditional
> expression ('ro' and 'rw')}}
> +  #else
> +  // expected-no-diagnostics
> +  #endif
> +}
> +
> +// In the following cases we purposefully differ from GCC and dont warn
> because
> +// this code pattern is quite sensitive and we dont want to produce so
> many false positives.
> +
> +int get_flag_anon_enum(int cond) {
> +  return cond ? A : C;
> +}
> +
> +int foo(int c) {
> +  return c ? STATUS_SOMETHING_INTERESTING : STATUS_SUCCESS;
> +}
>
>
> ___
> cfe-commits mail

[PATCH] D68162: [analyzer][MallocChecker][NFC] Communicate the allocation family information to auxiliary functions with template parameters

2019-10-01 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus added a comment.

In D68162#1686810 , @NoQ wrote:

> Thank you, fantastic finding!
>
> > in fact we know it //compile time//
>
> Yeah, but is it accidental or is there a good reason behind always having 
> this information at compile time? 'Cause i don't want to restrict the code to 
> always provide this information at compile time if we're not sure it'll 
> always be able to provide it in compile time.


Definitely accidental. And now that I think about it, maybe it would be better 
to turn these into non-optional regular arguments. Though its far in the 
future, we could eventually add annotations that tell whether a function 
returns with `new`ed or `malloc()`ated memory.

The entire point of the patch was to get rid of `getAllocationFamily`, because 
there really isn't a need to get the allocation family of hardcoded functions.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D68162



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


[PATCH] D68143: [clang] Make handling of unnamed template params similar to function params

2019-10-01 Thread Kadir Cetinkaya via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL373340: [clang] Make handling of unnamed template params 
similar to function params (authored by kadircet, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D68143?vs=222581&id=222604#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D68143

Files:
  cfe/trunk/lib/AST/DeclTemplate.cpp
  cfe/trunk/lib/Parse/ParseTemplate.cpp
  cfe/trunk/lib/Sema/SemaTemplate.cpp
  cfe/trunk/test/AST/ast-dump-decl.cpp
  cfe/trunk/test/AST/ast-dump-record-definition-data-json.cpp
  cfe/trunk/test/AST/ast-dump-template-decls-json.cpp
  cfe/trunk/test/AST/ast-dump-template-decls.cpp
  cfe/trunk/test/ASTMerge/class-template/test.cpp
  cfe/trunk/test/Index/index-templates.cpp

Index: cfe/trunk/lib/Parse/ParseTemplate.cpp
===
--- cfe/trunk/lib/Parse/ParseTemplate.cpp
+++ cfe/trunk/lib/Parse/ParseTemplate.cpp
@@ -630,11 +630,11 @@
   }
 
   // Grab the template parameter name (if given)
-  SourceLocation NameLoc;
+  SourceLocation NameLoc = Tok.getLocation();
   IdentifierInfo *ParamName = nullptr;
   if (Tok.is(tok::identifier)) {
 ParamName = Tok.getIdentifierInfo();
-NameLoc = ConsumeToken();
+ConsumeToken();
   } else if (Tok.isOneOf(tok::equal, tok::comma, tok::greater,
  tok::greatergreater)) {
 // Unnamed template parameter. Don't have to do anything here, just
@@ -727,11 +727,11 @@
: diag::ext_variadic_templates);
 
   // Get the identifier, if given.
-  SourceLocation NameLoc;
+  SourceLocation NameLoc = Tok.getLocation();
   IdentifierInfo *ParamName = nullptr;
   if (Tok.is(tok::identifier)) {
 ParamName = Tok.getIdentifierInfo();
-NameLoc = ConsumeToken();
+ConsumeToken();
   } else if (Tok.isOneOf(tok::equal, tok::comma, tok::greater,
  tok::greatergreater)) {
 // Unnamed template parameter. Don't have to do anything here, just
Index: cfe/trunk/lib/AST/DeclTemplate.cpp
===
--- cfe/trunk/lib/AST/DeclTemplate.cpp
+++ cfe/trunk/lib/AST/DeclTemplate.cpp
@@ -510,8 +510,12 @@
   if (hasDefaultArgument() && !defaultArgumentWasInherited())
 return SourceRange(getBeginLoc(),
getDefaultArgumentInfo()->getTypeLoc().getEndLoc());
-  else
-return TypeDecl::getSourceRange();
+  // TypeDecl::getSourceRange returns a range containing name location, which is
+  // wrong for unnamed template parameters. e.g:
+  // it will return <[[typename>]] instead of <[[typename]]>
+  else if (getDeclName().isEmpty())
+return SourceRange(getBeginLoc());
+  return TypeDecl::getSourceRange();
 }
 
 unsigned TemplateTypeParmDecl::getDepth() const {
Index: cfe/trunk/lib/Sema/SemaTemplate.cpp
===
--- cfe/trunk/lib/Sema/SemaTemplate.cpp
+++ cfe/trunk/lib/Sema/SemaTemplate.cpp
@@ -1005,15 +1005,10 @@
   assert(S->isTemplateParamScope() &&
  "Template type parameter not in template parameter scope!");
 
-  SourceLocation Loc = ParamNameLoc;
-  if (!ParamName)
-Loc = KeyLoc;
-
   bool IsParameterPack = EllipsisLoc.isValid();
-  TemplateTypeParmDecl *Param
-= TemplateTypeParmDecl::Create(Context, Context.getTranslationUnitDecl(),
-   KeyLoc, Loc, Depth, Position, ParamName,
-   Typename, IsParameterPack);
+  TemplateTypeParmDecl *Param = TemplateTypeParmDecl::Create(
+  Context, Context.getTranslationUnitDecl(), KeyLoc, ParamNameLoc, Depth,
+  Position, ParamName, Typename, IsParameterPack);
   Param->setAccess(AS_public);
 
   if (Param->isParameterPack())
@@ -1044,7 +1039,7 @@
 assert(DefaultTInfo && "expected source information for type");
 
 // Check for unexpanded parameter packs.
-if (DiagnoseUnexpandedParameterPack(Loc, DefaultTInfo,
+if (DiagnoseUnexpandedParameterPack(ParamNameLoc, DefaultTInfo,
 UPPC_DefaultArgument))
   return Param;
 
Index: cfe/trunk/test/ASTMerge/class-template/test.cpp
===
--- cfe/trunk/test/ASTMerge/class-template/test.cpp
+++ cfe/trunk/test/ASTMerge/class-template/test.cpp
@@ -9,13 +9,13 @@
 // CHECK: class-template2.cpp:9:15: note: declared here with type 'long'
 
 // CHECK: class-template1.cpp:12:14: warning: template parameter has different kinds in different translation units
-// CHECK: class-template2.cpp:12:10: note: template parameter declared here
+// CHECK: class-template2.cpp:12:18: note: template parameter declared here
 
 // CHECK: class-template1.cpp:18:23: warning: non-type template parameter declared with incompatible types in different tran

r373340 - [clang] Make handling of unnamed template params similar to function params

2019-10-01 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Tue Oct  1 07:08:51 2019
New Revision: 373340

URL: http://llvm.org/viewvc/llvm-project?rev=373340&view=rev
Log:
[clang] Make handling of unnamed template params similar to function params

Summary:
Clang uses the location identifier should be inserted for declarator
decls when a decl is unnamed. But for type template and template template
paramaters it uses the location of "typename/class" keyword, which makes it hard
for tooling to insert/change parameter names.

This change tries to unify these two cases by making template parameter
parsing and sourcerange operations similar to function params/declarator decls.

Reviewers: ilya-biryukov

Subscribers: arphaman, cfe-commits

Tags: #clang

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

Modified:
cfe/trunk/lib/AST/DeclTemplate.cpp
cfe/trunk/lib/Parse/ParseTemplate.cpp
cfe/trunk/lib/Sema/SemaTemplate.cpp
cfe/trunk/test/AST/ast-dump-decl.cpp
cfe/trunk/test/AST/ast-dump-record-definition-data-json.cpp
cfe/trunk/test/AST/ast-dump-template-decls-json.cpp
cfe/trunk/test/AST/ast-dump-template-decls.cpp
cfe/trunk/test/ASTMerge/class-template/test.cpp
cfe/trunk/test/Index/index-templates.cpp

Modified: cfe/trunk/lib/AST/DeclTemplate.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclTemplate.cpp?rev=373340&r1=373339&r2=373340&view=diff
==
--- cfe/trunk/lib/AST/DeclTemplate.cpp (original)
+++ cfe/trunk/lib/AST/DeclTemplate.cpp Tue Oct  1 07:08:51 2019
@@ -510,8 +510,12 @@ SourceRange TemplateTypeParmDecl::getSou
   if (hasDefaultArgument() && !defaultArgumentWasInherited())
 return SourceRange(getBeginLoc(),
getDefaultArgumentInfo()->getTypeLoc().getEndLoc());
-  else
-return TypeDecl::getSourceRange();
+  // TypeDecl::getSourceRange returns a range containing name location, which 
is
+  // wrong for unnamed template parameters. e.g:
+  // it will return <[[typename>]] instead of <[[typename]]>
+  else if (getDeclName().isEmpty())
+return SourceRange(getBeginLoc());
+  return TypeDecl::getSourceRange();
 }
 
 unsigned TemplateTypeParmDecl::getDepth() const {

Modified: cfe/trunk/lib/Parse/ParseTemplate.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseTemplate.cpp?rev=373340&r1=373339&r2=373340&view=diff
==
--- cfe/trunk/lib/Parse/ParseTemplate.cpp (original)
+++ cfe/trunk/lib/Parse/ParseTemplate.cpp Tue Oct  1 07:08:51 2019
@@ -630,11 +630,11 @@ NamedDecl *Parser::ParseTypeParameter(un
   }
 
   // Grab the template parameter name (if given)
-  SourceLocation NameLoc;
+  SourceLocation NameLoc = Tok.getLocation();
   IdentifierInfo *ParamName = nullptr;
   if (Tok.is(tok::identifier)) {
 ParamName = Tok.getIdentifierInfo();
-NameLoc = ConsumeToken();
+ConsumeToken();
   } else if (Tok.isOneOf(tok::equal, tok::comma, tok::greater,
  tok::greatergreater)) {
 // Unnamed template parameter. Don't have to do anything here, just
@@ -727,11 +727,11 @@ Parser::ParseTemplateTemplateParameter(u
: diag::ext_variadic_templates);
 
   // Get the identifier, if given.
-  SourceLocation NameLoc;
+  SourceLocation NameLoc = Tok.getLocation();
   IdentifierInfo *ParamName = nullptr;
   if (Tok.is(tok::identifier)) {
 ParamName = Tok.getIdentifierInfo();
-NameLoc = ConsumeToken();
+ConsumeToken();
   } else if (Tok.isOneOf(tok::equal, tok::comma, tok::greater,
  tok::greatergreater)) {
 // Unnamed template parameter. Don't have to do anything here, just

Modified: cfe/trunk/lib/Sema/SemaTemplate.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplate.cpp?rev=373340&r1=373339&r2=373340&view=diff
==
--- cfe/trunk/lib/Sema/SemaTemplate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplate.cpp Tue Oct  1 07:08:51 2019
@@ -1005,15 +1005,10 @@ NamedDecl *Sema::ActOnTypeParameter(Scop
   assert(S->isTemplateParamScope() &&
  "Template type parameter not in template parameter scope!");
 
-  SourceLocation Loc = ParamNameLoc;
-  if (!ParamName)
-Loc = KeyLoc;
-
   bool IsParameterPack = EllipsisLoc.isValid();
-  TemplateTypeParmDecl *Param
-= TemplateTypeParmDecl::Create(Context, Context.getTranslationUnitDecl(),
-   KeyLoc, Loc, Depth, Position, ParamName,
-   Typename, IsParameterPack);
+  TemplateTypeParmDecl *Param = TemplateTypeParmDecl::Create(
+  Context, Context.getTranslationUnitDecl(), KeyLoc, ParamNameLoc, Depth,
+  Position, ParamName, Typename, IsParameterPack);
   Param->setAccess(AS_public);
 
   if (Param->isParameterPack())
@@ -1044,7 +1039,7 @@ NamedDecl *Sema::ActOnTypeParameter(Scop
 assert(DefaultTInfo && "exp

[PATCH] D67706: [clang][analyzer] Using CallDescription in StreamChecker.

2019-10-01 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp:109-110
 bool StreamChecker::evalCall(const CallEvent &Call, CheckerContext &C) const {
+  if (!Call.isGlobalCFunction())
+return false;
+

balazske wrote:
> Szelethus wrote:
> > Isn't this redundant with my other inline about parameter types?
> Probably change to `isInSystemHeader` or use both?
Actually, this looks fine. How about preserving this...



Comment at: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp:127-131
+  for (auto P : Call.parameters()) {
+QualType T = P->getType();
+if (!T->isIntegralOrEnumerationType() && !T->isPointerType())
+  return nullptr;
+  }

Szelethus wrote:
> balazske wrote:
> > Szelethus wrote:
> > > I'm not sure why we need this, is it true that *all* stream related 
> > > functions return a pointer or a numerical value? Are we actually checking 
> > > whether this really is a library function? If so, this looks pretty 
> > > arbitrary.
> > This comes from code of CStringChecker:
> > ```
> >   // Pro-actively check that argument types are safe to do arithmetic upon.
> >   // We do not want to crash if someone accidentally passes a structure
> >   // into, say, a C++ overload of any of these functions. We could not check
> >   // that for std::copy because they may have arguments of other types.
> > ```
> > Still I am not sure that the checker works correct with code that contains 
> > similar named but "arbitrary" functions.
> Oops, meant to write that ", is it true that *all* stream related functions 
> have only pointer or a numerical parameters?".
...and removing this one, or changing it to an assert?



Comment at: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp:156
+void StreamChecker::evalFread(const CallEvent &Call, CheckerContext &C) const {
+  (void)CheckNullStream(Call.getArgSVal(3), C);
 }

balazske wrote:
> Szelethus wrote:
> > Why the need for `(void)`? `CheckNullSteam` doesn't seem to have an 
> > `LLVM_NODISCARD` attribute.
> I wanted to be sure to get no buildbot compile errors (where -Werror is used).
They actually break on this?? Let me guess, is it the windows one? :D


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D67706



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


[PATCH] D66049: [analyzer] PR41729: Fix some false positives and improve strlcat and strlcpy modeling

2019-10-01 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus added a comment.

The logic of the patch is fine in my eyes, but I dislike the formatting. Could 
you please make the code obey the LLVM coding style, and after that use 
clang-format-diff.py?
https://llvm.org/docs/CodingStandards.html
https://clang.llvm.org/docs/ClangFormat.html#script-for-patch-reformatting




Comment at: lib/StaticAnalyzer/Checkers/CStringChecker.cpp:31
 namespace {
+enum class appendKind { none = 0, strcat = 1, strlcat = 2 };
 class CStringChecker : public Checker< eval::Call,

Please capitalize these. Also, `ConcatFnKind` might be more descriptive? Ad 
absurdum, we might as well pass the `CallDescription` that is responsible for 
the concatenation. That maaay just be a little over engineered though.



Comment at: lib/StaticAnalyzer/Checkers/CStringChecker.cpp:133-134
   void evalStrlcpy(CheckerContext &C, const CallExpr *CE) const;
-  void evalStrcpyCommon(CheckerContext &C,
-const CallExpr *CE,
-bool returnEnd,
-bool isBounded,
-bool isAppending,
+  void evalStrcpyCommon(CheckerContext &C, const CallExpr *CE, bool returnEnd,
+bool isBounded, appendKind appendK,
 bool returnPtr = true) const;

CaPitALizeE :D



Comment at: lib/StaticAnalyzer/Checkers/CStringChecker.cpp:1556
+
+  // Get the string length of the destination
+  SVal dstStrLength = getCStringLength(C, state, Dst, DstVal);

Please terminate this sentence.



Comment at: lib/StaticAnalyzer/Checkers/CStringChecker.cpp:1580
 
   // If the function is strncpy, strncat, etc... it is bounded.
   if (isBounded) {

Ah, okay, so the assumption is that bounded functions' third argument is always 
a numerical size parameter. Why isn't that enforced at all?



Comment at: lib/StaticAnalyzer/Checkers/CStringChecker.cpp:1596
 
-  // Check if the max number to copy is less than the length of the src.
-  // If the bound is equal to the source length, strncpy won't null-
-  // terminate the result!
-  std::tie(stateSourceTooLong, stateSourceNotTooLong) = state->assume(
-  svalBuilder.evalBinOpNN(state, BO_GE, *strLengthNL, *lenValNL, cmpTy)
-  .castAs());
+  if (appendK == appendKind::none || appendK == appendKind::strcat) {
+ProgramStateRef stateSourceTooLong, stateSourceNotTooLong;

Can we just do a switch-case? If someone were to add a new concat type, it 
would even give a warning in case it was left unhandled.



Comment at: lib/StaticAnalyzer/Checkers/CStringChecker.cpp:1628
+  if (Optional freeSpaceNL = freeSpace.getAs()) {
+// Symbolic expression not too complex.
+

Please put comments like these before the branch. I like the following format 
better:

```lang=c++
// While unlikely, it is possible that the subtraction is too complexity
// to complex to compute, let's check whether it succeeded.
if (Optional freeSpaceNL = freeSpace.getAs())
```



Comment at: lib/StaticAnalyzer/Checkers/CStringChecker.cpp:1630
+
+SVal haveEnoughSpace = svalBuilder.evalBinOpNN(
+state, BO_LE, *strLengthNL, *freeSpaceNL, cmpTy);

`hasEnoughSpace`



Comment at: lib/StaticAnalyzer/Checkers/CStringChecker.cpp:1637-1640
+if (TrueState && !FalseState) {
+  // srcStrLength <= size - dstStrLength -1
+  amountCopied = strLength;
+}

All of these too, and omit braces too:

```lang=c++
// srcStrLength <= size - dstStrLength -1
if (TrueState && !FalseState)
  amountCopied = strLength;
```



Comment at: lib/StaticAnalyzer/Checkers/CStringChecker.cpp:1657
 if (lenValNL) {
-  if (isAppending) {
+  if (appendK == appendKind::strcat) {
 // For strncat, the check is strlen(dst) + lenVal < sizeof(dst)

Would prefer a switch case here too.


Repository:
  rC Clang

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

https://reviews.llvm.org/D66049



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


[PATCH] D67706: [clang][analyzer] Using CallDescription in StreamChecker.

2019-10-01 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp:127-131
+  for (auto P : Call.parameters()) {
+QualType T = P->getType();
+if (!T->isIntegralOrEnumerationType() && !T->isPointerType())
+  return nullptr;
+  }

balazske wrote:
> Szelethus wrote:
> > I'm not sure why we need this, is it true that *all* stream related 
> > functions return a pointer or a numerical value? Are we actually checking 
> > whether this really is a library function? If so, this looks pretty 
> > arbitrary.
> This comes from code of CStringChecker:
> ```
>   // Pro-actively check that argument types are safe to do arithmetic upon.
>   // We do not want to crash if someone accidentally passes a structure
>   // into, say, a C++ overload of any of these functions. We could not check
>   // that for std::copy because they may have arguments of other types.
> ```
> Still I am not sure that the checker works correct with code that contains 
> similar named but "arbitrary" functions.
Oops, meant to write that ", is it true that *all* stream related functions 
have only pointer or a numerical parameters?".


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D67706



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


[PATCH] D67706: [clang][analyzer] Using CallDescription in StreamChecker.

2019-10-01 Thread Balázs Kéri via Phabricator via cfe-commits
balazske marked 3 inline comments as done.
balazske added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp:109-110
 bool StreamChecker::evalCall(const CallEvent &Call, CheckerContext &C) const {
+  if (!Call.isGlobalCFunction())
+return false;
+

Szelethus wrote:
> Isn't this redundant with my other inline about parameter types?
Probably change to `isInSystemHeader` or use both?



Comment at: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp:127-131
+  for (auto P : Call.parameters()) {
+QualType T = P->getType();
+if (!T->isIntegralOrEnumerationType() && !T->isPointerType())
+  return nullptr;
+  }

Szelethus wrote:
> I'm not sure why we need this, is it true that *all* stream related functions 
> return a pointer or a numerical value? Are we actually checking whether this 
> really is a library function? If so, this looks pretty arbitrary.
This comes from code of CStringChecker:
```
  // Pro-actively check that argument types are safe to do arithmetic upon.
  // We do not want to crash if someone accidentally passes a structure
  // into, say, a C++ overload of any of these functions. We could not check
  // that for std::copy because they may have arguments of other types.
```
Still I am not sure that the checker works correct with code that contains 
similar named but "arbitrary" functions.



Comment at: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp:156
+void StreamChecker::evalFread(const CallEvent &Call, CheckerContext &C) const {
+  (void)CheckNullStream(Call.getArgSVal(3), C);
 }

Szelethus wrote:
> Why the need for `(void)`? `CheckNullSteam` doesn't seem to have an 
> `LLVM_NODISCARD` attribute.
I wanted to be sure to get no buildbot compile errors (where -Werror is used).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D67706



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


[PATCH] D67837: [CUDA][HIP] Fix host/device check with -fopenmp

2019-10-01 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: lib/Sema/SemaDecl.cpp:17618
+
+  if (LangOpts.CUDA) {
+// When compiling for device, host functions are never emitted.  Similarly,

Are you going to handle `#pragma omp declare target device_type(nohost)` in 
Cuda mode correctly? Such functions should not be emitted on the host in OpenMP 
5.0.



Comment at: lib/Sema/SemaOpenMP.cpp:1569-1574
+static Sema::FunctionEmissionStatus isKnownDeviceEmitted(Sema &S,
+ FunctionDecl *FD) {
   assert(S.LangOpts.OpenMP && S.LangOpts.OpenMPIsDevice &&
  "Expected OpenMP device compilation.");
-  // Templates are emitted when they're instantiated.
-  if (FD->isDependentContext())
-return FunctionEmissionStatus::Discarded;
-
-  Optional DevTy =
-  OMPDeclareTargetDeclAttr::getDeviceType(FD->getCanonicalDecl());
-  if (DevTy.hasValue())
-return (*DevTy == OMPDeclareTargetDeclAttr::DT_Host)
-   ? FunctionEmissionStatus::Discarded
-   : FunctionEmissionStatus::Emitted;
-
-  // Otherwise, the function is known-emitted if it's in our set of
-  // known-emitted functions.
-  return (S.DeviceKnownEmittedFns.count(FD) > 0)
- ? FunctionEmissionStatus::Emitted
- : FunctionEmissionStatus::Unknown;
+  return S.getEmissionStatus(FD);
 }

You can remove the whole function and use `Sema::getEmissionStatus()` instead.



Comment at: lib/Sema/SemaOpenMP.cpp:1593
+  case FunctionEmissionStatus::OMPDiscarded:
+  case FunctionEmissionStatus::CUDADiscarded:
 Kind = DeviceDiagBuilder::K_Nop;

I think, `CUDADiscarded` case must be unreachable and it must be a case for 
`llvm_unreachable()` in case of the OpenMP device code.



Comment at: lib/Sema/SemaOpenMP.cpp:1602-1607
+static Sema::FunctionEmissionStatus isKnownHostEmitted(Sema &S,
+   FunctionDecl *FD) {
   assert(S.LangOpts.OpenMP && !S.LangOpts.OpenMPIsDevice &&
  "Expected OpenMP host compilation.");
-  // In OpenMP 4.5 all the functions are host functions.
-  if (S.LangOpts.OpenMP <= 45)
-return FunctionEmissionStatus::Emitted;
-
-  Optional DevTy =
-  OMPDeclareTargetDeclAttr::getDeviceType(FD->getCanonicalDecl());
-  if (DevTy.hasValue())
-return (*DevTy == OMPDeclareTargetDeclAttr::DT_NoHost)
-   ? FunctionEmissionStatus::Discarded
-   : FunctionEmissionStatus::Emitted;
-
-  // Otherwise, the function is known-emitted if it's in our set of
-  // known-emitted functions.
-  return (S.DeviceKnownEmittedFns.count(FD) > 0)
- ? FunctionEmissionStatus::Emitted
- : FunctionEmissionStatus::Unknown;
+  return S.getEmissionStatus(FD);
 }

You can remove the whole function and use `Sema::getEmissionStatus()` instead.



Comment at: lib/Sema/SemaOpenMP.cpp:1647-1648
 FunctionEmissionStatus::Unknown)) &&
   isKnownDeviceEmitted(*this, Callee) ==
-  FunctionEmissionStatus::Discarded) {
+  FunctionEmissionStatus::OMPDiscarded) {
 StringRef HostDevTy =

I would add an assert thet this function does not return `CUDADiscarded` value.



Comment at: lib/Sema/SemaOpenMP.cpp:1684-1685
   isKnownHostEmitted(*this, Caller) == FunctionEmissionStatus::Emitted &&
-  isKnownHostEmitted(*this, Callee) == FunctionEmissionStatus::Discarded) {
+  isKnownHostEmitted(*this, Callee) ==
+  FunctionEmissionStatus::OMPDiscarded) {
 StringRef NoHostDevTy = getOpenMPSimpleClauseTypeName(

Also, it would be good to check that it cannot return `CUDADiscarded` here.


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

https://reviews.llvm.org/D67837



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


[PATCH] D68143: [clang] Make handling of unnamed template params similar to function params

2019-10-01 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov accepted this revision.
ilya-biryukov added a comment.
This revision is now accepted and ready to land.

Many thanks! LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D68143



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


[PATCH] D68268: [Alignment][NFC] Remove StoreInst::setAlignment(unsigned)

2019-10-01 Thread Guillaume Chatelet via Phabricator via cfe-commits
gchatelet created this revision.
gchatelet added a reviewer: courbet.
Herald added a reviewer: bollu.
Herald added subscribers: llvm-commits, cfe-commits, asbirlea, hiraditya.
Herald added a reviewer: jdoerfert.
Herald added projects: clang, LLVM.

This is patch is part of a series to introduce an Alignment type.
See this thread for context: 
http://lists.llvm.org/pipermail/llvm-dev/2019-July/133851.html
See this patch for the introduction of the type: https://reviews.llvm.org/D64790


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D68268

Files:
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CGCleanup.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  llvm/include/llvm/IR/IRBuilder.h
  llvm/include/llvm/IR/Instructions.h
  llvm/lib/CodeGen/AtomicExpandPass.cpp
  llvm/lib/IR/Core.cpp
  llvm/lib/IR/Instructions.cpp
  llvm/lib/Transforms/IPO/Attributor.cpp
  llvm/lib/Transforms/InstCombine/InstCombineAtomicRMW.cpp
  llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
  llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
  llvm/lib/Transforms/Scalar/AlignmentFromAssumptions.cpp
  llvm/lib/Transforms/Scalar/GVNHoist.cpp
  llvm/lib/Transforms/Scalar/LICM.cpp
  llvm/lib/Transforms/Scalar/SROA.cpp
  llvm/lib/Transforms/Utils/SimplifyCFG.cpp
  llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
  polly/lib/CodeGen/BlockGenerators.cpp

Index: polly/lib/CodeGen/BlockGenerators.cpp
===
--- polly/lib/CodeGen/BlockGenerators.cpp
+++ polly/lib/CodeGen/BlockGenerators.cpp
@@ -1209,7 +1209,7 @@
 StoreInst *Store = Builder.CreateStore(Vector, VectorPtr);
 
 if (!Aligned)
-  Store->setAlignment(8);
+  Store->setAlignment(Align(8));
   } else {
 for (unsigned i = 0; i < ScalarMaps.size(); i++) {
   Value *Scalar = Builder.CreateExtractElement(Vector, Builder.getInt32(i));
Index: llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
===
--- llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -4024,7 +4024,7 @@
   if (!Alignment)
 Alignment = DL->getABITypeAlignment(SI->getValueOperand()->getType());
 
-  ST->setAlignment(Alignment);
+  ST->setAlignment(Align(Alignment));
   Value *V = propagateMetadata(ST, E->Scalars);
   if (NeedToShuffleReuses) {
 V = Builder.CreateShuffleVector(V, UndefValue::get(VecTy),
Index: llvm/lib/Transforms/Utils/SimplifyCFG.cpp
===
--- llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -3087,15 +3087,15 @@
   // store that doesn't execute.
   if (MinAlignment != 0) {
 // Choose the minimum of all non-zero alignments.
-SI->setAlignment(MinAlignment);
+SI->setAlignment(Align(MinAlignment));
   } else if (MaxAlignment != 0) {
 // Choose the minimal alignment between the non-zero alignment and the ABI
 // default alignment for the type of the stored value.
-SI->setAlignment(std::min(MaxAlignment, TypeAlignment));
+SI->setAlignment(Align(std::min(MaxAlignment, TypeAlignment)));
   } else {
 // If both alignments are zero, use ABI default alignment for the type of
 // the stored value.
-SI->setAlignment(TypeAlignment);
+SI->setAlignment(Align(TypeAlignment));
   }
 
   QStore->eraseFromParent();
Index: llvm/lib/Transforms/Scalar/SROA.cpp
===
--- llvm/lib/Transforms/Scalar/SROA.cpp
+++ llvm/lib/Transforms/Scalar/SROA.cpp
@@ -3127,7 +3127,7 @@
   Value *Op = SI->getOperand(0);
   StoreAlign = DL.getABITypeAlignment(Op->getType());
 }
-SI->setAlignment(std::min(StoreAlign, getSliceAlign()));
+SI->setAlignment(MaybeAlign(std::min(StoreAlign, getSliceAlign(;
 continue;
   }
 
Index: llvm/lib/Transforms/Scalar/LICM.cpp
===
--- llvm/lib/Transforms/Scalar/LICM.cpp
+++ llvm/lib/Transforms/Scalar/LICM.cpp
@@ -1791,7 +1791,7 @@
   StoreInst *NewSI = new StoreInst(LiveInValue, Ptr, InsertPos);
   if (UnorderedAtomic)
 NewSI->setOrdering(AtomicOrdering::Unordered);
-  NewSI->setAlignment(Alignment);
+  NewSI->setAlignment(MaybeAlign(Alignment));
   NewSI->setDebugLoc(DL);
   if (AATags)
 NewSI->setAAMetadata(AATags);
Index: llvm/lib/Transforms/Scalar/GVNHoist.cpp
===
--- llvm/lib/Transforms/Scalar/GVNHoist.cpp
+++ llvm/lib/Transforms/Scalar/GVNHoist.cpp
@@ -894,8 +894,8 @@
   ++NumLoadsRemoved;
 } else if (auto *ReplacementStore = dyn_cast(Repl)) {
   ReplacementStore->setAlignment(
-  std::min(ReplacementStore->getAlignment(),
-   cast(I)->getAlignment()));
+  M

[PATCH] D68028: [clang] Add no_builtin attribute

2019-10-01 Thread Guillaume Chatelet via Phabricator via cfe-commits
gchatelet marked 7 inline comments as done.
gchatelet added a comment.

thx @aaron.ballman , I'm waiting for your reply before uploading the new patch 
(some of my comments won't have the accompanying code update sorry)




Comment at: clang/lib/Sema/SemaDeclAttr.cpp:1072
+NoBuiltinAttr *
+Sema::mergeNoBuiltinAttr(Sema &S, Decl *D, const AttributeCommonInfo &CI,
+ llvm::ArrayRef FunctionNames) {

aaron.ballman wrote:
> You're missing a call to this function within `mergeDeclAttribute()` in 
> SemaDecl.cpp.
Thx, I rearranged the signature a bit, do you happen to know how 
`mergeDeclAttribute` is tested?



Comment at: clang/lib/Sema/SemaDeclAttr.cpp:1078-1079
+  // Insert previous NoBuiltin attributes.
+  if (D->hasAttr())
+for (StringRef FunctionName : D->getAttr()->functionNames())
+  FunctionNamesSet.insert(FunctionName);

aaron.ballman wrote:
> Instead of doing `hasAttr<>` followed by `getAttr<>`, this should be:
> ```
> if (const auto *NBA = D->getAttr()) {
>   for (StringRef FunctionName : NBA->functionNames())
> ...
> }
> ```
> But are you able to use `llvm::copy()` instead of a manual loop?
I had to use a vector instead of a set and //uniquify// by hand.



Comment at: clang/lib/Sema/SemaDeclAttr.cpp:1086-1089
+  if (FunctionNamesSet.count(Wildcard) > 0) {
+FunctionNamesSet.clear();
+FunctionNamesSet.insert(Wildcard);
+  }

aaron.ballman wrote:
> Rather than walking the entire set like this, would it make more sense to 
> look for the wildcard in the above loop before inserting the name, and set a 
> local variable if found, so that you can do the clear without having to 
> rescan the entire list?
This is is conflict with the `llvm::copy` suggestion above. Which one do you 
prefer?



Comment at: clang/lib/Sema/SemaDeclAttr.cpp:1098-1099
+
+  if (D->hasAttr())
+D->dropAttr();
+

aaron.ballman wrote:
> Just making sure I understand the semantics you want: redeclarations do not 
> have to have matching lists of builtins, but instead the definition will use 
> a merged list? e.g.,
> ```
> [[clang::no_builtin("memset")]] void whatever();
> [[clang::no_builtin("memcpy")]] void whatever();
> 
> [[clang::no_builtin("memmove")]] void whatever() {
>  // Will not use memset, memcpy, or memmove builtins.
> }
> ```
> That seems a bit strange, to me. In fact, being able to apply this attribute 
> to a declaration seems a bit like a mistake -- this only impacts the 
> definition of the function, and I can't imagine good things coming from 
> hypothetical code like:
> ```
> [[clang::no_builtin("memset")]] void whatever();
> #include "whatever.h" // Provides a library declaration of whatever() with no 
> restrictions on it
> ```
> WDYT about restricting this attribute to only appear on definitions?
That's a very good point. Thx for noticing.
Indeed I think it only makes sense to have the attribute on the function 
definition.

I've tried to to use `FunctionDecl->hasBody()` during attribute handling in the 
Sema phase but it seems like the `FunctionDecl` is not complete at this point.
All calls to `hasBody()` return `false`, if I repeat the operation in `CGCall` 
then `hasBody` returns `true` and I can see the `CompoundStatement`.

Do you have any recommendations on where to perform the check?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D68028



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


[PATCH] D53137: Scalable vector core instruction support + size queries

2019-10-01 Thread Graham Hunter via Phabricator via cfe-commits
huntergr updated this revision to Diff 222593.
huntergr added a comment.
Herald added a subscriber: dexonsmith.

- Renamed `ScalableSize` to `TypeSize`, including header name.
- added `alignTo` function that takes and returns a `TypeSize`. I wasn't sure 
if this should be added to MathExtras.h where the other variants live, so just 
kept it in TypeSize.h for now


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D53137

Files:
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CGStmt.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  llvm/include/llvm/ADT/DenseMapInfo.h
  llvm/include/llvm/IR/DataLayout.h
  llvm/include/llvm/IR/DerivedTypes.h
  llvm/include/llvm/IR/InstrTypes.h
  llvm/include/llvm/IR/Type.h
  llvm/include/llvm/Support/MachineValueType.h
  llvm/include/llvm/Support/ScalableSize.h
  llvm/include/llvm/Support/TypeSize.h
  llvm/lib/Analysis/InlineCost.cpp
  llvm/lib/CodeGen/Analysis.cpp
  llvm/lib/IR/DataLayout.cpp
  llvm/lib/IR/Instructions.cpp
  llvm/lib/IR/Type.cpp
  llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
  llvm/lib/Transforms/Scalar/SROA.cpp
  llvm/test/Other/scalable-vectors-core-ir.ll
  llvm/unittests/CodeGen/ScalableVectorMVTsTest.cpp
  llvm/unittests/IR/VectorTypesTest.cpp

Index: llvm/unittests/IR/VectorTypesTest.cpp
===
--- llvm/unittests/IR/VectorTypesTest.cpp
+++ llvm/unittests/IR/VectorTypesTest.cpp
@@ -6,9 +6,10 @@
 //
 //===--===//
 
+#include "llvm/IR/DataLayout.h"
 #include "llvm/IR/DerivedTypes.h"
 #include "llvm/IR/LLVMContext.h"
-#include "llvm/Support/ScalableSize.h"
+#include "llvm/Support/TypeSize.h"
 #include "gtest/gtest.h"
 using namespace llvm;
 
@@ -161,4 +162,117 @@
   ASSERT_TRUE(EltCnt.Scalable);
 }
 
+TEST(VectorTypesTest, FixedLenComparisons) {
+  LLVMContext Ctx;
+  DataLayout DL("");
+
+  Type *Int32Ty = Type::getInt32Ty(Ctx);
+  Type *Int64Ty = Type::getInt64Ty(Ctx);
+
+  VectorType *V2Int32Ty = VectorType::get(Int32Ty, 2);
+  VectorType *V4Int32Ty = VectorType::get(Int32Ty, 4);
+
+  VectorType *V2Int64Ty = VectorType::get(Int64Ty, 2);
+
+  TypeSize V2I32Len = V2Int32Ty->getPrimitiveSizeInBits();
+  EXPECT_EQ(V2I32Len.getKnownMinSize(), 64U);
+  EXPECT_FALSE(V2I32Len.isScalable());
+
+  EXPECT_LT(V2Int32Ty->getPrimitiveSizeInBits(),
+V4Int32Ty->getPrimitiveSizeInBits());
+  EXPECT_GT(V2Int64Ty->getPrimitiveSizeInBits(),
+V2Int32Ty->getPrimitiveSizeInBits());
+  EXPECT_EQ(V4Int32Ty->getPrimitiveSizeInBits(),
+V2Int64Ty->getPrimitiveSizeInBits());
+  EXPECT_NE(V2Int32Ty->getPrimitiveSizeInBits(),
+V2Int64Ty->getPrimitiveSizeInBits());
+
+  // Check that a fixed-only comparison works for fixed size vectors.
+  EXPECT_EQ(V2Int64Ty->getPrimitiveSizeInBits().getFixedSize(),
+V4Int32Ty->getPrimitiveSizeInBits().getFixedSize());
+
+  // Check the DataLayout interfaces.
+  EXPECT_EQ(DL.getTypeSizeInBits(V2Int64Ty),
+DL.getTypeSizeInBits(V4Int32Ty));
+  EXPECT_EQ(DL.getTypeSizeInBits(V2Int32Ty), 64U);
+  EXPECT_EQ(DL.getTypeSizeInBits(V2Int64Ty), 128U);
+  EXPECT_EQ(DL.getTypeStoreSize(V2Int64Ty),
+DL.getTypeStoreSize(V4Int32Ty));
+  EXPECT_NE(DL.getTypeStoreSizeInBits(V2Int32Ty),
+DL.getTypeStoreSizeInBits(V2Int64Ty));
+  EXPECT_EQ(DL.getTypeStoreSizeInBits(V2Int32Ty), 64U);
+  EXPECT_EQ(DL.getTypeStoreSize(V2Int64Ty), 16U);
+  EXPECT_EQ(DL.getTypeAllocSize(V4Int32Ty),
+DL.getTypeAllocSize(V2Int64Ty));
+  EXPECT_NE(DL.getTypeAllocSizeInBits(V2Int32Ty),
+DL.getTypeAllocSizeInBits(V2Int64Ty));
+  EXPECT_EQ(DL.getTypeAllocSizeInBits(V4Int32Ty), 128U);
+  EXPECT_EQ(DL.getTypeAllocSize(V2Int32Ty), 8U);
+  ASSERT_TRUE(DL.typeSizeEqualsStoreSize(V4Int32Ty));
+}
+
+TEST(VectorTypesTest, ScalableComparisons) {
+  LLVMContext Ctx;
+  DataLayout DL("");
+
+  Type *Int32Ty = Type::getInt32Ty(Ctx);
+  Type *Int64Ty = Type::getInt64Ty(Ctx);
+
+  VectorType *ScV2Int32Ty = VectorType::get(Int32Ty, {2, true});
+  VectorType *ScV4Int32Ty = VectorType::get(Int32Ty, {4, true});
+
+  VectorType *ScV2Int64Ty = VectorType::get(Int64Ty, {2, true});
+
+  TypeSize ScV2I32Len = ScV2Int32Ty->getPrimitiveSizeInBits();
+  EXPECT_EQ(ScV2I32Len.getKnownMinSize(), 64U);
+  EXPECT_TRUE(ScV2I32Len.isScalable());
+
+  EXPECT_LT(ScV2Int32Ty->getPrimitiveSizeInBits(),
+ScV4Int32Ty->getPrimitiveSizeInBits());
+  EXPECT_GT(ScV2Int64Ty->getPrimitiveSizeInBits(),
+ScV2Int32Ty->getPrimitiveSizeInBits());
+  EXPECT_EQ(ScV4Int32Ty->getPrimitiveSizeInBits(),
+ScV2Int64Ty->getPrimitiveSizeInBits());
+  EXPECT_NE(ScV2Int32Ty->getPrimitiveSizeInBits(),
+ScV2Int64Ty->getPrimitiveSizeInBits());
+
+  // Check the DataLayout interfaces.
+  EXPECT_EQ(DL.getTypeSizeInBits(ScV2Int64Ty),
+DL.getTypeSizeInBits(ScV4Int32Ty));
+  EXPECT

[PATCH] D53137: Scalable vector core instruction support + size queries

2019-10-01 Thread Graham Hunter via Phabricator via cfe-commits
huntergr added inline comments.



Comment at: llvm/include/llvm/IR/DataLayout.h:454
+auto BaseSize = getTypeSizeInBits(Ty);
+return { (BaseSize.getKnownMinSize() + 7) / 8, BaseSize.isScalable() };
   }

rovka wrote:
> We already overload operator /, why not overload + as well so we don't have 
> to change the body of this method?
Scaling a size with * or / has a clear meaning to me, since it's independent of 
vscale; getting a vector that's half the size or four times larger just works.

Using + (or -) on the other hand doesn't seem to be as clear; I wasn't sure if 
a standalone int should be automatically treated as being the same as the 
TypeSize, or always considered Fixed. If we try for the former I can imagine 
quite a few bugs arising.

I could add a roundBitsToNearestByteSize method to move the arithmetic 
elsewhere if that would be acceptable?



Comment at: llvm/include/llvm/IR/DataLayout.h:656
+ 
getTypeSizeInBits(VTy->getElementType()).getKnownMinSize();
+return ScalableSize(MinBits, EltCnt.Scalable);
   }

rovka wrote:
> Maybe just return VTy->getElementCount() * 
> getTypeSizeInBits(VTy->getElementType()).getFixedSize().
There's no support for generating a TypeSize from an ElementCount in that way; 
is that an interface you feel is useful?

(I'll certainly change the `getKnownMinSize` to `getFixedSize` though, since 
we're just referring to a scalar)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D53137



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


r373327 - [clang] Ignore builtin namespaces in test/Import/cxx-anon-namespace

2019-10-01 Thread Raphael Isemann via cfe-commits
Author: teemperor
Date: Tue Oct  1 04:53:20 2019
New Revision: 373327

URL: http://llvm.org/viewvc/llvm-project?rev=373327&view=rev
Log:
[clang] Ignore builtin namespaces in test/Import/cxx-anon-namespace

Some platforms (e.g. AArch64) put __va_list in the 'std' namespace which might
end up being the first namespace we match in this test. Instead let
the first namespace match via file name/line so that we skip the
builtin namespaces.

Modified:
cfe/trunk/test/Import/cxx-anon-namespace/test.cpp

Modified: cfe/trunk/test/Import/cxx-anon-namespace/test.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Import/cxx-anon-namespace/test.cpp?rev=373327&r1=373326&r2=373327&view=diff
==
--- cfe/trunk/test/Import/cxx-anon-namespace/test.cpp (original)
+++ cfe/trunk/test/Import/cxx-anon-namespace/test.cpp Tue Oct  1 04:53:20 2019
@@ -2,9 +2,13 @@
 
 // The implicit UsingDirectiveDecls for the anonymous namespaces are created 
by the Sema.
 
-// CHECK: NamespaceDecl
+// There might be another builtin namespace before our first namespace, so we 
can't
+// just look for NamespaceDecl. Instead look for the first line of F.cpp 
(which only
+// contains the namespace we are looking for but no other decl).
+// CHECK: F.cpp:1:1
 // The nested anonymous namespace.
 // CHECK-NEXT: NamespaceDecl
+// CHECK-SAME: 
 // CHECK: FunctionDecl
 // CHECK-SAME: func4
 // CHECK-NEXT: CompoundStmt


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


[PATCH] D68024: [clangd] Implement GetEligiblePoints

2019-10-01 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 222590.
kadircet marked an inline comment as done.
kadircet added a comment.

- Address comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D68024

Files:
  clang-tools-extra/clangd/SourceCode.cpp
  clang-tools-extra/clangd/SourceCode.h
  clang-tools-extra/clangd/unittests/SourceCodeTests.cpp

Index: clang-tools-extra/clangd/unittests/SourceCodeTests.cpp
===
--- clang-tools-extra/clangd/unittests/SourceCodeTests.cpp
+++ clang-tools-extra/clangd/unittests/SourceCodeTests.cpp
@@ -19,6 +19,7 @@
 #include "llvm/Testing/Support/Error.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
+#include 
 
 namespace clang {
 namespace clangd {
@@ -603,6 +604,67 @@
 Test.llvm::Annotations::point("bar"));
 }
 
+TEST(SourceCodeTests, GetEligiblePoints) {
+  constexpr struct {
+const char *Code;
+const char *FullyQualifiedName;
+const char *EnclosingNamespace;
+  } Cases[] = {
+  {R"cpp(// FIXME: We should also mark positions before and after
+ //declarations/definitions as eligible.
+  namespace ns1 {
+  namespace a { namespace ns2 {} }
+  namespace ns2 {^
+  void foo();
+  namespace {}
+  void bar() {}
+  namespace ns3 {}
+  class T {};
+  ^}
+  using namespace ns2;
+  })cpp",
+   "ns1::ns2::symbol", "ns1::ns2::"},
+  {R"cpp(
+  namespace ns1 {^
+  namespace a { namespace ns2 {} }
+  namespace b {}
+  namespace ns {}
+  ^})cpp",
+   "ns1::ns2::symbol", "ns1::"},
+  {R"cpp(
+  namespace x {
+  namespace a { namespace ns2 {} }
+  namespace b {}
+  namespace ns {}
+  }^)cpp",
+   "ns1::ns2::symbol", ""},
+  {R"cpp(
+  namespace ns1 {
+  namespace ns2 {^^}
+  namespace b {}
+  namespace ns2 {^^}
+  }
+  namespace ns1 {namespace ns2 {^^}})cpp",
+   "ns1::ns2::symbol", "ns1::ns2::"},
+  {R"cpp(
+  namespace ns1 {^
+  namespace ns {}
+  namespace b {}
+  namespace ns {}
+  ^}
+  namespace ns1 {^namespace ns {}^})cpp",
+   "ns1::ns2::symbol", "ns1::"},
+  };
+  for (auto Case : Cases) {
+Annotations Test(Case.Code);
+
+auto Res = getEligiblePoints(Test.code(), Case.FullyQualifiedName,
+ format::getLLVMStyle());
+EXPECT_THAT(Res.EligiblePoints, testing::ElementsAreArray(Test.points()))
+<< Test.code();
+EXPECT_EQ(Res.EnclosingNamespace, Case.EnclosingNamespace) << Test.code();
+  }
+}
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/SourceCode.h
===
--- clang-tools-extra/clangd/SourceCode.h
+++ clang-tools-extra/clangd/SourceCode.h
@@ -262,6 +262,27 @@
 std::vector visibleNamespaces(llvm::StringRef Code,
const format::FormatStyle &Style);
 
+/// Represents locations that can accept a definition.
+struct EligibleRegion {
+  /// Namespace that owns all of the EligiblePoints, e.g.
+  /// namespace a{ namespace b {^ void foo();^} }
+  /// It will be “a::b” for both carrot locations.
+  std::string EnclosingNamespace;
+  /// Offsets into the code marking eligible points to insert a function
+  /// definition.
+  std::vector EligiblePoints;
+};
+
+/// Returns most eligible region to insert a definition for \p
+/// FullyQualifiedName in the \p Code.
+/// Pseudo parses \pCode under the hood to determine namespace decls and
+/// possible insertion points. Choses the region that matches the longest prefix
+/// of \p FullyQualifiedName. Returns EOF if there are no shared namespaces.
+/// \p FullyQualifiedName should not contain anonymous namespaces.
+EligibleRegion getEligiblePoints(llvm::StringRef Code,
+ llvm::StringRef FullyQualifiedName,
+ const format::FormatStyle &Style);
+
 struct DefinedMacro {
   llvm::StringRef Name;
   const MacroInfo *Info;
Index: clang-tools-extra/clangd/SourceCode.cpp
===
--- clang-tools-extra/clangd/SourceCode.cpp
+++ clang-tools-extra/clangd/SourceCode.cpp
@@ -20,9 +20,11 @@
 #include "clang/Format/Format.h"
 #include "clang/Lex/Lexer.h"
 #include "clang/Lex/Preprocessor.h"
+#include "clang/Lex/Token.h"
 #include "clang/Tooling/Core/Replacement.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/None.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringMap.h"
 #include "llv

[PATCH] D67706: [clang][analyzer] Using CallDescription in StreamChecker.

2019-10-01 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus added a comment.

A few nits inline, otherwise the patch is awesome, thank you!!




Comment at: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp:60-61
 private:
-  void Fopen(CheckerContext &C, const CallExpr *CE) const;
-  void Tmpfile(CheckerContext &C, const CallExpr *CE) const;
-  void Fclose(CheckerContext &C, const CallExpr *CE) const;
-  void Fread(CheckerContext &C, const CallExpr *CE) const;
-  void Fwrite(CheckerContext &C, const CallExpr *CE) const;
-  void Fseek(CheckerContext &C, const CallExpr *CE) const;
-  void Ftell(CheckerContext &C, const CallExpr *CE) const;
-  void Rewind(CheckerContext &C, const CallExpr *CE) const;
-  void Fgetpos(CheckerContext &C, const CallExpr *CE) const;
-  void Fsetpos(CheckerContext &C, const CallExpr *CE) const;
-  void Clearerr(CheckerContext &C, const CallExpr *CE) const;
-  void Feof(CheckerContext &C, const CallExpr *CE) const;
-  void Ferror(CheckerContext &C, const CallExpr *CE) const;
-  void Fileno(CheckerContext &C, const CallExpr *CE) const;
-
-  void OpenFileAux(CheckerContext &C, const CallExpr *CE) const;
-
-  ProgramStateRef CheckNullStream(SVal SV, ProgramStateRef state,
- CheckerContext &C) const;
-  ProgramStateRef CheckDoubleClose(const CallExpr *CE, ProgramStateRef state,
- CheckerContext &C) const;
+  typedef void (StreamChecker::*FnCheck)(const CallEvent &,
+ CheckerContext &) const;
+

Prefer using. When I wrote D68165, I spent about 10 minutes figuring out how to 
do it... Ah, the joys of the C++ syntax.
```lang=c++
using FnCheck = void (StreamChecker::*)(const CallEvent &,
CheckerContext &) const;
```



Comment at: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp:109-110
 bool StreamChecker::evalCall(const CallEvent &Call, CheckerContext &C) const {
+  if (!Call.isGlobalCFunction())
+return false;
+

Isn't this redundant with my other inline about parameter types?



Comment at: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp:127-131
+  for (auto P : Call.parameters()) {
+QualType T = P->getType();
+if (!T->isIntegralOrEnumerationType() && !T->isPointerType())
+  return nullptr;
+  }

I'm not sure why we need this, is it true that *all* stream related functions 
return a pointer or a numerical value? Are we actually checking whether this 
really is a library function? If so, this looks pretty arbitrary.



Comment at: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp:156
+void StreamChecker::evalFread(const CallEvent &Call, CheckerContext &C) const {
+  (void)CheckNullStream(Call.getArgSVal(3), C);
 }

Why the need for `(void)`? `CheckNullSteam` doesn't seem to have an 
`LLVM_NODISCARD` attribute.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D67706



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


[PATCH] D67695: [clangd] Implement getBeginning for overloaded operators.

2019-10-01 Thread Haojian Wu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL373323: [clangd] Implement getBeginning for overloaded 
operators. (authored by hokein, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D67695?vs=222583&id=222586#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D67695

Files:
  clang-tools-extra/trunk/clangd/SourceCode.cpp
  clang-tools-extra/trunk/clangd/SourceCode.h
  clang-tools-extra/trunk/clangd/unittests/SourceCodeTests.cpp
  clang-tools-extra/trunk/clangd/unittests/XRefsTests.cpp

Index: clang-tools-extra/trunk/clangd/SourceCode.cpp
===
--- clang-tools-extra/trunk/clangd/SourceCode.cpp
+++ clang-tools-extra/trunk/clangd/SourceCode.cpp
@@ -237,6 +237,45 @@
   return halfOpenToRange(SM, CharSourceRange::getCharRange(TokLoc, End));
 }
 
+namespace {
+
+enum TokenFlavor { Identifier, Operator, Whitespace, Other };
+
+bool isOverloadedOperator(const Token &Tok) {
+  switch (Tok.getKind()) {
+#define OVERLOADED_OPERATOR(Name, Spelling, Token, Unary, Binary, MemOnly) \
+  case tok::Token:
+#define OVERLOADED_OPERATOR_MULTI(Name, Spelling, Unary, Binary, MemOnly)
+#include "clang/Basic/OperatorKinds.def"
+return true;
+
+  default:
+break;
+  }
+  return false;
+}
+
+TokenFlavor getTokenFlavor(SourceLocation Loc, const SourceManager &SM,
+   const LangOptions &LangOpts) {
+  Token Tok;
+  Tok.setKind(tok::NUM_TOKENS);
+  if (Lexer::getRawToken(Loc, Tok, SM, LangOpts,
+ /*IgnoreWhiteSpace*/ false))
+return Other;
+
+  // getRawToken will return false without setting Tok when the token is
+  // whitespace, so if the flag is not set, we are sure this is a whitespace.
+  if (Tok.is(tok::TokenKind::NUM_TOKENS))
+return Whitespace;
+  if (Tok.is(tok::TokenKind::raw_identifier))
+return Identifier;
+  if (isOverloadedOperator(Tok))
+return Operator;
+  return Other;
+}
+
+} // namespace
+
 SourceLocation getBeginningOfIdentifier(const Position &Pos,
 const SourceManager &SM,
 const LangOptions &LangOpts) {
@@ -247,27 +286,57 @@
 return SourceLocation();
   }
 
-  // GetBeginningOfToken(pos) is almost what we want, but does the wrong thing
-  // if the cursor is at the end of the identifier.
-  // Instead, we lex at GetBeginningOfToken(pos - 1). The cases are:
-  //  1) at the beginning of an identifier, we'll be looking at something
-  //  that isn't an identifier.
-  //  2) at the middle or end of an identifier, we get the identifier.
-  //  3) anywhere outside an identifier, we'll get some non-identifier thing.
-  // We can't actually distinguish cases 1 and 3, but returning the original
-  // location is correct for both!
+  // GetBeginningOfToken(InputLoc) is almost what we want, but does the wrong
+  // thing if the cursor is at the end of the token (identifier or operator).
+  // The cases are:
+  //   1) at the beginning of the token
+  //   2) at the middle of the token
+  //   3) at the end of the token
+  //   4) anywhere outside the identifier or operator
+  // To distinguish all cases, we lex both at the
+  // GetBeginningOfToken(InputLoc-1) and GetBeginningOfToken(InputLoc), for
+  // cases 1 and 4, we just return the original location.
   SourceLocation InputLoc = SM.getComposedLoc(FID, *Offset);
-  if (*Offset == 0) // Case 1 or 3.
+  if (*Offset == 0) // Case 1 or 4.
 return InputLoc;
   SourceLocation Before = SM.getComposedLoc(FID, *Offset - 1);
+  SourceLocation BeforeTokBeginning =
+  Lexer::GetBeginningOfToken(Before, SM, LangOpts);
+  TokenFlavor BeforeKind = getTokenFlavor(BeforeTokBeginning, SM, LangOpts);
+
+  SourceLocation CurrentTokBeginning =
+  Lexer::GetBeginningOfToken(InputLoc, SM, LangOpts);
+  TokenFlavor CurrentKind = getTokenFlavor(CurrentTokBeginning, SM, LangOpts);
+
+  // At the middle of the token.
+  if (BeforeTokBeginning == CurrentTokBeginning) {
+// For interesting token, we return the beginning of the token.
+if (CurrentKind == Identifier || CurrentKind == Operator)
+  return CurrentTokBeginning;
+// otherwise, we return the original loc.
+return InputLoc;
+  }
 
-  Before = Lexer::GetBeginningOfToken(Before, SM, LangOpts);
-  Token Tok;
-  if (Before.isValid() &&
-  !Lexer::getRawToken(Before, Tok, SM, LangOpts, false) &&
-  Tok.is(tok::raw_identifier))
-return Before; // Case 2.
-  return InputLoc; // Case 1 or 3.
+  // Whitespace is not interesting.
+  if (BeforeKind == Whitespace)
+return CurrentTokBeginning;
+  if (CurrentKind == Whitespace)
+return BeforeTokBeginning;
+
+  // The cursor is at the token boundary, e.g. "Before^Current", we prefer
+  // identifiers to other tokens.
+  if (Curre

[clang-tools-extra] r373323 - [clangd] Implement getBeginning for overloaded operators.

2019-10-01 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Tue Oct  1 04:03:56 2019
New Revision: 373323

URL: http://llvm.org/viewvc/llvm-project?rev=373323&view=rev
Log:
[clangd] Implement getBeginning for overloaded operators.

Summary:
This will fix some bugs where navigation doesn't work on cases like
`std::cout <^< "hello"`.

Reviewers: ilya-biryukov

Subscribers: MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits

Tags: #clang

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

Modified:
clang-tools-extra/trunk/clangd/SourceCode.cpp
clang-tools-extra/trunk/clangd/SourceCode.h
clang-tools-extra/trunk/clangd/unittests/SourceCodeTests.cpp
clang-tools-extra/trunk/clangd/unittests/XRefsTests.cpp

Modified: clang-tools-extra/trunk/clangd/SourceCode.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/SourceCode.cpp?rev=373323&r1=373322&r2=373323&view=diff
==
--- clang-tools-extra/trunk/clangd/SourceCode.cpp (original)
+++ clang-tools-extra/trunk/clangd/SourceCode.cpp Tue Oct  1 04:03:56 2019
@@ -237,6 +237,45 @@ llvm::Optional getTokenRange(cons
   return halfOpenToRange(SM, CharSourceRange::getCharRange(TokLoc, End));
 }
 
+namespace {
+
+enum TokenFlavor { Identifier, Operator, Whitespace, Other };
+
+bool isOverloadedOperator(const Token &Tok) {
+  switch (Tok.getKind()) {
+#define OVERLOADED_OPERATOR(Name, Spelling, Token, Unary, Binary, MemOnly) 
\
+  case tok::Token:
+#define OVERLOADED_OPERATOR_MULTI(Name, Spelling, Unary, Binary, MemOnly)
+#include "clang/Basic/OperatorKinds.def"
+return true;
+
+  default:
+break;
+  }
+  return false;
+}
+
+TokenFlavor getTokenFlavor(SourceLocation Loc, const SourceManager &SM,
+   const LangOptions &LangOpts) {
+  Token Tok;
+  Tok.setKind(tok::NUM_TOKENS);
+  if (Lexer::getRawToken(Loc, Tok, SM, LangOpts,
+ /*IgnoreWhiteSpace*/ false))
+return Other;
+
+  // getRawToken will return false without setting Tok when the token is
+  // whitespace, so if the flag is not set, we are sure this is a whitespace.
+  if (Tok.is(tok::TokenKind::NUM_TOKENS))
+return Whitespace;
+  if (Tok.is(tok::TokenKind::raw_identifier))
+return Identifier;
+  if (isOverloadedOperator(Tok))
+return Operator;
+  return Other;
+}
+
+} // namespace
+
 SourceLocation getBeginningOfIdentifier(const Position &Pos,
 const SourceManager &SM,
 const LangOptions &LangOpts) {
@@ -247,27 +286,57 @@ SourceLocation getBeginningOfIdentifier(
 return SourceLocation();
   }
 
-  // GetBeginningOfToken(pos) is almost what we want, but does the wrong thing
-  // if the cursor is at the end of the identifier.
-  // Instead, we lex at GetBeginningOfToken(pos - 1). The cases are:
-  //  1) at the beginning of an identifier, we'll be looking at something
-  //  that isn't an identifier.
-  //  2) at the middle or end of an identifier, we get the identifier.
-  //  3) anywhere outside an identifier, we'll get some non-identifier thing.
-  // We can't actually distinguish cases 1 and 3, but returning the original
-  // location is correct for both!
+  // GetBeginningOfToken(InputLoc) is almost what we want, but does the wrong
+  // thing if the cursor is at the end of the token (identifier or operator).
+  // The cases are:
+  //   1) at the beginning of the token
+  //   2) at the middle of the token
+  //   3) at the end of the token
+  //   4) anywhere outside the identifier or operator
+  // To distinguish all cases, we lex both at the
+  // GetBeginningOfToken(InputLoc-1) and GetBeginningOfToken(InputLoc), for
+  // cases 1 and 4, we just return the original location.
   SourceLocation InputLoc = SM.getComposedLoc(FID, *Offset);
-  if (*Offset == 0) // Case 1 or 3.
+  if (*Offset == 0) // Case 1 or 4.
 return InputLoc;
   SourceLocation Before = SM.getComposedLoc(FID, *Offset - 1);
+  SourceLocation BeforeTokBeginning =
+  Lexer::GetBeginningOfToken(Before, SM, LangOpts);
+  TokenFlavor BeforeKind = getTokenFlavor(BeforeTokBeginning, SM, LangOpts);
 
-  Before = Lexer::GetBeginningOfToken(Before, SM, LangOpts);
-  Token Tok;
-  if (Before.isValid() &&
-  !Lexer::getRawToken(Before, Tok, SM, LangOpts, false) &&
-  Tok.is(tok::raw_identifier))
-return Before; // Case 2.
-  return InputLoc; // Case 1 or 3.
+  SourceLocation CurrentTokBeginning =
+  Lexer::GetBeginningOfToken(InputLoc, SM, LangOpts);
+  TokenFlavor CurrentKind = getTokenFlavor(CurrentTokBeginning, SM, LangOpts);
+
+  // At the middle of the token.
+  if (BeforeTokBeginning == CurrentTokBeginning) {
+// For interesting token, we return the beginning of the token.
+if (CurrentKind == Identifier || CurrentKind == Operator)
+  return CurrentTokBeginning;
+// otherwise, we return the original loc.
+return InputLoc;
+  }
+
+  // Whitespace is not interesting.

[PATCH] D68182: [Clangd] Ensure children are always RootStmt in ExtractFunction (Fixes #153)

2019-10-01 Thread Shaurya Gupta via Phabricator via cfe-commits
SureYeaah updated this revision to Diff 222585.
SureYeaah marked 2 inline comments as done.
SureYeaah added a comment.

Address review comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D68182

Files:
  clang-tools-extra/clangd/refactor/tweaks/ExtractFunction.cpp
  clang-tools-extra/clangd/unittests/TweakTests.cpp


Index: clang-tools-extra/clangd/unittests/TweakTests.cpp
===
--- clang-tools-extra/clangd/unittests/TweakTests.cpp
+++ clang-tools-extra/clangd/unittests/TweakTests.cpp
@@ -554,7 +554,7 @@
   EXPECT_THAT(apply(" [[int a = 5;]] a++; "), StartsWith("fail"));
   // Don't extract return
   EXPECT_THAT(apply(" if(true) [[return;]] "), StartsWith("fail"));
-  
+
 }
 
 TEST_F(ExtractFunctionTest, FileTest) {
@@ -631,6 +631,9 @@
 F ([[int x = 0;]])
   )cpp";
   EXPECT_EQ(apply(MacroFailInput), "unavailable");
+
+  // Shouldn't crash.
+  EXPECT_EQ(apply("void f([[int a]]);"), "unavailable");
 }
 
 TEST_F(ExtractFunctionTest, ControlFlow) {
Index: clang-tools-extra/clangd/refactor/tweaks/ExtractFunction.cpp
===
--- clang-tools-extra/clangd/refactor/tweaks/ExtractFunction.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/ExtractFunction.cpp
@@ -104,6 +104,7 @@
 }
 
 // Returns the (unselected) parent of all RootStmts given the commonAncestor.
+// Returns null if any child is not a RootStmt.
 // We only support extraction of RootStmts since it allows us to extract 
without
 // having to change the selection range. Also, this means that any scope that
 // begins in selection range, ends in selection range and any scope that begins
@@ -111,10 +112,11 @@
 const Node *getParentOfRootStmts(const Node *CommonAnc) {
   if (!CommonAnc)
 return nullptr;
+  const Node *Parent = nullptr;
   switch (CommonAnc->Selected) {
   case SelectionTree::Selection::Unselected:
-// Ensure all Children are RootStmts.
-return llvm::all_of(CommonAnc->Children, isRootStmt) ? CommonAnc : nullptr;
+Parent = CommonAnc;
+break;
   case SelectionTree::Selection::Partial:
 // Treat Partially selected VarDecl as completely selected since
 // SelectionTree doesn't always select VarDecls correctly.
@@ -125,14 +127,17 @@
   case SelectionTree::Selection::Complete:
 // If the Common Ancestor is completely selected, then it's a root 
statement
 // and its parent will be unselected.
-const Node *Parent = CommonAnc->Parent;
+Parent = CommonAnc->Parent;
 // If parent is a DeclStmt, even though it's unselected, we consider it a
 // root statement and return its parent. This is done because the VarDecls
 // claim the entire selection range of the Declaration and DeclStmt is
 // always unselected.
-return Parent->ASTNode.get() ? Parent->Parent : Parent;
+if (Parent->ASTNode.get())
+  Parent = Parent->Parent;
+break;
   }
-  llvm_unreachable("Unhandled SelectionTree::Selection enum");
+  // Ensure all Children are RootStmts.
+  return llvm::all_of(Parent->Children, isRootStmt) ? Parent : nullptr;
 }
 
 // The ExtractionZone class forms a view of the code wrt Zone.


Index: clang-tools-extra/clangd/unittests/TweakTests.cpp
===
--- clang-tools-extra/clangd/unittests/TweakTests.cpp
+++ clang-tools-extra/clangd/unittests/TweakTests.cpp
@@ -554,7 +554,7 @@
   EXPECT_THAT(apply(" [[int a = 5;]] a++; "), StartsWith("fail"));
   // Don't extract return
   EXPECT_THAT(apply(" if(true) [[return;]] "), StartsWith("fail"));
-  
+
 }
 
 TEST_F(ExtractFunctionTest, FileTest) {
@@ -631,6 +631,9 @@
 F ([[int x = 0;]])
   )cpp";
   EXPECT_EQ(apply(MacroFailInput), "unavailable");
+
+  // Shouldn't crash.
+  EXPECT_EQ(apply("void f([[int a]]);"), "unavailable");
 }
 
 TEST_F(ExtractFunctionTest, ControlFlow) {
Index: clang-tools-extra/clangd/refactor/tweaks/ExtractFunction.cpp
===
--- clang-tools-extra/clangd/refactor/tweaks/ExtractFunction.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/ExtractFunction.cpp
@@ -104,6 +104,7 @@
 }
 
 // Returns the (unselected) parent of all RootStmts given the commonAncestor.
+// Returns null if any child is not a RootStmt.
 // We only support extraction of RootStmts since it allows us to extract without
 // having to change the selection range. Also, this means that any scope that
 // begins in selection range, ends in selection range and any scope that begins
@@ -111,10 +112,11 @@
 const Node *getParentOfRootStmts(const Node *CommonAnc) {
   if (!CommonAnc)
 return nullptr;
+  const Node *Parent = nullptr;
   switch (CommonAnc->Selected) {
   case SelectionTree::Selection::Unselected:
-// Ensure all Children are RootStmts.
-return llvm::all_of(CommonAnc->Children, isRootStmt) ? CommonAnc : nullptr;
+

[PATCH] D67695: [clangd] Implement getBeginning for overloaded operators.

2019-10-01 Thread Haojian Wu via Phabricator via cfe-commits
hokein added inline comments.



Comment at: clang-tools-extra/clangd/unittests/SourceCodeTests.cpp:330
+   "/^/ comments", // non-interesting token
+   "void f(int abc) { abc ^ ++; }",// whitespace
+   "void f(int abc) { ^abc^++; }", // range of identifier

ilya-biryukov wrote:
> Do we test `++^^abc` anywhere?
no, but we have a similar test ` ++/**/^abc`, added it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D67695



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


[PATCH] D67695: [clangd] Implement getBeginning for overloaded operators.

2019-10-01 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 222583.
hokein marked 2 inline comments as done.
hokein added a comment.

add one more testcase.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D67695

Files:
  clang-tools-extra/clangd/SourceCode.cpp
  clang-tools-extra/clangd/SourceCode.h
  clang-tools-extra/clangd/unittests/SourceCodeTests.cpp
  clang-tools-extra/clangd/unittests/XRefsTests.cpp

Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp
===
--- clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -441,6 +441,15 @@
   auto x = m^akeX();
 }
   )cpp",
+
+  R"cpp(
+struct X {
+  X& [[operator]]++() {}
+};
+void foo(X& x) {
+  +^+x;
+}
+  )cpp",
   };
   for (const char *Test : Tests) {
 Annotations T(Test);
Index: clang-tools-extra/clangd/unittests/SourceCodeTests.cpp
===
--- clang-tools-extra/clangd/unittests/SourceCodeTests.cpp
+++ clang-tools-extra/clangd/unittests/SourceCodeTests.cpp
@@ -319,14 +319,29 @@
 Bar* bar;
   )cpp";
   // First ^ is the expected beginning, last is the search position.
-  for (std::string Text : std::vector{
+  for (const std::string &Text : std::vector{
"int ^f^oo();", // inside identifier
"int ^foo();",  // beginning of identifier
"int ^foo^();", // end of identifier
"int foo(^);",  // non-identifier
"^int foo();",  // beginning of file (can't back up)
"int ^f0^0();", // after a digit (lexing at N-1 is wrong)
-   "int ^λλ^λ();", // UTF-8 handled properly when backing up
+   "/^/ comments", // non-interesting token
+   "void f(int abc) { abc ^ ++; }",// whitespace
+   "void f(int abc) { ^abc^++; }", // range of identifier
+   "void f(int abc) { ++^abc^; }", // range of identifier
+   "void f(int abc) { ++^abc; }",  // range of identifier
+   "void f(int abc) { ^+^+abc; }", // range of operator
+   "void f(int abc) { ^abc^ ++; }",// range of identifier
+   "void f(int abc) { abc ^++^; }",// range of operator
+   "void f(int abc) { ^++^ abc; }",// range of operator
+   "void f(int abc) { ++ ^abc^; }",// range of identifier
+   "void f(int abc) { ^++^/**/abc; }", // range of operator
+   "void f(int abc) { ++/**/^abc; }",  // range of identifier
+   "void f(int abc) { ^abc^/**/++; }", // range of identifier
+   "void f(int abc) { abc/**/^++; }",  // range of operator
+   "void f() {^ }", // outside of identifier and operator
+   "int ^λλ^λ();",  // UTF-8 handled properly when backing up
 
// identifier in macro arg
"MACRO(bar->^func())",  // beginning of identifier
Index: clang-tools-extra/clangd/SourceCode.h
===
--- clang-tools-extra/clangd/SourceCode.h
+++ clang-tools-extra/clangd/SourceCode.h
@@ -79,7 +79,7 @@
 Position P);
 
 /// Get the beginning SourceLocation at a specified \p Pos in the main file.
-/// May be invalid if Pos is, or if there's no identifier.
+/// May be invalid if Pos is, or if there's no identifier or operators.
 /// The returned position is in the main file, callers may prefer to
 /// obtain the macro expansion location.
 SourceLocation getBeginningOfIdentifier(const Position &Pos,
Index: clang-tools-extra/clangd/SourceCode.cpp
===
--- clang-tools-extra/clangd/SourceCode.cpp
+++ clang-tools-extra/clangd/SourceCode.cpp
@@ -237,6 +237,45 @@
   return halfOpenToRange(SM, CharSourceRange::getCharRange(TokLoc, End));
 }
 
+namespace {
+
+enum TokenFlavor { Identifier, Operator, Whitespace, Other };
+
+bool isOverloadedOperator(const Token &Tok) {
+  switch (Tok.getKind()) {
+#define OVERLOADED_OPERATOR(Name, Spelling, Token, Unary, Binary, MemOnly) \
+  case tok::Token:
+#define OVERLOADED_OPERATOR_MULTI(Name, Spelling, Unary, Binary, MemOnly)
+#include "clang/Basic/OperatorKinds.def"
+return true;
+
+  default:
+break;
+  }
+  return false;
+}
+
+TokenFlavor getTokenFlavor(SourceLocation Loc, const SourceManager &SM,
+   const LangOptions &LangOpts) {
+  Token Tok;
+  Tok.setKind(tok::NUM_TOKENS);
+  if (Lexer::getRawToken(Loc, Tok, SM, LangOpts,
+ /*IgnoreWhiteSpace*/ false))
+return Other;
+
+  // getRawToken will return false without setting Tok when the token is
+  // whitespace, so if the flag is not set, we are sure this is a whitespace.
+  if (Tok.is(tok::TokenKind::NUM_TOKENS))
+return Whitespace;
+ 

[PATCH] D68024: [clangd] Implement GetEligiblePoints

2019-10-01 Thread Haojian Wu via Phabricator via cfe-commits
hokein accepted this revision.
hokein added a comment.
This revision is now accepted and ready to land.

looks good.




Comment at: clang-tools-extra/clangd/unittests/SourceCodeTests.cpp:610
+   /*FullyQualifiedName=*/const char *,
+   /*CurrentNamespace*/ const char *>
+  Cases[] = {

nit: I'd use a struct, it is hard to infer the member by reading `get<0>`,  
`get<1>` (I have to go back to the top)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D68024



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


[PATCH] D68143: [clang] Make handling of unnamed template params similar to function params

2019-10-01 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 222581.
kadircet added a comment.

- Address comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D68143

Files:
  clang/lib/AST/DeclTemplate.cpp
  clang/lib/Parse/ParseTemplate.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/test/AST/ast-dump-decl.cpp
  clang/test/AST/ast-dump-record-definition-data-json.cpp
  clang/test/AST/ast-dump-template-decls-json.cpp
  clang/test/AST/ast-dump-template-decls.cpp
  clang/test/ASTMerge/class-template/test.cpp
  clang/test/Index/index-templates.cpp

Index: clang/test/Index/index-templates.cpp
===
--- clang/test/Index/index-templates.cpp
+++ clang/test/Index/index-templates.cpp
@@ -155,7 +155,7 @@
 // CHECK-LOAD: index-templates.cpp:36:44: DeclRefExpr=OneDimension:35:16 Extent=[36:44 - 36:56]
 // CHECK-LOAD: index-templates.cpp:40:8: ClassTemplate=storage:40:8 (Definition) Extent=[39:1 - 40:19]
 // CHECK-LOAD: index-templates.cpp:39:45: TemplateTemplateParameter=DataStructure:39:45 (Definition) Extent=[39:10 - 39:66]
-// CHECK-LOAD: index-templates.cpp:39:19: TemplateTypeParameter=:39:19 (Definition) Extent=[39:19 - 39:27]
+// CHECK-LOAD: index-templates.cpp:39:27: TemplateTypeParameter=:39:27 (Definition) Extent=[39:19 - 39:27]
 // CHECK-LOAD: index-templates.cpp:39:37: NonTypeTemplateParameter=:39:37 (Definition) Extent=[39:29 - 39:37]
 // CHECK-LOAD: index-templates.cpp:39:61: TemplateRef=array:37:8 Extent=[39:61 - 39:66]
 // CHECK-LOAD: index-templates.cpp:42:18: TypedefDecl=Unsigned:42:18 (Definition) Extent=[42:1 - 42:26]
Index: clang/test/ASTMerge/class-template/test.cpp
===
--- clang/test/ASTMerge/class-template/test.cpp
+++ clang/test/ASTMerge/class-template/test.cpp
@@ -9,13 +9,13 @@
 // CHECK: class-template2.cpp:9:15: note: declared here with type 'long'
 
 // CHECK: class-template1.cpp:12:14: warning: template parameter has different kinds in different translation units
-// CHECK: class-template2.cpp:12:10: note: template parameter declared here
+// CHECK: class-template2.cpp:12:18: note: template parameter declared here
 
 // CHECK: class-template1.cpp:18:23: warning: non-type template parameter declared with incompatible types in different translation units ('long' vs. 'int')
 // CHECK: class-template2.cpp:18:23: note: declared here with type 'int'
 
-// CHECK: class-template1.cpp:21:10: warning: template parameter has different kinds in different translation units
-// CHECK: class-template2.cpp:21:10: note: template parameter declared here
+// CHECK: class-template1.cpp:21:18: warning: template parameter has different kinds in different translation units
+// CHECK: class-template2.cpp:21:31: note: template parameter declared here
 
 // CHECK: class-template2.cpp:27:20: warning: external variable 'x0r' declared with incompatible types in different translation units ('X0 *' vs. 'X0 *')
 // CHECK: class-template1.cpp:26:19: note: declared here with type 'X0 *'
Index: clang/test/AST/ast-dump-template-decls.cpp
===
--- clang/test/AST/ast-dump-template-decls.cpp
+++ clang/test/AST/ast-dump-template-decls.cpp
@@ -26,7 +26,7 @@
 // CHECK: FunctionTemplateDecl 0x{{[^ ]*}}  col:6 d
 // CHECK-NEXT: TemplateTypeParmDecl 0x{{[^ ]*}}  col:20 referenced typename depth 0 index 0 Ty
 // CHECK-NEXT: TemplateTemplateParmDecl 0x{{[^ ]*}}  col:52 depth 0 index 1 Uy
-// CHECK-NEXT: TemplateTypeParmDecl 0x{{[^ ]*}}  col:33 typename depth 1 index 0
+// CHECK-NEXT: TemplateTypeParmDecl 0x{{[^ ]*}}  col:41 typename depth 1 index 0
 void d(Ty, Uy);
 
 template 
@@ -47,7 +47,7 @@
 
 template 
 // CHECK: FunctionTemplateDecl 0x{{[^ ]*}}  col:6 h
-// CHECK-NEXT: TemplateTypeParmDecl 0x{{[^ ]*}}  col:11 typename depth 0 index 0
+// CHECK-NEXT: TemplateTypeParmDecl 0x{{[^ ]*}}  col:20 typename depth 0 index 0
 // CHECK-NEXT: TemplateArgument type 'void'
 void h();
 
Index: clang/test/AST/ast-dump-template-decls-json.cpp
===
--- clang/test/AST/ast-dump-template-decls-json.cpp
+++ clang/test/AST/ast-dump-template-decls-json.cpp
@@ -656,8 +656,8 @@
 // CHECK-NEXT:"id": "0x{{.*}}",
 // CHECK-NEXT:"kind": "TemplateTypeParmDecl",
 // CHECK-NEXT:"loc": {
-// CHECK-NEXT: "col": 33,
-// CHECK-NEXT: "tokLen": 8
+// CHECK-NEXT: "col": 41,
+// CHECK-NEXT: "tokLen": 1
 // CHECK-NEXT:},
 // CHECK-NEXT:"range": {
 // CHECK-NEXT: "begin": {
@@ -1099,8 +1099,8 @@
 // CHECK-NEXT:  "kind": "TemplateTypeParmDecl",
 // CHECK-NEXT:  "loc": {
 // CHECK-NEXT:   "line": 27,
-// CHECK-NEXT:   "col": 11,
-// CHECK-NEXT:   "tokLen": 8
+// CHECK-NEXT:   "col": 20,
+// CHECK-NEXT:   "tokLen": 1
 // CHECK-NEXT:  },
 // CHECK-NEXT:  

[PATCH] D68143: [clang] Make handling of unnamed template params similar to function params

2019-10-01 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet marked an inline comment as done.
kadircet added inline comments.



Comment at: clang/lib/AST/DeclTemplate.cpp:513
getDefaultArgumentInfo()->getTypeLoc().getEndLoc());
-  else
-return TypeDecl::getSourceRange();
+  else if(getName().empty())
+return SourceRange(getBeginLoc());

ilya-biryukov wrote:
> kadircet wrote:
> > ilya-biryukov wrote:
> > > Could you provide more details why we need this change?
> > added comments, you can also see the similar case in 
> > `DeclaratorDecl::getSourceRange()`
> Could you provide an example? What the range was before and what is it now?
> 
TypeDecl::getSourceRange will also include the next token if template parameter 
is unnamed for example:

```
template 
  ~
```

has the following `>` covered inside typerange.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D68143



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


  1   2   >