[PATCH] D131853: [clangd] Add doxygen parsing for Hover

2022-09-16 Thread Tom Praschan via Phabricator via cfe-commits
tom-anders added a comment.

In D131853#3793831 , @nridge wrote:

> In D131853#3792985 , @logankaser 
> wrote:
>
>> Is there anything I can do as a random member of the public that wants this 
>> and knows C++?
>
> Maybe apply the patch locally, use it for a bit, and provide feedback?

I'm sure that would help!

> I haven't forgotten about this review and I hope to get to it as time permits.

Would it maybe also help to split this patch into 2 or 3 smaller patches?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131853

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


[PATCH] D134018: [clang] [Driver] Add an option to disable default config filenames

2022-09-16 Thread Michał Górny via Phabricator via cfe-commits
mgorny created this revision.
mgorny added reviewers: sepavloff, asymptotically, MaskRay, tstellar.
Herald added a subscriber: StephenFan.
Herald added a project: All.
mgorny requested review of this revision.

Add a `--no-default-config` option that disables the search for default
set of config filenames (based on the compiler executable name).

Suggested in 
https://discourse.llvm.org/t/rfc-adding-a-default-file-location-to-config-file-support/63606.


https://reviews.llvm.org/D134018

Files:
  clang/docs/UsersManual.rst
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/Driver.cpp
  clang/test/Driver/config-file3.c


Index: clang/test/Driver/config-file3.c
===
--- clang/test/Driver/config-file3.c
+++ clang/test/Driver/config-file3.c
@@ -41,6 +41,12 @@
 //
 // CHECK-EXPLICIT: Configuration file: {{.*}}/Inputs/config/i386-qqq.cfg
 //
+//--- --no-default-config disables config search
+//
+// RUN: %t/testdmode/qqq-clang-g++ --config-system-dir= 
--config-user-dir=%t/testdmode --no-default-config -c -### %s 2>&1 | FileCheck 
%s -check-prefix NO-DEFAULT-CONFIG
+//
+// NO-DEFAULT-CONFIG-NOT: Configuration file:
+//
 //--- Invocation qqq-clang-g++ tries to find config file qqq.cfg if 
qqq-clang-g++.cfg is not found.
 //
 // RUN: rm %t/testdmode/qqq-clang-g++.cfg
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -1024,11 +1024,14 @@
 }
   }
 
-  // If config file is not specified explicitly, try to deduce configuration
-  // from executable name. For instance, an executable 'armv7l-clang' will
-  // search for config file 'armv7l-clang.cfg'.
-  if (CfgFileName.empty() && !ClangNameParts.TargetPrefix.empty())
-CfgFileName = ClangNameParts.TargetPrefix + '-' + 
ClangNameParts.ModeSuffix;
+  if (!CLOptions || !CLOptions->hasArg(options::OPT_no_default_config)) {
+// If config file is not specified explicitly, try to deduce configuration
+// from executable name. For instance, an executable 'armv7l-clang' will
+// search for config file 'armv7l-clang.cfg'.
+if (CfgFileName.empty() && !ClangNameParts.TargetPrefix.empty())
+  CfgFileName =
+  ClangNameParts.TargetPrefix + '-' + ClangNameParts.ModeSuffix;
+  }
 
   if (CfgFileName.empty())
 return false;
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -901,6 +901,8 @@
 def compatibility__version : JoinedOrSeparate<["-"], "compatibility_version">;
 def config : Separate<["--"], "config">, Flags<[NoXarchOption]>,
   HelpText<"Specifies configuration file">;
+def no_default_config : Flag<["--"], "no-default-config">, 
Flags<[NoXarchOption]>,
+  HelpText<"Disable loading default configuration files">;
 def config_system_dir_EQ : Joined<["--"], "config-system-dir=">, 
Flags<[NoXarchOption, HelpHidden]>,
   HelpText<"System directory for configuration files">;
 def config_user_dir_EQ : Joined<["--"], "config-user-dir=">, 
Flags<[NoXarchOption, HelpHidden]>,
Index: clang/docs/UsersManual.rst
===
--- clang/docs/UsersManual.rst
+++ clang/docs/UsersManual.rst
@@ -904,6 +904,10 @@
 CLANG_CONFIG_FILE_SYSTEM_DIR respectively. The first file found is used. It is
 an error if the required file cannot be found.
 
+If no explicit configuration file is specified, Clang searches for a default
+configuration file following the rules described in the next paragraphs.
+To disable this behavior, `--no-default-config` flag can be used.
+
 Another way to specify a configuration file is to encode it in executable name.
 For example, if the Clang executable is named `armv7l-clang` (it may be a
 symbolic link to `clang`), then Clang will search for file `armv7l.cfg` in the


Index: clang/test/Driver/config-file3.c
===
--- clang/test/Driver/config-file3.c
+++ clang/test/Driver/config-file3.c
@@ -41,6 +41,12 @@
 //
 // CHECK-EXPLICIT: Configuration file: {{.*}}/Inputs/config/i386-qqq.cfg
 //
+//--- --no-default-config disables config search
+//
+// RUN: %t/testdmode/qqq-clang-g++ --config-system-dir= --config-user-dir=%t/testdmode --no-default-config -c -### %s 2>&1 | FileCheck %s -check-prefix NO-DEFAULT-CONFIG
+//
+// NO-DEFAULT-CONFIG-NOT: Configuration file:
+//
 //--- Invocation qqq-clang-g++ tries to find config file qqq.cfg if qqq-clang-g++.cfg is not found.
 //
 // RUN: rm %t/testdmode/qqq-clang-g++.cfg
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -1024,11 +1024,14 @@
 }
   }
 
-  // If config file is not specified explicitly, try to deduce configuration
-  // f

[PATCH] D133634: [clang] Allow vector of BitInt

2022-09-16 Thread Xiang Li via Phabricator via cfe-commits
python3kgae updated this revision to Diff 460659.
python3kgae added a comment.

Limit BitInt vector to byte-sized and power of 2 BitInt.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133634

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/AST/ASTContext.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/Sema/builtin-classify-type.c
  clang/test/SemaCXX/ext-int.cpp

Index: clang/test/SemaCXX/ext-int.cpp
===
--- clang/test/SemaCXX/ext-int.cpp
+++ clang/test/SemaCXX/ext-int.cpp
@@ -84,10 +84,22 @@
 };
 
 // Reject vector types:
-// expected-error@+1{{invalid vector element type '_BitInt(32)'}}
-typedef _BitInt(32) __attribute__((vector_size(16))) VecTy;
-// expected-error@+1{{invalid vector element type '_BitInt(32)'}}
-typedef _BitInt(32) __attribute__((ext_vector_type(32))) OtherVecTy;
+// expected-error@+1{{invalid vector element type '_BitInt(2)', must be byte-sized and power of 2 _BitInt}}
+typedef _BitInt(2) __attribute__((vector_size(16))) VecTy;
+// expected-error@+1{{invalid vector element type '_BitInt(2)', must be byte-sized and power of 2 _BitInt}}
+typedef _BitInt(2) __attribute__((ext_vector_type(32))) OtherVecTy;
+// expected-error@+1{{invalid vector element type '_BitInt(4)', must be byte-sized and power of 2 _BitInt}}
+typedef _BitInt(4) __attribute__((vector_size(16))) VecTy2;
+// expected-error@+1{{invalid vector element type '_BitInt(4)', must be byte-sized and power of 2 _BitInt}}
+typedef _BitInt(4) __attribute__((ext_vector_type(32))) OtherVecTy2;
+// expected-error@+1{{invalid vector element type '_BitInt(5)', must be byte-sized and power of 2 _BitInt}}
+typedef _BitInt(5) __attribute__((vector_size(16))) VecTy3;
+// expected-error@+1{{invalid vector element type '_BitInt(5)', must be byte-sized and power of 2 _BitInt}}
+typedef _BitInt(5) __attribute__((ext_vector_type(32))) OtherVecTy3;
+// expected-error@+1{{invalid vector element type '_BitInt(37)', must be byte-sized and power of 2 _BitInt}}
+typedef _BitInt(37) __attribute__((vector_size(16))) VecTy4;
+// expected-error@+1{{invalid vector element type '_BitInt(37)', must be byte-sized and power of 2 _BitInt}}
+typedef _BitInt(37) __attribute__((ext_vector_type(32))) OtherVecTy4;
 
 // Allow _Complex:
 _Complex _BitInt(3) Cmplx;
Index: clang/test/Sema/builtin-classify-type.c
===
--- clang/test/Sema/builtin-classify-type.c
+++ clang/test/Sema/builtin-classify-type.c
@@ -29,6 +29,23 @@
   __attribute__((vector_size(16))) int vec;
   typedef __attribute__((ext_vector_type(4))) int evec_t;
   evec_t evec;
+  typedef _BitInt(8) int8_t3 __attribute__((ext_vector_type(3)));
+  int8_t3 t3;
+  typedef _BitInt(16) int16_t3 __attribute__((ext_vector_type(4)));
+  int16_t3 t4;
+  typedef _BitInt(32) int32_t3 __attribute__((ext_vector_type(5)));
+  int32_t3 t5;
+  typedef _BitInt(64) int64_t3 __attribute__((ext_vector_type(6)));
+  int64_t3 t6;
+  typedef _BitInt(8) vint8_t3 __attribute__((vector_size(3)));
+  vint8_t3 vt3;
+  typedef _BitInt(16) vint16_t3 __attribute__((vector_size(4)));
+  vint16_t3 vt4;
+  typedef _BitInt(32) vint32_t3 __attribute__((vector_size(8)));
+  vint32_t3 vt5;
+  typedef _BitInt(64) vint64_t3 __attribute__((vector_size(16)));
+  vint64_t3 vt6;
+
   _Atomic int atomic_i;
   _Atomic double atomic_d;
   _Complex int complex_i;
Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -2637,11 +2637,20 @@
   // can't already be a vector.
   if ((!CurType->isDependentType() &&
(!CurType->isBuiltinType() || CurType->isBooleanType() ||
-(!CurType->isIntegerType() && !CurType->isRealFloatingType( ||
+(!CurType->isIntegerType() && !CurType->isRealFloatingType())) &&
+   !CurType->isBitIntType()) ||
   CurType->isArrayType()) {
 Diag(AttrLoc, diag::err_attribute_invalid_vector_type) << CurType;
 return QualType();
   }
+  // Only support _BitInt elements with byte-sized power of 2 NumBits.
+  if (CurType->isBitIntType()) {
+unsigned NumBits = CurType->getAs()->getNumBits();
+if (!llvm::isPowerOf2_32(NumBits) || NumBits < 8) {
+  Diag(AttrLoc, diag::err_attribute_invalid_bitint_vector_type) << CurType;
+  return QualType();
+}
+  }
 
   if (SizeExpr->isTypeDependent() || SizeExpr->isValueDependent())
 return Context.getDependentVectorType(CurType, SizeExpr, AttrLoc,
@@ -2707,12 +2716,21 @@
   // We explictly allow bool elements in ext_vector_type for C/C++.
   bool IsNoBoolVecLang = getLangOpts().OpenCL || getLangOpts().OpenCLCPlusPlus;
   if ((!T->isDependentType() && !T->isIntegerType() &&
-   !T->isRealFloatingType()) || T->isBitIntType() ||
+   !T->isRealFloatingType()) ||
   (IsNoBoolVecLang && T->isBoo

[PATCH] D134018: [clang] [Driver] Add an option to disable default config filenames

2022-09-16 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

This makes sense.




Comment at: clang/lib/Driver/Driver.cpp:1027
 
-  // If config file is not specified explicitly, try to deduce configuration
-  // from executable name. For instance, an executable 'armv7l-clang' will
-  // search for config file 'armv7l-clang.cfg'.
-  if (CfgFileName.empty() && !ClangNameParts.TargetPrefix.empty())
-CfgFileName = ClangNameParts.TargetPrefix + '-' + 
ClangNameParts.ModeSuffix;
+  if (!CLOptions || !CLOptions->hasArg(options::OPT_no_default_config)) {
+// If config file is not specified explicitly, try to deduce configuration

`&&` ?



Comment at: clang/test/Driver/config-file3.c:49
+// NO-DEFAULT-CONFIG-NOT: Configuration file:
+//
 //--- Invocation qqq-clang-g++ tries to find config file qqq.cfg if 
qqq-clang-g++.cfg is not found.

The convention doesn't use otherwise empty `// `. The file does not obey the 
convention but your new lines can drop the empty `//`


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

https://reviews.llvm.org/D134018

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


[PATCH] D133634: [clang] Allow vector of BitInt

2022-09-16 Thread Xiang Li via Phabricator via cfe-commits
python3kgae added a comment.

Thanks for all the comments.
I've limit BitInt vector to BitInt with byte-sized and power of 2  NumBits.

For the ABI, is it OK to let mangleType of VectorType treat BitInt like other 
element types, call mangleType of BitInt for the element type part?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133634

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


[PATCH] D134018: [clang] [Driver] Add an option to disable default config filenames

2022-09-16 Thread Michał Górny via Phabricator via cfe-commits
mgorny added inline comments.



Comment at: clang/lib/Driver/Driver.cpp:1027
 
-  // If config file is not specified explicitly, try to deduce configuration
-  // from executable name. For instance, an executable 'armv7l-clang' will
-  // search for config file 'armv7l-clang.cfg'.
-  if (CfgFileName.empty() && !ClangNameParts.TargetPrefix.empty())
-CfgFileName = ClangNameParts.TargetPrefix + '-' + 
ClangNameParts.ModeSuffix;
+  if (!CLOptions || !CLOptions->hasArg(options::OPT_no_default_config)) {
+// If config file is not specified explicitly, try to deduce configuration

MaskRay wrote:
> `&&` ?
`&&` would mean dereferencing null pointer ;-).



Comment at: clang/test/Driver/config-file3.c:49
+// NO-DEFAULT-CONFIG-NOT: Configuration file:
+//
 //--- Invocation qqq-clang-g++ tries to find config file qqq.cfg if 
qqq-clang-g++.cfg is not found.

MaskRay wrote:
> The convention doesn't use otherwise empty `// `. The file does not obey the 
> convention but your new lines can drop the empty `//`
Do you mean the extra space or the entire empty line?


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

https://reviews.llvm.org/D134018

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


[PATCH] D134018: [clang] [Driver] Add an option to disable default config filenames

2022-09-16 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay accepted this revision.
MaskRay added a comment.
This revision is now accepted and ready to land.

LGTM.




Comment at: clang/lib/Driver/Driver.cpp:1027
 
-  // If config file is not specified explicitly, try to deduce configuration
-  // from executable name. For instance, an executable 'armv7l-clang' will
-  // search for config file 'armv7l-clang.cfg'.
-  if (CfgFileName.empty() && !ClangNameParts.TargetPrefix.empty())
-CfgFileName = ClangNameParts.TargetPrefix + '-' + 
ClangNameParts.ModeSuffix;
+  if (!CLOptions || !CLOptions->hasArg(options::OPT_no_default_config)) {
+// If config file is not specified explicitly, try to deduce configuration

mgorny wrote:
> MaskRay wrote:
> > `&&` ?
> `&&` would mean dereferencing null pointer ;-).
oh, i misread. sorry. the two `if` can be merged



Comment at: clang/test/Driver/config-file3.c:49
+// NO-DEFAULT-CONFIG-NOT: Configuration file:
+//
 //--- Invocation qqq-clang-g++ tries to find config file qqq.cfg if 
qqq-clang-g++.cfg is not found.

mgorny wrote:
> MaskRay wrote:
> > The convention doesn't use otherwise empty `// `. The file does not obey 
> > the convention but your new lines can drop the empty `//`
> Do you mean the extra space or the entire empty line?
I mean `^// *$`, which typically makes the test harder to browse.

(Think of `{` `}` in vim. If every line has `//`, `{` `}` isn't effective at 
all.)


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

https://reviews.llvm.org/D134018

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


[PATCH] D134020: [clang][Interp] Handle enums

2022-09-16 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder created this revision.
tbaeder added reviewers: aaron.ballman, erichkeane, tahonermann, shafik.
Herald added a project: All.
tbaeder requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Handle `DeclRefExpr`s pointing to `EnumConstantDecl`s.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D134020

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/test/AST/Interp/enums.cpp


Index: clang/test/AST/Interp/enums.cpp
===
--- /dev/null
+++ clang/test/AST/Interp/enums.cpp
@@ -0,0 +1,50 @@
+// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -verify %s
+// RUN: %clang_cc1 -verify=ref %s
+
+enum class EC : short {
+  A, B, C
+};
+static_assert(static_cast(EC::A) == 0, "");
+static_assert(static_cast(EC::B) == 1, "");
+static_assert(static_cast(EC::C) == 2, "");
+static_assert(sizeof(EC) == sizeof(short), "");
+
+constexpr EC ec = EC::C;
+static_assert(static_cast(ec) == 2, "");
+
+constexpr int N = 12;
+constexpr int M = 2;
+
+enum CE {
+  ONE = -1,
+  TWO = 2,
+  THREE,
+  FOUR = 4,
+  FIVE = N + M,
+  SIX = FIVE + 2,
+
+};
+static_assert(ONE == -1, "");
+static_assert(THREE == 3, "");
+static_assert(FIVE == 14, "");
+static_assert(SIX == 16, "");
+
+constexpr EC testEnums() {
+  EC e = EC::C;
+
+  e = EC::B;
+
+  EC::B = e; // expected-error{{expression is not assignable}} \
+ // ref-error{{expression is not assignable}}
+
+  return e;
+}
+
+constexpr EC getB() {
+  EC e = EC::C;
+  e = EC::B;
+  return e;
+}
+
+
+static_assert(getB() == EC::B, "");
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -855,6 +855,11 @@
 
   FoundDecl = true;
 }
+  } else if (const auto *ECD = dyn_cast(Decl)) {
+PrimType T = *classify(ECD->getType());
+
+return this->emitConst(T, getIntWidth(ECD->getType()), ECD->getInitVal(),
+   E);
   }
 
   // References are implemented using pointers, so when we get here,


Index: clang/test/AST/Interp/enums.cpp
===
--- /dev/null
+++ clang/test/AST/Interp/enums.cpp
@@ -0,0 +1,50 @@
+// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -verify %s
+// RUN: %clang_cc1 -verify=ref %s
+
+enum class EC : short {
+  A, B, C
+};
+static_assert(static_cast(EC::A) == 0, "");
+static_assert(static_cast(EC::B) == 1, "");
+static_assert(static_cast(EC::C) == 2, "");
+static_assert(sizeof(EC) == sizeof(short), "");
+
+constexpr EC ec = EC::C;
+static_assert(static_cast(ec) == 2, "");
+
+constexpr int N = 12;
+constexpr int M = 2;
+
+enum CE {
+  ONE = -1,
+  TWO = 2,
+  THREE,
+  FOUR = 4,
+  FIVE = N + M,
+  SIX = FIVE + 2,
+
+};
+static_assert(ONE == -1, "");
+static_assert(THREE == 3, "");
+static_assert(FIVE == 14, "");
+static_assert(SIX == 16, "");
+
+constexpr EC testEnums() {
+  EC e = EC::C;
+
+  e = EC::B;
+
+  EC::B = e; // expected-error{{expression is not assignable}} \
+ // ref-error{{expression is not assignable}}
+
+  return e;
+}
+
+constexpr EC getB() {
+  EC e = EC::C;
+  e = EC::B;
+  return e;
+}
+
+
+static_assert(getB() == EC::B, "");
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -855,6 +855,11 @@
 
   FoundDecl = true;
 }
+  } else if (const auto *ECD = dyn_cast(Decl)) {
+PrimType T = *classify(ECD->getType());
+
+return this->emitConst(T, getIntWidth(ECD->getType()), ECD->getInitVal(),
+   E);
   }
 
   // References are implemented using pointers, so when we get here,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D133941: [clang][Interp] Record item types in InterpStack

2022-09-16 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added a comment.

In D133941#3794441 , @junaire wrote:

> Do you think `std::is_same_v` will be even better?

I don't really have a preference.


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

https://reviews.llvm.org/D133941

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


[PATCH] D133924: add clang_CXXMethod_isDeleted function

2022-09-16 Thread Anders Langlands via Phabricator via cfe-commits
anderslanglands updated this revision to Diff 460663.
anderslanglands added a comment.

squashing all commits into one to hopefully fix the revision


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133924

Files:
  clang/bindings/python/clang/cindex.py
  clang/docs/ReleaseNotes.rst
  clang/include/clang-c/Index.h
  clang/test/Index/availability.cpp
  clang/test/Index/deletion.cpp
  clang/tools/c-index-test/c-index-test.c
  clang/tools/libclang/CIndex.cpp
  clang/tools/libclang/libclang.map

Index: clang/tools/libclang/libclang.map
===
--- clang/tools/libclang/libclang.map
+++ clang/tools/libclang/libclang.map
@@ -409,6 +409,7 @@
   global:
 clang_getUnqualifiedType;
 clang_getNonReferenceType;
+clang_CXXMethod_isDeleted;
 };
 
 # Example of how to add a new symbol version entry.  If you do add a new symbol
Index: clang/tools/libclang/CIndex.cpp
===
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/libclang/CIndex.cpp
@@ -8861,6 +8861,16 @@
   return (Method && Method->isDefaulted()) ? 1 : 0;
 }
 
+unsigned clang_CXXMethod_isDeleted(CXCursor C) {
+  if (!clang_isDeclaration(C.kind))
+return 0;
+
+  const Decl *D = cxcursor::getCursorDecl(C);
+  const CXXMethodDecl *Method =
+  D ? dyn_cast_or_null(D->getAsFunction()) : nullptr;
+  return (Method && Method->isDeleted()) ? 1 : 0;
+}
+
 unsigned clang_CXXMethod_isStatic(CXCursor C) {
   if (!clang_isDeclaration(C.kind))
 return 0;
Index: clang/tools/c-index-test/c-index-test.c
===
--- clang/tools/c-index-test/c-index-test.c
+++ clang/tools/c-index-test/c-index-test.c
@@ -900,6 +900,8 @@
   printf(" (mutable)");
 if (clang_CXXMethod_isDefaulted(Cursor))
   printf(" (defaulted)");
+if (clang_CXXMethod_isDeleted(Cursor))
+  printf(" (deleted)");
 if (clang_CXXMethod_isStatic(Cursor))
   printf(" (static)");
 if (clang_CXXMethod_isVirtual(Cursor))
Index: clang/test/Index/deletion.cpp
===
--- /dev/null
+++ clang/test/Index/deletion.cpp
@@ -0,0 +1,14 @@
+struct Foo {
+  int foo() = delete;
+  int bar();
+  Foo() = delete;
+  Foo(int);
+};
+
+
+// RUN: c-index-test -test-print-type --std=c++11 %s | FileCheck %s
+// CHECK: StructDecl=Foo:1:8 (Definition) [type=Foo] [typekind=Record] [isPOD=1]
+// CHECK: CXXMethod=foo:2:7 (unavailable) (deleted) [type=int (){{.*}}] [typekind=FunctionProto] [resulttype=int] [resulttypekind=Int] [isPOD=0]
+// CHECK: CXXMethod=bar:3:7 [type=int (){{.*}}] [typekind=FunctionProto] [resulttype=int] [resulttypekind=Int] [isPOD=0]
+// CHECK: CXXConstructor=Foo:4:3 (unavailable) (default constructor) (deleted) [type=void (){{.*}}] [typekind=FunctionProto] [resulttype=void] [resulttypekind=Void] [isPOD=0]
+// CHECK: CXXConstructor=Foo:5:3 (converting constructor) [type=void (int){{.*}}] [typekind=FunctionProto] [resulttype=void] [resulttypekind=Void] [args= [int] [Int]] [isPOD=0]
Index: clang/test/Index/availability.cpp
===
--- clang/test/Index/availability.cpp
+++ clang/test/Index/availability.cpp
@@ -9,5 +9,5 @@
 // RUN: c-index-test -test-print-type --std=c++11 %s | FileCheck %s
 // CHECK: FunctionDecl=foo:1:6 (unavailable) [type=void ()] [typekind=FunctionProto] [resulttype=void] [resulttypekind=Void] [isPOD=0]
 // CHECK: StructDecl=Foo:3:8 (Definition) [type=Foo] [typekind=Record] [isPOD=1]
-// CHECK: CXXMethod=foo:4:7 (unavailable) [type=int (){{.*}}] [typekind=FunctionProto] [resulttype=int] [resulttypekind=Int] [isPOD=0]
-// CHECK: CXXConstructor=Foo:5:3 (unavailable) (default constructor) [type=void (){{.*}}] [typekind=FunctionProto] [resulttype=void] [resulttypekind=Void] [isPOD=0]
+// CHECK: CXXMethod=foo:4:7 (unavailable) (deleted) [type=int (){{.*}}] [typekind=FunctionProto] [resulttype=int] [resulttypekind=Int] [isPOD=0]
+// CHECK: CXXConstructor=Foo:5:3 (unavailable) (default constructor) (deleted) [type=void (){{.*}}] [typekind=FunctionProto] [resulttype=void] [resulttypekind=Void] [isPOD=0]
Index: clang/include/clang-c/Index.h
===
--- clang/include/clang-c/Index.h
+++ clang/include/clang-c/Index.h
@@ -4924,6 +4924,11 @@
  */
 CINDEX_LINKAGE unsigned clang_CXXMethod_isDefaulted(CXCursor C);
 
+/**
+ * Determine if a C++ method is declared '= delete'.
+ */
+CINDEX_LINKAGE unsigned clang_CXXMethod_isDeleted(CXCursor C);
+
 /**
  * Determine if a C++ member function or member function template is
  * pure virtual.
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -319,6 +319,8 @@
   the behavior of

[PATCH] D133924: add clang_CXXMethod_isDeleted function

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



Comment at: clang/docs/ReleaseNotes.rst:323
+- Introduced the new function `clang_CXXMethod_isDeleted`, which queries
+  whether the method is declared `= delete.
 




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133924

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


[PATCH] D134018: [clang] [Driver] Add an option to disable default config filenames

2022-09-16 Thread Michał Górny via Phabricator via cfe-commits
mgorny updated this revision to Diff 460665.
mgorny added a comment.

Replace `!x || !y` logic with `!(x && y)` that may be easier to comprehend.

Replace `//` with empty lines on test boundaries.


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

https://reviews.llvm.org/D134018

Files:
  clang/docs/UsersManual.rst
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/Driver.cpp
  clang/test/Driver/config-file3.c


Index: clang/test/Driver/config-file3.c
===
--- clang/test/Driver/config-file3.c
+++ clang/test/Driver/config-file3.c
@@ -40,7 +40,13 @@
 // RUN: %t/testdmode/qqq-clang-g++ --config-system-dir=%S/Inputs/config 
--config-user-dir= --config i386-qqq -c -no-canonical-prefixes -### %s 2>&1 | 
FileCheck %s -check-prefix CHECK-EXPLICIT
 //
 // CHECK-EXPLICIT: Configuration file: {{.*}}/Inputs/config/i386-qqq.cfg
+
+//--- --no-default-config disables config search
+//
+// RUN: %t/testdmode/qqq-clang-g++ --config-system-dir= 
--config-user-dir=%t/testdmode --no-default-config -c -### %s 2>&1 | FileCheck 
%s -check-prefix NO-DEFAULT-CONFIG
 //
+// NO-DEFAULT-CONFIG-NOT: Configuration file:
+
 //--- Invocation qqq-clang-g++ tries to find config file qqq.cfg if 
qqq-clang-g++.cfg is not found.
 //
 // RUN: rm %t/testdmode/qqq-clang-g++.cfg
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -1024,11 +1024,14 @@
 }
   }
 
-  // If config file is not specified explicitly, try to deduce configuration
-  // from executable name. For instance, an executable 'armv7l-clang' will
-  // search for config file 'armv7l-clang.cfg'.
-  if (CfgFileName.empty() && !ClangNameParts.TargetPrefix.empty())
-CfgFileName = ClangNameParts.TargetPrefix + '-' + 
ClangNameParts.ModeSuffix;
+  if (!(CLOptions && CLOptions->hasArg(options::OPT_no_default_config))) {
+// If config file is not specified explicitly, try to deduce configuration
+// from executable name. For instance, an executable 'armv7l-clang' will
+// search for config file 'armv7l-clang.cfg'.
+if (CfgFileName.empty() && !ClangNameParts.TargetPrefix.empty())
+  CfgFileName =
+  ClangNameParts.TargetPrefix + '-' + ClangNameParts.ModeSuffix;
+  }
 
   if (CfgFileName.empty())
 return false;
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -901,6 +901,8 @@
 def compatibility__version : JoinedOrSeparate<["-"], "compatibility_version">;
 def config : Separate<["--"], "config">, Flags<[NoXarchOption]>,
   HelpText<"Specifies configuration file">;
+def no_default_config : Flag<["--"], "no-default-config">, 
Flags<[NoXarchOption]>,
+  HelpText<"Disable loading default configuration files">;
 def config_system_dir_EQ : Joined<["--"], "config-system-dir=">, 
Flags<[NoXarchOption, HelpHidden]>,
   HelpText<"System directory for configuration files">;
 def config_user_dir_EQ : Joined<["--"], "config-user-dir=">, 
Flags<[NoXarchOption, HelpHidden]>,
Index: clang/docs/UsersManual.rst
===
--- clang/docs/UsersManual.rst
+++ clang/docs/UsersManual.rst
@@ -904,6 +904,10 @@
 CLANG_CONFIG_FILE_SYSTEM_DIR respectively. The first file found is used. It is
 an error if the required file cannot be found.
 
+If no explicit configuration file is specified, Clang searches for a default
+configuration file following the rules described in the next paragraphs.
+To disable this behavior, `--no-default-config` flag can be used.
+
 Another way to specify a configuration file is to encode it in executable name.
 For example, if the Clang executable is named `armv7l-clang` (it may be a
 symbolic link to `clang`), then Clang will search for file `armv7l.cfg` in the


Index: clang/test/Driver/config-file3.c
===
--- clang/test/Driver/config-file3.c
+++ clang/test/Driver/config-file3.c
@@ -40,7 +40,13 @@
 // RUN: %t/testdmode/qqq-clang-g++ --config-system-dir=%S/Inputs/config --config-user-dir= --config i386-qqq -c -no-canonical-prefixes -### %s 2>&1 | FileCheck %s -check-prefix CHECK-EXPLICIT
 //
 // CHECK-EXPLICIT: Configuration file: {{.*}}/Inputs/config/i386-qqq.cfg
+
+//--- --no-default-config disables config search
+//
+// RUN: %t/testdmode/qqq-clang-g++ --config-system-dir= --config-user-dir=%t/testdmode --no-default-config -c -### %s 2>&1 | FileCheck %s -check-prefix NO-DEFAULT-CONFIG
 //
+// NO-DEFAULT-CONFIG-NOT: Configuration file:
+
 //--- Invocation qqq-clang-g++ tries to find config file qqq.cfg if qqq-clang-g++.cfg is not found.
 //
 // RUN: rm %t/testdmode/qqq-clang-g++.cfg
Index: clang/lib/Driver/Driver.cpp
===

[PATCH] D134018: [clang] [Driver] Add an option to disable default config filenames

2022-09-16 Thread Michał Górny via Phabricator via cfe-commits
mgorny added inline comments.



Comment at: clang/lib/Driver/Driver.cpp:1027
 
-  // If config file is not specified explicitly, try to deduce configuration
-  // from executable name. For instance, an executable 'armv7l-clang' will
-  // search for config file 'armv7l-clang.cfg'.
-  if (CfgFileName.empty() && !ClangNameParts.TargetPrefix.empty())
-CfgFileName = ClangNameParts.TargetPrefix + '-' + 
ClangNameParts.ModeSuffix;
+  if (!CLOptions || !CLOptions->hasArg(options::OPT_no_default_config)) {
+// If config file is not specified explicitly, try to deduce configuration

MaskRay wrote:
> mgorny wrote:
> > MaskRay wrote:
> > > `&&` ?
> > `&&` would mean dereferencing null pointer ;-).
> oh, i misread. sorry. the two `if` can be merged
I've deliberately left it like that to account for possibly more rules being 
added in the future (e.g. explicit `-target`, given the discourse discussion).

I've changed `!x || !y` to `!(x && y)`, perhaps that will be less confusing.



Comment at: clang/test/Driver/config-file3.c:49
+// NO-DEFAULT-CONFIG-NOT: Configuration file:
+//
 //--- Invocation qqq-clang-g++ tries to find config file qqq.cfg if 
qqq-clang-g++.cfg is not found.

MaskRay wrote:
> mgorny wrote:
> > MaskRay wrote:
> > > The convention doesn't use otherwise empty `// `. The file does not obey 
> > > the convention but your new lines can drop the empty `//`
> > Do you mean the extra space or the entire empty line?
> I mean `^// *$`, which typically makes the test harder to browse.
> 
> (Think of `{` `}` in vim. If every line has `//`, `{` `}` isn't effective at 
> all.)
Oh, so you mean to have empty lines between tests to make it easier to navigate 
between tests? Please let me know if I got this right.


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

https://reviews.llvm.org/D134018

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


[PATCH] D134018: [clang] [Driver] Add an option to disable default config filenames

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



Comment at: clang/test/Driver/config-file3.c:44
+
+//--- --no-default-config disables config search
+//

Append `.` after a complete sentence in a comment.



Comment at: clang/test/Driver/config-file3.c:49
+// NO-DEFAULT-CONFIG-NOT: Configuration file:
+//
 //--- Invocation qqq-clang-g++ tries to find config file qqq.cfg if 
qqq-clang-g++.cfg is not found.

mgorny wrote:
> MaskRay wrote:
> > mgorny wrote:
> > > MaskRay wrote:
> > > > The convention doesn't use otherwise empty `// `. The file does not 
> > > > obey the convention but your new lines can drop the empty `//`
> > > Do you mean the extra space or the entire empty line?
> > I mean `^// *$`, which typically makes the test harder to browse.
> > 
> > (Think of `{` `}` in vim. If every line has `//`, `{` `}` isn't effective 
> > at all.)
> Oh, so you mean to have empty lines between tests to make it easier to 
> navigate between tests? Please let me know if I got this right.
Thanks, this looks better. I think the convention is not to even leave `^//$` 
between RUN and CHECK, but the current form is already good enough.


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

https://reviews.llvm.org/D134018

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


[PATCH] D133698: [clang][dataflow] SignAnalysis, edgeTransfer, branchTransfer

2022-09-16 Thread Daniel Krupp via Phabricator via cfe-commits
dkrupp added inline comments.



Comment at: clang/unittests/Analysis/FlowSensitive/SignAnalysisTest.cpp:241
+? SignLattice(R.Val.getInt().getExtValue())
+: SignLattice::bottom();
+  } else {

Isn't this SignLattice::top() instead?

This is an initialization expression, which we cannot evaluate to int, but the 
variable is initialized.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133698

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


[PATCH] D134018: [clang] [Driver] Add an option to disable default config filenames

2022-09-16 Thread Michał Górny via Phabricator via cfe-commits
mgorny marked 6 inline comments as done.
mgorny added a comment.

Thanks! I'm going to give others a few more hours to chime in before merging it.


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

https://reviews.llvm.org/D134018

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


[PATCH] D133945: [clang][ASTImporter] DeclContext::localUncachedLookup: Continue lookup into decl chain when regular lookup fails

2022-09-16 Thread Gabor Marton via Phabricator via cfe-commits
martong accepted this revision.
martong added a comment.
This revision is now accepted and ready to land.

LGTM, Thanks!




Comment at: clang/lib/AST/DeclBase.cpp:1781
   if (Name && !hasLazyLocalLexicalLookups() &&
   !hasLazyExternalLexicalLookups()) {
 if (StoredDeclsMap *Map = LookupPtr) {

Michael137 wrote:
> Michael137 wrote:
> > Could merge the two if-blocks now I suppose
> Nevermind, not true
Yeah, we set HasLazyExternalLexicalLookups to true in 
https://reviews.llvm.org/D61333 exactly for the reason to continue the lookup 
into decl chain.



Comment at: clang/unittests/AST/ASTImporterTest.cpp:4927-4929
+  // Finds via linear search of its LexicalDC (A).
   FooLexicalDC->getRedeclContext()->localUncachedLookup(FooName, FoundDecls);
+  EXPECT_EQ(FoundDecls.size(), 1u);

Very good, now the behavior is the same that we have in case of the 
`ASTImporterLookupTable`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133945

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


[PATCH] D133924: add clang_CXXMethod_isDeleted function

2022-09-16 Thread Anders Langlands via Phabricator via cfe-commits
anderslanglands updated this revision to Diff 460672.
anderslanglands added a comment.

Adding in the dyn_cast_is_present change I missed on the previous one


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133924

Files:
  clang/bindings/python/clang/cindex.py
  clang/docs/ReleaseNotes.rst
  clang/include/clang-c/Index.h
  clang/test/Index/availability.cpp
  clang/test/Index/deletion.cpp
  clang/tools/c-index-test/c-index-test.c
  clang/tools/libclang/CIndex.cpp
  clang/tools/libclang/libclang.map

Index: clang/tools/libclang/libclang.map
===
--- clang/tools/libclang/libclang.map
+++ clang/tools/libclang/libclang.map
@@ -409,6 +409,7 @@
   global:
 clang_getUnqualifiedType;
 clang_getNonReferenceType;
+clang_CXXMethod_isDeleted;
 };
 
 # Example of how to add a new symbol version entry.  If you do add a new symbol
Index: clang/tools/libclang/CIndex.cpp
===
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/libclang/CIndex.cpp
@@ -8861,6 +8861,16 @@
   return (Method && Method->isDefaulted()) ? 1 : 0;
 }
 
+unsigned clang_CXXMethod_isDeleted(CXCursor C) {
+  if (!clang_isDeclaration(C.kind))
+return 0;
+
+  const Decl *D = cxcursor::getCursorDecl(C);
+  const CXXMethodDecl *Method =
+  D ? dyn_cast_if_present(D->getAsFunction()) : nullptr;
+  return (Method && Method->isDeleted()) ? 1 : 0;
+}
+
 unsigned clang_CXXMethod_isStatic(CXCursor C) {
   if (!clang_isDeclaration(C.kind))
 return 0;
Index: clang/tools/c-index-test/c-index-test.c
===
--- clang/tools/c-index-test/c-index-test.c
+++ clang/tools/c-index-test/c-index-test.c
@@ -900,6 +900,8 @@
   printf(" (mutable)");
 if (clang_CXXMethod_isDefaulted(Cursor))
   printf(" (defaulted)");
+if (clang_CXXMethod_isDeleted(Cursor))
+  printf(" (deleted)");
 if (clang_CXXMethod_isStatic(Cursor))
   printf(" (static)");
 if (clang_CXXMethod_isVirtual(Cursor))
Index: clang/test/Index/deletion.cpp
===
--- /dev/null
+++ clang/test/Index/deletion.cpp
@@ -0,0 +1,14 @@
+struct Foo {
+  int foo() = delete;
+  int bar();
+  Foo() = delete;
+  Foo(int);
+};
+
+
+// RUN: c-index-test -test-print-type --std=c++11 %s | FileCheck %s
+// CHECK: StructDecl=Foo:1:8 (Definition) [type=Foo] [typekind=Record] [isPOD=1]
+// CHECK: CXXMethod=foo:2:7 (unavailable) (deleted) [type=int (){{.*}}] [typekind=FunctionProto] [resulttype=int] [resulttypekind=Int] [isPOD=0]
+// CHECK: CXXMethod=bar:3:7 [type=int (){{.*}}] [typekind=FunctionProto] [resulttype=int] [resulttypekind=Int] [isPOD=0]
+// CHECK: CXXConstructor=Foo:4:3 (unavailable) (default constructor) (deleted) [type=void (){{.*}}] [typekind=FunctionProto] [resulttype=void] [resulttypekind=Void] [isPOD=0]
+// CHECK: CXXConstructor=Foo:5:3 (converting constructor) [type=void (int){{.*}}] [typekind=FunctionProto] [resulttype=void] [resulttypekind=Void] [args= [int] [Int]] [isPOD=0]
Index: clang/test/Index/availability.cpp
===
--- clang/test/Index/availability.cpp
+++ clang/test/Index/availability.cpp
@@ -9,5 +9,5 @@
 // RUN: c-index-test -test-print-type --std=c++11 %s | FileCheck %s
 // CHECK: FunctionDecl=foo:1:6 (unavailable) [type=void ()] [typekind=FunctionProto] [resulttype=void] [resulttypekind=Void] [isPOD=0]
 // CHECK: StructDecl=Foo:3:8 (Definition) [type=Foo] [typekind=Record] [isPOD=1]
-// CHECK: CXXMethod=foo:4:7 (unavailable) [type=int (){{.*}}] [typekind=FunctionProto] [resulttype=int] [resulttypekind=Int] [isPOD=0]
-// CHECK: CXXConstructor=Foo:5:3 (unavailable) (default constructor) [type=void (){{.*}}] [typekind=FunctionProto] [resulttype=void] [resulttypekind=Void] [isPOD=0]
+// CHECK: CXXMethod=foo:4:7 (unavailable) (deleted) [type=int (){{.*}}] [typekind=FunctionProto] [resulttype=int] [resulttypekind=Int] [isPOD=0]
+// CHECK: CXXConstructor=Foo:5:3 (unavailable) (default constructor) (deleted) [type=void (){{.*}}] [typekind=FunctionProto] [resulttype=void] [resulttypekind=Void] [isPOD=0]
Index: clang/include/clang-c/Index.h
===
--- clang/include/clang-c/Index.h
+++ clang/include/clang-c/Index.h
@@ -4924,6 +4924,11 @@
  */
 CINDEX_LINKAGE unsigned clang_CXXMethod_isDefaulted(CXCursor C);
 
+/**
+ * Determine if a C++ method is declared '= delete'.
+ */
+CINDEX_LINKAGE unsigned clang_CXXMethod_isDeleted(CXCursor C);
+
 /**
  * Determine if a C++ member function or member function template is
  * pure virtual.
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -319,6 +319,8 @@
   the

[PATCH] D133924: add clang_CXXMethod_isDeleted function

2022-09-16 Thread Anders Langlands via Phabricator via cfe-commits
anderslanglands added a comment.

OK that should all be good now. Thanks for your patience, it's my first time 
doing all this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133924

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


[PATCH] D133807: Update Unicode to 15.0

2022-09-16 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 460679.
cor3ntin added a comment.

Add tests


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133807

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Lex/UnicodeCharSets.h
  clang/test/Lexer/unicode.c
  llvm/lib/Support/Unicode.cpp
  llvm/lib/Support/UnicodeCaseFold.cpp
  llvm/lib/Support/UnicodeNameToCodepoint.cpp
  llvm/lib/Support/UnicodeNameToCodepointGenerated.cpp
  llvm/unittests/Support/UnicodeTest.cpp
  llvm/utils/UnicodeData/UnicodeNameMappingGenerator.cpp

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


[clang] e540965 - [AMDGPU] Added __builtin_amdgcn_ds_bvh_stack_rtn

2022-09-16 Thread Stanislav Mekhanoshin via cfe-commits

Author: Stanislav Mekhanoshin
Date: 2022-09-16T02:42:09-07:00
New Revision: e540965915a490f2f3cc51a09571ad5a573da05d

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

LOG: [AMDGPU] Added __builtin_amdgcn_ds_bvh_stack_rtn

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

Added: 
clang/test/CodeGenOpenCL/builtins-amdgcn-gfx11-err.cl

Modified: 
clang/include/clang/Basic/BuiltinsAMDGPU.def
clang/lib/CodeGen/CGBuiltin.cpp
clang/test/CodeGenOpenCL/builtins-amdgcn-gfx11.cl

Removed: 




diff  --git a/clang/include/clang/Basic/BuiltinsAMDGPU.def 
b/clang/include/clang/Basic/BuiltinsAMDGPU.def
index 6fc3214220106..d8f36f5c36021 100644
--- a/clang/include/clang/Basic/BuiltinsAMDGPU.def
+++ b/clang/include/clang/Basic/BuiltinsAMDGPU.def
@@ -281,6 +281,8 @@ TARGET_BUILTIN(__builtin_amdgcn_wmma_i32_16x16x16_iu4_w64, 
"V4iIbV2iIbV2iV4iIb",
 TARGET_BUILTIN(__builtin_amdgcn_s_sendmsg_rtn, "UiUIi", "n", "gfx11-insts")
 TARGET_BUILTIN(__builtin_amdgcn_s_sendmsg_rtnl, "UWiUIi", "n", "gfx11-insts")
 
+TARGET_BUILTIN(__builtin_amdgcn_ds_bvh_stack_rtn, "V2UiUiUiV4UiIi", "n", 
"gfx11-insts")
+
 
//===--===//
 // Special builtins.
 
//===--===//

diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index fff94678a6845..20a27622c6904 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -16897,6 +16897,21 @@ Value *CodeGenFunction::EmitAMDGPUBuiltinExpr(unsigned 
BuiltinID,
   RayInverseDir, TextureDescr});
   }
 
+  case AMDGPU::BI__builtin_amdgcn_ds_bvh_stack_rtn: {
+SmallVector Args;
+for (int i = 0, e = E->getNumArgs(); i != e; ++i)
+  Args.push_back(EmitScalarExpr(E->getArg(i)));
+
+Function *F = CGM.getIntrinsic(Intrinsic::amdgcn_ds_bvh_stack_rtn);
+Value *Call = Builder.CreateCall(F, Args);
+Value *Rtn = Builder.CreateExtractValue(Call, 0);
+Value *A = Builder.CreateExtractValue(Call, 1);
+llvm::Type *RetTy = ConvertType(E->getType());
+Value *I0 = Builder.CreateInsertElement(PoisonValue::get(RetTy), Rtn,
+(uint64_t)0);
+return Builder.CreateInsertElement(I0, A, 1);
+  }
+
   case AMDGPU::BI__builtin_amdgcn_wmma_bf16_16x16x16_bf16_w32:
   case AMDGPU::BI__builtin_amdgcn_wmma_bf16_16x16x16_bf16_w64:
   case AMDGPU::BI__builtin_amdgcn_wmma_f16_16x16x16_f16_w32:

diff  --git a/clang/test/CodeGenOpenCL/builtins-amdgcn-gfx11-err.cl 
b/clang/test/CodeGenOpenCL/builtins-amdgcn-gfx11-err.cl
new file mode 100644
index 0..00ecf32d94923
--- /dev/null
+++ b/clang/test/CodeGenOpenCL/builtins-amdgcn-gfx11-err.cl
@@ -0,0 +1,11 @@
+// REQUIRES: amdgpu-registered-target
+
+// RUN: %clang_cc1 -triple amdgcn-unknown-unknown -target-cpu gfx1100 -verify 
-S -emit-llvm -o - %s
+
+typedef unsigned int uint;
+typedef uint uint2 __attribute__((ext_vector_type(2)));
+typedef uint uint4 __attribute__((ext_vector_type(4)));
+
+kernel void builtins_amdgcn_bvh_err(global uint2* out, uint addr, uint data, 
uint4 data1, uint offset) {
+  *out = __builtin_amdgcn_ds_bvh_stack_rtn(addr, data, data1, offset); // 
expected-error {{'__builtin_amdgcn_ds_bvh_stack_rtn' must be a constant 
integer}}
+}

diff  --git a/clang/test/CodeGenOpenCL/builtins-amdgcn-gfx11.cl 
b/clang/test/CodeGenOpenCL/builtins-amdgcn-gfx11.cl
index f0dd36480a7e9..4d64d7c9b0fb4 100644
--- a/clang/test/CodeGenOpenCL/builtins-amdgcn-gfx11.cl
+++ b/clang/test/CodeGenOpenCL/builtins-amdgcn-gfx11.cl
@@ -6,6 +6,8 @@
 
 typedef unsigned int uint;
 typedef unsigned long ulong;
+typedef uint uint2 __attribute__((ext_vector_type(2)));
+typedef uint uint4 __attribute__((ext_vector_type(4)));
 
 // CHECK-LABEL: @test_s_sendmsg_rtn(
 // CHECK: call i32 @llvm.amdgcn.s.sendmsg.rtn.i32(i32 0)
@@ -18,3 +20,14 @@ void test_s_sendmsg_rtn(global uint* out) {
 void test_s_sendmsg_rtnl(global ulong* out) {
   *out = __builtin_amdgcn_s_sendmsg_rtnl(0);
 }
+
+// CHECK-LABEL: @test_ds_bvh_stack_rtn(
+// CHECK: %0 = tail call { i32, i32 } @llvm.amdgcn.ds.bvh.stack.rtn(i32 %addr, 
i32 %data, <4 x i32> %data1, i32 128)
+// CHECK: %1 = extractvalue { i32, i32 } %0, 0
+// CHECK: %2 = extractvalue { i32, i32 } %0, 1
+// CHECK: %3 = insertelement <2 x i32> poison, i32 %1, i64 0
+// CHECK: %4 = insertelement <2 x i32> %3, i32 %2, i64 1
+void test_ds_bvh_stack_rtn(global uint2* out, uint addr, uint data, uint4 
data1)
+{
+  *out = __builtin_amdgcn_ds_bvh_stack_rtn(addr, data, data1, 128);
+}



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

[PATCH] D133966: [AMDGPU] Added __builtin_amdgcn_ds_bvh_stack_rtn

2022-09-16 Thread Stanislav Mekhanoshin via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe540965915a4: [AMDGPU] Added 
__builtin_amdgcn_ds_bvh_stack_rtn (authored by rampitec).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133966

Files:
  clang/include/clang/Basic/BuiltinsAMDGPU.def
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGenOpenCL/builtins-amdgcn-gfx11-err.cl
  clang/test/CodeGenOpenCL/builtins-amdgcn-gfx11.cl


Index: clang/test/CodeGenOpenCL/builtins-amdgcn-gfx11.cl
===
--- clang/test/CodeGenOpenCL/builtins-amdgcn-gfx11.cl
+++ clang/test/CodeGenOpenCL/builtins-amdgcn-gfx11.cl
@@ -6,6 +6,8 @@
 
 typedef unsigned int uint;
 typedef unsigned long ulong;
+typedef uint uint2 __attribute__((ext_vector_type(2)));
+typedef uint uint4 __attribute__((ext_vector_type(4)));
 
 // CHECK-LABEL: @test_s_sendmsg_rtn(
 // CHECK: call i32 @llvm.amdgcn.s.sendmsg.rtn.i32(i32 0)
@@ -18,3 +20,14 @@
 void test_s_sendmsg_rtnl(global ulong* out) {
   *out = __builtin_amdgcn_s_sendmsg_rtnl(0);
 }
+
+// CHECK-LABEL: @test_ds_bvh_stack_rtn(
+// CHECK: %0 = tail call { i32, i32 } @llvm.amdgcn.ds.bvh.stack.rtn(i32 %addr, 
i32 %data, <4 x i32> %data1, i32 128)
+// CHECK: %1 = extractvalue { i32, i32 } %0, 0
+// CHECK: %2 = extractvalue { i32, i32 } %0, 1
+// CHECK: %3 = insertelement <2 x i32> poison, i32 %1, i64 0
+// CHECK: %4 = insertelement <2 x i32> %3, i32 %2, i64 1
+void test_ds_bvh_stack_rtn(global uint2* out, uint addr, uint data, uint4 
data1)
+{
+  *out = __builtin_amdgcn_ds_bvh_stack_rtn(addr, data, data1, 128);
+}
Index: clang/test/CodeGenOpenCL/builtins-amdgcn-gfx11-err.cl
===
--- /dev/null
+++ clang/test/CodeGenOpenCL/builtins-amdgcn-gfx11-err.cl
@@ -0,0 +1,11 @@
+// REQUIRES: amdgpu-registered-target
+
+// RUN: %clang_cc1 -triple amdgcn-unknown-unknown -target-cpu gfx1100 -verify 
-S -emit-llvm -o - %s
+
+typedef unsigned int uint;
+typedef uint uint2 __attribute__((ext_vector_type(2)));
+typedef uint uint4 __attribute__((ext_vector_type(4)));
+
+kernel void builtins_amdgcn_bvh_err(global uint2* out, uint addr, uint data, 
uint4 data1, uint offset) {
+  *out = __builtin_amdgcn_ds_bvh_stack_rtn(addr, data, data1, offset); // 
expected-error {{'__builtin_amdgcn_ds_bvh_stack_rtn' must be a constant 
integer}}
+}
Index: clang/lib/CodeGen/CGBuiltin.cpp
===
--- clang/lib/CodeGen/CGBuiltin.cpp
+++ clang/lib/CodeGen/CGBuiltin.cpp
@@ -16897,6 +16897,21 @@
   RayInverseDir, TextureDescr});
   }
 
+  case AMDGPU::BI__builtin_amdgcn_ds_bvh_stack_rtn: {
+SmallVector Args;
+for (int i = 0, e = E->getNumArgs(); i != e; ++i)
+  Args.push_back(EmitScalarExpr(E->getArg(i)));
+
+Function *F = CGM.getIntrinsic(Intrinsic::amdgcn_ds_bvh_stack_rtn);
+Value *Call = Builder.CreateCall(F, Args);
+Value *Rtn = Builder.CreateExtractValue(Call, 0);
+Value *A = Builder.CreateExtractValue(Call, 1);
+llvm::Type *RetTy = ConvertType(E->getType());
+Value *I0 = Builder.CreateInsertElement(PoisonValue::get(RetTy), Rtn,
+(uint64_t)0);
+return Builder.CreateInsertElement(I0, A, 1);
+  }
+
   case AMDGPU::BI__builtin_amdgcn_wmma_bf16_16x16x16_bf16_w32:
   case AMDGPU::BI__builtin_amdgcn_wmma_bf16_16x16x16_bf16_w64:
   case AMDGPU::BI__builtin_amdgcn_wmma_f16_16x16x16_f16_w32:
Index: clang/include/clang/Basic/BuiltinsAMDGPU.def
===
--- clang/include/clang/Basic/BuiltinsAMDGPU.def
+++ clang/include/clang/Basic/BuiltinsAMDGPU.def
@@ -281,6 +281,8 @@
 TARGET_BUILTIN(__builtin_amdgcn_s_sendmsg_rtn, "UiUIi", "n", "gfx11-insts")
 TARGET_BUILTIN(__builtin_amdgcn_s_sendmsg_rtnl, "UWiUIi", "n", "gfx11-insts")
 
+TARGET_BUILTIN(__builtin_amdgcn_ds_bvh_stack_rtn, "V2UiUiUiV4UiIi", "n", 
"gfx11-insts")
+
 
//===--===//
 // Special builtins.
 
//===--===//


Index: clang/test/CodeGenOpenCL/builtins-amdgcn-gfx11.cl
===
--- clang/test/CodeGenOpenCL/builtins-amdgcn-gfx11.cl
+++ clang/test/CodeGenOpenCL/builtins-amdgcn-gfx11.cl
@@ -6,6 +6,8 @@
 
 typedef unsigned int uint;
 typedef unsigned long ulong;
+typedef uint uint2 __attribute__((ext_vector_type(2)));
+typedef uint uint4 __attribute__((ext_vector_type(4)));
 
 // CHECK-LABEL: @test_s_sendmsg_rtn(
 // CHECK: call i32 @llvm.amdgcn.s.sendmsg.rtn.i32(i32 0)
@@ -18,3 +20,14 @@
 void test_s_sendmsg_rtnl(global ulong* out) {
   *out = _

[PATCH] D134018: [clang] [Driver] Add an option to disable default config filenames

2022-09-16 Thread Serge Pavlov via Phabricator via cfe-commits
sepavloff accepted this revision.
sepavloff added a comment.

LGTM.

Thanks!


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

https://reviews.llvm.org/D134018

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


[PATCH] D133941: [clang][Interp] Record item types in InterpStack

2022-09-16 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 460689.

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

https://reviews.llvm.org/D133941

Files:
  clang/lib/AST/Interp/InterpStack.h

Index: clang/lib/AST/Interp/InterpStack.h
===
--- clang/lib/AST/Interp/InterpStack.h
+++ clang/lib/AST/Interp/InterpStack.h
@@ -13,7 +13,9 @@
 #ifndef LLVM_CLANG_AST_INTERP_INTERPSTACK_H
 #define LLVM_CLANG_AST_INTERP_INTERPSTACK_H
 
+#include "PrimType.h"
 #include 
+#include 
 
 namespace clang {
 namespace interp {
@@ -29,10 +31,18 @@
   /// Constructs a value in place on the top of the stack.
   template  void push(Tys &&... Args) {
 new (grow(aligned_size())) T(std::forward(Args)...);
+#ifndef NDEBUG
+ItemTypes.push_back(toPrimType());
+#endif
   }
 
   /// Returns the value from the top of the stack and removes it.
   template  T pop() {
+#ifndef NDEBUG
+assert(!ItemTypes.empty());
+assert(ItemTypes.back() == toPrimType());
+ItemTypes.pop_back();
+#endif
 auto *Ptr = &peek();
 auto Value = std::move(*Ptr);
 Ptr->~T();
@@ -42,6 +52,10 @@
 
   /// Discards the top value from the stack.
   template  void discard() {
+#ifndef NDEBUG
+assert(ItemTypes.back() == toPrimType());
+ItemTypes.pop_back();
+#endif
 auto *Ptr = &peek();
 Ptr->~T();
 shrink(aligned_size());
@@ -49,6 +63,10 @@
 
   /// Returns a reference to the value on the top of the stack.
   template  T &peek() const {
+#ifndef NDEBUG
+assert(!ItemTypes.empty());
+assert(ItemTypes.back() == toPrimType());
+#endif
 return *reinterpret_cast(peek(aligned_size()));
   }
 
@@ -111,6 +129,45 @@
   StackChunk *Chunk = nullptr;
   /// Total size of the stack.
   size_t StackSize = 0;
+
+#ifndef NDEBUG
+  /// vector recording the type of data we pushed into the stack.
+  std::vector ItemTypes;
+
+  template  static constexpr PrimType toPrimType() {
+if constexpr (std::is_same::value)
+  return PT_Ptr;
+else if constexpr (std::is_same::value ||
+   std::is_same::value)
+  return PT_Bool;
+else if constexpr (std::is_same::value ||
+   std::is_same>::value)
+  return PT_Sint8;
+else if constexpr (std::is_same::value ||
+   std::is_same>::value)
+  return PT_Uint8;
+else if constexpr (std::is_same::value ||
+   std::is_same>::value)
+  return PT_Sint16;
+else if constexpr (std::is_same::value ||
+   std::is_same>::value)
+  return PT_Uint16;
+else if constexpr (std::is_same::value ||
+   std::is_same>::value)
+  return PT_Sint32;
+else if constexpr (std::is_same::value ||
+   std::is_same>::value)
+  return PT_Uint32;
+else if constexpr (std::is_same::value ||
+   std::is_same>::value)
+  return PT_Sint64;
+else if constexpr (std::is_same::value ||
+   std::is_same>::value)
+  return PT_Uint64;
+
+llvm_unreachable("unknown type push()'ed into InterpStack");
+  }
+#endif
 };
 
 } // namespace interp
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] aff1f63 - [clang] use getCommonSugar in an assortment of places

2022-09-16 Thread Matheus Izvekov via cfe-commits

Author: Matheus Izvekov
Date: 2022-09-16T11:55:40+02:00
New Revision: aff1f6310e5f4cea92c4504853d5fd824754a74f

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

LOG: [clang] use getCommonSugar in an assortment of places

For this patch, a simple search was performed for patterns where there are
two types (usually an LHS and an RHS) which are structurally the same, and there
is some result type which is resolved as either one of them (typically LHS for
consistency).

We change those cases to resolve as the common sugared type between those two,
utilizing the new infrastructure created for this purpose.

Signed-off-by: Matheus Izvekov 

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

Added: 
clang/test/Sema/sugar-common-types.c
clang/test/SemaCXX/sugar-common-types.cpp

Modified: 
clang-tools-extra/clangd/unittests/tweaks/ExtractVariableTests.cpp

clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/narrowing-conversions-ignoreconversionfromtypes-option.cpp
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/test/AST/ast-dump-fpfeatures.cpp
clang/test/CodeGen/compound-assign-overflow.c
clang/test/Sema/complex-int.c
clang/test/Sema/matrix-type-operators.c
clang/test/Sema/nullability.c
clang/test/SemaCXX/complex-conversion.cpp
clang/test/SemaCXX/matrix-type-operators.cpp
clang/test/SemaCXX/sugared-auto.cpp
clang/test/SemaObjC/format-strings-objc.m
compiler-rt/test/ubsan/TestCases/Integer/add-overflow.cpp
compiler-rt/test/ubsan/TestCases/Integer/no-recover.cpp
compiler-rt/test/ubsan/TestCases/Integer/sub-overflow.cpp
compiler-rt/test/ubsan/TestCases/Integer/uadd-overflow.cpp
compiler-rt/test/ubsan/TestCases/Integer/umul-overflow.cpp
compiler-rt/test/ubsan/TestCases/Integer/usub-overflow.cpp
lldb/test/API/commands/expression/rdar42038760/main.c
lldb/test/API/commands/expression/rdar44436068/main.c

Removed: 




diff  --git 
a/clang-tools-extra/clangd/unittests/tweaks/ExtractVariableTests.cpp 
b/clang-tools-extra/clangd/unittests/tweaks/ExtractVariableTests.cpp
index 70ecc202d0b28..6e38ea77ad68d 100644
--- a/clang-tools-extra/clangd/unittests/tweaks/ExtractVariableTests.cpp
+++ b/clang-tools-extra/clangd/unittests/tweaks/ExtractVariableTests.cpp
@@ -330,7 +330,7 @@ TEST_F(ExtractVariableTest, Test) {
  void bar() {
int (*placeholder)(int) = foo('c'); (void)placeholder;
  })cpp"},
-  // Arithmetic on typedef types yields plain integer types
+  // Arithmetic on typedef types preserves typedef types
   {R"cpp(typedef long NSInteger;
  void varDecl() {
 NSInteger a = 2 * 5;
@@ -339,7 +339,7 @@ TEST_F(ExtractVariableTest, Test) {
R"cpp(typedef long NSInteger;
  void varDecl() {
 NSInteger a = 2 * 5;
-long placeholder = a * 7; NSInteger b = placeholder + 3;
+NSInteger placeholder = a * 7; NSInteger b = placeholder + 3;
  })cpp"},
   };
   for (const auto &IO : InputOutputs) {

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/narrowing-conversions-ignoreconversionfromtypes-option.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/narrowing-conversions-ignoreconversionfromtypes-option.cpp
index 2fc5621c2fb8f..34da420fd0cc5 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/narrowing-conversions-ignoreconversionfromtypes-option.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/narrowing-conversions-ignoreconversionfromtypes-option.cpp
@@ -42,7 +42,7 @@ void narrowing_size_method() {
   // IGNORED: Warning is disabled with IgnoreConversionFromTypes=global_size_t.
 
   i = j + v.size();
-  // CHECK-MESSAGES-DEFAULT: :[[@LINE-1]]:7: warning: narrowing conversion 
from 'long long' to signed type 'int' is implementation-defined 
[cppcoreguidelines-narrowing-conversions]
+  // CHECK-MESSAGES-DEFAULT: :[[@LINE-1]]:7: warning: narrowing conversion 
from 'global_size_t' (aka 'long long') to signed type 'int' is 
implementation-defined [cppcoreguidelines-narrowing-conversions]
   // IGNORED: Warning is disabled with IgnoreConversionFromTypes=global_size_t.
 }
 
@@ -51,7 +51,7 @@ void narrowing_size_method_binary_expr() {
   int j;
   vector v;
   i = j + v.size();
-  // CHECK-MESSAGES-DEFAULT: :[[@LINE-1]]:7: warning: narrowing conversion 
from 'long long' to signed type 'int' is implementation-defined 
[cppcoreguidelines-narrowing-conversions]
+  // CHECK-MESSAGES-DEFAULT: :[[@LINE-1]]:7: warning: narrowing conversion 
from 'global_size_t' (aka 'long long') to signed type 'int' is 
implementation-defined [cppcoreguidelines-narrowing-conversion

[clang] aff1f63 - [clang] use getCommonSugar in an assortment of places

2022-09-16 Thread Matheus Izvekov via cfe-commits

Author: Matheus Izvekov
Date: 2022-09-16T11:55:40+02:00
New Revision: aff1f6310e5f4cea92c4504853d5fd824754a74f

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

LOG: [clang] use getCommonSugar in an assortment of places

For this patch, a simple search was performed for patterns where there are
two types (usually an LHS and an RHS) which are structurally the same, and there
is some result type which is resolved as either one of them (typically LHS for
consistency).

We change those cases to resolve as the common sugared type between those two,
utilizing the new infrastructure created for this purpose.

Signed-off-by: Matheus Izvekov 

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

Added: 
clang/test/Sema/sugar-common-types.c
clang/test/SemaCXX/sugar-common-types.cpp

Modified: 
clang-tools-extra/clangd/unittests/tweaks/ExtractVariableTests.cpp

clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/narrowing-conversions-ignoreconversionfromtypes-option.cpp
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/test/AST/ast-dump-fpfeatures.cpp
clang/test/CodeGen/compound-assign-overflow.c
clang/test/Sema/complex-int.c
clang/test/Sema/matrix-type-operators.c
clang/test/Sema/nullability.c
clang/test/SemaCXX/complex-conversion.cpp
clang/test/SemaCXX/matrix-type-operators.cpp
clang/test/SemaCXX/sugared-auto.cpp
clang/test/SemaObjC/format-strings-objc.m
compiler-rt/test/ubsan/TestCases/Integer/add-overflow.cpp
compiler-rt/test/ubsan/TestCases/Integer/no-recover.cpp
compiler-rt/test/ubsan/TestCases/Integer/sub-overflow.cpp
compiler-rt/test/ubsan/TestCases/Integer/uadd-overflow.cpp
compiler-rt/test/ubsan/TestCases/Integer/umul-overflow.cpp
compiler-rt/test/ubsan/TestCases/Integer/usub-overflow.cpp
lldb/test/API/commands/expression/rdar42038760/main.c
lldb/test/API/commands/expression/rdar44436068/main.c

Removed: 




diff  --git 
a/clang-tools-extra/clangd/unittests/tweaks/ExtractVariableTests.cpp 
b/clang-tools-extra/clangd/unittests/tweaks/ExtractVariableTests.cpp
index 70ecc202d0b28..6e38ea77ad68d 100644
--- a/clang-tools-extra/clangd/unittests/tweaks/ExtractVariableTests.cpp
+++ b/clang-tools-extra/clangd/unittests/tweaks/ExtractVariableTests.cpp
@@ -330,7 +330,7 @@ TEST_F(ExtractVariableTest, Test) {
  void bar() {
int (*placeholder)(int) = foo('c'); (void)placeholder;
  })cpp"},
-  // Arithmetic on typedef types yields plain integer types
+  // Arithmetic on typedef types preserves typedef types
   {R"cpp(typedef long NSInteger;
  void varDecl() {
 NSInteger a = 2 * 5;
@@ -339,7 +339,7 @@ TEST_F(ExtractVariableTest, Test) {
R"cpp(typedef long NSInteger;
  void varDecl() {
 NSInteger a = 2 * 5;
-long placeholder = a * 7; NSInteger b = placeholder + 3;
+NSInteger placeholder = a * 7; NSInteger b = placeholder + 3;
  })cpp"},
   };
   for (const auto &IO : InputOutputs) {

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/narrowing-conversions-ignoreconversionfromtypes-option.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/narrowing-conversions-ignoreconversionfromtypes-option.cpp
index 2fc5621c2fb8f..34da420fd0cc5 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/narrowing-conversions-ignoreconversionfromtypes-option.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/narrowing-conversions-ignoreconversionfromtypes-option.cpp
@@ -42,7 +42,7 @@ void narrowing_size_method() {
   // IGNORED: Warning is disabled with IgnoreConversionFromTypes=global_size_t.
 
   i = j + v.size();
-  // CHECK-MESSAGES-DEFAULT: :[[@LINE-1]]:7: warning: narrowing conversion 
from 'long long' to signed type 'int' is implementation-defined 
[cppcoreguidelines-narrowing-conversions]
+  // CHECK-MESSAGES-DEFAULT: :[[@LINE-1]]:7: warning: narrowing conversion 
from 'global_size_t' (aka 'long long') to signed type 'int' is 
implementation-defined [cppcoreguidelines-narrowing-conversions]
   // IGNORED: Warning is disabled with IgnoreConversionFromTypes=global_size_t.
 }
 
@@ -51,7 +51,7 @@ void narrowing_size_method_binary_expr() {
   int j;
   vector v;
   i = j + v.size();
-  // CHECK-MESSAGES-DEFAULT: :[[@LINE-1]]:7: warning: narrowing conversion 
from 'long long' to signed type 'int' is implementation-defined 
[cppcoreguidelines-narrowing-conversions]
+  // CHECK-MESSAGES-DEFAULT: :[[@LINE-1]]:7: warning: narrowing conversion 
from 'global_size_t' (aka 'long long') to signed type 'int' is 
implementation-defined [cppcoreguidelines-narrowing-conversion

[PATCH] D111509: [clang] use getCommonSugar in an assortment of places

2022-09-16 Thread Matheus Izvekov via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGaff1f6310e5f: [clang] use getCommonSugar in an assortment of 
places (authored by mizvekov).

Changed prior to commit:
  https://reviews.llvm.org/D111509?vs=460587&id=460691#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111509

Files:
  clang-tools-extra/clangd/unittests/tweaks/ExtractVariableTests.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/narrowing-conversions-ignoreconversionfromtypes-option.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/test/AST/ast-dump-fpfeatures.cpp
  clang/test/CodeGen/compound-assign-overflow.c
  clang/test/Sema/complex-int.c
  clang/test/Sema/matrix-type-operators.c
  clang/test/Sema/nullability.c
  clang/test/Sema/sugar-common-types.c
  clang/test/SemaCXX/complex-conversion.cpp
  clang/test/SemaCXX/matrix-type-operators.cpp
  clang/test/SemaCXX/sugar-common-types.cpp
  clang/test/SemaCXX/sugared-auto.cpp
  clang/test/SemaObjC/format-strings-objc.m
  compiler-rt/test/ubsan/TestCases/Integer/add-overflow.cpp
  compiler-rt/test/ubsan/TestCases/Integer/no-recover.cpp
  compiler-rt/test/ubsan/TestCases/Integer/sub-overflow.cpp
  compiler-rt/test/ubsan/TestCases/Integer/uadd-overflow.cpp
  compiler-rt/test/ubsan/TestCases/Integer/umul-overflow.cpp
  compiler-rt/test/ubsan/TestCases/Integer/usub-overflow.cpp
  lldb/test/API/commands/expression/rdar42038760/main.c
  lldb/test/API/commands/expression/rdar44436068/main.c

Index: lldb/test/API/commands/expression/rdar44436068/main.c
===
--- lldb/test/API/commands/expression/rdar44436068/main.c
+++ lldb/test/API/commands/expression/rdar44436068/main.c
@@ -3,6 +3,6 @@
 __int128_t n = 1;
 n = n + n;
 return n; //%self.expect("p n", substrs=['(__int128_t) $0 = 2'])
-  //%self.expect("p n + 6", substrs=['(__int128) $1 = 8'])
-  //%self.expect("p n + n", substrs=['(__int128) $2 = 4'])
+  //%self.expect("p n + 6", substrs=['(__int128_t) $1 = 8'])
+  //%self.expect("p n + n", substrs=['(__int128_t) $2 = 4'])
 }
Index: lldb/test/API/commands/expression/rdar42038760/main.c
===
--- lldb/test/API/commands/expression/rdar42038760/main.c
+++ lldb/test/API/commands/expression/rdar42038760/main.c
@@ -10,7 +10,7 @@
   struct S0 l_19;
   l_19.f2 = 419;
   uint32_t l_4037 = 4294967295UL;
-  l_19.f2 = g_463; //%self.expect("expr ((l_4037 % (-(g_463))) | l_19.f2)", substrs=['(unsigned int) $0 = 358717883'])
+  l_19.f2 = g_463; //%self.expect("expr ((l_4037 % (-(g_463))) | l_19.f2)", substrs=['(uint32_t) $0 = 358717883'])
 }
 int main()
 {
Index: compiler-rt/test/ubsan/TestCases/Integer/usub-overflow.cpp
===
--- compiler-rt/test/ubsan/TestCases/Integer/usub-overflow.cpp
+++ compiler-rt/test/ubsan/TestCases/Integer/usub-overflow.cpp
@@ -12,12 +12,12 @@
 
 #ifdef SUB_I32
   (void)(uint32_t(1) - uint32_t(2));
-  // CHECK-SUB_I32: usub-overflow.cpp:[[@LINE-1]]:22: runtime error: unsigned integer overflow: 1 - 2 cannot be represented in type 'unsigned int'
+  // CHECK-SUB_I32: usub-overflow.cpp:[[@LINE-1]]:22: runtime error: unsigned integer overflow: 1 - 2 cannot be represented in type '{{uint32_t|unsigned int}}'
 #endif
 
 #ifdef SUB_I64
   (void)(uint64_t(800ll) - uint64_t(900ll));
-  // CHECK-SUB_I64: 800 - 900 cannot be represented in type 'unsigned {{long( long)?}}'
+  // CHECK-SUB_I64: 800 - 900 cannot be represented in type '{{uint64_t|unsigned long( long)?}}'
 #endif
 
 #ifdef SUB_I128
@@ -26,6 +26,6 @@
 # else
   puts("__int128 not supported\n");
 # endif
-  // CHECK-SUB_I128: {{0x4000 - 0x8000 cannot be represented in type 'unsigned __int128'|__int128 not supported}}
+  // CHECK-SUB_I128: {{0x4000 - 0x8000 cannot be represented in type '__uint128_t'|__int128 not supported}}
 #endif
 }
Index: compiler-rt/test/ubsan/TestCases/Integer/umul-overflow.cpp
===
--- compiler-rt/test/ubsan/TestCases/Integer/umul-overflow.cpp
+++ compiler-rt/test/ubsan/TestCases/Integer/umul-overflow.cpp
@@ -13,7 +13,7 @@
   (void)(uint16_t(0x) * uint16_t(0x8001));
 
   (void)(uint32_t(0x) * uint32_t(0x2));
-  // CHECK: umul-overflow.cpp:15:31: runtime error: unsigned integer overflow: 4294967295 * 2 cannot be represented in type 'unsigned int'
+  // CHECK: umul-overflow.cpp:15:31: runtim

[PATCH] D133979: [clangd] XRef functions treat visible class definitions as primary.

2022-09-16 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clang-tools-extra/clangd/XRefs.cpp:291
+  // (This exception matches the spirit of our indexing heuristics).
+  if (/*PreferDef=*/[&] {
+if (Def == TD)

can we extract all of this into a `const TagDecl* getPublicDecl(const TagDecl* 
TD)` ?



Comment at: clang-tools-extra/clangd/XRefs.cpp:303
+// decl is some other header.
+return isHeaderFile(SM.getFileEntryRefForID(DefFile)->getName(),
+D->getASTContext().getLangOpts());

nit: we actually have the main file name in ParsedAST, but it's probably not 
worth propagating that into here.



Comment at: clang-tools-extra/clangd/XRefs.cpp:303
+// decl is some other header.
+return isHeaderFile(SM.getFileEntryRefForID(DefFile)->getName(),
+D->getASTContext().getLangOpts());

kadircet wrote:
> nit: we actually have the main file name in ParsedAST, but it's probably not 
> worth propagating that into here.
reaching here actually implies user is in the same file that has the type 
definition (I know we were mostly discussing this for index behaviour, and our 
reasoning for the index makes completely sense) but I am not sure if taking the 
user to public declaration, when they're actually writing some code in the same 
file as the type's private implementation is still the right thing to do.

I think; if the definition is visible through AST, we should always prefer 
that, unless it's in a private header (which in theory we can detect here, as 
we've information about include graph).
do you think jumping to public interface is still desirable even when the user 
is already implementing something inside the private implementation file?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133979

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


[clang-tools-extra] 1d1a98e - Revert "[clang] use getCommonSugar in an assortment of places"

2022-09-16 Thread Matheus Izvekov via cfe-commits

Author: Matheus Izvekov
Date: 2022-09-16T12:03:34+02:00
New Revision: 1d1a98e9a06ed7a9289b2fd7925035dbcbb7e0ce

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

LOG: Revert "[clang] use getCommonSugar in an assortment of places"

This reverts commit aff1f6310e5f4cea92c4504853d5fd824754a74f.

Added: 


Modified: 
clang-tools-extra/clangd/unittests/tweaks/ExtractVariableTests.cpp

clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/narrowing-conversions-ignoreconversionfromtypes-option.cpp
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/test/AST/ast-dump-fpfeatures.cpp
clang/test/CodeGen/compound-assign-overflow.c
clang/test/Sema/complex-int.c
clang/test/Sema/matrix-type-operators.c
clang/test/Sema/nullability.c
clang/test/SemaCXX/complex-conversion.cpp
clang/test/SemaCXX/matrix-type-operators.cpp
clang/test/SemaCXX/sugared-auto.cpp
clang/test/SemaObjC/format-strings-objc.m
compiler-rt/test/ubsan/TestCases/Integer/add-overflow.cpp
compiler-rt/test/ubsan/TestCases/Integer/no-recover.cpp
compiler-rt/test/ubsan/TestCases/Integer/sub-overflow.cpp
compiler-rt/test/ubsan/TestCases/Integer/uadd-overflow.cpp
compiler-rt/test/ubsan/TestCases/Integer/umul-overflow.cpp
compiler-rt/test/ubsan/TestCases/Integer/usub-overflow.cpp
lldb/test/API/commands/expression/rdar42038760/main.c
lldb/test/API/commands/expression/rdar44436068/main.c

Removed: 
clang/test/Sema/sugar-common-types.c
clang/test/SemaCXX/sugar-common-types.cpp



diff  --git 
a/clang-tools-extra/clangd/unittests/tweaks/ExtractVariableTests.cpp 
b/clang-tools-extra/clangd/unittests/tweaks/ExtractVariableTests.cpp
index 6e38ea77ad68d..70ecc202d0b28 100644
--- a/clang-tools-extra/clangd/unittests/tweaks/ExtractVariableTests.cpp
+++ b/clang-tools-extra/clangd/unittests/tweaks/ExtractVariableTests.cpp
@@ -330,7 +330,7 @@ TEST_F(ExtractVariableTest, Test) {
  void bar() {
int (*placeholder)(int) = foo('c'); (void)placeholder;
  })cpp"},
-  // Arithmetic on typedef types preserves typedef types
+  // Arithmetic on typedef types yields plain integer types
   {R"cpp(typedef long NSInteger;
  void varDecl() {
 NSInteger a = 2 * 5;
@@ -339,7 +339,7 @@ TEST_F(ExtractVariableTest, Test) {
R"cpp(typedef long NSInteger;
  void varDecl() {
 NSInteger a = 2 * 5;
-NSInteger placeholder = a * 7; NSInteger b = placeholder + 3;
+long placeholder = a * 7; NSInteger b = placeholder + 3;
  })cpp"},
   };
   for (const auto &IO : InputOutputs) {

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/narrowing-conversions-ignoreconversionfromtypes-option.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/narrowing-conversions-ignoreconversionfromtypes-option.cpp
index 34da420fd0cc5..2fc5621c2fb8f 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/narrowing-conversions-ignoreconversionfromtypes-option.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/narrowing-conversions-ignoreconversionfromtypes-option.cpp
@@ -42,7 +42,7 @@ void narrowing_size_method() {
   // IGNORED: Warning is disabled with IgnoreConversionFromTypes=global_size_t.
 
   i = j + v.size();
-  // CHECK-MESSAGES-DEFAULT: :[[@LINE-1]]:7: warning: narrowing conversion 
from 'global_size_t' (aka 'long long') to signed type 'int' is 
implementation-defined [cppcoreguidelines-narrowing-conversions]
+  // CHECK-MESSAGES-DEFAULT: :[[@LINE-1]]:7: warning: narrowing conversion 
from 'long long' to signed type 'int' is implementation-defined 
[cppcoreguidelines-narrowing-conversions]
   // IGNORED: Warning is disabled with IgnoreConversionFromTypes=global_size_t.
 }
 
@@ -51,7 +51,7 @@ void narrowing_size_method_binary_expr() {
   int j;
   vector v;
   i = j + v.size();
-  // CHECK-MESSAGES-DEFAULT: :[[@LINE-1]]:7: warning: narrowing conversion 
from 'global_size_t' (aka 'long long') to signed type 'int' is 
implementation-defined [cppcoreguidelines-narrowing-conversions]
+  // CHECK-MESSAGES-DEFAULT: :[[@LINE-1]]:7: warning: narrowing conversion 
from 'long long' to signed type 'int' is implementation-defined 
[cppcoreguidelines-narrowing-conversions]
   // IGNORED: Warning is disabled with IgnoreConversionFromTypes=global_size_t.
 }
 
@@ -63,7 +63,7 @@ void narrowing_size_method_binary_op() {
   // IGNORED: Warning is disabled with IgnoreConversionFromTypes=global_size_t.
 
   i += j + v.size();
-  // CHECK-MESSAGES-DEFAULT: :[[@LINE-1]]:8: warning: narrowing conversion 
from 'global_size_t' (aka 'long long') to signed type 'int' is 
implementatio

[PATCH] D133968: [clangd] Enable standard library index by default.

2022-09-16 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added a comment.

thanks, LG but seems to be failing on windows :/


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133968

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


[PATCH] D128462: [HLSL] add -I option for dxc mode.

2022-09-16 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added a comment.

In D128462#3793266 , @beanz wrote:

> I think we had no expectation that DXC-mode would be supported by the tooling 
> APIs at this point.

Right, and as I mentioned in my previous comments this is completely fine, at 
least in the start. because as more and more developers start working with your 
toolchain, they'll also start using clang-tools and their bugs will be on us, 
rather than the maintainers of these toolchain/driver modes. which I believe 
puts the pressure on the wrong end, because we cannot even know what the 
intended way of handling these flags are, let alone knowing about the details 
of file discovery etc. that turns out to be a problem if not done properly.
My main complaint here's around **breaking** functionality for existing 
driver-modes/toolchains, and I am asking either getting OWNERS approvals going 
forward or being more through with the changes or changing the design overall 
to make these less complicated.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128462

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


[PATCH] D133962: [clang(d)] Include/Exclude CLDXC options properly

2022-09-16 Thread Kadir Cetinkaya via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG23ace26e0d1a: [clang(d)] Include/Exclude CLDXC options 
properly (authored by kadircet).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133962

Files:
  clang-tools-extra/clangd/CompileCommands.cpp
  clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
  clang/lib/Tooling/InterpolatingCompilationDatabase.cpp


Index: clang/lib/Tooling/InterpolatingCompilationDatabase.cpp
===
--- clang/lib/Tooling/InterpolatingCompilationDatabase.cpp
+++ clang/lib/Tooling/InterpolatingCompilationDatabase.cpp
@@ -165,8 +165,8 @@
   const unsigned OldPos = Pos;
   std::unique_ptr Arg(OptTable.ParseOneArg(
   ArgList, Pos,
-  /* Include */ ClangCLMode ? CoreOption | CLOption : 0,
-  /* Exclude */ ClangCLMode ? 0 : CLOption));
+  /* Include */ ClangCLMode ? CoreOption | CLOption | CLDXCOption : 0,
+  /* Exclude */ ClangCLMode ? 0 : CLOption | CLDXCOption));
 
   if (!Arg)
 continue;
Index: clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
===
--- clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
+++ clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
@@ -415,6 +415,19 @@
   // Make sure we don't crash.
   Mangler.adjust(Args, "foo.cc");
 }
+
+TEST(CommandMangler, PathsAsPositional) {
+  const auto Mangler = CommandMangler::forTests();
+  std::vector Args = {
+  "clang",
+  "--driver-mode=cl",
+  "-I",
+  "foo",
+  };
+  // Make sure we don't crash.
+  Mangler.adjust(Args, "a.cc");
+  EXPECT_THAT(Args, Contains("foo"));
+}
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/CompileCommands.cpp
===
--- clang-tools-extra/clangd/CompileCommands.cpp
+++ clang-tools-extra/clangd/CompileCommands.cpp
@@ -220,10 +220,13 @@
   ArgList = OptTable.ParseArgs(
   llvm::makeArrayRef(OriginalArgs).drop_front(), IgnoredCount, 
IgnoredCount,
   /*FlagsToInclude=*/
-  IsCLMode ? (driver::options::CLOption | driver::options::CoreOption)
+  IsCLMode ? (driver::options::CLOption | driver::options::CoreOption |
+  driver::options::CLDXCOption)
: /*everything*/ 0,
   /*FlagsToExclude=*/driver::options::NoDriverOption |
-  (IsCLMode ? 0 : driver::options::CLOption));
+  (IsCLMode
+   ? 0
+   : (driver::options::CLOption | driver::options::CLDXCOption)));
 
   llvm::SmallVector IndicesToDrop;
   // Having multiple architecture options (e.g. when building fat binaries)


Index: clang/lib/Tooling/InterpolatingCompilationDatabase.cpp
===
--- clang/lib/Tooling/InterpolatingCompilationDatabase.cpp
+++ clang/lib/Tooling/InterpolatingCompilationDatabase.cpp
@@ -165,8 +165,8 @@
   const unsigned OldPos = Pos;
   std::unique_ptr Arg(OptTable.ParseOneArg(
   ArgList, Pos,
-  /* Include */ ClangCLMode ? CoreOption | CLOption : 0,
-  /* Exclude */ ClangCLMode ? 0 : CLOption));
+  /* Include */ ClangCLMode ? CoreOption | CLOption | CLDXCOption : 0,
+  /* Exclude */ ClangCLMode ? 0 : CLOption | CLDXCOption));
 
   if (!Arg)
 continue;
Index: clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
===
--- clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
+++ clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
@@ -415,6 +415,19 @@
   // Make sure we don't crash.
   Mangler.adjust(Args, "foo.cc");
 }
+
+TEST(CommandMangler, PathsAsPositional) {
+  const auto Mangler = CommandMangler::forTests();
+  std::vector Args = {
+  "clang",
+  "--driver-mode=cl",
+  "-I",
+  "foo",
+  };
+  // Make sure we don't crash.
+  Mangler.adjust(Args, "a.cc");
+  EXPECT_THAT(Args, Contains("foo"));
+}
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/CompileCommands.cpp
===
--- clang-tools-extra/clangd/CompileCommands.cpp
+++ clang-tools-extra/clangd/CompileCommands.cpp
@@ -220,10 +220,13 @@
   ArgList = OptTable.ParseArgs(
   llvm::makeArrayRef(OriginalArgs).drop_front(), IgnoredCount, IgnoredCount,
   /*FlagsToInclude=*/
-  IsCLMode ? (driver::options::CLOption | driver::options::CoreOption)
+  IsCLMode ? (driver::options::CLOption | driver::options::CoreOption |
+  driver::options::CLDXCOption)
: /*everything*/ 0,
   /*FlagsToExclude=*/driver::options::NoDriverOption |
-  (IsCLMode ? 0 : driver::o

[clang] 23ace26 - [clang(d)] Include/Exclude CLDXC options properly

2022-09-16 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2022-09-16T12:20:22+02:00
New Revision: 23ace26e0d1aa2283d65d192c37592fb0eef1b1f

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

LOG: [clang(d)] Include/Exclude CLDXC options properly

This handles the new CLDXC options that was introduced in
https://reviews.llvm.org/D128462 inside clang-tooling to make sure cl driver
mode is not broken.

Fixes https://github.com/clangd/clangd/issues/1292.

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

Added: 


Modified: 
clang-tools-extra/clangd/CompileCommands.cpp
clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
clang/lib/Tooling/InterpolatingCompilationDatabase.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/CompileCommands.cpp 
b/clang-tools-extra/clangd/CompileCommands.cpp
index 16e70d36640df..02acc92265ffa 100644
--- a/clang-tools-extra/clangd/CompileCommands.cpp
+++ b/clang-tools-extra/clangd/CompileCommands.cpp
@@ -220,10 +220,13 @@ void CommandMangler::adjust(std::vector &Cmd,
   ArgList = OptTable.ParseArgs(
   llvm::makeArrayRef(OriginalArgs).drop_front(), IgnoredCount, 
IgnoredCount,
   /*FlagsToInclude=*/
-  IsCLMode ? (driver::options::CLOption | driver::options::CoreOption)
+  IsCLMode ? (driver::options::CLOption | driver::options::CoreOption |
+  driver::options::CLDXCOption)
: /*everything*/ 0,
   /*FlagsToExclude=*/driver::options::NoDriverOption |
-  (IsCLMode ? 0 : driver::options::CLOption));
+  (IsCLMode
+   ? 0
+   : (driver::options::CLOption | driver::options::CLDXCOption)));
 
   llvm::SmallVector IndicesToDrop;
   // Having multiple architecture options (e.g. when building fat binaries)

diff  --git a/clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp 
b/clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
index e8cbaa2bba32d..28ae6ea01e87a 100644
--- a/clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
+++ b/clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
@@ -415,6 +415,19 @@ TEST(CommandMangler, EmptyArgs) {
   // Make sure we don't crash.
   Mangler.adjust(Args, "foo.cc");
 }
+
+TEST(CommandMangler, PathsAsPositional) {
+  const auto Mangler = CommandMangler::forTests();
+  std::vector Args = {
+  "clang",
+  "--driver-mode=cl",
+  "-I",
+  "foo",
+  };
+  // Make sure we don't crash.
+  Mangler.adjust(Args, "a.cc");
+  EXPECT_THAT(Args, Contains("foo"));
+}
 } // namespace
 } // namespace clangd
 } // namespace clang

diff  --git a/clang/lib/Tooling/InterpolatingCompilationDatabase.cpp 
b/clang/lib/Tooling/InterpolatingCompilationDatabase.cpp
index 0143b5f8df6b6..655be20572b66 100644
--- a/clang/lib/Tooling/InterpolatingCompilationDatabase.cpp
+++ b/clang/lib/Tooling/InterpolatingCompilationDatabase.cpp
@@ -165,8 +165,8 @@ struct TransferableCommand {
   const unsigned OldPos = Pos;
   std::unique_ptr Arg(OptTable.ParseOneArg(
   ArgList, Pos,
-  /* Include */ ClangCLMode ? CoreOption | CLOption : 0,
-  /* Exclude */ ClangCLMode ? 0 : CLOption));
+  /* Include */ ClangCLMode ? CoreOption | CLOption | CLDXCOption : 0,
+  /* Exclude */ ClangCLMode ? 0 : CLOption | CLDXCOption));
 
   if (!Arg)
 continue;



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


[PATCH] D122215: [WebAssembly] Initial support for reference type externref in clang

2022-09-16 Thread Paulo Matos via Phabricator via cfe-commits
pmatos updated this revision to Diff 460696.
pmatos marked an inline comment as done.
pmatos added a comment.

Fix a few of the issues mentioned in the revision comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122215

Files:
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/Type.h
  clang/include/clang/AST/TypeProperties.td
  clang/include/clang/Basic/AddressSpaces.h
  clang/include/clang/Basic/BuiltinsWebAssembly.def
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/WebAssemblyReferenceTypes.def
  clang/include/clang/Sema/Sema.h
  clang/include/clang/Serialization/ASTBitCodes.h
  clang/include/clang/module.modulemap
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/ExprConstant.cpp
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/MicrosoftMangle.cpp
  clang/lib/AST/NSAPI.cpp
  clang/lib/AST/PrintfFormatString.cpp
  clang/lib/AST/Type.cpp
  clang/lib/AST/TypeLoc.cpp
  clang/lib/Basic/Targets/DirectX.h
  clang/lib/Basic/Targets/NVPTX.h
  clang/lib/Basic/Targets/SPIR.h
  clang/lib/Basic/Targets/TCE.h
  clang/lib/Basic/Targets/X86.h
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CGDebugInfo.h
  clang/lib/CodeGen/CodeGenTypes.cpp
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  clang/lib/CodeGen/TargetInfo.cpp
  clang/lib/CodeGen/TargetInfo.h
  clang/lib/Index/USRGeneration.cpp
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaType.cpp
  clang/lib/Serialization/ASTCommon.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/test/CodeGen/WebAssembly/wasm-externref.c
  clang/test/CodeGen/builtins-wasm.c
  clang/test/CodeGenCXX/wasm-reftypes-mangle.cpp
  clang/test/CodeGenCXX/wasm-reftypes-typeinfo.cpp
  clang/test/Sema/wasm-refs-and-tables.c
  clang/test/SemaCXX/wasm-refs-and-tables.cpp
  clang/test/SemaTemplate/address_space-dependent.cpp
  clang/tools/libclang/CIndex.cpp
  llvm/include/llvm/IR/Type.h
  llvm/lib/CodeGen/ValueTypes.cpp
  llvm/lib/IR/Type.cpp

Index: llvm/lib/IR/Type.cpp
===
--- llvm/lib/IR/Type.cpp
+++ llvm/lib/IR/Type.cpp
@@ -304,6 +304,18 @@
   return getInt64Ty(C)->getPointerTo(AS);
 }
 
+Type *Type::getWasm_ExternrefTy(LLVMContext &C) {
+  // opaque pointer in addrspace(10)
+  static PointerType *Ty = PointerType::get(C, 10);
+  return Ty;
+}
+
+Type *Type::getWasm_FuncrefTy(LLVMContext &C) {
+  // opaque pointer in addrspace(20)
+  static PointerType *Ty = PointerType::get(C, 20);
+  return Ty;
+}
+
 //===--===//
 //   IntegerType Implementation
 //===--===//
Index: llvm/lib/CodeGen/ValueTypes.cpp
===
--- llvm/lib/CodeGen/ValueTypes.cpp
+++ llvm/lib/CodeGen/ValueTypes.cpp
@@ -204,12 +204,8 @@
   case MVT::x86mmx:  return Type::getX86_MMXTy(Context);
   case MVT::x86amx:  return Type::getX86_AMXTy(Context);
   case MVT::i64x8:   return IntegerType::get(Context, 512);
-  case MVT::externref:
-// pointer to opaque struct in addrspace(10)
-return PointerType::get(StructType::create(Context), 10);
-  case MVT::funcref:
-// pointer to i8 addrspace(20)
-return PointerType::get(Type::getInt8Ty(Context), 20);
+  case MVT::externref: return Type::getWasm_ExternrefTy(Context);
+  case MVT::funcref: return Type::getWasm_FuncrefTy(Context);
   case MVT::v1i1:
 return FixedVectorType::get(Type::getInt1Ty(Context), 1);
   case MVT::v2i1:
Index: llvm/include/llvm/IR/Type.h
===
--- llvm/include/llvm/IR/Type.h
+++ llvm/include/llvm/IR/Type.h
@@ -473,6 +473,8 @@
   static PointerType *getInt16PtrTy(LLVMContext &C, unsigned AS = 0);
   static PointerType *getInt32PtrTy(LLVMContext &C, unsigned AS = 0);
   static PointerType *getInt64PtrTy(LLVMContext &C, unsigned AS = 0);
+  static Type *getWasm_ExternrefTy(LLVMContext &C);
+  static Type *getWasm_FuncrefTy(LLVMContext &C);
 
   /// Return a pointer to the current type. This is equivalent to
   /// PointerType::get(Foo, AddrSpace).
Index: clang/tools/libclang/CIndex.cpp
===
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/libclang/CIndex.cpp
@@ -1627,6 +1627,8 @@
 #include "clang/Basic/PPCTypes.def"
 #define RVV_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
 #include "clang/Basic/RISCVVTypes.def"
+#define WASM_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
+#include "clang/Basic/WebAssemblyReferenceTypes.def"
 #define BUILTIN_TYPE(Id, SingletonId)
 #define SIGNED_TYPE(Id, SingletonId) case BuiltinType::Id:
 #define UNSIGNED_TYPE(Id, Singlet

[PATCH] D122215: [WebAssembly] Initial support for reference type externref in clang

2022-09-16 Thread Paulo Matos via Phabricator via cfe-commits
pmatos planned changes to this revision.
pmatos added a comment.

Still a few more changes are required.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122215

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


[PATCH] D133941: [clang][Interp] Record item types in InterpStack

2022-09-16 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 460697.

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

https://reviews.llvm.org/D133941

Files:
  clang/lib/AST/Interp/InterpStack.h


Index: clang/lib/AST/Interp/InterpStack.h
===
--- clang/lib/AST/Interp/InterpStack.h
+++ clang/lib/AST/Interp/InterpStack.h
@@ -13,7 +13,9 @@
 #ifndef LLVM_CLANG_AST_INTERP_INTERPSTACK_H
 #define LLVM_CLANG_AST_INTERP_INTERPSTACK_H
 
+#include "PrimType.h"
 #include 
+#include 
 
 namespace clang {
 namespace interp {
@@ -29,10 +31,18 @@
   /// Constructs a value in place on the top of the stack.
   template  void push(Tys &&... Args) {
 new (grow(aligned_size())) T(std::forward(Args)...);
+#ifndef NDEBUG
+ItemTypes.push_back(toPrimType());
+#endif
   }
 
   /// Returns the value from the top of the stack and removes it.
   template  T pop() {
+#ifndef NDEBUG
+assert(!ItemTypes.empty());
+assert(ItemTypes.back() == toPrimType());
+ItemTypes.pop_back();
+#endif
 auto *Ptr = &peek();
 auto Value = std::move(*Ptr);
 Ptr->~T();
@@ -42,6 +52,10 @@
 
   /// Discards the top value from the stack.
   template  void discard() {
+#ifndef NDEBUG
+assert(ItemTypes.back() == toPrimType());
+ItemTypes.pop_back();
+#endif
 auto *Ptr = &peek();
 Ptr->~T();
 shrink(aligned_size());
@@ -111,6 +125,45 @@
   StackChunk *Chunk = nullptr;
   /// Total size of the stack.
   size_t StackSize = 0;
+
+#ifndef NDEBUG
+  /// vector recording the type of data we pushed into the stack.
+  std::vector ItemTypes;
+
+  template  static constexpr PrimType toPrimType() {
+if constexpr (std::is_same::value)
+  return PT_Ptr;
+else if constexpr (std::is_same::value ||
+   std::is_same::value)
+  return PT_Bool;
+else if constexpr (std::is_same::value ||
+   std::is_same>::value)
+  return PT_Sint8;
+else if constexpr (std::is_same::value ||
+   std::is_same>::value)
+  return PT_Uint8;
+else if constexpr (std::is_same::value ||
+   std::is_same>::value)
+  return PT_Sint16;
+else if constexpr (std::is_same::value ||
+   std::is_same>::value)
+  return PT_Uint16;
+else if constexpr (std::is_same::value ||
+   std::is_same>::value)
+  return PT_Sint32;
+else if constexpr (std::is_same::value ||
+   std::is_same>::value)
+  return PT_Uint32;
+else if constexpr (std::is_same::value ||
+   std::is_same>::value)
+  return PT_Sint64;
+else if constexpr (std::is_same::value ||
+   std::is_same>::value)
+  return PT_Uint64;
+
+llvm_unreachable("unknown type push()'ed into InterpStack");
+  }
+#endif
 };
 
 } // namespace interp


Index: clang/lib/AST/Interp/InterpStack.h
===
--- clang/lib/AST/Interp/InterpStack.h
+++ clang/lib/AST/Interp/InterpStack.h
@@ -13,7 +13,9 @@
 #ifndef LLVM_CLANG_AST_INTERP_INTERPSTACK_H
 #define LLVM_CLANG_AST_INTERP_INTERPSTACK_H
 
+#include "PrimType.h"
 #include 
+#include 
 
 namespace clang {
 namespace interp {
@@ -29,10 +31,18 @@
   /// Constructs a value in place on the top of the stack.
   template  void push(Tys &&... Args) {
 new (grow(aligned_size())) T(std::forward(Args)...);
+#ifndef NDEBUG
+ItemTypes.push_back(toPrimType());
+#endif
   }
 
   /// Returns the value from the top of the stack and removes it.
   template  T pop() {
+#ifndef NDEBUG
+assert(!ItemTypes.empty());
+assert(ItemTypes.back() == toPrimType());
+ItemTypes.pop_back();
+#endif
 auto *Ptr = &peek();
 auto Value = std::move(*Ptr);
 Ptr->~T();
@@ -42,6 +52,10 @@
 
   /// Discards the top value from the stack.
   template  void discard() {
+#ifndef NDEBUG
+assert(ItemTypes.back() == toPrimType());
+ItemTypes.pop_back();
+#endif
 auto *Ptr = &peek();
 Ptr->~T();
 shrink(aligned_size());
@@ -111,6 +125,45 @@
   StackChunk *Chunk = nullptr;
   /// Total size of the stack.
   size_t StackSize = 0;
+
+#ifndef NDEBUG
+  /// vector recording the type of data we pushed into the stack.
+  std::vector ItemTypes;
+
+  template  static constexpr PrimType toPrimType() {
+if constexpr (std::is_same::value)
+  return PT_Ptr;
+else if constexpr (std::is_same::value ||
+   std::is_same::value)
+  return PT_Bool;
+else if constexpr (std::is_same::value ||
+   std::is_same>::value)
+  return PT_Sint8;
+else if constexpr (std::is_same::value ||
+   std::is_same>::value)
+  return PT_Uint8;
+else if constexpr (std::is_same::value ||
+   std::is_same>::value)
+  return PT_Sint16;
+else if constexpr (std::is_same::value ||
+   std::is_same>::value)
+ 

[PATCH] D133962: [clang(d)] Include/Exclude CLDXC options properly

2022-09-16 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added a comment.

asked for a backport for 15.0.1 in 
https://github.com/llvm/llvm-project/issues/57779


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133962

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


[PATCH] D122215: [WebAssembly] Initial support for reference type externref in clang

2022-09-16 Thread Paulo Matos via Phabricator via cfe-commits
pmatos marked 2 inline comments as done.
pmatos added inline comments.



Comment at: clang/include/clang/AST/Type.h:1972-1973
+  /// Check if this is a WebAssembly Reference Type.
+  bool isWebAssemblyReferenceType() const;
+  bool isWebAssemblyExternrefType() const;
   /// Determines if this is a sizeless type supported by the

aaron.ballman wrote:
> pmatos wrote:
> > aaron.ballman wrote:
> > > It's unfortunate to name this with `ReferenceType` given that we already 
> > > have a considerable number of APIs that assume "reference type" to mean 
> > > `&` or `&&`. We run into similar problems with "pointer type" and 
> > > objective-c pointers.
> > > 
> > > Basically, I worry we're setting ourselves up for another 
> > > `isObjCObjectPointerType()`/`isPointerType()` situation.
> > I understand this concern. However, unsure what else to call it given 
> > that's what it is. It's a WebAssembly Reference Type, which indeed is 
> > different from a C/C++ ReferenceType. Could call it OpaqueType but that 
> > would be even worse. Not only it's not called an opaque type in Wasm, it's 
> > also not what LLVM users will think of as Opaque Types.
> Yeah, I think this is as good of a name as we're likely to find; I certainly 
> haven't thought of something better. If we do think of something later, we 
> can refactor then.
OK - thanks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122215

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


[PATCH] D133757: [clangd] Turn QueryDriverDatabase into a CompileCommandsAdjuster

2022-09-16 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added a comment.

In D133757#3792930 , @nridge wrote:

> Thanks for the feedback! Yeah I'd be wary of introducing a corner case where 
> the user passes `--query-driver`, and there is in fact a driver available to 
> query in `PATH`, but we end up not querying it. Even if the outcome is the 
> same in cases we can think of, it feels like a footgun that's going to bite 
> some user somewhere.

Just to give my perspective here to close the loop, I agree that there could be 
users effected from this I just wasn't sure if that would be common enough (+ 
we have workarounds by specifying the absolute path in config, database etc.) 
to justify both performing all the necessary review and maintenance afterwards. 
I think we've agreed on a somewhat less intrusive way for the change with Sam 
for the maintenance efforts, and we've already paid the review costs anyways. 
So I am also fine with going down this path, and hopefully not ending up seeing 
some surprises on dark corners of the universe.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133757

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


[clang] c7c0ce7 - Fix the clang Sphinx bot

2022-09-16 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2022-09-16T07:19:30-04:00
New Revision: c7c0ce7d9ebdc0a49313bc77e14d1e856794f2e0

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

LOG: Fix the clang Sphinx bot

This addresses failures introduced by:
https://lab.llvm.org/buildbot/#/builders/92/builds/32809

It also fixes a secondary issue that crept in after the above build
started failing.

Added: 


Modified: 
clang/docs/JSONCompilationDatabase.rst
clang/docs/SanitizerCoverage.rst

Removed: 




diff  --git a/clang/docs/JSONCompilationDatabase.rst 
b/clang/docs/JSONCompilationDatabase.rst
index 3075920576814..0227f0bfe3e62 100644
--- a/clang/docs/JSONCompilationDatabase.rst
+++ b/clang/docs/JSONCompilationDatabase.rst
@@ -30,7 +30,7 @@ Supported Systems
 =
 
 Clang has the ability to generate compilation database fragments via
-the :option:`-MJ argument >`. You can concatenate those
+``-MJ argument >``. You can concatenate those
 fragments together between ``[`` and ``]`` to create a compilation database.
 
 Currently `CMake `_ (since 2.8.5) supports generation

diff  --git a/clang/docs/SanitizerCoverage.rst 
b/clang/docs/SanitizerCoverage.rst
index c6e77cd7295c2..c7ced397c7223 100644
--- a/clang/docs/SanitizerCoverage.rst
+++ b/clang/docs/SanitizerCoverage.rst
@@ -350,6 +350,7 @@ The table is encoded in a special section named 
``sancov_cfs``
 Example:
 
 .. code-block:: c++
+
   int foo (int x) {
 if (x > 0)
   bar(x);



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


[PATCH] D122215: [WebAssembly] Initial support for reference type externref in clang

2022-09-16 Thread Paulo Matos via Phabricator via cfe-commits
pmatos marked 10 inline comments as done.
pmatos added inline comments.



Comment at: clang/include/clang/Basic/AddressSpaces.h:59-60
 
+  wasm_var,
+  wasm_externref,
   // This denotes the count of language-specific address spaces and also

aaron.ballman wrote:
> tlively wrote:
> > What is `wasm_var`? It would be good to have a short comment here (and 
> > newline afterward).
> Agreed; I'm not certain why `wasm_var` is part of this changeset.
Yes, it was a mistake during patch splitting. I have removed it. Thanks.



Comment at: clang/lib/AST/ASTContext.cpp:2258
+Width = 0; 
\
+Align = 8; /* ? */ 
\
+break;

tlively wrote:
> I assume things will break if you say 0 here, but would 1 work?
Yes, 1 seems to work. I am not 100% sure but since externref cannot be written 
to memory, does it matter?



Comment at: clang/lib/AST/ASTContext.cpp:3984
+QualType ASTContext::getExternrefType() const {
+  if (Target->hasFeature("reference-types")) {
+#define WASM_REF_TYPE(Name, MangledName, Id, SingletonId, AS)  
\

tlively wrote:
> Do we need `Target.getTriple().isWasm()` here as well?
Might be useful, in case another target has also a feature called 
`reference-types`. :)



Comment at: clang/lib/Basic/Targets/DirectX.h:44-45
+0, // ptr64
+1, // wasm_var
+10,// wasm_externref
 };

tlively wrote:
> What are these for? I'm surprised we need to do anything here in the DirectX 
> target. Same for the similar lines in other targets.
I was surprised as well, but apparently if you don't add them to all targets, 
they will not compile. There's an assignment of these Target specific 
AddrSpaceMaps to the AddrSpaceMap: `AddrSpaceMap = &DirectXAddrSpaceMap;`, and 
AddrSpaceMap is a LangAS defined in AddressSpaces.h so anything added there 
needs to be added to all targets afaiu. 



Comment at: clang/test/Sema/wasm-refs-and-tables.c:3
+
+// Note: As WebAssembly references are sizeless types, we don't exhaustively
+// test for cases covered by sizeless-1.c and similar tests.

tlively wrote:
> Should this file be just `wasm-refs.c` since it doesn't do anything with 
> tables yet? Same for the next one.
Tables to be added in a future patch. ;)
But yeah, I will rename for now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122215

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


[PATCH] D133924: add clang_CXXMethod_isDeleted function

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

LGTM aside from the one minor nit.

Do you need someone to commit on your behalf? If so, what name and email 
address would you like used for patch attribution?




Comment at: clang/docs/ReleaseNotes.rst:323
+- Introduced the new function `clang_CXXMethod_isDeleted`, which queries
+  whether the method is declared `= delete.
 

tbaeder wrote:
> 
Looks like this change still needs to be applied.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133924

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


[PATCH] D133574: [C2x] reject type definitions in offsetof

2022-09-16 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/test/Sema/offsetof.c:79
+int a;
+struct B // no-error, struct B is not defined within __builtin_offsetof 
directly
+{

inclyc wrote:
> aaron.ballman wrote:
> > inclyc wrote:
> > > inclyc wrote:
> > > > aaron.ballman wrote:
> > > > > inclyc wrote:
> > > > > > aaron.ballman wrote:
> > > > > > > I think this is defensible. The wording in the standard is "If 
> > > > > > > the specified type defines a new type or if the specified member 
> > > > > > > is a bit-field, the behavior is undefined." and the specified 
> > > > > > > type in this case is `struct A`; that `struct A` happens to also 
> > > > > > > define `struct B` is immaterial.
> > > > > > > 
> > > > > > > However, the intent behind the change to the rule is to support 
> > > > > > > older implementations of `offsetof` to protect them from having 
> > > > > > > to deal with a case like: `offsetof(struct S { int a, b }, b);` 
> > > > > > > where `offsetof` is a macro and thus the comma between `a` and 
> > > > > > > `b` is treated as a separator. So there's a part of me that 
> > > > > > > wonders if we want to also support diagnosing this case. But then 
> > > > > > > we'd have to look at the declarator context more recursively to 
> > > > > > > see whether any of the contexts on the stack are an `offsetof` 
> > > > > > > context and that might be tricky.
> > > > > > > 
> > > > > > > Thoughts?
> > > > > > FWIW, gcc seems just rejects all definitions in this context. 
> > > > > > (Perhaps during Parsing the statements). If we add a bool state to 
> > > > > > the Parser (just using RAII object as before) struct B will trigger 
> > > > > > diagnostic error because the state "ParsingOffsetof" is passed into 
> > > > > > inner declaration.
> > > > > GCC accepts currently: https://godbolt.org/z/oEvzjW6Ee but you're 
> > > > > correct regarding switching back to an RAII object being an easier 
> > > > > way to address the nested declarations.
> > > > > 
> > > > > Let me think on this situation a bit
> > > > > GCC accepts currently
> > > > 
> > > > C++: https://godbolt.org/z/fon8e7dzf 
> > > ```
> > > : In function 'int main()':
> > > :3:3: error: types may not be defined within '__builtin_offsetof'
> > > 3 |   {
> > >   |   ^
> > > :6:5: error: types may not be defined within '__builtin_offsetof'
> > > 6 | {
> > >   | ^
> > > Compiler returned: 1
> > > ```
> > C++ is a different language in this case though. In C, you can generally 
> > define types anywhere you can spell a type, and in C++ you cannot. e.g., 
> > `void func(struct S { int x, y; } s);` is valid in C and invalid in C++.
> GCC explicitly reject type definitions since GCC 8 (in C++ mode). I guess the 
> logic here in GCC may also add a boolean state parameter to parser.
> 
> Interestingly, in C++ we treat the first parameter of `__builtin_offsetof` as 
> a type specifier, rejecting the definition of `struct A`, but not rejecting 
> nested definition `struct B`
> 
> https://godbolt.org/z/PqWjzqqYn
> 
> Emm, so, how about switch back to RAIIObject to support diagnosing nested 
> definitions?
> Interestingly, in C++ we treat the first parameter of __builtin_offsetof as a 
> type specifier, rejecting the definition of struct A, but not rejecting 
> nested definition struct B

Yeah, that is interesting!

> Emm, so, how about switch back to RAIIObject to support diagnosing nested 
> definitions?

I'm getting more comfortable with that approach. Please be sure to add C++ 
tests to make sure we diagnose in C and C++ the same way in terms of nested 
structures. Thank you for exploring the approaches with me!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133574

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


[PATCH] D133108: [clang] Rework IsTailPaddedMemberArray into isFlexibleArrayMemberExpr

2022-09-16 Thread serge via Phabricator via cfe-commits
serge-sans-paille updated this revision to Diff 460704.
serge-sans-paille added a comment.

Take reviews into account


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

https://reviews.llvm.org/D133108

Files:
  clang/lib/Sema/SemaChecking.cpp

Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -15891,17 +15891,24 @@
 << TRange << Op->getSourceRange();
 }
 
-/// Check whether this array fits the idiom of a size-one tail padded
-/// array member of a struct.
+/// Check whether this array fits the idiom of a flexible array member,
+/// depending on the value of -fstrict-flex-array.
 ///
-/// We avoid emitting out-of-bounds access warnings for such arrays as they are
-/// commonly used to emulate flexible arrays in C89 code.
-static bool IsTailPaddedMemberArray(Sema &S, const llvm::APInt &Size,
-const NamedDecl *ND,
-unsigned StrictFlexArraysLevel) {
+/// We avoid emitting out-of-bounds access warnings for such arrays.
+static bool isFlexibleArrayMemberExpr(Sema &S, const Expr *E,
+  const NamedDecl *ND,
+  unsigned StrictFlexArraysLevel) {
+
   if (!ND)
 return false;
 
+  const ConstantArrayType *ArrayTy =
+  S.Context.getAsConstantArrayType(E->getType());
+  llvm::APInt Size = ArrayTy->getSize();
+
+  if (Size == 0)
+return true;
+
   // FIXME: While the default -fstrict-flex-arrays=0 permits Size>1 trailing
   // arrays to be treated as flexible-array-members, we still emit diagnostics
   // as if they are not. Pending further discussion...
@@ -15967,11 +15974,21 @@
   const ConstantArrayType *ArrayTy =
   Context.getAsConstantArrayType(BaseExpr->getType());
 
+  const unsigned StrictFlexArraysLevel = getLangOpts().StrictFlexArrays;
+
+  const NamedDecl *ND = nullptr;
+  if (const auto *DRE = dyn_cast(BaseExpr))
+ND = DRE->getDecl();
+  else if (const auto *ME = dyn_cast(BaseExpr))
+ND = ME->getMemberDecl();
+
   const Type *BaseType =
   ArrayTy == nullptr ? nullptr : ArrayTy->getElementType().getTypePtr();
-  bool IsUnboundedArray = (BaseType == nullptr);
+  bool IsUnboundedArray =
+  BaseType == nullptr ||
+  isFlexibleArrayMemberExpr(*this, BaseExpr, ND, StrictFlexArraysLevel);
   if (EffectiveType->isDependentType() ||
-  (!IsUnboundedArray && BaseType->isDependentType()))
+  !IsUnboundedArray && BaseType->isDependentType())
 return;
 
   Expr::EvalResult Result;
@@ -15984,12 +16001,6 @@
 index = -index;
   }
 
-  const NamedDecl *ND = nullptr;
-  if (const DeclRefExpr *DRE = dyn_cast(BaseExpr))
-ND = DRE->getDecl();
-  if (const MemberExpr *ME = dyn_cast(BaseExpr))
-ND = ME->getMemberDecl();
-
   if (IsUnboundedArray) {
 if (EffectiveType->isFunctionType())
   return;
@@ -16067,17 +16078,10 @@
 // example). In this case we have no information about whether the array
 // access exceeds the array bounds. However we can still diagnose an array
 // access which precedes the array bounds.
-//
-// FIXME: this check should be redundant with the IsUnboundedArray check
-// above.
 if (BaseType->isIncompleteType())
   return;
 
-// FIXME: this check should be used to set IsUnboundedArray from the
-// beginning.
 llvm::APInt size = ArrayTy->getSize();
-if (!size.isStrictlyPositive())
-  return;
 
 if (BaseType != EffectiveType) {
   // Make sure we're comparing apples to apples when comparing index to size
@@ -16107,11 +16111,6 @@
 if (AllowOnePastEnd ? index.ule(size) : index.ult(size))
   return;
 
-// Also don't warn for Flexible Array Member emulation.
-const unsigned StrictFlexArraysLevel = getLangOpts().StrictFlexArrays;
-if (IsTailPaddedMemberArray(*this, size, ND, StrictFlexArraysLevel))
-  return;
-
 // Suppress the warning if the subscript expression (as identified by the
 // ']' location) and the index expression are both from macro expansions
 // within a system header.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D110869: [X86] Implement -fzero-call-used-regs option

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

Follow up fix: https://reviews.llvm.org/D133946


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110869

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


[PATCH] D122215: [WebAssembly] Initial support for reference type externref in clang

2022-09-16 Thread Paulo Matos via Phabricator via cfe-commits
pmatos updated this revision to Diff 460706.
pmatos marked 4 inline comments as done.
pmatos added a comment.

Further changes - more to come.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122215

Files:
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/Type.h
  clang/include/clang/AST/TypeProperties.td
  clang/include/clang/Basic/AddressSpaces.h
  clang/include/clang/Basic/BuiltinsWebAssembly.def
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/WebAssemblyReferenceTypes.def
  clang/include/clang/Sema/Sema.h
  clang/include/clang/Serialization/ASTBitCodes.h
  clang/include/clang/module.modulemap
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/ExprConstant.cpp
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/MicrosoftMangle.cpp
  clang/lib/AST/NSAPI.cpp
  clang/lib/AST/PrintfFormatString.cpp
  clang/lib/AST/Type.cpp
  clang/lib/AST/TypeLoc.cpp
  clang/lib/Basic/Targets/DirectX.h
  clang/lib/Basic/Targets/NVPTX.h
  clang/lib/Basic/Targets/SPIR.h
  clang/lib/Basic/Targets/TCE.h
  clang/lib/Basic/Targets/X86.h
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CGDebugInfo.h
  clang/lib/CodeGen/CodeGenTypes.cpp
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  clang/lib/CodeGen/TargetInfo.cpp
  clang/lib/CodeGen/TargetInfo.h
  clang/lib/Index/USRGeneration.cpp
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaType.cpp
  clang/lib/Serialization/ASTCommon.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/test/CodeGen/WebAssembly/wasm-externref.c
  clang/test/CodeGen/builtins-wasm.c
  clang/test/CodeGenCXX/wasm-reftypes-mangle.cpp
  clang/test/CodeGenCXX/wasm-reftypes-typeinfo.cpp
  clang/test/Sema/wasm-refs-and-tables.c
  clang/test/SemaCXX/wasm-refs.cpp
  clang/test/SemaTemplate/address_space-dependent.cpp
  clang/tools/libclang/CIndex.cpp
  llvm/include/llvm/IR/Type.h
  llvm/lib/CodeGen/ValueTypes.cpp
  llvm/lib/IR/Type.cpp

Index: llvm/lib/IR/Type.cpp
===
--- llvm/lib/IR/Type.cpp
+++ llvm/lib/IR/Type.cpp
@@ -304,6 +304,18 @@
   return getInt64Ty(C)->getPointerTo(AS);
 }
 
+Type *Type::getWasm_ExternrefTy(LLVMContext &C) {
+  // opaque pointer in addrspace(10)
+  static PointerType *Ty = PointerType::get(C, 10);
+  return Ty;
+}
+
+Type *Type::getWasm_FuncrefTy(LLVMContext &C) {
+  // opaque pointer in addrspace(20)
+  static PointerType *Ty = PointerType::get(C, 20);
+  return Ty;
+}
+
 //===--===//
 //   IntegerType Implementation
 //===--===//
Index: llvm/lib/CodeGen/ValueTypes.cpp
===
--- llvm/lib/CodeGen/ValueTypes.cpp
+++ llvm/lib/CodeGen/ValueTypes.cpp
@@ -204,12 +204,8 @@
   case MVT::x86mmx:  return Type::getX86_MMXTy(Context);
   case MVT::x86amx:  return Type::getX86_AMXTy(Context);
   case MVT::i64x8:   return IntegerType::get(Context, 512);
-  case MVT::externref:
-// pointer to opaque struct in addrspace(10)
-return PointerType::get(StructType::create(Context), 10);
-  case MVT::funcref:
-// pointer to i8 addrspace(20)
-return PointerType::get(Type::getInt8Ty(Context), 20);
+  case MVT::externref: return Type::getWasm_ExternrefTy(Context);
+  case MVT::funcref: return Type::getWasm_FuncrefTy(Context);
   case MVT::v1i1:
 return FixedVectorType::get(Type::getInt1Ty(Context), 1);
   case MVT::v2i1:
Index: llvm/include/llvm/IR/Type.h
===
--- llvm/include/llvm/IR/Type.h
+++ llvm/include/llvm/IR/Type.h
@@ -473,6 +473,8 @@
   static PointerType *getInt16PtrTy(LLVMContext &C, unsigned AS = 0);
   static PointerType *getInt32PtrTy(LLVMContext &C, unsigned AS = 0);
   static PointerType *getInt64PtrTy(LLVMContext &C, unsigned AS = 0);
+  static Type *getWasm_ExternrefTy(LLVMContext &C);
+  static Type *getWasm_FuncrefTy(LLVMContext &C);
 
   /// Return a pointer to the current type. This is equivalent to
   /// PointerType::get(Foo, AddrSpace).
Index: clang/tools/libclang/CIndex.cpp
===
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/libclang/CIndex.cpp
@@ -1627,6 +1627,8 @@
 #include "clang/Basic/PPCTypes.def"
 #define RVV_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
 #include "clang/Basic/RISCVVTypes.def"
+#define WASM_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
+#include "clang/Basic/WebAssemblyReferenceTypes.def"
 #define BUILTIN_TYPE(Id, SingletonId)
 #define SIGNED_TYPE(Id, SingletonId) case BuiltinType::Id:
 #define UNSIGNED_TYPE(Id, SingletonId) case BuiltinType::Id:
Index: clan

[PATCH] D133634: [clang] Allow vector of BitInt

2022-09-16 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a subscriber: eli.friedman.
erichkeane added a comment.

The CFE Changes look correct, but @eli.friedman/@craig.topper should comment as 
to whether this is acceptable.

It still needs a few codegen tests however, to make sure the basic operations 
work, and that these are passed correctly.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133634

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


[PATCH] D134020: [clang][Interp] Handle enums

2022-09-16 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

I can't come up with a way to get a reference to one of these, so the logic in 
the rest of the DeclRefExpr handling is a little MORE awkward looking now.  I 
think I'm OK with this, but I want to give a few other folks a chance to look.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134020

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


[PATCH] D134020: [clang][Interp] Handle enums

2022-09-16 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

Also note, the CI test is from your test!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134020

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


[PATCH] D133945: [clang][ASTImporter] DeclContext::localUncachedLookup: Continue lookup into decl chain when regular lookup fails

2022-09-16 Thread Michael Buch via Phabricator via cfe-commits
Michael137 updated this revision to Diff 460718.
Michael137 added a comment.

- Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133945

Files:
  clang/lib/AST/DeclBase.cpp
  clang/unittests/AST/ASTImporterTest.cpp
  
lldb/test/API/lang/cpp/gmodules/template-with-same-arg/TestTemplateWithSameArg.py


Index: 
lldb/test/API/lang/cpp/gmodules/template-with-same-arg/TestTemplateWithSameArg.py
===
--- 
lldb/test/API/lang/cpp/gmodules/template-with-same-arg/TestTemplateWithSameArg.py
+++ 
lldb/test/API/lang/cpp/gmodules/template-with-same-arg/TestTemplateWithSameArg.py
@@ -34,7 +34,6 @@
 self.main_source_file = lldb.SBFileSpec("main.cpp")
 
 @add_test_categories(["gmodules"])
-@skipIf(bugnumber='rdar://96581048')
 def test_same_template_arg(self):
 lldbutil.run_to_source_breakpoint(self, "Break here", 
self.main_source_file)
 
@@ -51,7 +50,6 @@
 ])
 
 @add_test_categories(["gmodules"])
-@skipIf(bugnumber='rdar://96581048')
 def test_duplicate_decls(self):
 lldbutil.run_to_source_breakpoint(self, "Break here", 
self.main_source_file)
 
Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -4924,9 +4924,9 @@
   FooDC->getRedeclContext()->localUncachedLookup(FooName, FoundDecls);
   EXPECT_EQ(FoundDecls.size(), 0u);
 
-  // Cannot find in the LookupTable of its LexicalDC (A).
+  // Finds via linear search of its LexicalDC (A).
   FooLexicalDC->getRedeclContext()->localUncachedLookup(FooName, FoundDecls);
-  EXPECT_EQ(FoundDecls.size(), 0u);
+  EXPECT_EQ(FoundDecls.size(), 1u);
 
   // Can't find in the list of Decls of the DC.
   EXPECT_EQ(findInDeclListOfDC(FooDC, FooName), nullptr);
Index: clang/lib/AST/DeclBase.cpp
===
--- clang/lib/AST/DeclBase.cpp
+++ clang/lib/AST/DeclBase.cpp
@@ -1771,7 +1771,8 @@
   if (!hasExternalVisibleStorage() && !hasExternalLexicalStorage() && Name) {
 lookup_result LookupResults = lookup(Name);
 Results.insert(Results.end(), LookupResults.begin(), LookupResults.end());
-return;
+if (!Results.empty())
+  return;
   }
 
   // If we have a lookup table, check there first. Maybe we'll get lucky.


Index: lldb/test/API/lang/cpp/gmodules/template-with-same-arg/TestTemplateWithSameArg.py
===
--- lldb/test/API/lang/cpp/gmodules/template-with-same-arg/TestTemplateWithSameArg.py
+++ lldb/test/API/lang/cpp/gmodules/template-with-same-arg/TestTemplateWithSameArg.py
@@ -34,7 +34,6 @@
 self.main_source_file = lldb.SBFileSpec("main.cpp")
 
 @add_test_categories(["gmodules"])
-@skipIf(bugnumber='rdar://96581048')
 def test_same_template_arg(self):
 lldbutil.run_to_source_breakpoint(self, "Break here", self.main_source_file)
 
@@ -51,7 +50,6 @@
 ])
 
 @add_test_categories(["gmodules"])
-@skipIf(bugnumber='rdar://96581048')
 def test_duplicate_decls(self):
 lldbutil.run_to_source_breakpoint(self, "Break here", self.main_source_file)
 
Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -4924,9 +4924,9 @@
   FooDC->getRedeclContext()->localUncachedLookup(FooName, FoundDecls);
   EXPECT_EQ(FoundDecls.size(), 0u);
 
-  // Cannot find in the LookupTable of its LexicalDC (A).
+  // Finds via linear search of its LexicalDC (A).
   FooLexicalDC->getRedeclContext()->localUncachedLookup(FooName, FoundDecls);
-  EXPECT_EQ(FoundDecls.size(), 0u);
+  EXPECT_EQ(FoundDecls.size(), 1u);
 
   // Can't find in the list of Decls of the DC.
   EXPECT_EQ(findInDeclListOfDC(FooDC, FooName), nullptr);
Index: clang/lib/AST/DeclBase.cpp
===
--- clang/lib/AST/DeclBase.cpp
+++ clang/lib/AST/DeclBase.cpp
@@ -1771,7 +1771,8 @@
   if (!hasExternalVisibleStorage() && !hasExternalLexicalStorage() && Name) {
 lookup_result LookupResults = lookup(Name);
 Results.insert(Results.end(), LookupResults.begin(), LookupResults.end());
-return;
+if (!Results.empty())
+  return;
   }
 
   // If we have a lookup table, check there first. Maybe we'll get lucky.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D133108: [clang] Rework IsTailPaddedMemberArray into isFlexibleArrayMemberExpr

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

Found a few more things while trying to convince myself this really is NFC, and 
I don't think it is. If you agree, then I think we should have some additional 
test coverage to show the behavioral changes.




Comment at: clang/lib/Sema/SemaChecking.cpp:15977
 
+  const unsigned StrictFlexArraysLevel = getLangOpts().StrictFlexArrays;
+

Missed this before, but drop the top-level `const` or remove the local and just 
use the call directly in the one place the value is needed.



Comment at: clang/lib/Sema/SemaChecking.cpp:15989
+  BaseType == nullptr ||
+  isFlexibleArrayMemberExpr(*this, BaseExpr, ND, StrictFlexArraysLevel);
   if (EffectiveType->isDependentType() ||

This seems like a functional change



Comment at: clang/lib/Sema/SemaChecking.cpp:15990-15991
+  isFlexibleArrayMemberExpr(*this, BaseExpr, ND, StrictFlexArraysLevel);
   if (EffectiveType->isDependentType() ||
-  (!IsUnboundedArray && BaseType->isDependentType()))
+  !IsUnboundedArray && BaseType->isDependentType())
 return;

I think the parens helped to add clarity here (also, there's probably a warning 
generated about mixed || and && from this too, isn't there?)



Comment at: clang/lib/Sema/SemaChecking.cpp:16004
 
-  const NamedDecl *ND = nullptr;
-  if (const DeclRefExpr *DRE = dyn_cast(BaseExpr))
-ND = DRE->getDecl();
-  if (const MemberExpr *ME = dyn_cast(BaseExpr))
-ND = ME->getMemberDecl();
-
   if (IsUnboundedArray) {
 if (EffectiveType->isFunctionType())

...because now we can get into this block...



Comment at: clang/lib/Sema/SemaChecking.cpp:16048
   // dependent CharUnits)
   DiagRuntimeBehavior(BaseExpr->getBeginLoc(), BaseExpr,
   PDiag(DiagID)

... which means we can now hit this diagnostic.


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

https://reviews.llvm.org/D133108

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


[PATCH] D134020: [clang][Interp] Handle enums

2022-09-16 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added a comment.

In D134020#3795091 , @erichkeane 
wrote:

> I can't come up with a way to get a reference to one of these, so the logic 
> in the rest of the DeclRefExpr handling is a little MORE awkward looking now. 
>  I think I'm OK with this, but I want to give a few other folks a chance to 
> look.

Ah right, I could to through that code path as well and not immediately return. 
I actually tested references but the AST expresses that through a 
`MaterializeTemporaryExpr`, which don't work yet.

In D134020#3795092 , @erichkeane 
wrote:

> Also note, the CI test is from your test!

Yup, that needs one of the other open patches.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134020

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


[PATCH] D133941: [clang][Interp] Record item types in InterpStack

2022-09-16 Thread Erich Keane via Phabricator via cfe-commits
erichkeane accepted this revision.
erichkeane added a comment.
This revision is now accepted and ready to land.

is_same_v would be an improvement, but otherwise I think this is fine.




Comment at: clang/lib/AST/Interp/InterpStack.h:140
+else if constexpr (std::is_same::value ||
+   std::is_same>::value)
+  return PT_Sint8;

Side note: Having `Integral`'s 2nd template parameter be a bool here is a bad 
design decision IMO.  It should probably be an enum, so that we can just do:

`Integral<8, Signed>` or `Integral<8, Unsigned>` kinda thing.


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

https://reviews.llvm.org/D133941

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


[PATCH] D133934: [clang][Interp] Handle sizeof() expressions

2022-09-16 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added inline comments.



Comment at: clang/lib/AST/Interp/ByteCodeExprGen.cpp:290
+
+if (!ArgType->isConstantSizeType() ||
+ArgType->isDependentType())

Documentation for `isConstantSizedType` says it isn't legal to call it on 
dependent or incomplete types.  so this probably needs to be:

``` if (ArgType->isDependentType() || ArgType->isIncompleteType() || 
!ArgType->isConstantSizedType())```

In roughly that order.


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

https://reviews.llvm.org/D133934

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


[PATCH] D111509: [clang] use getCommonSugar in an assortment of places

2022-09-16 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov updated this revision to Diff 460723.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111509

Files:
  clang-tools-extra/clangd/unittests/tweaks/ExtractVariableTests.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/narrowing-conversions-ignoreconversionfromtypes-option.cpp
  clang/lib/CodeGen/CGExprComplex.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/test/AST/ast-dump-fpfeatures.cpp
  clang/test/CodeGen/complex-math.c
  clang/test/CodeGen/compound-assign-overflow.c
  clang/test/Sema/complex-int.c
  clang/test/Sema/matrix-type-operators.c
  clang/test/Sema/nullability.c
  clang/test/Sema/sugar-common-types.c
  clang/test/SemaCXX/complex-conversion.cpp
  clang/test/SemaCXX/matrix-type-operators.cpp
  clang/test/SemaCXX/sugar-common-types.cpp
  clang/test/SemaCXX/sugared-auto.cpp
  clang/test/SemaObjC/format-strings-objc.m
  compiler-rt/test/ubsan/TestCases/Integer/add-overflow.cpp
  compiler-rt/test/ubsan/TestCases/Integer/no-recover.cpp
  compiler-rt/test/ubsan/TestCases/Integer/sub-overflow.cpp
  compiler-rt/test/ubsan/TestCases/Integer/uadd-overflow.cpp
  compiler-rt/test/ubsan/TestCases/Integer/umul-overflow.cpp
  compiler-rt/test/ubsan/TestCases/Integer/usub-overflow.cpp
  lldb/test/API/commands/expression/rdar42038760/main.c
  lldb/test/API/commands/expression/rdar44436068/main.c

Index: lldb/test/API/commands/expression/rdar44436068/main.c
===
--- lldb/test/API/commands/expression/rdar44436068/main.c
+++ lldb/test/API/commands/expression/rdar44436068/main.c
@@ -3,6 +3,6 @@
 __int128_t n = 1;
 n = n + n;
 return n; //%self.expect("p n", substrs=['(__int128_t) $0 = 2'])
-  //%self.expect("p n + 6", substrs=['(__int128) $1 = 8'])
-  //%self.expect("p n + n", substrs=['(__int128) $2 = 4'])
+  //%self.expect("p n + 6", substrs=['(__int128_t) $1 = 8'])
+  //%self.expect("p n + n", substrs=['(__int128_t) $2 = 4'])
 }
Index: lldb/test/API/commands/expression/rdar42038760/main.c
===
--- lldb/test/API/commands/expression/rdar42038760/main.c
+++ lldb/test/API/commands/expression/rdar42038760/main.c
@@ -10,7 +10,7 @@
   struct S0 l_19;
   l_19.f2 = 419;
   uint32_t l_4037 = 4294967295UL;
-  l_19.f2 = g_463; //%self.expect("expr ((l_4037 % (-(g_463))) | l_19.f2)", substrs=['(unsigned int) $0 = 358717883'])
+  l_19.f2 = g_463; //%self.expect("expr ((l_4037 % (-(g_463))) | l_19.f2)", substrs=['(uint32_t) $0 = 358717883'])
 }
 int main()
 {
Index: compiler-rt/test/ubsan/TestCases/Integer/usub-overflow.cpp
===
--- compiler-rt/test/ubsan/TestCases/Integer/usub-overflow.cpp
+++ compiler-rt/test/ubsan/TestCases/Integer/usub-overflow.cpp
@@ -12,12 +12,12 @@
 
 #ifdef SUB_I32
   (void)(uint32_t(1) - uint32_t(2));
-  // CHECK-SUB_I32: usub-overflow.cpp:[[@LINE-1]]:22: runtime error: unsigned integer overflow: 1 - 2 cannot be represented in type 'unsigned int'
+  // CHECK-SUB_I32: usub-overflow.cpp:[[@LINE-1]]:22: runtime error: unsigned integer overflow: 1 - 2 cannot be represented in type '{{uint32_t|unsigned int}}'
 #endif
 
 #ifdef SUB_I64
   (void)(uint64_t(800ll) - uint64_t(900ll));
-  // CHECK-SUB_I64: 800 - 900 cannot be represented in type 'unsigned {{long( long)?}}'
+  // CHECK-SUB_I64: 800 - 900 cannot be represented in type '{{uint64_t|unsigned long( long)?}}'
 #endif
 
 #ifdef SUB_I128
@@ -26,6 +26,6 @@
 # else
   puts("__int128 not supported\n");
 # endif
-  // CHECK-SUB_I128: {{0x4000 - 0x8000 cannot be represented in type 'unsigned __int128'|__int128 not supported}}
+  // CHECK-SUB_I128: {{0x4000 - 0x8000 cannot be represented in type '__uint128_t'|__int128 not supported}}
 #endif
 }
Index: compiler-rt/test/ubsan/TestCases/Integer/umul-overflow.cpp
===
--- compiler-rt/test/ubsan/TestCases/Integer/umul-overflow.cpp
+++ compiler-rt/test/ubsan/TestCases/Integer/umul-overflow.cpp
@@ -13,7 +13,7 @@
   (void)(uint16_t(0x) * uint16_t(0x8001));
 
   (void)(uint32_t(0x) * uint32_t(0x2));
-  // CHECK: umul-overflow.cpp:15:31: runtime error: unsigned integer overflow: 4294967295 * 2 cannot be represented in type 'unsigned int'
+  // CHECK: umul-overflow.cpp:15:31: runtime error: unsigned integer overflow: 4294967295 * 2 cannot be represented in type '{{uint32_t|unsigned int}}'
 
   return 0;
 }
Index: compiler-rt/test/ubsan/TestCases/Integer/uadd-overflow.cpp
===
--- compiler-rt/test/ubsan/T

[libunwind] c9cffdd - [libunwind] Fix usage of `_dl_find_object` on 32-bit x86

2022-09-16 Thread Adrian Vogelsgesang via cfe-commits

Author: Adrian Vogelsgesang
Date: 2022-09-16T06:29:49-07:00
New Revision: c9cffdde393f646acf62d6160e7fa6613e038508

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

LOG: [libunwind] Fix usage of `_dl_find_object` on 32-bit x86

On 32-bit x86, `_dl_find_object` also returns a `dlfo_eh_dbase` address.
So far, compiling against a version of `_dl_find_object` which returns a
`dlfo_eh_dbase` was blocked using a `#if` + `#error`. This commit now
removes this compile time assertion and simply ignores the returned
`dlfo_eh_dbase`. All test cases are passing on a 32-bit build now.

According to 
https://www.gnu.org/software/libc/manual/html_node/Dynamic-Linker-Introspection.html,
`dlfo_eh_dbase` should be the base address for all DW_EH_PE_datarel
relocations. However, glibc/elf/dl-find_object.h says that eh_dbase
is the relocated DT_PLTGOT value. I don't understand how those two
statements fit together, but to fix 32-bit x86, ignoring `dlfo_eh_dbase`
seems to be good enough.

Fixes #57733

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

Added: 


Modified: 
libunwind/src/AddressSpace.hpp

Removed: 




diff  --git a/libunwind/src/AddressSpace.hpp b/libunwind/src/AddressSpace.hpp
index 315289cd4211b..b0135b0c0519c 100644
--- a/libunwind/src/AddressSpace.hpp
+++ b/libunwind/src/AddressSpace.hpp
@@ -584,11 +584,6 @@ inline bool LocalAddressSpace::findUnwindSections(pint_t 
targetAddr,
   // support for _dl_find_object on other unwind formats is not implemented,
   // yet.
 #if defined(DLFO_STRUCT_HAS_EH_DBASE) & defined(_LIBUNWIND_SUPPORT_DWARF_INDEX)
-  // We expect to run on a platform which does not use a base address for
-  // exception information.
-#if DLFO_STRUCT_HAS_EH_DBASE
-#error dlfo_eh_dbase is not supported for DWARF-based unwinding
-#endif
   // We expect `_dl_find_object` to return PT_GNU_EH_FRAME.
 #if DLFO_EH_SEGMENT_TYPE != PT_GNU_EH_FRAME
 #error _dl_find_object retrieves an unexpected section type



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


[PATCH] D128861: [clang-tidy] add cppcoreguidelines-symmetric-binary-operator

2022-09-16 Thread Julian Schmidt via Phabricator via cfe-commits
5chmidti added a comment.

Ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128861

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


[clang] 2183fe2 - [clang-format] Parse the else part of `#if 0`

2022-09-16 Thread via cfe-commits

Author: sstwcw
Date: 2022-09-16T13:30:46Z
New Revision: 2183fe2160fbcb754893e98829f2bff4d0fccfa3

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

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

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.  In that case the outer parts would be parsed as
if nothing inside the conditional parts existed.  Now we use the second
conditional branch if the first condition is 0.

Reviewed By: owenpan

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

Added: 


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

Removed: 




diff  --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index 699d2d37c71dc..fce50d65fc364 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -1124,7 +1124,9 @@ void 
UnwrappedLineParser::conditionalCompilationStart(bool Unreachable) {
   ++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 will be parsed if there is one.
+PPLevelBranchIndex.push_back(Unreachable ? 1 : 0);
 PPLevelBranchCount.push_back(0);
   }
   PPChainBranchIndex.push(0);

diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index aae300e67f62a..8d9ccfd0cfe14 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -5993,6 +5993,16 @@ TEST_F(FormatTest, 
LayoutStatementsAroundPreprocessorDirectives) {
  ");\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) {
@@ -25367,27 +25377,12 @@ TEST_F(FormatTest, InsertBraces) {
 
   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;
 



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


[clang] e596422 - [clang-format] Fix template arguments in macros

2022-09-16 Thread via cfe-commits

Author: sstwcw
Date: 2022-09-16T13:30:46Z
New Revision: e5964223d99a119e4077e3ed1f1322fa2b8cc703

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

LOG: [clang-format] Fix template arguments in macros

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

old
```
#define FOO(typeName, realClass)   \
  {\
#typeName, foo < FooType>(new foo (#typeName))  \
  }
```
new
```
#define FOO(typeName, realClass)\
  { #typeName, foo(new foo(#typeName)) }
```

Previously, when an UnwrappedLine began with a hash in a macro
definition, the program incorrectly assumed the line was a preprocessor
directive.  It should be stringification.

The rule in spaceRequiredBefore was added in 8b5297117b.  Its purpose is
to add a space in an include directive.  It also added a space to a
template opener when the line began with a stringification hash.  So we
changed it.

Reviewed By: HazardyKnusperkeks, owenpan

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

Added: 


Modified: 
clang/lib/Format/TokenAnnotator.cpp
clang/lib/Format/TokenAnnotator.h
clang/lib/Format/UnwrappedLineParser.cpp
clang/lib/Format/UnwrappedLineParser.h
clang/unittests/Format/FormatTest.cpp
clang/unittests/Format/TokenAnnotatorTest.cpp

Removed: 




diff  --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index d7c2e66ca488..d18adc308efb 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -1427,7 +1427,7 @@ class AnnotatingParser {
 if (!CurrentToken)
   return LT_Invalid;
 NonTemplateLess.clear();
-if (CurrentToken->is(tok::hash)) {
+if (!Line.InMacroBody && CurrentToken->is(tok::hash)) {
   // We were not yet allowed to use C++17 optional when this was being
   // written. So we used LT_Invalid to mark that the line is not a
   // preprocessor directive.
@@ -4241,7 +4241,7 @@ bool TokenAnnotator::spaceRequiredBefore(const 
AnnotatedLine &Line,
 return false;
   }
   if (Right.is(tok::less) && Left.isNot(tok::l_paren) &&
-  Line.startsWith(tok::hash)) {
+  Line.Type == LT_ImportStatement) {
 return true;
   }
   if (Right.is(TT_TrailingUnaryOperator))

diff  --git a/clang/lib/Format/TokenAnnotator.h 
b/clang/lib/Format/TokenAnnotator.h
index 028ff6d2ccb2..b6f086d76728 100644
--- a/clang/lib/Format/TokenAnnotator.h
+++ b/clang/lib/Format/TokenAnnotator.h
@@ -40,7 +40,7 @@ class AnnotatedLine {
   : First(Line.Tokens.front().Tok), Level(Line.Level),
 MatchingOpeningBlockLineIndex(Line.MatchingOpeningBlockLineIndex),
 MatchingClosingBlockLineIndex(Line.MatchingClosingBlockLineIndex),
-InPPDirective(Line.InPPDirective),
+InPPDirective(Line.InPPDirective), InMacroBody(Line.InMacroBody),
 MustBeDeclaration(Line.MustBeDeclaration), MightBeFunctionDecl(false),
 IsMultiVariableDeclStmt(false), Affected(false),
 LeadingEmptyLinesAffected(false), ChildrenAffected(false),
@@ -130,6 +130,7 @@ class AnnotatedLine {
   size_t MatchingOpeningBlockLineIndex;
   size_t MatchingClosingBlockLineIndex;
   bool InPPDirective;
+  bool InMacroBody;
   bool MustBeDeclaration;
   bool MightBeFunctionDecl;
   bool IsMultiVariableDeclStmt;

diff  --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index fce50d65fc36..4fd4fd4f7c27 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -116,12 +116,14 @@ class ScopedMacroState : public FormatTokenSource {
 TokenSource = this;
 Line.Level = 0;
 Line.InPPDirective = true;
+// InMacroBody gets set after the `#define x` part.
   }
 
   ~ScopedMacroState() override {
 TokenSource = PreviousTokenSource;
 ResetToken = Token;
 Line.InPPDirective = false;
+Line.InMacroBody = false;
 Line.Level = PreviousLineLevel;
   }
 
@@ -196,6 +198,7 @@ class ScopedLineState {
 Parser.Line = std::make_unique();
 Parser.Line->Level = PreBlockLine->Level;
 Parser.Line->InPPDirective = PreBlockLine->InPPDirective;
+Parser.Line->InMacroBody = PreBlockLine->InMacroBody;
   }
 
   ~ScopedLineState() {
@@ -1253,6 +1256,7 @@ void UnwrappedLineParser::parsePPDefine() {
 Line->Level += PPBranchLevel + 1;
   addUnwrappedLine();
   ++Line->Level;
+  Line->InMacroBody = true;
 
   // Errors during a preprocessor directive can only affect the layout of the
   // preprocessor directive, and thus we ignore them. An alternative approach

diff  --git a/clang/lib/Format/UnwrappedLineParser.h 
b/clang/lib/Format/UnwrappedLineParser.h
index 7d6c84ecfb0d..ce51d17d5f9c 100644
--- a/c

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

2022-09-16 Thread sstwcw via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG2183fe2160fb: [clang-format] Parse the else part of `#if 0` 
(authored by sstwcw).

Changed prior to commit:
  https://reviews.llvm.org/D133647?vs=459305&id=460729#toc

Repository:
  rG LLVM Github Monorepo

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

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) {
@@ -25367,27 +25377,12 @@
 
   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;
 
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 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) {
@@ -25367,27 +25377,12 @@
 
   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;
 
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 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] D133954: [clang-format] Fix template arguments in macros

2022-09-16 Thread sstwcw via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe5964223d99a: [clang-format] Fix template arguments in 
macros (authored by sstwcw).

Changed prior to commit:
  https://reviews.llvm.org/D133954?vs=460446&id=460730#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133954

Files:
  clang/lib/Format/TokenAnnotator.cpp
  clang/lib/Format/TokenAnnotator.h
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/lib/Format/UnwrappedLineParser.h
  clang/unittests/Format/FormatTest.cpp
  clang/unittests/Format/TokenAnnotatorTest.cpp

Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -284,6 +284,17 @@
   EXPECT_TOKEN(Tokens[13], tok::ampamp, TT_BinaryOperator);
 }
 
+TEST_F(TokenAnnotatorTest, UnderstandsTemplatesInMacros) {
+  auto Tokens =
+  annotate("#define FOO(typeName) \\\n"
+   "  { #typeName, foo(new foo(#typeName)) }");
+  ASSERT_EQ(Tokens.size(), 27u) << Tokens;
+  EXPECT_TOKEN(Tokens[11], tok::less, TT_TemplateOpener);
+  EXPECT_TOKEN(Tokens[13], tok::greater, TT_TemplateCloser);
+  EXPECT_TOKEN(Tokens[17], tok::less, TT_TemplateOpener);
+  EXPECT_TOKEN(Tokens[19], tok::greater, TT_TemplateCloser);
+}
+
 TEST_F(TokenAnnotatorTest, UnderstandsWhitespaceSensitiveMacros) {
   FormatStyle Style = getLLVMStyle();
   Style.WhitespaceSensitiveMacros.push_back("FOO");
Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -9864,6 +9864,10 @@
   verifyFormat("Constructor(A... a) : a_(X{std::forward(a)}...) {}");
   verifyFormat("< < < < < < < < < < < < < < < < < < < < < < < < < < < < < <");
   verifyFormat("some_templated_type");
+
+  verifyFormat("#define FOO(typeName, realClass)   \\\n"
+   "  { #typeName, foo(new foo(#typeName)) }",
+   getLLVMStyleWithColumns(60));
 }
 
 TEST_F(FormatTest, UnderstandsShiftOperators) {
Index: clang/lib/Format/UnwrappedLineParser.h
===
--- clang/lib/Format/UnwrappedLineParser.h
+++ clang/lib/Format/UnwrappedLineParser.h
@@ -46,6 +46,8 @@
 
   /// Whether this \c UnwrappedLine is part of a preprocessor directive.
   bool InPPDirective;
+  /// Whether it is part of a macro body.
+  bool InMacroBody;
 
   bool MustBeDeclaration;
 
@@ -353,8 +355,8 @@
 };
 
 inline UnwrappedLine::UnwrappedLine()
-: Level(0), InPPDirective(false), MustBeDeclaration(false),
-  MatchingOpeningBlockLineIndex(kInvalidIndex) {}
+: Level(0), InPPDirective(false), InMacroBody(false),
+  MustBeDeclaration(false), MatchingOpeningBlockLineIndex(kInvalidIndex) {}
 
 } // end namespace format
 } // end namespace clang
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -116,12 +116,14 @@
 TokenSource = this;
 Line.Level = 0;
 Line.InPPDirective = true;
+// InMacroBody gets set after the `#define x` part.
   }
 
   ~ScopedMacroState() override {
 TokenSource = PreviousTokenSource;
 ResetToken = Token;
 Line.InPPDirective = false;
+Line.InMacroBody = false;
 Line.Level = PreviousLineLevel;
   }
 
@@ -196,6 +198,7 @@
 Parser.Line = std::make_unique();
 Parser.Line->Level = PreBlockLine->Level;
 Parser.Line->InPPDirective = PreBlockLine->InPPDirective;
+Parser.Line->InMacroBody = PreBlockLine->InMacroBody;
   }
 
   ~ScopedLineState() {
@@ -1253,6 +1256,7 @@
 Line->Level += PPBranchLevel + 1;
   addUnwrappedLine();
   ++Line->Level;
+  Line->InMacroBody = true;
 
   // Errors during a preprocessor directive can only affect the layout of the
   // preprocessor directive, and thus we ignore them. An alternative approach
Index: clang/lib/Format/TokenAnnotator.h
===
--- clang/lib/Format/TokenAnnotator.h
+++ clang/lib/Format/TokenAnnotator.h
@@ -40,7 +40,7 @@
   : First(Line.Tokens.front().Tok), Level(Line.Level),
 MatchingOpeningBlockLineIndex(Line.MatchingOpeningBlockLineIndex),
 MatchingClosingBlockLineIndex(Line.MatchingClosingBlockLineIndex),
-InPPDirective(Line.InPPDirective),
+InPPDirective(Line.InPPDirective), InMacroBody(Line.InMacroBody),
 MustBeDeclaration(Line.MustBeDeclaration), MightBeFunctionDecl(false),
 IsMultiVariableDeclStmt(false), Affected(false),
 LeadingEmptyLinesAffected(false), ChildrenAffected(false),
@@ -130,6 +130,7 @@
   size_t MatchingOpeningBlockLineIndex;
   size_t MatchingClosin

[PATCH] D133934: [clang][Interp] Handle sizeof() expressions

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

In D133934#3794389 , @tbaeder wrote:

> I can see that `HandleSizeOf()` uses 1 for void and function types as a gcc 
> extension, but I can't reproduce that: https://godbolt.org/z/njG9zh6PM

C code allows the construct: https://godbolt.org/z/5KfY9PPqa

Worth keeping in mind: C2x has support for `constexpr` objects, so we are going 
to have to care about this. We've not started doing the work to enable 
`constexpr` for C yet, so there's some wiggle room in terms of *when* we have 
to care, but we should try to keep C in mind when working on the new 
interpreter as much as is reasonable.




Comment at: clang/lib/AST/Interp/Boolean.h:50
 
   explicit operator unsigned() const { return V; }
+  explicit operator int8_t() const { return V; }

At some point, do we want to rename this (and int) to use uint32_t/int32_t?



Comment at: clang/lib/AST/Interp/ByteCodeExprGen.cpp:290
+return this->emitConst(
+E, Ctx.getASTContext().getTypeSizeInChars(ArgType).getQuantity());
+  }

tbaeder wrote:
> shafik wrote:
> > aaron.ballman wrote:
> > > erichkeane wrote:
> > > > shafik wrote:
> > > > > I notice that `HandleSizeof` special cases `void` and function types. 
> > > > OOOH, DEFINITELY make sure you test function types here, and figure out 
> > > > how HandleSizeof does it.
> > > > 
> > > > BUT, I think 'void' should error/be an invalid before we get here?
> > > > 
> > > > ALSO, now that I think further, I'm sure @aaron.ballman has a bunch of 
> > > > runtime-evaluated sizeof examples to share around vlas.
> > > I was just about to comment about everyone's favorite horrible C++ 
> > > extension. :-D We should make sure we properly reject code like:
> > > ```
> > > void func() {
> > >   int n = 12;
> > >   constexpr int oofda = sizeof(int[n++]);
> > > }
> > > ```
> > > while accepting code like:
> > > ```
> > > consteval int foo(int n) {
> > >   return sizeof(int[n]);
> > > }
> > > constinit int var = foo(5);
> > > ```
> > Note, that clang currently treats that as ill-formed and there is 
> > divergence with how gcc and clang treat the `constexpr` case as well.
> > 
> > So if we are going to say we want this to work then we should file a bug 
> > against clang. 
> Right, the second example doesn't seem to be accepted by current clang.
I'd add both of the test cases, put a FIXME comment above the one that 
currently fails but we'd like to see succeed. We can work on fixing that fixme 
whenever we get around to it.



Comment at: clang/test/AST/Interp/literals.cpp:89
+  static_assert(sizeof(&soint) == sizeof(void*), "");
+  static_assert(sizeof(&soint) == sizeof(nullptr), "");
+

This test got me thinking about another test case:
```
struct S {
  void func();
};

constexpr void (S::*Func)() = &S::func;
static_assert(sizeof(Func) == sizeof(&S::func), "");
```
(Can't test this one against `nullptr` because `sizeof(nullptr)` is not telling 
you the size of a pointer to member function despite `nullptr` being 
convertible to one.)


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

https://reviews.llvm.org/D133934

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


[PATCH] D134042: [clang-format] Fix alignment in #else preprocessor blocks

2022-09-16 Thread Mitchell via Phabricator via cfe-commits
mitchell-stellar created this revision.
mitchell-stellar added reviewers: HazardyKnusperkeks, curdeius, MyDeveloperDay.
mitchell-stellar added a project: clang-format.
Herald added a project: All.
mitchell-stellar requested review of this revision.
Herald added a project: clang.

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

clang-format makes multiple passes when #if/#else preprocessor blocks are 
found. It will make one pass for normal code and code in the #if block, and 
then it will make another pass for just the code in #else blocks. This often 
results in invalid alignment inside the else blocks because they do not have 
any scope or indentAndNestingLevel context from their surrounding tokens/lines.

This patch remedies that by caching any initial indentAndNestingLevel from a 
second pass and not breaking/returning early when a scope change is detected.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D134042

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

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -5743,6 +5743,139 @@
Style);
 }
 
+TEST_F(FormatTest, FormatAlignInsidePreprocessorElseBlock) {
+  FormatStyle Style = getLLVMStyleWithColumns(40);
+  Style.AlignConsecutiveAssignments.Enabled = true;
+  Style.AlignConsecutiveDeclarations.Enabled = true;
+
+  // Test with just #if blocks.
+  {
+const char *Expected = "void f1() {\n"
+   "#if 1\n"
+   "  int foo= 1;\n"
+   "  int foobar = 2;\n"
+   "#endif\n"
+   "}\n"
+   "\n"
+   "#if 1\n"
+   "int baz = 3;\n"
+   "#endif\n"
+   "\n"
+   "void f2() {\n"
+   "#if 1\n"
+   "  char *foobarbaz = \"foobarbaz\";\n"
+   "  int   quux  = 4;\n"
+   "}";
+const char *ToFormat = "void f1() {\n"
+   "#if 1\n"
+   "  int foo = 1;\n"
+   "  int foobar = 2;\n"
+   "#endif\n"
+   "}\n"
+   "\n"
+   "#if 1\n"
+   "int baz = 3;\n"
+   "#endif\n"
+   "\n"
+   "void f2() {\n"
+   "#if 1\n"
+   "  char *foobarbaz = \"foobarbaz\";\n"
+   "  int quux = 4;\n"
+   "}";
+EXPECT_EQ(Expected, format(ToFormat, Style));
+EXPECT_EQ(Expected, format(Expected, Style));
+  }
+
+  // Test with just #else blocks.
+  {
+const char *Expected = "void f1() {\n"
+   "#if 1\n"
+   "#else\n"
+   "  int foo= 1;\n"
+   "  int foobar = 2;\n"
+   "#endif\n"
+   "}\n"
+   "\n"
+   "#if 1\n"
+   "#else\n"
+   "int baz = 3;\n"
+   "#endif\n"
+   "\n"
+   "void f2() {\n"
+   "#if 1\n"
+   "#else\n"
+   "  char *foobarbaz = \"foobarbaz\";\n"
+   "  int   quux  = 4;\n"
+   "}";
+const char *ToFormat = "void f1() {\n"
+   "#if 1\n"
+   "#else\n"
+   "  int foo = 1;\n"
+   "  int foobar = 2;\n"
+   "#endif\n"
+   "}\n"
+   "\n"
+   "#if 1\n"
+   "#else\n"
+   "int baz = 3;\n"
+   "#endif\n"
+   "\n"
+   "void f2() {\n"
+   "#if 1\n"
+   "#else\n"
+   "  char *foobarbaz = \"foobarbaz\";\n"
+   "  int quux = 4;\n"
+   "}";
+EXPECT_EQ(Expected, format(ToFormat, Style));
+EXPECT_EQ(Expected, format(Expected, Style));
+  }
+
+  // Test with a mix of #if and #else blocks.
+  {
+const char *Expected = "void f1() {\n"
+   "#if 1\n"
+   "#else\n"
+   "  int foo= 1;\n"
+   "  in

[PATCH] D133711: [Sema] Reject array element types whose sizes aren't a multiple of their alignments

2022-09-16 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak updated this revision to Diff 460735.
ahatanak added a comment.

- Fix failing CodeGen test.
- Add release note to the Potentially Breaking Changes section.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133711

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/CodeGenCXX/override-layout-packed-base.cpp
  clang/test/CodeGenCXX/ubsan-new-checks.cpp
  clang/test/Layout/ms-aligned-array.c
  clang/test/Layout/ms-x86-misalignedarray.cpp
  clang/test/Sema/align-x86-64.c
  clang/test/Sema/align-x86.c
  clang/test/Sema/attr-aligned.c
  clang/test/SemaCXX/align-x86.cpp
  clang/test/SemaCXX/array-alignment.cpp
  clang/test/SemaCXX/warn-new-overaligned.cpp

Index: clang/test/SemaCXX/warn-new-overaligned.cpp
===
--- clang/test/SemaCXX/warn-new-overaligned.cpp
+++ clang/test/SemaCXX/warn-new-overaligned.cpp
@@ -19,9 +19,13 @@
 }
 
 namespace test2 {
+struct S {
+  char c[256];
+};
+
 class Test {
-  typedef int __attribute__((aligned(256))) aligned_int;
-  aligned_int high_contention_data[10];
+  typedef S __attribute__((aligned(256))) alignedS;
+  alignedS high_contention_data[10];
 };
 
 void helper() {
Index: clang/test/SemaCXX/array-alignment.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/array-alignment.cpp
@@ -0,0 +1,36 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+typedef char __attribute__((aligned(2))) AlignedChar;
+typedef AlignedChar arrayType0[4]; // expected-error {{size of array element}}
+
+struct __attribute__((aligned(8))) AlignedStruct {
+  int m0;
+};
+
+struct __attribute__((packed)) PackedStruct {
+  char m0;
+  int i0;
+};
+
+typedef PackedStruct AlignedPackedStruct __attribute__((aligned(4)));
+typedef AlignedPackedStruct arrayType1[4]; // expected-error {{(5 bytes) isn't a multiple of its alignment (4 bytes)}}
+
+AlignedChar a0[1]; // expected-error {{size of array element}}
+AlignedStruct a1[1];
+AlignedPackedStruct a2[1]; // expected-error {{size of array element}}
+
+struct S {
+  AlignedChar m0[1]; // expected-error {{size of array element}}
+  AlignedStruct m1[1];
+  AlignedPackedStruct m2[1]; // expected-error {{size of array element}}
+};
+
+void test(char *p) {
+  auto p0 = (AlignedChar(*)[1])p;// expected-error {{size of array element}}
+  auto r0 = (AlignedChar(&)[1])(*p); // expected-error {{size of array element}}
+  auto p1 = new AlignedChar[1];  // expected-error {{size of array element}}
+  auto p2 = (AlignedStruct(*)[1])p;
+  auto p3 = new AlignedStruct[1];
+  auto p4 = (AlignedPackedStruct(*)[1])p; // expected-error {{size of array element}}
+  auto p5 = new AlignedPackedStruct[1]; // expected-error {{size of array element}}
+}
Index: clang/test/SemaCXX/align-x86.cpp
===
--- clang/test/SemaCXX/align-x86.cpp
+++ clang/test/SemaCXX/align-x86.cpp
@@ -1,5 +1,4 @@
 // RUN: %clang_cc1 -std=c++11 -triple i386-apple-darwin9 -fsyntax-only -verify %s
-// expected-no-diagnostics
 
 using size_t = decltype(sizeof(0));
 
@@ -46,10 +45,10 @@
 } aligned_before_struct;
 
 static_assert(sizeof(aligned_before_struct)   == 3, "");
-static_assert(sizeof(aligned_before_struct[1])== 4, "");
-static_assert(sizeof(aligned_before_struct[2])== 6, "");
-static_assert(sizeof(aligned_before_struct[2][1]) == 8, "");
-static_assert(sizeof(aligned_before_struct[1][2]) == 6, "");
+static_assert(sizeof(aligned_before_struct[1])== 4, ""); // expected-error {{size of array element}}
+static_assert(sizeof(aligned_before_struct[2])== 6, ""); // expected-error {{size of array element}}
+static_assert(sizeof(aligned_before_struct[2][1]) == 8, ""); // expected-error {{size of array element}}
+static_assert(sizeof(aligned_before_struct[1][2]) == 6, ""); // expected-error {{size of array element}}
 
 typedef struct ALIGNED(2) {
   char a[3];
Index: clang/test/Sema/attr-aligned.c
===
--- clang/test/Sema/attr-aligned.c
+++ clang/test/Sema/attr-aligned.c
@@ -49,13 +49,14 @@
 char e1[__alignof__(e) == 2 ?: -1] = {0};
 char e2[__alignof__(e.member) == 2 ?: -1] = {0};
 
-typedef char overaligned_char __attribute__((aligned(16)));
-typedef overaligned_char array_with_overaligned_char[11];
+typedef struct { char c[16]; } S;
+typedef S overaligned_struct __attribute__((aligned(16)));
+typedef overaligned_struct array_with_overaligned_struct[11];
 typedef char array_with_align_attr[11] __attribute__((aligned(16)));
 
-char f0[__alignof__(array_with_overaligned_char) == 16 ? 1 : -1] = { 0 };
+char f0[__alignof__(array_with_overaligned_struct) == 16 ? 1 : -1] = { 0 };
 char f1[__alignof__(array_with_align_attr) 

[PATCH] D133737: [HLSL] [clang] Add vector version of abs for HLSL

2022-09-16 Thread Florian Hahn via Phabricator via cfe-commits
fhahn added a comment.

In D133737#3787066 , @RKSimon wrote:

> The elementwise builtins should work for scalars as well (and IIRC we do test 
> this as well).

Yep they should, it is specially specified here: 
https://clang.llvm.org/docs/LanguageExtensions.html#vector-builtins

> For scalar types, consider the operation applied to a vector with a single 
> element.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133737

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


[PATCH] D133956: Cuda Check for ignored errors after calling a CUDA kernel

2022-09-16 Thread Bartłomiej Cieślar via Phabricator via cfe-commits
barcisz updated this revision to Diff 460743.
barcisz added a comment.
Herald added a subscriber: aheejin.

documentation for the check


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133956

Files:
  .clang-tidy
  clang-tools-extra/clang-tidy/cuda/CMakeLists.txt
  clang-tools-extra/clang-tidy/cuda/CudaTidyModule.cpp
  clang-tools-extra/clang-tidy/cuda/UnsafeKernelCallCheck.cpp
  clang-tools-extra/clang-tidy/cuda/UnsafeKernelCallCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/cuda/unsafe-kernel-call.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/cuda/cuda_runtime.h
  
clang-tools-extra/test/clang-tidy/checkers/cuda/unsafe-kernel-call-function-handler.cu
  
clang-tools-extra/test/clang-tidy/checkers/cuda/unsafe-kernel-call-macro-handler.cu
  test.cu

Index: test.cu
===
--- /dev/null
+++ test.cu
@@ -0,0 +1,8 @@
+#include "clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/cuda/cuda_runtime.h"
+
+__global__
+void kernel();
+
+void foo() {
+  kernel<<<64, 128>>>();
+}
Index: clang-tools-extra/test/clang-tidy/checkers/cuda/unsafe-kernel-call-macro-handler.cu
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/cuda/unsafe-kernel-call-macro-handler.cu
@@ -0,0 +1,116 @@
+// RUN: %check_clang_tidy %s cuda-unsafe-kernel-call %t -- \
+// RUN:   -config="{CheckOptions: \
+// RUN: [{key: cuda-unsafe-kernel-call.HandlerName, \
+// RUN:   value: 'CUDA_CHECK_KERNEL'}, \
+// RUN:   {key: cuda-unsafe-kernel-call.AcceptedHandlers, \
+// RUN:value: 'ALTERNATIVE_CUDA_CHECK_KERNEL, cudaCheckKernel, \
+// RUN:alternative::alternativeCudaCheckKernel, \
+// RUN:otherAlternativeCudaCheckKernel'}] \
+// RUN: }" \
+// RUN:   -- -isystem %clang_tidy_headers
+
+#include 
+
+#define CUDA_CHECK_KERNEL() do {} while(0)
+
+#define ALTERNATIVE_CUDA_CHECK_KERNEL() CUDA_CHECK_KERNEL()
+
+void cudaCheckKernel();
+
+namespace alternative {
+
+void alternativeCudaCheckKernel();
+void otherAlternativeCudaCheckKernel();
+
+}
+
+__global__
+void b();
+
+#define KERNEL_CALL() do {b<<<1, 2>>>();} while(0)
+
+void errorCheck() {
+  auto err = cudaGetLastError();
+}
+
+void bad() {
+  b<<<1, 2>>>(); // sample comment
+  // CHECK-MESSAGES: :[[@LINE-1]]:{{[0-9]+}}: warning: Possible unchecked error after a kernel launch.
+
+  KERNEL_CALL(); // sample comment
+  // CHECK-MESSAGES: :[[@LINE-1]]:{{[0-9]+}}: warning: Possible unchecked error after a kernel launch.
+  // There isn't supposed to be a fix here since it's a macro call
+
+  if(true)
+b<<<1, 2>>>()  ; // Brackets omitted purposefully, since they create an additional AST node
+// CHECK-MESSAGES: :[[@LINE-1]]:{{[0-9]+}}: warning: Possible unchecked error after a kernel launch.
+  else {
+b<<<1, 2>>>();
+// CHECK-MESSAGES: :[[@LINE-1]]:{{[0-9]+}}: warning: Possible unchecked error after a kernel launch.
+b<<<1, 2>>>();
+// CHECK-MESSAGES: :[[@LINE-1]]:{{[0-9]+}}: warning: Possible unchecked error after a kernel launch.
+  }
+  auto err = cudaGetLastError();
+
+  b<<<1, 2>>>();
+  // CHECK-MESSAGES: :[[@LINE-1]]:{{[0-9]+}}: warning: Possible unchecked error after a kernel launch.
+  if (true)
+cudaGetLastError();
+
+  b<<<1, 2>>>();
+  // CHECK-MESSAGES: :[[@LINE-1]]:{{[0-9]+}}: warning: Possible unchecked error after a kernel launch.
+  for(;;)
+auto err2 = cudaGetLastError(); // Brackets omitted purposefully, since they create an additional AST node
+
+  b<<<1, 2>>>();
+  // CHECK-MESSAGES: :[[@LINE-1]]:{{[0-9]+}}: warning: Possible unchecked error after a kernel launch.
+  auto err3 = true ? 1 : cudaGetLastError();
+
+  b<<<1, 2>>>();
+  // CHECK-MESSAGES: :[[@LINE-1]]:{{[0-9]+}}: warning: Possible unchecked error after a kernel launch.
+  auto err4 = cudaDeviceReset() + cudaGetLastError();
+
+  b<<<1, 2>>>();
+  // CHECK-MESSAGES: :[[@LINE-1]]:{{[0-9]+}}: warning: Possible unchecked error after a kernel launch.
+  // Calling an error-checking function after a kernel is not considered safe.
+  errorCheck();
+}
+
+void good() {
+  b<<<1, 2>>>();; /* The semicolons are here because the
+detection of the macro is done with a lexer */ ;
+  CUDA_CHECK_KERNEL();
+
+  b<<<1, 2>>>();
+  ALTERNATIVE_CUDA_CHECK_KERNEL();
+
+  b<<<1, 2>>>();
+  alternative::alternativeCudaCheckKernel();
+
+  b<<<1, 2>>>();
+  alternative::otherAlternativeCudaCheckKernel();
+
+  b<<<1, 2>>>();
+  switch(1 + cudaGetLastError()) {
+default:;
+  }
+
+  b<<<1, 2>>>();
+  if(3 < cudaGetLastError()) {
+1;
+  } else {
+2;
+  }
+
+  b<<<1, 2>>>();
+  for(int i = cudaGetLastError();;);
+
+  b<<<1, 2>>>();
+  do {
+  do {
+  do {
+aut

[PATCH] D134046: [OpenMP] Add support for order(concurrent) to OMPIRBuilder for SIMD directive

2022-09-16 Thread Dominik Adamski via Phabricator via cfe-commits
domada created this revision.
domada added reviewers: kiranchandramohan, kiranktp.
domada added a project: OpenMP.
Herald added subscribers: bzcheeseman, awarzynski, sdasgup3, wenzhicui, wrengr, 
cota, teijeong, rdzhabarov, tatianashp, msifontes, jurahul, Kayjukh, grosul1, 
Joonsoo, liufengdb, aartbik, mgester, arpith-jacob, antiagainst, shauheen, 
rriddle, mehdi_amini, guansong, hiraditya, yaxunl.
Herald added a reviewer: ftynse.
Herald added a project: All.
domada requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added a reviewer: nicolasvasilache.
Herald added subscribers: llvm-commits, cfe-commits, pcwang-thead, sstefan1, 
stephenneuendorffer, nicolasvasilache.
Herald added a reviewer: dcaballe.
Herald added projects: clang, MLIR, LLVM.

If `order(concurrent)` clause is specified, then the iterations of SIMD loop 
can be executed concurrently.

This patch adds support for LLVM IR codegen via OMPIRBuilder for SIMD loop with 
`order(concurrent)` clause. The functionality added to OMPIRBuilder is similar 
to the functionality implemented in `CodeGenFunction::EmitOMPSimdInit`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D134046

Files:
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/test/OpenMP/irbuilder_safelen_order_concurrent.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
  llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
  mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp

Index: mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
===
--- mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
+++ mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
@@ -998,7 +998,8 @@
   ompBuilder->applySimd(
   loopInfo,
   loop.if_expr() ? moduleTranslation.lookupValue(loop.if_expr()) : nullptr,
-  simdlen, safelen);
+  llvm::OpenMPIRBuilder::OMPOrderClauseValue::NotSpecified, simdlen,
+  safelen);
 
   builder.restoreIP(afterIP);
   return success();
Index: llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
===
--- llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
+++ llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
@@ -1771,7 +1771,9 @@
   CanonicalLoopInfo *CLI = buildSingleLoopFunction(DL, OMPBuilder, 32);
 
   // Simd-ize the loop.
-  OMPBuilder.applySimd(CLI, /* IfCond */ nullptr, /* Simdlen */ nullptr,
+  OMPBuilder.applySimd(CLI, /* IfCond */ nullptr,
+   OpenMPIRBuilder::OMPOrderClauseValue::NotSpecified,
+   /* Simdlen */ nullptr,
/* Safelen */ nullptr);
 
   OMPBuilder.finalize();
@@ -1804,6 +1806,7 @@
 
   // Simd-ize the loop.
   OMPBuilder.applySimd(CLI, /* IfCond */ nullptr,
+   OpenMPIRBuilder::OMPOrderClauseValue::NotSpecified,
ConstantInt::get(Type::getInt32Ty(Ctx), 3),
/* Safelen */ nullptr);
 
@@ -1831,6 +1834,43 @@
   }));
 }
 
+TEST_F(OpenMPIRBuilderTest, ApplySafelenOrderConcurrent) {
+  OpenMPIRBuilder OMPBuilder(*M);
+
+  CanonicalLoopInfo *CLI = buildSingleLoopFunction(DL, OMPBuilder, 32);
+
+  // Simd-ize the loop.
+  OMPBuilder.applySimd(CLI, /* IfCond */ nullptr,
+   OpenMPIRBuilder::OMPOrderClauseValue::Concurrent,
+   /* Simdlen */ nullptr,
+   ConstantInt::get(Type::getInt32Ty(Ctx), 3));
+
+  OMPBuilder.finalize();
+  EXPECT_FALSE(verifyModule(*M, &errs()));
+
+  PassBuilder PB;
+  FunctionAnalysisManager FAM;
+  PB.registerFunctionAnalyses(FAM);
+  LoopInfo &LI = FAM.getResult(*F);
+
+  const std::vector &TopLvl = LI.getTopLevelLoops();
+  EXPECT_EQ(TopLvl.size(), 1u);
+
+  Loop *L = TopLvl.front();
+  // Parallel metadata shoudl be attached because of presence of
+  // the order(concurrent) OpenMP clause
+  EXPECT_TRUE(findStringMetadataForLoop(L, "llvm.loop.parallel_accesses"));
+  EXPECT_TRUE(getBooleanLoopAttribute(L, "llvm.loop.vectorize.enable"));
+  EXPECT_EQ(getIntLoopAttribute(L, "llvm.loop.vectorize.width"), 3);
+
+  // Check for llvm.access.group metadata attached to the printf
+  // function in the loop body.
+  BasicBlock *LoopBody = CLI->getBody();
+  EXPECT_TRUE(any_of(*LoopBody, [](Instruction &I) {
+return I.getMetadata("llvm.access.group") != nullptr;
+  }));
+}
+
 TEST_F(OpenMPIRBuilderTest, ApplySafelen) {
   OpenMPIRBuilder OMPBuilder(*M);
 
@@ -1838,6 +1878,7 @@
 
   // Simd-ize the loop.
   OMPBuilder.applySimd(CLI, /* IfCond */ nullptr,
+   OpenMPIRBuilder::OMPOrderClauseValue::NotSpecified,
/* Simdlen */ nullptr,
ConstantInt::get(Type::getInt32Ty(Ctx), 3));
 
@@ -1872,6 +1913,7 @@
 
   // Simd-ize the loop.
   OMPBuilder.applySimd(CLI, /* IfCond */ nullptr,
+   OpenMPIRBuilder::OMPOrd

[PATCH] D133934: [clang][Interp] Handle sizeof() expressions

2022-09-16 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder marked an inline comment as done.
tbaeder added inline comments.



Comment at: clang/lib/AST/Interp/ByteCodeExprGen.cpp:290
+
+if (!ArgType->isConstantSizeType() ||
+ArgType->isDependentType())

erichkeane wrote:
> Documentation for `isConstantSizedType` says it isn't legal to call it on 
> dependent or incomplete types.  so this probably needs to be:
> 
> ``` if (ArgType->isDependentType() || ArgType->isIncompleteType() || 
> !ArgType->isConstantSizedType())```
> 
> In roughly that order.
`isDependentType()` is implicitly assumed, isn't it? `ExprConstant.cpp` asserts 
everywhere that neither types nor expressions are (value)dependent. It also 
doesn't handle that in `HandleSizeof`.



Comment at: clang/test/AST/Interp/literals.cpp:89
+  static_assert(sizeof(&soint) == sizeof(void*), "");
+  static_assert(sizeof(&soint) == sizeof(nullptr), "");
+

aaron.ballman wrote:
> This test got me thinking about another test case:
> ```
> struct S {
>   void func();
> };
> 
> constexpr void (S::*Func)() = &S::func;
> static_assert(sizeof(Func) == sizeof(&S::func), "");
> ```
> (Can't test this one against `nullptr` because `sizeof(nullptr)` is not 
> telling you the size of a pointer to member function despite `nullptr` being 
> convertible to one.)
I'll add it, but might have to `#if 0` it out for the same reason I had to push 
https://reviews.llvm.org/rGa8843643cd75d0e93ebcf3f30b470d2b8e59868d


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

https://reviews.llvm.org/D133934

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


[PATCH] D111509: [clang] use getCommonSugar in an assortment of places

2022-09-16 Thread Matheus Izvekov via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG67e229831154: [clang] use getCommonSugar in an assortment of 
places (authored by mizvekov).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111509

Files:
  clang-tools-extra/clangd/unittests/tweaks/ExtractVariableTests.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/narrowing-conversions-ignoreconversionfromtypes-option.cpp
  clang/lib/CodeGen/CGExprComplex.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/test/AST/ast-dump-fpfeatures.cpp
  clang/test/CodeGen/complex-math.c
  clang/test/CodeGen/compound-assign-overflow.c
  clang/test/Sema/complex-int.c
  clang/test/Sema/matrix-type-operators.c
  clang/test/Sema/nullability.c
  clang/test/Sema/sugar-common-types.c
  clang/test/SemaCXX/complex-conversion.cpp
  clang/test/SemaCXX/matrix-type-operators.cpp
  clang/test/SemaCXX/sugar-common-types.cpp
  clang/test/SemaCXX/sugared-auto.cpp
  clang/test/SemaObjC/format-strings-objc.m
  compiler-rt/test/ubsan/TestCases/Integer/add-overflow.cpp
  compiler-rt/test/ubsan/TestCases/Integer/no-recover.cpp
  compiler-rt/test/ubsan/TestCases/Integer/sub-overflow.cpp
  compiler-rt/test/ubsan/TestCases/Integer/uadd-overflow.cpp
  compiler-rt/test/ubsan/TestCases/Integer/umul-overflow.cpp
  compiler-rt/test/ubsan/TestCases/Integer/usub-overflow.cpp
  lldb/test/API/commands/expression/rdar42038760/main.c
  lldb/test/API/commands/expression/rdar44436068/main.c

Index: lldb/test/API/commands/expression/rdar44436068/main.c
===
--- lldb/test/API/commands/expression/rdar44436068/main.c
+++ lldb/test/API/commands/expression/rdar44436068/main.c
@@ -3,6 +3,6 @@
 __int128_t n = 1;
 n = n + n;
 return n; //%self.expect("p n", substrs=['(__int128_t) $0 = 2'])
-  //%self.expect("p n + 6", substrs=['(__int128) $1 = 8'])
-  //%self.expect("p n + n", substrs=['(__int128) $2 = 4'])
+  //%self.expect("p n + 6", substrs=['(__int128_t) $1 = 8'])
+  //%self.expect("p n + n", substrs=['(__int128_t) $2 = 4'])
 }
Index: lldb/test/API/commands/expression/rdar42038760/main.c
===
--- lldb/test/API/commands/expression/rdar42038760/main.c
+++ lldb/test/API/commands/expression/rdar42038760/main.c
@@ -10,7 +10,7 @@
   struct S0 l_19;
   l_19.f2 = 419;
   uint32_t l_4037 = 4294967295UL;
-  l_19.f2 = g_463; //%self.expect("expr ((l_4037 % (-(g_463))) | l_19.f2)", substrs=['(unsigned int) $0 = 358717883'])
+  l_19.f2 = g_463; //%self.expect("expr ((l_4037 % (-(g_463))) | l_19.f2)", substrs=['(uint32_t) $0 = 358717883'])
 }
 int main()
 {
Index: compiler-rt/test/ubsan/TestCases/Integer/usub-overflow.cpp
===
--- compiler-rt/test/ubsan/TestCases/Integer/usub-overflow.cpp
+++ compiler-rt/test/ubsan/TestCases/Integer/usub-overflow.cpp
@@ -12,12 +12,12 @@
 
 #ifdef SUB_I32
   (void)(uint32_t(1) - uint32_t(2));
-  // CHECK-SUB_I32: usub-overflow.cpp:[[@LINE-1]]:22: runtime error: unsigned integer overflow: 1 - 2 cannot be represented in type 'unsigned int'
+  // CHECK-SUB_I32: usub-overflow.cpp:[[@LINE-1]]:22: runtime error: unsigned integer overflow: 1 - 2 cannot be represented in type '{{uint32_t|unsigned int}}'
 #endif
 
 #ifdef SUB_I64
   (void)(uint64_t(800ll) - uint64_t(900ll));
-  // CHECK-SUB_I64: 800 - 900 cannot be represented in type 'unsigned {{long( long)?}}'
+  // CHECK-SUB_I64: 800 - 900 cannot be represented in type '{{uint64_t|unsigned long( long)?}}'
 #endif
 
 #ifdef SUB_I128
@@ -26,6 +26,6 @@
 # else
   puts("__int128 not supported\n");
 # endif
-  // CHECK-SUB_I128: {{0x4000 - 0x8000 cannot be represented in type 'unsigned __int128'|__int128 not supported}}
+  // CHECK-SUB_I128: {{0x4000 - 0x8000 cannot be represented in type '__uint128_t'|__int128 not supported}}
 #endif
 }
Index: compiler-rt/test/ubsan/TestCases/Integer/umul-overflow.cpp
===
--- compiler-rt/test/ubsan/TestCases/Integer/umul-overflow.cpp
+++ compiler-rt/test/ubsan/TestCases/Integer/umul-overflow.cpp
@@ -13,7 +13,7 @@
   (void)(uint16_t(0x) * uint16_t(0x8001));
 
   (void)(uint32_t(0x) * uint32_t(0x2));
-  // CHECK: umul-overflow.cpp:15:31: runtime error: unsigned integer overflow: 4294967295 * 2 cannot be represented in type 'unsigned int'
+  // CHECK: umul-overflow.cpp:15:31: runtime error: un

[clang] 67e2298 - [clang] use getCommonSugar in an assortment of places

2022-09-16 Thread Matheus Izvekov via cfe-commits

Author: Matheus Izvekov
Date: 2022-09-16T16:36:00+02:00
New Revision: 67e22983115451ef5512ad2813dd337762c52da3

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

LOG: [clang] use getCommonSugar in an assortment of places

For this patch, a simple search was performed for patterns where there are
two types (usually an LHS and an RHS) which are structurally the same, and there
is some result type which is resolved as either one of them (typically LHS for
consistency).

We change those cases to resolve as the common sugared type between those two,
utilizing the new infrastructure created for this purpose.

Signed-off-by: Matheus Izvekov 

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

Added: 
clang/test/Sema/sugar-common-types.c
clang/test/SemaCXX/sugar-common-types.cpp

Modified: 
clang-tools-extra/clangd/unittests/tweaks/ExtractVariableTests.cpp

clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/narrowing-conversions-ignoreconversionfromtypes-option.cpp
clang/lib/CodeGen/CGExprComplex.cpp
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/test/AST/ast-dump-fpfeatures.cpp
clang/test/CodeGen/complex-math.c
clang/test/CodeGen/compound-assign-overflow.c
clang/test/Sema/complex-int.c
clang/test/Sema/matrix-type-operators.c
clang/test/Sema/nullability.c
clang/test/SemaCXX/complex-conversion.cpp
clang/test/SemaCXX/matrix-type-operators.cpp
clang/test/SemaCXX/sugared-auto.cpp
clang/test/SemaObjC/format-strings-objc.m
compiler-rt/test/ubsan/TestCases/Integer/add-overflow.cpp
compiler-rt/test/ubsan/TestCases/Integer/no-recover.cpp
compiler-rt/test/ubsan/TestCases/Integer/sub-overflow.cpp
compiler-rt/test/ubsan/TestCases/Integer/uadd-overflow.cpp
compiler-rt/test/ubsan/TestCases/Integer/umul-overflow.cpp
compiler-rt/test/ubsan/TestCases/Integer/usub-overflow.cpp
lldb/test/API/commands/expression/rdar42038760/main.c
lldb/test/API/commands/expression/rdar44436068/main.c

Removed: 




diff  --git 
a/clang-tools-extra/clangd/unittests/tweaks/ExtractVariableTests.cpp 
b/clang-tools-extra/clangd/unittests/tweaks/ExtractVariableTests.cpp
index 70ecc202d0b28..6e38ea77ad68d 100644
--- a/clang-tools-extra/clangd/unittests/tweaks/ExtractVariableTests.cpp
+++ b/clang-tools-extra/clangd/unittests/tweaks/ExtractVariableTests.cpp
@@ -330,7 +330,7 @@ TEST_F(ExtractVariableTest, Test) {
  void bar() {
int (*placeholder)(int) = foo('c'); (void)placeholder;
  })cpp"},
-  // Arithmetic on typedef types yields plain integer types
+  // Arithmetic on typedef types preserves typedef types
   {R"cpp(typedef long NSInteger;
  void varDecl() {
 NSInteger a = 2 * 5;
@@ -339,7 +339,7 @@ TEST_F(ExtractVariableTest, Test) {
R"cpp(typedef long NSInteger;
  void varDecl() {
 NSInteger a = 2 * 5;
-long placeholder = a * 7; NSInteger b = placeholder + 3;
+NSInteger placeholder = a * 7; NSInteger b = placeholder + 3;
  })cpp"},
   };
   for (const auto &IO : InputOutputs) {

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/narrowing-conversions-ignoreconversionfromtypes-option.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/narrowing-conversions-ignoreconversionfromtypes-option.cpp
index 2fc5621c2fb8f..34da420fd0cc5 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/narrowing-conversions-ignoreconversionfromtypes-option.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/narrowing-conversions-ignoreconversionfromtypes-option.cpp
@@ -42,7 +42,7 @@ void narrowing_size_method() {
   // IGNORED: Warning is disabled with IgnoreConversionFromTypes=global_size_t.
 
   i = j + v.size();
-  // CHECK-MESSAGES-DEFAULT: :[[@LINE-1]]:7: warning: narrowing conversion 
from 'long long' to signed type 'int' is implementation-defined 
[cppcoreguidelines-narrowing-conversions]
+  // CHECK-MESSAGES-DEFAULT: :[[@LINE-1]]:7: warning: narrowing conversion 
from 'global_size_t' (aka 'long long') to signed type 'int' is 
implementation-defined [cppcoreguidelines-narrowing-conversions]
   // IGNORED: Warning is disabled with IgnoreConversionFromTypes=global_size_t.
 }
 
@@ -51,7 +51,7 @@ void narrowing_size_method_binary_expr() {
   int j;
   vector v;
   i = j + v.size();
-  // CHECK-MESSAGES-DEFAULT: :[[@LINE-1]]:7: warning: narrowing conversion 
from 'long long' to signed type 'int' is implementation-defined 
[cppcoreguidelines-narrowing-conversions]
+  // CHECK-MESSAGES-DEFAULT: :[[@LINE-1]]:7: warning: narrowing conversion 
from 'global_size_t' (aka 'long long') to signed

[clang-tools-extra] 67e2298 - [clang] use getCommonSugar in an assortment of places

2022-09-16 Thread Matheus Izvekov via cfe-commits

Author: Matheus Izvekov
Date: 2022-09-16T16:36:00+02:00
New Revision: 67e22983115451ef5512ad2813dd337762c52da3

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

LOG: [clang] use getCommonSugar in an assortment of places

For this patch, a simple search was performed for patterns where there are
two types (usually an LHS and an RHS) which are structurally the same, and there
is some result type which is resolved as either one of them (typically LHS for
consistency).

We change those cases to resolve as the common sugared type between those two,
utilizing the new infrastructure created for this purpose.

Signed-off-by: Matheus Izvekov 

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

Added: 
clang/test/Sema/sugar-common-types.c
clang/test/SemaCXX/sugar-common-types.cpp

Modified: 
clang-tools-extra/clangd/unittests/tweaks/ExtractVariableTests.cpp

clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/narrowing-conversions-ignoreconversionfromtypes-option.cpp
clang/lib/CodeGen/CGExprComplex.cpp
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/test/AST/ast-dump-fpfeatures.cpp
clang/test/CodeGen/complex-math.c
clang/test/CodeGen/compound-assign-overflow.c
clang/test/Sema/complex-int.c
clang/test/Sema/matrix-type-operators.c
clang/test/Sema/nullability.c
clang/test/SemaCXX/complex-conversion.cpp
clang/test/SemaCXX/matrix-type-operators.cpp
clang/test/SemaCXX/sugared-auto.cpp
clang/test/SemaObjC/format-strings-objc.m
compiler-rt/test/ubsan/TestCases/Integer/add-overflow.cpp
compiler-rt/test/ubsan/TestCases/Integer/no-recover.cpp
compiler-rt/test/ubsan/TestCases/Integer/sub-overflow.cpp
compiler-rt/test/ubsan/TestCases/Integer/uadd-overflow.cpp
compiler-rt/test/ubsan/TestCases/Integer/umul-overflow.cpp
compiler-rt/test/ubsan/TestCases/Integer/usub-overflow.cpp
lldb/test/API/commands/expression/rdar42038760/main.c
lldb/test/API/commands/expression/rdar44436068/main.c

Removed: 




diff  --git 
a/clang-tools-extra/clangd/unittests/tweaks/ExtractVariableTests.cpp 
b/clang-tools-extra/clangd/unittests/tweaks/ExtractVariableTests.cpp
index 70ecc202d0b28..6e38ea77ad68d 100644
--- a/clang-tools-extra/clangd/unittests/tweaks/ExtractVariableTests.cpp
+++ b/clang-tools-extra/clangd/unittests/tweaks/ExtractVariableTests.cpp
@@ -330,7 +330,7 @@ TEST_F(ExtractVariableTest, Test) {
  void bar() {
int (*placeholder)(int) = foo('c'); (void)placeholder;
  })cpp"},
-  // Arithmetic on typedef types yields plain integer types
+  // Arithmetic on typedef types preserves typedef types
   {R"cpp(typedef long NSInteger;
  void varDecl() {
 NSInteger a = 2 * 5;
@@ -339,7 +339,7 @@ TEST_F(ExtractVariableTest, Test) {
R"cpp(typedef long NSInteger;
  void varDecl() {
 NSInteger a = 2 * 5;
-long placeholder = a * 7; NSInteger b = placeholder + 3;
+NSInteger placeholder = a * 7; NSInteger b = placeholder + 3;
  })cpp"},
   };
   for (const auto &IO : InputOutputs) {

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/narrowing-conversions-ignoreconversionfromtypes-option.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/narrowing-conversions-ignoreconversionfromtypes-option.cpp
index 2fc5621c2fb8f..34da420fd0cc5 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/narrowing-conversions-ignoreconversionfromtypes-option.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/narrowing-conversions-ignoreconversionfromtypes-option.cpp
@@ -42,7 +42,7 @@ void narrowing_size_method() {
   // IGNORED: Warning is disabled with IgnoreConversionFromTypes=global_size_t.
 
   i = j + v.size();
-  // CHECK-MESSAGES-DEFAULT: :[[@LINE-1]]:7: warning: narrowing conversion 
from 'long long' to signed type 'int' is implementation-defined 
[cppcoreguidelines-narrowing-conversions]
+  // CHECK-MESSAGES-DEFAULT: :[[@LINE-1]]:7: warning: narrowing conversion 
from 'global_size_t' (aka 'long long') to signed type 'int' is 
implementation-defined [cppcoreguidelines-narrowing-conversions]
   // IGNORED: Warning is disabled with IgnoreConversionFromTypes=global_size_t.
 }
 
@@ -51,7 +51,7 @@ void narrowing_size_method_binary_expr() {
   int j;
   vector v;
   i = j + v.size();
-  // CHECK-MESSAGES-DEFAULT: :[[@LINE-1]]:7: warning: narrowing conversion 
from 'long long' to signed type 'int' is implementation-defined 
[cppcoreguidelines-narrowing-conversions]
+  // CHECK-MESSAGES-DEFAULT: :[[@LINE-1]]:7: warning: narrowing conversion 
from 'global_size_t' (aka 'long long') to signed

[PATCH] D133934: [clang][Interp] Handle sizeof() expressions

2022-09-16 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added inline comments.



Comment at: clang/lib/AST/Interp/ByteCodeExprGen.cpp:290
+
+if (!ArgType->isConstantSizeType() ||
+ArgType->isDependentType())

tbaeder wrote:
> erichkeane wrote:
> > Documentation for `isConstantSizedType` says it isn't legal to call it on 
> > dependent or incomplete types.  so this probably needs to be:
> > 
> > ``` if (ArgType->isDependentType() || ArgType->isIncompleteType() || 
> > !ArgType->isConstantSizedType())```
> > 
> > In roughly that order.
> `isDependentType()` is implicitly assumed, isn't it? `ExprConstant.cpp` 
> asserts everywhere that neither types nor expressions are (value)dependent. 
> It also doesn't handle that in `HandleSizeof`.
Ok, good to know about that then.  I saw you'd tested for isDependentType 
above, but isConstantSizedType would assert in that case.



Comment at: clang/test/AST/Interp/literals.cpp:89
+  static_assert(sizeof(&soint) == sizeof(void*), "");
+  static_assert(sizeof(&soint) == sizeof(nullptr), "");
+

tbaeder wrote:
> aaron.ballman wrote:
> > This test got me thinking about another test case:
> > ```
> > struct S {
> >   void func();
> > };
> > 
> > constexpr void (S::*Func)() = &S::func;
> > static_assert(sizeof(Func) == sizeof(&S::func), "");
> > ```
> > (Can't test this one against `nullptr` because `sizeof(nullptr)` is not 
> > telling you the size of a pointer to member function despite `nullptr` 
> > being convertible to one.)
> I'll add it, but might have to `#if 0` it out for the same reason I had to 
> push https://reviews.llvm.org/rGa8843643cd75d0e93ebcf3f30b470d2b8e59868d
What is the cause of that leak?  Is that something we should be fixing ASAP so 
we can enable these tests?


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

https://reviews.llvm.org/D133934

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


[PATCH] D133052: [clang] Avoid crash when expanding conversion templates in concepts.

2022-09-16 Thread Luke Nihlen via Phabricator via cfe-commits
luken-google updated this revision to Diff 460756.
luken-google added a comment.

Refactor to check during template overload evaluation


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133052

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaInit.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/test/SemaTemplate/concepts.cpp


Index: clang/test/SemaTemplate/concepts.cpp
===
--- clang/test/SemaTemplate/concepts.cpp
+++ clang/test/SemaTemplate/concepts.cpp
@@ -262,3 +262,18 @@
 template  struct S {};
 void f(C auto);
 } // namespace GH55567
+
+namespace Issue50891 {
+template 
+concept Numeric =
+requires(T a) {
+foo(a);
+};
+
+struct Deferred {
+friend void foo(Deferred);
+template  operator TO();
+};
+
+static_assert(Numeric); // should not crash clang
+} // namespace Issue50891
Index: clang/lib/Sema/SemaOverload.cpp
===
--- clang/lib/Sema/SemaOverload.cpp
+++ clang/lib/Sema/SemaOverload.cpp
@@ -7565,6 +7565,24 @@
 return;
   }
 
+  // We won't go through a user-defined type conversion function to convert a
+  // derived to base as such conversions are given Conversion Rank. They only
+  // go through a copy constructor. 13.3.3.1.2-p4 [over.ics.user]
+  // Peforming this check here avoids possible infinite template expansion
+  // in the following call to DeduceTemplateArguments().
+  QualType FromCanon =
+  Context.getCanonicalType(From->getType().getUnqualifiedType());
+  QualType ToCanon = Context.getCanonicalType(ToType).getUnqualifiedType();
+  if (FromCanon == ToCanon ||
+  IsDerivedFrom(CandidateSet.getLocation(), FromCanon, ToCanon)) {
+OverloadCandidate &Candidate = CandidateSet.addCandidate();
+Candidate.FoundDecl = FoundDecl;
+Candidate.Function = FunctionTemplate->getTemplatedDecl();
+Candidate.Viable = false;
+Candidate.FailureKind = ovl_fail_trivial_conversion;
+return;
+  }
+
   TemplateDeductionInfo Info(CandidateSet.getLocation());
   CXXConversionDecl *Specialization = nullptr;
   if (TemplateDeductionResult Result
Index: clang/lib/Sema/SemaInit.cpp
===
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -4020,6 +4020,9 @@
   //
   // Note: SecondStepOfCopyInit is only ever true in this case when
   // evaluating whether to produce a C++98 compatibility warning.
+  //
+  // The last check avoids an infinite template expansion loop in
+  // requirements checking by skipping the conversion functions check.
   if (S.getLangOpts().CPlusPlus17 && Args.size() == 1 &&
   !SecondStepOfCopyInit) {
 Expr *Initializer = Args[0];
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -267,17 +267,17 @@
   `GH55216 `_.
 - Correctly set expression evaluation context as 'immediate function context' 
in
   consteval functions.
-  This fixes `GH51182 `_.
-
+  This fixes `GH51182 `
 - Fixes an assert crash caused by looking up missing vtable information on 
``consteval``
   virtual functions. Fixes `GH55065 
`_.
-
 - Skip rebuilding lambda expressions in arguments of immediate invocations.
   This fixes `GH56183 `_,
   `GH51695 `_,
   `GH50455 `_,
   `GH54872 `_,
   `GH54587 `_.
+- Fixed a crash during template instantiation on a conversion operator during 
constraint
+  evaulation. Fixes `GH50891 
`_.
 
 C++2b Feature Support
 ^


Index: clang/test/SemaTemplate/concepts.cpp
===
--- clang/test/SemaTemplate/concepts.cpp
+++ clang/test/SemaTemplate/concepts.cpp
@@ -262,3 +262,18 @@
 template  struct S {};
 void f(C auto);
 } // namespace GH55567
+
+namespace Issue50891 {
+template 
+concept Numeric =
+requires(T a) {
+foo(a);
+};
+
+struct Deferred {
+friend void foo(Deferred);
+template  operator TO();
+};
+
+static_assert(Numeric); // should not crash clang
+} // namespace Issue50891
Index: clang/lib/Sema/SemaOverload.cpp
===
--- clang/lib/Sema/SemaOverload.cpp
+++ clang/lib/Sema/SemaOverload.cpp
@@ -7565,6 +7565,24 @@
 return;
   }
 
+  // We won't go through a

[PATCH] D133052: [clang] Avoid crash when expanding conversion templates in concepts.

2022-09-16 Thread Luke Nihlen via Phabricator via cfe-commits
luken-google updated this revision to Diff 460757.
luken-google added a comment.

Remove extraneous comment.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133052

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaOverload.cpp
  clang/test/SemaTemplate/concepts.cpp


Index: clang/test/SemaTemplate/concepts.cpp
===
--- clang/test/SemaTemplate/concepts.cpp
+++ clang/test/SemaTemplate/concepts.cpp
@@ -262,3 +262,18 @@
 template  struct S {};
 void f(C auto);
 } // namespace GH55567
+
+namespace Issue50891 {
+template 
+concept Numeric =
+requires(T a) {
+foo(a);
+};
+
+struct Deferred {
+friend void foo(Deferred);
+template  operator TO();
+};
+
+static_assert(Numeric); // should not crash clang
+} // namespace Issue50891
Index: clang/lib/Sema/SemaOverload.cpp
===
--- clang/lib/Sema/SemaOverload.cpp
+++ clang/lib/Sema/SemaOverload.cpp
@@ -7565,6 +7565,24 @@
 return;
   }
 
+  // We won't go through a user-defined type conversion function to convert a
+  // derived to base as such conversions are given Conversion Rank. They only
+  // go through a copy constructor. 13.3.3.1.2-p4 [over.ics.user]
+  // Peforming this check here avoids possible infinite template expansion
+  // in the following call to DeduceTemplateArguments().
+  QualType FromCanon =
+  Context.getCanonicalType(From->getType().getUnqualifiedType());
+  QualType ToCanon = Context.getCanonicalType(ToType).getUnqualifiedType();
+  if (FromCanon == ToCanon ||
+  IsDerivedFrom(CandidateSet.getLocation(), FromCanon, ToCanon)) {
+OverloadCandidate &Candidate = CandidateSet.addCandidate();
+Candidate.FoundDecl = FoundDecl;
+Candidate.Function = FunctionTemplate->getTemplatedDecl();
+Candidate.Viable = false;
+Candidate.FailureKind = ovl_fail_trivial_conversion;
+return;
+  }
+
   TemplateDeductionInfo Info(CandidateSet.getLocation());
   CXXConversionDecl *Specialization = nullptr;
   if (TemplateDeductionResult Result
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -267,17 +267,17 @@
   `GH55216 `_.
 - Correctly set expression evaluation context as 'immediate function context' 
in
   consteval functions.
-  This fixes `GH51182 `_.
-
+  This fixes `GH51182 `
 - Fixes an assert crash caused by looking up missing vtable information on 
``consteval``
   virtual functions. Fixes `GH55065 
`_.
-
 - Skip rebuilding lambda expressions in arguments of immediate invocations.
   This fixes `GH56183 `_,
   `GH51695 `_,
   `GH50455 `_,
   `GH54872 `_,
   `GH54587 `_.
+- Fixed a crash during template instantiation on a conversion operator during 
constraint
+  evaulation. Fixes `GH50891 
`_.
 
 C++2b Feature Support
 ^


Index: clang/test/SemaTemplate/concepts.cpp
===
--- clang/test/SemaTemplate/concepts.cpp
+++ clang/test/SemaTemplate/concepts.cpp
@@ -262,3 +262,18 @@
 template  struct S {};
 void f(C auto);
 } // namespace GH55567
+
+namespace Issue50891 {
+template 
+concept Numeric =
+requires(T a) {
+foo(a);
+};
+
+struct Deferred {
+friend void foo(Deferred);
+template  operator TO();
+};
+
+static_assert(Numeric); // should not crash clang
+} // namespace Issue50891
Index: clang/lib/Sema/SemaOverload.cpp
===
--- clang/lib/Sema/SemaOverload.cpp
+++ clang/lib/Sema/SemaOverload.cpp
@@ -7565,6 +7565,24 @@
 return;
   }
 
+  // We won't go through a user-defined type conversion function to convert a
+  // derived to base as such conversions are given Conversion Rank. They only
+  // go through a copy constructor. 13.3.3.1.2-p4 [over.ics.user]
+  // Peforming this check here avoids possible infinite template expansion
+  // in the following call to DeduceTemplateArguments().
+  QualType FromCanon =
+  Context.getCanonicalType(From->getType().getUnqualifiedType());
+  QualType ToCanon = Context.getCanonicalType(ToType).getUnqualifiedType();
+  if (FromCanon == ToCanon ||
+  IsDerivedFrom(CandidateSet.getLocation(), FromCanon, ToCanon)) {
+OverloadCandidate &Candidate = CandidateSet.a

[PATCH] D133052: [clang] Avoid crash when expanding conversion templates in concepts.

2022-09-16 Thread Luke Nihlen via Phabricator via cfe-commits
luken-google added a comment.

@ilya-biryukov something like this?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133052

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


[PATCH] D133934: [clang][Interp] Handle sizeof() expressions

2022-09-16 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 460758.

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

https://reviews.llvm.org/D133934

Files:
  clang/lib/AST/Interp/Boolean.h
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/ByteCodeExprGen.h
  clang/lib/AST/Interp/Opcodes.td
  clang/test/AST/Interp/literals.cpp

Index: clang/test/AST/Interp/literals.cpp
===
--- clang/test/AST/Interp/literals.cpp
+++ clang/test/AST/Interp/literals.cpp
@@ -1,5 +1,7 @@
 // RUN: %clang_cc1 -fexperimental-new-constant-interpreter -std=c++11 -verify %s
+// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -std=c++20 -verify %s
 // RUN: %clang_cc1 -std=c++11 -verify=ref %s
+// RUN: %clang_cc1 -std=c++20 -verify=ref %s
 
 static_assert(true, "");
 static_assert(false, ""); // expected-error{{failed}} ref-error{{failed}}
@@ -72,10 +74,74 @@
 constexpr const int* getIntPointer() {
   return &m;
 }
-//static_assert(getIntPointer() == &m, ""); TODO
-//static_assert(*getIntPointer() == 10, ""); TODO
+static_assert(getIntPointer() == &m, "");
+static_assert(*getIntPointer() == 10, "");
 
 constexpr int gimme(int k) {
   return k;
 }
-// static_assert(gimme(5) == 5, ""); TODO
+static_assert(gimme(5) == 5, "");
+
+namespace SizeOf {
+  constexpr int soint = sizeof(int);
+  constexpr int souint = sizeof(unsigned int);
+  static_assert(soint == souint, "");
+
+  static_assert(sizeof(&soint) == sizeof(void*), "");
+  static_assert(sizeof(&soint) == sizeof(nullptr), "");
+
+  static_assert(sizeof(long) == sizeof(unsigned long), "");
+  static_assert(sizeof(char) == sizeof(unsigned char), "");
+
+  constexpr int N = 4;
+  constexpr int arr[N] = {1,2,3,4};
+  static_assert(sizeof(arr) == N * sizeof(int), "");
+  static_assert(sizeof(arr) == N * sizeof(arr[0]), "");
+
+  constexpr bool arrB[N] = {true, true, true, true};
+  static_assert(sizeof(arrB) == N * sizeof(bool), "");
+
+  static_assert(sizeof(bool) == 1, "");
+  static_assert(sizeof(char) == 1, "");
+
+  constexpr int F = sizeof(void); // expected-error{{incomplete type 'void'}} \
+  // ref-error{{incomplete type 'void'}}
+
+  constexpr int F2 = sizeof(gimme); // expected-error{{to a function type}} \
+// ref-error{{to a function type}}
+
+
+
+  /// FIXME: The following code should be accepted.
+  struct S {
+void func();
+  };
+  constexpr void (S::*Func)() = &S::func; // expected-error {{must be initialized by a constant expression}} \
+  // expected-error {{interpreter failed to evaluate an expression}}
+  static_assert(sizeof(Func) == sizeof(&S::func), "");
+
+
+  void func() {
+int n = 12;
+constexpr int oofda = sizeof(int[n++]); // expected-error {{must be initialized by a constant expression}} \
+// ref-error {{must be initialized by a constant expression}}
+  }
+
+
+#if __cplusplus >= 202002L
+  /// FIXME: The following code should be accepted.
+  consteval int foo(int n) { // ref-error {{consteval function never produces a constant expression}}
+return sizeof(int[n]); // ref-note 3{{not valid in a constant expression}} \
+   // expected-note {{not valid in a constant expression}}
+  }
+  constinit int var = foo(5); // ref-error {{not a constant expression}} \
+  // ref-note 2{{in call to}} \
+  // ref-error {{does not have a constant initializer}} \
+  // ref-note {{required by 'constinit' specifier}} \
+  // expected-error  {{is not a constant expression}} \
+  // expected-note {{in call to}} \
+  // expected-error {{does not have a constant initializer}} \
+  // expected-note {{required by 'constinit' specifier}} \
+
+#endif
+};
Index: clang/lib/AST/Interp/Opcodes.td
===
--- clang/lib/AST/Interp/Opcodes.td
+++ clang/lib/AST/Interp/Opcodes.td
@@ -427,11 +427,11 @@
 // TODO: Expand this to handle casts between more types.
 
 def FromCastTypeClass : TypeClass {
-  let Types = [Uint32, Sint32, Bool];
+  let Types = [Uint8, Sint8, Uint16, Sint16, Uint32, Sint32, Uint64, Sint64, Bool];
 }
 
 def ToCastTypeClass : TypeClass {
-  let Types = [Uint32, Sint32, Bool];
+  let Types = [Uint8, Sint8, Uint16, Sint16, Uint32, Sint32, Uint64, Sint64, Bool];
 }
 
 def Cast: Opcode {
Index: clang/lib/AST/Interp/ByteCodeExprGen.h
===
--- clang/lib/AST/Interp/ByteCodeExprGen.h
+++ clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -80,6 +80,7 @@
   bool VisitArraySubscriptExpr(const ArraySubscriptExpr *E);
   bool VisitInitListExpr(const InitListExpr *E);
   bool VisitConstantExpr(const ConstantExpr *

[PATCH] D133934: [clang][Interp] Handle sizeof() expressions

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



Comment at: clang/lib/AST/Interp/ByteCodeExprGen.cpp:290
+
+if (!ArgType->isConstantSizeType() ||
+ArgType->isDependentType())

erichkeane wrote:
> tbaeder wrote:
> > erichkeane wrote:
> > > Documentation for `isConstantSizedType` says it isn't legal to call it on 
> > > dependent or incomplete types.  so this probably needs to be:
> > > 
> > > ``` if (ArgType->isDependentType() || ArgType->isIncompleteType() || 
> > > !ArgType->isConstantSizedType())```
> > > 
> > > In roughly that order.
> > `isDependentType()` is implicitly assumed, isn't it? `ExprConstant.cpp` 
> > asserts everywhere that neither types nor expressions are (value)dependent. 
> > It also doesn't handle that in `HandleSizeof`.
> Ok, good to know about that then.  I saw you'd tested for isDependentType 
> above, but isConstantSizedType would assert in that case.
Yup, I switched the order around.



Comment at: clang/test/AST/Interp/literals.cpp:89
+  static_assert(sizeof(&soint) == sizeof(void*), "");
+  static_assert(sizeof(&soint) == sizeof(nullptr), "");
+

erichkeane wrote:
> tbaeder wrote:
> > aaron.ballman wrote:
> > > This test got me thinking about another test case:
> > > ```
> > > struct S {
> > >   void func();
> > > };
> > > 
> > > constexpr void (S::*Func)() = &S::func;
> > > static_assert(sizeof(Func) == sizeof(&S::func), "");
> > > ```
> > > (Can't test this one against `nullptr` because `sizeof(nullptr)` is not 
> > > telling you the size of a pointer to member function despite `nullptr` 
> > > being convertible to one.)
> > I'll add it, but might have to `#if 0` it out for the same reason I had to 
> > push https://reviews.llvm.org/rGa8843643cd75d0e93ebcf3f30b470d2b8e59868d
> What is the cause of that leak?  Is that something we should be fixing ASAP 
> so we can enable these tests?
IIRC it was creating a `Record` for the `RecordDecl` but never freeing it or 
something similar. The test case didn't do anything anyway since records aren't 
implemented yet. The only difference now is that I won't notice automatically 
that a test case suddenly starts working when I implement records.


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

https://reviews.llvm.org/D133934

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


[PATCH] D134034: [test] Use host platform specific error message substitution

2022-09-16 Thread Abhina Sree via Phabricator via cfe-commits
abhina.sreeskantharajan updated this revision to Diff 460761.
abhina.sreeskantharajan added a comment.
Herald added subscribers: cfe-commits, ormris.
Herald added a project: clang.

Add some more tests


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134034

Files:
  clang/test/Format/style-on-command-line.cpp
  llvm/test/tools/llvm-dis/errors.test
  llvm/test/tools/llvm-dwp/X86/diagnose_missing_dwos.test
  llvm/test/tools/llvm-reduce/mir/input-file-does-not-exist.mir
  llvm/test/tools/llvm-tapi-diff/misspelled-tbd.test


Index: llvm/test/tools/llvm-tapi-diff/misspelled-tbd.test
===
--- llvm/test/tools/llvm-tapi-diff/misspelled-tbd.test
+++ llvm/test/tools/llvm-tapi-diff/misspelled-tbd.test
@@ -1,3 +1,3 @@
-; RUN: not llvm-tapi-diff %S/Inputs/v4A.tbd %S/Inputs/v4.tbd 2>&1 | FileCheck 
%s
+; RUN: not llvm-tapi-diff %S/Inputs/v4A.tbd %S/Inputs/v4.tbd 2>&1 | FileCheck 
-DMSG=%errc_ENOENT %s
 
-; CHECK: error: {{.*}}v4.tbd' {{[Nn]}}o such file or directory
+; CHECK: error: {{.*}}v4.tbd' [[MSG]]
Index: llvm/test/tools/llvm-reduce/mir/input-file-does-not-exist.mir
===
--- llvm/test/tools/llvm-reduce/mir/input-file-does-not-exist.mir
+++ llvm/test/tools/llvm-reduce/mir/input-file-does-not-exist.mir
@@ -1,4 +1,4 @@
 # REQUIRES: amdgpu-registered-target
-# RUN: not llvm-reduce -mtriple=amdgcn-amd-amdhsa --test FileCheck --test-arg 
%s --test-arg --input-file does-not-exist.mir 2>&1 | FileCheck 
-check-prefix=ERR %s
+# RUN: not llvm-reduce -mtriple=amdgcn-amd-amdhsa --test FileCheck --test-arg 
%s --test-arg --input-file does-not-exist.mir 2>&1 | FileCheck 
-DMSG=%errc_ENOENT -check-prefix=ERR %s
 
-# ERR: {{.*}}llvm-reduce{{.*}}: {{[Nn]}}o such file or directory
+# ERR: {{.*}}llvm-reduce{{.*}}: [[MSG]]
Index: llvm/test/tools/llvm-dwp/X86/diagnose_missing_dwos.test
===
--- llvm/test/tools/llvm-dwp/X86/diagnose_missing_dwos.test
+++ llvm/test/tools/llvm-dwp/X86/diagnose_missing_dwos.test
@@ -3,11 +3,11 @@
 RUN: cd %t
 RUN: cp %p/../Inputs/dwos_list_from_exec/b.dwo b.dwo
 RUN: cp %p/../Inputs/dwos_list_from_exec/main main
-RUN: not llvm-dwp -e binary -o /dev/null 2>&1 | FileCheck %s 
--check-prefix=CHECK-BIN
-RUN: not llvm-dwp -e main -o /dev/null 2>&1 | FileCheck %s 
--check-prefix=CHECK-1ST-DWO
+RUN: not llvm-dwp -e binary -o /dev/null 2>&1 | FileCheck -DMSG=%errc_ENOENT 
%s --check-prefix=CHECK-BIN
+RUN: not llvm-dwp -e main -o /dev/null 2>&1 | FileCheck -DMSG=%errc_ENOENT %s 
--check-prefix=CHECK-1ST-DWO
 RUN: cp %p/../Inputs/dwos_list_from_exec/a.dwo a.dwo
 RUN: rm b.dwo
-RUN: not llvm-dwp -e main -o /dev/null 2>&1 | FileCheck %s 
--check-prefix=CHECK-2ND-DWO
+RUN: not llvm-dwp -e main -o /dev/null 2>&1 | FileCheck -DMSG=%errc_ENOENT %s 
--check-prefix=CHECK-2ND-DWO
 
 Build commands for the test binaries:
 
@@ -23,6 +23,6 @@
  return 0;
   }
 
-CHECK-BIN: error: 'binary': {{[Nn]}}o such file or directory
-CHECK-1ST-DWO: error: './a.dwo': {{[Nn]}}o such file or directory
-CHECK-2ND-DWO: error: './b.dwo': {{[Nn]}}o such file or directory
+CHECK-BIN: error: 'binary': [[MSG]]
+CHECK-1ST-DWO: error: './a.dwo': [[MSG]]
+CHECK-2ND-DWO: error: './b.dwo': [[MSG]]
Index: llvm/test/tools/llvm-dis/errors.test
===
--- llvm/test/tools/llvm-dis/errors.test
+++ llvm/test/tools/llvm-dis/errors.test
@@ -1,3 +1,3 @@
-# RUN: not llvm-dis missing-file-path 2>&1 | FileCheck %s 
--check-prefix=MISSING --ignore-case
+# RUN: not llvm-dis missing-file-path 2>&1 | FileCheck -DMSG=%errc_ENOENT %s 
--check-prefix=MISSING --ignore-case
 
-# MISSING: error: missing-file-path: no such file or directory
+# MISSING: error: missing-file-path: [[MSG]]
Index: clang/test/Format/style-on-command-line.cpp
===
--- clang/test/Format/style-on-command-line.cpp
+++ clang/test/Format/style-on-command-line.cpp
@@ -6,7 +6,7 @@
 // RUN: printf "BasedOnStyle: google\nIndentWidth: 5\n" > %t/.clang-format
 // RUN: clang-format -style=file -assume-filename=%t/foo.cpp < %s | FileCheck 
-strict-whitespace -check-prefix=CHECK5 %s
 // RUN: printf "Invalid:\n" > %t/.clang-format
-// RUN: not clang-format -style=file -fallback-style=webkit 
-assume-filename=%t/foo.cpp < %s 2>&1 | FileCheck -strict-whitespace 
-check-prefix=CHECK6 %s
+// RUN: not clang-format -style=file -fallback-style=webkit 
-assume-filename=%t/foo.cpp < %s 2>&1 | FileCheck -DMSG=%errc_EINVAL 
-strict-whitespace -check-prefix=CHECK6 %s
 // RUN: rm %t/.clang-format
 // RUN: printf "BasedOnStyle: google\nIndentWidth: 6\n" > %t/_clang-format
 // RUN: clang-format -style=file -assume-filename=%t/foo.cpp < %s | FileCheck 
-strict-whitespace -check-prefix=CHECK7 %s
@@ -35,7 +35,7 @@
 // CHECK4: Error parsi

[PATCH] D134049: [clang-format] Disallow trailing return arrows to be operators

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

In the following construction:
`template  requires Foo || Bar auto func() -> int;`

The `->` of the trailing return type was actually considered as an
operator as part of the binary operation in the requires clause, with
the precedence level of `PrecedenceArrowAndPeriod`, leading to fake
parens being inserted in strange locations, that would never be closed.

Fixes one part of https://github.com/llvm/llvm-project/issues/56213
(the rest will probably be in a separate patch)


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D134049

Files:
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/TokenAnnotatorTest.cpp


Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -440,6 +440,13 @@
   ASSERT_EQ(Tokens.size(), 18u) << Tokens;
   EXPECT_TOKEN(Tokens[11], tok::kw_requires, TT_RequiresClause);
 
+  Tokens = annotate("template \n"
+"requires Bar || Baz\n"
+"auto foo(T) -> int;");
+  ASSERT_EQ(Tokens.size(), 24u) << Tokens;
+  EXPECT_EQ(Tokens[11]->FakeLParens.size(), 0u);
+  EXPECT_TOKEN(Tokens[5], tok::kw_requires, TT_RequiresClause);
+
   Tokens = annotate("template \n"
 "struct S {\n"
 "  void foo() const requires Bar;\n"
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -2611,8 +2611,10 @@
   }
   if (Current->is(TT_BinaryOperator) || Current->is(tok::comma))
 return Current->getPrecedence();
-  if (Current->isOneOf(tok::period, tok::arrow))
+  if (Current->isOneOf(tok::period, tok::arrow) &&
+  !Current->is(TT_TrailingReturnArrow)) {
 return PrecedenceArrowAndPeriod;
+  }
   if ((Style.Language == FormatStyle::LK_Java || Style.isJavaScript()) &&
   Current->isOneOf(Keywords.kw_extends, Keywords.kw_implements,
Keywords.kw_throws)) {


Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -440,6 +440,13 @@
   ASSERT_EQ(Tokens.size(), 18u) << Tokens;
   EXPECT_TOKEN(Tokens[11], tok::kw_requires, TT_RequiresClause);
 
+  Tokens = annotate("template \n"
+"requires Bar || Baz\n"
+"auto foo(T) -> int;");
+  ASSERT_EQ(Tokens.size(), 24u) << Tokens;
+  EXPECT_EQ(Tokens[11]->FakeLParens.size(), 0u);
+  EXPECT_TOKEN(Tokens[5], tok::kw_requires, TT_RequiresClause);
+
   Tokens = annotate("template \n"
 "struct S {\n"
 "  void foo() const requires Bar;\n"
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -2611,8 +2611,10 @@
   }
   if (Current->is(TT_BinaryOperator) || Current->is(tok::comma))
 return Current->getPrecedence();
-  if (Current->isOneOf(tok::period, tok::arrow))
+  if (Current->isOneOf(tok::period, tok::arrow) &&
+  !Current->is(TT_TrailingReturnArrow)) {
 return PrecedenceArrowAndPeriod;
+  }
   if ((Style.Language == FormatStyle::LK_Java || Style.isJavaScript()) &&
   Current->isOneOf(Keywords.kw_extends, Keywords.kw_implements,
Keywords.kw_throws)) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D134034: [test] Use host platform specific error message substitution

2022-09-16 Thread Fanbo Meng via Phabricator via cfe-commits
fanbo-meng accepted this revision.
fanbo-meng added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134034

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


[PATCH] D133988: [clang][deps] Make sure ScanInstance outlives collector

2022-09-16 Thread Ben Langmuir via Phabricator via cfe-commits
benlangmuir accepted this revision.
benlangmuir added a comment.
This revision is now accepted and ready to land.

Good catch, thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133988

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


[PATCH] D128440: [WebAssembly] Initial support for reference type funcref in clang

2022-09-16 Thread Paulo Matos via Phabricator via cfe-commits
pmatos updated this revision to Diff 460764.
pmatos added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128440

Files:
  clang/include/clang/AST/Type.h
  clang/include/clang/Basic/AddressSpaces.h
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/BuiltinsWebAssembly.def
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/TokenKinds.def
  clang/include/clang/Parse/Parser.h
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/Type.cpp
  clang/lib/AST/TypePrinter.cpp
  clang/lib/Basic/Targets/DirectX.h
  clang/lib/Basic/Targets/NVPTX.h
  clang/lib/Basic/Targets/SPIR.h
  clang/lib/Basic/Targets/TCE.h
  clang/lib/Basic/Targets/WebAssembly.h
  clang/lib/Basic/Targets/X86.h
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/TargetInfo.cpp
  clang/lib/CodeGen/TargetInfo.h
  clang/lib/Format/FormatToken.h
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseTentative.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/CodeGen/WebAssembly/wasm-funcref.c
  clang/test/SemaTemplate/address_space-dependent.cpp

Index: clang/test/SemaTemplate/address_space-dependent.cpp
===
--- clang/test/SemaTemplate/address_space-dependent.cpp
+++ clang/test/SemaTemplate/address_space-dependent.cpp
@@ -43,7 +43,7 @@
 
 template 
 void tooBig() {
-  __attribute__((address_space(I))) int *bounds; // expected-error {{address space is larger than the maximum supported (8388586)}}
+  __attribute__((address_space(I))) int *bounds; // expected-error {{address space is larger than the maximum supported (8388585)}}
 }
 
 template 
@@ -101,7 +101,7 @@
   car<1, 2, 3>(); // expected-note {{in instantiation of function template specialization 'car<1, 2, 3>' requested here}}
   HasASTemplateFields<1> HASTF;
   neg<-1>(); // expected-note {{in instantiation of function template specialization 'neg<-1>' requested here}}
-  correct<0x7FFFEA>();
+  correct<0x7FFFE9>();
   tooBig<8388650>(); // expected-note {{in instantiation of function template specialization 'tooBig<8388650L>' requested here}}
 
   __attribute__((address_space(1))) char *x;
Index: clang/test/CodeGen/WebAssembly/wasm-funcref.c
===
--- /dev/null
+++ clang/test/CodeGen/WebAssembly/wasm-funcref.c
@@ -0,0 +1,84 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// RUN: %clang_cc1 -triple wasm32 -target-feature +reference-types -o - -emit-llvm %s | FileCheck %s
+
+typedef void (*__funcref funcref_t)();
+typedef int (*__funcref fn_funcref_t)(int);
+typedef int (*fn_t)(int);
+
+// Null funcref builtin call
+// CHECK-LABEL: @get_null(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = call ptr addrspace(20) @llvm.wasm.ref.null.func()
+// CHECK-NEXT:ret ptr addrspace(20) [[TMP0]]
+//
+funcref_t get_null() {
+  return __builtin_wasm_ref_null_func();
+}
+
+// Call to null funcref builtin but requires cast since
+// default return value for builtin is a funcref with function type () -> ().
+// CHECK-LABEL: @get_null_ii(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = call ptr addrspace(20) @llvm.wasm.ref.null.func()
+// CHECK-NEXT:ret ptr addrspace(20) [[TMP0]]
+//
+fn_funcref_t get_null_ii() {
+  return (fn_funcref_t) __builtin_wasm_ref_null_func();
+}
+
+// Identity function for funcref.
+// CHECK-LABEL: @identity(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[FN_ADDR:%.*]] = alloca ptr addrspace(20), align 4
+// CHECK-NEXT:store ptr addrspace(20) [[FN:%.*]], ptr [[FN_ADDR]], align 4
+// CHECK-NEXT:[[TMP0:%.*]] = load ptr addrspace(20), ptr [[FN_ADDR]], align 4
+// CHECK-NEXT:ret ptr addrspace(20) [[TMP0]]
+//
+funcref_t identity(funcref_t fn) {
+  return fn;
+}
+
+void helper(funcref_t);
+
+// Pass funcref ref as an argument to a helper function.
+// CHECK-LABEL: @handle(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[FN_ADDR:%.*]] = alloca ptr addrspace(20), align 4
+// CHECK-NEXT:store ptr addrspace(20) [[FN:%.*]], ptr [[FN_ADDR]], align 4
+// CHECK-NEXT:[[TMP0:%.*]] = load ptr addrspace(20), ptr [[FN_ADDR]], align 4
+// CHECK-NEXT:call void @helper(ptr addrspace(20) noundef [[TMP0]])
+// CHECK-NEXT:ret i32 0
+//
+int handle(funcref_t fn) {
+  helper(fn);
+  return 0;
+}
+
+// Return funcref from function pointer.
+// CHECK-LABEL: @get_ref(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[FNPTR_ADDR:%.*]] = alloca ptr, align 4
+// CHECK-NEXT:store ptr [[FNPTR:%.*]], ptr [[FNPTR_ADDR]], align 4
+// CHECK-NEXT:[[TMP0:%.*]] = load ptr, ptr [[FNPTR_ADDR]], align 4
+// CHECK-NEXT:[[TMP1:%.*]] = addrspacecast ptr [[TMP0]] to ptr addrspace(20)
+// CHECK-NEXT:ret ptr addrspace(20) [[TMP1]]
+//
+fn_funcref_t get_ref(fn_t fnptr) {
+  return (fn_fun

[PATCH] D133934: [clang][Interp] Handle sizeof() expressions

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



Comment at: clang/lib/AST/Interp/ByteCodeExprGen.cpp:290
+
+if (!ArgType->isConstantSizeType() ||
+ArgType->isDependentType())

tbaeder wrote:
> erichkeane wrote:
> > tbaeder wrote:
> > > erichkeane wrote:
> > > > Documentation for `isConstantSizedType` says it isn't legal to call it 
> > > > on dependent or incomplete types.  so this probably needs to be:
> > > > 
> > > > ``` if (ArgType->isDependentType() || ArgType->isIncompleteType() || 
> > > > !ArgType->isConstantSizedType())```
> > > > 
> > > > In roughly that order.
> > > `isDependentType()` is implicitly assumed, isn't it? `ExprConstant.cpp` 
> > > asserts everywhere that neither types nor expressions are 
> > > (value)dependent. It also doesn't handle that in `HandleSizeof`.
> > Ok, good to know about that then.  I saw you'd tested for isDependentType 
> > above, but isConstantSizedType would assert in that case.
> Yup, I switched the order around.
... and of course I run into an incomplete type assertion with the 
`sizeof(void)` example when the file type is C.


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

https://reviews.llvm.org/D133934

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


[PATCH] D133934: [clang][Interp] Handle sizeof() expressions

2022-09-16 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 460766.
tbaeder marked 11 inline comments as done.

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

https://reviews.llvm.org/D133934

Files:
  clang/lib/AST/Interp/Boolean.h
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/ByteCodeExprGen.h
  clang/lib/AST/Interp/Opcodes.td
  clang/test/AST/Interp/literals.cpp

Index: clang/test/AST/Interp/literals.cpp
===
--- clang/test/AST/Interp/literals.cpp
+++ clang/test/AST/Interp/literals.cpp
@@ -1,5 +1,7 @@
 // RUN: %clang_cc1 -fexperimental-new-constant-interpreter -std=c++11 -verify %s
+// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -std=c++20 -verify %s
 // RUN: %clang_cc1 -std=c++11 -verify=ref %s
+// RUN: %clang_cc1 -std=c++20 -verify=ref %s
 
 static_assert(true, "");
 static_assert(false, ""); // expected-error{{failed}} ref-error{{failed}}
@@ -72,10 +74,74 @@
 constexpr const int* getIntPointer() {
   return &m;
 }
-//static_assert(getIntPointer() == &m, ""); TODO
-//static_assert(*getIntPointer() == 10, ""); TODO
+static_assert(getIntPointer() == &m, "");
+static_assert(*getIntPointer() == 10, "");
 
 constexpr int gimme(int k) {
   return k;
 }
-// static_assert(gimme(5) == 5, ""); TODO
+static_assert(gimme(5) == 5, "");
+
+namespace SizeOf {
+  constexpr int soint = sizeof(int);
+  constexpr int souint = sizeof(unsigned int);
+  static_assert(soint == souint, "");
+
+  static_assert(sizeof(&soint) == sizeof(void*), "");
+  static_assert(sizeof(&soint) == sizeof(nullptr), "");
+
+  static_assert(sizeof(long) == sizeof(unsigned long), "");
+  static_assert(sizeof(char) == sizeof(unsigned char), "");
+
+  constexpr int N = 4;
+  constexpr int arr[N] = {1,2,3,4};
+  static_assert(sizeof(arr) == N * sizeof(int), "");
+  static_assert(sizeof(arr) == N * sizeof(arr[0]), "");
+
+  constexpr bool arrB[N] = {true, true, true, true};
+  static_assert(sizeof(arrB) == N * sizeof(bool), "");
+
+  static_assert(sizeof(bool) == 1, "");
+  static_assert(sizeof(char) == 1, "");
+
+  constexpr int F = sizeof(void); // expected-error{{incomplete type 'void'}} \
+  // ref-error{{incomplete type 'void'}}
+
+  constexpr int F2 = sizeof(gimme); // expected-error{{to a function type}} \
+// ref-error{{to a function type}}
+
+
+
+  /// FIXME: The following code should be accepted.
+  struct S {
+void func();
+  };
+  constexpr void (S::*Func)() = &S::func; // expected-error {{must be initialized by a constant expression}} \
+  // expected-error {{interpreter failed to evaluate an expression}}
+  static_assert(sizeof(Func) == sizeof(&S::func), "");
+
+
+  void func() {
+int n = 12;
+constexpr int oofda = sizeof(int[n++]); // expected-error {{must be initialized by a constant expression}} \
+// ref-error {{must be initialized by a constant expression}}
+  }
+
+
+#if __cplusplus >= 202002L
+  /// FIXME: The following code should be accepted.
+  consteval int foo(int n) { // ref-error {{consteval function never produces a constant expression}}
+return sizeof(int[n]); // ref-note 3{{not valid in a constant expression}} \
+   // expected-note {{not valid in a constant expression}}
+  }
+  constinit int var = foo(5); // ref-error {{not a constant expression}} \
+  // ref-note 2{{in call to}} \
+  // ref-error {{does not have a constant initializer}} \
+  // ref-note {{required by 'constinit' specifier}} \
+  // expected-error  {{is not a constant expression}} \
+  // expected-note {{in call to}} \
+  // expected-error {{does not have a constant initializer}} \
+  // expected-note {{required by 'constinit' specifier}} \
+
+#endif
+};
Index: clang/lib/AST/Interp/Opcodes.td
===
--- clang/lib/AST/Interp/Opcodes.td
+++ clang/lib/AST/Interp/Opcodes.td
@@ -427,11 +427,11 @@
 // TODO: Expand this to handle casts between more types.
 
 def FromCastTypeClass : TypeClass {
-  let Types = [Uint32, Sint32, Bool];
+  let Types = [Uint8, Sint8, Uint16, Sint16, Uint32, Sint32, Uint64, Sint64, Bool];
 }
 
 def ToCastTypeClass : TypeClass {
-  let Types = [Uint32, Sint32, Bool];
+  let Types = [Uint8, Sint8, Uint16, Sint16, Uint32, Sint32, Uint64, Sint64, Bool];
 }
 
 def Cast: Opcode {
Index: clang/lib/AST/Interp/ByteCodeExprGen.h
===
--- clang/lib/AST/Interp/ByteCodeExprGen.h
+++ clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -80,6 +80,7 @@
   bool VisitArraySubscriptExpr(const ArraySubscriptExpr *E);
   bool VisitInitListExpr(const InitListExpr *E);
   

[clang] 00ce271 - [clang] extend getCommonSugaredType to merge sugar nodes

2022-09-16 Thread Matheus Izvekov via cfe-commits

Author: Matheus Izvekov
Date: 2022-09-16T17:04:10+02:00
New Revision: 00ce271712d407b5347681c36474b80cfb0033d3

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

LOG: [clang] extend getCommonSugaredType to merge sugar nodes

This continues D111283 by extending the getCommonSugaredType
implementation to also merge non-canonical type nodes.

We merge these nodes by going up starting from the canonical
node, calculating their merged properties on the way.

If we reach a pair that is too different, or which we could not
otherwise unify, we bail out and don't try to keep going on to
the next pair, in effect striping out all the remaining top-level
sugar nodes. This avoids mismatching 'companion' nodes, such as
ElaboratedType, so that they don't end up elaborating some other
unrelated thing.

Signed-off-by: Matheus Izvekov 

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/AST/ASTContext.h
clang/lib/AST/ASTContext.cpp
clang/lib/Sema/SemaTemplate.cpp
clang/lib/Sema/SemaTemplateDeduction.cpp
clang/test/SemaCXX/sugar-common-types.cpp
clang/test/SemaTemplate/deduction.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index f897c68b2c87c..e4648cd3b2879 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -156,6 +156,12 @@ Improvements to Clang's diagnostics
 - Clang will now give a more suitale diagnostic for declaration of block
   scope identifiers that have external/internal linkage that has an 
initializer.
   Fixes `Issue 57478: `_.
+- New analysis pass will now help preserve sugar when combining deductions, in 
an
+  order agnostic way. This will be in effect when deducing template arguments,
+  when deducing function return type from multiple return statements, for the
+  conditional operator, and for most binary operations. Type sugar is combined
+  in a way that strips the sugar which is 
diff erent between terms, and preserves
+  those which are common.
 
 Non-comprehensive list of changes in this release
 -

diff  --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index 39f5b4d2e85cc..c0228465322ee 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -1366,6 +1366,9 @@ class ASTContext : public RefCountedBase {
   CanQualType getDecayedType(CanQualType T) const {
 return CanQualType::CreateUnsafe(getDecayedType((QualType) T));
   }
+  /// Return the uniqued reference to a specified decay from the original
+  /// type to the decayed type.
+  QualType getDecayedType(QualType Orig, QualType Decayed) const;
 
   /// Return the uniqued reference to the atomic type for the specified
   /// type.

diff  --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index c3e6f741b73b0..c326435ba5f5f 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -3332,6 +3332,26 @@ QualType ASTContext::getAdjustedType(QualType Orig, 
QualType New) const {
   return QualType(AT, 0);
 }
 
+QualType ASTContext::getDecayedType(QualType Orig, QualType Decayed) const {
+  llvm::FoldingSetNodeID ID;
+  AdjustedType::Profile(ID, Orig, Decayed);
+  void *InsertPos = nullptr;
+  AdjustedType *AT = AdjustedTypes.FindNodeOrInsertPos(ID, InsertPos);
+  if (AT)
+return QualType(AT, 0);
+
+  QualType Canonical = getCanonicalType(Decayed);
+
+  // Get the new insert position for the node we care about.
+  AT = AdjustedTypes.FindNodeOrInsertPos(ID, InsertPos);
+  assert(!AT && "Shouldn't be in the map!");
+
+  AT = new (*this, TypeAlignment) DecayedType(Orig, Decayed, Canonical);
+  Types.push_back(AT);
+  AdjustedTypes.InsertNode(AT, InsertPos);
+  return QualType(AT, 0);
+}
+
 QualType ASTContext::getDecayedType(QualType T) const {
   assert((T->isArrayType() || T->isFunctionType()) && "T does not decay");
 
@@ -3352,23 +3372,7 @@ QualType ASTContext::getDecayedType(QualType T) const {
   if (T->isFunctionType())
 Decayed = getPointerType(T);
 
-  llvm::FoldingSetNodeID ID;
-  AdjustedType::Profile(ID, T, Decayed);
-  void *InsertPos = nullptr;
-  AdjustedType *AT = AdjustedTypes.FindNodeOrInsertPos(ID, InsertPos);
-  if (AT)
-return QualType(AT, 0);
-
-  QualType Canonical = getCanonicalType(Decayed);
-
-  // Get the new insert position for the node we care about.
-  AT = AdjustedTypes.FindNodeOrInsertPos(ID, InsertPos);
-  assert(!AT && "Shouldn't be in the map!");
-
-  AT = new (*this, TypeAlignment) DecayedType(T, Decayed, Canonical);
-  Types.push_back(AT);
-  AdjustedTypes.InsertNode(AT, InsertPos);
-  return QualType(AT,

[PATCH] D130308: [clang] extend getCommonSugaredType to merge sugar nodes

2022-09-16 Thread Matheus Izvekov via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rG00ce271712d4: [clang] extend getCommonSugaredType to merge 
sugar nodes (authored by mizvekov).

Changed prior to commit:
  https://reviews.llvm.org/D130308?vs=460588&id=460767#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130308

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/ASTContext.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/test/SemaCXX/sugar-common-types.cpp
  clang/test/SemaTemplate/deduction.cpp

Index: clang/test/SemaTemplate/deduction.cpp
===
--- clang/test/SemaTemplate/deduction.cpp
+++ clang/test/SemaTemplate/deduction.cpp
@@ -190,6 +190,14 @@
 }
 } // namespace test7
 
+namespace test8 {
+template  void foo(T);
+void test(int a) {
+char n[a];
+foo(n);
+}
+} // namespace test8
+
 // Verify that we can deduce enum-typed arguments correctly.
 namespace test14 {
   enum E { E0, E1 };
Index: clang/test/SemaCXX/sugar-common-types.cpp
===
--- clang/test/SemaCXX/sugar-common-types.cpp
+++ clang/test/SemaCXX/sugar-common-types.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++20 -fenable-matrix
+// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++20 -fenable-matrix -triple i686-pc-win32
 
 enum class N {};
 
@@ -38,3 +38,77 @@
 N t7 = X4() + Y4(); // expected-error {{rvalue of type 'B4'}}
 N t8 = X4() * Y4(); // expected-error {{rvalue of type 'B4'}}
 N t9 = X5() * Y5(); // expected-error {{rvalue of type 'A4 __attribute__((matrix_type(3, 3)))'}}
+
+template  struct S1 {
+  template  struct S2 {};
+};
+
+N t10 = 0 ? S1() : S1(); // expected-error {{from 'S1' (aka 'S1')}}
+N t11 = 0 ? S1::S2() : S1::S2(); // expected-error {{from 'S1::S2' (aka 'S2')}}
+
+template  using Al = S1;
+
+N t12 = 0 ? Al() : Al(); // expected-error {{from 'Al' (aka 'S1')}}
+
+#define AS1 __attribute__((address_space(1)))
+#define AS2 __attribute__((address_space(1)))
+using AS1X1 = AS1 B1;
+using AS1Y1 = AS1 B1;
+using AS2Y1 = AS2 B1;
+N t13 = 0 ? (AS1X1){} : (AS1Y1){}; // expected-error {{rvalue of type 'AS1 B1' (aka '__attribute__((address_space(1))) int')}}
+N t14 = 0 ? (AS1X1){} : (AS2Y1){}; // expected-error {{rvalue of type '__attribute__((address_space(1))) B1' (aka '__attribute__((address_space(1))) int')}}
+
+using FX1 = X1 ();
+using FY1 = Y1 ();
+N t15 = 0 ? (FX1*){} : (FY1*){}; // expected-error {{rvalue of type 'B1 (*)()' (aka 'int (*)()')}}
+
+struct SS1 {};
+using SB1 = SS1;
+using SX1 = SB1;
+using SY1 = SB1;
+
+using MFX1 = X1 SX1::*();
+using MFY1 = Y1 SY1::*();
+
+N t16 = 0 ? (MFX1*){} : (MFY1*){}; // expected-error {{rvalue of type 'B1 SB1::*(*)()'}}
+
+N t17 = 0 ? (FX1 SX1::*){} : (FY1 SY1::*){}; // expected-error {{rvalue of type 'B1 (SB1::*)() __attribute__((thiscall))'}}
+
+N t18 = 0 ? (__typeof(X1*)){} : (__typeof(Y1*)){}; // expected-error {{rvalue of type 'typeof(B1 *)' (aka 'int *')}}
+
+struct Enums {
+  enum X : B1;
+  enum Y : ::B1;
+};
+using EnumsB = Enums;
+using EnumsX = EnumsB;
+using EnumsY = EnumsB;
+
+N t19 = 0 ? (__underlying_type(EnumsX::X)){} : (__underlying_type(EnumsY::Y)){};
+// expected-error@-1 {{rvalue of type 'B1' (aka 'int')}}
+
+N t20 = 0 ? (__underlying_type(EnumsX::X)){} : (__underlying_type(EnumsY::X)){};
+// expected-error@-1 {{rvalue of type '__underlying_type(Enums::X)' (aka 'int')}}
+
+using SBTF1 = SS1 [[clang::btf_type_tag("1")]];
+using SBTF2 = ::SS1 [[clang::btf_type_tag("1")]];
+using SBTF3 = ::SS1 [[clang::btf_type_tag("2")]];
+
+N t21 = 0 ? (SBTF1){} : (SBTF3){}; // expected-error {{from 'SS1'}}
+N t22 = 0 ? (SBTF1){} : (SBTF2){}; // expected-error {{from 'SS1 btf_type_tag(1)' (aka 'SS1')}}
+
+using QX = const SB1 *;
+using QY = const ::SB1 *;
+N t23 = 0 ? (QX){} : (QY){}; // expected-error {{rvalue of type 'const SB1 *' (aka 'const SS1 *')}}
+
+template  using Alias = short;
+N t24 = 0 ? (Alias){} : (Alias){}; // expected-error {{rvalue of type 'Alias' (aka 'short')}}
+N t25 = 0 ? (Alias){} : (Alias){}; // expected-error {{rvalue of type 'short'}}
+
+template  concept C1 = true;
+template  concept C2 = true;
+C1 auto t26_1 = (SB1){};
+C1 auto t26_2 = (::SB1){};
+C2 auto t26_3 = (::SB1){};
+N t26 = 0 ? t26_1 : t26_2; // expected-error {{from 'SB1' (aka 'SS1')}}
+N t27 = 0 ? t26_1 : t26_3; // expected-error {{from 'SB1' (aka 'SS1')}}
Index: clang/lib/Sema/SemaTemplateDeduction.cpp
===
--- clang/lib/Sema/SemaTemplateDeduction.cpp
+++ clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -3825,13 +3825,11 @@
 //   - If A is an array type, the pointer type produced by the
 // array-to-pointer st

[PATCH] D134050: [clang][RISCV][NFC][WIP/RFC] Move riscv-abi.cpp and riscv32-*abi.c tests to use update_cc_test_checks.py

2022-09-16 Thread Alex Bradbury via Phabricator via cfe-commits
asb created this revision.
asb added reviewers: reames, craig.topper, luismarques, kito-cheng.
Herald added subscribers: wingo, sunshaoce, pmatos, VincentWu, StephenFan, 
vkmr, frasercrmck, evandro, apazos, sameer.abuasal, s.egerton, Jim, benna, 
psnobl, jocewei, PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, 
edward-jones, zzheng, jrtc27, shiva0217, niosHD, sabuasal, simoncook, 
johnrusso, rbar, arichardson.
Herald added a project: All.
asb requested review of this revision.
Herald added subscribers: pcwang-thead, eopXD, MaskRay.

I think our current set of ABI test files is organised about as well as it can 
be when relying on manual editing, but maintenance is error-prone and tedious. 
Having files containing tests that have the same signature for the ABIs 
indicated in the filename simplifies some things, but can create additional 
work when adding a new test that has behaviour that's worth testing across 
multiple ABI combinations. It's also not easy to tell at a glance whether a 
given function signature is tested across a sufficient set of ABIs, as you may 
need to look in multiple files to check for this.

This patch isn't ready for committing, and I don't propose committing it in its 
current form. As I've had to do some work on update_cc_test_checks.py to make 
it suitable for generating our ABI tests (see D133943 
) and will need to do further work to 
finalise this work, I wanted to get some feedback on the proposed direction.

This patch demonstrates the proposed direction I'd like to take these ABI tests 
in, with some caveats:

- Due to an update_cc_test_checks.py bug I haven't spent the time to track down 
and fix yet, I have to include at least one line from the function body for it 
to merge CHECK lines with the same content. I'd anticipate fixing this if we're 
agreed this is the right direction.
- riscv-abi.cpp is now generated using update_cc_test_checks.py, and also 
demonstrates the style of tests I'd like to move to - where all ABI variants 
are tested in a single file (potentially split by language features if it 
becomes too large) and we rely on update_cc_test_checks.py merging common CHECK 
lines for us.
- The riscv32-*abi.c tests are all regenerated using update_cc_test_checks.py. 
This represents the first step of my proposed changes - the next step would be 
to combine into one (or a small number of files based on language features / 
aspect of the ABI rather than target ABI variant) and use multiple RUN lines 
with overlapping check prefixes much like riscv-abi.cpp
  - It _probably_ makes sense to combine riscv32-*abi.c and riscv64*-abi.c 
tests - I've just made a start with riscv32* so as to get something for quick 
feedback

So - how do people feel about this direction? Potential options:

- Don't change existing tests and don't move to update_cc_test_checks
- Convert current tests to update_cc_test_checks but don't pursue any further 
refactoring/merging
- Convert current tests to update_cc_test_checks and then pursue something like 
I suggest above, combining more tests in the style of riscv-abi.cpp


https://reviews.llvm.org/D134050

Files:
  clang/test/CodeGen/RISCV/riscv-abi.cpp
  clang/test/CodeGen/RISCV/riscv32-ilp32-abi.c
  clang/test/CodeGen/RISCV/riscv32-ilp32-ilp32f-abi.c
  clang/test/CodeGen/RISCV/riscv32-ilp32-ilp32f-ilp32d-abi.c
  clang/test/CodeGen/RISCV/riscv32-ilp32d-abi.c
  clang/test/CodeGen/RISCV/riscv32-ilp32f-abi.c
  clang/test/CodeGen/RISCV/riscv32-ilp32f-ilp32d-abi.c
  clang/test/CodeGen/RISCV/riscv32-vararg.c

Index: clang/test/CodeGen/RISCV/riscv32-vararg.c
===
--- /dev/null
+++ clang/test/CodeGen/RISCV/riscv32-vararg.c
@@ -0,0 +1,294 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --function-signature
+// RUN: %clang_cc1 -triple riscv32 -emit-llvm %s -o - | FileCheck %s
+// RUN: %clang_cc1 -triple riscv32 -target-feature +f -target-abi ilp32f -emit-llvm %s -o - \
+// RUN: | FileCheck %s
+// RUN: %clang_cc1 -triple riscv32 -target-feature +d -target-feature +f -target-abi ilp32d -emit-llvm %s -o - \
+// RUN: | FileCheck %s
+
+#include 
+#include 
+
+struct tiny {
+  uint8_t a, b, c, d;
+};
+struct small {
+  int32_t a, *b;
+};
+struct small_aligned {
+  int64_t a;
+};
+struct large {
+  int32_t a, b, c, d;
+};
+
+// Ensure that ABI lowering happens as expected for vararg calls. For RV32
+// with the base integer calling convention there will be no observable
+// differences in the lowered IR for a call with varargs vs without.
+
+int f_va_callee(int, ...);
+
+// CHECK-LABEL: define dso_local void @f_va_caller
+// CHECK-SAME: () #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[DOTCOMPOUNDLITERAL:%.*]] = alloca [[STRUCT_TINY:%.*]], align 1
+// CHECK-NEXT:[[DOTCOMPOUNDLITERAL1:%.*]] = alloca [[STRUCT_SMALL:%.*]], align 4
+// CHECK-NEXT:[[DOTCOMPOUNDLITERAL4:%.*]] = alloca [[ST

[clang] 1b69ce1 - Currently the options ‘ffast-math’ and ‘ffp-contract’ are connected.

2022-09-16 Thread Zahira Ammarguellat via cfe-commits

Author: Zahira Ammarguellat
Date: 2022-09-16T11:08:41-04:00
New Revision: 1b69ce1208976c71bf7ee3932aa272462c1feb1b

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

LOG: Currently the options ‘ffast-math’ and ‘ffp-contract’ are connected.
When ‘ffast-math’ is set, ffp-contract is altered this way:
-ffast-math/ Ofast -> ffp-contract=fast
-fno-fast-math -> if ffp-contract= fast then ffp-contract=on else
ffp-contract unchanged

This differs from gcc which doesn’t connect the two options.

Connecting these two options in clang, resulted in spurious warnings
when the user combines these two options -ffast-math -fno-fast-math; see
issue https://github.com/llvm/llvm-project/issues/54625.

The issue is that the ‘ffast-math’ option is an on/off flag, but the
‘ffp-contract’ is an on/off/fast flag. So when ‘fno-fast-math’ is used
there is no obvious value for ‘ffp-contract’. What should the value of
ffp-contract be for -ffp-contract=fast -fno-fast-math and -ffast-math
-ffp-contract=fast -fno-fast-math? The current logic sets ffp-contract
back to on in these cases. This doesn’t take into account that the value
of ffp-contract is modified by an explicit ffp-contract` option.
This patch is proposing a set of rules to apply when ffp-contract',
ffast-math and fno-fast-math are combined. These rules would give the
user the expected behavior and no diagnostic would be needed.

See RFC
https://discourse.llvm.org/t/rfc-making-ffast-math-option-unrelated-to-ffp-contract-option/61912

Added: 
clang/test/Driver/fp-contract.c

Modified: 
clang/docs/UsersManual.rst
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/CodeGen/ffp-contract-option.c

Removed: 




diff  --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index e9c1be4cdd0f5..bc107be41fab8 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -1359,8 +1359,8 @@ floating point semantic models: precise (the default), 
strict, and fast.
   "fenv_access", "off", "on", "off"
   "rounding_mode", "tonearest", "dynamic", "tonearest"
   "contract", "on", "off", "fast"
-  "denormal_fp_math", "IEEE", "IEEE", "PreserveSign"
-  "denormal_fp32_math", "IEEE","IEEE", "PreserveSign"
+  "denormal_fp_math", "IEEE", "IEEE", "IEEE"
+  "denormal_fp32_math", "IEEE","IEEE", "IEEE"
   "support_math_errno", "on", "on", "off"
   "no_honor_nans", "off", "off", "on"
   "no_honor_infinities", "off", "off", "on"
@@ -1408,6 +1408,61 @@ floating point semantic models: precise (the default), 
strict, and fast.
 
* ``-ffp-contract=fast``
 
+   Note: ``-ffast-math`` causes ``crtfastmath.o`` to be linked with code. See
+   :ref:`crtfastmath.o` for more details.
+
+.. option:: -fno-fast-math
+
+   Disable fast-math mode.  This options disables unsafe floating-point
+   optimizations by preventing the compiler from making any tranformations that
+   could affect the results.
+
+   This option implies:
+
+   * ``-fhonor-infinities``
+
+   * ``-fhonor-nans``
+
+   * ``-fmath-errno``
+
+   * ``-fno-finite-math-only``
+
+   * ``-fno-associative-math``
+
+   * ``-fno-reciprocal-math``
+
+   * ``-fsigned-zeros``
+
+   * ``-fno-trapping-math``
+
+   * ``-ffp-contract=on``
+
+   * ``-fdenormal-fp-math=ieee``
+
+   There is ambiguity about how ``-ffp-contract``, ``-ffast-math``,
+   and ``-fno-fast-math`` behave in combination. To keep the value of
+   ``-ffp-contract`` consistent, we define this set of rules:
+
+   * ``-ffast-math`` sets ``ffp-contract`` to ``fast``.
+
+   * ``-fno-fast-math`` sets ``-ffp-contract`` to ``on`` (``fast`` for CUDA and
+ HIP).
+
+   * If ``-ffast-math`` and ``-ffp-contract`` are both seen, but
+ ``-ffast-math`` is not followed by ``-fno-fast-math``, ``ffp-contract``
+ will be given the value of whichever option was last seen.
+
+   * If ``-fno-fast-math`` is seen and ``-ffp-contract`` has been seen at least
+ once, the ``ffp-contract`` will get the value of the last seen value of
+ ``-ffp-contract``.
+
+   * If ``-fno-fast-math`` is seen and ``-ffp-contract`` has not been seen, the
+ ``-ffp-contract`` setting is determined by the default value of
+ ``-ffp-contract``.
+
+   Note: ``-fno-fast-math`` implies ``-fdenormal-fp-math=ieee``.
+   ``-fno-fast-math`` causes ``crtfastmath.o`` to not be linked with code.
+
 .. option:: -fdenormal-fp-math=
 
Select which denormal numbers the code is permitted to require.
@@ -1632,6 +1687,15 @@ Note that floating-point operations performed as part of 
constant initialization
has no effect because the optimizer is prohibited from making unsafe
transformations.
 
+.. _crtfastmath.o:
+
+A note about ``crtfastmath.o``
+^^
+``-ffast-math`` and ``-funsafe-math-optimizations`` cause ``crtfastmath.o`` to 
be
+automatical

[PATCH] D133853: [AST] Add msvc-specific C++11 attributes

2022-09-16 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a reviewer: erichkeane.
aaron.ballman added a subscriber: erichkeane.
aaron.ballman added a comment.

In D133853#3793284 , @RIscRIpt wrote:

> In D133853#3792518 , @aaron.ballman 
> wrote:
>
>> I'm wondering what the goal is for these changes. ... Are you intending to 
>> add semantics for these attributes in follow-up patches?
>
> To be honest, I wasn't planning to do any of follow-up patches. I made a 
> patch for internal usage at my job, and decided to submit it upstream.
> The main reason I (we) need this patch is that we need to be able to parse 
> MSVC-specific code (in the current case - detect `constexpr` functions). 
> Since Visual Studio 17.3 (MSVC 14.33.31629), Microsoft's STL library added 
> `[[msvc::constexpr]]` attribute, which is not documented yet, but makes a 
> function to act like a `constexpr` function: see this godbolt sample 
>  (i.e. forbids non-constexpr statements 
> inside).
>
> To make the patch complete, I decided to browse previous Microsoft's STL 
> versions and see which vendor specific (`msvc::`) attributes they added 
> previously; in this patch I added all attributes I was able to find.
>
>> We don't typically add attributes to Clang that don't have any effect unless 
>> there's a very compelling reason to do so.
>
> Theoretically, I could re-submit (or adjust this) patch, which would add 
> support for `[[msvc::constexpr]]` attribute with semantic meaning of 
> `constexpr` for functions (for code parsed with `-fms-extensions` flag). 
> Regarding other attributes - unfortunately they are either poorly documented, 
> or not documented at all, so I can drop commits for these attributes.
>
> *Edit:* Please, let me know how we can proceed - either I abandon the patch; 
> or add support only for `[[msvc::constexpr]]`, or any other way of proceeding 
> further?

Thanks for the information! Roping in @erichkeane as attribute code owner to 
make sure he's on board with the idea, but my suggestion is to only support 
`[[msvc::constexpr]]` with the semantic meaning of `constexpr`. It's a good 
question as to whether we want to support that only when passing 
`-fms-extensions` or not (it seems like a generally useful attribute); we don't 
do the same for GNU attributes, but maybe we don't want to follow that pattern? 
This will be the first attribute we add with the `msvc` vendor namespace.

If you find there's a good reason to upstream the other ones, we can certainly 
consider it. FWIW, one Microsoft-specific attribute I know people have been 
asking about is `[[msvc::no_unique_address]]`. See 
https://github.com/llvm/llvm-project/issues/49358 for more details. Not 
suggesting you're on the hook for that or anything, just pointing it out in 
case you wanted to work on that one at some point.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133853

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


[clang] 591452e - NFC: [clang] add template AST test for make_integer_seq and type_pack_element

2022-09-16 Thread Matheus Izvekov via cfe-commits

Author: Matheus Izvekov
Date: 2022-09-16T17:12:49+02:00
New Revision: 591452eb235f0bdf5c22ba635114bf1b8dc7d01c

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

LOG: NFC: [clang] add template AST test for make_integer_seq and 
type_pack_element

Signed-off-by: Matheus Izvekov 

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

Added: 
clang/test/SemaTemplate/make_integer_seq.cpp
clang/test/SemaTemplate/type_pack_element.cpp

Modified: 


Removed: 




diff  --git a/clang/test/SemaTemplate/make_integer_seq.cpp 
b/clang/test/SemaTemplate/make_integer_seq.cpp
new file mode 100644
index 0..78d66c702c038
--- /dev/null
+++ b/clang/test/SemaTemplate/make_integer_seq.cpp
@@ -0,0 +1,103 @@
+// RUN: %clang_cc1 -std=c++2b -fsyntax-only -triple x86_64-linux-gnu -ast-dump 
-verify -xc++ < %s | FileCheck %s
+
+template  struct A {};
+
+using test1 = __make_integer_seq;
+//  CHECK: |-TypeAliasDecl 0x{{[0-9A-Fa-f]+}}  col:7 
test1 '__make_integer_seq':'A'
+// CHECK-NEXT: | `-ElaboratedType 0x{{[0-9A-Fa-f]+}} '__make_integer_seq' sugar
+// CHECK-NEXT: |   `-TemplateSpecializationType 0x{{[0-9A-Fa-f]+}} 
'__make_integer_seq' sugar __make_integer_seq
+// CHECK-NEXT: | |-TemplateArgument template A
+// CHECK-NEXT: | |-TemplateArgument type 'int'
+// CHECK-NEXT: | | `-BuiltinType 0x{{[0-9A-Fa-f]+}} 'int'
+// CHECK-NEXT: | |-TemplateArgument expr
+// CHECK-NEXT: | | `-ConstantExpr 0x{{[0-9A-Fa-f]+}}  'int'
+// CHECK-NEXT: | |   |-value: Int 1
+// CHECK-NEXT: | |   `-IntegerLiteral 0x{{[0-9A-Fa-f]+}}  'int' 1
+// CHECK-NEXT: | `-RecordType 0x{{[0-9A-Fa-f]+}} 'A'
+// CHECK-NEXT: |   `-ClassTemplateSpecialization 0x{{[0-9A-Fa-f]+}} 'A'
+
+template  using B = __make_integer_seq;
+using test2 = B;
+//  CHECK: |-TypeAliasDecl 0x{{[0-9A-Fa-f]+}}  col:7 
test2 'B':'A'
+// CHECK-NEXT:   `-ElaboratedType 0x{{[0-9A-Fa-f]+}} 'B' sugar
+// CHECK-NEXT: `-TemplateSpecializationType 0x{{[0-9A-Fa-f]+}} 'B' 
sugar alias B
+// CHECK-NEXT:   |-TemplateArgument type 'int'
+// CHECK-NEXT:   | `-BuiltinType 0x{{[0-9A-Fa-f]+}} 'int'
+// CHECK-NEXT:   |-TemplateArgument expr
+// CHECK-NEXT:   | `-ConstantExpr 0x{{[0-9A-Fa-f]+}}  'int'
+// CHECK-NEXT:   |   |-value: Int 1
+// CHECK-NEXT:   |   `-IntegerLiteral 0x{{[0-9A-Fa-f]+}}  'int' 1
+// CHECK-NEXT:   `-ElaboratedType 0x{{[0-9A-Fa-f]+}} 
'__make_integer_seq' sugar
+// CHECK-NEXT: `-TemplateSpecializationType 0x{{[0-9A-Fa-f]+}} 
'__make_integer_seq' sugar __make_integer_seq
+// CHECK-NEXT:   |-TemplateArgument template A
+// CHECK-NEXT:   |-TemplateArgument type 'int':'int'
+// CHECK-NEXT:   | `-SubstTemplateTypeParmType 0x{{[0-9A-Fa-f]+}} 
'int' sugar
+// CHECK-NEXT:   |   |-TemplateTypeParmType 0x{{[0-9A-Fa-f]+}} 'B1' 
dependent depth 0 index 0
+// CHECK-NEXT:   |   | `-TemplateTypeParm 0x{{[0-9A-Fa-f]+}} 'B1'
+// CHECK-NEXT:   |   `-BuiltinType 0x{{[0-9A-Fa-f]+}} 'int'
+// CHECK-NEXT:   |-TemplateArgument expr
+// CHECK-NEXT:   | `-ConstantExpr 0x{{[0-9A-Fa-f]+}}  'int'
+// CHECK-NEXT:   |   |-value: Int 1
+// CHECK-NEXT:   |   `-SubstNonTypeTemplateParmExpr 0x{{[0-9A-Fa-f]+}} 
 'int'
+// CHECK-NEXT:   | |-NonTypeTemplateParmDecl 0x{{[0-9A-Fa-f]+}} 
 col:24 referenced 'B1' depth 0 index 1 B2
+// CHECK-NEXT:   | `-IntegerLiteral 0x{{[0-9A-Fa-f]+}}  
'int' 1
+// CHECK-NEXT:   `-RecordType 0x{{[0-9A-Fa-f]+}} 'A'
+// CHECK-NEXT: `-ClassTemplateSpecialization 0x{{[0-9A-Fa-f]+}} 'A'
+
+template  class S, class T, int N> struct C {
+  using test3 = __make_integer_seq;
+//  CHECK: |-TypeAliasDecl 0x{{[0-9A-Fa-f]+}}  col:9 
test3 '__make_integer_seq':'__make_integer_seq'
+// CHECK-NEXT:   `-ElaboratedType 0x{{[0-9A-Fa-f]+}} '__make_integer_seq' sugar dependent
+// CHECK-NEXT: `-TemplateSpecializationType 0x{{[0-9A-Fa-f]+}} 
'__make_integer_seq' dependent __make_integer_seq
+// CHECK-NEXT:   |-TemplateArgument template S
+// CHECK-NEXT:   |-TemplateArgument type 'T'
+// CHECK-NEXT:   | `-TemplateTypeParmType 0x{{[0-9A-Fa-f]+}} 'T' dependent 
depth 0 index 1
+// CHECK-NEXT:   |   `-TemplateTypeParm 0x{{[0-9A-Fa-f]+}} 'T'
+// CHECK-NEXT:   `-TemplateArgument expr
+// CHECK-NEXT: `-ImplicitCastExpr 0x{{[0-9A-Fa-f]+}}  
'type-parameter-0-1':'type-parameter-0-1' 
+// CHECK-NEXT:   `-DeclRefExpr 0x{{[0-9A-Fa-f]+}}  'int' 
NonTypeTemplateParm 0x{{[0-9A-Fa-f]+}} 'N' 'int'
+
+  using test4 = __make_integer_seq;
+//  CHECK: |-TypeAliasDecl 0x{{[0-9A-Fa-f]+}}  col:9 
test4 '__make_integer_seq':'__make_integer_seq'
+// CHECK-NEXT:   `-ElaboratedType 0x{{[0-9A-Fa-f]+}} '__make_integer_seq' sugar dependent
+// CHECK-NE

[PATCH] D133261: NFC: [clang] add template AST test for make_integer_seq and type_pack_element

2022-09-16 Thread Matheus Izvekov via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rG591452eb235f: NFC: [clang] add template AST test for 
make_integer_seq and type_pack_element (authored by mizvekov).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133261

Files:
  clang/test/SemaTemplate/make_integer_seq.cpp
  clang/test/SemaTemplate/type_pack_element.cpp

Index: clang/test/SemaTemplate/type_pack_element.cpp
===
--- /dev/null
+++ clang/test/SemaTemplate/type_pack_element.cpp
@@ -0,0 +1,68 @@
+// RUN: %clang_cc1 -std=c++2b -fsyntax-only -triple x86_64-linux-gnu -ast-dump -verify -xc++ < %s | FileCheck %s
+
+using test1 = __type_pack_element<0, int>;
+//  CHECK: |-TypeAliasDecl 0x{{[0-9A-Fa-f]+}} <:3:1, col:41> col:7 test1 '__type_pack_element<0, int>':'int'
+// CHECK-NEXT:   `-ElaboratedType 0x{{[0-9A-Fa-f]+}} '__type_pack_element<0, int>' sugar
+// CHECK-NEXT: `-TemplateSpecializationType 0x{{[0-9A-Fa-f]+}} '__type_pack_element<0, int>' sugar __type_pack_element
+// CHECK-NEXT:   |-TemplateArgument expr
+// CHECK-NEXT:   | `-ConstantExpr 0x{{[0-9A-Fa-f]+}}  'unsigned long'
+// CHECK-NEXT:   |   |-value: Int 0
+// CHECK-NEXT:   |   `-ImplicitCastExpr 0x{{[0-9A-Fa-f]+}}  'unsigned long' 
+// CHECK-NEXT:   | `-IntegerLiteral 0x{{[0-9A-Fa-f]+}}  'int' 0
+// CHECK-NEXT:   |-TemplateArgument type 'int'
+// CHECK-NEXT:   | `-BuiltinType 0x{{[0-9A-Fa-f]+}} 'int'
+// CHECK-NEXT:   `-BuiltinType 0x{{[0-9A-Fa-f]+}} 'int'
+
+template struct A {
+  using test2 = __type_pack_element;
+//  CHECK: |-TypeAliasDecl 0x{{[0-9A-Fa-f]+}}  col:9 test2 '__type_pack_element':'__type_pack_element'
+// CHECK-NEXT:   `-ElaboratedType 0x{{[0-9A-Fa-f]+}} '__type_pack_element' sugar dependent
+// CHECK-NEXT: `-TemplateSpecializationType 0x{{[0-9A-Fa-f]+}} '__type_pack_element' dependent __type_pack_element
+// CHECK-NEXT:   |-TemplateArgument expr
+// CHECK-NEXT:   | `-ImplicitCastExpr 0x{{[0-9A-Fa-f]+}}  'unsigned long' 
+// CHECK-NEXT:   |   `-DeclRefExpr 0x{{[0-9A-Fa-f]+}}  'int' NonTypeTemplateParm 0x{{[0-9A-Fa-f]+}} 'N' 'int'
+// CHECK-NEXT:   `-TemplateArgument type 'Ts...'
+// CHECK-NEXT: `-PackExpansionType 0x{{[0-9A-Fa-f]+}} 'Ts...' dependent
+// CHECK-NEXT:   `-TemplateTypeParmType 0x{{[0-9A-Fa-f]+}} 'Ts' dependent contains_unexpanded_pack depth 0 index 1 pack
+// CHECK-NEXT: `-TemplateTypeParm 0x{{[0-9A-Fa-f]+}} 'Ts'
+
+  using test3 = __type_pack_element<0, Ts...>;
+//  CHECK: |-TypeAliasDecl 0x{{[0-9A-Fa-f]+}}  col:9 test3 '__type_pack_element<0, Ts...>':'__type_pack_element<0, Ts...>'
+// CHECK-NEXT:   `-ElaboratedType 0x{{[0-9A-Fa-f]+}} '__type_pack_element<0, Ts...>' sugar dependent
+// CHECK-NEXT: `-TemplateSpecializationType 0x{{[0-9A-Fa-f]+}} '__type_pack_element<0, Ts...>' dependent __type_pack_element
+// CHECK-NEXT:   |-TemplateArgument expr
+// CHECK-NEXT:   | `-ConstantExpr 0x{{[0-9A-Fa-f]+}}  'unsigned long'
+// CHECK-NEXT:   |   |-value: Int 0
+// CHECK-NEXT:   |   `-ImplicitCastExpr 0x{{[0-9A-Fa-f]+}}  'unsigned long' 
+// CHECK-NEXT:   | `-IntegerLiteral 0x{{[0-9A-Fa-f]+}}  'int' 0
+// CHECK-NEXT:   `-TemplateArgument type 'Ts...'
+// CHECK-NEXT: `-PackExpansionType 0x{{[0-9A-Fa-f]+}} 'Ts...' dependent
+// CHECK-NEXT:   `-TemplateTypeParmType 0x{{[0-9A-Fa-f]+}} 'Ts' dependent contains_unexpanded_pack depth 0 index 1 pack
+// CHECK-NEXT: `-TemplateTypeParm 0x{{[0-9A-Fa-f]+}} 'Ts'
+
+  using test4 = __type_pack_element;
+//  CHECK: `-TypeAliasDecl 0x{{[0-9A-Fa-f]+}}  col:9 test4 '__type_pack_element':'__type_pack_element'
+// CHECK-NEXT:   `-ElaboratedType 0x{{[0-9A-Fa-f]+}} '__type_pack_element' sugar dependent
+// CHECK-NEXT: `-TemplateSpecializationType 0x{{[0-9A-Fa-f]+}} '__type_pack_element' dependent __type_pack_element
+// CHECK-NEXT:   |-TemplateArgument expr
+// CHECK-NEXT:   | `-ImplicitCastExpr 0x{{[0-9A-Fa-f]+}}  'unsigned long' 
+// CHECK-NEXT:   |   `-DeclRefExpr 0x{{[0-9A-Fa-f]+}}  'int' NonTypeTemplateParm 0x{{[0-9A-Fa-f]+}} 'N' 'int'
+// CHECK-NEXT:   `-TemplateArgument type 'int'
+// CHECK-NEXT: `-BuiltinType 0x{{[0-9A-Fa-f]+}} 'int'
+};
+
+template  struct B; // expected-note {{template is declared here}}
+template  struct B> {};
+template struct B; // expected-error {{explicit instantiation of undefined template}}
+
+template  struct C; // expected-note {{template is declared here}}
+template  struct C> {};
+template struct C; // expected-error {{explicit instantiation of undefined template}}
+
+template  struct D;
+template  struct D<__type_pack_element<0, T, U>> {};
+template  struct D<__type_pack_element<0, U, T>> {};
+
+template  struct E;
+template  struct E<__

[PATCH] D133725: Searching for tokens including comments

2022-09-16 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.

Ah, thank you for the extra description, that helped a lot. The changes LGTM, 
though you should hold off on landing them until we're sure the clang-tidy 
changes are going in.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133725

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


[PATCH] D133853: [AST] Add msvc-specific C++11 attributes

2022-09-16 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

In D133853#3795579 , @aaron.ballman 
wrote:

> In D133853#3793284 , @RIscRIpt 
> wrote:
>
>> In D133853#3792518 , 
>> @aaron.ballman wrote:
>>
>>> I'm wondering what the goal is for these changes. ... Are you intending to 
>>> add semantics for these attributes in follow-up patches?
>>
>> To be honest, I wasn't planning to do any of follow-up patches. I made a 
>> patch for internal usage at my job, and decided to submit it upstream.
>> The main reason I (we) need this patch is that we need to be able to parse 
>> MSVC-specific code (in the current case - detect `constexpr` functions). 
>> Since Visual Studio 17.3 (MSVC 14.33.31629), Microsoft's STL library added 
>> `[[msvc::constexpr]]` attribute, which is not documented yet, but makes a 
>> function to act like a `constexpr` function: see this godbolt sample 
>>  (i.e. forbids non-constexpr statements 
>> inside).
>>
>> To make the patch complete, I decided to browse previous Microsoft's STL 
>> versions and see which vendor specific (`msvc::`) attributes they added 
>> previously; in this patch I added all attributes I was able to find.
>>
>>> We don't typically add attributes to Clang that don't have any effect 
>>> unless there's a very compelling reason to do so.
>>
>> Theoretically, I could re-submit (or adjust this) patch, which would add 
>> support for `[[msvc::constexpr]]` attribute with semantic meaning of 
>> `constexpr` for functions (for code parsed with `-fms-extensions` flag). 
>> Regarding other attributes - unfortunately they are either poorly 
>> documented, or not documented at all, so I can drop commits for these 
>> attributes.
>>
>> *Edit:* Please, let me know how we can proceed - either I abandon the patch; 
>> or add support only for `[[msvc::constexpr]]`, or any other way of 
>> proceeding further?
>
> Thanks for the information! Roping in @erichkeane as attribute code owner to 
> make sure he's on board with the idea, but my suggestion is to only support 
> `[[msvc::constexpr]]` with the semantic meaning of `constexpr`. It's a good 
> question as to whether we want to support that only when passing 
> `-fms-extensions` or not (it seems like a generally useful attribute); we 
> don't do the same for GNU attributes, but maybe we don't want to follow that 
> pattern? This will be the first attribute we add with the `msvc` vendor 
> namespace.
>
> If you find there's a good reason to upstream the other ones, we can 
> certainly consider it. FWIW, one Microsoft-specific attribute I know people 
> have been asking about is `[[msvc::no_unique_address]]`. See 
> https://github.com/llvm/llvm-project/issues/49358 for more details. Not 
> suggesting you're on the hook for that or anything, just pointing it out in 
> case you wanted to work on that one at some point.

I agree with Aaron here, there isn't much value in the "do nothing" attributes, 
I believe the 'unknown attribute' warning for them is superior to an ignored 
attribute.

A functional `msvc::constexpr` would be acceptable, however, I'm having a 
difficult time figuring out the purpose of it, it seems like it is just a 
'constepr keyword' replacement?




Comment at: clang/lib/Sema/SemaStmtAttr.cpp:296
+  // Validation is in Sema::ActOnAttributedStmt().
+  return ::new (S.Context) MSConstexprAttr(S.Context, A);
+}

Typically we try to do the ::Create function that is generated for attributes, 
rather than placement new.  I realize we are consistently inconsistent...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133853

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


[PATCH] D133443: [RISCV][MC] Add support for experimental Zawrs extension

2022-09-16 Thread Alex Bradbury via Phabricator via cfe-commits
asb requested changes to this revision.
asb added a comment.
This revision now requires changes to proceed.

Everything that's in this patch looks good to me - it's just missing some 
simple round-trip tests in the style of rv32zicboz-valid.s (and perhaps an 
-invalid.s that shows a sensible error message being produced when the 
instructions have an argument).

In terms of which *.td file to edit - RISCVInstrInfoA.td is another 
possibility. The plan had been that for the `z?foo` extensions, the letter 
after the z indicated which of the top-level extensions it was most relevant to 
- e.g. the zc* extensions (ztso predated this idea). I don't mind much either 
way - I'm happy with it in either location.


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

https://reviews.llvm.org/D133443

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


[PATCH] D133634: [clang] Allow vector of BitInt

2022-09-16 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:3024
 def err_attribute_invalid_vector_type : Error<"invalid vector element type 
%0">;
+def err_attribute_invalid_bitint_vector_type : Error<"invalid vector element 
type %0, must be byte-sized and power of 2 _BitInt">;
 def err_attribute_invalid_matrix_type : Error<"invalid matrix element type 
%0">;

We might as well spell out the failure conditions and make a more readable 
diagnostic.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133634

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


[PATCH] D134034: [test] Use host platform specific error message substitution

2022-09-16 Thread Zibi Sarbino via Phabricator via cfe-commits
zibi accepted this revision.
zibi added a comment.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134034

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


[clang] f4ea3bd - [clang] Fixes how we represent / emulate builtin templates

2022-09-16 Thread Matheus Izvekov via cfe-commits

Author: Matheus Izvekov
Date: 2022-09-16T17:44:12+02:00
New Revision: f4ea3bd4b2086e6de10131b197aaf7d066a24df8

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

LOG: [clang] Fixes how we represent / emulate builtin templates

We change the template specialization of builtin templates to
behave like aliases.

Though unlike real alias templates, these might still produce a canonical
TemplateSpecializationType when some important argument is dependent.

For example, we can't do anything about make_integer_seq when the
count is dependent, or a type_pack_element when the index is dependent.

We change type deduction to not try to deduce canonical TSTs of
builtin templates.

We also change those buitin templates to produce substitution sugar,
just like a real instantiation would, making the resulting type correctly
represent the template arguments used to specialize the underlying template.

And make_integer_seq will now produce a TST for the specialization
of it's first argument, which we use as the underlying type of
the builtin alias.

When performing member access on the resulting type, it's now
possible to map from a Subst* node to the template argument
as-written used in a regular fashion, without special casing.

And this fixes a bunch of bugs with relation to these builtin
templates factoring into deduction.

Fixes GH42102 and GH51928.

Depends on D133261

Signed-off-by: Matheus Izvekov 

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/AST/ASTContext.h
clang/include/clang/AST/DeclTemplate.h
clang/lib/AST/ASTContext.cpp
clang/lib/AST/DeclTemplate.cpp
clang/lib/CodeGen/CGDebugInfo.cpp
clang/lib/Sema/SemaTemplate.cpp
clang/lib/Sema/SemaTemplateDeduction.cpp
clang/test/SemaTemplate/make_integer_seq.cpp
clang/test/SemaTemplate/type_pack_element.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index e4648cd3b2879..1ec21a7b3acec 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -122,6 +122,9 @@ Bug Fixes
 - Clang will now no longer treat a C 'overloadable' function without a 
prototype as
   a variadic function with the attribute.  This should make further 
diagnostics more
   clear.
+- Fixes to builtin template emulation of regular templates.
+  `Issue 42102 `_
+  `Issue 51928 `_
 
 
 Improvements to Clang's diagnostics

diff  --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index c0228465322ee..14661ecc0c09c 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -1636,7 +1636,7 @@ class ASTContext : public RefCountedBase {
  ArrayRef Args) 
const;
 
   QualType getTemplateSpecializationType(TemplateName T,
- const TemplateArgumentListInfo &Args,
+ ArrayRef Args,
  QualType Canon = QualType()) const;
 
   TypeSourceInfo *

diff  --git a/clang/include/clang/AST/DeclTemplate.h 
b/clang/include/clang/AST/DeclTemplate.h
index baed5ca22fa75..dbea107f368fb 100644
--- a/clang/include/clang/AST/DeclTemplate.h
+++ b/clang/include/clang/AST/DeclTemplate.h
@@ -440,6 +440,9 @@ class TemplateDecl : public NamedDecl {
   /// Get the underlying, templated declaration.
   NamedDecl *getTemplatedDecl() const { return TemplatedDecl; }
 
+  // Should a specialization behave like an alias for another type.
+  bool isTypeAlias() const;
+
   // Implement isa/cast/dyncast/etc.
   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
 

diff  --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index c326435ba5f5f..5bf03d8f3c3aa 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -4848,7 +4848,8 @@ 
ASTContext::getTemplateSpecializationTypeInfo(TemplateName Name,
   QualType Underlying) const {
   assert(!Name.getAsDependentTemplateName() &&
  "No dependent template names here!");
-  QualType TST = getTemplateSpecializationType(Name, Args, Underlying);
+  QualType TST =
+  getTemplateSpecializationType(Name, Args.arguments(), Underlying);
 
   TypeSourceInfo *DI = CreateTypeSourceInfo(TST);
   TemplateSpecializationTypeLoc TL =
@@ -4864,14 +4865,14 @@ 
ASTContext::getTemplateSpecializationTypeInfo(TemplateName Name,
 
 QualType
 ASTContext::getTemplateSpecializationType(TemplateName Template,
-  const TemplateArgumentListInfo &Args,
+   

[PATCH] D133262: [clang] Fixes how we represent / emulate builtin templates

2022-09-16 Thread Matheus Izvekov via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf4ea3bd4b208: [clang] Fixes how we represent / emulate 
builtin templates (authored by mizvekov).

Changed prior to commit:
  https://reviews.llvm.org/D133262?vs=460590&id=460785#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133262

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/DeclTemplate.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/DeclTemplate.cpp
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/test/SemaTemplate/make_integer_seq.cpp
  clang/test/SemaTemplate/type_pack_element.cpp

Index: clang/test/SemaTemplate/type_pack_element.cpp
===
--- clang/test/SemaTemplate/type_pack_element.cpp
+++ clang/test/SemaTemplate/type_pack_element.cpp
@@ -3,7 +3,7 @@
 using test1 = __type_pack_element<0, int>;
 //  CHECK: |-TypeAliasDecl 0x{{[0-9A-Fa-f]+}} <:3:1, col:41> col:7 test1 '__type_pack_element<0, int>':'int'
 // CHECK-NEXT:   `-ElaboratedType 0x{{[0-9A-Fa-f]+}} '__type_pack_element<0, int>' sugar
-// CHECK-NEXT: `-TemplateSpecializationType 0x{{[0-9A-Fa-f]+}} '__type_pack_element<0, int>' sugar __type_pack_element
+// CHECK-NEXT: `-TemplateSpecializationType 0x{{[0-9A-Fa-f]+}} '__type_pack_element<0, int>' sugar alias __type_pack_element
 // CHECK-NEXT:   |-TemplateArgument expr
 // CHECK-NEXT:   | `-ConstantExpr 0x{{[0-9A-Fa-f]+}}  'unsigned long'
 // CHECK-NEXT:   |   |-value: Int 0
@@ -11,53 +11,79 @@
 // CHECK-NEXT:   | `-IntegerLiteral 0x{{[0-9A-Fa-f]+}}  'int' 0
 // CHECK-NEXT:   |-TemplateArgument type 'int'
 // CHECK-NEXT:   | `-BuiltinType 0x{{[0-9A-Fa-f]+}} 'int'
-// CHECK-NEXT:   `-BuiltinType 0x{{[0-9A-Fa-f]+}} 'int'
+// CHECK-NEXT:   `-SubstTemplateTypeParmType 0x{{[0-9A-Fa-f]+}} 'int' sugar
+// CHECK-NEXT: |-TemplateTypeParmType 0x{{[0-9A-Fa-f]+}} 'auto' dependent depth 0 index 1
+// CHECK-NEXT: | `-TemplateTypeParm 0x{{[0-9A-Fa-f]+}} ''
+// CHECK-NEXT: `-BuiltinType 0x{{[0-9A-Fa-f]+}} 'int'
 
 template struct A {
   using test2 = __type_pack_element;
-//  CHECK: |-TypeAliasDecl 0x{{[0-9A-Fa-f]+}}  col:9 test2 '__type_pack_element':'__type_pack_element'
+//  CHECK: |-TypeAliasDecl 0x{{[0-9A-Fa-f]+}}  col:9 test2 '__type_pack_element':'__type_pack_element'
 // CHECK-NEXT:   `-ElaboratedType 0x{{[0-9A-Fa-f]+}} '__type_pack_element' sugar dependent
-// CHECK-NEXT: `-TemplateSpecializationType 0x{{[0-9A-Fa-f]+}} '__type_pack_element' dependent __type_pack_element
+// CHECK-NEXT: `-TemplateSpecializationType 0x{{[0-9A-Fa-f]+}} '__type_pack_element' sugar dependent alias __type_pack_element
 // CHECK-NEXT:   |-TemplateArgument expr
 // CHECK-NEXT:   | `-ImplicitCastExpr 0x{{[0-9A-Fa-f]+}}  'unsigned long' 
 // CHECK-NEXT:   |   `-DeclRefExpr 0x{{[0-9A-Fa-f]+}}  'int' NonTypeTemplateParm 0x{{[0-9A-Fa-f]+}} 'N' 'int'
-// CHECK-NEXT:   `-TemplateArgument type 'Ts...'
-// CHECK-NEXT: `-PackExpansionType 0x{{[0-9A-Fa-f]+}} 'Ts...' dependent
-// CHECK-NEXT:   `-TemplateTypeParmType 0x{{[0-9A-Fa-f]+}} 'Ts' dependent contains_unexpanded_pack depth 0 index 1 pack
-// CHECK-NEXT: `-TemplateTypeParm 0x{{[0-9A-Fa-f]+}} 'Ts'
+// CHECK-NEXT:   |-TemplateArgument type 'Ts...'
+// CHECK-NEXT:   | `-PackExpansionType 0x{{[0-9A-Fa-f]+}} 'Ts...' dependent
+// CHECK-NEXT:   |   `-TemplateTypeParmType 0x{{[0-9A-Fa-f]+}} 'Ts' dependent contains_unexpanded_pack depth 0 index 1 pack
+// CHECK-NEXT:   | `-TemplateTypeParm 0x{{[0-9A-Fa-f]+}} 'Ts'
+// CHECK-NEXT:   `-TemplateSpecializationType 0x{{[0-9A-Fa-f]+}} '__type_pack_element' dependent __type_pack_element
+// CHECK-NEXT: |-TemplateArgument expr
+// CHECK-NEXT: | `-ImplicitCastExpr 0x{{[0-9A-Fa-f]+}}  'unsigned long' 
+// CHECK-NEXT: |   `-DeclRefExpr 0x{{[0-9A-Fa-f]+}}  'int' NonTypeTemplateParm 0x{{[0-9A-Fa-f]+}} 'N' 'int'
+// CHECK-NEXT: `-TemplateArgument pack
+// CHECK-NEXT:   `-TemplateArgument type 'type-parameter-0-1...'
+// CHECK-NEXT: `-PackExpansionType 0x{{[0-9A-Fa-f]+}} 'type-parameter-0-1...' dependent
+// CHECK-NEXT:   `-TemplateTypeParmType 0x{{[0-9A-Fa-f]+}} 'type-parameter-0-1' dependent contains_unexpanded_pack depth 0 index 1 pack
 
   using test3 = __type_pack_element<0, Ts...>;
-//  CHECK: |-TypeAliasDecl 0x{{[0-9A-Fa-f]+}}  col:9 test3 '__type_pack_element<0, Ts...>':'__type_pack_element<0, Ts...>'
+//  CHECK: |-TypeAliasDecl 0x{{[0-9A-Fa-f]+}}  col:9 test3 '__type_pack_element<0, Ts...>':'__type_pack_element<0, type-parameter-0-1...>'
 // CHECK-NEXT:   `-ElaboratedType

[PATCH] D134052: [clang-format] Disallow requires clauses to become function declarations

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

There already exists logic to disallow requires *expressions* to be
treated as function declarations, but this expands it to include
requires *clauses*, when they happen to also be parenthesized.

Previously, in the following case:

  template 
requires(Foo)
  T foo();

The line with the requires clause was actually being considered as the
line with the function declaration due to the parentheses, and the
*real* function declaration on the next line became a trailing
annotation

(Together with https://reviews.llvm.org/D134049) Fixes 
https://github.com/llvm/llvm-project/issues/56213


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D134052

Files:
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/TokenAnnotatorTest.cpp


Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -728,6 +728,16 @@
   BaseTokenCount = 26;
   TestRequires(__LINE__);
 
+  BaseCode = "template\n"
+ "T foo();";
+  ConstrainedCode = "template\n"
+"  requires(Foo)\n"
+"T foo();";
+  BaseTokenCount = 11;
+  RequiresTokenCount = 7;
+  PrefixTokenCount = 5;
+  TestRequires(__LINE__);
+
   BaseCode = "template\n"
  "Bar(T) -> Bar;";
   ConstrainedCode = "template\n"
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -1110,7 +1110,7 @@
   !Contexts.back().IsExpression && !Line.startsWith(TT_ObjCProperty) &&
   !Tok->isOneOf(TT_TypeDeclarationParen, TT_RequiresExpressionLParen) 
&&
   (!Tok->Previous ||
-   !Tok->Previous->isOneOf(tok::kw___attribute,
+   !Tok->Previous->isOneOf(tok::kw___attribute, TT_RequiresClause,
TT_LeadingJavaAnnotation))) {
 Line.MightBeFunctionDecl = true;
   }


Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -728,6 +728,16 @@
   BaseTokenCount = 26;
   TestRequires(__LINE__);
 
+  BaseCode = "template\n"
+ "T foo();";
+  ConstrainedCode = "template\n"
+"  requires(Foo)\n"
+"T foo();";
+  BaseTokenCount = 11;
+  RequiresTokenCount = 7;
+  PrefixTokenCount = 5;
+  TestRequires(__LINE__);
+
   BaseCode = "template\n"
  "Bar(T) -> Bar;";
   ConstrainedCode = "template\n"
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -1110,7 +1110,7 @@
   !Contexts.back().IsExpression && !Line.startsWith(TT_ObjCProperty) &&
   !Tok->isOneOf(TT_TypeDeclarationParen, TT_RequiresExpressionLParen) &&
   (!Tok->Previous ||
-   !Tok->Previous->isOneOf(tok::kw___attribute,
+   !Tok->Previous->isOneOf(tok::kw___attribute, TT_RequiresClause,
TT_LeadingJavaAnnotation))) {
 Line.MightBeFunctionDecl = true;
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D128462: [HLSL] add -I option for dxc mode.

2022-09-16 Thread Chris Bieneman via Phabricator via cfe-commits
beanz added a comment.

I understand your frustration with the regression, but let’s try to 
constructive. We all care about quality and we’re all working hard to do the 
best we can.

In D128462#3794868 , @kadircet wrote:

> My main complaint here's around **breaking** functionality for existing 
> driver-modes/toolchains, and I am asking either getting OWNERS approvals 
> going forward or being more through with the changes or changing the design 
> overall to make these less complicated.

Regressions happen. There are things we can do to avoid them (code review being 
one), but the most fool-proof way to avoid regressions is test coverage. Here 
we had a gap in test coverage of existing functionality. A new change went in, 
all the tests passed, but an important usage regression occurred. It is 
unfortunate, but it happened.

Getting owner approval before commit has never been required by our developer 
policy. In fact, the wording of the policy puts the onus on the owner for 
post-commit review. In this case we had a fairly innocuous seeming change by a 
relatively new contributor and I reviewed and approved it because it seemed 
fairly innocuous. This said, hopefully the recent changes in Clang code 
ownership will help here too.

This change was tested, and introduces a new test in accordance with our 
community standards and policy.

I don’t think it is fair to say this change contributed to a complicated design 
other than that llvm’s libOption is pretty complicated and has lots of 
difficult to see edge cases, and the tools that share option parsing logic 
often have disparate and duplicated logic for handing those options which can 
cause a variety of issues.

In terms of your other complaints around bug handling; I also understand 
frustration there. Unfortunately, clangd has a separate bug reporting and 
tracking process from the rest of the LLVM and Clang code it depends on. I’m 
sure it is frustrating to get bug reports that relate to code you didn’t write 
or design, but I think that is a reality of the process and complexity of the 
software that we have today. It is incredibly common in LLVM for bugs to get 
routed to the wrong area and need to be rerouted. Sometimes this is because 
users reporting issues don’t understand the architecture of the code base well 
enough to route to the right place, other times it is because the cultural 
boundaries of responsibility in LLVM aren’t well codified.

In order to support the incremental implementation process that LLVM has always 
used we need a way to be able to add driver and language modes incrementally. 
If there’s a gap in the Tooling testing or architecture we can change to make 
that better, let’s please discuss that, rather than trying to apply additional 
hurdles to a review process because a regression was introduced.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128462

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


  1   2   3   >