[PATCH] D133648: [Clang] changing behavior of constant array emission

2022-09-10 Thread Ofek Shochat via Phabricator via cfe-commits
OfekShochat created this revision.
OfekShochat added a reviewer: klimek.
Herald added a subscriber: hiraditya.
Herald added a project: All.
OfekShochat requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

fixes issue with emitting partially initialized constant arrays larger than 
2^32.
issue #57353 on github.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D133648

Files:
  clang/lib/CodeGen/CGExprConstant.cpp
  clang/lib/Sema/SemaInit.cpp
  clang/test/CodeGen/big-array-init.c
  llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp


Index: llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
===
--- llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -3164,7 +3164,7 @@
  const Constant *BaseCV, uint64_t Offset,
  AsmPrinter::AliasMapTy *AliasList) {
   // Print the fields in successive locations. Pad to align if needed!
-  unsigned Size = DL.getTypeAllocSize(CS->getType());
+  uint64_t Size = DL.getTypeAllocSize(CS->getType());
   const StructLayout *Layout = DL.getStructLayout(CS->getType());
   uint64_t SizeSoFar = 0;
   for (unsigned I = 0, E = CS->getNumOperands(); I != E; ++I) {
Index: clang/test/CodeGen/big-array-init.c
===
--- /dev/null
+++ clang/test/CodeGen/big-array-init.c
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 %s -O0 -triple x86_64-unknown-linux-gnu -S -emit-llvm -o - 
| FileCheck %s
+/* checks for #57353, arrays that are larger than 2^32 were emitting wrongly. 
*/
+
+// CHECK: @bad_char = global <{ i8, [4294967295 x i8] }> <{ i8 1, [4294967295 
x i8] zeroinitializer }>, align 16
+char bad_char[4294967296] = {1};
+// CHECK: @bad_int = global <{ i32, [1073741823 x i32] }> <{ i32 1, 
[1073741823 x i32] zeroinitializer }>, align 16
+int bad_int[1073741824] = {1};
Index: clang/lib/Sema/SemaInit.cpp
===
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -836,8 +836,8 @@
   QualType ElementType;
 
   InitializedEntity ElementEntity = Entity;
-  unsigned NumInits = ILE->getNumInits();
-  unsigned NumElements = NumInits;
+  uint64_t NumInits = ILE->getNumInits();
+  uint64_t NumElements = NumInits;
   if (const ArrayType *AType = SemaRef.Context.getAsArrayType(ILE->getType())) 
{
 ElementType = AType->getElementType();
 if (const auto *CAType = dyn_cast(AType))
@@ -857,7 +857,7 @@
 ElementType = ILE->getType();
 
   bool SkipEmptyInitChecks = false;
-  for (unsigned Init = 0; Init != NumElements; ++Init) {
+  for (uint64_t Init = 0; Init != NumElements; ++Init) {
 if (hadError)
   return;
 
Index: clang/lib/CodeGen/CGExprConstant.cpp
===
--- clang/lib/CodeGen/CGExprConstant.cpp
+++ clang/lib/CodeGen/CGExprConstant.cpp
@@ -391,7 +391,7 @@
 
 static llvm::Constant *
 EmitArrayConstant(CodeGenModule , llvm::ArrayType *DesiredType,
-  llvm::Type *CommonElementType, unsigned ArrayBound,
+  llvm::Type *CommonElementType, uint64_t ArrayBound,
   SmallVectorImpl ,
   llvm::Constant *Filler);
 
@@ -945,11 +945,11 @@
 
 static llvm::Constant *
 EmitArrayConstant(CodeGenModule , llvm::ArrayType *DesiredType,
-  llvm::Type *CommonElementType, unsigned ArrayBound,
+  llvm::Type *CommonElementType, uint64_t ArrayBound,
   SmallVectorImpl ,
   llvm::Constant *Filler) {
   // Figure out how long the initial prefix of non-zero elements is.
-  unsigned NonzeroLength = ArrayBound;
+  uint64_t NonzeroLength = ArrayBound;
   if (Elements.size() < NonzeroLength && Filler->isNullValue())
 NonzeroLength = Elements.size();
   if (NonzeroLength == Elements.size()) {
@@ -1223,11 +1223,11 @@
 auto *CAT = CGM.getContext().getAsConstantArrayType(ILE->getType());
 assert(CAT && "can't emit array init for non-constant-bound array");
 unsigned NumInitElements = ILE->getNumInits();
-unsigned NumElements = CAT->getSize().getZExtValue();
+uint64_t NumElements = CAT->getSize().getZExtValue();
 
 // Initialising an array requires us to automatically
 // initialise any elements that have not been initialised explicitly
-unsigned NumInitableElts = std::min(NumInitElements, NumElements);
+uint64_t NumInitableElts = std::min((uint64_t)NumInitElements, 
NumElements);
 
 QualType EltType = CAT->getElementType();
 


Index: llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
===
--- llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -3164,7 +3164,7 @@
  const Constant *BaseCV, 

[PATCH] D133589: [clang-format] JSON formatting add new option for controlling newlines in json arrays

2022-09-10 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks added inline comments.



Comment at: clang/.clang-format:2
 BasedOnStyle: LLVM
+RemoveBracesLLVM: true

Unrelated.



Comment at: clang/include/clang/Format/Format.h:2063
+  /// otherwise it will scan until the closing `]` to determine if it should 
add
+  /// newlines between elements (prettier compatible)
+  ///





Comment at: clang/include/clang/Format/Format.h:2065
+  ///
+  /// NOTE: This is currently only for formatting JSON
+  /// \code





Comment at: clang/include/clang/Format/Format.h:2076
+  /// \version 16
+  bool BreakArrays;
+

Please sort.



Comment at: clang/include/clang/Format/Format.h:2076
+  /// \version 16
+  bool BreakArrays;
+

HazardyKnusperkeks wrote:
> Please sort.
What about `Leave`?



Comment at: clang/include/clang/Format/Format.h:3917
EmptyLineBeforeAccessModifier == R.EmptyLineBeforeAccessModifier &&
+   BreakArrays == R.BreakArrays &&
ExperimentalAutoDetectBinPacking ==

Please sort.



Comment at: clang/lib/Format/TokenAnnotator.cpp:4402
   return true;
-// Always break after a JSON array opener.
-// [
-// ]
+// Always break after a JSON array opener based on BreakArrays
 if (Left.is(TT_ArrayInitializerLSquare) && Left.is(tok::l_square) &&




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

https://reviews.llvm.org/D133589

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


[PATCH] D133647: [clang-format] Parse the else part of `#if 0`

2022-09-10 Thread sstwcw via Phabricator via cfe-commits
sstwcw created this revision.
sstwcw added reviewers: HazardyKnusperkeks, MyDeveloperDay, curdeius, owenpan.
Herald added a project: All.
sstwcw requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Fixes https://github.com/llvm/llvm-project/issues/57539

Previously things outside of `#if` blocks were parsed as if only the
first branch of the conditional compilation branch existed.  Unless the
first condition is 0, then the outer parts would be parsed as if
everything inside the conditional parts didn't exist.  Now we use the
second conditional branch if the first condition is 0.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D133647

Files:
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/unittests/Format/FormatTest.cpp


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -5993,6 +5993,16 @@
  ");\n"
  "#else\n"
  "#endif");
+
+  // Verify that indentation is correct when there is an `#if 0` with an
+  // `#else`.
+  verifyFormat("#if 0\n"
+   "{\n"
+   "#else\n"
+   "{\n"
+   "#endif\n"
+   "  x;\n"
+   "}");
 }
 
 TEST_F(FormatTest, GraciouslyHandleIncorrectPreprocessorConditions) {
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -1124,7 +1124,9 @@
   ++PPBranchLevel;
   assert(PPBranchLevel >= 0 && PPBranchLevel <= 
(int)PPLevelBranchIndex.size());
   if (PPBranchLevel == (int)PPLevelBranchIndex.size()) {
-PPLevelBranchIndex.push_back(0);
+// If the first branch is unreachable, set the BranchIndex to 1.  This way
+// the next branch it will be parsed if there is one.
+PPLevelBranchIndex.push_back(Unreachable ? 1 : 0);
 PPLevelBranchCount.push_back(0);
   }
   PPChainBranchIndex.push(0);


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -5993,6 +5993,16 @@
  ");\n"
  "#else\n"
  "#endif");
+
+  // Verify that indentation is correct when there is an `#if 0` with an
+  // `#else`.
+  verifyFormat("#if 0\n"
+   "{\n"
+   "#else\n"
+   "{\n"
+   "#endif\n"
+   "  x;\n"
+   "}");
 }
 
 TEST_F(FormatTest, GraciouslyHandleIncorrectPreprocessorConditions) {
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -1124,7 +1124,9 @@
   ++PPBranchLevel;
   assert(PPBranchLevel >= 0 && PPBranchLevel <= (int)PPLevelBranchIndex.size());
   if (PPBranchLevel == (int)PPLevelBranchIndex.size()) {
-PPLevelBranchIndex.push_back(0);
+// If the first branch is unreachable, set the BranchIndex to 1.  This way
+// the next branch it will be parsed if there is one.
+PPLevelBranchIndex.push_back(Unreachable ? 1 : 0);
 PPLevelBranchCount.push_back(0);
   }
   PPChainBranchIndex.push(0);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D133571: [clang-format] Introduce NoFallThrough option into AllowShortCaseLabelsOnASingleLine

2022-09-10 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks added inline comments.



Comment at: clang/include/clang/Format/Format.h:469
+  /// Different styles for merging short case labels.
+  enum ShortCaseLabelStyle : int8_t {
+/// Never merge case code

While we're at it, shouldn't there be a `Leave`? ;)


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

https://reviews.llvm.org/D133571

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


[PATCH] D133194: rewording note note_constexpr_invalid_cast

2022-09-10 Thread Muhammad Usman Shahid via Phabricator via cfe-commits
Codesbyusman updated this revision to Diff 459296.
Codesbyusman added a comment.

updating with the suggested changes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133194

Files:
  clang/include/clang/Basic/DiagnosticASTKinds.td
  clang/lib/AST/ExprConstant.cpp
  clang/test/Sema/cast.c
  clang/test/SemaCXX/constant-expression-cxx11.cpp

Index: clang/test/SemaCXX/constant-expression-cxx11.cpp
===
--- clang/test/SemaCXX/constant-expression-cxx11.cpp
+++ clang/test/SemaCXX/constant-expression-cxx11.cpp
@@ -2,6 +2,7 @@
 // RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify=expected,cxx11_20,cxx20_2b -triple x86_64-linux -Wno-string-plus-int -Wno-pointer-arith -Wno-zero-length-array -Wno-c99-designator -fcxx-exceptions -pedantic %s -Wno-comment -Wno-tautological-pointer-compare -Wno-bool-conversion
 // RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify=expected,cxx11_20,cxx11-triple x86_64-linux -Wno-string-plus-int -Wno-pointer-arith -Wno-zero-length-array -Wno-c99-designator -fcxx-exceptions -pedantic %s -Wno-comment -Wno-tautological-pointer-compare -Wno-bool-conversion
 
+
 namespace StaticAssertFoldTest {
 
 int x;
@@ -11,6 +12,10 @@
 
 }
 
+int array[(long)(char *)0]; // expected-warning {{variable length arrays are a C99 feature}} \
+// expected-warning {{variable length array folded to constant array as an extension}} \
+// expected-note {{cast that performs the conversions of a reinterpret_cast is not allowed in a constant expression}}
+
 typedef decltype(sizeof(char)) size_t;
 
 template constexpr T id(const T ) { return t; }
@@ -2449,6 +2454,6 @@
 
   constexpr EMaxInt x19 = static_cast(__INT_MAX__-1);
   constexpr EMaxInt x20 = static_cast((long)__INT_MAX__+1); // expected-error {{must be initialized by a constant expression}}
-  // expected-note@-1 {{integer value 2147483648 is outside the valid range of values [-2147483648, 2147483647] for this enumeration type}}
+  // expected-note@-1 {{integer value 2147483648 is outside the valid range of values [-2147483648, 2147483647] for this enumeration type}} 
 }
 }
Index: clang/test/Sema/cast.c
===
--- clang/test/Sema/cast.c
+++ clang/test/Sema/cast.c
@@ -1,4 +1,8 @@
-// RUN: %clang_cc1 -fsyntax-only -triple x86_64-unknown-unknown %s -verify
+// RUN: %clang_cc1 -fsyntax-only -triple x86_64-unknown-unknown %s -verify -Wvla
+
+int array[(long)(char *)0]; // expected-warning {{variable length array used}} \
+// expected-warning {{variable length array folded to constant array as an extension}} \
+// expected-note {{this conversion is not allowed in a constant expression}}
 
 typedef struct { unsigned long bits[(((1) + (64) - 1) / (64))]; } cpumask_t;
 cpumask_t x;
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -8179,7 +8179,8 @@
   return LValueExprEvaluatorBaseTy::VisitCastExpr(E);
 
 case CK_LValueBitCast:
-  this->CCEDiag(E, diag::note_constexpr_invalid_cast) << 2;
+  this->CCEDiag(E, diag::note_constexpr_invalid_cast)
+  << 2 << Info.Ctx.getLangOpts().CPlusPlus;
   if (!Visit(E->getSubExpr()))
 return false;
   Result.Designator.setInvalid();
@@ -8890,9 +8891,10 @@
 Result.Designator.setInvalid();
 if (SubExpr->getType()->isVoidPointerType())
   CCEDiag(E, diag::note_constexpr_invalid_cast)
-<< 3 << SubExpr->getType();
+  << 3 << SubExpr->getType();
 else
-  CCEDiag(E, diag::note_constexpr_invalid_cast) << 2;
+  CCEDiag(E, diag::note_constexpr_invalid_cast)
+  << 2 << Info.Ctx.getLangOpts().CPlusPlus;
   }
 }
 if (E->getCastKind() == CK_AddressSpaceConversion && Result.IsNullPtr)
@@ -8929,7 +8931,8 @@
 return ZeroInitialization(E);
 
   case CK_IntegralToPointer: {
-CCEDiag(E, diag::note_constexpr_invalid_cast) << 2;
+CCEDiag(E, diag::note_constexpr_invalid_cast)
+<< 2 << Info.Ctx.getLangOpts().CPlusPlus;
 
 APValue Value;
 if (!EvaluateIntegerOrLValue(SubExpr, Value, Info))
@@ -13566,7 +13569,8 @@
   }
 
   case CK_PointerToIntegral: {
-CCEDiag(E, diag::note_constexpr_invalid_cast) << 2;
+CCEDiag(E, diag::note_constexpr_invalid_cast)
+<< 2 << Info.Ctx.getLangOpts().CPlusPlus;
 
 LValue LV;
 if (!EvaluatePointer(SubExpr, LV, Info))
Index: clang/include/clang/Basic/DiagnosticASTKinds.td
===
--- clang/include/clang/Basic/DiagnosticASTKinds.td
+++ clang/include/clang/Basic/DiagnosticASTKinds.td
@@ -11,8 +11,9 @@
 // Constant expression diagnostics. These 

[PATCH] D133194: rewording note note_constexpr_invalid_cast

2022-09-10 Thread Muhammad Usman Shahid via Phabricator via cfe-commits
Codesbyusman added a comment.

In D133194#3782198 , @aaron.ballman 
wrote:

> In D133194#3781271 , @Codesbyusman 
> wrote:
>
>> updated, I am not getting why this is happening but in the .cpp test file 
>> without Wvla all is working and is detecting by default as you are saying 
>> but when I use vla-warning/note it gives me error that "warning seen but not 
>> expected"
>
> It's because we're passing `-pedantic` on all three RUN lines; because the 
> file is a C++ source file, we issue the pedantic "you're using an extension" 
> warning: https://godbolt.org/z/a8nv6dhE5 so the `-Wvla` is redundant after 
> all (sorry for not catching that sooner).

Thank you for explanation.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133194

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


[PATCH] D132131: [clang-format] Adds a formatter for aligning trailing comments over empty lines

2022-09-10 Thread Yusuke Kadowaki via Phabricator via cfe-commits
yusuke-kadowaki marked 2 inline comments as done.
yusuke-kadowaki added a comment.

Thank you for the detailed explanation. I understood the needs for `unsigned 
OverEmptyLines` field.
Please review the struct definition first. Then I'll implement the rest of the 
code.




Comment at: clang/include/clang/Format/Format.h:428-433
+bool operator==(const TrailingCommentsAlignmentStyle ) const {
+  return Kind == R.Kind && OverEmptyLines == R.OverEmptyLines;
+}
+bool operator!=(const TrailingCommentsAlignmentStyle ) const {
+  return !(*this == R);
+}

> I don't understand the need for state as a struct could have multiple options 
> (as enums) each enum should have a state that means "Leave"

@MyDeveloperDay 
Without having state, how can this be implemented?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132131

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


[clang] 0e8afdd - [Clang] NFC: Remove duplicated variable def in CheckLValueConstantExpression

2022-09-10 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2022-09-10T19:10:23+02:00
New Revision: 0e8afddaa15fda1d50888b44695eecb89c0b1c0b

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

LOG: [Clang] NFC: Remove duplicated variable def in 
CheckLValueConstantExpression

Added: 


Modified: 
clang/lib/AST/ExprConstant.cpp

Removed: 




diff  --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index a5568e0158e33..26822a64b14c6 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -2174,12 +2174,10 @@ static bool CheckLValueConstantExpression(EvalInfo 
, SourceLocation Loc,
   // assumed to be global here.
   if (!IsGlobalLValue(Base)) {
 if (Info.getLangOpts().CPlusPlus11) {
-  const ValueDecl *VD = Base.dyn_cast();
   Info.FFDiag(Loc, diag::note_constexpr_non_global, 1)
-<< IsReferenceType << !Designator.Entries.empty()
-<< !!VD << VD;
-
-  auto *VarD = dyn_cast_or_null(VD);
+  << IsReferenceType << !Designator.Entries.empty() << !!BaseVD
+  << BaseVD;
+  auto *VarD = dyn_cast_or_null(BaseVD);
   if (VarD && VarD->isConstexpr()) {
 // Non-static local constexpr variables have unintuitive semantics:
 //   constexpr int a = 1;



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


[PATCH] D132131: [clang-format] Adds a formatter for aligning trailing comments over empty lines

2022-09-10 Thread Yusuke Kadowaki via Phabricator via cfe-commits
yusuke-kadowaki updated this revision to Diff 459292.
yusuke-kadowaki marked an inline comment as done.
yusuke-kadowaki added a comment.

Just updated the Style struct field definitions for review. Haven't implemented 
the logics.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132131

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/Format.cpp
  clang/lib/Format/WhitespaceManager.cpp
  clang/unittests/Format/FormatTest.cpp
  clang/unittests/Format/FormatTestComments.cpp

Index: clang/unittests/Format/FormatTestComments.cpp
===
--- clang/unittests/Format/FormatTestComments.cpp
+++ clang/unittests/Format/FormatTestComments.cpp
@@ -2858,6 +2858,182 @@
"int a; //\n");
 }
 
+TEST_F(FormatTestComments, AlignTrailingCommentsAcrossEmptyLines) {
+  FormatStyle Style = getLLVMStyle();
+  Style.AlignTrailingComments = FormatStyle::TCAS_AlignAcrossEmptyLines;
+  verifyFormat("#include \"a.h\"  // simple\n"
+   "\n"
+   "#include \"aa.h\" // example case\n",
+   Style);
+
+  verifyFormat("#include \"a.h\"   // align across\n"
+   "\n"
+   "#include \"aa.h\"  // two empty lines\n"
+   "\n"
+   "#include \"aaa.h\" // in a row\n",
+   Style);
+
+  verifyFormat("#include \"a.h\"  // align\n"
+   "#include \"aa.h\" // comment\n"
+   "#include \"aaa.h\"// blocks\n"
+   "\n"
+   "#include \".h\"   // across\n"
+   "#include \"a.h\"  // one\n"
+   "#include \"aa.h\" // empty line\n",
+   Style);
+
+  verifyFormat("#include \"a.h\"  // align trailing comments\n"
+   "#include \"a.h\"\n"
+   "#include \"aa.h\" // across a line without comment\n",
+   Style);
+
+  verifyFormat("#include \"a.h\"   // align across\n"
+   "#include \"a.h\"\n"
+   "#include \"aa.h\"  // two lines without comment\n"
+   "#include \"a.h\"\n"
+   "#include \"aaa.h\" // in a row\n",
+   Style);
+
+  verifyFormat("#include \"a.h\"  // align\n"
+   "#include \"aa.h\" // comment\n"
+   "#include \"aaa.h\"// blocks\n"
+   "#include \"a.h\"\n"
+   "#include \".h\"   // across\n"
+   "#include \"a.h\"  // a line without\n"
+   "#include \"aa.h\" // comment\n",
+   Style);
+
+  // Start of testing the combination with MaxEmptyLinesToKeep
+  Style.MaxEmptyLinesToKeep = 0;
+  verifyFormat("#include \"a.h\"  // comment\n"
+   "#include \"aa.h\" // comment\n",
+   Style);
+
+  Style.MaxEmptyLinesToKeep = 1;
+  verifyFormat("#include \"a.h\"  // comment\n"
+   "\n"
+   "#include \"aa.h\" // comment\n",
+   Style);
+
+  Style.MaxEmptyLinesToKeep = 2;
+  verifyFormat("#include \"a.h\"  // comment\n"
+   "\n"
+   "\n"
+   "#include \"aa.h\" // comment\n",
+   Style);
+
+  // Reset the setting
+  Style.MaxEmptyLinesToKeep = 1;
+  // End of testing the combination with MaxEmptyLinesToKeep
+
+  Style.ColumnLimit = 15;
+  EXPECT_EQ("int ab; // line\n"
+"int a;  // long\n"
+"// long\n"
+"\n"
+"// long",
+format("int ab; // line\n"
+   "int a; // long long\n"
+   "\n"
+   "// long",
+   Style));
+
+  Style.ColumnLimit = 15;
+  EXPECT_EQ("int ab; // line\n"
+"\n"
+"int a;  // long\n"
+"// long\n",
+format("int ab; // line\n"
+   "\n"
+   "int a; // long long\n",
+   Style));
+
+  Style.ColumnLimit = 30;
+  EXPECT_EQ("int foo = 12345; // comment\n"
+"int bar =\n"
+"1234;  // This is a very\n"
+"   // long comment\n"
+"   // which is wrapped\n"
+"   // arround.\n"
+"\n"
+"int x = 2; // Is this still\n"
+"   // aligned?\n",
+format("int foo = 12345; // comment\n"
+   "int bar = 1234; // This is a very long comment\n"
+   "// which is wrapped arround.\n"
+   "\n"
+   "int x = 2; // Is this still aligned?\n",
+   Style));
+
+  Style.ColumnLimit = 35;
+  EXPECT_EQ("int foo = 12345; // comment\n"
+"int bar =\n"
+"1234; // This is a very long\n"
+"  // comment which is\n"
+"  // wrapped arround.\n"
+"\n"

[PATCH] D125142: [clang][auto-init] Remove -enable flag for "zero" mode

2022-09-10 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 added a comment.

In D125142#3782244 , @nickdesaulniers 
wrote:

> @rsmith can we get some guidance here?  Has your opinion changed in the time 
> since GCC has been shipping this?

Maybe we should now ask @aaron.ballman as he is now main code owner.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125142

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


[PATCH] D133570: Clang codegen, fixes issue with emitting partially initialized constant arrays larger than 2^32

2022-09-10 Thread Ofek Shochat via Phabricator via cfe-commits
OfekShochat added a comment.

hello, solved the issue. it was, quite expectedly, a u64/unsigned problem in 
parsing, not codegen. no need to refactor this function. I will close this, 
thanks for the feedback and sorry for the hassle


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133570

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


[PATCH] D133088: [Clang] Fix wrong diagnostic for scope identifier with internal linkage

2022-09-10 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 459287.
junaire added a comment.

Try to address Aaron's comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133088

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaDecl.cpp
  clang/test/Parser/cxx1z-decomposition.cpp
  clang/test/Sema/array-init.c
  clang/test/Sema/err-decl-block-extern-no-init.c
  clang/test/Sema/private-extern.c

Index: clang/test/Sema/private-extern.c
===
--- clang/test/Sema/private-extern.c
+++ clang/test/Sema/private-extern.c
@@ -69,9 +69,9 @@
 struct s0 { int x; };
 
 void f9(void) {
-  extern int g15 = 0; // expected-error{{'extern' variable cannot have an initializer}}
+  extern int g15 = 0; // expected-error{{declaration of block scope identifier with linkage cannot have an initializer}}
   // FIXME: linkage specifier in warning.
-  __private_extern__ int g16 = 0; // expected-error{{'extern' variable cannot have an initializer}}
+  __private_extern__ int g16 = 0; // expected-error{{declaration of block scope identifier with linkage cannot have an initializer}}
 }
 
 extern int g17;
Index: clang/test/Sema/err-decl-block-extern-no-init.c
===
--- /dev/null
+++ clang/test/Sema/err-decl-block-extern-no-init.c
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fsyntax-only -verify %s
+static int x;
+
+void foo(void)
+{
+extern int x = 1; // expected-error {{declaration of block scope identifier with linkage cannot have an initializer}}
+}
+
+int y;
+
+void bar(void)
+{
+extern int y = 1; // expected-error {{declaration of block scope identifier with linkage cannot have an initializer}}
+
+}
Index: clang/test/Sema/array-init.c
===
--- clang/test/Sema/array-init.c
+++ clang/test/Sema/array-init.c
@@ -48,7 +48,7 @@
 
   struct threeElements *p = 7; // expected-error{{incompatible integer to pointer conversion initializing 'struct threeElements *' with an expression of type 'int'}}
 
-  extern int blockScopeExtern[3] = { 1, 3, 5 }; // expected-error{{'extern' variable cannot have an initializer}}
+  extern int blockScopeExtern[3] = { 1, 3, 5 }; // expected-error{{declaration of block scope identifier with linkage cannot have an initializer}}
 
   static long x2[3] = { 1.0,
 "abc", // expected-error{{incompatible pointer to integer conversion initializing 'long' with an expression of type 'char[4]'}}
Index: clang/test/Parser/cxx1z-decomposition.cpp
===
--- clang/test/Parser/cxx1z-decomposition.cpp
+++ clang/test/Parser/cxx1z-decomposition.cpp
@@ -69,7 +69,7 @@
 // storage-class-specifiers
 static auto &[a] = n; // expected-warning {{declared 'static' is a C++20 extension}}
 thread_local auto &[b] = n; // expected-warning {{declared 'thread_local' is a C++20 extension}}
-extern auto &[c] = n; // expected-error {{cannot be declared 'extern'}} expected-error {{cannot have an initializer}}
+extern auto &[c] = n; // expected-error {{cannot be declared 'extern'}} expected-error {{declaration of block scope identifier with linkage cannot have an initializer}}
 struct S {
   mutable auto &[d] = n; // expected-error {{not permitted in this context}}
 
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -12773,8 +12773,11 @@
 return;
   }
 
+  // C99 6.7.8p5. If the declaration of an identifier has block scope, and
+  // the identifier has external or internal linkage, the declaration shall
+  // have no initializer for the identifier.
+  // C++14 [dcl.init]p5 is the same restriction for C++.
   if (VDecl->isLocalVarDecl() && VDecl->hasExternalStorage()) {
-// C99 6.7.8p5. C++ has no such restriction, but that is a defect.
 Diag(VDecl->getLocation(), diag::err_block_extern_cant_init);
 VDecl->setInvalidDecl();
 return;
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -5901,7 +5901,7 @@
 : Error<"variable %0 cannot be declared both 'extern' and with the "
 "'loader_uninitialized' attribute">;
 def err_block_extern_cant_init : Error<
-  "'extern' variable cannot have an initializer">;
+  "declaration of block scope identifier with linkage cannot have an initializer">;
 def warn_extern_init : Warning<"'extern' variable has an initializer">,
   InGroup>;
 def err_variable_object_no_init : Error<
Index: clang/docs/ReleaseNotes.rst

[PATCH] D125142: [clang][auto-init] Remove -enable flag for "zero" mode

2022-09-10 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers added a comment.

@rsmith can we get some guidance here?  Has your opinion changed in the time 
since GCC has been shipping this?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125142

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


[PATCH] D133641: [Clang] [Sema] Ignore invalid multiversion function redeclarations

2022-09-10 Thread Evgeny Shulgin via Phabricator via cfe-commits
Izaron added a comment.

How the bug was working on this example:

  void foo() {}
  [[gnu::target("default")]] void foo() {}
  [[gnu::target("avx2")]] void foo() {}



1. Clang parses the definition of the `foo` function (line 1)
2. When parsing the second definition (line 2), Clang will delete `TargetAttr` 
in this function 

3. Eventually Clang will mark both `foo`s as invalid.
4. When parsing the third definition (line 3), in the 
`CheckMultiVersionAdditionalDecl` method Clang is trying to compare 
`TargetAttr` of the 2nd and the 3rd `foo`: link 
.
5. The `CurTA` variable is equal to `nullptr` (because we deleted the attribute 
in the second step), so there is undefined behaviour.

I suggest to stop looking to invalid declarations.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133641

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


[PATCH] D133641: [Clang] [Sema] Ignore invalid multiversion function redeclarations

2022-09-10 Thread Evgeny Shulgin via Phabricator via cfe-commits
Izaron created this revision.
Izaron added reviewers: tahonermann, erichkeane.
Herald added a project: All.
Izaron requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

If a redeclaration of a multiversion function is invalid,
it may be in a broken condition (for example, missing an important
attribute). We shouldn't analyze invalid redeclarations.

Fixes https://github.com/llvm/llvm-project/issues/57343


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D133641

Files:
  clang/lib/Sema/SemaDecl.cpp
  clang/test/Sema/attr-target-mv.c


Index: clang/test/Sema/attr-target-mv.c
===
--- clang/test/Sema/attr-target-mv.c
+++ clang/test/Sema/attr-target-mv.c
@@ -52,6 +52,15 @@
 // expected-note@-2 {{previous definition is here}}
 int __attribute__((target("default"))) redef2(void) { return 1;}
 
+int redef3(void) { return 1; }
+// expected-warning@+4 {{attribute declaration must precede definition}}
+// expected-note@-2 {{previous definition is here}}
+// expected-error@+2 {{redefinition of 'redef3'}}
+// expected-note@-4 {{previous definition is here}}
+int __attribute__((target("default"))) redef3(void) { return 1; }
+// allow this, since we don't complain about more than one redefinition
+int __attribute__((target("sse4.2"))) redef3(void) { return 1; }
+
 int __attribute__((target("sse4.2"))) mv_after_use(void) { return 1; }
 int use3(void) {
   return mv_after_use();
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -11081,11 +11081,11 @@
   bool MayNeedOverloadableChecks =
   AllowOverloadingOfFunction(Previous, S.Context, NewFD);
 
-  // Next, check ALL non-overloads to see if this is a redeclaration of a
-  // previous member of the MultiVersion set.
+  // Next, check ALL non-invalid non-overloads to see if this is a 
redeclaration
+  // of a previous member of the MultiVersion set.
   for (NamedDecl *ND : Previous) {
 FunctionDecl *CurFD = ND->getAsFunction();
-if (!CurFD)
+if (!CurFD || CurFD->isInvalidDecl())
   continue;
 if (MayNeedOverloadableChecks &&
 S.IsOverload(NewFD, CurFD, UseMemberUsingDeclRules))


Index: clang/test/Sema/attr-target-mv.c
===
--- clang/test/Sema/attr-target-mv.c
+++ clang/test/Sema/attr-target-mv.c
@@ -52,6 +52,15 @@
 // expected-note@-2 {{previous definition is here}}
 int __attribute__((target("default"))) redef2(void) { return 1;}
 
+int redef3(void) { return 1; }
+// expected-warning@+4 {{attribute declaration must precede definition}}
+// expected-note@-2 {{previous definition is here}}
+// expected-error@+2 {{redefinition of 'redef3'}}
+// expected-note@-4 {{previous definition is here}}
+int __attribute__((target("default"))) redef3(void) { return 1; }
+// allow this, since we don't complain about more than one redefinition
+int __attribute__((target("sse4.2"))) redef3(void) { return 1; }
+
 int __attribute__((target("sse4.2"))) mv_after_use(void) { return 1; }
 int use3(void) {
   return mv_after_use();
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -11081,11 +11081,11 @@
   bool MayNeedOverloadableChecks =
   AllowOverloadingOfFunction(Previous, S.Context, NewFD);
 
-  // Next, check ALL non-overloads to see if this is a redeclaration of a
-  // previous member of the MultiVersion set.
+  // Next, check ALL non-invalid non-overloads to see if this is a redeclaration
+  // of a previous member of the MultiVersion set.
   for (NamedDecl *ND : Previous) {
 FunctionDecl *CurFD = ND->getAsFunction();
-if (!CurFD)
+if (!CurFD || CurFD->isInvalidDecl())
   continue;
 if (MayNeedOverloadableChecks &&
 S.IsOverload(NewFD, CurFD, UseMemberUsingDeclRules))
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D133635: [clang-format] Don't insert braces for loops with a null statement

2022-09-10 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added a comment.

Can't tell you how much I love this `InsertBraces` feature @ownpan,  I work for 
a team (with a large code base) that uses them all the time, and we are 
catching missing braces in decade-old code! Thank you


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133635

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


[PATCH] D133589: [clang-format] JSON formatting add new option for controlling newlines in json arrays

2022-09-10 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added inline comments.



Comment at: clang/docs/ClangFormatStyleOptions.rst:3115
 
+**JsonMultilineArrays** (``Boolean``) :versionbadge:`clang-format 16`
+  If ``true``, clang-format will always break after a Json array `[`

MyDeveloperDay wrote:
> curdeius wrote:
> > Why limiting to JSON only?
> > Could we name it in a general fashion (we comment that it's JSON only for 
> > the time being). I believe it may be an interesting option for various 
> > languages.
> > 
> > How about BreakMultilineArrays, or just BreakArrays to follow the naming of 
> > existing options a bit?
> I'm going to change the name to be `BreakArrays` but I'm not 100% sure who it 
> might help other languages, but maybe we can look at this afterwards so 
> having a good name now will help us later on.
> Why limiting to JSON only?

I'm slightly wondering if it would get over rrules by code later on, but we 
could try I guess, I think we'd need to handle the [] / {} separately I think.




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

https://reviews.llvm.org/D133589

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


[PATCH] D133589: [clang-format] JSON formatting add new option for controlling newlines in json arrays

2022-09-10 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added a comment.

Addressed review comments, renamed the options




Comment at: clang/docs/ClangFormatStyleOptions.rst:3115
 
+**JsonMultilineArrays** (``Boolean``) :versionbadge:`clang-format 16`
+  If ``true``, clang-format will always break after a Json array `[`

curdeius wrote:
> Why limiting to JSON only?
> Could we name it in a general fashion (we comment that it's JSON only for the 
> time being). I believe it may be an interesting option for various languages.
> 
> How about BreakMultilineArrays, or just BreakArrays to follow the naming of 
> existing options a bit?
I'm going to change the name to be `BreakArrays` but I'm not 100% sure who it 
might help other languages, but maybe we can look at this afterwards so having 
a good name now will help us later on.



Comment at: clang/lib/Format/TokenAnnotator.cpp:4405-4408
 if (Left.is(TT_ArrayInitializerLSquare) && Left.is(tok::l_square) &&
 !Right.is(tok::r_square)) {
-  return true;
+  if (Right.is(tok::l_brace))
+return true;

owenpan wrote:
> Merge the check for `comma` below to avoid repeated code. Also, the check for 
> `l_brace` is redundant.
@owenpan you have a very fine eye.. I didn't see that and had to reread your 
comments a couple of times! Thank you its much cleaner now



Comment at: clang/lib/Format/TokenAnnotator.cpp:4427
+if (Left.is(tok::comma)) {
+  if (Right.is(tok::l_brace)) {
+return true;

curdeius wrote:
> You can elide braces here.
This was funny I had RemoveBracesLLVM on, but it didn't get rid of them 
automatically, I wonder if this was my fault or if we are missing a case for 
the RemoveBraces option, but thanks you be done now


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

https://reviews.llvm.org/D133589

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


[PATCH] D133589: [clang-format] JSON formatting add new option for controlling newlines in json arrays

2022-09-10 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay updated this revision to Diff 459283.
MyDeveloperDay marked 7 inline comments as done.

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

https://reviews.llvm.org/D133589

Files:
  clang/.clang-format
  clang/docs/ClangFormatStyleOptions.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/Format.cpp
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/FormatTestJson.cpp

Index: clang/unittests/Format/FormatTestJson.cpp
===
--- clang/unittests/Format/FormatTestJson.cpp
+++ clang/unittests/Format/FormatTestJson.cpp
@@ -159,6 +159,27 @@
"]");
 }
 
+TEST_F(FormatTestJson, JsonArrayOneLine) {
+  FormatStyle Style = getLLVMStyle(FormatStyle::LK_Json);
+  Style.BreakArrays = false;
+  Style.SpacesInContainerLiterals = false;
+  verifyFormat("[]", Style);
+  verifyFormat("[1]", Style);
+  verifyFormat("[1, 2]", Style);
+  verifyFormat("[1, 2, 3]", Style);
+  verifyFormat("[1, 2, 3, 4]", Style);
+  verifyFormat("[1, 2, 3, 4, 5]", Style);
+
+  verifyFormat("[\n"
+   "  1,\n"
+   "  2,\n"
+   "  {\n"
+   "A: 1\n"
+   "  }\n"
+   "]",
+   Style);
+}
+
 TEST_F(FormatTestJson, JsonNoStringSplit) {
   FormatStyle Style = getLLVMStyle(FormatStyle::LK_Json);
   Style.IndentWidth = 4;
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -4399,18 +4399,22 @@
 // }
 if (Left.is(TT_DictLiteral) && Left.is(tok::l_brace))
   return true;
-// Always break after a JSON array opener.
-// [
-// ]
+// Always break after a JSON array opener based on BreakArrays
 if (Left.is(TT_ArrayInitializerLSquare) && Left.is(tok::l_square) &&
-!Right.is(tok::r_square)) {
-  return true;
+Right.isNot(tok::r_square) ||
+Left.is(tok::comma)) {
+  if (Right.is(tok::l_brace))
+return true;
+  // scan to the right if an we see an object or an array inside
+  // then break
+  for (const auto *Tok =  Tok; Tok = Tok->Next) {
+if (Tok->isOneOf(tok::l_brace, tok::l_square))
+  return true;
+if (Tok->isOneOf(tok::r_brace, tok::r_square))
+  break;
+  }
+  return Style.BreakArrays;
 }
-// Always break after successive entries.
-// 1,
-// 2
-if (Left.is(tok::comma))
-  return true;
   }
 
   // If the last token before a '}', ']', or ')' is a comma or a trailing
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -756,6 +756,8 @@
 IO.mapOptional("ExperimentalAutoDetectBinPacking",
Style.ExperimentalAutoDetectBinPacking);
 
+IO.mapOptional("BreakArrays", Style.BreakArrays);
+
 IO.mapOptional("PackConstructorInitializers",
Style.PackConstructorInitializers);
 // For backward compatibility:
@@ -1249,6 +1251,7 @@
   LLVMStyle.EmptyLineAfterAccessModifier = FormatStyle::ELAAMS_Never;
   LLVMStyle.EmptyLineBeforeAccessModifier = FormatStyle::ELBAMS_LogicalBlock;
   LLVMStyle.ExperimentalAutoDetectBinPacking = false;
+  LLVMStyle.BreakArrays = true;
   LLVMStyle.PackConstructorInitializers = FormatStyle::PCIS_BinPack;
   LLVMStyle.FixNamespaceComments = true;
   LLVMStyle.ForEachMacros.push_back("foreach");
Index: clang/include/clang/Format/Format.h
===
--- clang/include/clang/Format/Format.h
+++ clang/include/clang/Format/Format.h
@@ -2058,6 +2058,23 @@
   /// \version 12
   EmptyLineBeforeAccessModifierStyle EmptyLineBeforeAccessModifier;
 
+  /// If ``true``, clang-format will always break after a Json array `[`
+  /// otherwise it will scan until the closing `]` to determine if it should add
+  /// newlines between elements (prettier compatible)
+  ///
+  /// NOTE: This is currently only for formatting JSON
+  /// \code
+  ///true:  false:
+  ///[  vs.  [1, 2, 3, 4]
+  ///  1,
+  ///  2,
+  ///  3,
+  ///  4
+  ///]
+  /// \endcode
+  /// \version 16
+  bool BreakArrays;
+
   /// If ``true``, clang-format detects whether function calls and
   /// definitions are formatted with one parameter per line.
   ///
@@ -3897,6 +3914,7 @@
DisableFormat == R.DisableFormat &&
EmptyLineAfterAccessModifier == R.EmptyLineAfterAccessModifier &&
EmptyLineBeforeAccessModifier == R.EmptyLineBeforeAccessModifier &&
+   BreakArrays == R.BreakArrays &&
ExperimentalAutoDetectBinPacking ==
R.ExperimentalAutoDetectBinPacking &&
PackConstructorInitializers == 

[PATCH] D133194: rewording note note_constexpr_invalid_cast

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

In D133194#3781271 , @Codesbyusman 
wrote:

> updated, I am not getting why this is happening but in the .cpp test file 
> without Wvla all is working and is detecting by default as you are saying but 
> when I use vla-warning/note it gives me error that "warning seen but not 
> expected"

It's because we're passing `-pedantic` on all three RUN lines; because the file 
is a C++ source file, we issue the pedantic "you're using an extension" 
warning: https://godbolt.org/z/a8nv6dhE5 so the `-Wvla` is redundant after all 
(sorry for not catching that sooner).




Comment at: clang/lib/AST/ExprConstant.cpp:7476-7477
   bool VisitCXXReinterpretCastExpr(const CXXReinterpretCastExpr *E) {
-CCEDiag(E, diag::note_constexpr_invalid_cast) << 0;
+CCEDiag(E, diag::note_constexpr_invalid_cast)
+<< 0 << Info.Ctx.getLangOpts().CPlusPlus;
 return static_cast(this)->VisitCastExpr(E);




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133194

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


[PATCH] D133518: [HLSL] Call global destructors from entries

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

In D133518#3781308 , @beanz wrote:

> In D133518#3781101 , @aaron.ballman 
> wrote:
>
>> This generally LGTM, but to double-check: the behavior if the user does call 
>> `atexit()` or or `at_quick_exit()` is that we simply don't call those 
>> handlers? As opposed to something worse like we dispatch to the handler and 
>> then crash on exit or something like that?
>
> There should be no way to successfully compile and link a shader calling 
> `atexit()` or `at_quick_exit()`. Neither of those functions are provided by 
> the runtime so it should turn into a compile or linking error somewhere in 
> the build process (either missing declaration or missing symbol resolution).

Wonderful! Then this LGTM!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133518

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


[PATCH] D133088: [Clang] Fix wrong diagnostic for scope identifier with internal linkage

2022-09-10 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D133088#3782126 , @pmor13 wrote:

> @aaron.ballman
>
>> block scope variable to have *internal* linkage instead of *no* linkage
>
>   static int x;
>   
>   void f(void)
>   {
>   extern int x;  // block scope, internal linkage 
>   }

No, I understood that, I meant in terms of the semantics. I'm not 100% 
convinced there's a way to *observe* the difference between no and internal 
linkage, but I *think* you might be able to observe it regarding an inline 
function returning the address of an internal linkage variable. If it's 
internal linkage, every copy of the function shares the same object but if it 
had no linkage, the linker wouldn't have to collapse them all down to the same 
object (maybe?).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133088

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


[PATCH] D133354: [Clang]: Diagnose deprecated copy operations also in MSVC compatibility mode

2022-09-10 Thread Julius via Phabricator via cfe-commits
ningvin updated this revision to Diff 459277.
ningvin added a comment.

I added the respective RUN lines to the different test cases, did not seem to 
break anything on my end.


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

https://reviews.llvm.org/D133354

Files:
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/SemaCXX/deprecated-copy-with-dtor.cpp
  clang/test/SemaCXX/deprecated-copy-with-user-provided-copy.cpp
  clang/test/SemaCXX/deprecated-copy-with-user-provided-dtor.cpp
  clang/test/SemaCXX/deprecated-copy.cpp
  clang/test/SemaCXX/deprecated.cpp


Index: clang/test/SemaCXX/deprecated.cpp
===
--- clang/test/SemaCXX/deprecated.cpp
+++ clang/test/SemaCXX/deprecated.cpp
@@ -1,10 +1,16 @@
 // RUN: %clang_cc1 -std=c++98 %s -Wno-parentheses -Wdeprecated 
-verify=expected,not-cxx20 -triple x86_64-linux-gnu
+// RUN: %clang_cc1 -std=c++98 %s -Wno-parentheses -Wdeprecated 
-verify=expected,not-cxx20 -triple x86_64-linux-gnu -fms-compatibility
 // RUN: %clang_cc1 -std=c++11 %s -Wno-parentheses -Wdeprecated 
-verify=expected,not-cxx20 -triple x86_64-linux-gnu
+// RUN: %clang_cc1 -std=c++11 %s -Wno-parentheses -Wdeprecated 
-verify=expected,not-cxx20 -triple x86_64-linux-gnu -fms-compatibility
 // RUN: %clang_cc1 -std=c++14 %s -Wno-parentheses -Wdeprecated 
-verify=expected,not-cxx20 -triple x86_64-linux-gnu
+// RUN: %clang_cc1 -std=c++14 %s -Wno-parentheses -Wdeprecated 
-verify=expected,not-cxx20 -triple x86_64-linux-gnu -fms-compatibility
 // RUN: %clang_cc1 -std=c++17 %s -Wno-parentheses -Wdeprecated 
-verify=expected,not-cxx20 -triple x86_64-linux-gnu
+// RUN: %clang_cc1 -std=c++17 %s -Wno-parentheses -Wdeprecated 
-verify=expected,not-cxx20 -triple x86_64-linux-gnu -fms-compatibility
 // RUN: %clang_cc1 -std=c++2a %s -Wno-parentheses -Wdeprecated 
-verify=expected,cxx20 -triple x86_64-linux-gnu
+// RUN: %clang_cc1 -std=c++2a %s -Wno-parentheses -Wdeprecated 
-verify=expected,cxx20 -triple x86_64-linux-gnu -fms-compatibility
 
 // RUN: %clang_cc1 -std=c++14 %s -Wno-parentheses -Wdeprecated 
-verify=expected,not-cxx20 -triple x86_64-linux-gnu -Wno-deprecated-register 
-DNO_DEPRECATED_FLAGS
+// RUN: %clang_cc1 -std=c++14 %s -Wno-parentheses -Wdeprecated 
-verify=expected,not-cxx20 -triple x86_64-linux-gnu -Wno-deprecated-register 
-DNO_DEPRECATED_FLAGS -fms-compatibility
 
 #include "Inputs/register.h"
 
Index: clang/test/SemaCXX/deprecated-copy.cpp
===
--- clang/test/SemaCXX/deprecated-copy.cpp
+++ clang/test/SemaCXX/deprecated-copy.cpp
@@ -1,5 +1,7 @@
 // RUN: %clang_cc1 -std=c++11 %s -Wdeprecated -verify
+// RUN: %clang_cc1 -std=c++11 %s -Wdeprecated -verify -fms-compatibility
 // RUN: %clang_cc1 -std=c++11 %s -Wdeprecated-copy -verify
+// RUN: %clang_cc1 -std=c++11 %s -Wdeprecated-copy -verify -fms-compatibility
 
 struct A {
 A& operator=(const A&) = default; // expected-warning {{definition of 
implicit copy constructor for 'A' is deprecated because it has a user-declared 
copy assignment operator}}
Index: clang/test/SemaCXX/deprecated-copy-with-user-provided-dtor.cpp
===
--- clang/test/SemaCXX/deprecated-copy-with-user-provided-dtor.cpp
+++ clang/test/SemaCXX/deprecated-copy-with-user-provided-dtor.cpp
@@ -1,5 +1,7 @@
 // RUN: %clang_cc1 -std=c++11 %s -Wdeprecated -verify
+// RUN: %clang_cc1 -std=c++11 %s -Wdeprecated -verify -fms-compatibility
 // RUN: %clang_cc1 -std=c++11 %s -Wdeprecated-copy-with-user-provided-dtor 
-verify
+// RUN: %clang_cc1 -std=c++11 %s -Wdeprecated-copy-with-user-provided-dtor 
-verify -fms-compatibility
 
 struct A {
   ~A(); // expected-warning {{definition of implicit copy constructor for 'A' 
is deprecated because it has a user-provided destructor}}
Index: clang/test/SemaCXX/deprecated-copy-with-user-provided-copy.cpp
===
--- clang/test/SemaCXX/deprecated-copy-with-user-provided-copy.cpp
+++ clang/test/SemaCXX/deprecated-copy-with-user-provided-copy.cpp
@@ -1,5 +1,7 @@
 // RUN: %clang_cc1 -std=c++11 %s -Wdeprecated -verify
+// RUN: %clang_cc1 -std=c++11 %s -Wdeprecated -verify -fms-compatibility
 // RUN: %clang_cc1 -std=c++11 %s -Wdeprecated-copy-with-user-provided-copy 
-verify
+// RUN: %clang_cc1 -std=c++11 %s -Wdeprecated-copy-with-user-provided-copy 
-verify -fms-compatibility
 
 struct A {
   A =(const A &); // expected-warning {{definition of implicit copy 
constructor for 'A' is deprecated because it has a user-provided copy 
assignment operator}}
Index: clang/test/SemaCXX/deprecated-copy-with-dtor.cpp
===
--- clang/test/SemaCXX/deprecated-copy-with-dtor.cpp
+++ clang/test/SemaCXX/deprecated-copy-with-dtor.cpp
@@ -1,6 +1,9 @@
 // RUN: %clang_cc1 -std=c++11 %s -Wdeprecated -verify
+// RUN: %clang_cc1 -std=c++11 %s -Wdeprecated 

[PATCH] D133405: [Linux] Hack around Linux/sparc

2022-09-10 Thread John Paul Adrian Glaubitz via Phabricator via cfe-commits
glaubitz added a comment.

In D133405#3782137 , @nikic wrote:

> In D133405#3782136 , @glaubitz 
> wrote:
>
>> In D133405#3782092 , @nikic wrote:
>>
 I've been using this hack to work around the Linux/sparc64 compile failure 
 described in Issue #47994, especially since the underlying glibc PR 
 build/27558 doesn't seem to be making progress and some fix is required to 
 have LLVM build on sparc64-unknown-linux-gnu at all, as evidenced on the 
 buildbot.
>>>
>>> Didn't this already get fixed by 
>>> https://github.com/bminor/glibc/commit/d0fa09a7701956036ff36f8ca188e9fff81553d8
>>>  upstream? There was also a later fix for the wchar.h header.
>>
>> Seems it has only been fixed for some headers, see: 
>> https://sourceware.org/bugzilla/show_bug.cgi?id=27087
>
> The other issue has also already been fixed in 
> https://github.com/bminor/glibc/commit/c7509d49c4e8fa494120c5ead21338559dad16f5
>  (and these fixes have been backported to glibc 2.34+).
>
> Are you still seeing any issues with a current glibc?

glibc 2.34 currently fails to build from source on sparc64 due to testsuite 
failures. I haven't reported these upstream yet which I will do now.

See: 
https://buildd.debian.org/status/fetch.php?pkg=glibc=sparc64=2.34-7=1661614017=0

  FAIL: elf/tst-audit24a
  FAIL: elf/tst-audit24b
  FAIL: elf/tst-audit24c
  FAIL: elf/tst-audit24d
  FAIL: elf/tst-audit25a
  FAIL: elf/tst-audit25b
  FAIL: elf/tst-ptrguard1-static
  FAIL: elf/tst-stackguard1-static
  FAIL: nptl/tst-cancel24-static
  FAIL: nptl/tst-cancel30
  FAIL: nptl/tst-pthread-attr-affinity-fail
  FAIL: nptl/tst-stackguard1-static
  FAIL: socket/tst-socket-timestamp


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133405

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


[PATCH] D133405: [Linux] Hack around Linux/sparc

2022-09-10 Thread Nikita Popov via Phabricator via cfe-commits
nikic added a comment.

In D133405#3782136 , @glaubitz wrote:

> In D133405#3782092 , @nikic wrote:
>
>>> I've been using this hack to work around the Linux/sparc64 compile failure 
>>> described in Issue #47994, especially since the underlying glibc PR 
>>> build/27558 doesn't seem to be making progress and some fix is required to 
>>> have LLVM build on sparc64-unknown-linux-gnu at all, as evidenced on the 
>>> buildbot.
>>
>> Didn't this already get fixed by 
>> https://github.com/bminor/glibc/commit/d0fa09a7701956036ff36f8ca188e9fff81553d8
>>  upstream? There was also a later fix for the wchar.h header.
>
> Seems it has only been fixed for some headers, see: 
> https://sourceware.org/bugzilla/show_bug.cgi?id=27087

The other issue has also already been fixed in 
https://github.com/bminor/glibc/commit/c7509d49c4e8fa494120c5ead21338559dad16f5 
(and these fixes have been backported to glibc 2.34+).

Are you still seeing any issues with a current glibc?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133405

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


[PATCH] D133405: [Linux] Hack around Linux/sparc

2022-09-10 Thread John Paul Adrian Glaubitz via Phabricator via cfe-commits
glaubitz added a comment.

In D133405#3782092 , @nikic wrote:

>> I've been using this hack to work around the Linux/sparc64 compile failure 
>> described in Issue #47994, especially since the underlying glibc PR 
>> build/27558 doesn't seem to be making progress and some fix is required to 
>> have LLVM build on sparc64-unknown-linux-gnu at all, as evidenced on the 
>> buildbot.
>
> Didn't this already get fixed by 
> https://github.com/bminor/glibc/commit/d0fa09a7701956036ff36f8ca188e9fff81553d8
>  upstream? There was also a later fix for the wchar.h header.

Seems it has only been fixed for some headers, see: 
https://sourceware.org/bugzilla/show_bug.cgi?id=27087


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133405

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


[PATCH] D133088: [Clang] Fix wrong diagnostic for scope identifier with internal linkage

2022-09-10 Thread pmor via Phabricator via cfe-commits
pmor13 added a comment.

@aaron.ballman

> block scope variable to have *internal* linkage instead of *no* linkage

  static int x;
  
  void f(void)
  {
  extern int x;  // block scope, internal linkage 
  }


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133088

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


[PATCH] D133405: [Linux] Hack around Linux/sparc

2022-09-10 Thread Nikita Popov via Phabricator via cfe-commits
nikic added a comment.

> I've been using this hack to work around the Linux/sparc64 compile failure 
> described in Issue #47994, especially since the underlying glibc PR 
> build/27558 doesn't seem to be making progress and some fix is required to 
> have LLVM build on sparc64-unknown-linux-gnu at all, as evidenced on the 
> buildbot.

Didn't this already get fixed by 
https://github.com/bminor/glibc/commit/d0fa09a7701956036ff36f8ca188e9fff81553d8 
upstream? There was also a later fix for the wchar.h header.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133405

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


[PATCH] D86049: RFC: Implement optional exportable wrapper function generation for objc_direct methods.

2022-09-10 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi marked an inline comment as done.
plotfi added inline comments.



Comment at: clang/test/CodeGenObjC/objc-direct-wrapper.m:35
+
+@interface C
+- (void)testMethod:(int)arg1 bar:(float)arg2 OBJC_DIRECT;

dmaclach wrote:
> I'd like to see a test for the protocol case for coverage.
How does this test look for protocol? 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86049

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


[PATCH] D133405: [Linux] Hack around Linux/sparc

2022-09-10 Thread Rainer Orth via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG1e56821bac02: [Linux] Hack around Linux/sparc 
bits/stdio-ldbl.h (authored by ro).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133405

Files:
  clang/lib/Basic/Targets/OSTargets.h
  clang/test/Preprocessor/init.c


Index: clang/test/Preprocessor/init.c
===
--- clang/test/Preprocessor/init.c
+++ clang/test/Preprocessor/init.c
@@ -874,6 +874,9 @@
 
 // RUN: %clang_cc1 -E -dM -ffreestanding -fgnuc-version=4.2.1 
-triple=sparc-none-none < /dev/null | FileCheck -match-full-lines -check-prefix 
SPARC -check-prefix SPARC-DEFAULT %s
 // RUN: %clang_cc1 -E -dM -ffreestanding -fgnuc-version=4.2.1 
-triple=sparc-rtems-elf < /dev/null | FileCheck -match-full-lines -check-prefix 
SPARC -check-prefix SPARC-DEFAULT %s
+// Check that clang defines __NO_INLINE__ unconditionally (even at -O) to
+// work around Issue #47994.
+// RUN: %clang_cc1 -E -dM -triple=sparc-unknown-linux-gnu -O < /dev/null | 
FileCheck -match-full-lines -check-prefix SPARC-LINUX %s
 // RUN: %clang_cc1 -E -dM -ffreestanding -fgnuc-version=4.2.1 
-triple=sparc-none-netbsd < /dev/null | FileCheck -match-full-lines 
-check-prefix SPARC -check-prefix SPARC-NETOPENBSD %s
 // RUN: %clang_cc1 -x c++ -E -dM -ffreestanding -fgnuc-version=4.2.1 
-triple=sparc-none-none < /dev/null | FileCheck -match-full-lines -check-prefix 
SPARC -check-prefix SPARC-DEFAULT -check-prefix SPARC-DEFAULT-CXX %s
 //
@@ -997,6 +1000,7 @@
 // SPARC:#define __LONG_LONG_MAX__ 9223372036854775807LL
 // SPARC:#define __LONG_MAX__ 2147483647L
 // SPARC-NOT:#define __LP64__
+// SPARC-LINUX:#define __NO_INLINE__ 1
 // SPARC:#define __POINTER_WIDTH__ 32
 // SPARC-DEFAULT:#define __PTRDIFF_TYPE__ int
 // SPARC-NETOPENBSD:#define __PTRDIFF_TYPE__ long int
@@ -1380,6 +1384,11 @@
 // SPARCV9:#define __SIZEOF_POINTER__ 8
 // SPARCV9:#define __UINTPTR_TYPE__ long unsigned int
 //
+// Check that clang defines __NO_INLINE__ unconditionally (even at -O) to
+// work around Issue #47994.
+// RUN: %clang_cc1 -E -dM -triple=sparc64-unknown-linux-gnu -O < /dev/null | 
FileCheck -match-full-lines -check-prefix SPARC64-LINUX %s
+// SPARC64-LINUX:#define __NO_INLINE__ 1
+//
 // RUN: %clang_cc1 -E -dM -ffreestanding -triple=sparc64-none-openbsd < 
/dev/null | FileCheck -match-full-lines -check-prefix SPARC64-OBSD %s
 // SPARC64-OBSD:#define __INT64_TYPE__ long long int
 // SPARC64-OBSD:#define __INTMAX_C_SUFFIX__ LL
Index: clang/lib/Basic/Targets/OSTargets.h
===
--- clang/lib/Basic/Targets/OSTargets.h
+++ clang/lib/Basic/Targets/OSTargets.h
@@ -388,6 +388,9 @@
 } else {
 Builder.defineMacro("__gnu_linux__");
 }
+// Work around Issue #47994 until glibc PR build/27558 is fixed.
+if (Triple.isSPARC())
+  Builder.defineMacro("__NO_INLINE__");
 if (Opts.POSIXThreads)
   Builder.defineMacro("_REENTRANT");
 if (Opts.CPlusPlus)


Index: clang/test/Preprocessor/init.c
===
--- clang/test/Preprocessor/init.c
+++ clang/test/Preprocessor/init.c
@@ -874,6 +874,9 @@
 
 // RUN: %clang_cc1 -E -dM -ffreestanding -fgnuc-version=4.2.1 -triple=sparc-none-none < /dev/null | FileCheck -match-full-lines -check-prefix SPARC -check-prefix SPARC-DEFAULT %s
 // RUN: %clang_cc1 -E -dM -ffreestanding -fgnuc-version=4.2.1 -triple=sparc-rtems-elf < /dev/null | FileCheck -match-full-lines -check-prefix SPARC -check-prefix SPARC-DEFAULT %s
+// Check that clang defines __NO_INLINE__ unconditionally (even at -O) to
+// work around Issue #47994.
+// RUN: %clang_cc1 -E -dM -triple=sparc-unknown-linux-gnu -O < /dev/null | FileCheck -match-full-lines -check-prefix SPARC-LINUX %s
 // RUN: %clang_cc1 -E -dM -ffreestanding -fgnuc-version=4.2.1 -triple=sparc-none-netbsd < /dev/null | FileCheck -match-full-lines -check-prefix SPARC -check-prefix SPARC-NETOPENBSD %s
 // RUN: %clang_cc1 -x c++ -E -dM -ffreestanding -fgnuc-version=4.2.1 -triple=sparc-none-none < /dev/null | FileCheck -match-full-lines -check-prefix SPARC -check-prefix SPARC-DEFAULT -check-prefix SPARC-DEFAULT-CXX %s
 //
@@ -997,6 +1000,7 @@
 // SPARC:#define __LONG_LONG_MAX__ 9223372036854775807LL
 // SPARC:#define __LONG_MAX__ 2147483647L
 // SPARC-NOT:#define __LP64__
+// SPARC-LINUX:#define __NO_INLINE__ 1
 // SPARC:#define __POINTER_WIDTH__ 32
 // SPARC-DEFAULT:#define __PTRDIFF_TYPE__ int
 // SPARC-NETOPENBSD:#define __PTRDIFF_TYPE__ long int
@@ -1380,6 +1384,11 @@
 // SPARCV9:#define __SIZEOF_POINTER__ 8
 // SPARCV9:#define __UINTPTR_TYPE__ long unsigned int
 //
+// Check that clang defines __NO_INLINE__ unconditionally (even at -O) to
+// work around Issue #47994.
+// RUN: %clang_cc1 -E -dM -triple=sparc64-unknown-linux-gnu -O < /dev/null | FileCheck -match-full-lines 

[PATCH] D86049: RFC: Implement optional exportable wrapper function generation for objc_direct methods.

2022-09-10 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi updated this revision to Diff 459268.
plotfi added a comment.

Adding a test case to cover @protocol methods not being allowed to contain 
direct


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86049

Files:
  clang/include/clang/AST/DeclObjC.h
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/lib/AST/DeclObjC.cpp
  clang/lib/AST/Mangle.cpp
  clang/lib/CodeGen/CGObjC.cpp
  clang/lib/CodeGen/CGObjCRuntime.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/CodeGenObjC/objc-direct-wrapper.m

Index: clang/test/CodeGenObjC/objc-direct-wrapper.m
===
--- /dev/null
+++ clang/test/CodeGenObjC/objc-direct-wrapper.m
@@ -0,0 +1,63 @@
+// RUN: %clang -fobjc-arc -Wno-objc-root-class -ObjC -fobjc-runtime=ios -FFoundation \
+// RUN: -DENABLE_VISIBLE_OBJC_DIRECT=1 \
+// RUN: -target x86_64-apple-macosx10.15.0 -c -o - %s | \
+// RUN: llvm-nm - | FileCheck -check-prefix=CHECK-WRAPPER %s
+
+// RUN: %clang -fobjc-arc -Wno-objc-root-class \
+// RUN: -target x86_64-apple-macosx10.15.0 \
+// RUN: -ObjC -fobjc-runtime=ios -FFoundation -c -o - %s | llvm-nm - | \
+// RUN: FileCheck -check-prefix=CHECK-DEFAULT %s
+
+// RUN: %clang -fobjc-arc -Wno-objc-root-class \
+// RUN: -DENABLE_VISIBLE_OBJC_DIRECT=1 \
+// RUN: -target x86_64-apple-macosx10.15.0 \
+// RUN: -ObjC -fobjc-runtime=ios -FFoundation -c -o - %s -S -emit-llvm | \
+// RUN: FileCheck -check-prefix=CHECK-WRAPPER-IR-DEFINE %s
+
+// RUN: %clang -fobjc-arc -Wno-objc-root-class -DNO_OBJC_IMPL \
+// RUN: -DENABLE_VISIBLE_OBJC_DIRECT=1 \
+// RUN: -target x86_64-apple-macosx10.15.0 \
+// RUN: -ObjC -fobjc-runtime=ios -FFoundation -c -o - %s -S -emit-llvm | \
+// RUN: FileCheck -check-prefix=CHECK-WRAPPER-IR-DECLARE %s
+
+// RUN: not %clang -fobjc-arc -Wno-objc-root-class -DENABLE_PROTOCOL_DIRECT_FAIL \
+// RUN: -DENABLE_VISIBLE_OBJC_DIRECT=1 \
+// RUN: -target x86_64-apple-macosx10.15.0 \
+// RUN: -ObjC -fobjc-runtime=ios -FFoundation -c -o - %s -S -emit-llvm 2>&1 | \
+// RUN: FileCheck -check-prefix=CHECK-PROTOCOL-DIRECT-FAIL %s
+
+// CHECK-WRAPPER: T _-
+ // TODO: Fix this
+// CHECK-DEFAULT: t -[C testMethod:bar:]
+// CHECK-WRAPPER-IR-DEFINE: define {{(dso_local )?}}void @"-"
+// CHECK-WRAPPER-IR-DECLARE: declare {{(dso_local )?}}void @"-"
+// CHECK-PROTOCOL-DIRECT-FAIL: error: 'objc_direct' attribute cannot be applied to methods declared in an Objective-C protocol
+
+#if ENABLE_VISIBLE_OBJC_DIRECT
+#define OBJC_DIRECT __attribute__((objc_direct_visible))
+#else
+#define OBJC_DIRECT
+#endif
+
+@interface C
+- (void)testMethod:(int)arg1 bar:(float)arg2 OBJC_DIRECT;
+@end
+
+#ifndef NO_OBJC_IMPL
+@implementation C
+- (void)testMethod:(int)arg1 bar:(float)arg2 OBJC_DIRECT {
+}
+@end
+#endif
+
+#ifdef ENABLE_PROTOCOL_DIRECT_FAIL
+@protocol ProtoDirectVisibleFail
+- (void)protoMethod OBJC_DIRECT;  // expected-error {{'objc_direct' attribute cannot be applied to methods declared in an Objective-C protocol}}
+@end
+#endif
+
+C *c;
+
+void f() {
+  [c testMethod:1 bar:1.0];
+}
Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -2943,6 +2943,22 @@
   }
 }
 
+static void handleObjCDirectVisibleAttr(Sema , Decl *D, const ParsedAttr ) {
+  // objc_direct cannot be set on methods declared in the context of a protocol
+  if (isa(D->getDeclContext())) {
+S.Diag(AL.getLoc(), diag::err_objc_direct_on_protocol) << false;
+return;
+  }
+
+  if (S.getLangOpts().ObjCRuntime.allowsDirectDispatch()) {
+if (!D->hasAttr())
+  handleSimpleAttribute(S, D, AL);
+handleSimpleAttribute(S, D, AL);
+  } else {
+S.Diag(AL.getLoc(), diag::warn_objc_direct_ignored) << AL;
+  }
+}
+
 static void handleObjCMethodFamilyAttr(Sema , Decl *D, const ParsedAttr ) {
   const auto *M = cast(D);
   if (!AL.isArgIdent(0)) {
@@ -8783,6 +8799,9 @@
   case ParsedAttr::AT_ObjCDirect:
 handleObjCDirectAttr(S, D, AL);
 break;
+  case ParsedAttr::AT_ObjCDirectVisible:
+handleObjCDirectVisibleAttr(S, D, AL);
+break;
   case ParsedAttr::AT_ObjCDirectMembers:
 handleObjCDirectMembersAttr(S, D, AL);
 handleSimpleAttribute(S, D, AL);
Index: clang/lib/CodeGen/CGObjCRuntime.cpp
===
--- clang/lib/CodeGen/CGObjCRuntime.cpp
+++ clang/lib/CodeGen/CGObjCRuntime.cpp
@@ -474,7 +474,7 @@
   std::string buffer;
   llvm::raw_string_ostream out(buffer);
   CGM.getCXXABI().getMangleContext().mangleObjCMethodName(OMD, out,
-   /*includePrefixByte=*/true,
+   /*includePrefixByte=*/!OMD->isDirectMethodVisible(),
includeCategoryName);
   return buffer;
 }
Index: clang/lib/CodeGen/CGObjC.cpp

[clang] 1e56821 - [Linux] Hack around Linux/sparc

2022-09-10 Thread Rainer Orth via cfe-commits

Author: Rainer Orth
Date: 2022-09-10T09:37:35+02:00
New Revision: 1e56821bac02a5d3c6249bbf3ef43b8b569d2551

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

LOG: [Linux] Hack around Linux/sparc 

I've been using this hack to work around the Linux/sparc64 compile failure
described in Issue #47994
, especially since the
underlying glibc PR build/27558
 doesn't seem to be
making progress and some fix is required to have LLVM build on
`sparc64-unknown-linux-gnu` at all, as evidenced on the buildbot.

Tested on `sparc64-unknown-linux-gnu`.

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

Added: 


Modified: 
clang/lib/Basic/Targets/OSTargets.h
clang/test/Preprocessor/init.c

Removed: 




diff  --git a/clang/lib/Basic/Targets/OSTargets.h 
b/clang/lib/Basic/Targets/OSTargets.h
index 54e66b5bd9e1f..c75f7d9fbafeb 100644
--- a/clang/lib/Basic/Targets/OSTargets.h
+++ b/clang/lib/Basic/Targets/OSTargets.h
@@ -388,6 +388,9 @@ class LLVM_LIBRARY_VISIBILITY LinuxTargetInfo : public 
OSTargetInfo {
 } else {
 Builder.defineMacro("__gnu_linux__");
 }
+// Work around Issue #47994 until glibc PR build/27558 is fixed.
+if (Triple.isSPARC())
+  Builder.defineMacro("__NO_INLINE__");
 if (Opts.POSIXThreads)
   Builder.defineMacro("_REENTRANT");
 if (Opts.CPlusPlus)

diff  --git a/clang/test/Preprocessor/init.c b/clang/test/Preprocessor/init.c
index e3a24824ff190..028f3448f8bda 100644
--- a/clang/test/Preprocessor/init.c
+++ b/clang/test/Preprocessor/init.c
@@ -874,6 +874,9 @@
 
 // RUN: %clang_cc1 -E -dM -ffreestanding -fgnuc-version=4.2.1 
-triple=sparc-none-none < /dev/null | FileCheck -match-full-lines -check-prefix 
SPARC -check-prefix SPARC-DEFAULT %s
 // RUN: %clang_cc1 -E -dM -ffreestanding -fgnuc-version=4.2.1 
-triple=sparc-rtems-elf < /dev/null | FileCheck -match-full-lines -check-prefix 
SPARC -check-prefix SPARC-DEFAULT %s
+// Check that clang defines __NO_INLINE__ unconditionally (even at -O) to
+// work around Issue #47994.
+// RUN: %clang_cc1 -E -dM -triple=sparc-unknown-linux-gnu -O < /dev/null | 
FileCheck -match-full-lines -check-prefix SPARC-LINUX %s
 // RUN: %clang_cc1 -E -dM -ffreestanding -fgnuc-version=4.2.1 
-triple=sparc-none-netbsd < /dev/null | FileCheck -match-full-lines 
-check-prefix SPARC -check-prefix SPARC-NETOPENBSD %s
 // RUN: %clang_cc1 -x c++ -E -dM -ffreestanding -fgnuc-version=4.2.1 
-triple=sparc-none-none < /dev/null | FileCheck -match-full-lines -check-prefix 
SPARC -check-prefix SPARC-DEFAULT -check-prefix SPARC-DEFAULT-CXX %s
 //
@@ -997,6 +1000,7 @@
 // SPARC:#define __LONG_LONG_MAX__ 9223372036854775807LL
 // SPARC:#define __LONG_MAX__ 2147483647L
 // SPARC-NOT:#define __LP64__
+// SPARC-LINUX:#define __NO_INLINE__ 1
 // SPARC:#define __POINTER_WIDTH__ 32
 // SPARC-DEFAULT:#define __PTRDIFF_TYPE__ int
 // SPARC-NETOPENBSD:#define __PTRDIFF_TYPE__ long int
@@ -1380,6 +1384,11 @@
 // SPARCV9:#define __SIZEOF_POINTER__ 8
 // SPARCV9:#define __UINTPTR_TYPE__ long unsigned int
 //
+// Check that clang defines __NO_INLINE__ unconditionally (even at -O) to
+// work around Issue #47994.
+// RUN: %clang_cc1 -E -dM -triple=sparc64-unknown-linux-gnu -O < /dev/null | 
FileCheck -match-full-lines -check-prefix SPARC64-LINUX %s
+// SPARC64-LINUX:#define __NO_INLINE__ 1
+//
 // RUN: %clang_cc1 -E -dM -ffreestanding -triple=sparc64-none-openbsd < 
/dev/null | FileCheck -match-full-lines -check-prefix SPARC64-OBSD %s
 // SPARC64-OBSD:#define __INT64_TYPE__ long long int
 // SPARC64-OBSD:#define __INTMAX_C_SUFFIX__ LL



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


[PATCH] D86049: RFC: Implement optional exportable wrapper function generation for objc_direct methods.

2022-09-10 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi updated this revision to Diff 459267.
plotfi added a comment.

Update test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86049

Files:
  clang/include/clang/AST/DeclObjC.h
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/lib/AST/DeclObjC.cpp
  clang/lib/AST/Mangle.cpp
  clang/lib/CodeGen/CGObjC.cpp
  clang/lib/CodeGen/CGObjCRuntime.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/CodeGenObjC/objc-direct-wrapper.m

Index: clang/test/CodeGenObjC/objc-direct-wrapper.m
===
--- /dev/null
+++ clang/test/CodeGenObjC/objc-direct-wrapper.m
@@ -0,0 +1,50 @@
+// RUN: %clang -fobjc-arc -Wno-objc-root-class -ObjC -fobjc-runtime=ios -FFoundation \
+// RUN: -DENABLE_VISIBLE_OBJC_DIRECT=1 \
+// RUN: -target x86_64-apple-macosx10.15.0 -c -o - %s | \
+// RUN: llvm-nm - | FileCheck -check-prefix=CHECK-WRAPPER %s
+
+// RUN: %clang -fobjc-arc -Wno-objc-root-class \
+// RUN: -target x86_64-apple-macosx10.15.0 \
+// RUN: -ObjC -fobjc-runtime=ios -FFoundation -c -o - %s | llvm-nm - | \
+// RUN: FileCheck -check-prefix=CHECK-DEFAULT %s
+
+// RUN: %clang -fobjc-arc -Wno-objc-root-class \
+// RUN: -DENABLE_VISIBLE_OBJC_DIRECT=1 \
+// RUN: -target x86_64-apple-macosx10.15.0 \
+// RUN: -ObjC -fobjc-runtime=ios -FFoundation -c -o - %s -S -emit-llvm | \
+// RUN: FileCheck -check-prefix=CHECK-WRAPPER-IR-DEFINE %s
+
+// RUN: %clang -fobjc-arc -Wno-objc-root-class -DNO_OBJC_IMPL \
+// RUN: -DENABLE_VISIBLE_OBJC_DIRECT=1 \
+// RUN: -target x86_64-apple-macosx10.15.0 \
+// RUN: -ObjC -fobjc-runtime=ios -FFoundation -c -o - %s -S -emit-llvm | \
+// RUN: FileCheck -check-prefix=CHECK-WRAPPER-IR-DECLARE %s
+
+// CHECK-WRAPPER: T _-
+ // TODO: Fix this
+// CHECK-DEFAULT: t -[C testMethod:bar:]
+// CHECK-WRAPPER-IR-DEFINE: define {{(dso_local )?}}void @"-"
+// CHECK-WRAPPER-IR-DECLARE: declare {{(dso_local )?}}void @"-"
+
+#if ENABLE_VISIBLE_OBJC_DIRECT
+#define OBJC_DIRECT __attribute__((objc_direct_visible))
+#else
+#define OBJC_DIRECT
+#endif
+
+@interface C
+- (void)testMethod:(int)arg1 bar:(float)arg2 OBJC_DIRECT;
+@end
+
+#ifndef NO_OBJC_IMPL
+@implementation C
+- (void)testMethod:(int)arg1 bar:(float)arg2 OBJC_DIRECT {
+}
+@end
+#endif
+
+C *c;
+
+void f() {
+  [c testMethod:1 bar:1.0];
+}
Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -2943,6 +2943,22 @@
   }
 }
 
+static void handleObjCDirectVisibleAttr(Sema , Decl *D, const ParsedAttr ) {
+  // objc_direct cannot be set on methods declared in the context of a protocol
+  if (isa(D->getDeclContext())) {
+S.Diag(AL.getLoc(), diag::err_objc_direct_on_protocol) << false;
+return;
+  }
+
+  if (S.getLangOpts().ObjCRuntime.allowsDirectDispatch()) {
+if (!D->hasAttr())
+  handleSimpleAttribute(S, D, AL);
+handleSimpleAttribute(S, D, AL);
+  } else {
+S.Diag(AL.getLoc(), diag::warn_objc_direct_ignored) << AL;
+  }
+}
+
 static void handleObjCMethodFamilyAttr(Sema , Decl *D, const ParsedAttr ) {
   const auto *M = cast(D);
   if (!AL.isArgIdent(0)) {
@@ -8783,6 +8799,9 @@
   case ParsedAttr::AT_ObjCDirect:
 handleObjCDirectAttr(S, D, AL);
 break;
+  case ParsedAttr::AT_ObjCDirectVisible:
+handleObjCDirectVisibleAttr(S, D, AL);
+break;
   case ParsedAttr::AT_ObjCDirectMembers:
 handleObjCDirectMembersAttr(S, D, AL);
 handleSimpleAttribute(S, D, AL);
Index: clang/lib/CodeGen/CGObjCRuntime.cpp
===
--- clang/lib/CodeGen/CGObjCRuntime.cpp
+++ clang/lib/CodeGen/CGObjCRuntime.cpp
@@ -474,7 +474,7 @@
   std::string buffer;
   llvm::raw_string_ostream out(buffer);
   CGM.getCXXABI().getMangleContext().mangleObjCMethodName(OMD, out,
-   /*includePrefixByte=*/true,
+   /*includePrefixByte=*/!OMD->isDirectMethodVisible(),
includeCategoryName);
   return buffer;
 }
Index: clang/lib/CodeGen/CGObjC.cpp
===
--- clang/lib/CodeGen/CGObjC.cpp
+++ clang/lib/CodeGen/CGObjC.cpp
@@ -760,7 +760,9 @@
 
   const CGFunctionInfo  = CGM.getTypes().arrangeObjCMethodDeclaration(OMD);
   if (OMD->isDirectMethod()) {
-Fn->setVisibility(llvm::Function::HiddenVisibility);
+Fn->setVisibility(OMD->isDirectMethodVisible()
+  ? llvm::Function::DefaultVisibility
+  : llvm::Function::HiddenVisibility);
 CGM.SetLLVMFunctionAttributes(OMD, FI, Fn, /*IsThunk=*/false);
 CGM.SetLLVMFunctionAttributesForDefinition(OMD, Fn);
   } else {
Index: clang/lib/AST/Mangle.cpp
===
--- clang/lib/AST/Mangle.cpp

[PATCH] D86049: RFC: Implement optional exportable wrapper function generation for objc_direct methods.

2022-09-10 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi added inline comments.



Comment at: clang/test/CodeGenObjC/objc-direct-wrapper.m:30
+#if ENABLE_VISIBLE_OBJC_DIRECT
+#define OBJC_DIRECT __attribute((objc_direct)) 
__attribute__((objc_direct_visible))
+#else

dmaclach wrote:
> This is the case that mwyman described above where we would prefer to only 
> have the single attribute correct?
Ah, sorry about that. I implemented the code to have one single attr but I 
accidentally copy pasted both attrs in the test. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86049

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


[PATCH] D133635: [clang-format] Don't insert braces for loops with a null statement

2022-09-10 Thread Owen Pan via Phabricator via cfe-commits
owenpan created this revision.
owenpan added reviewers: MyDeveloperDay, curdeius, HazardyKnusperkeks.
owenpan added a project: clang-format.
Herald added a project: All.
owenpan requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This is a workaround for https://github.com/llvm/llvm-project/issues/57539.

Fixes https://github.com/llvm/llvm-project/issues/57509.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D133635

Files:
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/unittests/Format/FormatTest.cpp


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -25327,6 +25327,30 @@
"}",
Style);
 
+  verifyFormat("do {\n"
+   "#if 0\n"
+   " if (a) {\n"
+   "#else\n"
+   "  if (b) {\n"
+   "#endif\n"
+   "}\n"
+   "}\n"
+   "while (0)\n"
+   "  ;",
+   Style);
+  // TODO: Replace the test above with the one below after #57539 is fixed.
+#if 0
+  verifyFormat("do {\n"
+   "#if 0\n"
+   "  if (a) {\n"
+   "#else\n"
+   "  if (b) {\n"
+   "#endif\n"
+   "  }\n"
+   "} while (0);",
+   Style);
+#endif
+
   Style.ColumnLimit = 15;
 
   verifyFormat("#define A \\\n"
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -2605,8 +2605,7 @@
   FormatToken *Tok = nullptr;
 
   if (Style.InsertBraces && !Line->InPPDirective && !Line->Tokens.empty() &&
-  PreprocessorDirectives.empty()) {
-assert(!Line->Tokens.empty());
+  PreprocessorDirectives.empty() && FormatTok->isNot(tok::semi)) {
 Tok = Style.BraceWrapping.AfterControlStatement == FormatStyle::BWACS_Never
   ? getLastNonComment(*Line)
   : Line->Tokens.back().Tok;


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -25327,6 +25327,30 @@
"}",
Style);
 
+  verifyFormat("do {\n"
+   "#if 0\n"
+   " if (a) {\n"
+   "#else\n"
+   "  if (b) {\n"
+   "#endif\n"
+   "}\n"
+   "}\n"
+   "while (0)\n"
+   "  ;",
+   Style);
+  // TODO: Replace the test above with the one below after #57539 is fixed.
+#if 0
+  verifyFormat("do {\n"
+   "#if 0\n"
+   "  if (a) {\n"
+   "#else\n"
+   "  if (b) {\n"
+   "#endif\n"
+   "  }\n"
+   "} while (0);",
+   Style);
+#endif
+
   Style.ColumnLimit = 15;
 
   verifyFormat("#define A \\\n"
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -2605,8 +2605,7 @@
   FormatToken *Tok = nullptr;
 
   if (Style.InsertBraces && !Line->InPPDirective && !Line->Tokens.empty() &&
-  PreprocessorDirectives.empty()) {
-assert(!Line->Tokens.empty());
+  PreprocessorDirectives.empty() && FormatTok->isNot(tok::semi)) {
 Tok = Style.BraceWrapping.AfterControlStatement == FormatStyle::BWACS_Never
   ? getLastNonComment(*Line)
   : Line->Tokens.back().Tok;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D86049: RFC: Implement optional exportable wrapper function generation for objc_direct methods.

2022-09-10 Thread Dave MacLachlan via Phabricator via cfe-commits
dmaclach added a comment.

Thanks Puyan! Awesome to see this moving forward.




Comment at: clang/test/CodeGenObjC/objc-direct-wrapper.m:30
+#if ENABLE_VISIBLE_OBJC_DIRECT
+#define OBJC_DIRECT __attribute((objc_direct)) 
__attribute__((objc_direct_visible))
+#else

This is the case that mwyman described above where we would prefer to only have 
the single attribute correct?



Comment at: clang/test/CodeGenObjC/objc-direct-wrapper.m:35
+
+@interface C
+- (void)testMethod:(int)arg1 bar:(float)arg2 OBJC_DIRECT;

I'd like to see a test for the protocol case for coverage.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86049

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


[PATCH] D133589: [clang-format] JSON formatting add new option for controlling newlines in json arrays

2022-09-10 Thread Owen Pan via Phabricator via cfe-commits
owenpan added inline comments.



Comment at: clang/lib/Format/TokenAnnotator.cpp:4405-4408
 if (Left.is(TT_ArrayInitializerLSquare) && Left.is(tok::l_square) &&
 !Right.is(tok::r_square)) {
-  return true;
+  if (Right.is(tok::l_brace))
+return true;

Merge the check for `comma` below to avoid repeated code. Also, the check for 
`l_brace` is redundant.



Comment at: clang/lib/Format/TokenAnnotator.cpp:4411-4420
+  const auto *Tok = 
+  while (Tok) {
+if (Tok->isOneOf(tok::l_brace, tok::l_square)) {
+  return true;
+}
+if (Tok->isOneOf(tok::r_brace, tok::r_square)) {
+  break;

Use a `for` loop instead.



Comment at: clang/lib/Format/TokenAnnotator.cpp:4426-
+if (Left.is(tok::comma)) {
+  if (Right.is(tok::l_brace)) {
+return true;
+  }
+  // scan to the right if an we see an object or an array inside
+  // then break
+  const auto *Tok = 

This can be deleted now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133589

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


[PATCH] D133571: [clang-format] Introduce NoFallThrough option into AllowShortCaseLabelsOnASingleLine

2022-09-10 Thread Owen Pan via Phabricator via cfe-commits
owenpan added inline comments.



Comment at: clang/lib/Format/UnwrappedLineFormatter.cpp:567
   return Style.AllowShortCaseLabelsOnASingleLine
- ? tryMergeShortCaseLabels(I, E, Limit)
+ ? tryMergeShortCaseLabels(I, E, Limit, PreviousLine, Style)
  : 0;

See below.



Comment at: clang/lib/Format/UnwrappedLineFormatter.cpp:635-636
   SmallVectorImpl::const_iterator E,
-  unsigned Limit) {
+  unsigned Limit, const AnnotatedLine *PreviousLine,
+  const FormatStyle ) {
 if (Limit == 0 || I + 1 == E ||

We don't need to add `Style`.



Comment at: clang/lib/Format/UnwrappedLineFormatter.cpp:643-644
   return 0;
+bool NoFallThrough = Style.AllowShortCaseLabelsOnASingleLine ==
+ FormatStyle::SCLS_NoFallThrough;
+// Don't merge if the last thing on the line before was just `case X:`.

Nit.



Comment at: clang/lib/Format/UnwrappedLineFormatter.cpp:646
+// Don't merge if the last thing on the line before was just `case X:`.
+if (NoFallThrough && PreviousLine && PreviousLine->Last) {
+  if (PreviousLine->Last->is(tok::colon))

`Last` should never be null.



Comment at: clang/lib/Format/UnwrappedLineFormatter.cpp:650-653
+  if (PreviousLine->Last->Previous && PreviousLine->Last->Previous) {
+auto *PrevPrev = PreviousLine->Last->Previous->Previous;
+if (PrevPrev && PrevPrev->startsSequence(TT_AttributeSquare,
+ TT_AttributeSquare, 
tok::semi))

curdeius wrote:
> Haven't seen this before.
Use `endsSequence` instead.


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

https://reviews.llvm.org/D133571

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


[PATCH] D86049: RFC: Implement optional exportable wrapper function generation for objc_direct methods.

2022-09-10 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi updated this revision to Diff 459261.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86049

Files:
  clang/include/clang/AST/DeclObjC.h
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/lib/AST/DeclObjC.cpp
  clang/lib/AST/Mangle.cpp
  clang/lib/CodeGen/CGObjC.cpp
  clang/lib/CodeGen/CGObjCRuntime.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/CodeGenObjC/objc-direct-wrapper.m

Index: clang/test/CodeGenObjC/objc-direct-wrapper.m
===
--- /dev/null
+++ clang/test/CodeGenObjC/objc-direct-wrapper.m
@@ -0,0 +1,50 @@
+// RUN: %clang -fobjc-arc -Wno-objc-root-class -ObjC -fobjc-runtime=ios -FFoundation \
+// RUN: -DENABLE_VISIBLE_OBJC_DIRECT=1 \
+// RUN: -target x86_64-apple-macosx10.15.0 -c -o - %s | \
+// RUN: llvm-nm - | FileCheck -check-prefix=CHECK-WRAPPER %s
+
+// RUN: %clang -fobjc-arc -Wno-objc-root-class \
+// RUN: -target x86_64-apple-macosx10.15.0 \
+// RUN: -ObjC -fobjc-runtime=ios -FFoundation -c -o - %s | llvm-nm - | \
+// RUN: FileCheck -check-prefix=CHECK-DEFAULT %s
+
+// RUN: %clang -fobjc-arc -Wno-objc-root-class \
+// RUN: -DENABLE_VISIBLE_OBJC_DIRECT=1 \
+// RUN: -target x86_64-apple-macosx10.15.0 \
+// RUN: -ObjC -fobjc-runtime=ios -FFoundation -c -o - %s -S -emit-llvm | \
+// RUN: FileCheck -check-prefix=CHECK-WRAPPER-IR-DEFINE %s
+
+// RUN: %clang -fobjc-arc -Wno-objc-root-class -DNO_OBJC_IMPL \
+// RUN: -DENABLE_VISIBLE_OBJC_DIRECT=1 \
+// RUN: -target x86_64-apple-macosx10.15.0 \
+// RUN: -ObjC -fobjc-runtime=ios -FFoundation -c -o - %s -S -emit-llvm | \
+// RUN: FileCheck -check-prefix=CHECK-WRAPPER-IR-DECLARE %s
+
+// CHECK-WRAPPER: T _-
+ // TODO: Fix this
+// CHECK-DEFAULT: t -[C testMethod:bar:]
+// CHECK-WRAPPER-IR-DEFINE: define {{(dso_local )?}}void @"-"
+// CHECK-WRAPPER-IR-DECLARE: declare {{(dso_local )?}}void @"-"
+
+#if ENABLE_VISIBLE_OBJC_DIRECT
+#define OBJC_DIRECT __attribute((objc_direct)) __attribute__((objc_direct_visible))
+#else
+#define OBJC_DIRECT
+#endif
+
+@interface C
+- (void)testMethod:(int)arg1 bar:(float)arg2 OBJC_DIRECT;
+@end
+
+#ifndef NO_OBJC_IMPL
+@implementation C
+- (void)testMethod:(int)arg1 bar:(float)arg2 OBJC_DIRECT {
+}
+@end
+#endif
+
+C *c;
+
+void f() {
+  [c testMethod:1 bar:1.0];
+}
Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -2943,6 +2943,22 @@
   }
 }
 
+static void handleObjCDirectVisibleAttr(Sema , Decl *D, const ParsedAttr ) {
+  // objc_direct cannot be set on methods declared in the context of a protocol
+  if (isa(D->getDeclContext())) {
+S.Diag(AL.getLoc(), diag::err_objc_direct_on_protocol) << false;
+return;
+  }
+
+  if (S.getLangOpts().ObjCRuntime.allowsDirectDispatch()) {
+if (!D->hasAttr())
+  handleSimpleAttribute(S, D, AL);
+handleSimpleAttribute(S, D, AL);
+  } else {
+S.Diag(AL.getLoc(), diag::warn_objc_direct_ignored) << AL;
+  }
+}
+
 static void handleObjCMethodFamilyAttr(Sema , Decl *D, const ParsedAttr ) {
   const auto *M = cast(D);
   if (!AL.isArgIdent(0)) {
@@ -8783,6 +8799,9 @@
   case ParsedAttr::AT_ObjCDirect:
 handleObjCDirectAttr(S, D, AL);
 break;
+  case ParsedAttr::AT_ObjCDirectVisible:
+handleObjCDirectVisibleAttr(S, D, AL);
+break;
   case ParsedAttr::AT_ObjCDirectMembers:
 handleObjCDirectMembersAttr(S, D, AL);
 handleSimpleAttribute(S, D, AL);
Index: clang/lib/CodeGen/CGObjCRuntime.cpp
===
--- clang/lib/CodeGen/CGObjCRuntime.cpp
+++ clang/lib/CodeGen/CGObjCRuntime.cpp
@@ -474,7 +474,7 @@
   std::string buffer;
   llvm::raw_string_ostream out(buffer);
   CGM.getCXXABI().getMangleContext().mangleObjCMethodName(OMD, out,
-   /*includePrefixByte=*/true,
+   /*includePrefixByte=*/!OMD->isDirectMethodVisible(),
includeCategoryName);
   return buffer;
 }
Index: clang/lib/CodeGen/CGObjC.cpp
===
--- clang/lib/CodeGen/CGObjC.cpp
+++ clang/lib/CodeGen/CGObjC.cpp
@@ -760,7 +760,9 @@
 
   const CGFunctionInfo  = CGM.getTypes().arrangeObjCMethodDeclaration(OMD);
   if (OMD->isDirectMethod()) {
-Fn->setVisibility(llvm::Function::HiddenVisibility);
+Fn->setVisibility(OMD->isDirectMethodVisible()
+  ? llvm::Function::DefaultVisibility
+  : llvm::Function::HiddenVisibility);
 CGM.SetLLVMFunctionAttributes(OMD, FI, Fn, /*IsThunk=*/false);
 CGM.SetLLVMFunctionAttributesForDefinition(OMD, Fn);
   } else {
Index: clang/lib/AST/Mangle.cpp
===
--- clang/lib/AST/Mangle.cpp
+++ 

[PATCH] D86049: RFC: Implement optional exportable wrapper function generation for objc_direct methods.

2022-09-10 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi marked an inline comment as done.
plotfi added inline comments.



Comment at: clang/include/clang/Basic/Attr.td:2251-2256
+def ObjCDirectVisible : Attr {
+  let Spellings = [Clang<"objc_direct_visible">];
+  let Subjects = SubjectList<[ObjCMethod], ErrorDiag>;
+  let LangOpts = [ObjC];
+  let Documentation = [ObjCDirectVisibleDocs];
+}

plotfi wrote:
> mwyman wrote:
> > Should this inherit `ObjCDirect`, to include both objc_direct and the 
> > visibility aspect? I don't see any reason we would want to add 
> > `objc_direct_visible` without also having `objc_direct`, so why make 
> > developers add both?
> > 
> > As an alternative, would it make sense to allow adding 
> > `__attribute__((visibility("default")))` on direct methods?
> > 
> > Also, it doesn't seem like this allows making `@property`s visible, so 
> > should there be a similar attribute for properties?
> I'd prefer to do `@property`s in a separate commit, but I suppose you are 
> thinking like a `objc_direct_members_visible` attribute? I think I can add 
> that in a subsequent commit. 
> 
> I took a look at how to make things inherit and I think the most 
> straightforward way is to have `handleObjCDirectVisibleAttr` set the 
> objc_direct attribute if it is not set already.
> 
> As for `__attribute__((visibility("default")))` I think the trouble lies in 
> what we want the default visibility behavior for objc methods to be and if we 
> want the behavior to be controlled by `-fvisibility=`. I tried going by 
> attribute visibility before and had some trouble too (I forget exactly what 
> though). 
> 
> 
I gave visibility a try and it seems that the trouble is everything is visible 
by default where for objc methods we want them hidden by default. I think I 
would rather add a separate attr for this than add an additional non-conformant 
visibility mode. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86049

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


[PATCH] D86049: RFC: Implement optional exportable wrapper function generation for objc_direct methods.

2022-09-10 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi updated this revision to Diff 459260.
plotfi added a comment.

Updated to use mangleObjCMethodName in clang/lib/AST/Mangle.cpp to set the 
`_+` direct method name.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86049

Files:
  clang/include/clang/AST/DeclObjC.h
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/lib/AST/DeclObjC.cpp
  clang/lib/AST/Mangle.cpp
  clang/lib/CodeGen/CGObjC.cpp
  clang/lib/CodeGen/CGObjCRuntime.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/CodeGenObjC/objc-direct-wrapper.m

Index: clang/test/CodeGenObjC/objc-direct-wrapper.m
===
--- /dev/null
+++ clang/test/CodeGenObjC/objc-direct-wrapper.m
@@ -0,0 +1,50 @@
+// RUN: %clang -fobjc-arc -Wno-objc-root-class -ObjC -fobjc-runtime=ios -FFoundation \
+// RUN: -DENABLE_VISIBLE_OBJC_DIRECT=1 \
+// RUN: -target x86_64-apple-macosx10.15.0 -c -o - %s | \
+// RUN: llvm-nm - | FileCheck -check-prefix=CHECK-WRAPPER %s
+
+// RUN: %clang -fobjc-arc -Wno-objc-root-class \
+// RUN: -target x86_64-apple-macosx10.15.0 \
+// RUN: -ObjC -fobjc-runtime=ios -FFoundation -c -o - %s | llvm-nm - | \
+// RUN: FileCheck -check-prefix=CHECK-DEFAULT %s
+
+// RUN: %clang -fobjc-arc -Wno-objc-root-class \
+// RUN: -DENABLE_VISIBLE_OBJC_DIRECT=1 \
+// RUN: -target x86_64-apple-macosx10.15.0 \
+// RUN: -ObjC -fobjc-runtime=ios -FFoundation -c -o - %s -S -emit-llvm | \
+// RUN: FileCheck -check-prefix=CHECK-WRAPPER-IR-DEFINE %s
+
+// RUN: %clang -fobjc-arc -Wno-objc-root-class -DNO_OBJC_IMPL \
+// RUN: -DENABLE_VISIBLE_OBJC_DIRECT=1 \
+// RUN: -target x86_64-apple-macosx10.15.0 \
+// RUN: -ObjC -fobjc-runtime=ios -FFoundation -c -o - %s -S -emit-llvm | \
+// RUN: FileCheck -check-prefix=CHECK-WRAPPER-IR-DECLARE %s
+
+// CHECK-WRAPPER: T _-
+ // TODO: Fix this
+// CHECK-DEFAULT: t -[C testMethod:bar:]
+// CHECK-WRAPPER-IR-DEFINE: define {{(dso_local )?}}void @"-"
+// CHECK-WRAPPER-IR-DECLARE: declare {{(dso_local )?}}void @"-"
+
+#if ENABLE_VISIBLE_OBJC_DIRECT
+#define OBJC_DIRECT __attribute((objc_direct)) __attribute__((objc_direct_visible))
+#else
+#define OBJC_DIRECT
+#endif
+
+@interface C
+- (void)testMethod:(int)arg1 bar:(float)arg2 OBJC_DIRECT __attribute__((visibility("default"))) ;
+@end
+
+#ifndef NO_OBJC_IMPL
+@implementation C
+- (void)testMethod:(int)arg1 bar:(float)arg2 OBJC_DIRECT {
+}
+@end
+#endif
+
+C *c;
+
+__attribute__((visibility("hidden"))) void f() {
+  [c testMethod:1 bar:1.0];
+}
Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -2943,6 +2943,22 @@
   }
 }
 
+static void handleObjCDirectVisibleAttr(Sema , Decl *D, const ParsedAttr ) {
+  // objc_direct cannot be set on methods declared in the context of a protocol
+  if (isa(D->getDeclContext())) {
+S.Diag(AL.getLoc(), diag::err_objc_direct_on_protocol) << false;
+return;
+  }
+
+  if (S.getLangOpts().ObjCRuntime.allowsDirectDispatch()) {
+if (!D->hasAttr())
+  handleSimpleAttribute(S, D, AL);
+handleSimpleAttribute(S, D, AL);
+  } else {
+S.Diag(AL.getLoc(), diag::warn_objc_direct_ignored) << AL;
+  }
+}
+
 static void handleObjCMethodFamilyAttr(Sema , Decl *D, const ParsedAttr ) {
   const auto *M = cast(D);
   if (!AL.isArgIdent(0)) {
@@ -8783,6 +8799,9 @@
   case ParsedAttr::AT_ObjCDirect:
 handleObjCDirectAttr(S, D, AL);
 break;
+  case ParsedAttr::AT_ObjCDirectVisible:
+handleObjCDirectVisibleAttr(S, D, AL);
+break;
   case ParsedAttr::AT_ObjCDirectMembers:
 handleObjCDirectMembersAttr(S, D, AL);
 handleSimpleAttribute(S, D, AL);
Index: clang/lib/CodeGen/CGObjCRuntime.cpp
===
--- clang/lib/CodeGen/CGObjCRuntime.cpp
+++ clang/lib/CodeGen/CGObjCRuntime.cpp
@@ -474,7 +474,7 @@
   std::string buffer;
   llvm::raw_string_ostream out(buffer);
   CGM.getCXXABI().getMangleContext().mangleObjCMethodName(OMD, out,
-   /*includePrefixByte=*/true,
+   /*includePrefixByte=*/!OMD->isDirectMethodVisible(),
includeCategoryName);
   return buffer;
 }
Index: clang/lib/CodeGen/CGObjC.cpp
===
--- clang/lib/CodeGen/CGObjC.cpp
+++ clang/lib/CodeGen/CGObjC.cpp
@@ -760,7 +760,9 @@
 
   const CGFunctionInfo  = CGM.getTypes().arrangeObjCMethodDeclaration(OMD);
   if (OMD->isDirectMethod()) {
-Fn->setVisibility(llvm::Function::HiddenVisibility);
+Fn->setVisibility(OMD->isDirectMethodVisible()
+  ? llvm::Function::DefaultVisibility
+  : llvm::Function::HiddenVisibility);
 CGM.SetLLVMFunctionAttributes(OMD, FI, Fn, /*IsThunk=*/false);