[PATCH] D135422: Fix clang-format misattributing preprocessor directives to macros

2022-10-06 Thread Jacob Abraham via Phabricator via cfe-commits
jacob-abraham created this revision.
jacob-abraham added reviewers: djasper, Typz.
jacob-abraham added a project: clang-format.
Herald added a project: All.
jacob-abraham requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This solves the issue I documented at 
https://github.com/llvm/llvm-project/issues/58214.

Essentially, a case statement inside a macro greedily adds preprocessor lines 
such as `#include` to the macro, even if they are not a part of the macro to 
begin with. Short quick fix. I tried to do it cleanly, but this was my first 
attempt at patching clang-format so if there is a cleaner/better way to fix 
this that would be awesome!


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D135422

Files:
  clang/lib/Format/UnwrappedLineFormatter.cpp


Index: clang/lib/Format/UnwrappedLineFormatter.cpp
===
--- clang/lib/Format/UnwrappedLineFormatter.cpp
+++ clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -643,6 +643,7 @@
 unsigned Length = 0;
 bool EndsWithComment = false;
 bool InPPDirective = I[0]->InPPDirective;
+bool InMacroBody = I[0]->InMacroBody;
 const unsigned Level = I[0]->Level;
 for (; NumStmts < 3; ++NumStmts) {
   if (I + 1 + NumStmts == E)
@@ -650,6 +651,8 @@
   const AnnotatedLine *Line = I[1 + NumStmts];
   if (Line->InPPDirective != InPPDirective)
 break;
+  if(Line->InMacroBody != InMacroBody)
+break;
   if (Line->First->isOneOf(tok::kw_case, tok::kw_default, tok::r_brace))
 break;
   if (Line->First->isOneOf(tok::kw_if, tok::kw_for, tok::kw_switch,


Index: clang/lib/Format/UnwrappedLineFormatter.cpp
===
--- clang/lib/Format/UnwrappedLineFormatter.cpp
+++ clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -643,6 +643,7 @@
 unsigned Length = 0;
 bool EndsWithComment = false;
 bool InPPDirective = I[0]->InPPDirective;
+bool InMacroBody = I[0]->InMacroBody;
 const unsigned Level = I[0]->Level;
 for (; NumStmts < 3; ++NumStmts) {
   if (I + 1 + NumStmts == E)
@@ -650,6 +651,8 @@
   const AnnotatedLine *Line = I[1 + NumStmts];
   if (Line->InPPDirective != InPPDirective)
 break;
+  if(Line->InMacroBody != InMacroBody)
+break;
   if (Line->First->isOneOf(tok::kw_case, tok::kw_default, tok::r_brace))
 break;
   if (Line->First->isOneOf(tok::kw_if, tok::kw_for, tok::kw_switch,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D134859: [clang][Interp] Implement basic support for floating point values

2022-10-06 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 465968.

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

https://reviews.llvm.org/D134859

Files:
  clang/lib/AST/CMakeLists.txt
  clang/lib/AST/Interp/Boolean.h
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/ByteCodeExprGen.h
  clang/lib/AST/Interp/Context.cpp
  clang/lib/AST/Interp/Descriptor.cpp
  clang/lib/AST/Interp/Floating.cpp
  clang/lib/AST/Interp/Floating.h
  clang/lib/AST/Interp/Integral.h
  clang/lib/AST/Interp/Interp.cpp
  clang/lib/AST/Interp/Interp.h
  clang/lib/AST/Interp/InterpStack.h
  clang/lib/AST/Interp/Opcodes.td
  clang/lib/AST/Interp/PrimType.h
  clang/lib/AST/Interp/Primitives.h
  clang/test/AST/Interp/literals.cpp

Index: clang/test/AST/Interp/literals.cpp
===
--- clang/test/AST/Interp/literals.cpp
+++ clang/test/AST/Interp/literals.cpp
@@ -270,3 +270,31 @@
   static_assert((1337 & -1) == 1337, "");
   static_assert((0 & gimme(12)) == 0, "");
 };
+
+namespace floats {
+  constexpr int i = 2;
+  constexpr float f = 1.0f;
+  static_assert(f == 1.0f, "");
+
+  constexpr float f2 = 1u * f;
+  static_assert(f2 == 1.0f, "");
+
+  static_assert(1.0f + 3u == 4, "");
+  static_assert(4.0f / 1.0f == 4, "");
+  static_assert(10.0f * false == 0, "");
+
+  constexpr float floats[] = {1.0f, 2.0f, 3.0f, 4.0f};
+
+  constexpr float m = 5.0f / 0.0f; // ref-error {{must be initialized by a constant expression}} \
+   // ref-note {{division by zero}} \
+   // expected-error {{must be initialized by a constant expression}} \
+   // expected-note {{division by zero}}
+
+  static_assert(~2.0f == 3, ""); // ref-error {{invalid argument type 'float' to unary expression}} \
+ // expected-error {{invalid argument type 'float' to unary expression}}
+
+  /// Initialized by a double.
+  constexpr float df = 0.0;
+  /// The other way around.
+  constexpr double fd = 0.0f;
+};
Index: clang/lib/AST/Interp/Primitives.h
===
--- /dev/null
+++ clang/lib/AST/Interp/Primitives.h
@@ -0,0 +1,36 @@
+//===-- Primitives.h - Types for the constexpr VM ---*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// Utilities and helper functions for all primitive types:
+//  - Integral
+//  - Floating
+//  - Boolean
+//
+//===--===//
+
+#ifndef LLVM_CLANG_AST_INTERP_PRIMITIVES_H
+#define LLVM_CLANG_AST_INTERP_PRIMITIVES_H
+
+#include "clang/AST/ComparisonCategories.h"
+
+namespace clang {
+namespace interp {
+
+/// Helper to compare two comparable types.
+template  ComparisonCategoryResult Compare(const T , const T ) {
+  if (X < Y)
+return ComparisonCategoryResult::Less;
+  if (X > Y)
+return ComparisonCategoryResult::Greater;
+  return ComparisonCategoryResult::Equal;
+}
+
+} // namespace interp
+} // namespace clang
+
+#endif
Index: clang/lib/AST/Interp/PrimType.h
===
--- clang/lib/AST/Interp/PrimType.h
+++ clang/lib/AST/Interp/PrimType.h
@@ -13,11 +13,12 @@
 #ifndef LLVM_CLANG_AST_INTERP_TYPE_H
 #define LLVM_CLANG_AST_INTERP_TYPE_H
 
+#include "Boolean.h"
+#include "Floating.h"
+#include "Integral.h"
 #include 
 #include 
 #include 
-#include "Boolean.h"
-#include "Integral.h"
 
 namespace clang {
 namespace interp {
@@ -35,6 +36,7 @@
   PT_Sint64,
   PT_Uint64,
   PT_Bool,
+  PT_Float,
   PT_Ptr,
 };
 
@@ -48,6 +50,7 @@
 template <> struct PrimConv { using T = Integral<32, false>; };
 template <> struct PrimConv { using T = Integral<64, true>; };
 template <> struct PrimConv { using T = Integral<64, false>; };
+template <> struct PrimConv { using T = Floating; };
 template <> struct PrimConv { using T = Boolean; };
 template <> struct PrimConv { using T = Pointer; };
 
@@ -70,6 +73,7 @@
   case PT_Uint32:
   case PT_Sint64:
   case PT_Uint64:
+  case PT_Float:
 return true;
   default:
 return false;
@@ -94,6 +98,7 @@
   TYPE_SWITCH_CASE(PT_Uint32, B)   \
   TYPE_SWITCH_CASE(PT_Sint64, B)   \
   TYPE_SWITCH_CASE(PT_Uint64, B)   \
+  TYPE_SWITCH_CASE(PT_Float, B)\
   TYPE_SWITCH_CASE(PT_Bool, B) \
   TYPE_SWITCH_CASE(PT_Ptr, B)  \
 }  \

[PATCH] D134859: [clang][Interp] Implement basic support for floating point values

2022-10-06 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added inline comments.



Comment at: clang/lib/AST/Interp/Floating.h:33-34
+  /// Primitive representing limits.
+  // static constexpr auto Min = std::numeric_limits::min();
+  // static constexpr auto Max = std::numeric_limits::max();
+

jcranmer-intel wrote:
> tbaeder wrote:
> > This is currently commented out, but I //think// I can get the semantics of 
> > the `APFloat` and ask its semantics for min/max values.
> `APFloat::get{Largest,Smallest}` will do the trick.
I only need them for `isMin()`, so `isSmallest()` even works, thanks!


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

https://reviews.llvm.org/D134859

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


[PATCH] D134859: [clang][Interp] Implement basic support for floating point values

2022-10-06 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 465967.
tbaeder marked 2 inline comments as done.

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

https://reviews.llvm.org/D134859

Files:
  clang/lib/AST/CMakeLists.txt
  clang/lib/AST/Interp/Boolean.h
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/ByteCodeExprGen.h
  clang/lib/AST/Interp/Context.cpp
  clang/lib/AST/Interp/Descriptor.cpp
  clang/lib/AST/Interp/Floating.cpp
  clang/lib/AST/Interp/Floating.h
  clang/lib/AST/Interp/Integral.h
  clang/lib/AST/Interp/Interp.cpp
  clang/lib/AST/Interp/Interp.h
  clang/lib/AST/Interp/InterpStack.h
  clang/lib/AST/Interp/Opcodes.td
  clang/lib/AST/Interp/PrimType.h
  clang/lib/AST/Interp/Primitives.h
  clang/test/AST/Interp/literals.cpp

Index: clang/test/AST/Interp/literals.cpp
===
--- clang/test/AST/Interp/literals.cpp
+++ clang/test/AST/Interp/literals.cpp
@@ -270,3 +270,26 @@
   static_assert((1337 & -1) == 1337, "");
   static_assert((0 & gimme(12)) == 0, "");
 };
+
+namespace floats {
+  constexpr int i = 2;
+  constexpr float f = 1.0f;
+  static_assert(f == 1.0f, "");
+
+  constexpr float f2 = 1u * f;
+  static_assert(f2 == 1.0f, "");
+
+  static_assert(1.0f + 3u == 4, "");
+  static_assert(4.0f / 1.0f == 4, "");
+  static_assert(10.0f * false == 0, "");
+
+  constexpr float floats[] = {1.0f, 2.0f, 3.0f, 4.0f};
+
+  constexpr float m = 5.0f / 0.0f; // ref-error {{must be initialized by a constant expression}} \
+   // ref-note {{division by zero}} \
+   // expected-error {{must be initialized by a constant expression}} \
+   // expected-note {{division by zero}}
+
+  static_assert(~2.0f == 3, ""); // ref-error {{invalid argument type 'float' to unary expression}} \
+ // expected-error {{invalid argument type 'float' to unary expression}}
+};
Index: clang/lib/AST/Interp/Primitives.h
===
--- /dev/null
+++ clang/lib/AST/Interp/Primitives.h
@@ -0,0 +1,36 @@
+//===-- Primitives.h - Types for the constexpr VM ---*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// Utilities and helper functions for all primitive types:
+//  - Integral
+//  - Floating
+//  - Boolean
+//
+//===--===//
+
+#ifndef LLVM_CLANG_AST_INTERP_PRIMITIVES_H
+#define LLVM_CLANG_AST_INTERP_PRIMITIVES_H
+
+#include "clang/AST/ComparisonCategories.h"
+
+namespace clang {
+namespace interp {
+
+/// Helper to compare two comparable types.
+template  ComparisonCategoryResult Compare(const T , const T ) {
+  if (X < Y)
+return ComparisonCategoryResult::Less;
+  if (X > Y)
+return ComparisonCategoryResult::Greater;
+  return ComparisonCategoryResult::Equal;
+}
+
+} // namespace interp
+} // namespace clang
+
+#endif
Index: clang/lib/AST/Interp/PrimType.h
===
--- clang/lib/AST/Interp/PrimType.h
+++ clang/lib/AST/Interp/PrimType.h
@@ -13,11 +13,12 @@
 #ifndef LLVM_CLANG_AST_INTERP_TYPE_H
 #define LLVM_CLANG_AST_INTERP_TYPE_H
 
+#include "Boolean.h"
+#include "Floating.h"
+#include "Integral.h"
 #include 
 #include 
 #include 
-#include "Boolean.h"
-#include "Integral.h"
 
 namespace clang {
 namespace interp {
@@ -35,6 +36,7 @@
   PT_Sint64,
   PT_Uint64,
   PT_Bool,
+  PT_Float,
   PT_Ptr,
 };
 
@@ -48,6 +50,7 @@
 template <> struct PrimConv { using T = Integral<32, false>; };
 template <> struct PrimConv { using T = Integral<64, true>; };
 template <> struct PrimConv { using T = Integral<64, false>; };
+template <> struct PrimConv { using T = Floating; };
 template <> struct PrimConv { using T = Boolean; };
 template <> struct PrimConv { using T = Pointer; };
 
@@ -70,6 +73,7 @@
   case PT_Uint32:
   case PT_Sint64:
   case PT_Uint64:
+  case PT_Float:
 return true;
   default:
 return false;
@@ -94,6 +98,7 @@
   TYPE_SWITCH_CASE(PT_Uint32, B)   \
   TYPE_SWITCH_CASE(PT_Sint64, B)   \
   TYPE_SWITCH_CASE(PT_Uint64, B)   \
+  TYPE_SWITCH_CASE(PT_Float, B)\
   TYPE_SWITCH_CASE(PT_Bool, B) \
   TYPE_SWITCH_CASE(PT_Ptr, B)  \
 }  \
Index: clang/lib/AST/Interp/Opcodes.td

[PATCH] D134699: [clang][Interp] Implement This pointer passing to methods

2022-10-06 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 465966.

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

https://reviews.llvm.org/D134699

Files:
  clang/lib/AST/Interp/ByteCodeEmitter.cpp
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/ByteCodeExprGen.h
  clang/lib/AST/Interp/ByteCodeStmtGen.cpp
  clang/lib/AST/Interp/Disasm.cpp
  clang/lib/AST/Interp/EvalEmitter.cpp
  clang/lib/AST/Interp/Function.cpp
  clang/lib/AST/Interp/Function.h
  clang/lib/AST/Interp/Interp.cpp
  clang/lib/AST/Interp/InterpFrame.cpp
  clang/lib/AST/Interp/InterpFrame.h
  clang/test/AST/Interp/records.cpp

Index: clang/test/AST/Interp/records.cpp
===
--- clang/test/AST/Interp/records.cpp
+++ clang/test/AST/Interp/records.cpp
@@ -102,3 +102,38 @@
   return 
 }
 static_assert(getPointer()->a == 100, "");
+
+constexpr C RVOAndParams(const C *c) {
+  return C();
+}
+constexpr C RVOAndParamsResult = RVOAndParams();
+
+constexpr int locals() {
+  C c;
+  c.a = 10;
+
+  // Assignment, not an initializer.
+  // c = C(); FIXME
+  c.a = 10;
+
+
+  // Assignment, not an initializer.
+  //c = RVOAndParams(); FIXME
+
+  return c.a;
+}
+static_assert(locals() == 10, "");
+
+namespace thisPointer {
+  struct S {
+constexpr int get12() { return 12; }
+  };
+
+  constexpr int foo() { // ref-error {{never produces a constant expression}}
+S *s = nullptr;
+return s->get12(); // ref-note 2{{member call on dereferenced null pointer}}
+  }
+  // FIXME: The new interpreter doesn't reject this currently.
+  static_assert(foo() == 12, ""); // ref-error {{not an integral constant expression}} \
+  // ref-note {{in call to 'foo()'}}
+};
Index: clang/lib/AST/Interp/InterpFrame.h
===
--- clang/lib/AST/Interp/InterpFrame.h
+++ clang/lib/AST/Interp/InterpFrame.h
@@ -35,6 +35,11 @@
   InterpFrame(InterpState , Function *Func, InterpFrame *Caller,
   CodePtr RetPC, Pointer &);
 
+  /// Creates a new frame with the values that make sense.
+  /// I.e., the caller is the current frame of S,
+  /// and the This() pointer is the current Pointer on the top of S's stack,
+  InterpFrame(InterpState , Function *Func, CodePtr RetPC);
+
   /// Destroys the frame, killing all live pointers to stack slots.
   ~InterpFrame();
 
Index: clang/lib/AST/Interp/InterpFrame.cpp
===
--- clang/lib/AST/Interp/InterpFrame.cpp
+++ clang/lib/AST/Interp/InterpFrame.cpp
@@ -36,6 +36,36 @@
   }
 }
 
+InterpFrame::InterpFrame(InterpState , Function *Func, CodePtr RetPC)
+: Caller(S.Current), S(S), Func(Func), RetPC(RetPC),
+  ArgSize(Func ? Func->getArgSize() : 0),
+  Args(static_cast(S.Stk.top())), FrameOffset(S.Stk.size()) {
+  assert(Func);
+
+  // As per our calling convention, the this pointer is
+  // part of the ArgSize.
+  // If the function has RVO, the RVO pointer is first.
+  // If the fuction has a This pointer, that one is next.
+  // Then follow the actual arguments (but those are handled
+  // in getParamPointer()).
+  if (Func->hasThisPointer()) {
+if (Func->hasRVO())
+  This = stackRef(sizeof(Pointer));
+else
+  This = stackRef(0);
+  }
+
+  if (unsigned FrameSize = Func->getFrameSize()) {
+Locals = std::make_unique(FrameSize);
+for (auto  : Func->scopes()) {
+  for (auto  : Scope.locals()) {
+Block *B = new (localBlock(Local.Offset)) Block(Local.Desc);
+B->invokeCtor();
+  }
+}
+  }
+}
+
 InterpFrame::~InterpFrame() {
   if (Func && Func->isConstructor() && This.isBaseClass())
 This.initialize();
Index: clang/lib/AST/Interp/Interp.cpp
===
--- clang/lib/AST/Interp/Interp.cpp
+++ clang/lib/AST/Interp/Interp.cpp
@@ -55,8 +55,7 @@
 
 template ::T>
 static bool Call(InterpState , CodePtr , const Function *Func) {
-  S.Current =
-  new InterpFrame(S, const_cast(Func), S.Current, PC, {});
+  S.Current = new InterpFrame(S, const_cast(Func), PC);
   APValue CallResult;
   // Note that we cannot assert(CallResult.hasValue()) here since
   // Ret() above only sets the APValue if the curent frame doesn't
@@ -66,8 +65,7 @@
 
 static bool CallVoid(InterpState , CodePtr , const Function *Func) {
   APValue VoidResult;
-  S.Current =
-  new InterpFrame(S, const_cast(Func), S.Current, PC, {});
+  S.Current = new InterpFrame(S, const_cast(Func), PC);
   bool Success = Interpret(S, VoidResult);
   assert(VoidResult.isAbsent());
 
Index: clang/lib/AST/Interp/Function.h
===
--- clang/lib/AST/Interp/Function.h
+++ clang/lib/AST/Interp/Function.h
@@ -56,6 +56,21 @@
 ///
 /// Contains links to the bytecode of the function, as well as metadata
 /// describing all arguments and stack-local variables.
+///
+/// # Calling Convention

[PATCH] D135421: Driver: Change default Android linker to lld.

2022-10-06 Thread Peter Collingbourne via Phabricator via cfe-commits
pcc created this revision.
pcc added reviewers: srhines, rprichard, danalbert.
Herald added subscribers: danielkiss, cryptoad.
Herald added a project: All.
pcc requested review of this revision.
Herald added a subscriber: MaskRay.
Herald added a project: clang.

The clang distributed with the Android NDK has defaulted to lld since r22,
so let's update the driver to match.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D135421

Files:
  clang/lib/Driver/ToolChains/Linux.cpp
  clang/lib/Driver/ToolChains/Linux.h
  clang/test/Driver/coverage-ld.c
  clang/test/Driver/fuse-ld.c
  clang/test/Driver/sanitizer-ld.c

Index: clang/test/Driver/sanitizer-ld.c
===
--- clang/test/Driver/sanitizer-ld.c
+++ clang/test/Driver/sanitizer-ld.c
@@ -169,7 +169,7 @@
 // RUN: --sysroot=%S/Inputs/basic_android_tree/sysroot \
 // RUN:   | FileCheck --check-prefix=CHECK-ASAN-ANDROID %s
 //
-// CHECK-ASAN-ANDROID: "{{(.*[^.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
+// CHECK-ASAN-ANDROID: "{{(.*[^.0-9A-Z_a-z])?}}ld.lld{{(.exe)?}}"
 // CHECK-ASAN-ANDROID: "-pie"
 // CHECK-ASAN-ANDROID-NOT: "-lc"
 // CHECK-ASAN-ANDROID-NOT: "-lpthread"
@@ -184,7 +184,7 @@
 // RUN: -static-libsan \
 // RUN:   | FileCheck --check-prefix=CHECK-ASAN-ANDROID-STATICLIBASAN %s
 //
-// CHECK-ASAN-ANDROID-STATICLIBASAN: "{{(.*[^.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
+// CHECK-ASAN-ANDROID-STATICLIBASAN: "{{(.*[^.0-9A-Z_a-z])?}}ld.lld{{(.exe)?}}"
 // CHECK-ASAN-ANDROID-STATICLIBASAN: libclang_rt.asan-arm-android.a"
 // CHECK-ASAN-ANDROID-STATICLIBASAN-NOT: "-lpthread"
 // CHECK-ASAN-ANDROID-STATICLIBASAN-NOT: "-lrt"
@@ -195,7 +195,7 @@
 // RUN: --sysroot=%S/Inputs/basic_android_tree/sysroot \
 // RUN:   | FileCheck --check-prefix=CHECK-UBSAN-ANDROID %s
 //
-// CHECK-UBSAN-ANDROID: "{{(.*[^.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
+// CHECK-UBSAN-ANDROID: "{{(.*[^.0-9A-Z_a-z])?}}ld.lld{{(.exe)?}}"
 // CHECK-UBSAN-ANDROID: "-pie"
 // CHECK-UBSAN-ANDROID-NOT: "-lc"
 // CHECK-UBSAN-ANDROID-NOT: "-lpthread"
@@ -210,7 +210,7 @@
 // RUN: -static-libsan \
 // RUN:   | FileCheck --check-prefix=CHECK-UBSAN-ANDROID-STATICLIBASAN %s
 //
-// CHECK-UBSAN-ANDROID-STATICLIBASAN: "{{(.*[^.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
+// CHECK-UBSAN-ANDROID-STATICLIBASAN: "{{(.*[^.0-9A-Z_a-z])?}}ld.lld{{(.exe)?}}"
 // CHECK-UBSAN-ANDROID-STATICLIBASAN: libclang_rt.ubsan_standalone-arm-android.a"
 // CHECK-UBSAN-ANDROID-STATICLIBASAN-NOT: "-lpthread"
 // CHECK-UBSAN-ANDROID-STATICLIBASAN-NOT: "-lrt"
@@ -222,7 +222,7 @@
 // RUN: --sysroot=%S/Inputs/basic_android_tree/sysroot \
 // RUN:   | FileCheck --check-prefix=CHECK-ASAN-ANDROID-X86 %s
 //
-// CHECK-ASAN-ANDROID-X86: "{{(.*[^.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
+// CHECK-ASAN-ANDROID-X86: "{{(.*[^.0-9A-Z_a-z])?}}ld.lld{{(.exe)?}}"
 // CHECK-ASAN-ANDROID-X86: "-pie"
 // CHECK-ASAN-ANDROID-X86-NOT: "-lc"
 // CHECK-ASAN-ANDROID-X86-NOT: "-lpthread"
@@ -245,7 +245,7 @@
 // RUN: -shared \
 // RUN:   | FileCheck --check-prefix=CHECK-ASAN-ANDROID-SHARED %s
 //
-// CHECK-ASAN-ANDROID-SHARED: "{{(.*[^.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
+// CHECK-ASAN-ANDROID-SHARED: "{{(.*[^.0-9A-Z_a-z])?}}ld.lld{{(.exe)?}}"
 // CHECK-ASAN-ANDROID-SHARED-NOT: "-lc"
 // CHECK-ASAN-ANDROID-SHARED: libclang_rt.asan-arm-android.so"
 // CHECK-ASAN-ANDROID-SHARED-NOT: "-lpthread"
@@ -760,7 +760,7 @@
 // RUN: --sysroot=%S/Inputs/basic_android_tree \
 // RUN:   | FileCheck --check-prefix=CHECK-SAFESTACK-ANDROID-ARM %s
 //
-// CHECK-SAFESTACK-ANDROID-ARM: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
+// CHECK-SAFESTACK-ANDROID-ARM: "{{(.*[^-.0-9A-Z_a-z])?}}ld.lld{{(.exe)?}}"
 // CHECK-SAFESTACK-ANDROID-ARM-NOT: libclang_rt.safestack
 
 // RUN: %clang -### %s -shared 2>&1 \
@@ -768,7 +768,7 @@
 // RUN: --sysroot=%S/Inputs/basic_android_tree \
 // RUN:   | FileCheck --check-prefix=CHECK-SAFESTACK-SHARED-ANDROID-ARM %s
 //
-// CHECK-SAFESTACK-SHARED-ANDROID-ARM: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
+// CHECK-SAFESTACK-SHARED-ANDROID-ARM: "{{(.*[^-.0-9A-Z_a-z])?}}ld.lld{{(.exe)?}}"
 // CHECK-SAFESTACK-SHARED-ANDROID-ARM-NOT: libclang_rt.safestack
 
 // RUN: %clang -### %s 2>&1 \
@@ -776,7 +776,7 @@
 // RUN: --sysroot=%S/Inputs/basic_android_tree \
 // RUN:   | FileCheck --check-prefix=CHECK-SAFESTACK-ANDROID-AARCH64 %s
 //
-// CHECK-SAFESTACK-ANDROID-AARCH64: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
+// CHECK-SAFESTACK-ANDROID-AARCH64: "{{(.*[^-.0-9A-Z_a-z])?}}ld.lld{{(.exe)?}}"
 // CHECK-SAFESTACK-ANDROID-AARCH64-NOT: libclang_rt.safestack
 
 // RUN: %clang -fsanitize=undefined -### %s 2>&1 \
@@ -891,7 +891,7 @@
 // RUN: --sysroot=%S/Inputs/basic_android_tree/sysroot \
 // RUN:   | FileCheck --check-prefix=CHECK-SCUDO-ANDROID %s
 //
-// CHECK-SCUDO-ANDROID: "{{(.*[^.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
+// CHECK-SCUDO-ANDROID: "{{(.*[^.0-9A-Z_a-z])?}}ld.lld{{(.exe)?}}"
 // CHECK-SCUDO-ANDROID-NOT: "-lc"
 // CHECK-SCUDO-ANDROID: "-pie"
 // CHECK-SCUDO-ANDROID-NOT: "-lpthread"
@@ -905,7 +905,7 @@
 // RUN: 

[PATCH] D135370: Narrow inline namespace filtration for unqualified friend declarations

2022-10-06 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added inline comments.



Comment at: clang/lib/Sema/SemaTemplateInstantiateDecl.cpp:2277-2278
+if (isFriend && !QualifierLoc && !FunctionTemplate) {
+  SemaRef.FilterLookupForScope(Previous, DC, /*Scope*/ nullptr,
+   /*ConsiderLinkage*/ true,
+   QualifierLoc.hasQualifier());

Nitpick ` /*Scope=*/nullptr` and `/*ConsiderLinkage=*/true`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135370

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


[clang] 3af06c7 - [CMake] Update cache file for Win to ARM Linux cross toolchain builders. NFC.

2022-10-06 Thread Vladimir Vereschaka via cfe-commits

Author: Vladimir Vereschaka
Date: 2022-10-06T19:40:33-07:00
New Revision: 3af06c72986356c6d580814fef80813ab3b3c34a

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

LOG: [CMake] Update cache file for Win to ARM Linux cross toolchain builders. 
NFC.

Do not specify the execution directory in the remote execution script command 
line
for the compiler-rt builtin library tests. There is a single execution file 
tests
within the single directory. No need to pack all of them every time, just run 
one by one.

Added: 


Modified: 
clang/cmake/caches/CrossWinToARMLinux.cmake

Removed: 




diff  --git a/clang/cmake/caches/CrossWinToARMLinux.cmake 
b/clang/cmake/caches/CrossWinToARMLinux.cmake
index 3f80478d16e32..e6f5650eac466 100644
--- a/clang/cmake/caches/CrossWinToARMLinux.cmake
+++ b/clang/cmake/caches/CrossWinToARMLinux.cmake
@@ -160,7 +160,7 @@ if(DEFINED REMOTE_TEST_HOST)
   endif()
 
   set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_COMPILER_RT_EMULATOR
-"\\\"${Python3_EXECUTABLE}\\\" 
\\\"${LLVM_PROJECT_DIR}/llvm/utils/remote-exec.py\\\" --execdir %T 
--exec-pattern='.*\\.c.*\\.tmp.*' 
--host=${REMOTE_TEST_USER}@${REMOTE_TEST_HOST}"
+"\\\"${Python3_EXECUTABLE}\\\" 
\\\"${LLVM_PROJECT_DIR}/llvm/utils/remote-exec.py\\\" 
--host=${REMOTE_TEST_USER}@${REMOTE_TEST_HOST}"
 CACHE STRING "")
 
   set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBUNWIND_EXECUTOR   
   "${DEFAULT_TEST_EXECUTOR}" CACHE STRING "")



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


[PATCH] D135326: Half-done attempt to move tail padding callback from TargetCXXABI to TargetInfo

2022-10-06 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added inline comments.



Comment at: clang/lib/Basic/Targets/OSTargets.h:169
+if (T.getOS() == llvm::Triple::WatchOS ||
+this->getCXXABI().getKind() == TargetCXXABI::AppleARM64)
+  return TargetInfo::UseTailPaddingUnlessPOD11;

rnk wrote:
> I think it would be equivalent to check `T.getArch() == 
> llvm::Triple::AArch64`, that's probably what set the TargetCXXABI.
Hmm, seems one of the tests failed because apparently CXXABI can be chosen 
separately from target. `clang/test/CodeGenCXX/armv7k.cpp` for instance runs 
with `-triple=arm64_32-apple-ios -emit-llvm -target-abi darwinpcs`

Which seems to have an UnknownOS on the triple, but a WatchOS on the 
TargetCXXABI... (I don't really understand/haven't looked into how all these 
things relate to the command line arguments there - none of it mentions 
WatchOS, but maybe `darwinpcs` is the name of watchOS?

Updating this function to inspect the CXXABI for WatchOS, AppleARM64, and iOS 
(which I'd missed from here previously) here makes the tests pass... 

Maybe that suggests we should move all this (& the D119051) to TargetCXXABI?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135326

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


[PATCH] D135326: Half-done attempt to move tail padding callback from TargetCXXABI to TargetInfo

2022-10-06 Thread David Blaikie via Phabricator via cfe-commits
dblaikie updated this revision to Diff 465957.
dblaikie added a comment.

Fix to use CXXABI


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135326

Files:
  clang/include/clang/Basic/TargetCXXABI.h
  clang/include/clang/Basic/TargetInfo.h
  clang/lib/AST/RecordLayoutBuilder.cpp
  clang/lib/Basic/Targets/OSTargets.h

Index: clang/lib/Basic/Targets/OSTargets.h
===
--- clang/lib/Basic/Targets/OSTargets.h
+++ clang/lib/Basic/Targets/OSTargets.h
@@ -13,6 +13,7 @@
 #define LLVM_CLANG_LIB_BASIC_TARGETS_OSTARGETS_H
 
 #include "Targets.h"
+#include "llvm/ADT/Triple.h"
 
 namespace clang {
 namespace targets {
@@ -161,6 +162,16 @@
: TargetInfo::UnsignedLongLong)
: TargetInfo::getLeastIntTypeByWidth(BitWidth, IsSigned);
   }
+
+  TargetInfo::TailPaddingUseRules getTailPaddingUseRules() const override {
+auto CXXABI = this->getCXXABI().getKind();
+if (CXXABI == TargetCXXABI::iOS)
+  return TargetInfo::UseTailPaddingUnlessPOD03;
+if (CXXABI == TargetCXXABI::WatchOS ||
+CXXABI == TargetCXXABI::AppleARM64)
+  return TargetInfo::UseTailPaddingUnlessPOD11;
+return TargetInfo::UseTailPaddingUnlessPOD03;
+  }
 };
 
 // DragonFlyBSD Target
@@ -845,6 +856,11 @@
 this->WCharType = TargetInfo::UnsignedShort;
 this->WIntType = TargetInfo::UnsignedShort;
   }
+  TargetInfo::TailPaddingUseRules getTailPaddingUseRules() const override {
+if (this->getTriple().isWindowsMSVCEnvironment())
+  return TargetInfo::AlwaysUseTailPadding;
+return TargetInfo::UseTailPaddingUnlessPOD03;
+  }
 };
 
 template 
@@ -922,6 +938,9 @@
 this->MCountName = "__mcount";
 this->TheCXXABI.set(TargetCXXABI::Fuchsia);
   }
+  TargetInfo::TailPaddingUseRules getTailPaddingUseRules() const override {
+return TargetInfo::UseTailPaddingUnlessPOD11;
+  }
 };
 
 // WebAssembly target
@@ -949,6 +968,9 @@
 this->TheCXXABI.set(TargetCXXABI::WebAssembly);
 this->HasFloat128 = true;
   }
+  TargetInfo::TailPaddingUseRules getTailPaddingUseRules() const override {
+return TargetInfo::UseTailPaddingUnlessPOD11;
+  }
 };
 
 // WASI target
Index: clang/lib/AST/RecordLayoutBuilder.cpp
===
--- clang/lib/AST/RecordLayoutBuilder.cpp
+++ clang/lib/AST/RecordLayoutBuilder.cpp
@@ -2392,12 +2392,12 @@
 /// Does the target C++ ABI require us to skip over the tail-padding
 /// of the given class (considering it as a base class) when allocating
 /// objects?
-static bool mustSkipTailPadding(TargetCXXABI ABI, const CXXRecordDecl *RD) {
-  switch (ABI.getTailPaddingUseRules()) {
-  case TargetCXXABI::AlwaysUseTailPadding:
+static bool mustSkipTailPadding(const TargetInfo , const CXXRecordDecl *RD) {
+  switch (TI.getTailPaddingUseRules()) {
+  case TargetInfo::AlwaysUseTailPadding:
 return false;
 
-  case TargetCXXABI::UseTailPaddingUnlessPOD03:
+  case TargetInfo::UseTailPaddingUnlessPOD03:
 // FIXME: To the extent that this is meant to cover the Itanium ABI
 // rules, we should implement the restrictions about over-sized
 // bitfields:
@@ -2418,7 +2418,7 @@
 //   intended.
 return RD->isPOD();
 
-  case TargetCXXABI::UseTailPaddingUnlessPOD11:
+  case TargetInfo::UseTailPaddingUnlessPOD11:
 // This is equivalent to RD->getTypeForDecl().isCXX11PODType(),
 // but with a lot of abstraction penalty stripped off.  This does
 // assume that these properties are set correctly even in C++98
@@ -3319,7 +3319,7 @@
   // tail-padding of base classes.  This is ABI-dependent.
   // FIXME: this should be stored in the record layout.
   bool skipTailPadding =
-  mustSkipTailPadding(getTargetInfo().getCXXABI(), RD);
+  mustSkipTailPadding(getTargetInfo(), RD);
 
   // FIXME: This should be done in FinalizeLayout.
   CharUnits DataSize =
Index: clang/include/clang/Basic/TargetInfo.h
===
--- clang/include/clang/Basic/TargetInfo.h
+++ clang/include/clang/Basic/TargetInfo.h
@@ -945,6 +945,14 @@
   virtual void getTargetDefines(const LangOptions ,
 MacroBuilder ) const = 0;
 
+  enum TailPaddingUseRules {
+AlwaysUseTailPadding,
+UseTailPaddingUnlessPOD03,
+UseTailPaddingUnlessPOD11
+  };
+  virtual TailPaddingUseRules getTailPaddingUseRules() const {
+return UseTailPaddingUnlessPOD03;
+  }
 
   /// Return information about target-specific builtins for
   /// the current primary target, and info about which builtins are non-portable
Index: clang/include/clang/Basic/TargetCXXABI.h
===
--- clang/include/clang/Basic/TargetCXXABI.h
+++ clang/include/clang/Basic/TargetCXXABI.h
@@ -257,57 +257,6 @@
 llvm_unreachable("bad ABI kind");
 

[PATCH] D119051: Extend the C++03 definition of POD to include defaulted functions

2022-10-06 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added inline comments.



Comment at: clang/lib/AST/DeclCXX.cpp:774-775
+if ((!Constructor->isDeleted() && !Constructor->isDefaulted()) ||
+(getLangOpts().getClangABICompat() <=
+ LangOptions::ClangABI::Ver15 || Target.isPS() || 
Target.isOSDarwin())) {
+  // C++ [class]p4:

rnk wrote:
> dblaikie wrote:
> > rnk wrote:
> > > I think this ought to be factored into a TargetInfo method, so we can 
> > > share the logic here and below somehow. Compare this for example with 
> > > `TargetInfo::getCallingConvKind`, which has a similar purpose.
> > Seems plausible - though the version is stored in LangOpts, which isn't 
> > currently plumbed through into TargetInfo - should it be plumbed through, 
> > or is there some layering thing there where targets shouldn't depend on 
> > lang opts?
> > 
> > Looks like it'd mostly involve passing LangOpts down here: 
> > https://github.com/llvm/llvm-project/blob/main/clang/lib/Frontend/CompilerInstance.cpp#L107
> >  and plumbing it through all the `TargetInfo` ctors, possibly either 
> > storing `LangOpts&` in the `TargetInfo`, or computing the 
> > `DefaultedSMFArePOD` property in the ctor and storing that as a `bool` 
> > member in `TargetInfo` to return from some query function to be added to 
> > that hierarchy.
> > 
> > Or I guess like `getOSDefines` have `getDefaultedSMFArePOD` takes 
> > `LangOptions` as a parameter?
> My main concern is keeping complex target-specific conditions out of DeclCXX 
> to improve readability. Any way to achieve that sounds good to me.
> 
> I think I'd lean towards passing LangOpts as a parameter. After that, storing 
> `DefaultedSMFArePOD` on TargetInfo as a bool sounds good. You can set the 
> field in `TargetInfo::adjust` to read LangOpts, and then override that in PS 
> & Darwin specific ::adjust method overrides.
Fair enough - tried this out with a LongOpts parameter (I guess 
`getCallingConvKind` passes in just the boolean about whether it's the right 
ABI compatibility version - requiring the caller to check, but that seems a bit 
weird/specific? So I prefer passing in the whole LangOpts here and querying the 
right property inside TargetInfo)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119051

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


[PATCH] D119051: Extend the C++03 definition of POD to include defaulted functions

2022-10-06 Thread David Blaikie via Phabricator via cfe-commits
dblaikie updated this revision to Diff 465956.
dblaikie added a comment.

Move condition to TargetInfo


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119051

Files:
  clang/include/clang/Basic/LangOptions.h
  clang/include/clang/Basic/TargetInfo.h
  clang/lib/AST/DeclCXX.cpp
  clang/lib/Basic/TargetInfo.cpp
  clang/lib/Basic/Targets/OSTargets.h
  clang/test/AST/conditionally-trivial-smfs.cpp
  clang/test/SemaCXX/class-layout.cpp

Index: clang/test/SemaCXX/class-layout.cpp
===
--- clang/test/SemaCXX/class-layout.cpp
+++ clang/test/SemaCXX/class-layout.cpp
@@ -1,10 +1,12 @@
-// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify -std=c++98 -Wno-inaccessible-base
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify -std=c++98 -Wno-inaccessible-base -Wno-c++11-extensions
 // RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify -std=c++11 -Wno-inaccessible-base
 // RUN: %clang_cc1 -triple x86_64-apple-darwin%s -fsyntax-only -verify -std=c++11 -Wno-inaccessible-base -DCLANG_ABI_COMPAT=14
 // RUN: %clang_cc1 -triple x86_64-scei-ps4%s -fsyntax-only -verify -std=c++11 -Wno-inaccessible-base -DCLANG_ABI_COMPAT=6
 // RUN: %clang_cc1 -triple x86_64-sie-ps5 %s -fsyntax-only -verify -std=c++11 -Wno-inaccessible-base -DCLANG_ABI_COMPAT=6
 // RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify -std=c++11 -Wno-inaccessible-base -fclang-abi-compat=6 -DCLANG_ABI_COMPAT=6
 // RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify -std=c++11 -Wno-inaccessible-base -fclang-abi-compat=14 -DCLANG_ABI_COMPAT=14
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify -std=c++11 -Wno-inaccessible-base -fclang-abi-compat=15 -DCLANG_ABI_COMPAT=15
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify -std=c++11 -Wno-inaccessible-base -fclang-abi-compat=16 -DCLANG_ABI_COMPAT=16
 // expected-no-diagnostics
 
 #define SA(n, p) int a##n[(p) ? 1 : -1]
@@ -642,3 +644,33 @@
 _Static_assert(_Alignof(t1) == 1, "");
 _Static_assert(_Alignof(t2) == 1, "");
 } // namespace non_pod_packed
+
+namespace cxx11_pod {
+struct t1 {
+  t1() = default;
+  t1(const t1&) = delete;
+  ~t1() = delete;
+  t1(t1&&) = default;
+  int a;
+  char c;
+};
+struct t2 {
+  t1 v1;
+} __attribute__((packed));
+// 14 and below consider t1 non-pod, but pack it anyway
+// 15 considers it non-pod and doesn't pack it
+// 16 and up considers it pod and packs it again...
+#if defined(CLANG_ABI_COMPAT) && CLANG_ABI_COMPAT == 15
+_Static_assert(_Alignof(t2) == 4, "");
+#else
+_Static_assert(_Alignof(t2) == 1, "");
+#endif
+struct t3 : t1 {
+  char c;
+};
+#if defined(CLANG_ABI_COMPAT) && CLANG_ABI_COMPAT <= 15
+_Static_assert(sizeof(t3) == 8, "");
+#else
+_Static_assert(sizeof(t3) == 12, "");
+#endif
+}
Index: clang/test/AST/conditionally-trivial-smfs.cpp
===
--- clang/test/AST/conditionally-trivial-smfs.cpp
+++ clang/test/AST/conditionally-trivial-smfs.cpp
@@ -297,6 +297,7 @@
 // CHECK-NEXT:  "isAggregate": true,
 // CHECK-NEXT:  "isEmpty": true,
 // CHECK-NEXT:  "isLiteral": true,
+// CHECK-NEXT:  "isPOD": true,
 // CHECK-NEXT:  "isStandardLayout": true,
 // CHECK-NEXT:  "isTrivial": true,
 // CHECK-NEXT:  "isTriviallyCopyable": true,
@@ -316,6 +317,7 @@
 // CHECK-NEXT:  "isAggregate": true,
 // CHECK-NEXT:  "isEmpty": true,
 // CHECK-NEXT:  "isLiteral": true,
+// CHECK-NEXT:  "isPOD": true,
 // CHECK-NEXT:  "isStandardLayout": true,
 // CHECK-NEXT:  "isTrivial": true,
 // CHECK-NEXT:  "isTriviallyCopyable": true,
@@ -335,6 +337,7 @@
 // CHECK-NEXT:  "isAggregate": true,
 // CHECK-NEXT:  "isEmpty": true,
 // CHECK-NEXT:  "isLiteral": true,
+// CHECK-NEXT:  "isPOD": true,
 // CHECK-NEXT:  "isStandardLayout": true,
 // CHECK-NEXT:  "moveAssign": {
 // CHECK-NEXT:"exists": true,
Index: clang/lib/Basic/Targets/OSTargets.h
===
--- clang/lib/Basic/Targets/OSTargets.h
+++ clang/lib/Basic/Targets/OSTargets.h
@@ -161,6 +161,10 @@
: TargetInfo::UnsignedLongLong)
: TargetInfo::getLeastIntTypeByWidth(BitWidth, IsSigned);
   }
+
+  bool areDefaultedSMFStillPOD(const LangOptions &) const override {
+return false;
+  }
 };
 
 // DragonFlyBSD Target
@@ -558,6 +562,10 @@
   checkCallingConvention(CallingConv CC) const override {
 return (CC == CC_C) ? TargetInfo::CCCR_OK : TargetInfo::CCCR_Error;
   }
+
+  bool areDefaultedSMFStillPOD(const LangOptions &) const override {
+return false;
+  }
 };
 
 // PS4 Target
Index: 

[PATCH] D130327: [ODRHash] Detect duplicate `ObjCProtocolDecl` ODR mismatches during parsing.

2022-10-06 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai updated this revision to Diff 465954.
vsapsai added a comment.

Rebase.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130327

Files:
  clang/include/clang/AST/DeclObjC.h
  clang/include/clang/AST/ODRDiagsEmitter.h
  clang/include/clang/Basic/DiagnosticASTKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/DeclObjC.cpp
  clang/lib/AST/ODRDiagsEmitter.cpp
  clang/lib/Parse/ParseObjc.cpp
  clang/lib/Sema/SemaDeclObjC.cpp
  clang/test/Modules/compare-objc-protocol.m
  clang/test/Modules/hidden-duplicates.m

Index: clang/test/Modules/hidden-duplicates.m
===
--- /dev/null
+++ clang/test/Modules/hidden-duplicates.m
@@ -0,0 +1,56 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: %clang_cc1 -emit-llvm -o %t/test.bc -I %t/include %t/test.m -verify \
+// RUN:-fmodules -fimplicit-module-maps -fmodules-cache-path=%t/modules.cache
+// RUN: %clang_cc1 -emit-llvm -o %t/test.bc -I %t/include %t/test.m -verify -DTEST_MAKE_HIDDEN_VISIBLE=1 \
+// RUN:-fmodules -fimplicit-module-maps -fmodules-cache-path=%t/modules.cache
+// RUN: %clang_cc1 -emit-llvm -o %t/test.bc -I %t/include %t/test.m -verify -x objective-c++ \
+// RUN:-fmodules -fimplicit-module-maps -fmodules-cache-path=%t/modules.cache
+// RUN: %clang_cc1 -emit-llvm -o %t/test.bc -I %t/include %t/test.m -verify -DTEST_MAKE_HIDDEN_VISIBLE=1 -x objective-c++ \
+// RUN:-fmodules -fimplicit-module-maps -fmodules-cache-path=%t/modules.cache
+
+// Test parsing duplicate Objective-C entities when a previous entity is defined
+// in a hidden [sub]module and cannot be used.
+//
+// Testing with header guards and includes on purpose as tracking imports in
+// modules is a separate issue.
+
+//--- include/textual.h
+#ifndef TEXTUAL_H
+#define TEXTUAL_H
+
+@protocol TestProtocol
+- (void)someMethod;
+@end
+
+@protocol ForwardDeclaredProtocolWithoutDefinition;
+
+id protocolDefinition(id t);
+id forwardDeclaredProtocol(
+id t);
+
+#endif
+
+//--- include/empty.h
+//--- include/initially_hidden.h
+#include "textual.h"
+
+//--- include/module.modulemap
+module Piecewise {
+  module Empty {
+header "empty.h"
+  }
+  module InitiallyHidden {
+header "initially_hidden.h"
+export *
+  }
+}
+
+//--- test.m
+// Including empty.h loads the entire module Piecewise but keeps InitiallyHidden hidden.
+#include "empty.h"
+#include "textual.h"
+#ifdef TEST_MAKE_HIDDEN_VISIBLE
+#include "initially_hidden.h"
+#endif
+// expected-no-diagnostics
Index: clang/test/Modules/compare-objc-protocol.m
===
--- clang/test/Modules/compare-objc-protocol.m
+++ clang/test/Modules/compare-objc-protocol.m
@@ -19,6 +19,11 @@
 // RUN: %clang_cc1 -I%t/include -verify %t/test.m -fblocks -fobjc-arc \
 // RUN:-fmodules -fimplicit-module-maps -fmodules-cache-path=%t/modules.cache
 
+// Run the same test with second.h being modular
+// RUN: cat %t/include/second.modulemap >> %t/include/module.modulemap
+// RUN: %clang_cc1 -I%t/include -verify %t/test.m -fblocks -fobjc-arc -DTEST_MODULAR=1 \
+// RUN:-fmodules -fimplicit-module-maps -fmodules-cache-path=%t/modules.cache
+
 // In non-modular case we ignore protocol redefinitions. But with modules
 // previous definition can come from a hidden [sub]module. And in this case we
 // allow a new definition if it is equivalent to the hidden one.
@@ -47,6 +52,7 @@
 export *
   }
 }
+//--- include/second.modulemap
 module Second {
   header "second.h"
   export *
@@ -99,17 +105,21 @@
 
 id compareProtocolPresence1;
 // expected-error@first.h:* {{'CompareProtocolPresence1' has different definitions in different modules; first difference is definition in module 'First.Hidden' found 1 referenced protocol}}
+#ifdef TEST_MODULAR
 // expected-note@second.h:* {{but in 'Second' found 0 referenced protocols}}
+#else
+// expected-note@second.h:* {{but in definition here found 0 referenced protocols}}
+#endif
 id compareProtocolPresence2;
 // expected-error@first.h:* {{'CompareProtocolPresence2' has different definitions in different modules; first difference is definition in module 'First.Hidden' found 0 referenced protocols}}
-// expected-note@second.h:* {{but in 'Second' found 1 referenced protocol}}
+// expected-note-re@second.h:* {{but in {{'Second'|definition here}} found 1 referenced protocol}}
 
 id compareDifferentProtocols;
 // expected-error@first.h:* {{'CompareDifferentProtocols' has different definitions in different modules; first difference is definition in module 'First.Hidden' found 1st referenced protocol with name 'CommonProtocol'}}
-// expected-note@second.h:* {{but in 'Second' found 1st referenced protocol with different name 'ExtraProtocol'}}
+// expected-note-re@second.h:* {{but in {{'Second'|definition here}} found 1st referenced protocol with 

[PATCH] D130326: [ODRHash] Hash `ObjCPropertyDecl` and diagnose discovered mismatches.

2022-10-06 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai updated this revision to Diff 465953.
vsapsai added a comment.

Rebase.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130326

Files:
  clang/include/clang/AST/ODRDiagsEmitter.h
  clang/include/clang/Basic/DiagnosticASTKinds.td
  clang/lib/AST/ODRDiagsEmitter.cpp
  clang/lib/AST/ODRHash.cpp
  clang/test/Modules/compare-objc-protocol.m

Index: clang/test/Modules/compare-objc-protocol.m
===
--- clang/test/Modules/compare-objc-protocol.m
+++ clang/test/Modules/compare-objc-protocol.m
@@ -242,3 +242,108 @@
 // expected-note@second.h:* {{but in 'Second' found 'required' method control}}
 id compareMethodRequirednessDefault; // no error
 #endif
+
+#if defined(FIRST)
+@protocol CompareMatchingProperties
+@property int matchingPropName;
+@end
+
+@protocol ComparePropertyPresence1
+@property int propPresence1;
+@end
+@protocol ComparePropertyPresence2
+@end
+
+@protocol ComparePropertyName
+@property int propNameA;
+@end
+
+@protocol ComparePropertyType
+@property int propType;
+@end
+
+@protocol ComparePropertyOrder
+@property int propOrderX;
+@property int propOrderY;
+@end
+
+@protocol CompareMatchingPropertyAttributes
+@property (nonatomic, assign) int matchingProp;
+@end
+@protocol ComparePropertyAttributes
+@property (nonatomic) int propAttributes;
+@end
+// Edge cases.
+@protocol CompareFirstImplAttribute
+@property int firstImplAttribute;
+@end
+@protocol CompareLastImplAttribute
+// Cannot test with protocols 'direct' attribute because it's not allowed.
+@property (class) int lastImplAttribute;
+@end
+#elif defined(SECOND)
+@protocol CompareMatchingProperties
+@property int matchingPropName;
+@end
+
+@protocol ComparePropertyPresence1
+@end
+@protocol ComparePropertyPresence2
+@property int propPresence2;
+@end
+
+@protocol ComparePropertyName
+@property int propNameB;
+@end
+
+@protocol ComparePropertyType
+@property float propType;
+@end
+
+@protocol ComparePropertyOrder
+@property int propOrderY;
+@property int propOrderX;
+@end
+
+@protocol CompareMatchingPropertyAttributes
+@property (assign, nonatomic) int matchingProp;
+@end
+@protocol ComparePropertyAttributes
+@property (atomic) int propAttributes;
+@end
+// Edge cases.
+@protocol CompareFirstImplAttribute
+@property (readonly) int firstImplAttribute;
+@end
+@protocol CompareLastImplAttribute
+@property int lastImplAttribute;
+@end
+#else
+id compareMatchingProperties;
+id comparePropertyPresence1;
+// expected-error@first.h:* {{'ComparePropertyPresence1' has different definitions in different modules; first difference is definition in module 'First.Hidden' found property}}
+// expected-note@second.h:* {{but in 'Second' found end of class}}
+id comparePropertyPresence2;
+// expected-error@first.h:* {{'ComparePropertyPresence2' has different definitions in different modules; first difference is definition in module 'First.Hidden' found end of class}}
+// expected-note@second.h:* {{but in 'Second' found property}}
+id comparePropertyName;
+// expected-error@first.h:* {{'ComparePropertyName' has different definitions in different modules; first difference is definition in module 'First.Hidden' found property 'propNameA'}}
+// expected-note@second.h:* {{but in 'Second' found property 'propNameB'}}
+id comparePropertyType;
+// expected-error@first.h:* {{'ComparePropertyType' has different definitions in different modules; first difference is definition in module 'First.Hidden' found property 'propType' with type 'int'}}
+// expected-note@second.h:* {{but in 'Second' found property 'propType' with type 'float'}}
+id comparePropertyOrder;
+// expected-error@first.h:* {{'ComparePropertyOrder' has different definitions in different modules; first difference is definition in module 'First.Hidden' found property 'propOrderX'}}
+// expected-note@second.h:* {{but in 'Second' found property 'propOrderY'}}
+
+id compareMatchingPropertyAttributes;
+id comparePropertyAttributes;
+// expected-error@first.h:* {{'ComparePropertyAttributes' has different definitions in different modules; first difference is definition in module 'First.Hidden' found property 'propAttributes' with 'nonatomic' attribute}}
+// expected-note@second.h:* {{but in 'Second' found property 'propAttributes' with different 'nonatomic' attribute}}
+id compareFirstImplAttribute;
+// expected-error@first.h:* {{'CompareFirstImplAttribute' has different definitions in different modules; first difference is definition in module 'First.Hidden' found property 'firstImplAttribute' with default 'readonly' attribute}}
+// expected-note@second.h:* {{but in 'Second' found property 'firstImplAttribute' with different 'readonly' attribute}}
+id compareLastImplAttribute;
+// expected-error@first.h:* {{'CompareLastImplAttribute' has different definitions in different modules; first difference is definition in module 'First.Hidden' found property 

[PATCH] D130325: [ODRHash] Hash `ObjCMethodDecl` and diagnose discovered mismatches.

2022-10-06 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai updated this revision to Diff 465952.
vsapsai added a comment.

Rebase.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130325

Files:
  clang/include/clang/AST/ODRDiagsEmitter.h
  clang/include/clang/Basic/DiagnosticASTKinds.td
  clang/lib/AST/ODRDiagsEmitter.cpp
  clang/lib/AST/ODRHash.cpp
  clang/test/Modules/compare-objc-protocol.m

Index: clang/test/Modules/compare-objc-protocol.m
===
--- clang/test/Modules/compare-objc-protocol.m
+++ clang/test/Modules/compare-objc-protocol.m
@@ -111,3 +111,134 @@
 // expected-error@first.h:* {{'CompareProtocolOrder' has different definitions in different modules; first difference is definition in module 'First.Hidden' found 1st referenced protocol with name 'CommonProtocol'}}
 // expected-note@second.h:* {{but in 'Second' found 1st referenced protocol with different name 'ExtraProtocol'}}
 #endif
+
+#if defined(FIRST)
+@protocol CompareMatchingMethods
+- (float)matchingMethod:(int)arg;
+@end
+
+@protocol CompareMethodPresence1
+- (void)presenceMethod1;
+@end
+@protocol CompareMethodPresence2
+@end
+
+@protocol CompareMethodName
+- (void)methodNameA;
+@end
+
+@protocol CompareMethodArgCount
+- (void)methodArgCount:(int)arg0 :(int)arg1;
+@end
+@protocol CompareMethodArgName
+- (void)methodArgName:(int)argNameA;
+@end
+@protocol CompareMethodArgType
+- (void)methodArgType:(int)argType;
+@end
+
+@protocol CompareMethodReturnType
+- (int)methodReturnType;
+@end
+
+@protocol CompareMethodOrder
+- (void)methodOrderFirst;
+- (void)methodOrderSecond;
+@end
+
+@protocol CompareMethodClassInstance
+- (void)methodClassInstance;
+@end
+
+@protocol CompareMethodRequirednessExplicit
+@optional
+- (void)methodRequiredness;
+@end
+@protocol CompareMethodRequirednessDefault
+// @required is default
+- (void)methodRequiredness;
+@end
+#elif defined(SECOND)
+@protocol CompareMatchingMethods
+- (float)matchingMethod:(int)arg;
+@end
+
+@protocol CompareMethodPresence1
+@end
+@protocol CompareMethodPresence2
+- (void)presenceMethod2;
+@end
+
+@protocol CompareMethodName
+- (void)methodNameB;
+@end
+
+@protocol CompareMethodArgCount
+- (void)methodArgCount:(int)arg0;
+@end
+@protocol CompareMethodArgName
+- (void)methodArgName:(int)argNameB;
+@end
+@protocol CompareMethodArgType
+- (void)methodArgType:(float)argType;
+@end
+
+@protocol CompareMethodReturnType
+- (float)methodReturnType;
+@end
+
+@protocol CompareMethodOrder
+- (void)methodOrderSecond;
+- (void)methodOrderFirst;
+@end
+
+@protocol CompareMethodClassInstance
++ (void)methodClassInstance;
+@end
+
+@protocol CompareMethodRequirednessExplicit
+@required
+- (void)methodRequiredness;
+@end
+@protocol CompareMethodRequirednessDefault
+@required
+- (void)methodRequiredness;
+@end
+#else
+id compareMatchingMethods; // no error
+id compareMethodPresence1;
+// expected-error@first.h:* {{'CompareMethodPresence1' has different definitions in different modules; first difference is definition in module 'First.Hidden' found method}}
+// expected-note@second.h:* {{but in 'Second' found end of class}}
+id compareMethodPresence2;
+// expected-error@first.h:* {{'CompareMethodPresence2' has different definitions in different modules; first difference is definition in module 'First.Hidden' found end of class}}
+// expected-note@second.h:* {{but in 'Second' found method}}
+id compareMethodName;
+// expected-error@first.h:* {{'CompareMethodName' has different definitions in different modules; first difference is definition in module 'First.Hidden' found method 'methodNameA'}}
+// expected-note@second.h:* {{but in 'Second' found different method 'methodNameB'}}
+
+id compareMethodArgCount;
+// expected-error@first.h:* {{'CompareMethodArgCount' has different definitions in different modules; first difference is definition in module 'First.Hidden' found method 'methodArgCount::' that has 2 parameters}}
+// expected-note@second.h:* {{but in 'Second' found method 'methodArgCount:' that has 1 parameter}}
+id compareMethodArgName;
+// expected-error@first.h:* {{'CompareMethodArgName' has different definitions in different modules; first difference is definition in module 'First.Hidden' found method 'methodArgName:' with 1st parameter named 'argNameA'}}
+// expected-note@second.h:* {{but in 'Second' found method 'methodArgName:' with 1st parameter named 'argNameB'}}
+id compareMethodArgType;
+// expected-error@first.h:* {{'CompareMethodArgType' has different definitions in different modules; first difference is definition in module 'First.Hidden' found method 'methodArgType:' with 1st parameter of type 'int'}}
+// expected-note@second.h:* {{but in 'Second' found method 'methodArgType:' with 1st parameter of type 'float'}}
+
+id compareMethodReturnType;
+// expected-error@first.h:* {{'CompareMethodReturnType' has different definitions in different modules; first difference is definition in module 

[PATCH] D130324: [ODRHash] Hash `ObjCProtocolDecl` and diagnose discovered mismatches.

2022-10-06 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai updated this revision to Diff 465950.
vsapsai added a comment.

Rebase.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130324

Files:
  clang/include/clang/AST/DeclObjC.h
  clang/include/clang/AST/ODRDiagsEmitter.h
  clang/include/clang/AST/ODRHash.h
  clang/include/clang/Basic/DiagnosticASTKinds.td
  clang/include/clang/Serialization/ASTReader.h
  clang/lib/AST/DeclObjC.cpp
  clang/lib/AST/ODRDiagsEmitter.cpp
  clang/lib/AST/ODRHash.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTReaderDecl.cpp
  clang/lib/Serialization/ASTWriterDecl.cpp
  clang/test/Modules/compare-objc-protocol.m

Index: clang/test/Modules/compare-objc-protocol.m
===
--- /dev/null
+++ clang/test/Modules/compare-objc-protocol.m
@@ -0,0 +1,113 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+
+// Build first header file
+// RUN: echo "#define FIRST" >> %t/include/first.h
+// RUN: cat %t/test.m>> %t/include/first.h
+// RUN: echo "#undef FIRST"  >> %t/include/first.h
+
+// Build second header file
+// RUN: echo "#define SECOND" >> %t/include/second.h
+// RUN: cat %t/test.m >> %t/include/second.h
+// RUN: echo "#undef SECOND"  >> %t/include/second.h
+
+// Test that each header can compile
+// RUN: %clang_cc1 -fsyntax-only -x objective-c %t/include/first.h -fblocks -fobjc-arc
+// RUN: %clang_cc1 -fsyntax-only -x objective-c %t/include/second.h -fblocks -fobjc-arc
+
+// Run test
+// RUN: %clang_cc1 -I%t/include -verify %t/test.m -fblocks -fobjc-arc \
+// RUN:-fmodules -fimplicit-module-maps -fmodules-cache-path=%t/modules.cache
+
+// In non-modular case we ignore protocol redefinitions. But with modules
+// previous definition can come from a hidden [sub]module. And in this case we
+// allow a new definition if it is equivalent to the hidden one.
+//
+// This test case is to verify equivalence checks.
+
+//--- include/common.h
+#ifndef COMMON_H
+#define COMMON_H
+@protocol CommonProtocol @end
+@protocol ExtraProtocol @end
+#endif
+
+//--- include/first-empty.h
+//--- include/module.modulemap
+module Common {
+  header "common.h"
+  export *
+}
+module First {
+  module Empty {
+header "first-empty.h"
+  }
+  module Hidden {
+header "first.h"
+export *
+  }
+}
+module Second {
+  header "second.h"
+  export *
+}
+
+//--- test.m
+#if defined(FIRST) || defined(SECOND)
+# include "common.h"
+#endif
+
+#if !defined(FIRST) && !defined(SECOND)
+# include "first-empty.h"
+# include "second.h"
+#endif
+
+#if defined(FIRST)
+@protocol CompareForwardDeclaration1;
+@protocol CompareForwardDeclaration2 @end
+#elif defined(SECOND)
+@protocol CompareForwardDeclaration1 @end
+@protocol CompareForwardDeclaration2;
+#else
+id compareForwardDeclaration1;
+id compareForwardDeclaration2;
+#endif
+
+#if defined(FIRST)
+@protocol CompareMatchingConformingProtocols @end
+@protocol ForwardProtocol;
+@protocol CompareMatchingConformingForwardProtocols @end
+
+@protocol CompareProtocolPresence1 @end
+@protocol CompareProtocolPresence2 @end
+
+@protocol CompareDifferentProtocols @end
+@protocol CompareProtocolOrder @end
+#elif defined(SECOND)
+@protocol CompareMatchingConformingProtocols @end
+@protocol ForwardProtocol @end
+@protocol CompareMatchingConformingForwardProtocols @end
+
+@protocol CompareProtocolPresence1 @end
+@protocol CompareProtocolPresence2 @end
+
+@protocol CompareDifferentProtocols @end
+@protocol CompareProtocolOrder @end
+#else
+id compareMatchingConformingProtocols;
+id compareMatchingConformingForwardProtocols;
+
+id compareProtocolPresence1;
+// expected-error@first.h:* {{'CompareProtocolPresence1' has different definitions in different modules; first difference is definition in module 'First.Hidden' found 1 referenced protocol}}
+// expected-note@second.h:* {{but in 'Second' found 0 referenced protocols}}
+id compareProtocolPresence2;
+// expected-error@first.h:* {{'CompareProtocolPresence2' has different definitions in different modules; first difference is definition in module 'First.Hidden' found 0 referenced protocols}}
+// expected-note@second.h:* {{but in 'Second' found 1 referenced protocol}}
+
+id compareDifferentProtocols;
+// expected-error@first.h:* {{'CompareDifferentProtocols' has different definitions in different modules; first difference is definition in module 'First.Hidden' found 1st referenced protocol with name 'CommonProtocol'}}
+// expected-note@second.h:* {{but in 'Second' found 1st referenced protocol with different name 'ExtraProtocol'}}
+id compareProtocolOrder;
+// expected-error@first.h:* {{'CompareProtocolOrder' has different definitions in different modules; first difference is definition in module 'First.Hidden' found 1st referenced protocol with name 'CommonProtocol'}}
+// expected-note@second.h:* {{but in 'Second' found 1st referenced protocol with different name 'ExtraProtocol'}}
+#endif

[PATCH] D129755: Thread safety analysis: Support copy-elided production of scoped capabilities through arbitrary calls

2022-10-06 Thread Aaron Puchert via Phabricator via cfe-commits
aaronpuchert added inline comments.



Comment at: clang/lib/Analysis/ThreadSafety.cpp:1789
+  auto inserted = ConstructedObjects.insert({Exp, Placeholder.first});
+  assert(inserted.second && "Are we visiting the same expression again?");
+  if (isa(Exp))

chapuni wrote:
> 'inserted' is used only here.
Correct, is that an issue? Perhaps `-Wunused-variable` in Release builds?

Otherwise I believe it's correct—we don't need the iterator and we should 
generally not insert expressions twice, hence the assertion.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129755

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


[PATCH] D129531: [clang][C++20] P0960R3: Allow initializing aggregates from a parenthesized list of values

2022-10-06 Thread Alan Zhao via Phabricator via cfe-commits
ayzhao updated this revision to Diff 465943.
ayzhao added a comment.

Fill out implementation for ClassifyExprValueKind(...)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129531

Files:
  clang/include/clang/AST/Decl.h
  clang/include/clang/AST/ExprCXX.h
  clang/include/clang/AST/RecursiveASTVisitor.h
  clang/include/clang/Basic/StmtNodes.td
  clang/include/clang/Sema/Initialization.h
  clang/lib/AST/Expr.cpp
  clang/lib/AST/ExprCXX.cpp
  clang/lib/AST/ExprClassification.cpp
  clang/lib/AST/ExprConstant.cpp
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/JSONNodeDumper.cpp
  clang/lib/AST/StmtPrinter.cpp
  clang/lib/AST/StmtProfile.cpp
  clang/lib/AST/TextNodeDumper.cpp
  clang/lib/CodeGen/CGExprAgg.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaExceptionSpec.cpp
  clang/lib/Sema/SemaInit.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTReaderStmt.cpp
  clang/lib/Serialization/ASTWriterStmt.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
  clang/test/CXX/class/class.compare/class.spaceship/p1.cpp
  clang/test/CXX/drs/dr2xx.cpp
  clang/test/CXX/temp/temp.decls/temp.variadic/p4.cpp
  clang/test/CodeGen/P0960R3.cpp
  clang/test/SemaCXX/P0960R3.cpp
  clang/test/SemaCXX/cxx2a-explicit-bool.cpp

Index: clang/test/SemaCXX/cxx2a-explicit-bool.cpp
===
--- clang/test/SemaCXX/cxx2a-explicit-bool.cpp
+++ clang/test/SemaCXX/cxx2a-explicit-bool.cpp
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -std=c++17 -fsyntax-only %s -verify -Wno-c++2a-extensions
-// RUN: %clang_cc1 -std=c++2a -fsyntax-only %s -verify
+// RUN: %clang_cc1 -std=c++17 -fsyntax-only %s -verify=expected,pre20 -Wno-c++2a-extensions
+// RUN: %clang_cc1 -std=c++2a -fsyntax-only %s -verify=expected,pro20
 
 template  struct enable_ifv {};
 
@@ -20,7 +20,7 @@
 
 template
 struct A {
-// expected-note@-1+ {{candidate constructor}}
+// pre20-note@-1+ {{candidate constructor}}
   explicit(1 << a)
 // expected-note@-1 {{negative shift count -1}}
 // expected-error@-2 {{explicit specifier argument is not a constant expression}}
@@ -28,8 +28,9 @@
 };
 
 A<-1> a(0);
-// expected-error@-1 {{no matching constructor}}
-// expected-note@-2 {{in instantiation of template class}}
+// pre20-error@-1 {{no matching constructor}}
+// pro20-error@-2 {{excess elements in struct initializer}}
+// expected-note@-3 {{in instantiation of template class}}
 
 template
 struct B {
Index: clang/test/SemaCXX/P0960R3.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/P0960R3.cpp
@@ -0,0 +1,76 @@
+// RUN: %clang_cc1 -verify -std=c++20 %s -fsyntax-only
+
+struct A { // expected-note 4{{candidate constructor}}
+  char i;
+  double j;
+};
+
+struct B {
+  A a;
+  int b[20];
+  int & // expected-note {{reference member declared here}}
+};
+
+struct C { // expected-note 2{{candidate constructor}}
+  A a;
+  int b[20];
+};
+
+struct D : public C, public A {
+  int a;
+};
+
+struct E { // expected-note 3{{candidate constructor}}
+  struct F {
+F(int, int);
+  };
+  int a;
+  F f;
+};
+
+union U {
+  int a;
+  char* b;
+};
+
+void foo() {
+  A a(1954, 9, 21);
+  // expected-error@-1 {{excess elements in struct initializer}}
+  A b(2.1);
+  // expected-warning@-1 {{implicit conversion from 'double' to 'char'}}
+  A e(-1.2, 9.8);
+  // expected-warning@-1 {{implicit conversion from 'double' to 'char'}}
+  A s = static_cast(1.1);
+  // expected-warning@-1 {{implicit conversion from 'double' to 'char'}}
+  A h = (A)3.1;
+  // expected-warning@-1 {{implicit conversion from 'double' to 'char'}}
+  A i = A(8.7);
+  // expected-warning@-1 {{implicit conversion from 'double' to 'char'}}
+
+  B n(2022, {7, 8});
+  // expected-error@-1 {{no viable conversion from 'int' to 'A'}}
+  B z(A(1), {}, 1);
+  // expected-error@-1 {{reference member 'c' binds to a temporary object whose lifetime would be shorter than the lifetime of the constructed object}}
+
+  C o(A(1), 1, 2, 3, 4);
+  // expected-error@-1 {{excess elements in struct initializer}}
+  D R(1);
+  // expected-error@-1 {{no viable conversion from 'int' to 'C'}}
+  D I(C(1));
+  // expected-error@-1 {{functional-style cast from 'int' to 'C' is not allowed}}
+  D P(C(A(1)), 1);
+  // expected-error@-1 {{no viable conversion from 'int' to 'A'}}
+
+  int arr1[](0, 1, 2, A(1));
+  // expected-error@-1 {{no viable conversion from 'A' to 'int'}}
+  int arr2[2](0, 1, 2);
+  // expected-error@-1 {{excess elements in array initializer}}
+
+  U u1("abcd");
+  // expected-error@-1 {{cannot initialize a member subobject of type 'int' with an lvalue of type 'const char[5]'}}
+  U u2(1, "efgh");
+  // expected-error@-1 {{excess elements in union initializer}}
+
+  E e1(1);
+  // expected-error@-1 {{no matching constructor for initialization of 'E'}}
+}
Index: clang/test/CodeGen/P0960R3.cpp

[PATCH] D135389: [Clang] Emit a warning for ambiguous joined '-o' arguments

2022-10-06 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

This breaks tests on windows: http://45.33.8.238/win/67644/step_7.txt

Please take a look and revert for now if it takes a while to fix.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135389

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


[PATCH] D135361: [clang][Interp] Implement bitwise Or operations

2022-10-06 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik accepted this revision.
shafik added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135361

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


[clang] b924c8c - [clang][LTO] Remove the use of `--` for arange option

2022-10-06 Thread Qiongsi Wu via cfe-commits

Author: Qiongsi Wu
Date: 2022-10-06T20:27:55-04:00
New Revision: b924c8c71daaa1bb869c42d9afca2a09a9b94629

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

LOG: [clang][LTO] Remove the use of `--` for arange option

https://reviews.llvm.org/D134668 removed all `--` (double dashes) when using 
`plugin-opt` to pass linker options and replaced them with `-`. 
https://reviews.llvm.org/D133092 was committed later but introduced an instance 
of `--`. This patch replaces the `--` with `-`.

Reviewed By: MaskRay

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

Added: 


Modified: 
clang/lib/Driver/ToolChains/CommonArgs.cpp
clang/test/Driver/debug-options-aranges.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 7f20122722365..7d4efaa88405d 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -514,7 +514,7 @@ void tools::addLTOOptions(const ToolChain , const 
ArgList ,
   // the way out.
   if (Args.hasArg(options::OPT_gdwarf_aranges)) {
 CmdArgs.push_back(
-Args.MakeArgString("--plugin-opt=-generate-arange-section"));
+Args.MakeArgString("-plugin-opt=-generate-arange-section"));
   }
 
   // Try to pass driver level flags relevant to LTO code generation down to

diff  --git a/clang/test/Driver/debug-options-aranges.c 
b/clang/test/Driver/debug-options-aranges.c
index 4dc098b7d185c..984f0e2411775 100644
--- a/clang/test/Driver/debug-options-aranges.c
+++ b/clang/test/Driver/debug-options-aranges.c
@@ -3,4 +3,4 @@
 /// Check that the linker plugin will get -generate-arange-section.
 // RUN: %clang -### -g --target=x86_64-linux -flto  -gdwarf-aranges %s 
2>&1 | FileCheck %s
 // RUN: %clang -### -g --target=x86_64-linux -flto=thin -gdwarf-aranges %s 
2>&1 | FileCheck %s
-// CHECK: --plugin-opt=-generate-arange-section
+// CHECK: "-plugin-opt=-generate-arange-section"



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


[PATCH] D135400: [clang][LTO] Remove the use of `--` for arange option

2022-10-06 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGb924c8c71daa: [clang][LTO] Remove the use of `--` for arange 
option (authored by Qiongsi Wu qiongs...@gmail.com).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135400

Files:
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/test/Driver/debug-options-aranges.c


Index: clang/test/Driver/debug-options-aranges.c
===
--- clang/test/Driver/debug-options-aranges.c
+++ clang/test/Driver/debug-options-aranges.c
@@ -3,4 +3,4 @@
 /// Check that the linker plugin will get -generate-arange-section.
 // RUN: %clang -### -g --target=x86_64-linux -flto  -gdwarf-aranges %s 
2>&1 | FileCheck %s
 // RUN: %clang -### -g --target=x86_64-linux -flto=thin -gdwarf-aranges %s 
2>&1 | FileCheck %s
-// CHECK: --plugin-opt=-generate-arange-section
+// CHECK: "-plugin-opt=-generate-arange-section"
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -514,7 +514,7 @@
   // the way out.
   if (Args.hasArg(options::OPT_gdwarf_aranges)) {
 CmdArgs.push_back(
-Args.MakeArgString("--plugin-opt=-generate-arange-section"));
+Args.MakeArgString("-plugin-opt=-generate-arange-section"));
   }
 
   // Try to pass driver level flags relevant to LTO code generation down to


Index: clang/test/Driver/debug-options-aranges.c
===
--- clang/test/Driver/debug-options-aranges.c
+++ clang/test/Driver/debug-options-aranges.c
@@ -3,4 +3,4 @@
 /// Check that the linker plugin will get -generate-arange-section.
 // RUN: %clang -### -g --target=x86_64-linux -flto  -gdwarf-aranges %s 2>&1 | FileCheck %s
 // RUN: %clang -### -g --target=x86_64-linux -flto=thin -gdwarf-aranges %s 2>&1 | FileCheck %s
-// CHECK: --plugin-opt=-generate-arange-section
+// CHECK: "-plugin-opt=-generate-arange-section"
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -514,7 +514,7 @@
   // the way out.
   if (Args.hasArg(options::OPT_gdwarf_aranges)) {
 CmdArgs.push_back(
-Args.MakeArgString("--plugin-opt=-generate-arange-section"));
+Args.MakeArgString("-plugin-opt=-generate-arange-section"));
   }
 
   // Try to pass driver level flags relevant to LTO code generation down to
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D129755: Thread safety analysis: Support copy-elided production of scoped capabilities through arbitrary calls

2022-10-06 Thread NAKAMURA Takumi via Phabricator via cfe-commits
chapuni added inline comments.



Comment at: clang/lib/Analysis/ThreadSafety.cpp:1789
+  auto inserted = ConstructedObjects.insert({Exp, Placeholder.first});
+  assert(inserted.second && "Are we visiting the same expression again?");
+  if (isa(Exp))

'inserted' is used only here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129755

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


[PATCH] D135091: Create storage for the `_cmd` argument to the helper function for generated getters/setters of `direct` Objective-C properties.

2022-10-06 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak accepted this revision.
ahatanak added a comment.

LGTM




Comment at: clang/test/CodeGenObjC/direct-method.m:178
+// CHECK-NEXT: [[IVAR:%.*]] = load {{.*}} @"OBJC_IVAR_$_Root._objectProperty",
+// CHECK-NEXT: call i8* @objc_getProperty(i8* noundef [[SELF]], i8* noundef 
undef, i64 noundef [[IVAR]], {{.*}})
+

`noundef` means the value isn't undefined, right? Is it safe to use it with 
`undef`? We might want to fix this if it isn't.


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

https://reviews.llvm.org/D135091

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


[PATCH] D135411: Add generic KCFI operand bundle lowering

2022-10-06 Thread Sami Tolvanen via Phabricator via cfe-commits
samitolvanen added a comment.

In D135411#3841693 , @kees wrote:

> What's the best way to test this in the kernel? I assume add 
> `ARCH_SUPPORTS_CFI_CLANG` to an arch, and see what blows up? :)

Yes, I think that's the best way.

> Have you tried this on any other arch yet?

The generic lowering pass is not ideal for kernel use as-is, because it doesn't 
generate a consistent machine instruction sequence, which makes error handling 
more difficult. The primary target audience here is firmware running on less 
common architectures.

That being said, I did compile a 64-bit MIPS kernel using this pass, but I 
didn't try booting it. I would expect to run into quite a few issues initially.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135411

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


[PATCH] D135370: Narrow inline namespace filtration for unqualified friend declarations

2022-10-06 Thread Bruno Cardoso Lopes via Phabricator via cfe-commits
bruno added subscribers: aaron.ballman, bruno.
bruno added a reviewer: aaron.ballman.
bruno accepted this revision.
bruno added a comment.
This revision is now accepted and ready to land.

Hi Troy, thanks for working on this, nice compile time perf savings. Can you 
update the diff to contain more context? If anything, `-U 99` or similar 
would do the job.

@aaron.ballman wdyt?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135370

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


[PATCH] D133586: [clang] initialize type qualifiers for FunctionNoProtoType

2022-10-06 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai added a comment.

In D133586#3833274 , @aaron.ballman 
wrote:

> Personally, I think the next step is to add a local `assert()` to this 
> function to try to find out why we're calling this on functions without a 
> prototype and fix up the call sites. I think the intent is that you should 
> not be calling this function on an unprototyped function and it'd be good for 
> debug builds to yell if we're doing that, but returning a default constructed 
> object is a safe recovery for release builds.

The problem with that approach is it won't work with the unit test we have. 
When we have more ODR hashing in C, we can replace the unit test with the one 
in D104963  but I wasn't able to make that 
one fail reliably (no MSAN on macOS), so not sure it is a sufficient testing.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133586

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


[PATCH] D135238: [clang] adds copy-constructible type-trait builtins

2022-10-06 Thread Christopher Di Bella via Phabricator via cfe-commits
cjdb added inline comments.



Comment at: clang/include/clang/Basic/TokenKinds.def:528
+TYPE_TRAIT_1(__is_nothrow_copy_constructible, IsNothrowCopyConstructible, 
KEYCXX)
+TYPE_TRAIT_1(__is_trivially_copy_constructible, IsTriviallyCopyConstructible, 
KEYCXX)
 TYPE_TRAIT_2(__reference_binds_to_temporary, ReferenceBindsToTemporary, KEYCXX)

jwakely wrote:
> cjdb wrote:
> > ldionne wrote:
> > > cjdb wrote:
> > > > erichkeane wrote:
> > > > > royjacobson wrote:
> > > > > > erichkeane wrote:
> > > > > > > cjdb wrote:
> > > > > > > > erichkeane wrote:
> > > > > > > > > So this one is a whole 'thing'.  The Clang definition of 
> > > > > > > > > 'trivially copy constructible' is a few DRs behind.  We 
> > > > > > > > > should probably discuss this with libcxx to make sure use of 
> > > > > > > > > this wouldn't be broken.
> > > > > > > > I'd prefer to get those DRs in before finalising D135238 and 
> > > > > > > > subsequent ones. Do you know the DR numbers I should be looking 
> > > > > > > > at, or should I just poke npaperbot?
> > > > > > > Not off the top of my head, Aaron and I both poked at it at one 
> > > > > > > point trying to get trivially constructible right at one point, 
> > > > > > > but I think we both gave up due to the ABI/versioning concerns.
> > > > > > Maybe DR1734? Although it's about the trivially copyable trait, not 
> > > > > > trivially copy constructible. 
> > > > > > 
> > > > > Yeah, I think that was the DR, that number sounds familiar.
> > > > The `__is_trivially_*` traits were, in part, what inspired the Great 
> > > > Split of D116208. I could remove them for now and revisit once I rip my 
> > > > hair out over these DRs, if that would substantially improve the 
> > > > chances of these commits landing (other commentary notwithstanding).
> > > I am not sure I see a problem with the "triviality" part of this -- we 
> > > already use a compiler builtin for `std::is_trivially_constructible`, so 
> > > I would expect either this patch is fine, or we already have a latent bug 
> > > in libc++.
> > > 
> > > I think I can echo @philnik's comment about this not necessarily 
> > > providing the biggest benefit since our implementation of 
> > > `std::is_trivially_copy_constructible` is a fairly trivial wrapper on top 
> > > of `__is_trivially_constructible`, but I wouldn't object to the patch on 
> > > that basis. I think it would probably be possible to instead provide a 
> > > set of basis builtin operations that we can then build all of the library 
> > > type traits on top of -- that would provide the highest bang-for-our-buck 
> > > ratio.
> > > 
> > > At the same time, there's something kind of enticing in the consistency 
> > > of defining every single type trait as a builtin, without exception. If 
> > > that's the end goal, I think that would also be neat and we'd likely 
> > > regroup all of our type traits under a single header, since each of them 
> > > would literally be a one liner.
> > > 
> > > There's also the question of whether GCC provides these builtins -- if 
> > > they don't and if they don't have plans to, then we'd actually need to 
> > > add complexity in libc++ to support both, which we would be unlikely to 
> > > do given that there's probably not a huge compile-time performance 
> > > benefit.
> > > 
> > > TLDR, I think the two questions that can help gauge how much interest 
> > > there will be from libc++ to use this are:
> > > 
> > > 1. Is the plan to provide *all* the type traits as builtins?
> > > 2. Will GCC implement them?
> > > 
> > > That being said, libc++ might not be the only potential user of these 
> > > builtins, so I wouldn't necessarily make it a hard requirement to satisfy 
> > > us.
> > > 
> > > I think I can echo @philnik's comment about this not necessarily 
> > > providing the biggest benefit since our implementation of 
> > > `std::is_trivially_copy_constructible` is a fairly trivial wrapper on top 
> > > of `__is_trivially_constructible`, but I wouldn't object to the patch on 
> > > that basis.
> > 
> > I haven't had time to do anything properly in the way of benchmarking, but 
> > after looking at @philnik's quoted code, I see that I'd naively addressed 
> > `__is_constructible(T, T const&)`, forgetting that `__add_lvalue_reference` 
> > would've fixed that issue.
> > 
> > > 1. Is the plan to provide *all* the type traits as builtins?
> > 
> > Yes, with the possible exception of `enable_if` and `add_const` etc. (see 
> > D116203 for why the qualifier ones aren't already in). The hardest ones 
> > will probably be `common_type`, `common_reference`, `*invocable*`, and 
> > `*swappable*`. The former two depend on technology that doesn't exist in 
> > Clang yet, and the latter two are likely hard due there not being prior art.
> > 
> > > 2. Will GCC implement them?
> > 
> > @jwakely do you know if there can be cross-compiler synergy here?
> > 
> > 
> Which traits are you asking about, just the 
> 

[PATCH] D135416: [clang][deps] Respect VFS overlays in canonical preprocessing mode

2022-10-06 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 updated this revision to Diff 465936.
jansvoboda11 added a comment.

Add forgotten hunk.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135416

Files:
  clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
  clang/test/ClangScanDeps/vfsoverlay.cpp


Index: clang/test/ClangScanDeps/vfsoverlay.cpp
===
--- clang/test/ClangScanDeps/vfsoverlay.cpp
+++ clang/test/ClangScanDeps/vfsoverlay.cpp
@@ -8,8 +8,8 @@
 // RUN: cp %S/Inputs/header.h %t.dir/Inputs/header.h
 // RUN: sed -e "s|DIR|%/t.dir|g" %S/Inputs/vfsoverlay_cdb.json > %t.cdb
 //
-// RUN: clang-scan-deps -compilation-database %t.cdb -j 1 | \
-// RUN:   FileCheck %s
+// RUN: clang-scan-deps -compilation-database %t.cdb -mode 
preprocess-dependency-directives -j 1 | FileCheck %s
+// RUN: clang-scan-deps -compilation-database %t.cdb -mode preprocess  
 -j 1 | FileCheck %s
 
 #include "not_real.h"
 
Index: clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
===
--- clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
+++ clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
@@ -192,6 +192,11 @@
 ScanInstance.getFrontendOpts().ModulesShareFileManager = false;
 
 ScanInstance.setFileManager(FileMgr);
+// Support for virtual file system overlays.
+FileMgr->setVirtualFileSystem(createVFSFromCompilerInvocation(
+ScanInstance.getInvocation(), ScanInstance.getDiagnostics(),
+FileMgr->getVirtualFileSystemPtr()));
+
 ScanInstance.createSourceManager(*FileMgr);
 
 llvm::StringSet<> PrebuiltModulesInputFiles;
@@ -206,12 +211,6 @@
 
 // Use the dependency scanning optimized file system if requested to do so.
 if (DepFS) {
-  // Support for virtual file system overlays on top of the caching
-  // filesystem.
-  FileMgr->setVirtualFileSystem(createVFSFromCompilerInvocation(
-  ScanInstance.getInvocation(), ScanInstance.getDiagnostics(),
-  FileMgr->getVirtualFileSystemPtr()));
-
   llvm::IntrusiveRefCntPtr LocalDepFS =
   DepFS;
   ScanInstance.getPreprocessorOpts().DependencyDirectivesForFile =


Index: clang/test/ClangScanDeps/vfsoverlay.cpp
===
--- clang/test/ClangScanDeps/vfsoverlay.cpp
+++ clang/test/ClangScanDeps/vfsoverlay.cpp
@@ -8,8 +8,8 @@
 // RUN: cp %S/Inputs/header.h %t.dir/Inputs/header.h
 // RUN: sed -e "s|DIR|%/t.dir|g" %S/Inputs/vfsoverlay_cdb.json > %t.cdb
 //
-// RUN: clang-scan-deps -compilation-database %t.cdb -j 1 | \
-// RUN:   FileCheck %s
+// RUN: clang-scan-deps -compilation-database %t.cdb -mode preprocess-dependency-directives -j 1 | FileCheck %s
+// RUN: clang-scan-deps -compilation-database %t.cdb -mode preprocess   -j 1 | FileCheck %s
 
 #include "not_real.h"
 
Index: clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
===
--- clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
+++ clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
@@ -192,6 +192,11 @@
 ScanInstance.getFrontendOpts().ModulesShareFileManager = false;
 
 ScanInstance.setFileManager(FileMgr);
+// Support for virtual file system overlays.
+FileMgr->setVirtualFileSystem(createVFSFromCompilerInvocation(
+ScanInstance.getInvocation(), ScanInstance.getDiagnostics(),
+FileMgr->getVirtualFileSystemPtr()));
+
 ScanInstance.createSourceManager(*FileMgr);
 
 llvm::StringSet<> PrebuiltModulesInputFiles;
@@ -206,12 +211,6 @@
 
 // Use the dependency scanning optimized file system if requested to do so.
 if (DepFS) {
-  // Support for virtual file system overlays on top of the caching
-  // filesystem.
-  FileMgr->setVirtualFileSystem(createVFSFromCompilerInvocation(
-  ScanInstance.getInvocation(), ScanInstance.getDiagnostics(),
-  FileMgr->getVirtualFileSystemPtr()));
-
   llvm::IntrusiveRefCntPtr LocalDepFS =
   DepFS;
   ScanInstance.getPreprocessorOpts().DependencyDirectivesForFile =
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D135416: [clang][deps] Respect VFS overlays in canonical preprocessing mode

2022-10-06 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 created this revision.
jansvoboda11 added reviewers: Bigcheese, benlangmuir.
Herald added a subscriber: ributzka.
Herald added a project: All.
jansvoboda11 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

The `-ivfsoverlay` flag was only being respected when the scanner was 
instructed to minimize the inputs. This patch respects that flag even in 
canonical preprocessing mode.

Depends on D135414 .


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D135416

Files:
  clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
  clang/test/ClangScanDeps/vfsoverlay.cpp


Index: clang/test/ClangScanDeps/vfsoverlay.cpp
===
--- clang/test/ClangScanDeps/vfsoverlay.cpp
+++ clang/test/ClangScanDeps/vfsoverlay.cpp
@@ -8,8 +8,8 @@
 // RUN: cp %S/Inputs/header.h %t.dir/Inputs/header.h
 // RUN: sed -e "s|DIR|%/t.dir|g" %S/Inputs/vfsoverlay_cdb.json > %t.cdb
 //
-// RUN: clang-scan-deps -compilation-database %t.cdb -j 1 | \
-// RUN:   FileCheck %s
+// RUN: clang-scan-deps -compilation-database %t.cdb -mode 
preprocess-dependency-directives -j 1 | FileCheck %s
+// RUN: clang-scan-deps -compilation-database %t.cdb -mode preprocess  
 -j 1 | FileCheck %s
 
 #include "not_real.h"
 
Index: clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
===
--- clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
+++ clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
@@ -192,6 +192,11 @@
 ScanInstance.getFrontendOpts().ModulesShareFileManager = false;
 
 ScanInstance.setFileManager(FileMgr);
+// Support for virtual file system overlays.
+FileMgr->setVirtualFileSystem(createVFSFromCompilerInvocation(
+ScanInstance.getInvocation(), ScanInstance.getDiagnostics(),
+FileMgr->getVirtualFileSystemPtr()));
+
 ScanInstance.createSourceManager(*FileMgr);
 
 llvm::StringSet<> PrebuiltModulesInputFiles;


Index: clang/test/ClangScanDeps/vfsoverlay.cpp
===
--- clang/test/ClangScanDeps/vfsoverlay.cpp
+++ clang/test/ClangScanDeps/vfsoverlay.cpp
@@ -8,8 +8,8 @@
 // RUN: cp %S/Inputs/header.h %t.dir/Inputs/header.h
 // RUN: sed -e "s|DIR|%/t.dir|g" %S/Inputs/vfsoverlay_cdb.json > %t.cdb
 //
-// RUN: clang-scan-deps -compilation-database %t.cdb -j 1 | \
-// RUN:   FileCheck %s
+// RUN: clang-scan-deps -compilation-database %t.cdb -mode preprocess-dependency-directives -j 1 | FileCheck %s
+// RUN: clang-scan-deps -compilation-database %t.cdb -mode preprocess   -j 1 | FileCheck %s
 
 #include "not_real.h"
 
Index: clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
===
--- clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
+++ clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
@@ -192,6 +192,11 @@
 ScanInstance.getFrontendOpts().ModulesShareFileManager = false;
 
 ScanInstance.setFileManager(FileMgr);
+// Support for virtual file system overlays.
+FileMgr->setVirtualFileSystem(createVFSFromCompilerInvocation(
+ScanInstance.getInvocation(), ScanInstance.getDiagnostics(),
+FileMgr->getVirtualFileSystemPtr()));
+
 ScanInstance.createSourceManager(*FileMgr);
 
 llvm::StringSet<> PrebuiltModulesInputFiles;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D135414: [clang][deps] Don't share in-memory VFS across scans

2022-10-06 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 created this revision.
jansvoboda11 added reviewers: Bigcheese, benlangmuir.
Herald added a subscriber: ributzka.
Herald added a project: All.
jansvoboda11 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

The dependency scanning worker may create an in-memory VFS and inject that into 
its `FileManager`. (Implemented in D109485 .) 
This VFS currently persists between scans, which is not correct: in-memory 
files created in one scan could affect subsequent scans. This patch changes 
things so that the in-memory VFS is local to 
`DependencyScanningWorker::computeDependencies()`.

To test this, one would first scan for dependencies of a named module and then 
run second scan (on the same worker) for something unrelated, which would pick 
up the in-memory file created in the first scan. This set up is impossible to 
achieve with `clang-scan-deps`. We could set this up in `ToolingTests`, but the 
scanner needs to access the physical filesystem to store `.pcm` files. AFAIK we 
don't have a good way to propagate something like `%t` into unit tests to make 
that feasible. (This could be achieved with something like the virtualized 
`OutputManager`.)


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D135414

Files:
  clang/include/clang/Basic/FileManager.h
  clang/include/clang/Tooling/DependencyScanning/DependencyScanningWorker.h
  clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp

Index: clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
===
--- clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
+++ clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
@@ -209,7 +209,8 @@
   // Support for virtual file system overlays on top of the caching
   // filesystem.
   FileMgr->setVirtualFileSystem(createVFSFromCompilerInvocation(
-  ScanInstance.getInvocation(), ScanInstance.getDiagnostics(), DepFS));
+  ScanInstance.getInvocation(), ScanInstance.getDiagnostics(),
+  FileMgr->getVirtualFileSystemPtr()));
 
   llvm::IntrusiveRefCntPtr LocalDepFS =
   DepFS;
@@ -324,15 +325,17 @@
   PCHContainerOps->registerWriter(
   std::make_unique());
 
-  auto OverlayFS =
-  llvm::makeIntrusiveRefCnt(std::move(FS));
-  InMemoryFS = llvm::makeIntrusiveRefCnt();
-  OverlayFS->pushOverlay(InMemoryFS);
-  RealFS = OverlayFS;
-
-  if (Service.getMode() == ScanningMode::DependencyDirectivesScan)
-DepFS = new DependencyScanningWorkerFilesystem(Service.getSharedCache(),
-   RealFS);
+  switch (Service.getMode()) {
+  case ScanningMode::DependencyDirectivesScan:
+DepFS =
+new DependencyScanningWorkerFilesystem(Service.getSharedCache(), FS);
+BaseFS = DepFS;
+break;
+  case ScanningMode::CanonicalPreprocessing:
+DepFS = nullptr;
+BaseFS = FS;
+break;
+  }
 }
 
 llvm::Error DependencyScanningWorker::computeDependencies(
@@ -386,22 +389,32 @@
 DependencyConsumer , DiagnosticConsumer ,
 llvm::Optional ModuleName) {
   // Reset what might have been modified in the previous worker invocation.
-  RealFS->setCurrentWorkingDirectory(WorkingDirectory);
-
-  FileSystemOptions FSOpts;
-  FSOpts.WorkingDir = WorkingDirectory.str();
-  auto FileMgr = llvm::makeIntrusiveRefCnt(FSOpts, RealFS);
+  BaseFS->setCurrentWorkingDirectory(WorkingDirectory);
 
   Optional> ModifiedCommandLine;
+  llvm::IntrusiveRefCntPtr ModifiedFS;
   if (ModuleName) {
 ModifiedCommandLine = CommandLine;
-InMemoryFS->addFile(*ModuleName, 0, llvm::MemoryBuffer::getMemBuffer(""));
 ModifiedCommandLine->emplace_back(*ModuleName);
+
+auto OverlayFS = llvm::makeIntrusiveRefCnt(
+std::move(BaseFS));
+auto InMemoryFS =
+llvm::makeIntrusiveRefCnt();
+InMemoryFS->setCurrentWorkingDirectory(WorkingDirectory);
+InMemoryFS->addFile(*ModuleName, 0, llvm::MemoryBuffer::getMemBuffer(""));
+OverlayFS->pushOverlay(InMemoryFS);
+ModifiedFS = OverlayFS;
   }
 
   const std::vector  =
   ModifiedCommandLine ? *ModifiedCommandLine : CommandLine;
 
+  FileSystemOptions FSOpts;
+  FSOpts.WorkingDir = WorkingDirectory.str();
+  auto FileMgr = llvm::makeIntrusiveRefCnt(
+  FSOpts, ModifiedFS ? ModifiedFS : BaseFS);
+
   std::vector FinalCCommandLine(CommandLine.size(), nullptr);
   llvm::transform(CommandLine, FinalCCommandLine.begin(),
   [](const std::string ) { return Str.c_str(); });
Index: clang/include/clang/Tooling/DependencyScanning/DependencyScanningWorker.h
===
--- clang/include/clang/Tooling/DependencyScanning/DependencyScanningWorker.h
+++ clang/include/clang/Tooling/DependencyScanning/DependencyScanningWorker.h
@@ -91,14 +91,13 @@
 
 private:
   std::shared_ptr 

[PATCH] D129531: [clang][C++20] P0960R3: Allow initializing aggregates from a parenthesized list of values

2022-10-06 Thread Alan Zhao via Phabricator via cfe-commits
ayzhao updated this revision to Diff 465927.
ayzhao added a comment.

implement StmtPrinter::VisitCXXParenListInitExpr(...)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129531

Files:
  clang/include/clang/AST/Decl.h
  clang/include/clang/AST/ExprCXX.h
  clang/include/clang/AST/RecursiveASTVisitor.h
  clang/include/clang/Basic/StmtNodes.td
  clang/include/clang/Sema/Initialization.h
  clang/lib/AST/Expr.cpp
  clang/lib/AST/ExprCXX.cpp
  clang/lib/AST/ExprClassification.cpp
  clang/lib/AST/ExprConstant.cpp
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/JSONNodeDumper.cpp
  clang/lib/AST/StmtPrinter.cpp
  clang/lib/AST/StmtProfile.cpp
  clang/lib/AST/TextNodeDumper.cpp
  clang/lib/CodeGen/CGExprAgg.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaExceptionSpec.cpp
  clang/lib/Sema/SemaInit.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTReaderStmt.cpp
  clang/lib/Serialization/ASTWriterStmt.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
  clang/test/CXX/class/class.compare/class.spaceship/p1.cpp
  clang/test/CXX/drs/dr2xx.cpp
  clang/test/CXX/temp/temp.decls/temp.variadic/p4.cpp
  clang/test/CodeGen/P0960R3.cpp
  clang/test/SemaCXX/P0960R3.cpp
  clang/test/SemaCXX/cxx2a-explicit-bool.cpp

Index: clang/test/SemaCXX/cxx2a-explicit-bool.cpp
===
--- clang/test/SemaCXX/cxx2a-explicit-bool.cpp
+++ clang/test/SemaCXX/cxx2a-explicit-bool.cpp
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -std=c++17 -fsyntax-only %s -verify -Wno-c++2a-extensions
-// RUN: %clang_cc1 -std=c++2a -fsyntax-only %s -verify
+// RUN: %clang_cc1 -std=c++17 -fsyntax-only %s -verify=expected,pre20 -Wno-c++2a-extensions
+// RUN: %clang_cc1 -std=c++2a -fsyntax-only %s -verify=expected,pro20
 
 template  struct enable_ifv {};
 
@@ -20,7 +20,7 @@
 
 template
 struct A {
-// expected-note@-1+ {{candidate constructor}}
+// pre20-note@-1+ {{candidate constructor}}
   explicit(1 << a)
 // expected-note@-1 {{negative shift count -1}}
 // expected-error@-2 {{explicit specifier argument is not a constant expression}}
@@ -28,8 +28,9 @@
 };
 
 A<-1> a(0);
-// expected-error@-1 {{no matching constructor}}
-// expected-note@-2 {{in instantiation of template class}}
+// pre20-error@-1 {{no matching constructor}}
+// pro20-error@-2 {{excess elements in struct initializer}}
+// expected-note@-3 {{in instantiation of template class}}
 
 template
 struct B {
Index: clang/test/SemaCXX/P0960R3.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/P0960R3.cpp
@@ -0,0 +1,76 @@
+// RUN: %clang_cc1 -verify -std=c++20 %s -fsyntax-only
+
+struct A { // expected-note 4{{candidate constructor}}
+  char i;
+  double j;
+};
+
+struct B {
+  A a;
+  int b[20];
+  int & // expected-note {{reference member declared here}}
+};
+
+struct C { // expected-note 2{{candidate constructor}}
+  A a;
+  int b[20];
+};
+
+struct D : public C, public A {
+  int a;
+};
+
+struct E { // expected-note 3{{candidate constructor}}
+  struct F {
+F(int, int);
+  };
+  int a;
+  F f;
+};
+
+union U {
+  int a;
+  char* b;
+};
+
+void foo() {
+  A a(1954, 9, 21);
+  // expected-error@-1 {{excess elements in struct initializer}}
+  A b(2.1);
+  // expected-warning@-1 {{implicit conversion from 'double' to 'char'}}
+  A e(-1.2, 9.8);
+  // expected-warning@-1 {{implicit conversion from 'double' to 'char'}}
+  A s = static_cast(1.1);
+  // expected-warning@-1 {{implicit conversion from 'double' to 'char'}}
+  A h = (A)3.1;
+  // expected-warning@-1 {{implicit conversion from 'double' to 'char'}}
+  A i = A(8.7);
+  // expected-warning@-1 {{implicit conversion from 'double' to 'char'}}
+
+  B n(2022, {7, 8});
+  // expected-error@-1 {{no viable conversion from 'int' to 'A'}}
+  B z(A(1), {}, 1);
+  // expected-error@-1 {{reference member 'c' binds to a temporary object whose lifetime would be shorter than the lifetime of the constructed object}}
+
+  C o(A(1), 1, 2, 3, 4);
+  // expected-error@-1 {{excess elements in struct initializer}}
+  D R(1);
+  // expected-error@-1 {{no viable conversion from 'int' to 'C'}}
+  D I(C(1));
+  // expected-error@-1 {{functional-style cast from 'int' to 'C' is not allowed}}
+  D P(C(A(1)), 1);
+  // expected-error@-1 {{no viable conversion from 'int' to 'A'}}
+
+  int arr1[](0, 1, 2, A(1));
+  // expected-error@-1 {{no viable conversion from 'A' to 'int'}}
+  int arr2[2](0, 1, 2);
+  // expected-error@-1 {{excess elements in array initializer}}
+
+  U u1("abcd");
+  // expected-error@-1 {{cannot initialize a member subobject of type 'int' with an lvalue of type 'const char[5]'}}
+  U u2(1, "efgh");
+  // expected-error@-1 {{excess elements in union initializer}}
+
+  E e1(1);
+  // expected-error@-1 {{no matching constructor for initialization of 'E'}}
+}
Index: clang/test/CodeGen/P0960R3.cpp

[PATCH] D135091: Create storage for the `_cmd` argument to the helper function for generated getters/setters of `direct` Objective-C properties.

2022-10-06 Thread Michael Wyman via Phabricator via cfe-commits
mwyman marked 2 inline comments as done.
mwyman added inline comments.



Comment at: clang/lib/CodeGen/CGObjC.cpp:1116
+// for the `_cmd` argument that no longer exists for direct methods.
+static llvm::Value *emitCmdLoadForGetterSetterBody(CodeGenFunction ,
+   ObjCMethodDecl *MD) {

ahatanak wrote:
> Since this is loading from an uninitialized alloca, can we just pass an 
> `undef` to the call to `objc_get/setProperty`? The optimization passes will 
> just do that, but we can still reduce the code size at `-O0`.
Great suggestion! Done.


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

https://reviews.llvm.org/D135091

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


[PATCH] D135091: Create storage for the `_cmd` argument to the helper function for generated getters/setters of `direct` Objective-C properties.

2022-10-06 Thread Michael Wyman via Phabricator via cfe-commits
mwyman updated this revision to Diff 465925.
mwyman added a comment.
Herald added a subscriber: nlopes.

Use explicit `undef` for the `cmd` parameter to 
`objc_getProperty`/`objc_setProperty` rather declaring and not initializing 
storage for the implicit `_cmd`.


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

https://reviews.llvm.org/D135091

Files:
  clang/lib/CodeGen/CGObjC.cpp
  clang/test/CodeGenObjC/direct-method.m


Index: clang/test/CodeGenObjC/direct-method.m
===
--- clang/test/CodeGenObjC/direct-method.m
+++ clang/test/CodeGenObjC/direct-method.m
@@ -14,6 +14,7 @@
 - (int)getInt __attribute__((objc_direct));
 @property(direct, readonly) int intProperty;
 @property(direct, readonly) int intProperty2;
+@property(direct, readonly) id objectProperty;
 @end
 
 @implementation Root
@@ -167,6 +168,15 @@
 @end
 // CHECK-LABEL: define hidden i32 @"\01-[Root intProperty]"
 
+// Check the synthesized objectProperty calls objc_getProperty(); this also
+// checks that the synthesized method passes undef for the `cmd` argument.
+// CHECK-LABEL: define hidden i8* @"\01-[Root objectProperty]"(
+// CHECK-LABEL: objc_direct_method.cont:
+// CHECK-NEXT: [[SELFVAL:%.*]] = load {{.*}} %self.addr,
+// CHECK-NEXT: [[SELF:%.*]] = bitcast {{.*}} [[SELFVAL]] to i8*
+// CHECK-NEXT: [[IVAR:%.*]] = load {{.*}} @"OBJC_IVAR_$_Root._objectProperty",
+// CHECK-NEXT: call i8* @objc_getProperty(i8* noundef [[SELF]], i8* noundef 
undef, i64 noundef [[IVAR]], {{.*}})
+
 @interface Foo : Root {
   id __strong _cause_cxx_destruct;
 }
Index: clang/lib/CodeGen/CGObjC.cpp
===
--- clang/lib/CodeGen/CGObjC.cpp
+++ clang/lib/CodeGen/CGObjC.cpp
@@ -25,6 +25,7 @@
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/Analysis/ObjCARCUtil.h"
 #include "llvm/BinaryFormat/MachO.h"
+#include "llvm/IR/Constants.h"
 #include "llvm/IR/DataLayout.h"
 #include "llvm/IR/InlineAsm.h"
 using namespace clang;
@@ -,6 +1112,22 @@
callee, ReturnValueSlot(), args);
 }
 
+// emitCmdLoadForGetterSetterBody - Handle emitting local storage declarations
+// for the `_cmd` argument that no longer exists for direct methods.
+static llvm::Value *emitCmdLoadForGetterSetterBody(CodeGenFunction ,
+   ObjCMethodDecl *MD) {
+  if (MD->isDirectMethod()) {
+// Direct methods no longer have a `_cmd` argument, so storage must be
+// emitted for it to be passed to the property helper. Since the `_cmd`
+// argument was never being initialized by the caller before, still pass
+// an uninitialized/undefined value here.
+llvm::Type *selType = CGF.ConvertType(CGF.getContext().getObjCSelType());
+return llvm::UndefValue::get(selType);
+  }
+
+  return CGF.Builder.CreateLoad(CGF.GetAddrOfLocalVar(MD->getCmdDecl()), 
"cmd");
+}
+
 void
 CodeGenFunction::generateObjCGetterBody(const ObjCImplementationDecl 
*classImpl,
 const ObjCPropertyImplDecl *propImpl,
@@ -1189,8 +1206,7 @@
 // Return (ivar-type) objc_getProperty((id) self, _cmd, offset, true).
 // FIXME: Can't this be simpler? This might even be worse than the
 // corresponding gcc code.
-llvm::Value *cmd =
-  Builder.CreateLoad(GetAddrOfLocalVar(getterMethod->getCmdDecl()), "cmd");
+llvm::Value *cmd = emitCmdLoadForGetterSetterBody(*this, getterMethod);
 llvm::Value *self = Builder.CreateBitCast(LoadObjCSelf(), VoidPtrTy);
 llvm::Value *ivarOffset =
   EmitIvarOffset(classImpl->getClassInterface(), ivar);
@@ -1475,8 +1491,7 @@
 
 // Emit objc_setProperty((id) self, _cmd, offset, arg,
 //   , ).
-llvm::Value *cmd =
-  Builder.CreateLoad(GetAddrOfLocalVar(setterMethod->getCmdDecl()));
+llvm::Value *cmd = emitCmdLoadForGetterSetterBody(*this, setterMethod);
 llvm::Value *self =
   Builder.CreateBitCast(LoadObjCSelf(), VoidPtrTy);
 llvm::Value *ivarOffset =


Index: clang/test/CodeGenObjC/direct-method.m
===
--- clang/test/CodeGenObjC/direct-method.m
+++ clang/test/CodeGenObjC/direct-method.m
@@ -14,6 +14,7 @@
 - (int)getInt __attribute__((objc_direct));
 @property(direct, readonly) int intProperty;
 @property(direct, readonly) int intProperty2;
+@property(direct, readonly) id objectProperty;
 @end
 
 @implementation Root
@@ -167,6 +168,15 @@
 @end
 // CHECK-LABEL: define hidden i32 @"\01-[Root intProperty]"
 
+// Check the synthesized objectProperty calls objc_getProperty(); this also
+// checks that the synthesized method passes undef for the `cmd` argument.
+// CHECK-LABEL: define hidden i8* @"\01-[Root objectProperty]"(
+// CHECK-LABEL: objc_direct_method.cont:
+// CHECK-NEXT: [[SELFVAL:%.*]] = load {{.*}} %self.addr,
+// CHECK-NEXT: [[SELF:%.*]] = bitcast {{.*}} [[SELFVAL]] to i8*
+// CHECK-NEXT: [[IVAR:%.*]] 

[clang] 4aa87a1 - [OpenMP][AMDGPU] Add 'uniform-work-group' attribute to OpenMP kernels

2022-10-06 Thread Joseph Huber via cfe-commits

Author: Joseph Huber
Date: 2022-10-06T18:22:09-05:00
New Revision: 4aa87a131f93de73b8e245021af0294545d063c5

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

LOG: [OpenMP][AMDGPU] Add 'uniform-work-group' attribute to OpenMP kernels

The `cl-uniform-work-group` attribute asserts that the global work-size
be a multiple of the work-group specified work group size. This should
allow optimizations. It is already present by default in the AMD
compiler and for HIP kernels so it should be safe to allow this for
OpenMP kernels by default.

Reviewed By: jdoerfert

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

Added: 


Modified: 
clang/lib/CodeGen/TargetInfo.cpp
clang/test/OpenMP/amdgcn-attributes.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/TargetInfo.cpp 
b/clang/lib/CodeGen/TargetInfo.cpp
index 02bcf8a19bbfb..74997f0f9e9dc 100644
--- a/clang/lib/CodeGen/TargetInfo.cpp
+++ b/clang/lib/CodeGen/TargetInfo.cpp
@@ -9423,8 +9423,12 @@ void AMDGPUTargetCodeGenInfo::setTargetAttributes(
 
   const bool IsHIPKernel =
   M.getLangOpts().HIP && FD && FD->hasAttr();
+  const bool IsOpenMPkernel =
+  M.getLangOpts().OpenMPIsDevice &&
+  (F->getCallingConv() == llvm::CallingConv::AMDGPU_KERNEL);
 
-  if (IsHIPKernel)
+  // TODO: This should be moved to language specific attributes instead.
+  if (IsHIPKernel || IsOpenMPkernel)
 F->addFnAttr("uniform-work-group-size", "true");
 
   if (M.getContext().getTargetInfo().allowAMDGPUUnsafeFPAtomics())

diff  --git a/clang/test/OpenMP/amdgcn-attributes.cpp 
b/clang/test/OpenMP/amdgcn-attributes.cpp
index ab11bf765b9bc..506989a8de138 100644
--- a/clang/test/OpenMP/amdgcn-attributes.cpp
+++ b/clang/test/OpenMP/amdgcn-attributes.cpp
@@ -32,10 +32,10 @@ int callable(int x) {
   return x + 1;
 }
 
-  // DEFAULT: attributes #0 = { convergent noinline norecurse nounwind optnone 
"frame-pointer"="none" "kernel" "min-legal-vector-width"="0" 
"no-trapping-math"="true" "stack-protector-buffer-size"="8" }
-  // CPU: attributes #0 = { convergent noinline norecurse nounwind optnone 
"frame-pointer"="none" "kernel" "min-legal-vector-width"="0" 
"no-trapping-math"="true" "stack-protector-buffer-size"="8" 
"target-cpu"="gfx900" 
"target-features"="+16-bit-insts,+ci-insts,+dpp,+flat-address-space,+gfx8-insts,+gfx9-insts,+s-memrealtime,+s-memtime-inst"
 }
-  // NOIEEE: attributes #0 = { convergent noinline norecurse nounwind optnone 
"amdgpu-ieee"="false" "frame-pointer"="none" "kernel" 
"min-legal-vector-width"="0" "no-nans-fp-math"="true" "no-trapping-math"="true" 
"stack-protector-buffer-size"="8" }
-  // UNSAFEATOMIC: attributes #0 = { convergent noinline norecurse nounwind 
optnone "amdgpu-unsafe-fp-atomics"="true" "frame-pointer"="none" "kernel" 
"min-legal-vector-width"="0" "no-trapping-math"="true" 
"stack-protector-buffer-size"="8" }
+// DEFAULT: attributes #0 = { convergent noinline norecurse nounwind optnone 
"frame-pointer"="none" "kernel" "min-legal-vector-width"="0" 
"no-trapping-math"="true" "stack-protector-buffer-size"="8" 
"uniform-work-group-size"="true" }
+// CPU: attributes #0 = { convergent noinline norecurse nounwind optnone 
"frame-pointer"="none" "kernel" "min-legal-vector-width"="0" 
"no-trapping-math"="true" "stack-protector-buffer-size"="8" 
"target-cpu"="gfx900" 
"target-features"="+16-bit-insts,+ci-insts,+dpp,+flat-address-space,+gfx8-insts,+gfx9-insts,+s-memrealtime,+s-memtime-inst"
 "uniform-work-group-size"="true" }
+// NOIEEE: attributes #0 = { convergent noinline norecurse nounwind optnone 
"amdgpu-ieee"="false" "frame-pointer"="none" "kernel" 
"min-legal-vector-width"="0" "no-nans-fp-math"="true" "no-trapping-math"="true" 
"stack-protector-buffer-size"="8" "uniform-work-group-size"="true" }
+// UNSAFEATOMIC: attributes #0 = { convergent noinline norecurse nounwind 
optnone "amdgpu-unsafe-fp-atomics"="true" "frame-pointer"="none" "kernel" 
"min-legal-vector-width"="0" "no-trapping-math"="true" 
"stack-protector-buffer-size"="8" "uniform-work-group-size"="true" }
 
 // DEFAULT: attributes #1 = { convergent mustprogress noinline nounwind 
optnone "frame-pointer"="none" "min-legal-vector-width"="0" 
"no-trapping-math"="true" "stack-protector-buffer-size"="8" }
 // CPU: attributes #1 = { convergent mustprogress noinline nounwind optnone 
"frame-pointer"="none" "min-legal-vector-width"="0" "no-trapping-math"="true" 
"stack-protector-buffer-size"="8" "target-cpu"="gfx900" 
"target-features"="+16-bit-insts,+ci-insts,+dpp,+flat-address-space,+gfx8-insts,+gfx9-insts,+s-memrealtime,+s-memtime-inst"
 }



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


[PATCH] D135374: [OpenMP][AMDGPU] Add 'uniform-work-group' attribute to OpenMP kernels

2022-10-06 Thread Joseph Huber via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG4aa87a131f93: [OpenMP][AMDGPU] Add 
uniform-work-group attribute to OpenMP kernels (authored by 
jhuber6).

Changed prior to commit:
  https://reviews.llvm.org/D135374?vs=465769=465923#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135374

Files:
  clang/lib/CodeGen/TargetInfo.cpp
  clang/test/OpenMP/amdgcn-attributes.cpp


Index: clang/test/OpenMP/amdgcn-attributes.cpp
===
--- clang/test/OpenMP/amdgcn-attributes.cpp
+++ clang/test/OpenMP/amdgcn-attributes.cpp
@@ -32,10 +32,10 @@
   return x + 1;
 }
 
-  // DEFAULT: attributes #0 = { convergent noinline norecurse nounwind optnone 
"frame-pointer"="none" "kernel" "min-legal-vector-width"="0" 
"no-trapping-math"="true" "stack-protector-buffer-size"="8" }
-  // CPU: attributes #0 = { convergent noinline norecurse nounwind optnone 
"frame-pointer"="none" "kernel" "min-legal-vector-width"="0" 
"no-trapping-math"="true" "stack-protector-buffer-size"="8" 
"target-cpu"="gfx900" 
"target-features"="+16-bit-insts,+ci-insts,+dpp,+flat-address-space,+gfx8-insts,+gfx9-insts,+s-memrealtime,+s-memtime-inst"
 }
-  // NOIEEE: attributes #0 = { convergent noinline norecurse nounwind optnone 
"amdgpu-ieee"="false" "frame-pointer"="none" "kernel" 
"min-legal-vector-width"="0" "no-nans-fp-math"="true" "no-trapping-math"="true" 
"stack-protector-buffer-size"="8" }
-  // UNSAFEATOMIC: attributes #0 = { convergent noinline norecurse nounwind 
optnone "amdgpu-unsafe-fp-atomics"="true" "frame-pointer"="none" "kernel" 
"min-legal-vector-width"="0" "no-trapping-math"="true" 
"stack-protector-buffer-size"="8" }
+// DEFAULT: attributes #0 = { convergent noinline norecurse nounwind optnone 
"frame-pointer"="none" "kernel" "min-legal-vector-width"="0" 
"no-trapping-math"="true" "stack-protector-buffer-size"="8" 
"uniform-work-group-size"="true" }
+// CPU: attributes #0 = { convergent noinline norecurse nounwind optnone 
"frame-pointer"="none" "kernel" "min-legal-vector-width"="0" 
"no-trapping-math"="true" "stack-protector-buffer-size"="8" 
"target-cpu"="gfx900" 
"target-features"="+16-bit-insts,+ci-insts,+dpp,+flat-address-space,+gfx8-insts,+gfx9-insts,+s-memrealtime,+s-memtime-inst"
 "uniform-work-group-size"="true" }
+// NOIEEE: attributes #0 = { convergent noinline norecurse nounwind optnone 
"amdgpu-ieee"="false" "frame-pointer"="none" "kernel" 
"min-legal-vector-width"="0" "no-nans-fp-math"="true" "no-trapping-math"="true" 
"stack-protector-buffer-size"="8" "uniform-work-group-size"="true" }
+// UNSAFEATOMIC: attributes #0 = { convergent noinline norecurse nounwind 
optnone "amdgpu-unsafe-fp-atomics"="true" "frame-pointer"="none" "kernel" 
"min-legal-vector-width"="0" "no-trapping-math"="true" 
"stack-protector-buffer-size"="8" "uniform-work-group-size"="true" }
 
 // DEFAULT: attributes #1 = { convergent mustprogress noinline nounwind 
optnone "frame-pointer"="none" "min-legal-vector-width"="0" 
"no-trapping-math"="true" "stack-protector-buffer-size"="8" }
 // CPU: attributes #1 = { convergent mustprogress noinline nounwind optnone 
"frame-pointer"="none" "min-legal-vector-width"="0" "no-trapping-math"="true" 
"stack-protector-buffer-size"="8" "target-cpu"="gfx900" 
"target-features"="+16-bit-insts,+ci-insts,+dpp,+flat-address-space,+gfx8-insts,+gfx9-insts,+s-memrealtime,+s-memtime-inst"
 }
Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -9423,8 +9423,12 @@
 
   const bool IsHIPKernel =
   M.getLangOpts().HIP && FD && FD->hasAttr();
+  const bool IsOpenMPkernel =
+  M.getLangOpts().OpenMPIsDevice &&
+  (F->getCallingConv() == llvm::CallingConv::AMDGPU_KERNEL);
 
-  if (IsHIPKernel)
+  // TODO: This should be moved to language specific attributes instead.
+  if (IsHIPKernel || IsOpenMPkernel)
 F->addFnAttr("uniform-work-group-size", "true");
 
   if (M.getContext().getTargetInfo().allowAMDGPUUnsafeFPAtomics())


Index: clang/test/OpenMP/amdgcn-attributes.cpp
===
--- clang/test/OpenMP/amdgcn-attributes.cpp
+++ clang/test/OpenMP/amdgcn-attributes.cpp
@@ -32,10 +32,10 @@
   return x + 1;
 }
 
-  // DEFAULT: attributes #0 = { convergent noinline norecurse nounwind optnone "frame-pointer"="none" "kernel" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
-  // CPU: attributes #0 = { convergent noinline norecurse nounwind optnone "frame-pointer"="none" "kernel" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="gfx900" "target-features"="+16-bit-insts,+ci-insts,+dpp,+flat-address-space,+gfx8-insts,+gfx9-insts,+s-memrealtime,+s-memtime-inst" 

[PATCH] D135381: [clang][modules] Fix handling of `ModuleHeaderRole::ExcludedHeader`

2022-10-06 Thread Jan Svoboda via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG586547687946: [clang][modules] Fix handling of 
`ModuleHeaderRole::ExcludedHeader` (authored by jansvoboda11).

Changed prior to commit:
  https://reviews.llvm.org/D135381?vs=465802=465921#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135381

Files:
  clang/include/clang/Lex/ModuleMap.h
  clang/lib/Lex/HeaderSearch.cpp
  clang/lib/Lex/ModuleMap.cpp
  clang/lib/Lex/PPDirectives.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/test/Modules/exclude-header-fw-umbrella.m

Index: clang/test/Modules/exclude-header-fw-umbrella.m
===
--- /dev/null
+++ clang/test/Modules/exclude-header-fw-umbrella.m
@@ -0,0 +1,25 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+
+//--- frameworks/A.framework/Modules/module.modulemap
+framework module A {
+  umbrella header "A.h"
+  exclude header "Excluded.h"
+
+  module Excluded {
+header "Excluded.h"
+  }
+}
+//--- frameworks/A.framework/Headers/A.h
+#import 
+//--- frameworks/A.framework/Headers/Sub.h
+//--- frameworks/A.framework/Headers/Excluded.h
+#import 
+@interface I
+@end
+
+//--- tu.m
+#import 
+
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/cache -iframework %t/frameworks -fsyntax-only %t/tu.m -verify
+// expected-no-diagnostics
Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -1829,8 +1829,6 @@
 }
   };
 
-  // FIXME: If the header is excluded, we should write out some
-  // record of that fact.
   for (auto ModInfo : Data.KnownHeaders)
 EmitModule(ModInfo.getModule(), ModInfo.getRole());
   if (Data.Unresolved.getPointer())
Index: clang/lib/Serialization/ASTReader.cpp
===
--- clang/lib/Serialization/ASTReader.cpp
+++ clang/lib/Serialization/ASTReader.cpp
@@ -1919,7 +1919,7 @@
 Module::Header H = {std::string(key.Filename), "",
 *FileMgr.getFile(Filename)};
 ModMap.addHeader(Mod, H, HeaderRole, /*Imported*/true);
-HFI.isModuleHeader |= !(HeaderRole & ModuleMap::TextualHeader);
+HFI.isModuleHeader |= ModuleMap::isModular(HeaderRole);
   }
 
   // This HeaderFileInfo was externally loaded.
Index: clang/lib/Lex/PPDirectives.cpp
===
--- clang/lib/Lex/PPDirectives.cpp
+++ clang/lib/Lex/PPDirectives.cpp
@@ -910,6 +910,10 @@
 continue;
   }
 
+  // Don't suggest explicitly excluded headers.
+  if (Header.getRole() == ModuleMap::ExcludedHeader)
+continue;
+
   // We'll suggest including textual headers below if they're
   // include-guarded.
   if (Header.getRole() & ModuleMap::TextualHeader)
Index: clang/lib/Lex/ModuleMap.cpp
===
--- clang/lib/Lex/ModuleMap.cpp
+++ clang/lib/Lex/ModuleMap.cpp
@@ -75,7 +75,6 @@
 
 Module::HeaderKind ModuleMap::headerRoleToKind(ModuleHeaderRole Role) {
   switch ((int)Role) {
-  default: llvm_unreachable("unknown header role");
   case NormalHeader:
 return Module::HK_Normal;
   case PrivateHeader:
@@ -84,7 +83,10 @@
 return Module::HK_Textual;
   case PrivateHeader | TextualHeader:
 return Module::HK_PrivateTextual;
+  case ExcludedHeader:
+return Module::HK_Excluded;
   }
+  llvm_unreachable("unknown header role");
 }
 
 ModuleMap::ModuleHeaderRole
@@ -99,11 +101,15 @@
   case Module::HK_PrivateTextual:
 return ModuleHeaderRole(PrivateHeader | TextualHeader);
   case Module::HK_Excluded:
-llvm_unreachable("unexpected header kind");
+return ExcludedHeader;
   }
   llvm_unreachable("unknown header kind");
 }
 
+bool ModuleMap::isModular(ModuleHeaderRole Role) {
+  return !(Role & (ModuleMap::TextualHeader | ModuleMap::ExcludedHeader));
+}
+
 Module::ExportDecl
 ModuleMap::resolveExport(Module *Mod,
  const Module::UnresolvedExportDecl ,
@@ -264,10 +270,7 @@
 } else {
   Module::Header H = {Header.FileName, std::string(RelativePathName.str()),
   *File};
-  if (Header.Kind == Module::HK_Excluded)
-excludeHeader(Mod, H);
-  else
-addHeader(Mod, H, headerKindToRole(Header.Kind));
+  addHeader(Mod, H, headerKindToRole(Header.Kind));
 }
   } else if (Header.HasBuiltinHeader && !Header.Size && !Header.ModTime) {
 // There's a builtin header but no corresponding on-disk header. Assume
@@ -489,6 +492,12 @@
   HeadersMap::iterator Known = findKnownHeader(File);
   if (Known != Headers.end()) {
 for (const KnownHeader  : Known->second) {
+  // Excluded 

[clang] 5865476 - [clang][modules] Fix handling of `ModuleHeaderRole::ExcludedHeader`

2022-10-06 Thread Jan Svoboda via cfe-commits

Author: Jan Svoboda
Date: 2022-10-06T16:20:24-07:00
New Revision: 586547687946b27a99d3bb4241226f9f126a173e

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

LOG: [clang][modules] Fix handling of `ModuleHeaderRole::ExcludedHeader`

This is a follow-up to D134224. The original patch added new `ExcludedHeader` 
enumerator to `ModuleMap::ModuleHeaderRole` and started associating headers 
with the modules they were excluded from. This was necessary to consider their 
module maps as "affecting" in certain situations and in turn serialize them 
into the PCM.

The association of the header and module needs to be handled when deserializing 
the PCM as well, though. This patch fixes a potential assertion failure and a 
regression. This essentially reverts parts of 
feb54b6ded123f8118fdc20620d3f657dfeab485.

Reviewed By: Bigcheese

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

Added: 
clang/test/Modules/exclude-header-fw-umbrella.m

Modified: 
clang/include/clang/Lex/ModuleMap.h
clang/lib/Lex/HeaderSearch.cpp
clang/lib/Lex/ModuleMap.cpp
clang/lib/Lex/PPDirectives.cpp
clang/lib/Serialization/ASTReader.cpp
clang/lib/Serialization/ASTWriter.cpp

Removed: 




diff  --git a/clang/include/clang/Lex/ModuleMap.h 
b/clang/include/clang/Lex/ModuleMap.h
index 10c5dfc25d9ce..ca04ce623616e 100644
--- a/clang/include/clang/Lex/ModuleMap.h
+++ b/clang/include/clang/Lex/ModuleMap.h
@@ -152,6 +152,9 @@ class ModuleMap {
   /// Convert a header role to a kind.
   static Module::HeaderKind headerRoleToKind(ModuleHeaderRole Role);
 
+  /// Check if the header with the given role is a modular one.
+  static bool isModular(ModuleHeaderRole Role);
+
   /// A header that is known to reside within a given module,
   /// whether it was included or excluded.
   class KnownHeader {
@@ -176,7 +179,7 @@ class ModuleMap {
 
 /// Whether this header is available in the module.
 bool isAvailable() const {
-  return getModule()->isAvailable();
+  return getRole() != ExcludedHeader && getModule()->isAvailable();
 }
 
 /// Whether this header is accessible from the specified module.
@@ -691,9 +694,6 @@ class ModuleMap {
   void addHeader(Module *Mod, Module::Header Header,
  ModuleHeaderRole Role, bool Imported = false);
 
-  /// Marks this header as being excluded from the given module.
-  void excludeHeader(Module *Mod, Module::Header Header);
-
   /// Parse the given module map file, and record any modules we
   /// encounter.
   ///

diff  --git a/clang/lib/Lex/HeaderSearch.cpp b/clang/lib/Lex/HeaderSearch.cpp
index 73f9678834969..bd69d8f697de8 100644
--- a/clang/lib/Lex/HeaderSearch.cpp
+++ b/clang/lib/Lex/HeaderSearch.cpp
@@ -1344,7 +1344,7 @@ bool HeaderSearch::isFileMultipleIncludeGuarded(const 
FileEntry *File) {
 void HeaderSearch::MarkFileModuleHeader(const FileEntry *FE,
 ModuleMap::ModuleHeaderRole Role,
 bool isCompilingModuleHeader) {
-  bool isModularHeader = !(Role & ModuleMap::TextualHeader);
+  bool isModularHeader = ModuleMap::isModular(Role);
 
   // Don't mark the file info as non-external if there's nothing to change.
   if (!isCompilingModuleHeader) {

diff  --git a/clang/lib/Lex/ModuleMap.cpp b/clang/lib/Lex/ModuleMap.cpp
index cbd3303f36636..2d8970516a5d2 100644
--- a/clang/lib/Lex/ModuleMap.cpp
+++ b/clang/lib/Lex/ModuleMap.cpp
@@ -75,7 +75,6 @@ void ModuleMap::addLinkAsDependency(Module *Mod) {
 
 Module::HeaderKind ModuleMap::headerRoleToKind(ModuleHeaderRole Role) {
   switch ((int)Role) {
-  default: llvm_unreachable("unknown header role");
   case NormalHeader:
 return Module::HK_Normal;
   case PrivateHeader:
@@ -84,7 +83,10 @@ Module::HeaderKind 
ModuleMap::headerRoleToKind(ModuleHeaderRole Role) {
 return Module::HK_Textual;
   case PrivateHeader | TextualHeader:
 return Module::HK_PrivateTextual;
+  case ExcludedHeader:
+return Module::HK_Excluded;
   }
+  llvm_unreachable("unknown header role");
 }
 
 ModuleMap::ModuleHeaderRole
@@ -99,11 +101,15 @@ ModuleMap::headerKindToRole(Module::HeaderKind Kind) {
   case Module::HK_PrivateTextual:
 return ModuleHeaderRole(PrivateHeader | TextualHeader);
   case Module::HK_Excluded:
-llvm_unreachable("unexpected header kind");
+return ExcludedHeader;
   }
   llvm_unreachable("unknown header kind");
 }
 
+bool ModuleMap::isModular(ModuleHeaderRole Role) {
+  return !(Role & (ModuleMap::TextualHeader | ModuleMap::ExcludedHeader));
+}
+
 Module::ExportDecl
 ModuleMap::resolveExport(Module *Mod,
  const Module::UnresolvedExportDecl ,
@@ -264,10 +270,7 @@ void ModuleMap::resolveHeader(Module *Mod,
 } else {
   Module::Header H = 

[clang] 5aba689 - [Clang] Emit a warning for ambiguous joined '-o' arguments

2022-10-06 Thread Joseph Huber via cfe-commits

Author: Joseph Huber
Date: 2022-10-06T18:20:15-05:00
New Revision: 5aba68960719c5d2de9ee0b459def9203e521f5e

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

LOG: [Clang] Emit a warning for ambiguous joined '-o' arguments

The offloading toolchain makes heavy use of options beginning with
`--o`. This is problematic when combined with the joined `-o` flag. In
the following situation, the user will not get the expected output and
will not notice as the expected output will still be written.
```
clang++ -x cuda foo.cu -offload-arch=sm_80 -o foo
```

This patch introduces a warning that checks for joined `-o` arguments
that would also be a valid driver argument if an additional `-` were
added. I believe this situation is uncommon enough to warrant a warning,
and can be trivially fixed by the end user by using the more common
separate form instead.

Reviewed By: tra, MaskRay

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

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticDriverKinds.td
clang/lib/Driver/Driver.cpp
clang/test/Driver/unknown-arg.c

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index e8a301ee6018c..b09e124206213 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -253,6 +253,9 @@ def warn_drv_yc_multiple_inputs_clang_cl : Warning<
   "support for '/Yc' with more than one source file not implemented yet; flag 
ignored">,
   InGroup;
 
+def warn_drv_potentially_misspelled_joined_argument : Warning<
+  "joined argument treated as '%0'; did you mean '%1'?">, 
InGroup;
+
 def err_drv_invalid_value : Error<"invalid value '%1' in '%0'">;
 def err_drv_invalid_int_value : Error<"invalid integral value '%1' in '%0'">;
 def err_drv_invalid_value_with_suggestion : Error<

diff  --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 21dc180d26c36..e612afdd56c9b 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -327,6 +327,19 @@ InputArgList Driver::ParseArgStrings(ArrayRef ArgStrings,
  DiagnosticsEngine::Warning;
   }
 
+  for (const Arg *A : Args.filtered(options::OPT_o)) {
+if (ArgStrings[A->getIndex()] == A->getSpelling())
+  continue;
+
+// Warn on joined arguments that are similar to a long argument.
+std::string ArgString = ArgStrings[A->getIndex()];
+std::string Nearest;
+if (getOpts().findNearest("-" + ArgString, Nearest, IncludedFlagsBitmask,
+  ExcludedFlagsBitmask) == 0)
+  Diags.Report(diag::warn_drv_potentially_misspelled_joined_argument)
+  << A->getAsString(Args) << Nearest;
+  }
+
   return Args;
 }
 

diff  --git a/clang/test/Driver/unknown-arg.c b/clang/test/Driver/unknown-arg.c
index 32346e3326f3f..9c1d433c8f0d4 100644
--- a/clang/test/Driver/unknown-arg.c
+++ b/clang/test/Driver/unknown-arg.c
@@ -1,5 +1,5 @@
-// RUN: not %clang %s -cake-is-lie -%0 -%d - -munknown-to-clang-option 
-print-stats -funknown-to-clang-option -ifoo -imultilib dir -### 2>&1 | \
-// RUN: FileCheck %s
+// RUN: not %clang %s -cake-is-lie -%0 -%d - -munknown-to-clang-option 
-print-stats -funknown-to-clang-option -ifoo -imultilib dir -o 
ffload-device-only -### 2>&1 | \
+// RUN: FileCheck %s --implicit-check-not=warning: 
 // RUN: %clang %s -imultilib dir -### 2>&1 | \
 // RUN: FileCheck %s --check-prefix=MULTILIB
 // RUN: not %clang %s -stdlibs=foo -hell -version -### 2>&1 | \
@@ -64,3 +64,9 @@
 // RUN: %clang -S %s -o %t.s  -Wunknown-to-clang-option 2>&1 | FileCheck 
--check-prefix=IGNORED %s
 
 // IGNORED: warning: unknown warning option '-Wunknown-to-clang-option'
+
+// RUN: %clang -### -offload-arch=sm_70 --offload-arch=sm_70 
-offload-device-only -o ffload-device-only \
+// RUN:   -output -o foo %s 2>&1 | FileCheck --check-prefix=O-WARN %s
+//  O-WARN: warning: joined argument treated as '-o ffload-arch=sm_70'; 
did you mean '--offload-arch=sm_70'?
+// O-WARN-NEXT: warning: joined argument treated as '-o ffload-device-only'; 
did you mean '--offload-device-only'?
+// O-WARN-NEXT: warning: joined argument treated as '-o utput'; did you mean 
'--output'?



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


[PATCH] D135389: [Clang] Emit a warning for ambiguous joined '-o' arguments

2022-10-06 Thread Joseph Huber via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG5aba68960719: [Clang] Emit a warning for ambiguous joined 
-o arguments (authored by jhuber6).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135389

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/lib/Driver/Driver.cpp
  clang/test/Driver/unknown-arg.c


Index: clang/test/Driver/unknown-arg.c
===
--- clang/test/Driver/unknown-arg.c
+++ clang/test/Driver/unknown-arg.c
@@ -1,5 +1,5 @@
-// RUN: not %clang %s -cake-is-lie -%0 -%d - -munknown-to-clang-option 
-print-stats -funknown-to-clang-option -ifoo -imultilib dir -### 2>&1 | \
-// RUN: FileCheck %s
+// RUN: not %clang %s -cake-is-lie -%0 -%d - -munknown-to-clang-option 
-print-stats -funknown-to-clang-option -ifoo -imultilib dir -o 
ffload-device-only -### 2>&1 | \
+// RUN: FileCheck %s --implicit-check-not=warning: 
 // RUN: %clang %s -imultilib dir -### 2>&1 | \
 // RUN: FileCheck %s --check-prefix=MULTILIB
 // RUN: not %clang %s -stdlibs=foo -hell -version -### 2>&1 | \
@@ -64,3 +64,9 @@
 // RUN: %clang -S %s -o %t.s  -Wunknown-to-clang-option 2>&1 | FileCheck 
--check-prefix=IGNORED %s
 
 // IGNORED: warning: unknown warning option '-Wunknown-to-clang-option'
+
+// RUN: %clang -### -offload-arch=sm_70 --offload-arch=sm_70 
-offload-device-only -o ffload-device-only \
+// RUN:   -output -o foo %s 2>&1 | FileCheck --check-prefix=O-WARN %s
+//  O-WARN: warning: joined argument treated as '-o ffload-arch=sm_70'; 
did you mean '--offload-arch=sm_70'?
+// O-WARN-NEXT: warning: joined argument treated as '-o ffload-device-only'; 
did you mean '--offload-device-only'?
+// O-WARN-NEXT: warning: joined argument treated as '-o utput'; did you mean 
'--output'?
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -327,6 +327,19 @@
  DiagnosticsEngine::Warning;
   }
 
+  for (const Arg *A : Args.filtered(options::OPT_o)) {
+if (ArgStrings[A->getIndex()] == A->getSpelling())
+  continue;
+
+// Warn on joined arguments that are similar to a long argument.
+std::string ArgString = ArgStrings[A->getIndex()];
+std::string Nearest;
+if (getOpts().findNearest("-" + ArgString, Nearest, IncludedFlagsBitmask,
+  ExcludedFlagsBitmask) == 0)
+  Diags.Report(diag::warn_drv_potentially_misspelled_joined_argument)
+  << A->getAsString(Args) << Nearest;
+  }
+
   return Args;
 }
 
Index: clang/include/clang/Basic/DiagnosticDriverKinds.td
===
--- clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -253,6 +253,9 @@
   "support for '/Yc' with more than one source file not implemented yet; flag 
ignored">,
   InGroup;
 
+def warn_drv_potentially_misspelled_joined_argument : Warning<
+  "joined argument treated as '%0'; did you mean '%1'?">, 
InGroup;
+
 def err_drv_invalid_value : Error<"invalid value '%1' in '%0'">;
 def err_drv_invalid_int_value : Error<"invalid integral value '%1' in '%0'">;
 def err_drv_invalid_value_with_suggestion : Error<


Index: clang/test/Driver/unknown-arg.c
===
--- clang/test/Driver/unknown-arg.c
+++ clang/test/Driver/unknown-arg.c
@@ -1,5 +1,5 @@
-// RUN: not %clang %s -cake-is-lie -%0 -%d - -munknown-to-clang-option -print-stats -funknown-to-clang-option -ifoo -imultilib dir -### 2>&1 | \
-// RUN: FileCheck %s
+// RUN: not %clang %s -cake-is-lie -%0 -%d - -munknown-to-clang-option -print-stats -funknown-to-clang-option -ifoo -imultilib dir -o ffload-device-only -### 2>&1 | \
+// RUN: FileCheck %s --implicit-check-not=warning: 
 // RUN: %clang %s -imultilib dir -### 2>&1 | \
 // RUN: FileCheck %s --check-prefix=MULTILIB
 // RUN: not %clang %s -stdlibs=foo -hell -version -### 2>&1 | \
@@ -64,3 +64,9 @@
 // RUN: %clang -S %s -o %t.s  -Wunknown-to-clang-option 2>&1 | FileCheck --check-prefix=IGNORED %s
 
 // IGNORED: warning: unknown warning option '-Wunknown-to-clang-option'
+
+// RUN: %clang -### -offload-arch=sm_70 --offload-arch=sm_70 -offload-device-only -o ffload-device-only \
+// RUN:   -output -o foo %s 2>&1 | FileCheck --check-prefix=O-WARN %s
+//  O-WARN: warning: joined argument treated as '-o ffload-arch=sm_70'; did you mean '--offload-arch=sm_70'?
+// O-WARN-NEXT: warning: joined argument treated as '-o ffload-device-only'; did you mean '--offload-device-only'?
+// O-WARN-NEXT: warning: joined argument treated as '-o utput'; did you mean '--output'?
Index: clang/lib/Driver/Driver.cpp
===
--- 

[PATCH] D135411: Add generic KCFI operand bundle lowering

2022-10-06 Thread Kees Cook via Phabricator via cfe-commits
kees added a comment.

What's the best way to test this in the kernel? I assume add 
`ARCH_SUPPORTS_CFI_CLANG` to an arch, and see what blows up? :) Have you tried 
this on any other arch yet?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135411

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


[PATCH] D135091: Create storage for the `_cmd` argument to the helper function for generated getters/setters of `direct` Objective-C properties.

2022-10-06 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak added inline comments.



Comment at: clang/lib/CodeGen/CGObjC.cpp:1116
+// for the `_cmd` argument that no longer exists for direct methods.
+static llvm::Value *emitCmdLoadForGetterSetterBody(CodeGenFunction ,
+   ObjCMethodDecl *MD) {

Since this is loading from an uninitialized alloca, can we just pass an `undef` 
to the call to `objc_get/setProperty`? The optimization passes will just do 
that, but we can still reduce the code size at `-O0`.


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

https://reviews.llvm.org/D135091

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


[PATCH] D135411: Add generic KCFI operand bundle lowering

2022-10-06 Thread Sami Tolvanen via Phabricator via cfe-commits
samitolvanen created this revision.
Herald added subscribers: Enna1, ormris, pengfei, hiraditya, kristof.beyls.
Herald added a project: All.
samitolvanen requested review of this revision.
Herald added subscribers: llvm-commits, cfe-commits, MaskRay.
Herald added projects: clang, LLVM.

The KCFI sanitizer emits "kcfi" operand bundles to indirect
call instructions, which the LLVM back-end lowers into an
architecture-specific type check with a known machine instruction
sequence. Currently, KCFI operand bundle lowering is supported only
on 64-bit X86 and AArch64 architectures.

As a lightweight forward-edge CFI implementation that doesn't
require LTO is also useful for non-Linux low-level targets on
other machine architectures, add a generic KCFI operand bundle
lowering pass that's only used when back-end lowering support is not
available and allows -fsanitize=kcfi to be enabled in Clang on all
architectures.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D135411

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/Driver/ToolChain.cpp
  llvm/include/llvm/InitializePasses.h
  llvm/include/llvm/Transforms/Instrumentation/KCFI.h
  llvm/lib/Passes/PassBuilder.cpp
  llvm/lib/Passes/PassRegistry.def
  llvm/lib/Transforms/Instrumentation/CMakeLists.txt
  llvm/lib/Transforms/Instrumentation/KCFI.cpp
  llvm/test/Transforms/KCFI/kcfi-patchable-function-prefix.ll
  llvm/test/Transforms/KCFI/kcfi-supported.ll
  llvm/test/Transforms/KCFI/kcfi.ll
  llvm/utils/gn/secondary/llvm/lib/Transforms/Instrumentation/BUILD.gn

Index: llvm/utils/gn/secondary/llvm/lib/Transforms/Instrumentation/BUILD.gn
===
--- llvm/utils/gn/secondary/llvm/lib/Transforms/Instrumentation/BUILD.gn
+++ llvm/utils/gn/secondary/llvm/lib/Transforms/Instrumentation/BUILD.gn
@@ -20,6 +20,7 @@
 "InstrOrderFile.cpp",
 "InstrProfiling.cpp",
 "Instrumentation.cpp",
+"KCFI.cpp",
 "MemProfiler.cpp",
 "MemorySanitizer.cpp",
 "PGOInstrumentation.cpp",
Index: llvm/test/Transforms/KCFI/kcfi.ll
===
--- /dev/null
+++ llvm/test/Transforms/KCFI/kcfi.ll
@@ -0,0 +1,21 @@
+; RUN: opt -S -passes=kcfi < %s | FileCheck %s
+
+; CHECK-LABEL: define void @f1
+define void @f1(ptr noundef %x) {
+  ; CHECK:  %[[#GEPI:]] = getelementptr inbounds i32, ptr %x, i32 -1
+  ; CHECK-NEXT: %[[#LOAD:]] = load i32, ptr %[[#GEPI]], align 4
+  ; CHECK-NEXT: %[[#ICMP:]] = icmp ne i32 %[[#LOAD]], 12345678
+  ; CHECK-NEXT: br i1 %[[#ICMP]], label %[[#TRAP:]], label %[[#CALL:]], !prof ![[#WEIGHTS:]]
+  ; CHECK:  [[#TRAP]]:
+  ; CHECK-NEXT: call void @llvm.trap()
+  ; CHECK-NEXT: br label %[[#CALL]]
+  ; CHECK:  [[#CALL]]:
+  ; CHECK-NEXT: call void %x()
+  ; CHECK-NOT:  [ "kcfi"(i32 12345678) ]
+  call void %x() [ "kcfi"(i32 12345678) ]
+  ret void
+}
+
+!llvm.module.flags = !{!0}
+!0 = !{i32 4, !"kcfi", i32 1}
+; CHECK: ![[#WEIGHTS]] = !{!"branch_weights", i32 1, i32 1048575}
Index: llvm/test/Transforms/KCFI/kcfi-supported.ll
===
--- /dev/null
+++ llvm/test/Transforms/KCFI/kcfi-supported.ll
@@ -0,0 +1,18 @@
+; REQUIRES: x86-registered-target
+; RUN: opt -S -passes=kcfi < %s | FileCheck %s
+
+; COM: If the back-end supports KCFI operand bundle lowering, KCFIPass should be a no-op.
+
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+; CHECK-LABEL: define void @f1
+define void @f1(ptr noundef %x) {
+  ; CHECK-NOT: call void @llvm.trap()
+  ; CHECK: call void %x() [ "kcfi"(i32 12345678) ]
+  call void %x() [ "kcfi"(i32 12345678) ]
+  ret void
+}
+
+!llvm.module.flags = !{!0}
+!0 = !{i32 4, !"kcfi", i32 1}
Index: llvm/test/Transforms/KCFI/kcfi-patchable-function-prefix.ll
===
--- /dev/null
+++ llvm/test/Transforms/KCFI/kcfi-patchable-function-prefix.ll
@@ -0,0 +1,12 @@
+; RUN: not opt -S -passes=kcfi < %s 2>&1 | FileCheck %s
+
+; CHECK: LLVM ERROR: -fpatchable-function-entry=N,M, where M>0 is not compatible with -fsanitize=kcfi on this target.
+define void @f1(ptr noundef %x) #0 {
+  call void %x() [ "kcfi"(i32 12345678) ]
+  ret void
+}
+
+attributes #0 = { "patchable-function-prefix"="1" }
+
+!llvm.module.flags = !{!0}
+!0 = !{i32 4, !"kcfi", i32 1}
Index: llvm/lib/Transforms/Instrumentation/KCFI.cpp
===
--- /dev/null
+++ llvm/lib/Transforms/Instrumentation/KCFI.cpp
@@ -0,0 +1,100 @@
+//===-- KCFI.cpp - Generic KCFI operand bundle lowering -*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//

[PATCH] D129531: [clang][C++20] P0960R3: Allow initializing aggregates from a parenthesized list of values

2022-10-06 Thread Alan Zhao via Phabricator via cfe-commits
ayzhao updated this revision to Diff 465913.
ayzhao added a comment.

implement initialization of remaining elements not in the list


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129531

Files:
  clang/include/clang/AST/Decl.h
  clang/include/clang/AST/ExprCXX.h
  clang/include/clang/AST/RecursiveASTVisitor.h
  clang/include/clang/Basic/StmtNodes.td
  clang/include/clang/Sema/Initialization.h
  clang/lib/AST/Expr.cpp
  clang/lib/AST/ExprCXX.cpp
  clang/lib/AST/ExprClassification.cpp
  clang/lib/AST/ExprConstant.cpp
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/JSONNodeDumper.cpp
  clang/lib/AST/StmtPrinter.cpp
  clang/lib/AST/StmtProfile.cpp
  clang/lib/AST/TextNodeDumper.cpp
  clang/lib/CodeGen/CGExprAgg.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaExceptionSpec.cpp
  clang/lib/Sema/SemaInit.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTReaderStmt.cpp
  clang/lib/Serialization/ASTWriterStmt.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
  clang/test/CXX/class/class.compare/class.spaceship/p1.cpp
  clang/test/CXX/drs/dr2xx.cpp
  clang/test/CXX/temp/temp.decls/temp.variadic/p4.cpp
  clang/test/CodeGen/P0960R3.cpp
  clang/test/SemaCXX/P0960R3.cpp
  clang/test/SemaCXX/cxx2a-explicit-bool.cpp

Index: clang/test/SemaCXX/cxx2a-explicit-bool.cpp
===
--- clang/test/SemaCXX/cxx2a-explicit-bool.cpp
+++ clang/test/SemaCXX/cxx2a-explicit-bool.cpp
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -std=c++17 -fsyntax-only %s -verify -Wno-c++2a-extensions
-// RUN: %clang_cc1 -std=c++2a -fsyntax-only %s -verify
+// RUN: %clang_cc1 -std=c++17 -fsyntax-only %s -verify=expected,pre20 -Wno-c++2a-extensions
+// RUN: %clang_cc1 -std=c++2a -fsyntax-only %s -verify=expected,pro20
 
 template  struct enable_ifv {};
 
@@ -20,7 +20,7 @@
 
 template
 struct A {
-// expected-note@-1+ {{candidate constructor}}
+// pre20-note@-1+ {{candidate constructor}}
   explicit(1 << a)
 // expected-note@-1 {{negative shift count -1}}
 // expected-error@-2 {{explicit specifier argument is not a constant expression}}
@@ -28,8 +28,9 @@
 };
 
 A<-1> a(0);
-// expected-error@-1 {{no matching constructor}}
-// expected-note@-2 {{in instantiation of template class}}
+// pre20-error@-1 {{no matching constructor}}
+// pro20-error@-2 {{excess elements in struct initializer}}
+// expected-note@-3 {{in instantiation of template class}}
 
 template
 struct B {
Index: clang/test/SemaCXX/P0960R3.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/P0960R3.cpp
@@ -0,0 +1,76 @@
+// RUN: %clang_cc1 -verify -std=c++20 %s -fsyntax-only
+
+struct A { // expected-note 4{{candidate constructor}}
+  char i;
+  double j;
+};
+
+struct B {
+  A a;
+  int b[20];
+  int & // expected-note {{reference member declared here}}
+};
+
+struct C { // expected-note 2{{candidate constructor}}
+  A a;
+  int b[20];
+};
+
+struct D : public C, public A {
+  int a;
+};
+
+struct E { // expected-note 3{{candidate constructor}}
+  struct F {
+F(int, int);
+  };
+  int a;
+  F f;
+};
+
+union U {
+  int a;
+  char* b;
+};
+
+void foo() {
+  A a(1954, 9, 21);
+  // expected-error@-1 {{excess elements in struct initializer}}
+  A b(2.1);
+  // expected-warning@-1 {{implicit conversion from 'double' to 'char'}}
+  A e(-1.2, 9.8);
+  // expected-warning@-1 {{implicit conversion from 'double' to 'char'}}
+  A s = static_cast(1.1);
+  // expected-warning@-1 {{implicit conversion from 'double' to 'char'}}
+  A h = (A)3.1;
+  // expected-warning@-1 {{implicit conversion from 'double' to 'char'}}
+  A i = A(8.7);
+  // expected-warning@-1 {{implicit conversion from 'double' to 'char'}}
+
+  B n(2022, {7, 8});
+  // expected-error@-1 {{no viable conversion from 'int' to 'A'}}
+  B z(A(1), {}, 1);
+  // expected-error@-1 {{reference member 'c' binds to a temporary object whose lifetime would be shorter than the lifetime of the constructed object}}
+
+  C o(A(1), 1, 2, 3, 4);
+  // expected-error@-1 {{excess elements in struct initializer}}
+  D R(1);
+  // expected-error@-1 {{no viable conversion from 'int' to 'C'}}
+  D I(C(1));
+  // expected-error@-1 {{functional-style cast from 'int' to 'C' is not allowed}}
+  D P(C(A(1)), 1);
+  // expected-error@-1 {{no viable conversion from 'int' to 'A'}}
+
+  int arr1[](0, 1, 2, A(1));
+  // expected-error@-1 {{no viable conversion from 'A' to 'int'}}
+  int arr2[2](0, 1, 2);
+  // expected-error@-1 {{excess elements in array initializer}}
+
+  U u1("abcd");
+  // expected-error@-1 {{cannot initialize a member subobject of type 'int' with an lvalue of type 'const char[5]'}}
+  U u2(1, "efgh");
+  // expected-error@-1 {{excess elements in union initializer}}
+
+  E e1(1);
+  // expected-error@-1 {{no matching constructor for initialization of 'E'}}
+}
Index: clang/test/CodeGen/P0960R3.cpp

[PATCH] D135400: [clang][LTO] Remove the use of `--` for arange option

2022-10-06 Thread Qiongsi Wu via Phabricator via cfe-commits
qiongsiwu1 updated this revision to Diff 465910.
qiongsiwu1 added a comment.

Thanks for the review! Comment addressed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135400

Files:
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/test/Driver/debug-options-aranges.c


Index: clang/test/Driver/debug-options-aranges.c
===
--- clang/test/Driver/debug-options-aranges.c
+++ clang/test/Driver/debug-options-aranges.c
@@ -3,4 +3,4 @@
 /// Check that the linker plugin will get -generate-arange-section.
 // RUN: %clang -### -g --target=x86_64-linux -flto  -gdwarf-aranges %s 
2>&1 | FileCheck %s
 // RUN: %clang -### -g --target=x86_64-linux -flto=thin -gdwarf-aranges %s 
2>&1 | FileCheck %s
-// CHECK: --plugin-opt=-generate-arange-section
+// CHECK: "-plugin-opt=-generate-arange-section"
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -514,7 +514,7 @@
   // the way out.
   if (Args.hasArg(options::OPT_gdwarf_aranges)) {
 CmdArgs.push_back(
-Args.MakeArgString("--plugin-opt=-generate-arange-section"));
+Args.MakeArgString("-plugin-opt=-generate-arange-section"));
   }
 
   // Try to pass driver level flags relevant to LTO code generation down to


Index: clang/test/Driver/debug-options-aranges.c
===
--- clang/test/Driver/debug-options-aranges.c
+++ clang/test/Driver/debug-options-aranges.c
@@ -3,4 +3,4 @@
 /// Check that the linker plugin will get -generate-arange-section.
 // RUN: %clang -### -g --target=x86_64-linux -flto  -gdwarf-aranges %s 2>&1 | FileCheck %s
 // RUN: %clang -### -g --target=x86_64-linux -flto=thin -gdwarf-aranges %s 2>&1 | FileCheck %s
-// CHECK: --plugin-opt=-generate-arange-section
+// CHECK: "-plugin-opt=-generate-arange-section"
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -514,7 +514,7 @@
   // the way out.
   if (Args.hasArg(options::OPT_gdwarf_aranges)) {
 CmdArgs.push_back(
-Args.MakeArgString("--plugin-opt=-generate-arange-section"));
+Args.MakeArgString("-plugin-opt=-generate-arange-section"));
   }
 
   // Try to pass driver level flags relevant to LTO code generation down to
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D135381: [clang][modules] Fix handling of `ModuleHeaderRole::ExcludedHeader`

2022-10-06 Thread Michael Spencer via Phabricator via cfe-commits
Bigcheese accepted this revision.
Bigcheese added a comment.
This revision is now accepted and ready to land.

lgtm


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135381

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


[PATCH] D135400: [clang][LTO] Remove the use of `--` for arange option

2022-10-06 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay accepted this revision.
MaskRay added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/test/Driver/debug-options-aranges.c:6
 // RUN: %clang -### -g --target=x86_64-linux -flto=thin -gdwarf-aranges %s 
2>&1 | FileCheck %s
-// CHECK: --plugin-opt=-generate-arange-section
+// CHECK: -plugin-opt=-generate-arange-section




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

https://reviews.llvm.org/D135400

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


[PATCH] D135397: [clang][dataflow] Add support for a Top value in boolean formulas.

2022-10-06 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun added inline comments.



Comment at: 
clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h:157
+  TopValue () {
+return takeOwnership(std::make_unique());
+  }

gribozavr2 wrote:
> Should we be creating a new top every time, or should it be a singleton like 
> true and false?
> 
> It seems like we explicitly don't care about its identity (or else it would 
> be isomorphic to AtomicBool).
Good point, a singleton Top might actually simplify some parts of the code.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135397

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


[PATCH] D135397: [clang][dataflow] Add support for a Top value in boolean formulas.

2022-10-06 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun accepted this revision.
xazax.hun added inline comments.
This revision is now accepted and ready to land.



Comment at: 
clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp:527-528
+auto *Prop2 = Val2.getProperty("has_value");
+return Prop1 == Prop2 || (Prop1 != nullptr && Prop2 != nullptr &&
+  isTop(*Prop1) && isTop(*Prop2));
   }

I feel like this logic is repeated multiple times. I wonder if we should define 
an `operator==` for `const BoolValue*`.



Comment at: 
clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp:1192
+ const Environment , const Value ,
+ const Environment ) final {
+// Changes to a sounds approximation, which allows us to test whether we 
can

Nit: I usually prefer marking whole classes final rather than individual 
virtual methods, but feel free to leave as is.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135397

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


[PATCH] D134668: [LTO][clang] Using Single Dash Consistently when Passing LTO Options

2022-10-06 Thread Qiongsi Wu via Phabricator via cfe-commits
qiongsiwu1 added a comment.

In D134668#3841464 , @MaskRay wrote:

> Err since `-plugin-opt=` was used a lot of before this change, I think this 
> is fine for consistency.

Ah ok this sounds good to me as well! Just to make sure I understand, we will 
need https://reviews.llvm.org/D135400 then. Is this correct?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134668

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


[PATCH] D135091: Create storage for the `_cmd` argument to the helper function for generated getters/setters of `direct` Objective-C properties.

2022-10-06 Thread Michael Wyman via Phabricator via cfe-commits
mwyman updated this revision to Diff 465896.
mwyman marked an inline comment as done.
mwyman added a comment.

Extracted the common new code into a helper function.


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

https://reviews.llvm.org/D135091

Files:
  clang/lib/CodeGen/CGObjC.cpp
  clang/test/CodeGenObjC/direct-method.m


Index: clang/test/CodeGenObjC/direct-method.m
===
--- clang/test/CodeGenObjC/direct-method.m
+++ clang/test/CodeGenObjC/direct-method.m
@@ -14,6 +14,7 @@
 - (int)getInt __attribute__((objc_direct));
 @property(direct, readonly) int intProperty;
 @property(direct, readonly) int intProperty2;
+@property(direct, readonly) id objectProperty;
 @end
 
 @implementation Root
@@ -167,6 +168,18 @@
 @end
 // CHECK-LABEL: define hidden i32 @"\01-[Root intProperty]"
 
+// Check the synthesized objectProperty calls objc_getProperty(); this also
+// checks that the synthesized method accesses _cmd (or rather loads the
+// selector, as it is an argument to objc_getProperty).
+// CHECK-LABEL: define hidden i8* @"\01-[Root objectProperty]"(
+// CHECK-LABEL: entry:
+// CHECK-NEXT: [[RETVAL:%.*]] = alloca i8*,
+// CHECK-NEXT: [[SELFADDR:%.*]] = alloca %0*,
+// CHECK-NEXT: [[CMDVAL:%_cmd]] = alloca i8*,
+// CHECK-LABEL: objc_direct_method.cont:
+// CHECK: [[CMD:%.*]] = load i8*, i8** [[CMDVAL]],
+// CHECK: call i8* @objc_getProperty({{.*}}, i8*{{.*}} [[CMD]], {{.*}})
+
 @interface Foo : Root {
   id __strong _cause_cxx_destruct;
 }
Index: clang/lib/CodeGen/CGObjC.cpp
===
--- clang/lib/CodeGen/CGObjC.cpp
+++ clang/lib/CodeGen/CGObjC.cpp
@@ -,6 +,21 @@
callee, ReturnValueSlot(), args);
 }
 
+// emitCmdLoadForGetterSetterBody - Handle emitting local storage declarations
+// for the `_cmd` argument that no longer exists for direct methods.
+static llvm::Value *emitCmdLoadForGetterSetterBody(CodeGenFunction ,
+   ObjCMethodDecl *MD) {
+  if (MD->isDirectMethod()) {
+// Direct methods no longer have a `_cmd` argument, so storage must be
+// emitted for it to be passed to the property helper. Since the `_cmd`
+// argument was never being initialized by the caller before, still pass
+// an uninitialized/undefined value here.
+CGF.EmitVarDecl(*MD->getCmdDecl());
+  }
+
+  return CGF.Builder.CreateLoad(CGF.GetAddrOfLocalVar(MD->getCmdDecl()), 
"cmd");
+}
+
 void
 CodeGenFunction::generateObjCGetterBody(const ObjCImplementationDecl 
*classImpl,
 const ObjCPropertyImplDecl *propImpl,
@@ -1189,8 +1204,7 @@
 // Return (ivar-type) objc_getProperty((id) self, _cmd, offset, true).
 // FIXME: Can't this be simpler? This might even be worse than the
 // corresponding gcc code.
-llvm::Value *cmd =
-  Builder.CreateLoad(GetAddrOfLocalVar(getterMethod->getCmdDecl()), "cmd");
+llvm::Value *cmd = emitCmdLoadForGetterSetterBody(*this, getterMethod);
 llvm::Value *self = Builder.CreateBitCast(LoadObjCSelf(), VoidPtrTy);
 llvm::Value *ivarOffset =
   EmitIvarOffset(classImpl->getClassInterface(), ivar);
@@ -1475,8 +1489,7 @@
 
 // Emit objc_setProperty((id) self, _cmd, offset, arg,
 //   , ).
-llvm::Value *cmd =
-  Builder.CreateLoad(GetAddrOfLocalVar(setterMethod->getCmdDecl()));
+llvm::Value *cmd = emitCmdLoadForGetterSetterBody(*this, setterMethod);
 llvm::Value *self =
   Builder.CreateBitCast(LoadObjCSelf(), VoidPtrTy);
 llvm::Value *ivarOffset =


Index: clang/test/CodeGenObjC/direct-method.m
===
--- clang/test/CodeGenObjC/direct-method.m
+++ clang/test/CodeGenObjC/direct-method.m
@@ -14,6 +14,7 @@
 - (int)getInt __attribute__((objc_direct));
 @property(direct, readonly) int intProperty;
 @property(direct, readonly) int intProperty2;
+@property(direct, readonly) id objectProperty;
 @end
 
 @implementation Root
@@ -167,6 +168,18 @@
 @end
 // CHECK-LABEL: define hidden i32 @"\01-[Root intProperty]"
 
+// Check the synthesized objectProperty calls objc_getProperty(); this also
+// checks that the synthesized method accesses _cmd (or rather loads the
+// selector, as it is an argument to objc_getProperty).
+// CHECK-LABEL: define hidden i8* @"\01-[Root objectProperty]"(
+// CHECK-LABEL: entry:
+// CHECK-NEXT: [[RETVAL:%.*]] = alloca i8*,
+// CHECK-NEXT: [[SELFADDR:%.*]] = alloca %0*,
+// CHECK-NEXT: [[CMDVAL:%_cmd]] = alloca i8*,
+// CHECK-LABEL: objc_direct_method.cont:
+// CHECK: [[CMD:%.*]] = load i8*, i8** [[CMDVAL]],
+// CHECK: call i8* @objc_getProperty({{.*}}, i8*{{.*}} [[CMD]], {{.*}})
+
 @interface Foo : Root {
   id __strong _cause_cxx_destruct;
 }
Index: clang/lib/CodeGen/CGObjC.cpp
===
--- clang/lib/CodeGen/CGObjC.cpp
+++ 

[PATCH] D135389: [Clang] Emit a warning for ambiguous joined '-o' arguments

2022-10-06 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 updated this revision to Diff 465894.
jhuber6 added a comment.

Using the implicit check suggestion.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135389

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/lib/Driver/Driver.cpp
  clang/test/Driver/unknown-arg.c


Index: clang/test/Driver/unknown-arg.c
===
--- clang/test/Driver/unknown-arg.c
+++ clang/test/Driver/unknown-arg.c
@@ -1,5 +1,5 @@
-// RUN: not %clang %s -cake-is-lie -%0 -%d - -munknown-to-clang-option 
-print-stats -funknown-to-clang-option -ifoo -imultilib dir -### 2>&1 | \
-// RUN: FileCheck %s
+// RUN: not %clang %s -cake-is-lie -%0 -%d - -munknown-to-clang-option 
-print-stats -funknown-to-clang-option -ifoo -imultilib dir -o 
ffload-device-only -### 2>&1 | \
+// RUN: FileCheck %s --implicit-check-not=warning: 
 // RUN: %clang %s -imultilib dir -### 2>&1 | \
 // RUN: FileCheck %s --check-prefix=MULTILIB
 // RUN: not %clang %s -stdlibs=foo -hell -version -### 2>&1 | \
@@ -64,3 +64,9 @@
 // RUN: %clang -S %s -o %t.s  -Wunknown-to-clang-option 2>&1 | FileCheck 
--check-prefix=IGNORED %s
 
 // IGNORED: warning: unknown warning option '-Wunknown-to-clang-option'
+
+// RUN: %clang -### -offload-arch=sm_70 --offload-arch=sm_70 
-offload-device-only -o ffload-device-only \
+// RUN:   -output -o foo %s 2>&1 | FileCheck --check-prefix=O-WARN %s
+//  O-WARN: warning: joined argument treated as '-o ffload-arch=sm_70'; 
did you mean '--offload-arch=sm_70'?
+// O-WARN-NEXT: warning: joined argument treated as '-o ffload-device-only'; 
did you mean '--offload-device-only'?
+// O-WARN-NEXT: warning: joined argument treated as '-o utput'; did you mean 
'--output'?
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -327,6 +327,19 @@
  DiagnosticsEngine::Warning;
   }
 
+  for (const Arg *A : Args.filtered(options::OPT_o)) {
+if (ArgStrings[A->getIndex()] == A->getSpelling())
+  continue;
+
+// Warn on joined arguments that are similar to a long argument.
+std::string ArgString = ArgStrings[A->getIndex()];
+std::string Nearest;
+if (getOpts().findNearest("-" + ArgString, Nearest, IncludedFlagsBitmask,
+  ExcludedFlagsBitmask) == 0)
+  Diags.Report(diag::warn_drv_potentially_misspelled_joined_argument)
+  << A->getAsString(Args) << Nearest;
+  }
+
   return Args;
 }
 
Index: clang/include/clang/Basic/DiagnosticDriverKinds.td
===
--- clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -253,6 +253,9 @@
   "support for '/Yc' with more than one source file not implemented yet; flag 
ignored">,
   InGroup;
 
+def warn_drv_potentially_misspelled_joined_argument : Warning<
+  "joined argument treated as '%0'; did you mean '%1'?">, 
InGroup;
+
 def err_drv_invalid_value : Error<"invalid value '%1' in '%0'">;
 def err_drv_invalid_int_value : Error<"invalid integral value '%1' in '%0'">;
 def err_drv_invalid_value_with_suggestion : Error<


Index: clang/test/Driver/unknown-arg.c
===
--- clang/test/Driver/unknown-arg.c
+++ clang/test/Driver/unknown-arg.c
@@ -1,5 +1,5 @@
-// RUN: not %clang %s -cake-is-lie -%0 -%d - -munknown-to-clang-option -print-stats -funknown-to-clang-option -ifoo -imultilib dir -### 2>&1 | \
-// RUN: FileCheck %s
+// RUN: not %clang %s -cake-is-lie -%0 -%d - -munknown-to-clang-option -print-stats -funknown-to-clang-option -ifoo -imultilib dir -o ffload-device-only -### 2>&1 | \
+// RUN: FileCheck %s --implicit-check-not=warning: 
 // RUN: %clang %s -imultilib dir -### 2>&1 | \
 // RUN: FileCheck %s --check-prefix=MULTILIB
 // RUN: not %clang %s -stdlibs=foo -hell -version -### 2>&1 | \
@@ -64,3 +64,9 @@
 // RUN: %clang -S %s -o %t.s  -Wunknown-to-clang-option 2>&1 | FileCheck --check-prefix=IGNORED %s
 
 // IGNORED: warning: unknown warning option '-Wunknown-to-clang-option'
+
+// RUN: %clang -### -offload-arch=sm_70 --offload-arch=sm_70 -offload-device-only -o ffload-device-only \
+// RUN:   -output -o foo %s 2>&1 | FileCheck --check-prefix=O-WARN %s
+//  O-WARN: warning: joined argument treated as '-o ffload-arch=sm_70'; did you mean '--offload-arch=sm_70'?
+// O-WARN-NEXT: warning: joined argument treated as '-o ffload-device-only'; did you mean '--offload-device-only'?
+// O-WARN-NEXT: warning: joined argument treated as '-o utput'; did you mean '--output'?
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -327,6 +327,19 @@
   

[PATCH] D135397: [clang][dataflow] Add support for a Top value in boolean formulas.

2022-10-06 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr2 added inline comments.



Comment at: 
clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h:157
+  TopValue () {
+return takeOwnership(std::make_unique());
+  }

Should we be creating a new top every time, or should it be a singleton like 
true and false?

It seems like we explicitly don't care about its identity (or else it would be 
isomorphic to AtomicBool).



Comment at: clang/include/clang/Analysis/FlowSensitive/Value.h:97
+/// formulas.
+class TopValue final : public BoolValue {
+public:

Here and throughout the patch: since we might have a top for other kinds of 
values, WDYT about renaming this type to TopBoolValue? Similarly createTop -> 
createTopBool ?



Comment at: clang/include/clang/Analysis/FlowSensitive/Value.h:102
+  static bool classof(const Value *Val) { return Val->getKind() == Kind::Top; }
+};
+

Since TopValue is a BoolValue, can we form say a ConjunctionValue where LHS or 
RHS is Top?

What if we create such a conjunction twice? It seems like such conjunctions 
would incorrectly compare equal, even though each Top will be replaced with a 
unique fresh variable.

Would it make sense to change our factory functions for boolean formulas to 
eagerly open Top?

Then we wouldn't need a recursive walk in unpackValue().



Comment at: clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp:378
+if (Val == It->second || (Val->getKind() == Value::Kind::Top &&
+  It->second->getKind() == Value::Kind::Top)) {
   JoinedEnv.LocToVal.insert({Loc, Val});

isa



Comment at: clang/lib/Analysis/FlowSensitive/Transfer.cpp:76
+  case Value::Kind::AtomicBool:
+return V;
+

llvm_unreachable(); because this can't happen, V is a BoolValue.



Comment at: clang/lib/Analysis/FlowSensitive/Transfer.cpp:123-124
+  return 
+}
+
+





Comment at: clang/lib/Analysis/FlowSensitive/WatchedLiteralsSolver.cpp:237-238
+  case Value::Kind::Top:
+// Nothing more to do. Each `Top` instance will be mapped to a fresh
+// variable and is thereafter anonymous.
+break;





Comment at: 
clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp:469
 
+static bool isTop(Value ) { return V.getKind() == Value::Kind::Top; }
+static bool isAtomic(Value ) {

`isa(...)`? and `isa(...)` below?



Comment at: 
clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp:621
+EXPECT_EQ(GetFooValue(Env3)->getProperty("has_value")->getKind(),
+  Value::Kind::Top);
   });

`EXPECT_TRUE(isa(...))` ?



Comment at: 
clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp:1193
+ const Environment ) final {
+// Changes to a sounds approximation, which allows us to test whether we 
can
+// (soundly) converge for some loops.





Comment at: 
clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp:1220-1221
+
+// void target(bool Foo) {
+void target() {
+  bool Foo = makeTop();





Comment at: 
clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp:1292
+ASSERT_THAT(FooVal2, NotNull());
+EXPECT_TRUE(isTop(*FooVal2));
+





Comment at: 
clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp:1302-1311
+void target(bool Cond) {
+  bool Foo = makeTop();
+  // Force a new block.
+  if (false) return;
+  (void)0;
+  /*[[p1]]*/
+

Similarly in tests below.

`if (false)` theoretically could be handled in a special way in future and 
could be folded away during CFG construction.



Comment at: 
clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp:1436-1440
+const ValueDecl *Zab1Decl = findValueDecl(AO.ASTCtx, "Zab1");
+ASSERT_THAT(Zab1Decl, NotNull());
+
+const ValueDecl *Zab2Decl = findValueDecl(AO.ASTCtx, "Zab2");
+ASSERT_THAT(Zab2Decl, NotNull());

Zab1Decl, Zab2Decl are unused apart from the NotNull check (which does not seem 
interesting to me).



Comment at: 
clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp:1454
+  });
+}
+

Could you add a variant of this test?

```
void target(bool Cond) {
  bool Foo = makeTop();
  // Force a new block.
  if (false) return;
  (void)0;
  /*[[p1]]*/

  bool Zab;
  if (Cond) {
Zab = Foo;
  } else {
Zab = Foo;
  }
  (void)0;
  if (Zab == Foo) { return; }
  /*[[p2]]*/
}
```

Show 

[PATCH] D133993: [HLSL] Remove global ctor/dtor variable for non-lib profile.

2022-10-06 Thread Xiang Li via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG2bdfececef43: [HLSL] Remove global ctor/dtor variable for 
non-lib profile. (authored by python3kgae).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133993

Files:
  clang/lib/CodeGen/CGHLSLRuntime.cpp
  clang/test/CodeGenHLSL/GlobalConstructorFunction.hlsl
  clang/test/CodeGenHLSL/GlobalConstructorLib.hlsl
  clang/test/CodeGenHLSL/GlobalConstructors.hlsl
  clang/test/CodeGenHLSL/GlobalDestructors.hlsl


Index: clang/test/CodeGenHLSL/GlobalDestructors.hlsl
===
--- clang/test/CodeGenHLSL/GlobalDestructors.hlsl
+++ clang/test/CodeGenHLSL/GlobalDestructors.hlsl
@@ -1,5 +1,10 @@
-// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-compute -std=hlsl202x -S 
-emit-llvm -disable-llvm-passes %s -o - | FileCheck %s
-// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -std=hlsl202x -S 
-emit-llvm -disable-llvm-passes %s -o - | FileCheck %s --check-prefixes=CHECK
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-compute -std=hlsl202x -S 
-emit-llvm -disable-llvm-passes %s -o - | FileCheck %s --check-prefixes=CS,CHECK
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -std=hlsl202x -S 
-emit-llvm -disable-llvm-passes %s -o - | FileCheck %s 
--check-prefixes=LIB,CHECK
+
+// Make sure global variable for dtors exist for lib profile.
+// LIB:@llvm.global_dtors
+// Make sure global variable for dtors removed for compute profile.
+// CS-NOT:llvm.global_dtors
 
 struct Tail {
   Tail() {
@@ -40,6 +45,9 @@
   Wag();
 }
 
+// Make sure global variable for ctors/dtors removed.
+// CHECK-NOT:@llvm.global_ctors
+// CHECK-NOT:@llvm.global_dtors
 //CHECK:  define void @main()
 //CHECK-NEXT: entry:
 //CHECK-NEXT:   call void @_GLOBAL__sub_I_GlobalDestructors.hlsl()
Index: clang/test/CodeGenHLSL/GlobalConstructors.hlsl
===
--- clang/test/CodeGenHLSL/GlobalConstructors.hlsl
+++ clang/test/CodeGenHLSL/GlobalConstructors.hlsl
@@ -5,6 +5,9 @@
 [numthreads(1,1,1)]
 void main(unsigned GI : SV_GroupIndex) {}
 
+// Make sure global variable for ctors/dtors removed.
+// CHECK-NOT:@llvm.global_ctors
+// CHECK-NOT:@llvm.global_dtors
 //CHECK:  define void @main()
 //CHECK-NEXT: entry:
 //CHECK-NEXT:   call void @_GLOBAL__sub_I_GlobalConstructors.hlsl()
Index: clang/test/CodeGenHLSL/GlobalConstructorLib.hlsl
===
--- clang/test/CodeGenHLSL/GlobalConstructorLib.hlsl
+++ clang/test/CodeGenHLSL/GlobalConstructorLib.hlsl
@@ -1,5 +1,8 @@
 // RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -S -emit-llvm 
-disable-llvm-passes %s -o - | FileCheck %s
 
+// Make sure global variable for ctors exist for lib profile.
+// CHECK:@llvm.global_ctors
+
 RWBuffer Buffer;
 
 [shader("compute")]
Index: clang/test/CodeGenHLSL/GlobalConstructorFunction.hlsl
===
--- clang/test/CodeGenHLSL/GlobalConstructorFunction.hlsl
+++ clang/test/CodeGenHLSL/GlobalConstructorFunction.hlsl
@@ -17,6 +17,10 @@
 [numthreads(1,1,1)]
 void main(unsigned GI : SV_GroupIndex) {}
 
+// Make sure global variable for ctors/dtors removed.
+// CHECK-NOT:@llvm.global_ctors
+// CHECK-NOT:@llvm.global_dtors
+
 //CHECK: define void @main()
 //CHECK-NEXT: entry:
 //CHECK-NEXT:   call void @"?call_me_first@@YAXXZ"()
Index: clang/lib/CodeGen/CGHLSLRuntime.cpp
===
--- clang/lib/CodeGen/CGHLSLRuntime.cpp
+++ clang/lib/CodeGen/CGHLSLRuntime.cpp
@@ -212,4 +212,14 @@
 for (auto *Fn : DtorFns)
   B.CreateCall(FunctionCallee(Fn));
   }
+
+  // No need to keep global ctors/dtors for non-lib profile after call to
+  // ctors/dtors added for entry.
+  Triple T(M.getTargetTriple());
+  if (T.getEnvironment() != Triple::EnvironmentType::Library) {
+if (auto *GV = M.getNamedGlobal("llvm.global_ctors"))
+  GV->eraseFromParent();
+if (auto *GV = M.getNamedGlobal("llvm.global_dtors"))
+  GV->eraseFromParent();
+  }
 }


Index: clang/test/CodeGenHLSL/GlobalDestructors.hlsl
===
--- clang/test/CodeGenHLSL/GlobalDestructors.hlsl
+++ clang/test/CodeGenHLSL/GlobalDestructors.hlsl
@@ -1,5 +1,10 @@
-// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-compute -std=hlsl202x -S -emit-llvm -disable-llvm-passes %s -o - | FileCheck %s
-// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -std=hlsl202x -S -emit-llvm -disable-llvm-passes %s -o - | FileCheck %s --check-prefixes=CHECK
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-compute -std=hlsl202x -S -emit-llvm -disable-llvm-passes %s -o - | FileCheck %s --check-prefixes=CS,CHECK
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -std=hlsl202x -S -emit-llvm 

[clang] 2bdfece - [HLSL] Remove global ctor/dtor variable for non-lib profile.

2022-10-06 Thread Xiang Li via cfe-commits

Author: Xiang Li
Date: 2022-10-06T15:00:50-07:00
New Revision: 2bdfececef4330b3a6489cdb67c57eb771d5f9e4

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

LOG: [HLSL] Remove global ctor/dtor variable for non-lib profile.

After generated call for ctor/dtor for entry, global variable for ctor/dtor are 
useless.
Remove them for non-lib profiles.
Lib profile still need these in case export function used the global variable 
which require ctor/dtor.

Reviewed By: efriedma

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

Added: 


Modified: 
clang/lib/CodeGen/CGHLSLRuntime.cpp
clang/test/CodeGenHLSL/GlobalConstructorFunction.hlsl
clang/test/CodeGenHLSL/GlobalConstructorLib.hlsl
clang/test/CodeGenHLSL/GlobalConstructors.hlsl
clang/test/CodeGenHLSL/GlobalDestructors.hlsl

Removed: 




diff  --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp 
b/clang/lib/CodeGen/CGHLSLRuntime.cpp
index 20106ab664835..96a8f22aa877e 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.cpp
+++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp
@@ -212,4 +212,14 @@ void CGHLSLRuntime::generateGlobalCtorDtorCalls() {
 for (auto *Fn : DtorFns)
   B.CreateCall(FunctionCallee(Fn));
   }
+
+  // No need to keep global ctors/dtors for non-lib profile after call to
+  // ctors/dtors added for entry.
+  Triple T(M.getTargetTriple());
+  if (T.getEnvironment() != Triple::EnvironmentType::Library) {
+if (auto *GV = M.getNamedGlobal("llvm.global_ctors"))
+  GV->eraseFromParent();
+if (auto *GV = M.getNamedGlobal("llvm.global_dtors"))
+  GV->eraseFromParent();
+  }
 }

diff  --git a/clang/test/CodeGenHLSL/GlobalConstructorFunction.hlsl 
b/clang/test/CodeGenHLSL/GlobalConstructorFunction.hlsl
index db47c5c565805..d65dec4a1ddf4 100644
--- a/clang/test/CodeGenHLSL/GlobalConstructorFunction.hlsl
+++ b/clang/test/CodeGenHLSL/GlobalConstructorFunction.hlsl
@@ -17,6 +17,10 @@ __attribute__((destructor)) void call_me_last(void) {
 [numthreads(1,1,1)]
 void main(unsigned GI : SV_GroupIndex) {}
 
+// Make sure global variable for ctors/dtors removed.
+// CHECK-NOT:@llvm.global_ctors
+// CHECK-NOT:@llvm.global_dtors
+
 //CHECK: define void @main()
 //CHECK-NEXT: entry:
 //CHECK-NEXT:   call void @"?call_me_first@@YAXXZ"()

diff  --git a/clang/test/CodeGenHLSL/GlobalConstructorLib.hlsl 
b/clang/test/CodeGenHLSL/GlobalConstructorLib.hlsl
index 4a366946219b4..e7fe4e0c4caf7 100644
--- a/clang/test/CodeGenHLSL/GlobalConstructorLib.hlsl
+++ b/clang/test/CodeGenHLSL/GlobalConstructorLib.hlsl
@@ -1,5 +1,8 @@
 // RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -S -emit-llvm 
-disable-llvm-passes %s -o - | FileCheck %s
 
+// Make sure global variable for ctors exist for lib profile.
+// CHECK:@llvm.global_ctors
+
 RWBuffer Buffer;
 
 [shader("compute")]

diff  --git a/clang/test/CodeGenHLSL/GlobalConstructors.hlsl 
b/clang/test/CodeGenHLSL/GlobalConstructors.hlsl
index cb250766099d5..332302e1a8bb0 100644
--- a/clang/test/CodeGenHLSL/GlobalConstructors.hlsl
+++ b/clang/test/CodeGenHLSL/GlobalConstructors.hlsl
@@ -5,6 +5,9 @@ RWBuffer Buffer;
 [numthreads(1,1,1)]
 void main(unsigned GI : SV_GroupIndex) {}
 
+// Make sure global variable for ctors/dtors removed.
+// CHECK-NOT:@llvm.global_ctors
+// CHECK-NOT:@llvm.global_dtors
 //CHECK:  define void @main()
 //CHECK-NEXT: entry:
 //CHECK-NEXT:   call void @_GLOBAL__sub_I_GlobalConstructors.hlsl()

diff  --git a/clang/test/CodeGenHLSL/GlobalDestructors.hlsl 
b/clang/test/CodeGenHLSL/GlobalDestructors.hlsl
index 6d618ff18eb22..03505e3e46c4b 100644
--- a/clang/test/CodeGenHLSL/GlobalDestructors.hlsl
+++ b/clang/test/CodeGenHLSL/GlobalDestructors.hlsl
@@ -1,5 +1,10 @@
-// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-compute -std=hlsl202x -S 
-emit-llvm -disable-llvm-passes %s -o - | FileCheck %s
-// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -std=hlsl202x -S 
-emit-llvm -disable-llvm-passes %s -o - | FileCheck %s --check-prefixes=CHECK
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-compute -std=hlsl202x -S 
-emit-llvm -disable-llvm-passes %s -o - | FileCheck %s --check-prefixes=CS,CHECK
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -std=hlsl202x -S 
-emit-llvm -disable-llvm-passes %s -o - | FileCheck %s 
--check-prefixes=LIB,CHECK
+
+// Make sure global variable for dtors exist for lib profile.
+// LIB:@llvm.global_dtors
+// Make sure global variable for dtors removed for compute profile.
+// CS-NOT:llvm.global_dtors
 
 struct Tail {
   Tail() {
@@ -40,6 +45,9 @@ void main(unsigned GI : SV_GroupIndex) {
   Wag();
 }
 
+// Make sure global variable for ctors/dtors removed.
+// CHECK-NOT:@llvm.global_ctors
+// CHECK-NOT:@llvm.global_dtors
 //CHECK:  define void @main()
 //CHECK-NEXT: entry:
 //CHECK-NEXT:   call void 

[PATCH] D134668: [LTO][clang] Using Single Dash Consistently when Passing LTO Options

2022-10-06 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

Err since `-plugin-opt=` was used a lot of before this change, I think this is 
fine for consistency.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134668

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


[PATCH] D135389: [Clang] Emit a warning for ambiguous joined '-o' arguments

2022-10-06 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay accepted this revision.
MaskRay added inline comments.



Comment at: clang/test/Driver/unknown-arg.c:74
+
+// RUN: %clang -### --offload-arch=sm_70 -o ffload-device-only 
-Werror=unknown-argument %s

jhuber6 wrote:
> tra wrote:
> > jhuber6 wrote:
> > > tra wrote:
> > > > Has this patch been updated with incomplete changes? This RUN line 
> > > > seems to miss `2>&1 | FileCheck` and the check lines.
> > > I'm relying on the fact that `-Werror` will cause clang to return a 
> > > non-zero error code and make the test fail if any warnings show up.
> > Got it. I've missed that.
> You were somewhat right, I had `-###` which apparently makes clang return 0 
> even on an error. So thanks for making me double check.
Use `-###` `--implicit-check-not=warning:` instead of `-emit-llvm` which runs 
more than the driver.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135389

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


[PATCH] D135238: [clang] adds copy-constructible type-trait builtins

2022-10-06 Thread Jonathan Wakely via Phabricator via cfe-commits
jwakely added inline comments.



Comment at: clang/include/clang/Basic/TokenKinds.def:528
+TYPE_TRAIT_1(__is_nothrow_copy_constructible, IsNothrowCopyConstructible, 
KEYCXX)
+TYPE_TRAIT_1(__is_trivially_copy_constructible, IsTriviallyCopyConstructible, 
KEYCXX)
 TYPE_TRAIT_2(__reference_binds_to_temporary, ReferenceBindsToTemporary, KEYCXX)

cjdb wrote:
> ldionne wrote:
> > cjdb wrote:
> > > erichkeane wrote:
> > > > royjacobson wrote:
> > > > > erichkeane wrote:
> > > > > > cjdb wrote:
> > > > > > > erichkeane wrote:
> > > > > > > > So this one is a whole 'thing'.  The Clang definition of 
> > > > > > > > 'trivially copy constructible' is a few DRs behind.  We should 
> > > > > > > > probably discuss this with libcxx to make sure use of this 
> > > > > > > > wouldn't be broken.
> > > > > > > I'd prefer to get those DRs in before finalising D135238 and 
> > > > > > > subsequent ones. Do you know the DR numbers I should be looking 
> > > > > > > at, or should I just poke npaperbot?
> > > > > > Not off the top of my head, Aaron and I both poked at it at one 
> > > > > > point trying to get trivially constructible right at one point, but 
> > > > > > I think we both gave up due to the ABI/versioning concerns.
> > > > > Maybe DR1734? Although it's about the trivially copyable trait, not 
> > > > > trivially copy constructible. 
> > > > > 
> > > > Yeah, I think that was the DR, that number sounds familiar.
> > > The `__is_trivially_*` traits were, in part, what inspired the Great 
> > > Split of D116208. I could remove them for now and revisit once I rip my 
> > > hair out over these DRs, if that would substantially improve the chances 
> > > of these commits landing (other commentary notwithstanding).
> > I am not sure I see a problem with the "triviality" part of this -- we 
> > already use a compiler builtin for `std::is_trivially_constructible`, so I 
> > would expect either this patch is fine, or we already have a latent bug in 
> > libc++.
> > 
> > I think I can echo @philnik's comment about this not necessarily providing 
> > the biggest benefit since our implementation of 
> > `std::is_trivially_copy_constructible` is a fairly trivial wrapper on top 
> > of `__is_trivially_constructible`, but I wouldn't object to the patch on 
> > that basis. I think it would probably be possible to instead provide a set 
> > of basis builtin operations that we can then build all of the library type 
> > traits on top of -- that would provide the highest bang-for-our-buck ratio.
> > 
> > At the same time, there's something kind of enticing in the consistency of 
> > defining every single type trait as a builtin, without exception. If that's 
> > the end goal, I think that would also be neat and we'd likely regroup all 
> > of our type traits under a single header, since each of them would 
> > literally be a one liner.
> > 
> > There's also the question of whether GCC provides these builtins -- if they 
> > don't and if they don't have plans to, then we'd actually need to add 
> > complexity in libc++ to support both, which we would be unlikely to do 
> > given that there's probably not a huge compile-time performance benefit.
> > 
> > TLDR, I think the two questions that can help gauge how much interest there 
> > will be from libc++ to use this are:
> > 
> > 1. Is the plan to provide *all* the type traits as builtins?
> > 2. Will GCC implement them?
> > 
> > That being said, libc++ might not be the only potential user of these 
> > builtins, so I wouldn't necessarily make it a hard requirement to satisfy 
> > us.
> > 
> > I think I can echo @philnik's comment about this not necessarily providing 
> > the biggest benefit since our implementation of 
> > `std::is_trivially_copy_constructible` is a fairly trivial wrapper on top 
> > of `__is_trivially_constructible`, but I wouldn't object to the patch on 
> > that basis.
> 
> I haven't had time to do anything properly in the way of benchmarking, but 
> after looking at @philnik's quoted code, I see that I'd naively addressed 
> `__is_constructible(T, T const&)`, forgetting that `__add_lvalue_reference` 
> would've fixed that issue.
> 
> > 1. Is the plan to provide *all* the type traits as builtins?
> 
> Yes, with the possible exception of `enable_if` and `add_const` etc. (see 
> D116203 for why the qualifier ones aren't already in). The hardest ones will 
> probably be `common_type`, `common_reference`, `*invocable*`, and 
> `*swappable*`. The former two depend on technology that doesn't exist in 
> Clang yet, and the latter two are likely hard due there not being prior art.
> 
> > 2. Will GCC implement them?
> 
> @jwakely do you know if there can be cross-compiler synergy here?
> 
> 
Which traits are you asking about, just the 
__is_{,trivially,nothrow}_copy_constructible ones? Or all type traits?

Either way, I think the answer is no. We already use 
__is_{,trivially,nothrow}_constructible for the copy-constructible traits, and 
it 

[PATCH] D135405: fix handling of braced-init temporaries for modernize-use-emplace

2022-10-06 Thread Peter Wolf via Phabricator via cfe-commits
BigPeet updated this revision to Diff 465888.
BigPeet added a comment.

- update comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135405

Files:
  clang-tools-extra/clang-tidy/modernize/UseEmplaceCheck.cpp
  clang-tools-extra/test/clang-tidy/checkers/modernize/use-emplace.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/modernize/use-emplace.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/modernize/use-emplace.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/modernize/use-emplace.cpp
@@ -1170,3 +1170,167 @@
   };
   v.emplace_back(std::make_pair(Something(), 2));
 }
+
+struct InnerType {
+  InnerType();
+  InnerType(char const*);
+};
+
+struct NonTrivialNoCtor {
+  InnerType it;
+};
+
+struct NonTrivialWithVector {
+  std::vector it;
+};
+
+struct NonTrivialWithCtor {
+  NonTrivialWithCtor();
+  NonTrivialWithCtor(std::vector const&);
+};
+
+void testBracedInitTemporaries() {
+  std::vector v1;
+
+  v1.push_back(NonTrivialNoCtor());
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: use emplace_back
+  // CHECK-FIXES: v1.emplace_back();
+  v1.push_back(NonTrivialNoCtor{});
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: use emplace_back
+  // CHECK-FIXES: v1.emplace_back();
+  v1.push_back({});
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: use emplace_back
+  // CHECK-FIXES: v1.emplace_back();
+  v1.push_back(NonTrivialNoCtor{InnerType{}});
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: use emplace_back
+  // CHECK-FIXES: v1.emplace_back();
+  v1.push_back({InnerType{}});
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: use emplace_back
+  // CHECK-FIXES: v1.emplace_back();
+  v1.push_back(NonTrivialNoCtor{InnerType()});
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: use emplace_back
+  // CHECK-FIXES: v1.emplace_back();
+  v1.push_back({InnerType()});
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: use emplace_back
+  // CHECK-FIXES: v1.emplace_back();
+  v1.push_back({{}});
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: use emplace_back
+  // CHECK-FIXES: v1.emplace_back();
+
+  v1.emplace_back(NonTrivialNoCtor());
+  // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: unnecessary temporary object created while calling emplace_back
+  // CHECK-FIXES: v1.emplace_back();
+  v1.emplace_back(NonTrivialNoCtor{});
+  // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: unnecessary temporary object created while calling emplace_back
+  // CHECK-FIXES: v1.emplace_back();
+  v1.emplace_back(NonTrivialNoCtor{InnerType{}});
+  // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: unnecessary temporary object created while calling emplace_back
+  // CHECK-FIXES: v1.emplace_back();
+  v1.emplace_back(NonTrivialNoCtor{{}});
+  // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: unnecessary temporary object created while calling emplace_back
+  // CHECK-FIXES: v1.emplace_back();
+
+  // These should not be noticed or fixed; after the correction, the code won't
+  // compile.
+  v1.push_back(NonTrivialNoCtor{""});
+  v1.push_back({""});
+  v1.push_back(NonTrivialNoCtor{InnerType{""}});
+  v1.push_back({InnerType{""}});
+  v1.emplace_back(NonTrivialNoCtor{""});
+
+  std::vector v2;
+
+  v2.push_back(NonTrivialWithVector());
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: use emplace_back
+  // CHECK-FIXES: v2.emplace_back();
+  v2.push_back(NonTrivialWithVector{});
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: use emplace_back
+  // CHECK-FIXES: v2.emplace_back();
+  v2.push_back({});
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: use emplace_back
+  // CHECK-FIXES: v2.emplace_back();
+  v2.push_back(NonTrivialWithVector{std::vector{}});
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: use emplace_back
+  // CHECK-FIXES: v2.emplace_back();
+  v2.push_back({std::vector{}});
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: use emplace_back
+  // CHECK-FIXES: v2.emplace_back();
+  v2.push_back(NonTrivialWithVector{std::vector()});
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: use emplace_back
+  // CHECK-FIXES: v2.emplace_back();
+  v2.push_back({std::vector()});
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: use emplace_back
+  // CHECK-FIXES: v2.emplace_back();
+  v2.push_back({{}});
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: use emplace_back
+  // CHECK-FIXES: v2.emplace_back();
+
+  v2.emplace_back(NonTrivialWithVector());
+  // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: unnecessary temporary object created while calling emplace_back
+  // CHECK-FIXES: v2.emplace_back();
+  v2.emplace_back(NonTrivialWithVector{});
+  // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: unnecessary temporary object created while calling emplace_back
+  // CHECK-FIXES: v2.emplace_back();
+  v2.emplace_back(NonTrivialWithVector{std::vector{}});
+  // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: unnecessary temporary object created while calling emplace_back
+  // CHECK-FIXES: v2.emplace_back();
+  

[PATCH] D135091: Create storage for the `_cmd` argument to the helper function for generated getters/setters of `direct` Objective-C properties.

2022-10-06 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi added a comment.

LGTM but waiting on Akira would be nice imho.




Comment at: clang/lib/CodeGen/CGObjC.cpp:1192
 // corresponding gcc code.
-llvm::Value *cmd =
-  Builder.CreateLoad(GetAddrOfLocalVar(getterMethod->getCmdDecl()), "cmd");
+if (getterMethod->isDirectMethod()) {
+  // Direct methods no longer have a `_cmd` argument, so storage must be

Could this entire code sequence be moved to a helper or helper method? I think 
it could be good if the _cmd argument emission and the associated code comments 
were only written once. 



Comment at: clang/lib/CodeGen/CGObjC.cpp:1485
 //   , ).
-llvm::Value *cmd =
-  Builder.CreateLoad(GetAddrOfLocalVar(setterMethod->getCmdDecl()));
-llvm::Value *self =
-  Builder.CreateBitCast(LoadObjCSelf(), VoidPtrTy);
+if (setterMethod->isDirectMethod()) {
+  // Direct methods no longer have a `_cmd` argument, so storage must be

Ditto


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

https://reviews.llvm.org/D135091

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


[PATCH] D135405: fix handling of braced-init temporaries for modernize-use-emplace

2022-10-06 Thread Peter Wolf via Phabricator via cfe-commits
BigPeet created this revision.
Herald added a subscriber: carlosgalvezp.
Herald added a project: All.
BigPeet requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

Addresses https://github.com/llvm/llvm-project/issues/55870


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D135405

Files:
  clang-tools-extra/clang-tidy/modernize/UseEmplaceCheck.cpp
  clang-tools-extra/test/clang-tidy/checkers/modernize/use-emplace.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/modernize/use-emplace.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/modernize/use-emplace.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/modernize/use-emplace.cpp
@@ -1170,3 +1170,167 @@
   };
   v.emplace_back(std::make_pair(Something(), 2));
 }
+
+struct InnerType {
+  InnerType();
+  InnerType(char const*);
+};
+
+struct NonTrivialNoCtor {
+  InnerType it;
+};
+
+struct NonTrivialWithVector {
+  std::vector it;
+};
+
+struct NonTrivialWithCtor {
+  NonTrivialWithCtor();
+  NonTrivialWithCtor(std::vector const&);
+};
+
+void testBracedInitTemporaries() {
+  std::vector v1;
+
+  v1.push_back(NonTrivialNoCtor());
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: use emplace_back
+  // CHECK-FIXES: v1.emplace_back();
+  v1.push_back(NonTrivialNoCtor{});
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: use emplace_back
+  // CHECK-FIXES: v1.emplace_back();
+  v1.push_back({});
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: use emplace_back
+  // CHECK-FIXES: v1.emplace_back();
+  v1.push_back(NonTrivialNoCtor{InnerType{}});
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: use emplace_back
+  // CHECK-FIXES: v1.emplace_back();
+  v1.push_back({InnerType{}});
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: use emplace_back
+  // CHECK-FIXES: v1.emplace_back();
+  v1.push_back(NonTrivialNoCtor{InnerType()});
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: use emplace_back
+  // CHECK-FIXES: v1.emplace_back();
+  v1.push_back({InnerType()});
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: use emplace_back
+  // CHECK-FIXES: v1.emplace_back();
+  v1.push_back({{}});
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: use emplace_back
+  // CHECK-FIXES: v1.emplace_back();
+
+  v1.emplace_back(NonTrivialNoCtor());
+  // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: unnecessary temporary object created while calling emplace_back
+  // CHECK-FIXES: v1.emplace_back();
+  v1.emplace_back(NonTrivialNoCtor{});
+  // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: unnecessary temporary object created while calling emplace_back
+  // CHECK-FIXES: v1.emplace_back();
+  v1.emplace_back(NonTrivialNoCtor{InnerType{}});
+  // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: unnecessary temporary object created while calling emplace_back
+  // CHECK-FIXES: v1.emplace_back();
+  v1.emplace_back(NonTrivialNoCtor{{}});
+  // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: unnecessary temporary object created while calling emplace_back
+  // CHECK-FIXES: v1.emplace_back();
+
+  // These should not be noticed or fixed; after the correction, the code won't
+  // compile.
+  v1.push_back(NonTrivialNoCtor{""});
+  v1.push_back({""});
+  v1.push_back(NonTrivialNoCtor{InnerType{""}});
+  v1.push_back({InnerType{""}});
+  v1.emplace_back(NonTrivialNoCtor{""});
+
+  std::vector v2;
+
+  v2.push_back(NonTrivialWithVector());
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: use emplace_back
+  // CHECK-FIXES: v2.emplace_back();
+  v2.push_back(NonTrivialWithVector{});
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: use emplace_back
+  // CHECK-FIXES: v2.emplace_back();
+  v2.push_back({});
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: use emplace_back
+  // CHECK-FIXES: v2.emplace_back();
+  v2.push_back(NonTrivialWithVector{std::vector{}});
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: use emplace_back
+  // CHECK-FIXES: v2.emplace_back();
+  v2.push_back({std::vector{}});
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: use emplace_back
+  // CHECK-FIXES: v2.emplace_back();
+  v2.push_back(NonTrivialWithVector{std::vector()});
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: use emplace_back
+  // CHECK-FIXES: v2.emplace_back();
+  v2.push_back({std::vector()});
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: use emplace_back
+  // CHECK-FIXES: v2.emplace_back();
+  v2.push_back({{}});
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: use emplace_back
+  // CHECK-FIXES: v2.emplace_back();
+
+  v2.emplace_back(NonTrivialWithVector());
+  // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: unnecessary temporary object created while calling emplace_back
+  // CHECK-FIXES: v2.emplace_back();
+  v2.emplace_back(NonTrivialWithVector{});
+  // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: unnecessary temporary object created while calling emplace_back
+  // CHECK-FIXES: v2.emplace_back();
+  v2.emplace_back(NonTrivialWithVector{std::vector{}});
+  // CHECK-MESSAGES: :[[@LINE-1]]:19: 

[PATCH] D135091: Create storage for the `_cmd` argument to the helper function for generated getters/setters of `direct` Objective-C properties.

2022-10-06 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi added a comment.

@ahatanak how does this diff look to you?


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

https://reviews.llvm.org/D135091

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


[PATCH] D135389: [Clang] Emit a warning for ambiguous joined '-o' arguments

2022-10-06 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 added inline comments.



Comment at: clang/test/Driver/unknown-arg.c:74
+
+// RUN: %clang -### --offload-arch=sm_70 -o ffload-device-only 
-Werror=unknown-argument %s

tra wrote:
> jhuber6 wrote:
> > tra wrote:
> > > Has this patch been updated with incomplete changes? This RUN line seems 
> > > to miss `2>&1 | FileCheck` and the check lines.
> > I'm relying on the fact that `-Werror` will cause clang to return a 
> > non-zero error code and make the test fail if any warnings show up.
> Got it. I've missed that.
You were somewhat right, I had `-###` which apparently makes clang return 0 
even on an error. So thanks for making me double check.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135389

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


[PATCH] D135389: [Clang] Emit a warning for ambiguous joined '-o' arguments

2022-10-06 Thread Artem Belevich via Phabricator via cfe-commits
tra accepted this revision.
tra added inline comments.



Comment at: clang/test/Driver/unknown-arg.c:74
+
+// RUN: %clang -### --offload-arch=sm_70 -o ffload-device-only 
-Werror=unknown-argument %s

jhuber6 wrote:
> tra wrote:
> > Has this patch been updated with incomplete changes? This RUN line seems to 
> > miss `2>&1 | FileCheck` and the check lines.
> I'm relying on the fact that `-Werror` will cause clang to return a non-zero 
> error code and make the test fail if any warnings show up.
Got it. I've missed that.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135389

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


[PATCH] D135389: [Clang] Emit a warning for ambiguous joined '-o' arguments

2022-10-06 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 updated this revision to Diff 465883.
jhuber6 added a comment.

Apparently `-###` prevents `clang` from returning a non-zero error code. Fixing.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135389

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/lib/Driver/Driver.cpp
  clang/test/Driver/unknown-arg.c


Index: clang/test/Driver/unknown-arg.c
===
--- clang/test/Driver/unknown-arg.c
+++ clang/test/Driver/unknown-arg.c
@@ -64,3 +64,11 @@
 // RUN: %clang -S %s -o %t.s  -Wunknown-to-clang-option 2>&1 | FileCheck 
--check-prefix=IGNORED %s
 
 // IGNORED: warning: unknown warning option '-Wunknown-to-clang-option'
+
+// RUN: %clang -### -offload-arch=sm_70 --offload-arch=sm_70 
-offload-device-only -o ffload-device-only \
+// RUN:   -output -o foo %s 2>&1 | FileCheck --check-prefix=O-WARN %s
+//  O-WARN: warning: joined argument treated as '-o ffload-arch=sm_70'; 
did you mean '--offload-arch=sm_70'?
+// O-WARN-NEXT: warning: joined argument treated as '-o ffload-device-only'; 
did you mean '--offload-device-only'?
+// O-WARN-NEXT: warning: joined argument treated as '-o utput'; did you mean 
'--output'?
+
+// RUN: %clang --offload-arch=sm_70 -o ffload-device-only 
-Werror=unknown-argument -S -emit-llvm %s
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -327,6 +327,19 @@
  DiagnosticsEngine::Warning;
   }
 
+  for (const Arg *A : Args.filtered(options::OPT_o)) {
+if (ArgStrings[A->getIndex()] == A->getSpelling())
+  continue;
+
+// Warn on joined arguments that are similar to a long argument.
+std::string ArgString = ArgStrings[A->getIndex()];
+std::string Nearest;
+if (getOpts().findNearest("-" + ArgString, Nearest, IncludedFlagsBitmask,
+  ExcludedFlagsBitmask) == 0)
+  Diags.Report(diag::warn_drv_potentially_misspelled_joined_argument)
+  << A->getAsString(Args) << Nearest;
+  }
+
   return Args;
 }
 
Index: clang/include/clang/Basic/DiagnosticDriverKinds.td
===
--- clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -253,6 +253,9 @@
   "support for '/Yc' with more than one source file not implemented yet; flag 
ignored">,
   InGroup;
 
+def warn_drv_potentially_misspelled_joined_argument : Warning<
+  "joined argument treated as '%0'; did you mean '%1'?">, 
InGroup;
+
 def err_drv_invalid_value : Error<"invalid value '%1' in '%0'">;
 def err_drv_invalid_int_value : Error<"invalid integral value '%1' in '%0'">;
 def err_drv_invalid_value_with_suggestion : Error<


Index: clang/test/Driver/unknown-arg.c
===
--- clang/test/Driver/unknown-arg.c
+++ clang/test/Driver/unknown-arg.c
@@ -64,3 +64,11 @@
 // RUN: %clang -S %s -o %t.s  -Wunknown-to-clang-option 2>&1 | FileCheck --check-prefix=IGNORED %s
 
 // IGNORED: warning: unknown warning option '-Wunknown-to-clang-option'
+
+// RUN: %clang -### -offload-arch=sm_70 --offload-arch=sm_70 -offload-device-only -o ffload-device-only \
+// RUN:   -output -o foo %s 2>&1 | FileCheck --check-prefix=O-WARN %s
+//  O-WARN: warning: joined argument treated as '-o ffload-arch=sm_70'; did you mean '--offload-arch=sm_70'?
+// O-WARN-NEXT: warning: joined argument treated as '-o ffload-device-only'; did you mean '--offload-device-only'?
+// O-WARN-NEXT: warning: joined argument treated as '-o utput'; did you mean '--output'?
+
+// RUN: %clang --offload-arch=sm_70 -o ffload-device-only -Werror=unknown-argument -S -emit-llvm %s
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -327,6 +327,19 @@
  DiagnosticsEngine::Warning;
   }
 
+  for (const Arg *A : Args.filtered(options::OPT_o)) {
+if (ArgStrings[A->getIndex()] == A->getSpelling())
+  continue;
+
+// Warn on joined arguments that are similar to a long argument.
+std::string ArgString = ArgStrings[A->getIndex()];
+std::string Nearest;
+if (getOpts().findNearest("-" + ArgString, Nearest, IncludedFlagsBitmask,
+  ExcludedFlagsBitmask) == 0)
+  Diags.Report(diag::warn_drv_potentially_misspelled_joined_argument)
+  << A->getAsString(Args) << Nearest;
+  }
+
   return Args;
 }
 
Index: clang/include/clang/Basic/DiagnosticDriverKinds.td
===
--- clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -253,6 +253,9 @@
   "support for '/Yc' with more than 

[PATCH] D135389: [Clang] Emit a warning for ambiguous joined '-o' arguments

2022-10-06 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 added inline comments.



Comment at: clang/test/Driver/unknown-arg.c:74
+
+// RUN: %clang -### --offload-arch=sm_70 -o ffload-device-only 
-Werror=unknown-argument %s

tra wrote:
> Has this patch been updated with incomplete changes? This RUN line seems to 
> miss `2>&1 | FileCheck` and the check lines.
I'm relying on the fact that `-Werror` will cause clang to return a non-zero 
error code and make the test fail if any warnings show up.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135389

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


[PATCH] D135389: [Clang] Emit a warning for ambiguous joined '-o' arguments

2022-10-06 Thread Artem Belevich via Phabricator via cfe-commits
tra added inline comments.



Comment at: clang/test/Driver/unknown-arg.c:74
+
+// RUN: %clang -### --offload-arch=sm_70 -o ffload-device-only 
-Werror=unknown-argument %s

Has this patch been updated with incomplete changes? This RUN line seems to 
miss `2>&1 | FileCheck` and the check lines.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135389

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


[PATCH] D135238: [clang] adds copy-constructible type-trait builtins

2022-10-06 Thread Christopher Di Bella via Phabricator via cfe-commits
cjdb added a subscriber: jwakely.
cjdb added inline comments.



Comment at: clang/include/clang/Basic/TokenKinds.def:528
+TYPE_TRAIT_1(__is_nothrow_copy_constructible, IsNothrowCopyConstructible, 
KEYCXX)
+TYPE_TRAIT_1(__is_trivially_copy_constructible, IsTriviallyCopyConstructible, 
KEYCXX)
 TYPE_TRAIT_2(__reference_binds_to_temporary, ReferenceBindsToTemporary, KEYCXX)

ldionne wrote:
> cjdb wrote:
> > erichkeane wrote:
> > > royjacobson wrote:
> > > > erichkeane wrote:
> > > > > cjdb wrote:
> > > > > > erichkeane wrote:
> > > > > > > So this one is a whole 'thing'.  The Clang definition of 
> > > > > > > 'trivially copy constructible' is a few DRs behind.  We should 
> > > > > > > probably discuss this with libcxx to make sure use of this 
> > > > > > > wouldn't be broken.
> > > > > > I'd prefer to get those DRs in before finalising D135238 and 
> > > > > > subsequent ones. Do you know the DR numbers I should be looking at, 
> > > > > > or should I just poke npaperbot?
> > > > > Not off the top of my head, Aaron and I both poked at it at one point 
> > > > > trying to get trivially constructible right at one point, but I think 
> > > > > we both gave up due to the ABI/versioning concerns.
> > > > Maybe DR1734? Although it's about the trivially copyable trait, not 
> > > > trivially copy constructible. 
> > > > 
> > > Yeah, I think that was the DR, that number sounds familiar.
> > The `__is_trivially_*` traits were, in part, what inspired the Great Split 
> > of D116208. I could remove them for now and revisit once I rip my hair out 
> > over these DRs, if that would substantially improve the chances of these 
> > commits landing (other commentary notwithstanding).
> I am not sure I see a problem with the "triviality" part of this -- we 
> already use a compiler builtin for `std::is_trivially_constructible`, so I 
> would expect either this patch is fine, or we already have a latent bug in 
> libc++.
> 
> I think I can echo @philnik's comment about this not necessarily providing 
> the biggest benefit since our implementation of 
> `std::is_trivially_copy_constructible` is a fairly trivial wrapper on top of 
> `__is_trivially_constructible`, but I wouldn't object to the patch on that 
> basis. I think it would probably be possible to instead provide a set of 
> basis builtin operations that we can then build all of the library type 
> traits on top of -- that would provide the highest bang-for-our-buck ratio.
> 
> At the same time, there's something kind of enticing in the consistency of 
> defining every single type trait as a builtin, without exception. If that's 
> the end goal, I think that would also be neat and we'd likely regroup all of 
> our type traits under a single header, since each of them would literally be 
> a one liner.
> 
> There's also the question of whether GCC provides these builtins -- if they 
> don't and if they don't have plans to, then we'd actually need to add 
> complexity in libc++ to support both, which we would be unlikely to do given 
> that there's probably not a huge compile-time performance benefit.
> 
> TLDR, I think the two questions that can help gauge how much interest there 
> will be from libc++ to use this are:
> 
> 1. Is the plan to provide *all* the type traits as builtins?
> 2. Will GCC implement them?
> 
> That being said, libc++ might not be the only potential user of these 
> builtins, so I wouldn't necessarily make it a hard requirement to satisfy us.
> 
> I think I can echo @philnik's comment about this not necessarily providing 
> the biggest benefit since our implementation of 
> `std::is_trivially_copy_constructible` is a fairly trivial wrapper on top of 
> `__is_trivially_constructible`, but I wouldn't object to the patch on that 
> basis.

I haven't had time to do anything properly in the way of benchmarking, but 
after looking at @philnik's quoted code, I see that I'd naively addressed 
`__is_constructible(T, T const&)`, forgetting that `__add_lvalue_reference` 
would've fixed that issue.

> 1. Is the plan to provide *all* the type traits as builtins?

Yes, with the possible exception of `enable_if` and `add_const` etc. (see 
D116203 for why the qualifier ones aren't already in). The hardest ones will 
probably be `common_type`, `common_reference`, `*invocable*`, and 
`*swappable*`. The former two depend on technology that doesn't exist in Clang 
yet, and the latter two are likely hard due there not being prior art.

> 2. Will GCC implement them?

@jwakely do you know if there can be cross-compiler synergy here?




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135238

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


[PATCH] D135400: [clang][LTO] Remove the use of `--` for arange option

2022-10-06 Thread Qiongsi Wu via Phabricator via cfe-commits
qiongsiwu1 added a comment.

In D135400#3841321 , @MaskRay wrote:

> I missed https://reviews.llvm.org/D134668 . See my comment there I don't 
> think the change is necessary.

Thanks for the comment! I posted a reply there.


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

https://reviews.llvm.org/D135400

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


[PATCH] D135404: [clang-tidy] Add a checker for converting into C++17 variable template type traits

2022-10-06 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson created this revision.
royjacobson added reviewers: njames93, ymandel, alexfh.
Herald added subscribers: carlosgalvezp, xazax.hun.
Herald added a project: All.
royjacobson requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

This adds a clang-tidy checker that can transform C++11-style type traits into 
C++17-style
variable templates. Variable templates can compile faster because they can be 
implemented
without instantiating classes.

I'm not very familiar with clang matchers; There's probably a better way to do 
what I
want than regex + hacky type checking, so suggestions are very welcome.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D135404

Files:
  clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
  clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
  clang-tools-extra/clang-tidy/modernize/TypeTraitsCheck.cpp
  clang-tools-extra/clang-tidy/modernize/TypeTraitsCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/docs/clang-tidy/checks/modernize/type-traits.rst
  clang-tools-extra/test/clang-tidy/checkers/modernize/type-traits.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/modernize/type-traits.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/modernize/type-traits.cpp
@@ -0,0 +1,49 @@
+// RUN: %check_clang_tidy -std=c++17-or-later %s modernize-type-traits %t
+
+namespace std {
+
+template 
+struct integral_constant {
+static constexpr inline T value = x;
+};
+
+template 
+struct is_same : integral_constant {};
+
+template 
+struct is_trivially_default_constructible : integral_constant {};
+
+template 
+struct alignment_of : integral_constant {};
+
+}
+
+
+template 
+void f() {
+auto x = std::is_same::value;
+auto y = std::is_trivially_default_constructible::value;
+auto z = std::alignment_of::value;
+
+// CHECK-FIXES:  auto x = std::is_same_v;
+// CHECK-FIXES-NEXT: auto y = std::is_trivially_default_constructible_v;
+// CHECK-FIXES-NEXT: auto z = std::alignment_of_v;
+// Test that we don't get this twice or something weird like that because
+// we're in a dependant context.
+// CHECK-FIXES-NOT:  auto x = std::is_same_v;
+}
+
+void g() {
+f();
+f();
+}
+
+void h() {
+auto x = std::is_same::value;
+auto y = std::is_trivially_default_constructible::value;
+auto z = std::alignment_of::value;
+// CHECK-FIXES: auto x = std::is_same_v;
+// CHECK-FIXES-NEXT: auto y = std::is_trivially_default_constructible_v;
+// CHECK-FIXES-NEXT: auto z = std::alignment_of_v;
+
+}
Index: clang-tools-extra/docs/clang-tidy/checks/modernize/type-traits.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/modernize/type-traits.rst
@@ -0,0 +1,33 @@
+.. title:: clang-tidy - modernize-type-traits
+
+modernize-type-traits
+=
+
+
+Convert type traits from the form ``trait<...>::value`` into ``trait_v<...>``
+The template variable traits from C++17 can improve compile times, as in
+modern library implementations they don't instantiate structs.
+
+For example, this:
+
+.. code-block:: c++
+
+  std::is_same::value
+  std::is_integral::value
+
+is replaced by:
+
+.. code-block:: c++
+
+  std::is_same_v
+  std::is_integral_v
+
+Options
+---
+
+.. option:: ValueTypeTraits
+
+Specifies a list of type traits which are used with a static ``::value``
+member for metaprogramming instead of the regular one of traits available
+in the STL. This check assumes that a matching version exists with the
+same name and a ``_v`` suffix.
\ No newline at end of file
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -275,6 +275,7 @@
`modernize-replace-random-shuffle `_, "Yes"
`modernize-return-braced-init-list `_, "Yes"
`modernize-shrink-to-fit `_, "Yes"
+   `modernize-type-traits `_, "Yes"
`modernize-unary-static-assert `_, "Yes"
`modernize-use-auto `_, "Yes"
`modernize-use-bool-literals `_, "Yes"
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -110,6 +110,13 @@
 
   Warns when a struct or class uses const or reference (lvalue or rvalue) data members.
 
+- New :doc:`modernize-type-traits
+  ` check.
+
+  Finds usages of C++11 style type traits like ``std::is_same<...>::value`` and replaces
+  them with the C++17 variable template ``std::is_same_v<...>``. This transformation can
+  help reduce compile times.
+
 New check aliases
 ^
 
Index: 

[PATCH] D135389: [Clang] Emit a warning for ambiguous joined '-o' arguments

2022-10-06 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 updated this revision to Diff 465876.
jhuber6 marked an inline comment as done.
jhuber6 added a comment.

Changing test to just check that we emit to warnings in a separate run line.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135389

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/lib/Driver/Driver.cpp
  clang/test/Driver/unknown-arg.c


Index: clang/test/Driver/unknown-arg.c
===
--- clang/test/Driver/unknown-arg.c
+++ clang/test/Driver/unknown-arg.c
@@ -64,3 +64,11 @@
 // RUN: %clang -S %s -o %t.s  -Wunknown-to-clang-option 2>&1 | FileCheck 
--check-prefix=IGNORED %s
 
 // IGNORED: warning: unknown warning option '-Wunknown-to-clang-option'
+
+// RUN: %clang -### -offload-arch=sm_70 --offload-arch=sm_70 
-offload-device-only -o ffload-device-only \
+// RUN:   -output -o foo %s 2>&1 | FileCheck --check-prefix=O-WARN %s
+//  O-WARN: warning: joined argument treated as '-o ffload-arch=sm_70'; 
did you mean '--offload-arch=sm_70'?
+// O-WARN-NEXT: warning: joined argument treated as '-o ffload-device-only'; 
did you mean '--offload-device-only'?
+// O-WARN-NEXT: warning: joined argument treated as '-o utput'; did you mean 
'--output'?
+
+// RUN: %clang -### --offload-arch=sm_70 -o ffload-device-only 
-Werror=unknown-argument %s
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -327,6 +327,19 @@
  DiagnosticsEngine::Warning;
   }
 
+  for (const Arg *A : Args.filtered(options::OPT_o)) {
+if (ArgStrings[A->getIndex()] == A->getSpelling())
+  continue;
+
+// Warn on joined arguments that are similar to a long argument.
+std::string ArgString = ArgStrings[A->getIndex()];
+std::string Nearest;
+if (getOpts().findNearest("-" + ArgString, Nearest, IncludedFlagsBitmask,
+  ExcludedFlagsBitmask) == 0)
+  Diags.Report(diag::warn_drv_potentially_misspelled_joined_argument)
+  << A->getAsString(Args) << Nearest;
+  }
+
   return Args;
 }
 
Index: clang/include/clang/Basic/DiagnosticDriverKinds.td
===
--- clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -253,6 +253,9 @@
   "support for '/Yc' with more than one source file not implemented yet; flag 
ignored">,
   InGroup;
 
+def warn_drv_potentially_misspelled_joined_argument : Warning<
+  "joined argument treated as '%0'; did you mean '%1'?">, 
InGroup;
+
 def err_drv_invalid_value : Error<"invalid value '%1' in '%0'">;
 def err_drv_invalid_int_value : Error<"invalid integral value '%1' in '%0'">;
 def err_drv_invalid_value_with_suggestion : Error<


Index: clang/test/Driver/unknown-arg.c
===
--- clang/test/Driver/unknown-arg.c
+++ clang/test/Driver/unknown-arg.c
@@ -64,3 +64,11 @@
 // RUN: %clang -S %s -o %t.s  -Wunknown-to-clang-option 2>&1 | FileCheck --check-prefix=IGNORED %s
 
 // IGNORED: warning: unknown warning option '-Wunknown-to-clang-option'
+
+// RUN: %clang -### -offload-arch=sm_70 --offload-arch=sm_70 -offload-device-only -o ffload-device-only \
+// RUN:   -output -o foo %s 2>&1 | FileCheck --check-prefix=O-WARN %s
+//  O-WARN: warning: joined argument treated as '-o ffload-arch=sm_70'; did you mean '--offload-arch=sm_70'?
+// O-WARN-NEXT: warning: joined argument treated as '-o ffload-device-only'; did you mean '--offload-device-only'?
+// O-WARN-NEXT: warning: joined argument treated as '-o utput'; did you mean '--output'?
+
+// RUN: %clang -### --offload-arch=sm_70 -o ffload-device-only -Werror=unknown-argument %s
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -327,6 +327,19 @@
  DiagnosticsEngine::Warning;
   }
 
+  for (const Arg *A : Args.filtered(options::OPT_o)) {
+if (ArgStrings[A->getIndex()] == A->getSpelling())
+  continue;
+
+// Warn on joined arguments that are similar to a long argument.
+std::string ArgString = ArgStrings[A->getIndex()];
+std::string Nearest;
+if (getOpts().findNearest("-" + ArgString, Nearest, IncludedFlagsBitmask,
+  ExcludedFlagsBitmask) == 0)
+  Diags.Report(diag::warn_drv_potentially_misspelled_joined_argument)
+  << A->getAsString(Args) << Nearest;
+  }
+
   return Args;
 }
 
Index: clang/include/clang/Basic/DiagnosticDriverKinds.td
===
--- clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -253,6 +253,9 @@
   "support for 

[PATCH] D134668: [LTO][clang] Using Single Dash Consistently when Passing LTO Options

2022-10-06 Thread Qiongsi Wu via Phabricator via cfe-commits
qiongsiwu1 added a comment.

In D134668#3841312 , @MaskRay wrote:

> I think I want to revert this change. `--plugin-opt=` is entirely fine with 
> lld and GNU gold/ld... And generally the double-dash long options are 
> preferred.

Sure. What we are aiming at is using single or double dashes consistently, so 
that when the AIX plugin prefix is introduced, we don't deal with arbitrary one 
or two dashes. I can work on a patch to change all `-plugin-opt=` to 
`--plugin-opt=`. How does having two dashes consistently sound?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134668

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


[PATCH] D135091: Create storage for the `_cmd` argument to the helper function for generated getters/setters of `direct` Objective-C properties.

2022-10-06 Thread Stephane Moore via Phabricator via cfe-commits
stephanemoore accepted this revision.
stephanemoore added inline comments.



Comment at: clang/lib/CodeGen/CGObjC.cpp:1194-1196
+  // emitted for it to be passed to the property helper. Since the `_cmd`
+  // argument was never being initialized by the caller before, still pass
+  // an uninitialized/undefined value here.

Thanks for matching the previous behavior 



Comment at: clang/lib/CodeGen/CGObjC.cpp:1493
+llvm::Value *cmd = 
Builder.CreateLoad(GetAddrOfLocalVar(setterMethod->getCmdDecl()),
+   "cmd");
+llvm::Value *self = Builder.CreateBitCast(LoadObjCSelf(), VoidPtrTy);

Previously this was using the default "" for the `Name` instead of "cmd".

I can't think of why it would intentionally want to use "". Using "cmd" is 
consistent with the codegen for the getter (now and before) so I don't disagree 
with using "cmd" for the name here.



Comment at: clang/lib/CodeGen/CGObjC.cpp:1494
+   "cmd");
+llvm::Value *self = Builder.CreateBitCast(LoadObjCSelf(), VoidPtrTy);
 llvm::Value *ivarOffset =

Strictly speaking, I think we can leave this line untouched now?


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

https://reviews.llvm.org/D135091

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


[PATCH] D135374: [OpenMP][AMDGPU] Add 'uniform-work-group' attribute to OpenMP kernels

2022-10-06 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert accepted this revision.
jdoerfert added a comment.
This revision is now accepted and ready to land.

LG, add a TODO to move the code.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135374

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


[PATCH] D135400: [clang][LTO] Remove the use of `--` for arange option

2022-10-06 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

I missed https://reviews.llvm.org/D134668 . See my comment there I don't think 
the change is necessary.


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

https://reviews.llvm.org/D135400

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


[PATCH] D134668: [LTO][clang] Using Single Dash Consistently when Passing LTO Options

2022-10-06 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

I think I want to revert this change. `--plugin-opt=` is entirely fine with lld 
and GNU gold/ld... And generally the double-dash long options are preferred.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134668

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


[PATCH] D135400: [clang][LTO] Remove the use of `--` for arange option

2022-10-06 Thread Qiongsi Wu via Phabricator via cfe-commits
qiongsiwu1 updated this revision to Diff 465872.
qiongsiwu1 added a comment.

Fix a patch upload error.


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

https://reviews.llvm.org/D135400

Files:
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/test/Driver/debug-options-aranges.c


Index: clang/test/Driver/debug-options-aranges.c
===
--- clang/test/Driver/debug-options-aranges.c
+++ clang/test/Driver/debug-options-aranges.c
@@ -3,4 +3,4 @@
 /// Check that the linker plugin will get -generate-arange-section.
 // RUN: %clang -### -g --target=x86_64-linux -flto  -gdwarf-aranges %s 
2>&1 | FileCheck %s
 // RUN: %clang -### -g --target=x86_64-linux -flto=thin -gdwarf-aranges %s 
2>&1 | FileCheck %s
-// CHECK: --plugin-opt=-generate-arange-section
+// CHECK: -plugin-opt=-generate-arange-section
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -514,7 +514,7 @@
   // the way out.
   if (Args.hasArg(options::OPT_gdwarf_aranges)) {
 CmdArgs.push_back(
-Args.MakeArgString("--plugin-opt=-generate-arange-section"));
+Args.MakeArgString("-plugin-opt=-generate-arange-section"));
   }
 
   // Try to pass driver level flags relevant to LTO code generation down to


Index: clang/test/Driver/debug-options-aranges.c
===
--- clang/test/Driver/debug-options-aranges.c
+++ clang/test/Driver/debug-options-aranges.c
@@ -3,4 +3,4 @@
 /// Check that the linker plugin will get -generate-arange-section.
 // RUN: %clang -### -g --target=x86_64-linux -flto  -gdwarf-aranges %s 2>&1 | FileCheck %s
 // RUN: %clang -### -g --target=x86_64-linux -flto=thin -gdwarf-aranges %s 2>&1 | FileCheck %s
-// CHECK: --plugin-opt=-generate-arange-section
+// CHECK: -plugin-opt=-generate-arange-section
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -514,7 +514,7 @@
   // the way out.
   if (Args.hasArg(options::OPT_gdwarf_aranges)) {
 CmdArgs.push_back(
-Args.MakeArgString("--plugin-opt=-generate-arange-section"));
+Args.MakeArgString("-plugin-opt=-generate-arange-section"));
   }
 
   // Try to pass driver level flags relevant to LTO code generation down to
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D135400: [clang][LTO] Remove the use of `--` for arange option

2022-10-06 Thread Qiongsi Wu via Phabricator via cfe-commits
qiongsiwu1 created this revision.
qiongsiwu1 added reviewers: w2yehia, MaskRay, azat, dblaikie.
qiongsiwu1 added projects: clang, LLVM.
Herald added subscribers: ormris, StephenFan, inglorion.
Herald added a project: All.
qiongsiwu1 requested review of this revision.
Herald added subscribers: lldb-commits, cfe-commits.
Herald added a project: LLDB.

https://reviews.llvm.org/D134668 attempted to remove all `--` (double dashes) 
when using `plugin-opt` to pass linker options and replaced them with `-`. 
https://reviews.llvm.org/D133092 was committed later but introduced an instance 
of `--`. This patch replaces the `--` with `-`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D135400

Files:
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/test/Driver/debug-options-aranges.c
  lldb/cmake/modules/AddLLDB.cmake


Index: lldb/cmake/modules/AddLLDB.cmake
===
--- lldb/cmake/modules/AddLLDB.cmake
+++ lldb/cmake/modules/AddLLDB.cmake
@@ -105,7 +105,7 @@
   # this may result in the wrong install DESTINATION. The FRAMEWORK property
   # must be set earlier.
   if(PARAM_FRAMEWORK)
-set_target_properties(liblldb PROPERTIES FRAMEWORK ON)
+set_target_properties(${name} PROPERTIES FRAMEWORK ON)
   endif()
 
   if(PARAM_SHARED)
Index: clang/test/Driver/debug-options-aranges.c
===
--- clang/test/Driver/debug-options-aranges.c
+++ clang/test/Driver/debug-options-aranges.c
@@ -3,4 +3,4 @@
 /// Check that the linker plugin will get -generate-arange-section.
 // RUN: %clang -### -g --target=x86_64-linux -flto  -gdwarf-aranges %s 
2>&1 | FileCheck %s
 // RUN: %clang -### -g --target=x86_64-linux -flto=thin -gdwarf-aranges %s 
2>&1 | FileCheck %s
-// CHECK: --plugin-opt=-generate-arange-section
+// CHECK: -plugin-opt=-generate-arange-section
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -514,7 +514,7 @@
   // the way out.
   if (Args.hasArg(options::OPT_gdwarf_aranges)) {
 CmdArgs.push_back(
-Args.MakeArgString("--plugin-opt=-generate-arange-section"));
+Args.MakeArgString("-plugin-opt=-generate-arange-section"));
   }
 
   // Try to pass driver level flags relevant to LTO code generation down to


Index: lldb/cmake/modules/AddLLDB.cmake
===
--- lldb/cmake/modules/AddLLDB.cmake
+++ lldb/cmake/modules/AddLLDB.cmake
@@ -105,7 +105,7 @@
   # this may result in the wrong install DESTINATION. The FRAMEWORK property
   # must be set earlier.
   if(PARAM_FRAMEWORK)
-set_target_properties(liblldb PROPERTIES FRAMEWORK ON)
+set_target_properties(${name} PROPERTIES FRAMEWORK ON)
   endif()
 
   if(PARAM_SHARED)
Index: clang/test/Driver/debug-options-aranges.c
===
--- clang/test/Driver/debug-options-aranges.c
+++ clang/test/Driver/debug-options-aranges.c
@@ -3,4 +3,4 @@
 /// Check that the linker plugin will get -generate-arange-section.
 // RUN: %clang -### -g --target=x86_64-linux -flto  -gdwarf-aranges %s 2>&1 | FileCheck %s
 // RUN: %clang -### -g --target=x86_64-linux -flto=thin -gdwarf-aranges %s 2>&1 | FileCheck %s
-// CHECK: --plugin-opt=-generate-arange-section
+// CHECK: -plugin-opt=-generate-arange-section
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -514,7 +514,7 @@
   // the way out.
   if (Args.hasArg(options::OPT_gdwarf_aranges)) {
 CmdArgs.push_back(
-Args.MakeArgString("--plugin-opt=-generate-arange-section"));
+Args.MakeArgString("-plugin-opt=-generate-arange-section"));
   }
 
   // Try to pass driver level flags relevant to LTO code generation down to
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D134733: [clang-format][NFC] more centric handling of include name matching

2022-10-06 Thread Owen Pan via Phabricator via cfe-commits
owenpan added a comment.

Can you rebase? I'll finish the review after that.




Comment at: clang/lib/Tooling/Inclusions/HeaderIncludes.cpp:410
+llvm::StringRef getIncludeNameFromMatches(
+const llvm::SmallVectorImpl ) {
+  if (Matches.size() >= 3) {

Use `ArrayRef` instead.



Comment at: clang/lib/Tooling/Inclusions/HeaderIncludes.cpp:411-415
+  if (Matches.size() >= 3) {
+return Matches[2];
+  }
+  llvm_unreachable("Matches is too small");
+  return llvm::StringRef();

You can simply assert and return.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134733

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


[PATCH] D129443: [clang-format] Add option for aligning requires clause body

2022-10-06 Thread Owen Pan via Phabricator via cfe-commits
owenpan added a comment.

Is this option really required? Can we just fix the regression as reported in 
https://github.com/llvm/llvm-project/issues/56283? It seems that we haven't 
followed the policy 

 lately when adding new options.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129443

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


[PATCH] D135389: [Clang] Emit a warning for ambiguous joined '-o' arguments

2022-10-06 Thread Artem Belevich via Phabricator via cfe-commits
tra accepted this revision.
tra added a comment.
This revision is now accepted and ready to land.

Test nit. LGTM otherwise.




Comment at: clang/test/Driver/unknown-arg.c:73
+// O-WARN-NEXT: warning: joined argument treated as '-o utput'; did you mean 
'--output'?
+//  O-WARN-NOT: warning: joined argument treated as '-o ffload-device-only'; 
did you mean '--offload-device-only'?

I think this check will never trigger, because, if the warning would happen to 
be issued, it would happen before the warning for ` -output` above and we'd 
miss it.

Doing negative test in a separate `RUN` would probably be the easiest way to 
deal with it.



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135389

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


[PATCH] D133993: [HLSL] Remove global ctor/dtor variable for non-lib profile.

2022-10-06 Thread Xiang Li via Phabricator via cfe-commits
python3kgae added a comment.

In D133993#3840838 , @efriedma wrote:

> It seems like it would be better to put the code in an LLVM IR transform 
> pass, if we can. It separates the concerns more clearly, and it would make 
> life easier for other compilers.  (If you need it to run early, see 
> registerPipelineEarlySimplificationEPCallback.)
>
> I won't block the patch on that, though.

Thanks for the review.
I like the idea to move code to LLVM IR pass.
I'll commit this PR as is, and create another one to move the code.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133993

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


[PATCH] D135238: [clang] adds copy-constructible type-trait builtins

2022-10-06 Thread Louis Dionne via Phabricator via cfe-commits
ldionne added inline comments.



Comment at: clang/include/clang/Basic/TokenKinds.def:528
+TYPE_TRAIT_1(__is_nothrow_copy_constructible, IsNothrowCopyConstructible, 
KEYCXX)
+TYPE_TRAIT_1(__is_trivially_copy_constructible, IsTriviallyCopyConstructible, 
KEYCXX)
 TYPE_TRAIT_2(__reference_binds_to_temporary, ReferenceBindsToTemporary, KEYCXX)

cjdb wrote:
> erichkeane wrote:
> > royjacobson wrote:
> > > erichkeane wrote:
> > > > cjdb wrote:
> > > > > erichkeane wrote:
> > > > > > So this one is a whole 'thing'.  The Clang definition of 'trivially 
> > > > > > copy constructible' is a few DRs behind.  We should probably 
> > > > > > discuss this with libcxx to make sure use of this wouldn't be 
> > > > > > broken.
> > > > > I'd prefer to get those DRs in before finalising D135238 and 
> > > > > subsequent ones. Do you know the DR numbers I should be looking at, 
> > > > > or should I just poke npaperbot?
> > > > Not off the top of my head, Aaron and I both poked at it at one point 
> > > > trying to get trivially constructible right at one point, but I think 
> > > > we both gave up due to the ABI/versioning concerns.
> > > Maybe DR1734? Although it's about the trivially copyable trait, not 
> > > trivially copy constructible. 
> > > 
> > Yeah, I think that was the DR, that number sounds familiar.
> The `__is_trivially_*` traits were, in part, what inspired the Great Split of 
> D116208. I could remove them for now and revisit once I rip my hair out over 
> these DRs, if that would substantially improve the chances of these commits 
> landing (other commentary notwithstanding).
I am not sure I see a problem with the "triviality" part of this -- we already 
use a compiler builtin for `std::is_trivially_constructible`, so I would expect 
either this patch is fine, or we already have a latent bug in libc++.

I think I can echo @philnik's comment about this not necessarily providing the 
biggest benefit since our implementation of 
`std::is_trivially_copy_constructible` is a fairly trivial wrapper on top of 
`__is_trivially_constructible`, but I wouldn't object to the patch on that 
basis. I think it would probably be possible to instead provide a set of basis 
builtin operations that we can then build all of the library type traits on top 
of -- that would provide the highest bang-for-our-buck ratio.

At the same time, there's something kind of enticing in the consistency of 
defining every single type trait as a builtin, without exception. If that's the 
end goal, I think that would also be neat and we'd likely regroup all of our 
type traits under a single header, since each of them would literally be a one 
liner.

There's also the question of whether GCC provides these builtins -- if they 
don't and if they don't have plans to, then we'd actually need to add 
complexity in libc++ to support both, which we would be unlikely to do given 
that there's probably not a huge compile-time performance benefit.

TLDR, I think the two questions that can help gauge how much interest there 
will be from libc++ to use this are:

1. Is the plan to provide *all* the type traits as builtins?
2. Will GCC implement them?

That being said, libc++ might not be the only potential user of these builtins, 
so I wouldn't necessarily make it a hard requirement to satisfy us.



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135238

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


[PATCH] D135097: Remove redundant option '-menable-unsafe-fp-math'.

2022-10-06 Thread Zahira Ammarguellat via Phabricator via cfe-commits
zahiraam added a comment.

In D135097#3840706 , @aaron.ballman 
wrote:

> I'm also okay with this direction. I took a look to see if people seemed to 
> be using this option in their build scripts (maybe we would need a louder 
> deprecation period), and it seems like most of the uses out there are in 
> forks of Clang. Once I excluded things that looked too clang-like, I spotted: 
> https://sourcegraph.com/search?q=context:global+-file:.*test.*+-file:.*clang.*+-file:Tools.cpp+-menable-unsafe-fp-math=standard
>  -- I don't have the impression we need a deprecation period for this. (Do we 
> consider this to be a potentially breaking change we need to list in the 
> release notes/announcements/clang-vendors?) The changes should have a release 
> note, regardless of what heading we put it under.

@aaron.ballman There is a chapter in the RN called "Removed Compiler Flags". 
Some text should definitely be added there. I let other people chime in for the 
"potentially breaking" in the RN or somewhere else.


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

https://reviews.llvm.org/D135097

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


[PATCH] D135397: [clang][dataflow] Add support for a Top value in boolean formulas.

2022-10-06 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel created this revision.
ymandel added reviewers: xazax.hun, sgatev.
Herald added subscribers: martong, rnkovacs.
Herald added a reviewer: NoQ.
Herald added a project: All.
ymandel requested review of this revision.
Herald added a project: clang.

Currently, our boolean formulas (`BoolValue`) don't form a lattice, since they
have no Top element. This patch adds such an element, thereby "completing" the
built-in model of bools to be a proper semi-lattice. It still has infinite
height, which is its own problem, but that can be solved separately, through
widening and the like.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D135397

Files:
  clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
  clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
  clang/include/clang/Analysis/FlowSensitive/Value.h
  clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
  clang/lib/Analysis/FlowSensitive/DebugSupport.cpp
  clang/lib/Analysis/FlowSensitive/Transfer.cpp
  clang/lib/Analysis/FlowSensitive/WatchedLiteralsSolver.cpp
  clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
@@ -17,6 +17,7 @@
 #include "clang/Analysis/FlowSensitive/DataflowAnalysisContext.h"
 #include "clang/Analysis/FlowSensitive/DataflowEnvironment.h"
 #include "clang/Analysis/FlowSensitive/DataflowLattice.h"
+#include "clang/Analysis/FlowSensitive/DebugSupport.h"
 #include "clang/Analysis/FlowSensitive/NoopAnalysis.h"
 #include "clang/Analysis/FlowSensitive/Value.h"
 #include "clang/Analysis/FlowSensitive/WatchedLiteralsSolver.h"
@@ -166,7 +167,7 @@
 auto CS = Elt->getAs();
 if (!CS)
   return;
-auto S = CS->getStmt();
+const auto *S = CS->getStmt();
 if (auto *C = dyn_cast(S)) {
   if (auto *F = dyn_cast(C->getCalleeDecl())) {
 E.CalledFunctions.insert(F->getNameInfo().getAsString());
@@ -322,7 +323,7 @@
 auto CS = Elt->getAs();
 if (!CS)
   return;
-auto S = CS->getStmt();
+const auto *S = CS->getStmt();
 auto SpecialBoolRecordDecl = recordDecl(hasName("SpecialBool"));
 auto HasSpecialBoolType = hasType(SpecialBoolRecordDecl);
 
@@ -465,12 +466,16 @@
   });
 }
 
+static bool isTop(Value ) { return V.getKind() == Value::Kind::Top; }
+static bool isAtomic(Value ) {
+  return V.getKind() == Value::Kind::AtomicBool;
+}
+
 class OptionalIntAnalysis
 : public DataflowAnalysis {
 public:
-  explicit OptionalIntAnalysis(ASTContext , BoolValue )
-  : DataflowAnalysis(Context),
-HasValueTop(HasValueTop) {}
+  explicit OptionalIntAnalysis(ASTContext )
+  : DataflowAnalysis(Context) {}
 
   static NoopLattice initialElement() { return {}; }
 
@@ -478,22 +483,23 @@
 auto CS = Elt->getAs();
 if (!CS)
   return;
-auto S = CS->getStmt();
+const Stmt *S = CS->getStmt();
 auto OptionalIntRecordDecl = recordDecl(hasName("OptionalInt"));
 auto HasOptionalIntType = hasType(OptionalIntRecordDecl);
 
+SmallVector Matches = match(
+stmt(anyOf(cxxConstructExpr(HasOptionalIntType).bind("construct"),
+   cxxOperatorCallExpr(
+   callee(cxxMethodDecl(ofClass(OptionalIntRecordDecl
+   .bind("operator"))),
+*S, getASTContext());
 if (const auto *E = selectFirst(
-"call", match(cxxConstructExpr(HasOptionalIntType).bind("call"), *S,
-  getASTContext( {
+"construct", Matches)) {
   auto  = *Env.createValue(E->getType());
   ConstructorVal.setProperty("has_value", Env.getBoolLiteralValue(false));
   Env.setValue(*Env.getStorageLocation(*E, SkipPast::None), ConstructorVal);
-} else if (const auto *E = selectFirst(
-   "call",
-   match(cxxOperatorCallExpr(callee(cxxMethodDecl(ofClass(
- OptionalIntRecordDecl
- .bind("call"),
- *S, getASTContext( {
+} else if (const auto *E =
+   selectFirst("operator", Matches)) {
   assert(E->getNumArgs() > 0);
   auto *Object = E->getArg(0);
   assert(Object != nullptr);
@@ -516,7 +522,10 @@
 Type->getAsCXXRecordDecl()->getQualifiedNameAsString() != "OptionalInt")
   return false;
 
-return Val1.getProperty("has_value") == Val2.getProperty("has_value");
+auto *Prop1  = Val1.getProperty("has_value");
+auto *Prop2 = Val2.getProperty("has_value");
+return Prop1 == Prop2 || (Prop1 != nullptr && Prop2 != nullptr &&
+  isTop(*Prop1) && isTop(*Prop2));
   }
 
   bool merge(QualType Type, 

[PATCH] D135389: [Clang] Emit a warning for ambiguous joined '-o' arguments

2022-10-06 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 marked 2 inline comments as done.
jhuber6 added inline comments.



Comment at: clang/lib/Driver/Driver.cpp:337
+std::string Nearest;
+if (getOpts().findNearest("-" + ArgString, Nearest, IncludedFlagsBitmask,
+  ExcludedFlagsBitmask) == 1)

tra wrote:
> This looks for all 1-symbol mismatches. and may trigger on differences other 
> than `--option` vs `-option`.  E.g. if user passes `-oip-link` (which looks 
> like something we may see in real life), we'll try to find the nearest for 
> `--oip-link` and will get a distance-1 match for the existing option 
> `--hip-link`.
> 
> We may need to verify that the nearest match that we've found is indeed due 
> to a missing leading `dash`.
> 
You're right, I changed it to use the raw string from the input. Since it's 
joined it will be the full string, so if we append a `-` to it and the edit 
length is zero then we know for a fact that it's due to a missing dash.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135389

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


[PATCH] D135341: [clang] adds `__reference_constructs_from_temporary` and `__reference_converts_from_temporary`

2022-10-06 Thread Christopher Di Bella via Phabricator via cfe-commits
cjdb added a comment.

In D135341#3841126 , @ldionne wrote:

> Interesting, I actually wasn't even aware of that C++23 feature in the 
> library. FWIW, libc++ will be more than happy to use that builtin instead of 
> trying to figure it out inside the library (if that's even possible)! We'll 
> have to check whether GCC implements it, but hopefully it has something 
> similar. So this definitely LGTM from the libc++ side of things, assuming the 
> Clang folks are happy with the implementation.

It's possible to easily implement `reference_constructs_from_temporary` in the 
library, but the converts one is far more tricky because 
`__reference_binds_to_temporary` only cares about construction. I don't know if 
GCC implements it (I thought it did, but I can't find the commit in a trivial 
Google search), but I did learn that libstdc++ has a guard for this name.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135341

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


[PATCH] D135389: [Clang] Emit a warning for ambiguous joined '-o' arguments

2022-10-06 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 updated this revision to Diff 465862.
jhuber6 added a comment.

Adjusting check to ensure that this only applies for an edit length of zero 
once the `-` is added. Also adding a negative check line for other inputs.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135389

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/lib/Driver/Driver.cpp
  clang/test/Driver/unknown-arg.c


Index: clang/test/Driver/unknown-arg.c
===
--- clang/test/Driver/unknown-arg.c
+++ clang/test/Driver/unknown-arg.c
@@ -64,3 +64,10 @@
 // RUN: %clang -S %s -o %t.s  -Wunknown-to-clang-option 2>&1 | FileCheck 
--check-prefix=IGNORED %s
 
 // IGNORED: warning: unknown warning option '-Wunknown-to-clang-option'
+
+// RUN: %clang -### -offload-arch=sm_70 --offload-arch=sm_70 
-offload-device-only -o ffload-device-only \
+// RUN:   -output -o foo %s 2>&1 | FileCheck --check-prefix=O-WARN %s
+//  O-WARN: warning: joined argument treated as '-o ffload-arch=sm_70'; 
did you mean '--offload-arch=sm_70'?
+// O-WARN-NEXT: warning: joined argument treated as '-o ffload-device-only'; 
did you mean '--offload-device-only'?
+// O-WARN-NEXT: warning: joined argument treated as '-o utput'; did you mean 
'--output'?
+//  O-WARN-NOT: warning: joined argument treated as '-o ffload-device-only'; 
did you mean '--offload-device-only'?
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -327,6 +327,19 @@
  DiagnosticsEngine::Warning;
   }
 
+  for (const Arg *A : Args.filtered(options::OPT_o)) {
+if (ArgStrings[A->getIndex()] == A->getSpelling())
+  continue;
+
+// Warn on joined arguments that are similar to a long argument.
+std::string ArgString = ArgStrings[A->getIndex()];
+std::string Nearest;
+if (getOpts().findNearest("-" + ArgString, Nearest, IncludedFlagsBitmask,
+  ExcludedFlagsBitmask) == 0)
+  Diags.Report(diag::warn_drv_potentially_misspelled_joined_argument)
+  << A->getAsString(Args) << Nearest;
+  }
+
   return Args;
 }
 
Index: clang/include/clang/Basic/DiagnosticDriverKinds.td
===
--- clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -253,6 +253,9 @@
   "support for '/Yc' with more than one source file not implemented yet; flag 
ignored">,
   InGroup;
 
+def warn_drv_potentially_misspelled_joined_argument : Warning<
+  "joined argument treated as '%0'; did you mean '%1'?">, 
InGroup;
+
 def err_drv_invalid_value : Error<"invalid value '%1' in '%0'">;
 def err_drv_invalid_int_value : Error<"invalid integral value '%1' in '%0'">;
 def err_drv_invalid_value_with_suggestion : Error<


Index: clang/test/Driver/unknown-arg.c
===
--- clang/test/Driver/unknown-arg.c
+++ clang/test/Driver/unknown-arg.c
@@ -64,3 +64,10 @@
 // RUN: %clang -S %s -o %t.s  -Wunknown-to-clang-option 2>&1 | FileCheck --check-prefix=IGNORED %s
 
 // IGNORED: warning: unknown warning option '-Wunknown-to-clang-option'
+
+// RUN: %clang -### -offload-arch=sm_70 --offload-arch=sm_70 -offload-device-only -o ffload-device-only \
+// RUN:   -output -o foo %s 2>&1 | FileCheck --check-prefix=O-WARN %s
+//  O-WARN: warning: joined argument treated as '-o ffload-arch=sm_70'; did you mean '--offload-arch=sm_70'?
+// O-WARN-NEXT: warning: joined argument treated as '-o ffload-device-only'; did you mean '--offload-device-only'?
+// O-WARN-NEXT: warning: joined argument treated as '-o utput'; did you mean '--output'?
+//  O-WARN-NOT: warning: joined argument treated as '-o ffload-device-only'; did you mean '--offload-device-only'?
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -327,6 +327,19 @@
  DiagnosticsEngine::Warning;
   }
 
+  for (const Arg *A : Args.filtered(options::OPT_o)) {
+if (ArgStrings[A->getIndex()] == A->getSpelling())
+  continue;
+
+// Warn on joined arguments that are similar to a long argument.
+std::string ArgString = ArgStrings[A->getIndex()];
+std::string Nearest;
+if (getOpts().findNearest("-" + ArgString, Nearest, IncludedFlagsBitmask,
+  ExcludedFlagsBitmask) == 0)
+  Diags.Report(diag::warn_drv_potentially_misspelled_joined_argument)
+  << A->getAsString(Args) << Nearest;
+  }
+
   return Args;
 }
 
Index: clang/include/clang/Basic/DiagnosticDriverKinds.td
===
--- clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ 

[PATCH] D135341: [clang] adds `__reference_constructs_from_temporary` and `__reference_converts_from_temporary`

2022-10-06 Thread Louis Dionne via Phabricator via cfe-commits
ldionne added a comment.

Interesting, I actually wasn't even aware of that C++23 feature in the library. 
FWIW, libc++ will be more than happy to use that builtin instead of trying to 
figure it out inside the library (if that's even possible)! We'll have to check 
whether GCC implements it, but hopefully it has something similar. So this 
definitely LGTM from the libc++ side of things, assuming the Clang folks are 
happy with the implementation.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135341

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


[PATCH] D135091: Create storage for the `_cmd` argument to the helper function for generated getters/setters of `direct` Objective-C properties.

2022-10-06 Thread Michael Wyman via Phabricator via cfe-commits
mwyman marked an inline comment as done.
mwyman added inline comments.



Comment at: clang/test/CodeGenObjC/direct-method.m:171-177
+// Check the synthesized objectProperty calls objc_getProperty(); this also
+// checks that the synthesized method accesses _cmd (or rather loads the
+// selector, as it is an argument to objc_getProperty).
+// CHECK-LABEL: define hidden i8* @"\01-[Root objectProperty]"(
+// CHECK-LABEL: objc_direct_method.cont:
+// CHECK-NEXT: load i8*, i8** @OBJC_SELECTOR_REFERENCES_
+// CHECK: call i8* @objc_getProperty({{.*}})

stephanemoore wrote:
> I'm not intricately familiar with the codegen checking mechanism in these 
> tests but without fully knowing the details, this seems consistent with the 
> checks in `-[Root accessCmd]` above which I would expect to require similar 
> checks.
> 
> Did you check that these added tests reproduce the previous assertion/failure 
> so that we can be confident that the code changes resolve the issue?
Yes, this new test previously triggered the assertion.


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

https://reviews.llvm.org/D135091

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


[PATCH] D135091: Create storage for the `_cmd` argument to the helper function for generated getters/setters of `direct` Objective-C properties.

2022-10-06 Thread Michael Wyman via Phabricator via cfe-commits
mwyman updated this revision to Diff 465857.
mwyman retitled this revision from "Load the `_cmd` selector for generated 
getters/setters of `direct` Objective-C properties." to "Create storage for the 
`_cmd` argument to the helper function for generated getters/setters of 
`direct` Objective-C properties.".
mwyman edited the summary of this revision.
mwyman added a comment.

Updated to eliminate loading the selector, as the prior implementation didn't 
pass a valid `_cmd` value (it just re-used the `_cmd` argument in the ABI, 
which was unset by the caller and so undefined in value).


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

https://reviews.llvm.org/D135091

Files:
  clang/lib/CodeGen/CGObjC.cpp
  clang/test/CodeGenObjC/direct-method.m


Index: clang/test/CodeGenObjC/direct-method.m
===
--- clang/test/CodeGenObjC/direct-method.m
+++ clang/test/CodeGenObjC/direct-method.m
@@ -14,6 +14,7 @@
 - (int)getInt __attribute__((objc_direct));
 @property(direct, readonly) int intProperty;
 @property(direct, readonly) int intProperty2;
+@property(direct, readonly) id objectProperty;
 @end
 
 @implementation Root
@@ -167,6 +168,18 @@
 @end
 // CHECK-LABEL: define hidden i32 @"\01-[Root intProperty]"
 
+// Check the synthesized objectProperty calls objc_getProperty(); this also
+// checks that the synthesized method accesses _cmd (or rather loads the
+// selector, as it is an argument to objc_getProperty).
+// CHECK-LABEL: define hidden i8* @"\01-[Root objectProperty]"(
+// CHECK-LABEL: entry:
+// CHECK-NEXT: [[RETVAL:%.*]] = alloca i8*,
+// CHECK-NEXT: [[SELFADDR:%.*]] = alloca %0*,
+// CHECK-NEXT: [[CMDVAL:%_cmd]] = alloca i8*,
+// CHECK-LABEL: objc_direct_method.cont:
+// CHECK: [[CMD:%.*]] = load i8*, i8** [[CMDVAL]],
+// CHECK: call i8* @objc_getProperty({{.*}}, i8*{{.*}} [[CMD]], {{.*}})
+
 @interface Foo : Root {
   id __strong _cause_cxx_destruct;
 }
Index: clang/lib/CodeGen/CGObjC.cpp
===
--- clang/lib/CodeGen/CGObjC.cpp
+++ clang/lib/CodeGen/CGObjC.cpp
@@ -1189,8 +1189,15 @@
 // Return (ivar-type) objc_getProperty((id) self, _cmd, offset, true).
 // FIXME: Can't this be simpler? This might even be worse than the
 // corresponding gcc code.
-llvm::Value *cmd =
-  Builder.CreateLoad(GetAddrOfLocalVar(getterMethod->getCmdDecl()), "cmd");
+if (getterMethod->isDirectMethod()) {
+  // Direct methods no longer have a `_cmd` argument, so storage must be
+  // emitted for it to be passed to the property helper. Since the `_cmd`
+  // argument was never being initialized by the caller before, still pass
+  // an uninitialized/undefined value here.
+  EmitVarDecl(*getterMethod->getCmdDecl());
+}
+llvm::Value *cmd = 
Builder.CreateLoad(GetAddrOfLocalVar(getterMethod->getCmdDecl()),
+ "cmd");
 llvm::Value *self = Builder.CreateBitCast(LoadObjCSelf(), VoidPtrTy);
 llvm::Value *ivarOffset =
   EmitIvarOffset(classImpl->getClassInterface(), ivar);
@@ -1475,10 +1482,16 @@
 
 // Emit objc_setProperty((id) self, _cmd, offset, arg,
 //   , ).
-llvm::Value *cmd =
-  Builder.CreateLoad(GetAddrOfLocalVar(setterMethod->getCmdDecl()));
-llvm::Value *self =
-  Builder.CreateBitCast(LoadObjCSelf(), VoidPtrTy);
+if (setterMethod->isDirectMethod()) {
+  // Direct methods no longer have a `_cmd` argument, so storage must be
+  // emitted for it to be passed to the property helper. Since the `_cmd`
+  // argument was never being initialized by the caller before, still pass
+  // an uninitialized/undefined value here.
+  EmitVarDecl(*setterMethod->getCmdDecl());
+}
+llvm::Value *cmd = 
Builder.CreateLoad(GetAddrOfLocalVar(setterMethod->getCmdDecl()),
+   "cmd");
+llvm::Value *self = Builder.CreateBitCast(LoadObjCSelf(), VoidPtrTy);
 llvm::Value *ivarOffset =
   EmitIvarOffset(classImpl->getClassInterface(), ivar);
 Address argAddr = GetAddrOfLocalVar(*setterMethod->param_begin());


Index: clang/test/CodeGenObjC/direct-method.m
===
--- clang/test/CodeGenObjC/direct-method.m
+++ clang/test/CodeGenObjC/direct-method.m
@@ -14,6 +14,7 @@
 - (int)getInt __attribute__((objc_direct));
 @property(direct, readonly) int intProperty;
 @property(direct, readonly) int intProperty2;
+@property(direct, readonly) id objectProperty;
 @end
 
 @implementation Root
@@ -167,6 +168,18 @@
 @end
 // CHECK-LABEL: define hidden i32 @"\01-[Root intProperty]"
 
+// Check the synthesized objectProperty calls objc_getProperty(); this also
+// checks that the synthesized method accesses _cmd (or rather loads the
+// selector, as it is an argument to objc_getProperty).
+// CHECK-LABEL: define hidden i8* @"\01-[Root objectProperty]"(
+// 

[PATCH] D135091: Load the `_cmd` selector for generated getters/setters of `direct` Objective-C properties.

2022-10-06 Thread Stephane Moore via Phabricator via cfe-commits
stephanemoore accepted this revision.
stephanemoore added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/lib/CodeGen/CGObjC.cpp:1189-1191
 // Return (ivar-type) objc_getProperty((id) self, _cmd, offset, true).
 // FIXME: Can't this be simpler? This might even be worse than the
 // corresponding gcc code.

I couldn't immediate tell if this TODO is still in the best position. I think 
it's fine?



Comment at: clang/test/CodeGenObjC/direct-method.m:171-177
+// Check the synthesized objectProperty calls objc_getProperty(); this also
+// checks that the synthesized method accesses _cmd (or rather loads the
+// selector, as it is an argument to objc_getProperty).
+// CHECK-LABEL: define hidden i8* @"\01-[Root objectProperty]"(
+// CHECK-LABEL: objc_direct_method.cont:
+// CHECK-NEXT: load i8*, i8** @OBJC_SELECTOR_REFERENCES_
+// CHECK: call i8* @objc_getProperty({{.*}})

I'm not intricately familiar with the codegen checking mechanism in these tests 
but without fully knowing the details, this seems consistent with the checks in 
`-[Root accessCmd]` above which I would expect to require similar checks.

Did you check that these added tests reproduce the previous assertion/failure 
so that we can be confident that the code changes resolve the issue?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135091

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


[PATCH] D129755: Thread safety analysis: Support copy-elided production of scoped capabilities through arbitrary calls

2022-10-06 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 rG0041a69495f8: Thread safety analysis: Support copy-elided 
production of scoped capabilities… (authored by aaronpuchert).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129755

Files:
  clang/docs/ReleaseNotes.rst
  clang/docs/ThreadSafetyAnalysis.rst
  clang/include/clang/Analysis/Analyses/ThreadSafetyCommon.h
  clang/include/clang/Analysis/Analyses/ThreadSafetyTIL.h
  clang/include/clang/Analysis/Analyses/ThreadSafetyTraverse.h
  clang/lib/Analysis/ThreadSafety.cpp
  clang/lib/Analysis/ThreadSafetyCommon.cpp
  clang/test/SemaCXX/warn-thread-safety-analysis.cpp

Index: clang/test/SemaCXX/warn-thread-safety-analysis.cpp
===
--- clang/test/SemaCXX/warn-thread-safety-analysis.cpp
+++ clang/test/SemaCXX/warn-thread-safety-analysis.cpp
@@ -1690,6 +1690,15 @@
   }
 #endif
 
+  void temporary() {
+MutexLock{}, a = 5;
+  }
+
+  void lifetime_extension() {
+const MutexLock  = MutexLock();
+a = 5;
+  }
+
   void foo2() {
 ReaderMutexLock mulock1();
 if (getBool()) {
@@ -1708,6 +1717,12 @@
   // expected-warning {{acquiring mutex 'mu1' that is already held}}
   }
 
+  void temporary_double_lock() {
+MutexLock mulock_a(); // expected-note{{mutex acquired here}}
+MutexLock{};  // \
+  // expected-warning {{acquiring mutex 'mu1' that is already held}}
+  }
+
   void foo4() {
 MutexLock mulock1(), mulock2();
 a = b+1;
@@ -4187,6 +4202,20 @@
   void foo() EXCLUSIVE_LOCKS_REQUIRED(this);
 };
 
+class SelfLockDeferred {
+public:
+  SelfLockDeferred() LOCKS_EXCLUDED(mu_);
+  ~SelfLockDeferred() UNLOCK_FUNCTION(mu_);
+
+  Mutex mu_;
+};
+
+class LOCKABLE SelfLockDeferred2 {
+public:
+  SelfLockDeferred2() LOCKS_EXCLUDED(this);
+  ~SelfLockDeferred2() UNLOCK_FUNCTION();
+};
+
 
 void test() {
   SelfLock s;
@@ -4198,6 +4227,14 @@
   s2.foo();
 }
 
+void testDeferredTemporary() {
+  SelfLockDeferred(); // expected-warning {{releasing mutex '.mu_' that was not held}}
+}
+
+void testDeferredTemporary2() {
+  SelfLockDeferred2(); // expected-warning {{releasing mutex '' that was not held}}
+}
+
 }  // end namespace SelfConstructorTest
 
 
@@ -5892,47 +5929,41 @@
 void f() { c[A()]->g(); }
 } // namespace PR34800
 
-namespace ReturnScopedLockable {
-  template class SCOPED_LOCKABLE ReadLockedPtr {
-  public:
-ReadLockedPtr(Object *ptr) SHARED_LOCK_FUNCTION((*this)->mutex);
-ReadLockedPtr(ReadLockedPtr &&) SHARED_LOCK_FUNCTION((*this)->mutex);
-~ReadLockedPtr() UNLOCK_FUNCTION();
+#ifdef __cpp_guaranteed_copy_elision
 
-Object *operator->() const { return object; }
+namespace ReturnScopedLockable {
 
-  private:
-Object *object;
-  };
+class Object {
+public:
+  MutexLock lock() EXCLUSIVE_LOCK_FUNCTION(mutex) {
+// TODO: False positive because scoped lock isn't destructed.
+return MutexLock(); // expected-note {{mutex acquired here}}
+  }   // expected-warning {{mutex 'mutex' is still held at the end of function}}
 
-  struct Object {
-int f() SHARED_LOCKS_REQUIRED(mutex);
-Mutex mutex;
-  };
+  int x GUARDED_BY(mutex);
+  void needsLock() EXCLUSIVE_LOCKS_REQUIRED(mutex);
 
-  ReadLockedPtr get();
-  int use() {
-auto ptr = get();
-return ptr->f();
-  }
-  void use_constructor() {
-auto ptr = ReadLockedPtr(nullptr);
-ptr->f();
-auto ptr2 = ReadLockedPtr{nullptr};
-ptr2->f();
-auto ptr3 = (ReadLockedPtr{nullptr});
-ptr3->f();
-  }
-  struct Convertible {
-Convertible();
-operator ReadLockedPtr();
-  };
-  void use_conversion() {
-ReadLockedPtr ptr = Convertible();
-ptr->f();
+  void testInside() {
+MutexLock scope = lock();
+x = 1;
+needsLock();
   }
+
+private:
+  Mutex mutex;
+};
+
+void testOutside() {
+  Object obj;
+  MutexLock scope = obj.lock();
+  obj.x = 1;
+  obj.needsLock();
 }
 
+} // namespace ReturnScopedLockable
+
+#endif
+
 namespace PR38640 {
 void f() {
   // Self-referencing assignment previously caused an infinite loop when thread
Index: clang/lib/Analysis/ThreadSafetyCommon.cpp
===
--- clang/lib/Analysis/ThreadSafetyCommon.cpp
+++ clang/lib/Analysis/ThreadSafetyCommon.cpp
@@ -115,19 +115,22 @@
 /// \param D   The declaration to which the attribute is attached.
 /// \param DeclExp An expression involving the Decl to which the attribute
 ///is attached.  E.g. the call to a function.
+/// \param SelfS-expression to substitute for a \ref CXXThisExpr.
 CapabilityExpr SExprBuilder::translateAttrExpr(const Expr *AttrExp,
const NamedDecl *D,
const Expr *DeclExp,
-  

[PATCH] D129752: Thread safety analysis: Handle additional cast in scoped capability construction

2022-10-06 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.
aaronpuchert marked an inline comment as done.
Closed by commit rGd8fa40dfa7ad: Thread safety analysis: Handle additional cast 
in scoped capability construction (authored by aaronpuchert).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129752

Files:
  clang/lib/Analysis/ThreadSafety.cpp
  clang/test/SemaCXX/warn-thread-safety-analysis.cpp


Index: clang/test/SemaCXX/warn-thread-safety-analysis.cpp
===
--- clang/test/SemaCXX/warn-thread-safety-analysis.cpp
+++ clang/test/SemaCXX/warn-thread-safety-analysis.cpp
@@ -1683,6 +1683,13 @@
 a = 5;
   }
 
+#ifdef __cpp_guaranteed_copy_elision
+  void const_lock() {
+const MutexLock mulock = MutexLock();
+a = 5;
+  }
+#endif
+
   void foo2() {
 ReaderMutexLock mulock1();
 if (getBool()) {
Index: clang/lib/Analysis/ThreadSafety.cpp
===
--- clang/lib/Analysis/ThreadSafety.cpp
+++ clang/lib/Analysis/ThreadSafety.cpp
@@ -2087,6 +2087,19 @@
   SourceRange(Loc, Loc));
 }
 
+static Expr *UnpackConstruction(Expr *E) {
+  if (auto *CE = dyn_cast(E))
+if (CE->getCastKind() == CK_NoOp)
+  E = CE->getSubExpr()->IgnoreParens();
+  if (auto *CE = dyn_cast(E))
+if (CE->getCastKind() == CK_ConstructorConversion ||
+CE->getCastKind() == CK_UserDefinedConversion)
+  E = CE->getSubExpr();
+  if (auto *BTE = dyn_cast(E))
+E = BTE->getSubExpr();
+  return E;
+}
+
 void BuildLockset::VisitDeclStmt(const DeclStmt *S) {
   // adjust the context
   LVarCtx = Analyzer->LocalVarMap.getNextContext(CtxIndex, S, LVarCtx);
@@ -2101,13 +2114,7 @@
   // handle constructors that involve temporaries
   if (auto *EWC = dyn_cast(E))
 E = EWC->getSubExpr()->IgnoreParens();
-  if (auto *CE = dyn_cast(E))
-if (CE->getCastKind() == CK_NoOp ||
-CE->getCastKind() == CK_ConstructorConversion ||
-CE->getCastKind() == CK_UserDefinedConversion)
-  E = CE->getSubExpr()->IgnoreParens();
-  if (auto *BTE = dyn_cast(E))
-E = BTE->getSubExpr()->IgnoreParens();
+  E = UnpackConstruction(E);
 
   if (const auto *CE = dyn_cast(E)) {
 const auto *CtorD = dyn_cast_or_null(CE->getConstructor());


Index: clang/test/SemaCXX/warn-thread-safety-analysis.cpp
===
--- clang/test/SemaCXX/warn-thread-safety-analysis.cpp
+++ clang/test/SemaCXX/warn-thread-safety-analysis.cpp
@@ -1683,6 +1683,13 @@
 a = 5;
   }
 
+#ifdef __cpp_guaranteed_copy_elision
+  void const_lock() {
+const MutexLock mulock = MutexLock();
+a = 5;
+  }
+#endif
+
   void foo2() {
 ReaderMutexLock mulock1();
 if (getBool()) {
Index: clang/lib/Analysis/ThreadSafety.cpp
===
--- clang/lib/Analysis/ThreadSafety.cpp
+++ clang/lib/Analysis/ThreadSafety.cpp
@@ -2087,6 +2087,19 @@
   SourceRange(Loc, Loc));
 }
 
+static Expr *UnpackConstruction(Expr *E) {
+  if (auto *CE = dyn_cast(E))
+if (CE->getCastKind() == CK_NoOp)
+  E = CE->getSubExpr()->IgnoreParens();
+  if (auto *CE = dyn_cast(E))
+if (CE->getCastKind() == CK_ConstructorConversion ||
+CE->getCastKind() == CK_UserDefinedConversion)
+  E = CE->getSubExpr();
+  if (auto *BTE = dyn_cast(E))
+E = BTE->getSubExpr();
+  return E;
+}
+
 void BuildLockset::VisitDeclStmt(const DeclStmt *S) {
   // adjust the context
   LVarCtx = Analyzer->LocalVarMap.getNextContext(CtxIndex, S, LVarCtx);
@@ -2101,13 +2114,7 @@
   // handle constructors that involve temporaries
   if (auto *EWC = dyn_cast(E))
 E = EWC->getSubExpr()->IgnoreParens();
-  if (auto *CE = dyn_cast(E))
-if (CE->getCastKind() == CK_NoOp ||
-CE->getCastKind() == CK_ConstructorConversion ||
-CE->getCastKind() == CK_UserDefinedConversion)
-  E = CE->getSubExpr()->IgnoreParens();
-  if (auto *BTE = dyn_cast(E))
-E = BTE->getSubExpr()->IgnoreParens();
+  E = UnpackConstruction(E);
 
   if (const auto *CE = dyn_cast(E)) {
 const auto *CtorD = dyn_cast_or_null(CE->getConstructor());
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 0041a69 - Thread safety analysis: Support copy-elided production of scoped capabilities through arbitrary calls

2022-10-06 Thread Aaron Puchert via cfe-commits

Author: Aaron Puchert
Date: 2022-10-06T22:19:09+02:00
New Revision: 0041a69495f828f6732803cfb0f1e3fddd7fbf2a

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

LOG: Thread safety analysis: Support copy-elided production of scoped 
capabilities through arbitrary calls

When support for copy elision was initially added in e97654b2f2807, it
was taking attributes from a constructor call, although that constructor
call is actually not involved. It seems more natural to use attributes
on the function returning the scoped capability, which is where it's
actually coming from. This would also support a number of interesting
use cases, like producing different scope kinds without the need for tag
types, or producing scopes from a private mutex.

Changing the behavior was surprisingly difficult: we were not handling
CXXConstructorExpr calls like regular calls but instead handled them
through the DeclStmt they're contained in. This was based on the
assumption that constructors are basically only called in variable
declarations (not true because of temporaries), and that variable
declarations necessitate constructors (not true with C++17 anymore).

Untangling this required separating construction from assigning a
variable name. When a call produces an object, we use a placeholder
til::LiteralPtr for `this`, and we collect the call expression and
placeholder in a map. Later when going through a DeclStmt, we look up
the call expression and set the placeholder to the new VarDecl.

The change has a couple of nice side effects:
* We don't miss constructor calls not contained in DeclStmts anymore,
  allowing patterns like
MutexLock{}, requiresMutex();
  The scoped lock temporary will be destructed at the end of the full
  statement, so it protects the following call without the need for a
  scope, but with the ability to unlock in case of an exception.
* We support lifetime extension of temporaries. While unusual, one can
  now write
const MutexLock  = MutexLock();
  and have it behave as expected.
* Destructors used to be handled in a weird way: since there is no
  expression in the AST for implicit destructor calls, we instead
  provided a made-up DeclRefExpr to the variable being destructed, and
  passed that instead of a CallExpr. Then later in translateAttrExpr
  there was special code that knew that destructor expressions worked a
  bit different.
* We were producing dummy DeclRefExprs in a number of places, this has
  been eliminated. We now use til::SExprs instead.

Technically this could break existing code, but the current handling
seems unexpected enough to justify this change.

Reviewed By: aaron.ballman

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/docs/ThreadSafetyAnalysis.rst
clang/include/clang/Analysis/Analyses/ThreadSafetyCommon.h
clang/include/clang/Analysis/Analyses/ThreadSafetyTIL.h
clang/include/clang/Analysis/Analyses/ThreadSafetyTraverse.h
clang/lib/Analysis/ThreadSafety.cpp
clang/lib/Analysis/ThreadSafetyCommon.cpp
clang/test/SemaCXX/warn-thread-safety-analysis.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index a1aea7e2753d..b9a5e0507e35 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -235,6 +235,11 @@ Improvements to Clang's diagnostics
   function definition without a prototype which is preceded by a static
   declaration of the function with a prototype. Fixes
   `Issue 58181 `_.
+- Copy-elided initialization of lock scopes is now handled 
diff erently in
+  ``-Wthread-safety-analysis``: annotations on the move constructor are no
+  longer taken into account, in favor of annotations on the function returning
+  the lock scope by value. This could result in new warnings if code depended
+  on the previous undocumented behavior.
 
 Non-comprehensive list of changes in this release
 -

diff  --git a/clang/docs/ThreadSafetyAnalysis.rst 
b/clang/docs/ThreadSafetyAnalysis.rst
index 23f460b248e1..dcde0c706c70 100644
--- a/clang/docs/ThreadSafetyAnalysis.rst
+++ b/clang/docs/ThreadSafetyAnalysis.rst
@@ -408,7 +408,8 @@ and destructor refer to the capability via 
diff erent names; see the
 Scoped capabilities are treated as capabilities that are implicitly acquired
 on construction and released on destruction. They are associated with
 the set of (regular) capabilities named in thread safety attributes on the
-constructor. Acquire-type attributes on other member functions are treated as
+constructor or function returning them by value (using C++17 guaranteed copy
+elision). Acquire-type attributes on 

[clang] d8fa40d - Thread safety analysis: Handle additional cast in scoped capability construction

2022-10-06 Thread Aaron Puchert via cfe-commits

Author: Aaron Puchert
Date: 2022-10-06T22:18:26+02:00
New Revision: d8fa40dfa7adb062c969ce7ea6ce505e10626838

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

LOG: Thread safety analysis: Handle additional cast in scoped capability 
construction

We might have a CK_NoOp cast and a further CK_ConstructorConversion.
As an optimization, drop some IgnoreParens calls: inside of the
CK_{Constructor,UserDefined}Conversion should be no more parentheses,
and inside the CXXBindTemporaryExpr should also be none.

Lastly, we factor out the unpacking so that we can reuse it for
MaterializeTemporaryExprs later on.

Reviewed By: aaron.ballman

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

Added: 


Modified: 
clang/lib/Analysis/ThreadSafety.cpp
clang/test/SemaCXX/warn-thread-safety-analysis.cpp

Removed: 




diff  --git a/clang/lib/Analysis/ThreadSafety.cpp 
b/clang/lib/Analysis/ThreadSafety.cpp
index 3291d7f8e3b3..a29134c6a5e7 100644
--- a/clang/lib/Analysis/ThreadSafety.cpp
+++ b/clang/lib/Analysis/ThreadSafety.cpp
@@ -2087,6 +2087,19 @@ static Expr *buildFakeCtorCall(CXXConstructorDecl *CD, 
ArrayRef Args,
   SourceRange(Loc, Loc));
 }
 
+static Expr *UnpackConstruction(Expr *E) {
+  if (auto *CE = dyn_cast(E))
+if (CE->getCastKind() == CK_NoOp)
+  E = CE->getSubExpr()->IgnoreParens();
+  if (auto *CE = dyn_cast(E))
+if (CE->getCastKind() == CK_ConstructorConversion ||
+CE->getCastKind() == CK_UserDefinedConversion)
+  E = CE->getSubExpr();
+  if (auto *BTE = dyn_cast(E))
+E = BTE->getSubExpr();
+  return E;
+}
+
 void BuildLockset::VisitDeclStmt(const DeclStmt *S) {
   // adjust the context
   LVarCtx = Analyzer->LocalVarMap.getNextContext(CtxIndex, S, LVarCtx);
@@ -2101,13 +2114,7 @@ void BuildLockset::VisitDeclStmt(const DeclStmt *S) {
   // handle constructors that involve temporaries
   if (auto *EWC = dyn_cast(E))
 E = EWC->getSubExpr()->IgnoreParens();
-  if (auto *CE = dyn_cast(E))
-if (CE->getCastKind() == CK_NoOp ||
-CE->getCastKind() == CK_ConstructorConversion ||
-CE->getCastKind() == CK_UserDefinedConversion)
-  E = CE->getSubExpr()->IgnoreParens();
-  if (auto *BTE = dyn_cast(E))
-E = BTE->getSubExpr()->IgnoreParens();
+  E = UnpackConstruction(E);
 
   if (const auto *CE = dyn_cast(E)) {
 const auto *CtorD = dyn_cast_or_null(CE->getConstructor());

diff  --git a/clang/test/SemaCXX/warn-thread-safety-analysis.cpp 
b/clang/test/SemaCXX/warn-thread-safety-analysis.cpp
index ac854dce0f7b..e1cfa1f3fd17 100644
--- a/clang/test/SemaCXX/warn-thread-safety-analysis.cpp
+++ b/clang/test/SemaCXX/warn-thread-safety-analysis.cpp
@@ -1683,6 +1683,13 @@ struct TestScopedLockable {
 a = 5;
   }
 
+#ifdef __cpp_guaranteed_copy_elision
+  void const_lock() {
+const MutexLock mulock = MutexLock();
+a = 5;
+  }
+#endif
+
   void foo2() {
 ReaderMutexLock mulock1();
 if (getBool()) {



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


[PATCH] D135389: [Clang] Emit a warning for ambiguous joined '-o' arguments

2022-10-06 Thread Artem Belevich via Phabricator via cfe-commits
tra added a comment.

LGTM in principle.




Comment at: clang/lib/Driver/Driver.cpp:337
+std::string Nearest;
+if (getOpts().findNearest("-" + ArgString, Nearest, IncludedFlagsBitmask,
+  ExcludedFlagsBitmask) == 1)

This looks for all 1-symbol mismatches. and may trigger on differences other 
than `--option` vs `-option`.  E.g. if user passes `-oip-link` (which looks 
like something we may see in real life), we'll try to find the nearest for 
`--oip-link` and will get a distance-1 match for the existing option 
`--hip-link`.

We may need to verify that the nearest match that we've found is indeed due to 
a missing leading `dash`.




Comment at: clang/test/Driver/unknown-arg.c:68
+
+// RUN: %clang -### -offload-arch=sm_70 --offload-arch=sm_70 
-offload-device-only -output -o foo \
+// RUN:   %s 2>&1 | FileCheck --check-prefix=O-WARN %s

I'd also add a test verifying that `-o ffload-device-only` does not trigger the 
warning.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135389

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


[PATCH] D135392: Use PoisonValue in vector BIs [NFC]

2022-10-06 Thread Manuel Brito via Phabricator via cfe-commits
ManuelJBrito created this revision.
ManuelJBrito added a reviewer: nlopes.
ManuelJBrito added a project: clang.
Herald added subscribers: dmgreen, arphaman, kbarton, nemanjai.
Herald added a project: All.
ManuelJBrito requested review of this revision.
Herald added a subscriber: cfe-commits.

Replacing the following instances of UndefValue with PoisonValue in 
clang/lib/CodeGen/CGBuiltin.cpp where the UndefValue is used as an arbitrary 
value.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D135392

Files:
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/PowerPC/builtins-ppc-int128.c
  clang/test/CodeGen/aarch64-bf16-ldst-intrinsics.c
  clang/test/CodeGen/aarch64-neon-intrinsics.c
  clang/test/CodeGen/aarch64-neon-ldst-one.c
  clang/test/CodeGen/aarch64-neon-scalar-x-indexed-elem.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_dupq-bfloat.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_dupq.c
  clang/test/CodeGen/arm-mve-intrinsics/vld24.c
  clang/test/CodeGen/arm_neon_intrinsics.c

Index: clang/test/CodeGen/arm_neon_intrinsics.c
===
--- clang/test/CodeGen/arm_neon_intrinsics.c
+++ clang/test/CodeGen/arm_neon_intrinsics.c
@@ -4077,7 +4077,7 @@
 
 // CHECK-LABEL: @test_vld1q_dup_u8(
 // CHECK:   [[TMP0:%.*]] = load i8, i8* %a, align 1
-// CHECK:   [[TMP1:%.*]] = insertelement <16 x i8> undef, i8 [[TMP0]], i32 0
+// CHECK:   [[TMP1:%.*]] = insertelement <16 x i8> poison, i8 [[TMP0]], i32 0
 // CHECK:   [[LANE:%.*]] = shufflevector <16 x i8> [[TMP1]], <16 x i8> [[TMP1]], <16 x i32> zeroinitializer
 // CHECK:   ret <16 x i8> [[LANE]]
 uint8x16_t test_vld1q_dup_u8(uint8_t const * a) {
@@ -4088,7 +4088,7 @@
 // CHECK:   [[TMP0:%.*]] = bitcast i16* %a to i8*
 // CHECK:   [[TMP1:%.*]] = bitcast i8* [[TMP0]] to i16*
 // CHECK:   [[TMP2:%.*]] = load i16, i16* [[TMP1]], align 2
-// CHECK:   [[TMP3:%.*]] = insertelement <8 x i16> undef, i16 [[TMP2]], i32 0
+// CHECK:   [[TMP3:%.*]] = insertelement <8 x i16> poison, i16 [[TMP2]], i32 0
 // CHECK:   [[LANE:%.*]] = shufflevector <8 x i16> [[TMP3]], <8 x i16> [[TMP3]], <8 x i32> zeroinitializer
 // CHECK:   ret <8 x i16> [[LANE]]
 uint16x8_t test_vld1q_dup_u16(uint16_t const * a) {
@@ -4099,7 +4099,7 @@
 // CHECK:   [[TMP0:%.*]] = bitcast i32* %a to i8*
 // CHECK:   [[TMP1:%.*]] = bitcast i8* [[TMP0]] to i32*
 // CHECK:   [[TMP2:%.*]] = load i32, i32* [[TMP1]], align 4
-// CHECK:   [[TMP3:%.*]] = insertelement <4 x i32> undef, i32 [[TMP2]], i32 0
+// CHECK:   [[TMP3:%.*]] = insertelement <4 x i32> poison, i32 [[TMP2]], i32 0
 // CHECK:   [[LANE:%.*]] = shufflevector <4 x i32> [[TMP3]], <4 x i32> [[TMP3]], <4 x i32> zeroinitializer
 // CHECK:   ret <4 x i32> [[LANE]]
 uint32x4_t test_vld1q_dup_u32(uint32_t const * a) {
@@ -4110,7 +4110,7 @@
 // CHECK:   [[TMP0:%.*]] = bitcast i64* %a to i8*
 // CHECK:   [[TMP1:%.*]] = bitcast i8* [[TMP0]] to i64*
 // CHECK:   [[TMP2:%.*]] = load i64, i64* [[TMP1]], align 4
-// CHECK:   [[TMP3:%.*]] = insertelement <2 x i64> undef, i64 [[TMP2]], i32 0
+// CHECK:   [[TMP3:%.*]] = insertelement <2 x i64> poison, i64 [[TMP2]], i32 0
 // CHECK:   [[LANE:%.*]] = shufflevector <2 x i64> [[TMP3]], <2 x i64> [[TMP3]], <2 x i32> zeroinitializer
 // CHECK:   ret <2 x i64> [[LANE]]
 uint64x2_t test_vld1q_dup_u64(uint64_t const * a) {
@@ -4119,7 +4119,7 @@
 
 // CHECK-LABEL: @test_vld1q_dup_s8(
 // CHECK:   [[TMP0:%.*]] = load i8, i8* %a, align 1
-// CHECK:   [[TMP1:%.*]] = insertelement <16 x i8> undef, i8 [[TMP0]], i32 0
+// CHECK:   [[TMP1:%.*]] = insertelement <16 x i8> poison, i8 [[TMP0]], i32 0
 // CHECK:   [[LANE:%.*]] = shufflevector <16 x i8> [[TMP1]], <16 x i8> [[TMP1]], <16 x i32> zeroinitializer
 // CHECK:   ret <16 x i8> [[LANE]]
 int8x16_t test_vld1q_dup_s8(int8_t const * a) {
@@ -4130,7 +4130,7 @@
 // CHECK:   [[TMP0:%.*]] = bitcast i16* %a to i8*
 // CHECK:   [[TMP1:%.*]] = bitcast i8* [[TMP0]] to i16*
 // CHECK:   [[TMP2:%.*]] = load i16, i16* [[TMP1]], align 2
-// CHECK:   [[TMP3:%.*]] = insertelement <8 x i16> undef, i16 [[TMP2]], i32 0
+// CHECK:   [[TMP3:%.*]] = insertelement <8 x i16> poison, i16 [[TMP2]], i32 0
 // CHECK:   [[LANE:%.*]] = shufflevector <8 x i16> [[TMP3]], <8 x i16> [[TMP3]], <8 x i32> zeroinitializer
 // CHECK:   ret <8 x i16> [[LANE]]
 int16x8_t test_vld1q_dup_s16(int16_t const * a) {
@@ -4141,7 +4141,7 @@
 // CHECK:   [[TMP0:%.*]] = bitcast i32* %a to i8*
 // CHECK:   [[TMP1:%.*]] = bitcast i8* [[TMP0]] to i32*
 // CHECK:   [[TMP2:%.*]] = load i32, i32* [[TMP1]], align 4
-// CHECK:   [[TMP3:%.*]] = insertelement <4 x i32> undef, i32 [[TMP2]], i32 0
+// CHECK:   [[TMP3:%.*]] = insertelement <4 x i32> poison, i32 [[TMP2]], i32 0
 // CHECK:   [[LANE:%.*]] = shufflevector <4 x i32> [[TMP3]], <4 x i32> [[TMP3]], <4 x i32> zeroinitializer
 // CHECK:   ret <4 x i32> [[LANE]]
 int32x4_t test_vld1q_dup_s32(int32_t const * a) {
@@ -4152,7 +4152,7 @@
 // CHECK:   [[TMP0:%.*]] = bitcast i64* %a to i8*
 // CHECK:   

[PATCH] D135128: [clang][cli] Simplify repetitive macro invocations

2022-10-06 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 added a comment.

In D135128#3839312 , @thieta wrote:

> This looks fine to me in principle. But I wonder if we should land the flag 
> change first separately and make sure that no buildbots break because of it. 
> Then we can merge the simplification a few days later when we are sure it's 
> stabilized, since something similar happened when we upgraded to C++17 - and 
> people already had merged code that used C++17 it was really hard to revert.

That makes sense, I'll commit the flag change separately. Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135128

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


[PATCH] D131424: Remove the unused/undefined _cmd parameter to objc_direct methods.

2022-10-06 Thread Stephane Moore via Phabricator via cfe-commits
stephanemoore added a comment.

LGTM after fixing the assertion ✅


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131424

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


  1   2   3   >