[PATCH] D108286: [clang][Driver][Linux] fix regression issue when define LIBCXX_LIBDIR_SUFFIX=64

2021-08-26 Thread lin.sun via Phabricator via cfe-commits
sunlin added a comment.

Thanks all of you!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108286

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


[clang] ad59735 - Fix __has_unique_object_representations with no_unique_address

2021-08-26 Thread Balazs Benics via cfe-commits

Author: Gabor Bencze
Date: 2021-08-26T09:23:37+02:00
New Revision: ad59735f9d150ebd10d4752a4468795c39f02c5d

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

LOG: Fix __has_unique_object_representations with no_unique_address

Fix incorrect behavior of `__has_unique_object_representations`
when using the no_unique_address attribute.
Based on the bug report: https://bugs.llvm.org/show_bug.cgi?id=47722

Reviewed By: aaron.ballman

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

Added: 
clang/test/SemaCXX/has_unique_object_reps_no_unique_addr.cpp

Modified: 
clang/lib/AST/ASTContext.cpp

Removed: 




diff  --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index cf5be0c3219a..591fa87d1878 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -2633,16 +2633,66 @@ static bool unionHasUniqueObjectRepresentations(const 
ASTContext &Context,
   return !RD->field_empty();
 }
 
-static bool isStructEmpty(QualType Ty) {
-  const RecordDecl *RD = Ty->castAs()->getDecl();
+static int64_t getSubobjectOffset(const FieldDecl *Field,
+  const ASTContext &Context,
+  const clang::ASTRecordLayout & /*Layout*/) {
+  return Context.getFieldOffset(Field);
+}
 
-  if (!RD->field_empty())
-return false;
+static int64_t getSubobjectOffset(const CXXRecordDecl *RD,
+  const ASTContext &Context,
+  const clang::ASTRecordLayout &Layout) {
+  return Context.toBits(Layout.getBaseClassOffset(RD));
+}
 
-  if (const auto *ClassDecl = dyn_cast(RD))
-return ClassDecl->isEmpty();
+static llvm::Optional
+structHasUniqueObjectRepresentations(const ASTContext &Context,
+ const RecordDecl *RD);
 
-  return true;
+static llvm::Optional
+getSubobjectSizeInBits(const FieldDecl *Field, const ASTContext &Context) {
+  if (Field->getType()->isRecordType()) {
+const RecordDecl *RD = Field->getType()->getAsRecordDecl();
+if (!RD->isUnion())
+  return structHasUniqueObjectRepresentations(Context, RD);
+  }
+  if (!Field->getType()->isReferenceType() &&
+  !Context.hasUniqueObjectRepresentations(Field->getType()))
+return llvm::None;
+
+  int64_t FieldSizeInBits =
+  Context.toBits(Context.getTypeSizeInChars(Field->getType()));
+  if (Field->isBitField()) {
+int64_t BitfieldSize = Field->getBitWidthValue(Context);
+if (BitfieldSize > FieldSizeInBits)
+  return llvm::None;
+FieldSizeInBits = BitfieldSize;
+  }
+  return FieldSizeInBits;
+}
+
+static llvm::Optional
+getSubobjectSizeInBits(const CXXRecordDecl *RD, const ASTContext &Context) {
+  return structHasUniqueObjectRepresentations(Context, RD);
+}
+
+template 
+static llvm::Optional structSubobjectsHaveUniqueObjectRepresentations(
+const RangeT &Subobjects, int64_t CurOffsetInBits,
+const ASTContext &Context, const clang::ASTRecordLayout &Layout) {
+  for (const auto *Subobject : Subobjects) {
+llvm::Optional SizeInBits =
+getSubobjectSizeInBits(Subobject, Context);
+if (!SizeInBits)
+  return llvm::None;
+if (*SizeInBits != 0) {
+  int64_t Offset = getSubobjectOffset(Subobject, Context, Layout);
+  if (Offset != CurOffsetInBits)
+return llvm::None;
+  CurOffsetInBits += *SizeInBits;
+}
+  }
+  return CurOffsetInBits;
 }
 
 static llvm::Optional
@@ -2656,58 +2706,32 @@ structHasUniqueObjectRepresentations(const ASTContext 
&Context,
 if (ClassDecl->isDynamicClass())
   return llvm::None;
 
-SmallVector, 4> Bases;
+SmallVector Bases;
 for (const auto &Base : ClassDecl->bases()) {
   // Empty types can be inherited from, and non-empty types can potentially
   // have tail padding, so just make sure there isn't an error.
-  if (!isStructEmpty(Base.getType())) {
-llvm::Optional Size = structHasUniqueObjectRepresentations(
-Context, Base.getType()->castAs()->getDecl());
-if (!Size)
-  return llvm::None;
-Bases.emplace_back(Base.getType(), Size.getValue());
-  }
+  Bases.emplace_back(Base.getType()->getAsCXXRecordDecl());
 }
 
-llvm::sort(Bases, [&](const std::pair &L,
-  const std::pair &R) {
-  return Layout.getBaseClassOffset(L.first->getAsCXXRecordDecl()) <
- Layout.getBaseClassOffset(R.first->getAsCXXRecordDecl());
+llvm::sort(Bases, [&](const CXXRecordDecl *L, const CXXRecordDecl *R) {
+  return Layout.getBaseClassOffset(L) < Layout.getBaseClassOffset(R);
 });
 
-for (const auto &Base : Bases) {
-  int64_t BaseOffset = Context.toBits(
-  Layout.getBaseClassOffset(Base.first->getAsCXXRecordDecl()));
- 

[clang-tools-extra] 3373e84 - [clang-tidy] Add bugprone-suspicious-memory-comparison check

2021-08-26 Thread Balazs Benics via cfe-commits

Author: Gabor Bencze
Date: 2021-08-26T09:23:37+02:00
New Revision: 3373e845398bfb8fa0e3c81b7ca84cbfedbad3ae

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

LOG: [clang-tidy] Add bugprone-suspicious-memory-comparison check

The check warns on suspicious calls to `memcmp`.
It currently checks for comparing types that do not have
unique object representations or are non-standard-layout.
Based on
  
https://wiki.sei.cmu.edu/confluence/display/c/EXP42-C.+Do+not+compare+padding+data
  
https://wiki.sei.cmu.edu/confluence/display/c/FLP37-C.+Do+not+use+object+representations+to+compare+floating-point+values
and part of
  
https://wiki.sei.cmu.edu/confluence/display/cplusplus/OOP57-CPP.+Prefer+special+member+functions+and+overloaded+operators+to+C+Standard+Library+functions
Add alias `cert-exp42-c` and `cert-flp37-c`.

Some tests are currently failing at head, the check depends on D89649.
Originally started in D71973

Reviewed By: aaron.ballman

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

Added: 
clang-tools-extra/clang-tidy/bugprone/SuspiciousMemoryComparisonCheck.cpp
clang-tools-extra/clang-tidy/bugprone/SuspiciousMemoryComparisonCheck.h

clang-tools-extra/docs/clang-tidy/checks/bugprone-suspicious-memory-comparison.rst
clang-tools-extra/docs/clang-tidy/checks/cert-exp42-c.rst
clang-tools-extra/docs/clang-tidy/checks/cert-flp37-c.rst

clang-tools-extra/test/clang-tidy/checkers/bugprone-suspicious-memory-comparison-32bits.cpp

clang-tools-extra/test/clang-tidy/checkers/bugprone-suspicious-memory-comparison.c

clang-tools-extra/test/clang-tidy/checkers/bugprone-suspicious-memory-comparison.cpp

Modified: 
clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/docs/clang-tidy/checks/list.rst

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp 
b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
index 35b5f2c37df6..9f0e6e3d7335 100644
--- a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
@@ -52,6 +52,7 @@
 #include "StringLiteralWithEmbeddedNulCheck.h"
 #include "SuspiciousEnumUsageCheck.h"
 #include "SuspiciousIncludeCheck.h"
+#include "SuspiciousMemoryComparisonCheck.h"
 #include "SuspiciousMemsetUsageCheck.h"
 #include "SuspiciousMissingCommaCheck.h"
 #include "SuspiciousSemicolonCheck.h"
@@ -160,6 +161,8 @@ class BugproneModule : public ClangTidyModule {
 "bugprone-suspicious-enum-usage");
 CheckFactories.registerCheck(
 "bugprone-suspicious-include");
+CheckFactories.registerCheck(
+"bugprone-suspicious-memory-comparison");
 CheckFactories.registerCheck(
 "bugprone-suspicious-memset-usage");
 CheckFactories.registerCheck(

diff  --git a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
index 78a70c703dc0..6bb9ed947439 100644
--- a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
@@ -47,6 +47,7 @@ add_clang_library(clangTidyBugproneModule
   StringLiteralWithEmbeddedNulCheck.cpp
   SuspiciousEnumUsageCheck.cpp
   SuspiciousIncludeCheck.cpp
+  SuspiciousMemoryComparisonCheck.cpp
   SuspiciousMemsetUsageCheck.cpp
   SuspiciousMissingCommaCheck.cpp
   SuspiciousSemicolonCheck.cpp

diff  --git 
a/clang-tools-extra/clang-tidy/bugprone/SuspiciousMemoryComparisonCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/SuspiciousMemoryComparisonCheck.cpp
new file mode 100644
index ..12497122bd88
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/bugprone/SuspiciousMemoryComparisonCheck.cpp
@@ -0,0 +1,85 @@
+//===--- SuspiciousMemoryComparisonCheck.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 "SuspiciousMemoryComparisonCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace bugprone {
+
+static llvm::Optional tryEvaluateSizeExpr(const Expr *SizeExpr,
+const ASTContext &Ctx) {
+  Expr::EvalResult Result;
+  if (SizeExpr->EvaluateAsRValue(Result, Ctx))
+return Ctx.toBits(
+CharUnits::fromQuan

[PATCH] D89649: Fix __has_unique_object_representations with no_unique_address

2021-08-26 Thread Balázs Benics via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGad59735f9d15: Fix __has_unique_object_representations with 
no_unique_address (authored by gbencze, committed by steakhal).

Changed prior to commit:
  https://reviews.llvm.org/D89649?vs=303082&id=368823#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89649

Files:
  clang/lib/AST/ASTContext.cpp
  clang/test/SemaCXX/has_unique_object_reps_no_unique_addr.cpp

Index: clang/test/SemaCXX/has_unique_object_reps_no_unique_addr.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/has_unique_object_reps_no_unique_addr.cpp
@@ -0,0 +1,42 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fsyntax-only -verify -std=c++2a %s
+//  expected-no-diagnostics
+
+struct Empty {};
+
+struct A {
+  [[no_unique_address]] Empty e;
+  char x;
+};
+
+static_assert(__has_unique_object_representations(A));
+
+struct B {
+  char x;
+  [[no_unique_address]] Empty e;
+};
+
+static_assert(__has_unique_object_representations(B));
+
+struct C {
+  char x;
+  [[no_unique_address]] Empty e1;
+  [[no_unique_address]] Empty e2;
+};
+
+static_assert(!__has_unique_object_representations(C));
+
+namespace TailPaddingReuse {
+struct A {
+private:
+  int a;
+
+public:
+  char b;
+};
+
+struct B {
+  [[no_unique_address]] A a;
+  char c[3];
+};
+} // namespace TailPaddingReuse
+static_assert(__has_unique_object_representations(TailPaddingReuse::B));
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -2633,16 +2633,66 @@
   return !RD->field_empty();
 }
 
-static bool isStructEmpty(QualType Ty) {
-  const RecordDecl *RD = Ty->castAs()->getDecl();
+static int64_t getSubobjectOffset(const FieldDecl *Field,
+  const ASTContext &Context,
+  const clang::ASTRecordLayout & /*Layout*/) {
+  return Context.getFieldOffset(Field);
+}
 
-  if (!RD->field_empty())
-return false;
+static int64_t getSubobjectOffset(const CXXRecordDecl *RD,
+  const ASTContext &Context,
+  const clang::ASTRecordLayout &Layout) {
+  return Context.toBits(Layout.getBaseClassOffset(RD));
+}
 
-  if (const auto *ClassDecl = dyn_cast(RD))
-return ClassDecl->isEmpty();
+static llvm::Optional
+structHasUniqueObjectRepresentations(const ASTContext &Context,
+ const RecordDecl *RD);
 
-  return true;
+static llvm::Optional
+getSubobjectSizeInBits(const FieldDecl *Field, const ASTContext &Context) {
+  if (Field->getType()->isRecordType()) {
+const RecordDecl *RD = Field->getType()->getAsRecordDecl();
+if (!RD->isUnion())
+  return structHasUniqueObjectRepresentations(Context, RD);
+  }
+  if (!Field->getType()->isReferenceType() &&
+  !Context.hasUniqueObjectRepresentations(Field->getType()))
+return llvm::None;
+
+  int64_t FieldSizeInBits =
+  Context.toBits(Context.getTypeSizeInChars(Field->getType()));
+  if (Field->isBitField()) {
+int64_t BitfieldSize = Field->getBitWidthValue(Context);
+if (BitfieldSize > FieldSizeInBits)
+  return llvm::None;
+FieldSizeInBits = BitfieldSize;
+  }
+  return FieldSizeInBits;
+}
+
+static llvm::Optional
+getSubobjectSizeInBits(const CXXRecordDecl *RD, const ASTContext &Context) {
+  return structHasUniqueObjectRepresentations(Context, RD);
+}
+
+template 
+static llvm::Optional structSubobjectsHaveUniqueObjectRepresentations(
+const RangeT &Subobjects, int64_t CurOffsetInBits,
+const ASTContext &Context, const clang::ASTRecordLayout &Layout) {
+  for (const auto *Subobject : Subobjects) {
+llvm::Optional SizeInBits =
+getSubobjectSizeInBits(Subobject, Context);
+if (!SizeInBits)
+  return llvm::None;
+if (*SizeInBits != 0) {
+  int64_t Offset = getSubobjectOffset(Subobject, Context, Layout);
+  if (Offset != CurOffsetInBits)
+return llvm::None;
+  CurOffsetInBits += *SizeInBits;
+}
+  }
+  return CurOffsetInBits;
 }
 
 static llvm::Optional
@@ -2656,58 +2706,32 @@
 if (ClassDecl->isDynamicClass())
   return llvm::None;
 
-SmallVector, 4> Bases;
+SmallVector Bases;
 for (const auto &Base : ClassDecl->bases()) {
   // Empty types can be inherited from, and non-empty types can potentially
   // have tail padding, so just make sure there isn't an error.
-  if (!isStructEmpty(Base.getType())) {
-llvm::Optional Size = structHasUniqueObjectRepresentations(
-Context, Base.getType()->castAs()->getDecl());
-if (!Size)
-  return llvm::None;
-Bases.emplace_back(Base.getType(), Size.getValue());
-  }
+  Bases.emplace_back(Base.getType()->getAsCXXRecordDecl());
   

[PATCH] D89651: [clang-tidy] Add bugprone-suspicious-memory-comparison check

2021-08-26 Thread Balázs Benics via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG3373e845398b: [clang-tidy] Add 
bugprone-suspicious-memory-comparison check (authored by gbencze, committed by 
steakhal).

Changed prior to commit:
  https://reviews.llvm.org/D89651?vs=306679&id=368824#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89651

Files:
  clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
  clang-tools-extra/clang-tidy/bugprone/SuspiciousMemoryComparisonCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/SuspiciousMemoryComparisonCheck.h
  clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/bugprone-suspicious-memory-comparison.rst
  clang-tools-extra/docs/clang-tidy/checks/cert-exp42-c.rst
  clang-tools-extra/docs/clang-tidy/checks/cert-flp37-c.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-suspicious-memory-comparison-32bits.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-suspicious-memory-comparison.c
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-suspicious-memory-comparison.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-suspicious-memory-comparison.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-suspicious-memory-comparison.cpp
@@ -0,0 +1,233 @@
+// RUN: %check_clang_tidy %s bugprone-suspicious-memory-comparison %t \
+// RUN: -- -- -target x86_64-unknown-unknown
+
+namespace std {
+typedef __SIZE_TYPE__ size_t;
+int memcmp(const void *lhs, const void *rhs, size_t count);
+} // namespace std
+
+namespace sei_cert_example_oop57_cpp {
+class C {
+  int i;
+
+public:
+  virtual void f();
+};
+
+void f(C &c1, C &c2) {
+  if (!std::memcmp(&c1, &c2, sizeof(C))) {
+// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: comparing object representation of non-standard-layout type 'sei_cert_example_oop57_cpp::C'; consider using a comparison operator instead
+  }
+}
+} // namespace sei_cert_example_oop57_cpp
+
+namespace inner_padding_64bit_only {
+struct S {
+  int x;
+  int *y;
+};
+
+void test() {
+  S a, b;
+  std::memcmp(&a, &b, sizeof(S));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: comparing object representation of type 'inner_padding_64bit_only::S' which does not have a unique object representation; consider comparing the members of the object manually
+}
+} // namespace inner_padding_64bit_only
+
+namespace padding_in_base {
+class Base {
+  char c;
+  int i;
+};
+
+class Derived : public Base {};
+
+class Derived2 : public Derived {};
+
+void testDerived() {
+  Derived a, b;
+  std::memcmp(&a, &b, sizeof(Base));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: comparing object representation of type 'padding_in_base::Derived' which does not have a unique object representation; consider comparing the members of the object manually
+  std::memcmp(&a, &b, sizeof(Derived));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: comparing object representation of type 'padding_in_base::Derived' which does not have a unique object representation; consider comparing the members of the object manually
+}
+
+void testDerived2() {
+  Derived2 a, b;
+  std::memcmp(&a, &b, sizeof(Base));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: comparing object representation of type 'padding_in_base::Derived2' which does not have a unique object representation; consider comparing the members of the object manually
+  std::memcmp(&a, &b, sizeof(Derived2));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: comparing object representation of type 'padding_in_base::Derived2' which does not have a unique object representation; consider comparing the members of the object manually
+}
+
+} // namespace padding_in_base
+
+namespace no_padding_in_base {
+class Base {
+  int a, b;
+};
+
+class Derived : public Base {};
+
+class Derived2 : public Derived {};
+
+void testDerived() {
+  Derived a, b;
+  std::memcmp(&a, &b, sizeof(Base));
+  std::memcmp(&a, &b, sizeof(Derived));
+}
+
+void testDerived2() {
+  Derived2 a, b;
+  std::memcmp(&a, &b, sizeof(char));
+  std::memcmp(&a, &b, sizeof(Base));
+  std::memcmp(&a, &b, sizeof(Derived2));
+}
+} // namespace no_padding_in_base
+
+namespace non_standard_layout {
+class C {
+private:
+  int x;
+
+public:
+  int y;
+};
+
+void test() {
+  C a, b;
+  std::memcmp(&a, &b, sizeof(C));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: comparing object representation of non-standard-layout type 'non_standard_layout::C'; consider using a comparison operator instead
+}
+
+} // namespace non_standard_layout
+
+namespace static_ignored {
+struct S {
+  static char c;
+  int i;
+};
+
+void test() {
+  S a, b;
+  std::memcmp(&a, &b, sizeof(S));
+}
+} // namespace static_ignored
+

[PATCH] D108742: Reclassify form-feed and vertical tab as vertical WS for the purposes of lexing.

2021-08-26 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 368826.
cor3ntin added a comment.

Fix tests


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108742

Files:
  clang/lib/Basic/CharInfo.cpp
  clang/unittests/Basic/CharInfoTest.cpp
  clang/unittests/Lex/DependencyDirectivesSourceMinimizerTest.cpp
  clang/unittests/Lex/LexerTest.cpp

Index: clang/unittests/Lex/LexerTest.cpp
===
--- clang/unittests/Lex/LexerTest.cpp
+++ clang/unittests/Lex/LexerTest.cpp
@@ -493,10 +493,11 @@
 
   EXPECT_TRUE(hasNewLineEscaped("\\\r"));
   EXPECT_TRUE(hasNewLineEscaped("\\\n"));
+  EXPECT_TRUE(hasNewLineEscaped("\\\t"));
+  EXPECT_TRUE(hasNewLineEscaped("\\\v"));
   EXPECT_TRUE(hasNewLineEscaped("\\\r\n"));
   EXPECT_TRUE(hasNewLineEscaped("\\\n\r"));
-  EXPECT_TRUE(hasNewLineEscaped("\\ \t\v\f\r"));
-  EXPECT_TRUE(hasNewLineEscaped("\\ \t\v\f\r\n"));
+  EXPECT_TRUE(hasNewLineEscaped("\\ \t\r\n"));
 
   EXPECT_FALSE(hasNewLineEscaped("\\\r\r"));
   EXPECT_FALSE(hasNewLineEscaped("\\\r\r\n"));
Index: clang/unittests/Lex/DependencyDirectivesSourceMinimizerTest.cpp
===
--- clang/unittests/Lex/DependencyDirectivesSourceMinimizerTest.cpp
+++ clang/unittests/Lex/DependencyDirectivesSourceMinimizerTest.cpp
@@ -162,29 +162,15 @@
   ASSERT_FALSE(minimizeSourceToDependencyDirectives(
   "#define MACRO(\t)\tcon \t tent\t", Out));
   EXPECT_STREQ("#define MACRO() con \t tent\n", Out.data());
-
-  ASSERT_FALSE(minimizeSourceToDependencyDirectives(
-  "#define MACRO(\f)\fcon \f tent\f", Out));
-  EXPECT_STREQ("#define MACRO() con \f tent\n", Out.data());
-
-  ASSERT_FALSE(minimizeSourceToDependencyDirectives(
-  "#define MACRO(\v)\vcon \v tent\v", Out));
-  EXPECT_STREQ("#define MACRO() con \v tent\n", Out.data());
-
-  ASSERT_FALSE(minimizeSourceToDependencyDirectives(
-  "#define MACRO \t\v\f\v\t con\f\t\vtent\v\f \v", Out));
-  EXPECT_STREQ("#define MACRO con\f\t\vtent\n", Out.data());
 }
 
 TEST(MinimizeSourceToDependencyDirectivesTest, DefineMultilineArgs) {
   SmallVector Out;
 
   ASSERT_FALSE(
-  minimizeSourceToDependencyDirectives("#define MACRO(a\\\n"
+  minimizeSourceToDependencyDirectives("#define MACRO(a\\\n\\\v\\\f"
"  )",
Out));
-  EXPECT_STREQ("#define MACRO(a)\n", Out.data());
-
   ASSERT_FALSE(
   minimizeSourceToDependencyDirectives("#define MACRO(a,   \\\n"
"  b)   \\\n"
Index: clang/unittests/Basic/CharInfoTest.cpp
===
--- clang/unittests/Basic/CharInfoTest.cpp
+++ clang/unittests/Basic/CharInfoTest.cpp
@@ -17,8 +17,8 @@
   using namespace charinfo;
   EXPECT_EQ((unsigned)CHAR_SPACE,   InfoTable[(unsigned)' ']);
   EXPECT_EQ((unsigned)CHAR_HORZ_WS, InfoTable[(unsigned)'\t']);
-  EXPECT_EQ((unsigned)CHAR_HORZ_WS, InfoTable[(unsigned)'\f']); // ??
-  EXPECT_EQ((unsigned)CHAR_HORZ_WS, InfoTable[(unsigned)'\v']); // ??
+  EXPECT_EQ((unsigned)CHAR_VERT_WS, InfoTable[(unsigned)'\f']);
+  EXPECT_EQ((unsigned)CHAR_VERT_WS, InfoTable[(unsigned)'\v']);
   EXPECT_EQ((unsigned)CHAR_VERT_WS, InfoTable[(unsigned)'\n']);
   EXPECT_EQ((unsigned)CHAR_VERT_WS, InfoTable[(unsigned)'\r']);
   EXPECT_EQ((unsigned)CHAR_UNDER,   InfoTable[(unsigned)'_']);
@@ -101,8 +101,6 @@
 
   EXPECT_TRUE(isHorizontalWhitespace(' '));
   EXPECT_TRUE(isHorizontalWhitespace('\t'));
-  EXPECT_TRUE(isHorizontalWhitespace('\f')); // ??
-  EXPECT_TRUE(isHorizontalWhitespace('\v')); // ??
 
   EXPECT_FALSE(isHorizontalWhitespace('\n'));
   EXPECT_FALSE(isHorizontalWhitespace('\r'));
@@ -123,9 +121,9 @@
 
   EXPECT_FALSE(isVerticalWhitespace(' '));
   EXPECT_FALSE(isVerticalWhitespace('\t'));
-  EXPECT_FALSE(isVerticalWhitespace('\f')); // ??
-  EXPECT_FALSE(isVerticalWhitespace('\v')); // ??
 
+  EXPECT_TRUE(isVerticalWhitespace('\f')); // ??
+  EXPECT_TRUE(isVerticalWhitespace('\v')); // ??
   EXPECT_TRUE(isVerticalWhitespace('\n'));
   EXPECT_TRUE(isVerticalWhitespace('\r'));
 
Index: clang/lib/Basic/CharInfo.cpp
===
--- clang/lib/Basic/CharInfo.cpp
+++ clang/lib/Basic/CharInfo.cpp
@@ -19,8 +19,8 @@
   0   , 0   , 0   , 0   ,
   // 8 BS  9 HT 10 NL 11 VT
   //12 NP 13 CR 14 SO 15 SI
-  0   , CHAR_HORZ_WS, CHAR_VERT_WS, CHAR_HORZ_WS,
-  CHAR_HORZ_WS, CHAR_VERT_WS, 0   , 0   ,
+  0   , CHAR_HORZ_WS, CHAR_VERT_WS, CHAR_VERT_WS,
+  CHAR_VERT_WS, CHAR_VERT_WS, 0   , 0   ,
   //16 DLE17 DC118 DC219 DC3
   //20 DC421 NAK22 SYN23 ETB
   0   , 0   , 0  

[libunwind] 21b25a1 - [libunwind] Support stack unwind in CET environment

2021-08-26 Thread via cfe-commits

Author: gejin
Date: 2021-08-26T16:20:38+08:00
New Revision: 21b25a1fb32ecd2e1f336123c2715f8ef1a49f97

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

LOG: [libunwind] Support stack unwind in CET environment

Control-flow Enforcement Technology (CET), published by Intel,
introduces shadow stack feature aiming to ensure a return from
a function is directed to where the function was called.
In a CET enabled system, each function call will push return
address into normal stack and shadow stack, when the function
returns, the address stored in shadow stack will be popped and
compared with the return address, program will fail if the 2
addresses don't match.
In exception handling, the control flow may skip some stack frames
and we must adjust shadow stack to avoid violating CET restriction.
In order to achieve this, we count the number of stack frames skipped
and adjust shadow stack by this number before jumping to landing pad.

Reviewed By: hjl.tools, compnerd, MaskRay
Differential Revision: https://reviews.llvm.org/D105968

Signed-off-by: gejin 

Added: 
libunwind/src/cet_unwind.h

Modified: 
libunwind/CMakeLists.txt
libunwind/src/CMakeLists.txt
libunwind/src/Registers.hpp
libunwind/src/UnwindCursor.hpp
libunwind/src/UnwindLevel1.c
libunwind/src/UnwindRegistersRestore.S
libunwind/src/UnwindRegistersSave.S
libunwind/src/assembly.h
libunwind/src/libunwind.cpp
libunwind/test/CMakeLists.txt
libunwind/test/libunwind/test/config.py
libunwind/test/lit.site.cfg.in

Removed: 




diff  --git a/libunwind/CMakeLists.txt b/libunwind/CMakeLists.txt
index a73f5b0c7bdf5..b6017382646b4 100644
--- a/libunwind/CMakeLists.txt
+++ b/libunwind/CMakeLists.txt
@@ -52,6 +52,7 @@ include(HandleCompilerRT)
 
 # Define options.
 option(LIBUNWIND_BUILD_32_BITS "Build 32 bit libunwind" ${LLVM_BUILD_32_BITS})
+option(LIBUNWIND_ENABLE_CET "Build libunwind with CET enabled." OFF)
 option(LIBUNWIND_ENABLE_ASSERTIONS "Enable assertions independent of build 
mode." ON)
 option(LIBUNWIND_ENABLE_PEDANTIC "Compile with pedantic enabled." ON)
 option(LIBUNWIND_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF)
@@ -93,6 +94,10 @@ if (NOT LIBUNWIND_ENABLE_SHARED AND NOT 
LIBUNWIND_ENABLE_STATIC)
   message(FATAL_ERROR "libunwind must be built as either a shared or static 
library.")
 endif()
 
+if (LIBUNWIND_ENABLE_CET AND MSVC)
+  message(FATAL_ERROR "libunwind CET support is not available for MSVC!")
+endif()
+
 # Check that we can build with 32 bits if requested.
 if (CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32)
   if (LIBUNWIND_BUILD_32_BITS AND NOT LLVM_BUILD_32_BITS) # Don't duplicate 
the output from LLVM
@@ -176,6 +181,17 @@ endif()
 
 add_compile_flags_if_supported(-Werror=return-type)
 
+if (LIBUNWIND_ENABLE_CET)
+  add_compile_flags_if_supported(-fcf-protection=full)
+  add_compile_flags_if_supported(-mshstk)
+  if (NOT LIBUNWIND_SUPPORTS_FCF_PROTECTION_EQ_FULL_FLAG)
+message(SEND_ERROR "Compiler doesn't support CET -fcf-protection option!")
+  endif()
+  if (NOT LIBUNWIND_SUPPORTS_MSHSTK_FLAG)
+message(SEND_ERROR "Compiler doesn't support CET -mshstk option!")
+  endif()
+endif()
+
 # Get warning flags
 add_compile_flags_if_supported(-W)
 add_compile_flags_if_supported(-Wall)

diff  --git a/libunwind/src/CMakeLists.txt b/libunwind/src/CMakeLists.txt
index 67fa61b8b0ba7..5794038fcd23f 100644
--- a/libunwind/src/CMakeLists.txt
+++ b/libunwind/src/CMakeLists.txt
@@ -34,6 +34,7 @@ set(LIBUNWIND_HEADERS
 AddressSpace.hpp
 assembly.h
 CompactUnwinder.hpp
+cet_unwind.h
 config.h
 dwarf2.h
 DwarfInstructions.hpp

diff  --git a/libunwind/src/Registers.hpp b/libunwind/src/Registers.hpp
index 0699743888e97..5e2f11fbe15ee 100644
--- a/libunwind/src/Registers.hpp
+++ b/libunwind/src/Registers.hpp
@@ -15,8 +15,9 @@
 #include 
 #include 
 
-#include "libunwind.h"
+#include "cet_unwind.h"
 #include "config.h"
+#include "libunwind.h"
 
 namespace libunwind {
 
@@ -42,6 +43,13 @@ enum {
 #if defined(_LIBUNWIND_TARGET_I386)
 class _LIBUNWIND_HIDDEN Registers_x86;
 extern "C" void __libunwind_Registers_x86_jumpto(Registers_x86 *);
+
+#if defined(_LIBUNWIND_USE_CET)
+extern "C" void *__libunwind_cet_get_jump_target() {
+  return reinterpret_cast(&__libunwind_Registers_x86_jumpto);
+}
+#endif
+
 /// Registers_x86 holds the register state of a thread in a 32-bit intel
 /// process.
 class _LIBUNWIND_HIDDEN Registers_x86 {
@@ -253,6 +261,13 @@ inline void Registers_x86::setVectorRegister(int, v128) {
 /// process.
 class _LIBUNWIND_HIDDEN Registers_x86_64;
 extern "C" void __libunwind_Registers_x86_64_jumpto(Registers_x86_64 *);
+
+#if defined(_LIBUNWIND_USE_CET)
+extern "C" void *__libunwind_cet_get_jump_target() {
+  return reinterpret_cast(&_

[PATCH] D108367: [NFC] computeSPIRKernelABIInfo(): use SPIRABInfo

2021-08-26 Thread Pekka Jääskeläinen via Phabricator via cfe-commits
pekka.jaaskelainen added a comment.

@Anastasia  I used to have svn commit access, but haven't committed anything 
for a long while in LLVM, so don't know if I can get them back to github by 
just asking. So, can you please commit these HIPSPV patches for us?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108367

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


[PATCH] D108752: [clang-format] Group options that pack constructor initializers

2021-08-26 Thread Owen Pan via Phabricator via cfe-commits
owenpan created this revision.
owenpan added reviewers: djasper, klimek, krasimir, MyDeveloperDay, curdeius, 
HazardyKnusperkeks.
owenpan added a project: clang-format.
owenpan requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Add a new option `PackConstructorInitializers` and deprecate the related 
options `ConstructorInitializerAllOnOneLineOrOnePerLine` and 
`AllowAllConstructorInitializersOnNextLine`. Below is the mapping:

  PackConstructorInitializers  ConstructorInitializer... AllowAll...
  Never-  -
  BinPackfalse-
  CurrentLinetrue   false
  NextLine   true   true

The option value `Never` fixes PR50549 
 by always placing each 
constructor initializer on its own line. Please see D105099 
 for previous discussions.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D108752

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/ContinuationIndenter.cpp
  clang/lib/Format/Format.cpp
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/FormatTest.cpp

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -5960,7 +5960,26 @@
"  at() {}");
 
   FormatStyle OnePerLine = getLLVMStyle();
-  OnePerLine.ConstructorInitializerAllOnOneLineOrOnePerLine = true;
+  OnePerLine.PackConstructorInitializers = FormatStyle::PCIS_Never;
+  verifyFormat("MyClass::MyClass()\n"
+   ": a(a),\n"
+   "  b(b),\n"
+   "  c(c) {}",
+   OnePerLine);
+  verifyFormat("MyClass::MyClass()\n"
+   ": a(a), // comment\n"
+   "  b(b),\n"
+   "  c(c) {}",
+   OnePerLine);
+  verifyFormat("MyClass::MyClass(int a)\n"
+   ": b(a),  // comment\n"
+   "  c(a + 1) { // lined up\n"
+   "}",
+   OnePerLine);
+  verifyFormat("Constructor()\n"
+   ": a(b, b, b) {}",
+   OnePerLine);
+  OnePerLine.PackConstructorInitializers = FormatStyle::PCIS_NextLine;
   OnePerLine.AllowAllParametersOfDeclarationOnNextLine = false;
   verifyFormat("SomeClass::Constructor()\n"
": a(aa),\n"
@@ -6013,8 +6032,6 @@
   FormatStyle Style = getLLVMStyle();
   Style.BreakConstructorInitializers = FormatStyle::BCIS_BeforeComma;
   Style.ColumnLimit = 60;
-  Style.ConstructorInitializerAllOnOneLineOrOnePerLine = true;
-  Style.AllowAllConstructorInitializersOnNextLine = true;
   Style.BinPackParameters = false;
 
   for (int i = 0; i < 4; ++i) {
@@ -6022,14 +6039,14 @@
 Style.AllowAllParametersOfDeclarationOnNextLine = i & 1;
 Style.AllowAllArgumentsOnNextLine = i & 2;
 
-Style.AllowAllConstructorInitializersOnNextLine = true;
+Style.PackConstructorInitializers = FormatStyle::PCIS_NextLine;
 Style.BreakConstructorInitializers = FormatStyle::BCIS_BeforeComma;
 verifyFormat("Constructor()\n"
  ": (a), b(b) {}",
  Style);
 verifyFormat("Constructor() : a(a), b(b) {}", Style);
 
-Style.AllowAllConstructorInitializersOnNextLine = false;
+Style.PackConstructorInitializers = FormatStyle::PCIS_CurrentLine;
 verifyFormat("Constructor()\n"
  ": (a)\n"
  ", b(b) {}",
@@ -6037,24 +6054,24 @@
 verifyFormat("Constructor() : a(a), b(b) {}", Style);
 
 Style.BreakConstructorInitializers = FormatStyle::BCIS_BeforeColon;
-Style.AllowAllConstructorInitializersOnNextLine = true;
+Style.PackConstructorInitializers = FormatStyle::PCIS_NextLine;
 verifyFormat("Constructor()\n"
  ": (a), b(b) {}",
  Style);
 
-Style.AllowAllConstructorInitializersOnNextLine = false;
+Style.PackConstructorInitializers = FormatStyle::PCIS_CurrentLine;
 verifyFormat("Constructor()\n"
  ": (a),\n"
  "  b(b) {}",
  Style);
 
 Style.BreakConstructorInitializers = FormatStyle::BCIS_AfterColon;
-Style.AllowAllConstructorInitializersOnNextLine = true;
+Style.PackConstructorInitializers = FormatStyle::PCIS_NextLine;
 verifyFormat("Constructor() :\n"
  "aa(a), b(b) {}",
  Style);
 
-Style.AllowAllCons

[clang] bf66b0e - Fix LLVM_ENABLE_THREADS check from 26a92d5852b2c6bf77efd26f6c0194c913f40285

2021-08-26 Thread Alex Richardson via cfe-commits

Author: Alex Richardson
Date: 2021-08-26T10:09:39+01:00
New Revision: bf66b0eefcda20170eeb574670121159fcd755fa

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

LOG: Fix LLVM_ENABLE_THREADS check from 26a92d5852b2c6bf77efd26f6c0194c913f40285

We should be using #if instead of #ifdef here since LLVM_ENABLE_THREADS
is set using #cmakedefine01 so is always defined.

Reviewed By: aaron.ballman

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

Added: 


Modified: 
clang/include/clang/Basic/Stack.h

Removed: 




diff  --git a/clang/include/clang/Basic/Stack.h 
b/clang/include/clang/Basic/Stack.h
index 3418c3bad11bd..30ebd94aedd1f 100644
--- a/clang/include/clang/Basic/Stack.h
+++ b/clang/include/clang/Basic/Stack.h
@@ -39,7 +39,7 @@ namespace clang {
   /// is insufficient, calls Diag to emit a diagnostic before calling Fn.
   inline void runWithSufficientStackSpace(llvm::function_ref Diag,
   llvm::function_ref Fn) {
-#ifdef LLVM_ENABLE_THREADS
+#if LLVM_ENABLE_THREADS
 if (LLVM_UNLIKELY(isStackNearlyExhausted()))
   runWithSufficientStackSpaceSlow(Diag, Fn);
 else



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


[clang] 7cab90a - Fix __attribute__((annotate("")) with non-zero globals AS

2021-08-26 Thread Alex Richardson via cfe-commits

Author: Alex Richardson
Date: 2021-08-26T10:09:40+01:00
New Revision: 7cab90a7b1c47780bbf7cfbfda4a1cbab24f0e5b

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

LOG: Fix __attribute__((annotate("")) with non-zero globals AS

The existing code attempting to bitcast from a value in the default globals AS
to i8 addrspace(0)* was triggering an assertion failure in our downstream fork.
I found this while compiling poppler for CHERI-RISC-V (we use AS200 for all
globals). The test case uses AMDGPU since that is one of the in-tree targets
with a non-zero default globals address space.
The new test previously triggered a "Invalid constantexpr bitcast!" assertion
and now correctly generates code with addrspace(1) pointers.

Reviewed By: rjmccall

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

Added: 


Modified: 
clang/lib/CodeGen/CodeGenModule.cpp
clang/lib/CodeGen/CodeGenTypeCache.h
clang/test/CodeGen/annotations-global.c

Removed: 




diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 87a15dbeb1b7f..664acefd1815c 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -130,8 +130,9 @@ CodeGenModule::CodeGenModule(ASTContext &C, const 
HeaderSearchOptions &HSO,
 C.getTargetInfo().getMaxPointerWidth());
   Int8PtrTy = Int8Ty->getPointerTo(0);
   Int8PtrPtrTy = Int8PtrTy->getPointerTo(0);
-  AllocaInt8PtrTy = Int8Ty->getPointerTo(
-  M.getDataLayout().getAllocaAddrSpace());
+  const llvm::DataLayout &DL = M.getDataLayout();
+  AllocaInt8PtrTy = Int8Ty->getPointerTo(DL.getAllocaAddrSpace());
+  GlobalsInt8PtrTy = Int8Ty->getPointerTo(DL.getDefaultGlobalsAddressSpace());
   ASTAllocaAddressSpace = getTargetCodeGenInfo().getASTAllocaAddressSpace();
 
   RuntimeCC = getTargetCodeGenInfo().getABIInfo().getRuntimeCC();
@@ -2532,7 +2533,7 @@ llvm::Constant 
*CodeGenModule::EmitAnnotationLineNo(SourceLocation L) {
 llvm::Constant *CodeGenModule::EmitAnnotationArgs(const AnnotateAttr *Attr) {
   ArrayRef Exprs = {Attr->args_begin(), Attr->args_size()};
   if (Exprs.empty())
-return llvm::ConstantPointerNull::get(Int8PtrTy);
+return llvm::ConstantPointerNull::get(GlobalsInt8PtrTy);
 
   llvm::FoldingSetNodeID ID;
   for (Expr *E : Exprs) {
@@ -2556,7 +2557,7 @@ llvm::Constant *CodeGenModule::EmitAnnotationArgs(const 
AnnotateAttr *Attr) {
   ".args");
   GV->setSection(AnnotationSection);
   GV->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
-  auto *Bitcasted = llvm::ConstantExpr::getBitCast(GV, Int8PtrTy);
+  auto *Bitcasted = llvm::ConstantExpr::getBitCast(GV, GlobalsInt8PtrTy);
 
   Lookup = Bitcasted;
   return Bitcasted;
@@ -2571,17 +2572,19 @@ llvm::Constant 
*CodeGenModule::EmitAnnotateAttr(llvm::GlobalValue *GV,
  *LineNoCst = EmitAnnotationLineNo(L),
  *Args = EmitAnnotationArgs(AA);
 
-  llvm::Constant *ASZeroGV = GV;
-  if (GV->getAddressSpace() != 0) {
-ASZeroGV = llvm::ConstantExpr::getAddrSpaceCast(
-   GV, GV->getValueType()->getPointerTo(0));
+  llvm::Constant *GVInGlobalsAS = GV;
+  if (GV->getAddressSpace() !=
+  getDataLayout().getDefaultGlobalsAddressSpace()) {
+GVInGlobalsAS = llvm::ConstantExpr::getAddrSpaceCast(
+GV, GV->getValueType()->getPointerTo(
+getDataLayout().getDefaultGlobalsAddressSpace()));
   }
 
   // Create the ConstantStruct for the global annotation.
   llvm::Constant *Fields[] = {
-  llvm::ConstantExpr::getBitCast(ASZeroGV, Int8PtrTy),
-  llvm::ConstantExpr::getBitCast(AnnoGV, Int8PtrTy),
-  llvm::ConstantExpr::getBitCast(UnitGV, Int8PtrTy),
+  llvm::ConstantExpr::getBitCast(GVInGlobalsAS, GlobalsInt8PtrTy),
+  llvm::ConstantExpr::getBitCast(AnnoGV, GlobalsInt8PtrTy),
+  llvm::ConstantExpr::getBitCast(UnitGV, GlobalsInt8PtrTy),
   LineNoCst,
   Args,
   };

diff  --git a/clang/lib/CodeGen/CodeGenTypeCache.h 
b/clang/lib/CodeGen/CodeGenTypeCache.h
index f258234fb4d8f..577f88367a3a6 100644
--- a/clang/lib/CodeGen/CodeGenTypeCache.h
+++ b/clang/lib/CodeGen/CodeGenTypeCache.h
@@ -69,6 +69,12 @@ struct CodeGenTypeCache {
 llvm::PointerType *AllocaInt8PtrTy;
   };
 
+  /// void* in default globals address space
+  union {
+llvm::PointerType *GlobalsVoidPtrTy;
+llvm::PointerType *GlobalsInt8PtrTy;
+  };
+
   /// The size and alignment of the builtin C type 'int'.  This comes
   /// up enough in various ABI lowering tasks to be worth pre-computing.
   union {

diff  --git a/clang/test/CodeGen/annotations-global.c 
b/clang/test/CodeGen/annotations-global.c
index 5afec5b4eb72e..2a5c847fd9602 100644
--- a/clang/test/CodeGen/annotations-global.c
+++ b/clang/test/CodeGen/annotations-gl

[PATCH] D108110: Fix LLVM_ENABLE_THREADS check from 26a92d5852b2c6bf77efd26f6c0194c913f40285

2021-08-26 Thread Alexander Richardson via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGbf66b0eefcda: Fix LLVM_ENABLE_THREADS check from 
26a92d5852b2c6bf77efd26f6c0194c913f40285 (authored by arichardson).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108110

Files:
  clang/include/clang/Basic/Stack.h


Index: clang/include/clang/Basic/Stack.h
===
--- clang/include/clang/Basic/Stack.h
+++ clang/include/clang/Basic/Stack.h
@@ -39,7 +39,7 @@
   /// is insufficient, calls Diag to emit a diagnostic before calling Fn.
   inline void runWithSufficientStackSpace(llvm::function_ref Diag,
   llvm::function_ref Fn) {
-#ifdef LLVM_ENABLE_THREADS
+#if LLVM_ENABLE_THREADS
 if (LLVM_UNLIKELY(isStackNearlyExhausted()))
   runWithSufficientStackSpaceSlow(Diag, Fn);
 else


Index: clang/include/clang/Basic/Stack.h
===
--- clang/include/clang/Basic/Stack.h
+++ clang/include/clang/Basic/Stack.h
@@ -39,7 +39,7 @@
   /// is insufficient, calls Diag to emit a diagnostic before calling Fn.
   inline void runWithSufficientStackSpace(llvm::function_ref Diag,
   llvm::function_ref Fn) {
-#ifdef LLVM_ENABLE_THREADS
+#if LLVM_ENABLE_THREADS
 if (LLVM_UNLIKELY(isStackNearlyExhausted()))
   runWithSufficientStackSpaceSlow(Diag, Fn);
 else
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D105972: Fix __attribute__((annotate("")) with non-zero globals AS

2021-08-26 Thread Alexander Richardson via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG7cab90a7b1c4: Fix __attribute__((annotate("")) 
with non-zero globals AS (authored by arichardson).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105972

Files:
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenTypeCache.h
  clang/test/CodeGen/annotations-global.c


Index: clang/test/CodeGen/annotations-global.c
===
--- clang/test/CodeGen/annotations-global.c
+++ clang/test/CodeGen/annotations-global.c
@@ -4,6 +4,7 @@
 // RUN: FileCheck --check-prefix=BAR %s < %t1
 // RUN: FileCheck --check-prefix=FOOS %s < %t1
 // RUN: FileCheck --check-prefix=ADDRSPACE %s < %t1
+// RUN: %clang_cc1 %s -triple r600 -emit-llvm -o - | FileCheck %s 
--check-prefix AS1-GLOBALS
 // END.
 
 static __attribute((annotate("sfoo_0"))) __attribute((annotate("sfoo_1"))) 
char sfoo;
@@ -45,3 +46,8 @@
 
 // ADDRSPACE: target triple
 // ADDRSPACE: @llvm.global.annotations = appending global {{.*}} addrspacecast 
(i8 addrspace(1)* @addrspace1_var to i8*), {{.*}}
+
+// AS1-GLOBALS: target datalayout = "{{.+}}-A5-G1"
+// AS1-GLOBALS: @llvm.global.annotations = appending addrspace(1) global [11 x 
{ i8 addrspace(1)*, i8 addrspace(1)*, i8 addrspace(1)*, i32, i8 addrspace(1)* }]
+// AS1-GLOBALS-SAME: { i8 addrspace(1)* @a.bar,
+// AS1-GLOBALS-SAME: { i8 addrspace(1)* @addrspace1_var,
Index: clang/lib/CodeGen/CodeGenTypeCache.h
===
--- clang/lib/CodeGen/CodeGenTypeCache.h
+++ clang/lib/CodeGen/CodeGenTypeCache.h
@@ -69,6 +69,12 @@
 llvm::PointerType *AllocaInt8PtrTy;
   };
 
+  /// void* in default globals address space
+  union {
+llvm::PointerType *GlobalsVoidPtrTy;
+llvm::PointerType *GlobalsInt8PtrTy;
+  };
+
   /// The size and alignment of the builtin C type 'int'.  This comes
   /// up enough in various ABI lowering tasks to be worth pre-computing.
   union {
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -130,8 +130,9 @@
 C.getTargetInfo().getMaxPointerWidth());
   Int8PtrTy = Int8Ty->getPointerTo(0);
   Int8PtrPtrTy = Int8PtrTy->getPointerTo(0);
-  AllocaInt8PtrTy = Int8Ty->getPointerTo(
-  M.getDataLayout().getAllocaAddrSpace());
+  const llvm::DataLayout &DL = M.getDataLayout();
+  AllocaInt8PtrTy = Int8Ty->getPointerTo(DL.getAllocaAddrSpace());
+  GlobalsInt8PtrTy = Int8Ty->getPointerTo(DL.getDefaultGlobalsAddressSpace());
   ASTAllocaAddressSpace = getTargetCodeGenInfo().getASTAllocaAddressSpace();
 
   RuntimeCC = getTargetCodeGenInfo().getABIInfo().getRuntimeCC();
@@ -2532,7 +2533,7 @@
 llvm::Constant *CodeGenModule::EmitAnnotationArgs(const AnnotateAttr *Attr) {
   ArrayRef Exprs = {Attr->args_begin(), Attr->args_size()};
   if (Exprs.empty())
-return llvm::ConstantPointerNull::get(Int8PtrTy);
+return llvm::ConstantPointerNull::get(GlobalsInt8PtrTy);
 
   llvm::FoldingSetNodeID ID;
   for (Expr *E : Exprs) {
@@ -2556,7 +2557,7 @@
   ".args");
   GV->setSection(AnnotationSection);
   GV->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
-  auto *Bitcasted = llvm::ConstantExpr::getBitCast(GV, Int8PtrTy);
+  auto *Bitcasted = llvm::ConstantExpr::getBitCast(GV, GlobalsInt8PtrTy);
 
   Lookup = Bitcasted;
   return Bitcasted;
@@ -2571,17 +2572,19 @@
  *LineNoCst = EmitAnnotationLineNo(L),
  *Args = EmitAnnotationArgs(AA);
 
-  llvm::Constant *ASZeroGV = GV;
-  if (GV->getAddressSpace() != 0) {
-ASZeroGV = llvm::ConstantExpr::getAddrSpaceCast(
-   GV, GV->getValueType()->getPointerTo(0));
+  llvm::Constant *GVInGlobalsAS = GV;
+  if (GV->getAddressSpace() !=
+  getDataLayout().getDefaultGlobalsAddressSpace()) {
+GVInGlobalsAS = llvm::ConstantExpr::getAddrSpaceCast(
+GV, GV->getValueType()->getPointerTo(
+getDataLayout().getDefaultGlobalsAddressSpace()));
   }
 
   // Create the ConstantStruct for the global annotation.
   llvm::Constant *Fields[] = {
-  llvm::ConstantExpr::getBitCast(ASZeroGV, Int8PtrTy),
-  llvm::ConstantExpr::getBitCast(AnnoGV, Int8PtrTy),
-  llvm::ConstantExpr::getBitCast(UnitGV, Int8PtrTy),
+  llvm::ConstantExpr::getBitCast(GVInGlobalsAS, GlobalsInt8PtrTy),
+  llvm::ConstantExpr::getBitCast(AnnoGV, GlobalsInt8PtrTy),
+  llvm::ConstantExpr::getBitCast(UnitGV, GlobalsInt8PtrTy),
   LineNoCst,
   Args,
   };


Index: clang/test/CodeGen/annotations-global.c
===
--- clang/test/CodeGen/annotations-global.c
+++ clang/test/CodeGen/annotations-global.c
@@ -4,6 +4,7 @@
 // RUN: FileCheck --check-prefix=BAR %s < %t1
 /

[libunwind] 5ece556 - [libunwind] Don't include cet.h/immintrin.h unconditionally

2021-08-26 Thread Benjamin Kramer via cfe-commits

Author: Benjamin Kramer
Date: 2021-08-26T11:37:07+02:00
New Revision: 5ece5562719dde1d8e88fdb41ec5ac0cf6f05274

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

LOG: [libunwind] Don't include cet.h/immintrin.h unconditionally

These may not exist when CET isn't available.

Added: 


Modified: 
libunwind/src/cet_unwind.h

Removed: 




diff  --git a/libunwind/src/cet_unwind.h b/libunwind/src/cet_unwind.h
index eac0bf12a3a6d..482e0c8086a20 100644
--- a/libunwind/src/cet_unwind.h
+++ b/libunwind/src/cet_unwind.h
@@ -11,8 +11,6 @@
 #define LIBUNWIND_CET_UNWIND_H
 
 #include "libunwind.h"
-#include 
-#include 
 
 // Currently, CET is implemented on Linux x86 platforms.
 #if defined(_LIBUNWIND_TARGET_LINUX) && defined(__CET__) && defined(__SHSTK__)
@@ -20,6 +18,9 @@
 #endif
 
 #if defined(_LIBUNWIND_USE_CET)
+#include 
+#include 
+
 #define _LIBUNWIND_POP_CET_SSP(x)  
\
   do { 
\
 unsigned long ssp = _get_ssp();
\



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


[PATCH] D108753: [analyzer] MallocChecker: Add notes from NoOwnershipChangeVisitor only when a function "intents", but doesn't change ownership, enable by default

2021-08-26 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus created this revision.
Szelethus added reviewers: NoQ, martong, steakhal, balazske, ASDenysPetrov, 
vsavchenko.
Szelethus added a project: clang.
Herald added subscribers: manas, gamesh411, dkrupp, donat.nagy, 
mikhail.ramalho, a.sidorin, rnkovacs, szepet, baloghadamsoftware, xazax.hun, 
whisperity, yaxunl.
Szelethus requested review of this revision.
Herald added a subscriber: cfe-commits.

D105819  Added NoOwnershipChangeVisitor, but 
it is only registered when an off-by-default, hidden checker option was 
enabled. The reason behind this was that it grossly overestimated the set of 
functions that really needed a note:

  std::string getTrainName(const Train *T) {
return T->name;
  } // note: Retuning without changing the ownership of or deallocating memory
  // Umm... I mean duh? Nor would I expect this function to do anything like 
that...
  
  void foo() {
Train *T = new Train("Land Plane");
print(getTrainName(T)); // note: calling getTrainName / returning from 
getTrainName
  } // warn: Memory leak

This patch adds a heuristic that guesses that any function that has an explicit 
`operator delete` call could have be responsible for deallocating the memory 
that ended up leaking. This is wy too conservative (see the TODOs in the 
new function), but it safer to err on the side of too little than too much, and 
would allow us to enable the option by default *now*, and add refinements 
one-by-one.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D108753

Files:
  clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
  clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
  clang/test/Analysis/NewDeleteLeaks.cpp
  clang/test/Analysis/analyzer-config.c

Index: clang/test/Analysis/analyzer-config.c
===
--- clang/test/Analysis/analyzer-config.c
+++ clang/test/Analysis/analyzer-config.c
@@ -116,7 +116,7 @@
 // CHECK-NEXT: suppress-null-return-paths = true
 // CHECK-NEXT: track-conditions = true
 // CHECK-NEXT: track-conditions-debug = false
-// CHECK-NEXT: unix.DynamicMemoryModeling:AddNoOwnershipChangeNotes = false
+// CHECK-NEXT: unix.DynamicMemoryModeling:AddNoOwnershipChangeNotes = true
 // CHECK-NEXT: unix.DynamicMemoryModeling:Optimistic = false
 // CHECK-NEXT: unroll-loops = false
 // CHECK-NEXT: widen-loops = false
Index: clang/test/Analysis/NewDeleteLeaks.cpp
===
--- clang/test/Analysis/NewDeleteLeaks.cpp
+++ clang/test/Analysis/NewDeleteLeaks.cpp
@@ -20,15 +20,16 @@
 
 bool coin();
 
+// TODO: AST analysis of sink would reveal that it doesn't indent to free the
+// allocated memory, but in this instance, its also the only function with
+// the ability to do so, we should see a note here.
 namespace memory_allocated_in_fn_call {
 
 void sink(int *P) {
-} // ownership-note {{Returning without deallocating memory or storing the pointer for later deallocation}}
+}
 
 void foo() {
   sink(new int(5)); // expected-note {{Memory is allocated}}
-// ownership-note@-1 {{Calling 'sink'}}
-// ownership-note@-2 {{Returning from 'sink'}}
 } // expected-warning {{Potential memory leak [cplusplus.NewDeleteLeaks]}}
 // expected-note@-1 {{Potential memory leak}}
 
@@ -109,17 +110,14 @@
 
 } // namespace memory_shared_with_ptr_of_same_lifetime
 
-// TODO: We don't want a note here. sink() doesn't seem like a function that
-// even attempts to take care of any memory ownership problems.
 namespace memory_passed_into_fn_that_doesnt_intend_to_free {
 
 void sink(int *P) {
-} // ownership-note {{Returning without deallocating memory or storing the pointer for later deallocation}}
+}
 
 void foo() {
   int *ptr = new int(5); // expected-note {{Memory is allocated}}
-  sink(ptr); // ownership-note {{Calling 'sink'}}
- // ownership-note@-1 {{Returning from 'sink'}}
+  sink(ptr);
 } // expected-warning {{Potential leak of memory pointed to by 'ptr' [cplusplus.NewDeleteLeaks]}}
 // expected-note@-1 {{Potential leak}}
 
Index: clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
@@ -52,6 +52,7 @@
 #include "clang/AST/Expr.h"
 #include "clang/AST/ExprCXX.h"
 #include "clang/AST/ParentMap.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
 #include "clang/Analysis/ProgramPoint.h"
 #include "clang/Basic/LLVM.h"
 #include "clang/Basic/SourceManager.h"
@@ -737,6 +738,7 @@
 // Definition of NoOwnershipChangeVisitor.
 //===--===//
 
+#include "clang/ASTMatchers/ASTMatchFinder.h"
 namespace {
 class NoOwnershipChangeVisitor final : public NoStateChangeFuncVisitor {
   SymbolRef Sym;
@@ -791,9 +793,28 @@
 return "";
   

[clang] 564d85e - The maximal representable alignment in LLVM IR is 1GiB, not 512MiB

2021-08-26 Thread Roman Lebedev via cfe-commits

Author: Roman Lebedev
Date: 2021-08-26T12:53:39+03:00
New Revision: 564d85e090afdaac6475d43708d77a7fa0cf5301

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

LOG: The maximal representable alignment in LLVM IR is 1GiB, not 512MiB

In LLVM IR, `AlignmentBitfieldElementT` is 5-bit wide
But that means that the maximal alignment exponent is `(1<<5)-2`,
which is `30`, not `29`. And indeed, alignment of `1073741824`
roundtrips IR serialization-deserialization.

While this doesn't seem all that important, this doubles
the maximal supported alignment from 512MiB to 1GiB,
and there's actually one noticeable use-case for that;
On X86, the huge pages can have sizes of 2MiB and 1GiB (!).

So while this doesn't add support for truly huge alignments,
which i think we can easily-ish do if wanted, i think this adds
zero-cost support for a not-trivially-dismissable case.

I don't believe we need any upgrade infrastructure,
and since we don't explicitly record the IR version,
we don't need to bump one either.

As @craig.topper speculates in D108661#2963519,
this might be an artificial limit imposed by the original implementation
of the `getAlignment()` functions.

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

Added: 
llvm/test/CodeGen/MIR/X86/load-with-1gb-alignment.mir

Modified: 
clang/include/clang/Sema/Sema.h
clang/test/CXX/drs/dr6xx.cpp
clang/test/CodeGen/builtin-assume-aligned.c

clang/test/CodeGen/catch-alignment-assumption-attribute-align_value-on-paramvar.cpp

clang/test/CodeGen/catch-alignment-assumption-builtin_assume_aligned-three-params-variable.cpp

clang/test/CodeGen/catch-alignment-assumption-builtin_assume_aligned-three-params.cpp

clang/test/CodeGen/catch-alignment-assumption-builtin_assume_aligned-two-params.cpp
clang/test/CodeGen/catch-alignment-assumption-openmp.cpp
clang/test/Sema/alloc-align-attr.c
clang/test/Sema/attr-aligned.c
clang/test/Sema/builtin-assume-aligned.c
clang/test/SemaCXX/alloc-align-attr.cpp
llvm/include/llvm/IR/Instruction.h
llvm/include/llvm/IR/Value.h
llvm/test/Assembler/align-inst-alloca.ll
llvm/test/Assembler/align-inst-load.ll
llvm/test/Assembler/align-inst-store.ll
llvm/test/Assembler/align-inst.ll
llvm/test/Bitcode/inalloca.ll
llvm/test/Transforms/Attributor/ArgumentPromotion/live_called_from_dead.ll
llvm/test/Transforms/Attributor/ArgumentPromotion/live_called_from_dead_2.ll
llvm/test/Transforms/Attributor/IPConstantProp/PR26044.ll
llvm/test/Transforms/Attributor/IPConstantProp/pthreads.ll
llvm/test/Transforms/Attributor/callbacks.ll
llvm/test/Transforms/Attributor/liveness.ll
llvm/test/Transforms/Attributor/memory_locations.ll
llvm/test/Transforms/Attributor/noalias.ll
llvm/test/Transforms/Attributor/nocapture-1.ll
llvm/test/Transforms/Attributor/noundef.ll
llvm/test/Transforms/Attributor/undefined_behavior.ll
llvm/test/Transforms/Attributor/value-simplify.ll
llvm/test/Transforms/GVN/PRE/2017-06-28-pre-load-dbgloc.ll
llvm/test/Transforms/InstCombine/atomic.ll
llvm/test/Transforms/InstCombine/getelementptr.ll
llvm/test/Transforms/InstCombine/load.ll
llvm/test/Transforms/InstCombine/mempcpy.ll
llvm/test/Transforms/InstCombine/pr44245.ll
llvm/test/Transforms/InstCombine/store.ll
llvm/test/Transforms/OpenMP/parallel_level_fold.ll
llvm/test/Verifier/align-md.ll
llvm/unittests/IR/ValueTest.cpp

Removed: 




diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 188e94a9645be..d5c685ee9791f 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -396,7 +396,7 @@ class Sema final {
   ///
   /// This is the greatest alignment value supported by load, store, and alloca
   /// instructions, and global values.
-  static const unsigned MaxAlignmentExponent = 29;
+  static const unsigned MaxAlignmentExponent = 30;
   static const unsigned MaximumAlignment = 1u << MaxAlignmentExponent;
 
   typedef OpaquePtr DeclGroupPtrTy;

diff  --git a/clang/test/CXX/drs/dr6xx.cpp b/clang/test/CXX/drs/dr6xx.cpp
index e9e08fd2e2c00..efca2b4292748 100644
--- a/clang/test/CXX/drs/dr6xx.cpp
+++ b/clang/test/CXX/drs/dr6xx.cpp
@@ -551,9 +551,11 @@ namespace dr648 { // dr648: yes
 
 #if __cplusplus >= 201103L
 namespace dr649 { // dr649: yes
-  alignas(0x4000) int n; // expected-error {{requested alignment}}1
-  struct alignas(0x4000) X {}; // expected-error {{requested alignment}}
-  struct Y { int n alignas(0x4000); }; // expected-error {{requested 
alignment}}
+alignas(0x8000) int n;   // expected-error {{requested alignment}}1
+struct alignas(0x8000) X {}; // expected-error {{requested alignment}}
+struct Y {
+  int n align

[PATCH] D108661: The maximal representable alignment in LLVM IR is 1GiB, not 512MiB

2021-08-26 Thread Roman Lebedev via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rG564d85e090af: The maximal representable alignment in LLVM IR 
is 1GiB, not 512MiB (authored by lebedev.ri).

Changed prior to commit:
  https://reviews.llvm.org/D108661?vs=368744&id=368837#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108661

Files:
  clang/include/clang/Sema/Sema.h
  clang/test/CXX/drs/dr6xx.cpp
  clang/test/CodeGen/builtin-assume-aligned.c
  
clang/test/CodeGen/catch-alignment-assumption-attribute-align_value-on-paramvar.cpp
  
clang/test/CodeGen/catch-alignment-assumption-builtin_assume_aligned-three-params-variable.cpp
  
clang/test/CodeGen/catch-alignment-assumption-builtin_assume_aligned-three-params.cpp
  
clang/test/CodeGen/catch-alignment-assumption-builtin_assume_aligned-two-params.cpp
  clang/test/CodeGen/catch-alignment-assumption-openmp.cpp
  clang/test/Sema/alloc-align-attr.c
  clang/test/Sema/attr-aligned.c
  clang/test/Sema/builtin-assume-aligned.c
  clang/test/SemaCXX/alloc-align-attr.cpp
  llvm/include/llvm/IR/Instruction.h
  llvm/include/llvm/IR/Value.h
  llvm/test/Assembler/align-inst-alloca.ll
  llvm/test/Assembler/align-inst-load.ll
  llvm/test/Assembler/align-inst-store.ll
  llvm/test/Assembler/align-inst.ll
  llvm/test/Bitcode/inalloca.ll
  llvm/test/CodeGen/MIR/X86/load-with-1gb-alignment.mir
  llvm/test/Transforms/Attributor/ArgumentPromotion/live_called_from_dead.ll
  llvm/test/Transforms/Attributor/ArgumentPromotion/live_called_from_dead_2.ll
  llvm/test/Transforms/Attributor/IPConstantProp/PR26044.ll
  llvm/test/Transforms/Attributor/IPConstantProp/pthreads.ll
  llvm/test/Transforms/Attributor/callbacks.ll
  llvm/test/Transforms/Attributor/liveness.ll
  llvm/test/Transforms/Attributor/memory_locations.ll
  llvm/test/Transforms/Attributor/noalias.ll
  llvm/test/Transforms/Attributor/nocapture-1.ll
  llvm/test/Transforms/Attributor/noundef.ll
  llvm/test/Transforms/Attributor/undefined_behavior.ll
  llvm/test/Transforms/Attributor/value-simplify.ll
  llvm/test/Transforms/GVN/PRE/2017-06-28-pre-load-dbgloc.ll
  llvm/test/Transforms/InstCombine/atomic.ll
  llvm/test/Transforms/InstCombine/getelementptr.ll
  llvm/test/Transforms/InstCombine/load.ll
  llvm/test/Transforms/InstCombine/mempcpy.ll
  llvm/test/Transforms/InstCombine/pr44245.ll
  llvm/test/Transforms/InstCombine/store.ll
  llvm/test/Transforms/OpenMP/parallel_level_fold.ll
  llvm/test/Verifier/align-md.ll
  llvm/unittests/IR/ValueTest.cpp

Index: llvm/unittests/IR/ValueTest.cpp
===
--- llvm/unittests/IR/ValueTest.cpp
+++ llvm/unittests/IR/ValueTest.cpp
@@ -61,9 +61,9 @@
  GlobalVariable::NotThreadLocal,
  1);
 
-  EXPECT_TRUE(Value::MaximumAlignment == 536870912U);
-  Dummy0->setAlignment(Align(536870912));
-  EXPECT_EQ(Dummy0->getAlignment(), 536870912U);
+  EXPECT_TRUE(Value::MaximumAlignment == 1073741824U);
+  Dummy0->setAlignment(Align(1073741824));
+  EXPECT_EQ(Dummy0->getAlignment(), 1073741824U);
 
   // Make sure the address space isn't dropped when returning this.
   Constant *Dummy1 = M->getOrInsertGlobal("dummy", Int32Ty);
@@ -101,7 +101,7 @@
  Constant::getAllOnesValue(Int32Ty), "var", nullptr,
  GlobalVariable::NotThreadLocal, 1);
 
-  EXPECT_DEATH(Var->setAlignment(Align(1073741824U)),
+  EXPECT_DEATH(Var->setAlignment(Align(2147483648U)),
"Alignment is greater than MaximumAlignment");
 }
 #endif
Index: llvm/test/Verifier/align-md.ll
===
--- llvm/test/Verifier/align-md.ll
+++ llvm/test/Verifier/align-md.ll
@@ -52,8 +52,8 @@
 
 define i8* @f7(i8** %x) {
 entry:
-  %y = load i8*, i8** %x, !align !{i64 1073741824}
+  %y = load i8*, i8** %x, !align !{i64 2147483648}
   ret i8* %y
 }
 ; CHECK: alignment is larger that implementation defined limit
-; CHECK-NEXT: load i8*, i8** %x
\ No newline at end of file
+; CHECK-NEXT: load i8*, i8** %x
Index: llvm/test/Transforms/OpenMP/parallel_level_fold.ll
===
--- llvm/test/Transforms/OpenMP/parallel_level_fold.ll
+++ llvm/test/Transforms/OpenMP/parallel_level_fold.ll
@@ -49,9 +49,9 @@
 
 define weak void @parallel() {
 ; CHECK-LABEL: define {{[^@]+}}@parallel() {
-; CHECK-NEXT:[[I:%.*]] = call i32 @__kmpc_target_init(%struct.ident_t* align 536870912 null, i1 true, i1 false, i1 false)
+; CHECK-NEXT:[[I:%.*]] = call i32 @__kmpc_target_init(%struct.ident_t* align 1073741824 null, i1 true, i1 false, i1 false)
 ; CHECK-NEXT:call void @spmd_helper()
-; CHECK-NEXT:call void @__kmpc_parallel_51(%struct.ident_t* noalias noundef align 536870912 null, i32 noundef 0, i32 noundef 0, i32 nound

[PATCH] D106191: [clang] Option control afn flag

2021-08-26 Thread Qiu Chaofan via Phabricator via cfe-commits
qiucf added a comment.

Making a new option mapped to another float op flag looks reasonable, but is 
there any clearer motivation for this? (such as the need for `-Ofast 
-fno-approx-func`)




Comment at: llvm/include/llvm/Target/TargetOptions.h:179
+/// with approximate calculations
+unsigned ApproxFuncFPMath : 1;
+

`-enable-no-signed-zeros-fp-math` is an `llc` flag.

Do we really have `-enable-approx-func-fp-math` for `llc` now?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106191

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


[PATCH] D107078: [analyzer] Catch leaking stack addresses via stack variables

2021-08-26 Thread Balázs Benics via Phabricator via cfe-commits
steakhal marked an inline comment as done.
steakhal added a comment.

I plan to commit to this tomorrow. @NoQ @martong


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

https://reviews.llvm.org/D107078

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


[PATCH] D107078: [analyzer] Catch leaking stack addresses via stack variables

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

Oh wait, it's not yet accepted by @NoQ. Then, consider this as a polite ping.


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

https://reviews.llvm.org/D107078

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


[clang] de15979 - Assert pointer cannot be null; NFC

2021-08-26 Thread Aaron Ballman via cfe-commits

Author: Sindhu Chittireddy
Date: 2021-08-26T06:58:56-04:00
New Revision: de15979bc32d761c9b5071fb7d28d7c04ebbfaf3

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

LOG: Assert pointer cannot be null; NFC

Klocwork static code analysis exposed this concern:
Pointer 'SubExpr' returned from call to getSubExpr() function which may
return NULL from 'cast_or_null(Operand)', which will be
dereferenced in the statement following it

Add an assert on SubExpr to make it clear this pointer cannot be null.

Added: 


Modified: 
clang/lib/CodeGen/MicrosoftCXXABI.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/MicrosoftCXXABI.cpp 
b/clang/lib/CodeGen/MicrosoftCXXABI.cpp
index 990648b131fe..6522ea58c27c 100644
--- a/clang/lib/CodeGen/MicrosoftCXXABI.cpp
+++ b/clang/lib/CodeGen/MicrosoftCXXABI.cpp
@@ -4348,6 +4348,7 @@ llvm::GlobalVariable 
*MicrosoftCXXABI::getThrowInfo(QualType T) {
 
 void MicrosoftCXXABI::emitThrow(CodeGenFunction &CGF, const CXXThrowExpr *E) {
   const Expr *SubExpr = E->getSubExpr();
+  assert(SubExpr && "SubExpr cannot be null");
   QualType ThrowType = SubExpr->getType();
   // The exception object lives on the stack and it's address is passed to the
   // runtime function.



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


[PATCH] D108756: [clang] Add '-ast-dump-filter=' support

2021-08-26 Thread Tommy Chiang via Phabricator via cfe-commits
oToToT created this revision.
oToToT added reviewers: rsmith, alexfh.
oToToT added a project: clang.
Herald added a subscriber: dang.
oToToT requested review of this revision.
Herald added a subscriber: cfe-commits.

Before this patch, we only support syntax like
`clang -cc1 -ast-dump -ast-dump-filter main a.c`
or
`clang -Xclang -ast-dump -Xclang -ast-dump-filter -Xclang main a.c`
when using ast-dump-filter.

It is helpful to also support `-ast-dump-filter=` syntax, so we can do 
something like
`clang -cc1 -ast-dump -ast-dump-filter=main a.c`
or
`clang -Xclang -ast-dump -Xclang -ast-dump-filter=main a.c`

It is more cleaner when passing arguments through `-Xclang` in this case.

Also, **clang-check** do support this syntax, and I think people might be 
confused when they found they can't use `-ast-dump-filter` with clang.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D108756

Files:
  clang/include/clang/Driver/Options.td


Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -5277,6 +5277,8 @@
" nodes having a certain substring in a qualified name. Use"
" -ast-list to list all filterable declaration node names.">,
   MarshallingInfoString>;
+def ast_dump_filter_EQ : Joined<["-"], "ast-dump-filter=">,
+  Alias;
 def fno_modules_global_index : Flag<["-"], "fno-modules-global-index">,
   HelpText<"Do not automatically generate or update the global module index">,
   MarshallingInfoNegativeFlag>;


Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -5277,6 +5277,8 @@
" nodes having a certain substring in a qualified name. Use"
" -ast-list to list all filterable declaration node names.">,
   MarshallingInfoString>;
+def ast_dump_filter_EQ : Joined<["-"], "ast-dump-filter=">,
+  Alias;
 def fno_modules_global_index : Flag<["-"], "fno-modules-global-index">,
   HelpText<"Do not automatically generate or update the global module index">,
   MarshallingInfoNegativeFlag>;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D108712: Avoid nullptr dereferencing of 'SubExpr'; NFC

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

I've committed on your behalf in de15979bc32d761c9b5071fb7d28d7c04ebbfaf3 
, thank 
you for the improvement!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108712

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


[PATCH] D107873: [clang-tidy] Add 'performance-const-parameter-value-or-ref' for checking const-qualified parameters

2021-08-26 Thread Julien Marrec via Phabricator via cfe-commits
jmarrec added a comment.

Imported some discussion from https://reviews.llvm.org/D107900#inline-1029358. 
Sorry it took that long




Comment at: 
clang-tools-extra/clang-tidy/performance/ConstParameterValueOrRef.h:40
+  static constexpr int DefaultSmallMaxSize = 16;
+  int SmallMaxSize = Options.get("SmallMaxSize", DefaultSmallMaxSize);
+

https://reviews.llvm.org/D107900#inline-1029358


On mine, I had another option `RestrictToBuiltInTypes` which I find an 
interesting option. It has a ` builtinType()` matcher in the registerMatchers 
function



Comment at: 
clang-tools-extra/clang-tidy/performance/ConstParameterValueOrRef.h:43
+  bool ForwardDeclarationsSuppressWarnings =
+  Options.get("ForwardDeclarationsSuppressWarnings", true);
+

Perhaps two additional options to turn off either "side" would be helpful? eg 
`CheckPassByValueIsAppropriate` and `CheckPassByRefIsAppropriate`, both 
defaulted to `true`



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/performance-const-parameter-value-or-ref.rst:44
+  // warning: 'const int' is a small, trivially copyable type: pass by value 
instead
+  // fix-it: void f6(const int i) {}
+

https://reviews.llvm.org/D107900#inline-1029358

I am removing the `const` as well in addition to the `&`. I guess you may be 
just relying on using it in conjunction with 
`readability-avoid-const-params-in-decls` but I think that makes it harder to 
use (you can't just do `-checks=-*,` you have to remember to add the 
`readability-avoid-const-params-in-decls` too...).

Taht being said, perhaps that's how it's meant to be...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107873

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


[PATCH] D108761: [OpenCL] Remove decls for scalar vloada_half and vstorea_half* fns

2021-08-26 Thread Stuart Brady via Phabricator via cfe-commits
stuart created this revision.
stuart added reviewers: svenvh, Anastasia, airlied, yaxunl.
Herald added a subscriber: ldrumm.
stuart requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

These functions are not part of the OpenCL C specification.

See https://github.com/KhronosGroup/OpenCL-Docs/issues/648 for a clarification 
regarding the vloada_half declaration.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D108761

Files:
  clang/lib/Headers/opencl-c.h
  clang/lib/Sema/OpenCLBuiltins.td

Index: clang/lib/Sema/OpenCLBuiltins.td
===
--- clang/lib/Sema/OpenCLBuiltins.td
+++ clang/lib/Sema/OpenCLBuiltins.td
@@ -836,7 +836,6 @@
 multiclass VloadVstoreHalf addrspaces, bit defStores> {
   foreach AS = addrspaces in {
 def : Builtin<"vload_half", [Float, Size, PointerType, AS>]>;
-def : Builtin<"vloada_half", [Float, Size, PointerType, AS>]>;
 foreach VSize = [2, 3, 4, 8, 16] in {
   foreach name = ["vload_half" # VSize] in {
 def : Builtin, Size, PointerType, AS>]>;
@@ -844,7 +843,7 @@
 }
 if defStores then {
   foreach rnd = ["", "_rte", "_rtz", "_rtp", "_rtn"] in {
-foreach name = ["vstore_half" # rnd, "vstorea_half" # rnd] in {
+foreach name = ["vstore_half" # rnd] in {
   def : Builtin]>;
   def : Builtin]>;
 }
Index: clang/lib/Headers/opencl-c.h
===
--- clang/lib/Headers/opencl-c.h
+++ clang/lib/Headers/opencl-c.h
@@ -12070,33 +12070,28 @@
  * The address computed as (p + (offset * 4))
  * must be aligned to sizeof (half) * 4 bytes.
  */
-float __ovld vloada_half(size_t offset, const __constant half *p);
 float2 __ovld vloada_half2(size_t offset, const __constant half *p);
 float3 __ovld vloada_half3(size_t offset, const __constant half *p);
 float4 __ovld vloada_half4(size_t offset, const __constant half *p);
 float8 __ovld vloada_half8(size_t offset, const __constant half *p);
 float16 __ovld vloada_half16(size_t offset, const __constant half *p);
 #if defined(__opencl_c_generic_address_space)
-float __ovld vloada_half(size_t offset, const half *p);
 float2 __ovld vloada_half2(size_t offset, const half *p);
 float3 __ovld vloada_half3(size_t offset, const half *p);
 float4 __ovld vloada_half4(size_t offset, const half *p);
 float8 __ovld vloada_half8(size_t offset, const half *p);
 float16 __ovld vloada_half16(size_t offset, const half *p);
 #else
-float __ovld vloada_half(size_t offset, const __global half *p);
 float2 __ovld vloada_half2(size_t offset, const __global half *p);
 float3 __ovld vloada_half3(size_t offset, const __global half *p);
 float4 __ovld vloada_half4(size_t offset, const __global half *p);
 float8 __ovld vloada_half8(size_t offset, const __global half *p);
 float16 __ovld vloada_half16(size_t offset, const __global half *p);
-float __ovld vloada_half(size_t offset, const __local half *p);
 float2 __ovld vloada_half2(size_t offset, const __local half *p);
 float3 __ovld vloada_half3(size_t offset, const __local half *p);
 float4 __ovld vloada_half4(size_t offset, const __local half *p);
 float8 __ovld vloada_half8(size_t offset, const __local half *p);
 float16 __ovld vloada_half16(size_t offset, const __local half *p);
-float __ovld vloada_half(size_t offset, const __private half *p);
 float2 __ovld vloada_half2(size_t offset, const __private half *p);
 float3 __ovld vloada_half3(size_t offset, const __private half *p);
 float4 __ovld vloada_half4(size_t offset, const __private half *p);
@@ -12121,35 +12116,30 @@
  * round to nearest even.
  */
 #if defined(__opencl_c_generic_address_space)
-void __ovld vstorea_half(float data, size_t offset, half *p);
 void __ovld vstorea_half2(float2 data, size_t offset, half *p);
 void __ovld vstorea_half3(float3 data, size_t offset, half *p);
 void __ovld vstorea_half4(float4 data, size_t offset, half *p);
 void __ovld vstorea_half8(float8 data, size_t offset, half *p);
 void __ovld vstorea_half16(float16 data, size_t offset, half *p);
 
-void __ovld vstorea_half_rte(float data, size_t offset, half *p);
 void __ovld vstorea_half2_rte(float2 data, size_t offset, half *p);
 void __ovld vstorea_half3_rte(float3 data, size_t offset, half *p);
 void __ovld vstorea_half4_rte(float4 data, size_t offset, half *p);
 void __ovld vstorea_half8_rte(float8 data, size_t offset, half *p);
 void __ovld vstorea_half16_rte(float16 data, size_t offset, half *p);
 
-void __ovld vstorea_half_rtz(float data, size_t offset, half *p);
 void __ovld vstorea_half2_rtz(float2 data, size_t offset, half *p);
 void __ovld vstorea_half3_rtz(float3 data, size_t offset, half *p);
 void __ovld vstorea_half4_rtz(float4 data, size_t offset, half *p);
 void __ovld vstorea_half8_rtz(float8 data, size_t offset, half *p);
 void __ovld vstorea_half16_rtz(float16 data, size_t offset, half *p);
 
-void __ovld vstore

[PATCH] D108752: [clang-format] Group options that pack constructor initializers

2021-08-26 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay accepted this revision.
MyDeveloperDay added a comment.
This revision is now accepted and ready to land.

This looks good, I like to move towards one style, it was getting too 
confusing. Did you test this on a large code base at all? and maybe wait for 
one of the others to take a look.

I'll pull the patch to my local source and see if it makes any changes, but to 
be honest we only use the `BreakConstructorInitializersBeforeComma` option


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108752

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


[PATCH] D108618: [CGCall] Add NoInline attr if presented for the target

2021-08-26 Thread Djordje Todorovic via Phabricator via cfe-commits
djtodoro added a comment.

In D108618#2964265 , @rjmccall wrote:

> Why do you want to add `noinline` to a function declaration that lacks a 
> definition?

If this won't be used at all I guess the compiler should throw a warning at 
least.
One example comes to my mind, and it includes LTO (and cross-compile unit 
inlining).

  $ cat test-1.c
  extern int __attribute__((noinline)) bar(void);
  
  int foo() {
  int v1 = bar();
  if (v1 > 100)
return 0;
  v1--;
  return v1;
  }
  
  $ cat $ cat test-2.c
  int __attribute__((always_inline)) bar(void);
  
  int foo2() {
  int v2 = bar();   
  if (v2 > 1000)
return 0;
  v2++;
  return v2;
  }
  
  $ cat test.c
  #include 
  
  extern int foo();
  extern int foo2();
  
  int bar() {
  int x;
  scanf("%d", &x);
  ++x;
  return x;
  }
  
  
  int main()
  {
  int i = foo();
  int j = foo2();
  return i - j;
  }
  
  $ clang test.c -g -S -flto -emit-llvm
  $ clang test-1.c -g -S -flto -emit-llvm
  $ clang test-2.c -g -S -flto -emit-llvm
  
  $ llvm-link -S -o linked.ll test-1.ll test-2.ll test.ll
  $ opt -S -O1 linked.ll -o optimized.ll

Having these simple compile units, I can expect that compiler is able to inline 
the `bar()` into `foo2()` but not into `foo()`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108618

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


[clang] 6097a41 - [analyzer] Extend the documentation of MallocOverflow

2021-08-26 Thread Balazs Benics via cfe-commits

Author: Balazs Benics
Date: 2021-08-26T15:20:41+02:00
New Revision: 6097a41924584b613153237d8e66e9660001ce7d

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

LOG: [analyzer] Extend the documentation of MallocOverflow

Previously by following the documentation it was not immediately clear
what the capabilities of this checker are.

In this patch, I add some clarification on when does the checker issue a
report and what it's limitations are.
I'm also advertising suppressing such reports by adding an assertion, as
demonstrated by the test3().
I'm highlighting that this checker might produce an extensive amount of
findings, but it might be still useful for code audits.

Reviewed By: martong

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

Added: 


Modified: 
clang/docs/analyzer/checkers.rst

Removed: 




diff  --git a/clang/docs/analyzer/checkers.rst 
b/clang/docs/analyzer/checkers.rst
index 9a74dffc1658d..66c540ec0b544 100644
--- a/clang/docs/analyzer/checkers.rst
+++ b/clang/docs/analyzer/checkers.rst
@@ -2154,7 +2154,14 @@ Warn about buffer overflows (newer checker).
 
 alpha.security.MallocOverflow (C)
 "
-Check for overflows in the arguments to malloc().
+Check for overflows in the arguments to ``malloc()``.
+It tries to catch ``malloc(n * c)`` patterns, where:
+ - ``n``: a variable or member access of an object
+ - ``c``: a constant foldable integral
+
+This checker was designed for code audits, so expect false-positive reports.
+One is supposed to silence this checker by ensuring proper bounds checking on
+the variable in question using e.g. an ``assert()`` or a branch.
 
 .. code-block:: c
 
@@ -2168,6 +2175,26 @@ Check for overflows in the arguments to malloc().
void *p = malloc(n * sizeof(int)); // no warning
  }
 
+ void test3(int n) {
+   assert(n <= 100 && "Contract violated.");
+   void *p = malloc(n * sizeof(int)); // no warning
+ }
+
+Limitations:
+ - The checker won't warn for variables involved in explicit casts,
+   since that might limit the variable's domain.
+   E.g.: ``(unsigned char)int x`` would limit the domain to ``[0,255]``.
+   The checker will miss the true-positive cases when the explicit cast would
+   not tighten the domain to prevent the overflow in the subsequent
+   multiplication operation.
+
+ - If the variable ``n`` participates in a comparison anywhere in the enclosing
+   function's scope, even after the ``malloc()``, the report will be still
+   suppressed.
+
+ - It is an AST-based checker, thus it does not make use of the
+   path-sensitive taint-analysis.
+
 .. _alpha-security-MmapWriteExec:
 
 alpha.security.MmapWriteExec (C)



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


[PATCH] D107756: [analyzer] Extend the documentation of MallocOverflow

2021-08-26 Thread Balázs Benics via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG6097a4192458: [analyzer] Extend the documentation of 
MallocOverflow (authored by steakhal).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107756

Files:
  clang/docs/analyzer/checkers.rst


Index: clang/docs/analyzer/checkers.rst
===
--- clang/docs/analyzer/checkers.rst
+++ clang/docs/analyzer/checkers.rst
@@ -2154,7 +2154,14 @@
 
 alpha.security.MallocOverflow (C)
 "
-Check for overflows in the arguments to malloc().
+Check for overflows in the arguments to ``malloc()``.
+It tries to catch ``malloc(n * c)`` patterns, where:
+ - ``n``: a variable or member access of an object
+ - ``c``: a constant foldable integral
+
+This checker was designed for code audits, so expect false-positive reports.
+One is supposed to silence this checker by ensuring proper bounds checking on
+the variable in question using e.g. an ``assert()`` or a branch.
 
 .. code-block:: c
 
@@ -2168,6 +2175,26 @@
void *p = malloc(n * sizeof(int)); // no warning
  }
 
+ void test3(int n) {
+   assert(n <= 100 && "Contract violated.");
+   void *p = malloc(n * sizeof(int)); // no warning
+ }
+
+Limitations:
+ - The checker won't warn for variables involved in explicit casts,
+   since that might limit the variable's domain.
+   E.g.: ``(unsigned char)int x`` would limit the domain to ``[0,255]``.
+   The checker will miss the true-positive cases when the explicit cast would
+   not tighten the domain to prevent the overflow in the subsequent
+   multiplication operation.
+
+ - If the variable ``n`` participates in a comparison anywhere in the enclosing
+   function's scope, even after the ``malloc()``, the report will be still
+   suppressed.
+
+ - It is an AST-based checker, thus it does not make use of the
+   path-sensitive taint-analysis.
+
 .. _alpha-security-MmapWriteExec:
 
 alpha.security.MmapWriteExec (C)


Index: clang/docs/analyzer/checkers.rst
===
--- clang/docs/analyzer/checkers.rst
+++ clang/docs/analyzer/checkers.rst
@@ -2154,7 +2154,14 @@
 
 alpha.security.MallocOverflow (C)
 "
-Check for overflows in the arguments to malloc().
+Check for overflows in the arguments to ``malloc()``.
+It tries to catch ``malloc(n * c)`` patterns, where:
+ - ``n``: a variable or member access of an object
+ - ``c``: a constant foldable integral
+
+This checker was designed for code audits, so expect false-positive reports.
+One is supposed to silence this checker by ensuring proper bounds checking on
+the variable in question using e.g. an ``assert()`` or a branch.
 
 .. code-block:: c
 
@@ -2168,6 +2175,26 @@
void *p = malloc(n * sizeof(int)); // no warning
  }
 
+ void test3(int n) {
+   assert(n <= 100 && "Contract violated.");
+   void *p = malloc(n * sizeof(int)); // no warning
+ }
+
+Limitations:
+ - The checker won't warn for variables involved in explicit casts,
+   since that might limit the variable's domain.
+   E.g.: ``(unsigned char)int x`` would limit the domain to ``[0,255]``.
+   The checker will miss the true-positive cases when the explicit cast would
+   not tighten the domain to prevent the overflow in the subsequent
+   multiplication operation.
+
+ - If the variable ``n`` participates in a comparison anywhere in the enclosing
+   function's scope, even after the ``malloc()``, the report will be still
+   suppressed.
+
+ - It is an AST-based checker, thus it does not make use of the
+   path-sensitive taint-analysis.
+
 .. _alpha-security-MmapWriteExec:
 
 alpha.security.MmapWriteExec (C)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 379b639 - Revert "[analyzer] Extend the documentation of MallocOverflow"

2021-08-26 Thread Balazs Benics via cfe-commits

Author: Balazs Benics
Date: 2021-08-26T15:29:32+02:00
New Revision: 379b6394d9ca254593b77ec3c0028e6d820715e4

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

LOG: Revert "[analyzer] Extend the documentation of MallocOverflow"

This reverts commit 6097a41924584b613153237d8e66e9660001ce7d.

Added: 


Modified: 
clang/docs/analyzer/checkers.rst

Removed: 




diff  --git a/clang/docs/analyzer/checkers.rst 
b/clang/docs/analyzer/checkers.rst
index 66c540ec0b544..9a74dffc1658d 100644
--- a/clang/docs/analyzer/checkers.rst
+++ b/clang/docs/analyzer/checkers.rst
@@ -2154,14 +2154,7 @@ Warn about buffer overflows (newer checker).
 
 alpha.security.MallocOverflow (C)
 "
-Check for overflows in the arguments to ``malloc()``.
-It tries to catch ``malloc(n * c)`` patterns, where:
- - ``n``: a variable or member access of an object
- - ``c``: a constant foldable integral
-
-This checker was designed for code audits, so expect false-positive reports.
-One is supposed to silence this checker by ensuring proper bounds checking on
-the variable in question using e.g. an ``assert()`` or a branch.
+Check for overflows in the arguments to malloc().
 
 .. code-block:: c
 
@@ -2175,26 +2168,6 @@ the variable in question using e.g. an ``assert()`` or a 
branch.
void *p = malloc(n * sizeof(int)); // no warning
  }
 
- void test3(int n) {
-   assert(n <= 100 && "Contract violated.");
-   void *p = malloc(n * sizeof(int)); // no warning
- }
-
-Limitations:
- - The checker won't warn for variables involved in explicit casts,
-   since that might limit the variable's domain.
-   E.g.: ``(unsigned char)int x`` would limit the domain to ``[0,255]``.
-   The checker will miss the true-positive cases when the explicit cast would
-   not tighten the domain to prevent the overflow in the subsequent
-   multiplication operation.
-
- - If the variable ``n`` participates in a comparison anywhere in the enclosing
-   function's scope, even after the ``malloc()``, the report will be still
-   suppressed.
-
- - It is an AST-based checker, thus it does not make use of the
-   path-sensitive taint-analysis.
-
 .. _alpha-security-MmapWriteExec:
 
 alpha.security.MmapWriteExec (C)



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


[PATCH] D106343: [OpenCL] Support cl_ext_float_atomics

2021-08-26 Thread Yang Haonan via Phabricator via cfe-commits
haonanya added a comment.

Hi, svenvh.
Should we use cl_khr_int64_base_atomics and cl_khr_int64_extended_atomics to 
guard  the functions using atomic_double type?
Thanks very much.

  #if defined(__opencl_c_ext_fp64_local_atomic_min_max)
  double __ovld atomic_fetch_min(volatile __local atomic_double *object,
 double operand);
  #endif




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

https://reviews.llvm.org/D106343

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


[PATCH] D108138: [SimplifyCFG] Remove switch statements before vectorization

2021-08-26 Thread Kerry McLaughlin via Phabricator via cfe-commits
kmclaughlin added a comment.

Thanks all for the suggestions on this patch :)

I had a look at the LowerSwitch pass as suggested by @junparser, and I did find 
that running it before vectorisation transforms the switch and allows the same 
loops to be vectorised. However, I did find that if the loop is not vectorised 
then the switch is not created again later by SimplifyCFG (possibly because the 
pass is also arbitrarily splitting cases into ranges and creating multiple 
branches to the default block?). Tests such as 
Transforms/PhaseOrdering/X86/simplifycfg-late.ll then fail, which attempts to 
convert a switch statement into a lookup table.

For example, running the @switch_no_vectorize test (from remove-switches.ll) 
with -lowerswitch results in:

  for.body: ; preds = %L3, %entry
%i = phi i64 [ %inc, %L3 ], [ 0, %entry ]
%sum.033 = phi float [ %conv20, %L3 ], [ 2.00e+00, %entry ]
%arrayidx = getelementptr inbounds i32, i32* %a, i64 %i
%0 = load i32, i32* %arrayidx, align 4
br label %NodeBlock
  
  NodeBlock:; preds = %for.body
%Pivot = icmp slt i32 %0, 3
br i1 %Pivot, label %LeafBlock, label %LeafBlock1
  
  LeafBlock1:   ; preds = %NodeBlock
%SwitchLeaf2 = icmp eq i32 %0, 3
br i1 %SwitchLeaf2, label %L3, label %NewDefault
  
  LeafBlock:; preds = %NodeBlock
%SwitchLeaf = icmp eq i32 %0, 2
br i1 %SwitchLeaf, label %L2, label %NewDefault
  
  NewDefault:   ; preds = %LeafBlock1, 
%LeafBlock
br label %L1

I also found that any weights assigned to the switch statement are ignored when 
creating the new branches in LowerSwitch.

I'm not sure what the best approach to this is - I could try to change 
LowerSwitch to create branches which SimplifyCFG will be able to recognise and 
replace with a switch, or try to change SimplifyCFG to recognise this pattern 
of compares & branches. Alternatively, the changes in this patch could be used 
as the basis for a new pass which runs before the vectoriser. I wondered if 
anyone has any thoughts or preferences on which would be the best option here?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108138

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


[PATCH] D108138: [SimplifyCFG] Remove switch statements before vectorization

2021-08-26 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

IMO anything other than enhancing LV is wrong.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108138

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


[PATCH] D107756: [analyzer] Extend the documentation of MallocOverflow

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

I'm not exactly sure what does the sphinx build bot complain about:

  Warning, treated as error:
  
/home/buildbot/llvm-build-dir/clang-sphinx-docs/llvm/build/tools/clang/docs/analyzer/checkers.rst:2159:Unexpected
 indentation.

Unfortunately, I could not (yet) set up sphinx locally, so I cannot reproduce 
this.
Does anyone have it have sphinx ready to go? Am I on the right track?




Comment at: clang/docs/analyzer/checkers.rst:2159-2160
+It tries to catch ``malloc(n * c)`` patterns, where:
+ - ``n``: a variable or member access of an object
+ - ``c``: a constant foldable integral
+

Am I supposed to indent this with 2 spaces? Or what.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107756

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


[PATCH] D108138: [SimplifyCFG] Remove switch statements before vectorization

2021-08-26 Thread David Sherwood via Phabricator via cfe-commits
david-arm added a comment.

In D108138#2967100 , @lebedev.ri 
wrote:

> IMO anything other than enhancing LV is wrong.

Hi @lebedev.ri  I personally disagree here. Adding support to LV for this is 
significantly more work (and IMO unnecessary) because there are cases when LV 
has to handle a lot more than just the obvious flattened vectorisation case 
using vector comparisons and select instructions. We will also need to add 
support for vectorisation factors of 1 (with interleaving) and cases where 
VF>1,but we have to scalarise the switch statement. These latter two cases 
require basically doing exactly the same thing as @kmclaughlin's patch does 
here, i.e. unswitching the switch statement into compares/branches and new 
blocks. It seems far simpler to have a small pass that runs prior to the 
vectoriser (when enabled) that unswitches.

Not sure what others think here?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108138

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


[PATCH] D108138: [SimplifyCFG] Remove switch statements before vectorization

2021-08-26 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

How is it conceptually different to break apart IR in LV itself, or do the same 
in a special pass just before that?
If we want to go this road, we need to completely make `switch`es 
illegal/non-canonical before LV.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108138

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


[PATCH] D107775: [Clang][AST] Resolve FIXME: Remove ObjCObjectPointer from isSpecifierType

2021-08-26 Thread David Goldman via Phabricator via cfe-commits
dgoldman added a comment.

> I put a case for it in the declprinter so it is handled appropriately so it 
> would get the pointee type, whereas before this was neglected.
>
> Other than that, there should be no difference.

It looks like DeclPrinter only uses that method here 

 - so it shouldn't make a difference.

but TypePrinter does call `isSpecifierType()` so this changes that behavior, 
right? Can you add a test to TypePrinterTest for this change?


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

https://reviews.llvm.org/D107775

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


[PATCH] D108138: [SimplifyCFG] Remove switch statements before vectorization

2021-08-26 Thread David Sherwood via Phabricator via cfe-commits
david-arm added a comment.

In D108138#2967133 , @lebedev.ri 
wrote:

> How is it conceptually different to break apart IR in LV itself, or do the 
> same in a special pass just before that?
> If we want to go this road, we need to completely make `switch`es 
> illegal/non-canonical before LV.

If I understand correctly you're suggesting that LV makes a scalar 
transformation prior to legalisation checks/cost model analysis? If that's the 
case then I don't think we can do that as this is beyond LV's remit and I don't 
see how that's any different to making a scalar transformation in a separate 
pass prior to LV.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108138

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


[PATCH] D108138: [SimplifyCFG] Remove switch statements before vectorization

2021-08-26 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

In D108138#2967156 , @david-arm wrote:

> In D108138#2967133 , @lebedev.ri 
> wrote:
>
>> How is it conceptually different to break apart IR in LV itself, or do the 
>> same in a special pass just before that?
>> If we want to go this road, we need to completely make `switch`es 
>> illegal/non-canonical before LV.
>
> If I understand correctly you're suggesting that LV makes a scalar 
> transformation prior to legalisation checks/cost model analysis? If that's 
> the case then I don't think we can do that as this is beyond LV's remit and I 
> don't see how that's any different to making a scalar transformation in a 
> separate pass prior to LV.

Actually no, i'm saying that since LV is not allowed to do such scalar 
transformations,
doing the same scalar transfomation, but just outside of LV, doesn't change the 
fact
that we've just made a preparatory transformation in hope that it will allow LV,
without actually knowing that. If it doesn't, we now need to undo it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108138

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


[PATCH] D105269: [X86] AVX512FP16 instructions enabling 6/6

2021-08-26 Thread LuoYuanke via Phabricator via cfe-commits
LuoYuanke added inline comments.



Comment at: clang/test/CodeGen/X86/avx512fp16-builtins.c:4223
+
+// CFC ADD PH
+

MADD?



Comment at: clang/test/CodeGen/X86/avx512fp16-builtins.c:4315
+
+// CF ADD PH
+

MADD?



Comment at: llvm/include/llvm/IR/IntrinsicsX86.td:5732
+
+  def int_x86_avx512fp16_mask_vfcmaddc_ph_128
+  : GCCBuiltin<"__builtin_ia32_vfcmaddcph128_mask">,

_cph?



Comment at: llvm/include/llvm/IR/IntrinsicsX86.td:5796
+  [ IntrNoMem, ImmArg> ]>;
+  def int_x86_avx512fp16_mask_vfmaddc_sh
+  : GCCBuiltin<"__builtin_ia32_vfmaddcsh_mask">,

_csh?



Comment at: llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp:3902
+  case X86::VFCMADDCSHZr:
+  case X86::VFCMADDCSHZrb:
+  case X86::VFCMADDCSHZrbk:

"b" means rounding. Right?



Comment at: llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp:3948
+for (unsigned i = 2; i < Inst.getNumOperands(); i++)
+  if (Inst.getOperand(i).isReg() && Dest == Inst.getOperand(i).getReg())
+return Warning(Ops[0]->getStartLoc(), "Destination register should be "

Sorry, I didn't find the constrain in the spec.



Comment at: llvm/lib/Target/X86/X86ISelLowering.cpp:47289
+return 0;
+  if (RHS->getOpcode() == ISD::BITCAST && RHS.hasOneUse() &&
+  (RHS->getOperand(0)->getOpcode() == X86ISD::VFMULC ||

Can swap LHS and RHS reduce some redundant code?



Comment at: llvm/lib/Target/X86/X86ISelLowering.cpp:47296
+};
+int MulId = getMulId();
+const TargetOptions &Options = DAG.getTarget().Options;

The lambda seems only be called once.



Comment at: llvm/lib/Target/X86/X86ISelLowering.cpp:47298
+const TargetOptions &Options = DAG.getTarget().Options;
+if ((Options.AllowFPOpFusion == FPOpFusion::Fast || Options.UnsafeFPMath) 
&&
+MulId < 2 && Subtarget.hasFP16() && IsAdd &&

Is it possible fast and non-fast instruction is mixed due to inline? Shall we 
check the instruction AllowContract flag?



Comment at: llvm/lib/Target/X86/X86ISelLowering.cpp:47359
+//  t23: v16f32 = X86ISD::VFCMULC[X86ISD::VFMULC]
+//  t8, t22
+//  t24: v32f16 = bitcast t23

Merge it to previous line.



Comment at: llvm/lib/Target/X86/X86InstrAVX512.td:5781
+ (MaskOpNode  _.RC:$src1, (_.VT (_.BroadcastLdFrag 
addr:$src2))),
+ 0, 0, 0, ClobberConstraint>,
  EVEX_4V, EVEX_B,

Moving ClobberConstraint before IsCommutable  saves the code for default value?



Comment at: llvm/lib/Target/X86/X86InstrAVX512.td:13604
+
+  defm VFMULCPH  : avx512_cfmbinop_common<0xD6, "vfmulcph", x86vfmulc, 
x86vfmulc,
+x86vfmulcRnd>, T_MAP6XS, EVEX_CD8<32, 
CD8VF>;

The name seems not accurate. Is it cfmop for mul and cfmaop for fma?



Comment at: llvm/lib/Target/X86/X86InstrAVX512.td:13640
+(v4f32 (OpNode VR128X:$src1, VR128X:$src2)),
+0, 0, 0, X86selects, "@earlyclobber $dst">, 
Sched<[sched.XMM]>;
+defm rm : AVX512_maskablehttps://reviews.llvm.org/D105269/new/

https://reviews.llvm.org/D105269

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


[PATCH] D106191: [clang] Option control afn flag

2021-08-26 Thread Masoud Ataei via Phabricator via cfe-commits
masoud.ataei added a comment.

In D106191#2966852 , @qiucf wrote:

> Making a new option mapped to another float op flag looks reasonable, but is 
> there any clearer motivation for this? (such as the need for `-Ofast 
> -fno-approx-func`)

This patch https://reviews.llvm.org/D101759 is the real motivation for option 
controlling afn flag. We want to have a way to distinguishes getting `_finite` 
or `non-finite` version of MASS functions. Only with afn flag (on O3 
), we want to get `non-finite` 
version of MASS functions. (finite version need extra fast-math flags.)




Comment at: llvm/include/llvm/Target/TargetOptions.h:179
+/// with approximate calculations
+unsigned ApproxFuncFPMath : 1;
+

qiucf wrote:
> `-enable-no-signed-zeros-fp-math` is an `llc` flag.
> 
> Do we really have `-enable-approx-func-fp-math` for `llc` now?
I am adding and using this option in https://reviews.llvm.org/D101759 patch. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106191

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


[PATCH] D108765: [docs] Fix documentation of clang-format BasedOnStyle type

2021-08-26 Thread Ludovic Jozeau via Phabricator via cfe-commits
FederAndInk created this revision.
FederAndInk requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Fix little inconsistency and use `std::string` (which is used everywhere
else) instead of `string`


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D108765

Files:
  clang/docs/ClangFormatStyleOptions.rst


Index: clang/docs/ClangFormatStyleOptions.rst
===
--- clang/docs/ClangFormatStyleOptions.rst
+++ clang/docs/ClangFormatStyleOptions.rst
@@ -125,7 +125,7 @@
 the configuration (without a prefix: ``Auto``).
 
 
-**BasedOnStyle** (``string``)
+**BasedOnStyle** (``std::string``)
   The style used for all options not specifically set in the configuration.
 
   This option is supported only in the :program:`clang-format` configuration


Index: clang/docs/ClangFormatStyleOptions.rst
===
--- clang/docs/ClangFormatStyleOptions.rst
+++ clang/docs/ClangFormatStyleOptions.rst
@@ -125,7 +125,7 @@
 the configuration (without a prefix: ``Auto``).
 
 
-**BasedOnStyle** (``string``)
+**BasedOnStyle** (``std::string``)
   The style used for all options not specifically set in the configuration.
 
   This option is supported only in the :program:`clang-format` configuration
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D108138: [SimplifyCFG] Remove switch statements before vectorization

2021-08-26 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 added a comment.

>> I could try to change LowerSwitch to create branches which SimplifyCFG will 
>> be able to recognise and replace with a switch, or try to change SimplifyCFG 
>> to recognise this pattern of compares & branches.



2. option is better.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108138

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


[PATCH] D101759: [PowerPC] Scalar IBM MASS library conversion pass

2021-08-26 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

Do we *really* need `-enable-approx-func-fp-math`?
I'm pretty sure we are moving away from such global options, onto relying only 
on the per-instruction fast-math flags.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101759

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


[PATCH] D108138: [SimplifyCFG] Remove switch statements before vectorization

2021-08-26 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 added a comment.

>> I had a look at the LowerSwitch pass as suggested by @junparser, and I did 
>> find that running it before vectorisation transforms the switch and allows 
>> the same loops to be vectorised. However, I did find that if the loop is not 
>> vectorised then the switch is not created again later by SimplifyCFG

Maybe always lower switch in loops before LV?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108138

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


[PATCH] D107900: [clang-tidy] Add a new clang-tidy check for trivially copyable types passed by const reference

2021-08-26 Thread Julien Marrec via Phabricator via cfe-commits
jmarrec updated this revision to Diff 368881.
jmarrec added a comment.

documentation updates


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107900

Files:
  clang-tools-extra/clang-tidy/misc/CMakeLists.txt
  clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
  clang-tools-extra/clang-tidy/misc/PodConstRefToValueCheck.cpp
  clang-tools-extra/clang-tidy/misc/PodConstRefToValueCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/docs/clang-tidy/checks/misc-pod-const-ref-to-value.rst
  clang-tools-extra/test/clang-tidy/checkers/misc-pod-const-ref-to-value.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/misc-pod-const-ref-to-value.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/misc-pod-const-ref-to-value.cpp
@@ -0,0 +1,75 @@
+// RUN: %check_clang_tidy %s misc-pod-const-ref-to-value %t
+
+int f1(const int &i);
+// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: argument 'i' is a trivially copyable type and should not be passed by const-reference but by value [misc-pod-const-ref-to-value]
+// CHECK-FIXES: int f1(int i);
+int f2(const int &i, double d);
+// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: argument 'i' is a trivially copyable type and should not be passed by const-reference but by value [misc-pod-const-ref-to-value]
+// CHECK-FIXES: int f2(int i, double d);
+
+int f3(double d, const int &i);
+// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: argument 'i' is a trivially copyable type and should not be passed by const-reference but by value [misc-pod-const-ref-to-value]
+// CHECK-FIXES: int f3(double d, int i);
+
+int f4(const double &d, const double &d2);
+// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: argument 'd' is a trivially copyable type and should not be passed by const-reference but by value [misc-pod-const-ref-to-value]
+// CHECK-MESSAGES: :[[@LINE-2]]:25: warning: argument 'd2' is a trivially copyable type and should not be passed by const-reference but by value [misc-pod-const-ref-to-value]
+// CHECK-FIXES: int f4(double d, double d2);
+
+// clang-format off
+int f5(const int& i);
+// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: argument 'i' is a trivially copyable type and should not be passed by const-reference but by value [misc-pod-const-ref-to-value]
+// CHECK-FIXES: int f5(int i);
+// clang-format on
+
+namespace n1 {
+class A {
+  static int g(const double &d);
+  // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: argument 'd' is a trivially copyable type and should not be passed by const-reference but by value [misc-pod-const-ref-to-value]
+  // CHECK-FIXES: static int g(double d);
+};
+
+int A::g(const double &d) {
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: argument 'd' is a trivially copyable type and should not be passed by const-reference but by value [misc-pod-const-ref-to-value]
+  // CHECK-FIXES: int A::g(double d) {
+  return static_cast(d);
+}
+} // namespace n1
+
+// Not triggering the check
+
+int f5(int i);
+int f6(int i, double d);
+int f7(int &i); // Might be used for return...
+
+namespace n2 {
+class A {
+  static int g(double d);
+};
+
+int A::g(double d) {
+  return static_cast(d);
+}
+
+class B {
+  static int g(double &d);
+};
+
+int B::g(double &d) {
+  return static_cast(d);
+}
+} // namespace n2
+
+template 
+void f(Args &&...args);
+
+struct Widget {
+  int a[1000];
+};
+void f(const Widget &);
+
+template 
+struct Max {
+  static T max(const T &a, const T &b);
+};
+int x = Max::max(1, 2); // passes `int` by const reference, but this is fine
Index: clang-tools-extra/docs/clang-tidy/checks/misc-pod-const-ref-to-value.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/misc-pod-const-ref-to-value.rst
@@ -0,0 +1,25 @@
+.. title:: clang-tidy - misc-pod-const-ref-to-value
+
+misc-pod-const-ref-to-value
+===
+
+This check detects when ``trivially_copyable`` types are passed by const-reference
+to a function and changes that to by value/
+
+For example in the following code, it is replaced by ``void f(int i, double d)``:
+
+.. code-block:: c++
+
+  void f(const int& i, const double& d);
+
+
+Options
+---
+
+.. option:: RestrictToBuiltInTypes
+
+   If set to `true`, this check will limit itself to the `builtinType()` types. Default is `false`.
+
+.. option:: MaxSize
+
+   MaxSize: int, default 16. Above this size, passing by const-reference makes sense
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
@@ -215,6 +215,7 @@
`misc-no-recursion `_,
`misc-non-copyable-objects `_,
`misc-non-private-member-variables-in-classes `_,
+   `misc-pod-const-ref-to

[PATCH] D108765: [docs] Fix documentation of clang-format BasedOnStyle type

2021-08-26 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay requested changes to this revision.
MyDeveloperDay added a comment.
This revision now requires changes to proceed.

Thank you for your submission, but...

1. This is not the way to change this file, its autogenerated from 
clang/include/Format/Format.h using  clang/docs/tools/dump_format_style.py
2. Why do you think it should be std::string? To be honest this file pretty 
much describes the `YAML` file format of `.clang-format` so actually I would 
suggest it saying string was more correct

I think the main problem is options like this:

F18679590: image.png 

Here we say its a `std::vector` which doesn't really tell you 
much, as its actually just a `YAML` array of `RawStringFormat` records without 
actually telling you what a `RawStringFormat` record contains

  RawStringFormats:
- Language: TextProto
Delimiters:
  - 'pb'
  - 'proto'
EnclosingFunctions:
  - 'PARSE_TEXT_PROTO'
BasedOnStyle: google
- Language: Cpp
Delimiters:
  - 'cc'
  - 'cpp'
BasedOnStyle: llvm
CanonicalDelimiter: 'cc'

So whilst I see that you were being consistent I kind of feel its in the wrong 
direction, we should be moving away from using `C++` names here but more 
explaining what the `YAML` should look like.

Alas the C++ in Format.h is important because the types are needed because we 
are generating the documentation directly from the code. But in most of places 
we are using an enumeration like this one.

F18679643: image.png 

we are not saying  `clang::FormatStyle::RefernceAlignmentStyle` and I'm not 
convinced we'd want to

I hope that helps, but thank you for the patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108765

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


[PATCH] D107764: [OpenMP][OpenMPIRBuilder] Implement loop unrolling.

2021-08-26 Thread Kiran Chandramohan via Phabricator via cfe-commits
kiranchandramohan added a comment.

I have a few minor questions.




Comment at: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp:2055
+/// Attach loop metadata \p Properties to the loop described by \p Loop. If the
+/// loop already has metadata, the loop properties are appended.
+static void addLoopMetadata(CanonicalLoopInfo *Loop,

Nit: In the body, it seems we are prepending.



Comment at: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp:2168-2169
+  // actually unrolls the loop.
+  UP.Threshold *= 1.5;
+  UP.PartialThreshold *= 1.5;
+

Should this be settable for experimentation or additional control? If not can 
you provide an explanation for these values?



Comment at: llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp:1666
 
+TEST_F(OpenMPIRBuilderTest, UnrollLoopFull) {
+  OpenMPIRBuilder OMPBuilder(*M);

Are we not calling ompbuilder finalize or verify because it is only adding 
metadata?



Comment at: llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp:1735
+
 TEST_F(OpenMPIRBuilderTest, StaticWorkShareLoop) {
   using InsertPointTy = OpenMPIRBuilder::InsertPointTy;

Should we add tests for workshare loops with unroll?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107764

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


[PATCH] D108621: [HIPSPV] Add CUDA->SPIR-V address space mapping

2021-08-26 Thread Alexey Bader via Phabricator via cfe-commits
bader added inline comments.



Comment at: clang/lib/Basic/Targets/SPIR.h:59
+// translation). This mapping is enabled when the language mode is HIP.
+1, // cuda_device
+// cuda_constant pointer can be casted to default/"flat" pointer, but in

Anastasia wrote:
> I am slightly confused as in the LLVM project those address spaces are for 
> SPIR not SPIR-V though. It is however used outside of LLVM project by some 
> tools like SPIRV-LLVM Translator as a path to SPIR-V, but it has only been 
> done as a workaround since we had no SPIR-V support in the LLVM project yet. 
> And if we are adding it let's do it clean to avoid/resolve any confusion.
> 
> I think we need to keep both because some vendors do target/use SPIR but not 
> SPIR-V.
> 
> So if you are interested in SPIR-V and not SPIR you should probably add a new 
> target that will make things cleaner.
> I think we need to keep both because some vendors do target/use SPIR but not 
> SPIR-V.

@Anastasia, could you elaborate more on the difference between SPIR and SPIR-V?
I would like to understand what these terms mean in the context of LLVM project.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108621

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


[PATCH] D105269: [X86] AVX512FP16 instructions enabling 6/6

2021-08-26 Thread Pengfei Wang via Phabricator via cfe-commits
pengfei added inline comments.



Comment at: llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp:3902
+  case X86::VFCMADDCSHZr:
+  case X86::VFCMADDCSHZrb:
+  case X86::VFCMADDCSHZrbk:

LuoYuanke wrote:
> "b" means rounding. Right?
broadcasting



Comment at: llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp:3948
+for (unsigned i = 2; i < Inst.getNumOperands(); i++)
+  if (Inst.getOperand(i).isReg() && Dest == Inst.getOperand(i).getReg())
+return Warning(Ops[0]->getStartLoc(), "Destination register should be "

LuoYuanke wrote:
> Sorry, I didn't find the constrain in the spec.
#UD if (dest_reg == src1_reg) or ( dest_reg == src2_reg)



Comment at: llvm/lib/Target/X86/X86InstrAVX512.td:13640
+(v4f32 (OpNode VR128X:$src1, VR128X:$src2)),
+0, 0, 0, X86selects, "@earlyclobber $dst">, 
Sched<[sched.XMM]>;
+defm rm : AVX512_maskable I didn't see this flag for other scalar instructions, why we need it for 
> complex instruction?
Because all complex instructions have constrains "dst != src1 && dst != src2". 
We use earlyclobber to avoid the dst been assigned to src1 or src2.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105269

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


[PATCH] D105269: [X86] AVX512FP16 instructions enabling 6/6

2021-08-26 Thread Pengfei Wang via Phabricator via cfe-commits
pengfei added inline comments.



Comment at: llvm/lib/Target/X86/X86InstrFoldTables.cpp:1852
+  { X86::VFCMULCPHZrr, X86::VFCMULCPHZrm, 0 },
+  { X86::VFCMULCSHZrr, X86::VFCMULCSHZrm, 
TB_NO_REVERSE },
   { X86::VFMADDPD4Yrr, X86::VFMADDPD4Ymr, 0 },

LuoYuanke wrote:
> Why FR32X version is not needed for complex scalar instructions?
Do you mean complex ss/sd? We don't have these instructions.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105269

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


[PATCH] D106431: [clang-tidy] Fix cppcoreguidelines-init-variables by removing the enum FixIt, and add support for initialization check of scoped enum.

2021-08-26 Thread Whisperity via Phabricator via cfe-commits
whisperity added a comment.

@Sockke Sorry to circle back here, but it seems to me that Clang now has a flag 
`-Wuninitialized`. Could you check how it behaves, compared to this check? If 
there are overlaps, what should we do, @aaron.ballman? Should parts of the 
check be deprecated?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106431

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


[PATCH] D101759: [PowerPC] Scalar IBM MASS library conversion pass

2021-08-26 Thread Masoud Ataei via Phabricator via cfe-commits
masoud.ataei marked an inline comment as done.
masoud.ataei added a comment.

In D101759#2967250 , @lebedev.ri 
wrote:

> Do we *really* need `-enable-approx-func-fp-math`?
> I'm pretty sure we are moving away from such global options, onto relying 
> only on the per-instruction fast-math flags.

I am handling LLVM intrinsic math functions in PPCISelLowering.cpp, so I need 
to check for `TM.Options.ApproxFuncFPMath`. This is the only place that I think 
I need it. 
Currently, I am updating `TM.Options.ApproxFuncFPMath` in 
`llvm/lib/CodeGen/CommandFlags.cpp` using the global option. Please let me know 
if there is a better way to update `TM.Options.ApproxFuncFPMath` based on the 
local fast-math flag.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101759

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


[PATCH] D106618: [Clang][LLVM] generate btf_tag annotations for DISubprogram types

2021-08-26 Thread Yonghong Song via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGd383df32c0d5: [DebugInfo] generate btf_tag annotations for 
DISubprogram types (authored by yonghong-song).

Changed prior to commit:
  https://reviews.llvm.org/D106618?vs=368805&id=368891#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106618

Files:
  llvm/include/llvm/IR/DIBuilder.h
  llvm/include/llvm/IR/DebugInfoMetadata.h
  llvm/lib/AsmParser/LLParser.cpp
  llvm/lib/Bitcode/Reader/MetadataLoader.cpp
  llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
  llvm/lib/IR/AsmWriter.cpp
  llvm/lib/IR/DIBuilder.cpp
  llvm/lib/IR/DebugInfoMetadata.cpp
  llvm/lib/IR/LLVMContextImpl.h
  llvm/test/Bitcode/attr-btf_tag-disubprogram.ll

Index: llvm/test/Bitcode/attr-btf_tag-disubprogram.ll
===
--- /dev/null
+++ llvm/test/Bitcode/attr-btf_tag-disubprogram.ll
@@ -0,0 +1,46 @@
+; REQUIRES: x86-registered-target
+; RUN: llvm-as < %s | llvm-dis | FileCheck %s
+
+; Function Attrs: mustprogress nofree norecurse nosync nounwind readnone uwtable willreturn
+define dso_local i32 @f(i32 %a) local_unnamed_addr #0 !dbg !8 {
+entry:
+  call void @llvm.dbg.value(metadata i32 %a, metadata !13, metadata !DIExpression()), !dbg !17
+  ret i32 0, !dbg !18
+}
+
+; Function Attrs: nofree nosync nounwind readnone speculatable willreturn
+declare void @llvm.dbg.value(metadata, metadata, metadata) #1
+
+attributes #0 = { mustprogress nofree norecurse nosync nounwind readnone uwtable willreturn "frame-pointer"="none" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
+attributes #1 = { nofree nosync nounwind readnone speculatable willreturn }
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!3, !4, !5, !6}
+!llvm.ident = !{!7}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 13.0.0 (https://github.com/llvm/llvm-project.git a6dd9d402a04d53403664bbb47771f2573c7ade0)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, splitDebugInlining: false, nameTableKind: None)
+!1 = !DIFile(filename: "func.c", directory: "/home/yhs/work/tests/llvm/btf_tag")
+!2 = !{}
+!3 = !{i32 7, !"Dwarf Version", i32 4}
+!4 = !{i32 2, !"Debug Info Version", i32 3}
+!5 = !{i32 1, !"wchar_size", i32 4}
+!6 = !{i32 7, !"uwtable", i32 1}
+!7 = !{!"clang version 13.0.0 (https://github.com/llvm/llvm-project.git a6dd9d402a04d53403664bbb47771f2573c7ade0)"}
+!8 = distinct !DISubprogram(name: "f", scope: !1, file: !1, line: 1, type: !9, scopeLine: 1, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !12, annotations: !14)
+!9 = !DISubroutineType(types: !10)
+!10 = !{!11, !11}
+!11 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+!12 = !{!13}
+!13 = !DILocalVariable(name: "a", arg: 1, scope: !8, file: !1, line: 1, type: !11)
+!14 = !{!15, !16}
+!15 = !{!"btf_tag", !"a"}
+!16 = !{!"btf_tag", !"b"}
+
+; CHECK:distinct !DISubprogram(name: "f"
+; CHECK-SAME:   annotations: ![[ANNOT:[0-9]+]]
+; CHECK:![[ANNOT]] = !{![[TAG1:[0-9]+]], ![[TAG2:[0-9]+]]}
+; CHECK:![[TAG1]] = !{!"btf_tag", !"a"}
+; CHECK:![[TAG2]] = !{!"btf_tag", !"b"}
+
+!17 = !DILocation(line: 0, scope: !8)
+!18 = !DILocation(line: 1, column: 77, scope: !8)
Index: llvm/lib/IR/LLVMContextImpl.h
===
--- llvm/lib/IR/LLVMContextImpl.h
+++ llvm/lib/IR/LLVMContextImpl.h
@@ -696,6 +696,7 @@
   Metadata *Declaration;
   Metadata *RetainedNodes;
   Metadata *ThrownTypes;
+  Metadata *Annotations;
 
   MDNodeKeyImpl(Metadata *Scope, MDString *Name, MDString *LinkageName,
 Metadata *File, unsigned Line, Metadata *Type,
@@ -703,13 +704,14 @@
 unsigned VirtualIndex, int ThisAdjustment, unsigned Flags,
 unsigned SPFlags, Metadata *Unit, Metadata *TemplateParams,
 Metadata *Declaration, Metadata *RetainedNodes,
-Metadata *ThrownTypes)
+Metadata *ThrownTypes, Metadata *Annotations)
   : Scope(Scope), Name(Name), LinkageName(LinkageName), File(File),
 Line(Line), Type(Type), ScopeLine(ScopeLine),
 ContainingType(ContainingType), VirtualIndex(VirtualIndex),
 ThisAdjustment(ThisAdjustment), Flags(Flags), SPFlags(SPFlags),
 Unit(Unit), TemplateParams(TemplateParams), Declaration(Declaration),
-RetainedNodes(RetainedNodes), ThrownTypes(ThrownTypes) {}
+RetainedNodes(RetainedNodes), ThrownTypes(ThrownTypes),
+Annotations(Annotations) {}
   MDNodeKeyImpl(const DISubprogram *N)
   : Scope(N->getRawScope()), Name(N->getRawN

[PATCH] D101759: [PowerPC] Scalar IBM MASS library conversion pass

2021-08-26 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a reviewer: spatel.
lebedev.ri added a comment.

In D101759#2967331 , @masoud.ataei 
wrote:

> In D101759#2967250 , @lebedev.ri 
> wrote:
>
>> Do we *really* need `-enable-approx-func-fp-math`?
>> I'm pretty sure we are moving away from such global options, onto relying 
>> only on the per-instruction fast-math flags.
>
> I am handling LLVM intrinsic math functions in PPCISelLowering.cpp, so I need 
> to check for `TM.Options.ApproxFuncFPMath`. This is the only place that I 
> think I need it.

How is this going to work e.g. in LTO when not all TU's are compiled with 
fast-math flags?

I'm not familiar with those llc flags, but i'm quite sure that e.g. DAGCombiner
is transitioned away from using them, so i'm wary of adding new ones.

> Currently, I am updating `TM.Options.ApproxFuncFPMath` in 
> `llvm/lib/CodeGen/CommandFlags.cpp` using the global option. Please let me 
> know if there is a better way to update `TM.Options.ApproxFuncFPMath` based 
> on the local fast-math flag.




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101759

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


[PATCH] D108765: [docs] Fix documentation of clang-format BasedOnStyle type

2021-08-26 Thread Ludovic Jozeau via Phabricator via cfe-commits
FederAndInk added a comment.

Thank you for your explanations, I understand now.

But as I look into `clang/docs/tools/dump_format_style.py` I see that it does 
not entirely generate `clang/docs/ClangFormatStyleOptions.rst` it replaces the 
lines between `{START,END}_FORMAT_STYLE_OPTIONS`

I understand your point, but as of now, the inconsistency comes from the part 
that is not auto-generated, are you suggesting editing `dump_format_style.py` 
to have simpler types such as `string`? Then how should we replace 
`std::vector`? Something like `Type[]` e.g. `string[]`?

Or maybe we should first include `BasedOnStyle` into `dump_format_style.py`. 
Then take care of how to render types?

What do you suggest? I am genuinely asking, as I really don't know what would 
be the best way to do things. Maybe we should include other people? I don't 
really know who to add as reviewers for that, but I think, the way to show 
types, should be discussed?

As for detailing `RawStringFormat`, it wasn't the purpose of this patch, and 
maybe it should have its own?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108765

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


[PATCH] D107647: [PowerPC] MMA - Add __builtin_vsx_build_pair and __builtin_mma_build_acc builtins

2021-08-26 Thread Lei Huang via Phabricator via cfe-commits
lei added inline comments.



Comment at: clang/lib/CodeGen/CGBuiltin.cpp:15833
+  // without the need for the programmer to swap operands.
+  if (IsLE) {
+SmallVector RevOps;

doesn't look like we need the interm var `IsLE`. Just use the call directly 
within the if stmt.
```
if (getTarget().isLittleEndian()) {
```



Comment at: clang/lib/CodeGen/CGBuiltin.cpp:15835-15837
+unsigned NumVecs = 2;
+if (BuiltinID == PPC::BI__builtin_mma_build_acc)
+  NumVecs = 4;

```
unsigned NumVecs = (BuiltinID == PPC::BI__builtin_mma_build_acc) ? 4 : 2;



Comment at: clang/test/CodeGen/builtins-ppc-pair-mma.c:2
 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
 // RUN: %clang_cc1 -O3 -triple powerpc64le-unknown-unknown -target-cpu future 
-emit-llvm %s -o - | FileCheck %s
 

future -> pwr10
We need to add BE tests.



Comment at: clang/test/Sema/ppc-pair-mma-types.c:2
 // RUN: %clang_cc1 -triple powerpc64le-unknown-unknown -fsyntax-only \
 // RUN:   -target-cpu future %s -verify
 

this should be `-target-cpu pwer10` now.



Comment at: clang/test/Sema/ppc-pair-mma-types.c:2
 // RUN: %clang_cc1 -triple powerpc64le-unknown-unknown -fsyntax-only \
 // RUN:   -target-cpu future %s -verify
 

lei wrote:
> this should be `-target-cpu pwer10` now.
Please add BE testing.



Comment at: clang/test/Sema/ppc-pair-mma-types.c:265
+  __builtin_mma_xvf64ger(&vq, vp3, vc);
+  *vpp = vp3;
+}

This looks like a dup of `testVPLocal()`.  Why not just add the new call line 
to that function right below the call to the deprecated function?




Comment at: clang/test/SemaCXX/ppc-pair-mma-types.cpp:2
 // RUN: %clang_cc1 -triple powerpc64le-unknown-unknown -fsyntax-only \
 // RUN:   -fcxx-exceptions -target-cpu future %s -verify
 

please update to pwr10


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107647

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


[PATCH] D108302: [PowerPC] Fixed the crash due to early if conversion with fixed CR fields.

2021-08-26 Thread Amy Kwan via Phabricator via cfe-commits
amyk added a comment.

Please update the patch with full context.




Comment at: llvm/lib/Target/PowerPC/PPCInstrInfo.cpp:1546
+  // into a select.
+  if (Register::isPhysicalRegister(Cond[1].getReg())) {
+return false;

nit: `uses a physical register`



Comment at: llvm/test/CodeGen/PowerPC/ifcvt_cr_field.ll:3
+; RUN: llc < %s -mtriple=powerpc64-unknown-linux-gnu -mcpu=pwr7 
-verify-machineinstrs | FileCheck %s
+target datalayout = 
"E-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-f128:128:128-v128:128:128-n32:64"
+target triple = "powerpc64-unknown-linux-gnu"

Are the  `target datalayout` and `target triple` necessary?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108302

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


[clang] 2de051b - [DebugInfo] convert btf_tag attrs to DI annotations for DISubprograms

2021-08-26 Thread Yonghong Song via cfe-commits

Author: Yonghong Song
Date: 2021-08-26T08:54:11-07:00
New Revision: 2de051ba124d92de953ac2420668407f458bcec6

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

LOG: [DebugInfo] convert btf_tag attrs to DI annotations for DISubprograms

Generate btf_tag annotations for DISubprograms. The annotations
are represented as an DINodeArray in DebugInfo.

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

Added: 
clang/test/CodeGen/attr-btf_tag-disubprogram-callsite.c
clang/test/CodeGen/attr-btf_tag-disubprogram.c

Modified: 
clang/lib/CodeGen/CGDebugInfo.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 989945a1b4ff..57f915028dde 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -3951,10 +3951,13 @@ void CGDebugInfo::emitFunctionStart(GlobalDecl GD, 
SourceLocation Loc,
   unsigned ScopeLine = getLineNumber(ScopeLoc);
   llvm::DISubroutineType *DIFnType = getOrCreateFunctionType(D, FnType, Unit);
   llvm::DISubprogram *Decl = nullptr;
-  if (D)
+  llvm::DINodeArray Annotations = nullptr;
+  if (D) {
 Decl = isa(D)
? getObjCMethodDeclaration(D, DIFnType, LineNo, Flags, SPFlags)
: getFunctionDeclaration(D);
+Annotations = CollectBTFTagAnnotations(D);
+  }
 
   // FIXME: The function declaration we're constructing here is mostly reusing
   // declarations from CXXMethodDecl and not constructing new ones for 
arbitrary
@@ -3963,7 +3966,8 @@ void CGDebugInfo::emitFunctionStart(GlobalDecl GD, 
SourceLocation Loc,
   // are emitted as CU level entities by the backend.
   llvm::DISubprogram *SP = DBuilder.createFunction(
   FDContext, Name, LinkageName, Unit, LineNo, DIFnType, ScopeLine,
-  FlagsForDef, SPFlagsForDef, TParamsArray.get(), Decl);
+  FlagsForDef, SPFlagsForDef, TParamsArray.get(), Decl, nullptr,
+  Annotations);
   Fn->setSubprogram(SP);
   // We might get here with a VarDecl in the case we're generating
   // code for the initialization of globals. Do not record these decls
@@ -4022,10 +4026,11 @@ void CGDebugInfo::EmitFunctionDecl(GlobalDecl GD, 
SourceLocation Loc,
   if (CGM.getLangOpts().Optimize)
 SPFlags |= llvm::DISubprogram::SPFlagOptimized;
 
+  llvm::DINodeArray Annotations = CollectBTFTagAnnotations(D);
   llvm::DISubprogram *SP = DBuilder.createFunction(
   FDContext, Name, LinkageName, Unit, LineNo,
   getOrCreateFunctionType(D, FnType, Unit), ScopeLine, Flags, SPFlags,
-  TParamsArray.get(), getFunctionDeclaration(D));
+  TParamsArray.get(), getFunctionDeclaration(D), nullptr, Annotations);
 
   if (IsDeclForCallSite)
 Fn->setSubprogram(SP);

diff  --git a/clang/test/CodeGen/attr-btf_tag-disubprogram-callsite.c 
b/clang/test/CodeGen/attr-btf_tag-disubprogram-callsite.c
new file mode 100644
index ..fcba5dd6d8a1
--- /dev/null
+++ b/clang/test/CodeGen/attr-btf_tag-disubprogram-callsite.c
@@ -0,0 +1,19 @@
+// REQUIRES: x86-registered-target
+// RUN: %clang -target x86_64 -g -S -O2 -emit-llvm -o - %s | FileCheck %s
+
+#define __tag1 __attribute__((btf_tag("tag1")))
+#define __tag2 __attribute__((btf_tag("tag2")))
+
+struct t1 {
+  int a;
+};
+
+extern int __tag1 __tag2 foo(struct t1 *);
+int foo2(struct t1 *arg) {
+  return foo(arg);
+}
+
+// CHECK: ![[#]] = !DISubprogram(name: "foo", scope: ![[#]], file: ![[#]], 
line: [[#]], type: ![[#]], flags: DIFlagPrototyped, spFlags: DISPFlagOptimized, 
retainedNodes: ![[#]], annotations: ![[ANNOT:[0-9]+]])
+// CHECK: ![[ANNOT]] = !{![[TAG1:[0-9]+]], ![[TAG2:[0-9]+]]}
+// CHECK: ![[TAG1]] = !{!"btf_tag", !"tag1"}
+// CHECK: ![[TAG2]] = !{!"btf_tag", !"tag2"}

diff  --git a/clang/test/CodeGen/attr-btf_tag-disubprogram.c 
b/clang/test/CodeGen/attr-btf_tag-disubprogram.c
new file mode 100644
index ..4c22e690f8df
--- /dev/null
+++ b/clang/test/CodeGen/attr-btf_tag-disubprogram.c
@@ -0,0 +1,40 @@
+// REQUIRES: x86-registered-target
+// RUN: %clang -target x86_64 -g -S -emit-llvm -o - %s | FileCheck %s
+
+#define __tag1 __attribute__((btf_tag("tag1")))
+#define __tag2 __attribute__((btf_tag("tag2")))
+
+struct t1 {
+  int a;
+};
+
+int __tag1 __tag2 foo(struct t1 *arg) {
+  return arg->a;
+}
+
+// CHECK: distinct !DISubprogram(name: "foo", scope: ![[#]], file: ![[#]], 
line: [[#]], type: ![[#]], scopeLine: [[#]], flags: DIFlagPrototyped, spFlags: 
DISPFlagDefinition, unit: ![[#]], retainedNodes: ![[#]], annotations: 
![[ANNOT:[0-9]+]])
+// CHECK: ![[ANNOT]] = !{![[TAG1:[0-9]+]], ![[TAG2:[0-9]+]]}
+// CHECK: ![[TAG1]] = !{!"btf_tag", !"tag1"}
+// CHECK: ![[TAG2]] = !{!"btf_tag", !"tag2"}
+
+int __tag1 __tag2 foo2(struct t1 *arg);
+int foo2(struct t1 *arg) {
+  return arg->a;
+}
+
+// CHECK: distinct !DISubprogram(name: "foo2", 

[PATCH] D108377: [asan] Implemented flag to emit intrinsics to optimize ASan callbacks.

2021-08-26 Thread Kirill Stoimenov via Phabricator via cfe-commits
kstoimenov updated this revision to Diff 368903.
kstoimenov added a comment.

Added a test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108377

Files:
  llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
  llvm/test/Instrumentation/AddressSanitizer/asan-optimize-callbacks.ll

Index: llvm/test/Instrumentation/AddressSanitizer/asan-optimize-callbacks.ll
===
--- /dev/null
+++ llvm/test/Instrumentation/AddressSanitizer/asan-optimize-callbacks.ll
@@ -0,0 +1,86 @@
+; RUN: opt < %s -asan -enable-new-pm=0 -asan-instrumentation-with-call-threshold=0 \
+;  -asan-optimize-callbacks -S | FileCheck %s --check-prefixes=LOAD,STORE
+; RUN: opt < %s -asan -enable-new-pm=0 -asan-instrumentation-with-call-threshold=0 \
+;  -asan-optimize-callbacks --asan-kernel -S | \
+;  FileCheck %s --check-prefixes=LOAD-KERNEL,STORE-KERNEL
+
+target triple = "x86_64-unknown-linux-gnu"
+
+define void @load(i8* %p1, i16* %p2, i32* %p4, i64* %p8, i128* %p16)
+sanitize_address {
+  %n1 = load i8, i8* %p1, align 1
+  %n2 = load i16, i16* %p2, align 2
+  %n4 = load i32, i32* %p4, align 4
+  %n8 = load i64, i64* %p8, align 8
+  %n16 = load i128, i128* %p16, align 16
+; LOAD:  call void @llvm.asan.check.memaccess(i8* %p1, i32 0)
+; LOAD-NEXT: %n1 = load i8, i8* %p1, align 1
+; LOAD-NEXT: %1 = bitcast i16* %p2 to i8*
+; LOAD-NEXT: call void @llvm.asan.check.memaccess(i8* %1, i32 2)
+; LOAD-NEXT: %n2 = load i16, i16* %p2, align 2
+; LOAD-NEXT: %2 = bitcast i32* %p4 to i8*
+; LOAD-NEXT: call void @llvm.asan.check.memaccess(i8* %2, i32 4)
+; LOAD-NEXT: %n4 = load i32, i32* %p4, align 4
+; LOAD-NEXT: %3 = bitcast i64* %p8 to i8*
+; LOAD-NEXT: call void @llvm.asan.check.memaccess(i8* %3, i32 6)
+; LOAD-NEXT: %n8 = load i64, i64* %p8, align 8
+; LOAD-NEXT: %4 = bitcast i128* %p16 to i8*
+; LOAD-NEXT: call void @llvm.asan.check.memaccess(i8* %4, i32 8)
+; LOAD-NEXT: %n16 = load i128, i128* %p16, align 16
+
+; LOAD-KERNEL:  call void @llvm.asan.check.memaccess(i8* %p1, i32 1)
+; LOAD-KERNEL-NEXT: %n1 = load i8, i8* %p1, align 1
+; LOAD-KERNEL-NEXT: %1 = bitcast i16* %p2 to i8*
+; LOAD-KERNEL-NEXT: call void @llvm.asan.check.memaccess(i8* %1, i32 3)
+; LOAD-KERNEL-NEXT: %n2 = load i16, i16* %p2, align 2
+; LOAD-KERNEL-NEXT: %2 = bitcast i32* %p4 to i8*
+; LOAD-KERNEL-NEXT: call void @llvm.asan.check.memaccess(i8* %2, i32 5)
+; LOAD-KERNEL-NEXT: %n4 = load i32, i32* %p4, align 4
+; LOAD-KERNEL-NEXT: %3 = bitcast i64* %p8 to i8*
+; LOAD-KERNEL-NEXT: call void @llvm.asan.check.memaccess(i8* %3, i32 7)
+; LOAD-KERNEL-NEXT: %n8 = load i64, i64* %p8, align 8
+; LOAD-KERNEL-NEXT: %4 = bitcast i128* %p16 to i8*
+; LOAD-KERNEL-NEXT: call void @llvm.asan.check.memaccess(i8* %4, i32 9)
+; LOAD-KERNEL-NEXT: %n16 = load i128, i128* %p16, align 16
+  ret void
+}
+
+define void @store(i8* %p1, i16* %p2, i32* %p4, i64* %p8, i128* %p16)
+sanitize_address {
+  store i8 0, i8* %p1, align 1
+  store i16 0, i16* %p2, align 2
+  store i32 0, i32* %p4, align 4
+  store i64 0, i64* %p8, align 8
+  store i128 0, i128* %p16, align 16
+; STORE:  call void @llvm.asan.check.memaccess(i8* %p1, i32 32)
+; STORE-NEXT: store i8 0, i8* %p1, align 1
+; STORE-NEXT: %1 = bitcast i16* %p2 to i8*
+; STORE-NEXT: call void @llvm.asan.check.memaccess(i8* %1, i32 34)
+; STORE-NEXT: store i16 0, i16* %p2, align 2
+; STORE-NEXT: %2 = bitcast i32* %p4 to i8*
+; STORE-NEXT: call void @llvm.asan.check.memaccess(i8* %2, i32 36)
+; STORE-NEXT: store i32 0, i32* %p4, align 4
+; STORE-NEXT: %3 = bitcast i64* %p8 to i8*
+; STORE-NEXT: call void @llvm.asan.check.memaccess(i8* %3, i32 38)
+; STORE-NEXT: store i64 0, i64* %p8, align 8
+; STORE-NEXT: %4 = bitcast i128* %p16 to i8*
+; STORE-NEXT: call void @llvm.asan.check.memaccess(i8* %4, i32 40)
+; STORE-NEXT: store i128 0, i128* %p16, align 16
+
+; STORE-KERNEL:  call void @llvm.asan.check.memaccess(i8* %p1, i32 33)
+; STORE-KERNEL-NEXT: store i8 0, i8* %p1, align 1
+; STORE-KERNEL-NEXT: %1 = bitcast i16* %p2 to i8*
+; STORE-KERNEL-NEXT: call void @llvm.asan.check.memaccess(i8* %1, i32 35)
+; STORE-KERNEL-NEXT: store i16 0, i16* %p2, align 2
+; STORE-KERNEL-NEXT: %2 = bitcast i32* %p4 to i8*
+; STORE-KERNEL-NEXT: call void @llvm.asan.check.memaccess(i8* %2, i32 37)
+; STORE-KERNEL-NEXT: store i32 0, i32* %p4, align 4
+; STORE-KERNEL-NEXT: %3 = bitcast i64* %p8 to i8*
+; STORE-KERNEL-NEXT: call void @llvm.asan.check.memaccess(i8* %3, i32 39)
+; STORE-KERNEL-NEXT: store i64 0, i64* %p8, align 8
+; STORE-KERNEL-NEXT: %4 = bitcast i128* %p16 to i8*
+; STORE-KERNEL-NEXT: call void @llvm.asan.check.memaccess(i8* %4, i32 41)
+; STORE-KERNEL-NEXT: store i128 0, i128* %p16, align 16
+; STORE-KERNEL-NEXT: ret void
+  ret void
+}
Index: llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
===
--- llvm/lib/Transforms/Instrumentatio

[PATCH] D108481: Avoid nullptr dereferencing of 'Constraint'

2021-08-26 Thread Mikhail Lychkov via Phabricator via cfe-commits
mlychkov added inline comments.



Comment at: clang/lib/Sema/SemaConcept.cpp:1065-1068
   assert(TC &&
  "TPL must have a template type parameter with a type constraint");
   auto *Constraint =
+  cast(TC->getImmediatelyDeclaredConstraint());

aaron.ballman wrote:
> If we're going to be touching this code, there's more suspect code here that 
> needs to be cleaned up a bit. Directly above this is:
> ```
>   const TypeConstraint *TC =
>   cast(TPL->getParam(0))->getTypeConstraint();
>   assert(TC &&
>  "TPL must have a template type parameter with a type constraint");
> ```
> That assertion can be removed entirely -- if the `cast<>` fails, it doesn't 
> return null, it asserts.
Actually, cast return nonnull value, but
   TC = "cast_result"->getTypeConstraint();
and TC may become nullptr, I suppose.


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

https://reviews.llvm.org/D108481

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


[clang] af79f1b - [analyzer] Extend the documentation of MallocOverflow

2021-08-26 Thread Balazs Benics via cfe-commits

Author: Balazs Benics
Date: 2021-08-26T18:15:10+02:00
New Revision: af79f1bff90bee957ec9f963b68226e0b33eb169

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

LOG: [analyzer] Extend the documentation of MallocOverflow

Previously by following the documentation it was not immediately clear
what the capabilities of this checker are.

In this patch, I add some clarification on when does the checker issue a
report and what it's limitations are.
I'm also advertising suppressing such reports by adding an assertion, as
demonstrated by the test3().
I'm highlighting that this checker might produce an extensive amount of
findings, but it might be still useful for code audits.

Reviewed By: martong

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

Added: 


Modified: 
clang/docs/analyzer/checkers.rst

Removed: 




diff  --git a/clang/docs/analyzer/checkers.rst 
b/clang/docs/analyzer/checkers.rst
index 9a74dffc1658d..dc8698b8f0c8a 100644
--- a/clang/docs/analyzer/checkers.rst
+++ b/clang/docs/analyzer/checkers.rst
@@ -2154,7 +2154,15 @@ Warn about buffer overflows (newer checker).
 
 alpha.security.MallocOverflow (C)
 "
-Check for overflows in the arguments to malloc().
+Check for overflows in the arguments to ``malloc()``.
+It tries to catch ``malloc(n * c)`` patterns, where:
+
+ - ``n``: a variable or member access of an object
+ - ``c``: a constant foldable integral
+
+This checker was designed for code audits, so expect false-positive reports.
+One is supposed to silence this checker by ensuring proper bounds checking on
+the variable in question using e.g. an ``assert()`` or a branch.
 
 .. code-block:: c
 
@@ -2168,6 +2176,27 @@ Check for overflows in the arguments to malloc().
void *p = malloc(n * sizeof(int)); // no warning
  }
 
+ void test3(int n) {
+   assert(n <= 100 && "Contract violated.");
+   void *p = malloc(n * sizeof(int)); // no warning
+ }
+
+Limitations:
+
+ - The checker won't warn for variables involved in explicit casts,
+   since that might limit the variable's domain.
+   E.g.: ``(unsigned char)int x`` would limit the domain to ``[0,255]``.
+   The checker will miss the true-positive cases when the explicit cast would
+   not tighten the domain to prevent the overflow in the subsequent
+   multiplication operation.
+
+ - If the variable ``n`` participates in a comparison anywhere in the enclosing
+   function's scope, even after the ``malloc()``, the report will be still
+   suppressed.
+
+ - It is an AST-based checker, thus it does not make use of the
+   path-sensitive taint-analysis.
+
 .. _alpha-security-MmapWriteExec:
 
 alpha.security.MmapWriteExec (C)



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


[PATCH] D104285: [analyzer][AST] Retrieve value by direct index from list initialization of constant array declaration.

2021-08-26 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov updated this revision to Diff 368905.
ASDenysPetrov edited the summary of this revision.
ASDenysPetrov added a comment.

Reworked the patch according to the discussion and taking UB into account. 
Moved `Expr::getExprForConstArrayByRawIndex` to `RegionStoreManager`.


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

https://reviews.llvm.org/D104285

Files:
  clang/include/clang/AST/Type.h
  clang/lib/AST/Type.cpp
  clang/lib/StaticAnalyzer/Core/RegionStore.cpp
  clang/test/Analysis/initialization.cpp

Index: clang/test/Analysis/initialization.cpp
===
--- clang/test/Analysis/initialization.cpp
+++ clang/test/Analysis/initialization.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -std=c++14 -triple i386-apple-darwin10 -analyze -analyzer-checker=core.builtin,debug.ExprInspection -verify %s
+// RUN: %clang_cc1 -std=c++14 -triple i386-apple-darwin10 -analyze -analyzer-checker=core.uninitialized.Assign,core.builtin,debug.ExprInspection,core.uninitialized.UndefReturn -verify %s
 
 void clang_analyzer_eval(int);
 
@@ -18,3 +18,106 @@
   // FIXME: Should recognize that it is 0.
   clang_analyzer_eval(arr[i][0]); // expected-warning{{UNKNOWN}}
 }
+
+int const glob_arr1[2][2][3] = {};
+void direct_index1() {
+  int const *ptr = (int const *)glob_arr1;
+  clang_analyzer_eval(ptr[0] == 0);  // expected-warning{{TRUE}}
+  clang_analyzer_eval(ptr[1] == 0);  // expected-warning{{TRUE}}
+  clang_analyzer_eval(ptr[2] == 0);  // expected-warning{{TRUE}}
+  clang_analyzer_eval(ptr[3] == 0);  // expected-warning{{UNDEFINED}}
+  clang_analyzer_eval(ptr[4] == 0);  // expected-warning{{UNDEFINED}}
+  clang_analyzer_eval(ptr[5] == 0);  // expected-warning{{UNDEFINED}}
+  clang_analyzer_eval(ptr[6] == 0);  // expected-warning{{UNDEFINED}}
+  clang_analyzer_eval(ptr[7] == 0);  // expected-warning{{UNDEFINED}}
+  clang_analyzer_eval(ptr[8] == 0);  // expected-warning{{UNDEFINED}}
+  clang_analyzer_eval(ptr[9] == 0);  // expected-warning{{UNDEFINED}}
+  clang_analyzer_eval(ptr[10] == 0); // expected-warning{{UNDEFINED}}
+  clang_analyzer_eval(ptr[11] == 0); // expected-warning{{UNDEFINED}}
+}
+
+int const glob_arr2[2][2][3] = {{{1, 2, 3}, {4, 5, 6}}, {{7, 8, 9}, {10, 11, 12}}};
+void direct_index2() {
+  int const *ptr = glob_arr2[0][0];
+  clang_analyzer_eval(ptr[0] == 1);   // expected-warning{{TRUE}}
+  clang_analyzer_eval(ptr[1] == 2);   // expected-warning{{TRUE}}
+  clang_analyzer_eval(ptr[2] == 3);   // expected-warning{{TRUE}}
+  clang_analyzer_eval(ptr[3] == 4);   // expected-warning{{UNDEFINED}}
+  clang_analyzer_eval(ptr[4] == 5);   // expected-warning{{UNDEFINED}}
+  clang_analyzer_eval(ptr[5] == 6);   // expected-warning{{UNDEFINED}}
+  clang_analyzer_eval(ptr[6] == 7);   // expected-warning{{UNDEFINED}}
+  clang_analyzer_eval(ptr[7] == 8);   // expected-warning{{UNDEFINED}}
+  clang_analyzer_eval(ptr[8] == 9);   // expected-warning{{UNDEFINED}}
+  clang_analyzer_eval(ptr[9] == 10);  // expected-warning{{UNDEFINED}}
+  clang_analyzer_eval(ptr[10] == 11); // expected-warning{{UNDEFINED}}
+  clang_analyzer_eval(ptr[11] == 12); // expected-warning{{UNDEFINED}}
+}
+
+int const glob_arr3[2][2][3] = {{{}, {}}, {{}, {}}};
+void direct_index3() {
+  int const *ptr = &(glob_arr3[0][0][0]);
+  clang_analyzer_eval(ptr[0] == 0);  // expected-warning{{TRUE}}
+  clang_analyzer_eval(ptr[1] == 0);  // expected-warning{{TRUE}}
+  clang_analyzer_eval(ptr[2] == 0);  // expected-warning{{TRUE}}
+  clang_analyzer_eval(ptr[3] == 0);  // expected-warning{{UNDEFINED}}
+  clang_analyzer_eval(ptr[4] == 0);  // expected-warning{{UNDEFINED}}
+  clang_analyzer_eval(ptr[5] == 0);  // expected-warning{{UNDEFINED}}
+  clang_analyzer_eval(ptr[6] == 0);  // expected-warning{{UNDEFINED}}
+  clang_analyzer_eval(ptr[7] == 0);  // expected-warning{{UNDEFINED}}
+  clang_analyzer_eval(ptr[8] == 0);  // expected-warning{{UNDEFINED}}
+  clang_analyzer_eval(ptr[9] == 0);  // expected-warning{{UNDEFINED}}
+  clang_analyzer_eval(ptr[10] == 0); // expected-warning{{UNDEFINED}}
+  clang_analyzer_eval(ptr[11] == 0); // expected-warning{{UNDEFINED}}
+}
+
+int const glob_arr4[2][2][3] = {{{1, 2}, {}}, {{7, 8}, {10, 11, 12}}};
+void direct_index4() {
+  int const *ptr = (int const *)glob_arr4[0];
+  clang_analyzer_eval(ptr[0] == 1);   // expected-warning{{TRUE}}
+  clang_analyzer_eval(ptr[1] == 2);   // expected-warning{{TRUE}}
+  clang_analyzer_eval(ptr[2] == 0);   // expected-warning{{TRUE}}
+  clang_analyzer_eval(ptr[3] == 0);   // expected-warning{{UNDEFINED}}
+  clang_analyzer_eval(ptr[4] == 0);   // expected-warning{{UNDEFINED}}
+  clang_analyzer_eval(ptr[5] == 0);   // expected-warning{{UNDEFINED}}
+  clang_analyzer_eval(ptr[6] == 7);   // expected-warning{{UNDEFINED}}
+  clang_analyzer_eval(ptr[7] == 8);   // expected-warning{{UNDEFINED}}
+  clang_analyzer_eval(ptr[8] == 0);   // expected-warning{{UNDEFINED}}
+  clang_analyzer_eval(ptr[9] == 10);  // expected-warning{{UNDEFINED

[PATCH] D101960: [openmp] Drop requirement on library path environment variables

2021-08-26 Thread Jon Chesterfield via Phabricator via cfe-commits
JonChesterfield added a comment.

Test setup can be fixed independently (and possibly should be).

D102043  is newly simplified. It looks for 
plugins next to libomptarget.so, which means it can find them even when the 
application uses a non-transitive method to find libomptarget.so.

Turns out libomptarget.so is linked directly to the application, not via 
libomp.so as I believed, and they're installed next to each other so whatever 
finds the first will find the second.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101960

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


[PATCH] D108481: Avoid nullptr dereferencing of 'Constraint'

2021-08-26 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/lib/Sema/SemaConcept.cpp:1065-1068
   assert(TC &&
  "TPL must have a template type parameter with a type constraint");
   auto *Constraint =
+  cast(TC->getImmediatelyDeclaredConstraint());

mlychkov wrote:
> aaron.ballman wrote:
> > If we're going to be touching this code, there's more suspect code here 
> > that needs to be cleaned up a bit. Directly above this is:
> > ```
> >   const TypeConstraint *TC =
> >   cast(TPL->getParam(0))->getTypeConstraint();
> >   assert(TC &&
> >  "TPL must have a template type parameter with a type constraint");
> > ```
> > That assertion can be removed entirely -- if the `cast<>` fails, it doesn't 
> > return null, it asserts.
> Actually, cast return nonnull value, but
>TC = "cast_result"->getTypeConstraint();
> and TC may become nullptr, I suppose.
Good catch! I think we should add the assertion on `TC` being nonnull back. 
I'll take care of that.


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

https://reviews.llvm.org/D108481

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


[PATCH] D108481: Avoid nullptr dereferencing of 'Constraint'

2021-08-26 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added inline comments.



Comment at: clang/lib/Sema/SemaConcept.cpp:1065-1068
   assert(TC &&
  "TPL must have a template type parameter with a type constraint");
   auto *Constraint =
+  cast(TC->getImmediatelyDeclaredConstraint());

aaron.ballman wrote:
> mlychkov wrote:
> > aaron.ballman wrote:
> > > If we're going to be touching this code, there's more suspect code here 
> > > that needs to be cleaned up a bit. Directly above this is:
> > > ```
> > >   const TypeConstraint *TC =
> > >   cast(TPL->getParam(0))->getTypeConstraint();
> > >   assert(TC &&
> > >  "TPL must have a template type parameter with a type 
> > > constraint");
> > > ```
> > > That assertion can be removed entirely -- if the `cast<>` fails, it 
> > > doesn't return null, it asserts.
> > Actually, cast return nonnull value, but
> >TC = "cast_result"->getTypeConstraint();
> > and TC may become nullptr, I suppose.
> Good catch! I think we should add the assertion on `TC` being nonnull back. 
> I'll take care of that.
Ooh, good catch!  I definitely missed that when suggesting removing the assert. 
 @aaron.ballman  can you re-add the assert on 1065?


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

https://reviews.llvm.org/D108481

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


[PATCH] D107756: [analyzer] Extend the documentation of MallocOverflow

2021-08-26 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added inline comments.



Comment at: clang/docs/analyzer/checkers.rst:2159-2160
+It tries to catch ``malloc(n * c)`` patterns, where:
+ - ``n``: a variable or member access of an object
+ - ``c``: a constant foldable integral
+

steakhal wrote:
> Am I supposed to indent this with 2 spaces? Or what.
It seems like an empty newline solved this before the list.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107756

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


[PATCH] D108624: [Clang][RISCV] Implement getConstraintRegister for RISC-V

2021-08-26 Thread Alex Bradbury via Phabricator via cfe-commits
asb accepted this revision.
asb added a comment.
This revision is now accepted and ready to land.

Looks good to me - I'm surprised only Arm, AArch64, and X86 implement this!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108624

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


[clang] 34e055d - [Clang][RISCV] Implement getConstraintRegister for RISC-V

2021-08-26 Thread Luís Marques via cfe-commits

Author: Luís Marques
Date: 2021-08-26T17:43:43+01:00
New Revision: 34e055d33e37cd87b9f6f4b0431a4c061628d036

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

LOG: [Clang][RISCV] Implement getConstraintRegister for RISC-V

The getConstraintRegister method is used by semantic checking of inline
assembly statements in order to diagnose conflicts between clobber list
and input/output lists. By overriding getConstraintRegister we get those
diagnostics and we match RISC-V GCC's behavior. The implementation is
trivial due to the lack of single-register RISC-V-specific constraints.

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

Added: 


Modified: 
clang/lib/Basic/Targets/RISCV.h
clang/test/Sema/inline-asm-validate-riscv.c

Removed: 




diff  --git a/clang/lib/Basic/Targets/RISCV.h b/clang/lib/Basic/Targets/RISCV.h
index 7e0846581ca1f..9609b6fc3f307 100644
--- a/clang/lib/Basic/Targets/RISCV.h
+++ b/clang/lib/Basic/Targets/RISCV.h
@@ -82,6 +82,11 @@ class RISCVTargetInfo : public TargetInfo {
 
   const char *getClobbers() const override { return ""; }
 
+  StringRef getConstraintRegister(StringRef Constraint,
+  StringRef Expression) const override {
+return Expression;
+  }
+
   ArrayRef getGCCRegNames() const override;
 
   int getEHDataRegisterNumber(unsigned RegNo) const override {

diff  --git a/clang/test/Sema/inline-asm-validate-riscv.c 
b/clang/test/Sema/inline-asm-validate-riscv.c
index 744f73e23cf26..43a5378bc3f25 100644
--- a/clang/test/Sema/inline-asm-validate-riscv.c
+++ b/clang/test/Sema/inline-asm-validate-riscv.c
@@ -21,3 +21,11 @@ void K(int k) {
   asm volatile ("" :: "K"(BelowMin)); // expected-error{{value '-1' out of 
range for constraint 'K'}}
   asm volatile ("" :: "K"(AboveMax)); // expected-error{{value '32' out of 
range for constraint 'K'}}
 }
+
+void test_clobber_conflict(void) {
+  register long x10 asm("x10");
+  asm volatile("" :: "r"(x10) : "x10"); // expected-error {{conflicts with asm 
clobber list}}
+  asm volatile("" :: "r"(x10) : "a0"); // expected-error {{conflicts with asm 
clobber list}}
+  asm volatile("" : "=r"(x10) :: "x10"); // expected-error {{conflicts with 
asm clobber list}}
+  asm volatile("" : "=r"(x10) :: "a0"); // expected-error {{conflicts with asm 
clobber list}}
+}



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


[PATCH] D108624: [Clang][RISCV] Implement getConstraintRegister for RISC-V

2021-08-26 Thread Luís Marques via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG34e055d33e37: [Clang][RISCV] Implement getConstraintRegister 
for RISC-V (authored by luismarques).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108624

Files:
  clang/lib/Basic/Targets/RISCV.h
  clang/test/Sema/inline-asm-validate-riscv.c


Index: clang/test/Sema/inline-asm-validate-riscv.c
===
--- clang/test/Sema/inline-asm-validate-riscv.c
+++ clang/test/Sema/inline-asm-validate-riscv.c
@@ -21,3 +21,11 @@
   asm volatile ("" :: "K"(BelowMin)); // expected-error{{value '-1' out of 
range for constraint 'K'}}
   asm volatile ("" :: "K"(AboveMax)); // expected-error{{value '32' out of 
range for constraint 'K'}}
 }
+
+void test_clobber_conflict(void) {
+  register long x10 asm("x10");
+  asm volatile("" :: "r"(x10) : "x10"); // expected-error {{conflicts with asm 
clobber list}}
+  asm volatile("" :: "r"(x10) : "a0"); // expected-error {{conflicts with asm 
clobber list}}
+  asm volatile("" : "=r"(x10) :: "x10"); // expected-error {{conflicts with 
asm clobber list}}
+  asm volatile("" : "=r"(x10) :: "a0"); // expected-error {{conflicts with asm 
clobber list}}
+}
Index: clang/lib/Basic/Targets/RISCV.h
===
--- clang/lib/Basic/Targets/RISCV.h
+++ clang/lib/Basic/Targets/RISCV.h
@@ -82,6 +82,11 @@
 
   const char *getClobbers() const override { return ""; }
 
+  StringRef getConstraintRegister(StringRef Constraint,
+  StringRef Expression) const override {
+return Expression;
+  }
+
   ArrayRef getGCCRegNames() const override;
 
   int getEHDataRegisterNumber(unsigned RegNo) const override {


Index: clang/test/Sema/inline-asm-validate-riscv.c
===
--- clang/test/Sema/inline-asm-validate-riscv.c
+++ clang/test/Sema/inline-asm-validate-riscv.c
@@ -21,3 +21,11 @@
   asm volatile ("" :: "K"(BelowMin)); // expected-error{{value '-1' out of range for constraint 'K'}}
   asm volatile ("" :: "K"(AboveMax)); // expected-error{{value '32' out of range for constraint 'K'}}
 }
+
+void test_clobber_conflict(void) {
+  register long x10 asm("x10");
+  asm volatile("" :: "r"(x10) : "x10"); // expected-error {{conflicts with asm clobber list}}
+  asm volatile("" :: "r"(x10) : "a0"); // expected-error {{conflicts with asm clobber list}}
+  asm volatile("" : "=r"(x10) :: "x10"); // expected-error {{conflicts with asm clobber list}}
+  asm volatile("" : "=r"(x10) :: "a0"); // expected-error {{conflicts with asm clobber list}}
+}
Index: clang/lib/Basic/Targets/RISCV.h
===
--- clang/lib/Basic/Targets/RISCV.h
+++ clang/lib/Basic/Targets/RISCV.h
@@ -82,6 +82,11 @@
 
   const char *getClobbers() const override { return ""; }
 
+  StringRef getConstraintRegister(StringRef Constraint,
+  StringRef Expression) const override {
+return Expression;
+  }
+
   ArrayRef getGCCRegNames() const override;
 
   int getEHDataRegisterNumber(unsigned RegNo) const override {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 0cf4f81 - Adding an assertion back.

2021-08-26 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2021-08-26T12:51:14-04:00
New Revision: 0cf4f81082e9fa052e60450b8cbb10007e59931c

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

LOG: Adding an assertion back.

This assert was removed in 98339f14a0420cdfbe4215d8d1bc0a01165e0495,
but during post-commit review, it was pointed out that the assert was
valid.

Added: 


Modified: 
clang/lib/Sema/SemaConcept.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp
index c582446426892..2932335f3ad49 100644
--- a/clang/lib/Sema/SemaConcept.cpp
+++ b/clang/lib/Sema/SemaConcept.cpp
@@ -1062,6 +1062,8 @@ ReturnTypeRequirement(TemplateParameterList *TPL) :
   assert(TPL->size() == 1);
   const TypeConstraint *TC =
   cast(TPL->getParam(0))->getTypeConstraint();
+  assert(TC &&
+ "TPL must have a template type parameter with a type constraint");
   auto *Constraint =
   cast(TC->getImmediatelyDeclaredConstraint());
   bool Dependent =



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


[PATCH] D108481: Avoid nullptr dereferencing of 'Constraint'

2021-08-26 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/lib/Sema/SemaConcept.cpp:1065-1068
   assert(TC &&
  "TPL must have a template type parameter with a type constraint");
   auto *Constraint =
+  cast(TC->getImmediatelyDeclaredConstraint());

erichkeane wrote:
> aaron.ballman wrote:
> > mlychkov wrote:
> > > aaron.ballman wrote:
> > > > If we're going to be touching this code, there's more suspect code here 
> > > > that needs to be cleaned up a bit. Directly above this is:
> > > > ```
> > > >   const TypeConstraint *TC =
> > > >   cast(TPL->getParam(0))->getTypeConstraint();
> > > >   assert(TC &&
> > > >  "TPL must have a template type parameter with a type 
> > > > constraint");
> > > > ```
> > > > That assertion can be removed entirely -- if the `cast<>` fails, it 
> > > > doesn't return null, it asserts.
> > > Actually, cast return nonnull value, but
> > >TC = "cast_result"->getTypeConstraint();
> > > and TC may become nullptr, I suppose.
> > Good catch! I think we should add the assertion on `TC` being nonnull back. 
> > I'll take care of that.
> Ooh, good catch!  I definitely missed that when suggesting removing the 
> assert.  @aaron.ballman  can you re-add the assert on 1065?
I've put the assert back in 0cf4f81082e9fa052e60450b8cbb10007e59931c, thanks 
for letting us know @mlychkov!


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

https://reviews.llvm.org/D108481

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


[PATCH] D108765: [docs] Fix documentation of clang-format BasedOnStyle type

2021-08-26 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added subscribers: HazardyKnusperkeks, owenpan, krasimir, 
sammccall, curdeius, klimek.
MyDeveloperDay added a comment.

In D108765#2967363 , @FederAndInk 
wrote:

> Thank you for your explanations, I understand now.
>
> But as I look into `clang/docs/tools/dump_format_style.py` I see that it does 
> not entirely generate `clang/docs/ClangFormatStyleOptions.rst` it replaces 
> the lines between `{START,END}_FORMAT_STYLE_OPTIONS`
>
> I understand your point, but as of now, the inconsistency comes from the part 
> that is not auto-generated, are you suggesting editing `dump_format_style.py` 
> to have simpler types such as `string`? Then how should we replace 
> `std::vector`? Something like `Type[]` e.g. `string[]`?
>
> Or maybe we should first include `BasedOnStyle` into `dump_format_style.py`. 
> Then take care of how to render types?
>
> What do you suggest? I am genuinely asking, as I really don't know what would 
> be the best way to do things. Maybe we should include other people? I don't 
> really know who to add as reviewers for that, but I think, the way to show 
> types, should be discussed?
>
> As for detailing `RawStringFormat`, it wasn't the purpose of this patch, and 
> maybe it should have its own?

You are correct the file isn't 100% generated and some of it comes from another 
.h file too.

But now we have you interesting in making a contribution which you clearly are 
lets think about how we might do this.

To hook into the clang-format team I always recommend adding the #clang-format 
 project, (which I added to this 
review), but also I recommend passing the review via @krasimir , 
@HazardyKnusperkeks , @curdeius there are some others who are hear often like 
@owenpan and @sammccall and of course @klimek (who started all this). Please 
also of course add me @MyDeveloperDay I try to check the reviews daily as one 
of my frustrations was not being able to get things reviewed so I try to be 
pretty active.

From my perspective I do like the idea of substituting out the `std::string` 
and `std::vector` for something like `string[]` how about we start with 
something simple like trying to fix the cases for `AttributeMacros 
(std::vector)` maybe with just simple substitution.

We can pass that via the rest of the team and see what they feel even if we 
ultimately have both

AttributeMacros (in configuration `string[]`)

or something like that, I'm not con convinced anyone is using this 
documentation to know its a std::vector!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108765

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


[clang] a233f03 - Typo fix; NFC

2021-08-26 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2021-08-26T12:53:52-04:00
New Revision: a233f0350d4790227f138e2118c0d18c2b45f855

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

LOG: Typo fix; NFC

Added: 


Modified: 
clang/include/clang/AST/DeclTemplate.h

Removed: 




diff  --git a/clang/include/clang/AST/DeclTemplate.h 
b/clang/include/clang/AST/DeclTemplate.h
index cbaa287f225a5..d59a0549f4c10 100644
--- a/clang/include/clang/AST/DeclTemplate.h
+++ b/clang/include/clang/AST/DeclTemplate.h
@@ -1189,7 +1189,7 @@ class TemplateTypeParmDecl final : public TypeDecl,
 
   /// Whether the type constraint has been initialized. This can be false if 
the
   /// constraint was not initialized yet or if there was an error forming the
-  /// type constriant.
+  /// type constraint.
   bool TypeConstraintInitialized : 1;
 
   /// Whether this non-type template parameter is an "expanded"



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


[PATCH] D108742: Reclassify form-feed and vertical tab as vertical WS for the purposes of lexing.

2021-08-26 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith added a comment.

Thanks for looking at this — I'm just reviewing the test changes in the 
minimizer (assuming the code change is the right thing to do).




Comment at: 
clang/unittests/Lex/DependencyDirectivesSourceMinimizerTest.cpp:170-173
   ASSERT_FALSE(
-  minimizeSourceToDependencyDirectives("#define MACRO(a\\\n"
+  minimizeSourceToDependencyDirectives("#define MACRO(a
\\\n\\\v\\\f"
"  )",
Out));

Please don't modify this assertion to test `\v` and `\f`. Instead add new 
assertions. I'm not sure if they belong in `DefineMultilineArgs`, or if 
`DefineSpacing` might be a better spot, or maybe a new test 
`DefineVerticalWhitespace`?



Comment at: clang/unittests/Lex/DependencyDirectivesSourceMinimizerTest.cpp:186
Out));
-  EXPECT_STREQ("#define MACRO(a)\n", Out.data());
-

Please don't remove this test coverage.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108742

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


[PATCH] D108695: [analyzer][NFCI] Allow clients of NoStateChangeFuncVisitor to check entire function calls, rather than each ExplodedNode in it

2021-08-26 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

Would this work correctly when the property is changed but then reverted to its 
original state? This probably can't happen to MallocChecker (what has been 
freed cannot be unfreed) but it may happen to eg. PthreadLockChecker or to, 
well, Stores. In such cases it would be incorrect to say "returning without 
changing the state".




Comment at: clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp:370
+  while (N && !N->getLocationAs())
+N = N->getFirstSucc();
+  return N;

This is the right successor because we're in a heavily trimmed exploded graph, 
right?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108695

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


[PATCH] D105167: [analyzer] Fix HTML report deduplication.

2021-08-26 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ updated this revision to Diff 368917.
NoQ marked 4 inline comments as done.
NoQ added a comment.

Address review comments!


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

https://reviews.llvm.org/D105167

Files:
  clang/include/clang/Analysis/PathDiagnostic.h
  clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def
  clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
  clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
  clang/test/Analysis/analyzer-config.c
  clang/test/Analysis/scan-build/Inputs/deduplication/1.c
  clang/test/Analysis/scan-build/Inputs/deduplication/2.c
  clang/test/Analysis/scan-build/Inputs/deduplication/header.h
  clang/test/Analysis/scan-build/deduplication.test
  clang/test/Analysis/scan-build/rebuild_index/rebuild_index.test
  clang/test/Analysis/scan-build/rebuild_index/report-3.html
  clang/test/Analysis/scan-build/rebuild_index/subdirectory/report-3.html
  clang/test/Analysis/scan-build/rebuild_index/subdirectory/report-4.html
  clang/tools/scan-build/bin/scan-build

Index: clang/tools/scan-build/bin/scan-build
===
--- clang/tools/scan-build/bin/scan-build
+++ clang/tools/scan-build/bin/scan-build
@@ -14,7 +14,6 @@
 use strict;
 use warnings;
 use FindBin qw($RealBin);
-use Digest::MD5;
 use File::Basename;
 use File::Find;
 use File::Copy qw(copy);
@@ -268,27 +267,6 @@
   $ENV{'CCC_ANALYZER_HTML'} = $Dir;
 }
 
-####
-# ComputeDigest - Compute a digest of the specified file.
-####
-
-sub ComputeDigest {
-  my $FName = shift;
-  DieDiag("Cannot read $FName to compute Digest.\n") if (! -r $FName);
-
-  # Use Digest::MD5.  We don't have to be cryptographically secure.  We're
-  # just looking for duplicate files that come from a non-malicious source.
-  # We use Digest::MD5 because it is a standard Perl module that should
-  # come bundled on most systems.
-  open(FILE, $FName) or DieDiag("Cannot open $FName when computing Digest.\n");
-  binmode FILE;
-  my $Result = Digest::MD5->new->addfile(*FILE)->hexdigest;
-  close(FILE);
-
-  # Return the digest.
-  return $Result;
-}
-
 ####
 #  UpdatePrefix - Compute the common prefix of files.
 ####
@@ -374,8 +352,6 @@
 # Sometimes a source file is scanned more than once, and thus produces
 # multiple error reports.  We use a cache to solve this problem.
 
-my %AlreadyScanned;
-
 sub ScanFile {
 
   my $Index = shift;
@@ -383,19 +359,6 @@
   my $FName = shift;
   my $Stats = shift;
 
-  # Compute a digest for the report file.  Determine if we have already
-  # scanned a file that looks just like it.
-
-  my $digest = ComputeDigest("$Dir/$FName");
-
-  if (defined $AlreadyScanned{$digest}) {
-# Redundant file.  Remove it.
-unlink("$Dir/$FName");
-return;
-  }
-
-  $AlreadyScanned{$digest} = 1;
-
   # At this point the report file is not world readable.  Make it happen.
   chmod(0644, "$Dir/$FName");
 
Index: clang/test/Analysis/scan-build/rebuild_index/subdirectory/report-4.html
===
--- clang/test/Analysis/scan-build/rebuild_index/subdirectory/report-4.html
+++ /dev/null
@@ -1,8 +0,0 @@
-
-
-
-
-
-
-
-
Index: clang/test/Analysis/scan-build/rebuild_index/subdirectory/report-3.html
===
--- /dev/null
+++ clang/test/Analysis/scan-build/rebuild_index/subdirectory/report-3.html
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
Index: clang/test/Analysis/scan-build/rebuild_index/report-3.html
===
--- clang/test/Analysis/scan-build/rebuild_index/report-3.html
+++ /dev/null
@@ -1,8 +0,0 @@
-
-
-
-
-
-
-
-
Index: clang/test/Analysis/scan-build/rebuild_index/rebuild_index.test
===
--- clang/test/Analysis/scan-build/rebuild_index/rebuild_index.test
+++ clang/test/Analysis/scan-build/rebuild_index/rebuild_index.test
@@ -4,9 +4,8 @@
 RUN: rm -rf %t.output_dir && mkdir %t.output_dir
 RUN: cp %S/report-1.html %t.output_dir
 RUN: cp %S/report-2.html %t.output_dir
-RUN: cp %S/report-3.html %t.output_dir
 RUN: mkdir %t.output_dir/subdirectory
-RUN: cp %S/subdirectory/report-4.html %t.output_dir/subdirectory
+RUN: cp %S/subdirectory/report-3.html %t.output_dir/subdirectory
 
 RUN: %scan-build --generate-index-only %t.output_dir
 
@@ -15,16 +14,13 @@
 CHECK-FILES:  index.html
 CHECK-FILES-NEXT: report-1.html
 CHECK-FILES-NEXT: report-2.html
-
-// report-3.html is a duplicate of report-1.html so it's not present.
-CHECK-FILES-NOT:  report-3.html
 CHECK-FILES-NEXT: scanview.css
 CHECK-FILES-NEXT: sorttable.js
 CHECK-

[PATCH] D105167: [analyzer] Fix HTML report deduplication.

2021-08-26 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

In D105167#2949521 , @ASDenysPetrov 
wrote:

> Nice work! Unfortunately I'm not able to run tests on my Windows env, but 
> I've run you tests files manually. It works for me.
>
> P.S. BTW, is there any workarounds to make current tests supported on 
> Windows? I know there is //REQUIRES// instruction 
> (https://llvm.org/docs/TestingGuide.html#constraining-test-execution) but I 
> didn't find any sufficient description of it.

Yes, you can always remove the `REQUIRES:` directive. The problem with 
generally enabling these tests on Windows is that scan-build is written in Perl 
and the Perl interpreter isn't shipped with Windows by default. Nothing else in 
LLVM is written in Perl so requiring a Perl installation to run LLVM tests just 
for this single use case is counter-productive.




Comment at: clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp:286-287
+  // but the stable report filename is still more verbose.
+  // We should rename the option ("verbose" filename?) but it will break
+  // people's workflows.
+  if (DiagOpts.ShouldWriteStableReportFilename) {

ASDenysPetrov wrote:
> vsavchenko wrote:
> > Can we make a mirror for this option and mark the other one as deprecated?
> Nice idea. I'm in favor of a mirorring.
The new option is `-analyzer-config verbose-report-filename=true` and the old 
option is preserved and acts exactly the same; the help text says that it's 
deprecated.



Comment at: clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp:300
+
+  filename << StringRef(getIssueHash(D, PP)).substr(0, 6).str() << ".html";
+  llvm::sys::path::append(ResultPath, Directory, filename.str());

ASDenysPetrov wrote:
> Do you think 6 trimmed characters are enough to avoid collisions?
It's basically same as before. Previously these 6 digits were completely 
random, now they're chunks of MD5 hashes of the real thing which is probably as 
random.

That's 16.7 million variants. The probability of collision on 6 digits with 100 
warnings is around 0.0001%, with 1000 warnings it goes up to 3% ([[ 
https://en.wikipedia.org/wiki/Birthday_problem | Birthday Problem]]). Even 
though 1000 warnings are a real possibility on a huge project (eg., LLVM or 
WebKit), this is way above the point where you care about collisions.

I think there's nothing that prevents us from bumping it (at least in the 
non-verbose filename mode; in the verbose filename mode it may cause slightly 
more breakages in the case where it's close to hitting the file system's 
filename length limit). Bumping from 6 digits to 8 digits would reduce the 
collision probability on 1000 warnings to 0.0001%. I'll think about it a bit 
more :)


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

https://reviews.llvm.org/D105167

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


[PATCH] D70172: [CUDA][HIP][OpenMP] Emit deferred diagnostics by a post-parsing AST travese

2021-08-26 Thread Wei Wang via Phabricator via cfe-commits
weiwang added a comment.

In D70172#2964118 , @sugak wrote:

> Hi @yaxunl! I'm working on upgrading a large codebase from LLVM-9 to LLVM-12. 
> I noticed on average 10% compilation speed regression that seems to be caused 
> this change. We use Clang modules and historically provide `-fopenmp` 
> compiler flag by default. The problem seems to be that compiling and 
> importing modules is now slower, with the generated modules size increased by 
> 2X. llvm-bcanalyzer tool shows that it's dominated by 
> `DECLS_TO_CHECK_FOR_DEFERRED_DIAGS`.  If I understand it right, your change 
> is only relevant when target offloading is used. I inspected all of `#pragma 
> omp` directives and can confirm that we don't use it.
>
> I see that most of this code is gated by OpenMP flag. I wonder if there is a 
> finer grain way to enable openmp parallel code generation without target 
> offloading? Would it make sense to extend this code to check if 
> `-fopenom-targets` is set before recording 
> `DECLS_TO_CHECK_FOR_DEFERRED_DIAGS`?
>
> Note, this was measured with @weiwang's https://reviews.llvm.org/D101793.

We did an internal measurement by not adding decls into deferred diags, and 
that resolves the build regression. Wonder if we can have a special case for 
emitting diag as they are encountered when everything is on host side.


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

https://reviews.llvm.org/D70172

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


[PATCH] D107769: [OpenCL] Make generic addrspace optional for -fdeclare-opencl-builtins

2021-08-26 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added a comment.

In D107769#2960441 , @svenvh wrote:

> I have done an alternative spin of this patch: instead of introducing 
> `RequireDisabledExtension`, simply always make the `private`, `global`, and 
> `local` overloads available.  This makes tablegen diverge from `opencl-c.h` 
> though.  Perhaps we should also always add make the `private`, `global`, and 
> `local` overloads available in `opencl-c.h`?

Yes, we could do this indeed as a clang extension. I don't think this will 
impact the user code. However, this means vendors will have to add extra 
overloads in OpenCL 2.0 mode?


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

https://reviews.llvm.org/D107769

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


[PATCH] D106619: [Clang][LLVM] generate btf_tag annotations for DIGlobalVariable

2021-08-26 Thread Yonghong Song via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG30c288489ae5: [DebugInfo] generate btf_tag annotations for 
DIGlobalVariable (authored by yonghong-song).

Changed prior to commit:
  https://reviews.llvm.org/D106619?vs=367710&id=368920#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106619

Files:
  llvm/include/llvm/IR/DIBuilder.h
  llvm/include/llvm/IR/DebugInfoMetadata.h
  llvm/lib/AsmParser/LLParser.cpp
  llvm/lib/Bitcode/Reader/MetadataLoader.cpp
  llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
  llvm/lib/IR/AsmWriter.cpp
  llvm/lib/IR/DIBuilder.cpp
  llvm/lib/IR/DebugInfoMetadata.cpp
  llvm/lib/IR/LLVMContextImpl.h
  llvm/test/Bitcode/attr-btf_tag-diglobalvariable.ll
  llvm/unittests/IR/MetadataTest.cpp

Index: llvm/unittests/IR/MetadataTest.cpp
===
--- llvm/unittests/IR/MetadataTest.cpp
+++ llvm/unittests/IR/MetadataTest.cpp
@@ -2574,7 +2574,8 @@
 
   auto *N = DIGlobalVariable::get(
   Context, Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit,
-  IsDefinition, StaticDataMemberDeclaration, templateParams, AlignInBits);
+  IsDefinition, StaticDataMemberDeclaration, templateParams, AlignInBits,
+  nullptr);
 
   EXPECT_EQ(dwarf::DW_TAG_variable, N->getTag());
   EXPECT_EQ(Scope, N->getScope());
@@ -2591,52 +2592,54 @@
   EXPECT_EQ(N, DIGlobalVariable::get(Context, Scope, Name, LinkageName, File,
  Line, Type, IsLocalToUnit, IsDefinition,
  StaticDataMemberDeclaration,
- templateParams, AlignInBits));
+ templateParams, AlignInBits, nullptr));
 
   EXPECT_NE(N, DIGlobalVariable::get(
Context, getSubprogram(), Name, LinkageName, File, Line,
Type, IsLocalToUnit, IsDefinition,
-   StaticDataMemberDeclaration, templateParams, AlignInBits));
+   StaticDataMemberDeclaration, templateParams, AlignInBits,
+   nullptr));
   EXPECT_NE(N, DIGlobalVariable::get(Context, Scope, "other", LinkageName, File,
  Line, Type, IsLocalToUnit, IsDefinition,
  StaticDataMemberDeclaration,
- templateParams, AlignInBits));
+ templateParams, AlignInBits, nullptr));
   EXPECT_NE(N, DIGlobalVariable::get(Context, Scope, Name, "other", File, Line,
  Type, IsLocalToUnit, IsDefinition,
  StaticDataMemberDeclaration,
- templateParams, AlignInBits));
+ templateParams, AlignInBits, nullptr));
   EXPECT_NE(N, DIGlobalVariable::get(Context, Scope, Name, LinkageName,
  getFile(), Line, Type, IsLocalToUnit,
  IsDefinition, StaticDataMemberDeclaration,
- templateParams, AlignInBits));
+ templateParams, AlignInBits, nullptr));
   EXPECT_NE(N, DIGlobalVariable::get(Context, Scope, Name, LinkageName, File,
  Line + 1, Type, IsLocalToUnit,
  IsDefinition, StaticDataMemberDeclaration,
- templateParams, AlignInBits));
+ templateParams, AlignInBits, nullptr));
   EXPECT_NE(N, DIGlobalVariable::get(Context, Scope, Name, LinkageName, File,
  Line, getDerivedType(), IsLocalToUnit,
  IsDefinition, StaticDataMemberDeclaration,
- templateParams, AlignInBits));
+ templateParams, AlignInBits, nullptr));
   EXPECT_NE(N, DIGlobalVariable::get(Context, Scope, Name, LinkageName, File,
  Line, Type, !IsLocalToUnit, IsDefinition,
  StaticDataMemberDeclaration,
- templateParams, AlignInBits));
+ templateParams, AlignInBits, nullptr));
   EXPECT_NE(N, DIGlobalVariable::get(Context, Scope, Name, LinkageName, File,
  Line, Type, IsLocalToUnit, !IsDefinition,
  StaticDataMemberDeclaration,
- templateParams, AlignInBits));
+ templateParams, AlignInBits, nullptr));
   EXPECT_NE(N, DIGlobalVariable::get(Context, Scope, Name, LinkageName, File,
  Line, 

[PATCH] D108704: [OpenCL] Define OpenCL 3.0 optional core features in C++ for OpenCL 2021

2021-08-26 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia accepted this revision.
Anastasia added a comment.
This revision is now accepted and ready to land.

LGTM! Thanks


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108704

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


[PATCH] D108693: [OpenCL] Defines helper function for kernel language compatible OpenCL version

2021-08-26 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia accepted this revision.
Anastasia added a comment.
This revision is now accepted and ready to land.

LGTM! Thanks!

This is a very nice clean up!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108693

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


[PATCH] D108243: Revert "Avoid needlessly copying a block to the heap when a block literal"

2021-08-26 Thread James Y Knight via Phabricator via cfe-commits
jyknight added a comment.

Ping. Any comment from Apple folks?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108243

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


[PATCH] D102449: [WIP][Clang][OpenMP] Add the support for compare clause in atomic directive

2021-08-26 Thread Carlo Bertolli via Phabricator via cfe-commits
carlo.bertolli added a comment.

Thanks for uploading this.

I tried it locally and it is missing proper parsing +sema of the cond-expr-stmt 
and cond-update-stmt as indicate in the openmp 5.1 spec's. I am sure you are 
aware of this and this is still WIP.
Do you plan to add support for that? The regression test is not exposing 
conditional statements, but update ones, so it is not really testing what it 
should.

You might also want to split parse+sema support from codegen, if it helps.

Many thanks again!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102449

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


[clang] d2d7a90 - [DebugInfo] convert btf_tag attrs to DI annotations for DIGlobalVariable

2021-08-26 Thread Yonghong Song via cfe-commits

Author: Yonghong Song
Date: 2021-08-26T10:36:33-07:00
New Revision: d2d7a90ceded94251905b7adcd5eb2ac5191896f

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

LOG: [DebugInfo] convert btf_tag attrs to DI annotations for DIGlobalVariable

Generate btf_tag annotations for DIGlobalVariable. The annotations
are represented as an DINodeArray in DebugInfo.

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

Added: 
clang/test/CodeGen/attr-btf_tag-diglobalvariable.c

Modified: 
clang/lib/CodeGen/CGDebugInfo.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 57f915028dde..2de933f65800 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -4828,12 +4828,13 @@ void 
CGDebugInfo::EmitGlobalVariable(llvm::GlobalVariable *Var,
 }
 AppendAddressSpaceXDeref(AddressSpace, Expr);
 
+llvm::DINodeArray Annotations = CollectBTFTagAnnotations(D);
 GVE = DBuilder.createGlobalVariableExpression(
 DContext, DeclName, LinkageName, Unit, LineNo, getOrCreateType(T, 
Unit),
 Var->hasLocalLinkage(), true,
 Expr.empty() ? nullptr : DBuilder.createExpression(Expr),
 getOrCreateStaticDataMemberDeclarationOrNull(D), TemplateParameters,
-Align);
+Align, Annotations);
 Var->addDebugInfo(GVE);
   }
   DeclCache[D->getCanonicalDecl()].reset(GVE);

diff  --git a/clang/test/CodeGen/attr-btf_tag-diglobalvariable.c 
b/clang/test/CodeGen/attr-btf_tag-diglobalvariable.c
new file mode 100644
index ..e8b20a202990
--- /dev/null
+++ b/clang/test/CodeGen/attr-btf_tag-diglobalvariable.c
@@ -0,0 +1,29 @@
+// REQUIRES: x86-registered-target
+// RUN: %clang -target x86_64 -g -S -emit-llvm -o - %s | FileCheck %s
+
+#define __tag1 __attribute__((btf_tag("tag1")))
+#define __tag2 __attribute__((btf_tag("tag2")))
+
+struct t1 {
+  int a;
+};
+struct t1 g1 __tag1 __tag2;
+
+extern struct t1 g2 __tag1 __tag2;
+struct t1 g2;
+
+// CHECK: distinct !DIGlobalVariable(name: "g1", scope: ![[#]], file: ![[#]], 
line: [[#]], type: ![[#]], isLocal: false, isDefinition: true, annotations: 
![[ANNOT:[0-9]+]])
+// CHECK: distinct !DIGlobalVariable(name: "g2", scope: ![[#]], file: ![[#]], 
line: [[#]], type: ![[#]], isLocal: false, isDefinition: true, annotations: 
![[ANNOT]])
+// CHECK: ![[ANNOT]] = !{![[TAG1:[0-9]+]], ![[TAG2:[0-9]+]]}
+// CHECK: ![[TAG1]] = !{!"btf_tag", !"tag1"}
+// CHECK: ![[TAG2]] = !{!"btf_tag", !"tag2"}
+
+extern struct t1 g3 __tag1;
+struct t1 g3 __tag2;
+
+// CHECK: distinct !DIGlobalVariable(name: "g3", scope: ![[#]], file: ![[#]], 
line: [[#]], type: ![[#]], isLocal: false, isDefinition: true, annotations: 
![[ANNOT]])
+
+extern struct t1 g4;
+struct t1 g4 __tag1 __tag2;
+
+// CHECK: distinct !DIGlobalVariable(name: "g4", scope: ![[#]], file: ![[#]], 
line: [[#]], type: ![[#]], isLocal: false, isDefinition: true, annotations: 
![[ANNOT]])



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


[PATCH] D108774: [OpenMP][FIX] Allow declare variant to work with reference types

2021-08-26 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert created this revision.
jdoerfert added reviewers: JonChesterfield, ABataev, pdhaliwal, aaron.ballman.
Herald added subscribers: guansong, bollu, yaxunl.
jdoerfert requested review of this revision.
Herald added a subscriber: sstefan1.
Herald added a project: clang.

Reference types in the return or parameter position did cause the OpenMP
declare variant overload reasoning to give up. We should allow them as
we allow any other type.

This should fix the bug reported on the mailing list:
https://lists.llvm.org/pipermail/openmp-dev/2021-August/004094.html


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D108774

Files:
  clang/lib/AST/ASTContext.cpp


Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -9680,11 +9680,16 @@
 QualType ASTContext::mergeTypes(QualType LHS, QualType RHS,
 bool OfBlockPointer,
 bool Unqualified, bool BlockReturnType) {
+  // For C++ we will not reach this code with reference types (see below),
+  // for OpenMP variant call overloading we might.
+  //
   // C++ [expr]: If an expression initially has the type "reference to T", the
   // type is adjusted to "T" prior to any further analysis, the expression
   // designates the object or function denoted by the reference, and the
   // expression is an lvalue unless the reference is an rvalue reference and
   // the expression is a function call (possibly inside parentheses).
+  if (LHS->getAs() && RHS->getAs())
+return mergeTypes(LHS->getAs()->getPointeeType() , 
RHS->getAs()->getPointeeType(), OfBlockPointer, Unqualified, 
BlockReturnType);
   if (LHS->getAs() || RHS->getAs())
 return {};
 


Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -9680,11 +9680,16 @@
 QualType ASTContext::mergeTypes(QualType LHS, QualType RHS,
 bool OfBlockPointer,
 bool Unqualified, bool BlockReturnType) {
+  // For C++ we will not reach this code with reference types (see below),
+  // for OpenMP variant call overloading we might.
+  //
   // C++ [expr]: If an expression initially has the type "reference to T", the
   // type is adjusted to "T" prior to any further analysis, the expression
   // designates the object or function denoted by the reference, and the
   // expression is an lvalue unless the reference is an rvalue reference and
   // the expression is a function call (possibly inside parentheses).
+  if (LHS->getAs() && RHS->getAs())
+return mergeTypes(LHS->getAs()->getPointeeType() , RHS->getAs()->getPointeeType(), OfBlockPointer, Unqualified, BlockReturnType);
   if (LHS->getAs() || RHS->getAs())
 return {};
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D108774: [OpenMP][FIX] Allow declare variant to work with reference types

2021-08-26 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert updated this revision to Diff 368940.
jdoerfert added a comment.

Add test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108774

Files:
  clang/lib/AST/ASTContext.cpp
  clang/test/AST/ast-dump-openmp-begin-declare-variant_reference.cpp

Index: clang/test/AST/ast-dump-openmp-begin-declare-variant_reference.cpp
===
--- /dev/null
+++ clang/test/AST/ast-dump-openmp-begin-declare-variant_reference.cpp
@@ -0,0 +1,146 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fopenmp -verify -ast-dump %s   | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fopenmp -verify -ast-dump %s -x c++| FileCheck %s
+// expected-no-diagnostics
+
+int Good, Bad;
+int& also_before() {
+  return Bad;
+}
+
+#pragma omp begin declare variant match(implementation={vendor(score(100):llvm)})
+int also_after(void) {
+  return 2;
+}
+int also_after(int&) {
+  return 3;
+}
+int also_after(double&) {
+  return 0;
+}
+#pragma omp end declare variant
+#pragma omp begin declare variant match(implementation={vendor(score(0):llvm)})
+int& also_before() {
+  return Good;
+}
+#pragma omp end declare variant
+
+int also_after(void) {
+  return 4;
+}
+int also_after(int) {
+  return 5;
+}
+int also_after(double&) {
+  return 6;
+}
+
+int test1() {
+  // Should return 0.
+  double d;
+  return also_after(d);
+}
+
+int test2() {
+  // Should return 0.
+  return &also_before() == &Good;
+}
+
+int test() {
+  // Should return 0.
+  return test1() + test2();
+}
+
+// CHECK:  |-VarDecl [[ADDR_0:0x[a-z0-9]*]] <{{.*}}, col:5> col:5 used Good 'int'
+// CHECK-NEXT: |-VarDecl [[ADDR_1:0x[a-z0-9]*]]  col:11 used Bad 'int'
+// CHECK-NEXT: |-FunctionDecl [[ADDR_2:0x[a-z0-9]*]]  line:6:6 used also_before 'int &({{.*}})'
+// CHECK-NEXT: | |-CompoundStmt [[ADDR_3:0x[a-z0-9]*]] 
+// CHECK-NEXT: | | `-ReturnStmt [[ADDR_4:0x[a-z0-9]*]] 
+// CHECK-NEXT: | |   `-DeclRefExpr [[ADDR_5:0x[a-z0-9]*]]  'int' {{.*}}Var [[ADDR_1]] 'Bad' 'int'
+// CHECK-NEXT: | `-OMPDeclareVariantAttr [[ADDR_6:0x[a-z0-9]*]] <> Implicit implementation={vendor(score(0): llvm)}
+// CHECK-NEXT: |   `-DeclRefExpr [[ADDR_7:0x[a-z0-9]*]]  'int &({{.*}})' {{.*}}Function [[ADDR_8:0x[a-z0-9]*]] 'also_before[implementation={vendor(llvm)}]' 'int &({{.*}})'
+// CHECK-NEXT: |-FunctionDecl [[ADDR_9:0x[a-z0-9]*]]  col:5 implicit also_after 'int ({{.*}})'
+// CHECK-NEXT: | `-OMPDeclareVariantAttr [[ADDR_10:0x[a-z0-9]*]] <> Implicit implementation={vendor(score(100): llvm)}
+// CHECK-NEXT: |   `-DeclRefExpr [[ADDR_11:0x[a-z0-9]*]]  'int ({{.*}})' {{.*}}Function [[ADDR_12:0x[a-z0-9]*]] 'also_after[implementation={vendor(llvm)}]' 'int ({{.*}})'
+// CHECK-NEXT: |-FunctionDecl [[ADDR_12]]  line:11:1 also_after[implementation={vendor(llvm)}] 'int ({{.*}})'
+// CHECK-NEXT: | `-CompoundStmt [[ADDR_13:0x[a-z0-9]*]] 
+// CHECK-NEXT: |   `-ReturnStmt [[ADDR_14:0x[a-z0-9]*]] 
+// CHECK-NEXT: | `-IntegerLiteral [[ADDR_15:0x[a-z0-9]*]]  'int' 2
+// CHECK-NEXT: |-FunctionDecl [[ADDR_16:0x[a-z0-9]*]]  col:5 implicit also_after 'int (int &)'
+// CHECK-NEXT: | |-ParmVarDecl [[ADDR_17:0x[a-z0-9]*]]  col:20 'int &'
+// CHECK-NEXT: | `-OMPDeclareVariantAttr [[ADDR_18:0x[a-z0-9]*]] <> Implicit implementation={vendor(score(100): llvm)}
+// CHECK-NEXT: |   `-DeclRefExpr [[ADDR_19:0x[a-z0-9]*]]  'int (int &)' {{.*}}Function [[ADDR_20:0x[a-z0-9]*]] 'also_after[implementation={vendor(llvm)}]' 'int (int &)'
+// CHECK-NEXT: |-FunctionDecl [[ADDR_20]]  line:14:1 also_after[implementation={vendor(llvm)}] 'int (int &)'
+// CHECK-NEXT: | |-ParmVarDecl [[ADDR_17]]  col:20 'int &'
+// CHECK-NEXT: | `-CompoundStmt [[ADDR_21:0x[a-z0-9]*]] 
+// CHECK-NEXT: |   `-ReturnStmt [[ADDR_22:0x[a-z0-9]*]] 
+// CHECK-NEXT: | `-IntegerLiteral [[ADDR_23:0x[a-z0-9]*]]  'int' 3
+// CHECK-NEXT: |-FunctionDecl [[ADDR_24:0x[a-z0-9]*]]  col:5 implicit used also_after 'int (double &)'
+// CHECK-NEXT: | |-ParmVarDecl [[ADDR_25:0x[a-z0-9]*]]  col:23 'double &'
+// CHECK-NEXT: | `-OMPDeclareVariantAttr [[ADDR_26:0x[a-z0-9]*]] <> Implicit implementation={vendor(score(100): llvm)}
+// CHECK-NEXT: |   `-DeclRefExpr [[ADDR_27:0x[a-z0-9]*]]  'int (double &)' {{.*}}Function [[ADDR_28:0x[a-z0-9]*]] 'also_after[implementation={vendor(llvm)}]' 'int (double &)'
+// CHECK-NEXT: |-FunctionDecl [[ADDR_28]]  line:17:1 also_after[implementation={vendor(llvm)}] 'int (double &)'
+// CHECK-NEXT: | |-ParmVarDecl [[ADDR_25]]  col:23 'double &'
+// CHECK-NEXT: | `-CompoundStmt [[ADDR_29:0x[a-z0-9]*]] 
+// CHECK-NEXT: |   `-ReturnStmt [[ADDR_30:0x[a-z0-9]*]] 
+// CHECK-NEXT: | `-IntegerLiteral [[ADDR_31:0x[a-z0-9]*]]  'int' 0
+// CHECK-NEXT: |-FunctionDecl [[ADDR_8]]  line:22:1 also_before[implementation={vendor(llvm)}] 'int &({{.*}})'
+// CHECK-NEXT: | `-CompoundStmt [[ADDR_32:0x[a-z0-9]*]] 
+// CHECK-NEXT: |   `-ReturnStmt [[ADDR_33:0x[a-z0-9]*]] 
+// CHECK-NEXT: | `-DeclRefExpr [[ADDR_34:0x

[PATCH] D108775: [CMake] Change -DENABLE_EXPERIMENTAL_NEW_PASS_MANAGER=off to -DLLVM_ENABLE_NEW_PASS_MANAGER=off

2021-08-26 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay created this revision.
MaskRay added reviewers: aeubanks, phosek, tstellar.
Herald added a subscriber: mgorny.
MaskRay requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

LLVM_ENABLE_NEW_PASS_MANAGER is set to ENABLE_EXPERIMENTAL_NEW_PASS_MANAGER, so
-D has no effect.

Change the cache variable to LLVM_ENABLE_NEW_PASS_MANAGER instead.

Also give a warning that -DLLVM_ENABLE_NEW_PASS_MANAGER=off is deprecated.

Intended for main and release/13.x


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D108775

Files:
  clang/cmake/caches/Fuchsia-stage2.cmake
  clang/cmake/caches/Fuchsia.cmake
  llvm/CMakeLists.txt
  llvm/docs/NewPassManager.rst


Index: llvm/docs/NewPassManager.rst
===
--- llvm/docs/NewPassManager.rst
+++ llvm/docs/NewPassManager.rst
@@ -449,7 +449,7 @@
 
 For the optimization pipeline, the new PM is the default PM. The legacy PM is
 available for the optimization pipeline either by setting the CMake flag
-``-DENABLE_EXPERIMENTAL_NEW_PASS_MANAGER=OFF`` when building LLVM, or by
+``-DLLVM_ENABLE_NEW_PASS_MANAGER=OFF`` when building LLVM, or by
 various compiler/linker flags, e.g. ``-flegacy-pass-manager`` for ``clang``.
 
 There will be efforts to deprecate and remove the legacy PM for the
Index: llvm/CMakeLists.txt
===
--- llvm/CMakeLists.txt
+++ llvm/CMakeLists.txt
@@ -706,8 +706,13 @@
 endif()
 option(LLVM_ENABLE_PLUGINS "Enable plugin support" 
${LLVM_ENABLE_PLUGINS_default})
 
-set(ENABLE_EXPERIMENTAL_NEW_PASS_MANAGER TRUE CACHE BOOL
+set(LLVM_ENABLE_NEW_PASS_MANAGER TRUE CACHE BOOL
   "Enable the new pass manager by default.")
+if(NOT LLVM_ENABLE_NEW_PASS_MANAGER)
+  message(WARNING "Using the legacy pass manager for the optimization pipeline"
+  " is deprecated. The functionality will degrade over time 
and"
+  " be removed in a future release.")
+endif()
 
 include(HandleLLVMOptions)
 
@@ -846,10 +851,6 @@
   set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS tf_xla_runtime)
 endif()
 
-# Keep the legacy CMake flag ENABLE_EXPERIMENTAL_NEW_PASS_MANAGER for
-# compatibility.
-set(LLVM_ENABLE_NEW_PASS_MANAGER ${ENABLE_EXPERIMENTAL_NEW_PASS_MANAGER})
-
 # Configure the three LLVM configuration header files.
 configure_file(
   ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/config.h.cmake
Index: clang/cmake/caches/Fuchsia.cmake
===
--- clang/cmake/caches/Fuchsia.cmake
+++ clang/cmake/caches/Fuchsia.cmake
@@ -32,7 +32,6 @@
 set(CLANG_ENABLE_STATIC_ANALYZER ON CACHE BOOL "")
 set(CLANG_PLUGIN_SUPPORT OFF CACHE BOOL "")
 
-set(ENABLE_EXPERIMENTAL_NEW_PASS_MANAGER ON CACHE BOOL "")
 set(ENABLE_LINKER_BUILD_ID ON CACHE BOOL "")
 set(ENABLE_X86_RELAX_RELOCATIONS ON CACHE BOOL "")
 
Index: clang/cmake/caches/Fuchsia-stage2.cmake
===
--- clang/cmake/caches/Fuchsia-stage2.cmake
+++ clang/cmake/caches/Fuchsia-stage2.cmake
@@ -41,7 +41,6 @@
 set(CLANG_ENABLE_STATIC_ANALYZER ON CACHE BOOL "")
 set(CLANG_PLUGIN_SUPPORT OFF CACHE BOOL "")
 
-set(ENABLE_EXPERIMENTAL_NEW_PASS_MANAGER ON CACHE BOOL "")
 set(ENABLE_LINKER_BUILD_ID ON CACHE BOOL "")
 set(ENABLE_X86_RELAX_RELOCATIONS ON CACHE BOOL "")
 


Index: llvm/docs/NewPassManager.rst
===
--- llvm/docs/NewPassManager.rst
+++ llvm/docs/NewPassManager.rst
@@ -449,7 +449,7 @@
 
 For the optimization pipeline, the new PM is the default PM. The legacy PM is
 available for the optimization pipeline either by setting the CMake flag
-``-DENABLE_EXPERIMENTAL_NEW_PASS_MANAGER=OFF`` when building LLVM, or by
+``-DLLVM_ENABLE_NEW_PASS_MANAGER=OFF`` when building LLVM, or by
 various compiler/linker flags, e.g. ``-flegacy-pass-manager`` for ``clang``.
 
 There will be efforts to deprecate and remove the legacy PM for the
Index: llvm/CMakeLists.txt
===
--- llvm/CMakeLists.txt
+++ llvm/CMakeLists.txt
@@ -706,8 +706,13 @@
 endif()
 option(LLVM_ENABLE_PLUGINS "Enable plugin support" ${LLVM_ENABLE_PLUGINS_default})
 
-set(ENABLE_EXPERIMENTAL_NEW_PASS_MANAGER TRUE CACHE BOOL
+set(LLVM_ENABLE_NEW_PASS_MANAGER TRUE CACHE BOOL
   "Enable the new pass manager by default.")
+if(NOT LLVM_ENABLE_NEW_PASS_MANAGER)
+  message(WARNING "Using the legacy pass manager for the optimization pipeline"
+  " is deprecated. The functionality will degrade over time and"
+  " be removed in a future release.")
+endif()
 
 include(HandleLLVMOptions)
 
@@ -846,10 +851,6 @@
   set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS tf_xla_runtime)
 endif()
 
-# Keep the legacy CMake flag ENABLE_EXPERIMENTAL_NEW_PASS_MANAGER for
-# compatibility.
-set(LLVM_ENABLE_NEW_PASS_MANAGER ${ENABL

[PATCH] D108774: [OpenMP][FIX] Allow declare variant to work with reference types

2021-08-26 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert updated this revision to Diff 368943.
jdoerfert added a comment.

Clang format patch


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108774

Files:
  clang/lib/AST/ASTContext.cpp
  clang/test/AST/ast-dump-openmp-begin-declare-variant_reference.cpp

Index: clang/test/AST/ast-dump-openmp-begin-declare-variant_reference.cpp
===
--- /dev/null
+++ clang/test/AST/ast-dump-openmp-begin-declare-variant_reference.cpp
@@ -0,0 +1,148 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fopenmp -verify -ast-dump %s   | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fopenmp -verify -ast-dump %s -x c++| FileCheck %s
+// expected-no-diagnostics
+
+int Good, Bad;
+int &also_before() {
+  return Bad;
+}
+
+#pragma omp begin declare variant match(implementation = {vendor(score(100) \
+ : llvm)})
+int also_after(void) {
+  return 2;
+}
+int also_after(int &) {
+  return 3;
+}
+int also_after(double &) {
+  return 0;
+}
+#pragma omp end declare variant
+#pragma omp begin declare variant match(implementation = {vendor(score(0) \
+ : llvm)})
+int &also_before() {
+  return Good;
+}
+#pragma omp end declare variant
+
+int also_after(void) {
+  return 4;
+}
+int also_after(int) {
+  return 5;
+}
+int also_after(double &) {
+  return 6;
+}
+
+int test1() {
+  // Should return 0.
+  double d;
+  return also_after(d);
+}
+
+int test2() {
+  // Should return 0.
+  return &also_before() == &Good;
+}
+
+int test() {
+  // Should return 0.
+  return test1() + test2();
+}
+
+// CHECK:  |-VarDecl [[ADDR_0:0x[a-z0-9]*]] <{{.*}}, col:5> col:5 used Good 'int'
+// CHECK-NEXT: |-VarDecl [[ADDR_1:0x[a-z0-9]*]]  col:11 used Bad 'int'
+// CHECK-NEXT: |-FunctionDecl [[ADDR_2:0x[a-z0-9]*]]  line:6:6 used also_before 'int &({{.*}})'
+// CHECK-NEXT: | |-CompoundStmt [[ADDR_3:0x[a-z0-9]*]] 
+// CHECK-NEXT: | | `-ReturnStmt [[ADDR_4:0x[a-z0-9]*]] 
+// CHECK-NEXT: | |   `-DeclRefExpr [[ADDR_5:0x[a-z0-9]*]]  'int' {{.*}}Var [[ADDR_1]] 'Bad' 'int'
+// CHECK-NEXT: | `-OMPDeclareVariantAttr [[ADDR_6:0x[a-z0-9]*]] <> Implicit implementation={vendor(score(0): llvm)}
+// CHECK-NEXT: |   `-DeclRefExpr [[ADDR_7:0x[a-z0-9]*]]  'int &({{.*}})' {{.*}}Function [[ADDR_8:0x[a-z0-9]*]] 'also_before[implementation={vendor(llvm)}]' 'int &({{.*}})'
+// CHECK-NEXT: |-FunctionDecl [[ADDR_9:0x[a-z0-9]*]]  col:5 implicit also_after 'int ({{.*}})'
+// CHECK-NEXT: | `-OMPDeclareVariantAttr [[ADDR_10:0x[a-z0-9]*]] <> Implicit implementation={vendor(score(100): llvm)}
+// CHECK-NEXT: |   `-DeclRefExpr [[ADDR_11:0x[a-z0-9]*]]  'int ({{.*}})' {{.*}}Function [[ADDR_12:0x[a-z0-9]*]] 'also_after[implementation={vendor(llvm)}]' 'int ({{.*}})'
+// CHECK-NEXT: |-FunctionDecl [[ADDR_12]]  line:11:1 also_after[implementation={vendor(llvm)}] 'int ({{.*}})'
+// CHECK-NEXT: | `-CompoundStmt [[ADDR_13:0x[a-z0-9]*]] 
+// CHECK-NEXT: |   `-ReturnStmt [[ADDR_14:0x[a-z0-9]*]] 
+// CHECK-NEXT: | `-IntegerLiteral [[ADDR_15:0x[a-z0-9]*]]  'int' 2
+// CHECK-NEXT: |-FunctionDecl [[ADDR_16:0x[a-z0-9]*]]  col:5 implicit also_after 'int (int &)'
+// CHECK-NEXT: | |-ParmVarDecl [[ADDR_17:0x[a-z0-9]*]]  col:20 'int &'
+// CHECK-NEXT: | `-OMPDeclareVariantAttr [[ADDR_18:0x[a-z0-9]*]] <> Implicit implementation={vendor(score(100): llvm)}
+// CHECK-NEXT: |   `-DeclRefExpr [[ADDR_19:0x[a-z0-9]*]]  'int (int &)' {{.*}}Function [[ADDR_20:0x[a-z0-9]*]] 'also_after[implementation={vendor(llvm)}]' 'int (int &)'
+// CHECK-NEXT: |-FunctionDecl [[ADDR_20]]  line:14:1 also_after[implementation={vendor(llvm)}] 'int (int &)'
+// CHECK-NEXT: | |-ParmVarDecl [[ADDR_17]]  col:20 'int &'
+// CHECK-NEXT: | `-CompoundStmt [[ADDR_21:0x[a-z0-9]*]] 
+// CHECK-NEXT: |   `-ReturnStmt [[ADDR_22:0x[a-z0-9]*]] 
+// CHECK-NEXT: | `-IntegerLiteral [[ADDR_23:0x[a-z0-9]*]]  'int' 3
+// CHECK-NEXT: |-FunctionDecl [[ADDR_24:0x[a-z0-9]*]]  col:5 implicit used also_after 'int (double &)'
+// CHECK-NEXT: | |-ParmVarDecl [[ADDR_25:0x[a-z0-9]*]]  col:23 'double &'
+// CHECK-NEXT: | `-OMPDeclareVariantAttr [[ADDR_26:0x[a-z0-9]*]] <> Implicit implementation={vendor(score(100): llvm)}
+// CHECK-NEXT: |   `-DeclRefExpr [[ADDR_27:0x[a-z0-9]*]]  'int (double &)' {{.*}}Function [[ADDR_28:0x[a-z0-9]*]] 'also_after[implementation={vendor(llvm)}]' 'int (double &)'
+// CHECK-NEXT: |-FunctionDecl [[ADDR_28]]  line:17:1 also_after[implementation={vendor(llvm)}] 'int (double &)'
+// CHECK-NEXT: | |-ParmVarDecl [[ADDR_25]]  col:23 'double &'
+// CHECK-NEXT: | `-CompoundStmt [[ADDR_29:0x[a-z0-9]*]] 
+// CHECK-NEXT: |   `-ReturnStmt [[ADDR_30:0x[a-z0-9]*]] 
+// CHECK-NEXT: | `-IntegerLiteral [[ADDR_31:0x[a-z0-9]*]]  'int' 0
+// CHECK-NEXT: |-FunctionDecl [[ADDR_8]]  line:22:1 also_before[implementation={vendor(llvm)}] 'int &({{.*}})'
+// CHE

[PATCH] D108775: [CMake] Change -DENABLE_EXPERIMENTAL_NEW_PASS_MANAGER=off to -DLLVM_ENABLE_NEW_PASS_MANAGER=off

2021-08-26 Thread Arthur Eubanks via Phabricator via cfe-commits
aeubanks accepted this revision.
aeubanks added a comment.
This revision is now accepted and ready to land.

this is good, but IMO it's not clear enough in the description that this is a 
breaking change in terms of CMake flags (use -DLLVM_ENABLE_NEW_PASS_MANAGER 
instead of -DEXPERIMENTAL_NEW_PASS_MANAGER)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108775

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


[PATCH] D108742: Reclassify form-feed and vertical tab as vertical WS for the purposes of lexing.

2021-08-26 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added inline comments.



Comment at: 
clang/unittests/Lex/DependencyDirectivesSourceMinimizerTest.cpp:170-173
   ASSERT_FALSE(
-  minimizeSourceToDependencyDirectives("#define MACRO(a\\\n"
+  minimizeSourceToDependencyDirectives("#define MACRO(a
\\\n\\\v\\\f"
"  )",
Out));

dexonsmith wrote:
> Please don't modify this assertion to test `\v` and `\f`. Instead add new 
> assertions. I'm not sure if they belong in `DefineMultilineArgs`, or if 
> `DefineSpacing` might be a better spot, or maybe a new test 
> `DefineVerticalWhitespace`?
I think this test is useful, you are right I should add more somewhere else. I 
will also add that new test without removing the old one!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108742

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


[PATCH] D108752: [clang-format] Group options that pack constructor initializers

2021-08-26 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks accepted this revision.
HazardyKnusperkeks added inline comments.



Comment at: clang/unittests/Format/FormatTest.cpp:18472
+  FormatStyle::PCIS_Never);
+
   Style.EmptyLineBeforeAccessModifier = FormatStyle::ELBAMS_LogicalBlock;

Should there be a test for the mapping?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108752

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


[PATCH] D108765: [docs] Fix documentation of clang-format BasedOnStyle type

2021-08-26 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks requested changes to this revision.
HazardyKnusperkeks added a comment.

As the one who wrote that:

1. Yes that part is not auto generated, because it is not in the `format.h`.
2. I'm more in favor of removing the `std::` from the documentation.
3. It is for the YAML documentation, then stick with the YAML names: `List of 
Strings` is my proposal.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108765

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


[PATCH] D108742: Reclassify form-feed and vertical tab as vertical WS for the purposes of lexing.

2021-08-26 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 368958.
cor3ntin added a comment.

- Add tests and fix existing tests (again)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108742

Files:
  clang/lib/Basic/CharInfo.cpp
  clang/unittests/Basic/CharInfoTest.cpp
  clang/unittests/Lex/DependencyDirectivesSourceMinimizerTest.cpp
  clang/unittests/Lex/LexerTest.cpp

Index: clang/unittests/Lex/LexerTest.cpp
===
--- clang/unittests/Lex/LexerTest.cpp
+++ clang/unittests/Lex/LexerTest.cpp
@@ -493,10 +493,10 @@
 
   EXPECT_TRUE(hasNewLineEscaped("\\\r"));
   EXPECT_TRUE(hasNewLineEscaped("\\\n"));
+  EXPECT_TRUE(hasNewLineEscaped("\\\v"));
   EXPECT_TRUE(hasNewLineEscaped("\\\r\n"));
   EXPECT_TRUE(hasNewLineEscaped("\\\n\r"));
-  EXPECT_TRUE(hasNewLineEscaped("\\ \t\v\f\r"));
-  EXPECT_TRUE(hasNewLineEscaped("\\ \t\v\f\r\n"));
+  EXPECT_TRUE(hasNewLineEscaped("\\ \t\r\n"));
 
   EXPECT_FALSE(hasNewLineEscaped("\\\r\r"));
   EXPECT_FALSE(hasNewLineEscaped("\\\r\r\n"));
Index: clang/unittests/Lex/DependencyDirectivesSourceMinimizerTest.cpp
===
--- clang/unittests/Lex/DependencyDirectivesSourceMinimizerTest.cpp
+++ clang/unittests/Lex/DependencyDirectivesSourceMinimizerTest.cpp
@@ -162,18 +162,6 @@
   ASSERT_FALSE(minimizeSourceToDependencyDirectives(
   "#define MACRO(\t)\tcon \t tent\t", Out));
   EXPECT_STREQ("#define MACRO() con \t tent\n", Out.data());
-
-  ASSERT_FALSE(minimizeSourceToDependencyDirectives(
-  "#define MACRO(\f)\fcon \f tent\f", Out));
-  EXPECT_STREQ("#define MACRO() con \f tent\n", Out.data());
-
-  ASSERT_FALSE(minimizeSourceToDependencyDirectives(
-  "#define MACRO(\v)\vcon \v tent\v", Out));
-  EXPECT_STREQ("#define MACRO() con \v tent\n", Out.data());
-
-  ASSERT_FALSE(minimizeSourceToDependencyDirectives(
-  "#define MACRO \t\v\f\v\t con\f\t\vtent\v\f \v", Out));
-  EXPECT_STREQ("#define MACRO con\f\t\vtent\n", Out.data());
 }
 
 TEST(MinimizeSourceToDependencyDirectivesTest, DefineMultilineArgs) {
@@ -194,6 +182,29 @@
   EXPECT_STREQ("#define MACRO(a,b) call((a), (b))\n", Out.data());
 }
 
+TEST(MinimizeSourceToDependencyDirectivesTest,
+ DefineMultilineArgsVerticalWhiteSpaces) {
+  SmallVector Out;
+
+  ASSERT_FALSE(
+  minimizeSourceToDependencyDirectives("#define MACRO(a\\\f"
+   "  )",
+   Out));
+  EXPECT_STREQ("#define MACRO(a)\n", Out.data());
+
+  ASSERT_FALSE(
+  minimizeSourceToDependencyDirectives("#define MACRO(a\\\v"
+   "  )",
+   Out));
+  EXPECT_STREQ("#define MACRO(a)\n", Out.data());
+
+  ASSERT_FALSE(minimizeSourceToDependencyDirectives(
+  "#define MACRO(a\\\f\\\v\\\v\\\f"
+  "  )",
+  Out));
+  EXPECT_STREQ("#define MACRO(a)\n", Out.data());
+}
+
 TEST(MinimizeSourceToDependencyDirectivesTest,
  DefineMultilineArgsCarriageReturn) {
   SmallVector Out;
Index: clang/unittests/Basic/CharInfoTest.cpp
===
--- clang/unittests/Basic/CharInfoTest.cpp
+++ clang/unittests/Basic/CharInfoTest.cpp
@@ -17,8 +17,8 @@
   using namespace charinfo;
   EXPECT_EQ((unsigned)CHAR_SPACE,   InfoTable[(unsigned)' ']);
   EXPECT_EQ((unsigned)CHAR_HORZ_WS, InfoTable[(unsigned)'\t']);
-  EXPECT_EQ((unsigned)CHAR_HORZ_WS, InfoTable[(unsigned)'\f']); // ??
-  EXPECT_EQ((unsigned)CHAR_HORZ_WS, InfoTable[(unsigned)'\v']); // ??
+  EXPECT_EQ((unsigned)CHAR_VERT_WS, InfoTable[(unsigned)'\f']);
+  EXPECT_EQ((unsigned)CHAR_VERT_WS, InfoTable[(unsigned)'\v']);
   EXPECT_EQ((unsigned)CHAR_VERT_WS, InfoTable[(unsigned)'\n']);
   EXPECT_EQ((unsigned)CHAR_VERT_WS, InfoTable[(unsigned)'\r']);
   EXPECT_EQ((unsigned)CHAR_UNDER,   InfoTable[(unsigned)'_']);
@@ -101,8 +101,6 @@
 
   EXPECT_TRUE(isHorizontalWhitespace(' '));
   EXPECT_TRUE(isHorizontalWhitespace('\t'));
-  EXPECT_TRUE(isHorizontalWhitespace('\f')); // ??
-  EXPECT_TRUE(isHorizontalWhitespace('\v')); // ??
 
   EXPECT_FALSE(isHorizontalWhitespace('\n'));
   EXPECT_FALSE(isHorizontalWhitespace('\r'));
@@ -123,9 +121,9 @@
 
   EXPECT_FALSE(isVerticalWhitespace(' '));
   EXPECT_FALSE(isVerticalWhitespace('\t'));
-  EXPECT_FALSE(isVerticalWhitespace('\f')); // ??
-  EXPECT_FALSE(isVerticalWhitespace('\v')); // ??
 
+  EXPECT_TRUE(isVerticalWhitespace('\f')); // ??
+  EXPECT_TRUE(isVerticalWhitespace('\v')); // ??
   EXPECT_TRUE(isVerticalWhitespace('\n'));
   EXPECT_TRUE(isVerticalWhitespace('\r'));
 
Index: clang/lib/Basic/CharInfo.cpp
===
--- clang/lib/Basic/CharInfo.cpp
+++ clang/lib/Basic/CharInfo.cpp
@@ -12,6 +12,7 @@
 
 // Statically initialize CharInfo table 

[PATCH] D108695: [analyzer][NFCI] Allow clients of NoStateChangeFuncVisitor to check entire function calls, rather than each ExplodedNode in it

2021-08-26 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus added a comment.

In D108695#2967540 , @NoQ wrote:

> Would this work correctly when the property is changed but then reverted to 
> its original state? This probably can't happen to MallocChecker (what has 
> been freed cannot be unfreed) but it may happen to eg. PthreadLockChecker or 
> to, well, Stores. In such cases it would be incorrect to say "returning 
> without changing the state".

It should! But you have a point, I don't have the code to prove it right away. 
Maybe if I factored out the symbol part into NoStateChangeToSymbolVisitor, as 
teased in D105553#2864318 , it'd have 
an easier time to see it. With that said, I don't currently see how the current 
implementation would be faulty, but even if it is, the patch adds an option, 
and doesn't the take old one (that NoStoreFuncVisitor still uses) away.




Comment at: clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp:370
+  while (N && !N->getLocationAs())
+N = N->getFirstSucc();
+  return N;

NoQ wrote:
> This is the right successor because we're in a heavily trimmed exploded 
> graph, right?
Should be, yes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108695

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


[PATCH] D108479: [Clang] Add __builtin_addressof_nocfi

2021-08-26 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers added inline comments.



Comment at: clang/lib/CodeGen/CGExprConstant.cpp:1890
 
-if (auto FD = dyn_cast(D))
-  return CGM.GetAddrOfFunction(FD);
+if (auto FD = dyn_cast(D)) {
+  auto *C = CGM.GetAddrOfFunction(FD);

fix linter warning



Comment at: clang/lib/CodeGen/CGExprConstant.cpp:1891
+if (auto FD = dyn_cast(D)) {
+  auto *C = CGM.GetAddrOfFunction(FD);
+  if (base.isNoCFIValue())

Don't use `auto` here.
https://llvm.org/docs/CodingStandards.html#use-auto-type-deduction-to-make-code-more-readable
It's common when the type is already specified on the RHS of an assignment 
that's using of the casting operators that's already explicitly specialized 
with the type.



Comment at: clang/test/CodeGen/builtin-addressof-nocfi.c:18
+  // CHECK: call void @c(void ()* no_cfi @a)
+  c(__builtin_addressof_nocfi(a));
+  e();

do we ever need the builtin address of a global that's NOT a function?

If so, we should add a test for that. If not, perhaps we don't need to waste 
space in every APValue?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108479

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


[PATCH] D108377: [asan] Implemented flag to emit intrinsics to optimize ASan callbacks.

2021-08-26 Thread Kirill Stoimenov via Phabricator via cfe-commits
kstoimenov updated this revision to Diff 368959.
kstoimenov added a comment.

Fixed the test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108377

Files:
  llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
  llvm/test/Instrumentation/AddressSanitizer/asan-optimize-callbacks.ll

Index: llvm/test/Instrumentation/AddressSanitizer/asan-optimize-callbacks.ll
===
--- /dev/null
+++ llvm/test/Instrumentation/AddressSanitizer/asan-optimize-callbacks.ll
@@ -0,0 +1,86 @@
+; RUN: opt < %s -asan -enable-new-pm=0 -asan-instrumentation-with-call-threshold=0 \
+; RUN:   -asan-optimize-callbacks -S | FileCheck %s --check-prefixes=LOAD,STORE
+; RUN: opt < %s -asan -enable-new-pm=0 -asan-instrumentation-with-call-threshold=0 \
+; RUN:   -asan-optimize-callbacks --asan-kernel -S | \
+; RUN:   FileCheck %s --check-prefixes=LOAD-KERNEL,STORE-KERNEL
+
+target triple = "x86_64-unknown-linux-gnu"
+
+define void @load(i8* %p1, i16* %p2, i32* %p4, i64* %p8, i128* %p16)
+sanitize_address {
+  %n1 = load i8, i8* %p1, align 1
+  %n2 = load i16, i16* %p2, align 2
+  %n4 = load i32, i32* %p4, align 4
+  %n8 = load i64, i64* %p8, align 8
+  %n16 = load i128, i128* %p16, align 16
+; LOAD:  call void @llvm.asan.check.memaccess(i8* %p1, i32 0)
+; LOAD-NEXT: %n1 = load i8, i8* %p1, align 1
+; LOAD-NEXT: %1 = bitcast i16* %p2 to i8*
+; LOAD-NEXT: call void @llvm.asan.check.memaccess(i8* %1, i32 2)
+; LOAD-NEXT: %n2 = load i16, i16* %p2, align 2
+; LOAD-NEXT: %2 = bitcast i32* %p4 to i8*
+; LOAD-NEXT: call void @llvm.asan.check.memaccess(i8* %2, i32 4)
+; LOAD-NEXT: %n4 = load i32, i32* %p4, align 4
+; LOAD-NEXT: %3 = bitcast i64* %p8 to i8*
+; LOAD-NEXT: call void @llvm.asan.check.memaccess(i8* %3, i32 6)
+; LOAD-NEXT: %n8 = load i64, i64* %p8, align 8
+; LOAD-NEXT: %4 = bitcast i128* %p16 to i8*
+; LOAD-NEXT: call void @llvm.asan.check.memaccess(i8* %4, i32 8)
+; LOAD-NEXT: %n16 = load i128, i128* %p16, align 16
+
+; LOAD-KERNEL:  call void @llvm.asan.check.memaccess(i8* %p1, i32 1)
+; LOAD-KERNEL-NEXT: %n1 = load i8, i8* %p1, align 1
+; LOAD-KERNEL-NEXT: %1 = bitcast i16* %p2 to i8*
+; LOAD-KERNEL-NEXT: call void @llvm.asan.check.memaccess(i8* %1, i32 3)
+; LOAD-KERNEL-NEXT: %n2 = load i16, i16* %p2, align 2
+; LOAD-KERNEL-NEXT: %2 = bitcast i32* %p4 to i8*
+; LOAD-KERNEL-NEXT: call void @llvm.asan.check.memaccess(i8* %2, i32 5)
+; LOAD-KERNEL-NEXT: %n4 = load i32, i32* %p4, align 4
+; LOAD-KERNEL-NEXT: %3 = bitcast i64* %p8 to i8*
+; LOAD-KERNEL-NEXT: call void @llvm.asan.check.memaccess(i8* %3, i32 7)
+; LOAD-KERNEL-NEXT: %n8 = load i64, i64* %p8, align 8
+; LOAD-KERNEL-NEXT: %4 = bitcast i128* %p16 to i8*
+; LOAD-KERNEL-NEXT: call void @llvm.asan.check.memaccess(i8* %4, i32 9)
+; LOAD-KERNEL-NEXT: %n16 = load i128, i128* %p16, align 16
+  ret void
+}
+
+define void @store(i8* %p1, i16* %p2, i32* %p4, i64* %p8, i128* %p16)
+sanitize_address {
+  store i8 0, i8* %p1, align 1
+  store i16 0, i16* %p2, align 2
+  store i32 0, i32* %p4, align 4
+  store i64 0, i64* %p8, align 8
+  store i128 0, i128* %p16, align 16
+; STORE:  call void @llvm.asan.check.memaccess(i8* %p1, i32 32)
+; STORE-NEXT: store i8 0, i8* %p1, align 1
+; STORE-NEXT: %1 = bitcast i16* %p2 to i8*
+; STORE-NEXT: call void @llvm.asan.check.memaccess(i8* %1, i32 34)
+; STORE-NEXT: store i16 0, i16* %p2, align 2
+; STORE-NEXT: %2 = bitcast i32* %p4 to i8*
+; STORE-NEXT: call void @llvm.asan.check.memaccess(i8* %2, i32 36)
+; STORE-NEXT: store i32 0, i32* %p4, align 4
+; STORE-NEXT: %3 = bitcast i64* %p8 to i8*
+; STORE-NEXT: call void @llvm.asan.check.memaccess(i8* %3, i32 38)
+; STORE-NEXT: store i64 0, i64* %p8, align 8
+; STORE-NEXT: %4 = bitcast i128* %p16 to i8*
+; STORE-NEXT: call void @llvm.asan.check.memaccess(i8* %4, i32 40)
+; STORE-NEXT: store i128 0, i128* %p16, align 16
+
+; STORE-KERNEL:  call void @llvm.asan.check.memaccess(i8* %p1, i32 33)
+; STORE-KERNEL-NEXT: store i8 0, i8* %p1, align 1
+; STORE-KERNEL-NEXT: %1 = bitcast i16* %p2 to i8*
+; STORE-KERNEL-NEXT: call void @llvm.asan.check.memaccess(i8* %1, i32 35)
+; STORE-KERNEL-NEXT: store i16 0, i16* %p2, align 2
+; STORE-KERNEL-NEXT: %2 = bitcast i32* %p4 to i8*
+; STORE-KERNEL-NEXT: call void @llvm.asan.check.memaccess(i8* %2, i32 37)
+; STORE-KERNEL-NEXT: store i32 0, i32* %p4, align 4
+; STORE-KERNEL-NEXT: %3 = bitcast i64* %p8 to i8*
+; STORE-KERNEL-NEXT: call void @llvm.asan.check.memaccess(i8* %3, i32 39)
+; STORE-KERNEL-NEXT: store i64 0, i64* %p8, align 8
+; STORE-KERNEL-NEXT: %4 = bitcast i128* %p16 to i8*
+; STORE-KERNEL-NEXT: call void @llvm.asan.check.memaccess(i8* %4, i32 41)
+; STORE-KERNEL-NEXT: store i128 0, i128* %p16, align 16
+; STORE-KERNEL-NEXT: ret void
+  ret void
+}
Index: llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
===
--- llvm/lib/Trans

[PATCH] D108482: [Clang] Fix instantiation of OpaqueValueExprs (Bug #45964)

2021-08-26 Thread Jason Rice via Phabricator via cfe-commits
ricejasonf updated this revision to Diff 368962.
ricejasonf added a comment.

I moved the test to CodeGenCXX and actually test output with FileCheck. I used 
the code from a non-template function as the expected output. Some minor 
formatting changes are also addressed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108482

Files:
  clang/lib/Sema/SemaInit.cpp
  clang/lib/Sema/TreeTransform.h
  clang/test/CodeGenCXX/pr45964-decomp-transform.cpp


Index: clang/test/CodeGenCXX/pr45964-decomp-transform.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/pr45964-decomp-transform.cpp
@@ -0,0 +1,27 @@
+// RUN: %clang_cc1 -std=c++1z -triple x86_64-linux-gnu -emit-llvm -o - %s | 
FileCheck %s
+
+int a[1];
+// CHECK: @a = global [1 x i32] zeroinitializer
+template 
+void test_transform() {
+  auto [b] = a;
+}
+void (*d)(){test_transform<0>};
+// CHECK-LABEL: define {{.*}} @_Z14test_transformILi0EEvv
+// CHECK:   [[ENTRY:.*]]:
+// CHECK-NEXT:  [[ARR:%.*]] = alloca [1 x i32]
+// CHECK-NEXT:  [[BEGIN:%.*]] = getelementptr inbounds [1 x i32], [1 x i32]* 
[[ARR]], i64 0, i64 0
+// CHECK-NEXT:  br label %[[BODY:.*]]
+// CHECK-EMPTY:
+// CHECK-NEXT:  [[BODY]]:
+// CHECK-NEXT:  [[CUR:%.*]] = phi i64 [ 0, %[[ENTRY]] ], [ [[NEXT:%.*]], 
%[[BODY]] ]
+// CHECK-NEXT:  [[DEST:%.*]] = getelementptr inbounds i32, i32* [[BEGIN]], i64 
[[CUR]]
+// CHECK-NEXT:  [[SRC:%.*]] = getelementptr inbounds [1 x i32], [1 x i32]* @a, 
i64 0, i64 [[CUR]]
+// CHECK-NEXT:  [[X:%.*]] = load i32, i32* [[SRC]]
+// CHECK-NEXT:  store i32 [[X]], i32* [[DEST]]
+// CHECK-NEXT:  [[NEXT]] = add nuw i64 [[CUR]], 1
+// CHECK-NEXT:  [[EQ:%.*]] = icmp eq i64 [[NEXT]], 1
+// CHECK-NEXT:  br i1 [[EQ]], label %[[FIN:.*]], label %[[BODY]]
+// CHECK-EMPTY:
+// CHECK-NEXT:  [[FIN]]:
+// CHECK-NEXT:  ret void
Index: clang/lib/Sema/TreeTransform.h
===
--- clang/lib/Sema/TreeTransform.h
+++ clang/lib/Sema/TreeTransform.h
@@ -10511,7 +10511,18 @@
 TreeTransform::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
   assert((!E->getSourceExpr() || 
getDerived().AlreadyTransformed(E->getType())) &&
  "opaque value expression requires transformation");
-  return E;
+
+  // Note that SourceExpr can be nullptr.
+  ExprResult SourceExpr = TransformExpr(E->getSourceExpr());
+  if (SourceExpr.isInvalid())
+return ExprError();
+  if (SourceExpr.get() == E->getSourceExpr() && !getDerived().AlwaysRebuild())
+return E;
+
+  OpaqueValueExpr *New = new (SemaRef.Context)
+  OpaqueValueExpr(E->getExprLoc(), E->getType(), E->getValueKind(),
+  E->getObjectKind(), SourceExpr.get());
+  return New;
 }
 
 template
Index: clang/lib/Sema/SemaInit.cpp
===
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -8643,9 +8643,13 @@
 
 case SK_ArrayLoopIndex: {
   Expr *Cur = CurInit.get();
-  Expr *BaseExpr = new (S.Context)
-  OpaqueValueExpr(Cur->getExprLoc(), Cur->getType(),
-  Cur->getValueKind(), Cur->getObjectKind(), Cur);
+  // Prevent nested OpaqueValueExprs.
+  Expr *BaseExpr = dyn_cast(Cur);
+  if (!BaseExpr) {
+BaseExpr = new (S.Context)
+OpaqueValueExpr(Cur->getExprLoc(), Cur->getType(),
+Cur->getValueKind(), Cur->getObjectKind(), Cur);
+  }
   Expr *IndexExpr =
   new (S.Context) ArrayInitIndexExpr(S.Context.getSizeType());
   CurInit = S.CreateBuiltinArraySubscriptExpr(


Index: clang/test/CodeGenCXX/pr45964-decomp-transform.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/pr45964-decomp-transform.cpp
@@ -0,0 +1,27 @@
+// RUN: %clang_cc1 -std=c++1z -triple x86_64-linux-gnu -emit-llvm -o - %s | FileCheck %s
+
+int a[1];
+// CHECK: @a = global [1 x i32] zeroinitializer
+template 
+void test_transform() {
+  auto [b] = a;
+}
+void (*d)(){test_transform<0>};
+// CHECK-LABEL: define {{.*}} @_Z14test_transformILi0EEvv
+// CHECK:   [[ENTRY:.*]]:
+// CHECK-NEXT:  [[ARR:%.*]] = alloca [1 x i32]
+// CHECK-NEXT:  [[BEGIN:%.*]] = getelementptr inbounds [1 x i32], [1 x i32]* [[ARR]], i64 0, i64 0
+// CHECK-NEXT:  br label %[[BODY:.*]]
+// CHECK-EMPTY:
+// CHECK-NEXT:  [[BODY]]:
+// CHECK-NEXT:  [[CUR:%.*]] = phi i64 [ 0, %[[ENTRY]] ], [ [[NEXT:%.*]], %[[BODY]] ]
+// CHECK-NEXT:  [[DEST:%.*]] = getelementptr inbounds i32, i32* [[BEGIN]], i64 [[CUR]]
+// CHECK-NEXT:  [[SRC:%.*]] = getelementptr inbounds [1 x i32], [1 x i32]* @a, i64 0, i64 [[CUR]]
+// CHECK-NEXT:  [[X:%.*]] = load i32, i32* [[SRC]]
+// CHECK-NEXT:  store i32 [[X]], i32* [[DEST]]
+// CHECK-NEXT:  [[NEXT]] = add nuw i64 [[CUR]], 1
+// CHECK-NEXT:  [[EQ:%.*]] = icmp eq i64 [[NEXT]], 1
+// CHECK-NEXT:  br i1 [[EQ]], label %[[F

[PATCH] D108774: [OpenMP][FIX] Allow declare variant to work with reference types

2021-08-26 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: clang/lib/AST/ASTContext.cpp:9691
   // the expression is a function call (possibly inside parentheses).
+  if (LHS->getAs() && RHS->getAs())
+return mergeTypes(LHS->getAs()->getPointeeType(),

Does it matter if it is an LValueReferenceType or RValueReferenceType? What if 
one type is `&` ref kind and another is `&&`?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108774

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


  1   2   >