[PATCH] D41412: [libcxx] implement concat() and split()

2019-07-25 Thread Tobias Grosser via Phabricator via cfe-commits
grosser added a comment.

@EricWF thanks again for offering your help here. We are not in a rush here, 
but I wonder if you happen to have a rough estimate when you might have the 
time to look into these patches?


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

https://reviews.llvm.org/D41412



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


[PATCH] D62731: [RFC] Add support for options -fp-model= and -fp-speculation= : specify floating point behavior

2019-07-25 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added inline comments.



Comment at: llvm/include/llvm/IR/FPState.h:1
+#ifndef LLVM_FPSTATE_H
+#define LLVM_FPSTATE_H

Missing license header and c++ mode comment



Comment at: llvm/lib/IR/FPState.cpp:1
+#include "llvm/IR/FPState.h"
+#include "llvm/IR/IRBuilder.h"

Missing license header



Comment at: llvm/lib/IR/FPState.cpp:73
+  if (IsConstrainedExcept && !IsConstrainedRounding) {
+// If the rounding mode isn't set explicitly above, then use ebToNearest
+// as the value when the constrained intrinsic is created

eb?



Comment at: llvm/unittests/IR/IRBuilderTest.cpp:205
+  V = Builder.CreateFAdd(V, V);
+  ASSERT_TRUE(!isa(V));
+

ASSERT_FALSE with no !



Comment at: llvm/unittests/IR/IRBuilderTest.cpp:217-218
+  ASSERT_TRUE(isa(V));
+  ASSERT_TRUE(CII->getExceptionBehavior() == ConstrainedFPIntrinsic::ebStrict);
+  ASSERT_TRUE(CII->getRoundingMode() == ConstrainedFPIntrinsic::rmDynamic);
+

Most of these should not be using ASSERT_, and instead EXPECT_EQ



Comment at: llvm/unittests/IR/IRBuilderTest.cpp:258
+  CII = cast(V);
+  ASSERT_TRUE(isa(V));
+  ASSERT_TRUE(CII->getExceptionBehavior() == 
ConstrainedFPIntrinsic::ebMayTrap);

This already would have crashed from the cast<> before



Comment at: llvm/unittests/IR/IRBuilderTest.cpp:259-260
+  ASSERT_TRUE(isa(V));
+  ASSERT_TRUE(CII->getExceptionBehavior() == 
ConstrainedFPIntrinsic::ebMayTrap);
+  ASSERT_TRUE(CII->getRoundingMode() == ConstrainedFPIntrinsic::rmToNearest);
 

EXPECT_EQ


Repository:
  rL LLVM

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

https://reviews.llvm.org/D62731



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


[PATCH] D65030: [clang-doc] Add second index for sections within info's content

2019-07-25 Thread Diego Astiazarán via Phabricator via cfe-commits
DiegoAstiazaran updated this revision to Diff 211869.
DiegoAstiazaran marked 3 inline comments as done.
DiegoAstiazaran added a comment.

Add comment.


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

https://reviews.llvm.org/D65030

Files:
  clang-tools-extra/clang-doc/HTMLGenerator.cpp
  clang-tools-extra/clang-doc/Representation.cpp
  clang-tools-extra/clang-doc/Representation.h
  clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp

Index: clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
+++ clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
@@ -44,26 +44,36 @@
   std::string Expected = R"raw(
 
 namespace Namespace
+
+  Namespaces
+  Records
+  Functions
+  OneFunction
+
+  Enums
+  OneEnum
+
+
 
   namespace Namespace
-  Namespaces
+  Namespaces
   
 ChildNamespace
   
-  Records
+  Records
   
 ChildStruct
   
-  Functions
+  Functions
   
-OneFunction
+OneFunction
 
   OneFunction()
 
   
-  Enums
+  Enums
   
-enum OneEnum
+enum OneEnum
   
 
 )raw";
@@ -106,6 +116,16 @@
   std::string Expected = R"raw(
 
 class r
+
+  Members
+  Records
+  Functions
+  OneFunction
+
+  Enums
+  OneEnum
+
+
 
   class r
   
@@ -117,25 +137,25 @@
  R"raw(">F
 , G
   
-  Members
+  Members
   
 private int X
   
-  Records
+  Records
   
 ChildStruct
   
-  Functions
+  Functions
   
-OneFunction
+OneFunction
 
   OneFunction()
 
   
-  Enums
+  Enums
   
-enum OneEnum
+enum OneEnum
   
 
 )raw";
@@ -172,7 +192,7 @@
 
 
 
-  f
+  f
   
 float
@@ -211,7 +231,7 @@
 
 
 
-  enum class e
+  enum class e
   
 X
   
@@ -271,7 +291,7 @@
 
 
 
-  f
+  f
   
 void f(int I, int J)
   
Index: clang-tools-extra/clang-doc/Representation.h
===
--- clang-tools-extra/clang-doc/Representation.h
+++ clang-tools-extra/clang-doc/Representation.h
@@ -239,7 +239,7 @@
   void mergeBase(Info &);
   bool mergeable(const Info );
 
-  llvm::SmallString<16> extractName();
+  llvm::SmallString<16> extractName() const;
 
   // Returns a reference to the parent scope (that is, the immediate parent
   // namespace or class in which this decl resides).
@@ -340,11 +340,14 @@
 
 struct Index : public Reference {
   Index() = default;
+  Index(StringRef Name, StringRef JumpToSection)
+  : Reference(Name), JumpToSection(JumpToSection) {}
   Index(SymbolID USR, StringRef Name, InfoType IT, StringRef Path)
   : Reference(USR, Name, IT, Path) {}
   bool operator==(const SymbolID ) const { return USR == Other; }
   bool operator<(const Index ) const { return Name < Other.Name; }
 
+  SmallString<16> JumpToSection;
   std::vector Children;
 
   void sort();
Index: clang-tools-extra/clang-doc/Representation.cpp
===
--- clang-tools-extra/clang-doc/Representation.cpp
+++ clang-tools-extra/clang-doc/Representation.cpp
@@ -197,7 +197,7 @@
   SymbolInfo::merge(std::move(Other));
 }
 
-llvm::SmallString<16> Info::extractName() {
+llvm::SmallString<16> Info::extractName() const {
   if (!Name.empty())
 return Name;
 
Index: clang-tools-extra/clang-doc/HTMLGenerator.cpp
===
--- clang-tools-extra/clang-doc/HTMLGenerator.cpp
+++ clang-tools-extra/clang-doc/HTMLGenerator.cpp
@@ -252,13 +252,20 @@
   return LinkNode;
 }
 
-static std::unique_ptr genTypeReference(const Reference ,
-  StringRef CurrentDirectory) {
-  if (Type.Path.empty())
-return llvm::make_unique(Type.Name);
+static std::unique_ptr
+genTypeReference(const Reference , StringRef CurrentDirectory,
+ StringRef JumpToSection = "") {
+  if (Type.Path.empty()) {
+if (JumpToSection.empty())
+  return llvm::make_unique(Type.Name);
+else
+  return genLink(Type.Name, "#" + JumpToSection);
+  }
   llvm::SmallString<128> Path =
   computeRelativePath(Type.Path, CurrentDirectory);
   llvm::sys::path::append(Path, Type.Name + ".html");
+  if (!JumpToSection.empty())
+Path += ("#" + JumpToSection).str();
   return genLink(Type.Name, Path);
 }
 
@@ -285,6 +292,7 @@
 
   std::vector> Out;
   Out.emplace_back(llvm::make_unique(HTMLTag::TAG_H2, "Enums"));
+  Out.back()->Attributes.try_emplace("id", "Enums");
   Out.emplace_back(llvm::make_unique(HTMLTag::TAG_DIV));
   auto  = Out.back();
   for (const auto  : Enums) {
@@ -313,6 +321,7 @@
 
   std::vector> Out;
   Out.emplace_back(llvm::make_unique(HTMLTag::TAG_H2, "Functions"));
+  Out.back()->Attributes.try_emplace("id", "Functions");
   Out.emplace_back(llvm::make_unique(HTMLTag::TAG_DIV));
   auto  = Out.back();
   for (const auto  : Functions) {
@@ -330,6 +339,7 @@
 
   std::vector> Out;
   

[PATCH] D65003: [clang-doc] Add index in each info html file

2019-07-25 Thread Diego Astiazarán via Phabricator via cfe-commits
DiegoAstiazaran added inline comments.



Comment at: clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp:337-346
+
+  A
+  B
+  C
+
+  D
+  E

juliehockett wrote:
> The indentation here seems a bit off
Fixed by D65005.


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

https://reviews.llvm.org/D65003



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


[PATCH] D65003: [clang-doc] Add index in each info html file

2019-07-25 Thread Diego Astiazarán via Phabricator via cfe-commits
DiegoAstiazaran updated this revision to Diff 211866.
DiegoAstiazaran marked 3 inline comments as done.
DiegoAstiazaran added a comment.

Rebase and add comments.


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

https://reviews.llvm.org/D65003

Files:
  clang-tools-extra/clang-doc/Generators.cpp
  clang-tools-extra/clang-doc/Generators.h
  clang-tools-extra/clang-doc/HTMLGenerator.cpp
  clang-tools-extra/clang-doc/Representation.cpp
  clang-tools-extra/clang-doc/Representation.h
  clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
  clang-tools-extra/unittests/clang-doc/CMakeLists.txt
  clang-tools-extra/unittests/clang-doc/ClangDocTest.cpp
  clang-tools-extra/unittests/clang-doc/ClangDocTest.h
  clang-tools-extra/unittests/clang-doc/GeneratorTest.cpp
  clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp

Index: clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
+++ clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
@@ -9,6 +9,7 @@
 #include "ClangDocTest.h"
 #include "Generators.h"
 #include "Representation.h"
+#include "Serialize.h"
 #include "gtest/gtest.h"
 
 namespace clang {
@@ -315,5 +316,79 @@
   EXPECT_EQ(Expected, Actual.str());
 }
 
+TEST(HTMLGeneratorTest, emitIndexHTML) {
+  RecordInfo I;
+  I.Path = "";
+  ClangDocContext CDCtx;
+  std::vector> Infos;
+  Infos.emplace_back(llvm::make_unique());
+  Info *InfoA = Infos.back().get();
+  InfoA->Name = "A";
+  InfoA->USR = serialize::hashUSR("1");
+  Infos.emplace_back(llvm::make_unique());
+  Info *InfoC = Infos.back().get();
+  InfoC->Name = "C";
+  InfoC->USR = serialize::hashUSR("3");
+  Reference RefB = Reference("B");
+  RefB.USR = serialize::hashUSR("2");
+  InfoC->Namespace = {std::move(RefB)};
+  Infos.emplace_back(llvm::make_unique());
+  Info *InfoD = Infos.back().get();
+  InfoD->Name = "D";
+  InfoD->USR = serialize::hashUSR("4");
+  Infos.emplace_back(llvm::make_unique());
+  Info *InfoF = Infos.back().get();
+  InfoF->Name = "F";
+  InfoF->USR = serialize::hashUSR("6");
+  Reference RefD = Reference("D");
+  RefD.USR = serialize::hashUSR("4");
+  Reference RefE = Reference("E");
+  RefE.USR = serialize::hashUSR("5");
+  InfoF->Namespace = {std::move(RefE), std::move(RefD)};
+  CDCtx.Idx = Generator::genIndex(Infos);
+
+  auto G = getHTMLGenerator();
+  assert(G);
+  std::string Buffer;
+  llvm::raw_string_ostream Actual(Buffer);
+  auto Err = G->generateDocForInfo(, Actual, CDCtx);
+  assert(!Err);
+  std::string Expected = R"raw(
+
+struct 
+
+  
+A
+  
+  
+B
+
+  
+C
+  
+
+  
+  
+D
+
+  
+E
+
+  
+F
+  
+
+  
+
+  
+
+
+  struct 
+
+)raw";
+
+  EXPECT_EQ(Expected, Actual.str());
+}
+
 } // namespace doc
 } // namespace clang
Index: clang-tools-extra/unittests/clang-doc/GeneratorTest.cpp
===
--- /dev/null
+++ clang-tools-extra/unittests/clang-doc/GeneratorTest.cpp
@@ -0,0 +1,70 @@
+//===-- clang-doc/GeneratorTest.cpp ---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "ClangDocTest.h"
+#include "Generators.h"
+#include "Representation.h"
+#include "Serialize.h"
+#include "gtest/gtest.h"
+
+namespace clang {
+namespace doc {
+
+TEST(GeneratorTest, emitIndex) {
+  std::vector> Infos;
+  Infos.emplace_back(llvm::make_unique());
+  Info *InfoA = Infos.back().get();
+  InfoA->Name = "A";
+  InfoA->USR = serialize::hashUSR("1");
+  Infos.emplace_back(llvm::make_unique());
+  Info *InfoC = Infos.back().get();
+  InfoC->Name = "C";
+  InfoC->USR = serialize::hashUSR("3");
+  Reference RefB = Reference("B");
+  RefB.USR = serialize::hashUSR("2");
+  InfoC->Namespace = {std::move(RefB)};
+  Infos.emplace_back(llvm::make_unique());
+  Info *InfoD = Infos.back().get();
+  InfoD->Name = "D";
+  InfoD->USR = serialize::hashUSR("4");
+  Infos.emplace_back(llvm::make_unique());
+  Info *InfoF = Infos.back().get();
+  InfoF->Name = "F";
+  InfoF->USR = serialize::hashUSR("6");
+  Reference RefD = Reference("D");
+  RefD.USR = serialize::hashUSR("4");
+  Reference RefE = Reference("E");
+  RefE.USR = serialize::hashUSR("5");
+  InfoF->Namespace = {std::move(RefE), std::move(RefD)};
+  Index Idx = Generator::genIndex(Infos);
+
+  Index ExpectedIdx;
+  Index IndexA;
+  IndexA.Name = "A";
+  ExpectedIdx.Children.emplace_back(std::move(IndexA));
+  Index IndexB;
+  IndexB.Name = "B";
+  Index IndexC;
+  IndexC.Name = "C";
+  IndexB.Children.emplace_back(std::move(IndexC));
+  

[PATCH] D64380: Add 'require_designated_init' and 'required' attribute to clang

2019-07-25 Thread Aditya Kumar via Phabricator via cfe-commits
hiraditya added a comment.

Thanks for addressing the feedback @emmettneyman , LGTM, deferring to other 
reviewers for final call.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64380



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


[PATCH] D65227: clang-format: Support `if CONSTEXPR` if CONSTEXPR is a macro.

2019-07-25 Thread Manuel Klimek via Phabricator via cfe-commits
klimek accepted this revision.
klimek added a comment.
This revision is now accepted and ready to land.

I am surprised this works as well as it does, but tests seem to indicate it 
does, so... LG (minus potentially reducing some duplication :)




Comment at: clang/lib/Format/TokenAnnotator.cpp:2415
   if (Left.is(tok::l_paren) && Left.Previous &&
   (Left.Previous->isOneOf(tok::kw_if, tok::kw_for) ||
+   Left.Previous->endsSequence(tok::kw_constexpr, tok::kw_if) ||

Do we want to pull out a function for the repeated condition?


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

https://reviews.llvm.org/D65227



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


r367076 - Revert "[Sema] Diagnose default-initialization, destruction, and copying of"

2019-07-25 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Thu Jul 25 17:02:17 2019
New Revision: 367076

URL: http://llvm.org/viewvc/llvm-project?rev=367076=rev
Log:
Revert "[Sema] Diagnose default-initialization, destruction, and copying of"

This reverts commit r365985.

Prior to r365985, clang used to mark C union fields that have
non-trivial ObjC ownership qualifiers as unavailable if the union was
declared in a system header. r365985 stopped doing so, which caused the
swift compiler to crash when it tried to import a non-trivial union.

I have a patch that fixes the crash (https://reviews.llvm.org/D65256),
but I'm temporarily reverting the original patch until we can decide on
whether it's taking the right approach.

Added:
cfe/trunk/test/CodeGenObjC/Inputs/strong_in_union.h
Removed:
cfe/trunk/test/PCH/non-trivial-c-union.m
cfe/trunk/test/SemaObjC/non-trivial-c-union.m
Modified:
cfe/trunk/include/clang/AST/Decl.h
cfe/trunk/include/clang/AST/DeclBase.h
cfe/trunk/include/clang/AST/Type.h
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/AST/Decl.cpp
cfe/trunk/lib/AST/Type.cpp
cfe/trunk/lib/Sema/Sema.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/lib/Sema/SemaType.cpp
cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
cfe/trunk/lib/Serialization/ASTWriterDecl.cpp
cfe/trunk/test/CodeGenObjC/strong-in-c-struct.m
cfe/trunk/test/SemaObjC/arc-decls.m

Modified: cfe/trunk/include/clang/AST/Decl.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=367076=367075=367076=diff
==
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Thu Jul 25 17:02:17 2019
@@ -3746,30 +3746,6 @@ public:
 RecordDeclBits.NonTrivialToPrimitiveDestroy = V;
   }
 
-  bool hasNonTrivialToPrimitiveDefaultInitializeCUnion() const {
-return RecordDeclBits.HasNonTrivialToPrimitiveDefaultInitializeCUnion;
-  }
-
-  void setHasNonTrivialToPrimitiveDefaultInitializeCUnion(bool V) {
-RecordDeclBits.HasNonTrivialToPrimitiveDefaultInitializeCUnion = V;
-  }
-
-  bool hasNonTrivialToPrimitiveDestructCUnion() const {
-return RecordDeclBits.HasNonTrivialToPrimitiveDestructCUnion;
-  }
-
-  void setHasNonTrivialToPrimitiveDestructCUnion(bool V) {
-RecordDeclBits.HasNonTrivialToPrimitiveDestructCUnion = V;
-  }
-
-  bool hasNonTrivialToPrimitiveCopyCUnion() const {
-return RecordDeclBits.HasNonTrivialToPrimitiveCopyCUnion;
-  }
-
-  void setHasNonTrivialToPrimitiveCopyCUnion(bool V) {
-RecordDeclBits.HasNonTrivialToPrimitiveCopyCUnion = V;
-  }
-
   /// Determine whether this class can be passed in registers. In C++ mode,
   /// it must have at least one trivial, non-deleted copy or move constructor.
   /// FIXME: This should be set as part of completeDefinition.

Modified: cfe/trunk/include/clang/AST/DeclBase.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclBase.h?rev=367076=367075=367076=diff
==
--- cfe/trunk/include/clang/AST/DeclBase.h (original)
+++ cfe/trunk/include/clang/AST/DeclBase.h Thu Jul 25 17:02:17 2019
@@ -1440,13 +1440,6 @@ class DeclContext {
 uint64_t NonTrivialToPrimitiveCopy : 1;
 uint64_t NonTrivialToPrimitiveDestroy : 1;
 
-/// The following bits indicate whether this is or contains a C union that
-/// is non-trivial to default-initialize, destruct, or copy. These bits
-/// imply the associated basic non-triviality predicates declared above.
-uint64_t HasNonTrivialToPrimitiveDefaultInitializeCUnion : 1;
-uint64_t HasNonTrivialToPrimitiveDestructCUnion : 1;
-uint64_t HasNonTrivialToPrimitiveCopyCUnion : 1;
-
 /// Indicates whether this struct is destroyed in the callee.
 uint64_t ParamDestroyedInCallee : 1;
 
@@ -1455,7 +1448,7 @@ class DeclContext {
   };
 
   /// Number of non-inherited bits in RecordDeclBitfields.
-  enum { NumRecordDeclBits = 14 };
+  enum { NumRecordDeclBits = 11 };
 
   /// Stores the bits used by OMPDeclareReductionDecl.
   /// If modified NumOMPDeclareReductionDeclBits and the accessor

Modified: cfe/trunk/include/clang/AST/Type.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=367076=367075=367076=diff
==
--- cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/trunk/include/clang/AST/Type.h Thu Jul 25 17:02:17 2019
@@ -1130,6 +1130,12 @@ public:
   };
 
   /// Check if this is a non-trivial type that would cause a C struct
+  /// transitively containing this type to be non-trivial. This function can be
+  /// used to determine whether a field of this type can be declared inside a C
+  /// union.
+  bool isNonTrivialPrimitiveCType(const ASTContext ) const;
+
+  /// Check if 

[PATCH] D65309: [clang-format] Fix style of css file paths

2019-07-25 Thread Diego Astiazarán via Phabricator via cfe-commits
DiegoAstiazaran created this revision.
DiegoAstiazaran added reviewers: juliehockett, jakehehrlich.
DiegoAstiazaran added a project: clang-tools-extra.

CSS files included in HTML should have a path in posix style, it should not be 
different for Windows.


https://reviews.llvm.org/D65309

Files:
  clang-tools-extra/clang-doc/HTMLGenerator.cpp
  clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp


Index: clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
+++ clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
@@ -110,34 +110,23 @@
   ClangDocContext CDCtx = getClangDocContext();
   auto Err = G->generateDocForInfo(, Actual, CDCtx);
   assert(!Err);
-  SmallString<16> PathToF;
-  llvm::sys::path::native("../../../path/to/F.html", PathToF);
-  SmallString<16> PathToInt;
-  llvm::sys::path::native("../int.html", PathToInt);
-  SmallString<16> PathToSylesheet;
-  llvm::sys::path::native("../../../clang-doc-default-stylesheet.css",
-  PathToSylesheet);
   std::string Expected = R"raw(
 
 class r
-
+
 
   class r
   Defined at line 10 of test.cpp
   
 Inherits from 
-F
+F
 , G
   
   Members
   
 
   private 
-  int
+  int
X
 
   
Index: clang-tools-extra/clang-doc/HTMLGenerator.cpp
===
--- clang-tools-extra/clang-doc/HTMLGenerator.cpp
+++ clang-tools-extra/clang-doc/HTMLGenerator.cpp
@@ -231,6 +231,7 @@
 SmallString<128> StylesheetPath = computeRelativePath("", InfoPath);
 llvm::sys::path::append(StylesheetPath,
 llvm::sys::path::filename(FilePath));
+llvm::sys::path::native(StylesheetPath, llvm::sys::path::Style::posix);
 LinkNode->Attributes.try_emplace("href", StylesheetPath);
 Out.emplace_back(std::move(LinkNode));
   }


Index: clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
+++ clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
@@ -110,34 +110,23 @@
   ClangDocContext CDCtx = getClangDocContext();
   auto Err = G->generateDocForInfo(, Actual, CDCtx);
   assert(!Err);
-  SmallString<16> PathToF;
-  llvm::sys::path::native("../../../path/to/F.html", PathToF);
-  SmallString<16> PathToInt;
-  llvm::sys::path::native("../int.html", PathToInt);
-  SmallString<16> PathToSylesheet;
-  llvm::sys::path::native("../../../clang-doc-default-stylesheet.css",
-  PathToSylesheet);
   std::string Expected = R"raw(
 
 class r
-
+
 
   class r
   Defined at line 10 of test.cpp
   
 Inherits from 
-F
+F
 , G
   
   Members
   
 
   private 
-  int
+  int
X
 
   
Index: clang-tools-extra/clang-doc/HTMLGenerator.cpp
===
--- clang-tools-extra/clang-doc/HTMLGenerator.cpp
+++ clang-tools-extra/clang-doc/HTMLGenerator.cpp
@@ -231,6 +231,7 @@
 SmallString<128> StylesheetPath = computeRelativePath("", InfoPath);
 llvm::sys::path::append(StylesheetPath,
 llvm::sys::path::filename(FilePath));
+llvm::sys::path::native(StylesheetPath, llvm::sys::path::Style::posix);
 LinkNode->Attributes.try_emplace("href", StylesheetPath);
 Out.emplace_back(std::move(LinkNode));
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D65308: [NFC][clang] Refactor getCompilationPhases()+Types.def step 3.

2019-07-25 Thread Saleem Abdulrasool via Phabricator via cfe-commits
compnerd added inline comments.



Comment at: clang/lib/Driver/Types.cpp:113
+   Id == TY_HIP_FATBIN);
+// clang-format on
 }

I think this is better written as:

```
static const clang::driver::types::ID kStaticLangageTypes[] = {
  TY_CUDA_DEVICE, TY_HIP_DEVICE, ...
};
return !llvm::contains(kStaticLangageTypes, Id);
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D65308



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


[PATCH] D65308: [NFC][clang] Refactor getCompilationPhases()+Types.def step 3.

2019-07-25 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi created this revision.
plotfi added reviewers: compnerd, aaron.ballman.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

New improved 'u'-less clang.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D65308

Files:
  clang/include/clang/Driver/Types.def
  clang/include/clang/Driver/Types.h
  clang/lib/Driver/Types.cpp

Index: clang/lib/Driver/Types.cpp
===
--- clang/lib/Driver/Types.cpp
+++ clang/lib/Driver/Types.cpp
@@ -18,15 +18,14 @@
 
 struct TypeInfo {
   const char *Name;
-  const char *Flags;
   const char *TempSuffix;
   ID PreprocessedType;
   const llvm::SmallVector Phases;
 };
 
 static const TypeInfo TypeInfos[] = {
-#define TYPE(NAME, ID, PP_TYPE, TEMP_SUFFIX, FLAGS, ...) \
-  { NAME, FLAGS, TEMP_SUFFIX, TY_##PP_TYPE, { __VA_ARGS__ }, },
+#define TYPE(NAME, ID, PP_TYPE, TEMP_SUFFIX, ...) \
+  { NAME, TEMP_SUFFIX, TY_##PP_TYPE, { __VA_ARGS__ }, },
 #include "clang/Driver/Types.def"
 #undef TYPE
 };
@@ -90,7 +89,28 @@
 }
 
 bool types::canTypeBeUserSpecified(ID Id) {
-  return strchr(getInfo(Id).Flags, 'u');
+// clang-format off
+  return !(Id == TY_CUDA_DEVICE ||
+   Id == TY_HIP_DEVICE ||
+   Id == TY_PP_CHeader ||
+   Id == TY_PP_ObjCHeader ||
+   Id == TY_PP_CXXHeader ||
+   Id == TY_ObjCXXHeader ||
+   Id == TY_PP_CXXModule ||
+   Id == TY_LTO_IR ||
+   Id == TY_LTO_BC ||
+   Id == TY_Plist ||
+   Id == TY_RewrittenObjC ||
+   Id == TY_RewrittenLegacyObjC ||
+   Id == TY_Remap ||
+   Id == TY_PCH ||
+   Id == TY_Object ||
+   Id == TY_Image ||
+   Id == TY_dSYM ||
+   Id == TY_Dependencies ||
+   Id == TY_CUDA_FATBIN ||
+   Id == TY_HIP_FATBIN);
+// clang-format on
 }
 
 bool types::appendSuffixForType(ID Id) {
Index: clang/include/clang/Driver/Types.h
===
--- clang/include/clang/Driver/Types.h
+++ clang/include/clang/Driver/Types.h
@@ -20,7 +20,7 @@
 namespace types {
   enum ID {
 TY_INVALID,
-#define TYPE(NAME, ID, PP_TYPE, TEMP_SUFFIX, FLAGS, ...) TY_##ID,
+#define TYPE(NAME, ID, PP_TYPE, TEMP_SUFFIX, ...) TY_##ID,
 #include "clang/Driver/Types.def"
 #undef TYPE
 TY_LAST
Index: clang/include/clang/Driver/Types.def
===
--- clang/include/clang/Driver/Types.def
+++ clang/include/clang/Driver/Types.def
@@ -29,76 +29,73 @@
 // The fourth value is the suffix to use when creating temporary files
 // of this type, or null if unspecified.
 
-// The fifth value is a string containing option flags. Valid values:
-//  u - The type can be user specified (with -x).
-
-// The sixth value is a variadic list of phases for each type. Eventually the
+// The final value is a variadic list of phases for each type. Eventually the
 // options flag string will be replaced with this variadic list.
 // Most of the options in Flags have been removed in favor of subsuming their
 // meaning from the phases list.
 
 // C family source language (with and without preprocessing).
-TYPE("cpp-output",   PP_C, INVALID, "i", "u", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
-TYPE("c",C,PP_C,"c", "u", phases::Preprocess, phases::Compile, phases::Backend, phases::Assemble, phases::Link)
-TYPE("cl",   CL,   PP_C,"cl","u", phases::Preprocess, phases::Compile, phases::Backend, phases::Assemble, phases::Link)
-TYPE("cuda-cpp-output",  PP_CUDA,  INVALID, "cui",   "u", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
-TYPE("cuda", CUDA, PP_CUDA, "cu","u", phases::Preprocess, phases::Compile, phases::Backend, phases::Assemble, phases::Link)
-TYPE("cuda", CUDA_DEVICE,  PP_CUDA, "cu","" , phases::Preprocess, phases::Compile, phases::Backend, phases::Assemble, phases::Link)
-TYPE("hip-cpp-output",   PP_HIP,   INVALID, "cui",   "u", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
-TYPE("hip",  HIP,  PP_HIP,  "cu","u", phases::Preprocess, phases::Compile, phases::Backend, phases::Assemble, phases::Link)
-TYPE("hip",  HIP_DEVICE,   PP_HIP,  "cu","" , phases::Preprocess, phases::Compile, phases::Backend, phases::Assemble, phases::Link)
-TYPE("objective-c-cpp-output",   PP_ObjC,  INVALID, "mi","u", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
-TYPE("objc-cpp-output",  PP_ObjC_Alias, INVALID,"mi","u", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
-TYPE("objective-c",  ObjC, PP_ObjC, 

[PATCH] D65306: [clang-doc] Fix failing tests on Windows

2019-07-25 Thread Diego Astiazarán via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL367074: [clang-doc] Fix failing tests on Windows (authored 
by DiegoAstiazaran, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D65306?vs=211848=211854#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D65306

Files:
  clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp


Index: clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp
===
--- clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp
+++ clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp
@@ -114,10 +114,15 @@
   llvm::sys::path::native("../../../path/to/F.html", PathToF);
   SmallString<16> PathToInt;
   llvm::sys::path::native("../int.html", PathToInt);
+  SmallString<16> PathToSylesheet;
+  llvm::sys::path::native("../../../clang-doc-default-stylesheet.css",
+  PathToSylesheet);
   std::string Expected = R"raw(
 
 class r
-
+
 
   class r
   Defined at line 10 of test.cpp


Index: clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp
===
--- clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp
+++ clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp
@@ -114,10 +114,15 @@
   llvm::sys::path::native("../../../path/to/F.html", PathToF);
   SmallString<16> PathToInt;
   llvm::sys::path::native("../int.html", PathToInt);
+  SmallString<16> PathToSylesheet;
+  llvm::sys::path::native("../../../clang-doc-default-stylesheet.css",
+  PathToSylesheet);
   std::string Expected = R"raw(
 
 class r
-
+
 
   class r
   Defined at line 10 of test.cpp
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r367074 - [clang-doc] Fix failing tests on Windows

2019-07-25 Thread Diego Astiazaran via cfe-commits
Author: diegoastiazaran
Date: Thu Jul 25 16:22:55 2019
New Revision: 367074

URL: http://llvm.org/viewvc/llvm-project?rev=367074=rev
Log:
[clang-doc] Fix failing tests on Windows

Tests on Windows were failing due to path separator differences.
'/' was being used as separator in the expected output, paths in expected 
output are now changed to their native form before comparing them to the actual 
output.

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

Modified:
clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp

Modified: clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp?rev=367074=367073=367074=diff
==
--- clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp (original)
+++ clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp Thu Jul 
25 16:22:55 2019
@@ -114,10 +114,15 @@ TEST(HTMLGeneratorTest, emitRecordHTML)
   llvm::sys::path::native("../../../path/to/F.html", PathToF);
   SmallString<16> PathToInt;
   llvm::sys::path::native("../int.html", PathToInt);
+  SmallString<16> PathToSylesheet;
+  llvm::sys::path::native("../../../clang-doc-default-stylesheet.css",
+  PathToSylesheet);
   std::string Expected = R"raw(
 
 class r
-
+
 
   class r
   Defined at line 10 of test.cpp


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


[PATCH] D63276: [AST] Add FunctionDecl::getParametersSourceRange()

2019-07-25 Thread Nicolas Manichon via Phabricator via cfe-commits
nicolas updated this revision to Diff 211849.
nicolas edited the summary of this revision.
nicolas added a comment.

I added the SourceLocation of the ellipsis to `FunctionProtoType` in addition 
to the `Variadic` boolean.


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

https://reviews.llvm.org/D63276

Files:
  clang/include/clang/AST/Decl.h
  clang/include/clang/AST/Type.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/Decl.cpp
  clang/lib/AST/Type.cpp
  clang/lib/Sema/SemaType.cpp
  clang/unittests/AST/SourceLocationTest.cpp

Index: clang/unittests/AST/SourceLocationTest.cpp
===
--- clang/unittests/AST/SourceLocationTest.cpp
+++ clang/unittests/AST/SourceLocationTest.cpp
@@ -648,6 +648,112 @@
   Language::Lang_CXX11));
 }
 
+class FunctionDeclParametersRangeVerifier : public RangeVerifier {
+protected:
+  SourceRange getRange(const FunctionDecl ) override {
+return Function.getParametersSourceRange();
+  }
+};
+
+TEST(FunctionDeclParameters, FunctionDeclOnlyVariadic) {
+  FunctionDeclParametersRangeVerifier Verifier;
+  Verifier.expectRange(1, 8, 1, 10);
+  EXPECT_TRUE(Verifier.match("void f(...);\n", functionDecl()));
+}
+
+TEST(FunctionDeclParameters, FunctionDeclVariadic) {
+  FunctionDeclParametersRangeVerifier Verifier;
+  Verifier.expectRange(1, 8, 1, 17);
+  EXPECT_TRUE(Verifier.match("void f(int a, ...);\n", functionDecl()));
+}
+
+TEST(FunctionDeclParameters, FunctionDeclMacroVariadic) {
+  FunctionDeclParametersRangeVerifier Verifier;
+  Verifier.expectRange(2, 8, 1, 18);
+  EXPECT_TRUE(Verifier.match("#define VARIADIC ...\n"
+ "void f(int a, VARIADIC);\n",
+ functionDecl()));
+}
+
+TEST(FunctionDeclParameters, FunctionDeclMacroParams) {
+  FunctionDeclParametersRangeVerifier Verifier;
+  Verifier.expectRange(1, 16, 2, 20);
+  EXPECT_TRUE(Verifier.match("#define PARAMS int a, int b\n"
+ "void f(PARAMS, int c);",
+ functionDecl()));
+}
+
+TEST(FunctionDeclParameters, FunctionDeclSingleParameter) {
+  FunctionDeclParametersRangeVerifier Verifier;
+  Verifier.expectRange(1, 8, 1, 12);
+  EXPECT_TRUE(Verifier.match("void f(int a);\n", functionDecl()));
+}
+
+TEST(FunctionDeclParameters, MemberFunctionDecl) {
+  FunctionDeclParametersRangeVerifier Verifier;
+  Verifier.expectRange(2, 8, 2, 12);
+  EXPECT_TRUE(Verifier.match("class A{\n"
+ "void f(int a);\n"
+ "};",
+ functionDecl()));
+}
+
+TEST(FunctionDeclParameters, MemberFunctionDeclVariadic) {
+  FunctionDeclParametersRangeVerifier Verifier;
+  Verifier.expectRange(2, 8, 2, 17);
+  EXPECT_TRUE(Verifier.match("class A{\n"
+ "void f(int a, ...);\n"
+ "};",
+ functionDecl()));
+}
+
+TEST(FunctionDeclParameters, StaticFunctionDecl) {
+  FunctionDeclParametersRangeVerifier Verifier;
+  Verifier.expectRange(2, 15, 2, 19);
+  EXPECT_TRUE(Verifier.match("class A{\n"
+ "static void f(int a);\n"
+ "};",
+ functionDecl()));
+}
+
+TEST(FunctionDeclParameters, FunctionDeclMultipleParameters) {
+  FunctionDeclParametersRangeVerifier Verifier;
+  Verifier.expectRange(1, 8, 1, 28);
+  EXPECT_TRUE(
+  Verifier.match("void f(int a, int b, char *c);\n", functionDecl()));
+}
+
+TEST(FunctionDeclParameters, FunctionDeclWithDefaultValue) {
+  FunctionDeclParametersRangeVerifier Verifier;
+  Verifier.expectRange(1, 8, 1, 16);
+  EXPECT_TRUE(Verifier.match("void f(int a = 5);\n", functionDecl()));
+}
+
+TEST(FunctionDeclParameters, FunctionDeclWithVolatile) {
+  FunctionDeclParametersRangeVerifier Verifier;
+  Verifier.expectRange(1, 8, 1, 22);
+  EXPECT_TRUE(Verifier.match("void f(volatile int *i);", functionDecl()));
+}
+
+TEST(FunctionDeclParameters, FunctionDeclWithConstParam) {
+  FunctionDeclParametersRangeVerifier Verifier;
+  Verifier.expectRange(1, 8, 1, 19);
+  EXPECT_TRUE(Verifier.match("void f(const int *i);", functionDecl()));
+}
+
+TEST(FunctionDeclParameters, FunctionDeclWithConstVolatileParam) {
+  FunctionDeclParametersRangeVerifier Verifier;
+  Verifier.expectRange(1, 8, 1, 28);
+  EXPECT_TRUE(Verifier.match("void f(const volatile int *i);", functionDecl()));
+}
+
+TEST(FunctionDeclParameters, FunctionDeclWithParamAttribute) {
+  FunctionDeclParametersRangeVerifier Verifier;
+  Verifier.expectRange(1, 8, 1, 36);
+  EXPECT_TRUE(Verifier.match("void f(__attribute__((unused)) int a) {}",
+ functionDecl()));
+}
+
 TEST(CXXMethodDecl, CXXMethodDeclWithThrowSpecification) {
   RangeVerifier Verifier;
   Verifier.expectRange(2, 1, 2, 16);
Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ 

[PATCH] D65300: [clang] [CodeGen] clang-misexpect prototype for compiler warnings

2019-07-25 Thread Paul Kirth via Phabricator via cfe-commits
paulkirth updated this revision to Diff 211853.
paulkirth added a comment.

Add missing test for switch statements when the expected value is not a compile 
time constant.

Make sure that when the expected value cannot be evaluated, we do not issue any 
warnings or errors


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D65300

Files:
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/CGStmt.cpp
  clang/lib/CodeGen/CMakeLists.txt
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/CodeGen/MisExpect.cpp
  clang/lib/CodeGen/MisExpect.h
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/Profile/Inputs/misexpect-branch-nonconst-expect-arg.proftext
  clang/test/Profile/Inputs/misexpect-branch.proftext
  clang/test/Profile/Inputs/misexpect-switch.proftext
  clang/test/Profile/misexpect-branch-cold.c
  clang/test/Profile/misexpect-branch-nonconst-expected-val.c
  clang/test/Profile/misexpect-branch.c
  clang/test/Profile/misexpect-no-warning-without-flag.c
  clang/test/Profile/misexpect-switch-default.c
  clang/test/Profile/misexpect-switch-nonconst.c
  clang/test/Profile/misexpect-switch.c

Index: clang/test/Profile/misexpect-switch.c
===
--- /dev/null
+++ clang/test/Profile/misexpect-switch.c
@@ -0,0 +1,68 @@
+// Test that misexpect detects mis-annotated switch statements
+
+// RUN: llvm-profdata merge %S/Inputs/misexpect-switch.proftext -o %t.profdata
+// RUN: %clang_cc1 %s -O2 -o - -disable-llvm-passes -emit-llvm -fprofile-instrument-use-path=%t.profdata -verify -fmisexpect
+
+int sum(int *buff, int size);
+int random_sample(int *buff, int size);
+int rand();
+
+const int inner_loop = 1000;
+const int outer_loop = 20;
+const int arry_size = 25;
+
+int arry[arry_size] = {0};
+
+void init_arry() {
+  int i;
+  for (i = 0; i < arry_size; ++i) {
+arry[i] = rand() % 10;
+  }
+}
+
+int main() {
+  init_arry();
+  int val = 0;
+
+  int j, k;
+  for (j = 0; j < outer_loop; ++j) {
+for (k = 0; k < inner_loop; ++k) {
+  unsigned condition = rand() % 1;
+  switch (__builtin_expect(condition, 0)) { //expected-warning {{Current PGO counters disagree with the use of __builtin_expect().}}
+  case 0:
+val += sum(arry, arry_size);
+break;
+  case 1:
+  case 2:
+  case 3:
+  case 4:
+val += random_sample(arry, arry_size);
+break;
+  default:
+__builtin_unreachable();
+  } // end switch
+}   // end inner_loop
+  } // end outer_loop
+
+  return 0;
+}
+
+int sum(int *buff, int size) {
+  int total = 0;
+  int i = 0;
+  for (i = 0; i < size; ++i) {
+total += buff[i];
+  }
+  return total;
+}
+
+int random_sample(int *buff, int size) {
+  int total = 0;
+  int i;
+  for (i = 0; i < size; ++i) {
+if (rand() % 5 == 0)
+  total += buff[i];
+  }
+
+  return total;
+}
Index: clang/test/Profile/misexpect-switch-nonconst.c
===
--- /dev/null
+++ clang/test/Profile/misexpect-switch-nonconst.c
@@ -0,0 +1,69 @@
+// Test that misexpect detects mis-annotated switch statements
+
+// RUN: llvm-profdata merge %S/Inputs/misexpect-switch.proftext -o %t.profdata
+// RUN: %clang_cc1 %s -O2 -o - -disable-llvm-passes -emit-llvm -fprofile-instrument-use-path=%t.profdata -verify -fmisexpect
+
+// expected-no-diagnostics
+int sum(int *buff, int size);
+int random_sample(int *buff, int size);
+int rand();
+
+const int inner_loop = 1000;
+const int outer_loop = 20;
+const int arry_size = 25;
+
+int arry[arry_size] = {0};
+
+void init_arry() {
+  int i;
+  for (i = 0; i < arry_size; ++i) {
+arry[i] = rand() % 10;
+  }
+}
+
+int main() {
+  init_arry();
+  int val = 0;
+
+  int j, k;
+  for (j = 0; j < outer_loop; ++j) {
+for (k = 0; k < inner_loop; ++k) {
+  unsigned condition = rand() % 1;
+  switch (__builtin_expect(condition, rand())) {
+  case 0:
+val += sum(arry, arry_size);
+break;
+  case 1:
+  case 2:
+  case 3:
+  case 4:
+val += random_sample(arry, arry_size);
+break;
+  default:
+__builtin_unreachable();
+  } // end switch
+}   // end inner_loop
+  } // end outer_loop
+
+  return 0;
+}
+
+int sum(int *buff, int size) {
+  int total = 0;
+  int i = 0;
+  for (i = 0; i < size; ++i) {
+total += buff[i];
+  }
+  return total;
+}
+
+int random_sample(int *buff, int size) {
+  int total = 0;
+  int i;
+  for (i = 0; i < size; ++i) {
+if (rand() % 5 == 0)
+  total += buff[i];
+  }
+
+  return total;
+}
Index: clang/test/Profile/misexpect-switch-default.c
===
--- /dev/null
+++ clang/test/Profile/misexpect-switch-default.c
@@ -0,0 +1,68 

[PATCH] D65306: [clang-doc] Fix failing tests on Windows

2019-07-25 Thread Diego Astiazarán via Phabricator via cfe-commits
DiegoAstiazaran created this revision.
DiegoAstiazaran added a reviewer: juliehockett.
DiegoAstiazaran added a project: clang-tools-extra.
juliehockett accepted this revision.
juliehockett added a comment.
This revision is now accepted and ready to land.

Make sure you update the other stylesheet patch, as well, before landing that.


Tests on Windows were failing due to path separator differences.
 '/' was being used as separator in the expected output, paths in expected 
output are now changed to their native form before comparing them to the actual 
output.


https://reviews.llvm.org/D65306

Files:
  clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp


Index: clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
+++ clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
@@ -114,10 +114,15 @@
   llvm::sys::path::native("../../../path/to/F.html", PathToF);
   SmallString<16> PathToInt;
   llvm::sys::path::native("../int.html", PathToInt);
+  SmallString<16> PathToSylesheet;
+  llvm::sys::path::native("../../../clang-doc-default-stylesheet.css",
+  PathToSylesheet);
   std::string Expected = R"raw(
 
 class r
-
+
 
   class r
   Defined at line 10 of test.cpp


Index: clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
+++ clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
@@ -114,10 +114,15 @@
   llvm::sys::path::native("../../../path/to/F.html", PathToF);
   SmallString<16> PathToInt;
   llvm::sys::path::native("../int.html", PathToInt);
+  SmallString<16> PathToSylesheet;
+  llvm::sys::path::native("../../../clang-doc-default-stylesheet.css",
+  PathToSylesheet);
   std::string Expected = R"raw(
 
 class r
-
+
 
   class r
   Defined at line 10 of test.cpp
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D65306: [clang-doc] Fix failing tests on Windows

2019-07-25 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett accepted this revision.
juliehockett added a comment.
This revision is now accepted and ready to land.

Make sure you update the other stylesheet patch, as well, before landing that.


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

https://reviews.llvm.org/D65306



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


[PATCH] D64938: [clang-doc] Add option for user provided stylesheets

2019-07-25 Thread Diego Astiazarán via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL367072: [clang-doc] Add option for user provided stylesheets 
(authored by DiegoAstiazaran, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D64938?vs=211841=211846#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D64938

Files:
  clang-tools-extra/trunk/clang-doc/Generators.h
  clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp
  clang-tools-extra/trunk/clang-doc/MDGenerator.cpp
  clang-tools-extra/trunk/clang-doc/Representation.h
  clang-tools-extra/trunk/clang-doc/YAMLGenerator.cpp
  clang-tools-extra/trunk/clang-doc/tool/ClangDocMain.cpp
  clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp
  clang-tools-extra/trunk/unittests/clang-doc/MDGeneratorTest.cpp
  clang-tools-extra/trunk/unittests/clang-doc/YAMLGeneratorTest.cpp

Index: clang-tools-extra/trunk/unittests/clang-doc/MDGeneratorTest.cpp
===
--- clang-tools-extra/trunk/unittests/clang-doc/MDGeneratorTest.cpp
+++ clang-tools-extra/trunk/unittests/clang-doc/MDGeneratorTest.cpp
@@ -38,7 +38,7 @@
   assert(G);
   std::string Buffer;
   llvm::raw_string_ostream Actual(Buffer);
-  auto Err = G->generateDocForInfo(, Actual);
+  auto Err = G->generateDocForInfo(, Actual, ClangDocContext());
   assert(!Err);
   std::string Expected = R"raw(# namespace Namespace
 
@@ -101,7 +101,7 @@
   assert(G);
   std::string Buffer;
   llvm::raw_string_ostream Actual(Buffer);
-  auto Err = G->generateDocForInfo(, Actual);
+  auto Err = G->generateDocForInfo(, Actual, ClangDocContext());
   assert(!Err);
   std::string Expected = R"raw(# class r
 
@@ -162,7 +162,7 @@
   assert(G);
   std::string Buffer;
   llvm::raw_string_ostream Actual(Buffer);
-  auto Err = G->generateDocForInfo(, Actual);
+  auto Err = G->generateDocForInfo(, Actual, ClangDocContext());
   assert(!Err);
   std::string Expected = R"raw(### f
 
@@ -190,7 +190,7 @@
   assert(G);
   std::string Buffer;
   llvm::raw_string_ostream Actual(Buffer);
-  auto Err = G->generateDocForInfo(, Actual);
+  auto Err = G->generateDocForInfo(, Actual, ClangDocContext());
   assert(!Err);
   std::string Expected = R"raw(| enum class e |
 
@@ -320,7 +320,7 @@
   assert(G);
   std::string Buffer;
   llvm::raw_string_ostream Actual(Buffer);
-  auto Err = G->generateDocForInfo(, Actual);
+  auto Err = G->generateDocForInfo(, Actual, ClangDocContext());
   assert(!Err);
   std::string Expected =
   R"raw(### f
Index: clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp
===
--- clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp
+++ clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp
@@ -21,6 +21,16 @@
   return std::move(G.get());
 }
 
+ClangDocContext
+getClangDocContext(std::vector UserStylesheets = {}) {
+  ClangDocContext CDCtx;
+  CDCtx.UserStylesheets = {UserStylesheets.begin(), UserStylesheets.end()};
+  CDCtx.UserStylesheets.insert(
+  CDCtx.UserStylesheets.begin(),
+  "../share/clang/clang-doc-default-stylesheet.css");
+  return CDCtx;
+}
+
 TEST(HTMLGeneratorTest, emitNamespaceHTML) {
   NamespaceInfo I;
   I.Name = "Namespace";
@@ -38,12 +48,14 @@
   assert(G);
   std::string Buffer;
   llvm::raw_string_ostream Actual(Buffer);
-  auto Err = G->generateDocForInfo(, Actual);
+  ClangDocContext CDCtx = getClangDocContext({"user-provided-stylesheet.css"});
+  auto Err = G->generateDocForInfo(, Actual, CDCtx);
   assert(!Err);
   std::string Expected = R"raw(
 
 namespace Namespace
 
+
 
   namespace Namespace
   Namespaces
@@ -95,7 +107,8 @@
   assert(G);
   std::string Buffer;
   llvm::raw_string_ostream Actual(Buffer);
-  auto Err = G->generateDocForInfo(, Actual);
+  ClangDocContext CDCtx = getClangDocContext();
+  auto Err = G->generateDocForInfo(, Actual, CDCtx);
   assert(!Err);
   SmallString<16> PathToF;
   llvm::sys::path::native("../../../path/to/F.html", PathToF);
@@ -161,7 +174,8 @@
   assert(G);
   std::string Buffer;
   llvm::raw_string_ostream Actual(Buffer);
-  auto Err = G->generateDocForInfo(, Actual);
+  ClangDocContext CDCtx = getClangDocContext();
+  auto Err = G->generateDocForInfo(, Actual, CDCtx);
   assert(!Err);
   SmallString<16> PathToFloat;
   llvm::sys::path::native("path/to/float.html", PathToFloat);
@@ -203,7 +217,8 @@
   assert(G);
   std::string Buffer;
   llvm::raw_string_ostream Actual(Buffer);
-  auto Err = G->generateDocForInfo(, Actual);
+  ClangDocContext CDCtx = getClangDocContext();
+  auto Err = G->generateDocForInfo(, Actual, CDCtx);
   assert(!Err);
   std::string Expected = R"raw(
 
@@ -271,7 +286,8 @@
   assert(G);
   std::string Buffer;
   llvm::raw_string_ostream Actual(Buffer);
-  auto Err = G->generateDocForInfo(, Actual);
+  

[PATCH] D65300: [clang] [CodeGen] clang-misexpect prototype for compiler warnings

2019-07-25 Thread Paul Kirth via Phabricator via cfe-commits
paulkirth added a comment.

In D65300#1601733 , @xbolva00 wrote:

> Nice work!


Glad to hear you like it.

> It would be nice if we also have “-fsuggest-expect” so we could fix perf 
> issues thanks to PGO counters even for non-PGO builds. What do you think?

Supporting suggestions is something we're planning to do in the future. Non-PGO 
builds are even the main motivation. I wanted to get this logic correct first, 
and make sure that we're handling all the odd edge cases before making new 
suggestions. I feel like our approach is really straightforward, but some 
things in clang are spread out in surprising ways or have interactions I've 
been surprised to find. That said, if finding problematic usage is done 
correctly, then reversing the logic to make a suggestions about useful 
annotations should be pretty easy.

I still need to give some thought to how to express the right balance between 
execution count and frequency when suggesting new annotations, so that the user 
won't be overwhelmed with suggestions. I'm not sure that branch weights by 
themselves are sufficient for that use-case, but we should be able to come up 
with something that behaves reasonably well without too much trouble.


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

https://reviews.llvm.org/D65300



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


[clang-tools-extra] r367072 - [clang-doc] Add option for user provided stylesheets

2019-07-25 Thread Diego Astiazaran via cfe-commits
Author: diegoastiazaran
Date: Thu Jul 25 15:46:40 2019
New Revision: 367072

URL: http://llvm.org/viewvc/llvm-project?rev=367072=rev
Log:
[clang-doc] Add option for user provided stylesheets

An option has been added to clang-doc to provide a list of css stylesheets that 
the user wants to use for the generated html docs.

Depends on D64539.

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

Modified:
clang-tools-extra/trunk/clang-doc/Generators.h
clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp
clang-tools-extra/trunk/clang-doc/MDGenerator.cpp
clang-tools-extra/trunk/clang-doc/Representation.h
clang-tools-extra/trunk/clang-doc/YAMLGenerator.cpp
clang-tools-extra/trunk/clang-doc/tool/ClangDocMain.cpp
clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp
clang-tools-extra/trunk/unittests/clang-doc/MDGeneratorTest.cpp
clang-tools-extra/trunk/unittests/clang-doc/YAMLGeneratorTest.cpp

Modified: clang-tools-extra/trunk/clang-doc/Generators.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-doc/Generators.h?rev=367072=367071=367072=diff
==
--- clang-tools-extra/trunk/clang-doc/Generators.h (original)
+++ clang-tools-extra/trunk/clang-doc/Generators.h Thu Jul 25 15:46:40 2019
@@ -26,7 +26,8 @@ public:
   virtual ~Generator() = default;
 
   // Write out the decl info in the specified format.
-  virtual llvm::Error generateDocForInfo(Info *I, llvm::raw_ostream ) = 0;
+  virtual llvm::Error generateDocForInfo(Info *I, llvm::raw_ostream ,
+ const ClangDocContext ) = 0;
   virtual bool createResources(ClangDocContext CDCtx) = 0;
 };
 

Modified: clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp?rev=367072=367071=367072=diff
==
--- clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp (original)
+++ clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp Thu Jul 25 15:46:40 2019
@@ -222,6 +222,21 @@ static SmallString<128> computeRelativeP
 
 // HTML generation
 
+std::vector>
+genStylesheetsHTML(StringRef InfoPath, const ClangDocContext ) {
+  std::vector> Out;
+  for (const auto  : CDCtx.UserStylesheets) {
+auto LinkNode = llvm::make_unique(HTMLTag::TAG_LINK);
+LinkNode->Attributes.try_emplace("rel", "stylesheet");
+SmallString<128> StylesheetPath = computeRelativePath("", InfoPath);
+llvm::sys::path::append(StylesheetPath,
+llvm::sys::path::filename(FilePath));
+LinkNode->Attributes.try_emplace("href", StylesheetPath);
+Out.emplace_back(std::move(LinkNode));
+  }
+  return Out;
+}
+
 static std::unique_ptr genLink(const Twine , const Twine ) {
   auto LinkNode = llvm::make_unique(HTMLTag::TAG_A, Text);
   LinkNode->Attributes.try_emplace("href", Link.str());
@@ -529,13 +544,15 @@ class HTMLGenerator : public Generator {
 public:
   static const char *Format;
 
-  llvm::Error generateDocForInfo(Info *I, llvm::raw_ostream ) override;
+  llvm::Error generateDocForInfo(Info *I, llvm::raw_ostream ,
+ const ClangDocContext ) override;
   bool createResources(ClangDocContext CDCtx) override;
 };
 
 const char *HTMLGenerator::Format = "html";
 
-llvm::Error HTMLGenerator::generateDocForInfo(Info *I, llvm::raw_ostream ) {
+llvm::Error HTMLGenerator::generateDocForInfo(Info *I, llvm::raw_ostream ,
+  const ClangDocContext ) {
   HTMLFile F;
 
   auto MetaNode = llvm::make_unique(HTMLTag::TAG_META);
@@ -577,12 +594,9 @@ llvm::Error HTMLGenerator::generateDocFo
 
   F.Children.emplace_back(
   llvm::make_unique(HTMLTag::TAG_TITLE, InfoTitle));
-  auto LinkNode = llvm::make_unique(HTMLTag::TAG_LINK);
-  LinkNode->Attributes.try_emplace("rel", "stylesheet");
-  SmallString<128> StylesheetPath = computeRelativePath("", I->Path);
-  llvm::sys::path::append(StylesheetPath, "clang-doc-default-stylesheet.css");
-  LinkNode->Attributes.try_emplace("href", StylesheetPath);
-  F.Children.emplace_back(std::move(LinkNode));
+  std::vector> StylesheetsNodes =
+  genStylesheetsHTML(I->Path, CDCtx);
+  AppendVector(std::move(StylesheetsNodes), F.Children);
   F.Children.emplace_back(std::move(MainContentNode));
   F.Render(OS);
 
@@ -591,22 +605,22 @@ llvm::Error HTMLGenerator::generateDocFo
 
 bool HTMLGenerator::createResources(ClangDocContext CDCtx) {
   llvm::outs() << "Generating stylesheet for docs...\n";
-  llvm::SmallString<128> StylesheetPathWrite;
-  llvm::sys::path::native(CDCtx.OutDirectory, StylesheetPathWrite);
-  llvm::sys::path::append(StylesheetPathWrite,
-  "clang-doc-default-stylesheet.css");
-  llvm::SmallString<128> StylesheetPathRead;
-  llvm::sys::path::native(CDCtx.ClangDocPath, StylesheetPathRead);
-  

[PATCH] D64938: [clang-doc] Add option for user provided stylesheets

2019-07-25 Thread Diego Astiazarán via Phabricator via cfe-commits
DiegoAstiazaran updated this revision to Diff 211841.

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

https://reviews.llvm.org/D64938

Files:
  clang-tools-extra/clang-doc/Generators.h
  clang-tools-extra/clang-doc/HTMLGenerator.cpp
  clang-tools-extra/clang-doc/MDGenerator.cpp
  clang-tools-extra/clang-doc/Representation.h
  clang-tools-extra/clang-doc/YAMLGenerator.cpp
  clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
  clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
  clang-tools-extra/unittests/clang-doc/MDGeneratorTest.cpp
  clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp

Index: clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp
+++ clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp
@@ -40,7 +40,7 @@
   assert(G);
   std::string Buffer;
   llvm::raw_string_ostream Actual(Buffer);
-  auto Err = G->generateDocForInfo(, Actual);
+  auto Err = G->generateDocForInfo(, Actual, ClangDocContext());
   assert(!Err);
   std::string Expected =
   R"raw(---
@@ -94,7 +94,7 @@
   assert(G);
   std::string Buffer;
   llvm::raw_string_ostream Actual(Buffer);
-  auto Err = G->generateDocForInfo(, Actual);
+  auto Err = G->generateDocForInfo(, Actual, ClangDocContext());
   assert(!Err);
   std::string Expected =
   R"raw(---
@@ -158,7 +158,7 @@
   assert(G);
   std::string Buffer;
   llvm::raw_string_ostream Actual(Buffer);
-  auto Err = G->generateDocForInfo(, Actual);
+  auto Err = G->generateDocForInfo(, Actual, ClangDocContext());
   assert(!Err);
   std::string Expected =
   R"raw(---
@@ -206,7 +206,7 @@
   assert(G);
   std::string Buffer;
   llvm::raw_string_ostream Actual(Buffer);
-  auto Err = G->generateDocForInfo(, Actual);
+  auto Err = G->generateDocForInfo(, Actual, ClangDocContext());
   assert(!Err);
   std::string Expected =
   R"raw(---
@@ -343,7 +343,7 @@
   assert(G);
   std::string Buffer;
   llvm::raw_string_ostream Actual(Buffer);
-  auto Err = G->generateDocForInfo(, Actual);
+  auto Err = G->generateDocForInfo(, Actual, ClangDocContext());
   assert(!Err);
   std::string Expected =
   R"raw(---
Index: clang-tools-extra/unittests/clang-doc/MDGeneratorTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/MDGeneratorTest.cpp
+++ clang-tools-extra/unittests/clang-doc/MDGeneratorTest.cpp
@@ -38,7 +38,7 @@
   assert(G);
   std::string Buffer;
   llvm::raw_string_ostream Actual(Buffer);
-  auto Err = G->generateDocForInfo(, Actual);
+  auto Err = G->generateDocForInfo(, Actual, ClangDocContext());
   assert(!Err);
   std::string Expected = R"raw(# namespace Namespace
 
@@ -101,7 +101,7 @@
   assert(G);
   std::string Buffer;
   llvm::raw_string_ostream Actual(Buffer);
-  auto Err = G->generateDocForInfo(, Actual);
+  auto Err = G->generateDocForInfo(, Actual, ClangDocContext());
   assert(!Err);
   std::string Expected = R"raw(# class r
 
@@ -162,7 +162,7 @@
   assert(G);
   std::string Buffer;
   llvm::raw_string_ostream Actual(Buffer);
-  auto Err = G->generateDocForInfo(, Actual);
+  auto Err = G->generateDocForInfo(, Actual, ClangDocContext());
   assert(!Err);
   std::string Expected = R"raw(### f
 
@@ -190,7 +190,7 @@
   assert(G);
   std::string Buffer;
   llvm::raw_string_ostream Actual(Buffer);
-  auto Err = G->generateDocForInfo(, Actual);
+  auto Err = G->generateDocForInfo(, Actual, ClangDocContext());
   assert(!Err);
   std::string Expected = R"raw(| enum class e |
 
@@ -320,7 +320,7 @@
   assert(G);
   std::string Buffer;
   llvm::raw_string_ostream Actual(Buffer);
-  auto Err = G->generateDocForInfo(, Actual);
+  auto Err = G->generateDocForInfo(, Actual, ClangDocContext());
   assert(!Err);
   std::string Expected =
   R"raw(### f
Index: clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
+++ clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
@@ -21,6 +21,16 @@
   return std::move(G.get());
 }
 
+ClangDocContext
+getClangDocContext(std::vector UserStylesheets = {}) {
+  ClangDocContext CDCtx;
+  CDCtx.UserStylesheets = {UserStylesheets.begin(), UserStylesheets.end()};
+  CDCtx.UserStylesheets.insert(
+  CDCtx.UserStylesheets.begin(),
+  "../share/clang/clang-doc-default-stylesheet.css");
+  return CDCtx;
+}
+
 TEST(HTMLGeneratorTest, emitNamespaceHTML) {
   NamespaceInfo I;
   I.Name = "Namespace";
@@ -38,12 +48,14 @@
   assert(G);
   std::string Buffer;
   llvm::raw_string_ostream Actual(Buffer);
-  auto Err = G->generateDocForInfo(, Actual);
+  ClangDocContext CDCtx = getClangDocContext({"user-provided-stylesheet.css"});
+  auto Err = G->generateDocForInfo(, Actual, CDCtx);
   assert(!Err);
   std::string Expected = R"raw(
 
 namespace Namespace
 

[PATCH] D65302: [clang][docs][release notes] mention asm goto support

2019-07-25 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers marked an inline comment as done.
nickdesaulniers added inline comments.



Comment at: clang/docs/ReleaseNotes.rst:116
+  control flow from inline assembly. The main consumer of this construct is the
+  Linux kernel and glib. There a few long tail bugs in Clang's integrated
+  assembler and IfConverter still being fixed related to the use of

I wasn't sure the best way to state something along the lines of "support is in 
beta shape, plz report bugz?"


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D65302



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


[PATCH] D65302: [clang][docs][release notes] mention asm goto support

2019-07-25 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers created this revision.
nickdesaulniers added reviewers: hans, tstellar.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
nickdesaulniers marked an inline comment as done.
nickdesaulniers added inline comments.



Comment at: clang/docs/ReleaseNotes.rst:116
+  control flow from inline assembly. The main consumer of this construct is the
+  Linux kernel and glib. There a few long tail bugs in Clang's integrated
+  assembler and IfConverter still being fixed related to the use of

I wasn't sure the best way to state something along the lines of "support is in 
beta shape, plz report bugz?"


add simple note


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D65302

Files:
  clang/docs/ReleaseNotes.rst


Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -111,6 +111,12 @@
   in all C-family languages. This macro is similar to ``__FILE__`` except it
   will always provide the last path component when possible.
 
+- Support for ``asm goto`` statements (a GNU C extension) has been added for
+  control flow from inline assembly. The main consumer of this construct is the
+  Linux kernel and glib. There a few long tail bugs in Clang's integrated
+  assembler and IfConverter still being fixed related to the use of
+  ``asm goto``.
+
 - ...
 
 C11 Feature Support


Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -111,6 +111,12 @@
   in all C-family languages. This macro is similar to ``__FILE__`` except it
   will always provide the last path component when possible.
 
+- Support for ``asm goto`` statements (a GNU C extension) has been added for
+  control flow from inline assembly. The main consumer of this construct is the
+  Linux kernel and glib. There a few long tail bugs in Clang's integrated
+  assembler and IfConverter still being fixed related to the use of
+  ``asm goto``.
+
 - ...
 
 C11 Feature Support
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D59963: [clang-tidy] Add a module for the Linux kernel.

2019-07-25 Thread Tom Roeder via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Revision".
This revision was automatically updated to reflect the committed changes.
tmroeder marked an inline comment as done.
Closed by commit rL367071: [clang-tidy] Add a module for the Linux kernel. 
(authored by tmroeder, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D59963?vs=211836=211840#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D59963

Files:
  clang-tools-extra/trunk/clang-tidy/CMakeLists.txt
  clang-tools-extra/trunk/clang-tidy/ClangTidyForceLinker.h
  clang-tools-extra/trunk/clang-tidy/linuxkernel/CMakeLists.txt
  clang-tools-extra/trunk/clang-tidy/linuxkernel/LinuxKernelTidyModule.cpp
  clang-tools-extra/trunk/clang-tidy/linuxkernel/MustCheckErrsCheck.cpp
  clang-tools-extra/trunk/clang-tidy/linuxkernel/MustCheckErrsCheck.h
  clang-tools-extra/trunk/clang-tidy/plugin/CMakeLists.txt
  clang-tools-extra/trunk/clang-tidy/tool/CMakeLists.txt
  clang-tools-extra/trunk/docs/ReleaseNotes.rst
  clang-tools-extra/trunk/docs/clang-tidy/checks/linuxkernel-must-use-errs.rst
  clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst
  clang-tools-extra/trunk/test/clang-tidy/linuxkernel-must-check-errs.c

Index: clang-tools-extra/trunk/clang-tidy/linuxkernel/MustCheckErrsCheck.h
===
--- clang-tools-extra/trunk/clang-tidy/linuxkernel/MustCheckErrsCheck.h
+++ clang-tools-extra/trunk/clang-tidy/linuxkernel/MustCheckErrsCheck.h
@@ -0,0 +1,43 @@
+//===--- MustCheckErrsCheck.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_LINUXKERNEL_MUSTCHECKERRSCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_LINUXKERNEL_MUSTCHECKERRSCHECK_H
+
+#include "../ClangTidyCheck.h"
+
+namespace clang {
+namespace tidy {
+namespace linuxkernel {
+
+/// Checks Linux kernel code to see if it uses the results from the functions in
+/// linux/err.h. Also checks to see if code uses the results from functions that
+/// directly return a value from one of these error functions.
+///
+/// This is important in the Linux kernel because ERR_PTR, PTR_ERR, IS_ERR,
+/// IS_ERR_OR_NULL, ERR_CAST, and PTR_ERR_OR_ZERO return values must be checked,
+/// since positive pointers and negative error codes are being used in the same
+/// context. These functions are marked with
+/// __attribute__((warn_unused_result)), but some kernel versions do not have
+/// this warning enabled for clang.
+///
+/// For the user-facing documentation see:
+/// http://clang.llvm.org/extra/clang-tidy/checks/linuxkernel-must-use-errs.html
+class MustCheckErrsCheck : public ClangTidyCheck {
+public:
+  MustCheckErrsCheck(StringRef Name, ClangTidyContext *Context)
+  : ClangTidyCheck(Name, Context) {}
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+  void check(const ast_matchers::MatchFinder::MatchResult ) override;
+};
+
+} // namespace linuxkernel
+} // namespace tidy
+} // namespace clang
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_LINUXKERNEL_MUSTCHECKERRSCHECK_H
Index: clang-tools-extra/trunk/clang-tidy/linuxkernel/MustCheckErrsCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/linuxkernel/MustCheckErrsCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/linuxkernel/MustCheckErrsCheck.cpp
@@ -0,0 +1,53 @@
+//===--- MustCheckErrsCheck.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 "MustCheckErrsCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace linuxkernel {
+
+void MustCheckErrsCheck::registerMatchers(MatchFinder *Finder) {
+  auto ErrFn =
+  functionDecl(hasAnyName("ERR_PTR", "PTR_ERR", "IS_ERR", "IS_ERR_OR_NULL",
+  "ERR_CAST", "PTR_ERR_OR_ZERO"));
+  auto NonCheckingStmts = stmt(anyOf(compoundStmt(), labelStmt()));
+  Finder->addMatcher(
+  callExpr(callee(ErrFn), hasParent(NonCheckingStmts)).bind("call"),
+  this);
+
+  auto ReturnToCheck = returnStmt(hasReturnValue(callExpr(callee(ErrFn;
+  auto ReturnsErrFn = functionDecl(hasDescendant(ReturnToCheck));
+  

[PATCH] D59692: [ASTImporter] Fix name conflict handling

2019-07-25 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added a comment.

First round of review.




Comment at: clang/lib/AST/ASTImporter.cpp:2632
+  ExpectedName NameOrErr = Importer.HandleNameConflict(
+  Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size());
+  if (!NameOrErr)

`Name` -> `SearchName`



Comment at: clang/unittests/AST/ASTImporterTest.cpp:2392
 
+struct ImportFunctionTemplates : ASTImporterOptionSpecificTestBase {};
+

What about tests for name conflicts for:

`NamespaceDecl` 
`TypedefNameDecl`
`TypeAliasTemplateDecl`
`EnumConstantDecl`
`RecordDecl`
`VarDecl`

Who were also modified above.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D59692



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


[PATCH] D59963: [clang-tidy] Add a module for the Linux kernel.

2019-07-25 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added inline comments.



Comment at: clang-tools-extra/docs/ReleaseNotes.rst:77
+
+  This is important in the Linux kernel because ``ERR_PTR``, ``PTR_ERR``,
+  ``IS_ERR``, ``IS_ERR_OR_NULL``, ``ERR_CAST``, and ``PTR_ERR_OR_ZERO`` return

Release Notes should include short description. One sentence is enough, but 
it'll good idea to keep it same as first statement of documentation.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D59963



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


[PATCH] D59963: [clang-tidy] Add a module for the Linux kernel.

2019-07-25 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers requested changes to this revision.
nickdesaulniers added inline comments.
This revision now requires changes to proceed.



Comment at: clang-tools-extra/clang-tidy/linuxkernel/MustCheckErrsCheck.cpp:12
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include 
+

tmroeder wrote:
> lebedev.ri wrote:
> > This looks wrong
> Yeah, I'm not sure where that came from. I'll remove it.
Hard to tell, but I don't think this `using` statement was ever removed as 
requested?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D59963



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


[clang-tools-extra] r367071 - [clang-tidy] Add a module for the Linux kernel.

2019-07-25 Thread Tom Roeder via cfe-commits
Author: tmroeder
Date: Thu Jul 25 15:32:50 2019
New Revision: 367071

URL: http://llvm.org/viewvc/llvm-project?rev=367071=rev
Log:
[clang-tidy] Add a module for the Linux kernel.

Summary:
Now that clang is going to be able to build the Linux kernel again on
x86, and we have gen_compile_commands.py upstream for generating
compile_commands.json, clang-tidy can be used on the Linux kernel
source.

To that end, this commit adds a new clang-tidy module to be used for
checks specific to Linux kernel source. The Linux kernel follows its own
style of C, and it will be useful to separate those checks into their
own module.

This also adds an initial check that makes sure that return values from
the kernel error functions like PTR_ERR and ERR_PTR are checked. It also
makes sure that any functions that directly return values from these
functions are checked.

Subscribers: xazax.hun, gribozavr, Eugene.Zelenko, lebedev.ri, mgorny, 
jdoerfert, cfe-commits

Tags: #clang, #clang-tools-extra

Reviewers: aaron.ballman, alexfh, hokein, JonasToth

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

Added:
clang-tools-extra/trunk/clang-tidy/linuxkernel/
clang-tools-extra/trunk/clang-tidy/linuxkernel/CMakeLists.txt
clang-tools-extra/trunk/clang-tidy/linuxkernel/LinuxKernelTidyModule.cpp
clang-tools-extra/trunk/clang-tidy/linuxkernel/MustCheckErrsCheck.cpp
clang-tools-extra/trunk/clang-tidy/linuxkernel/MustCheckErrsCheck.h
clang-tools-extra/trunk/docs/clang-tidy/checks/linuxkernel-must-use-errs.rst
clang-tools-extra/trunk/test/clang-tidy/linuxkernel-must-check-errs.c
Modified:
clang-tools-extra/trunk/clang-tidy/CMakeLists.txt
clang-tools-extra/trunk/clang-tidy/ClangTidyForceLinker.h
clang-tools-extra/trunk/clang-tidy/plugin/CMakeLists.txt
clang-tools-extra/trunk/clang-tidy/tool/CMakeLists.txt
clang-tools-extra/trunk/docs/ReleaseNotes.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst

Modified: clang-tools-extra/trunk/clang-tidy/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/CMakeLists.txt?rev=367071=367070=367071=diff
==
--- clang-tools-extra/trunk/clang-tidy/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-tidy/CMakeLists.txt Thu Jul 25 15:32:50 2019
@@ -44,6 +44,7 @@ add_subdirectory(cppcoreguidelines)
 add_subdirectory(fuchsia)
 add_subdirectory(google)
 add_subdirectory(hicpp)
+add_subdirectory(linuxkernel)
 add_subdirectory(llvm)
 add_subdirectory(misc)
 add_subdirectory(modernize)

Modified: clang-tools-extra/trunk/clang-tidy/ClangTidyForceLinker.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/ClangTidyForceLinker.h?rev=367071=367070=367071=diff
==
--- clang-tools-extra/trunk/clang-tidy/ClangTidyForceLinker.h (original)
+++ clang-tools-extra/trunk/clang-tidy/ClangTidyForceLinker.h Thu Jul 25 
15:32:50 2019
@@ -35,6 +35,11 @@ extern volatile int BugproneModuleAnchor
 static int LLVM_ATTRIBUTE_UNUSED BugproneModuleAnchorDestination =
 BugproneModuleAnchorSource;
 
+// This anchor is used to force the linker to link the LinuxKernelModule.
+extern volatile int LinuxKernelModuleAnchorSource;
+static int LLVM_ATTRIBUTE_UNUSED LinuxKernelModuleAnchorDestination =
+LinuxKernelModuleAnchorSource;
+
 // This anchor is used to force the linker to link the LLVMModule.
 extern volatile int LLVMModuleAnchorSource;
 static int LLVM_ATTRIBUTE_UNUSED LLVMModuleAnchorDestination =

Added: clang-tools-extra/trunk/clang-tidy/linuxkernel/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/linuxkernel/CMakeLists.txt?rev=367071=auto
==
--- clang-tools-extra/trunk/clang-tidy/linuxkernel/CMakeLists.txt (added)
+++ clang-tools-extra/trunk/clang-tidy/linuxkernel/CMakeLists.txt Thu Jul 25 
15:32:50 2019
@@ -0,0 +1,14 @@
+set(LLVM_LINK_COMPONENTS support)
+
+add_clang_library(clangTidyLinuxKernelModule
+  LinuxKernelTidyModule.cpp
+  MustCheckErrsCheck.cpp
+
+  LINK_LIBS
+  clangAST
+  clangASTMatchers
+  clangBasic
+  clangLex
+  clangTidy
+  clangTidyUtils
+  )

Added: clang-tools-extra/trunk/clang-tidy/linuxkernel/LinuxKernelTidyModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/linuxkernel/LinuxKernelTidyModule.cpp?rev=367071=auto
==
--- clang-tools-extra/trunk/clang-tidy/linuxkernel/LinuxKernelTidyModule.cpp 
(added)
+++ clang-tools-extra/trunk/clang-tidy/linuxkernel/LinuxKernelTidyModule.cpp 
Thu Jul 25 15:32:50 2019
@@ -0,0 +1,37 @@
+//===--- LinuxKernelTidyModule.cpp - 
clang-tidy===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See 

[PATCH] D65184: [Sema] Thread Safety Analysis: Fix negative capability's LockKind representation.

2019-07-25 Thread Aaron Puchert via Phabricator via cfe-commits
aaronpuchert added a reviewer: aaron.ballman.
aaronpuchert added a comment.

What distinguishes a shared from an exclusive negative capability? Negative 
capabilities (as I understand them) express the mutex not being held at all, 
meaning neither in shared nor in exclusive mode.




Comment at: clang/lib/Analysis/ThreadSafety.cpp:2188-2190
+/// shared + exclusive = exclusive
+/// generic + exclusive = exclusive
+/// generic + shared = shared

What do these lines mean? That we accept if a lock is shared in one branch and 
exclusive in the other, and that we make it exclusive after the merge point?



Comment at: clang/test/SemaCXX/warn-thread-safety-negative.cpp:135-140
+  if (condition) {
+assertNotHeld(); // expected-warning {{mutex '!mu' is acquired exclusively 
and shared in the same scope}}
+  } else {
+mu.Lock();
+mu.Unlock(); // expected-warning {{the other acquisition of mutex '!mu' is 
here}}
+  }

Why would I want these warnings here? This code seems fine to me.

However, I don't see why we don't get `acquiring mutex 'mu' requires negative 
capability '!mu'` at line 138, or does that disappear because of the assertion?


Repository:
  rL LLVM

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

https://reviews.llvm.org/D65184



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


[PATCH] D65184: [Sema] Thread Safety Analysis: Fix negative capability's LockKind representation.

2019-07-25 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers added inline comments.



Comment at: clang/lib/Analysis/ThreadSafety.cpp:2219-2221
+if (LDat1->kind() == LK_Generic || LDat2->kind() == LK_Generic) {
+  // No warning is issued in this case.
+  if (Modify && LDat1->kind() == LK_Generic) {

The double check of `LDat1->kind() == LK_Generic` is fishy to me.  Particularly 
the case where `LDat1->kind() == LK_Generic` is false but `LDat2->kind() == 
LK_Generic` is true.

This might be clearer as:
```
if (LDat2->kind() == LK_Generic)
  continue;
else if (LDat1->kind() == LK_Generic && Modify)
  *Iter1 = Fact;
else {
  ...
```
Or is there something else to this logic I'm missing?



Comment at: clang/test/SemaCXX/thread-safety-annotations.h:47
+// Enable thread safety attributes only with clang.
+// The attributes can be safely erased when compiling with other compilers.
+#if defined(__clang__) && (!defined(SWIG))

Is this test suite run with other compilers? If not, I think we can remove the 
case?


Repository:
  rL LLVM

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

https://reviews.llvm.org/D65184



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


[PATCH] D59963: [clang-tidy] Add a module for the Linux kernel.

2019-07-25 Thread Tom Roeder via Phabricator via cfe-commits
tmroeder updated this revision to Diff 211836.
tmroeder added a comment.

Synchronize the documentation, as requested.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D59963

Files:
  clang-tools-extra/clang-tidy/CMakeLists.txt
  clang-tools-extra/clang-tidy/ClangTidyForceLinker.h
  clang-tools-extra/clang-tidy/linuxkernel/CMakeLists.txt
  clang-tools-extra/clang-tidy/linuxkernel/LinuxKernelTidyModule.cpp
  clang-tools-extra/clang-tidy/linuxkernel/MustCheckErrsCheck.cpp
  clang-tools-extra/clang-tidy/linuxkernel/MustCheckErrsCheck.h
  clang-tools-extra/clang-tidy/plugin/CMakeLists.txt
  clang-tools-extra/clang-tidy/tool/CMakeLists.txt
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/linuxkernel-must-use-errs.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/test/clang-tidy/linuxkernel-must-check-errs.c

Index: clang-tools-extra/test/clang-tidy/linuxkernel-must-check-errs.c
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/linuxkernel-must-check-errs.c
@@ -0,0 +1,43 @@
+// RUN: %check_clang_tidy %s linuxkernel-must-check-errs %t
+
+#define __must_check __attribute__((warn_unused_result))
+
+// Prototypes of the error functions.
+void * __must_check ERR_PTR(long error);
+long  __must_check PTR_ERR(const void *ptr);
+int  __must_check IS_ERR(const void *ptr);
+int  __must_check IS_ERR_OR_NULL(const void *ptr);
+void * __must_check ERR_CAST(const void *ptr);
+int  __must_check PTR_ERR_OR_ZERO(const void *ptr);
+
+void f() {
+  ERR_PTR(0);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: result from function 'ERR_PTR' is unused
+  PTR_ERR((void *)0);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: result from function 'PTR_ERR' is unused
+  IS_ERR((void *)0);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: result from function 'IS_ERR' is unused
+  ERR_CAST((void *)0);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: result from function 'ERR_CAST' is unused
+out:
+  PTR_ERR_OR_ZERO((void *)0);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: result from function 'PTR_ERR_OR_ZERO' is unused
+}
+
+void *f1() {
+  return ERR_PTR(0);
+}
+
+long f2() {
+  if (IS_ERR((void *)0)) {
+return PTR_ERR((void *)0);
+  }
+  return -1;
+}
+
+void f3() {
+  f1();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: result from function 'f1' is unused but represents an error value
+  f2();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: result from function 'f2' is unused but represents an error value
+}
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -183,6 +183,7 @@
hicpp-use-nullptr (redirects to modernize-use-nullptr) 
hicpp-use-override (redirects to modernize-use-override) 
hicpp-vararg (redirects to cppcoreguidelines-pro-type-vararg) 
+   linuxkernel-must-use-errs
llvm-header-guard
llvm-include-order
llvm-namespace-comment
Index: clang-tools-extra/docs/clang-tidy/checks/linuxkernel-must-use-errs.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/linuxkernel-must-use-errs.rst
@@ -0,0 +1,26 @@
+.. title:: clang-tidy - linuxkernel-must-use-errs
+
+linuxkernel-must-use-errs
+=
+
+Checks for cases where the kernel error functions ``ERR_PTR``,
+``PTR_ERR``, ``IS_ERR``, ``IS_ERR_OR_NULL``, ``ERR_CAST``, and
+``PTR_ERR_OR_ZERO`` are called but the results are not used. These
+functions are marked with ``__attribute__((warn_unused_result))``, but
+the compiler warning for this attribute is not always enabled.
+
+This also checks for unused values returned by functions that return
+``ERR_PTR``.
+
+Examples:
+
+.. code-block:: c
+
+  /* Trivial unused call to an ERR function */
+  PTR_ERR_OR_ZERO(some_function_call());
+
+  /* A function that returns ERR_PTR. */
+  void *fn() { ERR_PTR(-EINVAL); }
+
+  /* An invalid use of fn. */
+  fn();
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -67,7 +67,19 @@
 Improvements to clang-tidy
 --
 
-The improvements are...
+- New :doc:`linuxkernel-must-use-errs
+  ` check.
+
+  Checks Linux kernel code to see if it uses the results from the functions in
+  ``linux/err.h``. Also checks to see if code uses the results from functions that
+  directly return a value from one of these error functions.
+
+  This is important in the Linux kernel because ``ERR_PTR``, ``PTR_ERR``,
+  ``IS_ERR``, ``IS_ERR_OR_NULL``, ``ERR_CAST``, and ``PTR_ERR_OR_ZERO`` return
+  values must be checked, since positive pointers and 

[PATCH] D64883: Add new warning -Walloca for use of builtin alloca function

2019-07-25 Thread George Burgess IV via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL367067: [Sema] add -Walloca to flag uses of `alloca` 
(authored by gbiv, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D64883?vs=211816=211837#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D64883

Files:
  cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
  cfe/trunk/lib/Sema/SemaChecking.cpp
  cfe/trunk/test/Sema/warn-alloca.c


Index: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
===
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
@@ -2779,6 +2779,11 @@
 def err_cannot_find_suitable_accessor : Error<
   "cannot find suitable %select{getter|setter}0 for property %1">;
 
+def warn_alloca : Warning<
+  "use of function %0 is discouraged; there is no way to check for failure but 
"
+  "failure may still occur, resulting in a possibly exploitable security 
vulnerability">,
+  InGroup>, DefaultIgnore;
+
 def warn_alloca_align_alignof : Warning<
   "second argument to __builtin_alloca_with_align is supposed to be in bits">,
   InGroup>;
Index: cfe/trunk/test/Sema/warn-alloca.c
===
--- cfe/trunk/test/Sema/warn-alloca.c
+++ cfe/trunk/test/Sema/warn-alloca.c
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -DSILENCE -fsyntax-only -verify -Wall %s
+// RUN: %clang_cc1 -fsyntax-only -verify -Walloca %s
+
+#ifdef SILENCE
+  // expected-no-diagnostics
+#endif
+
+void test1(int a) {
+  __builtin_alloca(a);
+#ifndef SILENCE
+  // expected-warning@-2 {{use of function '__builtin_alloca' is discouraged; 
there is no way to check for failure but failure may still occur, resulting in 
a possibly exploitable security vulnerability}}
+#endif
+}
+
+void test2(int a) {
+  __builtin_alloca_with_align(a, 32);
+#ifndef SILENCE
+  // expected-warning@-2 {{use of function '__builtin_alloca_with_align' is 
discouraged; there is no way to check for failure but failure may still occur, 
resulting in a possibly exploitable security vulnerability}}
+#endif
+}
Index: cfe/trunk/lib/Sema/SemaChecking.cpp
===
--- cfe/trunk/lib/Sema/SemaChecking.cpp
+++ cfe/trunk/lib/Sema/SemaChecking.cpp
@@ -1179,6 +1179,10 @@
   case Builtin::BI__builtin_alloca_with_align:
 if (SemaBuiltinAllocaWithAlign(TheCall))
   return ExprError();
+LLVM_FALLTHROUGH;
+  case Builtin::BI__builtin_alloca:
+Diag(TheCall->getBeginLoc(), diag::warn_alloca)
+<< TheCall->getDirectCallee();
 break;
   case Builtin::BI__assume:
   case Builtin::BI__builtin_assume:


Index: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
===
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
@@ -2779,6 +2779,11 @@
 def err_cannot_find_suitable_accessor : Error<
   "cannot find suitable %select{getter|setter}0 for property %1">;
 
+def warn_alloca : Warning<
+  "use of function %0 is discouraged; there is no way to check for failure but "
+  "failure may still occur, resulting in a possibly exploitable security vulnerability">,
+  InGroup>, DefaultIgnore;
+
 def warn_alloca_align_alignof : Warning<
   "second argument to __builtin_alloca_with_align is supposed to be in bits">,
   InGroup>;
Index: cfe/trunk/test/Sema/warn-alloca.c
===
--- cfe/trunk/test/Sema/warn-alloca.c
+++ cfe/trunk/test/Sema/warn-alloca.c
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -DSILENCE -fsyntax-only -verify -Wall %s
+// RUN: %clang_cc1 -fsyntax-only -verify -Walloca %s
+
+#ifdef SILENCE
+  // expected-no-diagnostics
+#endif
+
+void test1(int a) {
+  __builtin_alloca(a);
+#ifndef SILENCE
+  // expected-warning@-2 {{use of function '__builtin_alloca' is discouraged; there is no way to check for failure but failure may still occur, resulting in a possibly exploitable security vulnerability}}
+#endif
+}
+
+void test2(int a) {
+  __builtin_alloca_with_align(a, 32);
+#ifndef SILENCE
+  // expected-warning@-2 {{use of function '__builtin_alloca_with_align' is discouraged; there is no way to check for failure but failure may still occur, resulting in a possibly exploitable security vulnerability}}
+#endif
+}
Index: cfe/trunk/lib/Sema/SemaChecking.cpp
===
--- cfe/trunk/lib/Sema/SemaChecking.cpp
+++ cfe/trunk/lib/Sema/SemaChecking.cpp
@@ -1179,6 +1179,10 @@
   case Builtin::BI__builtin_alloca_with_align:
 if (SemaBuiltinAllocaWithAlign(TheCall))
   return ExprError();
+LLVM_FALLTHROUGH;
+  case Builtin::BI__builtin_alloca:
+

[PATCH] D59963: [clang-tidy] Add a module for the Linux kernel.

2019-07-25 Thread Tom Roeder via Phabricator via cfe-commits
tmroeder marked 2 inline comments as done.
tmroeder added inline comments.



Comment at: clang-tools-extra/docs/ReleaseNotes.rst:75
+
+  Checks Linux Kernel code to see if it uses the results from the functions in
+  linux/err.h. Also checks to see if code uses the results from functions that

Eugene.Zelenko wrote:
> Please highlight linux/err.h with double back-ticks. I think will be good 
> idea to synchronize documentation text.
Thanks, I've synchronized the documentation now between this file and the 
header.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D59963



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


r367067 - [Sema] add -Walloca to flag uses of `alloca`

2019-07-25 Thread George Burgess IV via cfe-commits
Author: gbiv
Date: Thu Jul 25 15:23:40 2019
New Revision: 367067

URL: http://llvm.org/viewvc/llvm-project?rev=367067=rev
Log:
[Sema] add -Walloca to flag uses of `alloca`

This CL adds an optional warning to diagnose uses of the
`__builtin_alloca` family of functions. The use of these functions is
discouraged by many, so it seems like a good idea to allow clang to warn
about it.

Patch by Elaina Guan!

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

Added:
cfe/trunk/test/Sema/warn-alloca.c
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaChecking.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=367067=367066=367067=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Thu Jul 25 15:23:40 
2019
@@ -2779,6 +2779,11 @@ def err_no_accessor_for_property : Error
 def err_cannot_find_suitable_accessor : Error<
   "cannot find suitable %select{getter|setter}0 for property %1">;
 
+def warn_alloca : Warning<
+  "use of function %0 is discouraged; there is no way to check for failure but 
"
+  "failure may still occur, resulting in a possibly exploitable security 
vulnerability">,
+  InGroup>, DefaultIgnore;
+
 def warn_alloca_align_alignof : Warning<
   "second argument to __builtin_alloca_with_align is supposed to be in bits">,
   InGroup>;

Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=367067=367066=367067=diff
==
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Thu Jul 25 15:23:40 2019
@@ -1179,6 +1179,10 @@ Sema::CheckBuiltinFunctionCall(FunctionD
   case Builtin::BI__builtin_alloca_with_align:
 if (SemaBuiltinAllocaWithAlign(TheCall))
   return ExprError();
+LLVM_FALLTHROUGH;
+  case Builtin::BI__builtin_alloca:
+Diag(TheCall->getBeginLoc(), diag::warn_alloca)
+<< TheCall->getDirectCallee();
 break;
   case Builtin::BI__assume:
   case Builtin::BI__builtin_assume:

Added: cfe/trunk/test/Sema/warn-alloca.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/warn-alloca.c?rev=367067=auto
==
--- cfe/trunk/test/Sema/warn-alloca.c (added)
+++ cfe/trunk/test/Sema/warn-alloca.c Thu Jul 25 15:23:40 2019
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -DSILENCE -fsyntax-only -verify -Wall %s
+// RUN: %clang_cc1 -fsyntax-only -verify -Walloca %s
+
+#ifdef SILENCE
+  // expected-no-diagnostics
+#endif
+
+void test1(int a) {
+  __builtin_alloca(a);
+#ifndef SILENCE
+  // expected-warning@-2 {{use of function '__builtin_alloca' is discouraged; 
there is no way to check for failure but failure may still occur, resulting in 
a possibly exploitable security vulnerability}}
+#endif
+}
+
+void test2(int a) {
+  __builtin_alloca_with_align(a, 32);
+#ifndef SILENCE
+  // expected-warning@-2 {{use of function '__builtin_alloca_with_align' is 
discouraged; there is no way to check for failure but failure may still occur, 
resulting in a possibly exploitable security vulnerability}}
+#endif
+}


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


[PATCH] D65300: [clang] [CodeGen] clang-misexpect prototype for compiler warnings

2019-07-25 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 added a comment.

Nice work!

It would be nice if we also have “-fsuggest-expect” so we could fix perf issues 
thanks to PGO counters even for non-PGO builds. What do you think?


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

https://reviews.llvm.org/D65300



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


[PATCH] D65106: [OPENMP]Add support for analysis of reduction variables.

2019-07-25 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ accepted this revision.
NoQ added a comment.
This revision is now accepted and ready to land.
Herald added a reviewer: jdoerfert.

Great, thanks!

That'll be fun to model in the static analyzer :/


Repository:
  rC Clang

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

https://reviews.llvm.org/D65106



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


[PATCH] D65176: [NFC][clang] Refactor getCompilationPhases()+Types.def step 2.

2019-07-25 Thread Puyan Lotfi via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL367063: [NFC][clang] Refactor 
getCompilationPhases()+Types.def step 2. (authored by zer0, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D65176?vs=211652=211832#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D65176

Files:
  cfe/trunk/include/clang/Driver/Types.def
  cfe/trunk/lib/Driver/Types.cpp

Index: cfe/trunk/include/clang/Driver/Types.def
===
--- cfe/trunk/include/clang/Driver/Types.def
+++ cfe/trunk/include/clang/Driver/Types.def
@@ -30,15 +30,12 @@
 // of this type, or null if unspecified.
 
 // The fifth value is a string containing option flags. Valid values:
-//  a - The type should only be assembled.
-//  p - The type should only be precompiled.
 //  u - The type can be user specified (with -x).
-//  m - Precompiling this type produces a module file.
-//  A - The type's temporary suffix should be appended when generating
-//  outputs of this type.
 
 // The sixth value is a variadic list of phases for each type. Eventually the
 // options flag string will be replaced with this variadic list.
+// Most of the options in Flags have been removed in favor of subsuming their
+// meaning from the phases list.
 
 // C family source language (with and without preprocessing).
 TYPE("cpp-output",   PP_C, INVALID, "i", "u", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
@@ -61,22 +58,22 @@
 TYPE("renderscript", RenderScript, PP_C,"rs","u", phases::Preprocess, phases::Compile, phases::Backend, phases::Assemble, phases::Link)
 
 // C family input files to precompile.
-TYPE("c-header-cpp-output",  PP_CHeader,   INVALID, "i", "p",  phases::Precompile)
-TYPE("c-header", CHeader,  PP_CHeader,  "h", "pu", phases::Preprocess, phases::Precompile)
-TYPE("cl-header",CLHeader, PP_CHeader,  "h", "pu", phases::Preprocess, phases::Precompile)
-TYPE("objective-c-header-cpp-output", PP_ObjCHeader, INVALID,   "mi","p",  phases::Precompile)
-TYPE("objective-c-header",   ObjCHeader,   PP_ObjCHeader,   "h", "pu", phases::Preprocess, phases::Precompile)
-TYPE("c++-header-cpp-output",PP_CXXHeader, INVALID, "ii","p",  phases::Precompile)
-TYPE("c++-header",   CXXHeader,PP_CXXHeader,"hh","pu", phases::Preprocess, phases::Precompile)
-TYPE("objective-c++-header-cpp-output", PP_ObjCXXHeader, INVALID, "mii", "p",  phases::Precompile)
-TYPE("objective-c++-header", ObjCXXHeader, PP_ObjCXXHeader, "h", "pu", phases::Preprocess, phases::Precompile)
-TYPE("c++-module",   CXXModule,PP_CXXModule,"cppm",  "mu", phases::Preprocess, phases::Precompile, phases::Compile, phases::Backend, phases::Assemble, phases::Link)
-TYPE("c++-module-cpp-output",PP_CXXModule, INVALID, "iim",   "m",  phases::Precompile, phases::Compile, phases::Backend, phases::Assemble, phases::Link)
+TYPE("c-header-cpp-output",  PP_CHeader,   INVALID, "i", "",   phases::Precompile)
+TYPE("c-header", CHeader,  PP_CHeader,  "h", "u",  phases::Preprocess, phases::Precompile)
+TYPE("cl-header",CLHeader, PP_CHeader,  "h", "u",  phases::Preprocess, phases::Precompile)
+TYPE("objective-c-header-cpp-output", PP_ObjCHeader, INVALID,   "mi","",   phases::Precompile)
+TYPE("objective-c-header",   ObjCHeader,   PP_ObjCHeader,   "h", "u",  phases::Preprocess, phases::Precompile)
+TYPE("c++-header-cpp-output",PP_CXXHeader, INVALID, "ii","",   phases::Precompile)
+TYPE("c++-header",   CXXHeader,PP_CXXHeader,"hh","u",  phases::Preprocess, phases::Precompile)
+TYPE("objective-c++-header-cpp-output", PP_ObjCXXHeader, INVALID, "mii", "",   phases::Precompile)
+TYPE("objective-c++-header", ObjCXXHeader, PP_ObjCXXHeader, "h", "u",  phases::Preprocess, phases::Precompile)
+TYPE("c++-module",   CXXModule,PP_CXXModule,"cppm",  "u",  phases::Preprocess, phases::Precompile, phases::Compile, phases::Backend, phases::Assemble, phases::Link)
+TYPE("c++-module-cpp-output",PP_CXXModule, INVALID, "iim",   "",   phases::Precompile, phases::Compile, phases::Backend, phases::Assemble, phases::Link)
 
 // Other languages.
 TYPE("ada",  Ada,  INVALID, nullptr, "u",  phases::Compile, phases::Backend, phases::Assemble, phases::Link)
-TYPE("assembler",PP_Asm,   INVALID, "s", "au", phases::Assemble, phases::Link)
-TYPE("assembler-with-cpp",   Asm,  PP_Asm,  "S", "au", phases::Preprocess, 

r367063 - [NFC][clang] Refactor getCompilationPhases()+Types.def step 2.

2019-07-25 Thread Puyan Lotfi via cfe-commits
Author: zer0
Date: Thu Jul 25 15:05:55 2019
New Revision: 367063

URL: http://llvm.org/viewvc/llvm-project?rev=367063=rev
Log:
[NFC][clang] Refactor getCompilationPhases()+Types.def step 2.

- Removing a few of the entries in the Flags for the Types.def table.
- Removing redundant parts of getCompilationPhases().

Flags have been removed from Types.def:

 a - The type should only be assembled: Now, check that Phases contains
 phases::Assemble but not phases::Compile or phases::Backend.
 p - The type should only be precompiled: Now, check that Phases contains
 phases::Precompile but that Flags does not contain 'm'.
 m - Precompiling this type produces a module file: Now, check that
 isPrepeocessedModuleType.



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

Modified:
cfe/trunk/include/clang/Driver/Types.def
cfe/trunk/lib/Driver/Types.cpp

Modified: cfe/trunk/include/clang/Driver/Types.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Types.def?rev=367063=367062=367063=diff
==
--- cfe/trunk/include/clang/Driver/Types.def (original)
+++ cfe/trunk/include/clang/Driver/Types.def Thu Jul 25 15:05:55 2019
@@ -30,15 +30,12 @@
 // of this type, or null if unspecified.
 
 // The fifth value is a string containing option flags. Valid values:
-//  a - The type should only be assembled.
-//  p - The type should only be precompiled.
 //  u - The type can be user specified (with -x).
-//  m - Precompiling this type produces a module file.
-//  A - The type's temporary suffix should be appended when generating
-//  outputs of this type.
 
 // The sixth value is a variadic list of phases for each type. Eventually the
 // options flag string will be replaced with this variadic list.
+// Most of the options in Flags have been removed in favor of subsuming their
+// meaning from the phases list.
 
 // C family source language (with and without preprocessing).
 TYPE("cpp-output",   PP_C, INVALID, "i", "u", 
phases::Compile, phases::Backend, phases::Assemble, phases::Link)
@@ -61,22 +58,22 @@ TYPE("objective-c++",ObjCXX,
 TYPE("renderscript", RenderScript, PP_C,"rs","u", 
phases::Preprocess, phases::Compile, phases::Backend, phases::Assemble, 
phases::Link)
 
 // C family input files to precompile.
-TYPE("c-header-cpp-output",  PP_CHeader,   INVALID, "i", "p",  
phases::Precompile)
-TYPE("c-header", CHeader,  PP_CHeader,  "h", "pu", 
phases::Preprocess, phases::Precompile)
-TYPE("cl-header",CLHeader, PP_CHeader,  "h", "pu", 
phases::Preprocess, phases::Precompile)
-TYPE("objective-c-header-cpp-output", PP_ObjCHeader, INVALID,   "mi","p",  
phases::Precompile)
-TYPE("objective-c-header",   ObjCHeader,   PP_ObjCHeader,   "h", "pu", 
phases::Preprocess, phases::Precompile)
-TYPE("c++-header-cpp-output",PP_CXXHeader, INVALID, "ii","p",  
phases::Precompile)
-TYPE("c++-header",   CXXHeader,PP_CXXHeader,"hh","pu", 
phases::Preprocess, phases::Precompile)
-TYPE("objective-c++-header-cpp-output", PP_ObjCXXHeader, INVALID, "mii", "p",  
phases::Precompile)
-TYPE("objective-c++-header", ObjCXXHeader, PP_ObjCXXHeader, "h", "pu", 
phases::Preprocess, phases::Precompile)
-TYPE("c++-module",   CXXModule,PP_CXXModule,"cppm",  "mu", 
phases::Preprocess, phases::Precompile, phases::Compile, phases::Backend, 
phases::Assemble, phases::Link)
-TYPE("c++-module-cpp-output",PP_CXXModule, INVALID, "iim",   "m",  
phases::Precompile, phases::Compile, phases::Backend, phases::Assemble, 
phases::Link)
+TYPE("c-header-cpp-output",  PP_CHeader,   INVALID, "i", "",   
phases::Precompile)
+TYPE("c-header", CHeader,  PP_CHeader,  "h", "u",  
phases::Preprocess, phases::Precompile)
+TYPE("cl-header",CLHeader, PP_CHeader,  "h", "u",  
phases::Preprocess, phases::Precompile)
+TYPE("objective-c-header-cpp-output", PP_ObjCHeader, INVALID,   "mi","",   
phases::Precompile)
+TYPE("objective-c-header",   ObjCHeader,   PP_ObjCHeader,   "h", "u",  
phases::Preprocess, phases::Precompile)
+TYPE("c++-header-cpp-output",PP_CXXHeader, INVALID, "ii","",   
phases::Precompile)
+TYPE("c++-header",   CXXHeader,PP_CXXHeader,"hh","u",  
phases::Preprocess, phases::Precompile)
+TYPE("objective-c++-header-cpp-output", PP_ObjCXXHeader, INVALID, "mii", "",   
phases::Precompile)
+TYPE("objective-c++-header", ObjCXXHeader, PP_ObjCXXHeader, "h", "u",  
phases::Preprocess, phases::Precompile)
+TYPE("c++-module",   CXXModule,PP_CXXModule,"cppm",  "u",  
phases::Preprocess, phases::Precompile, phases::Compile, phases::Backend, 
phases::Assemble, phases::Link)

[PATCH] D65300: [clang] [CodeGen] clang-misexpect prototype for compiler warnings

2019-07-25 Thread Paul Kirth via Phabricator via cfe-commits
paulkirth updated this revision to Diff 211831.
paulkirth added a comment.

Refactors some debug code to be more centralized and cleans up some comments.


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

https://reviews.llvm.org/D65300

Files:
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/CGStmt.cpp
  clang/lib/CodeGen/CMakeLists.txt
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/CodeGen/MisExpect.cpp
  clang/lib/CodeGen/MisExpect.h
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/Profile/Inputs/misexpect-branch-nonconst-expect-arg.proftext
  clang/test/Profile/Inputs/misexpect-branch.proftext
  clang/test/Profile/Inputs/misexpect-switch.proftext
  clang/test/Profile/misexpect-branch-cold.c
  clang/test/Profile/misexpect-branch-nonconst-expected-val.c
  clang/test/Profile/misexpect-branch.c
  clang/test/Profile/misexpect-no-warning-without-flag.c
  clang/test/Profile/misexpect-switch-default.c
  clang/test/Profile/misexpect-switch.c

Index: clang/test/Profile/misexpect-switch.c
===
--- /dev/null
+++ clang/test/Profile/misexpect-switch.c
@@ -0,0 +1,68 @@
+// Test that misexpect detects mis-annotated switch statements
+
+// RUN: llvm-profdata merge %S/Inputs/misexpect-switch.proftext -o %t.profdata
+// RUN: %clang_cc1 %s -O2 -o - -disable-llvm-passes -emit-llvm -fprofile-instrument-use-path=%t.profdata -verify -fmisexpect
+
+int sum(int *buff, int size);
+int random_sample(int *buff, int size);
+int rand();
+
+const int inner_loop = 1000;
+const int outer_loop = 20;
+const int arry_size = 25;
+
+int arry[arry_size] = {0};
+
+void init_arry() {
+  int i;
+  for (i = 0; i < arry_size; ++i) {
+arry[i] = rand() % 10;
+  }
+}
+
+int main() {
+  init_arry();
+  int val = 0;
+
+  int j, k;
+  for (j = 0; j < outer_loop; ++j) {
+for (k = 0; k < inner_loop; ++k) {
+  unsigned condition = rand() % 1;
+  switch (__builtin_expect(condition, 0)) { //expected-warning {{Current PGO counters disagree with the use of __builtin_expect().}}
+  case 0:
+val += sum(arry, arry_size);
+break;
+  case 1:
+  case 2:
+  case 3:
+  case 4:
+val += random_sample(arry, arry_size);
+break;
+  default:
+__builtin_unreachable();
+  } // end switch
+}   // end inner_loop
+  } // end outer_loop
+
+  return 0;
+}
+
+int sum(int *buff, int size) {
+  int total = 0;
+  int i = 0;
+  for (i = 0; i < size; ++i) {
+total += buff[i];
+  }
+  return total;
+}
+
+int random_sample(int *buff, int size) {
+  int total = 0;
+  int i;
+  for (i = 0; i < size; ++i) {
+if (rand() % 5 == 0)
+  total += buff[i];
+  }
+
+  return total;
+}
Index: clang/test/Profile/misexpect-switch-default.c
===
--- /dev/null
+++ clang/test/Profile/misexpect-switch-default.c
@@ -0,0 +1,68 @@
+// Test that misexpect detects mis-annotated switch statements
+
+// RUN: llvm-profdata merge %S/Inputs/misexpect-switch.proftext -o %t.profdata
+// RUN: %clang_cc1 %s -O2 -o - -disable-llvm-passes -emit-llvm -fprofile-instrument-use-path=%t.profdata -verify -fmisexpect
+
+int sum(int *buff, int size);
+int random_sample(int *buff, int size);
+int rand();
+
+const int inner_loop = 1000;
+const int outer_loop = 20;
+const int arry_size = 25;
+
+int arry[arry_size] = {0};
+
+void init_arry() {
+  int i;
+  for (i = 0; i < arry_size; ++i) {
+arry[i] = rand() % 10;
+  }
+}
+
+int main() {
+  init_arry();
+  int val = 0;
+
+  int j, k;
+  for (j = 0; j < outer_loop; ++j) {
+for (k = 0; k < inner_loop; ++k) {
+  unsigned condition = rand() % 5;
+  switch (__builtin_expect(condition, 6)) { //expected-warning {{Current PGO counters disagree with the use of __builtin_expect().}}
+  case 0:
+val += sum(arry, arry_size);
+break;
+  case 1:
+  case 2:
+  case 3:
+  case 4:
+val += random_sample(arry, arry_size);
+break;
+  default:
+__builtin_unreachable();
+  } // end switch
+}   // end inner_loop
+  } // end outer_loop
+
+  return 0;
+}
+
+int sum(int *buff, int size) {
+  int total = 0;
+  int i = 0;
+  for (i = 0; i < size; ++i) {
+total += buff[i];
+  }
+  return total;
+}
+
+int random_sample(int *buff, int size) {
+  int total = 0;
+  int i;
+  for (i = 0; i < size; ++i) {
+if (rand() % 5 == 0)
+  total += buff[i];
+  }
+
+  return total;
+}
Index: clang/test/Profile/misexpect-no-warning-without-flag.c
===
--- /dev/null
+++ clang/test/Profile/misexpect-no-warning-without-flag.c
@@ -0,0 +1,51 @@
+// Test that misexpect detects mis-annotated branches
+
+// RUN: llvm-profdata merge %S/Inputs/misexpect-branch.proftext -o %t.profdata

[PATCH] D65300: [clang] [CodeGen] clang-misexpect prototype for compiler warnings

2019-07-25 Thread Paul Kirth via Phabricator via cfe-commits
paulkirth created this revision.
paulkirth added reviewers: phosek, leonardchan, jakehehrlich, mcgrathr.
Herald added subscribers: cfe-commits, kristof.beyls, javed.absar, mgorny.
Herald added a project: clang.

**Overview**:
This patch contains a prototype of the basic functionality of clang-misexpect 
in the PGO pipeline.  clang-misexpect is a proposed clang-tool that can report 
potentially incorrect usage of __builtin_expect() by comparing the developer's 
annotation against a collected PGO profile.  A more detailed proposal and 
discussion appears on the CFE-dev mailing list 
(http://lists.llvm.org/pipermail/cfe-dev/2019-July/062971.html)

This patch adds the basic checking mechanisms to the compiler in the CodeGen 
library as a set of warnings usable when compiling with PGO. Once the logic in 
this patch is verified, it can be used to as the basis for a standalone tool.

This patch adds a new flag -fmisexpect to clang, and adds additional checks for 
branches and switch statements when branch weights are assigned in 
clang/lib/CodeGen/CodeGenFunction.cpp & clang/lib/CodeGen/CGStmt.cpp.

The bulk of the checking logic is implemented in 
clang/lib/CodeGen/MisExpect.cpp.  It has some minor changes to some of the 
logic in CGStmt.cpp to properly map the profiling counters to their concrete 
values in the case statements for switches.

The patch also provides a number of  lit based tests for various usage of 
__builtin_expect() for branches and switch statements.

**Details**:

The strategy for MisExpect checks is straightforward: when __builtin_expect() 
is used, then compare the relevant profile counter against a threshold value, 
and emit a warning if we've found a mismatch (i.e. the profile counter is 
outside the acceptable range).

For conditional statements this is simple.  We can determine whether the 
profile count agrees with the annotation via direct comparison w/ the 
appropriate hot/cold thresholds.

For switch statements the situation is slightly more complex due to the way 
profiling counters are assigned.

Each case statement in the switch body will get its own counter, except when 
the cases are empty fall-throughs, in which case they will share a counter.

So, in the case where:

  switch(x){
  case 1:
  case 2:
break;
  case default:
break;
  };

Here, values 1 & 2 will share a single counter, and all other cases will share 
a counter for the default case.

However, in the following example:

  switch(x){
  case 1:
   x = x+1;
  case 2:
break;
  case default:
break;
  };

In the example above, values 1 & 2 will each have their own profiling counter 
instead of sharing one, even though case 1 falls through to case 2.  The 
default case stays the same with a shared counter for every value not present 
in the switch body.

To be align with developer expectations we treat these empty fall-throughs 
conservatively for the purpose of generating warnings, i.e. if the expected 
value results in the hottest branch being executed we will not emit the 
warning, even though the strict semantics of __builtin_expect() are slightly 
different. We support this by maintaining a mapping from the concrete value in 
the switch arm back to its relevant profile counter.

In the case where the profile counters are not shared, we always do a direct 
check using the relevant profile counter.

Right now MisExpect only ensures that the hottest arm of the switch statement 
is the one the developer chosen, without reference to any particular threshold. 
It is arguable that we should have an additional check against a threshold, 
similar to what is done for conditional statements.

**Heuristics**: 
For branch 'hotness' I've used the existing thresholds for determining 
FFA_Hot/FFA_Cold function annotations. This is a dubious choice for the 
thresholds, but are a suitable heuristic for the prototype. Feedback on a more 
appropriate set of threshold values is welcome and desirable.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D65300

Files:
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/CGStmt.cpp
  clang/lib/CodeGen/CMakeLists.txt
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/CodeGen/MisExpect.cpp
  clang/lib/CodeGen/MisExpect.h
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/Profile/Inputs/misexpect-branch-nonconst-expect-arg.proftext
  clang/test/Profile/Inputs/misexpect-branch.proftext
  clang/test/Profile/Inputs/misexpect-switch.proftext
  clang/test/Profile/misexpect-branch-cold.c
  clang/test/Profile/misexpect-branch-nonconst-expected-val.c
  clang/test/Profile/misexpect-branch.c
  clang/test/Profile/misexpect-no-warning-without-flag.c
  clang/test/Profile/misexpect-switch-default.c
  clang/test/Profile/misexpect-switch.c

Index: clang/test/Profile/misexpect-switch.c

[PATCH] D65234: [CodeGen]: don't treat structures returned in registers as memory inputs

2019-07-25 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers added inline comments.



Comment at: clang/lib/CodeGen/CGStmt.cpp:1989
   std::vector Args;
+  std::vector ResultTypeRequiresCast;
 

Are we able to use something other than `std::vector` here from ADT?
http://llvm.org/docs/ProgrammersManual.html#bit-storage-containers-bitvector-sparsebitvector


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D65234



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


[PATCH] D64539: [clang-doc] Add stylesheet to generated html docs

2019-07-25 Thread Diego Astiazarán via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGdb5d8e3db253: [clang-doc] Add stylesheet to generated html 
docs (authored by DiegoAstiazaran).
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64539

Files:
  clang-tools-extra/clang-doc/Generators.h
  clang-tools-extra/clang-doc/HTMLGenerator.cpp
  clang-tools-extra/clang-doc/MDGenerator.cpp
  clang-tools-extra/clang-doc/Representation.h
  clang-tools-extra/clang-doc/Serialize.cpp
  clang-tools-extra/clang-doc/YAMLGenerator.cpp
  clang-tools-extra/clang-doc/stylesheets/clang-doc-default-stylesheet.css
  clang-tools-extra/clang-doc/tool/CMakeLists.txt
  clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
  clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp

Index: clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
+++ clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
@@ -43,6 +43,7 @@
   std::string Expected = R"raw(
 
 namespace Namespace
+
 
   namespace Namespace
   Namespaces
@@ -103,6 +104,7 @@
   std::string Expected = R"raw(
 
 class r
+
 
   class r
   Defined at line 10 of test.cpp
@@ -168,6 +170,7 @@
   std::string Expected = R"raw(
 
 
+
 
   f
   
@@ -205,6 +208,7 @@
   std::string Expected = R"raw(
 
 
+
 
   enum class e
   
@@ -272,6 +276,7 @@
   std::string Expected = R"raw(
 
 
+
 
   f
   void f(int I, int J)
Index: clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
===
--- clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
+++ clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
@@ -91,6 +91,15 @@
   llvm_unreachable("Unknown OutputFormatTy");
 }
 
+// This function isn't referenced outside its translation unit, but it
+// can't use the "static" keyword because its address is used for
+// GetMainExecutable (since some platforms don't support taking the
+// address of main, and some platforms can't implement GetMainExecutable
+// without being given the address of a function in the main executable).
+std::string GetExecutablePath(const char *Argv0, void *MainAddr) {
+  return llvm::sys::fs::getMainExecutable(Argv0, MainAddr);
+}
+
 bool CreateDirectory(const Twine , bool ClearDirectory = false) {
   std::error_code OK;
   llvm::SmallString<128> DocsRootPath;
@@ -129,7 +138,6 @@
  StringRef RelativePath,
  StringRef Name,
  StringRef Ext) {
-  std::error_code OK;
   llvm::SmallString<128> Path;
   llvm::sys::path::native(Root, Path);
   llvm::sys::path::append(Path, RelativePath);
@@ -195,8 +203,10 @@
 
   // Mapping phase
   llvm::outs() << "Mapping decls...\n";
+  void *MainAddr = (void *)(intptr_t)GetExecutablePath;
+  std::string ClangDocPath = GetExecutablePath(argv[0], MainAddr);
   clang::doc::ClangDocContext CDCtx = {Exec->get()->getExecutionContext(),
-   PublicOnly};
+   PublicOnly, OutDirectory, ClangDocPath};
   auto Err =
   Exec->get()->execute(doc::newMapperActionFactory(CDCtx), ArgAdjuster);
   if (Err) {
@@ -239,5 +249,8 @@
   llvm::errs() << toString(std::move(Err)) << "\n";
   }
 
+  if (!G->get()->createResources(CDCtx))
+return 1;
+
   return 0;
 }
Index: clang-tools-extra/clang-doc/tool/CMakeLists.txt
===
--- clang-tools-extra/clang-doc/tool/CMakeLists.txt
+++ clang-tools-extra/clang-doc/tool/CMakeLists.txt
@@ -14,4 +14,7 @@
   clangTooling
   clangToolingCore
   )
-  
\ No newline at end of file
+
+install(FILES ../stylesheets/clang-doc-default-stylesheet.css
+  DESTINATION share/clang
+  COMPONENT clang-doc)
Index: clang-tools-extra/clang-doc/stylesheets/clang-doc-default-stylesheet.css
===
--- /dev/null
+++ clang-tools-extra/clang-doc/stylesheets/clang-doc-default-stylesheet.css
@@ -0,0 +1,205 @@
+body,div {
+  margin: 0;
+  padding: 0;
+}
+
+body[no-overflow] {
+  overflow: hidden;
+}
+
+li>p:first-child {
+  margin-top: 0;
+}
+
+li>p:last-child {
+  margin-bottom: 0;
+}
+
+html {
+  -webkit-box-sizing: border-box;
+  box-sizing: border-box;
+}
+
+*,*::before,*::after {
+  -webkit-box-sizing: inherit;
+  box-sizing: inherit;
+}
+
+body,html {
+  color: #202124;
+  font: 400 16px/24px Roboto,sans-serif;
+  -moz-osx-font-smoothing: grayscale;
+  -webkit-font-smoothing: antialiased;
+  height: 100%;
+  margin: 36px;
+  -webkit-text-size-adjust: 100%;
+  -moz-text-size-adjust: 100%;
+  -ms-text-size-adjust: 100%;
+  text-size-adjust: 100%;
+}
+
+body[devsite-framebox] {
+  

[clang-tools-extra] r367056 - [clang-doc] Add stylesheet to generated html docs

2019-07-25 Thread Diego Astiazaran via cfe-commits
Author: diegoastiazaran
Date: Thu Jul 25 14:27:50 2019
New Revision: 367056

URL: http://llvm.org/viewvc/llvm-project?rev=367056=rev
Log:
[clang-doc] Add stylesheet to generated html docs

A default css stylesheet is included for docs generated in html format.

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

Added:
clang-tools-extra/trunk/clang-doc/stylesheets/

clang-tools-extra/trunk/clang-doc/stylesheets/clang-doc-default-stylesheet.css
Modified:
clang-tools-extra/trunk/clang-doc/Generators.h
clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp
clang-tools-extra/trunk/clang-doc/MDGenerator.cpp
clang-tools-extra/trunk/clang-doc/Representation.h
clang-tools-extra/trunk/clang-doc/Serialize.cpp
clang-tools-extra/trunk/clang-doc/YAMLGenerator.cpp
clang-tools-extra/trunk/clang-doc/tool/CMakeLists.txt
clang-tools-extra/trunk/clang-doc/tool/ClangDocMain.cpp
clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp

Modified: clang-tools-extra/trunk/clang-doc/Generators.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-doc/Generators.h?rev=367056=367055=367056=diff
==
--- clang-tools-extra/trunk/clang-doc/Generators.h (original)
+++ clang-tools-extra/trunk/clang-doc/Generators.h Thu Jul 25 14:27:50 2019
@@ -27,6 +27,7 @@ public:
 
   // Write out the decl info in the specified format.
   virtual llvm::Error generateDocForInfo(Info *I, llvm::raw_ostream ) = 0;
+  virtual bool createResources(ClangDocContext CDCtx) = 0;
 };
 
 typedef llvm::Registry GeneratorRegistry;

Modified: clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp?rev=367056=367055=367056=diff
==
--- clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp (original)
+++ clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp Thu Jul 25 14:27:50 2019
@@ -35,6 +35,7 @@ public:
 TAG_UL,
 TAG_LI,
 TAG_A,
+TAG_LINK,
   };
 
   HTMLTag() = default;
@@ -103,6 +104,7 @@ struct HTMLFile {
 bool HTMLTag::IsSelfClosing() const {
   switch (Value) {
   case HTMLTag::TAG_META:
+  case HTMLTag::TAG_LINK:
 return true;
   case HTMLTag::TAG_TITLE:
   case HTMLTag::TAG_DIV:
@@ -140,6 +142,8 @@ llvm::SmallString<16> HTMLTag::ToString(
 return llvm::SmallString<16>("li");
   case HTMLTag::TAG_A:
 return llvm::SmallString<16>("a");
+  case HTMLTag::TAG_LINK:
+return llvm::SmallString<16>("link");
   }
   llvm_unreachable("Unhandled HTMLTag::TagType");
 }
@@ -526,6 +530,7 @@ public:
   static const char *Format;
 
   llvm::Error generateDocForInfo(Info *I, llvm::raw_ostream ) override;
+  bool createResources(ClangDocContext CDCtx) override;
 };
 
 const char *HTMLGenerator::Format = "html";
@@ -572,12 +577,40 @@ llvm::Error HTMLGenerator::generateDocFo
 
   F.Children.emplace_back(
   llvm::make_unique(HTMLTag::TAG_TITLE, InfoTitle));
+  auto LinkNode = llvm::make_unique(HTMLTag::TAG_LINK);
+  LinkNode->Attributes.try_emplace("rel", "stylesheet");
+  SmallString<128> StylesheetPath = computeRelativePath("", I->Path);
+  llvm::sys::path::append(StylesheetPath, "clang-doc-default-stylesheet.css");
+  LinkNode->Attributes.try_emplace("href", StylesheetPath);
+  F.Children.emplace_back(std::move(LinkNode));
   F.Children.emplace_back(std::move(MainContentNode));
   F.Render(OS);
 
   return llvm::Error::success();
 }
 
+bool HTMLGenerator::createResources(ClangDocContext CDCtx) {
+  llvm::outs() << "Generating stylesheet for docs...\n";
+  llvm::SmallString<128> StylesheetPathWrite;
+  llvm::sys::path::native(CDCtx.OutDirectory, StylesheetPathWrite);
+  llvm::sys::path::append(StylesheetPathWrite,
+  "clang-doc-default-stylesheet.css");
+  llvm::SmallString<128> StylesheetPathRead;
+  llvm::sys::path::native(CDCtx.ClangDocPath, StylesheetPathRead);
+  StylesheetPathRead = llvm::sys::path::parent_path(StylesheetPathRead);
+  llvm::sys::path::append(StylesheetPathRead, "..", "share", "clang",
+  "clang-doc-default-stylesheet.css");
+  std::error_code OK;
+  std::error_code FileErr =
+  llvm::sys::fs::copy_file(StylesheetPathRead, StylesheetPathWrite);
+  if (FileErr != OK) {
+llvm::errs() << "Error creating stylesheet file: " << FileErr.message()
+ << "\n";
+return false;
+  }
+  return true;
+}
+
 static GeneratorRegistry::Add HTML(HTMLGenerator::Format,
   "Generator for HTML 
output.");
 

Modified: clang-tools-extra/trunk/clang-doc/MDGenerator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-doc/MDGenerator.cpp?rev=367056=367055=367056=diff
==
--- clang-tools-extra/trunk/clang-doc/MDGenerator.cpp 

[PATCH] D64539: [clang-doc] Add stylesheet to generated html docs

2019-07-25 Thread Diego Astiazarán via Phabricator via cfe-commits
DiegoAstiazaran updated this revision to Diff 211820.

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

https://reviews.llvm.org/D64539

Files:
  clang-tools-extra/clang-doc/Generators.h
  clang-tools-extra/clang-doc/HTMLGenerator.cpp
  clang-tools-extra/clang-doc/MDGenerator.cpp
  clang-tools-extra/clang-doc/Representation.h
  clang-tools-extra/clang-doc/Serialize.cpp
  clang-tools-extra/clang-doc/YAMLGenerator.cpp
  clang-tools-extra/clang-doc/stylesheets/clang-doc-default-stylesheet.css
  clang-tools-extra/clang-doc/tool/CMakeLists.txt
  clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
  clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp

Index: clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
+++ clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
@@ -43,6 +43,7 @@
   std::string Expected = R"raw(
 
 namespace Namespace
+
 
   namespace Namespace
   Namespaces
@@ -103,6 +104,7 @@
   std::string Expected = R"raw(
 
 class r
+
 
   class r
   Defined at line 10 of test.cpp
@@ -168,6 +170,7 @@
   std::string Expected = R"raw(
 
 
+
 
   f
   
@@ -205,6 +208,7 @@
   std::string Expected = R"raw(
 
 
+
 
   enum class e
   
@@ -272,6 +276,7 @@
   std::string Expected = R"raw(
 
 
+
 
   f
   void f(int I, int J)
Index: clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
===
--- clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
+++ clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
@@ -91,6 +91,15 @@
   llvm_unreachable("Unknown OutputFormatTy");
 }
 
+// This function isn't referenced outside its translation unit, but it
+// can't use the "static" keyword because its address is used for
+// GetMainExecutable (since some platforms don't support taking the
+// address of main, and some platforms can't implement GetMainExecutable
+// without being given the address of a function in the main executable).
+std::string GetExecutablePath(const char *Argv0, void *MainAddr) {
+  return llvm::sys::fs::getMainExecutable(Argv0, MainAddr);
+}
+
 bool CreateDirectory(const Twine , bool ClearDirectory = false) {
   std::error_code OK;
   llvm::SmallString<128> DocsRootPath;
@@ -129,7 +138,6 @@
  StringRef RelativePath,
  StringRef Name,
  StringRef Ext) {
-  std::error_code OK;
   llvm::SmallString<128> Path;
   llvm::sys::path::native(Root, Path);
   llvm::sys::path::append(Path, RelativePath);
@@ -195,8 +203,10 @@
 
   // Mapping phase
   llvm::outs() << "Mapping decls...\n";
+  void *MainAddr = (void *)(intptr_t)GetExecutablePath;
+  std::string ClangDocPath = GetExecutablePath(argv[0], MainAddr);
   clang::doc::ClangDocContext CDCtx = {Exec->get()->getExecutionContext(),
-   PublicOnly};
+   PublicOnly, OutDirectory, ClangDocPath};
   auto Err =
   Exec->get()->execute(doc::newMapperActionFactory(CDCtx), ArgAdjuster);
   if (Err) {
@@ -239,5 +249,8 @@
   llvm::errs() << toString(std::move(Err)) << "\n";
   }
 
+  if (!G->get()->createResources(CDCtx))
+return 1;
+
   return 0;
 }
Index: clang-tools-extra/clang-doc/tool/CMakeLists.txt
===
--- clang-tools-extra/clang-doc/tool/CMakeLists.txt
+++ clang-tools-extra/clang-doc/tool/CMakeLists.txt
@@ -14,4 +14,7 @@
   clangTooling
   clangToolingCore
   )
-  
\ No newline at end of file
+
+install(FILES ../stylesheets/clang-doc-default-stylesheet.css
+  DESTINATION share/clang
+  COMPONENT clang-doc)
Index: clang-tools-extra/clang-doc/stylesheets/clang-doc-default-stylesheet.css
===
--- /dev/null
+++ clang-tools-extra/clang-doc/stylesheets/clang-doc-default-stylesheet.css
@@ -0,0 +1,205 @@
+body,div {
+  margin: 0;
+  padding: 0;
+}
+
+body[no-overflow] {
+  overflow: hidden;
+}
+
+li>p:first-child {
+  margin-top: 0;
+}
+
+li>p:last-child {
+  margin-bottom: 0;
+}
+
+html {
+  -webkit-box-sizing: border-box;
+  box-sizing: border-box;
+}
+
+*,*::before,*::after {
+  -webkit-box-sizing: inherit;
+  box-sizing: inherit;
+}
+
+body,html {
+  color: #202124;
+  font: 400 16px/24px Roboto,sans-serif;
+  -moz-osx-font-smoothing: grayscale;
+  -webkit-font-smoothing: antialiased;
+  height: 100%;
+  margin: 36px;
+  -webkit-text-size-adjust: 100%;
+  -moz-text-size-adjust: 100%;
+  -ms-text-size-adjust: 100%;
+  text-size-adjust: 100%;
+}
+
+body[devsite-framebox] {
+  overflow: hidden;
+  padding: 20px;
+}
+
+body[sitemask--active] {
+  overflow: hidden;
+}
+
+p {
+  margin: 16px 0;
+  padding: 0;
+}
+
+:link,:visited {
+  color: #039be5;
+  outline: 0;
+  text-decoration: 

[clang-tools-extra] r367050 - [clang-doc] Fix output format of html

2019-07-25 Thread Diego Astiazaran via cfe-commits
Author: diegoastiazaran
Date: Thu Jul 25 13:49:00 2019
New Revision: 367050

URL: http://llvm.org/viewvc/llvm-project?rev=367050=rev
Log:
[clang-doc] Fix output format of html

The children of a TagNode are rendered in the same line as the parent only if 
they are all TextNodes.
When children are not inline; two text nodes that are adjacent won't have a new 
line between them, each tag node is rendered in its own line.

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

Modified:
clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp
clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp

Modified: clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp?rev=367050=367049=367050=diff
==
--- clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp (original)
+++ clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp Thu Jul 25 13:49:00 2019
@@ -44,9 +44,6 @@ public:
   operator bool() = delete;
 
   bool IsSelfClosing() const;
-
-  bool HasInlineChildren() const;
-
   llvm::SmallString<16> ToString() const;
 
 private:
@@ -67,29 +64,20 @@ struct HTMLNode {
 };
 
 struct TextNode : public HTMLNode {
-  TextNode(const Twine , bool Indented = true)
-  : HTMLNode(NodeType::NODE_TEXT), Text(Text.str()), Indented(Indented) {}
+  TextNode(const Twine )
+  : HTMLNode(NodeType::NODE_TEXT), Text(Text.str()) {}
 
   std::string Text; // Content of node
-  bool Indented; // Indicates if an indentation must be rendered before the 
text
   void Render(llvm::raw_ostream , int IndentationLevel) override;
 };
 
 struct TagNode : public HTMLNode {
-  TagNode(HTMLTag Tag)
-  : HTMLNode(NodeType::NODE_TAG), Tag(Tag),
-InlineChildren(Tag.HasInlineChildren()),
-SelfClosing(Tag.IsSelfClosing()) {}
+  TagNode(HTMLTag Tag) : HTMLNode(NodeType::NODE_TAG), Tag(Tag) {}
   TagNode(HTMLTag Tag, const Twine ) : TagNode(Tag) {
-Children.emplace_back(
-llvm::make_unique(Text.str(), !InlineChildren));
+Children.emplace_back(llvm::make_unique(Text.str()));
   }
 
-  HTMLTag Tag; // Name of HTML Tag (p, div, h1)
-  bool InlineChildren; // Indicates if children nodes are rendered in the same
-   // line as itself or if children must rendered in the
-   // next line and with additional indentation
-  bool SelfClosing;// Indicates if tag is self-closing
+  HTMLTag Tag; // Name of HTML Tag (p, div, h1)
   std::vector> Children; // List of child nodes
   llvm::StringMap>
   Attributes; // List of key-value attributes for tag
@@ -130,24 +118,6 @@ bool HTMLTag::IsSelfClosing() const {
   llvm_unreachable("Unhandled HTMLTag::TagType");
 }
 
-bool HTMLTag::HasInlineChildren() const {
-  switch (Value) {
-  case HTMLTag::TAG_META:
-  case HTMLTag::TAG_TITLE:
-  case HTMLTag::TAG_H1:
-  case HTMLTag::TAG_H2:
-  case HTMLTag::TAG_H3:
-  case HTMLTag::TAG_LI:
-  case HTMLTag::TAG_A:
-return true;
-  case HTMLTag::TAG_DIV:
-  case HTMLTag::TAG_P:
-  case HTMLTag::TAG_UL:
-return false;
-  }
-  llvm_unreachable("Unhandled HTMLTag::TagType");
-}
-
 llvm::SmallString<16> HTMLTag::ToString() const {
   switch (Value) {
   case HTMLTag::TAG_META:
@@ -175,17 +145,23 @@ llvm::SmallString<16> HTMLTag::ToString(
 }
 
 void TextNode::Render(llvm::raw_ostream , int IndentationLevel) {
-  if (Indented)
-OS.indent(IndentationLevel * 2);
+  OS.indent(IndentationLevel * 2);
   printHTMLEscaped(Text, OS);
 }
 
 void TagNode::Render(llvm::raw_ostream , int IndentationLevel) {
+  // Children nodes are rendered in the same line if all of them are text nodes
+  bool InlineChildren = true;
+  for (const auto  : Children)
+if (C->Type == NodeType::NODE_TAG) {
+  InlineChildren = false;
+  break;
+}
   OS.indent(IndentationLevel * 2);
   OS << "<" << Tag.ToString();
   for (const auto  : Attributes)
 OS << " " << A.getKey() << "=\"" << A.getValue() << "\"";
-  if (SelfClosing) {
+  if (Tag.IsSelfClosing()) {
 OS << "/>";
 return;
   }
@@ -385,7 +361,7 @@ static std::unique_ptr genHTML
   } else if (I.Kind == "TextComment") {
 if (I.Text == "")
   return nullptr;
-return llvm::make_unique(I.Text, true);
+return llvm::make_unique(I.Text);
   }
   return nullptr;
 }

Modified: clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp?rev=367050=367049=367050=diff
==
--- clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp (original)
+++ clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp Thu Jul 
25 13:49:00 2019
@@ -56,9 +56,7 @@ TEST(HTMLGeneratorTest, emitNamespaceHTM
   Functions
   
 OneFunction
-
-  OneFunction()
-
+ 

[PATCH] D64883: Add new warning -Walloca for use of builtin alloca function

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

LGTM, thank you for the patch!


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

https://reviews.llvm.org/D64883



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


[PATCH] D64938: [clang-doc] Add option for user provided stylesheets

2019-07-25 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett accepted this revision.
juliehockett added a comment.
This revision is now accepted and ready to land.

LGTM


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

https://reviews.llvm.org/D64938



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


r367055 - Revert "Revert "CodeGen: ensure placeholder instruction for cleanup is created""

2019-07-25 Thread Saleem Abdulrasool via cfe-commits
Author: compnerd
Date: Thu Jul 25 13:59:48 2019
New Revision: 367055

URL: http://llvm.org/viewvc/llvm-project?rev=367055=rev
Log:
Revert "Revert "CodeGen: ensure placeholder instruction for cleanup is created""

This reverts commit fd1274fa78cb0fd32cc1fa2e6f5bb8e62d29df19.

Add an explicit triple for the test which is pattern matching overly
aggressively.

Added:
cfe/trunk/test/CodeGenCXX/pr40771-ctad-with-lambda-copy-capture.cpp
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=367055=367054=367055=diff
==
--- cfe/trunk/lib/CodeGen/CGExprAgg.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprAgg.cpp Thu Jul 25 13:59:48 2019
@@ -1495,6 +1495,13 @@ void AggExprEmitter::VisitInitListExpr(I
   // initializers throws an exception.
   SmallVector cleanups;
   llvm::Instruction *cleanupDominator = nullptr;
+  auto addCleanup = [&](const EHScopeStack::stable_iterator ) {
+cleanups.push_back(cleanup);
+if (!cleanupDominator) // create placeholder once needed
+  cleanupDominator = CGF.Builder.CreateAlignedLoad(
+  CGF.Int8Ty, llvm::Constant::getNullValue(CGF.Int8PtrTy),
+  CharUnits::One());
+  };
 
   unsigned curInitIndex = 0;
 
@@ -1519,7 +1526,7 @@ void AggExprEmitter::VisitInitListExpr(I
   if (QualType::DestructionKind dtorKind =
   Base.getType().isDestructedType()) {
 CGF.pushDestroy(dtorKind, V, Base.getType());
-cleanups.push_back(CGF.EHStack.stable_begin());
+addCleanup(CGF.EHStack.stable_begin());
   }
 }
   }
@@ -1596,15 +1603,9 @@ void AggExprEmitter::VisitInitListExpr(I
   = field->getType().isDestructedType()) {
   assert(LV.isSimple());
   if (CGF.needsEHCleanup(dtorKind)) {
-if (!cleanupDominator)
-  cleanupDominator = CGF.Builder.CreateAlignedLoad(
-  CGF.Int8Ty,
-  llvm::Constant::getNullValue(CGF.Int8PtrTy),
-  CharUnits::One()); // placeholder
-
 CGF.pushDestroy(EHCleanup, LV.getAddress(), field->getType(),
 CGF.getDestroyer(dtorKind), false);
-cleanups.push_back(CGF.EHStack.stable_begin());
+addCleanup(CGF.EHStack.stable_begin());
 pushedCleanup = true;
   }
 }
@@ -1620,6 +1621,8 @@ void AggExprEmitter::VisitInitListExpr(I
 
   // Deactivate all the partial cleanups in reverse order, which
   // generally means popping them.
+  assert((cleanupDominator || cleanups.empty()) &&
+ "Missing cleanupDominator before deactivating cleanup blocks");
   for (unsigned i = cleanups.size(); i != 0; --i)
 CGF.DeactivateCleanupBlock(cleanups[i-1], cleanupDominator);
 

Added: cfe/trunk/test/CodeGenCXX/pr40771-ctad-with-lambda-copy-capture.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/pr40771-ctad-with-lambda-copy-capture.cpp?rev=367055=auto
==
--- cfe/trunk/test/CodeGenCXX/pr40771-ctad-with-lambda-copy-capture.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/pr40771-ctad-with-lambda-copy-capture.cpp Thu Jul 
25 13:59:48 2019
@@ -0,0 +1,55 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm --std=c++17 
-fcxx-exceptions -fexceptions -discard-value-names %s -o - | FileCheck %s
+
+struct Q { Q(); };
+struct R { R(Q); ~R(); };
+struct S { S(Q); ~S(); };
+struct T : R, S {};
+
+Q q;
+T t { R{q}, S{q} };
+
+// CHECK-LABEL: define internal void @__cxx_global_var_init.1() {{.*}} {
+// CHECK-NEXT: [[TMP_R:%[a-z0-9.]+]] = alloca %struct.R, align 1
+// CHECK-NEXT: [[TMP_Q1:%[a-z0-9.]+]] = alloca %struct.Q, align 1
+// CHECK-NEXT: [[TMP_S:%[a-z0-9.]+]] = alloca %struct.S, align 1
+// CHECK-NEXT: [[TMP_Q2:%[a-z0-9.]+]] = alloca %struct.Q, align 1
+// CHECK-NEXT: [[XPT:%[a-z0-9.]+]] = alloca i8*
+// CHECK-NEXT: [[SLOT:%[a-z0-9.]+]] = alloca i32
+// CHECK-NEXT: [[ACTIVE:%[a-z0-9.]+]] = alloca i1, align 1
+// CHECK-NEXT: call void @_ZN1RC1E1Q(%struct.R* [[TMP_R]])
+// CHECK-NEXT: store i1 true, i1* [[ACTIVE]], align 1
+// CHECK-NEXT: invoke void @_ZN1SC1E1Q(%struct.S* [[TMP_S]])
+// CHECK-NEXT:   to label %[[L1:[a-z0-9.]+]] unwind label %[[L2:[a-z0-9.]+]]
+// CHECK-EMPTY:
+// CHECK-NEXT: [[L1]]:
+// CHECK-NEXT: store i1 false, i1* [[ACTIVE]], align 1
+// CHECK-NEXT: call void @_ZN1SD1Ev(%struct.S*
+// CHECK-NEXT: call void @_ZN1RD1Ev(%struct.R*
+// CHECK-NEXT: [[EXIT:%[a-z0-9.]+]] = call i32 @__cxa_atexit(
+// CHECK-NEXT: ret void
+// CHECK-EMPTY:
+// CHECK-NEXT: [[L2]]:
+// CHECK-NEXT: [[LP:%[a-z0-9.]+]] = landingpad { i8*, i32 }
+// CHECK-NEXT:  cleanup
+// CHECK-NEXT: [[X1:%[a-z0-9.]+]] = extractvalue { i8*, i32 } [[LP]], 0
+// CHECK-NEXT: store i8* [[X1]], i8** [[XPT]], align 8
+// CHECK-NEXT: [[X2:%[a-z0-9.]+]] = extractvalue { i8*, i32 } [[LP]], 1
+// CHECK-NEXT: store 

[PATCH] D64883: Add new warning -Walloca for use of builtin alloca function

2019-07-25 Thread Elaina Guan via Phabricator via cfe-commits
ziyig updated this revision to Diff 211816.
ziyig marked an inline comment as done.

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

https://reviews.llvm.org/D64883

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaChecking.cpp
  clang/test/Sema/warn-alloca.c


Index: clang/test/Sema/warn-alloca.c
===
--- /dev/null
+++ clang/test/Sema/warn-alloca.c
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -DSILENCE -fsyntax-only -verify -Wall %s
+// RUN: %clang_cc1 -fsyntax-only -verify -Walloca %s
+
+#ifdef SILENCE
+  // expected-no-diagnostics
+#endif
+
+void test1(int a) {
+  __builtin_alloca(a);
+#ifndef SILENCE
+  // expected-warning@-2 {{use of function '__builtin_alloca' is discouraged; 
there is no way to check for failure but failure may still occur, resulting in 
a possibly exploitable security vulnerability}}
+#endif
+}
+
+void test2(int a) {
+  __builtin_alloca_with_align(a, 32);
+#ifndef SILENCE
+  // expected-warning@-2 {{use of function '__builtin_alloca_with_align' is 
discouraged; there is no way to check for failure but failure may still occur, 
resulting in a possibly exploitable security vulnerability}}
+#endif
+}
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -1169,6 +1169,10 @@
   case Builtin::BI__builtin_alloca_with_align:
 if (SemaBuiltinAllocaWithAlign(TheCall))
   return ExprError();
+LLVM_FALLTHROUGH;
+  case Builtin::BI__builtin_alloca:
+Diag(TheCall->getBeginLoc(), diag::warn_alloca)
+<< TheCall->getDirectCallee();
 break;
   case Builtin::BI__assume:
   case Builtin::BI__builtin_assume:
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -2772,6 +2772,11 @@
 def err_cannot_find_suitable_accessor : Error<
   "cannot find suitable %select{getter|setter}0 for property %1">;
 
+def warn_alloca : Warning<
+  "use of function %0 is discouraged; there is no way to check for failure but 
"
+  "failure may still occur, resulting in a possibly exploitable security 
vulnerability">,
+  InGroup>, DefaultIgnore;
+
 def warn_alloca_align_alignof : Warning<
   "second argument to __builtin_alloca_with_align is supposed to be in bits">,
   InGroup>;


Index: clang/test/Sema/warn-alloca.c
===
--- /dev/null
+++ clang/test/Sema/warn-alloca.c
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -DSILENCE -fsyntax-only -verify -Wall %s
+// RUN: %clang_cc1 -fsyntax-only -verify -Walloca %s
+
+#ifdef SILENCE
+  // expected-no-diagnostics
+#endif
+
+void test1(int a) {
+  __builtin_alloca(a);
+#ifndef SILENCE
+  // expected-warning@-2 {{use of function '__builtin_alloca' is discouraged; there is no way to check for failure but failure may still occur, resulting in a possibly exploitable security vulnerability}}
+#endif
+}
+
+void test2(int a) {
+  __builtin_alloca_with_align(a, 32);
+#ifndef SILENCE
+  // expected-warning@-2 {{use of function '__builtin_alloca_with_align' is discouraged; there is no way to check for failure but failure may still occur, resulting in a possibly exploitable security vulnerability}}
+#endif
+}
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -1169,6 +1169,10 @@
   case Builtin::BI__builtin_alloca_with_align:
 if (SemaBuiltinAllocaWithAlign(TheCall))
   return ExprError();
+LLVM_FALLTHROUGH;
+  case Builtin::BI__builtin_alloca:
+Diag(TheCall->getBeginLoc(), diag::warn_alloca)
+<< TheCall->getDirectCallee();
 break;
   case Builtin::BI__assume:
   case Builtin::BI__builtin_assume:
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -2772,6 +2772,11 @@
 def err_cannot_find_suitable_accessor : Error<
   "cannot find suitable %select{getter|setter}0 for property %1">;
 
+def warn_alloca : Warning<
+  "use of function %0 is discouraged; there is no way to check for failure but "
+  "failure may still occur, resulting in a possibly exploitable security vulnerability">,
+  InGroup>, DefaultIgnore;
+
 def warn_alloca_align_alignof : Warning<
   "second argument to __builtin_alloca_with_align is supposed to be in bits">,
   InGroup>;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r367053 - Reland the "[NewPM] Port Sancov" patch from rL365838. No functional

2019-07-25 Thread Leonard Chan via cfe-commits
Author: leonardchan
Date: Thu Jul 25 13:53:15 2019
New Revision: 367053

URL: http://llvm.org/viewvc/llvm-project?rev=367053=rev
Log:
Reland the "[NewPM] Port Sancov" patch from rL365838. No functional
changes were made to the patch since then.



[NewPM] Port Sancov

This patch contains a port of SanitizerCoverage to the new pass manager. This 
one's a bit hefty.

Changes:

- Split SanitizerCoverageModule into 2 SanitizerCoverage for passing over
  functions and ModuleSanitizerCoverage for passing over modules.
- ModuleSanitizerCoverage exists for adding 2 module level calls to 
initialization
  functions but only if there's a function that was instrumented by sancov.
- Added legacy and new PM wrapper classes that own instances of the 2 new 
classes.
- Update llvm tests and add clang tests.

Added:
cfe/trunk/test/CodeGen/sancov-new-pm.c
Modified:
cfe/trunk/lib/CodeGen/BackendUtil.cpp

Modified: cfe/trunk/lib/CodeGen/BackendUtil.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/BackendUtil.cpp?rev=367053=367052=367053=diff
==
--- cfe/trunk/lib/CodeGen/BackendUtil.cpp (original)
+++ cfe/trunk/lib/CodeGen/BackendUtil.cpp Thu Jul 25 13:53:15 2019
@@ -60,6 +60,7 @@
 #include "llvm/Transforms/Instrumentation/HWAddressSanitizer.h"
 #include "llvm/Transforms/Instrumentation/InstrProfiling.h"
 #include "llvm/Transforms/Instrumentation/MemorySanitizer.h"
+#include "llvm/Transforms/Instrumentation/SanitizerCoverage.h"
 #include "llvm/Transforms/Instrumentation/ThreadSanitizer.h"
 #include "llvm/Transforms/ObjCARC.h"
 #include "llvm/Transforms/Scalar.h"
@@ -195,11 +196,8 @@ static void addBoundsCheckingPass(const
   PM.add(createBoundsCheckingLegacyPass());
 }
 
-static void addSanitizerCoveragePass(const PassManagerBuilder ,
- legacy::PassManagerBase ) {
-  const PassManagerBuilderWrapper  =
-  static_cast(Builder);
-  const CodeGenOptions  = BuilderWrapper.getCGOpts();
+static SanitizerCoverageOptions
+getSancovOptsFromCGOpts(const CodeGenOptions ) {
   SanitizerCoverageOptions Opts;
   Opts.CoverageType =
   static_cast(CGOpts.SanitizeCoverageType);
@@ -215,7 +213,17 @@ static void addSanitizerCoveragePass(con
   Opts.Inline8bitCounters = CGOpts.SanitizeCoverageInline8bitCounters;
   Opts.PCTable = CGOpts.SanitizeCoveragePCTable;
   Opts.StackDepth = CGOpts.SanitizeCoverageStackDepth;
-  PM.add(createSanitizerCoverageModulePass(Opts));
+  return Opts;
+}
+
+static void addSanitizerCoveragePass(const PassManagerBuilder ,
+ legacy::PassManagerBase ) {
+  const PassManagerBuilderWrapper  =
+  static_cast(Builder);
+  const CodeGenOptions  = BuilderWrapper.getCGOpts();
+  auto Opts = getSancovOptsFromCGOpts(CGOpts);
+  PM.add(createModuleSanitizerCoverageLegacyPassPass(Opts));
+  PM.add(createSanitizerCoverageLegacyPassPass(Opts));
 }
 
 // Check if ASan should use GC-friendly instrumentation for globals.
@@ -1128,6 +1136,21 @@ void EmitAssemblyHelper::EmitAssemblyWit
 EntryExitInstrumenterPass(/*PostInlining=*/false)));
   });
 
+  if (CodeGenOpts.SanitizeCoverageType ||
+  CodeGenOpts.SanitizeCoverageIndirectCalls ||
+  CodeGenOpts.SanitizeCoverageTraceCmp) {
+auto SancovOpts = getSancovOptsFromCGOpts(CodeGenOpts);
+PB.registerPipelineStartEPCallback(
+[SancovOpts](ModulePassManager ) {
+  MPM.addPass(ModuleSanitizerCoveragePass(SancovOpts));
+});
+PB.registerOptimizerLastEPCallback(
+[SancovOpts](FunctionPassManager ,
+ PassBuilder::OptimizationLevel Level) {
+  FPM.addPass(SanitizerCoveragePass(SancovOpts));
+});
+  }
+
   // Register callbacks to schedule sanitizer passes at the appropriate 
part of
   // the pipeline.
   // FIXME: either handle asan/the remaining sanitizers or error out
@@ -1205,8 +1228,18 @@ void EmitAssemblyHelper::EmitAssemblyWit
   /*CompileKernel=*/true, /*Recover=*/true));
 }
 
-if (CodeGenOpts.OptimizationLevel == 0)
+if (CodeGenOpts.OptimizationLevel == 0) {
+  if (CodeGenOpts.SanitizeCoverageType ||
+  CodeGenOpts.SanitizeCoverageIndirectCalls ||
+  CodeGenOpts.SanitizeCoverageTraceCmp) {
+auto SancovOpts = getSancovOptsFromCGOpts(CodeGenOpts);
+MPM.addPass(ModuleSanitizerCoveragePass(SancovOpts));
+MPM.addPass(createModuleToFunctionPassAdaptor(
+SanitizerCoveragePass(SancovOpts)));
+  }
+
   addSanitizersAtO0(MPM, TargetTriple, LangOpts, CodeGenOpts);
+}
   }
 
   // FIXME: We still use the legacy pass manager to do code generation. We

Added: cfe/trunk/test/CodeGen/sancov-new-pm.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/sancov-new-pm.c?rev=367053=auto

[PATCH] D65005: [clang-doc] Fix output format of html

2019-07-25 Thread Diego Astiazarán via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL367050: [clang-doc] Fix output format of html (authored by 
DiegoAstiazaran, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D65005?vs=211812=211814#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D65005

Files:
  clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp
  clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp

Index: clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp
===
--- clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp
+++ clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp
@@ -56,9 +56,7 @@
   Functions
   
 OneFunction
-
-  OneFunction()
-
+OneFunction()
   
   Enums
   
@@ -107,9 +105,7 @@
 class r
 
   class r
-  
-Defined at line 10 of test.cpp
-  
+  Defined at line 10 of test.cpp
   
 Inherits from 
 
   Members
   
-private int X
+
+  private 
+  int
+   X
+
   
   Records
   
@@ -128,9 +128,7 @@
   Functions
   
 OneFunction
-
-  OneFunction()
-
+OneFunction()
   
   Enums
   
@@ -180,9 +178,7 @@
  R"raw(">int
  P)
   
-  
-Defined at line 10 of test.cpp
-  
+  Defined at line 10 of test.cpp
 
 )raw";
 
@@ -214,9 +210,7 @@
   
 X
   
-  
-Defined at line 10 of test.cpp
-  
+  Defined at line 10 of test.cpp
 
 )raw";
 
@@ -280,23 +274,13 @@
 
 
   f
-  
-void f(int I, int J)
-  
-  
-Defined at line 10 of test.cpp
-  
+  void f(int I, int J)
+  Defined at line 10 of test.cpp
   
 
-  
- Brief description.
-  
-  
- Extended description that continues onto the next line.
-  
-  
- Comment with html entities: , , , , .
-  
+   Brief description.
+   Extended description that continues onto the next line.
+   Comment with html entities: , , , , .
 
   
 
Index: clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp
===
--- clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp
+++ clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp
@@ -44,9 +44,6 @@
   operator bool() = delete;
 
   bool IsSelfClosing() const;
-
-  bool HasInlineChildren() const;
-
   llvm::SmallString<16> ToString() const;
 
 private:
@@ -67,29 +64,20 @@
 };
 
 struct TextNode : public HTMLNode {
-  TextNode(const Twine , bool Indented = true)
-  : HTMLNode(NodeType::NODE_TEXT), Text(Text.str()), Indented(Indented) {}
+  TextNode(const Twine )
+  : HTMLNode(NodeType::NODE_TEXT), Text(Text.str()) {}
 
   std::string Text; // Content of node
-  bool Indented; // Indicates if an indentation must be rendered before the text
   void Render(llvm::raw_ostream , int IndentationLevel) override;
 };
 
 struct TagNode : public HTMLNode {
-  TagNode(HTMLTag Tag)
-  : HTMLNode(NodeType::NODE_TAG), Tag(Tag),
-InlineChildren(Tag.HasInlineChildren()),
-SelfClosing(Tag.IsSelfClosing()) {}
+  TagNode(HTMLTag Tag) : HTMLNode(NodeType::NODE_TAG), Tag(Tag) {}
   TagNode(HTMLTag Tag, const Twine ) : TagNode(Tag) {
-Children.emplace_back(
-llvm::make_unique(Text.str(), !InlineChildren));
+Children.emplace_back(llvm::make_unique(Text.str()));
   }
 
-  HTMLTag Tag; // Name of HTML Tag (p, div, h1)
-  bool InlineChildren; // Indicates if children nodes are rendered in the same
-   // line as itself or if children must rendered in the
-   // next line and with additional indentation
-  bool SelfClosing;// Indicates if tag is self-closing
+  HTMLTag Tag; // Name of HTML Tag (p, div, h1)
   std::vector> Children; // List of child nodes
   llvm::StringMap>
   Attributes; // List of key-value attributes for tag
@@ -130,24 +118,6 @@
   llvm_unreachable("Unhandled HTMLTag::TagType");
 }
 
-bool HTMLTag::HasInlineChildren() const {
-  switch (Value) {
-  case HTMLTag::TAG_META:
-  case HTMLTag::TAG_TITLE:
-  case HTMLTag::TAG_H1:
-  case HTMLTag::TAG_H2:
-  case HTMLTag::TAG_H3:
-  case HTMLTag::TAG_LI:
-  case HTMLTag::TAG_A:
-return true;
-  case HTMLTag::TAG_DIV:
-  case HTMLTag::TAG_P:
-  case HTMLTag::TAG_UL:
-return false;
-  }
-  llvm_unreachable("Unhandled HTMLTag::TagType");
-}
-
 llvm::SmallString<16> HTMLTag::ToString() const {
   switch (Value) {
   case HTMLTag::TAG_META:
@@ -175,17 +145,23 @@
 }
 
 void TextNode::Render(llvm::raw_ostream , int IndentationLevel) {
-  if (Indented)
-OS.indent(IndentationLevel * 2);
+  OS.indent(IndentationLevel * 2);
   printHTMLEscaped(Text, OS);
 }
 
 void TagNode::Render(llvm::raw_ostream , int IndentationLevel) {
+  // Children nodes are rendered in the same line if all of 

[PATCH] D65287: [analyzer][CFG] Don't track the condition of asserts

2019-07-25 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

I'm sure i've seen something with a do-while(0) loop. Let's also add the 
following:

  #define assert(x) do {\
if (!x) \
  __assert_fail (#expr, __FILE__, __LINE__, __func__)   \
  } while (0)




Comment at: clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp:1753-1755
+  // It so happens that CFGBlock::getTerminatorCondition returns 'A' for block
+  // B1, 'A && B' for B2, and 'A && B || C' for B3. Let's check whether we
+  // reached the end of the condition!

Clever trick, but why not match for logical operators directly? Something like 
this:
```lang=c++
if (auto B = dyn_cast(OuterCond))
  if (B->isLogicalOp())
return isAssertlikeBlock(Else, Context);
```



Comment at: clang/test/Analysis/track-control-dependency-conditions.cpp:469-471
+extern void __assert_fail (__const char *__assertion, __const char *__file,
+   unsigned int __line, __const char *__function)
+__attribute__ ((__noreturn__));

I'm pretty sure you can define this function only once.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D65287



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


[PATCH] D64656: Ensure placeholder instruction for cleanup is created

2019-07-25 Thread JF Bastien via Phabricator via cfe-commits
jfb reopened this revision.
jfb added a comment.
This revision is now accepted and ready to land.

Reverted in r367051, it's causing failures: 
http://lab.llvm.org:8011/builders/clang-cmake-armv8-full/builds/13658/steps/ninja%20check%201/logs/FAIL%3A%20Clang%3A%3Apr40771-ctad-with-lambda-copy-capture.cpp

  
/home/buildslave/buildslave/clang-cmake-armv8-full/llvm/tools/clang/test/CodeGenCXX/pr40771-ctad-with-lambda-copy-capture.cpp:20:16:
 error: CHECK-NEXT: expected string not found in input
  // CHECK-NEXT: call void @_ZN1RC1E1Q(%struct.R* [[TMP_R]])
 ^
  :37:2: note: scanning from here
   %8 = call %struct.R* @_ZN1RC1E1Q(%struct.R* %1)
   ^
  :37:2: note: with "TMP_R" equal to "%1"
   %8 = call %struct.R* @_ZN1RC1E1Q(%struct.R* %1)
   ^
  :37:17: note: possible intended match here
   %8 = call %struct.R* @_ZN1RC1E1Q(%struct.R* %1)
  ^


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64656



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


r367051 - Revert "CodeGen: ensure placeholder instruction for cleanup is created"

2019-07-25 Thread JF Bastien via cfe-commits
Author: jfb
Date: Thu Jul 25 13:50:09 2019
New Revision: 367051

URL: http://llvm.org/viewvc/llvm-project?rev=367051=rev
Log:
Revert "CodeGen: ensure placeholder instruction for cleanup is created"

Originally in https://reviews.llvm.org/D64656

Causes bot failures:

/home/buildslave/buildslave/clang-cmake-armv8-full/llvm/tools/clang/test/CodeGenCXX/pr40771-ctad-with-lambda-copy-capture.cpp:20:16:
 error: CHECK-NEXT: expected string not found in input
// CHECK-NEXT: call void @_ZN1RC1E1Q(%struct.R* [[TMP_R]])
   ^
:37:2: note: scanning from here
 %8 = call %struct.R* @_ZN1RC1E1Q(%struct.R* %1)
 ^
:37:2: note: with "TMP_R" equal to "%1"
 %8 = call %struct.R* @_ZN1RC1E1Q(%struct.R* %1)
 ^
:37:17: note: possible intended match here
 %8 = call %struct.R* @_ZN1RC1E1Q(%struct.R* %1)
^

Removed:
cfe/trunk/test/CodeGenCXX/pr40771-ctad-with-lambda-copy-capture.cpp
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=367051=367050=367051=diff
==
--- cfe/trunk/lib/CodeGen/CGExprAgg.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprAgg.cpp Thu Jul 25 13:50:09 2019
@@ -1495,13 +1495,6 @@ void AggExprEmitter::VisitInitListExpr(I
   // initializers throws an exception.
   SmallVector cleanups;
   llvm::Instruction *cleanupDominator = nullptr;
-  auto addCleanup = [&](const EHScopeStack::stable_iterator ) {
-cleanups.push_back(cleanup);
-if (!cleanupDominator) // create placeholder once needed
-  cleanupDominator = CGF.Builder.CreateAlignedLoad(
-  CGF.Int8Ty, llvm::Constant::getNullValue(CGF.Int8PtrTy),
-  CharUnits::One());
-  };
 
   unsigned curInitIndex = 0;
 
@@ -1526,7 +1519,7 @@ void AggExprEmitter::VisitInitListExpr(I
   if (QualType::DestructionKind dtorKind =
   Base.getType().isDestructedType()) {
 CGF.pushDestroy(dtorKind, V, Base.getType());
-addCleanup(CGF.EHStack.stable_begin());
+cleanups.push_back(CGF.EHStack.stable_begin());
   }
 }
   }
@@ -1603,9 +1596,15 @@ void AggExprEmitter::VisitInitListExpr(I
   = field->getType().isDestructedType()) {
   assert(LV.isSimple());
   if (CGF.needsEHCleanup(dtorKind)) {
+if (!cleanupDominator)
+  cleanupDominator = CGF.Builder.CreateAlignedLoad(
+  CGF.Int8Ty,
+  llvm::Constant::getNullValue(CGF.Int8PtrTy),
+  CharUnits::One()); // placeholder
+
 CGF.pushDestroy(EHCleanup, LV.getAddress(), field->getType(),
 CGF.getDestroyer(dtorKind), false);
-addCleanup(CGF.EHStack.stable_begin());
+cleanups.push_back(CGF.EHStack.stable_begin());
 pushedCleanup = true;
   }
 }
@@ -1621,8 +1620,6 @@ void AggExprEmitter::VisitInitListExpr(I
 
   // Deactivate all the partial cleanups in reverse order, which
   // generally means popping them.
-  assert((cleanupDominator || cleanups.empty()) &&
- "Missing cleanupDominator before deactivating cleanup blocks");
   for (unsigned i = cleanups.size(); i != 0; --i)
 CGF.DeactivateCleanupBlock(cleanups[i-1], cleanupDominator);
 

Removed: cfe/trunk/test/CodeGenCXX/pr40771-ctad-with-lambda-copy-capture.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/pr40771-ctad-with-lambda-copy-capture.cpp?rev=367050=auto
==
--- cfe/trunk/test/CodeGenCXX/pr40771-ctad-with-lambda-copy-capture.cpp 
(original)
+++ cfe/trunk/test/CodeGenCXX/pr40771-ctad-with-lambda-copy-capture.cpp 
(removed)
@@ -1,56 +0,0 @@
-// RUN: %clang_cc1 -emit-llvm --std=c++17 -fcxx-exceptions -fexceptions \
-// RUN:   -discard-value-names %s -o - | FileCheck %s
-
-struct Q { Q(); };
-struct R { R(Q); ~R(); };
-struct S { S(Q); ~S(); };
-struct T : R, S {};
-
-Q q;
-T t { R{q}, S{q} };
-
-// CHECK-LABEL: define internal void @__cxx_global_var_init.1() {{.*}} {
-// CHECK-NEXT: [[TMP_R:%[a-z0-9.]+]] = alloca %struct.R, align 1
-// CHECK-NEXT: [[TMP_Q1:%[a-z0-9.]+]] = alloca %struct.Q, align 1
-// CHECK-NEXT: [[TMP_S:%[a-z0-9.]+]] = alloca %struct.S, align 1
-// CHECK-NEXT: [[TMP_Q2:%[a-z0-9.]+]] = alloca %struct.Q, align 1
-// CHECK-NEXT: [[XPT:%[a-z0-9.]+]] = alloca i8*
-// CHECK-NEXT: [[SLOT:%[a-z0-9.]+]] = alloca i32
-// CHECK-NEXT: [[ACTIVE:%[a-z0-9.]+]] = alloca i1, align 1
-// CHECK-NEXT: call void @_ZN1RC1E1Q(%struct.R* [[TMP_R]])
-// CHECK-NEXT: store i1 true, i1* [[ACTIVE]], align 1
-// CHECK-NEXT: invoke void @_ZN1SC1E1Q(%struct.S* [[TMP_S]])
-// CHECK-NEXT:   to label %[[L1:[a-z0-9.]+]] unwind label %[[L2:[a-z0-9.]+]]
-// CHECK-EMPTY:
-// CHECK-NEXT: [[L1]]:
-// CHECK-NEXT: store i1 false, i1* [[ACTIVE]], align 1
-// CHECK-NEXT: call void @_ZN1SD1Ev(%struct.S*
-// CHECK-NEXT: call void @_ZN1RD1Ev(%struct.R*
-// CHECK-NEXT: 

[PATCH] D65005: [clang-doc] Fix output format of html

2019-07-25 Thread Diego Astiazarán via Phabricator via cfe-commits
DiegoAstiazaran updated this revision to Diff 211812.

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

https://reviews.llvm.org/D65005

Files:
  clang-tools-extra/clang-doc/HTMLGenerator.cpp
  clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp

Index: clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
+++ clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
@@ -56,9 +56,7 @@
   Functions
   
 OneFunction
-
-  OneFunction()
-
+OneFunction()
   
   Enums
   
@@ -107,9 +105,7 @@
 class r
 
   class r
-  
-Defined at line 10 of test.cpp
-  
+  Defined at line 10 of test.cpp
   
 Inherits from 
 
   Members
   
-private int X
+
+  private 
+  int
+   X
+
   
   Records
   
@@ -128,9 +128,7 @@
   Functions
   
 OneFunction
-
-  OneFunction()
-
+OneFunction()
   
   Enums
   
@@ -180,9 +178,7 @@
  R"raw(">int
  P)
   
-  
-Defined at line 10 of test.cpp
-  
+  Defined at line 10 of test.cpp
 
 )raw";
 
@@ -214,9 +210,7 @@
   
 X
   
-  
-Defined at line 10 of test.cpp
-  
+  Defined at line 10 of test.cpp
 
 )raw";
 
@@ -280,23 +274,13 @@
 
 
   f
-  
-void f(int I, int J)
-  
-  
-Defined at line 10 of test.cpp
-  
+  void f(int I, int J)
+  Defined at line 10 of test.cpp
   
 
-  
- Brief description.
-  
-  
- Extended description that continues onto the next line.
-  
-  
- Comment with html entities: , , , , .
-  
+   Brief description.
+   Extended description that continues onto the next line.
+   Comment with html entities: , , , , .
 
   
 
Index: clang-tools-extra/clang-doc/HTMLGenerator.cpp
===
--- clang-tools-extra/clang-doc/HTMLGenerator.cpp
+++ clang-tools-extra/clang-doc/HTMLGenerator.cpp
@@ -44,9 +44,6 @@
   operator bool() = delete;
 
   bool IsSelfClosing() const;
-
-  bool HasInlineChildren() const;
-
   llvm::SmallString<16> ToString() const;
 
 private:
@@ -67,29 +64,20 @@
 };
 
 struct TextNode : public HTMLNode {
-  TextNode(const Twine , bool Indented = true)
-  : HTMLNode(NodeType::NODE_TEXT), Text(Text.str()), Indented(Indented) {}
+  TextNode(const Twine )
+  : HTMLNode(NodeType::NODE_TEXT), Text(Text.str()) {}
 
   std::string Text; // Content of node
-  bool Indented; // Indicates if an indentation must be rendered before the text
   void Render(llvm::raw_ostream , int IndentationLevel) override;
 };
 
 struct TagNode : public HTMLNode {
-  TagNode(HTMLTag Tag)
-  : HTMLNode(NodeType::NODE_TAG), Tag(Tag),
-InlineChildren(Tag.HasInlineChildren()),
-SelfClosing(Tag.IsSelfClosing()) {}
+  TagNode(HTMLTag Tag) : HTMLNode(NodeType::NODE_TAG), Tag(Tag) {}
   TagNode(HTMLTag Tag, const Twine ) : TagNode(Tag) {
-Children.emplace_back(
-llvm::make_unique(Text.str(), !InlineChildren));
+Children.emplace_back(llvm::make_unique(Text.str()));
   }
 
-  HTMLTag Tag; // Name of HTML Tag (p, div, h1)
-  bool InlineChildren; // Indicates if children nodes are rendered in the same
-   // line as itself or if children must rendered in the
-   // next line and with additional indentation
-  bool SelfClosing;// Indicates if tag is self-closing
+  HTMLTag Tag; // Name of HTML Tag (p, div, h1)
   std::vector> Children; // List of child nodes
   llvm::StringMap>
   Attributes; // List of key-value attributes for tag
@@ -130,24 +118,6 @@
   llvm_unreachable("Unhandled HTMLTag::TagType");
 }
 
-bool HTMLTag::HasInlineChildren() const {
-  switch (Value) {
-  case HTMLTag::TAG_META:
-  case HTMLTag::TAG_TITLE:
-  case HTMLTag::TAG_H1:
-  case HTMLTag::TAG_H2:
-  case HTMLTag::TAG_H3:
-  case HTMLTag::TAG_LI:
-  case HTMLTag::TAG_A:
-return true;
-  case HTMLTag::TAG_DIV:
-  case HTMLTag::TAG_P:
-  case HTMLTag::TAG_UL:
-return false;
-  }
-  llvm_unreachable("Unhandled HTMLTag::TagType");
-}
-
 llvm::SmallString<16> HTMLTag::ToString() const {
   switch (Value) {
   case HTMLTag::TAG_META:
@@ -175,17 +145,23 @@
 }
 
 void TextNode::Render(llvm::raw_ostream , int IndentationLevel) {
-  if (Indented)
-OS.indent(IndentationLevel * 2);
+  OS.indent(IndentationLevel * 2);
   printHTMLEscaped(Text, OS);
 }
 
 void TagNode::Render(llvm::raw_ostream , int IndentationLevel) {
+  // Children nodes are rendered in the same line if all of them are text nodes
+  bool InlineChildren = true;
+  for (const auto  : Children)
+if (C->Type == NodeType::NODE_TAG) {
+  InlineChildren = false;
+  break;
+}
   OS.indent(IndentationLevel * 2);
   OS << "<" << Tag.ToString();
   for (const auto  : Attributes)
 OS << " " << A.getKey() << "=\"" << A.getValue() << "\"";
-  if 

[PATCH] D65234: [CodeGen]: don't treat structures returned in registers as memory inputs

2019-07-25 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added inline comments.



Comment at: clang/lib/CodeGen/CGStmt.cpp:2287
   assert(RegResults.size() == ResultRegDests.size());
+  assert(ResultTypeRequiresCast.size() <= ResultRegDests.size());
   for (unsigned i = 0, e = RegResults.size(); i != e; ++i) {

Not "=="?



Comment at: clang/lib/CodeGen/CGStmt.cpp:2325
+  Dest = MakeAddrLValue(
+  A, getContext().getIntTypeForBitwidth(Size, /*Signed*/ false));
+}

Will this work if the struct is an unusual size, like `sizeof(struct s) == 3` 
or `sizeof(struct s) == 32`?  (3 is unlikely to show up in real code, but 32 
could correspond to a vector register.)



Comment at: clang/test/CodeGen/PR42672.c:2
+// RUN: %clang_cc1 -DSTRUCT -O2 -emit-llvm %s -o - | FileCheck %s
+// RUN: %clang_cc1 -USTRUCT -O2 -emit-llvm %s -o - | FileCheck %s
+//

We usually try to avoid tests that run "-O2"; it's simpler to just check the 
unoptimized clang output directly.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D65234



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


[PATCH] D65290: [analyzer][NFC] Prove that we only track the evaluated part of the condition

2019-07-25 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ accepted this revision.
NoQ added a comment.
This revision is now accepted and ready to land.

Just as planned!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D65290



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


[PATCH] D64883: Add new warning -Walloca for use of builtin alloca function

2019-07-25 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman marked an inline comment as done.
aaron.ballman added inline comments.



Comment at: clang/lib/Sema/SemaChecking.cpp:1172
   return ExprError();
+LLVM_FALLTHROUGH;
+  case Builtin::BI__builtin_alloca:

ziyig wrote:
> aaron.ballman wrote:
> > Do we want to warn on all uses of alloca(), or just the ones that get past 
> > the call to `SemaBuiltinAllocaWithAlign()`?
> I don't have strong opinion about this. Which one do you think is better?
I think the code is fine as-is. `SemaBuiltinAllocaWithAlign()` returns true 
when there's an error with the call, and so users will not get the warning only 
if the call is erroneous, which seems fine given that the code didn't compile. 
It turns out this matches GCC's behavior as well.



Comment at: clang/lib/Sema/SemaChecking.cpp:1175
+Diag(TheCall->getBeginLoc(), diag::warn_alloca)
+<< TheCall->getDirectCallee()->getNameInfo().getAsString();
 break;

You should pass in `TheCall->getDirectCallee()` and not try to get the name 
directly; the diagnostics engine will do the right thing automatically.


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

https://reviews.llvm.org/D64883



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


[PATCH] D65107: [clang-doc] Fix html entities in rendered text

2019-07-25 Thread Diego Astiazarán via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL367045: [clang-doc] Fix html entities in rendered text 
(authored by DiegoAstiazaran, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D65107?vs=211201=211806#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D65107

Files:
  clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp
  clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp


Index: clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp
===
--- clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp
+++ clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp
@@ -258,6 +258,15 @@
   Extended->Children.back()->Kind = "TextComment";
   Extended->Children.back()->Text = " continues onto the next line.";
 
+  Top.Children.emplace_back(llvm::make_unique());
+  CommentInfo *Entities = Top.Children.back().get();
+  Entities->Kind = "ParagraphComment";
+  Entities->Children.emplace_back(llvm::make_unique());
+  Entities->Children.back()->Kind = "TextComment";
+  Entities->Children.back()->Name = "ParagraphComment";
+  Entities->Children.back()->Text =
+  " Comment with html entities: &, <, >, \", \'.";
+
   I.Description.emplace_back(std::move(Top));
 
   auto G = getHTMLGenerator();
@@ -285,6 +294,9 @@
   
  Extended description that continues onto the next line.
   
+  
+ Comment with html entities: , , , , .
+  
 
   
 
Index: clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp
===
--- clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp
+++ clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp
@@ -8,6 +8,7 @@
 
 #include "Generators.h"
 #include "Representation.h"
+#include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
@@ -176,7 +177,7 @@
 void TextNode::Render(llvm::raw_ostream , int IndentationLevel) {
   if (Indented)
 OS.indent(IndentationLevel * 2);
-  OS << Text;
+  printHTMLEscaped(Text, OS);
 }
 
 void TagNode::Render(llvm::raw_ostream , int IndentationLevel) {


Index: clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp
===
--- clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp
+++ clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp
@@ -258,6 +258,15 @@
   Extended->Children.back()->Kind = "TextComment";
   Extended->Children.back()->Text = " continues onto the next line.";
 
+  Top.Children.emplace_back(llvm::make_unique());
+  CommentInfo *Entities = Top.Children.back().get();
+  Entities->Kind = "ParagraphComment";
+  Entities->Children.emplace_back(llvm::make_unique());
+  Entities->Children.back()->Kind = "TextComment";
+  Entities->Children.back()->Name = "ParagraphComment";
+  Entities->Children.back()->Text =
+  " Comment with html entities: &, <, >, \", \'.";
+
   I.Description.emplace_back(std::move(Top));
 
   auto G = getHTMLGenerator();
@@ -285,6 +294,9 @@
   
  Extended description that continues onto the next line.
   
+  
+ Comment with html entities: , , , , .
+  
 
   
 
Index: clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp
===
--- clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp
+++ clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp
@@ -8,6 +8,7 @@
 
 #include "Generators.h"
 #include "Representation.h"
+#include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
@@ -176,7 +177,7 @@
 void TextNode::Render(llvm::raw_ostream , int IndentationLevel) {
   if (Indented)
 OS.indent(IndentationLevel * 2);
-  OS << Text;
+  printHTMLEscaped(Text, OS);
 }
 
 void TagNode::Render(llvm::raw_ostream , int IndentationLevel) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r367045 - [clang-doc] Fix html entities in rendered text

2019-07-25 Thread Diego Astiazaran via cfe-commits
Author: diegoastiazaran
Date: Thu Jul 25 13:14:45 2019
New Revision: 367045

URL: http://llvm.org/viewvc/llvm-project?rev=367045=rev
Log:
[clang-doc] Fix html entities in rendered text

Replace &, <, >, ", and ' with their corresponding html entities in text 
rendered
by HTML generator.

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

Modified:
clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp
clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp

Modified: clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp?rev=367045=367044=367045=diff
==
--- clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp (original)
+++ clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp Thu Jul 25 13:14:45 2019
@@ -8,6 +8,7 @@
 
 #include "Generators.h"
 #include "Representation.h"
+#include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
@@ -176,7 +177,7 @@ llvm::SmallString<16> HTMLTag::ToString(
 void TextNode::Render(llvm::raw_ostream , int IndentationLevel) {
   if (Indented)
 OS.indent(IndentationLevel * 2);
-  OS << Text;
+  printHTMLEscaped(Text, OS);
 }
 
 void TagNode::Render(llvm::raw_ostream , int IndentationLevel) {

Modified: clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp?rev=367045=367044=367045=diff
==
--- clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp (original)
+++ clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp Thu Jul 
25 13:14:45 2019
@@ -258,6 +258,15 @@ TEST(HTMLGeneratorTest, emitCommentHTML)
   Extended->Children.back()->Kind = "TextComment";
   Extended->Children.back()->Text = " continues onto the next line.";
 
+  Top.Children.emplace_back(llvm::make_unique());
+  CommentInfo *Entities = Top.Children.back().get();
+  Entities->Kind = "ParagraphComment";
+  Entities->Children.emplace_back(llvm::make_unique());
+  Entities->Children.back()->Kind = "TextComment";
+  Entities->Children.back()->Name = "ParagraphComment";
+  Entities->Children.back()->Text =
+  " Comment with html entities: &, <, >, \", \'.";
+
   I.Description.emplace_back(std::move(Top));
 
   auto G = getHTMLGenerator();
@@ -285,6 +294,9 @@ TEST(HTMLGeneratorTest, emitCommentHTML)
   
  Extended description that continues onto the next line.
   
+  
+ Comment with html entities: , , , , .
+  
 
   
 


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


[PATCH] D65256: [Sema][ObjC] Mark C union fields that have non-trivial ObjC ownership qualifications as unavailable if the union is declared in a system header

2019-07-25 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

In D65256#1601510 , @jordan_rose wrote:

> In D65256#1601509 , @rjmccall wrote:
>
> > Sorry, am I missing something?  Such a union would've been either 
> > ill-formed or unavailable in ARC (depending on where it was declared) 
> > before this recent work.
>
>
> Apparently that was not the case if it was in a system header. Instead, Clang 
> marked the //member// unavailable rather than the entire union.


Ah, that's unfortunate.  It also just seems like a bug.

I guess my questions are whether we're fixing a specific source-compatibility 
problem here and, if so, whether this is the only reasonable approach for 
solving it.


Repository:
  rC Clang

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

https://reviews.llvm.org/D65256



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


[PATCH] D65256: [Sema][ObjC] Mark C union fields that have non-trivial ObjC ownership qualifications as unavailable if the union is declared in a system header

2019-07-25 Thread Jordan Rose via Phabricator via cfe-commits
jordan_rose added a comment.

In D65256#1601509 , @rjmccall wrote:

> Sorry, am I missing something?  Such a union would've been either ill-formed 
> or unavailable in ARC (depending on where it was declared) before this recent 
> work.


Apparently that was not the case if it was in a system header. Instead, Clang 
marked the //member// unavailable rather than the entire union.


Repository:
  rC Clang

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

https://reviews.llvm.org/D65256



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


[PATCH] D65294: Make the CXXABIs respect the target's default calling convention.

2019-07-25 Thread Erich Keane via Phabricator via cfe-commits
erichkeane created this revision.
erichkeane added a reviewer: Anastasia.

SPIR targets need to have all functions be SPIR calling convention,
however the CXXABIs were just returning CC_C in all non-'this-CC' cases.


https://reviews.llvm.org/D65294

Files:
  clang/lib/AST/ItaniumCXXABI.cpp
  clang/lib/AST/MicrosoftCXXABI.cpp
  clang/test/CodeGenOpenCLCXX/addrspace-derived-base.cl
  clang/test/CodeGenOpenCLCXX/addrspace-of-this.cl
  clang/test/CodeGenOpenCLCXX/addrspace-operators.cl
  clang/test/CodeGenOpenCLCXX/addrspace-with-class.cl
  clang/test/CodeGenOpenCLCXX/method-overload-address-space.cl
  clang/test/CodeGenOpenCLCXX/template-address-spaces.cl

Index: clang/test/CodeGenOpenCLCXX/template-address-spaces.cl
===
--- clang/test/CodeGenOpenCLCXX/template-address-spaces.cl
+++ clang/test/CodeGenOpenCLCXX/template-address-spaces.cl
@@ -14,11 +14,11 @@
 // CHECK: %struct.S.1 = type { i32 addrspace(1)* }
 
 // CHECK:  [[A1:%[.a-z0-9]+]] = addrspacecast %struct.S* %{{[a-z0-9]+}} to %struct.S addrspace(4)*
-// CHECK:  %call = call i32 @_ZNU3AS41SIiE3fooEv(%struct.S addrspace(4)* [[A1]]) #1
+// CHECK:  %call = call spir_func i32 @_ZNU3AS41SIiE3fooEv(%struct.S addrspace(4)* [[A1]]) #1
 // CHECK:  [[A2:%[.a-z0-9]+]] = addrspacecast %struct.S.0* %{{[a-z0-9]+}} to %struct.S.0 addrspace(4)*
-// CHECK:  %call1 = call i32 addrspace(4)* @_ZNU3AS41SIPU3AS4iE3fooEv(%struct.S.0 addrspace(4)* [[A2]]) #1
+// CHECK:  %call1 = call spir_func i32 addrspace(4)* @_ZNU3AS41SIPU3AS4iE3fooEv(%struct.S.0 addrspace(4)* [[A2]]) #1
 // CHECK:  [[A3:%[.a-z0-9]+]] = addrspacecast %struct.S.1* %{{[a-z0-9]+}} to %struct.S.1 addrspace(4)*
-// CHECK:  %call2 = call i32 addrspace(1)* @_ZNU3AS41SIPU3AS1iE3fooEv(%struct.S.1 addrspace(4)* [[A3]]) #1
+// CHECK:  %call2 = call spir_func i32 addrspace(1)* @_ZNU3AS41SIPU3AS1iE3fooEv(%struct.S.1 addrspace(4)* [[A3]]) #1
 
 void bar(){
   S sint;
Index: clang/test/CodeGenOpenCLCXX/method-overload-address-space.cl
===
--- clang/test/CodeGenOpenCLCXX/method-overload-address-space.cl
+++ clang/test/CodeGenOpenCLCXX/method-overload-address-space.cl
@@ -15,21 +15,21 @@
   __global C _ref = c1;
   __global C *c_ptr;
 
-  // CHECK: call void @_ZNU3AS11C3fooEv(%struct.C addrspace(1)*
+  // CHECK: call spir_func void @_ZNU3AS11C3fooEv(%struct.C addrspace(1)*
   c1.foo();
-  // CHECK: call void @_ZNU3AS31C3fooEv(%struct.C addrspace(3)*
+  // CHECK: call spir_func void @_ZNU3AS31C3fooEv(%struct.C addrspace(3)*
   c2.foo();
-  // CHECK: call void @_ZNU3AS41C3fooEv(%struct.C addrspace(4)*
+  // CHECK: call spir_func void @_ZNU3AS41C3fooEv(%struct.C addrspace(4)*
   c3.foo();
-  // CHECK: call void @_ZNU3AS11C3fooEv(%struct.C addrspace(1)*
+  // CHECK: call spir_func void @_ZNU3AS11C3fooEv(%struct.C addrspace(1)*
   c_ptr->foo();
-  // CHECK: void @_ZNU3AS11C3fooEv(%struct.C addrspace(1)*
+  // CHECK: spir_func void @_ZNU3AS11C3fooEv(%struct.C addrspace(1)*
   c_ref.foo();
 
-  // CHECK: call void @_ZNU3AS41C3barEv(%struct.C addrspace(4)* addrspacecast (%struct.C addrspace(1)* @c1 to %struct.C addrspace(4)*))
+  // CHECK: call spir_func void @_ZNU3AS41C3barEv(%struct.C addrspace(4)* addrspacecast (%struct.C addrspace(1)* @c1 to %struct.C addrspace(4)*))
   c1.bar();
   //FIXME: Doesn't compile yet
   //c_ptr->bar();
-  // CHECK: call void @_ZNU3AS41C3barEv(%struct.C addrspace(4)* addrspacecast (%struct.C addrspace(1)* @c1 to %struct.C addrspace(4)*))
+  // CHECK: call spir_func void @_ZNU3AS41C3barEv(%struct.C addrspace(4)* addrspacecast (%struct.C addrspace(1)* @c1 to %struct.C addrspace(4)*))
   c_ref.bar();
 }
Index: clang/test/CodeGenOpenCLCXX/addrspace-with-class.cl
===
--- clang/test/CodeGenOpenCLCXX/addrspace-with-class.cl
+++ clang/test/CodeGenOpenCLCXX/addrspace-with-class.cl
@@ -23,17 +23,17 @@
 // CHECK: @glob = addrspace(1) global %struct.MyType zeroinitializer
 MyType glob(1);
 
-// CHECK: call void @_ZNU3AS26MyTypeC1Ei(%struct.MyType addrspace(2)* @const1, i32 1)
-// CHECK: call void @_ZNU3AS26MyTypeC1Ei(%struct.MyType addrspace(2)* @const2, i32 2)
-// CHECK: call void @_ZNU3AS46MyTypeC1Ei(%struct.MyType addrspace(4)* addrspacecast (%struct.MyType addrspace(1)* @glob to %struct.MyType addrspace(4)*), i32 1)
+// CHECK: call spir_func void @_ZNU3AS26MyTypeC1Ei(%struct.MyType addrspace(2)* @const1, i32 1)
+// CHECK: call spir_func void @_ZNU3AS26MyTypeC1Ei(%struct.MyType addrspace(2)* @const2, i32 2)
+// CHECK: call spir_func void @_ZNU3AS46MyTypeC1Ei(%struct.MyType addrspace(4)* addrspacecast (%struct.MyType addrspace(1)* @glob to %struct.MyType addrspace(4)*), i32 1)
 
 // CHECK-LABEL: define spir_kernel void @fooGlobal()
 kernel void fooGlobal() {
-  // CHECK: call i32 @_ZNU3AS46MyType3barEv(%struct.MyType addrspace(4)* addrspacecast (%struct.MyType addrspace(1)* @glob to %struct.MyType addrspace(4)*))
+  // 

[PATCH] D65256: [Sema][ObjC] Mark C union fields that have non-trivial ObjC ownership qualifications as unavailable if the union is declared in a system header

2019-07-25 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

In D65256#1601415 , @jordan_rose wrote:

> In D65256#1601410 , @rjmccall wrote:
>
> > These were unavailable in system headers before because otherwise we 
> > would've had to make them invalid.  Since these unions are no longer 
> > otherwise invalid, there shouldn't be a problem with allowing them in 
> > system headers, and in fact making the semantics vary that way seems quite 
> > problematic.  Now, specific *uses* in system headers might still appear to 
> > be invalid — e.g. an ObjC ivar of type `union { __strong id x; }` — and the 
> > right behavior is definitely that those use sites should be marked as 
> > invalid instead of refusing to compile the system header.
>
>
> That's the right answer on paper, but it's source-breaking in practice, for 
> both Swift and Objective-C. On the Objective-C side, someone could have been 
> using, say, `glob_t` in a copyable way in their ARC code, never touching the 
> block field, and it would have been working fine. On the Swift side, we won't 
> be able to import such a union at all when previously we would have.


Sorry, am I missing something?  Such a union would've been either ill-formed or 
unavailable in ARC (depending on where it was declared) before this recent work.


Repository:
  rC Clang

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

https://reviews.llvm.org/D65256



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


[PATCH] D59474: [OpenMP 5.0] Codegen support for user-defined mappers

2019-07-25 Thread Lingda Li via Phabricator via cfe-commits
lildmh updated this revision to Diff 211794.
lildmh added a comment.

Remove virtual from function declaration


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

https://reviews.llvm.org/D59474

Files:
  include/clang/AST/GlobalDecl.h
  lib/AST/ASTContext.cpp
  lib/CodeGen/CGDecl.cpp
  lib/CodeGen/CGOpenMPRuntime.cpp
  lib/CodeGen/CGOpenMPRuntime.h
  lib/CodeGen/ModuleBuilder.cpp
  test/OpenMP/declare_mapper_codegen.cpp

Index: test/OpenMP/declare_mapper_codegen.cpp
===
--- test/OpenMP/declare_mapper_codegen.cpp
+++ test/OpenMP/declare_mapper_codegen.cpp
@@ -1,92 +1,414 @@
-///==///
-// RUN: %clang_cc1 -verify -fopenmp -fopenmp-targets=powerpc64le-ibm-linux-gnu -x c++ -triple powerpc64le-unknown-unknown -emit-llvm %s -o - | FileCheck -allow-deprecated-dag-overlap  %s
-// RUN: %clang_cc1 -fopenmp -fopenmp-targets=powerpc64le-ibm-linux-gnu -x c++ -std=c++11 -triple powerpc64le-unknown-unknown -emit-pch -o %t %s
-// RUN: %clang_cc1 -fopenmp -fopenmp-targets=powerpc64le-ibm-linux-gnu -x c++ -triple powerpc64le-unknown-unknown -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck -allow-deprecated-dag-overlap %s
-// RUN: %clang_cc1 -verify -fopenmp -fopenmp-targets=i386-pc-linux-gnu -x c++ -triple i386-unknown-unknown -emit-llvm %s -o - | FileCheck -allow-deprecated-dag-overlap %s
-// RUN: %clang_cc1 -fopenmp -fopenmp-targets=i386-pc-linux-gnu -x c++ -std=c++11 -triple i386-unknown-unknown -emit-pch -o %t %s
-// RUN: %clang_cc1 -fopenmp -fopenmp-targets=i386-pc-linux-gnu -x c++ -triple i386-unknown-unknown -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck -allow-deprecated-dag-overlap %s
-
-// RUN: %clang_cc1 -verify -fopenmp-simd -fopenmp-targets=powerpc64le-ibm-linux-gnu -x c++ -triple powerpc64le-unknown-unknown -emit-llvm %s -o - | FileCheck -allow-deprecated-dag-overlap  --check-prefix SIMD-ONLY0 %s
-// RUN: %clang_cc1 -fopenmp-simd -fopenmp-targets=powerpc64le-ibm-linux-gnu -x c++ -std=c++11 -triple powerpc64le-unknown-unknown -emit-pch -o %t %s
-// RUN: %clang_cc1 -fopenmp-simd -fopenmp-targets=powerpc64le-ibm-linux-gnu -x c++ -triple powerpc64le-unknown-unknown -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck -allow-deprecated-dag-overlap  --check-prefix SIMD-ONLY0 %s
-// RUN: %clang_cc1 -verify -fopenmp-simd -fopenmp-targets=i386-pc-linux-gnu -x c++ -triple i386-unknown-unknown -emit-llvm %s -o - | FileCheck -allow-deprecated-dag-overlap  --check-prefix SIMD-ONLY0 %s
-// RUN: %clang_cc1 -fopenmp-simd -fopenmp-targets=i386-pc-linux-gnu -x c++ -std=c++11 -triple i386-unknown-unknown -emit-pch -o %t %s
-// RUN: %clang_cc1 -fopenmp-simd -fopenmp-targets=i386-pc-linux-gnu -x c++ -triple i386-unknown-unknown -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck -allow-deprecated-dag-overlap  --check-prefix SIMD-ONLY0 %s
-
 // SIMD-ONLY0-NOT: {{__kmpc|__tgt}}
 
 // expected-no-diagnostics
 #ifndef HEADER
 #define HEADER
 
+///==///
+// RUN: %clang_cc1 -DCK0 -verify -fopenmp -fopenmp-targets=powerpc64le-ibm-linux-gnu -x c++ -triple powerpc64le-unknown-unknown -emit-llvm -femit-all-decls -disable-llvm-passes %s -o - | FileCheck --check-prefix CK0 --check-prefix CK0-64 %s
+// RUN: %clang_cc1 -DCK0 -fopenmp -fopenmp-targets=powerpc64le-ibm-linux-gnu -x c++ -std=c++11 -triple powerpc64le-unknown-unknown -emit-pch -femit-all-decls -disable-llvm-passes -o %t %s
+// RUN: %clang_cc1 -DCK0 -fopenmp -fopenmp-targets=powerpc64le-ibm-linux-gnu -x c++ -triple powerpc64le-unknown-unknown -std=c++11 -femit-all-decls -disable-llvm-passes -include-pch %t -verify %s -emit-llvm -o - | FileCheck --check-prefix CK0 --check-prefix CK0-64 %s
+// RUN: %clang_cc1 -DCK0 -verify -fopenmp -fopenmp-targets=i386-pc-linux-gnu -x c++ -triple i386-unknown-unknown -emit-llvm -femit-all-decls -disable-llvm-passes %s -o - | FileCheck --check-prefix CK0 --check-prefix CK0-32 %s
+// RUN: %clang_cc1 -DCK0 -fopenmp -fopenmp-targets=i386-pc-linux-gnu -x c++ -std=c++11 -triple i386-unknown-unknown -emit-pch -femit-all-decls -disable-llvm-passes -o %t %s
+// RUN: %clang_cc1 -DCK0 -fopenmp -fopenmp-targets=i386-pc-linux-gnu -x c++ -triple i386-unknown-unknown -std=c++11 -femit-all-decls -disable-llvm-passes -include-pch %t -verify %s -emit-llvm -o - | FileCheck --check-prefix CK0 --check-prefix CK0-32 %s
+
+// RUN: %clang_cc1 -DCK0 -verify -fopenmp-simd -fopenmp-targets=powerpc64le-ibm-linux-gnu -x c++ -triple powerpc64le-unknown-unknown -emit-llvm -femit-all-decls -disable-llvm-passes %s -o - | FileCheck --check-prefix SIMD-ONLY0 %s
+// RUN: %clang_cc1 -DCK0 -fopenmp-simd -fopenmp-targets=powerpc64le-ibm-linux-gnu -x c++ -std=c++11 -triple powerpc64le-unknown-unknown -emit-pch -femit-all-decls -disable-llvm-passes -o %t %s
+// RUN: %clang_cc1 -DCK0 -fopenmp-simd 

[PATCH] D64656: Ensure placeholder instruction for cleanup is created

2019-07-25 Thread Saleem Abdulrasool via Phabricator via cfe-commits
compnerd closed this revision.
compnerd added a comment.

SVN r367042


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64656



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


r367042 - CodeGen: ensure placeholder instruction for cleanup is created

2019-07-25 Thread Saleem Abdulrasool via cfe-commits
Author: compnerd
Date: Thu Jul 25 10:59:29 2019
New Revision: 367042

URL: http://llvm.org/viewvc/llvm-project?rev=367042=rev
Log:
CodeGen: ensure placeholder instruction for cleanup is created

A placeholder instruction for use in generation of cleanup code for an
initializer list would not be emitted if the base class contained a
non-trivial destructor and the class contains no fields of its own. This
would be the case when using CTAD to deduce the template arguments for a
struct with an overloaded call operator, e.g.

```
template  struct ctad : Ts... {};
template  ctad(Ts...)->ctad;
```

and this class was initialized with a list of lambdas capturing by copy,
e.g.

```
ctad c {[s](short){}, [s](long){}};
```

In a release build the bug would manifest itself as a crash in the SROA
pass, however, in a debug build the following assert in CGCleanup.cpp
would fail:

```
assert(dominatingIP && "no existing variable and no dominating IP!");
```

By ensuring that a placeholder instruction is emitted even if there's no
fields in the class, neither the assert nor the crash is reproducible.

See https://bugs.llvm.org/show_bug.cgi?id=40771

Patch by Øystein Dale!

Added:
cfe/trunk/test/CodeGenCXX/pr40771-ctad-with-lambda-copy-capture.cpp
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=367042=367041=367042=diff
==
--- cfe/trunk/lib/CodeGen/CGExprAgg.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprAgg.cpp Thu Jul 25 10:59:29 2019
@@ -1495,6 +1495,13 @@ void AggExprEmitter::VisitInitListExpr(I
   // initializers throws an exception.
   SmallVector cleanups;
   llvm::Instruction *cleanupDominator = nullptr;
+  auto addCleanup = [&](const EHScopeStack::stable_iterator ) {
+cleanups.push_back(cleanup);
+if (!cleanupDominator) // create placeholder once needed
+  cleanupDominator = CGF.Builder.CreateAlignedLoad(
+  CGF.Int8Ty, llvm::Constant::getNullValue(CGF.Int8PtrTy),
+  CharUnits::One());
+  };
 
   unsigned curInitIndex = 0;
 
@@ -1519,7 +1526,7 @@ void AggExprEmitter::VisitInitListExpr(I
   if (QualType::DestructionKind dtorKind =
   Base.getType().isDestructedType()) {
 CGF.pushDestroy(dtorKind, V, Base.getType());
-cleanups.push_back(CGF.EHStack.stable_begin());
+addCleanup(CGF.EHStack.stable_begin());
   }
 }
   }
@@ -1596,15 +1603,9 @@ void AggExprEmitter::VisitInitListExpr(I
   = field->getType().isDestructedType()) {
   assert(LV.isSimple());
   if (CGF.needsEHCleanup(dtorKind)) {
-if (!cleanupDominator)
-  cleanupDominator = CGF.Builder.CreateAlignedLoad(
-  CGF.Int8Ty,
-  llvm::Constant::getNullValue(CGF.Int8PtrTy),
-  CharUnits::One()); // placeholder
-
 CGF.pushDestroy(EHCleanup, LV.getAddress(), field->getType(),
 CGF.getDestroyer(dtorKind), false);
-cleanups.push_back(CGF.EHStack.stable_begin());
+addCleanup(CGF.EHStack.stable_begin());
 pushedCleanup = true;
   }
 }
@@ -1620,6 +1621,8 @@ void AggExprEmitter::VisitInitListExpr(I
 
   // Deactivate all the partial cleanups in reverse order, which
   // generally means popping them.
+  assert((cleanupDominator || cleanups.empty()) &&
+ "Missing cleanupDominator before deactivating cleanup blocks");
   for (unsigned i = cleanups.size(); i != 0; --i)
 CGF.DeactivateCleanupBlock(cleanups[i-1], cleanupDominator);
 

Added: cfe/trunk/test/CodeGenCXX/pr40771-ctad-with-lambda-copy-capture.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/pr40771-ctad-with-lambda-copy-capture.cpp?rev=367042=auto
==
--- cfe/trunk/test/CodeGenCXX/pr40771-ctad-with-lambda-copy-capture.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/pr40771-ctad-with-lambda-copy-capture.cpp Thu Jul 
25 10:59:29 2019
@@ -0,0 +1,56 @@
+// RUN: %clang_cc1 -emit-llvm --std=c++17 -fcxx-exceptions -fexceptions \
+// RUN:   -discard-value-names %s -o - | FileCheck %s
+
+struct Q { Q(); };
+struct R { R(Q); ~R(); };
+struct S { S(Q); ~S(); };
+struct T : R, S {};
+
+Q q;
+T t { R{q}, S{q} };
+
+// CHECK-LABEL: define internal void @__cxx_global_var_init.1() {{.*}} {
+// CHECK-NEXT: [[TMP_R:%[a-z0-9.]+]] = alloca %struct.R, align 1
+// CHECK-NEXT: [[TMP_Q1:%[a-z0-9.]+]] = alloca %struct.Q, align 1
+// CHECK-NEXT: [[TMP_S:%[a-z0-9.]+]] = alloca %struct.S, align 1
+// CHECK-NEXT: [[TMP_Q2:%[a-z0-9.]+]] = alloca %struct.Q, align 1
+// CHECK-NEXT: [[XPT:%[a-z0-9.]+]] = alloca i8*
+// CHECK-NEXT: [[SLOT:%[a-z0-9.]+]] = alloca i32
+// CHECK-NEXT: [[ACTIVE:%[a-z0-9.]+]] = alloca i1, align 1
+// CHECK-NEXT: call void @_ZN1RC1E1Q(%struct.R* [[TMP_R]])
+// CHECK-NEXT: store i1 true, i1* [[ACTIVE]], align 1

[PATCH] D63954: Add lifetime categories attributes

2019-07-25 Thread Matthias Gehre via Phabricator via cfe-commits
mgehre added a comment.

Thank you very much for dedicating your time for the review. It improved the 
code a lot!


Repository:
  rL LLVM

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

https://reviews.llvm.org/D63954



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


[PATCH] D63954: Add lifetime categories attributes

2019-07-25 Thread Matthias Gehre via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL367040: Add lifetime categories attributes (authored by 
mgehre, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D63954?vs=211600=211792#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D63954

Files:
  cfe/trunk/include/clang/Basic/Attr.td
  cfe/trunk/include/clang/Basic/AttrDocs.td
  cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
  cfe/trunk/lib/Parse/ParseDecl.cpp
  cfe/trunk/lib/Sema/SemaDeclAttr.cpp
  cfe/trunk/test/AST/ast-dump-attr.cpp
  cfe/trunk/test/Misc/pragma-attribute-supported-attributes-list.test
  cfe/trunk/test/SemaCXX/attr-gsl-owner-pointer.cpp
  cfe/trunk/test/SemaOpenCL/invalid-kernel-attrs.cl
  cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp

Index: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
===
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
@@ -2519,6 +2519,9 @@
   "'NSObject' attribute is for pointer types only">;
 def err_attributes_are_not_compatible : Error<
   "%0 and %1 attributes are not compatible">;
+def err_attribute_invalid_argument : Error<
+  "%select{'void'|a reference type|an array type|a non-vector or "
+  "non-vectorizable scalar type}0 is an invalid argument to attribute %1">;
 def err_attribute_wrong_number_arguments : Error<
   "%0 attribute %plural{0:takes no arguments|1:takes one argument|"
   ":requires exactly %1 arguments}1">;
@@ -2567,8 +2570,6 @@
 def err_init_priority_object_attr : Error<
   "can only use 'init_priority' attribute on file-scope definitions "
   "of objects of class type">;
-def err_attribute_argument_vec_type_hint : Error<
-  "invalid attribute argument %0 - expecting a vector or vectorizable scalar type">;
 def err_attribute_argument_out_of_bounds : Error<
   "%0 attribute parameter %1 is out of bounds">;
 def err_attribute_only_once_per_parameter : Error<
Index: cfe/trunk/include/clang/Basic/AttrDocs.td
===
--- cfe/trunk/include/clang/Basic/AttrDocs.td
+++ cfe/trunk/include/clang/Basic/AttrDocs.td
@@ -4230,3 +4230,71 @@
 the initializer on host side.
   }];
 }
+
+def LifetimeOwnerDocs : Documentation {
+  let Category = DocCatDecl;
+  let Content = [{
+.. Note:: This attribute is experimental and its effect on analysis is subject to change in
+  a future version of clang.
+
+The attribute ``[[gsl::Owner(T)]]`` applies to structs and classes that own an
+object of type ``T``:
+
+.. code-block:: c++
+
+  class [[gsl::Owner(int)]] IntOwner {
+  private:
+int value;
+  public:
+int *getInt() { return  }
+  };
+
+The argument ``T`` is optional and currently ignored.
+This attribute may be used by analysis tools and has no effect on code
+generation.
+
+See Pointer_ for an example.
+}];
+}
+
+def LifetimePointerDocs : Documentation {
+  let Category = DocCatDecl;
+  let Content = [{
+.. Note:: This attribute is experimental and its effect on analysis is subject to change in
+  a future version of clang.
+
+The attribute ``[[gsl::Pointer(T)]]`` applies to structs and classes that behave
+like pointers to an object of type ``T``:
+
+.. code-block:: c++
+
+  class [[gsl::Pointer(int)]] IntPointer {
+  private:
+int *valuePointer;
+  public:
+int *getInt() { return  }
+  };
+
+The argument ``T`` is optional and currently ignored.
+This attribute may be used by analysis tools and has no effect on code
+generation.
+
+Example:
+When constructing an instance of a class annotated like this (a Pointer) from
+an instance of a class annotated with ``[[gsl::Owner]]`` (an Owner),
+then the analysis will consider the Pointer to point inside the Owner.
+When the Owner's lifetime ends, it will consider the Pointer to be dangling.
+
+.. code-block:: c++
+
+  int f() {
+IntPointer P;
+if (true) {
+  IntOwner O(7);
+  P = IntPointer(O); // P "points into" O
+} // P is dangling
+return P.get(); // error: Using a dangling Pointer.
+  }
+
+}];
+}
Index: cfe/trunk/include/clang/Basic/Attr.td
===
--- cfe/trunk/include/clang/Basic/Attr.td
+++ cfe/trunk/include/clang/Basic/Attr.td
@@ -2796,6 +2796,20 @@
   let Documentation = [TypeTagForDatatypeDocs];
 }
 
+def Owner : InheritableAttr {
+  let Spellings = [CXX11<"gsl", "Owner">];
+  let Subjects = SubjectList<[Struct]>;
+  let Args = [TypeArgument<"DerefType", /*opt=*/1>];
+  let Documentation = [LifetimeOwnerDocs];
+}
+
+def Pointer : InheritableAttr {
+  let Spellings = [CXX11<"gsl", "Pointer">];
+  let Subjects = SubjectList<[Struct]>;
+  let Args = [TypeArgument<"DerefType", /*opt=*/1>];
+  let Documentation = [LifetimePointerDocs];
+}
+
 // 

r367040 - Add lifetime categories attributes

2019-07-25 Thread Matthias Gehre via cfe-commits
Author: mgehre
Date: Thu Jul 25 10:50:51 2019
New Revision: 367040

URL: http://llvm.org/viewvc/llvm-project?rev=367040=rev
Log:
Add lifetime categories attributes

Summary:
This is the first part of work announced in
"[RFC] Adding lifetime analysis to clang" [0],
i.e. the addition of the [[gsl::Owner(T)]] and
[[gsl::Pointer(T)]] attributes, which
will enable user-defined types to participate in
the lifetime analysis (which will be part of the
next PR).
The type `T` here is called "DerefType" in the paper,
and denotes the type that an Owner owns and a Pointer
points to. E.g. `std::vector` should be annotated
with `[[gsl::Owner(int)]]` and
a `std::vector::iterator` with `[[gsl::Pointer(int)]]`.

[0] http://lists.llvm.org/pipermail/cfe-dev/2018-November/060355.html

Reviewers: gribozavr

Subscribers: xazax.hun, cfe-commits

Tags: #clang

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

Added:
cfe/trunk/test/SemaCXX/attr-gsl-owner-pointer.cpp
Modified:
cfe/trunk/include/clang/Basic/Attr.td
cfe/trunk/include/clang/Basic/AttrDocs.td
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Parse/ParseDecl.cpp
cfe/trunk/lib/Sema/SemaDeclAttr.cpp
cfe/trunk/test/AST/ast-dump-attr.cpp
cfe/trunk/test/Misc/pragma-attribute-supported-attributes-list.test
cfe/trunk/test/SemaOpenCL/invalid-kernel-attrs.cl
cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp

Modified: cfe/trunk/include/clang/Basic/Attr.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Attr.td?rev=367040=367039=367040=diff
==
--- cfe/trunk/include/clang/Basic/Attr.td (original)
+++ cfe/trunk/include/clang/Basic/Attr.td Thu Jul 25 10:50:51 2019
@@ -2796,6 +2796,20 @@ def TypeTagForDatatype : InheritableAttr
   let Documentation = [TypeTagForDatatypeDocs];
 }
 
+def Owner : InheritableAttr {
+  let Spellings = [CXX11<"gsl", "Owner">];
+  let Subjects = SubjectList<[Struct]>;
+  let Args = [TypeArgument<"DerefType", /*opt=*/1>];
+  let Documentation = [LifetimeOwnerDocs];
+}
+
+def Pointer : InheritableAttr {
+  let Spellings = [CXX11<"gsl", "Pointer">];
+  let Subjects = SubjectList<[Struct]>;
+  let Args = [TypeArgument<"DerefType", /*opt=*/1>];
+  let Documentation = [LifetimePointerDocs];
+}
+
 // Microsoft-related attributes
 
 def MSNoVTable : InheritableAttr, TargetSpecificAttr {

Modified: cfe/trunk/include/clang/Basic/AttrDocs.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/AttrDocs.td?rev=367040=367039=367040=diff
==
--- cfe/trunk/include/clang/Basic/AttrDocs.td (original)
+++ cfe/trunk/include/clang/Basic/AttrDocs.td Thu Jul 25 10:50:51 2019
@@ -4230,3 +4230,71 @@ not initialized on device side. It has i
 the initializer on host side.
   }];
 }
+
+def LifetimeOwnerDocs : Documentation {
+  let Category = DocCatDecl;
+  let Content = [{
+.. Note:: This attribute is experimental and its effect on analysis is subject 
to change in
+  a future version of clang.
+
+The attribute ``[[gsl::Owner(T)]]`` applies to structs and classes that own an
+object of type ``T``:
+
+.. code-block:: c++
+
+  class [[gsl::Owner(int)]] IntOwner {
+  private:
+int value;
+  public:
+int *getInt() { return  }
+  };
+
+The argument ``T`` is optional and currently ignored.
+This attribute may be used by analysis tools and has no effect on code
+generation.
+
+See Pointer_ for an example.
+}];
+}
+
+def LifetimePointerDocs : Documentation {
+  let Category = DocCatDecl;
+  let Content = [{
+.. Note:: This attribute is experimental and its effect on analysis is subject 
to change in
+  a future version of clang.
+
+The attribute ``[[gsl::Pointer(T)]]`` applies to structs and classes that 
behave
+like pointers to an object of type ``T``:
+
+.. code-block:: c++
+
+  class [[gsl::Pointer(int)]] IntPointer {
+  private:
+int *valuePointer;
+  public:
+int *getInt() { return  }
+  };
+
+The argument ``T`` is optional and currently ignored.
+This attribute may be used by analysis tools and has no effect on code
+generation.
+
+Example:
+When constructing an instance of a class annotated like this (a Pointer) from
+an instance of a class annotated with ``[[gsl::Owner]]`` (an Owner),
+then the analysis will consider the Pointer to point inside the Owner.
+When the Owner's lifetime ends, it will consider the Pointer to be dangling.
+
+.. code-block:: c++
+
+  int f() {
+IntPointer P;
+if (true) {
+  IntOwner O(7);
+  P = IntPointer(O); // P "points into" O
+} // P is dangling
+return P.get(); // error: Using a dangling Pointer.
+  }
+
+}];
+}

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=367040=367039=367040=diff

[PATCH] D64454: [clang-tidy] Adding static analyzer check to list of clang-tidy checks

2019-07-25 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D64454#1601439 , @nickdesaulniers 
wrote:

> In D64454#1600922 , @aaron.ballman 
> wrote:
>
> > I use svn in-tree, so I tried it out and it does not seem to work for me.
> >
> >   c:\llvm\tools\clang\tools\extra\docs\clang-tidy\checks>python 
> > gen-static-analyzer-docs.py
> >   Traceback (most recent call last):
> > File "gen-static-analyzer-docs.py", line 120, in 
> >   main()
> > File "gen-static-analyzer-docs.py", line 109, in main
> >   checkers = get_checkers()
> > File "gen-static-analyzer-docs.py", line 23, in get_checkers
> >   result = subprocess.run(["llvm-tblgen", "--dump-json", "-I",
> >   AttributeError: 'module' object has no attribute 'run'
> >  
> >   c:\llvm\tools\clang\tools\extra\docs\clang-tidy\checks>python --version
> >   Python 2.7.16
> >
>
>
> Via: http://llvmweekly.org/issue/289
>
> > Tom Stellard reminds us that LLVM's subversion is scheduled to be retired 
> > by Oct 21 2019, and enourages everyone to move their workflow to GitHub as 
> > soon as possible. See the GitHub migration status for more info.
>
> @aaron.ballman should we really be spending time supporting a workflow that 
> is deprecated and due for removal?


Yes -- svn is still an official way to work with our repositories and it must 
continue to work until we retire it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64454



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


[PATCH] D64454: [clang-tidy] Adding static analyzer check to list of clang-tidy checks

2019-07-25 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers added a comment.

In D64454#1600922 , @aaron.ballman 
wrote:

> I use svn in-tree, so I tried it out and it does not seem to work for me.
>
>   c:\llvm\tools\clang\tools\extra\docs\clang-tidy\checks>python 
> gen-static-analyzer-docs.py
>   Traceback (most recent call last):
> File "gen-static-analyzer-docs.py", line 120, in 
>   main()
> File "gen-static-analyzer-docs.py", line 109, in main
>   checkers = get_checkers()
> File "gen-static-analyzer-docs.py", line 23, in get_checkers
>   result = subprocess.run(["llvm-tblgen", "--dump-json", "-I",
>   AttributeError: 'module' object has no attribute 'run'
>  
>   c:\llvm\tools\clang\tools\extra\docs\clang-tidy\checks>python --version
>   Python 2.7.16
>


Via: http://llvmweekly.org/issue/289

> Tom Stellard reminds us that LLVM's subversion is scheduled to be retired by 
> Oct 21 2019, and enourages everyone to move their workflow to GitHub as soon 
> as possible. See the GitHub migration status for more info.

@aaron.ballman should we really be spending time supporting a workflow that is 
deprecated and due for removal?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64454



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


[PATCH] D64958: [clang-doc] Fix link generation

2019-07-25 Thread Diego Astiazarán via Phabricator via cfe-commits
DiegoAstiazaran added a comment.

In D64958#1601228 , @juliehockett 
wrote:

> Under what circumstances, exactly, is the path not set where you would need 
> to create a link despite that? Is it only in the global namespace case? If 
> so, could you special-case that and ignore other empty paths?


It's not specifically in the GlobalNamespace info file. It happens in that one 
but also in any info whose parent namespace is the global namespace.


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

https://reviews.llvm.org/D64958



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


[PATCH] D64666: [Sema] Enable -Wimplicit-float-conversion for integral to floating point precision loss

2019-07-25 Thread Ziang Wan via Phabricator via cfe-commits
ziangwan added a comment.

My bad. I omit these two test cases. I apologize for my carelessness.

Yes, this warning definitely is a duplicate of c++11 narrowing, *when the code 
actually uses initialization-list syntax. For example, the following code would 
issue duplicated warnings for now:

  float ff = {L};  
  long a = L;
  float  = {a};

However, c++11 narrowing conversion does not handle these cases. It does not 
handle initialization without initialization-list syntax. It does not handle 
implicit conversion in expressions. It does not handle implicit conversion in 
argument passing as well.

  void test(float b) {}
  
  float f = L; // no narrowing warning
  
  long a = L;
  float fff = a; // warning
  float c = a + fff; // no narrowing warning of a from long to float
  
  test(a); // no narrowing warning

Handling extra cases allow us to sanity-check code that does not use 
initialization-list syntax or has implicit conversion in expressions. I believe 
it is a valuable addition. A fix would be to let 
`-Wimplicit-int-float-conversion` skip initialization-list syntax. The other 
way would to augment c++ narrowing. What do you guys think is the proper way?

I will continue work on this patch. Please don't panic.


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

https://reviews.llvm.org/D64666



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


[PATCH] D64958: [clang-doc] Fix link generation

2019-07-25 Thread Diego Astiazarán via Phabricator via cfe-commits
DiegoAstiazaran marked an inline comment as done.
DiegoAstiazaran added inline comments.



Comment at: clang-tools-extra/clang-doc/Representation.h:137
+// saved (possibly unresolved)
+  bool IsPathValid = false; // Indicates if a value has been assigned to Path,
+// it could be an empty string

juliehockett wrote:
> Is this field actually set anywhere? 
Yes, in the constructors where a path is assigned.


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

https://reviews.llvm.org/D64958



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


[PATCH] D65256: [Sema][ObjC] Mark C union fields that have non-trivial ObjC ownership qualifications as unavailable if the union is declared in a system header

2019-07-25 Thread Jordan Rose via Phabricator via cfe-commits
jordan_rose added a comment.

I'm personally still of the opinion that allowing non-trivial fields in unions 
was a mistake, but it's too late to change that as well.


Repository:
  rC Clang

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

https://reviews.llvm.org/D65256



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


[PATCH] D65256: [Sema][ObjC] Mark C union fields that have non-trivial ObjC ownership qualifications as unavailable if the union is declared in a system header

2019-07-25 Thread Jordan Rose via Phabricator via cfe-commits
jordan_rose added a comment.

In D65256#1601410 , @rjmccall wrote:

> These were unavailable in system headers before because otherwise we would've 
> had to make them invalid.  Since these unions are no longer otherwise 
> invalid, there shouldn't be a problem with allowing them in system headers, 
> and in fact making the semantics vary that way seems quite problematic.  Now, 
> specific *uses* in system headers might still appear to be invalid — e.g. an 
> ObjC ivar of type `union { __strong id x; }` — and the right behavior is 
> definitely that those use sites should be marked as invalid instead of 
> refusing to compile the system header.


That's the right answer on paper, but it's source-breaking in practice, for 
both Swift and Objective-C. On the Objective-C side, someone could have been 
using, say, `glob_t` in a copyable way in their ARC code, never touching the 
block field, and it would have been working fine. On the Swift side, we won't 
be able to import such a union at all when previously we would have.


Repository:
  rC Clang

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

https://reviews.llvm.org/D65256



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


RE: [PATCH] D62731: [RFC] Add support for options -fp-model= and -fp-speculation= : specify floating point behavior

2019-07-25 Thread Blower, Melanie via cfe-commits
Thanks for your review. I put some quick replies below.  I'll work on an update 
to this. 

> -Original Message-
> From: Kevin P. Neal via Phabricator [mailto:revi...@reviews.llvm.org]
> Sent: Thursday, July 25, 2019 1:09 PM
> To: Blower, Melanie ; chandl...@gmail.com
> Cc: mgo...@gentoo.org; hiradi...@msn.com; wuz...@cn.ibm.com; Wang,
> Pengfei ; lebedev...@gmail.com;
> cameron.mcina...@nyu.edu; llvm-comm...@lists.llvm.org; Rice, Michael P
> ; Kaylor, Andrew ;
> kevin.n...@sas.com; cfe-commits@lists.llvm.org; paul.robin...@sony.com;
> peter.wal...@arm.com
> Subject: [PATCH] D62731: [RFC] Add support for options -fp-model= and -fp-
> speculation= : specify floating point behavior
> 
> kpn added a comment.
> 
> In D62731#1601310 , @mibintc
> wrote:
> 
> > I think it would be convenient to have an "unset" setting for the different
> constrained modes, otherwise you need a boolean that says "no value was
> provided for this option".  But i'm a frontend person so I may need to have my
> attitude adjusted.
> 
> 
> What "different constrained modes"? The IRBuilder is either in constrained
> mode or it isn't. In constrained mode the exception behavior and rounding
> mode both have defaults, and those defaults can be changed individually
> without affecting the other setting. The current defaults can also be 
> retrieved if
> you need something for a function call where you don't want to change it but
> need an argument anyway. When do you need this "no value provided" setting?
[Blower, Melanie] I was thinking it would be convenient to have null values for 
RoundingMode and ExceptionBehavior but I'll work on the patch more in this area
> 
> Oh, I'd check the tools/clang/CODE_OWNERS.txt file and add additional
> appropriate reviewers. Perhaps John McCall and Richard Smith? I don't know
> who has opinions on how command line options should be handled.
[Blower, Melanie] Good idea but I'm not quite ready yet
> 
> Do we want the Unix driver to be compatible with gcc? Maybe, maybe not.
> Opinions, anyone?
[Blower, Melanie] For Intel's icc compiler, we support options describing 
fp-model in both Linux and Windows. Our customers find it useful. I want to add 
it both places. Gcc doesn't support these options.
> 
> The documentation request from lebedev.ri isn't in this ticket yet.
> 
> Also, for future historical research purposes I'd cut and paste the relevant
> portions of outside web pages (like intel.com's) and post them somewhere llvm-
> ish where they are findable. This ticket, for example, is a good place. Web 
> sites
> gets reorganized or vanish in full or in part. It's helpful to have some 
> insulation
> from that over time. I've had to fix compiler bugs that actually were 25 
> years old
> before. Yes, 25 years old. Being able to do the research is very helpful.
[Blower, Melanie] good idea, I will address that, adding it to this patch 
description? Or inline as comments in the source file itself?  (I may be able 
to compete with you on oldest bug fixed...)
> 
> Oh, it may be useful to know that constrained floating point and the
> FastMathFlags are not mutually exclusive. I don't know if that matters here or
> not, but you did mention FastMathFlags.
[Blower, Melanie] yes I worry about that
> 
> 
> 
> 
> Comment at: llvm/lib/IR/FPState.cpp:78
> +  }
> +
> +  Builder.setIsFPConstrained(IsConstrainedExcept || IsConstrainedRounding);
> 
> The IRBuilder already has defaults for exception behavior and rounding. Is it 
> a
> good idea to duplicate that knowledge here? Worse, what's here is different
> from what's in the IRBuilder. Why not ask the IRBuilder what its current 
> setting
> is and use that?
[Blower, Melanie] I was/am/ trying to translate the fp-model command line 
options semantics. I will look at this again.
> 
> Would it make sense to have setters/getters, and then have a separate
> updateBuilder() method? We still don't have a good way to get the #pragma
> down to the lower levels of clang. The current, unfinished, attempt doesn't 
> work
> for C++ templates and I'm told other cases as well. An updateBuilder() method
> could be helpful when moving from one scope to another. But keep in mind that
> if any constrained fp math is used in a function then the entire function has 
> to be
> constrained.
[Blower, Melanie] hmm
> 
> Given that last bit, it may make more sense to have the support somewhere
> higher level than as a wrapper around the IRBuilder. Maybe in
> CodeGenFunction or CodeGenModule? I've not spent much time in clang so I'm
> not sure if that makes sense or not.
> 
> 
> Repository:
>   rL LLVM
> 
> CHANGES SINCE LAST ACTION
>   https://reviews.llvm.org/D62731/new/
> 
> https://reviews.llvm.org/D62731
> 
> 

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


[PATCH] D65000: [ARM] Set default alignment to 64bits

2019-07-25 Thread Pirama Arumuga Nainar via Phabricator via cfe-commits
pirama accepted this revision.
pirama added a comment.

LGTM for Android.


Repository:
  rC Clang

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

https://reviews.llvm.org/D65000



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


r367039 - Remove CallingConvMethodType

2019-07-25 Thread Erich Keane via cfe-commits
Author: erichkeane
Date: Thu Jul 25 10:14:45 2019
New Revision: 367039

URL: http://llvm.org/viewvc/llvm-project?rev=367039=rev
Log:
Remove CallingConvMethodType

This seems to be an old vestage of a previous implementation of getting
the default calling convention, and everything is now using
CXXABI/ASTContext's getDefaultCallingConvention.  Remove it, since it
isn't doing anything.

Modified:
cfe/trunk/include/clang/Basic/TargetInfo.h
cfe/trunk/lib/AST/ASTContext.cpp
cfe/trunk/lib/Basic/Targets/SPIR.h
cfe/trunk/lib/Basic/Targets/X86.h

Modified: cfe/trunk/include/clang/Basic/TargetInfo.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TargetInfo.h?rev=367039=367038=367039=diff
==
--- cfe/trunk/include/clang/Basic/TargetInfo.h (original)
+++ cfe/trunk/include/clang/Basic/TargetInfo.h Thu Jul 25 10:14:45 2019
@@ -1249,15 +1249,9 @@ public:
   bool isBigEndian() const { return BigEndian; }
   bool isLittleEndian() const { return !BigEndian; }
 
-  enum CallingConvMethodType {
-CCMT_Unknown,
-CCMT_Member,
-CCMT_NonMember
-  };
-
   /// Gets the default calling convention for the given target and
   /// declaration context.
-  virtual CallingConv getDefaultCallingConv(CallingConvMethodType MT) const {
+  virtual CallingConv getDefaultCallingConv() const {
 // Not all targets will specify an explicit calling convention that we can
 // express.  This will always do the right thing, even though it's not
 // an explicit calling convention.

Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=367039=367038=367039=diff
==
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Thu Jul 25 10:14:45 2019
@@ -10035,7 +10035,7 @@ CallingConv ASTContext::getDefaultCallin
   break;
 }
   }
-  return Target->getDefaultCallingConv(TargetInfo::CCMT_Unknown);
+  return Target->getDefaultCallingConv();
 }
 
 bool ASTContext::isNearlyEmpty(const CXXRecordDecl *RD) const {

Modified: cfe/trunk/lib/Basic/Targets/SPIR.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets/SPIR.h?rev=367039=367038=367039=diff
==
--- cfe/trunk/lib/Basic/Targets/SPIR.h (original)
+++ cfe/trunk/lib/Basic/Targets/SPIR.h Thu Jul 25 10:14:45 2019
@@ -88,7 +88,7 @@ public:
 : CCCR_Warning;
   }
 
-  CallingConv getDefaultCallingConv(CallingConvMethodType MT) const override {
+  CallingConv getDefaultCallingConv() const override {
 return CC_SpirFunction;
   }
 

Modified: cfe/trunk/lib/Basic/Targets/X86.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets/X86.h?rev=367039=367038=367039=diff
==
--- cfe/trunk/lib/Basic/Targets/X86.h (original)
+++ cfe/trunk/lib/Basic/Targets/X86.h Thu Jul 25 10:14:45 2019
@@ -320,8 +320,8 @@ public:
 }
   }
 
-  CallingConv getDefaultCallingConv(CallingConvMethodType MT) const override {
-return MT == CCMT_Member ? CC_X86ThisCall : CC_C;
+  CallingConv getDefaultCallingConv() const override {
+return CC_C;
   }
 
   bool hasSjLjLowering() const override { return true; }
@@ -659,7 +659,7 @@ public:
 }
   }
 
-  CallingConv getDefaultCallingConv(CallingConvMethodType MT) const override {
+  CallingConv getDefaultCallingConv() const override {
 return CC_C;
   }
 


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


r367038 - Fix cxx_status html for r367027

2019-07-25 Thread Erich Keane via cfe-commits
Author: erichkeane
Date: Thu Jul 25 10:14:37 2019
New Revision: 367038

URL: http://llvm.org/viewvc/llvm-project?rev=367038=rev
Log:
Fix cxx_status html for r367027

Modified:
cfe/trunk/www/cxx_status.html

Modified: cfe/trunk/www/cxx_status.html
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/www/cxx_status.html?rev=367038=367037=367038=diff
==
--- cfe/trunk/www/cxx_status.html (original)
+++ cfe/trunk/www/cxx_status.html Thu Jul 25 10:14:37 2019
@@ -664,7 +664,7 @@ version 3.7.
 

 http://wg21.link/p1771r1;>P1771R1 (DR)
-SVN
+SVN
   
 
   [[maybe_unused]] attribute


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


[PATCH] D62731: [RFC] Add support for options -fp-model= and -fp-speculation= : specify floating point behavior

2019-07-25 Thread Kevin P. Neal via Phabricator via cfe-commits
kpn added a comment.

In D62731#1601310 , @mibintc wrote:

> I think it would be convenient to have an "unset" setting for the different 
> constrained modes, otherwise you need a boolean that says "no value was 
> provided for this option".  But i'm a frontend person so I may need to have 
> my attitude adjusted.


What "different constrained modes"? The IRBuilder is either in constrained mode 
or it isn't. In constrained mode the exception behavior and rounding mode both 
have defaults, and those defaults can be changed individually without affecting 
the other setting. The current defaults can also be retrieved if you need 
something for a function call where you don't want to change it but need an 
argument anyway. When do you need this "no value provided" setting?

Oh, I'd check the tools/clang/CODE_OWNERS.txt file and add additional 
appropriate reviewers. Perhaps John McCall and Richard Smith? I don't know who 
has opinions on how command line options should be handled.

Do we want the Unix driver to be compatible with gcc? Maybe, maybe not. 
Opinions, anyone?

The documentation request from lebedev.ri isn't in this ticket yet.

Also, for future historical research purposes I'd cut and paste the relevant 
portions of outside web pages (like intel.com's) and post them somewhere 
llvm-ish where they are findable. This ticket, for example, is a good place. 
Web sites gets reorganized or vanish in full or in part. It's helpful to have 
some insulation from that over time. I've had to fix compiler bugs that 
actually were 25 years old before. Yes, 25 years old. Being able to do the 
research is very helpful.

Oh, it may be useful to know that constrained floating point and the 
FastMathFlags are not mutually exclusive. I don't know if that matters here or 
not, but you did mention FastMathFlags.




Comment at: llvm/lib/IR/FPState.cpp:78
+  }
+
+  Builder.setIsFPConstrained(IsConstrainedExcept || IsConstrainedRounding);

The IRBuilder already has defaults for exception behavior and rounding. Is it a 
good idea to duplicate that knowledge here? Worse, what's here is different 
from what's in the IRBuilder. Why not ask the IRBuilder what its current 
setting is and use that?

Would it make sense to have setters/getters, and then have a separate 
updateBuilder() method? We still don't have a good way to get the #pragma down 
to the lower levels of clang. The current, unfinished, attempt doesn't work for 
C++ templates and I'm told other cases as well. An updateBuilder() method could 
be helpful when moving from one scope to another. But keep in mind that if any 
constrained fp math is used in a function then the entire function has to be 
constrained.

Given that last bit, it may make more sense to have the support somewhere 
higher level than as a wrapper around the IRBuilder. Maybe in CodeGenFunction 
or CodeGenModule? I've not spent much time in clang so I'm not sure if that 
makes sense or not.


Repository:
  rL LLVM

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

https://reviews.llvm.org/D62731



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


[PATCH] D65256: [Sema][ObjC] Mark C union fields that have non-trivial ObjC ownership qualifications as unavailable if the union is declared in a system header

2019-07-25 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

These were unavailable in system headers before because otherwise we would've 
had to make them invalid.  Since these unions are no longer otherwise invalid, 
there shouldn't be a problem with allowing them in system headers, and in fact 
making the semantics vary that way seems quite problematic.  Now, specific 
*uses* in system headers might still appear to be invalid — e.g. an ObjC ivar 
of type `union { __strong id x; }` — and the right behavior is definitely that 
those use sites should be marked as invalid instead of refusing to compile the 
system header.


Repository:
  rC Clang

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

https://reviews.llvm.org/D65256



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


[PATCH] D65286: [OpenCL] Allow OpenCL C style vector initialization in C++

2019-07-25 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

Wait, plain C++?  Do we currently allow this syntax outside of OpenCL?


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

https://reviews.llvm.org/D65286



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


[PATCH] D64883: Add new warning -Walloca for use of builtin alloca function

2019-07-25 Thread Elaina Guan via Phabricator via cfe-commits
ziyig added inline comments.



Comment at: clang/lib/Sema/SemaChecking.cpp:1172
   return ExprError();
+LLVM_FALLTHROUGH;
+  case Builtin::BI__builtin_alloca:

aaron.ballman wrote:
> Do we want to warn on all uses of alloca(), or just the ones that get past 
> the call to `SemaBuiltinAllocaWithAlign()`?
I don't have strong opinion about this. Which one do you think is better?


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

https://reviews.llvm.org/D64883



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


[PATCH] D64883: Add new warning -Walloca for use of builtin alloca function

2019-07-25 Thread Elaina Guan via Phabricator via cfe-commits
ziyig updated this revision to Diff 211785.
ziyig marked 9 inline comments as done.
ziyig added a comment.

Updated the warning message and the test cases.


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

https://reviews.llvm.org/D64883

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaChecking.cpp
  clang/test/Sema/warn-alloca.c


Index: clang/test/Sema/warn-alloca.c
===
--- /dev/null
+++ clang/test/Sema/warn-alloca.c
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -DSILENCE -fsyntax-only -verify -Wall %s
+// RUN: %clang_cc1 -fsyntax-only -verify -Walloca %s
+
+#ifdef SILENCE
+  // expected-no-diagnostics
+#endif
+
+void test1(int a) {
+  __builtin_alloca(a);
+#ifndef SILENCE
+  // expected-warning@-2 {{use of function __builtin_alloca is discouraged; 
there is no way to check for failure but failure may still occur, resulting in 
a possibly exploitable security vulnerability}}
+#endif
+}
+
+void test2(int a) {
+  __builtin_alloca_with_align(a, 32);
+#ifndef SILENCE
+  // expected-warning@-2 {{use of function __builtin_alloca_with_align is 
discouraged; there is no way to check for failure but failure may still occur, 
resulting in a possibly exploitable security vulnerability}}
+#endif
+}
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -1169,6 +1169,10 @@
   case Builtin::BI__builtin_alloca_with_align:
 if (SemaBuiltinAllocaWithAlign(TheCall))
   return ExprError();
+LLVM_FALLTHROUGH;
+  case Builtin::BI__builtin_alloca:
+Diag(TheCall->getBeginLoc(), diag::warn_alloca)
+<< TheCall->getDirectCallee()->getNameInfo().getAsString();
 break;
   case Builtin::BI__assume:
   case Builtin::BI__builtin_assume:
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -2772,6 +2772,11 @@
 def err_cannot_find_suitable_accessor : Error<
   "cannot find suitable %select{getter|setter}0 for property %1">;
 
+def warn_alloca : Warning<
+  "use of function %0 is discouraged; there is no way to check for failure but 
"
+  "failure may still occur, resulting in a possibly exploitable security 
vulnerability">,
+  InGroup>, DefaultIgnore;
+
 def warn_alloca_align_alignof : Warning<
   "second argument to __builtin_alloca_with_align is supposed to be in bits">,
   InGroup>;


Index: clang/test/Sema/warn-alloca.c
===
--- /dev/null
+++ clang/test/Sema/warn-alloca.c
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -DSILENCE -fsyntax-only -verify -Wall %s
+// RUN: %clang_cc1 -fsyntax-only -verify -Walloca %s
+
+#ifdef SILENCE
+  // expected-no-diagnostics
+#endif
+
+void test1(int a) {
+  __builtin_alloca(a);
+#ifndef SILENCE
+  // expected-warning@-2 {{use of function __builtin_alloca is discouraged; there is no way to check for failure but failure may still occur, resulting in a possibly exploitable security vulnerability}}
+#endif
+}
+
+void test2(int a) {
+  __builtin_alloca_with_align(a, 32);
+#ifndef SILENCE
+  // expected-warning@-2 {{use of function __builtin_alloca_with_align is discouraged; there is no way to check for failure but failure may still occur, resulting in a possibly exploitable security vulnerability}}
+#endif
+}
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -1169,6 +1169,10 @@
   case Builtin::BI__builtin_alloca_with_align:
 if (SemaBuiltinAllocaWithAlign(TheCall))
   return ExprError();
+LLVM_FALLTHROUGH;
+  case Builtin::BI__builtin_alloca:
+Diag(TheCall->getBeginLoc(), diag::warn_alloca)
+<< TheCall->getDirectCallee()->getNameInfo().getAsString();
 break;
   case Builtin::BI__assume:
   case Builtin::BI__builtin_assume:
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -2772,6 +2772,11 @@
 def err_cannot_find_suitable_accessor : Error<
   "cannot find suitable %select{getter|setter}0 for property %1">;
 
+def warn_alloca : Warning<
+  "use of function %0 is discouraged; there is no way to check for failure but "
+  "failure may still occur, resulting in a possibly exploitable security vulnerability">,
+  InGroup>, DefaultIgnore;
+
 def warn_alloca_align_alignof : Warning<
   "second argument to __builtin_alloca_with_align is supposed to be in bits">,
   InGroup>;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org

[PATCH] D59963: [clang-tidy] Add a module for the Linux kernel.

2019-07-25 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added inline comments.



Comment at: clang-tools-extra/docs/ReleaseNotes.rst:75
+
+  Checks Linux Kernel code to see if it uses the results from the functions in
+  linux/err.h. Also checks to see if code uses the results from functions that

Please highlight linux/err.h with double back-ticks. I think will be good idea 
to synchronize documentation text.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D59963



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


[PATCH] D59963: [clang-tidy] Add a module for the Linux kernel.

2019-07-25 Thread Tom Roeder via Phabricator via cfe-commits
tmroeder updated this revision to Diff 211783.
tmroeder added a comment.

Sync'ing to the latest HEAD commit on master.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D59963

Files:
  clang-tools-extra/clang-tidy/CMakeLists.txt
  clang-tools-extra/clang-tidy/ClangTidyForceLinker.h
  clang-tools-extra/clang-tidy/linuxkernel/CMakeLists.txt
  clang-tools-extra/clang-tidy/linuxkernel/LinuxKernelTidyModule.cpp
  clang-tools-extra/clang-tidy/linuxkernel/MustCheckErrsCheck.cpp
  clang-tools-extra/clang-tidy/linuxkernel/MustCheckErrsCheck.h
  clang-tools-extra/clang-tidy/plugin/CMakeLists.txt
  clang-tools-extra/clang-tidy/tool/CMakeLists.txt
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/linuxkernel-must-use-errs.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/test/clang-tidy/linuxkernel-must-check-errs.c

Index: clang-tools-extra/test/clang-tidy/linuxkernel-must-check-errs.c
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/linuxkernel-must-check-errs.c
@@ -0,0 +1,43 @@
+// RUN: %check_clang_tidy %s linuxkernel-must-check-errs %t
+
+#define __must_check __attribute__((warn_unused_result))
+
+// Prototypes of the error functions.
+void * __must_check ERR_PTR(long error);
+long  __must_check PTR_ERR(const void *ptr);
+int  __must_check IS_ERR(const void *ptr);
+int  __must_check IS_ERR_OR_NULL(const void *ptr);
+void * __must_check ERR_CAST(const void *ptr);
+int  __must_check PTR_ERR_OR_ZERO(const void *ptr);
+
+void f() {
+  ERR_PTR(0);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: result from function 'ERR_PTR' is unused
+  PTR_ERR((void *)0);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: result from function 'PTR_ERR' is unused
+  IS_ERR((void *)0);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: result from function 'IS_ERR' is unused
+  ERR_CAST((void *)0);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: result from function 'ERR_CAST' is unused
+out:
+  PTR_ERR_OR_ZERO((void *)0);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: result from function 'PTR_ERR_OR_ZERO' is unused
+}
+
+void *f1() {
+  return ERR_PTR(0);
+}
+
+long f2() {
+  if (IS_ERR((void *)0)) {
+return PTR_ERR((void *)0);
+  }
+  return -1;
+}
+
+void f3() {
+  f1();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: result from function 'f1' is unused but represents an error value
+  f2();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: result from function 'f2' is unused but represents an error value
+}
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -183,6 +183,7 @@
hicpp-use-nullptr (redirects to modernize-use-nullptr) 
hicpp-use-override (redirects to modernize-use-override) 
hicpp-vararg (redirects to cppcoreguidelines-pro-type-vararg) 
+   linuxkernel-must-use-errs
llvm-header-guard
llvm-include-order
llvm-namespace-comment
Index: clang-tools-extra/docs/clang-tidy/checks/linuxkernel-must-use-errs.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/linuxkernel-must-use-errs.rst
@@ -0,0 +1,26 @@
+.. title:: clang-tidy - linuxkernel-must-use-errs
+
+linuxkernel-must-use-errs
+=
+
+Checks for cases where the kernel error functions ``ERR_PTR``,
+``PTR_ERR``, ``IS_ERR``, ``IS_ERR_OR_NULL``, ``ERR_CAST``, and
+``PTR_ERR_OR_ZERO`` are called but the results are not used. These
+functions are marked with ``__attribute__((warn_unused_result))``, but
+the compiler warning for this attribute is not always enabled.
+
+This also checks for unused values returned by functions that return
+``ERR_PTR``.
+
+Examples:
+
+.. code-block:: c
+
+  /* Trivial unused call to an ERR function */
+  PTR_ERR_OR_ZERO(some_function_call());
+
+  /* A function that returns ERR_PTR. */
+  void *fn() { ERR_PTR(-EINVAL); }
+
+  /* An invalid use of fn. */
+  fn();
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -69,6 +69,13 @@
 
 The improvements are...
 
+- New :doc:`linuxkernel-must-use-errs
+  ` check.
+
+  Checks Linux Kernel code to see if it uses the results from the functions in
+  linux/err.h. Also checks to see if code uses the results from functions that
+  directly return a value from one of these error functions.
+
 Improvements to include-fixer
 -
 
Index: clang-tools-extra/clang-tidy/tool/CMakeLists.txt
===
--- clang-tools-extra/clang-tidy/tool/CMakeLists.txt
+++ 

RE: r367027 - Implement P1771

2019-07-25 Thread Keane, Erich via cfe-commits
Ah!  Thanks.  I’ll fix it now.

From: Richard Smith [mailto:rich...@metafoo.co.uk]
Sent: Thursday, July 25, 2019 9:26 AM
To: Keane, Erich 
Cc: cfe-commits 
Subject: Re: r367027 - Implement P1771

On Thu, 25 Jul 2019, 08:10 Erich Keane via cfe-commits, 
mailto:cfe-commits@lists.llvm.org>> wrote:
Author: erichkeane
Date: Thu Jul 25 08:10:56 2019
New Revision: 367027

URL: http://llvm.org/viewvc/llvm-project?rev=367027=rev
Log:
Implement P1771

As passed in the Cologne meeting and treated by Core as a DR,
[[nodiscard]] was applied to constructors so that they can be diagnosed
in cases where the user forgets a variable name for a type.

The intent is to enable the library to start using this on the
constructors of scope_guard/lock_guard.

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

Modified:
cfe/trunk/include/clang/Basic/Attr.td
cfe/trunk/include/clang/Basic/AttrDocs.td
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/AST/Expr.cpp
cfe/trunk/lib/Sema/SemaDeclAttr.cpp
cfe/trunk/lib/Sema/SemaStmt.cpp
cfe/trunk/test/CXX/dcl.dcl/dcl.attr/dcl.attr.nodiscard/p2.cpp
cfe/trunk/test/Preprocessor/has_attribute.cpp
cfe/trunk/www/cxx_status.html

Modified: cfe/trunk/include/clang/Basic/Attr.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Attr.td?rev=367027=367026=367027=diff
==
--- cfe/trunk/include/clang/Basic/Attr.td (original)
+++ cfe/trunk/include/clang/Basic/Attr.td Thu Jul 25 08:10:56 2019
@@ -2335,12 +2335,19 @@ def WarnUnused : InheritableAttr {
 }

 def WarnUnusedResult : InheritableAttr {
-  let Spellings = [CXX11<"", "nodiscard", 201603>, C2x<"", "nodiscard">,
+  let Spellings = [CXX11<"", "nodiscard", 201907>, C2x<"", "nodiscard">,
CXX11<"clang", "warn_unused_result">,
GCC<"warn_unused_result">];
   let Subjects = SubjectList<[ObjCMethod, Enum, Record, FunctionLike]>;
   let Args = [StringArgument<"Message", 1>];
   let Documentation = [WarnUnusedResultsDocs];
+  let AdditionalMembers = [{
+// Check whether this the C++11 nodiscard version, even in non C++11
+// spellings.
+bool IsCXX11NoDiscard() const {
+  return this->getSemanticSpelling() == CXX11_nodiscard;
+}
+  }];
 }

 def Weak : InheritableAttr {

Modified: cfe/trunk/include/clang/Basic/AttrDocs.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/AttrDocs.td?rev=367027=367026=367027=diff
==
--- cfe/trunk/include/clang/Basic/AttrDocs.td (original)
+++ cfe/trunk/include/clang/Basic/AttrDocs.td Thu Jul 25 08:10:56 2019
@@ -1500,6 +1500,33 @@ in any resulting diagnostics.
   }
   error_info ();
   void f() { foo(); } // Does not diagnose, error_info is a reference.
+
+Additionally, discarded temporaries resulting from a call to a constructor
+marked with ``[[nodiscard]]`` or a constructor of a type marked
+``[[nodiscard]]`` will also diagnose. This also applies to type conversions 
that
+use the annotated ``[[nodiscard]]`` constructor or result in an annotated type.
+
+.. code-block: c++
+  struct [[nodiscard]] marked_type {/*..*/ };
+  struct marked_ctor {
+[[nodiscard]] marked_ctor();
+marked_ctor(int);
+  };
+
+  struct S {
+operator marked_type() const;
+[[nodiscard]] operator int() const;
+  };
+
+  void usages() {
+marked_type(); // diagnoses.
+marked_ctor(); // diagnoses.
+marked_ctor(3); // Does not diagnose, int constructor isn't marked 
nodiscard.
+
+S s;
+static_cast(s); // diagnoses
+(int)s; // diagnoses
+  }
   }];
 }


Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=367027=367026=367027=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Thu Jul 25 08:10:56 
2019
@@ -7430,6 +7430,12 @@ def warn_unused_container_subscript_expr
 def warn_unused_call : Warning<
   "ignoring return value of function declared with %0 attribute">,
   InGroup;
+def warn_unused_constructor : Warning<
+  "ignoring temporary created by a constructor declared with %0 attribute">,
+  InGroup;
+def warn_unused_constructor_msg : Warning<
+  "ignoring temporary created by a constructor declared with %0 attribute: 
%1">,
+  InGroup;
 def warn_side_effects_unevaluated_context : Warning<
   "expression with side effects has no effect in an unevaluated context">,
   InGroup;

Modified: cfe/trunk/lib/AST/Expr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=367027=367026=367027=diff
==
--- cfe/trunk/lib/AST/Expr.cpp (original)
+++ 

[PATCH] D65256: [Sema][ObjC] Mark C union fields that have non-trivial ObjC ownership qualifications as unavailable if the union is declared in a system header

2019-07-25 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak marked an inline comment as done.
ahatanak added inline comments.



Comment at: test/SemaObjC/Inputs/non-trivial-c-union.h:10
+  _Nonnull id f1;
+  __weak id f2;
+} U0_SystemHeader;

Rather than making an exception for explicit `__strong` fields, should we have 
an attribute that can be used to instruct the compiler not to mark the field as 
unavailable?


Repository:
  rC Clang

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

https://reviews.llvm.org/D65256



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


Re: r367027 - Implement P1771

2019-07-25 Thread Richard Smith via cfe-commits
On Thu, 25 Jul 2019, 08:10 Erich Keane via cfe-commits, <
cfe-commits@lists.llvm.org> wrote:

> Author: erichkeane
> Date: Thu Jul 25 08:10:56 2019
> New Revision: 367027
>
> URL: http://llvm.org/viewvc/llvm-project?rev=367027=rev
> Log:
> Implement P1771
>
> As passed in the Cologne meeting and treated by Core as a DR,
> [[nodiscard]] was applied to constructors so that they can be diagnosed
> in cases where the user forgets a variable name for a type.
>
> The intent is to enable the library to start using this on the
> constructors of scope_guard/lock_guard.
>
> Differential Revision: https://reviews.llvm.org/D64914
>
> Modified:
> cfe/trunk/include/clang/Basic/Attr.td
> cfe/trunk/include/clang/Basic/AttrDocs.td
> cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> cfe/trunk/lib/AST/Expr.cpp
> cfe/trunk/lib/Sema/SemaDeclAttr.cpp
> cfe/trunk/lib/Sema/SemaStmt.cpp
> cfe/trunk/test/CXX/dcl.dcl/dcl.attr/dcl.attr.nodiscard/p2.cpp
> cfe/trunk/test/Preprocessor/has_attribute.cpp
> cfe/trunk/www/cxx_status.html
>
> Modified: cfe/trunk/include/clang/Basic/Attr.td
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Attr.td?rev=367027=367026=367027=diff
>
> ==
> --- cfe/trunk/include/clang/Basic/Attr.td (original)
> +++ cfe/trunk/include/clang/Basic/Attr.td Thu Jul 25 08:10:56 2019
> @@ -2335,12 +2335,19 @@ def WarnUnused : InheritableAttr {
>  }
>
>  def WarnUnusedResult : InheritableAttr {
> -  let Spellings = [CXX11<"", "nodiscard", 201603>, C2x<"", "nodiscard">,
> +  let Spellings = [CXX11<"", "nodiscard", 201907>, C2x<"", "nodiscard">,
> CXX11<"clang", "warn_unused_result">,
> GCC<"warn_unused_result">];
>let Subjects = SubjectList<[ObjCMethod, Enum, Record, FunctionLike]>;
>let Args = [StringArgument<"Message", 1>];
>let Documentation = [WarnUnusedResultsDocs];
> +  let AdditionalMembers = [{
> +// Check whether this the C++11 nodiscard version, even in non C++11
> +// spellings.
> +bool IsCXX11NoDiscard() const {
> +  return this->getSemanticSpelling() == CXX11_nodiscard;
> +}
> +  }];
>  }
>
>  def Weak : InheritableAttr {
>
> Modified: cfe/trunk/include/clang/Basic/AttrDocs.td
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/AttrDocs.td?rev=367027=367026=367027=diff
>
> ==
> --- cfe/trunk/include/clang/Basic/AttrDocs.td (original)
> +++ cfe/trunk/include/clang/Basic/AttrDocs.td Thu Jul 25 08:10:56 2019
> @@ -1500,6 +1500,33 @@ in any resulting diagnostics.
>}
>error_info ();
>void f() { foo(); } // Does not diagnose, error_info is a reference.
> +
> +Additionally, discarded temporaries resulting from a call to a constructor
> +marked with ``[[nodiscard]]`` or a constructor of a type marked
> +``[[nodiscard]]`` will also diagnose. This also applies to type
> conversions that
> +use the annotated ``[[nodiscard]]`` constructor or result in an annotated
> type.
> +
> +.. code-block: c++
> +  struct [[nodiscard]] marked_type {/*..*/ };
> +  struct marked_ctor {
> +[[nodiscard]] marked_ctor();
> +marked_ctor(int);
> +  };
> +
> +  struct S {
> +operator marked_type() const;
> +[[nodiscard]] operator int() const;
> +  };
> +
> +  void usages() {
> +marked_type(); // diagnoses.
> +marked_ctor(); // diagnoses.
> +marked_ctor(3); // Does not diagnose, int constructor isn't marked
> nodiscard.
> +
> +S s;
> +static_cast(s); // diagnoses
> +(int)s; // diagnoses
> +  }
>}];
>  }
>
>
> Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=367027=367026=367027=diff
>
> ==
> --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
> +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Thu Jul 25
> 08:10:56 2019
> @@ -7430,6 +7430,12 @@ def warn_unused_container_subscript_expr
>  def warn_unused_call : Warning<
>"ignoring return value of function declared with %0 attribute">,
>InGroup;
> +def warn_unused_constructor : Warning<
> +  "ignoring temporary created by a constructor declared with %0
> attribute">,
> +  InGroup;
> +def warn_unused_constructor_msg : Warning<
> +  "ignoring temporary created by a constructor declared with %0
> attribute: %1">,
> +  InGroup;
>  def warn_side_effects_unevaluated_context : Warning<
>"expression with side effects has no effect in an unevaluated context">,
>InGroup;
>
> Modified: cfe/trunk/lib/AST/Expr.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=367027=367026=367027=diff
>
> ==
> --- 

[PATCH] D65290: [analyzer][NFC] Prove that we only track the evaluated part of the condition

2019-07-25 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus created this revision.
Szelethus added reviewers: NoQ, xazax.hun, Charusso, rnkovacs, 
baloghadamsoftware, dcoughlin.
Szelethus added a project: clang.
Herald added subscribers: cfe-commits, gamesh411, dkrupp, donat.nagy, 
mikhail.ramalho, a.sidorin, szepet, whisperity.
Szelethus added a parent revision: D65287: [analyzer][CFG] Don't track the 
condition of asserts.

...because we're working with a `BugReporterVisitor`, and the non-evaluated 
part of the condition isn't in the bugpath.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D65290

Files:
  clang/test/Analysis/track-control-dependency-conditions.cpp


Index: clang/test/Analysis/track-control-dependency-conditions.cpp
===
--- clang/test/Analysis/track-control-dependency-conditions.cpp
+++ clang/test/Analysis/track-control-dependency-conditions.cpp
@@ -502,6 +502,7 @@
 }
 
 #undef assert
+
 } // end of namespace dont_track_assertlike_and_conditions
 
 namespace dont_track_assertlike_or_conditions {
@@ -541,3 +542,37 @@
 
 #undef assert
 } // end of namespace dont_track_assertlike_or_conditions
+
+namespace only_track_the_evaluated_condition {
+
+bool coin();
+
+void bar(int ) {
+  flag = coin(); // tracking-note{{Value assigned to 'flag'}}
+}
+
+void bar2(int ) {
+  flag2 = coin();
+}
+
+void f(int *x) {
+  if (x) // expected-note{{Assuming 'x' is null}}
+ // debug-note@-1{{Tracking condition 'x'}}
+ // expected-note@-2{{Taking false branch}}
+return;
+
+  int flag, flag2;
+  bar(flag); // tracking-note{{Calling 'bar'}}
+ // tracking-note@-1{{Returning from 'bar'}}
+  bar2(flag2);
+
+  if (flag && flag2) // expected-note   {{Assuming 'flag' is 0}}
+ // expected-note@-1{{Left side of '&&' is false}}
+ // debug-note@-2{{Tracking condition 'flag'}}
+return;
+
+  *x = 5; // expected-warning{{Dereference of null pointer}}
+  // expected-note@-1{{Dereference of null pointer}}
+}
+
+} // end of namespace only_track_the_evaluated_condition


Index: clang/test/Analysis/track-control-dependency-conditions.cpp
===
--- clang/test/Analysis/track-control-dependency-conditions.cpp
+++ clang/test/Analysis/track-control-dependency-conditions.cpp
@@ -502,6 +502,7 @@
 }
 
 #undef assert
+
 } // end of namespace dont_track_assertlike_and_conditions
 
 namespace dont_track_assertlike_or_conditions {
@@ -541,3 +542,37 @@
 
 #undef assert
 } // end of namespace dont_track_assertlike_or_conditions
+
+namespace only_track_the_evaluated_condition {
+
+bool coin();
+
+void bar(int ) {
+  flag = coin(); // tracking-note{{Value assigned to 'flag'}}
+}
+
+void bar2(int ) {
+  flag2 = coin();
+}
+
+void f(int *x) {
+  if (x) // expected-note{{Assuming 'x' is null}}
+ // debug-note@-1{{Tracking condition 'x'}}
+ // expected-note@-2{{Taking false branch}}
+return;
+
+  int flag, flag2;
+  bar(flag); // tracking-note{{Calling 'bar'}}
+ // tracking-note@-1{{Returning from 'bar'}}
+  bar2(flag2);
+
+  if (flag && flag2) // expected-note   {{Assuming 'flag' is 0}}
+ // expected-note@-1{{Left side of '&&' is false}}
+ // debug-note@-2{{Tracking condition 'flag'}}
+return;
+
+  *x = 5; // expected-warning{{Dereference of null pointer}}
+  // expected-note@-1{{Dereference of null pointer}}
+}
+
+} // end of namespace only_track_the_evaluated_condition
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D65256: [Sema][ObjC] Mark C union fields that have non-trivial ObjC ownership qualifications as unavailable if the union is declared in a system header

2019-07-25 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak updated this revision to Diff 211778.
ahatanak added a comment.

Mark fields that don't have an explicit `__strong` qualifier as unavailable.


Repository:
  rC Clang

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

https://reviews.llvm.org/D65256

Files:
  include/clang/AST/ASTContext.h
  lib/AST/ASTContext.cpp
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaExpr.cpp
  test/SemaObjC/Inputs/non-trivial-c-union.h
  test/SemaObjC/non-trivial-c-union.m

Index: test/SemaObjC/non-trivial-c-union.m
===
--- test/SemaObjC/non-trivial-c-union.m
+++ test/SemaObjC/non-trivial-c-union.m
@@ -1,4 +1,6 @@
-// RUN: %clang_cc1 -fsyntax-only -fblocks -fobjc-arc -fobjc-runtime-has-weak -verify %s
+// RUN: %clang_cc1 -fsyntax-only -fblocks -fobjc-arc -fobjc-runtime-has-weak -I %S/Inputs -verify %s
+
+#include "non-trivial-c-union.h"
 
 typedef union { // expected-note 12 {{'U0' has subobjects that are non-trivial to default-initialize}} expected-note 36 {{'U0' has subobjects that are non-trivial to destruct}} expected-note 28 {{'U0' has subobjects that are non-trivial to copy}}
   id f0; // expected-note 12 {{f0 has type '__strong id' that is non-trivial to default-initialize}} expected-note 36 {{f0 has type '__strong id' that is non-trivial to destruct}} expected-note 28 {{f0 has type '__strong id' that is non-trivial to copy}}
@@ -80,3 +82,7 @@
 void testVolatileLValueToRValue(volatile U0 *a) {
   (void)*a; // expected-error {{cannot use volatile type 'volatile U0' where it causes an lvalue-to-rvalue conversion since it is a union that is non-trivial to destruct}} // expected-error {{cannot use volatile type 'volatile U0' where it causes an lvalue-to-rvalue conversion since it is a union that is non-trivial to copy}}
 }
+
+void unionInSystemHeader0(U0_SystemHeader);
+
+void unionInSystemHeader1(U1_SystemHeader); // expected-error {{cannot use type 'U1_SystemHeader' for a function/method parameter since it is a union that is non-trivial to destruct}} expected-error {{cannot use type 'U1_SystemHeader' for a function/method parameter since it is a union that is non-trivial to copy}}
Index: test/SemaObjC/Inputs/non-trivial-c-union.h
===
--- /dev/null
+++ test/SemaObjC/Inputs/non-trivial-c-union.h
@@ -0,0 +1,16 @@
+// For backward compatibility, fields of C unions declared in system headers
+// that have non-trivial ObjC ownership qualifications are marked as unavailable
+// unless the qualifier is explicit and __strong.
+
+#pragma clang system_header
+
+typedef union {
+  id f0;
+  _Nonnull id f1;
+  __weak id f2;
+} U0_SystemHeader;
+
+typedef union { // expected-note {{'U1_SystemHeader' has subobjects that are non-trivial to destruct}} expected-note {{'U1_SystemHeader' has subobjects that are non-trivial to copy}}
+  __strong id f0; // expected-note {{f0 has type '__strong id' that is non-trivial to destruct}} expected-note {{f0 has type '__strong id' that is non-trivial to copy}}
+  _Nonnull id f1;
+} U1_SystemHeader;
Index: lib/Sema/SemaExpr.cpp
===
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -15456,27 +15456,11 @@
 
   // Warn about implicitly autoreleasing indirect parameters captured by blocks.
   if (const auto *PT = CaptureType->getAs()) {
-// This function finds out whether there is an AttributedType of kind
-// attr::ObjCOwnership in Ty. The existence of AttributedType of kind
-// attr::ObjCOwnership implies __autoreleasing was explicitly specified
-// rather than being added implicitly by the compiler.
-auto IsObjCOwnershipAttributedType = [](QualType Ty) {
-  while (const auto *AttrTy = Ty->getAs()) {
-if (AttrTy->getAttrKind() == attr::ObjCOwnership)
-  return true;
-
-// Peel off AttributedTypes that are not of kind ObjCOwnership.
-Ty = AttrTy->getModifiedType();
-  }
-
-  return false;
-};
-
 QualType PointeeTy = PT->getPointeeType();
 
 if (!Invalid && PointeeTy->getAs() &&
 PointeeTy.getObjCLifetime() == Qualifiers::OCL_Autoreleasing &&
-!IsObjCOwnershipAttributedType(PointeeTy)) {
+!S.Context.isObjCOwnershipAttributedType(PointeeTy)) {
   if (BuildAndDiagnose) {
 SourceLocation VarLoc = Var->getLocation();
 S.Diag(Loc, diag::warn_block_capture_autoreleasing);
Index: lib/Sema/SemaDecl.cpp
===
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -11173,7 +11173,8 @@
   << 0 << 0 << QT.getUnqualifiedType() << "";
 
 for (const FieldDecl *FD : RD->fields())
-  asDerived().visit(FD->getType(), FD, InNonTrivialUnion);
+  if (!FD->hasAttr())
+asDerived().visit(FD->getType(), FD, InNonTrivialUnion);
   }
 
   void visitTrivial(QualType QT, const FieldDecl *FD, bool InNonTrivialUnion) {}
@@ 

[PATCH] D53157: Teach the IRBuilder about constrained fadd and friends

2019-07-25 Thread Melanie Blower via Phabricator via cfe-commits
mibintc added a comment.

The proposed llvm changes are now part of https://reviews.llvm.org/D62731


Repository:
  rL LLVM

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

https://reviews.llvm.org/D53157



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


[PATCH] D65254: Allow prefetching from non-zero address spaces

2019-07-25 Thread JF Bastien via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL367032: Allow prefetching from non-zero address spaces 
(authored by jfb, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D65254?vs=211637=211774#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D65254

Files:
  cfe/trunk/lib/CodeGen/CGBuiltin.cpp
  cfe/trunk/lib/Sema/SemaExpr.cpp
  cfe/trunk/test/CodeGen/arm_acle.c
  cfe/trunk/test/CodeGen/builtins-arm.c
  cfe/trunk/test/CodeGen/builtins-arm64.c
  cfe/trunk/test/CodeGen/ppc-xmmintrin.c
  cfe/trunk/test/CodeGen/pr9614.c
  cfe/trunk/test/CodeGen/prefetch-addr-spaces.c
  cfe/trunk/test/CodeGen/prefetchw-builtins.c
  cfe/trunk/test/CodeGen/sse-builtins.c
  llvm/trunk/include/llvm/IR/Intrinsics.td
  llvm/trunk/lib/IR/AutoUpgrade.cpp
  llvm/trunk/lib/Transforms/Scalar/LoopDataPrefetch.cpp
  llvm/trunk/test/Assembler/auto_upgrade_intrinsics.ll
  llvm/trunk/test/Bitcode/compatibility-3.6.ll
  llvm/trunk/test/Bitcode/compatibility-3.7.ll
  llvm/trunk/test/Bitcode/compatibility-3.8.ll
  llvm/trunk/test/Bitcode/compatibility-3.9.ll
  llvm/trunk/test/Bitcode/compatibility-4.0.ll
  llvm/trunk/test/Bitcode/compatibility-5.0.ll
  llvm/trunk/test/Bitcode/compatibility-6.0.ll
  llvm/trunk/test/Bitcode/compatibility.ll
  llvm/trunk/test/Verifier/intrinsic-immarg.ll

Index: llvm/trunk/lib/IR/AutoUpgrade.cpp
===
--- llvm/trunk/lib/IR/AutoUpgrade.cpp
+++ llvm/trunk/lib/IR/AutoUpgrade.cpp
@@ -789,6 +789,19 @@
 }
 break;
 
+  case 'p':
+if (Name == "prefetch") {
+  // Handle address space overloading.
+  Type *Tys[] = {F->arg_begin()->getType()};
+  if (F->getName() != Intrinsic::getName(Intrinsic::prefetch, Tys)) {
+rename(F);
+NewFn =
+Intrinsic::getDeclaration(F->getParent(), Intrinsic::prefetch, Tys);
+return true;
+  }
+}
+break;
+
   case 's':
 if (Name == "stackprotectorcheck") {
   NewFn = nullptr;
Index: llvm/trunk/lib/Transforms/Scalar/LoopDataPrefetch.cpp
===
--- llvm/trunk/lib/Transforms/Scalar/LoopDataPrefetch.cpp
+++ llvm/trunk/lib/Transforms/Scalar/LoopDataPrefetch.cpp
@@ -312,8 +312,8 @@
   IRBuilder<> Builder(MemI);
   Module *M = BB->getParent()->getParent();
   Type *I32 = Type::getInt32Ty(BB->getContext());
-  Function *PrefetchFunc =
-  Intrinsic::getDeclaration(M, Intrinsic::prefetch);
+  Function *PrefetchFunc = Intrinsic::getDeclaration(
+  M, Intrinsic::prefetch, PrefPtrValue->getType());
   Builder.CreateCall(
   PrefetchFunc,
   {PrefPtrValue,
Index: llvm/trunk/include/llvm/IR/Intrinsics.td
===
--- llvm/trunk/include/llvm/IR/Intrinsics.td
+++ llvm/trunk/include/llvm/IR/Intrinsics.td
@@ -451,7 +451,7 @@
 // from being reordered overly much with respect to nearby access to the same
 // memory while not impeding optimization.
 def int_prefetch
-: Intrinsic<[], [ llvm_ptr_ty, llvm_i32_ty, llvm_i32_ty, llvm_i32_ty ],
+: Intrinsic<[], [ llvm_anyptr_ty, llvm_i32_ty, llvm_i32_ty, llvm_i32_ty ],
 [ IntrInaccessibleMemOrArgMemOnly, ReadOnly<0>, NoCapture<0>,
   ImmArg<1>, ImmArg<2>]>;
 def int_pcmarker  : Intrinsic<[], [llvm_i32_ty]>;
Index: llvm/trunk/test/Bitcode/compatibility-3.8.ll
===
--- llvm/trunk/test/Bitcode/compatibility-3.8.ll
+++ llvm/trunk/test/Bitcode/compatibility-3.8.ll
@@ -1319,7 +1319,7 @@
   ; CHECK: call void @llvm.stackrestore(i8* %stack)
 
   call void @llvm.prefetch(i8* %stack, i32 0, i32 3, i32 0)
-  ; CHECK: call void @llvm.prefetch(i8* %stack, i32 0, i32 3, i32 0)
+  ; CHECK: call void @llvm.prefetch.p0i8(i8* %stack, i32 0, i32 3, i32 0)
 
   call void @llvm.pcmarker(i32 1)
   ; CHECK: call void @llvm.pcmarker(i32 1)
Index: llvm/trunk/test/Bitcode/compatibility-6.0.ll
===
--- llvm/trunk/test/Bitcode/compatibility-6.0.ll
+++ llvm/trunk/test/Bitcode/compatibility-6.0.ll
@@ -1411,7 +1411,7 @@
   ; CHECK: call void @llvm.stackrestore(i8* %stack)
 
   call void @llvm.prefetch(i8* %stack, i32 0, i32 3, i32 0)
-  ; CHECK: call void @llvm.prefetch(i8* %stack, i32 0, i32 3, i32 0)
+  ; CHECK: call void @llvm.prefetch.p0i8(i8* %stack, i32 0, i32 3, i32 0)
 
   call void @llvm.pcmarker(i32 1)
   ; CHECK: call void @llvm.pcmarker(i32 1)
@@ -1627,10 +1627,10 @@
 
 
 declare void @f.writeonly() writeonly
-; CHECK: declare void @f.writeonly() #40
+; CHECK: declare void @f.writeonly() #39
 
 declare void @f.speculatable() speculatable
-; CHECK: declare void @f.speculatable() #41
+; CHECK: declare void @f.speculatable() #40
 
 ;; Constant Expressions
 
@@ -1678,9 +1678,9 @@
 ; 

[PATCH] D62731: [RFC] Add support for options -fp-model= and -fp-speculation= : specify floating point behavior

2019-07-25 Thread Melanie Blower via Phabricator via cfe-commits
mibintc updated this revision to Diff 211770.
mibintc added a comment.
Herald added subscribers: hiraditya, mgorny.

The IRBuilder now has  been taught about constrained fadd and friends.  I 
simply updated my patches to work with the committed revision.  Note that this 
diff now contains what was formerly being reviewed separately in clang+llvm.  
Also let's discuss the new llvm file fpState.h. In this revision I didn't spend 
a lot of time pondering the best way to support this in the current world, i 
just made a simple update so it would build.

I could put the entire patch under clang and not create new files in llvm.  I 
think it would be an advantage to have the interpretation of the floating point 
command line switches occur in llvm itself. For one reason, because Intel plans 
to contribute the same options in the Fortran compiler as well as the clang 
compiler. This puts the switch logic into a single place.  Other languages may 
want to add support for the options too. Note, we also plan to implement inline 
pragma's for clang which allow the fp modes to be set for the duration of a 
code block.

I think it would be convenient to have an "unset" setting for the different 
constrained modes, otherwise you need a boolean that says "no value was 
provided for this option".  But i'm a frontend person so I may need to have my 
attitude adjusted.

When I was coding this before, I needed to pull out FPState.h from within 
IRBuilder because otherwise I needed to sprinkle additional include directives 
in many clang files, if it's pulled out like this to be more or less standalone 
then that problem resolved.


Repository:
  rL LLVM

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

https://reviews.llvm.org/D62731

Files:
  clang/include/clang/Basic/LangOptions.h
  clang/include/clang/Driver/CC1Options.td
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/Driver/clang_f_opts.c
  llvm/include/llvm/IR/FPState.h
  llvm/lib/IR/CMakeLists.txt
  llvm/lib/IR/FPState.cpp
  llvm/unittests/IR/IRBuilderTest.cpp

Index: llvm/unittests/IR/IRBuilderTest.cpp
===
--- llvm/unittests/IR/IRBuilderTest.cpp
+++ llvm/unittests/IR/IRBuilderTest.cpp
@@ -10,6 +10,7 @@
 #include "llvm/IR/BasicBlock.h"
 #include "llvm/IR/DIBuilder.h"
 #include "llvm/IR/DataLayout.h"
+#include "llvm/IR/FPState.h"
 #include "llvm/IR/Function.h"
 #include "llvm/IR/IntrinsicInst.h"
 #include "llvm/IR/LLVMContext.h"
@@ -195,6 +196,68 @@
   EXPECT_EQ(CII->getIntrinsicID(), Intrinsic::experimental_constrained_fadd);
   ASSERT_TRUE(CII->getExceptionBehavior() == ConstrainedFPIntrinsic::ebMayTrap);
   ASSERT_TRUE(CII->getRoundingMode() == ConstrainedFPIntrinsic::rmDownward);
+  //
+  // Use FPState to update the builder settings
+  FPState fpState(Builder);
+
+  fpState.updateBuilder(FPState::FPM_Off, FPState::FPME_Off, FPState::FPS_Off);
+  V = Builder.CreateFAdd(V, V);
+  ASSERT_TRUE(!isa(V));
+
+  fpState.updateBuilder(FPState::FPM_Precise, FPState::FPME_Off,
+FPState::FPS_Off);
+  V = Builder.CreateFAdd(V, V);
+  ASSERT_TRUE(!isa(V));
+
+  fpState.updateBuilder(FPState::FPM_Strict, FPState::FPME_Off,
+FPState::FPS_Off);
+  V = Builder.CreateFAdd(V, V);
+  CII = cast(V);
+  ASSERT_TRUE(isa(V));
+  ASSERT_TRUE(CII->getExceptionBehavior() == ConstrainedFPIntrinsic::ebStrict);
+  ASSERT_TRUE(CII->getRoundingMode() == ConstrainedFPIntrinsic::rmDynamic);
+
+  fpState.updateBuilder(FPState::FPM_Off, FPState::FPME_Except,
+FPState::FPS_Off);
+  V = Builder.CreateFAdd(V, V);
+  CII = cast(V);
+  ASSERT_TRUE(isa(V));
+  ASSERT_TRUE(CII->getExceptionBehavior() == ConstrainedFPIntrinsic::ebStrict);
+  ASSERT_TRUE(CII->getRoundingMode() == ConstrainedFPIntrinsic::rmToNearest);
+
+  fpState.updateBuilder(FPState::FPM_Off, FPState::FPME_NoExcept,
+FPState::FPS_Off);
+  V = Builder.CreateFAdd(V, V);
+  CII = cast(V);
+  ASSERT_TRUE(isa(V));
+  ASSERT_TRUE(CII->getExceptionBehavior() == ConstrainedFPIntrinsic::ebIgnore);
+  ASSERT_TRUE(CII->getRoundingMode() == ConstrainedFPIntrinsic::rmToNearest);
+
+  fpState.updateBuilder(FPState::FPM_Fast, FPState::FPME_Off, FPState::FPS_Off);
+  V = Builder.CreateFAdd(V, V);
+  ASSERT_TRUE(!isa(V));
+
+  fpState.updateBuilder(FPState::FPM_Off, FPState::FPME_Off, FPState::FPS_Fast);
+  V = Builder.CreateFAdd(V, V);
+  CII = cast(V);
+  ASSERT_TRUE(isa(V));
+  ASSERT_TRUE(CII->getExceptionBehavior() == ConstrainedFPIntrinsic::ebIgnore);
+  ASSERT_TRUE(CII->getRoundingMode() == ConstrainedFPIntrinsic::rmToNearest);
+
+  fpState.updateBuilder(FPState::FPM_Off, FPState::FPME_Off,
+FPState::FPS_Strict);
+  V = Builder.CreateFAdd(V, V);
+  CII = cast(V);
+  ASSERT_TRUE(isa(V));
+  

r367032 - Allow prefetching from non-zero address spaces

2019-07-25 Thread JF Bastien via cfe-commits
Author: jfb
Date: Thu Jul 25 09:11:57 2019
New Revision: 367032

URL: http://llvm.org/viewvc/llvm-project?rev=367032=rev
Log:
Allow prefetching from non-zero address spaces

Summary:
This is useful for targets which have prefetch instructions for non-default 
address spaces.



Subscribers: nemanjai, javed.absar, hiraditya, kbarton, jkorous, dexonsmith, 
cfe-commits, llvm-commits, RKSimon, hfinkel, t.p.northover, craig.topper, anemet

Tags: #clang, #llvm

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

Added:
cfe/trunk/test/CodeGen/prefetch-addr-spaces.c
Modified:
cfe/trunk/lib/CodeGen/CGBuiltin.cpp
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/test/CodeGen/arm_acle.c
cfe/trunk/test/CodeGen/builtins-arm.c
cfe/trunk/test/CodeGen/builtins-arm64.c
cfe/trunk/test/CodeGen/ppc-xmmintrin.c
cfe/trunk/test/CodeGen/pr9614.c
cfe/trunk/test/CodeGen/prefetchw-builtins.c
cfe/trunk/test/CodeGen/sse-builtins.c

Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=367032=367031=367032=diff
==
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Thu Jul 25 09:11:57 2019
@@ -2133,7 +2133,7 @@ RValue CodeGenFunction::EmitBuiltinExpr(
 Locality = (E->getNumArgs() > 2) ? EmitScalarExpr(E->getArg(2)) :
   llvm::ConstantInt::get(Int32Ty, 3);
 Value *Data = llvm::ConstantInt::get(Int32Ty, 1);
-Function *F = CGM.getIntrinsic(Intrinsic::prefetch);
+Function *F = CGM.getIntrinsic(Intrinsic::prefetch, Address->getType());
 return RValue::get(Builder.CreateCall(F, {Address, RW, Locality, Data}));
   }
   case Builtin::BI__builtin_readcyclecounter: {
@@ -6021,7 +6021,7 @@ Value *CodeGenFunction::EmitARMBuiltinEx
 // Locality is not supported on ARM target
 Value *Locality = llvm::ConstantInt::get(Int32Ty, 3);
 
-Function *F = CGM.getIntrinsic(Intrinsic::prefetch);
+Function *F = CGM.getIntrinsic(Intrinsic::prefetch, Address->getType());
 return Builder.CreateCall(F, {Address, RW, Locality, IsData});
   }
 
@@ -6960,7 +6960,7 @@ Value *CodeGenFunction::EmitAArch64Built
 
 // FIXME: We need AArch64 specific LLVM intrinsic if we want to specify
 // PLDL3STRM or PLDL2STRM.
-Function *F = CGM.getIntrinsic(Intrinsic::prefetch);
+Function *F = CGM.getIntrinsic(Intrinsic::prefetch, Address->getType());
 return Builder.CreateCall(F, {Address, RW, Locality, IsData});
   }
 
@@ -10037,7 +10037,7 @@ Value *CodeGenFunction::EmitX86BuiltinEx
 Value *RW = ConstantInt::get(Int32Ty, (C->getZExtValue() >> 2) & 0x1);
 Value *Locality = ConstantInt::get(Int32Ty, C->getZExtValue() & 0x3);
 Value *Data = ConstantInt::get(Int32Ty, 1);
-Function *F = CGM.getIntrinsic(Intrinsic::prefetch);
+Function *F = CGM.getIntrinsic(Intrinsic::prefetch, Address->getType());
 return Builder.CreateCall(F, {Address, RW, Locality, Data});
   }
   case X86::BI_mm_clflush: {

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=367032=367031=367032=diff
==
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Thu Jul 25 09:11:57 2019
@@ -5375,8 +5375,8 @@ static FunctionDecl *rewriteBuiltinFunct
   QualType DeclType = FDecl->getType();
   const FunctionProtoType *FT = dyn_cast(DeclType);
 
-  if (!Context.BuiltinInfo.hasPtrArgsOrResult(FDecl->getBuiltinID()) ||
-  !FT || FT->isVariadic() || ArgExprs.size() != FT->getNumParams())
+  if (!Context.BuiltinInfo.hasPtrArgsOrResult(FDecl->getBuiltinID()) || !FT ||
+  ArgExprs.size() < FT->getNumParams())
 return nullptr;
 
   bool NeedsNewDecl = false;
@@ -5415,6 +5415,7 @@ static FunctionDecl *rewriteBuiltinFunct
 return nullptr;
 
   FunctionProtoType::ExtProtoInfo EPI;
+  EPI.Variadic = FT->isVariadic();
   QualType OverloadTy = Context.getFunctionType(FT->getReturnType(),
 OverloadParams, EPI);
   DeclContext *Parent = FDecl->getParent();

Modified: cfe/trunk/test/CodeGen/arm_acle.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/arm_acle.c?rev=367032=367031=367032=diff
==
--- cfe/trunk/test/CodeGen/arm_acle.c (original)
+++ cfe/trunk/test/CodeGen/arm_acle.c Thu Jul 25 09:11:57 2019
@@ -88,28 +88,28 @@ void test_swp(uint32_t x, volatile void
 /* 8.6 Memory prefetch intrinsics */
 /* 8.6.1 Data prefetch */
 // ARM-LABEL: test_pld
-// ARM: call void @llvm.prefetch(i8* null, i32 0, i32 3, i32 1)
+// ARM: call void @llvm.prefetch.p0i8(i8* null, i32 0, i32 3, i32 1)
 void test_pld() {
   __pld(0);
 }
 
 // ARM-LABEL: test_pldx
-// AArch32: call void @llvm.prefetch(i8* null, i32 1, i32 3, i32 1)
-// 

[PATCH] D65139: [clangd] Support extraction of binary "subexpressions" like a + [[b + c]].

2019-07-25 Thread Sam McCall via Phabricator via cfe-commits
sammccall updated this revision to Diff 211773.
sammccall marked 3 inline comments as done.
sammccall added a comment.

Elaborate tests and comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D65139

Files:
  clang-tools-extra/clangd/Selection.cpp
  clang-tools-extra/clangd/Selection.h
  clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp
  clang-tools-extra/clangd/unittests/SelectionTests.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
@@ -444,6 +444,77 @@
   // FIXME: Doesn't work correctly for \[\[clang::uninitialized\]\] int
   // b = [[1]]; since the attr is inside the DeclStmt and the bounds of
   // DeclStmt don't cover the attribute
+
+  // Binary subexpressions
+  {R"cpp(void f() {
+   int x = 1 + [[2 + 3 + 4]] + 5;
+ })cpp",
+   R"cpp(void f() {
+   auto dummy = 2 + 3 + 4; int x = 1 + dummy + 5;
+ })cpp"},
+  {R"cpp(void f() {
+   int x = [[1 + 2 + 3]] + 4 + 5;
+ })cpp",
+   R"cpp(void f() {
+   auto dummy = 1 + 2 + 3; int x = dummy + 4 + 5;
+ })cpp"},
+  {R"cpp(void f() {
+   int x = 1 + 2 + [[3 + 4 + 5]];
+ })cpp",
+   R"cpp(void f() {
+   auto dummy = 3 + 4 + 5; int x = 1 + 2 + dummy;
+ })cpp"},
+  // Non-associative operations have no special support
+  {R"cpp(void f() {
+   int x = 1 - [[2 - 3 - 4]] - 5;
+ })cpp",
+   R"cpp(void f() {
+   auto dummy = 1 - 2 - 3 - 4; int x = dummy - 5;
+ })cpp"},
+  // A mix of associative operators isn't associative.
+  {R"cpp(void f() {
+   int x = 1 * [[2 + 3 * 4]] + 5;
+ })cpp",
+   R"cpp(void f() {
+   auto dummy = 1 * 2 + 3 * 4; int x = dummy + 5;
+ })cpp"},
+  // Overloaded operators are supported, we assume associativity
+  // as if they were built-in.
+  {R"cpp(struct S {
+   S(int);
+ };
+ S operator+(S, S);
+
+ void f() {
+   S x = S(1) + [[S(2) + S(3) + S(4)]] + S(5);
+ })cpp",
+   R"cpp(struct S {
+   S(int);
+ };
+ S operator+(S, S);
+
+ void f() {
+   auto dummy = S(2) + S(3) + S(4); S x = S(1) + dummy + S(5);
+ })cpp"},
+   // Don't try to analyze across macro boundaries
+   // FIXME: it'd be nice to do this someday (in a safe way)
+  {R"cpp(#define ECHO(X) X
+ void f() {
+   int x = 1 + [[ECHO(2 + 3) + 4]] + 5;
+ })cpp",
+   R"cpp(#define ECHO(X) X
+ void f() {
+   auto dummy = 1 + ECHO(2 + 3) + 4; int x = dummy + 5;
+ })cpp"},
+  {R"cpp(#define ECHO(X) X
+ void f() {
+   int x = 1 + [[ECHO(2) + ECHO(3) + 4]] + 5;
+ })cpp",
+   R"cpp(#define ECHO(X) X
+ void f() {
+   auto dummy = 1 + ECHO(2) + ECHO(3) + 4; int x = dummy + 5;
+ })cpp"},
+
   };
   for (const auto  : InputOutputs) {
 checkTransform(ID, IO.first, IO.second);
Index: clang-tools-extra/clangd/unittests/SelectionTests.cpp
===
--- clang-tools-extra/clangd/unittests/SelectionTests.cpp
+++ clang-tools-extra/clangd/unittests/SelectionTests.cpp
@@ -335,6 +335,23 @@
   }
 }
 
+TEST(SelectionTest, Implicit) {
+  const char* Test = R"cpp(
+struct S { S(const char*); };
+int f(S);
+int x = f("^");
+  )cpp";
+  auto AST = TestTU::withCode(Annotations(Test).code()).build();
+  auto T = makeSelectionTree(Test, AST);
+
+  const SelectionTree::Node *Str = T.commonAncestor();
+  EXPECT_EQ("StringLiteral", nodeKind(Str)) << "Implicit selected?";
+  EXPECT_EQ("ImplicitCastExpr", nodeKind(Str->Parent));
+  EXPECT_EQ("CXXConstructExpr", nodeKind(Str->Parent->Parent));
+  EXPECT_EQ(Str, >Parent->Parent->ignoreImplicit())
+  << "Didn't unwrap " << nodeKind(>Parent->Parent->ignoreImplicit());
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp
===
--- clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp
+++ 

[PATCH] D65139: [clangd] Support extraction of binary "subexpressions" like a + [[b + c]].

2019-07-25 Thread Sam McCall via Phabricator via cfe-commits
sammccall marked 8 inline comments as done.
sammccall added inline comments.



Comment at: clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp:50
   // Generate Replacement for declaring the selected Expr as a new variable
-  tooling::Replacement insertDeclaration(llvm::StringRef VarName) const;
+  tooling::Replacement insertDeclaration(llvm::StringRef VarName,
+ SourceRange InitChars) const;

SureYeaah wrote:
> Nit: same parameter order for replaceWithVar and insertDeclaration.
I think this *is* the same parameter order semantically: this is roughly 
(thing, definition) in both cases.
The fact that the *types* match but in the opposite order is just a coincidence 
I think?



Comment at: clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp:245
+assert(E && "callee and args should be Exprs!");
+if (E == Op->getArg(0) || E == Op->getArg(1))
+  SelectedOperands.push_back(Child);

SureYeaah wrote:
> Why do we need to check this for CXXOperatorCallExpr and not BinaryOperator?
Because there's no child AST node corresponding to a builtin `+`, but there is 
one corresponding to an overloaded `+`: a `DeclRefExpr` to an `operator+` 
FunctionDecl.



Comment at: clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp:305
+  const SelectionTree::Node *Start = Op.SelectedOperands.front(); // LHS
+  const SelectionTree::Node *End = Op.SelectedOperands.back();// RHS
+  // End is already correct, Start needs to be pushed down to the right spot.

SureYeaah wrote:
> For 1 + [[2 + 3 * 4]] + 5, we probably don't get an invalid range from this 
> function. If so, we might want to add one more check where we parse End and 
> compare it's operator.
> 
> 
I'm not quite sure what you mean here.

Annotating the operators, for `1 +a [[2 +b 3 *c 4]] +d 5`:
 - N is `*c`
 - RHS is `4`
 - LHS is `1 +a 2 +b 3 *c 4`.

The point is that RHS can never be an operator of the same type, because if we 
replaced RHS with `x +e y` then N would be that `+e` instead (since `+` is 
left-associative).




Comment at: clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp:314
+}
+// Op.LHS (partially) selected, so descend into it.
+Start = Op.SelectedOperands.front();

SureYeaah wrote:
> Nit: For [[a + b + c]],
> 
>+
>  /  \
> +c
>/ \
>   a   b
> 
> For the second + as Op, a would be completely selected. So Op.LHS can be 
> partially or completely selected.
Yeah, I meant "at least partially". Elaborated comment.



Comment at: clang-tools-extra/clangd/unittests/TweakTests.cpp:448
+
+  // Binary subexpressions
+  {R"cpp(void f() {

SureYeaah wrote:
> Can we have some tests with macros as well?
Added a simple one that just verifies we support operands being wrapped in 
macros, but not operators.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D65139



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


[PATCH] D65287: [analyzer][CFG] Don't track the condition of asserts

2019-07-25 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus created this revision.
Szelethus added reviewers: NoQ, xazax.hun, baloghadamsoftware, Charusso, 
a_sidorin, rnkovacs, dcoughlin.
Szelethus added a project: clang.
Herald added subscribers: cfe-commits, gamesh411, dkrupp, donat.nagy, 
mikhail.ramalho, a.sidorin, szepet, whisperity.

Well, what is says on the tin I guess!

Some more changes:

- Move `isInevitablySinking()` from `BugReporter.cpp` to `CFGBlock`'s interface
- Rename and move `findBlockForNode()` from `BugReporter.cpp` to 
`ExplodedNode::getCFGBlock()`
- Add some testcases, but are these assert implementations esoteric enough?


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D65287

Files:
  clang/include/clang/Analysis/CFG.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h
  clang/lib/Analysis/CFG.cpp
  clang/lib/StaticAnalyzer/Core/BugReporter.cpp
  clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
  clang/lib/StaticAnalyzer/Core/ExplodedGraph.cpp
  clang/test/Analysis/track-control-dependency-conditions.cpp

Index: clang/test/Analysis/track-control-dependency-conditions.cpp
===
--- clang/test/Analysis/track-control-dependency-conditions.cpp
+++ clang/test/Analysis/track-control-dependency-conditions.cpp
@@ -428,3 +428,116 @@
 }
 
 } // end of namespace unimportant_write_before_collapse_point
+
+namespace dont_track_assertlike_conditions {
+
+extern void __assert_fail (__const char *__assertion, __const char *__file,
+   unsigned int __line, __const char *__function)
+__attribute__ ((__noreturn__));
+#define assert(expr) \
+((expr)  ? (void)(0)  : __assert_fail (#expr, __FILE__, __LINE__, __func__))
+
+int getInt();
+
+int cond1;
+
+void bar() {
+  cond1 = getInt();
+}
+
+void f(int flag) {
+  int *x = 0; // expected-note{{'x' initialized to a null pointer value}}
+
+  flag = getInt();
+
+  bar();
+  assert(cond1); // expected-note{{Assuming 'cond1' is not equal to 0}}
+ // expected-note@-1{{'?' condition is true}}
+
+  if (flag) // expected-note{{'flag' is not equal to 0}}
+// expected-note@-1{{Taking true branch}}
+// debug-note@-2{{Tracking condition 'flag'}}
+*x = 5; // expected-warning{{Dereference of null pointer}}
+// expected-note@-1{{Dereference of null pointer}}
+}
+
+#undef assert
+} // end of namespace dont_track_assertlike_conditions
+
+namespace dont_track_assertlike_and_conditions {
+
+extern void __assert_fail (__const char *__assertion, __const char *__file,
+   unsigned int __line, __const char *__function)
+__attribute__ ((__noreturn__));
+#define assert(expr) \
+((expr)  ? (void)(0)  : __assert_fail (#expr, __FILE__, __LINE__, __func__))
+
+int getInt();
+
+int cond1;
+int cond2;
+
+void bar() {
+  cond1 = getInt();
+  cond2 = getInt();
+}
+
+void f(int flag) {
+  int *x = 0; // expected-note{{'x' initialized to a null pointer value}}
+
+  flag = getInt();
+
+  bar();
+  assert(cond1 && cond2);
+  // expected-note@-1{{Assuming 'cond1' is not equal to 0}}
+  // expected-note@-2{{Assuming 'cond2' is not equal to 0}}
+  // expected-note@-3{{'?' condition is true}}
+  // expected-note@-4{{Left side of '&&' is true}}
+
+  if (flag) // expected-note{{'flag' is not equal to 0}}
+// expected-note@-1{{Taking true branch}}
+// debug-note@-2{{Tracking condition 'flag'}}
+*x = 5; // expected-warning{{Dereference of null pointer}}
+// expected-note@-1{{Dereference of null pointer}}
+}
+
+#undef assert
+} // end of namespace dont_track_assertlike_and_conditions
+
+namespace dont_track_assertlike_or_conditions {
+
+extern void __assert_fail (__const char *__assertion, __const char *__file,
+   unsigned int __line, __const char *__function)
+__attribute__ ((__noreturn__));
+#define assert(expr) \
+((expr)  ? (void)(0)  : __assert_fail (#expr, __FILE__, __LINE__, __func__))
+
+int getInt();
+
+int cond1;
+int cond2;
+
+void bar() {
+  cond1 = getInt();
+  cond2 = getInt();
+}
+
+void f(int flag) {
+  int *x = 0; // expected-note{{'x' initialized to a null pointer value}}
+
+  flag = getInt();
+
+  bar();
+  assert(cond1 || cond2);
+  // expected-note@-1{{Assuming 'cond1' is not equal to 0}}
+  // expected-note@-2{{Left side of '||' is true}}
+
+  if (flag) // expected-note{{'flag' is not equal to 0}}
+// expected-note@-1{{Taking true branch}}
+// debug-note@-2{{Tracking condition 'flag'}}
+*x = 5; // expected-warning{{Dereference of null pointer}}
+// expected-note@-1{{Dereference of null pointer}}
+}
+
+#undef assert
+} // end of namespace dont_track_assertlike_or_conditions
Index: clang/lib/StaticAnalyzer/Core/ExplodedGraph.cpp
===
--- clang/lib/StaticAnalyzer/Core/ExplodedGraph.cpp
+++ clang/lib/StaticAnalyzer/Core/ExplodedGraph.cpp
@@ -16,6 +16,7 @@
 

  1   2   >