[PATCH] D102592: [sanitizer] Caught global buffer underflow for first variable

2021-05-20 Thread Zhiwei Chen via Phabricator via cfe-commits
condy added a comment.

In D102592#2769811 , @eugenis wrote:

> I think it is too hit-and-miss to add even under a flag. It's just not the 
> right approach - but I also don't know what the right approach would be.
>
> Perhaps adding a small left redzone for all globals and reducing the right 
> redzone to keep the total size under control? This way when most globals are 
> instrumented we get approximately the same amount of redzone between any 2 of 
> them, but also a little on the left of the first one.

Thanks for explanation, I will try your suggested approach.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102592

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


[clang-tools-extra] 775ca3a - [clang-tidy] Fix a crash for raw-string-literal check.

2021-05-20 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2021-05-20T09:16:43+02:00
New Revision: 775ca3a89cba104d7c0dc762a0c5c5624c1d397c

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

LOG: [clang-tidy] Fix a crash for raw-string-literal check.

getSourceText could return an empty string for error cases (e.g. invalid
source locaiton), this patch makes the code more robust.

The crash did happen in our internal codebase, but unfortunately I
didn't manage to get a reproduce case. One thing I can confirm from
the core dump is that the crash is caused by calling isRawStringLiteral
on an empty Text.

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

Added: 


Modified: 
clang-tools-extra/clang-tidy/modernize/RawStringLiteralCheck.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/modernize/RawStringLiteralCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/RawStringLiteralCheck.cpp
index 7990bc2b8f2a6..26b1d8ecdc319 100644
--- a/clang-tools-extra/clang-tidy/modernize/RawStringLiteralCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/RawStringLiteralCheck.cpp
@@ -56,7 +56,7 @@ bool containsEscapedCharacters(const MatchFinder::MatchResult 
&Result,
   *Result.SourceManager, Result.Context->getLangOpts());
   StringRef Text = Lexer::getSourceText(CharRange, *Result.SourceManager,
 Result.Context->getLangOpts());
-  if (isRawStringLiteral(Text))
+  if (Text.empty() || isRawStringLiteral(Text))
 return false;
 
   return containsEscapes(Text, R"('\"?x01)");



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


[PATCH] D102770: [clang-tidy] Fix a crash for raw-string-literal check.

2021-05-20 Thread Haojian Wu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG775ca3a89cba: [clang-tidy] Fix a crash for 
raw-string-literal check. (authored by hokein).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102770

Files:
  clang-tools-extra/clang-tidy/modernize/RawStringLiteralCheck.cpp


Index: clang-tools-extra/clang-tidy/modernize/RawStringLiteralCheck.cpp
===
--- clang-tools-extra/clang-tidy/modernize/RawStringLiteralCheck.cpp
+++ clang-tools-extra/clang-tidy/modernize/RawStringLiteralCheck.cpp
@@ -56,7 +56,7 @@
   *Result.SourceManager, Result.Context->getLangOpts());
   StringRef Text = Lexer::getSourceText(CharRange, *Result.SourceManager,
 Result.Context->getLangOpts());
-  if (isRawStringLiteral(Text))
+  if (Text.empty() || isRawStringLiteral(Text))
 return false;
 
   return containsEscapes(Text, R"('\"?x01)");


Index: clang-tools-extra/clang-tidy/modernize/RawStringLiteralCheck.cpp
===
--- clang-tools-extra/clang-tidy/modernize/RawStringLiteralCheck.cpp
+++ clang-tools-extra/clang-tidy/modernize/RawStringLiteralCheck.cpp
@@ -56,7 +56,7 @@
   *Result.SourceManager, Result.Context->getLangOpts());
   StringRef Text = Lexer::getSourceText(CharRange, *Result.SourceManager,
 Result.Context->getLangOpts());
-  if (isRawStringLiteral(Text))
+  if (Text.empty() || isRawStringLiteral(Text))
 return false;
 
   return containsEscapes(Text, R"('\"?x01)");
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D102779: [clang-tidy] cppcoreguidelines-explicit-constructor-and-conversion: new alias

2021-05-20 Thread Marco Gartmann via Phabricator via cfe-commits
mgartmann updated this revision to Diff 346640.
mgartmann edited the summary of this revision.
mgartmann added a comment.

Added `ConstructorWhitelist`  option to the `google-explicit-constructor` check.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102779

Files:
  clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  clang-tools-extra/clang-tidy/google/ExplicitConstructorCheck.cpp
  clang-tools-extra/clang-tidy/google/ExplicitConstructorCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines-explicit-constructor-and-conversion.rst
  clang-tools-extra/docs/clang-tidy/checks/google-explicit-constructor.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/test/clang-tidy/checkers/google-explicit-constructor-constructorwhitelist-option.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/google-explicit-constructor-constructorwhitelist-option.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/google-explicit-constructor-constructorwhitelist-option.cpp
@@ -0,0 +1,99 @@
+// RUN: %check_clang_tidy -check-suffix=DEFAULT %s \
+// RUN: google-explicit-constructor %t -- \
+// RUN: -config='{CheckOptions: [ \
+// RUN: ]}'
+
+// RUN: %check_clang_tidy -check-suffix=WHITELISTED %s \
+// RUN: google-explicit-constructor %t -- \
+// RUN: -config='{CheckOptions: [ \
+// RUN:   {key: google-explicit-constructor.ConstructorWhitelist, value: "A;B"} \
+// RUN: ]}'
+
+struct A {
+  A() {}
+  A(int x, int y) {}
+
+  explicit A(void *x) {}
+  explicit A(void *x, void *y) {}
+
+  explicit A(const A &a) {}
+  // CHECK-MESSAGES-DEFAULT: :[[@LINE-1]]:12: warning: copy constructor should not be declared explicit [google-explicit-constructor]
+  // CHECK-FIXES-DEFAULT: {{^  }}A(const A &a) {}
+  // WHITELISTED: Warning disabled with ConstructorWhitelist=A
+
+  A(int x1);
+  // CHECK-MESSAGES-DEFAULT: :[[@LINE-1]]:3: warning: single-argument constructors must be marked explicit to avoid unintentional implicit conversions [google-explicit-constructor]
+  // CHECK-FIXES-DEFAULT: {{^  }}explicit A(int x1);
+  // WHITELISTED: Warning disabled with ConstructorWhitelist=A
+
+  A(double x2, double y = 3.14) {}
+  // CHECK-MESSAGES-DEFAULT: :[[@LINE-1]]:3: warning: constructors that are callable with a single argument must be marked explicit to avoid unintentional implicit conversions [google-explicit-constructor]
+  // CHECK-FIXES-DEFAULT: {{^  }}explicit A(double x2, double y = 3.14) {}
+  // WHITELISTED: Warning disabled with ConstructorWhitelist=A
+
+  template 
+  A(T &&...args);
+  // CHECK-MESSAGES-DEFAULT: :[[@LINE-1]]:3: warning: constructors that are callable with a single argument
+  // CHECK-FIXES-DEFAULT: {{^  }}explicit A(T &&...args);
+  // WHITELISTED: Warning disabled with ConstructorWhitelist=A
+};
+
+inline A::A(int x1) {}
+
+struct B {
+  B() {}
+  B(int x, int y) {}
+
+  explicit B(void *x) {}
+  explicit B(void *x, void *y) {}
+
+  explicit B(const B &b) {}
+  // CHECK-MESSAGES-DEFAULT: :[[@LINE-1]]:12: warning: copy constructor should not be declared explicit [google-explicit-constructor]
+  // CHECK-FIXES-DEFAULT: {{^  }}B(const B &b) {}
+  // WHITELISTED: Warning disabled with ConstructorWhitelist=B
+
+  B(int x1);
+  // CHECK-MESSAGES-DEFAULT: :[[@LINE-1]]:3: warning: single-argument constructors must be marked explicit to avoid unintentional implicit conversions [google-explicit-constructor]
+  // CHECK-FIXES-DEFAULT: {{^  }}explicit B(int x1);
+  // WHITELISTED: Warning disabled with ConstructorWhitelist=B
+
+  B(double x2, double y = 3.14) {}
+  // CHECK-MESSAGES-DEFAULT: :[[@LINE-1]]:3: warning: constructors that are callable with a single argument must be marked explicit to avoid unintentional implicit conversions [google-explicit-constructor]
+  // CHECK-FIXES-DEFAULT: {{^  }}explicit B(double x2, double y = 3.14) {}
+  // WHITELISTED: Warning disabled with ConstructorWhitelist=B
+
+  template 
+  B(T &&...args);
+  // CHECK-MESSAGES-DEFAULT: :[[@LINE-1]]:3: warning: constructors that are callable with a single argument
+  // CHECK-FIXES-DEFAULT: {{^  }}explicit B(T &&...args);
+  // WHITELISTED: Warning disabled with ConstructorWhitelist=B
+};
+
+struct C {
+  C() {}
+  C(int x, int y) {}
+
+  explicit C(void *x) {}
+  explicit C(void *x, void *y) {}
+
+  explicit C(const C &c) {}
+  // CHECK-MESSAGES-DEFAULT: :[[@LINE-1]]:12: warning: copy constructor should not be declared explicit [google-explicit-constructor]
+  // CHECK-MESSAGES-WHITELISTED: :[[@LINE-2]]:12: warning: copy constructor should not be declared explicit [google-explicit-constructor]
+  // CHECK-FIXES: {{^  }}C(const C &c) {}
+
+  C(int x1);
+  // CHECK-MESSAGES-DEFAULT: :[[@LINE-1]]:3: warning: single-argument constructors must be marked explicit to avoid unintentional 

[PATCH] D102791: [WebAssembly] Warn on exception spec for Emscripten EH

2021-05-20 Thread Heejin Ahn via Phabricator via cfe-commits
aheejin added a comment.

In D102791#2769892 , @dschuff wrote:

> BTW Is there a way to disable this warning?

The warning is like

  test.cpp:3:6: warning: dynamic exception specifications with types are 
currently ignored in wasm [-Wwasm-exception-spec]

So `-Wno-wasm-exception-spec` will disable the warning.

> Since IIUC this could cause code that was not warning (because it used 
> -fno-exceptions or used emscripten's default of -fignore-exceptions) to now 
> start warning, sometimes that makes users who use -Werror unhappy.

`-fno-exceptions` does not print this warning. `-fignore-exceptions` does. 
There is a way to disable this as I said above, but if this makes existing 
users unhappy, I can abandon this patch. It was just to give users a hint that 
this feature they are using is in fact not working.




Comment at: clang/lib/CodeGen/CGException.cpp:495
+CGM.getLangOpts().getExceptionHandling() ==
+LangOptions::ExceptionHandlingKind::None &&
+EST == EST_Dynamic)

dschuff wrote:
> Does emscripten's default of `-fignore-exceptions` also end up as haveing 
> `ExceptionHandlingKind::None` even though exceptions aren't disabled?
Yes. This `ExceptionHandlingKind` has nothing to do with whether it is enabled 
or disabled. It is defined here: 
https://github.com/llvm/llvm-project/blob/a647100b4320923b0e9d156cc3872b3be470ad98/clang/include/clang/Basic/LangOptions.h#L233-L234

This is the clang counterpart to `-exception-model` in LLVM backend. If we 
don't use `-fwasm-exceptions`, `ExceptionHandlingKind` will be `None` whether 
Emscripten EH is enabled or not.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102791

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


[PATCH] D102822: [Clang][CodeGen] Set the size of llvm.lifetime to unknown for scalable types.

2021-05-20 Thread Hsiangkai Wang via Phabricator via cfe-commits
HsiangKai updated this revision to Diff 346656.
HsiangKai added a comment.

Update the test case.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102822

Files:
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CGDecl.cpp
  clang/lib/CodeGen/CGExprAgg.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/test/CodeGen/RISCV/riscv-v-lifetime.cpp

Index: clang/test/CodeGen/RISCV/riscv-v-lifetime.cpp
===
--- /dev/null
+++ clang/test/CodeGen/RISCV/riscv-v-lifetime.cpp
@@ -0,0 +1,30 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// REQUIRES: riscv-registered-target
+// RUN: %clang_cc1 -std=c++11 -triple riscv64 -target-feature +experimental-v \
+// RUN:   -emit-llvm -O1 -o - %s | FileCheck %s
+
+#include 
+
+template 
+void Foo(T &&);
+
+template 
+T Baz();
+
+// CHECK-LABEL: @_Z4Testv(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[REF_TMP:%.*]] = alloca , align 8
+// CHECK-NEXT:[[TMP0:%.*]] = bitcast * [[REF_TMP]] to i8*
+// CHECK-NEXT:call void @llvm.lifetime.start.p0i8(i64 -1, i8* nonnull [[TMP0]]) #[[ATTR3:[0-9]+]]
+// CHECK-NEXT:[[CALL:%.*]] = call  @_Z3BazIu15__rvv_int32m1_tET_v() #[[ATTR3]]
+// CHECK-NEXT:store  [[CALL]], * [[REF_TMP]], align 8, !tbaa [[TBAA4:![0-9]+]]
+// CHECK-NEXT:call void @_Z3FooIRKu15__rvv_int32m1_tEvOT_(* nonnull align 4 [[REF_TMP]]) #[[ATTR3]]
+// CHECK-NEXT:[[TMP1:%.*]] = load , * [[REF_TMP]], align 8, !tbaa [[TBAA4]]
+// CHECK-NEXT:call void @llvm.lifetime.end.p0i8(i64 -1, i8* nonnull [[TMP0]]) #[[ATTR3]]
+// CHECK-NEXT:ret  [[TMP1]]
+//
+vint32m1_t Test() {
+  const vint32m1_t &a = Baz();
+  Foo(a);
+  return a;
+}
Index: clang/lib/CodeGen/CodeGenFunction.h
===
--- clang/lib/CodeGen/CodeGenFunction.h
+++ clang/lib/CodeGen/CodeGenFunction.h
@@ -2872,7 +2872,7 @@
   void EmitSehTryScopeBegin();
   void EmitSehTryScopeEnd();
 
-  llvm::Value *EmitLifetimeStart(uint64_t Size, llvm::Value *Addr);
+  llvm::Value *EmitLifetimeStart(llvm::TypeSize Size, llvm::Value *Addr);
   void EmitLifetimeEnd(llvm::Value *Size, llvm::Value *Addr);
 
   llvm::Value *EmitCXXNewExpr(const CXXNewExpr *E);
Index: clang/lib/CodeGen/CGExprAgg.cpp
===
--- clang/lib/CodeGen/CGExprAgg.cpp
+++ clang/lib/CodeGen/CGExprAgg.cpp
@@ -276,7 +276,7 @@
 RetAddr = Dest.getAddress();
   } else {
 RetAddr = CGF.CreateMemTemp(RetTy, "tmp", &RetAllocaAddr);
-uint64_t Size =
+llvm::TypeSize Size =
 CGF.CGM.getDataLayout().getTypeAllocSize(CGF.ConvertTypeForMem(RetTy));
 LifetimeSizePtr = CGF.EmitLifetimeStart(Size, RetAllocaAddr.getPointer());
 if (LifetimeSizePtr) {
Index: clang/lib/CodeGen/CGDecl.cpp
===
--- clang/lib/CodeGen/CGDecl.cpp
+++ clang/lib/CodeGen/CGDecl.cpp
@@ -1317,11 +1317,15 @@
 /// Emit a lifetime.begin marker if some criteria are satisfied.
 /// \return a pointer to the temporary size Value if a marker was emitted, null
 /// otherwise
-llvm::Value *CodeGenFunction::EmitLifetimeStart(uint64_t Size,
+llvm::Value *CodeGenFunction::EmitLifetimeStart(llvm::TypeSize Size,
 llvm::Value *Addr) {
   if (!ShouldEmitLifetimeMarkers)
 return nullptr;
 
+  // Use -1 as the unknown size.
+  if (Size.isScalable())
+Size = llvm::TypeSize::Fixed(-1);
+
   assert(Addr->getType()->getPointerAddressSpace() ==
  CGM.getDataLayout().getAllocaAddrSpace() &&
  "Pointer should be in alloca address space");
@@ -1551,9 +1555,7 @@
   llvm::TypeSize size =
   CGM.getDataLayout().getTypeAllocSize(allocaTy);
   emission.SizeForLifetimeMarkers =
-  size.isScalable() ? EmitLifetimeStart(-1, AllocaAddr.getPointer())
-: EmitLifetimeStart(size.getFixedSize(),
-AllocaAddr.getPointer());
+  EmitLifetimeStart(size, AllocaAddr.getPointer());
 }
   } else {
 assert(!emission.useLifetimeMarkers());
Index: clang/lib/CodeGen/CGCall.cpp
===
--- clang/lib/CodeGen/CGCall.cpp
+++ clang/lib/CodeGen/CGCall.cpp
@@ -4679,7 +4679,7 @@
 } else {
   SRetPtr = CreateMemTemp(RetTy, "tmp", &SRetAlloca);
   if (HaveInsertPoint() && ReturnValue.isUnused()) {
-uint64_t size =
+llvm::TypeSize size =
 CGM.getDataLayout().getTypeAllocSize(ConvertTypeForMem(RetTy));
 UnusedReturnSizePtr = EmitLifetimeStart(size, SRetAlloca.getPointer());
   }
@@ -4840,7 +4840,7 @@
   IRCallArgs[FirstIRArg] = AI.getPointer();
 
   // Emit lifetime markers for the temporary alloca.
-  uint64_

[PATCH] D102760: [llvm] Let SmallVector construct from any Iterable

2021-05-20 Thread Guillaume Chatelet via Phabricator via cfe-commits
gchatelet updated this revision to Diff 346657.
gchatelet added a comment.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

- Remove dependency on iterable_range header
- Simplified implementation, added tests


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102760

Files:
  clang/include/clang/Basic/Module.h
  llvm/include/llvm/ADT/IterableTraits.h
  llvm/include/llvm/ADT/SmallVector.h
  llvm/tools/llvm-xray/xray-converter.cpp
  llvm/unittests/ADT/CMakeLists.txt
  llvm/unittests/ADT/IterableTraitsTest.cpp
  llvm/unittests/ADT/SmallVectorTest.cpp

Index: llvm/unittests/ADT/SmallVectorTest.cpp
===
--- llvm/unittests/ADT/SmallVectorTest.cpp
+++ llvm/unittests/ADT/SmallVectorTest.cpp
@@ -226,6 +226,22 @@
   this->assertValuesInOrder(this->theVector, 3u, 1, 2, 3);
 }
 
+// Constructor test.
+TYPED_TEST(SmallVectorTest, ConstructorIterableCArrayTest) {
+  SCOPED_TRACE("ConstructorTest");
+  int arr[] = {1, 2, 3};
+  this->theVector = SmallVector(arr);
+  this->assertValuesInOrder(this->theVector, 3u, 1, 2, 3);
+}
+
+// Constructor test.
+TYPED_TEST(SmallVectorTest, ConstructorIterableVectorTest) {
+  SCOPED_TRACE("ConstructorTest");
+  std::vector vec = {1, 2, 3};
+  this->theVector = SmallVector(vec);
+  this->assertValuesInOrder(this->theVector, 3u, 1, 2, 3);
+}
+
 // New vector test.
 TYPED_TEST(SmallVectorTest, EmptyVectorTest) {
   SCOPED_TRACE("EmptyVectorTest");
Index: llvm/unittests/ADT/IterableTraitsTest.cpp
===
--- /dev/null
+++ llvm/unittests/ADT/IterableTraitsTest.cpp
@@ -0,0 +1,62 @@
+//===- IterableTraitsTest.cpp - Unit tests for is_range_iterable --===//
+//
+// 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 "llvm/ADT/IterableTraits.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/iterator_range.h"
+#include "gtest/gtest.h"
+#include 
+#include 
+#include 
+
+namespace llvm {
+
+class ForwardDeclared;
+
+TEST(IteratorRangeTest, IsForwardIterator) {
+  EXPECT_FALSE(is_forward_iterator::value);
+  EXPECT_TRUE(is_forward_iterator::value);
+  EXPECT_TRUE(is_forward_iterator::value);
+  EXPECT_TRUE(is_forward_iterator::value);
+  using ForwardList = std::forward_list;
+  EXPECT_TRUE(is_forward_iterator::value);
+  EXPECT_TRUE(is_forward_iterator::value);
+}
+
+TEST(IteratorRangeTest, IsIterableCArray) {
+  int Data[4];
+  EXPECT_TRUE(
+  is_range_iterable>::value);
+}
+
+TEST(IteratorRangeTest, IsIterableVector) {
+  using Vector = std::vector;
+  EXPECT_TRUE(is_range_iterable::value);
+}
+
+TEST(IteratorRangeTest, IsIterableArray) {
+  using Array = std::array;
+  EXPECT_TRUE(is_range_iterable::value);
+}
+
+TEST(IteratorRangeTest, IsIterableSmallVector) {
+  using SVector = SmallVector;
+  EXPECT_TRUE(is_range_iterable::value);
+}
+
+TEST(IteratorRangeTest, IsIterableRange) {
+  using Range = iterator_range;
+  EXPECT_TRUE(is_range_iterable::value);
+}
+
+TEST(IteratorRangeTest, NonIterableTypes) {
+  EXPECT_FALSE(is_range_iterable::value);
+  EXPECT_FALSE(is_range_iterable::value);
+}
+
+} // namespace llvm
Index: llvm/unittests/ADT/CMakeLists.txt
===
--- llvm/unittests/ADT/CMakeLists.txt
+++ llvm/unittests/ADT/CMakeLists.txt
@@ -41,6 +41,7 @@
   IntEqClassesTest.cpp
   IntervalMapTest.cpp
   IntrusiveRefCntPtrTest.cpp
+  IterableTraitsTest.cpp
   IteratorTest.cpp
   MappedIteratorTest.cpp
   MapVectorTest.cpp
Index: llvm/tools/llvm-xray/xray-converter.cpp
===
--- llvm/tools/llvm-xray/xray-converter.cpp
+++ llvm/tools/llvm-xray/xray-converter.cpp
@@ -158,6 +158,8 @@
 // A structure that allows building a dictionary of stack ids for the Chrome
 // trace event format.
 struct StackIdData {
+  StackIdData(const StackIdData &) = default;
+
   // Each Stack of function calls has a unique ID.
   unsigned id;
 
Index: llvm/include/llvm/ADT/SmallVector.h
===
--- llvm/include/llvm/ADT/SmallVector.h
+++ llvm/include/llvm/ADT/SmallVector.h
@@ -13,7 +13,7 @@
 #ifndef LLVM_ADT_SMALLVECTOR_H
 #define LLVM_ADT_SMALLVECTOR_H
 
-#include "llvm/ADT/iterator_range.h"
+#include "llvm/ADT/IterableTraits.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/MathExtras.h"
@@ -1188,10 +1188,12 @@
 this->append(S, E);
   }
 
-  template 
-  explicit SmallVector(const iterator_range &R)
+  template 
+  explicit SmallVector(
+  Iterable &&R,
+  std::enable_if_t::value, bool> = 

[PATCH] D102443: [PowerPC] Added multiple PowerPC builtins

2021-05-20 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

If these builtins are generally supposed to be accessed through a 
compiler-provided header, you could make that header define these functions 
using underlying builtins that have a `__builtin` prefix.  That's not 
completely necessary, though; we do support some other non-library builtins 
that lack the `__builtin` prefix.  And it sounds like maybe there isn't such a 
header anyway.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102443

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


[PATCH] D97183: [analyzer] Add NoteTag for smart-ptr get()

2021-05-20 Thread Valeriy Savchenko via Phabricator via cfe-commits
vsavchenko added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/SmartPtr.h:36
+
+class FindWhereConstrained : public BugReporterVisitor {
+private:

nit: class name should be a noun (functions and methods are verbs)



Comment at: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp:84
 REGISTER_MAP_WITH_PROGRAMSTATE(TrackedRegionMap, const MemRegion *, SVal)
+// REGISTER_SET_WITH_PROGRAMSTATE(ExprsFromGet, const Stmt *)
+REGISTER_MAP_WITH_PROGRAMSTATE(ExprsFromGet, const MemRegion *,

Probably forgotten



Comment at: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp:136-139
+if (StmtsCovered.contains(S)) {
+  return nullptr;
+}
+StmtsCovered.insert(S);

We probably should have a checker in clang-tidy (maybe we already do), for 
situations like this.
C++ has a long-lasting tradition that set's/map's `insert` return a pair: 
iterator + bool. The second part tells the user if the `insert` operation 
actually added the new element or it was already there.
This allows us to do 1 search instead of two.



Comment at: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp:141-163
+auto bugReportOnGet = [&](const Expr *E) -> auto {
+  if (const auto *MCE = llvm::dyn_cast(E)) {
+const auto *Method = MCE->getMethodDecl();
+const auto *Record = MCE->getRecordDecl();
+if (Method->getName() == "get" &&
+Record->getDeclContext()->isStdNamespace() &&
+Record->getName() == "unique_ptr") {

Is there any reason it's not a method of `FindWhereConstrained`?



Comment at: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp:165
+
+// If statement on raw pointer
+if (const auto *E = llvm::dyn_cast(S)) {

After that you have 3 distinct cases to handle. It's a good opportunity for 
extracting them into separate functions.



Comment at: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp:179-180
+  // P.get()
+  if (const auto *InnerCastExpr =
+  llvm::dyn_cast(Sub)) {
+Sub = InnerCastExpr->getSubExpr();

I think it's better to `IgnoreParensAndCasts` instead of manual traversal.



Comment at: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp:216
+// If b is a get() expression, then we can return a note
+auto report = bugReportOnGet(RHS);
+if (report) {

Variables are capitalized.



Comment at: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp:217
+auto report = bugReportOnGet(RHS);
+if (report) {
+  return report;

It is a widespread pattern in LLVM to declare such variables directly in `if` 
statements:
```
if (auto Report = bugReportOnGet(RHS))
  return Report;
```



Comment at: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp:227
+if (const auto *DS = llvm::dyn_cast(S)) {
+  const Decl *D = DS->getSingleDecl();
+  if (const auto *VD = llvm::dyn_cast(D)) {

So, situations like `int *a = nullptr, *b = smart.get();` are not supported?



Comment at: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp:229
+  if (const auto *VD = llvm::dyn_cast(D)) {
+for (const auto *I : PtrsTrackedAndConstrained) {
+  if (I->getName() == VD->getName()) {

`llvm::find_if`



Comment at: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp:238-245
+}
+  }
+}
+  }
+}
+  }
+}

This level of nestedness is frowned upon. It is a good tell that the function 
should be refactored.
The following code:
```
if (cond1) {
  . . .
  if (cond2) {
. . .
if (cond3) {
  . . .
}
  }
}
return nullptr;
```
can be refactored into:
```
if (!cond1)
  return nullptr;

. . .
if (!cond2)
  return nullptr;

. . .
if (!cond3)
  return nullptr;

. . .
```

It is easier to follow the logic if the function is composed in this manner 
because from the very beginning you know that `else` with more stuff is not 
going to follow.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97183

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


[PATCH] D102812: [clang] Don't pass multiple backend options if mixing -mimplicit-it and -Wa,-mimplicit-it

2021-05-20 Thread David Spickett via Phabricator via cfe-commits
DavidSpickett added a comment.

> If multiple instances of the -arm-implicit-it option is passed to
> the backend, it errors out.

Does it make sense to fix that side too?

Seems like we have a few options to handle this on clang's side:

1. Last of `-mimplicit-it` and `-Wa,-mimplicit-it` wins
2. If they're the same, accept it, if they mismatch, error
3. Take the (last) one that matches the current input type

There is some precedent for number 3 in 
1d51c699b9e2ebc5bcfdbe85c74cc871426333d4 
. Quoting 
from the commit msg:

  Now the same rules will apply to -Wa,-march/-mcpu as would
  if you just passed them to the compiler:
  * -Wa/-Xassembler options only apply to assembly files.
  * Architecture derived from mcpu beats any march options.
  * When there are multiple mcpu or multiple march, the last
one wins.
  * If there is a compiler option and an assembler option of
the same type, we prefer the one that fits the input type.
  * If there is an applicable mcpu option but it is overruled
by an march, the cpu value is still used for the "-target-cpu"
cc1 option.

I'm not up on all the background to this change so perhaps doing number 3 is 
going to break existing use cases.




Comment at: clang/lib/Driver/ToolChains/Clang.cpp:2584
   }
+  if (!ImplicitItCompiler.empty() && !ImplicitItAsm.empty()) {
+// Set both via compiler flag and asm flag; ok if they match.

```
if (ImplicitItCompiler.size() && ImplicitItAsm.size()) {
```



Comment at: clang/test/Driver/arm-target-as-mimplicit-it.s:39
 // ALWAYS: "-mllvm" "-arm-implicit-it=always"
+// ALWAYS-NOT: "-arm-implicit-it={{.*}}"
 // NEVER: "-mllvm" "-arm-implicit-it=never"

mstorsjo wrote:
> This pattern wouldn't detct if there's e.g. `-arm-implicit-it=never 
> -arm-implicit-it=always`, but I added test cases that pass 
> `-Wa,-mimplicit-it=always` twice, where this check should be able to verify 
> that we only output it once.
Could you do:
```
// ALWAYS-NOT: "-mllvm" "-arm-implicit-it=never"
// ALWAYS: "-mllvm" "-arm-implicit-it=always"
```

Not sure if doing the NOT moves the check forward to beyond where the always 
would be.



Comment at: clang/test/Driver/arm-target-as-mimplicit-it.s:44
 // THUMB: "-mllvm" "-arm-implicit-it=thumb"
-// NEVER_ALWAYS: "-mllvm" "-arm-implicit-it=never" "-mllvm" 
"-arm-implicit-it=always"
-// ALWAYS_NEVER: "-mllvm" "-arm-implicit-it=always" "-mllvm" 
"-arm-implicit-it=never"
+// MISMATCH: error: unsupported argument '{{.*}}' to option '-mimplicit-it'
 // INVALID: error: unsupported argument '-mimplicit-it=foo' to option 'Wa,'

Can you do this check without the regex?

Reading it as is this doesn't look like a very helpful error. I'd expect 
something like:
```
error: mismatched values for implicit-it "thumb" and "arm"
```



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102812

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


[PATCH] D102706: [clang-format] Add new LambdaBodyIndentation option

2021-05-20 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks added a comment.

In D102706#2766871 , @vlovich wrote:

> In D102706#2766680 , 
> @HazardyKnusperkeks wrote:
>
>> Maybe a bit more test cases with smaller lambdas? Or without the outer 
>> parenthesis?
>
> I'm not sure I understand this comment. Which test case are you referring to 
> by "or without the outer parenthesis"?



  verifyFormat("test() {\n"
 "  ([]() -> {\n"
 "int b = 32;\n"
 "return 3;\n"
 "  }).foo();\n"
 "}",
 Style);

There you have parenthesis around the lambda, how about without?
Maybe just something like

  std::sort(v.begin(), v.end(), [](const auto& lhs, const auto& rhs) { return 
lhs.Foo < rhs.Foo; });


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102706

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


[PATCH] D102730: [clang-format] Support custom If macros

2021-05-20 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks added a comment.

Looks good, but please add a test with the `else IF` and just `else` case.

Also for me it would be ok to add your `KJ_IF_MAYBE` to the default 
configuration. But I have no experience on that.




Comment at: clang/include/clang/Format/Format.h:2098
+  ///
+  /// For example: KJ_IF_MAYBE.
+  std::vector IfMacros;

vlovich wrote:
> Should I put a hyperlink to 
> https://github.com/capnproto/capnproto/blob/master/kjdoc/tour.md#maybes?
Maybe. *scnr*


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102730

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


[PATCH] D102760: [llvm] Let SmallVector construct from any Iterable

2021-05-20 Thread Guillaume Chatelet via Phabricator via cfe-commits
gchatelet updated this revision to Diff 346669.
gchatelet added a comment.

- Forward argument


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102760

Files:
  clang/include/clang/Basic/Module.h
  llvm/include/llvm/ADT/IterableTraits.h
  llvm/include/llvm/ADT/SmallVector.h
  llvm/tools/llvm-xray/xray-converter.cpp
  llvm/unittests/ADT/CMakeLists.txt
  llvm/unittests/ADT/IterableTraitsTest.cpp
  llvm/unittests/ADT/SmallVectorTest.cpp

Index: llvm/unittests/ADT/SmallVectorTest.cpp
===
--- llvm/unittests/ADT/SmallVectorTest.cpp
+++ llvm/unittests/ADT/SmallVectorTest.cpp
@@ -226,6 +226,22 @@
   this->assertValuesInOrder(this->theVector, 3u, 1, 2, 3);
 }
 
+// Constructor test.
+TYPED_TEST(SmallVectorTest, ConstructorIterableCArrayTest) {
+  SCOPED_TRACE("ConstructorTest");
+  int arr[] = {1, 2, 3};
+  this->theVector = SmallVector(arr);
+  this->assertValuesInOrder(this->theVector, 3u, 1, 2, 3);
+}
+
+// Constructor test.
+TYPED_TEST(SmallVectorTest, ConstructorIterableVectorTest) {
+  SCOPED_TRACE("ConstructorTest");
+  std::vector vec = {1, 2, 3};
+  this->theVector = SmallVector(vec);
+  this->assertValuesInOrder(this->theVector, 3u, 1, 2, 3);
+}
+
 // New vector test.
 TYPED_TEST(SmallVectorTest, EmptyVectorTest) {
   SCOPED_TRACE("EmptyVectorTest");
Index: llvm/unittests/ADT/IterableTraitsTest.cpp
===
--- /dev/null
+++ llvm/unittests/ADT/IterableTraitsTest.cpp
@@ -0,0 +1,62 @@
+//===- IterableTraitsTest.cpp - Unit tests for is_range_iterable --===//
+//
+// 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 "llvm/ADT/IterableTraits.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/iterator_range.h"
+#include "gtest/gtest.h"
+#include 
+#include 
+#include 
+
+namespace llvm {
+
+class ForwardDeclared;
+
+TEST(IteratorRangeTest, IsForwardIterator) {
+  EXPECT_FALSE(is_forward_iterator::value);
+  EXPECT_TRUE(is_forward_iterator::value);
+  EXPECT_TRUE(is_forward_iterator::value);
+  EXPECT_TRUE(is_forward_iterator::value);
+  using ForwardList = std::forward_list;
+  EXPECT_TRUE(is_forward_iterator::value);
+  EXPECT_TRUE(is_forward_iterator::value);
+}
+
+TEST(IteratorRangeTest, IsIterableCArray) {
+  int Data[4];
+  EXPECT_TRUE(
+  is_range_iterable>::value);
+}
+
+TEST(IteratorRangeTest, IsIterableVector) {
+  using Vector = std::vector;
+  EXPECT_TRUE(is_range_iterable::value);
+}
+
+TEST(IteratorRangeTest, IsIterableArray) {
+  using Array = std::array;
+  EXPECT_TRUE(is_range_iterable::value);
+}
+
+TEST(IteratorRangeTest, IsIterableSmallVector) {
+  using SVector = SmallVector;
+  EXPECT_TRUE(is_range_iterable::value);
+}
+
+TEST(IteratorRangeTest, IsIterableRange) {
+  using Range = iterator_range;
+  EXPECT_TRUE(is_range_iterable::value);
+}
+
+TEST(IteratorRangeTest, NonIterableTypes) {
+  EXPECT_FALSE(is_range_iterable::value);
+  EXPECT_FALSE(is_range_iterable::value);
+}
+
+} // namespace llvm
Index: llvm/unittests/ADT/CMakeLists.txt
===
--- llvm/unittests/ADT/CMakeLists.txt
+++ llvm/unittests/ADT/CMakeLists.txt
@@ -41,6 +41,7 @@
   IntEqClassesTest.cpp
   IntervalMapTest.cpp
   IntrusiveRefCntPtrTest.cpp
+  IterableTraitsTest.cpp
   IteratorTest.cpp
   MappedIteratorTest.cpp
   MapVectorTest.cpp
Index: llvm/tools/llvm-xray/xray-converter.cpp
===
--- llvm/tools/llvm-xray/xray-converter.cpp
+++ llvm/tools/llvm-xray/xray-converter.cpp
@@ -158,6 +158,8 @@
 // A structure that allows building a dictionary of stack ids for the Chrome
 // trace event format.
 struct StackIdData {
+  StackIdData(const StackIdData &) = default;
+
   // Each Stack of function calls has a unique ID.
   unsigned id;
 
Index: llvm/include/llvm/ADT/SmallVector.h
===
--- llvm/include/llvm/ADT/SmallVector.h
+++ llvm/include/llvm/ADT/SmallVector.h
@@ -13,7 +13,7 @@
 #ifndef LLVM_ADT_SMALLVECTOR_H
 #define LLVM_ADT_SMALLVECTOR_H
 
-#include "llvm/ADT/iterator_range.h"
+#include "llvm/ADT/IterableTraits.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/MathExtras.h"
@@ -1188,10 +1188,13 @@
 this->append(S, E);
   }
 
-  template 
-  explicit SmallVector(const iterator_range &R)
+  template 
+  explicit SmallVector(
+  Iterable &&Range,
+  std::enable_if_t::value, bool> = true)
   : SmallVectorImpl(N) {
-this->append(R.begin(), R.end());
+this->append(std::begin(std::forward(Range)),
+   

[PATCH] D102835: [analyzer] Correctly propagate ConstructionContextLayer thru ParenExpr

2021-05-20 Thread Tomasz Kamiński via Phabricator via cfe-commits
tomasz-kaminski-sonarsource created this revision.
tomasz-kaminski-sonarsource added a reviewer: dcoughlin.
Herald added subscribers: manas, steakhal, ASDenysPetrov, dkrupp, donat.nagy, 
Szelethus, mikhail.ramalho, a.sidorin, szepet, baloghadamsoftware, xazax.hun.
tomasz-kaminski-sonarsource requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Previously, information about ConstructionContextLayer was not propagated thru 
causing the expression like:
Var c = (createVar());
To produce unrelated temporary for the createVar() result and conjure new 
symbol for value of c in C++17 mode.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D102835

Files:
  clang/lib/Analysis/CFG.cpp
  clang/test/Analysis/NewDelete-checker-test.cpp


Index: clang/test/Analysis/NewDelete-checker-test.cpp
===
--- clang/test/Analysis/NewDelete-checker-test.cpp
+++ clang/test/Analysis/NewDelete-checker-test.cpp
@@ -26,6 +26,35 @@
 // RUN:   -verify=expected,leak \
 // RUN:   -analyzer-checker=core \
 // RUN:   -analyzer-checker=cplusplus.NewDeleteLeaks
+//
+// RUN: %clang_analyze_cc1 -std=c++17 -fblocks %s \
+// RUN:   -verify=expected,newdelete \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=cplusplus.NewDelete
+//
+// RUN: %clang_analyze_cc1 -DLEAKS -std=c++17 -fblocks %s \
+// RUN:   -verify=expected,newdelete,leak \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=cplusplus.NewDelete \
+// RUN:   -analyzer-checker=cplusplus.NewDeleteLeaks
+//
+// RUN: %clang_analyze_cc1 -std=c++17 -fblocks %s \
+// RUN:   -verify=expected,newdelete \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=cplusplus.NewDelete \
+// RUN:   -analyzer-config c++-allocator-inlining=true
+//
+// RUN: %clang_analyze_cc1 -std=c++17 -fblocks -verify %s \
+// RUN:   -verify=expected,newdelete,leak \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=cplusplus.NewDelete \
+// RUN:   -analyzer-checker=cplusplus.NewDeleteLeaks \
+// RUN:   -analyzer-config c++-allocator-inlining=true
+//
+// RUN: %clang_analyze_cc1 -std=c++17 -fblocks -verify %s \
+// RUN:   -verify=expected,leak \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=cplusplus.NewDeleteLeaks
 
 #include "Inputs/system-header-simulator-cxx.h"
 
@@ -288,7 +317,7 @@
 explicit shared_ptr(T *p) : p(p), control(new control_block) {
   control->retain();
 }
-shared_ptr(shared_ptr &other) : p(other.p), control(other.control) {
+shared_ptr(const shared_ptr &other) : p(other.p), control(other.control) {
   if (control)
   control->retain();
 }
@@ -314,11 +343,26 @@
 }
   };
 
+  template 
+  shared_ptr make_shared(Args &&...args) {
+return shared_ptr(new T(static_cast(args)...));
+  }
+
   void testSingle() {
 shared_ptr a(new int);
 *a = 1;
   }
 
+  void testMake() {
+shared_ptr a = make_shared();
+*a = 1;
+  }
+
+  void testMakeInParens() {
+shared_ptr a = (make_shared());
+*a = 1;
+  }
+
   void testDouble() {
 shared_ptr a(new int);
 shared_ptr b = a;
Index: clang/lib/Analysis/CFG.cpp
===
--- clang/lib/Analysis/CFG.cpp
+++ clang/lib/Analysis/CFG.cpp
@@ -1456,6 +1456,13 @@
 // TODO: Handle other cases. For now, fail to find construction contexts.
 break;
   }
+  case Stmt::ParenExprClass: {
+// If expression is placed into parenthesis we should propagate the parent
+// construction context to subexpressions.
+auto *PE = cast(Child);
+findConstructionContexts(Layer, PE->getSubExpr());
+break;
+  }
   default:
 break;
   }


Index: clang/test/Analysis/NewDelete-checker-test.cpp
===
--- clang/test/Analysis/NewDelete-checker-test.cpp
+++ clang/test/Analysis/NewDelete-checker-test.cpp
@@ -26,6 +26,35 @@
 // RUN:   -verify=expected,leak \
 // RUN:   -analyzer-checker=core \
 // RUN:   -analyzer-checker=cplusplus.NewDeleteLeaks
+//
+// RUN: %clang_analyze_cc1 -std=c++17 -fblocks %s \
+// RUN:   -verify=expected,newdelete \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=cplusplus.NewDelete
+//
+// RUN: %clang_analyze_cc1 -DLEAKS -std=c++17 -fblocks %s \
+// RUN:   -verify=expected,newdelete,leak \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=cplusplus.NewDelete \
+// RUN:   -analyzer-checker=cplusplus.NewDeleteLeaks
+//
+// RUN: %clang_analyze_cc1 -std=c++17 -fblocks %s \
+// RUN:   -verify=expected,newdelete \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=cplusplus.NewDelete \
+// RUN:   -analyzer-config c++-allocator-inlining=true
+//
+// RUN: %clang_analyze_cc1 -std=c++17 -fblocks -verify %s \
+// RUN:   -verify=expected,newdelete,leak \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=cplusplus.NewDe

[PATCH] D102836: [clang] Fix Typo in AST Matcher Reference

2021-05-20 Thread Marco Gartmann via Phabricator via cfe-commits
mgartmann created this revision.
mgartmann added a reviewer: klimek.
mgartmann added a project: clang.
mgartmann requested review of this revision.

In AST Matcher Reference 
, the example of 
matcher `hasDeclContext` contained a typo.

`cxxRcordDecl` was changed to `cxxRecordDecl`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D102836

Files:
  clang/docs/LibASTMatchersReference.html


Index: clang/docs/LibASTMatchersReference.html
===
--- clang/docs/LibASTMatchersReference.html
+++ clang/docs/LibASTMatchersReference.html
@@ -7439,7 +7439,7 @@
 }
   }
 
-cxxRcordDecl(hasDeclContext(namedDecl(hasName("M" matches the
+cxxRecordDecl(hasDeclContext(namedDecl(hasName("M" matches the
 declaration of class D.
 
 


Index: clang/docs/LibASTMatchersReference.html
===
--- clang/docs/LibASTMatchersReference.html
+++ clang/docs/LibASTMatchersReference.html
@@ -7439,7 +7439,7 @@
 }
   }
 
-cxxRcordDecl(hasDeclContext(namedDecl(hasName("M" matches the
+cxxRecordDecl(hasDeclContext(namedDecl(hasName("M" matches the
 declaration of class D.
 
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D102273: [analyzer] LoopUnrolling: fix crash when a loop counter is captured in a lambda by reference

2021-05-20 Thread Abbas Sabra via Phabricator via cfe-commits
AbbasSabra added a comment.
Herald added a subscriber: manas.

In D102273#2766531 , @NoQ wrote:

> I've just been patching up clang-tidy's infinite loop checker and the problem 
> sounds s similar. Maybe we should move clang-tidy's alias analysis into 
> `libAnalysis` and re-use it?

I'm not familiar with clang-tidy's alias analysis. Do you think it should be 
part of this patch? or a follow-up one?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102273

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


[PATCH] D102835: [analyzer] Correctly propagate ConstructionContextLayer thru ParenExpr

2021-05-20 Thread Tomasz Kamiński via Phabricator via cfe-commits
tomasz-kaminski-sonarsource updated this revision to Diff 346683.
tomasz-kaminski-sonarsource added a comment.

Added // no warn comment to line that was raising warning before the fix.


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

https://reviews.llvm.org/D102835

Files:
  clang/lib/Analysis/CFG.cpp
  clang/test/Analysis/NewDelete-checker-test.cpp


Index: clang/test/Analysis/NewDelete-checker-test.cpp
===
--- clang/test/Analysis/NewDelete-checker-test.cpp
+++ clang/test/Analysis/NewDelete-checker-test.cpp
@@ -26,6 +26,35 @@
 // RUN:   -verify=expected,leak \
 // RUN:   -analyzer-checker=core \
 // RUN:   -analyzer-checker=cplusplus.NewDeleteLeaks
+//
+// RUN: %clang_analyze_cc1 -std=c++17 -fblocks %s \
+// RUN:   -verify=expected,newdelete \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=cplusplus.NewDelete
+//
+// RUN: %clang_analyze_cc1 -DLEAKS -std=c++17 -fblocks %s \
+// RUN:   -verify=expected,newdelete,leak \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=cplusplus.NewDelete \
+// RUN:   -analyzer-checker=cplusplus.NewDeleteLeaks
+//
+// RUN: %clang_analyze_cc1 -std=c++17 -fblocks %s \
+// RUN:   -verify=expected,newdelete \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=cplusplus.NewDelete \
+// RUN:   -analyzer-config c++-allocator-inlining=true
+//
+// RUN: %clang_analyze_cc1 -std=c++17 -fblocks -verify %s \
+// RUN:   -verify=expected,newdelete,leak \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=cplusplus.NewDelete \
+// RUN:   -analyzer-checker=cplusplus.NewDeleteLeaks \
+// RUN:   -analyzer-config c++-allocator-inlining=true
+//
+// RUN: %clang_analyze_cc1 -std=c++17 -fblocks -verify %s \
+// RUN:   -verify=expected,leak \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=cplusplus.NewDeleteLeaks
 
 #include "Inputs/system-header-simulator-cxx.h"
 
@@ -288,7 +317,7 @@
 explicit shared_ptr(T *p) : p(p), control(new control_block) {
   control->retain();
 }
-shared_ptr(shared_ptr &other) : p(other.p), control(other.control) {
+shared_ptr(const shared_ptr &other) : p(other.p), control(other.control) {
   if (control)
   control->retain();
 }
@@ -314,11 +343,26 @@
 }
   };
 
+  template 
+  shared_ptr make_shared(Args &&...args) {
+return shared_ptr(new T(static_cast(args)...));
+  }
+
   void testSingle() {
 shared_ptr a(new int);
 *a = 1;
   }
 
+  void testMake() {
+shared_ptr a = make_shared();
+*a = 1;
+  }
+
+  void testMakeInParens() {
+shared_ptr a = (make_shared()); // no warn
+*a = 1;
+  }
+
   void testDouble() {
 shared_ptr a(new int);
 shared_ptr b = a;
Index: clang/lib/Analysis/CFG.cpp
===
--- clang/lib/Analysis/CFG.cpp
+++ clang/lib/Analysis/CFG.cpp
@@ -1456,6 +1456,13 @@
 // TODO: Handle other cases. For now, fail to find construction contexts.
 break;
   }
+  case Stmt::ParenExprClass: {
+// If expression is placed into parenthesis we should propagate the parent
+// construction context to subexpressions.
+auto *PE = cast(Child);
+findConstructionContexts(Layer, PE->getSubExpr());
+break;
+  }
   default:
 break;
   }


Index: clang/test/Analysis/NewDelete-checker-test.cpp
===
--- clang/test/Analysis/NewDelete-checker-test.cpp
+++ clang/test/Analysis/NewDelete-checker-test.cpp
@@ -26,6 +26,35 @@
 // RUN:   -verify=expected,leak \
 // RUN:   -analyzer-checker=core \
 // RUN:   -analyzer-checker=cplusplus.NewDeleteLeaks
+//
+// RUN: %clang_analyze_cc1 -std=c++17 -fblocks %s \
+// RUN:   -verify=expected,newdelete \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=cplusplus.NewDelete
+//
+// RUN: %clang_analyze_cc1 -DLEAKS -std=c++17 -fblocks %s \
+// RUN:   -verify=expected,newdelete,leak \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=cplusplus.NewDelete \
+// RUN:   -analyzer-checker=cplusplus.NewDeleteLeaks
+//
+// RUN: %clang_analyze_cc1 -std=c++17 -fblocks %s \
+// RUN:   -verify=expected,newdelete \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=cplusplus.NewDelete \
+// RUN:   -analyzer-config c++-allocator-inlining=true
+//
+// RUN: %clang_analyze_cc1 -std=c++17 -fblocks -verify %s \
+// RUN:   -verify=expected,newdelete,leak \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=cplusplus.NewDelete \
+// RUN:   -analyzer-checker=cplusplus.NewDeleteLeaks \
+// RUN:   -analyzer-config c++-allocator-inlining=true
+//
+// RUN: %clang_analyze_cc1 -std=c++17 -fblocks -verify %s \
+// RUN:   -verify=expected,leak \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=cplusplus.NewDeleteLeaks
 
 #include "Inputs/system-header-simulator-cxx.h"
 
@@ -288,7 +317,7 @@
 explicit shared_ptr(T *p) : p(p)

[PATCH] D93565: scan-view: Remove Reporter.py and associated AppleScript files

2021-05-20 Thread Ben Jackson via Phabricator via cfe-commits
puremourning added a comment.

Unless i'm missing something, this change seems to have broken scan-view, as it 
now just says

"ModuleNotFOundError: No module named 'Reporter'"

Due to :

`import Reporter` in `ScanView.py`

Am i losing my mind?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D93565

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


[PATCH] D93565: scan-view: Remove Reporter.py and associated AppleScript files

2021-05-20 Thread Ben Jackson via Phabricator via cfe-commits
puremourning added a comment.

In D93565#2770709 , @puremourning 
wrote:

> Unless i'm missing something, this change seems to have broken scan-view, as 
> it now just says
>
> "ModuleNotFOundError: No module named 'Reporter'"
>
> Due to :
>
> `import Reporter` in `ScanView.py`
>
> Am i losing my mind?

This seems to fix it:

  index 5a5d15e85b30..4eccb9958a05 100644
  --- a/clang/tools/scan-view/share/ScanView.py
  +++ b/clang/tools/scan-view/share/ScanView.py
  @@ -26,7 +26,6 @@ import time
   import socket
   import itertools
  
  -import Reporter
   try:
   import configparser
   except ImportError:
  Stage this hunk [y,n,q,a,d,j,J,g,/,e,?]? y
  @@ -775,9 +774,7 @@ File Bug
  
  
   def create_server(address, options, root):
  -import Reporter
  -
  -reporters = Reporter.getReporters()
  +reporters = []
  
   return ScanViewServer(address, ScanViewRequestHandler,
 root,


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D93565

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


[PATCH] D102760: [llvm] Let SmallVector construct from any Iterable

2021-05-20 Thread Florian Hahn via Phabricator via cfe-commits
fhahn added inline comments.



Comment at: clang/include/clang/Basic/Module.h:98
 public:
+  Module(const Module &) = default;
+

how is this related?



Comment at: llvm/tools/llvm-xray/xray-converter.cpp:161
 struct StackIdData {
+  StackIdData(const StackIdData &) = default;
+

how is this related?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102760

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


[clang] 7defab0 - Reapply "[clang][deps] Support inferred modules"

2021-05-20 Thread Jan Svoboda via cfe-commits

Author: Michael Spencer
Date: 2021-05-20T12:41:52+02:00
New Revision: 7defab082070adf3d04b326ba160b029394edc7c

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

LOG: Reapply "[clang][deps] Support inferred modules"

This reverts commit 76b8754d and ensures the PCM files are created in the 
correct directory (not in the current working directory).

Added: 

clang/test/ClangScanDeps/Inputs/frameworks/Inferred.framework/Frameworks/Sub.framework/Headers/Sub.h

clang/test/ClangScanDeps/Inputs/frameworks/Inferred.framework/Headers/Inferred.h
clang/test/ClangScanDeps/Inputs/frameworks/System.framework/Headers/System.h

clang/test/ClangScanDeps/Inputs/frameworks/System.framework/Modules/module.modulemap
clang/test/ClangScanDeps/Inputs/frameworks/module.modulemap
clang/test/ClangScanDeps/Inputs/modules_inferred_cdb.json
clang/test/ClangScanDeps/modules-inferred-explicit-build.m
clang/test/ClangScanDeps/modules-inferred.m
clang/utils/module-deps-to-rsp.py

Modified: 
clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
clang/test/ClangScanDeps/modules-full.cpp

Removed: 




diff  --git a/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp 
b/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
index 51b7fc48628c1..dfd853822327e 100644
--- a/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
+++ b/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
@@ -33,7 +33,6 @@ makeInvocationForModuleBuildWithoutPaths(const ModuleDeps 
&Deps,
   CI.getFrontendOpts().IsSystemModule = Deps.IsSystem;
 
   CI.getLangOpts()->ImplicitModules = false;
-  CI.getHeaderSearchOpts().ImplicitModuleMaps = false;
 
   return CI;
 }
@@ -57,10 +56,16 @@ std::vector 
ModuleDeps::getCanonicalCommandLine(
 std::function LookupPCMPath,
 std::function LookupModuleDeps) const {
   CompilerInvocation CI(Invocation);
+  FrontendOptions &FrontendOpts = CI.getFrontendOpts();
+
+  InputKind ModuleMapInputKind(FrontendOpts.DashX.getLanguage(),
+   InputKind::Format::ModuleMap);
+  FrontendOpts.Inputs.emplace_back(ClangModuleMapFile, ModuleMapInputKind);
+  FrontendOpts.OutputFile = std::string(LookupPCMPath(ID));
 
   dependencies::detail::collectPCMAndModuleMapPaths(
   ClangModuleDeps, LookupPCMPath, LookupModuleDeps,
-  CI.getFrontendOpts().ModuleFiles, CI.getFrontendOpts().ModuleMapFiles);
+  FrontendOpts.ModuleFiles, FrontendOpts.ModuleMapFiles);
 
   return serializeCompilerInvocation(CI);
 }
@@ -179,13 +184,22 @@ ModuleID ModuleDepCollectorPP::handleTopLevelModule(const 
Module *M) {
   const FileEntry *ModuleMap = Instance.getPreprocessor()
.getHeaderSearchInfo()
.getModuleMap()
-   .getContainingModuleMapFile(M);
+   .getModuleMapFileForUniquing(M);
   MD.ClangModuleMapFile = std::string(ModuleMap ? ModuleMap->getName() : "");
 
   serialization::ModuleFile *MF =
   MDC.Instance.getASTReader()->getModuleManager().lookup(M->getASTFile());
   MDC.Instance.getASTReader()->visitInputFiles(
   *MF, true, true, [&](const serialization::InputFile &IF, bool isSystem) {
+// __inferred_module.map is the result of the way in which an implicit
+// module build handles inferred modules. It adds an overlay VFS with
+// this file in the proper directory and relies on the rest of Clang to
+// handle it like normal. With explicitly built modules we don't need
+// to play VFS tricks, so replace it with the correct module map.
+if (IF.getFile()->getName().endswith("__inferred_module.map")) {
+  MD.FileDeps.insert(ModuleMap->getName());
+  return;
+}
 MD.FileDeps.insert(IF.getFile()->getName());
   });
 

diff  --git 
a/clang/test/ClangScanDeps/Inputs/frameworks/Inferred.framework/Frameworks/Sub.framework/Headers/Sub.h
 
b/clang/test/ClangScanDeps/Inputs/frameworks/Inferred.framework/Frameworks/Sub.framework/Headers/Sub.h
new file mode 100644
index 0..e69de29bb2d1d

diff  --git 
a/clang/test/ClangScanDeps/Inputs/frameworks/Inferred.framework/Headers/Inferred.h
 
b/clang/test/ClangScanDeps/Inputs/frameworks/Inferred.framework/Headers/Inferred.h
new file mode 100644
index 0..1855e4fad5f8d
--- /dev/null
+++ 
b/clang/test/ClangScanDeps/Inputs/frameworks/Inferred.framework/Headers/Inferred.h
@@ -0,0 +1 @@
+typedef int inferred;

diff  --git 
a/clang/test/ClangScanDeps/Inputs/frameworks/System.framework/Headers/System.h 
b/clang/test/ClangScanDeps/Inputs/frameworks/System.framework/Headers/System.h
new file mode 100644
index 0..a90c62886749f
--- /dev/null
+++ 
b/c

[PATCH] D102495: [clang][deps] Support inferred modules

2021-05-20 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 added inline comments.



Comment at: clang/test/ClangScanDeps/modules-inferred-explicit-build.m:13-15
+// RUN: %clang @%t.inferred.cc1.rsp -pedantic -Werror
+// RUN: %clang @%t.system.cc1.rsp -pedantic -Werror
+// RUN: %clang -x objective-c -fsyntax-only %t.dir/modules_cdb_input.cpp \

frgossen wrote:
> These three commands rely on file creations in the current working directory.
Thanks for the heads-up and for the revert. Fixed in 7defab082070.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102495

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


[PATCH] D102839: [RISCV][Clang] Add -mno-idiv option to disable hardware int division

2021-05-20 Thread ksyx via Phabricator via cfe-commits
ksyx created this revision.
ksyx added reviewers: asb, rsmith, shiva0217.
Herald added subscribers: vkmr, frasercrmck, dang, evandro, luismarques, 
apazos, sameer.abuasal, s.egerton, Jim, benna, psnobl, jocewei, PkmX, the_o, 
brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, jrtc27, kito-cheng, 
niosHD, sabuasal, simoncook, johnrusso, rbar, hiraditya.
ksyx requested review of this revision.
Herald added subscribers: llvm-commits, cfe-commits, MaskRay.
Herald added projects: clang, LLVM.

With option `-mno-idiv`, hardware integral division and modulus instructions in 
M extension will be disabled, while leaving multiply instructions enabled.

I am not sure whether there is a better way of implementing this, so please 
point out if there is one, thanks.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D102839

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Basic/Targets/RISCV.cpp
  clang/lib/Basic/Targets/RISCV.h
  clang/lib/Driver/ToolChains/Arch/RISCV.cpp
  clang/test/Driver/riscv-no-idiv.c
  llvm/lib/Target/RISCV/RISCV.td
  llvm/lib/Target/RISCV/RISCVISelLowering.cpp
  llvm/lib/Target/RISCV/RISCVInstrInfoM.td
  llvm/lib/Target/RISCV/RISCVSubtarget.h
  llvm/test/CodeGen/RISCV/no-idiv.ll
  llvm/test/MC/RISCV/rv32m-no-idiv-div.s
  llvm/test/MC/RISCV/rv32m-no-idiv-mul.s
  llvm/test/MC/RISCV/rv64m-no-idiv-div.s
  llvm/test/MC/RISCV/rv64m-no-idiv-mul.s

Index: llvm/test/MC/RISCV/rv64m-no-idiv-mul.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/rv64m-no-idiv-mul.s
@@ -0,0 +1,5 @@
+# RUN: llvm-mc %s -triple=riscv64 -mattr=+m,+no-idiv -riscv-no-aliases 2>&1 \
+# RUN: | FileCheck -check-prefixes=CHECK-INST %s
+
+# CHECK-INST: mulw ra, sp, gp
+mulw ra, sp, gp
Index: llvm/test/MC/RISCV/rv64m-no-idiv-div.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/rv64m-no-idiv-div.s
@@ -0,0 +1,14 @@
+# RUN: not llvm-mc %s -triple=riscv64 -mattr=+m,+no-idiv -riscv-no-aliases 2>&1 \
+# RUN: | FileCheck -check-prefixes=CHECK-ERROR %s
+
+# CHECK-ERROR: 5:1: error: instruction requires the following: Hardware integral division not disabled
+divw tp, t0, t1
+
+# CHECK-ERROR: 8:1: error: instruction requires the following: Hardware integral division not disabled
+divuw t2, s0, s2
+
+# CHECK-ERROR: 11:1: error: instruction requires the following: Hardware integral division not disabled
+remw a0, a1, a2
+
+# CHECK-ERROR: 14:1: error: instruction requires the following: Hardware integral division not disabled
+remuw a3, a4, a5
Index: llvm/test/MC/RISCV/rv32m-no-idiv-mul.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/rv32m-no-idiv-mul.s
@@ -0,0 +1,14 @@
+# RUN: llvm-mc %s -triple=riscv32 -mattr=+m,+no-idiv -riscv-no-aliases 2>&1 \
+# RUN: | FileCheck -check-prefixes=CHECK-INST %s
+
+# CHECK-INST: mul a4, ra, s0
+mul a4, ra, s0
+
+# CHECK-INST: mulh ra, zero, zero
+mulh x1, x0, x0
+
+# CHECK-INST: mulhsu t0, t2, t1
+mulhsu t0, t2, t1
+
+# CHECK-INST: mulhu a5, a4, a3
+mulhu a5, a4, a3
Index: llvm/test/MC/RISCV/rv32m-no-idiv-div.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/rv32m-no-idiv-div.s
@@ -0,0 +1,14 @@
+# RUN: not llvm-mc %s -triple=riscv32 -mattr=+m,+no-idiv -riscv-no-aliases 2>&1 \
+# RUN: | FileCheck -check-prefixes=CHECK-ERROR %s
+
+# CHECK-ERROR: 5:1: error: instruction requires the following: Hardware integral division not disabled
+div s0, s0, s0
+
+# CHECK-ERROR: 8:1: error: instruction requires the following: Hardware integral division not disabled
+divu gp, a0, a1
+
+# CHECK-ERROR: 11:1: error: instruction requires the following: Hardware integral division not disabled
+rem s2, s2, s8
+
+# CHECK-ERROR: 14:1: error: instruction requires the following: Hardware integral division not disabled
+remu x18, x18, x24
Index: llvm/test/CodeGen/RISCV/no-idiv.ll
===
--- /dev/null
+++ llvm/test/CodeGen/RISCV/no-idiv.ll
@@ -0,0 +1,45 @@
+; RUN: llc -mtriple=riscv32 -mattr=+m,+no-idiv -verify-machineinstrs < %s \
+; RUN:  | not FileCheck -check-prefix=CHECK-DIV %s
+; RUN: llc -mtriple=riscv64 -mattr=+m,+no-idiv -verify-machineinstrs < %s \
+; RUN:  | not FileCheck -check-prefix=CHECK-DIV %s
+; RUN: llc -mtriple=riscv32 -mattr=+m,+no-idiv -verify-machineinstrs < %s \
+; RUN:  | not FileCheck -check-prefix=CHECK-REM %s
+; RUN: llc -mtriple=riscv64 -mattr=+m,+no-idiv -verify-machineinstrs < %s \
+; RUN:  | not FileCheck -check-prefix=CHECK-REM %s
+
+; RUN: llc -mtriple=riscv32 -mattr=+m,+no-idiv -verify-machineinstrs < %s \
+; RUN:  | not FileCheck -check-prefix=CHECK-UDIV %s
+; RUN: llc -mtriple=riscv64 -mattr=+m,+no-idiv -verify-machineinstrs < %s \
+; RUN:  | not FileCheck -check-prefix=CHECK-UDIV %s
+; RUN: llc -mtriple=riscv32 -mattr=+m,+no-idiv -verify-machineinstrs < %s \
+; RUN:  | no

[PATCH] D100630: [Debug-Info][DBX] DW_TAG_rvalue_reference_type should not be generated when dwarf version is smaller than 4

2021-05-20 Thread ChenZheng via Phabricator via cfe-commits
shchenz updated this revision to Diff 346680.
shchenz added a comment.

1: use the solution in the FE


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100630

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/test/CodeGenCXX/debug-info-rvalue-ref.cpp


Index: clang/test/CodeGenCXX/debug-info-rvalue-ref.cpp
===
--- clang/test/CodeGenCXX/debug-info-rvalue-ref.cpp
+++ clang/test/CodeGenCXX/debug-info-rvalue-ref.cpp
@@ -1,4 +1,8 @@
 // RUN: %clang_cc1 -std=c++11 -emit-llvm -debug-info-kind=limited -triple 
x86_64-apple-darwin %s -o - | FileCheck %s
+// RUN: %clang_cc1 -std=c++11 -dwarf-version=4 -gstrict-dwarf -emit-llvm 
-debug-info-kind=limited \
+// RUN:   -triple x86_64-apple-darwin %s -o - | FileCheck %s
+// RUN: %clang_cc1 -std=c++11 -dwarf-version=3 -gstrict-dwarf -emit-llvm 
-debug-info-kind=limited \
+// RUN:  -triple x86_64-apple-darwin %s -o - | FileCheck %s 
--check-prefix=NORVALUE
 
 extern "C" {
 extern int printf(const char * format, ...);
@@ -10,3 +14,4 @@
 
 // CHECK: !DIDerivedType(tag: DW_TAG_rvalue_reference_type, baseType: 
![[INT:[0-9]+]], size: 64)
 // CHECK: ![[INT]] = !DIBasicType(name: "int"
+// NORVALUE: !DIDerivedType(tag: DW_TAG_reference_type, baseType: 
![[INT:[0-9]+]], size: 64)
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -2989,8 +2989,13 @@
 
 llvm::DIType *CGDebugInfo::CreateType(const RValueReferenceType *Ty,
   llvm::DIFile *Unit) {
-  return CreatePointerLikeType(llvm::dwarf::DW_TAG_rvalue_reference_type, Ty,
-   Ty->getPointeeType(), Unit);
+  llvm::dwarf::Tag Tag = llvm::dwarf::DW_TAG_rvalue_reference_type;
+  // DW_TAG_rvalue_reference_type was introduced in DWARF 4.
+  if (CGM.getCodeGenOpts().DebugStrictDwarf &&
+  CGM.getCodeGenOpts().DwarfVersion < 4)
+Tag = llvm::dwarf::DW_TAG_reference_type;
+
+  return CreatePointerLikeType(Tag, Ty, Ty->getPointeeType(), Unit);
 }
 
 llvm::DIType *CGDebugInfo::CreateType(const MemberPointerType *Ty,


Index: clang/test/CodeGenCXX/debug-info-rvalue-ref.cpp
===
--- clang/test/CodeGenCXX/debug-info-rvalue-ref.cpp
+++ clang/test/CodeGenCXX/debug-info-rvalue-ref.cpp
@@ -1,4 +1,8 @@
 // RUN: %clang_cc1 -std=c++11 -emit-llvm -debug-info-kind=limited -triple x86_64-apple-darwin %s -o - | FileCheck %s
+// RUN: %clang_cc1 -std=c++11 -dwarf-version=4 -gstrict-dwarf -emit-llvm -debug-info-kind=limited \
+// RUN:   -triple x86_64-apple-darwin %s -o - | FileCheck %s
+// RUN: %clang_cc1 -std=c++11 -dwarf-version=3 -gstrict-dwarf -emit-llvm -debug-info-kind=limited \
+// RUN:  -triple x86_64-apple-darwin %s -o - | FileCheck %s --check-prefix=NORVALUE
 
 extern "C" {
 extern int printf(const char * format, ...);
@@ -10,3 +14,4 @@
 
 // CHECK: !DIDerivedType(tag: DW_TAG_rvalue_reference_type, baseType: ![[INT:[0-9]+]], size: 64)
 // CHECK: ![[INT]] = !DIBasicType(name: "int"
+// NORVALUE: !DIDerivedType(tag: DW_TAG_reference_type, baseType: ![[INT:[0-9]+]], size: 64)
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -2989,8 +2989,13 @@
 
 llvm::DIType *CGDebugInfo::CreateType(const RValueReferenceType *Ty,
   llvm::DIFile *Unit) {
-  return CreatePointerLikeType(llvm::dwarf::DW_TAG_rvalue_reference_type, Ty,
-   Ty->getPointeeType(), Unit);
+  llvm::dwarf::Tag Tag = llvm::dwarf::DW_TAG_rvalue_reference_type;
+  // DW_TAG_rvalue_reference_type was introduced in DWARF 4.
+  if (CGM.getCodeGenOpts().DebugStrictDwarf &&
+  CGM.getCodeGenOpts().DwarfVersion < 4)
+Tag = llvm::dwarf::DW_TAG_reference_type;
+
+  return CreatePointerLikeType(Tag, Ty, Ty->getPointeeType(), Unit);
 }
 
 llvm::DIType *CGDebugInfo::CreateType(const MemberPointerType *Ty,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D100630: [Debug-Info][DBX] DW_TAG_rvalue_reference_type should not be generated when dwarf version is smaller than 4

2021-05-20 Thread ChenZheng via Phabricator via cfe-commits
shchenz added a comment.

@dblaikie Hi David, should we change to use the FE solution? Maybe we should 
fix the issue where it happens? We should not let the FE generate the un-strict 
dwarf tag in FE and then fix it in the BE. I have changed this patch to fix 
this strict DWARF issue in FE. What do you think? Thanks


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100630

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


[PATCH] D102812: [clang] Don't pass multiple backend options if mixing -mimplicit-it and -Wa,-mimplicit-it

2021-05-20 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo added a comment.

In D102812#2770516 , @DavidSpickett 
wrote:

>> If multiple instances of the -arm-implicit-it option is passed to
>> the backend, it errors out.
>
> Does it make sense to fix that side too?

I guess it could, although I didn't look into whether it's trivial or tricky. 
This particular case was at least easy, as all options are handled at once 
place in one single function.

> Seems like we have a few options to handle this on clang's side:
>
> 1. Last of `-mimplicit-it` and `-Wa,-mimplicit-it` wins
> 2. If they're the same, accept it, if they mismatch, error
> 3. Take the (last) one that matches the current input type
>
> There is some precedent for number 3 in 
> 1d51c699b9e2ebc5bcfdbe85c74cc871426333d4 
> . 
> Quoting from the commit msg:
>
>   Now the same rules will apply to -Wa,-march/-mcpu as would
>   if you just passed them to the compiler:
>   * -Wa/-Xassembler options only apply to assembly files.
>   * Architecture derived from mcpu beats any march options.
>   * When there are multiple mcpu or multiple march, the last
> one wins.
>   * If there is a compiler option and an assembler option of
> the same type, we prefer the one that fits the input type.
>   * If there is an applicable mcpu option but it is overruled
> by an march, the cpu value is still used for the "-target-cpu"
> cc1 option.
>
> I'm not up on all the background to this change so perhaps doing number 3 is 
> going to break existing use cases.

If case 3 would mean that `-mimplicit-it=` is ignored when compiling assembly 
files, that would indeed break existing use cases. If using the input file type 
to disambiguate cases when there's conflicts, then that's fine, although I'm 
not sure if there's need for it really.

In this case, the compiler level option is around for historical reasons, and 
we're aiming to phase out its use within some time frame (although there's much 
less urgency with it now if we get this resolved more cleanly), so I'm not sure 
if it's worth to complicate things for it.

Also, if considering the predecent for how the option behaves from 
GCC/binutils; there, there's only the -Wa level option, and one could plausibly 
compile a C file with inline assembly that requires adding implicit IT 
instructions, so there, the -Wa option needs to be respected even when the 
original source is C.




Comment at: clang/lib/Driver/ToolChains/Clang.cpp:2584
   }
+  if (!ImplicitItCompiler.empty() && !ImplicitItAsm.empty()) {
+// Set both via compiler flag and asm flag; ok if they match.

DavidSpickett wrote:
> ```
> if (ImplicitItCompiler.size() && ImplicitItAsm.size()) {
> ```
Thanks, that'd be even nicer.



Comment at: clang/test/Driver/arm-target-as-mimplicit-it.s:39
 // ALWAYS: "-mllvm" "-arm-implicit-it=always"
+// ALWAYS-NOT: "-arm-implicit-it={{.*}}"
 // NEVER: "-mllvm" "-arm-implicit-it=never"

DavidSpickett wrote:
> mstorsjo wrote:
> > This pattern wouldn't detct if there's e.g. `-arm-implicit-it=never 
> > -arm-implicit-it=always`, but I added test cases that pass 
> > `-Wa,-mimplicit-it=always` twice, where this check should be able to verify 
> > that we only output it once.
> Could you do:
> ```
> // ALWAYS-NOT: "-mllvm" "-arm-implicit-it=never"
> // ALWAYS: "-mllvm" "-arm-implicit-it=always"
> ```
> 
> Not sure if doing the NOT moves the check forward to beyond where the always 
> would be.
Thanks, I think that could work to further guard against that case.



Comment at: clang/test/Driver/arm-target-as-mimplicit-it.s:44
 // THUMB: "-mllvm" "-arm-implicit-it=thumb"
-// NEVER_ALWAYS: "-mllvm" "-arm-implicit-it=never" "-mllvm" 
"-arm-implicit-it=always"
-// ALWAYS_NEVER: "-mllvm" "-arm-implicit-it=always" "-mllvm" 
"-arm-implicit-it=never"
+// MISMATCH: error: unsupported argument '{{.*}}' to option '-mimplicit-it'
 // INVALID: error: unsupported argument '-mimplicit-it=foo' to option 'Wa,'

DavidSpickett wrote:
> Can you do this check without the regex?
> 
> Reading it as is this doesn't look like a very helpful error. I'd expect 
> something like:
> ```
> error: mismatched values for implicit-it "thumb" and "arm"
> ```
> 
Yeah this is mostly me being lazy in the first iteration of the patch (I wrote 
it late last night and wanted to have something to show before finishing) and 
reusing existing diagnostic messages - it does print `unsupported argument 
'always and never' to option '-mimplicit-it'` in the current form, which is a 
bit odd indeed.

But I guess if I'd handle both option variants in the same loop, so we can be 
certain about which one was set last, we could simply define it as last one set 
wins and we could get rid of the error case altogether.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D102

[PATCH] D102812: [clang] Don't pass multiple backend options if mixing -mimplicit-it and -Wa,-mimplicit-it

2021-05-20 Thread David Spickett via Phabricator via cfe-commits
DavidSpickett added a comment.

> If case 3 would mean that -mimplicit-it= is ignored when compiling assembly 
> files, that would indeed break existing use cases. If using the input file 
> type to disambiguate cases when there's conflicts, then that's fine, although 
> I'm not sure if there's need for it really.

Yes, I mis-stated that one. Let me try again.

You have both options: use the one that applies to the input type
You have 2 of one option: choose the last one
You have 2 of each option: choose the last one that applies to the input type

I think that would accommodate the C with inline asm case. I only suggest it 
because that's what I did in the past, I don't have specific use cases to 
support it.

That said we've had issues downstream with `-mcpu` and `-march` options that 
conflict, or should conflict, and they don't warn in any way. I would like to 
avoid another situation like that.

Given that using both options currently crashes clang and GCC doesn't have 
`-mimplicit-it` I think what you have is actually the best way to go. If the 
two options agree, fine, if they don't, error. Let's not make it more 
complicated than it has to be.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102812

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


[PATCH] D102760: [llvm] Let SmallVector construct from any Iterable

2021-05-20 Thread Guillaume Chatelet via Phabricator via cfe-commits
gchatelet added inline comments.



Comment at: clang/include/clang/Basic/Module.h:98
 public:
+  Module(const Module &) = default;
+

fhahn wrote:
> how is this related?
> how is this related?

I'm glad you ask! I'm still investigating the errors that led to this addition 
(and the one in `llvm/tools/llvm-xray/xray-converter.cpp`) but I suspect this 
is due to the recursive nature of these classes.
Both `Module` and `StackIdData` contains self-referencing `SmallVector`. It is 
unclear to me why the compiler is trying to instantiate the newly added 
`SmallVector` constructor //during// type declaration.

I'll post the compiler errors below the additions.



Comment at: clang/include/clang/Basic/Module.h:98
 public:
+  Module(const Module &) = default;
+

gchatelet wrote:
> fhahn wrote:
> > how is this related?
> > how is this related?
> 
> I'm glad you ask! I'm still investigating the errors that led to this 
> addition (and the one in `llvm/tools/llvm-xray/xray-converter.cpp`) but I 
> suspect this is due to the recursive nature of these classes.
> Both `Module` and `StackIdData` contains self-referencing `SmallVector`. It 
> is unclear to me why the compiler is trying to instantiate the newly added 
> `SmallVector` constructor //during// type declaration.
> 
> I'll post the compiler errors below the additions.
```
FAILED: tools/clang/lib/Lex/CMakeFiles/obj.clangLex.dir/HeaderSearch.cpp.o 
/redacted/build-llvm/download/clang/bin/clang++ 
--sysroot=/redacted/build-llvm/download/sysroot -DGTEST_HAS_RTTI=0 
-D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS 
-D__STDC_LIMIT_MACROS -Itools/clang/lib/Lex 
-I/redacted/git/llvm-project/clang/lib/Lex 
-I/redacted/git/llvm-project/clang/include -Itools/clang/include -Iinclude 
-I/redacted/git/llvm-project/llvm/include -fPIC -fvisibility-inlines-hidden 
-Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra 
-Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers 
-pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough 
-Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor 
-Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion 
-Wmisleading-indentation -fdiagnostics-color -ffunction-sections 
-fdata-sections -fno-common -Woverloaded-virtual -Wno-nested-anon-types -O3 
-DNDEBUG  -fno-exceptions -fno-rtti -std=c++14 -MD -MT 
tools/clang/lib/Lex/CMakeFiles/obj.clangLex.dir/HeaderSearch.cpp.o -MF 
tools/clang/lib/Lex/CMakeFiles/obj.clangLex.dir/HeaderSearch.cpp.o.d -o 
tools/clang/lib/Lex/CMakeFiles/obj.clangLex.dir/HeaderSearch.cpp.o -c 
/redacted/git/llvm-project/clang/lib/Lex/HeaderSearch.cpp
In file included from 
/redacted/git/llvm-project/clang/lib/Lex/HeaderSearch.cpp:13:
In file included from 
/redacted/git/llvm-project/clang/include/clang/Lex/HeaderSearch.h:16:
In file included from 
/redacted/git/llvm-project/clang/include/clang/Basic/SourceLocation.h:19:
/redacted/git/llvm-project/llvm/include/llvm/Support/PointerLikeTypeTraits.h:61:28:
 error: invalid application of 'alignof' to an incomplete type 'clang::Module'
  detail::ConstantLog2::value;
   ^~
/redacted/git/llvm-project/llvm/include/llvm/ADT/IterableTraits.h:23:33: note: 
in instantiation of template class 'llvm::PointerLikeTypeTraits' requested here
std::next(std::declval()),
^
/redacted/git/llvm-project/llvm/include/llvm/ADT/IterableTraits.h:36:39: note: 
while substituting explicitly-specified template arguments into function 
template 'is_forward_iterator' 
struct is_forward_iterator : decltype(detail::is_forward_iterator(0)) {};
  ^
/redacted/git/llvm-project/llvm/include/llvm/ADT/IterableTraits.h:46:42: note: 
in instantiation of template class 'llvm::is_forward_iterator *>' requested here
 llvm::is_forward_iterator{});
 ^
/redacted/git/llvm-project/llvm/include/llvm/ADT/IterableTraits.h:51:37: note: 
while substituting deduced template arguments into function template 
'is_range_iterable' [with T = const 
llvm::SmallVector, 2> &, I = (no 
value)]
struct is_range_iterable : decltype(detail::is_range_iterable(0)) {};
^
/redacted/git/llvm-project/llvm/include/llvm/ADT/SmallVector.h:1194:30: note: 
in instantiation of template class 'llvm::is_range_iterable, 2> &>' 
requested here
  std::enable_if_t::value, bool> = true)
 ^
/redacted/git/llvm-project/llvm/include/llvm/ADT/SmallVector.h:1168:22: note: 
while substituting deduced template arguments into function template 
'SmallVector' [with Iterable = const 
llvm::SmallVector, 2> &]
class LLVM_GSL_OWNER SmallVector : public SmallVectorImpl,
 ^
/redacted/git/llvm-project/clang/include/clang/Basic/Module.h:96:7: note: while 
declaring t

[PATCH] D102835: [analyzer] Correctly propagate ConstructionContextLayer thru ParenExpr

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

This looks great!




Comment at: clang/test/Analysis/NewDelete-checker-test.cpp:41-52
+// RUN: %clang_analyze_cc1 -std=c++17 -fblocks %s \
+// RUN:   -verify=expected,newdelete \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=cplusplus.NewDelete \
+// RUN:   -analyzer-config c++-allocator-inlining=true
+//
+// RUN: %clang_analyze_cc1 -std=c++17 -fblocks -verify %s \

This mail adds some insight into the usage of `c++-allocator-inlining`:

https://lists.llvm.org/pipermail/cfe-dev/2020-February/064754.html

About the code in `MallocChecker` that handles this flag (`NewDelete` is a part 
of this as well):

> Yes, we should remove the old code for c++-allocator-inlining=false. The 
> worry we've had back then as that in the new mode we've disabled aggressive 
> behavior of MallocChecker in which it reacted to some overloaded operator new 
> invocations but i think this was the right thing to do and also nobody 
> complained; also nothing prevents us from bringing back the old behavior in a 
> much less confusing way.

As a response, D75432 removed all code that handed 
`c++-allocator-inlinging=false`. So these RUN lines can be removed I think.



Comment at: clang/test/Analysis/NewDelete-checker-test.cpp:54-57
+// RUN: %clang_analyze_cc1 -std=c++17 -fblocks -verify %s \
+// RUN:   -verify=expected,leak \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=cplusplus.NewDeleteLeaks

This last RUN seems to be the same as the first.


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

https://reviews.llvm.org/D102835

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


[PATCH] D102273: [analyzer] LoopUnrolling: fix crash when a loop counter is captured in a lambda by reference

2021-05-20 Thread Abbas Sabra via Phabricator via cfe-commits
AbbasSabra added a comment.

Note: I don't have the right to re-run the failed build/test. I assume that it 
is not related to my change since the test compile and runs omp code(Static 
analyzer doesn't run on that test)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102273

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


[PATCH] D100252: [clang] Fix for "Bug 27113 - MSVC-compat __identifier implementation incomplete"

2021-05-20 Thread Hans Wennborg via Phabricator via cfe-commits
hans accepted this revision.
hans added a comment.
This revision is now accepted and ready to land.

lgtm


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

https://reviews.llvm.org/D100252

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


[PATCH] D102835: [analyzer] Correctly propagate ConstructionContextLayer thru ParenExpr

2021-05-20 Thread Tomasz Kamiński via Phabricator via cfe-commits
tomasz-kaminski-sonarsource added inline comments.



Comment at: clang/test/Analysis/NewDelete-checker-test.cpp:54-57
+// RUN: %clang_analyze_cc1 -std=c++17 -fblocks -verify %s \
+// RUN:   -verify=expected,leak \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=cplusplus.NewDeleteLeaks

Szelethus wrote:
> This last RUN seems to be the same as the first.
This checker enables NewDeleteLeaks, while first enables NewDelete. From what I 
have checked, this two seem to have different behavior.


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

https://reviews.llvm.org/D102835

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


[PATCH] D102835: [analyzer] Correctly propagate ConstructionContextLayer thru ParenExpr

2021-05-20 Thread Tomasz Kamiński via Phabricator via cfe-commits
tomasz-kaminski-sonarsource updated this revision to Diff 346700.
tomasz-kaminski-sonarsource added a comment.

Removed duplicated runs that were only differing by specifying 
c++-allocator-inlinging=true, which is the default value.


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

https://reviews.llvm.org/D102835

Files:
  clang/lib/Analysis/CFG.cpp
  clang/test/Analysis/NewDelete-checker-test.cpp
  clang/test/Analysis/NewDelete-path-notes.cpp
  clang/test/Analysis/NewDeleteLeaks-PR19102.cpp

Index: clang/test/Analysis/NewDeleteLeaks-PR19102.cpp
===
--- clang/test/Analysis/NewDeleteLeaks-PR19102.cpp
+++ clang/test/Analysis/NewDeleteLeaks-PR19102.cpp
@@ -1,5 +1,4 @@
 // RUN: %clang_analyze_cc1 -analyzer-checker=core,cplusplus.NewDeleteLeaks -verify %s
-// RUN: %clang_analyze_cc1 -analyzer-checker=core,cplusplus.NewDeleteLeaks -analyzer-config c++-allocator-inlining=true -verify %s
 
 class A0 {};
 
Index: clang/test/Analysis/NewDelete-path-notes.cpp
===
--- clang/test/Analysis/NewDelete-path-notes.cpp
+++ clang/test/Analysis/NewDelete-path-notes.cpp
@@ -4,11 +4,6 @@
 // RUN:   -analyzer-output=text -verify %s
 // RUN: %clang_analyze_cc1 \
 // RUN:   -analyzer-checker=cplusplus.NewDelete,unix.Malloc \
-// RUN:   -analyzer-config c++-allocator-inlining=true \
-// RUN:   -analyzer-config add-pop-up-notes=false \
-// RUN:   -analyzer-output=text -verify %s
-// RUN: %clang_analyze_cc1 \
-// RUN:   -analyzer-checker=cplusplus.NewDelete,unix.Malloc \
 // RUN:   -analyzer-config add-pop-up-notes=false \
 // RUN:   -analyzer-output=plist %s -o %t.plist
 // RUN: %normalize_plist <%t.plist | diff -ub \
Index: clang/test/Analysis/NewDelete-checker-test.cpp
===
--- clang/test/Analysis/NewDelete-checker-test.cpp
+++ clang/test/Analysis/NewDelete-checker-test.cpp
@@ -9,20 +9,23 @@
 // RUN:   -analyzer-checker=cplusplus.NewDelete \
 // RUN:   -analyzer-checker=cplusplus.NewDeleteLeaks
 //
-// RUN: %clang_analyze_cc1 -std=c++11 -fblocks %s \
+// RUN: %clang_analyze_cc1 -std=c++11 -fblocks -verify %s \
+// RUN:   -verify=expected,leak \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=cplusplus.NewDeleteLeaks
+//
+// RUN: %clang_analyze_cc1 -std=c++17 -fblocks %s \
 // RUN:   -verify=expected,newdelete \
 // RUN:   -analyzer-checker=core \
-// RUN:   -analyzer-checker=cplusplus.NewDelete \
-// RUN:   -analyzer-config c++-allocator-inlining=true
+// RUN:   -analyzer-checker=cplusplus.NewDelete
 //
-// RUN: %clang_analyze_cc1 -std=c++11 -fblocks -verify %s \
+// RUN: %clang_analyze_cc1 -DLEAKS -std=c++17 -fblocks %s \
 // RUN:   -verify=expected,newdelete,leak \
 // RUN:   -analyzer-checker=core \
 // RUN:   -analyzer-checker=cplusplus.NewDelete \
-// RUN:   -analyzer-checker=cplusplus.NewDeleteLeaks \
-// RUN:   -analyzer-config c++-allocator-inlining=true
+// RUN:   -analyzer-checker=cplusplus.NewDeleteLeaks
 //
-// RUN: %clang_analyze_cc1 -std=c++11 -fblocks -verify %s \
+// RUN: %clang_analyze_cc1 -std=c++17 -fblocks -verify %s \
 // RUN:   -verify=expected,leak \
 // RUN:   -analyzer-checker=core \
 // RUN:   -analyzer-checker=cplusplus.NewDeleteLeaks
@@ -288,7 +291,7 @@
 explicit shared_ptr(T *p) : p(p), control(new control_block) {
   control->retain();
 }
-shared_ptr(shared_ptr &other) : p(other.p), control(other.control) {
+shared_ptr(const shared_ptr &other) : p(other.p), control(other.control) {
   if (control)
   control->retain();
 }
@@ -314,11 +317,26 @@
 }
   };
 
+  template 
+  shared_ptr make_shared(Args &&...args) {
+return shared_ptr(new T(static_cast(args)...));
+  }
+
   void testSingle() {
 shared_ptr a(new int);
 *a = 1;
   }
 
+  void testMake() {
+shared_ptr a = make_shared();
+*a = 1;
+  }
+
+  void testMakeInParens() {
+shared_ptr a = (make_shared()); // no warn
+*a = 1;
+  }
+
   void testDouble() {
 shared_ptr a(new int);
 shared_ptr b = a;
Index: clang/lib/Analysis/CFG.cpp
===
--- clang/lib/Analysis/CFG.cpp
+++ clang/lib/Analysis/CFG.cpp
@@ -1456,6 +1456,13 @@
 // TODO: Handle other cases. For now, fail to find construction contexts.
 break;
   }
+  case Stmt::ParenExprClass: {
+// If expression is placed into parenthesis we should propagate the parent
+// construction context to subexpressions.
+auto *PE = cast(Child);
+findConstructionContexts(Layer, PE->getSubExpr());
+break;
+  }
   default:
 break;
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D102835: [analyzer] Correctly propagate ConstructionContextLayer thru ParenExpr

2021-05-20 Thread Tomasz Kamiński via Phabricator via cfe-commits
tomasz-kaminski-sonarsource added inline comments.



Comment at: clang/test/Analysis/NewDelete-checker-test.cpp:41-52
+// RUN: %clang_analyze_cc1 -std=c++17 -fblocks %s \
+// RUN:   -verify=expected,newdelete \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=cplusplus.NewDelete \
+// RUN:   -analyzer-config c++-allocator-inlining=true
+//
+// RUN: %clang_analyze_cc1 -std=c++17 -fblocks -verify %s \

Szelethus wrote:
> This mail adds some insight into the usage of `c++-allocator-inlining`:
> 
> https://lists.llvm.org/pipermail/cfe-dev/2020-February/064754.html
> 
> About the code in `MallocChecker` that handles this flag (`NewDelete` is a 
> part of this as well):
> 
> > Yes, we should remove the old code for c++-allocator-inlining=false. The 
> > worry we've had back then as that in the new mode we've disabled aggressive 
> > behavior of MallocChecker in which it reacted to some overloaded operator 
> > new invocations but i think this was the right thing to do and also nobody 
> > complained; also nothing prevents us from bringing back the old behavior in 
> > a much less confusing way.
> 
> As a response, D75432 removed all code that handed 
> `c++-allocator-inlinging=false`. So these RUN lines can be removed I think.
I have removed new runs with the c++-allocator-inlinging=true, and checked 
other files that have duplicated runs, and removed them.


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

https://reviews.llvm.org/D102835

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


[PATCH] D102835: [analyzer] Correctly propagate ConstructionContextLayer thru ParenExpr

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

Looks good to me.


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

https://reviews.llvm.org/D102835

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


[PATCH] D102835: [analyzer] Correctly propagate ConstructionContextLayer thru ParenExpr

2021-05-20 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus added inline comments.



Comment at: clang/test/Analysis/NewDelete-checker-test.cpp:54-57
+// RUN: %clang_analyze_cc1 -std=c++17 -fblocks -verify %s \
+// RUN:   -verify=expected,leak \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=cplusplus.NewDeleteLeaks

tomasz-kaminski-sonarsource wrote:
> Szelethus wrote:
> > This last RUN seems to be the same as the first.
> This checker enables NewDeleteLeaks, while first enables NewDelete. From what 
> I have checked, this two seem to have different behavior.
Oh, silly me. you're right. :) 


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

https://reviews.llvm.org/D102835

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


[PATCH] D102835: [analyzer] Correctly propagate ConstructionContextLayer thru ParenExpr

2021-05-20 Thread Tomasz Kamiński via Phabricator via cfe-commits
tomasz-kaminski-sonarsource updated this revision to Diff 346707.
tomasz-kaminski-sonarsource added a comment.

Adjusted  Clang.Analysis::NewDelete-path-notes.cpp.plist for removed lines.


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

https://reviews.llvm.org/D102835

Files:
  clang/lib/Analysis/CFG.cpp
  clang/test/Analysis/Inputs/expected-plists/NewDelete-path-notes.cpp.plist
  clang/test/Analysis/NewDelete-checker-test.cpp
  clang/test/Analysis/NewDelete-path-notes.cpp
  clang/test/Analysis/NewDeleteLeaks-PR19102.cpp

Index: clang/test/Analysis/NewDeleteLeaks-PR19102.cpp
===
--- clang/test/Analysis/NewDeleteLeaks-PR19102.cpp
+++ clang/test/Analysis/NewDeleteLeaks-PR19102.cpp
@@ -1,5 +1,4 @@
 // RUN: %clang_analyze_cc1 -analyzer-checker=core,cplusplus.NewDeleteLeaks -verify %s
-// RUN: %clang_analyze_cc1 -analyzer-checker=core,cplusplus.NewDeleteLeaks -analyzer-config c++-allocator-inlining=true -verify %s
 
 class A0 {};
 
Index: clang/test/Analysis/NewDelete-path-notes.cpp
===
--- clang/test/Analysis/NewDelete-path-notes.cpp
+++ clang/test/Analysis/NewDelete-path-notes.cpp
@@ -4,11 +4,6 @@
 // RUN:   -analyzer-output=text -verify %s
 // RUN: %clang_analyze_cc1 \
 // RUN:   -analyzer-checker=cplusplus.NewDelete,unix.Malloc \
-// RUN:   -analyzer-config c++-allocator-inlining=true \
-// RUN:   -analyzer-config add-pop-up-notes=false \
-// RUN:   -analyzer-output=text -verify %s
-// RUN: %clang_analyze_cc1 \
-// RUN:   -analyzer-checker=cplusplus.NewDelete,unix.Malloc \
 // RUN:   -analyzer-config add-pop-up-notes=false \
 // RUN:   -analyzer-output=plist %s -o %t.plist
 // RUN: %normalize_plist <%t.plist | diff -ub \
Index: clang/test/Analysis/NewDelete-checker-test.cpp
===
--- clang/test/Analysis/NewDelete-checker-test.cpp
+++ clang/test/Analysis/NewDelete-checker-test.cpp
@@ -9,20 +9,23 @@
 // RUN:   -analyzer-checker=cplusplus.NewDelete \
 // RUN:   -analyzer-checker=cplusplus.NewDeleteLeaks
 //
-// RUN: %clang_analyze_cc1 -std=c++11 -fblocks %s \
+// RUN: %clang_analyze_cc1 -std=c++11 -fblocks -verify %s \
+// RUN:   -verify=expected,leak \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=cplusplus.NewDeleteLeaks
+//
+// RUN: %clang_analyze_cc1 -std=c++17 -fblocks %s \
 // RUN:   -verify=expected,newdelete \
 // RUN:   -analyzer-checker=core \
-// RUN:   -analyzer-checker=cplusplus.NewDelete \
-// RUN:   -analyzer-config c++-allocator-inlining=true
+// RUN:   -analyzer-checker=cplusplus.NewDelete
 //
-// RUN: %clang_analyze_cc1 -std=c++11 -fblocks -verify %s \
+// RUN: %clang_analyze_cc1 -DLEAKS -std=c++17 -fblocks %s \
 // RUN:   -verify=expected,newdelete,leak \
 // RUN:   -analyzer-checker=core \
 // RUN:   -analyzer-checker=cplusplus.NewDelete \
-// RUN:   -analyzer-checker=cplusplus.NewDeleteLeaks \
-// RUN:   -analyzer-config c++-allocator-inlining=true
+// RUN:   -analyzer-checker=cplusplus.NewDeleteLeaks
 //
-// RUN: %clang_analyze_cc1 -std=c++11 -fblocks -verify %s \
+// RUN: %clang_analyze_cc1 -std=c++17 -fblocks -verify %s \
 // RUN:   -verify=expected,leak \
 // RUN:   -analyzer-checker=core \
 // RUN:   -analyzer-checker=cplusplus.NewDeleteLeaks
@@ -288,7 +291,7 @@
 explicit shared_ptr(T *p) : p(p), control(new control_block) {
   control->retain();
 }
-shared_ptr(shared_ptr &other) : p(other.p), control(other.control) {
+shared_ptr(const shared_ptr &other) : p(other.p), control(other.control) {
   if (control)
   control->retain();
 }
@@ -314,11 +317,26 @@
 }
   };
 
+  template 
+  shared_ptr make_shared(Args &&...args) {
+return shared_ptr(new T(static_cast(args)...));
+  }
+
   void testSingle() {
 shared_ptr a(new int);
 *a = 1;
   }
 
+  void testMake() {
+shared_ptr a = make_shared();
+*a = 1;
+  }
+
+  void testMakeInParens() {
+shared_ptr a = (make_shared()); // no warn
+*a = 1;
+  }
+
   void testDouble() {
 shared_ptr a(new int);
 shared_ptr b = a;
Index: clang/test/Analysis/Inputs/expected-plists/NewDelete-path-notes.cpp.plist
===
--- clang/test/Analysis/Inputs/expected-plists/NewDelete-path-notes.cpp.plist
+++ clang/test/Analysis/Inputs/expected-plists/NewDelete-path-notes.cpp.plist
@@ -12,7 +12,7 @@
  kindevent
  location
  
-  line24
+  line19
   col3
   file0
  
@@ -20,12 +20,12 @@
  

 
- line24
+ line19
  col3
  file0
 
 
- line24
+ line19
  col10
  file0
 
@@ -45,12 +45,12 @@
 start
  
   
-   line17
+   line12
col1
file0
   
   
-   line17
+   line12
col4
  

[PATCH] D99455: [AST] Store regular ValueDecl* in BindingDecl

2021-05-20 Thread Aaron Puchert via Phabricator via cfe-commits
aaronpuchert added a comment.

Ping @rsmith.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99455

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


[PATCH] D99455: [AST] Store regular ValueDecl* in BindingDecl

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

LGTM, please add `NFC` to the commit message though. Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99455

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


[clang] 80c1adf - [clang] Invalidate a non-dependent-type RecordDecl when it has any dependent-type base class specifier.

2021-05-20 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2021-05-20T15:33:05+02:00
New Revision: 80c1adfd18b5308422827f8372c28cc2ecfaa015

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

LOG: [clang] Invalidate a non-dependent-type RecordDecl when it has any 
dependent-type base class specifier.

This happens during the error-recovery, and it would esacpe all
dependent-type check guards in getTypeInfo/constexpr-evaluator code
paths, which lead to crashes.

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

Added: 


Modified: 
clang/lib/Sema/SemaDeclCXX.cpp
clang/test/SemaTemplate/temp_class_spec.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 1a8ef40aa86b..f4d8f4d9aa33 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -2508,6 +2508,14 @@ Sema::CheckBaseSpecifier(CXXRecordDecl *Class,
   }
 }
 
+// Make sure that we don't make an ill-formed AST where the type of the
+// Class is non-dependent and its attached base class specifier is an
+// dependent type, which violates invariants in many clang code paths (e.g.
+// constexpr evaluator). If this case happens (in errory-recovery mode), we
+// explicitly mark the Class decl invalid. The diagnostic was already
+// emitted.
+if (!Class->getTypeForDecl()->isDependentType())
+  Class->setInvalidDecl();
 return new (Context) CXXBaseSpecifier(SpecifierRange, Virtual,
   Class->getTagKind() == TTK_Class,
   Access, TInfo, EllipsisLoc);

diff  --git a/clang/test/SemaTemplate/temp_class_spec.cpp 
b/clang/test/SemaTemplate/temp_class_spec.cpp
index f92c52e9624e..bf57b13725dc 100644
--- a/clang/test/SemaTemplate/temp_class_spec.cpp
+++ b/clang/test/SemaTemplate/temp_class_spec.cpp
@@ -375,3 +375,16 @@ class Bar<0> : public Foo { // expected-error{{partial 
specialization of 'Bar
   Bar() : Foo() {}
 };
 } // namespace
+
+namespace Crash {
+template
+class Base {};
+
+template class Foo;
+
+template 
+class Foo : public Base {}; // expected-error{{partial specialization 
of 'Foo' does not use any of its template parameters}}
+
+// verify that getASTRecordLayout doesn't crash on the 
ClassTemplateSpecializationDecl.
+constexpr int s = sizeof(Foo);
+}



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


[PATCH] D102773: [clang] invalidate a non-dependent-type RecordDecl when it has any dependent-type base class specifier.

2021-05-20 Thread Haojian Wu 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 rG80c1adfd18b5: [clang] Invalidate a non-dependent-type 
RecordDecl when it has any dependent… (authored by hokein).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102773

Files:
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/SemaTemplate/temp_class_spec.cpp


Index: clang/test/SemaTemplate/temp_class_spec.cpp
===
--- clang/test/SemaTemplate/temp_class_spec.cpp
+++ clang/test/SemaTemplate/temp_class_spec.cpp
@@ -375,3 +375,16 @@
   Bar() : Foo() {}
 };
 } // namespace
+
+namespace Crash {
+template
+class Base {};
+
+template class Foo;
+
+template 
+class Foo : public Base {}; // expected-error{{partial specialization 
of 'Foo' does not use any of its template parameters}}
+
+// verify that getASTRecordLayout doesn't crash on the 
ClassTemplateSpecializationDecl.
+constexpr int s = sizeof(Foo);
+}
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -2508,6 +2508,14 @@
   }
 }
 
+// Make sure that we don't make an ill-formed AST where the type of the
+// Class is non-dependent and its attached base class specifier is an
+// dependent type, which violates invariants in many clang code paths (e.g.
+// constexpr evaluator). If this case happens (in errory-recovery mode), we
+// explicitly mark the Class decl invalid. The diagnostic was already
+// emitted.
+if (!Class->getTypeForDecl()->isDependentType())
+  Class->setInvalidDecl();
 return new (Context) CXXBaseSpecifier(SpecifierRange, Virtual,
   Class->getTagKind() == TTK_Class,
   Access, TInfo, EllipsisLoc);


Index: clang/test/SemaTemplate/temp_class_spec.cpp
===
--- clang/test/SemaTemplate/temp_class_spec.cpp
+++ clang/test/SemaTemplate/temp_class_spec.cpp
@@ -375,3 +375,16 @@
   Bar() : Foo() {}
 };
 } // namespace
+
+namespace Crash {
+template
+class Base {};
+
+template class Foo;
+
+template 
+class Foo : public Base {}; // expected-error{{partial specialization of 'Foo' does not use any of its template parameters}}
+
+// verify that getASTRecordLayout doesn't crash on the ClassTemplateSpecializationDecl.
+constexpr int s = sizeof(Foo);
+}
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -2508,6 +2508,14 @@
   }
 }
 
+// Make sure that we don't make an ill-formed AST where the type of the
+// Class is non-dependent and its attached base class specifier is an
+// dependent type, which violates invariants in many clang code paths (e.g.
+// constexpr evaluator). If this case happens (in errory-recovery mode), we
+// explicitly mark the Class decl invalid. The diagnostic was already
+// emitted.
+if (!Class->getTypeForDecl()->isDependentType())
+  Class->setInvalidDecl();
 return new (Context) CXXBaseSpecifier(SpecifierRange, Virtual,
   Class->getTagKind() == TTK_Class,
   Access, TInfo, EllipsisLoc);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D100991: Fix parsing of vector keyword in presence of conflicting uses.

2021-05-20 Thread Zarko Todorovski via Phabricator via cfe-commits
ZarkoCA added inline comments.



Comment at: clang/test/Parser/altivec-non-type-vector.c:1-24
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple 
powerpc64-ibm-aix
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple 
powerpc64-ibm-aix-xcoff
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple 
powerpc64le-ibm-linux-gnu
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple 
powerpc64le-linux-unknown
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple 
powerpc64le-unknown-linux
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple 
powerpc64le-unknown-linux-gnu
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple 
powerpc64le-unknown-unknown

Sorry, didn't mean to imply you needed all of these.  These should suffice. 


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

https://reviews.llvm.org/D100991

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


[clang] d74b663 - Fix LIT failure on native aix

2021-05-20 Thread Xiangling Liao via cfe-commits

Author: Xiangling Liao
Date: 2021-05-20T09:38:52-04:00
New Revision: d74b6635ef38d123793f025a2ea1ef28153d803a

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

LOG: Fix LIT failure on native aix

On AIX, char bitfields have the same alignment as unsigned int.
Reference: https://reviews.llvm.org/D87029

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

Added: 


Modified: 
clang/test/Sema/struct-packed-align.c

Removed: 




diff  --git a/clang/test/Sema/struct-packed-align.c 
b/clang/test/Sema/struct-packed-align.c
index 122b7f2764612..b4bddebe230e2 100644
--- a/clang/test/Sema/struct-packed-align.c
+++ b/clang/test/Sema/struct-packed-align.c
@@ -146,18 +146,17 @@ extern int n2[__alignof(struct nS) == 1 ? 1 : -1];
 // GCC 4.4 but the change can lead to 
diff erences in the structure layout.
 // See the documentation of -Wpacked-bitfield-compat for more information.
 struct packed_chars {
-  char a:4;
+  char a : 8, b : 8, c : 8, d : 4;
 #ifdef __ORBIS__
   // Test for pre-r254596 clang behavior on the PS4 target. PS4 must maintain
   // ABI backwards compatibility.
-  char b:8 __attribute__ ((packed));
+  char e : 8 __attribute__((packed));
   // expected-warning@-1 {{'packed' attribute ignored for field of type 
'char'}}
-  char c:4;
 #else
-  char b:8 __attribute__ ((packed));
+  char e : 8 __attribute__((packed));
   // expected-warning@-1 {{'packed' attribute was ignored on bit-fields with 
single-byte alignment in older versions of GCC and Clang}}
-  char c:4;
 #endif
+  char f : 4, g : 8, h : 8, i : 8;
 };
 
 #if (defined(_WIN32) || defined(__ORBIS__)) && !defined(__declspec) // 
_MSC_VER is unavailable in cc1.
@@ -165,9 +164,13 @@ struct packed_chars {
 //
 // Additionally, test for pre-r254596 clang behavior on the PS4 target. PS4
 // must maintain ABI backwards compatibility.
-extern int o1[sizeof(struct packed_chars) == 3 ? 1 : -1];
+extern int o1[sizeof(struct packed_chars) == 9 ? 1 : -1];
 extern int o2[__alignof(struct packed_chars) == 1 ? 1 : -1];
+#elif defined(_AIX)
+// On AIX, char bitfields have the same alignment as unsigned int.
+extern int o1[sizeof(struct packed_chars) == 8 ? 1 : -1];
+extern int o2[__alignof(struct packed_chars) == 4 ? 1 : -1];
 #else
-extern int o1[sizeof(struct packed_chars) == 2 ? 1 : -1];
+extern int o1[sizeof(struct packed_chars) == 8 ? 1 : -1];
 extern int o2[__alignof(struct packed_chars) == 1 ? 1 : -1];
 #endif



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


[PATCH] D102715: Fix LIT failure on native aix

2021-05-20 Thread Xiangling Liao via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGd74b6635ef38: Fix LIT failure on native aix (authored by 
Xiangling_L).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102715

Files:
  clang/test/Sema/struct-packed-align.c


Index: clang/test/Sema/struct-packed-align.c
===
--- clang/test/Sema/struct-packed-align.c
+++ clang/test/Sema/struct-packed-align.c
@@ -146,18 +146,17 @@
 // GCC 4.4 but the change can lead to differences in the structure layout.
 // See the documentation of -Wpacked-bitfield-compat for more information.
 struct packed_chars {
-  char a:4;
+  char a : 8, b : 8, c : 8, d : 4;
 #ifdef __ORBIS__
   // Test for pre-r254596 clang behavior on the PS4 target. PS4 must maintain
   // ABI backwards compatibility.
-  char b:8 __attribute__ ((packed));
+  char e : 8 __attribute__((packed));
   // expected-warning@-1 {{'packed' attribute ignored for field of type 
'char'}}
-  char c:4;
 #else
-  char b:8 __attribute__ ((packed));
+  char e : 8 __attribute__((packed));
   // expected-warning@-1 {{'packed' attribute was ignored on bit-fields with 
single-byte alignment in older versions of GCC and Clang}}
-  char c:4;
 #endif
+  char f : 4, g : 8, h : 8, i : 8;
 };
 
 #if (defined(_WIN32) || defined(__ORBIS__)) && !defined(__declspec) // 
_MSC_VER is unavailable in cc1.
@@ -165,9 +164,13 @@
 //
 // Additionally, test for pre-r254596 clang behavior on the PS4 target. PS4
 // must maintain ABI backwards compatibility.
-extern int o1[sizeof(struct packed_chars) == 3 ? 1 : -1];
+extern int o1[sizeof(struct packed_chars) == 9 ? 1 : -1];
 extern int o2[__alignof(struct packed_chars) == 1 ? 1 : -1];
+#elif defined(_AIX)
+// On AIX, char bitfields have the same alignment as unsigned int.
+extern int o1[sizeof(struct packed_chars) == 8 ? 1 : -1];
+extern int o2[__alignof(struct packed_chars) == 4 ? 1 : -1];
 #else
-extern int o1[sizeof(struct packed_chars) == 2 ? 1 : -1];
+extern int o1[sizeof(struct packed_chars) == 8 ? 1 : -1];
 extern int o2[__alignof(struct packed_chars) == 1 ? 1 : -1];
 #endif


Index: clang/test/Sema/struct-packed-align.c
===
--- clang/test/Sema/struct-packed-align.c
+++ clang/test/Sema/struct-packed-align.c
@@ -146,18 +146,17 @@
 // GCC 4.4 but the change can lead to differences in the structure layout.
 // See the documentation of -Wpacked-bitfield-compat for more information.
 struct packed_chars {
-  char a:4;
+  char a : 8, b : 8, c : 8, d : 4;
 #ifdef __ORBIS__
   // Test for pre-r254596 clang behavior on the PS4 target. PS4 must maintain
   // ABI backwards compatibility.
-  char b:8 __attribute__ ((packed));
+  char e : 8 __attribute__((packed));
   // expected-warning@-1 {{'packed' attribute ignored for field of type 'char'}}
-  char c:4;
 #else
-  char b:8 __attribute__ ((packed));
+  char e : 8 __attribute__((packed));
   // expected-warning@-1 {{'packed' attribute was ignored on bit-fields with single-byte alignment in older versions of GCC and Clang}}
-  char c:4;
 #endif
+  char f : 4, g : 8, h : 8, i : 8;
 };
 
 #if (defined(_WIN32) || defined(__ORBIS__)) && !defined(__declspec) // _MSC_VER is unavailable in cc1.
@@ -165,9 +164,13 @@
 //
 // Additionally, test for pre-r254596 clang behavior on the PS4 target. PS4
 // must maintain ABI backwards compatibility.
-extern int o1[sizeof(struct packed_chars) == 3 ? 1 : -1];
+extern int o1[sizeof(struct packed_chars) == 9 ? 1 : -1];
 extern int o2[__alignof(struct packed_chars) == 1 ? 1 : -1];
+#elif defined(_AIX)
+// On AIX, char bitfields have the same alignment as unsigned int.
+extern int o1[sizeof(struct packed_chars) == 8 ? 1 : -1];
+extern int o2[__alignof(struct packed_chars) == 4 ? 1 : -1];
 #else
-extern int o1[sizeof(struct packed_chars) == 2 ? 1 : -1];
+extern int o1[sizeof(struct packed_chars) == 8 ? 1 : -1];
 extern int o2[__alignof(struct packed_chars) == 1 ? 1 : -1];
 #endif
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] fa6e87c - [TableGen] [Clang] Clean up arm_mve.td file.

2021-05-20 Thread Paul C. Anagnostopoulos via cfe-commits

Author: Paul C. Anagnostopoulos
Date: 2021-05-20T09:39:57-04:00
New Revision: fa6e87cc5a21f885a4f6d0c7a51ad0f40022f5c8

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

LOG: [TableGen] [Clang] Clean up arm_mve.td file.

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

Added: 


Modified: 
clang/include/clang/Basic/arm_mve.td

Removed: 




diff  --git a/clang/include/clang/Basic/arm_mve.td 
b/clang/include/clang/Basic/arm_mve.td
index 55c2fbe7f021..52185ca07da4 100644
--- a/clang/include/clang/Basic/arm_mve.td
+++ b/clang/include/clang/Basic/arm_mve.td
@@ -575,7 +575,7 @@ defm vmaxnmavq: Reduction;
 }
 
 foreach half = [ "b", "t" ] in {
-  defvar halfconst = !if(!eq(half, "b"), 0, 1);
+  defvar halfconst = !ne(half, "b");
 
   let params = [f32], pnt = PNT_None in {
 def vcvt#half#q_f16: Intrinsic<
@@ -1153,8 +1153,7 @@ defm vshlltq : vshll_imm<1>;
 
 multiclass DyadicImmShift {
-  defvar intparams = !if(!eq(!cast(outtype), !cast(Vector)),
- [Vector], [outtype, Vector]);
+  defvar intparams = !if(!eq(outtype, Vector), [Vector], [outtype, Vector]);
 
   def q_n: Intrinsic<
   outtype, (args outtype:$a, Vector:$b, imm:$sh),
@@ -1529,12 +1528,7 @@ let params = T.Usual in {
 foreach desttype = T.All in {
   // We want a vreinterpretq between every pair of supported vector types
   // _except_ that there shouldn't be one from a type to itself.
-  //
-  // So this foldl expression implements what you'd write in Python as
-  // [srctype for srctype in T.All if srctype != desttype]
-  let params = !foldl([], T.All, tlist, srctype, !listconcat(tlist,
-  !if(!eq(!cast(desttype),!cast(srctype)),[],[srctype])))
-  in {
+  let params = !filter(srctype, T.All, !ne(srctype, desttype)) in {
 def "vreinterpretq_" # desttype: Intrinsic<
 VecOf, (args Vector:$x), (vreinterpret $x, VecOf)>;
   }
@@ -1576,8 +1570,9 @@ foreach desttype = !listconcat(T.Int16, T.Int32, T.Float) 
in {
   defvar is_dest_float = !eq(desttype.kind, "f");
   defvar is_dest_unsigned = !eq(desttype.kind, "u");
   // First immediate operand of the LLVM intrinsic
-  defvar unsigned_flag = !if(is_dest_float, (unsignedflag Scalar),
- !if(is_dest_unsigned, V.True, V.False));
+  defvar unsigned_flag = !cond(is_dest_float: (unsignedflag Scalar),
+   is_dest_unsigned: V.True,
+   true: V.False);
   // For float->int conversions _n and _x_n intrinsics are not polymorphic
   // because the signedness of the destination type cannot be inferred.
   defvar pnt_nx = !if(is_dest_float, PNT_2Type, PNT_None);



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


[PATCH] D102238: [TableGen] [Clang] Clean up arm_mve.td file

2021-05-20 Thread Paul C. Anagnostopoulos 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 rGfa6e87cc5a21: [TableGen] [Clang] Clean up arm_mve.td file. 
(authored by Paul-C-Anagnostopoulos).

Changed prior to commit:
  https://reviews.llvm.org/D102238?vs=344810&id=346712#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102238

Files:
  clang/include/clang/Basic/arm_mve.td


Index: clang/include/clang/Basic/arm_mve.td
===
--- clang/include/clang/Basic/arm_mve.td
+++ clang/include/clang/Basic/arm_mve.td
@@ -575,7 +575,7 @@
 }
 
 foreach half = [ "b", "t" ] in {
-  defvar halfconst = !if(!eq(half, "b"), 0, 1);
+  defvar halfconst = !ne(half, "b");
 
   let params = [f32], pnt = PNT_None in {
 def vcvt#half#q_f16: Intrinsic<
@@ -1153,8 +1153,7 @@
 
 multiclass DyadicImmShift {
-  defvar intparams = !if(!eq(!cast(outtype), !cast(Vector)),
- [Vector], [outtype, Vector]);
+  defvar intparams = !if(!eq(outtype, Vector), [Vector], [outtype, Vector]);
 
   def q_n: Intrinsic<
   outtype, (args outtype:$a, Vector:$b, imm:$sh),
@@ -1529,12 +1528,7 @@
 foreach desttype = T.All in {
   // We want a vreinterpretq between every pair of supported vector types
   // _except_ that there shouldn't be one from a type to itself.
-  //
-  // So this foldl expression implements what you'd write in Python as
-  // [srctype for srctype in T.All if srctype != desttype]
-  let params = !foldl([], T.All, tlist, srctype, !listconcat(tlist,
-  !if(!eq(!cast(desttype),!cast(srctype)),[],[srctype])))
-  in {
+  let params = !filter(srctype, T.All, !ne(srctype, desttype)) in {
 def "vreinterpretq_" # desttype: Intrinsic<
 VecOf, (args Vector:$x), (vreinterpret $x, VecOf)>;
   }
@@ -1576,8 +1570,9 @@
   defvar is_dest_float = !eq(desttype.kind, "f");
   defvar is_dest_unsigned = !eq(desttype.kind, "u");
   // First immediate operand of the LLVM intrinsic
-  defvar unsigned_flag = !if(is_dest_float, (unsignedflag Scalar),
- !if(is_dest_unsigned, V.True, V.False));
+  defvar unsigned_flag = !cond(is_dest_float: (unsignedflag Scalar),
+   is_dest_unsigned: V.True,
+   true: V.False);
   // For float->int conversions _n and _x_n intrinsics are not polymorphic
   // because the signedness of the destination type cannot be inferred.
   defvar pnt_nx = !if(is_dest_float, PNT_2Type, PNT_None);


Index: clang/include/clang/Basic/arm_mve.td
===
--- clang/include/clang/Basic/arm_mve.td
+++ clang/include/clang/Basic/arm_mve.td
@@ -575,7 +575,7 @@
 }
 
 foreach half = [ "b", "t" ] in {
-  defvar halfconst = !if(!eq(half, "b"), 0, 1);
+  defvar halfconst = !ne(half, "b");
 
   let params = [f32], pnt = PNT_None in {
 def vcvt#half#q_f16: Intrinsic<
@@ -1153,8 +1153,7 @@
 
 multiclass DyadicImmShift {
-  defvar intparams = !if(!eq(!cast(outtype), !cast(Vector)),
- [Vector], [outtype, Vector]);
+  defvar intparams = !if(!eq(outtype, Vector), [Vector], [outtype, Vector]);
 
   def q_n: Intrinsic<
   outtype, (args outtype:$a, Vector:$b, imm:$sh),
@@ -1529,12 +1528,7 @@
 foreach desttype = T.All in {
   // We want a vreinterpretq between every pair of supported vector types
   // _except_ that there shouldn't be one from a type to itself.
-  //
-  // So this foldl expression implements what you'd write in Python as
-  // [srctype for srctype in T.All if srctype != desttype]
-  let params = !foldl([], T.All, tlist, srctype, !listconcat(tlist,
-  !if(!eq(!cast(desttype),!cast(srctype)),[],[srctype])))
-  in {
+  let params = !filter(srctype, T.All, !ne(srctype, desttype)) in {
 def "vreinterpretq_" # desttype: Intrinsic<
 VecOf, (args Vector:$x), (vreinterpret $x, VecOf)>;
   }
@@ -1576,8 +1570,9 @@
   defvar is_dest_float = !eq(desttype.kind, "f");
   defvar is_dest_unsigned = !eq(desttype.kind, "u");
   // First immediate operand of the LLVM intrinsic
-  defvar unsigned_flag = !if(is_dest_float, (unsignedflag Scalar),
- !if(is_dest_unsigned, V.True, V.False));
+  defvar unsigned_flag = !cond(is_dest_float: (unsignedflag Scalar),
+   is_dest_unsigned: V.True,
+   true: V.False);
   // For float->int conversions _n and _x_n intrinsics are not polymorphic
   // because the signedness of the destination type cannot be inferred.
   defvar pnt_nx = !if(is_dest_float, PNT_2Type, PNT_None);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 603818b - [test] Fix pre-ra-sched.c to check for error message from stderr

2021-05-20 Thread Hubert Tong via cfe-commits

Author: Hubert Tong
Date: 2021-05-20T09:51:21-04:00
New Revision: 603818b97c795114f66a6fc13e8a5f0e54b49a13

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

LOG: [test] Fix pre-ra-sched.c to check for error message from stderr

The test previous accidentally passed because it was looking for a lack
of specific input from the binary(!) output being sent to stdout.

Added: 


Modified: 
clang/test/CodeGen/pre-ra-sched.c

Removed: 




diff  --git a/clang/test/CodeGen/pre-ra-sched.c 
b/clang/test/CodeGen/pre-ra-sched.c
index 3bd7594a5db9..376e5641b63b 100644
--- a/clang/test/CodeGen/pre-ra-sched.c
+++ b/clang/test/CodeGen/pre-ra-sched.c
@@ -1,4 +1,4 @@
-// RUN: %clang %s -mllvm -pre-RA-sched=fast -c -o - | FileCheck %s
-// RUN: %clang %s -mllvm -pre-RA-sched=linearize -c -o - | FileCheck %s
+// RUN: %clang %s -mllvm -pre-RA-sched=fast -c -o %t-fast.o 2>&1 | FileCheck 
--allow-empty %s
+// RUN: %clang %s -mllvm -pre-RA-sched=linearize -c -o %t-linearize.o 2>&1 | 
FileCheck --allow-empty %s
 
 // CHECK-NOT: clang (LLVM option parsing): for the --pre-RA-sched option: 
Cannot find option named



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


[PATCH] D101601: [SelectionDAG] Make fast and linearize visible by clang -pre-RA-sched

2021-05-20 Thread Hubert Tong via Phabricator via cfe-commits
hubert.reinterpretcast added inline comments.



Comment at: clang/test/CodeGen/pre-ra-sched.c:1-2
+// RUN: %clang %s -mllvm -pre-RA-sched=fast -c -o - | FileCheck %s
+// RUN: %clang %s -mllvm -pre-RA-sched=linearize -c -o - | FileCheck %s
+

hubert.reinterpretcast wrote:
> The test as was committed is bogus. It checks the output binary(!) stream for 
> an error message when stderr was not even redirected. Please fix.
Fix committed: 
https://github.com/llvm/llvm-project/commit/603818b97c795114f66a6fc13e8a5f0e54b49a13


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101601

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


[PATCH] D102791: [WebAssembly] Warn on exception spec for Emscripten EH

2021-05-20 Thread Alon Zakai via Phabricator via cfe-commits
kripken accepted this revision.
kripken added a comment.
This revision is now accepted and ready to land.

I'm not very familiar with this code, but it looks right, and sgtm to add a 
warning here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102791

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


[PATCH] D100991: Fix parsing of vector keyword in presence of conflicting uses.

2021-05-20 Thread Jamie Schmeiser via Phabricator via cfe-commits
jamieschmeiser updated this revision to Diff 346722.
jamieschmeiser added a comment.

Remove unnecessary tests.


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

https://reviews.llvm.org/D100991

Files:
  clang/lib/Parse/Parser.cpp
  clang/test/Parser/altivec-non-type-vector.c
  clang/test/Parser/altivec-template-vector.cpp
  clang/test/Parser/altivec-typedef-vector.c


Index: clang/test/Parser/altivec-typedef-vector.c
===
--- /dev/null
+++ clang/test/Parser/altivec-typedef-vector.c
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple 
powerpc64-ibm-aix-xcoff
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple 
powerpc64le-ibm-linux-gnu
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple 
powerpc64-linux-gnu
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple 
powerpc-ibm-aix-xcoff
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple 
powerpc-linux-gnu
+
+typedef int vector;
+
+void test() {
+  vector unsigned int v = {0};
+}
Index: clang/test/Parser/altivec-template-vector.cpp
===
--- /dev/null
+++ clang/test/Parser/altivec-template-vector.cpp
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple 
powerpc64-ibm-aix-xcoff
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple 
powerpc64le-ibm-linux-gnu
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple 
powerpc64-linux-gnu
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple 
powerpc-ibm-aix-xcoff
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple 
powerpc-linux-gnu
+
+template  class vector {
+public:
+  vector(int) {}
+};
+
+void f() {
+  vector int v = {0};
+  vector vi = {0};
+}
Index: clang/test/Parser/altivec-non-type-vector.c
===
--- /dev/null
+++ clang/test/Parser/altivec-non-type-vector.c
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple 
powerpc64-ibm-aix-xcoff
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple 
powerpc64le-ibm-linux-gnu
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple 
powerpc64-linux-gnu
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple 
powerpc-ibm-aix-xcoff
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple 
powerpc-linux-gnu
+
+int vector();
+
+void test() {
+  vector unsigned int v = {0};
+}
Index: clang/lib/Parse/Parser.cpp
===
--- clang/lib/Parse/Parser.cpp
+++ clang/lib/Parse/Parser.cpp
@@ -1695,6 +1695,11 @@
 break;
 
   case Sema::NC_Type: {
+if (TryAltiVecVectorToken())
+  // vector has been found as a type id when altivec is enabled but
+  // this is followed by a declaration specifier so this is really the
+  // altivec vector token.  Leave it unannotated.
+  break;
 SourceLocation BeginLoc = NameLoc;
 if (SS.isNotEmpty())
   BeginLoc = SS.getBeginLoc();
@@ -1736,6 +1741,11 @@
 return ANK_Success;
 
   case Sema::NC_NonType:
+if (TryAltiVecVectorToken())
+  // vector has been found as a non-type id when altivec is enabled but
+  // this is followed by a declaration specifier so this is really the
+  // altivec vector token.  Leave it unannotated.
+  break;
 Tok.setKind(tok::annot_non_type);
 setNonTypeAnnotation(Tok, Classification.getNonTypeDecl());
 Tok.setLocation(NameLoc);


Index: clang/test/Parser/altivec-typedef-vector.c
===
--- /dev/null
+++ clang/test/Parser/altivec-typedef-vector.c
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple powerpc64-ibm-aix-xcoff
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple powerpc64le-ibm-linux-gnu
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple powerpc64-linux-gnu
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple powerpc-ibm-aix-xcoff
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple powerpc-linux-gnu
+
+typedef int vector;
+
+void test() {
+  vector unsigned int v = {0};
+}
Index: clang/test/Parser/altivec-template-vector.cpp
===
--- /dev/null
+++ clang/test/Parser/altivec-template-vector.cpp
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple powerpc64-ibm-aix-xcoff
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple powerpc64le-ibm-linux-gnu
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple powerpc64-linux-gnu
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple powerpc-ibm-aix-xcoff

[clang] a5c2ec9 - [AST] Store regular ValueDecl* in BindingDecl (NFC)

2021-05-20 Thread Aaron Puchert via cfe-commits

Author: Aaron Puchert
Date: 2021-05-20T16:28:58+02:00
New Revision: a5c2ec96e5f9f14b31b705e40bcb267257612316

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

LOG: [AST] Store regular ValueDecl* in BindingDecl (NFC)

We were always storing a regular ValueDecl* as decomposition declaration
and haven't been using the opportunity to initialize it lazily.

Reviewed By: aaron.ballman

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

Added: 


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

Removed: 




diff  --git a/clang/include/clang/AST/DeclCXX.h 
b/clang/include/clang/AST/DeclCXX.h
index c3c326b50397..07c4eb261aac 100644
--- a/clang/include/clang/AST/DeclCXX.h
+++ b/clang/include/clang/AST/DeclCXX.h
@@ -3827,7 +3827,7 @@ class StaticAssertDecl : public Decl {
 /// DecompositionDecl of type 'int (&)[3]'.
 class BindingDecl : public ValueDecl {
   /// The declaration that this binding binds to part of.
-  LazyDeclPtr Decomp;
+  ValueDecl *Decomp;
   /// The binding represented by this declaration. References to this
   /// declaration are effectively equivalent to this expression (except
   /// that it is only evaluated once at the point of declaration of the
@@ -3853,7 +3853,7 @@ class BindingDecl : public ValueDecl {
 
   /// Get the decomposition declaration that this binding represents a
   /// decomposition of.
-  ValueDecl *getDecomposedDecl() const;
+  ValueDecl *getDecomposedDecl() const { return Decomp; }
 
   /// Get the variable (if any) that holds the value of evaluating the binding.
   /// Only present for user-defined bindings for tuple-like types.

diff  --git a/clang/lib/AST/DeclCXX.cpp b/clang/lib/AST/DeclCXX.cpp
index 3d1faee0ab11..2bb7acc21a93 100644
--- a/clang/lib/AST/DeclCXX.cpp
+++ b/clang/lib/AST/DeclCXX.cpp
@@ -3179,12 +3179,6 @@ BindingDecl *BindingDecl::CreateDeserialized(ASTContext 
&C, unsigned ID) {
   return new (C, ID) BindingDecl(nullptr, SourceLocation(), nullptr);
 }
 
-ValueDecl *BindingDecl::getDecomposedDecl() const {
-  ExternalASTSource *Source =
-  Decomp.isOffset() ? getASTContext().getExternalSource() : nullptr;
-  return cast_or_null(Decomp.get(Source));
-}
-
 VarDecl *BindingDecl::getHoldingVar() const {
   Expr *B = getBinding();
   if (!B)



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


[PATCH] D99455: [AST] Store regular ValueDecl* in BindingDecl

2021-05-20 Thread Aaron Puchert 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 rGa5c2ec96e5f9: [AST] Store regular ValueDecl* in BindingDecl 
(NFC) (authored by aaronpuchert).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99455

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


Index: clang/lib/AST/DeclCXX.cpp
===
--- clang/lib/AST/DeclCXX.cpp
+++ clang/lib/AST/DeclCXX.cpp
@@ -3179,12 +3179,6 @@
   return new (C, ID) BindingDecl(nullptr, SourceLocation(), nullptr);
 }
 
-ValueDecl *BindingDecl::getDecomposedDecl() const {
-  ExternalASTSource *Source =
-  Decomp.isOffset() ? getASTContext().getExternalSource() : nullptr;
-  return cast_or_null(Decomp.get(Source));
-}
-
 VarDecl *BindingDecl::getHoldingVar() const {
   Expr *B = getBinding();
   if (!B)
Index: clang/include/clang/AST/DeclCXX.h
===
--- clang/include/clang/AST/DeclCXX.h
+++ clang/include/clang/AST/DeclCXX.h
@@ -3827,7 +3827,7 @@
 /// DecompositionDecl of type 'int (&)[3]'.
 class BindingDecl : public ValueDecl {
   /// The declaration that this binding binds to part of.
-  LazyDeclPtr Decomp;
+  ValueDecl *Decomp;
   /// The binding represented by this declaration. References to this
   /// declaration are effectively equivalent to this expression (except
   /// that it is only evaluated once at the point of declaration of the
@@ -3853,7 +3853,7 @@
 
   /// Get the decomposition declaration that this binding represents a
   /// decomposition of.
-  ValueDecl *getDecomposedDecl() const;
+  ValueDecl *getDecomposedDecl() const { return Decomp; }
 
   /// Get the variable (if any) that holds the value of evaluating the binding.
   /// Only present for user-defined bindings for tuple-like types.


Index: clang/lib/AST/DeclCXX.cpp
===
--- clang/lib/AST/DeclCXX.cpp
+++ clang/lib/AST/DeclCXX.cpp
@@ -3179,12 +3179,6 @@
   return new (C, ID) BindingDecl(nullptr, SourceLocation(), nullptr);
 }
 
-ValueDecl *BindingDecl::getDecomposedDecl() const {
-  ExternalASTSource *Source =
-  Decomp.isOffset() ? getASTContext().getExternalSource() : nullptr;
-  return cast_or_null(Decomp.get(Source));
-}
-
 VarDecl *BindingDecl::getHoldingVar() const {
   Expr *B = getBinding();
   if (!B)
Index: clang/include/clang/AST/DeclCXX.h
===
--- clang/include/clang/AST/DeclCXX.h
+++ clang/include/clang/AST/DeclCXX.h
@@ -3827,7 +3827,7 @@
 /// DecompositionDecl of type 'int (&)[3]'.
 class BindingDecl : public ValueDecl {
   /// The declaration that this binding binds to part of.
-  LazyDeclPtr Decomp;
+  ValueDecl *Decomp;
   /// The binding represented by this declaration. References to this
   /// declaration are effectively equivalent to this expression (except
   /// that it is only evaluated once at the point of declaration of the
@@ -3853,7 +3853,7 @@
 
   /// Get the decomposition declaration that this binding represents a
   /// decomposition of.
-  ValueDecl *getDecomposedDecl() const;
+  ValueDecl *getDecomposedDecl() const { return Decomp; }
 
   /// Get the variable (if any) that holds the value of evaluating the binding.
   /// Only present for user-defined bindings for tuple-like types.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D102479: [clang][driver] Treat unkonwn -flto= values as -flto

2021-05-20 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 346737.
tbaeder added a comment.

Use `hasFlag()` instead of `hasArg()` in Driver.cpp


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

https://reviews.llvm.org/D102479

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/lto.c


Index: clang/test/Driver/lto.c
===
--- clang/test/Driver/lto.c
+++ clang/test/Driver/lto.c
@@ -77,3 +77,11 @@
 //
 // CHECK-TUNING-LLDB:   "-plugin-opt=-debugger-tune=lldb"
 // CHECK-NO-TUNING-NOT: "-plugin-opt=-debugger-tune
+//
+// -flto=auto and -flto=jobserver pass along -flto=full
+// RUN: %clang -target x86_64-unknown-linux -### %s -flto=auto 2>&1 | 
FileCheck --check-prefix=FLTO-AUTO %s
+// RUN: %clang -target x86_64-unknown-linux -### %s -flto=jobserver 2>&1 | 
FileCheck --check-prefix=FLTO-JOBSERVER %s
+//
+// FLTO-AUTO: -flto=full
+// FLTO-JOBSERVER: -flto=full
+//
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -4454,7 +4454,14 @@
JA.isDeviceOffloading(Action::OFK_Host));
 
 if (D.isUsingLTO() && !isDeviceOffloadAction) {
-  Args.AddLastArg(CmdArgs, options::OPT_flto, options::OPT_flto_EQ);
+  if (Args.hasArg(options::OPT_flto))
+CmdArgs.push_back("-flto");
+  else {
+if (D.getLTOMode() == LTOK_Thin)
+  CmdArgs.push_back("-flto=thin");
+else
+  CmdArgs.push_back("-flto=full");
+  }
   CmdArgs.push_back("-flto-unit");
 }
   }
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -598,7 +598,10 @@
 void Driver::setLTOMode(const llvm::opt::ArgList &Args) {
   LTOMode = LTOK_None;
   if (!Args.hasFlag(options::OPT_flto, options::OPT_flto_EQ,
-options::OPT_fno_lto, false))
+options::OPT_fno_lto, false) &&
+  !Args.hasFlag(options::OPT_flto_EQ_auto, options::OPT_fno_lto, false) &&
+  !Args.hasFlag(options::OPT_flto_EQ_jobserver, options::OPT_fno_lto,
+false))
 return;
 
   StringRef LTOName("full");
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -1958,6 +1958,8 @@
   HelpText<"Force linking the clang builtins runtime library">;
 def flto_EQ : Joined<["-"], "flto=">, Flags<[CoreOption, CC1Option]>, 
Group,
   HelpText<"Set LTO mode to either 'full' or 'thin'">, Values<"thin,full">;
+def flto_EQ_jobserver : Flag<["-"], "flto=jobserver">, Group;
+def flto_EQ_auto : Flag<["-"], "flto=auto">, Group;
 def flto : Flag<["-"], "flto">, Flags<[CoreOption, CC1Option]>, Group,
   HelpText<"Enable LTO in 'full' mode">;
 def fno_lto : Flag<["-"], "fno-lto">, Flags<[CoreOption, CC1Option]>, 
Group,
@@ -4252,8 +4254,6 @@
 defm branch_count_reg : BooleanFFlag<"branch-count-reg">, 
Group;
 defm default_inline : BooleanFFlag<"default-inline">, 
Group;
 defm fat_lto_objects : BooleanFFlag<"fat-lto-objects">, 
Group;
-def : Flag<["-"], "flto=auto">, Group;
-def : Flag<["-"], "flto=jobserver">, 
Group;
 defm float_store : BooleanFFlag<"float-store">, 
Group;
 defm friend_injection : BooleanFFlag<"friend-injection">, 
Group;
 defm function_attribute_list : BooleanFFlag<"function-attribute-list">, 
Group;


Index: clang/test/Driver/lto.c
===
--- clang/test/Driver/lto.c
+++ clang/test/Driver/lto.c
@@ -77,3 +77,11 @@
 //
 // CHECK-TUNING-LLDB:   "-plugin-opt=-debugger-tune=lldb"
 // CHECK-NO-TUNING-NOT: "-plugin-opt=-debugger-tune
+//
+// -flto=auto and -flto=jobserver pass along -flto=full
+// RUN: %clang -target x86_64-unknown-linux -### %s -flto=auto 2>&1 | FileCheck --check-prefix=FLTO-AUTO %s
+// RUN: %clang -target x86_64-unknown-linux -### %s -flto=jobserver 2>&1 | FileCheck --check-prefix=FLTO-JOBSERVER %s
+//
+// FLTO-AUTO: -flto=full
+// FLTO-JOBSERVER: -flto=full
+//
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -4454,7 +4454,14 @@
JA.isDeviceOffloading(Action::OFK_Host));
 
 if (D.isUsingLTO() && !isDeviceOffloadAction) {
-  Args.AddLastArg(CmdArgs, options::OPT_flto, options::OPT_flto_EQ);
+  if (Args.hasArg(options::OPT_flto))
+CmdArgs.push_back("-flto");
+  else {
+if (D.getLTOMode() == LTOK_Thin)
+  CmdArgs.push_back("-flto=thin");
+else
+  CmdArgs.push_back("-flto=full");
+  }
   CmdAr

[PATCH] D100991: Fix parsing of vector keyword in presence of conflicting uses.

2021-05-20 Thread Zarko Todorovski via Phabricator via cfe-commits
ZarkoCA accepted this revision.
ZarkoCA added a comment.
This revision is now accepted and ready to land.

LGTM, thanks.


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

https://reviews.llvm.org/D100991

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


[PATCH] D102689: [C++4OpenCL] Allow address space conversion in reinterpret_cast

2021-05-20 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added a comment.

Just to move the discussion from https://reviews.llvm.org/D101519 here. First 
of all I think this change should not be OpenCL specific i.e. there is not 
reason to do something different from  C++ in general.

Embedded C doesn't regulate the conversions between non-pointer types with 
different address spaces but in OpenCL C we have allowed them apparently 
https://godbolt.org/z/9f75zxj7v. I am not sure whether this was done 
intentionally or not.

However, in C there are no references and other features that might create 
problems.

At the same time it seems C++ allows casting away const 
https://godbolt.org/z/fo3axbq3e

But it contradicts the comment in the code:

> // C++ 5.2.10p2 has a note that mentions that, subject to all other
> // restrictions, a cast to the same type is allowed so long as it does not
> // cast away constness. In C++98, the intent was not entirely clear here,
> // since all other paragraphs explicitly forbid casts to the same type.
> // C++11 clarifies this case with p2.

I would like to see if @rjmccall  has any opinion on whether reinterpreting 
between non-pointer types with different address spaces is reasonable?

In general it makes sense to follow logic for other type qualifier here but I  
was thinking of whether we can allow something weird to be written by relaxing 
this for address spaces

  local int i;
  const global int & ii = reinterpret_cast(i);

I think this code is completely meaningless as it requires creating a temporary 
in global address space? I am not sure what we will even emit in IR?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102689

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


[clang] 801ab71 - [ARM][AArch64] SLSHardening: make non-comdat thunks possible

2021-05-20 Thread Daniel Kiss via cfe-commits

Author: Daniel Kiss
Date: 2021-05-20T17:07:05+02:00
New Revision: 801ab71032e157eb7bcd38efeb6486742a7c53bb

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

LOG: [ARM][AArch64] SLSHardening: make non-comdat thunks possible

Linker scripts might not handle COMDAT sections. SLSHardeing adds
new section for each __llvm_slsblr_thunk_xN. This new option allows
the generation of the thunks into the normal text section to handle these
exceptional cases.
,comdat or ,noncomdat can be added to harden-sls to control the codegen.
-mharden-sls=[all|retbr|blr],nocomdat.

Reviewed By: kristof.beyls

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

Added: 


Modified: 
clang/lib/Driver/ToolChains/Arch/AArch64.cpp
clang/lib/Driver/ToolChains/Arch/ARM.cpp
clang/test/Driver/sls-hardening-options.c
llvm/include/llvm/CodeGen/IndirectThunks.h
llvm/lib/Target/AArch64/AArch64.td
llvm/lib/Target/AArch64/AArch64SLSHardening.cpp
llvm/lib/Target/AArch64/AArch64Subtarget.h
llvm/lib/Target/ARM/ARM.td
llvm/lib/Target/ARM/ARMSLSHardening.cpp
llvm/lib/Target/ARM/ARMSubtarget.h
llvm/test/CodeGen/AArch64/speculation-hardening-sls.ll
llvm/test/CodeGen/ARM/speculation-hardening-sls.ll

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Arch/AArch64.cpp 
b/clang/lib/Driver/ToolChains/Arch/AArch64.cpp
index 4ce797f9bc73..503685ab533a 100644
--- a/clang/lib/Driver/ToolChains/Arch/AArch64.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/AArch64.cpp
@@ -235,11 +235,17 @@ void aarch64::getAArch64TargetFeatures(const Driver &D,
 StringRef Scope = A->getValue();
 bool EnableRetBr = false;
 bool EnableBlr = false;
-if (Scope != "none" && Scope != "all") {
+bool DisableComdat = false;
+if (Scope != "none") {
   SmallVector Opts;
   Scope.split(Opts, ",");
   for (auto Opt : Opts) {
 Opt = Opt.trim();
+if (Opt == "all") {
+  EnableBlr = true;
+  EnableRetBr = true;
+  continue;
+}
 if (Opt == "retbr") {
   EnableRetBr = true;
   continue;
@@ -248,19 +254,27 @@ void aarch64::getAArch64TargetFeatures(const Driver &D,
   EnableBlr = true;
   continue;
 }
+if (Opt == "comdat") {
+  DisableComdat = false;
+  continue;
+}
+if (Opt == "nocomdat") {
+  DisableComdat = true;
+  continue;
+}
 D.Diag(diag::err_invalid_sls_hardening)
 << Scope << A->getAsString(Args);
 break;
   }
-} else if (Scope == "all") {
-  EnableRetBr = true;
-  EnableBlr = true;
 }
 
 if (EnableRetBr)
   Features.push_back("+harden-sls-retbr");
 if (EnableBlr)
   Features.push_back("+harden-sls-blr");
+if (DisableComdat) {
+  Features.push_back("+harden-sls-nocomdat");
+}
   }
 
   // En/disable crc

diff  --git a/clang/lib/Driver/ToolChains/Arch/ARM.cpp 
b/clang/lib/Driver/ToolChains/Arch/ARM.cpp
index 16d72e5367f5..4ab547fabe43 100644
--- a/clang/lib/Driver/ToolChains/Arch/ARM.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/ARM.cpp
@@ -796,11 +796,17 @@ void arm::getARMTargetFeatures(const Driver &D, const 
llvm::Triple &Triple,
 StringRef Scope = A->getValue();
 bool EnableRetBr = false;
 bool EnableBlr = false;
-if (Scope != "none" && Scope != "all") {
+bool DisableComdat = false;
+if (Scope != "none") {
   SmallVector Opts;
   Scope.split(Opts, ",");
   for (auto Opt : Opts) {
 Opt = Opt.trim();
+if (Opt == "all") {
+  EnableBlr = true;
+  EnableRetBr = true;
+  continue;
+}
 if (Opt == "retbr") {
   EnableRetBr = true;
   continue;
@@ -809,13 +815,18 @@ void arm::getARMTargetFeatures(const Driver &D, const 
llvm::Triple &Triple,
   EnableBlr = true;
   continue;
 }
+if (Opt == "comdat") {
+  DisableComdat = false;
+  continue;
+}
+if (Opt == "nocomdat") {
+  DisableComdat = true;
+  continue;
+}
 D.Diag(diag::err_invalid_sls_hardening)
 << Scope << A->getAsString(Args);
 break;
   }
-} else if (Scope == "all") {
-  EnableRetBr = true;
-  EnableBlr = true;
 }
 
 if (EnableRetBr || EnableBlr)
@@ -827,6 +838,9 @@ void arm::getARMTargetFeatures(const Driver &D, const 
llvm::Triple &Triple,
   Features.push_back("+harden-sls-retbr");
 if (EnableBlr)
   Features.push_back("+harden-sls-blr");
+if (DisableComdat) {
+  Features.push_back("+harden-sls-nocomdat");
+}
   }
 
 }

diff  --git a/clang/test/Driver/sls-hardening-options.c 
b/clang/test/Driver/sls-hardening-options.c
index c48b6

[PATCH] D100546: [ARM][AArch64] SLSHardening: make non-comdat thunks possible

2021-05-20 Thread Daniel Kiss via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
danielkiss marked an inline comment as done.
Closed by commit rG801ab71032e1: [ARM][AArch64] SLSHardening: make non-comdat 
thunks possible (authored by danielkiss).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100546

Files:
  clang/lib/Driver/ToolChains/Arch/AArch64.cpp
  clang/lib/Driver/ToolChains/Arch/ARM.cpp
  clang/test/Driver/sls-hardening-options.c
  llvm/include/llvm/CodeGen/IndirectThunks.h
  llvm/lib/Target/AArch64/AArch64.td
  llvm/lib/Target/AArch64/AArch64SLSHardening.cpp
  llvm/lib/Target/AArch64/AArch64Subtarget.h
  llvm/lib/Target/ARM/ARM.td
  llvm/lib/Target/ARM/ARMSLSHardening.cpp
  llvm/lib/Target/ARM/ARMSubtarget.h
  llvm/test/CodeGen/AArch64/speculation-hardening-sls.ll
  llvm/test/CodeGen/ARM/speculation-hardening-sls.ll

Index: llvm/test/CodeGen/ARM/speculation-hardening-sls.ll
===
--- llvm/test/CodeGen/ARM/speculation-hardening-sls.ll
+++ llvm/test/CodeGen/ARM/speculation-hardening-sls.ll
@@ -1,15 +1,23 @@
-; RUN: llc -mattr=harden-sls-retbr -mattr=harden-sls-blr -verify-machineinstrs -mtriple=armv8-linux-gnueabi < %s | FileCheck %s --check-prefixes=CHECK,ARM,HARDEN,ISBDSB -dump-input-context=100
-; RUN: llc -mattr=harden-sls-retbr -mattr=harden-sls-blr -verify-machineinstrs -mtriple=thumbv8-linux-gnueabi < %s | FileCheck %s --check-prefixes=CHECK,THUMB,HARDENTHUMB,HARDEN,ISBDSB -dump-input-context=100
-; RUN: llc -mattr=harden-sls-retbr -mattr=harden-sls-blr -mattr=+sb -verify-machineinstrs -mtriple=armv8-linux-gnueabi < %s | FileCheck %s --check-prefixes=CHECK,ARM,HARDEN,SB -dump-input-context=100
-; RUN: llc -mattr=harden-sls-retbr -mattr=harden-sls-blr -mattr=+sb -verify-machineinstrs -mtriple=thumbv8-linux-gnueabi < %s | FileCheck %s --check-prefixes=CHECK,THUMB,HARDENTHUMB,HARDEN,SB -dump-input-context=100
+; RUN: llc -mattr=harden-sls-retbr -mattr=harden-sls-blr -verify-machineinstrs -mtriple=armv8-linux-gnueabi < %s | FileCheck %s --check-prefixes=CHECK,ARM,HARDEN,HARDEN-COMDAT,ISBDSB -dump-input-context=100
+; RUN: llc -mattr=harden-sls-retbr -mattr=harden-sls-blr -verify-machineinstrs -mtriple=thumbv8-linux-gnueabi < %s | FileCheck %s --check-prefixes=CHECK,THUMB,HARDENTHUMB,HARDEN,HARDEN-COMDAT,ISBDSB -dump-input-context=100
+; RUN: llc -mattr=harden-sls-retbr -mattr=harden-sls-blr -mattr=+sb -verify-machineinstrs -mtriple=armv8-linux-gnueabi < %s | FileCheck %s --check-prefixes=CHECK,ARM,HARDEN,HARDEN-COMDAT,SB -dump-input-context=100
+; RUN: llc -mattr=harden-sls-retbr -mattr=harden-sls-blr -mattr=+sb -verify-machineinstrs -mtriple=thumbv8-linux-gnueabi < %s | FileCheck %s --check-prefixes=CHECK,THUMB,HARDENTHUMB,HARDEN,HARDEN-COMDAT,SB -dump-input-context=100
+; RUN: llc -mattr=harden-sls-retbr -mattr=harden-sls-blr -mattr=harden-sls-nocomdat -verify-machineinstrs -mtriple=armv8-linux-gnueabi < %s | FileCheck %s --check-prefixes=CHECK,ARM,HARDEN,HARDEN-COMDAT-OFF,ISBDSB -dump-input-context=100
+; RUN: llc -mattr=harden-sls-retbr -mattr=harden-sls-blr -mattr=harden-sls-nocomdat -verify-machineinstrs -mtriple=thumbv8-linux-gnueabi < %s | FileCheck %s --check-prefixes=CHECK,THUMB,HARDENTHUMB,HARDEN,HARDEN-COMDAT-OFF,ISBDSB -dump-input-context=100
+; RUN: llc -mattr=harden-sls-retbr -mattr=harden-sls-blr -mattr=harden-sls-nocomdat -mattr=+sb -verify-machineinstrs -mtriple=armv8-linux-gnueabi < %s | FileCheck %s --check-prefixes=CHECK,ARM,HARDEN,HARDEN-COMDAT-OFF,SB -dump-input-context=100
+; RUN: llc -mattr=harden-sls-retbr -mattr=harden-sls-blr -mattr=harden-sls-nocomdat -mattr=+sb -verify-machineinstrs -mtriple=thumbv8-linux-gnueabi < %s | FileCheck %s --check-prefixes=CHECK,THUMB,HARDENTHUMB,HARDEN,HARDEN-COMDAT-OFF,SB -dump-input-context=100
 ; RUN: llc -verify-machineinstrs -mtriple=armv8-linux-gnueabi < %s | FileCheck %s --check-prefixes=CHECK,ARM,NOHARDENARM -dump-input-context=100
 ; RUN: llc -verify-machineinstrs -mtriple=thumbv8-linux-gnueabi < %s | FileCheck %s --check-prefixes=CHECK,THUMB,NOHARDENTHUMB
-; RUN: llc -global-isel -global-isel-abort=0 -mattr=harden-sls-retbr -mattr=harden-sls-blr -verify-machineinstrs -mtriple=armv8-linux-gnueabi < %s | FileCheck %s --check-prefixes=CHECK,ARM,HARDEN,ISBDSB
-; RUN: llc -global-isel -global-isel-abort=0 -mattr=harden-sls-retbr -mattr=harden-sls-blr -verify-machineinstrs -mtriple=thumbv8-linux-gnueabi < %s | FileCheck %s --check-prefixes=CHECK,THUMB,HARDENTHUMB,HARDEN,ISBDSB
+; RUN: llc -global-isel -global-isel-abort=0 -mattr=harden-sls-retbr -mattr=harden-sls-blr -verify-machineinstrs -mtriple=armv8-linux-gnueabi < %s | FileCheck %s --check-prefixes=CHECK,ARM,HARDEN,HARDEN-COMDAT,ISBDSB
+; RUN: llc -global-isel -global-isel-abort=0 -mattr=harden-sls-retbr -mattr=harde

[clang] beb5a3a - Correct some thread safety analysis diagnostics; NFC.

2021-05-20 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2021-05-20T11:30:21-04:00
New Revision: beb5a3a298a1bb2687b421cb960d36a5e9b3ad43

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

LOG: Correct some thread safety analysis diagnostics; NFC.

The diagnostics were not following the usual style rules.

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/test/SemaCXX/warn-thread-safety-verbose.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 9dd9b1b5118b..fff6b62f3b7f 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3634,13 +3634,13 @@ def warn_fun_requires_lock_precise :
 def note_found_mutex_near_match : Note<"found near match '%0'">;
 
 // Verbose thread safety warnings
-def warn_thread_safety_verbose : Warning<"Thread safety verbose warning.">,
+def warn_thread_safety_verbose : Warning<"thread safety verbose warning">,
   InGroup, DefaultIgnore;
-def note_thread_warning_in_fun : Note<"Thread warning in function %0">;
-def note_guarded_by_declared_here : Note<"Guarded_by declared here.">;
+def note_thread_warning_in_fun : Note<"thread warning in function %0">;
+def note_guarded_by_declared_here : Note<"guarded_by declared here">;
 
 // Dummy warning that will trigger "beta" warnings from the analysis if 
enabled.
-def warn_thread_safety_beta : Warning<"Thread safety beta warning.">,
+def warn_thread_safety_beta : Warning<"thread safety beta warning">,
   InGroup, DefaultIgnore;
 
 // Consumed warnings

diff  --git a/clang/test/SemaCXX/warn-thread-safety-verbose.cpp 
b/clang/test/SemaCXX/warn-thread-safety-verbose.cpp
index 2f892cd1e175..e8b229f3373b 100644
--- a/clang/test/SemaCXX/warn-thread-safety-verbose.cpp
+++ b/clang/test/SemaCXX/warn-thread-safety-verbose.cpp
@@ -21,41 +21,41 @@ class LOCKABLE Mutex {
 
 class Test {
   Mutex mu;
-  int a GUARDED_BY(mu);  // expected-note3 {{Guarded_by declared here.}}
+  int a GUARDED_BY(mu);  // expected-note3 {{guarded_by declared here}}
 
   void foo1() EXCLUSIVE_LOCKS_REQUIRED(mu);
   void foo2() SHARED_LOCKS_REQUIRED(mu);
   void foo3() LOCKS_EXCLUDED(mu);
 
-  void test1() {  // expected-note {{Thread warning in function 'test1'}}
+  void test1() {  // expected-note {{thread warning in function 'test1'}}
 a = 0;// expected-warning {{writing variable 'a' requires holding 
mutex 'mu' exclusively}}
   }
 
-  void test2() {  // expected-note {{Thread warning in function 'test2'}}
+  void test2() {  // expected-note {{thread warning in function 'test2'}}
 int b = a;// expected-warning {{reading variable 'a' requires holding 
mutex 'mu'}}
   }
 
-  void test3() {  // expected-note {{Thread warning in function 'test3'}}
+  void test3() {  // expected-note {{thread warning in function 'test3'}}
 foo1();   // expected-warning {{calling function 'foo1' requires 
holding mutex 'mu' exclusively}}
   }
 
-  void test4() {  // expected-note {{Thread warning in function 'test4'}}
+  void test4() {  // expected-note {{thread warning in function 'test4'}}
 foo2();   // expected-warning {{calling function 'foo2' requires 
holding mutex 'mu'}}
   }
 
-  void test5() {  // expected-note {{Thread warning in function 'test5'}}
+  void test5() {  // expected-note {{thread warning in function 'test5'}}
 mu.ReaderLock();
 foo1();   // expected-warning {{calling function 'foo1' requires 
holding mutex 'mu' exclusively}}
 mu.Unlock();
   }
 
-  void test6() {  // expected-note {{Thread warning in function 'test6'}}
+  void test6() {  // expected-note {{thread warning in function 'test6'}}
 mu.ReaderLock();
 a = 0;// expected-warning {{writing variable 'a' requires holding 
mutex 'mu' exclusively}}
 mu.Unlock();
   }
 
-  void test7() {  // expected-note {{Thread warning in function 'test7'}}
+  void test7() {  // expected-note {{thread warning in function 'test7'}}
 mu.Lock();
 foo3();   // expected-warning {{cannot call function 'foo3' while 
mutex 'mu' is held}}
 mu.Unlock();



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


[PATCH] D98798: Produce warning for performing pointer arithmetic on a null pointer.

2021-05-20 Thread Jamie Schmeiser via Phabricator via cfe-commits
jamieschmeiser updated this revision to Diff 346751.
jamieschmeiser added a comment.

Fix formatting.


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

https://reviews.llvm.org/D98798

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Sema/Inputs/pointer-subtraction.h
  clang/test/Sema/pointer-subtraction.c
  clang/test/Sema/pointer-subtraction.cpp

Index: clang/test/Sema/pointer-subtraction.cpp
===
--- /dev/null
+++ clang/test/Sema/pointer-subtraction.cpp
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 %s -fsyntax-only -verify -pedantic -Wextra -std=c++11 -isystem %S/Inputs
+// RUN: %clang_cc1 %s -fsyntax-only -verify -pedantic -Wnull-pointer-subtraction -std=c++11 -isystem %S/Inputs
+// RUN: %clang_cc1 %s -fsyntax-only -verify -pedantic -Wextra -std=c++11 -isystem %S/Inputs -Wsystem-headers -DSYSTEM_WARNINGS
+// RUN: %clang_cc1 %s -fsyntax-only -verify -pedantic -Wnull-pointer-subtraction -std=c++11 -isystem %S/Inputs -Wsystem-headers -DSYSTEM_WARNINGS
+
+#include 
+
+void a() {
+  char *f = (char *)0;
+  f = (char *)((char *)0 - f); // expected-warning {{performing pointer subtraction with a null pointer may have undefined behavior}}
+  f = (char *)(f - (char *)0); // expected-warning {{performing pointer subtraction with a null pointer may have undefined behavior}}
+  f = (char *)((char *)0 - (char *)0); // valid in C++
+
+#ifndef SYSTEM_WARNINGS
+  SYSTEM_MACRO(f);
+#else
+  SYSTEM_MACRO(f); // expected-warning {{performing pointer subtraction with a null pointer may have undefined behavior}}
+#endif
+}
Index: clang/test/Sema/pointer-subtraction.c
===
--- /dev/null
+++ clang/test/Sema/pointer-subtraction.c
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 %s -fsyntax-only -verify -pedantic -Wextra -std=c11 -isystem %S/Inputs
+// RUN: %clang_cc1 %s -fsyntax-only -verify -pedantic -Wnull-pointer-subtraction -std=c11 -isystem %S/Inputs
+// RUN: %clang_cc1 %s -fsyntax-only -verify -pedantic -Wextra -std=c11 -isystem %S/Inputs -Wsystem-headers -DSYSTEM_WARNINGS
+// RUN: %clang_cc1 %s -fsyntax-only -verify -pedantic -Wnull-pointer-subtraction -std=c11 -isystem %S/Inputs -Wsystem-headers -DSYSTEM_WARNINGS
+
+#include 
+
+void a() {
+  char *f = (char *)0;
+  f = (char *)((char *)0 - f); // expected-warning {{performing pointer subtraction with a null pointer has undefined behavior}}
+  f = (char *)(f - (char *)0); // expected-warning {{performing pointer subtraction with a null pointer has undefined behavior}}
+  f = (char *)((char *)0 - (char *)0); // expected-warning {{performing pointer subtraction with a null pointer has undefined behavior}} expected-warning {{performing pointer subtraction with a null pointer has undefined behavior}}
+
+#ifndef SYSTEM_WARNINGS
+  SYSTEM_MACRO(f);
+#else
+  SYSTEM_MACRO(f); // expected-warning {{performing pointer subtraction with a null pointer has undefined behavior}}
+#endif
+}
Index: clang/test/Sema/Inputs/pointer-subtraction.h
===
--- /dev/null
+++ clang/test/Sema/Inputs/pointer-subtraction.h
@@ -0,0 +1 @@
+#define SYSTEM_MACRO(x) (x) = (char *)((char *)0 - (x))
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -10366,6 +10366,22 @@
   << S.getLangOpts().CPlusPlus << Pointer->getSourceRange();
 }
 
+/// Diagnose invalid subraction on a null pointer.
+///
+static void diagnoseSubtractionOnNullPointer(Sema &S, SourceLocation Loc,
+ Expr *Pointer, bool BothNull) {
+  // Null - null is valid in C++ [expr.add]p7
+  if (BothNull && S.getLangOpts().CPlusPlus)
+return;
+
+  // Is this s a macro from a system header?
+  if (S.Diags.getSuppressSystemWarnings() && S.SourceMgr.isInSystemMacro(Loc))
+return;
+
+  S.Diag(Loc, diag::warn_pointer_sub_null_ptr)
+  << S.getLangOpts().CPlusPlus << Pointer->getSourceRange();
+}
+
 /// Diagnose invalid arithmetic on two function pointers.
 static void diagnoseArithmeticOnTwoFunctionPointers(Sema &S, SourceLocation Loc,
 Expr *LHS, Expr *RHS) {
@@ -10797,7 +10813,16 @@
LHS.get(), RHS.get()))
 return QualType();
 
-  // FIXME: Add warnings for nullptr - ptr.
+  bool LHSIsNullPtr = LHS.get()->IgnoreParenCasts()->isNullPointerConstant(
+  Context, Expr::NPC_ValueDependentIsNotNull);
+  bool RHSIsNullPtr = RHS.get()->IgnoreParenCasts()->isNullPointerConstant(
+  Context, Expr::NPC_ValueDependentIsNotNull);
+
+  // Subtracting nullptr or from nullptr is suspect
+  if (LHSIsNullPtr)
+ 

[PATCH] D102849: [flang][driver] Add support for the "-init-only" option

2021-05-20 Thread Stuart Ellis via Phabricator via cfe-commits
stuartellis created this revision.
Herald added a reviewer: sscalpone.
Herald added a subscriber: dang.
Herald added a reviewer: awarzynski.
stuartellis requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Adding the -init-only option and corresponding frontend action
to generate a diagnostic.

It also adds a Driver test to check this action.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D102849

Files:
  clang/include/clang/Driver/Options.td
  flang/include/flang/Frontend/FrontendActions.h
  flang/include/flang/Frontend/FrontendOptions.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/lib/Frontend/FrontendActions.cpp
  flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
  flang/test/Driver/driver-help.f90
  flang/test/Driver/init-only.f90

Index: flang/test/Driver/init-only.f90
===
--- /dev/null
+++ flang/test/Driver/init-only.f90
@@ -0,0 +1,5 @@
+! Verify that -init-only flag generates a diagnostic as expected
+
+! RUN: %flang_fc1 -init-only 2>&1 | FileCheck %s
+
+! CHECK: warning: Use `-init-only` for testing purposes only
Index: flang/test/Driver/driver-help.f90
===
--- flang/test/Driver/driver-help.f90
+++ flang/test/Driver/driver-help.f90
@@ -104,6 +104,7 @@
 ! HELP-FC1-NEXT: -fopenmp   Parse OpenMP pragmas and generate parallel code.
 ! HELP-FC1-NEXT: -fxor-operator Enable .XOR. as a synonym of .NEQV.
 ! HELP-FC1-NEXT: -help  Display available options
+! HELP-FC1-NEXT: -init-only Only execute frontend initialization
 ! HELP-FC1-NEXT: -IAdd directory to the end of the list of include search paths
 ! HELP-FC1-NEXT: -module-dir   Put MODULE files in 
 ! HELP-FC1-NEXT: -nocpp Disable predefined and command line preprocessor macros
Index: flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
===
--- flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
+++ flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
@@ -73,6 +73,9 @@
   case GetSymbolsSources:
 return std::make_unique();
 break;
+  case InitializationOnly:
+return std::make_unique();
+break;
   default:
 break;
 // TODO:
Index: flang/lib/Frontend/FrontendActions.cpp
===
--- flang/lib/Frontend/FrontendActions.cpp
+++ flang/lib/Frontend/FrontendActions.cpp
@@ -447,3 +447,11 @@
   clang::DiagnosticsEngine::Error, "code-generation is not available yet");
   ci.diagnostics().Report(DiagID);
 }
+
+void InitializationOnlyAction::ExecuteAction() {
+  CompilerInstance &ci = this->instance();
+  unsigned DiagID =
+  ci.diagnostics().getCustomDiagID(clang::DiagnosticsEngine::Warning,
+  "Use `-init-only` for testing purposes only");
+  ci.diagnostics().Report(DiagID);
+}
Index: flang/lib/Frontend/CompilerInvocation.cpp
===
--- flang/lib/Frontend/CompilerInvocation.cpp
+++ flang/lib/Frontend/CompilerInvocation.cpp
@@ -162,9 +162,12 @@
 case clang::driver::options::OPT_fget_definition:
   opts.programAction_ = GetDefinition;
   break;
+case clang::driver::options::OPT_init_only:
+  opts.programAction_ = InitializationOnly;
+  break;
 
   // TODO:
-  // case calng::driver::options::OPT_emit_llvm:
+  // case clang::driver::options::OPT_emit_llvm:
   // case clang::driver::options::OPT_emit_llvm_only:
   // case clang::driver::options::OPT_emit_codegen_only:
   // case clang::driver::options::OPT_emit_module:
Index: flang/include/flang/Frontend/FrontendOptions.h
===
--- flang/include/flang/Frontend/FrontendOptions.h
+++ flang/include/flang/Frontend/FrontendOptions.h
@@ -71,7 +71,10 @@
   GetDefinition,
 
   /// Parse, run semantics and then dump symbol sources map
-  GetSymbolsSources
+  GetSymbolsSources,
+
+  /// Only execute frontend initialization
+  InitializationOnly
 
   /// TODO: RunPreprocessor, EmitLLVM, EmitLLVMOnly,
   /// EmitCodeGenOnly, EmitAssembly, (...)
Index: flang/include/flang/Frontend/FrontendActions.h
===
--- flang/include/flang/Frontend/FrontendActions.h
+++ flang/include/flang/Frontend/FrontendActions.h
@@ -38,6 +38,10 @@
   void ExecuteAction() override;
 };
 
+class InitializationOnlyAction : public FrontendAction {
+  void ExecuteAction() override;
+};
+
 //===--===//
 // Prescan Actions
 //===--===//
Index: clang/include/clang/Driver/Options.td
===
--- 

[PATCH] D102850: [C++4OpenCL] Allow address space conversion in reinterpret_cast

2021-05-20 Thread Ole Strohm via Phabricator via cfe-commits
olestrohm created this revision.
olestrohm added reviewers: Anastasia, svenvh.
olestrohm added a project: clang.
Herald added subscribers: ldrumm, yaxunl.
olestrohm requested review of this revision.
Herald added a subscriber: cfe-commits.

This fixes the prioritization of address spaces when choosing a constructor,
stopping them from being considered equally good, which made the construction
of types that could be constructed by more than one of the constructors.

It does this by preferring the most specific address space, which is decided by 
seeing
if one of the address spaces is a superset of the other, and preferring the 
other.

Fixes: PR50329


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D102850

Files:
  clang/lib/Sema/SemaOverload.cpp
  clang/test/CodeGenOpenCLCXX/addrspace-constructors.clcpp


Index: clang/test/CodeGenOpenCLCXX/addrspace-constructors.clcpp
===
--- clang/test/CodeGenOpenCLCXX/addrspace-constructors.clcpp
+++ clang/test/CodeGenOpenCLCXX/addrspace-constructors.clcpp
@@ -11,8 +11,7 @@
   int x;
 
   // Local variables are handled in local_addrspace_init.clcpp
-  // FIXME: __private and __generic constructors clash for __private variable
-  // X() /*__generic*/ = default;
+  X() /*__generic*/ = default;
   X() __private : x(0) {}
   X() __global : x(0) {}
   constexpr X() __constant : x(0) {}
@@ -30,7 +29,7 @@
 // CHECK: @_ZZ1kE3cx2 = internal addrspace(2) constant %struct.X { i32 1 }
 
 kernel void k() {
-  // Check that the constructor for px is executed
+  // Check that the constructor for px calls the __private constructor
   // CHECK: %px = alloca %struct.X
   // CHECK-NEXT: call spir_func void @_ZN1XC1Ev(%struct.X* {{.*}}%px)
   __private X px;
Index: clang/lib/Sema/SemaOverload.cpp
===
--- clang/lib/Sema/SemaOverload.cpp
+++ clang/lib/Sema/SemaOverload.cpp
@@ -9867,6 +9867,16 @@
S.IdentifyCUDAPreference(Caller, Cand2.Function);
   }
 
+  if (S.getLangOpts().OpenCL) {
+if (const auto *CD1 = 
dyn_cast_or_null(Cand1.Function)) {
+  if (const auto *CD2 = 
dyn_cast_or_null(Cand2.Function)) {
+return Qualifiers::isAddressSpaceSupersetOf(
+CD2->getMethodQualifiers().getAddressSpace(),
+CD1->getMethodQualifiers().getAddressSpace());
+  }
+}
+  }
+
   return false;
 }
 


Index: clang/test/CodeGenOpenCLCXX/addrspace-constructors.clcpp
===
--- clang/test/CodeGenOpenCLCXX/addrspace-constructors.clcpp
+++ clang/test/CodeGenOpenCLCXX/addrspace-constructors.clcpp
@@ -11,8 +11,7 @@
   int x;
 
   // Local variables are handled in local_addrspace_init.clcpp
-  // FIXME: __private and __generic constructors clash for __private variable
-  // X() /*__generic*/ = default;
+  X() /*__generic*/ = default;
   X() __private : x(0) {}
   X() __global : x(0) {}
   constexpr X() __constant : x(0) {}
@@ -30,7 +29,7 @@
 // CHECK: @_ZZ1kE3cx2 = internal addrspace(2) constant %struct.X { i32 1 }
 
 kernel void k() {
-  // Check that the constructor for px is executed
+  // Check that the constructor for px calls the __private constructor
   // CHECK: %px = alloca %struct.X
   // CHECK-NEXT: call spir_func void @_ZN1XC1Ev(%struct.X* {{.*}}%px)
   __private X px;
Index: clang/lib/Sema/SemaOverload.cpp
===
--- clang/lib/Sema/SemaOverload.cpp
+++ clang/lib/Sema/SemaOverload.cpp
@@ -9867,6 +9867,16 @@
S.IdentifyCUDAPreference(Caller, Cand2.Function);
   }
 
+  if (S.getLangOpts().OpenCL) {
+if (const auto *CD1 = dyn_cast_or_null(Cand1.Function)) {
+  if (const auto *CD2 = dyn_cast_or_null(Cand2.Function)) {
+return Qualifiers::isAddressSpaceSupersetOf(
+CD2->getMethodQualifiers().getAddressSpace(),
+CD1->getMethodQualifiers().getAddressSpace());
+  }
+}
+  }
+
   return false;
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 2d574a1 - [CodeGen][AArch64][SVE] Canonicalize intrinsic rdffr{ => _z}

2021-05-20 Thread Peter Waller via cfe-commits

Author: Peter Waller
Date: 2021-05-20T16:22:50Z
New Revision: 2d574a110440597eefe1b2a8b6144e4e89c21d05

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

LOG: [CodeGen][AArch64][SVE] Canonicalize intrinsic rdffr{ => _z}

Follow up to D101357 / 3fa6510f6.
Supersedes D102330.

Goal: Use flags setting rdffrs instead of rdffr + ptest.

Problem: RDFFR_P doesn't have have a flags setting equivalent.

Solution: in instcombine, canonicalize to RDFFR_PP at the IR level, and
rely on RDFFR_PP+PTEST => RDFFRS_PP optimization in
AArch64InstrInfo::optimizePTestInstr.

While here:

* Test that rdffr.z+ptest generates a rdffrs.
* Use update_{test,llc}_checks.py on the tests.
* Use sve attribute on functions.

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

Added: 
llvm/test/Transforms/InstCombine/AArch64/sve-intrinsics-rdffr-predication.ll

Modified: 
clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_rdffr.c
llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
llvm/test/CodeGen/AArch64/sve-intrinsics-ffr-manipulation.ll

Removed: 




diff  --git a/clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_rdffr.c 
b/clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_rdffr.c
index 9b871ee3a8dc..a85ac7bb5cef 100644
--- a/clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_rdffr.c
+++ b/clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_rdffr.c
@@ -7,7 +7,8 @@
 svbool_t test_svrdffr()
 {
   // CHECK-LABEL: test_svrdffr
-  // CHECK: %[[INTRINSIC:.*]] = call  
@llvm.aarch64.sve.rdffr()
+  // CHECK: %[[INTRINSIC:.*]] = call  
@llvm.aarch64.sve.rdffr.z(
+  // CHECK-NOT: rdffr
   // CHECK: ret  %[[INTRINSIC]]
   return svrdffr();
 }

diff  --git a/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp 
b/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
index 90762052dc3a..846c07863467 100644
--- a/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
+++ b/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
@@ -470,6 +470,23 @@ static Optional 
instCombineSVELast(InstCombiner &IC,
   return IC.replaceInstUsesWith(II, Extract);
 }
 
+static Optional instCombineRDFFR(InstCombiner &IC,
+IntrinsicInst &II) {
+  LLVMContext &Ctx = II.getContext();
+  IRBuilder<> Builder(Ctx);
+  Builder.SetInsertPoint(&II);
+  // Replace rdffr with predicated rdffr.z intrinsic, so that 
optimizePTestInstr
+  // can work with RDFFR_PP for ptest elimination.
+  auto *AllPat =
+  ConstantInt::get(Type::getInt32Ty(Ctx), AArch64SVEPredPattern::all);
+  auto *PTrue = Builder.CreateIntrinsic(Intrinsic::aarch64_sve_ptrue,
+{II.getType()}, {AllPat});
+  auto *RDFFR =
+  Builder.CreateIntrinsic(Intrinsic::aarch64_sve_rdffr_z, {}, {PTrue});
+  RDFFR->takeName(&II);
+  return IC.replaceInstUsesWith(II, RDFFR);
+}
+
 Optional
 AArch64TTIImpl::instCombineIntrinsic(InstCombiner &IC,
  IntrinsicInst &II) const {
@@ -481,6 +498,8 @@ AArch64TTIImpl::instCombineIntrinsic(InstCombiner &IC,
 return instCombineConvertFromSVBool(IC, II);
   case Intrinsic::aarch64_sve_dup:
 return instCombineSVEDup(IC, II);
+  case Intrinsic::aarch64_sve_rdffr:
+return instCombineRDFFR(IC, II);
   case Intrinsic::aarch64_sve_lasta:
   case Intrinsic::aarch64_sve_lastb:
 return instCombineSVELast(IC, II);

diff  --git a/llvm/test/CodeGen/AArch64/sve-intrinsics-ffr-manipulation.ll 
b/llvm/test/CodeGen/AArch64/sve-intrinsics-ffr-manipulation.ll
index 7460037078d1..bc07c972e5fb 100644
--- a/llvm/test/CodeGen/AArch64/sve-intrinsics-ffr-manipulation.ll
+++ b/llvm/test/CodeGen/AArch64/sve-intrinsics-ffr-manipulation.ll
@@ -1,33 +1,51 @@
-; RUN: llc -mtriple=aarch64-linux-gnu -mattr=+sve < %s | FileCheck %s
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc < %s | FileCheck %s
+
+target triple = "aarch64-unknown-linux-gnu"
 
 ;
 ; RDFFR
 ;
 
-define  @rdffr() {
+define  @rdffr() #0 {
 ; CHECK-LABEL: rdffr:
-; CHECK: rdffr p0.b
-; CHECK-NEXT: ret
+; CHECK:   // %bb.0:
+; CHECK-NEXT:rdffr p0.b
+; CHECK-NEXT:ret
   %out = call  @llvm.aarch64.sve.rdffr()
   ret  %out
 }
 
-define  @rdffr_z( %pg) {
+define  @rdffr_z( %pg) #0 {
 ; CHECK-LABEL: rdffr_z:
-; CHECK: rdffr p0.b, p0/z
-; CHECK-NEXT: ret
+; CHECK:   // %bb.0:
+; CHECK-NEXT:rdffr p0.b, p0/z
+; CHECK-NEXT:ret
   %out = call  @llvm.aarch64.sve.rdffr.z( 
%pg)
   ret  %out
 }
 
+; Test that rdffr.z followed by ptest optimizes to flags-setting rdffrs.
+define i1 @rdffr_z_ptest( %pg) #0 {
+; CHECK-LABEL: rdffr_z_ptest:
+; CHECK:   // %bb.0:
+; CHECK-NEXT:rdffrs p0.b, p0/z
+; CHECK-NEXT:cset w0, ne
+; CHECK-NEXT:ret
+  %rdffr = call  @llvm.aarch64.sve.rdffr.z( %pg)
+  %out = call

[PATCH] D102623: [CodeGen][AArch64][SVE] Canonicalize intrinsic rdffr{ => _z}

2021-05-20 Thread Peter Waller 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 rG2d574a110440: [CodeGen][AArch64][SVE] Canonicalize intrinsic 
rdffr{ => _z} (authored by peterwaller-arm).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102623

Files:
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_rdffr.c
  llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
  llvm/test/CodeGen/AArch64/sve-intrinsics-ffr-manipulation.ll
  llvm/test/Transforms/InstCombine/AArch64/sve-intrinsics-rdffr-predication.ll

Index: llvm/test/Transforms/InstCombine/AArch64/sve-intrinsics-rdffr-predication.ll
===
--- /dev/null
+++ llvm/test/Transforms/InstCombine/AArch64/sve-intrinsics-rdffr-predication.ll
@@ -0,0 +1,19 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt -S -instcombine < %s | FileCheck %s
+
+target triple = "aarch64-unknown-linux-gnu"
+
+; Test that rdffr is substituted with predicated form which enables ptest optimization later.
+define  @predicate_rdffr() #0 {
+; CHECK-LABEL: @predicate_rdffr(
+; CHECK-NEXT:[[TMP1:%.*]] = call  @llvm.aarch64.sve.ptrue.nxv16i1(i32 31)
+; CHECK-NEXT:[[OUT:%.*]] = call  @llvm.aarch64.sve.rdffr.z( [[TMP1]])
+; CHECK-NEXT:ret  [[OUT]]
+;
+  %out = call  @llvm.aarch64.sve.rdffr()
+  ret  %out
+}
+
+declare  @llvm.aarch64.sve.rdffr()
+
+attributes #0 = { "target-features"="+sve" }
Index: llvm/test/CodeGen/AArch64/sve-intrinsics-ffr-manipulation.ll
===
--- llvm/test/CodeGen/AArch64/sve-intrinsics-ffr-manipulation.ll
+++ llvm/test/CodeGen/AArch64/sve-intrinsics-ffr-manipulation.ll
@@ -1,33 +1,51 @@
-; RUN: llc -mtriple=aarch64-linux-gnu -mattr=+sve < %s | FileCheck %s
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc < %s | FileCheck %s
+
+target triple = "aarch64-unknown-linux-gnu"
 
 ;
 ; RDFFR
 ;
 
-define  @rdffr() {
+define  @rdffr() #0 {
 ; CHECK-LABEL: rdffr:
-; CHECK: rdffr p0.b
-; CHECK-NEXT: ret
+; CHECK:   // %bb.0:
+; CHECK-NEXT:rdffr p0.b
+; CHECK-NEXT:ret
   %out = call  @llvm.aarch64.sve.rdffr()
   ret  %out
 }
 
-define  @rdffr_z( %pg) {
+define  @rdffr_z( %pg) #0 {
 ; CHECK-LABEL: rdffr_z:
-; CHECK: rdffr p0.b, p0/z
-; CHECK-NEXT: ret
+; CHECK:   // %bb.0:
+; CHECK-NEXT:rdffr p0.b, p0/z
+; CHECK-NEXT:ret
   %out = call  @llvm.aarch64.sve.rdffr.z( %pg)
   ret  %out
 }
 
+; Test that rdffr.z followed by ptest optimizes to flags-setting rdffrs.
+define i1 @rdffr_z_ptest( %pg) #0 {
+; CHECK-LABEL: rdffr_z_ptest:
+; CHECK:   // %bb.0:
+; CHECK-NEXT:rdffrs p0.b, p0/z
+; CHECK-NEXT:cset w0, ne
+; CHECK-NEXT:ret
+  %rdffr = call  @llvm.aarch64.sve.rdffr.z( %pg)
+  %out = call i1 @llvm.aarch64.sve.ptest.any.nxv16i1( %pg,  %rdffr)
+  ret i1 %out
+}
+
 ;
 ; SETFFR
 ;
 
-define void @set_ffr() {
+define void @set_ffr() #0 {
 ; CHECK-LABEL: set_ffr:
-; CHECK: setffr
-; CHECK-NEXT: ret
+; CHECK:   // %bb.0:
+; CHECK-NEXT:setffr
+; CHECK-NEXT:ret
   call void @llvm.aarch64.sve.setffr()
   ret void
 }
@@ -36,10 +54,11 @@
 ; WRFFR
 ;
 
-define void @wrffr( %a) {
+define void @wrffr( %a) #0 {
 ; CHECK-LABEL: wrffr:
-; CHECK: wrffr p0.b
-; CHECK-NEXT: ret
+; CHECK:   // %bb.0:
+; CHECK-NEXT:wrffr p0.b
+; CHECK-NEXT:ret
   call void @llvm.aarch64.sve.wrffr( %a)
   ret void
 }
@@ -48,3 +67,7 @@
 declare  @llvm.aarch64.sve.rdffr.z()
 declare void @llvm.aarch64.sve.setffr()
 declare void @llvm.aarch64.sve.wrffr()
+
+declare i1 @llvm.aarch64.sve.ptest.any.nxv16i1(, )
+
+attributes #0 = { "target-features"="+sve" }
Index: llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
===
--- llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
+++ llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
@@ -470,6 +470,23 @@
   return IC.replaceInstUsesWith(II, Extract);
 }
 
+static Optional instCombineRDFFR(InstCombiner &IC,
+IntrinsicInst &II) {
+  LLVMContext &Ctx = II.getContext();
+  IRBuilder<> Builder(Ctx);
+  Builder.SetInsertPoint(&II);
+  // Replace rdffr with predicated rdffr.z intrinsic, so that optimizePTestInstr
+  // can work with RDFFR_PP for ptest elimination.
+  auto *AllPat =
+  ConstantInt::get(Type::getInt32Ty(Ctx), AArch64SVEPredPattern::all);
+  auto *PTrue = Builder.CreateIntrinsic(Intrinsic::aarch64_sve_ptrue,
+{II.getType()}, {AllPat});
+  auto *RDFFR =
+  Builder.CreateIntrinsic(Intrinsic::aarch64_sve_rdffr_z, {}, {PTrue});
+  RDFFR->takeName(&II);
+  return IC.replaceInstUsesWith(II, RDFFR);
+}
+
 Optional
 AArch64TTIImpl::instCombineIntrinsic(InstCombiner &IC,
 

[PATCH] D102756: [clang-repl] Tell the LLJIT the exact target triple we use.

2021-05-20 Thread Lang Hames via Phabricator via cfe-commits
lhames accepted this revision.
lhames added a comment.
This revision is now accepted and ready to land.

LGTM. :)


Repository:
  rC Clang

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

https://reviews.llvm.org/D102756

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


[clang] 136ced4 - When vector is found as a type or non-type id, check if it is really the altivec vector token.

2021-05-20 Thread Jamie Schmeiser via cfe-commits

Author: Jamie Schmeiser
Date: 2021-05-20T12:39:04-04:00
New Revision: 136ced498ba84f6b6126051626e319f18ba740f5

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

LOG: When vector is found as a type or non-type id, check if it is really the 
altivec vector token.

Summary:
Call TryAltiVecVectorToken when an identifier is seen in the parser before
annotating the token.  This checks the next token where necessary to ensure
that vector is properly handled as the altivec token.

Author: Jamie Schmeiser 
Reviewed By: ZarkoCA (Zarko Todorovski)
Differential Revision: https://reviews.llvm.org/D100991

Added: 
clang/test/Parser/altivec-non-type-vector.c
clang/test/Parser/altivec-template-vector.cpp
clang/test/Parser/altivec-typedef-vector.c

Modified: 
clang/lib/Parse/Parser.cpp

Removed: 




diff  --git a/clang/lib/Parse/Parser.cpp b/clang/lib/Parse/Parser.cpp
index 389180ea01f7..cbcbca127c9d 100644
--- a/clang/lib/Parse/Parser.cpp
+++ b/clang/lib/Parse/Parser.cpp
@@ -1695,6 +1695,11 @@ Parser::TryAnnotateName(CorrectionCandidateCallback 
*CCC) {
 break;
 
   case Sema::NC_Type: {
+if (TryAltiVecVectorToken())
+  // vector has been found as a type id when altivec is enabled but
+  // this is followed by a declaration specifier so this is really the
+  // altivec vector token.  Leave it unannotated.
+  break;
 SourceLocation BeginLoc = NameLoc;
 if (SS.isNotEmpty())
   BeginLoc = SS.getBeginLoc();
@@ -1736,6 +1741,11 @@ Parser::TryAnnotateName(CorrectionCandidateCallback 
*CCC) {
 return ANK_Success;
 
   case Sema::NC_NonType:
+if (TryAltiVecVectorToken())
+  // vector has been found as a non-type id when altivec is enabled but
+  // this is followed by a declaration specifier so this is really the
+  // altivec vector token.  Leave it unannotated.
+  break;
 Tok.setKind(tok::annot_non_type);
 setNonTypeAnnotation(Tok, Classification.getNonTypeDecl());
 Tok.setLocation(NameLoc);

diff  --git a/clang/test/Parser/altivec-non-type-vector.c 
b/clang/test/Parser/altivec-non-type-vector.c
new file mode 100644
index ..d0868a60d0c3
--- /dev/null
+++ b/clang/test/Parser/altivec-non-type-vector.c
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple 
powerpc64-ibm-aix-xcoff
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple 
powerpc64le-ibm-linux-gnu
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple 
powerpc64-linux-gnu
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple 
powerpc-ibm-aix-xcoff
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple 
powerpc-linux-gnu
+
+int vector();
+
+void test() {
+  vector unsigned int v = {0};
+}

diff  --git a/clang/test/Parser/altivec-template-vector.cpp 
b/clang/test/Parser/altivec-template-vector.cpp
new file mode 100644
index ..f0c1d86563fe
--- /dev/null
+++ b/clang/test/Parser/altivec-template-vector.cpp
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple 
powerpc64-ibm-aix-xcoff
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple 
powerpc64le-ibm-linux-gnu
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple 
powerpc64-linux-gnu
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple 
powerpc-ibm-aix-xcoff
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple 
powerpc-linux-gnu
+
+template  class vector {
+public:
+  vector(int) {}
+};
+
+void f() {
+  vector int v = {0};
+  vector vi = {0};
+}

diff  --git a/clang/test/Parser/altivec-typedef-vector.c 
b/clang/test/Parser/altivec-typedef-vector.c
new file mode 100644
index ..5e00824b4de7
--- /dev/null
+++ b/clang/test/Parser/altivec-typedef-vector.c
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple 
powerpc64-ibm-aix-xcoff
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple 
powerpc64le-ibm-linux-gnu
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple 
powerpc64-linux-gnu
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple 
powerpc-ibm-aix-xcoff
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple 
powerpc-linux-gnu
+
+typedef int vector;
+
+void test() {
+  vector unsigned int v = {0};
+}



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


[PATCH] D100991: Fix parsing of vector keyword in presence of conflicting uses.

2021-05-20 Thread Jamie Schmeiser via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG136ced498ba8: When vector is found as a type or non-type id, 
check if it is really the… (authored by jamieschmeiser).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100991

Files:
  clang/lib/Parse/Parser.cpp
  clang/test/Parser/altivec-non-type-vector.c
  clang/test/Parser/altivec-template-vector.cpp
  clang/test/Parser/altivec-typedef-vector.c


Index: clang/test/Parser/altivec-typedef-vector.c
===
--- /dev/null
+++ clang/test/Parser/altivec-typedef-vector.c
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple 
powerpc64-ibm-aix-xcoff
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple 
powerpc64le-ibm-linux-gnu
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple 
powerpc64-linux-gnu
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple 
powerpc-ibm-aix-xcoff
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple 
powerpc-linux-gnu
+
+typedef int vector;
+
+void test() {
+  vector unsigned int v = {0};
+}
Index: clang/test/Parser/altivec-template-vector.cpp
===
--- /dev/null
+++ clang/test/Parser/altivec-template-vector.cpp
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple 
powerpc64-ibm-aix-xcoff
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple 
powerpc64le-ibm-linux-gnu
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple 
powerpc64-linux-gnu
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple 
powerpc-ibm-aix-xcoff
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple 
powerpc-linux-gnu
+
+template  class vector {
+public:
+  vector(int) {}
+};
+
+void f() {
+  vector int v = {0};
+  vector vi = {0};
+}
Index: clang/test/Parser/altivec-non-type-vector.c
===
--- /dev/null
+++ clang/test/Parser/altivec-non-type-vector.c
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple 
powerpc64-ibm-aix-xcoff
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple 
powerpc64le-ibm-linux-gnu
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple 
powerpc64-linux-gnu
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple 
powerpc-ibm-aix-xcoff
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple 
powerpc-linux-gnu
+
+int vector();
+
+void test() {
+  vector unsigned int v = {0};
+}
Index: clang/lib/Parse/Parser.cpp
===
--- clang/lib/Parse/Parser.cpp
+++ clang/lib/Parse/Parser.cpp
@@ -1695,6 +1695,11 @@
 break;
 
   case Sema::NC_Type: {
+if (TryAltiVecVectorToken())
+  // vector has been found as a type id when altivec is enabled but
+  // this is followed by a declaration specifier so this is really the
+  // altivec vector token.  Leave it unannotated.
+  break;
 SourceLocation BeginLoc = NameLoc;
 if (SS.isNotEmpty())
   BeginLoc = SS.getBeginLoc();
@@ -1736,6 +1741,11 @@
 return ANK_Success;
 
   case Sema::NC_NonType:
+if (TryAltiVecVectorToken())
+  // vector has been found as a non-type id when altivec is enabled but
+  // this is followed by a declaration specifier so this is really the
+  // altivec vector token.  Leave it unannotated.
+  break;
 Tok.setKind(tok::annot_non_type);
 setNonTypeAnnotation(Tok, Classification.getNonTypeDecl());
 Tok.setLocation(NameLoc);


Index: clang/test/Parser/altivec-typedef-vector.c
===
--- /dev/null
+++ clang/test/Parser/altivec-typedef-vector.c
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple powerpc64-ibm-aix-xcoff
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple powerpc64le-ibm-linux-gnu
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple powerpc64-linux-gnu
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple powerpc-ibm-aix-xcoff
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple powerpc-linux-gnu
+
+typedef int vector;
+
+void test() {
+  vector unsigned int v = {0};
+}
Index: clang/test/Parser/altivec-template-vector.cpp
===
--- /dev/null
+++ clang/test/Parser/altivec-template-vector.cpp
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple powerpc64-ibm-aix-xcoff
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple powerpc64le-ibm-linux-gnu
+// RUN: %clang_cc1 -target-feature +altive

[PATCH] D102479: [clang][driver] Treat unkonwn -flto= values as -flto

2021-05-20 Thread Steven Wu via Phabricator via cfe-commits
steven_wu accepted this revision.
steven_wu added a comment.
This revision is now accepted and ready to land.

LGTM


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

https://reviews.llvm.org/D102479

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


[PATCH] D102818: [PGO] Don't reference functions unless value profiling is enabled

2021-05-20 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added a comment.

Thanks! I'll wait to see if I can get an ack from the Apple folks who indicated 
that they are using frontend PGO.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102818

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


[PATCH] D102818: [PGO] Don't reference functions unless value profiling is enabled

2021-05-20 Thread Vedant Kumar via Phabricator via cfe-commits
vsk accepted this revision.
vsk added a comment.

Thanks, lgtm as well. On Darwin, the __llvm_prf_data section is marked with 
S_ATTR_LIVE_SUPPORT to allow the linker to dead strip functions even if they 
are pointed-to by a profd global. Removing the reference altogether should 
yield even better size benefits.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102818

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


[PATCH] D102853: [OpenCL] Align definition of __IMAGE_SUPPORT__ feature macro with OpenCL version and __opencl_c_images feature macro definition

2021-05-20 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov created this revision.
azabaznov added reviewers: Anastasia, svenvh.
Herald added subscribers: ldrumm, yaxunl.
azabaznov requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D102853

Files:
  clang/lib/Frontend/InitPreprocessor.cpp
  clang/test/Preprocessor/predefined-macros.c
  clang/test/SemaOpenCL/features.cl


Index: clang/test/SemaOpenCL/features.cl
===
--- clang/test/SemaOpenCL/features.cl
+++ clang/test/SemaOpenCL/features.cl
@@ -1,9 +1,9 @@
 // RUN: %clang_cc1 -triple spir-unknown-unknown %s -E -dM -o - -x cl 
-cl-std=CL3.0 -cl-ext=-all \
-// RUN:   | FileCheck -match-full-lines %s  --check-prefix=NO-FEATURES
+// RUN:   | FileCheck -match-full-lines %s  
--check-prefixes=NO-FEATURES,NO-FEATURES-CL30
 // RUN: %clang_cc1 -triple spir-unknown-unknown %s -E -dM -o - -x cl 
-cl-std=CL3.0 -cl-ext=+all \
 // RUN:   | FileCheck -match-full-lines %s  --check-prefix=FEATURES
 // RUN: %clang_cc1 -triple r600-unknown-unknown %s -E -dM -o - -x cl 
-cl-std=CL3.0 \
-// RUN:   | FileCheck -match-full-lines %s  --check-prefix=NO-FEATURES
+// RUN:   | FileCheck -match-full-lines %s  
--check-prefixes=NO-FEATURES,NO-FEATURES-CL30
 // RUN: %clang_cc1 -triple r600-unknown-unknown %s -E -dM -o - -x cl 
-cl-std=CL3.0 -cl-ext=+all \
 // RUN:   | FileCheck -match-full-lines %s  --check-prefix=FEATURES
 
@@ -21,6 +21,7 @@
 // Note that __opencl_c_int64 is always defined assuming
 // always compiling for FULL OpenCL profile
 
+// FEATURES: #define __IMAGE_SUPPORT__ 1
 // FEATURES: #define __opencl_c_3d_image_writes 1
 // FEATURES: #define __opencl_c_atomic_order_acq_rel 1
 // FEATURES: #define __opencl_c_atomic_order_seq_cst 1
@@ -46,3 +47,4 @@
 // NO-FEATURES-NOT: __opencl_c_program_scope_global_variables
 // NO-FEATURES-NOT: __opencl_c_read_write_images
 // NO-FEATURES-NOT: __opencl_c_subgroups
+// NO-FEATURES-CL30-NOT: __IMAGE_SUPPORT__
Index: clang/test/Preprocessor/predefined-macros.c
===
--- clang/test/Preprocessor/predefined-macros.c
+++ clang/test/Preprocessor/predefined-macros.c
@@ -188,14 +188,12 @@
 
 // RUN: %clang_cc1 %s -E -dM -o - -x cl -triple spir-unknown-unknown \
 // RUN:   | FileCheck -match-full-lines %s --check-prefix=CHECK-SPIR
-// CHECK-SPIR-DAG: #define __IMAGE_SUPPORT__ 1
 // CHECK-SPIR-DAG: #define __SPIR__ 1
 // CHECK-SPIR-DAG: #define __SPIR32__ 1
 // CHECK-SPIR-NOT: #define __SPIR64__ 1
 
 // RUN: %clang_cc1 %s -E -dM -o - -x cl -triple spir64-unknown-unknown \
 // RUN:   | FileCheck -match-full-lines %s --check-prefix=CHECK-SPIR64
-// CHECK-SPIR64-DAG: #define __IMAGE_SUPPORT__ 1
 // CHECK-SPIR64-DAG: #define __SPIR__ 1
 // CHECK-SPIR64-DAG: #define __SPIR64__ 1
 // CHECK-SPIR64-NOT: #define __SPIR32__ 1
Index: clang/lib/Frontend/InitPreprocessor.cpp
===
--- clang/lib/Frontend/InitPreprocessor.cpp
+++ clang/lib/Frontend/InitPreprocessor.cpp
@@ -603,9 +603,9 @@
 
 /// InitializeOpenCLFeatureTestMacros - Define OpenCL macros based on target
 /// settings and language version
-void InitializeOpenCLFeatureTestMacros(const TargetInfo &TI,
-   const LangOptions &Opts,
-   MacroBuilder &Builder) {
+static void InitializeOpenCLFeatureTestMacros(const TargetInfo &TI,
+  const LangOptions &Opts,
+  MacroBuilder &Builder) {
   const llvm::StringMap &OpenCLFeaturesMap = TI.getSupportedOpenCLOpts();
   // FIXME: OpenCL options which affect language semantics/syntax
   // should be moved into LangOptions.
@@ -622,6 +622,10 @@
 
   // Assume compiling for FULL profile
   Builder.defineMacro("__opencl_c_int64");
+
+  if (Opts.OpenCLCPlusPlus || Opts.OpenCLVersion < 300 ||
+  TI.hasFeatureEnabled(OpenCLFeaturesMap, "__opencl_c_images"))
+Builder.defineMacro("__IMAGE_SUPPORT__");
 }
 
 static void InitializePredefinedMacros(const TargetInfo &TI,
@@ -1159,13 +1163,9 @@
   }
 
   // OpenCL definitions.
-  if (LangOpts.OpenCL) {
+  if (LangOpts.OpenCL)
 InitializeOpenCLFeatureTestMacros(TI, LangOpts, Builder);
 
-if (TI.getTriple().isSPIR())
-  Builder.defineMacro("__IMAGE_SUPPORT__");
-  }
-
   if (TI.hasInt128Type() && LangOpts.CPlusPlus && LangOpts.GNUMode) {
 // For each extended integer type, g++ defines a macro mapping the
 // index of the type (0 in this case) in some list of extended types


Index: clang/test/SemaOpenCL/features.cl
===
--- clang/test/SemaOpenCL/features.cl
+++ clang/test/SemaOpenCL/features.cl
@@ -1,9 +1,9 @@
 // RUN: %clang_cc1 -triple spir-unknown-unknown %s -E -dM -o - -x cl -cl-std=CL3.0 -cl-ext=-all \
-// RUN:   | FileCheck 

[PATCH] D20401: [Lexer] Don't merge macro args from different macro files

2021-05-20 Thread Vedant Kumar via Phabricator via cfe-commits
vsk added a comment.

In D20401#2770059 , @nickdesaulniers 
wrote:

> I know this was sped up slightly in 3339c568c43e4644f02289e5edfc78c860f19c9f, 
> but this change makes `updateConsecutiveMacroArgTokens` the hottest function 
> in clang in a bottom up profile of an entire build of the Linux kernel.  It 
> thrashes the one entry LastFileIDLookup cache, and we end up looking up the 
> same FileID again and again and again for each token when we expand nested 
> function like macros.
>
> Is there anything we can do to speed this up?  Is there any way to record 
> which FileID corresponds to a given Token so that we don't have to keep 
> rematerializing that?  Is it possible to find whether two SourceLocations 
> correspond to the same FileID without having to figure out which FileID in 
> particular each belongs to?

Perhaps you could try:

- using SourceManager::isInFileID(NextLoc, getFileID(CurLoc), ...) (to halve 
the number of necessary getFileID lookups), or
- using a 2-element cache in getFileID?

>> I discussed this bug with Argyrios off-list, who lgtm'd on the condition 
>> that it doesn't introduce a performance regression.
>
> Well, I'd say it's a performance regression, though perhaps reported 5 years 
> too late.

If the performance issue manifests on Linux kernel sources from 5 years ago, 
then sure, I'd agree :).


Repository:
  rL LLVM

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

https://reviews.llvm.org/D20401

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


[PATCH] D101479: [Driver] Support libc++ in MSVC

2021-05-20 Thread Reid Kleckner via Phabricator via cfe-commits
rnk accepted this revision.
rnk added a comment.
This revision is now accepted and ready to land.

lgtm, sorry for the delay, this fell off the end.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101479

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


[PATCH] D102814: [AIX] Print printable byte list as quoted string

2021-05-20 Thread Jinsong Ji via Phabricator via cfe-commits
jsji updated this revision to Diff 346794.
jsji added a comment.

Address comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102814

Files:
  clang/test/CodeGenCXX/debug-info-byval.cpp
  llvm/include/llvm/MC/MCAsmInfo.h
  llvm/lib/MC/MCAsmInfoXCOFF.cpp
  llvm/lib/MC/MCAsmStreamer.cpp
  llvm/test/CodeGen/PowerPC/aix-emit-tracebacktable-clobber-register.ll
  llvm/test/CodeGen/PowerPC/aix-emit-tracebacktable.ll
  llvm/test/CodeGen/PowerPC/aix-exception.ll
  llvm/test/CodeGen/PowerPC/aix-xcoff-data.ll
  llvm/test/CodeGen/PowerPC/aix-xcoff-rodata.ll
  llvm/test/DebugInfo/XCOFF/empty.ll
  llvm/test/DebugInfo/XCOFF/explicit-section.ll
  llvm/test/DebugInfo/XCOFF/function-sections.ll

Index: llvm/test/DebugInfo/XCOFF/function-sections.ll
===
--- llvm/test/DebugInfo/XCOFF/function-sections.ll
+++ llvm/test/DebugInfo/XCOFF/function-sections.ll
@@ -72,7 +72,7 @@
 ; CHECK-NEXT:  .byte   0x01# NumberOfFPParms = 0, +HasParmsOnStack
 ; CHECK-NEXT:  .vbyte  4, L..foo0-.foo[PR] # Function size
 ; CHECK-NEXT:  .vbyte  2, 0x0003   # Function name len = 3
-; CHECK-NEXT:  .byte   'f,'o,'o# Function Name
+; CHECK-NEXT:  .byte   "foo"   # Function Name
 ; CHECK-NEXT:  L..func_end0:
 ; CHECK-NEXT:  # -- End function
 ; CHECK-NEXT:  .csect .bar[PR],2
@@ -108,7 +108,7 @@
 ; CHECK-NEXT:  .byte   0x01# NumberOfFPParms = 0, +HasParmsOnStack
 ; CHECK-NEXT:  .vbyte  4, L..bar0-.bar[PR] # Function size
 ; CHECK-NEXT:  .vbyte  2, 0x0003   # Function name len = 3
-; CHECK-NEXT:  .byte   'b,'a,'r# Function Name
+; CHECK-NEXT:  .byte   "bar"   # Function Name
 ; CHECK-NEXT:  L..func_end1:
 ; CHECK-NEXT:  # -- End function
 ; CHECK-NEXT:  L..sec_end0:
@@ -258,10 +258,10 @@
 ; CHECK-NEXT:  .byte   0
 ; CHECK-NEXT:  .byte   0
 ; CHECK-NEXT:  .byte   1
-; CHECK-NEXT:  .byte   'd,'e,'b,'u,'g
+; CHECK-NEXT:  .byte   "debug"
 ; CHECK-NEXT:  .byte   0
 ; CHECK-NEXT:  .byte   0
-; CHECK-NEXT:  .byte   '1,'.,'c
+; CHECK-NEXT:  .byte   "1.c"
 ; CHECK-NEXT:  .byte   0
 ; CHECK-NEXT:  .byte   1
 ; CHECK-NEXT:  .byte   0
Index: llvm/test/DebugInfo/XCOFF/explicit-section.ll
===
--- llvm/test/DebugInfo/XCOFF/explicit-section.ll
+++ llvm/test/DebugInfo/XCOFF/explicit-section.ll
@@ -77,7 +77,7 @@
 ; CHECK-NEXT:  .byte   0x01# NumberOfFPParms = 0, +HasParmsOnStack
 ; CHECK-NEXT:  .vbyte  4, L..bar0-.bar # Function size
 ; CHECK-NEXT:  .vbyte  2, 0x0003   # Function name len = 3
-; CHECK-NEXT:  .byte   'b,'a,'r# Function Name
+; CHECK-NEXT:  .byte   "bar"   # Function Name
 ; CHECK-NEXT:  L..func_end0:
 ; CHECK-NEXT:  # -- End function
 ; CHECK-NEXT:  .csect explicit_main_sec[PR],2
@@ -125,7 +125,7 @@
 ; CHECK-NEXT:  .byte   0x01# NumberOfFPParms = 0, +HasParmsOnStack
 ; CHECK-NEXT:  .vbyte  4, L..main0-.main   # Function size
 ; CHECK-NEXT:  .vbyte  2, 0x0004   # Function name len = 4
-; CHECK-NEXT:  .byte   'm,'a,'i,'n # Function Name
+; CHECK-NEXT:  .byte   "main"  # Function Name
 ; CHECK-NEXT:  L..func_end1:
 ; CHECK-NEXT:  # -- End function
 ; CHECK-NEXT:  L..sec_end0:
@@ -271,10 +271,10 @@
 ; CHECK-NEXT:  .byte   0
 ; CHECK-NEXT:  .byte   0
 ; CHECK-NEXT:  .byte   1
-; CHECK-NEXT:  .byte   'd,'e,'b,'u,'g
+; CHECK-NEXT:  .byte   "debug"
 ; CHECK-NEXT:  .byte   0
 ; CHECK-NEXT:  .byte   0
-; CHECK-NEXT:  .byte   '2,'.,'c
+; CHECK-NEXT:  .byte   "2.c"
 ; CHECK-NEXT:  .byte   0
 ; CHECK-NEXT:  .byte   1
 ; CHECK-NEXT:  .byte   0
Index: llvm/test/DebugInfo/XCOFF/empty.ll
===
--- llvm/test/DebugInfo/XCOFF/empty.ll
+++ llvm/test/DebugInfo/XCOFF/empty.ll
@@ -71,7 +71,7 @@
 ; ASM32-NEXT:  .byte   0x01# NumberOfFPParms = 0, +HasParmsOnStack
 ; ASM32-NEXT:  .vbyte  4, L..main0-.main   # Function size
 ; ASM32-NEXT:  .vbyte  2, 0x0004   # Function name len = 4
-;

[PATCH] D102812: [clang] Don't pass multiple backend options if mixing -mimplicit-it and -Wa,-mimplicit-it

2021-05-20 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: clang/lib/Driver/ToolChains/Clang.cpp:2369
 
-static bool AddARMImplicitITArgs(const ArgList &Args, ArgStringList &CmdArgs,
+static bool CheckARMImplicitITArg(StringRef Value) {
+  return Value == "always" || Value == "never" || Value == "arm" ||

Use `functionName` for new functions.



Comment at: clang/test/Driver/arm-target-as-mimplicit-it.s:39
 // ALWAYS: "-mllvm" "-arm-implicit-it=always"
+// ALWAYS-NOT: "-arm-implicit-it={{.*}}"
 // NEVER: "-mllvm" "-arm-implicit-it=never"

mstorsjo wrote:
> DavidSpickett wrote:
> > mstorsjo wrote:
> > > This pattern wouldn't detct if there's e.g. `-arm-implicit-it=never 
> > > -arm-implicit-it=always`, but I added test cases that pass 
> > > `-Wa,-mimplicit-it=always` twice, where this check should be able to 
> > > verify that we only output it once.
> > Could you do:
> > ```
> > // ALWAYS-NOT: "-mllvm" "-arm-implicit-it=never"
> > // ALWAYS: "-mllvm" "-arm-implicit-it=always"
> > ```
> > 
> > Not sure if doing the NOT moves the check forward to beyond where the 
> > always would be.
> Thanks, I think that could work to further guard against that case.
The NOT pattern can omit the value to catch more cases.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102812

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


[PATCH] D102801: [CUDA][HIP] Fix device variables used by host

2021-05-20 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl updated this revision to Diff 346796.
yaxunl retitled this revision from "[CUDA][HIP] Fix implicit constant variable" 
to "[CUDA][HIP] Fix device variables used by host".
yaxunl edited the summary of this revision.
yaxunl added a comment.

Fix the other regression


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

https://reviews.llvm.org/D102801

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/CodeGen/CGDeclCXX.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/Sema/SemaCUDA.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/AST/ast-dump-constant-var.cu
  clang/test/CodeGenCUDA/host-used-device-var.cu
  clang/test/SemaCUDA/static-device-var.cu

Index: clang/test/SemaCUDA/static-device-var.cu
===
--- clang/test/SemaCUDA/static-device-var.cu
+++ clang/test/SemaCUDA/static-device-var.cu
@@ -1,16 +1,14 @@
 // REQUIRES: x86-registered-target
 // REQUIRES: amdgpu-registered-target
 
-// RUN: %clang_cc1 -triple nvptx -fcuda-is-device \
-// RUN:-emit-llvm -o - %s -fsyntax-only -verify=dev
+// RUN: %clang_cc1 -triple nvptx -fcuda-is-device -std=c++11 \
+// RUN:-emit-llvm -o - %s -fsyntax-only -verify=dev,com
 
-// RUN: %clang_cc1 -triple x86_64-gnu-linux \
-// RUN:-emit-llvm -o - %s -fsyntax-only -verify=host
+// RUN: %clang_cc1 -triple x86_64-gnu-linux -std=c++11 \
+// RUN:-emit-llvm -o - %s -fsyntax-only -verify=host,com
 
 // Checks allowed usage of file-scope and function-scope static variables.
 
-// host-no-diagnostics
-
 #include "Inputs/cuda.h"
 
 // Checks static variables are allowed in device functions.
@@ -42,6 +40,28 @@
   // dev-error@-1 {{reference to __host__ variable 'z' in __global__ function}}
 }
 
+// Check dynamic initialization of static device variable is not allowed.
+
+namespace TestStaticVarInLambda {
+class A {
+public:
+  A(char *);
+};
+class B {
+public:
+  __device__ B(char *);
+};
+void fun() {
+  (void) [](char *c) {
+static A var1(c);
+static __device__ B var2(c);
+// com-error@-1 {{dynamic initialization is not supported for __device__, __constant__, __shared__, and __managed__ variables}}
+(void) var1;
+(void) var2;
+  };
+}
+}
+
 int* getDeviceSymbol(int *x);
 
 void foo() {
Index: clang/test/CodeGenCUDA/host-used-device-var.cu
===
--- clang/test/CodeGenCUDA/host-used-device-var.cu
+++ clang/test/CodeGenCUDA/host-used-device-var.cu
@@ -66,30 +66,148 @@
 template 
 __device__ func_t p_add_func = add_func;
 
+// Check non-constant constexpr variables ODR-used by host code only is not emitted.
+// DEV-NEG-NOT: constexpr_var1a
+// DEV-NEG-NOT: constexpr_var1b
+constexpr int constexpr_var1a = 1;
+inline constexpr int constexpr_var1b = 1;
+
+// Check constant constexpr variables ODR-used by host code only.
+// Non-inline constexpr variable has internal linkage, therefore it is not accessible by host and not kept.
+// Inline constexpr variable has linkonce_ord linkage, therefore it can be accessed by host and kept.
+// DEV-NEG-NOT: constexpr_var2a
+// DEV-DAG: @constexpr_var2b = linkonce_odr addrspace(4) externally_initialized constant i32 2
+__constant__ constexpr int constexpr_var2a = 2;
+inline __constant__ constexpr int constexpr_var2b = 2;
+
 void use(func_t p);
-void use(int *p);
+__host__ __device__ void use(const int *p);
 
+// Check static device variable in host function.
+// DEV-DAG:  @_ZZ4fun1vE11static_var1 = dso_local addrspace(1) externally_initialized global i32 3
 void fun1() {
+  static __device__ int static_var1 = 3;
   use(&u1);
   use(&u2);
   use(&u3);
   use(&ext_var);
   use(&inline_var);
   use(p_add_func);
+  use(&constexpr_var1a);
+  use(&constexpr_var1b);
+  use(&constexpr_var2a);
+  use(&constexpr_var2b);
+  use(&static_var1);
+}
+
+// Check static variable in host device function.
+// DEV-DAG:  @_ZZ4fun2vE11static_var2 = internal addrspace(1) global i32 4
+// DEV-DAG:  @_ZZ4fun2vE11static_var3 = dso_local addrspace(1) global i32 4
+__host__ __device__ void fun2() {
+  static int static_var2 = 4;
+  static __device__ int static_var3 = 4;
+  use(&static_var2);
+  use(&static_var3);
 }
 
 __global__ void kern1(int **x) {
   *x = &u4;
+  fun2();
+}
+
+// Check static variables of lambda functions.
+
+// Lambda functions are implicit host device functions.
+// Default static variables in lambda functions should be treated
+// as host variables on host side, therefore should not be forced
+// to be emitted on device.
+
+// DEV-DAG: @_ZZZN21TestStaticVarInLambda3funEvENKUlPcE_clES0_E4var2 = dso_local addrspace(1) externally_initialized global i32 5
+// DEV-NEG-NOT: @_ZZZN21TestStaticVarInLambda3funEvENKUlPcE_clES0_E4var1
+namespace TestStaticVarInLambda {
+class A {
+public:
+  A(char *);
+};
+void fun() {
+  (void) [](char *c) {
+static A var1(c);
+static __device__ int var2 = 5;
+(void) var1;
+(void) var2;
+  };
+}
+}
+
+

[PATCH] D102592: [sanitizer] Caught global buffer underflow for first variable

2021-05-20 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka requested changes to this revision.
vitalybuka added a comment.
This revision now requires changes to proceed.

So I will hide it from "Ready to Review" list.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102592

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


[PATCH] D102517: [clang] Add support for the "abstract" contextual keyword of MSVC

2021-05-20 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added a comment.

@hans, can you review this? I am trying to offload clang reviews.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102517

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


[PATCH] D102801: [CUDA][HIP] Fix device variables used by host

2021-05-20 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl marked 2 inline comments as done.
yaxunl added a comment.

In D102801#2769936 , @tra wrote:

> This patch does not appear to fix the second regression introduced by the 
> D102237 .
>
> Trying to compile the following code triggers an assertion in CGExpr.cpp:
>
>   class a {
>   public:
> a(char *);
>   };
>   void b() {
> [](char *c) {
>   static a d(c);
>   d;
> };
>   }
>
> With assertions disabled it eventually leads to a different error: 
> `Module has a nontrivial global ctor, which NVPTX does not support.`
> https://godbolt.org/z/sYE1dKr1W

The root cause is similar to the last regression. Basically when a variable is 
emitted on both sides but as different entities, we should not treat it as a 
device variable on host side. I have updated the patch to fix both regressions.




Comment at: clang/lib/CodeGen/CodeGenModule.cpp:2386
+  };
+  if (!HasImplicitConstantAttr(V))
+DeferredDeclsToEmit.push_back(V);

tra wrote:
> IIUIC, The idea here is that we do not want to emit `constexpr int foo;` on 
> device, even if we happen to ODR-use it there.
> And the way we detect this is by checking for implicit `__constant__` we 
> happen to add to constexpr variables.
> 
> I think this may be relying on the implementation details too much. It also 
> makes compiler's behavior somewhat surprising -- we would potentially emit 
> other variables that do not get any device attributes attribute, but would 
> not emit the variables with implicit `__constant__`, which is a device 
> attribute.
> 
> I'm not sure if we have any good options here. This may be an acceptable 
> compromise, but I wonder if there's a better way to deal with this.
> 
> That said, this patch is OK to fix the regression we have now, but we may 
> need to revisit this.
> 
we need to differentiate `constexpr int a` and `__constant__ constexpr int a`, 
since the former is emitted on both sides, and the later is only emitted on 
device side. It seems the only way to differentiate them is to check whether 
the constant attribute is explicit or not.



Comment at: clang/test/CodeGenCUDA/host-used-device-var.cu:103-131
+// Check implicit constant variable ODR-used by host code is not emitted.
+// DEV-NEG-NOT: _ZN16TestConstexprVar1oE
+namespace TestConstexprVar {
+char o;
+class ou {
+public:
+  ou(char) { __builtin_strlen(&o); }

tra wrote:
> This definitely needs some comments. Otherwise this is nearly 
> incomprehensible and it's impossible to tell what's going on.
done


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

https://reviews.llvm.org/D102801

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


[PATCH] D102801: [CUDA][HIP] Fix device variables used by host

2021-05-20 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl marked 2 inline comments as done.
yaxunl added a comment.

In D102801#2769619 , @tra wrote:

> Tentative LGTM as we need it to fix the regression soon.
>
> Summoning @rsmith for the 'big picture' opinion. 
> While the patch may fix this particular regression, I wonder if there's a 
> better way to deal with this. We're growing a bit too many nuances that would 
> be hard to explain and may cause more corner cases to appear.

In the updated patch I have a simpler solution which is easier to explain to 
the users. Basically we classify variables by how they are emitted: device side 
only, host side only, both sides as different entities (e.g. default constexpr 
var), and both sides as unified entity (e.g. managed var). For variables 
emitted on both sides as separate entities, we have limited knowledge and we 
limit what we can do for them. I think users should understand the compiler's 
limitation in such cases. And they can easily workaround that by making the 
variable explicitly device variable.


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

https://reviews.llvm.org/D102801

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


[clang] 8f20ac9 - [PGO] Don't reference functions unless value profiling is enabled

2021-05-20 Thread Reid Kleckner via cfe-commits

Author: Reid Kleckner
Date: 2021-05-20T11:09:24-07:00
New Revision: 8f20ac9595c8b279641dace6f212b8a9673b24e4

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

LOG: [PGO] Don't reference functions unless value profiling is enabled

This reduces the size of chrome.dll.pdb built with optimizations,
coverage, and line table info from 4,690,210,816 to 2,181,128,192, which
makes it possible to fit under the 4GB limit.

This change can greatly reduce binary size in coverage builds, which do
not need value profiling. IR PGO builds are unaffected. There is a minor
behavior change for frontend PGO.

PGO and coverage both use InstrProfiling to create profile data with
counters. PGO records the address of each function in the __profd_
global. It is used later to map runtime function pointer values back to
source-level function names. Coverage does not appear to use this
information.

Recording the address of every function with code coverage drastically
increases code size. Consider this program:

  void foo();
  void bar();
  inline void inlineMe(int x) {
if (x > 0)
  foo();
else
  bar();
  }
  int getVal();
  int main() { inlineMe(getVal()); }

With code coverage, the InstrProfiling pass runs before inlining, and it
captures the address of inlineMe in the __profd_ global. This greatly
increases code size, because now the compiler can no longer delete
trivial code.

One downside to this approach is that users of frontend PGO must apply
the -mllvm -enable-value-profiling flag globally in TUs that enable PGO.
Otherwise, some inline virtual method addresses may not be recorded and
will not be able to be promoted. My assumption is that this mllvm flag
is not popular, and most frontend PGO users don't enable it.

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

Added: 


Modified: 
clang/lib/CodeGen/CodeGenModule.cpp
clang/lib/CodeGen/CodeGenPGO.cpp
clang/lib/CodeGen/CodeGenPGO.h
compiler-rt/test/profile/instrprof-value-prof-2.c
compiler-rt/test/profile/instrprof-value-prof.c
llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index e38dee92db293..03920982ee086 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -511,6 +511,7 @@ void CodeGenModule::Release() {
   EmitGlobalAnnotations();
   EmitStaticExternCAliases();
   EmitDeferredUnusedCoverageMappings();
+  CodeGenPGO(*this).setValueProfilingFlag(getModule());
   if (CoverageMapping)
 CoverageMapping->emit();
   if (CodeGenOpts.SanitizeCfiCrossDso) {

diff  --git a/clang/lib/CodeGen/CodeGenPGO.cpp 
b/clang/lib/CodeGen/CodeGenPGO.cpp
index 49b38a404f5dc..d828ac0eb5e98 100644
--- a/clang/lib/CodeGen/CodeGenPGO.cpp
+++ b/clang/lib/CodeGen/CodeGenPGO.cpp
@@ -962,6 +962,12 @@ void CodeGenPGO::emitCounterIncrement(CGBuilderTy 
&Builder, const Stmt *S,
 makeArrayRef(Args));
 }
 
+void CodeGenPGO::setValueProfilingFlag(llvm::Module &M) {
+  if (CGM.getCodeGenOpts().hasProfileClangInstr())
+M.addModuleFlag(llvm::Module::Warning, "EnableValueProfiling",
+uint32_t(EnableValueProfiling));
+}
+
 // This method either inserts a call to the profile run-time during
 // instrumentation or puts profile data into metadata for PGO use.
 void CodeGenPGO::valueProfile(CGBuilderTy &Builder, uint32_t ValueKind,

diff  --git a/clang/lib/CodeGen/CodeGenPGO.h b/clang/lib/CodeGen/CodeGenPGO.h
index 906c5e406d77c..f740692ac205b 100644
--- a/clang/lib/CodeGen/CodeGenPGO.h
+++ b/clang/lib/CodeGen/CodeGenPGO.h
@@ -87,6 +87,10 @@ class CodeGenPGO {
   // Insert instrumentation or attach profile metadata at value sites
   void valueProfile(CGBuilderTy &Builder, uint32_t ValueKind,
 llvm::Instruction *ValueSite, llvm::Value *ValuePtr);
+
+  // Set a module flag indicating if value profiling is enabled.
+  void setValueProfilingFlag(llvm::Module &M);
+
 private:
   void setFuncName(llvm::Function *Fn);
   void setFuncName(StringRef Name, llvm::GlobalValue::LinkageTypes Linkage);

diff  --git a/compiler-rt/test/profile/instrprof-value-prof-2.c 
b/compiler-rt/test/profile/instrprof-value-prof-2.c
index 88a2de039979e..abc990ac8b052 100644
--- a/compiler-rt/test/profile/instrprof-value-prof-2.c
+++ b/compiler-rt/test/profile/instrprof-value-prof-2.c
@@ -1,4 +1,4 @@
-// RUN: %clang_profgen -O2 -o %t %s
+// RUN: %clang_profgen -mllvm -enable-value-profiling -O2 -o %t %s
 // RUN: env LLVM_PROFILE_FILE=%t.profraw %run %t
 // RUN: llvm-profdata merge -o %t.profdata %t.profraw
 // RUN: llvm-profdata show --all-functions -ic-targets  %t.profdata > %t.out

diff  --git a/compiler-rt/test/profile/instrprof-value-prof.c 
b/compiler-rt/test/profi

[PATCH] D102818: [PGO] Don't reference functions unless value profiling is enabled

2021-05-20 Thread Reid Kleckner 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 rG8f20ac9595c8: [PGO] Don't reference functions unless 
value profiling is enabled (authored by rnk).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102818

Files:
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenPGO.cpp
  clang/lib/CodeGen/CodeGenPGO.h
  compiler-rt/test/profile/instrprof-value-prof-2.c
  compiler-rt/test/profile/instrprof-value-prof.c
  llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp


Index: llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
===
--- llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
+++ llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
@@ -748,7 +748,26 @@
   return (Prefix + Name + "." + Twine(FuncHash)).str();
 }
 
+static uint64_t getIntModuleFlagOrZero(Module *M, StringRef Flag) {
+  auto *MD = dyn_cast_or_null(M->getModuleFlag(Flag));
+  if (!MD)
+return 0;
+
+  // If the flag is a ConstantAsMetadata, it should be an integer representable
+  // in 64-bits.
+  return cast(MD->getValue())->getZExtValue();
+}
+
 static inline bool shouldRecordFunctionAddr(Function *F) {
+  // Only record function addresses if IR PGO is enabled or if clang value
+  // profiling is enabled. Recording function addresses greatly increases 
object
+  // file size, because it prevents the inliner from deleting functions that
+  // have been inlined everywhere.
+  if (!isIRPGOFlagSet(F->getParent()) &&
+  getIntModuleFlagOrZero(F->getParent(), "EnableValueProfiling") == 0) {
+return false;
+  }
+
   // Check the linkage
   bool HasAvailableExternallyLinkage = F->hasAvailableExternallyLinkage();
   if (!F->hasLinkOnceLinkage() && !F->hasLocalLinkage() &&
Index: compiler-rt/test/profile/instrprof-value-prof.c
===
--- compiler-rt/test/profile/instrprof-value-prof.c
+++ compiler-rt/test/profile/instrprof-value-prof.c
@@ -1,4 +1,4 @@
-// RUN: %clang_profgen -mllvm -vp-static-alloc=false  -O2 -o %t %s
+// RUN: %clang_profgen -mllvm -enable-value-profiling -mllvm 
-vp-static-alloc=false  -O2 -o %t %s
 // RUN: env LLVM_PROFILE_FILE=%t.profraw %run %t
 // RUN: env LLVM_PROFILE_FILE=%t-2.profraw %run %t DO_NOT_INSTRUMENT
 // RUN: llvm-profdata merge -o %t.profdata %t.profraw
Index: compiler-rt/test/profile/instrprof-value-prof-2.c
===
--- compiler-rt/test/profile/instrprof-value-prof-2.c
+++ compiler-rt/test/profile/instrprof-value-prof-2.c
@@ -1,4 +1,4 @@
-// RUN: %clang_profgen -O2 -o %t %s
+// RUN: %clang_profgen -mllvm -enable-value-profiling -O2 -o %t %s
 // RUN: env LLVM_PROFILE_FILE=%t.profraw %run %t
 // RUN: llvm-profdata merge -o %t.profdata %t.profraw
 // RUN: llvm-profdata show --all-functions -ic-targets  %t.profdata > %t.out
Index: clang/lib/CodeGen/CodeGenPGO.h
===
--- clang/lib/CodeGen/CodeGenPGO.h
+++ clang/lib/CodeGen/CodeGenPGO.h
@@ -87,6 +87,10 @@
   // Insert instrumentation or attach profile metadata at value sites
   void valueProfile(CGBuilderTy &Builder, uint32_t ValueKind,
 llvm::Instruction *ValueSite, llvm::Value *ValuePtr);
+
+  // Set a module flag indicating if value profiling is enabled.
+  void setValueProfilingFlag(llvm::Module &M);
+
 private:
   void setFuncName(llvm::Function *Fn);
   void setFuncName(StringRef Name, llvm::GlobalValue::LinkageTypes Linkage);
Index: clang/lib/CodeGen/CodeGenPGO.cpp
===
--- clang/lib/CodeGen/CodeGenPGO.cpp
+++ clang/lib/CodeGen/CodeGenPGO.cpp
@@ -962,6 +962,12 @@
 makeArrayRef(Args));
 }
 
+void CodeGenPGO::setValueProfilingFlag(llvm::Module &M) {
+  if (CGM.getCodeGenOpts().hasProfileClangInstr())
+M.addModuleFlag(llvm::Module::Warning, "EnableValueProfiling",
+uint32_t(EnableValueProfiling));
+}
+
 // This method either inserts a call to the profile run-time during
 // instrumentation or puts profile data into metadata for PGO use.
 void CodeGenPGO::valueProfile(CGBuilderTy &Builder, uint32_t ValueKind,
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -511,6 +511,7 @@
   EmitGlobalAnnotations();
   EmitStaticExternCAliases();
   EmitDeferredUnusedCoverageMappings();
+  CodeGenPGO(*this).setValueProfilingFlag(getModule());
   if (CoverageMapping)
 CoverageMapping->emit();
   if (CodeGenOpts.SanitizeCfiCrossDso) {


Index: llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
===
---

[PATCH] D102742: [IR] make stack-protector-guard-* flags into module attrs

2021-05-20 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers updated this revision to Diff 346800.
nickdesaulniers added a comment.

- fix lints


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102742

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/CodeGen/stack-protector-guard.c
  llvm/include/llvm/CodeGen/CommandFlags.h
  llvm/include/llvm/IR/Module.h
  llvm/include/llvm/Target/TargetOptions.h
  llvm/lib/CodeGen/CommandFlags.cpp
  llvm/lib/CodeGen/StackProtector.cpp
  llvm/lib/IR/Module.cpp
  llvm/lib/Target/AArch64/AArch64InstrInfo.cpp
  llvm/lib/Target/X86/X86ISelLowering.cpp
  llvm/test/CodeGen/AArch64/stack-guard-sysreg.ll
  llvm/test/CodeGen/X86/stack-protector-3.ll

Index: llvm/test/CodeGen/X86/stack-protector-3.ll
===
--- llvm/test/CodeGen/X86/stack-protector-3.ll
+++ llvm/test/CodeGen/X86/stack-protector-3.ll
@@ -1,10 +1,18 @@
-; RUN: llc -mtriple=x86_64-pc-linux-gnu -o - < %s | FileCheck --check-prefix=CHECK-TLS-FS-40 %s
-; RUN: llc -mtriple=x86_64-pc-linux-gnu -stack-protector-guard=tls -o - < %s | FileCheck --check-prefix=CHECK-TLS-FS-40 %s
-; RUN: llc -mtriple=x86_64-pc-linux-gnu -stack-protector-guard=global -o - < %s | FileCheck --check-prefix=CHECK-GLOBAL %s
-; RUN: llc -mtriple=x86_64-pc-linux-gnu -stack-protector-guard-reg=fs -o - < %s | FileCheck --check-prefix=CHECK-TLS-FS-40 %s
-; RUN: llc -mtriple=x86_64-pc-linux-gnu -stack-protector-guard-reg=gs -o - < %s | FileCheck --check-prefix=CHECK-GS %s
-; RUN: llc -mtriple=x86_64-pc-linux-gnu -stack-protector-guard-offset=20 -o - < %s | FileCheck --check-prefix=CHECK-OFFSET %s
-; RUN: llc -mtriple=x86_64-pc-linux-gnu -stack-protector-guard-offset=-20 -o - < %s | FileCheck --check-prefix=CHECK-NEGATIVE-OFFSET %s
+; RUN: split-file %s %t
+; RUN: cat %t/main.ll %t/a.ll > %t/a2.ll
+; RUN: cat %t/main.ll %t/b.ll > %t/b2.ll
+; RUN: cat %t/main.ll %t/c.ll > %t/c2.ll
+; RUN: cat %t/main.ll %t/d.ll > %t/d2.ll
+; RUN: cat %t/main.ll %t/e.ll > %t/e2.ll
+; RUN: cat %t/main.ll %t/f.ll > %t/f2.ll
+; RUN: cat %t/main.ll %t/g.ll > %t/g2.ll
+; RUN: llc -mtriple=x86_64-pc-linux-gnu -o - < %t/a2.ll | FileCheck --check-prefix=CHECK-TLS-FS-40 %s
+; RUN: llc -mtriple=x86_64-pc-linux-gnu -o - < %t/b2.ll | FileCheck --check-prefix=CHECK-TLS-FS-40 %s
+; RUN: llc -mtriple=x86_64-pc-linux-gnu -o - < %t/c2.ll | FileCheck --check-prefix=CHECK-GLOBAL %s
+; RUN: llc -mtriple=x86_64-pc-linux-gnu -o - < %t/d2.ll | FileCheck --check-prefix=CHECK-TLS-FS-40 %s
+; RUN: llc -mtriple=x86_64-pc-linux-gnu -o - < %t/e2.ll | FileCheck --check-prefix=CHECK-GS %s
+; RUN: llc -mtriple=x86_64-pc-linux-gnu -o - < %t/f2.ll | FileCheck --check-prefix=CHECK-OFFSET %s
+; RUN: llc -mtriple=x86_64-pc-linux-gnu -o - < %t/g2.ll | FileCheck --check-prefix=CHECK-NEGATIVE-OFFSET %s
 
 ; CHECK-TLS-FS-40:   movq%fs:40, %rax
 ; CHECK-TLS-FS-40:   movq%fs:40, %rax
@@ -47,6 +55,8 @@
 ; CHECK-GLOBAL-NEXT:  .cfi_def_cfa_offset 32
 ; CHECK-GLOBAL-NEXT:  callq   __stack_chk_fail
 
+;--- main.ll
+
 ; ModuleID = 't.c'
 @.str = private unnamed_addr constant [14 x i8] c"stackoverflow\00", align 1
 @a = dso_local local_unnamed_addr global i8* null, align 8
@@ -75,3 +85,23 @@
 attributes #0 = { nounwind sspreq uwtable writeonly "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="none" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" "unsafe-fp-math"="false" "use-soft-float"="false" }
 attributes #1 = { argmemonly nounwind willreturn }
 attributes #2 = { nounwind }
+
+;--- a.ll
+;--- b.ll
+!llvm.module.flags = !{!1}
+!1 = !{i32 2, !"stack-protector-guard", !"tls"}
+;--- c.ll
+!llvm.module.flags = !{!1}
+!1 = !{i32 2, !"stack-protector-guard", !"global"}
+;--- d.ll
+!llvm.module.flags = !{!1}
+!1 = !{i32 2, !"stack-protector-guard-reg", !"fs"}
+;--- e.ll
+!llvm.module.flags = !{!1}
+!1 = !{i32 2, !"stack-protector-guard-reg", !"gs"}
+;--- f.ll
+!llvm.module.flags = !{!1}
+!1 = !{i32 2, !"stack-protector-guard-offset", i32 20}
+;--- g.ll
+!llvm.module.flags = !{!1}
+!1 = !{i32 2, !"stack-protector-guard-offset", i32 -20}
Index: llvm/test/CodeGen/AArch64/stack-guard-sysreg.ll
===
--- llvm/test/CodeGen/AArch64/stack-guard-sysreg.ll
+++ llvm/test/CodeGen/AArch64/stack-guard-sysreg.ll
@@ -1,46 +1,39 @@
-; RUN: llc %s --stack-protector-guard=sysreg \
-; RUN:   --stack-protector-guard-reg=sp_el0 \
-; RUN:   --stack-protector-guard-offset=0 -verify-machineinstrs -o - | \
+; RUN: split-file %s %t
+; RUN: cat %t/main.ll %t/a.ll > %t/a2.ll
+; RUN: ca

[PATCH] D102801: [CUDA][HIP] Fix device variables used by host

2021-05-20 Thread Artem Belevich via Phabricator via cfe-commits
tra added a comment.

In D102801#2771664 , @yaxunl wrote:

> In the updated patch I have a simpler solution which is easier to explain to 
> the users. Basically we classify variables by how they are emitted: device 
> side only, host side only, both sides as different entities (e.g. default 
> constexpr var), and both sides as unified entity (e.g. managed var). For 
> variables emitted on both sides as separate entities, we have limited 
> knowledge and we limit what we can do for them. I think users should 
> understand the compiler's limitation in such cases. And they can easily 
> workaround that by making the variable explicitly device variable.

This is really nice.

Let me test it internally and see if anything breaks.




Comment at: clang/include/clang/Sema/Sema.h:12066
 
+  enum CUDAVariableTarget {
+CVT_Device,  /// Device only

Wasn't there another kind, where the variable is emitted on the host with 
device-side shadow? I vaguely recall it had something to do with textures.



Comment at: clang/include/clang/Sema/Sema.h:12067
+  enum CUDAVariableTarget {
+CVT_Device,  /// Device only
+CVT_Host,/// Host only

I think we should mention the host-side shadows, too.



Comment at: clang/lib/Sema/SemaCUDA.cpp:148-149
+return CVT_Unified;
+  if (hasImplicitAttr(Var))
+return CVT_Both;
+  if (Var->hasAttr() || Var->hasAttr() ||

I'm still not a fan of relying on a implicit __constant__.
Can we change it to more direct `is-a-constexpr && 
!has-explicit-device-side-attr` ?
We may eventually consider relaxing this to `can-be-const-evaluated` and allow 
const vars with known values.



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

https://reviews.llvm.org/D102801

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


[PATCH] D102814: [AIX] Print printable byte list as quoted string

2021-05-20 Thread Jinsong Ji via Phabricator via cfe-commits
jsji added inline comments.



Comment at: llvm/lib/MC/MCAsmStreamer.cpp:1008
+  for (const unsigned char C : Data) {
+if (!isPrint(C))
+  return false;

This still need some slight change to deal with the ending 0 so that we can 
handle .string.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102814

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


[PATCH] D102791: [WebAssembly] Warn on exception spec for Emscripten EH

2021-05-20 Thread Derek Schuff via Phabricator via cfe-commits
dschuff accepted this revision.
dschuff added a comment.

Got it, this makes sense to me too. And since it can be turned off, I'm not too 
worried about annoying users.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102791

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


[PATCH] D97183: [analyzer] Add NoteTag for smart-ptr get()

2021-05-20 Thread Deep Majumder via Phabricator via cfe-commits
RedDocMD updated this revision to Diff 346808.
RedDocMD marked 10 inline comments as done.
RedDocMD added a comment.

Code clean up


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97183

Files:
  clang/lib/StaticAnalyzer/Checkers/SmartPtr.h
  clang/lib/StaticAnalyzer/Checkers/SmartPtrChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
  clang/test/Analysis/smart-ptr-text-output.cpp

Index: clang/test/Analysis/smart-ptr-text-output.cpp
===
--- clang/test/Analysis/smart-ptr-text-output.cpp
+++ clang/test/Analysis/smart-ptr-text-output.cpp
@@ -306,10 +306,81 @@
 };
 
 void derefAfterBranchingOnUnknownInnerPtr(std::unique_ptr P) {
-  A *RP = P.get();
+  A *RP = P.get(); // expected-note {{Obtained null inner pointer from 'P'}}
   if (!RP) { // expected-note {{Assuming 'RP' is null}}
 // expected-note@-1 {{Taking true branch}}
 P->foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}}
 // expected-note@-1{{Dereference of null smart pointer 'P'}}
   }
 }
+
+void multpleDeclsWithGet(std::unique_ptr P) {
+  A *dummy1 = nullptr, *RP = P.get(), *dummy2; // expected-note {{Obtained null inner pointer from 'P'}}
+  if (!RP) {   // expected-note {{Assuming 'RP' is null}}
+// expected-note@-1 {{Taking true branch}}
+P->foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}}
+// expected-note@-1{{Dereference of null smart pointer 'P'}}
+  }
+}
+
+void multipleGetsShouldNotAllHaveNotes(std::unique_ptr P) {
+  A *RP = P.get(); // expected-note {{Obtained null inner pointer from 'P'}}
+  A *dummy1 = P.get();
+  A *dummy2 = P.get();
+  if (!RP) { // expected-note {{Assuming 'RP' is null}}
+// expected-note@-1 {{Taking true branch}}
+P->foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}}
+// expected-note@-1{{Dereference of null smart pointer 'P'}}
+  }
+}
+
+void getShouldNotAlwaysLeaveANote() {
+  std::unique_ptr P; // expected-note {{Default constructed smart pointer 'P' is null}}
+  A *a = P.get();
+  P->foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}}
+// expected-note@-1{{Dereference of null smart pointer 'P'}}
+}
+
+void getShouldNotLeaveANoteAfterReset(std::unique_ptr P) {
+  A *a = P.get();
+  P.reset(); // expected-note {{Smart pointer 'P' reset using a null value}}
+  P->foo();  // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}}
+ // expected-note@-1{{Dereference of null smart pointer 'P'}}
+}
+
+void getShouldNotLeaveNoteWhenPtrNotUsed(std::unique_ptr P) {
+  A *a = P.get();
+  if (!P) { // expected-note {{Taking true branch}}
+// expected-note@-1 {{Assuming smart pointer 'P' is null}}
+P->foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}}
+// expected-note@-1{{Dereference of null smart pointer 'P'}}
+  }
+}
+
+void getShouldLeaveANoteWithWhileLoop(std::unique_ptr P) {
+  A *RP = P.get(); // expected-note {{Obtained null inner pointer from 'P'}}
+  while (!RP) {// expected-note {{Assuming 'RP' is null}}
+// expected-note@-1 {{Loop condition is true.  Entering loop body}}
+P->foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}}
+// expected-note@-1{{Dereference of null smart pointer 'P'}}
+  }
+}
+
+void getShouldLeaveANoteWithForLoop(std::unique_ptr P) {
+  for (A *RP = P.get(); !RP;) { // expected-note {{Assuming 'RP' is null}}
+// expected-note@-1 {{Loop condition is true.  Entering loop body}}
+// expected-note@-2 {{Obtained null inner pointer from 'P'}}
+P->foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}}
+// expected-note@-1{{Dereference of null smart pointer 'P'}}
+  }
+}
+
+void getShouldLeaveNoteOnChaining(std::unique_ptr P) {
+  A *praw = P.get(), *other; // expected-note {{Obtained null inner pointer from 'P'}}
+  other = praw;  // expected-note {{Obtained null value here}}
+  if (!other) {  // expected-note {{Assuming 'other' is null}}
+// expected-note@-1 {{Taking true branch}}
+P->foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}}
+// expected-note@-1{{Dereference of null smart pointer 'P'}}
+  }
+}
\ No newline at end of file
Index: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
+++ clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
@@ -26,6 +26,7 @@
 #include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
 #include "clang/StaticAnalyzer/Core/

[PATCH] D97183: [analyzer] Add NoteTag for smart-ptr get()

2021-05-20 Thread Deep Majumder via Phabricator via cfe-commits
RedDocMD added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp:141-163
+auto bugReportOnGet = [&](const Expr *E) -> auto {
+  if (const auto *MCE = llvm::dyn_cast(E)) {
+const auto *Method = MCE->getMethodDecl();
+const auto *Record = MCE->getRecordDecl();
+if (Method->getName() == "get" &&
+Record->getDeclContext()->isStdNamespace() &&
+Record->getName() == "unique_ptr") {

vsavchenko wrote:
> Is there any reason it's not a method of `FindWhereConstrained`?
Not really.



Comment at: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp:179-180
+  // P.get()
+  if (const auto *InnerCastExpr =
+  llvm::dyn_cast(Sub)) {
+Sub = InnerCastExpr->getSubExpr();

vsavchenko wrote:
> I think it's better to `IgnoreParensAndCasts` instead of manual traversal.
What is IgnoreParensAndCasts`? I didn't find it in the source code anywhere 
(ripgrep, that is).



Comment at: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp:227
+if (const auto *DS = llvm::dyn_cast(S)) {
+  const Decl *D = DS->getSingleDecl();
+  if (const auto *VD = llvm::dyn_cast(D)) {

vsavchenko wrote:
> So, situations like `int *a = nullptr, *b = smart.get();` are not supported?
No it works even in that case (I have added a test for that). It's got to do 
with how the AST data structures are (`int *a = nullptr, *b = smart.get();` is 
considered a single decl).



Comment at: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp:229
+  if (const auto *VD = llvm::dyn_cast(D)) {
+for (const auto *I : PtrsTrackedAndConstrained) {
+  if (I->getName() == VD->getName()) {

vsavchenko wrote:
> `llvm::find_if`
Not sure if that'll work neatly since I actually need the return value of the 
predicate function (the report).



Comment at: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp:238-245
+}
+  }
+}
+  }
+}
+  }
+}

vsavchenko wrote:
> This level of nestedness is frowned upon. It is a good tell that the function 
> should be refactored.
> The following code:
> ```
> if (cond1) {
>   . . .
>   if (cond2) {
> . . .
> if (cond3) {
>   . . .
> }
>   }
> }
> return nullptr;
> ```
> can be refactored into:
> ```
> if (!cond1)
>   return nullptr;
> 
> . . .
> if (!cond2)
>   return nullptr;
> 
> . . .
> if (!cond3)
>   return nullptr;
> 
> . . .
> ```
> 
> It is easier to follow the logic if the function is composed in this manner 
> because from the very beginning you know that `else` with more stuff is not 
> going to follow.
Do you still think that's the case now? (After breaking it into functions).
I also think that for the sort of pattern matching we are doing in this patch, 
the nested if's make more sense.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97183

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


[PATCH] D102860: [clang][deps] NFC: Remove the `module-deps-to-rsp.py` utility

2021-05-20 Thread Georgeta Igna via Phabricator via cfe-commits
georgi_igna created this revision.
georgi_igna requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This was upstreamed in https://reviews.llvm.org/D102495 and put into 
`clang/utils`.

Merge commit 'b99b18eb59ed' from apple/main into internal/main


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D102860

Files:
  clang/test/ClangScanDeps/module-deps-to-rsp.py


Index: clang/test/ClangScanDeps/module-deps-to-rsp.py
===
--- clang/test/ClangScanDeps/module-deps-to-rsp.py
+++ /dev/null
@@ -1,76 +0,0 @@
-#!/usr/bin/env python
-
-import argparse
-import json
-import sys
-
-class ModuleNotFoundError(Exception):
-  def __init__(self, module_name):
-self.module_name = module_name
-
-class FullDeps:
-  def __init__(self):
-self.modules = dict()
-self.translation_units = str()
-
-def getModulePathArgs(modules, full_deps):
-  cmd = []
-  for md in modules:
-m = full_deps.modules[md['module-name'] + '-' + md['context-hash']]
-cmd += [u'-fmodule-map-file=' + m['clang-modulemap-file']]
-cmd += [u'-fmodule-file=' + md['module-name'] + '-' + md['context-hash'] + 
'.pcm']
-  return cmd
-
-def getCommandLineForModule(module_name, full_deps):
-  for m in full_deps.modules.values():
-if m['name'] == module_name:
-  module = m
-  break
-  else:
-raise ModuleNotFoundError(module_name)
-
-  cmd = m['command-line']
-  cmd += getModulePathArgs(m['clang-module-deps'], full_deps)
-  cmd += [u'-o', m['name'] + '-' + m['context-hash'] + '.pcm']
-  cmd += [m['clang-modulemap-file']]
-  
-  return cmd
-  
-def getCommandLineForTU(tu, full_deps):
-  cmd = tu['command-line']
-  cmd = [a for a in cmd if not (a.startswith('-fmodule-map-file=') or 
a.startswith('-fmodule-file='))]
-  cmd += getModulePathArgs(tu['clang-module-deps'], full_deps)
-  return cmd
-
-def parseFullDeps(json):
-  ret = FullDeps()
-  for m in json['modules']:
-ret.modules[m['name'] + '-' + m['context-hash']] = m
-  ret.translation_units = json['translation-units']
-  return ret
-
-def main():
-  parser = argparse.ArgumentParser()
-  parser.add_argument("full_deps_file", help="Path to the full dependencies 
json file",
-  type=str)
-  action = parser.add_mutually_exclusive_group(required=True)
-  action.add_argument("--module-name", help="The name of the module to get 
arguments for",
-  type=str)
-  action.add_argument("--tu-index", help="The index of the translation unit to 
get arguments for",
-  type=int)
-  args = parser.parse_args()
-  
-  full_deps = parseFullDeps(json.load(open(args.full_deps_file, 'r')))
-  
-  try:
-if args.module_name:
-  print(" ".join(getCommandLineForModule(args.module_name, full_deps)))
-
-elif args.tu_index != None:
-  print(" 
".join(getCommandLineForTU(full_deps.translation_units[args.tu_index], 
full_deps)))
-  except:
-print("Unexpected error:", sys.exc_info()[0])
-raise
-
-if __name__ == '__main__':
-  main()


Index: clang/test/ClangScanDeps/module-deps-to-rsp.py
===
--- clang/test/ClangScanDeps/module-deps-to-rsp.py
+++ /dev/null
@@ -1,76 +0,0 @@
-#!/usr/bin/env python
-
-import argparse
-import json
-import sys
-
-class ModuleNotFoundError(Exception):
-  def __init__(self, module_name):
-self.module_name = module_name
-
-class FullDeps:
-  def __init__(self):
-self.modules = dict()
-self.translation_units = str()
-
-def getModulePathArgs(modules, full_deps):
-  cmd = []
-  for md in modules:
-m = full_deps.modules[md['module-name'] + '-' + md['context-hash']]
-cmd += [u'-fmodule-map-file=' + m['clang-modulemap-file']]
-cmd += [u'-fmodule-file=' + md['module-name'] + '-' + md['context-hash'] + '.pcm']
-  return cmd
-
-def getCommandLineForModule(module_name, full_deps):
-  for m in full_deps.modules.values():
-if m['name'] == module_name:
-  module = m
-  break
-  else:
-raise ModuleNotFoundError(module_name)
-
-  cmd = m['command-line']
-  cmd += getModulePathArgs(m['clang-module-deps'], full_deps)
-  cmd += [u'-o', m['name'] + '-' + m['context-hash'] + '.pcm']
-  cmd += [m['clang-modulemap-file']]
-  
-  return cmd
-  
-def getCommandLineForTU(tu, full_deps):
-  cmd = tu['command-line']
-  cmd = [a for a in cmd if not (a.startswith('-fmodule-map-file=') or a.startswith('-fmodule-file='))]
-  cmd += getModulePathArgs(tu['clang-module-deps'], full_deps)
-  return cmd
-
-def parseFullDeps(json):
-  ret = FullDeps()
-  for m in json['modules']:
-ret.modules[m['name'] + '-' + m['context-hash']] = m
-  ret.translation_units = json['translation-units']
-  return ret
-
-def main():
-  parser = argparse.ArgumentParser()
-  parser.add_argument("full_deps_file", help="Path to the full dependencies json file",
-  type=str)
-  action = parser.ad

[PATCH] D97183: [analyzer] Add NoteTag for smart-ptr get()

2021-05-20 Thread Deep Majumder via Phabricator via cfe-commits
RedDocMD updated this revision to Diff 346817.
RedDocMD added a comment.

Removed un-necessary includes


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97183

Files:
  clang/lib/StaticAnalyzer/Checkers/SmartPtr.h
  clang/lib/StaticAnalyzer/Checkers/SmartPtrChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
  clang/test/Analysis/smart-ptr-text-output.cpp

Index: clang/test/Analysis/smart-ptr-text-output.cpp
===
--- clang/test/Analysis/smart-ptr-text-output.cpp
+++ clang/test/Analysis/smart-ptr-text-output.cpp
@@ -306,10 +306,81 @@
 };
 
 void derefAfterBranchingOnUnknownInnerPtr(std::unique_ptr P) {
-  A *RP = P.get();
+  A *RP = P.get(); // expected-note {{Obtained null inner pointer from 'P'}}
   if (!RP) { // expected-note {{Assuming 'RP' is null}}
 // expected-note@-1 {{Taking true branch}}
 P->foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}}
 // expected-note@-1{{Dereference of null smart pointer 'P'}}
   }
 }
+
+void multpleDeclsWithGet(std::unique_ptr P) {
+  A *dummy1 = nullptr, *RP = P.get(), *dummy2; // expected-note {{Obtained null inner pointer from 'P'}}
+  if (!RP) {   // expected-note {{Assuming 'RP' is null}}
+// expected-note@-1 {{Taking true branch}}
+P->foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}}
+// expected-note@-1{{Dereference of null smart pointer 'P'}}
+  }
+}
+
+void multipleGetsShouldNotAllHaveNotes(std::unique_ptr P) {
+  A *RP = P.get(); // expected-note {{Obtained null inner pointer from 'P'}}
+  A *dummy1 = P.get();
+  A *dummy2 = P.get();
+  if (!RP) { // expected-note {{Assuming 'RP' is null}}
+// expected-note@-1 {{Taking true branch}}
+P->foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}}
+// expected-note@-1{{Dereference of null smart pointer 'P'}}
+  }
+}
+
+void getShouldNotAlwaysLeaveANote() {
+  std::unique_ptr P; // expected-note {{Default constructed smart pointer 'P' is null}}
+  A *a = P.get();
+  P->foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}}
+// expected-note@-1{{Dereference of null smart pointer 'P'}}
+}
+
+void getShouldNotLeaveANoteAfterReset(std::unique_ptr P) {
+  A *a = P.get();
+  P.reset(); // expected-note {{Smart pointer 'P' reset using a null value}}
+  P->foo();  // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}}
+ // expected-note@-1{{Dereference of null smart pointer 'P'}}
+}
+
+void getShouldNotLeaveNoteWhenPtrNotUsed(std::unique_ptr P) {
+  A *a = P.get();
+  if (!P) { // expected-note {{Taking true branch}}
+// expected-note@-1 {{Assuming smart pointer 'P' is null}}
+P->foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}}
+// expected-note@-1{{Dereference of null smart pointer 'P'}}
+  }
+}
+
+void getShouldLeaveANoteWithWhileLoop(std::unique_ptr P) {
+  A *RP = P.get(); // expected-note {{Obtained null inner pointer from 'P'}}
+  while (!RP) {// expected-note {{Assuming 'RP' is null}}
+// expected-note@-1 {{Loop condition is true.  Entering loop body}}
+P->foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}}
+// expected-note@-1{{Dereference of null smart pointer 'P'}}
+  }
+}
+
+void getShouldLeaveANoteWithForLoop(std::unique_ptr P) {
+  for (A *RP = P.get(); !RP;) { // expected-note {{Assuming 'RP' is null}}
+// expected-note@-1 {{Loop condition is true.  Entering loop body}}
+// expected-note@-2 {{Obtained null inner pointer from 'P'}}
+P->foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}}
+// expected-note@-1{{Dereference of null smart pointer 'P'}}
+  }
+}
+
+void getShouldLeaveNoteOnChaining(std::unique_ptr P) {
+  A *praw = P.get(), *other; // expected-note {{Obtained null inner pointer from 'P'}}
+  other = praw;  // expected-note {{Obtained null value here}}
+  if (!other) {  // expected-note {{Assuming 'other' is null}}
+// expected-note@-1 {{Taking true branch}}
+P->foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}}
+// expected-note@-1{{Dereference of null smart pointer 'P'}}
+  }
+}
\ No newline at end of file
Index: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
+++ clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
@@ -76,11 +76,16 @@
   {{"release"}, &SmartPtrModeling::handleRelease},
   {{"swap", 1}, &SmartPtrModeling::handleSwap},
   {{"get"}, &

[PATCH] D102863: rdar://77307290 (Disable retain-count tracking for references to OSMetaClass)

2021-05-20 Thread Georgeta Igna via Phabricator via cfe-commits
georgi_igna created this revision.
georgi_igna requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

OSMetaClass does not use reference-counting. We should ignore references to 
OSMetaClass in class RetainSummaryManager.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D102863

Files:
  clang/test/Analysis/osobject-retain-release.cpp


Index: clang/test/Analysis/osobject-retain-release.cpp
===
--- clang/test/Analysis/osobject-retain-release.cpp
+++ clang/test/Analysis/osobject-retain-release.cpp
@@ -155,20 +155,12 @@
 void use_always_write_into_two_out_params_leak() {
   OSObject *obj1;
   OSObject *obj2;
-  always_write_into_two_out_params(
-  &obj1, &obj2); // expected-note-re{{Call to function
- // 'always_write_into_two_out_params' writes an OSObject 
of
- // type 'OSObject' with a +1 retain count into an out
- // parameter 'a'{{$ expected-note-re@-1{{Call to
- // function 'always_write_into_two_out_params' writes an
- // OSObject of type 'OSObject' with a +1 retain count into
- // an out parameter 'b'{{$
+  always_write_into_two_out_params(&obj1, &obj2); // expected-note-re{{Call to 
function 'always_write_into_two_out_params' writes an OSObject of type 
'OSObject' with a +1 retain count into an out parameter 'a'{{$
+  // expected-note-re@-1{{Call 
to function 'always_write_into_two_out_params' writes an OSObject of type 
'OSObject' with a +1 retain count into an out parameter 'b'{{$
 } // expected-warning{{Potential leak of an object stored into 'obj1'}}
   // expected-warning@-1{{Potential leak of an object stored into 'obj2'}}
-  // expected-note@-2{{Object leaked: object allocated and stored into 'obj1' 
is
-  // not referenced later in this execution path and has a retain count of +1}}
-  // expected-note@-3{{Object leaked: object allocated and stored into 'obj2' 
is
-  // not referenced later in this execution path and has a retain count of +1}}
+  // expected-note@-2{{Object leaked: object allocated and stored into 'obj1' 
is not referenced later in this execution path and has a retain count of +1}}
+  // expected-note@-3{{Object leaked: object allocated and stored into 'obj2' 
is not referenced later in this execution path and has a retain count of +1}}
 
 char *write_into_out_param_on_nonnull(OS_RETURNS_RETAINED OSObject **obj);
 


Index: clang/test/Analysis/osobject-retain-release.cpp
===
--- clang/test/Analysis/osobject-retain-release.cpp
+++ clang/test/Analysis/osobject-retain-release.cpp
@@ -155,20 +155,12 @@
 void use_always_write_into_two_out_params_leak() {
   OSObject *obj1;
   OSObject *obj2;
-  always_write_into_two_out_params(
-  &obj1, &obj2); // expected-note-re{{Call to function
- // 'always_write_into_two_out_params' writes an OSObject of
- // type 'OSObject' with a +1 retain count into an out
- // parameter 'a'{{$ expected-note-re@-1{{Call to
- // function 'always_write_into_two_out_params' writes an
- // OSObject of type 'OSObject' with a +1 retain count into
- // an out parameter 'b'{{$
+  always_write_into_two_out_params(&obj1, &obj2); // expected-note-re{{Call to function 'always_write_into_two_out_params' writes an OSObject of type 'OSObject' with a +1 retain count into an out parameter 'a'{{$
+  // expected-note-re@-1{{Call to function 'always_write_into_two_out_params' writes an OSObject of type 'OSObject' with a +1 retain count into an out parameter 'b'{{$
 } // expected-warning{{Potential leak of an object stored into 'obj1'}}
   // expected-warning@-1{{Potential leak of an object stored into 'obj2'}}
-  // expected-note@-2{{Object leaked: object allocated and stored into 'obj1' is
-  // not referenced later in this execution path and has a retain count of +1}}
-  // expected-note@-3{{Object leaked: object allocated and stored into 'obj2' is
-  // not referenced later in this execution path and has a retain count of +1}}
+  // expected-note@-2{{Object leaked: object allocated and stored into 'obj1' is not referenced later in this execution path and has a retain count of +1}}
+  // expected-note@-3{{Object leaked: object allocated and stored into 'obj2' is not referenced later in this execution path and has a retain count of +1}}
 
 char *write_into_out_param_on_nonnull(OS_RETURNS_RETAINED OSObject **obj);
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D102863: [analyzer] RetainCountChecker: Disable tracking for references to OSMetaClass.

2021-05-20 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

Please upload the actual change you want to make in the llvm.org main branch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102863

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


[PATCH] D74436: Change clang option -ffp-model=precise to select ffp-contract=on

2021-05-20 Thread Melanie Blower via Phabricator via cfe-commits
mibintc added a comment.

In D74436#2190566 , @lebedev.ri wrote:

> In D74436#2190492 , @lebedev.ri 
> wrote:
>
>> <...>
>
> And by codegen changes i mostly mean newly-set/now-unset fp fast-math 
> instruction flags.

I added some codegen tests to show you what ffp-contract is doing: the tests 
added are: ffp-contract={on,off,fast} * {ffast-math * fno-fast-math}


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D74436

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


[PATCH] D74436: Change clang option -ffp-model=precise to select ffp-contract=on

2021-05-20 Thread Melanie Blower via Phabricator via cfe-commits
mibintc added a comment.

I created https://reviews.llvm.org/D102861 to make changes to the failing LNT 
tests. Hoping to push this commit after the test changes in D102862 
 are approved.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D74436

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


[PATCH] D100252: [clang] Fix for "Bug 27113 - MSVC-compat __identifier implementation incomplete"

2021-05-20 Thread Melvin Fox via Phabricator via cfe-commits
super_concat marked 3 inline comments as done.
super_concat added a comment.

@hans, could you land this for me? I do not have commit access.


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

https://reviews.llvm.org/D100252

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


[PATCH] D102814: [AIX] Print printable byte list as quoted string

2021-05-20 Thread Jinsong Ji via Phabricator via cfe-commits
jsji updated this revision to Diff 346830.
jsji added a comment.

Update .string handling.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102814

Files:
  clang/test/CodeGenCXX/debug-info-byval.cpp
  llvm/include/llvm/MC/MCAsmInfo.h
  llvm/lib/MC/MCAsmInfoXCOFF.cpp
  llvm/lib/MC/MCAsmStreamer.cpp
  llvm/test/CodeGen/PowerPC/aix-emit-tracebacktable-clobber-register.ll
  llvm/test/CodeGen/PowerPC/aix-emit-tracebacktable.ll
  llvm/test/CodeGen/PowerPC/aix-exception.ll
  llvm/test/CodeGen/PowerPC/aix-xcoff-data-sections.ll
  llvm/test/CodeGen/PowerPC/aix-xcoff-data.ll
  llvm/test/CodeGen/PowerPC/aix-xcoff-mergeable-str.ll
  llvm/test/CodeGen/PowerPC/aix-xcoff-rodata.ll
  llvm/test/DebugInfo/XCOFF/empty.ll
  llvm/test/DebugInfo/XCOFF/explicit-section.ll
  llvm/test/DebugInfo/XCOFF/function-sections.ll

Index: llvm/test/DebugInfo/XCOFF/function-sections.ll
===
--- llvm/test/DebugInfo/XCOFF/function-sections.ll
+++ llvm/test/DebugInfo/XCOFF/function-sections.ll
@@ -72,7 +72,7 @@
 ; CHECK-NEXT:  .byte   0x01# NumberOfFPParms = 0, +HasParmsOnStack
 ; CHECK-NEXT:  .vbyte  4, L..foo0-.foo[PR] # Function size
 ; CHECK-NEXT:  .vbyte  2, 0x0003   # Function name len = 3
-; CHECK-NEXT:  .byte   'f,'o,'o# Function Name
+; CHECK-NEXT:  .byte   "foo"   # Function Name
 ; CHECK-NEXT:  L..func_end0:
 ; CHECK-NEXT:  # -- End function
 ; CHECK-NEXT:  .csect .bar[PR],2
@@ -108,7 +108,7 @@
 ; CHECK-NEXT:  .byte   0x01# NumberOfFPParms = 0, +HasParmsOnStack
 ; CHECK-NEXT:  .vbyte  4, L..bar0-.bar[PR] # Function size
 ; CHECK-NEXT:  .vbyte  2, 0x0003   # Function name len = 3
-; CHECK-NEXT:  .byte   'b,'a,'r# Function Name
+; CHECK-NEXT:  .byte   "bar"   # Function Name
 ; CHECK-NEXT:  L..func_end1:
 ; CHECK-NEXT:  # -- End function
 ; CHECK-NEXT:  L..sec_end0:
@@ -222,17 +222,17 @@
 ; CHECK:   .dwsect 0x7
 ; CHECK-NEXT:  L...dwstr:
 ; CHECK-NEXT:  L..info_string0:
-; CHECK-NEXT:  .byte   'c,'l,'a,'n,'g,' ,'v,'e,'r,'s,'i,'o,'n,' ,'1,'3,'.,'0,'.,'0, # string offset=0
+; CHECK-NEXT:  .string "clang version 13.0.0"  # string offset=0
 ; CHECK-NEXT:  L..info_string1:
-; CHECK-NEXT:  .byte   '1,'.,'c,   # string offset=21
+; CHECK-NEXT:  .string "1.c"   # string offset=21
 ; CHECK-NEXT:  L..info_string2:
-; CHECK-NEXT:  .byte   'd,'e,'b,'u,'g, # string offset=25
+; CHECK-NEXT:  .string "debug" # string offset=25
 ; CHECK-NEXT:  L..info_string3:
-; CHECK-NEXT:  .byte   'f,'o,'o,   # string offset=31
+; CHECK-NEXT:  .string "foo"   # string offset=31
 ; CHECK-NEXT:  L..info_string4:
-; CHECK-NEXT:  .byte   'i,'n,'t,   # string offset=35
+; CHECK-NEXT:  .string "int"   # string offset=35
 ; CHECK-NEXT:  L..info_string5:
-; CHECK-NEXT:  .byte   'b,'a,'r,   # string offset=39
+; CHECK-NEXT:  .string "bar"   # string offset=39
 ; CHECK-NEXT:  .toc
 ; CHECK:   .dwsect 0x2
 ; CHECK-NEXT:  L...dwline:
@@ -258,10 +258,10 @@
 ; CHECK-NEXT:  .byte   0
 ; CHECK-NEXT:  .byte   0
 ; CHECK-NEXT:  .byte   1
-; CHECK-NEXT:  .byte   'd,'e,'b,'u,'g
+; CHECK-NEXT:  .byte   "debug"
 ; CHECK-NEXT:  .byte   0
 ; CHECK-NEXT:  .byte   0
-; CHECK-NEXT:  .byte   '1,'.,'c
+; CHECK-NEXT:  .byte   "1.c"
 ; CHECK-NEXT:  .byte   0
 ; CHECK-NEXT:  .byte   1
 ; CHECK-NEXT:  .byte   0
Index: llvm/test/DebugInfo/XCOFF/explicit-section.ll
===
--- llvm/test/DebugInfo/XCOFF/explicit-section.ll
+++ llvm/test/DebugInfo/XCOFF/explicit-section.ll
@@ -77,7 +77,7 @@
 ; CHECK-NEXT:  .byte   0x01# NumberOfFPParms = 0, +HasParmsOnStack
 ; CHECK-NEXT:  .vbyte  4, L..bar0-.bar # Function size
 ; CHECK-NEXT:  .vbyte  2, 0x0003   # Function name len = 3
-; CHECK-NEXT:  .byte   'b,'a,'r# Function Name
+; CHECK-NEXT:  .byte   "bar"   # Function Name
 ; CHECK-NEXT:  L..func_end0:
 ; CHECK-NEXT:  # -- End function
 ; CHECK-NEXT:  .csect explicit_main_sec[PR]

[PATCH] D102814: [AIX] Print printable byte list as quoted string

2021-05-20 Thread Jinsong Ji via Phabricator via cfe-commits
jsji added inline comments.



Comment at: llvm/lib/MC/MCAsmStreamer.cpp:1008
+  for (const unsigned char C : Data) {
+if (!isPrint(C))
+  return false;

jsji wrote:
> This still need some slight change to deal with the ending 0 so that we can 
> handle .string.
Done.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102814

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


[PATCH] D102801: [CUDA][HIP] Fix device variables used by host

2021-05-20 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl marked 3 inline comments as done.
yaxunl added inline comments.



Comment at: clang/include/clang/Sema/Sema.h:12066
 
+  enum CUDAVariableTarget {
+CVT_Device,  /// Device only

tra wrote:
> Wasn't there another kind, where the variable is emitted on the host with 
> device-side shadow? I vaguely recall it had something to do with textures.
That was the first implementation, which was similar to managed var but used 
pinned host memory as a common memory shared by device and host.

However, that implementation was later replaced by a different implementation 
which is similar to nvcc. In the new implementation textures and surfaces are 
like usual device variables. So far I do not see the necessity to differentiate 
them from usual device variables.



Comment at: clang/include/clang/Sema/Sema.h:12067
+  enum CUDAVariableTarget {
+CVT_Device,  /// Device only
+CVT_Host,/// Host only

tra wrote:
> I think we should mention the host-side shadows, too.
will do



Comment at: clang/lib/Sema/SemaCUDA.cpp:148-149
+return CVT_Unified;
+  if (hasImplicitAttr(Var))
+return CVT_Both;
+  if (Var->hasAttr() || Var->hasAttr() ||

tra wrote:
> I'm still not a fan of relying on a implicit __constant__.
> Can we change it to more direct `is-a-constexpr && 
> !has-explicit-device-side-attr` ?
> We may eventually consider relaxing this to `can-be-const-evaluated` and 
> allow const vars with known values.
> 
will do. agree we should relax this for const var in the future


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

https://reviews.llvm.org/D102801

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


[PATCH] D102801: [CUDA][HIP] Fix device variables used by host

2021-05-20 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl updated this revision to Diff 346831.
yaxunl marked 3 inline comments as done.
yaxunl added a comment.

revised by Artem's comments


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

https://reviews.llvm.org/D102801

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/CodeGen/CGDeclCXX.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/Sema/SemaCUDA.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/AST/ast-dump-constant-var.cu
  clang/test/CodeGenCUDA/host-used-device-var.cu
  clang/test/SemaCUDA/static-device-var.cu

Index: clang/test/SemaCUDA/static-device-var.cu
===
--- clang/test/SemaCUDA/static-device-var.cu
+++ clang/test/SemaCUDA/static-device-var.cu
@@ -1,16 +1,14 @@
 // REQUIRES: x86-registered-target
 // REQUIRES: amdgpu-registered-target
 
-// RUN: %clang_cc1 -triple nvptx -fcuda-is-device \
-// RUN:-emit-llvm -o - %s -fsyntax-only -verify=dev
+// RUN: %clang_cc1 -triple nvptx -fcuda-is-device -std=c++11 \
+// RUN:-emit-llvm -o - %s -fsyntax-only -verify=dev,com
 
-// RUN: %clang_cc1 -triple x86_64-gnu-linux \
-// RUN:-emit-llvm -o - %s -fsyntax-only -verify=host
+// RUN: %clang_cc1 -triple x86_64-gnu-linux -std=c++11 \
+// RUN:-emit-llvm -o - %s -fsyntax-only -verify=host,com
 
 // Checks allowed usage of file-scope and function-scope static variables.
 
-// host-no-diagnostics
-
 #include "Inputs/cuda.h"
 
 // Checks static variables are allowed in device functions.
@@ -42,6 +40,28 @@
   // dev-error@-1 {{reference to __host__ variable 'z' in __global__ function}}
 }
 
+// Check dynamic initialization of static device variable is not allowed.
+
+namespace TestStaticVarInLambda {
+class A {
+public:
+  A(char *);
+};
+class B {
+public:
+  __device__ B(char *);
+};
+void fun() {
+  (void) [](char *c) {
+static A var1(c);
+static __device__ B var2(c);
+// com-error@-1 {{dynamic initialization is not supported for __device__, __constant__, __shared__, and __managed__ variables}}
+(void) var1;
+(void) var2;
+  };
+}
+}
+
 int* getDeviceSymbol(int *x);
 
 void foo() {
Index: clang/test/CodeGenCUDA/host-used-device-var.cu
===
--- clang/test/CodeGenCUDA/host-used-device-var.cu
+++ clang/test/CodeGenCUDA/host-used-device-var.cu
@@ -66,30 +66,148 @@
 template 
 __device__ func_t p_add_func = add_func;
 
+// Check non-constant constexpr variables ODR-used by host code only is not emitted.
+// DEV-NEG-NOT: constexpr_var1a
+// DEV-NEG-NOT: constexpr_var1b
+constexpr int constexpr_var1a = 1;
+inline constexpr int constexpr_var1b = 1;
+
+// Check constant constexpr variables ODR-used by host code only.
+// Non-inline constexpr variable has internal linkage, therefore it is not accessible by host and not kept.
+// Inline constexpr variable has linkonce_ord linkage, therefore it can be accessed by host and kept.
+// DEV-NEG-NOT: constexpr_var2a
+// DEV-DAG: @constexpr_var2b = linkonce_odr addrspace(4) externally_initialized constant i32 2
+__constant__ constexpr int constexpr_var2a = 2;
+inline __constant__ constexpr int constexpr_var2b = 2;
+
 void use(func_t p);
-void use(int *p);
+__host__ __device__ void use(const int *p);
 
+// Check static device variable in host function.
+// DEV-DAG:  @_ZZ4fun1vE11static_var1 = dso_local addrspace(1) externally_initialized global i32 3
 void fun1() {
+  static __device__ int static_var1 = 3;
   use(&u1);
   use(&u2);
   use(&u3);
   use(&ext_var);
   use(&inline_var);
   use(p_add_func);
+  use(&constexpr_var1a);
+  use(&constexpr_var1b);
+  use(&constexpr_var2a);
+  use(&constexpr_var2b);
+  use(&static_var1);
+}
+
+// Check static variable in host device function.
+// DEV-DAG:  @_ZZ4fun2vE11static_var2 = internal addrspace(1) global i32 4
+// DEV-DAG:  @_ZZ4fun2vE11static_var3 = dso_local addrspace(1) global i32 4
+__host__ __device__ void fun2() {
+  static int static_var2 = 4;
+  static __device__ int static_var3 = 4;
+  use(&static_var2);
+  use(&static_var3);
 }
 
 __global__ void kern1(int **x) {
   *x = &u4;
+  fun2();
+}
+
+// Check static variables of lambda functions.
+
+// Lambda functions are implicit host device functions.
+// Default static variables in lambda functions should be treated
+// as host variables on host side, therefore should not be forced
+// to be emitted on device.
+
+// DEV-DAG: @_ZZZN21TestStaticVarInLambda3funEvENKUlPcE_clES0_E4var2 = dso_local addrspace(1) externally_initialized global i32 5
+// DEV-NEG-NOT: @_ZZZN21TestStaticVarInLambda3funEvENKUlPcE_clES0_E4var1
+namespace TestStaticVarInLambda {
+class A {
+public:
+  A(char *);
+};
+void fun() {
+  (void) [](char *c) {
+static A var1(c);
+static __device__ int var2 = 5;
+(void) var1;
+(void) var2;
+  };
+}
+}
+
+// Check implicit constant variable ODR-used by host code is not emitted.
+
+// AST contains instantiation of al, which triggers AST 

[clang] 3eb12b0 - [WebAssembly] Warn on exception spec for Emscripten EH

2021-05-20 Thread Heejin Ahn via cfe-commits

Author: Heejin Ahn
Date: 2021-05-20T13:00:20-07:00
New Revision: 3eb12b0ae11fe23dc06e55e526fb45e460f72f1e

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

LOG: [WebAssembly] Warn on exception spec for Emscripten EH

It turns out we have not correctly supported exception spec all along in
Emscripten EH. Emscripten EH supports `throw()` but not `throw` with
types. See https://bugs.llvm.org/show_bug.cgi?id=50396.

Wasm EH also only supports `throw()` but not `throw` with types, and we
have been printing a warning message for the latter. This prints the
same warning message for `throw` with types when Emscripten EH is used,
or more precisely, when Wasm EH is not used. (So this will print the
warning messsage even when `-fno-exceptions` is used but I think that
should be fine. It's cumbersome to do a complilcated option checking in
CGException.cpp and options checkings are mostly done in elsewhere.)

Reviewed By: dschuff, kripken

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

Added: 


Modified: 
clang/lib/CodeGen/CGException.cpp
clang/test/CodeGenCXX/wasm-eh.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGException.cpp 
b/clang/lib/CodeGen/CGException.cpp
index 2467922baf95e..9f65e9eb120cf 100644
--- a/clang/lib/CodeGen/CGException.cpp
+++ b/clang/lib/CodeGen/CGException.cpp
@@ -486,9 +486,9 @@ void CodeGenFunction::EmitStartEHSpec(const Decl *D) {
 // encode these in an object file but MSVC doesn't do anything with it.
 if (getTarget().getCXXABI().isMicrosoft())
   return;
-// In wasm we currently treat 'throw()' in the same way as 'noexcept'. In
+// In Wasm EH we currently treat 'throw()' in the same way as 'noexcept'. 
In
 // case of throw with types, we ignore it and print a warning for now.
-// TODO Correctly handle exception specification in wasm
+// TODO Correctly handle exception specification in Wasm EH
 if (CGM.getLangOpts().hasWasmExceptions()) {
   if (EST == EST_DynamicNone)
 EHStack.pushTerminate();
@@ -498,6 +498,19 @@ void CodeGenFunction::EmitStartEHSpec(const Decl *D) {
 << FD->getExceptionSpecSourceRange();
   return;
 }
+// Currently Emscripten EH only handles 'throw()' but not 'throw' with
+// types. 'throw()' handling will be done in JS glue code so we don't need
+// to do anything in that case. Just print a warning message in case of
+// throw with types.
+// TODO Correctly handle exception specification in Emscripten EH
+if (getTarget().getCXXABI() == TargetCXXABI::WebAssembly &&
+CGM.getLangOpts().getExceptionHandling() ==
+LangOptions::ExceptionHandlingKind::None &&
+EST == EST_Dynamic)
+  CGM.getDiags().Report(D->getLocation(),
+diag::warn_wasm_dynamic_exception_spec_ignored)
+  << FD->getExceptionSpecSourceRange();
+
 unsigned NumExceptions = Proto->getNumExceptions();
 EHFilterScope *Filter = EHStack.pushFilter(NumExceptions);
 

diff  --git a/clang/test/CodeGenCXX/wasm-eh.cpp 
b/clang/test/CodeGenCXX/wasm-eh.cpp
index c9beb69474387..de5cf40259b9a 100644
--- a/clang/test/CodeGenCXX/wasm-eh.cpp
+++ b/clang/test/CodeGenCXX/wasm-eh.cpp
@@ -381,7 +381,7 @@ void test8() {
 // RUN: %clang_cc1 %s -triple wasm32-unknown-unknown -fms-extensions 
-fexceptions -fcxx-exceptions -exception-model=wasm -target-feature 
+exception-handling -emit-llvm -o - -std=c++11 2>&1 | FileCheck %s 
--check-prefix=WARNING-DEFAULT
 // RUN: %clang_cc1 %s -triple wasm32-unknown-unknown -fms-extensions 
-fexceptions -fcxx-exceptions -exception-model=wasm -target-feature 
+exception-handling -Wwasm-exception-spec -emit-llvm -o - -std=c++11 2>&1 | 
FileCheck %s --check-prefix=WARNING-ON
 // RUN: %clang_cc1 %s -triple wasm32-unknown-unknown -fms-extensions 
-fexceptions -fcxx-exceptions -exception-model=wasm -target-feature 
+exception-handling -Wno-wasm-exception-spec -emit-llvm -o - -std=c++11 2>&1 | 
FileCheck %s --check-prefix=WARNING-OFF
-// RUN: %clang_cc1 %s -triple wasm32-unknown-unknown -fexceptions 
-fcxx-exceptions -emit-llvm -o - -std=c++11 2>&1 | FileCheck %s 
--check-prefix=NOT-WASM-EH
+// RUN: %clang_cc1 %s -triple wasm32-unknown-unknown -fexceptions 
-fcxx-exceptions -emit-llvm -o - -std=c++11 2>&1 | FileCheck %s 
--check-prefix=EM-EH-WARNING
 
 // Wasm EH ignores dynamic exception specifications with types at the moment.
 // This is controlled by -Wwasm-exception-spec, which is on by default. This
@@ -392,7 +392,7 @@ void test9() throw(int) {
 // WARNING-DEFAULT: warning: dynamic exception specifications with types are 
currently ignored in wasm
 // WARNING-ON: warning: dynamic exception specifications with types are 
currently ignored in wasm
 // WARNING-OFF-NOT: warning: dynamic excep

[PATCH] D102791: [WebAssembly] Warn on exception spec for Emscripten EH

2021-05-20 Thread Heejin Ahn via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG3eb12b0ae11f: [WebAssembly] Warn on exception spec for 
Emscripten EH (authored by aheejin).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102791

Files:
  clang/lib/CodeGen/CGException.cpp
  clang/test/CodeGenCXX/wasm-eh.cpp


Index: clang/test/CodeGenCXX/wasm-eh.cpp
===
--- clang/test/CodeGenCXX/wasm-eh.cpp
+++ clang/test/CodeGenCXX/wasm-eh.cpp
@@ -381,7 +381,7 @@
 // RUN: %clang_cc1 %s -triple wasm32-unknown-unknown -fms-extensions 
-fexceptions -fcxx-exceptions -exception-model=wasm -target-feature 
+exception-handling -emit-llvm -o - -std=c++11 2>&1 | FileCheck %s 
--check-prefix=WARNING-DEFAULT
 // RUN: %clang_cc1 %s -triple wasm32-unknown-unknown -fms-extensions 
-fexceptions -fcxx-exceptions -exception-model=wasm -target-feature 
+exception-handling -Wwasm-exception-spec -emit-llvm -o - -std=c++11 2>&1 | 
FileCheck %s --check-prefix=WARNING-ON
 // RUN: %clang_cc1 %s -triple wasm32-unknown-unknown -fms-extensions 
-fexceptions -fcxx-exceptions -exception-model=wasm -target-feature 
+exception-handling -Wno-wasm-exception-spec -emit-llvm -o - -std=c++11 2>&1 | 
FileCheck %s --check-prefix=WARNING-OFF
-// RUN: %clang_cc1 %s -triple wasm32-unknown-unknown -fexceptions 
-fcxx-exceptions -emit-llvm -o - -std=c++11 2>&1 | FileCheck %s 
--check-prefix=NOT-WASM-EH
+// RUN: %clang_cc1 %s -triple wasm32-unknown-unknown -fexceptions 
-fcxx-exceptions -emit-llvm -o - -std=c++11 2>&1 | FileCheck %s 
--check-prefix=EM-EH-WARNING
 
 // Wasm EH ignores dynamic exception specifications with types at the moment.
 // This is controlled by -Wwasm-exception-spec, which is on by default. This
@@ -392,7 +392,7 @@
 // WARNING-DEFAULT: warning: dynamic exception specifications with types are 
currently ignored in wasm
 // WARNING-ON: warning: dynamic exception specifications with types are 
currently ignored in wasm
 // WARNING-OFF-NOT: warning: dynamic exception specifications with types are 
currently ignored in wasm
-// NOT-WASM-EH-NOT: warning: dynamic exception specifications with types are 
currently ignored in wasm
+// EM-EH-WARNING: warning: dynamic exception specifications with types are 
currently ignored in wasm
 
 // Wasm curremtly treats 'throw()' in the same way as 'noexept'. Check if the
 // same warning message is printed as if when a 'noexcept' function throws.
Index: clang/lib/CodeGen/CGException.cpp
===
--- clang/lib/CodeGen/CGException.cpp
+++ clang/lib/CodeGen/CGException.cpp
@@ -486,9 +486,9 @@
 // encode these in an object file but MSVC doesn't do anything with it.
 if (getTarget().getCXXABI().isMicrosoft())
   return;
-// In wasm we currently treat 'throw()' in the same way as 'noexcept'. In
+// In Wasm EH we currently treat 'throw()' in the same way as 'noexcept'. 
In
 // case of throw with types, we ignore it and print a warning for now.
-// TODO Correctly handle exception specification in wasm
+// TODO Correctly handle exception specification in Wasm EH
 if (CGM.getLangOpts().hasWasmExceptions()) {
   if (EST == EST_DynamicNone)
 EHStack.pushTerminate();
@@ -498,6 +498,19 @@
 << FD->getExceptionSpecSourceRange();
   return;
 }
+// Currently Emscripten EH only handles 'throw()' but not 'throw' with
+// types. 'throw()' handling will be done in JS glue code so we don't need
+// to do anything in that case. Just print a warning message in case of
+// throw with types.
+// TODO Correctly handle exception specification in Emscripten EH
+if (getTarget().getCXXABI() == TargetCXXABI::WebAssembly &&
+CGM.getLangOpts().getExceptionHandling() ==
+LangOptions::ExceptionHandlingKind::None &&
+EST == EST_Dynamic)
+  CGM.getDiags().Report(D->getLocation(),
+diag::warn_wasm_dynamic_exception_spec_ignored)
+  << FD->getExceptionSpecSourceRange();
+
 unsigned NumExceptions = Proto->getNumExceptions();
 EHFilterScope *Filter = EHStack.pushFilter(NumExceptions);
 


Index: clang/test/CodeGenCXX/wasm-eh.cpp
===
--- clang/test/CodeGenCXX/wasm-eh.cpp
+++ clang/test/CodeGenCXX/wasm-eh.cpp
@@ -381,7 +381,7 @@
 // RUN: %clang_cc1 %s -triple wasm32-unknown-unknown -fms-extensions -fexceptions -fcxx-exceptions -exception-model=wasm -target-feature +exception-handling -emit-llvm -o - -std=c++11 2>&1 | FileCheck %s --check-prefix=WARNING-DEFAULT
 // RUN: %clang_cc1 %s -triple wasm32-unknown-unknown -fms-extensions -fexceptions -fcxx-exceptions -exception-model=wasm -target-feature +exception-handling -Wwasm-exception-spec -emit-llvm -o - -std=c++11 2>&1 | FileCheck %s --check-prefix=WARNING-ON
 //

  1   2   >