[PATCH] D155710: [clang][Interp] Create a new local variable in VisitCXXDefaultArgExpr

2023-07-29 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder abandoned this revision.
tbaeder added a comment.

Abandoning in favor of https://reviews.llvm.org/D156027


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155710

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


[PATCH] D156277: [Parser][ObjC] Fix parser crash on nested top-level block with better recovery path

2023-07-29 Thread Ding Fei via Phabricator via cfe-commits
danix800 updated this revision to Diff 545343.
danix800 added a comment.

Cleanup spaghetti-ish code.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156277

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Parse/ParseObjc.cpp
  clang/test/Parser/missing-end-1-gh64065-nocrash.m
  clang/test/Parser/missing-end-2.m
  clang/test/Parser/missing-end-3.m
  clang/test/Parser/missing-end-4.m

Index: clang/test/Parser/missing-end-4.m
===
--- clang/test/Parser/missing-end-4.m
+++ clang/test/Parser/missing-end-4.m
@@ -37,10 +37,10 @@
 - (C*) MyMeth {}
 @end
 
-@interface I2 {}
-@protocol P2; // expected-error {{illegal interface qualifier}}
-@class C2; // expected-error {{illegal interface qualifier}}
-@end
+@interface I2 {} // expected-note {{class started here}}
+@protocol P2; // expected-error {{missing '@end'}}
+@class C2;
+@end // expected-error {{'@end' must appear in an Objective-C context}}
 
 @interface I3
 @end
Index: clang/test/Parser/missing-end-3.m
===
--- clang/test/Parser/missing-end-3.m
+++ clang/test/Parser/missing-end-3.m
@@ -1,10 +1,12 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s
 // rdar://8283484
+// expected-note@+1 {{previous definition is here}}
 @interface blah { // expected-note {{class started here}}
 @private
 }
 // since I forgot the @end here it should say something
 
+// expected-error@+1 {{duplicate interface definition for class 'blah'}}
 @interface blah  // expected-error {{missing '@end'}}
-@end // and Unknown type name 'end' here
+@end
 
Index: clang/test/Parser/missing-end-2.m
===
--- clang/test/Parser/missing-end-2.m
+++ clang/test/Parser/missing-end-2.m
@@ -1,9 +1,10 @@
-// RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -fsyntax-only -Wno-objc-root-class -verify %s
 // rdar: //7824372
 
 @interface A // expected-note {{class started here}}
--(void) im0;
+-(void) im0; // expected-note {{method 'im0' declared here}}
 
+// expected-warning@+1 {{method definition for 'im0' not found}}
 @implementation A // expected-error {{missing '@end'}}
 @end
 
@@ -13,7 +14,8 @@
 @implementation B // expected-error {{missing '@end'}}
 @end
 
-@interface C // expected-note 2 {{class started here}}
+@interface C // expected-note 1 {{class started here}}
 @property int P;
 
+// expected-note@+1 {{implementation started here}}
 @implementation C // expected-error 2 {{missing '@end'}}
Index: clang/test/Parser/missing-end-1-gh64065-nocrash.m
===
--- /dev/null
+++ clang/test/Parser/missing-end-1-gh64065-nocrash.m
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+@interface Roo // expected-note {{class started here}}
+// expected-error@+1 {{missing '@end'}}
+@interface // expected-error {{expected identifier}}
Index: clang/lib/Parse/ParseObjc.cpp
===
--- clang/lib/Parse/ParseObjc.cpp
+++ clang/lib/Parse/ParseObjc.cpp
@@ -613,6 +613,19 @@
   /*mayBeProtocolList=*/false);
 }
 
+static bool isTopLevelObjCKeyword(tok::ObjCKeywordKind DirectiveKind) {
+  switch (DirectiveKind) {
+  case tok::objc_class:
+  case tok::objc_compatibility_alias:
+  case tok::objc_interface:
+  case tok::objc_implementation:
+  case tok::objc_protocol:
+return true;
+  default:
+return false;
+  }
+}
+
 ///   objc-interface-decl-list:
 /// empty
 /// objc-interface-decl-list objc-property-decl [OBJC2]
@@ -705,27 +718,33 @@
   continue;
 }
 
-// Otherwise, we have an @ directive, eat the @.
-SourceLocation AtLoc = ConsumeToken(); // the "@"
-if (Tok.is(tok::code_completion)) {
+// Otherwise, we have an @ directive, peak at the next token
+SourceLocation AtLoc = Tok.getLocation();
+const auto &NextTok = NextToken();
+if (NextTok.is(tok::code_completion)) {
   cutOffParsing();
   Actions.CodeCompleteObjCAtDirective(getCurScope());
   return;
 }
 
-tok::ObjCKeywordKind DirectiveKind = Tok.getObjCKeywordID();
-
+tok::ObjCKeywordKind DirectiveKind = NextTok.getObjCKeywordID();
 if (DirectiveKind == tok::objc_end) { // @end -> terminate list
+  ConsumeToken(); // the "@"
   AtEnd.setBegin(AtLoc);
   AtEnd.setEnd(Tok.getLocation());
   break;
 } else if (DirectiveKind == tok::objc_not_keyword) {
-  Diag(Tok, diag::err_objc_unknown_at);
+  Diag(NextTok, diag::err_objc_unknown_at);
   SkipUntil(tok::semi);
   continue;
 }
 
-// Eat the identifier.
+// Bail out as if we saw an '@end'
+if (isTopLevelObjCKeyword(DirectiveKind))
+  break;
+
+// Otherwise parse it as part of the current declaration. Eat "@identif

[clang] 7dbc7b1 - [Options] Fix a couple of incorrect comments. NFC

2023-07-29 Thread Justin Bogner via cfe-commits

Author: Justin Bogner
Date: 2023-07-29T01:38:52-07:00
New Revision: 7dbc7b18a0cd02c6a4a74443a8596aba508f12b0

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

LOG: [Options] Fix a couple of incorrect comments. NFC

Added: 


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

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 9b44e11535c2a9..8ec28841f91000 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5533,7 +5533,7 @@ def triple : Separate<["-"], "triple">,
   MarshallingInfoString, 
"llvm::Triple::normalize(llvm::sys::getDefaultTargetTriple())">,
   AlwaysEmit, Normalizer<"normalizeTriple">;
 
-} // let Flags = [CC1Option, CC1ASOption, FC1Option, NoDriverOption]
+} // let Flags = [CC1Option, CC1AsOption, FC1Option, NoDriverOption]
 
 
//===--===//
 // Target Options (other)
@@ -6869,7 +6869,7 @@ def dwarf_debug_producer : Separate<["-"], 
"dwarf-debug-producer">,
 def defsym : Separate<["-"], "defsym">,
   HelpText<"Define a value for a symbol">;
 
-} // let Flags = [CC1AsOption]
+} // let Flags = [CC1AsOption, NoDriverOption]
 
 
//===--===//
 // clang-cl Options



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


[clang] ff80fc0 - [clang][Interp] Implement __builtin_isnan()

2023-07-29 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-07-29T10:48:10+02:00
New Revision: ff80fc0ea2f9ec043d679f343c875bdf43e1395e

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

LOG: [clang][Interp] Implement __builtin_isnan()

The previous version was using llvm::reverse(CallExpr::arguments()),
which causes problems when clang is compiled with GCC.

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

Added: 


Modified: 
clang/lib/AST/Interp/Function.cpp
clang/lib/AST/Interp/Function.h
clang/lib/AST/Interp/Interp.cpp
clang/lib/AST/Interp/Interp.h
clang/lib/AST/Interp/InterpBuiltin.cpp
clang/test/Sema/constant-builtins-fmin.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/Function.cpp 
b/clang/lib/AST/Interp/Function.cpp
index 75312999d23d66..e409002171c4b7 100644
--- a/clang/lib/AST/Interp/Function.cpp
+++ b/clang/lib/AST/Interp/Function.cpp
@@ -7,10 +7,11 @@
 
//===--===//
 
 #include "Function.h"
-#include "Program.h"
 #include "Opcode.h"
+#include "Program.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclCXX.h"
+#include "clang/Basic/Builtins.h"
 
 using namespace clang;
 using namespace clang::interp;
@@ -47,3 +48,9 @@ bool Function::isVirtual() const {
 return M->isVirtual();
   return false;
 }
+
+bool Function::needsRuntimeArgPop(const ASTContext &Ctx) const {
+  if (!isBuiltin())
+return false;
+  return Ctx.BuiltinInfo.hasCustomTypechecking(getBuiltinID());
+}

diff  --git a/clang/lib/AST/Interp/Function.h b/clang/lib/AST/Interp/Function.h
index 644d4cd53b1e19..5444c9f59cda7e 100644
--- a/clang/lib/AST/Interp/Function.h
+++ b/clang/lib/AST/Interp/Function.h
@@ -171,6 +171,12 @@ class Function final {
 
   unsigned getBuiltinID() const { return F->getBuiltinID(); }
 
+  bool isBuiltin() const { return F->getBuiltinID() != 0; }
+
+  /// Does this function need its arguments to be classified at runtime
+  /// rather than at bytecode-compile-time?
+  bool needsRuntimeArgPop(const ASTContext &Ctx) const;
+
   unsigned getNumParams() const { return ParamTypes.size(); }
 
   unsigned getParamOffset(unsigned ParamIndex) const {

diff  --git a/clang/lib/AST/Interp/Interp.cpp b/clang/lib/AST/Interp/Interp.cpp
index b891306e6aa405..2b7f3bf35aa598 100644
--- a/clang/lib/AST/Interp/Interp.cpp
+++ b/clang/lib/AST/Interp/Interp.cpp
@@ -122,6 +122,19 @@ static bool CheckGlobal(InterpState &S, CodePtr OpPC, 
const Pointer &Ptr) {
 namespace clang {
 namespace interp {
 
+bool popBuiltinArgs(InterpState &S, CodePtr OpPC) {
+  assert(S.Current && 
S.Current->getFunction()->needsRuntimeArgPop(S.getCtx()));
+  const Expr *E = S.Current->getExpr(OpPC);
+  assert(isa(E));
+  const CallExpr *CE = cast(E);
+  for (int32_t I = CE->getNumArgs() - 1; I >= 0; --I) {
+const Expr *A = CE->getArg(I);
+PrimType Ty = S.getContext().classify(A->getType()).value_or(PT_Ptr);
+TYPE_SWITCH(Ty, S.Stk.discard());
+  }
+  return true;
+}
+
 bool CheckExtern(InterpState &S, CodePtr OpPC, const Pointer &Ptr) {
   if (!Ptr.isExtern())
 return true;

diff  --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index 9eae79ba5d1e7a..4da5985e3b3d6f 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -181,6 +181,9 @@ enum class ArithOp { Add, Sub };
 // Returning values
 
//===--===//
 
+/// Pop arguments of builtins defined as func-name(...).
+bool popBuiltinArgs(InterpState &S, CodePtr OpPC);
+
 template ::T>
 bool Ret(InterpState &S, CodePtr &PC, APValue &Result) {
   const T &Ret = S.Stk.pop();
@@ -197,8 +200,16 @@ bool Ret(InterpState &S, CodePtr &PC, APValue &Result) {
   }
 
   assert(S.Current->getFrameOffset() == S.Stk.size() && "Invalid frame");
-  if (!S.checkingPotentialConstantExpression() || S.Current->Caller)
-S.Current->popArgs();
+  if (!S.checkingPotentialConstantExpression() || S.Current->Caller) {
+// Certain builtin functions are declared as func-name(...), so the
+// parameters are checked in Sema and only available through the CallExpr.
+// The interp::Function we create for them has 0 parameters, so we need to
+// remove them from the stack by checking the CallExpr.
+if (S.Current && S.Current->getFunction()->needsRuntimeArgPop(S.getCtx()))
+  popBuiltinArgs(S, PC);
+else
+  S.Current->popArgs();
+  }
 
   if (InterpFrame *Caller = S.Current->Caller) {
 PC = S.Current->getRetPC();

diff  --git a/clang/lib/AST/Interp/InterpBuiltin.cpp 
b/clang/lib/AST/Interp/InterpBuiltin.cpp
index b023d09df48784..01c41339bba8c8 100644
--- a/clang/lib/AST/Interp/InterpBuiltin.cpp
+++ b/clang/lib/AST/Interp/InterpBuiltin.cpp
@@ -162,6 +162,17 @@ static bo

[PATCH] D155568: [clang][Interp] Make sure we push integers of the correct size

2023-07-29 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 545349.

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

https://reviews.llvm.org/D155568

Files:
  clang/lib/AST/Interp/Integral.h
  clang/lib/AST/Interp/InterpBuiltin.cpp
  clang/test/AST/Interp/builtin-functions.cpp

Index: clang/test/AST/Interp/builtin-functions.cpp
===
--- clang/test/AST/Interp/builtin-functions.cpp
+++ clang/test/AST/Interp/builtin-functions.cpp
@@ -2,6 +2,8 @@
 // RUN: %clang_cc1 -verify=ref %s -Wno-constant-evaluated
 // RUN: %clang_cc1 -std=c++20 -fexperimental-new-constant-interpreter %s -verify
 // RUN: %clang_cc1 -std=c++20 -verify=ref %s -Wno-constant-evaluated
+// RUN: %clang_cc1 -triple avr -std=c++20 -fexperimental-new-constant-interpreter %s -verify
+// RUN: %clang_cc1 -triple avr -std=c++20 -verify=ref %s -Wno-constant-evaluated
 
 
 namespace strcmp {
@@ -93,10 +95,12 @@
   char isfpclass_pos_1[!__builtin_isfpclass(1.0f, 0x0008) ? 1 : -1]; // fcNegNormal
   char isfpclass_pos_2[__builtin_isfpclass(1.0L, 0x01F8) ? 1 : -1]; // fcFinite
   char isfpclass_pos_3[!__builtin_isfpclass(1.0, 0x0003) ? 1 : -1]; // fcSNan|fcQNan
+#ifndef __AVR__
   char isfpclass_pdenorm_0[__builtin_isfpclass(1.0e-40f, 0x0080) ? 1 : -1]; // fcPosSubnormal
   char isfpclass_pdenorm_1[__builtin_isfpclass(1.0e-310, 0x01F8) ? 1 : -1]; // fcFinite
   char isfpclass_pdenorm_2[!__builtin_isfpclass(1.0e-40f, 0x003C) ? 1 : -1]; // fcNegative
   char isfpclass_pdenorm_3[!__builtin_isfpclass(1.0e-310, 0x0207) ? 1 : -1]; // ~fcFinite
+#endif
   char isfpclass_pzero_0  [__builtin_isfpclass(0.0f, 0x0060) ? 1 : -1]; // fcZero
   char isfpclass_pzero_1  [__builtin_isfpclass(0.0, 0x01F8) ? 1 : -1]; // fcFinite
   char isfpclass_pzero_2  [!__builtin_isfpclass(0.0L, 0x0020) ? 1 : -1]; // fcNegZero
@@ -106,9 +110,11 @@
   char isfpclass_nzero_2  [!__builtin_isfpclass(-0.0L, 0x0040) ? 1 : -1]; // fcPosZero
   char isfpclass_nzero_3  [!__builtin_isfpclass(-0.0, 0x0003) ? 1 : -1]; // fcNan
   char isfpclass_ndenorm_0[__builtin_isfpclass(-1.0e-40f, 0x0010) ? 1 : -1]; // fcNegSubnormal
-  char isfpclass_ndenorm_1[__builtin_isfpclass(-1.0e-310, 0x01F8) ? 1 : -1]; // fcFinite
   char isfpclass_ndenorm_2[!__builtin_isfpclass(-1.0e-40f, 0x03C0) ? 1 : -1]; // fcPositive
+#ifndef __AVR__
+  char isfpclass_ndenorm_1[__builtin_isfpclass(-1.0e-310, 0x01F8) ? 1 : -1]; // fcFinite
   char isfpclass_ndenorm_3[!__builtin_isfpclass(-1.0e-310, 0x0207) ? 1 : -1]; // ~fcFinite
+#endif
   char isfpclass_neg_0[__builtin_isfpclass(-1.0, 0x0008) ? 1 : -1]; // fcNegNormal
   char isfpclass_neg_1[!__builtin_isfpclass(-1.0f, 0x00100) ? 1 : -1]; // fcPosNormal
   char isfpclass_neg_2[__builtin_isfpclass(-1.0L, 0x01F8) ? 1 : -1]; // fcFinite
@@ -133,9 +139,11 @@
   char classify_inf [__builtin_fpclassify(-1, +1, -1, -1, -1, __builtin_inf())];
   char classify_neg_inf [__builtin_fpclassify(-1, +1, -1, -1, -1, -__builtin_inf())];
   char classify_normal  [__builtin_fpclassify(-1, -1, +1, -1, -1, 1.539)];
+#ifndef __AVR__
   char classify_normal2 [__builtin_fpclassify(-1, -1, +1, -1, -1, 1e-307)];
   char classify_denorm  [__builtin_fpclassify(-1, -1, -1, +1, -1, 1e-308)];
   char classify_denorm2 [__builtin_fpclassify(-1, -1, -1, +1, -1, -1e-308)];
+#endif
   char classify_zero[__builtin_fpclassify(-1, -1, -1, -1, +1, 0.0)];
   char classify_neg_zero[__builtin_fpclassify(-1, -1, -1, -1, +1, -0.0)];
   char classify_subnorm [__builtin_fpclassify(-1, -1, -1, +1, -1, 1.0e-38f)];
@@ -145,6 +153,7 @@
   static_assert(__builtin_fabs(-14.0) == 14.0, "");
 }
 
+#ifndef __AVR__
 namespace ArithmeticFence {
   constexpr double d = __arithmetic_fence(13.0);
   static_assert(d == 13.0, "");
@@ -157,3 +166,4 @@
   _Complex double CD = __arithmetic_fence(CD);
 #endif
 }
+#endif
Index: clang/lib/AST/Interp/InterpBuiltin.cpp
===
--- clang/lib/AST/Interp/InterpBuiltin.cpp
+++ clang/lib/AST/Interp/InterpBuiltin.cpp
@@ -32,6 +32,30 @@
   return R;
 }
 
+/// Pushes \p Val to the stack, as a target-dependent 'int'.
+static void pushInt(InterpState &S, int32_t Val) {
+  const TargetInfo &TI = S.getCtx().getTargetInfo();
+  unsigned IntWidth = TI.getIntWidth();
+
+  if (IntWidth == 32)
+S.Stk.push>(Integral<32, true>::from(Val));
+  else if (IntWidth == 16)
+S.Stk.push>(Integral<16, true>::from(Val));
+  else
+llvm_unreachable("Int isn't 16 or 32 bit?");
+}
+
+static bool retInt(InterpState &S, CodePtr OpPC, APValue &Result) {
+  const TargetInfo &TI = S.getCtx().getTargetInfo();
+  unsigned IntWidth = TI.getIntWidth();
+
+  if (IntWidth == 32)
+return Ret(S, OpPC, Result);
+  else if (IntWidth == 16)
+return Ret(S, OpPC, Result);
+  llvm_unreachable("Int isn't 16 or 32 bit?");
+}
+
 static bool interp__builtin_strcmp(InterpState &S, CodePtr OpPC,
const InterpFrame *Frame) {
   const Pointer &A = getParam

[PATCH] D155568: [clang][Interp] Make sure we push integers of the correct size

2023-07-29 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added a comment.

In D155568#4542764 , @aaron.ballman 
wrote:

> In D155568#4525488 , @tbaeder wrote:
>
>> This patch is missing the `Ret` part in `InterpBuiltin()` in the 
>> same file. That needs to change to the correct type as well.
>>
>> I can do that in a follow-up commit. @aaron.ballman Can you come up with a 
>> value I can pass to `-triple` so I can actually test that this works?
>
> Oops, sorry on the delayed response, this one slipped under my radar. You 
> should be able to use `avr-unknown-unknown`: https://godbolt.org/z/4TsPW41d5

Thanks, updated with the avr RUN lines.


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

https://reviews.llvm.org/D155568

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


[PATCH] D155165: [clang][Interp] Fully serialize Floatings to bytes

2023-07-29 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 545353.
tbaeder marked 2 inline comments as done.

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

https://reviews.llvm.org/D155165

Files:
  clang/lib/AST/Interp/ByteCodeEmitter.cpp
  clang/lib/AST/Interp/Disasm.cpp
  clang/lib/AST/Interp/Floating.h
  clang/lib/AST/Interp/Interp.h
  clang/lib/AST/Interp/Source.h
  clang/test/AST/Interp/floats.cpp

Index: clang/test/AST/Interp/floats.cpp
===
--- clang/test/AST/Interp/floats.cpp
+++ clang/test/AST/Interp/floats.cpp
@@ -144,6 +144,22 @@
 
 namespace LongDouble {
   constexpr long double ld = 3.1425926539;
+
+  constexpr long double f() {
+const long double L = __LDBL_MAX__;
+
+return L;
+  };
+  static_assert(f() == __LDBL_MAX__);
+
+#ifdef __FLOAT128__
+  constexpr __float128 f128() {
+const __float128 L = __LDBL_MAX__;
+
+return L;
+  };
+  static_assert(f128() == __LDBL_MAX__);
+#endif
 }
 
 namespace Compare {
Index: clang/lib/AST/Interp/Source.h
===
--- clang/lib/AST/Interp/Source.h
+++ clang/lib/AST/Interp/Source.h
@@ -43,6 +43,7 @@
   }
 
   bool operator!=(const CodePtr &RHS) const { return Ptr != RHS.Ptr; }
+  const std::byte *operator*() const { return Ptr; }
 
   operator bool() const { return Ptr; }
 
Index: clang/lib/AST/Interp/Interp.h
===
--- clang/lib/AST/Interp/Interp.h
+++ clang/lib/AST/Interp/Interp.h
@@ -1903,6 +1903,12 @@
   }
 }
 
+template <> inline Floating ReadArg(InterpState &S, CodePtr &OpPC) {
+  Floating F = Floating::deserialize(*OpPC);
+  OpPC += align(F.bytesToSerialize());
+  return F;
+}
+
 } // namespace interp
 } // namespace clang
 
Index: clang/lib/AST/Interp/Floating.h
===
--- clang/lib/AST/Interp/Floating.h
+++ clang/lib/AST/Interp/Floating.h
@@ -135,6 +135,27 @@
 llvm::StoreIntToMemory(API, (uint8_t *)Buff, bitWidth() / 8);
   }
 
+  // === Serialization support ===
+  size_t bytesToSerialize() const {
+return sizeof(llvm::fltSemantics *) +
+   (APFloat::semanticsSizeInBits(F.getSemantics()) / 8);
+  }
+
+  void serialize(std::byte *Buff) const {
+// Semantics followed by an APInt.
+*reinterpret_cast(Buff) = &F.getSemantics();
+
+llvm::APInt API = F.bitcastToAPInt();
+llvm::StoreIntToMemory(API, (uint8_t *)(Buff + sizeof(void *)),
+   bitWidth() / 8);
+  }
+
+  static Floating deserialize(const std::byte *Buff) {
+const llvm::fltSemantics *Sem;
+std::memcpy((void *)&Sem, Buff, sizeof(void *));
+return bitcastFromMemory(Buff + sizeof(void *), *Sem);
+  }
+
   // ---
 
   static APFloat::opStatus add(const Floating &A, const Floating &B,
Index: clang/lib/AST/Interp/Disasm.cpp
===
--- clang/lib/AST/Interp/Disasm.cpp
+++ clang/lib/AST/Interp/Disasm.cpp
@@ -31,6 +31,12 @@
   }
 }
 
+template <> inline Floating ReadArg(Program &P, CodePtr &OpPC) {
+  Floating F = Floating::deserialize(*OpPC);
+  OpPC += align(F.bytesToSerialize());
+  return F;
+}
+
 LLVM_DUMP_METHOD void Function::dump() const { dump(llvm::errs()); }
 
 LLVM_DUMP_METHOD void Function::dump(llvm::raw_ostream &OS) const {
Index: clang/lib/AST/Interp/ByteCodeEmitter.cpp
===
--- clang/lib/AST/Interp/ByteCodeEmitter.cpp
+++ clang/lib/AST/Interp/ByteCodeEmitter.cpp
@@ -206,6 +206,25 @@
   }
 }
 
+template <>
+void emit(Program &P, std::vector &Code, const Floating &Val,
+  bool &Success) {
+  size_t Size = Val.bytesToSerialize();
+
+  if (Code.size() + Size > std::numeric_limits::max()) {
+Success = false;
+return;
+  }
+
+  // Access must be aligned!
+  size_t ValPos = align(Code.size());
+  Size = align(Size);
+  assert(aligned(ValPos + Size));
+  Code.resize(ValPos + Size);
+
+  Val.serialize(Code.data() + ValPos);
+}
+
 template 
 bool ByteCodeEmitter::emitOp(Opcode Op, const Tys &... Args, const SourceInfo &SI) {
   bool Success = true;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] 87d0aed - [clang-tidy] Add readability-reference-to-constructed-temporary check

2023-07-29 Thread Piotr Zegar via cfe-commits

Author: Piotr Zegar
Date: 2023-07-29T10:39:17Z
New Revision: 87d0aedaa285cfca92aef67367ce55c476cf444e

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

LOG: [clang-tidy] Add readability-reference-to-constructed-temporary check

Detects code where a temporary object is directly constructed by calling
a constructor or using an initializer list and immediately assigned to a
reference variable.

Reviewed By: xgupta

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

Added: 

clang-tools-extra/clang-tidy/readability/ReferenceToConstructedTemporaryCheck.cpp

clang-tools-extra/clang-tidy/readability/ReferenceToConstructedTemporaryCheck.h

clang-tools-extra/docs/clang-tidy/checks/readability/reference-to-constructed-temporary.rst

clang-tools-extra/test/clang-tidy/checkers/readability/reference-to-constructed-temporary.cpp

Modified: 
clang-tools-extra/clang-tidy/readability/CMakeLists.txt
clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/docs/clang-tidy/checks/list.rst

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/readability/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
index 421698cd615f9d..ba83cb441845c5 100644
--- a/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
@@ -41,6 +41,7 @@ add_clang_library(clangTidyReadabilityModule
   RedundantSmartptrGetCheck.cpp
   RedundantStringCStrCheck.cpp
   RedundantStringInitCheck.cpp
+  ReferenceToConstructedTemporaryCheck.cpp
   SimplifyBooleanExprCheck.cpp
   SimplifySubscriptExprCheck.cpp
   StaticAccessedThroughInstanceCheck.cpp

diff  --git 
a/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp 
b/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
index f95fa636f15774..b8e6e641432060 100644
--- a/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
@@ -44,6 +44,7 @@
 #include "RedundantSmartptrGetCheck.h"
 #include "RedundantStringCStrCheck.h"
 #include "RedundantStringInitCheck.h"
+#include "ReferenceToConstructedTemporaryCheck.h"
 #include "SimplifyBooleanExprCheck.h"
 #include "SimplifySubscriptExprCheck.h"
 #include "StaticAccessedThroughInstanceCheck.h"
@@ -116,6 +117,8 @@ class ReadabilityModule : public ClangTidyModule {
 "readability-redundant-member-init");
 CheckFactories.registerCheck(
 "readability-redundant-preprocessor");
+CheckFactories.registerCheck(
+"readability-reference-to-constructed-temporary");
 CheckFactories.registerCheck(
 "readability-simplify-subscript-expr");
 CheckFactories.registerCheck(

diff  --git 
a/clang-tools-extra/clang-tidy/readability/ReferenceToConstructedTemporaryCheck.cpp
 
b/clang-tools-extra/clang-tidy/readability/ReferenceToConstructedTemporaryCheck.cpp
new file mode 100644
index 00..587ae8ea305802
--- /dev/null
+++ 
b/clang-tools-extra/clang-tidy/readability/ReferenceToConstructedTemporaryCheck.cpp
@@ -0,0 +1,85 @@
+//===--- ReferenceToConstructedTemporaryCheck.cpp - clang-tidy
+//--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "ReferenceToConstructedTemporaryCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::readability {
+
+namespace {
+
+// Predicate structure to check if lifetime of temporary is not extended by
+// ValueDecl pointed out by ID
+struct NotExtendedByDeclBoundToPredicate {
+  bool operator()(const internal::BoundNodesMap &Nodes) const {
+const auto *Other = Nodes.getNodeAs(ID);
+if (!Other)
+  return true;
+
+const auto *Self = Node.get();
+if (!Self)
+  return true;
+
+return Self->getExtendingDecl() != Other;
+  }
+
+  StringRef ID;
+  ::clang::DynTypedNode Node;
+};
+
+AST_MATCHER_P(MaterializeTemporaryExpr, isExtendedByDeclBoundTo, StringRef,
+  ID) {
+  NotExtendedByDeclBoundToPredicate Predicate{
+  ID, ::clang::DynTypedNode::create(Node)};
+  return Builder->removeBindings(Predicate);
+}
+
+} // namespace
+
+bool ReferenceToConstructedTemporaryCheck::isLanguageVersionSupported(
+const LangOptions &LangOpts) const {
+  return LangOpts.CPlusPlus;
+}
+
+std::optional
+ReferenceToConstructedTemporaryCheck::getCheckTraversalKind() const {
+  return TK_AsIs;
+}
+
+v

[PATCH] D146368: [clang-tidy] Add readability-reference-to-constructed-temporary check

2023-07-29 Thread Piotr Zegar via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG87d0aedaa285: [clang-tidy] Add 
readability-reference-to-constructed-temporary check (authored by PiotrZSL).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146368

Files:
  clang-tools-extra/clang-tidy/readability/CMakeLists.txt
  clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
  
clang-tools-extra/clang-tidy/readability/ReferenceToConstructedTemporaryCheck.cpp
  
clang-tools-extra/clang-tidy/readability/ReferenceToConstructedTemporaryCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/docs/clang-tidy/checks/readability/reference-to-constructed-temporary.rst
  
clang-tools-extra/test/clang-tidy/checkers/readability/reference-to-constructed-temporary.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/readability/reference-to-constructed-temporary.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/readability/reference-to-constructed-temporary.cpp
@@ -0,0 +1,30 @@
+// RUN: %check_clang_tidy -std=c++11-or-later %s readability-reference-to-constructed-temporary %t
+
+struct WithConstructor
+{
+WithConstructor(int, int);
+};
+
+struct WithoutConstructor
+{
+int a, b;
+};
+
+void test()
+{
+// CHECK-MESSAGES: :[[@LINE+1]]:27: warning: reference variable 'tmp1' extends the lifetime of a just-constructed temporary object 'const WithConstructor', consider changing reference to value [readability-reference-to-constructed-temporary]
+   const WithConstructor& tmp1{1,2};
+
+// CHECK-MESSAGES: :[[@LINE+1]]:30: warning: reference variable 'tmp2' extends the lifetime of a just-constructed temporary object 'const WithoutConstructor', consider changing reference to value [readability-reference-to-constructed-temporary]
+   const WithoutConstructor& tmp2{1,2};
+
+
+// CHECK-MESSAGES: :[[@LINE+1]]:22: warning: reference variable 'tmp3' extends the lifetime of a just-constructed temporary object 'WithConstructor', consider changing reference to value [readability-reference-to-constructed-temporary]
+   WithConstructor&& tmp3{1,2};
+
+// CHECK-MESSAGES: :[[@LINE+1]]:25: warning: reference variable 'tmp4' extends the lifetime of a just-constructed temporary object 'WithoutConstructor', consider changing reference to value [readability-reference-to-constructed-temporary]
+   WithoutConstructor&& tmp4{1,2};
+
+   WithConstructor tmp5{1,2};
+   WithoutConstructor tmp6{1,2};
+}
Index: clang-tools-extra/docs/clang-tidy/checks/readability/reference-to-constructed-temporary.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/readability/reference-to-constructed-temporary.rst
@@ -0,0 +1,32 @@
+.. title:: clang-tidy - readability-reference-to-constructed-temporary
+
+readability-reference-to-constructed-temporary
+==
+
+Detects C++ code where a reference variable is used to extend the lifetime of
+a temporary object that has just been constructed.
+
+This construction is often the result of multiple code refactorings or a lack
+of developer knowledge, leading to confusion or subtle bugs. In most cases,
+what the developer really wanted to do is create a new variable rather than
+extending the lifetime of a temporary object.
+
+Examples of problematic code include:
+
+.. code-block:: c++
+
+   const std::string& str("hello");
+
+   struct Point { int x; int y; };
+   const Point& p = { 1, 2 };
+
+In the first example, a ``const std::string&`` reference variable ``str`` is
+assigned a temporary object created by the ``std::string("hello")``
+constructor. In the second example, a ``const Point&`` reference variable ``p``
+is assigned an object that is constructed from an initializer list ``{ 1, 2 }``.
+Both of these examples extend the lifetime of the temporary object to the
+lifetime of the reference variable, which can make it difficult to reason about
+and may lead to subtle bugs or misunderstanding.
+
+To avoid these issues, it is recommended to change the reference variable to a
+(``const``) value variable.
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
@@ -380,6 +380,7 @@
`readability-redundant-smartptr-get `_, "Yes"
`readability-redundant-string-cstr `_, "Yes"
`readability-redundant-string-init `_, "Yes"
+   `readability-reference-to-constructed-temporary `_,
`readability-simplify-boolean-expr `_, "Yes"
`readability-simplify-subscript-expr `_, "Yes"
`readability-static-accessed-through-instance `_, "Yes"
Index: clang-tools-extra/docs/ReleaseNotes.rst

[PATCH] D156588: feat: Add support for Rocky Linux to LLVM Distro

2023-07-29 Thread xufei via Phabricator via cfe-commits
zkkxu updated this revision to Diff 545358.
zkkxu added a comment.

- fix wrong ut test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156588

Files:
  clang/include/clang/Driver/Distro.h
  clang/lib/Driver/Distro.cpp
  clang/unittests/Driver/DistroTest.cpp

Index: clang/unittests/Driver/DistroTest.cpp
===
--- clang/unittests/Driver/DistroTest.cpp
+++ clang/unittests/Driver/DistroTest.cpp
@@ -50,6 +50,7 @@
   ASSERT_EQ(Distro(Distro::UbuntuTrusty), UbuntuTrusty);
   ASSERT_TRUE(UbuntuTrusty.IsUbuntu());
   ASSERT_FALSE(UbuntuTrusty.IsRedhat());
+  ASSERT_FALSE(UbuntuTrusty.IsRocky());
   ASSERT_FALSE(UbuntuTrusty.IsOpenSUSE());
   ASSERT_FALSE(UbuntuTrusty.IsDebian());
   ASSERT_FALSE(UbuntuTrusty.IsGentoo());
@@ -83,6 +84,7 @@
   ASSERT_EQ(Distro(Distro::UbuntuYakkety), UbuntuYakkety);
   ASSERT_TRUE(UbuntuYakkety.IsUbuntu());
   ASSERT_FALSE(UbuntuYakkety.IsRedhat());
+  ASSERT_FALSE(UbuntuYakkety.IsRocky());
   ASSERT_FALSE(UbuntuYakkety.IsOpenSUSE());
   ASSERT_FALSE(UbuntuYakkety.IsDebian());
   ASSERT_FALSE(UbuntuYakkety.IsGentoo());
@@ -118,6 +120,7 @@
   ASSERT_EQ(Distro(Distro::Fedora), Fedora25);
   ASSERT_FALSE(Fedora25.IsUbuntu());
   ASSERT_TRUE(Fedora25.IsRedhat());
+  ASSERT_FALSE(Fedora25.IsRocky());
   ASSERT_FALSE(Fedora25.IsOpenSUSE());
   ASSERT_FALSE(Fedora25.IsDebian());
   ASSERT_FALSE(Fedora25.IsGentoo());
@@ -155,11 +158,56 @@
   ASSERT_EQ(Distro(Distro::RHEL7), CentOS7);
   ASSERT_FALSE(CentOS7.IsUbuntu());
   ASSERT_TRUE(CentOS7.IsRedhat());
+  ASSERT_FALSE(CentOS7.IsRocky());
   ASSERT_FALSE(CentOS7.IsOpenSUSE());
   ASSERT_FALSE(CentOS7.IsDebian());
   ASSERT_FALSE(CentOS7.IsGentoo());
 }
 
+TEST(DistroTest, DetectRocky) {
+  llvm::vfs::InMemoryFileSystem RockyFileSystem;
+  RockyFileSystem.addFile(
+  "/etc/system-release-cpe", 0,
+  llvm::MemoryBuffer::getMemBuffer("cpe:/o:rocky:rocky:8:GA\n"));
+  // Both files are symlinks to rocky-release.
+  RockyFileSystem.addFile("/etc/system-release", 0,
+  llvm::MemoryBuffer::getMemBuffer(
+  "Rocky Linux release 8.6 (Green Obsidian) \n"));
+  RockyFileSystem.addFile("/etc/redhat-release", 0,
+  llvm::MemoryBuffer::getMemBuffer(
+  "Rocky Linux release 8.6 (Green Obsidian) \n"));
+  RockyFileSystem.addFile("/etc/centos-release", 0,
+  llvm::MemoryBuffer::getMemBuffer(
+  "Rocky Linux release 8.6 (Green Obsidian) \n"));
+  RockyFileSystem.addFile(
+  "/etc/os-release", 0,
+  llvm::MemoryBuffer::getMemBuffer(
+  "NAME=\"Rocky Linux\"\n"
+  "VERSION=\"8.6 (Green Obsidian)\"\n"
+  "ID=\"rocky\"\n"
+  "ID_LIKE=\"rhel centos fedora\"\n"
+  "VERSION_ID=\"8.6\"\n"
+  "PLATFORM_ID=\"platform:el8\"\n"
+  "PRETTY_NAME=\"Rocky Linux 8.6 (Green Obsidian)\"\n"
+  "ANSI_COLOR=\"0;32\"\n"
+  "CPE_NAME=\"cpe:/o:rocky:rocky:8:GA\"\n"
+  "HOME_URL=\"https://rockylinux.org\"\n";
+  "BUG_REPORT_URL=\"https://bugs.rockylinux.org/\"\n";
+  "ROCKY_SUPPORT_PRODUCT=\"Rocky Linux\"\n"
+  "ROCKY_SUPPORT_PRODUCT_VERSION=\"8\"\n"
+  "REDHAT_SUPPORT_PRODUCT=\"Rocky Linux\"\n"
+  "REDHAT_SUPPORT_PRODUCT_VERSION=\"8\"\n"));
+
+  Distro Rocky{RockyFileSystem, llvm::Triple("unknown-pc-linux")};
+  ASSERT_EQ(Distro(Distro::RHEL8), Rocky);
+  ASSERT_FALSE(Rocky.IsUbuntu());
+  ASSERT_FALSE(Rocky.IsRedhat());
+  ASSERT_TRUE(Rocky.IsRocky());
+  ASSERT_FALSE(Rocky.IsOpenSUSE());
+  ASSERT_FALSE(Rocky.IsDebian());
+  ASSERT_FALSE(Rocky.IsGentoo());
+}
+
 TEST(DistroTest, DetectOpenSUSE) {
   llvm::vfs::InMemoryFileSystem OpenSUSELeap421FileSystem;
   OpenSUSELeap421FileSystem.addFile("/etc/SuSE-release", 0,
@@ -183,6 +231,7 @@
   ASSERT_EQ(Distro(Distro::OpenSUSE), OpenSUSELeap421);
   ASSERT_FALSE(OpenSUSELeap421.IsUbuntu());
   ASSERT_FALSE(OpenSUSELeap421.IsRedhat());
+  ASSERT_FALSE(OpenSUSELeap421.IsRocky());
   ASSERT_TRUE(OpenSUSELeap421.IsOpenSUSE());
   ASSERT_FALSE(OpenSUSELeap421.IsDebian());
   ASSERT_FALSE(OpenSUSELeap421.IsGentoo());
@@ -209,6 +258,7 @@
   ASSERT_EQ(Distro(Distro::OpenSUSE), OpenSUSE132);
   ASSERT_FALSE(OpenSUSE132.IsUbuntu());
   ASSERT_FALSE(OpenSUSE132.IsRedhat());
+  ASSERT_FALSE(OpenSUSE132.IsRocky());
   ASSERT_TRUE(OpenSUSE132.IsOpenSUSE());
   ASSERT_FALSE(OpenSUSE132.IsDebian());
   ASSERT_FALSE(OpenSUSE132.IsGentoo());
@@ -226,6 +276,7 @@
   ASSERT_EQ(Distro(Distro::UnknownDistro), SLES10);
   ASSERT_FALSE(SLES10.IsUbuntu());
   ASSERT_FALSE(SLES10.IsRedhat());
+  ASSERT_FALSE(SLES10.IsRocky());
   ASSERT_FALSE(SLES10.IsOpenSUSE());
   ASSERT_FALSE(SLES10.IsDebian());
   ASSERT_FALSE(SLES10.IsGentoo());
@@ -249,6 +300,7 @@
   ASSERT_EQ(Distro(Distro::DebianJessie), DebianJessie);
   ASSERT_FALSE(De

[clang] 065da35 - clang driver throws error for -mabi=elfv2 or elfv2

2023-07-29 Thread Kishan Parmar via cfe-commits

Author: Kishan Parmar
Date: 2023-07-29T16:10:51+05:30
New Revision: 065da3574b4fe9d4ee6283de2c82b8ce1c08af08

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

LOG: clang driver throws error for -mabi=elfv2 or elfv2

After clang release/16.x there is a regression that -mabi=elfv1
or -mabi=elfv2 are being unused and throws warning. But clang-trunk
throws error for -mabi=elfv2 or elfv1. Intent of this patch to accept
elfv1 or elfv2 for -mabi.

Reviewed By : nemanjai
Differential Revision: https://reviews.llvm.org/D156351

Added: 


Modified: 
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/ppc-abi.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 0fc476fba53f34..170eedf0ac6222 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -2068,6 +2068,12 @@ void Clang::AddPPCTargetArgs(const ArgList &Args,
 } else if (V == "vec-extabi") {
   VecExtabi = true;
   A->claim();
+} else if (V == "elfv1") {
+  ABIName = "elfv1";
+  A->claim();
+} else if (V == "elfv2") {
+  ABIName = "elfv2";
+  A->claim();
 } else if (V != "altivec")
   // The ppc64 linux abis are all "altivec" abis by default. Accept and 
ignore
   // the option if given as we don't have backend support for any targets

diff  --git a/clang/test/Driver/ppc-abi.c b/clang/test/Driver/ppc-abi.c
index cc07b084132f15..a433f4c0f5d8fc 100644
--- a/clang/test/Driver/ppc-abi.c
+++ b/clang/test/Driver/ppc-abi.c
@@ -15,6 +15,10 @@
 // RUN:   -mabi=elfv2 | FileCheck -check-prefix=CHECK-ELFv2 %s
 // RUN: %clang -target powerpc64le-unknown-linux-gnu %s -### -o %t.o 2>&1 \
 // RUN:   -mabi=altivec | FileCheck -check-prefix=CHECK-ELFv2 %s
+// RUN: %clang --target=ppc64 -mabi=elfv1 %s -### -o %t.o 2>&1 \
+// RUN: | FileCheck -check-prefix=CHECK-UNKNOWN-ELFv1 %s
+// RUN: %clang --target=ppc64 -mabi=elfv2 %s -### -o %t.o 2>&1 \
+// RUN: | FileCheck -check-prefix=CHECK-UNKNOWN-ELFv2 %s
 
 // RUN: %clang -target powerpc64-unknown-freebsd11 %s -### 2>&1 | FileCheck 
--check-prefix=CHECK-ELFv1 %s
 // RUN: %clang -target powerpc64-unknown-freebsd12 %s -### 2>&1 | FileCheck 
--check-prefix=CHECK-ELFv1 %s
@@ -31,6 +35,8 @@
 // CHECK-ELFv2-BE: "-target-abi" "elfv2"
 // CHECK-ELFv2-BE-PIE: "-mrelocation-model" "pic" "-pic-level" "2" 
"-pic-is-pie"
 // CHECK-ELFv2-BE-PIE: "-target-abi" "elfv2"
+// CHECK-UNKNOWN-ELFv1: "-target-abi" "elfv1"
+// CHECK-UNKNOWN-ELFv2: "-target-abi" "elfv2"
 
 // RUN: %clang -fPIC -target powerpc64-unknown-linux-gnu %s -### -o %t.o 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHECK-ELFv1-PIC %s



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


[PATCH] D156351: clang driver throws error for -mabi=elfv2 or elfv2

2023-07-29 Thread Kishan Parmar 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 rG065da3574b4f: clang driver throws error for -mabi=elfv2 or 
elfv2 (authored by long5hot).

Changed prior to commit:
  https://reviews.llvm.org/D156351?vs=544674&id=545359#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156351

Files:
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/ppc-abi.c


Index: clang/test/Driver/ppc-abi.c
===
--- clang/test/Driver/ppc-abi.c
+++ clang/test/Driver/ppc-abi.c
@@ -15,6 +15,10 @@
 // RUN:   -mabi=elfv2 | FileCheck -check-prefix=CHECK-ELFv2 %s
 // RUN: %clang -target powerpc64le-unknown-linux-gnu %s -### -o %t.o 2>&1 \
 // RUN:   -mabi=altivec | FileCheck -check-prefix=CHECK-ELFv2 %s
+// RUN: %clang --target=ppc64 -mabi=elfv1 %s -### -o %t.o 2>&1 \
+// RUN: | FileCheck -check-prefix=CHECK-UNKNOWN-ELFv1 %s
+// RUN: %clang --target=ppc64 -mabi=elfv2 %s -### -o %t.o 2>&1 \
+// RUN: | FileCheck -check-prefix=CHECK-UNKNOWN-ELFv2 %s
 
 // RUN: %clang -target powerpc64-unknown-freebsd11 %s -### 2>&1 | FileCheck 
--check-prefix=CHECK-ELFv1 %s
 // RUN: %clang -target powerpc64-unknown-freebsd12 %s -### 2>&1 | FileCheck 
--check-prefix=CHECK-ELFv1 %s
@@ -31,6 +35,8 @@
 // CHECK-ELFv2-BE: "-target-abi" "elfv2"
 // CHECK-ELFv2-BE-PIE: "-mrelocation-model" "pic" "-pic-level" "2" 
"-pic-is-pie"
 // CHECK-ELFv2-BE-PIE: "-target-abi" "elfv2"
+// CHECK-UNKNOWN-ELFv1: "-target-abi" "elfv1"
+// CHECK-UNKNOWN-ELFv2: "-target-abi" "elfv2"
 
 // RUN: %clang -fPIC -target powerpc64-unknown-linux-gnu %s -### -o %t.o 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHECK-ELFv1-PIC %s
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -2068,6 +2068,12 @@
 } else if (V == "vec-extabi") {
   VecExtabi = true;
   A->claim();
+} else if (V == "elfv1") {
+  ABIName = "elfv1";
+  A->claim();
+} else if (V == "elfv2") {
+  ABIName = "elfv2";
+  A->claim();
 } else if (V != "altivec")
   // The ppc64 linux abis are all "altivec" abis by default. Accept and 
ignore
   // the option if given as we don't have backend support for any targets


Index: clang/test/Driver/ppc-abi.c
===
--- clang/test/Driver/ppc-abi.c
+++ clang/test/Driver/ppc-abi.c
@@ -15,6 +15,10 @@
 // RUN:   -mabi=elfv2 | FileCheck -check-prefix=CHECK-ELFv2 %s
 // RUN: %clang -target powerpc64le-unknown-linux-gnu %s -### -o %t.o 2>&1 \
 // RUN:   -mabi=altivec | FileCheck -check-prefix=CHECK-ELFv2 %s
+// RUN: %clang --target=ppc64 -mabi=elfv1 %s -### -o %t.o 2>&1 \
+// RUN: | FileCheck -check-prefix=CHECK-UNKNOWN-ELFv1 %s
+// RUN: %clang --target=ppc64 -mabi=elfv2 %s -### -o %t.o 2>&1 \
+// RUN: | FileCheck -check-prefix=CHECK-UNKNOWN-ELFv2 %s
 
 // RUN: %clang -target powerpc64-unknown-freebsd11 %s -### 2>&1 | FileCheck --check-prefix=CHECK-ELFv1 %s
 // RUN: %clang -target powerpc64-unknown-freebsd12 %s -### 2>&1 | FileCheck --check-prefix=CHECK-ELFv1 %s
@@ -31,6 +35,8 @@
 // CHECK-ELFv2-BE: "-target-abi" "elfv2"
 // CHECK-ELFv2-BE-PIE: "-mrelocation-model" "pic" "-pic-level" "2" "-pic-is-pie"
 // CHECK-ELFv2-BE-PIE: "-target-abi" "elfv2"
+// CHECK-UNKNOWN-ELFv1: "-target-abi" "elfv1"
+// CHECK-UNKNOWN-ELFv2: "-target-abi" "elfv2"
 
 // RUN: %clang -fPIC -target powerpc64-unknown-linux-gnu %s -### -o %t.o 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHECK-ELFv1-PIC %s
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -2068,6 +2068,12 @@
 } else if (V == "vec-extabi") {
   VecExtabi = true;
   A->claim();
+} else if (V == "elfv1") {
+  ABIName = "elfv1";
+  A->claim();
+} else if (V == "elfv2") {
+  ABIName = "elfv2";
+  A->claim();
 } else if (V != "altivec")
   // The ppc64 linux abis are all "altivec" abis by default. Accept and ignore
   // the option if given as we don't have backend support for any targets
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D156351: clang driver throws error for -mabi=elfv2 or elfv2

2023-07-29 Thread Kishan Parmar via Phabricator via cfe-commits
long5hot added inline comments.



Comment at: clang/test/Driver/ppc-abi.c:18
 // RUN:   -mabi=altivec | FileCheck -check-prefix=CHECK-ELFv2 %s
+// RUN: %clang --target=ppc64 -mabi=elfv1 %s -### -o %t.o 2>&1 \
+// RUN: | FileCheck -check-prefix=CHECK-UNKNOWN-ELFv1 %s

Did a small testCase change here, because of this [[ 
https://github.com/llvm/llvm-project/issues/64194 | #64194 ]] bug ..



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156351

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


[PATCH] D149867: [Clang][M68k] Add Clang support for the new M68k_RTD CC

2023-07-29 Thread John Paul Adrian Glaubitz via Phabricator via cfe-commits
glaubitz added a comment.

Any update on this?


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

https://reviews.llvm.org/D149867

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


[PATCH] D112921: [clang] Enable sized deallocation by default in C++14 onwards

2023-07-29 Thread Mark de Wever via Phabricator via cfe-commits
Mordante added a comment.

In D112921#4541063 , @wangpc wrote:

> - Rebase.
> - Unsupport clang-18.

I see the libc++ build failed. It seems like timeouts uploading artifacts, so 
not related to your patch. Can you rebase and give it another run on the CI? (I 
didn't look at the other build failures.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112921

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


[PATCH] D156027: [clang][Interp] Rework how initializers work

2023-07-29 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added inline comments.



Comment at: clang/lib/AST/Interp/ByteCodeExprGen.cpp:240
+return Initializing ? this->visitInitializer(SubExpr)
+: this->visit(SubExpr);
 

aaron.ballman wrote:
> tbaeder wrote:
> > This pattern shows up a few times, so it might make sense to add a function 
> > that simply passes on all the flags and doesn't do anything else. I'm just 
> > not sure what to call it.
> It's not clear to me when you should use this pattern to begin with.
Whenever you just pass on the visit, essentially ignoring the current node. 
Another good example is `ConstantExpr`s, where we don't do anything for the 
node and then just pass move on to the `SubExpr`.


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

https://reviews.llvm.org/D156027

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


[PATCH] D156027: [clang][Interp] Rework how initializers work

2023-07-29 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added inline comments.



Comment at: clang/lib/AST/Interp/Context.cpp:131
   if (T->isFunctionPointerType() || T->isFunctionReferenceType() ||
-  T->isFunctionType())
+  T->isFunctionType() || 
T->isSpecificBuiltinType(BuiltinType::BoundMember))
 return PT_FnPtr;

aaron.ballman wrote:
> tbaeder wrote:
> > I've removed this change in https://reviews.llvm.org/D144164 since it 
> > didn't  seem necessary, but it //is// necessary after applying this patch.
> Which test case exercises this bit?
We have this line in `records.cpp`:

```
  constexpr int value = (s.*foo)();
```
and its type is:

```
BuiltinType 0x6211fbe0 ''
```

it just so happens that we _now_ call `classify()` on this earlier in the code 
path while before we didn't do that, so we need to know that the bound member 
function type is now some composite type.


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

https://reviews.llvm.org/D156027

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


[PATCH] D154189: [clang][Interp] Implement zero-init of record types

2023-07-29 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 545367.
tbaeder marked an inline comment as done.

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

https://reviews.llvm.org/D154189

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/ByteCodeExprGen.h
  clang/lib/AST/Interp/Descriptor.cpp
  clang/lib/AST/Interp/Descriptor.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
@@ -931,3 +931,116 @@
   O o1(0);
 }
 #endif
+
+
+namespace ZeroInit {
+  struct F {
+int a;
+  };
+
+  namespace Simple {
+struct A {
+  char a;
+  bool b;
+  int c[4];
+  float d;
+};
+constexpr int foo(A x) {
+  return x.a + static_cast(x.b) + x.c[0] + x.c[3] + static_cast(x.d);
+}
+static_assert(foo(A()) == 0, "");
+  }
+
+  namespace Inheritance {
+struct F2 : F {
+  float f;
+};
+
+constexpr int foo(F2 f) {
+  return (int)f.f + f.a;
+}
+static_assert(foo(F2()) == 0, "");
+  }
+
+  namespace BitFields {
+struct F {
+  unsigned a : 6;
+};
+constexpr int foo(F f) {
+  return f.a;
+}
+static_assert(foo(F()) == 0, "");
+  }
+
+  namespace Nested {
+struct F2 {
+  float f;
+  char c;
+};
+
+struct F {
+  F2 f2;
+  int i;
+};
+
+constexpr int foo(F f) {
+  return f.i + f.f2.f + f.f2.c;
+}
+static_assert(foo(F()) == 0, "");
+  }
+
+  namespace CompositeArrays {
+struct F2 {
+  float f;
+  char c;
+};
+
+struct F {
+  F2 f2[2];
+  int i;
+};
+
+constexpr int foo(F f) {
+  return f.i + f.f2[0].f + f.f2[0].c + f.f2[1].f + f.f2[1].c;
+}
+static_assert(foo(F()) == 0, "");
+  }
+
+  /// FIXME: This needs support for unions on the new interpreter.
+  /// We diagnose an uninitialized object in c++14.
+#if __cplusplus > 201402L
+  namespace Unions {
+struct F {
+  union {
+int a;
+char c[4];
+float f;
+  } U;
+  int i;
+};
+
+constexpr int foo(F f) {
+  return f.i + f.U.f; // ref-note {{read of member 'f' of union with active member 'a'}}
+}
+static_assert(foo(F()) == 0, ""); // ref-error {{not an integral constant expression}} \
+  // ref-note {{in call to}}
+  }
+#endif
+
+#if __cplusplus >= 202002L
+  namespace Failure {
+struct S {
+  int a;
+  F f{12};
+};
+constexpr int foo(S x) {
+  return x.a; // expected-note {{read of uninitialized object}} \
+  // ref-note {{read of uninitialized object}}
+}
+static_assert(foo(S()) == 0, ""); // expected-error {{not an integral constant expression}} \
+  // expected-note {{in call to}} \
+  // ref-error {{not an integral constant expression}} \
+  // ref-note {{in call to}}
+  };
+#endif
+}
Index: clang/lib/AST/Interp/Descriptor.h
===
--- clang/lib/AST/Interp/Descriptor.h
+++ clang/lib/AST/Interp/Descriptor.h
@@ -140,6 +140,7 @@
  bool IsTemporary, bool IsMutable);
 
   QualType getType() const;
+  QualType getElemQualType() const;
   SourceLocation getLocation() const;
 
   const Decl *asDecl() const { return Source.dyn_cast(); }
Index: clang/lib/AST/Interp/Descriptor.cpp
===
--- clang/lib/AST/Interp/Descriptor.cpp
+++ clang/lib/AST/Interp/Descriptor.cpp
@@ -289,6 +289,12 @@
   llvm_unreachable("Invalid descriptor type");
 }
 
+QualType Descriptor::getElemQualType() const {
+  assert(isArray());
+  const auto *AT = cast(getType());
+  return AT->getElementType();
+}
+
 SourceLocation Descriptor::getLocation() const {
   if (auto *D = Source.dyn_cast())
 return D->getLocation();
Index: clang/lib/AST/Interp/ByteCodeExprGen.h
===
--- clang/lib/AST/Interp/ByteCodeExprGen.h
+++ clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -222,6 +222,7 @@
 
   /// Emits a zero initializer.
   bool visitZeroInitializer(QualType QT, const Expr *E);
+  bool visitZeroRecordInitializer(const Record *R, const Expr *E);
 
   enum class DerefKind {
 /// Value is read and pushed to stack.
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1394,7 +1394,15 @@
   assert(!classify(T));
 
   if (T->isRecordType()) {
-const Function *Func = getFunction(E->getConstructor());
+const CXXConstructorDecl *Ctor = E->getConstructor();
+
+// Trivial zero initialization.
+if (E->requiresZeroInitialization() && Ctor->isTrivial()) {
+   

[PATCH] D155165: [clang][Interp] Fully serialize Floatings to bytes

2023-07-29 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added inline comments.



Comment at: clang/lib/AST/Interp/Source.h:63-64
   /// Pointer into the code owned by a function.
+public:
   const std::byte *Ptr;
 };

aaron.ballman wrote:
> Any chance we can use friendship here as well, rather than exposing the data 
> member directly?
added a `operator*` to `CodePtr`.


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

https://reviews.llvm.org/D155165

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


[PATCH] D156027: [clang][Interp] Rework how initializers work

2023-07-29 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added a comment.

Do you want me to squash the patches I abandoned into this one?


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

https://reviews.llvm.org/D156027

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


[PATCH] D156596: [Clang] Produce a warning instead of an error in unevaluated strings before C++26

2023-07-29 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin created this revision.
Herald added a project: All.
cor3ntin requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D156596

Files:
  clang/include/clang/Basic/DiagnosticLexKinds.td
  clang/lib/Lex/LiteralSupport.cpp
  clang/test/CXX/dcl.dcl/dcl.link/p2.cpp
  clang/test/CXX/dcl.dcl/p4-0x.cpp
  clang/test/SemaCXX/static-assert.cpp

Index: clang/test/SemaCXX/static-assert.cpp
===
--- clang/test/SemaCXX/static-assert.cpp
+++ clang/test/SemaCXX/static-assert.cpp
@@ -29,13 +29,19 @@
 S s1; // expected-note {{in instantiation of template class 'S' requested here}}
 S s2;
 
-static_assert(false, L"\x"); // expected-error {{an unevaluated string literal cannot have an encoding prefix}} \
- // expected-error {{invalid escape sequence '\x' in an unevaluated string literal}}
-static_assert(false, u"\U000317FF"); // expected-error {{an unevaluated string literal cannot have an encoding prefix}}
-// FIXME: render this as u8"\u03A9"
-static_assert(false, u8"Ω"); // expected-error {{an unevaluated string literal cannot have an encoding prefix}}
-static_assert(false, L"\u1234"); // expected-error {{an unevaluated string literal cannot have an encoding prefix}}
-static_assert(false, L"\x1ff"// expected-error {{an unevaluated string literal cannot have an encoding prefix}} \
+static_assert(false, L"\x"); // expected-warning {{encoding prefix 'L' on an unevaluated string literal has no effect and is incompatible with c++2c}} \
+ // expected-error {{invalid escape sequence '\x' in an unevaluated string literal}} \
+ // expected-error {{hex escape sequence out of range}}
+static_assert(false, u"\U000317FF"); // expected-warning {{encoding prefix 'u' on an unevaluated string literal has no effect and is incompatible with c++2c}} \
+ // expected-error {{static assertion failed}}
+
+static_assert(false, u8"Ω"); // expected-warning {{encoding prefix 'u8' on an unevaluated string literal has no effect and is incompatible with c++2c}} \
+ // expected-error {{static assertion failed: Ω}}
+static_assert(false, L"\u1234"); // expected-warning {{encoding prefix 'L' on an unevaluated string literal has no effect and is incompatible with c++2c}} \
+ // expected-error {{static assertion failed: ሴ}}
+
+static_assert(false, L"\x1ff"// expected-warning {{encoding prefix 'L' on an unevaluated string literal has no effect and is incompatible with c++2c}} \
+ // expected-error {{hex escape sequence out of range}} \
  // expected-error {{invalid escape sequence '\x1ff' in an unevaluated string literal}}
  "0\x123"// expected-error {{invalid escape sequence '\x123' in an unevaluated string literal}}
  "fx\xf" // expected-error {{invalid escape sequence '\xf' in an unevaluated string literal}}
Index: clang/test/CXX/dcl.dcl/p4-0x.cpp
===
--- clang/test/CXX/dcl.dcl/p4-0x.cpp
+++ clang/test/CXX/dcl.dcl/p4-0x.cpp
@@ -18,7 +18,7 @@
 static_assert(T(), "");
 static_assert(U(), ""); // expected-error {{ambiguous}}
 
-static_assert(false, L"\x14hi" // expected-error {{an unevaluated string literal cannot have an encoding prefix}} \
+static_assert(false, L"\x14hi" // expected-warning {{encoding prefix 'L' on an unevaluated string literal has no effect and is incompatible with c++2c}} \
// expected-error {{invalid escape sequence '\x14' in an unevaluated string literal}}
  "!"
  R"x(")x");
Index: clang/test/CXX/dcl.dcl/dcl.link/p2.cpp
===
--- clang/test/CXX/dcl.dcl/dcl.link/p2.cpp
+++ clang/test/CXX/dcl.dcl/dcl.link/p2.cpp
@@ -8,7 +8,7 @@
 extern "C" plusplus {
 }
 
-extern u8"C" {}  // expected-error {{an unevaluated string literal cannot have an encoding prefix}}
-extern L"C" {}   // expected-error {{an unevaluated string literal cannot have an encoding prefix}}
-extern u"C++" {} // expected-error {{an unevaluated string literal cannot have an encoding prefix}}
-extern U"C" {}   // expected-error {{an unevaluated string literal cannot have an encoding prefix}}
+extern u8"C" {}  // expected-warning {{encoding prefix 'u8' on an unevaluated string literal has no effect and is incompatible with c++2c}}
+extern L"C" {}   // expected-warning {{encoding prefix 'L' on an unevaluated string literal has no effect and is incompatible with c++2c}}
+extern u"C++" {} // expected-warning {{encoding prefix 'u' on an unev

[PATCH] D156597: [Clang] Handle static_assert messages with an expression started by a literal

2023-07-29 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin created this revision.
Herald added a project: All.
cor3ntin requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D156597

Files:
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/test/SemaCXX/static-assert-cxx26.cpp


Index: clang/test/SemaCXX/static-assert-cxx26.cpp
===
--- clang/test/SemaCXX/static-assert-cxx26.cpp
+++ clang/test/SemaCXX/static-assert-cxx26.cpp
@@ -65,6 +65,10 @@
 }
 };
 
+constexpr string_view operator+(auto, string_view S) {
+return S;
+}
+
 constexpr const char g_[] = "long string";
 
 template 
@@ -79,6 +83,11 @@
 };
 
 static_assert(false, string_view("test")); // expected-error {{static 
assertion failed: test}}
+static_assert(false, "Literal" + string_view("test")); // expected-error 
{{static assertion failed: test}}
+static_assert(false, L"Wide Literal" + string_view("test")); // expected-error 
{{static assertion failed: test}}
+static_assert(false, "Wild" "Literal" "Concatenation" + string_view("test")); 
// expected-error {{static assertion failed: test}}
+static_assert(false, "Wild" "Literal" L"Concatenation" + string_view("test")); 
// expected-error {{static assertion failed: test}}
+static_assert(false, "Wild" u"Literal" L"Concatenation" + 
string_view("test")); // expected-error {{unsupported non-standard 
concatenation of string literals}}
 static_assert(false, string_view("😀")); // expected-error {{static assertion 
failed: 😀}}
 static_assert(false, string_view(0, nullptr)); // expected-error {{static 
assertion failed:}}
 static_assert(false, string_view(1, "ABC")); // expected-error {{static 
assertion failed: A}}
Index: clang/lib/Parse/ParseDeclCXX.cpp
===
--- clang/lib/Parse/ParseDeclCXX.cpp
+++ clang/lib/Parse/ParseDeclCXX.cpp
@@ -1016,10 +1016,23 @@
   return nullptr;
 }
 
-if (isTokenStringLiteral())
-  AssertMessage = ParseUnevaluatedStringLiteralExpression();
-else if (getLangOpts().CPlusPlus26)
+bool ParseAsExression = false;
+if(getLangOpts().CPlusPlus26) {
+  for(unsigned I = 0; ; ++I) {
+const Token & T = GetLookAheadToken(I);
+if(T.is(tok::r_paren))
+  break;
+if(T.isNot(tok::string_literal)) {
+  ParseAsExression = true;
+  break;
+}
+  }
+}
+
+if(ParseAsExression)
   AssertMessage = ParseConstantExpressionInExprEvalContext();
+else if (isTokenStringLiteral())
+  AssertMessage = ParseUnevaluatedStringLiteralExpression();
 else {
   Diag(Tok, diag::err_expected_string_literal)
   << /*Source='static_assert'*/ 1;


Index: clang/test/SemaCXX/static-assert-cxx26.cpp
===
--- clang/test/SemaCXX/static-assert-cxx26.cpp
+++ clang/test/SemaCXX/static-assert-cxx26.cpp
@@ -65,6 +65,10 @@
 }
 };
 
+constexpr string_view operator+(auto, string_view S) {
+return S;
+}
+
 constexpr const char g_[] = "long string";
 
 template 
@@ -79,6 +83,11 @@
 };
 
 static_assert(false, string_view("test")); // expected-error {{static assertion failed: test}}
+static_assert(false, "Literal" + string_view("test")); // expected-error {{static assertion failed: test}}
+static_assert(false, L"Wide Literal" + string_view("test")); // expected-error {{static assertion failed: test}}
+static_assert(false, "Wild" "Literal" "Concatenation" + string_view("test")); // expected-error {{static assertion failed: test}}
+static_assert(false, "Wild" "Literal" L"Concatenation" + string_view("test")); // expected-error {{static assertion failed: test}}
+static_assert(false, "Wild" u"Literal" L"Concatenation" + string_view("test")); // expected-error {{unsupported non-standard concatenation of string literals}}
 static_assert(false, string_view("😀")); // expected-error {{static assertion failed: 😀}}
 static_assert(false, string_view(0, nullptr)); // expected-error {{static assertion failed:}}
 static_assert(false, string_view(1, "ABC")); // expected-error {{static assertion failed: A}}
Index: clang/lib/Parse/ParseDeclCXX.cpp
===
--- clang/lib/Parse/ParseDeclCXX.cpp
+++ clang/lib/Parse/ParseDeclCXX.cpp
@@ -1016,10 +1016,23 @@
   return nullptr;
 }
 
-if (isTokenStringLiteral())
-  AssertMessage = ParseUnevaluatedStringLiteralExpression();
-else if (getLangOpts().CPlusPlus26)
+bool ParseAsExression = false;
+if(getLangOpts().CPlusPlus26) {
+  for(unsigned I = 0; ; ++I) {
+const Token & T = GetLookAheadToken(I);
+if(T.is(tok::r_paren))
+  break;
+if(T.isNot(tok::string_literal)) {
+  ParseAsExression = true;
+  break;
+}
+  }
+}
+
+if(ParseAsExression)
   AssertMessage = ParseConstantE

[PATCH] D149015: [clang-tidy] Added bugprone-inc-dec-in-conditions check

2023-07-29 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL updated this revision to Diff 545371.
PiotrZSL marked 4 inline comments as done.
PiotrZSL edited the summary of this revision.
PiotrZSL added a comment.

Rebase + Fix review comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149015

Files:
  clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
  clang-tools-extra/clang-tidy/bugprone/IncDecInConditionsCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/IncDecInConditionsCheck.h
  clang-tools-extra/clang-tidy/utils/CMakeLists.txt
  clang-tools-extra/clang-tidy/utils/Matchers.cpp
  clang-tools-extra/clang-tidy/utils/Matchers.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/bugprone/inc-dec-in-conditions.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/test/clang-tidy/checkers/bugprone/inc-dec-in-conditions.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone/inc-dec-in-conditions.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone/inc-dec-in-conditions.cpp
@@ -0,0 +1,70 @@
+// RUN: %check_clang_tidy %s bugprone-inc-dec-in-conditions %t
+
+template
+struct Iterator {
+  Iterator operator++(int);
+  Iterator operator--(int);
+  Iterator& operator++();
+  Iterator& operator--();
+  T operator*();
+  bool operator==(Iterator) const;
+  bool operator!=(Iterator) const;
+};
+
+template
+struct Container {
+  Iterator begin();
+  Iterator end();
+};
+
+bool f(int x) {
+  return (++x != 5 or x == 10);
+  // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: incrementing and referencing a variable in a complex condition can cause unintended side-effects due to C++'s order of evaluation, consider moving the modification outside of the condition to avoid misunderstandings [bugprone-inc-dec-in-conditions]
+}
+
+bool f2(int x) {
+  return (x++ != 5 or x == 10);
+  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: incrementing and referencing a variable in a complex condition can cause unintended side-effects due to C++'s order of evaluation, consider moving the modification outside of the condition to avoid misunderstandings [bugprone-inc-dec-in-conditions]
+}
+
+bool c(Container x) {
+  auto it = x.begin();
+  return (it++ != x.end() and *it);
+  // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: incrementing and referencing a variable in a complex condition can cause unintended side-effects due to C++'s order of evaluation, consider moving the modification outside of the condition to avoid misunderstandings [bugprone-inc-dec-in-conditions]
+}
+
+bool c2(Container x) {
+  auto it = x.begin();
+  return (++it != x.end() and *it);
+  // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: incrementing and referencing a variable in a complex condition can cause unintended side-effects due to C++'s order of evaluation, consider moving the modification outside of the condition to avoid misunderstandings [bugprone-inc-dec-in-conditions]
+}
+
+bool d(int x) {
+  return (--x != 5 or x == 10);
+  // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: decrementing and referencing a variable in a complex condition can cause unintended side-effects due to C++'s order of evaluation, consider moving the modification outside of the condition to avoid misunderstandings [bugprone-inc-dec-in-conditions]
+}
+
+bool d2(int x) {
+  return (x-- != 5 or x == 10);
+  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: decrementing and referencing a variable in a complex condition can cause unintended side-effects due to C++'s order of evaluation, consider moving the modification outside of the condition to avoid misunderstandings [bugprone-inc-dec-in-conditions]
+}
+
+bool g(Container x) {
+  auto it = x.begin();
+  return (it-- != x.end() and *it);
+  // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: decrementing and referencing a variable in a complex condition can cause unintended side-effects due to C++'s order of evaluation, consider moving the modification outside of the condition to avoid misunderstandings [bugprone-inc-dec-in-conditions]
+}
+
+bool g2(Container x) {
+  auto it = x.begin();
+  return (--it != x.end() and *it);
+  // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: decrementing and referencing a variable in a complex condition can cause unintended side-effects due to C++'s order of evaluation, consider moving the modification outside of the condition to avoid misunderstandings [bugprone-inc-dec-in-conditions]
+}
+
+bool doubleCheck(Container x) {
+  auto it = x.begin();
+  auto it2 = x.begin();
+  return (--it != x.end() and ++it2 != x.end()) and (*it == *it2);
+  // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: decrementing and referencing a variable in a complex condition can cause unintended side-effects due to C++'s order of evaluation, consider moving the modification outside of the condition to avoid misund

[PATCH] D147357: [clang-tidy] Add bugprone-optional-value-conversion check

2023-07-29 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL updated this revision to Diff 545372.
PiotrZSL added a comment.

Rebase + Ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147357

Files:
  clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
  clang-tools-extra/clang-tidy/bugprone/OptionalValueConversionCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/OptionalValueConversionCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/bugprone/optional-value-conversion.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/test/clang-tidy/checkers/bugprone/optional-value-conversion.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone/optional-value-conversion.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone/optional-value-conversion.cpp
@@ -0,0 +1,213 @@
+// RUN: %check_clang_tidy -std=c++17-or-later %s bugprone-optional-value-conversion %t -- --fix-notes
+// RUN: %check_clang_tidy -check-suffix=CUSTOM -std=c++17-or-later %s bugprone-optional-value-conversion %t -- \
+// RUN: -config="{CheckOptions: [{key: 'bugprone-optional-value-conversion.OptionalTypes', value: 'CustomOptional'}, \
+// RUN:  {key: 'bugprone-optional-value-conversion.ValueMethods', value: '::Read$;::Ooo$'}]}" --fix-notes
+
+namespace std {
+  template
+  struct optional
+  {
+constexpr optional() noexcept;
+constexpr optional(T&&) noexcept;
+constexpr optional(const T&) noexcept;
+template
+constexpr optional(U&&) noexcept;
+const T& operator*() const;
+T* operator->();
+const T* operator->() const;
+T& operator*();
+const T& value() const;
+T& value();
+const T& get() const;
+T& get();
+T value_or(T) const;
+  };
+
+  template 
+  T&& move(T &x) {
+return static_cast(x);
+  }
+}
+
+namespace boost {
+  template
+  struct optional {
+constexpr optional() noexcept;
+constexpr optional(const T&) noexcept;
+const T& operator*() const;
+const T& get() const;
+  };
+}
+
+namespace absl {
+  template
+  struct optional {
+constexpr optional() noexcept;
+constexpr optional(const T&) noexcept;
+const T& operator*() const;
+const T& value() const;
+  };
+}
+
+template
+struct CustomOptional {
+  CustomOptional();
+  CustomOptional(const T&);
+  const T& Read() const;
+  T& operator*();
+  T& Ooo();
+};
+
+void takeOptionalValue(std::optional);
+void takeOptionalRef(const std::optional&);
+void takeOptionalRRef(std::optional&&);
+void takeOtherOptional(std::optional);
+void takeBOptionalValue(boost::optional);
+void takeAOptionalValue(absl::optional);
+
+void incorrect(std::optional param)
+{
+  std::optional* ptr = ¶m;
+  takeOptionalValue(**ptr);
+  // CHECK-MESSAGES: :[[@LINE-1]]:21: warning: conversion from 'std::optional' into 'int' and back into 'std::optional', remove potentially error-prone optional dereference [bugprone-optional-value-conversion]
+  // CHECK-FIXES: takeOptionalValue(*ptr);
+  takeOptionalValue(*param);
+  // CHECK-MESSAGES: :[[@LINE-1]]:21: warning: conversion from 'std::optional' into 'int' and back into 'std::optional', remove potentially error-prone optional dereference [bugprone-optional-value-conversion]
+  // CHECK-FIXES: takeOptionalValue(param);
+  takeOptionalValue(param.value());
+  // CHECK-MESSAGES: :[[@LINE-1]]:21: warning: conversion from 'std::optional' into 'int' and back into 'std::optional', remove potentially error-prone optional dereference [bugprone-optional-value-conversion]
+  // CHECK-FIXES: takeOptionalValue(param);
+  takeOptionalValue(ptr->value());
+  // CHECK-MESSAGES: :[[@LINE-1]]:21: warning: conversion from 'std::optional' into 'int' and back into 'std::optional', remove potentially error-prone optional dereference [bugprone-optional-value-conversion]
+  // CHECK-FIXES: takeOptionalValue(*ptr);
+  takeOptionalValue(param.operator*());
+  // CHECK-MESSAGES: :[[@LINE-1]]:21: warning: conversion from 'std::optional' into 'int' and back into 'std::optional', remove potentially error-prone optional dereference [bugprone-optional-value-conversion]
+  // CHECK-FIXES: takeOptionalValue(param);
+  takeOptionalValue(ptr->operator*());
+  // CHECK-MESSAGES: :[[@LINE-1]]:21: warning: conversion from 'std::optional' into 'int' and back into 'std::optional', remove potentially error-prone optional dereference [bugprone-optional-value-conversion]
+  // CHECK-FIXES: takeOptionalValue(*ptr);
+  takeOptionalRef(*param);
+  // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: conversion from 'std::optional' into 'int' and back into 'std::optional', remove potentially error-prone optional dereference [bugprone-optional-value-conversion]
+  // CHECK-FIXES: takeOptionalRef(param);
+  takeOptionalRef(param.value());
+  // CHECK-MESSAGES: :[

[PATCH] D141892: [clang-tidy] Implement modernize-use-constraints

2023-07-29 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL added inline comments.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/modernize/use-constraints.rst:4
+modernize-use-constraints
+==
+




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141892

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


[PATCH] D156596: [Clang] Produce a warning instead of an error in unevaluated strings before C++26

2023-07-29 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 545374.
cor3ntin added a comment.

Format + Add FixIt tests


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156596

Files:
  clang/include/clang/Basic/DiagnosticLexKinds.td
  clang/lib/Lex/LiteralSupport.cpp
  clang/test/CXX/dcl.dcl/dcl.link/p2.cpp
  clang/test/CXX/dcl.dcl/p4-0x.cpp
  clang/test/FixIt/unevaluated-strings.cpp
  clang/test/SemaCXX/static-assert.cpp

Index: clang/test/SemaCXX/static-assert.cpp
===
--- clang/test/SemaCXX/static-assert.cpp
+++ clang/test/SemaCXX/static-assert.cpp
@@ -29,13 +29,19 @@
 S s1; // expected-note {{in instantiation of template class 'S' requested here}}
 S s2;
 
-static_assert(false, L"\x"); // expected-error {{an unevaluated string literal cannot have an encoding prefix}} \
- // expected-error {{invalid escape sequence '\x' in an unevaluated string literal}}
-static_assert(false, u"\U000317FF"); // expected-error {{an unevaluated string literal cannot have an encoding prefix}}
-// FIXME: render this as u8"\u03A9"
-static_assert(false, u8"Ω"); // expected-error {{an unevaluated string literal cannot have an encoding prefix}}
-static_assert(false, L"\u1234"); // expected-error {{an unevaluated string literal cannot have an encoding prefix}}
-static_assert(false, L"\x1ff"// expected-error {{an unevaluated string literal cannot have an encoding prefix}} \
+static_assert(false, L"\x"); // expected-warning {{encoding prefix 'L' on an unevaluated string literal has no effect and is incompatible with c++2c}} \
+ // expected-error {{invalid escape sequence '\x' in an unevaluated string literal}} \
+ // expected-error {{hex escape sequence out of range}}
+static_assert(false, u"\U000317FF"); // expected-warning {{encoding prefix 'u' on an unevaluated string literal has no effect and is incompatible with c++2c}} \
+ // expected-error {{static assertion failed}}
+
+static_assert(false, u8"Ω"); // expected-warning {{encoding prefix 'u8' on an unevaluated string literal has no effect and is incompatible with c++2c}} \
+ // expected-error {{static assertion failed: Ω}}
+static_assert(false, L"\u1234"); // expected-warning {{encoding prefix 'L' on an unevaluated string literal has no effect and is incompatible with c++2c}} \
+ // expected-error {{static assertion failed: ሴ}}
+
+static_assert(false, L"\x1ff"// expected-warning {{encoding prefix 'L' on an unevaluated string literal has no effect and is incompatible with c++2c}} \
+ // expected-error {{hex escape sequence out of range}} \
  // expected-error {{invalid escape sequence '\x1ff' in an unevaluated string literal}}
  "0\x123"// expected-error {{invalid escape sequence '\x123' in an unevaluated string literal}}
  "fx\xf" // expected-error {{invalid escape sequence '\xf' in an unevaluated string literal}}
Index: clang/test/FixIt/unevaluated-strings.cpp
===
--- /dev/null
+++ clang/test/FixIt/unevaluated-strings.cpp
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 -verify -std=c++2c %s
+// RUN: cp %s %t
+// RUN: not %clang_cc1 -x c++ -std=c++2c -fixit %t
+// RUN: %clang_cc1 -x c++ -std=c++2c %t
+// RUN: not %clang_cc1 -std=c++2c -x c++ -fsyntax-only -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
+
+static_assert(true, L""); // expected-error{{an unevaluated string literal cannot have an encoding prefix}}
+// CHECK: fix-it:{{.*}}:{7:21-7:22}
+
+static_assert(true, u8""); // expected-error{{an unevaluated string literal cannot have an encoding prefix}}
+// CHECK: fix-it:{{.*}}:{10:21-10:23}
+
+static_assert(true, u""); // expected-error{{an unevaluated string literal cannot have an encoding prefix}}
+// CHECK: fix-it:{{.*}}:{13:21-13:22}
+
+static_assert(true, U""); // expected-error{{an unevaluated string literal cannot have an encoding prefix}}
+// CHECK: fix-it:{{.*}}:{16:21-16:22}
Index: clang/test/CXX/dcl.dcl/p4-0x.cpp
===
--- clang/test/CXX/dcl.dcl/p4-0x.cpp
+++ clang/test/CXX/dcl.dcl/p4-0x.cpp
@@ -18,7 +18,7 @@
 static_assert(T(), "");
 static_assert(U(), ""); // expected-error {{ambiguous}}
 
-static_assert(false, L"\x14hi" // expected-error {{an unevaluated string literal cannot have an encoding prefix}} \
+static_assert(false, L"\x14hi" // expected-warning {{encoding prefix 'L' on an unevaluated string literal has no effect and is incompatible with c++2c}} \
// expected-error {{invalid escape sequence '\x14' in an

[PATCH] D156599: [profiling] Move option declarations into headers

2023-07-29 Thread Tom Stellard via Phabricator via cfe-commits
tstellar created this revision.
tstellar added reviewers: bogner, dnovillo, hoy, huangjd.
Herald added subscribers: wlei, Enna1, ormris, wenlei, hiraditya.
Herald added a project: All.
tstellar requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

This will make it possible to add visibility attributes to these
variables.  This also fixes some type mismatches between the
declaration and the definition.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D156599

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  llvm/include/llvm/ProfileData/ProfileCommon.h
  llvm/include/llvm/Transforms/IPO/SampleProfile.h
  llvm/include/llvm/Transforms/Instrumentation/PGOInstrumentation.h
  llvm/lib/Analysis/ProfileSummaryInfo.cpp
  llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
  llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
  llvm/tools/llvm-profgen/CSPreInliner.cpp

Index: llvm/tools/llvm-profgen/CSPreInliner.cpp
===
--- llvm/tools/llvm-profgen/CSPreInliner.cpp
+++ llvm/tools/llvm-profgen/CSPreInliner.cpp
@@ -11,6 +11,7 @@
 #include "llvm/ADT/SCCIterator.h"
 #include "llvm/ADT/Statistic.h"
 #include "llvm/DebugInfo/Symbolize/SymbolizableModule.h"
+#include "llvm/Transforms/IPO/SampleProfile.h"
 #include 
 #include 
 
@@ -35,13 +36,6 @@
 // TODO: the actual threshold to be tuned here because the size here is based
 // on machine code not LLVM IR.
 namespace llvm {
-extern cl::opt SampleHotCallSiteThreshold;
-extern cl::opt SampleColdCallSiteThreshold;
-extern cl::opt ProfileInlineGrowthLimit;
-extern cl::opt ProfileInlineLimitMin;
-extern cl::opt ProfileInlineLimitMax;
-extern cl::opt SortProfiledSCC;
-
 cl::opt EnableCSPreInliner(
 "csspgo-preinliner", cl::Hidden, cl::init(true),
 cl::desc("Run a global pre-inliner to merge context profile based on "
Index: llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
===
--- llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
+++ llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
@@ -327,7 +327,6 @@
 // Defined in Analysis/BlockFrequencyInfo.cpp:  -view-bfi-func-name=
 extern cl::opt ViewBlockFreqFuncName;
 
-extern cl::opt DebugInfoCorrelate;
 } // namespace llvm
 
 static cl::opt
Index: llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
===
--- llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
+++ llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
@@ -47,6 +47,7 @@
 #include "llvm/Support/Error.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/TargetParser/Triple.h"
+#include "llvm/Transforms/Instrumentation/PGOInstrumentation.h"
 #include "llvm/Transforms/Utils/ModuleUtils.h"
 #include "llvm/Transforms/Utils/SSAUpdater.h"
 #include 
Index: llvm/lib/Analysis/ProfileSummaryInfo.cpp
===
--- llvm/lib/Analysis/ProfileSummaryInfo.cpp
+++ llvm/lib/Analysis/ProfileSummaryInfo.cpp
@@ -23,16 +23,6 @@
 #include 
 using namespace llvm;
 
-// Knobs for profile summary based thresholds.
-namespace llvm {
-extern cl::opt ProfileSummaryCutoffHot;
-extern cl::opt ProfileSummaryCutoffCold;
-extern cl::opt ProfileSummaryHugeWorkingSetSizeThreshold;
-extern cl::opt ProfileSummaryLargeWorkingSetSizeThreshold;
-extern cl::opt ProfileSummaryHotCount;
-extern cl::opt ProfileSummaryColdCount;
-} // namespace llvm
-
 static cl::opt PartialProfile(
 "partial-profile", cl::Hidden, cl::init(false),
 cl::desc("Specify the current profile is used as a partial profile."));
Index: llvm/include/llvm/Transforms/Instrumentation/PGOInstrumentation.h
===
--- llvm/include/llvm/Transforms/Instrumentation/PGOInstrumentation.h
+++ llvm/include/llvm/Transforms/Instrumentation/PGOInstrumentation.h
@@ -18,11 +18,14 @@
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/IntrusiveRefCntPtr.h"
 #include "llvm/IR/PassManager.h"
+#include "llvm/Support/CommandLine.h"
 #include 
 #include 
 
 namespace llvm {
 
+extern cl::opt DebugInfoCorrelate;
+
 class Function;
 class Instruction;
 class Module;
Index: llvm/include/llvm/Transforms/IPO/SampleProfile.h
===
--- llvm/include/llvm/Transforms/IPO/SampleProfile.h
+++ llvm/include/llvm/Transforms/IPO/SampleProfile.h
@@ -17,12 +17,20 @@
 #include "llvm/ADT/IntrusiveRefCntPtr.h"
 #include "llvm/IR/PassManager.h"
 #include "llvm/Pass.h"
+#include "llvm/Support/CommandLine.h"
 #include 
 
 namespace llvm {
 
 class Module;
 
+extern cl::opt SampleHotCallSiteThreshold;
+extern cl::opt SampleColdCallSiteThreshold;
+extern cl::opt ProfileInlineGrowthLimit;
+extern cl::opt ProfileInlineLimitMin;
+extern cl::opt ProfileInlineLimitMax;
+extern cl::opt S

[PATCH] D149015: [clang-tidy] Added bugprone-inc-dec-in-conditions check

2023-07-29 Thread Shivam Gupta via Phabricator via cfe-commits
xgupta accepted this revision.
xgupta 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/D149015/new/

https://reviews.llvm.org/D149015

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


[PATCH] D156597: [Clang] Handle static_assert messages with an expression started by a literal

2023-07-29 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added inline comments.



Comment at: clang/lib/Parse/ParseDeclCXX.cpp:1019
 
-if (isTokenStringLiteral())
-  AssertMessage = ParseUnevaluatedStringLiteralExpression();
-else if (getLangOpts().CPlusPlus26)
+bool ParseAsExression = false;
+if(getLangOpts().CPlusPlus26) {




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156597

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


[PATCH] D140828: [C++] Implement "Deducing this" (P0847R7)

2023-07-29 Thread Hristo Hristov via Phabricator via cfe-commits
Zingam added a comment.

Is this going to land soon? There is a libc++ paper I'm interested in that 
relies on "deducing this" and I wonder if I should wait for "this" first before 
I start working on it?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140828

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


[PATCH] D140828: [C++] Implement "Deducing this" (P0847R7)

2023-07-29 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added a comment.

In D140828#4544433 , @Zingam wrote:

> Is this going to land soon? There is a libc++ paper I'm interested in that 
> relies on "deducing this" and I wonder if I should wait for "this" first 
> before I start working on it?

Hard to tell. Maybe in the next few weeks depending on reviewers availability. 
I'm curious, what paper is that?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140828

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


[PATCH] D141892: [clang-tidy] Implement modernize-use-constraints

2023-07-29 Thread Chris Cotter via Phabricator via cfe-commits
ccotter updated this revision to Diff 545379.
ccotter added a comment.

- Fix docs


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141892

Files:
  clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
  clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
  clang-tools-extra/clang-tidy/modernize/UseConstraintsCheck.cpp
  clang-tools-extra/clang-tidy/modernize/UseConstraintsCheck.h
  clang-tools-extra/clang-tidy/utils/LexerUtils.cpp
  clang-tools-extra/clang-tidy/utils/LexerUtils.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/docs/clang-tidy/checks/modernize/use-constraints.rst
  
clang-tools-extra/test/clang-tidy/checkers/modernize/use-constraints-first-greatergreater.cpp
  clang-tools-extra/test/clang-tidy/checkers/modernize/use-constraints.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/modernize/use-constraints.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/modernize/use-constraints.cpp
@@ -0,0 +1,726 @@
+// RUN: %check_clang_tidy -std=c++20 %s modernize-use-constraints %t -- -- -fno-delayed-template-parsing
+
+// NOLINTBEGIN
+namespace std {
+template  struct enable_if { };
+
+template  struct enable_if { typedef T type; };
+
+template 
+using enable_if_t = typename enable_if::type;
+
+} // namespace std
+// NOLINTEND
+
+template 
+struct ConsumeVariadic;
+
+struct Obj {
+};
+
+namespace enable_if_in_return_type {
+
+
+// Section 1: enable_if in return type of function
+
+
+
+// General tests
+
+
+template 
+typename std::enable_if::type basic() {
+  return Obj{};
+}
+// CHECK-MESSAGES: :[[@LINE-3]]:1: warning: use C++20 requires constraints instead of enable_if [modernize-use-constraints]
+// CHECK-FIXES: {{^}}Obj basic() requires T::some_value {{{$}}
+
+template 
+std::enable_if_t basic_t() {
+  return Obj{};
+}
+// CHECK-MESSAGES: :[[@LINE-3]]:1: warning: use C++20 requires constraints instead of enable_if [modernize-use-constraints]
+// CHECK-FIXES: {{^}}Obj basic_t() requires T::some_value {{{$}}
+
+template 
+auto basic_trailing() -> typename std::enable_if::type {
+  return Obj{};
+}
+// CHECK-MESSAGES: :[[@LINE-3]]:26: warning: use C++20 requires constraints instead of enable_if [modernize-use-constraints]
+// CHECK-FIXES: {{^}}auto basic_trailing() -> Obj requires T::some_value {{{$}}
+
+template 
+typename std::enable_if::type existing_constraint() requires (T::another_value) {
+  return Obj{};
+}
+// CHECK-MESSAGES: :[[@LINE-3]]:1: warning: use C++20 requires constraints instead of enable_if [modernize-use-constraints]
+// CHECK-FIXES: {{^}}typename std::enable_if::type existing_constraint() requires (T::another_value) {{{$}}
+
+template 
+typename std::enable_if::type decl_without_def();
+
+template 
+typename std::enable_if::type decl_with_separate_def();
+
+template 
+typename std::enable_if::type decl_with_separate_def() {
+  return Obj{};
+}
+// FIXME - Support definitions with separate decls
+
+template 
+std::enable_if_t no_dependent_type(U) {
+  return Obj{};
+}
+// FIXME - Support non-dependent enable_ifs. Low priority though...
+
+template 
+typename std::enable_if::type* pointer_of_enable_if() {
+  return nullptr;
+}
+// CHECK-MESSAGES: :[[@LINE-3]]:1: warning: use C++20 requires constraints instead of enable_if [modernize-use-constraints]
+// CHECK-FIXES: {{^}}template {{$}}
+// CHECK-FIXES-NEXT: {{^}}int* pointer_of_enable_if() requires T::some_value {{{$}}
+
+template 
+std::enable_if_t* pointer_of_enable_if_t() {
+  return nullptr;
+}
+// CHECK-MESSAGES: :[[@LINE-3]]:1: warning: use C++20 requires constraints instead of enable_if [modernize-use-constraints]
+// CHECK-FIXES: {{^}}template {{$}}
+// CHECK-FIXES-NEXT: {{^}}int* pointer_of_enable_if_t() requires T::some_value {{{$}}
+
+template 
+const std::enable_if_t* const_pointer_of_enable_if_t() {
+  return nullptr;
+}
+// CHECK-MESSAGES: :[[@LINE-3]]:7: warning: use C++20 requires constraints instead of enable_if [modernize-use-constraints]
+// CHECK-FIXES: {{^}}template {{$}}
+// CHECK-FIXES-NEXT: {{^}}const int* const_pointer_of_enable_if_t() requires T::some_value {{{$}}
+
+template 
+std::enable_if_t const * const_pointer_of_enable_if_t2() {
+  return nullptr;
+}
+// CHECK-MESSAGES: :[[@LINE-3]]:1: warning: use C++20 requires constraints instead of enable_if [modernize-use-constraints]
+// CHECK-FIXES: {{^}}template {{$}}
+// CHECK-FIXES-NEXT: {{^}}int const * const_pointer_of_enable_if_t2() requires T::some_value {{{$}}
+
+
+template 
+std::enable_if_t& reference_of_enable_if_t() {
+  static int x; return x;
+}
+// CHECK-MESSAGES: :[[@LINE-3]]:1: warning: use C++20 requires constraints instead of enable_if [modernize-use-constraints]
+// CH

[PATCH] D141892: [clang-tidy] Implement modernize-use-constraints

2023-07-29 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL accepted this revision.
PiotrZSL added a comment.
This revision is now accepted and ready to land.

Overall this check is complicated, simply because it's doing complicated stuff.

1. Add description to all functions (what is their purpose, what is expected 
outcome, maybe put some "example")
2. Extend documentation, add "supported" constructions, (pre C++20, C++20).
3. What about boost enable_if ? Support it, or restrict check to std only.
4. What about enable_if used as an function argument ? Support it, or add some 
info to documentation that such construction is not supported.

I don't think that this check will ever be "perfect", so LGTM.
We got entire release to "stabilize it".




Comment at: clang-tools-extra/clang-tidy/modernize/UseConstraintsCheck.cpp:54
+  if (const auto Dep = TheType.getAs()) {
+if (Dep.getTypePtr()->getIdentifier()->getName() != "type" ||
+Dep.getTypePtr()->getKeyword() != ETK_Typename) {

what if we do not have Identifier here ?



Comment at: 
clang-tools-extra/clang-tidy/modernize/UseConstraintsCheck.cpp:205-208
+  } else {
+return SourceRange(EnableIf.getLAngleLoc().getLocWithOffset(1),
+   getRAngleFileLoc(SM, EnableIf));
+  }





Comment at: clang-tools-extra/clang-tidy/modernize/UseConstraintsCheck.cpp:352
+  FixIts.push_back(FixItHint::CreateInsertion(
+  *ConstraintInsertionLoc, "requires " + *ConditionText + " "));
+  return FixIts;

You not checking anywhere if this optional is initialized.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/modernize/use-constraints.rst:10
+template based on type traits or other requirements. ``enable_if`` changes the
+meta-arity of the template, and has other `adverse side effects 
`_
+in the code. C++20 introduces concepts and constraints as a cleaner language

move this link to new line, 80 characters limit



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/modernize/use-constraints.rst:20-24
+  template 
+  std::enable_if_t only_if_t_has_the_trait() { ... }
+
+  template  = 0>
+  void another_version() { ... }

Put into documentation also example how this code should look in C++20.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141892

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


[PATCH] D149867: [Clang][M68k] Add Clang support for the new M68k_RTD CC

2023-07-29 Thread Min-Yih Hsu via Phabricator via cfe-commits
myhsu added a comment.

In D149867#4544281 , @glaubitz wrote:

> Any update on this?

Sorry I was busy on my phd defense (which I passed!) in the past month. I'll 
get back to this next week.


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

https://reviews.llvm.org/D149867

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


[PATCH] D154093: [clang-format] Break long strings in Verilog

2023-07-29 Thread Owen Pan via Phabricator via cfe-commits
owenpan added inline comments.



Comment at: clang/lib/Format/ContinuationIndenter.cpp:2152-2154
 // FIXME: String literal breaking is currently disabled for C#, Java, Json
 // and JavaScript, as it requires strings to be merged using "+" which we
 // don't support.

Can we support using `+` first?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154093

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


[PATCH] D154093: [clang-format] Break long strings in Verilog

2023-07-29 Thread Owen Pan via Phabricator via cfe-commits
owenpan added a comment.

In D154093#4542339 , @sstwcw wrote:

> @owenpan What do you think about this revision especially the replacement 
> part?

See D154093#4544495 . Then we can 
extend it by using `,` instead of `+` for Verilog (plus inserting a pair of 
braces).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154093

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


[PATCH] D151373: [libclang] Expose arguments of clang::annotate

2023-07-29 Thread Fridtjof Mund via Phabricator via cfe-commits
fridtjof updated this revision to Diff 545388.
fridtjof added a comment.

Whoops, forgot to run clang-format on the last diff. Also took the opportunity 
to just get rid of the template mess now that we're only dealing with 
AnnotateAttr anyway.


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

https://reviews.llvm.org/D151373

Files:
  clang/docs/ReleaseNotes.rst
  clang/tools/libclang/CIndex.cpp
  clang/tools/libclang/CursorVisitor.h
  clang/unittests/libclang/LibclangTest.cpp

Index: clang/unittests/libclang/LibclangTest.cpp
===
--- clang/unittests/libclang/LibclangTest.cpp
+++ clang/unittests/libclang/LibclangTest.cpp
@@ -1246,6 +1246,50 @@
   EXPECT_EQ(fromCXString(clang_getCursorSpelling(*staticAssertCsr)), "");
 }
 
+TEST_F(LibclangParseTest, ExposesAnnotateArgs) {
+  const char testSource[] = R"cpp(
+[[clang::annotate("category", 42)]]
+void func() {}
+)cpp";
+  std::string fileName = "main.cpp";
+  WriteFile(fileName, testSource);
+
+  const char *Args[] = {"-xc++"};
+  ClangTU = clang_parseTranslationUnit(Index, fileName.c_str(), Args, 1,
+   nullptr, 0, TUFlags);
+
+  int attrCount = 0;
+
+  Traverse(
+  [&attrCount](CXCursor cursor, CXCursor parent) -> CXChildVisitResult {
+if (cursor.kind == CXCursor_AnnotateAttr) {
+  int childCount = 0;
+  clang_visitChildren(
+  cursor,
+  [](CXCursor child, CXCursor,
+ CXClientData data) -> CXChildVisitResult {
+int *pcount = static_cast(data);
+
+// we only expect one argument here, so bail otherwise
+EXPECT_EQ(*pcount, 0);
+
+auto *result = clang_Cursor_Evaluate(child);
+EXPECT_NE(result, nullptr);
+EXPECT_EQ(clang_EvalResult_getAsInt(result), 42);
+++*pcount;
+
+return CXChildVisit_Recurse;
+  },
+  &childCount);
+  attrCount++;
+  return CXChildVisit_Continue;
+}
+return CXChildVisit_Recurse;
+  });
+
+  EXPECT_EQ(attrCount, 1);
+}
+
 class LibclangRewriteTest : public LibclangParseTest {
 public:
   CXRewriter Rew = nullptr;
Index: clang/tools/libclang/CursorVisitor.h
===
--- clang/tools/libclang/CursorVisitor.h
+++ clang/tools/libclang/CursorVisitor.h
@@ -276,7 +276,9 @@
   bool IsInRegionOfInterest(CXCursor C);
   bool RunVisitorWorkList(VisitorWorkList &WL);
   void EnqueueWorkList(VisitorWorkList &WL, const Stmt *S);
+  void EnqueueWorkList(VisitorWorkList &WL, const Attr *A);
   LLVM_ATTRIBUTE_NOINLINE bool Visit(const Stmt *S);
+  LLVM_ATTRIBUTE_NOINLINE bool Visit(const Attr *A);
 
 private:
   std::optional handleDeclForVisitation(const Decl *D);
Index: clang/tools/libclang/CIndex.cpp
===
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/libclang/CIndex.cpp
@@ -23,6 +23,7 @@
 #include "CursorVisitor.h"
 #include "clang-c/FatalErrorHandler.h"
 #include "clang/AST/Attr.h"
+#include "clang/AST/AttrVisitor.h"
 #include "clang/AST/DeclObjCCommon.h"
 #include "clang/AST/Expr.h"
 #include "clang/AST/ExprCXX.h"
@@ -575,6 +576,13 @@
   A->getInterfaceLoc()->getTypeLoc().getBeginLoc(), TU));
   }
 
+  if (clang_isAttribute(Cursor.kind)) {
+if (const Attr *A = getCursorAttr(Cursor))
+  return Visit(A);
+
+return false;
+  }
+
   // If pointing inside a macro definition, check if the token is an identifier
   // that was ever defined as a macro. In such a case, create a "pseudo" macro
   // expansion cursor for that token.
@@ -2089,7 +2097,8 @@
 (SourceLocation::UIntTy)(uintptr_t)data[1]);
   }
 };
-class EnqueueVisitor : public ConstStmtVisitor {
+class EnqueueVisitor : public ConstStmtVisitor,
+   public ConstAttrVisitor {
   friend class OMPClauseEnqueue;
   VisitorWorkList &WL;
   CXCursor Parent;
@@ -2231,6 +2240,9 @@
   void VisitOMPTargetTeamsDistributeSimdDirective(
   const OMPTargetTeamsDistributeSimdDirective *D);
 
+  // Attributes
+  void VisitAnnotateAttr(const AnnotateAttr *A);
+
 private:
   void AddDeclarationNameInfo(const Stmt *S);
   void AddNestedNameSpecifierLoc(NestedNameSpecifierLoc Qualifier);
@@ -2242,6 +2254,7 @@
   void AddTypeLoc(TypeSourceInfo *TI);
   void EnqueueChildren(const Stmt *S);
   void EnqueueChildren(const OMPClause *S);
+  void EnqueueChildren(const AnnotateAttr *A);
 };
 } // namespace
 
@@ -2736,6 +2749,20 @@
   VisitorWorkList::iterator I = WL.begin() + size, E = WL.end();
   std::reverse(I, E);
 }
+
+void EnqueueVisitor::EnqueueChildren(const AnnotateAttr *A) {
+  unsigned size = WL.size();
+  for (const Expr *Arg : A->args()) {
+VisitStmt(Arg);
+  }
+  if (size == WL.size())
+return;
+  // Now reverse the entries we just added.  This will match the DFS
+

[PATCH] D142660: [AIX] supporting -X options for llvm-ranlib in AIX OS

2023-07-29 Thread Digger Lin via Phabricator via cfe-commits
DiggerLin updated this revision to Diff 545392.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142660

Files:
  clang/lib/Driver/OffloadBundler.cpp
  clang/test/lit.cfg.py
  clang/tools/clang-offload-packager/ClangOffloadPackager.cpp
  llvm/include/llvm/Object/Archive.h
  llvm/include/llvm/Object/ArchiveWriter.h
  llvm/lib/ObjCopy/Archive.cpp
  llvm/lib/ObjCopy/MachO/MachOObjcopy.cpp
  llvm/lib/Object/Archive.cpp
  llvm/lib/Object/ArchiveWriter.cpp
  llvm/lib/Object/COFFImportFile.cpp
  llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp
  llvm/test/tools/llvm-ranlib/aix-X-option.test
  llvm/test/tools/llvm-ranlib/non-AIX-not-supportedwq-X-option.test
  llvm/tools/llvm-ar/llvm-ar.cpp
  llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp

Index: llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp
===
--- llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp
+++ llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp
@@ -600,18 +600,17 @@
 
   if (NewMembers.size() == 1)
 return writeArchive(OutputFile, NewMembers.begin()->second.getMembers(),
-/*WriteSymtab=*/true,
+SymtabWritingMode::NormalSymtab,
 /*Kind=*/object::Archive::K_DARWIN, C.Deterministic,
 /*Thin=*/false);
 
   SmallVector, 2> OutputBinaries;
   for (const std::pair &M : NewMembers) {
 Expected> OutputBufferOrErr =
-writeArchiveToBuffer(M.second.getMembers(),
- /*WriteSymtab=*/true,
- /*Kind=*/object::Archive::K_DARWIN,
- C.Deterministic,
- /*Thin=*/false);
+writeArchiveToBuffer(
+M.second.getMembers(), SymtabWritingMode::NormalSymtab,
+/*Kind=*/object::Archive::K_DARWIN, C.Deterministic,
+/*Thin=*/false);
 if (!OutputBufferOrErr)
   return OutputBufferOrErr.takeError();
 std::unique_ptr &OutputBuffer = OutputBufferOrErr.get();
Index: llvm/tools/llvm-ar/llvm-ar.cpp
===
--- llvm/tools/llvm-ar/llvm-ar.cpp
+++ llvm/tools/llvm-ar/llvm-ar.cpp
@@ -61,15 +61,18 @@
 static StringRef Stem;
 
 static void printRanLibHelp(StringRef ToolName) {
-  outs() << "OVERVIEW: LLVM ranlib\n\n"
- << "Generate an index for archives\n\n"
- << "USAGE: " + ToolName + " archive...\n\n"
- << "OPTIONS:\n"
- << "  -h --help - Display available options\n"
- << "  -v --version  - Display the version of this program\n"
- << "  -D- Use zero for timestamps and uids/gids "
-"(default)\n"
- << "  -U- Use actual timestamps and uids/gids\n";
+  outs()
+  << "OVERVIEW: LLVM ranlib\n\n"
+  << "Generate an index for archives\n\n"
+  << "USAGE: " + ToolName + " archive...\n\n"
+  << "OPTIONS:\n"
+  << "  -h --help - Display available options\n"
+  << "  -v --version  - Display the version of this program\n"
+  << "  -D- Use zero for timestamps and uids/gids "
+ "(default)\n"
+  << "  -U- Use actual timestamps and uids/gids\n"
+  << "  -X{32|64|32_64|any}   - Specifies which archive symbol tables "
+ "should be generated if they do not already exist (AIX OS only)\n";
 }
 
 static void printArHelp(StringRef ToolName) {
@@ -225,7 +228,8 @@
 static bool CompareFullPath = false;  ///< 'P' modifier
 static bool OnlyUpdate = false;   ///< 'u' modifier
 static bool Verbose = false;  ///< 'v' modifier
-static bool Symtab = true;///< 's' modifier
+static SymtabWritingMode Symtab =
+SymtabWritingMode::NormalSymtab;  ///< 's' modifier
 static bool Deterministic = true; ///< 'D' and 'U' modifiers
 static bool Thin = false; ///< 'T' modifier
 static bool AddLibrary = false;   ///< 'L' modifier
@@ -371,11 +375,11 @@
   CompareFullPath = true;
   break;
 case 's':
-  Symtab = true;
+  Symtab = SymtabWritingMode::NormalSymtab;
   MaybeJustCreateSymTab = true;
   break;
 case 'S':
-  Symtab = false;
+  Symtab = SymtabWritingMode::NoSymtab;
   break;
 case 'u':
   OnlyUpdate = true;
@@ -1074,9 +1078,27 @@
   // In summary, we only need to update the symbol table if we have none.
   // This is actually very common because of broken build systems that think
   // they have to run ranlib.
-  if (OldArchive->hasSymbolTable())
-return;
+  if (OldArchive->hasSymbolTable()) {
+if (OldArchive->kind() != object::Archive::K_AIXBIG)
+  return;
 
+// For archives in the Big Archive format, the bit mode option specifies
+// which symbol table to g

[PATCH] D156300: [clangd] Avoid unexpected desugaring in isSugaredTemplateParameter

2023-07-29 Thread Younan Zhang via Phabricator via cfe-commits
zyounan added a comment.

Ping~


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156300

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


[PATCH] D156300: [clangd] Avoid unexpected desugaring in isSugaredTemplateParameter

2023-07-29 Thread Nathan Ridge via Phabricator via cfe-commits
nridge added a comment.

Your patience is appreciated. I have a number of patches in my review queue, 
and 3 days is often not a realistic turnaround time for me.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156300

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


[PATCH] D156300: [clangd] Avoid unexpected desugaring in isSugaredTemplateParameter

2023-07-29 Thread Younan Zhang via Phabricator via cfe-commits
zyounan added a comment.

Oops, my apologies for bothering you. Thanks again for the explanation and your 
dedication!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156300

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


[clang] abae53f - [Driver][test] Change some -fuse-ld=lld tests to be agnostic of host ld.lld

2023-07-29 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2023-07-29T19:34:14-07:00
New Revision: abae53f43f0d1da8d8e421f4a628d7ec64d6e365

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

LOG: [Driver][test] Change some -fuse-ld=lld tests to be agnostic of host ld.lld

If program paths (GCC installation, --sysroot, -B, etc) don't contain
ld.lld, whether -fuse-ld=lld succeeds depends on whether a PATH
directory contains ld.lld.

> error: invalid linker name in argument '-fuse-ld=lld'

This behavior is not suitable when we adopt the new strict behavior of
-### in D156363.

For some tests, append -B%S/Inputs/lld similar to D92028.
For others, use -fuse-ld=ld so that getDefaultLinker (instead of 
CLANG_DEFAULT_LINKER) is used. The complexity stems from CLANG_DEFAULT_LINKER.

Added: 
clang/test/Driver/Inputs/lld/ld.lld

Modified: 
clang/test/Driver/csky-toolchain.c
clang/test/Driver/fuchsia.c
clang/test/Driver/fuchsia.cpp
clang/test/Driver/hip-toolchain-no-rdc.hip
clang/test/Driver/hip-toolchain-rdc-separate.hip
clang/test/Driver/hip-toolchain-rdc-static-lib.hip
clang/test/Driver/hip-toolchain-rdc.hip
clang/test/Driver/mingw-lto.c
clang/test/Driver/ohos.c
clang/test/Driver/ohos.cpp
clang/test/Driver/opt-record.c
clang/test/Driver/riscv32-toolchain.c
clang/test/Driver/riscv64-toolchain.c

Removed: 




diff  --git a/clang/test/Driver/Inputs/lld/ld.lld 
b/clang/test/Driver/Inputs/lld/ld.lld
new file mode 100755
index 00..e69de29bb2d1d6

diff  --git a/clang/test/Driver/csky-toolchain.c 
b/clang/test/Driver/csky-toolchain.c
index 5762f5666bca7b..386317ad3e0c67 100644
--- a/clang/test/Driver/csky-toolchain.c
+++ b/clang/test/Driver/csky-toolchain.c
@@ -4,10 +4,6 @@
 // RUN: %clang -### %s --target=csky 2>&1 | FileCheck -check-prefix=CC1 %s
 // CC1: "-cc1" "-triple" "csky"
 
-// Test interaction with -fuse-ld=lld, if lld is available.
-// RUN: %clang -### %s --target=csky -fuse-ld=lld 2>&1 | FileCheck 
-check-prefix=LLD %s
-// LLD: {{(error: invalid linker name in argument '-fuse-ld=lld')|(ld.lld)}}
-
 // In the below tests, --rtlib=platform is used so that the driver ignores
 // the configure-time CLANG_DEFAULT_RTLIB option when choosing the runtime lib
 

diff  --git a/clang/test/Driver/fuchsia.c b/clang/test/Driver/fuchsia.c
index c785e3a52251cd..4415123d69d744 100644
--- a/clang/test/Driver/fuchsia.c
+++ b/clang/test/Driver/fuchsia.c
@@ -1,26 +1,26 @@
 // RUN: %clang -### %s --target=x86_64-unknown-fuchsia \
 // RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \
-// RUN: --sysroot=%S/platform -fuse-ld=lld 2>&1 \
+// RUN: --sysroot=%S/platform -fuse-ld=ld 2>&1 \
 // RUN: | FileCheck -check-prefixes=CHECK,CHECK-X86_64 %s
 // RUN: %clang -### %s --target=aarch64-unknown-fuchsia \
 // RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \
-// RUN: --sysroot=%S/platform -fuse-ld=lld 2>&1 \
+// RUN: --sysroot=%S/platform -fuse-ld=ld 2>&1 \
 // RUN: | FileCheck -check-prefixes=CHECK,CHECK-AARCH64 %s
 // RUN: %clang -### %s --target=riscv64-unknown-fuchsia \
 // RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \
-// RUN: --sysroot=%S/platform -fuse-ld=lld 2>&1 \
+// RUN: --sysroot=%S/platform -fuse-ld=ld 2>&1 \
 // RUN: | FileCheck -check-prefixes=CHECK,CHECK-RISCV64 %s
 // RUN: %clang -### %s --target=x86_64-fuchsia \
 // RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \
-// RUN: --sysroot=%S/platform -fuse-ld=lld 2>&1 \
+// RUN: --sysroot=%S/platform -fuse-ld=ld 2>&1 \
 // RUN: | FileCheck -check-prefixes=CHECK,CHECK-X86_64 %s
 // RUN: %clang -### %s --target=aarch64-fuchsia \
 // RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \
-// RUN: --sysroot=%S/platform -fuse-ld=lld 2>&1 \
+// RUN: --sysroot=%S/platform -fuse-ld=ld 2>&1 \
 // RUN: | FileCheck -check-prefixes=CHECK,CHECK-AARCH64 %s
 // RUN: %clang -### %s --target=riscv64-fuchsia \
 // RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \
-// RUN: --sysroot=%S/platform -fuse-ld=lld 2>&1 \
+// RUN: --sysroot=%S/platform -fuse-ld=ld 2>&1 \
 // RUN: | FileCheck -check-prefixes=CHECK,CHECK-RISCV64 %s
 // CHECK: "-cc1"
 // CHECK-X86_64: "-triple" "x86_64-unknown-fuchsia"
@@ -71,22 +71,22 @@
 // CHECK-FP-NONLEAF: "-mframe-pointer=non-leaf"
 // CHECK-FP-NONE: "-mframe-pointer=none"
 
-// RUN: %clang -### %s --target=x86_64-unknown-fuchsia -rtlib=libgcc 
-fuse-ld=lld 2>&1 \
+// RUN: %clang -### %s --target=x86_64-unknown-fuchsia -rtlib=libgcc 2>&1 \
 // RUN: | FileCheck %s -check-prefix=CHECK-RTLIB
 // CHECK-RTLIB: error: invalid runtime library name in argument '-rtlib=libgcc'
 
-// RUN: %clang -### %s --target=x86_64-unknow

[clang] 8e39241 - [Driver][test] Remove unneeded REQUIRES: system-darwin

2023-07-29 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2023-07-29T19:38:08-07:00
New Revision: 8e39241fdef07bba2b1293ef187f2c894140c4d6

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

LOG: [Driver][test] Remove unneeded REQUIRES: system-darwin

Added: 


Modified: 
clang/test/Driver/darwin-opt-record.c

Removed: 




diff  --git a/clang/test/Driver/darwin-opt-record.c 
b/clang/test/Driver/darwin-opt-record.c
index 4a61932bc32e81..d996e7ab2ec75a 100644
--- a/clang/test/Driver/darwin-opt-record.c
+++ b/clang/test/Driver/darwin-opt-record.c
@@ -1,5 +1,3 @@
-// REQUIRES: system-darwin
-
 // RUN: %clang -target x86_64-apple-darwin10 -### -c -o FOO 
-fsave-optimization-record -arch x86_64 -arch x86_64h %s 2>&1 | FileCheck %s 
--check-prefix=CHECK-MULTIPLE-ARCH
 // RUN: %clang -target x86_64-apple-darwin10 -### -c -o FOO 
-foptimization-record-file=tmp -arch x86_64 -arch x86_64h %s 2>&1 | FileCheck 
%s --check-prefix=CHECK-MULTIPLE-ARCH-ERROR
 // RUN: %clang -target x86_64-apple-darwin10 -### -o FOO 
-fsave-optimization-record %s 2>&1 | FileCheck %s 
--check-prefix=CHECK-DSYMUTIL-NO-G



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


[clang] 5fe4558 - [test] Add --sysroot= for -fuse-ld=gold test

2023-07-29 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2023-07-29T20:00:34-07:00
New Revision: 5fe45586d9903447a6c0f1645ecd1eabe7882adf

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

LOG: [test] Add --sysroot= for -fuse-ld=gold test

Similar to abae53f43f0d1da8d8e421f4a628d7ec64d6e365 for lld by using -B.

Added: 


Modified: 
clang/test/Driver/opt-record.c

Removed: 




diff  --git a/clang/test/Driver/opt-record.c b/clang/test/Driver/opt-record.c
index eed0653f6ca27e..220f5db7fbca2c 100644
--- a/clang/test/Driver/opt-record.c
+++ b/clang/test/Driver/opt-record.c
@@ -48,7 +48,7 @@
 
 // Pass-through:
 // RUN: %clang --target=x86_64-linux -### -fuse-ld=lld -B%S/Inputs/lld -flto 
-fdiagnostics-hotness-threshold=100 -fsave-optimization-record 
-foptimization-record-passes=inline %s 2>&1 | FileCheck %s 
-check-prefix=CHECK-PASS-A
-// RUN: %clang --target=x86_64-linux -### -o FOO -fuse-ld=gold -flto 
-fdiagnostics-hotness-threshold=100 -fsave-optimization-record 
-foptimization-record-passes=inline %s 2>&1 | FileCheck %s 
-check-prefix=CHECK-PASS
+// RUN: %clang --target=x86_64-linux -### -o FOO 
--sysroot=%S/Inputs/basic_cross_linux_tree -fuse-ld=gold -flto 
-fdiagnostics-hotness-threshold=100 -fsave-optimization-record 
-foptimization-record-passes=inline %s 2>&1 | FileCheck %s 
-check-prefix=CHECK-PASS
 // RUN: %clang --target=x86_64-linux -### -o FOO -fuse-ld=lld -B%S/Inputs/lld 
-flto=thin -fdiagnostics-hotness-threshold=100 
-fsave-optimization-record=some-format -foptimization-record-file=FOO.txt %s 
2>&1 | FileCheck %s -check-prefix=CHECK-PASS-CUSTOM
 // RUN: %clang --target=x86_64-linux -### -o FOO -fuse-ld=lld -B%S/Inputs/lld 
-flto=thin -fdiagnostics-hotness-threshold=100 -Rpass=inline 
-Rpass-missed=inline -Rpass-analysis=inline %s 2>&1 | FileCheck %s 
-check-prefix=CHECK-PASS-RPASS
 // RUN: %clang --target=x86_64-linux -### -o FOO -fuse-ld=lld -B%S/Inputs/lld 
-flto=thin -fdiagnostics-hotness-threshold=auto -Rpass=inline 
-Rpass-missed=inline -Rpass-analysis=inline %s 2>&1 | FileCheck %s 
-check-prefix=CHECK-PASS-AUTO



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


[clang] 4dd1467 - [test] Improve visibility.cpp

2023-07-29 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2023-07-29T20:09:38-07:00
New Revision: 4dd1467df8885e61ca6ad42715435916ab26d8cb

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

LOG: [test] Improve visibility.cpp

Added: 


Modified: 
clang/test/CodeGenCXX/visibility.cpp

Removed: 




diff  --git a/clang/test/CodeGenCXX/visibility.cpp 
b/clang/test/CodeGenCXX/visibility.cpp
index 8c31613e76b923..001c8fa71d50da 100644
--- a/clang/test/CodeGenCXX/visibility.cpp
+++ b/clang/test/CodeGenCXX/visibility.cpp
@@ -123,6 +123,39 @@ namespace test72 {
   // CHECK-NEXT: @_ZN6test723fooIlE4var2IiEE = linkonce_odr global i32 0
 }
 
+namespace test73 {
+  struct HIDDEN foo {};
+  DEFAULT foo da, db, dc, dd;
+  HIDDEN foo ha, hb, hc, hd;
+  template DEFAULT int var;
+
+  template int var<&da>;
+  template int DEFAULT var<&db>;
+  template int HIDDEN var<&dc>;
+  template int var<&ha>;
+  template int DEFAULT var<&hb>;
+  template int HIDDEN var<&hc>;
+
+  int use() { return var<&dd> + var<&hd>; }
+  // CHECK:  @_ZN6test733varIXadL_ZNS_2daE = weak_odr hidden global 
i32 0
+  // CHECK-NEXT: @_ZN6test733varIXadL_ZNS_2dbE = weak_odr global i32 0
+  // CHECK-NEXT: @_ZN6test733varIXadL_ZNS_2dcE = weak_odr hidden global 
i32 0
+  // CHECK-NEXT: @_ZN6test733varIXadL_ZNS_2haE = weak_odr hidden global 
i32 0
+  // CHECK-NEXT: @_ZN6test733varIXadL_ZNS_2hbE = weak_odr global i32 0
+  // CHECK-NEXT: @_ZN6test733varIXadL_ZNS_2hcE = weak_odr hidden global 
i32 0
+  // CHECK:  @_ZN6test733varIXadL_ZNS_2ddE = linkonce_odr hidden 
global i32 0
+  // CHECK-NEXT: @_ZN6test733varIXadL_ZNS_2hdE = linkonce_odr hidden 
global i32 0
+
+  // CHECK-HIDDEN:  @_ZN6test733varIXadL_ZNS_2daE = weak_odr hidden 
global i32 0
+  // CHECK-HIDDEN-NEXT: @_ZN6test733varIXadL_ZNS_2dbE = weak_odr global 
i32 0
+  // CHECK-HIDDEN-NEXT: @_ZN6test733varIXadL_ZNS_2dcE = weak_odr hidden 
global i32 0
+  // CHECK-HIDDEN-NEXT: @_ZN6test733varIXadL_ZNS_2haE = weak_odr hidden 
global i32 0
+  // CHECK-HIDDEN-NEXT: @_ZN6test733varIXadL_ZNS_2hbE = weak_odr global 
i32 0
+  // CHECK-HIDDEN-NEXT: @_ZN6test733varIXadL_ZNS_2hcE = weak_odr hidden 
global i32 0
+  // CHECK-HIDDEN:  @_ZN6test733varIXadL_ZNS_2ddE = linkonce_odr 
hidden global i32 0
+  // CHECK-HIDDEN-NEXT: @_ZN6test733varIXadL_ZNS_2hdE = linkonce_odr 
hidden global i32 0
+}
+
 // CHECK: @_ZN5Test425VariableInHiddenNamespaceE = hidden global i32 10
 // CHECK: @_ZN5Test71aE = hidden global
 // CHECK: @_ZN5Test71bE = global
@@ -977,25 +1010,44 @@ namespace test51 {
   // template. Note that is a case where we disagree with gcc, it produces
   // a default symbol.
 
-  struct HIDDEN foo {
-  };
-  DEFAULT foo x, y, z;
+  struct HIDDEN foo {};
+  DEFAULT foo da, db, dc, dd;
+  HIDDEN foo ha, hb, hc, hd;
   template
   void DEFAULT zed() {
   }
-  template void zed<&x>();
-  // CHECK-LABEL: define weak_odr hidden void 
@_ZN6test513zedIXadL_ZNS_1xEvv
-  // CHECK-HIDDEN-LABEL: define weak_odr hidden void 
@_ZN6test513zedIXadL_ZNS_1xEvv
+  template void zed<&da>();
+  // CHECK-LABEL: define weak_odr hidden void 
@_ZN6test513zedIXadL_ZNS_2daEvv(
+  // CHECK-HIDDEN-LABEL: define weak_odr hidden void 
@_ZN6test513zedIXadL_ZNS_2daEvv(
+
+  template void DEFAULT zed<&db>();
+  // CHECK-LABEL: define weak_odr void @_ZN6test513zedIXadL_ZNS_2dbEvv(
+  // CHECK-HIDDEN-LABEL: define weak_odr void 
@_ZN6test513zedIXadL_ZNS_2dbEvv(
+
+  template void HIDDEN zed<&dc>();
+  // CHECK-LABEL: define weak_odr hidden void 
@_ZN6test513zedIXadL_ZNS_2dcEvv(
+  // CHECK-HIDDEN-LABEL: define weak_odr hidden void 
@_ZN6test513zedIXadL_ZNS_2dcEvv(
+
+  template void zed<&ha>();
+  // CHECK-LABEL: define weak_odr hidden void 
@_ZN6test513zedIXadL_ZNS_2haEvv(
+  // CHECK-HIDDEN-LABEL: define weak_odr hidden void 
@_ZN6test513zedIXadL_ZNS_2haEvv(
+
+  template void DEFAULT zed<&hb>();
+  // CHECK-LABEL: define weak_odr void @_ZN6test513zedIXadL_ZNS_2hbEvv(
+  // CHECK-HIDDEN-LABEL: define weak_odr void 
@_ZN6test513zedIXadL_ZNS_2hbEvv(
 
-  template void HIDDEN zed<&y>();
-  // CHECK-LABEL: define weak_odr hidden void 
@_ZN6test513zedIXadL_ZNS_1yEvv(
-  // CHECK-HIDDEN-LABEL: define weak_odr hidden void 
@_ZN6test513zedIXadL_ZNS_1yEvv(
+  template void HIDDEN zed<&hc>();
+  // CHECK-LABEL: define weak_odr hidden void 
@_ZN6test513zedIXadL_ZNS_2hcEvv(
+  // CHECK-HIDDEN-LABEL: define weak_odr hidden void 
@_ZN6test513zedIXadL_ZNS_2hcEvv(
 
   void use() {
-zed<&z>();
+zed<&dd>();
+zed<&hd>();
   }
-  // CHECK-LABEL: define linkonce_odr hidden void 
@_ZN6test513zedIXadL_ZNS_1zEvv(
-  // CHECK-HIDDEN-LABEL: define linkonce_odr hidden void 
@_ZN6test513zedIXadL_ZNS_1zEvv(
+  // CHECK

[clang] 2a1edeb - [Driver] Add -Wno-msvc-not-found to %clang_cl -Werror tests that don't want the diagnostic

2023-07-29 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2023-07-29T20:51:44-07:00
New Revision: 2a1edebdf1a887fdf01f039d60497626576c837b

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

LOG: [Driver] Add -Wno-msvc-not-found to %clang_cl -Werror tests that don't 
want the diagnostic

and remove a -### -fno-integrated-as test that would fail with 
--target=x86_64-windows-msvc.

Added: 


Modified: 
clang/test/Driver/cl-options.c
clang/test/Driver/clang-s-opts.s

Removed: 




diff  --git a/clang/test/Driver/cl-options.c b/clang/test/Driver/cl-options.c
index 94d13411986a48..324360e6b6424c 100644
--- a/clang/test/Driver/cl-options.c
+++ b/clang/test/Driver/cl-options.c
@@ -196,20 +196,20 @@
 // PR24003: -mframe-pointer=all
 // PR24003: -Os
 
-// RUN: not %clang_cl --target=i686-pc-win32 -Werror /Oy- /O2 -### -- %s 2>&1 
| FileCheck -check-prefix=Oy_2 %s
+// RUN: %clang_cl --target=i686-pc-win32 -Werror -Wno-msvc-not-found /Oy- /O2 
-### -- %s 2>&1 | FileCheck -check-prefix=Oy_2 %s
 // Oy_2: -mframe-pointer=all
 // Oy_2: -O2
 
-// RUN: not %clang_cl --target=aarch64-pc-windows-msvc -Werror /Oy- /O2 -### 
-- %s 2>&1 | FileCheck -check-prefix=Oy_aarch64 %s
+// RUN: %clang_cl --target=aarch64-pc-windows-msvc -Werror -Wno-msvc-not-found 
/Oy- /O2 -### -- %s 2>&1 | FileCheck -check-prefix=Oy_aarch64 %s
 // Oy_aarch64: -mframe-pointer=non-leaf
 // Oy_aarch64: -O2
 
-// RUN: not %clang_cl --target=i686-pc-win32 -Werror /O2 /O2 -### -- %s 2>&1 | 
FileCheck -check-prefix=O2O2 %s
+// RUN: %clang_cl --target=i686-pc-win32 -Werror -Wno-msvc-not-found /O2 /O2 
-### -- %s 2>&1 | FileCheck -check-prefix=O2O2 %s
 // O2O2: "-O2"
 
 // RUN: %clang_cl /Zs -Werror /Oy -- %s 2>&1
 
-// RUN: not %clang_cl --target=i686-pc-win32 -Werror /Oy- -### -- %s 2>&1 | 
FileCheck -check-prefix=Oy_ %s
+// RUN: %clang_cl --target=i686-pc-win32 -Werror -Wno-msvc-not-found /Oy- -### 
-- %s 2>&1 | FileCheck -check-prefix=Oy_ %s
 // Oy_: -mframe-pointer=all
 
 // RUN: %clang_cl /Qvec -### -- %s 2>&1 | FileCheck -check-prefix=Qvec %s

diff  --git a/clang/test/Driver/clang-s-opts.s 
b/clang/test/Driver/clang-s-opts.s
index f29270882f0ac9..8490bba62dda42 100644
--- a/clang/test/Driver/clang-s-opts.s
+++ b/clang/test/Driver/clang-s-opts.s
@@ -1,4 +1,3 @@
 // RUN: %clang -### -c -flto -fno-lto %s 2>&1 | FileCheck %s
-// RUN: %clang -### -c -flto -fno-lto -fno-integrated-as %s 2>&1 | FileCheck %s
 
 // CHECK-NOT: argument unused during compilation



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


[clang] 0c2cd74 - [Driver][test] Ensure fuzzer.c commands have --target=

2023-07-29 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2023-07-29T20:53:40-07:00
New Revision: 0c2cd74ff85a43a346ee05a2bfb88f07d9e60647

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

LOG: [Driver][test] Ensure fuzzer.c commands have --target=

Added: 


Modified: 
clang/test/Driver/fuzzer.c

Removed: 




diff  --git a/clang/test/Driver/fuzzer.c b/clang/test/Driver/fuzzer.c
index de1d51d0d88ef9..14caf7690057d8 100644
--- a/clang/test/Driver/fuzzer.c
+++ b/clang/test/Driver/fuzzer.c
@@ -18,7 +18,7 @@
 
 
 // Check that we don't link in libFuzzer.a when producing a shared object.
-// RUN: %clang -fsanitize=fuzzer %s -shared -o %t.so -### 2>&1 | FileCheck 
--check-prefixes=CHECK-NOLIB-SO %s
+// RUN: %clang --target=x86_64-linux-gnu -fsanitize=fuzzer %s -shared -### 
2>&1 | FileCheck --check-prefixes=CHECK-NOLIB-SO %s
 // CHECK-NOLIB-SO-NOT: libclang_rt.libfuzzer
 
 // Check that we don't link in libFuzzer when compiling with 
-fsanitize=fuzzer-no-link.
@@ -26,9 +26,6 @@
 // CHECK-NOLIB-NOT: libclang_rt.libfuzzer
 // CHECK-COV: -fsanitize-coverage-inline-8bit-counters
 
-// RUN: %clang -fsanitize=fuzzer -fsanitize-coverage=trace-pc %s -### 2>&1 | 
FileCheck --check-prefixes=CHECK-MSG %s
-// CHECK-MSG-NOT: argument unused during compilation
-
 // Check that we respect whether thes tandard library should be linked
 // statically.
 //



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


[PATCH] D156604: [clang][ExprConst] Use call source range for 'in call to' diags

2023-07-29 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder created this revision.
tbaeder added reviewers: cjdb, aaron.ballman, hazohelet.
Herald added a project: All.
tbaeder requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Before:

  array.cpp:74:15: error: static assertion expression is not an integral 
constant expression
 74 | static_assert(ints(1, div(true, false), 2, div(false, true)) == 1, 
"");
|   ^~~
  array.cpp:68:12: note: division by zero
 68 |   return 1 / (int)b;
|^
  array.cpp:74:23: note: in call to 'div(true, false)'
 74 | static_assert(ints(1, div(true, false), 2, div(false, true)) == 1, 
"");
|   ^
  1 error generated.

After:

  array.cpp:74:15: error: static assertion expression is not an integral 
constant expression
 74 | static_assert(ints(1, div(true, false), 2, div(false, true)) == 1, 
"");
|   ^~~
  array.cpp:68:12: note: division by zero
 68 |   return 1 / (int)b;
|^
  array.cpp:74:23: note: in call to 'div(true, false)'
 74 | static_assert(ints(1, div(true, false), 2, div(false, true)) == 1, 
"");
|   ^~~~

As you can see I have a test case, but I didn't attach it in 
`test/Misc/constexpr-source-ranges.cpp` because I can't get 
`-fdiagnostics-print-source-range-info` to actually print anything for them.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D156604

Files:
  clang/lib/AST/ExprConstant.cpp
  clang/lib/AST/Interp/Frame.h
  clang/lib/AST/Interp/InterpFrame.cpp
  clang/lib/AST/Interp/InterpFrame.h
  clang/lib/AST/Interp/State.cpp

Index: clang/lib/AST/Interp/State.cpp
===
--- clang/lib/AST/Interp/State.cpp
+++ clang/lib/AST/Interp/State.cpp
@@ -129,13 +129,13 @@
   const Frame *Top = getCurrentFrame();
   const Frame *Bottom = getBottomFrame();
   for (const Frame *F = Top; F != Bottom; F = F->getCaller(), ++CallIdx) {
-SourceLocation CallLocation = F->getCallLocation();
+SourceRange CallRange = F->getCallRange();
 
 // Skip this call?
 if (CallIdx >= SkipStart && CallIdx < SkipEnd) {
   if (CallIdx == SkipStart) {
 // Note that we're skipping calls.
-addDiag(CallLocation, diag::note_constexpr_calls_suppressed)
+addDiag(CallRange.getBegin(), diag::note_constexpr_calls_suppressed)
 << unsigned(ActiveCalls - Limit);
   }
   continue;
@@ -146,7 +146,8 @@
 if (const auto *CD =
 dyn_cast_if_present(F->getCallee());
 CD && CD->isInheritingConstructor()) {
-  addDiag(CallLocation, diag::note_constexpr_inherited_ctor_call_here)
+  addDiag(CallRange.getBegin(),
+  diag::note_constexpr_inherited_ctor_call_here)
   << CD->getParent();
   continue;
 }
@@ -154,6 +155,7 @@
 SmallString<128> Buffer;
 llvm::raw_svector_ostream Out(Buffer);
 F->describe(Out);
-addDiag(CallLocation, diag::note_constexpr_call_here) << Out.str();
+addDiag(CallRange.getBegin(), diag::note_constexpr_call_here)
+<< Out.str() << CallRange;
   }
 }
Index: clang/lib/AST/Interp/InterpFrame.h
===
--- clang/lib/AST/Interp/InterpFrame.h
+++ clang/lib/AST/Interp/InterpFrame.h
@@ -56,7 +56,7 @@
   Frame *getCaller() const override;
 
   /// Returns the location of the call to the frame.
-  SourceLocation getCallLocation() const override;
+  SourceRange getCallRange() const override;
 
   /// Returns the caller.
   const FunctionDecl *getCallee() const override;
Index: clang/lib/AST/Interp/InterpFrame.cpp
===
--- clang/lib/AST/Interp/InterpFrame.cpp
+++ clang/lib/AST/Interp/InterpFrame.cpp
@@ -176,10 +176,10 @@
   return S.getSplitFrame();
 }
 
-SourceLocation InterpFrame::getCallLocation() const {
+SourceRange InterpFrame::getCallRange() const {
   if (!Caller->Func)
-return S.getLocation(nullptr, {});
-  return S.getLocation(Caller->Func, RetPC - sizeof(uintptr_t));
+return S.getRange(nullptr, {});
+  return S.getRange(Caller->Func, RetPC - sizeof(uintptr_t));
 }
 
 const FunctionDecl *InterpFrame::getCallee() const {
Index: clang/lib/AST/Interp/Frame.h
===
--- clang/lib/AST/Interp/Frame.h
+++ clang/lib/AST/Interp/Frame.h
@@ -33,7 +33,7 @@
   virtual Frame *getCaller() const = 0;
 
   /// Returns the location of the call site.
-  virtual SourceLocation getCallLocation() const = 0;
+  virtual SourceRange getCallRange() const = 0;
 
   /// Returns the called function's declaration.
   virtual const FunctionDecl *getCallee() const = 0;
Index: clang/lib/AST/ExprConstant.cpp

[PATCH] D156605: [CodeComplete] Mark 'Derived().Base::foo()' CanBeCall

2023-07-29 Thread Younan Zhang via Phabricator via cfe-commits
zyounan created this revision.
zyounan added reviewers: sammccall, nridge, hokein.
Herald added subscribers: kadircet, arphaman.
Herald added a project: All.
zyounan published this revision for review.
Herald added projects: clang, clang-tools-extra.
Herald added a subscriber: cfe-commits.

This resolves https://reviews.llvm.org/D155370#4531274.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D156605

Files:
  clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
  clang/lib/Sema/SemaCodeComplete.cpp
  clang/unittests/Sema/CodeCompleteTest.cpp

Index: clang/unittests/Sema/CodeCompleteTest.cpp
===
--- clang/unittests/Sema/CodeCompleteTest.cpp
+++ clang/unittests/Sema/CodeCompleteTest.cpp
@@ -214,15 +214,25 @@
 struct OtherClass {
   OtherClass() {
 Foo f;
+Derived d;
 f.$canBeCall^
+; // Prevent parsing as 'f.f'
+f.Foo::$canBeCall^
 &Foo::$cannotBeCall^
+;
+d.Foo::$canBeCall^
   }
 };
 
 int main() {
   Foo f;
+  Derived d;
   f.$canBeCall^
+  ; // Prevent parsing as 'f.f'
+  f.Foo::$canBeCall^
   &Foo::$cannotBeCall^
+  ;
+  d.Foo::$canBeCall^
 }
 )cpp");
 
Index: clang/lib/Sema/SemaCodeComplete.cpp
===
--- clang/lib/Sema/SemaCodeComplete.cpp
+++ clang/lib/Sema/SemaCodeComplete.cpp
@@ -338,8 +338,11 @@
   ///
   /// \param InBaseClass whether the result was found in a base
   /// class of the searched context.
+  ///
+  /// \param BaseType the type of expression that precedes the "." or "->"
+  /// in a member access expression.
   void AddResult(Result R, DeclContext *CurContext, NamedDecl *Hiding,
- bool InBaseClass);
+ bool InBaseClass, QualType BaseType);
 
   /// Add a new non-declaration result to this result set.
   void AddResult(Result R);
@@ -1262,7 +1265,8 @@
 }
 
 void ResultBuilder::AddResult(Result R, DeclContext *CurContext,
-  NamedDecl *Hiding, bool InBaseClass = false) {
+  NamedDecl *Hiding, bool InBaseClass = false,
+  QualType BaseType = QualType()) {
   if (R.Kind != Result::RK_Declaration) {
 // For non-declaration results, just add the result.
 Results.push_back(R);
@@ -1380,9 +1384,7 @@
 OverloadSet.Add(Method, Results.size());
   }
 
-  // When completing a non-static member function (and not via
-  // dot/arrow member access) and we're not inside that class' scope,
-  // it can't be a call.
+  // Decide whether or not a non-static member function can be a call.
   if (CompletionContext.getKind() == clang::CodeCompletionContext::CCC_Symbol) {
 const NamedDecl *ND = R.getDeclaration();
 if (const auto *FuncTmpl = dyn_cast(ND)) {
@@ -1404,10 +1406,24 @@
 return nullptr;
   }();
 
+  // When completing a non-static member function (and not via
+  // dot/arrow member access) and we're not inside that class' scope,
+  // it can't be a call.
   R.FunctionCanBeCall =
   CurrentClassScope &&
   (CurrentClassScope == Method->getParent() ||
CurrentClassScope->isDerivedFrom(Method->getParent()));
+
+  // If the member access "." or "->" is followed by a qualified Id and the
+  // object type is derived from or the same as that of the Id, then
+  // the candidate functions should be perceived as calls.
+  if (const CXXRecordDecl *MaybeDerived = nullptr;
+  !BaseType.isNull() &&
+  (MaybeDerived = BaseType->getAsCXXRecordDecl())) {
+auto *MaybeBase = Method->getParent();
+R.FunctionCanBeCall =
+MaybeDerived == MaybeBase || MaybeDerived->isDerivedFrom(MaybeBase);
+  }
 }
   }
 
@@ -1683,7 +1699,7 @@
  bool InBaseClass) override {
 ResultBuilder::Result Result(ND, Results.getBasePriority(ND), nullptr,
  false, IsAccessible(ND, Ctx), FixIts);
-Results.AddResult(Result, InitialLookupCtx, Hiding, InBaseClass);
+Results.AddResult(Result, InitialLookupCtx, Hiding, InBaseClass, BaseType);
   }
 
   void EnteredContext(DeclContext *Ctx) override {
Index: clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
===
--- clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
+++ clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
@@ -552,15 +552,25 @@
   struct OtherClass {
 OtherClass() {
   Foo f;
+  Derived d;
   f.$canBeCall^
+  ; // Prevent parsing as 'f.f'
+  f.Foo::$canBeCall^
   &Foo::$canNotBeCall^
+  ;
+  d.Foo::$canBeCall^
 }
   };
 
   int main() {
 Foo f;
+Derived d;
 f.$canBeCall^
+; // Prevent parsing as 'f.f'

[PATCH] D156286: [docs] Bump minimum GCC version to 7.5

2023-07-29 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

In D156286#4534968 , @aaron.ballman 
wrote:

> There's a mention on the RFC thread that Ubuntu 18.04 still ships with GCC 
> 7.3. That's an LTS release but it EOLed just last month, so it's not clear 
> how disruptive this would be. (To be clear, I'm not saying I'm opposed to the 
> changes.)

The entire 16.x releases `LLVMAnalysis` cannot be built with GCC 7.3, so this 
CMake change shouldn't be a larger disruption to any GCC <= 7.3 user.
And we should get the GCC bump patch into 17.x so that users will not get 
confused by the supportness.

The question is whether we bump to 7.4 or 7.5. I'd prefer 7.5, as there appears 
to be more users on 7.5 and can verify that 7.5 works reliably.

There is a user who prefers 7.4 but 7.5 works for them.
https://discourse.llvm.org/t/require-gcc-7-5-as-gcc-7-3-cannot-build-llvm-16-x-or-main/72310/29
 says that Ubuntu 18.04 (End of Standard Support in June 2023) gets GCC 7.5 
updates.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156286

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


[clang] f92551b - [Driver][test] pgo-sample-use-profi.c: specify --target=

2023-07-29 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2023-07-29T21:25:31-07:00
New Revision: f92551ba6b5aaef28d886ea6b3c4f9774fa8fadd

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

LOG: [Driver][test] pgo-sample-use-profi.c: specify --target=

Some targets (e.g. AIX) report an error for certain unimplemented
features, making Clang exit with 1.

Added: 


Modified: 
clang/test/Driver/pgo-sample-use-profi.c

Removed: 




diff  --git a/clang/test/Driver/pgo-sample-use-profi.c 
b/clang/test/Driver/pgo-sample-use-profi.c
index 454a511a06281b..0370d947ce590f 100644
--- a/clang/test/Driver/pgo-sample-use-profi.c
+++ b/clang/test/Driver/pgo-sample-use-profi.c
@@ -1,4 +1,4 @@
 /// Test if profi flat is enabled in frontend as user-facing feature.
-// RUN: %clang -c -fsample-profile-use-profi -fprofile-sample-use=/dev/null 
-### %s 2>&1 | FileCheck %s
+// RUN: %clang --target=x86_64 -c -fsample-profile-use-profi 
-fprofile-sample-use=/dev/null -### %s 2>&1 | FileCheck %s
 
 // CHECK: "-mllvm" "-sample-profile-use-profi"



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


[clang] 989a5fe - [Driver][test] clang_f_opts.c: unsupport AIX

2023-07-29 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2023-07-29T21:31:15-07:00
New Revision: 989a5feb2ca7d3f63db6c3c33590cfd7596724a8

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

LOG: [Driver][test] clang_f_opts.c: unsupport AIX

AIX prefers rejecting certain unimplemented features like
-fprofile-sample-use, making clang_f_opts.c (legacy test file testing
many miscellaneous features) not suitable. We could specify --target=,
but this style change is probably not the best for this legacy file.

Added: 


Modified: 
clang/test/Driver/clang_f_opts.c

Removed: 




diff  --git a/clang/test/Driver/clang_f_opts.c 
b/clang/test/Driver/clang_f_opts.c
index cec93935eb3a95..a59496fb0b313d 100644
--- a/clang/test/Driver/clang_f_opts.c
+++ b/clang/test/Driver/clang_f_opts.c
@@ -1,4 +1,4 @@
-
+// UNSUPPORTED: target={{.*}}-aix{{.*}}
 // RUN: %clang -### -S -fasm -fblocks -fbuiltin -fno-math-errno -fcommon 
-fpascal-strings -fno-blocks -fno-builtin -fmath-errno -fno-common 
-fno-pascal-strings -fblocks -fbuiltin -fmath-errno -fcommon -fpascal-strings 
-fsplit-stack %s 2>&1 | FileCheck -check-prefix=CHECK-OPTIONS1 %s
 // RUN: %clang -### -S -fasm -fblocks -fbuiltin -fno-math-errno -fcommon 
-fpascal-strings -fno-asm -fno-blocks -fno-builtin -fmath-errno -fno-common 
-fno-pascal-strings -fno-show-source-location -fshort-enums -fprotect-parens %s 
2>&1 | FileCheck -check-prefix=CHECK-OPTIONS2 %s
 



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


[PATCH] D155370: [CodeComplete] Improve FunctionCanBeCall

2023-07-29 Thread Younan Zhang via Phabricator via cfe-commits
zyounan added inline comments.



Comment at: clang/lib/Sema/SemaCodeComplete.cpp:1407
 
   R.FunctionCanBeCall =
   CurrentClassScope &&

zyounan wrote:
> The current heuristic results in the following:
> 
> ```
> struct Base {
>   void foo(int);
> };
> struct Derived : Base {
>   void foo(float);
> };
> 
> int main() {
>   Derived d;
>   d.Base::^// FunctionCanBeCall for `foo` is false.
> }
> ```
> 
> In situations where it is intended to invoke base member functions hidden by 
> subclasses, we shouldn't remove parentheses, IMO.
D156605 to address this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155370

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


[clang] c835dca - [Driver][test] Add -Wno-msvc-not-found to %clang_cl -WX tests that don't want the diagnostic

2023-07-29 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2023-07-29T21:45:41-07:00
New Revision: c835dcaccf8ef46a7aa8f535ae7a55a862c426c4

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

LOG: [Driver][test] Add -Wno-msvc-not-found to %clang_cl -WX tests that don't 
want the diagnostic

similar to 2a1edebdf1a887fdf01f039d60497626576c837b

Added: 


Modified: 
clang/test/Driver/cl-options.c

Removed: 




diff  --git a/clang/test/Driver/cl-options.c b/clang/test/Driver/cl-options.c
index 324360e6b6424c..11096ad55b59ae 100644
--- a/clang/test/Driver/cl-options.c
+++ b/clang/test/Driver/cl-options.c
@@ -290,7 +290,7 @@
 // W4: -WCL4
 // Weverything: -Weverything
 
-// RUN: not %clang_cl /WX -### -- %s 2>&1 | FileCheck -check-prefix=WX %s
+// RUN: %clang_cl /WX -Wno-msvc-not-found -### -- %s 2>&1 | FileCheck 
-check-prefix=WX %s
 // WX: -Werror
 
 // RUN: %clang_cl /WX- -### -- %s 2>&1 | FileCheck -check-prefix=WX_ %s



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


[PATCH] D156607: [Clang][CMake] Allow using passthrough BOLT in BOLT-PGO.cmake

2023-07-29 Thread Amir Ayupov via Phabricator via cfe-commits
Amir created this revision.
Amir added reviewers: bolt, phosek, beanz.
Herald added subscribers: wlei, ekilmer, wenlei.
Herald added a project: All.
Amir requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Factor out bolt project dependency from Clang-BOLT usage.
Allow using

- user-specified BOLT: `LLVM_BOLT` and `MERGE_FDATA` variables,
- BOLT from system path (with CMake's `find_program`),
- built from `bolt` project (the only previously supported way).

Customize BOLT-PGO.cmake cache file to build BOLT in first-stage build, and
passthrough and use it in the final clang-bolt invocation (on top of PGO 
binary).
This avoids building PGO'd BOLT (first instrumented and then optimized), cutting
the build time.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D156607

Files:
  clang/CMakeLists.txt
  clang/cmake/caches/BOLT-PGO-stage2.cmake
  clang/cmake/caches/BOLT-PGO.cmake
  clang/utils/perf-training/CMakeLists.txt

Index: clang/utils/perf-training/CMakeLists.txt
===
--- clang/utils/perf-training/CMakeLists.txt
+++ clang/utils/perf-training/CMakeLists.txt
@@ -78,9 +78,21 @@
 COMMAND "${Python3_EXECUTABLE}" ${CMAKE_CURRENT_SOURCE_DIR}/perf-helper.py clean ${CMAKE_CURRENT_BINARY_DIR} fdata
 COMMENT "Clearing old BOLT fdata")
 
-  # Merge profiles into one using merge-fdata
-  add_custom_target(clang-bolt-profile
-COMMAND "${Python3_EXECUTABLE}" ${CMAKE_CURRENT_SOURCE_DIR}/perf-helper.py merge-fdata $ ${CMAKE_CURRENT_BINARY_DIR}/prof.fdata ${CMAKE_CURRENT_BINARY_DIR}
-COMMENT "Merging BOLT fdata"
-DEPENDS merge-fdata generate-bolt-fdata)
+  add_custom_target(clang-bolt-profile-deps)
+  if ("bolt" IN_LIST LLVM_ENABLE_PROJECTS)
+add_dependencies(clang-bolt-profile-deps merge-fdata)
+set(MERGE_FDATA $)
+  elseif (NOT MERGE_FDATA)
+find_program(MERGE_FDATA merge-fdata)
+  endif()
+
+  if (NOT MERGE_FDATA AND NOT "bolt" IN_LIST LLVM_ENABLE_PROJECTS)
+message(STATUS "To enable optimizing Clang with BOLT enable bolt project or set MERGE_FDATA")
+  else()
+# Merge profiles into one using merge-fdata
+add_custom_target(clang-bolt-profile
+  COMMAND "${Python3_EXECUTABLE}" ${CMAKE_CURRENT_SOURCE_DIR}/perf-helper.py merge-fdata ${MERGE_FDATA} ${CMAKE_CURRENT_BINARY_DIR}/prof.fdata ${CMAKE_CURRENT_BINARY_DIR}
+  COMMENT "Merging BOLT fdata"
+  DEPENDS generate-bolt-fdata)
+  endif()
 endif()
Index: clang/cmake/caches/BOLT-PGO.cmake
===
--- clang/cmake/caches/BOLT-PGO.cmake
+++ clang/cmake/caches/BOLT-PGO.cmake
@@ -11,7 +11,9 @@
   install-distribution
   CACHE STRING "")
 
+set(BOOTSTRAP_LLVM_BOLT ON)
+
 set(PGO_BUILD_CONFIGURATION
-  ${CMAKE_CURRENT_LIST_DIR}/BOLT.cmake
+  ${CMAKE_CURRENT_LIST_DIR}/BOLT-PGO-stage2.cmake
   CACHE STRING "")
 include(${CMAKE_CURRENT_LIST_DIR}/PGO.cmake)
Index: clang/cmake/caches/BOLT-PGO-stage2.cmake
===
--- /dev/null
+++ clang/cmake/caches/BOLT-PGO-stage2.cmake
@@ -0,0 +1,13 @@
+set(CMAKE_BUILD_TYPE Release CACHE STRING "")
+set(CLANG_BOLT_INSTRUMENT ON CACHE BOOL "")
+set(CMAKE_EXE_LINKER_FLAGS "-Wl,--emit-relocs,-znow" CACHE STRING "")
+
+set(LLVM_ENABLE_PROJECTS "clang" CACHE STRING "")
+set(LLVM_TARGETS_TO_BUILD Native CACHE STRING "")
+
+# setup toolchain
+set(LLVM_INSTALL_TOOLCHAIN_ONLY ON CACHE BOOL "")
+set(LLVM_DISTRIBUTION_COMPONENTS
+  clang
+  clang-resource-headers
+  CACHE STRING "")
Index: clang/CMakeLists.txt
===
--- clang/CMakeLists.txt
+++ clang/CMakeLists.txt
@@ -711,6 +711,16 @@
 endif()
   endif()
 
+  if(BOOTSTRAP_LLVM_BOLT)
+add_dependencies(clang-bootstrap-deps llvm-bolt merge-fdata)
+set(LLVM_BOLT ${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-bolt)
+set(MERGE_FDATA ${LLVM_RUNTIME_OUTPUT_INTDIR}/merge-fdata)
+list(APPEND _BOOTSTRAP_DEFAULT_PASSTHROUGH
+  LLVM_BOLT
+  MERGE_FDATA
+)
+  endif()
+
   if(BOOTSTRAP_LLVM_BUILD_INSTRUMENTED)
 add_dependencies(clang-bootstrap-deps llvm-profdata)
 set(PGO_OPT -DLLVM_PROFDATA=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-profdata)
@@ -854,35 +864,47 @@
   set(CLANG_INSTRUMENTED ${CLANG_PATH}-bolt.inst)
   set(BOLT_FDATA ${CMAKE_CURRENT_BINARY_DIR}/utils/perf-training/prof.fdata)
 
-  # Instrument clang with BOLT
-  add_custom_target(clang-instrumented
-DEPENDS ${CLANG_INSTRUMENTED}
-  )
-  add_custom_command(OUTPUT ${CLANG_INSTRUMENTED}
-DEPENDS clang llvm-bolt
-COMMAND llvm-bolt ${CLANG_PATH} -o ${CLANG_INSTRUMENTED}
-  -instrument --instrumentation-file-append-pid
-  --instrumentation-file=${BOLT_FDATA}
-COMMENT "Instrumenting clang binary with BOLT"
-VERBATIM
-  )
+  add_custom_target(bolt-clang-instrumented-deps)
+  if ("bolt" IN_LIST LLVM_ENABLE_PROJECTS)
+add_dependencies(bolt-clang-instrument

[PATCH] D156607: [Clang][CMake] Allow using passthrough BOLT in BOLT-PGO.cmake

2023-07-29 Thread Amir Ayupov via Phabricator via cfe-commits
Amir updated this revision to Diff 545406.
Amir added a comment.

Add clang-bolt-profile-deps dependency


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156607

Files:
  clang/CMakeLists.txt
  clang/cmake/caches/BOLT-PGO-stage2.cmake
  clang/cmake/caches/BOLT-PGO.cmake
  clang/utils/perf-training/CMakeLists.txt

Index: clang/utils/perf-training/CMakeLists.txt
===
--- clang/utils/perf-training/CMakeLists.txt
+++ clang/utils/perf-training/CMakeLists.txt
@@ -78,9 +78,21 @@
 COMMAND "${Python3_EXECUTABLE}" ${CMAKE_CURRENT_SOURCE_DIR}/perf-helper.py clean ${CMAKE_CURRENT_BINARY_DIR} fdata
 COMMENT "Clearing old BOLT fdata")
 
-  # Merge profiles into one using merge-fdata
-  add_custom_target(clang-bolt-profile
-COMMAND "${Python3_EXECUTABLE}" ${CMAKE_CURRENT_SOURCE_DIR}/perf-helper.py merge-fdata $ ${CMAKE_CURRENT_BINARY_DIR}/prof.fdata ${CMAKE_CURRENT_BINARY_DIR}
-COMMENT "Merging BOLT fdata"
-DEPENDS merge-fdata generate-bolt-fdata)
+  add_custom_target(clang-bolt-profile-deps)
+  if ("bolt" IN_LIST LLVM_ENABLE_PROJECTS)
+add_dependencies(clang-bolt-profile-deps merge-fdata)
+set(MERGE_FDATA $)
+  elseif (NOT MERGE_FDATA)
+find_program(MERGE_FDATA merge-fdata)
+  endif()
+
+  if (NOT MERGE_FDATA AND NOT "bolt" IN_LIST LLVM_ENABLE_PROJECTS)
+message(STATUS "To enable optimizing Clang with BOLT enable bolt project or set MERGE_FDATA")
+  else()
+# Merge profiles into one using merge-fdata
+add_custom_target(clang-bolt-profile
+  COMMAND "${Python3_EXECUTABLE}" ${CMAKE_CURRENT_SOURCE_DIR}/perf-helper.py merge-fdata ${MERGE_FDATA} ${CMAKE_CURRENT_BINARY_DIR}/prof.fdata ${CMAKE_CURRENT_BINARY_DIR}
+  COMMENT "Merging BOLT fdata"
+  DEPENDS clang-bolt-profile-deps generate-bolt-fdata)
+  endif()
 endif()
Index: clang/cmake/caches/BOLT-PGO.cmake
===
--- clang/cmake/caches/BOLT-PGO.cmake
+++ clang/cmake/caches/BOLT-PGO.cmake
@@ -11,7 +11,9 @@
   install-distribution
   CACHE STRING "")
 
+set(BOOTSTRAP_LLVM_BOLT ON)
+
 set(PGO_BUILD_CONFIGURATION
-  ${CMAKE_CURRENT_LIST_DIR}/BOLT.cmake
+  ${CMAKE_CURRENT_LIST_DIR}/BOLT-PGO-stage2.cmake
   CACHE STRING "")
 include(${CMAKE_CURRENT_LIST_DIR}/PGO.cmake)
Index: clang/cmake/caches/BOLT-PGO-stage2.cmake
===
--- /dev/null
+++ clang/cmake/caches/BOLT-PGO-stage2.cmake
@@ -0,0 +1,13 @@
+set(CMAKE_BUILD_TYPE Release CACHE STRING "")
+set(CLANG_BOLT_INSTRUMENT ON CACHE BOOL "")
+set(CMAKE_EXE_LINKER_FLAGS "-Wl,--emit-relocs,-znow" CACHE STRING "")
+
+set(LLVM_ENABLE_PROJECTS "clang" CACHE STRING "")
+set(LLVM_TARGETS_TO_BUILD Native CACHE STRING "")
+
+# setup toolchain
+set(LLVM_INSTALL_TOOLCHAIN_ONLY ON CACHE BOOL "")
+set(LLVM_DISTRIBUTION_COMPONENTS
+  clang
+  clang-resource-headers
+  CACHE STRING "")
Index: clang/CMakeLists.txt
===
--- clang/CMakeLists.txt
+++ clang/CMakeLists.txt
@@ -711,6 +711,16 @@
 endif()
   endif()
 
+  if(BOOTSTRAP_LLVM_BOLT)
+add_dependencies(clang-bootstrap-deps llvm-bolt merge-fdata)
+set(LLVM_BOLT ${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-bolt)
+set(MERGE_FDATA ${LLVM_RUNTIME_OUTPUT_INTDIR}/merge-fdata)
+list(APPEND _BOOTSTRAP_DEFAULT_PASSTHROUGH
+  LLVM_BOLT
+  MERGE_FDATA
+)
+  endif()
+
   if(BOOTSTRAP_LLVM_BUILD_INSTRUMENTED)
 add_dependencies(clang-bootstrap-deps llvm-profdata)
 set(PGO_OPT -DLLVM_PROFDATA=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-profdata)
@@ -854,35 +864,47 @@
   set(CLANG_INSTRUMENTED ${CLANG_PATH}-bolt.inst)
   set(BOLT_FDATA ${CMAKE_CURRENT_BINARY_DIR}/utils/perf-training/prof.fdata)
 
-  # Instrument clang with BOLT
-  add_custom_target(clang-instrumented
-DEPENDS ${CLANG_INSTRUMENTED}
-  )
-  add_custom_command(OUTPUT ${CLANG_INSTRUMENTED}
-DEPENDS clang llvm-bolt
-COMMAND llvm-bolt ${CLANG_PATH} -o ${CLANG_INSTRUMENTED}
-  -instrument --instrumentation-file-append-pid
-  --instrumentation-file=${BOLT_FDATA}
-COMMENT "Instrumenting clang binary with BOLT"
-VERBATIM
-  )
+  add_custom_target(bolt-clang-instrumented-deps)
+  if ("bolt" IN_LIST LLVM_ENABLE_PROJECTS)
+add_dependencies(bolt-clang-instrumented-deps llvm-bolt)
+set(LLVM_BOLT $)
+  elseif (NOT LLVM_BOLT)
+find_program(LLVM_BOLT llvm-bolt)
+  endif()
 
-  # Optimize original (pre-bolt) Clang using the collected profile
-  set(CLANG_OPTIMIZED ${CMAKE_CURRENT_BINARY_DIR}/clang.bolt)
-  add_custom_target(clang-bolt
-DEPENDS ${CLANG_OPTIMIZED}
-  )
-  add_custom_command(OUTPUT ${CLANG_OPTIMIZED}
-DEPENDS clang-bolt-profile
-COMMAND llvm-bolt ${CLANG_PATH}
-  -o ${CLANG_OPTIMIZED}
-  -data ${BOLT_FDATA}
-  -reorder-blocks=ext-tsp -reorder-functions=hfsort+ -split-functions
-  -sp